ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 223 of file class.ilCachedObjectDefinition.php.

224 {
225 if ($this->changed) {
226 $this->changed = false;
227 $this->cache->set('data', $this->getRawData());
228 }
229 }

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 167 of file class.ilCachedObjectDefinition.php.

167 : array
168 {
170 }

References $il_object_def.

◆ getIlObjectGroup()

ilCachedObjectDefinition::getIlObjectGroup ( )

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

172 : array
173 {
175 }

References $il_object_group.

◆ getIlObjectSubType()

ilCachedObjectDefinition::getIlObjectSubType ( )

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

177 : array
178 {
180 }

References $il_object_sub_type.

◆ getInstance()

static ilCachedObjectDefinition::getInstance ( )
static

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

183 {
184 if (!isset(self::$instance)) {
185 return self::$instance = new self();
186 }
187
188 return self::$instance;
189 }
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 77 of file class.ilCachedObjectDefinition.php.

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

References $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 }

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 236 of file class.ilCachedObjectDefinition.php.

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

◆ lookupSubObjForParent()

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

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

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

◆ readFromCache()

ilCachedObjectDefinition::readFromCache ( )
protected

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

93 : void
94 {
95 // This is a workaround for the fact that transformatuin cannot be created by
96 // $DIC->refinery()->xy() since we are in a hell of dependencies. E.g. we cant instantiate the
97 // caching service with $DIC->refinery() since the Refinery needs ilLanguage, but ilLanguage
98 // needs the caching service and so on...
99 $cached_results = $this->cache->get('data', new Transformation(function ($data) {
100 return $data;
101 }));
102 if (is_array($cached_results)) {
104 } else {
105 $this->readFromDB();
106 }
107 }
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 109 of file class.ilCachedObjectDefinition.php.

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

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 88 of file class.ilCachedObjectDefinition.php.

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

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 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: