29 $event = $params[
'event'];
30 $userId = $params[
'userId'];
31 $answer = $params[
'answer'];
32 $userEmail = $params[
'emailTo'];
33 $organizerEmail = $event[
'ORGANIZER_MAIL'][
'EMAIL'];
35 $event = static::updateEvent($event, $userId, $answer);
36 $attendees = static::handleAttendeesFromRequest([
37 'attendees' => $event[
'ATTENDEES_MAIL'],
40 'userEmail' => $userEmail,
41 'organizerEmail' => $organizerEmail
44 $parentId = \CCalendar::SaveEvent([
45 'arFields' => static::updateParentEvent($event),
48 \CCalendar::SaveEvent([
49 'arFields' => static::updateChildEvent($event, $parentId),
54 'icalMethod' =>
'reply',
56 'userIndex' => $attendees,
57 'receiver' => $event[
'ORGANIZER_MAIL'],
58 'sender' => $attendees[$event[
'OWNER_ID']],
59 ])->replyInvitation()->getStatus();
64 $uid = $params[
'event'][
'DAV_XML_ID'];
65 $emailUser = $params[
'event'][
'ATTENDEES_MAIL'][0];
66 $userId = ICalUtil::getUserIdByEmail($emailUser);
67 $localEvent = ICalUtil::getEventByUId($userId, $uid);
69 if (!empty($localEvent))
71 $status = $params[
'event'][
'ATTENDEES_MAIL'][0][
'STATUS'];
73 \CCalendarEvent::SetMeetingStatusEx([
74 'attendeeId' => $localEvent[
'OWNER_ID'],
75 'eventId' => $localEvent[
'ID'],
76 'status' => Dictionary::LOCAL_ATTENDEES_STATUS[$status],
77 'personalNotification' => $localEvent[
'MEETING_HOST'],
86 $attachments = $event->getParameter(
'attachments');
88 if (is_array($attachments))
90 foreach($attachments as $key => $file)
94 $fileObject = new \Bitrix\Main\IO\File($file[
'tmp_name'], $event->getParameter(
'site_id'));
97 $fileContent = $fileObject->getContents();
104 $icalComponent = static::getDataInfo($fileContent);
106 if ($method === Dictionary::METHODS[
'reply'])
108 static::handleReply([
'event' => $icalEvent]);
117 $event = $params[
'event'];
118 $userId = $params[
'userId'];
120 $originalValue = ICalUtil::getEventByUId($userId, $event[
'DAV_XML_ID']);
121 if (!empty($originalValue))
124 'sendNotification' =>
true,
125 'checkPermissions' =>
false,
128 \CCalendar::DeleteEvent($originalValue[
'ID'],
true, $deleteParams);
138 $event = $attachmentManager->prepareEventAttachment()->getEvent();
139 $method = $attachmentManager->getMethod();
141 return [$event, $method];
146 $params[
'event'][
'SKIP_TIME'] = $params[
'event'][
'DT_SKIP_TIME'] ===
'Y';
148 $attendees = static::handleAttendeesByUser(
149 ICalUtil::getUsersByCode($params[
'event'][
'ATTENDEES_CODES']),
155 ->setSelect([
'EMAIL' =>
'MAILBOX.EMAIL'])
156 ->registerRuntimeField(
161 Join::on(
'this.MAILBOX_ID',
'ref.ID'),
162 [
'join_type' => Join::TYPE_INNER]
166 ->where(
'ENTITY_ID', $params[
'event'][
'ID'])
169 $mailbox = $mailBoxQuery->fetch();
175 $params[
'event'][
'ORGANIZER_MAIL'] = $attendees[$params[
'event'][
'MEETING_HOST']];
176 $params[
'event'][
'ORGANIZER_MAIL'][
'MAILTO'] = $params[
'event'][
'MEETING'][
'MAILTO'];
177 $params[
'event'][
'ATTENDEES_MAIL'] = $attendees[$params[
'event'][
'OWNER_ID']];
178 $params[
'event'][
'ICAL_ORGANIZER'] = (Helper::getAttendee($params[
'event'][
'MEETING_HOST'], $params[
'event'][
'PARENT_ID'],
false))
185 $answer = isset($params[
'answer']) && $params[
'answer']
186 ? IncomingInvitationRequestHandler::MEETING_STATUS_ACCEPTED_CODE
187 : IncomingInvitationRequestHandler::MEETING_STATUS_DECLINED_CODE
189 $attendee = Helper::getAttendee($params[
'event'][
'OWNER_ID'], $params[
'event'][
'PARENT_ID'],
false);
190 $status = Dictionary::OUT_ATTENDEES_STATUS[$answer];
191 $attendee->setStatus($status);
192 $attendee->setEmail($mailbox[
'EMAIL'])->setMailto($mailbox[
'EMAIL']);
196 'icalMethod' =>
'reply',
197 'arFields' => $params[
'event'],
198 'userIndex' => $attendeesCollection,
199 'receiver' => $params[
'event'][
'ORGANIZER_MAIL'],
200 'sender' => $attendees[$params[
'event'][
'OWNER_ID']],
202 ])->replyInvitation()->getStatus();
205 private static function updateEvent(array $event, $userId, $answer): array
207 if (isset($event[
'DATE_FROM']))
209 $event[
'DATE_FROM_MAIL'] = $event[
'SKIP_TIME']
210 ? static::getDateString($event[
'DATE_FROM'])
211 : static::getDateTimeString($event[
'DATE_FROM']);
212 $event[
'DATE_FROM'] = static::getDateTimeString($event[
'DATE_FROM']);
215 if (isset($event[
'DATE_TO']))
217 $event[
'DATE_TO'] = static::getDateTimeString($event[
'DATE_TO']);
220 if (isset($event[
'DATE_CREATE']))
222 $event[
'DATE_CREATE'] = static::getDateTimeString($event[
'DATE_CREATE']);
225 if (isset($event[
'TIMESTAMP_X']))
227 $event[
'TIMESTAMP_X'] = static::getDateTimeString($event[
'TIMESTAMP_X']);
230 if (isset($event[
'DT_STAMP']))
232 $event[
'DT_STAMP'] = static::getDateTimeString($event[
'DT_STAMP']);
235 if (isset($event[
'TZ_FROM']))
237 $event[
'TZ_FROM'] = static::getTimezoneNameString($event[
'TZ_FROM']);
240 if (isset($event[
'TZ_TO']))
242 $event[
'TZ_TO'] = static::getTimezoneNameString($event[
'TZ_TO']);
246 $event[
'MEETING_HOST'] = ICalUtil::getUserIdByEmail($event[
'ORGANIZER_MAIL']);
247 $event[
'IS_MEETING'] = 1;
248 $event[
'SECTION_CAL_TYPE'] =
'user';
249 $event[
'ATTENDEES_CODES'] = [
'U'.$event[
'OWNER_ID'],
'U'.$event[
'MEETING_HOST']];
250 $event[
'MEETING_STATUS'] = $answer ===
'confirmed' ?
'Y' :
'N';
252 if (empty($event[
'ACCESSIBILITY']))
254 $event[
'ACCESSIBILITY'] =
'free';
257 if (empty($event[
'IMPORTANCE']))
259 $event[
'IMPORTANCE'] =
'normal';
262 if (empty($event[
'STATUS']))
264 $event[
'STATUS'] = $answer ===
'ACCEPT' ?
'CONFIRMED' :
'CANCELLED';
267 if (empty($event[
'REMIND']))
275 if (empty($event[
'MEETING']))
277 $event[
'MEETING'] = [
278 'HOST_NAME' => $event[
'ORGANIZER_MAIL'][
'name'],
282 'MEETING_CREATOR' => $event[
'MEETING_HOST'],
283 'EXTERNAL_TYPE' =>
'mail',
287 $originalValue = ICalUtil::getEventByUId($userId, $event[
'DAV_XML_ID']);
288 $event[
'ID'] = $originalValue ? $originalValue[
'ID'] : 0;
293 private static function getDateTimeString(Date $date): string
295 return $date->format(Date::convertFormatToPhp(FORMAT_DATETIME));
298 private static function getDateString(Date $date): string
300 return $date->format(
'd.m.Y');
303 private static function getTimezoneNameString(\DateTimeZone $tz)
305 return $tz->getName();
308 private static function handleAttendeesFromRequest(array $params): array
312 foreach ($params[
'attendees'] as $attendee)
314 if ($attendee[
'EMAIL'] == $params[
'userEmail'])
316 $usersInfo = ICalUtil::getIndexUsersById([$params[
'userId']]);
317 $attendee[
'NAME'] = $usersInfo[$params[
'userId']][
'NAME'];
318 $attendee[
'LAST_NAME'] = $usersInfo[$params[
'userId']][
'LAST_NAME'];
319 $attendee[
'STATUS'] = $params[
'answer'] ===
'confirmed' ?
'accepted' :
'declined';
320 $result[$params[
'userId']] = $attendee;
323 if ($attendee[
'EMAIL'] == $params[
'organizerEmail'])
325 $id = ICalUtil::getUserIdByEmail($attendee);
326 $result[$id] = $attendee;
333 private static function handleAttendeesByUser(array $attendees, $answer, $userId)
336 foreach ($attendees as $attendee)
338 if ($attendee[
'ID'] == $userId)
340 $attendee[
'STATUS'] = $answer ?
'accepted' :
'declined';
343 $result[$attendee[
'ID']] = $attendee;
349 private static function updateChildEvent(array $event, $parentId)
351 $event[
'PARENT_ID'] = $parentId;
352 $event[
'MEETING'][
'MAILTO'] = $event[
'ORGANIZER_MAIL'][
'MAILTO'];
353 $event[
'DESCRIPTION'] .=
"\r\n"
354 .
Loc::getMessage(
'EC_ORGANIZER_NAME_TITLE') .
': ' . static::getOrganizerString($event[
'ORGANIZER_MAIL']) .
"\r\n"
355 .
Loc::getMessage(
'EC_ATTENDEES_LIST_TITLE') .
': ' . static::getAttendeesString($event[
'ATTENDEES_MAIL']);
356 if (!empty($event[
'ATTACHMENT_LINK']))
358 $event[
'DESCRIPTION'] .=
"\r\n"
359 .
Loc::getMessage(
'EC_FILES_TITLE') .
': ' . static::getFilesString($event[
'ATTACHMENT_LINK']);
364 private static function getAttendeesString($attendees)
367 foreach ($attendees as $attendee)
369 $res[] = $attendee[
'NAME'] .
' ' . $attendee[
'LAST_NAME'] .
' ('. $attendee[
'EMAIL'] .
')';
372 return implode(
', ', $res);
375 private static function getOrganizerString($organizer)
377 return $organizer[
'NAME'] .
' ' . $organizer[
'LAST_NAME'] .
' ('. $organizer[
'EMAIL'] .
')';
380 private static function updateParentEvent(array $event)
382 $event[
'OWNER_ID'] = $event[
'MEETING_HOST'];
383 unset($event[
'DAV_XML_ID']);
388 private static function getFilesString(array $attachments)
391 foreach ($attachments as $attachment)
393 $res[] = $attachment[
'filename'] .
' (' . $attachment[
'link'] .
')';
395 return implode(
', ', $res);
static getMessage($code, $replace=null, $language=null)