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!";
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!";
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!";
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." 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
00436 function getOwner()
00437 {
00438 return $this->owner;
00439 }
00440
00441
00442
00443
00444
00445
00446
00447 function getOwnerName()
00448 {
00449 return ilObject::_lookupOwnerName($this->getOwner());
00450 }
00451
00455 function _lookupOwnerName($a_owner_id)
00456 {
00457 global $lng;
00458
00459 if ($a_owner_id != -1)
00460 {
00461 if (ilObject::_exists($a_owner_id))
00462 {
00463 $owner = new ilObjUser($a_owner_id);
00464 }
00465 }
00466
00467 if (is_object($owner))
00468 {
00469 $own_name = $owner->getFullname();
00470 }
00471 else
00472 {
00473 $own_name = $lng->txt("unknown");
00474 }
00475
00476 return $own_name;
00477 }
00478
00485 function setOwner($a_owner)
00486 {
00487 $this->owner = $a_owner;
00488 }
00489
00495 function getCreateDate()
00496 {
00497 return $this->create_date;
00498 }
00499
00505 function getLastUpdateDate()
00506 {
00507 return $this->last_update;
00508 }
00509
00518 function setObjDataRecord($a_record)
00519 {
00520 $this->obj_data_record = $a_record;
00521 }
00522
00531 function create()
00532 {
00533 global $ilDB, $log,$ilUser,$objDefinition;
00534
00535 if (!isset($this->type))
00536 {
00537 $message = get_class($this)."::create(): No object type given!";
00538 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00539 }
00540
00541
00542 $log->write("ilObject::create(), start");
00543
00544 $this->title = ilUtil::shortenText($this->getTitle(), $this->max_title, $this->add_dots);
00545 $this->desc = ilUtil::shortenText($this->getDescription(), $this->max_desc, $this->add_dots);
00546
00547 $q = "INSERT INTO object_data ".
00548 "(type,title,description,owner,create_date,last_update,import_id) ".
00549 "VALUES ".
00550 "('".$this->type."',".$ilDB->quote($this->getTitle()).",'".ilUtil::prepareDBString($this->getDescription())."',".
00551 "'".$ilUser->getId()."',now(),now(),'".
00552 $this->getImportId()."')";
00553
00554 $ilDB->query($q);
00555
00556 $this->id = $ilDB->getLastInsertId();
00557
00558
00559
00560
00561 if($objDefinition->isRBACObject($this->getType()))
00562 {
00563 $query = "INSERT INTO object_description SET ".
00564 "obj_id = '".$this->id."', ".
00565 "description = '".ilUtil::prepareDBString($this->getLongDescription())."'";
00566
00567 $ilDB->query($query);
00568 }
00569
00570
00571
00572
00573
00574 $q = "SELECT last_update, create_date FROM object_data".
00575 " WHERE obj_id = '".$this->id."'";
00576 $obj_set = $this->ilias->db->query($q);
00577 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00578 $this->last_update = $obj_rec["last_update"];
00579 $this->create_date = $obj_rec["create_date"];
00580
00581
00582 $this->setOwner($ilUser->getId());
00583
00584
00585 $log->write("ilObject::create(), finished, obj_id: ".$this->id.", type: ".
00586 $this->type.", title: ".$this->getTitle());
00587
00588 return $this->id;
00589 }
00590
00597 function update()
00598 {
00599 global $objDefinition;
00600
00601 $q = "UPDATE object_data ".
00602 "SET ".
00603 "title = '".ilUtil::prepareDBString($this->getTitle())."',".
00604 "description = '".ilUtil::prepareDBString($this->getDescription())."', ".
00605 "import_id = '".$this->getImportId()."', ".
00606 "last_update = now() ".
00607 "WHERE obj_id = '".$this->getId()."'";
00608 $this->ilias->db->query($q);
00609
00610
00611
00612
00613 $q = "SELECT last_update FROM object_data".
00614 " WHERE obj_id = '".$this->getId()."'";
00615 $obj_set = $this->ilias->db->query($q);
00616 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00617 $this->last_update = $obj_rec["last_update"];
00618
00619 if($objDefinition->isRBACObject($this->getType()))
00620 {
00621
00622 $res = $this->ilias->db->query("SELECT * FROM object_description WHERE obj_id = '".$this->getId()."'");
00623 if($res->numRows())
00624 {
00625 $query = "UPDATE object_description SET description = '".
00626 ilUtil::prepareDBString($this->getLongDescription())."' ".
00627 "WHERE obj_id = '".$this->getId()."'";
00628 }
00629 else
00630 {
00631 $query = "INSERT INTO object_description SET obj_id = '".$this->getId()."', ".
00632 "description = '".ilUtil::prepareDBString($this->getLongDescription())."'";
00633 }
00634 $this->ilias->db->query($query);
00635 }
00636
00637 return true;
00638 }
00639
00651 function MDUpdateListener($a_element)
00652 {
00653 include_once 'Services/MetaData/classes/class.ilMD.php';
00654
00655 switch($a_element)
00656 {
00657 case 'General':
00658
00659
00660 $md = new ilMD($this->getId(), 0, $this->getType());
00661 $md_gen = $md->getGeneral();
00662
00663 ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
00664 $this->setTitle($md_gen->getTitle());
00665
00666 foreach($md_gen->getDescriptionIds() as $id)
00667 {
00668 $md_des = $md_gen->getDescription($id);
00669 ilObject::_writeDescription($this->getId(),$md_des->getDescription());
00670 $this->setDescription($md_des->getDescription());
00671 break;
00672 }
00673
00674 break;
00675
00676 default:
00677 }
00678 return true;
00679 }
00680
00684 function createMetaData()
00685 {
00686 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
00687
00688 global $ilUser;
00689
00690 $md_creator = new ilMDCreator($this->getId(),0,$this->getType());
00691 $md_creator->setTitle($this->getTitle());
00692 $md_creator->setTitleLanguage($ilUser->getPref('language'));
00693 $md_creator->setDescription($this->getLongDescription());
00694 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
00695 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
00696 $md_creator->setLanguage($ilUser->getPref('language'));
00697 $md_creator->create();
00698
00699 return true;
00700 }
00701
00705 function updateMetaData()
00706 {
00707 include_once("Services/MetaData/classes/class.ilMD.php");
00708 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
00709 include_once("Services/MetaData/classes/class.ilMDDescription.php");
00710
00711 $md =& new ilMD($this->getId(), 0, $this->getType());
00712 $md_gen =& $md->getGeneral();
00713 $md_gen->setTitle($this->getTitle());
00714
00715
00716 $md_des_ids =& $md_gen->getDescriptionIds();
00717 if (count($md_des_ids) > 0)
00718 {
00719 $md_des =& $md_gen->getDescription($md_des_ids[0]);
00720 $md_des->setDescription($this->getLongDescription());
00721 $md_des->update();
00722 }
00723 $md_gen->update();
00724
00725 }
00726
00730 function deleteMetaData()
00731 {
00732
00733 include_once('Services/MetaData/classes/class.ilMD.php');
00734 $md = new ilMD($this->getId(), 0, $this->getType());
00735 $md->deleteAll();
00736 }
00737
00744 function updateOwner()
00745 {
00746 $q = "UPDATE object_data ".
00747 "SET ".
00748 "owner = '".$this->getOwner()."', ".
00749 "last_update = now() ".
00750 "WHERE obj_id = '".$this->getId()."'";
00751 $this->ilias->db->query($q);
00752
00753 $q = "SELECT last_update FROM object_data".
00754 " WHERE obj_id = '".$this->getId()."'";
00755 $obj_set = $this->ilias->db->query($q);
00756 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00757 $this->last_update = $obj_rec["last_update"];
00758
00759 return true;
00760 }
00761
00769 function _getIdForImportId($a_import_id)
00770 {
00771 global $ilDB;
00772
00773 $q = "SELECT * FROM object_data WHERE import_id = '".$a_import_id."'".
00774 " ORDER BY create_date DESC LIMIT 1";
00775 $obj_set = $ilDB->query($q);
00776
00777 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00778 {
00779 return $obj_rec["obj_id"];
00780 }
00781 else
00782 {
00783 return 0;
00784 }
00785 }
00786
00792 function _getAllReferences($a_id)
00793 {
00794 global $ilDB;
00795
00796 $q = "SELECT * FROM object_reference WHERE obj_id = '".$a_id."'";
00797 $obj_set = $ilDB->query($q);
00798 $ref = array();
00799
00800 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00801 {
00802 $ref[$obj_rec["ref_id"]] = $obj_rec["ref_id"];
00803 }
00804
00805 return $ref;
00806 }
00807
00813 function _lookupTitle($a_id)
00814 {
00815 global $ilDB;
00816
00817 $q = "SELECT title FROM object_data WHERE obj_id = '".$a_id."'";
00818 $obj_set = $ilDB->query($q);
00819 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00820
00821 return $obj_rec["title"];
00822 }
00823
00829 function _lookupDescription($a_id)
00830 {
00831 global $ilDB;
00832
00833 $q = "SELECT description FROM object_data WHERE obj_id = '".$a_id."'";
00834 $obj_set = $ilDB->query($q);
00835 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00836
00837 return $obj_rec["description"];
00838 }
00839
00845 function _lookupLastUpdate($a_id)
00846 {
00847 global $ilDB;
00848
00849 $q = "SELECT last_update FROM object_data WHERE obj_id = '".$a_id."'";
00850 $obj_set = $ilDB->query($q);
00851 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00852
00853 return $obj_rec["last_update"];
00854 }
00855
00856 function _lookupObjId($a_id)
00857 {
00858 global $ilDB;
00859
00860 $query = "SELECT obj_id FROM object_reference ".
00861 "WHERE ref_id = '".$a_id."'";
00862 $res = $ilDB->query($query);
00863 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00864 {
00865 return $row->obj_id;
00866 }
00867 return 0;
00868 }
00869
00877 function _writeTitle($a_obj_id, $a_title)
00878 {
00879 global $ilDB;
00880
00881 $q = "UPDATE object_data ".
00882 "SET ".
00883 "title = ".$ilDB->quote($a_title).",".
00884 "last_update = now() ".
00885 "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00886
00887 $ilDB->query($q);
00888 }
00889
00897 function _writeDescription($a_obj_id, $a_desc)
00898 {
00899 global $ilDB,$objDefinition;
00900
00901
00902 $desc = ilUtil::shortenText($a_desc,MAXLENGTH_OBJ_DESC,true);
00903
00904 $q = "UPDATE object_data ".
00905 "SET ".
00906 "description = ".$ilDB->quote($desc).",".
00907 "last_update = now() ".
00908 "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00909
00910 $ilDB->query($q);
00911
00912 if($objDefinition->isRBACObject($this->getType()))
00913 {
00914
00915 $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = '".$a_obj_id."'");
00916 if($res->numRows())
00917 {
00918 $query = "UPDATE object_description SET description = '".
00919 ilUtil::prepareDBString($a_desc)."' ".
00920 "WHERE obj_id = '".$this->getId()."'";
00921 }
00922 else
00923 {
00924 $query = "INSERT INTO object_description SET obj_id = '".$this->getId()."', ".
00925 "description = '".ilUtil::prepareDBString($a_desc)."'";
00926 }
00927 $ilDB->query($query);
00928 }
00929 }
00930
00938 function _writeImportId($a_obj_id, $a_import_id)
00939 {
00940 global $ilDB;
00941
00942 $q = "UPDATE object_data ".
00943 "SET ".
00944 "import_id = ".$ilDB->quote($a_import_id).",".
00945 "last_update = now() ".
00946 "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00947
00948 $ilDB->query($q);
00949 }
00950
00956 function _lookupType($a_id,$a_reference = false)
00957 {
00958 global $ilDB;
00959
00960 if ($a_reference === true)
00961 {
00962 $q = "SELECT type FROM object_reference as obr, object_data as obd ".
00963 "WHERE obr.ref_id = '".$a_id."' ".
00964 "AND obr.obj_id = obd.obj_id ";
00965
00966 #$q = "SELECT type FROM object_data as obj ".
00967 # "LEFT JOIN object_reference as ref ON ref.obj_id=obj.obj_id ".
00968 # "WHERE ref.ref_id = '".$a_id."'";
00969 }
00970 else
00971 {
00972 $q = "SELECT type FROM object_data WHERE obj_id = '".$a_id."'";
00973 }
00974
00975 $obj_set = $ilDB->query($q);
00976 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00977
00978 return $obj_rec["type"];
00979 }
00980
00984 function _isInTrash($a_ref_id)
00985 {
00986 global $tree;
00987
00988 return $tree->isSaved($a_ref_id);
00989 }
00990
00994 function _hasUntrashedReference($a_obj_id)
00995 {
00996 $ref_ids = ilObject::_getAllReferences($a_obj_id);
00997 foreach($ref_ids as $ref_id)
00998 {
00999 if(!ilObject::_isInTrash($ref_id))
01000 {
01001 return true;
01002 }
01003 }
01004
01005 return false;
01006 }
01007
01013 function _lookupObjectId($a_ref_id)
01014 {
01015 global $ilDB;
01016
01017 $q = "SELECT obj_id FROM object_reference WHERE ref_id = '".$a_ref_id."'";
01018 $obj_set = $ilDB->query($q);
01019 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
01020
01021 return $obj_rec["obj_id"];
01022 }
01023
01034 function _getObjectsDataForType($a_type, $a_omit_trash = false)
01035 {
01036 global $ilDB;
01037
01038 $q = "SELECT * FROM object_data WHERE type = ".$ilDB->quote($a_type);
01039 $obj_set = $ilDB->query($q);
01040
01041 $objects = array();
01042 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
01043 {
01044 if ((!$a_omit_trash) || ilObject::_hasUntrashedReference($obj_rec["obj_id"]))
01045 {
01046 $objects[$obj_rec["title"].".".$obj_rec["obj_id"]] = array("id" => $obj_rec["obj_id"],
01047 "type" => $obj_rec["type"], "title" => $obj_rec["title"],
01048 "description" => $obj_rec["description"]);
01049 }
01050 }
01051 ksort($objects);
01052 return $objects;
01053 }
01054
01060 function putInTree($a_parent_ref)
01061 {
01062 global $tree, $log;
01063
01064 $tree->insertNode($this->getRefId(), $a_parent_ref);
01065
01066
01067 $log->write("ilObject::putInTree(), parent_ref: $a_parent_ref, ref_id: ".
01068 $this->getRefId().", obj_id: ".$this->getId().", type: ".
01069 $this->getType().", title: ".$this->getTitle());
01070
01071 }
01072
01079 function setPermissions($a_parent_ref)
01080 {
01081 global $rbacadmin, $rbacreview;
01082
01083 $parentRoles = $rbacreview->getParentRoleIds($a_parent_ref);
01084
01085 foreach ($parentRoles as $parRol)
01086 {
01087 $ops = $rbacreview->getOperationsOfRole($parRol["obj_id"], $this->getType(), $parRol["parent"]);
01088 $rbacadmin->grantPermission($parRol["obj_id"], $ops, $this->getRefId());
01089 }
01090 }
01091
01098 function createReference()
01099 {
01100 global $ilDB;
01101
01102 if (!isset($this->id))
01103 {
01104 $message = "ilObject::createNewReference(): No obj_id given!";
01105 $this->raiseError($message,$this->ilias->error_obj->WARNING);
01106 }
01107
01108 $q = "INSERT INTO object_reference ".
01109 "(obj_id) VALUES ('".$this->id."')";
01110 $this->ilias->db->query($q);
01111
01112 $this->ref_id = $ilDB->getLastInsertId();
01113 $this->referenced = true;
01114
01115 return $this->ref_id;
01116 }
01117
01118
01125 function countReferences()
01126 {
01127 if (!isset($this->id))
01128 {
01129 $message = "ilObject::countReferences(): No obj_id given!";
01130 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
01131 }
01132
01133 $q = "SELECT COUNT(ref_id) AS num FROM object_reference ".
01134 "WHERE obj_id = '".$this->id."'";
01135 $row = $this->ilias->db->getRow($q);
01136
01137 return $row->num;
01138 }
01139
01140
01151 function ilClone($a_parent_ref)
01152 {
01153 global $log;
01154
01155 $new_obj = new ilObject();
01156 $new_obj->setTitle($this->getTitle());
01157 $new_obj->setType($this->getType());
01158 $new_obj->setDescription($this->getDescription());
01159 $new_obj->create();
01160 $new_ref_id = $new_obj->createReference();
01161 $new_obj->putInTree($a_parent_ref);
01162 $new_obj->setPermissions($a_parent_ref);
01163
01164 unset($new_obj);
01165
01166
01167 $log->write("ilObject::ilClone(), ref_id: ".$this->getRefId().",obj_id: ".$this->getId().", type: ".
01168 $this->getType().", title: ".$this->getTitle().
01169 ", new ref_id: ".$new_obj->getRefId().", new obj_id:".$new_obj->getId());
01170
01171
01172 return $new_ref_id;
01173 }
01174
01175
01185 function delete()
01186 {
01187 global $rbacadmin, $log;
01188
01189 $remove = false;
01190
01191
01192 if ((!$this->referenced) || ($this->countReferences() == 1))
01193 {
01194
01195 $q = "DELETE FROM object_data ".
01196 "WHERE obj_id = '".$this->getId()."'";
01197 $this->ilias->db->query($q);
01198
01199
01200 $query = "DELETE FROM object_description WHERE obj_id = '".$this->getId()."'";
01201 $this->ilias->db->query($query);
01202
01203
01204 $log->write("ilObject::delete(), deleted object, obj_id: ".$this->getId().", type: ".
01205 $this->getType().", title: ".$this->getTitle());
01206
01207 $remove = true;
01208 }
01209 else
01210 {
01211
01212 $log->write("ilObject::delete(), object not deleted, number of references: ".
01213 $this->countReferences().", obj_id: ".$this->getId().", type: ".
01214 $this->getType().", title: ".$this->getTitle());
01215 }
01216
01217
01218 if ($this->referenced)
01219 {
01220
01221 $q = "DELETE FROM object_reference ".
01222 "WHERE ref_id = '".$this->getRefId()."'";
01223 $this->ilias->db->query($q);
01224
01225
01226 $log->write("ilObject::delete(), reference deleted, ref_id: ".$this->getRefId().
01227 ", obj_id: ".$this->getId().", type: ".
01228 $this->getType().", title: ".$this->getTitle());
01229
01230
01231
01232
01233
01234 $rbacadmin->revokePermission($this->getRefId());
01235 }
01236
01237
01238 if ($this->referenced)
01239 {
01240 $ch =& new ilConditionHandler();
01241 $ch->delete($this->getRefId());
01242 unset($ch);
01243 }
01244
01245 return $remove;
01246 }
01247
01255 function initDefaultRoles()
01256 {
01257 return array();
01258 }
01259
01269 function createRoleFolder()
01270 {
01271 global $rbacreview;
01272
01273
01274
01275
01276 if ($rolf_data = $rbacreview->getRoleFolderofObject($this->getRefId()))
01277 {
01278 $rfoldObj = $this->ilias->obj_factory->getInstanceByRefId($rolf_data["ref_id"]);
01279 }
01280 else
01281 {
01282 include_once ("classes/class.ilObjRoleFolder.php");
01283 $rfoldObj = new ilObjRoleFolder();
01284 $rfoldObj->setTitle($this->getId());
01285 $rfoldObj->setDescription(" (ref_id ".$this->getRefId().")");
01286 $rfoldObj->create();
01287 $rfoldObj->createReference();
01288 $rfoldObj->putInTree($this->getRefId());
01289 $rfoldObj->setPermissions($this->getRefId());
01290 }
01291
01292 return $rfoldObj;
01293 }
01294
01303 function _exists($a_id, $a_reference = false)
01304 {
01305 global $ilias;
01306
01307 if ($a_reference)
01308 {
01309 $q = "SELECT * FROM object_data ".
01310 "LEFT JOIN object_reference ON object_reference.obj_id=object_data.obj_id ".
01311 "WHERE object_reference.ref_id='".$a_id."'";
01312 }
01313 else
01314 {
01315 $q = "SELECT * FROM object_data WHERE obj_id='".$a_id."'";
01316 }
01317
01318 $r = $ilias->db->query($q);
01319
01320 return $r->numRows() ? true : false;
01321 }
01322
01335 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
01336 {
01337 global $tree;
01338
01339 $parent_id = (int) $tree->getParentId($a_node_id);
01340
01341 if ($parent_id != 0)
01342 {
01343 $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
01344 $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
01345 }
01346
01347 return true;
01348 }
01349
01350
01351 function setRegisterMode($a_bool)
01352 {
01353 $this->register = (bool) $a_bool;
01354 }
01355
01356
01357
01358 function isUserRegistered($a_user_id = 0)
01359 {
01360 return false;
01361 }
01362
01363 function requireRegistration()
01364 {
01365 return $this->register;
01366 }
01367
01368
01369 function getXMLZip()
01370 {
01371 return false;
01372 }
01373 function getHTMLDirectory()
01374 {
01375 return false;
01376 }
01377
01378
01379 }
01380 ?>