ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
4include_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 {
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
153 return $title;
154 }
155
162 public function getNodeIcon($a_node)
163 {
164 $obj_id = ilObject::_lookupObjId($a_node["child"]);
165 return ilObject::_getIcon($obj_id, "tiny", $a_node["type"]);
166 }
167
174 public function getNodeIconAlt($a_node)
175 {
177
178 if ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
179 $title = $a_node["title"];
180 if ($title == "ILIAS") {
181 $title = $lng->txt("repository");
182 }
183 return $title;
184 }
185
187 return $lng->txt("obj_" . $a_node["type"]) . ": " . $this->getNodeContent($a_node);
188 }
189
196 public function isNodeHighlighted($a_node)
197 {
198 if ($a_node["child"] == $_GET["ref_id"] ||
199 ($_GET["ref_id"] == "" && $a_node["child"] == $this->getNodeId($this->getRootNode()))) {
200 return true;
201 }
202 return false;
203 }
204
211 public function getNodeHref($a_node)
212 {
214
215 switch ($a_node["type"]) {
216 case "root":
217 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
218 $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
219 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
220 return $link;
221
222 case "cat":
223 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
224 $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
225 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
226 return $link;
227
228 case "catr":
229 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
230 $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
231 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
232 return $link;
233
234 case "grp":
235 $ilCtrl->setParameterByClass("ilobjgroupgui", "ref_id", $a_node["child"]);
236 $link = $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjgroupgui"), "");
237 $ilCtrl->setParameterByClass("ilobjgroupgui", "ref_id", $_GET["ref_id"]);
238 return $link;
239
240 case "grpr":
241 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
242 $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
243 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
244 return $link;
245
246 case "crs":
247 $ilCtrl->setParameterByClass("ilobjcoursegui", "ref_id", $a_node["child"]);
248 $link = $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjcoursegui"), "view");
249 $ilCtrl->setParameterByClass("ilobjcoursegui", "ref_id", $_GET["ref_id"]);
250 return $link;
251
252 case "crsr":
253 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
254 $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
255 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
256 return $link;
257
258 case 'rcrs':
259 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
260 $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "infoScreen");
261 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
262 return $link;
263
264 case 'prg':
265 $ilCtrl->setParameterByClass("ilobjstudyprogrammegui", "ref_id", $a_node["child"]);
266 $link = $ilCtrl->getLinkTargetByClass(array("ilrepositorygui", "ilobjstudyprogrammegui"), "view");
267 $ilCtrl->setParameterByClass("ilobjstudyprogrammegui", "ref_id", $_GET["ref_id"]);
268 return $link;
269 case "prgr":
270 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node["child"]);
271 $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
272 $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
273 return $link;
274
275 default:
276 include_once('./Services/Link/classes/class.ilLink.php');
277 return ilLink::_getStaticLink($a_node["child"], $a_node["type"], true);
278
279 }
280 }
281
288 public function isNodeVisible($a_node)
289 {
290 $ilAccess = $this->access;
293
294 if (!$ilAccess->checkAccess('visible', '', $a_node["child"])) {
295 return false;
296 }
297
298 if ($ilSetting->get("repository_tree_pres") == "all_types") {
299 /*$container_parent_id = $tree->checkForParentType($a_node["child"], 'grp');
300 if (!$container_parent_id) {
301 $container_parent_id = $tree->checkForParentType($a_node["child"], 'crs');
302 }*/
303 // see #21215
304 $container_parent_id = $this->getParentCourseOrGroup($a_node["child"]);
305 if ($container_parent_id > 0) {
306 // do not display session materials for container course/group
307 if ($container_parent_id != $a_node["child"]) {
308 // get container event items only once
309 if (!isset($this->session_materials[$container_parent_id])) {
310 include_once './Modules/Session/classes/class.ilEventItems.php';
311 $this->session_materials[$container_parent_id] = ilEventItems::_getItemsOfContainer($container_parent_id);
312 }
313 if (in_array($a_node["child"], $this->session_materials[$container_parent_id])) {
314 return false;
315 }
316 }
317 }
318 }
319
320 return true;
321 }
322
329 protected function getParentCourseOrGroup($node_id)
330 {
331 $current_node_id = $node_id;
332 while (isset($this->parent_node_id[$current_node_id])) {
333 $parent_node_id = $this->parent_node_id[$current_node_id];
334 if (isset($this->node_data[$parent_node_id]) && in_array($this->node_data[$parent_node_id]["type"], ["grp", "crs"])) {
335 return $parent_node_id;
336 }
337 $current_node_id = $parent_node_id;
338 }
339 return 0;
340 }
341
342
351 public function sortChilds($a_childs, $a_parent_node_id)
352 {
353 $objDefinition = $this->obj_definition;
354 $ilAccess = $this->access;
355
356 $parent_obj_id = ilObject::_lookupObjId($a_parent_node_id);
357 if ($parent_obj_id > 0) {
358 $parent_type = ilObject::_lookupType($parent_obj_id);
359 } else {
360 $parent_type = "dummy";
361 $this->type_grps["dummy"] = array("root" => "dummy");
362 }
363
364 // alex: if this is not initialized, things are messed up
365 // see bug 0015978
366 $this->type_grps = array();
367
368 if (empty($this->type_grps[$parent_type])) {
369 $this->type_grps[$parent_type] =
370 $objDefinition->getGroupedRepositoryObjectTypes($parent_type);
371 }
372
373 // #14465 - item groups
374 include_once('./Services/Object/classes/class.ilObjectActivation.php');
375 $group = array();
376 $igroup = array(); // used for item groups, see bug #0015978
377 $in_any_group = array();
378 foreach ($a_childs as $child) {
379 // item group: get childs
380 if ($child["type"] == "itgr") {
381 $g = $child["child"];
383 if ($items) {
384 // add item group ref id to item group block
385 $this->type_grps[$parent_type]["itgr"]["ref_ids"][] = $g;
386
387 // #16697 - check item group permissions
388 $may_read = $ilAccess->checkAccess('read', '', $g);
389
390 // see bug #0015978
391 if ($may_read) {
392 include_once("./Services/Container/classes/class.ilContainerSorting.php");
393 $items = ilContainerSorting::_getInstance($parent_obj_id)->sortSubItems('itgr', $child["obj_id"], $items);
394 }
395
396 foreach ($items as $item) {
397 $in_any_group[] = $item["child"];
398
399 if ($may_read) {
400 $igroup[$g][] = $item;
401 $group[$g][] = $item;
402 }
403 }
404 }
405 }
406 // type group
407 else {
408 $g = $objDefinition->getGroupOfObj($child["type"]);
409 if ($g == "") {
410 $g = $child["type"];
411 }
412 $group[$g][] = $child;
413 }
414 }
415
416 $in_any_group = array_unique($in_any_group);
417
418 // custom block sorting?
419 include_once("./Services/Container/classes/class.ilContainerSorting.php");
420 $sort = ilContainerSorting::_getInstance($parent_obj_id);
421 $block_pos = $sort->getBlockPositions();
422 if (is_array($block_pos) && count($block_pos) > 0) {
423 $tmp = $this->type_grps[$parent_type];
424
425 $this->type_grps[$parent_type] = array();
426 foreach ($block_pos as $block_type) {
427 // type group
428 if (!is_numeric($block_type) &&
429 array_key_exists($block_type, $tmp)) {
430 $this->type_grps[$parent_type][$block_type] = $tmp[$block_type];
431 unset($tmp[$block_type]);
432 }
433 // item group
434 else {
435 // using item group ref id directly
436 $this->type_grps[$parent_type][$block_type] = array();
437 }
438 }
439
440 // append missing
441 if (sizeof($tmp)) {
442 foreach ($tmp as $block_type => $grp) {
443 $this->type_grps[$parent_type][$block_type] = $grp;
444 }
445 }
446
447 unset($tmp);
448 }
449
450 $childs = array();
451 $done = array();
452
453 foreach ($this->type_grps[$parent_type] as $t => $g) {
454 // type group
455 if (is_array($group[$t])) {
456 // see bug #0015978
457 // custom sorted igroups
458 if (is_array($igroup[$t])) {
459 foreach ($igroup[$t] as $k => $item) {
460 if (!in_array($item["child"], $done)) {
461 $childs[] = $item;
462 $done[] = $item["child"];
463 }
464 }
465 } else {
466 // do we have to sort this group??
467 include_once("./Services/Container/classes/class.ilContainer.php");
468 include_once("./Services/Container/classes/class.ilContainerSorting.php");
469 $sort = ilContainerSorting::_getInstance($parent_obj_id);
470 $group = $sort->sortItems($group);
471
472 // need extra session sorting here
473 if ($t == "sess") {
474 foreach ($group[$t] as $k => $v) {
475 $app_info = ilSessionAppointment::_lookupAppointment($v["obj_id"]);
476 $group[$t][$k]["start"] = $app_info["start"];
477 }
478 $group[$t] = ilUtil::sortArray($group[$t], 'start', 'asc', true, false);
479 }
480
481 foreach ($group[$t] as $k => $item) {
482 if (!in_array($item["child"], $done) &&
483 !in_array($item["child"], $in_any_group)) { // #16697
484 $childs[] = $item;
485 $done[] = $item["child"];
486 }
487 }
488 }
489 }
490 // item groups (if not custom block sorting)
491 elseif ($t == "itgr" &&
492 is_array($g["ref_ids"])) {
493 foreach ($g["ref_ids"] as $ref_id) {
494 if (isset($group[$ref_id])) {
495 foreach ($group[$ref_id] as $k => $item) {
496 if (!in_array($item["child"], $done)) {
497 $childs[] = $item;
498 $done[] = $item["child"];
499 }
500 }
501 }
502 }
503 }
504 }
505
506 return $childs;
507 }
508
515 public function getChildsOfNode($a_parent_node_id)
516 {
518
519 if (!$rbacsystem->checkAccess("read", $a_parent_node_id)) {
520 return array();
521 }
522
523 $obj_id = ilObject::_lookupObjId($a_parent_node_id);
524 if (!ilConditionHandler::_checkAllConditionsOfTarget($a_parent_node_id, $obj_id)) {
525 return array();
526 }
527
528 $childs = parent::getChildsOfNode($a_parent_node_id);
529
530 foreach ($childs as $c) {
531 $this->parent_node_id[$c["child"]] = $a_parent_node_id;
532 $this->node_data[$c["child"]] = $c;
533 }
534
535 return $childs;
536 }
537
544 public function isNodeClickable($a_node)
545 {
550 $ilAccess = $this->access;
551
552 $obj_id = ilObject::_lookupObjId($a_node["child"]);
553 if (!ilConditionHandler::_checkAllConditionsOfTarget($a_node["child"], $obj_id)) {
554 return false;
555 }
556
557 switch ($a_node["type"]) {
558 case 'tst':
559 if (!$rbacsystem->checkAccess("read", $a_node["child"])) {
560 return false;
561 }
562
563 $query = sprintf("SELECT * FROM tst_tests WHERE obj_fi=%s", $obj_id);
564 $res = $ilDB->query($query);
565 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
566 return (bool) $row->complete;
567 }
568 return false;
569
570 case 'svy':
571 if (!$rbacsystem->checkAccess("read", $a_node["child"])) {
572 return false;
573 }
574
575 $query = sprintf("SELECT * FROM svy_svy WHERE obj_fi=%s", $obj_id);
576 $res = $ilDB->query($query);
577 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
578 return (bool) $row->complete;
579 }
580 return false;
581
582 // media pools can only be edited
583 case "mep":
584 if ($rbacsystem->checkAccess("read", $a_node["child"])) {
585 return true;
586 } else {
587 return false;
588 }
589 break;
590 case 'grpr':
591 case 'crsr':
592 case 'catr':
593 include_once('./Services/ContainerReference/classes/class.ilContainerReferenceAccess.php');
594 return ilContainerReferenceAccess::_isAccessible($a_node["child"]);
595
596 case 'prg':
597 return $rbacsystem->checkAccess("read", $a_node["child"]);
598
599 // all other types are only clickable, if read permission is given
600 default:
601 if ($rbacsystem->checkAccess("read", $a_node["child"])) {
602 // check if lm is online
603 if ($a_node["type"] == "lm") {
604 include_once("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
605 $lm_obj = new ilObjLearningModule($a_node["child"]);
606 if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
607 return false;
608 }
609 }
610 // check if fblm is online
611 if ($a_node["type"] == "htlm") {
612 include_once("./Modules/HTMLLearningModule/classes/class.ilObjFileBasedLM.php");
613 $lm_obj = new ilObjFileBasedLM($a_node["child"]);
614 if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
615 return false;
616 }
617 }
618 // check if fblm is online
619 if ($a_node["type"] == "sahs") {
620 include_once("./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php");
621 $lm_obj = new ilObjSAHSLearningModule($a_node["child"]);
622 if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
623 return false;
624 }
625 }
626 // check if glossary is online
627 if ($a_node["type"] == "glo") {
628 $obj_id = ilObject::_lookupObjectId($a_node["child"]);
629 if ((!ilObjGlossary::_lookupOnline($obj_id)) &&
630 (!$rbacsystem->checkAccess('write', $a_node["child"]))) {
631 return false;
632 }
633 }
634
635 return true;
636 } else {
637 return false;
638 }
639 break;
640 }
641 }
642
643 public static function getTopNodeForRefId(int $ref_id) : int {
644 global $DIC;
645
646 $setting = $DIC->settings();
647 $tree = $DIC->repositoryTree();
648
649 $top_node = 0;
650 if ($setting->get("rep_tree_limit_grp_crs") && $ref_id > 0) {
651 $path = $tree->getPathId($ref_id);
652 foreach ($path as $n) {
653 if ($top_node > 0) {
654 break;
655 }
656 if (in_array(
658 array("crs", "grp")
659 )) {
660 $top_node = $n;
661 }
662 }
663 }
664 return $top_node;
665 }
666}
user()
Definition: user.php:4
$n
Definition: RandomTest.php:85
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
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
static _isAccessible($a_ref_id)
Check if target is accessible and not deleted.
static _getInstance($a_obj_id)
get instance by obj_id
static _getItemsOfContainer($a_ref_id)
setChildLimit($a_val)
Set child limit.
setSkipRootNode($a_val)
Set skip root node.
setNodeOpen($a_id)
Set node to be opened (additional custom opened node, not standard expand behaviour)
File Based Learning Module (HTML) object.
static _lookupOnline($a_id)
check wether content object is online
Class ilObjLearningModule.
Class ilObjSCORMLearningModule.
static getItemsByItemGroup($a_item_group_ref_id)
Get materials of item group.
static _lookupObjId($a_id)
static _lookupObjectId($a_ref_id)
lookup object id
static _lookupType($a_id, $a_reference=false)
lookup object type
Repository explorer GUI class.
getNodeContent($a_node)
Get node content.
getParentCourseOrGroup($node_id)
Get upper course or group.
getChildsOfNode($a_parent_node_id)
Get childs of node.
isNodeHighlighted($a_node)
Is node highlighted?
getNodeHref($a_node)
Get href for node.
sortChilds($a_childs, $a_parent_node_id)
Sort childs.
__construct($a_parent_obj, $a_parent_cmd)
Constructor.
isNodeClickable($a_node)
Is node clickable?
isNodeVisible($a_node)
Is node visible.
getNodeIconAlt($a_node)
Get node icon alt text.
static _lookupAppointment($a_obj_id)
lookup appointment
static _appointmentToString($start, $end, $fulltime)
Explorer class that works on tree objects (Services/Tree)
setTypeWhiteList($a_val)
Set type white list.
setPathOpen($a_id)
Set node path to be opened.
getNodeId($a_node)
Get id for node.
setOrderField($a_val, $a_numeric=false)
Set order field.
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
global $ilCtrl
Definition: ilias.php:18
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $ilSetting
Definition: privfeed.php:17
$query
foreach($_POST as $key=> $value) $res
settings()
Definition: settings.php:2
global $ilDB
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46