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;
247 $this->
logger->notice(
'Cannot create appointment for app_id: ' . $app->
getEntryId());
251 if (!strlen((
string) $test_date)) {
256 $str_writer->addLine(
'BEGIN:VEVENT');
257 $str_writer->addLine(
'DTSTAMP:'
264 $str_writer->addLine(
'LAST-MODIFIED:' . $last_mod);
266 $startInit =
$app->getStart();
267 $endInit =
$app->getEnd();
270 if (
$app->isFullday()) {
274 $start = $startInit->get(
IL_CAL_FKT_DATE,
'Ymd', $this->il_user->getTimeZone());
275 $end = $endInit->get(
IL_CAL_FKT_DATE,
'Ymd', $this->il_user->getTimeZone());
276 $str_writer->addLine(
'DTSTART;VALUE=DATE:' . $start);
277 $str_writer->addLine(
'DTEND;VALUE=DATE:' . $end);
282 $str_writer->addLine(
'DTSTART:' . $start);
283 $str_writer->addLine(
'DTEND:' . $end);
285 $start = $startInit->get(
IL_CAL_FKT_DATE,
'Ymd\THis', $this->il_user->getTimeZone());
286 $end = $endInit->get(
IL_CAL_FKT_DATE,
'Ymd\THis', $this->il_user->getTimeZone());
287 $str_writer->addLine(
'DTSTART;TZID=' . $this->il_user->getTimezone() .
':' . $start);
288 $str_writer->addLine(
'DTEND;TZID=' . $this->il_user->getTimezone() .
':' . $end);
295 if (strlen(
$app->getDescription())) {
298 if (strlen(
$app->getLocation())) {
304 $str_writer->addLine(
'END:VEVENT');
311 include_once
'./Services/Calendar/classes/class.ilCalendarRecurrences.php';
314 $str_writer->addLine($excl->toICal());
316 $recurrence_ical = $rec->toICal($this->il_user->getId());
317 if (strlen($recurrence_ical)) {
318 $str_writer->addLine($recurrence_ical);
326 return $this->str_writer_export->__toString();
336 $str_writer->addLine(
'URL;VALUE=URI:' . ILIAS_HTTP_PATH);
339 include_once
'./Services/Link/classes/class.ilLink.php';
static _lookupCategories(int $a_cal_id)
static _getAssignedAppointments(array $a_cat_id)
Get assigned apointments.
static getInstanceByCategoryId(int $a_cat_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
@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)
static _getLink(?int $a_ref_id, string $a_type='', array $a_params=array(), string $append="")
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