ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDataCollectionCache.php
Go to the documentation of this file.
1 <?php
13  protected static $tables_cache;
14 
18  protected static $fields_cache;
19 
23  protected static $records_cache;
24 
29  protected static $record_field_cache;
30 
31 
37  public static function getTableCache($table_id = 0){
39  if(!isset($tables_cache[$table_id]))
40  $tables_cache[$table_id] = new ilDataCollectionTable($table_id);
41  return $tables_cache[$table_id];
42  }
43 
44 
50  public static function getFieldCache($field_id = 0){
52  if(!isset($fields_cache[$field_id]))
53  $fields_cache[$field_id] = new ilDataCollectionField($field_id);
54  return $fields_cache[$field_id];
55  }
56 
57 
63  public static function getRecordCache($record_id = 0){
65  if(!isset($records_cache[$record_id]))
66  $records_cache[$record_id] = new ilDataCollectionRecord($record_id);
67  return $records_cache[$record_id];
68  }
69 
75  public static function getRecordFieldCache($record, $field){
76  $fid = $field->getId();
77  $rid = $record->getId();
78  if(!isset(self::$record_field_cache[$rid])){
79  self::$record_field_cache[$rid] = array();
80  self::$record_field_cache[$rid][$fid] = self::getInstance($record, $field);
81  }elseif(!isset(self::$record_field_cache[$rid][$fid])){
82  self::$record_field_cache[$rid][$fid] = self::getInstance($record, $field);
83  }
84  return self::$record_field_cache[$rid][$fid];
85  }
86 
93  public static function getInstance($record, $field){
94  switch($field->getDatatypeId()){
96  return new ilDataCollectionRatingField($record, $field);
98  return new ilDataCollectionILIASRefField($record, $field);
100  return new ilDataCollectionReferenceField($record, $field);
101  default:
102  return new ilDataCollectionRecordField($record, $field);
103  }
104  }
105 
106  public static function buildFieldFromRecord($rec){
108  if(isset($fields_cache[$rec["id"]])){
109  return $fields_cache[$rec["id"]];
110  }
111  $field = new ilDataCollectionField();
112  $field->setId($rec["id"]);
113  $field->setTableId($rec["table_id"]);
114  $field->setTitle($rec["title"]);
115  $field->setDescription($rec["description"]);
116  $field->setDatatypeId($rec["datatype_id"]);
117  $field->setRequired($rec["required"]);
118  $field->setUnique($rec["is_unique"]);
119  $field->setLocked($rec["is_locked"]);
120  $fields_cache[$rec["id"]] = $field;
121  return $field;
122  }
123 }