ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilChatroomTabFactory.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  private function activateTab(array $commandParts, $config)
48  {
52  global $ilTabs;
53 
54  if(count($commandParts) > 1)
55  {
56  if(isset($config[$commandParts[0]]))
57  {
58  $ilTabs->activateTab($commandParts[0]);
59 
60  if(isset($config[$commandParts[0]]['subtabs'][$commandParts[1]]))
61  {
62  $ilTabs->activateSubTab($commandParts[1]);
63  }
64  }
65  }
66  else if(count($commandParts) == 1)
67  {
68  $ilTabs->activateTab($commandParts[0]);
69  }
70  }
71 
77  public function getAdminTabsForCommand($command)
78  {
84  global $ilTabs, $ilCtrl, $ilDB;
85 
86  $command = $this->convertLowerCamelCaseToUnderscoreCaseConversion($command);
87  $stopCommands = array('create');
88 
89  if(in_array($command, $stopCommands))
90  {
91  return;
92  }
93 
94  $settings = new ilSetting('chatroom');
95  $public_room_ref = $settings->get('public_room_ref');
96 
97  $query = 'SELECT ref_id FROM object_reference INNER JOIN object_data ON object_data.obj_id = object_reference.obj_id WHERE type = ' . $ilDB->quote('chta', 'text');
98  $rset = $ilDB->query($query);
99  $data = $ilDB->fetchAssoc($rset);
100  $admin_ref = $data['ref_id'];
101 
102  $ilCtrl->setParameterByClass('ilObjChatroomAdminGUI', 'ref_id', $admin_ref);
103 
104  $config = array(
105  'view' => array(
106  'lng' => 'settings',
107  'link' => $ilCtrl->getLinkTargetByClass('ilObjChatroomAdminGUI', 'view-clientsettings'),
108  'permission' => 'read',
109  'subtabs' => array(
110  'clientsettings' => array(
111  'lng' => 'client_settings',
112  'link' => $ilCtrl->getLinkTargetByClass('ilObjChatroomAdminGUI', 'view-clientsettings'),
113  'permission' => 'read'
114  ),
115  'serversettings' => array(
116  'lng' => 'server_settings',
117  'link' => $ilCtrl->getLinkTargetByClass('ilObjChatroomAdminGUI', 'view-serversettings'),
118  'permission' => 'read'
119  )
120  )
121  ),
122  'smiley' => array(
123  'lng' => 'smiley',
124  'link' => $ilCtrl->getLinkTargetByClass('ilObjChatroomAdminGUI', 'smiley'),
125  'permission' => 'read'
126  )
127  );
128  $ilCtrl->setParameterByClass('ilObjChatroomGUI', 'ref_id', $public_room_ref);
129 
130  $config['settings'] = array(
131  'lng' => 'public_chat_settings',
132  'link' => $ilCtrl->getLinkTargetByClass('ilObjChatroomGUI', 'settings-general'),
133  'permission' => 'write',
134  'subtabs' => array(
135  'settings' => array(
136  'lng' => 'settings',
137  'link' => $ilCtrl->getLinkTarget($this->gui, 'settings-general'),
138  'permission' => 'write'
139  ),
140  'ban' => array(
141  'lng' => 'bans',
142  'link' => $ilCtrl->getLinkTargetByClass('ilObjChatroomGUI', 'ban-show'),
143  'permission' => 'moderate'
144  )
145  )
146  );
147 
148  $ilCtrl->setParameterByClass('ilPermissionGUI', 'ref_id', $public_room_ref);
149  $config['perm'] = array(
150  'lng' => 'public_chat_permissions',
151  'link' => $ilCtrl->getLinkTargetByClass('ilPermissionGUI', 'perm'),
152  'permission' => 'write',
153  );
154  $ilCtrl->clearParametersByClass('ilPermissionGUI');
155 
156  $ilCtrl->setParameterByClass('ilPermissionGUI', 'ref_id', $admin_ref);
157  $config['perm_settings'] = array(
158  'lng' => 'perm_settings',
159  'link' => $ilCtrl->getLinkTargetByClass('ilpermissiongui', 'perm'),
160  'permission' => 'write',
161  );
162  $ilCtrl->clearParametersByClass('ilPermissionGUI');
163 
164  $commandParts = explode('_', $command, 2);
165  if($command == 'ban_show')
166  {
167  $commandParts[0] = 'settings';
168  $commandParts[1] = 'ban';
169  }
170  else if($command == 'settings_general')
171  {
172  $commandParts[0] = 'settings';
173  $commandParts[1] = 'settings';
174  }
175  else if($ilCtrl->getCmdClass() == 'ilpermissiongui' && $_REQUEST['ref_id'] == $public_room_ref)
176  {
177  $commandParts[0] = 'perm';
178  $ilCtrl->setParameterByClass('ilPermissionGUI', 'ref_id', $public_room_ref);
179  }
180  else if($ilCtrl->getCmdClass() == 'ilpermissiongui' && $_REQUEST['ref_id'] == $admin_ref)
181  {
182  $commandParts[0] = 'perm_settings';
183  $ilCtrl->setParameterByClass('ilPermissionGUI', 'ref_id', $admin_ref);
184  }
185 
186  $this->buildTabs($ilTabs, $config, $commandParts);
187  $this->activateTab($commandParts, $config);
188  }
189 
195  public function getTabsForCommand($command)
196  {
201  global $ilTabs, $ilCtrl;
202 
203  $command = $this->convertLowerCamelCaseToUnderscoreCaseConversion($command);
204  $stopCommands = array('create');
205 
206  if(in_array($command, $stopCommands))
207  {
208  return;
209  }
210 
211  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
212  $room = ilChatroom::byObjectId($this->gui->object->getId());
213 
214  $config = array(
215  'view' => array(
216  'lng' => 'view',
217  'link' => $ilCtrl->getLinkTarget($this->gui, 'view'),
218  'permission' => 'read'
219  ),
220  'history' => array(
221  'lng' => 'history',
222  'link' => $ilCtrl->getLinkTarget($this->gui, 'history-byday'),
223  'permission' => 'read',
224  'enabled' => $room ? $room->getSetting('enable_history') : false,
225  'subtabs' => array(
226  'byday' => array(
227  'lng' => 'history_by_day',
228  'link' => $ilCtrl->getLinkTarget($this->gui, 'history-byday'),
229  'permission' => 'read'
230  ),
231  'bysession' => array(
232  'lng' => 'history_by_session',
233  'link' => $ilCtrl->getLinkTarget($this->gui, 'history-bysession'),
234  'permission' => 'read'
235  )
236  )
237  ),
238  'info' => array(
239  'lng' => 'info_short',
240  'link' => $ilCtrl->getLinkTargetByClass(array(get_class($this->gui), 'ilinfoscreengui'), 'info'),
241  'permission' => 'read'
242  ),
243  'settings' => array(
244  'lng' => 'settings',
245  'link' => $ilCtrl->getLinkTarget($this->gui, 'settings-general'),
246  'permission' => 'write',
247  'subtabs' => array(
248  'general' => array(
249  'lng' => 'settings_general',
250  'link' => $ilCtrl->getLinkTarget($this->gui, 'settings-general'),
251  'permission' => 'write'
252  )
253  )
254  ),
255  'ban' => array(
256  'lng' => 'bans',
257  'link' => $ilCtrl->getLinkTarget($this->gui, 'ban-show'),
258  'permission' => 'moderate',
259  'subtabs' => array(
260  'show' => array(
261  'lng' => 'bans_table',
262  'link' => $ilCtrl->getLinkTarget($this->gui, 'ban-show'),
263  'permission' => 'moderate'
264  )
265  )
266  ),
267  'perm' => array(
268  'lng' => 'permissions',
269  'link' => $ilCtrl->getLinkTargetByClass('ilpermissiongui', 'perm'),
270  'permission' => 'write'
271  )
272  );
273 
274  $commandParts = explode('_', $command, 2);
275 
276  if($ilCtrl->getCmdClass() == 'ilpermissiongui')
277  {
278  $commandParts[0] = 'perm';
279  }
280 
281  $this->buildTabs($ilTabs, $config, $commandParts);
282  $this->activateTab($commandParts, $config);
283  }
284 
292  private function buildTabs(ilTabsGUI $tabs, $config, $command)
293  {
297  global $rbacsystem;
298 
299  require_once 'Modules/Chatroom/classes/class.ilChatroom.php';
300  foreach($config as $id => $tabDefinition)
301  {
302  if(!ilChatroom::checkUserPermissions($tabDefinition['permission'], $this->gui->getRefId(), false))
303  {
304  continue;
305  }
306  else if(isset($tabDefinition['enabled']) && !$tabDefinition['enabled'])
307  {
308  continue;
309  }
310 
311  $tabs->addTab($id, $this->getLabel($tabDefinition, $id), $tabDefinition['link']);
312 
313  if($command[0] == $id && isset($tabDefinition['subtabs']) &&
314  is_array($tabDefinition['subtabs'])
315  )
316  {
317  foreach($tabDefinition['subtabs'] as $subid => $subTabDefinition)
318  {
319  if(!$rbacsystem->checkAccess($subTabDefinition['permission'], $this->gui->getRefId()))
320  {
321  continue;
322  }
323  else if(isset($subTabDefinition['enabled']) && !$subTabDefinition['enabled'])
324  {
325  continue;
326  }
327  $tabs->addSubTab(
328  $subid, $this->getLabel($subTabDefinition, $subid),
329  $subTabDefinition['link']
330  );
331  }
332  }
333  }
334  }
335 
345  private function getLabel($tabDefinition, $id)
346  {
347  if(isset($tabDefinition['lng']))
348  return $this->lng->txt($tabDefinition['lng']);
349  else
350  return $this->lng->txt($id);
351  }
352 
358  public static function convertLowerCamelCaseToUnderscoreCaseConversion($value)
359  {
360  return strtolower(preg_replace('/(.*?)-(.*?)/', '$1_$2', $value));
361  }
362 
369  public static function convertUnderscoreCaseToLowerCamelCaseConversion($value, $upper_case_first = FALSE)
370  {
371  $tokens = (array)explode('_', $value);
372  $value = '';
373 
374  foreach($tokens as $token)
375  {
376  $value .= ucfirst($token);
377  }
378 
379  if($upper_case_first === FALSE)
380  {
381  $value = strtolower($value, 0, 1) . substr($value, 1);
382  }
383 
384  return $value;
385  }
386 }