ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilRoleAssignmentTableGUI.php
Go to the documentation of this file.
1<?php
2
24{
26 protected array $filter; // Missing array type.
27 protected \ILIAS\UI\Factory $factory;
28 protected \ILIAS\UI\Renderer $renderer;
29 protected ilAccess $access;
30
32 protected bool $edit_access;
33
34 public function __construct(
35 object $a_parent_obj,
36 string $a_parent_cmd
37 ) {
38 global $DIC;
39
40 $ilCtrl = $DIC['ilCtrl'];
41 $lng = $DIC['lng'];
42 $rbacsystem = $DIC['rbacsystem'];
43 $this->objectDefinition = $DIC['objDefinition'];
44 $this->factory = $DIC->ui()->factory();
45 $this->renderer = $DIC->ui()->renderer();
46 $this->access = $DIC['ilAccess'];
47
48 $lng->loadLanguageModule('rbac');
49 $this->setId("usrroleass");
50
51 parent::__construct($a_parent_obj, $a_parent_cmd);
52
53 $this->setTitle($lng->txt("role_assignment"));
54 $this->setDefaultOrderField("title");
55 $this->setDefaultOrderDirection("asc");
56 $this->setDisableFilterHiding(true);
57 $this->addColumn("", "", "1", true);
58 $this->addColumn($this->lng->txt("role"), "title");
59 $this->addColumn($this->lng->txt("description"), "description");
60 $this->addColumn($this->lng->txt("context"), "context");
61 $this->addColumn($this->lng->txt('path'), 'path');
62 $this->edit_access = $rbacsystem->checkAccess("edit_roleassignment", USER_FOLDER_ID);
63 $this->initFilter();
64 $this->setEnableHeader(true);
65 $this->setRowTemplate("tpl.role_assignment_row.html", "components/ILIAS/User");
66 $this->setEnableTitle(true);
67
68 if ($this->edit_access) {
69 $this->setSelectAllCheckbox("role_id[]");
70 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
71 $this->addMultiCommand("assignSave", $lng->txt("change_assignment"));
72 }
73
74 $this->path_gui = new ilPathGUI();
75 $this->getPathGUI()->enableTextOnly(false);
76 $this->getPathGUI()->enableHideLeaf(false);
77 }
78
79 public function getPathGUI(): ilPathGUI
80 {
81 return $this->path_gui;
82 }
83
84 public function initFilter(): void
85 {
86 global $DIC;
87
88 $lng = $DIC['lng'];
89
90 // roles
91 $option[0] = $lng->txt('assigned_roles');
92 $option[1] = $lng->txt('all_roles');
93 $option[2] = $lng->txt('all_global_roles');
94 $option[3] = $lng->txt('all_local_roles');
95 $option[4] = $lng->txt('internal_local_roles_only');
96 $option[5] = $lng->txt('non_internal_local_roles_only');
97
98 if ($this->edit_access) {
99 $si = new ilSelectInputGUI($lng->txt("roles"), "role_filter");
100 $si->setOptions($option);
101 $this->addFilterItem($si);
102 $si->readFromSession();
103 $this->filter["role_filter"] = $si->getValue();
104 } else {
105 $this->filter["role_filter"] = 0;
106 }
107 }
108
109 protected function fillRow(array $a_set): void // Missing array type.
110 {
111 if ($this->edit_access) {
112 if (isset($a_set['checkbox']['id'])) {
113 $this->tpl->setVariable('VAL_ID', $a_set['checkbox']['id']);
114 if ($a_set['checkbox']['disabled']) {
115 $this->tpl->setVariable('VAL_DISABLED', 'disabled="disabled"');
116 }
117 if ($a_set['checkbox']['checked']) {
118 $this->tpl->setVariable('VAL_CHECKED', 'checked="checked"');
119 }
120 }
121 }
122
123 $this->ctrl->setParameterByClass("ilobjrolegui", "ref_id", $a_set['ref_id']);
124 $this->ctrl->setParameterByClass("ilobjrolegui", "obj_id", $a_set["obj_id"]);
125
126 $role = ilObjRole::_getTranslation($a_set['title']);
127 if ($this->access->checkAccess('edit_permission', '', (int) $a_set['ref_id'])) {
128 $role = $this->renderer->render(
129 $this->factory->link()->standard(
130 ilObjRole::_getTranslation($a_set['title']),
131 $this->ctrl->getLinkTargetByClass(ilObjRoleGUI::class, 'perm')
132 )
133 );
134 }
135 $this->tpl->setVariable('ROLE', $role);
136 $this->tpl->setVariable('DESCRIPTION', $a_set['description']);
137 // Add link to objector local Rores
138 $context = $a_set['context'];
139 if ($a_set['role_type'] === 'local' &&
140 ($this->access->checkAccess('visible', '', (int) $a_set['ref_id']) ||
141 $this->access->checkAccess('read', '', (int) $a_set['ref_id']))) {
142 $context = $this->renderer->render(
143 $this->factory->link()->standard(
144 $context,
145 ilLink::_getLink(
146 $a_set['ref_id'],
148 )
149 )
150 );
151 }
152 $this->tpl->setVariable('CONTEXT', $context);
153 $this->tpl->setVariable('PATH', $a_set['path']);
154 }
155
156 public function parse(int $usr_id): void
157 {
158 global $DIC;
159 $rbacreview = $DIC->rbac()->review();
160 $tree = $DIC->repositoryTree();
161 $ilUser = $DIC->user();
162 $assignable = false; // @todo: check this
163
164 $assigned_roles = $rbacreview->assignedRoles($usr_id);
165
166 $counter = 0;
167
168 $records = [];
169 foreach ($rbacreview->getRolesByFilter((int) $this->filter['role_filter'], $usr_id) as $role) {
170 // fetch context path of role
171 $rolf = $rbacreview->getFoldersAssignedToRole($role["obj_id"], true);
172 $ref_id = $rbacreview->getObjectReferenceOfRole($role['rol_id']);
173
174 // only list roles that are not set to status "deleted"
175 if ($rbacreview->isDeleted($rolf[0])) {
176 continue;
177 }
178
179 $context = "";
180 if ($tree->isInTree($rolf[0])) {
181 if ($rolf[0] == ROLE_FOLDER_ID) {
182 $context = $this->lng->txt("global");
183 } else {
184 $tmpPath = $tree->getPathFull($rolf[0]);
186 }
187 } else {
188 $context = "<b>Rolefolder " . $rolf[0] . " not found in tree! (Role " . $role["obj_id"] . ")</b>";
189 }
190
191 $disabled = false;
192 // disable checkbox for system role for the system user
193 if (
194 ($usr_id === (int) SYSTEM_USER_ID && $role["obj_id"] === (int) SYSTEM_ROLE_ID) ||
195 (!in_array(SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId())) && $role["obj_id"] === (int) SYSTEM_ROLE_ID)
196 ) {
197 $disabled = true;
198 }
199
200 // protected admin role
201 if ($role['obj_id'] == SYSTEM_ROLE_ID && !$rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID)) {
202 if (ilSecuritySettings::_getInstance()->isAdminRoleProtected()) {
203 $disabled = true;
204 }
205 }
206
207 if (strpos($role["title"], "il_") === 0) {
208 if (!$assignable) {
209 $rolf_arr = $rbacreview->getFoldersAssignedToRole($role["obj_id"], true);
210 $rolf2 = $rolf_arr[0];
211 } else {
212 $rolf2 = $rolf;
213 }
214
215 $parent_node = $tree->getNodeData($rolf2);
216 if (!isset($parent_node['type']) || !isset($parent_node['obj_id'])) {
217 continue;
218 }
219 $role['description'] = "{$this->lng->txt("obj_{$parent_node['type']}")}&nbsp;(#{$parent_node['obj_id']})";
220 }
221
222 $role_ids[$counter] = $role["obj_id"];
223
224 $checkbox = [
225 'id' => $role['obj_id'],
226 'disabled' => $disabled,
227 'checked' => in_array($role['obj_id'], $assigned_roles)
228 ];
229
230 $title = ilObjRole::_getTranslation($role["title"]);
231
232 $records[] = [
233 "description" => $role["description"],
234 "context" => $context,
235 "checkbox" => $checkbox,
236 "role_type" => $role["role_type"],
237 "ref_id" => $ref_id,
238 "obj_id" => $role["obj_id"],
239 "title" => $title,
240 'path' => $this->getPathGUI()->getPath(ROOT_FOLDER_ID, $ref_id)
241 ];
242 ++$counter;
243 }
244 $this->setData($records);
245 }
246
247 protected function getTitleForReference(int $ref_id): string
248 {
249 $type = ilObject::_lookupType($ref_id, true);
252
253 if ($this->objectDefinition->isAdministrationObject($type)) {
254 return $this->lng->txt('obj_' . $type);
255 }
256
257 try {
259 $list->initItem(
260 $ref_id,
261 $obj_id,
262 $type,
263 $title
264 );
265
267 $title = $list->getTitle();
269 return $title;
270 } catch (ilObjectException $e) {
271 // could be an administration object
272 }
273 return $title;
274 }
275}
renderer()
factory()
Class ilAccessHandler Checks access for ILIAS objects.
static resetToDefaults()
reset to defaults
static setUseRelativeDates(bool $a_status)
set use relative dates
loadLanguageModule(string $a_module)
Load language module.
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static _getTranslation(string $a_role_title)
parses the objects.xml it handles the xml-description of all ilias objects
Base exception class for object service.
static _getListGUIByType(string $type, int $context=ilObjectListGUI::CONTEXT_REPOSITORY)
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
fillRow(array $a_set)
Standard Version of Fill Row.
__construct(object $a_parent_obj, string $a_parent_cmd)
static _getInstance()
Get instance of ilSecuritySettings.
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...
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setEnableTitle(bool $a_enabletitle)
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)
setEnableHeader(bool $a_enableheader)
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.
ilLanguage $lng
const SYSTEM_ROLE_ID
Definition: constants.php:29
const USER_FOLDER_ID
Definition: constants.php:33
const SYSTEM_USER_ID
This file contains constants for PHPStan analyis, see: https://phpstan.org/config-reference#constants...
Definition: constants.php:26
const ROLE_FOLDER_ID
Definition: constants.php:34
const ROOT_FOLDER_ID
Definition: constants.php:32
$ref_id
Definition: ltiauth.php:66
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, array $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $DIC
Definition: shib_login.php:26
$counter