• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilObject.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00033 class ilObject
00034 {
00040         var $ilias;
00041 
00047         var $lng;
00048 
00054         var $id;        // true object_id!!!!
00055         var $ref_id;// reference_id
00056         var $type;
00057         var $title;
00058         var $desc;
00059         var $long_desc;
00060         var $owner;
00061         var $create_date;
00062         var $last_update;
00063         var $import_id;
00064         var $register = false;          // registering required for object? set to true to implement a subscription interface
00065 
00071         var $referenced;
00072 
00078         var $objectList;
00079 
00084         var $max_title;
00085 
00090         var $max_desc;
00091 
00096         var $add_dots;
00097 
00101         var $obj_data_record;
00102 
00109         function ilObject($a_id = 0, $a_reference = true)
00110         {
00111                 global $ilias, $lng, $ilBench;
00112 
00113                 $ilBench->start("Core", "ilObject_Constructor");
00114 
00115                 if (DEBUG)
00116                 {
00117                         echo "<br/><font color=\"red\">type(".$this->type.") id(".$a_id.") referenced(".$a_reference.")</font>";
00118                 }
00119 
00120                 $this->ilias =& $ilias;
00121                 $this->lng =& $lng;
00122 
00123                 $this->max_title = MAXLENGTH_OBJ_TITLE;
00124                 $this->max_desc = MAXLENGTH_OBJ_DESC;
00125                 $this->add_dots = true;
00126 
00127                 $this->referenced = $a_reference;
00128                 $this->call_by_reference = $a_reference;
00129 
00130                 if ($a_id == 0)
00131                 {
00132                         $this->referenced = false;              // newly created objects are never referenced
00133                 }                                                                       // they will get referenced if createReference() is called
00134 
00135                 if ($this->referenced)
00136                 {
00137                         $this->ref_id = $a_id;
00138                 }
00139                 else
00140                 {
00141                         $this->id = $a_id;
00142                 }
00143                 // read object data
00144                 if ($a_id != 0)
00145                 {
00146                         $this->read();
00147                 }
00148 
00149                 $ilBench->stop("Core", "ilObject_Constructor");
00150         }
00151 
00155         function withReferences()
00156         {
00157                 // both vars could differ. this method should always return true if one of them is true without changing their status
00158                 return ($this->call_by_reference) ? true : $this->referenced;
00159         }
00160 
00161 
00167         function read($a_force_db = false)
00168         {
00169                 global $objDefinition, $ilBench, $ilDB;
00170 
00171                 $ilBench->start("Core", "ilObject_read");
00172 
00173                 if (isset($this->obj_data_record) && !$a_force_db)
00174                 {
00175                         $obj = $this->obj_data_record;
00176                 }
00177                 else if ($this->referenced)
00178                 {
00179                         // check reference id
00180                         if (!isset($this->ref_id))
00181                         {
00182                                 $message = "ilObject::read(): No ref_id given! (".$this->type.")";
00183                                 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00184                         }
00185 
00186                         // read object data
00187                         $ilBench->start("Core", "ilObject_read_readData");
00188                         /* old query (very slow)
00189                         $q = "SELECT * FROM object_data ".
00190                                  "LEFT JOIN object_reference ON object_data.obj_id=object_reference.obj_id ".
00191                                  "WHERE object_reference.ref_id='".$this->ref_id."'"; */
00192 
00193                         $q = "SELECT * FROM object_data, object_reference WHERE object_data.obj_id=object_reference.obj_id ".
00194                                  "AND object_reference.ref_id= ".$ilDB->quote($this->ref_id);
00195                         $object_set = $this->ilias->db->query($q);
00196                         $ilBench->stop("Core", "ilObject_read_readData");
00197 
00198                         // check number of records
00199                         if ($object_set->numRows() == 0)
00200                         {
00201                                 $message = "ilObject::read(): Object with ref_id ".$this->ref_id." not found! (".$this->type.")";
00202                                 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00203                         }
00204 
00205                         $obj = $object_set->fetchRow(DB_FETCHMODE_ASSOC);
00206                 }
00207                 else
00208                 {
00209                         // check object id
00210                         if (!isset($this->id))
00211                         {
00212                                 $message = "ilObject::read(): No obj_id given! (".$this->type.")";
00213                                 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00214                         }
00215 
00216                         // read object data
00217                         $q = "SELECT * FROM object_data ".
00218                                  "WHERE obj_id = ".$ilDB->quote($this->id);
00219                         $object_set = $this->ilias->db->query($q);
00220 
00221                         // check number of records
00222                         if ($object_set->numRows() == 0)
00223                         {
00224                                 $message = "ilObject::read(): Object with obj_id: ".$this->id." (".$this->type.") not found!";
00225                                 $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00226                         }
00227 
00228                         $obj = $object_set->fetchRow(DB_FETCHMODE_ASSOC);
00229                 }
00230 
00231                 $this->id = $obj["obj_id"];
00232                 $this->type = $obj["type"];
00233                 $this->title = $obj["title"];
00234                 $this->desc = $obj["description"];
00235                 $this->owner = $obj["owner"];
00236                 $this->create_date = $obj["create_date"];
00237                 $this->last_update = $obj["last_update"];
00238                 $this->import_id = $obj["import_id"];
00239 
00240                 if($objDefinition->isRBACObject($this->getType()))
00241                 {
00242                         // Read long description
00243                         $query = "SELECT * FROM object_description WHERE obj_id = ".$ilDB->quote($this->id);
00244                         $res = $this->ilias->db->query($query);
00245                         while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00246                         {
00247                                 $this->setDescription($row->description);
00248                         }
00249                 }
00250 
00251                 // multilingual support systemobjects (sys) & categories (db)
00252                 $ilBench->start("Core", "ilObject_Constructor_getTranslation");
00253                 $translation_type = $objDefinition->getTranslationType($this->type);
00254 
00255                 if ($translation_type == "sys")
00256                 {
00257                         $this->title = $this->lng->txt("obj_".$this->type);
00258                         $this->desc = $this->lng->txt("obj_".$this->type."_desc");
00259                 }
00260                 elseif ($translation_type == "db")
00261                 {
00262                         $q = "SELECT title,description FROM object_translation ".
00263                                  "WHERE obj_id = ".$ilDB->quote($this->id)." ".
00264                                  "AND lang_code = ".$ilDB->quote($this->ilias->account->getCurrentLanguage())." ".
00265                                  "AND NOT lang_default = 1";
00266                         $r = $this->ilias->db->query($q);
00267                         $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
00268 
00269                         if ($row)
00270                         {
00271                                 $this->title = $row->title;
00272                                 $this->setDescription($row->description);
00273                                 #$this->desc = $row->description;
00274                         }
00275                 }
00276 
00277                 $ilBench->stop("Core", "ilObject_Constructor_getTranslation");
00278 
00279                 $ilBench->stop("Core", "ilObject_read");
00280         }
00281 
00287         function getId()
00288         {
00289                 return $this->id;
00290         }
00291 
00297         function setId($a_id)
00298         {
00299                 $this->id = $a_id;
00300         }
00301 
00307         function setRefId($a_id)
00308         {
00309                 $this->ref_id = $a_id;
00310                 $this->referenced = true;
00311         }
00312 
00318         function getRefId()
00319         {
00320                 return $this->ref_id;
00321         }
00322 
00328         function getType()
00329         {
00330                 return $this->type;
00331         }
00332 
00338         function setType($a_type)
00339         {
00340                 $this->type = $a_type;
00341         }
00342 
00348         function getTitle()
00349         {
00350                 return $this->title;
00351         }
00352 
00359         function setTitle($a_title)
00360         {
00361                 if ($a_title == "")
00362                 {
00363                         $a_title = "NO TITLE";
00364                 }
00365 
00366                 $this->title = ilUtil::shortenText($a_title, $this->max_title, $this->add_dots);
00367         }
00368 
00375         function getDescription()
00376         {
00377                 return $this->desc;
00378         }
00379 
00386         function setDescription($a_desc)
00387         {
00388                 // Shortened form is storted in object_data. Long form is stored in object_description
00389                 $this->desc = ilUtil::shortenText($a_desc, $this->max_desc, $this->add_dots);
00390 
00391                 $this->long_desc = $a_desc;
00392 
00393                 return true;
00394         }
00395 
00402         function getLongDescription()
00403         {
00404                 return strlen($this->long_desc) ? $this->long_desc : $this->desc;
00405         }
00406 
00413         function getImportId()
00414         {
00415                 return $this->import_id;
00416         }
00417 
00424         function setImportId($a_import_id)
00425         {
00426                 $this->import_id = $a_import_id;
00427         }
00428 
00429         function _lookupObjIdByImportId($a_import_id)
00430         {
00431                 global $ilDB;
00432 
00433                 $query = "SELECT * FROM object_data ".
00434                         "WHERE import_id = '".$a_import_id."' ".
00435                         "ORDER BY create_date DESC";
00436                 $res = $ilDB->query($query);
00437                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00438                 {
00439                         return $row->obj_id;
00440                 }
00441                 return 0;
00442         }
00443 
00450         function getOwner()
00451         {
00452                 return $this->owner;
00453         }
00454 
00455         /*
00456         * get full name of object owner
00457         *
00458         * @access       public
00459         * @return       string  owner name or unknown
00460         */
00461         function getOwnerName()
00462         {
00463                 return ilObject::_lookupOwnerName($this->getOwner());
00464         }
00465 
00469         function _lookupOwnerName($a_owner_id)
00470         {
00471                 global $lng;
00472 
00473                 if ($a_owner_id != -1)
00474                 {
00475                         if (ilObject::_exists($a_owner_id))
00476                         {
00477                                 $owner = new ilObjUser($a_owner_id);
00478                         }
00479                 }
00480 
00481                 if (is_object($owner))
00482                 {
00483                         $own_name = $owner->getFullname();
00484                 }
00485                 else
00486                 {
00487                         $own_name = $lng->txt("unknown");
00488                 }
00489 
00490                 return $own_name;
00491         }
00492 
00499         function setOwner($a_owner)
00500         {
00501                 $this->owner = $a_owner;
00502         }
00503 
00504 
00505 
00511         function getCreateDate()
00512         {
00513                 return $this->create_date;
00514         }
00515 
00521         function getLastUpdateDate()
00522         {
00523                 return $this->last_update;
00524         }
00525 
00534         function setObjDataRecord($a_record)
00535         {
00536                 $this->obj_data_record = $a_record;
00537         }
00538 
00547         function create()
00548         {
00549                 global $ilDB, $log,$ilUser,$objDefinition;
00550 
00551                 if (!isset($this->type))
00552                 {
00553                         $message = get_class($this)."::create(): No object type given!";
00554                         $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00555                 }
00556 
00557                 // write log entry
00558                 $log->write("ilObject::create(), start");
00559 
00560                 $this->title = ilUtil::shortenText($this->getTitle(), $this->max_title, $this->add_dots);
00561                 $this->desc = ilUtil::shortenText($this->getDescription(), $this->max_desc, $this->add_dots);
00562                 
00563                 // determine owner
00564                 if ($this->getOwner() > 0)
00565                 {
00566                         $owner = $this->getOwner();
00567                 }
00568                 else
00569                 {
00570                         $owner = $ilUser->getId();
00571                 }
00572 
00573                 $q = "INSERT INTO object_data ".
00574                          "(type,title,description,owner,create_date,last_update,import_id) ".
00575                          "VALUES ".
00576                          "('".$this->type."',".$ilDB->quote($this->getTitle()).",'".ilUtil::prepareDBString($this->getDescription())."',".
00577                          "'".$owner."',now(),now(),'".
00578                         $this->getImportId()."')";
00579 
00580                 $ilDB->query($q);
00581 
00582                 $this->id = $ilDB->getLastInsertId();
00583 
00584 
00585                 
00586                 // Save long form of description if is rbac object
00587                 if($objDefinition->isRBACObject($this->getType()))
00588                 {
00589                         $query = "INSERT INTO object_description SET ".
00590                                 "obj_id = '".$this->id."', ".
00591                                 "description = '".ilUtil::prepareDBString($this->getLongDescription())."'";
00592                         
00593                         $ilDB->query($query);
00594                 }
00595                 
00596 
00597                 // the line ($this->read();) messes up meta data handling: meta data,
00598                 // that is not saved at this time, gets lost, so we query for the dates alone
00599                 //$this->read();
00600                 $q = "SELECT last_update, create_date FROM object_data".
00601                          " WHERE obj_id = '".$this->id."'";
00602                 $obj_set = $this->ilias->db->query($q);
00603                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00604                 $this->last_update = $obj_rec["last_update"];
00605                 $this->create_date = $obj_rec["create_date"];
00606 
00607                 // set owner for new objects
00608                 $this->setOwner($owner);
00609 
00610                 // write log entry
00611                 $log->write("ilObject::create(), finished, obj_id: ".$this->id.", type: ".
00612                         $this->type.", title: ".$this->getTitle());
00613 
00614                 return $this->id;
00615         }
00616 
00623         function update()
00624         {
00625                 global $objDefinition, $ilDB;
00626 
00627                 $q = "UPDATE object_data ".
00628                         "SET ".
00629                         "title = '".ilUtil::prepareDBString($this->getTitle())."',".
00630                         "description = '".ilUtil::prepareDBString($this->getDescription())."', ".
00631                         "import_id = '".$this->getImportId()."', ".
00632                         "last_update = now() ".
00633                         "WHERE obj_id = '".$this->getId()."'";
00634                 $this->ilias->db->query($q);
00635 
00636                 // the line ($this->read();) messes up meta data handling: meta data,
00637                 // that is not saved at this time, gets lost, so we query for the dates alone
00638                 //$this->read();
00639                 $q = "SELECT last_update FROM object_data".
00640                          " WHERE obj_id = ".$ilDB->quote($this->getId());
00641                 $obj_set = $this->ilias->db->query($q);
00642                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00643                 $this->last_update = $obj_rec["last_update"];
00644 
00645                 if($objDefinition->isRBACObject($this->getType()))
00646                 {
00647                         // Update long description
00648                         $res = $this->ilias->db->query("SELECT * FROM object_description WHERE obj_id = '".$this->getId()."'");
00649                         if($res->numRows())
00650                         {
00651                                 $query = "UPDATE object_description SET description = '".
00652                                         ilUtil::prepareDBString($this->getLongDescription())."' ".
00653                                         "WHERE obj_id = '".$this->getId()."'";
00654                         }
00655                         else
00656                         {
00657                                 $query = "INSERT INTO object_description SET obj_id = '".$this->getId()."', ".
00658                                         "description = '".ilUtil::prepareDBString($this->getLongDescription())."'";
00659                         }
00660                         $this->ilias->db->query($query);
00661                 }               
00662 
00663                 return true;
00664         }
00665 
00677         function MDUpdateListener($a_element)
00678         {
00679                 include_once 'Services/MetaData/classes/class.ilMD.php';
00680 
00681                 switch($a_element)
00682                 {
00683                         case 'General':
00684 
00685                                 // Update Title and description
00686                                 $md = new ilMD($this->getId(),0, $this->getType());
00687                                 if(!is_object($md_gen = $md->getGeneral()))
00688                                 {
00689                                         return false;
00690                                 }
00691 
00692                                 ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
00693                                 $this->setTitle($md_gen->getTitle());
00694 
00695                                 foreach($md_gen->getDescriptionIds() as $id)
00696                                 {
00697                                         $md_des = $md_gen->getDescription($id);
00698                                         ilObject::_writeDescription($this->getId(),$md_des->getDescription());
00699                                         $this->setDescription($md_des->getDescription());
00700                                         break;
00701                                 }
00702 
00703                                 break;
00704 
00705                         default:
00706                 }
00707                 return true;
00708         }
00709 
00713         function createMetaData()
00714         {
00715                 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
00716 
00717                 global $ilUser;
00718 
00719                 $md_creator = new ilMDCreator($this->getId(),0,$this->getType());
00720                 $md_creator->setTitle($this->getTitle());
00721                 $md_creator->setTitleLanguage($ilUser->getPref('language'));
00722                 $md_creator->setDescription($this->getLongDescription());
00723                 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
00724                 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
00725                 $md_creator->setLanguage($ilUser->getPref('language'));
00726                 $md_creator->create();
00727 
00728                 return true;
00729         }
00730 
00734         function updateMetaData()
00735         {
00736                 include_once("Services/MetaData/classes/class.ilMD.php");
00737                 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
00738                 include_once("Services/MetaData/classes/class.ilMDDescription.php");
00739 
00740                 $md =& new ilMD($this->getId(), 0, $this->getType());
00741                 $md_gen =& $md->getGeneral();
00742                 $md_gen->setTitle($this->getTitle());
00743 
00744                 // sets first description (maybe not appropriate)
00745                 $md_des_ids =& $md_gen->getDescriptionIds();
00746                 if (count($md_des_ids) > 0)
00747                 {
00748                         $md_des =& $md_gen->getDescription($md_des_ids[0]);
00749                         $md_des->setDescription($this->getLongDescription());
00750                         $md_des->update();
00751                 }
00752                 $md_gen->update();
00753 
00754         }
00755 
00759         function deleteMetaData()
00760         {
00761                 // Delete meta data
00762                 include_once('Services/MetaData/classes/class.ilMD.php');
00763                 $md = new ilMD($this->getId(), 0, $this->getType());
00764                 $md->deleteAll();
00765         }
00766 
00773     function updateOwner()
00774     {
00775         $q = "UPDATE object_data ".
00776             "SET ".
00777             "owner = '".$this->getOwner()."', ".
00778             "last_update = now() ".
00779             "WHERE obj_id = '".$this->getId()."'";
00780         $this->ilias->db->query($q);
00781 
00782         $q = "SELECT last_update FROM object_data".
00783              " WHERE obj_id = '".$this->getId()."'";
00784         $obj_set = $this->ilias->db->query($q);
00785         $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00786         $this->last_update = $obj_rec["last_update"];
00787 
00788         return true;
00789     }
00790 
00798         function _getIdForImportId($a_import_id)
00799         {
00800                 global $ilDB;
00801                 
00802                 $q = "SELECT * FROM object_data WHERE import_id = ".$ilDB->quote($a_import_id).
00803                         " ORDER BY create_date DESC LIMIT 1";
00804                 $obj_set = $ilDB->query($q);
00805 
00806                 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00807                 {
00808                         return $obj_rec["obj_id"];
00809                 }
00810                 else
00811                 {
00812                         return 0;
00813                 }
00814         }
00815 
00821         function _getAllReferences($a_id)
00822         {
00823                 global $ilDB;
00824 
00825                 $q = "SELECT * FROM object_reference WHERE obj_id = ".
00826                         $ilDB->quote($a_id);
00827                 $obj_set = $ilDB->query($q);
00828                 $ref = array();
00829 
00830                 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00831                 {
00832                         $ref[$obj_rec["ref_id"]] = $obj_rec["ref_id"];
00833                 }
00834 
00835                 return $ref;
00836         }
00837 
00843         function _lookupTitle($a_id)
00844         {
00845                 global $ilObjDataCache;
00846 
00847                 return $ilObjDataCache->lookupTitle($a_id);
00848         }
00849 
00855         function _lookupDescription($a_id)
00856         {
00857                 global $ilObjDataCache;
00858 
00859                 return $ilObjDataCache->lookupDescription($a_id);
00860         }
00861 
00867         function _lookupLastUpdate($a_id, $a_as_string = false)
00868         {
00869                 global $ilObjDataCache;
00870                 
00871                 if ($a_as_string)
00872                 {
00873                         include_once("classes/class.ilFormat.php");
00874                         return ilFormat::formatDate($ilObjDataCache->lookupLastUpdate($a_id), "datetime", true);
00875                 }
00876                 else
00877                 {
00878                         return $ilObjDataCache->lookupLastUpdate($a_id);
00879                 }
00880         }
00881 
00882         function _lookupObjId($a_id)
00883         {
00884                 global $ilObjDataCache;
00885 
00886                 return (int) $ilObjDataCache->lookupObjId($a_id);
00887         }
00888         
00892         function _setDeletedDate($a_ref_id)
00893         {
00894                 global $ilDB;
00895                 
00896                 $q = "UPDATE object_reference SET deleted=now() ".
00897                         "WHERE ref_id = ".$ilDB->quote($a_ref_id);
00898                 $ilDB->query($q);
00899         }
00900 
00904         function _resetDeletedDate($a_ref_id)
00905         {
00906                 global $ilDB;
00907                 
00908                 $q = "UPDATE object_reference SET deleted= ".$ilDB->quote("0000-00-00 00:00:00").
00909                         " WHERE ref_id = ".$ilDB->quote($a_ref_id);
00910                 $ilDB->query($q);
00911         }
00912 
00920         function _writeTitle($a_obj_id, $a_title)
00921         {
00922                 global $ilDB;
00923 
00924                 $q = "UPDATE object_data ".
00925                         "SET ".
00926                         "title = ".$ilDB->quote($a_title).",".
00927                         "last_update = now() ".
00928                         "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00929 
00930                 $ilDB->query($q);
00931         }
00932 
00940         function _writeDescription($a_obj_id, $a_desc)
00941         {
00942                 global $ilDB,$objDefinition;
00943 
00944 
00945                 $desc = ilUtil::shortenText($a_desc,MAXLENGTH_OBJ_DESC,true);
00946 
00947                 $q = "UPDATE object_data ".
00948                         "SET ".
00949                         "description = ".$ilDB->quote($desc).",".
00950                         "last_update = now() ".
00951                         "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00952 
00953                 $ilDB->query($q);
00954 
00955                 if($objDefinition->isRBACObject($this->getType()))
00956                 {
00957                         // Update long description
00958                         $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = '".$a_obj_id."'");
00959                         if($res->numRows())
00960                         {
00961                                 $query = "UPDATE object_description SET description = '".
00962                                         ilUtil::prepareDBString($a_desc)."' ".
00963                                         "WHERE obj_id = '".$this->getId()."'";
00964                         }
00965                         else
00966                         {
00967                                 $query = "INSERT INTO object_description SET obj_id = '".$this->getId()."', ".
00968                                         "description = '".ilUtil::prepareDBString($a_desc)."'";
00969                         }
00970                         $ilDB->query($query);
00971                 }
00972         }
00973 
00981         function _writeImportId($a_obj_id, $a_import_id)
00982         {
00983                 global $ilDB;
00984 
00985                 $q = "UPDATE object_data ".
00986                         "SET ".
00987                         "import_id = ".$ilDB->quote($a_import_id).",".
00988                         "last_update = now() ".
00989                         "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00990 
00991                 $ilDB->query($q);
00992         }
00993 
00999         function _lookupType($a_id,$a_reference = false)
01000         {
01001                 global $ilObjDataCache;
01002 
01003                 if($a_reference)
01004                 {
01005                         return $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_id));
01006                 }
01007                 return $ilObjDataCache->lookupType($a_id);
01008 
01009                 global $ilDB;
01010 
01011                 if ($a_reference === true)
01012                 {
01013                         $q = "SELECT type FROM object_reference as obr, object_data as obd ".
01014                                 "WHERE obr.ref_id = ".$ilDB->quote($a_id)." ".
01015                                 "AND obr.obj_id = obd.obj_id ";
01016                         
01017                         #$q = "SELECT type FROM object_data as obj ".
01018                         #        "LEFT JOIN object_reference as ref ON ref.obj_id=obj.obj_id ".
01019                         #        "WHERE ref.ref_id = '".$a_id."'";
01020                 }
01021                 else
01022                 {
01023                         $q = "SELECT type FROM object_data WHERE obj_id = ".$ilDB->quote($a_id);
01024                 }
01025 
01026                 $obj_set = $ilDB->query($q);
01027                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
01028 
01029                 return $obj_rec["type"];
01030         }
01031 
01035         function _isInTrash($a_ref_id)
01036         {
01037                 global $tree;
01038 
01039                 return $tree->isSaved($a_ref_id);
01040         }
01041 
01045         function _hasUntrashedReference($a_obj_id)
01046         {
01047                 $ref_ids  = ilObject::_getAllReferences($a_obj_id);
01048                 foreach($ref_ids as $ref_id)
01049                 {
01050                         if(!ilObject::_isInTrash($ref_id))
01051                         {
01052                                 return true;
01053                         }
01054                 }
01055 
01056                 return false;
01057         }
01058 
01064         function _lookupObjectId($a_ref_id)
01065         {
01066                 global $ilObjDataCache;
01067 
01068                 return (int) $ilObjDataCache->lookupObjId($a_ref_id);
01069         }
01070 
01081         function _getObjectsDataForType($a_type, $a_omit_trash = false)
01082         {
01083                 global $ilDB;
01084 
01085                 $q = "SELECT * FROM object_data WHERE type = ".$ilDB->quote($a_type);
01086                 $obj_set = $ilDB->query($q);
01087 
01088                 $objects = array();
01089                 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
01090                 {
01091                         if ((!$a_omit_trash) || ilObject::_hasUntrashedReference($obj_rec["obj_id"]))
01092                         {
01093                                 $objects[$obj_rec["title"].".".$obj_rec["obj_id"]] = array("id" => $obj_rec["obj_id"],
01094                                         "type" => $obj_rec["type"], "title" => $obj_rec["title"],
01095                                         "description" => $obj_rec["description"]);
01096                         }
01097                 }
01098                 ksort($objects);
01099                 return $objects;
01100         }
01101 
01107         function putInTree($a_parent_ref)
01108         {
01109                 global $tree, $log;
01110 
01111                 $tree->insertNode($this->getRefId(), $a_parent_ref);
01112                 
01113                 // write log entry
01114                 $log->write("ilObject::putInTree(), parent_ref: $a_parent_ref, ref_id: ".
01115                         $this->getRefId().", obj_id: ".$this->getId().", type: ".
01116                         $this->getType().", title: ".$this->getTitle());
01117 
01118         }
01119 
01126         function setPermissions($a_parent_ref)
01127         {
01128                 global $rbacadmin, $rbacreview;
01129 
01130                 $parentRoles = $rbacreview->getParentRoleIds($a_parent_ref);
01131 
01132                 foreach ($parentRoles as $parRol)
01133                 {
01134                         $ops = $rbacreview->getOperationsOfRole($parRol["obj_id"], $this->getType(), $parRol["parent"]);
01135                         $rbacadmin->grantPermission($parRol["obj_id"], $ops, $this->getRefId());
01136                 }
01137         }
01138 
01145         function createReference()
01146         {
01147                 global $ilDB;
01148 
01149                 if (!isset($this->id))
01150                 {
01151                         $message = "ilObject::createNewReference(): No obj_id given!";
01152                         $this->raiseError($message,$this->ilias->error_obj->WARNING);
01153                 }
01154 
01155                 $q = "INSERT INTO object_reference ".
01156                          "(obj_id) VALUES ('".$this->id."')";
01157                 $this->ilias->db->query($q);
01158 
01159                 $this->ref_id = $ilDB->getLastInsertId();
01160                 $this->referenced = true;
01161 
01162                 return $this->ref_id;
01163         }
01164 
01165 
01172         function countReferences()
01173         {
01174                 if (!isset($this->id))
01175                 {
01176                         $message = "ilObject::countReferences(): No obj_id given!";
01177                         $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
01178                 }
01179 
01180                 $q = "SELECT COUNT(ref_id) AS num FROM object_reference ".
01181                         "WHERE obj_id = '".$this->id."'";
01182                 $row = $this->ilias->db->getRow($q);
01183 
01184                 return $row->num;
01185         }
01186 
01187 
01198         function ilClone($a_parent_ref)
01199         {
01200                 global $log;
01201                 
01202                 $new_obj = new ilObject();
01203                 $new_obj->setTitle($this->getTitle());
01204                 $new_obj->setType($this->getType());
01205                 $new_obj->setDescription($this->getDescription());
01206                 $new_obj->create();
01207                 $new_ref_id = $new_obj->createReference();
01208                 $new_obj->putInTree($a_parent_ref);
01209                 $new_obj->setPermissions($a_parent_ref);
01210 
01211                 unset($new_obj);
01212                 
01213                 // write log entry
01214                 $log->write("ilObject::ilClone(), ref_id: ".$this->getRefId().",obj_id: ".$this->getId().", type: ".
01215                         $this->getType().", title: ".$this->getTitle().
01216                         ", new ref_id: ".$new_obj->getRefId().", new obj_id:".$new_obj->getId());
01217         
01218                 // ... and finally always return new reference ID!!
01219                 return $new_ref_id;
01220         }
01221 
01222 
01232         function delete()
01233         {
01234                 global $rbacadmin, $log;
01235 
01236                 $remove = false;
01237 
01238                 // delete object_data entry
01239                 if ((!$this->referenced) || ($this->countReferences() == 1))
01240                 {
01241                         // delete entry in object_data
01242                         $q = "DELETE FROM object_data ".
01243                                 "WHERE obj_id = '".$this->getId()."'";
01244                         $this->ilias->db->query($q);
01245 
01246                         // delete long description
01247                         $query = "DELETE FROM object_description WHERE obj_id = '".$this->getId()."'";
01248                         $this->ilias->db->query($query);
01249 
01250                         // write log entry
01251                         $log->write("ilObject::delete(), deleted object, obj_id: ".$this->getId().", type: ".
01252                                 $this->getType().", title: ".$this->getTitle());
01253                         
01254                         $remove = true;
01255                 }
01256                 else
01257                 {
01258                         // write log entry
01259                         $log->write("ilObject::delete(), object not deleted, number of references: ".
01260                                 $this->countReferences().", obj_id: ".$this->getId().", type: ".
01261                                 $this->getType().", title: ".$this->getTitle());
01262                 }
01263 
01264                 // delete object_reference entry
01265                 if ($this->referenced)
01266                 {
01267                         // delete entry in object_reference
01268                         $q = "DELETE FROM object_reference ".
01269                                 "WHERE ref_id = '".$this->getRefId()."'";
01270                         $this->ilias->db->query($q);
01271 
01272                         // write log entry
01273                         $log->write("ilObject::delete(), reference deleted, ref_id: ".$this->getRefId().
01274                                 ", obj_id: ".$this->getId().", type: ".
01275                                 $this->getType().", title: ".$this->getTitle());
01276 
01277                         // DELETE PERMISSION ENTRIES IN RBAC_PA
01278                         // DONE: method overwritten in ilObjRole & ilObjUser.
01279                         // this call only applies for objects in rbac (not usr,role,rolt)
01280                         // TODO: Do this for role templates too
01281                         $rbacadmin->revokePermission($this->getRefId(),0,false);
01282 
01283                         // Remove desktop items
01284                         ilUtil::removeItemFromDesktops($this->getRefId());
01285                 }
01286 
01287                 // remove conditions
01288                 if ($this->referenced)
01289                 {
01290                         $ch =& new ilConditionHandler();
01291                         $ch->delete($this->getRefId());
01292                         unset($ch);
01293                 }
01294 
01295                 
01296 
01297                 return $remove;
01298         }
01299 
01307         function initDefaultRoles()
01308         {
01309                 return array();
01310         }
01311         
01321         function createRoleFolder()
01322         {
01323                 global $rbacreview;
01324                 
01325                 // does a role folder already exists?
01326                 // (this check is only 'to be sure' that no second role folder is created under one object.
01327                 // the if-construct should never return true)
01328                 if ($rolf_data = $rbacreview->getRoleFolderofObject($this->getRefId()))
01329                 {
01330                         $rfoldObj = $this->ilias->obj_factory->getInstanceByRefId($rolf_data["ref_id"]);
01331                 }
01332                 else
01333                 {
01334                         include_once ("classes/class.ilObjRoleFolder.php");
01335                         $rfoldObj = new ilObjRoleFolder();
01336                         $rfoldObj->setTitle($this->getId());
01337                         $rfoldObj->setDescription(" (ref_id ".$this->getRefId().")");
01338                         $rfoldObj->create();
01339                         $rfoldObj->createReference();
01340                         $rfoldObj->putInTree($this->getRefId());
01341                         $rfoldObj->setPermissions($this->getRefId());
01342                 }
01343                 
01344                 return $rfoldObj;
01345         }
01346 
01355         function _exists($a_id, $a_reference = false)
01356         {
01357                 global $ilias;
01358                 
01359                 if ($a_reference)
01360                 {
01361                         $q = "SELECT * FROM object_data ".
01362                                  "LEFT JOIN object_reference ON object_reference.obj_id=object_data.obj_id ".
01363                                  "WHERE object_reference.ref_id='".$a_id."'";
01364                 }
01365                 else
01366                 {
01367                         $q = "SELECT * FROM object_data WHERE obj_id='".$a_id."'";
01368                 }
01369                 
01370                 $r = $ilias->db->query($q);
01371 
01372                 return $r->numRows() ? true : false;
01373         }
01374 
01387         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
01388         { 
01389                 global $tree;
01390                 
01391                 $parent_id = (int) $tree->getParentId($a_node_id);
01392                 
01393                 if ($parent_id != 0)
01394                 {
01395                         $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
01396                         $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
01397                 }
01398                                 
01399                 return true;
01400         }
01401         
01402         // toggle subscription interface
01403         function setRegisterMode($a_bool)
01404         {
01405                 $this->register = (bool) $a_bool;
01406         }
01407         
01408         // check register status of current user
01409         // abstract method; overwrite in object type class
01410         function isUserRegistered($a_user_id = 0)
01411         {
01412                 return false;
01413         }
01414 
01415         function requireRegistration()
01416         {
01417                 return $this->register;
01418         }
01419 
01420 
01421         function getXMLZip()
01422         {
01423                 return false;
01424         }
01425         function getHTMLDirectory()
01426         {
01427                 return false;
01428         }
01429 
01430 
01431 } // END class.ilObject
01432 ?>

Generated on Fri Dec 13 2013 13:52:07 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1