ILIAS  release_8 Revision v8.24
class.ilHierarchyFormGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use ILIAS\HTTP;
23
31{
33 protected string $exp_target_script = "";
34 protected string $icon = "";
35 protected string $exp_id = "";
36 protected ilLanguage $lng;
37 protected ilCtrl $ctrl;
38 protected string $expand_variable = "";
39 protected ?array $white_list = null;
40 protected array $highlighted_nodes = [];
41 protected string $focus_id = "";
42 protected string $exp_frame = "";
43 protected string $triggered_update_command = "";
44 protected array $drag_target = [];
45 protected array $drag_content = [];
46 protected object $parent_obj;
47 protected string $parent_cmd = "";
48 protected ilTree $tree;
49 protected int $currenttopnodeid = 0;
50 protected string $title = "";
51 protected string $checkboxname = "";
52 protected string $dragicon = "";
53 protected int $maxdepth = 0;
54 protected array $help_items = [];
55 protected array $diss_menues = [];
56 protected array $multi_commands = [];
57 protected array $commands = [];
58 protected array $expanded = [];
60 protected Refinery\Factory $refinery;
61
62
63 public function __construct()
64 {
65 global $DIC;
66
67 $this->lng = $DIC->language();
68 $this->ctrl = $DIC->ctrl();
69 $lng = $DIC->language();
70 $this->main_tpl = $DIC->ui()->mainTemplate();
71
72 $this->maxdepth = -1;
73 $this->multi_commands = array();
74 $this->commands = array();
75 $this->drag_target[] = array();
76 $this->drag_content[] = array();
77 $lng->loadLanguageModule("form");
78 $this->setCheckboxName("cbox");
79 $this->help_items = array();
80
82 $this->main_tpl->addJavascript("./Services/Form/js/ServiceFormHierarchyForm.js");
83
84
85 $this->http = $DIC->http();
86 $this->refinery = $DIC->refinery();
87 }
88
89 public function setParentCommand(
90 object $a_parent_obj,
91 string $a_parent_cmd
92 ): void {
93 $this->parent_obj = $a_parent_obj;
94 $this->parent_cmd = $a_parent_cmd;
95 }
96
97 public function getParentObject(): object
98 {
99 return $this->parent_obj;
100 }
101
102 public function getParentCommand(): string
103 {
104 return $this->parent_cmd;
105 }
106
110 public function setId(string $a_id): void
111 {
112 throw new ilException("ilHierarchyFormGUI does currently not support multiple forms (multiple IDs). ID is always hform.");
113 }
114
115 public function getId(): string
116 {
117 return "hform";
118 }
119
120 public function setTree(ilTree $a_tree): void
121 {
122 $this->tree = $a_tree;
123 }
124
125 public function getTree(): ilTree
126 {
127 return $this->tree;
128 }
129
130 public function setCurrentTopNodeId(int $a_currenttopnodeid): void
131 {
132 $this->currenttopnodeid = $a_currenttopnodeid;
133 }
134
135 public function getCurrentTopNodeId(): int
136 {
137 return $this->currenttopnodeid;
138 }
139
140 public function setTitle(string $a_title): void
141 {
142 $this->title = $a_title;
143 }
144
145 public function getTitle(): string
146 {
147 return $this->title;
148 }
149
150 public function setIcon(string $a_icon): void
151 {
152 $this->icon = $a_icon;
153 }
154
155 public function getIcon(): string
156 {
157 return $this->icon;
158 }
159
160 public function setCheckboxName(string $a_checkboxname): void
161 {
162 $this->checkboxname = $a_checkboxname;
163 }
164
165 public function getCheckboxName(): string
166 {
167 return $this->checkboxname;
168 }
169
170 public function setDragIcon(string $a_dragicon): void
171 {
172 $this->dragicon = $a_dragicon;
173 }
174
175 public function getDragIcon(): string
176 {
177 return $this->dragicon;
178 }
179
180 public function setMaxDepth(int $a_maxdepth): void
181 {
182 $this->maxdepth = $a_maxdepth;
183 }
184
185 public function getMaxDepth(): int
186 {
187 return $this->maxdepth;
188 }
189
190 public function setExplorerUpdater(
191 string $a_exp_frame,
192 string $a_exp_id,
193 string $a_exp_target_script
194 ): void {
195 $this->exp_frame = $a_exp_frame;
196 $this->exp_id = $a_exp_id;
197 $this->exp_target_script = $a_exp_target_script;
198 }
199
201 string $a_triggered_update_command
202 ): void {
203 $this->triggered_update_command = $a_triggered_update_command;
204 }
205
206 public function addHelpItem(
207 string $a_text,
208 string $a_image = ""
209 ): void {
210 $this->help_items[] = array("text" => $a_text,
211 "image" => $a_image);
212 }
213
214 public function getHelpItems(): array
215 {
216 return $this->help_items;
217 }
218
219 // Makes a nodes (following droparea) a drag target
220 public function makeDragTarget(
221 string $a_id,
222 string $a_group,
223 bool $a_first_child_drop_area = false,
224 bool $a_as_subitem = false,
225 string $a_diss_text = ""
226 ): void {
227 if ($a_first_child_drop_area == true) { // first child drop areas only insert as subitems
228 $a_as_subitem = true;
229 }
230
231 if ($a_id != "") {
232 if ($a_first_child_drop_area) {
233 $a_id .= "fc";
234 }
235
236 $this->drag_target[] = array("id" => $a_id, "group" => $a_group);
237 $this->diss_menues[$a_id][$a_group][] = array("subitem" => $a_as_subitem, "text" => $a_diss_text);
238 }
239 }
240
241 // Makes a node a drag content
242 public function makeDragContent(
243 string $a_id,
244 string $a_group
245 ): void {
246 if ($a_id != "") {
247 $this->drag_content[] = array("id" => $a_id, "group" => $a_group);
248 }
249 }
250
251 // Add a multi command (for selection of items)
252 public function addMultiCommand(
253 string $a_txt,
254 string $a_cmd
255 ): void {
256 $this->multi_commands[] = array("text" => $a_txt, "cmd" => $a_cmd);
257 }
258
259 public function addCommand(
260 string $a_txt,
261 string $a_cmd
262 ): void {
263 $this->commands[] = array("text" => $a_txt, "cmd" => $a_cmd);
264 }
265
266 public function setHighlightedNodes(
267 array $a_val
268 ): void {
269 $this->highlighted_nodes = $a_val;
270 }
271
272 public function getHighlightedNodes(): array
273 {
274 return $this->highlighted_nodes;
275 }
276
277 public function setFocusId(string $a_val): void
278 {
279 $this->focus_id = $a_val;
280 }
281
282 public function getFocusId(): string
283 {
284 return $this->focus_id;
285 }
286
287 public function setExpandVariable(string $a_val): void
288 {
289 $this->expand_variable = $a_val;
290 }
291
292 public function getExpandVariable(): string
293 {
294 return $this->expand_variable;
295 }
296
297 public function setExpanded(array $a_val): void
298 {
299 $this->expanded = $a_val;
300 }
301
302 public function getExpanded(): array
303 {
304 return $this->expanded;
305 }
306
307 protected function str($key): string
308 {
309 return self::_str($key);
310 }
311
312 protected static function _str($key): string
313 {
314 global $DIC;
315
316 $w = $DIC->http()->wrapper();
317 $t = $DIC->refinery()->kindlyTo()->string();
318
319 if (!$w->post()->has($key) && !$w->query()->has($key)) {
320 return "";
321 }
322
323 $val = (string) ($w->post()->retrieve($key, $t) ?? "");
324
325 if ($val == "") {
326 $val = (string) ($w->query()->retrieve($key, $t) ?? "");
327 }
328 return ilUtil::stripSlashes($val);
329 }
330
331
332 public function updateExpanded(): void
333 {
334 $ev = $this->getExpandVariable();
335 $node_id = 0;
336 if ($ev == "") {
337 return;
338 }
339
340 // init empty session
341 if (!is_array(ilSession::get($ev))) {
342 ilSession::set($ev, array($this->getTree()->getRootId()));
343 }
344
345 if ($this->str("il_hform_expand") != "") {
346 $node_id = $this->str("il_hform_expand");
347 }
348 if ($this->str($ev) != "") {
349 $node_id = $this->str($ev);
350 }
351
352 // if positive => expand this node
353 if ($node_id > 0 && !in_array($node_id, ilSession::get($ev))) {
354 $nodes = ilSession::get($ev);
355 $nodes[] = $node_id;
356 ilSession::set($ev, $nodes);
357 }
358 // if negative => compress this node
359 if ($node_id < 0) {
360 $key = array_keys(ilSession::get($ev), -(int) $node_id);
361 $nodes = ilSession::get($ev);
362 unset($nodes[$ev][$key[0]]);
363 ilSession::set($ev, $nodes);
364 }
365 $this->setExpanded(ilSession::get($ev));
366 }
367
368 public function setTypeWhiteList(array $a_val): void
369 {
370 $this->white_list = $a_val;
371 }
372
373 public function getTypeWhiteList(): array
374 {
375 return $this->white_list;
376 }
377
382 public function getChilds(?int $a_node_id = null): array
383 {
384 if ($a_node_id == null) {
385 $a_node_id = $this->getCurrentTopNodeId();
386 }
387
388 $tree_childs = $this->getTree()->getChilds($a_node_id);
389 $childs = array();
390 foreach ($tree_childs as $tree_child) {
391 if (!isset($this->white_list) || !is_array($this->white_list) || in_array($tree_child["type"], $this->white_list)) {
392 $childs[] = array("node_id" => $tree_child["child"],
393 "title" => $tree_child["title"],
394 "type" => $tree_child["type"],
395 "depth" => $tree_child["depth"]
396 );
397 }
398 }
399
400 return $childs;
401 }
402
403 public function getContent(): string
404 {
406 $single = false;
407 $multi = false;
408
409 if ($this->getExpandVariable() != "") {
410 $this->updateExpanded();
411 }
412
413 $ttpl = new ilTemplate("tpl.hierarchy_form.html", true, true, "Services/Form");
414 $ttpl->setVariable("TXT_SAVING", $lng->txt("saving"));
415 $top_node_data = $this->getTree()->getNodeData($this->getCurrentTopNodeId());
416 $top_node = array("node_id" => $top_node_data["child"] ?? 0,
417 "title" => $top_node_data["title"] ?? "",
418 "type" => $top_node_data["type"] ?? "");
419
420 $childs = [];
421 $nodes_html = $this->getLevelHTML($top_node, 0, $childs);
422
423
424 // commands
425 $secs = array("1", "2");
426 foreach ($secs as $sec) {
427 reset($this->commands);
428 reset($this->multi_commands);
429 if (count($this->multi_commands) > 0 || count($this->commands) > 0) {
430 if (count($childs) > 0) {
431 $single = false;
432 foreach ($this->commands as $cmd) {
433 $ttpl->setCurrentBlock("cmd" . $sec);
434 $ttpl->setVariable("CMD", $cmd["cmd"]);
435 $ttpl->setVariable("CMD_TXT", $cmd["text"]);
436 $ttpl->parseCurrentBlock();
437 $single = true;
438 }
439
440 $multi = false;
441 foreach ($this->multi_commands as $cmd) {
442 $ttpl->setCurrentBlock("multi_cmd" . $sec);
443 $ttpl->setVariable("MULTI_CMD", $cmd["cmd"]);
444 $ttpl->setVariable("MULTI_CMD_TXT", $cmd["text"]);
445 $ttpl->parseCurrentBlock();
446 $multi = true;
447 }
448 if ($multi) {
449 $ttpl->setCurrentBlock("multi_cmds" . $sec);
450 $ttpl->setVariable("MCMD_ALT", $lng->txt("commands"));
451 if ($sec == "1") {
452 $ttpl->setVariable("MCMD_IMG", ilUtil::getImagePath("arrow_downright.svg"));
453 } else {
454 $ttpl->setVariable("MCMD_IMG", ilUtil::getImagePath("arrow_upright.svg"));
455 }
456 $ttpl->parseCurrentBlock();
457 }
458 }
459
460 if ($single || $multi) {
461 $ttpl->setCurrentBlock("commands" . $sec);
462 $ttpl->parseCurrentBlock();
463 }
464 $single = true;
465 }
466 }
467
468 // explorer updater
469 /*
470 if ($this->exp_frame != "") {
471 $ttpl->setCurrentBlock("updater");
472 $ttpl->setVariable("UPDATER_FRAME", $this->exp_frame);
473 $ttpl->setVariable("EXP_ID_UPDATER", $this->exp_id);
474 $ttpl->setVariable("HREF_UPDATER", $this->exp_target_script);
475 $ttpl->parseCurrentBlock();
476 }*/
477
478 // drag and drop initialisation
479 foreach ($this->drag_target as $drag_target) {
480 $this->main_tpl->addOnLoadCode('d = new ilDragTarget("droparea_" + "'.($drag_target["id"] ?? "").
481 '", "'.($drag_target["group"] ?? "").'");');
482 }
483 foreach ($this->drag_content as $drag_content) {
484 $this->main_tpl->addOnLoadCode('d = new ilDragContent("il_img_" + "'.($drag_content["id"] ?? "").
485 '", "'.($drag_content["group"] ?? "").'");');
486 }
487
488 // disambiguation menues and "insert as first child" flags
489 if (is_array($this->diss_menues)) {
490 foreach ($this->diss_menues as $node_id => $d_menu) {
491 foreach ($d_menu as $group => $menu) {
492 if (count($menu) > 1) {
493 foreach ($menu as $menu_item) {
494 $ttpl->setCurrentBlock("dmenu_cmd");
495 $ttpl->setVariable("SUBITEM", (int) $menu_item["subitem"]);
496 $ttpl->setVariable("TXT_MENU_CMD", $menu_item["text"]);
497 $ttpl->parseCurrentBlock();
498 }
499
500 $ttpl->setCurrentBlock("disambiguation_menu");
501 $ttpl->setVariable("DNODE_ID", $node_id);
502 $ttpl->setVariable("GRP", $group);
503 $ttpl->parseCurrentBlock();
504 } elseif (count($menu) == 1) {
505 // set first child flag
506 $this->main_tpl->addOnLoadCode('as_subitem["'.$node_id.'" + "_" + "'.$group.'"] = "'.(int) $menu[0]["subitem"].'";');
507 }
508 }
509 }
510 }
511// $this->diss_menues[$a_id][$a_group][] = array("type" => $a_type, "text" => $a_diss_text);
512
513
514 if ($this->triggered_update_command != "") {
515 $ttpl->setCurrentBlock("tr_update");
516 $ttpl->setVariable("UPDATE_CMD", $this->triggered_update_command);
517 $ttpl->parseCurrentBlock();
518 }
519
520 // disambiguation menues and "insert as first child" flags
521 if (is_array($this->diss_menues)) {
522 foreach ($this->diss_menues as $node_id => $d_menu) {
523 foreach ($d_menu as $group => $menu) {
524 if (count($menu) > 1) {
525 foreach ($menu as $menu_item) {
526 $ttpl->setCurrentBlock("dmenu_cmd");
527 $ttpl->setVariable("SUBITEM", (int) $menu_item["subitem"]);
528 $ttpl->setVariable("TXT_MENU_CMD", $menu_item["text"]);
529 $ttpl->parseCurrentBlock();
530 }
531
532 $ttpl->setCurrentBlock("disambiguation_menu");
533 $ttpl->setVariable("DNODE_ID", $node_id);
534 $ttpl->setVariable("GRP", $group);
535 $ttpl->parseCurrentBlock();
536 } elseif (count($menu) == 1) {
537 // set first child flag
538 $this->main_tpl->addOnLoadCode('as_subitem["'.$node_id.'" + "_" + "'.$group.'"] = "'.(int) $menu[0]["subitem"].'";');
539 }
540 }
541 }
542 }
543 //$this->diss_menues[$a_id][$a_group][] = array("type" => $a_type, "text" => $a_diss_text);
544
545 // nodes
546 $ttpl->setVariable("NODES", $nodes_html);
547
548 // title
549 //echo "<br>".htmlentities($this->getTitle())." --- ".htmlentities(ilUtil::prepareFormOutput($this->getTitle()));
550 $ttpl->setVariable("TITLE", $this->getTitle());
551
552
553 return $ttpl->get();
554 }
555
556 public function getLegend(): string
557 {
559
560 $ttpl = new ilTemplate("tpl.hierarchy_form_legend.html", true, true, "Services/Form");
561 if ($this->getDragIcon() != "") {
562 $ttpl->setCurrentBlock("help_drag");
563 $ttpl->setVariable("IMG_DRAG", $this->getDragIcon());
564 $ttpl->setVariable(
565 "DRAG_ARROW",
567 );
568 $ttpl->setVariable(
569 "TXT_DRAG",
570 $lng->txt("form_hierarchy_drag_drop_help")
571 );
572 $ttpl->setVariable("PLUS", ilGlyphGUI::get(ilGlyphGUI::ADD));
573 $ttpl->parseCurrentBlock();
574 }
575
576 // additional help items
577 foreach ($this->getHelpItems() as $help) {
578 if ($help["image"] != "") {
579 $ttpl->setCurrentBlock("help_img");
580 $ttpl->setVariable("IMG_HELP", $help["image"]);
581 $ttpl->parseCurrentBlock();
582 }
583 $ttpl->setCurrentBlock("help_item");
584 $ttpl->setVariable("TXT_HELP", $help["text"]);
585 $ttpl->parseCurrentBlock();
586 }
587
588 $ttpl->setVariable(
589 "TXT_ADD_EL",
590 $lng->txt("form_hierarchy_add_elements")
591 );
592 $ttpl->setVariable("PLUS2", ilGlyphGUI::get(ilGlyphGUI::ADD));
593
594 return $ttpl->get();
595 }
596
597 public function getLevelHTML(
598 array $a_par_node,
599 int $a_depth,
600 array &$a_childs
601 ): string {
602 $lng = $this->lng;
603
604 if ($this->getMaxDepth() > -1 && $this->getMaxDepth() < $a_depth) {
605 return "";
606 }
607
608 $childs = $this->getChilds((int) $a_par_node["node_id"]);
609 $a_childs = $childs;
610 $ttpl = new ilTemplate("tpl.hierarchy_form_nodes.html", true, true, "Services/Form");
611
612 // prepended drop area
613 if ($this->nodeAllowsChilds($a_par_node) && (count($childs) > 0 || $a_depth == 0)) {
614 $ttpl->setCurrentBlock("drop_area");
615 $ttpl->setVariable("DNODE_ID", $a_par_node["node_id"] . "fc"); // fc means "first child"
616 $ttpl->setVariable("IMG_BLANK", ilUtil::getImagePath("spacer.png"));
617 if (count($childs) == 0) {
618 $ttpl->setVariable("NO_CONTENT_CLASS", "ilCOPGNoPageContent");
619 $ttpl->setVariable("NO_CONTENT_TXT", " &nbsp;" . $lng->txt("form_hier_click_to_add"));
620 }
621 $ttpl->parseCurrentBlock();
622
623 $this->manageDragAndDrop($a_par_node, $a_depth, true, null, $childs);
624 $menu_items = $this->getMenuItems($a_par_node, $a_depth, true, null, $childs);
625 //var_dump($menu_items);
626 if (count($menu_items) > 0) {
627 // determine maximum of multi add numbers
628 $max = 1;
629 foreach ($menu_items as $menu_item) {
630 if ($menu_item["multi"] > $max) {
631 $max = $menu_item["multi"];
632 }
633 }
634
635 reset($menu_items);
636 $mcnt = 1;
637 foreach ($menu_items as $menu_item) {
638 if ($menu_item["multi"] > 1) {
639 for ($i = 1; $i <= $menu_item["multi"]; $i++) {
640 $ttpl->setCurrentBlock("multi_add");
641 $ttpl->setVariable("MA_NUM", $i);
642 $ttpl->setVariable("MENU_CMD", $menu_item["cmd"]);
643 $ttpl->setVariable("FC", "1");
644 $ttpl->setVariable("CMD_NODE", $a_par_node["node_id"]);
645 $ttpl->setVariable("MCNT", $mcnt . "fc");
646 $ttpl->parseCurrentBlock();
647 }
648 }
649
650 // buffer td for lower multis
651 if ($max > $menu_item["multi"]) {
652 $ttpl->setCurrentBlock("multi_buffer");
653 $ttpl->setVariable("BUF_SPAN", $max - $menu_item["multi"]);
654 $ttpl->parseCurrentBlock();
655 }
656 $ttpl->setCurrentBlock("menu_cmd");
657 $ttpl->setVariable("TXT_MENU_CMD", $menu_item["text"]);
658 $ttpl->setVariable("MENU_CMD", $menu_item["cmd"]);
659 $ttpl->setVariable("CMD_NODE", $a_par_node["node_id"]);
660 $ttpl->setVariable("FC", "1");
661 $ttpl->setVariable("MCNT", $mcnt . "fc");
662 $ttpl->parseCurrentBlock();
663 $mcnt++;
664 }
665 $ttpl->setCurrentBlock("drop_area_menu");
666 $ttpl->setVariable("MNODE_ID", $a_par_node["node_id"] . "fc");
667 $ttpl->parseCurrentBlock();
668
669 $ttpl->setCurrentBlock("element");
670 $ttpl->parseCurrentBlock();
671 }
672 }
673
674 // insert childs
675 if (count($childs) > 0) {
676 for ($i = 0, $iMax = count($childs); $i < $iMax; $i++) {
677 $next_sibling = ($i < (count($childs) - 1))
678 ? $childs[$i + 1]
679 : null;
680
681 $this->renderChild($ttpl, $childs[$i], $a_depth, $next_sibling);
682 }
683 }
684
685 $html = $ttpl->get();
686 unset($ttpl);
687
688 return $html;
689 }
690
694 public function renderChild(
695 ilTemplate $a_tpl,
696 array $a_child,
697 int $a_depth,
698 ?array $next_sibling = null
699 ) {
700 $ilCtrl = $this->ctrl;
701
702 // image
703 $a_tpl->setCurrentBlock("img");
704 $a_tpl->setVariable("IMGPATH", $this->getChildIcon($a_child));
705 $a_tpl->setVariable("IMGALT", $this->getChildIconAlt($a_child));
706 $a_tpl->setVariable("IMG_NODE", $a_child["node_id"]);
707 $a_tpl->setVariable("NODE_ID", $a_child["node_id"]);
708 $a_tpl->setVariable("TYPE", $a_child["type"]);
709 $a_tpl->parseCurrentBlock();
710
711 // checkbox
712 $a_tpl->setCurrentBlock("cbox");
713 $a_tpl->setVariable("CNODE_ID", $a_child["node_id"]);
714 $a_tpl->setVariable("CBOX_NAME", $this->getCheckboxName());
715 $a_tpl->parseCurrentBlock();
716
717 // node info
718 if (($info = $this->getChildInfo($a_child)) != "") {
719 $a_tpl->setCurrentBlock("node_info");
720 $a_tpl->setVariable("NODE_INFO", $info);
721 $a_tpl->parseCurrentBlock();
722 }
723
724 // commands of child node
725 $child_commands = $this->getChildCommands($a_child);
726 if (is_array($child_commands)) {
727 foreach ($child_commands as $command) {
728 $a_tpl->setCurrentBlock("node_cmd");
729 $a_tpl->setVariable("HREF_NODE_CMD", $command["link"]);
730 $a_tpl->setVariable("TXT_NODE_CMD", $command["text"]);
731 $a_tpl->parseCurrentBlock();
732 }
733 }
734
735 // title
736 $a_tpl->setCurrentBlock("text");
737 $hl = $this->getHighlightedNodes();
738 if (is_array($hl) && in_array($a_child["node_id"], $hl)) {
739 $a_tpl->setVariable("CLASS", ' class="ilHFormHighlighted" ');
740 }
741 $a_tpl->setVariable("VAL_TITLE", ilLegacyFormElementsUtil::prepareFormOutput($this->getChildTitle($a_child)));
742 $a_tpl->setVariable("TNODE_ID", $a_child["node_id"]);
743 $a_tpl->parseCurrentBlock();
744 $grandchilds = [];
745 $grandchilds_html = $this->getLevelHTML($a_child, $a_depth + 1, $grandchilds);
746
747 // focus
748 if ($this->getFocusId() == $a_child["node_id"]) {
749 $this->main_tpl->addOnLoadCode('document.getElementById("inp'.$a_child["node_id"].'").focus();');
750 }
751
752 // expander
753 if ($this->getExpandVariable() != "") {
754 $a_tpl->setCurrentBlock("expand_icon");
755 if (!is_null($grandchilds) && count($grandchilds) > 0) {
756 if (!in_array($a_child["node_id"], $this->getExpanded())) {
757 $ilCtrl->setParameter($this->getParentObject(), $this->getExpandVariable(), $a_child["node_id"]);
758 $a_tpl->setVariable("IMG_EXPAND", ilUtil::getImagePath("browser/plus.png"));
759 $a_tpl->setVariable("HREF_NAME", "n" . $a_child["node_id"]);
760 $a_tpl->setVariable(
761 "HREF_EXPAND",
762 $ilCtrl->getLinkTarget($this->getParentObject(), $this->getParentCommand(), "n" . $a_child["node_id"])
763 );
764 $grandchilds_html = "";
765 } else {
766 $ilCtrl->setParameter($this->getParentObject(), $this->getExpandVariable(), -$a_child["node_id"]);
767 $a_tpl->setVariable("IMG_EXPAND", ilUtil::getImagePath("browser/minus.png"));
768 $a_tpl->setVariable("HREF_NAME", "n" . $a_child["node_id"]);
769 $a_tpl->setVariable(
770 "HREF_EXPAND",
771 $ilCtrl->getLinkTarget($this->getParentObject(), $this->getParentCommand(), "n" . $a_child["node_id"])
772 );
773 }
774 $ilCtrl->setParameter($this->getParentObject(), $this->getExpandVariable(), "");
775 } else {
776 $a_tpl->setVariable("IMG_EXPAND", ilUtil::getImagePath("spacer.png"));
777 }
778 $a_tpl->parseCurrentBlock();
779 }
780
781 // childs
782 $a_tpl->setCurrentBlock("list_item");
783 $a_tpl->setVariable("CHILDS", $grandchilds_html);
784 $a_tpl->parseCurrentBlock();
785
786 $a_tpl->setCurrentBlock("element");
787 $a_tpl->parseCurrentBlock();
788
789 // drop area after child
790 $a_tpl->setCurrentBlock("drop_area");
791 $a_tpl->setVariable("DNODE_ID", $a_child["node_id"]);
792 $a_tpl->setVariable("IMG_BLANK", ilUtil::getImagePath("spacer.png"));
793 $a_tpl->parseCurrentBlock();
794
795 // manage drag and drop areas
796 $this->manageDragAndDrop($a_child, $a_depth, false, $next_sibling, $grandchilds);
797
798 // drop area menu
799 $menu_items = $this->getMenuItems($a_child, $a_depth, false, $next_sibling, $grandchilds);
800 if (count($menu_items) > 0) {
801 // determine maximum of multi add numbers
802 $max = 1;
803 foreach ($menu_items as $menu_item) {
804 if ($menu_item["multi"] > $max) {
805 $max = $menu_item["multi"];
806 }
807 }
808
809 reset($menu_items);
810 $mcnt = 1;
811 foreach ($menu_items as $menu_item) {
812 if ($menu_item["multi"] > 1) {
813 for ($i = 1; $i <= $menu_item["multi"]; $i++) {
814 $a_tpl->setCurrentBlock("multi_add");
815 $a_tpl->setVariable("MA_NUM", $i);
816 $a_tpl->setVariable("MENU_CMD", $menu_item["cmd"]);
817 if ($menu_item["as_subitem"] ?? false) {
818 $a_tpl->setVariable("FC", "1");
819 $a_tpl->setVariable("MCNT", $mcnt . "fc");
820 } else {
821 $a_tpl->setVariable("FC", "0");
822 $a_tpl->setVariable("MCNT", $mcnt);
823 }
824 $a_tpl->setVariable("CMD_NODE", $a_child["node_id"]);
825 $a_tpl->parseCurrentBlock();
826 }
827 }
828
829 // buffer td for lower multis
830 if ($max > $menu_item["multi"]) {
831 $a_tpl->setCurrentBlock("multi_buffer");
832 $a_tpl->setVariable("BUF_SPAN", $max - $menu_item["multi"]);
833 $a_tpl->parseCurrentBlock();
834 }
835
836 $a_tpl->setCurrentBlock("menu_cmd");
837 $a_tpl->setVariable("TXT_MENU_CMD", $menu_item["text"]);
838 $a_tpl->setVariable("MENU_CMD", $menu_item["cmd"]);
839 if ($menu_item["as_subitem"] ?? false) {
840 $a_tpl->setVariable("FC", "1");
841 $a_tpl->setVariable("MCNT", $mcnt . "fc");
842 } else {
843 $a_tpl->setVariable("FC", "0");
844 $a_tpl->setVariable("MCNT", $mcnt);
845 }
846 $a_tpl->setVariable("CMD_NODE", $a_child["node_id"]);
847 $a_tpl->parseCurrentBlock();
848 $mcnt++;
849 }
850 $a_tpl->setCurrentBlock("drop_area_menu");
851 $a_tpl->setVariable("MNODE_ID", $a_child["node_id"]);
852 $a_tpl->parseCurrentBlock();
853 }
854
855 $a_tpl->setCurrentBlock("element");
856 $a_tpl->parseCurrentBlock();
857 }
858
859 public function getChildIcon(array $a_item): string
860 {
861 return ilUtil::getImagePath("icon_" . $a_item["type"] . ".svg");
862 }
863
864 public function getChildIconAlt(array $a_item): string
865 {
867
868 return $lng->txt($a_item["type"]);
869 }
870
871 public function getChildCommands(array $a_item): array
872 {
873 return [];
874 }
875
876 public function getChildTitle(array $a_child): string
877 {
878 return $a_child["title"];
879 }
880
881 public function getChildInfo(array $a_child): string
882 {
883 return "";
884 }
885
896 public function getMenuItems(
897 array $a_node,
898 int $a_depth,
899 bool $a_first_child = false,
900 ?array $a_next_sibling = null,
901 ?array $a_childs = null
902 ): array {
903 return array();
904 }
905
910 public function nodeAllowsChilds(array $a_node): bool
911 {
912 return true;
913 }
914
920 public function manageDragAndDrop(
921 array $a_node,
922 int $a_depth,
923 bool $a_first_child = false,
924 ?array $a_next_sibling = null,
925 ?array $a_childs = null
926 ): void {
927 //$this->makeDragTarget($a_node["id"], $a_group);
928 //$this->makeDragTarget($a_node["id"], $a_group);
929 }
930
934 public static function getPostMulti(): int
935 {
936 return max(1, (int) self::_str("il_hform_multi"));
937 }
938
942 public static function getPostNodeId(): string
943 {
944 return self::_str("il_hform_node");
945 }
946
950 public static function getPostFirstChild(): bool
951 {
952 return ((int) self::_str("il_hform_fc") == 1);
953 }
954
955 public function getHTML(): string
956 {
957 return parent::getHTML() . $this->getLegend();
958 }
959
960 public static function getPostFields(): array
961 {
962 return array(
963 "il_hform_node" => self::_str("il_hform_node"),
964 "il_hform_fc" => self::_str("il_hform_fc"),
965 "il_hform_as_subitem" => self::_str("il_hform_as_subitem"),
966 "il_hform_multi" => self::_str("il_hform_multi"),
967 "il_hform_source_id" => self::_str("il_hform_source_id"),
968 "il_hform_target_id" => self::_str("il_hform_target_id")
969 );
970 }
971}
static return function(ContainerConfigurator $containerConfigurator)
Definition: basic_rector.php:9
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
return true
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static get(string $a_glyph, string $a_text="")
This class represents a hierarchical form.
static getPostNodeId()
Get node ID of _POST input.
setCheckboxName(string $a_checkboxname)
setParentCommand(object $a_parent_obj, string $a_parent_cmd)
makeDragTarget(string $a_id, string $a_group, bool $a_first_child_drop_area=false, bool $a_as_subitem=false, string $a_diss_text="")
setTriggeredUpdateCommand(string $a_triggered_update_command)
setExplorerUpdater(string $a_exp_frame, string $a_exp_id, string $a_exp_target_script)
addHelpItem(string $a_text, string $a_image="")
renderChild(ilTemplate $a_tpl, array $a_child, int $a_depth, ?array $next_sibling=null)
Render a single child (including grandchilds)
addCommand(string $a_txt, string $a_cmd)
makeDragContent(string $a_id, string $a_group)
getChilds(?int $a_node_id=null)
Get all childs of current node.
nodeAllowsChilds(array $a_node)
Checks, whether current nodes allows childs at all.
setCurrentTopNodeId(int $a_currenttopnodeid)
getMenuItems(array $a_node, int $a_depth, bool $a_first_child=false, ?array $a_next_sibling=null, ?array $a_childs=null)
Get menu items for drop area of node.
manageDragAndDrop(array $a_node, int $a_depth, bool $a_first_child=false, ?array $a_next_sibling=null, ?array $a_childs=null)
Makes nodes drag and drop content and targets.
setDragIcon(string $a_dragicon)
addMultiCommand(string $a_txt, string $a_cmd)
getLevelHTML(array $a_par_node, int $a_depth, array &$a_childs)
ilGlobalTemplateInterface $main_tpl
static getPostFirstChild()
Should node be inserted as first child of target node (true) or as successor (false)
language handling
loadLanguageModule(string $a_module)
Load language module.
static prepareFormOutput($a_str, bool $a_strip=false)
static get(string $a_var)
static set(string $a_var, $a_val)
Set a value.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
static initDragDrop(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI Drag and Drop used in Modules/Survey, Services/Calendar, Services/COPage,...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $key
Consumer key/client ID value.
Definition: System.php:193
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: ByTrying.php:21
$lng