ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilTreeExplorerGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/UIComponent/Explorer2/classes/class.ilExplorerBaseGUI.php");
5
15{
16 protected $tree = null;
17 protected $order_field = "";
18 protected $order_field_numeric = false;
19 protected $type_white_list = array();
20 protected $type_black_list = array();
21 protected $childs = array(); // preloaded childs
22 protected $preloaded = false;
23 protected $preload_childs = false;
24 protected $root_node_data = null;
25 protected $all_childs = array();
26
30 public function __construct($a_expl_id, $a_parent_obj, $a_parent_cmd, $a_tree)
31 {
32 parent::__construct($a_expl_id, $a_parent_obj, $a_parent_cmd);
33 $this->tree = $a_tree;
34 }
35
41 function getTree()
42 {
43 return $this->tree;
44 }
45
51 function setOrderField($a_val, $a_numeric = false)
52 {
53 $this->order_field = $a_val;
54 $this->order_field_numeric = $a_numeric;
55 }
56
62 function getOrderField()
63 {
64 return $this->order_field;
65 }
66
72 function setTypeWhiteList($a_val)
73 {
74 $this->type_white_list = $a_val;
75 }
76
83 {
85 }
86
92 function setTypeBlackList($a_val)
93 {
94 $this->type_black_list = $a_val;
95 }
96
103 {
105 }
106
112 function setPreloadChilds($a_val)
113 {
114 $this->preload_childs = $a_val;
115 }
116
123 {
125 }
126
130 protected function preloadChilds()
131 {
132 $subtree = $this->tree->getSubTree($this->getRootNode());
133 foreach ($subtree as $s)
134 {
135 $wl = $this->getTypeWhiteList();
136 if (is_array($wl) && count($wl) > 0 && !in_array($s["type"], $wl))
137 {
138 continue;
139 }
140 $bl = $this->getTypeBlackList();
141 if (is_array($bl) && count($bl) > 0 && in_array($s["type"], $bl))
142 {
143 continue;
144 }
145 $this->childs[$s["parent"]][] = $s;
146 $this->all_childs[$s["child"]] = $s;
147 }
148
149 if ($this->order_field != "")
150 {
151 foreach ($this->childs as $k => $childs)
152 {
153 $this->childs[$k] = ilUtil::sortArray($childs, $this->order_field, "asc", $this->order_field_numeric);
154 }
155 }
156
157 // sort childs and store prev/next reference
158 if ($this->order_field == "")
159 {
160 $this->all_childs =
161 ilUtil::sortArray($this->all_childs, "lft", "asc", true, true);
162 $prev = false;
163 foreach ($this->all_childs as $k => $c)
164 {
165 if ($prev)
166 {
167 $this->all_childs[$prev]["next_node_id"] = $k;
168 }
169 $this->all_childs[$k]["prev_node_id"] = $prev;
170 $this->all_childs[$k]["next_node_id"] = false;
171 $prev = $k;
172 }
173 }
174
175 $this->preloaded = true;
176 }
177
178
179
187 function getSuccessorNode($a_node_id, $a_type = "")
188 {
189 if ($this->order_field != "")
190 {
191 die("ilTreeExplorerGUI::getSuccessorNode not implemented for order field ".$this->order_field);
192 }
193
194 if ($this->preloaded)
195 {
196 $next_id = $a_node_id;
197 while (($next_id = $this->all_childs[$next_id]["next_node_id"]) && $a_type != "" &&
198 $this->all_childs[$next_id]["type"] != $a_type);
199 if ($next_id)
200 {
201 return $this->all_childs[$next_id];
202 }
203 return false;
204 }
205 return $this->getTree()->fetchSuccessorNode($a_node_id, $a_type);
206 }
207
208
209
216 function getChildsOfNode($a_parent_node_id)
217 {
218 if ($this->preloaded)
219 {
220 if (is_array($this->childs[$a_parent_node_id]))
221 {
222 return $this->childs[$a_parent_node_id];
223 }
224 return array();
225 }
226
227 $wl = $this->getTypeWhiteList();
228 if (is_array($wl) && count($wl) > 0)
229 {
230 $childs = $this->tree->getChildsByTypeFilter($a_parent_node_id, $wl, $this->getOrderField());
231 }
232 else
233 {
234 $childs = $this->tree->getChilds($a_parent_node_id, $this->getOrderField());
235 }
236
237 // apply black list filter
238 $bl = $this->getTypeBlackList();
239 if (is_array($bl) && count($bl) > 0)
240 {
241 $bl_childs = array();
242 foreach($childs as $k => $c)
243 {
244 if (!in_array($c["type"], $bl))
245 {
246 $bl_childs[$k] = $c;
247 }
248 }
249 return $bl_childs;
250 }
251
252 return $childs;
253 }
254
261 function getNodeId($a_node)
262 {
263 return $a_node["child"];
264 }
265
272 function getNodeIconAlt($a_node)
273 {
274 global $lng;
275
276 return $lng->txt("icon")." ".$lng->txt("obj_".$a_node["type"]);
277 }
278
284 function getRootNode()
285 {
286 if (isset($this->root_node_data))
287 {
289 }
290 $root_id = $this->getTree()->readRootId();
291 $this->root_node_data = $this->getTree()->getNodeData($root_id);
293 }
294
300 function setPathOpen($a_id)
301 {
302 $path = $this->getTree()->getPathId($a_id);
303 foreach ($path as $id)
304 {
305 $this->setNodeOpen($id);
306 }
307 }
308
314 function getHTML()
315 {
316 if ($this->getPreloadChilds())
317 {
318 $this->preloadChilds();
319 }
320 return parent::getHTML();
321 }
322
323
324}
325
326?>
Explorer base GUI class.
setNodeOpen($a_id)
Set node to be opened (additional custom opened node, not standard expand behaviour)
Explorer class that works on tree objects (Services/Tree)
__construct($a_expl_id, $a_parent_obj, $a_parent_cmd, $a_tree)
Constructor.
setTypeWhiteList($a_val)
Set type white list.
preloadChilds()
Preload childs.
setPathOpen($a_id)
Set node path to be opened.
getTypeWhiteList()
Get type white list.
getNodeId($a_node)
Get id for node.
setTypeBlackList($a_val)
Set type black list.
getChildsOfNode($a_parent_node_id)
Get childs of node.
getTypeBlackList()
Get type black list.
setPreloadChilds($a_val)
Set preload childs.
getNodeIconAlt($a_node)
Get node icon alt attribute.
getOrderField()
Get order field.
getPreloadChilds()
Get preload childs.
getSuccessorNode($a_node_id, $a_type="")
Get successor node (currently only(!) based on lft/rgt tree values)
setOrderField($a_val, $a_numeric=false)
Set order field.
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
global $lng
Definition: privfeed.php:40
$path
Definition: index.php:22