ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilObjOrgUnit.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
16{
17 const TABLE_NAME = 'orgu_data';
21 protected static $root_ref_id;
25 protected static $root_id;
31 protected static $icons_cache;
37 protected $orgu_type_id = 0;
43 protected $amd_data;
44
45
50 public function __construct($a_id = 0, $a_call_by_reference = true)
51 {
52 $this->type = "orgu";
53 parent::__construct($a_id, $a_call_by_reference);
54 }
55
56
57 public function read()
58 {
59 global $DIC;
60 $ilDB = $DIC['ilDB'];
61 parent::read();
63 $sql = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE orgu_id = ' . $ilDB->quote($this->getId(), 'integer');
64 $set = $ilDB->query($sql);
65 if ($ilDB->numRows($set)) {
66 $rec = $ilDB->fetchObject($set);
67 $this->setOrgUnitTypeId($rec->orgu_type_id);
68 }
69 }
70
71
72 public function create()
73 {
74 global $DIC;
75 $ilDB = $DIC['ilDB'];
76 parent::create();
77 $ilDB->insert(self::TABLE_NAME, array(
78 'orgu_type_id' => array('integer', $this->getOrgUnitTypeId()),
79 'orgu_id' => array('integer', $this->getId()),
80 ));
81 }
82
83
84 public function update()
85 {
86 global $DIC;
87 $ilDB = $DIC['ilDB'];
88 parent::update();
89 $sql = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE orgu_id = ' . $ilDB->quote($this->getId(), 'integer');
90 $set = $ilDB->query($sql);
91 if ($ilDB->numRows($set)) {
92 $ilDB->update(self::TABLE_NAME, array(
93 'orgu_type_id' => array('integer', $this->getOrgUnitTypeId()),
94 ), array(
95 'orgu_id' => array('integer', $this->getId()),
96 ));
97 } else {
98 $ilDB->insert(self::TABLE_NAME, array(
99 'orgu_type_id' => array('integer', $this->getOrgUnitTypeId()),
100 'orgu_id' => array('integer', $this->getId()),
101 ));
102 }
103 // Update selection for advanced meta data of the type
104 if ($this->getOrgUnitTypeId()) {
105 ilAdvancedMDRecord::saveObjRecSelection($this->getId(), 'orgu_type', $this->getOrgUnitType()->getAssignedAdvancedMDRecordIds());
106 } else {
107 // If no type is assigned, delete relations by passing an empty array
108 ilAdvancedMDRecord::saveObjRecSelection($this->getId(), 'orgu_type', array());
109 }
110 }
111
112
116 public function getOrgUnitTypeId()
117 {
118 return $this->orgu_type_id;
119 }
120
121
125 public function getOrgUnitType()
126 {
128 }
129
130
134 public function setOrgUnitTypeId($a_id)
135 {
136 $this->orgu_type_id = $a_id;
137 }
138
139
150 public function getAdvancedMDValues($a_record_id = 0)
151 {
152 if (!$this->getOrgUnitTypeId()) {
153 return array();
154 }
155 // Serve from cache?
156 if (is_array($this->amd_data)) {
157 if ($a_record_id) {
158 return (isset($this->amd_data[$a_record_id])) ? $this->amd_data[$a_record_id] : array();
159 } else {
160 return $this->amd_data;
161 }
162 }
164 foreach (ilAdvancedMDValues::getInstancesForObjectId($this->getId(), 'orgu') as $record_id => $amd_values) {
165 $amd_values = new ilAdvancedMDValues($record_id, $this->getId(), 'orgu_type', $this->getOrgUnitTypeId());
166 $amd_values->read();
167 $this->amd_data[$record_id] = $amd_values->getADTGroup()->getElements();
168 }
169 if ($a_record_id) {
170 return (isset($this->amd_data[$a_record_id])) ? $this->amd_data[$a_record_id] : array();
171 } else {
172 return $this->amd_data;
173 }
174 }
175
176
184 public static function getIconsCache()
185 {
186 if (is_array(self::$icons_cache)) {
187 return self::$icons_cache;
188 }
189 global $DIC;
190 $ilDB = $DIC['ilDB'];
192 $sql = 'SELECT orgu_id, ot.id AS type_id FROM orgu_data
193 INNER JOIN orgu_types AS ot ON (ot.id = orgu_data.orgu_type_id)
194 WHERE ot.icon IS NOT NULL';
195 $set = $ilDB->query($sql);
196 $icons_cache = array();
197 while ($row = $ilDB->fetchObject($set)) {
198 $type = ilOrgUnitType::getInstance($row->type_id);
199 if ($type && is_file($type->getIconPath(true))) {
200 $icons_cache[$row->orgu_id] = $type->getIconPath(true);
201 }
202 }
203 self::$icons_cache = $icons_cache;
204
205 return $icons_cache;
206 }
207
208
212 public static function getRootOrgRefId() : int
213 {
215
216 return self::$root_ref_id;
217 }
218
219
223 public static function getRootOrgId() : int
224 {
226
227 return self::$root_id;
228 }
229
230
231 private static function loadRootOrgRefIdAndId() : void
232 {
233 if (self::$root_ref_id === null || self::$root_id === null) {
234 global $DIC;
235 $ilDB = $DIC['ilDB'];
236 $q = "SELECT o.obj_id, r.ref_id FROM object_data o
237 INNER JOIN object_reference r ON r.obj_id = o.obj_id
238 WHERE title = " . $ilDB->quote('__OrgUnitAdministration', 'text') . "";
239 $set = $ilDB->query($q);
240 $res = $ilDB->fetchAssoc($set);
241 self::$root_id = (int) $res["obj_id"];
242 self::$root_ref_id = (int) $res["ref_id"];
243 }
244 }
245
246
252 public function assignUsersToEmployeeRole($user_ids)
253 {
254 global $DIC;
255 $ilAppEventHandler = $DIC['ilAppEventHandler'];
257
258 foreach ($user_ids as $user_id) {
259 ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $this->getRefId());
260
261 $ilAppEventHandler->raise('Modules/OrgUnit', 'assignUsersToEmployeeRole', array(
262 'object' => $this,
263 'obj_id' => $this->getId(),
264 'ref_id' => $this->getRefId(),
265 'position_id' => $position_id,
266 'user_id' => $user_id,
267 ));
268 }
269 }
270
271
277 public function assignUsersToSuperiorRole($user_ids)
278 {
279 global $DIC;
280 $ilAppEventHandler = $DIC['ilAppEventHandler'];
282
283 foreach ($user_ids as $user_id) {
284 ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $this->getRefId());
285
286 $ilAppEventHandler->raise('Modules/OrgUnit', 'assignUsersToSuperiorRole', array(
287 'object' => $this,
288 'obj_id' => $this->getId(),
289 'ref_id' => $this->getRefId(),
290 'position_id' => $position_id,
291 'user_id' => $user_id,
292 ));
293 }
294 }
295
296
297 public function deassignUserFromEmployeeRole($user_id)
298 {
299 global $DIC;
301
302 $ilAppEventHandler = $DIC['ilAppEventHandler'];
303 ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $this->getRefId())->delete();
304
305 $ilAppEventHandler->raise('Modules/OrgUnit', 'deassignUserFromEmployeeRole', array(
306 'object' => $this,
307 'obj_id' => $this->getId(),
308 'ref_id' => $this->getRefId(),
309 'position_id' => $position_id,
310 'user_id' => $user_id,
311 ));
312 }
313
314
315 public function deassignUserFromSuperiorRole($user_id)
316 {
317 global $DIC;
319
320 $ilAppEventHandler = $DIC['ilAppEventHandler'];
321 ilOrgUnitUserAssignment::findOrCreateAssignment($user_id, $position_id, $this->getRefId())->delete();
322
323 $ilAppEventHandler->raise('Modules/OrgUnit', 'deassignUserFromSuperiorRole', array(
324 'object' => $this,
325 'obj_id' => $this->getId(),
326 'ref_id' => $this->getRefId(),
327 'position_id' => $position_id,
328 'user_id' => $user_id,
329 ));
330 }
331
332
341 public function assignUserToLocalRole($role_id, $user_id)
342 {
343 global $DIC;
344 $rbacreview = $DIC['rbacreview'];
345 $rbacadmin = $DIC['rbacadmin'];
346 $ilAppEventHandler = $DIC['ilAppEventHandler'];
347
348 $arrLocalRoles = $rbacreview->getLocalRoles($this->getRefId());
349 if (!in_array($role_id, $arrLocalRoles)) {
350 return false;
351 }
352
353 $return = $rbacadmin->assignUser($role_id, $user_id);
354
355 $ilAppEventHandler->raise('Modules/OrgUnit', 'assignUserToLocalRole', array(
356 'object' => $this,
357 'obj_id' => $this->getId(),
358 'ref_id' => $this->getRefId(),
359 'role_id' => $role_id,
360 'user_id' => $user_id,
361 ));
362
363 return $return;
364 }
365
366
375 public function deassignUserFromLocalRole($role_id, $user_id)
376 {
377 global $DIC;
378 $rbacreview = $DIC['rbacreview'];
379 $rbacadmin = $DIC['rbacadmin'];
380 $ilAppEventHandler = $DIC['ilAppEventHandler'];
381
382 $arrLocalRoles = $rbacreview->getLocalRoles($this->getRefId());
383 if (!in_array($role_id, $arrLocalRoles)) {
384 return false;
385 }
386
387 $return = $rbacadmin->deassignUser($role_id, $user_id);
388
389 $ilAppEventHandler->raise('Modules/OrgUnit', 'deassignUserFromLocalRole', array(
390 'object' => $this,
391 'obj_id' => $this->getId(),
392 'ref_id' => $this->getRefId(),
393 'role_id' => $role_id,
394 'user_id' => $user_id,
395 ));
396
397 return $return;
398 }
399
400
408 public static function _exists($a_id, $a_reference = false, $type = "orgu")
409 {
410 return parent::_exists($a_id, $a_reference, "orgu");
411 }
412
413
419 public function getTitle()
420 {
421 if (parent::getTitle() != "__OrgUnitAdministration") {
422 return parent::getTitle();
423 } else {
424 return $this->lng->txt("objs_orgu");
425 }
426 }
427
428
435 public function getLongDescription()
436 {
437 if (parent::getTitle() == "__OrgUnitAdministration") {
438 return $this->lng->txt("obj_orgu_description");
439 } else {
440 return parent::getLongDescription();
441 }
442 }
443
444
448 public function getTranslations()
449 {
450 global $DIC;
451 $lng = $DIC['lng'];
452 $ilDB = $DIC['ilDB'];
453
454 $q = "SELECT * FROM object_translation WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer') . " ORDER BY lang_default DESC";
455 $r = $this->db->query($q);
456
457
458 $data = [];
459 while ($row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
460 $data[$row->lang_code] = array(
461 "title" => $row->title,
462 "desc" => $row->description,
463 "lang" => $row->lang_code,
464 'default' => $row->lang_default,
465 );
466
467 }
468
469 $translations = $data;
470
471 if (!count($translations)) {
472 $this->addTranslation($this->getTitle(), "", $lng->getDefaultLanguage(), true);
473 $translations[$lng->getDefaultLanguage()] = array(
474 "title" => $this->getTitle(),
475 "desc" => "",
476 "lang" => $lng->getDefaultLanguage(),
477 );
478 }
479
480 return $translations;
481 }
482
483
490 public function delete()
491 {
492 global $DIC;
493 $ilDB = $DIC['ilDB'];
494 $ilAppEventHandler = $DIC['ilAppEventHandler'];
495
496 // always call parent delete function first!!
497 if (!parent::delete()) {
498 return false;
499 }
500
501 // put here category specific stuff
503
504 $query = "DELETE FROM object_translation WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
505 $ilDB->manipulate($query);
506
507 $ilAppEventHandler->raise('Modules/OrgUnit', 'delete', array(
508 'object' => $this,
509 'obj_id' => $this->getId(),
510 ));
511
512 $sql = 'DELETE FROM ' . self::TABLE_NAME . ' WHERE orgu_id = ' . $ilDB->quote($this->getId(), 'integer');
513 $ilDB->manipulate($sql);
514
515 $path = ilOrgUnitPathStorage::find($this->getRefId());
516 if ($path instanceof ilOrgUnitPathStorage) {
517 $path->delete();
518 }
519
520 // Delete all position assignments to this object.
521 $assignments = ilOrgUnitUserAssignment::where(array(
522 'orgu_id' => $this->getRefId(),
523 ))->get();
524 foreach ($assignments as $assignment) {
525 $assignment->delete();
526 }
527
528 return true;
529 }
530
531
535 public function removeTranslations()
536 {
537 global $DIC;
538 $ilDB = $DIC['ilDB'];
539
540 $query = "DELETE FROM object_translation WHERE obj_id= " . $ilDB->quote($this->getId(), 'integer');
541 $res = $ilDB->manipulate($query);
542 }
543
544
550 public function deleteTranslation($a_lang)
551 {
552 global $DIC;
553 $ilDB = $DIC['ilDB'];
554
555 $query = "DELETE FROM object_translation WHERE obj_id= " . $ilDB->quote($this->getId(), 'integer') . " AND lang_code = "
556 . $ilDB->quote($a_lang, 'text');
557 $res = $ilDB->manipulate($query);
558 }
559
560
571 public function addTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
572 {
573 global $DIC;
574 $ilDB = $DIC['ilDB'];
575
576 if (empty($a_title)) {
577 $a_title = "NO TITLE";
578 }
579
580 $query = "INSERT INTO object_translation " . "(obj_id,title,description,lang_code,lang_default) " . "VALUES " . "("
581 . $ilDB->quote($this->getId(), 'integer') . "," . $ilDB->quote($a_title, 'text') . "," . $ilDB->quote($a_desc, 'text') . ","
582 . $ilDB->quote($a_lang, 'text') . "," . $ilDB->quote($a_lang_default, 'integer') . ")";
583 $res = $ilDB->manipulate($query);
584
585 return true;
586 }
587
588
599 public function updateTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
600 {
601 global $DIC;
602 $ilDB = $DIC['ilDB'];
603
604 if (empty($a_title)) {
605 $a_title = "NO TITLE";
606 }
607
608 $query = "UPDATE object_translation SET ";
609
610 $query .= " title = " . $ilDB->quote($a_title, 'text');
611
612 if ($a_desc != "") {
613 $query .= ", description = " . $ilDB->quote($a_desc, 'text') . " ";
614 }
615
616
617 $query .= ", lang_default = " . $ilDB->quote($a_lang_default, 'integer') . " ";
618
619
620 $query .= " WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer') . " AND lang_code = " . $ilDB->quote($a_lang, 'text');
621 $ilDB->manipulate($query);
622
623 return true;
624 }
625
626
627 public function writePath()
628 {
629 if ($this->getRefId()) {
630 ilOrgUnitPathStorage::writePathByRefId($this->getRefId());
631 }
632 }
633}
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
static saveObjRecSelection($a_obj_id, $a_sub_type="", array $a_records=null, $a_delete_before=true)
Save repository object record selection.
static getInstancesForObjectId($a_obj_id, $a_obj_type=null, $a_sub_type="-", $a_sub_id=0)
Get instances for given object id.
Class ilContainer.
Class ilObjOrgUnit.
assignUsersToSuperiorRole($user_ids)
Adds the user ids to the position superior.
static loadRootOrgRefIdAndId()
getTitle()
Return title.
deassignUserFromSuperiorRole($user_id)
addTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
add a new translation to current OrgUnit
deassignUserFromEmployeeRole($user_id)
deassignUserFromLocalRole($role_id, $user_id)
Deassign a given user to a given local role.
__construct($a_id=0, $a_call_by_reference=true)
removeTranslations()
remove all Translations of current OrgUnit
deleteTranslation($a_lang)
remove translations of current OrgUnit
assignUserToLocalRole($role_id, $user_id)
Assign a given user to a given local role.
getLongDescription()
get object long description (stored in object_description)
static _exists($a_id, $a_reference=false, $type="orgu")
assignUsersToEmployeeRole($user_ids)
Adds the user ids to the position employee.
static getRootOrgRefId()
updateTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
update a translation to current OrgUnit
static _updateUserFolderAssignment($a_old_id, $a_new_id)
Update user folder assignment Typically called after deleting a category with local user accounts.
getRefId()
get reference id @access public
getId()
get object id @access public
Class ilOrgUnitPathStorage.
static getCorePositionId($core_identifier)
static getInstance($a_id)
Public.
static findOrCreateAssignment($user_id, $position_id, $orgu_id)
const USER_FOLDER_ID
Definition: constants.php:31
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$data
Definition: storeScorm.php:23