ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilRepositorySelectorExplorerGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
31 {
32  private string $clickable_permission = 'read';
34  protected array $type_grps = [];
35  protected array $session_materials = [];
36  protected string $highlighted_node = "";
37  protected array $clickable_types = [];
38  protected array $selectable_types = [];
40  protected ?Closure $nc_modifier = null;
41  protected ?string $selection_gui = null;
42  protected string $selection_par;
43  protected string $selection_cmd;
45  protected int $cur_ref_id;
46 
51  public function __construct(
52  $a_parent_obj,
53  string $a_parent_cmd,
54  $a_selection_gui = null,
55  string $a_selection_cmd = "selectObject",
56  string $a_selection_par = "sel_ref_id",
57  string $a_id = "rep_exp_sel",
58  string $a_node_parameter_name = "node_id"
59  ) {
61  global $DIC;
62  $this->tree = $DIC->repositoryTree();
63  $this->obj_definition = $DIC["objDefinition"];
64  $this->lng = $DIC->language();
65  $tree = $DIC->repositoryTree();
66  $ilSetting = $DIC->settings();
67  $objDefinition = $DIC["objDefinition"];
68  $this->request = $DIC->repository()->internal()->gui()->standardRequest();
69  $this->cur_ref_id = $this->request->getRefId();
70 
71  $this->access = $DIC->access();
72  $this->ctrl = $DIC->ctrl();
73 
74  if (is_null($a_selection_gui)) {
75  $a_selection_gui = $a_parent_obj;
76  }
77 
78  $this->selection_gui = is_object($a_selection_gui)
79  ? strtolower(get_class($a_selection_gui))
80  : strtolower($a_selection_gui);
81  $this->selection_cmd = $a_selection_cmd;
82  $this->selection_par = $a_selection_par;
83  parent::__construct($a_id, $a_parent_obj, $a_parent_cmd, $tree, $a_node_parameter_name);
84 
85  $this->setSkipRootNode(false);
86  $this->setAjax(true);
87  $this->setOrderField("title");
88 
89  // per default: all object types, except item groups
90  $white = [];
91  foreach ($objDefinition->getSubObjectsRecursively("root") as $rtype) {
92  if ($rtype["name"] !== "itgr" && !$objDefinition->isSideBlock($rtype["name"])) {
93  $white[] = $rtype["name"];
94  }
95  }
96  $this->setTypeWhiteList($white);
97 
98  // always open the path to the current ref id
99  $this->setPathOpen($this->tree->readRootId());
100  if ($this->cur_ref_id > 0) {
101  $this->setPathOpen($this->cur_ref_id);
102  }
103  $this->setChildLimit((int) $ilSetting->get("rep_tree_limit_number"));
104  }
105 
106  public function setNodeContentModifier(Closure $a_val): void
107  {
108  $this->nc_modifier = $a_val;
109  }
110 
111  public function getNodeContentModifier(): ?Closure
112  {
113  return $this->nc_modifier;
114  }
115 
116  public function getNodeContent($a_node): string
117  {
118  $lng = $this->lng;
119 
120  $c = $this->getNodeContentModifier();
121  if (is_callable($c)) {
122  return $c($a_node);
123  }
124 
125  $title = $a_node["title"];
126  if ($title === "ILIAS" && (int) $a_node["child"] === (int) $this->getNodeId($this->getRootNode())) {
127  $title = $lng->txt("repository");
128  }
129 
130  return (string) $title;
131  }
132 
133  public function getNodeIcon($a_node): string
134  {
135  $obj_id = ilObject::_lookupObjId($a_node["child"]);
136  return ilObject::_getIcon($obj_id, "tiny", $a_node["type"]);
137  }
138 
139  public function getNodeIconAlt($a_node): string
140  {
141  $lng = $this->lng;
142 
143  if ($a_node["child"] == $this->getNodeId($this->getRootNode())) {
144  $title = $a_node["title"];
145  if ($title === "ILIAS") {
146  $title = $lng->txt("repository");
147  }
148  return $lng->txt("icon") . " " . $title;
149  }
150 
151  return parent::getNodeIconAlt($a_node);
152  }
153 
154  public function isNodeHighlighted($a_node): bool
155  {
156  if ($this->getHighlightedNode()) {
157  if ((int) $this->getHighlightedNode() === (int) $a_node["child"]) {
158  return true;
159  }
160  return false;
161  }
162 
163  if ((int) $a_node["child"] === $this->cur_ref_id ||
164  ($this->cur_ref_id === 0 && (int) $a_node["child"] === (int) $this->getNodeId($this->getRootNode()))) {
165  return true;
166  }
167  return false;
168  }
169 
170  public function getNodeHref($a_node): string
171  {
172  $ilCtrl = $this->ctrl;
173 
174  if ($this->select_postvar === "") {
175  $ilCtrl->setParameterByClass($this->selection_gui, $this->selection_par, $a_node["child"]);
176  $link = $ilCtrl->getLinkTargetByClass($this->selection_gui, $this->selection_cmd);
177  $ilCtrl->setParameterByClass($this->selection_gui, $this->selection_par, "");
178  } else {
179  return "#";
180  }
181 
182  return $link;
183  }
184 
185  public function isNodeVisible($a_node): bool
186  {
187  $ilAccess = $this->access;
188 
189  if (!$ilAccess->checkAccess('visible', '', $a_node["child"])) {
190  return false;
191  }
192 
193  return true;
194  }
195 
196  public function sortChilds(array $a_childs, $a_parent_node_id): array
197  {
198  $objDefinition = $this->obj_definition;
199 
200  $parent_obj_id = ilObject::_lookupObjId((int) $a_parent_node_id);
201 
202  if ($parent_obj_id > 0) {
203  $parent_type = ilObject::_lookupType($parent_obj_id);
204  } else {
205  $parent_type = "dummy";
206  $this->type_grps["dummy"] = ["root" => "dummy"];
207  }
208 
209  if (empty($this->type_grps[$parent_type])) {
210  $this->type_grps[$parent_type] =
211  $objDefinition::getGroupedRepositoryObjectTypes($parent_type);
212  }
213  $group = [];
214 
215  foreach ($a_childs as $child) {
216  $g = $objDefinition->getGroupOfObj($child["type"]);
217  if ($g == "") {
218  $g = $child["type"];
219  }
220  $group[$g][] = $child;
221  }
222 
223  // #14587 - $objDefinition->getGroupedRepositoryObjectTypes does NOT include side blocks!
224  $wl = $this->getTypeWhiteList();
225  if (is_array($wl) && in_array("poll", $wl, true)) {
226  $this->type_grps[$parent_type]["poll"] = [];
227  }
228 
229  $childs = [];
230  foreach ($this->type_grps[$parent_type] as $t => $g) {
231  if (isset($group[$t])) {
232  // do we have to sort this group??
233  $sort = ilContainerSorting::_getInstance($parent_obj_id);
234  $group = $sort->sortItems($group);
235 
236  foreach ($group[$t] as $k => $item) {
237  $childs[] = $item;
238  }
239  }
240  }
241 
242  return $childs;
243  }
244 
245  public function getChildsOfNode($a_parent_node_id): array
246  {
247  $ilAccess = $this->access;
248  if (!$ilAccess->checkAccess("read", "", (int) $a_parent_node_id)) {
249  return [];
250  }
251 
252  return parent::getChildsOfNode($a_parent_node_id);
253  }
254 
255  public function setClickablePermission(string $rbac_perm): void
256  {
257  $this->clickable_permission = $rbac_perm;
258  }
259 
260  public function isNodeClickable($a_node): bool
261  {
262  $ilAccess = $this->access;
263 
264  if (!$ilAccess->hasUserRBACorAnyPositionAccess($this->clickable_permission, $a_node["child"])) {
265  return false;
266  }
267 
268  if (is_array($this->getClickableTypes()) && count($this->getClickableTypes()) > 0) {
269  return in_array($a_node["type"], $this->getClickableTypes(), true);
270  }
271 
272  return true;
273  }
274 
275  public function setHighlightedNode(string $a_value): void
276  {
277  $this->highlighted_node = $a_value;
278  }
279 
280  public function getHighlightedNode(): string
281  {
283  }
284 
285  public function setClickableTypes(array $a_types): void
286  {
287  $this->clickable_types = $a_types;
288  }
289 
290  public function getClickableTypes(): array
291  {
292  return $this->clickable_types;
293  }
294 
295  public function setSelectableTypes(array $a_types): void
296  {
297  $this->selectable_types = $a_types;
298  }
299 
300  public function getSelectableTypes(): array
301  {
303  }
304 
305  protected function isNodeSelectable($a_node): bool
306  {
307  if (count($this->getSelectableTypes())) {
308  return in_array($a_node['type'], $this->getSelectableTypes(), true);
309  }
310  return true;
311  }
312 }
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.
$c
Definition: deliver.php:25
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:22
sortChilds(array $a_childs, $a_parent_node_id)
getNodeId($a_node)
Get id for node.
getRootNode()
Get root node.
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)
getTypeWhiteList()
Get type white list.
__construct(string $a_expl_id, $a_parent_obj, string $a_parent_cmd, ilTree $a_tree, string $a_node_parameter_name="node_id")