ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilObjectDataCache Class Reference

class ilObjectDataCache More...

+ Collaboration diagram for ilObjectDataCache:

Public Member Functions

 __construct ()
 
 deleteCachedEntry (int $obj_id)
 
 lookupObjId (int $ref_id)
 
 lookupTitle (int $obj_id)
 
 lookupType (int $obj_id)
 
 lookupOwner (int $obj_id)
 
 lookupDescription (int $obj_id)
 
 lookupLastUpdate (int $obj_id)
 
 lookupOfflineStatus (int $obj_id)
 Check if supports centralized offline handling and is offline. More...
 
 isTranslatedDescription (int $obj_id)
 
 preloadObjectCache (array $obj_ids, string $lang='')
 Stores object data in cache. More...
 
 preloadTranslations (array $obj_ids, string $lang)
 Preload translation information. More...
 
 preloadReferenceCache (array $ref_ids, bool $incl_obj=true)
 

Protected Attributes

ilDBInterface $db
 
array $trans_loaded = []
 
array $reference_cache = []
 
array $object_data_cache = []
 
array $description_trans = []
 

Private Member Functions

 __isReferenceCached (int $ref_id)
 checks whether a reference id is already in cache or not More...
 
 __isObjectCached (int $obj_id)
 checks whether an object is already in cache or not More...
 
 __storeReference (int $ref_id)
 Stores Reference in cache. More...
 
 __storeObjectData (int $obj_id)
 Stores object data in cache. More...
 

Detailed Description

class ilObjectDataCache

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

This class caches some properties of the object_data table. Like title description owner obj_id

Definition at line 29 of file class.ilObjectDataCache.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjectDataCache::__construct ( )

Definition at line 39 of file class.ilObjectDataCache.php.

40 {
41 global $DIC;
42 $this->db = $DIC->database();
43 }
global $DIC
Definition: shib_login.php:26

References $DIC.

Member Function Documentation

◆ __isObjectCached()

ilObjectDataCache::__isObjectCached ( int  $obj_id)
private

checks whether an object is already in cache or not

Definition at line 135 of file class.ilObjectDataCache.php.

135 : bool
136 {
137 if (isset($this->object_data_cache[$obj_id])) {
138 return true;
139 }
140
141 return false;
142 }

Referenced by lookupDescription(), lookupLastUpdate(), lookupOfflineStatus(), lookupOwner(), lookupTitle(), and lookupType().

+ Here is the caller graph for this function:

◆ __isReferenceCached()

ilObjectDataCache::__isReferenceCached ( int  $ref_id)
private

checks whether a reference id is already in cache or not

Definition at line 123 of file class.ilObjectDataCache.php.

123 : bool
124 {
125 if (isset($this->reference_cache[$ref_id])) {
126 return true;
127 }
128
129 return false;
130 }
$ref_id
Definition: ltiauth.php:66

References $ref_id.

Referenced by lookupObjId().

+ Here is the caller graph for this function:

◆ __storeObjectData()

ilObjectDataCache::__storeObjectData ( int  $obj_id)
private

Stores object data in cache.

Definition at line 167 of file class.ilObjectDataCache.php.

167 : void
168 {
169 global $DIC;
170
171 $obj_definition = $DIC["objDefinition"];
172 $user = $DIC["ilUser"];
173
174 $sql =
175 "SELECT object_data.obj_id, object_data.type, object_data.title, object_data.description, " . PHP_EOL
176 . "object_data.owner, object_data.create_date, object_data.last_update, object_data.import_id, " . PHP_EOL
177 . "object_data.offline, object_description.description as long_description " . PHP_EOL
178 . "FROM object_data LEFT JOIN object_description ON object_data.obj_id = object_description.obj_id " . PHP_EOL
179 . "WHERE object_data.obj_id = " . $this->db->quote($obj_id, 'integer') . PHP_EOL
180 ;
181 $res = $this->db->query($sql);
182 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
183 $this->object_data_cache[$obj_id]['title'] = $row->title;
184 $this->object_data_cache[$obj_id]['description'] = $row->description;
185 if ($row->long_description !== null) {
186 $this->object_data_cache[$row->obj_id]['description'] = $row->long_description;
187 }
188 $this->object_data_cache[$obj_id]['type'] = $row->type;
189 $this->object_data_cache[$obj_id]['owner'] = $row->owner;
190 $this->object_data_cache[$obj_id]['last_update'] = $row->last_update;
191 $this->object_data_cache[$obj_id]['offline'] = $row->offline;
192
193 $translation_type = $obj_definition->getTranslationType($row->type);
194
195 if ($translation_type === "db" && !isset($this->trans_loaded[$obj_id])) {
196 $sql =
197 "SELECT title, description" . PHP_EOL
198 . "FROM object_translation" . PHP_EOL
199 . "WHERE obj_id = " . $this->db->quote($obj_id, 'integer') . PHP_EOL
200 . "AND lang_code = " . $this->db->quote($user->getLanguage(), 'text') . PHP_EOL
201 ;
202 $trans_res = $this->db->query($sql);
203
204 $trans_row = $trans_res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
205 if ($trans_row) {
206 $this->object_data_cache[$obj_id]['title'] = $trans_row->title;
207 $this->object_data_cache[$obj_id]['description'] = $trans_row->description;
208 $this->description_trans[] = $obj_id;
209 }
210 $this->trans_loaded[$obj_id] = true;
211 }
212 }
213 }
$res
Definition: ltiservices.php:69

References $DIC, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by lookupDescription(), lookupLastUpdate(), lookupObjId(), lookupOfflineStatus(), lookupOwner(), lookupTitle(), and lookupType().

+ Here is the caller graph for this function:

◆ __storeReference()

ilObjectDataCache::__storeReference ( int  $ref_id)
private

Stores Reference in cache.

Maybe it could be useful to find all references of that object and store them also in the cache. But this would be an extra query.

Definition at line 149 of file class.ilObjectDataCache.php.

149 : int
150 {
151 $sql =
152 "SELECT obj_id" . PHP_EOL
153 . "FROM object_reference" . PHP_EOL
154 . "WHERE ref_id = " . $this->db->quote($ref_id, 'integer') . PHP_EOL
155 ;
156 $result = $this->db->query($sql);
157 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
158 $this->reference_cache[$ref_id] = (int) $row['obj_id'];
159 }
160
161 return (int) ($this->reference_cache[$ref_id] ?? 0);
162 }

References $ref_id, ilDBConstants\FETCHMODE_ASSOC, and ILIAS\Repository\int().

Referenced by lookupObjId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteCachedEntry()

ilObjectDataCache::deleteCachedEntry ( int  $obj_id)

Definition at line 45 of file class.ilObjectDataCache.php.

45 : void
46 {
47 if (isset($this->object_data_cache[$obj_id])) {
48 unset($this->object_data_cache[$obj_id]);
49 }
50 }

◆ isTranslatedDescription()

ilObjectDataCache::isTranslatedDescription ( int  $obj_id)

Definition at line 215 of file class.ilObjectDataCache.php.

215 : bool
216 {
217 return in_array($obj_id, $this->description_trans);
218 }

◆ lookupDescription()

ilObjectDataCache::lookupDescription ( int  $obj_id)

Definition at line 89 of file class.ilObjectDataCache.php.

89 : string
90 {
91 if (!$this->__isObjectCached($obj_id)) {
92 $this->__storeObjectData($obj_id);
93 }
94
95 return (string) ($this->object_data_cache[$obj_id]['description'] ?? '');
96 }
__storeObjectData(int $obj_id)
Stores object data in cache.
__isObjectCached(int $obj_id)
checks whether an object is already in cache or not

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupLastUpdate()

ilObjectDataCache::lookupLastUpdate ( int  $obj_id)

Definition at line 98 of file class.ilObjectDataCache.php.

98 : string
99 {
100 if (!$this->__isObjectCached($obj_id)) {
101 $this->__storeObjectData($obj_id);
102 }
103 return (string) ($this->object_data_cache[$obj_id]['last_update']);
104 }

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupObjId()

ilObjectDataCache::lookupObjId ( int  $ref_id)

Definition at line 52 of file class.ilObjectDataCache.php.

52 : int
53 {
54 if (!$this->__isReferenceCached($ref_id)) {
55 $obj_id = $this->__storeReference($ref_id);
56 $this->__storeObjectData($obj_id);
57 }
58
59 return (int) ($this->reference_cache[$ref_id] ?? 0);
60 }
__storeReference(int $ref_id)
Stores Reference in cache.
__isReferenceCached(int $ref_id)
checks whether a reference id is already in cache or not

References $ref_id, __isReferenceCached(), __storeObjectData(), and __storeReference().

Referenced by ilLearningProgressBaseGUI\__construct(), ilLPListOfObjectsGUI\__initDetails(), ilLPListOfProgressGUI\__initDetails(), ilLearningProgressBaseGUI\__setSubTabs(), ilLPStatusCollection\_getCompleted(), ilLPStatusCollection\_getFailed(), and ilLPStatusCollection\_getTypicalLearningTime().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupOfflineStatus()

ilObjectDataCache::lookupOfflineStatus ( int  $obj_id)

Check if supports centralized offline handling and is offline.

Definition at line 109 of file class.ilObjectDataCache.php.

109 : bool
110 {
111 if (!$this->__isObjectCached($obj_id)) {
112 $this->__storeObjectData($obj_id);
113 }
114
115 return (bool) ($this->object_data_cache[$obj_id]['offline'] ?? false);
116 }

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupOwner()

ilObjectDataCache::lookupOwner ( int  $obj_id)

Definition at line 80 of file class.ilObjectDataCache.php.

80 : int
81 {
82 if (!$this->__isObjectCached($obj_id)) {
83 $this->__storeObjectData($obj_id);
84 }
85
86 return (int) ($this->object_data_cache[$obj_id]['owner'] ?? 0);
87 }

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupTitle()

ilObjectDataCache::lookupTitle ( int  $obj_id)

Definition at line 62 of file class.ilObjectDataCache.php.

62 : string
63 {
64 if (!$this->__isObjectCached($obj_id)) {
65 $this->__storeObjectData($obj_id);
66 }
67
68 return (string) ($this->object_data_cache[$obj_id]['title'] ?? '');
69 }

References __isObjectCached(), and __storeObjectData().

+ Here is the call graph for this function:

◆ lookupType()

ilObjectDataCache::lookupType ( int  $obj_id)

Definition at line 71 of file class.ilObjectDataCache.php.

71 : string
72 {
73 if (!$this->__isObjectCached($obj_id)) {
74 $this->__storeObjectData($obj_id);
75 }
76
77 return (string) ($this->object_data_cache[$obj_id]['type'] ?? '');
78 }

References __isObjectCached(), and __storeObjectData().

Referenced by ilLearningProgressBaseGUI\__construct(), ilLPMarks\__construct(), ilLPListOfObjectsGUI\__initDetails(), ilLPListOfProgressGUI\__initDetails(), ilLearningProgressBaseGUI\__setSubTabs(), and ilLPStatusCollection\_getTypicalLearningTime().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ preloadObjectCache()

ilObjectDataCache::preloadObjectCache ( array  $obj_ids,
string  $lang = '' 
)

Stores object data in cache.

Parameters
int[]$obj_ids
string$lang

Definition at line 225 of file class.ilObjectDataCache.php.

225 : void
226 {
227 global $DIC;
228
229 $obj_definition = $DIC["objDefinition"];
230 $user = $DIC["ilUser"];
231
232 if ($lang == "") {
233 $lang = $user->getLanguage();
234 }
235
236 if ($obj_ids === []) {
237 return;
238 }
239
240 $sql =
241 "SELECT object_data.obj_id, object_data.type, object_data.title, object_data.description, " . PHP_EOL
242 . "object_data.owner, object_data.create_date, object_data.last_update, object_data.import_id, " . PHP_EOL
243 . "object_data.offline, object_description.description as long_description " . PHP_EOL
244 . "FROM object_data LEFT JOIN object_description ON object_data.obj_id = object_description.obj_id " . PHP_EOL
245 . "WHERE " . $this->db->in('object_data.obj_id', $obj_ids, false, 'integer') . PHP_EOL
246 ;
247 $res = $this->db->query($sql);
248 $db_trans = [];
249 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
250 $obj_id = (int) $row->obj_id;
251
252 if (!isset($this->trans_loaded[$obj_id])) {
253 $this->object_data_cache[$obj_id]['title'] = $row->title;
254 $this->object_data_cache[$obj_id]['description'] = $row->description;
255 if ($row->long_description !== null) {
256 $this->object_data_cache[$row->obj_id]['description'] = $row->long_description;
257 }
258 }
259 $this->object_data_cache[$obj_id]['type'] = $row->type;
260 $this->object_data_cache[$obj_id]['owner'] = $row->owner;
261 $this->object_data_cache[$obj_id]['last_update'] = $row->last_update;
262 $this->object_data_cache[$obj_id]['offline'] = $row->offline;
263
264 $translation_type = $obj_definition->getTranslationType($row->type);
265
266 if ($translation_type === "db") {
267 $db_trans[$obj_id] = $obj_id;
268 }
269 }
270
271 if (count($db_trans) > 0) {
272 $this->preloadTranslations($db_trans, $lang);
273 }
274 }
preloadTranslations(array $obj_ids, string $lang)
Preload translation information.
if(!file_exists('../ilias.ini.php'))
$lang
Definition: xapiexit.php:25

References $DIC, $lang, $res, ilDBConstants\FETCHMODE_OBJECT, if, ILIAS\Repository\int(), and preloadTranslations().

Referenced by preloadReferenceCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ preloadReferenceCache()

ilObjectDataCache::preloadReferenceCache ( array  $ref_ids,
bool  $incl_obj = true 
)
Parameters
int[]$ref_ids
bool$incl_obj

Definition at line 314 of file class.ilObjectDataCache.php.

314 : void
315 {
316 if ($ref_ids === []) {
317 return;
318 }
319
320 $sql =
321 "SELECT ref_id, obj_id" . PHP_EOL
322 . "FROM object_reference" . PHP_EOL
323 . "WHERE " . $this->db->in('ref_id', $ref_ids, false, 'integer') . PHP_EOL
324 ;
325 $res = $this->db->query($sql);
326
327 $obj_ids = [];
328 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
329 $this->reference_cache[(int) $row['ref_id']] = (int) $row['obj_id'];
330 $obj_ids[] = (int) $row['obj_id'];
331 }
332
333 if ($incl_obj) {
334 $this->preloadObjectCache($obj_ids);
335 }
336 }
preloadObjectCache(array $obj_ids, string $lang='')
Stores object data in cache.

References $res, ilDBConstants\FETCHMODE_ASSOC, ILIAS\Repository\int(), and preloadObjectCache().

+ Here is the call graph for this function:

◆ preloadTranslations()

ilObjectDataCache::preloadTranslations ( array  $obj_ids,
string  $lang 
)

Preload translation information.

Parameters
int[]$obj_ids
string$lang

Definition at line 281 of file class.ilObjectDataCache.php.

281 : void
282 {
283 $ids = [];
284 foreach ($obj_ids as $id) {
285 // do not load an id more than one time
286 if (!isset($this->trans_loaded[$id])) {
287 $ids[] = $id;
288 $this->trans_loaded[$id] = true;
289 }
290 }
291
292 if ($ids !== []) {
293 $sql =
294 "SELECT obj_id, title, description" . PHP_EOL
295 . "FROM object_translation" . PHP_EOL
296 . "WHERE " . $this->db->in('obj_id', $ids, false, 'integer') . PHP_EOL
297 . "AND lang_code = " . $this->db->quote($lang, 'text') . PHP_EOL
298 ;
299 $result = $this->db->query($sql);
300 while ($row = $result->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
301 $obj_id = (int) $row->obj_id;
302
303 $this->object_data_cache[$obj_id]['title'] = $row->title;
304 $this->object_data_cache[$obj_id]['description'] = $row->description;
305 $this->description_trans[] = $obj_id;
306 }
307 }
308 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

References $id, $lang, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

Referenced by preloadObjectCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db

ilDBInterface ilObjectDataCache::$db
protected

Definition at line 31 of file class.ilObjectDataCache.php.

◆ $description_trans

array ilObjectDataCache::$description_trans = []
protected

Definition at line 37 of file class.ilObjectDataCache.php.

◆ $object_data_cache

array ilObjectDataCache::$object_data_cache = []
protected

Definition at line 36 of file class.ilObjectDataCache.php.

◆ $reference_cache

array ilObjectDataCache::$reference_cache = []
protected

Definition at line 35 of file class.ilObjectDataCache.php.

◆ $trans_loaded

array ilObjectDataCache::$trans_loaded = []
protected

Definition at line 34 of file class.ilObjectDataCache.php.


The documentation for this class was generated from the following file: