ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 include_once("./Services/UIComponent/Explorer2/classes/class.ilExplorerBaseGUI.php");
5 
14 abstract class ilTreeExplorerGUI extends ilExplorerBaseGUI
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 
82  function getTypeWhiteList()
83  {
85  }
86 
92  function setTypeBlackList($a_val)
93  {
94  $this->type_black_list = $a_val;
95  }
96 
102  function getTypeBlackList()
103  {
104  return $this->type_black_list;
105  }
106 
112  function setPreloadChilds($a_val)
113  {
114  $this->preload_childs = $a_val;
115  }
116 
122  function getPreloadChilds()
123  {
124  return $this->preload_childs;
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  {
288  $this->root_node_data = $this->getTree()->getNodeData($this->getRootId());
289  }
290  return $this->root_node_data;
291  }
292 
293  function setRootId($a_root)
294  {
295  $this->root_id = $a_root;
296  }
297 
298  protected function getRootId()
299  {
300  return $this->root_id
301  ? $this->root_id
302  : $this->getTree()->readRootId();
303  }
304 
310  function setPathOpen($a_id)
311  {
312  $path = $this->getTree()->getPathId($a_id);
313  foreach ($path as $id)
314  {
315  $this->setNodeOpen($id);
316  }
317  }
318 
324  function getHTML()
325  {
326  if ($this->getPreloadChilds())
327  {
328  $this->preloadChilds();
329  }
330  return parent::getHTML();
331  }
332 
333 
334 }
335 
336 ?>
getSuccessorNode($a_node_id, $a_type="")
Get successor node (currently only(!) based on lft/rgt tree values)
$path
Definition: aliased.php:25
preloadChilds()
Preload childs.
getPreloadChilds()
Get preload childs.
__construct($a_expl_id, $a_parent_obj, $a_parent_cmd, $a_tree)
Constructor.
getTypeBlackList()
Get type black list.
setPathOpen($a_id)
Set node path to be opened.
setNodeOpen($a_id)
Set node to be opened (additional custom opened node, not standard expand behaviour) ...
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
setTypeWhiteList($a_val)
Set type white list.
setPreloadChilds($a_val)
Set preload childs.
$a_type
Definition: workflow.php:93
setTypeBlackList($a_val)
Set type black list.
Explorer base GUI class.
getNodeIconAlt($a_node)
Get node icon alt attribute.
getNodeId($a_node)
Get id for node.
Create styles array
The data for the language used.
getRootNode()
Get root node.
getOrderField()
Get order field.
Explorer class that works on tree objects (Services/Tree)
global $lng
Definition: privfeed.php:17
setOrderField($a_val, $a_numeric=false)
Set order field.
getChildsOfNode($a_parent_node_id)
Get childs of node.
getTypeWhiteList()
Get type white list.