Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
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 ?>