3 require_once
"./Services/Container/classes/class.ilContainer.php";
4 require_once(
"./Modules/OrgUnit/classes/class.ilOrgUnitImporter.php");
5 require_once(
'./Modules/OrgUnit/classes/Types/class.ilOrgUnitType.php');
6 require_once(
'./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
7 require_once(
'./Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php');
51 public function __construct($a_id = 0, $a_call_by_reference =
true) {
57 public function read() {
61 $sql =
'SELECT * FROM ' . self::TABLE_NAME .
' WHERE orgu_id = ' . $ilDB->quote($this->
getId(),
'integer');
62 $set = $ilDB->query($sql);
63 if ($ilDB->numRows($set)) {
64 $rec = $ilDB->fetchObject($set);
73 $ilDB->insert(self::TABLE_NAME, array(
75 'orgu_id' => array(
'integer', $this->
getId() ),
83 $sql =
'SELECT * FROM ' . self::TABLE_NAME .
' WHERE orgu_id = ' . $ilDB->quote($this->
getId(),
'integer');
84 $set = $ilDB->query($sql);
85 if ($ilDB->numRows($set)) {
86 $ilDB->update(self::TABLE_NAME, array(
89 'orgu_id' => array(
'integer', $this->
getId() ),
92 $ilDB->insert(self::TABLE_NAME, array(
94 'orgu_id' => array(
'integer', $this->
getId() ),
127 $this->orgu_type_id = $a_id;
140 public function getAdvancedMDValues($a_record_id = 0) {
145 if (is_array($this->amd_data)) {
147 return (isset($this->amd_data[$a_record_id])) ? $this->amd_data[$a_record_id] : array();
156 $this->amd_data[$record_id] = $amd_values->getADTGroup()->getElements();
159 return (isset($this->amd_data[$a_record_id])) ? $this->amd_data[$a_record_id] : array();
173 public static function getIconsCache() {
174 if (is_array(self::$icons_cache)) {
179 $sql =
'SELECT orgu_id, ot.id AS type_id FROM orgu_data
180 INNER JOIN orgu_types AS ot ON (ot.id = orgu_data.orgu_type_id)
181 WHERE ot.icon IS NOT NULL';
182 $set = $ilDB->query($sql);
184 while (
$row = $ilDB->fetchObject($set)) {
186 if (
$type && is_file(
$type->getIconPath(
true))) {
211 if (self::$root_ref_id === NULL || self::$root_id === NULL) {
213 $q =
"SELECT o.obj_id, r.ref_id FROM object_data o
214 INNER JOIN object_reference r ON r.obj_id = o.obj_id
215 WHERE title = " . $ilDB->quote(
'__OrgUnitAdministration',
'text') .
"";
216 $set = $ilDB->query($q);
217 $res = $ilDB->fetchAssoc($set);
218 self::$root_id =
$res[
"obj_id"];
219 self::$root_ref_id =
$res[
"ref_id"];
226 if (!$this->employee_role || !$this->superior_role) {
230 if (!$this->employee_role || !$this->superior_role) {
233 if (!$this->employee_role || !$this->superior_role) {
234 throw new Exception(
"The standard roles the orgu object with id: " . $this->
getId()
235 .
" aren't initialized or have been deleted, newly creating them didn't work!");
237 $ilLog->write(
"[" . __FILE__ .
":" . __LINE__ .
"] The standard roles for the orgu obj with id: " . $this->
getId()
238 .
" were newly created as they couldnt be found.");
246 if (!$this->employee_role || !$this->superior_role) {
247 $q =
"SELECT obj_id, title FROM object_data WHERE title LIKE 'il_orgu_employee_" . $ilDB->quote($this->
getRefId(),
"integer")
248 .
"' OR title LIKE 'il_orgu_superior_" . $ilDB->quote($this->
getRefId(),
"integer") .
"'";
249 $set = $ilDB->query($q);
250 while (
$res = $ilDB->fetchAssoc($set)) {
251 if (
$res[
"title"] ==
"il_orgu_employee_" . $this->
getRefId()) {
252 $this->employee_role =
$res[
"obj_id"];
253 } elseif (
$res[
"title"] ==
"il_orgu_superior_" . $this->
getRefId()) {
254 $this->superior_role =
$res[
"obj_id"];
258 if (!$this->employee_role || !$this->superior_role) {
259 throw new Exception(
"The standard roles the orgu object with id: " . $this->
getId() .
" aren't initialized or have been deleted!");
266 global $rbacadmin, $ilAppEventHandler;
267 foreach ($user_ids as $user_id) {
270 $ilAppEventHandler->raise(
'Modules/OrgUnit',
'assignUsersToEmployeeRole', array(
272 'obj_id' => $this->
getId(),
275 'user_id' => $user_id
282 global $rbacadmin, $ilAppEventHandler;
283 foreach ($user_ids as $user_id) {
286 $ilAppEventHandler->raise(
'Modules/OrgUnit',
'assignUsersToSuperiorRole', array(
288 'obj_id' => $this->
getId(),
291 'user_id' => $user_id
298 global $rbacadmin, $ilAppEventHandler;
301 $ilAppEventHandler->raise(
'Modules/OrgUnit',
'deassignUserFromEmployeeRole', array(
303 'obj_id' => $this->
getId(),
306 'user_id' => $user_id
312 global $rbacadmin, $ilAppEventHandler;
315 $ilAppEventHandler->raise(
'Modules/OrgUnit',
'deassignUserFromSuperiorRole', array(
317 'obj_id' => $this->
getId(),
320 'user_id' => $user_id
334 global $rbacreview, $rbacadmin, $ilAppEventHandler;
336 $arrLocalRoles = $rbacreview->getLocalRoles($this->
getRefId());
337 if ( ! in_array($role_id, $arrLocalRoles)) {
341 $return = $rbacadmin->assignUser($role_id, $user_id);
343 $ilAppEventHandler->raise(
'Modules/OrgUnit',
344 'assignUserToLocalRole',
345 array(
'object' => $this,
346 'obj_id' => $this->
getId(),
348 'role_id' => $role_id,
349 'user_id' => $user_id));
364 global $rbacreview, $rbacadmin, $ilAppEventHandler;
366 $arrLocalRoles = $rbacreview->getLocalRoles($this->
getRefId());
367 if ( ! in_array($role_id, $arrLocalRoles)) {
371 $return = $rbacadmin->deassignUser($role_id, $user_id);
373 $ilAppEventHandler->raise(
'Modules/OrgUnit',
374 'deassignUserFromLocalRole',
375 array(
'object' => $this,
376 'obj_id' => $this->
getId(),
378 'role_id' => $role_id,
379 'user_id' => $user_id));
392 public static function _exists($a_id, $a_reference =
false) {
426 global $rbacadmin, $rbacreview, $ilAppEventHandler;
427 include_once
'./Services/AccessControl/classes/class.ilObjRole.php';
429 $role->setTitle(
"il_orgu_employee_" . $this->
getRefId());
430 $role->setDescription(
"Emplyee of org unit obj_no." . $this->
getId());
433 $GLOBALS[
'rbacadmin']->assignRoleToFolder($role->getId(), $this->
getRefId(),
'y');
435 include_once
'./Services/AccessControl/classes/class.ilObjRole.php';
439 $ilAppEventHandler->raise(
'Modules/OrgUnit',
'initDefaultRoles', array(
441 'obj_id' => $this->
getId(),
443 'role_superior_id' => $role->getId(),
444 'role_employee_id' => $role_sup->getId()
454 if (parent::getTitle() !=
"__OrgUnitAdministration") {
457 return $this->lng->txt(
"objs_orgu");
469 if (parent::getTitle() ==
"__OrgUnitAdministration") {
470 return $this->lng->txt(
"obj_orgu_description");
483 $translations = array();
485 $q =
"SELECT * FROM object_translation WHERE obj_id = " . $ilDB->quote($this->
getId(),
'integer') .
" ORDER BY lang_default DESC";
486 $r = $this->ilias->db->query($q);
491 $data[
"Fobject"][$num] = array(
492 "title" =>
$row->title,
493 "desc" =>
$row->description,
494 "lang" =>
$row->lang_code,
495 'lang_default' =>
$row->lang_default,
500 $translations = $data;
502 if (!count($translations[
"Fobject"])) {
504 $translations[
"Fobject"][] = array(
507 "lang" => $lng->getDefaultLanguage()
511 return $translations;
522 global
$ilDB, $ilAppEventHandler;
525 if (!parent::delete()) {
530 include_once(
'./Services/User/classes/class.ilObjUserFolder.php');
533 $query =
"DELETE FROM object_translation WHERE obj_id = " . $ilDB->quote($this->
getId(),
'integer');
536 $ilAppEventHandler->raise(
'Modules/OrgUnit',
'delete', array(
538 'obj_id' => $this->
getId()
541 $sql =
'DELETE FROM ' . self::TABLE_NAME .
' WHERE orgu_id = ' . $ilDB->quote($this->
getId(),
'integer');
542 $ilDB->manipulate($sql);
552 $query =
"DELETE FROM object_translation WHERE obj_id= " . $ilDB->quote($this->
getId(),
'integer');
561 $query =
"DELETE FROM object_translation WHERE obj_id= " . $ilDB->quote($this->
getId(),
'integer') .
" AND lang_code = "
562 . $ilDB->quote($a_lang,
'text');
571 if (empty($a_title)) {
572 $a_title =
"NO TITLE";
575 $query =
"INSERT INTO object_translation " .
"(obj_id,title,description,lang_code,lang_default) " .
"VALUES " .
"("
576 . $ilDB->quote($this->
getId(),
'integer') .
"," . $ilDB->quote($a_title,
'text') .
"," . $ilDB->quote($a_desc,
'text') .
","
577 . $ilDB->quote($a_lang,
'text') .
"," . $ilDB->quote($a_lang_default,
'integer') .
")";
588 if (empty($a_title)) {
589 $a_title =
"NO TITLE";
592 $query =
"UPDATE object_translation SET ";
594 $query .=
" title = " . $ilDB->quote($a_title,
'text');
597 $query .=
", description = " . $ilDB->quote($a_desc,
'text') .
" ";
600 if ($a_lang_default) {
601 $query .=
", lang_default = " . $ilDB->quote($a_lang_default,
'integer') .
" ";
604 $query .=
" WHERE obj_id = " . $ilDB->quote($this->
getId(),
'integer') .
" AND lang_code = " . $ilDB->quote($a_lang,
'text');