ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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()
 

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.

References $DIC, and $ilDB.

21  {
22  global $DIC;
23 
24  $ilDB = $DIC->database();
25 
26  $this->db = $ilDB;
27  }
global $ilDB
$DIC
Definition: xapitoken.php:46

Member Function Documentation

◆ __isObjectCached()

ilObjectDataCache::__isObjectCached (   $a_obj_id)

checks whether an object is aleady in cache or not

private

Parameters
int$a_obj_idobject id
Returns
boolean

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

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

129  {
130  static $cached = 0;
131  static $not_cached = 0;
132 
133 
134  if (@$this->object_data_cache[$a_obj_id]) {
135  #echo "Object ". ++$cached ."cached<br>";
136  return true;
137  }
138  #echo "Object ". ++$not_cached ." not cached<br>";
139  return false;
140  }
+ 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

private

Parameters
int$a_ref_idreference id
Returns
boolean

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

Referenced by lookupObjId().

108  {
109  #return false;
110  #static $cached = 0;
111  #static $not_cached = 0;
112 
113  if (@$this->reference_cache[$a_ref_id]) {
114  #echo "Reference ". ++$cached ."cached<br>";
115  return true;
116  }
117  #echo "Reference ". ++$not_cached ." not cached<br>";
118  return false;
119  }
+ Here is the caller graph for this function:

◆ __storeObjectData()

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

Stores object data in cache.

private

Parameters
int$a_obj_idobject id
Returns
bool

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

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

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

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

private

Parameters
int$a_ref_idreference id
Returns
int $obj_id

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

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

Referenced by lookupObjId().

153  {
154  $ilDB = $this->db;
155 
156  $query = "SELECT obj_id FROM object_reference WHERE ref_id = " . $ilDB->quote($a_ref_id, 'integer');
157  $res = $this->db->query($query);
158  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
159  $this->reference_cache[$a_ref_id] = $row['obj_id'];
160  }
161  return (int) @$this->reference_cache[$a_ref_id];
162  }
foreach($_POST as $key=> $value) $res
$query
global $ilDB
+ 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 224 of file class.ilObjectDataCache.php.

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

◆ lookupDescription()

ilObjectDataCache::lookupDescription (   $a_obj_id)

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

References __isObjectCached(), and __storeObjectData().

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.
+ Here is the call graph for this function:

◆ lookupLastUpdate()

ilObjectDataCache::lookupLastUpdate (   $a_obj_id)

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

References __isObjectCached(), and __storeObjectData().

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  }
__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.
+ Here is the call graph for this function:

◆ lookupObjId()

ilObjectDataCache::lookupObjId (   $a_ref_id)

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

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

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
__storeObjectData($a_obj_id, $a_lang="")
Stores object data in cache.
__storeReference($a_ref_id)
Stores Reference in cache.
+ 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 90 of file class.ilObjectDataCache.php.

References __isObjectCached(), and __storeObjectData().

91  {
92  if (!$this->__isObjectCached($a_obj_id)) {
93  $this->__storeObjectData($a_obj_id);
94  }
95  return (bool) $this->object_data_cache[$a_obj_id]['offline'];
96  }
__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.
+ Here is the call graph for this function:

◆ lookupOwner()

ilObjectDataCache::lookupOwner (   $a_obj_id)

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

References __isObjectCached(), and __storeObjectData().

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  }
__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.
+ Here is the call graph for this function:

◆ lookupTitle()

ilObjectDataCache::lookupTitle (   $a_obj_id)

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

References __isObjectCached(), and __storeObjectData().

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  }
__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.
+ Here is the call graph for this function:

◆ lookupType()

ilObjectDataCache::lookupType (   $a_obj_id)

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

References __isObjectCached(), and __storeObjectData().

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  }
__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.
+ Here is the call graph for this function:

◆ preloadObjectCache()

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

Stores object data in cache.

private

Parameters
int$a_obj_idobject id
Returns
bool

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

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

Referenced by preloadReferenceCache().

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

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

320  {
321  $ilDB = $this->db;
322 
323  if (!is_array($a_ref_ids)) {
324  return;
325  }
326  if (count($a_ref_ids) == 0) {
327  return;
328  }
329 
330  $query = "SELECT ref_id, obj_id FROM object_reference " .
331  "WHERE " . $ilDB->in('ref_id', $a_ref_ids, false, 'integer');
332  $res = $ilDB->query($query);
333 
334  $obj_ids = array();
335  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
336  $this->reference_cache[$row['ref_id']] = $row['obj_id'];
337  //echo "<br>store_ref-".$row['ref_id']."-".$row['obj_id']."-";
338  $obj_ids[] = $row['obj_id'];
339  }
340  if ($a_incl_obj) {
341  $this->preloadObjectCache($obj_ids);
342  }
343  }
preloadObjectCache($a_obj_ids, $a_lang="")
Stores object data in cache.
foreach($_POST as $key=> $value) $res
$query
global $ilDB
+ 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 293 of file class.ilObjectDataCache.php.

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

Referenced by preloadObjectCache().

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