ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilOrgUnitPosition.php
Go to the documentation of this file.
1<?php
2
9{
12
13
17 public static function returnDbTableName()
18 {
19 return "il_orgu_positions";
20 }
21
22
28 public static function get()
29 {
31 return parent::get();
32 }
33
34
40 public static function getCorePosition($core_identifier)
41 {
43 return ilOrgUnitPosition::where(['core_identifier' => $core_identifier])->first();
44 }
45
46
52 public static function getCorePositionId($core_identifier)
53 {
55 }
56
57
61 public function delete()
62 {
63 if ($this->isCorePosition()) {
64 throw new ilException('Cannot delete Core-Position');
65 }
66 parent::delete();
67 }
68
69
74 public static function getActive()
75 {
76 arObjectCache::flush(self::class);
77 $q = "SELECT DISTINCT il_orgu_positions.id, il_orgu_positions.*
78 FROM il_orgu_positions
79 LEFT JOIN il_orgu_ua ON il_orgu_positions.id = il_orgu_ua.position_id
80 WHERE il_orgu_ua.user_id IS NOT NULL
81 OR il_orgu_positions.core_position = 1";
82 $database = $GLOBALS['DIC']->database();
83 $st = $database->query($q);
84
85 $positions = array();
86
87 while ($data = $database->fetchAssoc($st)) {
88 $position = new self();
89 $position->buildFromArray($data);
90 $positions[] = $position;
91 }
92
93 return $positions;
94 }
95
96
103 public static function getActiveForPosition($orgu_ref_id)
104 {
105 arObjectCache::flush(self::class);
106 $q = "SELECT DISTINCT il_orgu_positions.id, il_orgu_positions.*
107 FROM il_orgu_positions
108 LEFT JOIN il_orgu_ua ON il_orgu_positions.id = il_orgu_ua.position_id AND il_orgu_ua.orgu_id = %s
109 WHERE il_orgu_ua.user_id IS NOT NULL
110 OR core_position = 1";
111 $database = $GLOBALS['DIC']->database();
112 $st = $database->queryF($q, array('integer'), array($orgu_ref_id));
113
114 $positions = array();
115
116 while ($data = $database->fetchAssoc($st)) {
117 $position = new self();
118 $position->buildFromArray($data);
119 $positions[] = $position;
120 }
121
122 return $positions;
123 }
124
125
136 protected $id = 0;
144 protected $title = "";
152 protected $description = "";
160 protected $core_position = false;
168 protected $core_identifier = 0;
172 protected $authorities = array();
173
174
175 public function afterObjectLoad()
176 {
177 $this->authorities = ilOrgUnitAuthority::where(array(ilOrgUnitAuthority::POSITION_ID => $this->getId()))
178 ->get();
179 }
180
181
182 public function update()
183 {
184 parent::update();
185 $this->storeAuthorities();
186 }
187
188
189 public function create()
190 {
191 parent::create();
192 $this->storeAuthorities();
193 }
194
195
199 public function getAuthoritiesAsArray()
200 {
201 $return = array();
202 foreach ($this->authorities as $authority) {
203 $return[] = $authority->__toArray();
204 }
205
206 return $return;
207 }
208
209
213 public function __toString()
214 {
215 return $this->getTitle();
216 }
217
218
222 public function getDependentAuthorities()
223 {
224 $dependent = ilOrgUnitAuthority::where(array(ilOrgUnitAuthority::FIELD_OVER => $this->getId()))
225 ->get();
226
227 $arr = $dependent + $this->authorities;
228
229 return (array) $arr;
230 }
231
232
237 {
238 foreach ($this->getDependentAuthorities() as $authority) {
239 $authority->delete();
240 }
241
242 $ilOrgUnitUserAssignmentQueries = ilOrgUnitUserAssignmentQueries::getInstance();
243 foreach ($ilOrgUnitUserAssignmentQueries->getUserAssignmentsOfPosition($this->getId()) as $assignment) {
244 $assignment->delete();
245 }
246 parent::delete();
247 }
248
249
253 public function getId()
254 {
255 return $this->id;
256 }
257
258
262 public function setId($id)
263 {
264 $this->id = $id;
265 }
266
267
271 public function getTitle()
272 {
273 return $this->title;
274 }
275
276
280 public function setTitle($title)
281 {
282 $this->title = $title;
283 }
284
285
289 public function getDescription()
290 {
291 return $this->description;
292 }
293
294
299 {
300 $this->description = $description;
301 }
302
303
307 public function isCorePosition()
308 {
310 }
311
312
317 {
318 $this->core_position = $core_position;
319 }
320
321
325 public function getAuthorities()
326 {
327 return $this->authorities;
328 }
329
330
335 {
336 $this->authorities = $authorities;
337 }
338
339
343 public function getCoreIdentifier()
344 {
346 }
347
348
353 {
354 $this->core_identifier = $core_identifier;
355 }
356
357
358 private function storeAuthorities()
359 {
360 $ids = [];
361 foreach ($this->getAuthorities() as $authority) {
362 $authority->setPositionId($this->getId());
363 if ($authority->getId()) {
364 $authority->update();
365 } else {
366 $authority->create();
367 }
368 $ids[] = $authority->getId();
369 }
370 if (count($ids) > 0) {
371 foreach (
373 'id' => $ids,
374 'position_id' => $this->getId(),
375 ), array('id' => 'NOT IN', 'position_id' => '='))->get() as $authority
376 ) {
377 $authority->delete();
378 }
379 }
380
381 if (count($ids) === 0) {
382 foreach (
384 'position_id' => $this->getId(),
385 ))->get() as $authority
386 ) {
387 $authority->delete();
388 }
389 }
390 }
391}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Class ActiveRecord.
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
static flush($class_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilOrgUnitPosition.
setCoreIdentifier($core_identifier)
static getActiveForPosition($orgu_ref_id)
static getCorePosition($core_identifier)
deleteWithAllDependencies()
This deletes the Position, it's Authorities, dependent Authorities and all User-Assignements!
static getCorePositionId($core_identifier)
setCorePosition($core_position)
get(string $class_name)
$data
Definition: storeScorm.php:23