ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilChatroomTabGUIFactory.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
12{
16 private $gui;
17
21 private $lng;
22
26 public function __construct(ilObjectGUI $gui)
27 {
28 global $DIC;
29
30 $this->gui = $gui;
31 $this->lng = $DIC->language();
32 }
33
40 public static function convertUnderscoreCaseToLowerCamelCaseConversion($value, $upper_case_first = false)
41 {
42 $tokens = (array) explode('_', $value);
43 $value = '';
44
45 foreach ($tokens as $token) {
46 $value .= ucfirst($token);
47 }
48
49 if ($upper_case_first === false) {
50 $value = strtolower(substr($value, 0, 1)) . substr($value, 1);
51 }
52
53 return $value;
54 }
55
61 public function getAdminTabsForCommand($command)
62 {
63 global $DIC;
64
65 $command = $this->convertLowerCamelCaseToUnderscoreCaseConversion($command);
66 $stopCommands = array('create');
67
68 if (in_array($command, $stopCommands)) {
69 return;
70 }
71
72 $settings = new ilSetting('chatroom');
73 $public_room_ref = $settings->get('public_room_ref');
74
75 $objIds = ilObject::_getObjectsByType('chta');
76 $firstObjId = current(array_keys($objIds));
77 $refIds = ilObject::_getAllReferences($firstObjId);
78 $admin_ref = current($refIds);
79
80 $DIC->ctrl()->setParameterByClass('ilObjChatroomAdminGUI', 'ref_id', $admin_ref);
81
82 $config = array(
83 'view' => array(
84 'lng' => 'settings',
85 'link' => $DIC->ctrl()->getLinkTargetByClass('ilObjChatroomAdminGUI', 'view-clientsettings'),
86 'permission' => 'read',
87 'subtabs' => array(
88 'clientsettings' => array(
89 'lng' => 'client_settings',
90 'link' => $DIC->ctrl()->getLinkTargetByClass('ilObjChatroomAdminGUI', 'view-clientsettings'),
91 'permission' => 'read'
92 ),
93 'serversettings' => array(
94 'lng' => 'server_settings',
95 'link' => $DIC->ctrl()->getLinkTargetByClass('ilObjChatroomAdminGUI', 'view-serversettings'),
96 'permission' => 'read'
97 )
98 )
99 ),
100 'smiley' => array(
101 'lng' => 'smiley',
102 'link' => $DIC->ctrl()->getLinkTargetByClass('ilObjChatroomAdminGUI', 'smiley'),
103 'permission' => 'read'
104 )
105 );
106 $DIC->ctrl()->setParameterByClass('ilObjChatroomGUI', 'ref_id', $public_room_ref);
107
108 $config['settings'] = array(
109 'lng' => 'public_chat_settings',
110 'link' => $DIC->ctrl()->getLinkTargetByClass('ilObjChatroomGUI', 'settings-general'),
111 'permission' => 'write',
112 'subtabs' => array(
113 'settings' => array(
114 'lng' => 'settings',
115 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'settings-general'),
116 'permission' => 'write'
117 ),
118 'ban' => array(
119 'lng' => 'bans',
120 'link' => $DIC->ctrl()->getLinkTargetByClass('ilObjChatroomGUI', 'ban-show'),
121 'permission' => 'moderate'
122 )
123 )
124 );
125
126 $DIC->ctrl()->setParameterByClass('ilPermissionGUI', 'ref_id', $public_room_ref);
127 $config['perm'] = array(
128 'lng' => 'public_chat_permissions',
129 'link' => $DIC->ctrl()->getLinkTargetByClass('ilPermissionGUI', 'perm'),
130 'permission' => 'edit_permission',
131 );
132 $DIC->ctrl()->clearParametersByClass('ilPermissionGUI');
133
134 $DIC->ctrl()->setParameterByClass('ilPermissionGUI', 'ref_id', $admin_ref);
135 $config['perm_settings'] = array(
136 'lng' => 'perm_settings',
137 'link' => $DIC->ctrl()->getLinkTargetByClass('ilpermissiongui', 'perm'),
138 'permission' => 'edit_permission',
139 );
140 $DIC->ctrl()->clearParametersByClass('ilPermissionGUI');
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_savesettings') {
150 $commandParts[0] = 'view';
151 $commandParts[1] = 'serversettings';
152 } elseif ($command == 'view_saveclientsettings') {
153 $commandParts[0] = 'view';
154 $commandParts[1] = 'clientsettings';
155 } elseif ($DIC->ctrl()->getCmdClass() == 'ilpermissiongui' && $_REQUEST['ref_id'] == $public_room_ref) {
156 $commandParts[0] = 'perm';
157 $DIC->ctrl()->setParameterByClass('ilPermissionGUI', 'ref_id', $public_room_ref);
158 } elseif ($DIC->ctrl()->getCmdClass() == 'ilpermissiongui' && $_REQUEST['ref_id'] == $admin_ref) {
159 $commandParts[0] = 'perm_settings';
160 $DIC->ctrl()->setParameterByClass('ilPermissionGUI', 'ref_id', $admin_ref);
161 }
162
163 $this->buildTabs($DIC->tabs(), $config, $commandParts, false);
164 $this->activateTab($commandParts, $config);
165 }
166
173 {
174 return strtolower(preg_replace('/(.*?)-(.*?)/', '$1_$2', $value));
175 }
176
185 private function buildTabs(ilTabsGUI $tabs, $config, $command, $inRoom = true)
186 {
187 global $DIC;
188
189 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
190 foreach ($config as $id => $tabDefinition) {
191 if (!$inRoom && !$DIC->rbac()->system()->checkAccess($tabDefinition['permission'], $this->gui->getRefId())) {
192 continue;
193 } elseif ($inRoom && !ilChatroom::checkUserPermissions($tabDefinition['permission'], $this->gui->getRefId(), false)) {
194 continue;
195 } elseif (isset($tabDefinition['enabled']) && !$tabDefinition['enabled']) {
196 continue;
197 }
198
199 $tabs->addTab($id, $this->getLabel($tabDefinition, $id), $tabDefinition['link']);
200
201 if ($command[0] == $id && isset($tabDefinition['subtabs']) &&
202 is_array($tabDefinition['subtabs'])
203 ) {
204 foreach ($tabDefinition['subtabs'] as $subid => $subTabDefinition) {
205 if (!$inRoom && !$DIC->rbac()->system()->checkAccess($tabDefinition['permission'], $this->gui->getRefId())) {
206 continue;
207 } elseif ($inRoom && !ilChatroom::checkUserPermissions($subTabDefinition['permission'], $this->gui->getRefId())) {
208 continue;
209 } elseif (isset($subTabDefinition['enabled']) && !$subTabDefinition['enabled']) {
210 continue;
211 }
212 $tabs->addSubTab(
213 $subid,
214 $this->getLabel($subTabDefinition, $subid),
215 $subTabDefinition['link']
216 );
217 }
218 }
219 }
220 }
221
231 private function getLabel($tabDefinition, $id)
232 {
233 if (isset($tabDefinition['lng'])) {
234 return $this->lng->txt($tabDefinition['lng']);
235 } else {
236 return $this->lng->txt($id);
237 }
238 }
239
246 private function activateTab(array $commandParts, $config)
247 {
248 global $DIC;
249
250 if (count($commandParts) > 1) {
251 if (isset($config[$commandParts[0]])) {
252 $DIC->tabs()->activateTab($commandParts[0]);
253
254 if (isset($config[$commandParts[0]]['subtabs'][$commandParts[1]])) {
255 $DIC->tabs()->activateSubTab($commandParts[1]);
256 }
257 }
258 } elseif (count($commandParts) == 1) {
259 $DIC->tabs()->activateTab($commandParts[0]);
260 }
261 }
262
268 public function getTabsForCommand($command)
269 {
270 global $DIC;
271
272 $command = $this->convertLowerCamelCaseToUnderscoreCaseConversion($command);
273 $stopCommands = array('create');
274
275 if (in_array($command, $stopCommands)) {
276 return;
277 }
278
279 require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
280 $room = ilChatroom::byObjectId($this->gui->object->getId());
281
282 $config = array(
283 'view' => array(
284 'lng' => 'view',
285 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'view'),
286 'permission' => 'read'
287 ),
288 'history' => array(
289 'lng' => 'history',
290 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'history-byday'),
291 'permission' => 'read',
292 'enabled' => $room ? $room->getSetting('enable_history') : false,
293 'subtabs' => array(
294 'byday' => array(
295 'lng' => 'history_by_day',
296 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'history-byday'),
297 'permission' => 'read'
298 ),
299 'bysession' => array(
300 'lng' => 'history_by_session',
301 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'history-bysession'),
302 'permission' => 'read'
303 )
304 )
305 ),
306 'info' => array(
307 'lng' => 'info_short',
308 'link' => $DIC->ctrl()->getLinkTargetByClass(array(get_class($this->gui), 'ilinfoscreengui'), 'info'),
309 'permission' => 'read'
310 ),
311 'settings' => array(
312 'lng' => 'settings',
313 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'settings-general'),
314 'permission' => 'write',
315 'subtabs' => array(
316 'general' => array(
317 'lng' => 'settings_general',
318 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'settings-general'),
319 'permission' => 'write'
320 )
321 )
322 ),
323 'ban' => array(
324 'lng' => 'bans',
325 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'ban-show'),
326 'permission' => 'moderate',
327 'subtabs' => array(
328 'show' => array(
329 'lng' => 'bans_table',
330 'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'ban-show'),
331 'permission' => 'moderate'
332 )
333 )
334 ),
335 'export' => array(
336 'lng' => 'export',
337 'link' => $DIC->ctrl()->getLinkTargetByClass('ilexportgui', ''),
338 'permission' => 'write'
339 ),
340 'perm' => array(
341 'lng' => 'permissions',
342 'link' => $DIC->ctrl()->getLinkTargetByClass('ilpermissiongui', 'perm'),
343 'permission' => 'edit_permission'
344 )
345 );
346
347 $commandParts = explode('_', $command, 2);
348
349 if ($DIC->ctrl()->getCmdClass() == 'ilpermissiongui') {
350 $commandParts[0] = 'perm';
351 }
352
353 $this->buildTabs($DIC->tabs(), $config, $commandParts);
354 $this->activateTab($commandParts, $config);
355 }
356}
An exception for terminatinating execution or to throw for unit testing.
Class ilChatroomTabGUIFactory.
buildTabs(ilTabsGUI $tabs, $config, $command, $inRoom=true)
Builds tabs and subtabs using given $tabs, $config and $command parameters.
activateTab(array $commandParts, $config)
Activates tab or subtab if existing.
getLabel($tabDefinition, $id)
Returns label for tab by $tabDefinition or $id.
static convertLowerCamelCaseToUnderscoreCaseConversion($value)
Convert a value given in lower camel case conversion to underscore case conversion (e....
static convertUnderscoreCaseToLowerCamelCaseConversion($value, $upper_case_first=false)
Convert a value given in underscore case conversion to lower camel case conversion (e....
getAdminTabsForCommand($command)
Builds $config and $commandparts arrays to assign them as parameters when calling $this->buildTabs an...
getTabsForCommand($command)
Builds $config and $commandparts arrays to assign them as parameters when calling $this->buildTabs an...
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
Class ilObjectGUI Basic methods of all Output classes.
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
static _getAllReferences($a_id)
get all reference ids of object
ILIAS Setting Class.
Tabs GUI.
if(!empty($this->data['faventry'])) $tabs
Definition: disco.tpl.php:124
if(!array_key_exists('StateId', $_REQUEST)) $id
$config
Definition: bootstrap.php:15
global $DIC
Definition: saml.php:7