ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilOrgUnitPermissionTableGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
26  private int $ref_id = 0;
27  protected \ilOrgUnitPositionDBRepository $positionRepo;
28  protected \ilOrgUnitPermissionDBRepository $permissionRepo;
29  protected \ilOrgUnitOperationDBRepository $operationRepo;
30 
31  public function __construct(object $a_parent_obj, string $a_parent_cmd, int $a_ref_id)
32  {
33  global $ilCtrl, $tpl;
34 
35  parent::__construct($a_parent_obj, $a_parent_cmd);
36 
38  $this->positionRepo = $dic["repo.Positions"];
39  $this->permissionRepo = $dic["repo.Permissions"];
40  $this->operationRepo = $dic["repo.Operations"];
41 
42  $this->lng->loadLanguageModule('rbac');
43  $this->lng->loadLanguageModule("orgu");
44 
45  $this->ref_id = $a_ref_id;
46 
47  $this->setId('objpositionperm_' . $this->ref_id);
48 
49  $tpl->addJavaScript('assets/js/ilPermSelect.js');
50 
51  $this->setTitle($this->lng->txt('org_permission_settings'));
52  $this->setEnableHeader(true);
53  $this->disable('sort');
54  $this->setFormAction($ilCtrl->getFormAction($a_parent_obj, $a_parent_cmd));
55  $this->disable('numinfo');
56  $this->setRowTemplate("tpl.obj_position_perm_row.html", "components/ILIAS/OrgUnit");
57  $this->setShowRowsSelector(false);
58  $this->setDisableFilterHiding(true);
59  $this->setNoEntriesText($this->lng->txt('msg_no_roles_of_type'));
60 
62  }
63 
64  public function getRefId(): int
65  {
66  return $this->ref_id;
67  }
68 
72  public function getObjId(): int
73  {
74  return ilObject::_lookupObjId($this->getRefId());
75  }
76 
77  public function getObjType(): string
78  {
79  return ilObject::_lookupType($this->getObjId());
80  }
81 
85  public function fillRow(array $a_set): void
86  {
87  // Select all
88  if (isset($a_set['show_select_all'])) {
89  $this->fillSelectAll($a_set);
90 
91  return;
92  }
93  if (isset($a_set['header_command'])) {
94  $this->fillHeaderCommand($a_set);
95 
96  return;
97  }
98 
99  $objdefinition = $this->dic()['objDefinition'];
100  $is_plugin = $objdefinition->isPlugin($this->getObjType());
101 
102  foreach ($a_set as $permission) {
103  $position = $permission["position"];
104  $op_id = $permission["op_id"];
105  $operation = $permission["operation"];
106  $this->tpl->setCurrentBlock('position_td');
107  $this->tpl->setVariable('POSITION_ID', $position->getId());
108  $this->tpl->setVariable('PERM_ID', $op_id);
109 
110  if ($is_plugin) {
111  $label = ilObjectPlugin::lookupTxtById($this->getObjType(), $operation->getOperationString());
112  } else {
113  $label = $this->dic()->language()->txt('org_op_' . $operation->getOperationString());
114  }
115 
116  $this->tpl->setVariable('TXT_PERM', $label);
117  $this->tpl->setVariable('PERM_LONG', $op_id);
118 
119  if ($permission['permission_set']) {
120  $this->tpl->setVariable('PERM_CHECKED', 'checked="checked"');
121  }
122  if ($permission['from_template']) {
123  $this->tpl->setVariable('PERM_DISABLED', 'disabled="disabled"');
124  }
125 
126  $this->tpl->parseCurrentBlock();
127  }
128  }
129 
130  public function collectData(): void
131  {
132  $positions = $this->positionRepo->getAllPositions();
133 
134  $this->initColumns($positions);
135 
136  $perms = [];
137 
138  $operations = $this->operationRepo->getOperationsByContextName($this->getObjType());
139  $ops_ids = [];
140  $from_templates = [];
141  foreach ($operations as $op) {
142  $ops_ids[] = $op->getOperationId();
143 
144  $ops = [];
145  foreach ($positions as $position) {
146  $ilOrgUnitPermission = $this->permissionRepo->getLocalorDefault(
147  $this->getRefId(),
148  $position->getId()
149  );
150 
151  $is_template = $ilOrgUnitPermission->isTemplate();
152  $from_templates[$position->getId()] = $is_template;
153 
154  $ops[] = [
155  "op_id" => $op->getOperationId(),
156  "operation" => $op,
157  "position" => $position,
158  "permission" => $ilOrgUnitPermission,
159  "permission_set" => $ilOrgUnitPermission->isOperationIdSelected($op->getOperationId()),
160  "from_template" => $is_template,
161  ];
162  }
163  $perms[] = $ops;
164  }
165 
166  $perms[] = [
167  "show_select_all" => true,
168  "positions" => $positions,
169  "ops" => $ops_ids,
170  "template" => $from_templates,
171  ];
173  ->isPositionAccessActiveForObject($this->getObjId())
174  ) {
175  $perms[] = [
176  "header_command" => true,
177  "positions" => $positions,
178  "template" => $from_templates,
179  ];
180  }
181 
182  $this->setData($perms);
183  }
184 
185  protected function initColumns(array $positions): bool
186  {
187  foreach ($positions as $position) {
188  $this->addColumn($position->getTitle(), '', '', '', false, $position->getDescription());
189  }
190 
191  return true;
192  }
193 
194  private function dic(): \ILIAS\DI\Container
195  {
196  return $GLOBALS['DIC'];
197  }
198 
202  protected function fillSelectAll(array $row): void
203  {
204  foreach ($row["positions"] as $position) {
205  assert($position instanceof ilOrgUnitPosition);
206  $this->tpl->setCurrentBlock('position_select_all');
207  $id = $position->getId();
208  $this->tpl->setVariable('JS_ROLE_ID', $id);
209  $this->tpl->setVariable('JS_SUBID', 0);
210  $this->tpl->setVariable('JS_ALL_PERMS', "['" . implode("','", $row['ops']) . "']");
211  $this->tpl->setVariable('JS_FORM_NAME', $this->getFormName());
212  $this->tpl->setVariable('TXT_SEL_ALL', $this->lng->txt('select_all'));
213  if ($row["template"][$id]) {
214  $this->tpl->setVariable('ALL_DISABLED', "disabled='disabled'");
215  }
216  $this->tpl->parseCurrentBlock();
217  }
218  }
219 
223  protected function fillHeaderCommand(array $row): void
224  {
225  foreach ($row["positions"] as $position) {
226  $this->tpl->setCurrentBlock('header_command');
227  $this->tpl->setVariable('POSITION_ID', $position->getId());
228  $this->tpl->setVariable('HEADER_COMMAND_TXT', $this->dic()
229  ->language()
230  ->txt('positions_override_operations'));
231  if ($this->permissionRepo->find($this->getRefId(), $position->getId())) {
232  $this->tpl->setVariable('HEADER_CHECKED', "checked='checked'");
233  }
234 
235  $this->tpl->parseCurrentBlock();
236  }
237  }
238 }
setNoEntriesText(string $a_text)
setData(array $a_data)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFormAction(string $a_form_action, bool $a_multipart=false)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
Interface Observer Contains several chained tasks and infos about them.
setDisableFilterHiding(bool $a_val=true)
__construct(object $a_parent_obj, string $a_parent_cmd, int $a_ref_id)
ilOrgUnitPermissionDBRepository $permissionRepo
setId(string $a_val)
static _lookupObjId(int $ref_id)
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
$GLOBALS["DIC"]
Definition: wac.php:30
Class HTTPServicesTest.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
static lookupTxtById(string $plugin_id, string $lang_var)
ilOrgUnitOperationDBRepository $operationRepo
__construct(Container $dic, ilPlugin $plugin)
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)
$dic
Definition: ltiresult.php:33
disable(string $a_module_name)
language()
description: > Example for rendring a language glyph.
Definition: language.php:25
static _lookupType(int $id, bool $reference=false)
ilOrgUnitPositionDBRepository $positionRepo
setEnableHeader(bool $a_enableheader)