Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
projecttagprovider.php
1
<?php
2
namespace
Bitrix\SocialNetwork\Integration\UI\EntitySelector
;
3
4
use Bitrix\Main\Entity\Query;
5
use Bitrix\Main\Entity\Query\Join;
6
use Bitrix\Main\Entity\ReferenceField;
7
use
Bitrix\Main\Localization\Loc
;
8
use Bitrix\SocialNetwork\EO_WorkgroupTag ;
9
use Bitrix\SocialNetwork\EO_WorkgroupTag_Collection ;
10
use
Bitrix\Socialnetwork\UserToGroupTable
;
11
use
Bitrix\Socialnetwork\WorkgroupTable
;
12
use
Bitrix\Socialnetwork\WorkgroupTagTable
;
13
use
Bitrix\UI\EntitySelector\BaseProvider
;
14
use
Bitrix\UI\EntitySelector\Dialog
;
15
use
Bitrix\UI\EntitySelector\Item
;
16
use
Bitrix\UI\EntitySelector\RecentItem
;
17
use
Bitrix\UI\EntitySelector\SearchQuery
;
18
use
Bitrix\UI\EntitySelector\Tab
;
19
25
class
ProjectTagProvider
extends
BaseProvider
26
{
27
private
static
$entityId =
'project-tag'
;
28
private
static
$maxCount = 100;
29
30
public
function
__construct
(array
$options
= [])
31
{
32
parent::__construct();
33
34
$this->options[
'groupId'
] =
$options
[
'groupId'
];
35
}
36
37
public
function
isAvailable
(): bool
38
{
39
return
$GLOBALS[
'USER'
]->isAuthorized();
40
}
41
42
public
function
getItems
(array $ids): array
43
{
44
return
[];
45
}
46
47
public
function
getSelectedItems
(array $ids): array
48
{
49
return
[];
50
}
51
52
public
function
getTagItems
(array
$options
= []): array
53
{
54
return
$this->
makeTagItems
($this->
getTagCollection
(
$options
),
$options
);
55
}
56
57
public
function
getTagCollection
(array
$options
= []): EO_WorkgroupTag_Collection
58
{
59
$options
= array_merge($this->
getOptions
(),
$options
);
60
61
return
self::getTags
(
$options
);
62
}
63
64
public
static
function
getTags
(array
$options
= []): EO_WorkgroupTag_Collection
65
{
66
$query = WorkgroupTagTable::query();
67
$query->setSelect([
'NAME'
,
'GROUP_ID'
]);
68
69
if
((
$options
[
'selected'
] ??
null
) &&
$options
[
'groupId'
])
70
{
71
$query->where(
'GROUP_ID'
,
$options
[
'groupId'
]);
72
}
73
74
if
(!empty(
$options
[
'searchQuery'
] ??
null
) && is_string(
$options
[
'searchQuery'
]))
75
{
76
$query
77
->setDistinct(
true
)
78
->registerRuntimeField(
79
'G'
,
80
new
ReferenceField(
81
'G'
,
82
WorkgroupTable::getEntity(),
83
Join::on(
'this.GROUP_ID'
,
'ref.ID'
),
84
[
'join_type'
=>
'left'
]
85
)
86
)
87
->registerRuntimeField(
88
'UG'
,
89
new
ReferenceField(
90
'UG'
,
91
UserToGroupTable::getEntity(),
92
Join::on(
'this.GROUP_ID'
,
'ref.GROUP_ID'
),
93
[
'join_type'
=>
'left'
]
94
)
95
)
96
->where(
97
Query::filter()
98
->logic(
'or'
)
99
->where(
'G.VISIBLE'
,
'Y'
)
100
->where(
101
Query::filter()
102
->whereNotNull(
'UG.ID'
)
103
->whereIn(
'UG.ROLE'
, UserToGroupTable::getRolesMember())
104
)
105
)
106
->whereLike(
'NAME'
,
"{$options['searchQuery']}%"
)
107
;
108
}
109
110
return
$query->exec()->fetchCollection();
111
}
112
113
public
function
makeTagItems
(EO_WorkgroupTag_Collection $tags, array
$options
= []): array
114
{
115
return
self::makeItems
($tags, array_merge($this->
getOptions
(),
$options
));
116
}
117
123
public
static
function
makeItems
(EO_WorkgroupTag_Collection $tags, array
$options
= []): array
124
{
125
$result = [];
126
foreach
($tags as $tag)
127
{
128
$result[] =
self::makeItem
($tag,
$options
);
129
}
130
131
return
$result;
132
}
133
140
public
static
function
makeItem
(EO_WorkgroupTag $tag, array
$options
= []):
Item
141
{
142
return
new
Item
([
143
'id'
=> $tag->getName(),
144
'entityId'
=> self::$entityId,
145
'title'
=> $tag->getName(),
146
'selected'
=> (isset(
$options
[
'selected'
]) &&
$options
[
'selected'
]),
147
'tabs'
=> [
'all'
],
148
]);
149
}
150
151
public
function
doSearch
(
SearchQuery
$searchQuery,
Dialog
$dialog): void
152
{
153
$dialog->
addItems
(
154
$this->
getTagItems
([
'searchQuery'
=> $searchQuery->
getQuery
()])
155
);
156
}
157
158
public
function
fillDialog
(
Dialog
$dialog): void
159
{
160
$dialog->
addTab
(
161
new
Tab
([
162
'id'
=>
'all'
,
163
'title'
=>
Loc::getMessage
(
'SOCNET_ENTITY_SELECTOR_PROJECT_TAG_TAB_TITLE'
),
164
'stub'
=>
true
,
165
])
166
);
167
168
$options
= $this->
getOptions
();
169
if
(
$options
[
'groupId'
])
170
{
171
$dialog->
addItems
(
172
$this->
getTagItems
([
'selected'
=>
true
])
173
);
174
}
175
176
if
($dialog->
getItemCollection
()->count() < self::$maxCount)
177
{
178
$this->fillWithRecentTags($dialog);
179
}
180
}
181
182
private
function
fillWithRecentTags(
Dialog
$dialog): void
183
{
184
$recentItems = $dialog->
getRecentItems
()->getAll();
185
foreach
($recentItems as $item)
186
{
188
if
($dialog->
getItemCollection
()->get(self::$entityId, $item->getId()))
189
{
190
continue
;
191
}
192
193
$name = (string)$item->getId();
194
$dialog->
addItem
(
195
new
Item([
196
'id'
=> $name,
197
'entityId'
=> self::$entityId,
198
'title'
=> $name,
199
'selected'
=>
false
,
200
'tabs'
=> [
'all'
],
201
])
202
);
203
204
if
($dialog->
getItemCollection
()->count() >= self::$maxCount)
205
{
206
break
;
207
}
208
}
209
}
210
}
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider
Definition
projecttagprovider.php:26
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider\__construct
__construct(array $options=[])
Definition
projecttagprovider.php:30
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider\makeItem
static makeItem(EO_WorkgroupTag $tag, array $options=[])
Definition
projecttagprovider.php:140
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider\getTagItems
getTagItems(array $options=[])
Definition
projecttagprovider.php:52
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider\makeTagItems
makeTagItems(EO_WorkgroupTag_Collection $tags, array $options=[])
Definition
projecttagprovider.php:113
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider\fillDialog
fillDialog(Dialog $dialog)
Definition
projecttagprovider.php:158
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider\getTags
static getTags(array $options=[])
Definition
projecttagprovider.php:64
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider\getTagCollection
getTagCollection(array $options=[])
Definition
projecttagprovider.php:57
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider\makeItems
static makeItems(EO_WorkgroupTag_Collection $tags, array $options=[])
Definition
projecttagprovider.php:123
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider\getSelectedItems
getSelectedItems(array $ids)
Definition
projecttagprovider.php:47
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider\getItems
getItems(array $ids)
Definition
projecttagprovider.php:42
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider\doSearch
doSearch(SearchQuery $searchQuery, Dialog $dialog)
Definition
projecttagprovider.php:151
Bitrix\SocialNetwork\Integration\UI\EntitySelector\ProjectTagProvider\isAvailable
isAvailable()
Definition
projecttagprovider.php:37
Bitrix\Socialnetwork\UserToGroupTable
Definition
usertogroup.php:33
Bitrix\Socialnetwork\WorkgroupTable
Definition
workgroup.php:33
Bitrix\Socialnetwork\WorkgroupTagTable
Definition
workgrouptag.php:30
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\getRecentItems
getRecentItems()
Definition
dialog.php:225
Bitrix\UI\EntitySelector\Dialog\addItems
addItems(array $items)
Definition
dialog.php:121
Bitrix\UI\EntitySelector\Dialog\addItem
addItem(Item $item)
Definition
dialog.php:112
Bitrix\UI\EntitySelector\Dialog\addTab
addTab(Tab $tab)
Definition
dialog.php:235
Bitrix\UI\EntitySelector\Dialog\getItemCollection
getItemCollection()
Definition
dialog.php:102
Bitrix\UI\EntitySelector\Item
Definition
item.php:8
Bitrix\UI\EntitySelector\RecentItem
Definition
recentitem.php:6
Bitrix\UI\EntitySelector\SearchQuery
Definition
searchquery.php:5
Bitrix\UI\EntitySelector\SearchQuery\getQuery
getQuery()
Definition
searchquery.php:40
Bitrix\UI\EntitySelector\Tab
Definition
tab.php:5
Bitrix\SocialNetwork\Integration\UI\EntitySelector
Definition
projectrolesprovider.php:2
modules
socialnetwork
lib
integration
ui
entityselector
projecttagprovider.php
Создано системой
1.10.0