1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ContractorProvider.php
См. документацию.
1<?php
2
3namespace Bitrix\Catalog\v2\Integration\UI\EntitySelector;
4
5use Bitrix\Catalog\ContractorTable;
6use Bitrix\UI\EntitySelector\BaseProvider;
7use Bitrix\UI\EntitySelector\Dialog;
8use Bitrix\UI\EntitySelector\Item;
9use Bitrix\UI\EntitySelector\SearchQuery;
10
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}
doSearch(SearchQuery $searchQuery, Dialog $dialog)
Определения ContractorProvider.php:36
static getList(array $parameters=array())
Определения datamanager.php:431
loadPreselectedItems($preselectedMode=true)
Определения dialog.php:410
addItems(array $items)
Определения dialog.php:135
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
$filter
Определения iblock_catalog_list.php:54
$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
$title
Определения pdf.php:123