ILIAS  release_8 Revision v8.24
class.arField.php
Go to the documentation of this file.
1<?php
2
3/******************************************************************************
4 *
5 * This file is part of ILIAS, a powerful learning management system.
6 *
7 * ILIAS is licensed with the GPL-3.0, you should have received a copy
8 * of said license along with the source code.
9 *
10 * If this is not the case or you just want to try ILIAS, you'll find
11 * us at:
12 * https://www.ilias.de
13 * https://github.com/ILIAS-eLearning
14 *
15 *****************************************************************************/
22{
23 public const FIELD_TYPE_TEXT = 'text'; // MySQL varchar, char
24 public const FIELD_TYPE_INTEGER = 'integer'; // MySQL tinyint, smallint, mediumint, int, bigint
25 public const FIELD_TYPE_FLOAT = 'float'; // MySQL double
26 public const FIELD_TYPE_DATE = 'date'; // MySQL date
27 public const FIELD_TYPE_TIME = 'time'; // MySQL time
28 public const FIELD_TYPE_TIMESTAMP = 'timestamp'; // MySQL datetime
29 public const FIELD_TYPE_CLOB = 'clob';
30 protected static array $allowed_attributes = array(
31 self::FIELD_TYPE_TEXT => array(
35 ),
36 self::FIELD_TYPE_INTEGER => array(
41 ),
42 self::FIELD_TYPE_FLOAT => array(
44 ),
45 self::FIELD_TYPE_DATE => array(
47 ),
48 self::FIELD_TYPE_TIME => array(
50 ),
51 self::FIELD_TYPE_TIMESTAMP => array(
53 ),
54 self::FIELD_TYPE_CLOB => array(
56 ),
57 );
58 protected static array $date_fields = array(
59 self::FIELD_TYPE_DATE,
60 self::FIELD_TYPE_TIME,
61 self::FIELD_TYPE_TIMESTAMP
62 );
63
64 public function loadFromArray(string $name, array $array): void
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 public function loadFromStdClass(string $name, stdClass $stdClass): void
83 {
84 $array = (array) $stdClass;
85 $this->loadFromArray($name, $array);
86 }
87
91 public function getAttributesForConnector(): array
92 {
93 $return = array();
94 foreach (arFieldList::getAllowedConnectorFields() as $field_name) {
95 if (isset($this->{$field_name}) && $this->{$field_name} && self::isAllowedAttribute(
96 $this->getFieldType(),
97 $field_name
98 )) {
99 $return[arFieldList::mapKey($field_name)] = $this->{$field_name};
100 }
101 }
102
103 return $return;
104 }
105
109 public function getAttributesForDescription(): array
110 {
111 $return = array();
112 foreach (arFieldList::getAllowedDescriptionFields() as $field_name) {
113 if ($this->{$field_name} && self::isAllowedAttribute($this->getFieldType(), $field_name)) {
114 $return[arFieldList::mapKey($field_name)] = $this->{$field_name};
115 }
116 }
117
118 return $return;
119 }
120
121 public function isDateField(): bool
122 {
123 return self::isDateFieldType($this->getFieldType());
124 }
125
129 protected string $fieldtype;
130 protected ?int $length = null;
131 protected bool $is_primary = false;
132 protected string $name = '';
133 protected bool $not_null = false;
134 protected bool $has_field = false;
135 protected bool $sequence = false;
136 protected bool $index = false;
137
138 public function setFieldType(string $field_type): void
139 {
140 $this->fieldtype = $field_type;
141 }
142
143 public function getFieldType(): string
144 {
145 return $this->fieldtype;
146 }
147
148 public function setHasField(bool $has_field): void
149 {
150 $this->has_field = $has_field;
151 }
152
153 public function getHasField(): bool
154 {
155 return $this->has_field;
156 }
157
158 public function setLength(int $length): void
159 {
160 $this->length = $length;
161 }
162
163 public function getLength(): ?int
164 {
165 return $this->length;
166 }
167
168 public function setName(string $name): void
169 {
170 $this->name = $name;
171 }
172
173 public function getName(): string
174 {
175 return $this->name;
176 }
177
178 public function setNotNull(bool $not_null): void
179 {
180 $this->not_null = $not_null;
181 }
182
183 public function getNotNull(): bool
184 {
185 return $this->not_null;
186 }
187
188 public function setPrimary(bool $primary): void
189 {
190 $this->is_primary = $primary;
191 }
192
193 public function getPrimary(): bool
194 {
195 return $this->is_primary;
196 }
197
198 public function setSequence(bool $sequence): void
199 {
200 $this->sequence = $sequence;
201 }
202
203 public function getSequence(): bool
204 {
205 return $this->sequence;
206 }
207
208 public function setIndex(bool $index): void
209 {
210 $this->index = $index;
211 }
212
213 public function getIndex(): bool
214 {
215 return $this->index;
216 }
217
218 public static function isAllowedAttribute(string $type, string $field_name): bool
219 {
220 if ($field_name === arFieldList::FIELDTYPE || $field_name === arFieldList::HAS_FIELD) {
221 return true;
222 }
223
224 return in_array($field_name, self::$allowed_attributes[$type], true);
225 }
226
227 public static function isDateFieldType($field_type): bool
228 {
229 return in_array($field_type, self::$date_fields, true);
230 }
231}
static mapKey(string $key)
static getAllowedDescriptionFields()
static getAllowedConnectorFields()
Class arField.
setLength(int $length)
string $name
bool $has_field
setIndex(bool $index)
const FIELD_TYPE_TEXT
const FIELD_TYPE_FLOAT
setSequence(bool $sequence)
bool $sequence
setFieldType(string $field_type)
bool $is_primary
const FIELD_TYPE_DATE
const FIELD_TYPE_TIME
setNotNull(bool $not_null)
const FIELD_TYPE_INTEGER
static array $allowed_attributes
const FIELD_TYPE_TIMESTAMP
static isDateFieldType($field_type)
setName(string $name)
static isAllowedAttribute(string $type, string $field_name)
getAttributesForDescription()
bool $not_null
loadFromArray(string $name, array $array)
setPrimary(bool $primary)
string $fieldtype
loadFromStdClass(string $name, stdClass $stdClass)
setHasField(bool $has_field)
getAttributesForConnector()
const FIELD_TYPE_CLOB
static array $date_fields
string $key
Consumer key/client ID value.
Definition: System.php:193
$type