ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.arField.php
Go to the documentation of this file.
1 <?php
2 
10 class arField {
11 
12  const FIELD_TYPE_TEXT = 'text'; // MySQL varchar, char
13  const FIELD_TYPE_INTEGER = 'integer'; // MySQL tinyint, smallint, mediumint, int, bigint
14  const FIELD_TYPE_FLOAT = 'float'; // MySQL double
15  const FIELD_TYPE_DATE = 'date'; // MySQL date
16  const FIELD_TYPE_TIME = 'time'; // MySQL time
17  const FIELD_TYPE_TIMESTAMP = 'timestamp'; // MySQL datetime
18  const FIELD_TYPE_CLOB = 'clob'; // MySQL longtext
22  protected static $allowed_attributes = array(
23  self::FIELD_TYPE_TEXT => array(
28  ),
29  self::FIELD_TYPE_INTEGER => array(
35  ),
36  self::FIELD_TYPE_FLOAT => array(
38  ),
39  self::FIELD_TYPE_DATE => array(
41  ),
42  self::FIELD_TYPE_TIME => array(
44  ),
45  self::FIELD_TYPE_TIMESTAMP => array(
47  ),
48  self::FIELD_TYPE_CLOB => array(
50  ),
51  );
55  protected static $date_fields = array(
56  self::FIELD_TYPE_DATE,
57  self::FIELD_TYPE_TIME,
58  self::FIELD_TYPE_TIMESTAMP
59  );
60 
61 
66  public function loadFromArray($name, array $array) {
67  $this->setName($name);
68  foreach ($array as $key => $value) {
69  switch ($value) {
70  case 'true':
71  $this->{$key} = true;
72  break;
73  case 'false':
74  $this->{$key} = false;
75  break;
76  default:
77  $this->{$key} = $value;
78  break;
79  }
80  }
81  }
82 
83 
88  public function loadFromStdClass($name, stdClass $stdClass) {
89  $array = (array)$stdClass;
90  $this->loadFromArray($name, $array);
91  }
92 
93 
97  public function getAttributesForConnector() {
98  $return = array();
99  foreach (arFieldList::getAllowedConnectorFields() as $field_name) {
100  if (isset($this->{$field_name}) && $this->{$field_name} AND self::isAllowedAttribute($this->getFieldType(), $field_name)) {
101  $return[arFieldList::mapKey($field_name)] = $this->{$field_name};
102  }
103  }
104 
105  return $return;
106  }
107 
108 
112  public function getAttributesForDescription() {
113  $return = array();
114  foreach (arFieldList::getAllowedDescriptionFields() as $field_name) {
115  if ($this->{$field_name} AND self::isAllowedAttribute($this->getFieldType(), $field_name)) {
116  $return[arFieldList::mapKey($field_name)] = $this->{$field_name};
117  }
118  }
119 
120  return $return;
121  }
122 
123 
127  public function isDateField() {
128  return self::isDateFieldType($this->getFieldType());
129  }
130 
131 
135  protected $fieldtype;
139  protected $length = NULL;
143  protected $is_primary = false;
147  protected $name = '';
151  protected $not_null = false;
155  protected $unique = false;
159  protected $has_field = false;
163  protected $sequence = false;
167  protected $index = false;
168 
169 
173  public function setFieldType($field_type) {
174  $this->fieldtype = $field_type;
175  }
176 
177 
181  public function getFieldType() {
182  return $this->fieldtype;
183  }
184 
185 
189  public function setHasField($has_field) {
190  $this->has_field = $has_field;
191  }
192 
193 
197  public function getHasField() {
198  return $this->has_field;
199  }
200 
201 
205  public function setLength($length) {
206  $this->length = $length;
207  }
208 
209 
213  public function getLength() {
214  return $this->length;
215  }
216 
217 
221  public function setName($name) {
222  $this->name = $name;
223  }
224 
225 
229  public function getName() {
230  return $this->name;
231  }
232 
233 
237  public function setNotNull($not_null) {
238  $this->not_null = $not_null;
239  }
240 
241 
245  public function getNotNull() {
246  return $this->not_null;
247  }
248 
249 
253  public function setPrimary($primary) {
254  $this->is_primary = $primary;
255  }
256 
257 
261  public function getPrimary() {
262  return $this->is_primary;
263  }
264 
265 
269  public function setUnique($unique) {
270  $this->unique = $unique;
271  }
272 
273 
277  public function getUnique() {
278  return $this->unique;
279  }
280 
281 
285  public function setSequence($sequence) {
286  $this->sequence = $sequence;
287  }
288 
289 
293  public function getSequence() {
294  return $this->sequence;
295  }
296 
297 
301  public function setIndex($index) {
302  $this->index = $index;
303  }
304 
305 
309  public function getIndex() {
310  return $this->index;
311  }
312 
313 
320  public static function isAllowedAttribute($type, $field_name) {
321  if ($field_name == arFieldList::FIELDTYPE OR $field_name == arFieldList::HAS_FIELD) {
322  return true;
323  }
324 
325  return in_array($field_name, self::$allowed_attributes[$type]);
326  }
327 
328 
334  public static function isDateFieldType($field_type) {
335  return in_array($field_type, self::$date_fields);
336  }
337 }
338 
339 ?>