ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
111 if ($this->system->checkAccess('write', $this->parent_obj->getRefId())) {
112 $this->tpl->setVariable('VAL_TITLE_LINKED', $a_set['title']);
113 $this->tpl->setVariable('VAL_LINK', $link);
114 } else {
115 $this->tpl->setVariable('VAL_TITLE', $a_set['title']);
116 }
117 if (strlen($a_set['description'])) {
118 $this->tpl->setVariable('VAL_DESC', $a_set['description']);
119 }
120
121 $ref = $a_set['parent'];
122 if ($ref == ROLE_FOLDER_ID) {
123 $this->tpl->setVariable('CONTEXT', $this->lng->txt('rbac_context_global'));
124 } else {
125 $this->tpl->setVariable(
126 'CONTEXT',
127 $this->getPathGUI()->getPath(ROOT_FOLDER_ID, (int) $ref)
128 );
129 }
130
131 if ($this->getType() == self::TYPE_VIEW and $a_set['obj_id'] != SYSTEM_ROLE_ID) {
132 if ($this->system->checkAccess('write', $this->role_folder_id)) {
133 // Copy role
134 $this->tpl->setVariable('COPY_TEXT', $this->lng->txt('rbac_copy_role_copy'));
135 $this->ctrl->setParameter($this->getParentObject(), "csource", $a_set["obj_id"]);
136 $link = $this->ctrl->getLinkTarget($this->getParentObject(), 'roleSearch');
137 $this->tpl->setVariable(
138 'COPY_LINK',
139 $link
140 );
141 }
142 }
143 }
144
148 public function init(): void
149 {
150 $this->addColumn('', 'f', '1px');
151
152 switch ($this->getType()) {
153 case self::TYPE_VIEW:
154 $this->setShowRowsSelector(true);
155 $this->setDefaultOrderField('title');
156 $this->setDefaultOrderDirection('asc');
157 //$this->setId('rolf_role_tbl');
158 $this->addColumn($this->lng->txt('search_title_description'), 'title', '30%');
159 $this->addColumn($this->lng->txt('type'), 'rtype', '20%');
160 $this->addColumn($this->lng->txt('context'), '', '40%');
161 $this->addColumn($this->lng->txt('actions'), '', '10%');
162 $this->setTitle($this->lng->txt('objs_role'));
163
164 if ($GLOBALS['DIC']['rbacsystem']->checkAccess(
165 'delete',
166 $this->getParentObject()->getObject()->getRefId()
167 )) {
168 $this->addMultiCommand('confirmDelete', $this->lng->txt('delete'));
169 }
170 break;
171
173 $this->setShowRowsSelector(true);
174 $this->disable('sort');
175 //$this->setId('rolf_role_search_tbl');
176 $this->addColumn($this->lng->txt('search_title_description'), 'title', '30%');
177 $this->addColumn($this->lng->txt('type'), 'rtype', '20%');
178 $this->addColumn($this->lng->txt('context'), '', '50%');
179 $this->setTitle($this->lng->txt('rbac_select_roles'));
180 $this->addMultiCommand('chooseCopyBehaviour', $this->lng->txt('btn_next'));
181 $this->addCommandButton('roleSearch', $this->lng->txt('btn_previous'));
182 break;
183 }
184
185 $this->setRowTemplate('tpl.role_row.html', 'components/ILIAS/AccessControl');
186 $this->setFormAction($this->ctrl->getFormAction($this->getParentObject()));
187 $this->setSelectAllCheckbox('roles');
188
189 $this->path_gui = new ilPathGUI();
190 $this->getPathGUI()->enableTextOnly(false);
191 $this->getPathGUI()->enableHideLeaf(false);
192 if ($this->type === self::TYPE_VIEW) {
193 $this->initFilter();
194 }
195 }
196
197 public function getType(): int
198 {
199 return $this->type;
200 }
201
202 public function setType(int $a_type): void
203 {
204 $this->type = $a_type;
205 }
206
207 protected function getPathGUI(): ilPathGUI
208 {
209 return $this->path_gui;
210 }
211
215 public function initFilter(): void
216 {
217 $this->setDisableFilterHiding(true);
218
219 $action = [];
220 switch ($this->getType()) {
221 case self::TYPE_VIEW:
222 $action[ilRbacReview::FILTER_ALL] = $this->lng->txt('all_roles');
223 $action[ilRbacReview::FILTER_ALL_GLOBAL] = $this->lng->txt('all_global_roles');
224 $action[ilRbacReview::FILTER_ALL_LOCAL] = $this->lng->txt('all_local_roles');
225 $action[ilRbacReview::FILTER_INTERNAL] = $this->lng->txt('internal_local_roles_only');
226 $action[ilRbacReview::FILTER_NOT_INTERNAL] = $this->lng->txt('non_internal_local_roles_only');
227 $action[ilRbacReview::FILTER_TEMPLATES] = $this->lng->txt('role_templates_only');
228 break;
229
231 $action[ilRbacReview::FILTER_ALL] = $this->lng->txt('all_roles');
232 $action[ilRbacReview::FILTER_ALL_GLOBAL] = $this->lng->txt('all_global_roles');
233 $action[ilRbacReview::FILTER_ALL_LOCAL] = $this->lng->txt('all_local_roles');
234 $action[ilRbacReview::FILTER_INTERNAL] = $this->lng->txt('internal_local_roles_only');
235 $action[ilRbacReview::FILTER_NOT_INTERNAL] = $this->lng->txt('non_internal_local_roles_only');
236 break;
237 }
238
239 $roles = new ilSelectInputGUI($this->lng->txt('rbac_role_selection'), 'role_type');
240 $roles->setOptions($action);
241 $this->addFilterItem($roles);
242 $roles->readFromSession();
243
244 if (!$roles->getValue()) {
245 $roles->setValue(ilRbacReview::FILTER_ALL_GLOBAL);
246 }
247
248 // title filter
249 $title = new ilTextInputGUI($this->lng->txt('title'), self::FILTER_TITLE);
250 $title->setSize(16);
251 $title->setMaxLength(64);
252 $this->addFilterItem($title);
253 $title->readFromSession();
254
255 $this->filter[self::FILTER_ROLE_TYPE] = (int) $roles->getValue();
256 $this->filter[self::FILTER_TITLE] = (string) $title->getValue();
257 }
258
263 public function parse(int $role_folder_id): void
264 {
265 $this->role_folder_id = $role_folder_id;
266
267 $filter_orig = '';
268 if ($this->getType() == self::TYPE_VIEW) {
269 $filter_orig = $this->filter[self::FILTER_TITLE];
270 $type_filter = $this->filter[self::FILTER_ROLE_TYPE];
271 } else {
272 $filter_orig = $this->getRoleTitleFilter();
273 $type_filter = ilRbacReview::FILTER_ALL;
274 }
275
276 $counter = 0;
277 $rows = [];
278 foreach ($this->rbacreview->getRolesByFilter($type_filter, 0, '') as $role) {
279 if (
280 $role['parent'] and
281 (
282 $this->tree->isDeleted($role['parent']) ||
283 !$this->tree->isInTree($role['parent'])
284 )
285 ) {
286 continue;
287 }
288 $title = ilObjRole::_getTranslation($role['title']);
289 if (strlen($filter_orig)) {
290 if (stristr($title, $filter_orig) == false) {
291 continue;
292 }
293 }
294
295 $rows[$counter]['title_orig'] = $role['title'];
296 $rows[$counter]['title'] = $title;
297 $rows[$counter]['description'] = $role['description'];
298 $rows[$counter]['obj_id'] = $role['obj_id'];
299 $rows[$counter]['parent'] = $role['parent'];
300 $rows[$counter]['type'] = $role['type'];
301
302 $auto = substr($role['title'], 0, 3) == 'il_';
303
304 // Role templates
305 if ($role['type'] == 'rolt') {
306 $rows[$counter]['rtype'] = $auto ? self::TYPE_ROLT_AU : self::TYPE_ROLT_UD;
307 } elseif ($role['parent'] == ROLE_FOLDER_ID) {
308 // Roles
309 if ($role['obj_id'] == ANONYMOUS_ROLE_ID || $role['obj_id'] == SYSTEM_ROLE_ID) {
310 $rows[$counter]['rtype'] = self::TYPE_GLOBAL_AU;
311 } else {
312 $rows[$counter]['rtype'] = self::TYPE_GLOBAL_UD;
313 }
314 } else {
315 $rows[$counter]['rtype'] = $auto ? self::TYPE_LOCAL_AU : self::TYPE_LOCAL_UD;
316 }
317
318 ++$counter;
319 }
320 $this->setMaxCount(count($rows));
321 $this->setData($rows);
322 }
323
324 public function getRoleTitleFilter(): string
325 {
327 }
328
329 public function setRoleTitleFilter(string $a_filter): void
330 {
331 $this->role_title_filter = $a_filter;
332 }
333}
static _getTranslation(string $a_role_title)
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.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
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
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $DIC
Definition: shib_login.php:26
$counter
$GLOBALS["DIC"]
Definition: wac.php:54