19declare(strict_types=1);
56 $this->il_user =
$DIC->user();
57 $this->
logger = $DIC->logger()->cal();
58 $this->calendars = $a_calendar_ids;
60 $this->appointments = [];
75 $this->appointments = $a_apps;
91 $this->calendars = $a_cal_ids;
104 $this->export_type = $a_type;
113 $this->str_writer_export->clear();
115 $str_writer_prefix->addLine(
'BEGIN:VCALENDAR');
116 $str_writer_prefix->addLine(
'VERSION:2.0');
117 $str_writer_prefix->addLine(
'METHOD:PUBLISH');
118 $str_writer_prefix->addLine(
'PRODID:-//ilias.de/NONSGML ILIAS Calendar V4.4//EN');
121 $str_writer_suffix->addLine(
'END:VCALENDAR');
122 $this->str_writer_export->append($str_writer_prefix);
125 $byte_sum = $str_writer_prefix->byteCount() + $str_writer_suffix->byteCount();
126 $remaining_bytes = self::BYTE_LIMIT - $byte_sum;
128 $this->str_writer_export->append($str_builder_body);
133 $this->str_writer_export->append($str_builder_body);
136 $this->str_writer_export->append($str_writer_suffix);
146 $str_writer->addLine(
'X-WR-TIMEZONE:' . $this->il_user->getTimeZone());
148 if (!is_file($tzid_file)) {
151 $reader = fopen($tzid_file,
'r');
152 while ($line = fgets($reader)) {
153 $line = str_replace(
"\n",
'', $line);
154 $str_writer->addLine($line);
161 $single_appointments = [];
164 foreach ($this->calendars as $category_id) {
169 $str_writer_appointments->append($str_writer_appointment);
172 $single_appointments[] = $appointment;
177 if(
$a->getStart() ===
$b->getStart()) {
180 return $a->getStart() >
$b->getStart() ? 1 : -1;
184 if ($this->is_export_limited) {
185 $single_appointments = array_filter($single_appointments,
function (
ilCalendarEntry $a) {
188 $str_time_start =
$a->getStart()->get(
IL_CAL_FKT_DATE,
'Ymd', $this->il_user->getTimeZone());
189 if ($str_time_start ===
null) {
192 $start =
new DateTimeImmutable($str_time_start);
193 $now =
new DateTimeImmutable($str_time_now);
194 $lower_bound = $now->sub(
new DateInterval(
'P30D'));
195 return $lower_bound <= $start;
199 foreach ($single_appointments as $appointment) {
203 $this->is_export_limited &&
204 ($str_writer_appointments->byteCount() + $str_writer_appointment->byteCount()) > $remaining_bytes
208 $str_writer_appointments->append($str_writer_appointment);
211 return $str_writer_appointments;
224 $str_builder_appointments->append($str_writer_appointment);
226 return $str_builder_appointments;
243 $this->
logger->notice(
'Cannot create appointment for app_id: ' . $app->
getEntryId());
247 if (!strlen((
string) $test_date)) {
252 $str_writer->addLine(
'BEGIN:VEVENT');
253 $str_writer->addLine(
'DTSTAMP:'
260 $str_writer->addLine(
'LAST-MODIFIED:' . $last_mod);
263 $endInit = $app->
getEnd();
270 $start = $startInit->get(
IL_CAL_FKT_DATE,
'Ymd', $this->il_user->getTimeZone());
271 $end = $endInit->get(
IL_CAL_FKT_DATE,
'Ymd', $this->il_user->getTimeZone());
272 $str_writer->addLine(
'DTSTART;VALUE=DATE:' . $start);
273 $str_writer->addLine(
'DTEND;VALUE=DATE:' . $end);
278 $str_writer->addLine(
'DTSTART:' . $start);
279 $str_writer->addLine(
'DTEND:' . $end);
281 $start = $startInit->get(
IL_CAL_FKT_DATE,
'Ymd\THis', $this->il_user->getTimeZone());
282 $end = $endInit->get(
IL_CAL_FKT_DATE,
'Ymd\THis', $this->il_user->getTimeZone());
283 $str_writer->addLine(
'DTSTART;TZID=' . $this->il_user->getTimezone() .
':' . $start);
284 $str_writer->addLine(
'DTEND;TZID=' . $this->il_user->getTimezone() .
':' . $end);
300 $str_writer->addLine(
'END:VEVENT');
309 $str_writer->addLine($excl->toICal());
311 $recurrence_ical = $rec->toICal($this->il_user->getId());
312 if (strlen($recurrence_ical)) {
313 $str_writer->addLine($recurrence_ical);
321 return $this->str_writer_export->__toString();
331 $str_writer->addLine(
'URL;VALUE=URI:' . ILIAS_HTTP_PATH);
334 $str_writer->addLine(
'URL;VALUE=URI:' . ilLink::_getLink(current($refs)));
static _lookupCategories(int $a_cal_id)
static _getAssignedAppointments(array $a_cat_id)
Get assigned apointments.
static getInstanceByCategoryId(int $a_cat_id)
Model for a calendar entry.
getEnd()
Get end of period.
getStart()
Get start of date period.
isFullday()
is event a fullday period
getPresentationTitle(bool $a_shorten=true)
@classDescription Export calendar(s) to ical format
ilICalWriter $str_writer_export
buildAppointmentUrl(ilCalendarEntry $entry)
setAppointments(array $a_apps)
ilCalendarUserSettings $user_settings
createAppointment(ilCalendarEntry $appointment)
createVTODO(ilCalendarEntry $app)
createVEVENT(ilCalendarEntry $app)
const EXPORT_APPOINTMENTS
addCategories(int $remaining_bytes)
createRecurrences(ilCalendarEntry $app)
__construct(array $a_calendar_ids=[], bool $is_export_limited=false)
setCalendarIds(array $a_cal_ids)
setExportType(int $a_type)
isRepeatingAppointment(ilCalendarEntry $appointment)
static getExclusionDates($a_cal_id)
Read exclusion dates.
static _getRecurrences(int $a_cal_id)
get all recurrences of an appointment
static _getInstanceByUserId(int $a_user_id)
static getZoneInfoFile($a_tz)
@classDescription Date and time handling
static escapeText(string $a_text)
Component logger with individual log levels by component id.
static _getAllReferences(int $id)
get all reference ids for object ID
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples