ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilRepositoryExplorer.php
Go to the documentation of this file.
1 <?php
2 
20 
21 /*
22  * Repository Explorer
23  *
24  * @author Alexander Killing <killing@leifos.de>
25  * @deprecated
26  * only use seems to be ilPasteIntoMultipleItemsExplorer
27  * which is still used in repository and workspace.
28  */
30 {
31  protected ilSetting $settings;
32  protected ilDBInterface $db;
33  protected ilObjUser $user;
35  protected ilCtrl $ctrl;
36  protected array $force_open_path;
38  protected array $session_materials;
39  protected array $item_group_items;
40  protected array $type_grps;
41 
42  public function __construct(string $a_target, int $a_top_node = 0)
43  {
45  global $DIC;
46 
47  $this->lng = $DIC->language();
48  $this->settings = $DIC->settings();
49  $this->obj_definition = $DIC["objDefinition"];
50  $this->rbacsystem = $DIC->rbac()->system();
51  $this->db = $DIC->database();
52  $this->user = $DIC->user();
53  $this->access = $DIC->access();
54  $tree = $DIC->repositoryTree();
55  $ilCtrl = $DIC->ctrl();
56  $lng = $DIC->language();
57  $ilSetting = $DIC->settings();
58  $objDefinition = $DIC["objDefinition"];
59 
60  $this->ctrl = $ilCtrl;
61 
62 
63  $this->force_open_path = [];
64  $this->request = $DIC->repository()->internal()->gui()->standardRequest();
65 
66 
67  parent::__construct($a_target);
68  $this->tree = $tree;
69  $this->root_id = $this->tree->readRootId();
70  $this->order_column = "title";
71  $this->setSessionExpandVariable("repexpand");
72  $this->setTitle($lng->txt("overview"));
73 
74  // please do not uncomment this
75  if ($ilSetting->get("repository_tree_pres") == "" ||
76  ($ilSetting->get("rep_tree_limit_grp_crs") && $a_top_node === 0)) {
77  foreach ($objDefinition->getExplorerContainerTypes() as $type) {
78  $this->addFilter($type);
79  }
80  $this->setFiltered(true);
82  } elseif ($ilSetting->get("repository_tree_pres") === "all_types") {
83  foreach ($objDefinition->getAllRBACObjects() as $rtype) {
84  $this->addFilter($rtype);
85  }
86  $this->setFiltered(true);
88  }
89  }
90 
94  public function setForceOpenPath(array $a_path): void
95  {
96  $this->force_open_path = $a_path;
97  }
98 
102  public function buildLinkTarget($a_node_id, string $a_type): string
103  {
104  $ilCtrl = $this->ctrl;
105 
106  $ref_id = $this->request->getRefId();
107 
108  switch ($a_type) {
109  case "cat":
110  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node_id);
111  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
112  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
113  return $link;
114 
115  case "grpr":
116  case "crsr":
117  case "catr":
118  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node_id);
119  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "redirect");
120  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
121  return $link;
122 
123  case "grp":
124  $ilCtrl->setParameterByClass("ilobjgroupgui", "ref_id", $a_node_id);
125  $link = $ilCtrl->getLinkTargetByClass(["ilrepositorygui", "ilobjgroupgui"], "");
126  $ilCtrl->setParameterByClass("ilobjgroupgui", "ref_id", $ref_id);
127  return $link;
128 
129  case "crs":
130  $ilCtrl->setParameterByClass("ilobjcoursegui", "ref_id", $a_node_id);
131  $link = $ilCtrl->getLinkTargetByClass(["ilrepositorygui", "ilobjcoursegui"], "view");
132  $ilCtrl->setParameterByClass("ilobjcoursegui", "ref_id", $ref_id);
133  return $link;
134 
135  case 'rcrs':
136  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $a_node_id);
137  $link = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "infoScreen");
138  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $ref_id);
139  return $link;
140 
141  case 'prg':
142  $ilCtrl->setParameterByClass("ilobjstudyprogrammegui", "ref_id", $a_node_id);
143  $link = $ilCtrl->getLinkTargetByClass("ilobjstudyprogrammegui", "view");
144  $ilCtrl->setParameterByClass("ilobjstudyprogrammegui", "ref_id", $ref_id);
145  return $link;
146 
147  default:
148  return ilLink::_getStaticLink($a_node_id, $a_type, true);
149 
150  }
151  }
152 
153  public function getImage(string $a_name, string $a_type = "", $a_obj_id = ""): string
154  {
155  if ($a_type !== "") {
156  return ilObject::_getIcon((int) $a_obj_id, "tiny", $a_type);
157  }
158 
159  return parent::getImage($a_name);
160  }
161 
162  public function isClickable(string $type, int $ref_id = 0): bool
163  {
165  $ilDB = $this->db;
166 
167  $obj_id = ilObject::_lookupObjId($ref_id);
169  $ref_id,
170  $obj_id
171  )) {
172  return false;
173  }
174 
175  switch ($type) {
176  case 'tst':
177  if (!$rbacsystem->checkAccess("read", $ref_id)) {
178  return false;
179  }
180 
181  $query = sprintf("SELECT * FROM tst_tests WHERE obj_fi=%s", $obj_id);
182  $res = $ilDB->query($query);
183  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
184  return (bool) $row->complete;
185  }
186  return false;
187 
188  case 'svy':
189  if (!$rbacsystem->checkAccess("read", $ref_id)) {
190  return false;
191  }
192 
193  $query = sprintf("SELECT * FROM svy_svy WHERE obj_fi=%s", $obj_id);
194  $res = $ilDB->query($query);
195  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
196  return (bool) $row->complete;
197  }
198  return false;
199 
200  // media pools can only be edited
201  case "mep":
202  if ($rbacsystem->checkAccess("read", $ref_id)) {
203  return true;
204  }
205  return false;
206  case 'grpr':
207  case 'crsr':
208  case 'catr':
210  case 'prg':
211  return $rbacsystem->checkAccess("visible", $ref_id);
212 
213 
214 
215  // all other types are only clickable, if read permission is given
216  default:
217  if ($rbacsystem->checkAccess("read", $ref_id)) {
218  // check if lm is online
219  if ($type === "lm") {
220  $lm_obj = new ilObjLearningModule($ref_id);
221  if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $ref_id))) {
222  return false;
223  }
224  }
225  // check if fblm is online
226  if ($type === "htlm") {
227  $lm_obj = new ilObjFileBasedLM($ref_id);
228  if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $ref_id))) {
229  return false;
230  }
231  }
232  // check if fblm is online
233  if ($type === "sahs") {
234  $lm_obj = new ilObjSAHSLearningModule($ref_id);
235  if (($lm_obj->getOfflineStatus()) && (!$rbacsystem->checkAccess('write', $ref_id))) {
236  return false;
237  }
238  }
239  // check if glossary is online
240  if ($type === "glo") {
242  if ((!ilObjGlossary::_lookupOnline($obj_id)) &&
243  (!$rbacsystem->checkAccess('write', $ref_id))) {
244  return false;
245  }
246  }
247 
248  return true;
249  }
250  return false;
251  }
252  }
253 
257  public function showChilds($a_parent_id, int $a_obj_id = 0): bool
258  {
260 
261  if ($a_parent_id == 0) {
262  return true;
263  }
264  if (!ilConditionHandler::_checkAllConditionsOfTarget((int) $a_parent_id, $a_obj_id)) {
265  return false;
266  }
267  if ($rbacsystem->checkAccess("read", (int) $a_parent_id)) {
268  return true;
269  }
270 
271  return false;
272  }
273 
274  public function isVisible($a_ref_id, string $a_type): bool
275  {
276  $ilAccess = $this->access;
277  $tree = $this->tree;
279 
280  if (!$ilAccess->checkAccess('visible', '', $a_ref_id)) {
281  return false;
282  }
283 
284  $is_course = false;
285  $container_parent_id = $tree->checkForParentType($a_ref_id, 'grp');
286  if (!$container_parent_id) {
287  $is_course = true;
288  $container_parent_id = $tree->checkForParentType($a_ref_id, 'crs');
289  }
290  if ($container_parent_id) {
291  // do not display session materials for container course/group
292  if ($container_parent_id !== $a_ref_id && $ilSetting->get("repository_tree_pres") === "all_types") {
293  // get container event items only once
294  if (!isset($this->session_materials[$container_parent_id])) {
295  $this->session_materials[$container_parent_id] = ilEventItems::_getItemsOfContainer($container_parent_id);
296  }
297  // get item group items only once
298  if (!isset($this->item_group_items[$container_parent_id])) {
299  $this->item_group_items[$container_parent_id] = ilItemGroupItems::_getItemsOfContainer($container_parent_id);
300  }
301  if (in_array($a_ref_id, $this->session_materials[$container_parent_id])) {
302  return false;
303  }
304  if (in_array($a_ref_id, $this->item_group_items[$container_parent_id])) {
305  return false;
306  }
307  }
308  }
309 
310  return true;
311  }
312 
313 
314  public function formatHeader(ilTemplate $tpl, $a_obj_id, array $a_option): void
315  {
316  $lng = $this->lng;
317  $tree = $this->tree;
318  $ilCtrl = $this->ctrl;
319 
320  // custom icons
321  $path = ilObject::_getIcon((int) $a_obj_id, "tiny", "root");
322 
323  $tpl->setCurrentBlock("icon");
325  $title = $nd["title"];
326  if ($title === "ILIAS") {
327  $title = $lng->txt("repository");
328  }
329 
330  $tpl->setVariable("ICON_IMAGE", $path);
331  $tpl->setVariable("TXT_ALT_IMG", $lng->txt("icon") . " " . $title);
332  $tpl->parseCurrentBlock();
333 
334  $tpl->setCurrentBlock("link");
335  $tpl->setVariable("TITLE", $title);
336  $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", "1");
337  $tpl->setVariable(
338  "LINK_TARGET",
339  $ilCtrl->getLinkTargetByClass("ilrepositorygui", "")
340  );
341  $ilCtrl->setParameterByClass(
342  "ilrepositorygui",
343  "ref_id",
344  $this->request->getRefId()
345  );
346  $tpl->setVariable("TARGET", " target=\"_top\"");
347  $tpl->parseCurrentBlock();
348 
349  $tpl->setCurrentBlock("element");
350  $tpl->parseCurrentBlock();
351  }
352 
353  public function sortNodes(array $a_nodes, $a_parent_obj_id): array
354  {
355  $objDefinition = $this->obj_definition;
356 
357  if ($a_parent_obj_id > 0) {
358  $parent_type = ilObject::_lookupType($a_parent_obj_id);
359  } else {
360  $parent_type = "dummy";
361  $this->type_grps["dummy"] = ["root" => "dummy"];
362  }
363 
364  if (empty($this->type_grps[$parent_type])) {
365  $this->type_grps[$parent_type] = $objDefinition->getGroupedRepositoryObjectTypes($parent_type);
366  }
367  $group = [];
368 
369  foreach ($a_nodes as $node) {
370  $g = $objDefinition->getGroupOfObj($node["type"]);
371  if ($g == "") {
372  $g = $node["type"];
373  }
374  $group[$g][] = $node;
375  }
376 
377  $nodes = [];
378  foreach ($this->type_grps[$parent_type] as $t => $g) {
379  if (array_key_exists($t, $group)
380  && is_array($group[$t])) {
381  // do we have to sort this group??
382  $sort = ilContainerSorting::_getInstance($a_parent_obj_id);
383  $group = $sort->sortItems($group);
384 
385  foreach ($group[$t] as $k => $item) {
386  $nodes[] = $item;
387  }
388  }
389  }
390 
391  return $nodes;
392  }
393 
394  public function forceExpanded($a_obj_id): bool
395  {
396  if (in_array($a_obj_id, $this->force_open_path)) {
397  return true;
398  }
399  return false;
400  }
401 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setSessionExpandVariable(string $a_var_name="expand")
$res
Definition: ltiservices.php:69
formatHeader(ilTemplate $tpl, $a_obj_id, array $a_option)
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFiltered(bool $a_bool)
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...
$type
const ROOT_FOLDER_ID
Definition: constants.php:32
ilLanguage $lng
isVisible($a_ref_id, string $a_type)
static _lookupOnline(int $a_id)
setTitle(string $a_val)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $tpl
const IL_FM_POSITIVE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
showChilds($a_parent_id, int $a_obj_id=0)
ilRbacSystem $rbacsystem
static _getItemsOfContainer(int $a_ref_id)
$path
Definition: ltiservices.php:32
static _lookupObjId(int $ref_id)
buildLinkTarget($a_node_id, string $a_type)
note: most of this stuff is used by ilCourseContentInterface too
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 ...
setForceOpenPath(array $a_path)
set force open path
checkForParentType(int $a_ref_id, string $a_type, bool $a_exclude_source_check=false)
Check for parent type e.g check if a folder (ref_id 3) is in a parent course obj => checkForParentTyp...
$ref_id
Definition: ltiauth.php:67
$nd
Definition: error.php:12
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
static _getItemsOfContainer(int $a_ref_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjectId(int $ref_id)
$query
class for explorer view in admin frame
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
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
getImage(string $a_name, string $a_type="", $a_obj_id="")
global $ilSetting
Definition: privfeed.php:17
__construct(Container $dic, ilPlugin $plugin)
static _getInstance(int $a_obj_id)
isClickable(string $type, int $ref_id=0)
addFilter(string $a_item)
static _isAccessible(int $a_ref_id)
Check if target is accessible and not deleted.
static _lookupType(int $id, bool $reference=false)
setFilterMode(int $a_mode=IL_FM_NEGATIVE)
Class ilObjSCORMLearningModule.
sortNodes(array $a_nodes, $a_parent_obj_id)
ilObjectDefinition $obj_definition