1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
IblockPropertySectionProvider.php
См. документацию.
1<?php
2
3namespace Bitrix\Iblock\Integration\UI\EntitySelector;
4
5use Bitrix\Iblock\Component\Tools;
6use Bitrix\UI\EntitySelector\BaseProvider;
7use Bitrix\UI\EntitySelector\Dialog;
8use Bitrix\UI\EntitySelector\Item;
9use Bitrix\UI\EntitySelector\SearchQuery;
10
12{
13 public const ENTITY_ID = 'iblock-property-section';
14 private const ELEMENTS_LIMIT = 100;
15
16 public function __construct(array $options = [])
17 {
18 parent::__construct();
19
20 $this->options = $options;
21 }
22
23 public function isAvailable(): bool
24 {
25 return $GLOBALS['USER']->isAuthorized();
26 }
27
28 public function getItems(array $ids): array
29 {
30 $items = [];
31
32 $filter = !empty($ids) ? ['ID' => $ids] : [];
33
34 foreach ($this->getElements($filter) as $element)
35 {
36 $items[] = $this->makeItem($element);
37 }
38
39 return $items;
40 }
41
42 public function fillDialog(Dialog $dialog): void
43 {
44 $dialog->loadPreselectedItems();
45
46 if ($dialog->getItemCollection()->count() > 0)
47 {
48 foreach ($dialog->getItemCollection() as $item)
49 {
50 $dialog->addRecentItem($item);
51 }
52 }
53
54 $recentItems = $dialog->getRecentItems()->getEntityItems(self::ENTITY_ID);
55 $recentItemsCount = count($recentItems);
56
57 if ($recentItemsCount < self::ELEMENTS_LIMIT)
58 {
59 $elements = $this->getElements([], self::ELEMENTS_LIMIT);
60 foreach ($elements as $element)
61 {
62 $dialog->addRecentItem($this->makeItem($element));
63 }
64 }
65 }
66
67 public function doSearch(SearchQuery $searchQuery, Dialog $dialog): void
68 {
69 $filter = [];
70
71 $query = $searchQuery->getQuery();
72 if ($query !== '')
73 {
74 $filter = $this->getQueryFilter($query);
75 }
76
77 $elements = $this->getElements($filter, self::ELEMENTS_LIMIT);
78 if (count($elements) === self::ELEMENTS_LIMIT)
79 {
80 $searchQuery->setCacheable(false);
81 }
82 foreach ($elements as $element)
83 {
84 $dialog->addItem(
85 $this->makeItem($element)
86 );
87 }
88 }
89
90 public function getPreselectedItems(array $ids): array
91 {
92 return $this->getItems($ids);
93 }
94
95 private function getQueryFilter(string $query): array
96 {
97 return [
98 '%NAME' => $query,
99 ];
100 }
101
102 private function getElements(array $additionalFilter = [], ?int $limit = null): array
103 {
104 $elements = [];
105
106 $filter = $this->getDefaultFilter();
107 if (!empty($additionalFilter))
108 {
109 $filter = array_merge($filter, $additionalFilter);
110 }
111
112 $navParams = false;
113 if ($limit)
114 {
115 $navParams = ['nTopCount' => $limit];
116 }
117
118 $selectFields = [
119 'ID',
120 'NAME',
121 'DESCRIPTION',
122 'PICTURE',
123 'IBLOCK_ID',
124 'XML_ID',
125 ];
126
127 if (!empty($filter))
128 {
129 $elementData = \CIBlockSection::GetList(
130 [],
131 $filter,
132 false,
135 );
136 while ($element = $elementData->fetch())
137 {
138 $element['PICTURE'] = $this->getImageSource((int)$element['PICTURE']);
139 $elements[] = $element;
140 }
141 }
142
143 return $elements;
144 }
145
146 private function makeItem(array $element): Item
147 {
148 $itemParams = [
149 'id' => $element['ID'] ?? null,
150 'entityId' => self::ENTITY_ID,
151 'title' => $element['NAME'] ?? null,
152 'subtitle' => $element['ID'] ?? null,
153 'description' => $element['DESCRIPTION'] ?? null,
154 'avatar' => $element['PICTURE'] ?? null,
155 'customData' => [
156 'xmlId' => $element['XML_ID'] ?? null,
157 ],
158 ];
159
160 return new Item($itemParams);
161 }
162
163 private function getDefaultFilter(): array
164 {
165 $filter = [
166 'CHECK_PERMISSIONS' => 'Y',
167 'MIN_PERMISSION' => 'R',
168 ];
169
170 $iblockId = (int)($this->getOption('iblockId', 0));
171 if (!empty($iblockId))
172 {
173 $filter['IBLOCK_ID'] = $iblockId;
174 }
175
176 $activeFilter = $this->getOption('activeFilter', false);
177 if ($activeFilter)
178 {
179 $filter['ACTIVE'] = 'Y';
180 }
181
182 return $filter;
183 }
184
185 private function getImageSource(int $id): ?string
186 {
187 if ($id <= 0)
188 {
189 return null;
190 }
191
192 $file = \CFile::GetFileArray($id);
193 if (!$file)
194 {
195 return null;
196 }
197
198 return Tools::getImageSrc($file, false) ?: null;
199 }
200}
getOption(string $option, $defaultValue=null)
Определения baseprovider.php:48
loadPreselectedItems($preselectedMode=true)
Определения dialog.php:410
addItem(Item $item)
Определения dialog.php:126
addRecentItem(Item $item)
Определения dialog.php:143
getItemCollection()
Определения dialog.php:116
setCacheable(bool $flag=true)
Определения searchquery.php:72
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
$iblockId
Определения iblock_catalog_edit.php:30
$filter
Определения iblock_catalog_list.php:54
$selectFields
Определения iblock_catalog_list.php:160
$navParams
Определения csv_new_run.php:35
$GLOBALS['____1690880296']
Определения license.php:1
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$items
Определения template.php:224