ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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  )
94  ),
95  'smiley' => array(
96  'lng' => 'smiley',
97  'link' => $DIC->ctrl()->getLinkTargetByClass('ilObjChatroomAdminGUI', 'smiley'),
98  'permission' => 'read'
99  )
100  );
101  $DIC->ctrl()->setParameterByClass('ilObjChatroomGUI', 'ref_id', $public_room_ref);
102 
103  $config['settings'] = array(
104  'lng' => 'public_chat_settings',
105  'link' => $DIC->ctrl()->getLinkTargetByClass('ilObjChatroomGUI', 'settings-general'),
106  'permission' => 'read',
107  'subtabs' => array(
108  'settings' => array(
109  'lng' => 'settings',
110  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'settings-general'),
111  'permission' => 'read'
112  ),
113  'ban' => array(
114  'lng' => 'bans',
115  'link' => $DIC->ctrl()->getLinkTargetByClass('ilObjChatroomGUI', 'ban-show'),
116  'permission' => 'read'
117  )
118  )
119  );
120 
121  $DIC->ctrl()->setParameterByClass('ilPermissionGUI', 'ref_id', $public_room_ref);
122  $config['perm'] = array(
123  'lng' => 'public_chat_permissions',
124  'link' => $DIC->ctrl()->getLinkTargetByClass('ilPermissionGUI', 'perm'),
125  'permission' => 'read',
126  );
127  $DIC->ctrl()->clearParametersByClass('ilPermissionGUI');
128 
129  $DIC->ctrl()->setParameterByClass('ilPermissionGUI', 'ref_id', $admin_ref);
130  $config['perm_settings'] = array(
131  'lng' => 'perm_settings',
132  'link' => $DIC->ctrl()->getLinkTargetByClass('ilpermissiongui', 'perm'),
133  'permission' => 'edit_permission',
134  );
135  $DIC->ctrl()->clearParametersByClass('ilPermissionGUI');
136 
137  $commandParts = explode('_', $command, 2);
138  if ($command == 'ban_show') {
139  $commandParts[0] = 'settings';
140  $commandParts[1] = 'ban';
141  } elseif ($command == 'settings_general') {
142  $commandParts[0] = 'settings';
143  $commandParts[1] = 'settings';
144  } elseif ($command == 'view_saveclientsettings') {
145  $commandParts[0] = 'view';
146  $commandParts[1] = 'clientsettings';
147  } elseif ($DIC->ctrl()->getCmdClass() == 'ilpermissiongui' && $_REQUEST['ref_id'] == $public_room_ref) {
148  $commandParts[0] = 'perm';
149  $DIC->ctrl()->setParameterByClass('ilPermissionGUI', 'ref_id', $public_room_ref);
150  } elseif ($DIC->ctrl()->getCmdClass() == 'ilpermissiongui' && $_REQUEST['ref_id'] == $admin_ref) {
151  $commandParts[0] = 'perm_settings';
152  $DIC->ctrl()->setParameterByClass('ilPermissionGUI', 'ref_id', $admin_ref);
153  }
154 
155  $this->buildTabs($DIC->tabs(), $config, $commandParts, false);
156  $this->activateTab($commandParts, $config);
157  }
158 
164  public static function convertLowerCamelCaseToUnderscoreCaseConversion($value)
165  {
166  return strtolower(preg_replace('/(.*?)-(.*?)/', '$1_$2', $value));
167  }
168 
177  private function buildTabs(ilTabsGUI $tabs, $config, $command, $inRoom = true)
178  {
179  global $DIC;
180 
181  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
182  foreach ($config as $id => $tabDefinition) {
183  if (!$inRoom && !$DIC->rbac()->system()->checkAccess($tabDefinition['permission'], $this->gui->getRefId())) {
184  continue;
185  } elseif ($inRoom && !ilChatroom::checkUserPermissions($tabDefinition['permission'], $this->gui->getRefId(), false)) {
186  continue;
187  } elseif (isset($tabDefinition['enabled']) && !$tabDefinition['enabled']) {
188  continue;
189  }
190 
191  $tabs->addTab($id, $this->getLabel($tabDefinition, $id), $tabDefinition['link']);
192 
193  if ($command[0] == $id && isset($tabDefinition['subtabs']) &&
194  is_array($tabDefinition['subtabs'])
195  ) {
196  foreach ($tabDefinition['subtabs'] as $subid => $subTabDefinition) {
197  if (!$inRoom && !$DIC->rbac()->system()->checkAccess($tabDefinition['permission'], $this->gui->getRefId())) {
198  continue;
199  } elseif ($inRoom && !ilChatroom::checkUserPermissions($subTabDefinition['permission'], $this->gui->getRefId())) {
200  continue;
201  } elseif (isset($subTabDefinition['enabled']) && !$subTabDefinition['enabled']) {
202  continue;
203  }
204  $tabs->addSubTab(
205  $subid,
206  $this->getLabel($subTabDefinition, $subid),
207  $subTabDefinition['link']
208  );
209  }
210  }
211  }
212  }
213 
223  private function getLabel($tabDefinition, $id)
224  {
225  if (isset($tabDefinition['lng'])) {
226  return $this->lng->txt($tabDefinition['lng']);
227  } else {
228  return $this->lng->txt($id);
229  }
230  }
231 
238  private function activateTab(array $commandParts, $config)
239  {
240  global $DIC;
241 
242  if (count($commandParts) > 1) {
243  if (isset($config[$commandParts[0]])) {
244  $DIC->tabs()->activateTab($commandParts[0]);
245 
246  if (isset($config[$commandParts[0]]['subtabs'][$commandParts[1]])) {
247  $DIC->tabs()->activateSubTab($commandParts[1]);
248  }
249  }
250  } elseif (count($commandParts) == 1) {
251  $DIC->tabs()->activateTab($commandParts[0]);
252  }
253  }
254 
260  public function getTabsForCommand($command)
261  {
262  global $DIC;
263 
264  $command = $this->convertLowerCamelCaseToUnderscoreCaseConversion($command);
265  $stopCommands = array('create');
266 
267  if (in_array($command, $stopCommands)) {
268  return;
269  }
270 
271  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
272  $room = ilChatroom::byObjectId($this->gui->object->getId());
273 
274  $config = array(
275  'view' => array(
276  'lng' => 'view',
277  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'view'),
278  'permission' => 'read'
279  ),
280  'history' => array(
281  'lng' => 'history',
282  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'history-byday'),
283  'permission' => 'read',
284  'enabled' => $room ? $room->getSetting('enable_history') : false,
285  'subtabs' => array(
286  'byday' => array(
287  'lng' => 'history_by_day',
288  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'history-byday'),
289  'permission' => 'read'
290  ),
291  'bysession' => array(
292  'lng' => 'history_by_session',
293  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'history-bysession'),
294  'permission' => 'read'
295  )
296  )
297  ),
298  'info' => array(
299  'lng' => 'info_short',
300  'link' => $DIC->ctrl()->getLinkTargetByClass(array(get_class($this->gui), 'ilinfoscreengui'), 'info'),
301  'permission' => 'read'
302  ),
303  'settings' => array(
304  'lng' => 'settings',
305  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'settings-general'),
306  'permission' => 'write',
307  'subtabs' => array(
308  'general' => array(
309  'lng' => 'settings_general',
310  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'settings-general'),
311  'permission' => 'write'
312  )
313  )
314  ),
315  'ban' => array(
316  'lng' => 'bans',
317  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'ban-show'),
318  'permission' => 'moderate',
319  'subtabs' => array(
320  'show' => array(
321  'lng' => 'bans_table',
322  'link' => $DIC->ctrl()->getLinkTarget($this->gui, 'ban-show'),
323  'permission' => 'moderate'
324  )
325  )
326  ),
327  'export' => array(
328  'lng' => 'export',
329  'link' => $DIC->ctrl()->getLinkTargetByClass('ilexportgui', ''),
330  'permission' => 'write'
331  ),
332  'perm' => array(
333  'lng' => 'permissions',
334  'link' => $DIC->ctrl()->getLinkTargetByClass('ilpermissiongui', 'perm'),
335  'permission' => 'edit_permission'
336  )
337  );
338 
339  $commandParts = explode('_', $command, 2);
340 
341  if ($DIC->ctrl()->getCmdClass() == 'ilpermissiongui') {
342  $commandParts[0] = 'perm';
343  }
344 
345  $this->buildTabs($DIC->tabs(), $config, $commandParts);
346  $this->activateTab($commandParts, $config);
347  }
348 }
static convertUnderscoreCaseToLowerCamelCaseConversion($value, $upper_case_first=false)
Convert a value given in underscore case conversion to lower camel case conversion (e...
getLabel($tabDefinition, $id)
Returns label for tab by $tabDefinition or $id.
Tabs GUI.
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
static _getAllReferences($a_id)
get all reference ids of object
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.
getTabsForCommand($command)
Builds $config and $commandparts arrays to assign them as parameters when calling $this->buildTabs an...
static checkUserPermissions($permissions, $ref_id, $send_info=true)
Checks user permissions by given array and ref_id.
$token
Definition: xapitoken.php:52
getAdminTabsForCommand($command)
Builds $config and $commandparts arrays to assign them as parameters when calling $this->buildTabs an...
Class ilObjectGUI Basic methods of all Output classes.
global $DIC
Definition: goto.php:24
addSubTab($a_id, $a_text, $a_link, $a_frame="")
Add a Subtab.
Class ilChatroomTabGUIFactory.
static convertLowerCamelCaseToUnderscoreCaseConversion($value)
Convert a value given in lower camel case conversion to underscore case conversion (e...
addTab($a_id, $a_text, $a_link, $a_frame="")
Add a Tab.
static byObjectId($object_id)
Returns ilChatroom object by given $object_id.