Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
notificationmanager.php
1<?php
2
4
8use CAgent;
9use CIMNotify;
10use CTimeZone;
11
12use function ConvertTimeStamp;
13
15{
16 private const FINISHED_SYNC_NOTIFICATION_DELAY = 60;
17
26 public static function sendFinishedSyncNotification(int $userId, string $vendorName): void
27 {
28 if (
29 Main\Loader::includeModule("im")
30 && $userId
31 && !empty($vendorName)
32 )
33 {
34 CIMNotify::Add([
35 'TO_USER_ID' => $userId,
36 'FROM_USER_ID' => $userId,
37 'NOTIFY_TYPE' => IM_NOTIFY_SYSTEM,
38 'NOTIFY_MODULE' => 'calendar',
39 'NOTIFY_TAG' => 'CALENDAR|SYNC_FINISH|'.$userId,
40 'NOTIFY_SUB_TAG' => 'CALENDAR|SYNC_FINISH|'.$userId,
41 'NOTIFY_MESSAGE' => Loc::getMessage('FINISHED_SYNC_NOTIFICATION_'.mb_strtoupper($vendorName))
42 ]);
43 }
44 }
45
54 public static function sendRollbackSyncNotification(int $userId, string $vendorName): void
55 {
56 if (
57 Main\Loader::includeModule("im")
58 && $userId
59 && !empty($vendorName)
60 )
61 {
62 CIMNotify::Add([
63 'TO_USER_ID' => $userId,
64 'FROM_USER_ID' => $userId,
65 'NOTIFY_TYPE' => IM_NOTIFY_SYSTEM,
66 'NOTIFY_MODULE' => 'calendar',
67 'NOTIFY_TAG' => 'CALENDAR|SYNC_ROLLBACK|'.$userId,
68 'NOTIFY_SUB_TAG' => 'CALENDAR|SYNC_ROLLBACK|'.$userId,
69 'NOTIFY_MESSAGE' => Loc::getMessage('ROLLBACK_SYNC_NOTIFICATION_'.mb_strtoupper($vendorName))
70 ]);
71 }
72 }
73
80 public static function clearFinishedSyncNotificationAgent(int $userId, string $vendorName): void
81 {
82 CAgent::RemoveAgent(
83 '\\Bitrix\\Calendar\\Sync\\Managers\\NotificationManager::sendFinishedSyncNotification('
84 . $userId . ', '
85 . "'" . $vendorName . "'" . ');',
86 'calendar'
87 );
88 }
89
96 public static function addFinishedSyncNotificationAgent(int $userId, string $vendorName): void
97 {
98 CAgent::AddAgent(
99 '\\Bitrix\\Calendar\\Sync\\Managers\\NotificationManager::sendFinishedSyncNotification('
100 . $userId . ', '
101 . "'" . $vendorName . "'" . ');',
102 'calendar',
103 'Y',
104 0,
105 '',
106 'Y',
107 ConvertTimeStamp(time() + CTimeZone::GetOffset() + self::FINISHED_SYNC_NOTIFICATION_DELAY, 'FULL')
108 );
109 }
110
119 public static function sendBlockChangeNotification(int $userId, $messageCode, $vars)
120 {
121 if (
122 Main\Loader::includeModule("im")
123 && $userId
124 && !empty(Loc::getMessage($messageCode))
125 )
126 {
127 $message = Loc::getMessage($messageCode, $vars);
128
129 CIMNotify::Add([
130 'TO_USER_ID' => $userId,
131 'FROM_USER_ID' => $userId,
132 'NOTIFY_TYPE' => IM_NOTIFY_SYSTEM,
133 'NOTIFY_MODULE' => 'calendar',
134 'NOTIFY_TAG' => 'CALENDAR|SYNC_ROLLBACK|' . $userId . '|' . ($vars['EVENT_ID'] ?? rand(1,100)),
135 'NOTIFY_SUB_TAG' => 'CALENDAR|SYNC_ROLLBACK|'.$userId,
136 'NOTIFY_MESSAGE' => $message
137 ]);
138 }
139 }
140}
static addFinishedSyncNotificationAgent(int $userId, string $vendorName)
static sendRollbackSyncNotification(int $userId, string $vendorName)
static clearFinishedSyncNotificationAgent(int $userId, string $vendorName)
static sendFinishedSyncNotification(int $userId, string $vendorName)
static sendBlockChangeNotification(int $userId, $messageCode, $vars)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29