ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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(
27  ),
28  self::FIELD_TYPE_INTEGER => array(
33  ),
34  self::FIELD_TYPE_FLOAT => array(
36  ),
37  self::FIELD_TYPE_DATE => array(
39  ),
40  self::FIELD_TYPE_TIME => array(
42  ),
43  self::FIELD_TYPE_TIMESTAMP => array(
45  ),
46  self::FIELD_TYPE_CLOB => array(
48  ),
49  );
53  protected static $date_fields = array(
54  self::FIELD_TYPE_DATE,
55  self::FIELD_TYPE_TIME,
56  self::FIELD_TYPE_TIMESTAMP
57  );
58 
59 
64  public function loadFromArray($name, array $array)
65  {
66  $this->setName($name);
67  foreach ($array as $key => $value) {
68  switch ($value) {
69  case 'true':
70  $this->{$key} = true;
71  break;
72  case 'false':
73  $this->{$key} = false;
74  break;
75  default:
76  $this->{$key} = $value;
77  break;
78  }
79  }
80  }
81 
82 
87  public function loadFromStdClass($name, stdClass $stdClass)
88  {
89  $array = (array) $stdClass;
90  $this->loadFromArray($name, $array);
91  }
92 
93 
97  public function getAttributesForConnector()
98  {
99  $return = array();
100  foreach (arFieldList::getAllowedConnectorFields() as $field_name) {
101  if (isset($this->{$field_name}) && $this->{$field_name} and self::isAllowedAttribute($this->getFieldType(), $field_name)) {
102  $return[arFieldList::mapKey($field_name)] = $this->{$field_name};
103  }
104  }
105 
106  return $return;
107  }
108 
109 
113  public function getAttributesForDescription()
114  {
115  $return = array();
116  foreach (arFieldList::getAllowedDescriptionFields() as $field_name) {
117  if ($this->{$field_name} and self::isAllowedAttribute($this->getFieldType(), $field_name)) {
118  $return[arFieldList::mapKey($field_name)] = $this->{$field_name};
119  }
120  }
121 
122  return $return;
123  }
124 
125 
129  public function isDateField()
130  {
131  return self::isDateFieldType($this->getFieldType());
132  }
133 
134 
138  protected $fieldtype;
142  protected $length = null;
146  protected $is_primary = false;
150  protected $name = '';
154  protected $not_null = false;
158  protected $has_field = false;
162  protected $sequence = false;
166  protected $index = false;
167 
168 
172  public function setFieldType($field_type)
173  {
174  $this->fieldtype = $field_type;
175  }
176 
177 
181  public function getFieldType()
182  {
183  return $this->fieldtype;
184  }
185 
186 
190  public function setHasField($has_field)
191  {
192  $this->has_field = $has_field;
193  }
194 
195 
199  public function getHasField()
200  {
201  return $this->has_field;
202  }
203 
204 
208  public function setLength($length)
209  {
210  $this->length = $length;
211  }
212 
213 
217  public function getLength()
218  {
219  return $this->length;
220  }
221 
222 
226  public function setName($name)
227  {
228  $this->name = $name;
229  }
230 
231 
235  public function getName()
236  {
237  return $this->name;
238  }
239 
240 
244  public function setNotNull($not_null)
245  {
246  $this->not_null = $not_null;
247  }
248 
249 
253  public function getNotNull()
254  {
255  return $this->not_null;
256  }
257 
258 
262  public function setPrimary($primary)
263  {
264  $this->is_primary = $primary;
265  }
266 
267 
271  public function getPrimary()
272  {
273  return $this->is_primary;
274  }
275 
276 
280  public function setSequence($sequence)
281  {
282  $this->sequence = $sequence;
283  }
284 
285 
289  public function getSequence()
290  {
291  return $this->sequence;
292  }
293 
294 
298  public function setIndex($index)
299  {
300  $this->index = $index;
301  }
302 
303 
307  public function getIndex()
308  {
309  return $this->index;
310  }
311 
312 
319  public static function isAllowedAttribute($type, $field_name)
320  {
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  {
336  return in_array($field_type, self::$date_fields);
337  }
338 }
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)
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)