00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00035 class ilObject
00036 {
00042 var $ilias;
00043
00049 var $lng;
00050
00056 var $id;
00057 var $ref_id;
00058 var $type;
00059 var $title;
00060 var $desc;
00061 var $long_desc;
00062 var $owner;
00063 var $create_date;
00064 var $last_update;
00065 var $import_id;
00066 var $register = false;
00067
00073 var $referenced;
00074
00080 var $objectList;
00081
00086 var $max_title;
00087
00092 var $max_desc;
00093
00098 var $add_dots;
00099
00103 var $obj_data_record;
00104
00111 function ilObject($a_id = 0, $a_reference = true)
00112 {
00113 global $ilias, $lng, $ilBench;
00114
00115 $ilBench->start("Core", "ilObject_Constructor");
00116
00117 if (DEBUG)
00118 {
00119 echo "<br/><font color=\"red\">type(".$this->type.") id(".$a_id.") referenced(".$a_reference.")</font>";
00120 }
00121
00122 $this->ilias =& $ilias;
00123 $this->lng =& $lng;
00124
00125 $this->max_title = MAXLENGTH_OBJ_TITLE;
00126 $this->max_desc = MAXLENGTH_OBJ_DESC;
00127 $this->add_dots = true;
00128
00129 $this->referenced = $a_reference;
00130 $this->call_by_reference = $a_reference;
00131
00132 if ($a_id == 0)
00133 {
00134 $this->referenced = false;
00135 }
00136
00137 if ($this->referenced)
00138 {
00139 $this->ref_id = $a_id;
00140 }
00141 else
00142 {
00143 $this->id = $a_id;
00144 }
00145
00146 if ($a_id != 0)
00147 {
00148 $this->read();
00149 }
00150
00151 $ilBench->stop("Core", "ilObject_Constructor");
00152 }
00153
00157 function withReferences()
00158 {
00159
00160 return ($this->call_by_reference) ? true : $this->referenced;
00161 }
00162
00163
00169 function read($a_force_db = false)
00170 {
00171 global $objDefinition, $ilBench;
00172
00173 $ilBench->start("Core", "ilObject_read");
00174
00175 if (isset($this->obj_data_record) && !$a_force_db)
00176 {
00177 $obj = $this->obj_data_record;
00178 }
00179 else if ($this->referenced)
00180 {
00181
00182 if (!isset($this->ref_id))
00183 {
00184 $message = "ilObject::read(): No ref_id given! (".$this->type.")";
00185 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00186 }
00187
00188
00189 $ilBench->start("Core", "ilObject_read_readData");
00190
00191
00192
00193
00194 $q = "SELECT * FROM object_data, object_reference WHERE object_data.obj_id=object_reference.obj_id ".
00195 "AND object_reference.ref_id='".$this->ref_id."'";
00196 $object_set = $this->ilias->db->query($q);
00197 $ilBench->stop("Core", "ilObject_read_readData");
00198
00199
00200 if ($object_set->numRows() == 0)
00201 {
00202 $message = "ilObject::read(): Object with ref_id ".$this->ref_id." not found! (".$this->type.")";
00203 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00204 }
00205
00206 $obj = $object_set->fetchRow(DB_FETCHMODE_ASSOC);
00207 }
00208 else
00209 {
00210
00211 if (!isset($this->id))
00212 {
00213 $message = "ilObject::read(): No obj_id given! (".$this->type.")";
00214 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00215 }
00216
00217
00218 $q = "SELECT * FROM object_data ".
00219 "WHERE obj_id = '".$this->id."'";
00220 $object_set = $this->ilias->db->query($q);
00221
00222
00223 if ($object_set->numRows() == 0)
00224 {
00225 $message = "ilObject::read(): Object with obj_id: ".$this->id." (".$this->type.") not found!";
00226 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00227 }
00228
00229 $obj = $object_set->fetchRow(DB_FETCHMODE_ASSOC);
00230 }
00231
00232 $this->id = $obj["obj_id"];
00233 $this->type = $obj["type"];
00234 $this->title = $obj["title"];
00235 $this->desc = $obj["description"];
00236 $this->owner = $obj["owner"];
00237 $this->create_date = $obj["create_date"];
00238 $this->last_update = $obj["last_update"];
00239 $this->import_id = $obj["import_id"];
00240
00241 if($objDefinition->isRBACObject($this->getType()))
00242 {
00243
00244 $query = "SELECT * FROM object_description WHERE obj_id = '".$this->id."'";
00245 $res = $this->ilias->db->query($query);
00246 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00247 {
00248 $this->setDescription($row->description);
00249 }
00250 }
00251
00252
00253 $ilBench->start("Core", "ilObject_Constructor_getTranslation");
00254 $translation_type = $objDefinition->getTranslationType($this->type);
00255
00256 if ($translation_type == "sys")
00257 {
00258 $this->title = $this->lng->txt("obj_".$this->type);
00259 $this->desc = $this->lng->txt("obj_".$this->type."_desc");
00260 }
00261 elseif ($translation_type == "db")
00262 {
00263 $q = "SELECT title,description FROM object_translation ".
00264 "WHERE obj_id = ".$this->id." ".
00265 "AND lang_code = '".$this->ilias->account->getCurrentLanguage()."' ".
00266 "AND NOT lang_default = 1";
00267 $r = $this->ilias->db->query($q);
00268 $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
00269
00270 if ($row)
00271 {
00272 $this->title = $row->title;
00273 $this->setDescription($row->description);
00274 #$this->desc = $row->description;
00275 }
00276 }
00277
00278 $ilBench->stop("Core", "ilObject_Constructor_getTranslation");
00279
00280 $ilBench->stop("Core", "ilObject_read");
00281 }
00282
00288 function getId()
00289 {
00290 return $this->id;
00291 }
00292
00298 function setId($a_id)
00299 {
00300 $this->id = $a_id;
00301 }
00302
00308 function setRefId($a_id)
00309 {
00310 $this->ref_id = $a_id;
00311 $this->referenced = true;
00312 }
00313
00319 function getRefId()
00320 {
00321 return $this->ref_id;
00322 }
00323
00329 function getType()
00330 {
00331 return $this->type;
00332 }
00333
00339 function setType($a_type)
00340 {
00341 $this->type = $a_type;
00342 }
00343
00349 function getTitle()
00350 {
00351 return $this->title;
00352 }
00353
00360 function setTitle($a_title)
00361 {
00362 if ($a_title == "")
00363 {
00364 $a_title = "NO TITLE";
00365 }
00366
00367 $this->title = ilUtil::shortenText($a_title, $this->max_title, $this->add_dots);
00368 }
00369
00376 function getDescription()
00377 {
00378 return $this->desc;
00379 }
00380
00387 function setDescription($a_desc)
00388 {
00389
00390 $this->desc = ilUtil::shortenText($a_desc, $this->max_desc, $this->add_dots);
00391
00392 $this->long_desc = $a_desc;
00393
00394 return true;
00395 }
00396
00403 function getLongDescription()
00404 {
00405 return strlen($this->long_desc) ? $this->long_desc : $this->desc;
00406 }
00407
00414 function getImportId()
00415 {
00416 return $this->import_id;
00417 }
00418
00425 function setImportId($a_import_id)
00426 {
00427 $this->import_id = $a_import_id;
00428 }
00429
00430 function _lookupObjIdByImportId($a_import_id)
00431 {
00432 global $ilDB;
00433
00434 $query = "SELECT * FROM object_data ".
00435 "WHERE import_id = '".$a_import_id."' ".
00436 "ORDER BY create_date DESC";
00437 $res = $ilDB->query($query);
00438 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00439 {
00440 return $row->obj_id;
00441 }
00442 return 0;
00443 }
00444
00451 function getOwner()
00452 {
00453 return $this->owner;
00454 }
00455
00456
00457
00458
00459
00460
00461
00462 function getOwnerName()
00463 {
00464 return ilObject::_lookupOwnerName($this->getOwner());
00465 }
00466
00470 function _lookupOwnerName($a_owner_id)
00471 {
00472 global $lng;
00473
00474 if ($a_owner_id != -1)
00475 {
00476 if (ilObject::_exists($a_owner_id))
00477 {
00478 $owner = new ilObjUser($a_owner_id);
00479 }
00480 }
00481
00482 if (is_object($owner))
00483 {
00484 $own_name = $owner->getFullname();
00485 }
00486 else
00487 {
00488 $own_name = $lng->txt("unknown");
00489 }
00490
00491 return $own_name;
00492 }
00493
00500 function setOwner($a_owner)
00501 {
00502 $this->owner = $a_owner;
00503 }
00504
00505
00506
00512 function getCreateDate()
00513 {
00514 return $this->create_date;
00515 }
00516
00522 function getLastUpdateDate()
00523 {
00524 return $this->last_update;
00525 }
00526
00535 function setObjDataRecord($a_record)
00536 {
00537 $this->obj_data_record = $a_record;
00538 }
00539
00548 function create()
00549 {
00550 global $ilDB, $log,$ilUser,$objDefinition;
00551
00552 if (!isset($this->type))
00553 {
00554 $message = get_class($this)."::create(): No object type given!";
00555 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00556 }
00557
00558
00559 $log->write("ilObject::create(), start");
00560
00561 $this->title = ilUtil::shortenText($this->getTitle(), $this->max_title, $this->add_dots);
00562 $this->desc = ilUtil::shortenText($this->getDescription(), $this->max_desc, $this->add_dots);
00563
00564 $q = "INSERT INTO object_data ".
00565 "(type,title,description,owner,create_date,last_update,import_id) ".
00566 "VALUES ".
00567 "('".$this->type."',".$ilDB->quote($this->getTitle()).",'".ilUtil::prepareDBString($this->getDescription())."',".
00568 "'".$ilUser->getId()."',now(),now(),'".
00569 $this->getImportId()."')";
00570
00571 $ilDB->query($q);
00572
00573 $this->id = $ilDB->getLastInsertId();
00574
00575
00576
00577
00578 if($objDefinition->isRBACObject($this->getType()))
00579 {
00580 $query = "INSERT INTO object_description SET ".
00581 "obj_id = '".$this->id."', ".
00582 "description = '".ilUtil::prepareDBString($this->getLongDescription())."'";
00583
00584 $ilDB->query($query);
00585 }
00586
00587
00588
00589
00590
00591 $q = "SELECT last_update, create_date FROM object_data".
00592 " WHERE obj_id = '".$this->id."'";
00593 $obj_set = $this->ilias->db->query($q);
00594 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00595 $this->last_update = $obj_rec["last_update"];
00596 $this->create_date = $obj_rec["create_date"];
00597
00598
00599 $this->setOwner($ilUser->getId());
00600
00601
00602 $log->write("ilObject::create(), finished, obj_id: ".$this->id.", type: ".
00603 $this->type.", title: ".$this->getTitle());
00604
00605 return $this->id;
00606 }
00607
00614 function update()
00615 {
00616 global $objDefinition;
00617
00618 $q = "UPDATE object_data ".
00619 "SET ".
00620 "title = '".ilUtil::prepareDBString($this->getTitle())."',".
00621 "description = '".ilUtil::prepareDBString($this->getDescription())."', ".
00622 "import_id = '".$this->getImportId()."', ".
00623 "last_update = now() ".
00624 "WHERE obj_id = '".$this->getId()."'";
00625 $this->ilias->db->query($q);
00626
00627
00628
00629
00630 $q = "SELECT last_update FROM object_data".
00631 " WHERE obj_id = '".$this->getId()."'";
00632 $obj_set = $this->ilias->db->query($q);
00633 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00634 $this->last_update = $obj_rec["last_update"];
00635
00636 if($objDefinition->isRBACObject($this->getType()))
00637 {
00638
00639 $res = $this->ilias->db->query("SELECT * FROM object_description WHERE obj_id = '".$this->getId()."'");
00640 if($res->numRows())
00641 {
00642 $query = "UPDATE object_description SET description = '".
00643 ilUtil::prepareDBString($this->getLongDescription())."' ".
00644 "WHERE obj_id = '".$this->getId()."'";
00645 }
00646 else
00647 {
00648 $query = "INSERT INTO object_description SET obj_id = '".$this->getId()."', ".
00649 "description = '".ilUtil::prepareDBString($this->getLongDescription())."'";
00650 }
00651 $this->ilias->db->query($query);
00652 }
00653
00654 return true;
00655 }
00656
00668 function MDUpdateListener($a_element)
00669 {
00670 include_once 'Services/MetaData/classes/class.ilMD.php';
00671
00672 switch($a_element)
00673 {
00674 case 'General':
00675
00676
00677 $md = new ilMD($this->getId(),0, $this->getType());
00678 if(!is_object($md_gen = $md->getGeneral()))
00679 {
00680 return false;
00681 }
00682
00683 ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
00684 $this->setTitle($md_gen->getTitle());
00685
00686 foreach($md_gen->getDescriptionIds() as $id)
00687 {
00688 $md_des = $md_gen->getDescription($id);
00689 ilObject::_writeDescription($this->getId(),$md_des->getDescription());
00690 $this->setDescription($md_des->getDescription());
00691 break;
00692 }
00693
00694 break;
00695
00696 default:
00697 }
00698 return true;
00699 }
00700
00704 function createMetaData()
00705 {
00706 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
00707
00708 global $ilUser;
00709
00710 $md_creator = new ilMDCreator($this->getId(),0,$this->getType());
00711 $md_creator->setTitle($this->getTitle());
00712 $md_creator->setTitleLanguage($ilUser->getPref('language'));
00713 $md_creator->setDescription($this->getLongDescription());
00714 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
00715 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
00716 $md_creator->setLanguage($ilUser->getPref('language'));
00717 $md_creator->create();
00718
00719 return true;
00720 }
00721
00725 function updateMetaData()
00726 {
00727 include_once("Services/MetaData/classes/class.ilMD.php");
00728 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
00729 include_once("Services/MetaData/classes/class.ilMDDescription.php");
00730
00731 $md =& new ilMD($this->getId(), 0, $this->getType());
00732 $md_gen =& $md->getGeneral();
00733 $md_gen->setTitle($this->getTitle());
00734
00735
00736 $md_des_ids =& $md_gen->getDescriptionIds();
00737 if (count($md_des_ids) > 0)
00738 {
00739 $md_des =& $md_gen->getDescription($md_des_ids[0]);
00740 $md_des->setDescription($this->getLongDescription());
00741 $md_des->update();
00742 }
00743 $md_gen->update();
00744
00745 }
00746
00750 function deleteMetaData()
00751 {
00752
00753 include_once('Services/MetaData/classes/class.ilMD.php');
00754 $md = new ilMD($this->getId(), 0, $this->getType());
00755 $md->deleteAll();
00756 }
00757
00764 function updateOwner()
00765 {
00766 $q = "UPDATE object_data ".
00767 "SET ".
00768 "owner = '".$this->getOwner()."', ".
00769 "last_update = now() ".
00770 "WHERE obj_id = '".$this->getId()."'";
00771 $this->ilias->db->query($q);
00772
00773 $q = "SELECT last_update FROM object_data".
00774 " WHERE obj_id = '".$this->getId()."'";
00775 $obj_set = $this->ilias->db->query($q);
00776 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00777 $this->last_update = $obj_rec["last_update"];
00778
00779 return true;
00780 }
00781
00789 function _getIdForImportId($a_import_id)
00790 {
00791 global $ilDB;
00792
00793 $q = "SELECT * FROM object_data WHERE import_id = '".$a_import_id."'".
00794 " ORDER BY create_date DESC LIMIT 1";
00795 $obj_set = $ilDB->query($q);
00796
00797 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00798 {
00799 return $obj_rec["obj_id"];
00800 }
00801 else
00802 {
00803 return 0;
00804 }
00805 }
00806
00812 function _getAllReferences($a_id)
00813 {
00814 global $ilDB;
00815
00816 $q = "SELECT * FROM object_reference WHERE obj_id = '".$a_id."'";
00817 $obj_set = $ilDB->query($q);
00818 $ref = array();
00819
00820 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00821 {
00822 $ref[$obj_rec["ref_id"]] = $obj_rec["ref_id"];
00823 }
00824
00825 return $ref;
00826 }
00827
00833 function _lookupTitle($a_id)
00834 {
00835 global $ilObjDataCache;
00836
00837 return $ilObjDataCache->lookupTitle($a_id);
00838 }
00839
00845 function _lookupDescription($a_id)
00846 {
00847 global $ilObjDataCache;
00848
00849 return $ilObjDataCache->lookupDescription($a_id);
00850 }
00851
00857 function _lookupLastUpdate($a_id)
00858 {
00859 global $ilObjDataCache;
00860
00861 return $ilObjDataCache->lookupLastUpdate($a_id);
00862 }
00863
00864 function _lookupObjId($a_id)
00865 {
00866 global $ilObjDataCache;
00867
00868 return (int) $ilObjDataCache->lookupObjId($a_id);
00869 }
00870
00874 function _setDeletedDate($a_ref_id)
00875 {
00876 global $ilDB;
00877
00878 $q = "UPDATE object_reference SET deleted=now() ".
00879 "WHERE ref_id = ".$ilDB->quote($a_ref_id);
00880 $ilDB->query($q);
00881 }
00882
00886 function _resetDeletedDate($a_ref_id)
00887 {
00888 global $ilDB;
00889
00890 $q = "UPDATE object_reference SET deleted= ".$ilDB->quote("0000-00-00 00:00:00").
00891 " WHERE ref_id = ".$ilDB->quote($a_ref_id);
00892 $ilDB->query($q);
00893 }
00894
00902 function _writeTitle($a_obj_id, $a_title)
00903 {
00904 global $ilDB;
00905
00906 $q = "UPDATE object_data ".
00907 "SET ".
00908 "title = ".$ilDB->quote($a_title).",".
00909 "last_update = now() ".
00910 "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00911
00912 $ilDB->query($q);
00913 }
00914
00922 function _writeDescription($a_obj_id, $a_desc)
00923 {
00924 global $ilDB,$objDefinition;
00925
00926
00927 $desc = ilUtil::shortenText($a_desc,MAXLENGTH_OBJ_DESC,true);
00928
00929 $q = "UPDATE object_data ".
00930 "SET ".
00931 "description = ".$ilDB->quote($desc).",".
00932 "last_update = now() ".
00933 "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00934
00935 $ilDB->query($q);
00936
00937 if($objDefinition->isRBACObject($this->getType()))
00938 {
00939
00940 $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = '".$a_obj_id."'");
00941 if($res->numRows())
00942 {
00943 $query = "UPDATE object_description SET description = '".
00944 ilUtil::prepareDBString($a_desc)."' ".
00945 "WHERE obj_id = '".$this->getId()."'";
00946 }
00947 else
00948 {
00949 $query = "INSERT INTO object_description SET obj_id = '".$this->getId()."', ".
00950 "description = '".ilUtil::prepareDBString($a_desc)."'";
00951 }
00952 $ilDB->query($query);
00953 }
00954 }
00955
00963 function _writeImportId($a_obj_id, $a_import_id)
00964 {
00965 global $ilDB;
00966
00967 $q = "UPDATE object_data ".
00968 "SET ".
00969 "import_id = ".$ilDB->quote($a_import_id).",".
00970 "last_update = now() ".
00971 "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00972
00973 $ilDB->query($q);
00974 }
00975
00981 function _lookupType($a_id,$a_reference = false)
00982 {
00983 global $ilObjDataCache;
00984
00985 if($a_reference)
00986 {
00987 return $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_id));
00988 }
00989 return $ilObjDataCache->lookupType($a_id);
00990
00991 global $ilDB;
00992
00993 if ($a_reference === true)
00994 {
00995 $q = "SELECT type FROM object_reference as obr, object_data as obd ".
00996 "WHERE obr.ref_id = '".$a_id."' ".
00997 "AND obr.obj_id = obd.obj_id ";
00998
00999 #$q = "SELECT type FROM object_data as obj ".
01000 # "LEFT JOIN object_reference as ref ON ref.obj_id=obj.obj_id ".
01001 # "WHERE ref.ref_id = '".$a_id."'";
01002 }
01003 else
01004 {
01005 $q = "SELECT type FROM object_data WHERE obj_id = '".$a_id."'";
01006 }
01007
01008 $obj_set = $ilDB->query($q);
01009 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
01010
01011 return $obj_rec["type"];
01012 }
01013
01017 function _isInTrash($a_ref_id)
01018 {
01019 global $tree;
01020
01021 return $tree->isSaved($a_ref_id);
01022 }
01023
01027 function _hasUntrashedReference($a_obj_id)
01028 {
01029 $ref_ids = ilObject::_getAllReferences($a_obj_id);
01030 foreach($ref_ids as $ref_id)
01031 {
01032 if(!ilObject::_isInTrash($ref_id))
01033 {
01034 return true;
01035 }
01036 }
01037
01038 return false;
01039 }
01040
01046 function _lookupObjectId($a_ref_id)
01047 {
01048 global $ilObjDataCache;
01049
01050 return (int) $ilObjDataCache->lookupObjId($a_ref_id);
01051 }
01052
01063 function _getObjectsDataForType($a_type, $a_omit_trash = false)
01064 {
01065 global $ilDB;
01066
01067 $q = "SELECT * FROM object_data WHERE type = ".$ilDB->quote($a_type);
01068 $obj_set = $ilDB->query($q);
01069
01070 $objects = array();
01071 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
01072 {
01073 if ((!$a_omit_trash) || ilObject::_hasUntrashedReference($obj_rec["obj_id"]))
01074 {
01075 $objects[$obj_rec["title"].".".$obj_rec["obj_id"]] = array("id" => $obj_rec["obj_id"],
01076 "type" => $obj_rec["type"], "title" => $obj_rec["title"],
01077 "description" => $obj_rec["description"]);
01078 }
01079 }
01080 ksort($objects);
01081 return $objects;
01082 }
01083
01089 function putInTree($a_parent_ref)
01090 {
01091 global $tree, $log;
01092
01093 $tree->insertNode($this->getRefId(), $a_parent_ref);
01094
01095
01096 $log->write("ilObject::putInTree(), parent_ref: $a_parent_ref, ref_id: ".
01097 $this->getRefId().", obj_id: ".$this->getId().", type: ".
01098 $this->getType().", title: ".$this->getTitle());
01099
01100 }
01101
01108 function setPermissions($a_parent_ref)
01109 {
01110 global $rbacadmin, $rbacreview;
01111
01112 $parentRoles = $rbacreview->getParentRoleIds($a_parent_ref);
01113
01114 foreach ($parentRoles as $parRol)
01115 {
01116 $ops = $rbacreview->getOperationsOfRole($parRol["obj_id"], $this->getType(), $parRol["parent"]);
01117 $rbacadmin->grantPermission($parRol["obj_id"], $ops, $this->getRefId());
01118 }
01119 }
01120
01127 function createReference()
01128 {
01129 global $ilDB;
01130
01131 if (!isset($this->id))
01132 {
01133 $message = "ilObject::createNewReference(): No obj_id given!";
01134 $this->raiseError($message,$this->ilias->error_obj->WARNING);
01135 }
01136
01137 $q = "INSERT INTO object_reference ".
01138 "(obj_id) VALUES ('".$this->id."')";
01139 $this->ilias->db->query($q);
01140
01141 $this->ref_id = $ilDB->getLastInsertId();
01142 $this->referenced = true;
01143
01144 return $this->ref_id;
01145 }
01146
01147
01154 function countReferences()
01155 {
01156 if (!isset($this->id))
01157 {
01158 $message = "ilObject::countReferences(): No obj_id given!";
01159 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
01160 }
01161
01162 $q = "SELECT COUNT(ref_id) AS num FROM object_reference ".
01163 "WHERE obj_id = '".$this->id."'";
01164 $row = $this->ilias->db->getRow($q);
01165
01166 return $row->num;
01167 }
01168
01169
01180 function ilClone($a_parent_ref)
01181 {
01182 global $log;
01183
01184 $new_obj = new ilObject();
01185 $new_obj->setTitle($this->getTitle());
01186 $new_obj->setType($this->getType());
01187 $new_obj->setDescription($this->getDescription());
01188 $new_obj->create();
01189 $new_ref_id = $new_obj->createReference();
01190 $new_obj->putInTree($a_parent_ref);
01191 $new_obj->setPermissions($a_parent_ref);
01192
01193 unset($new_obj);
01194
01195
01196 $log->write("ilObject::ilClone(), ref_id: ".$this->getRefId().",obj_id: ".$this->getId().", type: ".
01197 $this->getType().", title: ".$this->getTitle().
01198 ", new ref_id: ".$new_obj->getRefId().", new obj_id:".$new_obj->getId());
01199
01200
01201 return $new_ref_id;
01202 }
01203
01204
01214 function delete()
01215 {
01216 global $rbacadmin, $log;
01217
01218 $remove = false;
01219
01220
01221 if ((!$this->referenced) || ($this->countReferences() == 1))
01222 {
01223
01224 $q = "DELETE FROM object_data ".
01225 "WHERE obj_id = '".$this->getId()."'";
01226 $this->ilias->db->query($q);
01227
01228
01229 $query = "DELETE FROM object_description WHERE obj_id = '".$this->getId()."'";
01230 $this->ilias->db->query($query);
01231
01232
01233 $log->write("ilObject::delete(), deleted object, obj_id: ".$this->getId().", type: ".
01234 $this->getType().", title: ".$this->getTitle());
01235
01236 $remove = true;
01237 }
01238 else
01239 {
01240
01241 $log->write("ilObject::delete(), object not deleted, number of references: ".
01242 $this->countReferences().", obj_id: ".$this->getId().", type: ".
01243 $this->getType().", title: ".$this->getTitle());
01244 }
01245
01246
01247 if ($this->referenced)
01248 {
01249
01250 $q = "DELETE FROM object_reference ".
01251 "WHERE ref_id = '".$this->getRefId()."'";
01252 $this->ilias->db->query($q);
01253
01254
01255 $log->write("ilObject::delete(), reference deleted, ref_id: ".$this->getRefId().
01256 ", obj_id: ".$this->getId().", type: ".
01257 $this->getType().", title: ".$this->getTitle());
01258
01259
01260
01261
01262
01263 $rbacadmin->revokePermission($this->getRefId(),0,false);
01264
01265
01266 ilUtil::removeItemFromDesktops($this->getRefId());
01267 }
01268
01269
01270 if ($this->referenced)
01271 {
01272 $ch =& new ilConditionHandler();
01273 $ch->delete($this->getRefId());
01274 unset($ch);
01275 }
01276
01277
01278
01279 return $remove;
01280 }
01281
01289 function initDefaultRoles()
01290 {
01291 return array();
01292 }
01293
01303 function createRoleFolder()
01304 {
01305 global $rbacreview;
01306
01307
01308
01309
01310 if ($rolf_data = $rbacreview->getRoleFolderofObject($this->getRefId()))
01311 {
01312 $rfoldObj = $this->ilias->obj_factory->getInstanceByRefId($rolf_data["ref_id"]);
01313 }
01314 else
01315 {
01316 include_once ("classes/class.ilObjRoleFolder.php");
01317 $rfoldObj = new ilObjRoleFolder();
01318 $rfoldObj->setTitle($this->getId());
01319 $rfoldObj->setDescription(" (ref_id ".$this->getRefId().")");
01320 $rfoldObj->create();
01321 $rfoldObj->createReference();
01322 $rfoldObj->putInTree($this->getRefId());
01323 $rfoldObj->setPermissions($this->getRefId());
01324 }
01325
01326 return $rfoldObj;
01327 }
01328
01337 function _exists($a_id, $a_reference = false)
01338 {
01339 global $ilias;
01340
01341 if ($a_reference)
01342 {
01343 $q = "SELECT * FROM object_data ".
01344 "LEFT JOIN object_reference ON object_reference.obj_id=object_data.obj_id ".
01345 "WHERE object_reference.ref_id='".$a_id."'";
01346 }
01347 else
01348 {
01349 $q = "SELECT * FROM object_data WHERE obj_id='".$a_id."'";
01350 }
01351
01352 $r = $ilias->db->query($q);
01353
01354 return $r->numRows() ? true : false;
01355 }
01356
01369 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
01370 {
01371 global $tree;
01372
01373 $parent_id = (int) $tree->getParentId($a_node_id);
01374
01375 if ($parent_id != 0)
01376 {
01377 $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
01378 $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
01379 }
01380
01381 return true;
01382 }
01383
01384
01385 function setRegisterMode($a_bool)
01386 {
01387 $this->register = (bool) $a_bool;
01388 }
01389
01390
01391
01392 function isUserRegistered($a_user_id = 0)
01393 {
01394 return false;
01395 }
01396
01397 function requireRegistration()
01398 {
01399 return $this->register;
01400 }
01401
01402
01403 function getXMLZip()
01404 {
01405 return false;
01406 }
01407 function getHTMLDirectory()
01408 {
01409 return false;
01410 }
01411
01412
01413 }
01414 ?>