/
OrderFormField.php
351 lines (308 loc) · 6.39 KB
/
OrderFormField.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<?php
declare(strict_types=1);
namespace Pixelant\PxaProductManager\Domain\Model;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
/**
* Class OrderFormField
* @package Pixelant\PxaProductManager\Domain\Model
*/
class OrderFormField extends AbstractDomainObject
{
/**
* Type simple input
*/
const FIELD_INPUT = 1;
/**
* Type textarea
*/
const FIELD_TEXTAREA = 2;
/**
* Type select box
*/
const FIELD_SELECTBOX = 3;
/**
* Name
*
* @var string
*/
protected $name = '';
/**
* Label
*
* @var string
*/
protected $label = '';
/**
* If if static, user can't change it value when filling in form
*
* @var bool
*/
protected $static = false;
/**
* Placeholder
*
* @var string
*/
protected $placeholder = '';
/**
* Type of field
*
* @var int
*/
protected $type = 0;
/**
* @var string
*/
protected $validationRules = [];
/**
* @var bool
*/
protected $userEmailField = false;
/**
* Value of field
* Has no DB field
*
* @var string
*/
protected $value = '';
/**
* Validation errors
* Is not stored in DB
*
* @var array
*/
protected $errors = [];
/**
* @lazy
* @cascade
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\PxaProductManager\Domain\Model\Option>
*/
protected $options = [];
/**
* __construct
*/
public function __construct()
{
//Do not remove the next line: It would break the functionality
$this->initStorageObjects();
}
/**
* Initializes all ObjectStorage properties
* Do not modify this method!
* It will be rewritten on each save in the extension builder
* You may modify the constructor of this class instead
*
* @return void
*/
protected function initStorageObjects()
{
$this->options = new ObjectStorage();
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return bool
*/
public function isStatic(): bool
{
return $this->static;
}
/**
* @param bool $static
*/
public function setStatic(bool $static)
{
$this->static = $static;
}
/**
* @return string
*/
public function getValue(): string
{
return $this->value;
}
/**
* @return string
*/
public function getValueAsText(): string
{
switch ($this->value) {
case self::FIELD_SELECTBOX:
$optionUid = (int)$this->value;
/** @var Option $option */
foreach ($this->getOptions() as $option) {
if ($option->getUid() === $optionUid) {
return $option->getValue();
}
}
break;
default:
return $this->value;
}
return '';
}
/**
* @param string $value
*/
public function setValue($value)
{
$this->value = $value;
}
/**
* @return string
*/
public function getPlaceholder(): string
{
return $this->placeholder;
}
/**
* @param string $placeholder
*/
public function setPlaceholder(string $placeholder)
{
$this->placeholder = $placeholder;
}
/**
* @return int
*/
public function getType(): int
{
return $this->type;
}
/**
* @param int $type
*/
public function setType(int $type)
{
$this->type = $type;
}
/**
* @return string
*/
public function getValidationRules(): string
{
return $this->validationRules;
}
/**
* Explode validation rules
*
* @return array
*/
public function getValidationRulesArray(): array
{
return GeneralUtility::trimExplode(
',',
$this->getValidationRules(),
true
);
}
/**
* @param string $validationRules
*/
public function setValidationRules(string $validationRules)
{
$this->validationRules = $validationRules;
}
/**
* Adds a Option
*
* @param Option $option
* @return void
*/
public function addOption(Option $option)
{
$this->options->attach($option);
}
/**
* Removes a Option
*
* @param Option $optionToRemove The Option to be removed
* @return void
*/
public function removeOption(Option $optionToRemove)
{
$this->options->detach($optionToRemove);
}
/**
* Returns the options
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\PxaProductManager\Domain\Model\Option> $options
*/
public function getOptions(): ObjectStorage
{
return $this->options;
}
/**
* Sets the options
*
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\Pixelant\PxaProductManager\Domain\Model\Option> $options
* @return void
*/
public function setOptions(ObjectStorage $options)
{
$this->options = $options;
}
/**
* @return string
*/
public function getLabel(): string
{
return $this->label;
}
/**
* @param string $label
*/
public function setLabel(string $label)
{
$this->label = $label;
}
/**
* @return bool
*/
public function isUserEmailField(): bool
{
return $this->userEmailField;
}
/**
* @param bool $userEmailField
*/
public function setUserEmailField(bool $userEmailField)
{
$this->userEmailField = $userEmailField;
}
/**
* @return array
*/
public function getErrors(): array
{
return $this->errors;
}
/**
* @param array $errors
*/
public function setErrors(array $errors)
{
$this->errors = $errors;
}
/**
* @param string $error
*/
public function addError(string $error)
{
$this->errors[] = $error;
}
}