From a636dcb33e542e196ed07daf6b9e41beedab9910 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Wed, 3 Apr 2024 11:54:33 +0000 Subject: [PATCH] fixes #3922 Closes #3922 Merge request studip/studip!2792 --- app/controllers/calendar/contentbox.php | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/app/controllers/calendar/contentbox.php b/app/controllers/calendar/contentbox.php index 8ba5215f0d1..89b0ad32923 100644 --- a/app/controllers/calendar/contentbox.php +++ b/app/controllers/calendar/contentbox.php @@ -78,6 +78,15 @@ class Calendar_ContentboxController extends StudipController if ($this->admin) { $this->isProfile = $this->single && $this->userRange; } + + // Sort dates + usort($this->termine, function ($a, $b) { + [$a_begin, $a_end] = $this->parseBeginAndEndFromDate($a); + [$b_begin, $b_end] = $this->parseBeginAndEndFromDate($b); + + return $a_begin - $b_begin + ?: $a_end - $b_end; + }); } private function parseSeminar($id) @@ -170,4 +179,23 @@ class Calendar_ContentboxController extends StudipController $this->termine[] = $assignment; } } + + private function parseBeginAndEndFromDate($date): array + { + if ($date instanceof CalendarDateAssignment) { + return [ + $date->calendar_date->begin, + $date->calendar_date->end, + ]; + } + + if ($date instanceof CourseDate || $date instanceof CourseExDate) { + return [ + $date->date, + $date->end_time, + ]; + } + + throw new Exception('Invalid date type passed: ' . get_class($date)); + } } -- GitLab