ILIAS  Release_5_0_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 require_once('class.ilDataCollectionReferenceField.php');
3 require_once('class.ilDataCollectionRatingField.php');
4 require_once('class.ilDataCollectionILIASRefField.php');
5 require_once('./Modules/DataCollection/classes/Field/Formula/class.ilDataCollectionFormulaField.php');
6 require_once('class.ilDataCollectionNReferenceField.php');
7 
15 
19  protected static $tables_cache;
23  protected static $fields_cache;
27  protected static $records_cache;
33  protected static $record_field_cache;
34 
35 
41  public static function getTableCache($table_id = 0) {
42  if ($table_id == 0) {
43  return new ilDataCollectionTable();
44  }
46  if (!isset($tables_cache[$table_id])) {
47  $tables_cache[$table_id] = new ilDataCollectionTable($table_id);
48  }
49 
50  return $tables_cache[$table_id];
51  }
52 
53 
59  public static function getFieldCache($field_id = 0) {
61  if (!isset($fields_cache[$field_id])) {
62  $fields_cache[$field_id] = new ilDataCollectionField($field_id);
63  }
64 
65  return $fields_cache[$field_id];
66  }
67 
68 
74  public static function getRecordCache($record_id = 0) {
76  if (!isset($records_cache[$record_id])) {
77  $records_cache[$record_id] = new ilDataCollectionRecord($record_id);
78  }
79 
80  return $records_cache[$record_id];
81  }
82 
83 
90  public static function getRecordFieldCache($record, $field) {
91  $fid = $field->getId();
92  $rid = $record->getId();
93  if (!isset(self::$record_field_cache[$rid])) {
94  self::$record_field_cache[$rid] = array();
95  self::$record_field_cache[$rid][$fid] = self::getInstance($record, $field);
96  } elseif (!isset(self::$record_field_cache[$rid][$fid])) {
97  self::$record_field_cache[$rid][$fid] = self::getInstance($record, $field);
98  }
99 
100  return self::$record_field_cache[$rid][$fid];
101  }
102 
103 
112  public static function getInstance($record, $field) {
113  switch ($field->getDatatypeId()) {
115  return new ilDataCollectionRatingField($record, $field);
117  return new ilDataCollectionILIASRefField($record, $field);
119  if (!$field->isNRef()) {
120  return new ilDataCollectionReferenceField($record, $field);
121  } else {
122  return new ilDataCollectionNReferenceField($record, $field);
123  }
125  return new ilDataCollectionFormulaField($record, $field);
126  default:
127  return new ilDataCollectionRecordField($record, $field);
128  }
129  }
130 
131 
137  public static function buildFieldFromRecord($rec) {
139  if (isset($fields_cache[$rec["id"]])) {
140  return $fields_cache[$rec["id"]];
141  }
142  $field = new ilDataCollectionField();
143  $field->setId($rec["id"]);
144  $field->setTableId($rec["table_id"]);
145  $field->setTitle($rec["title"]);
146  $field->setDescription($rec["description"]);
147  $field->setDatatypeId($rec["datatype_id"]);
148  $field->setRequired($rec["required"]);
149  $field->setUnique($rec["is_unique"]);
150  $field->setLocked($rec["is_locked"]);
151  $fields_cache[$rec["id"]] = $field;
152 
153  return $field;
154  }
155 }