ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilRepositoryExplorerGUI.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 
17 {
21  protected $settings;
22 
26  protected $obj_definition;
27 
31  protected $lng;
32 
36  protected $ctrl;
37 
41  protected $access;
42 
46  protected $rbacsystem;
47 
51  protected $db;
52 
56  protected $user;
57 
58  protected $type_grps = array();
59  protected $session_materials = array();
60 
61  protected $parent_node_id = [];
62  protected $node_data = [];
63 
67  public function __construct($a_parent_obj, $a_parent_cmd)
68  {
69  global $DIC;
70 
71  $this->tree = $DIC->repositoryTree();
72  $this->settings = $DIC->settings();
73  $this->obj_definition = $DIC["objDefinition"];
74  $this->lng = $DIC->language();
75  $this->ctrl = $DIC->ctrl();
76  $this->access = $DIC->access();
77  $this->rbacsystem = $DIC->rbac()->system();
78  $this->db = $DIC->database();
79  $this->user = $DIC->user();
80  $tree = $DIC->repositoryTree();
81  $ilSetting = $DIC->settings();
82  $objDefinition = $DIC["objDefinition"];
83 
84  $this->cur_ref_id = (int) $_GET["ref_id"];
85 
86  $this->top_node_id = 0;
87  if ($ilSetting->get("rep_tree_limit_grp_crs") && $this->cur_ref_id > 0) {
88  $path = $tree->getPathId($this->cur_ref_id);
89  foreach ($path as $n) {
90  if ($top_node > 0) {
91  break;
92  }
93  if (in_array(
95  array("crs", "grp")
96  )) {
97  $this->top_node_id = $n;
98  }
99  }
100  }
101 
102  parent::__construct("rep_exp", $a_parent_obj, $a_parent_cmd, $tree);
103 
104  $this->setSkipRootNode(false);
105  $this->setAjax(true);
106  $this->setOrderField("title");
107  if ($ilSetting->get("repository_tree_pres") == "" ||
108  ($ilSetting->get("rep_tree_limit_grp_crs") && $this->top_node_id == 0)) {
109  $this->setTypeWhiteList($objDefinition->getExplorerContainerTypes());
110  } elseif ($ilSetting->get("repository_tree_pres") == "all_types") {
111  $white = array();
112  foreach ($objDefinition->getSubObjectsRecursively("root") as $rtype) {
113  if (/* $rtype["name"] != "itgr" && */ !$objDefinition->isSideBlock($rtype["name"])) {
114  $white[] = $rtype["name"];
115  }
116  }
117  $this->setTypeWhiteList($white);
118  }
119  if ((int) $_GET["ref_id"] > 0) {
120  $this->setPathOpen((int) $_GET["ref_id"]);
121  }
122 
123  $this->setChildLimit((int) $ilSetting->get("rep_tree_limit_number"));
124  }
125 
132  public function getRootNode()
133  {
134  if ($this->top_node_id > 0) {
135  $root_node = $this->getTree()->getNodeData($this->top_node_id);
136  } else {
137  $root_node = parent::getRootNode();
138  }
139  $this->node_data[$root_node["child"]] = $root_node;
140  return $root_node;
141  }
142 
149  public function getNodeContent($a_node)
150  {
151  $lng = $this->lng;
152 
153  $title = $a_node["title"];
154 
155  if ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
156  if ($title == "ILIAS") {
157  $title = $lng->txt("repository");
158  }
159  } elseif ($a_node["type"] == "sess" &&
160  !trim($title)) {
161  // #14367 - see ilObjSessionListGUI
162  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
163  $app_info = ilSessionAppointment::_lookupAppointment($a_node["obj_id"]);
164  $title = ilSessionAppointment::_appointmentToString($app_info['start'], $app_info['end'], $app_info['fullday']);
165  }
166 
167  return $title;
168  }
169 
176  public function getNodeIcon($a_node)
177  {
178  $obj_id = ilObject::_lookupObjId($a_node["child"]);
179  return ilObject::_getIcon($obj_id, "tiny", $a_node["type"]);
180  }
181 
188  public function getNodeIconAlt($a_node)
189  {
190  $lng = $this->lng;
191 
192  if ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
193  $title = $a_node["title"];
194  if ($title == "ILIAS") {
195  $title = $lng->txt("repository");
196  }
197  return $lng->txt("icon") . " " . $title;
198  }
199 
200 
201  return parent::getNodeIconAlt($a_node);
202  }
203 
210  public function isNodeHighlighted($a_node)
211  {
212  if ($a_node["child"] == $_GET["ref_id"] ||
213  ($_GET["ref_id"] == "" && $a_node["child"] == $this->getNodeId($this->getRootNode()))) {
214  return true;
215  }
216  return false;
217  }
218 
225  public function getNodeHref($a_node)
226  {
228 
229  switch ($a_node["type"]) {
230  case "root":
231  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
232  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
233  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
234  return $link;
235 
236  case "cat":
237  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
238  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
239  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
240  return $link;
241 
242  case "catr":
243  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
244  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
245  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
246  return $link;
247 
248  case "grp":
249  $ilCtrl->setParameterByClass("ilobjgroupgui", "ref_id", $a_node["child"]);
250  $link = $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjgroupgui"), "");
251  $ilCtrl->setParameterByClass("ilobjgroupgui", "ref_id", $_GET["ref_id"]);
252  return $link;
253 
254  case "grpr":
255  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
256  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
257  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
258  return $link;
259 
260  case "crs":
261  $ilCtrl->setParameterByClass("ilobjcoursegui", "ref_id", $a_node["child"]);
262  $link = $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjcoursegui"), "view");
263  $ilCtrl->setParameterByClass("ilobjcoursegui", "ref_id", $_GET["ref_id"]);
264  return $link;
265 
266  case "crsr":
267  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
268  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
269  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
270  return $link;
271 
272  case 'rcrs':
273  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
274  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "infoScreen");
275  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
276  return $link;
277 
278  case 'prg':
279  $ilCtrl->setParameterByClass("ilobjstudyprogrammegui", "ref_id", $a_node["child"]);
280  $link = $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjstudyprogrammegui"), "view");
281  $ilCtrl->setParameterByClass("ilobjstudyprogrammegui", "ref_id", $_GET["ref_id"]);
282  return $link;
283 
284  default:
285  include_once('./Services/Link/classes/class.ilLink.php');
286  return ilLink::_getStaticLink($a_node["child"], $a_node["type"], true);
287 
288  }
289  }
290 
297  public function isNodeVisible($a_node)
298  {
299  $ilAccess = $this->access;
300  $tree = $this->tree;
302 
303  if (!$ilAccess->checkAccess('visible', '', $a_node["child"])) {
304  return false;
305  }
306 
307  if ($ilSetting->get("repository_tree_pres") == "all_types") {
308  /*$container_parent_id = $tree->checkForParentType($a_node["child"], 'grp');
309  if (!$container_parent_id) {
310  $container_parent_id = $tree->checkForParentType($a_node["child"], 'crs');
311  }*/
312  // see #21215
313  $container_parent_id = $this->getParentCourseOrGroup($a_node["child"]);
314  if ($container_parent_id > 0) {
315  // do not display session materials for container course/group
316  if ($container_parent_id != $a_node["child"]) {
317  // get container event items only once
318  if (!isset($this->session_materials[$container_parent_id])) {
319  include_once './Modules/Session/classes/class.ilEventItems.php';
320  $this->session_materials[$container_parent_id] = ilEventItems::_getItemsOfContainer($container_parent_id);
321  }
322  if (in_array($a_node["child"], $this->session_materials[$container_parent_id])) {
323  return false;
324  }
325  }
326  }
327  }
328 
329  return true;
330  }
331 
338  protected function getParentCourseOrGroup($node_id)
339  {
340  $current_node_id = $node_id;
341  while (isset($this->parent_node_id[$current_node_id])) {
342  $parent_node_id = $this->parent_node_id[$current_node_id];
343  if (isset($this->node_data[$parent_node_id]) && in_array($this->node_data[$parent_node_id]["type"], ["grp", "crs"])) {
344  return $parent_node_id;
345  }
346  $current_node_id = $parent_node_id;
347  }
348  return 0;
349  }
350 
351 
360  public function sortChilds($a_childs, $a_parent_node_id)
361  {
362  $objDefinition = $this->obj_definition;
363  $ilAccess = $this->access;
364 
365  $parent_obj_id = ilObject::_lookupObjId($a_parent_node_id);
366  if ($parent_obj_id > 0) {
367  $parent_type = ilObject::_lookupType($parent_obj_id);
368  } else {
369  $parent_type = "dummy";
370  $this->type_grps["dummy"] = array("root" => "dummy");
371  }
372 
373  // alex: if this is not initialized, things are messed up
374  // see bug 0015978
375  $this->type_grps = array();
376 
377  if (empty($this->type_grps[$parent_type])) {
378  $this->type_grps[$parent_type] =
379  $objDefinition->getGroupedRepositoryObjectTypes($parent_type);
380  }
381 
382  // #14465 - item groups
383  include_once('./Services/Object/classes/class.ilObjectActivation.php');
384  $group = array();
385  $igroup = array(); // used for item groups, see bug #0015978
386  $in_any_group = array();
387  foreach ($a_childs as $child) {
388  // item group: get childs
389  if ($child["type"] == "itgr") {
390  $g = $child["child"];
392  if ($items) {
393  // add item group ref id to item group block
394  $this->type_grps[$parent_type]["itgr"]["ref_ids"][] = $g;
395 
396  // #16697 - check item group permissions
397  $may_read = $ilAccess->checkAccess('read', '', $g);
398 
399  // see bug #0015978
400  if ($may_read) {
401  include_once("./Services/Container/classes/class.ilContainerSorting.php");
402  $items = ilContainerSorting::_getInstance($parent_obj_id)->sortSubItems('itgr', $child["obj_id"], $items);
403  }
404 
405  foreach ($items as $item) {
406  $in_any_group[] = $item["child"];
407 
408  if ($may_read) {
409  $igroup[$g][] = $item;
410  $group[$g][] = $item;
411  }
412  }
413  }
414  }
415  // type group
416  else {
417  $g = $objDefinition->getGroupOfObj($child["type"]);
418  if ($g == "") {
419  $g = $child["type"];
420  }
421  $group[$g][] = $child;
422  }
423  }
424 
425  $in_any_group = array_unique($in_any_group);
426 
427  // custom block sorting?
428  include_once("./Services/Container/classes/class.ilContainerSorting.php");
429  $sort = ilContainerSorting::_getInstance($parent_obj_id);
430  $block_pos = $sort->getBlockPositions();
431  if (is_array($block_pos) && count($block_pos) > 0) {
432  $tmp = $this->type_grps[$parent_type];
433 
434  $this->type_grps[$parent_type] = array();
435  foreach ($block_pos as $block_type) {
436  // type group
437  if (!is_numeric($block_type) &&
438  array_key_exists($block_type, $tmp)) {
439  $this->type_grps[$parent_type][$block_type] = $tmp[$block_type];
440  unset($tmp[$block_type]);
441  }
442  // item group
443  else {
444  // using item group ref id directly
445  $this->type_grps[$parent_type][$block_type] = array();
446  }
447  }
448 
449  // append missing
450  if (sizeof($tmp)) {
451  foreach ($tmp as $block_type => $grp) {
452  $this->type_grps[$parent_type][$block_type] = $grp;
453  }
454  }
455 
456  unset($tmp);
457  }
458 
459  $childs = array();
460  $done = array();
461 
462  foreach ($this->type_grps[$parent_type] as $t => $g) {
463  // type group
464  if (is_array($group[$t])) {
465  // see bug #0015978
466  // custom sorted igroups
467  if (is_array($igroup[$t])) {
468  foreach ($igroup[$t] as $k => $item) {
469  if (!in_array($item["child"], $done)) {
470  $childs[] = $item;
471  $done[] = $item["child"];
472  }
473  }
474  } else {
475  // do we have to sort this group??
476  include_once("./Services/Container/classes/class.ilContainer.php");
477  include_once("./Services/Container/classes/class.ilContainerSorting.php");
478  $sort = ilContainerSorting::_getInstance($parent_obj_id);
479  $group = $sort->sortItems($group);
480 
481  // need extra session sorting here
482  if ($t == "sess") {
483  }
484 
485  foreach ($group[$t] as $k => $item) {
486  if (!in_array($item["child"], $done) &&
487  !in_array($item["child"], $in_any_group)) { // #16697
488  $childs[] = $item;
489  $done[] = $item["child"];
490  }
491  }
492  }
493  }
494  // item groups (if not custom block sorting)
495  elseif ($t == "itgr" &&
496  is_array($g["ref_ids"])) {
497  foreach ($g["ref_ids"] as $ref_id) {
498  if (isset($group[$ref_id])) {
499  foreach ($group[$ref_id] as $k => $item) {
500  if (!in_array($item["child"], $done)) {
501  $childs[] = $item;
502  $done[] = $item["child"];
503  }
504  }
505  }
506  }
507  }
508  }
509 
510  return $childs;
511  }
512 
519  public function getChildsOfNode($a_parent_node_id)
520  {
522 
523  if (!$rbacsystem->checkAccess("read", $a_parent_node_id)) {
524  return array();
525  }
526 
527  $obj_id = ilObject::_lookupObjId($a_parent_node_id);
528  if (!ilConditionHandler::_checkAllConditionsOfTarget($a_parent_node_id, $obj_id)) {
529  return array();
530  }
531 
532  $childs = parent::getChildsOfNode($a_parent_node_id);
533 
534  foreach ($childs as $c) {
535  $this->parent_node_id[$c["child"]] = $a_parent_node_id;
536  $this->node_data[$c["child"]] = $c;
537  }
538 
539  return $childs;
540  }
541 
548  public function isNodeClickable($a_node)
549  {
551  $tree = $this->tree;
552  $ilDB = $this->db;
554  $ilAccess = $this->access;
555 
556  $obj_id = ilObject::_lookupObjId($a_node["child"]);
557  if (!ilConditionHandler::_checkAllConditionsOfTarget($a_node["child"], $obj_id)) {
558  return false;
559  }
560 
561  switch ($a_node["type"]) {
562  case 'tst':
563  if (!$rbacsystem->checkAccess("read", $a_node["child"])) {
564  return false;
565  }
566 
567  $query = sprintf("SELECT * FROM tst_tests WHERE obj_fi=%s", $obj_id);
568  $res = $ilDB->query($query);
569  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
570  return (bool) $row->complete;
571  }
572  return false;
573 
574  case 'svy':
575  if (!$rbacsystem->checkAccess("read", $a_node["child"])) {
576  return false;
577  }
578 
579  $query = sprintf("SELECT * FROM svy_svy WHERE obj_fi=%s", $obj_id);
580  $res = $ilDB->query($query);
581  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
582  return (bool) $row->complete;
583  }
584  return false;
585 
586  // media pools can only be edited
587  case "mep":
588  if ($rbacsystem->checkAccess("read", $a_node["child"])) {
589  return true;
590  } else {
591  return false;
592  }
593  break;
594  case 'grpr':
595  case 'crsr':
596  case 'catr':
597  include_once('./Services/ContainerReference/classes/class.ilContainerReferenceAccess.php');
598  return ilContainerReferenceAccess::_isAccessible($a_node["child"]);
599 
600  case 'prg':
601  return $rbacsystem->checkAccess("read", $a_node["child"]);
602 
603  // all other types are only clickable, if read permission is given
604  default:
605  if ($rbacsystem->checkAccess("read", $a_node["child"])) {
606  // check if lm is online
607  if ($a_node["type"] == "lm") {
608  include_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
609  $lm_obj = new ilObjLearningModule($a_node["child"]);
610  if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
611  return false;
612  }
613  }
614  // check if fblm is online
615  if ($a_node["type"] == "htlm") {
616  include_once("./Modules/HTMLLearningModule/classes/class.ilObjFileBasedLM.php");
617  $lm_obj = new ilObjFileBasedLM($a_node["child"]);
618  if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
619  return false;
620  }
621  }
622  // check if fblm is online
623  if ($a_node["type"] == "sahs") {
624  include_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
625  $lm_obj = new ilObjSAHSLearningModule($a_node["child"]);
626  if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
627  return false;
628  }
629  }
630  // check if glossary is online
631  if ($a_node["type"] == "glo") {
632  $obj_id = ilObject::_lookupObjectId($a_node["child"]);
633  include_once("./Modules/Glossary/classes/class.ilObjGlossary.php");
634  if ((!ilObjGlossary::_lookupOnline($obj_id)) &&
635  (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
636  return false;
637  }
638  }
639 
640  return true;
641  } else {
642  return false;
643  }
644  break;
645  }
646  }
647 }
getParentCourseOrGroup($node_id)
Get upper course or group.
$path
Definition: aliased.php:25
settings()
Definition: settings.php:2
Class ilObjLearningModule.
getNodeIconAlt($a_node)
Get node icon alt text.
global $DIC
Definition: saml.php:7
$_GET["client_id"]
__construct($a_parent_obj, $a_parent_cmd)
Constructor.
static _getItemsOfContainer($a_ref_id)
setSkipRootNode($a_val)
Set skip root node.
File Based Learning Module (HTML) object.
getChildsOfNode($a_parent_node_id)
Get childs of node.
setPathOpen($a_id)
Set node path to be opened.
isNodeHighlighted($a_node)
Is node highlighted?
getNodeHref($a_node)
Get href for node.
user()
Definition: user.php:4
setTypeWhiteList($a_val)
Set type white list.
static _lookupObjectId($a_ref_id)
lookup object id
global $ilCtrl
Definition: ilias.php:18
foreach($_POST as $key=> $value) $res
static _isAccessible($a_ref_id)
Check if target is accessible and not deleted.
static _lookupObjId($a_id)
Repository explorer GUI class.
static _appointmentToString($start, $end, $fulltime)
sortChilds($a_childs, $a_parent_node_id)
Sort childs.
$ilUser
Definition: imgupload.php:18
static _checkAllConditionsOfTarget($a_target_ref_id, $a_target_id, $a_target_type="", $a_usr_id=0)
checks wether all conditions of a target object are fulfilled
$query
$n
Definition: RandomTest.php:85
getNodeId($a_node)
Get id for node.
static _lookupType($a_id, $a_reference=false)
lookup object type
isNodeClickable($a_node)
Is node clickable?
$row
getNodeContent($a_node)
Get node content.
$white
Definition: example_030.php:84
global $ilSetting
Definition: privfeed.php:17
Explorer class that works on tree objects (Services/Tree)
static _lookupAppointment($a_obj_id)
lookup appointment
global $ilDB
setOrderField($a_val, $a_numeric=false)
Set order field.
static getItemsByItemGroup($a_item_group_ref_id)
Get materials of item group.
isNodeVisible($a_node)
Is node visible.
static _getInstance($a_obj_id)
get instance by obj_id
setChildLimit($a_val)
Set child limit.
Class ilObjSCORMLearningModule.
static _lookupOnline($a_id)
check wether content object is online