ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilLSTOCGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
12{
13 protected $id = 'ls_toc';
14 protected $structure;
15 protected $nodes = [];
19 protected $url_builder;
20
21 public function __construct(
23 ilCtrl $il_ctrl
24 ) {
25 $this->url_builder = $url_builder;
26 $this->ctrl = $il_ctrl; //ilExplorerBaseGUI needs ctrl...
27 $this->setSkipRootNode(false);
28 $this->setNodeOnclickEnabled(true);
29 }
30
31 public function withStructure(string $json_structure)
32 {
33 $clone = clone $this;
34 $clone->structure = $clone->addIds(
35 json_decode($json_structure, true)
36 );
37 $clone->buildLookup($clone->structure); //sets $this->nodes
38 $clone->open_nodes = array_keys($clone->nodes); //all open
39 return $clone;
40 }
41
42 protected $counter = 0;
43 protected function addIds(array $node) : array
44 {
45 $node['_id'] = $this->counter;
46 $this->counter++;
47 if (array_key_exists('childs', $node)) {
48 foreach ($node['childs'] as $idx => $child) {
49 $node['childs'][$idx] = $this->addIds($child);
50 }
51 }
52 return $node;
53 }
54
55 protected function buildLookup(array $node)
56 {
57 $this->nodes[$node['_id']] = $node;
58 if (array_key_exists('childs', $node)) {
59 foreach ($node['childs'] as $child) {
60 $this->buildLookup($child);
61 }
62 }
63 }
64
68 public function getRootNode()
69 {
70 return reset($this->nodes);
71 }
72
76 public function getChildsOfNode($a_parent_node_id)
77 {
78 $parent_node = $this->nodes[$a_parent_node_id];
79 return $parent_node['childs'];
80 }
81
85 public function getNodeContent($a_node)
86 {
87 return $a_node['label'];
88 }
89
93 public function getNodeId($a_node)
94 {
95 return $a_node['_id'];
96 }
97
101 public function getNodeHref($a_node)
102 {
103 return $this->url_builder->getHref($a_node['command'], $a_node['parameter']);
104 }
105
109 public function isNodeClickable($a_node)
110 {
111 return !is_null($a_node['parameter']);
112 }
113}
An exception for terminatinating execution or to throw for unit testing.
Class LSUrlBuilder.
This class provides processing control methods.
Explorer base GUI class.
setNodeOnclickEnabled($nodeOnclickEnabled)
setSkipRootNode($a_val)
Set skip root node.
Tree-GUI for ToC.
getRootNode()
Get root node.Please note that the class does not make any requirements how nodes are represented (ar...
addIds(array $node)
getChildsOfNode($a_parent_node_id)
Get childs of node.array childs
buildLookup(array $node)
__construct(LSUrlBuilder $url_builder, ilCtrl $il_ctrl)
getNodeId($a_node)
Get id of a node.string id of node
withStructure(string $json_structure)
isNodeClickable($a_node)
Is node clickable?boolean node clickable true/false
getNodeContent($a_node)
Get content of a node.string content of the node
getNodeHref($a_node)
Get href for node.string href attribute