ILIAS  release_7 Revision v7.30-3-g800a261c036
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{
16 protected $trans_loaded = [];
17
18 public $db = null;
19 public $reference_cache = array();
20 public $object_data_cache = array();
21 public $description_trans = array();
22
23 public function __construct()
24 {
25 global $DIC;
26
27 $ilDB = $DIC->database();
28
29 $this->db = $ilDB;
30 }
31
32 public function deleteCachedEntry($a_obj_id)
33 {
34 unset($this->object_data_cache[$a_obj_id]);
35 }
36
37 public function lookupObjId($a_ref_id)
38 {
39 if (!$this->__isReferenceCached($a_ref_id)) {
40 //echo"-objidmissed-$a_ref_id-";
41 $obj_id = $this->__storeReference($a_ref_id);
42 $this->__storeObjectData($obj_id);
43 }
44 return (int) @$this->reference_cache[$a_ref_id];
45 }
46
47 public function lookupTitle($a_obj_id)
48 {
49 if (!$this->__isObjectCached($a_obj_id)) {
50 $this->__storeObjectData($a_obj_id);
51 }
52 return @$this->object_data_cache[$a_obj_id]['title'];
53 }
54
55 public function lookupType($a_obj_id)
56 {
57 if (!$this->__isObjectCached($a_obj_id)) {
58 //echo"-typemissed-$a_obj_id-";
59 $this->__storeObjectData($a_obj_id);
60 }
61 return @$this->object_data_cache[$a_obj_id]['type'];
62 }
63
64 public function lookupOwner($a_obj_id)
65 {
66 if (!$this->__isObjectCached($a_obj_id)) {
67 $this->__storeObjectData($a_obj_id);
68 }
69 return @$this->object_data_cache[$a_obj_id]['owner'];
70 }
71
72 public function lookupDescription($a_obj_id)
73 {
74 if (!$this->__isObjectCached($a_obj_id)) {
75 $this->__storeObjectData($a_obj_id);
76 }
77 return @$this->object_data_cache[$a_obj_id]['description'];
78 }
79
80 public function lookupLastUpdate($a_obj_id)
81 {
82 if (!$this->__isObjectCached($a_obj_id)) {
83 $this->__storeObjectData($a_obj_id);
84 }
85 return @$this->object_data_cache[$a_obj_id]['last_update'];
86 }
87
93 public function lookupOfflineStatus($a_obj_id)
94 {
95 if (!$this->__isObjectCached($a_obj_id)) {
96 $this->__storeObjectData($a_obj_id);
97 }
98 return (bool) $this->object_data_cache[$a_obj_id]['offline'];
99 }
100
101 // PRIVATE
102
110 public function __isReferenceCached($a_ref_id)
111 {
112 #return false;
113 #static $cached = 0;
114 #static $not_cached = 0;
115
116 if (@$this->reference_cache[$a_ref_id]) {
117 #echo "Reference ". ++$cached ."cached<br>";
118 return true;
119 }
120 #echo "Reference ". ++$not_cached ." not cached<br>";
121 return false;
122 }
123
131 public function __isObjectCached($a_obj_id)
132 {
133 static $cached = 0;
134 static $not_cached = 0;
135
136
137 if (@$this->object_data_cache[$a_obj_id]) {
138 #echo "Object ". ++$cached ."cached<br>";
139 return true;
140 }
141 #echo "Object ". ++$not_cached ." not cached<br>";
142 return false;
143 }
144
145
155 public function __storeReference($a_ref_id)
156 {
158
159 $query = "SELECT obj_id FROM object_reference WHERE ref_id = " . $ilDB->quote($a_ref_id, 'integer');
160 $res = $this->db->query($query);
161 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
162 $this->reference_cache[$a_ref_id] = $row['obj_id'];
163 }
164 return (int) @$this->reference_cache[$a_ref_id];
165 }
166
174 public function __storeObjectData($a_obj_id, $a_lang = "")
175 {
176 global $DIC;
177
179 $objDefinition = $DIC["objDefinition"];
180 $ilUser = $DIC["ilUser"];
181
182 if (is_object($ilUser) && $a_lang == "") {
183 $a_lang = $ilUser->getLanguage();
184 }
185
186 $query = "SELECT object_data.*, object_description.description as long_description " .
187 "FROM object_data LEFT JOIN object_description ON object_data.obj_id = object_description.obj_id " .
188 "WHERE object_data.obj_id = " . $ilDB->quote($a_obj_id, 'integer');
189 $res = $this->db->query($query);
190 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
191 $this->object_data_cache[$a_obj_id]['title'] = $row->title;
192 $this->object_data_cache[$a_obj_id]['description'] = $row->description;
193 if ($row->long_description !== null) {
194 $this->object_data_cache[$a_obj_id]['description'] = $row->long_description;
195 }
196 $this->object_data_cache[$a_obj_id]['type'] = $row->type;
197 $this->object_data_cache[$a_obj_id]['owner'] = $row->owner;
198 $this->object_data_cache[$a_obj_id]['last_update'] = $row->last_update;
199 $this->object_data_cache[$a_obj_id]['offline'] = $row->offline;
200
201 if (is_object($objDefinition)) {
202 $translation_type = $objDefinition->getTranslationType($row->type);
203 }
204
205 if ($translation_type == "db") {
206 if (!$this->trans_loaded[$a_obj_id]) {
207 $q = "SELECT title,description FROM object_translation " .
208 "WHERE obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
209 "AND lang_code = " . $ilDB->quote($a_lang, 'text');
210 $r = $ilDB->query($q);
211
212 $row = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
213 if ($row) {
214 $this->object_data_cache[$a_obj_id]['title'] = $row->title;
215 $this->object_data_cache[$a_obj_id]['description'] = $row->description;
216 $this->description_trans[] = $a_obj_id;
217 }
218 $this->trans_loaded[$a_obj_id] = true;
219 }
220 }
221 }
222
223 return true;
224 }
225
226 public function isTranslatedDescription($a_obj_id)
227 {
228 return (is_array($this->description_trans) &&
229 in_array($a_obj_id, $this->description_trans));
230 }
231
239 public function preloadObjectCache($a_obj_ids, $a_lang = "")
240 {
241 global $DIC;
242
244 $objDefinition = $DIC["objDefinition"];
245 $ilUser = $DIC["ilUser"];
246
247 if (is_object($ilUser) && $a_lang == "") {
248 $a_lang = $ilUser->getLanguage();
249 }
250 if (!is_array($a_obj_ids)) {
251 return;
252 }
253 if (count($a_obj_ids) == 0) {
254 return;
255 }
256
257 $query = "SELECT object_data.*, object_description.description as long_description " .
258 "FROM object_data LEFT JOIN object_description ON object_data.obj_id = object_description.obj_id " .
259 "WHERE " . $ilDB->in('object_data.obj_id', $a_obj_ids, false, 'integer');
260 $res = $ilDB->query($query);
261 $db_trans = array();
262 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
263
264 // this if fixes #9960
265 if (!$this->trans_loaded[$row->obj_id]) {
266 $this->object_data_cache[$row->obj_id]['title'] = $row->title;
267 $this->object_data_cache[$row->obj_id]['description'] = $row->description;
268 if ($row->long_description !== null) {
269 $this->object_data_cache[$row->obj_id]['description'] = $row->long_description;
270 }
271 }
272 $this->object_data_cache[$row->obj_id]['type'] = $row->type;
273 $this->object_data_cache[$row->obj_id]['owner'] = $row->owner;
274 $this->object_data_cache[$row->obj_id]['last_update'] = $row->last_update;
275 $this->object_data_cache[$row->obj_id]['offline'] = $row->offline;
276
277 if (is_object($objDefinition)) {
278 $translation_type = $objDefinition->getTranslationType($row->type);
279 }
280
281 if ($translation_type == "db") {
282 $db_trans[$row->obj_id] = $row->obj_id;
283 }
284 }
285 if (count($db_trans) > 0) {
286 $this->preloadTranslations($db_trans, $a_lang);
287 }
288 }
289
295 public function preloadTranslations($a_obj_ids, $a_lang)
296 {
298
299 $obj_ids = array();
300 foreach ($a_obj_ids as $id) {
301 // do not load an id more than one time
302 if (!$this->trans_loaded[$id]) {
303 $obj_ids[] = $id;
304 $this->trans_loaded[$id] = true;
305 }
306 }
307 if (count($obj_ids) > 0) {
308 $q = "SELECT obj_id, title, description FROM object_translation " .
309 "WHERE " . $ilDB->in('obj_id', $obj_ids, false, 'integer') . " " .
310 "AND lang_code = " . $ilDB->quote($a_lang, 'text');
311 $r = $ilDB->query($q);
312 while ($row2 = $r->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
313 $this->object_data_cache[$row2->obj_id]['title'] = $row2->title;
314 $this->object_data_cache[$row2->obj_id]['description'] = $row2->description;
315 $this->description_trans[] = $row2->obj_id;
316 }
317 }
318 }
319
320 public function preloadReferenceCache($a_ref_ids, $a_incl_obj = true)
321 {
323
324 if (!is_array($a_ref_ids)) {
325 return;
326 }
327 if (count($a_ref_ids) == 0) {
328 return;
329 }
330
331 $query = "SELECT ref_id, obj_id FROM object_reference " .
332 "WHERE " . $ilDB->in('ref_id', $a_ref_ids, false, 'integer');
333 $res = $ilDB->query($query);
334
335 $obj_ids = array();
336 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
337 $this->reference_cache[$row['ref_id']] = $row['obj_id'];
338 //echo "<br>store_ref-".$row['ref_id']."-".$row['obj_id']."-";
339 $obj_ids[] = $row['obj_id'];
340 }
341 if ($a_incl_obj) {
342 $this->preloadObjectCache($obj_ids);
343 }
344 }
345}
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.
global $DIC
Definition: goto.php:24
$ilUser
Definition: imgupload.php:18
$query
foreach($_POST as $key=> $value) $res
global $ilDB