Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
SectionProvider.php
1
<?php
2
3
namespace
Bitrix\Catalog\v2\Integration\UI\EntitySelector
;
4
5
use
Bitrix\UI\EntitySelector\BaseProvider
;
6
use
Bitrix\UI\EntitySelector\Dialog
;
7
use
Bitrix\UI\EntitySelector\Item
;
8
use
Bitrix\UI\EntitySelector\SearchQuery
;
9
10
class
SectionProvider
extends
BaseProvider
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
],
139
BX_RESIZE_IMAGE_EXACT,
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
}
Bitrix\Catalog\v2\Integration\UI\EntitySelector\SectionProvider
Definition
SectionProvider.php:11
Bitrix\Catalog\v2\Integration\UI\EntitySelector\SectionProvider\SECTION_ENTITY_ID
const SECTION_ENTITY_ID
Definition
SectionProvider.php:13
Bitrix\Catalog\v2\Integration\UI\EntitySelector\SectionProvider\__construct
__construct(array $options=[])
Definition
SectionProvider.php:15
Bitrix\Catalog\v2\Integration\UI\EntitySelector\SectionProvider\fillDialog
fillDialog(Dialog $dialog)
Definition
SectionProvider.php:55
Bitrix\Catalog\v2\Integration\UI\EntitySelector\SectionProvider\getActiveSections
getActiveSections(array $additionalFilter=[])
Definition
SectionProvider.php:103
Bitrix\Catalog\v2\Integration\UI\EntitySelector\SectionProvider\getSections
getSections(array $additionalFilter=[])
Definition
SectionProvider.php:108
Bitrix\Catalog\v2\Integration\UI\EntitySelector\SectionProvider\getSelectedItems
getSelectedItems(array $ids)
Definition
SectionProvider.php:41
Bitrix\Catalog\v2\Integration\UI\EntitySelector\SectionProvider\getItems
getItems(array $ids)
Definition
SectionProvider.php:27
Bitrix\Catalog\v2\Integration\UI\EntitySelector\SectionProvider\doSearch
doSearch(SearchQuery $searchQuery, Dialog $dialog)
Definition
SectionProvider.php:80
Bitrix\Catalog\v2\Integration\UI\EntitySelector\SectionProvider\makeItem
makeItem(array $section)
Definition
SectionProvider.php:151
Bitrix\Catalog\v2\Integration\UI\EntitySelector\SectionProvider\isAvailable
isAvailable()
Definition
SectionProvider.php:22
Bitrix\UI\EntitySelector\BaseProvider
Definition
baseprovider.php:5
Bitrix\UI\EntitySelector\BaseProvider\$options
$options
Definition
baseprovider.php:6
Bitrix\UI\EntitySelector\BaseProvider\getOptions
getOptions()
Definition
baseprovider.php:43
Bitrix\UI\EntitySelector\Dialog
Definition
dialog.php:10
Bitrix\UI\EntitySelector\Dialog\loadPreselectedItems
loadPreselectedItems($preselectedMode=true)
Definition
dialog.php:389
Bitrix\UI\EntitySelector\Dialog\getRecentItems
getRecentItems()
Definition
dialog.php:225
Bitrix\UI\EntitySelector\Dialog\addItem
addItem(Item $item)
Definition
dialog.php:112
Bitrix\UI\EntitySelector\Dialog\addRecentItem
addRecentItem(Item $item)
Definition
dialog.php:129
Bitrix\UI\EntitySelector\Dialog\getItemCollection
getItemCollection()
Definition
dialog.php:102
Bitrix\UI\EntitySelector\Item
Definition
item.php:8
Bitrix\UI\EntitySelector\SearchQuery
Definition
searchquery.php:5
Bitrix\UI\EntitySelector\SearchQuery\getQuery
getQuery()
Definition
searchquery.php:40
Bitrix\UI\EntitySelector\SearchQuery\setCacheable
setCacheable(bool $flag=true)
Definition
searchquery.php:72
Bitrix\Catalog\v2\Integration\UI\EntitySelector
Bitrix\Main\$GLOBALS
$GLOBALS['____1444769544']
Definition
license.php:1
modules
catalog
lib
v2
Integration
UI
EntitySelector
SectionProvider.php
Создано системой
1.10.0