10 PRODID =
'-//Bitrix//Bitrix Calendar//EN',
23 $availableProperties = [
62 if (in_array($key, $this->availableProperties) && !empty($value))
64 $this->properties[$key] = $this->prepareValue($value, $key);
72 if (is_array($config))
74 if (isset($config[
'timezoneFrom']))
76 $this->timezoneFrom = $config[
'timezoneFrom'];
78 if (isset($config[
'timezoneTo']))
80 $this->timezoneTo = $config[
'timezoneTo'];
87 $this->fullDayMode = $value;
92 $this->organizer = [
'name' => $name,
'email' => $email,
'phone' => $phone];
97 if (is_array($attendeeDataList))
99 foreach($attendeeDataList as $attendeeData)
101 $this->attendees[] = $attendeeData;
108 return implode(
"\r\n", $this->buildBody());
111 private function buildBody()
116 'PRODID:'.self::PRODID,
118 'CALSCALE:GREGORIAN',
119 'METHOD:'.self::$METHOD,
126 if (isset($this->organizer[
'email']))
128 $props[self::formatOrganizerKey($this->organizer)] = self::formatEmailValue($this->organizer[
'email']);
130 else if (isset($this->organizer[
'phone']))
132 $props[self::formatOrganizerKey($this->organizer)] = self::formatPhoneValue($this->organizer[
'phone']);
136 if (is_array($this->attendees))
138 foreach($this->attendees as $k => $attendee)
140 $props[self::formatAttendeeKey($attendee)] = self::formatEmailValue($attendee[
'email']);
145 foreach($this->properties as $k => $v)
147 if ($k ===
'dtstamp')
149 $props[
'DTSTAMP'] = self::formatDateTimeValue($v);
154 $props[
'URL;VALUE=URI'] = $v;
156 else if ($k ===
'dtstart' || $k ===
'dtend')
158 if ($this->fullDayMode)
160 $props[mb_strtoupper($k).
';VALUE=DATE'] = self::formatDateValue($v);
164 $tzid = ($k ===
'dtstart') ? $this->timezoneFrom : $this->timezoneTo;
165 $props[mb_strtoupper($k).
';TZID='.$tzid] = self::formatDateTimeValue($v);
170 $props[mb_strtoupper($k)] = $v;
175 foreach ($props as $k => $v)
179 $ics_props[] =
"$k:$v";
183 $ics_props[] =
'BEGIN:VALARM';
184 $ics_props[] =
'TRIGGER:-PT' . $props[
'ALARM'];
185 $ics_props[] =
'ACTION:DISPLAY';
186 $ics_props[] =
'END:VALARM';
191 $ics_props[] =
'END:VEVENT';
192 $ics_props[] =
'END:VCALENDAR';
197 private function prepareValue($val, $key =
false)
207 $val = $this->escapeString($val);
212 private static function formatDateValue($timestamp)
214 $dt = new \DateTime();
215 $dt->setTimestamp($timestamp);
216 return $dt->format(self::DATE_FORMAT);
219 private static function formatDateTimeValue($timestamp)
221 $dt = new \DateTime();
224 $dt->setTimestamp($timestamp);
226 return $dt->format(self::DATETIME_FORMAT);
229 private static function formatEmailValue($email)
231 return 'mailto:'.$email;
234 private static function formatPhoneValue($phone): string
236 return 'tel:'.$phone;
240 private static function formatAttendeeKey($attendee)
243 $key .=
';CUTYPE=INDIVIDUAL';
245 $key .=
';RSVP=TRUE';
246 $key .=
';CN='.$attendee[
'email'];
250 private static function formatOrganizerKey(
$organizer)
255 $key .=
';CN='.$organizer[
'name'];
260 private static function escapeString($str)
262 return preg_replace(
'/([\,;])/',
'\\\$1', $str);