Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
ContractorProvider.php
1
<?php
2
3
namespace
Bitrix\Catalog\v2\Integration\UI\EntitySelector
;
4
5
use
Bitrix\Catalog\ContractorTable
;
6
use
Bitrix\UI\EntitySelector\BaseProvider
;
7
use
Bitrix\UI\EntitySelector\Dialog
;
8
use
Bitrix\UI\EntitySelector\Item
;
9
use
Bitrix\UI\EntitySelector\SearchQuery
;
10
11
class
ContractorProvider
extends
BaseProvider
12
{
13
private
const
MAX_ITEMS_IN_RECENT = 10;
14
private
const
ENTITY_ID =
'contractor'
;
15
16
public
function
__construct
(array
$options
= [])
17
{
18
parent::__construct();
19
}
20
21
public
function
isAvailable
(): bool
22
{
23
return
$GLOBALS
[
"USER"
]->IsAuthorized();
24
}
25
26
public
function
getItems
(array $ids): array
27
{
28
return
$this->getContractorItemsByFilter([
'ID'
=> $ids]);
29
}
30
31
public
function
getSelectedItems
(array $ids): array
32
{
33
return
$this->getContractorItemsByFilter([
'ID'
=> $ids]);
34
}
35
36
public
function
doSearch
(
SearchQuery
$searchQuery,
Dialog
$dialog): void
37
{
38
$searchQuery->
setCacheable
(
false
);
39
$query = $searchQuery->
getQuery
();
40
41
$filter = [
42
'LOGIC'
=>
'OR'
,
43
[
'%PERSON_NAME'
=> $query],
44
[
'%COMPANY'
=> $query],
45
];
46
$items = $this->getContractorItemsByFilter($filter);
47
48
$dialog->
addItems
($items);
49
}
50
51
public
function
fillDialog
(
Dialog
$dialog): void
52
{
53
$dialog->
loadPreselectedItems
();
54
55
if
($dialog->
getItemCollection
()->count() > 0)
56
{
57
foreach
($dialog->
getItemCollection
() as $item)
58
{
59
$dialog->
addRecentItem
($item);
60
}
61
}
62
63
$recentItemsCount = count($dialog->
getRecentItems
()->getEntityItems(self::ENTITY_ID));
64
65
if
($recentItemsCount < self::MAX_ITEMS_IN_RECENT)
66
{
67
$amountToSelect = self::MAX_ITEMS_IN_RECENT - $recentItemsCount;
68
$excludedIds = array_keys($dialog->
getRecentItems
()->getEntityItems(self::ENTITY_ID));
69
$contractors =
ContractorTable::getList
([
70
'select'
=> [
'ID'
,
'PERSON_TYPE'
,
'PERSON_NAME'
,
'COMPANY'
],
71
'order'
=> [
'ID'
=>
'ASC'
],
72
'filter'
=> [
'!ID'
=> $excludedIds],
73
'limit'
=> $amountToSelect,
74
])->fetchAll();
75
foreach
($contractors as $contractor)
76
{
77
$dialog->
addRecentItem
($this->makeItem($contractor));
78
}
79
}
80
}
81
82
private
function
getContractorItemsByFilter($filter)
83
{
84
$contractors =
ContractorTable::getList
([
85
'select'
=> [
'ID'
,
'PERSON_TYPE'
,
'PERSON_NAME'
,
'COMPANY'
],
86
'filter'
=> $filter,
87
])->fetchAll();
88
89
$items = [];
90
foreach
($contractors as $contractor)
91
{
92
$items[] = $this->makeItem($contractor);
93
}
94
95
return
$items;
96
}
97
98
private
function
makeItem($contractor)
99
{
100
if
((
int
)$contractor[
'PERSON_TYPE'
] === (
int
)\
Bitrix
\Catalog\
ContractorTable::TYPE_INDIVIDUAL
)
101
{
102
$title = $contractor[
'PERSON_NAME'
];
103
}
104
else
105
{
106
$title = $contractor[
'COMPANY'
];
107
}
108
109
return
new
Item([
110
'id'
=> $contractor[
'ID'
],
111
'entityId'
=> self::ENTITY_ID,
112
'title'
=> $title,
113
]);
114
}
115
}
Bitrix\Catalog\ContractorTable
Definition
contractortable.php:55
Bitrix\Catalog\ContractorTable\TYPE_INDIVIDUAL
const TYPE_INDIVIDUAL
Definition
contractortable.php:56
Bitrix\Catalog\v2\Integration\UI\EntitySelector\ContractorProvider
Definition
ContractorProvider.php:12
Bitrix\Catalog\v2\Integration\UI\EntitySelector\ContractorProvider\__construct
__construct(array $options=[])
Definition
ContractorProvider.php:16
Bitrix\Catalog\v2\Integration\UI\EntitySelector\ContractorProvider\fillDialog
fillDialog(Dialog $dialog)
Definition
ContractorProvider.php:51
Bitrix\Catalog\v2\Integration\UI\EntitySelector\ContractorProvider\getSelectedItems
getSelectedItems(array $ids)
Definition
ContractorProvider.php:31
Bitrix\Catalog\v2\Integration\UI\EntitySelector\ContractorProvider\getItems
getItems(array $ids)
Definition
ContractorProvider.php:26
Bitrix\Catalog\v2\Integration\UI\EntitySelector\ContractorProvider\doSearch
doSearch(SearchQuery $searchQuery, Dialog $dialog)
Definition
ContractorProvider.php:36
Bitrix\Catalog\v2\Integration\UI\EntitySelector\ContractorProvider\isAvailable
isAvailable()
Definition
ContractorProvider.php:21
Bitrix\Main\ORM\Data\DataManager\getList
static getList(array $parameters=array())
Definition
datamanager.php:441
Bitrix\UI\EntitySelector\BaseProvider
Definition
baseprovider.php:5
Bitrix\UI\EntitySelector\BaseProvider\$options
$options
Definition
baseprovider.php:6
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\addItems
addItems(array $items)
Definition
dialog.php:121
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
Bitrix
modules
catalog
lib
v2
Integration
UI
EntitySelector
ContractorProvider.php
Создано системой
1.10.0