aboutsummaryrefslogtreecommitdiff
path: root/app/controllers/calendar/contentbox.php
diff options
context:
space:
mode:
authorPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
committerPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
commit4459dd7917f4d1c34f40bb68f0e991e9c3d53e4c (patch)
tree5c07151ae61276d334e88f6309c30d439a85c12e /app/controllers/calendar/contentbox.php
parentda0022e5c1abbf9825ae76debaabdff7e8623bb4 (diff)
parent97a188592c679890a25c37ab78463add76a52ff7 (diff)
Merge branch 'main' into issue-3911issue-3911
Diffstat (limited to 'app/controllers/calendar/contentbox.php')
-rw-r--r--app/controllers/calendar/contentbox.php49
1 files changed, 38 insertions, 11 deletions
diff --git a/app/controllers/calendar/contentbox.php b/app/controllers/calendar/contentbox.php
index 8ba5215..b684905 100644
--- a/app/controllers/calendar/contentbox.php
+++ b/app/controllers/calendar/contentbox.php
@@ -78,21 +78,29 @@ 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)
{
- $course = Course::find($id);
- $this->termine = $course->getDatesWithExdates()->findBy('end_time', [$this->start, $this->start + $this->timespan], '><');
- foreach ($this->termine as $course_date) {
- if ($this->course_range) {
- //Display only date and time:
- $this->titles[$course_date->id] = $course_date->getFullName('include-room');
- } else {
- //Include the course title:
- $this->titles[$course_date->id] = $course_date->getFullName('verbose');
- }
- }
+ // Display only date and time if in course range, include course title
+ // otherwise
+ $date_format = $this->course_range ? 'include-room' : 'verbose';
+
+ $this->termine = Course::find($id)->getDatesWithExdates()
+ ->findBy('end_time', [$this->start, $this->start + $this->timespan], '><')
+ ->map(function ($course_date) use ($date_format) {
+ $this->titles[$course_date->id] = $course_date->getFullName($date_format);
+ return $course_date;
+ });
}
private function parseUser($id)
@@ -170,4 +178,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));
+ }
}