ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 
4 
14 class ilObject
15 {
19  const TITLE_LENGTH = 255; // title column max length in db
20  const DESC_LENGTH = 128; // (short) description column max length in db
21 
22 
28  var $ilias;
29 
35  var $lng;
36 
42  var $id; // true object_id!!!!
43  var $ref_id;// reference_id
44  var $type;
45  var $title;
46  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
48  // END WebDAV: WebDAV needs to access the untranslated title of an object
49  var $desc;
51  var $owner;
55  var $register = false; // registering required for object? set to true to implement a subscription interface
56 
63 
70 
76 
81  var $max_desc;
82 
87  var $add_dots;
88 
93 
100  function ilObject($a_id = 0, $a_reference = true)
101  {
102  global $ilias, $lng, $ilBench, $objDefinition;
103 
104  $ilBench->start("Core", "ilObject_Constructor");
105 
106  if (DEBUG)
107  {
108  echo "<br/><font color=\"red\">type(".$this->type.") id(".$a_id.") referenced(".$a_reference.")</font>";
109  }
110 
111  $this->ilias =& $ilias;
112  $this->lng =& $lng;
113  $this->objDefinition = $objDefinition;
114 
115  $this->max_title = self::TITLE_LENGTH;
116  $this->max_desc = self::DESC_LENGTH;
117  $this->add_dots = true;
118 
119  $this->referenced = $a_reference;
120  $this->call_by_reference = $a_reference;
121 
122  if ($a_id == 0)
123  {
124  $this->referenced = false; // newly created objects are never referenced
125  } // they will get referenced if createReference() is called
126 
127  if ($this->referenced)
128  {
129  $this->ref_id = $a_id;
130  }
131  else
132  {
133  $this->id = $a_id;
134  }
135  // read object data
136  if ($a_id != 0)
137  {
138  $this->read();
139  }
140 
141  $ilBench->stop("Core", "ilObject_Constructor");
142  }
143 
147  function withReferences()
148  {
149  // both vars could differ. this method should always return true if one of them is true without changing their status
150  return ($this->call_by_reference) ? true : $this->referenced;
151  }
152 
153 
159  function read($a_force_db = false)
160  {
161  global $objDefinition, $ilBench, $ilDB, $log;
162 
163  $ilBench->start("Core", "ilObject_read");
164  if (isset($this->obj_data_record) && !$a_force_db)
165  {
166  $obj = $this->obj_data_record;
167  }
168  else if ($this->referenced)
169  {
170  // check reference id
171  if (!isset($this->ref_id))
172  {
173  $message = "ilObject::read(): No ref_id given! (".$this->type.")";
174  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
175  }
176 
177  // read object data
178  $ilBench->start("Core", "ilObject_read_readData");
179 
180  $q = "SELECT * FROM object_data, object_reference WHERE object_data.obj_id=object_reference.obj_id ".
181  "AND object_reference.ref_id= ".$ilDB->quote($this->ref_id, "integer");
182  $object_set = $ilDB->query($q);
183  $ilBench->stop("Core", "ilObject_read_readData");
184 
185  // check number of records
186  if ($ilDB->numRows($object_set) == 0)
187  {
188  $message = "ilObject::read(): Object with ref_id ".$this->ref_id." not found! (".$this->type.")";
189  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
190  }
191 
192  $obj = $ilDB->fetchAssoc($object_set);
193  }
194  else
195  {
196  // check object id
197  if (!isset($this->id))
198  {
199  $message = "ilObject::read(): No obj_id given! (".$this->type.")";
200  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
201  }
202 
203  // read object data
204  $q = "SELECT * FROM object_data ".
205  "WHERE obj_id = ".$ilDB->quote($this->id, "integer");
206  $object_set = $ilDB->query($q);
207 
208  // check number of records
209  if ($ilDB->numRows($object_set) == 0)
210  {
211  include_once("./Services/Object/exceptions/class.ilObjectNotFoundException.php");
212  throw new ilObjectNotFoundException("ilObject::read(): Object with obj_id: ".$this->id.
213  " (".$this->type.") not found!");
214  return;
215  }
216 
217  $obj = $ilDB->fetchAssoc($object_set);
218  }
219 
220  $this->id = $obj["obj_id"];
221 
222  // check type match (the "xxx" type is used for the unit test)
223  if ($this->type != $obj["type"] && $obj["type"] != "xxx")
224  {
225  $message = "ilObject::read(): Type mismatch. Object with obj_id: ".$this->id." ".
226  "was instantiated by type '".$this->type."'. DB type is: ".$obj["type"];
227 
228  // write log entry
229  $log->write($message);
230 
231  // raise error
232  include_once("./Services/Object/exceptions/class.ilObjectTypeMismatchException.php");
233  throw new ilObjectTypeMismatchException($message);
234  return;
235  }
236 
237  $this->type = $obj["type"];
238  $this->title = $obj["title"];
239  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
240  $this->untranslatedTitle = $obj["title"];
241  // END WebDAV: WebDAV needs to access the untranslated title of an object
242  $this->desc = $obj["description"];
243  $this->owner = $obj["owner"];
244  $this->create_date = $obj["create_date"];
245  $this->last_update = $obj["last_update"];
246  $this->import_id = $obj["import_id"];
247 
248  if($objDefinition->isRBACObject($this->getType()))
249  {
250  // Read long description
251  $query = "SELECT * FROM object_description WHERE obj_id = ".$ilDB->quote($this->id,'integer');
252  $res = $this->ilias->db->query($query);
253  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
254  {
255  if(strlen($row->description))
256  {
257  $this->setDescription($row->description);
258  }
259  }
260  }
261 
262  // multilingual support systemobjects (sys) & categories (db)
263  $ilBench->start("Core", "ilObject_Constructor_getTranslation");
264  $translation_type = $objDefinition->getTranslationType($this->type);
265 
266  if ($translation_type == "sys")
267  {
268  $this->title = $this->lng->txt("obj_".$this->type);
269  $this->setDescription($this->lng->txt("obj_".$this->type."_desc"));
270  }
271  elseif ($translation_type == "db")
272  {
273  $q = "SELECT title,description FROM object_translation ".
274  "WHERE obj_id = ".$ilDB->quote($this->id,'integer')." ".
275  "AND lang_code = ".$ilDB->quote($this->ilias->account->getCurrentLanguage(),'text')." ".
276  "AND NOT lang_default = 1";
277  $r = $this->ilias->db->query($q);
278  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
279  if ($row)
280  {
281  $this->title = $row->title;
282  $this->setDescription($row->description);
283  #$this->desc = $row->description;
284  }
285  }
286 
287  $ilBench->stop("Core", "ilObject_Constructor_getTranslation");
288 
289  $ilBench->stop("Core", "ilObject_read");
290  }
291 
297  function getId()
298  {
299  return $this->id;
300  }
301 
307  function setId($a_id)
308  {
309  $this->id = $a_id;
310  }
311 
317  function setRefId($a_id)
318  {
319  $this->ref_id = $a_id;
320  $this->referenced = true;
321  }
322 
328  function getRefId()
329  {
330  return $this->ref_id;
331  }
332 
338  function getType()
339  {
340  return $this->type;
341  }
342 
348  function setType($a_type)
349  {
350  $this->type = $a_type;
351  }
352 
362  public function getPresentationTitle()
363  {
364  return $this->getTitle();
365  }
366 
367 
373  function getTitle()
374  {
375  return $this->title;
376  }
377  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
384  {
386  }
387  // END WebDAV: WebDAV needs to access the untranslated title of an object
388 
395  function setTitle($a_title)
396  {
397  $this->title = ilUtil::shortenText($a_title, $this->max_title, $this->add_dots);
398  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
399  $this->untranslatedTitle = $this->title;
400  // END WebDAV: WebDAV needs to access the untranslated title of an object
401  }
402 
409  function getDescription()
410  {
411  return $this->desc;
412  }
413 
420  function setDescription($a_desc)
421  {
422  // Shortened form is storted in object_data. Long form is stored in object_description
423  $this->desc = ilUtil::shortenText($a_desc, $this->max_desc, $this->add_dots);
424 
425  $this->long_desc = $a_desc;
426 
427  return true;
428  }
429 
437  {
438  return strlen($this->long_desc) ? $this->long_desc : $this->desc;
439  }
440 
447  function getImportId()
448  {
449  return $this->import_id;
450  }
451 
458  function setImportId($a_import_id)
459  {
460  $this->import_id = $a_import_id;
461  }
462 
463  public static function _lookupObjIdByImportId($a_import_id)
464  {
465  global $ilDB;
466 
467  $query = "SELECT * FROM object_data ".
468  "WHERE import_id = ".$ilDB->quote($a_import_id, "text")." ".
469  "ORDER BY create_date DESC";
470  $res = $ilDB->query($query);
471  while($row = $ilDB->fetchObject($res))
472  {
473  return $row->obj_id;
474  }
475  return 0;
476  }
477 
478  public static function _lookupImportId($a_obj_id)
479  {
480  global $ilDB;
481 
482  $query = "SELECT import_id FROM object_data ".
483  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
484  $res = $ilDB->query($query);
485  $row = $ilDB->fetchObject($res);
486  return $row->import_id;
487  }
488 
495  function getOwner()
496  {
497  return $this->owner;
498  }
499 
500  /*
501  * get full name of object owner
502  *
503  * @access public
504  * @return string owner name or unknown
505  */
506  function getOwnerName()
507  {
508  return ilObject::_lookupOwnerName($this->getOwner());
509  }
510 
514  function _lookupOwnerName($a_owner_id)
515  {
516  global $lng;
517 
518  if ($a_owner_id != -1)
519  {
520  if (ilObject::_exists($a_owner_id))
521  {
522  $owner = new ilObjUser($a_owner_id);
523  }
524  }
525 
526  if (is_object($owner))
527  {
528  $own_name = $owner->getFullname();
529  }
530  else
531  {
532  $own_name = $lng->txt("unknown");
533  }
534 
535  return $own_name;
536  }
537 
544  function setOwner($a_owner)
545  {
546  $this->owner = $a_owner;
547  }
548 
549 
550 
556  function getCreateDate()
557  {
558  return $this->create_date;
559  }
560 
566  function getLastUpdateDate()
567  {
568  return $this->last_update;
569  }
570 
571 
583  function getDiskUsage()
584  {
585  return null;
586  }
587 
596  function setObjDataRecord($a_record)
597  {
598  $this->obj_data_record = $a_record;
599  }
600 
609  function create()
610  {
611  global $ilDB, $log,$ilUser,$objDefinition;
612 
613  if (!isset($this->type))
614  {
615  $message = get_class($this)."::create(): No object type given!";
616  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
617  }
618 
619  // write log entry
620  $log->write("ilObject::create(), start");
621 
622  $this->title = ilUtil::shortenText($this->getTitle(), $this->max_title, $this->add_dots);
623  $this->desc = ilUtil::shortenText($this->getDescription(), $this->max_desc, $this->add_dots);
624 
625  // determine owner
626  if ($this->getOwner() > 0)
627  {
628  $owner = $this->getOwner();
629  }
630  elseif(is_object($ilUser))
631  {
632  $owner = $ilUser->getId();
633  }
634  else
635  {
636  $owner = 0;
637  }
638  $this->id = $ilDB->nextId("object_data");
639  $q = "INSERT INTO object_data ".
640  "(obj_id,type,title,description,owner,create_date,last_update,import_id) ".
641  "VALUES ".
642  "(".
643  $ilDB->quote($this->id, "integer").",".
644  $ilDB->quote($this->type, "text").",".
645  $ilDB->quote($this->getTitle(), "text").",".
646  $ilDB->quote($this->getDescription(), "text").",".
647  $ilDB->quote($owner, "integer").",".
648  $ilDB->now().",".
649  $ilDB->now().",".
650  $ilDB->quote($this->getImportId(), "text").")";
651 
652  $ilDB->manipulate($q);
653 
654  //$this->id = $ilDB->getLastInsertId();
655 
656 
657  // Save long form of description if is rbac object
658  if($objDefinition->isRBACObject($this->getType()))
659  {
660  $values = array(
661  'obj_id' => array('integer',$this->id),
662  'description' => array('clob', $this->getLongDescription()));
663 //var_dump($values);
664  $ilDB->insert('object_description',$values);
665  }
666 
667 
668  // the line ($this->read();) messes up meta data handling: meta data,
669  // that is not saved at this time, gets lost, so we query for the dates alone
670  //$this->read();
671  $q = "SELECT last_update, create_date FROM object_data".
672  " WHERE obj_id = ".$ilDB->quote($this->id, "integer");
673  $obj_set = $ilDB->query($q);
674  $obj_rec = $ilDB->fetchAssoc($obj_set);
675  $this->last_update = $obj_rec["last_update"];
676  $this->create_date = $obj_rec["create_date"];
677 
678  // set owner for new objects
679  $this->setOwner($owner);
680 
681  // write log entry
682  $log->write("ilObject::create(), finished, obj_id: ".$this->id.", type: ".
683  $this->type.", title: ".$this->getTitle());
684 
685  $GLOBALS['ilAppEventHandler']->raise(
686  'Services/Object',
687  'create',
688  array('obj_id' => $this->id,'obj_type' => $this->type));
689 
690  return $this->id;
691  }
692 
699  function update()
700  {
701  global $objDefinition, $ilDB;
702 
703  $q = "UPDATE object_data ".
704  "SET ".
705  "title = ".$ilDB->quote($this->getTitle(), "text").",".
706  "description = ".$ilDB->quote($this->getDescription(), "text").", ".
707  "import_id = ".$ilDB->quote($this->getImportId(), "text").",".
708  "last_update = ".$ilDB->now()." ".
709  "WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
710  $ilDB->manipulate($q);
711 
712  // the line ($this->read();) messes up meta data handling: meta data,
713  // that is not saved at this time, gets lost, so we query for the dates alone
714  //$this->read();
715  $q = "SELECT last_update FROM object_data".
716  " WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
717  $obj_set = $ilDB->query($q);
718  $obj_rec = $ilDB->fetchAssoc($obj_set);
719  $this->last_update = $obj_rec["last_update"];
720 
721  if($objDefinition->isRBACObject($this->getType()))
722  {
723  // Update long description
724  $res = $this->ilias->db->query("SELECT * FROM object_description WHERE obj_id = ".
725  $ilDB->quote($this->getId(),'integer'));
726  if($res->numRows())
727  {
728  $values = array(
729  'description' => array('clob',$this->getLongDescription())
730  );
731  $ilDB->update('object_description',$values,array('obj_id' => array('integer',$this->getId())));
732  }
733  else
734  {
735  $values = array(
736  'description' => array('clob',$this->getLongDescription()),
737  'obj_id' => array('integer',$this->getId()));
738  $ilDB->insert('object_description',$values);
739  }
740  }
741  $GLOBALS['ilAppEventHandler']->raise(
742  'Services/Object',
743  'update',
744  array('obj_id' => $this->getId(),
745  'obj_type' => $this->getType(),
746  'ref_id' => $this->getRefId()));
747 
748  return true;
749  }
750 
762  function MDUpdateListener($a_element)
763  {
764  include_once 'Services/MetaData/classes/class.ilMD.php';
765 
766  $GLOBALS['ilAppEventHandler']->raise(
767  'Services/Object',
768  'update',
769  array('obj_id' => $this->getId(),
770  'obj_type' => $this->getType(),
771  'ref_id' => $this->getRefId()));
772 
773  switch($a_element)
774  {
775  case 'General':
776 
777  // Update Title and description
778  $md = new ilMD($this->getId(),0, $this->getType());
779  if(!is_object($md_gen = $md->getGeneral()))
780  {
781  return false;
782  }
783  $this->setTitle($md_gen->getTitle());
784 
785  foreach($md_gen->getDescriptionIds() as $id)
786  {
787  $md_des = $md_gen->getDescription($id);
788  $this->setDescription($md_des->getDescription());
789  break;
790  }
791  $this->update();
792  break;
793 
794  default:
795  }
796 
797  return true;
798  }
799 
803  function createMetaData()
804  {
805  include_once 'Services/MetaData/classes/class.ilMDCreator.php';
806 
807  global $ilUser;
808 
809  $md_creator = new ilMDCreator($this->getId(),0,$this->getType());
810  $md_creator->setTitle($this->getTitle());
811  $md_creator->setTitleLanguage($ilUser->getPref('language'));
812  $md_creator->setDescription($this->getLongDescription());
813  $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
814  $md_creator->setKeywordLanguage($ilUser->getPref('language'));
815  $md_creator->setLanguage($ilUser->getPref('language'));
816  $md_creator->create();
817 
818  return true;
819  }
820 
824  function updateMetaData()
825  {
826  include_once("Services/MetaData/classes/class.ilMD.php");
827  include_once("Services/MetaData/classes/class.ilMDGeneral.php");
828  include_once("Services/MetaData/classes/class.ilMDDescription.php");
829 
830  $md =& new ilMD($this->getId(), 0, $this->getType());
831  $md_gen =& $md->getGeneral();
832  // BEGIN WebDAV: meta data can be missing sometimes.
833  if ($md_gen == null)
834  {
835  $this->createMetaData();
836  $md =& new ilMD($this->getId(), 0, $this->getType());
837  $md_gen =& $md->getGeneral();
838  }
839  // END WebDAV: meta data can be missing sometimes.
840  $md_gen->setTitle($this->getTitle());
841 
842  // sets first description (maybe not appropriate)
843  $md_des_ids =& $md_gen->getDescriptionIds();
844  if (count($md_des_ids) > 0)
845  {
846  $md_des =& $md_gen->getDescription($md_des_ids[0]);
847  $md_des->setDescription($this->getLongDescription());
848  $md_des->update();
849  }
850  $md_gen->update();
851 
852  }
853 
857  function deleteMetaData()
858  {
859  // Delete meta data
860  include_once('Services/MetaData/classes/class.ilMD.php');
861  $md = new ilMD($this->getId(), 0, $this->getType());
862  $md->deleteAll();
863  }
864 
871  function updateOwner()
872  {
873  global $ilDB;
874 
875  $q = "UPDATE object_data ".
876  "SET ".
877  "owner = ".$ilDB->quote($this->getOwner(), "integer").", ".
878  "last_update = ".$ilDB->now()." ".
879  "WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
880  $ilDB->manipulate($q);
881 
882  $q = "SELECT last_update FROM object_data".
883  " WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
884  $obj_set = $ilDB->query($q);
885  $obj_rec = $ilDB->fetchAssoc($obj_set);
886  $this->last_update = $obj_rec["last_update"];
887 
888  return true;
889  }
890 
898  function _getIdForImportId($a_import_id)
899  {
900  global $ilDB;
901 
902  $ilDB->setLimit(1,0);
903  $q = "SELECT * FROM object_data WHERE import_id = ".$ilDB->quote($a_import_id, "text").
904  " ORDER BY create_date DESC";
905  $obj_set = $ilDB->query($q);
906 
907  if ($obj_rec = $ilDB->fetchAssoc($obj_set))
908  {
909  return $obj_rec["obj_id"];
910  }
911  else
912  {
913  return 0;
914  }
915  }
916 
922  public static function _getAllReferences($a_id)
923  {
924  global $ilDB;
925 
926  $query = "SELECT * FROM object_reference WHERE obj_id = ".
927  $ilDB->quote($a_id,'integer');
928 
929  $res = $ilDB->query($query);
930  $ref = array();
931  while($obj_rec = $ilDB->fetchAssoc($res))
932  {
933  $ref[$obj_rec["ref_id"]] = $obj_rec["ref_id"];
934  }
935 
936  return $ref;
937  }
938 
944  public static function _lookupTitle($a_id)
945  {
946  global $ilObjDataCache;
947 
948  $tit = $ilObjDataCache->lookupTitle($a_id);
949 //echo "<br>LOOKING-$a_id-:$tit";
950  return $tit;
951  }
952 
958  function _lookupOwner($a_id)
959  {
960  global $ilObjDataCache;
961 
962  $owner = $ilObjDataCache->lookupOwner($a_id);
963  return $owner;
964  }
965 
966  public static function _getIdsForTitle($title, $type = '', $partialmatch = false)
967  {
968  global $ilDB;
969 
970  $query = (!$partialmatch)
971  ? "SELECT obj_id FROM object_data WHERE title = ".$ilDB->quote($title, "text")
972  : "SELECT obj_id FROM object_data WHERE ".$ilDB->like("title", "text", '%'.$title.'%');
973  if($type != '')
974  {
975  $query .= " AND type = ".$ilDB->quote($type, "text");
976  }
977 
978  $result = $ilDB->query($query);
979 
980  $object_ids = array();
981  while($row = $ilDB->fetchAssoc($result))
982  {
983  $object_ids[] = $row['obj_id'];
984  }
985 
986  return is_array($object_ids) ? $object_ids : array();
987  }
988 
994  public static function _lookupDescription($a_id)
995  {
996  global $ilObjDataCache;
997 
998  return $ilObjDataCache->lookupDescription($a_id);
999  }
1000 
1006  function _lookupLastUpdate($a_id, $a_as_string = false)
1007  {
1008  global $ilObjDataCache;
1009 
1010  if ($a_as_string)
1011  {
1012  return ilDatePresentation::formatDate(new ilDateTime($ilObjDataCache->lookupLastUpdate($a_id),IL_CAL_DATETIME));
1013  }
1014  else
1015  {
1016  return $ilObjDataCache->lookupLastUpdate($a_id);
1017  }
1018  }
1019 
1025  function _getLastUpdateOfObjects($a_objs)
1026  {
1027  global $ilDB;
1028 
1029  if (!is_array($a_objs))
1030  {
1031  $a_objs = array($a_objs);
1032  }
1033  $types = array();
1034  $set = $ilDB->query("SELECT max(last_update) as last_update FROM object_data ".
1035  "WHERE ".$ilDB->in("obj_id", $a_objs, false, "integer")." ");
1036  $rec = $ilDB->fetchAssoc($set);
1037 
1038  return ($rec["last_update"]);
1039  }
1040 
1041  public static function _lookupObjId($a_id)
1042  {
1043  global $ilObjDataCache;
1044 
1045  return (int) $ilObjDataCache->lookupObjId($a_id);
1046  }
1047 
1051  function _setDeletedDate($a_ref_id)
1052  {
1053  global $ilDB;
1054 
1055  $query = "UPDATE object_reference SET deleted= ".$ilDB->now().' '.
1056  "WHERE ref_id = ".$ilDB->quote($a_ref_id,'integer');
1057  $res = $ilDB->manipulate($query);
1058  }
1059 
1066  public static function setDeletedDates($a_ref_ids)
1067  {
1068  global $ilDB;
1069 
1070  $query = 'UPDATE object_reference SET deleted = '.$ilDB->now().' '.
1071  'WHERE '.$ilDB->in('ref_id',(array) $a_ref_ids,false,'integer');
1072 
1073  $GLOBALS['ilLog']->write(__METHOD__.': Query is '. $query);
1074  $ilDB->manipulate($query);
1075  return;
1076  }
1077 
1081  function _resetDeletedDate($a_ref_id)
1082  {
1083  global $ilDB;
1084 
1085  $query = "UPDATE object_reference SET deleted = ".$ilDB->quote(null,'timestamp').
1086  " WHERE ref_id = ".$ilDB->quote($a_ref_id,'integer');
1087  $res = $ilDB->manipulate($query);
1088  }
1089 
1093  function _lookupDeletedDate($a_ref_id)
1094  {
1095  global $ilDB;
1096 
1097  $query = "SELECT deleted FROM object_reference".
1098  " WHERE ref_id = ".$ilDB->quote($a_ref_id, "integer");
1099  $set = $ilDB->query($query);
1100  $rec = $ilDB->fetchAssoc($set);
1101 
1102  return $rec["deleted"];
1103  }
1104 
1105 
1113  function _writeTitle($a_obj_id, $a_title)
1114  {
1115  global $ilDB;
1116 
1117  $q = "UPDATE object_data ".
1118  "SET ".
1119  "title = ".$ilDB->quote($a_title, "text").",".
1120  "last_update = ".$ilDB->now()." ".
1121  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
1122 
1123  $ilDB->manipulate($q);
1124  }
1125 
1133  function _writeDescription($a_obj_id, $a_desc)
1134  {
1135  global $ilDB,$objDefinition;
1136 
1137 
1138  $desc = ilUtil::shortenText($a_desc,self::DESC_LENGTH,true);
1139 
1140  $q = "UPDATE object_data ".
1141  "SET ".
1142  "description = ".$ilDB->quote($desc, "text").",".
1143  "last_update = ".$ilDB->now()." ".
1144  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
1145 
1146  $ilDB->manipulate($q);
1147 
1148  if($objDefinition->isRBACObject(ilObject::_lookupType($a_obj_id)))
1149  {
1150  // Update long description
1151  $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = ".
1152  $ilDB->quote($a_obj_id,'integer'));
1153 
1154  if($res->numRows())
1155  {
1156  $values = array(
1157  'description' => array('clob',$a_desc)
1158  );
1159  $ilDB->update('object_description',$values,array('obj_id' => array('integer',$a_obj_id)));
1160  }
1161  else
1162  {
1163  $values = array(
1164  'description' => array('clob',$a_desc),
1165  'obj_id' => array('integer',$a_obj_id));
1166  $ilDB->insert('object_description',$values);
1167  }
1168  }
1169  }
1170 
1178  function _writeImportId($a_obj_id, $a_import_id)
1179  {
1180  global $ilDB;
1181 
1182  $q = "UPDATE object_data ".
1183  "SET ".
1184  "import_id = ".$ilDB->quote($a_import_id, "text").",".
1185  "last_update = ".$ilDB->now()." ".
1186  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
1187 
1188  $ilDB->manipulate($q);
1189  }
1190 
1196  public static function _lookupType($a_id,$a_reference = false)
1197  {
1198  global $ilObjDataCache;
1199 
1200  if($a_reference)
1201  {
1202  return $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_id));
1203  }
1204  return $ilObjDataCache->lookupType($a_id);
1205  }
1206 
1210  function _isInTrash($a_ref_id)
1211  {
1212  global $tree;
1213 
1214  return $tree->isSaved($a_ref_id);
1215  }
1216 
1220  function _hasUntrashedReference($a_obj_id)
1221  {
1222  $ref_ids = ilObject::_getAllReferences($a_obj_id);
1223  foreach($ref_ids as $ref_id)
1224  {
1225  if(!ilObject::_isInTrash($ref_id))
1226  {
1227  return true;
1228  }
1229  }
1230 
1231  return false;
1232  }
1233 
1239  public static function _lookupObjectId($a_ref_id)
1240  {
1241  global $ilObjDataCache;
1242 
1243  return (int) $ilObjDataCache->lookupObjId($a_ref_id);
1244  }
1245 
1256  function _getObjectsDataForType($a_type, $a_omit_trash = false)
1257  {
1258  global $ilDB;
1259 
1260  $q = "SELECT * FROM object_data WHERE type = ".$ilDB->quote($a_type, "text");
1261  $obj_set = $ilDB->query($q);
1262 
1263  $objects = array();
1264  while ($obj_rec = $ilDB->fetchAssoc($obj_set))
1265  {
1266  if ((!$a_omit_trash) || ilObject::_hasUntrashedReference($obj_rec["obj_id"]))
1267  {
1268  $objects[$obj_rec["title"].".".$obj_rec["obj_id"]] = array("id" => $obj_rec["obj_id"],
1269  "type" => $obj_rec["type"], "title" => $obj_rec["title"],
1270  "description" => $obj_rec["description"]);
1271  }
1272  }
1273  ksort($objects);
1274  return $objects;
1275  }
1276 
1282  function putInTree($a_parent_ref)
1283  {
1284  global $tree, $log;
1285 
1286  $tree->insertNode($this->getRefId(), $a_parent_ref);
1287 
1288  // write log entry
1289  $log->write("ilObject::putInTree(), parent_ref: $a_parent_ref, ref_id: ".
1290  $this->getRefId().", obj_id: ".$this->getId().", type: ".
1291  $this->getType().", title: ".$this->getTitle());
1292 
1293  }
1294 
1301  function setPermissions($a_parent_ref)
1302  {
1303  $this->setParentRolePermissions($a_parent_ref);
1304  $this->initDefaultRoles();
1305  }
1306 
1311  public function setParentRolePermissions($a_parent_ref)
1312  {
1313  global $rbacadmin, $rbacreview;
1314 
1315  $parent_roles = $rbacreview->getParentRoleIds($a_parent_ref);
1316  foreach((array) $parent_roles as $parent_role)
1317  {
1318  $operations = $rbacreview->getOperationsOfRole(
1319  $parent_role['obj_id'],
1320  $this->getType(),
1321  $parent_role['parent']
1322  );
1323  $rbacadmin->grantPermission(
1324  $parent_role['obj_id'],
1325  $operations,
1326  $this->getRefId()
1327  );
1328  }
1329  return true;
1330  }
1331 
1338  function createReference()
1339  {
1340  global $ilDB;
1341 
1342  if (!isset($this->id))
1343  {
1344  $message = "ilObject::createNewReference(): No obj_id given!";
1345  $this->raiseError($message,$this->ilias->error_obj->WARNING);
1346  }
1347 
1348  $next_id = $ilDB->nextId('object_reference');
1349  $query = "INSERT INTO object_reference ".
1350  "(ref_id, obj_id) VALUES (".$ilDB->quote($next_id,'integer').','.$ilDB->quote($this->id ,'integer').")";
1351  $this->ilias->db->query($query);
1352 
1353  $this->ref_id = $next_id;
1354  $this->referenced = true;
1355 
1356  return $this->ref_id;
1357  }
1358 
1359 
1366  function countReferences()
1367  {
1368  global $ilDB;
1369 
1370  if (!isset($this->id))
1371  {
1372  $message = "ilObject::countReferences(): No obj_id given!";
1373  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
1374  }
1375 
1376  $query = "SELECT COUNT(ref_id) num FROM object_reference ".
1377  "WHERE obj_id = ".$ilDB->quote($this->id,'integer')." ";
1378  $res = $ilDB->query($query);
1379  $row = $ilDB->fetchObject($res);
1380 
1381  return $row->num;
1382  }
1383 
1384 
1385 
1386 
1396  function delete()
1397  {
1398  global $rbacadmin, $log, $ilDB;
1399 
1400  $remove = false;
1401 
1402  // delete object_data entry
1403  if ((!$this->referenced) || ($this->countReferences() == 1))
1404  {
1405  // check type match
1406  $db_type = ilObject::_lookupType($this->getId());
1407  if ($this->type != $db_type)
1408  {
1409  $message = "ilObject::delete(): Type mismatch. Object with obj_id: ".$this->id." ".
1410  "was instantiated by type '".$this->type."'. DB type is: ".$db_type;
1411 
1412  // write log entry
1413  $log->write($message);
1414 
1415  // raise error
1416  $this->ilias->raiseError("ilObject::delete(): Type mismatch. (".$this->type."/".$this->id.")",$this->ilias->error_obj->WARNING);
1417  }
1418 
1419  // delete entry in object_data
1420  $q = "DELETE FROM object_data ".
1421  "WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
1422  $ilDB->manipulate($q);
1423 
1424  // delete long description
1425  $query = "DELETE FROM object_description WHERE obj_id = ".
1426  $ilDB->quote($this->getId(), "integer");
1427  $ilDB->manipulate($query);
1428 
1429  // write log entry
1430  $log->write("ilObject::delete(), deleted object, obj_id: ".$this->getId().", type: ".
1431  $this->getType().", title: ".$this->getTitle());
1432 
1433  // remove news
1434  include_once("./Services/News/classes/class.ilNewsItem.php");
1435  $news_item = new ilNewsItem();
1436  $news_item->deleteNewsOfContext($this->getId(), $this->getType());
1437  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1439 
1440  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1442 
1443  /* remove notes (see infoscreen gui)
1444  as they can be seen as personal data we are keeping them for now
1445  include_once("Services/Notes/classes/class.ilNote.php");
1446  foreach(array(IL_NOTE_PRIVATE, IL_NOTE_PUBLIC) as $note_type)
1447  {
1448  foreach(ilNote::_getNotesOfObject($this->id, 0, $this->type, $note_type) as $note)
1449  {
1450  $note->delete();
1451  }
1452  }
1453  */
1454 
1455  // BEGIN WebDAV: Delete WebDAV properties
1456  $query = "DELETE FROM dav_property ".
1457  "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer');
1458  $res = $ilDB->manipulate($query);
1459  // END WebDAV: Delete WebDAV properties
1460 
1461  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
1463 
1464  include_once("Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
1466 
1467  include_once("Services/Tracking/classes/class.ilLPObjSettings.php");
1469 
1470  $remove = true;
1471  }
1472  else
1473  {
1474  // write log entry
1475  $log->write("ilObject::delete(), object not deleted, number of references: ".
1476  $this->countReferences().", obj_id: ".$this->getId().", type: ".
1477  $this->getType().", title: ".$this->getTitle());
1478  }
1479 
1480  // delete object_reference entry
1481  if ($this->referenced)
1482  {
1483  include_once "Services/Object/classes/class.ilObjectActivation.php";
1485 
1486  // delete entry in object_reference
1487  $query = "DELETE FROM object_reference ".
1488  "WHERE ref_id = ".$ilDB->quote($this->getRefId(),'integer');
1489  $res = $ilDB->manipulate($query);
1490 
1491  // write log entry
1492  $log->write("ilObject::delete(), reference deleted, ref_id: ".$this->getRefId().
1493  ", obj_id: ".$this->getId().", type: ".
1494  $this->getType().", title: ".$this->getTitle());
1495 
1496  // DELETE PERMISSION ENTRIES IN RBAC_PA
1497  // DONE: method overwritten in ilObjRole & ilObjUser.
1498  // this call only applies for objects in rbac (not usr,role,rolt)
1499  // TODO: Do this for role templates too
1500  $rbacadmin->revokePermission($this->getRefId(),0,false);
1501 
1502  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
1503  ilRbacLog::delete($this->getRefId());
1504 
1505  // Remove applied didactic template setting
1506  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1508 
1509  // Remove desktop items
1511  }
1512 
1513  // remove conditions
1514  if ($this->referenced)
1515  {
1516  $ch =& new ilConditionHandler();
1517  $ch->delete($this->getRefId());
1518  unset($ch);
1519  }
1520 
1521  return $remove;
1522  }
1523 
1531  function initDefaultRoles()
1532  {
1533  return array();
1534  }
1535 
1536 
1541  public function applyDidacticTemplate($a_tpl_id)
1542  {
1543  if(!$a_tpl_id)
1544  {
1545  return true;
1546  }
1547 
1548  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1549  ilDidacticTemplateObjSettings::assignTemplate($this->getRefId(), $this->getId(), (int) $a_tpl_id);
1550 
1551  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
1552  foreach(ilDidacticTemplateActionFactory::getActionsByTemplateId($a_tpl_id) as $action)
1553  {
1554  $action->setRefId($this->getRefId());
1555  $action->apply();
1556  }
1557  }
1558 
1568  public static function _exists($a_id, $a_reference = false, $a_type = null)
1569  {
1570  global $ilDB;
1571 
1572  if ($a_reference)
1573  {
1574  $q = "SELECT * FROM object_data ".
1575  "LEFT JOIN object_reference ON object_reference.obj_id=object_data.obj_id ".
1576  "WHERE object_reference.ref_id= ".$ilDB->quote($a_id, "integer");
1577  }
1578  else
1579  {
1580  $q = "SELECT * FROM object_data WHERE obj_id=".$ilDB->quote($a_id, "integer");
1581  }
1582 
1583  if($a_type)
1584  $q .= " AND object_data.type = ".$ilDB->quote($a_type, "text");
1585 
1586  $r = $ilDB->query($q);
1587 
1588  return $ilDB->numRows($r) ? true : false;
1589  }
1590 
1603  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1604  {
1605  global $tree;
1606 
1607  $parent_id = (int) $tree->getParentId($a_node_id);
1608 
1609  if ($parent_id != 0)
1610  {
1611  $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1612  $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
1613  }
1614 
1615  return true;
1616  }
1617 
1618  // toggle subscription interface
1619  function setRegisterMode($a_bool)
1620  {
1621  $this->register = (bool) $a_bool;
1622  }
1623 
1624  // check register status of current user
1625  // abstract method; overwrite in object type class
1626  function isUserRegistered($a_user_id = 0)
1627  {
1628  return false;
1629  }
1630 
1632  {
1633  return $this->register;
1634  }
1635 
1636 
1637  function getXMLZip()
1638  {
1639  return false;
1640  }
1641  function getHTMLDirectory()
1642  {
1643  return false;
1644  }
1645 
1649  static function _getObjectsByType($a_obj_type = "", $a_owner = "")
1650  {
1651  global $ilDB;
1652 
1653  $order = " ORDER BY title";
1654 
1655  // where clause
1656  if ($a_obj_type)
1657  {
1658  $where_clause = "WHERE type = ".
1659  $ilDB->quote($a_obj_type, "text");
1660 
1661  if ($a_owner != "")
1662  {
1663  $where_clause.= " AND owner = ".$ilDB->quote($a_owner, "integer");
1664  }
1665  }
1666 
1667  $q = "SELECT * FROM object_data ".$where_clause.$order;
1668  $r = $ilDB->query($q);
1669 
1670  $arr = array();
1671  if ($ilDB->numRows($r) > 0)
1672  {
1673  while ($row = $ilDB->fetchAssoc($r))
1674  {
1675  $row["desc"] = $row["description"];
1676  $arr[$row["obj_id"]] = $row;
1677  }
1678  }
1679 
1680  return $arr;
1681  }
1682 
1691  public static function _prepareCloneSelection($a_ref_ids,$new_type,$show_path = true)
1692  {
1693  global $ilDB,$lng,$objDefinition;
1694 
1695  $query = "SELECT obj_data.title obj_title,path_data.title path_title,child FROM tree ".
1696  "JOIN object_reference obj_ref ON child = obj_ref.ref_id ".
1697  "JOIN object_data obj_data ON obj_ref.obj_id = obj_data.obj_id ".
1698  "JOIN object_reference path_ref ON parent = path_ref.ref_id ".
1699  "JOIN object_data path_data ON path_ref.obj_id = path_data.obj_id ".
1700  "WHERE ".$ilDB->in("child", $a_ref_ids, false, "integer")." ".
1701  "ORDER BY obj_data.title ";
1702  $res = $ilDB->query($query);
1703 
1704  if (!$objDefinition->isPlugin($new_type))
1705  {
1706  $options[0] = $lng->txt('obj_'.$new_type.'_select');
1707  }
1708  else
1709  {
1710  include_once("./Services/Component/classes/class.ilPlugin.php");
1711  $options[0] = ilPlugin::lookupTxt("rep_robj", $new_type, "obj_".$new_type."_select");
1712  }
1713 
1714  while($row = $ilDB->fetchObject($res))
1715  {
1716  if(strlen($title = $row->obj_title) > 40)
1717  {
1718  $title = substr($title,0,40).'...';
1719  }
1720 
1721  if($show_path)
1722  {
1723  if(strlen($path = $row->path_title) > 40)
1724  {
1725  $path = substr($path,0,40).'...';
1726  }
1727 
1728  $title .= ' ('.$lng->txt('path').': '.$path.')';
1729  }
1730 
1731  $options[$row->child] = $title;
1732  }
1733  return $options ? $options : array();
1734  }
1735 
1745  public function cloneObject($a_target_id,$a_copy_id = 0,$a_omit_tree = false)
1746  {
1747  global $objDefinition,$ilUser,$rbacadmin, $ilDB;
1748 
1749  $location = $objDefinition->getLocation($this->getType());
1750  $class_name = ('ilObj'.$objDefinition->getClassName($this->getType()));
1751 
1752  if(!$a_omit_tree)
1753  {
1754  $title = $this->appendCopyInfo($a_target_id,$a_copy_id);
1755  }
1756  else
1757  {
1758  $title = $this->getTitle();
1759  }
1760 
1761  // create instance
1762  include_once($location."/class.".$class_name.".php");
1763  $new_obj = new $class_name(0, false);
1764  $new_obj->setOwner($ilUser->getId());
1765  $new_obj->setTitle($title);
1766  $new_obj->setDescription($this->getLongDescription());
1767  $new_obj->setType($this->getType());
1768  // Choose upload mode to avoid creation of additional settings, db entries ...
1769  $new_obj->create(true);
1770 
1771  if(!$a_omit_tree)
1772  {
1773  $new_obj->createReference();
1774  $new_obj->putInTree($a_target_id);
1775  $new_obj->setPermissions($a_target_id);
1776 
1777  // when copying from personal workspace we have no current ref id
1778  if($this->getRefId())
1779  {
1780  // copy local roles
1781  $rbacadmin->copyLocalRoles($this->getRefId(),$new_obj->getRefId());
1782  }
1783  }
1784 
1785  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1786  ilAdvancedMDValues::_cloneValues($this->getId(),$new_obj->getId());
1787 
1788  // BEGIN WebDAV: Clone WebDAV properties
1789  $query = "INSERT INTO dav_property (obj_id,node_id,ns,name,value) ".
1790  "SELECT ".$ilDB->quote($new_obj->getId(),'integer').",node_id,ns,name,value ".
1791  "FROM dav_property ".
1792  "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer');
1793  $res = $ilDB->manipulate($query);
1794  // END WebDAV: Clone WebDAV properties
1795 
1796  return $new_obj;
1797  }
1798 
1806  public function appendCopyInfo($a_target_id,$a_copy_id)
1807  {
1808  global $tree;
1809 
1810  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
1811  $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
1812  if(!$cp_options->isRootNode($this->getRefId()))
1813  {
1814  return $this->getTitle();
1815  }
1816  $nodes = $tree->getChilds($a_target_id);
1817 
1818  $title_unique = false;
1819  require_once 'Modules/File/classes/class.ilObjFileAccess.php';
1820  $numberOfCopy = 1;
1821  $handleExtension = ($this->getType() == "file"); // #14883
1822  $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), $numberOfCopy, $handleExtension);
1823  while(!$title_unique)
1824  {
1825  $found = 0;
1826  foreach($nodes as $node)
1827  {
1828  if(($title == $node['title']) and ($this->getType() == $node['type']))
1829  {
1830  $found++;
1831  }
1832  }
1833  if($found > 0)
1834  {
1835  $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), ++$numberOfCopy, $handleExtension);
1836  }
1837  else
1838  {
1839  break;
1840  }
1841  }
1842  return $title;
1843  }
1844 
1857  public function cloneDependencies($a_target_id,$a_copy_id)
1858  {
1859  include_once './Services/AccessControl/classes/class.ilConditionHandler.php' ;
1860  ilConditionHandler::cloneDependencies($this->getRefId(),$a_target_id,$a_copy_id);
1861 
1862  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1864  if($tpl_id)
1865  {
1866  include_once './Services/Object/classes/class.ilObjectFactory.php';
1867  $factory = new ilObjectFactory();
1868  $obj = $factory->getInstanceByRefId($a_target_id, FALSE);
1869  if($obj instanceof ilObject)
1870  {
1871  $obj->applyDidacticTemplate($tpl_id);
1872  }
1873  }
1874  return true;
1875  }
1876 
1884  public function cloneMetaData($target_obj)
1885  {
1886  include_once "./Services/MetaData/classes/class.ilMD.php";
1887  $md = new ilMD($this->getId(),0,$this->getType());
1888  $md->cloneMD($target_obj->getId(),0,$target_obj->getType());
1889  return true;
1890  }
1891 
1900  public static function _getIcon($a_obj_id = "", $a_size = "big", $a_type = "",
1901  $a_offline = false)
1902  {
1903  global $ilSetting, $objDefinition;
1904 
1905  if ($a_obj_id == "" && $a_type == "")
1906  {
1907  return "";
1908  }
1909 
1910  if ($a_type == "")
1911  {
1912  $a_type = ilObject::_lookupType($a_obj_id);
1913  }
1914 
1915  if ($a_size == "")
1916  {
1917  $a_size = "big";
1918  }
1919 
1920  if ($ilSetting->get("custom_icons") &&
1921  in_array($a_type, array("cat","grp","crs", "root", "fold", "prg")))
1922  {
1923  require_once("./Services/Container/classes/class.ilContainer.php");
1924  if (ilContainer::_lookupContainerSetting($a_obj_id, "icon_custom"))
1925  {
1926  $cont_dir = ilContainer::_getContainerDirectory($a_obj_id);
1927 
1928  $file_name = $cont_dir."/icon_custom.svg";
1929  if (is_file($file_name))
1930  {
1931  return $file_name;
1932  }
1933  }
1934  }
1935 
1936  if (!$a_offline)
1937  {
1938  if ($objDefinition->isPluginTypeName($a_type))
1939  {
1940  if ($objDefinition->getClassName($a_type) != "")
1941  {
1942  $class_name = "il".$objDefinition->getClassName($a_type).'Plugin';
1943  $location = $objDefinition->getLocation($a_type);
1944  if (is_file($location."/class.".$class_name.".php"))
1945  {
1946  include_once($location."/class.".$class_name.".php");
1947  return call_user_func(array($class_name, "_getIcon"), $a_type, $a_size, $a_obj_id);
1948  }
1949  }
1950  return ilUtil::getImagePath("icon_cmps.svg");
1951  }
1952 
1953  return ilUtil::getImagePath("icon_".$a_type.".svg");
1954  }
1955  else
1956  {
1957  return "./images/icon_".$a_type.".svg";
1958  }
1959  }
1960 
1967  static function collectDeletionDependencies(&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth = 0)
1968  {
1969  global $objDefinition, $tree;
1970 
1971  if ($a_depth == 0)
1972  {
1973  $deps["dep"] = array();
1974  }
1975 
1976  $deps["del_ids"][$a_obj_id] = $a_obj_id;
1977 
1978  if (!$objDefinition->isPluginTypeName($a_type))
1979  {
1980  $class_name = "ilObj".$objDefinition->getClassName($a_type);
1981  $location = $objDefinition->getLocation($a_type);
1982  include_once($location."/class.".$class_name.".php");
1983  $odeps = call_user_func(array($class_name, "getDeletionDependencies"), $a_obj_id);
1984  if (is_array($odeps))
1985  {
1986  foreach ($odeps as $id => $message)
1987  {
1988  $deps["dep"][$id][$a_obj_id][] = $message;
1989  }
1990  }
1991 
1992  // get deletion dependency of childs
1993  foreach ($tree->getChilds($a_ref_id) as $c)
1994  {
1995  ilObject::collectDeletionDependencies($deps, $c["child"], $c["obj_id"], $c["type"], $a_depth + 1);
1996  }
1997  }
1998 
1999  // delete all dependencies to objects that will be deleted, too
2000  if ($a_depth == 0)
2001  {
2002  foreach ($deps["del_ids"] as $obj_id)
2003  {
2004  unset($deps["dep"][$obj_id]);
2005  }
2006  $deps = $deps["dep"];
2007  }
2008  }
2009 
2014  static function getDeletionDependencies($a_obj_id)
2015  {
2016  return false;
2017  }
2018 
2025  static function getLongDescriptions(array $a_obj_ids)
2026  {
2027  global $ilDB;
2028 
2029  $res = $ilDB->query("SELECT * FROM object_description".
2030  " WHERE ".$ilDB->in("obj_id", $a_obj_ids, "", "integer"));
2031  $all = array();
2032  while($row = $ilDB->fetchAssoc($res))
2033  {
2034  $all[$row["obj_id"]] = $row["description"];
2035  }
2036  return $all;
2037  }
2038 
2045  static function getAllOwnedRepositoryObjects($a_user_id)
2046  {
2047  global $ilDB, $objDefinition;
2048 
2049  $all = array();
2050 
2051  // restrict to repository
2052  $types = array_keys($objDefinition->getSubObjectsRecursively("root"));
2053 
2054  $sql = "SELECT od.obj_id,od.type,od.title FROM object_data od".
2055  " JOIN object_reference oref ON(oref.obj_id = od.obj_id)".
2056  " JOIN tree ON (tree.child = oref.ref_id)";
2057 
2058  if($a_user_id)
2059  {
2060  $sql .= " WHERE od.owner = ".$ilDB->quote($a_user_id, "integer");
2061  }
2062  else
2063  {
2064  $sql .= " LEFT JOIN usr_data ud ON (ud.usr_id = od.owner)".
2065  " WHERE (od.owner < ".$ilDB->quote(1, "integer").
2066  " OR od.owner IS NULL OR ud.login IS NULL)".
2067  " AND od.owner <> ".$ilDB->quote(-1, "integer");
2068  }
2069 
2070  $sql .= " AND ".$ilDB->in("od.type", $types, "", "text").
2071  " AND tree.tree > ".$ilDB->quote(0, "integer"); // #12485
2072 
2073  $res = $ilDB->query($sql);
2074  while($row = $ilDB->fetchAssoc($res))
2075  {
2076  $all[$row["type"]][$row["obj_id"]] = $row["title"];
2077  }
2078 
2079  return $all;
2080  }
2081 
2088  static function fixMissingTitles($a_type, array &$a_obj_title_map)
2089  {
2090  global $ilDB;
2091 
2092  if(!in_array($a_type, array("catr", "crsr", "sess")))
2093  {
2094  return;
2095  }
2096 
2097  // any missing titles?
2098  $missing_obj_ids = array();
2099  foreach($a_obj_title_map as $obj_id => $title)
2100  {
2101  if(!trim($title))
2102  {
2103  $missing_obj_ids[] = $obj_id;
2104  }
2105  }
2106 
2107  if(!sizeof($missing_obj_ids))
2108  {
2109  return;
2110  }
2111 
2112  switch($a_type)
2113  {
2114  case "catr":
2115  case "crsr":
2116  $set = $ilDB->query("SELECT oref.obj_id, od.type, od.title FROM object_data od".
2117  " JOIN container_reference oref ON (od.obj_id = oref.target_obj_id)".
2118  " AND ".$ilDB->in("oref.obj_id", $missing_obj_ids, "", "integer"));
2119  while($row = $ilDB->fetchAssoc($set))
2120  {
2121  $a_obj_title_map[$row["obj_id"]] = $row["title"];
2122  }
2123  break;
2124 
2125  case "sess":
2126  include_once "Modules/Session/classes/class.ilObjSession.php";
2127  foreach($missing_obj_ids as $obj_id)
2128  {
2129  $sess = new ilObjSession($obj_id, false);
2130  $a_obj_title_map[$obj_id] = $sess->getFirstAppointment()->appointmentToString();
2131  }
2132  break;
2133  }
2134  }
2135 
2142  function _lookupCreationDate($a_id)
2143  {
2144  global $ilDB;
2145 
2146  $set = $ilDB->query("SELECT create_date FROM object_data ".
2147  " WHERE obj_id = ".$ilDB->quote($a_id, "integer"));
2148  $rec = $ilDB->fetchAssoc($set);
2149  return $rec["create_date"];
2150  }
2151 
2159  public static function hasAutoRating($a_type, $a_ref_id)
2160  {
2161  global $tree;
2162 
2163  if(!$a_ref_id ||
2164  !in_array($a_type, array("file", "lm", "wiki")))
2165  {
2166  return false;
2167  }
2168 
2169  // find parent container
2170  $parent_ref_id = $tree->checkForParentType($a_ref_id, "grp");
2171  if(!$parent_ref_id)
2172  {
2173  $parent_ref_id = $tree->checkForParentType($a_ref_id, "crs");
2174  }
2175  if($parent_ref_id)
2176  {
2177  include_once './Services/Object/classes/class.ilObjectServiceSettingsGUI.php';
2178 
2179  // get auto rate setting
2180  $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
2182  $parent_obj_id,
2184  false
2185  );
2186  }
2187  return false;
2188  }
2189 
2199  function getPossibleSubObjects($a_filter = true) {
2200  return $this->objDefinition->getSubObjects($this->type, $a_filter);
2201  }
2202 } // END class.ilObject
2203 ?>
static lookupTemplateId($a_ref_id)
Lookup template id ilDB $ilDB.
static setDeletedDates($a_ref_ids)
Set deleted date type $ilDB.
$obj_data_record
object_data record
static getDeletionDependencies($a_obj_id)
Get deletion dependencies.
_writeTitle($a_obj_id, $a_title)
write title to db (static)
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static removeItemFromDesktops($a_id)
removes object from all user&#39;s desktops public
_resetDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
Class ilObjectFactory.
_lookupOwner($a_id)
lookup object owner
const IL_CAL_DATETIME
static _prepareCloneSelection($a_ref_ids, $new_type, $show_path=true)
Prepare copy wizard object selection.
$result
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone object permissions, put in tree ...
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.
$location
Definition: buildRTE.php:44
_writeDescription($a_obj_id, $a_desc)
write description to db (static)
updateMetaData()
update meta data entry
Class ilObject Basic functions for all objects.
withReferences()
determines wehter objects are referenced or not (got ref ids or not)
const DESC_LENGTH
setId($a_id)
set object id public
createMetaData()
create meta data entry
_getContainerDirectory($a_id)
Get the container directory.
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
_getIdForImportId($a_import_id)
get current object id for import id (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...
_lookupCreationDate($a_id)
Lookup creation date.
_setDeletedDate($a_ref_id)
only called in ilTree::saveSubTree
getCreateDate()
get create date public
getOwner()
get object owner
static _deleteByObjId($a_obj_id)
Delete by obj_id.
ilObject($a_id=0, $a_reference=true)
Constructor public.
static _getAllReferences($a_id)
get all reference ids of object
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
static _deleteByObjId($a_obj_id)
Delete by objekt id.
setTitle($a_title)
set object title
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.
createReference()
creates reference for object
_lookupOwnerName($a_owner_id)
lookup owner name for owner id
static assignTemplate($a_ref_id, $a_obj_id, $a_tpl_id)
Assign template to object ilDB $ilDB.
applyDidacticTemplate($a_tpl_id)
Apply template.
setObjDataRecord($a_record)
set object_data record (note: this method should only be called from the ilObjectFactory class) ...
static lookupTxt($a_mod_prefix, $a_pl_id, $a_lang_var)
Lookup language text.
$r
Definition: example_031.php:79
static _getInstance($a_copy_id)
Get instance of copy wizard options.
_lookupDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
create()
create
_writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
setOwner($a_owner)
set object owner
if(!is_array($argv)) $options
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 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 _lookupObjId($a_id)
setRefId($a_id)
set reference id public
static formatDate(ilDateTime $date)
Format a date 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
redirection script todo: (a better solution should control the processing via a xml file) ...
cloneMetaData($target_obj)
Copy meta data.
read($a_force_db=false)
read object data from db into object
initDefaultRoles()
init default roles settings Purpose of this function is to create a local role folder and local roles...
static _lookupImportId($a_obj_id)
_isInTrash($a_ref_id)
checks wether object is in trash
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.
_lookupLastUpdate($a_id, $a_as_string=false)
lookup last update
setImportId($a_import_id)
set import id
Handles conditions for accesses to different ILIAS objects.
static delete($a_ref_id)
notify($a_event, $a_ref_id, $a_parent_non_rbac_id, $a_node_id, $a_params=0)
notifys an object about an event occured Based on the event passed, each object may decide how it rea...
_hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
global $ilUser
Definition: imgupload.php:15
static fixMissingTitles($a_type, array &$a_obj_title_map)
Try to fix missing object titles.
global $ilSetting
Definition: privfeed.php:40
$path
Definition: index.php:22
_lookupContainerSetting($a_id, $a_keyword, $a_default_value=NULL)
Lookup a container setting.
global $ilBench
Definition: ilias.php:18
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 cloneDependencies($a_src_ref_id, $a_target_ref_id, $a_copy_id)
update()
update object in db
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
getLastUpdateDate()
get last update date public
_getLastUpdateOfObjects($a_objs)
Get last update for a set of media objects.
static _deleteByObjId($a_obj_id)
getUntranslatedTitle()
get untranslated object title public
setType($a_type)
set object type public
_getObjectsDataForType($a_type, $a_omit_trash=false)
get all objects of a certain type
setPermissions($a_parent_ref)
set permissions of object
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 _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.
MDUpdateListener($a_element)
Meta data update listener.
setRegisterMode($a_bool)