ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 function __constructor()
25 {
26 $this->list_class[0] = "il_Explorer";
27 $this->childs[0] = array();
28 }
29
35 function setItemClass($a_val)
36 {
37 $this->item_class = $a_val;
38 }
39
45 function getItemClass()
46 {
47 return $this->item_class;
48 }
49
55 function setListClass($a_val, $a_depth = 0)
56 {
57//var_dump($a_val);
58 $this->list_class[$a_depth] = $a_val;
59 }
60
66 function getListClass($a_depth = 0)
67 {
68 return $this->list_class[$a_depth];
69 }
70
77 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 function getNumbers()
109 {
110 return $this->nr;
111 }
112
113
120 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 {
128 $this->listStart($tpl, $depth);
129 foreach ($this->childs[0] as $child)
130 {
131 $this->renderNode($child, $tpl, $depth, $nr);
132 }
133 $this->listEnd($tpl);
134 }
135
136 return $tpl->get();
137 }
138
145 function renderNode($a_id, $tpl, $depth, &$nr)
146 {
147 if (!isset($nr[$depth]))
148 {
149 $nr[$depth] = 1;
150 }
151 else
152 {
153 $nr[$depth]++;
154 }
155
156 $nr_str = $sep = "";
157 if ($this->getAutoNumbering())
158 {
159 for($i = 1; $i <= $depth; $i++)
160 {
161 $nr_str.= $sep.$nr[$i];
162 $sep = ".";
163 }
164 }
165
166 $this->listItemStart($tpl);
167 $tpl->setCurrentBlock("content");
168 $tpl->setVariable("CONTENT", $nr_str." ".$this->nodes[$a_id]);
169 $this->nr[$a_id] = $nr_str;
170//echo "<br>".$this->nodes[$a_id];
171 $tpl->parseCurrentBlock();
172 $tpl->touchBlock("tag");
173
174 if (is_array($this->childs[$a_id]) && count($this->childs[$a_id]) > 0)
175 {
176 $this->listStart($tpl, $depth + 1);
177 foreach ($this->childs[$a_id] as $child)
178 {
179 $this->renderNode($child, $tpl, $depth + 1, $nr);
180 }
181 $this->listEnd($tpl);
182 }
183 unset($nr[$depth + 1]);
184
185 $this->listItemEnd($tpl);
186 }
187
195 {
196 if ($this->getItemClass() != "")
197 {
198 $tpl->setCurrentBlock("list_item_start");
199 $tpl->setVariable("LI_CLASS", ' class="'.$this->getItemClass().'" ');
200 $tpl->parseCurrentBlock();
201 }
202 else
203 {
204 $tpl->touchBlock("list_item_start");
205 }
206 $tpl->touchBlock("tag");
207 }
208
216 {
217 $tpl->touchBlock("list_item_end");
218 $tpl->touchBlock("tag");
219 }
220
227 function listStart($tpl, $depth)
228 {
229//echo "<br>listStart";
230
231 $class = ($this->getListClass($depth) != "")
232 ? $this->getListClass($depth)
233 : $this->getListClass();
234//echo "-$class-";
235 if ($class != "")
236 {
237 $tpl->setCurrentBlock("list_start");
238 $tpl->setVariable("UL_CLASS", ' class="'.$class.'" ');
239 $tpl->parseCurrentBlock();
240 }
241 else
242 {
243 $tpl->touchBlock("list_start");
244 }
245 $tpl->touchBlock("tag");
246 }
247
254 function listEnd($tpl)
255 {
256//echo "<br>listEnd";
257 $tpl->touchBlock("list_end");
258 $tpl->touchBlock("tag");
259 }
260
261}
262?>
global $tpl
Definition: ilias.php:8
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