116 $ilBench->start(
"Core",
"ilObject_Constructor");
120 echo
"<br/><font color=\"red\">type(".$this->type.
") id(".$a_id.
") referenced(".$a_reference.
")</font>";
126 $this->max_title = MAXLENGTH_OBJ_TITLE;
127 $this->max_desc = MAXLENGTH_OBJ_DESC;
128 $this->add_dots =
true;
130 $this->referenced = $a_reference;
131 $this->call_by_reference = $a_reference;
135 $this->referenced =
false;
138 if ($this->referenced)
140 $this->ref_id = $a_id;
152 $ilBench->stop(
"Core",
"ilObject_Constructor");
170 function read($a_force_db =
false)
174 $ilBench->start(
"Core",
"ilObject_read");
176 if (isset($this->obj_data_record) && !$a_force_db)
180 else if ($this->referenced)
183 if (!isset($this->ref_id))
185 $message =
"ilObject::read(): No ref_id given! (".$this->type.
")";
186 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
190 $ilBench->start(
"Core",
"ilObject_read_readData");
196 $q =
"SELECT * FROM object_data, object_reference WHERE object_data.obj_id=object_reference.obj_id ".
197 "AND object_reference.ref_id= ".$ilDB->quote($this->ref_id);
198 $object_set = $this->ilias->db->query($q);
199 $ilBench->stop(
"Core",
"ilObject_read_readData");
202 if ($object_set->numRows() == 0)
204 $message =
"ilObject::read(): Object with ref_id ".$this->ref_id.
" not found! (".$this->type.
")";
205 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
213 if (!isset($this->
id))
215 $message =
"ilObject::read(): No obj_id given! (".$this->type.
")";
216 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
220 $q =
"SELECT * FROM object_data ".
221 "WHERE obj_id = ".$ilDB->quote($this->
id);
222 $object_set = $ilDB->query($q);
225 if ($object_set->numRows() == 0)
227 $message =
"ilObject::read(): Object with obj_id: ".$this->id.
" (".$this->type.
") not found!";
228 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
234 $this->
id = $obj[
"obj_id"];
237 if ($this->type != $obj[
"type"])
239 $message =
"ilObject::read(): Type mismatch. Object with obj_id: ".$this->id.
" ".
240 "was instantiated by type '".$this->type.
"'. DB type is: ".$obj[
"type"];
243 $log->write($message);
246 $this->ilias->raiseError(
"ilObject::read(): Type mismatch. (".$this->type.
"/".$this->id.
")",$this->ilias->error_obj->WARNING);
249 $this->type = $obj[
"type"];
250 $this->title = $obj[
"title"];
252 $this->untranslatedTitle = $obj[
"title"];
254 $this->desc = $obj[
"description"];
255 $this->owner = $obj[
"owner"];
256 $this->create_date = $obj[
"create_date"];
257 $this->last_update = $obj[
"last_update"];
258 $this->import_id = $obj[
"import_id"];
260 if($objDefinition->isRBACObject($this->getType()))
263 $query =
"SELECT * FROM object_description WHERE obj_id = ".$ilDB->quote($this->
id);
264 $res = $this->ilias->db->query($query);
272 $ilBench->start(
"Core",
"ilObject_Constructor_getTranslation");
273 $translation_type = $objDefinition->getTranslationType($this->type);
275 if ($translation_type ==
"sys")
277 $this->title = $this->lng->txt(
"obj_".$this->type);
278 $this->desc = $this->lng->txt(
"obj_".$this->type.
"_desc");
280 elseif ($translation_type ==
"db")
282 $q =
"SELECT title,description FROM object_translation ".
283 "WHERE obj_id = ".$ilDB->quote($this->
id).
" ".
284 "AND lang_code = ".$ilDB->quote($this->ilias->account->getCurrentLanguage()).
" ".
285 "AND NOT lang_default = 1";
286 $r = $this->ilias->db->query($q);
291 $this->title = $row->title;
293 #$this->desc = $row->description;
297 $ilBench->stop(
"Core",
"ilObject_Constructor_getTranslation");
299 $ilBench->stop(
"Core",
"ilObject_read");
329 $this->ref_id = $a_id;
330 $this->referenced =
true;
360 $this->type = $a_type;
409 $a_title =
"NO TITLE";
440 $this->long_desc = $a_desc;
453 return strlen($this->long_desc) ? $this->long_desc :
$this->desc;
475 $this->import_id = $a_import_id;
482 $query =
"SELECT * FROM object_data ".
483 "WHERE import_id = ".$ilDB->quote($a_import_id).
" ".
484 "ORDER BY create_date DESC";
485 $res = $ilDB->query($query);
522 if ($a_owner_id != -1)
532 $own_name =
$owner->getFullname();
536 $own_name = $lng->txt(
"unknown");
550 $this->owner = $a_owner;
585 $this->obj_data_record = $a_record;
598 global $ilDB,
$log,$ilUser,$objDefinition;
600 if (!isset($this->type))
602 $message = get_class($this).
"::create(): No object type given!";
603 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
607 $log->write(
"ilObject::create(), start");
617 elseif(is_object($ilUser))
619 $owner = $ilUser->getId();
625 $q =
"INSERT INTO object_data ".
626 "(type,title,description,owner,create_date,last_update,import_id) ".
629 $ilDB->quote($this->type).
",".
630 $ilDB->quote($this->
getTitle()).
",".
632 $ilDB->quote(
$owner).
",now(),now(),".
637 $this->
id = $ilDB->getLastInsertId();
642 if($objDefinition->isRBACObject($this->getType()))
644 $query =
"INSERT INTO object_description SET ".
645 "obj_id = ".$ilDB->quote($this->
id).
",".
648 $ilDB->query($query);
655 $q =
"SELECT last_update, create_date FROM object_data".
656 " WHERE obj_id = ".$ilDB->quote($this->
id);
657 $obj_set = $this->ilias->db->query($q);
659 $this->last_update = $obj_rec[
"last_update"];
660 $this->create_date = $obj_rec[
"create_date"];
666 $log->write(
"ilObject::create(), finished, obj_id: ".$this->
id.
", type: ".
667 $this->type.
", title: ".$this->getTitle());
680 global $objDefinition, $ilDB;
682 $q =
"UPDATE object_data ".
684 "title = ".$ilDB->quote($this->
getTitle()).
",".
686 "import_id = ".$ilDB->quote($this->
getImportId()).
",".
687 "last_update = now() ".
688 "WHERE obj_id = ".$ilDB->quote($this->
getId());
689 $this->ilias->db->query($q);
694 $q =
"SELECT last_update FROM object_data".
695 " WHERE obj_id = ".$ilDB->quote($this->
getId());
696 $obj_set = $this->ilias->db->query($q);
698 $this->last_update = $obj_rec[
"last_update"];
700 if($objDefinition->isRBACObject($this->getType()))
703 $res = $this->ilias->db->query(
"SELECT * FROM object_description WHERE obj_id = ".
704 $ilDB->quote($this->getId()));
707 $query =
"UPDATE object_description SET description = ".
709 "WHERE obj_id = ".$ilDB->quote($this->
getId());
713 $query =
"INSERT INTO object_description SET obj_id = ".$ilDB->quote($this->
getId()).
", ".
716 $this->ilias->db->query($query);
735 include_once
'Services/MetaData/classes/class.ilMD.php';
743 if(!is_object($md_gen = $md->getGeneral()))
749 $this->
setTitle($md_gen->getTitle());
751 foreach($md_gen->getDescriptionIds() as
$id)
753 $md_des = $md_gen->getDescription(
$id);
771 include_once
'Services/MetaData/classes/class.ilMDCreator.php';
776 $md_creator->setTitle($this->
getTitle());
777 $md_creator->setTitleLanguage($ilUser->getPref(
'language'));
779 $md_creator->setDescriptionLanguage($ilUser->getPref(
'language'));
780 $md_creator->setKeywordLanguage($ilUser->getPref(
'language'));
781 $md_creator->setLanguage($ilUser->getPref(
'language'));
782 $md_creator->create();
792 include_once(
"Services/MetaData/classes/class.ilMD.php");
793 include_once(
"Services/MetaData/classes/class.ilMDGeneral.php");
794 include_once(
"Services/MetaData/classes/class.ilMDDescription.php");
797 $md_gen =& $md->getGeneral();
803 $md_gen =& $md->getGeneral();
806 $md_gen->setTitle($this->
getTitle());
809 $md_des_ids =& $md_gen->getDescriptionIds();
810 if (count($md_des_ids) > 0)
812 $md_des =& $md_gen->getDescription($md_des_ids[0]);
826 include_once(
'Services/MetaData/classes/class.ilMD.php');
841 $q =
"UPDATE object_data ".
843 "owner = ".$ilDB->quote($this->
getOwner()).
", ".
844 "last_update = now() ".
845 "WHERE obj_id = ".$ilDB->quote($this->
getId());
846 $this->ilias->db->query($q);
848 $q =
"SELECT last_update FROM object_data".
849 " WHERE obj_id = ".$ilDB->quote($this->
getId());
850 $obj_set = $this->ilias->db->query($q);
852 $this->last_update = $obj_rec[
"last_update"];
868 $q =
"SELECT * FROM object_data WHERE import_id = ".$ilDB->quote($a_import_id).
869 " ORDER BY create_date DESC LIMIT 1";
870 $obj_set = $ilDB->query($q);
874 return $obj_rec[
"obj_id"];
891 $q =
"SELECT * FROM object_reference WHERE obj_id = ".
893 $obj_set = $ilDB->query($q);
898 $ref[$obj_rec[
"ref_id"]] = $obj_rec[
"ref_id"];
911 global $ilObjDataCache;
913 $tit = $ilObjDataCache->lookupTitle($a_id);
922 $query =
"SELECT obj_id FROM object_data WHERE title = ?";
923 $datatypes = array(
'text');
927 $query .=
" AND type = ?";
928 $datatypes[] =
'text';
932 $statement = $ilDB->prepare($query, $datatypes);
933 $result = $ilDB->execute($statement, $values);
935 $object_ids = array();
936 while($row = $ilDB->fetchAssoc(
$result))
938 $object_ids[] = $row[
'obj_id'];
941 return is_array($object_ids) ? $object_ids : array();
951 global $ilObjDataCache;
953 return $ilObjDataCache->lookupDescription($a_id);
963 global $ilObjDataCache;
971 return $ilObjDataCache->lookupLastUpdate($a_id);
984 if (!is_array($a_objs))
986 $a_objs = array($a_objs);
989 $st = $ilDB->prepare(
"SELECT max(last_update) as last_update FROM object_data ".
990 "WHERE ".$ilDB->getInClause(
"obj_id", $a_objs),
991 $ilDB->addTypesToArray($types,
"integer", count($a_objs)));
992 $set = $ilDB->execute($st, $a_objs);
993 $rec = $ilDB->fetchAssoc($set);
995 return ($rec[
"last_update"]);
1000 global $ilObjDataCache;
1002 return (
int) $ilObjDataCache->lookupObjId($a_id);
1012 $q =
"UPDATE object_reference SET deleted=now() ".
1013 "WHERE ref_id = ".$ilDB->quote($a_ref_id);
1024 $q =
"UPDATE object_reference SET deleted= ".$ilDB->quote(
"0000-00-00 00:00:00").
1025 " WHERE ref_id = ".$ilDB->quote($a_ref_id);
1040 $q =
"UPDATE object_data ".
1042 "title = ".$ilDB->quote($a_title).
",".
1043 "last_update = now() ".
1044 "WHERE obj_id = ".$ilDB->quote($a_obj_id);
1058 global $ilDB,$objDefinition;
1063 $q =
"UPDATE object_data ".
1065 "description = ".$ilDB->quote(
$desc).
",".
1066 "last_update = now() ".
1067 "WHERE obj_id = ".$ilDB->quote($a_obj_id);
1071 if($objDefinition->isRBACObject($this->getType()))
1074 $res = $ilDB->query(
"SELECT * FROM object_description WHERE obj_id = ".
1075 $ilDB->quote($a_obj_id));
1078 $query =
"UPDATE object_description SET description = ".
1079 $ilDB->quote($a_desc).
" ".
1080 "WHERE obj_id = ".$ilDB->quote($this->
getId());
1084 $query =
"INSERT INTO object_description SET obj_id = ".
1085 $ilDB->quote($this->
getId()).
", ".
1086 "description = ".$ilDB->quote($a_desc);
1088 $ilDB->query($query);
1103 $q =
"UPDATE object_data ".
1105 "import_id = ".$ilDB->quote($a_import_id).
",".
1106 "last_update = now() ".
1107 "WHERE obj_id = ".$ilDB->quote($a_obj_id);
1119 global $ilObjDataCache;
1123 return $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_id));
1125 return $ilObjDataCache->lookupType($a_id);
1129 if ($a_reference ===
true)
1131 $q =
"SELECT type FROM object_reference as obr, object_data as obd ".
1132 "WHERE obr.ref_id = ".$ilDB->quote($a_id).
" ".
1133 "AND obr.obj_id = obd.obj_id ";
1135 #$q = "SELECT type FROM object_data as obj ".
1136 # "LEFT JOIN object_reference as ref ON ref.obj_id=obj.obj_id ".
1137 # "WHERE ref.ref_id = '".$a_id."'";
1141 $q =
"SELECT type FROM object_data WHERE obj_id = ".$ilDB->quote($a_id);
1144 $obj_set = $ilDB->query($q);
1147 return $obj_rec[
"type"];
1157 return $tree->isSaved($a_ref_id);
1184 global $ilObjDataCache;
1186 return (
int) $ilObjDataCache->lookupObjId($a_ref_id);
1203 $q =
"SELECT * FROM object_data WHERE type = ".$ilDB->quote($a_type);
1204 $obj_set = $ilDB->query($q);
1211 $objects[$obj_rec[
"title"].
".".$obj_rec[
"obj_id"]] = array(
"id" => $obj_rec[
"obj_id"],
1212 "type" => $obj_rec[
"type"],
"title" => $obj_rec[
"title"],
1213 "description" => $obj_rec[
"description"]);
1229 $tree->insertNode($this->
getRefId(), $a_parent_ref);
1232 $log->write(
"ilObject::putInTree(), parent_ref: $a_parent_ref, ref_id: ".
1246 global $rbacadmin, $rbacreview;
1248 $parentRoles = $rbacreview->getParentRoleIds($a_parent_ref);
1250 foreach ($parentRoles as $parRol)
1252 $ops = $rbacreview->getOperationsOfRole($parRol[
"obj_id"], $this->
getType(), $parRol[
"parent"]);
1253 $rbacadmin->grantPermission($parRol[
"obj_id"], $ops, $this->
getRefId());
1267 if (!isset($this->
id))
1269 $message =
"ilObject::createNewReference(): No obj_id given!";
1270 $this->raiseError($message,$this->ilias->error_obj->WARNING);
1273 $q =
"INSERT INTO object_reference ".
1274 "(obj_id) VALUES (".$ilDB->quote($this->
id).
")";
1275 $this->ilias->db->query($q);
1277 $this->ref_id = $ilDB->getLastInsertId();
1278 $this->referenced =
true;
1292 if (!isset($this->
id))
1294 $message =
"ilObject::countReferences(): No obj_id given!";
1295 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
1298 $q =
"SELECT COUNT(ref_id) AS num FROM object_reference ".
1299 "WHERE obj_id = '".$this->id.
"'";
1300 $row = $this->ilias->db->getRow($q);
1319 global $rbacadmin,
$log, $ilDB;
1328 if ($this->type != $db_type)
1330 $message =
"ilObject::delete(): Type mismatch. Object with obj_id: ".$this->id.
" ".
1331 "was instantiated by type '".$this->type.
"'. DB type is: ".$db_type;
1334 $log->write($message);
1337 $this->ilias->raiseError(
"ilObject::delete(): Type mismatch. (".$this->type.
"/".$this->id.
")",$this->ilias->error_obj->WARNING);
1341 $q =
"DELETE FROM object_data ".
1342 "WHERE obj_id = ".$ilDB->quote($this->
getId());
1343 $this->ilias->db->query($q);
1346 $query =
"DELETE FROM object_description WHERE obj_id = ".
1347 $ilDB->quote($this->
getId());
1348 $this->ilias->db->query($query);
1351 $log->write(
"ilObject::delete(), deleted object, obj_id: ".$this->
getId().
", type: ".
1355 include_once(
"./Services/News/classes/class.ilNewsItem.php");
1357 $news_item->deleteNewsOfContext($this->
getId(), $this->
getType());
1358 include_once(
"./Services/Block/classes/class.ilBlockSetting.php");
1366 $log->write(
"ilObject::delete(), object not deleted, number of references: ".
1372 if ($this->referenced)
1375 $q =
"DELETE FROM object_reference ".
1376 "WHERE ref_id = ".$ilDB->quote($this->
getRefId());
1377 $this->ilias->db->query($q);
1380 $log->write(
"ilObject::delete(), reference deleted, ref_id: ".$this->
getRefId().
1381 ", obj_id: ".$this->
getId().
", type: ".
1388 $rbacadmin->revokePermission($this->
getRefId(),0,
false);
1395 if ($this->referenced)
1403 $q =
"DELETE FROM dav_property ".
1404 "WHERE obj_id = ".$ilDB->quote($this->
getId());
1405 $this->ilias->db->query($q);
1409 $q =
"DELETE FROM write_event ".
1410 "WHERE obj_id = ".$ilDB->quote($this->
getId());
1411 $this->ilias->db->query($q);
1412 $q =
"DELETE FROM read_event ".
1413 "WHERE obj_id = ".$ilDB->quote($this->
getId());
1414 $this->ilias->db->query($q);
1448 if ($rolf_data = $rbacreview->getRoleFolderofObject($this->getRefId()))
1450 $rfoldObj = $this->ilias->obj_factory->getInstanceByRefId($rolf_data[
"ref_id"]);
1454 include_once (
"./Services/AccessControl/classes/class.ilObjRoleFolder.php");
1456 $rfoldObj->setTitle($this->
getId());
1457 $rfoldObj->setDescription(
" (ref_id ".$this->
getRefId().
")");
1458 $rfoldObj->create();
1459 $rfoldObj->createReference();
1460 $rfoldObj->putInTree($this->
getRefId());
1461 $rfoldObj->setPermissions($this->
getRefId());
1481 $q =
"SELECT * FROM object_data ".
1482 "LEFT JOIN object_reference ON object_reference.obj_id=object_data.obj_id ".
1483 "WHERE object_reference.ref_id= ".$ilDB->quote($a_id);
1487 $q =
"SELECT * FROM object_data WHERE obj_id=".$ilDB->quote($a_id);
1490 $r = $ilDB->query($q);
1492 return $r->numRows() ?
true :
false;
1507 function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
1511 $parent_id = (int) $tree->getParentId($a_node_id);
1513 if ($parent_id != 0)
1515 $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
1516 $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
1525 $this->
register = (bool) $a_bool;
1557 $order =
" ORDER BY title";
1562 $where_clause =
"WHERE type = ".
1563 $ilDB->quote($a_obj_type);
1566 $q =
"SELECT * FROM object_data ".$where_clause.$order;
1567 $r = $ilDB->query($q);
1570 if ($r->numRows() > 0)
1574 $row[
"desc"] = $row[
"description"];
1575 $arr[$row[
"obj_id"]] = $row;
1594 $query =
"SELECT obj_data.title as obj_title,path_data.title as path_title,child FROM tree ".
1595 "JOIN object_reference as obj_ref ON child = obj_ref.ref_id ".
1596 "JOIN object_data as obj_data ON obj_ref.obj_id = obj_data.obj_id ".
1597 "JOIN object_reference as path_ref ON parent = path_ref.ref_id ".
1598 "JOIN object_data as path_data ON path_ref.obj_id = path_data.obj_id ".
1600 "ORDER BY obj_data.title ";
1601 $res = $ilDB->query($query);
1603 $options[0] = $lng->txt(
'obj_'.$new_type.
'_select');
1606 if(strlen(
$title = $row->obj_title) > 40)
1610 if(strlen($path = $row->path_title) > 40)
1612 $path = substr($path,0,40).
'...';
1616 $options[$row->child] = (
$title.
' ('.$lng->txt(
'path').
': '.$path.
')');
1618 return $options ? $options : array();
1632 global $objDefinition,$ilUser,$rbacadmin, $ilDB;
1635 $class_name = (
'ilObj'.$objDefinition->getClassName($this->
getType()));
1640 include_once(
$location.
"/class.".$class_name.
".php");
1641 $new_obj =
new $class_name(0,
false);
1642 $new_obj->setOwner($ilUser->getId());
1643 $new_obj->setTitle(
$title);
1645 $new_obj->setType($this->
getType());
1647 $new_obj->create(
true);
1648 $new_obj->createReference();
1649 $new_obj->putInTree($a_target_id);
1650 $new_obj->setPermissions($a_target_id);
1651 $new_obj->initDefaultRoles();
1654 $rbacadmin->copyLocalRoles($this->
getRefId(),$new_obj->getRefId());
1656 include_once(
'./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
1660 $q =
"INSERT INTO dav_property (obj_id,node_id,ns,name,value) ".
1661 "SELECT ".$ilDB->quote($new_obj->getId()).
",node_id,ns,name,value ".
1662 "FROM dav_property ".
1663 "WHERE obj_id = ".$ilDB->quote($this->getId());
1664 $this->ilias->db->query($q);
1681 include_once(
'Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
1683 if(!$cp_options->isRootNode($this->getRefId()))
1687 $nodes = $tree->getChilds($a_target_id);
1689 $title_unique =
false;
1690 require_once
'Modules/File/classes/class.ilObjFileAccess.php';
1693 while(!$title_unique)
1696 foreach($nodes as $node)
1698 if((
$title == $node[
'title']) and ($this->
getType() == $node[
'type']))
1737 include_once
"./Services/MetaData/classes/class.ilMD.php";
1739 $md->cloneMD($target_obj->getId(),0,$target_obj->getType());
1743 public static function _getIcon($a_obj_id =
"", $a_size =
"big", $a_type =
"",
1748 if ($a_obj_id ==
"" && $a_type ==
"")
1763 if ($ilSetting->get(
"custom_icons") &&
1764 in_array($a_type, array(
"cat",
"grp",
"crs",
"root")))
1766 require_once(
"./Services/Container/classes/class.ilContainer.php");
1770 $file_name = $cont_dir.
"/icon_".$a_size.
".gif";
1781 case "small": $suff =
"";
break;
1782 case "tiny": $suff =
"_s";
break;
1783 default: $suff =
"_b";
break;
1792 return "./images/icon_".$a_type.$suff.
".gif";