ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 require_once('./Services/Repository/classes/class.ilObjectPlugin.php');
5 
15 class ilObject
16 {
20  const TITLE_LENGTH = 255; // title column max length in db
21  const DESC_LENGTH = 128; // (short) description column max length in db
22 
23 
29  var $ilias;
30 
36  var $lng;
37 
43  var $id; // true object_id!!!!
44  var $ref_id;// reference_id
45  var $type;
46  var $title;
47  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
49  // END WebDAV: WebDAV needs to access the untranslated title of an object
50  var $desc;
52  var $owner;
56  var $register = false; // registering required for object? set to true to implement a subscription interface
57 
64 
71 
77 
82  var $max_desc;
83 
88  var $add_dots;
89 
90 
97  function __construct($a_id = 0, $a_reference = true)
98  {
99  global $ilias, $lng, $ilBench, $objDefinition;
100 
101  $ilBench->start("Core", "ilObject_Constructor");
102 
103  if (DEBUG)
104  {
105  echo "<br/><font color=\"red\">type(".$this->type.") id(".$a_id.") referenced(".$a_reference.")</font>";
106  }
107 
108  $this->ilias =& $ilias;
109  $this->lng =& $lng;
110  $this->objDefinition = $objDefinition;
111 
112  $this->max_title = self::TITLE_LENGTH;
113  $this->max_desc = self::DESC_LENGTH;
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  public function read()
157  {
158  global $objDefinition, $ilBench, $ilDB, $log;
159 
160  $ilBench->start("Core", "ilObject_read");
161  if ($this->referenced)
162  {
163  // check reference id
164  if (!isset($this->ref_id))
165  {
166  $message = "ilObject::read(): No ref_id given! (".$this->type.")";
167  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
168  }
169 
170  // read object data
171  $ilBench->start("Core", "ilObject_read_readData");
172 
173  $q = "SELECT * FROM object_data, object_reference WHERE object_data.obj_id=object_reference.obj_id ".
174  "AND object_reference.ref_id= ".$ilDB->quote($this->ref_id, "integer");
175  $object_set = $ilDB->query($q);
176  $ilBench->stop("Core", "ilObject_read_readData");
177 
178  // check number of records
179  if ($ilDB->numRows($object_set) == 0)
180  {
181  $message = "ilObject::read(): Object with ref_id ".$this->ref_id." not found! (".$this->type.")";
182  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
183  }
184 
185  $obj = $ilDB->fetchAssoc($object_set);
186  }
187  else
188  {
189  // check object id
190  if (!isset($this->id))
191  {
192  $message = "ilObject::read(): No obj_id given! (".$this->type.")";
193  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
194  }
195 
196  // read object data
197  $q = "SELECT * FROM object_data ".
198  "WHERE obj_id = ".$ilDB->quote($this->id, "integer");
199  $object_set = $ilDB->query($q);
200 
201  // check number of records
202  if ($ilDB->numRows($object_set) == 0)
203  {
204  include_once("./Services/Object/exceptions/class.ilObjectNotFoundException.php");
205  throw new ilObjectNotFoundException("ilObject::read(): Object with obj_id: ".$this->id.
206  " (".$this->type.") not found!");
207  return;
208  }
209 
210  $obj = $ilDB->fetchAssoc($object_set);
211  }
212 
213  $this->id = $obj["obj_id"];
214 
215  // check type match (the "xxx" type is used for the unit test)
216  if ($this->type != $obj["type"] && $obj["type"] != "xxx")
217  {
218  $message = "ilObject::read(): Type mismatch. Object with obj_id: ".$this->id." ".
219  "was instantiated by type '".$this->type."'. DB type is: ".$obj["type"];
220 
221  // write log entry
222  $log->write($message);
223 
224  // raise error
225  include_once("./Services/Object/exceptions/class.ilObjectTypeMismatchException.php");
226  throw new ilObjectTypeMismatchException($message);
227  return;
228  }
229 
230  $this->type = $obj["type"];
231  $this->title = $obj["title"];
232  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
233  $this->untranslatedTitle = $obj["title"];
234  // END WebDAV: WebDAV needs to access the untranslated title of an object
235  $this->desc = $obj["description"];
236  $this->owner = $obj["owner"];
237  $this->create_date = $obj["create_date"];
238  $this->last_update = $obj["last_update"];
239  $this->import_id = $obj["import_id"];
240 
241  if($objDefinition->isRBACObject($this->getType()))
242  {
243  // Read long description
244  $query = "SELECT * FROM object_description WHERE obj_id = ".$ilDB->quote($this->id,'integer');
245  $res = $this->ilias->db->query($query);
246  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
247  {
248  if(strlen($row->description))
249  {
250  $this->setDescription($row->description);
251  }
252  }
253  }
254 
255  // multilingual support systemobjects (sys) & categories (db)
256  $ilBench->start("Core", "ilObject_Constructor_getTranslation");
257  $translation_type = $objDefinition->getTranslationType($this->type);
258 
259  if ($translation_type == "sys")
260  {
261  $this->title = $this->lng->txt("obj_".$this->type);
262  $this->setDescription($this->lng->txt("obj_".$this->type."_desc"));
263  }
264  elseif ($translation_type == "db")
265  {
266  $q = "SELECT title,description FROM object_translation ".
267  "WHERE obj_id = ".$ilDB->quote($this->id,'integer')." ".
268  "AND lang_code = ".$ilDB->quote($this->ilias->account->getCurrentLanguage(),'text')." ".
269  "AND NOT lang_default = 1";
270  $r = $this->ilias->db->query($q);
272  if ($row)
273  {
274  $this->title = $row->title;
275  $this->setDescription($row->description);
276  #$this->desc = $row->description;
277  }
278  }
279 
280  $ilBench->stop("Core", "ilObject_Constructor_getTranslation");
281 
282  $ilBench->stop("Core", "ilObject_read");
283  }
284 
290  function getId()
291  {
292  return $this->id;
293  }
294 
300  function setId($a_id)
301  {
302  $this->id = $a_id;
303  }
304 
310  function setRefId($a_id)
311  {
312  $this->ref_id = $a_id;
313  $this->referenced = true;
314  }
315 
321  function getRefId()
322  {
323  return $this->ref_id;
324  }
325 
331  function getType()
332  {
333  return $this->type;
334  }
335 
341  function setType($a_type)
342  {
343  $this->type = $a_type;
344  }
345 
355  public function getPresentationTitle()
356  {
357  return $this->getTitle();
358  }
359 
360 
366  function getTitle()
367  {
368  return $this->title;
369  }
370  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
377  {
379  }
380  // END WebDAV: WebDAV needs to access the untranslated title of an object
381 
388  function setTitle($a_title)
389  {
390  $this->title = ilUtil::shortenText($a_title, $this->max_title, $this->add_dots);
391  // BEGIN WebDAV: WebDAV needs to access the untranslated title of an object
392  $this->untranslatedTitle = $this->title;
393  // END WebDAV: WebDAV needs to access the untranslated title of an object
394  }
395 
402  function getDescription()
403  {
404  return $this->desc;
405  }
406 
413  function setDescription($a_desc)
414  {
415  // Shortened form is storted in object_data. Long form is stored in object_description
416  $this->desc = ilUtil::shortenText($a_desc, $this->max_desc, $this->add_dots);
417 
418  $this->long_desc = $a_desc;
419 
420  return true;
421  }
422 
430  {
431  return strlen($this->long_desc) ? $this->long_desc : $this->desc;
432  }
433 
440  function getImportId()
441  {
442  return $this->import_id;
443  }
444 
451  function setImportId($a_import_id)
452  {
453  $this->import_id = $a_import_id;
454  }
455 
456  public static function _lookupObjIdByImportId($a_import_id)
457  {
458  global $ilDB;
459 
460  $query = "SELECT * FROM object_data ".
461  "WHERE import_id = ".$ilDB->quote($a_import_id, "text")." ".
462  "ORDER BY create_date DESC";
463  $res = $ilDB->query($query);
464  while($row = $ilDB->fetchObject($res))
465  {
466  return $row->obj_id;
467  }
468  return 0;
469  }
470 
471  public static function _lookupImportId($a_obj_id)
472  {
473  global $ilDB;
474 
475  $query = "SELECT import_id FROM object_data ".
476  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
477  $res = $ilDB->query($query);
478  $row = $ilDB->fetchObject($res);
479  return $row->import_id;
480  }
481 
488  function getOwner()
489  {
490  return $this->owner;
491  }
492 
493  /*
494  * get full name of object owner
495  *
496  * @access public
497  * @return string owner name or unknown
498  */
499  function getOwnerName()
500  {
501  return ilObject::_lookupOwnerName($this->getOwner());
502  }
503 
507  static function _lookupOwnerName($a_owner_id)
508  {
509  global $lng;
510 
511  if ($a_owner_id != -1)
512  {
513  if (ilObject::_exists($a_owner_id))
514  {
515  $owner = new ilObjUser($a_owner_id);
516  }
517  }
518 
519  if (is_object($owner))
520  {
521  $own_name = $owner->getFullname();
522  }
523  else
524  {
525  $own_name = $lng->txt("unknown");
526  }
527 
528  return $own_name;
529  }
530 
537  function setOwner($a_owner)
538  {
539  $this->owner = $a_owner;
540  }
541 
542 
543 
549  function getCreateDate()
550  {
551  return $this->create_date;
552  }
553 
559  function getLastUpdateDate()
560  {
561  return $this->last_update;
562  }
563 
564 
576  function getDiskUsage()
577  {
578  return null;
579  }
580 
589  function create()
590  {
591  global $ilDB, $log,$ilUser,$objDefinition;
592 
593  if (!isset($this->type))
594  {
595  $message = get_class($this)."::create(): No object type given!";
596  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
597  }
598 
599  // write log entry
600  $log->write("ilObject::create(), start");
601 
602  $this->title = ilUtil::shortenText($this->getTitle(), $this->max_title, $this->add_dots);
603  $this->desc = ilUtil::shortenText($this->getDescription(), $this->max_desc, $this->add_dots);
604 
605  // determine owner
606  if ($this->getOwner() > 0)
607  {
608  $owner = $this->getOwner();
609  }
610  elseif(is_object($ilUser))
611  {
612  $owner = $ilUser->getId();
613  }
614  else
615  {
616  $owner = 0;
617  }
618  $this->id = $ilDB->nextId("object_data");
619  $q = "INSERT INTO object_data ".
620  "(obj_id,type,title,description,owner,create_date,last_update,import_id) ".
621  "VALUES ".
622  "(".
623  $ilDB->quote($this->id, "integer").",".
624  $ilDB->quote($this->type, "text").",".
625  $ilDB->quote($this->getTitle(), "text").",".
626  $ilDB->quote($this->getDescription(), "text").",".
627  $ilDB->quote($owner, "integer").",".
628  $ilDB->now().",".
629  $ilDB->now().",".
630  $ilDB->quote($this->getImportId(), "text").")";
631 
632  $ilDB->manipulate($q);
633 
634  //$this->id = $ilDB->getLastInsertId();
635 
636 
637  // Save long form of description if is rbac object
638  if($objDefinition->isRBACObject($this->getType()))
639  {
640  $values = array(
641  'obj_id' => array('integer',$this->id),
642  'description' => array('clob', $this->getLongDescription()));
643 //var_dump($values);
644  $ilDB->insert('object_description',$values);
645  }
646 
647 
648  // the line ($this->read();) messes up meta data handling: meta data,
649  // that is not saved at this time, gets lost, so we query for the dates alone
650  //$this->read();
651  $q = "SELECT last_update, create_date FROM object_data".
652  " WHERE obj_id = ".$ilDB->quote($this->id, "integer");
653  $obj_set = $ilDB->query($q);
654  $obj_rec = $ilDB->fetchAssoc($obj_set);
655  $this->last_update = $obj_rec["last_update"];
656  $this->create_date = $obj_rec["create_date"];
657 
658  // set owner for new objects
659  $this->setOwner($owner);
660 
661  // write log entry
662  $log->write("ilObject::create(), finished, obj_id: ".$this->id.", type: ".
663  $this->type.", title: ".$this->getTitle());
664 
665  $GLOBALS['ilAppEventHandler']->raise(
666  'Services/Object',
667  'create',
668  array('obj_id' => $this->id,'obj_type' => $this->type));
669 
670  return $this->id;
671  }
672 
679  function update()
680  {
681  global $objDefinition, $ilDB;
682 
683  $q = "UPDATE object_data ".
684  "SET ".
685  "title = ".$ilDB->quote($this->getTitle(), "text").",".
686  "description = ".$ilDB->quote($this->getDescription(), "text").", ".
687  "import_id = ".$ilDB->quote($this->getImportId(), "text").",".
688  "last_update = ".$ilDB->now()." ".
689  "WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
690  $ilDB->manipulate($q);
691 
692  // the line ($this->read();) messes up meta data handling: meta data,
693  // that is not saved at this time, gets lost, so we query for the dates alone
694  //$this->read();
695  $q = "SELECT last_update FROM object_data".
696  " WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
697  $obj_set = $ilDB->query($q);
698  $obj_rec = $ilDB->fetchAssoc($obj_set);
699  $this->last_update = $obj_rec["last_update"];
700 
701  if($objDefinition->isRBACObject($this->getType()))
702  {
703  // Update long description
704  $res = $this->ilias->db->query("SELECT * FROM object_description WHERE obj_id = ".
705  $ilDB->quote($this->getId(),'integer'));
706  if($res->numRows())
707  {
708  $values = array(
709  'description' => array('clob',$this->getLongDescription())
710  );
711  $ilDB->update('object_description',$values,array('obj_id' => array('integer',$this->getId())));
712  }
713  else
714  {
715  $values = array(
716  'description' => array('clob',$this->getLongDescription()),
717  'obj_id' => array('integer',$this->getId()));
718  $ilDB->insert('object_description',$values);
719  }
720  }
721  $GLOBALS['ilAppEventHandler']->raise(
722  'Services/Object',
723  'update',
724  array('obj_id' => $this->getId(),
725  'obj_type' => $this->getType(),
726  'ref_id' => $this->getRefId()));
727 
728  return true;
729  }
730 
742  function MDUpdateListener($a_element)
743  {
744  include_once 'Services/MetaData/classes/class.ilMD.php';
745 
746  $GLOBALS['ilAppEventHandler']->raise(
747  'Services/Object',
748  'update',
749  array('obj_id' => $this->getId(),
750  'obj_type' => $this->getType(),
751  'ref_id' => $this->getRefId()));
752 
753  switch($a_element)
754  {
755  case 'General':
756 
757  // Update Title and description
758  $md = new ilMD($this->getId(),0, $this->getType());
759  if(!is_object($md_gen = $md->getGeneral()))
760  {
761  return false;
762  }
763  $this->setTitle($md_gen->getTitle());
764 
765  foreach($md_gen->getDescriptionIds() as $id)
766  {
767  $md_des = $md_gen->getDescription($id);
768  $this->setDescription($md_des->getDescription());
769  break;
770  }
771  $this->update();
772  break;
773 
774  default:
775  }
776 
777  return true;
778  }
779 
783  function createMetaData()
784  {
785  include_once 'Services/MetaData/classes/class.ilMDCreator.php';
786 
787  global $ilUser;
788 
789  $md_creator = new ilMDCreator($this->getId(),0,$this->getType());
790  $md_creator->setTitle($this->getTitle());
791  $md_creator->setTitleLanguage($ilUser->getPref('language'));
792  $md_creator->setDescription($this->getLongDescription());
793  $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
794  $md_creator->setKeywordLanguage($ilUser->getPref('language'));
795  $md_creator->setLanguage($ilUser->getPref('language'));
796  $md_creator->create();
797 
798  return true;
799  }
800 
804  function updateMetaData()
805  {
806  include_once("Services/MetaData/classes/class.ilMD.php");
807  include_once("Services/MetaData/classes/class.ilMDGeneral.php");
808  include_once("Services/MetaData/classes/class.ilMDDescription.php");
809 
810  $md = new ilMD($this->getId(), 0, $this->getType());
811  $md_gen =& $md->getGeneral();
812  // BEGIN WebDAV: meta data can be missing sometimes.
813  if ($md_gen == null)
814  {
815  $this->createMetaData();
816  $md = new ilMD($this->getId(), 0, $this->getType());
817  $md_gen =& $md->getGeneral();
818  }
819  // END WebDAV: meta data can be missing sometimes.
820  $md_gen->setTitle($this->getTitle());
821 
822  // sets first description (maybe not appropriate)
823  $md_des_ids =& $md_gen->getDescriptionIds();
824  if (count($md_des_ids) > 0)
825  {
826  $md_des =& $md_gen->getDescription($md_des_ids[0]);
827  $md_des->setDescription($this->getLongDescription());
828  $md_des->update();
829  }
830  $md_gen->update();
831 
832  }
833 
837  function deleteMetaData()
838  {
839  // Delete meta data
840  include_once('Services/MetaData/classes/class.ilMD.php');
841  $md = new ilMD($this->getId(), 0, $this->getType());
842  $md->deleteAll();
843  }
844 
851  function updateOwner()
852  {
853  global $ilDB;
854 
855  $q = "UPDATE object_data ".
856  "SET ".
857  "owner = ".$ilDB->quote($this->getOwner(), "integer").", ".
858  "last_update = ".$ilDB->now()." ".
859  "WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
860  $ilDB->manipulate($q);
861 
862  $q = "SELECT last_update FROM object_data".
863  " WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
864  $obj_set = $ilDB->query($q);
865  $obj_rec = $ilDB->fetchAssoc($obj_set);
866  $this->last_update = $obj_rec["last_update"];
867 
868  return true;
869  }
870 
878  static function _getIdForImportId($a_import_id)
879  {
880  global $ilDB;
881 
882  $ilDB->setLimit(1,0);
883  $q = "SELECT * FROM object_data WHERE import_id = ".$ilDB->quote($a_import_id, "text").
884  " ORDER BY create_date DESC";
885  $obj_set = $ilDB->query($q);
886 
887  if ($obj_rec = $ilDB->fetchAssoc($obj_set))
888  {
889  return $obj_rec["obj_id"];
890  }
891  else
892  {
893  return 0;
894  }
895  }
896 
902  public static function _getAllReferences($a_id)
903  {
904  global $ilDB;
905 
906  $query = "SELECT * FROM object_reference WHERE obj_id = ".
907  $ilDB->quote($a_id,'integer');
908 
909  $res = $ilDB->query($query);
910  $ref = array();
911  while($obj_rec = $ilDB->fetchAssoc($res))
912  {
913  $ref[$obj_rec["ref_id"]] = $obj_rec["ref_id"];
914  }
915 
916  return $ref;
917  }
918 
924  public static function _lookupTitle($a_id)
925  {
926  global $ilObjDataCache;
927 
928  $tit = $ilObjDataCache->lookupTitle($a_id);
929 //echo "<br>LOOKING-$a_id-:$tit";
930  return $tit;
931  }
932 
938  static function _lookupOwner($a_id)
939  {
940  global $ilObjDataCache;
941 
942  $owner = $ilObjDataCache->lookupOwner($a_id);
943  return $owner;
944  }
945 
946  public static function _getIdsForTitle($title, $type = '', $partialmatch = false)
947  {
948  global $ilDB;
949 
950  $query = (!$partialmatch)
951  ? "SELECT obj_id FROM object_data WHERE title = ".$ilDB->quote($title, "text")
952  : "SELECT obj_id FROM object_data WHERE ".$ilDB->like("title", "text", '%'.$title.'%');
953  if($type != '')
954  {
955  $query .= " AND type = ".$ilDB->quote($type, "text");
956  }
957 
958  $result = $ilDB->query($query);
959 
960  $object_ids = array();
961  while($row = $ilDB->fetchAssoc($result))
962  {
963  $object_ids[] = $row['obj_id'];
964  }
965 
966  return is_array($object_ids) ? $object_ids : array();
967  }
968 
974  public static function _lookupDescription($a_id)
975  {
976  global $ilObjDataCache;
977 
978  return $ilObjDataCache->lookupDescription($a_id);
979  }
980 
986  static function _lookupLastUpdate($a_id, $a_as_string = false)
987  {
988  global $ilObjDataCache;
989 
990  if ($a_as_string)
991  {
992  return ilDatePresentation::formatDate(new ilDateTime($ilObjDataCache->lookupLastUpdate($a_id),IL_CAL_DATETIME));
993  }
994  else
995  {
996  return $ilObjDataCache->lookupLastUpdate($a_id);
997  }
998  }
999 
1005  static function _getLastUpdateOfObjects($a_objs)
1006  {
1007  global $ilDB;
1008 
1009  if (!is_array($a_objs))
1010  {
1011  $a_objs = array($a_objs);
1012  }
1013  $types = array();
1014  $set = $ilDB->query("SELECT max(last_update) as last_update FROM object_data ".
1015  "WHERE ".$ilDB->in("obj_id", $a_objs, false, "integer")." ");
1016  $rec = $ilDB->fetchAssoc($set);
1017 
1018  return ($rec["last_update"]);
1019  }
1020 
1021  public static function _lookupObjId($a_id)
1022  {
1023  global $ilObjDataCache;
1024 
1025  return (int) $ilObjDataCache->lookupObjId($a_id);
1026  }
1027 
1031  static function _setDeletedDate($a_ref_id)
1032  {
1033  global $ilDB;
1034 
1035  $query = "UPDATE object_reference SET deleted= ".$ilDB->now().' '.
1036  "WHERE ref_id = ".$ilDB->quote($a_ref_id,'integer');
1037  $res = $ilDB->manipulate($query);
1038  }
1039 
1046  public static function setDeletedDates($a_ref_ids)
1047  {
1048  global $ilDB;
1049 
1050  $query = 'UPDATE object_reference SET deleted = '.$ilDB->now().' '.
1051  'WHERE '.$ilDB->in('ref_id',(array) $a_ref_ids,false,'integer');
1052 
1053  $GLOBALS['ilLog']->write(__METHOD__.': Query is '. $query);
1054  $ilDB->manipulate($query);
1055  return;
1056  }
1057 
1061  public static function _resetDeletedDate($a_ref_id)
1062  {
1063  global $ilDB;
1064 
1065  $query = "UPDATE object_reference SET deleted = ".$ilDB->quote(null,'timestamp').
1066  " WHERE ref_id = ".$ilDB->quote($a_ref_id,'integer');
1067  $ilDB->manipulate($query);
1068  }
1069 
1073  static function _lookupDeletedDate($a_ref_id)
1074  {
1075  global $ilDB;
1076 
1077  $query = "SELECT deleted FROM object_reference".
1078  " WHERE ref_id = ".$ilDB->quote($a_ref_id, "integer");
1079  $set = $ilDB->query($query);
1080  $rec = $ilDB->fetchAssoc($set);
1081 
1082  return $rec["deleted"];
1083  }
1084 
1085 
1093  static function _writeTitle($a_obj_id, $a_title)
1094  {
1095  global $ilDB;
1096 
1097  $q = "UPDATE object_data ".
1098  "SET ".
1099  "title = ".$ilDB->quote($a_title, "text").",".
1100  "last_update = ".$ilDB->now()." ".
1101  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
1102 
1103  $ilDB->manipulate($q);
1104  }
1105 
1113  static function _writeDescription($a_obj_id, $a_desc)
1114  {
1115  global $ilDB,$objDefinition;
1116 
1117 
1118  $desc = ilUtil::shortenText($a_desc,self::DESC_LENGTH,true);
1119 
1120  $q = "UPDATE object_data ".
1121  "SET ".
1122  "description = ".$ilDB->quote($desc, "text").",".
1123  "last_update = ".$ilDB->now()." ".
1124  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
1125 
1126  $ilDB->manipulate($q);
1127 
1128  if($objDefinition->isRBACObject(ilObject::_lookupType($a_obj_id)))
1129  {
1130  // Update long description
1131  $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = ".
1132  $ilDB->quote($a_obj_id,'integer'));
1133 
1134  if($res->numRows())
1135  {
1136  $values = array(
1137  'description' => array('clob',$a_desc)
1138  );
1139  $ilDB->update('object_description',$values,array('obj_id' => array('integer',$a_obj_id)));
1140  }
1141  else
1142  {
1143  $values = array(
1144  'description' => array('clob',$a_desc),
1145  'obj_id' => array('integer',$a_obj_id));
1146  $ilDB->insert('object_description',$values);
1147  }
1148  }
1149  }
1150 
1158  static function _writeImportId($a_obj_id, $a_import_id)
1159  {
1160  global $ilDB;
1161 
1162  $q = "UPDATE object_data ".
1163  "SET ".
1164  "import_id = ".$ilDB->quote($a_import_id, "text").",".
1165  "last_update = ".$ilDB->now()." ".
1166  "WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
1167 
1168  $ilDB->manipulate($q);
1169  }
1170 
1176  public static function _lookupType($a_id,$a_reference = false)
1177  {
1178  global $ilObjDataCache;
1179 
1180  if($a_reference)
1181  {
1182  return $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_id));
1183  }
1184  return $ilObjDataCache->lookupType($a_id);
1185  }
1186 
1190  public static function _isInTrash($a_ref_id)
1191  {
1192  global $tree;
1193 
1194  return $tree->isSaved($a_ref_id);
1195  }
1196 
1200  static function _hasUntrashedReference($a_obj_id)
1201  {
1202  $ref_ids = ilObject::_getAllReferences($a_obj_id);
1203  foreach($ref_ids as $ref_id)
1204  {
1205  if(!ilObject::_isInTrash($ref_id))
1206  {
1207  return true;
1208  }
1209  }
1210 
1211  return false;
1212  }
1213 
1219  public static function _lookupObjectId($a_ref_id)
1220  {
1221  global $ilObjDataCache;
1222 
1223  return (int) $ilObjDataCache->lookupObjId($a_ref_id);
1224  }
1225 
1236  static function _getObjectsDataForType($a_type, $a_omit_trash = false)
1237  {
1238  global $ilDB;
1239 
1240  $q = "SELECT * FROM object_data WHERE type = ".$ilDB->quote($a_type, "text");
1241  $obj_set = $ilDB->query($q);
1242 
1243  $objects = array();
1244  while ($obj_rec = $ilDB->fetchAssoc($obj_set))
1245  {
1246  if ((!$a_omit_trash) || ilObject::_hasUntrashedReference($obj_rec["obj_id"]))
1247  {
1248  $objects[$obj_rec["title"].".".$obj_rec["obj_id"]] = array("id" => $obj_rec["obj_id"],
1249  "type" => $obj_rec["type"], "title" => $obj_rec["title"],
1250  "description" => $obj_rec["description"]);
1251  }
1252  }
1253  ksort($objects);
1254  return $objects;
1255  }
1256 
1262  function putInTree($a_parent_ref)
1263  {
1264  global $tree, $log;
1265 
1266  $tree->insertNode($this->getRefId(), $a_parent_ref);
1267 
1268  // write log entry
1269  $log->write("ilObject::putInTree(), parent_ref: $a_parent_ref, ref_id: ".
1270  $this->getRefId().", obj_id: ".$this->getId().", type: ".
1271  $this->getType().", title: ".$this->getTitle());
1272 
1273  }
1274 
1281  function setPermissions($a_parent_ref)
1282  {
1283  $this->setParentRolePermissions($a_parent_ref);
1284  $this->initDefaultRoles();
1285  }
1286 
1291  public function setParentRolePermissions($a_parent_ref)
1292  {
1293  global $rbacadmin, $rbacreview;
1294 
1295  $parent_roles = $rbacreview->getParentRoleIds($a_parent_ref);
1296  foreach((array) $parent_roles as $parent_role)
1297  {
1298  $operations = $rbacreview->getOperationsOfRole(
1299  $parent_role['obj_id'],
1300  $this->getType(),
1301  $parent_role['parent']
1302  );
1303  $rbacadmin->grantPermission(
1304  $parent_role['obj_id'],
1305  $operations,
1306  $this->getRefId()
1307  );
1308  }
1309  return true;
1310  }
1311 
1318  function createReference()
1319  {
1320  global $ilDB;
1321 
1322  if (!isset($this->id))
1323  {
1324  $message = "ilObject::createNewReference(): No obj_id given!";
1325  $this->raiseError($message,$this->ilias->error_obj->WARNING);
1326  }
1327 
1328  $next_id = $ilDB->nextId('object_reference');
1329  $query = "INSERT INTO object_reference ".
1330  "(ref_id, obj_id) VALUES (".$ilDB->quote($next_id,'integer').','.$ilDB->quote($this->id ,'integer').")";
1331  $this->ilias->db->query($query);
1332 
1333  $this->ref_id = $next_id;
1334  $this->referenced = true;
1335 
1336  return $this->ref_id;
1337  }
1338 
1339 
1346  function countReferences()
1347  {
1348  global $ilDB;
1349 
1350  if (!isset($this->id))
1351  {
1352  $message = "ilObject::countReferences(): No obj_id given!";
1353  $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
1354  }
1355 
1356  $query = "SELECT COUNT(ref_id) num FROM object_reference ".
1357  "WHERE obj_id = ".$ilDB->quote($this->id,'integer')." ";
1358  $res = $ilDB->query($query);
1359  $row = $ilDB->fetchObject($res);
1360 
1361  return $row->num;
1362  }
1363 
1364 
1365 
1366 
1376  function delete()
1377  {
1378  global $rbacadmin, $log, $ilDB;
1379 
1380  $remove = false;
1381 
1382  // delete object_data entry
1383  if ((!$this->referenced) || ($this->countReferences() == 1))
1384  {
1385  // check type match
1386  $db_type = ilObject::_lookupType($this->getId());
1387  if ($this->type != $db_type)
1388  {
1389  $message = "ilObject::delete(): Type mismatch. Object with obj_id: ".$this->id." ".
1390  "was instantiated by type '".$this->type."'. DB type is: ".$db_type;
1391 
1392  // write log entry
1393  $log->write($message);
1394 
1395  // raise error
1396  $this->ilias->raiseError("ilObject::delete(): Type mismatch. (".$this->type."/".$this->id.")",$this->ilias->error_obj->WARNING);
1397  }
1398 
1399  // delete entry in object_data
1400  $q = "DELETE FROM object_data ".
1401  "WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
1402  $ilDB->manipulate($q);
1403 
1404  // delete long description
1405  $query = "DELETE FROM object_description WHERE obj_id = ".
1406  $ilDB->quote($this->getId(), "integer");
1407  $ilDB->manipulate($query);
1408 
1409  // write log entry
1410  $log->write("ilObject::delete(), deleted object, obj_id: ".$this->getId().", type: ".
1411  $this->getType().", title: ".$this->getTitle());
1412 
1413  // keep log of core object data
1414  include_once "Services/Object/classes/class.ilObjectDataDeletionLog.php";
1416 
1417  // remove news
1418  include_once("./Services/News/classes/class.ilNewsItem.php");
1419  $news_item = new ilNewsItem();
1420  $news_item->deleteNewsOfContext($this->getId(), $this->getType());
1421  include_once("./Services/Block/classes/class.ilBlockSetting.php");
1423 
1424  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1426 
1427  /* remove notes (see infoscreen gui)
1428  as they can be seen as personal data we are keeping them for now
1429  include_once("Services/Notes/classes/class.ilNote.php");
1430  foreach(array(IL_NOTE_PRIVATE, IL_NOTE_PUBLIC) as $note_type)
1431  {
1432  foreach(ilNote::_getNotesOfObject($this->id, 0, $this->type, $note_type) as $note)
1433  {
1434  $note->delete();
1435  }
1436  }
1437  */
1438 
1439  // BEGIN WebDAV: Delete WebDAV properties
1440  $query = "DELETE FROM dav_property ".
1441  "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer');
1442  $res = $ilDB->manipulate($query);
1443  // END WebDAV: Delete WebDAV properties
1444 
1445  include_once './Services/WebServices/ECS/classes/class.ilECSImport.php';
1447 
1448  include_once("Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php");
1450 
1451  include_once("Services/Tracking/classes/class.ilLPObjSettings.php");
1453 
1454  $remove = true;
1455  }
1456  else
1457  {
1458  // write log entry
1459  $log->write("ilObject::delete(), object not deleted, number of references: ".
1460  $this->countReferences().", obj_id: ".$this->getId().", type: ".
1461  $this->getType().", title: ".$this->getTitle());
1462  }
1463 
1464  // delete object_reference entry
1465  if ($this->referenced)
1466  {
1467  include_once "Services/Object/classes/class.ilObjectActivation.php";
1469 
1470  // delete entry in object_reference
1471  $query = "DELETE FROM object_reference ".
1472  "WHERE ref_id = ".$ilDB->quote($this->getRefId(),'integer');
1473  $res = $ilDB->manipulate($query);
1474 
1475  // write log entry
1476  $log->write("ilObject::delete(), reference deleted, ref_id: ".$this->getRefId().
1477  ", obj_id: ".$this->getId().", type: ".
1478  $this->getType().", title: ".$this->getTitle());
1479 
1480  // DELETE PERMISSION ENTRIES IN RBAC_PA
1481  // DONE: method overwritten in ilObjRole & ilObjUser.
1482  // this call only applies for objects in rbac (not usr,role,rolt)
1483  // TODO: Do this for role templates too
1484  $rbacadmin->revokePermission($this->getRefId(),0,false);
1485 
1486  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
1487  ilRbacLog::delete($this->getRefId());
1488 
1489  // Remove applied didactic template setting
1490  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1492 
1493  // Remove desktop items
1495  }
1496 
1497  // remove conditions
1498  if ($this->referenced)
1499  {
1500  $ch = new ilConditionHandler();
1501  $ch->delete($this->getRefId());
1502  unset($ch);
1503  }
1504 
1505  return $remove;
1506  }
1507 
1515  function initDefaultRoles()
1516  {
1517  return array();
1518  }
1519 
1520 
1525  public function applyDidacticTemplate($a_tpl_id)
1526  {
1527  ilLoggerFactory::getLogger('obj')->debug('Applying didactic template with id: ' . (int) $a_tpl_id);
1528  if($a_tpl_id)
1529  {
1530  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
1531  foreach(ilDidacticTemplateActionFactory::getActionsByTemplateId($a_tpl_id) as $action)
1532  {
1533  $action->setRefId($this->getRefId());
1534  $action->apply();
1535  }
1536  }
1537 
1538  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1539  ilDidacticTemplateObjSettings::assignTemplate($this->getRefId(), $this->getId(), (int) $a_tpl_id);
1540  return $a_tpl_id ? true : false;
1541  }
1542 
1552  public static function _exists($a_id, $a_reference = false, $a_type = null)
1553  {
1554  global $ilDB;
1555 
1556  if ($a_reference)
1557  {
1558  $q = "SELECT * FROM object_data ".
1559  "LEFT JOIN object_reference ON object_reference.obj_id=object_data.obj_id ".
1560  "WHERE object_reference.ref_id= ".$ilDB->quote($a_id, "integer");
1561  }
1562  else
1563  {
1564  $q = "SELECT * FROM object_data WHERE obj_id=".$ilDB->quote($a_id, "integer");
1565  }
1566 
1567  if($a_type)
1568  $q .= " AND object_data.type = ".$ilDB->quote($a_type, "text");
1569 
1570  $r = $ilDB->query($q);
1571 
1572  return $ilDB->numRows($r) ? true : false;
1573  }
1574 
1575 // toggle subscription interface
1576  function setRegisterMode($a_bool)
1577  {
1578  $this->register = (bool) $a_bool;
1579  }
1580 
1581  // check register status of current user
1582  // abstract method; overwrite in object type class
1583  function isUserRegistered($a_user_id = 0)
1584  {
1585  return false;
1586  }
1587 
1589  {
1590  return $this->register;
1591  }
1592 
1593 
1594  function getXMLZip()
1595  {
1596  return false;
1597  }
1598  function getHTMLDirectory()
1599  {
1600  return false;
1601  }
1602 
1606  static function _getObjectsByType($a_obj_type = "", $a_owner = "")
1607  {
1608  global $ilDB;
1609 
1610  $order = " ORDER BY title";
1611 
1612  // where clause
1613  if ($a_obj_type)
1614  {
1615  $where_clause = "WHERE type = ".
1616  $ilDB->quote($a_obj_type, "text");
1617 
1618  if ($a_owner != "")
1619  {
1620  $where_clause.= " AND owner = ".$ilDB->quote($a_owner, "integer");
1621  }
1622  }
1623 
1624  $q = "SELECT * FROM object_data ".$where_clause.$order;
1625  $r = $ilDB->query($q);
1626 
1627  $arr = array();
1628  if ($ilDB->numRows($r) > 0)
1629  {
1630  while ($row = $ilDB->fetchAssoc($r))
1631  {
1632  $row["desc"] = $row["description"];
1633  $arr[$row["obj_id"]] = $row;
1634  }
1635  }
1636 
1637  return $arr;
1638  }
1639 
1655  public static function _prepareCloneSelection($a_ref_ids,$new_type,$show_path = true)
1656  {
1657  global $ilDB,$lng,$objDefinition;
1658 
1659  $query = "SELECT obj_data.title obj_title,path_data.title path_title,child FROM tree ".
1660  "JOIN object_reference obj_ref ON child = obj_ref.ref_id ".
1661  "JOIN object_data obj_data ON obj_ref.obj_id = obj_data.obj_id ".
1662  "JOIN object_reference path_ref ON parent = path_ref.ref_id ".
1663  "JOIN object_data path_data ON path_ref.obj_id = path_data.obj_id ".
1664  "WHERE ".$ilDB->in("child", $a_ref_ids, false, "integer")." ".
1665  "ORDER BY obj_data.title ";
1666  $res = $ilDB->query($query);
1667 
1668  if (!$objDefinition->isPlugin($new_type))
1669  {
1670  $options[0] = $lng->txt('obj_'.$new_type.'_select');
1671  }
1672  else
1673  {
1674  include_once("./Services/Component/classes/class.ilPlugin.php");
1675  $options[0] = ilObjectPlugin::lookupTxtById($new_type, "obj_".$new_type."_select");
1676  }
1677 
1678  while($row = $ilDB->fetchObject($res))
1679  {
1680  if(strlen($title = $row->obj_title) > 40)
1681  {
1682  $title = substr($title,0,40).'...';
1683  }
1684 
1685  if($show_path)
1686  {
1687  if(strlen($path = $row->path_title) > 40)
1688  {
1689  $path = substr($path,0,40).'...';
1690  }
1691 
1692  $title .= ' ('.$lng->txt('path').': '.$path.')';
1693  }
1694 
1695  $options[$row->child] = $title;
1696  }
1697  return $options ? $options : array();
1698  }
1699 
1709  public function cloneObject($a_target_id,$a_copy_id = 0, $a_omit_tree = false)
1710  {
1711  global $objDefinition,$ilUser,$rbacadmin, $ilDB;
1712 
1713  $location = $objDefinition->getLocation($this->getType());
1714  $class_name = ('ilObj'.$objDefinition->getClassName($this->getType()));
1715 
1716  include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
1718 
1719  if(!$options->isTreeCopyDisabled() && !$a_omit_tree)
1720  {
1721  $title = $this->appendCopyInfo($a_target_id,$a_copy_id);
1722  }
1723  else
1724  {
1725  $title = $this->getTitle();
1726  }
1727 
1728  // create instance
1729  include_once($location."/class.".$class_name.".php");
1730  $new_obj = new $class_name(0, false);
1731  $new_obj->setOwner($ilUser->getId());
1732  $new_obj->setTitle($title);
1733  $new_obj->setDescription($this->getLongDescription());
1734  $new_obj->setType($this->getType());
1735  // Choose upload mode to avoid creation of additional settings, db entries ...
1736  $new_obj->create(true);
1737 
1738  if(!$options->isTreeCopyDisabled() && !$a_omit_tree)
1739  {
1740  ilLoggerFactory::getLogger('obj')->debug('Tree copy is enabled');
1741  $new_obj->createReference();
1742  $new_obj->putInTree($a_target_id);
1743  $new_obj->setPermissions($a_target_id);
1744 
1745  // when copying from personal workspace we have no current ref id
1746  if($this->getRefId())
1747  {
1748  // copy local roles
1749  $rbacadmin->copyLocalRoles($this->getRefId(),$new_obj->getRefId());
1750  }
1751  }
1752  else
1753  {
1754  ilLoggerFactory::getLogger('obj')->debug('Tree copy is disabled');
1755  }
1756 
1757  include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1758  ilAdvancedMDValues::_cloneValues($this->getId(),$new_obj->getId());
1759 
1760  // BEGIN WebDAV: Clone WebDAV properties
1761  $query = "INSERT INTO dav_property (obj_id,node_id,ns,name,value) ".
1762  "SELECT ".$ilDB->quote($new_obj->getId(),'integer').",node_id,ns,name,value ".
1763  "FROM dav_property ".
1764  "WHERE obj_id = ".$ilDB->quote($this->getId(),'integer');
1765  $res = $ilDB->manipulate($query);
1766  // END WebDAV: Clone WebDAV properties
1767 
1768  return $new_obj;
1769  }
1770 
1778  public function appendCopyInfo($a_target_id,$a_copy_id)
1779  {
1780  global $tree;
1781 
1782  include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
1783  $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
1784  if(!$cp_options->isRootNode($this->getRefId()))
1785  {
1786  return $this->getTitle();
1787  }
1788  $nodes = $tree->getChilds($a_target_id);
1789 
1790  $title_unique = false;
1791  require_once 'Modules/File/classes/class.ilObjFileAccess.php';
1792  $numberOfCopy = 1;
1793  $handleExtension = ($this->getType() == "file"); // #14883
1794  $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), $numberOfCopy, $handleExtension);
1795  while(!$title_unique)
1796  {
1797  $found = 0;
1798  foreach($nodes as $node)
1799  {
1800  if(($title == $node['title']) and ($this->getType() == $node['type']))
1801  {
1802  $found++;
1803  }
1804  }
1805  if($found > 0)
1806  {
1807  $title = ilObjFileAccess::_appendNumberOfCopyToFilename($this->getTitle(), ++$numberOfCopy, $handleExtension);
1808  }
1809  else
1810  {
1811  break;
1812  }
1813  }
1814  return $title;
1815  }
1816 
1829  public function cloneDependencies($a_target_id,$a_copy_id)
1830  {
1831  include_once './Services/AccessControl/classes/class.ilConditionHandler.php' ;
1832  ilConditionHandler::cloneDependencies($this->getRefId(),$a_target_id,$a_copy_id);
1833 
1834  include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
1836  if($tpl_id)
1837  {
1838  include_once './Services/Object/classes/class.ilObjectFactory.php';
1839  $factory = new ilObjectFactory();
1840  $obj = $factory->getInstanceByRefId($a_target_id, FALSE);
1841  if($obj instanceof ilObject)
1842  {
1843  $obj->applyDidacticTemplate($tpl_id);
1844  }
1845  }
1846  return true;
1847  }
1848 
1856  public function cloneMetaData($target_obj)
1857  {
1858  include_once "./Services/MetaData/classes/class.ilMD.php";
1859  $md = new ilMD($this->getId(),0,$this->getType());
1860  $md->cloneMD($target_obj->getId(),0,$target_obj->getType());
1861  return true;
1862  }
1863 
1872  public static function _getIcon($a_obj_id = "", $a_size = "big", $a_type = "",
1873  $a_offline = false)
1874  {
1875  global $ilSetting, $objDefinition;
1876 
1877  if ($a_obj_id == "" && $a_type == "")
1878  {
1879  return "";
1880  }
1881 
1882  if ($a_type == "")
1883  {
1884  $a_type = ilObject::_lookupType($a_obj_id);
1885  }
1886 
1887  if ($a_size == "")
1888  {
1889  $a_size = "big";
1890  }
1891 
1892  if ($ilSetting->get("custom_icons") &&
1893  in_array($a_type, array("cat","grp","crs", "root", "fold", "prg")))
1894  {
1895  require_once("./Services/Container/classes/class.ilContainer.php");
1896  if (ilContainer::_lookupContainerSetting($a_obj_id, "icon_custom"))
1897  {
1898  $cont_dir = ilContainer::_getContainerDirectory($a_obj_id);
1899 
1900  $file_name = $cont_dir."/icon_custom.svg";
1901  if (is_file($file_name))
1902  {
1903  return $file_name;
1904  }
1905  }
1906  }
1907 
1908  if (!$a_offline)
1909  {
1910  if ($objDefinition->isPluginTypeName($a_type))
1911  {
1912  if ($objDefinition->getClassName($a_type) != "")
1913  {
1914  $class_name = "il".$objDefinition->getClassName($a_type).'Plugin';
1915  $location = $objDefinition->getLocation($a_type);
1916  if (is_file($location."/class.".$class_name.".php"))
1917  {
1918  include_once($location."/class.".$class_name.".php");
1919  return call_user_func(array($class_name, "_getIcon"), $a_type, $a_size, $a_obj_id);
1920  }
1921  }
1922  return ilUtil::getImagePath("icon_cmps.svg");
1923  }
1924 
1925  return ilUtil::getImagePath("icon_".$a_type.".svg");
1926  }
1927  else
1928  {
1929  return "./images/icon_".$a_type.".svg";
1930  }
1931  }
1932 
1939  static function collectDeletionDependencies(&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth = 0)
1940  {
1941  global $objDefinition, $tree;
1942 
1943  if ($a_depth == 0)
1944  {
1945  $deps["dep"] = array();
1946  }
1947 
1948  $deps["del_ids"][$a_obj_id] = $a_obj_id;
1949 
1950  if (!$objDefinition->isPluginTypeName($a_type))
1951  {
1952  $class_name = "ilObj".$objDefinition->getClassName($a_type);
1953  $location = $objDefinition->getLocation($a_type);
1954  include_once($location."/class.".$class_name.".php");
1955  $odeps = call_user_func(array($class_name, "getDeletionDependencies"), $a_obj_id);
1956  if (is_array($odeps))
1957  {
1958  foreach ($odeps as $id => $message)
1959  {
1960  $deps["dep"][$id][$a_obj_id][] = $message;
1961  }
1962  }
1963 
1964  // get deletion dependency of childs
1965  foreach ($tree->getChilds($a_ref_id) as $c)
1966  {
1967  ilObject::collectDeletionDependencies($deps, $c["child"], $c["obj_id"], $c["type"], $a_depth + 1);
1968  }
1969  }
1970 
1971  // delete all dependencies to objects that will be deleted, too
1972  if ($a_depth == 0)
1973  {
1974  foreach ($deps["del_ids"] as $obj_id)
1975  {
1976  unset($deps["dep"][$obj_id]);
1977  }
1978  $deps = $deps["dep"];
1979  }
1980  }
1981 
1986  static function getDeletionDependencies($a_obj_id)
1987  {
1988  return false;
1989  }
1990 
1997  static function getLongDescriptions(array $a_obj_ids)
1998  {
1999  global $ilDB;
2000 
2001  $res = $ilDB->query("SELECT * FROM object_description".
2002  " WHERE ".$ilDB->in("obj_id", $a_obj_ids, "", "integer"));
2003  $all = array();
2004  while($row = $ilDB->fetchAssoc($res))
2005  {
2006  $all[$row["obj_id"]] = $row["description"];
2007  }
2008  return $all;
2009  }
2010 
2017  static function getAllOwnedRepositoryObjects($a_user_id)
2018  {
2019  global $ilDB, $objDefinition;
2020 
2021  $all = array();
2022 
2023  // restrict to repository
2024  $types = array_keys($objDefinition->getSubObjectsRecursively("root"));
2025 
2026  $sql = "SELECT od.obj_id,od.type,od.title FROM object_data od".
2027  " JOIN object_reference oref ON(oref.obj_id = od.obj_id)".
2028  " JOIN tree ON (tree.child = oref.ref_id)";
2029 
2030  if($a_user_id)
2031  {
2032  $sql .= " WHERE od.owner = ".$ilDB->quote($a_user_id, "integer");
2033  }
2034  else
2035  {
2036  $sql .= " LEFT JOIN usr_data ud ON (ud.usr_id = od.owner)".
2037  " WHERE (od.owner < ".$ilDB->quote(1, "integer").
2038  " OR od.owner IS NULL OR ud.login IS NULL)".
2039  " AND od.owner <> ".$ilDB->quote(-1, "integer");
2040  }
2041 
2042  $sql .= " AND ".$ilDB->in("od.type", $types, "", "text").
2043  " AND tree.tree > ".$ilDB->quote(0, "integer"); // #12485
2044 
2045  $res = $ilDB->query($sql);
2046  while($row = $ilDB->fetchAssoc($res))
2047  {
2048  $all[$row["type"]][$row["obj_id"]] = $row["title"];
2049  }
2050 
2051  return $all;
2052  }
2053 
2060  static function fixMissingTitles($a_type, array &$a_obj_title_map)
2061  {
2062  global $ilDB;
2063 
2064  if(!in_array($a_type, array("catr", "crsr", "sess", "grpr")))
2065  {
2066  return;
2067  }
2068 
2069  // any missing titles?
2070  $missing_obj_ids = array();
2071  foreach($a_obj_title_map as $obj_id => $title)
2072  {
2073  if(!trim($title))
2074  {
2075  $missing_obj_ids[] = $obj_id;
2076  }
2077  }
2078 
2079  if(!sizeof($missing_obj_ids))
2080  {
2081  return;
2082  }
2083 
2084  switch($a_type)
2085  {
2086  case "grpr":
2087  case "catr":
2088  case "crsr":
2089  $set = $ilDB->query("SELECT oref.obj_id, od.type, od.title FROM object_data od".
2090  " JOIN container_reference oref ON (od.obj_id = oref.target_obj_id)".
2091  " AND ".$ilDB->in("oref.obj_id", $missing_obj_ids, "", "integer"));
2092  while($row = $ilDB->fetchAssoc($set))
2093  {
2094  $a_obj_title_map[$row["obj_id"]] = $row["title"];
2095  }
2096  break;
2097 
2098  case "sess":
2099  include_once "Modules/Session/classes/class.ilObjSession.php";
2100  foreach($missing_obj_ids as $obj_id)
2101  {
2102  $sess = new ilObjSession($obj_id, false);
2103  $a_obj_title_map[$obj_id] = $sess->getFirstAppointment()->appointmentToString();
2104  }
2105  break;
2106  }
2107  }
2108 
2115  static function _lookupCreationDate($a_id)
2116  {
2117  global $ilDB;
2118 
2119  $set = $ilDB->query("SELECT create_date FROM object_data ".
2120  " WHERE obj_id = ".$ilDB->quote($a_id, "integer"));
2121  $rec = $ilDB->fetchAssoc($set);
2122  return $rec["create_date"];
2123  }
2124 
2132  public static function hasAutoRating($a_type, $a_ref_id)
2133  {
2134  global $tree;
2135 
2136  if(!$a_ref_id ||
2137  !in_array($a_type, array("file", "lm", "wiki")))
2138  {
2139  return false;
2140  }
2141 
2142  // find parent container
2143  $parent_ref_id = $tree->checkForParentType($a_ref_id, "grp");
2144  if(!$parent_ref_id)
2145  {
2146  $parent_ref_id = $tree->checkForParentType($a_ref_id, "crs");
2147  }
2148  if($parent_ref_id)
2149  {
2150  include_once './Services/Object/classes/class.ilObjectServiceSettingsGUI.php';
2151 
2152  // get auto rate setting
2153  $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
2155  $parent_obj_id,
2157  false
2158  );
2159  }
2160  return false;
2161  }
2162 
2172  function getPossibleSubObjects($a_filter = true) {
2173  return $this->objDefinition->getSubObjects($this->type, $a_filter);
2174  }
2175 } // END class.ilObject
2176 ?>
static lookupTemplateId($a_ref_id)
Lookup template id ilDB $ilDB.
static setDeletedDates($a_ref_ids)
Set deleted date type $ilDB.
static getDeletionDependencies($a_obj_id)
Get deletion dependencies.
static _getIcon($a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
static _resetDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
static _lookupDeletedDate($a_ref_id)
only called in ilObjectGUI::insertSavedNodes
$path
Definition: aliased.php:25
static removeItemFromDesktops($a_id)
removes object from all user&#39;s desktops public
static _getContainerDirectory($a_id)
Get the container directory.
Class ilObjectFactory.
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
const IL_CAL_DATETIME
static lookupTxtById($plugin_id, $lang_var)
__construct($a_id=0, $a_reference=true)
Constructor public.
static _prepareCloneSelection($a_ref_ids, $new_type, $show_path=true)
Prepare copy wizard object selection.
$result
cloneObject($a_target_id, $a_copy_id=0, $a_omit_tree=false)
Clone object permissions, put in tree ...
static getLongDescriptions(array $a_obj_ids)
Get long description data.
cloneDependencies($a_target_id, $a_copy_id)
Clone object dependencies.
static _appendNumberOfCopyToFilename($a_file_name, $nth_copy=null, $a_handle_extension=false)
Appends the text " - Copy" to a filename in the language of the current user.
static getAllOwnedRepositoryObjects($a_user_id)
Get all ids of objects user owns.
const TITLE_LENGTH
max length of object title
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
static deleteByRefId($a_ref_id)
Delete by ref_id ilDB $ilDB.
read()
read object data from db into object
$location
Definition: buildRTE.php:44
updateMetaData()
update meta data entry
Class ilObject Basic functions for all objects.
withReferences()
determines wehter objects are referenced or not (got ref ids or not)
const DESC_LENGTH
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
setId($a_id)
set object id public
createMetaData()
create meta data entry
static _isInTrash($a_ref_id)
checks wether object is in trash
static shortenText($a_str, $a_len, $a_dots=false, $a_next_blank=false, $a_keep_extension=false)
shorten a string to given length.
static _writeTitle($a_obj_id, $a_title)
write title to db (static)
getDiskUsage()
Gets the disk usage of the object in bytes.
static _lookupTitle($a_id)
lookup object title
static _getObjectsByType($a_obj_type="", $a_owner="")
Get objects by type.
getPossibleSubObjects($a_filter=true)
get all possible subobjects of this type the object can decide which types of subobjects are possible...
getCreateDate()
get create date public
getOwner()
get object owner
static _deleteByObjId($a_obj_id)
Delete by obj_id.
static _setDeletedDate($a_ref_id)
only called in ilTree::saveSubTree
static _getAllReferences($a_id)
get all reference ids of object
static _deleteByObjId($a_obj_id)
Delete by objekt id.
setTitle($a_title)
set object title
static _lookupLastUpdate($a_id, $a_as_string=false)
lookup last update
static collectDeletionDependencies(&$deps, $a_ref_id, $a_obj_id, $a_type, $a_depth=0)
Collect deletion dependencies.
static _lookupObjectId($a_ref_id)
lookup object id
const DEBUG
static hasAutoRating($a_type, $a_ref_id)
Check if auto rating is active for parent group/course.
$a_type
Definition: workflow.php:93
createReference()
creates reference for object
static assignTemplate($a_ref_id, $a_obj_id, $a_tpl_id)
Assign template to object ilDB $ilDB.
applyDidacticTemplate($a_tpl_id)
Apply template.
$r
Definition: example_031.php:79
static _getInstance($a_copy_id)
Get instance of copy wizard options.
create()
create
setOwner($a_owner)
set object owner
if(!is_array($argv)) $options
getId()
get object id public
static _cloneValues($a_source_id, $a_target_id, $a_sub_type=null, $a_source_sub_id=null, $a_target_sub_id=null)
Clone Advanced Meta Data.
isUserRegistered($a_user_id=0)
static _lookupCreationDate($a_id)
Lookup creation date.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static _lookupDescription($a_id)
lookup object description
static _lookupObjId($a_id)
static add(ilObject $a_object)
setRefId($a_id)
set reference id public
static formatDate(ilDateTime $date)
Format a date public.
getTitle()
get object title public
static _deleteSettingsOfBlock($a_block_id, $a_block_type)
Delete block settings of block.
updateOwner()
update owner of object in db
getDescription()
get object description
getImportId()
get import id
Date and time handling
$ilUser
Definition: imgupload.php:18
redirection script todo: (a better solution should control the processing via a xml file) ...
cloneMetaData($target_obj)
Copy meta data.
static _lookupOwner($a_id)
lookup object owner
initDefaultRoles()
init default roles settings Purpose of this function is to create a local role folder and local roles...
static _lookupImportId($a_obj_id)
putInTree($a_parent_ref)
maybe this method should be in tree object!?
getType()
get object type public
appendCopyInfo($a_target_id, $a_copy_id)
Prepend Copy info if object with same name exists in that container.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
static deleteAllEntries($a_ref_id)
Delete all db entries for ref id.
setImportId($a_import_id)
set import id
static _lookupContainerSetting($a_id, $a_keyword, $a_default_value=NULL)
Lookup a container setting.
Handles conditions for accesses to different ILIAS objects.
static _writeDescription($a_obj_id, $a_desc)
write description to db (static)
static delete($a_ref_id)
static _getLastUpdateOfObjects($a_objs)
Get last update for a set of media objects.
static fixMissingTitles($a_type, array &$a_obj_title_map)
Try to fix missing object titles.
global $ilSetting
Definition: privfeed.php:17
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
global $ilBench
Definition: ilias.php:18
global $ilDB
getLongDescription()
get object long description (stored in object_description)
getRefId()
get reference id public
static _getIdsForTitle($title, $type='', $partialmatch=false)
countReferences()
count references of object
deleteMetaData()
delete meta data entry
static deleteByObjId($a_obj_id)
Delete by obj id ilDB $ilDB.
setDescription($a_desc)
set object description
static getLogger($a_component_id)
Get component logger.
static cloneDependencies($a_src_ref_id, $a_target_ref_id, $a_copy_id)
update()
update object in db
getLastUpdateDate()
get last update date public
static _deleteByObjId($a_obj_id)
getUntranslatedTitle()
get untranslated object title public
setType($a_type)
set object type public
static _lookupOwnerName($a_owner_id)
lookup owner name for owner id
setPermissions($a_parent_ref)
set permissions of object
static _getObjectsDataForType($a_type, $a_omit_trash=false)
get all objects of a certain type
setParentRolePermissions($a_parent_ref)
Initialize the permissions of parent roles (local roles of categories, global roles...) This method is overwritten in e.g courses, groups for building permission intersections with non_member templates.
static _lookupObjIdByImportId($a_import_id)
getPresentationTitle()
get presentation title Normally same as title Overwritten for sessions
static getActionsByTemplateId($a_tpl_id)
Get actions of one template.
static _getIdForImportId($a_import_id)
get current object id for import id (static)
MDUpdateListener($a_element)
Meta data update listener.
setRegisterMode($a_bool)