Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
icalmaileventmanager.php
1<?php
2
4
16
18{
19 public static function onMailMessageNew(Event $event)
20 {
21 $message = $event->getParameter('message');
22 $attachments = $event->getParameter('attachments');
23 $userId = $event->getParameter('userId');
24 $icalAccess = $event->getParameter('icalAccess');
25
27 {
29 $files = static::getFiles($message);
30
31 foreach ($files as $file)
32 {
33 $data = ICalMailManager::getFileContent($file['FILE_ID']);
34 $icalComponent = ICalMailManager::parseRequest($data);
35
36 if (!($icalComponent instanceof Calendar))
37 {
38 continue;
39 }
40
41 if (empty($message['OPTIONS']['iCal']))
42 {
43 $message['OPTIONS']['iCal'] = $data;
44
45 MailMessageTable::update($message['ID'], [
46 'OPTIONS' => $message['OPTIONS'],
47 ]);
48 }
49
50 if (!$icalComponent->hasOneEvent())
51 {
52 break;
53 }
54
55 if ($icalComponent->getMethod() === Dictionary::METHOD['reply'])
56 {
57 $result = ICalMailManager::handleReply($icalComponent);
58
59 break;
60 }
61 elseif (
62 ($icalComponent->getMethod() === Dictionary::METHOD['request'])
63 && $icalAccess
64 )
65 {
67 $icalComponent,
68 $userId,
69 IncomingInvitationRequestHandler::MEETING_STATUS_QUESTION_CODE,
70 $message
71 );
72
73 if ($result !== null)
74 {
76 $message['ID'],
78 $result,
79 $userId
80 );
81 }
82
83 break;
84 }
85 elseif ($icalComponent->getMethod() === Dictionary::METHOD['cancel'])
86 {
87 $result = ICalMailManager::handleCancel($icalComponent, $userId);
88
89 break;
90 }
91 }
92 }
93 }
94
95 public static function onUnbindEvent($calendarEventId, $entry): void
96 {
97 Loader::includeModule('calendar');
98 $calendarEventId = (int)$calendarEventId;
99
100 $userParams = [];
101
102 if ($calendarEventId <= 0)
103 {
104 return;
105 }
106
107 $events = EventTable::getList([
108 'select' => ['ID', 'OWNER_ID'],
109 'filter' => [
110 'PARENT_ID' => $calendarEventId,
111 '!ID' => $calendarEventId,
112 ],
113 ])->fetchAll();
114
115 $entityValues = array_map(fn($event) => (int)$event['ID'], $events);
116
117 $messageAccessCollection = MessageAccessTable::getList([
118 'select' => ['MESSAGE_ID', 'ENTITY_ID'],
119 'filter' => [
120 'ENTITY_TYPE' => MessageAccessTable::ENTITY_TYPE_CALENDAR_EVENT,
121 'ENTITY_ID' => $entityValues,
122 ],
123 ])->fetchAll();
124
125 foreach ($events as $event)
126 {
127 $messageAccess = array_filter($messageAccessCollection, fn($msgAccess) => (int)$msgAccess['ENTITY_ID'] === (int)$event['ID']);
128 if ($messageAccess)
129 {
130 $messageId = (int)$messageAccess[0]['MESSAGE_ID'];
131 $userParams[(int)$event['OWNER_ID']] = ['messageId' => $messageId];
132 }
133 }
134
135 MessageAccessTable::deleteByFilter([
136 'ENTITY_TYPE' => MessageAccessTable::ENTITY_TYPE_CALENDAR_EVENT,
137 'ENTITY_ID' => $entityValues,
138 ]);
139
140 \Bitrix\Pull\Event::add(array_keys($userParams), [
141 'module_id' => 'mail',
142 'command' => 'unbindItem',
143 'params' => [
144 'type' => 'meeting',
145 ],
146 'user_params' => $userParams,
147 ]
148 );
149 }
150
151 private static function getFiles($message)
152 {
153 if ($message['ATTACHMENTS'] > 0)
154 {
155 return MailMessageAttachmentTable::getList([
156 'select' => [
157 'ID',
158 'FILE_ID',
159 'FILE_NAME',
160 'FILE_SIZE',
161 'CONTENT_TYPE',
162 ],
163 'filter' => [
164 '=MESSAGE_ID' => $message['ID'],
165 '@CONTENT_TYPE' => ICalMailManager::CONTENT_TYPES
166 ],
167 ])->fetchAll();
168 }
169
170 return [];
171 }
172}
static ensureAttachments(&$message)
Definition message.php:498
static handleRequest(Calendar $icalComponent, int $userId, string $decision, $message)
static handleCancel(Calendar $icalComponent, $userId)
static provideAccessToMessage(int $mailMessageId, string $entityType, int $entityId, int $userId)
getParameter($key)
Definition event.php:80