23
23
// $id: current page Id.
24
24
// $parentId: the id of parent article.
25
25
// $wikiHeadline: the output, ordered array. will be modified inside the method.
26
- // $wikiHL: the array returned from Service.getAllWikiHeadlines.
26
+ // $wikiHL: the array returned from Service.getAllWikiHeadlines.
27
27
// Even if it is passed by reference for performance the method will not modify it.
28
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
-
29
+ function createTree ($ id , $ parentId , &$ wikiHeadlines , &$ wikiHL , $ indent )
30
+ {
31
+ // Finds the first article
32
+ $ articles = array_filter ($ wikiHL , function ($ v ) use ($ parentId ) {
33
+ return $ v ->parent == $ parentId ;
34
+ });
35
+ if (count ($ articles ) > 0 ) {
36
+ usort ($ articles , function ($ a1 , $ a2 ) {
37
+ return $ a1 ->title > $ a2 ->title ;
38
+ });
39
+ if ($ parentId != null ) {
40
+ $ indent = $ indent .'- ' ;
41
+ }
42
+ foreach ($ articles as $ article ) {
43
+ // This check prevents circular references by hiding the current page and its childs from list.
44
+ if ($ article ->id != $ id ) {
45
+ $ art = $ article ;
46
+ $ art ->title = $ indent .$ article ->title ;
47
+ $ wikiHeadlines [] = $ art ;
48
+ createTree ($ id , $ article ->id , $ wikiHeadlines , $ wikiHL , $ indent );
49
+ }
50
+ }
51
+ }
52
+ // var_dump($articles);
53
+
49
54
}
50
55
51
56
// --------------------------
@@ -61,7 +66,7 @@ function createTree($id, $parentId, &$wikiHeadlines, &$wikiHL, $indent) {
61
66
}
62
67
63
68
// Populates the options tree
64
- createTree ($ id , null , $ wikiHeadlines , $ wikiHL , "" );
69
+ createTree ($ id , null , $ wikiHeadlines , $ wikiHL , '' );
65
70
66
71
?>
67
72
0 commit comments