ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilObject.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
14{
18 protected $objDefinition;
19
23 protected $db;
24
28 protected $log;
29
33 protected $error;
34
38 protected $tree;
39
44
48 protected $rbacadmin;
49
53 protected $rbacreview;
54
58 const TITLE_LENGTH = 255; // title column max length in db
59 const DESC_LENGTH = 128; // (short) description column max length in db
60
61
67 public $lng;
68
74 public $id; // true object_id!!!!
75 public $ref_id;// reference_id
76 public $type;
77 public $title;
78 // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
80 // END WebDAV: WebDAV needs to access the untranslated title of an object
81 public $desc;
82 public $long_desc;
83 public $owner;
86 public $import_id;
87 public $register = false; // registering required for object? set to true to implement a subscription interface
88
95
102
108
113 public $max_desc;
114
119 public $add_dots;
120
121
128 public function __construct($a_id = 0, $a_reference = true)
129 {
130 global $DIC;
131
132
133 $this->ilias = $DIC["ilias"];
134
135 $this->db = $DIC->database();
136 $this->log = $DIC["ilLog"];
137 $this->error = $DIC["ilErr"];
138 $this->tree = $DIC->repositoryTree();
139 $this->app_event_handler = $DIC["ilAppEventHandler"];
140 $objDefinition = $DIC["objDefinition"];
141
142 if (DEBUG) {
143 echo "<br/><font color=\"red\">type(" . $this->type . ") id(" . $a_id . ") referenced(" . $a_reference . ")</font>";
144 }
145
146 if (isset($DIC["lng"])) {
147 $this->lng = $DIC["lng"];
148 }
149 $this->objDefinition = $objDefinition;
150
151 $this->max_title = self::TITLE_LENGTH;
152 $this->max_desc = self::DESC_LENGTH;
153 $this->add_dots = true;
154
155 $this->referenced = $a_reference;
156 $this->call_by_reference = $a_reference;
157
158 if ($a_id == 0) {
159 $this->referenced = false; // newly created objects are never referenced
160 } // they will get referenced if createReference() is called
161
162 if ($this->referenced) {
163 $this->ref_id = $a_id;
164 } else {
165 $this->id = $a_id;
166 }
167 // read object data
168 if ($a_id != 0) {
169 $this->read();
170 }
171 }
172
176 public function withReferences()
177 {
178 // both vars could differ. this method should always return true if one of them is true without changing their status
179 return ($this->call_by_reference) ? true : $this->referenced;
180 }
181
182
188 public function read()
189 {
190 global $DIC;
191
196 try {
197 $ilUser = $DIC["ilUser"];
198 } catch (\InvalidArgumentException $e) {
199 }
200
201 if ($this->referenced) {
202 // check reference id
203 if (!isset($this->ref_id)) {
204 $message = "ilObject::read(): No ref_id given! (" . $this->type . ")";
205 $ilErr->raiseError($message, $ilErr->WARNING);
206 }
207
208 // read object data
209
210 $q = "SELECT * FROM object_data, object_reference WHERE object_data.obj_id=object_reference.obj_id " .
211 "AND object_reference.ref_id= " . $ilDB->quote($this->ref_id, "integer");
212 $object_set = $ilDB->query($q);
213
214 // check number of records
215 if ($ilDB->numRows($object_set) == 0) {
216 $message = "ilObject::read(): Object with ref_id " . $this->ref_id . " not found! (" . $this->type . ")";
217 $ilErr->raiseError($message, $ilErr->WARNING);
218 }
219
220 $obj = $ilDB->fetchAssoc($object_set);
221 } else {
222 // check object id
223 if (!isset($this->id)) {
224 $message = "ilObject::read(): No obj_id given! (" . $this->type . ")";
225 $ilErr->raiseError($message, $ilErr->WARNING);
226 }
227
228 // read object data
229 $q = "SELECT * FROM object_data " .
230 "WHERE obj_id = " . $ilDB->quote($this->id, "integer");
231 $object_set = $ilDB->query($q);
232
233 // check number of records
234 if ($ilDB->numRows($object_set) == 0) {
235 include_once("./Services/Object/exceptions/class.ilObjectNotFoundException.php");
236 throw new ilObjectNotFoundException("ilObject::read(): Object with obj_id: " . $this->id .
237 " (" . $this->type . ") not found!");
238 return;
239 }
240
241 $obj = $ilDB->fetchAssoc($object_set);
242 }
243
244 $this->id = $obj["obj_id"];
245
246 // check type match (the "xxx" type is used for the unit test)
247 if ($this->type != $obj["type"] && $obj["type"] != "xxx") {
248 $message = "ilObject::read(): Type mismatch. Object with obj_id: " . $this->id . " " .
249 "was instantiated by type '" . $this->type . "'. DB type is: " . $obj["type"];
250
251 // write log entry
252 $ilLog->write($message);
253
254 // raise error
255 include_once("./Services/Object/exceptions/class.ilObjectTypeMismatchException.php");
257 return;
258 }
259
260 $this->type = $obj["type"];
261 $this->title = $obj["title"];
262 // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
263 $this->untranslatedTitle = $obj["title"];
264 // END WebDAV: WebDAV needs to access the untranslated title of an object
265 $this->desc = $obj["description"];
266 $this->owner = $obj["owner"];
267 $this->create_date = $obj["create_date"];
268 $this->last_update = $obj["last_update"];
269 $this->import_id = $obj["import_id"];
270
271 if ($objDefinition->isRBACObject($this->getType())) {
272 // Read long description
273 $query = "SELECT * FROM object_description WHERE obj_id = " . $ilDB->quote($this->id, 'integer');
274 $res = $ilDB->query($query);
275 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
276 if (strlen($row->description)) {
277 $this->setDescription($row->description);
278 }
279 }
280 }
281
282 // multilingual support systemobjects (sys) & categories (db)
283 $translation_type = $objDefinition->getTranslationType($this->type);
284
285 if ($translation_type == "sys") {
286 $this->title = $this->lng->txt("obj_" . $this->type);
287 $this->setDescription($this->lng->txt("obj_" . $this->type . "_desc"));
288 } elseif ($translation_type == "db") {
289 $q = "SELECT title,description FROM object_translation " .
290 "WHERE obj_id = " . $ilDB->quote($this->id, 'integer') . " " .
291 "AND lang_code = " . $ilDB->quote($ilUser->getCurrentLanguage(), 'text') . " " .
292 "AND NOT lang_default = 1";
293 $r = $ilDB->query($q);
295 if ($row) {
296 $this->title = $row->title;
297 $this->setDescription($row->description);
298 #$this->desc = $row->description;
299 }
300 }
301 }
302
308 public function getId()
309 {
310 return $this->id;
311 }
312
318 public function setId($a_id)
319 {
320 $this->id = $a_id;
321 }
322
328 public function setRefId($a_id)
329 {
330 $this->ref_id = $a_id;
331 $this->referenced = true;
332 }
333
339 public function getRefId()
340 {
341 return $this->ref_id;
342 }
343
349 public function getType()
350 {
351 return $this->type;
352 }
353
359 public function setType($a_type)
360 {
361 $this->type = $a_type;
362 }
363
373 public function getPresentationTitle()
374 {
375 return $this->getTitle();
376 }
377
378
384 public function getTitle()
385 {
386 return $this->title;
387 }
388 // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
394 public function getUntranslatedTitle()
395 {
397 }
398 // END WebDAV: WebDAV needs to access the untranslated title of an object
399
406 public function setTitle($a_title)
407 {
408 $this->title = ilUtil::shortenText($a_title, $this->max_title, $this->add_dots);
409 // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
410 $this->untranslatedTitle = $this->title;
411 // END WebDAV: WebDAV needs to access the untranslated title of an object
412 }
413
420 public function getDescription()
421 {
422 return $this->desc;
423 }
424
431 public function setDescription($a_desc)
432 {
433 // Shortened form is storted in object_data. Long form is stored in object_description
434 $this->desc = ilUtil::shortenText($a_desc, $this->max_desc, $this->add_dots);
435
436 $this->long_desc = $a_desc;
437
438 return true;
439 }
440
447 public function getLongDescription()
448 {
449 return strlen($this->long_desc) ? $this->long_desc : $this->desc;
450 }
451
458 public function getImportId()
459 {
460 return $this->import_id;
461 }
462
469 public function setImportId($a_import_id)
470 {
471 $this->import_id = $a_import_id;
472 }
473
474 public static function _lookupObjIdByImportId($a_import_id)
475 {
476 global $DIC;
477
478 $ilDB = $DIC->database();
479
480 $query = "SELECT * FROM object_data " .
481 "WHERE import_id = " . $ilDB->quote($a_import_id, "text") . " " .
482 "ORDER BY create_date DESC";
483 $res = $ilDB->query($query);
484 while ($row = $ilDB->fetchObject($res)) {
485 return $row->obj_id;
486 }
487 return 0;
488 }
489
490 public static function _lookupImportId($a_obj_id)
491 {
492 global $DIC;
493
494 $ilDB = $DIC->database();
495
496 $query = "SELECT import_id FROM object_data " .
497 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
498 $res = $ilDB->query($query);
499 $row = $ilDB->fetchObject($res);
500 return $row->import_id;
501 }
502
509 public function getOwner()
510 {
511 return $this->owner;
512 }
513
514 /*
515 * get full name of object owner
516 *
517 * @access public
518 * @return string owner name or unknown
519 */
520 public function getOwnerName()
521 {
522 return ilObject::_lookupOwnerName($this->getOwner());
523 }
524
528 public static function _lookupOwnerName($a_owner_id)
529 {
530 global $DIC;
531
532 $lng = $DIC->language();
533
534 if ($a_owner_id != -1) {
535 if (ilObject::_exists($a_owner_id)) {
536 $owner = new ilObjUser($a_owner_id);
537 }
538 }
539
540 if (is_object($owner)) {
541 $own_name = $owner->getFullname();
542 } else {
543 $own_name = $lng->txt("unknown");
544 }
545
546 return $own_name;
547 }
548
555 public function setOwner($a_owner)
556 {
557 $this->owner = $a_owner;
558 }
559
560
561
567 public function getCreateDate()
568 {
569 return $this->create_date;
570 }
571
577 public function getLastUpdateDate()
578 {
579 return $this->last_update;
580 }
581
582
594 public function getDiskUsage()
595 {
596 return null;
597 }
598
607 public function create()
608 {
609 global $DIC;
610
613 $ilUser = $DIC["ilUser"];
616
617 if (!isset($this->type)) {
618 $message = get_class($this) . "::create(): No object type given!";
619 $ilErr->raiseError($message, $ilErr->WARNING);
620 }
621
622 // write log entry
623 $ilLog->write("ilObject::create(), start");
624
625 $this->title = ilUtil::shortenText($this->getTitle(), $this->max_title, $this->add_dots);
626 $this->desc = ilUtil::shortenText($this->getDescription(), $this->max_desc, $this->add_dots);
627
628 // determine owner
629 if ($this->getOwner() > 0) {
630 $owner = $this->getOwner();
631 } elseif (is_object($ilUser)) {
632 $owner = $ilUser->getId();
633 } else {
634 $owner = 0;
635 }
636 $this->id = $ilDB->nextId("object_data");
637 $q = "INSERT INTO object_data " .
638 "(obj_id,type,title,description,owner,create_date,last_update,import_id) " .
639 "VALUES " .
640 "(" .
641 $ilDB->quote($this->id, "integer") . "," .
642 $ilDB->quote($this->type, "text") . "," .
643 $ilDB->quote($this->getTitle(), "text") . "," .
644 $ilDB->quote($this->getDescription(), "text") . "," .
645 $ilDB->quote($owner, "integer") . "," .
646 $ilDB->now() . "," .
647 $ilDB->now() . "," .
648 $ilDB->quote($this->getImportId(), "text") . ")";
649
650 $ilDB->manipulate($q);
651
652
653 // Save long form of description if is rbac object
654 if ($objDefinition->isRBACObject($this->getType())) {
655 $values = array(
656 'obj_id' => array('integer',$this->id),
657 'description' => array('clob', $this->getLongDescription()));
658 $ilDB->insert('object_description', $values);
659 }
660
661 if ($GLOBALS['DIC']['objDefinition']->isOrgUnitPermissionType($this->type)) {
662 ilOrgUnitGlobalSettings::getInstance()->saveDefaultPositionActivationStatus($this->id);
663 }
664
665 // the line ($this->read();) messes up meta data handling: meta data,
666 // that is not saved at this time, gets lost, so we query for the dates alone
667 //$this->read();
668 $q = "SELECT last_update, create_date FROM object_data" .
669 " WHERE obj_id = " . $ilDB->quote($this->id, "integer");
670 $obj_set = $ilDB->query($q);
671 $obj_rec = $ilDB->fetchAssoc($obj_set);
672 $this->last_update = $obj_rec["last_update"];
673 $this->create_date = $obj_rec["create_date"];
674
675 // set owner for new objects
676 $this->setOwner($owner);
677
678 // write log entry
679 $ilLog->write("ilObject::create(), finished, obj_id: " . $this->id . ", type: " .
680 $this->type . ", title: " . $this->getTitle());
681
682 $GLOBALS['ilAppEventHandler']->raise(
683 'Services/Object',
684 'create',
685 array('obj_id' => $this->id,'obj_type' => $this->type)
686 );
687
688 return $this->id;
689 }
690
697 public function update()
698 {
701
702 $q = "UPDATE object_data " .
703 "SET " .
704 "title = " . $ilDB->quote($this->getTitle(), "text") . "," .
705 "description = " . $ilDB->quote($this->getDescription(), "text") . ", " .
706 "import_id = " . $ilDB->quote($this->getImportId(), "text") . "," .
707 "last_update = " . $ilDB->now() . " " .
708 "WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
709 $ilDB->manipulate($q);
710
711 // the line ($this->read();) messes up meta data handling: meta data,
712 // that is not saved at this time, gets lost, so we query for the dates alone
713 //$this->read();
714 $q = "SELECT last_update FROM object_data" .
715 " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
716 $obj_set = $ilDB->query($q);
717 $obj_rec = $ilDB->fetchAssoc($obj_set);
718 $this->last_update = $obj_rec["last_update"];
719
720 if ($objDefinition->isRBACObject($this->getType())) {
721 // Update long description
722 $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = " .
723 $ilDB->quote($this->getId(), 'integer'));
724 if ($res->numRows()) {
725 $values = array(
726 'description' => array('clob',$this->getLongDescription())
727 );
728 $ilDB->update('object_description', $values, array('obj_id' => array('integer',$this->getId())));
729 } else {
730 $values = array(
731 'description' => array('clob',$this->getLongDescription()),
732 'obj_id' => array('integer',$this->getId()));
733 $ilDB->insert('object_description', $values);
734 }
735 }
736 $GLOBALS['ilAppEventHandler']->raise(
737 'Services/Object',
738 'update',
739 array('obj_id' => $this->getId(),
740 'obj_type' => $this->getType(),
741 'ref_id' => $this->getRefId())
742 );
743
744 return true;
745 }
746
758 public function MDUpdateListener($a_element)
759 {
760 include_once 'Services/MetaData/classes/class.ilMD.php';
761
762 $GLOBALS['ilAppEventHandler']->raise(
763 'Services/Object',
764 'update',
765 array('obj_id' => $this->getId(),
766 'obj_type' => $this->getType(),
767 'ref_id' => $this->getRefId())
768 );
769
770 switch ($a_element) {
771 case 'General':
772
773 // Update Title and description
774 $md = new ilMD($this->getId(), 0, $this->getType());
775 if (!is_object($md_gen = $md->getGeneral())) {
776 return false;
777 }
778 $this->setTitle($md_gen->getTitle());
779
780 foreach ($md_gen->getDescriptionIds() as $id) {
781 $md_des = $md_gen->getDescription($id);
782 $this->setDescription($md_des->getDescription());
783 break;
784 }
785 $this->update();
786 break;
787
788 default:
789 }
790
791 return true;
792 }
793
797 public function createMetaData()
798 {
799 global $DIC;
800
801 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
802
803 $ilUser = $DIC["ilUser"];
804
805 $md_creator = new ilMDCreator($this->getId(), 0, $this->getType());
806 $md_creator->setTitle($this->getTitle());
807 $md_creator->setTitleLanguage($ilUser->getPref('language'));
808 $md_creator->setDescription($this->getLongDescription());
809 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
810 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
811 $md_creator->setLanguage($ilUser->getPref('language'));
812 $md_creator->create();
813
814 return true;
815 }
816
820 public function updateMetaData()
821 {
822 $md = new ilMD($this->getId(), 0, $this->getType());
823 $md_gen = $md->getGeneral();
824 // BEGIN WebDAV: meta data can be missing sometimes.
825 if (!$md_gen instanceof ilMDGeneral) {
826 $this->createMetaData();
827 $md = new ilMD($this->getId(), 0, $this->getType());
828 $md_gen = $md->getGeneral();
829 }
830 // END WebDAV: meta data can be missing sometimes.
831 $md_gen->setTitle($this->getTitle());
832
833 // sets first description (maybe not appropriate)
834 $md_des_ids = $md_gen->getDescriptionIds();
835 if (count($md_des_ids) > 0) {
836 $md_des = $md_gen->getDescription($md_des_ids[0]);
837 $md_des->setDescription($this->getLongDescription());
838 $md_des->update();
839 }
840 $md_gen->update();
841 }
842
846 public function deleteMetaData()
847 {
848 // Delete meta data
849 include_once('Services/MetaData/classes/class.ilMD.php');
850 $md = new ilMD($this->getId(), 0, $this->getType());
851 $md->deleteAll();
852 }
853
860 public function updateOwner()
861 {
863
864 $q = "UPDATE object_data " .
865 "SET " .
866 "owner = " . $ilDB->quote($this->getOwner(), "integer") . ", " .
867 "last_update = " . $ilDB->now() . " " .
868 "WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
869 $ilDB->manipulate($q);
870
871 $q = "SELECT last_update FROM object_data" .
872 " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
873 $obj_set = $ilDB->query($q);
874 $obj_rec = $ilDB->fetchAssoc($obj_set);
875 $this->last_update = $obj_rec["last_update"];
876
877 return true;
878 }
879
887 public static function _getIdForImportId($a_import_id)
888 {
889 global $DIC;
890
891 $ilDB = $DIC->database();
892
893 $ilDB->setLimit(1, 0);
894 $q = "SELECT * FROM object_data WHERE import_id = " . $ilDB->quote($a_import_id, "text") .
895 " ORDER BY create_date DESC";
896 $obj_set = $ilDB->query($q);
897
898 if ($obj_rec = $ilDB->fetchAssoc($obj_set)) {
899 return $obj_rec["obj_id"];
900 } else {
901 return 0;
902 }
903 }
904
910 public static function _getAllReferences($a_id)
911 {
912 global $DIC;
913
914 $ilDB = $DIC->database();
915
916 $query = "SELECT * FROM object_reference WHERE obj_id = " .
917 $ilDB->quote($a_id, 'integer');
918
919 $res = $ilDB->query($query);
920 $ref = array();
921 while ($obj_rec = $ilDB->fetchAssoc($res)) {
922 $ref[$obj_rec["ref_id"]] = $obj_rec["ref_id"];
923 }
924
925 return $ref;
926 }
927
933 public static function _lookupTitle($a_id)
934 {
935 global $DIC;
936
937 $ilObjDataCache = $DIC["ilObjDataCache"];
938
939 $tit = $ilObjDataCache->lookupTitle($a_id);
940 //echo "<br>LOOKING-$a_id-:$tit";
941 return $tit;
942 }
943
949 public static function _lookupOwner($a_id)
950 {
951 global $DIC;
952
953 $ilObjDataCache = $DIC["ilObjDataCache"];
954
955 $owner = $ilObjDataCache->lookupOwner($a_id);
956 return $owner;
957 }
958
959 public static function _getIdsForTitle($title, $type = '', $partialmatch = false)
960 {
961 global $DIC;
962
963 $ilDB = $DIC->database();
964
965 $query = (!$partialmatch)
966 ? "SELECT obj_id FROM object_data WHERE title = " . $ilDB->quote($title, "text")
967 : "SELECT obj_id FROM object_data WHERE " . $ilDB->like("title", "text", '%' . $title . '%');
968 if ($type != '') {
969 $query .= " AND type = " . $ilDB->quote($type, "text");
970 }
971
972 $result = $ilDB->query($query);
973
974 $object_ids = array();
975 while ($row = $ilDB->fetchAssoc($result)) {
976 $object_ids[] = $row['obj_id'];
977 }
978
979 return is_array($object_ids) ? $object_ids : array();
980 }
981
987 public static function _lookupDescription($a_id)
988 {
989 global $DIC;
990
991 $ilObjDataCache = $DIC["ilObjDataCache"];
992
993 return $ilObjDataCache->lookupDescription($a_id);
994 }
995
1001 public static function _lookupLastUpdate($a_id, $a_as_string = false)
1002 {
1003 global $DIC;
1004
1005 $ilObjDataCache = $DIC["ilObjDataCache"];
1006
1007 if ($a_as_string) {
1008 return ilDatePresentation::formatDate(new ilDateTime($ilObjDataCache->lookupLastUpdate($a_id), IL_CAL_DATETIME));
1009 } else {
1010 return $ilObjDataCache->lookupLastUpdate($a_id);
1011 }
1012 }
1013
1019 public static function _getLastUpdateOfObjects($a_objs)
1020 {
1021 global $DIC;
1022
1023 $ilDB = $DIC->database();
1024
1025 if (!is_array($a_objs)) {
1026 $a_objs = array($a_objs);
1027 }
1028 $types = array();
1029 $set = $ilDB->query("SELECT max(last_update) as last_update FROM object_data " .
1030 "WHERE " . $ilDB->in("obj_id", $a_objs, false, "integer") . " ");
1031 $rec = $ilDB->fetchAssoc($set);
1032
1033 return ($rec["last_update"]);
1034 }
1035
1036 public static function _lookupObjId($a_id)
1037 {
1038 global $DIC;
1039
1040 $ilObjDataCache = $DIC["ilObjDataCache"];
1041
1042 return (int) $ilObjDataCache->lookupObjId($a_id);
1043 }
1044
1048 public static function _setDeletedDate($a_ref_id)
1049 {
1050 global $DIC;
1051
1052 $ilDB = $DIC->database();
1053
1054 $query = "UPDATE object_reference SET deleted= " . $ilDB->now() . ' ' .
1055 "WHERE ref_id = " . $ilDB->quote($a_ref_id, 'integer');
1056 $res = $ilDB->manipulate($query);
1057 }
1058
1065 public static function setDeletedDates($a_ref_ids)
1066 {
1067 global $DIC;
1068
1069 $ilDB = $DIC->database();
1070
1071 $query = 'UPDATE object_reference SET deleted = ' . $ilDB->now() . ' ' .
1072 'WHERE ' . $ilDB->in('ref_id', (array) $a_ref_ids, false, 'integer');
1073
1074 $GLOBALS['ilLog']->write(__METHOD__ . ': Query is ' . $query);
1075 $ilDB->manipulate($query);
1076 return;
1077 }
1078
1082 public static function _resetDeletedDate($a_ref_id)
1083 {
1084 global $DIC;
1085
1086 $ilDB = $DIC->database();
1087
1088 $query = "UPDATE object_reference SET deleted = " . $ilDB->quote(null, 'timestamp') .
1089 " WHERE ref_id = " . $ilDB->quote($a_ref_id, 'integer');
1090 $ilDB->manipulate($query);
1091 }
1092
1096 public static function _lookupDeletedDate($a_ref_id)
1097 {
1098 global $DIC;
1099
1100 $ilDB = $DIC->database();
1101
1102 $query = "SELECT deleted FROM object_reference" .
1103 " WHERE ref_id = " . $ilDB->quote($a_ref_id, "integer");
1104 $set = $ilDB->query($query);
1105 $rec = $ilDB->fetchAssoc($set);
1106
1107 return $rec["deleted"];
1108 }
1109
1110
1118 public static function _writeTitle($a_obj_id, $a_title)
1119 {
1120 global $DIC;
1121
1122 $ilDB = $DIC->database();
1123
1124 $q = "UPDATE object_data " .
1125 "SET " .
1126 "title = " . $ilDB->quote($a_title, "text") . "," .
1127 "last_update = " . $ilDB->now() . " " .
1128 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
1129
1130 $ilDB->manipulate($q);
1131 }
1132
1140 public static function _writeDescription($a_obj_id, $a_desc)
1141 {
1142 global $DIC;
1143
1144 $ilDB = $DIC->database();
1145 $objDefinition = $DIC["objDefinition"];
1146
1147
1148 $desc = ilUtil::shortenText($a_desc, self::DESC_LENGTH, true);
1149
1150 $q = "UPDATE object_data " .
1151 "SET " .
1152 "description = " . $ilDB->quote($desc, "text") . "," .
1153 "last_update = " . $ilDB->now() . " " .
1154 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
1155
1156 $ilDB->manipulate($q);
1157
1158 if ($objDefinition->isRBACObject(ilObject::_lookupType($a_obj_id))) {
1159 // Update long description
1160 $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = " .
1161 $ilDB->quote($a_obj_id, 'integer'));
1162
1163 if ($res->numRows()) {
1164 $values = array(
1165 'description' => array('clob',$a_desc)
1166 );
1167 $ilDB->update('object_description', $values, array('obj_id' => array('integer',$a_obj_id)));
1168 } else {
1169 $values = array(
1170 'description' => array('clob',$a_desc),
1171 'obj_id' => array('integer',$a_obj_id));
1172 $ilDB->insert('object_description', $values);
1173 }
1174 }
1175 }
1176
1184 public static function _writeImportId($a_obj_id, $a_import_id)
1185 {
1186 global $DIC;
1187
1188 $ilDB = $DIC->database();
1189
1190 $q = "UPDATE object_data " .
1191 "SET " .
1192 "import_id = " . $ilDB->quote($a_import_id, "text") . "," .
1193 "last_update = " . $ilDB->now() . " " .
1194 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
1195
1196 $ilDB->manipulate($q);
1197 }
1198
1204 public static function _lookupType($a_id, $a_reference = false)
1205 {
1206 global $DIC;
1207
1208 $ilObjDataCache = $DIC["ilObjDataCache"];
1209
1210 if ($a_reference) {
1211 return $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_id));
1212 }
1213 return $ilObjDataCache->lookupType($a_id);
1214 }
1215
1219 public static function _isInTrash($a_ref_id)
1220 {
1221 global $DIC;
1222
1223 $tree = $DIC->repositoryTree();
1224
1225 return $tree->isSaved($a_ref_id);
1226 }
1227
1231 public static function _hasUntrashedReference($a_obj_id)
1232 {
1233 $ref_ids = ilObject::_getAllReferences($a_obj_id);
1234 foreach ($ref_ids as $ref_id) {
1236 return true;
1237 }
1238 }
1239
1240 return false;
1241 }
1242
1248 public static function _lookupObjectId($a_ref_id)
1249 {
1250 global $DIC;
1251
1252 $ilObjDataCache = $DIC["ilObjDataCache"];
1253
1254 return (int) $ilObjDataCache->lookupObjId($a_ref_id);
1255 }
1256
1267 public static function _getObjectsDataForType($a_type, $a_omit_trash = false)
1268 {
1269 global $DIC;
1270
1271 $ilDB = $DIC->database();
1272
1273 $q = "SELECT * FROM object_data WHERE type = " . $ilDB->quote($a_type, "text");
1274 $obj_set = $ilDB->query($q);
1275
1276 $objects = array();
1277 while ($obj_rec = $ilDB->fetchAssoc($obj_set)) {
1278 if ((!$a_omit_trash) || ilObject::_hasUntrashedReference($obj_rec["obj_id"])) {
1279 $objects[$obj_rec["title"] . "." . $obj_rec["obj_id"]] = array("id" => $obj_rec["obj_id"],
1280 "type" => $obj_rec["type"], "title" => $obj_rec["title"],
1281 "description" => $obj_rec["description"]);
1282 }
1283 }
1284 ksort($objects);
1285 return $objects;
1286 }
1287
1288
1296 public function putInTree($a_parent_ref)
1297 {
1300 $ilAppEventHandler = $this->app_event_handler;
1301
1302 $tree->insertNode($this->getRefId(), $a_parent_ref);
1303
1304 // write log entry
1305 $ilLog->write("ilObject::putInTree(), parent_ref: $a_parent_ref, ref_id: " .
1306 $this->getRefId() . ", obj_id: " . $this->getId() . ", type: " .
1307 $this->getType() . ", title: " . $this->getTitle());
1308
1309 $ilAppEventHandler->raise(
1310 'Services/Object',
1311 'putObjectInTree',
1312 array(
1313 'object' => $this,
1314 'obj_type' => $this->getType(),
1315 'obj_id' => $this->getId(),
1316 'parent_ref_id' => $a_parent_ref,
1317 )
1318 );
1319 }
1320
1327 public function setPermissions($a_parent_ref)
1328 {
1329 $this->setParentRolePermissions($a_parent_ref);
1330 $this->initDefaultRoles();
1331 }
1332
1337 public function setParentRolePermissions($a_parent_ref)
1338 {
1339 global $DIC;
1340
1341 $rbacadmin = $DIC["rbacadmin"];
1342 $rbacreview = $DIC["rbacreview"];
1343
1344 $parent_roles = $rbacreview->getParentRoleIds($a_parent_ref);
1345 foreach ((array) $parent_roles as $parent_role) {
1346 $operations = $rbacreview->getOperationsOfRole(
1347 $parent_role['obj_id'],
1348 $this->getType(),
1349 $parent_role['parent']
1350 );
1351 $rbacadmin->grantPermission(
1352 $parent_role['obj_id'],
1353 $operations,
1354 $this->getRefId()
1355 );
1356 }
1357 return true;
1358 }
1359
1366 public function createReference()
1367 {
1368 $ilDB = $this->db;
1370
1371 if (!isset($this->id)) {
1372 $message = "ilObject::createNewReference(): No obj_id given!";
1373 $ilErr->raiseError($message, $ilErr->WARNING);
1374 }
1375
1376 $next_id = $ilDB->nextId('object_reference');
1377 $query = "INSERT INTO object_reference " .
1378 "(ref_id, obj_id) VALUES (" . $ilDB->quote($next_id, 'integer') . ',' . $ilDB->quote($this->id, 'integer') . ")";
1379 $ilDB->query($query);
1380
1381 $this->ref_id = $next_id;
1382 $this->referenced = true;
1383
1384 return $this->ref_id;
1385 }
1386
1387
1394 public function countReferences()
1395 {
1396 $ilDB = $this->db;
1398
1399 if (!isset($this->id)) {
1400 $message = "ilObject::countReferences(): No obj_id given!";
1401 $ilErr->raiseError($message, $ilErr->WARNING);
1402 }
1403
1404 $query = "SELECT COUNT(ref_id) num FROM object_reference " .
1405 "WHERE obj_id = " . $ilDB->quote($this->id, 'integer') . " ";
1406 $res = $ilDB->query($query);
1407 $row = $ilDB->fetchObject($res);
1408
1409 return $row->num;
1410 }
1411
1412
1423 public function delete()
1424 {
1425 global $DIC;
1426
1427 $rbacadmin = $DIC["rbacadmin"];
1429 $ilDB = $this->db;
1430 $ilAppEventHandler = $this->app_event_handler;
1436 $remove = false;
1437
1438 // delete object_data entry
1439 if ((!$this->referenced) || ($this->countReferences() == 1)) {
1440 // check type match
1441 $db_type = ilObject::_lookupType($this->getId());
1442 if ($this->type != $db_type) {
1443 $message = "ilObject::delete(): Type mismatch. Object with obj_id: " . $this->id . " " .
1444 "was instantiated by type '" . $this->type . "'. DB type is: " . $db_type;
1445
1446 // write log entry
1447 $ilLog->write($message);
1448
1449 // raise error
1450 $ilErr->raiseError("ilObject::delete(): Type mismatch. (" . $this->type . "/" . $this->id . ")", $ilErr->WARNING);
1451 }
1452
1453 $ilAppEventHandler->raise('Services/Object', 'beforeDeletion', array( 'object' => $this ));
1454
1455 // delete entry in object_data
1456 $q = "DELETE FROM object_data " .
1457 "WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
1458 $ilDB->manipulate($q);
1459
1460 // delete long description
1461 $query = "DELETE FROM object_description WHERE obj_id = " .
1462 $ilDB->quote($this->getId(), "integer");
1463 $ilDB->manipulate($query);
1464
1465 // write log entry
1466 $ilLog->write("ilObject::delete(), deleted object, obj_id: " . $this->getId() . ", type: " .
1467 $this->getType() . ", title: " . $this->getTitle());
1468
1469 // keep log of core object data
1470 include_once "Services/Object/classes/class.ilObjectDataDeletionLog.php";
1472
1473 // remove news
1474 include_once("./Services/News/classes/class.ilNewsItem.php");
1475 $news_item = new ilNewsItem();
1476 $news_item->deleteNewsOfContext($this->getId(), $this->getType());
1477 include_once("./Services/Block/classes/class.ilBlockSetting.php");
1479
1480 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1482
1483 /* remove notes (see infoscreen gui)
1484 as they can be seen as personal data we are keeping them for now
1485 include_once("Services/Notes/classes/class.ilNote.php");
1486 foreach(array(IL_NOTE_PRIVATE, IL_NOTE_PUBLIC) as $note_type)
1487 {
1488 foreach(ilNote::_getNotesOfObject($this->id, 0, $this->type, $note_type) as $note)
1489 {
1490 $note->delete();
1491 }
1492 }
1493 */
1494
1495 // BEGIN WebDAV: Delete WebDAV properties
1496 $query = "DELETE FROM dav_property " .
1497 "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
1498 $res = $ilDB->manipulate($query);
1499 // END WebDAV: Delete WebDAV properties
1500
1501 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
1503
1504 include_once("Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
1506
1507 include_once("Services/Tracking/classes/class.ilLPObjSettings.php");
1509
1510 $remove = true;
1511 } else {
1512 // write log entry
1513 $ilLog->write("ilObject::delete(), object not deleted, number of references: " .
1514 $this->countReferences() . ", obj_id: " . $this->getId() . ", type: " .
1515 $this->getType() . ", title: " . $this->getTitle());
1516 }
1517
1518 // delete object_reference entry
1519 if ($this->referenced) {
1520 include_once "Services/Object/classes/class.ilObjectActivation.php";
1522
1523 // delete entry in object_reference
1524 $query = "DELETE FROM object_reference " .
1525 "WHERE ref_id = " . $ilDB->quote($this->getRefId(), 'integer');
1526 $res = $ilDB->manipulate($query);
1527
1528 // write log entry
1529 $ilLog->write("ilObject::delete(), reference deleted, ref_id: " . $this->getRefId() .
1530 ", obj_id: " . $this->getId() . ", type: " .
1531 $this->getType() . ", title: " . $this->getTitle());
1532
1533 // DELETE PERMISSION ENTRIES IN RBAC_PA
1534 // DONE: method overwritten in ilObjRole & ilObjUser.
1535 // this call only applies for objects in rbac (not usr,role,rolt)
1536 // TODO: Do this for role templates too
1537 $rbacadmin->revokePermission($this->getRefId(), 0, false);
1538
1539 include_once "Services/AccessControl/classes/class.ilRbacLog.php";
1540 ilRbacLog::delete($this->getRefId());
1541
1542 // Remove applied didactic template setting
1543 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1545
1546 // Remove desktop items
1548 }
1549
1550 // remove conditions
1551 if ($this->referenced) {
1552 $ch = new ilConditionHandler();
1553 $ch->delete($this->getRefId());
1554 unset($ch);
1555 }
1556
1557 return $remove;
1558 }
1559
1567 public function initDefaultRoles()
1568 {
1569 return array();
1570 }
1571
1572
1577 public function applyDidacticTemplate($a_tpl_id)
1578 {
1579 ilLoggerFactory::getLogger('obj')->debug('Applying didactic template with id: ' . (int) $a_tpl_id);
1580 if ($a_tpl_id) {
1581 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
1583 $action->setRefId($this->getRefId());
1584 $action->apply();
1585 }
1586 }
1587
1588 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1589 ilDidacticTemplateObjSettings::assignTemplate($this->getRefId(), $this->getId(), (int) $a_tpl_id);
1590 return $a_tpl_id ? true : false;
1591 }
1592
1602 public static function _exists($a_id, $a_reference = false, $a_type = null)
1603 {
1604 global $DIC;
1605
1606 $ilDB = $DIC->database();
1607
1608 if ($a_reference) {
1609 $q = "SELECT * FROM object_data " .
1610 "LEFT JOIN object_reference ON object_reference.obj_id=object_data.obj_id " .
1611 "WHERE object_reference.ref_id= " . $ilDB->quote($a_id, "integer");
1612 } else {
1613 $q = "SELECT * FROM object_data WHERE obj_id=" . $ilDB->quote($a_id, "integer");
1614 }
1615
1616 if ($a_type) {
1617 $q .= " AND object_data.type = " . $ilDB->quote($a_type, "text");
1618 }
1619
1620 $r = $ilDB->query($q);
1621
1622 return $ilDB->numRows($r) ? true : false;
1623 }
1624
1625 // toggle subscription interface
1626 public function setRegisterMode($a_bool)
1627 {
1628 $this->register = (bool) $a_bool;
1629 }
1630
1631 // check register status of current user
1632 // abstract method; overwrite in object type class
1633 public function isUserRegistered($a_user_id = 0)
1634 {
1635 return false;
1636 }
1637
1638 public function requireRegistration()
1639 {
1640 return $this->register;
1641 }
1642
1643
1644 public function getXMLZip()
1645 {
1646 return false;
1647 }
1648 public function getHTMLDirectory()
1649 {
1650 return false;
1651 }
1652
1656 public static function _getObjectsByType($a_obj_type = "", $a_owner = "")
1657 {
1658 global $DIC;
1659
1660 $ilDB = $DIC->database();
1661
1662 $order = " ORDER BY title";
1663
1664 // where clause
1665 if ($a_obj_type) {
1666 $where_clause = "WHERE type = " .
1667 $ilDB->quote($a_obj_type, "text");
1668
1669 if ($a_owner != "") {
1670 $where_clause.= " AND owner = " . $ilDB->quote($a_owner, "integer");
1671 }
1672 }
1673
1674 $q = "SELECT * FROM object_data " . $where_clause . $order;
1675 $r = $ilDB->query($q);
1676
1677 $arr = array();
1678 if ($ilDB->numRows($r) > 0) {
1679 while ($row = $ilDB->fetchAssoc($r)) {
1680 $row["desc"] = $row["description"];
1681 $arr[$row["obj_id"]] = $row;
1682 }
1683 }
1684
1685 return $arr;
1686 }
1687
1703 public static function _prepareCloneSelection($a_ref_ids, $new_type, $show_path = true)
1704 {
1705 global $DIC;
1706
1707 $ilDB = $DIC->database();
1708 $lng = $DIC->language();
1709 $objDefinition = $DIC["objDefinition"];
1710
1711 $query = "SELECT obj_data.title obj_title,path_data.title path_title,child FROM tree " .
1712 "JOIN object_reference obj_ref ON child = obj_ref.ref_id " .
1713 "JOIN object_data obj_data ON obj_ref.obj_id = obj_data.obj_id " .
1714 "JOIN object_reference path_ref ON parent = path_ref.ref_id " .
1715 "JOIN object_data path_data ON path_ref.obj_id = path_data.obj_id " .
1716 "WHERE " . $ilDB->in("child", $a_ref_ids, false, "integer") . " " .
1717 "ORDER BY obj_data.title ";
1718 $res = $ilDB->query($query);
1719
1720 if (!$objDefinition->isPlugin($new_type)) {
1721 $options[0] = $lng->txt('obj_' . $new_type . '_select');
1722 } else {
1723 require_once("Services/Repository/classes/class.ilObjectPlugin.php");
1724 $options[0] = ilObjectPlugin::lookupTxtById($new_type, "obj_" . $new_type . "_select");
1725 }
1726
1727 while ($row = $ilDB->fetchObject($res)) {
1728 if (strlen($title = $row->obj_title) > 40) {
1729 $title = substr($title, 0, 40) . '...';
1730 }
1731
1732 if ($show_path) {
1733 if (strlen($path = $row->path_title) > 40) {
1734 $path = substr($path, 0, 40) . '...';
1735 }
1736
1737 $title .= ' (' . $lng->txt('path') . ': ' . $path . ')';
1738 }
1739
1740 $options[$row->child] = $title;
1741 }
1742 return $options ? $options : array();
1743 }
1744
1754 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
1755 {
1756 global $DIC;
1757
1759 $ilUser = $DIC["ilUser"];
1760 $rbacadmin = $DIC["rbacadmin"];
1761 $ilDB = $this->db;
1762 $ilAppEventHandler = $this->app_event_handler;
1767 $location = $objDefinition->getLocation($this->getType());
1768 $class_name = ('ilObj' . $objDefinition->getClassName($this->getType()));
1769
1770 include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1772
1773 if (!$options->isTreeCopyDisabled() && !$a_omit_tree) {
1774 $title = $this->appendCopyInfo($a_target_id, $a_copy_id);
1775 } else {
1776 $title = $this->getTitle();
1777 }
1778
1779 // create instance
1780 include_once($location . "/class." . $class_name . ".php");
1781 $new_obj = new $class_name(0, false);
1782 $new_obj->setOwner($ilUser->getId());
1783 $new_obj->setTitle($title);
1784 $new_obj->setDescription($this->getLongDescription());
1785 $new_obj->setType($this->getType());
1786 // Choose upload mode to avoid creation of additional settings, db entries ...
1787 $new_obj->create(true);
1788
1789 if (!$options->isTreeCopyDisabled() && !$a_omit_tree) {
1790 ilLoggerFactory::getLogger('obj')->debug('Tree copy is enabled');
1791 $new_obj->createReference();
1792 $new_obj->putInTree($a_target_id);
1793 $new_obj->setPermissions($a_target_id);
1794
1795 // when copying from personal workspace we have no current ref id
1796 if ($this->getRefId()) {
1797 // copy local roles
1798 $rbacadmin->copyLocalRoles($this->getRefId(), $new_obj->getRefId());
1799 }
1800 } else {
1801 ilLoggerFactory::getLogger('obj')->debug('Tree copy is disabled');
1802 }
1803
1804 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1805 ilAdvancedMDValues::_cloneValues($this->getId(), $new_obj->getId());
1806
1807 // BEGIN WebDAV: Clone WebDAV properties
1808 $query = "INSERT INTO dav_property (obj_id,node_id,ns,name,value) " .
1809 "SELECT " . $ilDB->quote($new_obj->getId(), 'integer') . ",node_id,ns,name,value " .
1810 "FROM dav_property " .
1811 "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
1812 $res = $ilDB->manipulate($query);
1813 // END WebDAV: Clone WebDAV properties
1814
1815 $ilAppEventHandler->raise('Services/Object', 'cloneObject', array(
1816 'object' => $new_obj,
1817 'cloned_from_object' => $this,
1818 ));
1819
1820 return $new_obj;
1821 }
1822
1830 public function appendCopyInfo($a_target_id, $a_copy_id)
1831 {
1833
1834 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
1835 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
1836 if (!$cp_options->isRootNode($this->getRefId())) {
1837 return $this->getTitle();
1838 }
1839 $nodes = $tree->getChilds($a_target_id);
1840
1841 $title_unique = false;
1842 require_once 'Modules/File/classes/class.ilObjFileAccess.php';
1843 $numberOfCopy = 1;
1844 $handleExtension = ($this->getType() == "file"); // #14883
1845 $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), $numberOfCopy, $handleExtension);
1846 while (!$title_unique) {
1847 $found = 0;
1848 foreach ($nodes as $node) {
1849 if (($title == $node['title']) and ($this->getType() == $node['type'])) {
1850 $found++;
1851 }
1852 }
1853 if ($found > 0) {
1854 $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), ++$numberOfCopy, $handleExtension);
1855 } else {
1856 break;
1857 }
1858 }
1859 return $title;
1860 }
1861
1874 public function cloneDependencies($a_target_id, $a_copy_id)
1875 {
1876 include_once './Services/AccessControl/classes/class.ilConditionHandler.php' ;
1877 ilConditionHandler::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
1878
1879 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1881 if ($tpl_id) {
1882 include_once './Services/Object/classes/class.ilObjectFactory.php';
1883 $factory = new ilObjectFactory();
1884 $obj = $factory->getInstanceByRefId($a_target_id, false);
1885 if ($obj instanceof ilObject) {
1886 $obj->applyDidacticTemplate($tpl_id);
1887 }
1888 }
1889 return true;
1890 }
1891
1899 public function cloneMetaData($target_obj)
1900 {
1901 $md = new ilMD($this->getId(), 0, $this->getType());
1902 $md->cloneMD($target_obj->getId(), 0, $target_obj->getType());
1903 return true;
1904 }
1905
1914 public static function _getIcon(
1915 $a_obj_id = "",
1916 $a_size = "big",
1917 $a_type = "",
1918 $a_offline = false
1919 ) {
1920 global $DIC;
1921
1922 $ilSetting = $DIC->settings();
1923 $objDefinition = $DIC["objDefinition"];
1924
1925 if ($a_obj_id == "" && $a_type == "") {
1926 return "";
1927 }
1928
1929 if ($a_type == "") {
1930 $a_type = ilObject::_lookupType($a_obj_id);
1931 }
1932
1933 if ($a_size == "") {
1934 $a_size = "big";
1935 }
1936
1937 if ($ilSetting->get("custom_icons") &&
1938 in_array($a_type, array("cat","grp","crs", "root", "fold", "prg"))) {
1939 require_once("./Services/Container/classes/class.ilContainer.php");
1940 if (ilContainer::_lookupContainerSetting($a_obj_id, "icon_custom")) {
1941 $cont_dir = ilContainer::_getContainerDirectory($a_obj_id);
1942
1943 $file_name = $cont_dir . "/icon_custom.svg";
1944 if (is_file($file_name)) {
1945 // prevent caching
1946 return $file_name . "?tmp=" . filemtime($file_name);
1947 }
1948 }
1949 }
1950
1951 if (!$a_offline) {
1952 if ($objDefinition->isPluginTypeName($a_type)) {
1953 if ($objDefinition->getClassName($a_type) != "") {
1954 $class_name = "il" . $objDefinition->getClassName($a_type) . 'Plugin';
1955 $location = $objDefinition->getLocation($a_type);
1956 if (is_file($location . "/class." . $class_name . ".php")) {
1957 include_once($location . "/class." . $class_name . ".php");
1958 return call_user_func(array($class_name, "_getIcon"), $a_type, $a_size, $a_obj_id);
1959 }
1960 }
1961 return ilUtil::getImagePath("icon_cmps.svg");
1962 }
1963
1964 return ilUtil::getImagePath("icon_" . $a_type . ".svg");
1965 } else {
1966 return "./images/icon_" . $a_type . ".svg";
1967 }
1968 }
1969
1976 public static function collectDeletionDependencies(&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth = 0)
1977 {
1978 global $DIC;
1979
1980 $objDefinition = $DIC["objDefinition"];
1981 $tree = $DIC->repositoryTree();
1982
1983 if ($a_depth == 0) {
1984 $deps["dep"] = array();
1985 }
1986
1987 $deps["del_ids"][$a_obj_id] = $a_obj_id;
1988
1989 if (!$objDefinition->isPluginTypeName($a_type)) {
1990 $class_name = "ilObj" . $objDefinition->getClassName($a_type);
1991 $location = $objDefinition->getLocation($a_type);
1992 include_once($location . "/class." . $class_name . ".php");
1993 $odeps = call_user_func(array($class_name, "getDeletionDependencies"), $a_obj_id);
1994 if (is_array($odeps)) {
1995 foreach ($odeps as $id => $message) {
1996 $deps["dep"][$id][$a_obj_id][] = $message;
1997 }
1998 }
1999
2000 // get deletion dependency of childs
2001 foreach ($tree->getChilds($a_ref_id) as $c) {
2002 ilObject::collectDeletionDependencies($deps, $c["child"], $c["obj_id"], $c["type"], $a_depth + 1);
2003 }
2004 }
2005
2006 // delete all dependencies to objects that will be deleted, too
2007 if ($a_depth == 0) {
2008 foreach ($deps["del_ids"] as $obj_id) {
2009 unset($deps["dep"][$obj_id]);
2010 }
2011 $deps = $deps["dep"];
2012 }
2013 }
2014
2019 public static function getDeletionDependencies($a_obj_id)
2020 {
2021 return false;
2022 }
2023
2030 public static function getLongDescriptions(array $a_obj_ids)
2031 {
2032 global $DIC;
2033
2034 $ilDB = $DIC->database();
2035
2036 $res = $ilDB->query("SELECT * FROM object_description" .
2037 " WHERE " . $ilDB->in("obj_id", $a_obj_ids, "", "integer"));
2038 $all = array();
2039 while ($row = $ilDB->fetchAssoc($res)) {
2040 $all[$row["obj_id"]] = $row["description"];
2041 }
2042 return $all;
2043 }
2044
2051 public static function getAllOwnedRepositoryObjects($a_user_id)
2052 {
2053 global $DIC;
2054
2055 $ilDB = $DIC->database();
2056 $objDefinition = $DIC["objDefinition"];
2057
2058 $all = array();
2059
2060 // restrict to repository
2061 $types = array_keys($objDefinition->getSubObjectsRecursively("root"));
2062
2063 $sql = "SELECT od.obj_id,od.type,od.title FROM object_data od" .
2064 " JOIN object_reference oref ON(oref.obj_id = od.obj_id)" .
2065 " JOIN tree ON (tree.child = oref.ref_id)";
2066
2067 if ($a_user_id) {
2068 $sql .= " WHERE od.owner = " . $ilDB->quote($a_user_id, "integer");
2069 } else {
2070 $sql .= " LEFT JOIN usr_data ud ON (ud.usr_id = od.owner)" .
2071 " WHERE (od.owner < " . $ilDB->quote(1, "integer") .
2072 " OR od.owner IS NULL OR ud.login IS NULL)" .
2073 " AND od.owner <> " . $ilDB->quote(-1, "integer");
2074 }
2075
2076 $sql .= " AND " . $ilDB->in("od.type", $types, "", "text") .
2077 " AND tree.tree > " . $ilDB->quote(0, "integer"); // #12485
2078
2079 $res = $ilDB->query($sql);
2080 while ($row = $ilDB->fetchAssoc($res)) {
2081 $all[$row["type"]][$row["obj_id"]] = $row["title"];
2082 }
2083
2084 return $all;
2085 }
2086
2093 public static function fixMissingTitles($a_type, array &$a_obj_title_map)
2094 {
2095 global $DIC;
2096
2097 $ilDB = $DIC->database();
2098
2099 if (!in_array($a_type, array("catr", "crsr", "sess", "grpr"))) {
2100 return;
2101 }
2102
2103 // any missing titles?
2104 $missing_obj_ids = array();
2105 foreach ($a_obj_title_map as $obj_id => $title) {
2106 if (!trim($title)) {
2107 $missing_obj_ids[] = $obj_id;
2108 }
2109 }
2110
2111 if (!sizeof($missing_obj_ids)) {
2112 return;
2113 }
2114
2115 switch ($a_type) {
2116 case "grpr":
2117 case "catr":
2118 case "crsr":
2119 $set = $ilDB->query("SELECT oref.obj_id, od.type, od.title FROM object_data od" .
2120 " JOIN container_reference oref ON (od.obj_id = oref.target_obj_id)" .
2121 " AND " . $ilDB->in("oref.obj_id", $missing_obj_ids, "", "integer"));
2122 while ($row = $ilDB->fetchAssoc($set)) {
2123 $a_obj_title_map[$row["obj_id"]] = $row["title"];
2124 }
2125 break;
2126
2127 case "sess":
2128 include_once "Modules/Session/classes/class.ilObjSession.php";
2129 foreach ($missing_obj_ids as $obj_id) {
2130 $sess = new ilObjSession($obj_id, false);
2131 $a_obj_title_map[$obj_id] = $sess->getFirstAppointment()->appointmentToString();
2132 }
2133 break;
2134 }
2135 }
2136
2143 public static function _lookupCreationDate($a_id)
2144 {
2145 global $DIC;
2146
2147 $ilDB = $DIC->database();
2148
2149 $set = $ilDB->query("SELECT create_date FROM object_data " .
2150 " WHERE obj_id = " . $ilDB->quote($a_id, "integer"));
2151 $rec = $ilDB->fetchAssoc($set);
2152 return $rec["create_date"];
2153 }
2154
2162 public static function hasAutoRating($a_type, $a_ref_id)
2163 {
2164 global $DIC;
2165
2166 $tree = $DIC->repositoryTree();
2167
2168 if (!$a_ref_id ||
2169 !in_array($a_type, array("file", "lm", "wiki"))) {
2170 return false;
2171 }
2172
2173 // find parent container
2174 $parent_ref_id = $tree->checkForParentType($a_ref_id, "grp");
2175 if (!$parent_ref_id) {
2176 $parent_ref_id = $tree->checkForParentType($a_ref_id, "crs");
2177 }
2178 if ($parent_ref_id) {
2179 include_once './Services/Object/classes/class.ilObjectServiceSettingsGUI.php';
2180
2181 // get auto rate setting
2182 $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
2184 $parent_obj_id,
2186 false
2187 );
2188 }
2189 return false;
2190 }
2191
2201 public function getPossibleSubObjects($a_filter = true)
2202 {
2203 return $this->objDefinition->getSubObjects($this->type, $a_filter);
2204 }
2205} // END class.ilObject
$result
$factory
Definition: metadata.php:47
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
$location
Definition: buildRTE.php:44
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
error($a_errmsg)
set error message @access public
static _deleteByObjId($a_obj_id)
Delete by objekt id.
static _cloneValues($a_source_id, $a_target_id, $a_sub_type=null, $a_source_sub_id=null, $a_target_sub_id=null)
Clone Advanced Meta Data.
static _deleteSettingsOfBlock($a_block_id, $a_block_type)
Delete block settings of block.
Handles conditions for accesses to different ILIAS objects.
static cloneDependencies($a_src_ref_id, $a_target_ref_id, $a_copy_id)
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
static _getContainerDirectory($a_id)
Get the container directory.
static _getInstance($a_copy_id)
Get instance of copy wizard options.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date @access public.
@classDescription Date and time handling
static getActionsByTemplateId($a_tpl_id)
Get actions of one template.
static assignTemplate($a_ref_id, $a_obj_id, $a_tpl_id)
Assign template to object @global ilDB $ilDB.
static deleteByObjId($a_obj_id)
Delete by obj id @global ilDB $ilDB.
static deleteByRefId($a_ref_id)
Delete by ref_id @global ilDB $ilDB.
static lookupTemplateId($a_ref_id)
Lookup template id @global ilDB $ilDB.
static _deleteByObjId($a_obj_id)
Delete by obj_id.
static _deleteByObjId($a_obj_id)
static getLogger($a_component_id)
Get component logger.
static _appendNumberOfCopyToFilename($a_file_name, $nth_copy=null, $a_handle_extension=false)
Appends the text " - Copy" to a filename in the language of the current user.
static deleteAllEntries($a_ref_id)
Delete all db entries for ref id.
static add(ilObject $a_object)
Class ilObjectFactory.
static lookupTxtById($plugin_id, $lang_var)
Class ilObject Basic functions for all objects.
static _lookupOwnerName($a_owner_id)
lookup owner name for owner id
static getDeletionDependencies($a_obj_id)
Get deletion dependencies.
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
getType()
get object type @access public
getDiskUsage()
Gets the disk usage of the object in bytes.
getOwner()
get object owner
setParentRolePermissions($a_parent_ref)
Initialize the permissions of parent roles (local roles of categories, global roles....
static hasAutoRating($a_type, $a_ref_id)
Check if auto rating is active for parent group/course.
static _lookupObjId($a_id)
createReference()
creates reference for object
setRefId($a_id)
set reference id @access public
setId($a_id)
set object id @access public
const TITLE_LENGTH
max length of object title
MDUpdateListener($a_element)
Meta data update listener.
static setDeletedDates($a_ref_ids)
Set deleted date @global type $ilDB.
update()
update object in db
static _resetDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
static _lookupImportId($a_obj_id)
static getAllOwnedRepositoryObjects($a_user_id)
Get all ids of objects user owns.
getPossibleSubObjects($a_filter=true)
get all possible subobjects of this type the object can decide which types of subobjects are possible...
static _lookupTitle($a_id)
lookup object title
initDefaultRoles()
init default roles settings Purpose of this function is to create a local role folder and local roles...
cloneDependencies($a_target_id, $a_copy_id)
Clone object dependencies.
updateOwner()
update owner of object in db
setType($a_type)
set object type @access public
static fixMissingTitles($a_type, array &$a_obj_title_map)
Try to fix missing object titles.
static _lookupObjectId($a_ref_id)
lookup object id
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
setTitle($a_title)
set object title
setRegisterMode($a_bool)
static _lookupCreationDate($a_id)
Lookup creation date.
deleteMetaData()
delete meta data entry
getLastUpdateDate()
get last update date @access public
static _lookupDescription($a_id)
lookup object description
updateMetaData()
update meta data entry
isUserRegistered($a_user_id=0)
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
setDescription($a_desc)
set object description
createMetaData()
create meta data entry
setPermissions($a_parent_ref)
set permissions of object
withReferences()
determines wehter objects are referenced or not (got ref ids or not)
getRefId()
get reference id @access public
static _setDeletedDate($a_ref_id)
only called in ilTree::saveSubTree
setOwner($a_owner)
set object owner
appendCopyInfo($a_target_id, $a_copy_id)
Prepend Copy info if object with same name exists in that container.
getLongDescription()
get object long description (stored in object_description)
static _getAllReferences($a_id)
get all reference ids of object
getDescription()
get object description
cloneMetaData($target_obj)
Copy meta data.
create()
create
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static _getLastUpdateOfObjects($a_objs)
Get last update for a set of media objects.
getId()
get object id @access public
getUntranslatedTitle()
get untranslated object title @access public
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
static _writeTitle($a_obj_id, $a_title)
write title to db (static)
setImportId($a_import_id)
set import id
static _lookupObjIdByImportId($a_import_id)
static _prepareCloneSelection($a_ref_ids, $new_type, $show_path=true)
Prepare copy wizard object selection.
putInTree($a_parent_ref)
maybe this method should be in tree object!?
read()
read object data from db into object
static collectDeletionDependencies(&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth=0)
Collect deletion dependencies.
const DESC_LENGTH
static _getObjectsDataForType($a_type, $a_omit_trash=false)
get all objects of a certain type
__construct($a_id=0, $a_reference=true)
Constructor @access public.
applyDidacticTemplate($a_tpl_id)
Apply template.
static _lookupDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
static getLongDescriptions(array $a_obj_ids)
Get long description data.
static _lookupLastUpdate($a_id, $a_as_string=false)
lookup last update
static _lookupOwner($a_id)
lookup object owner
static _isInTrash($a_ref_id)
checks wether object is in trash
static _lookupType($a_id, $a_reference=false)
lookup object type
static _writeDescription($a_obj_id, $a_desc)
write description to db (static)
static _getIdsForTitle($title, $type='', $partialmatch=false)
getImportId()
get import id
getCreateDate()
get create date @access public
getTitle()
get object title @access public
static _getIdForImportId($a_import_id)
get current object id for import id (static)
countReferences()
count references of object
getPresentationTitle()
get presentation title Normally same as title Overwritten for sessions
static delete($a_ref_id)
static removeItemFromDesktops($a_id)
removes object from all user's desktops @access public
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$action
$r
Definition: example_031.php:79
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
const DEBUG
catch(Exception $e) $message
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:17
$query
global $ilErr
Definition: raiseError.php:16
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92