1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
Collab.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Im\V2\Integration\Socialnetwork
;
4
5
use
Bitrix\Im\V2\Chat
;
6
use
Bitrix\Im\V2\Entity\User\User
;
7
use
Bitrix\Im\V2\Result
;
8
use
Bitrix\Main\ArgumentException
;
9
use
Bitrix\Main\Error
;
10
use
Bitrix\Main\Loader
;
11
use
Bitrix\Pull\Event
;
12
use
Bitrix\Socialnetwork\Collab\CollabFeature
;
13
use
Bitrix\Socialnetwork\Collab\Control\CollabService
;
14
use
Bitrix\Socialnetwork\Collab\Control\Command\CollabUpdateCommand
;
15
use
Bitrix\Socialnetwork\Collab\Control\Option\OptionFactory
;
16
use
Bitrix\Socialnetwork\Collab\Provider\CollabProvider
;
17
use
Bitrix\Socialnetwork\Collab\Requirement
;
18
use
Bitrix\Socialnetwork\Control\Decorator\AccessDecorator
;
19
use Bitrix\Socialnetwork\Item\Workgroup\Type;
20
use
Bitrix\Socialnetwork\Provider\GroupProvider
;
21
22
class
Collab
23
{
24
public
static
function
isAvailable
(): bool
25
{
26
return
27
Loader::includeModule(
'socialnetwork'
)
28
&&
CollabFeature::isOn
()
29
&&
Requirement::check
()->isSuccess()
30
;
31
}
32
33
public
static
function
isCreationAvailable
(): bool
34
{
35
$userId
=
User::getCurrent
()->getId() ?? 0;
36
37
return
self::isAvailable() &&
Requirement::checkWithAccess
(
$userId
)->isSuccess();
38
}
39
40
public
static
function
updateCollabOption
(
Chat
\
CollabChat
$chat,
string
$name
,
string
$value):
Result
41
{
42
$result
=
new
Result
();
43
44
if
(!Loader::includeModule(
'socialnetwork'
))
45
{
46
return
$result
;
47
}
48
49
$collabId = (int)$chat->getEntityId();
50
$option
=
OptionFactory::createOption
(
$name
, $value);
51
52
try
53
{
54
$command = (
new
CollabUpdateCommand
())
55
->setId($collabId)
56
->setInitiatorId($chat->getContext()->getUserId())
57
->addOption(
$option
)
58
;
59
}
60
catch
(
ArgumentException
$e)
61
{
62
return
$result
->addError(
Error::createFromThrowable
($e));
63
}
64
65
$service
=
new
CollabService
();
66
$updateResult = (
new
AccessDecorator
(
$service
))->update($command);
67
68
if
(!$updateResult->isSuccess())
69
{
70
$result
->addErrors($updateResult->getErrors());
71
}
72
73
return
$result
;
74
}
75
76
public
static
function
onEntityCountersUpdate
(
int
$collabId,
array
$counters
,
string
$entityType): void
77
{
78
if
(!Loader::includeModule(
'socialnetwork'
))
79
{
80
return
;
81
}
82
83
$collab = CollabProvider::getInstance()->getCollab($collabId);
84
if
($collab ===
null
)
85
{
86
return
;
87
}
88
89
$chatId = $collab->getChatId();
90
$chat =
Chat::getInstance
($chatId);
91
if
(!$chat instanceof
Chat
\
CollabChat
)
92
{
93
return
;
94
}
95
96
$dialogId = $chat->getDialogId();
97
98
if
(!Loader::includeModule(
'pull'
))
99
{
100
return
;
101
}
102
103
if
(empty(
$counters
))
104
{
105
return
;
106
}
107
108
foreach
(
$counters
as
$userId
=>
$counter
)
109
{
110
Event::add(
$userId
, [
111
'module_id'
=>
'im'
,
112
'command'
=>
'updateCollabEntityCounter'
,
113
'params'
=> [
114
'dialogId'
=> $dialogId,
115
'chatId'
=> $chatId,
116
'entity'
=> $entityType,
117
'counter'
=>
$counter
,
118
],
119
'extra'
=> \
Bitrix
\
Im
\
Common::getPullExtra
(),
120
]);
121
}
122
}
123
124
public
static
function
isCollab
(
int
$collabId): bool
125
{
126
if
(!Loader::includeModule(
'socialnetwork'
))
127
{
128
return
false
;
129
}
130
$type
= GroupProvider::getInstance()->getGroupType($collabId);
131
132
return
$type
=== Type::Collab;
133
}
134
}
$type
$type
Определения
options.php:106
$userId
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения
check_mail.php:18
Bitrix\Im\Common\getPullExtra
static getPullExtra()
Определения
common.php:127
Bitrix\Im\V2\Chat\CollabChat
Определения
CollabChat.php:22
Bitrix\Im\V2\Entity\User\User
Определения
User.php:27
Bitrix\Im\V2\Entity\User\User\getCurrent
static getCurrent()
Определения
User.php:89
Bitrix\Im\V2\Integration\Socialnetwork\Collab\isCreationAvailable
static isCreationAvailable()
Определения
Collab.php:33
Bitrix\Im\V2\Integration\Socialnetwork\Collab\updateCollabOption
static updateCollabOption(Chat\CollabChat $chat, string $name, string $value)
Определения
Collab.php:40
Bitrix\Im\V2\Integration\Socialnetwork\Collab\isCollab
static isCollab(int $collabId)
Определения
Collab.php:124
Bitrix\Im\V2\Integration\Socialnetwork\Collab\onEntityCountersUpdate
static onEntityCountersUpdate(int $collabId, array $counters, string $entityType)
Определения
Collab.php:76
Bitrix\Im\V2\Integration\Socialnetwork\Collab\isAvailable
static isAvailable()
Определения
Collab.php:24
Bitrix\Main\Application\getInstance
static getInstance()
Определения
application.php:98
Bitrix\Main\ArgumentException
Определения
ArgumentException.php:9
Bitrix\Main\DB\Result
Определения
result.php:20
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\Error\createFromThrowable
static createFromThrowable(Throwable $exception)
Определения
error.php:45
Bitrix\Main\Event
Определения
event.php:5
Bitrix\Main\Loader
Определения
loader.php:13
Bitrix\Socialnetwork\Collab\CollabFeature
Определения
CollabFeature.php:15
Bitrix\Socialnetwork\Collab\CollabFeature\isOn
static isOn()
Определения
CollabFeature.php:34
Bitrix\Socialnetwork\Collab\Control\CollabService
Определения
CollabService.php:47
Bitrix\Socialnetwork\Collab\Control\Command\CollabUpdateCommand
Определения
CollabUpdateCommand.php:27
Bitrix\Socialnetwork\Collab\Control\Option\OptionFactory
Определения
OptionFactory.php:18
Bitrix\Socialnetwork\Collab\Control\Option\OptionFactory\createOption
static createOption(string $name, string $value,)
Определения
OptionFactory.php:32
Bitrix\Socialnetwork\Collab\Provider\CollabProvider
Определения
CollabProvider.php:23
Bitrix\Socialnetwork\Collab\Requirement
Определения
Requirement.php:17
Bitrix\Socialnetwork\Collab\Requirement\check
static check()
Определения
Requirement.php:45
Bitrix\Socialnetwork\Collab\Requirement\checkWithAccess
static checkWithAccess(int $userId)
Определения
Requirement.php:28
Bitrix\Socialnetwork\Control\Decorator\AccessDecorator
Определения
AccessDecorator.php:16
Bitrix\Socialnetwork\Provider\GroupProvider
Определения
GroupProvider.php:16
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
$name
$name
Определения
menu_edit.php:35
Bitrix\Im\V2\Chat\Collab
Определения
CollabInfo.php:3
Bitrix\Im\V2\Chat
Bitrix\Im\V2\Integration\Socialnetwork
Определения
Collab.php:3
Bitrix\Im
Bitrix
$service
$service
Определения
payment.php:18
$counter
$counter
Определения
options.php:5
$option
$option
Определения
options.php:1711
$counters
$counters
Определения
options.php:100
bitrix
modules
im
lib
V2
Integration
Socialnetwork
Collab.php
Создано системой
1.14.0