ILIAS  release_8 Revision v8.24
class.ilTabsGUI.php
Go to the documentation of this file.
1<?php
2
24{
25 protected ilCtrl $ctrl;
26
27 public string $target_script;
28 public string $obj_type;
31 public array $tabs;
32 public array $target = array();
33 public array $sub_target = array();
34 public array $non_tabbed_link = array();
35 public bool $setup_mode = false;
36 protected bool $force_one_tab = false;
37 protected bool $manual_activation;
39 protected bool $sub_tabs;
40 protected string $temp_var;
41 protected string $back_title;
42 public string $back_target;
43 protected string $back_2_target;
44 protected string $back_2_title;
45 protected string $back_2_frame;
46 protected string $back_frame;
47
48 public function __construct()
49 {
51 global $DIC;
52
53 $this->ctrl = $DIC->ctrl();
54 $this->tpl = $DIC->ui()->mainTemplate();
55 $lng = $DIC->language();
56 $this->lng = $lng;
57 $this->manual_activation = false;
58 $this->subtab_manual_activation = false;
59 $this->temp_var = "TABS";
60 $this->sub_tabs = false;
61 $this->back_title = "";
62 $this->back_target = "";
63 $this->back_2_target = "";
64 $this->back_2_title = "";
65 }
66
67 public function setSetupMode(bool $a_val): void
68 {
69 $this->setup_mode = $a_val;
70 }
71
72 public function getSetupMode(): bool
73 {
74 return $this->setup_mode;
75 }
76
77 public function setBackTarget(
78 string $a_title,
79 string $a_target,
80 string $a_frame = ""
81 ): void {
82 $this->back_title = $a_title;
83 $this->back_target = $a_target;
84 $this->back_frame = $a_frame;
85 }
86
87 public function setBack2Target(
88 string $a_title,
89 string $a_target,
90 string $a_frame = ""
91 ): void {
92 $this->back_2_title = $a_title;
93 $this->back_2_target = $a_target;
94 $this->back_2_frame = $a_frame;
95 }
96
97 public function setForcePresentationOfSingleTab(bool $a_val): void
98 {
99 $this->force_one_tab = $a_val;
100 }
101
102 public function getForcePresentationOfSingleTab(): bool
103 {
104 return $this->force_one_tab;
105 }
106
112 public function addTarget(
113 string $a_text,
114 string $a_link,
115 $a_cmd = "",
116 $a_cmdClass = "",
117 string $a_frame = "",
118 bool $a_activate = false,
119 bool $a_dir_text = false
120 ): void {
121 if (!$a_cmdClass) {
122 $a_cmdClass = array();
123 }
124 $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
125
126 if ($a_activate) {
127 $this->manual_activation = true;
128 }
129 $this->target[] = array("text" => $a_text, "link" => $a_link,
130 "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
131 "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
132 }
133
137 public function addTab(
138 string $a_id,
139 string $a_text,
140 string $a_link,
141 string $a_frame = ""
142 ): void {
143 $this->target[] = array("text" => $a_text, "link" => $a_link,
144 "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
145 }
146
150 public function removeTab(string $a_id): void
151 {
152 foreach ($this->target as $key => $target) {
153 if ($target['id'] == $a_id) {
154 unset($this->target[$key]);
155 }
156 }
157 }
158
162 public function removeSubTab(string $a_id): void
163 {
164 foreach ($this->sub_target as $i => $sub_target) {
165 if ($this->sub_target[$i]['id'] == $a_id) {
166 unset($this->sub_target[$i]);
167 }
168 }
169 }
170
174 public function replaceTab(
175 string $a_old_id,
176 string $a_new_id,
177 string $a_text,
178 string $a_link,
179 string $a_frame = ''
180 ): void {
181 for ($i = 0, $iMax = count($this->target); $i < $iMax; $i++) {
182 if ($this->target[$i]['id'] == $a_old_id) {
183 $this->target[$i] = array(
184 "text" => $a_text,
185 "link" => $a_link,
186 "frame" => $a_frame,
187 "dir_text" => true,
188 "id" => $a_new_id,
189 "cmdClass" => array());
190 }
191 }
192 }
193
197 public function clearTargets(): void
198 {
199 global $DIC;
200
201 $ilHelp = $DIC["ilHelp"] ?? null;
202
203 if (!$this->getSetupMode()) {
204 $ilHelp->setScreenIdComponent("");
205 }
206
207 $this->target = array();
208 $this->sub_target = array();
209 $this->non_tabbed_link = array();
210 $this->back_title = "";
211 $this->back_target = "";
212 $this->back_2_target = "";
213 $this->back_2_title = "";
214 $this->setTabActive("");
215 $this->setSubTabActive("");
216 }
217
223 public function addSubTabTarget(
224 string $a_text,
225 string $a_link,
226 $a_cmd = "",
227 $a_cmdClass = "",
228 string $a_frame = "",
229 bool $a_activate = false,
230 bool $a_dir_text = false
231 ): void {
232 if (!$a_cmdClass) {
233 $a_cmdClass = array();
234 }
235 $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
236 #$a_cmdClass = strtolower($a_cmdClass);
237
238 if ($a_activate) {
239 $this->subtab_manual_activation = true;
240 }
241 $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
242 "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
243 "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
244 }
245
246 public function addSubTab(
247 string $a_id,
248 string $a_text,
249 string $a_link,
250 string $a_frame = ""
251 ): void {
252 $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
253 "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
254 }
255
259 public function setTabActive(string $a_id): void
260 {
261 foreach ($this->target as $key => $target) {
262 $this->target[$key]['activate'] = $this->target[$key]['id'] === $a_id;
263 }
264 if ($a_id !== "") {
265 $this->manual_activation = true;
266 } else {
267 $this->manual_activation = false;
268 }
269 }
270
271 public function activateTab(string $a_id): void
272 {
273 $this->setTabActive($a_id);
274 }
275
279 public function setSubTabActive(string $a_text): void
280 {
281 for ($i = 0, $iMax = count($this->sub_target); $i < $iMax; $i++) {
282 $this->sub_target[$i]['activate'] = $this->sub_target[$i]['id'] === $a_text;
283 }
284 $this->subtab_manual_activation = true;
285 }
286
287 public function activateSubTab(string $a_id): void
288 {
289 $this->setSubTabActive($a_id);
290 }
291
292 public function clearSubTabs(): void
293 {
294 $this->sub_target = array();
295 }
296
297 public function getHTML(bool $a_after_tabs_anchor = false): string
298 {
299 return $this->__getHTML(false, $a_after_tabs_anchor);
300 }
301
302 public function getSubTabHTML(): string
303 {
304 return $this->__getHTML(true);
305 }
306
307 public function addNonTabbedLink(
308 string $a_id,
309 string $a_text,
310 string $a_link,
311 string $a_frame = ""
312 ): void {
313 $this->non_tabbed_link[] = array("text" => $a_text, "link" => $a_link,
314 "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
315 }
316
317 public function removeNonTabbedLinks(): void
318 {
319 $this->non_tabbed_link = [];
320 }
321
322 private function __getHTML(
323 bool $a_get_sub_tabs,
324 bool $a_after_tabs_anchor = false
325 ): string {
327 global $DIC;
328
329 $cmd = null;
330 $cmdClass = null;
331 $sr_pre = "";
332 $hash = "";
333
334 $ilHelp = $DIC["ilHelp"] ?? null;
335
336 $ilCtrl = $this->ctrl;
338 $ilUser = null;
339 if (isset($DIC["ilUser"])) {
340 $ilUser = $DIC->user();
341 }
342 $component_factory = $DIC["component.factory"] ?? null;
343
344 // user interface hook [uihk]
345 if ($component_factory && !$this->getSetupMode()) {
346 foreach ($component_factory->getActivePluginsInSlot("uihk") as $plugin) {
347 $gui_class = $plugin->getUIClassInstance();
348 $resp = $gui_class->modifyGUI(
349 "",
350 $a_get_sub_tabs ? "sub_tabs" : "tabs",
351 array("tabs" => $this)
352 );
353 }
354 }
355
356
357 // user interface hook [uihk]
358 if (!$this->getSetupMode()) {
359 $cmd = $ilCtrl->getCmd();
360 $cmdClass = $ilCtrl->getCmdClass();
361 }
362
363 if ($a_get_sub_tabs) {
364 $tpl = new ilTemplate("tpl.sub_tabs.html", true, true, "Services/UIComponent/Tabs");
365 $pre = "sub";
366 $pre2 = "SUB_";
367 $sr_pre = "sub_";
368 } else {
369 $tpl = new ilTemplate("tpl.tabs.html", true, true, "Services/UIComponent/Tabs");
370 if ($a_after_tabs_anchor) {
371 $tpl->touchBlock("after_tabs");
372 }
373 $pre = $pre2 = "";
374
375 // back 2 tab
376 if ($this->back_2_title !== "") {
377 $tpl->setCurrentBlock("back_2_tab");
378 $tpl->setVariable("BACK_2_ICON", ilGlyphGUI::get(ilGlyphGUI::PREVIOUS, ilGlyphGUI::NO_TEXT));
379 $tpl->setVariable("BACK_2_TAB_LINK", ilUtil::secureUrl($this->back_2_target));
380 $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
381 if ($this->back_2_frame !== "") {
382 $tpl->setVariable("BACK_2_TAB_TARGET", ' target="' . $this->back_2_frame . '" ');
383 }
384
385 $tpl->parseCurrentBlock();
386 }
387
388 // back tab
389 if ($this->back_title !== "") {
390 $tpl->setCurrentBlock("back_tab");
392 $tpl->setVariable("BACK_TAB_LINK", ilUtil::secureUrl($this->back_target));
393 $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
394 if ($this->back_frame !== "") {
395 $tpl->setVariable("BACK_TAB_TARGET", ' target="' . $this->back_frame . '" ');
396 }
397 $tpl->parseCurrentBlock();
398 }
399 }
400
401 $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
402
403 $i = 0;
404
405 // do not display one tab only
406 if ((count($targets) > 1 || $this->force_one_tab) || ($this->back_title !== "" && !$a_get_sub_tabs)
407 || (count($this->non_tabbed_link) > 0 && !$a_get_sub_tabs)) {
408 foreach ($targets as $target) {
409 $i++;
410
411 if (isset($target['cmd'])) {
412 if (!is_array($target['cmd'])) {
413 $target['cmd'] = [$target['cmd']];
414 }
415 } else {
416 $target['cmd'] = [];
417 }
418
419 if ($this->isTabActive($a_get_sub_tabs, $target, $cmd, $cmdClass)) {
420 $tabtype = $pre . "tabactive";
421 } else {
422 $tabtype = $pre . "tabinactive";
423 }
424
425 if (($a_get_sub_tabs ? $this->subtab_manual_activation : $this->manual_activation) && ($target["activate"] ?? false)) {
426 $tabtype = $pre . "tabactive";
427 }
428
429 if ($tabtype === "tabactive" || $tabtype === "subtabactive") {
430 $tpl->setCurrentBlock("sel_text");
431 $tpl->setVariable("TXT_SELECTED", $lng->txt("stat_selected"));
432 $tpl->parseCurrentBlock();
433
434 if (!$this->getSetupMode()) {
435 if ($a_get_sub_tabs) {
437 } else {
439 }
440 $ilHelp->setDefaultScreenId($part, $target["id"]);
441 }
442 }
443
444 $tpl->setCurrentBlock($pre . "tab");
445 $tpl->setVariable("ID", $pre . "tab_" . $target["id"]);
446
447 // tooltip
448 if (!$this->getSetupMode()) {
449 $ttext = $ilHelp->getTabTooltipText($target["id"]);
450 if ($ttext !== "") {
452 $pre . "tab_" . $target["id"],
453 $ttext,
454 "",
455 "bottom center",
456 "top center",
457 false
458 );
459 }
460 }
461
462 // bs-patch: start
463 $tabtype = in_array($tabtype, array("tabactive", "subtabactive"))
464 ? "active"
465 : "";
466 // bs-patch: end
467
468 $tpl->setVariable($pre2 . "TAB_TYPE", $tabtype);
469 $hash = "";
470 $tpl->setVariable($pre2 . "TAB_LINK", $target["link"] . $hash);
471 if ($target["dir_text"]) {
472 $tpl->setVariable($pre2 . "TAB_TEXT", $target["text"]);
473 } else {
474 $tpl->setVariable($pre2 . "TAB_TEXT", $lng->txt($target["text"]));
475 }
476 if ($target["frame"] != "") {
477 $tpl->setVariable($pre2 . "TAB_TARGET", ' target="' . $target["frame"] . '" ');
478 }
479 $tpl->parseCurrentBlock();
480 }
481
482 if ($a_get_sub_tabs) {
483 $tpl->setVariable("TXT_SUBTABS", $this->getTabTextOfId($this->getActiveTab()) . ": " . $lng->txt("subtabs"));
484 } else {
485 $tpl->setVariable("TXT_TABS", $lng->txt("tabs"));
486 $tpl->setVariable("LAST_TAB_LABEL", $lng->txt("show_more"));
487
488 // non tabbed links
489 foreach ($this->non_tabbed_link as $link) {
490 $tpl->setCurrentBlock("tab");
491 $tpl->setVariable("TAB_TYPE", "nontabbed");
492 $tpl->setVariable("TAB_ICON", " " . ilGlyphGUI::get(ilGlyphGUI::NEXT, ilGlyphGUI::NO_TEXT));
493 $tpl->setVariable("TAB_TEXT", $link["text"]);
494 $tpl->setVariable("TAB_LINK", $link["link"]);
495 $tpl->setVariable("TAB_TARGET", $link["frame"]);
496 $tpl->setVariable("ID", "nontab_" . $link["id"]);
497 $tpl->parseCurrentBlock();
498
499 // tooltip
500 if (!$this->getSetupMode()) {
501 $ttext = $ilHelp->getTabTooltipText($link["id"]);
502 if ($ttext !== "") {
504 "nontab_" . $link["id"],
505 $ttext,
506 "",
507 "bottom center",
508 "top center",
509 false
510 );
511 }
512 }
513 }
514 }
515
516 return $tpl->get();
517 } else {
518 return "";
519 }
520 }
521
522 protected function getTabTextOfId(string $id): string
523 {
524 foreach ($this->target as $i => $target) {
525 if ($this->target[$i]['id'] == $id) {
526 if ($target["dir_text"]) {
527 return $target["text"];
528 } else {
529 return $this->lng->txt($target["text"]);
530 }
531 }
532 }
533 return "";
534 }
535
536 public function getActiveTab(): string
537 {
538 foreach ($this->target as $i => $target) {
539 if ($this->target[$i]['activate'] ?? null) {
540 return $this->target[$i]['id'];
541 }
542 }
543 return "";
544 }
545
546 public function hasTabs(): bool
547 {
548 return $this->target !== [];
549 }
550
551 private function isTabActive(bool $isSubTabsContext, array $target, ?string $cmd, ?string $cmdClass): bool
552 {
553 if (($isSubTabsContext && $this->subtab_manual_activation) || (!$isSubTabsContext && $this->manual_activation)) {
554 return false;
555 }
556
557 $cmdClass = (string) $cmdClass;
558 $cmd = (string) $cmd;
559
560 $targetMatchesCmdClass = (
561 !$target['cmdClass'] ||
562 in_array(strtolower($cmdClass), array_map('strtolower', $target['cmdClass']), true)
563 );
564
565 $targetMatchesCmd = (
566 in_array(strtolower($cmd), array_map('strtolower', $target['cmd']), true) ||
567 (count($target['cmd']) === 1 && $target['cmd'][0] === '')
568 );
569
570 return $targetMatchesCmd && $targetMatchesCmdClass;
571 }
572}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
return true
Class ilCtrl provides processing control methods.
static get(string $a_glyph, string $a_text="")
const ID_PART_SCREEN
const ID_PART_SUB_SCREEN
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $obj_type
setBack2Target(string $a_title, string $a_target, string $a_frame="")
array $non_tabbed_link
addTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
Add a Tab.
getHTML(bool $a_after_tabs_anchor=false)
removeTab(string $a_id)
Remove a tab identified by its id.
bool $subtab_manual_activation
replaceTab(string $a_old_id, string $a_new_id, string $a_text, string $a_link, string $a_frame='')
Replace a tab.
string $target_script
getForcePresentationOfSingleTab()
ilGlobalTemplateInterface $tpl
string $back_title
setBackTarget(string $a_title, string $a_target, string $a_frame="")
string $back_2_target
setForcePresentationOfSingleTab(bool $a_val)
string $temp_var
addNonTabbedLink(string $a_id, string $a_text, string $a_link, string $a_frame="")
array $sub_target
ilLanguage $lng
setTabActive(string $a_id)
addTarget(string $a_text, string $a_link, $a_cmd="", $a_cmdClass="", string $a_frame="", bool $a_activate=false, bool $a_dir_text=false)
bool $force_one_tab
activateSubTab(string $a_id)
string $back_target
clearTargets()
clear all targets
setSetupMode(bool $a_val)
activateTab(string $a_id)
string $back_2_frame
isTabActive(bool $isSubTabsContext, array $target, ?string $cmd, ?string $cmdClass)
string $back_frame
getTabTextOfId(string $id)
bool $manual_activation
setSubTabActive(string $a_text)
addSubTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
removeSubTab(string $a_id)
Remove a subtab identified by its id.
string $back_2_title
addSubTabTarget(string $a_text, string $a_link, $a_cmd="", $a_cmdClass="", string $a_frame="", bool $a_activate=false, bool $a_dir_text=false)
special template class to simplify handling of ITX/PEAR
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)
static secureUrl(string $url)
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
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
$lng