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