ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLSTOCGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
31 public const NODE_ICONS = [
32 TOCBuilder::LP_NOT_STARTED => "./assets/images/scorm/not_attempted.svg",
33 TOCBuilder::LP_IN_PROGRESS => "./assets/images/scorm/incomplete.svg",
34 TOCBuilder::LP_COMPLETED => "./assets/images/scorm/completed.svg",
35 TOCBuilder::LP_FAILED => "./assets/images/scorm/failed.svg"
36 ];
37
41 protected array $structure;
42
46 protected array $nodes = [];
48 protected int $counter = 0;
49
53 protected array $node_icons = [
54 TOCBuilder::LP_NOT_STARTED => '',
55 TOCBuilder::LP_IN_PROGRESS => '',
56 TOCBuilder::LP_COMPLETED => '',
57 TOCBuilder::LP_FAILED => ''
58 ];
59
61 {
62 parent::__construct("lsq_toc", null, "");
63
64 $this->url_builder = $url_builder;
65 $this->setSkipRootNode(false);
66 $this->setNodeOnclickEnabled(true);
67
68 //get the image paths to the node icons
70 $this->node_icons[TOCBuilder::LP_NOT_STARTED] = $lp_icons->getImagePathNotAttempted();
71 $this->node_icons[TOCBuilder::LP_COMPLETED] = $lp_icons->getImagePathCompleted();
72 $this->node_icons[TOCBuilder::LP_IN_PROGRESS] = $lp_icons->getImagePathInProgress();
73 $this->node_icons[TOCBuilder::LP_FAILED] = $lp_icons->getImagePathFailed();
74 }
75
76 public function withStructure(string $json_structure): self
77 {
78 $clone = clone $this;
79 $clone->structure = $clone->addIds(json_decode($json_structure, true));
80 $clone->buildLookup($clone->structure);
81 $clone->open_nodes = array_keys($clone->nodes);
82 return $clone;
83 }
84
85 protected function addIds(array $node): array
86 {
87 $node['_id'] = $this->counter;
88 $this->counter++;
89 if (array_key_exists('childs', $node)) {
90 foreach ($node['childs'] as $idx => $child) {
91 $node['childs'][$idx] = $this->addIds($child);
92 }
93 }
94 return $node;
95 }
96
97 protected function buildLookup(array $node): void
98 {
99 $this->nodes[$node['_id']] = $node;
100 if (array_key_exists('childs', $node)) {
101 foreach ($node['childs'] as $child) {
102 $this->buildLookup($child);
103 }
104 }
105 }
106
110 public function getRootNode()
111 {
112 return reset($this->nodes);
113 }
114
118 public function getChildsOfNode($a_parent_node_id): array
119 {
120 $parent_node = $this->nodes[$a_parent_node_id];
121 return (array) ($parent_node['childs'] ?? []);
122 }
123
127 public function getNodeContent($a_node): string
128 {
129 return $a_node['label'];
130 }
131
135 public function getNodeIcon($a_node): string
136 {
137 $state = $a_node['state'] ?? TOCBuilder::LP_NOT_STARTED;
138 return $this->node_icons[$state];
139 }
140
144 public function getNodeId($a_node)
145 {
146 return $a_node['_id'];
147 }
148
152 public function getNodeHref($a_node): string
153 {
154 return $this->url_builder->getHref($a_node['command'], $a_node['parameter']);
155 }
156
160 public function isNodeClickable($a_node): bool
161 {
162 return !is_null($a_node['parameter']);
163 }
164
168 public function isNodeHighlighted($a_node): bool
169 {
170 return $a_node['current'] ?? false;
171 }
172}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setNodeOnclickEnabled(bool $nodeOnclickEnabled)
static getInstance(int $variant=ilLPStatusIcons::ICON_VARIANT_DEFAULT, ?\ILIAS\UI\Renderer $renderer=null, ?\ILIAS\UI\Factory $factory=null)
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)
getNodeIcon($a_node)
Get node icon path.string image file path
getChildsOfNode($a_parent_node_id)
Get children of node.array
LSUrlBuilder $url_builder
buildLookup(array $node)
isNodeHighlighted($a_node)
Is node highlighted?bool node highlighted true/false
getNodeId($a_node)
Get id of a node.string id of node
withStructure(string $json_structure)
isNodeClickable($a_node)
Is node clickable?bool node clickable true/false
__construct(LSUrlBuilder $url_builder)
getNodeContent($a_node)
Get content of a node.string content of the node
getNodeHref($a_node)
Get href for node.string href attribute
Build a nested table of contents for the view.
Definition: TOCBuilder.php:29
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc