ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilRoleTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once './Services/Table/classes/class.ilTable2GUI.php';
5 
15 {
16  const TYPE_GLOBAL_AU = 1;
17  const TYPE_GLOBAL_UD = 2;
18  const TYPE_LOCAL_AU = 3;
19  const TYPE_LOCAL_UD = 4;
20  const TYPE_ROLT_AU = 5;
21  const TYPE_ROLT_UD = 6;
22 
23 
24  const TYPE_VIEW = 1;
25  const TYPE_SEARCH = 2;
26 
27  private $path_gui = null;
28 
30  private $role_title_filter = '';
31 
37  public function __construct($a_parent_gui,$a_parent_cmd)
38  {
39  global $ilCtrl;
40 
41  $this->ctrl = $ilCtrl;
42 
43  parent::__construct($a_parent_gui, $a_parent_cmd);
44  $this->lng->loadLanguageModule('rbac');
45  $this->lng->loadLanguageModule('search');
46  }
47 
52  public function setType($a_type)
53  {
54  $this->type = $a_type;
55  }
56 
61  public function setRoleTitleFilter($a_filter)
62  {
63  $this->role_title_filter = $a_filter;
64  }
65 
70  public function getRoleTitleFilter()
71  {
73  }
74 
78  public function getType()
79  {
80  return $this->type;
81  }
82 
87  protected function getPathGUI()
88  {
89  return $this->path_gui;
90  }
91 
92 
93 
97  public function init()
98  {
99  $this->addColumn('','f','1px');
100 
101  switch($this->getType())
102  {
103  case self::TYPE_VIEW:
104  $this->setDefaultOrderField('title');
105  $this->setDefaultOrderDirection('asc');
106  $this->setId('rolf_role_tbl');
107  $this->addColumn($this->lng->txt('search_title_description'),'title','30%');
108  $this->addColumn($this->lng->txt('type'),'rtype','20%');
109  $this->addColumn($this->lng->txt('context'),'','40%');
110  $this->addColumn($this->lng->txt('actions'),'','10%');
111  $this->setTitle($this->lng->txt('objs_role'));
112  $this->addMultiCommand('confirmDelete',$this->lng->txt('delete'));
113  break;
114 
115  case self::TYPE_SEARCH:
116  $this->disable('sort');
117  $this->setId('rolf_role_search_tbl');
118  $this->addColumn($this->lng->txt('search_title_description'),'title','30%');
119  $this->addColumn($this->lng->txt('type'),'rtype','20%');
120  $this->addColumn($this->lng->txt('context'),'','50%');
121  $this->setTitle($this->lng->txt('rbac_role_rights_copy'));
122  $this->addMultiCommand('chooseCopyBehaviour',$this->lng->txt('btn_next'));
123  $this->addCommandButton('roleSearch', $this->lng->txt('btn_previous'));
124  break;
125  }
126 
127 
128  #$this->setShowRowsSelector(true);
129  $this->setRowTemplate('tpl.role_row.html','Services/AccessControl');
130  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
131  $this->setSelectAllCheckbox('roles');
132 
133  include_once './Services/Tree/classes/class.ilPathGUI.php';
134  $this->path_gui = new ilPathGUI();
135  $this->getPathGUI()->enableTextOnly(false);
136 
137 
138  // Filter initialisation
139 
140  if($this->getType() == self::TYPE_VIEW)
141  {
142  $this->initFilter();
143  }
144  }
145 
149  public function initFilter()
150  {
151  $this->setDisableFilterHiding(true);
152 
153  switch($this->getType())
154  {
155  case self::TYPE_VIEW:
156  $action[ilRbacReview::FILTER_ALL] = $this->lng->txt('all_roles');
157  $action[ilRbacReview::FILTER_ALL_GLOBAL] = $this->lng->txt('all_global_roles');
158  $action[ilRbacReview::FILTER_ALL_LOCAL] = $this->lng->txt('all_local_roles');
159  $action[ilRbacReview::FILTER_INTERNAL] = $this->lng->txt('internal_local_roles_only');
160  $action[ilRbacReview::FILTER_NOT_INTERNAL] = $this->lng->txt('non_internal_local_roles_only');
161  $action[ilRbacReview::FILTER_TEMPLATES] = $this->lng->txt('role_templates_only');
162  break;
163 
164  case self::TYPE_SEARCH:
165  $action[ilRbacReview::FILTER_ALL] = $this->lng->txt('all_roles');
166  $action[ilRbacReview::FILTER_ALL_GLOBAL] = $this->lng->txt('all_global_roles');
167  $action[ilRbacReview::FILTER_ALL_LOCAL] = $this->lng->txt('all_local_roles');
168  $action[ilRbacReview::FILTER_INTERNAL] = $this->lng->txt('internal_local_roles_only');
169  $action[ilRbacReview::FILTER_NOT_INTERNAL] = $this->lng->txt('non_internal_local_roles_only');
170  break;
171  }
172 
173  include_once './Services/Form/classes/class.ilSelectInputGUI.php';
174  $roles = new ilSelectInputGUI($this->lng->txt('rbac_role_selection'), 'role_type');
175 
176  $roles->setOptions($action);
177 
178  $this->addFilterItem($roles);
179 
180  $roles->readFromSession();
181  if(!$roles->getValue())
182  {
183  $roles->setValue(ilRbacReview::FILTER_ALL_GLOBAL);
184  }
185 
186  // title filter
187  include_once './Services/Form/classes/class.ilTextInputGUI.php';
188  $title = new ilTextInputGUI($this->lng->txt('title'), 'role_title');
189  $title->setSize(16);
190  $title->setMaxLength(64);
191 
192  $this->addFilterItem($title);
193  $title->readFromSession();
194 
195  $this->filter['role_type'] = $roles->getValue();
196  $this->filter['role_title'] = $title->getValue();
197  }
198 
203  public function fillRow($set)
204  {
205  global $rbacreview,$tree;
206 
207  if($set['type'] == 'role')
208  {
209  if($set['parent'] != ROLE_FOLDER_ID)
210  {
211  $this->ctrl->setParameterByClass(
212  "ilobjrolegui",
213  "rolf_ref_id",
214  $set['parent']
215  );
216  }
217 
218  $this->ctrl->setParameterByClass("ilobjrolegui", "obj_id", $set["obj_id"]);
219  $link = $this->ctrl->getLinkTargetByClass("ilobjrolegui", "perm");
220  $this->ctrl->setParameterByClass("ilobjrolegui", "rolf_ref_id", "");
221  }
222  else
223  {
224  $this->ctrl->setParameterByClass("ilobjroletemplategui", "obj_id", $set["obj_id"]);
225  $link = $this->ctrl->getLinkTargetByClass("ilobjroletemplategui", "perm");
226  }
227 
228  switch($set['rtype'])
229  {
230  case self::TYPE_GLOBAL_AU:
231  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_global'));
232  break;
233  case self::TYPE_GLOBAL_UD:
234  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_global'));
235  break;
236  case self::TYPE_LOCAL_AU:
237  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_local'));
238  break;
239  case self::TYPE_LOCAL_UD:
240  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_local'));
241  break;
242  case self::TYPE_ROLT_AU:
243  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_rolt'));
244  break;
245  case self::TYPE_ROLT_UD:
246  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_rolt'));
247  break;
248  }
249 
250 
251 
252  if(
253  $set['obj_id'] != ANONYMOUS_ROLE_ID and
254  $set['obj_id'] != SYSTEM_ROLE_ID and
255  substr($set['title_orig'],0,3) != 'il_')
256  {
257  $this->tpl->setVariable('VAL_ID', $set['obj_id']);
258  }
259  $this->tpl->setVariable('VAL_TITLE_LINKED', $set['title']);
260  $this->tpl->setVariable('VAL_LINK', $link);
261  if(strlen($set['description']))
262  {
263  $this->tpl->setVariable('VAL_DESC', $set['description']);
264  }
265 
273  $ref = $set['parent'];
274  if($ref == ROLE_FOLDER_ID)
275  {
276  $this->tpl->setVariable('CONTEXT', $this->lng->txt('rbac_context_global'));
277  }
278  else
279  {
280  $this->tpl->setVariable(
281  'CONTEXT',
282  (string) $this->getPathGUI()->getPath(ROOT_FOLDER_ID,$ref)
283  );
284  }
285 
286  if($this->getType() == self::TYPE_VIEW)
287  {
288  // Copy role
289  $this->tpl->setVariable('COPY_TEXT',$this->lng->txt('rbac_role_rights_copy'));
290  $this->ctrl->setParameter($this->getParentObject(), "copy_source", $set["obj_id"]);
291  $link = $this->ctrl->getLinkTarget($this->getParentObject(),'roleSearch');
292  $this->tpl->setVariable(
293  'COPY_LINK',
294  $link
295  );
296  }
297 
298  }
299 
304  public function parse($role_folder_id)
305  {
306  global $rbacreview,$ilUser;
307 
308  include_once './Services/AccessControl/classes/class.ilObjRole.php';
309 
310  if($this->getType() == self::TYPE_VIEW)
311  {
312  $filter = $this->getFilterItemByPostVar('role_title')->getValue();
313  $type = $this->getFilterItemByPostVar('role_type')->getValue();
314  }
315  else
316  {
317  $filter = $this->getRoleTitleFilter();
319  }
320 
321 
322  // @todo: check this
324  {
325  $filter = '';
326  }
327 
328  $role_list = $rbacreview->getRolesByFilter(
329  $type,
330  0,
331  $filter
332  );
333 
334  $counter = 0;
335  $rows = array();
336  foreach((array) $role_list as $role)
337  {
338  $title = ilObjRole::_getTranslation($role['title']);
340  {
341  if(strlen($filter))
342  {
343  if(stristr($title, $filter) == FALSE)
344  {
345  continue;
346  }
347  }
348  }
349  $rows[$counter]['title_orig'] = $role['title'];
350  $rows[$counter]['title'] = $title;
351  $rows[$counter]['description'] = $role['description'];
352  $rows[$counter]['obj_id'] = $role['obj_id'];
353  $rows[$counter]['parent'] = $role['parent'];
354  $rows[$counter]['type'] = $role['type'];
355 
356  $auto = (substr($role['title'], 0, 3) == 'il_' ? true : false);
357 
358 
359  // Role templates
360  if($role['type'] == 'rolt')
361  {
362  $rows[$counter]['rtype'] = $auto ? self::TYPE_ROLT_AU : self::TYPE_ROLT_UD;
363  }
364  else
365  {
366  // Roles
367  if($role['parent'] == ROLE_FOLDER_ID)
368  {
369  if($role['obj_id'] == ANONYMOUS_ROLE_ID or $role['obj_id'] == SYSTEM_ROLE_ID)
370  {
371  $rows[$counter]['rtype'] = self::TYPE_GLOBAL_AU;
372  }
373  else
374  {
375  $rows[$counter]['rtype'] = self::TYPE_GLOBAL_UD;
376  }
377  }
378  else
379  {
380  $rows[$counter]['rtype'] = $auto ? self::TYPE_LOCAL_AU : self::TYPE_LOCAL_UD;
381  }
382  }
383 
384  ++$counter;
385  }
386  $this->setMaxCount(count($rows));
387  $this->setData($rows);
388  }
389 }
390 
391 ?>