1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
ExternalChat.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Chat;
4
5use Bitrix\Im\V2\Chat;
6use Bitrix\Im\V2\Chat\ExternalChat\Config;
7use Bitrix\Im\V2\Chat\ExternalChat\Event\AfterCreateEvent;
8use Bitrix\Im\V2\Chat\ExternalChat\Event\BeforeCreateEvent;
9use Bitrix\Im\V2\Chat\ExternalChat\Event\BeforeUsersAddEvent;
10use Bitrix\Im\V2\Chat\ExternalChat\Event\FilterUsersByAccessEvent;
11use Bitrix\Im\V2\Chat\ExternalChat\Event\GetUsersForRecentEvent;
12use Bitrix\Im\V2\Chat\ExternalChat\ExternalTypeRegistry;
13use Bitrix\Im\V2\Relation\AddUsersConfig;
14use Bitrix\Im\V2\Relation\ExternalChatRelations;
15use Bitrix\Im\V2\Result;
16use Bitrix\Im\V2\Service\Context;
17
19{
20 protected Config $config;
21
22 public function add(array $params, ?Context $context = null): Result
23 {
24 $beforeCreateEvent = new BeforeCreateEvent($params);
25 $beforeCreateEvent->send();
26 $result = $beforeCreateEvent->getResult();
27
28 if (!$result->isSuccess())
29 {
30 return $result;
31 }
32
33 $params = $result->getResult()['fields'] ?? $params;
34
35 $addResult = parent::add($params, $context);
36
37 (new AfterCreateEvent($params['ENTITY_TYPE'] ?? '', $addResult))->send();
38
39 return $addResult;
40 }
41
42 protected function prepareParams(array $params = []): Result
43 {
44 if (empty($params['ENTITY_TYPE']))
45 {
46 return (new Result())->addError(new ChatError(ChatError::ENTITY_TYPE_EMPTY));
47 }
48
49 return parent::prepareParams($params);
50 }
51
52 protected function checkAccessInternal(int $userId): Result
53 {
55 $event->send();
56 if (!$event->hasResult())
57 {
58 return parent::checkAccessInternal($userId);
59 }
60
61 $result = new Result();
62 $usersWithAccess = $event->getUsersWithAccess();
63
64 if (!in_array($userId, $usersWithAccess, true))
65 {
66 return $result->addError(new ChatError(ChatError::ACCESS_DENIED));
67 }
68
69 return $result;
70 }
71
72 protected function getUsersToAddToRecent(): array
73 {
74 $event = new GetUsersForRecentEvent($this);
75 $event->send();
76 if (!$event->hasResult())
77 {
78 return parent::getUsersToAddToRecent();
79 }
80
81 return $event->getUsersForRecent();
82 }
83
85 {
86 if ($this->getId())
87 {
88 $this->chatRelations ??= ExternalChatRelations::getInstance($this->getId());
89 }
90
91 return $this->chatRelations;
92 }
93
94 public function isAutoJoinEnabled(): bool
95 {
96 return $this->getConfig()->isAutoJoinEnabled;
97 }
98
99 public function addUsers(array $userIds, AddUsersConfig $config = new AddUsersConfig()): Chat
100 {
101 $event = new BeforeUsersAddEvent($this, $userIds, $config);
102 $event->send();
103 if (!$event->getResult()->isSuccess())
104 {
105 return $this;
106 }
107
108 $userIds = $event->getNewUserIds() ?? $userIds;
109 $config = $event->getNewAddUsersConfig() ?? $config;
110
111 return parent::addUsers($userIds, $config);
112 }
113
114 public function getConfig(): Config
115 {
116 $this->config ??=
117 ExternalTypeRegistry::getInstance()->getConfigByType($this->getExtendedType(false))
118 ?? new Config()
119 ;
120
121 return $this->config;
122 }
123
124 protected function needToSendMessageUserDelete(): bool
125 {
126 return false;
127 }
128}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
const ENTITY_TYPE_EMPTY
Определения ChatError.php:36
const ACCESS_DENIED
Определения ChatError.php:19
checkAccessInternal(int $userId)
Определения ExternalChat.php:52
needToSendMessageUserDelete()
Определения ExternalChat.php:124
add(array $params, ?Context $context=null)
Определения ExternalChat.php:22
addUsers(array $userIds, AddUsersConfig $config=new AddUsersConfig())
Определения ExternalChat.php:99
prepareParams(array $params=[])
Определения ExternalChat.php:42
static getInstance(int $chatId)
Определения ChatRelations.php:35
Определения result.php:20
</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
$context
Определения csv_new_setup.php:223
Определения culture.php:9
$event
Определения prolog_after.php:141
$config
Определения quickway.php:69
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799