ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
31 protected bool $edit_access;
32
33 public function __construct(
34 object $a_parent_obj,
35 string $a_parent_cmd
36 ) {
37 global $DIC;
38
39 $ilCtrl = $DIC['ilCtrl'];
40 $lng = $DIC['lng'];
41 $rbacsystem = $DIC['rbacsystem'];
42 $this->objectDefinition = $DIC['objDefinition'];
43 $this->factory = $DIC->ui()->factory();
44 $this->renderer = $DIC->ui()->renderer();
45
46
47 $lng->loadLanguageModule('rbac');
48 $this->setId("usrroleass");
49
50 parent::__construct($a_parent_obj, $a_parent_cmd);
51
52 $this->setTitle($lng->txt("role_assignment"));
53 $this->setDefaultOrderField("title");
54 $this->setDefaultOrderDirection("asc");
55 $this->setDisableFilterHiding(true);
56 $this->addColumn("", "", "1", true);
57 $this->addColumn($this->lng->txt("role"), "title");
58 $this->addColumn($this->lng->txt("description"), "description");
59 $this->addColumn($this->lng->txt("context"), "context");
60 $this->addColumn($this->lng->txt('path'), 'path');
61 $this->edit_access = $rbacsystem->checkAccess("edit_roleassignment", USER_FOLDER_ID);
62 $this->initFilter();
63 $this->setEnableHeader(true);
64 $this->setRowTemplate("tpl.role_assignment_row.html", "components/ILIAS/User");
65 $this->setEnableTitle(true);
66
67 if ($this->edit_access) {
68 $this->setSelectAllCheckbox("role_id[]");
69 $this->setFormAction($ilCtrl->getFormAction($a_parent_obj));
70 $this->addMultiCommand("assignSave", $lng->txt("change_assignment"));
71 }
72
73 $this->path_gui = new ilPathGUI();
74 $this->getPathGUI()->enableTextOnly(false);
75 $this->getPathGUI()->enableHideLeaf(false);
76 }
77
78 public function getPathGUI(): ilPathGUI
79 {
80 return $this->path_gui;
81 }
82
83 public function initFilter(): void
84 {
85 global $DIC;
86
87 $lng = $DIC['lng'];
88
89 // roles
90 $option[0] = $lng->txt('assigned_roles');
91 $option[1] = $lng->txt('all_roles');
92 $option[2] = $lng->txt('all_global_roles');
93 $option[3] = $lng->txt('all_local_roles');
94 $option[4] = $lng->txt('internal_local_roles_only');
95 $option[5] = $lng->txt('non_internal_local_roles_only');
96
97 if ($this->edit_access) {
98 $si = new ilSelectInputGUI($lng->txt("roles"), "role_filter");
99 $si->setOptions($option);
100 $this->addFilterItem($si);
101 $si->readFromSession();
102 $this->filter["role_filter"] = $si->getValue();
103 } else {
104 $this->filter["role_filter"] = 0;
105 }
106 }
107
108 protected function fillRow(array $a_set): void // Missing array type.
109 {
110 if ($this->edit_access) {
111 if (isset($a_set['checkbox']['id'])) {
112 $this->tpl->setVariable('VAL_ID', $a_set['checkbox']['id']);
113 if ($a_set['checkbox']['disabled']) {
114 $this->tpl->setVariable('VAL_DISABLED', 'disabled="disabled"');
115 }
116 if ($a_set['checkbox']['checked']) {
117 $this->tpl->setVariable('VAL_CHECKED', 'checked="checked"');
118 }
119 }
120 }
121
122 $this->ctrl->setParameterByClass("ilobjrolegui", "ref_id", $a_set['ref_id']);
123 $this->ctrl->setParameterByClass("ilobjrolegui", "obj_id", $a_set["obj_id"]);
124
125 $this->tpl->setVariable(
126 'ROLE',
127 $this->renderer->render(
128 $this->factory->link()->standard(
129 ilObjRole::_getTranslation($a_set['title']),
130 $this->ctrl->getLinkTargetByClass(ilObjRoleGUI::class, 'perm')
131 )
132 )
133 );
134 $this->tpl->setVariable('DESCRIPTION', $a_set['description']);
135 // Add link to objector local Rores
136 $context = $a_set['context'];
137 if ($a_set['role_type'] === 'local') {
138 $context = $this->renderer->render(
139 $this->factory->link()->standard(
140 $context,
141 ilLink::_getLink(
142 $a_set['ref_id'],
144 )
145 )
146 );
147 }
148 $this->tpl->setVariable('CONTEXT', $context);
149 $this->tpl->setVariable('PATH', $a_set['path']);
150 }
151
152 public function parse(int $usr_id): void
153 {
154 global $DIC;
155 $rbacreview = $DIC->rbac()->review();
156 $tree = $DIC->repositoryTree();
157 $ilUser = $DIC->user();
158 $assignable = false; // @todo: check this
159
160 $assigned_roles = $rbacreview->assignedRoles($usr_id);
161
162 $counter = 0;
163
164 $records = [];
165 foreach ($rbacreview->getRolesByFilter((int) $this->filter['role_filter'], $usr_id) as $role) {
166 // fetch context path of role
167 $rolf = $rbacreview->getFoldersAssignedToRole($role["obj_id"], true);
168 $ref_id = $rbacreview->getObjectReferenceOfRole($role['rol_id']);
169
170 // only list roles that are not set to status "deleted"
171 if ($rbacreview->isDeleted($rolf[0])) {
172 continue;
173 }
174
175 $context = "";
176 if ($tree->isInTree($rolf[0])) {
177 if ($rolf[0] == ROLE_FOLDER_ID) {
178 $context = $this->lng->txt("global");
179 } else {
180 $tmpPath = $tree->getPathFull($rolf[0]);
182 }
183 } else {
184 $context = "<b>Rolefolder " . $rolf[0] . " not found in tree! (Role " . $role["obj_id"] . ")</b>";
185 }
186
187 $disabled = false;
188 // disable checkbox for system role for the system user
189 if (
190 ($usr_id === (int) SYSTEM_USER_ID && $role["obj_id"] === (int) SYSTEM_ROLE_ID) ||
191 (!in_array(SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId())) && $role["obj_id"] === (int) SYSTEM_ROLE_ID)
192 ) {
193 $disabled = true;
194 }
195
196 // protected admin role
197 if ($role['obj_id'] == SYSTEM_ROLE_ID && !$rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID)) {
198 if (ilSecuritySettings::_getInstance()->isAdminRoleProtected()) {
199 $disabled = true;
200 }
201 }
202
203 if (strpos($role["title"], "il_") === 0) {
204 if (!$assignable) {
205 $rolf_arr = $rbacreview->getFoldersAssignedToRole($role["obj_id"], true);
206 $rolf2 = $rolf_arr[0];
207 } else {
208 $rolf2 = $rolf;
209 }
210
211 $parent_node = $tree->getNodeData($rolf2);
212 if (!isset($parent_node['type']) || !isset($parent_node['obj_id'])) {
213 continue;
214 }
215 $role['description'] = "{$this->lng->txt("obj_{$parent_node['type']}")}&nbsp;(#{$parent_node['obj_id']})";
216 }
217
218 $role_ids[$counter] = $role["obj_id"];
219
220 $checkbox = [
221 'id' => $role['obj_id'],
222 'disabled' => $disabled,
223 'checked' => in_array($role['obj_id'], $assigned_roles)
224 ];
225
226 $title = ilObjRole::_getTranslation($role["title"]);
227
228 $records[] = [
229 "description" => $role["description"],
230 "context" => $context,
231 "checkbox" => $checkbox,
232 "role_type" => $role["role_type"],
233 "ref_id" => $ref_id,
234 "obj_id" => $role["obj_id"],
235 "title" => $title,
236 'path' => $this->getPathGUI()->getPath(ROOT_FOLDER_ID, $ref_id)
237 ];
238 ++$counter;
239 }
240 $this->setData($records);
241 }
242
243 protected function getTitleForReference(int $ref_id): string
244 {
245 $type = ilObject::_lookupType($ref_id, true);
248
249 if ($this->objectDefinition->isAdministrationObject($type)) {
250 return $this->lng->txt('obj_' . $type);
251 }
252
253 try {
255 $list->initItem(
256 $ref_id,
257 $obj_id,
258 $type,
259 $title
260 );
261
263 $title = $list->getTitle();
265 return $title;
266 } catch (ilObjectException $e) {
267 // could be an administration object
268 }
269 return $title;
270 }
271}
renderer()
factory()
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, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $DIC
Definition: shib_login.php:26
$counter