ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilDataCollectionCache.php
Go to the documentation of this file.
1 <?php
2 
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 
32  public static function getTableCache($table_id = 0){
34  if(!isset($tables_cache[$table_id]))
35  $tables_cache[$table_id] = new ilDataCollectionTable($table_id);
36  return $tables_cache[$table_id];
37  }
38 
39  public static function getFieldCache($field_id = 0){
41  if(!isset($fields_cache[$field_id]))
42  $fields_cache[$field_id] = new ilDataCollectionField($field_id);
43  return $fields_cache[$field_id];
44  }
45 
46  public static function getRecordCache($record_id = 0){
48  if(!isset($records_cache[$record_id]))
49  $records_cache[$record_id] = new ilDataCollectionRecord($record_id);
50  return $records_cache[$record_id];
51  }
52 
58  public static function getRecordFieldCache($record, $field){
59  $fid = $field->getId();
60  $rid = $record->getId();
61  if(!isset(self::$record_field_cache[$rid])){
62  self::$record_field_cache[$rid] = array();
63  self::$record_field_cache[$rid][$fid] = self::getInstance($record, $field);
64  }elseif(!isset(self::$record_field_cache[$rid][$fid])){
65  self::$record_field_cache[$rid][$fid] = self::getInstance($record, $field);
66  }
67  return self::$record_field_cache[$rid][$fid];
68  }
69 
76  public static function getInstance($record, $field){
77  switch($field->getDatatypeId()){
79  return new ilDataCollectionRatingField($record, $field);
81  return new ilDataCollectionILIASRefField($record, $field);
83  if(!$field->isNRef())
84  return new ilDataCollectionReferenceField($record, $field);
85  else
86  return new ilDataCollectionNReferenceField($record, $field);
87  default:
88  return new ilDataCollectionRecordField($record, $field);
89  }
90  }
91 
92  public static function buildFieldFromRecord($rec){
94  if(isset($fields_cache[$rec["id"]])){
95  return $fields_cache[$rec["id"]];
96  }
97  $field = new ilDataCollectionField();
98  $field->setId($rec["id"]);
99  $field->setTableId($rec["table_id"]);
100  $field->setTitle($rec["title"]);
101  $field->setDescription($rec["description"]);
102  $field->setDatatypeId($rec["datatype_id"]);
103  $field->setRequired($rec["required"]);
104  $field->setUnique($rec["is_unique"]);
105  $field->setLocked($rec["is_locked"]);
106  $fields_cache[$rec["id"]] = $field;
107  return $field;
108  }
109 }