Skip to content

Commit

Permalink
Merge pull request #6386 from chlulei/8_mantis_31342_ical
Browse files Browse the repository at this point in the history
0038146: iCal URL problems
  • Loading branch information
smeyer-ilias authored Oct 6, 2023
2 parents 7010c05 + f60bbf3 commit 3f548de
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions Services/Calendar/classes/Export/class.ilCalendarExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,38 +168,41 @@ protected function addCategories(int $remaining_bytes): ilICalWriter
}
$single_appointments[] = $appointment;
}
}

usort($single_appointments, function (ilCalendarEntry $a, ilCalendarEntry $b) {
return $a->getStart() > $b->getStart();
});

// Apply a filter on limited exports only
if ($this->is_export_limited) {
$single_appointments = array_filter($single_appointments, function (ilCalendarEntry $a) {
$time_now = new ilDateTime(time(), IL_CAL_UNIX);
$str_time_now = $time_now->get(IL_CAL_FKT_DATE, 'Ymd', ilTimeZone::UTC);
$str_time_start = $a->getStart()->get(IL_CAL_FKT_DATE, 'Ymd', $this->il_user->getTimeZone());
$start = new DateTimeImmutable($str_time_start);
$now = new DateTimeImmutable($str_time_now);
$lower_bound = $now->sub(new DateInterval('P30D'));
return $lower_bound <= $start;
});
usort($single_appointments, function (ilCalendarEntry $a, ilCalendarEntry $b) {
if($a->getStart() === $b->getStart()) {
return 0;
}
return $a->getStart() > $b->getStart() ? 1 : -1;
});

// Apply a filter on limited exports only
if ($this->is_export_limited) {
$single_appointments = array_filter($single_appointments, function (ilCalendarEntry $a) {
$time_now = new ilDateTime(time(), IL_CAL_UNIX);
$str_time_now = $time_now->get(IL_CAL_FKT_DATE, 'Ymd', ilTimeZone::UTC);
$str_time_start = $a->getStart()->get(IL_CAL_FKT_DATE, 'Ymd', $this->il_user->getTimeZone());
$start = new DateTimeImmutable($str_time_start);
$now = new DateTimeImmutable($str_time_now);
$lower_bound = $now->sub(new DateInterval('P30D'));
return $lower_bound <= $start;
});
}

foreach ($single_appointments as $appointment) {
$str_writer_appointment = $this->createAppointment($appointment);
// Check byte count for limited exports only
if (
$this->is_export_limited &&
($str_writer_appointments->byteCount() + $str_writer_appointment->byteCount()) > $remaining_bytes
) {
break;
}
$str_writer_appointments->append($str_writer_appointment);
foreach ($single_appointments as $appointment) {
$str_writer_appointment = $this->createAppointment($appointment);
// Check byte count for limited exports only
if (
$this->is_export_limited &&
($str_writer_appointments->byteCount() + $str_writer_appointment->byteCount()) > $remaining_bytes
) {
break;
}

return $str_writer_appointments;
$str_writer_appointments->append($str_writer_appointment);
}

return $str_writer_appointments;
}

protected function isRepeatingAppointment(ilCalendarEntry $appointment): bool
Expand All @@ -211,7 +214,7 @@ protected function addAppointments(): ilICalWriter
{
$str_builder_appointments = new ilICalWriter();
foreach ($this->getAppointments() as $app) {
$str_writer_appointment = $this->createAppointment($app);
$str_writer_appointment = $this->createAppointment(new ilCalendarEntry($app));
$str_builder_appointments->append($str_writer_appointment);
}
return $str_builder_appointments;
Expand Down

0 comments on commit 3f548de

Please sign in to comment.