ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
48  case "integer":
50 
51  case "float":
53 
54  case "text":
56 
57  case "date":
59 
60  case "timestamp":
62 
63  case "integer":
65 
66  /*
67  case "clob":
68  return arField::FIELD_TYPE_CLOB;
69 
70  case "time":
71  return arField::FIELD_TYPE_TIME;
72  */
73  }
74  }
75 
79  protected function initFieldList()
80  {
81  require_once "Services/ActiveRecord/classes/Fields/class.arFieldList.php";
82  $this->fields = new arFieldList();
83 
84  // element => fields
85 
86  $fields = array();
87  foreach($this->properties->getActiveRecordFields() as $element_id => $element_fields)
88  {
89  foreach($element_fields as $field)
90  {
91  $this->field_element_map[$field->getName()] = $element_id;
92  }
93 
94  $fields = array_merge($fields, $element_fields);
95  }
96 
97  $this->fields->setFields($fields);
98 
99  // primary
100 
101  if(sizeof($this->properties->getPrimary()) > 1)
102  {
103  throw new ilException("ilADTActiveRecordWrapper - no complex primary keys supported yet");
104  }
105 
106  foreach($this->properties->getPrimary() as $primary_id => $primary_element)
107  {
108  $field = new arField();
109  $field->setHasField(true);
110  $field->setNotNull(true);
111  $field->setFieldType($this->getActiveRecordFieldTypeFromMDB2($primary_element[0]));
112  $field->setName($primary_id);
113  $this->fields->setPrimaryField($field);
114  }
115  }
116 
117 
118  //
119  // active record meta (table/primary key)
120  //
121 
122  public function getConnectorContainerName()
123  {
124  return $this->properties->getTableName();
125  }
126 
127  public static function returnDbTableName()
128  {
129  // :TODO: cannot be static
130  }
131 
132  public function getPrimaryFieldValue()
133  {
134  $primary = array_shift($this->properties->getPrimary());
135  return $primary[1];
136  }
137 
138 
139  //
140  // active record CRUD
141  //
142 
143  public function sleep($field_name)
144  {
145  if(array_key_exists($field_name, $this->field_element_map))
146  {
147  $element = $this->properties->getElement($this->field_element_map[$field_name]);
148  return $element->getFieldValue($field_name);
149  }
150 
151  // returning NULL would result in direct property access!
152  return false;
153  }
154 
155  public function wakeUp($field_name, $field_value)
156  {
157  if(array_key_exists($field_name, $this->field_element_map))
158  {
159  $element = $this->properties->getElement($this->field_element_map[$field_name]);
160  return $element->setFieldValue($field_name, $field_value);
161  }
162 
163  // returning NULL would result in direct property access!
164  return false;
165  }
166 }
167 
168 ?>
initFieldList()
Get field list instance for ADT group.
const FIELD_TYPE_FLOAT
Class arField.
ADT Active Record service wrapper class.
Base class for ILIAS Exception handling.
Class arConnectorDB.
Class ActiveRecord.
const FIELD_TYPE_TEXT
Class arConnector.
$errors fields
Definition: imgupload.php:52
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