ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
ilObjectDataCache Class Reference

class ilObjectDataCache More...

+ Collaboration diagram for ilObjectDataCache:

Public Member Functions

 ilObjectDataCache ()
 
 deleteCachedEntry ($a_obj_id)
 
 lookupObjId ($a_ref_id)
 
 lookupTitle ($a_obj_id)
 
 lookupType ($a_obj_id)
 
 lookupOwner ($a_obj_id)
 
 lookupDescription ($a_obj_id)
 
 lookupLastUpdate ($a_obj_id)
 
 __isReferenceCached ($a_ref_id)
 checks whether an reference id is already in cache or not More...
 
 __isObjectCached ($a_obj_id)
 checks whether an object is aleady in cache or not More...
 
 __storeReference ($a_ref_id)
 Stores Reference in cache. More...
 
 __storeObjectData ($a_obj_id, $a_lang="")
 Stores object data in cache. More...
 
 isTranslatedDescription ($a_obj_id)
 
 preloadObjectCache ($a_obj_ids, $a_lang="")
 Stores object data in cache. More...
 
 preloadTranslations ($a_obj_ids, $a_lang)
 Preload translation informations. More...
 
 preloadReferenceCache ($a_ref_ids, $a_incl_obj=true)
 

Data Fields

 $db = null
 
 $reference_cache = array()
 
 $object_data_cache = array()
 
 $description_trans = array()
 

Detailed Description

class ilObjectDataCache

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

This class caches some properties of the object_data table. Like title description owner obj_id

Definition at line 13 of file class.ilObjectDataCache.php.

Member Function Documentation

◆ __isObjectCached()

ilObjectDataCache::__isObjectCached (   $a_obj_id)

checks whether an object is aleady in cache or not

@access private

Parameters
int$a_obj_idobject id
Returns
boolean

Definition at line 120 of file class.ilObjectDataCache.php.

121 {
122 static $cached = 0;
123 static $not_cached = 0;
124
125
126 if(@$this->object_data_cache[$a_obj_id])
127 {
128 #echo "Object ". ++$cached ."cached<br>";
129 return true;
130 }
131 #echo "Object ". ++$not_cached ." not cached<br>";
132 return false;
133 }

Referenced by lookupDescription(), lookupLastUpdate(), lookupOwner(), lookupTitle(), and lookupType().

+ Here is the caller graph for this function:

◆ __isReferenceCached()

ilObjectDataCache::__isReferenceCached (   $a_ref_id)

checks whether an reference id is already in cache or not

@access private

Parameters
int$a_ref_idreference id
Returns
boolean

Definition at line 97 of file class.ilObjectDataCache.php.

98 {
99 #return false;
100 #static $cached = 0;
101 #static $not_cached = 0;
102
103 if(@$this->reference_cache[$a_ref_id])
104 {
105 #echo "Reference ". ++$cached ."cached<br>";
106 return true;
107 }
108 #echo "Reference ". ++$not_cached ." not cached<br>";
109 return false;
110
111 }

Referenced by lookupObjId().

+ Here is the caller graph for this function:

◆ __storeObjectData()

ilObjectDataCache::__storeObjectData (   $a_obj_id,
  $a_lang = "" 
)

Stores object data in cache.

@access private

Parameters
int$a_obj_idobject id
Returns
bool

Definition at line 165 of file class.ilObjectDataCache.php.

166 {
167 global $ilDB, $objDefinition, $ilUser;
168
169 if (is_object($ilUser) && $a_lang == "")
170 {
171 $a_lang = $ilUser->getLanguage();
172 }
173
174 $query = "SELECT * FROM object_data WHERE obj_id = ".
175 $ilDB->quote($a_obj_id ,'integer');
176 $res = $this->db->query($query);
177 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
178 {
179 $this->object_data_cache[$a_obj_id]['title'] = $row->title;
180 $this->object_data_cache[$a_obj_id]['description'] = $row->description;
181 $this->object_data_cache[$a_obj_id]['type'] = $row->type;
182 $this->object_data_cache[$a_obj_id]['owner'] = $row->owner;
183 $this->object_data_cache[$a_obj_id]['last_update'] = $row->last_update;
184
185 if (is_object($objDefinition))
186 {
187 $translation_type = $objDefinition->getTranslationType($row->type);
188 }
189
190 if ($translation_type == "db")
191 {
192 if (!$this->trans_loaded[$a_obj_id])
193 {
194 $q = "SELECT title,description FROM object_translation ".
195 "WHERE obj_id = ".$ilDB->quote($a_obj_id,'integer')." ".
196 "AND lang_code = ".$ilDB->quote($a_lang,'text')." ".
197 "AND NOT lang_default = 1";
198 $r = $ilDB->query($q);
199
200 $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
201 if ($row)
202 {
203 $this->object_data_cache[$a_obj_id]['title'] = $row->title;
204 $this->object_data_cache[$a_obj_id]['description'] = $row->description;
205 $this->description_trans[] = $a_obj_id;
206 }
207 $this->trans_loaded[$a_obj_id] = true;
208 }
209 }
210 }
211
212 return true;
213 }
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
$r
Definition: example_031.php:79
global $ilDB
global $ilUser
Definition: imgupload.php:15

References $ilDB, $ilUser, $query, $r, $res, $row, and DB_FETCHMODE_OBJECT.

Referenced by lookupDescription(), lookupLastUpdate(), lookupObjId(), lookupOwner(), lookupTitle(), and lookupType().

+ Here is the caller graph for this function:

◆ __storeReference()

ilObjectDataCache::__storeReference (   $a_ref_id)

Stores Reference in cache.

Maybe it could be useful to find all references of that object andd store them also in the cache. But this would be an extra query.

@access private

Parameters
int$a_ref_idreference id
Returns
int $obj_id

Definition at line 145 of file class.ilObjectDataCache.php.

146 {
147 global $ilDB;
148
149 $query = "SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($a_ref_id,'integer');
150 $res = $this->db->query($query);
151 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
152 {
153 $this->reference_cache[$a_ref_id] = $row['obj_id'];
154 }
155 return (int) @$this->reference_cache[$a_ref_id];
156 }
const DB_FETCHMODE_ASSOC
Definition: class.ilDB.php:10

References $ilDB, $query, $res, $row, and DB_FETCHMODE_ASSOC.

Referenced by lookupObjId().

+ Here is the caller graph for this function:

◆ deleteCachedEntry()

ilObjectDataCache::deleteCachedEntry (   $a_obj_id)

Definition at line 27 of file class.ilObjectDataCache.php.

28 {
29 unset($this->object_data_cache[$a_obj_id]);
30 }

◆ ilObjectDataCache()

ilObjectDataCache::ilObjectDataCache ( )

Definition at line 20 of file class.ilObjectDataCache.php.

21 {
22 global $ilDB;
23
24 $this->db =& $ilDB;
25 }

References $ilDB.

◆ isTranslatedDescription()

ilObjectDataCache::isTranslatedDescription (   $a_obj_id)

Definition at line 215 of file class.ilObjectDataCache.php.

216 {
217 return (is_array($this->description_trans) &&
218 in_array($a_obj_id, $this->description_trans));
219 }

◆ lookupDescription()

ilObjectDataCache::lookupDescription (   $a_obj_id)

Definition at line 71 of file class.ilObjectDataCache.php.

72 {
73 if(!$this->__isObjectCached($a_obj_id))
74 {
75 $this->__storeObjectData($a_obj_id);
76 }
77 return @$this->object_data_cache[$a_obj_id]['description'];
78 }
__isObjectCached($a_obj_id)
checks whether an object is aleady in cache or not
__storeObjectData($a_obj_id, $a_lang="")
Stores object data in cache.

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupLastUpdate()

ilObjectDataCache::lookupLastUpdate (   $a_obj_id)

Definition at line 80 of file class.ilObjectDataCache.php.

81 {
82 if(!$this->__isObjectCached($a_obj_id))
83 {
84 $this->__storeObjectData($a_obj_id);
85 }
86 return @$this->object_data_cache[$a_obj_id]['last_update'];
87 }

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupObjId()

ilObjectDataCache::lookupObjId (   $a_ref_id)

Definition at line 32 of file class.ilObjectDataCache.php.

33 {
34 if(!$this->__isReferenceCached($a_ref_id))
35 {
36//echo"-objidmissed-$a_ref_id-";
37 $obj_id = $this->__storeReference($a_ref_id);
38 $this->__storeObjectData($obj_id);
39 }
40 return (int) @$this->reference_cache[$a_ref_id];
41 }
__isReferenceCached($a_ref_id)
checks whether an reference id is already in cache or not
__storeReference($a_ref_id)
Stores Reference in cache.

References __isReferenceCached(), __storeObjectData(), and __storeReference().

+ Here is the call graph for this function:

◆ lookupOwner()

ilObjectDataCache::lookupOwner (   $a_obj_id)

Definition at line 62 of file class.ilObjectDataCache.php.

63 {
64 if(!$this->__isObjectCached($a_obj_id))
65 {
66 $this->__storeObjectData($a_obj_id);
67 }
68 return @$this->object_data_cache[$a_obj_id]['owner'];
69 }

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupTitle()

ilObjectDataCache::lookupTitle (   $a_obj_id)

Definition at line 43 of file class.ilObjectDataCache.php.

44 {
45 if(!$this->__isObjectCached($a_obj_id))
46 {
47 $this->__storeObjectData($a_obj_id);
48 }
49 return @$this->object_data_cache[$a_obj_id]['title'];
50 }

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupType()

ilObjectDataCache::lookupType (   $a_obj_id)

Definition at line 52 of file class.ilObjectDataCache.php.

53 {
54 if(!$this->__isObjectCached($a_obj_id))
55 {
56//echo"-typemissed-$a_obj_id-";
57 $this->__storeObjectData($a_obj_id);
58 }
59 return @$this->object_data_cache[$a_obj_id]['type'];
60 }

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ preloadObjectCache()

ilObjectDataCache::preloadObjectCache (   $a_obj_ids,
  $a_lang = "" 
)

Stores object data in cache.

@access private

Parameters
int$a_obj_idobject id
Returns
bool

Definition at line 228 of file class.ilObjectDataCache.php.

229 {
230 global $ilDB, $objDefinition, $ilUser, $tree;
231
232 if (is_object($ilUser) && $a_lang == "")
233 {
234 $a_lang = $ilUser->getLanguage();
235 }
236//echo "<br>-preloading-"; var_dump($a_obj_ids);
237 if (!is_array($a_obj_ids)) return;
238 if (count($a_obj_ids) == 0) return;
239
240
241 $query = "SELECT * FROM object_data ".
242 "WHERE ".$ilDB->in('obj_id',$a_obj_ids,false,'integer');
243 $res = $ilDB->query($query);
244 $db_trans = array();
245 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
246 {
247//echo "<br>store_obj-".$row->obj_id."-".$row->type."-".$row->title."-";
248
249 // this if fixes #9960
250 if (!$this->trans_loaded[$row->obj_id])
251 {
252 $this->object_data_cache[$row->obj_id]['title'] = $row->title;
253 $this->object_data_cache[$row->obj_id]['description'] = $row->description;
254 }
255 $this->object_data_cache[$row->obj_id]['type'] = $row->type;
256 $this->object_data_cache[$row->obj_id]['owner'] = $row->owner;
257 $this->object_data_cache[$row->obj_id]['last_update'] = $row->last_update;
258
259 if (is_object($objDefinition))
260 {
261 $translation_type = $objDefinition->getTranslationType($row->type);
262 }
263
264 if ($translation_type == "db")
265 {
266 $db_trans[$row->obj_id] = $row->obj_id;
267 }
268 }
269 if (count($db_trans) > 0)
270 {
271 $this->preloadTranslations($db_trans, $a_lang);
272 }
273 }
preloadTranslations($a_obj_ids, $a_lang)
Preload translation informations.

References $ilDB, $ilUser, $query, $res, $row, DB_FETCHMODE_OBJECT, and preloadTranslations().

Referenced by preloadReferenceCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ preloadReferenceCache()

ilObjectDataCache::preloadReferenceCache (   $a_ref_ids,
  $a_incl_obj = true 
)

Definition at line 310 of file class.ilObjectDataCache.php.

311 {
312 global $ilDB;
313
314 if (!is_array($a_ref_ids)) return;
315 if (count($a_ref_ids) == 0) return;
316
317 $query = "SELECT ref_id, obj_id FROM object_reference ".
318 "WHERE ".$ilDB->in('ref_id',$a_ref_ids,false,'integer');
319 $res = $ilDB->query($query);
320
321 $obj_ids = array();
322 while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
323 {
324 $this->reference_cache[$row['ref_id']] = $row['obj_id'];
325//echo "<br>store_ref-".$row['ref_id']."-".$row['obj_id']."-";
326 $obj_ids[] = $row['obj_id'];
327 }
328 if ($a_incl_obj)
329 {
330 $this->preloadObjectCache($obj_ids);
331 }
332 }
preloadObjectCache($a_obj_ids, $a_lang="")
Stores object data in cache.

References $ilDB, $query, $res, $row, DB_FETCHMODE_ASSOC, and preloadObjectCache().

+ Here is the call graph for this function:

◆ preloadTranslations()

ilObjectDataCache::preloadTranslations (   $a_obj_ids,
  $a_lang 
)

Preload translation informations.

Parameters
array$a_obj_idsarray of object ids

Definition at line 280 of file class.ilObjectDataCache.php.

281 {
282 global $ilDB, $tree;
283
284 $obj_ids = array();
285 foreach ($a_obj_ids as $id)
286 {
287 // do not load an id more than one time
288 if (!$this->trans_loaded[$id])
289 {
290 $obj_ids[] = $id;
291 $this->trans_loaded[$id] = true;
292 }
293 }
294 if (count($obj_ids) > 0)
295 {
296 $q = "SELECT obj_id, title, description FROM object_translation ".
297 "WHERE ".$ilDB->in('obj_id', $obj_ids, false, 'integer')." ".
298 "AND lang_code = ".$ilDB->quote($a_lang, 'text')." ".
299 "AND NOT lang_default = 1";
300 $r = $ilDB->query($q);
301 while ($row2 = $r->fetchRow(DB_FETCHMODE_OBJECT))
302 {
303 $this->object_data_cache[$row2->obj_id]['title'] = $row2->title;
304 $this->object_data_cache[$row2->obj_id]['description'] = $row2->description;
305 $this->description_trans[] = $row2->obj_id;
306 }
307 }
308 }

References $ilDB, $r, and DB_FETCHMODE_OBJECT.

Referenced by preloadObjectCache().

+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilObjectDataCache::$db = null

Definition at line 15 of file class.ilObjectDataCache.php.

◆ $description_trans

ilObjectDataCache::$description_trans = array()

Definition at line 18 of file class.ilObjectDataCache.php.

◆ $object_data_cache

ilObjectDataCache::$object_data_cache = array()

Definition at line 17 of file class.ilObjectDataCache.php.

◆ $reference_cache

ilObjectDataCache::$reference_cache = array()

Definition at line 16 of file class.ilObjectDataCache.php.


The documentation for this class was generated from the following file: