1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Collab.php
См. документацию.
1<?php
2
4
19use Bitrix\Socialnetwork\Item\Workgroup\Type;
21
22class Collab
23{
24 public static function isAvailable(): bool
25 {
26 return
27 Loader::includeModule('socialnetwork')
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();
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
Определения options.php:106
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getPullExtra()
Определения common.php:127
static getCurrent()
Определения User.php:89
static updateCollabOption(Chat\CollabChat $chat, string $name, string $value)
Определения Collab.php:40
static isCollab(int $collabId)
Определения Collab.php:124
static onEntityCountersUpdate(int $collabId, array $counters, string $entityType)
Определения Collab.php:76
static getInstance()
Определения application.php:98
Определения result.php:20
Определения error.php:15
static createFromThrowable(Throwable $exception)
Определения error.php:45
Определения event.php:5
Определения loader.php:13
static createOption(string $name, string $value,)
Определения OptionFactory.php:32
static checkWithAccess(int $userId)
Определения Requirement.php:28
</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
$name
Определения menu_edit.php:35
$service
Определения payment.php:18
$counter
Определения options.php:5
$option
Определения options.php:1711
$counters
Определения options.php:100