ILIAS  release_8 Revision v8.24
class.ilDclCache.php
Go to the documentation of this file.
1<?php
2
20{
21 public const TYPE_DATACOLLECTION = 'dcl';
22 public const TYPE_TABLE = 'table';
23 public const TYPE_FIELD = 'field';
24 public const TYPE_RECORD = 'record';
25 public const TYPE_TABLEVIEW = 'tableview';
29 protected static array $tables_cache = [];
33 protected static array $fields_cache = [];
37 protected static array $records_cache = [];
42 protected static array $record_field_cache = [];
46 protected static array $field_representation_cache = [];
50 protected static array $record_representation_cache = [];
54 protected static array $field_properties_cache = [];
58 protected static array $datatype_cache = [];
71 protected static array $clone_mapping = [];
72
73 public static function setCloneOf(int $old, int $new, string $type): void
74 {
75 if (!self::$clone_mapping) {
77 }
78 self::$clone_mapping[$type][$old] = $new;
79 }
80
81 protected static function initCloneMapping(): void
82 {
83 self::$clone_mapping = array(
84 self::TYPE_DATACOLLECTION => array(),
85 self::TYPE_TABLE => array(),
86 self::TYPE_FIELD => array(),
87 self::TYPE_RECORD => array(),
88 self::TYPE_TABLEVIEW => array(),
89 );
90 }
91
92 public static function getCloneOf(int $id, string $type): ?object
93 {
94 $type_cache = self::$clone_mapping[$type];
95 $clone_id = null;
96
97 if (!is_array($type_cache)) {
98 return null;
99 }
100
101 if (isset($type_cache[$id])) {
102 $clone_id = $type_cache[$id];
103 } else {
104 foreach ($type_cache as $key => $mapping) {
105 if ($mapping == $id) {
106 $clone_id = $key;
107 }
108 }
109 }
110
111 if (!$clone_id) {
112 return null;
113 }
114
115 switch ($type) {
117 return new ilObjDataCollection($clone_id);
118 case self::TYPE_FIELD:
119 return self::getFieldCache($clone_id);
120 case self::TYPE_TABLE:
121 return self::getTableCache($clone_id);
123 return self::getRecordCache($clone_id);
124 }
125
126 return null;
127 }
128
129 public static function getTableCache(int $table_id = null): ilDclTable
130 {
131 if (is_null($table_id) === true || $table_id === 0) {
132 return new ilDclTable();
133 }
135 if (!isset($tables_cache[$table_id])) {
136 $tables_cache[$table_id] = new ilDclTable($table_id);
137 }
138
139 return $tables_cache[$table_id];
140 }
141
142 public static function getFieldCache(int $field_id = 0): ilDclBaseFieldModel
143 {
145 if (!isset($fields_cache[$field_id])) {
147 }
148
149 return $fields_cache[$field_id];
150 }
151
152 public static function getRecordCache(?int $record_id): ilDclBaseRecordModel
153 {
155 if (!$record_id || !isset($records_cache[$record_id])) {
157 }
158
159 return $records_cache[$record_id];
160 }
161
162 public static function getRecordFieldCache(
163 object $record, //object|ilDclBaseRecordModel
164 object $field //object|ilDclBaseFieldModel
166 $fid = $field->getId();
167 $rid = $record->getId();
168 if (!isset(self::$record_field_cache[$rid])) {
169 self::$record_field_cache[$rid] = [];
170 self::$record_field_cache[$rid][$fid] = ilDclFieldFactory::getRecordFieldInstance($field, $record);
171 } elseif (!isset(self::$record_field_cache[$rid][$fid])) {
172 self::$record_field_cache[$rid][$fid] = ilDclFieldFactory::getRecordFieldInstance($field, $record);
173 }
174
175 return self::$record_field_cache[$rid][$fid];
176 }
177
182 {
183 if (!isset(self::$field_representation_cache[$field->getId()])) {
184 self::$field_representation_cache[$field->getId()] = ilDclFieldFactory::getFieldRepresentationInstance($field);
185 }
186
187 return self::$field_representation_cache[$field->getId()];
188 }
189
194 public static function getRecordRepresentation(
195 ilDclBaseRecordFieldModel $record_field
197 if ($record_field == null) {
198 throw new ilDclException("Cannot get Representation of null object!");
199 }
200
201 if (!isset(self::$record_representation_cache[$record_field->getId()])) {
202 self::$record_representation_cache[$record_field->getId()] = ilDclFieldFactory::getRecordRepresentationInstance($record_field);
203 }
204
205 return self::$record_representation_cache[$record_field->getId()];
206 }
207
213 public static function getFieldProperties($field_id): array
214 {
215 if (!isset(self::$field_properties_cache[$field_id])) {
216 self::$field_properties_cache[$field_id] = array();
217 $result = ilDclFieldProperty::where(array('field_id' => $field_id))->get();
218 foreach ($result as $prop) {
219 self::$field_properties_cache[$field_id][$prop->getName()] = $prop;
220 }
221 }
222
223 return self::$field_properties_cache[$field_id];
224 }
225
230 public static function preloadFieldProperties(array $fields): void
231 {
232 foreach ($fields as $field_key => $field) {
233 if (isset(self::$field_properties_cache[$field->getId()])) {
234 unset($fields[$field_key]);
235 }
236 }
237
238 if (count($fields) > 0) {
239 $field_ids = array();
240 foreach ($fields as $field) {
241 $field_ids[] = $field->getId();
242 }
243 $result = ilDclFieldProperty::where(array('field_id' => $field_ids), 'IN')->get();
244 foreach ($result as $prop) {
245 if (!isset(self::$field_properties_cache[$prop->getFieldId()])) {
246 self::$field_properties_cache[$prop->getFieldId()] = array();
247 }
248 self::$field_properties_cache[$prop->getFieldId()][$prop->getName()] = $prop;
249 }
250 }
251 }
252
257 public static function getDatatype(int $datatyp_id): ilDclDatatype
258 {
259 if (self::$datatype_cache == null) {
260 self::$datatype_cache = ilDclDatatype::getAllDatatype();
261 }
262
263 if (!isset(self::$datatype_cache[$datatyp_id])) {
264 return new ilDclDatatype();
265 }
266
267 return self::$datatype_cache[$datatyp_id];
268 }
269
270 public static function buildFieldFromRecord(array $rec): ilDclBaseFieldModel
271 {
272 $fields_cache = &self::$fields_cache;
273 if (isset($fields_cache[$rec["id"]])) {
274 return $fields_cache[$rec["id"]];
275 }
277 $field->setId($rec["id"]);
278 $field->setTableId($rec["table_id"]);
279 if (null !== $rec["title"]) {
280 $field->setTitle($rec["title"]);
281 }
282 if (null !== $rec["description"]) {
283 $field->setDescription($rec["description"]);
284 }
285 $field->setDatatypeId($rec["datatype_id"]);
286 $field->setUnique($rec["is_unique"]);
287 $fields_cache[$rec["id"]] = $field;
288
289 return $field;
290 }
291
295 public static function resetCache(): void
296 {
297 self::$fields_cache = array();
298 self::$record_field_cache = array();
299 self::$records_cache = array();
300 }
301}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static where($where, $operator=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getRecordCache(?int $record_id)
static getRecordFieldCache(object $record, object $field)
static getFieldProperties($field_id)
Cache Field properties.
static array $field_properties_cache
const TYPE_TABLEVIEW
static array $fields_cache
static getFieldCache(int $field_id=0)
static resetCache()
Resets all the cache fields.
static buildFieldFromRecord(array $rec)
static getRecordRepresentation(ilDclBaseRecordFieldModel $record_field)
Returns a record representation.
static array $tables_cache
static array $clone_mapping
const TYPE_DATACOLLECTION
static initCloneMapping()
static array $datatype_cache
static array $record_representation_cache
static array $record_field_cache
static array $records_cache
static array $field_representation_cache
static getTableCache(int $table_id=null)
static preloadFieldProperties(array $fields)
Preloads field properties.
static getFieldRepresentation(ilDclBaseFieldModel $field)
static setCloneOf(int $old, int $new, string $type)
static getCloneOf(int $id, string $type)
static getDatatype(int $datatyp_id)
Get cached datatypes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getAllDatatype(bool $force=false)
Get all possible Datatypes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getRecordRepresentationInstance(ilDclBaseRecordFieldModel $record_field)
Get RecordRepresentation from RecordFieldModel.
static getFieldRepresentationInstance(ilDclBaseFieldModel $field)
static getRecordModelInstance(?int $record_id)
static getRecordFieldInstance(object $field, object $record)
Creates a RecordField instance and loads the field and record representation.
static getFieldModelInstanceByClass(ilDclBaseFieldModel $field, ?int $field_id=null)
Gets the correct instance of a fieldModel class Checks if a field is a plugin a replaces the fieldMod...
static getFieldModelInstance(int $field_id, ?int $datatype=null)
Get FieldModel from field-id and datatype.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
string $key
Consumer key/client ID value.
Definition: System.php:193
$type