ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
60 public function delete()
61 {
62 if ($this->isCorePosition()) {
63 throw new ilException('Cannot delete Core-Position');
64 }
65 parent::delete();
66 }
67
68
73 public static function getActive()
74 {
75 arObjectCache::flush(self::class);
76 $q = "SELECT DISTINCT il_orgu_positions.id, il_orgu_positions.*
77 FROM il_orgu_positions
78 LEFT JOIN il_orgu_ua ON il_orgu_positions.id = il_orgu_ua.position_id
79 WHERE il_orgu_ua.user_id IS NOT NULL
80 OR il_orgu_positions.core_position = 1";
81 $database = $GLOBALS['DIC']->database();
82 $st = $database->query($q);
83
84 $positions = array();
85
86 while ($data = $database->fetchAssoc($st)) {
87 $position = new self();
88 $position->buildFromArray($data);
89 $positions[] = $position;
90 }
91
92 return $positions;
93 }
94
95
102 public static function getActiveForPosition($orgu_ref_id)
103 {
104 arObjectCache::flush(self::class);
105 $q = "SELECT DISTINCT il_orgu_positions.id, il_orgu_positions.*
106 FROM il_orgu_positions
107 LEFT JOIN il_orgu_ua ON il_orgu_positions.id = il_orgu_ua.position_id AND il_orgu_ua.orgu_id = %s
108 WHERE il_orgu_ua.user_id IS NOT NULL
109 OR core_position = 1";
110 $database = $GLOBALS['DIC']->database();
111 $st = $database->queryF($q, array( 'integer' ), array( $orgu_ref_id ));
112
113 $positions = array();
114
115 while ($data = $database->fetchAssoc($st)) {
116 $position = new self();
117 $position->buildFromArray($data);
118 $positions[] = $position;
119 }
120
121 return $positions;
122 }
123
124
135 protected $id = 0;
143 protected $title = "";
151 protected $description = "";
159 protected $core_position = false;
167 protected $core_identifier = 0;
171 protected $authorities = array();
172
173
174 public function afterObjectLoad()
175 {
176 $this->authorities = ilOrgUnitAuthority::where(array( ilOrgUnitAuthority::POSITION_ID => $this->getId() ))
177 ->get();
178 }
179
180
181 public function update()
182 {
184 $this->storeAuthorities();
185 }
186
187
188 public function create()
189 {
190 parent::create();
191 $this->storeAuthorities();
192 }
193
194
198 public function getAuthoritiesAsArray()
199 {
200 $return = array();
201 foreach ($this->authorities as $authority) {
202 $return[] = $authority->__toArray();
203 }
204
205 return $return;
206 }
207
208
212 public function __toString()
213 {
214 return $this->getTitle();
215 }
216
217
221 public function getDependentAuthorities()
222 {
223 $dependent = ilOrgUnitAuthority::where(array( ilOrgUnitAuthority::FIELD_OVER => $this->getId() ))
224 ->get();
225
226 $arr = $dependent + $this->authorities;
227
228 return (array) $arr;
229 }
230
231
236 {
237 foreach ($this->getDependentAuthorities() as $authority) {
238 $authority->delete();
239 }
240
241 $ilOrgUnitUserAssignmentQueries = ilOrgUnitUserAssignmentQueries::getInstance();
242 foreach ($ilOrgUnitUserAssignmentQueries->getUserAssignmentsOfPosition($this->getId()) as $assignment) {
243 $assignment->delete();
244 }
245 parent::delete();
246 }
247
248
252 public function getId()
253 {
254 return $this->id;
255 }
256
257
261 public function setId($id)
262 {
263 $this->id = $id;
264 }
265
266
270 public function getTitle()
271 {
272 return $this->title;
273 }
274
275
279 public function setTitle($title)
280 {
281 $this->title = $title;
282 }
283
284
288 public function getDescription()
289 {
290 return $this->description;
291 }
292
293
298 {
299 $this->description = $description;
300 }
301
302
306 public function isCorePosition()
307 {
309 }
310
311
316 {
317 $this->core_position = $core_position;
318 }
319
320
324 public function getAuthorities()
325 {
326 return $this->authorities;
327 }
328
329
334 {
335 $this->authorities = $authorities;
336 }
337
338
342 public function getCoreIdentifier()
343 {
345 }
346
347
352 {
353 $this->core_identifier = $core_identifier;
354 }
355
356
357 private function storeAuthorities()
358 {
359 $ids = [];
360 foreach ($this->getAuthorities() as $authority) {
361 $authority->setPositionId($this->getId());
362 if ($authority->getId()) {
363 $authority->update();
364 } else {
365 $authority->create();
366 }
367 $ids[] = $authority->getId();
368 }
369 if (count($ids) > 0) {
370 foreach (ilOrgUnitAuthority::where(array(
371 'id' => $ids,
372 'position_id' => $this->getId(),
373 ), array( 'id' => 'NOT IN', 'position_id' => '=' ))->get() as $authority) {
374 $authority->delete();
375 }
376 }
377
378 if (count($ids) === 0) {
379 foreach (ilOrgUnitAuthority::where(array(
380 'position_id' => $this->getId(),
381 ))->get() as $authority) {
382 $authority->delete();
383 }
384 }
385 }
386}
Class ActiveRecord.
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
static flush($class_name)
Base class for ILIAS Exception handling.
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)
$authority
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
get(string $class_name)
update($pash, $contents, Config $config)
$data
Definition: bench.php:6