56 private $changeFields;
57 private $counterInvitations;
61 return new self($params);
66 $this->method = $params[
'icalMethod'];
67 $this->eventFields = $params[
'arFields'];
68 $this->attendees = $params[
'userIndex'];
69 $this->receiver = $params[
'receiver'];
70 $this->sender = $params[
'sender'];
71 $this->changeFields = $params[
'changeFields'];
72 $this->counterInvitations = 0;
73 $this->answer = $params[
'answer'];
79 'method' => $this->method,
80 'eventFields' => $this->eventFields,
81 'attendees' => $this->attendees,
82 'receiver' => $this->receiver,
83 'sender' => $this->sender,
84 'changeFields' => $this->changeFields,
90 $this->method = $data[
'method'];
91 $this->eventFields = $data[
'eventFields'];
92 $this->attendees = $data[
'attendees'];
93 $this->receiver = $data[
'receiver'];
94 $this->sender = $data[
'sender'];
95 $this->changeFields = $data[
'changeFields'];
100 $this->checkOrganizerEmail();
101 $filesContent = $this->getRequestContent();
102 $mailEventFields = $this->getRequestMailEventFields();
103 $files = $this->getFiles();
104 $this->status = \CEvent::sendImmediate(
'SEND_ICAL_INVENT', SITE_ID, $mailEventFields,
"Y",
"", $files,
'', $filesContent);
111 $filesContent = $this->getReplyContent();
112 $mailEventFields = $this->getReplyMailEventFields();
113 $files = $this->getFiles();
114 $this->status = \CEvent::sendImmediate(
'SEND_ICAL_INVENT', SITE_ID, $mailEventFields,
"Y",
"", $files,
'', $filesContent);
121 $filesContent = $this->getCancelContent();
122 $mailEventFields = $this->getCancelMailEventFields();
124 $this->status = \CEvent::sendImmediate(
'SEND_ICAL_INVENT', SITE_ID, $mailEventFields,
"Y",
"", $files,
'', $filesContent);
136 $this->counterInvitations++;
141 return $this->eventFields[
'ID'];
146 return $this->eventFields;
151 return $this->method;
156 return $this->counterInvitations;
161 return $this->status;
166 return $this->receiver;
169 private function getSenderAddress(): string
171 return $this->eventFields[
'MEETING'][
'MAIL_FROM'] ?? $this->sender[
'EMAIL'];
174 private function getReceiverAddress(): string
176 if (isset($this->receiver[
'MAILTO']))
178 return $this->receiver[
'MAILTO'];
181 return $this->receiver[
'EMAIL'];
184 private function getBodyMessage(): string
186 return 'ical body message';
189 private function getSubjectMessage(): string
192 $siteName = \COption::GetOptionString(
"main",
"site_name",
'');
193 if ($siteName !==
'')
195 $result =
"[".$siteName.
"]";
198 switch ($this->method)
201 $result .=
' ' .
Loc::getMessage(
"EC_CALENDAR_ICAL_MAIL_METHOD_REQUEST");
207 $result .=
' ' .
Loc::getMessage(
"EC_CALENDAR_ICAL_MAIL_METHOD_CANCEL");
210 $answer = match ($this->answer)
212 IncomingInvitationRequestHandler::MEETING_STATUS_ACCEPTED_CODE =>
Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_METHOD_REPLY_ACCEPTED'),
213 IncomingInvitationRequestHandler::MEETING_STATUS_DECLINED_CODE =>
Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_METHOD_REPLY_DECLINED'),
214 default =>
throw new LogicException(
'Calendar. Ical. With the reply method, none of the statuses matched')
216 $result .=
' ' . $answer;
220 $result .=
": ".$this->eventFields[
'NAME'];
225 private function getFiles(): array
230 private function getRequestContent(): array
232 $attachmentManager =
new OutcomingAttachmentManager ($this->eventFields, $this->attendees, $this->method);
233 $attachmentManager->prepareRequestAttachment();
234 $this->uid = $attachmentManager->getUid();
235 $fileContent = Encoding::convertEncoding($attachmentManager->getAttachment(), SITE_CHARSET,
"utf-8");
237 'CONTENT' => $fileContent,
239 'METHOD' => Dictionary::METHODS[$this->method],
242 'ID' => Helper::getUniqId(),
246 private function getRequestMailEventFields(): array
251 private function getReplyMailEventFields()
254 'EMAIL_FROM' => $this->getSenderAddress(),
255 'EMAIL_TO' => $this->getReceiverAddress(),
257 'MESSAGE_SUBJECT' => $this->getSubjectMessage(),
258 'MESSAGE_PHP' => $this->getReplyBodyMessage(),
259 'NAME' => $this->eventFields[
'NAME'],
260 'ANSWER' => $this->answer,
261 'DATE_FROM' => $this->eventFields[
'DATE_FROM'],
262 'DATE_TO' => $this->eventFields[
'DATE_TO'],
263 'FULL_DAY' => $this->eventFields[
'SKIP_TIME'] ?
'Y' :
'N',
264 'DESCRIPTION' => str_replace(
"\r\n",
"#$&#$&#$&", $this->eventFields[
'DESCRIPTION']),
265 'ATTENDEES' => $this->getAttendeesList(),
266 'ATTENDEES_LIST' => $this->getAttendeesList(),
267 'ORGANIZER' => $this->getOrganizerName(),
268 'LOCATION' => $this->eventFields[
'LOCATION'],
269 'FILES_LINK' =>$this->getFilesLink(),
270 'METHOD' => $this->method,
274 private function getCancelMailEventFields()
277 "=Reply-To" => $this->getOrganizerName().
' <'.$this->getReceiverAddress().
'>',
278 "=From" => $this->getOrganizerName().
' <'.$this->getSenderAddress().
'>',
279 "=Message-Id" => $this->getMessageId(),
280 "=In-Reply-To" => $this->getMessageReplyTo(),
281 'EMAIL_FROM' => $this->getSenderAddress(),
282 'EMAIL_TO' => $this->getReceiverAddress(),
283 'MESSAGE_SUBJECT' => $this->getSubjectMessage(),
284 'MESSAGE_PHP' => $this->getBodyMessage(),
285 'DATE_FROM' => $this->eventFields[
'DATE_FROM'],
286 'DATE_TO' => $this->eventFields[
'DATE_TO'],
287 'NAME' => $this->eventFields[
'NAME'],
288 'DESCRIPTION' => str_replace(
"\r\n",
"#$&#$&#$&", $this->eventFields[
'DESCRIPTION']),
289 'ATTENDEES' => $this->getAttendeesList(),
290 'ORGANIZER' => $this->getOrganizerName(),
291 'LOCATION' => $this->eventFields[
'LOCATION'],
292 'FILES_LINK' =>$this->getFilesLink(),
293 'METHOD' => $this->method,
297 private function getAttendeesList(): string
299 if ($this->eventFields[
'MEETING'][
'HIDE_GUESTS'])
301 return (
string)
Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_HIDE_GUESTS_INFORMATION');
307 foreach ($this->attendees as $attendee)
309 if (!empty($attendee->getFullName()))
311 $attendees[] = $attendee->getFullName();
315 return implode(
", ", $attendees);
318 private function getOrganizerName(): string
321 $organizer = $this->eventFields[
'ICAL_ORGANIZER'];
322 return $organizer->getFullName() .
' (' . $organizer->getEmail() .
')';
325 private function getFilesLink()
329 foreach ($this->eventFields[
'ATTACHES'] as $attach)
331 $attaches[] =
'<a href="'.$attach[
'link'].
'">'.$attach[
'name'].
'</a><br />' ;
334 return implode(
" ", $attaches);
337 private function getMessageId(): string
339 return "<CALENDAR_EVENT_".$this->eventFields[
'PARENT_ID'].
"@".
$GLOBALS[
"SERVER_NAME"].
">";
342 private function getMessageReplyTo(): string
344 return $this->getMessageId();
347 private function getReplyContent(): array
349 $attachmentManager =
new OutcomingAttachmentManager ($this->eventFields, $this->attendees, $this->method);
350 $attachmentManager->prepareReplyAttachment();
351 $fileContent = Encoding::convertEncoding($attachmentManager->getAttachment(), SITE_CHARSET,
"utf-8");
353 'CONTENT' => $fileContent,
355 'METHOD' => Dictionary::METHODS[$this->method],
358 'ID' => Helper::getUniqId(),
362 private function getReplyBodyMessage()
364 return 'reply body message';
367 private function getCancelContent(): array
369 $attachmentManager =
new OutcomingAttachmentManager ($this->eventFields, $this->attendees, $this->method);
370 $attachmentManager->prepareCancelAttachment();
371 $fileContent = Encoding::convertEncoding($attachmentManager->getAttachment(), SITE_CHARSET,
"utf-8");
373 'CONTENT' => $fileContent,
375 'METHOD' => Dictionary::METHODS[$this->method],
378 'ID' => ICalUtil::getUniqId(),
382 private function getDateForTemplate()
384 $res = Util::getIcalTemplateDate([
385 'DATE_FROM' => $this->eventFields[
'DATE_FROM'],
386 'DATE_TO' => $this->eventFields[
'DATE_TO'],
387 'TZ_FROM' => $this->eventFields[
'TZ_FROM'],
388 'TZ_TO' => $this->eventFields[
'TZ_TO'],
389 'FULL_DAY' => $this->eventFields[
'SKIP_TIME'],
392 $res .=
' (' . $this->eventFields[
'TZ_FROM'] .
', ' .
'UTC' . $offset .
')';
394 if (isset($this->eventFields[
'RRULE'][
'FREQ']) && $this->eventFields[
'RRULE'][
'FREQ'] !==
'NONE')
396 $rruleString = Util::getIcalTemplateRRule($this->eventFields[
'RRULE'],
398 'DATE_FROM' => $this->eventFields[
'DATE_FROM'],
399 'DATE_TO' => $this->eventFields[
'DATE_TO'],
400 'TZ_FROM' => $this->eventFields[
'TZ_FROM'],
401 'TZ_TO' => $this->eventFields[
'TZ_TO'],
402 'FULL_DAY' => $this->eventFields[
'SKIP_TIME'],
405 $res .=
', (' . $rruleString .
')';
411 private function getEditTitle()
413 if ($this->method !==
'edit')
418 if (count($this->changeFields) === 1)
420 switch ($this->changeFields[0][
'fieldKey'])
423 return Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_DATE');
425 return Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_LOCATION');
427 return Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_ATTENDEES');
429 return Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_RRULE');
431 return Loc::getMessage(
'EC_CALENDAR_ICAL_MAIL_CHANGE_FIELD_TITLE_NAME');
440 private function getChangeFieldsString()
443 if (!empty($this->changeFields))
445 foreach ($this->changeFields as $changeField)
447 $res[] = $changeField[
'fieldKey'];
450 return implode(
';', $res);
453 private function checkOrganizerEmail()
455 if (Loader::includeModule(
'mail'))
457 if (empty($this->sender[
'EMAIL']))
459 $boxes = \Bitrix\Mail\MailboxTable::getUserMailboxes($this->eventFields[
'MEETING_HOST']);
460 $email = array_shift($boxes)[
'EMAIL'];
461 $this->sender[
'EMAIL'] = $email;
462 $this->attendees[$this->eventFields[
'MEETING_HOST']][
'EMAIL'] = $email;
static getMessage($code, $replace=null, $language=null)