• 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, $log;
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 = $ilDB->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                 // check type match 
00233                 if ($this->type != $obj["type"])
00234                 {
00235                         $message = "ilObject::read(): Type mismatch. Object with obj_id: ".$this->id." ".
00236                                 "was instantiated by type '".$this->type."'. DB type is: ".$obj["type"];
00237 
00238                         // write log entry
00239                         $log->write($message);
00240                                 
00241                         // raise error
00242                         $this->ilias->raiseError("ilObject::read(): Type mismatch. (".$this->type."/".$this->id.")",$this->ilias->error_obj->WARNING);
00243                 }
00244                 
00245                 $this->type = $obj["type"];
00246                 $this->title = $obj["title"];
00247                 $this->desc = $obj["description"];
00248                 $this->owner = $obj["owner"];
00249                 $this->create_date = $obj["create_date"];
00250                 $this->last_update = $obj["last_update"];
00251                 $this->import_id = $obj["import_id"];
00252 
00253                 if($objDefinition->isRBACObject($this->getType()))
00254                 {
00255                         // Read long description
00256                         $query = "SELECT * FROM object_description WHERE obj_id = ".$ilDB->quote($this->id);
00257                         $res = $this->ilias->db->query($query);
00258                         while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00259                         {
00260                                 $this->setDescription($row->description);
00261                         }
00262                 }
00263 
00264                 // multilingual support systemobjects (sys) & categories (db)
00265                 $ilBench->start("Core", "ilObject_Constructor_getTranslation");
00266                 $translation_type = $objDefinition->getTranslationType($this->type);
00267 
00268                 if ($translation_type == "sys")
00269                 {
00270                         $this->title = $this->lng->txt("obj_".$this->type);
00271                         $this->desc = $this->lng->txt("obj_".$this->type."_desc");
00272                 }
00273                 elseif ($translation_type == "db")
00274                 {
00275                         $q = "SELECT title,description FROM object_translation ".
00276                                  "WHERE obj_id = ".$ilDB->quote($this->id)." ".
00277                                  "AND lang_code = ".$ilDB->quote($this->ilias->account->getCurrentLanguage())." ".
00278                                  "AND NOT lang_default = 1";
00279                         $r = $this->ilias->db->query($q);
00280                         $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
00281 
00282                         if ($row)
00283                         {
00284                                 $this->title = $row->title;
00285                                 $this->setDescription($row->description);
00286                                 #$this->desc = $row->description;
00287                         }
00288                 }
00289 
00290                 $ilBench->stop("Core", "ilObject_Constructor_getTranslation");
00291 
00292                 $ilBench->stop("Core", "ilObject_read");
00293         }
00294 
00300         function getId()
00301         {
00302                 return $this->id;
00303         }
00304 
00310         function setId($a_id)
00311         {
00312                 $this->id = $a_id;
00313         }
00314 
00320         function setRefId($a_id)
00321         {
00322                 $this->ref_id = $a_id;
00323                 $this->referenced = true;
00324         }
00325 
00331         function getRefId()
00332         {
00333                 return $this->ref_id;
00334         }
00335 
00341         function getType()
00342         {
00343                 return $this->type;
00344         }
00345 
00351         function setType($a_type)
00352         {
00353                 $this->type = $a_type;
00354         }
00355 
00361         function getTitle()
00362         {
00363                 return $this->title;
00364         }
00365 
00372         function setTitle($a_title)
00373         {
00374                 if ($a_title == "")
00375                 {
00376                         $a_title = "NO TITLE";
00377                 }
00378 
00379                 $this->title = ilUtil::shortenText($a_title, $this->max_title, $this->add_dots);
00380         }
00381 
00388         function getDescription()
00389         {
00390                 return $this->desc;
00391         }
00392 
00399         function setDescription($a_desc)
00400         {
00401                 // Shortened form is storted in object_data. Long form is stored in object_description
00402                 $this->desc = ilUtil::shortenText($a_desc, $this->max_desc, $this->add_dots);
00403 
00404                 $this->long_desc = $a_desc;
00405 
00406                 return true;
00407         }
00408 
00415         function getLongDescription()
00416         {
00417                 return strlen($this->long_desc) ? $this->long_desc : $this->desc;
00418         }
00419 
00426         function getImportId()
00427         {
00428                 return $this->import_id;
00429         }
00430 
00437         function setImportId($a_import_id)
00438         {
00439                 $this->import_id = $a_import_id;
00440         }
00441 
00442         function _lookupObjIdByImportId($a_import_id)
00443         {
00444                 global $ilDB;
00445 
00446                 $query = "SELECT * FROM object_data ".
00447                         "WHERE import_id = ".$ilDB->quote($a_import_id)." ".
00448                         "ORDER BY create_date DESC";
00449                 $res = $ilDB->query($query);
00450                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00451                 {
00452                         return $row->obj_id;
00453                 }
00454                 return 0;
00455         }
00456 
00463         function getOwner()
00464         {
00465                 return $this->owner;
00466         }
00467 
00468         /*
00469         * get full name of object owner
00470         *
00471         * @access       public
00472         * @return       string  owner name or unknown
00473         */
00474         function getOwnerName()
00475         {
00476                 return ilObject::_lookupOwnerName($this->getOwner());
00477         }
00478 
00482         function _lookupOwnerName($a_owner_id)
00483         {
00484                 global $lng;
00485 
00486                 if ($a_owner_id != -1)
00487                 {
00488                         if (ilObject::_exists($a_owner_id))
00489                         {
00490                                 $owner = new ilObjUser($a_owner_id);
00491                         }
00492                 }
00493 
00494                 if (is_object($owner))
00495                 {
00496                         $own_name = $owner->getFullname();
00497                 }
00498                 else
00499                 {
00500                         $own_name = $lng->txt("unknown");
00501                 }
00502 
00503                 return $own_name;
00504         }
00505 
00512         function setOwner($a_owner)
00513         {
00514                 $this->owner = $a_owner;
00515         }
00516 
00517 
00518 
00524         function getCreateDate()
00525         {
00526                 return $this->create_date;
00527         }
00528 
00534         function getLastUpdateDate()
00535         {
00536                 return $this->last_update;
00537         }
00538 
00547         function setObjDataRecord($a_record)
00548         {
00549                 $this->obj_data_record = $a_record;
00550         }
00551 
00560         function create()
00561         {
00562                 global $ilDB, $log,$ilUser,$objDefinition;
00563 
00564                 if (!isset($this->type))
00565                 {
00566                         $message = get_class($this)."::create(): No object type given!";
00567                         $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00568                 }
00569 
00570                 // write log entry
00571                 $log->write("ilObject::create(), start");
00572 
00573                 $this->title = ilUtil::shortenText($this->getTitle(), $this->max_title, $this->add_dots);
00574                 $this->desc = ilUtil::shortenText($this->getDescription(), $this->max_desc, $this->add_dots);
00575                 
00576                 // determine owner
00577                 if ($this->getOwner() > 0)
00578                 {
00579                         $owner = $this->getOwner();
00580                 }
00581                 elseif(is_object($ilUser))
00582                 {
00583                         $owner = $ilUser->getId();
00584                 }
00585                 else
00586                 {
00587                         $owner = 0;
00588                 }
00589                 $q = "INSERT INTO object_data ".
00590                          "(type,title,description,owner,create_date,last_update,import_id) ".
00591                          "VALUES ".
00592                          "(".
00593                          $ilDB->quote($this->type).",".
00594                          $ilDB->quote($this->getTitle()).",".
00595                          $ilDB->quote($this->getDescription()).",".
00596                          $ilDB->quote($owner).",now(),now(),".
00597                          $ilDB->quote($this->getImportId()).")";
00598 
00599                 $ilDB->query($q);
00600 
00601                 $this->id = $ilDB->getLastInsertId();
00602 
00603 
00604                 
00605                 // Save long form of description if is rbac object
00606                 if($objDefinition->isRBACObject($this->getType()))
00607                 {
00608                         $query = "INSERT INTO object_description SET ".
00609                                 "obj_id = ".$ilDB->quote($this->id).",".
00610                                 "description = ".$ilDB->quote($this->getLongDescription());
00611                         
00612                         $ilDB->query($query);
00613                 }
00614                 
00615 
00616                 // the line ($this->read();) messes up meta data handling: meta data,
00617                 // that is not saved at this time, gets lost, so we query for the dates alone
00618                 //$this->read();
00619                 $q = "SELECT last_update, create_date FROM object_data".
00620                          " WHERE obj_id = ".$ilDB->quote($this->id);
00621                 $obj_set = $this->ilias->db->query($q);
00622                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00623                 $this->last_update = $obj_rec["last_update"];
00624                 $this->create_date = $obj_rec["create_date"];
00625 
00626                 // set owner for new objects
00627                 $this->setOwner($owner);
00628 
00629                 // write log entry
00630                 $log->write("ilObject::create(), finished, obj_id: ".$this->id.", type: ".
00631                         $this->type.", title: ".$this->getTitle());
00632 
00633                 return $this->id;
00634         }
00635 
00642         function update()
00643         {
00644                 global $objDefinition, $ilDB;
00645 
00646                 $q = "UPDATE object_data ".
00647                         "SET ".
00648                         "title = ".$ilDB->quote($this->getTitle()).",".
00649                         "description = ".$ilDB->quote($this->getDescription()).", ".
00650                         "import_id = ".$ilDB->quote($this->getImportId()).",".
00651                         "last_update = now() ".
00652                         "WHERE obj_id = ".$ilDB->quote($this->getId());
00653                 $this->ilias->db->query($q);
00654 
00655                 // the line ($this->read();) messes up meta data handling: meta data,
00656                 // that is not saved at this time, gets lost, so we query for the dates alone
00657                 //$this->read();
00658                 $q = "SELECT last_update FROM object_data".
00659                          " WHERE obj_id = ".$ilDB->quote($this->getId());
00660                 $obj_set = $this->ilias->db->query($q);
00661                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00662                 $this->last_update = $obj_rec["last_update"];
00663 
00664                 if($objDefinition->isRBACObject($this->getType()))
00665                 {
00666                         // Update long description
00667                         $res = $this->ilias->db->query("SELECT * FROM object_description WHERE obj_id = ".
00668                                 $ilDB->quote($this->getId()));
00669                         if($res->numRows())
00670                         {
00671                                 $query = "UPDATE object_description SET description = ".
00672                                         $ilDB->quote($this->getLongDescription())." ".
00673                                         "WHERE obj_id = ".$ilDB->quote($this->getId());
00674                         }
00675                         else
00676                         {
00677                                 $query = "INSERT INTO object_description SET obj_id = ".$ilDB->quote($this->getId()).", ".
00678                                         "description = ".$ilDB->quote($this->getLongDescription());
00679                         }
00680                         $this->ilias->db->query($query);
00681                 }               
00682 
00683                 return true;
00684         }
00685 
00697         function MDUpdateListener($a_element)
00698         {
00699                 include_once 'Services/MetaData/classes/class.ilMD.php';
00700 
00701                 switch($a_element)
00702                 {
00703                         case 'General':
00704 
00705                                 // Update Title and description
00706                                 $md = new ilMD($this->getId(),0, $this->getType());
00707                                 if(!is_object($md_gen = $md->getGeneral()))
00708                                 {
00709                                         return false;
00710                                 }
00711 
00712                                 ilObject::_writeTitle($this->getId(),$md_gen->getTitle());
00713                                 $this->setTitle($md_gen->getTitle());
00714 
00715                                 foreach($md_gen->getDescriptionIds() as $id)
00716                                 {
00717                                         $md_des = $md_gen->getDescription($id);
00718                                         ilObject::_writeDescription($this->getId(),$md_des->getDescription());
00719                                         $this->setDescription($md_des->getDescription());
00720                                         break;
00721                                 }
00722 
00723                                 break;
00724 
00725                         default:
00726                 }
00727                 return true;
00728         }
00729 
00733         function createMetaData()
00734         {
00735                 include_once 'Services/MetaData/classes/class.ilMDCreator.php';
00736 
00737                 global $ilUser;
00738 
00739                 $md_creator = new ilMDCreator($this->getId(),0,$this->getType());
00740                 $md_creator->setTitle($this->getTitle());
00741                 $md_creator->setTitleLanguage($ilUser->getPref('language'));
00742                 $md_creator->setDescription($this->getLongDescription());
00743                 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
00744                 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
00745                 $md_creator->setLanguage($ilUser->getPref('language'));
00746                 $md_creator->create();
00747 
00748                 return true;
00749         }
00750 
00754         function updateMetaData()
00755         {
00756                 include_once("Services/MetaData/classes/class.ilMD.php");
00757                 include_once("Services/MetaData/classes/class.ilMDGeneral.php");
00758                 include_once("Services/MetaData/classes/class.ilMDDescription.php");
00759 
00760                 $md =& new ilMD($this->getId(), 0, $this->getType());
00761                 $md_gen =& $md->getGeneral();
00762                 $md_gen->setTitle($this->getTitle());
00763 
00764                 // sets first description (maybe not appropriate)
00765                 $md_des_ids =& $md_gen->getDescriptionIds();
00766                 if (count($md_des_ids) > 0)
00767                 {
00768                         $md_des =& $md_gen->getDescription($md_des_ids[0]);
00769                         $md_des->setDescription($this->getLongDescription());
00770                         $md_des->update();
00771                 }
00772                 $md_gen->update();
00773 
00774         }
00775 
00779         function deleteMetaData()
00780         {
00781                 // Delete meta data
00782                 include_once('Services/MetaData/classes/class.ilMD.php');
00783                 $md = new ilMD($this->getId(), 0, $this->getType());
00784                 $md->deleteAll();
00785         }
00786 
00793     function updateOwner()
00794     {
00795                 global $ilDB;
00796                 
00797         $q = "UPDATE object_data ".
00798             "SET ".
00799             "owner = ".$ilDB->quote($this->getOwner()).", ".
00800             "last_update = now() ".
00801             "WHERE obj_id = ".$ilDB->quote($this->getId());
00802         $this->ilias->db->query($q);
00803 
00804         $q = "SELECT last_update FROM object_data".
00805              " WHERE obj_id = ".$ilDB->quote($this->getId());
00806         $obj_set = $this->ilias->db->query($q);
00807         $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
00808         $this->last_update = $obj_rec["last_update"];
00809 
00810         return true;
00811     }
00812 
00820         function _getIdForImportId($a_import_id)
00821         {
00822                 global $ilDB;
00823                 
00824                 $q = "SELECT * FROM object_data WHERE import_id = ".$ilDB->quote($a_import_id).
00825                         " ORDER BY create_date DESC LIMIT 1";
00826                 $obj_set = $ilDB->query($q);
00827 
00828                 if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00829                 {
00830                         return $obj_rec["obj_id"];
00831                 }
00832                 else
00833                 {
00834                         return 0;
00835                 }
00836         }
00837 
00843         function _getAllReferences($a_id)
00844         {
00845                 global $ilDB;
00846 
00847                 $q = "SELECT * FROM object_reference WHERE obj_id = ".
00848                         $ilDB->quote($a_id);
00849                 $obj_set = $ilDB->query($q);
00850                 $ref = array();
00851 
00852                 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
00853                 {
00854                         $ref[$obj_rec["ref_id"]] = $obj_rec["ref_id"];
00855                 }
00856 
00857                 return $ref;
00858         }
00859 
00865         function _lookupTitle($a_id)
00866         {
00867                 global $ilObjDataCache;
00868 
00869                 $tit = $ilObjDataCache->lookupTitle($a_id);
00870 //echo "<br>LOOKING-$a_id-:$tit";               
00871                 return $tit;
00872         }
00873 
00879         function _lookupDescription($a_id)
00880         {
00881                 global $ilObjDataCache;
00882 
00883                 return $ilObjDataCache->lookupDescription($a_id);
00884         }
00885 
00891         function _lookupLastUpdate($a_id, $a_as_string = false)
00892         {
00893                 global $ilObjDataCache;
00894                 
00895                 if ($a_as_string)
00896                 {
00897                         include_once("classes/class.ilFormat.php");
00898                         return ilFormat::formatDate($ilObjDataCache->lookupLastUpdate($a_id), "datetime", true);
00899                 }
00900                 else
00901                 {
00902                         return $ilObjDataCache->lookupLastUpdate($a_id);
00903                 }
00904         }
00905 
00906         function _lookupObjId($a_id)
00907         {
00908                 global $ilObjDataCache;
00909 
00910                 return (int) $ilObjDataCache->lookupObjId($a_id);
00911         }
00912         
00916         function _setDeletedDate($a_ref_id)
00917         {
00918                 global $ilDB;
00919                 
00920                 $q = "UPDATE object_reference SET deleted=now() ".
00921                         "WHERE ref_id = ".$ilDB->quote($a_ref_id);
00922                 $ilDB->query($q);
00923         }
00924 
00928         function _resetDeletedDate($a_ref_id)
00929         {
00930                 global $ilDB;
00931                 
00932                 $q = "UPDATE object_reference SET deleted= ".$ilDB->quote("0000-00-00 00:00:00").
00933                         " WHERE ref_id = ".$ilDB->quote($a_ref_id);
00934                 $ilDB->query($q);
00935         }
00936 
00944         function _writeTitle($a_obj_id, $a_title)
00945         {
00946                 global $ilDB;
00947 
00948                 $q = "UPDATE object_data ".
00949                         "SET ".
00950                         "title = ".$ilDB->quote($a_title).",".
00951                         "last_update = now() ".
00952                         "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00953 
00954                 $ilDB->query($q);
00955         }
00956 
00964         function _writeDescription($a_obj_id, $a_desc)
00965         {
00966                 global $ilDB,$objDefinition;
00967 
00968 
00969                 $desc = ilUtil::shortenText($a_desc,MAXLENGTH_OBJ_DESC,true);
00970 
00971                 $q = "UPDATE object_data ".
00972                         "SET ".
00973                         "description = ".$ilDB->quote($desc).",".
00974                         "last_update = now() ".
00975                         "WHERE obj_id = ".$ilDB->quote($a_obj_id);
00976 
00977                 $ilDB->query($q);
00978 
00979                 if($objDefinition->isRBACObject($this->getType()))
00980                 {
00981                         // Update long description
00982                         $res = $ilDB->query("SELECT * FROM object_description WHERE obj_id = ".
00983                                 $ilDB->quote($a_obj_id));
00984                         if($res->numRows())
00985                         {
00986                                 $query = "UPDATE object_description SET description = ".
00987                                         $ilDB->quote($a_desc)." ".
00988                                         "WHERE obj_id = ".$ilDB->quote($this->getId());
00989                         }
00990                         else
00991                         {
00992                                 $query = "INSERT INTO object_description SET obj_id = ".
00993                                         $ilDB->quote($this->getId()).", ".
00994                                         "description = ".$ilDB->quote($a_desc);
00995                         }
00996                         $ilDB->query($query);
00997                 }
00998         }
00999 
01007         function _writeImportId($a_obj_id, $a_import_id)
01008         {
01009                 global $ilDB;
01010 
01011                 $q = "UPDATE object_data ".
01012                         "SET ".
01013                         "import_id = ".$ilDB->quote($a_import_id).",".
01014                         "last_update = now() ".
01015                         "WHERE obj_id = ".$ilDB->quote($a_obj_id);
01016 
01017                 $ilDB->query($q);
01018         }
01019 
01025         function _lookupType($a_id,$a_reference = false)
01026         {
01027                 global $ilObjDataCache;
01028 
01029                 if($a_reference)
01030                 {
01031                         return $ilObjDataCache->lookupType($ilObjDataCache->lookupObjId($a_id));
01032                 }
01033                 return $ilObjDataCache->lookupType($a_id);
01034 
01035                 global $ilDB;
01036 
01037                 if ($a_reference === true)
01038                 {
01039                         $q = "SELECT type FROM object_reference as obr, object_data as obd ".
01040                                 "WHERE obr.ref_id = ".$ilDB->quote($a_id)." ".
01041                                 "AND obr.obj_id = obd.obj_id ";
01042                         
01043                         #$q = "SELECT type FROM object_data as obj ".
01044                         #        "LEFT JOIN object_reference as ref ON ref.obj_id=obj.obj_id ".
01045                         #        "WHERE ref.ref_id = '".$a_id."'";
01046                 }
01047                 else
01048                 {
01049                         $q = "SELECT type FROM object_data WHERE obj_id = ".$ilDB->quote($a_id);
01050                 }
01051 
01052                 $obj_set = $ilDB->query($q);
01053                 $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
01054 
01055                 return $obj_rec["type"];
01056         }
01057 
01061         function _isInTrash($a_ref_id)
01062         {
01063                 global $tree;
01064 
01065                 return $tree->isSaved($a_ref_id);
01066         }
01067 
01071         function _hasUntrashedReference($a_obj_id)
01072         {
01073                 $ref_ids  = ilObject::_getAllReferences($a_obj_id);
01074                 foreach($ref_ids as $ref_id)
01075                 {
01076                         if(!ilObject::_isInTrash($ref_id))
01077                         {
01078                                 return true;
01079                         }
01080                 }
01081 
01082                 return false;
01083         }
01084 
01090         function _lookupObjectId($a_ref_id)
01091         {
01092                 global $ilObjDataCache;
01093 
01094                 return (int) $ilObjDataCache->lookupObjId($a_ref_id);
01095         }
01096 
01107         function _getObjectsDataForType($a_type, $a_omit_trash = false)
01108         {
01109                 global $ilDB;
01110 
01111                 $q = "SELECT * FROM object_data WHERE type = ".$ilDB->quote($a_type);
01112                 $obj_set = $ilDB->query($q);
01113 
01114                 $objects = array();
01115                 while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
01116                 {
01117                         if ((!$a_omit_trash) || ilObject::_hasUntrashedReference($obj_rec["obj_id"]))
01118                         {
01119                                 $objects[$obj_rec["title"].".".$obj_rec["obj_id"]] = array("id" => $obj_rec["obj_id"],
01120                                         "type" => $obj_rec["type"], "title" => $obj_rec["title"],
01121                                         "description" => $obj_rec["description"]);
01122                         }
01123                 }
01124                 ksort($objects);
01125                 return $objects;
01126         }
01127 
01133         function putInTree($a_parent_ref)
01134         {
01135                 global $tree, $log;
01136 
01137                 $tree->insertNode($this->getRefId(), $a_parent_ref);
01138                 
01139                 // write log entry
01140                 $log->write("ilObject::putInTree(), parent_ref: $a_parent_ref, ref_id: ".
01141                         $this->getRefId().", obj_id: ".$this->getId().", type: ".
01142                         $this->getType().", title: ".$this->getTitle());
01143 
01144         }
01145 
01152         function setPermissions($a_parent_ref)
01153         {
01154                 global $rbacadmin, $rbacreview;
01155 
01156                 $parentRoles = $rbacreview->getParentRoleIds($a_parent_ref);
01157 
01158                 foreach ($parentRoles as $parRol)
01159                 {
01160                         $ops = $rbacreview->getOperationsOfRole($parRol["obj_id"], $this->getType(), $parRol["parent"]);
01161                         $rbacadmin->grantPermission($parRol["obj_id"], $ops, $this->getRefId());
01162                 }
01163         }
01164 
01171         function createReference()
01172         {
01173                 global $ilDB;
01174 
01175                 if (!isset($this->id))
01176                 {
01177                         $message = "ilObject::createNewReference(): No obj_id given!";
01178                         $this->raiseError($message,$this->ilias->error_obj->WARNING);
01179                 }
01180 
01181                 $q = "INSERT INTO object_reference ".
01182                          "(obj_id) VALUES (".$ilDB->quote($this->id).")";
01183                 $this->ilias->db->query($q);
01184 
01185                 $this->ref_id = $ilDB->getLastInsertId();
01186                 $this->referenced = true;
01187 
01188                 return $this->ref_id;
01189         }
01190 
01191 
01198         function countReferences()
01199         {
01200                 if (!isset($this->id))
01201                 {
01202                         $message = "ilObject::countReferences(): No obj_id given!";
01203                         $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
01204                 }
01205 
01206                 $q = "SELECT COUNT(ref_id) AS num FROM object_reference ".
01207                         "WHERE obj_id = '".$this->id."'";
01208                 $row = $this->ilias->db->getRow($q);
01209 
01210                 return $row->num;
01211         }
01212 
01213 
01214 
01215 
01225         function delete()
01226         {
01227                 global $rbacadmin, $log, $ilDB;
01228 
01229                 $remove = false;
01230 
01231                 // delete object_data entry
01232                 if ((!$this->referenced) || ($this->countReferences() == 1))
01233                 {
01234                         // check type match
01235                         $db_type = ilObject::_lookupType($this->getId());
01236                         if ($this->type != $db_type)
01237                         {
01238                                 $message = "ilObject::delete(): Type mismatch. Object with obj_id: ".$this->id." ".
01239                                         "was instantiated by type '".$this->type."'. DB type is: ".$db_type;
01240                                         
01241                                 // write log entry
01242                                 $log->write($message);
01243                                         
01244                                 // raise error
01245                                 $this->ilias->raiseError("ilObject::delete(): Type mismatch. (".$this->type."/".$this->id.")",$this->ilias->error_obj->WARNING);
01246                         }
01247 
01248                         // delete entry in object_data
01249                         $q = "DELETE FROM object_data ".
01250                                 "WHERE obj_id = ".$ilDB->quote($this->getId());
01251                         $this->ilias->db->query($q);
01252 
01253                         // delete long description
01254                         $query = "DELETE FROM object_description WHERE obj_id = ".
01255                                 $ilDB->quote($this->getId());
01256                         $this->ilias->db->query($query);
01257 
01258                         // write log entry
01259                         $log->write("ilObject::delete(), deleted object, obj_id: ".$this->getId().", type: ".
01260                                 $this->getType().", title: ".$this->getTitle());
01261                         
01262                         $remove = true;
01263                 }
01264                 else
01265                 {
01266                         // write log entry
01267                         $log->write("ilObject::delete(), object not deleted, number of references: ".
01268                                 $this->countReferences().", obj_id: ".$this->getId().", type: ".
01269                                 $this->getType().", title: ".$this->getTitle());
01270                 }
01271 
01272                 // delete object_reference entry
01273                 if ($this->referenced)
01274                 {
01275                         // delete entry in object_reference
01276                         $q = "DELETE FROM object_reference ".
01277                                 "WHERE ref_id = ".$ilDB->quote($this->getRefId());
01278                         $this->ilias->db->query($q);
01279 
01280                         // write log entry
01281                         $log->write("ilObject::delete(), reference deleted, ref_id: ".$this->getRefId().
01282                                 ", obj_id: ".$this->getId().", type: ".
01283                                 $this->getType().", title: ".$this->getTitle());
01284 
01285                         // DELETE PERMISSION ENTRIES IN RBAC_PA
01286                         // DONE: method overwritten in ilObjRole & ilObjUser.
01287                         // this call only applies for objects in rbac (not usr,role,rolt)
01288                         // TODO: Do this for role templates too
01289                         $rbacadmin->revokePermission($this->getRefId(),0,false);
01290 
01291                         // Remove desktop items
01292                         ilUtil::removeItemFromDesktops($this->getRefId());
01293                 }
01294 
01295                 // remove conditions
01296                 if ($this->referenced)
01297                 {
01298                         $ch =& new ilConditionHandler();
01299                         $ch->delete($this->getRefId());
01300                         unset($ch);
01301                 }
01302 
01303                 // remove news
01304                 include_once("./Services/News/classes/class.ilNewsItem.php");
01305                 $news_item = new ilNewsItem();
01306                 $news_item->deleteNewsOfContext($this->getId(), $this->getType());
01307                 include_once("./Services/Block/classes/class.ilBlockSetting.php");
01308                 ilBlockSetting::_deleteSettingsOfBlock($this->getId(), "news");
01309 
01310                 return $remove;
01311         }
01312 
01320         function initDefaultRoles()
01321         {
01322                 return array();
01323         }
01324         
01334         function createRoleFolder()
01335         {
01336                 global $rbacreview;
01337                 
01338                 // does a role folder already exists?
01339                 // (this check is only 'to be sure' that no second role folder is created under one object.
01340                 // the if-construct should never return true)
01341                 if ($rolf_data = $rbacreview->getRoleFolderofObject($this->getRefId()))
01342                 {
01343                         $rfoldObj = $this->ilias->obj_factory->getInstanceByRefId($rolf_data["ref_id"]);
01344                 }
01345                 else
01346                 {
01347                         include_once ("classes/class.ilObjRoleFolder.php");
01348                         $rfoldObj = new ilObjRoleFolder();
01349                         $rfoldObj->setTitle($this->getId());
01350                         $rfoldObj->setDescription(" (ref_id ".$this->getRefId().")");
01351                         $rfoldObj->create();
01352                         $rfoldObj->createReference();
01353                         $rfoldObj->putInTree($this->getRefId());
01354                         $rfoldObj->setPermissions($this->getRefId());
01355                 }
01356                 
01357                 return $rfoldObj;
01358         }
01359 
01368         function _exists($a_id, $a_reference = false)
01369         {
01370                 global $ilias, $ilDB;
01371                 
01372                 if ($a_reference)
01373                 {
01374                         $q = "SELECT * FROM object_data ".
01375                                  "LEFT JOIN object_reference ON object_reference.obj_id=object_data.obj_id ".
01376                                  "WHERE object_reference.ref_id= ".$ilDB->quote($a_id);
01377                 }
01378                 else
01379                 {
01380                         $q = "SELECT * FROM object_data WHERE obj_id=".$ilDB->quote($a_id);
01381                 }
01382                 
01383                 $r = $ilDB->query($q);
01384 
01385                 return $r->numRows() ? true : false;
01386         }
01387 
01400         function notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$a_node_id,$a_params = 0)
01401         { 
01402                 global $tree;
01403                 
01404                 $parent_id = (int) $tree->getParentId($a_node_id);
01405                 
01406                 if ($parent_id != 0)
01407                 {
01408                         $obj_data =& $this->ilias->obj_factory->getInstanceByRefId($a_node_id);
01409                         $obj_data->notify($a_event,$a_ref_id,$a_parent_non_rbac_id,$parent_id,$a_params);
01410                 }
01411                                 
01412                 return true;
01413         }
01414         
01415         // toggle subscription interface
01416         function setRegisterMode($a_bool)
01417         {
01418                 $this->register = (bool) $a_bool;
01419         }
01420         
01421         // check register status of current user
01422         // abstract method; overwrite in object type class
01423         function isUserRegistered($a_user_id = 0)
01424         {
01425                 return false;
01426         }
01427 
01428         function requireRegistration()
01429         {
01430                 return $this->register;
01431         }
01432 
01433 
01434         function getXMLZip()
01435         {
01436                 return false;
01437         }
01438         function getHTMLDirectory()
01439         {
01440                 return false;
01441         }
01442 
01446         static function _getObjectsByType($a_obj_type = "")
01447         {
01448                 global $ilDB;
01449                 
01450                 $order = " ORDER BY title";
01451 
01452                 // where clause
01453                 if ($a_obj_type)
01454                 {
01455                         $where_clause = "WHERE type = ".
01456                                 $ilDB->quote($a_obj_type);
01457                 }
01458         
01459                 $q = "SELECT * FROM object_data ".$where_clause.$order;
01460                 $r = $ilDB->query($q);
01461         
01462                 $arr = array();
01463                 if ($r->numRows() > 0)
01464                 {
01465                         while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
01466                         {
01467                                 $row["desc"] = $row["description"];
01468                                 $arr[$row["obj_id"]] = $row;
01469                         }
01470                 }
01471         
01472                 return $arr;
01473         }
01474         
01483         public static function _prepareCloneSelection($a_ref_ids,$new_type)
01484         {
01485                 global $ilDB,$lng;
01486                 
01487                 $query = "SELECT obj_data.title as obj_title,path_data.title as path_title,child FROM tree ".
01488                         "JOIN object_reference as obj_ref ON child = obj_ref.ref_id ".
01489                         "JOIN object_data as obj_data ON obj_ref.obj_id = obj_data.obj_id ".
01490                         "JOIN object_reference as path_ref ON parent = path_ref.ref_id ".
01491                         "JOIN object_data as path_data ON path_ref.obj_id = path_data.obj_id ".
01492                         "WHERE child IN (".implode(',',ilUtil::quoteArray($a_ref_ids)).") ".
01493                         "ORDER BY obj_data.title ";
01494                 $res = $ilDB->query($query);
01495                 
01496                 $options[0] = $lng->txt('obj_'.$new_type.'_select');
01497                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
01498                 {
01499                         if(strlen($title = $row->obj_title) > 40)
01500                         {
01501                                 $title = substr($title,0,40).'...';
01502                         }
01503                         if(strlen($path = $row->path_title) > 40)
01504                         {
01505                                 $path = substr($path,0,40).'...';
01506                         }
01507                         
01508                         
01509                         $options[$row->child] = ($title.' ('.$lng->txt('path').': '.$path.')');
01510                 }
01511                 return $options ? $options : array();
01512         }
01513 
01523         public function cloneObject($a_target_id,$a_copy_id = 0)
01524         {
01525                 global $objDefinition,$ilUser,$rbacadmin;
01526                 
01527                 $module = $objDefinition->getModule($this->getType());
01528                 $module_dir = ($module == "")
01529                         ? ""
01530                         : $module."/";
01531                 $class_name = ('ilObj'.$objDefinition->getClassName($this->getType()));
01532                 
01533                 $title = $this->prependCopyInfo($a_copy_id);
01534 
01535                 // create instance
01536                 include_once($module_dir."classes/class.".$class_name.".php");
01537                 $new_obj = new $class_name(0, false);
01538                 $new_obj->setOwner($ilUser->getId());
01539                 $new_obj->setTitle($title);
01540                 $new_obj->setDescription($this->getDescription());
01541                 $new_obj->setType($this->getType());
01542                 // Choose upload mode to avoid creation of additional settings, db entries ...
01543                 $new_obj->create(true);
01544                 $new_obj->createReference();
01545                 $new_obj->putInTree($a_target_id);
01546                 $new_obj->setPermissions($a_target_id);
01547                 $new_obj->initDefaultRoles();
01548                 
01549                 // copy local roles
01550                 $rbacadmin->copyLocalRoles($this->getRefId(),$new_obj->getRefId());
01551                 
01552                 include_once('./Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
01553                 ilAdvancedMDValues::_cloneValues($this->getId(),$new_obj->getId());
01554                 
01555                 return $new_obj;
01556         }
01557         
01565         public function prependCopyInfo($a_copy_id)
01566         {
01567                 global $tree;
01568                 
01569                 include_once('Services/CopyWizard/classes/class.ilCopyWizardOptions.php');
01570                 $cp_options = ilCopyWizardOptions::_getInstance($a_copy_id);
01571                 if(!$cp_options->isRootNode($this->getRefId()))
01572                 {
01573                         return $this->getTitle();
01574                 }
01575                 $nodes = $tree->getChilds($tree->getParentId($this->getRefId()));
01576                 $title_unique = false;
01577                 $title = $this->getTitle();
01578                 $increment = 0;
01579                 while(!$title_unique)
01580                 {
01581                         $found = 0;
01582                         foreach($nodes as $node)
01583                         {
01584                                 if(($title == $node['title']) and ($this->getType() == $node['type']))
01585                                 {
01586                                         $found++;
01587                                 }
01588                         }
01589                         if($found > 0)
01590                         {
01591                                 if(!$increment)
01592                                 {
01593                                         $title = $this->getTitle().' (Copy)';
01594                                         $increment++;
01595                                 }
01596                                 else
01597                                 {
01598                                         $title = ($this->getTitle().' (Copy '.($increment+1).')');
01599                                         $increment++;
01600                                 }
01601                         }
01602                         else
01603                         {
01604                                 break;
01605                         }
01606                 }
01607                 return $title;
01608         }       
01609         
01618         public function cloneDependencies($a_target_id,$a_copy_id)
01619         {
01620                 return true;
01621         }
01622         
01630         public function cloneMetaData($target_obj)
01631         {
01632                 include_once "./Services/MetaData/classes/class.ilMD.php";
01633                 $md = new ilMD($this->getId(),0,$this->getType());
01634                 $md->cloneMD($target_obj->getId(),0,$target_obj->getType());
01635                 return true;            
01636         }
01637         
01638         public function _getIcon($a_obj_id = "", $a_size = "big", $a_type = "",
01639                 $a_offline = false)
01640         {
01641                 global $ilSetting;
01642                 
01643                 if ($a_obj_id == "" && $a_type == "")
01644                 {
01645                         return "";
01646                 }
01647                 
01648                 if ($a_type == "")
01649                 {
01650                         $a_type = ilObject::_lookupType($a_obj_id);
01651                 }
01652                 
01653                 if ($a_size == "")
01654                 {
01655                         $a_size = "big";
01656                 }
01657                 
01658                 if ($ilSetting->get("custom_icons") &&
01659                         in_array($a_type, array("cat","grp","crs", "root")))
01660                 {
01661                         require_once("classes/class.ilContainer.php");
01662                         if (ilContainer::_lookupContainerSetting($a_obj_id, "icon_".$a_size))
01663                         {
01664                                 $cont_dir = ilContainer::_getContainerDirectory($a_obj_id);
01665                                 $file_name = $cont_dir."/icon_".$a_size.".gif";
01666         
01667                                 if (is_file($file_name))
01668                                 {
01669                                         return $file_name;
01670                                 }
01671                         }
01672                 }
01673                 
01674                 switch($a_size)
01675                 {
01676                         case "small": $suff = ""; break;
01677                         case "tiny": $suff = "_s"; break;
01678                         default: $suff = "_b"; break;
01679                 }
01680                 
01681                 if (!$a_offline)
01682                 {
01683                         return ilUtil::getImagePath("icon_".$a_type.$suff.".gif");
01684                 }
01685                 else
01686                 {
01687                         return "./images/icon_".$a_type.$suff.".gif";
01688                 }
01689         }
01690 
01691 } // END class.ilObject
01692 ?>

Generated on Fri Dec 13 2013 17:56:47 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1