ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Tabs.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\GlobalScreen\GUI\I18n\Translator;
26
31class Tabs
32{
34 private ?string $active_tab = null;
35 private ?string $active_subtab = null;
36
37 public function __construct(
38 private Translator $translator,
39 private \ilCtrlInterface $ctrl,
40 private \ilTabsGUI $tabs_gui,
41 private Flow $flow,
42 ) {
43 $this->structure = new Structure();
44 }
45
46 public function activate(string $tab_id): void
47 {
48 $tab = $this->structure->getById($tab_id);
49 if ($tab === null) {
50 return;
51 }
52 if ($tab->getParent() === null) {
53 $this->active_tab = $tab_id;
54 } else {
55 $this->active_subtab = $tab_id;
56 $this->active_tab = $tab->getParent()->getId();
57 }
58 }
59
60 public function build(
61 string $id,
62 string $language_key,
63 array|URI $target,
64 ?Tab $parent = null,
65 ?string $handling_class = null,
66 ): Tab {
67 if ($handling_class === null) {
68 if ($target instanceof URI) {
69 throw new \InvalidArgumentException('No handling class given');
70 }
71 if (is_array($target[0])) {
72 // get last element of array without changing the array
73 $handling_class = $target[0][count($target[0]) - 1];
74 } elseif (is_string($target[0])) {
75 $handling_class = $target[0];
76 } else {
77 throw new \InvalidArgumentException('No handling class given');
78 }
79 }
80
81 if ($handling_class === null) {
82 throw new \InvalidArgumentException('No handling class given');
83 }
84 if (!$target instanceof URI) {
85 $target_class = $target[0];
86 $command = $target[1] ?? null;
87 //
88 // if ($parent !== null && !is_array($target_class)) {
89 // $flow = $this->flow->getHereAsFlow();
90 // $flow[] = $target_class;
91 // } else {
92 // $flow = $target_class;
93 // }
94
95 $uri = $this->flow->getTargetURI($target_class, $command);
96 } else {
97 $uri = $target;
98 }
99
100 return new Tab(
101 $id,
102 $language_key,
103 $uri,
104 $handling_class,
105 $parent
106 );
107 }
108
109 public function show(): void
110 {
111 $this->tabs_gui->clearTargets();
112
113 $current_tab = $this->structure->getByHandlingClass(
114 $this->flow->getCurrentClass() ?? ''
115 );
116
117 if (
118 $current_tab !== null
119 && $current_tab->getParent() !== null
120 && $current_tab->getParent()->getParent() !== null
121 ) {
122 // add backtab
123 $this->tabs_gui->setBackTarget(
124 $this->translator->translate('back'),
125 $this->ctrl->getLinkTargetByClass(
126 $current_tab->getParent()->getHandlingClass()
127 )
128 );
129 return;
130 }
131
132 foreach ($this->structure->get() as $tab) {
133 if ($tab->getParent() === null) {
134 $this->tabs_gui->addTab(
135 $tab->getId(),
136 $this->translator->t($tab->getLanguageKey()),
137 (string) $tab->getTarget()
138 );
139 } elseif ($tab->getParent()->getId() === $this->active_tab) {
140 $this->tabs_gui->addSubTab(
141 $tab->getId(),
142 $this->translator->t($tab->getLanguageKey()),
143 (string) $tab->getTarget()
144 );
145 }
146 }
147 if ($this->active_tab !== null) {
148 $this->tabs_gui->activateTab($this->active_tab);
149 }
150 if ($this->active_subtab !== null) {
151 $this->tabs_gui->activateSubTab($this->active_subtab);
152 }
153 }
154
155 public function structure(): Structure
156 {
157 return $this->structure;
158 }
159
160 public function add(Tab ...$tab): void
161 {
162 foreach ($tab as $t) {
163 $this->structure->add($t);
164 }
165 }
166
167 public function backToMainTab(): void
168 {
169 $this->tabs_gui->clearTargets();
170
171 if (
173 && $this->ctrl->getCmdClass() === strtolower(ilFooterEntriesGUI::class)
174 ) {
175 $this->tabs_gui->setBackTarget(
176 $this->translator->translate('back'),
177 $this->ctrl->getLinkTargetByClass(
178 ilFooterEntriesGUI::class,
180 )
181 );
182 return;
183 }
184
185 $this->tabs_gui->setBackTarget(
186 $this->translator->translate('back'),
187 $this->ctrl->getLinkTargetByClass(
188 ilObjFooterAdministrationGUI::class,
190 )
191 );
192 }
193}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
activate(string $tab_id)
Definition: Tabs.php:46
__construct(private Translator $translator, private \ilCtrlInterface $ctrl, private \ilTabsGUI $tabs_gui, private Flow $flow,)
Definition: Tabs.php:37
build(string $id, string $language_key, array|URI $target, ?Tab $parent=null, ?string $handling_class=null,)
Definition: Tabs.php:60
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...
if(!file_exists('../ilias.ini.php'))