ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTabsGUI.php
Go to the documentation of this file.
1<?php
2
26{
27 protected ilCtrl $ctrl;
28
29 public string $target_script;
30 public string $obj_type;
33 public array $tabs;
34 public array $target = array();
35 public array $sub_target = array();
36 public array $non_tabbed_link = array();
37 public bool $setup_mode = false;
38 protected bool $force_one_tab = false;
39 protected bool $manual_activation;
41 protected bool $sub_tabs;
42 protected string $temp_var;
43 protected string $back_title;
44 public string $back_target;
45 protected string $back_2_target;
46 protected string $back_2_title;
47 protected string $back_2_frame;
48 protected string $back_frame;
49
50 public function __construct()
51 {
53 global $DIC;
54
55 $this->ctrl = $DIC->ctrl();
56 $this->tpl = $DIC->ui()->mainTemplate();
57 $lng = $DIC->language();
58 $this->lng = $lng;
59 $this->manual_activation = false;
60 $this->subtab_manual_activation = false;
61 $this->temp_var = "TABS";
62 $this->sub_tabs = false;
63 $this->back_title = "";
64 $this->back_target = "";
65 $this->back_2_target = "";
66 $this->back_2_title = "";
67 }
68
69 protected function symbol(): \ILIAS\Repository\Symbol\SymbolAdapterGUI
70 {
71 global $DIC;
72 return $DIC->repository()->internal()->gui()->symbol();
73 }
74
75 public function setSetupMode(bool $a_val): void
76 {
77 $this->setup_mode = $a_val;
78 }
79
80 public function getSetupMode(): bool
81 {
82 return $this->setup_mode;
83 }
84
85 public function setBackTarget(
86 string $a_title,
87 string $a_target,
88 string $a_frame = ""
89 ): void {
90 $this->back_title = $a_title;
91 $this->back_target = $a_target;
92 $this->back_frame = $a_frame;
93 }
94
95 public function setBack2Target(
96 string $a_title,
97 string $a_target,
98 string $a_frame = ""
99 ): void {
100 $this->back_2_title = $a_title;
101 $this->back_2_target = $a_target;
102 $this->back_2_frame = $a_frame;
103 }
104
105 public function setForcePresentationOfSingleTab(bool $a_val): void
106 {
107 $this->force_one_tab = $a_val;
108 }
109
110 public function getForcePresentationOfSingleTab(): bool
111 {
112 return $this->force_one_tab;
113 }
114
120 public function addTarget(
121 string $a_text,
122 string $a_link,
123 $a_cmd = "",
124 $a_cmdClass = "",
125 string $a_frame = "",
126 bool $a_activate = false,
127 bool $a_dir_text = false
128 ): void {
129 if (!$a_cmdClass) {
130 $a_cmdClass = array();
131 }
132 $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
133
134 if ($a_activate) {
135 $this->manual_activation = true;
136 }
137 $this->target[] = array("text" => $a_text, "link" => $a_link,
138 "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
139 "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
140 }
141
145 public function addTab(
146 string $a_id,
147 string $a_text,
148 string $a_link,
149 string $a_frame = ""
150 ): void {
151 $this->target[] = array("text" => $a_text, "link" => $a_link,
152 "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
153 }
154
158 public function removeTab(string $a_id): void
159 {
160 foreach ($this->target as $key => $target) {
161 if ($target['id'] == $a_id) {
162 unset($this->target[$key]);
163 }
164 }
165 }
166
170 public function removeSubTab(string $a_id): void
171 {
172 foreach ($this->sub_target as $i => $sub_target) {
173 if ($this->sub_target[$i]['id'] == $a_id) {
174 unset($this->sub_target[$i]);
175 }
176 }
177 }
178
182 public function replaceTab(
183 string $a_old_id,
184 string $a_new_id,
185 string $a_text,
186 string $a_link,
187 string $a_frame = ''
188 ): void {
189 for ($i = 0, $iMax = count($this->target); $i < $iMax; $i++) {
190 if ($this->target[$i]['id'] == $a_old_id) {
191 $this->target[$i] = array(
192 "text" => $a_text,
193 "link" => $a_link,
194 "frame" => $a_frame,
195 "dir_text" => true,
196 "id" => $a_new_id,
197 "cmdClass" => array());
198 }
199 }
200 }
201
205 public function clearTargets(): void
206 {
207 global $DIC;
208
209 $ilHelp = $DIC["ilHelp"] ?? null;
210
211 if (!$this->getSetupMode()) {
212 $ilHelp->setScreenIdComponent("");
213 }
214
215 $this->target = array();
216 $this->sub_target = array();
217 $this->non_tabbed_link = array();
218 $this->back_title = "";
219 $this->back_target = "";
220 $this->back_2_target = "";
221 $this->back_2_title = "";
222 $this->setTabActive("");
223 $this->setSubTabActive("");
224 }
225
231 public function addSubTabTarget(
232 string $a_text,
233 string $a_link,
234 $a_cmd = "",
235 $a_cmdClass = "",
236 string $a_frame = "",
237 bool $a_activate = false,
238 bool $a_dir_text = false
239 ): void {
240 if (!$a_cmdClass) {
241 $a_cmdClass = array();
242 }
243 $a_cmdClass = !is_array($a_cmdClass) ? array(strtolower($a_cmdClass)) : $a_cmdClass;
244 #$a_cmdClass = strtolower($a_cmdClass);
245
246 if ($a_activate) {
247 $this->subtab_manual_activation = true;
248 }
249 $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
250 "cmd" => $a_cmd, "cmdClass" => $a_cmdClass, "frame" => $a_frame,
251 "activate" => $a_activate, "dir_text" => $a_dir_text, "id" => $a_text);
252 }
253
254 public function addSubTab(
255 string $a_id,
256 string $a_text,
257 string $a_link,
258 string $a_frame = ""
259 ): void {
260 $this->sub_target[] = array("text" => $a_text, "link" => $a_link,
261 "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
262 }
263
267 public function setTabActive(string $a_id): void
268 {
269 foreach ($this->target as $key => $target) {
270 $this->target[$key]['activate'] = $this->target[$key]['id'] === $a_id;
271 }
272 if ($a_id !== "") {
273 $this->manual_activation = true;
274 } else {
275 $this->manual_activation = false;
276 }
277 }
278
279 public function activateTab(string $a_id): void
280 {
281 $this->setTabActive($a_id);
282 }
283
287 public function setSubTabActive(string $a_text): void
288 {
289 for ($i = 0, $iMax = count($this->sub_target); $i < $iMax; $i++) {
290 $this->sub_target[$i]['activate'] = $this->sub_target[$i]['id'] === $a_text;
291 }
292 $this->subtab_manual_activation = true;
293 }
294
295 public function activateSubTab(string $a_id): void
296 {
297 $this->setSubTabActive($a_id);
298 }
299
300 public function clearSubTabs(): void
301 {
302 $this->sub_target = array();
303 }
304
305 public function getHTML(bool $a_after_tabs_anchor = false): string
306 {
307 return $this->__getHTML(false, $a_after_tabs_anchor);
308 }
309
310 public function getSubTabHTML(): string
311 {
312 return $this->__getHTML(true);
313 }
314
315 public function addNonTabbedLink(
316 string $a_id,
317 string $a_text,
318 string $a_link,
319 string $a_frame = ""
320 ): void {
321 $this->non_tabbed_link[] = array("text" => $a_text, "link" => $a_link,
322 "frame" => $a_frame, "dir_text" => true, "id" => $a_id, "cmdClass" => array());
323 }
324
325 public function removeNonTabbedLinks(): void
326 {
327 $this->non_tabbed_link = [];
328 }
329
330 private function __getHTML(
331 bool $a_get_sub_tabs,
332 bool $a_after_tabs_anchor = false
333 ): string {
335 global $DIC;
336
337 $cmd = null;
338 $cmdClass = null;
339 $sr_pre = "";
340 $hash = "";
341 $f = $DIC->ui()->factory();
342 $r = $DIC->ui()->renderer();
343
344 $ilHelp = $DIC["ilHelp"] ?? null;
345
346 $ilCtrl = $this->ctrl;
348 $ilUser = null;
349 if (isset($DIC["ilUser"])) {
350 $ilUser = $DIC->user();
351 }
352 $component_factory = $DIC["component.factory"] ?? null;
353
354 // user interface hook [uihk]
355 if ($component_factory && !$this->getSetupMode()) {
356 foreach ($component_factory->getActivePluginsInSlot("uihk") as $plugin) {
357 $gui_class = $plugin->getUIClassInstance();
358 $resp = $gui_class->modifyGUI(
359 "",
360 $a_get_sub_tabs ? "sub_tabs" : "tabs",
361 array("tabs" => $this)
362 );
363 }
364 }
365
366
367 // user interface hook [uihk]
368 if (!$this->getSetupMode()) {
369 $cmd = $ilCtrl->getCmd();
370 $cmdClass = $ilCtrl->getCmdClass();
371 }
372
373 if ($a_get_sub_tabs) {
374 $tpl = new ilTemplate("tpl.sub_tabs.html", true, true, "components/ILIAS/UIComponent/Tabs");
375 $pre = "sub";
376 $pre2 = "SUB_";
377 $sr_pre = "sub_";
378 } else {
379 $tpl = new ilTemplate("tpl.tabs.html", true, true, "components/ILIAS/UIComponent/Tabs");
380 if ($a_after_tabs_anchor) {
381 $tpl->touchBlock("after_tabs");
382 }
383 $pre = $pre2 = "";
384
385 // back 2 tab
386 if ($this->back_2_title !== "") {
387 $tpl->setCurrentBlock("back_2_tab");
388 $tpl->setVariable("BACK_2_ICON", $this->symbol()->glyph("back")->render());
389 $tpl->setVariable("BACK_2_TAB_LINK", ilUtil::secureUrl($this->back_2_target));
390 $tpl->setVariable("BACK_2_TAB_TEXT", $this->back_2_title);
391 if ($this->back_2_frame !== "") {
392 $tpl->setVariable("BACK_2_TAB_TARGET", ' target="' . $this->back_2_frame . '" ');
393 }
394
395 $tpl->parseCurrentBlock();
396 }
397
398 // back tab
399 if ($this->back_title !== "") {
400 $tpl->setCurrentBlock("back_tab");
401 $tpl->setVariable("BACK_ICON", $this->symbol()->glyph("back")->render());
402 $tpl->setVariable("BACK_TAB_LINK", ilUtil::secureUrl($this->back_target));
403 $tpl->setVariable("BACK_TAB_TEXT", $this->back_title);
404 if ($this->back_frame !== "") {
405 $tpl->setVariable("BACK_TAB_TARGET", ' target="' . $this->back_frame . '" ');
406 }
407 $tpl->parseCurrentBlock();
408 }
409 }
410
411 $targets = $a_get_sub_tabs ? $this->sub_target : $this->target;
412
413 $i = 0;
414
415 // do not display one tab only
416 if ((count($targets) > 1 || $this->force_one_tab) || ($this->back_title !== "" && !$a_get_sub_tabs)
417 || (count($this->non_tabbed_link) > 0 && !$a_get_sub_tabs)) {
418 foreach ($targets as $target) {
419 $i++;
420
421 if (isset($target['cmd'])) {
422 if (!is_array($target['cmd'])) {
423 $target['cmd'] = [$target['cmd']];
424 }
425 } else {
426 $target['cmd'] = [];
427 }
428
429 if ($this->isTabActive($a_get_sub_tabs, $target, $cmd, $cmdClass)) {
430 $tabtype = $pre . "tabactive";
431 } else {
432 $tabtype = $pre . "tabinactive";
433 }
434
435 if (($a_get_sub_tabs ? $this->subtab_manual_activation : $this->manual_activation) && ($target["activate"] ?? false)) {
436 $tabtype = $pre . "tabactive";
437 }
438
439 if ($tabtype === "tabactive" || $tabtype === "subtabactive") {
440 $tpl->setCurrentBlock("sel_text");
441 $tpl->setVariable("TXT_SELECTED", $lng->txt("stat_selected"));
442 $tpl->parseCurrentBlock();
443
444 if (!$this->getSetupMode()) {
445 if ($a_get_sub_tabs) {
447 } else {
449 }
450 $ilHelp->setDefaultScreenId($part, $target["id"]);
451 }
452 }
453
454 $tpl->setCurrentBlock($pre . "tab");
455 $tpl->setVariable("ID", $pre . "tab_" . $target["id"]);
456
457 // bs-patch: start
458 $tabtype = in_array($tabtype, array("tabactive", "subtabactive"))
459 ? "active"
460 : "";
461 // bs-patch: end
462
463 $tpl->setVariable($pre2 . "TAB_TYPE", $tabtype);
464 $hash = "";
465 if ($target["dir_text"]) {
466 $text = $target["text"];
467 } else {
468 $text = $lng->txt($target["text"]);
469 }
470 $link = $f->link()->standard($text, $target["link"]);
471 if ($target["frame"] != "") {
472 $link->withOpenInNewViewport(true);
473 }
474 $ttext = $ilHelp->getTabTooltipText($target["id"]);
475 if ($ttext !== "") {
476 $link = $link->withHelpTopics(
477 ...$f->helpTopics($ttext)
478 );
479 }
480
481 $tpl->setVariable($pre2 . "LINK", $r->render($link));
482 $tpl->parseCurrentBlock();
483 }
484
485 if ($a_get_sub_tabs) {
486 $tpl->setVariable("TXT_SUBTABS", $this->getTabTextOfId($this->getActiveTab()) . ": " . $lng->txt("subtabs"));
487 } else {
488 $tpl->setVariable("TXT_TABS", $lng->txt("tabs"));
489 $tpl->setVariable("LAST_TAB_LABEL", $lng->txt("show_more"));
490
491 // non tabbed links
492 foreach ($this->non_tabbed_link as $link) {
493 $tpl->setCurrentBlock("tab");
494 $tpl->setVariable("TAB_TYPE", "nontabbed");
495 $l = $f->link()->standard(
496 $link["text"] . " " . $this->symbol()->glyph("next")->render(),
497 $link["link"]
498 );
499 if ($link["frame"] !== "") {
500 $l = $l->withOpenInNewViewport(true);
501 }
502
503 // tooltip
504 if (!$this->getSetupMode()) {
505 $ttext = $ilHelp->getTabTooltipText($link["id"]);
506 if ($ttext !== "") {
507 $ttext = $ilHelp->getTabTooltipText($link["id"]);
508 if ($ttext !== "") {
509 $l = $l->withHelpTopics(
510 ...$f->helpTopics($ttext)
511 );
512 }
513 }
514 }
515
516 $tpl->setVariable("LINK", $r->render($l));
517 //$tpl->setVariable("ID", "nontab_" . $link["id"]);
518 $tpl->parseCurrentBlock();
519 }
520 }
521
522 $this->tpl->addOnLoadCode('il.UICore.initLastTabDropdown()');
523 return $tpl->get();
524 } else {
525 return "";
526 }
527 }
528
529 protected function getTabTextOfId(string $id): string
530 {
531 foreach ($this->target as $i => $target) {
532 if ($this->target[$i]['id'] == $id) {
533 if ($target["dir_text"]) {
534 return $target["text"];
535 } else {
536 return $this->lng->txt($target["text"]);
537 }
538 }
539 }
540 return "";
541 }
542
543 public function getActiveTab(): string
544 {
545 foreach ($this->target as $i => $target) {
546 if ($this->target[$i]['activate'] ?? null) {
547 return $this->target[$i]['id'];
548 }
549 }
550 return "";
551 }
552
553 public function hasTabs(): bool
554 {
555 return $this->target !== [];
556 }
557
558 private function isTabActive(bool $isSubTabsContext, array $target, ?string $cmd, ?string $cmdClass): bool
559 {
560 if (($isSubTabsContext && $this->subtab_manual_activation) || (!$isSubTabsContext && $this->manual_activation)) {
561 return false;
562 }
563
564 $cmdClass = (string) $cmdClass;
565 $cmd = (string) $cmd;
566
567 $targetMatchesCmdClass = (
568 !$target['cmdClass'] ||
569 in_array(strtolower($cmdClass), array_map('strtolower', $target['cmdClass']), true)
570 );
571
572 $targetMatchesCmd = (
573 in_array(strtolower($cmd), array_map('strtolower', $target['cmd']), true) ||
574 (count($target['cmd']) === 1 && $target['cmd'][0] === '')
575 );
576
577 return $targetMatchesCmd && $targetMatchesCmdClass;
578 }
579}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
return true
Class ilCtrl provides processing control methods.
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 secureUrl(string $url)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
touchBlock(string $block)
overwrites ITX::touchBlock.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26