|
3 | 3 | $$var = $val; // necessary for blade refactor
|
4 | 4 | }
|
5 | 5 | $currentArticle = $tpl->get('article');
|
| 6 | + |
| 7 | +/* |
| 8 | +Original line: |
| 9 | +
|
6 | 10 | $wikiHeadlines = $tpl->get('wikiHeadlines');
|
7 |
| -?> |
8 | 11 |
|
| 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 | +} |
9 | 50 |
|
10 |
| -<?php |
| 51 | +// -------------------------- |
11 | 52 |
|
| 53 | +// The following is the second original php block |
12 | 54 | if (! isset($_GET['closeModal'])) {
|
13 | 55 | echo $tpl->displayNotification();
|
14 | 56 | }
|
|
18 | 60 | $id = $currentArticle->id;
|
19 | 61 | }
|
20 | 62 |
|
| 63 | +// Populates the options tree |
| 64 | +createTree($id, null, $wikiHeadlines, $wikiHL, ""); |
| 65 | + |
21 | 66 | ?>
|
22 | 67 |
|
23 | 68 | <form class="formModal" method="post" action="<?= CURRENT_URL ?>">
|
|
0 commit comments