ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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  public function isNodeVisible($a_node): bool
208  {
209  $ilAccess = $this->access;
210  $tree = $this->tree;
212 
213  if (!$ilAccess->checkAccess('visible', '', $a_node["child"])) {
214  return false;
215  }
216 
217  if ($ilSetting->get("repository_tree_pres") === "all_types") {
218  /*$container_parent_id = $tree->checkForParentType($a_node["child"], 'grp');
219  if (!$container_parent_id) {
220  $container_parent_id = $tree->checkForParentType($a_node["child"], 'crs');
221  }*/
222  // see #21215
223  $container_parent_id = $this->getParentCourseOrGroup($a_node["child"]);
224  if ($container_parent_id > 0) {
225  // do not display session materials for container course/group
226  if ($container_parent_id !== (int) $a_node["child"]) {
227  // get container event items only once
228  if (!isset($this->session_materials[$container_parent_id])) {
229  $this->session_materials[$container_parent_id] = ilEventItems::_getItemsOfContainer($container_parent_id);
230  }
231  if (in_array($a_node["child"], $this->session_materials[$container_parent_id])) {
232  return false;
233  }
234  }
235  }
236  }
237 
238  return true;
239  }
240 
241  protected function getParentCourseOrGroup(int $node_id): int
242  {
243  $current_node_id = $node_id;
244  while (isset($this->parent_node_id[$current_node_id])) {
245  $parent_node_id = $this->parent_node_id[$current_node_id];
246  if (isset($this->node_data[$parent_node_id]) && in_array($this->node_data[$parent_node_id]["type"], ["grp", "crs"])) {
247  return $parent_node_id;
248  }
249  $current_node_id = $parent_node_id;
250  }
251  return 0;
252  }
253 
254 
255  public function sortChilds(array $a_childs, $a_parent_node_id): array
256  {
257  $objDefinition = $this->obj_definition;
258  $ilAccess = $this->access;
259 
260  $parent_obj_id = ilObject::_lookupObjId((int) $a_parent_node_id);
261  if ($parent_obj_id > 0) {
262  $parent_type = ilObject::_lookupType($parent_obj_id);
263  } else {
264  $parent_type = "dummy";
265  $this->type_grps["dummy"] = ["root" => "dummy"];
266  }
267 
268  // alex: if this is not initialized, things are messed up
269  // see bug 0015978
270  $this->type_grps = [];
271 
272  $this->type_grps[$parent_type] =
273  $objDefinition::getGroupedRepositoryObjectTypes($parent_type);
274 
275  // #14465 - item groups
276  $group = [];
277  $igroup = []; // used for item groups, see bug #0015978
278  $in_any_group = [];
279  foreach ($a_childs as $child) {
280  // item group: get childs
281  if ($child["type"] === "itgr") {
282  $g = $child["child"];
284  if ($items) {
285  // add item group ref id to item group block
286  $this->type_grps[$parent_type]["itgr"]["ref_ids"][] = $g;
287 
288  // #16697 - check item group permissions
289  $may_read = $ilAccess->checkAccess('read', '', $g);
290 
291  // see bug #0015978
292  if ($may_read) {
293  $items = ilContainerSorting::_getInstance($parent_obj_id)->sortSubItems('itgr', $child["obj_id"], $items);
294  }
295 
296  foreach ($items as $item) {
297  $in_any_group[] = $item["child"];
298 
299  if ($may_read) {
300  $igroup[$g][] = $item;
301  $group[$g][] = $item;
302  }
303  }
304  }
305  }
306  // type group
307  else {
308  $g = $objDefinition->getGroupOfObj($child["type"]);
309  if ($g == "") {
310  $g = $child["type"];
311  }
312  $group[$g][] = $child;
313  }
314  }
315 
316  $in_any_group = array_unique($in_any_group);
317 
318  // custom block sorting?
319  $sort = ilContainerSorting::_getInstance($parent_obj_id);
320  $block_pos = $sort->getBlockPositions();
321  if (is_array($block_pos) && count($block_pos) > 0) {
322  $tmp = $this->type_grps[$parent_type];
323 
324  $this->type_grps[$parent_type] = [];
325  foreach ($block_pos as $block_type) {
326  // type group
327  if (!is_numeric($block_type) &&
328  array_key_exists($block_type, $tmp)) {
329  $this->type_grps[$parent_type][$block_type] = $tmp[$block_type];
330  unset($tmp[$block_type]);
331  }
332  // item group
333  else {
334  // using item group ref id directly
335  $this->type_grps[$parent_type][$block_type] = [];
336  }
337  }
338 
339  // append missing
340  if (count($tmp)) {
341  foreach ($tmp as $block_type => $grp) {
342  $this->type_grps[$parent_type][$block_type] = $grp;
343  }
344  }
345 
346  unset($tmp);
347  }
348 
349  $childs = [];
350  $done = [];
351 
352  foreach ($this->type_grps[$parent_type] as $t => $g) {
353  // type group
354  if (isset($group[$t]) && is_array($group[$t])) {
355  // see bug #0015978
356  // custom sorted igroups
357  if (isset($igroup[$t]) && is_array($igroup[$t])) {
358  foreach ($igroup[$t] as $k => $item) {
359  if (!in_array($item["child"], $done)) {
360  $childs[] = $item;
361  $done[] = $item["child"];
362  }
363  }
364  } else {
365  // do we have to sort this group??
366  $sort = ilContainerSorting::_getInstance($parent_obj_id);
367  $group = $sort->sortItems($group);
368 
369  // need extra session sorting here
370  if ($t === "sess") {
371  foreach ($group[$t] as $k => $v) {
372  $app_info = ilSessionAppointment::_lookupAppointment($v["obj_id"]);
373  $group[$t][$k]["start"] = $app_info["start"];
374  }
375  $group[$t] = ilArrayUtil::sortArray($group[$t], 'start', 'asc', true, false);
376  }
377 
378  foreach ($group[$t] as $k => $item) {
379  if (!in_array($item["child"], $done) &&
380  !in_array($item["child"], $in_any_group)) { // #16697
381  $childs[] = $item;
382  $done[] = $item["child"];
383  }
384  }
385  }
386  }
387  // item groups (if not custom block sorting)
388  elseif ($t === "itgr" &&
389  isset($g["ref_ids"]) &&
390  is_array($g["ref_ids"])) {
391  foreach ($g["ref_ids"] as $ref_id) {
392  if (isset($group[$ref_id])) {
393  foreach ($group[$ref_id] as $k => $item) {
394  if (!in_array($item["child"], $done)) {
395  $childs[] = $item;
396  $done[] = $item["child"];
397  }
398  }
399  }
400  }
401  }
402  }
403 
404  return $childs;
405  }
406 
411  public function nodeHasVisibleChilds($a_node): bool
412  {
413  if (!$this->obj_definition->isContainer($a_node["type"] ?? "")) {
414  return false;
415  }
416  return parent::nodeHasVisibleChilds($a_node);
417  }
418 
419  public function getChildsOfNode($a_parent_node_id): array
420  {
421  $rbacsystem = $this->rbacsystem;
422 
423  if (!$rbacsystem->checkAccess("read", $a_parent_node_id)) {
424  return [];
425  }
426 
427  $obj_id = ilObject::_lookupObjId($a_parent_node_id);
428  if (!ilConditionHandler::_checkAllConditionsOfTarget($a_parent_node_id, $obj_id)) {
429  return [];
430  }
431 
432  $childs = parent::getChildsOfNode($a_parent_node_id);
433 
434  foreach ($childs as $c) {
435  $this->parent_node_id[$c["child"]] = $a_parent_node_id;
436  $this->node_data[$c["child"]] = $c;
437  }
438 
439  return $childs;
440  }
441 
442  public function isNodeClickable($a_node): bool
443  {
444  return
445  $this->access->checkAccess("read", "", (int) $a_node["child"]) ||
446  $this->access->checkAccess("join", "", (int) $a_node["child"]);
447  }
448 
449  public static function getTopNodeForRefId(int $ref_id): int
450  {
451  global $DIC;
452 
453  $setting = $DIC->settings();
454  $tree = $DIC->repositoryTree();
455 
456  $top_node = 0;
457  if ($ref_id > 0 && $setting->get("rep_tree_limit_grp_crs")) {
458  $path = $tree->getPathId($ref_id);
459  foreach ($path as $n) {
460  if ($top_node > 0) {
461  break;
462  }
463  if (in_array(
465  ["crs", "grp"]
466  )) {
467  $top_node = $n;
468  }
469  }
470  }
471  return $top_node;
472  }
473 }
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...
setTypeWhiteList(array $a_val)
Set type white list.
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) ...
$c
Definition: deliver.php:25
static _getItemsOfContainer(int $a_ref_id)
$path
Definition: ltiservices.php:29
static _lookupObjId(int $ref_id)
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 ...
static _lookupAppointment(int $a_obj_id)
$ref_id
Definition: ltiauth.php:65
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Repository explorer GUI class.
global $DIC
Definition: shib_login.php:26
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:31
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 _lookupType(int $id, bool $reference=false)
sortChilds(array $a_childs, $a_parent_node_id)
__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)