ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilDclCache.php
Go to the documentation of this file.
1 <?php
2 
9 class ilDclCache
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';
16 
20  protected static $tables_cache;
24  protected static $fields_cache;
28  protected static $records_cache;
34  protected static $record_field_cache;
35 
39  protected static $field_representation_cache;
40 
44  protected static $record_representation_cache;
48  protected static $field_properties_cache;
49 
53  protected static $datatype_cache;
54 
68  protected static $clone_mapping;
69 
70  public static function setCloneOf($old, $new, $type)
71  {
72  if (!self::$clone_mapping) {
73  self::initCloneMapping();
74  }
75  self::$clone_mapping[$type][$old] = $new;
76  }
77 
78  protected static function initCloneMapping()
79  {
80  self::$clone_mapping = array(
81  self::TYPE_DATACOLLECTION => array(),
82  self::TYPE_TABLE => array(),
83  self::TYPE_FIELD => array(),
84  self::TYPE_RECORD => array(),
85  self::TYPE_TABLEVIEW => array(),
86  );
87  }
88 
89  public static function getCloneOf($id, $type)
90  {
91  $type_cache = self::$clone_mapping[$type];
92  if (!is_array($type_cache)) {
93  return false;
94  }
95 
96  if (isset($type_cache[$id])) {
97  $clone_id = $type_cache[$id];
98  } else {
99  foreach ($type_cache as $key => $mapping) {
100  if ($mapping == $id) {
101  $clone_id = $key;
102  }
103  }
104  }
105 
106  if (!$clone_id) {
107  return false;
108  }
109 
110 
111  switch ($type) {
112  case self::TYPE_DATACOLLECTION:
113  return new ilObjDataCollection($clone_id);
114  case self::TYPE_FIELD:
115  return self::getFieldCache($clone_id);
116  case self::TYPE_TABLE:
117  return self::getTableCache($clone_id);
118  case self::TYPE_RECORD:
119  return self::getRecordCache($clone_id);
120  }
121  }
122 
128  public static function getTableCache($table_id = 0)
129  {
130  if ($table_id == 0) {
131  return new ilDclTable();
132  }
133  $tables_cache = &self::$tables_cache;
134  if (!isset($tables_cache[$table_id])) {
135  $tables_cache[$table_id] = new ilDclTable($table_id);
136  }
137 
138  return $tables_cache[$table_id];
139  }
140 
141 
147  public static function getFieldCache($field_id = 0)
148  {
149  $fields_cache = &self::$fields_cache;
150  if (!isset($fields_cache[$field_id])) {
152  }
153 
154  return $fields_cache[$field_id];
155  }
156 
157 
163  public static function getRecordCache($record_id = 0)
164  {
165  $records_cache = &self::$records_cache;
166  if (!isset($records_cache[$record_id])) {
168  }
169 
170  return $records_cache[$record_id];
171  }
172 
173 
180  public static function getRecordFieldCache($record, $field)
181  {
182  $fid = $field->getId();
183  $rid = $record->getId();
184  if (!isset(self::$record_field_cache[$rid])) {
185  self::$record_field_cache[$rid] = array();
186  self::$record_field_cache[$rid][$fid] = ilDclFieldFactory::getRecordFieldInstance($field, $record);
187  } elseif (!isset(self::$record_field_cache[$rid][$fid])) {
188  self::$record_field_cache[$rid][$fid] = ilDclFieldFactory::getRecordFieldInstance($field, $record);
189  }
190 
191  return self::$record_field_cache[$rid][$fid];
192  }
193 
194 
201  public static function getFieldRepresentation(ilDclBaseFieldModel $field)
202  {
203  if (!isset(self::$field_representation_cache[$field->getId()])) {
204  self::$field_representation_cache[$field->getId()] = ilDclFieldFactory::getFieldRepresentationInstance($field);
205  }
206  return self::$field_representation_cache[$field->getId()];
207  }
208 
209 
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  return self::$record_representation_cache[$record_field->getId()];
227  }
228 
229 
236  public static function getFieldProperties($field_id)
237  {
238  if (!isset(self::$field_properties_cache[$field_id])) {
239  self::$field_properties_cache[$field_id] = array();
240  $result = ilDclFieldProperty::where(array('field_id'=>$field_id))->get();
241  foreach ($result as $prop) {
242  self::$field_properties_cache[$field_id][$prop->getName()] = $prop;
243  }
244  }
245  return self::$field_properties_cache[$field_id];
246  }
247 
248 
253  public static function preloadFieldProperties(array $fields)
254  {
255  foreach ($fields as $field_key => $field) {
256  if (isset(self::$field_properties_cache[$field->getId()])) {
257  unset($fields[$field_key]);
258  }
259  }
260 
261  if (count($fields) > 0) {
262  $field_ids = array();
263  foreach ($fields as $field) {
264  $field_ids[] = $field->getId();
265  }
266  $result = ilDclFieldProperty::where(array('field_id'=>$field_ids), 'IN')->get();
267  foreach ($result as $prop) {
268  if (!isset(self::$field_properties_cache[$prop->getFieldId()])) {
269  self::$field_properties_cache[$prop->getFieldId()] = array();
270  }
271  self::$field_properties_cache[$prop->getFieldId()][$prop->getName()] = $prop;
272  }
273  }
274  }
275 
276 
285  public static function getDatatype($datatyp_id)
286  {
287  if (self::$datatype_cache == null) {
288  self::$datatype_cache = ilDclDatatype::getAllDatatype();
289  }
290 
291  if (!isset(self::$datatype_cache[$datatyp_id])) {
292  return new ilDclDatatype();
293  }
294  return self::$datatype_cache[$datatyp_id];
295  }
296 
297 
303  public static function buildFieldFromRecord($rec)
304  {
305  $fields_cache = &self::$fields_cache;
306  if (isset($fields_cache[$rec["id"]])) {
307  return $fields_cache[$rec["id"]];
308  }
310  $field->setId($rec["id"]);
311  $field->setTableId($rec["table_id"]);
312  $field->setTitle($rec["title"]);
313  $field->setDescription($rec["description"]);
314  $field->setDatatypeId($rec["datatype_id"]);
315  $field->setRequired($rec["required"]);
316  $field->setUnique($rec["is_unique"]);
317  $field->setLocked($rec["is_locked"]);
318  $fields_cache[$rec["id"]] = $field;
319 
320  return $field;
321  }
322 
323 
327  public static function resetCache()
328  {
329  self::$fields_cache = array();
330  self::$record_field_cache = array();
331  self::$records_cache = array();
332  }
333 }
Class ilDclBaseFieldModel.
static getCloneOf($id, $type)
const TYPE_DATACOLLECTION
static setCloneOf($old, $new, $type)
static $field_representation_cache
static buildFieldFromRecord($rec)
$result
static getFieldProperties($field_id)
Cache Field properties.
static getAllDatatype()
Get all possible Datatypes.
$type
static preloadFieldProperties(array $fields)
Preloads field properties.
static getFieldCache($field_id=0)
static getFieldRepresentationInstance(ilDclBaseFieldModel $field)
Returns FieldRepresentation from BaseFieldModel.
static initCloneMapping()
if(!array_key_exists('StateId', $_REQUEST)) $id
const TYPE_TABLEVIEW
static getTableCache($table_id=0)
Class ilDclBaseFieldModel.
static where($where, $operator=null)
static $field_properties_cache
static getRecordFieldInstance(ilDclBaseFieldModel $field, ilDclBaseRecordModel $record)
Creates a RecordField instance and loads the field and record representation.
static resetCache()
Resets all the cache fields.
static getFieldRepresentation(ilDclBaseFieldModel $field)
static $clone_mapping
static $tables_cache
static getFieldModelInstance($field_id, $datatype=null)
Get FieldModel from field-id and datatype.
static getRecordCache($record_id=0)
static $record_representation_cache
static getRecordRepresentation(ilDclBaseRecordFieldModel $record_field)
Returns a record representation.
$old
Create styles array
The data for the language used.
static getRecordRepresentationInstance(ilDclBaseRecordFieldModel $record_field)
Get RecordRepresentation from RecordFieldModel.
Class ilDclDatatype.
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 getRecordFieldCache($record, $field)
Class ilDclException.
static $records_cache
static $datatype_cache
static getRecordModelInstance($record_id)
Creates a RecordModel instance.
static $fields_cache
$key
Definition: croninfo.php:18
static $record_field_cache
static getDatatype($datatyp_id)
Get cached datatypes.
Class ilObjDataCollection.
Class ilDclCache.