1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sitegroupsprovider.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Integration\UI\EntitySelector;
4
5use Bitrix\Main\GroupTable;
6use Bitrix\Main\Localization\Loc;
7use Bitrix\Main\Type\ArrayHelper;
8use Bitrix\UI\EntitySelector\BaseProvider;
9use Bitrix\UI\EntitySelector\Dialog;
10use Bitrix\UI\EntitySelector\Item;
11use Bitrix\UI\EntitySelector\RecentItem;
12use Bitrix\UI\EntitySelector\SearchQuery;
13use Bitrix\UI\EntitySelector\Tab;
14
16{
17 public const ENTITY_ID = 'site-groups';
18
19 private const RECENT_TAB_FILL_LIMIT = 20;
20 private const SEARCH_ITEMS_LIMIT = self::RECENT_TAB_FILL_LIMIT;
21
22 public function __construct(array $options = [])
23 {
24 parent::__construct();
25 }
26
27 public function isAvailable(): bool
28 {
29 global $USER;
30 if (!($USER instanceof \CUser))
31 {
32 return false;
33 }
34
35 return $USER->IsAuthorized() && $USER->CanDoOperation('view_groups');
36 }
37
38 public function fillDialog(Dialog $dialog): void
39 {
40 $recent = $dialog->getRecentItems();
41
42 $moreToFillCount = self::RECENT_TAB_FILL_LIMIT - $recent->count();
43 if ($moreToFillCount > 0)
44 {
45 $addedCount = $this->fillRecentFromGlobalContext($dialog, $moreToFillCount);
46 $moreToFillCount -= $addedCount;
47 }
48
49 if ($moreToFillCount > 0)
50 {
51 $this->fillRecentFromDB($dialog, $moreToFillCount);
52 }
53
54 $dialog->addTab(new Tab([
55 'id' => self::ENTITY_ID,
56 'title' => Loc::getMessage('SOCNET_ENTITY_SELECTOR_SITE_GROUPS_TAB_TITLE'),
57 ]));
58 }
59
60 private function fillRecentFromGlobalContext(Dialog $dialog, int $maxItemsToAdd): int
61 {
62 $recent = $dialog->getRecentItems();
63
64 $addedCount = 0;
65
67 foreach ($dialog->getGlobalRecentItems()->getEntityItems(self::ENTITY_ID) as $globalRecentItem)
68 {
69 if ($addedCount >= $maxItemsToAdd)
70 {
71 break;
72 }
73
74 $recent->add($globalRecentItem);
75 $addedCount++;
76 }
77
78 return $addedCount;
79 }
80
81 private function fillRecentFromDB(Dialog $dialog, int $limit): void
82 {
83 $query = GroupTable::query()
84 ->setSelect(['ID'])
85 ->where('ANONYMOUS', 'N')
86 ->whereNotNull('NAME')
87 ->setLimit($limit)
88 ;
89
90 $alreadyAddedIds = array_map(fn(RecentItem $item) => $item->getId(), $dialog->getRecentItems()->getAll());
91 ArrayHelper::normalizeArrayValuesByInt($alreadyAddedIds);
92 if (!empty($alreadyAddedIds))
93 {
94 $query->whereNotIn('ID', $alreadyAddedIds);
95 }
96
97 $ids = $query->fetchCollection()->getIdList();
98 foreach ($ids as $id)
99 {
100 $dialog->getRecentItems()->add(new RecentItem([
101 'id' => $id,
102 'entityId' => self::ENTITY_ID,
103 ]));
104 }
105 }
106
107 public function getItems(array $ids): array
108 {
109 if (empty($ids))
110 {
111 return [];
112 }
113
114 $result = [];
115
116 $groupItems = GroupTable::query()
117 ->setSelect(['ID', 'NAME'])
118 ->where('ANONYMOUS', 'N')
119 ->whereNotNull('NAME')
120 ->whereIn('ID', $ids)
121 ->fetchAll()
122 ;
123
124 foreach ($groupItems as $groupItem)
125 {
126 $item = new Item([
127 'id' => $groupItem['ID'],
128 'entityId' => static::ENTITY_ID,
129 'title' => $groupItem['NAME'],
130 ]);
131
132 $item->addTab(['site-groups']);
133
134 $result[] = $item;
135 }
136
137 return $result;
138 }
139
140 public function doSearch(SearchQuery $searchQuery, Dialog $dialog): void
141 {
142 $items = GroupTable::query()
143 ->setSelect(['ID', 'NAME'])
144 ->where('ANONYMOUS', 'N')
145 ->whereNotNull('NAME')
146 ->whereLike('NAME', "%{$searchQuery->getQuery()}%")
147 ->setLimit(self::SEARCH_ITEMS_LIMIT)
148 ->fetchAll()
149 ;
150
151 foreach ($items as $item)
152 {
153 $dialog->addItem(new Item([
154 'id' => $item['ID'],
155 'entityId' => self::ENTITY_ID,
156 'title' => $item['NAME'],
157 ]));
158 }
159
160 $isTherePossiblyMoreResultsForThisQuery = count($items) >= self::SEARCH_ITEMS_LIMIT;
161 $searchQuery->setCacheable(!$isTherePossiblyMoreResultsForThisQuery);
162 }
163}
Определения dialog.php:11
doSearch(SearchQuery $searchQuery, Dialog $dialog)
Определения sitegroupsprovider.php:140
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
$result
Определения get_property_values.php:14
$query
Определения get_search.php:11
global $USER
Определения csv_new_run.php:40
</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