ILIAS  release_7 Revision v7.30-3-g800a261c036
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  $this->top_node_id = self::getTopNodeForRefId($this->cur_ref_id);
86 
87  parent::__construct("rep_exp", $a_parent_obj, $a_parent_cmd, $tree);
88 
89  $this->setSkipRootNode(false);
90  $this->setNodeOpen($this->tree->readRootId());
91  $this->setAjax(true);
92  $this->setOrderField("title");
93  if ($ilSetting->get("repository_tree_pres") == "" ||
94  ($ilSetting->get("rep_tree_limit_grp_crs") && $this->top_node_id == 0)) {
95  $this->setTypeWhiteList($objDefinition->getExplorerContainerTypes());
96  } elseif ($ilSetting->get("repository_tree_pres") == "all_types") {
97  $white = array();
98  foreach ($objDefinition->getSubObjectsRecursively("root") as $rtype) {
99  if (/* $rtype["name"] != "itgr" && */ !$objDefinition->isSideBlock($rtype["name"])) {
100  $white[] = $rtype["name"];
101  }
102  }
103  $this->setTypeWhiteList($white);
104  }
105  if ((int) $_GET["ref_id"] > 0) {
106  $this->setPathOpen((int) $_GET["ref_id"]);
107  }
108 
109  $this->setChildLimit((int) $ilSetting->get("rep_tree_limit_number"));
110  }
111 
118  public function getRootNode()
119  {
120  if ($this->top_node_id > 0) {
121  $root_node = $this->getTree()->getNodeData($this->top_node_id);
122  } else {
123  $root_node = parent::getRootNode();
124  }
125  $this->node_data[$root_node["child"]] = $root_node;
126  return $root_node;
127  }
128 
135  public function getNodeContent($a_node)
136  {
137  $lng = $this->lng;
138 
139  $title = $a_node["title"];
140 
141  if ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
142  if ($title == "ILIAS") {
143  $title = $lng->txt("repository");
144  }
145  } elseif ($a_node["type"] == "sess" &&
146  !trim($title)) {
147  // #14367 - see ilObjSessionListGUI
148  include_once('./Modules/Session/classes/class.ilSessionAppointment.php');
149  $app_info = ilSessionAppointment::_lookupAppointment($a_node["obj_id"]);
150  $title = ilSessionAppointment::_appointmentToString($app_info['start'], $app_info['end'], $app_info['fullday']);
151  }
152  return $title;
153  }
154 
161  public function getNodeIcon($a_node)
162  {
163  $obj_id = ilObject::_lookupObjId($a_node["child"]);
164  return ilObject::_getIcon($obj_id, "tiny", $a_node["type"]);
165  }
166 
173  public function getNodeIconAlt($a_node)
174  {
175  $lng = $this->lng;
176 
177  if ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
178  $title = $a_node["title"];
179  if ($title == "ILIAS") {
180  $title = $lng->txt("repository");
181  }
182  return $title;
183  }
184 
185  $lng = $this->lng;
186  return $lng->txt("obj_" . $a_node["type"]) . ": " . $this->getNodeContent($a_node);
187  }
188 
195  public function isNodeHighlighted($a_node)
196  {
197  if ($a_node["child"] == $_GET["ref_id"] ||
198  ($_GET["ref_id"] == "" && $a_node["child"] == $this->getNodeId($this->getRootNode()))) {
199  return true;
200  }
201  return false;
202  }
203 
210  public function getNodeHref($a_node)
211  {
212  $ilCtrl = $this->ctrl;
213 
214  switch ($a_node["type"]) {
215  case "root":
216  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
217  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
218  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
219  return $link;
220 
221  case "cat":
222  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
223  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
224  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
225  return $link;
226 
227  case "catr":
228  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
229  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
230  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
231  return $link;
232 
233  case "grp":
234  $ilCtrl->setParameterByClass("ilobjgroupgui", "ref_id", $a_node["child"]);
235  $link = $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjgroupgui"), "");
236  $ilCtrl->setParameterByClass("ilobjgroupgui", "ref_id", $_GET["ref_id"]);
237  return $link;
238 
239  case "grpr":
240  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
241  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
242  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
243  return $link;
244 
245  case "crs":
246  $ilCtrl->setParameterByClass("ilobjcoursegui", "ref_id", $a_node["child"]);
247  $link = $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjcoursegui"), "view");
248  $ilCtrl->setParameterByClass("ilobjcoursegui", "ref_id", $_GET["ref_id"]);
249  return $link;
250 
251  case "crsr":
252  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
253  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
254  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
255  return $link;
256 
257  case 'rcrs':
258  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
259  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "infoScreen");
260  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
261  return $link;
262 
263  case 'prg':
264  $ilCtrl->setParameterByClass("ilobjstudyprogrammegui", "ref_id", $a_node["child"]);
265  $link = $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjstudyprogrammegui"), "view");
266  $ilCtrl->setParameterByClass("ilobjstudyprogrammegui", "ref_id", $_GET["ref_id"]);
267  return $link;
268  case "prgr":
269  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
270  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
271  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
272  return $link;
273 
274  default:
275  include_once('./Services/Link/classes/class.ilLink.php');
276  return ilLink::_getStaticLink($a_node["child"], $a_node["type"], true);
277 
278  }
279  }
280 
287  public function isNodeVisible($a_node)
288  {
289  $ilAccess = $this->access;
290  $tree = $this->tree;
292 
293  if (!$ilAccess->checkAccess('visible', '', $a_node["child"])) {
294  return false;
295  }
296 
297  if ($ilSetting->get("repository_tree_pres") == "all_types") {
298  /*$container_parent_id = $tree->checkForParentType($a_node["child"], 'grp');
299  if (!$container_parent_id) {
300  $container_parent_id = $tree->checkForParentType($a_node["child"], 'crs');
301  }*/
302  // see #21215
303  $container_parent_id = $this->getParentCourseOrGroup($a_node["child"]);
304  if ($container_parent_id > 0) {
305  // do not display session materials for container course/group
306  if ($container_parent_id != $a_node["child"]) {
307  // get container event items only once
308  if (!isset($this->session_materials[$container_parent_id])) {
309  include_once './Modules/Session/classes/class.ilEventItems.php';
310  $this->session_materials[$container_parent_id] = ilEventItems::_getItemsOfContainer($container_parent_id);
311  }
312  if (in_array($a_node["child"], $this->session_materials[$container_parent_id])) {
313  return false;
314  }
315  }
316  }
317  }
318 
319  return true;
320  }
321 
328  protected function getParentCourseOrGroup($node_id)
329  {
330  $current_node_id = $node_id;
331  while (isset($this->parent_node_id[$current_node_id])) {
332  $parent_node_id = $this->parent_node_id[$current_node_id];
333  if (isset($this->node_data[$parent_node_id]) && in_array($this->node_data[$parent_node_id]["type"], ["grp", "crs"])) {
334  return $parent_node_id;
335  }
336  $current_node_id = $parent_node_id;
337  }
338  return 0;
339  }
340 
341 
350  public function sortChilds($a_childs, $a_parent_node_id)
351  {
352  $objDefinition = $this->obj_definition;
353  $ilAccess = $this->access;
354 
355  $parent_obj_id = ilObject::_lookupObjId($a_parent_node_id);
356  if ($parent_obj_id > 0) {
357  $parent_type = ilObject::_lookupType($parent_obj_id);
358  } else {
359  $parent_type = "dummy";
360  $this->type_grps["dummy"] = array("root" => "dummy");
361  }
362 
363  // alex: if this is not initialized, things are messed up
364  // see bug 0015978
365  $this->type_grps = array();
366 
367  if (empty($this->type_grps[$parent_type])) {
368  $this->type_grps[$parent_type] =
369  $objDefinition->getGroupedRepositoryObjectTypes($parent_type);
370  }
371 
372  // #14465 - item groups
373  include_once('./Services/Object/classes/class.ilObjectActivation.php');
374  $group = array();
375  $igroup = array(); // used for item groups, see bug #0015978
376  $in_any_group = array();
377  foreach ($a_childs as $child) {
378  // item group: get childs
379  if ($child["type"] == "itgr") {
380  $g = $child["child"];
382  if ($items) {
383  // add item group ref id to item group block
384  $this->type_grps[$parent_type]["itgr"]["ref_ids"][] = $g;
385 
386  // #16697 - check item group permissions
387  $may_read = $ilAccess->checkAccess('read', '', $g);
388 
389  // see bug #0015978
390  if ($may_read) {
391  include_once("./Services/Container/classes/class.ilContainerSorting.php");
392  $items = ilContainerSorting::_getInstance($parent_obj_id)->sortSubItems('itgr', $child["obj_id"], $items);
393  }
394 
395  foreach ($items as $item) {
396  $in_any_group[] = $item["child"];
397 
398  if ($may_read) {
399  $igroup[$g][] = $item;
400  $group[$g][] = $item;
401  }
402  }
403  }
404  }
405  // type group
406  else {
407  $g = $objDefinition->getGroupOfObj($child["type"]);
408  if ($g == "") {
409  $g = $child["type"];
410  }
411  $group[$g][] = $child;
412  }
413  }
414 
415  $in_any_group = array_unique($in_any_group);
416 
417  // custom block sorting?
418  include_once("./Services/Container/classes/class.ilContainerSorting.php");
419  $sort = ilContainerSorting::_getInstance($parent_obj_id);
420  $block_pos = $sort->getBlockPositions();
421  if (is_array($block_pos) && count($block_pos) > 0) {
422  $tmp = $this->type_grps[$parent_type];
423 
424  $this->type_grps[$parent_type] = array();
425  foreach ($block_pos as $block_type) {
426  // type group
427  if (!is_numeric($block_type) &&
428  array_key_exists($block_type, $tmp)) {
429  $this->type_grps[$parent_type][$block_type] = $tmp[$block_type];
430  unset($tmp[$block_type]);
431  }
432  // item group
433  else {
434  // using item group ref id directly
435  $this->type_grps[$parent_type][$block_type] = array();
436  }
437  }
438 
439  // append missing
440  if (sizeof($tmp)) {
441  foreach ($tmp as $block_type => $grp) {
442  $this->type_grps[$parent_type][$block_type] = $grp;
443  }
444  }
445 
446  unset($tmp);
447  }
448 
449  $childs = array();
450  $done = array();
451 
452  foreach ($this->type_grps[$parent_type] as $t => $g) {
453  // type group
454  if (is_array($group[$t])) {
455  // see bug #0015978
456  // custom sorted igroups
457  if (is_array($igroup[$t])) {
458  foreach ($igroup[$t] as $k => $item) {
459  if (!in_array($item["child"], $done)) {
460  $childs[] = $item;
461  $done[] = $item["child"];
462  }
463  }
464  } else {
465  // do we have to sort this group??
466  include_once("./Services/Container/classes/class.ilContainer.php");
467  include_once("./Services/Container/classes/class.ilContainerSorting.php");
468  $sort = ilContainerSorting::_getInstance($parent_obj_id);
469  $group = $sort->sortItems($group);
470 
471  // need extra session sorting here
472  if ($t == "sess") {
473  foreach ($group[$t] as $k => $v) {
474  $app_info = ilSessionAppointment::_lookupAppointment($v["obj_id"]);
475  $group[$t][$k]["start"] = $app_info["start"];
476  }
477  $group[$t] = ilUtil::sortArray($group[$t], 'start', 'asc', true, false);
478  }
479 
480  foreach ($group[$t] as $k => $item) {
481  if (!in_array($item["child"], $done) &&
482  !in_array($item["child"], $in_any_group)) { // #16697
483  $childs[] = $item;
484  $done[] = $item["child"];
485  }
486  }
487  }
488  }
489  // item groups (if not custom block sorting)
490  elseif ($t == "itgr" &&
491  is_array($g["ref_ids"])) {
492  foreach ($g["ref_ids"] as $ref_id) {
493  if (isset($group[$ref_id])) {
494  foreach ($group[$ref_id] as $k => $item) {
495  if (!in_array($item["child"], $done)) {
496  $childs[] = $item;
497  $done[] = $item["child"];
498  }
499  }
500  }
501  }
502  }
503  }
504 
505  return $childs;
506  }
507 
508  public function nodeHasVisibleChilds($a_node)
509  {
510  if (!$this->obj_definition->isContainer($a_node["type"] ?? "")) {
511  return false;
512  }
513  return parent::nodeHasVisibleChilds($a_node);
514  }
515 
522  public function getChildsOfNode($a_parent_node_id)
523  {
525 
526  if (!$rbacsystem->checkAccess("read", $a_parent_node_id)) {
527  return array();
528  }
529 
530  $obj_id = ilObject::_lookupObjId($a_parent_node_id);
531  if (!ilConditionHandler::_checkAllConditionsOfTarget($a_parent_node_id, $obj_id)) {
532  return array();
533  }
534 
535  $childs = parent::getChildsOfNode($a_parent_node_id);
536 
537  foreach ($childs as $c) {
538  $this->parent_node_id[$c["child"]] = $a_parent_node_id;
539  $this->node_data[$c["child"]] = $c;
540  }
541 
542  return $childs;
543  }
544 
551  public function isNodeClickable($a_node)
552  {
554  $tree = $this->tree;
555  $ilDB = $this->db;
557  $ilAccess = $this->access;
558 
559  $obj_id = ilObject::_lookupObjId($a_node["child"]);
560  if (
561  !ilConditionHandler::_checkAllConditionsOfTarget($a_node["child"], $obj_id)
562  && !$rbacsystem->checkAccess('write', $a_node["child"])
563  ) {
564  return false;
565  }
566 
567  switch ($a_node["type"]) {
568  case 'tst':
569  if (!$rbacsystem->checkAccess("read", $a_node["child"])) {
570  return false;
571  }
572 
573  $query = sprintf("SELECT * FROM tst_tests WHERE obj_fi=%s", $obj_id);
574  $res = $ilDB->query($query);
575  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
576  return (bool) $row->complete;
577  }
578  return false;
579 
580  case 'svy':
581  if (!$rbacsystem->checkAccess("read", $a_node["child"])) {
582  return false;
583  }
584 
585  $query = sprintf("SELECT * FROM svy_svy WHERE obj_fi=%s", $obj_id);
586  $res = $ilDB->query($query);
587  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
588  return (bool) $row->complete;
589  }
590  return false;
591 
592  // media pools can only be edited
593  case "mep":
594  if ($rbacsystem->checkAccess("read", $a_node["child"])) {
595  return true;
596  } else {
597  return false;
598  }
599  break;
600  case 'grpr':
601  case 'crsr':
602  case 'catr':
603  include_once('./Services/ContainerReference/classes/class.ilContainerReferenceAccess.php');
604  return ilContainerReferenceAccess::_isAccessible($a_node["child"]);
605 
606  case 'prg':
607  return $rbacsystem->checkAccess("read", $a_node["child"]);
608 
609  // all other types are only clickable, if read permission is given
610  default:
611  if ($rbacsystem->checkAccess("read", $a_node["child"])) {
612  // check if lm is online
613  if ($a_node["type"] == "lm") {
614  include_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
615  $lm_obj = new ilObjLearningModule($a_node["child"]);
616  if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
617  return false;
618  }
619  }
620  // check if fblm is online
621  if ($a_node["type"] == "htlm") {
622  include_once("./Modules/HTMLLearningModule/classes/class.ilObjFileBasedLM.php");
623  $lm_obj = new ilObjFileBasedLM($a_node["child"]);
624  if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
625  return false;
626  }
627  }
628  // check if fblm is online
629  if ($a_node["type"] == "sahs") {
630  include_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
631  $lm_obj = new ilObjSAHSLearningModule($a_node["child"]);
632  if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
633  return false;
634  }
635  }
636  // check if glossary is online
637  if ($a_node["type"] == "glo") {
638  $obj_id = ilObject::_lookupObjectId($a_node["child"]);
639  if ((!ilObjGlossary::_lookupOnline($obj_id)) &&
640  (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
641  return false;
642  }
643  }
644 
645  return true;
646  } else {
647  return false;
648  }
649  break;
650  }
651  }
652 
653  public static function getTopNodeForRefId(int $ref_id) : int
654  {
655  global $DIC;
656 
657  $setting = $DIC->settings();
658  $tree = $DIC->repositoryTree();
659 
660  $top_node = 0;
661  if ($setting->get("rep_tree_limit_grp_crs") && $ref_id > 0) {
662  $path = $tree->getPathId($ref_id);
663  foreach ($path as $n) {
664  if ($top_node > 0) {
665  break;
666  }
667  if (in_array(
669  array("crs", "grp")
670  )) {
671  $top_node = $n;
672  }
673  }
674  }
675  return $top_node;
676  }
677 }
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
getParentCourseOrGroup($node_id)
Get upper course or group.
settings()
Definition: settings.php:2
Class ilObjLearningModule.
$c
Definition: cli.php:37
getNodeIconAlt($a_node)
Get node icon alt text.
$_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.
setNodeOpen($a_id)
Set node to be opened (additional custom opened node, not standard expand behaviour) ...
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
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.
global $DIC
Definition: goto.php:24
static _appointmentToString($start, $end, $fulltime)
sortChilds($a_childs, $a_parent_node_id)
Sort childs.
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?
getNodeContent($a_node)
Get node content.
global $ilSetting
Definition: privfeed.php:17
Explorer class that works on tree objects (Services/Tree)
__construct(Container $dic, ilPlugin $plugin)
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
$ilUser
Definition: imgupload.php:18
setChildLimit($a_val)
Set child limit.
Class ilObjSCORMLearningModule.
static _lookupOnline($a_id)
check wether content object is online