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