1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
SectionProvider.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\v2\Integration\UI\EntitySelector;
4
5use Bitrix\UI\EntitySelector\BaseProvider;
6use Bitrix\UI\EntitySelector\Dialog;
7use Bitrix\UI\EntitySelector\Item;
8use Bitrix\UI\EntitySelector\SearchQuery;
9
11{
12 private const SECTION_LIMIT = 20;
13 protected const SECTION_ENTITY_ID = 'section';
14
15 public function __construct(array $options = [])
16 {
17 parent::__construct();
18
19 $this->options = $options;
20 }
21
22 public function isAvailable(): bool
23 {
24 return $GLOBALS['USER']->isAuthorized();
25 }
26
27 public function getItems(array $ids): array
28 {
29 $items = [];
30
31 $filter = !empty($ids) ? ['ID' => $ids] : [];
32
33 foreach ($this->getActiveSections($filter) as $section)
34 {
35 $items[] = $this->makeItem($section);
36 }
37
38 return $items;
39 }
40
41 public function getSelectedItems(array $ids): array
42 {
43 $selectedItems = [];
44
45 $filter = !empty($ids) ? ['ID' => $ids] : [];
46
47 foreach ($this->getSections($filter) as $section)
48 {
49 $selectedItems[] = $this->makeItem($section);
50 }
51
52 return $selectedItems;
53 }
54
55 public function fillDialog(Dialog $dialog): void
56 {
57 $dialog->loadPreselectedItems();
58
59 if ($dialog->getItemCollection()->count() > 0)
60 {
61 foreach ($dialog->getItemCollection() as $item)
62 {
63 $dialog->addRecentItem($item);
64 }
65 }
66
67 $recentItemsCount = count($dialog->getRecentItems()->getEntityItems(static::SECTION_ENTITY_ID));
68
69 if ($recentItemsCount < self::SECTION_LIMIT)
70 {
71 foreach ($this->getActiveSections() as $section)
72 {
73 $dialog->addRecentItem(
74 $this->makeItem($section)
75 );
76 }
77 }
78 }
79
80 public function doSearch(SearchQuery $searchQuery, Dialog $dialog): void
81 {
82 $filter = [];
83
84 $query = $searchQuery->getQuery();
85 if ($query !== '')
86 {
87 $filter['%NAME'] = $query;
88 }
89
90 foreach ($this->getActiveSections($filter) as $section)
91 {
92 $dialog->addItem(
93 $this->makeItem($section)
94 );
95 }
96
97 if ($dialog->getItemCollection()->count() >= self::SECTION_LIMIT)
98 {
99 $searchQuery->setCacheable(false);
100 }
101 }
102
103 protected function getActiveSections(array $additionalFilter = []): array
104 {
105 return $this->getSections(array_merge(['=ACTIVE' => 'Y'], $additionalFilter));
106 }
107
108 protected function getSections(array $additionalFilter = []): array
109 {
110 $sections = [];
111
112 $filter = $this->getDefaultFilter();
113 if (!empty($additionalFilter))
114 {
115 $filter = array_merge($filter, $additionalFilter);
116 }
117
118 if (!empty($filter))
119 {
120 $sectionData = \CIBlockSection::GetList(
121 [],
122 $filter,
123 false,
124 ['ID', 'NAME', 'PICTURE'],
125 [
126 'nTopCount' => self::SECTION_LIMIT,
127 ]
128 );
129 while ($section = $sectionData->fetch())
130 {
131 if (!empty($section['PICTURE']))
132 {
133 $section['PICTURE'] = \CFile::resizeImageGet(
134 $section['PICTURE'],
135 [
136 'width' => 100,
137 'height' => 100,
138 ],
140 false
141 )['src'];
142 }
143
144 $sections[] = $section;
145 }
146 }
147
148 return $sections;
149 }
150
151 protected function makeItem(array $section): Item
152 {
153 return new Item([
154 'id' => $section['ID'],
155 'entityId' => static::SECTION_ENTITY_ID,
156 'title' => $section['NAME'],
157 'avatar' => $section['PICTURE'],
158 ]);
159 }
160
161 private function getDefaultFilter(): array
162 {
163 $filter = [];
164
165 $iblockId = (int)($this->getOptions()['iblockId'] ?? 0);
166 if (!empty($iblockId))
167 {
168 $filter['IBLOCK_ID'] = $iblockId;
169 }
170
171 return $filter;
172 }
173}
doSearch(SearchQuery $searchQuery, Dialog $dialog)
Определения SectionProvider.php:80
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
const BX_RESIZE_IMAGE_EXACT
Определения constants.php:12
$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