ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups 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 
4 
13 class ilObject
14 {
18  const TITLE_LENGTH = 128;
19 
20 
26  var $ilias;
27 
33  var $lng;
34 
40  var $id; // true object_id!!!!
41  var $ref_id;// reference_id
42  var $type;
43  var $title;
44  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
46  // END WebDAV: WebDAV needs to access the untranslated title of an object
47  var $desc;
49  var $owner;
53  var $register = false; // registering required for object? set to true to implement a subscription interface
54 
61 
68 
74 
79  var $max_desc;
80 
85  var $add_dots;
86 
91 
98  function ilObject($a_id = 0, $a_reference = true)
99  {
100  global $ilias, $lng, $ilBench;
101 
102  $ilBench->start("Core", "ilObject_Constructor");
103 
104  if (DEBUG)
105  {
106  echo "<br/><font color=\"red\">type(".$this->type.") id(".$a_id.") referenced(".$a_reference.")</font>";
107  }
108 
109  $this->ilias =& $ilias;
110  $this->lng =& $lng;
111 
112  $this->max_title = MAXLENGTH_OBJ_TITLE;
113  $this->max_desc = MAXLENGTH_OBJ_DESC;
114  $this->add_dots = true;
115 
116  $this->referenced = $a_reference;
117  $this->call_by_reference = $a_reference;
118 
119  if ($a_id == 0)
120  {
121  $this->referenced = false; // newly created objects are never referenced
122  } // they will get referenced if createReference() is called
123 
124  if ($this->referenced)
125  {
126  $this->ref_id = $a_id;
127  }
128  else
129  {
130  $this->id = $a_id;
131  }
132  // read object data
133  if ($a_id != 0)
134  {
135  $this->read();
136  }
137 
138  $ilBench->stop("Core", "ilObject_Constructor");
139  }
140 
144  function withReferences()
145  {
146  // both vars could differ. this method should always return true if one of them is true without changing their status
147  return ($this->call_by_reference) ? true : $this->referenced;
148  }
149 
150 
156  function read($a_force_db = false)
157  {
158  global $objDefinition, $ilBench, $ilDB, $log;
159 
160  $ilBench->start("Core", "ilObject_read");
161 
162  if (isset($this->obj_data_record) && !$a_force_db)
163  {
164  $obj = $this->obj_data_record;
165  }
166  else if ($this->referenced)
167  {
168  // check reference id
169  if (!isset($this->ref_id))
170  {
171  $message = "ilObject::read(): No ref_id given! (".$this->type.")";
172  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
173  }
174 
175  // read object data
176  $ilBench->start("Core", "ilObject_read_readData");
177 
178  $q = "SELECT * FROM object_data, object_reference WHERE object_data.obj_id=object_reference.obj_id ".
179  "AND object_reference.ref_id= ".$ilDB->quote($this->ref_id, "integer");
180  $object_set = $ilDB->query($q);
181  $ilBench->stop("Core", "ilObject_read_readData");
182 
183  // check number of records
184  if ($ilDB->numRows($object_set) == 0)
185  {
186  $message = "ilObject::read(): Object with ref_id ".$this->ref_id." not found! (".$this->type.")";
187  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
188  }
189 
190  $obj = $ilDB->fetchAssoc($object_set);
191  }
192  else
193  {
194  // check object id
195  if (!isset($this->id))
196  {
197  $message = "ilObject::read(): No obj_id given! (".$this->type.")";
198  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
199  }
200 
201  // read object data
202  $q = "SELECT * FROM object_data ".
203  "WHERE obj_id = ".$ilDB->quote($this->id, "integer");
204  $object_set = $ilDB->query($q);
205 
206  // check number of records
207  if ($ilDB->numRows($object_set) == 0)
208  {
209  include_once("./Services/Object/exceptions/class.ilObjectNotFoundException.php");
210  throw new ilObjectNotFoundException("ilObject::read(): Object with obj_id: ".$this->id.
211  " (".$this->type.") not found!");
212  return;
213  }
214 
215  $obj = $ilDB->fetchAssoc($object_set);
216  }
217 
218  $this->id = $obj["obj_id"];
219 
220  // check type match (the "xxx" type is used for the unit test)
221  if ($this->type != $obj["type"] && $obj["type"] != "xxx")
222  {
223  $message = "ilObject::read(): Type mismatch. Object with obj_id: ".$this->id." ".
224  "was instantiated by type '".$this->type."'. DB type is: ".$obj["type"];
225 
226  // write log entry
227  $log->write($message);
228 
229  // raise error
230  $this->ilias->raiseError("ilObject::read(): Type mismatch. (".$this->type."/".$this->id.")",$this->ilias->error_obj->WARNING);
231  }
232 
233  $this->type = $obj["type"];
234  $this->title = $obj["title"];
235  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
236  $this->untranslatedTitle = $obj["title"];
237  // END WebDAV: WebDAV needs to access the untranslated title of an object
238  $this->desc = $obj["description"];
239  $this->owner = $obj["owner"];
240  $this->create_date = $obj["create_date"];
241  $this->last_update = $obj["last_update"];
242  $this->import_id = $obj["import_id"];
243 
244  if($objDefinition->isRBACObject($this->getType()))
245  {
246  // Read long description
247  $query = "SELECT * FROM object_description WHERE obj_id = ".$ilDB->quote($this->id,'integer');
248  $res = $this->ilias->db->query($query);
249  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
250  {
251  if(strlen($row->description))
252  {
253  $this->setDescription($row->description);
254  }
255  }
256  }
257 
258  // multilingual support systemobjects (sys) & categories (db)
259  $ilBench->start("Core", "ilObject_Constructor_getTranslation");
260  $translation_type = $objDefinition->getTranslationType($this->type);
261 
262  if ($translation_type == "sys")
263  {
264  $this->title = $this->lng->txt("obj_".$this->type);
265  $this->desc = $this->lng->txt("obj_".$this->type."_desc");
266  }
267  elseif ($translation_type == "db")
268  {
269  $q = "SELECT title,description FROM object_translation ".
270  "WHERE obj_id = ".$ilDB->quote($this->id,'integer')." ".
271  "AND lang_code = ".$ilDB->quote($this->ilias->account->getCurrentLanguage(),'text')." ".
272  "AND NOT lang_default = 1";
273  $r = $this->ilias->db->query($q);
274  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
275 
276  if ($row)
277  {
278  $this->title = $row->title;
279  $this->setDescription($row->description);
280  #$this->desc = $row->description;
281  }
282  }
283 
284  $ilBench->stop("Core", "ilObject_Constructor_getTranslation");
285 
286  $ilBench->stop("Core", "ilObject_read");
287  }
288 
294  function getId()
295  {
296  return $this->id;
297  }
298 
304  function setId($a_id)
305  {
306  $this->id = $a_id;
307  }
308 
314  function setRefId($a_id)
315  {
316  $this->ref_id = $a_id;
317  $this->referenced = true;
318  }
319 
325  function getRefId()
326  {
327  return $this->ref_id;
328  }
329 
335  function getType()
336  {
337  return $this->type;
338  }
339 
345  function setType($a_type)
346  {
347  $this->type = $a_type;
348  }
349 
359  public function getPresentationTitle()
360  {
361  return $this->getTitle();
362  }
363 
364 
370  function getTitle()
371  {
372  return $this->title;
373  }
374  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
381  {
383  }
384  // END WebDAV: WebDAV needs to access the untranslated title of an object
385 
392  function setTitle($a_title)
393  {
394  $this->title = ilUtil::shortenText($a_title, $this->max_title, $this->add_dots);
395  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
396  $this->untranslatedTitle = $this->title;
397  // END WebDAV: WebDAV needs to access the untranslated title of an object
398  }
399 
406  function getDescription()
407  {
408  return $this->desc;
409  }
410 
417  function setDescription($a_desc)
418  {
419  // Shortened form is storted in object_data. Long form is stored in object_description
420  $this->desc = ilUtil::shortenText($a_desc, $this->max_desc, $this->add_dots);
421 
422  $this->long_desc = $a_desc;
423 
424  return true;
425  }
426 
434  {
435  return strlen($this->long_desc) ? $this->long_desc : $this->desc;
436  }
437 
444  function getImportId()
445  {
446  return $this->import_id;
447  }
448 
455  function setImportId($a_import_id)
456  {
457  $this->import_id = $a_import_id;
458  }
459 
460  public static function _lookupObjIdByImportId($a_import_id)
461  {
462  global $ilDB;
463 
464  $query = "SELECT * FROM object_data ".
465  "WHERE import_id = ".$ilDB->quote($a_import_id, "text")." ".
466  "ORDER BY create_date DESC";
467  $res = $ilDB->query($query);
468  while($row = $ilDB->fetchObject($res))
469  {
470  return $row->obj_id;
471  }
472  return 0;
473  }
474 
481  function getOwner()
482  {
483  return $this->owner;
484  }
485 
486  /*
487  * get full name of object owner
488  *
489  * @access public
490  * @return string owner name or unknown
491  */
492  function getOwnerName()
493  {
494  return ilObject::_lookupOwnerName($this->getOwner());
495  }
496 
500  function _lookupOwnerName($a_owner_id)
501  {
502  global $lng;
503 
504  if ($a_owner_id != -1)
505  {
506  if (ilObject::_exists($a_owner_id))
507  {
508  $owner = new ilObjUser($a_owner_id);
509  }
510  }
511 
512  if (is_object($owner))
513  {
514  $own_name = $owner->getFullname();
515  }
516  else
517  {
518  $own_name = $lng->txt("unknown");
519  }
520 
521  return $own_name;
522  }
523 
530  function setOwner($a_owner)
531  {
532  $this->owner = $a_owner;
533  }
534 
535 
536 
542  function getCreateDate()
543  {
544  return $this->create_date;
545  }
546 
552  function getLastUpdateDate()
553  {
554  return $this->last_update;
555  }
556 
557 
569  function getDiskUsage()
570  {
571  return null;
572  }
573 
582  function setObjDataRecord($a_record)
583  {
584  $this->obj_data_record = $a_record;
585  }
586 
595  function create()
596  {
597  global $ilDB, $log,$ilUser,$objDefinition;
598 
599  if (!isset($this->type))
600  {
601  $message = get_class($this)."::create(): No object type given!";
602  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
603  }
604 
605  // write log entry
606  $log->write("ilObject::create(), start");
607 
608  $this->title = ilUtil::shortenText($this->getTitle(), $this->max_title, $this->add_dots);
609  $this->desc = ilUtil::shortenText($this->getDescription(), $this->max_desc, $this->add_dots);
610 
611  // determine owner
612  if ($this->getOwner() > 0)
613  {
614  $owner = $this->getOwner();
615  }
616  elseif(is_object($ilUser))
617  {
618  $owner = $ilUser->getId();
619  }
620  else
621  {
622  $owner = 0;
623  }
624  $this->id = $ilDB->nextId("object_data");
625  $q = "INSERT INTO object_data ".
626  "(obj_id,type,title,description,owner,create_date,last_update,import_id) ".
627  "VALUES ".
628  "(".
629  $ilDB->quote($this->id, "integer").",".
630  $ilDB->quote($this->type, "text").",".
631  $ilDB->quote($this->getTitle(), "text").",".
632  $ilDB->quote($this->getDescription(), "text").",".
633  $ilDB->quote($owner, "integer").",".
634  $ilDB->now().",".
635  $ilDB->now().",".
636  $ilDB->quote($this->getImportId(), "text").")";
637 
638  $ilDB->manipulate($q);
639 
640  //$this->id = $ilDB->getLastInsertId();
641 
642 
643  // Save long form of description if is rbac object
644  if($objDefinition->isRBACObject($this->getType()))
645  {
646  $values = array(
647  'obj_id' => array('integer',$this->id),
648  'description' => array('clob', $this->getLongDescription()));
649 //var_dump($values);
650  $ilDB->insert('object_description',$values);
651  }
652 
653 
654  // the line ($this->read();) messes up meta data handling: meta data,
655  // that is not saved at this time, gets lost, so we query for the dates alone
656  //$this->read();
657  $q = "SELECT last_update, create_date FROM object_data".
658  " WHERE obj_id = ".$ilDB->quote($this->id, "integer");
659  $obj_set = $ilDB->query($q);
660  $obj_rec = $ilDB->fetchAssoc($obj_set);
661  $this->last_update = $obj_rec["last_update"];
662  $this->create_date = $obj_rec["create_date"];
663 
664  // set owner for new objects
665  $this->setOwner($owner);
666 
667  // write log entry
668  $log->write("ilObject::create(), finished, obj_id: ".$this->id.", type: ".
669  $this->type.", title: ".$this->getTitle());
670 
671  $GLOBALS['ilAppEventHandler']->raise(
672  'Services/Object',
673  'create',
674  array('obj_id' => $this->id,'obj_type' => $this->type));
675 
676  return $this->id;
677  }
678 
685  function update()
686  {
687  global $objDefinition, $ilDB;
688 
689  $q = "UPDATE object_data ".
690  "SET ".
691  "title = ".$ilDB->quote($this->getTitle(), "text").",".
692  "description = ".$ilDB->quote($this->getDescription(), "text").", ".
693  "import_id = ".$ilDB->quote($this->getImportId(), "text").",".
694  "last_update = ".$ilDB->now()." ".
695  "WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
696  $ilDB->manipulate($q);
697 
698  // the line ($this->read();) messes up meta data handling: meta data,
699  // that is not saved at this time, gets lost, so we query for the dates alone
700  //$this->read();
701  $q = "SELECT last_update FROM object_data".
702  " WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
703  $obj_set = $ilDB->query($q);
704  $obj_rec = $ilDB->fetchAssoc($obj_set);
705  $this->last_update = $obj_rec["last_update"];
706 
707  if($objDefinition->isRBACObject($this->getType()))
708  {
709  // Update long description
710  $res = $this->ilias->db->query("SELECT * FROM object_description WHERE obj_id = ".
711  $ilDB->quote($this->getId(),'integer'));
712  if($res->numRows())
713  {
714  $values = array(
715  'description' => array('clob',$this->getLongDescription())
716  );
717  $ilDB->update('object_description',$values,array('obj_id' => array('integer',$this->getId())));
718  }
719  else
720  {
721  $values = array(
722  'description' => array('clob',$this->getLongDescription()),
723  'obj_id' => array('integer',$this->getId()));
724  $ilDB->insert('object_description',$values);
725  }
726  }
727  $GLOBALS['ilAppEventHandler']->raise(
728  'Services/Object',
729  'update',
730  array('obj_id' => $this->getId(),
731  'obj_type' => $this->getType(),
732  'ref_id' => $this->getRefId()));
733 
734  return true;
735  }
736 
748  function MDUpdateListener($a_element)
749  {
750  include_once 'Services/MetaData/classes/class.ilMD.php';
751 
752  $GLOBALS['ilAppEventHandler']->raise(
753  'Services/Object',
754  'update',
755  array('obj_id' => $this->getId(),
756  'obj_type' => $this->getType(),
757  'ref_id' => $this->getRefId()));
758 
759  switch($a_element)
760  {
761  case 'General':
762 
763  // Update Title and description
764  $md = new ilMD($this->getId(),0, $this->getType());
765  if(!is_object($md_gen = $md->getGeneral()))
766  {
767  return false;
768  }
769  $this->setTitle($md_gen->getTitle());
770 
771  foreach($md_gen->getDescriptionIds() as $id)
772  {
773  $md_des = $md_gen->getDescription($id);
774  $this->setDescription($md_des->getDescription());
775  break;
776  }
777  $this->update();
778  break;
779 
780  default:
781  }
782 
783  return true;
784  }
785 
789  function createMetaData()
790  {
791  include_once 'Services/MetaData/classes/class.ilMDCreator.php';
792 
793  global $ilUser;
794 
795  $md_creator = new ilMDCreator($this->getId(),0,$this->getType());
796  $md_creator->setTitle($this->getTitle());
797  $md_creator->setTitleLanguage($ilUser->getPref('language'));
798  $md_creator->setDescription($this->getLongDescription());
799  $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
800  $md_creator->setKeywordLanguage($ilUser->getPref('language'));
801  $md_creator->setLanguage($ilUser->getPref('language'));
802  $md_creator->create();
803 
804  return true;
805  }
806 
810  function updateMetaData()
811  {
812  include_once("Services/MetaData/classes/class.ilMD.php");
813  include_once("Services/MetaData/classes/class.ilMDGeneral.php");
814  include_once("Services/MetaData/classes/class.ilMDDescription.php");
815 
816  $md =& new ilMD($this->getId(), 0, $this->getType());
817  $md_gen =& $md->getGeneral();
818  // BEGIN WebDAV: meta data can be missing sometimes.
819  if ($md_gen == null)
820  {
821  $this->createMetaData();
822  $md =& new ilMD($this->getId(), 0, $this->getType());
823  $md_gen =& $md->getGeneral();
824  }
825  // END WebDAV: meta data can be missing sometimes.
826  $md_gen->setTitle($this->getTitle());
827 
828  // sets first description (maybe not appropriate)
829  $md_des_ids =& $md_gen->getDescriptionIds();
830  if (count($md_des_ids) > 0)
831  {
832  $md_des =& $md_gen->getDescription($md_des_ids[0]);
833  $md_des->setDescription($this->getLongDescription());
834  $md_des->update();
835  }
836  $md_gen->update();
837 
838  }
839 
843  function deleteMetaData()
844  {
845  // Delete meta data
846  include_once('Services/MetaData/classes/class.ilMD.php');
847  $md = new ilMD($this->getId(), 0, $this->getType());
848  $md->deleteAll();
849  }
850 
857  function updateOwner()
858  {
859  global $ilDB;
860 
861  $q = "UPDATE object_data ".
862  "SET ".
863  "owner = ".$ilDB->quote($this->getOwner(), "integer").", ".
864  "last_update = ".$ilDB->now()." ".
865  "WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
866  $ilDB->manipulate($q);
867 
868  $q = "SELECT last_update FROM object_data".
869  " WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
870  $obj_set = $ilDB->query($q);
871  $obj_rec = $ilDB->fetchAssoc($obj_set);
872  $this->last_update = $obj_rec["last_update"];
873 
874  return true;
875  }
876 
884  function _getIdForImportId($a_import_id)
885  {
886  global $ilDB;
887 
888  $ilDB->setLimit(1,0);
889  $q = "SELECT * FROM object_data WHERE import_id = ".$ilDB->quote($a_import_id, "text").
890  " ORDER BY create_date DESC";
891  $obj_set = $ilDB->query($q);
892 
893  if ($obj_rec = $ilDB->fetchAssoc($obj_set))
894  {
895  return $obj_rec["obj_id"];
896  }
897  else
898  {
899  return 0;
900  }
901  }
902 
908  public static function _getAllReferences($a_id)
909  {
910  global $ilDB;
911 
912  $query = "SELECT * FROM object_reference WHERE obj_id = ".
913  $ilDB->quote($a_id,'integer');
914 
915  $res = $ilDB->query($query);
916  $ref = array();
917  while($obj_rec = $ilDB->fetchAssoc($res))
918  {
919  $ref[$obj_rec["ref_id"]] = $obj_rec["ref_id"];
920  }
921 
922  return $ref;
923  }
924 
930  public static function _lookupTitle($a_id)
931  {
932  global $ilObjDataCache;
933 
934  $tit = $ilObjDataCache->lookupTitle($a_id);
935 //echo "<br>LOOKING-$a_id-:$tit";
936  return $tit;
937  }
938 
944  function _lookupOwner($a_id)
945  {
946  global $ilObjDataCache;
947 
948  $owner = $ilObjDataCache->lookupOwner($a_id);
949  return $owner;
950  }
951 
952  public static function _getIdsForTitle($title, $type = '', $partialmatch = false)
953  {
954  global $ilDB;
955 
956  $query = (!$partialmatch)
957  ? "SELECT obj_id FROM object_data WHERE title = ".$ilDB->quote($title, "text")
958  : "SELECT obj_id FROM object_data WHERE ".$ilDB->like("title", "text", '%'.$title.'%');
959  if($type != '')
960  {
961  $query .= " AND type = ".$ilDB->quote($type, "text");
962  }
963 
964  $result = $ilDB->query($query);
965 
966  $object_ids = array();
967  while($row = $ilDB->fetchAssoc($result))
968  {
969  $object_ids[] = $row['obj_id'];
970  }
971 
972  return is_array($object_ids) ? $object_ids : array();
973  }
974 
980  public static function _lookupDescription($a_id)
981  {
982  global $ilObjDataCache;
983 
984  return $ilObjDataCache->lookupDescription($a_id);
985  }
986 
992  function _lookupLastUpdate($a_id, $a_as_string = false)
993  {
994  global $ilObjDataCache;
995 
996  if ($a_as_string)
997  {
998  return ilDatePresentation::formatDate(new ilDateTime($ilObjDataCache->lookupLastUpdate($a_id),IL_CAL_DATETIME));
999  }
1000  else
1001  {
1002  return $ilObjDataCache->lookupLastUpdate($a_id);
1003  }
1004  }
1005 
1011  function _getLastUpdateOfObjects($a_objs)
1012  {
1013  global $ilDB;
1014 
1015  if (!is_array($a_objs))
1016  {
1017  $a_objs = array($a_objs);
1018  }
1019  $types = array();
1020  $set = $ilDB->query("SELECT max(last_update) as last_update FROM object_data ".
1021  "WHERE ".$ilDB->in("obj_id", $a_objs, false, "integer")." ");
1022  $rec = $ilDB->fetchAssoc($set);
1023 
1024  return ($rec["last_update"]);
1025  }
1026 
1027  public static function _lookupObjId($a_id)
1028  {
1029  global $ilObjDataCache;
1030 
1031  return (int) $ilObjDataCache->lookupObjId($a_id);
1032  }
1033 
1037  function _setDeletedDate($a_ref_id)
1038  {
1039  global $ilDB;
1040 
1041  $query = "UPDATE object_reference SET deleted= ".$ilDB->now().' '.
1042  "WHERE ref_id = ".$ilDB->quote($a_ref_id,'integer');
1043  $res = $ilDB->manipulate($query);
1044  }
1045 
1049  function _resetDeletedDate($a_ref_id)
1050  {
1051  global $ilDB;
1052 
1053  $query = "UPDATE object_reference SET deleted = ".$ilDB->quote(null,'timestamp').
1054  " WHERE ref_id = ".$ilDB->quote($a_ref_id,'integer');
1055  $res = $ilDB->manipulate($query);
1056  }
1057 
1061  function _lookupDeletedDate($a_ref_id)
1062  {
1063  global $ilDB;
1064 
1065  $query = "SELECT deleted FROM object_reference".
1066  " WHERE ref_id = ".$ilDB->quote($a_ref_id, "integer");
1067  $set = $ilDB->query($query);
1068  $rec = $ilDB->fetchAssoc($set);
1069 
1070  return $rec["deleted"];
1071  }
1072 
1073 
1081  function _writeTitle($a_obj_id, $a_title)
1082  {
1083  global $ilDB;
1084 
1085  $q = "UPDATE object_data ".
1086  "SET ".
1087  "title = ".$ilDB->quote($a_title, "text").",".
1088  "last_update = ".$ilDB->now()." ".
1089  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
1090 
1091  $ilDB->manipulate($q);
1092  }
1093 
1101  function _writeDescription($a_obj_id, $a_desc)
1102  {
1103  global $ilDB,$objDefinition;
1104 
1105 
1106  $desc = ilUtil::shortenText($a_desc,MAXLENGTH_OBJ_DESC,true);
1107 
1108  $q = "UPDATE object_data ".
1109  "SET ".
1110  "description = ".$ilDB->quote($desc, "text").",".
1111  "last_update = ".$ilDB->now()." ".
1112  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
1113 
1114  $ilDB->manipulate($q);
1115 
1116  if($objDefinition->isRBACObject($this->getType()))
1117  {
1118  // Update long description
1119  $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = ".
1120  $ilDB->quote($a_obj_id,'integer'));
1121 
1122  if($res->numRows())
1123  {
1124  $values = array(
1125  'description' => array('clob',$this->getLongDescription())
1126  );
1127  $ilDB->update('object_description',$values,array('obj_id' => array('integer',$this->getId())));
1128  }
1129  else
1130  {
1131  $values = array(
1132  'description' => array('clob',$this->getLongDescription()),
1133  'obj_id' => array('integer',$this->getId()));
1134  $ilDB->insert('object_description',$values);
1135  }
1136  }
1137  }
1138 
1146  function _writeImportId($a_obj_id, $a_import_id)
1147  {
1148  global $ilDB;
1149 
1150  $q = "UPDATE object_data ".
1151  "SET ".
1152  "import_id = ".$ilDB->quote($a_import_id, "text").",".
1153  "last_update = ".$ilDB->now()." ".
1154  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
1155 
1156  $ilDB->manipulate($q);
1157  }
1158 
1164  public static function _lookupType($a_id,$a_reference = false)
1165  {
1166  global $ilObjDataCache;
1167 
1168  if($a_reference)
1169  {
1170  return $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_id));
1171  }
1172  return $ilObjDataCache->lookupType($a_id);
1173 
1174  global $ilDB;
1175 
1176  if ($a_reference === true)
1177  {
1178  $q = "SELECT type FROM object_reference obr, object_data obd ".
1179  "WHERE obr.ref_id = ".$ilDB->quote($a_id, "integer")." ".
1180  "AND obr.obj_id = obd.obj_id ";
1181  }
1182  else
1183  {
1184  $q = "SELECT type FROM object_data WHERE obj_id = ".$ilDB->quote($a_id, "integer");
1185  }
1186 
1187  $obj_set = $ilDB->query($q);
1188  $obj_rec = $ilDB->fetchAssoc($obj_set);
1189 
1190  return $obj_rec["type"];
1191  }
1192 
1196  function _isInTrash($a_ref_id)
1197  {
1198  global $tree;
1199 
1200  return $tree->isSaved($a_ref_id);
1201  }
1202 
1206  function _hasUntrashedReference($a_obj_id)
1207  {
1208  $ref_ids = ilObject::_getAllReferences($a_obj_id);
1209  foreach($ref_ids as $ref_id)
1210  {
1211  if(!ilObject::_isInTrash($ref_id))
1212  {
1213  return true;
1214  }
1215  }
1216 
1217  return false;
1218  }
1219 
1225  public static function _lookupObjectId($a_ref_id)
1226  {
1227  global $ilObjDataCache;
1228 
1229  return (int) $ilObjDataCache->lookupObjId($a_ref_id);
1230  }
1231 
1242  function _getObjectsDataForType($a_type, $a_omit_trash = false)
1243  {
1244  global $ilDB;
1245 
1246  $q = "SELECT * FROM object_data WHERE type = ".$ilDB->quote($a_type, "text");
1247  $obj_set = $ilDB->query($q);
1248 
1249  $objects = array();
1250  while ($obj_rec = $ilDB->fetchAssoc($obj_set))
1251  {
1252  if ((!$a_omit_trash) || ilObject::_hasUntrashedReference($obj_rec["obj_id"]))
1253  {
1254  $objects[$obj_rec["title"].".".$obj_rec["obj_id"]] = array("id" => $obj_rec["obj_id"],
1255  "type" => $obj_rec["type"], "title" => $obj_rec["title"],
1256  "description" => $obj_rec["description"]);
1257  }
1258  }
1259  ksort($objects);
1260  return $objects;
1261  }
1262 
1268  function putInTree($a_parent_ref)
1269  {
1270  global $tree, $log;
1271 
1272  $tree->insertNode($this->getRefId(), $a_parent_ref);
1273 
1274  // write log entry
1275  $log->write("ilObject::putInTree(), parent_ref: $a_parent_ref, ref_id: ".
1276  $this->getRefId().", obj_id: ".$this->getId().", type: ".
1277  $this->getType().", title: ".$this->getTitle());
1278 
1279  }
1280 
1287  function setPermissions($a_parent_ref)
1288  {
1289  global $rbacadmin, $rbacreview;
1290 
1291  $parentRoles = $rbacreview->getParentRoleIds($a_parent_ref);
1292 
1293  foreach ($parentRoles as $parRol)
1294  {
1295  $ops = $rbacreview->getOperationsOfRole($parRol["obj_id"], $this->getType(), $parRol["parent"]);
1296  $rbacadmin->grantPermission($parRol["obj_id"], $ops, $this->getRefId());
1297  }
1298 
1299  $this->initDefaultRoles();
1300  }
1301 
1308  function createReference()
1309  {
1310  global $ilDB;
1311 
1312  if (!isset($this->id))
1313  {
1314  $message = "ilObject::createNewReference(): No obj_id given!";
1315  $this->raiseError($message,$this->ilias->error_obj->WARNING);
1316  }
1317 
1318  $next_id = $ilDB->nextId('object_reference');
1319  $query = "INSERT INTO object_reference ".
1320  "(ref_id, obj_id) VALUES (".$ilDB->quote($next_id,'integer').','.$ilDB->quote($this->id ,'integer').")";
1321  $this->ilias->db->query($query);
1322 
1323  $this->ref_id = $next_id;
1324  $this->referenced = true;
1325 
1326  return $this->ref_id;
1327  }
1328 
1329 
1336  function countReferences()
1337  {
1338  global $ilDB;
1339 
1340  if (!isset($this->id))
1341  {
1342  $message = "ilObject::countReferences(): No obj_id given!";
1343  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
1344  }
1345 
1346  $query = "SELECT COUNT(ref_id) num FROM object_reference ".
1347  "WHERE obj_id = ".$ilDB->quote($this->id,'integer')." ";
1348  $res = $ilDB->query($query);
1349  $row = $ilDB->fetchObject($res);
1350 
1351  return $row->num;
1352  }
1353 
1354 
1355 
1356 
1366  function delete()
1367  {
1368  global $rbacadmin, $log, $ilDB;
1369 
1370  $remove = false;
1371 
1372  // delete object_data entry
1373  if ((!$this->referenced) || ($this->countReferences() == 1))
1374  {
1375  // check type match
1376  $db_type = ilObject::_lookupType($this->getId());
1377  if ($this->type != $db_type)
1378  {
1379  $message = "ilObject::delete(): Type mismatch. Object with obj_id: ".$this->id." ".
1380  "was instantiated by type '".$this->type."'. DB type is: ".$db_type;
1381 
1382  // write log entry
1383  $log->write($message);
1384 
1385  // raise error
1386  $this->ilias->raiseError("ilObject::delete(): Type mismatch. (".$this->type."/".$this->id.")",$this->ilias->error_obj->WARNING);
1387  }
1388 
1389  // delete entry in object_data
1390  $q = "DELETE FROM object_data ".
1391  "WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
1392  $ilDB->manipulate($q);
1393 
1394  // delete long description
1395  $query = "DELETE FROM object_description WHERE obj_id = ".
1396  $ilDB->quote($this->getId(), "integer");
1397  $ilDB->manipulate($query);
1398 
1399  // write log entry
1400  $log->write("ilObject::delete(), deleted object, obj_id: ".$this->getId().", type: ".
1401  $this->getType().", title: ".$this->getTitle());
1402 
1403  // remove news
1404  include_once("./Services/News/classes/class.ilNewsItem.php");
1405  $news_item = new ilNewsItem();
1406  $news_item->deleteNewsOfContext($this->getId(), $this->getType());
1407  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1409 
1410  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1412 
1413  /* remove notes (see infoscreen gui)
1414  as they can be seen as personal data we are keeping them for now
1415  include_once("Services/Notes/classes/class.ilNote.php");
1416  foreach(array(IL_NOTE_PRIVATE, IL_NOTE_PUBLIC) as $note_type)
1417  {
1418  foreach(ilNote::_getNotesOfObject($this->id, 0, $this->type, $note_type) as $note)
1419  {
1420  $note->delete();
1421  }
1422  }
1423  */
1424 
1425  // BEGIN WebDAV: Delete WebDAV properties
1426  $query = "DELETE FROM dav_property ".
1427  "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer');
1428  $res = $ilDB->manipulate($query);
1429  // END WebDAV: Delete WebDAV properties
1430 
1431  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
1433 
1434  $remove = true;
1435  }
1436  else
1437  {
1438  // write log entry
1439  $log->write("ilObject::delete(), object not deleted, number of references: ".
1440  $this->countReferences().", obj_id: ".$this->getId().", type: ".
1441  $this->getType().", title: ".$this->getTitle());
1442  }
1443 
1444  // delete object_reference entry
1445  if ($this->referenced)
1446  {
1447  include_once "Services/Object/classes/class.ilObjectActivation.php";
1449 
1450  // delete entry in object_reference
1451  $query = "DELETE FROM object_reference ".
1452  "WHERE ref_id = ".$ilDB->quote($this->getRefId(),'integer');
1453  $res = $ilDB->manipulate($query);
1454 
1455  // write log entry
1456  $log->write("ilObject::delete(), reference deleted, ref_id: ".$this->getRefId().
1457  ", obj_id: ".$this->getId().", type: ".
1458  $this->getType().", title: ".$this->getTitle());
1459 
1460  // DELETE PERMISSION ENTRIES IN RBAC_PA
1461  // DONE: method overwritten in ilObjRole & ilObjUser.
1462  // this call only applies for objects in rbac (not usr,role,rolt)
1463  // TODO: Do this for role templates too
1464  $rbacadmin->revokePermission($this->getRefId(),0,false);
1465 
1466  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
1467  ilRbacLog::delete($this->getRefId());
1468 
1469  // Remove applied didactic template setting
1470  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1472 
1473  // Remove desktop items
1475  }
1476 
1477  // remove conditions
1478  if ($this->referenced)
1479  {
1480  $ch =& new ilConditionHandler();
1481  $ch->delete($this->getRefId());
1482  unset($ch);
1483  }
1484 
1485  return $remove;
1486  }
1487 
1495  function initDefaultRoles()
1496  {
1497  return array();
1498  }
1499 
1509  function createRoleFolder()
1510  {
1511  global $rbacreview;
1512 
1513  // does a role folder already exists?
1514  // (this check is only 'to be sure' that no second role folder is created under one object.
1515  // the if-construct should never return true)
1516  if ($rolf_data = $rbacreview->getRoleFolderofObject($this->getRefId()))
1517  {
1518  $rfoldObj = $this->ilias->obj_factory->getInstanceByRefId($rolf_data["ref_id"]);
1519  }
1520  else
1521  {
1522  include_once ("./Services/AccessControl/classes/class.ilObjRoleFolder.php");
1523  $rfoldObj = new ilObjRoleFolder();
1524  $rfoldObj->setTitle($this->getId());
1525  $rfoldObj->setDescription(" (ref_id ".$this->getRefId().")");
1526  $rfoldObj->create();
1527  $rfoldObj->createReference();
1528  $rfoldObj->putInTree($this->getRefId());
1529  $rfoldObj->setPermissions($this->getRefId());
1530  }
1531 
1532  return $rfoldObj;
1533  }
1534 
1539  public function applyDidacticTemplate($a_tpl_id)
1540  {
1541  if(!$a_tpl_id)
1542  {
1543  return true;
1544  }
1545 
1546  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1547  ilDidacticTemplateObjSettings::assignTemplate($this->getRefId(), $this->getId(), (int) $a_tpl_id);
1548 
1549  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
1550  foreach(ilDidacticTemplateActionFactory::getActionsByTemplateId($a_tpl_id) as $action)
1551  {
1552  $action->setRefId($this->getRefId());
1553  $action->apply();
1554  }
1555  }
1556 
1565  function _exists($a_id, $a_reference = false)
1566  {
1567  global $ilias, $ilDB;
1568 
1569  if ($a_reference)
1570  {
1571  $q = "SELECT * FROM object_data ".
1572  "LEFT JOIN object_reference ON object_reference.obj_id=object_data.obj_id ".
1573  "WHERE object_reference.ref_id= ".$ilDB->quote($a_id, "integer");
1574  }
1575  else
1576  {
1577  $q = "SELECT * FROM object_data WHERE obj_id=".$ilDB->quote($a_id, "integer");
1578  }
1579 
1580  $r = $ilDB->query($q);
1581 
1582  return $ilDB->numRows($r) ? true : false;
1583  }
1584 
1597  function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1598  {
1599  global $tree;
1600 
1601  $parent_id = (int) $tree->getParentId($a_node_id);
1602 
1603  if ($parent_id != 0)
1604  {
1605  $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1606  $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
1607  }
1608 
1609  return true;
1610  }
1611 
1612  // toggle subscription interface
1613  function setRegisterMode($a_bool)
1614  {
1615  $this->register = (bool) $a_bool;
1616  }
1617 
1618  // check register status of current user
1619  // abstract method; overwrite in object type class
1620  function isUserRegistered($a_user_id = 0)
1621  {
1622  return false;
1623  }
1624 
1626  {
1627  return $this->register;
1628  }
1629 
1630 
1631  function getXMLZip()
1632  {
1633  return false;
1634  }
1635  function getHTMLDirectory()
1636  {
1637  return false;
1638  }
1639 
1643  static function _getObjectsByType($a_obj_type = "", $a_owner = "")
1644  {
1645  global $ilDB;
1646 
1647  $order = " ORDER BY title";
1648 
1649  // where clause
1650  if ($a_obj_type)
1651  {
1652  $where_clause = "WHERE type = ".
1653  $ilDB->quote($a_obj_type, "text");
1654 
1655  if ($a_owner != "")
1656  {
1657  $where_clause.= " AND owner = ".$ilDB->quote($a_owner, "integer");
1658  }
1659  }
1660 
1661  $q = "SELECT * FROM object_data ".$where_clause.$order;
1662  $r = $ilDB->query($q);
1663 
1664  $arr = array();
1665  if ($ilDB->numRows($r) > 0)
1666  {
1667  while ($row = $ilDB->fetchAssoc($r))
1668  {
1669  $row["desc"] = $row["description"];
1670  $arr[$row["obj_id"]] = $row;
1671  }
1672  }
1673 
1674  return $arr;
1675  }
1676 
1685  public static function _prepareCloneSelection($a_ref_ids,$new_type,$show_path = true)
1686  {
1687  global $ilDB,$lng,$objDefinition;
1688 
1689  $query = "SELECT obj_data.title obj_title,path_data.title path_title,child FROM tree ".
1690  "JOIN object_reference obj_ref ON child = obj_ref.ref_id ".
1691  "JOIN object_data obj_data ON obj_ref.obj_id = obj_data.obj_id ".
1692  "JOIN object_reference path_ref ON parent = path_ref.ref_id ".
1693  "JOIN object_data path_data ON path_ref.obj_id = path_data.obj_id ".
1694  "WHERE ".$ilDB->in("child", $a_ref_ids, false, "integer")." ".
1695  "ORDER BY obj_data.title ";
1696  $res = $ilDB->query($query);
1697 
1698  if (!$objDefinition->isPlugin($new_type))
1699  {
1700  $options[0] = $lng->txt('obj_'.$new_type.'_select');
1701  }
1702  else
1703  {
1704  include_once("./Services/Component/classes/class.ilPlugin.php");
1705  $options[0] = ilPlugin::lookupTxt("rep_robj", $new_type, "obj_".$new_type."_select");
1706  }
1707 
1708  while($row = $ilDB->fetchObject($res))
1709  {
1710  if(strlen($title = $row->obj_title) > 40)
1711  {
1712  $title = substr($title,0,40).'...';
1713  }
1714 
1715  if($show_path)
1716  {
1717  if(strlen($path = $row->path_title) > 40)
1718  {
1719  $path = substr($path,0,40).'...';
1720  }
1721 
1722  $title .= ' ('.$lng->txt('path').': '.$path.')';
1723  }
1724 
1725  $options[$row->child] = $title;
1726  }
1727  return $options ? $options : array();
1728  }
1729 
1739  public function cloneObject($a_target_id,$a_copy_id = 0,$a_omit_tree = false)
1740  {
1741  global $objDefinition,$ilUser,$rbacadmin, $ilDB;
1742 
1743  $location = $objDefinition->getLocation($this->getType());
1744  $class_name = ('ilObj'.$objDefinition->getClassName($this->getType()));
1745 
1746  if(!$a_omit_tree)
1747  {
1748  $title = $this->appendCopyInfo($a_target_id,$a_copy_id);
1749  }
1750  else
1751  {
1752  $title = $this->getTitle();
1753  }
1754 
1755  // create instance
1756  include_once($location."/class.".$class_name.".php");
1757  $new_obj = new $class_name(0, false);
1758  $new_obj->setOwner($ilUser->getId());
1759  $new_obj->setTitle($title);
1760  $new_obj->setDescription($this->getLongDescription());
1761  $new_obj->setType($this->getType());
1762  // Choose upload mode to avoid creation of additional settings, db entries ...
1763  $new_obj->create(true);
1764 
1765  if(!$a_omit_tree)
1766  {
1767  $new_obj->createReference();
1768  $new_obj->putInTree($a_target_id);
1769  $new_obj->setPermissions($a_target_id);
1770 
1771  // when copying from personal workspace we have no current ref id
1772  if($this->getRefId())
1773  {
1774  // copy local roles
1775  $rbacadmin->copyLocalRoles($this->getRefId(),$new_obj->getRefId());
1776  }
1777  }
1778 
1779  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1780  ilAdvancedMDValues::_cloneValues($this->getId(),$new_obj->getId());
1781 
1782  // BEGIN WebDAV: Clone WebDAV properties
1783  $query = "INSERT INTO dav_property (obj_id,node_id,ns,name,value) ".
1784  "SELECT ".$ilDB->quote($new_obj->getId(),'integer').",node_id,ns,name,value ".
1785  "FROM dav_property ".
1786  "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer');
1787  $res = $ilDB->manipulate($query);
1788  // END WebDAV: Clone WebDAV properties
1789 
1790  return $new_obj;
1791  }
1792 
1800  public function appendCopyInfo($a_target_id,$a_copy_id)
1801  {
1802  global $tree;
1803 
1804  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
1805  $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
1806  if(!$cp_options->isRootNode($this->getRefId()))
1807  {
1808  return $this->getTitle();
1809  }
1810  $nodes = $tree->getChilds($a_target_id);
1811 
1812  $title_unique = false;
1813  require_once 'Modules/File/classes/class.ilObjFileAccess.php';
1814  $numberOfCopy = 1;
1816  while(!$title_unique)
1817  {
1818  $found = 0;
1819  foreach($nodes as $node)
1820  {
1821  if(($title == $node['title']) and ($this->getType() == $node['type']))
1822  {
1823  $found++;
1824  }
1825  }
1826  if($found > 0)
1827  {
1828  $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), ++$numberOfCopy);
1829  }
1830  else
1831  {
1832  break;
1833  }
1834  }
1835  return $title;
1836  }
1837 
1850  public function cloneDependencies($a_target_id,$a_copy_id)
1851  {
1852  include_once './Services/AccessControl/classes/class.ilConditionHandler.php';
1853  include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1854 
1855  $cwo = ilCopyWizardOptions::_getInstance($a_copy_id);
1856  $mappings = $cwo->getMappings();
1857 
1858  $conditions = ilConditionHandler::_getConditionsOfTarget($this->getRefId(), $this->getId());
1859  foreach($conditions as $con)
1860  {
1861  if($mappings[$con['trigger_ref_id']])
1862  {
1863  $newCondition = new ilConditionHandler();
1864 
1865  $target_obj = ilObject::_lookupObjId($a_target_id);
1866  $target_typ = ilObject::_lookupType($target_obj);
1867 
1868  $newCondition->setTargetRefId($a_target_id);
1869  $newCondition->setTargetObjId($target_obj);
1870  $newCondition->setTargetType($target_typ);
1871 
1872  $trigger_ref = $mappings[$con['trigger_ref_id']];
1873  $trigger_obj = ilObject::_lookupObjId($trigger_ref);
1874  $trigger_typ = ilObject::_lookupType($trigger_obj);
1875 
1876  $newCondition->setTriggerRefId($trigger_ref);
1877  $newCondition->setTriggerObjId($trigger_obj);
1878  $newCondition->setTriggerType($trigger_typ);
1879  $newCondition->setOperator($con['operator']);
1880  $newCondition->setValue($con['value']);
1881  $newCondition->setReferenceHandlingType($con['ref_handling']);
1882  $newCondition->setObligatory($con['obligatory']);
1883  $newCondition->storeCondition();
1884  }
1885  }
1886 
1887  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1889  if($tpl_id)
1890  {
1891  include_once './Services/Object/classes/class.ilObjectFactory.php';
1892  $factory = new ilObjectFactory();
1893  $obj = $factory->getInstanceByRefId($a_target_id, FALSE);
1894  if($obj instanceof ilObject)
1895  {
1896  $obj->applyDidacticTemplate($tpl_id);
1897  }
1898  }
1899  return true;
1900  }
1901 
1909  public function cloneMetaData($target_obj)
1910  {
1911  include_once "./Services/MetaData/classes/class.ilMD.php";
1912  $md = new ilMD($this->getId(),0,$this->getType());
1913  $md->cloneMD($target_obj->getId(),0,$target_obj->getType());
1914  return true;
1915  }
1916 
1925  public static function _getIcon($a_obj_id = "", $a_size = "big", $a_type = "",
1926  $a_offline = false)
1927  {
1928  global $ilSetting, $objDefinition;
1929 
1930  if ($a_obj_id == "" && $a_type == "")
1931  {
1932  return "";
1933  }
1934 
1935  if ($a_type == "")
1936  {
1937  $a_type = ilObject::_lookupType($a_obj_id);
1938  }
1939 
1940  if ($a_size == "")
1941  {
1942  $a_size = "big";
1943  }
1944 
1945  if ($ilSetting->get("custom_icons") &&
1946  in_array($a_type, array("cat","grp","crs", "root")))
1947  {
1948  require_once("./Services/Container/classes/class.ilContainer.php");
1949  if (ilContainer::_lookupContainerSetting($a_obj_id, "icon_".$a_size))
1950  {
1951  $cont_dir = ilContainer::_getContainerDirectory($a_obj_id);
1952 
1953  // png version? (introduced with ILIAS 4.3)
1954  $file_name = $cont_dir."/icon_".$a_size.".png";
1955  if (is_file($file_name))
1956  {
1957  return $file_name;
1958  }
1959 
1960  // gif version? (prior to ILIAS 4.3)
1961  $file_name = $cont_dir."/icon_".$a_size.".gif";
1962  if (is_file($file_name))
1963  {
1964  return $file_name;
1965  }
1966  }
1967  }
1968 
1969  switch($a_size)
1970  {
1971  case "small": $suff = ""; break;
1972  case "tiny": $suff = "_s"; break;
1973  default: $suff = "_b"; break;
1974  }
1975  if (!$a_offline)
1976  {
1977  if ($objDefinition->isPluginTypeName($a_type))
1978  {
1979  include_once("./Services/Repository/classes/class.ilRepositoryObjectPlugin.php");
1980  return ilRepositoryObjectPlugin::_getIcon($a_type, $a_size);
1981  }
1982  return ilUtil::getImagePath("icon_".$a_type.$suff.".png");
1983  }
1984  else
1985  {
1986  return "./images/icon_".$a_type.$suff.".png";
1987  }
1988  }
1989 
1996  static final function collectDeletionDependencies(&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth = 0)
1997  {
1998  global $objDefinition, $tree;
1999 
2000  if ($a_depth == 0)
2001  {
2002  $deps["dep"] = array();
2003  }
2004 
2005  $deps["del_ids"][$a_obj_id] = $a_obj_id;
2006 
2007  if (!$objDefinition->isPlugin($type))
2008  {
2009  $class_name = "ilObj".$objDefinition->getClassName($a_type);
2010  $location = $objDefinition->getLocation($a_type);
2011  include_once($location."/class.".$class_name.".php");
2012  $odeps = call_user_func(array($class_name, "getDeletionDependencies"), $a_obj_id);
2013  if (is_array($odeps))
2014  {
2015  foreach ($odeps as $id => $message)
2016  {
2017  $deps["dep"][$id][$a_obj_id][] = $message;
2018  }
2019  }
2020 
2021  // get deletion dependency of childs
2022  foreach ($tree->getChilds($a_ref_id) as $c)
2023  {
2024  ilObject::collectDeletionDependencies($deps, $c["child"], $c["obj_id"], $c["type"], $a_depth + 1);
2025  }
2026  }
2027 
2028  // delete all dependencies to objects that will be deleted, too
2029  if ($a_depth == 0)
2030  {
2031  foreach ($deps["del_ids"] as $obj_id)
2032  {
2033  unset($deps["dep"][$obj_id]);
2034  }
2035  $deps = $deps["dep"];
2036  }
2037  }
2038 
2043  static function getDeletionDependencies($a_obj_id)
2044  {
2045  return false;
2046  }
2047 
2054  static function getLongDescriptions(array $a_obj_ids)
2055  {
2056  global $ilDB;
2057 
2058  $res = $ilDB->query("SELECT * FROM object_description".
2059  " WHERE ".$ilDB->in("obj_id", $a_obj_ids, "", "integer"));
2060  $all = array();
2061  while($row = $ilDB->fetchAssoc($res))
2062  {
2063  $all[$row["obj_id"]] = $row["description"];
2064  }
2065  return $all;
2066  }
2067 
2074  static function getAllOwnedRepositoryObjects($a_user_id)
2075  {
2076  global $ilDB, $objDefinition;
2077 
2078  $all = array();
2079 
2080  // restrict to repository
2081  $types = array_keys($objDefinition->getSubObjectsRecursively("root"));
2082 
2083  $sql = "SELECT od.obj_id,od.type,od.title FROM object_data od";
2084 
2085  if($a_user_id)
2086  {
2087  $sql .= " WHERE od.owner = ".$ilDB->quote($a_user_id, "integer");
2088  }
2089  else
2090  {
2091  $sql .= " LEFT JOIN usr_data ud ON (ud.usr_id = od.owner)".
2092  " WHERE (od.owner < ".$ilDB->quote(1, "integer").
2093  " OR od.owner IS NULL OR ud.login IS NULL)".
2094  " AND od.owner <> ".$ilDB->quote(-1, "integer");
2095  }
2096 
2097  $sql .= " AND ".$ilDB->in("od.type", $types, "", "text");
2098 
2099  $res = $ilDB->query($sql);
2100  while($row = $ilDB->fetchAssoc($res))
2101  {
2102  $all[$row["type"]][$row["obj_id"]] = $row["title"];
2103  }
2104 
2105  return $all;
2106  }
2107 
2114  function _lookupCreationDate($a_id)
2115  {
2116  global $ilDB;
2117 
2118  $set = $ilDB->query("SELECT create_date FROM object_data ".
2119  " WHERE obj_id = ".$ilDB->quote($a_id, "integer"));
2120  $rec = $ilDB->fetchAssoc($set);
2121  return $rec["create_date"];
2122  }
2123 
2124 } // END class.ilObject
2125 ?>