17 private const FILE_TYPE =
'text/calendar';
18 private const FILE_NAME =
'event';
19 private const FILE_EXTENSION =
'.ics';
20 private const MODULE_ID =
'calendar';
33 return self::$instance;
41 $fileData = $this->getIcsFileData($event, $params);
42 $fileId = \CFile::SaveFile($fileData,
'calendar');
44 if (!$this->checkIcsFileExistence($fileId))
52 private function getIcsFileData(
Event $event, array $params): array
55 $fileContent = Encoding::convertEncoding($fileContent, SITE_CHARSET,
"utf-8");
57 'name' => self::FILE_NAME . self::FILE_EXTENSION,
58 'type' => self::FILE_TYPE,
59 'MODULE_ID' => self::MODULE_ID,
60 'content' => $fileContent,
64 private function checkIcsFileExistence(
int $fileId): bool
66 return is_array(\CFile::GetFileArray($fileId));
74 $dtEnd += \CCalendar::GetDayLen();
76 $icsBuilder = new \Bitrix\Calendar\ICal\IcsBuilder(
78 'summary' => $event->
getName() ??
'',
79 'description' => $this->prepareEventDescription($event, $params),
83 'location' => $this->prepareLocationField($event),
84 'uid' => $event->
getUid() ?? uniqid(
'',
true),
88 if (isset($params[
'organizer']))
90 $organizer = $params[
'organizer'];
91 $icsBuilder->setOrganizer($organizer[
'name'], $organizer[
'email'] ??
null, $organizer[
'phone'] ??
null);
96 $icsBuilder->setConfig(
104 return $icsBuilder->render();
107 private function prepareEventDescription(
Event $event, array $params): string
109 $languageId = \CCalendar::getUserLanguageId($event->
getOwner()->getId());
110 $eventDescription =
'';
115 && count($attendeesCodes) > 1
119 $this->formatAttendeesDescription($attendeesCodes, $event->
getParentId(), $languageId)
124 if ($params[
'eventUrl'])
126 $eventDescription .=
Loc::getMessage(
'EC_EVENT_LINK') . $params[
'eventUrl'] .
'\\n';
129 if ($params[
'conferenceUrl'])
131 $eventDescription .=
Loc::getMessage(
'EC_CONFERENCE_LINK') . $params[
'conferenceUrl'].
'\\n';
136 $eventDescription .=
Loc::getMessage(
'EC_CALENDAR_ICS_COMMENT') .
': '. $description;
139 return $eventDescription;
142 private function formatAttendeesDescription(array $codes, ?
int $parentId,
string $languageId): string
144 $users = \CCalendar::GetDestinationUsers($codes,
true);
146 $names = array_map(
static function($user) {
147 return $user[
'FORMATTED_NAME'];
153 $result .= implode(
", ", $names);
159 private function prepareLocationField(Event $event): string
161 $locationProperty = $event->getLocation();
163 return $locationProperty ? \CCalendar::getTextLocation($locationProperty->getActualLocation()) :
'';
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)