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