ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
All Data Structures Namespaces Files Functions Variables Typedefs Modules Pages
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;
26 
32  protected static $icons_cache;
38  protected $orgu_type_id = 0;
44  protected $amd_data;
45 
46 
51  public function __construct($a_id = 0, $a_call_by_reference = true)
52  {
53  $this->type = "orgu";
54  parent::__construct($a_id, $a_call_by_reference);
55  }
56 
57 
58  public function read()
59  {
60  global $DIC;
61  $ilDB = $DIC['ilDB'];
62  parent::read();
64  $sql = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE orgu_id = '
65  . $ilDB->quote($this->getId(), 'integer');
66  $set = $ilDB->query($sql);
67  if ($ilDB->numRows($set)) {
68  $rec = $ilDB->fetchObject($set);
69  $this->setOrgUnitTypeId($rec->orgu_type_id);
70  }
71  }
72 
73 
74  public function create()
75  {
76  global $DIC;
77  $ilDB = $DIC['ilDB'];
78  parent::create();
79  $ilDB->insert(self::TABLE_NAME, array(
80  'orgu_type_id' => array( 'integer', $this->getOrgUnitTypeId() ),
81  'orgu_id' => array( 'integer', $this->getId() ),
82  ));
83  }
84 
85 
86  public function update()
87  {
88  global $DIC;
89  $ilDB = $DIC['ilDB'];
91  $sql = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE orgu_id = '
92  . $ilDB->quote($this->getId(), 'integer');
93  $set = $ilDB->query($sql);
94  if ($ilDB->numRows($set)) {
95  $ilDB->update(self::TABLE_NAME, array(
96  'orgu_type_id' => array( 'integer', $this->getOrgUnitTypeId() ),
97  ), array(
98  'orgu_id' => array( 'integer', $this->getId() ),
99  ));
100  } else {
101  $ilDB->insert(self::TABLE_NAME, array(
102  'orgu_type_id' => array( 'integer', $this->getOrgUnitTypeId() ),
103  'orgu_id' => array( 'integer', $this->getId() ),
104  ));
105  }
106  // Update selection for advanced meta data of the type
107  if ($this->getOrgUnitTypeId()) {
108  ilAdvancedMDRecord::saveObjRecSelection($this->getId(), 'orgu_type', $this->getOrgUnitType()
109  ->getAssignedAdvancedMDRecordIds());
110  } else {
111  // If no type is assigned, delete relations by passing an empty array
112  ilAdvancedMDRecord::saveObjRecSelection($this->getId(), 'orgu_type', array());
113  }
114  }
115 
116 
120  public function getOrgUnitTypeId()
121  {
122  return $this->orgu_type_id;
123  }
124 
125 
129  public function getOrgUnitType()
130  {
132  }
133 
134 
138  public function setOrgUnitTypeId($a_id)
139  {
140  $this->orgu_type_id = $a_id;
141  }
142 
143 
154  public function getAdvancedMDValues($a_record_id = 0)
155  {
156  if (!$this->getOrgUnitTypeId()) {
157  return array();
158  }
159  // Serve from cache?
160  if (is_array($this->amd_data)) {
161  if ($a_record_id) {
162  return (isset($this->amd_data[$a_record_id])) ? $this->amd_data[$a_record_id] : array();
163  } else {
164  return $this->amd_data;
165  }
166  }
168  foreach (ilAdvancedMDValues::getInstancesForObjectId($this->getId(), 'orgu') as $record_id => $amd_values) {
169  $amd_values = new ilAdvancedMDValues($record_id, $this->getId(), 'orgu_type', $this->getOrgUnitTypeId());
170  $amd_values->read();
171  $this->amd_data[$record_id] = $amd_values->getADTGroup()->getElements();
172  }
173  if ($a_record_id) {
174  return (isset($this->amd_data[$a_record_id])) ? $this->amd_data[$a_record_id] : array();
175  } else {
176  return $this->amd_data;
177  }
178  }
179 
180 
188  public static function getIconsCache()
189  {
190  if (is_array(self::$icons_cache)) {
191  return self::$icons_cache;
192  }
193  global $DIC;
194  $ilDB = $DIC['ilDB'];
196  $sql = 'SELECT orgu_id, ot.id AS type_id FROM orgu_data
197  INNER JOIN orgu_types AS ot ON (ot.id = orgu_data.orgu_type_id)
198  WHERE ot.icon IS NOT NULL';
199  $set = $ilDB->query($sql);
200  $icons_cache = array();
201  while ($row = $ilDB->fetchObject($set)) {
203  if ($type && is_file($type->getIconPath(true))) {
204  $icons_cache[$row->orgu_id] = $type->getIconPath(true);
205  }
206  }
207  self::$icons_cache = $icons_cache;
208 
209  return $icons_cache;
210  }
211 
212 
216  public static function getRootOrgRefId()
217  {
218  self::loadRootOrgRefIdAndId();
219 
220  return self::$root_ref_id;
221  }
222 
223 
227  public static function getRootOrgId()
228  {
229  self::loadRootOrgRefIdAndId();
230 
231  return self::$root_id;
232  }
233 
234 
235  private static function loadRootOrgRefIdAndId()
236  {
237  if (self::$root_ref_id === null || self::$root_id === null) {
238  global $DIC;
239  $ilDB = $DIC['ilDB'];
240  $q = "SELECT o.obj_id, r.ref_id FROM object_data o
241  INNER JOIN object_reference r ON r.obj_id = o.obj_id
242  WHERE title = " . $ilDB->quote('__OrgUnitAdministration', 'text') . "";
243  $set = $ilDB->query($q);
244  $res = $ilDB->fetchAssoc($set);
245  self::$root_id = $res["obj_id"];
246  self::$root_ref_id = $res["ref_id"];
247  }
248  }
249 
255  public function assignUsersToEmployeeRole($user_ids)
256  {
257  global $DIC;
258  $ilAppEventHandler = $DIC['ilAppEventHandler'];
260 
261  foreach ($user_ids as $user_id) {
263  $user_id,
264  $position_id,
265  $this->getRefId()
266  );
267 
268  $ilAppEventHandler->raise('Modules/OrgUnit', 'assignUsersToEmployeeRole', array(
269  'object' => $this,
270  'obj_id' => $this->getId(),
271  'ref_id' => $this->getRefId(),
272  'position_id' => $position_id,
273  'user_id' => $user_id,
274  ));
275  }
276  }
277 
283  public function assignUsersToSuperiorRole($user_ids)
284  {
285  global $DIC;
286  $ilAppEventHandler = $DIC['ilAppEventHandler'];
288 
289  foreach ($user_ids as $user_id) {
291  $user_id,
292  $position_id,
293  $this->getRefId()
294  );
295 
296  $ilAppEventHandler->raise('Modules/OrgUnit', 'assignUsersToSuperiorRole', array(
297  'object' => $this,
298  'obj_id' => $this->getId(),
299  'ref_id' => $this->getRefId(),
300  'position_id' => $position_id,
301  'user_id' => $user_id,
302  ));
303  }
304  }
305 
306 
307  public function deassignUserFromEmployeeRole($user_id)
308  {
309  global $DIC;
311 
312  $ilAppEventHandler = $DIC['ilAppEventHandler'];
314  $user_id,
315  $position_id,
316  $this->getRefId()
317  )->delete();
318 
319  $ilAppEventHandler->raise('Modules/OrgUnit', 'deassignUserFromEmployeeRole', array(
320  'object' => $this,
321  'obj_id' => $this->getId(),
322  'ref_id' => $this->getRefId(),
323  'position_id' => $position_id,
324  'user_id' => $user_id,
325  ));
326  }
327 
328 
329  public function deassignUserFromSuperiorRole($user_id)
330  {
331  global $DIC;
333 
334  $ilAppEventHandler = $DIC['ilAppEventHandler'];
336  $user_id,
337  $position_id,
338  $this->getRefId()
339  )->delete();
340 
341  $ilAppEventHandler->raise('Modules/OrgUnit', 'deassignUserFromSuperiorRole', array(
342  'object' => $this,
343  'obj_id' => $this->getId(),
344  'ref_id' => $this->getRefId(),
345  'position_id' => $position_id,
346  'user_id' => $user_id,
347  ));
348  }
349 
350 
358  public function assignUserToLocalRole($role_id, $user_id)
359  {
360  global $DIC;
361  $rbacreview = $DIC['rbacreview'];
362  $rbacadmin = $DIC['rbacadmin'];
363  $ilAppEventHandler = $DIC['ilAppEventHandler'];
364 
365  $arrLocalRoles = $rbacreview->getLocalRoles($this->getRefId());
366  if (!in_array($role_id, $arrLocalRoles)) {
367  return false;
368  }
369 
370  $return = $rbacadmin->assignUser($role_id, $user_id);
371 
372  $ilAppEventHandler->raise('Modules/OrgUnit', 'assignUserToLocalRole', array(
373  'object' => $this,
374  'obj_id' => $this->getId(),
375  'ref_id' => $this->getRefId(),
376  'role_id' => $role_id,
377  'user_id' => $user_id,
378  ));
379 
380  return $return;
381  }
382 
383 
391  public function deassignUserFromLocalRole($role_id, $user_id)
392  {
393  global $DIC;
394  $rbacreview = $DIC['rbacreview'];
395  $rbacadmin = $DIC['rbacadmin'];
396  $ilAppEventHandler = $DIC['ilAppEventHandler'];
397 
398  $arrLocalRoles = $rbacreview->getLocalRoles($this->getRefId());
399  if (!in_array($role_id, $arrLocalRoles)) {
400  return false;
401  }
402 
403  $return = $rbacadmin->deassignUser($role_id, $user_id);
404 
405  $ilAppEventHandler->raise('Modules/OrgUnit', 'deassignUserFromLocalRole', array(
406  'object' => $this,
407  'obj_id' => $this->getId(),
408  'ref_id' => $this->getRefId(),
409  'role_id' => $role_id,
410  'user_id' => $user_id,
411  ));
412 
413  return $return;
414  }
415 
422  public static function _exists($a_id, $a_reference = false, $type = "orgu")
423  {
424  return parent::_exists($a_id, $a_reference, "orgu");
425  }
426 
432  public function getTitle()
433  {
434  if (parent::getTitle() != "__OrgUnitAdministration") {
435  return parent::getTitle();
436  } else {
437  return $this->lng->txt("objs_orgu");
438  }
439  }
440 
441 
448  public function getLongDescription()
449  {
450  if (parent::getTitle() == "__OrgUnitAdministration") {
451  return $this->lng->txt("obj_orgu_description");
452  } else {
453  return parent::getLongDescription();
454  }
455  }
456 
457 
461  public function getTranslations()
462  {
463  global $DIC;
464  $lng = $DIC['lng'];
465  $ilDB = $DIC['ilDB'];
466 
467  $q = "SELECT * FROM object_translation WHERE obj_id = "
468  . $ilDB->quote($this->getId(), 'integer') . " ORDER BY lang_default DESC";
469  $r = $this->db->query($q);
470 
471  $num = 0;
472  $data = ["Fobject" => []];
473  while ($row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
474  $data["Fobject"][$num] = array(
475  "title" => $row->title,
476  "desc" => $row->description,
477  "lang" => $row->lang_code,
478  'lang_default' => $row->lang_default,
479  );
480  $num++;
481  }
482 
483  $translations = $data;
484 
485  if (!count($translations["Fobject"])) {
486  $this->addTranslation($this->getTitle(), "", $lng->getDefaultLanguage(), true);
487  $translations["Fobject"][] = array(
488  "title" => $this->getTitle(),
489  "desc" => "",
490  "lang" => $lng->getDefaultLanguage(),
491  );
492  }
493 
494  return $translations;
495  }
496 
497 
505  public function delete()
506  {
507  global $DIC;
508  $ilDB = $DIC['ilDB'];
509  $ilAppEventHandler = $DIC['ilAppEventHandler'];
510 
511  // always call parent delete function first!!
512  if (!parent::delete()) {
513  return false;
514  }
515 
516  // put here category specific stuff
518 
519  $query = "DELETE FROM object_translation WHERE obj_id = "
520  . $ilDB->quote($this->getId(), 'integer');
521  $ilDB->manipulate($query);
522 
523  $ilAppEventHandler->raise('Modules/OrgUnit', 'delete', array(
524  'object' => $this,
525  'obj_id' => $this->getId(),
526  ));
527 
528  $sql = 'DELETE FROM ' . self::TABLE_NAME . ' WHERE orgu_id = '
529  . $ilDB->quote($this->getId(), 'integer');
530  $ilDB->manipulate($sql);
531 
532  $path = ilOrgUnitPathStorage::find($this->getRefId());
533  if ($path instanceof ilOrgUnitPathStorage) {
534  $path->delete();
535  }
536 
537  // Delete all position assignments to this object.
538  $assignments = ilOrgUnitUserAssignment::where(array(
539  'orgu_id' => $this->getRefId(),
540  ))->get();
541  foreach ($assignments as $assignment) {
542  $assignment->delete();
543  }
544 
545  return true;
546  }
547 
548 
552  public function removeTranslations()
553  {
554  global $DIC;
555  $ilDB = $DIC['ilDB'];
556 
557  $query = "DELETE FROM object_translation WHERE obj_id= "
558  . $ilDB->quote($this->getId(), 'integer');
559  $res = $ilDB->manipulate($query);
560  }
561 
562 
568  public function deleteTranslation($a_lang)
569  {
570  global $DIC;
571  $ilDB = $DIC['ilDB'];
572 
573  $query = "DELETE FROM object_translation WHERE obj_id= "
574  . $ilDB->quote($this->getId(), 'integer') . " AND lang_code = "
575  . $ilDB->quote($a_lang, 'text');
576  $res = $ilDB->manipulate($query);
577  }
578 
579 
589  public function addTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
590  {
591  global $DIC;
592  $ilDB = $DIC['ilDB'];
593 
594  if (empty($a_title)) {
595  $a_title = "NO TITLE";
596  }
597 
598  $query = "INSERT INTO object_translation "
599  . "(obj_id,title,description,lang_code,lang_default) " . "VALUES " . "("
600  . $ilDB->quote($this->getId(), 'integer') . "," . $ilDB->quote($a_title, 'text')
601  . "," . $ilDB->quote($a_desc, 'text') . "," . $ilDB->quote($a_lang, 'text') . ","
602  . $ilDB->quote($a_lang_default, 'integer') . ")";
603  $res = $ilDB->manipulate($query);
604 
605  return true;
606  }
607 
608 
618  public function updateTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
619  {
620  global $DIC;
621  $ilDB = $DIC['ilDB'];
622 
623  if (empty($a_title)) {
624  $a_title = "NO TITLE";
625  }
626 
627  $query = "UPDATE object_translation SET ";
628 
629  $query .= " title = " . $ilDB->quote($a_title, 'text');
630 
631  if ($a_desc != "") {
632  $query .= ", description = " . $ilDB->quote($a_desc, 'text') . " ";
633  }
634 
635  if ($a_lang_default) {
636  $query .= ", lang_default = " . $ilDB->quote($a_lang_default, 'integer') . " ";
637  }
638 
639  $query .= " WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer') . " AND lang_code = "
640  . $ilDB->quote($a_lang, 'text');
641  $ilDB->manipulate($query);
642 
643  return true;
644  }
645 
646 
647  public function writePath()
648  {
649  if ($this->getRefId()) {
650  ilOrgUnitPathStorage::writePathByRefId($this->getRefId());
651  }
652  }
653 }
static _updateUserFolderAssignment($a_old_id, $a_new_id)
Update user folder assignment Typically called after deleting a category with local user accounts...
static getInstancesForObjectId($a_obj_id, $a_obj_type=null, $a_sub_type="-", $a_sub_id=0)
Get instances for given object id.
removeTranslations()
remove all Translations of current OrgUnit
__construct($a_id=0, $a_call_by_reference=true)
global $DIC
Definition: saml.php:7
static findOrCreateAssignment($user_id, $position_id, $orgu_id)
deassignUserFromSuperiorRole($user_id)
assignUsersToSuperiorRole($user_ids)
Adds the user ids to the position superior.
static getCorePositionId($core_identifier)
static _exists($a_id, $a_reference=false, $type="orgu")
Class ilOrgUnitPathStorage.
assignUsersToEmployeeRole($user_ids)
Adds the user ids to the position employee.
updateTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
update a translation to current OrgUnit
deassignUserFromLocalRole($role_id, $user_id)
Deassign a given user to a given local role.
static where($where, $operator=null)
static saveObjRecSelection($a_obj_id, $a_sub_type="", array $a_records=null, $a_delete_before=true)
Save repository object record selection.
static loadRootOrgRefIdAndId()
$r
Definition: example_031.php:79
foreach($_POST as $key=> $value) $res
addTranslation($a_title, $a_desc, $a_lang, $a_lang_default)
add a new translation to current OrgUnit
getId()
get object id public
deleteTranslation($a_lang)
remove translations of current OrgUnit
getTitle()
Return title.
getLongDescription()
get object long description (stored in object_description)
Class ilObjOrgUnit.
static getInstance($a_id)
Public.
Class ilContainer.
assignUserToLocalRole($role_id, $user_id)
Assign a given user to a given local role.
$query
deassignUserFromEmployeeRole($user_id)
Create styles array
The data for the language used.
static getRootOrgRefId()
update($pash, $contents, Config $config)
global $ilDB
getRefId()
get reference id public
const USER_FOLDER_ID
Class ilObjUserFolder.