ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  {
54  return self::getCorePosition($core_identifier)->getId();
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  {
183  parent::update();
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  {
224  ->get();
225 
226  $arr = $dependent + $this->authorities;
227 
228  return (array) $arr;
229  }
230 
231 
235  public function deleteWithAllDependencies()
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 
297  public function setDescription($description)
298  {
299  $this->description = $description;
300  }
301 
302 
306  public function isCorePosition()
307  {
308  return $this->core_position;
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 
333  public function setAuthorities($authorities)
334  {
335  $this->authorities = $authorities;
336  }
337 
338 
342  public function getCoreIdentifier()
343  {
344  return $this->core_identifier;
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) {
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) {
380  'position_id' => $this->getId(),
381  ))->get() as $authority) {
382  $authority->delete();
383  }
384  }
385  }
386 }
Class ActiveRecord.
static getCorePositionId($core_identifier)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static getCorePosition($core_identifier)
static where($where, $operator=null)
deleteWithAllDependencies()
This deletes the Position, it&#39;s Authorities, dependent Authorities and all User-Assignements! ...
setCoreIdentifier($core_identifier)
static getActiveForPosition($orgu_ref_id)
Create styles array
The data for the language used.
static flush($class_name)
update($pash, $contents, Config $config)
setCorePosition($core_position)
Class ilOrgUnitPosition.
$authority