ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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);
306  $row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
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() : int
321  {
322  return (int) $this->id;
323  }
324 
330  public function setId($a_id)
331  {
332  $this->id = (int) $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 
1120  public static function _setDeletedDate($a_ref_id, $a_deleted_by)
1121  {
1122  global $DIC;
1123 
1124  $ilDB = $DIC->database();
1125  $query = "UPDATE object_reference SET " .
1126  'deleted = ' . $ilDB->now() . ', '.
1127  'deleted_by = ' . $ilDB->quote($a_deleted_by, \ilDBConstants::T_INTEGER) . ' ' .
1128  "WHERE ref_id = " . $ilDB->quote($a_ref_id, 'integer');
1129  $res = $ilDB->manipulate($query);
1130  }
1131 
1138  public static function setDeletedDates($a_ref_ids, $a_user_id)
1139  {
1140  global $DIC;
1141 
1142  $ilDB = $DIC->database();
1143 
1144  $query = 'UPDATE object_reference SET ' .
1145  'deleted = ' . $ilDB->now() . ', ' .
1146  'deleted_by = ' . $ilDB->quote($a_user_id, ilDBConstants::T_INTEGER) . ' ' .
1147  'WHERE ' . $ilDB->in('ref_id', (array) $a_ref_ids, false, ilDBConstants::T_INTEGER);
1148  $ilDB->manipulate($query);
1149  return;
1150  }
1151 
1155  public static function _resetDeletedDate($a_ref_id)
1156  {
1157  global $DIC;
1158 
1159  $ilDB = $DIC->database();
1160 
1161  $query = "UPDATE object_reference SET deleted = " . $ilDB->quote(null, 'timestamp'). ', ' .
1162  'deleted_by = ' . $ilDB->quote(0, \ilDBConstants::T_INTEGER). ' '.
1163  " WHERE ref_id = " . $ilDB->quote($a_ref_id, 'integer');
1164  $ilDB->manipulate($query);
1165  }
1166 
1170  public static function _lookupDeletedDate($a_ref_id)
1171  {
1172  global $DIC;
1173 
1174  $ilDB = $DIC->database();
1175 
1176  $query = "SELECT deleted FROM object_reference" .
1177  " WHERE ref_id = " . $ilDB->quote($a_ref_id, "integer");
1178  $set = $ilDB->query($query);
1179  $rec = $ilDB->fetchAssoc($set);
1180 
1181  return $rec["deleted"];
1182  }
1183 
1184 
1192  public static function _writeTitle($a_obj_id, $a_title)
1193  {
1194  global $DIC;
1195 
1196  $ilDB = $DIC->database();
1197 
1198  $q = "UPDATE object_data " .
1199  "SET " .
1200  "title = " . $ilDB->quote($a_title, "text") . "," .
1201  "last_update = " . $ilDB->now() . " " .
1202  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
1203 
1204  $ilDB->manipulate($q);
1205  }
1206 
1214  public static function _writeDescription($a_obj_id, $a_desc)
1215  {
1216  global $DIC;
1217 
1218  $ilDB = $DIC->database();
1219  $objDefinition = $DIC["objDefinition"];
1220 
1221 
1222  $desc = ilUtil::shortenText($a_desc, self::DESC_LENGTH, true);
1223 
1224  $q = "UPDATE object_data " .
1225  "SET " .
1226  "description = " . $ilDB->quote($desc, "text") . "," .
1227  "last_update = " . $ilDB->now() . " " .
1228  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
1229 
1230  $ilDB->manipulate($q);
1231 
1232  if ($objDefinition->isRBACObject(ilObject::_lookupType($a_obj_id))) {
1233  // Update long description
1234  $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = " .
1235  $ilDB->quote($a_obj_id, 'integer'));
1236 
1237  if ($res->numRows()) {
1238  $values = array(
1239  'description' => array('clob',$a_desc)
1240  );
1241  $ilDB->update('object_description', $values, array('obj_id' => array('integer',$a_obj_id)));
1242  } else {
1243  $values = array(
1244  'description' => array('clob',$a_desc),
1245  'obj_id' => array('integer',$a_obj_id));
1246  $ilDB->insert('object_description', $values);
1247  }
1248  }
1249  }
1250 
1258  public static function _writeImportId($a_obj_id, $a_import_id)
1259  {
1260  global $DIC;
1261 
1262  $ilDB = $DIC->database();
1263 
1264  $q = "UPDATE object_data " .
1265  "SET " .
1266  "import_id = " . $ilDB->quote($a_import_id, "text") . "," .
1267  "last_update = " . $ilDB->now() . " " .
1268  "WHERE obj_id = " . $ilDB->quote($a_obj_id, "integer");
1269 
1270  $ilDB->manipulate($q);
1271  }
1272 
1278  public static function _lookupType($a_id, $a_reference = false)
1279  {
1280  global $DIC;
1281 
1282  $ilObjDataCache = $DIC["ilObjDataCache"];
1283 
1284  if ($a_reference) {
1285  return $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_id));
1286  }
1287  return $ilObjDataCache->lookupType($a_id);
1288  }
1289 
1293  public static function _isInTrash($a_ref_id)
1294  {
1295  global $DIC;
1296 
1297  $tree = $DIC->repositoryTree();
1298 
1299  return $tree->isSaved($a_ref_id);
1300  }
1301 
1305  public static function _hasUntrashedReference($a_obj_id)
1306  {
1307  $ref_ids = ilObject::_getAllReferences($a_obj_id);
1308  foreach ($ref_ids as $ref_id) {
1309  if (!ilObject::_isInTrash($ref_id)) {
1310  return true;
1311  }
1312  }
1313 
1314  return false;
1315  }
1316 
1322  public static function _lookupObjectId($a_ref_id)
1323  {
1324  global $DIC;
1325 
1326  $ilObjDataCache = $DIC["ilObjDataCache"];
1327 
1328  return (int) $ilObjDataCache->lookupObjId($a_ref_id);
1329  }
1330 
1341  public static function _getObjectsDataForType($a_type, $a_omit_trash = false)
1342  {
1343  global $DIC;
1344 
1345  $ilDB = $DIC->database();
1346 
1347  $q = "SELECT * FROM object_data WHERE type = " . $ilDB->quote($a_type, "text");
1348  $obj_set = $ilDB->query($q);
1349 
1350  $objects = array();
1351  while ($obj_rec = $ilDB->fetchAssoc($obj_set)) {
1352  if ((!$a_omit_trash) || ilObject::_hasUntrashedReference($obj_rec["obj_id"])) {
1353  $objects[$obj_rec["title"] . "." . $obj_rec["obj_id"]] = array("id" => $obj_rec["obj_id"],
1354  "type" => $obj_rec["type"], "title" => $obj_rec["title"],
1355  "description" => $obj_rec["description"]);
1356  }
1357  }
1358  ksort($objects);
1359  return $objects;
1360  }
1361 
1362 
1370  public function putInTree($a_parent_ref)
1371  {
1372  $tree = $this->tree;
1373  $ilLog = $this->log;
1374  $ilAppEventHandler = $this->app_event_handler;
1375 
1376  $tree->insertNode($this->getRefId(), $a_parent_ref);
1377 
1378  // write log entry
1379  $ilLog->write("ilObject::putInTree(), parent_ref: $a_parent_ref, ref_id: " .
1380  $this->getRefId() . ", obj_id: " . $this->getId() . ", type: " .
1381  $this->getType() . ", title: " . $this->getTitle());
1382 
1383  $ilAppEventHandler->raise(
1384  'Services/Object',
1385  'putObjectInTree',
1386  array(
1387  'object' => $this,
1388  'obj_type' => $this->getType(),
1389  'obj_id' => $this->getId(),
1390  'parent_ref_id' => $a_parent_ref,
1391  )
1392  );
1393  }
1394 
1401  public function setPermissions($a_parent_ref)
1402  {
1403  $this->setParentRolePermissions($a_parent_ref);
1404  $this->initDefaultRoles();
1405  }
1406 
1411  public function setParentRolePermissions($a_parent_ref)
1412  {
1413  global $DIC;
1414 
1415  $rbacadmin = $DIC["rbacadmin"];
1416  $rbacreview = $DIC["rbacreview"];
1417 
1418  $parent_roles = $rbacreview->getParentRoleIds($a_parent_ref);
1419  foreach ((array) $parent_roles as $parent_role) {
1420  $operations = $rbacreview->getOperationsOfRole(
1421  $parent_role['obj_id'],
1422  $this->getType(),
1423  $parent_role['parent']
1424  );
1425  $rbacadmin->grantPermission(
1426  $parent_role['obj_id'],
1427  $operations,
1428  $this->getRefId()
1429  );
1430  }
1431  return true;
1432  }
1433 
1440  public function createReference()
1441  {
1442  $ilDB = $this->db;
1443  $ilErr = $this->error;
1444 
1445  if (!isset($this->id)) {
1446  $message = "ilObject::createNewReference(): No obj_id given!";
1447  $ilErr->raiseError($message, $ilErr->WARNING);
1448  }
1449 
1450  $next_id = $ilDB->nextId('object_reference');
1451  $query = "INSERT INTO object_reference " .
1452  "(ref_id, obj_id) VALUES (" . $ilDB->quote($next_id, 'integer') . ',' . $ilDB->quote($this->id, 'integer') . ")";
1453  $ilDB->query($query);
1454 
1455  $this->ref_id = $next_id;
1456  $this->referenced = true;
1457 
1458  return $this->ref_id;
1459  }
1460 
1461 
1468  public function countReferences()
1469  {
1470  $ilDB = $this->db;
1471  $ilErr = $this->error;
1472 
1473  if (!isset($this->id)) {
1474  $message = "ilObject::countReferences(): No obj_id given!";
1475  $ilErr->raiseError($message, $ilErr->WARNING);
1476  }
1477 
1478  $query = "SELECT COUNT(ref_id) num FROM object_reference " .
1479  "WHERE obj_id = " . $ilDB->quote($this->id, 'integer') . " ";
1480  $res = $ilDB->query($query);
1481  $row = $ilDB->fetchObject($res);
1482 
1483  return $row->num;
1484  }
1485 
1486 
1497  public function delete()
1498  {
1499  global $DIC;
1500 
1501  $rbacadmin = $DIC["rbacadmin"];
1502  $ilLog = $this->log;
1503  $ilDB = $this->db;
1504  $ilAppEventHandler = $this->app_event_handler;
1505  $ilErr = $this->error;
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  /* remove notes (see infoscreen gui)
1558  as they can be seen as personal data we are keeping them for now
1559  include_once("Services/Notes/classes/class.ilNote.php");
1560  foreach(array(IL_NOTE_PRIVATE, IL_NOTE_PUBLIC) as $note_type)
1561  {
1562  foreach(ilNote::_getNotesOfObject($this->id, 0, $this->type, $note_type) as $note)
1563  {
1564  $note->delete();
1565  }
1566  }
1567  */
1568 
1569  // BEGIN WebDAV: Delete WebDAV properties
1570  $query = "DELETE FROM dav_property " .
1571  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
1572  $res = $ilDB->manipulate($query);
1573  // END WebDAV: Delete WebDAV properties
1574 
1575  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
1577 
1578  include_once("Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
1580 
1581  include_once("Services/Tracking/classes/class.ilLPObjSettings.php");
1583 
1584  $remove = true;
1585  } else {
1586  // write log entry
1587  $ilLog->write("ilObject::delete(), object not deleted, number of references: " .
1588  $this->countReferences() . ", obj_id: " . $this->getId() . ", type: " .
1589  $this->getType() . ", title: " . $this->getTitle());
1590  }
1591 
1592  // delete object_reference entry
1593  if ($this->referenced) {
1594  include_once "Services/Object/classes/class.ilObjectActivation.php";
1596 
1597  $ilAppEventHandler->raise('Services/Object', 'deleteReference', array( 'ref_id' => $this->getRefId()));
1598 
1599  // delete entry in object_reference
1600  $query = "DELETE FROM object_reference " .
1601  "WHERE ref_id = " . $ilDB->quote($this->getRefId(), 'integer');
1602  $res = $ilDB->manipulate($query);
1603 
1604  // write log entry
1605  $ilLog->write("ilObject::delete(), reference deleted, ref_id: " . $this->getRefId() .
1606  ", obj_id: " . $this->getId() . ", type: " .
1607  $this->getType() . ", title: " . $this->getTitle());
1608 
1609  // DELETE PERMISSION ENTRIES IN RBAC_PA
1610  // DONE: method overwritten in ilObjRole & ilObjUser.
1611  // this call only applies for objects in rbac (not usr,role,rolt)
1612  // TODO: Do this for role templates too
1613  $rbacadmin->revokePermission($this->getRefId(), 0, false);
1614 
1615  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
1616  ilRbacLog::delete($this->getRefId());
1617 
1618  // Remove applied didactic template setting
1619  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1621  }
1622 
1623  // remove conditions
1624  if ($this->referenced) {
1625  $ch = new ilConditionHandler();
1626  $ch->delete($this->getRefId());
1627  unset($ch);
1628  }
1629 
1630  return $remove;
1631  }
1632 
1640  public function initDefaultRoles()
1641  {
1642  return array();
1643  }
1644 
1645 
1650  public function applyDidacticTemplate($a_tpl_id)
1651  {
1652  ilLoggerFactory::getLogger('obj')->debug('Applying didactic template with id: ' . (int) $a_tpl_id);
1653  if ($a_tpl_id) {
1654  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
1655  foreach (ilDidacticTemplateActionFactory::getActionsByTemplateId($a_tpl_id) as $action) {
1656  $action->setRefId($this->getRefId());
1657  $action->apply();
1658  }
1659  }
1660 
1661  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1662  ilDidacticTemplateObjSettings::assignTemplate($this->getRefId(), $this->getId(), (int) $a_tpl_id);
1663  return $a_tpl_id ? true : false;
1664  }
1665 
1675  public static function _exists($a_id, $a_reference = false, $a_type = null)
1676  {
1677  global $DIC;
1678 
1679  $ilDB = $DIC->database();
1680 
1681  if ($a_reference) {
1682  $q = "SELECT * FROM object_data " .
1683  "LEFT JOIN object_reference ON object_reference.obj_id=object_data.obj_id " .
1684  "WHERE object_reference.ref_id= " . $ilDB->quote($a_id, "integer");
1685  } else {
1686  $q = "SELECT * FROM object_data WHERE obj_id=" . $ilDB->quote($a_id, "integer");
1687  }
1688 
1689  if ($a_type) {
1690  $q .= " AND object_data.type = " . $ilDB->quote($a_type, "text");
1691  }
1692 
1693  $r = $ilDB->query($q);
1694 
1695  return $ilDB->numRows($r) ? true : false;
1696  }
1697 
1698  // toggle subscription interface
1699  public function setRegisterMode($a_bool)
1700  {
1701  $this->register = (bool) $a_bool;
1702  }
1703 
1704  // check register status of current user
1705  // abstract method; overwrite in object type class
1706  public function isUserRegistered($a_user_id = 0)
1707  {
1708  return false;
1709  }
1710 
1711  public function requireRegistration()
1712  {
1713  return $this->register;
1714  }
1715 
1716 
1717  public function getXMLZip()
1718  {
1719  return false;
1720  }
1721  public function getHTMLDirectory()
1722  {
1723  return false;
1724  }
1725 
1729  public static function _getObjectsByType($a_obj_type = "", $a_owner = "")
1730  {
1731  global $DIC;
1732 
1733  $ilDB = $DIC->database();
1734 
1735  $order = " ORDER BY title";
1736 
1737  // where clause
1738  if ($a_obj_type) {
1739  $where_clause = "WHERE type = " .
1740  $ilDB->quote($a_obj_type, "text");
1741 
1742  if ($a_owner != "") {
1743  $where_clause .= " AND owner = " . $ilDB->quote($a_owner, "integer");
1744  }
1745  }
1746 
1747  $q = "SELECT * FROM object_data " . $where_clause . $order;
1748  $r = $ilDB->query($q);
1749 
1750  $arr = array();
1751  if ($ilDB->numRows($r) > 0) {
1752  while ($row = $ilDB->fetchAssoc($r)) {
1753  $row["desc"] = $row["description"];
1754  $arr[$row["obj_id"]] = $row;
1755  }
1756  }
1757 
1758  return $arr;
1759  }
1760 
1773  public static function _prepareCloneSelection($a_ref_ids, $new_type, $show_path = true)
1774  {
1775  global $DIC;
1776 
1777  $ilDB = $DIC->database();
1778  $lng = $DIC->language();
1779  $objDefinition = $DIC["objDefinition"];
1780 
1781  $query = "SELECT obj_data.title obj_title,path_data.title path_title,child FROM tree " .
1782  "JOIN object_reference obj_ref ON child = obj_ref.ref_id " .
1783  "JOIN object_data obj_data ON obj_ref.obj_id = obj_data.obj_id " .
1784  "JOIN object_reference path_ref ON parent = path_ref.ref_id " .
1785  "JOIN object_data path_data ON path_ref.obj_id = path_data.obj_id " .
1786  "WHERE " . $ilDB->in("child", $a_ref_ids, false, "integer") . " " .
1787  "ORDER BY obj_data.title ";
1788  $res = $ilDB->query($query);
1789 
1790  if (!$objDefinition->isPlugin($new_type)) {
1791  $options[0] = $lng->txt('obj_' . $new_type . '_select');
1792  } else {
1793  require_once("Services/Repository/classes/class.ilObjectPlugin.php");
1794  $options[0] = ilObjectPlugin::lookupTxtById($new_type, "obj_" . $new_type . "_select");
1795  }
1796 
1797  while ($row = $ilDB->fetchObject($res)) {
1798  if (strlen($title = $row->obj_title) > 40) {
1799  $title = substr($title, 0, 40) . '...';
1800  }
1801 
1802  if ($show_path) {
1803  if (strlen($path = $row->path_title) > 40) {
1804  $path = substr($path, 0, 40) . '...';
1805  }
1806 
1807  $title .= ' (' . $lng->txt('path') . ': ' . $path . ')';
1808  }
1809 
1810  $options[$row->child] = $title;
1811  }
1812  return $options ? $options : array();
1813  }
1814 
1824  public function cloneObject($a_target_id, $a_copy_id = 0, $a_omit_tree = false)
1825  {
1826  global $DIC;
1827 
1829  $ilUser = $DIC["ilUser"];
1830  $rbacadmin = $DIC["rbacadmin"];
1831  $ilDB = $this->db;
1832  $ilAppEventHandler = $this->app_event_handler;
1837  $location = $objDefinition->getLocation($this->getType());
1838  $class_name = ('ilObj' . $objDefinition->getClassName($this->getType()));
1839 
1840  include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1841  $options = ilCopyWizardOptions::_getInstance($a_copy_id);
1842 
1843  if (!$options->isTreeCopyDisabled() && !$a_omit_tree) {
1844  $title = $this->appendCopyInfo($a_target_id, $a_copy_id);
1845  } else {
1846  $title = $this->getTitle();
1847  }
1848 
1849  // create instance
1850  include_once($location . "/class." . $class_name . ".php");
1851  $new_obj = new $class_name(0, false);
1852  $new_obj->setOwner($ilUser->getId());
1853  $new_obj->setTitle($title);
1854  $new_obj->setDescription($this->getLongDescription());
1855  $new_obj->setType($this->getType());
1856 
1857  // Choose upload mode to avoid creation of additional settings, db entries ...
1858  $new_obj->create(true);
1859 
1860  if ($this->supportsOfflineHandling()) {
1861  $new_obj->setOffLineStatus($this->getOfflineStatus());
1862  $new_obj->update();
1863  }
1864 
1865  if (!$options->isTreeCopyDisabled() && !$a_omit_tree) {
1866  ilLoggerFactory::getLogger('obj')->debug('Tree copy is enabled');
1867  $new_obj->createReference();
1868  $new_obj->putInTree($a_target_id);
1869  $new_obj->setPermissions($a_target_id);
1870 
1871  // when copying from personal workspace we have no current ref id
1872  if ($this->getRefId()) {
1873  // copy local roles
1874  $rbacadmin->copyLocalRoles($this->getRefId(), $new_obj->getRefId());
1875  }
1876  } else {
1877  ilLoggerFactory::getLogger('obj')->debug('Tree copy is disabled');
1878  }
1879 
1880  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1881  ilAdvancedMDValues::_cloneValues($this->getId(), $new_obj->getId());
1882 
1883  // BEGIN WebDAV: Clone WebDAV properties
1884  $query = "INSERT INTO dav_property (obj_id,node_id,ns,name,value) " .
1885  "SELECT " . $ilDB->quote($new_obj->getId(), 'integer') . ",node_id,ns,name,value " .
1886  "FROM dav_property " .
1887  "WHERE obj_id = " . $ilDB->quote($this->getId(), 'integer');
1888  $res = $ilDB->manipulate($query);
1889  // END WebDAV: Clone WebDAV properties
1890 
1892  $customIconFactory = $DIC['object.customicons.factory'];
1893  $customIcon = $customIconFactory->getByObjId($this->getId(), $this->getType());
1894  $customIcon->copy($new_obj->getId());
1895 
1896  $tile_image = $DIC->object()->commonSettings()->tileImage()->getByObjId($this->getId());
1897  $tile_image->copy($new_obj->getId());
1898 
1899  $ilAppEventHandler->raise('Services/Object', 'cloneObject', array(
1900  'object' => $new_obj,
1901  'cloned_from_object' => $this,
1902  ));
1903 
1904  return $new_obj;
1905  }
1906 
1914  public function appendCopyInfo($a_target_id, $a_copy_id)
1915  {
1916  $tree = $this->tree;
1917 
1918  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
1919  $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
1920  if (!$cp_options->isRootNode($this->getRefId())) {
1921  return $this->getTitle();
1922  }
1923  $nodes = $tree->getChilds($a_target_id);
1924 
1925  $title_unique = false;
1926  require_once 'Modules/File/classes/class.ilObjFileAccess.php';
1927  $numberOfCopy = 1;
1928  $handleExtension = ($this->getType() == "file"); // #14883
1929  $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), $numberOfCopy, $handleExtension);
1930  while (!$title_unique) {
1931  $found = 0;
1932  foreach ($nodes as $node) {
1933  if (($title == $node['title']) and ($this->getType() == $node['type'])) {
1934  $found++;
1935  }
1936  }
1937  if ($found > 0) {
1938  $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), ++$numberOfCopy, $handleExtension);
1939  } else {
1940  break;
1941  }
1942  }
1943  return $title;
1944  }
1945 
1958  public function cloneDependencies($a_target_id, $a_copy_id)
1959  {
1960  include_once './Services/Conditions/classes/class.ilConditionHandler.php' ;
1961  ilConditionHandler::cloneDependencies($this->getRefId(), $a_target_id, $a_copy_id);
1962 
1963  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1965  if ($tpl_id) {
1966  include_once './Services/Object/classes/class.ilObjectFactory.php';
1967  $factory = new ilObjectFactory();
1968  $obj = $factory->getInstanceByRefId($a_target_id, false);
1969  if ($obj instanceof ilObject) {
1970  $obj->applyDidacticTemplate($tpl_id);
1971  }
1972  }
1973  return true;
1974  }
1975 
1983  public function cloneMetaData($target_obj)
1984  {
1985  $md = new ilMD($this->getId(), 0, $this->getType());
1986  $md->cloneMD($target_obj->getId(), 0, $target_obj->getType());
1987  return true;
1988  }
1989 
1998  public static function _getIcon(
1999  $a_obj_id = "",
2000  $a_size = "big",
2001  $a_type = "",
2002  $a_offline = false
2003  ) {
2004  global $DIC;
2005 
2006  $ilSetting = $DIC->settings();
2007  $objDefinition = $DIC["objDefinition"];
2008 
2009  if ($a_obj_id == "" && $a_type == "") {
2010  return "";
2011  }
2012 
2013  if ($a_type == "") {
2014  $a_type = ilObject::_lookupType($a_obj_id);
2015  }
2016 
2017  if ($a_size == "") {
2018  $a_size = "big";
2019  }
2020 
2021  if (
2022  $a_obj_id &&
2023  $ilSetting->get('custom_icons')
2024  ) {
2026  $customIconFactory = $DIC['object.customicons.factory'];
2027  $customIcon = $customIconFactory->getPresenterByObjId((int) $a_obj_id, (string) $a_type);
2028  if ($customIcon->exists()) {
2029  $filename = $customIcon->getFullPath();
2030  return $filename . '?tmp=' . filemtime($filename);
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 
2059  public static function collectDeletionDependencies(&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth = 0)
2060  {
2061  global $DIC;
2062 
2063  $objDefinition = $DIC["objDefinition"];
2064  $tree = $DIC->repositoryTree();
2065 
2066  if ($a_depth == 0) {
2067  $deps["dep"] = array();
2068  }
2069 
2070  $deps["del_ids"][$a_obj_id] = $a_obj_id;
2071 
2072  if (!$objDefinition->isPluginTypeName($a_type)) {
2073  $class_name = "ilObj" . $objDefinition->getClassName($a_type);
2074  $location = $objDefinition->getLocation($a_type);
2075  include_once($location . "/class." . $class_name . ".php");
2076  $odeps = call_user_func(array($class_name, "getDeletionDependencies"), $a_obj_id);
2077  if (is_array($odeps)) {
2078  foreach ($odeps as $id => $message) {
2079  $deps["dep"][$id][$a_obj_id][] = $message;
2080  }
2081  }
2082 
2083  // get deletion dependency of childs
2084  foreach ($tree->getChilds($a_ref_id) as $c) {
2085  ilObject::collectDeletionDependencies($deps, $c["child"], $c["obj_id"], $c["type"], $a_depth + 1);
2086  }
2087  }
2088 
2089  // delete all dependencies to objects that will be deleted, too
2090  if ($a_depth == 0) {
2091  foreach ($deps["del_ids"] as $obj_id) {
2092  unset($deps["dep"][$obj_id]);
2093  }
2094  $deps = $deps["dep"];
2095  }
2096  }
2097 
2102  public static function getDeletionDependencies($a_obj_id)
2103  {
2104  return false;
2105  }
2106 
2113  public static function getLongDescriptions(array $a_obj_ids)
2114  {
2115  global $DIC;
2116 
2117  $ilDB = $DIC->database();
2118 
2119  $res = $ilDB->query("SELECT * FROM object_description" .
2120  " WHERE " . $ilDB->in("obj_id", $a_obj_ids, "", "integer"));
2121  $all = array();
2122  while ($row = $ilDB->fetchAssoc($res)) {
2123  $all[$row["obj_id"]] = $row["description"];
2124  }
2125  return $all;
2126  }
2127 
2134  public static function getAllOwnedRepositoryObjects($a_user_id)
2135  {
2136  global $DIC;
2137 
2138  $ilDB = $DIC->database();
2139  $objDefinition = $DIC["objDefinition"];
2140 
2141  $all = array();
2142 
2143  // restrict to repository
2144  $types = array_keys($objDefinition->getSubObjectsRecursively("root"));
2145 
2146  $sql = "SELECT od.obj_id,od.type,od.title FROM object_data od" .
2147  " JOIN object_reference oref ON(oref.obj_id = od.obj_id)" .
2148  " JOIN tree ON (tree.child = oref.ref_id)";
2149 
2150  if ($a_user_id) {
2151  $sql .= " WHERE od.owner = " . $ilDB->quote($a_user_id, "integer");
2152  } else {
2153  $sql .= " LEFT JOIN usr_data ud ON (ud.usr_id = od.owner)" .
2154  " WHERE (od.owner < " . $ilDB->quote(1, "integer") .
2155  " OR od.owner IS NULL OR ud.login IS NULL)" .
2156  " AND od.owner <> " . $ilDB->quote(-1, "integer");
2157  }
2158 
2159  $sql .= " AND " . $ilDB->in("od.type", $types, "", "text") .
2160  " AND tree.tree > " . $ilDB->quote(0, "integer"); // #12485
2161 
2162  $res = $ilDB->query($sql);
2163  while ($row = $ilDB->fetchAssoc($res)) {
2164  $all[$row["type"]][$row["obj_id"]] = $row["title"];
2165  }
2166 
2167  return $all;
2168  }
2169 
2176  public static function fixMissingTitles($a_type, array &$a_obj_title_map)
2177  {
2178  global $DIC;
2179 
2180  $ilDB = $DIC->database();
2181 
2182  if (!in_array($a_type, array("catr", "crsr", "sess", "grpr", "prgr"))) {
2183  return;
2184  }
2185 
2186  // any missing titles?
2187  $missing_obj_ids = array();
2188  foreach ($a_obj_title_map as $obj_id => $title) {
2189  if (!trim($title)) {
2190  $missing_obj_ids[] = $obj_id;
2191  }
2192  }
2193 
2194  if (!sizeof($missing_obj_ids)) {
2195  return;
2196  }
2197 
2198  switch ($a_type) {
2199  case "grpr":
2200  case "catr":
2201  case "crsr":
2202  case "prgr":
2203  $set = $ilDB->query("SELECT oref.obj_id, od.type, od.title FROM object_data od" .
2204  " JOIN container_reference oref ON (od.obj_id = oref.target_obj_id)" .
2205  " AND " . $ilDB->in("oref.obj_id", $missing_obj_ids, "", "integer"));
2206  while ($row = $ilDB->fetchAssoc($set)) {
2207  $a_obj_title_map[$row["obj_id"]] = $row["title"];
2208  }
2209  break;
2210 
2211  case "sess":
2212  include_once "Modules/Session/classes/class.ilObjSession.php";
2213  foreach ($missing_obj_ids as $obj_id) {
2214  $sess = new ilObjSession($obj_id, false);
2215  $a_obj_title_map[$obj_id] = $sess->getFirstAppointment()->appointmentToString();
2216  }
2217  break;
2218  }
2219  }
2220 
2227  public static function _lookupCreationDate($a_id)
2228  {
2229  global $DIC;
2230 
2231  $ilDB = $DIC->database();
2232 
2233  $set = $ilDB->query("SELECT create_date FROM object_data " .
2234  " WHERE obj_id = " . $ilDB->quote($a_id, "integer"));
2235  $rec = $ilDB->fetchAssoc($set);
2236  return $rec["create_date"];
2237  }
2238 
2246  public static function hasAutoRating($a_type, $a_ref_id)
2247  {
2248  global $DIC;
2249 
2250  $tree = $DIC->repositoryTree();
2251 
2252  if (!$a_ref_id ||
2253  !in_array($a_type, array("file", "lm", "wiki"))) {
2254  return false;
2255  }
2256 
2257  // find parent container
2258  $parent_ref_id = $tree->checkForParentType($a_ref_id, "grp");
2259  if (!$parent_ref_id) {
2260  $parent_ref_id = $tree->checkForParentType($a_ref_id, "crs");
2261  }
2262  if ($parent_ref_id) {
2263  include_once './Services/Object/classes/class.ilObjectServiceSettingsGUI.php';
2264 
2265  // get auto rate setting
2266  $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
2268  $parent_obj_id,
2270  false
2271  );
2272  }
2273  return false;
2274  }
2275 
2285  public function getPossibleSubObjects($a_filter = true)
2286  {
2287  return $this->objDefinition->getSubObjects($this->type, $a_filter);
2288  }
2289 } // END class.ilObject
static lookupTemplateId($a_ref_id)
Lookup template id ilDB $ilDB.
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
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.
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 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
static setDeletedDates($a_ref_ids, $a_user_id)
Set deleted date.
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.
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 _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.
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)
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
$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
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
$DIC
Definition: xapitoken.php:46
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.
$message
Definition: xapiexit.php:14
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.
$factory
Definition: metadata.php:58
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=null)
Lookup a container setting.
static _setDeletedDate($a_ref_id, $a_deleted_by)
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)