ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
ilCachedObjectDefinition Class Reference

Cache for object definitions, based on ilGlobalCache. More...

+ Inheritance diagram for ilCachedObjectDefinition:
+ Collaboration diagram for ilCachedObjectDefinition:

Public Member Functions

 getContainerKey ()
 
 isForced ()
 
 init ()
 
 getIlObjectDef ()
 
 getIlObjectGroup ()
 
 getIlObjectSubType ()
 
 lookupSubObjForParent ($parent)
 
 __destruct ()
 
 lookupGroupedRepObj ($parent)
 
 getContainerKey ()
 
 isForced ()
 

Static Public Member Functions

static getInstance ()
 

Protected Member Functions

 __construct ()
 
 loadFromRawData (array $data)
 
 getRawData ()
 
 saveToCache ()
 
 readFromCache ()
 
 readFromDB ()
 

Protected Attributes

array $cached_results = []
 
bool $changed = false
 
array $il_object_def = []
 
array $subobj_for_parent = []
 
array $grouped_rep_obj_types = []
 
array $il_object_group = []
 
array $il_object_sub_type = []
 

Static Protected Attributes

static ilCachedObjectDefinition $instance = null
 

Private Attributes

ILIAS Cache Container Container $cache
 

Detailed Description

Cache for object definitions, based on ilGlobalCache.

Definition at line 27 of file class.ilCachedObjectDefinition.php.

Constructor & Destructor Documentation

◆ __construct()

ilCachedObjectDefinition::__construct ( )
protected

Definition at line 40 of file class.ilCachedObjectDefinition.php.

41 {
42 global $DIC;
43 $this->cache = $DIC->globalCache()->get($this);
44 $this->init();
45 }
global $DIC
Definition: shib_login.php:26

References $DIC, and init().

+ Here is the call graph for this function:

◆ __destruct()

ilCachedObjectDefinition::__destruct ( )

Definition at line 226 of file class.ilCachedObjectDefinition.php.

227 {
228 if ($this->changed) {
229 $this->changed = false;
230 $this->cache->set('data', $this->getRawData());
231 }
232 }

References getRawData().

+ Here is the call graph for this function:

Member Function Documentation

◆ getContainerKey()

ilCachedObjectDefinition::getContainerKey ( )

Implements ILIAS\Cache\Container\Request.

Definition at line 47 of file class.ilCachedObjectDefinition.php.

47 : string
48 {
49 return 'objdef';
50 }

◆ getIlObjectDef()

ilCachedObjectDefinition::getIlObjectDef ( )

Definition at line 170 of file class.ilCachedObjectDefinition.php.

170 : array
171 {
173 }

References $il_object_def.

◆ getIlObjectGroup()

ilCachedObjectDefinition::getIlObjectGroup ( )

Definition at line 175 of file class.ilCachedObjectDefinition.php.

175 : array
176 {
178 }

References $il_object_group.

◆ getIlObjectSubType()

ilCachedObjectDefinition::getIlObjectSubType ( )

Definition at line 180 of file class.ilCachedObjectDefinition.php.

180 : array
181 {
183 }

References $il_object_sub_type.

◆ getInstance()

static ilCachedObjectDefinition::getInstance ( )
static

Definition at line 185 of file class.ilCachedObjectDefinition.php.

186 {
187 if (!isset(self::$instance)) {
188 return self::$instance = new self();
189 }
190
191 return self::$instance;
192 }
Cache for object definitions, based on ilGlobalCache.
static ilCachedObjectDefinition $instance

References $instance.

Referenced by ilObjectDefinition\getGroupedRepositoryObjectTypes(), and ilObjectDefinition\readDefinitionData().

+ Here is the caller graph for this function:

◆ getRawData()

ilCachedObjectDefinition::getRawData ( )
protected

Definition at line 78 of file class.ilCachedObjectDefinition.php.

78 : array
79 {
80 return [
81 'il_object_def' => $this->il_object_def,
82 'subobj_for_parent' => $this->subobj_for_parent,
83 'grouped_rep_obj_types' => $this->grouped_rep_obj_types,
84 'il_object_group' => $this->il_object_group,
85 'il_object_sub_type' => $this->il_object_sub_type,
86 'cached_results' => $this->cached_results,
87 ];
88 }

References $cached_results, $grouped_rep_obj_types, $il_object_def, $il_object_group, $il_object_sub_type, and $subobj_for_parent.

Referenced by __destruct(), and saveToCache().

+ Here is the caller graph for this function:

◆ init()

ilCachedObjectDefinition::init ( )

Definition at line 58 of file class.ilCachedObjectDefinition.php.

58 : void
59 {
60 if ($this->cache->has('data')) {
61 $this->readFromCache();
62 } else {
63 $this->readFromDB();
64 $this->saveToCache();
65 }
66 }

References readFromCache(), readFromDB(), and saveToCache().

Referenced by __construct().

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

◆ isForced()

ilCachedObjectDefinition::isForced ( )

Implements ILIAS\Cache\Container\Request.

Definition at line 53 of file class.ilCachedObjectDefinition.php.

53 : bool
54 {
55 return false;
56 }

◆ loadFromRawData()

ilCachedObjectDefinition::loadFromRawData ( array  $data)
protected

Definition at line 68 of file class.ilCachedObjectDefinition.php.

68 : void
69 {
70 $this->il_object_def = $data['il_object_def'];
71 $this->subobj_for_parent = $data['subobj_for_parent'];
72 $this->grouped_rep_obj_types = $data['grouped_rep_obj_types'];
73 $this->il_object_group = $data['il_object_group'];
74 $this->il_object_sub_type = $data['il_object_sub_type'];
75 $this->cached_results = $data['cached_results'];
76 }

References $data.

Referenced by readFromCache(), and readFromDB().

+ Here is the caller graph for this function:

◆ lookupGroupedRepObj()

ilCachedObjectDefinition::lookupGroupedRepObj (   $parent)
Parameters
mixed$parent
Returns
mixed

Definition at line 239 of file class.ilCachedObjectDefinition.php.

240 {
241 if (is_array($parent)) {
242 $index = md5(serialize($parent));
243 if (isset($this->cached_results['grpd_repo'][$index])) {
244 return $this->cached_results['grpd_repo'][$index];
245 }
246
247 $return = [];
248 $sids = [];
249 foreach ($parent as $p) {
250 $s = $this->grouped_rep_obj_types[$p];
251 foreach ($s as $child) {
252 if (!in_array($child['sid'], $sids)) {
253 $sids[] = $child['sid'];
254 $return[] = $child;
255 }
256 }
257 }
258 $this->changed = true;
259 $this->cached_results['grpd_repo'][$index] = $return;
260
261 return $return;
262 } else {
263 return $this->grouped_rep_obj_types[$parent] ?? null;
264 }
265 }

◆ lookupSubObjForParent()

ilCachedObjectDefinition::lookupSubObjForParent (   $parent)
Parameters
mixed$parent
Returns
mixed

Definition at line 200 of file class.ilCachedObjectDefinition.php.

201 {
202 if (is_array($parent)) {
203 $index = md5(serialize($parent));
204 if (isset($this->cached_results['subop_par'][$index])) {
205 return $this->cached_results['subop_par'][$index];
206 }
207
208 $return = [];
209 foreach ($parent as $p) {
210 if (isset($this->subobj_for_parent[$p]) && is_array($this->subobj_for_parent[$p])) {
211 foreach ($this->subobj_for_parent[$p] as $rec) {
212 $return[] = $rec;
213 }
214 }
215 }
216
217 $this->cached_results['subop_par'][$index] = $return;
218 $this->changed = true;
219
220 return $return;
221 }
222
223 return $this->subobj_for_parent[$parent];
224 }

◆ readFromCache()

ilCachedObjectDefinition::readFromCache ( )
protected

Definition at line 95 of file class.ilCachedObjectDefinition.php.

95 : void
96 {
97 // This is a workaround for the fact that transformatuin cannot be created by
98 // $DIC->refinery()->xy() since we are in a hell of dependencies. E.g. we cant instantiate the
99 // caching service with $DIC->refinery() since the Refinery needs ilLanguage, but ilLanguage
100 // needs the caching service and so on...
101 $cached_results = $this->cache->get('data', new Transformation(function ($data) {
102 return $data;
103 }));
104 if (is_array($cached_results)) {
106 } else {
107 $this->readFromDB();
108 }
109 }
Transform values according to custom configuration.

References $cached_results, $data, loadFromRawData(), and readFromDB().

Referenced by init().

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

◆ readFromDB()

ilCachedObjectDefinition::readFromDB ( )
protected

Definition at line 111 of file class.ilCachedObjectDefinition.php.

111 : void
112 {
113 global $DIC;
114 $db = $DIC->database();
115
116 $data = [];
117
118 $sql =
119 "SELECT id, class_name, component, location, checkbox, inherit, translate, devmode, allow_link," . PHP_EOL
120 . "allow_copy, rbac, `system`, sideblock, default_pos, grp, default_pres_pos, `export`, repository," . PHP_EOL
121 . "workspace, administration, amet, orgunit_permissions, lti_provider, offline_handling" . PHP_EOL
122 . "FROM il_object_def" . PHP_EOL;
123 $set = $db->query($sql);
124 while ($rec = $db->fetchAssoc($set)) {
125 $data['il_object_def'][$rec['id']] = $rec;
126 }
127
128 $sql =
129 "SELECT parent, subobj, mmax" . PHP_EOL
130 . "FROM il_object_subobj" . PHP_EOL;
131 $set = $db->query($sql);
132 while ($rec = $db->fetchAssoc($set)) {
133 $parent = $rec['parent'];
134 $data['subobj_for_parent'][$parent][] = $rec;
135 }
136
137 $sql =
138 "SELECT DISTINCT(id) AS sid, parent, id, class_name, component, location, checkbox, inherit," . PHP_EOL
139 . "translate, devmode, allow_link, allow_copy, rbac, `system`, sideblock, default_pos, grp," . PHP_EOL
140 . "default_pres_pos, `export`, repository, workspace, administration, amet, orgunit_permissions," . PHP_EOL
141 . "lti_provider, offline_handling" . PHP_EOL
142 . "FROM il_object_def, il_object_subobj" . PHP_EOL
143 . "WHERE NOT (" . $db->quoteIdentifier('system') . " = 1)" . PHP_EOL
144 . "AND NOT (sideblock = 1)" . PHP_EOL
145 . "AND subobj = id" . PHP_EOL;
146 $set = $db->query($sql);
147 while ($rec = $db->fetchAssoc($set)) {
148 $data['grouped_rep_obj_types'][$rec['parent']][] = $rec;
149 }
150
151 $sql =
152 "SELECT id, name, default_pres_pos" . PHP_EOL
153 . "FROM il_object_group" . PHP_EOL;
154 $set = $db->query($sql);
155 while ($rec = $db->fetchAssoc($set)) {
156 $data['il_object_group'][$rec['id']] = $rec;
157 }
158
159 $sql =
160 "SELECT obj_type, sub_type, amet" . PHP_EOL
161 . "FROM il_object_sub_type" . PHP_EOL;
162 $set = $db->query($sql);
163 while ($rec = $db->fetchAssoc($set)) {
164 $data['il_object_sub_type'][$rec['obj_type']][] = $rec;
165 }
166 $data['cached_results'] = [];
167 $this->loadFromRawData($data);
168 }

References $data, $DIC, and loadFromRawData().

Referenced by init(), and readFromCache().

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

◆ saveToCache()

ilCachedObjectDefinition::saveToCache ( )
protected

Definition at line 90 of file class.ilCachedObjectDefinition.php.

90 : void
91 {
92 $this->cache->set('data', $this->getRawData());
93 }

References getRawData().

Referenced by init().

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

Field Documentation

◆ $cache

ILIAS Cache Container Container ilCachedObjectDefinition::$cache
private

Definition at line 30 of file class.ilCachedObjectDefinition.php.

◆ $cached_results

array ilCachedObjectDefinition::$cached_results = []
protected

Definition at line 32 of file class.ilCachedObjectDefinition.php.

Referenced by getRawData(), and readFromCache().

◆ $changed

bool ilCachedObjectDefinition::$changed = false
protected

Definition at line 33 of file class.ilCachedObjectDefinition.php.

◆ $grouped_rep_obj_types

array ilCachedObjectDefinition::$grouped_rep_obj_types = []
protected

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

Referenced by getRawData().

◆ $il_object_def

array ilCachedObjectDefinition::$il_object_def = []
protected

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

Referenced by getIlObjectDef(), and getRawData().

◆ $il_object_group

array ilCachedObjectDefinition::$il_object_group = []
protected

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

Referenced by getIlObjectGroup(), and getRawData().

◆ $il_object_sub_type

array ilCachedObjectDefinition::$il_object_sub_type = []
protected

Definition at line 38 of file class.ilCachedObjectDefinition.php.

Referenced by getIlObjectSubType(), and getRawData().

◆ $instance

ilCachedObjectDefinition ilCachedObjectDefinition::$instance = null
staticprotected

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

Referenced by getInstance().

◆ $subobj_for_parent

array ilCachedObjectDefinition::$subobj_for_parent = []
protected

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

Referenced by getRawData().


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