ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilGroupedListGUI.php
Go to the documentation of this file.
1<?php
2
27{
28 protected ilCtrl $ctrl;
29 protected bool $multi_column = false;
30 protected array $items = array();
31 protected bool $as_dropdown = false;
32 protected bool $dd_pullright = false;
33 protected string $id;
34
35 public function __construct(string $id = "")
36 {
38 global $DIC;
39
40 $this->id = $id;
41 $this->ctrl = $DIC->ctrl();
42 }
43
44 public function setAsDropDown(
45 bool $a_val,
46 bool $a_pullright = false
47 ): void {
48 $this->as_dropdown = $a_val;
49 $this->dd_pullright = $a_pullright;
50 }
51
52 public function getAsDropDown(): bool
53 {
54 return $this->as_dropdown;
55 }
56
57 public function addGroupHeader(
58 string $a_content,
59 string $a_add_class = ""
60 ): void {
61 $this->items[] = array("type" => "group_head", "content" => $a_content,
62 "add_class" => $a_add_class);
63 }
64
65 public function addSeparator(): void
66 {
67 $this->items[] = array("type" => "sep");
68 }
69
70 public function nextColumn(): void
71 {
72 $this->items[] = array("type" => "next_col");
73 $this->multi_column = true;
74 }
75
76 public function addEntry(
77 string $a_content,
78 string $a_href = "",
79 string $a_target = "",
80 string $a_onclick = "",
81 string $a_add_class = "",
82 string $a_id = "",
83 string $a_ttip = "",
84 string $a_tt_my = "right center",
85 string $a_tt_at = "left center",
86 bool $a_tt_use_htmlspecialchars = true
87 ): void {
88 $this->items[] = array("type" => "entry", "content" => $a_content,
89 "href" => $a_href, "target" => $a_target, "onclick" => $a_onclick,
90 "add_class" => $a_add_class, "id" => $a_id, "ttip" => $a_ttip,
91 "tt_my" => $a_tt_my, "tt_at" => $a_tt_at,
92 "tt_use_htmlspecialchars" => $a_tt_use_htmlspecialchars);
93 }
94
95 public function getHTML(): string
96 {
97 $ilCtrl = $this->ctrl;
98
99 $tpl = new ilTemplate("tpl.grouped_list.html", true, true, "components/ILIAS/UIComponent/GroupedList");
100 $tt_calls = "";
101 foreach ($this->items as $i) {
102 switch ($i["type"]) {
103 case "sep":
104 $tpl->touchBlock("sep");
105 $tpl->touchBlock("item");
106 break;
107
108 case "next_col":
109 $tpl->touchBlock("next_col");
110 $tpl->touchBlock("item");
111 break;
112
113 case "group_head":
114 $tpl->setCurrentBlock("group_head");
115 if ($i["add_class"] != "") {
116 $tpl->setVariable("ADD_CLASS", $i["add_class"]);
117 }
118 $tpl->setVariable("GROUP_HEAD", $i["content"]);
119 $tpl->parseCurrentBlock();
120 $tpl->touchBlock("item");
121 break;
122
123 case "entry":
124 if ($i["href"] != "") {
125 $tpl->setCurrentBlock("linked_entry");
126 if ($i["add_class"] != "") {
127 $tpl->setVariable("ADD_CLASS", $i["add_class"]);
128 }
129 $tpl->setVariable("HREF", str_replace('&amp;', '&', ilUtil::secureUrl($i["href"])));
130 $tpl->setVariable("TXT_ENTRY", $i["content"]);
131 if ($i["target"] != "") {
132 $tpl->setVariable("TARGET", 'target="' . $i["target"] . '"');
133 } else {
134 $tpl->setVariable("TARGET", 'target="_top"');
135 }
136 if ($i["onclick"] != "") {
137 $tpl->setVariable("ONCLICK", 'onclick="' . $i["onclick"] . '"');
138 }
139 if ($i["id"] != "") {
140 $tpl->setVariable("ID", 'id="' . $i["id"] . '"');
141 }
142 if ($this->getAsDropDown()) {
143 $tpl->setVariable("ITEM_ROLE", 'role="menuitem"');
144 }
145 $tpl->parseCurrentBlock();
146 $tpl->touchBlock("item");
147 } else {
148 $tpl->setCurrentBlock("unlinked_entry");
149 if ($i["add_class"] != "") {
150 $tpl->setVariable("ADD_CLASS2", $i["add_class"]);
151 }
152 $tpl->setVariable("TXT_ENTRY2", $i["content"]);
153 $tpl->parseCurrentBlock();
154 }
155 break;
156 }
157 }
158
159 if ($this->multi_column) {
160 $tpl->touchBlock("multi_start");
161 $tpl->touchBlock("multi_end");
162 }
163
164 if ($tt_calls !== "") {
165 $tpl->setCurrentBlock("script");
166 $tpl->setVariable("TT_CALLS", $tt_calls);
167 $tpl->parseCurrentBlock();
168 }
169
170 if ($this->id !== "") {
171 $tpl->setCurrentBlock("id");
172 $tpl->setVariable("ID", $this->id);
173 $tpl->parseCurrentBlock();
174 }
175
176 if ($this->getAsDropDown()) {
177 if ($this->dd_pullright) {
178 $tpl->setVariable("LIST_CLASS", "dropdown-menu pull-right");
179 } else {
180 $tpl->setVariable("LIST_CLASS", "dropdown-menu");
181 }
182 $tpl->setVariable("LIST_ROLE", 'role="menu"');
183 } else {
184 $tpl->setVariable("LIST_CLASS", "");
185 $tpl->setVariable("LIST_ROLE", "");
186 }
187
188 return $tpl->get();
189 }
190}
Class ilCtrl provides processing control methods.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addGroupHeader(string $a_content, string $a_add_class="")
addEntry(string $a_content, string $a_href="", string $a_target="", string $a_onclick="", string $a_add_class="", string $a_id="", string $a_ttip="", string $a_tt_my="right center", string $a_tt_at="left center", bool $a_tt_use_htmlspecialchars=true)
setAsDropDown(bool $a_val, bool $a_pullright=false)
special template class to simplify handling of ITX/PEAR
static secureUrl(string $url)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26