24include_once
'./Services/Calendar/classes/class.ilCalendarUserSettings.php';
25include_once
'./Services/Calendar/classes/iCal/class.ilICalWriter.php';
26include_once
'./Services/Calendar/classes/class.ilCalendarCategory.php';
27include_once
'./Services/Calendar/classes/class.ilCalendarEntry.php';
28include_once
'./Services/Calendar/classes/class.ilCalendarCategoryAssignments.php';
82 $this->il_user =
$DIC->user();
83 $this->logger =
$DIC->logger()->cal();
84 $this->calendars = $a_calendar_ids;
86 $this->appointments = [];
98 $this->appointments = $a_apps;
111 $this->calendars = $a_cal_ids;
124 $this->export_type = $a_type;
134 $this->str_writer_export->clear();
136 $str_writer_prefix->addLine(
'BEGIN:VCALENDAR');
137 $str_writer_prefix->addLine(
'VERSION:2.0');
138 $str_writer_prefix->addLine(
'METHOD:PUBLISH');
139 $str_writer_prefix->addLine(
'PRODID:-//ilias.de/NONSGML ILIAS Calendar V4.4//EN');
142 $str_writer_suffix->addLine(
'END:VCALENDAR');
143 $this->str_writer_export->append($str_writer_prefix);
146 $byte_sum = $str_writer_prefix->byteCount() + $str_writer_suffix->byteCount();
147 $remaining_bytes = self::BYTE_LIMIT - $byte_sum;
149 $this->str_writer_export->append($str_builder_body);
154 $this->str_writer_export->append($str_builder_body);
157 $this->str_writer_export->append($str_writer_suffix);
167 $str_writer->addLine(
'X-WR-TIMEZONE:' . $this->il_user->getTimeZone());
169 include_once
'./Services/Calendar/classes/class.ilCalendarUtil.php';
171 if (!is_file($tzid_file)) {
174 $reader = fopen($tzid_file,
'r');
175 while ($line = fgets($reader)) {
176 $line = str_replace(
"\n",
'', $line);
177 $str_writer->addLine($line);
184 $single_appointments = [];
187 foreach ($this->calendars as $category_id) {
192 $str_writer_appointments->append($str_writer_appointment);
195 $single_appointments[] = $appointment;
200 return $a->getStart() >
$b->getStart();
204 if ($this->is_export_limited) {
205 $single_appointments = array_filter($single_appointments,
function (
ilCalendarEntry $a) {
208 $str_time_start =
$a->getStart()->get(
IL_CAL_FKT_DATE,
'Ymd', $this->il_user->getTimeZone());
209 $start =
new DateTimeImmutable($str_time_start);
210 $now =
new DateTimeImmutable($str_time_now);
211 $lower_bound = $now->sub(
new DateInterval(
'P30D'));
212 return $lower_bound <= $start;
216 foreach ($single_appointments as $appointment) {
220 $this->is_export_limited &&
221 ($str_writer_appointments->byteCount() + $str_writer_appointment->byteCount()) > $remaining_bytes
225 $str_writer_appointments->append($str_writer_appointment);
228 return $str_writer_appointments;
241 $str_builder_appointments->append($str_writer_appointment);
243 return $str_builder_appointments;
264 $this->logger->notice(
'Cannot create appointment for app_id: ' .
$app->getEntryId());
268 if (!strlen((
string) $test_date)) {
273 $str_writer->addLine(
'BEGIN:VEVENT');
274 $str_writer->addLine(
'DTSTAMP:'
281 $str_writer->addLine(
'LAST-MODIFIED:' . $last_mod);
283 $startInit =
$app->getStart();
284 $endInit =
$app->getEnd();
287 if (
$app->isFullday()) {
291 $start = $startInit->get(
IL_CAL_FKT_DATE,
'Ymd', $this->il_user->getTimeZone());
292 $end = $endInit->get(
IL_CAL_FKT_DATE,
'Ymd', $this->il_user->getTimeZone());
293 $str_writer->addLine(
'DTSTART;VALUE=DATE:' . $start);
294 $str_writer->addLine(
'DTEND;VALUE=DATE:' . $end);
299 $str_writer->addLine(
'DTSTART:' . $start);
300 $str_writer->addLine(
'DTEND:' . $end);
302 $start = $startInit->get(
IL_CAL_FKT_DATE,
'Ymd\THis', $this->il_user->getTimeZone());
303 $end = $endInit->get(
IL_CAL_FKT_DATE,
'Ymd\THis', $this->il_user->getTimeZone());
304 $str_writer->addLine(
'DTSTART;TZID=' . $this->il_user->getTimezone() .
':' . $start);
305 $str_writer->addLine(
'DTEND;TZID=' . $this->il_user->getTimezone() .
':' . $end);
312 if (strlen(
$app->getDescription())) {
315 if (strlen(
$app->getLocation())) {
321 $str_writer->addLine(
'END:VEVENT');
328 include_once
'./Services/Calendar/classes/class.ilCalendarRecurrences.php';
331 $str_writer->addLine($excl->toICal());
333 $recurrence_ical = $rec->toICal($this->il_user->getId());
334 if (strlen($recurrence_ical)) {
335 $str_writer->addLine($recurrence_ical);
343 return $this->str_writer_export->__toString();
353 $str_writer->addLine(
'URL;VALUE=URI:' . ILIAS_HTTP_PATH);
356 include_once
'./Services/Link/classes/class.ilLink.php';
An exception for terminatinating execution or to throw for unit testing.
static _getAssignedAppointments($a_cat_id)
Get assigned apointments.
static _lookupCategories($a_cal_id)
lookup categories
static getInstanceByCategoryId($a_cat_id)
Get instance by category id.
Model for a calendar entry.
isMilestone()
is milestone
@classDescription Export calendar(s) to ical format
buildAppointmentUrl(ilCalendarEntry $entry)
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($a_cal_id)
get all recurrences of an appointment
static _getInstanceByUserId($a_user_id)
get singleton instance
static getZoneInfoFile($a_tz)
@classDescription Date and time handling
static escapeText($a_text)
static _getLink($a_ref_id, $a_type='', $a_params=array(), $append="")
static _getAllReferences($a_id)
get all reference ids of object
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples