ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilChatroomTabGUIFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
23 
32 {
33  private ilObjectGUI $gui;
34  private ilLanguage $lng;
38  private ?string $activated_tab = null;
39  private ?string $activated_sub_tab = null;
40 
41  public function __construct(ilObjectGUI $gui)
42  {
44  global $DIC;
45 
46  $this->gui = $gui;
47  $this->lng = $DIC->language();
48  $this->rbacSystem = $DIC->rbac()->system();
49  $this->http = $DIC->http();
50  $this->refinery = $DIC->refinery();
51  }
52 
58  public function getAdminTabsForCommand(string $command): void
59  {
60  global $DIC;
61 
62  $command = self::convertLowerCamelCaseToUnderscoreCaseConversion($command);
63  $stopCommands = ['create'];
64 
65  if (in_array($command, $stopCommands, true)) {
66  return;
67  }
68 
69  $settings = new ilSetting('chatroom');
70  $public_room_ref = (int) $settings->get('public_room_ref', '0');
71 
72  $objIds = ilObject::_getObjectsByType('chta');
73  $firstObjId = (int) current(array_keys($objIds));
74  $refIds = ilObject::_getAllReferences($firstObjId);
75  $admin_ref = (int) current($refIds);
76 
77  $DIC->ctrl()->setParameterByClass(ilObjChatroomAdminGUI::class, 'ref_id', $admin_ref);
78 
79  $config = [
80  'view' => [
81  'lng' => 'settings',
82  'link' => $DIC->ctrl()->getLinkTargetByClass(ilObjChatroomAdminGUI::class, 'view-clientsettings'),
83  'permission' => 'read',
84  'subtabs' => [
85  'clientsettings' => [
86  'lng' => 'client_settings',
87  'link' => $DIC->ctrl()->getLinkTargetByClass(
88  ilObjChatroomAdminGUI::class,
89  'view-clientsettings'
90  ),
91  'permission' => 'read'
92  ]
93  ]
94  ],
95  'smiley' => [
96  'lng' => 'smiley',
97  'link' => $DIC->ctrl()->getLinkTargetByClass(ilObjChatroomAdminGUI::class, 'smiley'),
98  'permission' => 'read'
99  ]
100  ];
101  $DIC->ctrl()->setParameterByClass(ilObjChatroomGUI::class, 'ref_id', $public_room_ref);
102 
103  $config['settings'] = [
104  'lng' => 'public_chat_settings',
105  'link' => $DIC->ctrl()->getLinkTargetByClass(ilObjChatroomGUI::class, 'settings-general'),
106  'permission' => 'read',
107  'subtabs' => [
108  'settings' => [
109  'lng' => 'settings',
110  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'settings-general'),
111  'permission' => 'read'
112  ],
113  'ban' => [
114  'lng' => 'bans',
115  'link' => $DIC->ctrl()->getLinkTargetByClass(ilObjChatroomGUI::class, 'ban-show'),
116  'permission' => 'read'
117  ]
118  ]
119  ];
120 
121  $DIC->ctrl()->setParameterByClass(ilPermissionGUI::class, 'ref_id', $public_room_ref);
122  $config['perm'] = [
123  'lng' => 'public_chat_permissions',
124  'link' => $DIC->ctrl()->getLinkTargetByClass(ilPermissionGUI::class, 'perm'),
125  'permission' => 'read',
126  ];
127  $DIC->ctrl()->clearParametersByClass(ilPermissionGUI::class);
128 
129  $DIC->ctrl()->setParameterByClass(ilPermissionGUI::class, 'ref_id', $admin_ref);
130  $config['perm_settings'] = [
131  'lng' => 'perm_settings',
132  'link' => $DIC->ctrl()->getLinkTargetByClass(ilPermissionGUI::class, 'perm'),
133  'permission' => 'edit_permission',
134  ];
135  $DIC->ctrl()->clearParametersByClass(ilPermissionGUI::class);
136 
137  $is_in_permission_gui = (
138  strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilPermissionGUI::class) ||
139  strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilObjectPermissionStatusGUI::class)
140  );
141 
142  $commandParts = explode('_', $command, 2);
143  if ($command === 'ban_show') {
144  $commandParts[0] = 'settings';
145  $commandParts[1] = 'ban';
146  } elseif ($command === 'settings_general') {
147  $commandParts[0] = 'settings';
148  $commandParts[1] = 'settings';
149  } elseif ($command === 'view_saveclientsettings') {
150  $commandParts[0] = 'view';
151  $commandParts[1] = 'clientsettings';
152  } elseif (
153  $is_in_permission_gui &&
154  $this->http->wrapper()->query()->has('ref_id') &&
155  $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int()) === $public_room_ref
156  ) {
157  $commandParts[0] = 'perm';
158  $DIC->ctrl()->setParameterByClass(ilPermissionGUI::class, 'ref_id', $public_room_ref);
159  } elseif (
160  $is_in_permission_gui &&
161  $this->http->wrapper()->query()->has('ref_id') &&
162  $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int()) === $admin_ref
163  ) {
164  $commandParts[0] = 'perm_settings';
165  $DIC->ctrl()->setParameterByClass(ilPermissionGUI::class, 'ref_id', $admin_ref);
166  }
167 
168  $this->buildTabs($DIC->tabs(), $config, $commandParts, false);
169  $this->activateTab($commandParts, $config);
170  }
171 
177  private static function convertLowerCamelCaseToUnderscoreCaseConversion(string $value): string
178  {
179  return strtolower(preg_replace('/(.*?)-(.*?)/', '$1_$2', $value));
180  }
181 
190  private function buildTabs(ilTabsGUI $tabs, array $config, array $command, bool $inRoom = true): void
191  {
192  foreach ($config as $id => $tabDefinition) {
193  if (!$inRoom && !$this->rbacSystem->checkAccess($tabDefinition['permission'], $this->gui->getRefId())) {
194  continue;
195  }
196 
197  if (
198  $inRoom &&
199  !ilChatroom::checkUserPermissions($tabDefinition['permission'], $this->gui->getRefId(), false)
200  ) {
201  continue;
202  }
203 
204  if (isset($tabDefinition['enabled']) && !$tabDefinition['enabled']) {
205  continue;
206  }
207 
208  $tabs->addTab($id, $this->getLabel($tabDefinition, $id), $tabDefinition['link']);
209 
210  if (
211  $command[0] === $id && isset($tabDefinition['subtabs']) &&
212  is_array($tabDefinition['subtabs'])
213  ) {
214  foreach ($tabDefinition['subtabs'] as $subid => $subTabDefinition) {
215  if (
216  !$inRoom &&
217  $this->rbacSystem->checkAccess($tabDefinition['permission'], $this->gui->getRefId())
218  ) {
219  continue;
220  }
221 
222  if (
223  $inRoom &&
224  !ilChatroom::checkUserPermissions($subTabDefinition['permission'], $this->gui->getRefId())
225  ) {
226  continue;
227  }
228 
229  if (isset($subTabDefinition['enabled']) && !$subTabDefinition['enabled']) {
230  continue;
231  }
232 
233  $tabs->addSubTab(
234  $subid,
235  $this->getLabel($subTabDefinition, $subid),
236  $subTabDefinition['link']
237  );
238  }
239  }
240  }
241  }
242 
249  private function getLabel(array $tabDefinition, string $id): string
250  {
251  if (isset($tabDefinition['lng'])) {
252  return $this->lng->txt($tabDefinition['lng']);
253  }
254 
255  return $this->lng->txt($id);
256  }
257 
265  private function activateTab(array $commandParts, array $config): void
266  {
267  global $DIC;
268 
269  if (count($commandParts) > 1) {
270  if (isset($config[$commandParts[0]])) {
271  $DIC->tabs()->activateTab($commandParts[0]);
272  $this->activated_tab = $commandParts[0];
273 
274  if (isset($config[$commandParts[0]]['subtabs'][$commandParts[1]])) {
275  $DIC->tabs()->activateSubTab($commandParts[1]);
276  $this->activated_sub_tab = $commandParts[1];
277  }
278  }
279  } elseif (count($commandParts) === 1) {
280  $DIC->tabs()->activateTab($commandParts[0]);
281  $this->activated_tab = $commandParts[0];
282  }
283  }
284 
285  public function getActivatedTab(): ?string
286  {
287  return $this->activated_tab;
288  }
289 
290  public function getActivatedSubTab(): ?string
291  {
293  }
294 
300  public function getTabsForCommand(string $command): void
301  {
302  global $DIC;
303 
304  $command = self::convertLowerCamelCaseToUnderscoreCaseConversion($command);
305  $stopCommands = ['create'];
306 
307  if (in_array($command, $stopCommands, true)) {
308  return;
309  }
310 
311  $room = ilChatroom::byObjectId($this->gui->getObject()->getId());
312 
313  $config = [
314  'view' => [
315  'lng' => 'view',
316  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'view'),
317  'permission' => 'read'
318  ],
319  'history' => [
320  'lng' => 'history',
321  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'history-byday'),
322  'permission' => 'read',
323  'enabled' => $room ? $room->getSetting('enable_history') : false,
324  'subtabs' => [
325  'byday' => [
326  'lng' => 'history_by_day',
327  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'history-byday'),
328  'permission' => 'read'
329  ],
330  'bysession' => [
331  'lng' => 'history_by_session',
332  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'history-bysession'),
333  'permission' => 'read'
334  ]
335  ]
336  ],
337  'info' => [
338  'lng' => 'info_short',
339  'link' => $DIC->ctrl()->getLinkTargetByClass([get_class($this->gui), ilInfoScreenGUI::class], 'info'),
340  'permission' => 'read'
341  ],
342  'settings' => [
343  'lng' => 'settings',
344  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'settings-general'),
345  'permission' => 'write',
346  'subtabs' => [
347  'general' => [
348  'lng' => 'settings_general',
349  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'settings-general'),
350  'permission' => 'write'
351  ]
352  ]
353  ],
354  'ban' => [
355  'lng' => 'bans',
356  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'ban-show'),
357  'permission' => 'moderate',
358  'subtabs' => [
359  'show' => [
360  'lng' => 'bans_table',
361  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'ban-show'),
362  'permission' => 'moderate'
363  ]
364  ]
365  ],
366  'export' => [
367  'lng' => 'export',
368  'link' => $DIC->ctrl()->getLinkTargetByClass(ilExportGUI::class, ''),
369  'permission' => 'write'
370  ],
371  'perm' => [
372  'lng' => 'permissions',
373  'link' => $DIC->ctrl()->getLinkTargetByClass(ilPermissionGUI::class, 'perm'),
374  'permission' => 'edit_permission'
375  ]
376  ];
377 
378  $commandParts = explode('_', $command, 2);
379  if (strtolower($DIC->ctrl()->getCmdClass()) === strtolower(ilPermissionGUI::class)) {
380  $commandParts[0] = 'perm';
381  }
382 
383  $this->buildTabs($DIC->tabs(), $config, $commandParts);
384  $this->activateTab($commandParts, $config);
385  }
386 }
static checkUserPermissions($permissions, int $ref_id, bool $send_info=true)
Checks user permissions by given array and ref_id.
buildTabs(ilTabsGUI $tabs, array $config, array $command, bool $inRoom=true)
Builds tabs and subtabs using given $tabs, $config and $command parameters.
Interface GlobalHttpState.
activateTab(array $commandParts, array $config)
Activates tab or subtab if existing.
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static convertLowerCamelCaseToUnderscoreCaseConversion(string $value)
Convert a value given in lower camel case conversion to underscore case conversion (e...
getAdminTabsForCommand(string $command)
Builds $config and $commandparts arrays to assign them as parameters when calling $this->buildTabs an...
static _getAllReferences(int $id)
get all reference ids for object ID
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
static _getObjectsByType(string $obj_type="", int $owner=null)
global $DIC
Definition: feed.php:28
addSubTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
static http()
Fetches the global http state from ILIAS.
Class ilObjectGUI Basic methods of all Output classes.
Class ilChatroomTabGUIFactory.
getLabel(array $tabDefinition, string $id)
Returns label for tab by $tabDefinition or $id.
__construct(Container $dic, ilPlugin $plugin)
static byObjectId(int $object_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getTabsForCommand(string $command)
Builds $config and $commandparts arrays to assign them as parameters when calling $this->buildTabs an...
addTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
Add a Tab.