ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilObjectDataCache.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
14 {
15  public $db = null;
16  public $reference_cache = array();
17  public $object_data_cache = array();
18  public $description_trans = array();
19 
20  public function __construct()
21  {
22  global $DIC;
23 
24  $ilDB = $DIC->database();
25 
26  $this->db = $ilDB;
27  }
28 
29  public function deleteCachedEntry($a_obj_id)
30  {
31  unset($this->object_data_cache[$a_obj_id]);
32  }
33 
34  public function lookupObjId($a_ref_id)
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  }
43 
44  public function lookupTitle($a_obj_id)
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  }
51 
52  public function lookupType($a_obj_id)
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  }
60 
61  public function lookupOwner($a_obj_id)
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  }
68 
69  public function lookupDescription($a_obj_id)
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  }
76 
77  public function lookupLastUpdate($a_obj_id)
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  }
84 
90  public function lookupOfflineStatus($a_obj_id)
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  }
97 
98  // PRIVATE
99 
107  public function __isReferenceCached($a_ref_id)
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  }
120 
128  public function __isObjectCached($a_obj_id)
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  }
141 
142 
152  public function __storeReference($a_ref_id)
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  }
163 
171  public function __storeObjectData($a_obj_id, $a_lang = "")
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 * FROM object_data WHERE obj_id = " .
184  $ilDB->quote($a_obj_id, 'integer');
185  $res = $this->db->query($query);
186  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
187  $this->object_data_cache[$a_obj_id]['title'] = $row->title;
188  $this->object_data_cache[$a_obj_id]['description'] = $row->description;
189  $this->object_data_cache[$a_obj_id]['type'] = $row->type;
190  $this->object_data_cache[$a_obj_id]['owner'] = $row->owner;
191  $this->object_data_cache[$a_obj_id]['last_update'] = $row->last_update;
192  $this->object_data_cache[$a_obj_id]['offline'] = $row->offline;
193 
194  if (is_object($objDefinition)) {
195  $translation_type = $objDefinition->getTranslationType($row->type);
196  }
197 
198  if ($translation_type == "db") {
199  if (!$this->trans_loaded[$a_obj_id]) {
200  $q = "SELECT title,description FROM object_translation " .
201  "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
202  "AND lang_code = " . $ilDB->quote($a_lang, 'text') . " " .
203  "AND NOT lang_default = 1";
204  $r = $ilDB->query($q);
205 
207  if ($row) {
208  $this->object_data_cache[$a_obj_id]['title'] = $row->title;
209  $this->object_data_cache[$a_obj_id]['description'] = $row->description;
210  $this->description_trans[] = $a_obj_id;
211  }
212  $this->trans_loaded[$a_obj_id] = true;
213  }
214  }
215  }
216 
217  return true;
218  }
219 
220  public function isTranslatedDescription($a_obj_id)
221  {
222  return (is_array($this->description_trans) &&
223  in_array($a_obj_id, $this->description_trans));
224  }
225 
233  public function preloadObjectCache($a_obj_ids, $a_lang = "")
234  {
235  global $DIC;
236 
237  $ilDB = $this->db;
238  $objDefinition = $DIC["objDefinition"];
239  $ilUser = $DIC["ilUser"];
240 
241  if (is_object($ilUser) && $a_lang == "") {
242  $a_lang = $ilUser->getLanguage();
243  }
244  if (!is_array($a_obj_ids)) {
245  return;
246  }
247  if (count($a_obj_ids) == 0) {
248  return;
249  }
250 
251 
252  $query = "SELECT * FROM object_data " .
253  "WHERE " . $ilDB->in('obj_id', $a_obj_ids, false, 'integer');
254  $res = $ilDB->query($query);
255  $db_trans = array();
256  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
257 
258  // this if fixes #9960
259  if (!$this->trans_loaded[$row->obj_id]) {
260  $this->object_data_cache[$row->obj_id]['title'] = $row->title;
261  $this->object_data_cache[$row->obj_id]['description'] = $row->description;
262  }
263  $this->object_data_cache[$row->obj_id]['type'] = $row->type;
264  $this->object_data_cache[$row->obj_id]['owner'] = $row->owner;
265  $this->object_data_cache[$row->obj_id]['last_update'] = $row->last_update;
266  $this->object_data_cache[$row->obj_id]['offline'] = $row->offline;
267 
268  if (is_object($objDefinition)) {
269  $translation_type = $objDefinition->getTranslationType($row->type);
270  }
271 
272  if ($translation_type == "db") {
273  $db_trans[$row->obj_id] = $row->obj_id;
274  }
275  }
276  if (count($db_trans) > 0) {
277  $this->preloadTranslations($db_trans, $a_lang);
278  }
279  }
280 
286  public function preloadTranslations($a_obj_ids, $a_lang)
287  {
288  $ilDB = $this->db;
289 
290  $obj_ids = array();
291  foreach ($a_obj_ids as $id) {
292  // do not load an id more than one time
293  if (!$this->trans_loaded[$id]) {
294  $obj_ids[] = $id;
295  $this->trans_loaded[$id] = true;
296  }
297  }
298  if (count($obj_ids) > 0) {
299  $q = "SELECT obj_id, title, description FROM object_translation " .
300  "WHERE " . $ilDB->in('obj_id', $obj_ids, false, 'integer') . " " .
301  "AND lang_code = " . $ilDB->quote($a_lang, 'text') . " " .
302  "AND NOT lang_default = 1";
303  $r = $ilDB->query($q);
304  while ($row2 = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
305  $this->object_data_cache[$row2->obj_id]['title'] = $row2->title;
306  $this->object_data_cache[$row2->obj_id]['description'] = $row2->description;
307  $this->description_trans[] = $row2->obj_id;
308  }
309  }
310  }
311 
312  public function preloadReferenceCache($a_ref_ids, $a_incl_obj = true)
313  {
314  $ilDB = $this->db;
315 
316  if (!is_array($a_ref_ids)) {
317  return;
318  }
319  if (count($a_ref_ids) == 0) {
320  return;
321  }
322 
323  $query = "SELECT ref_id, obj_id FROM object_reference " .
324  "WHERE " . $ilDB->in('ref_id', $a_ref_ids, false, 'integer');
325  $res = $ilDB->query($query);
326 
327  $obj_ids = array();
328  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
329  $this->reference_cache[$row['ref_id']] = $row['obj_id'];
330  //echo "<br>store_ref-".$row['ref_id']."-".$row['obj_id']."-";
331  $obj_ids[] = $row['obj_id'];
332  }
333  if ($a_incl_obj) {
334  $this->preloadObjectCache($obj_ids);
335  }
336  }
337 }
__isObjectCached($a_obj_id)
checks whether an object is aleady in cache or not
__isReferenceCached($a_ref_id)
checks whether an reference id is already in cache or not
global $DIC
Definition: saml.php:7
preloadTranslations($a_obj_ids, $a_lang)
Preload translation informations.
lookupOfflineStatus($a_obj_id)
Check if supports centralized offline handling and is offline.
preloadObjectCache($a_obj_ids, $a_lang="")
Stores object data in cache.
__storeObjectData($a_obj_id, $a_lang="")
Stores object data in cache.
if(!array_key_exists('StateId', $_REQUEST)) $id
class ilObjectDataCache
__storeReference($a_ref_id)
Stores Reference in cache.
$r
Definition: example_031.php:79
foreach($_POST as $key=> $value) $res
$ilUser
Definition: imgupload.php:18
$query
preloadReferenceCache($a_ref_ids, $a_incl_obj=true)
$row
global $ilDB