ILIAS  release_8 Revision v8.24
class.ilRoleTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(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']) {
87 $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_global'));
88 break;
90 $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_global'));
91 break;
93 $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_local'));
94 break;
96 $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_ud_local'));
97 break;
99 $this->tpl->setVariable('ROLE_TYPE', $this->lng->txt('rbac_auto_rolt'));
100 break;
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_role_rights_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
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_role_rights_copy'));
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 $this->initFilter();
188 }
189
190 public function getType(): int
191 {
192 return $this->type;
193 }
194
195 public function setType(int $a_type): void
196 {
197 $this->type = $a_type;
198 }
199
200 protected function getPathGUI(): ilPathGUI
201 {
202 return $this->path_gui;
203 }
204
208 public function initFilter(): void
209 {
210 $this->setDisableFilterHiding(true);
211
212 $action = [];
213 switch ($this->getType()) {
214 case self::TYPE_VIEW:
215 $action[ilRbacReview::FILTER_ALL] = $this->lng->txt('all_roles');
216 $action[ilRbacReview::FILTER_ALL_GLOBAL] = $this->lng->txt('all_global_roles');
217 $action[ilRbacReview::FILTER_ALL_LOCAL] = $this->lng->txt('all_local_roles');
218 $action[ilRbacReview::FILTER_INTERNAL] = $this->lng->txt('internal_local_roles_only');
219 $action[ilRbacReview::FILTER_NOT_INTERNAL] = $this->lng->txt('non_internal_local_roles_only');
220 $action[ilRbacReview::FILTER_TEMPLATES] = $this->lng->txt('role_templates_only');
221 break;
222
224 $action[ilRbacReview::FILTER_ALL] = $this->lng->txt('all_roles');
225 $action[ilRbacReview::FILTER_ALL_GLOBAL] = $this->lng->txt('all_global_roles');
226 $action[ilRbacReview::FILTER_ALL_LOCAL] = $this->lng->txt('all_local_roles');
227 $action[ilRbacReview::FILTER_INTERNAL] = $this->lng->txt('internal_local_roles_only');
228 $action[ilRbacReview::FILTER_NOT_INTERNAL] = $this->lng->txt('non_internal_local_roles_only');
229 break;
230 }
231
232 $roles = new ilSelectInputGUI($this->lng->txt('rbac_role_selection'), 'role_type');
233 $roles->setOptions($action);
234 $this->addFilterItem($roles);
235 $roles->readFromSession();
236
237 if (!$roles->getValue()) {
238 $roles->setValue(ilRbacReview::FILTER_ALL_GLOBAL);
239 }
240
241 // title filter
242 $title = new ilTextInputGUI($this->lng->txt('title'), self::FILTER_TITLE);
243 $title->setSize(16);
244 $title->setMaxLength(64);
245 $this->addFilterItem($title);
246 $title->readFromSession();
247
248 $this->filter[self::FILTER_ROLE_TYPE] = (int) $roles->getValue();
249 $this->filter[self::FILTER_TITLE] = (string) $title->getValue();
250 }
251
256 public function parse(int $role_folder_id): void
257 {
258 $this->role_folder_id = $role_folder_id;
259
260 $filter_orig = '';
261 if ($this->getType() == self::TYPE_VIEW) {
262 $filter_orig = $this->filter[self::FILTER_TITLE];
263 $type_filter = $this->filter[self::FILTER_ROLE_TYPE];
264 } else {
265 $filter_orig = $this->getRoleTitleFilter();
266 $type_filter = ilRbacReview::FILTER_ALL;
267 }
268
269 $counter = 0;
270 $rows = [];
271 foreach ($this->rbacreview->getRolesByFilter($type_filter, 0, '') as $role) {
272 if (
273 $role['parent'] and
274 (
275 $this->tree->isDeleted($role['parent']) ||
276 !$this->tree->isInTree($role['parent'])
277 )
278 ) {
279 continue;
280 }
281 $title = ilObjRole::_getTranslation($role['title']);
282 if (strlen($filter_orig)) {
283 if (stristr($title, $filter_orig) == false) {
284 continue;
285 }
286 }
287
288 $rows[$counter]['title_orig'] = $role['title'];
289 $rows[$counter]['title'] = $title;
290 $rows[$counter]['description'] = $role['description'];
291 $rows[$counter]['obj_id'] = $role['obj_id'];
292 $rows[$counter]['parent'] = $role['parent'];
293 $rows[$counter]['type'] = $role['type'];
294
295 $auto = substr($role['title'], 0, 3) == 'il_';
296
297 // Role templates
298 if ($role['type'] == 'rolt') {
299 $rows[$counter]['rtype'] = $auto ? self::TYPE_ROLT_AU : self::TYPE_ROLT_UD;
300 } elseif ($role['parent'] == ROLE_FOLDER_ID) {
301 // Roles
302 if ($role['obj_id'] == ANONYMOUS_ROLE_ID || $role['obj_id'] == SYSTEM_ROLE_ID) {
303 $rows[$counter]['rtype'] = self::TYPE_GLOBAL_AU;
304 } else {
305 $rows[$counter]['rtype'] = self::TYPE_GLOBAL_UD;
306 }
307 } else {
308 $rows[$counter]['rtype'] = $auto ? self::TYPE_LOCAL_AU : self::TYPE_LOCAL_UD;
309 }
310
311 ++$counter;
312 }
313 $this->setMaxCount(count($rows));
314 $this->setData($rows);
315 }
316
317 public function getRoleTitleFilter(): string
318 {
320 }
321
322 public function setRoleTitleFilter(string $a_filter): void
323 {
324 $this->role_title_filter = $a_filter;
325 }
326}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
static _getTranslation(string $a_role_title)
Creates a path for a start and endnode.
class ilRbacReview Contains Review functions of core Rbac.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
TableGUI for the presentation og roles and role templates.
initFilter()
Init filter.
ilRbacReview $rbacreview
__construct(object $a_parent_gui, string $a_parent_cmd)
fillRow(array $a_set)
Standard Version of Fill Row.
setRoleTitleFilter(string $a_filter)
parse(int $role_folder_id)
Parse role list.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
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)
setDefaultOrderField(string $a_defaultorderfield)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setDisableFilterHiding(bool $a_val=true)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setData(array $a_data)
Set table data.
disable(string $a_module_name)
setMaxCount(int $a_max_count)
set max.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const SYSTEM_ROLE_ID
Definition: constants.php:29
const ANONYMOUS_ROLE_ID
Definition: constants.php:28
const ROLE_FOLDER_ID
Definition: constants.php:34
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$rows
Definition: xhr_table.php:10