Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
element.php
1<?php
3
9
10Loc::loadMessages(__FILE__);
11
12class Element extends Entity
13{
14 protected $catalogIncluded = null;
15
17 protected $elementProperties = null;
18
20 protected $offerProperties = null;
21
22 public function __construct($component = null)
23 {
24 parent::__construct($component);
25 $this->useImplicitPageNavigation();
26 }
27
31 public function onIncludeComponentLang()
32 {
33 parent::onIncludeComponentLang();
34 Loc::loadMessages(__FILE__);
35 }
36
40 protected function checkModules()
41 {
42 if ($this->catalogIncluded === null)
43 $this->catalogIncluded = Loader::includeModule('catalog');
44 }
45
49 protected function initEntitySettings()
50 {
51 parent::initEntitySettings();
52 if (!$this->catalogIncluded)
53 return;
54 $iblockId = (int)$this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'IBLOCK_ID');
55 if ($iblockId > 0)
56 {
57 $description = [
58 'CATALOG_TYPE' => null,
59 'OFFERS_IBLOCK_ID' => null,
60 'SKU_PROPERTY_ID' => null,
61 ];
62 $catalog = \CCatalogSku::GetInfoByIBlock($iblockId);
63 if (!empty($catalog))
64 {
65 $description['CATALOG_TYPE'] = $catalog['CATALOG_TYPE'];
66 if (
67 $catalog['CATALOG_TYPE'] == \CCatalogSku::TYPE_FULL
68 || $catalog['CATALOG_TYPE'] == \CCatalogSku::TYPE_PRODUCT
69 )
70 {
71 $description['OFFERS_IBLOCK_ID'] = $catalog['IBLOCK_ID'];
72 $description['SKU_PROPERTY_ID'] = $catalog['SKU_PROPERTY_ID'];
73 }
74 $description['FILTER_ALL'] = Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_SLIDER_FILTER_ALL_PRODUCTS');
75
76 }
77 unset($catalog);
78 $this->fillStorageNode(self::STORAGE_ENTITY_IBLOCK, $description);
79 unset($description);
80 }
81 unset($iblockId);
82 }
83
87 protected function getGridFilterDefinition()
88 {
89 $result = parent::getGridFilterDefinition();
90
91 $sectionFilter = $this->getSectionFilterDefinition();
92 if (!empty($sectionFilter))
93 {
94 $newResult = [];
95 foreach ($result as $id => $row)
96 {
97 $newResult[$id] = $row;
98 if ($id == 'ID')
99 {
100 foreach (array_keys($sectionFilter) as $index)
101 $newResult[$index] = $sectionFilter[$index];
102 unset($index);
103 }
104 }
105 unset($id, $row);
106 $result = $newResult;
107 unset($newResult);
108 }
109 unset($sectionFilter);
110
111 $result = array_merge(
112 $result,
114 );
115
116 $result = array_merge(
117 $result,
119 );
120
121 $result = array_merge(
122 $result,
124 );
125 $result = array_merge(
126 $result,
128 );
129
130 return $result;
131 }
132
136 protected function getGridColumnsDescription()
137 {
138 $result = array_merge(
139 parent::getGridColumnsDescription(),
141 );
142
143 $result = array_merge(
144 $result,
146 );
147
148 $properties = $this->getElementPropertiesDescription();
149 if (!empty($properties))
150 $result = array_merge($result, $properties);
151 unset($properties);
152
153 return $result;
154 }
155
160 protected function compileUserFilter(array $filter)
161 {
162 $result = parent::compileUserFilter($filter);
163
164 if ($this->catalogIncluded)
165 {
166 $iblockId = (int)$this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'OFFERS_IBLOCK_ID');
167 $skuPropertyId = (int)$this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'SKU_PROPERTY_ID');
168
169 if ($iblockId > 0 && $skuPropertyId > 0)
170 {
171 if (isset($filter['offer']))
172 {
173 $subFilter = $filter['offer'];
174 $subFilter['IBLOCK_ID'] = $iblockId;
175 $result['=ID'] = \CIBlockElement::SubQuery('PROPERTY_'.$skuPropertyId, $subFilter);
176 unset($subFilter);
177 }
178 }
179 }
180
181 return $result;
182 }
183
187 protected function getClientExtensions()
188 {
189 return array_merge(
190 parent::getClientExtensions(),
191 ['date']
192 );
193 }
194
198 protected function getDataOrder()
199 {
200 $result = parent::getDataOrder();
201
202 if (!isset($result['ID']))
203 {
204 if (isset($result['TYPE']))
205 {
206 $result['BUNDLE'] = $result['TYPE'];
207 }
208 $result['ID'] = 'ASC';
209 }
210
211 return $result;
212 }
213
217 protected function getData()
218 {
219 Loader::includeModule('fileman');
220
221 $this->rows = [];
222
223 $listImageSize = Main\Config\Option::get('iblock', 'list_image_size');
224 $minImageSize = ['W' => 1, 'H' => 1];
225 $maxImageSize = ['W' => $listImageSize, 'H' => $listImageSize];
226 unset($listImageSize);
227
228 $binaryStates = $this->getBinaryDictionary();
229
230 $allowedSets = Catalog\Config\Feature::isProductSetsEnabled();
231
233
234 $viewedColumns = $this->getDataFields();
235 $selectedFields = [];
236 $selectedProperties = [];
237 foreach ($viewedColumns as $columnId)
238 {
239 if (strncmp($columnId, 'PROPERTY_', 9) == 0)
240 {
241 if (isset($this->elementProperties[$columnId]))
242 {
243 $selectedProperties[] = $this->elementProperties[$columnId]['ID'];
244 }
245 }
246 else
247 {
248 $selectedFields[] = $columnId;
249 if ($columnId == 'TYPE')
250 $selectedFields[] = 'BUNDLE';
251 }
252 }
253 unset($columnId);
254 if (!in_array('ID', $selectedFields))
255 $selectedFields[] = 'ID';
256
257 $viewedColumns = array_fill_keys($viewedColumns, true);
258
259 $iblockId = (int)$this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'IBLOCK_ID');
260 $needProperties = $iblockId > 0 && !empty($selectedProperties);
261
262 $productTypeList = [];
263 if ($this->catalogIncluded)
264 $productTypeList = Catalog\ProductTable::getProductTypes(true);
265
266 $listIds = [];
267
268 $iterator = \CIBlockElement::GetList(
269 $this->getDataOrder(),
270 $this->getDataFilter(),
271 false,
272 $this->getGridNavigationParams(),
273 $selectedFields
274 );
275 $iterator->bShowAll = false;
276 while ($row = $iterator->Fetch())
277 {
278 $row['ID'] = (int)$row['ID'];
279
280 if (isset($viewedColumns['ACTIVE']))
281 $row['ACTIVE'] = ($row['ACTIVE'] == 'Y' ? $binaryStates['Y'] : $binaryStates['N']);
282 if (isset($viewedColumns['NAME']))
283 $row['NAME'] = htmlspecialcharsEx((string)$row['NAME']);
284 if (isset($viewedColumns['SORT']))
285 $row['SORT'] = (int)$row['SORT'];
286 if (isset($viewedColumns['CODE']))
287 $row['CODE'] = htmlspecialcharsbx((string)$row['CODE']);
288 if (isset($viewedColumns['XML_ID']))
289 $row['XML_ID'] = htmlspecialcharsbx((string)$row['XML_ID']);
290 if (isset($viewedColumns['ACTIVE_FROM']))
291 $row['ACTIVE_FROM'] = htmlspecialcharsbx((string)$row['ACTIVE_FROM']);
292 if (isset($viewedColumns['ACTIVE_TO']))
293 $row['ACTIVE_TO'] = htmlspecialcharsbx((string)$row['ACTIVE_TO']);
294
295 if (isset($viewedColumns['TYPE']))
296 {
297 if ($row['TYPE'] === null)
298 {
299 $row['TYPE'] = Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_MESS_IS_NOT_PRODUCT');
300 }
301 else
302 {
303 $productType = (int)$row['TYPE'];
304 if (isset($productTypeList[$productType]))
305 {
306 $row['TYPE'] = $productTypeList[$productType];
307 }
308 else
309 {
310 $row['TYPE'] = Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_MESS_BAD_PRODUCT_TYPE');
311 }
312 if ($allowedSets && $row['BUNDLE'] == 'Y')
313 {
314 $row['TYPE'] = Loc::getMessage(
315 'IBLOCK_SELECTOR_ELEMENT_MESS_TYPE_DESCRIPTION',
316 ['#TYPE#' => $row['TYPE']]
317 );
318 }
319 }
320 unset($row['BUNDLE']);
321 }
322 if (isset($viewedColumns['AVAILABLE']))
323 $row['AVAILABLE'] = ($row['AVAILABLE'] == 'Y' ? $binaryStates['Y'] : $binaryStates['N']);
324
325 if ($needProperties)
326 $row['PROPERTIES'] = [];
327 $this->rows[$row['ID']] = $row;
328 $listIds[] = $row['ID'];
329 }
330 unset($row);
331
332 if (!empty($this->rows) && $needProperties)
333 {
334 \CIBlockElement::GetPropertyValuesArray(
335 $this->rows,
336 $iblockId,
337 ['ID' => $listIds],
338 ['ID' => $selectedProperties],
339 [
340 'USE_PROPERTY_ID' => 'Y',
341 'PROPERTY_FIELDS' => ['ID'],
342 'GET_RAW_DATA' => 'Y'
343 ]
344 );
345
346 $elementCache = [];
347 $sectionCache = [];
348
349 foreach ($listIds as $id)
350 {
351 foreach ($selectedProperties as $propertyId)
352 {
353 $viewedValue = '';
354 $index = 'PROPERTY_'.$propertyId;
355 if (isset($this->rows[$id]['PROPERTIES'][$propertyId]))
356 {
357 $property = $this->elementProperties[$index];
358 $value = $this->rows[$id]['PROPERTIES'][$propertyId];
359 $complexValue = is_array($value['VALUE']);
360 if (
361 ($complexValue && !empty($value['VALUE']))
362 || (!$complexValue && (string)$value['VALUE'] !== '')
363 )
364 {
365 $direct = false;
366 $assembly = [];
367 $userType = $property['PROPERTY_USER_TYPE'];
368 if (isset($userType['GetAdminListViewHTML']))
369 {
370 $rawValue = $value['VALUE'];
371 if ($property['MULTIPLE'] == 'N' || !$complexValue)
372 $rawValue = [$rawValue];
373 foreach ($rawValue as $item)
374 {
375 $itemValue = (string)call_user_func_array(
376 $userType['GetAdminListViewHTML'],
377 [
378 $property,
379 [
380 'VALUE' => $item,
381 'DESCRIPTION' => ''
382 ],
383 [
384 'MODE' => 'iblock_element_admin',
385 'FORM_NAME' => ''
386 ]
387 ]
388 );
389 if ($itemValue !== '')
390 $assembly[] = $itemValue;
391 }
392 }
393 else
394 {
395 $rawValue = $value['VALUE'];
396 if (!$complexValue)
397 $rawValue = [$rawValue];
398
399 switch ($this->elementProperties[$index]['PROPERTY_TYPE'])
400 {
401 case Iblock\PropertyTable::TYPE_STRING:
402 case Iblock\PropertyTable::TYPE_NUMBER:
403 case Iblock\PropertyTable::TYPE_LIST:
404 $assembly = $rawValue;
405 break;
406 case Iblock\PropertyTable::TYPE_ELEMENT:
407 foreach ($rawValue as $item)
408 {
409 if (!isset($elementCache[$item]))
410 {
411 $elementCache[$item] = '';
412 $valueIterator = Iblock\ElementTable::getList([
413 'select' => ['ID', 'NAME'],
414 'filter' => ['=ID' => $item]
415 ]);
416 $valueRow = $valueIterator->fetch();
417 if (!empty($valueRow))
418 $elementCache[$item] = '['.$valueRow['ID'].'] '.$valueRow['NAME'];
419 unset($valueRow, $valueIterator);
420 }
421 if ($elementCache[$item] !== '')
422 $assembly[] = $elementCache[$item];
423 }
424 break;
425 case Iblock\PropertyTable::TYPE_SECTION:
426 foreach ($rawValue as $item)
427 {
428 if (!isset($sectionCache[$item]))
429 {
430 $sectionCache[$item] = '';
431 $valueIterator = Iblock\SectionTable::getList([
432 'select' => ['ID', 'NAME'],
433 'filter' => ['=ID' => $item]
434 ]);
435 $valueRow = $valueIterator->fetch();
436 if (!empty($valueRow))
437 $sectionCache[$item] = '['.$valueRow['ID'].'] '.$valueRow['NAME'];
438 unset($valueRow, $valueIterator);
439 }
440 if ($sectionCache[$item] !== '')
441 $assembly[] = $sectionCache[$item];
442 }
443 break;
444 case Iblock\PropertyTable::TYPE_FILE:
445 $direct = true;
446 /* $fileInputParams = [
447 'edit' => false,
448 'description' => true,
449 'upload' => false,
450 'medialib' => false,
451 'fileDialog' => false,
452 'cloud' => false,
453 'delete' => false,
454 ];
455 if ($property['MULTIPLE'] == 'Y')
456 {
457 $fileInputParams['name'] = $index.'[#IND#]';
458 }
459 else
460 {
461 $fileInputParams['name'] = $index;
462 $fileInputParams['maxCount'] = 1;
463 $rawValue = reset($rawValue);
464 }
465 $assembly = UI\FileInput::createInstance($fileInputParams)->show(
466 $rawValue,
467 false
468 );
469 unset($fileInputParams); */
470 $fileInputParams = [
471 'upload' => false,
472 'medialib' => false,
473 'file_dialog' => false,
474 'cloud' => false,
475 'del' => false,
476 'description' => false
477 ];
478 $fileOptions = [
479 'IMAGE' => 'Y',
480 'PATH' => 'N',
481 'FILE_SIZE' => 'N',
482 'DIMENSIONS' => 'N',
483 'IMAGE_POPUP' => 'Y',
484 'MAX_SIZE' => $maxImageSize,
485 'MIN_SIZE' => $minImageSize,
486 ];
487 if ($property['MULTIPLE'] == 'Y')
488 {
489 $assembly = \CFileInput::ShowMultiple(
490 $rawValue,
491 $index.'[#IND#]',
492 $fileOptions,
493 false,
494 $fileInputParams
495 );
496 }
497 else
498 {
499 $rawValue = reset($rawValue);
500 $assembly = \CFileInput::Show(
501 $index,
502 $rawValue,
503 $fileOptions,
504 $fileInputParams
505 );
506 }
507 break;
508 }
509 }
510 if (!empty($assembly))
511 {
512 $viewedValue = ($direct ? $assembly : htmlspecialcharsbx(implode(' / ', $assembly)));
513 }
514 unset($direct, $assembly);
515 }
516 }
517 $this->rows[$id][$index] = $viewedValue;
518 unset($viewedValue);
519 }
520 unset($this->rows[$id]['PROPERTIES']);
521 }
522
523 unset($sectionCache, $elementCache);
524 }
525 if (!empty($this->rows))
526 $this->rows = array_values($this->rows);
527
528 $this->setImplicitNavigationData($iterator);
529 unset($iterator);
530 }
531
535 protected function getNavigationTitle()
536 {
537 $title = $this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'IBLOCK_ELEMENTS_NAME');
538 if (!empty($title))
539 return $title;
540 return Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_GRID_PAGENAVIGATION_TITLE');
541 }
542
546 protected function getInternalFilter()
547 {
548 $filter = parent::getInternalFilter();
549
550 $filter['CHECK_PERMISSIONS'] = 'Y';
551 $filter['MIN_PERMISSION'] = 'R';
552
553 return $filter;
554 }
555
559 protected function getSectionFilterDefinition()
560 {
561 $result = [];
562
563 if ($this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'IBLOCK_SECTIONS') == 'Y')
564 {
565 $list = [];
566 $iterator = \CIBlockSection::GetList(
567 [
568 'LEFT_MARGIN' => 'ASC',
569 ],
570 [
571 'IBLOCK_ID' => $this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'IBLOCK_ID'),
572 'ACTIVE' => 'Y',
573 'GLOBAL_ACTIVE' => 'Y',
574 'CHECK_PERMISSIONS' => 'Y',
575 'MIN_PERMISSION' => 'R',
576 ],
577 false,
578 [
579 'ID',
580 'NAME',
581 'IBLOCK_ID',
582 'DEPTH_LEVEL',
583 'LEFT_MARGIN',
584 ]
585 );
586 while ($row = $iterator->Fetch())
587 {
588 $margin = max((int)$row['DEPTH_LEVEL'], 1) - 1;
589 $list[$row['ID']] = str_repeat('.', $margin) . $row['NAME'];
590 }
591 unset($row, $iterator);
592 $result = [
593 'SECTION_ID' => [
594 'id' => 'SECTION_ID',
595 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_FILTER_FIELD_SECTION_ID'),
596 'type' => 'list',
597 'items' => $list,
598 'operators' => [
599 'default' => '='
600 ],
601 'default' => true
602 ],
603 'INCLUDE_SUBSECTIONS' => [
604 'id' => 'INCLUDE_SUBSECTIONS',
605 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_FILTER_FIELD_INCLUDE_SUBSECTIONS'),
606 'type' => 'checkbox',
607 'operators' => [
608 'default' => ''
609 ],
610 'default' => true
611 ]
612 ];
613 unset($list);
614 }
615
616 return $result;
617 }
618
623 {
624 $result = [];
625
626 $result['ACTIVE_FROM'] = [
627 'id' => 'ACTIVE_FROM',
628 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_GRID_COLUMN_ACTIVE_FROM'),
629 'type' => 'date',
630 'operators' => [
631 'default' => '=',
632 'range' => '><'
633 ]
634 ];
635 $result['ACTIVE_TO'] = [
636 'id' => 'ACTIVE_TO',
637 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_GRID_COLUMN_ACTIVE_TO'),
638 'type' => 'date',
639 'operators' => [
640 'default' => '=',
641 'range' => '><'
642 ]
643 ];
644
645 return $result;
646 }
647
652 {
653 $result = [];
654
655 $binaryStates = $this->getBinaryDictionary();
656
657 if (
658 $this->catalogIncluded
659 && (string)$this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'CATALOG_TYPE') !== ''
660 )
661 {
662 $result['TYPE'] = [
663 'id' => 'TYPE',
664 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_GRID_COLUMN_TYPE'),
665 'type' => 'list',
666 'items' => \CCatalogAdminTools::getIblockProductTypeList(
667 $this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'IBLOCK_ID'),
668 true
669 ),
670 'params' => ['multiple' => 'Y'],
671 'operators' => [
672 'default' => '=',
673 'exact' => '=',
674 'enum' => '@'
675 ]
676 ];
677 if (Catalog\Config\Feature::isProductSetsEnabled())
678 {
679 $result['BUNDLE'] = [
680 'id' => 'BUNDLE',
681 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_FILTER_FIELD_BUNDLE'),
682 'type' => 'list',
683 'items' => $binaryStates,
684 'operators' => [
685 'default' => '='
686 ]
687 ];
688 }
689 $result['AVAILABLE'] = [
690 'id' => 'AVAILABLE',
691 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_GRID_COLUMN_AVAILABLE'),
692 'type' => 'list',
693 'items' => $binaryStates,
694 'operators' => [
695 'default' => '='
696 ]
697 ];
698 }
699
700 return $result;
701 }
702
707 {
708 $result = [];
709
711 if (!empty($this->elementProperties))
712 $result = $this->compileFilterProperties($this->elementProperties);
713
714 return $result;
715 }
716
721 {
722 $result = [];
723
725 if (!empty($this->offerProperties))
726 {
727 $result = $this->compileFilterProperties($this->offerProperties);
728 if (!empty($result))
729 {
730 foreach (array_keys($result) as $index)
731 $result[$index]['entity'] = 'offer';
732 unset($index);
733 }
734 }
735
736 return $result;
737 }
738
743 protected function compileFilterProperties(array $list)
744 {
745 $result = [];
746 if (empty($list))
747 return $result;
748
749 $operators = [
750 Iblock\PropertyTable::TYPE_STRING => [
751 'default' => '?',
752 'quickSearch' => '?'
753 ],
754 Iblock\PropertyTable::TYPE_NUMBER => [
755 'default' => '=',
756 'exact' => '=',
757 'range' => '><',
758 'more' => '>',
759 'less' => '<'
760 ],
761 Iblock\PropertyTable::TYPE_LIST => [
762 'default' => '=',
763 'exact' => '='
764 ],
765 Iblock\PropertyTable::TYPE_ELEMENT => [
766 'default' => '=',
767 'exact' => '='
768 ],
769 Iblock\PropertyTable::TYPE_SECTION => [
770 'default' => '=',
771 'exact' => '='
772 ]
773 ];
774
775 $list = array_filter($list, [__CLASS__, 'isFilterableProperty']);
776 foreach ($list as $id => $row)
777 {
778 $field = null;
779 $type = $row['PROPERTY_TYPE'];
780 if (
781 $row['USER_TYPE'] !== ''
782 && isset($row['PROPERTY_USER_TYPE']['GetUIFilterProperty'])
783 && is_callable($row['PROPERTY_USER_TYPE']['GetUIFilterProperty'])
784 )
785 {
786 $type = 'USER_TYPE';
787 }
788 switch ($type)
789 {
790 case 'USER_TYPE':
791 $field = [
792 'id' => $id,
793 'name' => $row['NAME'],
794 'type' => 'custom',
795 'value' => ''
796 ];
797 if (isset($operators[$row['PROPERTY_TYPE']]))
798 $field['operators'] = $operators[$row['PROPERTY_TYPE']];
799 call_user_func_array(
800 $row['PROPERTY_USER_TYPE']['GetUIFilterProperty'],
801 [
802 $row,
803 ['VALUE' => $id, 'FORM_NAME' => 'main-ui-filter'],
804 &$field
805 ]
806 );
807 break;
808 case Iblock\PropertyTable::TYPE_STRING:
809 $field = [
810 'id' => $id,
811 'name' => $row['NAME'],
812 'type' => 'string',
813 'operators' => $operators[Iblock\PropertyTable::TYPE_STRING],
814 ];
815 break;
816 case Iblock\PropertyTable::TYPE_NUMBER:
817 $field = [
818 'id' => $id,
819 'name' => $row['NAME'],
820 'type' => 'number',
821 'operators' => $operators[Iblock\PropertyTable::TYPE_NUMBER]
822 ];
823 break;
824 case Iblock\PropertyTable::TYPE_LIST:
825 $list = [];
826 $valueIterator = Iblock\PropertyEnumerationTable::getList([
827 'select' => ['ID', 'VALUE', 'SORT'],
828 'filter' => ['=PROPERTY_ID' => $row['ID']],
829 'order' => ['SORT' => 'ASC', 'VALUE' => 'ASC']
830 ]);
831 while ($value = $valueIterator->fetch())
832 $list[$value['ID']] = $value['VALUE'];
833 unset($value, $valueIterator);
834 if (!empty($list))
835 {
836 $field = [
837 'id' => $id,
838 'name' => $row['NAME'],
839 'type' => 'list',
840 'items' => $list,
841 'params' => ['multiple' => 'Y'],
842 'operators' => $operators[Iblock\PropertyTable::TYPE_LIST]
843 ];
844 }
845 unset($list);
846 break;
847 case Iblock\PropertyTable::TYPE_ELEMENT:
848 $row['LINK_IBLOCK_ID'] = (int)$row['LINK_IBLOCK_ID'];
849 if ($row['LINK_IBLOCK_ID'] > 0)
850 {
851 $list = [];
852 $valueIterator = \CIBlockElement::GetList(
853 ['SORT' => 'ASC', 'NAME' => 'ASC'],
854 ['IBLOCK_ID' => $row['LINK_IBLOCK_ID'], 'CHECK_PERMISSIONS' => 'Y', 'MIN_PERMISSION' => 'R'],
855 false,
856 false,
857 ['ID', 'IBLOCK_ID', 'NAME', 'SORT']
858 );
859 while ($value = $valueIterator->Fetch())
860 $list[$value['ID']] = '['.$value['ID'].'] '.$value['NAME'];
861 unset($value, $valueIterator);
862 if (!empty($list))
863 {
864 $field = [
865 'id' => $id,
866 'name' => $row['NAME'],
867 'type' => 'list',
868 'items' => $list,
869 'params' => ['multiple' => 'Y'],
870 'operators' => $operators[Iblock\PropertyTable::TYPE_ELEMENT]
871 ];
872 }
873 unset($list);
874 }
875 break;
876 case Iblock\PropertyTable::TYPE_SECTION:
877 $row['LINK_IBLOCK_ID'] = (int)$row['LINK_IBLOCK_ID'];
878 if ($row['LINK_IBLOCK_ID'] > 0)
879 {
880 $list = [];
881 $valueIterator = \CIBlockSection::GetList(
882 [
883 'LEFT_MARGIN' => 'ASC',
884 ],
885 [
886 'IBLOCK_ID' => $row['LINK_IBLOCK_ID'],
887 'CHECK_PERMISSIONS' => 'Y',
888 'MIN_PERMISSION' => 'R',
889 ],
890 false,
891 [
892 'ID',
893 'IBLOCK_ID',
894 'DEPTH_LEVEL',
895 'NAME',
896 'LEFT_MARGIN',
897 ]
898 );
899 while ($value = $valueIterator->Fetch())
900 {
901 $margin = max((int)$value['DEPTH_LEVEL'], 1) - 1;
902 $list[$value['ID']] =
903 str_repeat('. ', $margin)
904 . '[' . $value['ID'] . '] '. $value['NAME']
905 ;
906 }
907 unset($value, $valueIterator);
908 if (!empty($list))
909 {
910 $field = [
911 'id' => $id,
912 'name' => $row['NAME'],
913 'type' => 'list',
914 'items' => $list,
915 'operators' => $operators[Iblock\PropertyTable::TYPE_SECTION]
916 ];
917 }
918 unset($list);
919 }
920 break;
921 }
922 if (!empty($field))
923 $result[$id] = $field;
924 }
925 unset($id, $row, $iterator);
926 unset($operators);
927
928 return $result;
929 }
930
934 protected function getElementFieldsDescription()
935 {
936 $result = [];
937
938 $result['ACTIVE_FROM'] = [
939 'id' => 'ACTIVE_FROM',
940 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_GRID_COLUMN_ACTIVE_FROM'),
941 'sort' => 'ACTIVE_FROM',
942 'default' => false
943 ];
944 $result['ACTIVE_TO'] = [
945 'id' => 'ACTIVE_TO',
946 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_GRID_COLUMN_ACTIVE_TO'),
947 'sort' => 'ACTIVE_TO',
948 'default' => false
949 ];
950
951 if (
952 $this->catalogIncluded
953 && (string)$this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'CATALOG_TYPE') !== ''
954 )
955 {
956 $result['TYPE'] = [
957 'id' => 'TYPE',
958 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_GRID_COLUMN_TYPE'),
959 'sort' => 'TYPE',
960 'default' => false
961 ];
962 $result['AVAILABLE'] = [
963 'id' => 'AVAILABLE',
964 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_GRID_COLUMN_AVAILABLE'),
965 'sort' => 'AVAILABLE',
966 'default' => false
967 ];
968 }
969
970 return $result;
971 }
972
976 protected function getProductFieldsDescription()
977 {
978 $result = [];
979
980 if (
981 $this->catalogIncluded
982 && (string)$this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'CATALOG_TYPE') !== ''
983 )
984 {
985 $result['TYPE'] = [
986 'id' => 'TYPE',
987 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_GRID_COLUMN_TYPE'),
988 'sort' => 'TYPE',
989 'default' => false
990 ];
991 $result['AVAILABLE'] = [
992 'id' => 'AVAILABLE',
993 'name' => Loc::getMessage('IBLOCK_SELECTOR_ELEMENT_GRID_COLUMN_AVAILABLE'),
994 'sort' => 'AVAILABLE',
995 'default' => false
996 ];
997 }
998
999 return $result;
1000 }
1001
1006 {
1007 $result = null;
1008
1009 $iblockId = (int)$this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'IBLOCK_ID');
1010 if ($iblockId > 0)
1011 {
1013 if (!empty($this->elementProperties))
1014 {
1015 $result = [];
1016 foreach ($this->elementProperties as $id => $row)
1017 {
1018 $result[$id] = [
1019 'id' => $id,
1020 'name' => $row['NAME'],
1021 'sort' => ($row['MULTIPLE'] == 'N'),
1022 'default' => false
1023 ];
1024 }
1025 }
1026 }
1027
1028 return $result;
1029 }
1030
1035 {
1036 if ($this->elementProperties !== null)
1037 return;
1038
1039 $iblockId = (int)$this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'IBLOCK_ID');
1040 if ($iblockId > 0)
1041 {
1042 $this->elementProperties = $this->loadPropertiesDescription([
1043 '=IBLOCK_ID' => $iblockId, '=ACTIVE' => 'Y'
1044 ]);
1045 }
1046 unset($iblockId);
1047 }
1048
1053 {
1054 if ($this->offerProperties !== null)
1055 return;
1056
1057 if (!$this->catalogIncluded)
1058 return;
1059
1060 $iblockId = (int)$this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'OFFERS_IBLOCK_ID');
1061 $skuPropertyId = (int)$this->getStorageItem(self::STORAGE_ENTITY_IBLOCK, 'SKU_PROPERTY_ID');
1062
1063 if ($iblockId > 0 && $skuPropertyId > 0)
1064 {
1065 $this->offerProperties = $this->loadPropertiesDescription([
1066 '=IBLOCK_ID' => $iblockId, '!=ID' => $skuPropertyId, '=ACTIVE' => 'Y'
1067 ]);
1068 }
1069 unset($skuPropertyId, $iblockId);
1070 }
1071
1076 protected function loadPropertiesDescription(array $filter)
1077 {
1078 $result = [];
1079 if (empty($filter))
1080 return $result;
1081
1082 $iterator = Iblock\PropertyTable::getList([
1083 'select' => [
1084 'ID', 'IBLOCK_ID', 'NAME', 'SORT', 'PROPERTY_TYPE',
1085 'MULTIPLE', 'LINK_IBLOCK_ID', 'FILTRABLE', 'VERSION',
1086 'USER_TYPE', 'USER_TYPE_SETTINGS_LIST'
1087 ],
1088 'filter' => $filter,
1089 'order' => ['SORT' => 'ASC', 'NAME' => 'ASC']
1090 ]);
1091 while ($row = $iterator->fetch())
1092 {
1093 $row['USER_TYPE'] = (string)$row['USER_TYPE'];
1094 $row['PROPERTY_USER_TYPE'] = ($row['USER_TYPE'] !== '' ? \CIBlockProperty::GetUserType($row['USER_TYPE']) : []);
1095 $row['USER_TYPE_SETTINGS'] = $row['USER_TYPE_SETTINGS_LIST'];
1096 unset($row['USER_TYPE_SETTINGS_LIST']);
1097 $result['PROPERTY_'.$row['ID']] = $row;
1098 }
1099 unset($row, $iterator);
1100
1101 return $result;
1102 }
1103
1108 protected static function isFilterableProperty(array $row)
1109 {
1110 return ($row['FILTRABLE'] == 'Y' && $row['PROPERTY_TYPE'] != Iblock\PropertyTable::TYPE_FILE);
1111 }
1112}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29