Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
field.php
1<?php
2
3namespace Bitrix\Seo\LeadAds;
4
11class Field
12{
13 public const TYPE_INPUT = 'input';
14 public const TYPE_TEXT_AREA = 'textarea';
15 public const TYPE_RADIO = 'radio';
16 public const TYPE_CHECKBOX = 'checkbox';
17 public const TYPE_SELECT = 'select';
18 public const TYPE_DATE_TIME = 'date';
19 public const TYPE_CONDITION_QUESTION = 'condition';
20
21 //This constants represent pre-fill forms types:
22 //personal data:
23 public const TYPE_NAME = 'NAME';
24 public const TYPE_LAST_NAME = 'LAST_NAME';
25 public const TYPE_FULL_NAME = 'FULL_NAME';
26 public const TYPE_PATRONYMIC_NAME = 'PATRONYMIC_NAME';
27 public const TYPE_GENDER = 'GENDER';
28 public const TYPE_AGE = 'AGE';
29 public const TYPE_BIRTHDAY = 'BIRTHDAY';
30
31 //contact data:
32 public const TYPE_PHONE = 'PHONE';
33 public const TYPE_EMAIL = 'EMAIL';
34 public const TYPE_LOCATION_FULL = 'LOCATION'; //Country, state, city
35 public const TYPE_LOCATION_COUNTRY = 'COUNTRY';
36 public const TYPE_LOCATION_STATE = 'STATE';
37 public const TYPE_LOCATION_CITY = 'CITY';
38 public const TYPE_LOCATION_STREET_ADDRESS = 'ADDRESS';
39 public const TYPE_LOCATION_ZIP = 'ZIP'; //ZIP-CODE: https://en.wikipedia.org/wiki/ZIP_Code
40
41 //demographic data
42 public const TYPE_MILITARY_STATUS = 'MILITARY_STATUS';
43 public const TYPE_MARITIAL_STATUS = 'MARITIAL_STATUS';
44 public const TYPE_RELATIONSHIP_STATUS = 'RELATIONSHIP_STATUS';
45
46 //job data
47 public const TYPE_COMPANY_NAME = 'COMPANY_NAME';
48 public const TYPE_JOB_TITLE = 'JOB_TITLE';
49 public const TYPE_WORK_EMAIL = 'WORK_EMAIL';
50 public const TYPE_WORK_PHONE = 'WORK_PHONE';
51
52
53 // National Ids Types
54 public const TYPE_CPF = 'CPF'; // https://brasil-russia.ru/cpf/
55 public const TYPE_DNI_ARGENTINA = 'DNI_AR'; //
56 public const TYPE_DNI_PERU = 'DNI_PE';
57 public const TYPE_RUT = 'RUT';
58 public const TYPE_CC = 'CC';
59 public const TYPE_CI = 'CI';
60
61
65 public static function getTypes(): array
66 {
67 static $list;
68 return $list = $list ?? (new \ReflectionClass(static::class))->getConstants();
69 }
70
71
73 private $type;
74
76 private $name;
77
79 private $label;
80
82 private $key;
83
85 private $options = [];
86
92 public function toArray(): array
93 {
94 $result = [];
95
96 foreach ($this as $key => $value)
97 {
98 if (isset($value))
99 {
100 $result[$key] = $value;
101 }
102 }
103
104 return $result;
105 }
106
115 public function __construct(
116 string $type = self::TYPE_INPUT,
117 ?string $name = null,
118 ?string $label = null,
119 ?string $key = null,
120 array $options = []
121 )
122 {
123 $this->type = $type;
124 $this->name = $name;
125 $this->label = $label;
126 $this->key = $key;
127 $this->setOptions($options);
128 }
129
137 public function addOption(string $key, string $label): Field
138 {
139 $this->options[] = [
140 'key' => $key,
141 'label' => $label
142 ];
143
144 return $this;
145 }
146
154 public function setOptions(array $options): Field
155 {
156 $this->options = [];
157
158 foreach ($options as $option)
159 {
160 $this->addOption(
161 $option['key'],
162 $option['label']
163 );
164 }
165
166 return $this;
167 }
168
174 public function getType(): string
175 {
176 return $this->type;
177 }
178
184 public function getName(): ?string
185 {
186 return $this->name;
187 }
188
194 public function getLabel(): ?string
195 {
196 return $this->label;
197 }
198
204 public function getKey(): ?string
205 {
206 return $this->key;
207 }
208
214 public function getOptions(): array
215 {
216 return $this->options;
217 }
218}
addOption(string $key, string $label)
Definition field.php:137
setOptions(array $options)
Definition field.php:154
const TYPE_RELATIONSHIP_STATUS
Definition field.php:44
const TYPE_CONDITION_QUESTION
Definition field.php:19
__construct(string $type=self::TYPE_INPUT, ?string $name=null, ?string $label=null, ?string $key=null, array $options=[])
Definition field.php:115
const TYPE_LOCATION_STREET_ADDRESS
Definition field.php:38