ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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(
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  {
68  $this->setName($name);
69  foreach ($array as $key => $value) {
70  switch ($value) {
71  case 'true':
72  $this->{$key} = true;
73  break;
74  case 'false':
75  $this->{$key} = false;
76  break;
77  default:
78  $this->{$key} = $value;
79  break;
80  }
81  }
82  }
83 
84 
89  public function loadFromStdClass($name, stdClass $stdClass)
90  {
91  $array = (array) $stdClass;
92  $this->loadFromArray($name, $array);
93  }
94 
95 
99  public function getAttributesForConnector()
100  {
101  $return = array();
102  foreach (arFieldList::getAllowedConnectorFields() as $field_name) {
103  if (isset($this->{$field_name}) && $this->{$field_name} and self::isAllowedAttribute($this->getFieldType(), $field_name)) {
104  $return[arFieldList::mapKey($field_name)] = $this->{$field_name};
105  }
106  }
107 
108  return $return;
109  }
110 
111 
115  public function getAttributesForDescription()
116  {
117  $return = array();
118  foreach (arFieldList::getAllowedDescriptionFields() as $field_name) {
119  if ($this->{$field_name} and self::isAllowedAttribute($this->getFieldType(), $field_name)) {
120  $return[arFieldList::mapKey($field_name)] = $this->{$field_name};
121  }
122  }
123 
124  return $return;
125  }
126 
127 
131  public function isDateField()
132  {
133  return self::isDateFieldType($this->getFieldType());
134  }
135 
136 
140  protected $fieldtype;
144  protected $length = null;
148  protected $is_primary = false;
152  protected $name = '';
156  protected $not_null = false;
160  protected $unique = false;
164  protected $has_field = false;
168  protected $sequence = false;
172  protected $index = false;
173 
174 
178  public function setFieldType($field_type)
179  {
180  $this->fieldtype = $field_type;
181  }
182 
183 
187  public function getFieldType()
188  {
189  return $this->fieldtype;
190  }
191 
192 
196  public function setHasField($has_field)
197  {
198  $this->has_field = $has_field;
199  }
200 
201 
205  public function getHasField()
206  {
207  return $this->has_field;
208  }
209 
210 
214  public function setLength($length)
215  {
216  $this->length = $length;
217  }
218 
219 
223  public function getLength()
224  {
225  return $this->length;
226  }
227 
228 
232  public function setName($name)
233  {
234  $this->name = $name;
235  }
236 
237 
241  public function getName()
242  {
243  return $this->name;
244  }
245 
246 
250  public function setNotNull($not_null)
251  {
252  $this->not_null = $not_null;
253  }
254 
255 
259  public function getNotNull()
260  {
261  return $this->not_null;
262  }
263 
264 
268  public function setPrimary($primary)
269  {
270  $this->is_primary = $primary;
271  }
272 
273 
277  public function getPrimary()
278  {
279  return $this->is_primary;
280  }
281 
282 
286  public function setUnique($unique)
287  {
288  $this->unique = $unique;
289  }
290 
291 
295  public function getUnique()
296  {
297  return $this->unique;
298  }
299 
300 
304  public function setSequence($sequence)
305  {
306  $this->sequence = $sequence;
307  }
308 
309 
313  public function getSequence()
314  {
315  return $this->sequence;
316  }
317 
318 
322  public function setIndex($index)
323  {
324  $this->index = $index;
325  }
326 
327 
331  public function getIndex()
332  {
333  return $this->index;
334  }
335 
336 
343  public static function isAllowedAttribute($type, $field_name)
344  {
345  if ($field_name == arFieldList::FIELDTYPE or $field_name == arFieldList::HAS_FIELD) {
346  return true;
347  }
348 
349  return in_array($field_name, self::$allowed_attributes[$type]);
350  }
351 
352 
358  public static function isDateFieldType($field_type)
359  {
360  return in_array($field_type, self::$date_fields);
361  }
362 }
const FIELD_TYPE_FLOAT
Class arField.
setIndex($index)
static $date_fields
const FIELD_TYPE_CLOB
$type
static mapKey($key)
static getAllowedConnectorFields()
const FIELD_TYPE_TEXT
static isAllowedAttribute($type, $field_name)
loadFromArray($name, array $array)
const FIELD_TYPE_INTEGER
setLength($length)
const FIELD_TYPE_DATE
setPrimary($primary)
static $allowed_attributes
const FIELD_TYPE_TIMESTAMP
setName($name)
loadFromStdClass($name, stdClass $stdClass)
setUnique($unique)
Create styles array
The data for the language used.
setFieldType($field_type)
static getAllowedDescriptionFields()
const FIELD_TYPE_TIME
setHasField($has_field)
getAttributesForConnector()
setNotNull($not_null)
const FIELD_TYPE_TEXT
setSequence($sequence)
getAttributesForDescription()
$key
Definition: croninfo.php:18
static isDateFieldType($field_type)