Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
recentchatprovider.php
1
<?php
2
namespace
Bitrix\Im\Integration\UI\EntitySelector
;
3
4
use
Bitrix\Main\ModuleManager
;
5
use
Bitrix\Main\UserTable
;
6
use
Bitrix\Socialnetwork\Integration\UI\EntitySelector\UserProvider
;
7
use
Bitrix\UI\EntitySelector\BaseProvider
;
8
use
Bitrix\UI\EntitySelector\Dialog
;
9
use
Bitrix\UI\EntitySelector\Item
;
10
11
class
RecentChatProvider
extends
BaseProvider
12
{
13
protected
const
ITEM_TYPE_CHAT
=
'chat'
;
14
protected
const
ITEM_TYPE_USER
=
'user'
;
15
16
public
function
__construct
(array
$options
= [])
17
{
18
parent::__construct();
19
20
if
(isset(
$options
[
'limit'
]) && is_int(
$options
[
'limit'
]))
21
{
22
$this->options[
'limit'
] =
$options
[
'limit'
];
23
}
24
}
25
26
public
function
isAvailable
(): bool
27
{
28
return
$GLOBALS
[
'USER'
]->isAuthorized();
29
}
30
31
public
function
fillDialog
(
Dialog
$dialog): void
32
{
33
$recentList = \Bitrix\Im\Recent::getList(
null
, [
34
'LIMIT'
=> $this->
getOption
(
'limit'
, 50),
35
'OFFSET'
=> 0,
36
]);
37
38
$items = (is_array($recentList) && isset($recentList[
'ITEMS'
]) && is_array($recentList[
'ITEMS'
]))
39
? $recentList[
'ITEMS'
]
40
: []
41
;
42
43
$dialog->
addRecentItems
($this->
makeRecentChatItems
($items));
44
}
45
46
public
function
makeRecentChatItems
(array $items, array
$options
= []): array
47
{
48
return
self::makeItems
($items, array_merge($this->
getOptions
(),
$options
));
49
}
50
51
public
function
getItems
(array $ids): array
52
{
53
return
[];
54
}
55
56
public
function
getSelectedItems
(array $ids): array
57
{
58
return
[];
59
}
60
61
public
static
function
makeItems
(array $items, array
$options
= []): array
62
{
63
$result = [];
64
foreach
($items as $item)
65
{
66
$result[] = static::makeItem($item,
$options
);
67
}
68
69
return
$result;
70
}
71
72
public
static
function
makeItem
(array $item, array
$options
= []):
Item
73
{
74
$itemOptions = [
75
'id'
=> $item[
'ID'
],
76
'entityId'
=>
self::getEntityIdByItem
($item),
77
'entityType'
=>
self::getEntityTypeByItem
($item),
78
'title'
=> $item[
'TITLE'
],
79
'avatar'
=> $item[
'AVATAR'
][
'URL'
],
80
'customData'
=>
self::getCustomDataByItem
($item),
81
'saveable'
=>
false
,
82
];
83
84
return
new
Item
($itemOptions);
85
}
86
87
protected
static
function
getEntityIdByItem
(array $item): string
88
{
89
if
($item[
'TYPE'
] === self::ITEM_TYPE_USER && !$item[
'USER'
][
'BOT'
])
90
{
91
return
$item[
'TYPE'
];
92
}
93
94
if
($item[
'TYPE'
] === self::ITEM_TYPE_USER && $item[
'USER'
][
'BOT'
])
95
{
96
return
'im-bot'
;
97
}
98
99
return
'im-'
. $item[
'TYPE'
];
100
}
101
102
protected
static
function
getEntityTypeByItem
(array $item): string
103
{
104
if
($item[
'TYPE'
] === self::ITEM_TYPE_CHAT)
105
{
106
return
self::getEntityTypeByChat
($item[
'CHAT'
]);
107
}
108
109
if
($item[
'TYPE'
] === self::ITEM_TYPE_USER)
110
{
111
return
self::getEntityTypeByUser
($item[
'USER'
]);
112
}
113
114
return
''
;
115
}
116
117
protected
static
function
getCustomDataByItem
(array $item): array
118
{
119
$customData = [];
120
if
($item[
'TYPE'
] === self::ITEM_TYPE_CHAT)
121
{
122
$customData[
'imChat'
] = $item[
'CHAT'
] ?: [];
123
124
return
$customData;
125
}
126
127
if
($item[
'TYPE'
] === self::ITEM_TYPE_USER)
128
{
129
$customData[
'imUser'
] = $item[
'USER'
] ?: [];
130
131
if
($item[
'USER'
] && $item[
'USER'
][
'BOT'
])
132
{
133
$customData[
'imBot'
] = \Bitrix\Im\Bot::getCache($item[
'ID'
]) ?: [];
134
}
135
}
136
137
return
$customData;
138
}
139
140
protected
static
function
getEntityTypeByChat
(array $chat): string
141
{
142
$entityType = $chat[
'ENTITY_TYPE'
];
143
if
($entityType !==
''
&& $entityType !==
null
)
144
{
145
return
$entityType;
146
}
147
148
$type = $chat[
'MESSAGE_TYPE'
];
149
switch
($type)
150
{
151
case \Bitrix\Im\Chat::TYPE_GROUP:
152
return
'GROUP'
;
153
154
case \Bitrix\Im\Chat::TYPE_OPEN:
155
return
'CHANNEL'
;
156
}
157
158
return
''
;
159
}
160
161
protected
static
function
getEntityTypeByUser
(array $user): string
162
{
163
if
(!$user[
'ACTIVE'
])
164
{
165
$type =
'inactive'
;
166
}
167
else
if
($user[
'EXTERNAL_AUTH_ID'
] ===
'email'
)
168
{
169
$type =
'email'
;
170
}
171
else
if
($user[
'EXTERNAL_AUTH_ID'
] ===
'replica'
)
172
{
173
$type =
'network'
;
174
}
175
else
if
(!in_array($user[
'EXTERNAL_AUTH_ID'
], UserTable::getExternalUserTypes(),
true
))
176
{
177
if
(
ModuleManager::isModuleInstalled
(
'intranet'
))
178
{
179
if
(
UserProvider::isIntegrator
($user[
'ID'
]))
180
{
181
$type =
'integrator'
;
182
}
183
else
184
{
185
$ufDepartment = $user[
'DEPARTMENTS'
];
186
if
(
187
empty($ufDepartment)
188
|| (
189
is_array($ufDepartment)
190
&& count($ufDepartment) === 1
191
&& (
int
)$ufDepartment[0] === 0
192
)
193
)
194
{
195
$type =
'extranet'
;
196
}
197
else
198
{
199
$type =
'employee'
;
200
}
201
}
202
}
203
else
204
{
205
$type =
'user'
;
206
}
207
}
208
else
209
{
210
$type =
'unknown'
;
211
}
212
213
return
$type;
214
}
215
}
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider
Definition
recentchatprovider.php:12
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\getCustomDataByItem
static getCustomDataByItem(array $item)
Definition
recentchatprovider.php:117
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\getEntityTypeByUser
static getEntityTypeByUser(array $user)
Definition
recentchatprovider.php:161
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\__construct
__construct(array $options=[])
Definition
recentchatprovider.php:16
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\makeItems
static makeItems(array $items, array $options=[])
Definition
recentchatprovider.php:61
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\getEntityTypeByChat
static getEntityTypeByChat(array $chat)
Definition
recentchatprovider.php:140
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\fillDialog
fillDialog(Dialog $dialog)
Definition
recentchatprovider.php:31
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\getEntityTypeByItem
static getEntityTypeByItem(array $item)
Definition
recentchatprovider.php:102
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\ITEM_TYPE_USER
const ITEM_TYPE_USER
Definition
recentchatprovider.php:14
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\makeRecentChatItems
makeRecentChatItems(array $items, array $options=[])
Definition
recentchatprovider.php:46
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\getEntityIdByItem
static getEntityIdByItem(array $item)
Definition
recentchatprovider.php:87
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\getSelectedItems
getSelectedItems(array $ids)
Definition
recentchatprovider.php:56
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\getItems
getItems(array $ids)
Definition
recentchatprovider.php:51
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\makeItem
static makeItem(array $item, array $options=[])
Definition
recentchatprovider.php:72
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\isAvailable
isAvailable()
Definition
recentchatprovider.php:26
Bitrix\Im\Integration\UI\EntitySelector\RecentChatProvider\ITEM_TYPE_CHAT
const ITEM_TYPE_CHAT
Definition
recentchatprovider.php:13
Bitrix\Main\ModuleManager
Definition
modulemanager.php:5
Bitrix\Main\ModuleManager\isModuleInstalled
static isModuleInstalled($moduleName)
Definition
modulemanager.php:67
Bitrix\Main\UserTable
Definition
user.php:46
Bitrix\Socialnetwork\Integration\UI\EntitySelector\UserProvider
Definition
userprovider.php:32
Bitrix\Socialnetwork\Integration\UI\EntitySelector\UserProvider\isIntegrator
static isIntegrator(int $userId=null)
Definition
userprovider.php:535
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\BaseProvider\getOption
getOption(string $option, $defaultValue=null)
Definition
baseprovider.php:48
Bitrix\UI\EntitySelector\Dialog
Definition
dialog.php:10
Bitrix\UI\EntitySelector\Dialog\addRecentItems
addRecentItems(array $items)
Definition
dialog.php:148
Bitrix\UI\EntitySelector\Item
Definition
item.php:8
Bitrix\Im\Integration\UI\EntitySelector
Definition
botprovider.php:2
Bitrix\Main\$GLOBALS
$GLOBALS['____1444769544']
Definition
license.php:1
modules
im
lib
integration
ui
entityselector
recentchatprovider.php
Создано системой
1.10.0