Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
TaskAttributeType | |
0.00% |
0 / 22 |
|
0.00% |
0 / 7 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
setL11n | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
getL11n | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
setFields | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDefaults | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toArray | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package Modules\Tasks\Models |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace Modules\Tasks\Models; |
16 | |
17 | use phpOMS\Localization\BaseStringL11n; |
18 | use phpOMS\Localization\ISO639x1Enum; |
19 | |
20 | /** |
21 | * Task Attribute Type class. |
22 | * |
23 | * @package Modules\Tasks\Models |
24 | * @license OMS License 2.0 |
25 | * @link https://jingga.app |
26 | * @since 1.0.0 |
27 | */ |
28 | class TaskAttributeType implements \JsonSerializable |
29 | { |
30 | /** |
31 | * Id |
32 | * |
33 | * @var int |
34 | * @since 1.0.0 |
35 | */ |
36 | public int $id = 0; |
37 | |
38 | /** |
39 | * Name/string identifier by which it can be found/categorized |
40 | * |
41 | * @var string |
42 | * @since 1.0.0 |
43 | */ |
44 | public string $name = ''; |
45 | |
46 | /** |
47 | * Which field data type is required (string, int, ...) in the value |
48 | * |
49 | * @var int |
50 | * @since 1.0.0 |
51 | */ |
52 | public int $fields = 0; |
53 | |
54 | /** |
55 | * Is a custom value allowed (e.g. custom string) |
56 | * |
57 | * @var bool |
58 | * @since 1.0.0 |
59 | */ |
60 | public bool $custom = false; |
61 | |
62 | public string $validationPattern = ''; |
63 | |
64 | public bool $isRequired = false; |
65 | |
66 | /** |
67 | * Datatype of the attribute |
68 | * |
69 | * @var int |
70 | * @since 1.0.0 |
71 | */ |
72 | public int $datatype = AttributeValueType::_STRING; |
73 | |
74 | /** |
75 | * Localization |
76 | * |
77 | * @var BaseStringL11n |
78 | */ |
79 | public string | BaseStringL11n $l11n = ''; |
80 | |
81 | /** |
82 | * Possible default attribute values |
83 | * |
84 | * @var array |
85 | */ |
86 | public array $defaults = []; |
87 | |
88 | /** |
89 | * Default attribute value |
90 | * |
91 | * @var int |
92 | * @since 1.0.0 |
93 | */ |
94 | public int $default = 0; |
95 | |
96 | /** |
97 | * Constructor. |
98 | * |
99 | * @param string $name Name/identifier of the attribute type |
100 | * |
101 | * @since 1.0.0 |
102 | */ |
103 | public function __construct(string $name = '') |
104 | { |
105 | $this->name = $name; |
106 | } |
107 | |
108 | /** |
109 | * Set l11n |
110 | * |
111 | * @param string|BaseStringL11n $l11n Tag article l11n |
112 | * @param string $lang Language |
113 | * |
114 | * @return void |
115 | * |
116 | * @since 1.0.0 |
117 | */ |
118 | public function setL11n(string | BaseStringL11n $l11n, string $lang = ISO639x1Enum::_EN) : void |
119 | { |
120 | if ($l11n instanceof BaseStringL11n) { |
121 | $this->l11n = $l11n; |
122 | } elseif (isset($this->l11n) && $this->l11n instanceof BaseStringL11n) { |
123 | $this->l11n->content = $l11n; |
124 | $this->l11n->setLanguage($lang); |
125 | } else { |
126 | $this->l11n = new BaseStringL11n(); |
127 | $this->l11n->content = $l11n; |
128 | $this->l11n->setLanguage($lang); |
129 | } |
130 | } |
131 | |
132 | /** |
133 | * @return string |
134 | * |
135 | * @since 1.0.0 |
136 | */ |
137 | public function getL11n() : string |
138 | { |
139 | if (!isset($this->l11n)) { |
140 | return ''; |
141 | } |
142 | |
143 | return $this->l11n instanceof BaseStringL11n ? $this->l11n->content : $this->l11n; |
144 | } |
145 | |
146 | /** |
147 | * Set fields |
148 | * |
149 | * @param int $fields Fields |
150 | * |
151 | * @return void |
152 | * |
153 | * @since 1.0.0 |
154 | */ |
155 | public function setFields(int $fields) : void |
156 | { |
157 | $this->fields = $fields; |
158 | } |
159 | |
160 | /** |
161 | * Get default values |
162 | * |
163 | * @return array |
164 | * |
165 | * @sicne 1.0.0 |
166 | */ |
167 | public function getDefaults() : array |
168 | { |
169 | return $this->defaults; |
170 | } |
171 | |
172 | /** |
173 | * {@inheritdoc} |
174 | */ |
175 | public function toArray() : array |
176 | { |
177 | return [ |
178 | 'id' => $this->id, |
179 | 'name' => $this->name, |
180 | 'validationPattern' => $this->validationPattern, |
181 | 'custom' => $this->custom, |
182 | 'isRequired' => $this->isRequired, |
183 | ]; |
184 | } |
185 | |
186 | /** |
187 | * {@inheritdoc} |
188 | */ |
189 | public function jsonSerialize() : mixed |
190 | { |
191 | return $this->toArray(); |
192 | } |
193 | } |