ILIAS  release_7 Revision v7.30-3-g800a261c036
class.arFieldList.php
Go to the documentation of this file.
1<?php
2require_once('class.arField.php');
3
12{
13 const HAS_FIELD = 'has_field';
14 const IS_PRIMARY = 'is_primary';
15 const IS_NOTNULL = 'is_notnull';
16 const FIELDTYPE = 'fieldtype';
17 const LENGTH = 'length';
18 const SEQUENCE = 'sequence';
19 const INDEX = 'index';
23 protected static $prefixes = array( 'db', 'con' );
27 protected static $protected_names = array( 'arConnector', 'arFieldList' );
31 protected static $allowed_description_fields = array(
32 'is_unique', // There are many classes which already use this (without any function)
33 self::IS_PRIMARY,
34 self::IS_NOTNULL,
35 self::FIELDTYPE,
36 self::LENGTH,
37 self::SEQUENCE,
38 self::INDEX
39 );
43 protected static $allowed_connector_fields = array(
44 self::IS_NOTNULL,
45 self::FIELDTYPE,
46 self::LENGTH,
47 );
51 protected $primary_field;
55 protected $primary_fields = array();
59 protected $raw_fields = array();
63 protected $fields = array();
67 protected $ar;
71 protected static $key_maps = array(
72 self::FIELDTYPE => 'type',
73 self::IS_NOTNULL => 'notnull',
74 );
75
76
82 public function __construct(ActiveRecord $ar)
83 {
84 $this->ar = $ar;
85 }
86
87
93 public static function mapKey($key)
94 {
95 if (isset(self::$key_maps[$key])) {
96 return self::$key_maps[$key];
97 }
98
99 return $key;
100 }
101
102
106 public static function getAllowedConnectorFields()
107 {
109 }
110
111
115 public static function getAllowedDescriptionFields()
116 {
118 }
119
120
121
127 public static function getInstance(ActiveRecord $ar)
128 {
129 $arFieldList = new self($ar);
130 $arFieldList->initRawFields($ar);
131 $arFieldList->initFields();
132
133 return $arFieldList;
134 }
135
136
143 public static function getInstanceFromStorage($ar)
144 {
145 $arFieldList = new self();
146 $arFieldList->initRawFields($ar);
147 $arFieldList->initFields();
148
149 return $arFieldList;
150 }
151
152
156 public function getArrayForConnector()
157 {
158 $return = array();
159 foreach ($this->getFields() as $field) {
160 $return[$field->getName()] = $field->getAttributesForConnector();
161 }
162
163 return $return;
164 }
165
166
167 protected function initFields()
168 {
169 foreach ($this->getRawFields() as $fieldname => $attributes) {
170 if (self::checkAttributes($attributes)) {
171 $arField = new arField();
172 $arField->getHasField();
173 $arField->loadFromArray($fieldname, $attributes);
174 $this->fields[] = $arField;
175 if ($arField->getPrimary()) {
176 $this->setPrimaryField($arField);
177 }
178 }
179 }
180 }
181
182
188 public function getFieldByName($field_name)
189 {
190 $field = null;
191 static $field_map;
192 $field_key = $this->ar->getConnectorContainerName() . '.' . $field_name;
193 if (is_array($field_map) && array_key_exists($field_key, $field_map)) {
194 return $field_map[$field_key];
195 }
196 foreach ($this->getFields() as $field) {
197 if ($field->getName() == $field_name) {
198 $field_map[$field_key] = $field;
199
200 return $field;
201 }
202 }
203 }
204
205
211 public function isField($field_name)
212 {
213 $is_field = false;
214 foreach ($this->getFields() as $field) {
215 if ($field->getName() == $field_name) {
216 $is_field = true;
217 }
218 }
219
220 return $is_field;
221 }
222
223
227 public function getPrimaryFieldName()
228 {
229 return $this->getPrimaryField()->getName();
230 }
231
232
236 public function getPrimaryFieldType()
237 {
238 return $this->getPrimaryField()->getFieldType();
239 }
240
241
248 {
249 $regex = "/[ ]*\\* @(" . implode('|', self::$prefixes) . ")_([a-zA-Z0-9_]*)[ ]*([a-zA-Z0-9_]*)/u";
250 $reflectionClass = new ReflectionClass($ar);
251 $raw_fields = array();
252 foreach ($reflectionClass->getProperties() as $property) {
253 if (in_array($property->getName(), self::$protected_names)) {
254 continue;
255 }
256 $properties_array = array();
257 $has_property = false;
258 foreach (explode("\n", $property->getDocComment()) as $line) {
259 if (preg_match($regex, $line, $matches)) {
260 $has_property = true;
261 $properties_array[(string) $matches[2]] = $matches[3];
262 }
263 }
264 if ($has_property) {
265 $raw_fields[$property->getName()] = $properties_array;
266 }
267 }
268
270 }
271
272
278 protected static function isAllowedAttribute($attribute_name)
279 {
280 return in_array($attribute_name, array_merge(self::$allowed_description_fields, array( self::HAS_FIELD )));
281 }
282
283
289 protected static function checkAttributes(array $attributes)
290 {
291 if (isset($attributes[self::HAS_FIELD]) && $attributes[self::HAS_FIELD] === 'true') {
292 foreach (array_keys($attributes) as $atr) {
293 if (!self::isAllowedAttribute($atr)) {
294 return false;
295 }
296 }
297 } else {
298 return false;
299 }
300
301 return true;
302 }
303
304
308 public function setFields($fields)
309 {
310 $this->fields = $fields;
311 }
312
313
317 public function getFields()
318 {
319 return $this->fields;
320 }
321
322
327 {
328 $this->primary_field = $primary_field;
329 }
330
331
335 public function getPrimaryField()
336 {
338 }
339
340
344 public function setRawFields($raw_fields)
345 {
346 $this->raw_fields = $raw_fields;
347 }
348
349
353 public function getRawFields()
354 {
355 return $this->raw_fields;
356 }
357
358
363 {
364 $this->primary_fields = $primary_fields;
365 }
366
367
371 public function getPrimaryFields()
372 {
374 }
375}
Class ActiveRecord.
An exception for terminatinating execution or to throw for unit testing.
Class arFieldList.
static mapKey($key)
setPrimaryField($primary_field)
__construct(ActiveRecord $ar)
arFieldList constructor.
static checkAttributes(array $attributes)
static $allowed_description_fields
static getInstanceFromStorage($ar)
static getAllowedDescriptionFields()
static getInstance(ActiveRecord $ar)
static $allowed_connector_fields
initRawFields(arStorageInterface $ar)
setRawFields($raw_fields)
static isAllowedAttribute($attribute_name)
static $protected_names
getFieldByName($field_name)
static getAllowedConnectorFields()
setPrimaryFields($primary_fields)
isField($field_name)
Class arField.
$errors fields
Definition: imgupload.php:51
Class arStorageInterface.
$attributes
Definition: metadata.php:231