Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
status.php
1<?php
2namespace Bitrix\Im\Replica;
3
5Loc::loadMessages(__FILE__);
6
7class Status
8{
9 public static function isDeprecated(): bool
10 {
11 return (
12 time() > mktime(0, 0, 0, 9, 1, 2021)
13 || \Bitrix\Main\Config\Option::get('im', 'test_replica_deprecated') === 'Y'
14 );
15 }
16
17 public static function getMessageDialog(): string
18 {
19 $link = '[URL='.\Bitrix\UI\Util::getArticleUrlByCode("14137758").']'.
20 Loc::getMessage('IM_REPLICA_STATUS_LINK').
21 '[/URL]';
22
23 return Loc::getMessage('IM_REPLICA_STATUS_DIALOG', [
24 '#LINK#' => $link,
25 ]);
26 }
27
28 public static function getMessageChat(array $users): string
29 {
30 $link = '[URL='.\Bitrix\UI\Util::getArticleUrlByCode("14137758").']'.
31 Loc::getMessage('IM_REPLICA_STATUS_LINK').
32 '[/URL]';
33
34 if (count($users) > 1)
35 {
36 $message = Loc::getMessage('IM_REPLICA_STATUS_CHAT', [
37 '#LINK#' => $link,
38 '#USERS#' => implode(', ', $users)
39 ]);
40 }
41 else
42 {
43 $message = Loc::getMessage('IM_REPLICA_STATUS_CHAT_SINGLE', [
44 '#LINK#' => $link,
45 '#USER#' => $users[0]
46 ]);
47 }
48
49 return $message;
50 }
51
52 private static function getReplicaCode(): string
53 {
54 if (function_exists('bx_domain_to_name'))
55 {
56 return bx_domain_to_name(BX24_HOST_NAME);
57 }
58
59 if (defined("BX24_REPLICA_NAME"))
60 {
61 return BX24_REPLICA_NAME;
62 }
63
64 return '';
65 }
66
67 public static function checkAgent(): string
68 {
69 if (!self::isDeprecated())
70 {
71 return '\Bitrix\Im\Chat::checkReplicaDeprecatedAgent();';
72 }
73
74 $db = \Bitrix\Main\Application::getInstance()->getConnection();
75 if (!$db->isTableExists('b_replica_map'))
76 {
77 return '';
78 }
79
80 $replicaCode = $db->getSqlHelper()->forSql(self::getReplicaCode());
81
82 $result = $db->query("
83 SELECT distinct RM.ID_VALUE as CHAT_ID
84 from b_replica_map RM
85 INNER JOIN b_im_chat C ON C.ID = RM.ID_VALUE AND C.TYPE = 'C'
86 where RM.TABLE_NAME = 'b_im_chat.ID' AND RM.NODE_TO <> '".$replicaCode."'
87 ");
88 while ($row = $result->fetch())
89 {
90 $chatId = (int)$row['CHAT_ID'];
91 $userList = [];
92 $relationList = [];
93
94 $users = $db->query("
95 SELECT R.ID as RID, R.NOTIFY_BLOCK, U.ID, U.LOGIN, U.NAME, U.LAST_NAME, U.PERSONAL_GENDER, U.EXTERNAL_AUTH_ID
96 FROM b_im_relation R
97 INNER JOIN b_user U ON U.EXTERNAL_AUTH_ID = 'replica' AND U.ID = R.USER_ID
98 WHERE R.CHAT_ID = ".$chatId."
99 ");
100 while ($user = $users->fetch())
101 {
102 if ($user['NOTIFY_BLOCK'] === 'Y')
103 {
104 continue;
105 }
106
107 $relationList[] = $user['RID'];
108 $userList[$user['ID']] = '[b]'.\Bitrix\Im\User::formatFullNameFromDatabase($user).'[/b]';
109 }
110
111 if (empty($userList))
112 {
113 continue;
114 }
115
116 $message = \Bitrix\Im\Replica\Status::getMessageChat($userList);
117
118 \Bitrix\Im\Model\MessageTable::add([
119 'CHAT_ID' => $chatId,
120 'AUTHOR_ID' => 0,
121 'MESSAGE' => $message,
122 'NOTIFY_MODULE' => 'im',
123 'NOTIFY_EVENT' => 'group',
124 ]);
125
126 foreach ($relationList as $relationId)
127 {
128 \Bitrix\Im\Model\RelationTable::update($relationId, [
129 'NOTIFY_BLOCK' => 'Y'
130 ]);
131 }
132 }
133
134 return '';
135 }
136}
static getMessageDialog()
Definition status.php:17
static getMessageChat(array $users)
Definition status.php:28
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29