Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
field.php
1<?php
2
3namespace Bitrix\Lists;
4
5use Bitrix\Crm\UserField\Types\ElementType;
11
12Loc::loadMessages(__FILE__);
13
20class Field
21{
22 protected static $cache = array();
23 protected static $separator = '<br>';
24 protected static $renderForForm = false;
25
32 public static function renderField(array $field)
33 {
34 $result = '';
35 $controlSettings = !empty($field['CONTROL_SETTINGS']) ? $field['CONTROL_SETTINGS'] : array();
36
37 if(!empty($field['DEFAULT']))
38 {
39 $field['VALUE'] = $field['DEFAULT_VALUE'];
40 if(in_array($field['TYPE'], array('S:DiskFile')))
41 {
42 $renderMethod = 'renderCustomDefaultValue'.$field['PROPERTY_USER_TYPE']['USER_TYPE'];
43 return self::$renderMethod($field);
44 }
45 }
46
47 if(!empty($field['SEPARATOR']))
48 {
49 self::$separator = $field['SEPARATOR'];
50 }
51
52 if(self::$renderForForm && isset($field['CURRENT_VALUE']))
53 {
54 $field['VALUE'] = $field['CURRENT_VALUE'];
55 }
56
57 if(isset($field['PROPERTY_USER_TYPE']['USER_TYPE'])
58 && method_exists(__CLASS__, 'renderFieldByUserType'.$field['PROPERTY_USER_TYPE']['USER_TYPE']))
59 {
60 $renderMethod = 'renderFieldByUserType'.$field['PROPERTY_USER_TYPE']['USER_TYPE'];
61 $result = self::$renderMethod($field);
62 }
63 elseif(isset($field['PROPERTY_USER_TYPE']['GetPublicViewHTMLMulty']))
64 {
65 $result = call_user_func_array(
66 $field['PROPERTY_USER_TYPE']['GetPublicViewHTMLMulty'], array($field, $field, $controlSettings));
67 }
68 elseif(isset($field['PROPERTY_USER_TYPE']['GetPublicViewHTML']))
69 {
70 if($field['MULTIPLE'] === 'Y' && is_array($field['VALUE']))
71 {
72 $results = array();
73 if(\CLists::isAssociativeArray($field['VALUE']))
74 {
75 $result = call_user_func_array(
76 $field['PROPERTY_USER_TYPE']['GetPublicViewHTML'], array($field, $field, $controlSettings));
77 }
78 else
79 {
80 foreach($field['VALUE'] as $value)
81 {
82 $fieldParam = array('VALUE' => $value);
83 $results[] = call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicViewHTML'],
84 array($field, $fieldParam, $controlSettings));
85 }
86 $result = implode(self::$separator, $results);
87 }
88 }
89 else
90 {
91 $result = call_user_func_array(
92 $field['PROPERTY_USER_TYPE']['GetPublicViewHTML'], array($field, $field, $controlSettings));
93 }
94
95 if ($field['TYPE'] == 'S:DiskFile' && ($field['READ'] ?? '') == 'Y')
96 {
97 $field['VALUE'] = array_filter((is_array($field['VALUE']) ? $field['VALUE'] : array($field['VALUE'])));
98 foreach ($field['VALUE'] as $key => $value)
99 {
100 $result .= '<input type="hidden" name="'.$field['FIELD_ID'].'[n'.$key.'][VALUE][]" value="'.HtmlFilter::encode($value).'">';
101 }
102 }
103 }
104 elseif($field['PROPERTY_TYPE'] != '')
105 {
106 $renderMethod = 'renderFieldByType'.$field['PROPERTY_TYPE'];
107 if(method_exists(__CLASS__, $renderMethod))
108 {
109 $result = self::$renderMethod($field);
110 }
111 }
112 elseif($field['TYPE'] != '')
113 {
114 $renderMethod = 'renderFieldByField'.str_replace('_', '', $field['TYPE']);
115 if(method_exists(__CLASS__, $renderMethod))
116 {
117 $result = self::$renderMethod($field);
118 }
119 else
120 {
121 $result = self::renderDefaultField($field);
122 }
123 }
124
125 return $result;
126 }
127
128 public static function prepareFieldDataForEditForm(array $field)
129 {
130 $result = ['customHtml' => ''];
131
132 self::$renderForForm = true;
133
134 $field['SHOW'] = 'Y';
135 if (!empty($field['ELEMENT_ID']) && !empty($field['SETTINGS']['SHOW_EDIT_FORM']))
136 {
137 $field['SHOW'] = $field['SETTINGS']['SHOW_EDIT_FORM'];
138 }
139 if (empty($field['ELEMENT_ID']) && !empty($field['SETTINGS']['SHOW_ADD_FORM']))
140 {
141 $field['SHOW'] = $field['SETTINGS']['SHOW_ADD_FORM'];
142 }
143
144 $field['READ'] = 'N';
145 if (!empty($field['ELEMENT_ID']) && !empty($field['SETTINGS']['EDIT_READ_ONLY_FIELD']))
146 {
147 $field['READ'] = $field['SETTINGS']['EDIT_READ_ONLY_FIELD'];
148 }
149 if (empty($field['ELEMENT_ID']) && !empty($field['SETTINGS']['ADD_READ_ONLY_FIELD']))
150 {
151 $field['READ'] = $field['SETTINGS']['ADD_READ_ONLY_FIELD'];
152 }
153
154 if ($field['TYPE'] === 'S:employee')
155 {
156 $field['SETTINGS']['USE_ENTITY_SELECTOR'] = 'Y';
157 }
158
159 if(isset($field['PROPERTY_USER_TYPE']['USER_TYPE']) && method_exists(
160 __CLASS__, 'prepareEditFieldByUserType'.$field['PROPERTY_USER_TYPE']['USER_TYPE']))
161 {
162 $prepareEditMethod = 'prepareEditFieldByUserType'.$field['PROPERTY_USER_TYPE']['USER_TYPE'];
163 $result = self::$prepareEditMethod($field);
164 }
165 elseif(isset($field['PROPERTY_USER_TYPE']['GetPublicEditHTMLMulty']) && $field['MULTIPLE'] == 'Y')
166 {
167 if(!is_array($field['VALUE']))
168 $field['VALUE'] = array($field['VALUE']);
169 $html = '';
170 $isEmptyValue = true;
171 foreach($field['VALUE'] as $key => $value)
172 {
173 if($field['READ'] == 'Y')
174 {
175 if(empty($value['VALUE']))
176 {
177 continue;
178 }
179 else
180 {
181 $isEmptyValue = false;
182 $field['CURRENT_VALUE'] = $value['VALUE'];
183 $html .= ' '.self::renderField($field);
184 }
185 $value['VALUE'] = (!is_array($value['VALUE']) ? [$value['VALUE']] : $value['VALUE']);
186 foreach ($value['VALUE'] as $innerKey => $innerValue)
187 {
188 $result['customHtml'] .= '<input type="hidden" name="'.
189 $field['FIELD_ID'].'[n'.$innerKey.'][VALUE]" value="'.HtmlFilter::encode($innerValue).'">';
190 }
191 }
192 }
193 if($field['READ'] == 'N')
194 {
195 $html .= call_user_func_array(
196 $field['PROPERTY_USER_TYPE']['GetPublicEditHTMLMulty'],
197 [
198 $field,
199 $field['VALUE'],
200 [
201 'VALUE' => $field['FIELD_ID'],
202 'DESCRIPTION' => '',
203 'FORM_NAME' => 'form_' . ($field['FORM_ID'] ?? ''),
204 'MODE' => 'FORM_FILL',
205 ],
206 ]
207 );
208 }
209 else
210 {
211 if($isEmptyValue)
212 $html .= Loc::getMessage('LISTS_FIELD_NOT_DATA');
213 }
214 $result['id'] = $field['FIELD_ID'];
215 $result['name'] = $field['NAME'];
216 $result['required'] = $field['IS_REQUIRED'] == 'Y' ? true : false;
217 $result['type'] = 'custom';
218 $result['value'] = $html;
219 $result['show'] = $field['SHOW'];
220 }
221 elseif(isset($field['PROPERTY_USER_TYPE']['GetPublicEditHTML']))
222 {
223 $listTypeNotMultiple = array('S:DiskFile', 'S:ECrm');
224 if (!isset($field['VALUE']) || !is_array($field['VALUE']))
225 {
226 $field['VALUE'] = [$field['VALUE'] ?? null];
227 }
228
229 if($field['MULTIPLE'] == 'Y' && !in_array($field['TYPE'], $listTypeNotMultiple))
230 {
231 $html = '<table id="tbl'.$field['FIELD_ID'].'">';
232 $isEmptyValue = true;
233 foreach($field['VALUE'] as $key => $value)
234 {
235 if($field['READ'] == 'Y')
236 {
237 if(empty($value['VALUE']))
238 {
239 continue;
240 }
241 else
242 {
243 $isEmptyValue = false;
244 $field['CURRENT_VALUE'] = $value['VALUE'];
245 $html .= '<tr><td>' . self::renderField($field).'</td></tr>';
246 }
247 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
248 '['.$key.'][VALUE]" value="'.HtmlFilter::encode($value['VALUE']).'">';
249 }
250 else
251 {
252 $html .= '<tr><td>'.call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicEditHTML'],
253 array(
254 $field,
255 $value,
256 array(
257 'VALUE' => $field['FIELD_ID']."[".$key."][VALUE]",
258 'DESCRIPTION' => '',
259 'FORM_NAME' => 'form_' . ($field['FORM_ID'] ?? ''),
260 'MODE' => "FORM_FILL",
261 'COPY' => $field['COPY_ID'] > 0,
262 )
263 )).'</td></tr>';
264 }
265 }
266 if($field['READ'] == 'Y')
267 {
268 if($isEmptyValue)
269 $html .= Loc::getMessage('LISTS_FIELD_NOT_DATA');
270 }
271 $html .= '</table>';
272 if($field['READ'] == 'N')
273 {
274 $regExp = '/'.$field['FIELD_ID'].'\[(n)([0-9]*)\]/g';
275 $html .= '<input type="button" value="'.Loc::getMessage("LISTS_FIELD_ADD_BUTTON").'"
276 onclick="BX.Lists.addNewTableRow(\'tbl'.$field['FIELD_ID'].
277 '\', 1, '.HtmlFilter::encode($regExp).', 2)">';
278 }
279 }
280 else
281 {
282 $html = '';
283 $isEmptyValue = true;
284 foreach($field['VALUE'] as $key => $value)
285 {
286 if($field['READ'] == 'Y')
287 {
288 if(empty($value['VALUE']))
289 {
290 continue;
291 }
292 else
293 {
294 $isEmptyValue = false;
295 $field['CURRENT_VALUE'] = $value['VALUE'];
296 $html .= ' '.self::renderField($field);
297 }
298 if(!is_array($value['VALUE']))
299 {
300 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
301 '['.$key.'][VALUE]" value="'.HtmlFilter::encode($value['VALUE']).'">';
302 }
303 }
304 else
305 {
306 if ($field['TYPE'] == 'S:DiskFile')
307 {
308 $html .= call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicViewHTML'],
309 array($field, $value, array()));
310 }
311 $html .= call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicEditHTML'],
312 array(
313 $field,
314 $value,
315 array(
316 'VALUE' => $field['FIELD_ID']."[".$key."][VALUE]",
317 'DESCRIPTION' => '',
318 'FORM_NAME' => 'form_' . ($field['FORM_ID'] ?? ''),
319 'MODE' => 'FORM_FILL',
320 'COPY' => $field['COPY_ID'] > 0,
321 ),
322 ));
323 }
324 break;
325 }
326 if($field['READ'] == 'Y')
327 {
328 if($isEmptyValue)
329 $html .= Loc::getMessage('LISTS_FIELD_NOT_DATA');
330 }
331 }
332 $result['id'] = $field['FIELD_ID'];
333 $result['name'] = $field['NAME'];
334 $result['required'] = $field['IS_REQUIRED'] == 'Y' ? true: false;
335 $result['type'] = 'custom';
336 $result['value'] = $html;
337 $result['show'] = $field['SHOW'];
338 }
339 elseif($field['PROPERTY_TYPE'] != '')
340 {
341 $prepareEditMethod = 'prepareEditFieldByType'.$field['PROPERTY_TYPE'];
342 if(method_exists(__CLASS__, $prepareEditMethod))
343 {
344 $result = self::$prepareEditMethod($field);
345 }
346 }
347 elseif($field['TYPE'] != '')
348 {
349 $prepareEditMethod = 'prepareEditFieldByField'.str_replace('_', '', $field['TYPE']);
350 if(method_exists(__CLASS__, $prepareEditMethod))
351 {
352 $result = self::$prepareEditMethod($field);
353 }
354 else
355 {
356 $result = self::prepareEditDefaultField($field);
357 }
358 }
359
360 return $result;
361 }
362
369 public static function prepareFieldDataForFilter(array $field)
370 {
371 $customEntityType = array('employee');
372 if($field['TYPE'] == 'SORT' || $field['TYPE'] == 'N')
373 {
374 $result = array(
375 'id' => $field['FIELD_ID'],
376 'name' => $field['NAME'],
377 'type' => 'number',
378 'filterable' => ''
379 );
380 }
381 elseif($field['TYPE'] == 'ACTIVE_FROM' || $field['TYPE'] == 'ACTIVE_TO')
382 {
383 $result = array(
384 'id' => 'DATE_'.$field['FIELD_ID'],
385 'name' => $field['NAME'],
386 'type' => 'date',
387 'filterable' => '',
388 'dateFilter' => true
389 );
390 }
391 elseif($field['TYPE'] == 'DATE_CREATE' || $field['TYPE'] == 'TIMESTAMP_X')
392 {
393 $result = array(
394 'id' => $field['FIELD_ID'],
395 'name' => $field['NAME'],
396 'type' => 'date',
397 'filterable' => '',
398 'dateFilter' => true
399 );
400 }
401 elseif($field['TYPE'] == 'CREATED_BY' || $field['TYPE'] == 'MODIFIED_BY')
402 {
403 $result = array(
404 'id' => $field['FIELD_ID'],
405 'name' => $field['NAME'],
406 'type' => 'custom_entity',
407 'filterable' => '',
408 );
409 }
410 elseif($field['TYPE'] == 'L')
411 {
412 $items = array();
413 $queryObject = \CIBlockProperty::getPropertyEnum($field['ID'], array('SORT' => 'ASC', 'NAME' => 'ASC'));
414 while($queryResult = $queryObject->fetch())
415 $items[$queryResult['ID']] = $queryResult['VALUE'];
416
417 $result = array(
418 'id' => $field['FIELD_ID'],
419 'name' => $field['NAME'],
420 'type' => 'list',
421 'items' => $items,
422 'params' => array('multiple' => 'Y'),
423 'filterable' => ''
424 );
425 }
426 elseif($field['TYPE'] == 'E')
427 {
428 $result = array(
429 'id' => $field['FIELD_ID'],
430 'name' => $field['NAME'],
431 'type' => 'custom_entity',
432 'filterable' => '',
433 'customFilter' => array('Bitrix\Iblock\Helpers\Filter\Property', 'addFilter')
434 );
435 }
436 elseif($field['TYPE'] == 'E:EList')
437 {
438 $items = array();
439 $queryObject = \CIBlockElement::getList(
440 array('SORT' => 'ASC'),
441 array('IBLOCK_ID' => $field['LINK_IBLOCK_ID']),
442 false,
443 false,
444 array('ID', 'NAME', 'SORT')
445 );
446 while($queryResult = $queryObject->fetch())
447 $items[$queryResult['ID']] = $queryResult['NAME'];
448
449 $result = array(
450 'id' => $field['FIELD_ID'],
451 'name' => $field['NAME'],
452 'type' => 'list',
453 'items' => $items,
454 'params' => array('multiple' => 'Y'),
455 'filterable' => ''
456 );
457 }
458 elseif($field['TYPE'] == 'G')
459 {
460 $items = array();
461 $queryObject = \CIBlockSection::getList(
462 array('LEFT_MARGIN' => 'ASC'),
463 array('IBLOCK_ID' => $field['LINK_IBLOCK_ID']),
464 false,
465 array('ID', 'IBLOCK_ID', 'NAME', 'DEPTH_LEVEL', 'LEFT_MARGIN')
466 );
467 while($queryResult = $queryObject->fetch())
468 $items[$queryResult['ID']] = str_repeat('. ', $queryResult['DEPTH_LEVEL'] - 1).$queryResult['NAME'];
469
470 $result = array(
471 'id' => $field['FIELD_ID'],
472 'name' => $field['NAME'],
473 'type' => 'list',
474 'items' => $items,
475 'params' => array('multiple' => 'Y'),
476 'filterable' => ''
477 );
478 }
479 elseif(is_array($field['PROPERTY_USER_TYPE']) && !empty($field['PROPERTY_USER_TYPE']['USER_TYPE']))
480 {
481 $type = $field['PROPERTY_USER_TYPE']['USER_TYPE'];
482 if($type == 'Date')
483 {
484 $result = array(
485 'id' => $field['FIELD_ID'],
486 'name' => $field['NAME'],
487 'type' => 'date',
488 'filterable' => '',
489 'dateFilter' => true
490 );
491 }
492 elseif($type == 'DateTime')
493 {
494 $result = array(
495 'id' => $field['FIELD_ID'],
496 'name' => $field['NAME'],
497 'type' => 'date',
498 'time' => true,
499 'filterable' => '',
500 'dateFilter' => true
501 );
502 }
503 elseif($type == 'Sequence')
504 {
505 $result = array(
506 'id' => $field['FIELD_ID'],
507 'name' => $field['NAME'],
508 'type' => 'number',
509 'filterable' => ''
510 );
511 }
512 elseif($type === 'ECrm')
513 {
514 $result = [
515 'id' => $field['FIELD_ID'],
516 'name' => $field['NAME'],
517 'type' => 'dest_selector',
518 'params' => ElementType::getDestSelectorParametersForFilter(
519 $field['USER_TYPE_SETTINGS'],
520 $isMultiple = (isset($field['MULTIPLE']) && $field['MULTIPLE'] === 'Y')
521 ),
522 'filterable' => '',
523 ];
524 }
525 elseif(in_array($type, $customEntityType))
526 {
527 $result = array(
528 'id' => $field['FIELD_ID'],
529 'name' => $field['NAME'],
530 'type' => 'custom_entity',
531 'filterable' => '',
532 );
533 }
534 else
535 {
536 if(array_key_exists('GetPublicFilterHTML', $field['PROPERTY_USER_TYPE']))
537 {
538 $result = array(
539 'id' => $field['FIELD_ID'],
540 'name' => $field['NAME'],
541 'type' => 'custom',
542 'enable_settings' => false,
543 'value' => call_user_func_array(
544 $field['PROPERTY_USER_TYPE']['GetPublicFilterHTML'],
545 array(
546 $field,
547 array(
548 'VALUE' => $field['FIELD_ID'],
549 'FORM_NAME'=>'filter_'.$field['GRID_ID'],
550 'GRID_ID' => $field['GRID_ID']
551 )
552 )
553 ),
554 'filterable' => ''
555 );
556 }
557 else
558 {
559 $listLikeProperty = array('S:HTML');
560 $result = array(
561 'id' => $field['FIELD_ID'],
562 'name' => $field['NAME'],
563 'filterable' => in_array($field['TYPE'], $listLikeProperty) ? '?' : ''
564 );
565 }
566 }
567 if(array_key_exists('AddFilterFields', $field['PROPERTY_USER_TYPE']))
568 $result['customFilter'] = $field['PROPERTY_USER_TYPE']['AddFilterFields'];
569 }
570 else
571 {
572 $listLikeField = array('NAME', 'DETAIL_TEXT', 'PREVIEW_TEXT', 'S');
573 $result = array(
574 'id' => $field['FIELD_ID'],
575 'name' => $field['NAME'],
576 'filterable' => in_array($field['TYPE'], $listLikeField) ? '?' : ''
577 );
578 if($field['FIELD_ID'] == 'NAME')
579 {
580 $result['default'] = true;
581 }
582 }
583
584 return $result;
585 }
586
587 protected static function renderFieldByTypeS(array $field)
588 {
589 if($field['MULTIPLE'] == 'Y' && is_array($field['VALUE']))
590 {
591 $results = array();
592 foreach($field['VALUE'] as $value)
593 {
594 $results[] = nl2br(HtmlFilter::encode($value));
595 }
596 $result = implode(self::$separator, $results);
597 }
598 else
599 {
600 $result = nl2br(HtmlFilter::encode($field['VALUE']));
601 }
602 return $result;
603 }
604
605 protected static function renderFieldByTypeN(array $field)
606 {
607 if(empty($field['VALUE']))
608 return '';
609
610 if($field['MULTIPLE'] == 'Y' && is_array($field['VALUE']))
611 {
612 $results = array();
613 foreach($field['VALUE'] as $value)
614 {
615 $results[] = (float)$value;
616 }
617 $result = implode(self::$separator, $results);
618 }
619 else
620 {
621 $result = (float)$field['VALUE'];
622 }
623 return $result;
624 }
625
626 protected static function renderFieldByTypeL(array $field)
627 {
628 if(!empty(self::$cache[$field['ID']]))
629 {
630 $items = self::$cache[$field['ID']];
631 }
632 else
633 {
634 $items = array();
635 if(empty($field['DEFAULT']))
636 $items[] = Loc::getMessage('LISTS_FIELD_NO_VALUE');
637 $listElements = \CIBlockProperty::getPropertyEnum($field['ID']);
638 while($listElement = $listElements->fetch())
639 {
640 if(!empty($field['DEFAULT']))
641 {
642 if($listElement['DEF'] == 'Y')
643 {
644 $items[$listElement['ID']] = HtmlFilter::encode($listElement['VALUE']);
645 }
646 }
647 else
648 {
649 $items[$listElement['ID']] = HtmlFilter::encode($listElement['VALUE']);
650 }
651 if ($listElement['DEF'] == 'Y')
652 {
653 $field['DEFAULT_VALUE'] = HtmlFilter::encode($listElement['VALUE']);
654 }
655 }
656
657 self::$cache[$field['ID']] = $items;
658 }
659
660 if (is_array($field['VALUE']) && empty($field['VALUE']))
661 {
662 $result = $items[0] ?? null;
663 }
664 elseif (is_array($field['VALUE']))
665 {
666 foreach ($items as $itemKey => $itemValue)
667 {
668 if (!in_array($itemKey, $field['VALUE']))
669 {
670 unset($items[$itemKey]);
671 }
672 }
673 $result = implode(self::$separator, $items);
674 }
675 else
676 {
677 $result = $items[$field['VALUE']] ?? null;
678 }
679
680 return ($result ?: $field['DEFAULT_VALUE']);
681 }
682
683 protected static function renderFieldByTypeF(array $field)
684 {
685 if((empty($field['VALUE']) || !empty($field['DEFAULT'])) && !self::$renderForForm)
686 return '';
687
688 $iblockId = !empty($field['IBLOCK_ID']) ? intval($field['IBLOCK_ID']) : 0;
689 $sectionId = !empty($field['SECTION_ID']) ? intval($field['SECTION_ID']) : 0;
690 $elementId = !empty($field['ELEMENT_ID']) ? intval($field['ELEMENT_ID']) : 0;
691 $fieldId = !empty($field['FIELD_ID']) ? $field['FIELD_ID'] : '';
692 $socnetGroupId = !empty($field['SOCNET_GROUP_ID']) ? intval($field['SOCNET_GROUP_ID']) : 0;
693 $urlTemplate = !empty($field['LIST_FILE_URL']) ? $field['LIST_FILE_URL'] : '';
694 $downloadUrl = !empty($field['DOWNLOAD_FILE_URL']) ? $field['DOWNLOAD_FILE_URL'] : '';
695
696 $params = array(
697 'max_size' => 2024000,
698 'max_width' => 100,
699 'max_height' => 100,
700 'url_template' => $urlTemplate,
701 'download_url' => $downloadUrl,
702 'download_text' => Loc::getMessage('LISTS_FIELD_FILE_DOWNLOAD'),
703 'show_input' => false
704 );
705 if(!empty($field['READ']) && $field['READ'] == 'N')
706 $params['show_input'] = true;
707
708 if($field['MULTIPLE'] == 'Y' && is_array($field['VALUE']))
709 {
710 $results = array();
711 foreach($field['VALUE'] as $key => $value)
712 {
713 $file = new \CListFile($iblockId, $sectionId, $elementId, $fieldId,
714 is_array($value) && isset($value['VALUE']) ? $value['VALUE'] : $value);
715 $file->setSocnetGroup($socnetGroupId);
716 $fieldControlId = $field['TYPE'] == 'F' && self::$renderForForm ?
717 $fieldId.'['.$key.'][VALUE]' : $fieldId;
718 $fileControl = new \CListFileControl($file, $fieldControlId);
719 $results[] = $fileControl->getHTML($params);
720 }
721 $result = implode(self::$separator, $results);
722 }
723 else
724 {
725 if(is_array($field['VALUE']))
726 {
727 $results = array();
728 foreach($field['VALUE'] as $key => $value)
729 {
730 $file = new \CListFile($iblockId, $sectionId, $elementId, $fieldId,
731 is_array($value) && isset($value['VALUE']) ? $value['VALUE'] : $value);
732 $file->setSocnetGroup($socnetGroupId);
733 $fieldControlId = $field['TYPE'] == 'F' && self::$renderForForm ?
734 $fieldId.'['.$key.'][VALUE]' : $fieldId;
735 $fileControl = new \CListFileControl($file, $fieldControlId);
736 $results[] = $fileControl->getHTML($params);
737 }
738 $result = implode(self::$separator, $results);
739 }
740 else
741 {
742 $file = new \CListFile($iblockId, $sectionId, $elementId, $fieldId, $field['VALUE']);
743 $file->setSocnetGroup($socnetGroupId);
744 $fileControl = new \CListFileControl($file, $fieldId);
745 $result = $fileControl->getHTML($params);
746 }
747 }
748
749 return $result;
750 }
751
752 protected static function renderFieldByTypeE(array $field)
753 {
754 return self::getLinkToElement($field);
755 }
756
757 protected static function renderFieldByTypeG(array $field)
758 {
759 if(empty($field['VALUE']))
760 return Loc::getMessage('LISTS_FIELD_NOT_DATA');
761
762 if(!is_array($field['VALUE']))
763 $field['VALUE'] = array($field['VALUE']);
764
765 $urlTemplate = !empty($field['LIST_URL']) ? $field['LIST_URL'] : '';
766 $socnetGroupId = !empty($field['SOCNET_GROUP_ID']) ? intval($field['SOCNET_GROUP_ID']) : 0;
767
768 $result = array();
769 $filter = array();
770 foreach($field['VALUE'] as $value)
771 {
772 if(!empty(self::$cache[$field['TYPE']][$value]))
773 $result[] = self::$cache[$field['TYPE']][$value];
774
775 $filter['ID'][] = $value;
776 }
777
778 if(!empty($result) && (count($result) == count($field['VALUE'])))
779 return implode(self::$separator, $result);
780 else
781 $result = array();
782
783 $queryObject = \CIBlockSection::getList(array(),
784 array('=ID' => $field['VALUE']), false, array('ID', 'IBLOCK_ID', 'NAME'));
785 while($section = $queryObject->getNext())
786 {
787 if($urlTemplate)
788 {
789 $sectionUrl = \CHTTP::URN2URI(\CHTTP::urlAddParams(
790 str_replace(array("#list_id#", "#section_id#", "#group_id#"),
791 array($section['IBLOCK_ID'], 0, $socnetGroupId),
792 $urlTemplate), array('list_section_id' => $section['ID'])));
793
794 $html = '<a href="'.HtmlFilter::encode($sectionUrl).'" target="_blank">'.
795 HtmlFilter::encode($section['~NAME']).'</a>';
796 }
797 else
798 {
799 $html = HtmlFilter::encode($section['~NAME']);
800 }
801
802 $result[] = $html;
803 self::$cache[$field['TYPE']][$section['ID']] = $html;
804 }
805
806 return implode(self::$separator, $result);
807 }
808
809 protected static function renderFieldByUserTypeElist(array $field)
810 {
811 return self::getLinkToElement($field);
812 }
813
814 protected static function renderFieldByFieldPreviewPicture(array $field)
815 {
816 return self::renderFieldByTypeF($field);
817 }
818
819 protected static function renderFieldByFieldDetailPicture(array $field)
820 {
821 return self::renderFieldByTypeF($field);
822 }
823
824 protected static function renderFieldByFieldActiveFrom(array $field)
825 {
826 return self::renderDateField($field);
827 }
828
829 protected static function renderFieldByFieldActiveTo(array $field)
830 {
831 return self::renderDateField($field);
832 }
833
834 protected static function renderFieldByFieldDateCreate(array $field)
835 {
836 return self::renderDateField($field);
837 }
838
839 protected static function renderFieldByFieldTimestampX(array $field)
840 {
841 return self::renderDateField($field);
842 }
843
844 protected static function renderFieldByFieldCreatedBy(array $field)
845 {
846 $userId = (int)$field['VALUE'];
847
848 if(!empty(self::$cache[$field['TYPE']][$userId]))
849 return self::$cache[$field['TYPE']][$userId];
850
851 $user = new \CUser();
852 $userDetails = $user->getByID($userId)->fetch();
853 $result = null;
854
855 if(is_array($userDetails))
856 {
857 $siteNameFormat = \CSite::getNameFormat(false);
858 $formattedUsersName = \CUser::formatName($siteNameFormat, $userDetails, true, true);
859
860 $pathToUser = str_replace(array('#user_id#'), $userId,
861 Option::get('main', 'TOOLTIP_PATH_TO_USER', false, SITE_ID));
862
863 $result = '<a href="'.$pathToUser.'" target="_blank" bx-tooltip-user-id="'.$userId.'">'.$formattedUsersName.'</a>';
864
865 self::$cache[$field['TYPE']][$userId] = $result;
866 }
867
868 return $result;
869 }
870
871 protected static function renderFieldByFieldModifiedBy(array $field)
872 {
873 return self::renderFieldByFieldCreatedBy($field);
874 }
875
876 protected static function renderFieldByFieldDetailText(array $field)
877 {
878 if(isset($field["SETTINGS"]["USE_EDITOR"]) && $field["SETTINGS"]["USE_EDITOR"] == "Y")
879 return nl2br($field['VALUE']);
880 else
881 return nl2br(HtmlFilter::encode($field['VALUE']));
882 }
883
884 protected static function renderFieldByFieldPreviewText(array $field)
885 {
886 if(isset($field["SETTINGS"]["USE_EDITOR"]) && $field["SETTINGS"]["USE_EDITOR"] == "Y")
887 return nl2br($field['VALUE']);
888 else
889 return nl2br(HtmlFilter::encode($field['VALUE']));
890 }
891
892 protected static function renderDateField(array $field)
893 {
894 if(empty($field['VALUE']))
895 return '';
896
897 if($field['VALUE'] === '=now')
898 return ConvertTimeStamp(time()+\CTimeZone::getOffset(), 'FULL');
899 elseif($field['VALUE'] === '=today')
900 return ConvertTimeStamp(time()+\CTimeZone::getOffset(), 'SHORT');
901
902 if($field['MULTIPLE'] == 'Y' && is_array($field['VALUE']))
903 {
904 $results = array();
905 foreach($field['VALUE'] as $value)
906 {
907 $results[] = FormatDateFromDB($value, 'FULL');
908 }
909 $result = implode(self::$separator, $results);
910 }
911 else
912 {
913 $result = FormatDateFromDB($field['VALUE'], 'FULL');
914 }
915 return $result;
916 }
917
918 protected static function renderFieldByFieldName(array $field)
919 {
920 if(empty($field['LIST_ELEMENT_URL']))
921 return self::renderDefaultField($field);
922
923 $iblockId = !empty($field['IBLOCK_ID']) ? intval($field['IBLOCK_ID']) : 0;
924 $sectionId = !empty($field['SECTION_ID']) ? intval($field['SECTION_ID']) : 0;
925 $elementId = !empty($field['ELEMENT_ID']) ? intval($field['ELEMENT_ID']) : 0;
926 $socnetGroupId = !empty($field['SOCNET_GROUP_ID']) ? intval($field['SOCNET_GROUP_ID']) : 0;
927 $urlTemplate = $field['LIST_ELEMENT_URL'];
928
929 $url = str_replace(
930 ['#list_id#', '#section_id#', '#element_id#', '#group_id#'],
931 [$iblockId, $sectionId, $elementId, $socnetGroupId],
932 $urlTemplate
933 );
934 $url = \CHTTP::urlAddParams($url, ['list_section_id' => ($sectionId ? $sectionId : '')]);
935
936 $result = '<a href="'.\CHTTP::URN2URI(HtmlFilter::encode($url)).'">'.HtmlFilter::encode($field['VALUE']).'</a>';
937 return $result;
938 }
939
940 protected static function renderDefaultField(array $field)
941 {
942 if($field['MULTIPLE'] == 'Y' && is_array($field['VALUE']))
943 {
944 $results = array();
945 foreach($field['VALUE'] as $value)
946 {
947 $results[] = $value;
948 }
949 $result = implode(self::$separator, $results);
950 }
951 else
952 {
953 $result = $field['VALUE'];
954 }
955 return HtmlFilter::encode($result);
956 }
957
958 protected static function getLinkToElement(array $field)
959 {
960 if(empty($field['VALUE']))
961 return Loc::getMessage('LISTS_FIELD_NOT_DATA');
962
963 if(!is_array($field['VALUE']))
964 $field['VALUE'] = array($field['VALUE']);
965
966 $result = array();
967 $filter = array();
968 foreach($field['VALUE'] as $value)
969 {
970 if(!empty(self::$cache[$field['TYPE']][$value]))
971 $result[] = self::$cache[$field['TYPE']][$value];
972
973 $filter['ID'][] = $value;
974 }
975
976 if(!empty($result) && (count($result) == count($field['VALUE'])))
977 return implode(self::$separator, $result);
978 else
979 $result = array();
980
981 $urlTemplate = \CList::getUrlByIblockId($field['LINK_IBLOCK_ID']);
982 if(!$urlTemplate && !empty($field["LIST_ELEMENT_URL"]))
983 $urlTemplate = $field["LIST_ELEMENT_URL"];
984 $filter['CHECK_PERMISSIONS'] = 'Y';
985 if ($field['LINK_IBLOCK_ID'] > 0)
986 $filter['IBLOCK_ID'] = $field['LINK_IBLOCK_ID'];
987
988 $queryObject = \CIBlockElement::getList(array(), $filter, false, false, array('*'));
989 while($element = $queryObject->getNext())
990 {
991 $elementUrl = str_replace(
992 array('#list_id#', '#section_id#', '#element_id#'),
993 array($element['IBLOCK_ID'], '0', $element['ID']),
994 $urlTemplate
995 );
996 $elementUrl = \CHTTP::urlAddParams($elementUrl, array("list_section_id" => ""));
997 $result[] = '<a href="'.HtmlFilter::encode($elementUrl).'" target="_blank">'.HtmlFilter::encode(
998 $element['~NAME']).'</a>';
999
1000 self::$cache[$field['TYPE']][$element['ID']] =
1001 '<a href="'.HtmlFilter::encode($elementUrl).'" target="_blank">'.HtmlFilter::encode(
1002 $element['~NAME']).'</a>';
1003 }
1004
1005 return implode(self::$separator, $result);
1006 }
1007
1008 protected static function renderCustomDefaultValueDiskFile(array $field)
1009 {
1010 if(!Loader::includeModule('disk'))
1011 return '';
1012
1013 if(is_array($field['VALUE']))
1014 $field['VALUE'] = array_diff($field['VALUE'], array(''));
1015 else
1016 $field['VALUE'] = explode(',', $field['VALUE']);
1017
1018 $listValue = array();
1019 foreach($field['VALUE'] as $value)
1020 {
1021 [$type, $realId] = \Bitrix\Disk\Uf\FileUserType::detectType($value);
1022 if($type == \Bitrix\Disk\Uf\FileUserType::TYPE_NEW_OBJECT)
1023 {
1024 $fileModel = \Bitrix\Disk\File::loadById($realId, array('STORAGE'));
1025 if(!$fileModel)
1026 {
1027 return '';
1028 }
1029
1030 $listValue[] = $fileModel->getName();
1031 }
1032 else
1033 {
1034 $listValue[] = $realId;
1035 }
1036 }
1037
1038 return implode(',', $listValue);
1039 }
1040
1041 protected static function prepareEditFieldByTypeL(array $field)
1042 {
1043 $items = array('' => Loc::getMessage('LISTS_FIELD_NO_VALUE'));
1044 $queryObject = \CIBlockProperty::getPropertyEnum($field['ID']);
1045 while($enum = $queryObject->fetch())
1046 {
1047 if ($enum['DEF'] == 'Y')
1048 {
1049 $field['DEFAULT_VALUE'] = $enum['ID'];
1050 }
1051 $items[$enum['ID']] = $enum['VALUE'];
1052 }
1053
1054 $inputName = $field['FIELD_ID'];
1055 if($field['MULTIPLE'] == 'Y')
1056 {
1057 $inputName .= '[]';
1058 $params = array('size' => 5, 'multiple' => 'multiple');
1059 }
1060 else
1061 {
1062 $params = array();
1063 }
1064
1065 if (!is_array($field['VALUE']))
1066 {
1067 $field['VALUE'] = ($field['VALUE'] ? array($field['VALUE']) : array());
1068 }
1069
1070 if (empty($field['VALUE']))
1071 {
1072 $field['VALUE'][] = $field['DEFAULT_VALUE'];
1073 }
1074
1075 $result = array(
1076 'id' => $inputName,
1077 'name' => $field['NAME'],
1078 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1079 "type"=>'list',
1080 "items"=>$items,
1081 'show' => $field['SHOW'],
1082 'value' => $field['VALUE'],
1083 'customHtml' => '',
1084 );
1085 if($field['READ'] == 'Y')
1086 {
1087 $params['disabled'] = 'disabled';
1088
1089 foreach($field['VALUE'] as $value)
1090 {
1091 $result['customHtml'] .= '<input type="hidden" name="'.$inputName.
1092 '" value="'.HtmlFilter::encode($value).'">';
1093 }
1094 }
1095 $result['params'] = $params;
1096
1097 return $result;
1098 }
1099
1100 protected static function prepareEditFieldByTypeS(array $field)
1101 {
1102 $html = '';
1103 $disabled = $field['READ'] == 'Y' ? 'disabled' : '';
1104 if(!is_array($field['VALUE']))
1105 $field['VALUE'] = array($field['VALUE']);
1106
1107 if($field['MULTIPLE'] == 'Y')
1108 {
1109 $html .= '<table id="tbl'.$field['FIELD_ID'].'">';
1110 if ($field["ROW_COUNT"] > 1)
1111 {
1112 foreach($field['VALUE'] as $key => $value)
1113 {
1114 if($field['READ'] == 'Y')
1115 {
1116 if(empty($value['VALUE'])) continue;
1117 $html .= '<input type="hidden" name="'.$field['FIELD_ID'].'['.$key.'][VALUE]" value="'.
1118 HtmlFilter::encode($value["VALUE"]).'">';
1119 }
1120 $html.='<tr><td><textarea '.$disabled.' style="width:auto;height:auto;" name="'.$field['FIELD_ID'].
1121 '['.$key.'][VALUE]" rows="'.intval($field["ROW_COUNT"]).'" cols="'.
1122 intval($field["COL_COUNT"]).'">'.HtmlFilter::encode($value["VALUE"]).'</textarea></td></tr>';
1123 }
1124 }
1125 else
1126 {
1127 foreach($field['VALUE'] as $key => $value)
1128 {
1129 if($field['READ'] == 'Y')
1130 {
1131 if(empty($value['VALUE'])) continue;
1132 $html .= '<input type="hidden" name="'.$field['FIELD_ID'].'['.$key.'][VALUE]" value="'.
1133 HtmlFilter::encode($value["VALUE"]).'">';
1134 }
1135 $html .= '<tr><td class="bx-field-value"><input '.$disabled.' type="text" name="'.$field['FIELD_ID'].
1136 '['.$key.'][VALUE]" value="'.HtmlFilter::encode($value['VALUE']).'" size="'.
1137 intval($field["COL_COUNT"]).'"></td></tr>';
1138 }
1139 }
1140 $html .= '</table>';
1141 if($field['READ'] == 'N')
1142 {
1143 $html .= '<input type="button" value="'.Loc::getMessage('LISTS_FIELD_ADD_BUTTON').'"
1144 onclick="BX.Lists.addNewTableRow(\'tbl'.$field['FIELD_ID'].'\', 1, /'.
1145 $field['FIELD_ID'].'\[(n)([0-9]*)\]/g, 2)">';
1146 }
1147 }
1148 else
1149 {
1150 if ($field["ROW_COUNT"] > 1)
1151 {
1152 foreach($field['VALUE'] as $key => $value)
1153 {
1154 $html .= '<textarea '.$disabled.' style="width:auto;height:auto;" name="'.$field['FIELD_ID'].
1155 '['.$key.'][VALUE]" rows="'.intval($field["ROW_COUNT"]).'" cols="'.intval($field["COL_COUNT"]).'">'.HtmlFilter::encode($value["VALUE"]).'</textarea>';
1156 if($field['READ'] == 'Y')
1157 {
1158 if(empty($value['VALUE'])) continue;
1159 $html .= '<input type="hidden" name="'.$field['FIELD_ID'].'['.$key.'][VALUE]" value="'.
1160 HtmlFilter::encode($value["VALUE"]).'">';
1161 }
1162 }
1163 }
1164 else
1165 {
1166 foreach($field['VALUE'] as $key => $value)
1167 {
1168 $html .= '<input '.$disabled.' type="text" name="'.$field['FIELD_ID'].'['.$key.'][VALUE]" value="'.
1169 HtmlFilter::encode($value["VALUE"]).'" size="'.intval($field["COL_COUNT"]).'">';
1170 if($field['READ'] == 'Y')
1171 {
1172 if(empty($value['VALUE'])) continue;
1173 $html .= '<input type="hidden" name="'.$field['FIELD_ID'].'['.$key.'][VALUE]" value="'.
1174 HtmlFilter::encode($value["VALUE"]).'">';
1175 }
1176 }
1177 }
1178 }
1179
1180 $result = array(
1181 'id' => $field['FIELD_ID'],
1182 'name' => $field['NAME'],
1183 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1184 'type' => 'custom',
1185 'show' => $field['SHOW'],
1186 'value' => $html
1187 );
1188
1189 return $result;
1190 }
1191
1192 protected static function prepareEditFieldByTypeN(array $field)
1193 {
1194 $result = array(
1195 'id' => $field['FIELD_ID'],
1196 'name' => $field['NAME'],
1197 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1198 'type' => 'custom',
1199 'show' => $field['SHOW'],
1200 'customHtml' => '',
1201 );
1202 $html = '';
1203 $disabled = $field['READ'] == 'Y' ? 'disabled' : '';
1204 if(!is_array($field['VALUE']))
1205 $field['VALUE'] = array($field['VALUE']);
1206
1207 if($field['MULTIPLE'] == 'Y')
1208 {
1209 $html .= '<table id="tbl'.$field['FIELD_ID'].'">';
1210 foreach($field['VALUE'] as $key => $value)
1211 {
1212 if($field['READ'] == 'Y')
1213 {
1214 if(empty($value['VALUE'])) continue;
1215 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
1216 '['.$key.'][VALUE]" value="'.$value['VALUE'].'">';
1217 }
1218 $html .= '<tr><td class="bx-field-value"><input '.$disabled.' type="text" name="'.$field['FIELD_ID'].
1219 '['.$key.'][VALUE]" value="'.HtmlFilter::encode($value["VALUE"]).'"></td></tr>';
1220 }
1221 $html .= '</table>';
1222 if($field['READ'] == 'N')
1223 {
1224 $html .= '<input type="button" value="'.Loc::getMessage('LISTS_FIELD_ADD_BUTTON').'"
1225 onclick="BX.Lists.addNewTableRow(\'tbl'.$field['FIELD_ID'].'\', 1, /'.
1226 $field['FIELD_ID'].'\[(n)([0-9]*)\]/g, 2)">';
1227 }
1228 }
1229 else
1230 {
1231 foreach($field['VALUE'] as $key => $value)
1232 {
1233 $html .= '<input '.$disabled.' type="text" name="'.$field['FIELD_ID'].
1234 '['.$key.'][VALUE]" value="'.HtmlFilter::encode($value["VALUE"]).'">';
1235 if($field['READ'] == 'Y')
1236 {
1237 if(empty($value['VALUE'])) continue;
1238 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
1239 '['.$key.'][VALUE]" value="'.$value["VALUE"].'">';
1240 }
1241 }
1242 }
1243 $result['value'] = $html;
1244
1245 return $result;
1246 }
1247
1248 protected static function prepareEditFieldByUserTypeHTML(array $field)
1249 {
1250 $result = [
1251 'id' => $field['FIELD_ID'] . '[]',
1252 'name' => $field['NAME'],
1253 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1254 'type' => 'custom',
1255 'show' => $field['SHOW'],
1256 'customHtml' => '',
1257 ];
1258 $html = '';
1259 if (!isset($field['VALUE']) || !is_array($field['VALUE']))
1260 {
1261 $field['VALUE'] = [$field['VALUE'] ?? null];
1262 }
1263
1264 $isEmptyValue = true;
1265 foreach($field['VALUE'] as $value)
1266 {
1267 if(!empty($value['VALUE']))
1268 $isEmptyValue = false;
1269 }
1270 if($isEmptyValue && $field['READ'] == 'Y')
1271 {
1272 $result['value'] = Loc::getMessage('LISTS_FIELD_NOT_DATA');
1273 return $result;
1274 }
1275
1276 if($field['MULTIPLE'] == 'Y')
1277 {
1278 $params = array('width' => '100%','height' => '200px');
1279 $html .= '<table id="tbl'.$field['FIELD_ID'].'">';
1280 foreach($field['VALUE'] as $key => $value)
1281 {
1282 if($field['READ'] == 'Y')
1283 {
1284 $html .= call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicViewHTML'],
1285 array(
1286 $field,
1287 $value,
1288 array(
1289 'VALUE' => $field['FIELD_ID']."[".$key."][VALUE]",
1290 'DESCRIPTION' => '',
1291 'FORM_NAME' => 'form_'.$field['FORM_ID'],
1292 'MODE' => 'FORM_FILL',
1293 'COPY' => $field['COPY_ID'] > 0,
1294 ),
1295 ));
1296 if(is_array($value['VALUE']))
1297 {
1298 $value['VALUE']['TEXT'] ? $htmlContent = $value['VALUE']['TEXT'] : $htmlContent = '';
1299 }
1300 else
1301 {
1302 $value['VALUE'] ? $htmlContent = $value['VALUE'] : $htmlContent = '';
1303 }
1304 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
1305 '['.$key.'][VALUE][TYPE]" value="html">';
1306 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
1307 '['.$key.'][VALUE][TEXT]" value="'.HtmlFilter::encode($htmlContent).'">';
1308 }
1309 else
1310 {
1311 if(is_array($value['VALUE']))
1312 $htmlContent = $value['VALUE']['TEXT'] ? $value['VALUE']['TEXT'] : '';
1313 else
1314 $htmlContent = $value['VALUE'] ? $value['VALUE'] : '';
1315 $fieldIdForHtml = 'id_'.$field['FIELD_ID'].'__'.$key.'_';
1316 $fieldNameForHtml = $field['FIELD_ID']."[".$key."][VALUE][TEXT]";
1317 $html .= '<tr><td><input type="hidden" name="'.$field['FIELD_ID'].
1318 '['.$key.'][VALUE][TYPE]" value="html">'.self::renderHtmlEditor(
1319 $fieldIdForHtml, $fieldNameForHtml, $params, $htmlContent).'</td></tr>';
1320 }
1321 }
1322 $html .= '</table>';
1323 if($field['READ'] == 'N')
1324 {
1325 $html .= '<input type="button" value="'.Loc::getMessage("LISTS_FIELD_ADD_BUTTON").'"
1326 onclick="BX.Lists.createAdditionalHtmlEditor(\'tbl'.$field['FIELD_ID'].'\',
1327 \''.$field['FIELD_ID'].'\', \''.$field['FIELD_ID'].'\');">';
1328 }
1329
1330 }
1331 else
1332 {
1333 foreach($field['VALUE'] as $key => $value)
1334 {
1335 if($field['READ'] == 'Y')
1336 {
1337 $html .= call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicViewHTML'],
1338 array(
1339 $field,
1340 $value,
1341 array(
1342 'VALUE' => $field['FIELD_ID']."[".$key."][VALUE]",
1343 'DESCRIPTION' => '',
1344 'FORM_NAME' => 'form_' . ($field['FORM_ID'] ?? ''),
1345 'MODE' => 'FORM_FILL',
1346 'COPY' => isset($field['COPY_ID']) && $field['COPY_ID'] > 0,
1347 ),
1348 ));
1349 if(is_array($value['VALUE']))
1350 $value['VALUE']['TEXT'] ? $htmlContent = $value['VALUE']['TEXT'] : $htmlContent = '';
1351 else
1352 $value['VALUE'] ? $htmlContent = $value['VALUE'] : $htmlContent = '';
1353 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
1354 '['.$key.'][VALUE][TYPE]" value="html">';
1355 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].
1356 '['.$key.'][VALUE][TEXT]" value="'.HtmlFilter::encode($htmlContent).'">';
1357 }
1358 else
1359 {
1360 $html .= call_user_func_array($field['PROPERTY_USER_TYPE']['GetPublicEditHTML'],
1361 array(
1362 $field,
1363 $value,
1364 array(
1365 'VALUE' => $field['FIELD_ID']."[".$key."][VALUE]",
1366 'DESCRIPTION' => '',
1367 'FORM_NAME' => 'form_' . ($field['FORM_ID'] ?? ''),
1368 'MODE' => 'FORM_FILL',
1369 'COPY' => $field['COPY_ID'] > 0,
1370 ),
1371 ));
1372 }
1373 }
1374 }
1375
1376 $result['value'] = $html;
1377
1378 return $result;
1379 }
1380
1381 protected static function prepareEditFieldByFieldCreatedBy(array $field)
1382 {
1383 $result = array();
1384 if($field['ELEMENT_ID'])
1385 {
1386 $result = array(
1387 'id' => $field['FIELD_ID'],
1388 'name' => $field['NAME'],
1389 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1390 'type' => 'custom',
1391 'show' => $field['SHOW'],
1392 'value' => self::renderFieldByFieldCreatedBy($field)
1393 );
1394 }
1395 return $result;
1396 }
1397
1398 protected static function prepareEditFieldByFieldModifiedBy(array $field)
1399 {
1400 return self::prepareEditFieldByFieldCreatedBy($field);
1401 }
1402
1403 protected static function prepareEditFieldByFieldDateCreate(array $field)
1404 {
1405 $result = array();
1406 if($field['ELEMENT_ID'])
1407 {
1408 $result = array(
1409 'id' => $field['FIELD_ID'],
1410 'name' => $field['NAME'],
1411 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1412 'type' => 'custom',
1413 'show' => $field['SHOW'],
1414 'value' => $field['VALUE']
1415 );
1416 }
1417 return $result;
1418 }
1419
1420 protected static function prepareEditFieldByFieldTimestampX(array $field)
1421 {
1422 return self::prepareEditFieldByFieldDateCreate($field);
1423 }
1424
1425 protected static function prepareEditFieldByFieldDetailText(array $field)
1426 {
1427 return self::prepareEditFieldByText($field);
1428 }
1429
1430 protected static function prepareEditFieldByFieldPreviewText(array $field)
1431 {
1432 return self::prepareEditFieldByText($field);
1433 }
1434
1435 protected static function prepareEditFieldByFieldPreviewPicture(array $field)
1436 {
1437 $result = array(
1438 'id' => $field['FIELD_ID'],
1439 'name' => $field['NAME'],
1440 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1441 'type' => 'custom',
1442 'show' => $field['SHOW'],
1443 'value' => ($field['ELEMENT_ID'] > 0 && empty($field['VALUE']) && $field['READ'] == 'Y') ?
1444 Loc::getMessage('LISTS_FIELD_NOT_DATA') : self::renderFieldByTypeF($field)
1445 );
1446 return $result;
1447 }
1448
1449 protected static function prepareEditFieldByFieldDetailPicture(array $field)
1450 {
1451 $result = array(
1452 'id' => $field['FIELD_ID'],
1453 'name' => $field['NAME'],
1454 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1455 'type' => 'custom',
1456 'show' => $field['SHOW'],
1457 'value' => ($field['ELEMENT_ID'] > 0 && empty($field['VALUE']) && $field['READ'] == 'Y') ?
1458 Loc::getMessage('LISTS_FIELD_NOT_DATA') : self::renderFieldByTypeF($field)
1459 );
1460 return $result;
1461 }
1462
1463 protected static function prepareEditFieldByFieldActiveFrom(array $field)
1464 {
1465 return self::prepareDateEditField($field);
1466 }
1467
1468 protected static function prepareEditFieldByFieldActiveTo(array $field)
1469 {
1470 return self::prepareDateEditField($field);
1471 }
1472
1473 protected static function prepareEditFieldByText($field)
1474 {
1475 if($field['READ'] == 'Y')
1476 {
1477 $result = array(
1478 'id' => $field['FIELD_ID'],
1479 'name' => $field['NAME'],
1480 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1481 'type' => 'custom',
1482 'value' => '<textarea disabled>'.HtmlFilter::encode($field['VALUE'] ?? '').'</textarea>
1483 <input type="hidden" name="'.$field['FIELD_ID'].'" value="'.HtmlFilter::encode($field['VALUE'] ?? '').'">',
1484 'show' => $field['SHOW']
1485 );
1486 }
1487 else
1488 {
1489 $result = array(
1490 'id' => $field['FIELD_ID'],
1491 'name' => $field['NAME'],
1492 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1493 'type' => 'textarea',
1494 'show' => $field['SHOW']
1495 );
1496 if($field['SETTINGS']['USE_EDITOR'] == 'Y')
1497 {
1498 $params = array('width' => '100%', 'height' => '200px');
1499 $match = array();
1500 if(preg_match('/\s*(\d+)\s*(px|%|)/', $field['SETTINGS']['WIDTH'], $match) && ($match[1] > 0))
1501 $params['width'] = $match[1].$match[2];
1502 if(preg_match('/\s*(\d+)\s*(px|%|)/', $field['SETTINGS']['HEIGHT'], $match) && ($match[1] > 0))
1503 $params['height'] = $match[1].$match[2];
1504 $result['type'] = 'custom';
1505 $result['params'] = $params;
1506 $result['value'] = self::renderHtmlEditor(
1507 $field['FIELD_ID'], $field['FIELD_ID'], $params, $field['VALUE']);
1508 }
1509 else
1510 {
1511 $params = array('style' => '');
1512 if(preg_match('/\s*(\d+)\s*(px|%|)/', $field['SETTINGS']['WIDTH'], $match) && ($match[1] > 0))
1513 $params['style'] .= 'width:'.$match[1].'px;';
1514 if(preg_match('/\s*(\d+)\s*(px|%|)/', $field['SETTINGS']['HEIGHT'], $match) && ($match[1] > 0))
1515 $params['style'] .= 'height:'.$match[1].'px;';
1516 $result['params'] = $params;
1517 }
1518 }
1519
1520 return $result;
1521 }
1522
1523 protected static function prepareEditFieldByTypeE(array $field)
1524 {
1525 if($field['READ'] == 'Y' && empty($field['VALUE']))
1526 {
1527 return array(
1528 'id' => $field['FIELD_ID'],
1529 'name' => $field['NAME'],
1530 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1531 'type' => 'custom',
1532 'show' => $field['SHOW'],
1533 'value' => Loc::getMessage('LISTS_FIELD_NOT_DATA')
1534 );
1535 }
1536
1537 if(!is_array($field['VALUE']))
1538 $field['VALUE'] = array($field['VALUE']);
1539
1540 $currentElements = array();
1541 foreach($field['VALUE'] as $value)
1542 {
1543 if($value)
1544 {
1545 $currentElements[] = $value;
1546 }
1547 }
1548
1549 $randomGenerator = new RandomSequence($field['FIELD_ID']);
1550 $randString = mb_strtolower($randomGenerator->randString(6));
1551
1552 $html = '';
1553 global $APPLICATION;
1554 ob_start();
1555 $APPLICATION->includeComponent('bitrix:iblock.element.selector', '',
1556 array(
1557 'SELECTOR_ID' => $randString,
1558 'INPUT_NAME' => $field['FIELD_ID'],
1559 'IBLOCK_ID' => $field['LINK_IBLOCK_ID'],
1560 'MULTIPLE' => $field['MULTIPLE'],
1561 'CURRENT_ELEMENTS_ID' => $currentElements,
1562 'POPUP' => 'Y',
1563 'ONLY_READ' => $field['READ'],
1564 'PANEL_SELECTED_VALUES' => 'Y',
1565 'TEMPLATE_URL' => $field['LIST_ELEMENT_URL']
1566 ),
1567 null, array('HIDE_ICONS' => 'Y')
1568 );
1569 $html .= ob_get_contents();
1570 ob_end_clean();
1571
1572 $result = array(
1573 'id' => $field['FIELD_ID'],
1574 'name' => $field['NAME'],
1575 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1576 'type' => 'custom',
1577 'show' => $field['SHOW'],
1578 'value' => $html
1579 );
1580
1581 return $result;
1582 }
1583
1584 protected static function prepareEditFieldByTypeG(array $field)
1585 {
1586 if($field['IS_REQUIRED'] == 'Y')
1587 $items = array();
1588 else
1589 $items = array('' => Loc::getMessage('LISTS_FIELD_NO_VALUE'));
1590
1591 $queryObject = \CIBlockSection::getTreeList(array('IBLOCK_ID' => $field['LINK_IBLOCK_ID']));
1592 while($section = $queryObject->getNext())
1593 $items[$section['ID']] = str_repeat(' . ', $section['DEPTH_LEVEL']).$section['~NAME'];
1594
1595 $inputName = $field['FIELD_ID'];
1596 if($field['MULTIPLE'] == 'Y')
1597 {
1598 $inputName .= '[]';
1599 $params = array('size' => 5, 'multiple' => 'multiple');
1600 }
1601 else
1602 {
1603 $params = array();
1604 }
1605 if($field['READ'] == 'Y')
1606 $params["disabled"] = 'disabled';
1607
1608 if(!is_array($field['VALUE']))
1609 $field['VALUE'] = array($field['VALUE']);
1610
1611 $result = array(
1612 'id' => $inputName,
1613 'name' => $field['NAME'],
1614 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1615 'type' => 'list',
1616 'show' => $field['SHOW'],
1617 'value' => $field['VALUE'],
1618 'items' => $items,
1619 'params' => $params
1620 );
1621
1622 if($field['READ'] == 'Y')
1623 {
1624 foreach($field['VALUE'] as $value)
1625 $result['customHtml'] .= '<input type="hidden" name="'.$field['FIELD_ID'].'[]" value="'.
1626 HtmlFilter::encode($value).'">';
1627 }
1628
1629 return $result;
1630 }
1631
1632 protected static function prepareEditFieldByTypeF(array $field)
1633 {
1634 $html = '';
1635 if(!is_array($field['VALUE']))
1636 $field['VALUE'] = array($field['VALUE']);
1637
1638 $isEmptyValue = true;
1639 foreach($field['VALUE'] as $value)
1640 {
1641 if(!empty($value['VALUE']))
1642 $isEmptyValue = false;
1643 }
1644
1645 if($field['MULTIPLE'] == 'Y')
1646 {
1647 $html .= '<table id="tbl'.$field['FIELD_ID'].'">';
1648 if($field['ELEMENT_ID'] > 0 && $isEmptyValue && $field['READ'] == 'Y')
1649 {
1650 $html .= '<tr><td>';
1651 $html .= Loc::getMessage('LISTS_FIELD_NOT_DATA');
1652 $html .= '</td></tr>';
1653 }
1654 else
1655 {
1656 $iblockId = !empty($field['IBLOCK_ID']) ? intval($field['IBLOCK_ID']) : 0;
1657 $sectionId = !empty($field['SECTION_ID']) ? intval($field['SECTION_ID']) : 0;
1658 $elementId = !empty($field['ELEMENT_ID']) ? intval($field['ELEMENT_ID']) : 0;
1659 $fieldId = !empty($field['FIELD_ID']) ? $field['FIELD_ID'] : '';
1660 $socnetGroupId = !empty($field['SOCNET_GROUP_ID']) ? intval($field['SOCNET_GROUP_ID']) : 0;
1661 $urlTemplate = !empty($field['LIST_FILE_URL']) ? $field['LIST_FILE_URL'] : '';
1662 $downloadUrl = !empty($field['DOWNLOAD_FILE_URL']) ? $field['DOWNLOAD_FILE_URL'] : '';
1663 $params = array(
1664 'max_size' => 2024000,
1665 'max_width' => 100,
1666 'max_height' => 100,
1667 'url_template' => $urlTemplate,
1668 'download_url' => $downloadUrl,
1669 'download_text' => Loc::getMessage('LISTS_FIELD_FILE_DOWNLOAD'),
1670 'show_input' => $field['READ'] == 'N'
1671 );
1672 foreach($field['VALUE'] as $key => $value)
1673 {
1674 $html .= '<tr><td>';
1675 $file = new \CListFile($iblockId, $sectionId, $elementId, $fieldId,
1676 is_array($value) && isset($value['VALUE']) ? $value['VALUE'] : $value);
1677 $file->setSocnetGroup($socnetGroupId);
1678 $fieldControlId = $field['TYPE'] == 'F' && self::$renderForForm ?
1679 $fieldId.'['.$key.'][VALUE]' : $fieldId;
1680 $fileControl = new \CListFileControl($file, $fieldControlId);
1681 $html .= $fileControl->getHTML($params);
1682 $html .= '</td></tr>';
1683 }
1684 }
1685 $html .= '</table>';
1686 if($field['READ'] == 'N')
1687 {
1688 $html .= '<input type="button" value="'.Loc::getMessage("LISTS_FIELD_ADD_BUTTON").'"
1689 onclick="BX.Lists.addNewTableRow(\'tbl'.$field['FIELD_ID'].'\', 1, /'.
1690 $field['FIELD_ID'].'\[(n)([0-9]*)\]/g, 2)">';
1691 }
1692 }
1693 else
1694 {
1695 $html .= ($field['ELEMENT_ID'] > 0 && $isEmptyValue && $field['READ'] == 'Y') ?
1696 Loc::getMessage('LISTS_FIELD_NOT_DATA') : self::renderFieldByTypeF($field);
1697 }
1698
1699 $result = array(
1700 'id' => $field['FIELD_ID'],
1701 'name' => $field['NAME'],
1702 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1703 'type' => 'custom',
1704 'show' => $field['SHOW'],
1705 'value' => $html
1706 );
1707 return $result;
1708 }
1709
1710 protected static function prepareDateEditField(array $field)
1711 {
1712 $result = array(
1713 'id' => $field['FIELD_ID'],
1714 'name' => $field['NAME'],
1715 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1716 'type' => 'date',
1717 'show' => $field['SHOW']
1718 );
1719
1720 if($field['READ'] == 'Y')
1721 {
1722 $result['type'] = 'custom';
1723 if(($field['ELEMENT_ID'] ?? 0) > 0 && empty($field['VALUE']))
1724 {
1725 $result['value'] = Loc::getMessage('LISTS_FIELD_NOT_DATA');
1726 }
1727 else
1728 {
1729 $result['value'] = '<input disabled type="text" value="'.HtmlFilter::encode($field['VALUE']).
1730 '"><input type="hidden" name="'.$field['FIELD_ID'].'" value="'.
1731 HtmlFilter::encode($field['VALUE']).'">';
1732 }
1733 }
1734 return $result;
1735 }
1736
1737 protected static function prepareEditDefaultField(array $field)
1738 {
1739 $result = array(
1740 'id' => $field['FIELD_ID'],
1741 'name' => $field['NAME'],
1742 'required' => $field['IS_REQUIRED'] == 'Y' ? true : false,
1743 'type' => 'text',
1744 'show' => $field['SHOW']
1745 );
1746 if($field['READ'] == 'Y')
1747 {
1748 $result['type'] = 'custom';
1749 $result['value'] = '<input disabled type="text" value="'.HtmlFilter::encode($field['VALUE']).
1750 '"><input type="hidden" name="'.$field["FIELD_ID"].'" value="'.HtmlFilter::encode($field['VALUE']).'">';
1751 }
1752 return $result;
1753 }
1754
1755 protected static function renderHtmlEditor($fieldId, $fieldNameForHtml, $params, $content)
1756 {
1757 $html = '';
1758 if (Loader::includeModule('fileman'))
1759 {
1760 ob_start();
1761 $editor = new \CHTMLEditor;
1762 $res = array(
1763 'name' => $fieldNameForHtml,
1764 'inputName' => $fieldNameForHtml,
1765 'id' => $fieldId,
1766 'width' => $params['width'],
1767 'height' => $params['height'],
1768 'content' => $content,
1769 'useFileDialogs' => false,
1770 'minBodyWidth' => 350,
1771 'normalBodyWidth' => 555,
1772 'bAllowPhp' => false,
1773 'limitPhpAccess' => false,
1774 'showTaskbars' => false,
1775 'showNodeNavi' => false,
1776 'beforeUnloadHandlerAllowed' => true,
1777 'askBeforeUnloadPage' => false,
1778 'bbCode' => false,
1779 'siteId' => SITE_ID,
1780 'autoResize' => true,
1781 'autoResizeOffset' => 40,
1782 'saveOnBlur' => true,
1783 'actionUrl' => '/bitrix/tools/html_editor_action.php',
1784 'setFocusAfterShow' => false,
1785 'controlsMap' => array(
1786 array('id' => 'Bold', 'compact' => true, 'sort' => 80),
1787 array('id' => 'Italic', 'compact' => true, 'sort' => 90),
1788 array('id' => 'Underline', 'compact' => true, 'sort' => 100),
1789 array('id' => 'Strikeout', 'compact' => true, 'sort' => 110),
1790 array('id' => 'RemoveFormat', 'compact' => true, 'sort' => 120),
1791 array('id' => 'Color', 'compact' => true, 'sort' => 130),
1792 array('id' => 'FontSelector', 'compact' => false, 'sort' => 135),
1793 array('id' => 'FontSize', 'compact' => false, 'sort' => 140),
1794 array('separator' => true, 'compact' => false, 'sort' => 145),
1795 array('id' => 'OrderedList', 'compact' => true, 'sort' => 150),
1796 array('id' => 'UnorderedList', 'compact' => true, 'sort' => 160),
1797 array('id' => 'AlignList', 'compact' => false, 'sort' => 190),
1798 array('separator' => true, 'compact' => false, 'sort' => 200),
1799 array('id' => 'InsertLink', 'compact' => true, 'sort' => 210),
1800 array('id' => 'InsertImage', 'compact' => false, 'sort' => 220),
1801 array('id' => 'InsertVideo', 'compact' => true, 'sort' => 230),
1802 array('id' => 'InsertTable', 'compact' => false, 'sort' => 250),
1803 array('separator' => true, 'compact' => false, 'sort' => 290),
1804 array('id' => 'Fullscreen', 'compact' => false, 'sort' => 310),
1805 array('id' => 'More', 'compact' => true, 'sort' => 400)
1806 ),
1807 );
1808 $editor->show($res);
1809 $html = ob_get_contents();
1810 ob_end_clean();
1811 }
1812 return $html;
1813 }
1814}
static prepareFieldDataForEditForm(array $field)
Definition field.php:128
static renderDefaultField(array $field)
Definition field.php:940
static $separator
Definition field.php:23
static $renderForForm
Definition field.php:24
static renderField(array $field)
Definition field.php:32
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29