From ea611ecd35d7adc989c622edba64ec51b32d63a5 Mon Sep 17 00:00:00 2001
From: Jan-Hendrik Willms <tleilax+studip@gmail.com>
Date: Thu, 4 Apr 2024 09:58:39 +0000
Subject: [PATCH] fixes #3940

Closes #3940

Merge request studip/studip!2799
---
 app/controllers/calendar/contentbox.php | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/app/controllers/calendar/contentbox.php b/app/controllers/calendar/contentbox.php
index 89b0ad32923..b684905c70d 100644
--- a/app/controllers/calendar/contentbox.php
+++ b/app/controllers/calendar/contentbox.php
@@ -91,17 +91,16 @@ class Calendar_ContentboxController extends StudipController
 
     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)
-- 
GitLab