ILIAS  release_8 Revision v8.24
class.ilCachedObjectDefinition.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
25{
26 protected static ?ilCachedObjectDefinition $instance = null;
27
29 protected array $cached_results = [];
30 protected bool $changed = false;
31 protected array $il_object_def = [];
32 protected array $subobj_for_parent = [];
33 protected array $grouped_rep_obj_types = [];
34 protected array $il_object_group = [];
35 protected array $il_object_sub_type = [];
36
37 protected function __construct()
38 {
40 $this->readFromDB();
41 }
42
43
44 protected function readFromDB(): void
45 {
46 global $DIC;
47 $db = $DIC->database();
48
49 $sql =
50 "SELECT id, class_name, component, location, checkbox, inherit, translate, devmode, allow_link," . PHP_EOL
51 . "allow_copy, rbac, `system`, sideblock, default_pos, grp, default_pres_pos, `export`, repository," . PHP_EOL
52 . "workspace, administration, amet, orgunit_permissions, lti_provider, offline_handling" . PHP_EOL
53 . "FROM il_object_def" . PHP_EOL
54 ;
55 $set = $db->query($sql);
56 while ($rec = $db->fetchAssoc($set)) {
57 $this->il_object_def[$rec['id']] = $rec;
58 }
59
60 $sql =
61 "SELECT parent, subobj, mmax" . PHP_EOL
62 . "FROM il_object_subobj" . PHP_EOL
63 ;
64 $set = $db->query($sql);
65 while ($rec = $db->fetchAssoc($set)) {
66 $parent = $rec['parent'];
67 $this->subobj_for_parent[$parent][] = $rec;
68 }
69
70 $sql =
71 "SELECT DISTINCT(id) AS sid, parent, id, class_name, component, location, checkbox, inherit," . PHP_EOL
72 . "translate, devmode, allow_link, allow_copy, rbac, `system`, sideblock, default_pos, grp," . PHP_EOL
73 . "default_pres_pos, `export`, repository, workspace, administration, amet, orgunit_permissions," . PHP_EOL
74 . "lti_provider, offline_handling" . PHP_EOL
75 . "FROM il_object_def, il_object_subobj" . PHP_EOL
76 . "WHERE NOT (" . $db->quoteIdentifier('system') . " = 1)" . PHP_EOL
77 . "AND NOT (sideblock = 1)" . PHP_EOL
78 . "AND subobj = id" . PHP_EOL
79 ;
80 $set = $db->query($sql);
81 while ($rec = $db->fetchAssoc($set)) {
82 $this->grouped_rep_obj_types[$rec['parent']][] = $rec;
83 }
84
85 $sql =
86 "SELECT id, name, default_pres_pos" . PHP_EOL
87 . "FROM il_object_group" . PHP_EOL
88 ;
89 $set = $db->query($sql);
90 while ($rec = $db->fetchAssoc($set)) {
91 $this->il_object_group[$rec['id']] = $rec;
92 }
93
94 $sql =
95 "SELECT obj_type, sub_type, amet" . PHP_EOL
96 . "FROM il_object_sub_type" . PHP_EOL
97 ;
98 $set = $db->query($sql);
99 while ($rec = $db->fetchAssoc($set)) {
100 $this->il_object_sub_type[$rec['obj_type']][] = $rec;
101 }
102 }
103
104 public function getIlObjectDef(): array
105 {
107 }
108
109 public function getIlObjectGroup(): array
110 {
112 }
113
114 public function getIlObjectSubType(): array
115 {
117 }
118
119 public static function getInstance(): ilCachedObjectDefinition
120 {
121 if (!isset(self::$instance)) {
123 $cached_obj = $global_cache->get('ilCachedObjectDefinition');
124 if ($cached_obj instanceof ilCachedObjectDefinition) {
125 self::$instance = $cached_obj;
126 } else {
127 self::$instance = new self();
128 $global_cache->set('ilCachedObjectDefinition', self::$instance);
129 }
130 }
131
132 return self::$instance;
133 }
134
135
136 public static function flush(): void
137 {
139 self::$instance = null;
140 }
141
147 public function lookupSubObjForParent($parent)
148 {
149 if (is_array($parent)) {
150 $index = md5(serialize($parent));
151 if (isset($this->cached_results['subop_par'][$index])) {
152 return $this->cached_results['subop_par'][$index];
153 }
154
155 $return = array();
156 foreach ($parent as $p) {
157 if (isset($this->subobj_for_parent[$p]) && is_array($this->subobj_for_parent[$p])) {
158 foreach ($this->subobj_for_parent[$p] as $rec) {
159 $return[] = $rec;
160 }
161 }
162 }
163
164 $this->cached_results['subop_par'][$index] = $return;
165 $this->changed = true;
166
167 return $return;
168 }
169
170 return $this->subobj_for_parent[$parent];
171 }
172
173 public function __destruct()
174 {
176 if ($this->changed && $ilGlobalCache->isActive()) {
177 $this->changed = false;
178 $ilGlobalCache->set('ilCachedObjectDefinition', $this);
179 }
180 }
181
187 public function lookupGroupedRepObj($parent)
188 {
189 if (is_array($parent)) {
190 $index = md5(serialize($parent));
191 if (isset($this->cached_results['grpd_repo'][$index])) {
192 return $this->cached_results['grpd_repo'][$index];
193 }
194
195 $return = array();
196 $sids = array();
197 foreach ($parent as $p) {
198 $s = $this->grouped_rep_obj_types[$p];
199 foreach ($s as $child) {
200 if (!in_array($child['sid'], $sids)) {
201 $sids[] = $child['sid'];
202 $return[] = $child;
203 }
204 }
205 }
206 $this->changed = true;
207 $this->cached_results['grpd_repo'][$index] = $return;
208
209 return $return;
210 } else {
211 return $this->grouped_rep_obj_types[$parent] ?? null;
212 }
213 }
214}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static ilCachedObjectDefinition $instance
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(?string $component)
set(string $key, $value, int $ttl=null)
global $DIC
Definition: feed.php:28
$index
Definition: metadata.php:145