ILIAS  release_8 Revision v8.24
class.ilOrgUnitPosition.php
Go to the documentation of this file.
1<?php
24{
25 public const CORE_POSITION_EMPLOYEE = 1;
26 public const CORE_POSITION_SUPERIOR = 2;
27
28 public static function returnDbTableName(): string
29 {
30 return "il_orgu_positions";
31 }
32
37 public static function get(): array
38 {
40 return parent::get();
41 }
42
43 public static function getCorePosition(int $core_identifier): self
44 {
46 return self::where(['core_identifier' => $core_identifier])->first();
47 }
48
49 public static function getCorePositionId(int $core_identifier): int
50 {
52 }
53
57 public function delete(): void
58 {
59 if ($this->isCorePosition()) {
60 throw new ilException('Cannot delete Core-Position');
61 }
62 parent::delete();
63 }
64
69 public static function getActive(): array
70 {
71 arObjectCache::flush(self::class);
72 $q = "SELECT DISTINCT il_orgu_positions.id, il_orgu_positions.*
73 FROM il_orgu_positions
74 LEFT JOIN il_orgu_ua ON il_orgu_positions.id = il_orgu_ua.position_id
75 WHERE il_orgu_ua.user_id IS NOT NULL
76 OR il_orgu_positions.core_position = 1";
77 $database = $GLOBALS['DIC']->database();
78 $st = $database->query($q);
79
80 $positions = array();
81
82 while ($data = $database->fetchAssoc($st)) {
83 $position = new self();
84 $position->buildFromArray($data);
85 $positions[] = $position;
86 }
87
88 return $positions;
89 }
90
96 public static function getActiveForPosition(int $orgu_ref_id): array
97 {
98 arObjectCache::flush(self::class);
99 $q = "SELECT DISTINCT il_orgu_positions.id, il_orgu_positions.*
100 FROM il_orgu_positions
101 LEFT JOIN il_orgu_ua ON il_orgu_positions.id = il_orgu_ua.position_id AND il_orgu_ua.orgu_id = %s
102 WHERE il_orgu_ua.user_id IS NOT NULL
103 OR core_position = 1";
104 $database = $GLOBALS['DIC']->database();
105 $st = $database->queryF($q, array('integer'), array($orgu_ref_id));
106
107 $positions = array();
108
109 while ($data = $database->fetchAssoc($st)) {
110 $position = new self();
111 $position->buildFromArray($data);
112 $positions[] = $position;
113 }
114
115 return $positions;
116 }
117
128 protected ?int $id = 0;
135 protected string $title = "";
142 protected string $description = "";
149 protected bool $core_position = false;
156 protected int $core_identifier = 0;
160 protected array $authorities = array();
161
162 public function afterObjectLoad(): void
163 {
164 $this->authorities = ilOrgUnitAuthority::where(array(ilOrgUnitAuthority::POSITION_ID => $this->getId()))
165 ->get();
166 }
167
168 public function update(): void
169 {
170 parent::update();
171 $this->storeAuthorities();
172 }
173
174 public function create(): void
175 {
176 parent::create();
177 $this->storeAuthorities();
178 }
179
180 public function getAuthoritiesAsArray(): array
181 {
182 $return = array();
183 foreach ($this->authorities as $authority) {
184 $return[] = $authority->__toArray();
185 }
186
187 return $return;
188 }
189
190 public function __toString(): string
191 {
192 return $this->getTitle();
193 }
194
198 public function getDependentAuthorities(): array
199 {
200 $dependent = ilOrgUnitAuthority::where(array(ilOrgUnitAuthority::FIELD_OVER => $this->getId()))
201 ->get();
202
203 return $dependent + $this->authorities;
204 }
205
209 public function deleteWithAllDependencies(): void
210 {
211 foreach ($this->getDependentAuthorities() as $authority) {
212 $authority->delete();
213 }
214
215 $ilOrgUnitUserAssignmentQueries = ilOrgUnitUserAssignmentQueries::getInstance();
216 foreach ($ilOrgUnitUserAssignmentQueries->getUserAssignmentsOfPosition($this->getId()) as $assignment) {
217 $assignment->delete();
218 }
219 parent::delete();
220 }
221
222 public function getId(): ?int
223 {
224 return $this->id;
225 }
226
227 public function setId(?int $id)
228 {
229 $this->id = $id;
230 }
231
232 public function getTitle(): string
233 {
234 return $this->title;
235 }
236
237 public function setTitle(string $title)
238 {
239 $this->title = $title;
240 }
241
242 public function getDescription(): string
243 {
244 return $this->description;
245 }
246
247 public function setDescription(string $description)
248 {
249 $this->description = $description;
250 }
251
252 public function isCorePosition(): bool
253 {
255 }
256
257 public function setCorePosition(bool $core_position)
258 {
259 $this->core_position = $core_position;
260 }
261
265 public function getAuthorities(): array
266 {
267 return $this->authorities;
268 }
269
273 public function setAuthorities(array $authorities)
274 {
275 $this->authorities = $authorities;
276 }
277
281 public function getCoreIdentifier(): int
282 {
284 }
285
290 {
291 $this->core_identifier = $core_identifier;
292 }
293
294 private function storeAuthorities(): void
295 {
296 $ids = [];
297 foreach ($this->getAuthorities() as $authority) {
298 $authority->setPositionId($this->getId());
299 if ($authority->getId()) {
300 $authority->update();
301 } else {
302 $authority->create();
303 }
304 $ids[] = $authority->getId();
305 }
306 if (count($ids) > 0) {
307 foreach (
309 'id' => $ids,
310 'position_id' => $this->getId(),
311 ), array('id' => 'NOT IN', 'position_id' => '='))->get() as $authority
312 ) {
313 $authority->delete();
314 }
315 }
316
317 if (count($ids) === 0) {
318 foreach (
320 'position_id' => $this->getId(),
321 ))->get() as $authority
322 ) {
323 $authority->delete();
324 }
325 }
326 }
327}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Class ActiveRecord.
static where($where, $operator=null)
static flush($class_name)
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...
setDescription(string $description)
static getCorePositionId(int $core_identifier)
setCorePosition(bool $core_position)
deleteWithAllDependencies()
This deletes the Position, it's Authorities, dependent Authorities and all User-Assignements!
static getCorePosition(int $core_identifier)
setCoreIdentifier(int $core_identifier)
static getActiveForPosition(int $orgu_ref_id)
setAuthorities(array $authorities)
get(string $key, Refinery\Transformation $t)
Get passed parameter, if not data passed, get key from http request.