Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
property.php
1<?php
2
3
5
6
9
10class Property extends Base
11{
12 const PROPERTY_TYPE_STRING = 'STRING';
13 const PROPERTY_TYPE_YN = 'Y/N';
14 const PROPERTY_TYPE_NUMBER = 'NUMBER';
15 const PROPERTY_TYPE_ENUM = 'ENUM';
16 const PROPERTY_TYPE_FILE = 'FILE';
17 const PROPERTY_TYPE_DATE = 'DATE';
18 const PROPERTY_TYPE_LOCATION = 'LOCATION';
19 const PROPERTY_TYPE_ADDRESS = 'ADDRESS';
20
21 public function prepareFieldInfos($fields)
22 {
23 $fieldsInfo = parent::prepareFieldInfos($fields);
24
25 foreach($fields as $name => $info)
26 {
27 if($name == 'SETTINGS')
28 {
29 $fieldsInfo[$name]['FIELDS'] = parent::prepareFieldInfos($info['FIELDS']);
30 }
31 }
32 return $fieldsInfo;
33 }
34
35 public function getFields()
36 {
37 return array_merge(
38 [
39 'ID'=>[
40 'TYPE'=>self::TYPE_INT,
41 'ATTRIBUTES'=>[Attributes::ReadOnly]
42 ],
43 'PERSON_TYPE_ID'=>[
44 'TYPE'=>self::TYPE_INT,
45 'ATTRIBUTES'=>[
48 ]
49 ],
50 'PROPS_GROUP_ID'=>[
51 'TYPE'=>self::TYPE_INT,
52 'ATTRIBUTES'=>[
55 ]
56 ],
57 'NAME'=>[
58 'TYPE'=>self::TYPE_STRING,
59 'ATTRIBUTES'=>[Attributes::Required]
60 ],
61 'CODE'=>[
62 'TYPE'=>self::TYPE_STRING
63 ],
64 'ACTIVE'=>[
65 'TYPE'=>self::TYPE_CHAR
66 ],
67 'UTIL' =>[
68 'TYPE'=>self::TYPE_CHAR
69 ],
70 'USER_PROPS'=>[
71 'TYPE'=>self::TYPE_CHAR
72 ],
73 'IS_FILTERED'=>[
74 'TYPE'=>self::TYPE_CHAR
75 ],
76 'SORT'=>[
77 'TYPE'=>self::TYPE_INT
78 ],
79 'DESCRIPTION'=>[
80 'TYPE'=>self::TYPE_STRING
81 ],
82 'XML_ID'=>[
83 'TYPE'=>self::TYPE_STRING
84 ],
85 'TYPE'=>[
86 'TYPE'=>self::TYPE_STRING,
87 'ATTRIBUTES'=>[
90 ]
91 ],
92 'REQUIRED'=>[
93 'TYPE'=>self::TYPE_CHAR
94 ],
95 'MULTIPLE'=>[
96 'TYPE'=>self::TYPE_CHAR
97 ],
98 'DEFAULT_VALUE'=>[
99 'TYPE'=>self::TYPE_STRING
100 ],
101 'SETTINGS'=>[
102 'TYPE'=>self::TYPE_DATATYPE,
103 //'ATTRIBUTES'=>[Attributes::ReadOnly]
104 ],
105 ],
106 $this->getFieldsByTypeString(),
109 );
110 }
111
112 public function getFieldsByType($type)
113 {
114 $filterMap = [
115 self::PROPERTY_TYPE_STRING => function ($k)
116 {
117 return (
118 is_set($this->getFieldsByTypeLocation(), $k) === false
119 && is_set($this->getFieldsByTypeAddress(), $k) === false
120 );
121 },
122 self::PROPERTY_TYPE_LOCATION => function ($k)
123 {
124 return (
125 is_set($this->getFieldsByTypeString(), $k) === false
126 && is_set($this->getFieldsByTypeAddress(), $k) === false
127 );
128 },
129 self::PROPERTY_TYPE_ADDRESS => function ($k)
130 {
131 return (
132 is_set($this->getFieldsByTypeString(), $k) === false
133 && is_set($this->getFieldsByTypeLocation(), $k) === false
134 );
135 },
136 'DEFAULT' => function ($k)
137 {
138 return (
139 is_set($this->getFieldsByTypeString(), $k) === false
140 && is_set($this->getFieldsByTypeLocation(), $k) === false
141 && is_set($this->getFieldsByTypeAddress(), $k) === false
142 );
143 },
144 ];
145
146 $filter = isset($filterMap[$type]) ? $filterMap[$type] : $filterMap['DEFAULT'];
147
148 $r = array_filter($this->getFields(), $filter, ARRAY_FILTER_USE_KEY);
149
150 $r['SETTINGS']['FIELDS'] = $this->getFieldsSettingsByType($type);
151
152 return $r;
153 }
154
155 protected function getFieldsSettingsByType($type)
156 {
157 $r = [];
158
159 if($type == self::PROPERTY_TYPE_STRING)
160 {
161 $r = $this->getFieldsSettingsByTypeString();
162 }
163 elseif($type == self::PROPERTY_TYPE_YN)
164 {
166 }
167 elseif($type == self::PROPERTY_TYPE_NUMBER)
168 {
169 $r = $this->getFieldsSettingsByNumberType();
170 }
171 elseif($type == self::PROPERTY_TYPE_ENUM)
172 {
173 $r = $this->getFieldsSettingsByEnumType();
174 }
175 elseif($type == self::PROPERTY_TYPE_FILE)
176 {
177 $r = $this->getFieldsSettingsByFileType();
178 }
179 elseif($type == self::PROPERTY_TYPE_DATE)
180 {
181 $r = $this->getFieldsSettingsByDateType();
182 }
183 elseif($type == self::PROPERTY_TYPE_LOCATION)
184 {
185 $r = $this->getFieldsSettingsByLocation();
186 }
187
188 return $r;
189 }
190
191 protected function getFieldsByTypeString()
192 {
193 return [
194 'IS_PROFILE_NAME'=>[
195 'TYPE'=>self::TYPE_CHAR
196 ],
197 'IS_PAYER'=>[
198 'TYPE'=>self::TYPE_CHAR
199 ],
200 'IS_EMAIL'=>[
201 'TYPE'=>self::TYPE_CHAR
202 ],
203 'IS_PHONE'=>[
204 'TYPE'=>self::TYPE_CHAR
205 ],
206 'IS_ZIP'=>[
207 'TYPE'=>self::TYPE_CHAR
208 ],
209 'IS_ADDRESS'=>[
210 'TYPE'=>self::TYPE_CHAR
211 ],
212 ];
213 }
214
215 protected function getFieldsByTypeAddress()
216 {
217 return [
218 'IS_ADDRESS_FROM'=>[
219 'TYPE'=>self::TYPE_CHAR
220 ],
221 'IS_ADDRESS_TO'=>[
222 'TYPE'=>self::TYPE_CHAR
223 ],
224 ];
225 }
226
227 protected function getFieldsByTypeLocation()
228 {
229 $r = [
230 'IS_LOCATION'=>[
231 'TYPE'=>self::TYPE_CHAR
232 ],
233 'INPUT_FIELD_LOCATION'=>[
234 'TYPE'=>self::TYPE_STRING // enum
235 ],
236 'IS_LOCATION4TAX'=>[
237 'TYPE'=>self::TYPE_CHAR
238 ]
239 ];
240 return $r;
241 }
242
243 protected function getFieldsSettingsByTypeString()
244 {
245 return [
246 'MINLENGTH'=>[
247 'TYPE'=>self::TYPE_INT,
248 ],
249 'MAXLENGTH'=>[
250 'TYPE'=>self::TYPE_INT,
251 ],
252 'PATTERN'=>[
253 'TYPE'=>self::TYPE_STRING,
254 ],
255 'MULTILINE'=>[
256 'TYPE'=>self::TYPE_CHAR,
257 ],
258 'COLS'=>[
259 'TYPE'=>self::TYPE_INT,
260 ],
261 'ROWS'=>[
262 'TYPE'=>self::TYPE_INT,
263 ],
264 'SIZE'=>[
265 'TYPE'=>self::TYPE_INT,
266 ],
267 ];
268 }
269
271 {
272 return [];
273 }
274
275 protected function getFieldsSettingsByNumberType()
276 {
277 return [
278 'MIN'=>[
279 'TYPE'=>self::TYPE_INT,
280 ],
281 'MAX'=>[
282 'TYPE'=>self::TYPE_INT,
283 ],
284 'STEP'=>[
285 'TYPE'=>self::TYPE_INT,
286 ]
287 ];
288 }
289
290 protected function getFieldsSettingsByEnumType()
291 {
292 return [
293 'MULTIELEMENT'=>[
294 'TYPE'=>self::TYPE_CHAR,
295 ],
296 'SIZE'=>[
297 'TYPE'=>self::TYPE_INT,
298 ]
299 ];
300 }
301
302 protected function getFieldsSettingsByFileType()
303 {
304 return [
305 'MAXSIZE'=>[
306 'TYPE'=>self::TYPE_INT,
307 ],
308 'ACCEPT'=>[
309 'TYPE'=>self::TYPE_STRING,
310 ]
311 ];
312 }
313
314 protected function getFieldsSettingsByDateType()
315 {
316 return [
317 'TIME'=>[
318 'TYPE'=>self::TYPE_CHAR,
319 ]
320 ];
321 }
322
323 protected function getFieldsSettingsByLocation()
324 {
325 return [];
326 }
327
328 public function convertKeysToSnakeCaseArguments($name, $arguments)
329 {
330 if($name == 'getfieldssettingsbytype'
331 || $name == 'getfieldsbytype'
332 ){
333 if(isset($arguments['type']))
334 {
335 $fields = $arguments['type'];
336 if(!empty($fields))
337 {
338 $converter = new Converter(Converter::VALUES | Converter::TO_UPPER);
339 $arguments['type'] = $converter->process($fields);
340 }
341 }
342 }
343
344 return $arguments;
345 }
346
347 public function internalizeArguments($name, $arguments)
348 {
349 if($name == 'getfieldssettingsbytype'
350 || $name == 'getfieldsbytype'
351 ){}
352 else
353 {
354 parent::internalizeArguments($name, $arguments);
355 }
356
357 return $arguments;
358 }
359
360 public function externalizeResult($name, $fields)
361 {
362 if($name == 'getfieldssettingsbytype'
363 || $name == 'getfieldsbytype'
364 ){}
365 else
366 {
367 parent::externalizeResult($name, $fields);
368 }
369 return $fields;
370 }
371}
internalizeArguments($name, $arguments)
Definition property.php:347
convertKeysToSnakeCaseArguments($name, $arguments)
Definition property.php:328
externalizeResult($name, $fields)
Definition property.php:360