ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
13 class ilObject
14 {
18  protected $objDefinition;
19 
23  protected $db;
24 
28  protected $log;
29 
33  protected $error;
34 
38  protected $tree;
39 
43  protected $app_event_handler;
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;
94  public $create_date;
95  public $last_update;
96  public $import_id;
97  public $register = false; // registering required for object? set to true to implement a subscription interface
98 
104  public $referenced;
105 
111  public $objectList;
112 
117  public $max_title;
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 
203  $ilDB = $this->db;
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  "AND NOT lang_default = 1";
305  $r = $ilDB->query($q);
307  if ($row) {
308  $this->title = $row->title;
309  $this->setDescription($row->description);
310  #$this->desc = $row->description;
311  }
312  }
313  }
314 
320  public function getId()
321  {
322  return $this->id;
323  }
324 
330  public function setId($a_id)
331  {
332  $this->id = $a_id;
333  }
334 
340  public function setRefId($a_id)
341  {
342  $this->ref_id = $a_id;
343  $this->referenced = true;
344  }
345 
351  public function getRefId()
352  {
353  return $this->ref_id;
354  }
355 
361  public function getType()
362  {
363  return $this->type;
364  }
365 
371  public function setType($a_type)
372  {
373  $this->type = $a_type;
374  }
375 
385  public function getPresentationTitle()
386  {
387  return $this->getTitle();
388  }
389 
390 
396  public function getTitle()
397  {
398  return $this->title;
399  }
400  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
406  public function getUntranslatedTitle()
407  {
409  }
410  // END WebDAV: WebDAV needs to access the untranslated title of an object
411 
418  public function setTitle($a_title)
419  {
420  $this->title = ilUtil::shortenText($a_title, $this->max_title, $this->add_dots);
421  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
422  $this->untranslatedTitle = $this->title;
423  // END WebDAV: WebDAV needs to access the untranslated title of an object
424  }
425 
432  public function getDescription()
433  {
434  return $this->desc;
435  }
436 
443  public function setDescription($a_desc)
444  {
445  // Shortened form is storted in object_data. Long form is stored in object_description
446  $this->desc = ilUtil::shortenText($a_desc, $this->max_desc, $this->add_dots);
447 
448  $this->long_desc = $a_desc;
449 
450  return true;
451  }
452 
459  public function getLongDescription()
460  {
461  return strlen($this->long_desc) ? $this->long_desc : $this->desc;
462  }
463 
470  public function getImportId()
471  {
472  return $this->import_id;
473  }
474 
481  public function setImportId($a_import_id)
482  {
483  $this->import_id = $a_import_id;
484  }
485 
486  public static function _lookupObjIdByImportId($a_import_id)
487  {
488  global $DIC;
489 
490  $ilDB = $DIC->database();
491 
492  $query = "SELECT * FROM object_data " .
493  "WHERE import_id = " . $ilDB->quote($a_import_id, "text") . " " .
494  "ORDER BY create_date DESC";
495  $res = $ilDB->query($query);
496  while ($row = $ilDB->fetchObject($res)) {
497  return $row->obj_id;
498  }
499  return 0;
500  }
501 
506  public function setOfflineStatus($a_status)
507  {
508  $this->offline = $a_status;
509  }
510 
515  public function getOfflineStatus()
516  {
517  return $this->offline;
518  }
519 
524  public function supportsOfflineHandling()
525  {
526  global $DIC;
527 
528  return (bool) $DIC['objDefinition']->supportsOfflineHandling($this->getType());
529  }
530 
531 
532 
533 
534  public static function _lookupImportId($a_obj_id)
535  {
536  global $DIC;
537 
538  $ilDB = $DIC->database();
539 
540  $query = "SELECT import_id FROM object_data " .
541  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
542  $res = $ilDB->query($query);
543  $row = $ilDB->fetchObject($res);
544  return $row->import_id;
545  }
546 
553  public function getOwner()
554  {
555  return $this->owner;
556  }
557 
558  /*
559  * get full name of object owner
560  *
561  * @access public
562  * @return string owner name or unknown
563  */
564  public function getOwnerName()
565  {
566  return ilObject::_lookupOwnerName($this->getOwner());
567  }
568 
572  public static function _lookupOwnerName($a_owner_id)
573  {
574  global $DIC;
575 
576  $lng = $DIC->language();
577 
578  if ($a_owner_id != -1) {
579  if (ilObject::_exists($a_owner_id)) {
580  $owner = new ilObjUser($a_owner_id);
581  }
582  }
583 
584  if (is_object($owner)) {
585  $own_name = $owner->getFullname();
586  } else {
587  $own_name = $lng->txt("unknown");
588  }
589 
590  return $own_name;
591  }
592 
599  public function setOwner($a_owner)
600  {
601  $this->owner = $a_owner;
602  }
603 
604 
605 
611  public function getCreateDate()
612  {
613  return $this->create_date;
614  }
615 
621  public function getLastUpdateDate()
622  {
623  return $this->last_update;
624  }
625 
626 
638  public function getDiskUsage()
639  {
640  return null;
641  }
642 
651  public function create()
652  {
653  global $DIC;
654 
655  $app_event = $DIC->event();
656  $ilDB = $this->db;
657  $ilLog = $this->log;
658  $ilUser = $DIC["ilUser"];
661 
662  if (!isset($this->type)) {
663  $message = get_class($this) . "::create(): No object type given!";
664  $ilErr->raiseError($message, $ilErr->WARNING);
665  }
666 
667  // write log entry
668  $ilLog->write("ilObject::create(), start");
669 
670  $this->title = ilUtil::shortenText($this->getTitle(), $this->max_title, $this->add_dots);
671  $this->desc = ilUtil::shortenText($this->getDescription(), $this->max_desc, $this->add_dots);
672 
673  // determine owner
674  if ($this->getOwner() > 0) {
675  $owner = $this->getOwner();
676  } elseif (is_object($ilUser)) {
677  $owner = $ilUser->getId();
678  } else {
679  $owner = 0;
680  }
681  $this->id = $ilDB->nextId("object_data");
682  $q = "INSERT INTO object_data " .
683  "(obj_id,type,title,description,offline,owner,create_date,last_update,import_id) " .
684  "VALUES " .
685  "(" .
686  $ilDB->quote($this->id, "integer") . "," .
687  $ilDB->quote($this->type, "text") . "," .
688  $ilDB->quote($this->getTitle(), "text") . "," .
689  $ilDB->quote($this->getDescription(), "text") . "," .
690  $ilDB->quote($this->supportsOfflineHandling() ? $this->getOfflineStatus() : null, 'integer') . ', ' .
691  $ilDB->quote($owner, "integer") . "," .
692  $ilDB->now() . "," .
693  $ilDB->now() . "," .
694  $ilDB->quote($this->getImportId(), "text") . ")";
695 
696  $ilDB->manipulate($q);
697 
698 
699  // Save long form of description if is rbac object
700  if ($objDefinition->isRBACObject($this->getType())) {
701  $values = array(
702  'obj_id' => array('integer',$this->id),
703  'description' => array('clob', $this->getLongDescription()));
704  $ilDB->insert('object_description', $values);
705  }
706 
707  if ($objDefinition->isOrgUnitPermissionType($this->type)) {
708  ilOrgUnitGlobalSettings::getInstance()->saveDefaultPositionActivationStatus($this->id);
709  }
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, create_date FROM object_data" .
715  " WHERE obj_id = " . $ilDB->quote($this->id, "integer");
716  $obj_set = $ilDB->query($q);
717  $obj_rec = $ilDB->fetchAssoc($obj_set);
718  $this->last_update = $obj_rec["last_update"];
719  $this->create_date = $obj_rec["create_date"];
720 
721  // set owner for new objects
722  $this->setOwner($owner);
723 
724  // write log entry
725  $ilLog->write("ilObject::create(), finished, obj_id: " . $this->id . ", type: " .
726  $this->type . ", title: " . $this->getTitle());
727 
728  $app_event->raise(
729  'Services/Object',
730  'create',
731  array('obj_id' => $this->id,'obj_type' => $this->type)
732  );
733 
734  return $this->id;
735  }
736 
743  public function update()
744  {
745  global $DIC;
746 
747  $app_event = $DIC->event();
748 
750  $ilDB = $this->db;
751 
752  $q = "UPDATE object_data " .
753  "SET " .
754  "title = " . $ilDB->quote($this->getTitle(), "text") . "," .
755  "description = " . $ilDB->quote($this->getDescription(), "text") . ", " .
756  'offline = ' . $ilDB->quote($this->supportsOfflineHandling() ? $this->getOfflineStatus() : null, 'integer') . ', ' .
757  "import_id = " . $ilDB->quote($this->getImportId(), "text") . "," .
758  "last_update = " . $ilDB->now() . " " .
759  "WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
760  $ilDB->manipulate($q);
761 
762  // the line ($this->read();) messes up meta data handling: meta data,
763  // that is not saved at this time, gets lost, so we query for the dates alone
764  //$this->read();
765  $q = "SELECT last_update FROM object_data" .
766  " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
767  $obj_set = $ilDB->query($q);
768  $obj_rec = $ilDB->fetchAssoc($obj_set);
769  $this->last_update = $obj_rec["last_update"];
770 
771  if ($objDefinition->isRBACObject($this->getType())) {
772  // Update long description
773  $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = " .
774  $ilDB->quote($this->getId(), 'integer'));
775  if ($res->numRows()) {
776  $values = array(
777  'description' => array('clob',$this->getLongDescription())
778  );
779  $ilDB->update('object_description', $values, array('obj_id' => array('integer',$this->getId())));
780  } else {
781  $values = array(
782  'description' => array('clob',$this->getLongDescription()),
783  'obj_id' => array('integer',$this->getId()));
784  $ilDB->insert('object_description', $values);
785  }
786  }
787  $app_event->raise(
788  'Services/Object',
789  'update',
790  array('obj_id' => $this->getId(),
791  'obj_type' => $this->getType(),
792  'ref_id' => $this->getRefId())
793  );
794 
795  return true;
796  }
797 
809  public function MDUpdateListener($a_element)
810  {
811  global $DIC;
812 
813  $app_event = $DIC->event();
814 
815  include_once 'Services/MetaData/classes/class.ilMD.php';
816 
817  $app_event->raise(
818  'Services/Object',
819  'update',
820  array('obj_id' => $this->getId(),
821  'obj_type' => $this->getType(),
822  'ref_id' => $this->getRefId())
823  );
824 
825  switch ($a_element) {
826  case 'General':
827 
828  // Update Title and description
829  $md = new ilMD($this->getId(), 0, $this->getType());
830  if (!is_object($md_gen = $md->getGeneral())) {
831  return false;
832  }
833  $this->setTitle($md_gen->getTitle());
834 
835  foreach ($md_gen->getDescriptionIds() as $id) {
836  $md_des = $md_gen->getDescription($id);
837  $this->setDescription($md_des->getDescription());
838  break;
839  }
840  $this->update();
841  break;
842 
843  default:
844  }
845 
846  return true;
847  }
848 
852  public function createMetaData()
853  {
854  global $DIC;
855 
856  include_once 'Services/MetaData/classes/class.ilMDCreator.php';
857 
858  $ilUser = $DIC["ilUser"];
859 
860  $md_creator = new ilMDCreator($this->getId(), 0, $this->getType());
861  $md_creator->setTitle($this->getTitle());
862  $md_creator->setTitleLanguage($ilUser->getPref('language'));
863  $md_creator->setDescription($this->getLongDescription());
864  $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
865  $md_creator->setKeywordLanguage($ilUser->getPref('language'));
866  $md_creator->setLanguage($ilUser->getPref('language'));
867  $md_creator->create();
868 
869  return true;
870  }
871 
875  public function updateMetaData()
876  {
877  $md = new ilMD($this->getId(), 0, $this->getType());
878  $md_gen = $md->getGeneral();
879  // BEGIN WebDAV: meta data can be missing sometimes.
880  if (!$md_gen instanceof ilMDGeneral) {
881  $this->createMetaData();
882  $md = new ilMD($this->getId(), 0, $this->getType());
883  $md_gen = $md->getGeneral();
884  }
885  // END WebDAV: meta data can be missing sometimes.
886  $md_gen->setTitle($this->getTitle());
887 
888  // sets first description (maybe not appropriate)
889  $md_des_ids = $md_gen->getDescriptionIds();
890  if (count($md_des_ids) > 0) {
891  $md_des = $md_gen->getDescription($md_des_ids[0]);
892  $md_des->setDescription($this->getLongDescription());
893  $md_des->update();
894  }
895  $md_gen->update();
896  }
897 
901  public function deleteMetaData()
902  {
903  // Delete meta data
904  include_once('Services/MetaData/classes/class.ilMD.php');
905  $md = new ilMD($this->getId(), 0, $this->getType());
906  $md->deleteAll();
907  }
908 
915  public function updateOwner()
916  {
917  $ilDB = $this->db;
918 
919  $q = "UPDATE object_data " .
920  "SET " .
921  "owner = " . $ilDB->quote($this->getOwner(), "integer") . ", " .
922  "last_update = " . $ilDB->now() . " " .
923  "WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
924  $ilDB->manipulate($q);
925 
926  $q = "SELECT last_update FROM object_data" .
927  " WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
928  $obj_set = $ilDB->query($q);
929  $obj_rec = $ilDB->fetchAssoc($obj_set);
930  $this->last_update = $obj_rec["last_update"];
931 
932  return true;
933  }
934 
942  public static function _getIdForImportId($a_import_id)
943  {
944  global $DIC;
945 
946  $ilDB = $DIC->database();
947 
948  $ilDB->setLimit(1, 0);
949  $q = "SELECT * FROM object_data WHERE import_id = " . $ilDB->quote($a_import_id, "text") .
950  " ORDER BY create_date DESC";
951  $obj_set = $ilDB->query($q);
952 
953  if ($obj_rec = $ilDB->fetchAssoc($obj_set)) {
954  return $obj_rec["obj_id"];
955  } else {
956  return 0;
957  }
958  }
959 
965  public static function _getAllReferences($a_id)
966  {
967  global $DIC;
968 
969  $ilDB = $DIC->database();
970 
971  $query = "SELECT * FROM object_reference WHERE obj_id = " .
972  $ilDB->quote($a_id, 'integer');
973 
974  $res = $ilDB->query($query);
975  $ref = array();
976  while ($obj_rec = $ilDB->fetchAssoc($res)) {
977  $ref[$obj_rec["ref_id"]] = $obj_rec["ref_id"];
978  }
979 
980  return $ref;
981  }
982 
988  public static function _lookupTitle($a_id)
989  {
990  global $DIC;
991 
992  $ilObjDataCache = $DIC["ilObjDataCache"];
993 
994  $tit = $ilObjDataCache->lookupTitle($a_id);
995  //echo "<br>LOOKING-$a_id-:$tit";
996  return $tit;
997  }
998 
1006  public static function lookupOfflineStatus($a_obj_id)
1007  {
1008  global $DIC;
1009 
1010  return $DIC['ilObjDataCache']->lookupOfflineStatus($a_obj_id);
1011  }
1012 
1013 
1014 
1020  public static function _lookupOwner($a_id)
1021  {
1022  global $DIC;
1023 
1024  $ilObjDataCache = $DIC["ilObjDataCache"];
1025 
1026  $owner = $ilObjDataCache->lookupOwner($a_id);
1027  return $owner;
1028  }
1029 
1030  public static function _getIdsForTitle($title, $type = '', $partialmatch = false)
1031  {
1032  global $DIC;
1033 
1034  $ilDB = $DIC->database();
1035 
1036  $query = (!$partialmatch)
1037  ? "SELECT obj_id FROM object_data WHERE title = " . $ilDB->quote($title, "text")
1038  : "SELECT obj_id FROM object_data WHERE " . $ilDB->like("title", "text", '%' . $title . '%');
1039  if ($type != '') {
1040  $query .= " AND type = " . $ilDB->quote($type, "text");
1041  }
1042 
1043  $result = $ilDB->query($query);
1044 
1045  $object_ids = array();
1046  while ($row = $ilDB->fetchAssoc($result)) {
1047  $object_ids[] = $row['obj_id'];
1048  }
1049 
1050  return is_array($object_ids) ? $object_ids : array();
1051  }
1052 
1058  public static function _lookupDescription($a_id)
1059  {
1060  global $DIC;
1061 
1062  $ilObjDataCache = $DIC["ilObjDataCache"];
1063 
1064  return $ilObjDataCache->lookupDescription($a_id);
1065  }
1066 
1072  public static function _lookupLastUpdate($a_id, $a_as_string = false)
1073  {
1074  global $DIC;
1075 
1076  $ilObjDataCache = $DIC["ilObjDataCache"];
1077 
1078  if ($a_as_string) {
1079  return ilDatePresentation::formatDate(new ilDateTime($ilObjDataCache->lookupLastUpdate($a_id), IL_CAL_DATETIME));
1080  } else {
1081  return $ilObjDataCache->lookupLastUpdate($a_id);
1082  }
1083  }
1084 
1090  public static function _getLastUpdateOfObjects($a_objs)
1091  {
1092  global $DIC;
1093 
1094  $ilDB = $DIC->database();
1095 
1096  if (!is_array($a_objs)) {
1097  $a_objs = array($a_objs);
1098  }
1099  $types = array();
1100  $set = $ilDB->query("SELECT max(last_update) as last_update FROM object_data " .
1101  "WHERE " . $ilDB->in("obj_id", $a_objs, false, "integer") . " ");
1102  $rec = $ilDB->fetchAssoc($set);
1103 
1104  return ($rec["last_update"]);
1105  }
1106 
1107  public static function _lookupObjId($a_id)
1108  {
1109  global $DIC;
1110 
1111  $ilObjDataCache = $DIC["ilObjDataCache"];
1112 
1113  return (int) $ilObjDataCache->lookupObjId($a_id);
1114  }
1115 
1119  public static function _setDeletedDate($a_ref_id)
1120  {
1121  global $DIC;
1122 
1123  $ilDB = $DIC->database();
1124 
1125  $query = "UPDATE object_reference SET deleted= " . $ilDB->now() . ' ' .
1126  "WHERE ref_id = " . $ilDB->quote($a_ref_id, 'integer');
1127  $res = $ilDB->manipulate($query);
1128  }
1129 
1135  public static function setDeletedDates($a_ref_ids)
1136  {
1137  global $DIC;
1138 
1139  $ilDB = $DIC->database();
1140  $log = $DIC->logger()->root();
1141 
1142  $query = 'UPDATE object_reference SET deleted = ' . $ilDB->now() . ' ' .
1143  'WHERE ' . $ilDB->in('ref_id', (array) $a_ref_ids, false, 'integer');
1144 
1145  $log->debug(__METHOD__ . ': Query is ' . $query);
1146  $ilDB->manipulate($query);
1147  return;
1148  }
1149 
1153  public static function _resetDeletedDate($a_ref_id)
1154  {
1155  global $DIC;
1156 
1157  $ilDB = $DIC->database();
1158 
1159  $query = "UPDATE object_reference SET deleted = " . $ilDB->quote(null, 'timestamp') .
1160  " WHERE ref_id = " . $ilDB->quote($a_ref_id, 'integer');
1161  $ilDB->manipulate($query);
1162  }
1163 
1167  public static function _lookupDeletedDate($a_ref_id)
1168  {
1169  global $DIC;
1170 
1171  $ilDB = $DIC->database();
1172 
1173  $query = "SELECT deleted FROM object_reference" .
1174  " WHERE ref_id = " . $ilDB->quote($a_ref_id, "integer");
1175  $set = $ilDB->query($query);
1176  $rec = $ilDB->fetchAssoc($set);
1177 
1178  return $rec["deleted"];
1179  }
1180 
1181 
1189  public static function _writeTitle($a_obj_id, $a_title)
1190  {
1191  global $DIC;
1192 
1193  $ilDB = $DIC->database();
1194 
1195  $q = "UPDATE object_data " .
1196  "SET " .
1197  "title = " . $ilDB->quote($a_title, "text") . "," .
1198  "last_update = " . $ilDB->now() . " " .
1199  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
1200 
1201  $ilDB->manipulate($q);
1202  }
1203 
1211  public static function _writeDescription($a_obj_id, $a_desc)
1212  {
1213  global $DIC;
1214 
1215  $ilDB = $DIC->database();
1216  $objDefinition = $DIC["objDefinition"];
1217 
1218 
1219  $desc = ilUtil::shortenText($a_desc, self::DESC_LENGTH, true);
1220 
1221  $q = "UPDATE object_data " .
1222  "SET " .
1223  "description = " . $ilDB->quote($desc, "text") . "," .
1224  "last_update = " . $ilDB->now() . " " .
1225  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
1226 
1227  $ilDB->manipulate($q);
1228 
1229  if ($objDefinition->isRBACObject(ilObject::_lookupType($a_obj_id))) {
1230  // Update long description
1231  $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = " .
1232  $ilDB->quote($a_obj_id, 'integer'));
1233 
1234  if ($res->numRows()) {
1235  $values = array(
1236  'description' => array('clob',$a_desc)
1237  );
1238  $ilDB->update('object_description', $values, array('obj_id' => array('integer',$a_obj_id)));
1239  } else {
1240  $values = array(
1241  'description' => array('clob',$a_desc),
1242  'obj_id' => array('integer',$a_obj_id));
1243  $ilDB->insert('object_description', $values);
1244  }
1245  }
1246  }
1247 
1255  public static function _writeImportId($a_obj_id, $a_import_id)
1256  {
1257  global $DIC;
1258 
1259  $ilDB = $DIC->database();
1260 
1261  $q = "UPDATE object_data " .
1262  "SET " .
1263  "import_id = " . $ilDB->quote($a_import_id, "text") . "," .
1264  "last_update = " . $ilDB->now() . " " .
1265  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
1266 
1267  $ilDB->manipulate($q);
1268  }
1269 
1275  public static function _lookupType($a_id, $a_reference = false)
1276  {
1277  global $DIC;
1278 
1279  $ilObjDataCache = $DIC["ilObjDataCache"];
1280 
1281  if ($a_reference) {
1282  return $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_id));
1283  }
1284  return $ilObjDataCache->lookupType($a_id);
1285  }
1286 
1290  public static function _isInTrash($a_ref_id)
1291  {
1292  global $DIC;
1293 
1294  $tree = $DIC->repositoryTree();
1295 
1296  return $tree->isSaved($a_ref_id);
1297  }
1298 
1302  public static function _hasUntrashedReference($a_obj_id)
1303  {
1304  $ref_ids = ilObject::_getAllReferences($a_obj_id);
1305  foreach ($ref_ids as $ref_id) {
1306  if (!ilObject::_isInTrash($ref_id)) {
1307  return true;
1308  }
1309  }
1310 
1311  return false;
1312  }
1313 
1319  public static function _lookupObjectId($a_ref_id)
1320  {
1321  global $DIC;
1322 
1323  $ilObjDataCache = $DIC["ilObjDataCache"];
1324 
1325  return (int) $ilObjDataCache->lookupObjId($a_ref_id);
1326  }
1327 
1338  public static function _getObjectsDataForType($a_type, $a_omit_trash = false)
1339  {
1340  global $DIC;
1341 
1342  $ilDB = $DIC->database();
1343 
1344  $q = "SELECT * FROM object_data WHERE type = " . $ilDB->quote($a_type, "text");
1345  $obj_set = $ilDB->query($q);
1346 
1347  $objects = array();
1348  while ($obj_rec = $ilDB->fetchAssoc($obj_set)) {
1349  if ((!$a_omit_trash) || ilObject::_hasUntrashedReference($obj_rec["obj_id"])) {
1350  $objects[$obj_rec["title"] . "." . $obj_rec["obj_id"]] = array("id" => $obj_rec["obj_id"],
1351  "type" => $obj_rec["type"], "title" => $obj_rec["title"],
1352  "description" => $obj_rec["description"]);
1353  }
1354  }
1355  ksort($objects);
1356  return $objects;
1357  }
1358 
1359 
1367  public function putInTree($a_parent_ref)
1368  {
1369  $tree = $this->tree;
1370  $ilLog = $this->log;
1371  $ilAppEventHandler = $this->app_event_handler;
1372 
1373  $tree->insertNode($this->getRefId(), $a_parent_ref);
1374 
1375  // write log entry
1376  $ilLog->write("ilObject::putInTree(), parent_ref: $a_parent_ref, ref_id: " .
1377  $this->getRefId() . ", obj_id: " . $this->getId() . ", type: " .
1378  $this->getType() . ", title: " . $this->getTitle());
1379 
1380  $ilAppEventHandler->raise(
1381  'Services/Object',
1382  'putObjectInTree',
1383  array(
1384  'object' => $this,
1385  'obj_type' => $this->getType(),
1386  'obj_id' => $this->getId(),
1387  'parent_ref_id' => $a_parent_ref,
1388  )
1389  );
1390  }
1391 
1398  public function setPermissions($a_parent_ref)
1399  {
1400  $this->setParentRolePermissions($a_parent_ref);
1401  $this->initDefaultRoles();
1402  }
1403 
1408  public function setParentRolePermissions($a_parent_ref)
1409  {
1410  global $DIC;
1411 
1412  $rbacadmin = $DIC["rbacadmin"];
1413  $rbacreview = $DIC["rbacreview"];
1414 
1415  $parent_roles = $rbacreview->getParentRoleIds($a_parent_ref);
1416  foreach ((array) $parent_roles as $parent_role) {
1417  $operations = $rbacreview->getOperationsOfRole(
1418  $parent_role['obj_id'],
1419  $this->getType(),
1420  $parent_role['parent']
1421  );
1422  $rbacadmin->grantPermission(
1423  $parent_role['obj_id'],
1424  $operations,
1425  $this->getRefId()
1426  );
1427  }
1428  return true;
1429  }
1430 
1437  public function createReference()
1438  {
1439  $ilDB = $this->db;
1440  $ilErr = $this->error;
1441 
1442  if (!isset($this->id)) {
1443  $message = "ilObject::createNewReference(): No obj_id given!";
1444  $ilErr->raiseError($message, $ilErr->WARNING);
1445  }
1446 
1447  $next_id = $ilDB->nextId('object_reference');
1448  $query = "INSERT INTO object_reference " .
1449  "(ref_id, obj_id) VALUES (" . $ilDB->quote($next_id, 'integer') . ',' . $ilDB->quote($this->id, 'integer') . ")";
1450  $ilDB->query($query);
1451 
1452  $this->ref_id = $next_id;
1453  $this->referenced = true;
1454 
1455  return $this->ref_id;
1456  }
1457 
1458 
1465  public function countReferences()
1466  {
1467  $ilDB = $this->db;
1468  $ilErr = $this->error;
1469 
1470  if (!isset($this->id)) {
1471  $message = "ilObject::countReferences(): No obj_id given!";
1472  $ilErr->raiseError($message, $ilErr->WARNING);
1473  }
1474 
1475  $query = "SELECT COUNT(ref_id) num FROM object_reference " .
1476  "WHERE obj_id = " . $ilDB->quote($this->id, 'integer') . " ";
1477  $res = $ilDB->query($query);
1478  $row = $ilDB->fetchObject($res);
1479 
1480  return $row->num;
1481  }
1482 
1483 
1494  public function delete()
1495  {
1496  global $DIC;
1497 
1498  $rbacadmin = $DIC["rbacadmin"];
1499  $ilLog = $this->log;
1500  $ilDB = $this->db;
1501  $ilAppEventHandler = $this->app_event_handler;
1502  $ilErr = $this->error;
1507  $remove = false;
1508 
1509  // delete object_data entry
1510  if ((!$this->referenced) || ($this->countReferences() == 1)) {
1511  // check type match
1512  $db_type = ilObject::_lookupType($this->getId());
1513  if ($this->type != $db_type) {
1514  $message = "ilObject::delete(): Type mismatch. Object with obj_id: " . $this->id . " " .
1515  "was instantiated by type '" . $this->type . "'. DB type is: " . $db_type;
1516 
1517  // write log entry
1518  $ilLog->write($message);
1519 
1520  // raise error
1521  $ilErr->raiseError("ilObject::delete(): Type mismatch. (" . $this->type . "/" . $this->id . ")", $ilErr->WARNING);
1522  }
1523 
1524  $ilAppEventHandler->raise('Services/Object', 'beforeDeletion', array( 'object' => $this ));
1525 
1526  // delete entry in object_data
1527  $q = "DELETE FROM object_data " .
1528  "WHERE obj_id = " . $ilDB->quote($this->getId(), "integer");
1529  $ilDB->manipulate($q);
1530 
1531  // delete long description
1532  $query = "DELETE FROM object_description WHERE obj_id = " .
1533  $ilDB->quote($this->getId(), "integer");
1534  $ilDB->manipulate($query);
1535 
1536  // write log entry
1537  $ilLog->write("ilObject::delete(), deleted object, obj_id: " . $this->getId() . ", type: " .
1538  $this->getType() . ", title: " . $this->getTitle());
1539 
1540  // keep log of core object data
1541  include_once "Services/Object/classes/class.ilObjectDataDeletionLog.php";
1543 
1544  // remove news
1545  include_once("./Services/News/classes/class.ilNewsItem.php");
1546  $news_item = new ilNewsItem();
1547  $news_item->deleteNewsOfContext($this->getId(), $this->getType());
1548  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1550 
1551  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1553 
1554  /* remove notes (see infoscreen gui)
1555  as they can be seen as personal data we are keeping them for now
1556  include_once("Services/Notes/classes/class.ilNote.php");
1557  foreach(array(IL_NOTE_PRIVATE, IL_NOTE_PUBLIC) as $note_type)
1558  {
1559  foreach(ilNote::_getNotesOfObject($this->id, 0, $this->type, $note_type) as $note)
1560  {
1561  $note->delete();
1562  }
1563  }
1564  */
1565 
1566  // BEGIN WebDAV: Delete WebDAV properties
1567  $query = "DELETE FROM dav_property " .
1568  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
1569  $res = $ilDB->manipulate($query);
1570  // END WebDAV: Delete WebDAV properties
1571 
1572  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
1574 
1575  include_once("Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
1577 
1578  include_once("Services/Tracking/classes/class.ilLPObjSettings.php");
1580 
1581  $remove = true;
1582  } else {
1583  // write log entry
1584  $ilLog->write("ilObject::delete(), object not deleted, number of references: " .
1585  $this->countReferences() . ", obj_id: " . $this->getId() . ", type: " .
1586  $this->getType() . ", title: " . $this->getTitle());
1587  }
1588 
1589  // delete object_reference entry
1590  if ($this->referenced) {
1591  include_once "Services/Object/classes/class.ilObjectActivation.php";
1593 
1594  // delete entry in object_reference
1595  $query = "DELETE FROM object_reference " .
1596  "WHERE ref_id = " . $ilDB->quote($this->getRefId(), 'integer');
1597  $res = $ilDB->manipulate($query);
1598 
1599  // write log entry
1600  $ilLog->write("ilObject::delete(), reference deleted, ref_id: " . $this->getRefId() .
1601  ", obj_id: " . $this->getId() . ", type: " .
1602  $this->getType() . ", title: " . $this->getTitle());
1603 
1604  // DELETE PERMISSION ENTRIES IN RBAC_PA
1605  // DONE: method overwritten in ilObjRole & ilObjUser.
1606  // this call only applies for objects in rbac (not usr,role,rolt)
1607  // TODO: Do this for role templates too
1608  $rbacadmin->revokePermission($this->getRefId(), 0, false);
1609 
1610  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
1611  ilRbacLog::delete($this->getRefId());
1612 
1613  // Remove applied didactic template setting
1614  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1616 
1617  // Remove desktop items
1619  }
1620 
1621  // remove conditions
1622  if ($this->referenced) {
1623  $ch = new ilConditionHandler();
1624  $ch->delete($this->getRefId());
1625  unset($ch);
1626  }
1627 
1628  return $remove;
1629  }
1630 
1638  public function initDefaultRoles()
1639  {
1640  return array();
1641  }
1642 
1643 
1648  public function applyDidacticTemplate($a_tpl_id)
1649  {
1650  ilLoggerFactory::getLogger('obj')->debug('Applying didactic template with id: ' . (int) $a_tpl_id);
1651  if ($a_tpl_id) {
1652  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
1654  $action->setRefId($this->getRefId());
1655  $action->apply();
1656  }
1657  }
1658 
1659  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1660  ilDidacticTemplateObjSettings::assignTemplate($this->getRefId(), $this->getId(), (int) $a_tpl_id);
1661  return $a_tpl_id ? true : false;
1662  }
1663 
1673  public static function _exists($a_id, $a_reference = false, $a_type = null)
1674  {
1675  global $DIC;
1676 
1677  $ilDB = $DIC->database();
1678 
1679  if ($a_reference) {
1680  $q = "SELECT * FROM object_data " .
1681  "LEFT JOIN object_reference ON object_reference.obj_id=object_data.obj_id " .
1682  "WHERE object_reference.ref_id= " . $ilDB->quote($a_id, "integer");
1683  } else {
1684  $q = "SELECT * FROM object_data WHERE obj_id=" . $ilDB->quote($a_id, "integer");
1685  }
1686 
1687  if ($a_type) {
1688  $q .= " AND object_data.type = " . $ilDB->quote($a_type, "text");
1689  }
1690 
1691  $r = $ilDB->query($q);
1692 
1693  return $ilDB->numRows($r) ? true : false;
1694  }
1695 
1696  // toggle subscription interface
1697  public function setRegisterMode($a_bool)
1698  {
1699  $this->register = (bool) $a_bool;
1700  }
1701 
1702  // check register status of current user
1703  // abstract method; overwrite in object type class
1704  public function isUserRegistered($a_user_id = 0)
1705  {
1706  return false;
1707  }
1708 
1709  public function requireRegistration()
1710  {
1711  return $this->register;
1712  }
1713 
1714 
1715  public function getXMLZip()
1716  {
1717  return false;
1718  }
1719  public function getHTMLDirectory()
1720  {
1721  return false;
1722  }
1723 
1727  public static function _getObjectsByType($a_obj_type = "", $a_owner = "")
1728  {
1729  global $DIC;
1730 
1731  $ilDB = $DIC->database();
1732 
1733  $order = " ORDER BY title";
1734 
1735  // where clause
1736  if ($a_obj_type) {
1737  $where_clause = "WHERE type = " .
1738  $ilDB->quote($a_obj_type, "text");
1739 
1740  if ($a_owner != "") {
1741  $where_clause .= " AND owner = " . $ilDB->quote($a_owner, "integer");
1742  }
1743  }
1744 
1745  $q = "SELECT * FROM object_data " . $where_clause . $order;
1746  $r = $ilDB->query($q);
1747 
1748  $arr = array();
1749  if ($ilDB->numRows($r) > 0) {
1750  while ($row = $ilDB->fetchAssoc($r)) {
1751  $row["desc"] = $row["description"];
1752  $arr[$row["obj_id"]] = $row;
1753  }
1754  }
1755 
1756  return $arr;
1757  }
1758 
1771  public static function _prepareCloneSelection($a_ref_ids, $new_type, $show_path = true)
1772  {
1773  global $DIC;
1774 
1775  $ilDB = $DIC->database();
1776  $lng = $DIC->language();
1777  $objDefinition = $DIC["objDefinition"];
1778 
1779  $query = "SELECT obj_data.title obj_title,path_data.title path_title,child FROM tree " .
1780  "JOIN object_reference obj_ref ON child = obj_ref.ref_id " .
1781  "JOIN object_data obj_data ON obj_ref.obj_id = obj_data.obj_id " .
1782  "JOIN object_reference path_ref ON parent = path_ref.ref_id " .
1783  "JOIN object_data path_data ON path_ref.obj_id = path_data.obj_id " .
1784  "WHERE " . $ilDB->in("child", $a_ref_ids, false, "integer") . " " .
1785  "ORDER BY obj_data.title ";
1786  $res = $ilDB->query($query);
1787 
1788  if (!$objDefinition->isPlugin($new_type)) {
1789  $options[0] = $lng->txt('obj_' . $new_type . '_select');
1790  } else {
1791  require_once("Services/Repository/classes/class.ilObjectPlugin.php");
1792  $options[0] = ilObjectPlugin::lookupTxtById($new_type, "obj_" . $new_type . "_select");
1793  }
1794 
1795  while ($row = $ilDB->fetchObject($res)) {
1796  if (strlen($title = $row->obj_title) > 40) {
1797  $title = substr($title, 0, 40) . '...';
1798  }
1799 
1800  if ($show_path) {
1801  if (strlen($path = $row->path_title) > 40) {
1802  $path = substr($path, 0, 40) . '...';
1803  }
1804 
1805  $title .= ' (' . $lng->txt('path') . ': ' . $path . ')';
1806  }
1807 
1808  $options[$row->child] = $title;
1809  }
1810  return $options ? $options : array();
1811  }
1812 
1822  public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
1823  {
1824  global $DIC;
1825 
1827  $ilUser = $DIC["ilUser"];
1828  $rbacadmin = $DIC["rbacadmin"];
1829  $ilDB = $this->db;
1830  $ilAppEventHandler = $this->app_event_handler;
1835  $location = $objDefinition->getLocation($this->getType());
1836  $class_name = ('ilObj' . $objDefinition->getClassName($this->getType()));
1837 
1838  include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1840 
1841  if (!$options->isTreeCopyDisabled() && !$a_omit_tree) {
1842  $title = $this->appendCopyInfo($a_target_id, $a_copy_id);
1843  } else {
1844  $title = $this->getTitle();
1845  }
1846 
1847  // create instance
1848  include_once($location . "/class." . $class_name . ".php");
1849  $new_obj = new $class_name(0, false);
1850  $new_obj->setOwner($ilUser->getId());
1851  $new_obj->setTitle($title);
1852  $new_obj->setDescription($this->getLongDescription());
1853  $new_obj->setType($this->getType());
1854 
1855  // Choose upload mode to avoid creation of additional settings, db entries ...
1856  $new_obj->create(true);
1857 
1858  if ($this->supportsOfflineHandling()) {
1859  $new_obj->setOffLineStatus($this->getOfflineStatus());
1860  $new_obj->update();
1861  }
1862 
1863  if (!$options->isTreeCopyDisabled() && !$a_omit_tree) {
1864  ilLoggerFactory::getLogger('obj')->debug('Tree copy is enabled');
1865  $new_obj->createReference();
1866  $new_obj->putInTree($a_target_id);
1867  $new_obj->setPermissions($a_target_id);
1868 
1869  // when copying from personal workspace we have no current ref id
1870  if ($this->getRefId()) {
1871  // copy local roles
1872  $rbacadmin->copyLocalRoles($this->getRefId(), $new_obj->getRefId());
1873  }
1874  } else {
1875  ilLoggerFactory::getLogger('obj')->debug('Tree copy is disabled');
1876  }
1877 
1878  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1879  ilAdvancedMDValues::_cloneValues($this->getId(), $new_obj->getId());
1880 
1881  // BEGIN WebDAV: Clone WebDAV properties
1882  $query = "INSERT INTO dav_property (obj_id,node_id,ns,name,value) " .
1883  "SELECT " . $ilDB->quote($new_obj->getId(), 'integer') . ",node_id,ns,name,value " .
1884  "FROM dav_property " .
1885  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
1886  $res = $ilDB->manipulate($query);
1887  // END WebDAV: Clone WebDAV properties
1888 
1890  $customIconFactory = $DIC['object.customicons.factory'];
1891  $customIcon = $customIconFactory->getByObjId($this->getId(), $this->getType());
1892  $customIcon->copy($new_obj->getId());
1893 
1894  $tile_image = $DIC->object()->commonSettings()->tileImage()->getByObjId($this->getId());
1895  $tile_image->copy($new_obj->getId());
1896 
1897  $ilAppEventHandler->raise('Services/Object', 'cloneObject', array(
1898  'object' => $new_obj,
1899  'cloned_from_object' => $this,
1900  ));
1901 
1902  return $new_obj;
1903  }
1904 
1912  public function appendCopyInfo($a_target_id, $a_copy_id)
1913  {
1914  $tree = $this->tree;
1915 
1916  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
1917  $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
1918  if (!$cp_options->isRootNode($this->getRefId())) {
1919  return $this->getTitle();
1920  }
1921  $nodes = $tree->getChilds($a_target_id);
1922 
1923  $title_unique = false;
1924  require_once 'Modules/File/classes/class.ilObjFileAccess.php';
1925  $numberOfCopy = 1;
1926  $handleExtension = ($this->getType() == "file"); // #14883
1927  $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), $numberOfCopy, $handleExtension);
1928  while (!$title_unique) {
1929  $found = 0;
1930  foreach ($nodes as $node) {
1931  if (($title == $node['title']) and ($this->getType() == $node['type'])) {
1932  $found++;
1933  }
1934  }
1935  if ($found > 0) {
1936  $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), ++$numberOfCopy, $handleExtension);
1937  } else {
1938  break;
1939  }
1940  }
1941  return $title;
1942  }
1943 
1956  public function cloneDependencies($a_target_id, $a_copy_id)
1957  {
1958  include_once './Services/Conditions/classes/class.ilConditionHandler.php' ;
1959  ilConditionHandler::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
1960 
1961  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1963  if ($tpl_id) {
1964  include_once './Services/Object/classes/class.ilObjectFactory.php';
1965  $factory = new ilObjectFactory();
1966  $obj = $factory->getInstanceByRefId($a_target_id, false);
1967  if ($obj instanceof ilObject) {
1968  $obj->applyDidacticTemplate($tpl_id);
1969  }
1970  }
1971  return true;
1972  }
1973 
1981  public function cloneMetaData($target_obj)
1982  {
1983  $md = new ilMD($this->getId(), 0, $this->getType());
1984  $md->cloneMD($target_obj->getId(), 0, $target_obj->getType());
1985  return true;
1986  }
1987 
1996  public static function _getIcon(
1997  $a_obj_id = "",
1998  $a_size = "big",
1999  $a_type = "",
2000  $a_offline = false
2001  ) {
2002  global $DIC;
2003 
2004  $ilSetting = $DIC->settings();
2005  $objDefinition = $DIC["objDefinition"];
2006 
2007  if ($a_obj_id == "" && $a_type == "") {
2008  return "";
2009  }
2010 
2011  if ($a_type == "") {
2012  $a_type = ilObject::_lookupType($a_obj_id);
2013  }
2014 
2015  if ($a_size == "") {
2016  $a_size = "big";
2017  }
2018 
2019  if (
2020  $a_obj_id &&
2021  $ilSetting->get('custom_icons')
2022  ) {
2024  $customIconFactory = $DIC['object.customicons.factory'];
2025  $customIcon = $customIconFactory->getPresenterByObjId((int) $a_obj_id, (string) $a_type);
2026  if ($customIcon->exists()) {
2027  $filename = $customIcon->getFullPath();
2028  return $filename . '?tmp=' . filemtime($filename);
2029  }
2030  }
2031 
2032  if (!$a_offline) {
2033  if ($objDefinition->isPluginTypeName($a_type)) {
2034  if ($objDefinition->getClassName($a_type) != "") {
2035  $class_name = "il" . $objDefinition->getClassName($a_type) . 'Plugin';
2036  $location = $objDefinition->getLocation($a_type);
2037  if (is_file($location . "/class." . $class_name . ".php")) {
2038  include_once($location . "/class." . $class_name . ".php");
2039  return call_user_func(array($class_name, "_getIcon"), $a_type, $a_size, $a_obj_id);
2040  }
2041  }
2042  return ilUtil::getImagePath("icon_cmps.svg");
2043  }
2044 
2045  return ilUtil::getImagePath("icon_" . $a_type . ".svg");
2046  } else {
2047  return "./images/icon_" . $a_type . ".svg";
2048  }
2049  }
2050 
2057  public static function collectDeletionDependencies(&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth = 0)
2058  {
2059  global $DIC;
2060 
2061  $objDefinition = $DIC["objDefinition"];
2062  $tree = $DIC->repositoryTree();
2063 
2064  if ($a_depth == 0) {
2065  $deps["dep"] = array();
2066  }
2067 
2068  $deps["del_ids"][$a_obj_id] = $a_obj_id;
2069 
2070  if (!$objDefinition->isPluginTypeName($a_type)) {
2071  $class_name = "ilObj" . $objDefinition->getClassName($a_type);
2072  $location = $objDefinition->getLocation($a_type);
2073  include_once($location . "/class." . $class_name . ".php");
2074  $odeps = call_user_func(array($class_name, "getDeletionDependencies"), $a_obj_id);
2075  if (is_array($odeps)) {
2076  foreach ($odeps as $id => $message) {
2077  $deps["dep"][$id][$a_obj_id][] = $message;
2078  }
2079  }
2080 
2081  // get deletion dependency of childs
2082  foreach ($tree->getChilds($a_ref_id) as $c) {
2083  ilObject::collectDeletionDependencies($deps, $c["child"], $c["obj_id"], $c["type"], $a_depth + 1);
2084  }
2085  }
2086 
2087  // delete all dependencies to objects that will be deleted, too
2088  if ($a_depth == 0) {
2089  foreach ($deps["del_ids"] as $obj_id) {
2090  unset($deps["dep"][$obj_id]);
2091  }
2092  $deps = $deps["dep"];
2093  }
2094  }
2095 
2100  public static function getDeletionDependencies($a_obj_id)
2101  {
2102  return false;
2103  }
2104 
2111  public static function getLongDescriptions(array $a_obj_ids)
2112  {
2113  global $DIC;
2114 
2115  $ilDB = $DIC->database();
2116 
2117  $res = $ilDB->query("SELECT * FROM object_description" .
2118  " WHERE " . $ilDB->in("obj_id", $a_obj_ids, "", "integer"));
2119  $all = array();
2120  while ($row = $ilDB->fetchAssoc($res)) {
2121  $all[$row["obj_id"]] = $row["description"];
2122  }
2123  return $all;
2124  }
2125 
2132  public static function getAllOwnedRepositoryObjects($a_user_id)
2133  {
2134  global $DIC;
2135 
2136  $ilDB = $DIC->database();
2137  $objDefinition = $DIC["objDefinition"];
2138 
2139  $all = array();
2140 
2141  // restrict to repository
2142  $types = array_keys($objDefinition->getSubObjectsRecursively("root"));
2143 
2144  $sql = "SELECT od.obj_id,od.type,od.title FROM object_data od" .
2145  " JOIN object_reference oref ON(oref.obj_id = od.obj_id)" .
2146  " JOIN tree ON (tree.child = oref.ref_id)";
2147 
2148  if ($a_user_id) {
2149  $sql .= " WHERE od.owner = " . $ilDB->quote($a_user_id, "integer");
2150  } else {
2151  $sql .= " LEFT JOIN usr_data ud ON (ud.usr_id = od.owner)" .
2152  " WHERE (od.owner < " . $ilDB->quote(1, "integer") .
2153  " OR od.owner IS NULL OR ud.login IS NULL)" .
2154  " AND od.owner <> " . $ilDB->quote(-1, "integer");
2155  }
2156 
2157  $sql .= " AND " . $ilDB->in("od.type", $types, "", "text") .
2158  " AND tree.tree > " . $ilDB->quote(0, "integer"); // #12485
2159 
2160  $res = $ilDB->query($sql);
2161  while ($row = $ilDB->fetchAssoc($res)) {
2162  $all[$row["type"]][$row["obj_id"]] = $row["title"];
2163  }
2164 
2165  return $all;
2166  }
2167 
2174  public static function fixMissingTitles($a_type, array &$a_obj_title_map)
2175  {
2176  global $DIC;
2177 
2178  $ilDB = $DIC->database();
2179 
2180  if (!in_array($a_type, array("catr", "crsr", "sess", "grpr"))) {
2181  return;
2182  }
2183 
2184  // any missing titles?
2185  $missing_obj_ids = array();
2186  foreach ($a_obj_title_map as $obj_id => $title) {
2187  if (!trim($title)) {
2188  $missing_obj_ids[] = $obj_id;
2189  }
2190  }
2191 
2192  if (!sizeof($missing_obj_ids)) {
2193  return;
2194  }
2195 
2196  switch ($a_type) {
2197  case "grpr":
2198  case "catr":
2199  case "crsr":
2200  $set = $ilDB->query("SELECT oref.obj_id, od.type, od.title FROM object_data od" .
2201  " JOIN container_reference oref ON (od.obj_id = oref.target_obj_id)" .
2202  " AND " . $ilDB->in("oref.obj_id", $missing_obj_ids, "", "integer"));
2203  while ($row = $ilDB->fetchAssoc($set)) {
2204  $a_obj_title_map[$row["obj_id"]] = $row["title"];
2205  }
2206  break;
2207 
2208  case "sess":
2209  include_once "Modules/Session/classes/class.ilObjSession.php";
2210  foreach ($missing_obj_ids as $obj_id) {
2211  $sess = new ilObjSession($obj_id, false);
2212  $a_obj_title_map[$obj_id] = $sess->getFirstAppointment()->appointmentToString();
2213  }
2214  break;
2215  }
2216  }
2217 
2224  public static function _lookupCreationDate($a_id)
2225  {
2226  global $DIC;
2227 
2228  $ilDB = $DIC->database();
2229 
2230  $set = $ilDB->query("SELECT create_date FROM object_data " .
2231  " WHERE obj_id = " . $ilDB->quote($a_id, "integer"));
2232  $rec = $ilDB->fetchAssoc($set);
2233  return $rec["create_date"];
2234  }
2235 
2243  public static function hasAutoRating($a_type, $a_ref_id)
2244  {
2245  global $DIC;
2246 
2247  $tree = $DIC->repositoryTree();
2248 
2249  if (!$a_ref_id ||
2250  !in_array($a_type, array("file", "lm", "wiki"))) {
2251  return false;
2252  }
2253 
2254  // find parent container
2255  $parent_ref_id = $tree->checkForParentType($a_ref_id, "grp");
2256  if (!$parent_ref_id) {
2257  $parent_ref_id = $tree->checkForParentType($a_ref_id, "crs");
2258  }
2259  if ($parent_ref_id) {
2260  include_once './Services/Object/classes/class.ilObjectServiceSettingsGUI.php';
2261 
2262  // get auto rate setting
2263  $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
2265  $parent_obj_id,
2267  false
2268  );
2269  }
2270  return false;
2271  }
2272 
2282  public function getPossibleSubObjects($a_filter = true)
2283  {
2284  return $this->objDefinition->getSubObjects($this->type, $a_filter);
2285  }
2286 } // END class.ilObject
static lookupTemplateId($a_ref_id)
Lookup template id ilDB $ilDB.
static setDeletedDates($a_ref_ids)
Set deleted date.
static getDeletionDependencies($a_obj_id)
Get deletion dependencies.
static _resetDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
static _lookupDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
$path
Definition: aliased.php:25
static removeItemFromDesktops($a_id)
removes object from all user&#39;s desktops public
supportsOfflineHandling()
Check whether object supports offline handling.
Class ilObjectFactory.
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
static shortenText( $a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
const IL_CAL_DATETIME
static lookupTxtById($plugin_id, $lang_var)
__construct($a_id=0, $a_reference=true)
Constructor public.
static _prepareCloneSelection($a_ref_ids, $new_type, $show_path=true)
Prepare copy wizard object selection.
$result
static getLongDescriptions(array $a_obj_ids)
Get long description data.
cloneDependencies($a_target_id, $a_copy_id)
Clone object dependencies.
$action
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.
global $DIC
Definition: saml.php:7
static getAllOwnedRepositoryObjects($a_user_id)
Get all ids of objects user owns.
const TITLE_LENGTH
max length of object title
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
static deleteByRefId($a_ref_id)
Delete by ref_id ilDB $ilDB.
read()
read object data from db into object
$location
Definition: buildRTE.php:44
updateMetaData()
update meta data entry
withReferences()
determines wehter objects are referenced or not (got ref ids or not)
const DESC_LENGTH
getOfflineStatus()
Get offline status.
$factory
Definition: metadata.php:43
setId($a_id)
set object id public
createMetaData()
create meta data entry
static _isInTrash($a_ref_id)
checks wether object is in trash
static _writeTitle($a_obj_id, $a_title)
write title to db (static)
getDiskUsage()
Gets the disk usage of the object in bytes.
static _lookupTitle($a_id)
lookup object title
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
getPossibleSubObjects($a_filter=true)
get all possible subobjects of this type the object can decide which types of subobjects are possible...
getCreateDate()
get create date public
getOwner()
get object owner
static _deleteByObjId($a_obj_id)
Delete by obj_id.
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
static _setDeletedDate($a_ref_id)
only called in ilTree::saveSubTree
static _getAllReferences($a_id)
get all reference ids of object
static _deleteByObjId($a_obj_id)
Delete by objekt id.
$ilErr
Definition: raiseError.php:18
setTitle($a_title)
set object title
static _lookupLastUpdate($a_id, $a_as_string=false)
lookup last update
static collectDeletionDependencies(&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth=0)
Collect deletion dependencies.
static _lookupObjectId($a_ref_id)
lookup object id
const DEBUG
static hasAutoRating($a_type, $a_ref_id)
Check if auto rating is active for parent group/course.
$a_type
Definition: workflow.php:92
createReference()
creates reference for object
static assignTemplate($a_ref_id, $a_obj_id, $a_tpl_id)
Assign template to object ilDB $ilDB.
applyDidacticTemplate($a_tpl_id)
Apply template.
$r
Definition: example_031.php:79
catch(Exception $e) $message
static _getInstance($a_copy_id)
Get instance of copy wizard options.
create()
create
setOwner($a_owner)
set object owner
foreach($_POST as $key=> $value) $res
getId()
get object id public
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.
isUserRegistered($a_user_id=0)
static _lookupCreationDate($a_id)
Lookup creation date.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
$values
static _lookupDescription($a_id)
lookup object description
static lookupOfflineStatus($a_obj_id)
Lookup offline status using objectDataCache.
static _lookupObjId($a_id)
static add(ilObject $a_object)
setRefId($a_id)
set reference id public
getTitle()
get object title public
static _deleteSettingsOfBlock($a_block_id, $a_block_type)
Delete block settings of block.
updateOwner()
update owner of object in db
getDescription()
get object description
getImportId()
get import id
Date and time handling
$ilUser
Definition: imgupload.php:18
redirection script todo: (a better solution should control the processing via a xml file) ...
cloneMetaData($target_obj)
Copy meta data.
static _lookupOwner($a_id)
lookup object owner
$query
initDefaultRoles()
init default roles settings Purpose of this function is to create a local role folder and local roles...
static _lookupImportId($a_obj_id)
putInTree($a_parent_ref)
maybe this method should be in tree object!?
getType()
get object type public
appendCopyInfo($a_target_id, $a_copy_id)
Prepend Copy info if object with same name exists in that container.
static _lookupType($a_id, $a_reference=false)
lookup object type
static deleteAllEntries($a_ref_id)
Delete all db entries for ref id.
$filename
Definition: buildRTE.php:89
setImportId($a_import_id)
set import id
$row
INTERNAL CLASS: Please do not use in consumer code.
static _writeDescription($a_obj_id, $a_desc)
write description to db (static)
static delete($a_ref_id)
static _getLastUpdateOfObjects($a_objs)
Get last update for a set of media objects.
static fixMissingTitles($a_type, array &$a_obj_title_map)
Try to fix missing object titles.
global $ilSetting
Definition: privfeed.php:17
setOfflineStatus($a_status)
Set offline status.
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
global $ilDB
getLongDescription()
get object long description (stored in object_description)
getRefId()
get reference id public
static _getIdsForTitle($title, $type='', $partialmatch=false)
countReferences()
count references of object
deleteMetaData()
delete meta data entry
static deleteByObjId($a_obj_id)
Delete by obj id ilDB $ilDB.
setDescription($a_desc)
set object description
static getLogger($a_component_id)
Get component logger.
static cloneDependencies($a_src_ref_id, $a_target_ref_id, $a_copy_id)
update()
update object in db
getLastUpdateDate()
get last update date public
static _deleteByObjId($a_obj_id)
getUntranslatedTitle()
get untranslated object title public
setType($a_type)
set object type public
static _lookupOwnerName($a_owner_id)
lookup owner name for owner id
setPermissions($a_parent_ref)
set permissions of object
static _getObjectsDataForType($a_type, $a_omit_trash=false)
get all objects of a certain type
setParentRolePermissions($a_parent_ref)
Initialize the permissions of parent roles (local roles of categories, global roles...) This method is overwritten in e.g courses, groups for building permission intersections with non_member templates.
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
static _lookupObjIdByImportId($a_import_id)
getPresentationTitle()
get presentation title Normally same as title Overwritten for sessions
static getActionsByTemplateId($a_tpl_id)
Get actions of one template.
static _getIdForImportId($a_import_id)
get current object id for import id (static)
MDUpdateListener($a_element)
Meta data update listener.
setRegisterMode($a_bool)