ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilNestedList.php
Go to the documentation of this file.
1<?php
2
26{
27 protected string $item_class = "il_Explorer";
28 protected array $list_class = array();
29 protected bool $auto_numbering = false;
30 protected array $nr = array();
31 protected array $nodes = [];
32 protected array $childs = [];
33
34 public function __construct()
35 {
36 $this->list_class[0] = "il_Explorer";
37 $this->childs[0] = array();
38 }
39
40 // Set li class
41 public function setItemClass(string $a_val): void
42 {
43 $this->item_class = $a_val;
44 }
45
46 public function getItemClass(): string
47 {
48 return $this->item_class;
49 }
50
51 // Set list class
52 public function setListClass(string $a_val, int $a_depth = 0): void
53 {
54 $this->list_class[$a_depth] = $a_val;
55 }
56
57 public function getListClass(int $a_depth = 0): string
58 {
59 return $this->list_class[$a_depth] ?? "";
60 }
61
62 public function addListNode(
63 string $a_content,
64 string $a_id,
65 $a_parent = 0
66 ): void {
67 $this->nodes[$a_id] = $a_content;
68 $this->childs[$a_parent][] = $a_id;
69 }
70
71 public function setAutoNumbering(bool $a_val): void
72 {
73 $this->auto_numbering = $a_val;
74 }
75
76 public function getAutoNumbering(): bool
77 {
78 return $this->auto_numbering;
79 }
80
81 public function getNumbers(): array
82 {
83 return $this->nr;
84 }
85
86 public function getHTML(): string
87 {
88 $tpl = new ilTemplate("tpl.nested_list.html", true, true, "components/ILIAS/UIComponent/NestedList");
89
90 $nr = array();
91 $depth = 1;
92 if (isset($this->childs[0]) && count($this->childs[0]) > 0) {
93 $this->listStart($tpl, $depth);
94 foreach ($this->childs[0] as $child) {
95 $this->renderNode($child, $tpl, $depth, $nr);
96 }
97 $this->listEnd($tpl);
98 }
99
100 return $tpl->get();
101 }
102
103 public function renderNode(
104 $a_id,
105 ilTemplate $tpl,
106 int $depth,
107 array &$nr
108 ): void {
109 if (!isset($nr[$depth])) {
110 $nr[$depth] = 1;
111 } else {
112 $nr[$depth]++;
113 }
114
115 $nr_str = $sep = "";
116 if ($this->getAutoNumbering()) {
117 for ($i = 1; $i <= $depth; $i++) {
118 $nr_str .= $sep . $nr[$i];
119 $sep = ".";
120 }
121 }
122
123 $this->listItemStart($tpl);
124 $tpl->setCurrentBlock("content");
125 $tpl->setVariable("CONTENT", $nr_str . " " . $this->nodes[$a_id]);
126 $this->nr[$a_id] = $nr_str;
127 //echo "<br>".$this->nodes[$a_id];
128 $tpl->parseCurrentBlock();
129 $tpl->touchBlock("tag");
130
131 if (isset($this->childs[$a_id]) && count($this->childs[$a_id]) > 0) {
132 $this->listStart($tpl, $depth + 1);
133 foreach ($this->childs[$a_id] as $child) {
134 $this->renderNode($child, $tpl, $depth + 1, $nr);
135 }
136 $this->listEnd($tpl);
137 }
138 unset($nr[$depth + 1]);
139
140 $this->listItemEnd($tpl);
141 }
142
143 public function listItemStart(ilTemplate $tpl): void
144 {
145 if ($this->getItemClass() !== "") {
146 $tpl->setCurrentBlock("list_item_start");
147 $tpl->setVariable("LI_CLASS", ' class="' . $this->getItemClass() . '" ');
148 $tpl->parseCurrentBlock();
149 } else {
150 $tpl->touchBlock("list_item_start");
151 }
152 $tpl->touchBlock("tag");
153 }
154
155 public function listItemEnd(ilTemplate $tpl): void
156 {
157 $tpl->touchBlock("list_item_end");
158 $tpl->touchBlock("tag");
159 }
160
161 public function listStart(ilTemplate $tpl, int $depth): void
162 {
163 //echo "<br>listStart";
164
165 $class = ($this->getListClass($depth) !== "")
166 ? $this->getListClass($depth)
167 : $this->getListClass();
168 //echo "-$class-";
169 if ($class !== "") {
170 $tpl->setCurrentBlock("list_start");
171 $tpl->setVariable("UL_CLASS", ' class="' . $class . '" ');
172 $tpl->parseCurrentBlock();
173 } else {
174 $tpl->touchBlock("list_start");
175 }
176 $tpl->touchBlock("tag");
177 }
178
179 public function listEnd(ilTemplate $tpl): void
180 {
181 //echo "<br>listEnd";
182 $tpl->touchBlock("list_end");
183 $tpl->touchBlock("tag");
184 }
185}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
listItemStart(ilTemplate $tpl)
listStart(ilTemplate $tpl, int $depth)
getListClass(int $a_depth=0)
listEnd(ilTemplate $tpl)
renderNode( $a_id, ilTemplate $tpl, int $depth, array &$nr)
listItemEnd(ilTemplate $tpl)
setListClass(string $a_val, int $a_depth=0)
setItemClass(string $a_val)
setAutoNumbering(bool $a_val)
addListNode(string $a_content, string $a_id, $a_parent=0)
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
touchBlock(string $block)
if(!file_exists('../ilias.ini.php'))