ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.arFieldList.php
Go to the documentation of this file.
1 <?php
2 require_once('class.arField.php');
3 
12 {
13  const HAS_FIELD = 'has_field';
14  const IS_UNIQUE = 'is_unique';
15  const IS_PRIMARY = 'is_primary';
16  const IS_NOTNULL = 'is_notnull';
17  const FIELDTYPE = 'fieldtype';
18  const LENGTH = 'length';
19  const SEQUENCE = 'sequence';
20  const INDEX = 'index';
24  protected static $prefixes = array( 'db', 'con' );
28  protected static $protected_names = array( 'arConnector', 'arFieldList' );
32  protected static $allowed_description_fields = array(
33  self::IS_UNIQUE,
34  self::IS_PRIMARY,
35  self::IS_NOTNULL,
36  self::FIELDTYPE,
37  self::LENGTH,
38  self::SEQUENCE,
39  self::INDEX,
40  );
44  protected static $allowed_connector_fields = array(
45  self::IS_NOTNULL,
46  self::FIELDTYPE,
47  self::LENGTH,
48  );
52  protected $primary_field;
56  protected $primary_fields = array();
60  protected $raw_fields = array();
64  protected $fields = array();
68  protected $ar;
72  protected static $key_maps = array(
73  self::FIELDTYPE => 'type',
74  self::IS_NOTNULL => 'notnull',
75  );
76 
77 
83  public function __construct(ActiveRecord $ar)
84  {
85  $this->ar = $ar;
86  }
87 
88 
94  public static function mapKey($key)
95  {
96  if (isset(self::$key_maps[$key])) {
97  return self::$key_maps[$key];
98  }
99 
100  return $key;
101  }
102 
103 
107  public static function getAllowedConnectorFields()
108  {
109  return self::$allowed_connector_fields;
110  }
111 
112 
116  public static function getAllowedDescriptionFields()
117  {
118  return self::$allowed_description_fields;
119  }
120 
121 
122 
128  public static function getInstance(ActiveRecord $ar)
129  {
130  $arFieldList = new self($ar);
131  $arFieldList->initRawFields($ar);
132  $arFieldList->initFields();
133 
134  return $arFieldList;
135  }
136 
137 
144  public static function getInstanceFromStorage($ar)
145  {
146  $arFieldList = new self();
147  $arFieldList->initRawFields($ar);
148  $arFieldList->initFields();
149 
150  return $arFieldList;
151  }
152 
153 
157  public function getArrayForConnector()
158  {
159  $return = array();
160  foreach ($this->getFields() as $field) {
161  $return[$field->getName()] = $field->getAttributesForConnector();
162  }
163 
164  return $return;
165  }
166 
167 
168  protected function initFields()
169  {
170  foreach ($this->getRawFields() as $fieldname => $attributes) {
171  if (self::checkAttributes($attributes)) {
172  $arField = new arField();
173  $arField->getHasField(true);
174  $arField->loadFromArray($fieldname, $attributes);
175  $this->fields[] = $arField;
176  if ($arField->getPrimary()) {
177  $this->setPrimaryField($arField);
178  }
179  }
180  }
181  }
182 
183 
189  public function getFieldByName($field_name)
190  {
191  $field = null;
192  static $field_map;
193  $field_key = $this->ar->getConnectorContainerName() . '.' . $field_name;
194  if ($field_map[$field_key]) {
195  return $field_map[$field_key];
196  }
197  foreach ($this->getFields() as $field) {
198  if ($field->getName() == $field_name) {
199  $field_map[$field_key] = $field;
200 
201  return $field;
202  }
203  }
204  }
205 
206 
212  public function isField($field_name)
213  {
214  $is_field = false;
215  foreach ($this->getFields() as $field) {
216  if ($field->getName() == $field_name) {
217  $is_field = true;
218  }
219  }
220 
221  return $is_field;
222  }
223 
224 
228  public function getPrimaryFieldName()
229  {
230  return $this->getPrimaryField()->getName();
231  }
232 
233 
237  public function getPrimaryFieldType()
238  {
239  return $this->getPrimaryField()->getFieldType();
240  }
241 
242 
249  {
250  $regex = "/[ ]*\\* @(" . implode('|', self::$prefixes) . ")_([a-zA-Z0-9_]*)[ ]*([a-zA-Z0-9_]*)/u";
251  $reflectionClass = new ReflectionClass($ar);
252  $raw_fields = array();
253  foreach ($reflectionClass->getProperties() as $property) {
254  if (in_array($property->getName(), self::$protected_names)) {
255  continue;
256  }
257  $properties_array = array();
258  $has_property = false;
259  foreach (explode("\n", $property->getDocComment()) as $line) {
260  if (preg_match($regex, $line, $matches)) {
261  $has_property = true;
262  $properties_array[(string) $matches[2]] = $matches[3];
263  }
264  }
265  if ($has_property) {
266  $raw_fields[$property->getName()] = $properties_array;
267  }
268  }
269 
270  $this->setRawFields($raw_fields);
271  }
272 
273 
279  protected static function isAllowedAttribute($attribute_name)
280  {
281  return in_array($attribute_name, array_merge(self::$allowed_description_fields, array( self::HAS_FIELD )));
282  }
283 
284 
290  protected static function checkAttributes(array $attributes)
291  {
292  if (isset($attributes[self::HAS_FIELD]) && $attributes[self::HAS_FIELD] === 'true') {
293  foreach (array_keys($attributes) as $atr) {
294  if (!self::isAllowedAttribute($atr)) {
295  return false;
296  }
297  }
298  } else {
299  return false;
300  }
301 
302  return true;
303  }
304 
305 
309  public function setFields($fields)
310  {
311  $this->fields = $fields;
312  }
313 
314 
318  public function getFields()
319  {
320  return $this->fields;
321  }
322 
323 
328  {
329  $this->primary_field = $primary_field;
330  }
331 
332 
336  public function getPrimaryField()
337  {
338  return $this->primary_field;
339  }
340 
341 
345  public function setRawFields($raw_fields)
346  {
347  $this->raw_fields = $raw_fields;
348  }
349 
350 
354  public function getRawFields()
355  {
356  return $this->raw_fields;
357  }
358 
359 
364  {
365  $this->primary_fields = $primary_fields;
366  }
367 
368 
372  public function getPrimaryFields()
373  {
374  return $this->primary_fields;
375  }
376 }
Class arField.
Add rich text string
Class arStorageInterface.
getFieldByName($field_name)
setRawFields($raw_fields)
static getInstance(ActiveRecord $ar)
static $protected_names
Class ActiveRecord.
static $allowed_description_fields
setPrimaryFields($primary_fields)
static mapKey($key)
static getAllowedConnectorFields()
$attributes
initRawFields(arStorageInterface $ar)
static isAllowedAttribute($attribute_name)
setPrimaryField($primary_field)
$errors fields
Definition: imgupload.php:51
static $allowed_connector_fields
static getInstanceFromStorage($ar)
Create styles array
The data for the language used.
Class arFieldList.
static checkAttributes(array $attributes)
isField($field_name)
static getAllowedDescriptionFields()
__construct(ActiveRecord $ar)
arFieldList constructor.
$key
Definition: croninfo.php:18