ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 // PRIVATE
85
93 public function __isReferenceCached($a_ref_id)
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 }
106
114 public function __isObjectCached($a_obj_id)
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 }
127
128
138 public function __storeReference($a_ref_id)
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 }
149
157 public function __storeObjectData($a_obj_id, $a_lang = "")
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 }
204
205 public function isTranslatedDescription($a_obj_id)
206 {
207 return (is_array($this->description_trans) &&
208 in_array($a_obj_id, $this->description_trans));
209 }
210
218 public function preloadObjectCache($a_obj_ids, $a_lang = "")
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 }
266
272 public function preloadTranslations($a_obj_ids, $a_lang)
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 }
297
298 public function preloadReferenceCache($a_ref_ids, $a_incl_obj = true)
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 }
323}
An exception for terminatinating execution or to throw for unit testing.
class ilObjectDataCache
__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
preloadTranslations($a_obj_ids, $a_lang)
Preload translation informations.
__storeObjectData($a_obj_id, $a_lang="")
Stores object data in cache.
__storeReference($a_ref_id)
Stores Reference in cache.
preloadReferenceCache($a_ref_ids, $a_incl_obj=true)
preloadObjectCache($a_obj_ids, $a_lang="")
Stores object data in cache.
$r
Definition: example_031.php:79
if(!array_key_exists('StateId', $_REQUEST)) $id
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18