ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCachedComponentData.php
Go to the documentation of this file.
1<?php
2
10{
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_slotid = array();
91 protected $il_plugin_by_name = array();
92
93
94 protected function __construct()
95 {
97 $this->readFromDB();
98 }
99
100
104 public function getLoaded()
105 {
106 return $this->loaded;
107 }
108
109
113 public function setLoaded($loaded)
114 {
115 $this->loaded = $loaded;
116 }
117
118
119 protected function readFromDB()
120 {
121 global $DIC;
122 $ilDB = $DIC->database();
127 $set = $ilDB->query('SELECT * FROM il_component');
128 while ($rec = $ilDB->fetchAssoc($set)) {
129 $this->il_component[$rec['id']] = $rec;
130 $this->obj_def_name_to_id[$rec['id']] = $rec['name'];
131 $this->obj_def_name_and_type_raw[$rec['type']][$rec['name']] = $rec;
132 }
133
134 $set = $ilDB->query('SELECT * FROM il_object_def');
135 while ($rec = $ilDB->fetchAssoc($set)) {
136 $this->il_object_def[$rec['id']] = $rec;
137 }
138
139 $set = $ilDB->query('SELECT * FROM il_object_subobj');
140 while ($rec = $ilDB->fetchAssoc($set)) {
141 $this->il_object_subobj[] = $rec;
142 $parent = $rec['parent'];
143 $this->subobj_for_parent[$parent][] = $rec;
144 }
145 $set = $ilDB->query('SELECT DISTINCT(id) AS sid, parent, il_object_def.* FROM il_object_def, il_object_subobj WHERE NOT (' . $ilDB->quoteIdentifier('system') . ' = 1) AND NOT (sideblock = 1) AND subobj = id');
146 while ($rec = $ilDB->fetchAssoc($set)) {
147 $this->grouped_rep_obj_types[$rec['parent']][] = $rec;
148 }
149
150 $set = $ilDB->query('SELECT * FROM il_pluginslot');
151 while ($rec = $ilDB->fetchAssoc($set)) {
152 $this->il_pluginslot_by_comp[$rec['component']][] = $rec;
153 $this->il_pluginslot_by_id[$rec['id']] = $rec;
154 $this->il_pluginslot_by_name[$rec['name']] = $rec;
155 }
156
157 $set = $ilDB->query('SELECT * FROM il_plugin');
158 $this->il_plugin_active = array();
159 while ($rec = $ilDB->fetchAssoc($set)) {
160 $this->il_plugin_by_id[$rec['plugin_id']] = $rec;
161 $this->il_plugin_by_name[$rec['name']] = $rec;
162 $this->il_plugin_by_slotid[$rec['slot_id']][] = $rec;
163 if ($rec['active'] == 1) {
164 $this->il_plugin_active[$rec['slot_id']][] = $rec;
165 }
166 }
167 $set = $ilDB->query('SELECT * FROM il_object_group');
168 while ($rec = $ilDB->fetchAssoc($set)) {
169 $this->il_object_group[$rec['id']] = $rec;
170 }
171 $set = $ilDB->query('SELECT * FROM il_object_sub_type');
172 while ($rec = $ilDB->fetchAssoc($set)) {
173 $this->il_object_sub_type[$rec['obj_type']][] = $rec;
174 }
175 }
176
177
181 public function getIlComponent()
182 {
183 return $this->il_component;
184 }
185
186
191 {
192 $this->il_component = $il_component;
193 }
194
195
199 public function getObjDefNameAndTypeRaw()
200 {
202 }
203
204
209 {
210 $this->obj_def_name_and_type_raw = $obj_def_name_and_type_raw;
211 }
212
213
217 public function getObjDefNameToId()
218 {
220 }
221
222
227 {
228 $this->obj_def_name_to_id = $obj_def_name_to_id;
229 }
230
231
235 public function getIlObjectDef()
236 {
238 }
239
240
245 {
246 $this->il_object_def = $il_object_def;
247 }
248
249
253 public function getIlObjectSubobj()
254 {
256 }
257
258
263 {
264 $this->il_object_subobj = $il_object_subobj;
265 }
266
267
271 public function getGroupedRepObjTypes()
272 {
274 }
275
276
281 {
282 $this->grouped_rep_obj_types = $grouped_rep_obj_types;
283 }
284
285
289 public function getIlPluginslotByComp()
290 {
292 }
293
294
298 public function setIlPluginslotByComp($il_pluginslot_by_service)
299 {
300 $this->il_pluginslot_by_comp = $il_pluginslot_by_service;
301 }
302
303
307 public function getIlPluginslotById()
308 {
310 }
311
312
317 {
318 $this->il_pluginslot_by_id = $il_pluginslot_by_id;
319 }
320
321
325 public function getIlPluginslotByName()
326 {
328 }
329
330
335 {
336 $this->il_pluginslot_by_name = $il_pluginslot_by_name;
337 }
338
339
343 public function getIlPluginById()
344 {
346 }
347
348
353 {
354 $this->il_plugin_by_id = $il_plugin_by_id;
355 }
356
357
361 public function getIlPluginByName()
362 {
364 }
365
366
371 {
372 $this->il_plugin_by_name = $il_plugin_by_name;
373 }
374
375
379 public function getIlPluginActive()
380 {
382 }
383
384
389 {
390 $this->il_plugin_active = $il_plugin_active;
391 }
392
393
397 public function getIlObjectGroup()
398 {
400 }
401
402
407 {
408 $this->il_object_group = $il_object_group;
409 }
410
411
415 public function getIlObjectSubType()
416 {
418 }
419
420
425 {
426 $this->il_object_sub_type = $il_object_sub_type;
427 }
428
429
433 public static function getInstance()
434 {
435 if (!isset(self::$instance)) {
437 $cached_obj = $global_cache->get('ilCachedComponentData');
438 if ($cached_obj instanceof ilCachedComponentData) {
439 self::$instance = $cached_obj;
440 } else {
441 self::$instance = new self();
442 $global_cache->set('ilCachedComponentData', self::$instance);
443 }
444 }
445
446 return self::$instance;
447 }
448
449
450 public static function flush()
451 {
453 self::$instance = null;
454 }
455
456
462 public function lookupPluginByName($name)
463 {
464 return $this->il_plugin_by_name[$name];
465 }
466
467
473 public function lookupActivePluginsBySlotId($slot_id)
474 {
475 if (isset($this->il_plugin_active[$slot_id]) && is_array($this->il_plugin_active[$slot_id])) {
476 return $this->il_plugin_active[$slot_id];
477 } else {
478 return array();
479 }
480 }
481
487 public function lookupPluginsBySlotId($slot_id)
488 {
489 return $this->il_plugin_by_slotid[$slot_id];
490 }
491
497 public function lookupSubObjForParent($parent)
498 {
499 if (is_array($parent)) {
500 $index = md5(serialize($parent));
501 if (isset($this->cached_results['subop_par'][$index])) {
502 return $this->cached_results['subop_par'][$index];
503 }
504
505 $return = array();
506 foreach ($parent as $p) {
507 if (is_array($this->subobj_for_parent[$p])) {
508 foreach ($this->subobj_for_parent[$p] as $rec) {
509 $return[] = $rec;
510 }
511 }
512 }
513
514 $this->cached_results['subop_par'][$index] = $return;
515 $this->changed = true;
516
517 return $return;
518 }
519
520 return $this->subobj_for_parent[$parent];
521 }
522
523
530 public function lookCompId($type, $name)
531 {
532 return $this->obj_def_name_and_type_raw[$type][$name]['id'];
533 }
534
535
542 public function lookupCompInfo($type, $name)
543 {
544 if (!$type) {
545 if (isset($this->obj_def_name_and_type_raw['Modules'][$name])) {
546 $type = 'Modules';
547 } else {
548 $type = 'Services';
549 }
550 }
551
552 return $this->obj_def_name_and_type_raw[$type][$name];
553 }
554
555
556 public function __destruct()
557 {
559 if ($this->changed && $ilGlobalCache->isActive()) {
560 $this->changed = false;
561 $ilGlobalCache->set('ilCachedComponentData', $this);
562 }
563 }
564
565
571 public function lookupGroupedRepObj($parent)
572 {
573 if (is_array($parent)) {
574 $index = md5(serialize($parent));
575 if (isset($this->cached_results['grpd_repo'][$index])) {
576 return $this->cached_results['grpd_repo'][$index];
577 }
578
579 $return = array();
580 $sids = array();
581 foreach ($parent as $p) {
582 $s = $this->grouped_rep_obj_types[$p];
583 foreach ($s as $child) {
584 if (!in_array($child['sid'], $sids)) {
585 $sids[] = $child['sid'];
586 $return[] = $child;
587 }
588 }
589 }
590 $this->changed = true;
591 $this->cached_results['grpd_repo'][$index] = $return;
592
593 return $return;
594 } else {
595 return $this->grouped_rep_obj_types[$parent];
596 }
597 }
598
599
605 public function lookupPluginSlotByComponent($component)
606 {
607 if (isset($this->il_pluginslot_by_comp[$component]) && is_array($this->il_pluginslot_by_comp[$component])) {
608 return $this->il_pluginslot_by_comp[$component];
609 }
610
611 return array();
612 }
613
614
620 public function lookupPluginSlotById($id)
621 {
622 return $this->il_pluginslot_by_id[$id];
623 }
624
625
632 {
633 return $this->il_pluginslot_by_name[$name];
634 }
635
636
640 public function getSubobjForParent()
641 {
643 }
644
645
650 {
651 $this->subobj_for_parent = $subobj_for_parent;
652 }
653}
An exception for terminatinating execution or to throw for unit testing.
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 $DIC
Definition: goto.php:24
if($format !==null) $name
Definition: metadata.php:230
$index
Definition: metadata.php:128
$type
global $ilDB