ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
29  public function __construct(ilObjectGUI $gui)
30  {
35  global $lng;
36 
37  $this->gui = $gui;
38  $this->lng = $lng;
39  }
40 
47  public static function convertUnderscoreCaseToLowerCamelCaseConversion($value, $upper_case_first = FALSE)
48  {
49  $tokens = (array)explode('_', $value);
50  $value = '';
51 
52  foreach($tokens as $token)
53  {
54  $value .= ucfirst($token);
55  }
56 
57  if($upper_case_first === FALSE)
58  {
59  $value = strtolower($value, 0, 1) . substr($value, 1);
60  }
61 
62  return $value;
63  }
64 
70  public function getAdminTabsForCommand($command)
71  {
76  global $ilTabs, $ilCtrl;
77 
78  $command = $this->convertLowerCamelCaseToUnderscoreCaseConversion($command);
79  $stopCommands = array('create');
80 
81  if(in_array($command, $stopCommands))
82  {
83  return;
84  }
85 
86  $settings = new ilSetting('chatroom');
87  $public_room_ref = $settings->get('public_room_ref');
88 
89  $objIds = ilObject::_getObjectsByType('chta');
90  $firstObjId = current(array_keys($objIds));
91  $refIds = ilObject::_getAllReferences($firstObjId);
92  $admin_ref = current($refIds);
93 
94  $ilCtrl->setParameterByClass('ilObjChatroomAdminGUI', 'ref_id', $admin_ref);
95 
96  $config = array(
97  'view' => array(
98  'lng' => 'settings',
99  'link' => $ilCtrl->getLinkTargetByClass('ilObjChatroomAdminGUI', 'view-clientsettings'),
100  'permission' => 'read',
101  'subtabs' => array(
102  'clientsettings' => array(
103  'lng' => 'client_settings',
104  'link' => $ilCtrl->getLinkTargetByClass('ilObjChatroomAdminGUI', 'view-clientsettings'),
105  'permission' => 'read'
106  ),
107  'serversettings' => array(
108  'lng' => 'server_settings',
109  'link' => $ilCtrl->getLinkTargetByClass('ilObjChatroomAdminGUI', 'view-serversettings'),
110  'permission' => 'read'
111  )
112  )
113  ),
114  'smiley' => array(
115  'lng' => 'smiley',
116  'link' => $ilCtrl->getLinkTargetByClass('ilObjChatroomAdminGUI', 'smiley'),
117  'permission' => 'read'
118  )
119  );
120  $ilCtrl->setParameterByClass('ilObjChatroomGUI', 'ref_id', $public_room_ref);
121 
122  $config['settings'] = array(
123  'lng' => 'public_chat_settings',
124  'link' => $ilCtrl->getLinkTargetByClass('ilObjChatroomGUI', 'settings-general'),
125  'permission' => 'write',
126  'subtabs' => array(
127  'settings' => array(
128  'lng' => 'settings',
129  'link' => $ilCtrl->getLinkTarget($this->gui, 'settings-general'),
130  'permission' => 'write'
131  ),
132  'ban' => array(
133  'lng' => 'bans',
134  'link' => $ilCtrl->getLinkTargetByClass('ilObjChatroomGUI', 'ban-show'),
135  'permission' => 'moderate'
136  )
137  )
138  );
139 
140  $ilCtrl->setParameterByClass('ilPermissionGUI', 'ref_id', $public_room_ref);
141  $config['perm'] = array(
142  'lng' => 'public_chat_permissions',
143  'link' => $ilCtrl->getLinkTargetByClass('ilPermissionGUI', 'perm'),
144  'permission' => 'write',
145  );
146  $ilCtrl->clearParametersByClass('ilPermissionGUI');
147 
148  $ilCtrl->setParameterByClass('ilPermissionGUI', 'ref_id', $admin_ref);
149  $config['perm_settings'] = array(
150  'lng' => 'perm_settings',
151  'link' => $ilCtrl->getLinkTargetByClass('ilpermissiongui', 'perm'),
152  'permission' => 'write',
153  );
154  $ilCtrl->clearParametersByClass('ilPermissionGUI');
155 
156  $commandParts = explode('_', $command, 2);
157  if($command == 'ban_show')
158  {
159  $commandParts[0] = 'settings';
160  $commandParts[1] = 'ban';
161  }
162  else if($command == 'settings_general')
163  {
164  $commandParts[0] = 'settings';
165  $commandParts[1] = 'settings';
166  }
167  else if($command == 'view_savesettings')
168  {
169  $commandParts[0] = 'view';
170  $commandParts[1] = 'serversettings';
171  }
172  else if($command == 'view_saveclientsettings')
173  {
174  $commandParts[0] = 'view';
175  $commandParts[1] = 'clientsettings';
176  }
177  else if($ilCtrl->getCmdClass() == 'ilpermissiongui' && $_REQUEST['ref_id'] == $public_room_ref)
178  {
179  $commandParts[0] = 'perm';
180  $ilCtrl->setParameterByClass('ilPermissionGUI', 'ref_id', $public_room_ref);
181  }
182  else if($ilCtrl->getCmdClass() == 'ilpermissiongui' && $_REQUEST['ref_id'] == $admin_ref)
183  {
184  $commandParts[0] = 'perm_settings';
185  $ilCtrl->setParameterByClass('ilPermissionGUI', 'ref_id', $admin_ref);
186  }
187 
188  $this->buildTabs($ilTabs, $config, $commandParts);
189  $this->activateTab($commandParts, $config);
190  }
191 
197  public static function convertLowerCamelCaseToUnderscoreCaseConversion($value)
198  {
199  return strtolower(preg_replace('/(.*?)-(.*?)/', '$1_$2', $value));
200  }
201 
209  private function buildTabs(ilTabsGUI $tabs, $config, $command)
210  {
214  global $rbacsystem;
215 
216  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
217  foreach($config as $id => $tabDefinition)
218  {
219  if(!ilChatroom::checkUserPermissions($tabDefinition['permission'], $this->gui->getRefId(), false))
220  {
221  continue;
222  }
223  else if(isset($tabDefinition['enabled']) && !$tabDefinition['enabled'])
224  {
225  continue;
226  }
227 
228  $tabs->addTab($id, $this->getLabel($tabDefinition, $id), $tabDefinition['link']);
229 
230  if($command[0] == $id && isset($tabDefinition['subtabs']) &&
231  is_array($tabDefinition['subtabs'])
232  )
233  {
234  foreach($tabDefinition['subtabs'] as $subid => $subTabDefinition)
235  {
236  if(!$rbacsystem->checkAccess($subTabDefinition['permission'], $this->gui->getRefId()))
237  {
238  continue;
239  }
240  else if(isset($subTabDefinition['enabled']) && !$subTabDefinition['enabled'])
241  {
242  continue;
243  }
244  $tabs->addSubTab(
245  $subid, $this->getLabel($subTabDefinition, $subid),
246  $subTabDefinition['link']
247  );
248  }
249  }
250  }
251  }
252 
262  private function getLabel($tabDefinition, $id)
263  {
264  if(isset($tabDefinition['lng']))
265  return $this->lng->txt($tabDefinition['lng']);
266  else
267  return $this->lng->txt($id);
268  }
269 
276  private function activateTab(array $commandParts, $config)
277  {
281  global $ilTabs;
282 
283  if(count($commandParts) > 1)
284  {
285  if(isset($config[$commandParts[0]]))
286  {
287  $ilTabs->activateTab($commandParts[0]);
288 
289  if(isset($config[$commandParts[0]]['subtabs'][$commandParts[1]]))
290  {
291  $ilTabs->activateSubTab($commandParts[1]);
292  }
293  }
294  }
295  else if(count($commandParts) == 1)
296  {
297  $ilTabs->activateTab($commandParts[0]);
298  }
299  }
300 
306  public function getTabsForCommand($command)
307  {
312  global $ilTabs, $ilCtrl;
313 
314  $command = $this->convertLowerCamelCaseToUnderscoreCaseConversion($command);
315  $stopCommands = array('create');
316 
317  if(in_array($command, $stopCommands))
318  {
319  return;
320  }
321 
322  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
323  $room = ilChatroom::byObjectId($this->gui->object->getId());
324 
325  $config = array(
326  'view' => array(
327  'lng' => 'view',
328  'link' => $ilCtrl->getLinkTarget($this->gui, 'view'),
329  'permission' => 'read'
330  ),
331  'history' => array(
332  'lng' => 'history',
333  'link' => $ilCtrl->getLinkTarget($this->gui, 'history-byday'),
334  'permission' => 'read',
335  'enabled' => $room ? $room->getSetting('enable_history') : false,
336  'subtabs' => array(
337  'byday' => array(
338  'lng' => 'history_by_day',
339  'link' => $ilCtrl->getLinkTarget($this->gui, 'history-byday'),
340  'permission' => 'read'
341  ),
342  'bysession' => array(
343  'lng' => 'history_by_session',
344  'link' => $ilCtrl->getLinkTarget($this->gui, 'history-bysession'),
345  'permission' => 'read'
346  )
347  )
348  ),
349  'info' => array(
350  'lng' => 'info_short',
351  'link' => $ilCtrl->getLinkTargetByClass(array(get_class($this->gui), 'ilinfoscreengui'), 'info'),
352  'permission' => 'read'
353  ),
354  'settings' => array(
355  'lng' => 'settings',
356  'link' => $ilCtrl->getLinkTarget($this->gui, 'settings-general'),
357  'permission' => 'write',
358  'subtabs' => array(
359  'general' => array(
360  'lng' => 'settings_general',
361  'link' => $ilCtrl->getLinkTarget($this->gui, 'settings-general'),
362  'permission' => 'write'
363  )
364  )
365  ),
366  'ban' => array(
367  'lng' => 'bans',
368  'link' => $ilCtrl->getLinkTarget($this->gui, 'ban-show'),
369  'permission' => 'moderate',
370  'subtabs' => array(
371  'show' => array(
372  'lng' => 'bans_table',
373  'link' => $ilCtrl->getLinkTarget($this->gui, 'ban-show'),
374  'permission' => 'moderate'
375  )
376  )
377  ),
378  'perm' => array(
379  'lng' => 'permissions',
380  'link' => $ilCtrl->getLinkTargetByClass('ilpermissiongui', 'perm'),
381  'permission' => 'write'
382  )
383  );
384 
385  $commandParts = explode('_', $command, 2);
386 
387  if($ilCtrl->getCmdClass() == 'ilpermissiongui')
388  {
389  $commandParts[0] = 'perm';
390  }
391 
392  $this->buildTabs($ilTabs, $config, $commandParts);
393  $this->activateTab($commandParts, $config);
394  }
395 }
ILIAS Setting Class.
getLabel($tabDefinition, $id)
Returns label for tab by $tabDefinition or $id.
Tabs GUI.
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
static _getAllReferences($a_id)
get all reference ids of object
global $ilCtrl
Definition: ilias.php:18
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.
addSubTab($a_id, $a_text, $a_link, $a_frame="")
Add a Subtab.
Create styles array
The data for the language used.
Class ilChatroomTabGUIFactory.
static convertUnderscoreCaseToLowerCamelCaseConversion($value, $upper_case_first=FALSE)
Convert a value given in underscore case conversion to lower camel case conversion (e...
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.