1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
metauserprovider.php
См. документацию.
1
<?
2
3
namespace
Bitrix\Socialnetwork\Integration\UI\EntitySelector;
4
5
use Bitrix\Main\Localization\Loc;
6
use Bitrix\Main\ModuleManager;
7
use Bitrix\UI\EntitySelector\BaseProvider;
8
use Bitrix\UI\EntitySelector\Dialog;
9
use Bitrix\UI\EntitySelector\Item;
10
11
class
MetaUserProvider
extends
BaseProvider
12
{
13
private
const
SUPPORTED_IDS = [self::ALL_USERS, self::OTHER_USERS];
14
15
private
const
ALL_USERS =
'all-users'
;
16
private
const
OTHER_USERS =
'other-users'
;
17
18
public
function
__construct
(
array
$options
= [])
19
{
20
parent::__construct();
21
22
$internalizeOption =
function
(
array
$options
,
string
$key
):
void
{
23
if
(isset(
$options
[
$key
]))
24
{
25
$this->options[
$key
] = is_array(
$options
[
$key
]) ?
$options
[
$key
] : [];
26
if
(
27
!isset($this->options[
$key
][
'allowView'
])
28
|| !is_bool($this->options[
$key
][
'allowView'
])
29
)
30
{
31
$this->options[
$key
][
'allowView'
] =
null
;
32
}
33
}
34
};
35
36
foreach
(self::SUPPORTED_IDS as $id)
37
{
38
$internalizeOption(
$options
, $id);
39
}
40
}
41
42
public
function
isAvailable
(): bool
43
{
44
return
$GLOBALS
[
'USER'
]->isAuthorized();
45
}
46
47
public
function
fillDialog
(
Dialog
$dialog): void
48
{
49
if
(!self::canViewAllUsers())
50
{
51
return
;
52
}
53
54
$options
= $this->
getOptions
();
55
$ids = [];
56
foreach
(self::SUPPORTED_IDS as $id)
57
{
58
if
(isset(
$options
[$id]) &&
$options
[$id][
'allowView'
] !==
false
)
59
{
60
$ids[] = $id;
61
}
62
}
63
64
foreach
(self::getMetaUsers($ids,
$options
) as $metaUser)
65
{
66
$dialog->addRecentItem($metaUser);
67
}
68
}
69
70
public
function
getItems
(
array
$ids):
array
71
{
72
return
self::getMetaUsers
($ids, $this->
getOptions
());
73
}
74
75
public
function
getSelectedItems
(
array
$ids):
array
76
{
77
$options
= [];
78
foreach
(self::SUPPORTED_IDS as $id)
79
{
80
$options
[$id] = [
81
'allowView'
=>
true
,
82
'deselectable'
=>
self::canViewAllUsers
(),
83
];
84
}
85
86
return
self::getMetaUsers
($ids, array_merge(
$options
, $this->
getOptions
()));
87
}
88
89
public
static
function
canViewAllUsers
(): bool
90
{
91
$intranetInstalled = ModuleManager::isModuleInstalled(
'intranet'
);
92
93
return
!$intranetInstalled || ($intranetInstalled &&
UserProvider::isIntranetUser
());
94
}
95
96
public
static
function
getMetaUsers
(
array
$ids,
$options
= []):
array
97
{
98
$users = [];
99
100
$sort = 1;
101
foreach
($ids as $id)
102
{
103
if
(!isset($users[$id]) && in_array($id, self::SUPPORTED_IDS,
true
))
104
{
105
$itemOptions
=
106
isset(
$options
[$id]) && is_array(
$options
[$id]) ?
$options
[$id]: []
107
;
108
109
$canView =
110
isset(
$itemOptions
[
'allowView'
]) && is_bool(
$itemOptions
[
'allowView'
])
111
?
$itemOptions
[
'allowView'
] :
112
self::canViewAllUsers
()
113
;
114
115
if
($canView)
116
{
117
$itemOptions
[
'sort'
] ??= $sort;
118
$users[$id] = self::getMetaUserItem($id,
$itemOptions
);
119
$sort++;
120
}
121
}
122
}
123
124
return
array_values($users);
125
}
126
127
public
static
function
getAllUsersItem
(
array
$options
= []):
Item
128
{
129
return
self::getMetaUserItem(self::ALL_USERS,
$options
);
130
}
131
132
private
static
function
getMetaUserItem(
string
$id,
array
$options
= []):
Item
133
{
134
$title
= isset(
$options
[
'title'
]) && is_string(
$options
[
'title'
]) ?
$options
[
'title'
] :
''
;
135
if
(empty(
$title
))
136
{
137
$title
= self::getTitle($id);
138
}
139
140
$deselectable =
141
isset(
$options
[
'deselectable'
]) && is_bool(
$options
[
'deselectable'
]) ?
$options
[
'deselectable'
] : true
142
;
143
144
$searchable =
145
isset(
$options
[
'searchable'
]) && is_bool(
$options
[
'searchable'
]) ?
$options
[
'searchable'
] :
false
146
;
147
148
$availableInRecentTab =
149
isset(
$options
[
'availableInRecentTab'
]) && is_bool(
$options
[
'availableInRecentTab'
])
150
?
$options
[
'availableInRecentTab'
]
151
: true
152
;
153
154
$sort = isset(
$options
[
'sort'
]) && is_numeric(
$options
[
'sort'
]) ? (int)
$options
[
'sort'
] : 1;
155
156
return
new
Item
([
157
'id'
=> $id,
158
'entityId'
=>
'meta-user'
,
159
'entityType'
=> $id,
160
'title'
=>
$title
,
161
'searchable'
=> $searchable,
162
'saveable'
=>
false
,
163
'deselectable'
=> $deselectable,
164
'availableInRecentTab'
=> $availableInRecentTab,
165
'sort'
=> $sort,
166
]);
167
}
168
169
private
static
function
getTitle(
string
$id): ?string
170
{
171
$intranetInstalled = ModuleManager::isModuleInstalled(
'intranet'
);
172
173
if
($id === self::ALL_USERS)
174
{
175
return
Loc::getMessage(
176
$intranetInstalled ?
'SOCNET_ENTITY_SELECTOR_ALL_EMPLOYEES'
:
'SOCNET_ENTITY_SELECTOR_ALL_USERS'
177
);
178
}
179
180
if
($id === self::OTHER_USERS)
181
{
182
return
Loc::getMessage(
183
$intranetInstalled ?
'SOCNET_ENTITY_SELECTOR_OTHER_EMPLOYEES'
:
'SOCNET_ENTITY_SELECTOR_OTHER_USERS'
184
);
185
}
186
187
return
null
;
188
}
189
}
Bitrix\Im\Dialog
Определения
dialog.php:11
Bitrix\Socialnetwork\Integration\UI\EntitySelector\MetaUserProvider
Определения
metauserprovider.php:12
Bitrix\Socialnetwork\Integration\UI\EntitySelector\MetaUserProvider\getAllUsersItem
static getAllUsersItem(array $options=[])
Определения
metauserprovider.php:127
Bitrix\Socialnetwork\Integration\UI\EntitySelector\MetaUserProvider\canViewAllUsers
static canViewAllUsers()
Определения
metauserprovider.php:89
Bitrix\Socialnetwork\Integration\UI\EntitySelector\MetaUserProvider\__construct
__construct(array $options=[])
Определения
metauserprovider.php:18
Bitrix\Socialnetwork\Integration\UI\EntitySelector\MetaUserProvider\getMetaUsers
static getMetaUsers(array $ids, $options=[])
Определения
metauserprovider.php:96
Bitrix\Socialnetwork\Integration\UI\EntitySelector\MetaUserProvider\fillDialog
fillDialog(Dialog $dialog)
Определения
metauserprovider.php:47
Bitrix\Socialnetwork\Integration\UI\EntitySelector\MetaUserProvider\getSelectedItems
getSelectedItems(array $ids)
Определения
metauserprovider.php:75
Bitrix\Socialnetwork\Integration\UI\EntitySelector\MetaUserProvider\getItems
getItems(array $ids)
Определения
metauserprovider.php:70
Bitrix\Socialnetwork\Integration\UI\EntitySelector\MetaUserProvider\isAvailable
isAvailable()
Определения
metauserprovider.php:42
Bitrix\Socialnetwork\Integration\UI\EntitySelector\UserProvider\isIntranetUser
static isIntranetUser(int $userId=null)
Определения
userprovider.php:509
Bitrix\UI\EntitySelector\BaseProvider
Определения
baseprovider.php:5
Bitrix\UI\EntitySelector\BaseProvider\$options
$options
Определения
baseprovider.php:6
Bitrix\UI\EntitySelector\BaseProvider\getOptions
getOptions()
Определения
baseprovider.php:43
$options
$options
Определения
commerceml2.php:49
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
Bitrix\Main\$GLOBALS
$GLOBALS['____1690880296']
Определения
license.php:1
Bitrix\Socialnetwork\Item
Определения
contentviewhandler.php:9
false
return false
Определения
prolog_main_admin.php:185
$key
if(empty($signedUserToken)) $key
Определения
quickway.php:257
$title
$title
Определения
pdf.php:123
$itemOptions
if($vatExport) $itemOptions
Определения
yandex_run.php:952
bitrix
modules
socialnetwork
lib
integration
ui
entityselector
metauserprovider.php
Создано системой
1.14.0