ILIAS  release_7 Revision v7.30-3-g800a261c036
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
85 private $offline = null;
86
87
88 // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
90 // END WebDAV: WebDAV needs to access the untranslated title of an object
91 public $desc;
92 public $long_desc;
93 public $owner;
96 public $import_id;
97 public $register = false; // registering required for object? set to true to implement a subscription interface
98
105
112
118
123 public $max_desc;
124
129 public $add_dots;
130
131
138 public function __construct($a_id = 0, $a_reference = true)
139 {
140 global $DIC;
141
142
143 $this->ilias = $DIC["ilias"];
144
145 $this->db = $DIC->database();
146 $this->log = $DIC["ilLog"];
147 $this->error = $DIC["ilErr"];
148 $this->tree = $DIC->repositoryTree();
149 $this->app_event_handler = $DIC["ilAppEventHandler"];
150 $objDefinition = $DIC["objDefinition"];
151
152 if (DEBUG) {
153 echo "<br/><font color=\"red\">type(" . $this->type . ") id(" . $a_id . ") referenced(" . $a_reference . ")</font>";
154 }
155
156 if (isset($DIC["lng"])) {
157 $this->lng = $DIC["lng"];
158 }
159 $this->objDefinition = $objDefinition;
160
161 $this->max_title = self::TITLE_LENGTH;
162 $this->max_desc = self::DESC_LENGTH;
163 $this->add_dots = true;
164
165 $this->referenced = $a_reference;
166 $this->call_by_reference = $a_reference;
167
168 if ($a_id == 0) {
169 $this->referenced = false; // newly created objects are never referenced
170 } // they will get referenced if createReference() is called
171
172 if ($this->referenced) {
173 $this->ref_id = $a_id;
174 } else {
175 $this->id = $a_id;
176 }
177 // read object data
178 if ($a_id != 0) {
179 $this->read();
180 }
181 }
182
186 public function withReferences()
187 {
188 // both vars could differ. this method should always return true if one of them is true without changing their status
189 return ($this->call_by_reference) ? true : $this->referenced;
190 }
191
192
198 public function read()
199 {
200 global $DIC;
201
204 $ilLog = $this->log;
206 try {
207 $ilUser = $DIC["ilUser"];
208 } catch (\InvalidArgumentException $e) {
209 }
210
211 if ($this->referenced) {
212 // check reference id
213 if (!isset($this->ref_id)) {
214 $message = "ilObject::read(): No ref_id given! (" . $this->type . ")";
215 $ilErr->raiseError($message, $ilErr->WARNING);
216 }
217
218 // read object data
219
220 $q = "SELECT * FROM object_data, object_reference WHERE object_data.obj_id=object_reference.obj_id " .
221 "AND object_reference.ref_id= " . $ilDB->quote($this->ref_id, "integer");
222 $object_set = $ilDB->query($q);
223
224 // check number of records
225 if ($ilDB->numRows($object_set) == 0) {
226 $message = "ilObject::read(): Object with ref_id " . $this->ref_id . " not found! (" . $this->type . ")";
227 $ilErr->raiseError($message, $ilErr->WARNING);
228 }
229
230 $obj = $ilDB->fetchAssoc($object_set);
231 } else {
232 // check object id
233 if (!isset($this->id)) {
234 $message = "ilObject::read(): No obj_id given! (" . $this->type . ")";
235 $ilErr->raiseError($message, $ilErr->WARNING);
236 }
237
238 // read object data
239 $q = "SELECT * FROM object_data " .
240 "WHERE obj_id = " . $ilDB->quote($this->id, "integer");
241 $object_set = $ilDB->query($q);
242
243 // check number of records
244 if ($ilDB->numRows($object_set) == 0) {
245 include_once("./Services/Object/exceptions/class.ilObjectNotFoundException.php");
246 throw new ilObjectNotFoundException("ilObject::read(): Object with obj_id: " . $this->id .
247 " (" . $this->type . ") not found!");
248 return;
249 }
250
251 $obj = $ilDB->fetchAssoc($object_set);
252 }
253
254 $this->id = $obj["obj_id"];
255
256 // check type match (the "xxx" type is used for the unit test)
257 if ($this->type != $obj["type"] && $obj["type"] != "xxx") {
258 $message = "ilObject::read(): Type mismatch. Object with obj_id: " . $this->id . " " .
259 "was instantiated by type '" . $this->type . "'. DB type is: " . $obj["type"];
260
261 // write log entry
262 $ilLog->write($message);
263
264 // raise error
265 include_once("./Services/Object/exceptions/class.ilObjectTypeMismatchException.php");
267 return;
268 }
269
270 $this->type = $obj["type"];
271 $this->title = $obj["title"];
272 // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
273 $this->untranslatedTitle = $obj["title"];
274 // END WebDAV: WebDAV needs to access the untranslated title of an object
275 $this->desc = $obj["description"];
276 $this->owner = $obj["owner"];
277 $this->create_date = $obj["create_date"];
278 $this->last_update = $obj["last_update"];
279 $this->import_id = $obj["import_id"];
280
281 $this->setOfflineStatus($obj['offline']);
282
283 if ($objDefinition->isRBACObject($this->getType())) {
284 // Read long description
285 $query = "SELECT * FROM object_description WHERE obj_id = " . $ilDB->quote($this->id, 'integer');
286 $res = $ilDB->query($query);
287 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
288 if (strlen($row->description)) {
289 $this->setDescription($row->description);
290 }
291 }
292 }
293
294 // multilingual support systemobjects (sys) & categories (db)
295 $translation_type = $objDefinition->getTranslationType($this->type);
296
297 if ($translation_type == "sys") {
298 $this->title = $this->lng->txt("obj_" . $this->type);
299 $this->setDescription($this->lng->txt("obj_" . $this->type . "_desc"));
300 } elseif ($translation_type == "db") {
301 $q = "SELECT title,description FROM object_translation " .
302 "WHERE obj_id = " . $ilDB->quote($this->id, 'integer') . " " .
303 "AND lang_code = " . $ilDB->quote($ilUser->getCurrentLanguage(), 'text');
304 $r = $ilDB->query($q);
305 $row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
306 if ($row) {
307 $this->title = $row->title;
308 $this->setDescription($row->description);
309 #$this->desc = $row->description;
310 }
311 }
312 }
313
319 public function getId() : int
320 {
321 return (int) $this->id;
322 }
323
329 public function setId($a_id)
330 {
331 $this->id = (int) $a_id;
332 }
333
339 public function setRefId($a_id)
340 {
341 $this->ref_id = $a_id;
342 $this->referenced = true;
343 }
344
350 public function getRefId()
351 {
352 return $this->ref_id;
353 }
354
360 public function getType()
361 {
362 return $this->type;
363 }
364
370 public function setType($a_type)
371 {
372 $this->type = $a_type;
373 }
374
384 public function getPresentationTitle()
385 {
386 return $this->getTitle();
387 }
388
389
395 public function getTitle()
396 {
397 return $this->title;
398 }
399 // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
405 public function getUntranslatedTitle()
406 {
408 }
409 // END WebDAV: WebDAV needs to access the untranslated title of an object
410
417 public function setTitle($a_title)
418 {
419 $this->title = ilUtil::shortenText($a_title, $this->max_title, $this->add_dots);
420 // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
421 $this->untranslatedTitle = $this->title;
422 // END WebDAV: WebDAV needs to access the untranslated title of an object
423 }
424
431 public function getDescription()
432 {
433 return $this->desc ?? '';
434 }
435
442 public function setDescription($a_desc)
443 {
444 // Shortened form is storted in object_data. Long form is stored in object_description
445 $this->desc = ilUtil::shortenText($a_desc, $this->max_desc, $this->add_dots);
446
447 $this->long_desc = $a_desc;
448
449 return true;
450 }
451
458 public function getLongDescription()
459 {
460 if (strlen($this->long_desc)) {
461 return $this->long_desc;
462 }
463
464 return $this->getDescription();
465 }
466
473 public function getImportId()
474 {
475 return $this->import_id;
476 }
477
484 public function setImportId($a_import_id)
485 {
486 $this->import_id = $a_import_id;
487 }
488
489 public static function _lookupObjIdByImportId($a_import_id)
490 {
491 global $DIC;
492
493 $ilDB = $DIC->database();
494
495 $query = "SELECT * FROM object_data " .
496 "WHERE import_id = " . $ilDB->quote($a_import_id, "text") . " " .
497 "ORDER BY create_date DESC";
498 $res = $ilDB->query($query);
499 while ($row = $ilDB->fetchObject($res)) {
500 return $row->obj_id;
501 }
502 return 0;
503 }
504
509 public function setOfflineStatus($a_status)
510 {
511 $this->offline = $a_status;
512 }
513
518 public function getOfflineStatus()
519 {
520 return $this->offline;
521 }
522
527 public function supportsOfflineHandling()
528 {
529 global $DIC;
530
531 return (bool) $DIC['objDefinition']->supportsOfflineHandling($this->getType());
532 }
533
534
535
536
537 public static function _lookupImportId($a_obj_id)
538 {
539 global $DIC;
540
541 $ilDB = $DIC->database();
542
543 $query = "SELECT import_id FROM object_data " .
544 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
545 $res = $ilDB->query($query);
546 $row = $ilDB->fetchObject($res);
547 return $row->import_id;
548 }
549
556 public function getOwner()
557 {
558 return $this->owner;
559 }
560
561 /*
562 * get full name of object owner
563 *
564 * @access public
565 * @return string owner name or unknown
566 */
567 public function getOwnerName()
568 {
569 return ilObject::_lookupOwnerName($this->getOwner());
570 }
571
575 public static function _lookupOwnerName($a_owner_id)
576 {
577 global $DIC;
578
579 $lng = $DIC->language();
580
581 if ($a_owner_id != -1) {
582 if (ilObject::_exists($a_owner_id)) {
583 $owner = new ilObjUser($a_owner_id);
584 }
585 }
586
587 if (is_object($owner)) {
588 $own_name = $owner->getFullname();
589 } else {
590 $own_name = $lng->txt("unknown");
591 }
592
593 return $own_name;
594 }
595
602 public function setOwner($a_owner)
603 {
604 $this->owner = $a_owner;
605 }
606
607
608
614 public function getCreateDate()
615 {
616 return $this->create_date;
617 }
618
624 public function getLastUpdateDate()
625 {
626 return $this->last_update;
627 }
628
629
641 public function getDiskUsage()
642 {
643 return null;
644 }
645
654 public function create()
655 {
656 global $DIC;
657
658 $app_event = $DIC->event();
660 $ilLog = $this->log;
661 $ilUser = $DIC["ilUser"];
664
665 if (!isset($this->type)) {
666 $message = get_class($this) . "::create(): No object type given!";
667 $ilErr->raiseError($message, $ilErr->WARNING);
668 }
669
670 // write log entry
671 $ilLog->write("ilObject::create(), start");
672
673 $this->title = ilUtil::shortenText($this->getTitle(), $this->max_title, $this->add_dots);
674 $this->desc = ilUtil::shortenText($this->getDescription(), $this->max_desc, $this->add_dots);
675
676 // determine owner
677 if ($this->getOwner() > 0) {
678 $owner = $this->getOwner();
679 } elseif (is_object($ilUser)) {
680 $owner = $ilUser->getId();
681 } else {
682 $owner = 0;
683 }
684 $this->id = $ilDB->nextId("object_data");
685 $q = "INSERT INTO object_data " .
686 "(obj_id,type,title,description,offline,owner,create_date,last_update,import_id) " .
687 "VALUES " .
688 "(" .
689 $ilDB->quote($this->id, "integer") . "," .
690 $ilDB->quote($this->type, "text") . "," .
691 $ilDB->quote($this->getTitle(), "text") . "," .
692 $ilDB->quote($this->getDescription(), "text") . "," .
693 $ilDB->quote($this->supportsOfflineHandling() ? $this->getOfflineStatus() : null, 'integer') . ', ' .
694 $ilDB->quote($owner, "integer") . "," .
695 $ilDB->now() . "," .
696 $ilDB->now() . "," .
697 $ilDB->quote($this->getImportId(), "text") . ")";
698
699 $ilDB->manipulate($q);
700
701
702 // Save long form of description if is rbac object
703 if ($objDefinition->isRBACObject($this->getType())) {
704 $values = array(
705 'obj_id' => array('integer',$this->id),
706 'description' => array('clob', $this->getLongDescription()));
707 $ilDB->insert('object_description', $values);
708 }
709
710 if ($objDefinition->isOrgUnitPermissionType($this->type)) {
711 ilOrgUnitGlobalSettings::getInstance()->saveDefaultPositionActivationStatus($this->id);
712 }
713
714 // the line ($this->read();) messes up meta data handling: meta data,
715 // that is not saved at this time, gets lost, so we query for the dates alone
716 //$this->read();
717 $q = "SELECT last_update, create_date FROM object_data" .
718 " WHERE obj_id = " . $ilDB->quote($this->id, "integer");
719 $obj_set = $ilDB->query($q);
720 $obj_rec = $ilDB->fetchAssoc($obj_set);
721 $this->last_update = $obj_rec["last_update"];
722 $this->create_date = $obj_rec["create_date"];
723
724 // set owner for new objects
725 $this->setOwner($owner);
726
727 // write log entry
728 $ilLog->write("ilObject::create(), finished, obj_id: " . $this->id . ", type: " .
729 $this->type . ", title: " . $this->getTitle());
730
731 $app_event->raise(
732 'Services/Object',
733 'create',
734 array('obj_id' => $this->id,'obj_type' => $this->type)
735 );
736
737 return $this->id;
738 }
739
746 public function update()
747 {
748 global $DIC;
749
750 $app_event = $DIC->event();
751
754
755 $q = "UPDATE object_data " .
756 "SET " .
757 "title = " . $ilDB->quote($this->getTitle(), "text") . "," .
758 "description = " . $ilDB->quote($this->getDescription(), "text") . ", " .
759 'offline = ' . $ilDB->quote($this->supportsOfflineHandling() ? $this->getOfflineStatus() : null, 'integer') . ', ' .
760 "import_id = " . $ilDB->quote($this->getImportId(), "text") . "," .
761 "last_update = " . $ilDB->now() . " " .
762 "WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
763 $ilDB->manipulate($q);
764
765 // the line ($this->read();) messes up meta data handling: meta data,
766 // that is not saved at this time, gets lost, so we query for the dates alone
767 //$this->read();
768 $q = "SELECT last_update FROM object_data" .
769 " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
770 $obj_set = $ilDB->query($q);
771 $obj_rec = $ilDB->fetchAssoc($obj_set);
772 $this->last_update = $obj_rec["last_update"];
773
774 if ($objDefinition->isRBACObject($this->getType())) {
775 // Update long description
776 $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = " .
777 $ilDB->quote($this->getId(), 'integer'));
778 if ($res->numRows()) {
779 $values = array(
780 'description' => array('clob',$this->getLongDescription())
781 );
782 $ilDB->update('object_description', $values, array('obj_id' => array('integer',$this->getId())));
783 } else {
784 $values = array(
785 'description' => array('clob',$this->getLongDescription()),
786 'obj_id' => array('integer',$this->getId()));
787 $ilDB->insert('object_description', $values);
788 }
789 }
790 $app_event->raise(
791 'Services/Object',
792 'update',
793 array('obj_id' => $this->getId(),
794 'obj_type' => $this->getType(),
795 'ref_id' => $this->getRefId())
796 );
797
798 return true;
799 }
800
812 public function MDUpdateListener($a_element)
813 {
814 global $DIC;
815
816 $app_event = $DIC->event();
817
818 include_once 'Services/MetaData/classes/class.ilMD.php';
819
820 $app_event->raise(
821 'Services/Object',
822 'update',
823 array('obj_id' => $this->getId(),
824 'obj_type' => $this->getType(),
825 'ref_id' => $this->getRefId())
826 );
827
828 switch ($a_element) {
829 case 'General':
830
831 // Update Title and description
832 $md = new ilMD($this->getId(), 0, $this->getType());
833 if (!is_object($md_gen = $md->getGeneral())) {
834 return false;
835 }
836 $this->setTitle($md_gen->getTitle());
837
838 foreach ($md_gen->getDescriptionIds() as $id) {
839 $md_des = $md_gen->getDescription($id);
840 $this->setDescription($md_des->getDescription());
841 break;
842 }
843 $this->update();
844 break;
845
846 default:
847 }
848
849 return true;
850 }
851
855 public function createMetaData()
856 {
857 global $DIC;
858
859 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
860
861 $ilUser = $DIC["ilUser"];
862
863 $md_creator = new ilMDCreator($this->getId(), 0, $this->getType());
864 $md_creator->setTitle($this->getTitle());
865 $md_creator->setTitleLanguage($ilUser->getPref('language'));
866 $md_creator->setDescription($this->getLongDescription());
867 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
868 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
869 $md_creator->setLanguage($ilUser->getPref('language'));
870 $md_creator->create();
871
872 return true;
873 }
874
878 public function updateMetaData()
879 {
880 $md = new ilMD($this->getId(), 0, $this->getType());
881 $md_gen = $md->getGeneral();
882 // BEGIN WebDAV: meta data can be missing sometimes.
883 if (!$md_gen instanceof ilMDGeneral) {
884 $this->createMetaData();
885 $md = new ilMD($this->getId(), 0, $this->getType());
886 $md_gen = $md->getGeneral();
887 }
888 // END WebDAV: meta data can be missing sometimes.
889 $md_gen->setTitle($this->getTitle());
890
891 // sets first description (maybe not appropriate)
892 $md_des_ids = $md_gen->getDescriptionIds();
893 if (count($md_des_ids) > 0) {
894 $md_des = $md_gen->getDescription($md_des_ids[0]);
895 $md_des->setDescription($this->getLongDescription());
896 $md_des->update();
897 }
898 $md_gen->update();
899 }
900
904 public function deleteMetaData()
905 {
906 // Delete meta data
907 include_once('Services/MetaData/classes/class.ilMD.php');
908 $md = new ilMD($this->getId(), 0, $this->getType());
909 $md->deleteAll();
910 }
911
918 public function updateOwner()
919 {
921
922 $q = "UPDATE object_data " .
923 "SET " .
924 "owner = " . $ilDB->quote($this->getOwner(), "integer") . ", " .
925 "last_update = " . $ilDB->now() . " " .
926 "WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
927 $ilDB->manipulate($q);
928
929 $q = "SELECT last_update FROM object_data" .
930 " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
931 $obj_set = $ilDB->query($q);
932 $obj_rec = $ilDB->fetchAssoc($obj_set);
933 $this->last_update = $obj_rec["last_update"];
934
935 return true;
936 }
937
945 public static function _getIdForImportId($a_import_id)
946 {
947 global $DIC;
948
949 $ilDB = $DIC->database();
950
951 $ilDB->setLimit(1, 0);
952 $q = "SELECT * FROM object_data WHERE import_id = " . $ilDB->quote($a_import_id, "text") .
953 " ORDER BY create_date DESC";
954 $obj_set = $ilDB->query($q);
955
956 if ($obj_rec = $ilDB->fetchAssoc($obj_set)) {
957 return $obj_rec["obj_id"];
958 } else {
959 return 0;
960 }
961 }
962
968 public static function _getAllReferences($a_id)
969 {
970 global $DIC;
971
972 $ilDB = $DIC->database();
973
974 $query = "SELECT * FROM object_reference WHERE obj_id = " .
975 $ilDB->quote($a_id, 'integer');
976
977 $res = $ilDB->query($query);
978 $ref = array();
979 while ($obj_rec = $ilDB->fetchAssoc($res)) {
980 $ref[$obj_rec["ref_id"]] = $obj_rec["ref_id"];
981 }
982
983 return $ref;
984 }
985
991 public static function _lookupTitle($a_id)
992 {
993 global $DIC;
994
995 $ilObjDataCache = $DIC["ilObjDataCache"];
996
997 $tit = $ilObjDataCache->lookupTitle($a_id);
998 //echo "<br>LOOKING-$a_id-:$tit";
999 return $tit;
1000 }
1001
1009 public static function lookupOfflineStatus($a_obj_id)
1010 {
1011 global $DIC;
1012
1013 return $DIC['ilObjDataCache']->lookupOfflineStatus($a_obj_id);
1014 }
1015
1016
1017
1023 public static function _lookupOwner($a_id)
1024 {
1025 global $DIC;
1026
1027 $ilObjDataCache = $DIC["ilObjDataCache"];
1028
1029 $owner = $ilObjDataCache->lookupOwner($a_id);
1030 return $owner;
1031 }
1032
1033 public static function _getIdsForTitle($title, $type = '', $partialmatch = false)
1034 {
1035 global $DIC;
1036
1037 $ilDB = $DIC->database();
1038
1039 $query = (!$partialmatch)
1040 ? "SELECT obj_id FROM object_data WHERE title = " . $ilDB->quote($title, "text")
1041 : "SELECT obj_id FROM object_data WHERE " . $ilDB->like("title", "text", '%' . $title . '%');
1042 if ($type != '') {
1043 $query .= " AND type = " . $ilDB->quote($type, "text");
1044 }
1045
1046 $result = $ilDB->query($query);
1047
1048 $object_ids = array();
1049 while ($row = $ilDB->fetchAssoc($result)) {
1050 $object_ids[] = $row['obj_id'];
1051 }
1052
1053 return is_array($object_ids) ? $object_ids : array();
1054 }
1055
1061 public static function _lookupDescription($a_id)
1062 {
1063 global $DIC;
1064
1065 $ilObjDataCache = $DIC["ilObjDataCache"];
1066
1067 return $ilObjDataCache->lookupDescription($a_id);
1068 }
1069
1075 public static function _lookupLastUpdate($a_id, $a_as_string = false)
1076 {
1077 global $DIC;
1078
1079 $ilObjDataCache = $DIC["ilObjDataCache"];
1080
1081 if ($a_as_string) {
1082 return ilDatePresentation::formatDate(new ilDateTime($ilObjDataCache->lookupLastUpdate($a_id), IL_CAL_DATETIME));
1083 } else {
1084 return $ilObjDataCache->lookupLastUpdate($a_id);
1085 }
1086 }
1087
1093 public static function _getLastUpdateOfObjects($a_objs)
1094 {
1095 global $DIC;
1096
1097 $ilDB = $DIC->database();
1098
1099 if (!is_array($a_objs)) {
1100 $a_objs = array($a_objs);
1101 }
1102 $types = array();
1103 $set = $ilDB->query("SELECT max(last_update) as last_update FROM object_data " .
1104 "WHERE " . $ilDB->in("obj_id", $a_objs, false, "integer") . " ");
1105 $rec = $ilDB->fetchAssoc($set);
1106
1107 return ($rec["last_update"]);
1108 }
1109
1110 public static function _lookupObjId($a_id)
1111 {
1112 global $DIC;
1113
1114 $ilObjDataCache = $DIC["ilObjDataCache"];
1115
1116 return (int) $ilObjDataCache->lookupObjId($a_id);
1117 }
1118
1123 public static function _setDeletedDate($a_ref_id, $a_deleted_by)
1124 {
1125 global $DIC;
1126
1127 $ilDB = $DIC->database();
1128 $query = "UPDATE object_reference SET " .
1129 'deleted = ' . $ilDB->now() . ', ' .
1130 'deleted_by = ' . $ilDB->quote($a_deleted_by, \ilDBConstants::T_INTEGER) . ' ' .
1131 "WHERE ref_id = " . $ilDB->quote($a_ref_id, 'integer');
1132 $res = $ilDB->manipulate($query);
1133 }
1134
1141 public static function setDeletedDates($a_ref_ids, $a_user_id)
1142 {
1143 global $DIC;
1144
1145 $ilDB = $DIC->database();
1146
1147 $query = 'UPDATE object_reference SET ' .
1148 'deleted = ' . $ilDB->now() . ', ' .
1149 'deleted_by = ' . $ilDB->quote($a_user_id, ilDBConstants::T_INTEGER) . ' ' .
1150 'WHERE ' . $ilDB->in('ref_id', (array) $a_ref_ids, false, ilDBConstants::T_INTEGER);
1151 $ilDB->manipulate($query);
1152 return;
1153 }
1154
1158 public static function _resetDeletedDate($a_ref_id)
1159 {
1160 global $DIC;
1161
1162 $ilDB = $DIC->database();
1163
1164 $query = "UPDATE object_reference SET deleted = " . $ilDB->quote(null, 'timestamp') . ', ' .
1165 'deleted_by = ' . $ilDB->quote(0, \ilDBConstants::T_INTEGER) . ' ' .
1166 " WHERE ref_id = " . $ilDB->quote($a_ref_id, 'integer');
1167 $ilDB->manipulate($query);
1168 }
1169
1173 public static function _lookupDeletedDate($a_ref_id)
1174 {
1175 global $DIC;
1176
1177 $ilDB = $DIC->database();
1178
1179 $query = "SELECT deleted FROM object_reference" .
1180 " WHERE ref_id = " . $ilDB->quote($a_ref_id, "integer");
1181 $set = $ilDB->query($query);
1182 $rec = $ilDB->fetchAssoc($set);
1183
1184 return $rec["deleted"];
1185 }
1186
1187
1195 public static function _writeTitle($a_obj_id, $a_title)
1196 {
1197 global $DIC;
1198
1199 $ilDB = $DIC->database();
1200
1201 $q = "UPDATE object_data " .
1202 "SET " .
1203 "title = " . $ilDB->quote($a_title, "text") . "," .
1204 "last_update = " . $ilDB->now() . " " .
1205 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
1206
1207 $ilDB->manipulate($q);
1208 }
1209
1217 public static function _writeDescription($a_obj_id, $a_desc)
1218 {
1219 global $DIC;
1220
1221 $ilDB = $DIC->database();
1222 $objDefinition = $DIC["objDefinition"];
1223
1224
1225 $desc = ilUtil::shortenText($a_desc, self::DESC_LENGTH, true);
1226
1227 $q = "UPDATE object_data " .
1228 "SET " .
1229 "description = " . $ilDB->quote($desc, "text") . "," .
1230 "last_update = " . $ilDB->now() . " " .
1231 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
1232
1233 $ilDB->manipulate($q);
1234
1235 if ($objDefinition->isRBACObject(ilObject::_lookupType($a_obj_id))) {
1236 // Update long description
1237 $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = " .
1238 $ilDB->quote($a_obj_id, 'integer'));
1239
1240 if ($res->numRows()) {
1241 $values = array(
1242 'description' => array('clob',$a_desc)
1243 );
1244 $ilDB->update('object_description', $values, array('obj_id' => array('integer',$a_obj_id)));
1245 } else {
1246 $values = array(
1247 'description' => array('clob',$a_desc),
1248 'obj_id' => array('integer',$a_obj_id));
1249 $ilDB->insert('object_description', $values);
1250 }
1251 }
1252 }
1253
1261 public static function _writeImportId($a_obj_id, $a_import_id)
1262 {
1263 global $DIC;
1264
1265 $ilDB = $DIC->database();
1266
1267 $q = "UPDATE object_data " .
1268 "SET " .
1269 "import_id = " . $ilDB->quote($a_import_id, "text") . "," .
1270 "last_update = " . $ilDB->now() . " " .
1271 "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
1272
1273 $ilDB->manipulate($q);
1274 }
1275
1281 public static function _lookupType($a_id, $a_reference = false)
1282 {
1283 global $DIC;
1284
1285 $ilObjDataCache = $DIC["ilObjDataCache"];
1286
1287 if ($a_reference) {
1288 return $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_id));
1289 }
1290 return $ilObjDataCache->lookupType($a_id);
1291 }
1292
1296 public static function _isInTrash($a_ref_id)
1297 {
1298 global $DIC;
1299
1300 $tree = $DIC->repositoryTree();
1301
1302 return $tree->isSaved($a_ref_id);
1303 }
1304
1308 public static function _hasUntrashedReference($a_obj_id)
1309 {
1310 $ref_ids = ilObject::_getAllReferences($a_obj_id);
1311 foreach ($ref_ids as $ref_id) {
1313 return true;
1314 }
1315 }
1316
1317 return false;
1318 }
1319
1325 public static function _lookupObjectId($a_ref_id)
1326 {
1327 global $DIC;
1328
1329 $ilObjDataCache = $DIC["ilObjDataCache"];
1330
1331 return (int) $ilObjDataCache->lookupObjId($a_ref_id);
1332 }
1333
1344 public static function _getObjectsDataForType($a_type, $a_omit_trash = false)
1345 {
1346 global $DIC;
1347
1348 $ilDB = $DIC->database();
1349
1350 $q = "SELECT * FROM object_data WHERE type = " . $ilDB->quote($a_type, "text");
1351 $obj_set = $ilDB->query($q);
1352
1353 $objects = array();
1354 while ($obj_rec = $ilDB->fetchAssoc($obj_set)) {
1355 if ((!$a_omit_trash) || ilObject::_hasUntrashedReference($obj_rec["obj_id"])) {
1356 $objects[$obj_rec["title"] . "." . $obj_rec["obj_id"]] = array("id" => $obj_rec["obj_id"],
1357 "type" => $obj_rec["type"], "title" => $obj_rec["title"],
1358 "description" => $obj_rec["description"]);
1359 }
1360 }
1361 ksort($objects);
1362 return $objects;
1363 }
1364
1365
1373 public function putInTree($a_parent_ref)
1374 {
1376 $ilLog = $this->log;
1377 $ilAppEventHandler = $this->app_event_handler;
1378
1379 $tree->insertNode($this->getRefId(), $a_parent_ref);
1380
1381 // write log entry
1382 $ilLog->write("ilObject::putInTree(), parent_ref: $a_parent_ref, ref_id: " .
1383 $this->getRefId() . ", obj_id: " . $this->getId() . ", type: " .
1384 $this->getType() . ", title: " . $this->getTitle());
1385
1386 $ilAppEventHandler->raise(
1387 'Services/Object',
1388 'putObjectInTree',
1389 array(
1390 'object' => $this,
1391 'obj_type' => $this->getType(),
1392 'obj_id' => $this->getId(),
1393 'parent_ref_id' => $a_parent_ref,
1394 )
1395 );
1396 }
1397
1404 public function setPermissions($a_parent_ref)
1405 {
1406 $this->setParentRolePermissions($a_parent_ref);
1407 $this->initDefaultRoles();
1408 }
1409
1414 public function setParentRolePermissions($a_parent_ref)
1415 {
1416 global $DIC;
1417
1418 $rbacadmin = $DIC["rbacadmin"];
1419 $rbacreview = $DIC["rbacreview"];
1420
1421 $parent_roles = $rbacreview->getParentRoleIds($a_parent_ref);
1422 foreach ((array) $parent_roles as $parent_role) {
1423 $operations = $rbacreview->getOperationsOfRole(
1424 $parent_role['obj_id'],
1425 $this->getType(),
1426 $parent_role['parent']
1427 );
1428 $rbacadmin->grantPermission(
1429 $parent_role['obj_id'],
1430 $operations,
1431 $this->getRefId()
1432 );
1433 }
1434 return true;
1435 }
1436
1443 public function createReference()
1444 {
1445 $ilDB = $this->db;
1447
1448 if (!isset($this->id)) {
1449 $message = "ilObject::createNewReference(): No obj_id given!";
1450 $ilErr->raiseError($message, $ilErr->WARNING);
1451 }
1452
1453 $next_id = $ilDB->nextId('object_reference');
1454 $query = "INSERT INTO object_reference " .
1455 "(ref_id, obj_id) VALUES (" . $ilDB->quote($next_id, 'integer') . ',' . $ilDB->quote($this->id, 'integer') . ")";
1456 $ilDB->query($query);
1457
1458 $this->ref_id = $next_id;
1459 $this->referenced = true;
1460
1461 return $this->ref_id;
1462 }
1463
1464
1471 public function countReferences()
1472 {
1473 $ilDB = $this->db;
1475
1476 if (!isset($this->id)) {
1477 $message = "ilObject::countReferences(): No obj_id given!";
1478 $ilErr->raiseError($message, $ilErr->WARNING);
1479 }
1480
1481 $query = "SELECT COUNT(ref_id) num FROM object_reference " .
1482 "WHERE obj_id = " . $ilDB->quote($this->id, 'integer') . " ";
1483 $res = $ilDB->query($query);
1484 $row = $ilDB->fetchObject($res);
1485
1486 return $row->num;
1487 }
1488
1489
1500 public function delete()
1501 {
1502 global $DIC;
1503
1504 $rbacadmin = $DIC["rbacadmin"];
1505 $ilLog = $this->log;
1506 $ilDB = $this->db;
1507 $ilAppEventHandler = $this->app_event_handler;
1509
1510 $remove = false;
1511
1512 // delete object_data entry
1513 if ((!$this->referenced) || ($this->countReferences() == 1)) {
1514 // check type match
1515 $db_type = ilObject::_lookupType($this->getId());
1516 if ($this->type != $db_type) {
1517 $message = "ilObject::delete(): Type mismatch. Object with obj_id: " . $this->id . " " .
1518 "was instantiated by type '" . $this->type . "'. DB type is: " . $db_type;
1519
1520 // write log entry
1521 $ilLog->write($message);
1522
1523 // raise error
1524 $ilErr->raiseError("ilObject::delete(): Type mismatch. (" . $this->type . "/" . $this->id . ")", $ilErr->WARNING);
1525 }
1526
1527 $ilAppEventHandler->raise('Services/Object', 'beforeDeletion', array( 'object' => $this ));
1528
1529 // delete entry in object_data
1530 $q = "DELETE FROM object_data " .
1531 "WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
1532 $ilDB->manipulate($q);
1533
1534 // delete long description
1535 $query = "DELETE FROM object_description WHERE obj_id = " .
1536 $ilDB->quote($this->getId(), "integer");
1537 $ilDB->manipulate($query);
1538
1539 // write log entry
1540 $ilLog->write("ilObject::delete(), deleted object, obj_id: " . $this->getId() . ", type: " .
1541 $this->getType() . ", title: " . $this->getTitle());
1542
1543 // keep log of core object data
1544 include_once "Services/Object/classes/class.ilObjectDataDeletionLog.php";
1546
1547 // remove news
1548 include_once("./Services/News/classes/class.ilNewsItem.php");
1549 $news_item = new ilNewsItem();
1550 $news_item->deleteNewsOfContext($this->getId(), $this->getType());
1551 include_once("./Services/Block/classes/class.ilBlockSetting.php");
1553
1554 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1556
1557 // BEGIN WebDAV: Delete WebDAV properties
1558 $query = "DELETE FROM dav_property " .
1559 "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
1560 $res = $ilDB->manipulate($query);
1561 // END WebDAV: Delete WebDAV properties
1562
1563 include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
1565
1566 include_once("Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
1568
1569 include_once("Services/Tracking/classes/class.ilLPObjSettings.php");
1571
1572 $remove = true;
1573 } else {
1574 // write log entry
1575 $ilLog->write("ilObject::delete(), object not deleted, number of references: " .
1576 $this->countReferences() . ", obj_id: " . $this->getId() . ", type: " .
1577 $this->getType() . ", title: " . $this->getTitle());
1578 }
1579
1580 // delete object_reference entry
1581 if ($this->referenced) {
1582 include_once "Services/Object/classes/class.ilObjectActivation.php";
1584
1585 $ilAppEventHandler->raise('Services/Object', 'deleteReference', array( 'ref_id' => $this->getRefId()));
1586
1587 // delete entry in object_reference
1588 $query = "DELETE FROM object_reference " .
1589 "WHERE ref_id = " . $ilDB->quote($this->getRefId(), 'integer');
1590 $res = $ilDB->manipulate($query);
1591
1592 // write log entry
1593 $ilLog->write("ilObject::delete(), reference deleted, ref_id: " . $this->getRefId() .
1594 ", obj_id: " . $this->getId() . ", type: " .
1595 $this->getType() . ", title: " . $this->getTitle());
1596
1597 // DELETE PERMISSION ENTRIES IN RBAC_PA
1598 // DONE: method overwritten in ilObjRole & ilObjUser.
1599 // this call only applies for objects in rbac (not usr,role,rolt)
1600 // TODO: Do this for role templates too
1601 $rbacadmin->revokePermission($this->getRefId(), 0, false);
1602
1603 include_once "Services/AccessControl/classes/class.ilRbacLog.php";
1604 ilRbacLog::delete($this->getRefId());
1605
1606 // Remove applied didactic template setting
1607 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1609 }
1610
1611 // remove conditions
1612 if ($this->referenced) {
1613 $ch = new ilConditionHandler();
1614 $ch->delete($this->getRefId());
1615 unset($ch);
1616 }
1617
1618 return $remove;
1619 }
1620
1628 public function initDefaultRoles()
1629 {
1630 return array();
1631 }
1632
1633
1638 public function applyDidacticTemplate($a_tpl_id)
1639 {
1640 ilLoggerFactory::getLogger('obj')->debug('Applying didactic template with id: ' . (int) $a_tpl_id);
1641 if ($a_tpl_id) {
1642 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
1643 foreach (ilDidacticTemplateActionFactory::getActionsByTemplateId($a_tpl_id) as $action) {
1644 $action->setRefId($this->getRefId());
1645 $action->apply();
1646 }
1647 }
1648
1649 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1650 ilDidacticTemplateObjSettings::assignTemplate($this->getRefId(), $this->getId(), (int) $a_tpl_id);
1651 return $a_tpl_id ? true : false;
1652 }
1653
1663 public static function _exists($a_id, $a_reference = false, $a_type = null)
1664 {
1665 global $DIC;
1666
1667 $ilDB = $DIC->database();
1668
1669 if ($a_reference) {
1670 $q = "SELECT * FROM object_data " .
1671 "LEFT JOIN object_reference ON object_reference.obj_id=object_data.obj_id " .
1672 "WHERE object_reference.ref_id= " . $ilDB->quote($a_id, "integer");
1673 } else {
1674 $q = "SELECT * FROM object_data WHERE obj_id=" . $ilDB->quote($a_id, "integer");
1675 }
1676
1677 if ($a_type) {
1678 $q .= " AND object_data.type = " . $ilDB->quote($a_type, "text");
1679 }
1680
1681 $r = $ilDB->query($q);
1682
1683 return $ilDB->numRows($r) ? true : false;
1684 }
1685
1686 // toggle subscription interface
1687 public function setRegisterMode($a_bool)
1688 {
1689 $this->register = (bool) $a_bool;
1690 }
1691
1692 // check register status of current user
1693 // abstract method; overwrite in object type class
1694 public function isUserRegistered($a_user_id = 0)
1695 {
1696 return false;
1697 }
1698
1699 public function requireRegistration()
1700 {
1701 return $this->register;
1702 }
1703
1704
1705 public function getXMLZip()
1706 {
1707 return false;
1708 }
1709 public function getHTMLDirectory()
1710 {
1711 return false;
1712 }
1713
1717 public static function _getObjectsByType($a_obj_type = "", $a_owner = "")
1718 {
1719 global $DIC;
1720
1721 $ilDB = $DIC->database();
1722
1723 $order = " ORDER BY title";
1724
1725 // where clause
1726 if ($a_obj_type) {
1727 $where_clause = "WHERE type = " .
1728 $ilDB->quote($a_obj_type, "text");
1729
1730 if ($a_owner != "") {
1731 $where_clause .= " AND owner = " . $ilDB->quote($a_owner, "integer");
1732 }
1733 }
1734
1735 $q = "SELECT * FROM object_data " . $where_clause . $order;
1736 $r = $ilDB->query($q);
1737
1738 $arr = array();
1739 if ($ilDB->numRows($r) > 0) {
1740 while ($row = $ilDB->fetchAssoc($r)) {
1741 $row["desc"] = $row["description"];
1742 $arr[$row["obj_id"]] = $row;
1743 }
1744 }
1745
1746 return $arr;
1747 }
1748
1761 public static function _prepareCloneSelection($a_ref_ids, $new_type, $show_path = true)
1762 {
1763 global $DIC;
1764
1765 $ilDB = $DIC->database();
1766 $lng = $DIC->language();
1767 $objDefinition = $DIC["objDefinition"];
1768
1769 $query = "SELECT obj_data.title obj_title,path_data.title path_title,child FROM tree " .
1770 "JOIN object_reference obj_ref ON child = obj_ref.ref_id " .
1771 "JOIN object_data obj_data ON obj_ref.obj_id = obj_data.obj_id " .
1772 "JOIN object_reference path_ref ON parent = path_ref.ref_id " .
1773 "JOIN object_data path_data ON path_ref.obj_id = path_data.obj_id " .
1774 "WHERE " . $ilDB->in("child", $a_ref_ids, false, "integer") . " " .
1775 "ORDER BY obj_data.title ";
1776 $res = $ilDB->query($query);
1777
1778 if (!$objDefinition->isPlugin($new_type)) {
1779 $options[0] = $lng->txt('obj_' . $new_type . '_select');
1780 } else {
1781 require_once("Services/Repository/classes/class.ilObjectPlugin.php");
1782 $options[0] = ilObjectPlugin::lookupTxtById($new_type, "obj_" . $new_type . "_select");
1783 }
1784
1785 while ($row = $ilDB->fetchObject($res)) {
1786 if (strlen($title = $row->obj_title) > 40) {
1787 $title = substr($title, 0, 40) . '...';
1788 }
1789
1790 if ($show_path) {
1791 if (strlen($path = $row->path_title) > 40) {
1792 $path = substr($path, 0, 40) . '...';
1793 }
1794
1795 $title .= ' (' . $lng->txt('path') . ': ' . $path . ')';
1796 }
1797
1798 $options[$row->child] = $title;
1799 }
1800 return $options ? $options : array();
1801 }
1802
1812 public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
1813 {
1814 global $DIC;
1815
1817 $ilUser = $DIC["ilUser"];
1818 $rbacadmin = $DIC["rbacadmin"];
1819 $ilDB = $this->db;
1820 $ilAppEventHandler = $this->app_event_handler;
1825 $location = $objDefinition->getLocation($this->getType());
1826 $class_name = ('ilObj' . $objDefinition->getClassName($this->getType()));
1827
1828 include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1829 $options = ilCopyWizardOptions::_getInstance($a_copy_id);
1830
1831 if (!$options->isTreeCopyDisabled() && !$a_omit_tree) {
1832 $title = $this->appendCopyInfo($a_target_id, $a_copy_id);
1833 } else {
1834 $title = $this->getTitle();
1835 }
1836
1837 // create instance
1838 include_once($location . "/class." . $class_name . ".php");
1839 $new_obj = new $class_name(0, false);
1840 $new_obj->setOwner($ilUser->getId());
1841 $new_obj->setTitle($title);
1842 $new_obj->setDescription($this->getLongDescription());
1843 $new_obj->setType($this->getType());
1844
1845 // Choose upload mode to avoid creation of additional settings, db entries ...
1846 $new_obj->create(true);
1847
1848 if ($this->supportsOfflineHandling()) {
1849 $new_obj->setOffLineStatus($this->getOfflineStatus());
1850 $new_obj->update();
1851 }
1852
1853 if (!$options->isTreeCopyDisabled() && !$a_omit_tree) {
1854 ilLoggerFactory::getLogger('obj')->debug('Tree copy is enabled');
1855 $new_obj->createReference();
1856 $new_obj->putInTree($a_target_id);
1857 $new_obj->setPermissions($a_target_id);
1858
1859 // when copying from personal workspace we have no current ref id
1860 if ($this->getRefId()) {
1861 // copy local roles
1862 $rbacadmin->copyLocalRoles($this->getRefId(), $new_obj->getRefId());
1863 }
1864 } else {
1865 ilLoggerFactory::getLogger('obj')->debug('Tree copy is disabled');
1866 }
1867
1868 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1869 ilAdvancedMDValues::_cloneValues($this->getId(), $new_obj->getId());
1870
1871 // BEGIN WebDAV: Clone WebDAV properties
1872 $query = "INSERT INTO dav_property (obj_id,node_id,ns,name,value) " .
1873 "SELECT " . $ilDB->quote($new_obj->getId(), 'integer') . ",node_id,ns,name,value " .
1874 "FROM dav_property " .
1875 "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
1876 $res = $ilDB->manipulate($query);
1877 // END WebDAV: Clone WebDAV properties
1878
1880 $customIconFactory = $DIC['object.customicons.factory'];
1881 $customIcon = $customIconFactory->getByObjId($this->getId(), $this->getType());
1882 $customIcon->copy($new_obj->getId());
1883
1884 $tile_image = $DIC->object()->commonSettings()->tileImage()->getByObjId($this->getId());
1885 $tile_image->copy($new_obj->getId());
1886
1887 $ilAppEventHandler->raise('Services/Object', 'cloneObject', array(
1888 'object' => $new_obj,
1889 'cloned_from_object' => $this,
1890 ));
1891
1892 return $new_obj;
1893 }
1894
1902 public function appendCopyInfo($a_target_id, $a_copy_id)
1903 {
1905
1906 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
1907 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
1908 if (!$cp_options->isRootNode($this->getRefId())) {
1909 return $this->getTitle();
1910 }
1911 $nodes = $tree->getChilds($a_target_id);
1912
1913 $title_unique = false;
1914 require_once 'Modules/File/classes/class.ilObjFileAccess.php';
1915 $numberOfCopy = 1;
1916 $handleExtension = ($this->getType() == "file"); // #14883
1917 $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), $numberOfCopy, $handleExtension);
1918 while (!$title_unique) {
1919 $found = 0;
1920 foreach ($nodes as $node) {
1921 if (($title == $node['title']) and ($this->getType() == $node['type'])) {
1922 $found++;
1923 }
1924 }
1925 if ($found > 0) {
1926 $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), ++$numberOfCopy, $handleExtension);
1927 } else {
1928 break;
1929 }
1930 }
1931 return $title;
1932 }
1933
1946 public function cloneDependencies($a_target_id, $a_copy_id)
1947 {
1948 include_once './Services/Conditions/classes/class.ilConditionHandler.php' ;
1949 ilConditionHandler::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
1950
1951 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1953 if ($tpl_id) {
1954 include_once './Services/Object/classes/class.ilObjectFactory.php';
1955 $factory = new ilObjectFactory();
1956 $obj = $factory->getInstanceByRefId($a_target_id, false);
1957 if ($obj instanceof ilObject) {
1958 $obj->applyDidacticTemplate($tpl_id);
1959 }
1960 }
1961 return true;
1962 }
1963
1971 public function cloneMetaData($target_obj)
1972 {
1973 $md = new ilMD($this->getId(), 0, $this->getType());
1974 $md->cloneMD($target_obj->getId(), 0, $target_obj->getType());
1975 return true;
1976 }
1977
1986 public static function getIconForReference(
1987 int $a_ref_id,
1988 int $a_obj_id,
1989 string $a_size,
1990 string $a_type = '',
1991 bool $a_offline = false
1992 ) {
1993 global $DIC;
1994
1995 $ilSetting = $DIC->settings();
1996 $objDefinition = $DIC["objDefinition"];
1997
1998 if ($a_obj_id == "" && $a_type == "") {
1999 return "";
2000 }
2001
2002 if ($a_type == "") {
2003 $a_type = ilObject::_lookupType($a_obj_id);
2004 }
2005
2006 if ($a_size == "") {
2007 $a_size = "big";
2008 }
2009
2010 if (
2011 $a_obj_id &&
2012 $ilSetting->get('custom_icons')
2013 ) {
2015 $customIconFactory = $DIC['object.customicons.factory'];
2016 $customIcon = $customIconFactory->getPresenterByObjId((int) $a_obj_id, (string) $a_type);
2017 if ($customIcon->exists()) {
2018 $filename = $customIcon->getFullPath();
2019 return $filename . '?tmp=' . filemtime($filename);
2020 }
2021 }
2022 if ($a_obj_id) {
2023 $dtpl_icon_factory = ilDidacticTemplateIconFactory::getInstance();
2024 if ($a_ref_id) {
2025 $path = $dtpl_icon_factory->getIconPathForReference((int) $a_ref_id);
2026 } else {
2027 $path = $dtpl_icon_factory->getIconPathForObject((int) $a_obj_id);
2028 }
2029 if ($path) {
2030 return $path . '?tmp=' . filemtime($path);
2031 }
2032 }
2033
2034 if (!$a_offline) {
2035 if ($objDefinition->isPluginTypeName($a_type)) {
2036 if ($objDefinition->getClassName($a_type) != "") {
2037 $class_name = "il" . $objDefinition->getClassName($a_type) . 'Plugin';
2038 $location = $objDefinition->getLocation($a_type);
2039 if (is_file($location . "/class." . $class_name . ".php")) {
2040 include_once($location . "/class." . $class_name . ".php");
2041 return call_user_func(array($class_name, "_getIcon"), $a_type, $a_size, $a_obj_id);
2042 }
2043 }
2044 return ilUtil::getImagePath("icon_cmps.svg");
2045 }
2046
2047 return ilUtil::getImagePath("icon_" . $a_type . ".svg");
2048 } else {
2049 return "./images/icon_" . $a_type . ".svg";
2050 }
2051 }
2052
2061 public static function _getIcon(
2062 $a_obj_id = "",
2063 $a_size = "big",
2064 $a_type = "",
2065 $a_offline = false
2066 ) {
2067 return self::getIconForReference(
2068 0,
2069 (int) $a_obj_id,
2070 (string) $a_size,
2071 (string) $a_type,
2072 (bool) $a_offline
2073 );
2074 }
2075
2082 public static function collectDeletionDependencies(&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth = 0)
2083 {
2084 global $DIC;
2085
2086 $objDefinition = $DIC["objDefinition"];
2087 $tree = $DIC->repositoryTree();
2088
2089 if ($a_depth == 0) {
2090 $deps["dep"] = array();
2091 }
2092
2093 $deps["del_ids"][$a_obj_id] = $a_obj_id;
2094
2095 if (!$objDefinition->isPluginTypeName($a_type)) {
2096 $class_name = "ilObj" . $objDefinition->getClassName($a_type);
2097 $location = $objDefinition->getLocation($a_type);
2098 include_once($location . "/class." . $class_name . ".php");
2099 $odeps = call_user_func(array($class_name, "getDeletionDependencies"), $a_obj_id);
2100 if (is_array($odeps)) {
2101 foreach ($odeps as $id => $message) {
2102 $deps["dep"][$id][$a_obj_id][] = $message;
2103 }
2104 }
2105
2106 // get deletion dependency of childs
2107 foreach ($tree->getChilds($a_ref_id) as $c) {
2108 ilObject::collectDeletionDependencies($deps, $c["child"], $c["obj_id"], $c["type"], $a_depth + 1);
2109 }
2110 }
2111
2112 // delete all dependencies to objects that will be deleted, too
2113 if ($a_depth == 0) {
2114 foreach ($deps["del_ids"] as $obj_id) {
2115 unset($deps["dep"][$obj_id]);
2116 }
2117 $deps = $deps["dep"];
2118 }
2119 }
2120
2125 public static function getDeletionDependencies($a_obj_id)
2126 {
2127 return false;
2128 }
2129
2136 public static function getLongDescriptions(array $a_obj_ids)
2137 {
2138 global $DIC;
2139
2140 $ilDB = $DIC->database();
2141
2142 $res = $ilDB->query("SELECT * FROM object_description" .
2143 " WHERE " . $ilDB->in("obj_id", $a_obj_ids, "", "integer"));
2144 $all = array();
2145 while ($row = $ilDB->fetchAssoc($res)) {
2146 $all[$row["obj_id"]] = $row["description"];
2147 }
2148 return $all;
2149 }
2150
2157 public static function getAllOwnedRepositoryObjects($a_user_id)
2158 {
2159 global $DIC;
2160
2161 $ilDB = $DIC->database();
2162 $objDefinition = $DIC["objDefinition"];
2163
2164 $all = array();
2165
2166 // restrict to repository
2167 $types = array_keys($objDefinition->getSubObjectsRecursively("root"));
2168
2169 $sql = "SELECT od.obj_id,od.type,od.title FROM object_data od" .
2170 " JOIN object_reference oref ON(oref.obj_id = od.obj_id)" .
2171 " JOIN tree ON (tree.child = oref.ref_id)";
2172
2173 if ($a_user_id) {
2174 $sql .= " WHERE od.owner = " . $ilDB->quote($a_user_id, "integer");
2175 } else {
2176 $sql .= " LEFT JOIN usr_data ud ON (ud.usr_id = od.owner)" .
2177 " WHERE (od.owner < " . $ilDB->quote(1, "integer") .
2178 " OR od.owner IS NULL OR ud.login IS NULL)" .
2179 " AND od.owner <> " . $ilDB->quote(-1, "integer");
2180 }
2181
2182 $sql .= " AND " . $ilDB->in("od.type", $types, "", "text") .
2183 " AND tree.tree > " . $ilDB->quote(0, "integer"); // #12485
2184
2185 $res = $ilDB->query($sql);
2186 while ($row = $ilDB->fetchAssoc($res)) {
2187 $all[$row["type"]][$row["obj_id"]] = $row["title"];
2188 }
2189
2190 return $all;
2191 }
2192
2199 public static function fixMissingTitles($a_type, array &$a_obj_title_map)
2200 {
2201 global $DIC;
2202
2203 $ilDB = $DIC->database();
2204
2205 if (!in_array($a_type, array("catr", "crsr", "sess", "grpr", "prgr"))) {
2206 return;
2207 }
2208
2209 // any missing titles?
2210 $missing_obj_ids = array();
2211 foreach ($a_obj_title_map as $obj_id => $title) {
2212 if (!trim($title)) {
2213 $missing_obj_ids[] = $obj_id;
2214 }
2215 }
2216
2217 if (!sizeof($missing_obj_ids)) {
2218 return;
2219 }
2220
2221 switch ($a_type) {
2222 case "grpr":
2223 case "catr":
2224 case "crsr":
2225 case "prgr":
2226 $set = $ilDB->query("SELECT oref.obj_id, od.type, od.title FROM object_data od" .
2227 " JOIN container_reference oref ON (od.obj_id = oref.target_obj_id)" .
2228 " AND " . $ilDB->in("oref.obj_id", $missing_obj_ids, "", "integer"));
2229 while ($row = $ilDB->fetchAssoc($set)) {
2230 $a_obj_title_map[$row["obj_id"]] = $row["title"];
2231 }
2232 break;
2233
2234 case "sess":
2235 include_once "Modules/Session/classes/class.ilObjSession.php";
2236 foreach ($missing_obj_ids as $obj_id) {
2237 $sess = new ilObjSession($obj_id, false);
2238 $a_obj_title_map[$obj_id] = $sess->getFirstAppointment()->appointmentToString();
2239 }
2240 break;
2241 }
2242 }
2243
2250 public static function _lookupCreationDate($a_id)
2251 {
2252 global $DIC;
2253
2254 $ilDB = $DIC->database();
2255
2256 $set = $ilDB->query("SELECT create_date FROM object_data " .
2257 " WHERE obj_id = " . $ilDB->quote($a_id, "integer"));
2258 $rec = $ilDB->fetchAssoc($set);
2259 return $rec["create_date"];
2260 }
2261
2269 public static function hasAutoRating($a_type, $a_ref_id)
2270 {
2271 global $DIC;
2272
2273 $tree = $DIC->repositoryTree();
2274
2275 if (!$a_ref_id ||
2276 !in_array($a_type, array("file", "lm", "wiki"))) {
2277 return false;
2278 }
2279
2280 // find parent container
2281 $parent_ref_id = $tree->checkForParentType($a_ref_id, "grp");
2282 if (!$parent_ref_id) {
2283 $parent_ref_id = $tree->checkForParentType($a_ref_id, "crs");
2284 }
2285 if ($parent_ref_id) {
2286 include_once './Services/Object/classes/class.ilObjectServiceSettingsGUI.php';
2287
2288 // get auto rate setting
2289 $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
2291 $parent_obj_id,
2293 false
2294 );
2295 }
2296 return false;
2297 }
2298
2308 public function getPossibleSubObjects($a_filter = true)
2309 {
2310 return $this->objDefinition->getSubObjects($this->type, $a_filter);
2311 }
2312} // END class.ilObject
$result
$filename
Definition: buildRTE.php:89
$location
Definition: buildRTE.php:44
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATETIME
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
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, $use_stored_record_map=false)
Clone Advanced Meta Data.
static _deleteSettingsOfBlock($a_block_id, $a_block_type)
Delete block settings of block.
INTERNAL CLASS: Please do not use in consumer code.
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 _getInstance($a_copy_id)
Get instance of copy wizard options.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=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 This class offers methods to get instances of the type-specific object classes ...
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, $a_user_id)
Set deleted date.
setOfflineStatus($a_status)
Set offline status.
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
supportsOfflineHandling()
Check whether object supports offline handling.
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
getOfflineStatus()
Get offline status.
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
setOwner($a_owner)
set object owner
static lookupOfflineStatus($a_obj_id)
Lookup offline status using objectDataCache.
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.
static _setDeletedDate($a_ref_id, $a_deleted_by)
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 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)
$c
Definition: cli.php:37
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
$factory
Definition: metadata.php:58
redirection script todo: (a better solution should control the processing via a xml file)
global $ilSetting
Definition: privfeed.php:17
$query
$ilErr
Definition: raiseError.php:18
foreach($_POST as $key=> $value) $res
global $ilDB
$message
Definition: xapiexit.php:14