ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilChatroomTabGUIFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Refinery\Factory as Refinery;
23
32{
33 private readonly ilLanguage $lng;
34 private readonly ilRbacSystem $rbacSystem;
35 private readonly GlobalHttpState $http;
36 private readonly Refinery $refinery;
37 private ?string $activated_tab = null;
38 private ?string $activated_sub_tab = null;
39
40 public function __construct(private readonly ilObjectGUI $gui)
41 {
43 global $DIC;
44 $this->lng = $DIC->language();
45 $this->rbacSystem = $DIC->rbac()->system();
46 $this->http = $DIC->http();
47 $this->refinery = $DIC->refinery();
48 }
49
54 public function getAdminTabsForCommand(string $command): void
55 {
56 global $DIC;
57
59 $stopCommands = ['create'];
60
61 if (in_array($command, $stopCommands, true)) {
62 return;
63 }
64
65 $settings = new ilSetting('chatroom');
66 $public_room_ref = (int) $settings->get('public_room_ref', '0');
67
68 $objIds = ilObject::_getObjectsByType('chta');
69 $firstObjId = (int) current(array_keys($objIds));
70 $refIds = ilObject::_getAllReferences($firstObjId);
71 $admin_ref = (int) current($refIds);
72
73 $DIC->ctrl()->setParameterByClass(ilObjChatroomAdminGUI::class, 'ref_id', $admin_ref);
74
75 $config = [
76 'view' => [
77 'lng' => 'settings',
78 'link' => $DIC->ctrl()->getLinkTargetByClass(ilObjChatroomAdminGUI::class, 'view-clientsettings'),
79 'permission' => 'read',
80 'subtabs' => [
81 'clientsettings' => [
82 'lng' => 'client_settings',
83 'link' => $DIC->ctrl()->getLinkTargetByClass(
84 ilObjChatroomAdminGUI::class,
85 'view-clientsettings'
86 ),
87 'permission' => 'read'
88 ]
89 ]
90 ],
91 ];
92 $DIC->ctrl()->setParameterByClass(ilObjChatroomGUI::class, 'ref_id', $public_room_ref);
93
94 $config['settings'] = [
95 'lng' => 'public_chat_settings',
96 'link' => $DIC->ctrl()->getLinkTargetByClass(ilObjChatroomGUI::class, 'settings-general'),
97 'permission' => 'read',
98 'subtabs' => [
99 'settings' => [
100 'lng' => 'settings',
101 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'settings-general'),
102 'permission' => 'read'
103 ],
104 'ban' => [
105 'lng' => 'bans',
106 'link' => $DIC->ctrl()->getLinkTargetByClass(ilObjChatroomGUI::class, 'ban-show'),
107 'permission' => 'read'
108 ]
109 ]
110 ];
111
112 $DIC->ctrl()->setParameterByClass(ilPermissionGUI::class, 'ref_id', $public_room_ref);
113 $config['perm'] = [
114 'lng' => 'public_chat_permissions',
115 'link' => $DIC->ctrl()->getLinkTargetByClass(ilPermissionGUI::class, 'perm'),
116 'permission' => 'read',
117 ];
118 $DIC->ctrl()->clearParametersByClass(ilPermissionGUI::class);
119
120 $DIC->ctrl()->setParameterByClass(ilPermissionGUI::class, 'ref_id', $admin_ref);
121 $config['perm_settings'] = [
122 'lng' => 'perm_settings',
123 'link' => $DIC->ctrl()->getLinkTargetByClass(ilPermissionGUI::class, 'perm'),
124 'permission' => 'edit_permission',
125 ];
126 $DIC->ctrl()->clearParametersByClass(ilPermissionGUI::class);
127
128 $is_in_permission_gui = (
129 strtolower($DIC->ctrl()->getCmdClass() ?? '') === strtolower(ilPermissionGUI::class) ||
130 strtolower($DIC->ctrl()->getCmdClass() ?? '') === strtolower(ilObjectPermissionStatusGUI::class)
131 );
132
133 $commandParts = explode('_', $command, 2);
134 if ($command === 'ban_show') {
135 $commandParts[0] = 'settings';
136 $commandParts[1] = 'ban';
137 } elseif ($command === 'settings_general') {
138 $commandParts[0] = 'settings';
139 $commandParts[1] = 'settings';
140 } elseif ($command === 'view_saveclientsettings') {
141 $commandParts[0] = 'view';
142 $commandParts[1] = 'clientsettings';
143 } elseif (
144 $is_in_permission_gui &&
145 $this->http->wrapper()->query()->has('ref_id') &&
146 $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int()) === $public_room_ref
147 ) {
148 $commandParts[0] = 'perm';
149 $DIC->ctrl()->setParameterByClass(ilPermissionGUI::class, 'ref_id', $public_room_ref);
150 } elseif (
151 $is_in_permission_gui &&
152 $this->http->wrapper()->query()->has('ref_id') &&
153 $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int()) === $admin_ref
154 ) {
155 $commandParts[0] = 'perm_settings';
156 $DIC->ctrl()->setParameterByClass(ilPermissionGUI::class, 'ref_id', $admin_ref);
157 }
158
159 $this->buildTabs($DIC->tabs(), $config, $commandParts, false);
160 $this->activateTab($commandParts, $config);
161 }
162
168 private static function convertLowerCamelCaseToUnderscoreCaseConversion(string $value): string
169 {
170 return strtolower(preg_replace('/(.*?)-(.*?)/', '$1_$2', $value));
171 }
172
177 private function buildTabs(ilTabsGUI $tabs, array $config, array $command, bool $inRoom = true): void
178 {
179 foreach ($config as $id => $tabDefinition) {
180 if (!$inRoom && !$this->rbacSystem->checkAccess($tabDefinition['permission'], $this->gui->getRefId())) {
181 continue;
182 }
183
184 if (
185 $inRoom &&
186 !ilChatroom::checkUserPermissions($tabDefinition['permission'], $this->gui->getRefId(), false)
187 ) {
188 continue;
189 }
190
191 if (isset($tabDefinition['enabled']) && !$tabDefinition['enabled']) {
192 continue;
193 }
194
195 $tabs->addTab($id, $this->getLabel($tabDefinition, $id), $tabDefinition['link']);
196
197 if (
198 $command[0] === $id && isset($tabDefinition['subtabs']) &&
199 is_array($tabDefinition['subtabs'])
200 ) {
201 foreach ($tabDefinition['subtabs'] as $subid => $subTabDefinition) {
202 if (
203 !$inRoom &&
204 $this->rbacSystem->checkAccess($tabDefinition['permission'], $this->gui->getRefId())
205 ) {
206 continue;
207 }
208
209 if (
210 $inRoom &&
211 !ilChatroom::checkUserPermissions($subTabDefinition['permission'], $this->gui->getRefId())
212 ) {
213 continue;
214 }
215
216 if (isset($subTabDefinition['enabled']) && !$subTabDefinition['enabled']) {
217 continue;
218 }
219
220 $tabs->addSubTab(
221 $subid,
222 $this->getLabel($subTabDefinition, $subid),
223 $subTabDefinition['link']
224 );
225 }
226 }
227 }
228 }
229
233 private function getLabel(array $tabDefinition, string $id): string
234 {
235 if (isset($tabDefinition['lng'])) {
236 return $this->lng->txt($tabDefinition['lng']);
237 }
238
239 return $this->lng->txt($id);
240 }
241
247 private function activateTab(array $commandParts, array $config): void
248 {
249 global $DIC;
250
251 if (count($commandParts) > 1) {
252 if (isset($config[$commandParts[0]])) {
253 $DIC->tabs()->activateTab($commandParts[0]);
254 $this->activated_tab = $commandParts[0];
255
256 if (isset($config[$commandParts[0]]['subtabs'][$commandParts[1]])) {
257 $DIC->tabs()->activateSubTab($commandParts[1]);
258 $this->activated_sub_tab = $commandParts[1];
259 }
260 }
261 } elseif (count($commandParts) === 1) {
262 $DIC->tabs()->activateTab($commandParts[0]);
263 $this->activated_tab = $commandParts[0];
264 }
265 }
266
267 public function getActivatedTab(): ?string
268 {
270 }
271
272 public function getActivatedSubTab(): ?string
273 {
275 }
276
281 public function getTabsForCommand(string $command): void
282 {
283 global $DIC;
284
286 $stopCommands = ['create'];
287
288 if (in_array($command, $stopCommands, true)) {
289 return;
290 }
291
292 $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
293
294 $config = [
295 'view' => [
296 'lng' => 'obj_chtr',
297 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'view'),
298 'permission' => 'read'
299 ],
300 'history' => [
301 'lng' => 'history',
302 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'history-byday'),
303 'permission' => 'read',
304 'enabled' => $room ? $room->getSetting('enable_history') : false,
305 ],
306 'info' => [
307 'lng' => 'info_short',
308 'link' => $DIC->ctrl()->getLinkTargetByClass([$this->gui::class, ilInfoScreenGUI::class], 'showSummary'),
309 'permission' => 'read'
310 ],
311 'settings' => [
312 'lng' => 'settings',
313 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'settings-general'),
314 'permission' => 'write',
315 'subtabs' => [
316 'general' => [
317 'lng' => 'settings_general',
318 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'settings-general'),
319 'permission' => 'write'
320 ]
321 ]
322 ],
323 'ban' => [
324 'lng' => 'bans',
325 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'ban-show'),
326 'permission' => 'moderate',
327 'subtabs' => [
328 'show' => [
329 'lng' => 'bans_table',
330 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'ban-show'),
331 'permission' => 'moderate'
332 ]
333 ]
334 ],
335 'export' => [
336 'lng' => 'export',
337 'link' => $DIC->ctrl()->getLinkTargetByClass(ilExportGUI::class, ''),
338 'permission' => 'write'
339 ],
340 'perm' => [
341 'lng' => 'permissions',
342 'link' => $DIC->ctrl()->getLinkTargetByClass(ilPermissionGUI::class, 'perm'),
343 'permission' => 'edit_permission'
344 ]
345 ];
346
347 $commandParts = explode('_', $command, 2);
348 if (strtolower($DIC->ctrl()->getCmdClass() ?? '') === strtolower(ilPermissionGUI::class)) {
349 $commandParts[0] = 'perm';
350 }
351 if (strtolower($DIC->ctrl()->getCmdClass() ?? '') === strtolower(ilInfoScreenGUI::class)) {
352 $commandParts[0] = 'info';
353 }
354
355 $this->buildTabs($DIC->tabs(), $config, $commandParts);
356 $this->activateTab($commandParts, $config);
357 }
358}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds data types.
Definition: Factory.php:36
Class ilChatroomTabGUIFactory.
static convertLowerCamelCaseToUnderscoreCaseConversion(string $value)
Convert a value given in lower camel case conversion to underscore case conversion (e....
getTabsForCommand(string $command)
Builds $config and $commandparts arrays to assign them as parameters when calling $this->buildTabs an...
buildTabs(ilTabsGUI $tabs, array $config, array $command, bool $inRoom=true)
Builds tabs and subtabs using given $tabs, $config and $command parameters.
activateTab(array $commandParts, array $config)
Activates tab or subtab if existing.
getAdminTabsForCommand(string $command)
Builds $config and $commandparts arrays to assign them as parameters when calling $this->buildTabs an...
getLabel(array $tabDefinition, string $id)
Returns label for tab by $tabDefinition or $id.
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
static byObjectId(int $object_id)
language handling
Class ilObjectGUI Basic methods of all Output classes.
static _getAllReferences(int $id)
get all reference ids for object ID
static _getObjectsByType(string $obj_type="", ?int $owner=null)
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
Add a Tab.
addSubTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
Interface GlobalHttpState.
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26