ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCachedComponentData.php
Go to the documentation of this file.
1<?php
2require_once('./Services/GlobalCache/classes/class.ilGlobalCacheDBLayer.php');
3
11
15 protected $cached_results = array();
19 protected static $instance;
23 protected $changed = false;
27 protected $loaded = false;
31 protected $obj_def_name_to_id = array();
35 protected $obj_def_name_and_type_raw = array();
39 protected $il_component = array();
43 protected $il_object_def = array();
47 protected $il_object_subobj = array();
51 protected $subobj_for_parent = array();
55 protected $grouped_rep_obj_types = array();
59 protected $il_pluginslot_by_comp = array();
63 protected $il_pluginslot_by_id = array();
67 protected $il_pluginslot_by_name = array();
71 protected $il_plugin_by_id = array();
75 protected $il_object_group = array();
79 protected $il_object_sub_type = array();
83 protected $il_plugin_active = array();
87 protected $il_plugin_by_name = array();
88
89
90 protected function __construct() {
92 $this->readFromDB();
93 }
94
95
99 public function getLoaded() {
100 return $this->loaded;
101 }
102
103
107 public function setLoaded($loaded) {
108 $this->loaded = $loaded;
109 }
110
111
112 protected function readFromDB() {
113 global $ilDB;
118 $set = $ilDB->query('SELECT * FROM il_component');
119 while ($rec = $ilDB->fetchAssoc($set)) {
120 $this->il_component[$rec['id']] = $rec;
121 $this->obj_def_name_to_id[$rec['id']] = $rec['name'];
122 $this->obj_def_name_and_type_raw[$rec['type']][$rec['name']] = $rec;
123 }
124
125 $set = $ilDB->query('SELECT * FROM il_object_def');
126 while ($rec = $ilDB->fetchAssoc($set)) {
127 $this->il_object_def[$rec['id']] = $rec;
128 }
129
130 $set = $ilDB->query('SELECT * FROM il_object_subobj');
131 while ($rec = $ilDB->fetchAssoc($set)) {
132 $this->il_object_subobj[] = $rec;
133 $parent = $rec['parent'];
134 $this->subobj_for_parent[$parent][] = $rec;
135 }
136 $set = $ilDB->query('SELECT DISTINCT(id) AS sid, parent, il_object_def.* FROM il_object_def, il_object_subobj WHERE NOT (system = 1) AND NOT (sideblock = 1) AND subobj = id');
137 while ($rec = $ilDB->fetchAssoc($set)) {
138 $this->grouped_rep_obj_types[$rec['parent']][] = $rec;
139 }
140
141 $set = $ilDB->query('SELECT * FROM il_pluginslot');
142 while ($rec = $ilDB->fetchAssoc($set)) {
143 $this->il_pluginslot_by_comp[$rec['component']][] = $rec;
144 $this->il_pluginslot_by_id[$rec['id']] = $rec;
145 $this->il_pluginslot_by_name[$rec['name']] = $rec;
146 }
147
148 $set = $ilDB->query('SELECT * FROM il_plugin');
149 $this->il_plugin_active = array();
150 while ($rec = $ilDB->fetchAssoc($set)) {
151 $this->il_plugin_by_id[$rec['plugin_id']] = $rec;
152 $this->il_plugin_by_name[$rec['name']] = $rec;
153 if ($rec['active'] == 1) {
154 $this->il_plugin_active[$rec['slot_id']][] = $rec;
155 }
156 }
157 $set = $ilDB->query('SELECT * FROM il_object_group');
158 while ($rec = $ilDB->fetchAssoc($set)) {
159 $this->il_object_group[$rec['id']] = $rec;
160 }
161 $set = $ilDB->query('SELECT * FROM il_object_sub_type');
162 while ($rec = $ilDB->fetchAssoc($set)) {
163 $this->il_object_sub_type[$rec['obj_type']][] = $rec;
164 }
165 }
166
167
171 public function getIlComponent() {
172 return $this->il_component;
173 }
174
175
179 public function setIlComponent($il_component) {
180 $this->il_component = $il_component;
181 }
182
183
187 public function getObjDefNameAndTypeRaw() {
189 }
190
191
196 $this->obj_def_name_and_type_raw = $obj_def_name_and_type_raw;
197 }
198
199
203 public function getObjDefNameToId() {
205 }
206
207
212 $this->obj_def_name_to_id = $obj_def_name_to_id;
213 }
214
215
219 public function getIlObjectDef() {
221 }
222
223
228 $this->il_object_def = $il_object_def;
229 }
230
231
235 public function getIlObjectSubobj() {
237 }
238
239
244 $this->il_object_subobj = $il_object_subobj;
245 }
246
247
251 public function getGroupedRepObjTypes() {
253 }
254
255
260 $this->grouped_rep_obj_types = $grouped_rep_obj_types;
261 }
262
263
267 public function getIlPluginslotByComp() {
269 }
270
271
275 public function setIlPluginslotByComp($il_pluginslot_by_service) {
276 $this->il_pluginslot_by_comp = $il_pluginslot_by_service;
277 }
278
279
283 public function getIlPluginslotById() {
285 }
286
287
292 $this->il_pluginslot_by_id = $il_pluginslot_by_id;
293 }
294
295
299 public function getIlPluginslotByName() {
301 }
302
303
308 $this->il_pluginslot_by_name = $il_pluginslot_by_name;
309 }
310
311
315 public function getIlPluginById() {
317 }
318
319
324 $this->il_plugin_by_id = $il_plugin_by_id;
325 }
326
327
331 public function getIlPluginByName() {
333 }
334
335
340 $this->il_plugin_by_name = $il_plugin_by_name;
341 }
342
343
347 public function getIlPluginActive() {
349 }
350
351
356 $this->il_plugin_active = $il_plugin_active;
357 }
358
359
363 public function getIlObjectGroup() {
365 }
366
367
372 $this->il_object_group = $il_object_group;
373 }
374
375
379 public function getIlObjectSubType() {
381 }
382
383
388 $this->il_object_sub_type = $il_object_sub_type;
389 }
390
391
395 public static function getInstance() {
396 if (!isset(self::$instance)) {
398 $cached_obj = $global_cache->get('ilCachedComponentData');
399 if ($cached_obj instanceof ilCachedComponentData) {
400 self::$instance = $cached_obj;
401 } else {
402 self::$instance = new self();
403 $global_cache->set('ilCachedComponentData', self::$instance);
404 }
405 }
406
407 return self::$instance;
408 }
409
410
411 public static function flush() {
413 self::$instance = NULL;
414 }
415
416
422 public function lookupPluginByName($name) {
423 return $this->il_plugin_by_name[$name];
424 }
425
426
432 public function lookupActivePluginsBySlotId($slot_id) {
433 if (is_array($this->il_plugin_active[$slot_id])) {
434 return $this->il_plugin_active[$slot_id];
435 } else {
436 return array();
437 }
438 }
439
440
446 public function lookupSubObjForParent($parent) {
447 if (is_array($parent)) {
448 $index = md5(serialize($parent));
449 if (isset($this->cached_results['subop_par'][$index])) {
450 return $this->cached_results['subop_par'][$index];
451 }
452
453 $return = array();
454 foreach ($parent as $p) {
455 if (is_array($this->subobj_for_parent[$p])) {
456 foreach ($this->subobj_for_parent[$p] as $rec) {
457 $return[] = $rec;
458 }
459 }
460 }
461
462 $this->cached_results['subop_par'][$index] = $return;
463 $this->changed = true;
464
465 return $return;
466 }
467
468 return $this->subobj_for_parent[$parent];
469 }
470
471
478 public function lookCompId($type, $name) {
479 return $this->obj_def_name_and_type_raw[$type][$name]['id'];
480 }
481
482
489 public function lookupCompInfo($type, $name) {
490 if (!$type) {
491 if (isset($this->obj_def_name_and_type_raw['Modules'][$name])) {
492 $type = 'Modules';
493 } else {
494 $type = 'Services';
495 }
496 }
497
498 return $this->obj_def_name_and_type_raw[$type][$name];
499 }
500
501
502 public function __destruct() {
504 if ($this->changed && $ilGlobalCache->isActive()) {
505 $this->changed = false;
506 $ilGlobalCache->set('ilCachedComponentData', $this);
507 }
508 }
509
510
516 public function lookupGroupedRepObj($parent) {
517 if (is_array($parent)) {
518 $index = md5(serialize($parent));
519 if (isset($cached_results['grpd_repo'][$index])) {
520 return $cached_results['grpd_repo'][$index];
521 }
522
523 $return = array();
524 $sids = array();
525 foreach ($parent as $p) {
526 $s = $this->grouped_rep_obj_types[$p];
527 foreach ($s as $child) {
528 if (!in_array($child['sid'], $sids)) {
529 $sids[] = $child['sid'];
530 $return[] = $child;
531 }
532 }
533 }
534 $this->changed = true;
535 $this->cached_results['grpd_repo'][$index] = $return;
536
537 return $return;
538 } else {
539 return $this->grouped_rep_obj_types[$parent];
540 }
541 }
542
543
549 public function lookupPluginSlotByComponent($component) {
550 if (is_array($this->il_pluginslot_by_comp[$component])) {
551 return $this->il_pluginslot_by_comp[$component];
552 }
553
554 return array();
555 }
556
557
563 public function lookupPluginSlotById($id) {
564 return $this->il_pluginslot_by_id[$id];
565 }
566
567
573 public function lookupPluginSlotByName($name) {
574 return $this->il_pluginslot_by_name[$name];
575 }
576
577
581 public function getSubobjForParent() {
583 }
584
585
590 $this->subobj_for_parent = $subobj_for_parent;
591 }
592}
593
594?>
Class ilCachedComponentData.
setSubobjForParent($subobj_for_parent)
setIlObjectSubType($il_object_sub_type)
setGroupedRepObjTypes($grouped_rep_obj_types)
setObjDefNameAndTypeRaw($obj_def_name_and_type_raw)
setObjDefNameToId($obj_def_name_to_id)
setIlPluginslotByName($il_pluginslot_by_name)
setIlPluginslotByComp($il_pluginslot_by_service)
setIlPluginslotById($il_pluginslot_by_id)
static getInstance($component)
global $ilDB