ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.arField.php
Go to the documentation of this file.
1<?php
2
25{
26 public $not_null;
27 protected bool $is_unique = false;
28 public const FIELD_TYPE_TEXT = 'text'; // MySQL varchar, char
29 public const FIELD_TYPE_INTEGER = 'integer'; // MySQL tinyint, smallint, mediumint, int, bigint
30 public const FIELD_TYPE_FLOAT = 'float'; // MySQL double
31 public const FIELD_TYPE_DATE = 'date'; // MySQL date
32 public const FIELD_TYPE_TIME = 'time'; // MySQL time
33 public const FIELD_TYPE_TIMESTAMP = 'timestamp'; // MySQL datetime
34 public const FIELD_TYPE_CLOB = 'clob';
35 protected static array $allowed_attributes = [
36 self::FIELD_TYPE_TEXT => [
40 ],
41 self::FIELD_TYPE_INTEGER => [
46 ],
47 self::FIELD_TYPE_FLOAT => [arFieldList::IS_NOTNULL],
48 self::FIELD_TYPE_DATE => [arFieldList::IS_NOTNULL],
49 self::FIELD_TYPE_TIME => [arFieldList::IS_NOTNULL],
50 self::FIELD_TYPE_TIMESTAMP => [arFieldList::IS_NOTNULL],
51 self::FIELD_TYPE_CLOB => [arFieldList::IS_NOTNULL]
52 ];
54
55 public function loadFromArray(string $name, array $array): void
56 {
57 $this->setName($name);
58 foreach ($array as $key => $value) {
59 $this->{$key} = match ($value) {
60 'true' => true,
61 'false' => false,
62 default => $value,
63 };
64 }
65 }
66
67 public function loadFromStdClass(string $name, stdClass $stdClass): void
68 {
69 $array = (array) $stdClass;
70 $this->loadFromArray($name, $array);
71 }
72
76 public function getAttributesForConnector(): array
77 {
78 $return = [];
79 foreach (arFieldList::getAllowedConnectorFields() as $field_name) {
80 if (isset($this->{$field_name}) && $this->{$field_name} && self::isAllowedAttribute(
81 $this->getFieldType(),
82 $field_name
83 )) {
84 $return[arFieldList::mapKey($field_name)] = $this->{$field_name};
85 }
86 }
87
88 return $return;
89 }
90
94 public function getAttributesForDescription(): array
95 {
96 $return = [];
97 foreach (arFieldList::getAllowedDescriptionFields() as $field_name) {
98 if ($this->{$field_name} && self::isAllowedAttribute($this->getFieldType(), $field_name)) {
99 $return[arFieldList::mapKey($field_name)] = $this->{$field_name};
100 }
101 }
102
103 return $return;
104 }
105
106 public function isDateField(): bool
107 {
108 return self::isDateFieldType($this->getFieldType());
109 }
110
111 protected string $fieldtype;
112 protected ?int $length = null;
113 protected bool $is_primary = false;
114 protected string $name = '';
115 protected bool $is_notnull = false;
116 protected bool $has_field = false;
117 protected bool $sequence = false;
118 protected bool $index = false;
119
120 public function setFieldType(string $field_type): void
121 {
122 $this->fieldtype = $field_type;
123 }
124
125 public function getFieldType(): string
126 {
127 return $this->fieldtype;
128 }
129
130 public function setHasField(bool $has_field): void
131 {
132 $this->has_field = $has_field;
133 }
134
135 public function getHasField(): bool
136 {
137 return $this->has_field;
138 }
139
140 public function setLength(int $length): void
141 {
142 $this->length = $length;
143 }
144
145 public function getLength(): ?int
146 {
147 return $this->length;
148 }
149
150 public function setName(string $name): void
151 {
152 $this->name = $name;
153 }
154
155 public function getName(): string
156 {
157 return $this->name;
158 }
159
160 public function setNotNull(bool $not_null): void
161 {
162 $this->not_null = $not_null;
163 }
164
165 public function getNotNull(): bool
166 {
167 return $this->not_null;
168 }
169
170 public function setPrimary(bool $primary): void
171 {
172 $this->is_primary = $primary;
173 }
174
175 public function getPrimary(): bool
176 {
177 return $this->is_primary;
178 }
179
180 public function setSequence(bool $sequence): void
181 {
182 $this->sequence = $sequence;
183 }
184
185 public function getSequence(): bool
186 {
187 return $this->sequence;
188 }
189
190 public function setIndex(bool $index): void
191 {
192 $this->index = $index;
193 }
194
195 public function getIndex(): bool
196 {
197 return $this->index;
198 }
199
200 public static function isAllowedAttribute(string $type, string $field_name): bool
201 {
202 if ($field_name === arFieldList::FIELDTYPE) {
203 return true;
204 }
205 if ($field_name === arFieldList::HAS_FIELD) {
206 return true;
207 }
208 return in_array($field_name, self::$allowed_attributes[$type], true);
209 }
210
211 public static function isDateFieldType($field_type): bool
212 {
213 return in_array($field_type, self::$date_fields, true);
214 }
215}
static mapKey(string $key)
static getAllowedDescriptionFields()
static getAllowedConnectorFields()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
bool $is_notnull
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 $is_unique
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