ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilRepositoryExplorerGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
28 {
29  protected ilSetting $settings;
33  protected ilDBInterface $db;
34  protected ilObjUser $user;
35  protected array $type_grps = [];
36  protected array $session_materials = [];
37  protected array $parent_node_id = [];
38  protected array $node_data = [];
40  protected int $cur_ref_id = 0;
41  protected int $top_node_id;
42 
46  public function __construct(
47  $a_parent_obj,
48  string $a_parent_cmd
49  ) {
51  global $DIC;
52 
53  $this->tree = $DIC->repositoryTree();
54  $this->settings = $DIC->settings();
55  $this->obj_definition = $DIC["objDefinition"];
56  $this->lng = $DIC->language();
57  $this->ctrl = $DIC->ctrl();
58  $this->access = $DIC->access();
59  $this->rbacsystem = $DIC->rbac()->system();
60  $this->db = $DIC->database();
61  $this->user = $DIC->user();
62  $tree = $DIC->repositoryTree();
63  $ilSetting = $DIC->settings();
64  $objDefinition = $DIC["objDefinition"];
65  $this->request = $DIC->repository()->internal()->gui()->standardRequest();
66 
67  $this->cur_ref_id = $this->request->getRefId();
68  $this->top_node_id = self::getTopNodeForRefId($this->cur_ref_id);
69 
70  parent::__construct("rep_exp", $a_parent_obj, $a_parent_cmd, $tree);
71 
72  $this->setSkipRootNode(false);
73  $this->setNodeOpen($this->tree->readRootId());
74  $this->setAjax(true);
75  $this->setOrderField("title");
76  if ($ilSetting->get("repository_tree_pres") == "" ||
77  ($ilSetting->get("rep_tree_limit_grp_crs") && $this->top_node_id === 0)) {
78  $this->setTypeWhiteList($objDefinition->getExplorerContainerTypes());
79  } elseif ($ilSetting->get("repository_tree_pres") === "all_types") {
80  $white = [];
81  foreach ($objDefinition->getSubObjectsRecursively("root") as $rtype) {
82  if (/* $rtype["name"] != "itgr" && */ !$objDefinition->isSideBlock($rtype["name"])) {
83  $white[] = $rtype["name"];
84  }
85  }
86  $this->setTypeWhiteList($white);
87  }
88 
89  if ($this->cur_ref_id > 0) {
90  $this->setPathOpen($this->cur_ref_id);
91  }
92 
93  $this->setChildLimit((int) $ilSetting->get("rep_tree_limit_number"));
94  }
95 
96  public function getRootNode()
97  {
98  if ($this->top_node_id > 0) {
99  $root_node = $this->getTree()->getNodeData($this->top_node_id);
100  } else {
101  $root_node = parent::getRootNode();
102  }
103  $this->node_data[$root_node["child"]] = $root_node;
104  return $root_node;
105  }
106 
107  public function getNodeContent($a_node): string
108  {
109  $lng = $this->lng;
110 
111  $title = $a_node["title"];
112 
113  if ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
114  if ($title === "ILIAS") {
115  $title = $lng->txt("repository");
116  }
117  } elseif ($a_node["type"] === "sess" &&
118  !trim($title)) {
119  // #14367 - see ilObjSessionListGUI
120  $app_info = ilSessionAppointment::_lookupAppointment($a_node["obj_id"]);
121  $title = ilSessionAppointment::_appointmentToString($app_info['start'], $app_info['end'], (bool) $app_info['fullday']);
122  }
123  return $title;
124  }
125 
126  public function getNodeIcon($a_node): string
127  {
128  $obj_id = ilObject::_lookupObjId((int) $a_node["child"]);
129  return ilObject::_getIcon($obj_id, "tiny", $a_node["type"]);
130  }
131 
132  public function getNodeIconAlt($a_node): string
133  {
134  $lng = $this->lng;
135 
136  if ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
137  $title = $a_node["title"];
138  if ($title === "ILIAS") {
139  $title = $lng->txt("repository");
140  }
141  return $title;
142  }
143 
144  $lng = $this->lng;
145  return $lng->txt("obj_" . $a_node["type"]) . ": " . $this->getNodeContent($a_node);
146  }
147 
148  public function isNodeHighlighted($a_node): bool
149  {
150  if ((int) $a_node["child"] === $this->cur_ref_id ||
151  ($this->cur_ref_id === 0 && (int) $a_node["child"] === (int) $this->getNodeId($this->getRootNode()))) {
152  return true;
153  }
154  return false;
155  }
156 
157  public function getNodeHref($a_node): string
158  {
159  $ilCtrl = $this->ctrl;
160 
161  switch ($a_node["type"]) {
162  case "cat":
163  case "root":
164  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
165  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
166  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->cur_ref_id);
167  return $link;
168 
169  case "grpr":
170  case "crsr":
171  case "prgr":
172  case "catr":
173  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
174  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
175  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->cur_ref_id);
176  return $link;
177 
178  case "grp":
179  $ilCtrl->setParameterByClass("ilobjgroupgui", "ref_id", $a_node["child"]);
180  $link = $ilCtrl->getLinkTargetByClass(["ilrepositorygui", "ilobjgroupgui"], "");
181  $ilCtrl->setParameterByClass("ilobjgroupgui", "ref_id", $this->cur_ref_id);
182  return $link;
183 
184  case "crs":
185  $ilCtrl->setParameterByClass("ilobjcoursegui", "ref_id", $a_node["child"]);
186  $link = $ilCtrl->getLinkTargetByClass(["ilrepositorygui", "ilobjcoursegui"], "view");
187  $ilCtrl->setParameterByClass("ilobjcoursegui", "ref_id", $this->cur_ref_id);
188  return $link;
189 
190  case 'rcrs':
191  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
192  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "infoScreen");
193  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->cur_ref_id);
194  return $link;
195 
196  case 'prg':
197  $ilCtrl->setParameterByClass("ilobjstudyprogrammegui", "ref_id", $a_node["child"]);
198  $link = $ilCtrl->getLinkTargetByClass(["ilrepositorygui", "ilobjstudyprogrammegui"], "view");
199  $ilCtrl->setParameterByClass("ilobjstudyprogrammegui", "ref_id", $this->cur_ref_id);
200  return $link;
201 
202  default:
203  return ilLink::_getStaticLink($a_node["child"], $a_node["type"], true);
204 
205  }
206  }
207 
208  public function isNodeVisible($a_node): bool
209  {
210  $ilAccess = $this->access;
211  $tree = $this->tree;
213 
214  if (!$ilAccess->checkAccess('visible', '', $a_node["child"])) {
215  return false;
216  }
217 
218  if ($ilSetting->get("repository_tree_pres") === "all_types") {
219  /*$container_parent_id = $tree->checkForParentType($a_node["child"], 'grp');
220  if (!$container_parent_id) {
221  $container_parent_id = $tree->checkForParentType($a_node["child"], 'crs');
222  }*/
223  // see #21215
224  $container_parent_id = $this->getParentCourseOrGroup($a_node["child"]);
225  if ($container_parent_id > 0) {
226  // do not display session materials for container course/group
227  if ($container_parent_id !== (int) $a_node["child"]) {
228  // get container event items only once
229  if (!isset($this->session_materials[$container_parent_id])) {
230  $this->session_materials[$container_parent_id] = ilEventItems::_getItemsOfContainer($container_parent_id);
231  }
232  if (in_array($a_node["child"], $this->session_materials[$container_parent_id])) {
233  return false;
234  }
235  }
236  }
237  }
238 
239  return true;
240  }
241 
242  protected function getParentCourseOrGroup(int $node_id): int
243  {
244  $current_node_id = $node_id;
245  while (isset($this->parent_node_id[$current_node_id])) {
246  $parent_node_id = $this->parent_node_id[$current_node_id];
247  if (isset($this->node_data[$parent_node_id]) && in_array($this->node_data[$parent_node_id]["type"], ["grp", "crs"])) {
248  return $parent_node_id;
249  }
250  $current_node_id = $parent_node_id;
251  }
252  return 0;
253  }
254 
255 
256  public function sortChilds(array $a_childs, $a_parent_node_id): array
257  {
258  $objDefinition = $this->obj_definition;
259  $ilAccess = $this->access;
260 
261  $parent_obj_id = ilObject::_lookupObjId((int) $a_parent_node_id);
262  if ($parent_obj_id > 0) {
263  $parent_type = ilObject::_lookupType($parent_obj_id);
264  } else {
265  $parent_type = "dummy";
266  $this->type_grps["dummy"] = ["root" => "dummy"];
267  }
268 
269  // alex: if this is not initialized, things are messed up
270  // see bug 0015978
271  $this->type_grps = [];
272 
273  $this->type_grps[$parent_type] =
274  $objDefinition::getGroupedRepositoryObjectTypes($parent_type);
275 
276  // #14465 - item groups
277  $group = [];
278  $igroup = []; // used for item groups, see bug #0015978
279  $in_any_group = [];
280  foreach ($a_childs as $child) {
281  // item group: get childs
282  if ($child["type"] === "itgr") {
283  $g = $child["child"];
285  if ($items) {
286  // add item group ref id to item group block
287  $this->type_grps[$parent_type]["itgr"]["ref_ids"][] = $g;
288 
289  // #16697 - check item group permissions
290  $may_read = $ilAccess->checkAccess('read', '', $g);
291 
292  // see bug #0015978
293  if ($may_read) {
294  $items = ilContainerSorting::_getInstance($parent_obj_id)->sortSubItems('itgr', $child["obj_id"], $items);
295  }
296 
297  foreach ($items as $item) {
298  $in_any_group[] = $item["child"];
299 
300  if ($may_read) {
301  $igroup[$g][] = $item;
302  $group[$g][] = $item;
303  }
304  }
305  }
306  }
307  // type group
308  else {
309  $g = $objDefinition->getGroupOfObj($child["type"]);
310  if ($g == "") {
311  $g = $child["type"];
312  }
313  $group[$g][] = $child;
314  }
315  }
316 
317  $in_any_group = array_unique($in_any_group);
318 
319  // custom block sorting?
320  $sort = ilContainerSorting::_getInstance($parent_obj_id);
321  $block_pos = $sort->getBlockPositions();
322  if (is_array($block_pos) && count($block_pos) > 0) {
323  $tmp = $this->type_grps[$parent_type];
324 
325  $this->type_grps[$parent_type] = [];
326  foreach ($block_pos as $block_type) {
327  // type group
328  if (!is_numeric($block_type) &&
329  array_key_exists($block_type, $tmp)) {
330  $this->type_grps[$parent_type][$block_type] = $tmp[$block_type];
331  unset($tmp[$block_type]);
332  }
333  // item group
334  else {
335  // using item group ref id directly
336  $this->type_grps[$parent_type][$block_type] = [];
337  }
338  }
339 
340  // append missing
341  if (count($tmp)) {
342  foreach ($tmp as $block_type => $grp) {
343  $this->type_grps[$parent_type][$block_type] = $grp;
344  }
345  }
346 
347  unset($tmp);
348  }
349 
350  $childs = [];
351  $done = [];
352 
353  foreach ($this->type_grps[$parent_type] as $t => $g) {
354  // type group
355  if (isset($group[$t]) && is_array($group[$t])) {
356  // see bug #0015978
357  // custom sorted igroups
358  if (isset($igroup[$t]) && is_array($igroup[$t])) {
359  foreach ($igroup[$t] as $k => $item) {
360  if (!in_array($item["child"], $done)) {
361  $childs[] = $item;
362  $done[] = $item["child"];
363  }
364  }
365  } else {
366  // do we have to sort this group??
367  $sort = ilContainerSorting::_getInstance($parent_obj_id);
368  $group = $sort->sortItems($group);
369 
370  // need extra session sorting here
371  if ($t === "sess") {
372  foreach ($group[$t] as $k => $v) {
373  $app_info = ilSessionAppointment::_lookupAppointment($v["obj_id"]);
374  $group[$t][$k]["start"] = $app_info["start"];
375  }
376  $group[$t] = ilArrayUtil::sortArray($group[$t], 'start', 'asc', true, false);
377  }
378 
379  foreach ($group[$t] as $k => $item) {
380  if (!in_array($item["child"], $done) &&
381  !in_array($item["child"], $in_any_group)) { // #16697
382  $childs[] = $item;
383  $done[] = $item["child"];
384  }
385  }
386  }
387  }
388  // item groups (if not custom block sorting)
389  elseif ($t === "itgr" &&
390  isset($g["ref_ids"]) &&
391  is_array($g["ref_ids"])) {
392  foreach ($g["ref_ids"] as $ref_id) {
393  if (isset($group[$ref_id])) {
394  foreach ($group[$ref_id] as $k => $item) {
395  if (!in_array($item["child"], $done)) {
396  $childs[] = $item;
397  $done[] = $item["child"];
398  }
399  }
400  }
401  }
402  }
403  }
404 
405  return $childs;
406  }
407 
412  public function nodeHasVisibleChilds($a_node): bool
413  {
414  if (!$this->obj_definition->isContainer($a_node["type"] ?? "")) {
415  return false;
416  }
417  return parent::nodeHasVisibleChilds($a_node);
418  }
419 
420  public function getChildsOfNode($a_parent_node_id): array
421  {
422  $rbacsystem = $this->rbacsystem;
423 
424  if (!$rbacsystem->checkAccess("read", $a_parent_node_id)) {
425  return [];
426  }
427 
428  $obj_id = ilObject::_lookupObjId($a_parent_node_id);
429  if (!ilConditionHandler::_checkAllConditionsOfTarget($a_parent_node_id, $obj_id)) {
430  return [];
431  }
432 
433  $childs = parent::getChildsOfNode($a_parent_node_id);
434 
435  foreach ($childs as $c) {
436  $this->parent_node_id[$c["child"]] = $a_parent_node_id;
437  $this->node_data[$c["child"]] = $c;
438  }
439 
440  return $childs;
441  }
442 
443  public function isNodeClickable($a_node): bool
444  {
445  $rbacsystem = $this->rbacsystem;
446  $ilDB = $this->db;
447 
448  $obj_id = ilObject::_lookupObjId($a_node["child"]);
449  if (
450  !ilConditionHandler::_checkAllConditionsOfTarget($a_node["child"], $obj_id)
451  && !$rbacsystem->checkAccess('write', $a_node["child"])
452  ) {
453  return false;
454  }
455 
456  switch ($a_node["type"]) {
457  case 'tst':
458  if (!$rbacsystem->checkAccess("read", $a_node["child"])) {
459  return false;
460  }
461 
462  $query = sprintf("SELECT * FROM tst_tests WHERE obj_fi=%s", $obj_id);
463  $res = $ilDB->query($query);
464  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
465  return (bool) $row->complete;
466  }
467  return false;
468 
469  case 'svy':
470  if (!$rbacsystem->checkAccess("read", $a_node["child"])) {
471  return false;
472  }
473 
474  $query = sprintf("SELECT * FROM svy_svy WHERE obj_fi=%s", $obj_id);
475  $res = $ilDB->query($query);
476  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
477  return (bool) $row->complete;
478  }
479  return false;
480 
481  // media pools can only be edited
482  case "mep":
483  if ($rbacsystem->checkAccess("read", $a_node["child"])) {
484  return true;
485  }
486  return false;
487  case 'grpr':
488  case 'crsr':
489  case 'catr':
490  return ilContainerReferenceAccess::_isAccessible($a_node["child"]);
491 
492  case 'prg':
493  return $rbacsystem->checkAccess("read", $a_node["child"]);
494 
495  case 'crs':
496  case 'grp':
497  return $rbacsystem->checkAccess("read", $a_node["child"]) ||
498  $rbacsystem->checkAccess("join", $a_node["child"]);
499 
500  // all other types are only clickable, if read permission is given
501  default:
502  if ($rbacsystem->checkAccess("read", $a_node["child"])) {
503  // check if lm is online
504  if ($a_node["type"] === "lm") {
505  $lm_obj = new ilObjLearningModule($a_node["child"]);
506  if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
507  return false;
508  }
509  }
510  // check if fblm is online
511  if ($a_node["type"] === "htlm") {
512  $lm_obj = new ilObjFileBasedLM($a_node["child"]);
513  if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
514  return false;
515  }
516  }
517  // check if fblm is online
518  if ($a_node["type"] === "sahs") {
519  $lm_obj = new ilObjSAHSLearningModule($a_node["child"]);
520  if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
521  return false;
522  }
523  }
524  // check if glossary is online
525  if ($a_node["type"] === "glo") {
526  $obj_id = ilObject::_lookupObjectId($a_node["child"]);
527  if ((!ilObjGlossary::_lookupOnline($obj_id)) &&
528  (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
529  return false;
530  }
531  }
532 
533  return true;
534  }
535  return false;
536  }
537  }
538 
539  public static function getTopNodeForRefId(int $ref_id): int
540  {
541  global $DIC;
542 
543  $setting = $DIC->settings();
544  $tree = $DIC->repositoryTree();
545 
546  $top_node = 0;
547  if ($ref_id > 0 && $setting->get("rep_tree_limit_grp_crs")) {
548  $path = $tree->getPathId($ref_id);
549  foreach ($path as $n) {
550  if ($top_node > 0) {
551  break;
552  }
553  if (in_array(
555  ["crs", "grp"]
556  )) {
557  $top_node = $n;
558  }
559  }
560  }
561  return $top_node;
562  }
563 }
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: cli.php:38
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _lookupOnline(int $a_id)
setTypeWhiteList(array $a_val)
Set type white list.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setParameterByClass(string $a_class, string $a_parameter, $a_value)
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 _getItemsOfContainer(int $a_ref_id)
$path
Definition: ltiservices.php:32
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
checkAccess(string $a_operations, int $a_ref_id, string $a_type="")
checkAccess represents the main method of the RBAC-system in ILIAS3 developers want to use With this ...
parses the objects.xml it handles the xml-description of all ilias objects
static _lookupAppointment(int $a_obj_id)
$ref_id
Definition: ltiauth.php:67
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Repository explorer GUI class.
static _lookupObjectId(int $ref_id)
$query
getNodeId($a_node)
Get id for node.
static getItemsByItemGroup(int $item_group_ref_id)
Get materials of item group.
static _appointmentToString(int $start, int $end, bool $fulltime)
getPathId(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
static _checkAllConditionsOfTarget(int $a_target_ref_id, int $a_target_id, string $a_target_type="", int $a_usr_id=0)
checks wether all conditions of a target object are fulfilled
global $ilSetting
Definition: privfeed.php:17
Explorer class that works on tree objects (Services/Tree)
__construct(Container $dic, ilPlugin $plugin)
static _getInstance(int $a_obj_id)
setOrderField(string $a_val, bool $a_numeric=false)
static _isAccessible(int $a_ref_id)
Check if target is accessible and not deleted.
static _lookupType(int $id, bool $reference=false)
sortChilds(array $a_childs, $a_parent_node_id)
Class ilObjSCORMLearningModule.
__construct(string $a_expl_id, $a_parent_obj, string $a_parent_cmd, ilTree $a_tree, string $a_node_parameter_name="node_id")
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)