ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 {
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
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 }
223
224 public function isTranslatedDescription($a_obj_id)
225 {
226 return (is_array($this->description_trans) &&
227 in_array($a_obj_id, $this->description_trans));
228 }
229
237 public function preloadObjectCache($a_obj_ids, $a_lang = "")
238 {
239 global $DIC;
240
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 }
287
293 public function preloadTranslations($a_obj_ids, $a_lang)
294 {
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 }
318
319 public function preloadReferenceCache($a_ref_ids, $a_incl_obj = true)
320 {
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 }
344}
An exception for terminatinating execution or to throw for unit testing.
class ilObjectDataCache
lookupOfflineStatus($a_obj_id)
Check if supports centralized offline handling and is offline.
__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.
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46