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

classes/class.ilObjectDataCache.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 
00034 class ilObjectDataCache
00035 {
00036         var $db = null;
00037         var $reference_cache = array();
00038         var $object_data_cache = array();
00039 
00040         function ilObjectDataCache()
00041         {
00042                 global $ilDB;
00043 
00044                 $this->db =& $ilDB;
00045         }
00046 
00047         function deleteCachedEntry($a_obj_id)
00048         {
00049                 unset($this->object_data_cache[$a_obj_id]);
00050         }
00051 
00052         function lookupObjId($a_ref_id)
00053         {
00054                 if(!$this->__isReferenceCached($a_ref_id))
00055                 {
00056                         $obj_id = $this->__storeReference($a_ref_id);
00057                         $this->__storeObjectData($obj_id);
00058                 }
00059                 return (int) @$this->reference_cache[$a_ref_id];
00060         }
00061 
00062         function lookupTitle($a_obj_id)
00063         {
00064                 if(!$this->__isObjectCached($a_obj_id))
00065                 {
00066                         $this->__storeObjectData($a_obj_id);
00067                 }
00068                 return @$this->object_data_cache[$a_obj_id]['title'];
00069         }
00070 
00071         function lookupType($a_obj_id)
00072         {
00073                 if(!$this->__isObjectCached($a_obj_id))
00074                 {
00075                         $this->__storeObjectData($a_obj_id);
00076                 }
00077                 return @$this->object_data_cache[$a_obj_id]['type'];
00078         }
00079 
00080         function lookupOwner($a_obj_id)
00081         {
00082                 if(!$this->__isObjectCached($a_obj_id))
00083                 {
00084                         $this->__storeObjectData($a_obj_id);
00085                 }
00086                 return @$this->object_data_cache[$a_obj_id]['owner'];
00087         }
00088 
00089         function lookupDescription($a_obj_id)
00090         {
00091                 if(!$this->__isObjectCached($a_obj_id))
00092                 {
00093                         $this->__storeObjectData($a_obj_id);
00094                 }
00095                 return @$this->object_data_cache[$a_obj_id]['description'];
00096         }
00097 
00098         function lookupLastUpdate($a_obj_id)
00099         {
00100                 if(!$this->__isObjectCached($a_obj_id))
00101                 {
00102                         $this->__storeObjectData($a_obj_id);
00103                 }
00104                 return @$this->object_data_cache[$a_obj_id]['last_update'];
00105         }
00106         // PRIVATE
00107 
00115         function __isReferenceCached($a_ref_id)
00116         {
00117                 #return false;
00118                 #static $cached = 0;
00119                 #static $not_cached = 0;
00120 
00121                 if(@$this->reference_cache[$a_ref_id])
00122                 {
00123                         #echo "Reference ". ++$cached ."cached<br>";
00124                         return true;
00125                 }
00126                 #echo "Reference ". ++$not_cached ." not cached<br>";
00127                 return false;
00128                 
00129         }
00130 
00138         function __isObjectCached($a_obj_id)
00139         {
00140                 static $cached = 0;
00141                 static $not_cached = 0;
00142                         
00143 
00144                 if(@$this->object_data_cache[$a_obj_id])
00145                 {
00146                         #echo "Object ". ++$cached ."cached<br>";
00147                         return true;
00148                 }
00149                 #echo "Object ". ++$not_cached ." not cached<br>";
00150                 return false;
00151         }
00152 
00153 
00163         function __storeReference($a_ref_id)
00164         {
00165                 global $ilDB;
00166                 
00167                 $query = "SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($a_ref_id);
00168                 $res = $this->db->query($query);
00169                 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00170                 {
00171                         $this->reference_cache[$a_ref_id] = $row['obj_id'];
00172                 }
00173                 return (int) @$this->reference_cache[$a_ref_id];
00174         }
00175 
00183         function __storeObjectData($a_obj_id)
00184         {
00185                 $query = "SELECT * FROM object_data WHERE obj_id = '".$a_obj_id."'";
00186                 $res = $this->db->query($query);
00187                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00188                 {
00189                         $this->object_data_cache[$a_obj_id]['title'] = $row->title;
00190                         $this->object_data_cache[$a_obj_id]['description'] = $row->description;
00191                         $this->object_data_cache[$a_obj_id]['type'] = $row->type;
00192                         $this->object_data_cache[$a_obj_id]['owner'] = $row->owner;
00193                         $this->object_data_cache[$a_obj_id]['last_update'] = $row->last_update;
00194 
00195                 }
00196                 return true;
00197         }
00198 }
00199 ?>

Generated on Fri Dec 13 2013 11:57:54 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1