ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilDclCache.php
Go to the documentation of this file.
1<?php
2
10{
11 const TYPE_DATACOLLECTION = 'dcl';
12 const TYPE_TABLE = 'table';
13 const TYPE_FIELD = 'field';
14 const TYPE_RECORD = 'record';
15 const TYPE_TABLEVIEW = 'tableview';
19 protected static $tables_cache;
23 protected static $fields_cache;
27 protected static $records_cache;
33 protected static $record_field_cache;
45 protected static $field_properties_cache;
49 protected static $datatype_cache;
63 protected static $clone_mapping;
64
65
66 public static function setCloneOf($old, $new, $type)
67 {
68 if (!self::$clone_mapping) {
70 }
71 self::$clone_mapping[$type][$old] = $new;
72 }
73
74
75 protected static function initCloneMapping()
76 {
77 self::$clone_mapping = array(
78 self::TYPE_DATACOLLECTION => array(),
79 self::TYPE_TABLE => array(),
80 self::TYPE_FIELD => array(),
81 self::TYPE_RECORD => array(),
82 self::TYPE_TABLEVIEW => array(),
83 );
84 }
85
86
87 public static function getCloneOf($id, $type)
88 {
89 $type_cache = self::$clone_mapping[$type];
90 if (!is_array($type_cache)) {
91 return false;
92 }
93
94 if (isset($type_cache[$id])) {
95 $clone_id = $type_cache[$id];
96 } else {
97 foreach ($type_cache as $key => $mapping) {
98 if ($mapping == $id) {
99 $clone_id = $key;
100 }
101 }
102 }
103
104 if (!$clone_id) {
105 return false;
106 }
107
108 switch ($type) {
110 return new ilObjDataCollection($clone_id);
111 case self::TYPE_FIELD:
112 return self::getFieldCache($clone_id);
113 case self::TYPE_TABLE:
114 return self::getTableCache($clone_id);
116 return self::getRecordCache($clone_id);
117 }
118 }
119
120
126 public static function getTableCache($table_id = 0)
127 {
128 if ($table_id == 0) {
129 return new ilDclTable();
130 }
132 if (!isset($tables_cache[$table_id])) {
133 $tables_cache[$table_id] = new ilDclTable($table_id);
134 }
135
136 return $tables_cache[$table_id];
137 }
138
139
145 public static function getFieldCache($field_id = 0)
146 {
148 if (!isset($fields_cache[$field_id])) {
150 }
151
152 return $fields_cache[$field_id];
153 }
154
155
161 public static function getRecordCache($record_id = 0)
162 {
164 if (!isset($records_cache[$record_id])) {
166 }
167
168 return $records_cache[$record_id];
169 }
170
171
178 public static function getRecordFieldCache($record, $field)
179 {
180 $fid = $field->getId();
181 $rid = $record->getId();
182 if (!isset(self::$record_field_cache[$rid])) {
183 self::$record_field_cache[$rid] = array();
184 self::$record_field_cache[$rid][$fid] = ilDclFieldFactory::getRecordFieldInstance($field, $record);
185 } elseif (!isset(self::$record_field_cache[$rid][$fid])) {
186 self::$record_field_cache[$rid][$fid] = ilDclFieldFactory::getRecordFieldInstance($field, $record);
187 }
188
189 return self::$record_field_cache[$rid][$fid];
190 }
191
192
199 public static function getFieldRepresentation(ilDclBaseFieldModel $field)
200 {
201 if (!isset(self::$field_representation_cache[$field->getId()])) {
202 self::$field_representation_cache[$field->getId()] = ilDclFieldFactory::getFieldRepresentationInstance($field);
203 }
204
205 return self::$field_representation_cache[$field->getId()];
206 }
207
208
217 public static function getRecordRepresentation(ilDclBaseRecordFieldModel $record_field)
218 {
219 if ($record_field == null) {
220 throw new ilDclException("Cannot get Representation of null object!");
221 }
222
223 if (!isset(self::$record_representation_cache[$record_field->getId()])) {
224 self::$record_representation_cache[$record_field->getId()] = ilDclFieldFactory::getRecordRepresentationInstance($record_field);
225 }
226
227 return self::$record_representation_cache[$record_field->getId()];
228 }
229
230
238 public static function getFieldProperties($field_id)
239 {
240 if (!isset(self::$field_properties_cache[$field_id])) {
241 self::$field_properties_cache[$field_id] = array();
242 $result = ilDclFieldProperty::where(array('field_id' => $field_id))->get();
243 foreach ($result as $prop) {
244 self::$field_properties_cache[$field_id][$prop->getName()] = $prop;
245 }
246 }
247
248 return self::$field_properties_cache[$field_id];
249 }
250
251
257 public static function preloadFieldProperties(array $fields)
258 {
259 foreach ($fields as $field_key => $field) {
260 if (isset(self::$field_properties_cache[$field->getId()])) {
261 unset($fields[$field_key]);
262 }
263 }
264
265 if (count($fields) > 0) {
266 $field_ids = array();
267 foreach ($fields as $field) {
268 $field_ids[] = $field->getId();
269 }
270 $result = ilDclFieldProperty::where(array('field_id' => $field_ids), 'IN')->get();
271 foreach ($result as $prop) {
272 if (!isset(self::$field_properties_cache[$prop->getFieldId()])) {
273 self::$field_properties_cache[$prop->getFieldId()] = array();
274 }
275 self::$field_properties_cache[$prop->getFieldId()][$prop->getName()] = $prop;
276 }
277 }
278 }
279
280
289 public static function getDatatype($datatyp_id)
290 {
291 if (self::$datatype_cache == null) {
292 self::$datatype_cache = ilDclDatatype::getAllDatatype();
293 }
294
295 if (!isset(self::$datatype_cache[$datatyp_id])) {
296 return new ilDclDatatype();
297 }
298
299 return self::$datatype_cache[$datatyp_id];
300 }
301
302
308 public static function buildFieldFromRecord($rec)
309 {
311 if (isset($fields_cache[$rec["id"]])) {
312 return $fields_cache[$rec["id"]];
313 }
315 $field->setId($rec["id"]);
316 $field->setTableId($rec["table_id"]);
317 $field->setTitle($rec["title"]);
318 $field->setDescription($rec["description"]);
319 $field->setDatatypeId($rec["datatype_id"]);
320 $field->setRequired($rec["required"]);
321 $field->setUnique($rec["is_unique"]);
322 $field->setLocked($rec["is_locked"]);
323 $fields_cache[$rec["id"]] = $field;
324
325 return $field;
326 }
327
328
332 public static function resetCache()
333 {
334 self::$fields_cache = array();
335 self::$record_field_cache = array();
336 self::$records_cache = array();
337 }
338}
$result
static where($where, $operator=null)
An exception for terminatinating execution or to throw for unit testing.
Class ilDclBaseFieldModel.
Class ilDclCache.
static getDatatype($datatyp_id)
Get cached datatypes.
static getRecordFieldCache($record, $field)
static getFieldProperties($field_id)
Cache Field properties.
const TYPE_TABLEVIEW
static $field_properties_cache
static getTableCache($table_id=0)
static $field_representation_cache
static $tables_cache
static getRecordCache($record_id=0)
static $fields_cache
static resetCache()
Resets all the cache fields.
static $record_field_cache
static getRecordRepresentation(ilDclBaseRecordFieldModel $record_field)
Returns a record representation.
static $clone_mapping
static $records_cache
static getCloneOf($id, $type)
const TYPE_DATACOLLECTION
static initCloneMapping()
static buildFieldFromRecord($rec)
static $datatype_cache
static setCloneOf($old, $new, $type)
static getFieldCache($field_id=0)
static preloadFieldProperties(array $fields)
Preloads field properties.
static getFieldRepresentation(ilDclBaseFieldModel $field)
static $record_representation_cache
Class ilDclDatatype.
static getAllDatatype()
Get all possible Datatypes.
Class ilDclException.
static getRecordRepresentationInstance(ilDclBaseRecordFieldModel $record_field)
Get RecordRepresentation from RecordFieldModel.
static getFieldModelInstance($field_id, $datatype=null)
Get FieldModel from field-id and datatype.
static getFieldRepresentationInstance(ilDclBaseFieldModel $field)
Returns FieldRepresentation from BaseFieldModel.
static getRecordFieldInstance(ilDclBaseFieldModel $field, ilDclBaseRecordModel $record)
Creates a RecordField instance and loads the field and record representation.
static getFieldModelInstanceByClass(ilDclBaseFieldModel $field, $field_id=null)
Gets the correct instance of a fieldModel class Checks if a field is a plugin a replaces the fieldMod...
static getRecordModelInstance($record_id)
Creates a RecordModel instance.
Class ilDclBaseFieldModel.
Class ilObjDataCollection.
$key
Definition: croninfo.php:18
if(!array_key_exists('StateId', $_REQUEST)) $id
$type