ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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)
 
 __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.

Constructor & Destructor Documentation

◆ __construct()

ilObjectDataCache::__construct ( )

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

21 {
22 global $DIC;
23
24 $ilDB = $DIC->database();
25
26 $this->db = $ilDB;
27 }
global $DIC
Definition: saml.php:7
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 114 of file class.ilObjectDataCache.php.

115 {
116 static $cached = 0;
117 static $not_cached = 0;
118
119
120 if (@$this->object_data_cache[$a_obj_id]) {
121 #echo "Object ". ++$cached ."cached<br>";
122 return true;
123 }
124 #echo "Object ". ++$not_cached ." not cached<br>";
125 return false;
126 }

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

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

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

158 {
159 global $DIC;
160
162 $objDefinition = $DIC["objDefinition"];
163 $ilUser = $DIC["ilUser"];
164
165 if (is_object($ilUser) && $a_lang == "") {
166 $a_lang = $ilUser->getLanguage();
167 }
168
169 $query = "SELECT * FROM object_data WHERE obj_id = " .
170 $ilDB->quote($a_obj_id, 'integer');
171 $res = $this->db->query($query);
172 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
173 $this->object_data_cache[$a_obj_id]['title'] = $row->title;
174 $this->object_data_cache[$a_obj_id]['description'] = $row->description;
175 $this->object_data_cache[$a_obj_id]['type'] = $row->type;
176 $this->object_data_cache[$a_obj_id]['owner'] = $row->owner;
177 $this->object_data_cache[$a_obj_id]['last_update'] = $row->last_update;
178
179 if (is_object($objDefinition)) {
180 $translation_type = $objDefinition->getTranslationType($row->type);
181 }
182
183 if ($translation_type == "db") {
184 if (!$this->trans_loaded[$a_obj_id]) {
185 $q = "SELECT title,description FROM object_translation " .
186 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
187 "AND lang_code = " . $ilDB->quote($a_lang, 'text') . " " .
188 "AND NOT lang_default = 1";
189 $r = $ilDB->query($q);
190
192 if ($row) {
193 $this->object_data_cache[$a_obj_id]['title'] = $row->title;
194 $this->object_data_cache[$a_obj_id]['description'] = $row->description;
195 $this->description_trans[] = $a_obj_id;
196 }
197 $this->trans_loaded[$a_obj_id] = true;
198 }
199 }
200 }
201
202 return true;
203 }
$r
Definition: example_031.php:79
$query
foreach($_POST as $key=> $value) $res
$ilUser
Definition: imgupload.php:18

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

139 {
141
142 $query = "SELECT obj_id FROM object_reference WHERE ref_id = " . $ilDB->quote($a_ref_id, 'integer');
143 $res = $this->db->query($query);
144 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
145 $this->reference_cache[$a_ref_id] = $row['obj_id'];
146 }
147 return (int) @$this->reference_cache[$a_ref_id];
148 }

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

Referenced by lookupObjId().

+ Here is the caller graph for this function:

◆ deleteCachedEntry()

ilObjectDataCache::deleteCachedEntry (   $a_obj_id)

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

30 {
31 unset($this->object_data_cache[$a_obj_id]);
32 }

◆ isTranslatedDescription()

ilObjectDataCache::isTranslatedDescription (   $a_obj_id)

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

206 {
207 return (is_array($this->description_trans) &&
208 in_array($a_obj_id, $this->description_trans));
209 }

◆ lookupDescription()

ilObjectDataCache::lookupDescription (   $a_obj_id)

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

70 {
71 if (!$this->__isObjectCached($a_obj_id)) {
72 $this->__storeObjectData($a_obj_id);
73 }
74 return @$this->object_data_cache[$a_obj_id]['description'];
75 }
__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 77 of file class.ilObjectDataCache.php.

78 {
79 if (!$this->__isObjectCached($a_obj_id)) {
80 $this->__storeObjectData($a_obj_id);
81 }
82 return @$this->object_data_cache[$a_obj_id]['last_update'];
83 }

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupObjId()

ilObjectDataCache::lookupObjId (   $a_ref_id)

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

35 {
36 if (!$this->__isReferenceCached($a_ref_id)) {
37 //echo"-objidmissed-$a_ref_id-";
38 $obj_id = $this->__storeReference($a_ref_id);
39 $this->__storeObjectData($obj_id);
40 }
41 return (int) @$this->reference_cache[$a_ref_id];
42 }
__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 61 of file class.ilObjectDataCache.php.

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

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupTitle()

ilObjectDataCache::lookupTitle (   $a_obj_id)

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

45 {
46 if (!$this->__isObjectCached($a_obj_id)) {
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 //echo"-typemissed-$a_obj_id-";
56 $this->__storeObjectData($a_obj_id);
57 }
58 return @$this->object_data_cache[$a_obj_id]['type'];
59 }

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

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

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

299 {
301
302 if (!is_array($a_ref_ids)) {
303 return;
304 }
305 if (count($a_ref_ids) == 0) {
306 return;
307 }
308
309 $query = "SELECT ref_id, obj_id FROM object_reference " .
310 "WHERE " . $ilDB->in('ref_id', $a_ref_ids, false, 'integer');
311 $res = $ilDB->query($query);
312
313 $obj_ids = array();
314 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
315 $this->reference_cache[$row['ref_id']] = $row['obj_id'];
316 //echo "<br>store_ref-".$row['ref_id']."-".$row['obj_id']."-";
317 $obj_ids[] = $row['obj_id'];
318 }
319 if ($a_incl_obj) {
320 $this->preloadObjectCache($obj_ids);
321 }
322 }
preloadObjectCache($a_obj_ids, $a_lang="")
Stores object data in cache.

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

273 {
275
276 $obj_ids = array();
277 foreach ($a_obj_ids as $id) {
278 // do not load an id more than one time
279 if (!$this->trans_loaded[$id]) {
280 $obj_ids[] = $id;
281 $this->trans_loaded[$id] = true;
282 }
283 }
284 if (count($obj_ids) > 0) {
285 $q = "SELECT obj_id, title, description FROM object_translation " .
286 "WHERE " . $ilDB->in('obj_id', $obj_ids, false, 'integer') . " " .
287 "AND lang_code = " . $ilDB->quote($a_lang, 'text') . " " .
288 "AND NOT lang_default = 1";
289 $r = $ilDB->query($q);
290 while ($row2 = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
291 $this->object_data_cache[$row2->obj_id]['title'] = $row2->title;
292 $this->object_data_cache[$row2->obj_id]['description'] = $row2->description;
293 $this->description_trans[] = $row2->obj_id;
294 }
295 }
296 }
if(!array_key_exists('StateId', $_REQUEST)) $id

References $db, $id, $ilDB, $r, 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 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: