ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilNestedList.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
13 protected $item_class = "il_Explorer";
14 protected $list_class = array();
15 protected $auto_numbering = false;
16 protected $nr = array();
17
24 public function __constructor()
25 {
26 $this->list_class[0] = "il_Explorer";
27 $this->childs[0] = array();
28 }
29
35 public function setItemClass($a_val)
36 {
37 $this->item_class = $a_val;
38 }
39
45 public function getItemClass()
46 {
47 return $this->item_class;
48 }
49
55 public function setListClass($a_val, $a_depth = 0)
56 {
57 //var_dump($a_val);
58 $this->list_class[$a_depth] = $a_val;
59 }
60
66 public function getListClass($a_depth = 0)
67 {
68 return $this->list_class[$a_depth];
69 }
70
77 public function addListNode($a_content, $a_id, $a_parent = 0)
78 {
79 $this->nodes[$a_id] = $a_content;
80 $this->childs[$a_parent][] = $a_id;
81 }
82
88 public function setAutoNumbering($a_val)
89 {
90 $this->auto_numbering = $a_val;
91 }
92
98 public function getAutoNumbering()
99 {
101 }
102
108 public function getNumbers()
109 {
110 return $this->nr;
111 }
112
113
120 public function getHTML()
121 {
122 $tpl = new ilTemplate("tpl.nested_list.html", true, true, "Services/UIComponent/NestedList");
123
124 $nr = array();
125 $depth = 1;
126 if (is_array($this->childs[0]) && count($this->childs[0]) > 0) {
127 $this->listStart($tpl, $depth);
128 foreach ($this->childs[0] as $child) {
129 $this->renderNode($child, $tpl, $depth, $nr);
130 }
131 $this->listEnd($tpl);
132 }
133
134 return $tpl->get();
135 }
136
143 public function renderNode($a_id, $tpl, $depth, &$nr)
144 {
145 if (!isset($nr[$depth])) {
146 $nr[$depth] = 1;
147 } else {
148 $nr[$depth]++;
149 }
150
151 $nr_str = $sep = "";
152 if ($this->getAutoNumbering()) {
153 for ($i = 1; $i <= $depth; $i++) {
154 $nr_str.= $sep . $nr[$i];
155 $sep = ".";
156 }
157 }
158
159 $this->listItemStart($tpl);
160 $tpl->setCurrentBlock("content");
161 $tpl->setVariable("CONTENT", $nr_str . " " . $this->nodes[$a_id]);
162 $this->nr[$a_id] = $nr_str;
163 //echo "<br>".$this->nodes[$a_id];
164 $tpl->parseCurrentBlock();
165 $tpl->touchBlock("tag");
166
167 if (is_array($this->childs[$a_id]) && count($this->childs[$a_id]) > 0) {
168 $this->listStart($tpl, $depth + 1);
169 foreach ($this->childs[$a_id] as $child) {
170 $this->renderNode($child, $tpl, $depth + 1, $nr);
171 }
172 $this->listEnd($tpl);
173 }
174 unset($nr[$depth + 1]);
175
176 $this->listItemEnd($tpl);
177 }
178
185 public function listItemStart($tpl)
186 {
187 if ($this->getItemClass() != "") {
188 $tpl->setCurrentBlock("list_item_start");
189 $tpl->setVariable("LI_CLASS", ' class="' . $this->getItemClass() . '" ');
190 $tpl->parseCurrentBlock();
191 } else {
192 $tpl->touchBlock("list_item_start");
193 }
194 $tpl->touchBlock("tag");
195 }
196
203 public function listItemEnd($tpl)
204 {
205 $tpl->touchBlock("list_item_end");
206 $tpl->touchBlock("tag");
207 }
208
215 public function listStart($tpl, $depth)
216 {
217 //echo "<br>listStart";
218
219 $class = ($this->getListClass($depth) != "")
220 ? $this->getListClass($depth)
221 : $this->getListClass();
222 //echo "-$class-";
223 if ($class != "") {
224 $tpl->setCurrentBlock("list_start");
225 $tpl->setVariable("UL_CLASS", ' class="' . $class . '" ');
226 $tpl->parseCurrentBlock();
227 } else {
228 $tpl->touchBlock("list_start");
229 }
230 $tpl->touchBlock("tag");
231 }
232
239 public function listEnd($tpl)
240 {
241 //echo "<br>listEnd";
242 $tpl->touchBlock("list_end");
243 $tpl->touchBlock("tag");
244 }
245}
$tpl
Definition: ilias.php:10
An exception for terminatinating execution or to throw for unit testing.
listItemEnd($tpl)
List item end.
setListClass($a_val, $a_depth=0)
Set list class.
getListClass($a_depth=0)
Get list class.
addListNode($a_content, $a_id, $a_parent=0)
Add list node.
getNumbers()
Get numbers.
listEnd($tpl)
List end.
__constructor()
Constructor.
listItemStart($tpl)
List item start.
listStart($tpl, $depth)
List start.
getItemClass()
Get li class.
renderNode($a_id, $tpl, $depth, &$nr)
Render node.
setAutoNumbering($a_val)
Set auto numbering.
getAutoNumbering()
Get auto numbering.
setItemClass($a_val)
Set li class.
special template class to simplify handling of ITX/PEAR
$i
Definition: disco.tpl.php:19
$a_content
Definition: workflow.php:93