ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  var $db = null;
16  var $reference_cache = array();
17  var $object_data_cache = array();
18 
19  function ilObjectDataCache()
20  {
21  global $ilDB;
22 
23  $this->db =& $ilDB;
24  }
25 
26  function deleteCachedEntry($a_obj_id)
27  {
28  unset($this->object_data_cache[$a_obj_id]);
29  }
30 
31  function lookupObjId($a_ref_id)
32  {
33  if(!$this->__isReferenceCached($a_ref_id))
34  {
35 //echo"-objidmissed-$a_ref_id-";
36  $obj_id = $this->__storeReference($a_ref_id);
37  $this->__storeObjectData($obj_id);
38  }
39  return (int) @$this->reference_cache[$a_ref_id];
40  }
41 
42  function lookupTitle($a_obj_id)
43  {
44  if(!$this->__isObjectCached($a_obj_id))
45  {
46  $this->__storeObjectData($a_obj_id);
47  }
48  return @$this->object_data_cache[$a_obj_id]['title'];
49  }
50 
51  function lookupType($a_obj_id)
52  {
53  if(!$this->__isObjectCached($a_obj_id))
54  {
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  function lookupOwner($a_obj_id)
62  {
63  if(!$this->__isObjectCached($a_obj_id))
64  {
65  $this->__storeObjectData($a_obj_id);
66  }
67  return @$this->object_data_cache[$a_obj_id]['owner'];
68  }
69 
70  function lookupDescription($a_obj_id)
71  {
72  if(!$this->__isObjectCached($a_obj_id))
73  {
74  $this->__storeObjectData($a_obj_id);
75  }
76  return @$this->object_data_cache[$a_obj_id]['description'];
77  }
78 
79  function lookupLastUpdate($a_obj_id)
80  {
81  if(!$this->__isObjectCached($a_obj_id))
82  {
83  $this->__storeObjectData($a_obj_id);
84  }
85  return @$this->object_data_cache[$a_obj_id]['last_update'];
86  }
87  // PRIVATE
88 
96  function __isReferenceCached($a_ref_id)
97  {
98  #return false;
99  #static $cached = 0;
100  #static $not_cached = 0;
101 
102  if(@$this->reference_cache[$a_ref_id])
103  {
104  #echo "Reference ". ++$cached ."cached<br>";
105  return true;
106  }
107  #echo "Reference ". ++$not_cached ." not cached<br>";
108  return false;
109 
110  }
111 
119  function __isObjectCached($a_obj_id)
120  {
121  static $cached = 0;
122  static $not_cached = 0;
123 
124 
125  if(@$this->object_data_cache[$a_obj_id])
126  {
127  #echo "Object ". ++$cached ."cached<br>";
128  return true;
129  }
130  #echo "Object ". ++$not_cached ." not cached<br>";
131  return false;
132  }
133 
134 
144  function __storeReference($a_ref_id)
145  {
146  global $ilDB;
147 
148  $query = "SELECT obj_id FROM object_reference WHERE ref_id = ".$ilDB->quote($a_ref_id,'integer');
149  $res = $this->db->query($query);
150  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
151  {
152  $this->reference_cache[$a_ref_id] = $row['obj_id'];
153  }
154  return (int) @$this->reference_cache[$a_ref_id];
155  }
156 
164  function __storeObjectData($a_obj_id, $a_lang = "")
165  {
166  global $ilDB, $objDefinition, $ilUser;
167 
168  if (is_object($ilUser) && $a_lang == "")
169  {
170  $a_lang = $ilUser->getLanguage();
171  }
172 
173  $query = "SELECT * FROM object_data WHERE obj_id = ".
174  $ilDB->quote($a_obj_id ,'integer');
175  $res = $this->db->query($query);
176  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
177  {
178  $this->object_data_cache[$a_obj_id]['title'] = $row->title;
179  $this->object_data_cache[$a_obj_id]['description'] = $row->description;
180  $this->object_data_cache[$a_obj_id]['type'] = $row->type;
181  $this->object_data_cache[$a_obj_id]['owner'] = $row->owner;
182  $this->object_data_cache[$a_obj_id]['last_update'] = $row->last_update;
183 
184  //$ilBench->start("Tree", "fetchNodeData_readDefinition");
185  if (is_object($objDefinition))
186  {
187  $translation_type = $objDefinition->getTranslationType($row->type);
188  }
189  //$ilBench->stop("Tree", "fetchNodeData_readDefinition");
190 
191  if ($translation_type == "db")
192  {
193  //$ilBench->start("Tree", "fetchNodeData_getTranslation");
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  }
206  //$ilBench->stop("Tree", "fetchNodeData_getTranslation");
207  }
208  }
209 
210  return true;
211  }
212 
220  function preloadObjectCache($a_obj_ids, $a_lang = "")
221  {
222  global $ilDB, $objDefinition, $ilUser;
223 
224  if (is_object($ilUser) && $a_lang == "")
225  {
226  $a_lang = $ilUser->getLanguage();
227  }
228 
229 //echo "<br>-preloading-"; var_dump($a_obj_ids);
230  if (!is_array($a_obj_ids)) return;
231  if (count($a_obj_ids) == 0) return;
232 
233 
234  $query = "SELECT * FROM object_data ".
235  "WHERE ".$ilDB->in('obj_id',$a_obj_ids,false,'integer');
236  $res = $ilDB->query($query);
237  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
238  {
239 //echo "<br>store_obj-".$row->obj_id."-".$row->type."-".$row->title."-";
240  $this->object_data_cache[$row->obj_id]['title'] = $row->title;
241  $this->object_data_cache[$row->obj_id]['description'] = $row->description;
242  $this->object_data_cache[$row->obj_id]['type'] = $row->type;
243  $this->object_data_cache[$row->obj_id]['owner'] = $row->owner;
244  $this->object_data_cache[$row->obj_id]['last_update'] = $row->last_update;
245 
246  if (is_object($objDefinition))
247  {
248  $translation_type = $objDefinition->getTranslationType($row->type);
249  }
250  //$ilBench->stop("Tree", "fetchNodeData_readDefinition");
251 
252  if ($translation_type == "db")
253  {
254  //$ilBench->start("Tree", "fetchNodeData_getTranslation");
255  $q = "SELECT title,description FROM object_translation ".
256  "WHERE obj_id = ".$ilDB->quote($row->obj_id,'integer')." ".
257  "AND lang_code = ".$ilDB->quote($a_lang,'text')." ".
258  "AND NOT lang_default = 1";
259  $r = $ilDB->query($q);
260 
261  $row2 = $r->fetchRow(DB_FETCHMODE_OBJECT);
262  if ($row2)
263  {
264  $this->object_data_cache[$row->obj_id]['title'] = $row2->title;
265  $this->object_data_cache[$row->obj_id]['description'] = $row2->description;
266  }
267  //$ilBench->stop("Tree", "fetchNodeData_getTranslation");
268  }
269  }
270  }
271 
272  function preloadReferenceCache($a_ref_ids, $a_incl_obj = true)
273  {
274  global $ilDB;
275 
276  if (!is_array($a_ref_ids)) return;
277  if (count($a_ref_ids) == 0) return;
278 
279  $query = "SELECT ref_id, obj_id FROM object_reference ".
280  "WHERE ".$ilDB->in('ref_id',$a_ref_ids,false,'integer');
281  $res = $ilDB->query($query);
282 
283  $obj_ids = array();
284  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
285  {
286  $this->reference_cache[$row['ref_id']] = $row['obj_id'];
287 //echo "<br>store_ref-".$row['ref_id']."-".$row['obj_id']."-";
288  $obj_ids[] = $row['obj_id'];
289  }
290  if ($a_incl_obj)
291  {
292  $this->preloadObjectCache($obj_ids);
293  }
294  }
295 
296 }
297 ?>