ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLSTOCGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
6
14{
18 const NODE_ICONS = [
19 TOCBuilder::LP_NOT_STARTED => "./templates/default/images/scorm/not_attempted.svg",
20 TOCBuilder::LP_IN_PROGRESS => "./templates/default/images/scorm/incomplete.svg",
21 TOCBuilder::LP_COMPLETED => "./templates/default/images/scorm/completed.svg",
22 TOCBuilder::LP_FAILED => "./templates/default/images/scorm/failed.svg"
23 ];
24
25 protected $id = 'ls_toc';
26 protected $structure;
27 protected $nodes = [];
31 protected $url_builder;
32
36 protected $node_icons = [
37 TOCBuilder::LP_NOT_STARTED => '',
38 TOCBuilder::LP_IN_PROGRESS => '',
39 TOCBuilder::LP_COMPLETED => '',
40 TOCBuilder::LP_FAILED => ''
41 ];
42
43 public function __construct(
45 ilCtrl $il_ctrl
46 ) {
47 parent::__construct("lsq_toc", null, "");
48 $this->url_builder = $url_builder;
49 $this->ctrl = $il_ctrl; //ilExplorerBaseGUI needs ctrl...
50 $this->setSkipRootNode(false);
51 $this->setNodeOnclickEnabled(true);
52
53 //get the image paths to the node icons
55 $this->node_icons[TOCBuilder::LP_NOT_STARTED] = $lp_icons->getImagePathNotAttempted();
56 $this->node_icons[TOCBuilder::LP_COMPLETED] = $lp_icons->getImagePathCompleted();
57 $this->node_icons[TOCBuilder::LP_IN_PROGRESS] = $lp_icons->getImagePathInProgress();
58 $this->node_icons[TOCBuilder::LP_FAILED] = $lp_icons->getImagePathFailed();
59 }
60
61 public function withStructure(string $json_structure)
62 {
63 $clone = clone $this;
64 $clone->structure = $clone->addIds(
65 json_decode($json_structure, true)
66 );
67 $clone->buildLookup($clone->structure); //sets $this->nodes
68 $clone->open_nodes = array_keys($clone->nodes); //all open
69 return $clone;
70 }
71
72 protected $counter = 0;
73 protected function addIds(array $node) : array
74 {
75 $node['_id'] = $this->counter;
76 $this->counter++;
77 if (array_key_exists('childs', $node)) {
78 foreach ($node['childs'] as $idx => $child) {
79 $node['childs'][$idx] = $this->addIds($child);
80 }
81 }
82 return $node;
83 }
84
85 protected function buildLookup(array $node)
86 {
87 $this->nodes[$node['_id']] = $node;
88 if (array_key_exists('childs', $node)) {
89 foreach ($node['childs'] as $child) {
90 $this->buildLookup($child);
91 }
92 }
93 }
94
98 public function getRootNode()
99 {
100 return reset($this->nodes);
101 }
102
106 public function getChildsOfNode($a_parent_node_id)
107 {
108 $parent_node = $this->nodes[$a_parent_node_id];
109 return (array) $parent_node['childs'];
110 }
111
115 public function getNodeContent($a_node)
116 {
117 return $a_node['label'];
118 }
119
123 public function getNodeIcon($a_node)
124 {
125 $state = $a_node['state'] ?? TOCBuilder::LP_NOT_STARTED;
126 return $this->node_icons[$state];
127 }
128
132 public function getNodeId($a_node)
133 {
134 return $a_node['_id'];
135 }
136
140 public function getNodeHref($a_node)
141 {
142 return $this->url_builder->getHref($a_node['command'], $a_node['parameter']);
143 }
144
148 public function isNodeClickable($a_node)
149 {
150 return !is_null($a_node['parameter']);
151 }
152
156 public function isNodeHighlighted($a_node)
157 {
158 return $a_node['current'];
159 }
160}
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.
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 childs of node.array childs
buildLookup(array $node)
__construct(LSUrlBuilder $url_builder, ilCtrl $il_ctrl)
isNodeHighlighted($a_node)
Is node highlighted?boolean 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?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
Build a nested table of contents for the view.
Definition: TOCBuilder.php:12
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc