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