ILIAS  release_7 Revision v7.30-3-g800a261c036
ilObjectDataCache Class Reference

class ilObjectDataCache More...

+ Collaboration diagram for ilObjectDataCache:

Public Member Functions

 __construct ()
 
 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)
 
 lookupOfflineStatus ($a_obj_id)
 Check if supports centralized offline handling and is offline. More...
 
 __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()
 

Protected Attributes

 $trans_loaded = []
 

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.

Constructor & Destructor Documentation

◆ __construct()

ilObjectDataCache::__construct ( )

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

24 {
25 global $DIC;
26
27 $ilDB = $DIC->database();
28
29 $this->db = $ilDB;
30 }
global $DIC
Definition: goto.php:24
global $ilDB

References $DIC, and $ilDB.

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 131 of file class.ilObjectDataCache.php.

132 {
133 static $cached = 0;
134 static $not_cached = 0;
135
136
137 if (@$this->object_data_cache[$a_obj_id]) {
138 #echo "Object ". ++$cached ."cached<br>";
139 return true;
140 }
141 #echo "Object ". ++$not_cached ." not cached<br>";
142 return false;
143 }

Referenced by lookupDescription(), lookupLastUpdate(), lookupOfflineStatus(), 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 110 of file class.ilObjectDataCache.php.

111 {
112 #return false;
113 #static $cached = 0;
114 #static $not_cached = 0;
115
116 if (@$this->reference_cache[$a_ref_id]) {
117 #echo "Reference ". ++$cached ."cached<br>";
118 return true;
119 }
120 #echo "Reference ". ++$not_cached ." not cached<br>";
121 return false;
122 }

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 174 of file class.ilObjectDataCache.php.

175 {
176 global $DIC;
177
179 $objDefinition = $DIC["objDefinition"];
180 $ilUser = $DIC["ilUser"];
181
182 if (is_object($ilUser) && $a_lang == "") {
183 $a_lang = $ilUser->getLanguage();
184 }
185
186 $query = "SELECT object_data.*, object_description.description as long_description " .
187 "FROM object_data LEFT JOIN object_description ON object_data.obj_id = object_description.obj_id " .
188 "WHERE object_data.obj_id = " . $ilDB->quote($a_obj_id, 'integer');
189 $res = $this->db->query($query);
190 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
191 $this->object_data_cache[$a_obj_id]['title'] = $row->title;
192 $this->object_data_cache[$a_obj_id]['description'] = $row->description;
193 if ($row->long_description !== null) {
194 $this->object_data_cache[$a_obj_id]['description'] = $row->long_description;
195 }
196 $this->object_data_cache[$a_obj_id]['type'] = $row->type;
197 $this->object_data_cache[$a_obj_id]['owner'] = $row->owner;
198 $this->object_data_cache[$a_obj_id]['last_update'] = $row->last_update;
199 $this->object_data_cache[$a_obj_id]['offline'] = $row->offline;
200
201 if (is_object($objDefinition)) {
202 $translation_type = $objDefinition->getTranslationType($row->type);
203 }
204
205 if ($translation_type == "db") {
206 if (!$this->trans_loaded[$a_obj_id]) {
207 $q = "SELECT title,description FROM object_translation " .
208 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
209 "AND lang_code = " . $ilDB->quote($a_lang, 'text');
210 $r = $ilDB->query($q);
211
212 $row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
213 if ($row) {
214 $this->object_data_cache[$a_obj_id]['title'] = $row->title;
215 $this->object_data_cache[$a_obj_id]['description'] = $row->description;
216 $this->description_trans[] = $a_obj_id;
217 }
218 $this->trans_loaded[$a_obj_id] = true;
219 }
220 }
221 }
222
223 return true;
224 }
$ilUser
Definition: imgupload.php:18
$query
foreach($_POST as $key=> $value) $res

References $db, $DIC, $ilDB, $ilUser, $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by lookupDescription(), lookupLastUpdate(), lookupObjId(), lookupOfflineStatus(), 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 155 of file class.ilObjectDataCache.php.

156 {
158
159 $query = "SELECT obj_id FROM object_reference WHERE ref_id = " . $ilDB->quote($a_ref_id, 'integer');
160 $res = $this->db->query($query);
161 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
162 $this->reference_cache[$a_ref_id] = $row['obj_id'];
163 }
164 return (int) @$this->reference_cache[$a_ref_id];
165 }

References $db, $ilDB, $query, $res, and ilDBConstants\FETCHMODE_ASSOC.

Referenced by lookupObjId().

+ Here is the caller graph for this function:

◆ deleteCachedEntry()

ilObjectDataCache::deleteCachedEntry (   $a_obj_id)

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

33 {
34 unset($this->object_data_cache[$a_obj_id]);
35 }

◆ isTranslatedDescription()

ilObjectDataCache::isTranslatedDescription (   $a_obj_id)

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

227 {
228 return (is_array($this->description_trans) &&
229 in_array($a_obj_id, $this->description_trans));
230 }

◆ lookupDescription()

ilObjectDataCache::lookupDescription (   $a_obj_id)

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

73 {
74 if (!$this->__isObjectCached($a_obj_id)) {
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 $this->__storeObjectData($a_obj_id);
84 }
85 return @$this->object_data_cache[$a_obj_id]['last_update'];
86 }

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupObjId()

ilObjectDataCache::lookupObjId (   $a_ref_id)

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

38 {
39 if (!$this->__isReferenceCached($a_ref_id)) {
40 //echo"-objidmissed-$a_ref_id-";
41 $obj_id = $this->__storeReference($a_ref_id);
42 $this->__storeObjectData($obj_id);
43 }
44 return (int) @$this->reference_cache[$a_ref_id];
45 }
__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:

◆ lookupOfflineStatus()

ilObjectDataCache::lookupOfflineStatus (   $a_obj_id)

Check if supports centralized offline handling and is offline.

Parameters
$a_obj_id
Returns
bool

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

94 {
95 if (!$this->__isObjectCached($a_obj_id)) {
96 $this->__storeObjectData($a_obj_id);
97 }
98 return (bool) $this->object_data_cache[$a_obj_id]['offline'];
99 }

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupOwner()

ilObjectDataCache::lookupOwner (   $a_obj_id)

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

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

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupTitle()

ilObjectDataCache::lookupTitle (   $a_obj_id)

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

48 {
49 if (!$this->__isObjectCached($a_obj_id)) {
50 $this->__storeObjectData($a_obj_id);
51 }
52 return @$this->object_data_cache[$a_obj_id]['title'];
53 }

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupType()

ilObjectDataCache::lookupType (   $a_obj_id)

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

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

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 239 of file class.ilObjectDataCache.php.

240 {
241 global $DIC;
242
244 $objDefinition = $DIC["objDefinition"];
245 $ilUser = $DIC["ilUser"];
246
247 if (is_object($ilUser) && $a_lang == "") {
248 $a_lang = $ilUser->getLanguage();
249 }
250 if (!is_array($a_obj_ids)) {
251 return;
252 }
253 if (count($a_obj_ids) == 0) {
254 return;
255 }
256
257 $query = "SELECT object_data.*, object_description.description as long_description " .
258 "FROM object_data LEFT JOIN object_description ON object_data.obj_id = object_description.obj_id " .
259 "WHERE " . $ilDB->in('object_data.obj_id', $a_obj_ids, false, 'integer');
260 $res = $ilDB->query($query);
261 $db_trans = array();
262 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
263
264 // this if fixes #9960
265 if (!$this->trans_loaded[$row->obj_id]) {
266 $this->object_data_cache[$row->obj_id]['title'] = $row->title;
267 $this->object_data_cache[$row->obj_id]['description'] = $row->description;
268 if ($row->long_description !== null) {
269 $this->object_data_cache[$row->obj_id]['description'] = $row->long_description;
270 }
271 }
272 $this->object_data_cache[$row->obj_id]['type'] = $row->type;
273 $this->object_data_cache[$row->obj_id]['owner'] = $row->owner;
274 $this->object_data_cache[$row->obj_id]['last_update'] = $row->last_update;
275 $this->object_data_cache[$row->obj_id]['offline'] = $row->offline;
276
277 if (is_object($objDefinition)) {
278 $translation_type = $objDefinition->getTranslationType($row->type);
279 }
280
281 if ($translation_type == "db") {
282 $db_trans[$row->obj_id] = $row->obj_id;
283 }
284 }
285 if (count($db_trans) > 0) {
286 $this->preloadTranslations($db_trans, $a_lang);
287 }
288 }
preloadTranslations($a_obj_ids, $a_lang)
Preload translation informations.

References $db, $DIC, $ilDB, $ilUser, $query, $res, ilDBConstants\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 320 of file class.ilObjectDataCache.php.

321 {
323
324 if (!is_array($a_ref_ids)) {
325 return;
326 }
327 if (count($a_ref_ids) == 0) {
328 return;
329 }
330
331 $query = "SELECT ref_id, obj_id FROM object_reference " .
332 "WHERE " . $ilDB->in('ref_id', $a_ref_ids, false, 'integer');
333 $res = $ilDB->query($query);
334
335 $obj_ids = array();
336 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
337 $this->reference_cache[$row['ref_id']] = $row['obj_id'];
338 //echo "<br>store_ref-".$row['ref_id']."-".$row['obj_id']."-";
339 $obj_ids[] = $row['obj_id'];
340 }
341 if ($a_incl_obj) {
342 $this->preloadObjectCache($obj_ids);
343 }
344 }
preloadObjectCache($a_obj_ids, $a_lang="")
Stores object data in cache.

References $db, $ilDB, $query, $res, ilDBConstants\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 295 of file class.ilObjectDataCache.php.

296 {
298
299 $obj_ids = array();
300 foreach ($a_obj_ids as $id) {
301 // do not load an id more than one time
302 if (!$this->trans_loaded[$id]) {
303 $obj_ids[] = $id;
304 $this->trans_loaded[$id] = true;
305 }
306 }
307 if (count($obj_ids) > 0) {
308 $q = "SELECT obj_id, title, description FROM object_translation " .
309 "WHERE " . $ilDB->in('obj_id', $obj_ids, false, 'integer') . " " .
310 "AND lang_code = " . $ilDB->quote($a_lang, 'text');
311 $r = $ilDB->query($q);
312 while ($row2 = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
313 $this->object_data_cache[$row2->obj_id]['title'] = $row2->title;
314 $this->object_data_cache[$row2->obj_id]['description'] = $row2->description;
315 $this->description_trans[] = $row2->obj_id;
316 }
317 }
318 }

References $db, $ilDB, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by preloadObjectCache().

+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilObjectDataCache::$db = null

◆ $description_trans

ilObjectDataCache::$description_trans = array()

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

◆ $object_data_cache

ilObjectDataCache::$object_data_cache = array()

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

◆ $reference_cache

ilObjectDataCache::$reference_cache = array()

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

◆ $trans_loaded

ilObjectDataCache::$trans_loaded = []
protected

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


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