Skip to content

Commit 8a1a45c

Browse files
authored
Update articleDialog.tpl.php
1 parent 8d0e88d commit 8a1a45c

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

app/Domain/Wiki/Templates/articleDialog.tpl.php

+47-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,54 @@
33
$$var = $val; // necessary for blade refactor
44
}
55
$currentArticle = $tpl->get('article');
6+
7+
/*
8+
Original line:
9+
610
$wikiHeadlines = $tpl->get('wikiHeadlines');
7-
?>
811
12+
The following block orders and formats the headlines in the combobox.
13+
*/
14+
15+
// --------------------------
16+
17+
$wikiHL = $tpl->get('wikiHeadlines');
18+
19+
$wikiHeadlines = [];
20+
21+
// Adds to $wikiHeadlines all the options and suboptions from $wikiHL for articles with parent $parentId.
22+
// The method is called recursively.
23+
// $id: current page Id.
24+
// $parentId: the id of parent article.
25+
// $wikiHeadline: the output, ordered array. will be modified inside the method.
26+
// $wikiHL: the array returned from Service.getAllWikiHeadlines.
27+
// Even if it is passed by reference for performance the method will not modify it.
28+
// $indent is the string to put before the title, any level will add a space.
29+
function createTree($id, $parentId, &$wikiHeadlines, &$wikiHL, $indent) {
30+
// Finds the first article
31+
$articles = array_filter($wikiHL, function($v) use($parentId) { return $v->parent == $parentId; });
32+
if (count($articles) > 0) {
33+
usort ($articles, function($a1, $a2) { return $a1->title > $a2->title; });
34+
if ($parentId != null) {
35+
$indent = $indent . "-";
36+
}
37+
foreach ($articles as $article) {
38+
// This check prevents circular references by hiding the current page and its childs from list.
39+
if ($article->id != $id) {
40+
$art = $article;
41+
$art->title = $indent . $article->title;
42+
$wikiHeadlines[] = $art;
43+
createTree($id, $article->id, $wikiHeadlines, $wikiHL, $indent);
44+
}
45+
}
46+
}
47+
//var_dump($articles);
48+
49+
}
950

10-
<?php
51+
// --------------------------
1152

53+
// The following is the second original php block
1254
if (! isset($_GET['closeModal'])) {
1355
echo $tpl->displayNotification();
1456
}
@@ -18,6 +60,9 @@
1860
$id = $currentArticle->id;
1961
}
2062

63+
// Populates the options tree
64+
createTree($id, null, $wikiHeadlines, $wikiHL, "");
65+
2166
?>
2267

2368
<form class="formModal" method="post" action="<?= CURRENT_URL ?>">

0 commit comments

Comments
 (0)