ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilADTActiveRecordWrapper.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "Services/ActiveRecord/classes/class.ActiveRecord.php";
5 
18 {
19  protected $properties; // [ilADTGroupActiveRecordBridge]
20  protected $fields; // [arFieldList]
21  protected $field_element_map = []; // [array]
22 
29  public function __construct(ilADTGroupActiveRecordBridge $a_properties)
30  {
31  $this->properties = $a_properties;
32 
33  // see ActiveRecord::__construct();
34  $this->initFieldList();
35  $this->arConnector = new arConnectorDB();
36  }
37 
38 
39  //
40  // active record field(s)
41  //
42 
43  protected function getActiveRecordFieldTypeFromMDB2($a_mdb2_type)
44  {
45  // currently they are all the same
46  switch ($a_mdb2_type) {
47  case "integer":
49 
50  case "float":
52 
53  case "text":
55 
56  case "date":
58 
59  case "timestamp":
61 
62  case "integer":
64 
65  /*
66  case "clob":
67  return arField::FIELD_TYPE_CLOB;
68 
69  case "time":
70  return arField::FIELD_TYPE_TIME;
71  */
72  }
73  }
74 
78  protected function initFieldList()
79  {
80  require_once "Services/ActiveRecord/classes/Fields/class.arFieldList.php";
81  $this->fields = new arFieldList();
82 
83  // element => fields
84 
85  $fields = array();
86  foreach ($this->properties->getActiveRecordFields() as $element_id => $element_fields) {
87  foreach ($element_fields as $field) {
88  $this->field_element_map[$field->getName()] = $element_id;
89  }
90 
91  $fields = array_merge($fields, $element_fields);
92  }
93 
94  $this->fields->setFields($fields);
95 
96  // primary
97 
98  if (sizeof($this->properties->getPrimary()) > 1) {
99  throw new ilException("ilADTActiveRecordWrapper - no complex primary keys supported yet");
100  }
101 
102  foreach ($this->properties->getPrimary() as $primary_id => $primary_element) {
103  $field = new arField();
104  $field->setHasField(true);
105  $field->setNotNull(true);
106  $field->setFieldType($this->getActiveRecordFieldTypeFromMDB2($primary_element[0]));
107  $field->setName($primary_id);
108  $this->fields->setPrimaryField($field);
109  }
110  }
111 
112 
113  //
114  // active record meta (table/primary key)
115  //
116 
117  public function getConnectorContainerName()
118  {
119  return $this->properties->getTableName();
120  }
121 
122  public static function returnDbTableName()
123  {
124  // :TODO: cannot be static
125  }
126 
127  public function getPrimaryFieldValue()
128  {
129  $primary = array_shift($this->properties->getPrimary());
130  return $primary[1];
131  }
132 
133 
134  //
135  // active record CRUD
136  //
137 
138  public function sleep($field_name)
139  {
140  if (array_key_exists($field_name, $this->field_element_map)) {
141  $element = $this->properties->getElement($this->field_element_map[$field_name]);
142  return $element->getFieldValue($field_name);
143  }
144 
145  // returning NULL would result in direct property access!
146  return false;
147  }
148 
149  public function wakeUp($field_name, $field_value)
150  {
151  if (array_key_exists($field_name, $this->field_element_map)) {
152  $element = $this->properties->getElement($this->field_element_map[$field_name]);
153  return $element->setFieldValue($field_name, $field_value);
154  }
155 
156  // returning NULL would result in direct property access!
157  return false;
158  }
159 }
initFieldList()
Get field list instance for ADT group.
const FIELD_TYPE_FLOAT
Class arField.
ADT Active Record service wrapper class.
Class arConnectorDB.
Class ActiveRecord.
const FIELD_TYPE_TEXT
Class arConnector.
$errors fields
Definition: imgupload.php:51
const FIELD_TYPE_INTEGER
__construct(ilADTGroupActiveRecordBridge $a_properties)
Constructor.
const FIELD_TYPE_DATE
const FIELD_TYPE_TIMESTAMP
Create styles array
The data for the language used.
Class arFieldList.
Set document properties