ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilRoleTableGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 {
28  private const TYPE_GLOBAL_AU = 1;
29  private const TYPE_GLOBAL_UD = 2;
30  private const TYPE_LOCAL_AU = 3;
31  private const TYPE_LOCAL_UD = 4;
32  private const TYPE_ROLT_AU = 5;
33  private const TYPE_ROLT_UD = 6;
34 
35  private const FILTER_ROLE_TYPE = 'role_type';
36  private const FILTER_TITLE = 'title';
37 
38  public const TYPE_VIEW = 1;
39  public const TYPE_SEARCH = 2;
40 
42 
43  private int $type = self::TYPE_VIEW;
44  private string $role_title_filter = '';
45  private int $role_folder_id = 0;
46 
47  private array $filter = [];
48  private ilTree $tree;
51 
52  public function __construct(object $a_parent_gui, string $a_parent_cmd)
53  {
54  global $DIC;
55 
56  $this->rbacreview = $DIC->rbac()->review();
57  $this->tree = $DIC->repositoryTree();
58  $this->system = $DIC->rbac()->system();
59 
60  $this->setId('rolf_role_tbl');
61  parent::__construct($a_parent_gui, $a_parent_cmd);
62  $this->lng->loadLanguageModule('rbac');
63  $this->lng->loadLanguageModule('search');
64  }
65 
66  protected function fillRow(array $a_set): void
67  {
68  if ($a_set['type'] == 'role') {
69  if ($a_set['parent'] != ROLE_FOLDER_ID) {
70  $this->ctrl->setParameterByClass(
71  "ilobjrolegui",
72  "rolf_ref_id",
73  $a_set['parent']
74  );
75  }
76 
77  $this->ctrl->setParameterByClass("ilobjrolegui", "obj_id", $a_set["obj_id"]);
78  $link = $this->ctrl->getLinkTargetByClass("ilobjrolegui", "perm");
79  $this->ctrl->setParameterByClass("ilobjrolegui", "rolf_ref_id", "");
80  } else {
81  $this->ctrl->setParameterByClass("ilobjroletemplategui", "obj_id", $a_set["obj_id"]);
82  $link = $this->ctrl->getLinkTargetByClass("ilobjroletemplategui", "perm");
83  }
84 
85  switch ($a_set['rtype']) {
86  case self::TYPE_GLOBAL_AU:
87  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_global'));
88  break;
89  case self::TYPE_GLOBAL_UD:
90  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_global'));
91  break;
92  case self::TYPE_LOCAL_AU:
93  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_local'));
94  break;
95  case self::TYPE_LOCAL_UD:
96  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_local'));
97  break;
98  case self::TYPE_ROLT_AU:
99  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_rolt'));
100  break;
101  case self::TYPE_ROLT_UD:
102  $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_rolt'));
103  break;
104  }
105 
106  if (
107  $a_set['obj_id'] != ANONYMOUS_ROLE_ID && $a_set['obj_id'] != SYSTEM_ROLE_ID && substr($a_set['title_orig'], 0, 3) != 'il_' || $this->getType() == self::TYPE_SEARCH) {
108  $this->tpl->setVariable('VAL_ID', $a_set['obj_id']);
109  }
110  $this->tpl->setVariable('VAL_TITLE_LINKED', $a_set['title']);
111  $this->tpl->setVariable('VAL_LINK', $link);
112  if (strlen($a_set['description'])) {
113  $this->tpl->setVariable('VAL_DESC', $a_set['description']);
114  }
115 
116  $ref = $a_set['parent'];
117  if ($ref == ROLE_FOLDER_ID) {
118  $this->tpl->setVariable('CONTEXT', $this->lng->txt('rbac_context_global'));
119  } else {
120  $this->tpl->setVariable(
121  'CONTEXT',
122  $this->getPathGUI()->getPath(ROOT_FOLDER_ID, (int) $ref)
123  );
124  }
125 
126  if ($this->getType() == self::TYPE_VIEW and $a_set['obj_id'] != SYSTEM_ROLE_ID) {
127  if ($this->system->checkAccess('write', $this->role_folder_id)) {
128  // Copy role
129  $this->tpl->setVariable('COPY_TEXT', $this->lng->txt('rbac_copy_role_copy'));
130  $this->ctrl->setParameter($this->getParentObject(), "csource", $a_set["obj_id"]);
131  $link = $this->ctrl->getLinkTarget($this->getParentObject(), 'roleSearch');
132  $this->tpl->setVariable(
133  'COPY_LINK',
134  $link
135  );
136  }
137  }
138  }
139 
143  public function init(): void
144  {
145  $this->addColumn('', 'f', '1px');
146 
147  switch ($this->getType()) {
148  case self::TYPE_VIEW:
149  $this->setShowRowsSelector(true);
150  $this->setDefaultOrderField('title');
151  $this->setDefaultOrderDirection('asc');
152  //$this->setId('rolf_role_tbl');
153  $this->addColumn($this->lng->txt('search_title_description'), 'title', '30%');
154  $this->addColumn($this->lng->txt('type'), 'rtype', '20%');
155  $this->addColumn($this->lng->txt('context'), '', '40%');
156  $this->addColumn($this->lng->txt('actions'), '', '10%');
157  $this->setTitle($this->lng->txt('objs_role'));
158 
159  if ($GLOBALS['DIC']['rbacsystem']->checkAccess(
160  'delete',
161  $this->getParentObject()->getObject()->getRefId()
162  )) {
163  $this->addMultiCommand('confirmDelete', $this->lng->txt('delete'));
164  }
165  break;
166 
167  case self::TYPE_SEARCH:
168  $this->setShowRowsSelector(true);
169  $this->disable('sort');
170  //$this->setId('rolf_role_search_tbl');
171  $this->addColumn($this->lng->txt('search_title_description'), 'title', '30%');
172  $this->addColumn($this->lng->txt('type'), 'rtype', '20%');
173  $this->addColumn($this->lng->txt('context'), '', '50%');
174  $this->setTitle($this->lng->txt('rbac_select_roles'));
175  $this->addMultiCommand('chooseCopyBehaviour', $this->lng->txt('btn_next'));
176  $this->addCommandButton('roleSearch', $this->lng->txt('btn_previous'));
177  break;
178  }
179 
180  $this->setRowTemplate('tpl.role_row.html', 'Services/AccessControl');
181  $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
182  $this->setSelectAllCheckbox('roles');
183 
184  $this->path_gui = new ilPathGUI();
185  $this->getPathGUI()->enableTextOnly(false);
186  $this->getPathGUI()->enableHideLeaf(false);
187  if ($this->type === self::TYPE_VIEW) {
188  $this->initFilter();
189  }
190  }
191 
192  public function getType(): int
193  {
194  return $this->type;
195  }
196 
197  public function setType(int $a_type): void
198  {
199  $this->type = $a_type;
200  }
201 
202  protected function getPathGUI(): ilPathGUI
203  {
204  return $this->path_gui;
205  }
206 
210  public function initFilter(): void
211  {
212  $this->setDisableFilterHiding(true);
213 
214  $action = [];
215  switch ($this->getType()) {
216  case self::TYPE_VIEW:
217  $action[ilRbacReview::FILTER_ALL] = $this->lng->txt('all_roles');
218  $action[ilRbacReview::FILTER_ALL_GLOBAL] = $this->lng->txt('all_global_roles');
219  $action[ilRbacReview::FILTER_ALL_LOCAL] = $this->lng->txt('all_local_roles');
220  $action[ilRbacReview::FILTER_INTERNAL] = $this->lng->txt('internal_local_roles_only');
221  $action[ilRbacReview::FILTER_NOT_INTERNAL] = $this->lng->txt('non_internal_local_roles_only');
222  $action[ilRbacReview::FILTER_TEMPLATES] = $this->lng->txt('role_templates_only');
223  break;
224 
225  case self::TYPE_SEARCH:
226  $action[ilRbacReview::FILTER_ALL] = $this->lng->txt('all_roles');
227  $action[ilRbacReview::FILTER_ALL_GLOBAL] = $this->lng->txt('all_global_roles');
228  $action[ilRbacReview::FILTER_ALL_LOCAL] = $this->lng->txt('all_local_roles');
229  $action[ilRbacReview::FILTER_INTERNAL] = $this->lng->txt('internal_local_roles_only');
230  $action[ilRbacReview::FILTER_NOT_INTERNAL] = $this->lng->txt('non_internal_local_roles_only');
231  break;
232  }
233 
234  $roles = new ilSelectInputGUI($this->lng->txt('rbac_role_selection'), 'role_type');
235  $roles->setOptions($action);
236  $this->addFilterItem($roles);
237  $roles->readFromSession();
238 
239  if (!$roles->getValue()) {
240  $roles->setValue(ilRbacReview::FILTER_ALL_GLOBAL);
241  }
242 
243  // title filter
244  $title = new ilTextInputGUI($this->lng->txt('title'), self::FILTER_TITLE);
245  $title->setSize(16);
246  $title->setMaxLength(64);
247  $this->addFilterItem($title);
248  $title->readFromSession();
249 
250  $this->filter[self::FILTER_ROLE_TYPE] = (int) $roles->getValue();
251  $this->filter[self::FILTER_TITLE] = (string) $title->getValue();
252  }
253 
258  public function parse(int $role_folder_id): void
259  {
260  $this->role_folder_id = $role_folder_id;
261 
262  $filter_orig = '';
263  if ($this->getType() == self::TYPE_VIEW) {
264  $filter_orig = $this->filter[self::FILTER_TITLE];
265  $type_filter = $this->filter[self::FILTER_ROLE_TYPE];
266  } else {
267  $filter_orig = $this->getRoleTitleFilter();
268  $type_filter = ilRbacReview::FILTER_ALL;
269  }
270 
271  $counter = 0;
272  $rows = [];
273  foreach ($this->rbacreview->getRolesByFilter($type_filter, 0, '') as $role) {
274  if (
275  $role['parent'] and
276  (
277  $this->tree->isDeleted($role['parent']) ||
278  !$this->tree->isInTree($role['parent'])
279  )
280  ) {
281  continue;
282  }
283  $title = ilObjRole::_getTranslation($role['title']);
284  if (strlen($filter_orig)) {
285  if (stristr($title, $filter_orig) == false) {
286  continue;
287  }
288  }
289 
290  $rows[$counter]['title_orig'] = $role['title'];
291  $rows[$counter]['title'] = $title;
292  $rows[$counter]['description'] = $role['description'];
293  $rows[$counter]['obj_id'] = $role['obj_id'];
294  $rows[$counter]['parent'] = $role['parent'];
295  $rows[$counter]['type'] = $role['type'];
296 
297  $auto = substr($role['title'], 0, 3) == 'il_';
298 
299  // Role templates
300  if ($role['type'] == 'rolt') {
301  $rows[$counter]['rtype'] = $auto ? self::TYPE_ROLT_AU : self::TYPE_ROLT_UD;
302  } elseif ($role['parent'] == ROLE_FOLDER_ID) {
303  // Roles
304  if ($role['obj_id'] == ANONYMOUS_ROLE_ID || $role['obj_id'] == SYSTEM_ROLE_ID) {
305  $rows[$counter]['rtype'] = self::TYPE_GLOBAL_AU;
306  } else {
307  $rows[$counter]['rtype'] = self::TYPE_GLOBAL_UD;
308  }
309  } else {
310  $rows[$counter]['rtype'] = $auto ? self::TYPE_LOCAL_AU : self::TYPE_LOCAL_UD;
311  }
312 
313  ++$counter;
314  }
315  $this->setMaxCount(count($rows));
316  $this->setData($rows);
317  }
318 
319  public function getRoleTitleFilter(): string
320  {
322  }
323 
324  public function setRoleTitleFilter(string $a_filter): void
325  {
326  $this->role_title_filter = $a_filter;
327  }
328 }
setData(array $a_data)
Creates a path for a start and endnode.
This class represents a selection list property in a property form.
setFormAction(string $a_form_action, bool $a_multipart=false)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
const ROOT_FOLDER_ID
Definition: constants.php:32
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
const SYSTEM_ROLE_ID
Definition: constants.php:29
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setDisableFilterHiding(bool $a_val=true)
__construct(object $a_parent_gui, string $a_parent_cmd)
setOptions(array $a_options)
parse(int $role_folder_id)
Parse role list.
setId(string $a_val)
TableGUI for the presentation og roles and role templates.
ilRbacReview $rbacreview
global $DIC
Definition: feed.php:28
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
__construct(VocabulariesInterface $vocabularies)
$GLOBALS["DIC"]
Definition: wac.php:31
setDefaultOrderField(string $a_defaultorderfield)
static _getTranslation(string $a_role_title)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
const ROLE_FOLDER_ID
Definition: constants.php:34
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
const ANONYMOUS_ROLE_ID
Definition: constants.php:28
initFilter()
Init filter.
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
disable(string $a_module_name)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
setRoleTitleFilter(string $a_filter)
addMultiCommand(string $a_cmd, string $a_text)
setMaxCount(int $a_max_count)
set max.
fillRow(array $a_set)