Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
configurationoption.php
1<?php
10
12{
13 public const TYPE_DATE_TIME = 'datetime';
14 public const TYPE_TIME = 'time';
15 public const TYPE_NUMBER = 'number';
16 public const TYPE_PRESET_STRING = 'preset-string';
17 public const TYPE_CUSTOM = 'custom';
18 public const TYPE_STRING = 'string';
19 public const TYPE_CHECKBOX = 'checkbox';
20 public const TYPE_CONSENT = 'user-consent';
21 public const TYPE_CONSENT_CONTENT = 'user-consent-content';
22 public const TYPE_EMAIL = 'email';
23 public const TYPE_LIST = 'list';
24 public const TYPE_HTML = 'html';
25 public const TYPE_TEXT = 'text';
26 public const TYPE_FILE = 'file';
27 public const TYPE_TITLE = 'title';
28 public const TYPE_TEMPLATE_TYPE = 'template-type';
29 public const TYPE_TEMPLATE_ID = 'template-id';
30 public const TYPE_MAIL_EDITOR = 'mail-editor';
31 public const TYPE_AUDIO = 'audio';
32 public const TYPE_SMS_EDITOR = 'sms-editor';
33 public const TYPE_USER_LIST = 'user-list';
34 public const GROUP_DEFAULT = 0;
35 public const GROUP_ADDITIONAL = 1;
36
38 protected $type;
39
41 protected $code;
42
44 protected $view;
45
47 protected $name;
48
50 protected $value;
51
53 protected $items = [];
54
57
59 protected $hint;
60
61 protected string|array|null $placeholder = null;
62
64 protected $required = false;
65
67 protected $templated = false;
68
70 protected $readonlyView;
71
73 protected $showInList = false;
74
76 protected $showInFilter = false;
77
79 protected $showPreview = false;
80
82 protected $showHelper = false;
83
85 protected $maxLength;
86
88 protected $maxValue;
89
91 protected $minValue;
92
97 public function __construct(array $data = [])
98 {
99 if (isset($data['type']))
100 {
101 $this->setType($data['type']);
102 }
103 if (isset($data['code']))
104 {
105 $this->setCode($data['code']);
106 }
107 if (isset($data['name']))
108 {
109 $this->setName($data['name']);
110 }
111 if (isset($data['view']))
112 {
113 $this->setView($data['view']);
114 }
115 if (isset($data['value']))
116 {
117 $this->setValue($data['value']);
118 }
119 if (isset($data['group']))
120 {
121 $this->setGroup($data['group']);
122 }
123 if (isset($data['items']))
124 {
125 $this->setItems($data['items']);
126 }
127 if (isset($data['required']))
128 {
129 $this->setRequired($data['required']);
130 }
131 if (isset($data['templated']))
132 {
133 $this->setTemplated($data['templated']);
134 }
135 if (isset($data['hint']))
136 {
137 $this->setHint($data['hint']);
138 }
139 if (isset($data['placeholder']))
140 {
141 $this->setPlaceholder($data['placeholder']);
142 }
143 if (isset($data['readonly_view']))
144 {
145 $this->setReadonlyView($data['readonly_view']);
146 }
147 if (isset($data['show_in_list']))
148 {
149 $this->setShowInList($data['show_in_list']);
150 }
151 if (isset($data['show_in_filter']))
152 {
153 $this->setShowInFilter($data['show_in_filter']);
154 }
155 if (isset($data['show_preview']))
156 {
157 $this->setShowPreview($data['show_preview']);
158 }
159 if (isset($data['show_helper']))
160 {
161 $this->setShowHelper($data['show_helper']);
162 }
163 if (isset($data['max_length']))
164 {
165 $this->setMaxLength($data['max_length']);
166 }
167 if (isset($data['max_value']))
168 {
169 $this->setMaxValue($data['max_value']);
170 }
171 if (isset($data['min_value']))
172 {
173 $this->setMinValue($data['min_value']);
174 }
175 }
176
182 public function getArray()
183 {
184 return [
185 'type' => $this->getType(),
186 'code' => $this->getCode(),
187 'name' => $this->getName(),
188 'view' => $this->getView(),
189 'value' => $this->getValue(),
190 'group' => $this->getGroup(),
191 'items' => $this->getItems(),
192 'required' => $this->isRequired(),
193 'templated' => $this->isTemplated(),
194 'hint' => $this->getHint(),
195 'placeholder' => $this->getPlaceholder(),
196 'max_length' => $this->getMaxLength(),
197 'min_value' => $this->getMinValue(),
198 'max_value' => $this->getMaxValue(),
199 'show_in_list' => $this->getShowInList(),
200 'show_preview' => $this->getShowPreview(),
201 'show_helper' => $this->getShowHelper(),
202 ];
203 }
204
210 public function getType()
211 {
212 return $this->type;
213 }
214
221 public function setType($type)
222 {
223 $this->type = $type;
224 }
225
231 public function getCode()
232 {
233 return $this->code;
234 }
235
242 public function setCode($code)
243 {
244 $this->code = $code;
245 }
246
252 public function getView()
253 {
254 return $this->view;
255 }
256
263 public function setView($view)
264 {
265 $this->view = $view;
266 }
267
273 public function getName()
274 {
275 return $this->name;
276 }
277
284 public function setName($name)
285 {
286 $this->name = $name;
287 }
288
294 public function getValue()
295 {
296 return $this->value;
297 }
298
304 public function hasValue()
305 {
306 return is_array($this->value) ? count($this->value) > 0 : (bool)$this->value;
307 }
308
315 public function setValue($value)
316 {
317 $this->value = $value;
318 }
319
325 public function getGroup()
326 {
327 return $this->group;
328 }
329
336 public function setGroup($group)
337 {
338 $this->group = $group;
339 }
340
346 public function getItems()
347 {
348 return $this->items;
349 }
350
357 public function setItems(array $items)
358 {
359 if (!is_numeric(implode('', array_keys($items))))
360 {
361 $this->items = [];
362 foreach ($items as $code => $value)
363 {
364 $this->items[] = ['code' => $code, 'value' => $value];
365 }
366 }
367 else
368 {
369 $this->items = $items;
370 }
371 }
372
378 public function isRequired()
379 {
380 return $this->required;
381 }
382
389 public function setRequired($required)
390 {
391 $this->required = (bool)$required;
392 }
393
399 public function isTemplated()
400 {
401 return $this->templated;
402 }
403
410 public function setTemplated($templated)
411 {
412 $this->templated = (bool)$templated;
413 }
414
420 public function getHint()
421 {
422 return $this->hint;
423 }
424
431 public function setHint($hint)
432 {
433 $this->hint = $hint;
434 }
435
436
443 public function getReadonlyView($value)
444 {
445 if (is_callable($this->readonlyView))
446 {
447 $callback = $this->readonlyView;
448 $value = $callback($value);
449 }
450 return $value;
451 }
452
456 public function getMaxLength()
457 {
458 return $this->maxLength;
459 }
460
461
467 public function getShowInList()
468 {
469 return $this->showInList;
470 }
471
477 public function getShowInFilter()
478 {
479 return $this->showInFilter;
480 }
481
489 {
490 $this->readonlyView = $readonlyView;
491 }
492
499 public function setShowInList($showInList)
500 {
501 $this->showInList = $showInList;
502 }
503
511 {
512 $this->showInFilter = $showInFilter;
513 }
514
518 public function setMaxLength(int $maxLength)
519 {
520 $this->maxLength = $maxLength;
521 }
522
526 public function getMaxValue()
527 {
528 return $this->maxValue;
529 }
530
536 public function setMaxValue(int $maxValue)
537 {
538 $this->maxValue = $maxValue;
539
540 return $this;
541 }
542
546 public function getMinValue()
547 {
548 return $this->minValue;
549 }
550
556 public function setMinValue(int $minValue)
557 {
558 $this->minValue = $minValue;
559
560 return $this;
561 }
562
566 public function getShowPreview(): bool
567 {
568 return $this->showPreview;
569 }
570
576 {
577 $this->showPreview = $showPreview;
578 return $this;
579 }
580
584 public function getShowHelper(): bool
585 {
586 return $this->showHelper;
587 }
588
594 {
595 $this->showHelper = $showHelper;
596 return $this;
597 }
598
599 private function getPlaceholder(): array|string|null
600 {
601 return $this->placeholder;
602 }
603
604 private function setPlaceholder(mixed $placeholder): void
605 {
606 $this->placeholder = $placeholder;
607 }
608
609}