ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectRoleTemplatePermissionTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once ('./Services/Table/classes/class.ilTable2GUI.php');
5 include_once './Services/AccessControl/classes/class.ilPermissionGUI.php';
6 
17 {
18  private $ref_id = null;
19  private $role_id = null;
20  private $role_folder_id = 0;
21 
22  private $tpl_type = '';
23 
24  private $show_admin_permissions = false;
25 
26  private static $template_permissions = NULL;
27 
28 
33  public function __construct($a_parent_obj,$a_parent_cmd, $a_ref_id,$a_role_id,$a_type,$a_show_admin_permissions = false)
34  {
35  global $ilCtrl,$rbacreview,$tpl;
36 
37  $this->tpl_type = $a_type;
38  $this->show_admin_permissions = $a_show_admin_permissions;
39 
40  parent::__construct($a_parent_obj,$a_parent_cmd);
41 
42  $this->setId('role_template_'.$a_ref_id.'_'.$a_type);
43  $this->setFormName('role_template_permissions');
44  $this->setSelectAllCheckbox('template_perm['.$this->getTemplateType().']');
45 
46 
47  $this->lng->loadLanguageModule('rbac');
48 
49  $this->ref_id = $a_ref_id;
50  $this->role_id = $a_role_id;
51 
52  $this->role_folder_id = $rbacreview->getRoleFolderIdOfObject($this->getRefId());
53 
54  $this->setRowTemplate("tpl.obj_role_template_perm_row.html", "Services/AccessControl");
55  $this->setLimit(100);
56  $this->setShowRowsSelector(false);
57  $this->setDisableFilterHiding(true);
58  $this->setNoEntriesText($this->lng->txt('msg_no_roles_of_type'));
59 
60  $this->setEnableHeader(false);
61  $this->disable('sort');
62  $this->disable('numinfo');
63  $this->disable('form');
64 
65  $this->addColumn('','','0');
66  $this->addColumn('','','100%');
67 
68  $this->initTemplatePermissions();
69 
70  }
71 
76  protected function initTemplatePermissions()
77  {
78  global $rbacreview;
79 
80  if(self::$template_permissions !== NULL)
81  {
82  return true;
83  }
84  self::$template_permissions = $rbacreview->getAllOperationsOfRole(
85  $this->getRoleId(),
86  $this->getRoleFolderId()
87  );
88  }
89 
95  protected function getPermissions($a_type)
96  {
97  return self::$template_permissions[$a_type] ? self::$template_permissions[$a_type] : array();
98  }
99 
105  public function initTemplateType($a_type)
106  {
107  }
108 
113  public function getTemplateType()
114  {
115  return $this->tpl_type;
116  }
117 
122  public function getRoleFolderId()
123  {
124  return $this->role_folder_id;
125  }
126 
131  public function getRoleId()
132  {
133  return $this->role_id;
134  }
135 
140  public function getRefId()
141  {
142  return $this->ref_id;
143  }
144 
149  public function getObjId()
150  {
151  return ilObject::_lookupObjId($this->getRefId());
152  }
153 
158  public function getObjType()
159  {
160  return ilObject::_lookupType($this->getObjId());
161  }
162 
167  public function fillRow($row)
168  {
169  global $objDefinition;
170 
171  if(isset($row['show_ce']))
172  {
173  $this->tpl->setCurrentBlock('ce_td');
174  $this->tpl->setVariable('CE_TYPE',$this->getTemplateType());
175  $this->tpl->parseCurrentBlock();
176 
177  $this->tpl->setCurrentBlock('ce_desc_td');
178  $this->tpl->setVariable('CE_DESC_TYPE',$this->getTemplateType());
179  $this->tpl->setVariable('CE_LONG',$this->lng->txt('change_existing_object_type_desc'));
180 
181  if($objDefinition->isSystemObject($this->getTemplateType()))
182  {
183  $this->tpl->setVariable("TXT_CE",
184  $this->lng->txt("change_existing_prefix_single")." ".
185  $this->lng->txt("obj_".$this->getTemplateType())." ".
186  $this->lng->txt("change_existing_suffix_single")
187  );
188  }
189  else
190  {
191  $pl_txt = ($objDefinition->isPlugin($this->getTemplateType()))
192  ? ilPlugin::lookupTxt("rep_robj", $this->getTemplateType(),
193  "objs_".$this->getTemplateType())
194  : $this->lng->txt('objs_'.$this->getTemplateType());
195 
196  $this->tpl->setVariable('TXT_CE',
197  $this->lng->txt('change_existing_prefix').' '.
198  $pl_txt.' '.
199  $this->lng->txt('change_existing_suffix'));
200  $this->tpl->parseCurrentBlock();
201  }
202  return true;
203  }
204  else
205  {
206  $this->tpl->setCurrentBlock('perm_td');
207  $this->tpl->setVariable('OBJ_TYPE',$this->getTemplateType());
208  $this->tpl->setVariable('PERM_PERM_ID',$row['ops_id']);
209  $this->tpl->setVariable('PERM_CHECKED',$row['set'] ? 'checked="checked"' : '');
210  $this->tpl->parseCurrentBlock();
211 
212  $this->tpl->setCurrentBlock('perm_desc_td');
213  $this->tpl->setVariable('DESC_TYPE',$this->getTemplateType());
214  $this->tpl->setVariable('DESC_PERM_ID',$row['ops_id']);
215 
216  if ($row["create_type"] != "" && $objDefinition->isPlugin($row['create_type']))
217  {
218  $this->tpl->setVariable('TXT_PERMISSION',
219  ilPlugin::lookupTxt("rep_robj", $row['create_type'],
220  $this->getTemplateType()."_".$row['name']));
221  }
222  else if ($row["create_type"] == "" && $objDefinition->isPlugin($this->getTemplateType()))
223  {
224  $this->tpl->setVariable('TXT_PERMISSION',
225  ilPlugin::lookupTxt("rep_robj", $this->getTemplateType(),
226  $this->getTemplateType()."_".$row['name']));
227  }
228  else
229  {
230  if(substr($row['name'],0,6) == 'create')
231  {
232  $perm = $this->lng->txt($this->getTemplateType().'_'.$row['name']);
233  }
234  elseif($this->lng->exists($this->getTemplateType().'_'.$row['name'].'_short'))
235  {
236  $perm = $this->lng->txt($this->getTemplateType().'_'.$row['name'].'_short').': '.
237  $this->lng->txt($this->getTemplateType().'_'.$row['name']);
238  }
239  else
240  {
241  $perm = $this->lng->txt($row['name']).': '.$this->lng->txt($this->getTemplateType().'_'.$row['name']);
242  }
243 
244  $this->tpl->setVariable('TXT_PERMISSION',$perm);
245  }
246  $this->tpl->parseCurrentBlock();
247 
248  return true;
249  }
250  }
251 
256  public function parse()
257  {
258  global $rbacreview, $objDefinition;
259 
260  $operations = $this->getPermissions($this->getTemplateType());
261 
262 
263  // Object permissions
264  $rows = array();
265  foreach($rbacreview->getOperationsByTypeAndClass($this->getTemplateType(), 'object') as $ops_id)
266  {
267  $operations = $this->getPermissions($this->getTemplateType());
268 
269  $operation = $rbacreview->getOperation($ops_id);
270 
271  $perm['ops_id'] = $ops_id;
272  $perm['set'] = in_array($ops_id,$operations);
273  $perm['name'] = $operation['operation'];
274 
275  $rows[] = $perm;
276  }
277 
278  // Get creatable objects
279  $objects = $objDefinition->getCreatableSubObjects($this->getTemplateType());
280  $ops_ids = ilRbacReview::lookupCreateOperationIds(array_keys($objects));
281 
282  foreach($objects as $type => $info)
283  {
284  $ops_id = $ops_ids[$type];
285 
286  if(!$ops_id)
287  {
288  continue;
289  }
290 
291  $perm['ops_id'] = $ops_id;
292  $perm['set'] = in_array($ops_id,$operations);
293 
294  $perm['name'] = 'create_'.$info['name'];
295  $perm['create_type'] = $info['name'];
296 
297  $rows[] = $perm;
298  }
299 
300  if(!$this->show_admin_permissions)
301  {
302  $rows[] = array('show_ce' => 1);
303  }
304 
305  $this->setData($rows);
306  }
307 
308 
309 
310 }
311 ?>