ILIAS  release_8 Revision v8.24
class.ilOrgUnitPermission.php
Go to the documentation of this file.
1<?php
24{
25 public const PARENT_TEMPLATE = -1;
26 public const TABLE_NAME = 'il_orgu_permissions';
36 protected ?int $id = 0;
43 protected int $context_id = 0;
50 protected array $operations = [];
54 protected array $possible_operations = [];
58 protected array $selected_operation_ids = [];
72 protected int $position_id = 0;
79 protected bool $protected = false;
80 protected bool $newly_created = false;
81
82 public function __construct($primary_key = 0)
83 {
84 parent::__construct($primary_key);
85 $this->afterObjectLoad();
86 }
87
88 public function update(): void
89 {
90 if ($this->isProtected()) {
91 throw new ilException('Cannot modify a protected ilOrgUnitPermission');
92 }
93 parent::update();
94 }
95
96 public function create(): void
97 {
98 if ($this->isProtected()) {
99 throw new ilException('Cannot modify a protected ilOrgUnitPermission');
100 }
101 parent::create();
102 }
103
104 public function delete(): void
105 {
106 if ($this->isProtected()) {
107 throw new ilException('Cannot modify a protected ilOrgUnitPermission');
108 }
109 parent::delete();
110 }
111
112 public function afterObjectLoad(): void
113 {
114 $this->possible_operations = ilOrgUnitOperationQueries::getOperationsForContextId($this->getContextId());
115 $this->operations = is_array($this->operations) ? $this->operations : array();
116 foreach ($this->operations as $operation) {
117 $this->selected_operation_ids[] = $operation->getOperationId();
118 }
120 }
121
122 public function getId(): ?int
123 {
124 return $this->id;
125 }
126
130 public function setId(?int $id): void
131 {
132 $this->id = $id;
133 }
134
138 public function getContextId(): int
139 {
140 return $this->context_id;
141 }
142
146 public function setContextId(int $context_id): void
147 {
148 $this->context_id = $context_id;
149 }
150
154 public function getOperations(): array
155 {
156 return $this->operations;
157 }
158
162 public function setOperations(array $operations): void
163 {
164 $this->operations = $operations;
165 }
166
167 public function getParentId(): int
168 {
169 return $this->parent_id;
170 }
171
172 public function setParentId(int $parent_id)
173 {
174 $this->parent_id = $parent_id;
175 }
176
177 public function getPossibleOperations(): array
178 {
180 }
181
182 public function getSelectedOperationIds(): array
183 {
185 }
186
187 public function isOperationIdSelected(int $operation_id): bool
188 {
189 return in_array($operation_id, $this->selected_operation_ids);
190 }
191
193 {
194 return $this->context;
195 }
196
198 {
199 $this->context = $context;
200 }
201
202 public static function returnDbTableName(): string
203 {
204 return self::TABLE_NAME;
205 }
206
207 public function getPositionId(): int
208 {
209 return $this->position_id;
210 }
211
212 public function setPositionId(int $position_id)
213 {
214 $this->position_id = $position_id;
215 }
216
217 public function isTemplate(): bool
218 {
219 return ($this->getParentId() === self::PARENT_TEMPLATE);
220 }
221
222 public function isDedicated(): bool
223 {
224 return ($this->getParentId() != self::PARENT_TEMPLATE);
225 }
226
227 public function isProtected(): bool
228 {
229 return $this->protected;
230 }
231
232 public function setProtected(bool $protected): void
233 {
234 $this->protected = $protected;
235 }
236
237 public function isNewlyCreated(): bool
238 {
240 }
241
242 public function setNewlyCreated(bool $newly_created)
243 {
244 $this->newly_created = $newly_created;
245 }
246
247 public function sleep($field_name)
248 {
249 switch ($field_name) {
250 case 'operations':
251 $ids = [];
252 foreach ($this->operations as $operation) {
253 $ids[] = $operation->getOperationId();
254 }
255
256 return json_encode($ids);
257 }
258
259 return parent::sleep($field_name);
260 }
261
267 public function wakeUp($field_name, $field_value)
268 {
269 switch ($field_name) {
270 case 'operations':
271 $ids = json_decode($field_value);
272 $ids = is_array($ids) ? $ids : array();
273 $operations = [];
274 foreach ($ids as $id) {
275 $ilOrgUnitOperation = ilOrgUnitOperationQueries::findById($id);
276 if ($ilOrgUnitOperation) {
277 $operations[] = $ilOrgUnitOperation;
278 }
279 }
280
281 return $operations;
282 }
283
284 return parent::wakeUp($field_name, $field_value);
285 }
286}
Class ActiveRecord.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getOperationsForContextId(string $context_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setContext(ilOrgUnitOperationContext $context)
ilOrgUnitOperationContext $context
wakeUp($field_name, $field_value)
isOperationIdSelected(int $operation_id)
setOperations(array $operations)
bool $protected
@con_has_field true @con_fieldtype integer @con_length 1
setNewlyCreated(bool $newly_created)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc