ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilRepositorySelectorExplorerGUI.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.ilTreeExplorerGUI.php");
5 
19 {
23  protected $obj_definition;
24 
28  protected $lng;
29 
30  protected $type_grps = array();
31  protected $session_materials = array();
32  protected $highlighted_node = null;
33  protected $clickable_types = array();
34 
38  protected $ctrl;
39 
43  protected $access;
44 
48  protected $nc_modifier = null;
49 
53  protected $selection_gui = null;
54 
58  protected $selection_par;
59 
63  protected $selection_cmd;
64 
74  public function __construct(
75  $a_parent_obj,
76  $a_parent_cmd,
77  $a_selection_gui = null,
78  $a_selection_cmd = "selectObject",
79  $a_selection_par = "sel_ref_id",
80  $a_id = "rep_exp_sel"
81  ) {
82  global $DIC;
83 
84  $this->tree = $DIC->repositoryTree();
85  $this->obj_definition = $DIC["objDefinition"];
86  $this->lng = $DIC->language();
87  $tree = $DIC->repositoryTree();
88  $objDefinition = $DIC["objDefinition"];
89 
90  $this->access = $DIC->access();
91  $this->ctrl = $DIC->ctrl();
92 
93  if (is_null($a_selection_gui)) {
94  $a_selection_gui = $a_parent_obj;
95  }
96 
97  $this->selection_gui = is_object($a_selection_gui)
98  ? strtolower(get_class($a_selection_gui))
99  : strtolower($a_selection_gui);
100  $this->selection_cmd = $a_selection_cmd;
101  $this->selection_par = $a_selection_par;
102  parent::__construct($a_id, $a_parent_obj, $a_parent_cmd, $tree);
103 
104  $this->setSkipRootNode(false);
105  $this->setAjax(true);
106  $this->setOrderField("title");
107 
108  // per default: all object types, except item groups
109  $white = array();
110  foreach ($objDefinition->getSubObjectsRecursively("root") as $rtype) {
111  if ($rtype["name"] != "itgr" && !$objDefinition->isSideBlock($rtype["name"])) {
112  $white[] = $rtype["name"];
113  }
114  }
115  $this->setTypeWhiteList($white);
116 
117  // always open the path to the current ref id
118  if ((int) $_GET["ref_id"] > 0) {
119  $this->setPathOpen((int) $_GET["ref_id"]);
120  }
121  }
122 
128  public function setNodeContentModifier(callable $a_val)
129  {
130  $this->nc_modifier = $a_val;
131  }
132 
138  public function getNodeContentModifier()
139  {
140  return $this->nc_modifier;
141  }
142 
149  public function getNodeContent($a_node)
150  {
151  $lng = $this->lng;
152 
153  $c = $this->getNodeContentModifier();
154  if (is_callable($c)) {
155  return $c($a_node);
156  }
157 
158  $title = $a_node["title"];
159  if ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
160  if ($title == "ILIAS") {
161  $title = $lng->txt("repository");
162  }
163  }
164 
165  return $title;
166  }
167 
174  public function getNodeIcon($a_node)
175  {
176  $obj_id = ilObject::_lookupObjId($a_node["child"]);
177  return ilObject::_getIcon($obj_id, "tiny", $a_node["type"]);
178  }
179 
186  public function getNodeIconAlt($a_node)
187  {
188  $lng = $this->lng;
189 
190  if ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
191  $title = $a_node["title"];
192  if ($title == "ILIAS") {
193  $title = $lng->txt("repository");
194  }
195  return $lng->txt("icon") . " " . $title;
196  }
197 
198 
199  return parent::getNodeIconAlt($a_node);
200  }
201 
208  public function isNodeHighlighted($a_node)
209  {
210  if ($this->getHighlightedNode()) {
211  if ($this->getHighlightedNode() == $a_node["child"]) {
212  return true;
213  }
214  return false;
215  }
216 
217  if ($a_node["child"] == $_GET["ref_id"] ||
218  ($_GET["ref_id"] == "" && $a_node["child"] == $this->getNodeId($this->getRootNode()))) {
219  return true;
220  }
221  return false;
222  }
223 
230  public function getNodeHref($a_node)
231  {
233 
234  if ($this->select_postvar == "") {
235  $ilCtrl->setParameterByClass($this->selection_gui, $this->selection_par, $a_node["child"]);
236  $link = $ilCtrl->getLinkTargetByClass($this->selection_gui, $this->selection_cmd);
237  $ilCtrl->setParameterByClass($this->selection_gui, $this->selection_par, "");
238  } else {
239  return "#";
240  }
241 
242  return $link;
243  }
244 
251  public function isNodeVisible($a_node)
252  {
253  $ilAccess = $this->access;
254 
255  if (!$ilAccess->checkAccess('visible', '', $a_node["child"])) {
256  return false;
257  }
258 
259  return true;
260  }
261 
269  public function sortChilds($a_childs, $a_parent_node_id)
270  {
271  $objDefinition = $this->obj_definition;
272 
273  $parent_obj_id = ilObject::_lookupObjId($a_parent_node_id);
274 
275  if ($parent_obj_id > 0) {
276  $parent_type = ilObject::_lookupType($parent_obj_id);
277  } else {
278  $parent_type = "dummy";
279  $this->type_grps["dummy"] = array("root" => "dummy");
280  }
281 
282  if (empty($this->type_grps[$parent_type])) {
283  $this->type_grps[$parent_type] =
284  $objDefinition->getGroupedRepositoryObjectTypes($parent_type);
285  }
286  $group = array();
287 
288  foreach ($a_childs as $child) {
289  $g = $objDefinition->getGroupOfObj($child["type"]);
290  if ($g == "") {
291  $g = $child["type"];
292  }
293  $group[$g][] = $child;
294  }
295 
296  // #14587 - $objDefinition->getGroupedRepositoryObjectTypes does NOT include side blocks!
297  $wl = $this->getTypeWhiteList();
298  if (is_array($wl) && in_array("poll", $wl)) {
299  $this->type_grps[$parent_type]["poll"] = array();
300  }
301 
302  $childs = array();
303  foreach ($this->type_grps[$parent_type] as $t => $g) {
304  if (is_array($group[$t])) {
305  // do we have to sort this group??
306  include_once("./Services/Container/classes/class.ilContainer.php");
307  include_once("./Services/Container/classes/class.ilContainerSorting.php");
308  $sort = ilContainerSorting::_getInstance($parent_obj_id);
309  $group = $sort->sortItems($group);
310 
311  // need extra session sorting here
312  if ($t == "sess") {
313  }
314 
315  foreach ($group[$t] as $k => $item) {
316  $childs[] = $item;
317  }
318  }
319  }
320 
321  return $childs;
322  }
323 
330  public function getChildsOfNode($a_parent_node_id)
331  {
332  $ilAccess = $this->access;
333 
334  if (!$ilAccess->checkAccess("read", "", $a_parent_node_id)) {
335  return array();
336  }
337 
338  return parent::getChildsOfNode($a_parent_node_id);
339  }
340 
347  public function isNodeClickable($a_node)
348  {
349  $ilAccess = $this->access;
350 
351  if ($this->select_postvar != "") {
352  // return false; #14354
353  }
354 
355  if (!$ilAccess->hasUserRBACorAnyPositionAccess("read", $a_node["child"])) {
356  return false;
357  }
358 
359  if (is_array($this->getClickableTypes()) && count($this->getClickableTypes())>0) {
360  return in_array($a_node["type"], $this->getClickableTypes());
361  }
362 
363  return true;
364  }
365 
371  public function setHighlightedNode($a_value)
372  {
373  $this->highlighted_node = $a_value;
374  }
375 
382  public function getHighlightedNode()
383  {
385  }
386 
392  public function setClickableTypes($a_types)
393  {
394  if (!is_array($a_types)) {
395  $a_types = array($a_types);
396  }
397  $this->clickable_types = $a_types;
398  }
399 
405  public function getClickableTypes()
406  {
407  return (array) $this->clickable_types;
408  }
409 
416  /* function getHTML()
417  {
418  global $ilCtrl, $tpl;
419 
420  $add = "";
421  if ($ilCtrl->isAsynch())
422  {
423  $add = $this->getOnLoadCode();
424  }
425  else
426  {
427  $tpl->addOnloadCode($this->getOnLoadCode());
428  }
429 
430  return parent::getHTML().$add;
431  }
432  */
433 
439  public function setSelectableTypes($a_types)
440  {
441  if (!is_array($a_types)) {
442  $a_types = array($a_types);
443  }
444  $this->selectable_types = $a_types;
445  }
446 
452  public function getSelectableTypes()
453  {
454  return (array) $this->selectable_types;
455  }
456 
463  protected function isNodeSelectable($a_node)
464  {
465  if (count($this->getSelectableTypes())) {
466  return in_array($a_node['type'], $this->getSelectableTypes());
467  }
468  return true;
469  }
470 }
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
Explorer for selecting repository items.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
setNodeContentModifier(callable $a_val)
Set node content modifier.
setSkipRootNode($a_val)
Set skip root node.
sortChilds($a_childs, $a_parent_node_id)
Sort childs.
getHighlightedNode()
get an alternate highlighted node if $_GET["ref_id"] is not set or wrong Returns null if not set ...
setPathOpen($a_id)
Set node path to be opened.
setHighlightedNode($a_value)
set an alternate highlighted node if $_GET["ref_id"] is not set or wrong
setTypeWhiteList($a_val)
Set type white list.
global $ilCtrl
Definition: ilias.php:18
static _lookupObjId($a_id)
getNodeId($a_node)
Get id for node.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
getRootNode()
Get root node.
$white
Definition: example_030.php:84
getClickableTypes()
get whitelist for clickable items
Explorer class that works on tree objects (Services/Tree)
getChildsOfNode($a_parent_node_id)
Get childs of node.
getSelectableTypes()
get whitelist for clickable items
setOrderField($a_val, $a_numeric=false)
Set order field.
static _getInstance($a_obj_id)
get instance by obj_id
setClickableTypes($a_types)
set Whitelist for clickable items
__construct( $a_parent_obj, $a_parent_cmd, $a_selection_gui=null, $a_selection_cmd="selectObject", $a_selection_par="sel_ref_id", $a_id="rep_exp_sel")
Constructor.
getTypeWhiteList()
Get type white list.