ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilExplorer.php
Go to the documentation of this file.
1<?php
2
21
30{
35 protected ilLanguage $lng;
36 public string $id = "";
37 public string $output = "";
38 public array $format_options = [];
39 public ilTree $tree;
40 public string $target = "";
41 public string $target_get = "";
42 public string $params_get = "";
43 public array $expanded = [];
44 public string $order_column = "";
45 public string $order_direction = "asc";
46 public ?string $expand_target = null;
47 public bool $rbac_check = false;
48 public bool $output_icons = false;
49 public string $expand_variable = "";
50 // array ($type => clickable (empty means true, "n" means false)
51 public array $is_clickable = [];
52 public bool $post_sort = false;
53 public bool $filtered = false;
54 protected $filter = [];
55 public bool $filter_mode;
56 // expand entire tree regardless of values in $expanded
57 public bool $expand_all = false;
58 public $root_id = null;
59 public bool $use_standard_frame = false;
60 protected string $highlighted = "";
61 protected bool $show_minus = true;
62 protected int $counter = 0;
63 protected bool $asnch_expanding = false;
64 protected int $textwidth = 0;
65 protected string $title = "";
66 protected string $up_frame = "";
67 protected string $a_up_script = "";
68 protected string $up_params = "";
69 protected string $frame_target = "";
70 protected string $up_script = "";
71 protected string $tree_lead = "";
72 protected array $iconList = [];
73
74 protected \ILIAS\Refinery\Factory $refinery;
75 protected \ILIAS\HTTP\Wrapper\WrapperFactory $wrapper;
76
77 public function __construct(string $a_target)
78 {
80 global $DIC;
81
82 $this->obj_definition = $DIC["objDefinition"];
83 $this->error = $DIC["ilErr"];
84 $this->rbacsystem = $DIC->rbac()->system();
85 $this->tpl = $DIC["tpl"];
86 $this->lng = $DIC->language();
87 $objDefinition = $DIC["objDefinition"];
88 $ilErr = $DIC["ilErr"];
89
90 if (!isset($a_target) or !is_string($a_target)) {
91 $ilErr->raiseError(get_class($this) . "::Constructor(): No target given!", $ilErr->WARNING);
92 }
93
94 // autofilter object types in devmode
95 $devtypes = $objDefinition->getDevModeAll();
96
97 if (count($devtypes) > 0) {
98 // activate filter if objects found in devmode
99 $this->setFiltered(true);
100
101 foreach ($devtypes as $type) {
102 $this->addFilter($type);
103 }
104 }
105
106 $this->expanded = array();
107 $this->target = $a_target;
108 $this->target_get = 'ref_id';
109 $this->frame_target = "content";
110 $this->order_column = "title";
111 $this->tree = new ilTree(ROOT_FOLDER_ID);
112 $this->tree->initLangCode();
113 $this->expand_target = $_SERVER["PATH_INFO"] ?? "";
114 $this->rbac_check = true;
115 $this->output_icons = true;
116 $this->expand_variable = "expand";
117 $this->setTitleLength(50);
118 $this->post_sort = true;
120 $this->highlighted = "";
121 $this->show_minus = true;
122 $this->counter = 0;
123 $this->asnch_expanding = false;
124 $this->refinery = $DIC->refinery();
125 $this->wrapper = $DIC->http()->wrapper();
126 }
127
128 protected function requestStr(string $key): string
129 {
130 $str = $this->refinery->kindlyTo()->string();
131 if ($this->wrapper->post()->has($key)) {
132 return $this->wrapper->post()->retrieve($key, $str);
133 }
134 if ($this->wrapper->query()->has($key)) {
135 return $this->wrapper->query()->retrieve($key, $str);
136 }
137 return "";
138 }
139
140 public function setId(string $a_val): void
141 {
142 $this->id = $a_val;
143 }
144
145 public function getId(): string
146 {
147 return $this->id;
148 }
149
150 public function setAsynchExpanding(bool $a_val): void
151 {
152 $this->asnch_expanding = $a_val;
153 }
154
155 public function getAsynchExpanding(): bool
156 {
158 }
159
160 public function initItemCounter(int $a_number): void
161 {
162 $this->counter = $a_number;
163 }
164
165 public function setTitle(string $a_val): void
166 {
167 $this->title = $a_val;
168 }
169
170 public function setTitleLength(int $a_length): void
171 {
172 $this->textwidth = $a_length;
173 }
174
175 public function getTitleLength(): int
176 {
177 return $this->textwidth;
178 }
179
180 public function getTitle(): string
181 {
182 return $this->title;
183 }
184
185 public function setRoot($a_root_id): void
186 {
187 #$this->tree = new ilTree(ROOT_FOLDER_ID,$a_root_id);
188 $this->root_id = $a_root_id;
189 }
190
191 public function getRoot(): ?int
192 {
193 return $this->root_id ?? $this->tree->getRootId();
194 }
195
196 public function setOrderColumn(string $a_column): void
197 {
198 $this->order_column = $a_column;
199 }
200
201 public function setOrderDirection(string $a_direction): void
202 {
203 if ($a_direction === "desc") {
204 $this->order_direction = $a_direction;
205 } else {
206 $this->order_direction = "asc";
207 }
208 }
209
213 public function setTargetGet(string $a_target_get): void
214 {
216
217 if (!isset($a_target_get) or !is_string($a_target_get)) {
218 $ilErr->raiseError(get_class($this) . "::setTargetGet(): No target given!", $ilErr->WARNING);
219 }
220
221 $this->target_get = $a_target_get;
222 }
223
224 public function setParamsGet(array $a_params_get): void
225 {
227
228 if (!isset($a_params_get) or !is_array($a_params_get)) {
229 $ilErr->raiseError(get_class($this) . "::setTargetGet(): No target given!", $ilErr->WARNING);
230 }
231 $str = "";
232 foreach ($a_params_get as $key => $val) {
233 $str .= "&" . $key . "=" . $val;
234 }
235
236 $this->params_get = $str;
237 }
238
239
245 public function setExpandTarget(string $a_exp_target): void
246 {
247 $this->expand_target = $a_exp_target;
248 }
249
250 public function setFrameUpdater(
251 string $a_up_frame,
252 string $a_up_script,
253 string $a_params = ""
254 ): void {
255 $this->up_frame = $a_up_frame;
256 $this->up_script = $a_up_script;
257 $this->up_params = $a_params;
258 }
259
260
261 public function highlightNode(string $a_id): void
262 {
263 $this->highlighted = $a_id;
264 }
265
266 public function checkPermissions(bool $a_check): void
267 {
268 $this->rbac_check = $a_check;
269 }
270
271 public function setSessionExpandVariable(string $a_var_name = "expand"): void
272 {
273 $this->expand_variable = $a_var_name;
274 }
275
276 public function outputIcons(bool $a_icons): void
277 {
278 $this->output_icons = $a_icons;
279 }
280
281 public function setClickable(string $a_type, bool $a_clickable): void
282 {
283 if ($a_clickable) {
284 $this->is_clickable[$a_type] = "";
285 } else {
286 $this->is_clickable[$a_type] = "n";
287 }
288 }
289
290 public function isVisible(
291 $a_ref_id,
292 string $a_type
293 ): bool {
294 $rbacsystem = $this->rbacsystem;
295
296 if (!$this->rbac_check) {
297 return true;
298 }
299
300 $visible = $rbacsystem->checkAccess('visible', $a_ref_id);
301
302 return $visible;
303 }
304
305 // Set tree leading content
306 public function setTreeLead(string $a_val): void
307 {
308 $this->tree_lead = $a_val;
309 }
310
311 public function getTreeLead(): string
312 {
313 return $this->tree_lead;
314 }
315
316 // check if links for certain object type are activated
317 public function isClickable(
318 string $type,
319 int $ref_id = 0
320 ): bool {
321 // in this standard implementation
322 // only the type determines, wether an object should be clickable or not
323 // but this method can be overwritten and make $exp->setFilterMode(IL_FM_NEGATIVE);use of the ref id
324 // (this happens e.g. in class ilRepositoryExplorerGUI)
325 return $this->is_clickable[$type] !== "n";
326 }
327
328 public function setPostSort(bool $a_sort): void
329 {
330 $this->post_sort = $a_sort;
331 }
332
333 public function setFilterMode(int $a_mode = IL_FM_NEGATIVE): void
334 {
335 $this->filter_mode = $a_mode;
336 }
337
341 public function getFilterMode(): int
342 {
343 return $this->filter_mode;
344 }
345
350 public function setUseStandardFrame(bool $a_val): void
351 {
352 $this->use_standard_frame = $a_val;
353 }
354
355 public function getUseStandardFrame(): bool
356 {
357 return $this->use_standard_frame;
358 }
359
360 public function getChildsOfNode($a_parent_id): array
361 {
362 return $this->tree->getChilds($a_parent_id, $this->order_column);
363 }
364
365
370 public function setOutput(
371 $a_parent_id,
372 int $a_depth = 1,
373 int $a_obj_id = 0,
374 bool $a_highlighted_subtree = false
375 ): void {
376 $ilErr = $this->error;
377
378 $parent_index = 0;
379
380 if (!isset($a_parent_id)) {
381 $ilErr->raiseError(get_class($this) . "::setOutput(): No node_id given!", $ilErr->WARNING);
382 }
383
384 if ($this->showChilds($a_parent_id)) {
385 $objects = $this->getChildsOfNode($a_parent_id);
386 } else {
387 $objects = array();
388 }
389
390 $objects = $this->modifyChilds($a_parent_id, $objects);
391
392 // force expansion (of single nodes)
393 if ($this->forceExpanded($a_parent_id) && !in_array($a_parent_id, $this->expanded)) {
394 $this->expanded[] = $a_parent_id;
395 }
396
397 if (count($objects) > 0) {
398 // Maybe call a lexical sort function for the child objects
399 $tab = ++$a_depth - 2;
400 if ($this->post_sort) {
401 $objects = $this->sortNodes($objects, $a_obj_id);
402 }
403 $skip_rest = false;
404 foreach ($objects as $key => $object) {
405 // skip childs, if parent is not expanded
406 if (!$this->forceExpanded($object["child"]) && $skip_rest) {
407 continue;
408 }
409 //echo "<br>-".$object["child"]."-".$this->forceExpanded($object["child"])."-";
410 //ask for FILTER
411 if ($this->filtered === false || $this->checkFilter($object["type"]) === false) {
412 if ($this->isVisible($object['child'], $object['type'])) {
413 #echo 'CHILD getIndex() '.$object['child'].' parent: '.$this->getRoot();
414 if ($object["child"] != $this->getRoot()) {
415 $parent_index = $this->getIndex($object);
416 }
417 $this->format_options[(string) $this->counter]["parent"] = $object["parent"];
418 $this->format_options[(string) $this->counter]["child"] = $object["child"];
419 $this->format_options[(string) $this->counter]["title"] = $object["title"];
420 $this->format_options[(string) $this->counter]["type"] = $object["type"];
421 $this->format_options[(string) $this->counter]["obj_id"] = $object["obj_id"];
422 $this->format_options[(string) $this->counter]["desc"] = "obj_" . $object["type"];
423 $this->format_options[(string) $this->counter]["depth"] = $tab;
424 $this->format_options[(string) $this->counter]["container"] = false;
425 $this->format_options[(string) $this->counter]["visible"] = true;
426 $this->format_options[(string) $this->counter]["highlighted_subtree"] = $a_highlighted_subtree;
427
428 // Create prefix array
429 for ($i = 0; $i < $tab; ++$i) {
430 $this->format_options[(string) $this->counter]["tab"][] = 'blank';
431 }
432
433 // fix explorer (sometimes explorer disappears)
434 if ($parent_index === 0) {
435 if (!$this->expand_all && !in_array($object["parent"], $this->expanded)) {
436 $this->expanded[] = $object["parent"];
437 }
438 }
439
440 // only if parent is expanded and visible, object is visible
441 if ($object["child"] != $this->getRoot() && ((!$this->expand_all && !in_array($object["parent"], $this->expanded))
442 or !$this->format_options[(string) $parent_index]["visible"])) {
443 if (!$this->forceExpanded($object["child"])) {
444 // if parent is not expanded, and one child is
445 // visible we don't need more information and
446 // can skip the rest of the childs
447 if ($this->format_options[(string) $this->counter]["visible"]) {
448 //echo "-setSkipping";
449 $skip_rest = true;
450 }
451 $this->format_options[(string) $this->counter]["visible"] = false;
452 }
453 }
454
455 // if object exists parent is container
456 if ($object["child"] != $this->getRoot()) {
457 $this->format_options[(string) $parent_index]["container"] = true;
458
459 if ($this->expand_all || in_array($object["parent"], $this->expanded)) {
460 //echo "<br>-".$object["child"]."-".$this->forceExpanded($object["child"])."-";
461 if ($this->forceExpanded($object["parent"])) {
462 $this->format_options[(string) $parent_index]["tab"][($tab - 2)] = 'forceexp';
463 } else {
464 $this->format_options[(string) $parent_index]["tab"][($tab - 2)] = 'minus';
465 }
466 } else {
467 $this->format_options[(string) $parent_index]["tab"][($tab - 2)] = 'plus';
468 }
469 }
470 //echo "-"."$parent_index"."-";
471 //var_dump($this->format_options["$parent_index"]);
473
474 // stop recursion if 2. level beyond expanded nodes is reached
475 if ($this->expand_all || in_array($object["parent"], $this->expanded) or ($object["parent"] == 0)
476 or $this->forceExpanded($object["child"])) {
477 $highlighted_subtree = $a_highlighted_subtree ||
478 ($object["child"] == $this->highlighted);
479
480 // recursive
481 $this->setOutput($object["child"], $a_depth, $object['obj_id'], $highlighted_subtree);
482 }
483 } //if
484 } //if FILTER
485 } //foreach
486 } //if
487 } //function
488
489 public function modifyChilds(
490 $a_parent_id,
491 array $a_objects
492 ): array {
493 return $a_objects;
494 }
495
501 public function showChilds($a_parent_id): bool
502 {
503 return true;
504 }
505
509 public function forceExpanded($a_obj_id): bool
510 {
511 return false;
512 }
513
514 public function getMaximumTreeDepth(): int
515 {
516 return 0; // seems to not return the value...
517 }
518
519
520 public function getOutput(): string
521 {
522 $tpl = $this->tpl;
524
525 $this->format_options[0]["tab"] = array();
526
527 $depth = $this->getMaximumTreeDepth();
528
529 for ($i = 0;$i < $depth;++$i) {
530 $this->createLines($i);
531 }
532
533 $tpl->addJavaScript("assets/js/ilExplorer.js");
534
535 //echo "hh";
536 // set global body class
537 // $tpl->setBodyClass("il_Explorer");
538
539 $tpl_tree = new ilTemplate("tpl.tree.html", true, true, "components/ILIAS/UIComponent/Explorer");
540
541 // updater
542 if (($this->requestStr("ict") !== "" ||
543 $this->requestStr("collapseAll") !== "" ||
544 $this->requestStr("expandAll") !== "") && $this->up_frame !== "") {
545 $tpl_tree->setCurrentBlock("updater");
546 $tpl_tree->setVariable("UPDATE_FRAME", $this->up_frame);
547 $tpl_tree->setVariable("UPDATE_SCRIPT", $this->up_script);
548 if (is_array($this->up_params)) {
549 $up_str = $lim = "";
550 foreach ($this->up_params as $p) {
551 $up_str .= $lim . "'" . $p . "'";
552 $lim = ",";
553 }
554 $tpl_tree->setVariable("UPDATE_PARAMS", $up_str);
555 }
556 $tpl_tree->parseCurrentBlock();
557 }
558 $cur_depth = -1;
559 foreach ($this->format_options as $key => $options) {
560 //echo "-".$options["depth"]."-";
561 if (!($options["visible"] ?? false)) {
562 continue;
563 }
564
565 // end tags
566 $this->handleListEndTags($tpl_tree, $cur_depth, $options["depth"]);
567
568 // start tags
569 $this->handleListStartTags($tpl_tree, $cur_depth, $options["depth"]);
570
571 $cur_depth = $options["depth"];
572
573 if ($options["visible"] and $key != 0) {
574 $this->formatObject($tpl_tree, $options["child"], $options, $options['obj_id']);
575 }
576 if ($key == 0) {
577 $this->formatHeader($tpl_tree, $options["child"], $options);
578 }
579 }
580
581 $this->handleListEndTags($tpl_tree, $cur_depth, -1);
582
583 $tpl_tree->setVariable("TREE_LEAD", "");
584 if ($this->tree_lead !== "") {
585 $tpl_tree->setCurrentBlock("tree_lead");
586 $tpl_tree->setVariable("TREE_LEAD", $this->tree_lead);
587 $tpl_tree->parseCurrentBlock();
588 }
589 if ($this->getId() !== "") {
590 $tpl_tree->setVariable("TREE_ID", 'id="' . $this->getId() . '_tree"');
591 }
592
593 $html = $tpl_tree->get();
594
595 if ($this->getUseStandardFrame()) {
596 $mtpl = new ilGlobalTemplate("tpl.main.html", true, true);
597 $mtpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation());
598 $mtpl->setVariable("BODY_CLASS", "il_Explorer");
599 $mtpl->addBlockFile("CONTENT", "content", "tpl.explorer.html");
600 if ($this->getTitle() !== "") {
601 $mtpl->setVariable("TXT_EXPLORER_HEADER", $this->getTitle());
602 }
603 if ($this->getId() !== "") {
604 $mtpl->setVariable("ID", 'id="' . $this->getId() . '"');
605 }
606 $mtpl->setVariable("IMG_SPACE", ilUtil::getImagePath("media/spacer.png", false));
607 $mtpl->setCurrentBlock("content");
608 $mtpl->setVariable("EXPLORER", $html);
609 $mtpl->setVariable("EXP_REFRESH", $lng->txt("refresh"));
610 $mtpl->parseCurrentBlock();
611 $html = $mtpl->get();
612 }
613
614 return $html;
615 }
616
617
618
622 public function handleListEndTags(
623 ilTemplate $a_tpl_tree,
624 int $a_cur_depth,
625 int $a_item_depth
626 ): void {
627 if ($a_item_depth < $a_cur_depth) {
628 // </li></ul> for ending lists
629 for ($i = 0; $i < ($a_cur_depth - $a_item_depth); $i++) {
630 $a_tpl_tree->touchBlock("end_list_item");
631 $a_tpl_tree->touchBlock("element");
632
633 $a_tpl_tree->touchBlock("end_list");
634 $a_tpl_tree->touchBlock("element");
635 }
636 } elseif ($a_item_depth == $a_cur_depth) {
637 // </li> for ending list items
638 $a_tpl_tree->touchBlock("end_list_item");
639 $a_tpl_tree->touchBlock("element");
640 }
641 }
642
646 public function handleListStartTags(
647 ilTemplate $a_tpl_tree,
648 int $a_cur_depth,
649 int $a_item_depth
650 ): void {
651 // start tags
652 if ($a_item_depth > $a_cur_depth) {
653 // <ul><li> for new lists
654 if ($a_item_depth > 1) {
655 $a_tpl_tree->touchBlock("start_list");
656 } else {
657 $a_tpl_tree->touchBlock("start_list_no_indent");
658 }
659 $a_tpl_tree->touchBlock("element");
660 }
661 $a_tpl_tree->touchBlock("start_list_item");
662 $a_tpl_tree->touchBlock("element");
663 }
664
665 public function formatHeader(
666 ilTemplate $tpl,
667 $a_obj_id,
668 array $a_option
669 ): void {
670 }
671
672 public function formatObject(
673 ilTemplate $tpl,
674 $a_node_id,
675 array $a_option,
676 $a_obj_id = 0
677 ): void {
678 $lng = $this->lng;
679 $ilErr = $this->error;
680
681 if (!isset($a_node_id) or !is_array($a_option)) {
682 $ilErr->raiseError(get_class($this) . "::formatObject(): Missing parameter or wrong datatype! " .
683 "node_id: " . $a_node_id . " options:" . var_export($a_option, true), $ilErr->WARNING);
684 }
685
686 $pic = false;
687 foreach ((array) $a_option["tab"] as $picture) {
688 if ($picture === 'plus') {
689 $tpl->setCurrentBlock("expander");
690 $tpl->setVariable("EXP_DESC", $lng->txt("collapsed"));
691 $tpl->setVariable("LINK_NAME", $a_node_id);
692 if (!$this->getAsynchExpanding()) {
693 $target = $this->createTarget('+', $a_node_id, $a_option["highlighted_subtree"]);
694 $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
695 } else {
696 $target = $this->createTarget('+', $a_node_id, $a_option["highlighted_subtree"], false);
697 $tpl->setVariable("ONCLICK_TARGET_EXPANDER", " onclick=\"return il.Explorer.refresh('tree_div', '" . $target . "');\"");
698 $tpl->setVariable("LINK_TARGET_EXPANDER", "#");
699 }
700 $tpl->setVariable("IMGPATH", $this->getImage("browser/plus.png"));
701 $tpl->parseCurrentBlock();
702 $pic = true;
703 }
704
705 if ($picture === 'forceexp') {
706 $tpl->setCurrentBlock("expander");
707 $tpl->setVariable("EXP_DESC", $lng->txt("expanded"));
708 $target = $this->createTarget('+', $a_node_id);
709 $tpl->setVariable("LINK_NAME", $a_node_id);
710 $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
711 $tpl->setVariable("IMGPATH", $this->getImage("browser/forceexp.png"));
712 $tpl->parseCurrentBlock();
713 $pic = true;
714 }
715
716 if ($picture === 'minus' && $this->show_minus) {
717 $tpl->setCurrentBlock("expander");
718 $tpl->setVariable("EXP_DESC", $lng->txt("expanded"));
719 $tpl->setVariable("LINK_NAME", $a_node_id);
720 if (!$this->getAsynchExpanding()) {
721 $target = $this->createTarget('-', $a_node_id, $a_option["highlighted_subtree"]);
722 $tpl->setVariable("LINK_TARGET_EXPANDER", $target);
723 } else {
724 $target = $this->createTarget('-', $a_node_id, $a_option["highlighted_subtree"], false);
725 $tpl->setVariable("ONCLICK_TARGET_EXPANDER", " onclick=\"return il.Explorer.refresh('tree_div', '" . $target . "');\"");
726 $tpl->setVariable("LINK_TARGET_EXPANDER", "#");
727 }
728 $tpl->setVariable("IMGPATH", $this->getImage("browser/minus.png"));
729 $tpl->parseCurrentBlock();
730 $pic = true;
731 }
732 }
733
734 if (!$pic) {
735 $tpl->setCurrentBlock("blank");
736 $tpl->setVariable("BLANK_PATH", $this->getImage("browser/blank.png"));
737 $tpl->parseCurrentBlock();
738 }
739
740 if ($this->output_icons) {
741 $tpl->setCurrentBlock("icon");
742 $tpl->setVariable("ICON_IMAGE", $this->getImage("standard/icon_" . $a_option["type"] . ".svg", $a_option["type"], $a_obj_id));
743
744 $tpl->setVariable("TARGET_ID", "iconid_" . $a_node_id);
745 $this->iconList[] = "iconid_" . $a_node_id;
746 $tpl->setVariable(
747 "TXT_ALT_IMG",
748 $this->getImageAlt($lng->txt("icon") . " " . $lng->txt($a_option["desc"]), $a_option["type"], $a_obj_id)
749 );
750 $tpl->parseCurrentBlock();
751 }
752
753 if (($sel = $this->buildSelect($a_node_id, $a_option['type'])) !== '') {
754 $tpl->setCurrentBlock('select');
755 $tpl->setVariable('OBJ_SEL', $sel);
756 $tpl->parseCurrentBlock();
757 }
758
759 if ($this->isClickable($a_option["type"], $a_node_id)) { // output link
760 $tpl->setCurrentBlock("link");
761 //$target = (strpos($this->target, "?") === false) ?
762 // $this->target."?" : $this->target."&";
763 //$tpl->setVariable("LINK_TARGET", $target.$this->target_get."=".$a_node_id.$this->params_get);
764 $tpl->setVariable("LINK_TARGET", $this->buildLinkTarget($a_node_id, $a_option["type"]));
765
766 $style_class = $this->getNodeStyleClass($a_node_id, $a_option["type"]);
767
768 if ($style_class !== "") {
769 $tpl->setVariable("A_CLASS", ' class="' . $style_class . '" ');
770 }
771
772 if (($onclick = $this->buildOnClick($a_node_id, $a_option["type"], $a_option["title"])) != "") {
773 $tpl->setVariable("ONCLICK", "onClick=\"$onclick\"");
774 }
775
776 //$tpl->setVariable("LINK_NAME", $a_node_id);
777 $tpl->setVariable(
778 "TITLE",
780 $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]),
781 $this->textwidth,
782 true
783 )
784 );
785 $tpl->setVariable(
786 "DESC",
788 $this->buildDescription($a_option["description"] ?? "", $a_node_id, $a_option["type"]),
789 $this->textwidth,
790 true
791 )
792 );
793 $frame_target = $this->buildFrameTarget($a_option["type"], $a_node_id, $a_option["obj_id"]);
794 if ($frame_target !== "") {
795 $tpl->setVariable("TARGET", " target=\"" . $frame_target . "\"");
796 }
797 } else { // output text only
798 $tpl->setCurrentBlock("text");
799 $tpl->setVariable(
800 "OBJ_TITLE",
802 $this->buildTitle($a_option["title"], $a_node_id, $a_option["type"]),
803 $this->textwidth,
804 true
805 )
806 );
807 $tpl->setVariable(
808 "OBJ_DESC",
810 $this->buildDescription($a_option["desc"], $a_node_id, $a_option["type"]),
811 $this->textwidth,
812 true
813 )
814 );
815 }
816 $tpl->parseCurrentBlock();
817
818 $tpl->setCurrentBlock("list_item");
819 $tpl->parseCurrentBlock();
820 $tpl->touchBlock("element");
821 }
822
823 public function getImage(
824 string $a_name,
825 string $a_type = "",
826 $a_obj_id = ""
827 ): string {
828 return ilUtil::getImagePath($a_name);
829 }
830
831 public function getImageAlt(
832 string $a_default_text,
833 string $a_type = "",
834 $a_obj_id = ""
835 ): string {
836 return $a_default_text;
837 }
838
839 public function getNodeStyleClass(
840 $a_id,
841 string $a_type
842 ): string {
843 if ($a_id == $this->highlighted) {
844 return "il_HighlightedNode";
845 }
846 return "";
847 }
848
849 public function buildLinkTarget(
850 $a_node_id,
851 string $a_type
852 ): string {
853 $target = (strpos($this->target, "?") === false)
854 ? $this->target . "?"
855 : $this->target . "&";
856 return $target . $this->target_get . "=" . $a_node_id . $this->params_get;
857 }
858
859 public function buildOnClick(
860 $a_node_id,
861 string $a_type,
862 string $a_title
863 ): string {
864 return "";
865 }
866
867 public function buildTitle(
868 string $a_title,
869 $a_id,
870 string $a_type
871 ): string {
872 return $a_title;
873 }
874
875 public function buildDescription(
876 string $a_desc,
877 $a_id,
878 string $a_type
879 ): string {
880 return "";
881 }
882
886 public function buildSelect($a_node_id, string $a_type): string
887 {
888 return "";
889 }
890
891 public function buildFrameTarget(
892 string $a_type,
893 $a_child = 0,
894 $a_obj_id = 0
895 ): string {
896 return $this->frame_target;
897 }
898
899
900 public function createTarget(
901 string $a_type,
902 $a_node_id,
903 bool $a_highlighted_subtree = false,
904 bool $a_append_anch = true
905 ): string {
906 $ilErr = $this->error;
907
908 if (!isset($a_type) or !is_string($a_type) or !isset($a_node_id)) {
909 $ilErr->raiseError(get_class($this) . "::createTarget(): Missing parameter or wrong datatype! " .
910 "type: " . $a_type . " node_id:" . $a_node_id, $ilErr->WARNING);
911 }
912
913 // SET expand parameter:
914 // positive if object is expanded
915 // negative if object is compressed
916 $a_node_id = $a_type === '+' ? $a_node_id : -(int) $a_node_id;
917
918 $sep = (is_int(strpos($this->expand_target, "?")))
919 ? "&"
920 : "?";
921
922 // in current tree flag
923 $ict_str = ($a_highlighted_subtree || $this->highlighted === "")
924 ? "&ict=1"
925 : "";
926 if ($this->getAsynchExpanding()) {
927 $ict_str .= "&cmdMode=asynch";
928 }
929 if ($a_append_anch) {
930 return $this->expand_target . $sep . $this->expand_variable . "=" . $a_node_id . $this->params_get . $ict_str . "#" . abs($a_node_id);
931 } else {
932 return $this->expand_target . $sep . $this->expand_variable . "=" . $a_node_id . $this->params_get . $ict_str;
933 }
934 }
935
936 public function setFrameTarget(string $a_target): void
937 {
938 $this->frame_target = $a_target;
939 }
940
941 public function createLines(int $a_depth): void
942 {
943 for ($i = 0, $iMax = count($this->format_options); $i < $iMax; ++$i) {
944 if ($this->format_options[$i]["depth"] == $a_depth + 1
945 and !$this->format_options[$i]["container"]
946 and $this->format_options[$i]["depth"] != 1) {
947 $this->format_options[$i]["tab"][(string) $a_depth] = "quer";
948 }
949
950 if ($this->format_options[$i]["depth"] == $a_depth + 2) {
951 if ($this->is_in_array($i + 1, $this->format_options[$i]["depth"])) {
952 $this->format_options[$i]["tab"][(string) $a_depth] = "winkel";
953 } else {
954 $this->format_options[$i]["tab"][(string) $a_depth] = "ecke";
955 }
956 }
957
958 if ($this->format_options[$i]["depth"] > $a_depth + 2) {
959 if ($this->is_in_array($i + 1, $a_depth + 2)) {
960 $this->format_options[$i]["tab"][(string) $a_depth] = "hoch";
961 }
962 }
963 }
964 }
965
966 public function is_in_array(
967 int $a_start,
968 int $a_depth
969 ): bool {
970 for ($i = $a_start, $iMax = count($this->format_options); $i < $iMax; ++$i) {
971 if ($this->format_options[$i]["depth"] < $a_depth) {
972 break;
973 }
974
975 if ($this->format_options[$i]["depth"] == $a_depth) {
976 return true;
977 }
978 }
979 return false;
980 }
981
982 // get index of format_options array from specific ref_id,parent_id
983 public function getIndex(array $a_data): int
984 {
985 if (!is_array($this->format_options)) {
986 return -1;
987 }
988
989 foreach ($this->format_options as $key => $value) {
990 if (($value["child"] == $a_data["parent"])) {
991 return $key;
992 }
993 }
994
995 return -1;
996 }
997
998 public function addFilter(string $a_item): bool
999 {
1000 if (is_array($this->filter)) {
1001 //run through filter
1002 foreach ($this->filter as $item) {
1003 if ($item === $a_item) {
1004 return false;
1005 }
1006 }
1007 } else {
1008 $this->filter = array();
1009 }
1010 $this->filter[] = $a_item;
1011
1012 return true;
1013 }
1014
1015 public function delFilter(string $a_item): bool
1016 {
1017 $deleted = 0;
1018 //check if a filter exists
1019 if (is_array($this->filter)) {
1020 //build copy of the existing filter without the given item
1021 $tmp = array();
1022
1023 foreach ($this->filter as $item) {
1024 if ($item !== $a_item) {
1025 $tmp[] = $item;
1026 } else {
1027 $deleted = 1;
1028 }
1029 }
1030
1031 $this->filter = $tmp;
1032 } else {
1033 return false;
1034 }
1035
1036 return $deleted === 1;
1037 }
1038
1043 public function setExpand($a_node_id): void
1044 {
1045 // IF ISN'T SET CREATE SESSION VARIABLE
1046 if (!is_array(ilSession::get($this->expand_variable))) {
1047 ilSession::set($this->expand_variable, [$this->getRoot()]);
1048 }
1049 if ($a_node_id > 0 && !in_array($a_node_id, ilSession::get($this->expand_variable))) {
1050 $exp = ilSession::get($this->expand_variable);
1051 $exp[] = $a_node_id;
1052 ilSession::set($this->expand_variable, $exp);
1053 }
1054 if ($a_node_id < 0) {
1055 $key = array_keys(ilSession::get($this->expand_variable), -(int) $a_node_id);
1056 $exp = ilSession::get($this->expand_variable);
1057 if (isset($key[0]) && isset($exp[$key[0]])) {
1058 unset($exp[$key[0]]);
1059 }
1060 ilSession::set($this->expand_variable, $exp);
1061 }
1062 $this->expanded = (array) ilSession::get($this->expand_variable);
1063 }
1064
1069 public function forceExpandAll(
1070 bool $a_mode,
1071 bool $a_show_minus = true
1072 ): void {
1073 $this->expand_all = $a_mode;
1074 $this->show_minus = $a_show_minus;
1075 }
1076
1077 public function setFiltered(bool $a_bool): bool
1078 {
1079 $this->filtered = $a_bool;
1080 return true;
1081 }
1082
1083 public function checkFilter(string $a_item): bool
1084 {
1085 if (is_array($this->filter)) {
1086 if (in_array($a_item, $this->filter)) {
1087 $ret = true;
1088 } else {
1089 $ret = false;
1090 }
1091 } else {
1092 $ret = false;
1093 }
1094
1095 if ($this->getFilterMode() === IL_FM_NEGATIVE) {
1096 return $ret;
1097 } else {
1098 return !$ret;
1099 }
1100 }
1101
1105 public function sortNodes(array $a_nodes, $a_parent_obj_id): array
1106 {
1107 $adm_node = null;
1108 foreach ($a_nodes as $key => $node) {
1109 if ($node["type"] === "adm") {
1110 $match = $key;
1111 $adm_node = $node;
1112 break;
1113 }
1114 }
1115
1116 // cut off adm node
1117 if (isset($match)) {
1118 array_splice($a_nodes, $match, 1);
1119 }
1120
1121 $a_nodes = ilArrayUtil::sortArray($a_nodes, $this->order_column, $this->order_direction);
1122
1123 // append adm node to end of list
1124 if (isset($match)) {
1125 $a_nodes[] = $adm_node;
1126 }
1127
1128 return $a_nodes;
1129 }
1130}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
const IL_FM_POSITIVE
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_FM_NEGATIVE
error(string $a_errmsg)
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
Error Handling & global info handling.
class for explorer view in admin frame
isClickable(string $type, int $ref_id=0)
setTitle(string $a_val)
handleListStartTags(ilTemplate $a_tpl_tree, int $a_cur_depth, int $a_item_depth)
handle list start tags (
setTreeLead(string $a_val)
addFilter(string $a_item)
ilRbacSystem $rbacsystem
ILIAS Refinery Factory $refinery
buildSelect($a_node_id, string $a_type)
standard implementation for adding an option select box between image and title
buildOnClick( $a_node_id, string $a_type, string $a_title)
ilErrorHandling $error
setOrderColumn(string $a_column)
getNodeStyleClass( $a_id, string $a_type)
showChilds($a_parent_id)
determines wether the childs of an object should be shown or not note: this standard implementation a...
setExpand($a_node_id)
set the expand option this value is stored in a SESSION variable to save it different view (lo view,...
checkPermissions(bool $a_check)
string $expand_variable
delFilter(string $a_item)
setRoot($a_root_id)
ILIAS HTTP Wrapper WrapperFactory $wrapper
formatHeader(ilTemplate $tpl, $a_obj_id, array $a_option)
buildTitle(string $a_title, $a_id, string $a_type)
getImageAlt(string $a_default_text, string $a_type="", $a_obj_id="")
buildFrameTarget(string $a_type, $a_child=0, $a_obj_id=0)
setTargetGet(string $a_target_get)
outputIcons(bool $a_icons)
string $order_direction
string $order_column
initItemCounter(int $a_number)
setFilterMode(int $a_mode=IL_FM_NEGATIVE)
string $target_get
setSessionExpandVariable(string $a_var_name="expand")
array $format_options
string $expand_target
modifyChilds( $a_parent_id, array $a_objects)
string $highlighted
buildDescription(string $a_desc, $a_id, string $a_type)
is_in_array(int $a_start, int $a_depth)
getImage(string $a_name, string $a_type="", $a_obj_id="")
setTitleLength(int $a_length)
bool $use_standard_frame
checkFilter(string $a_item)
setClickable(string $a_type, bool $a_clickable)
handleListEndTags(ilTemplate $a_tpl_tree, int $a_cur_depth, int $a_item_depth)
handle list end tags ( and )
ilObjectDefinition $obj_definition
getIndex(array $a_data)
requestStr(string $key)
buildLinkTarget( $a_node_id, string $a_type)
setParamsGet(array $a_params_get)
setFrameTarget(string $a_target)
getChildsOfNode($a_parent_id)
string $frame_target
setUseStandardFrame(bool $a_val)
Set use standard frame.
string $a_up_script
ilLanguage $lng
setExpandTarget(string $a_exp_target)
target script for expand icons
createTarget(string $a_type, $a_node_id, bool $a_highlighted_subtree=false, bool $a_append_anch=true)
setOrderDirection(string $a_direction)
setFiltered(bool $a_bool)
setId(string $a_val)
string $params_get
forceExpanded($a_obj_id)
force expansion of node
highlightNode(string $a_id)
forceExpandAll(bool $a_mode, bool $a_show_minus=true)
force expandAll.
setFrameUpdater(string $a_up_frame, string $a_up_script, string $a_params="")
setPostSort(bool $a_sort)
setAsynchExpanding(bool $a_val)
setOutput( $a_parent_id, int $a_depth=1, int $a_obj_id=0, bool $a_highlighted_subtree=false)
Creates output for explorer view in admin menue recursive method.
ilGlobalTemplateInterface $tpl
sortNodes(array $a_nodes, $a_parent_obj_id)
sort nodes and put adm object to the end of sorted array
isVisible( $a_ref_id, string $a_type)
createLines(int $a_depth)
special template class to simplify handling of ITX/PEAR
language handling
parses the objects.xml it handles the xml-description of all ilias objects
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
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 get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
touchBlock(string $block)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Util class various functions, usage as namespace.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static getStyleSheetLocation(string $mode="output", string $a_css_name="")
get full style sheet file name (path inclusive) of current user
const ROOT_FOLDER_ID
Definition: constants.php:32
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, array $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $lng
Definition: privfeed.php:31
$_SERVER['HTTP_HOST']
Definition: raiseError.php:26
$ilErr
Definition: raiseError.php:33
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26
$counter