From 0b6b806bd3fbca590742af7003b479903ae36b67 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms Date: Fri, 13 Feb 2026 13:41:38 +0100 Subject: allow api to return non-html, re #6258 Merge request studip/studip!4734 --- app/controllers/admin/courses.php | 7 ++++++- lib/classes/AdminCourseFilter.php | 2 +- lib/classes/CourseDateList.php | 9 +++++++-- lib/models/SeminarCycleDate.php | 16 +++++++++------- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/controllers/admin/courses.php b/app/controllers/admin/courses.php index c1df335..a6c4bab 100644 --- a/app/controllers/admin/courses.php +++ b/app/controllers/admin/courses.php @@ -1006,7 +1006,12 @@ class Admin_CoursesController extends AuthenticatedController if (in_array('room_time', $filter_config)) { $dates = $course->getAllDatesInSemester($this->semester); - $row['room_time'] = strip_tags(implode("\n", $dates->toStringArray(true))) ?: _('nicht angegeben'); + $date_strings = $dates->toStringArray( + group_by_rooms: true, + as_html: false + ); + + $row['room_time'] = implode("\n", $date_strings) ?: _('nicht angegeben'); } if (in_array('requests', $filter_config)) { diff --git a/lib/classes/AdminCourseFilter.php b/lib/classes/AdminCourseFilter.php index bdb84d2..6d89231 100644 --- a/lib/classes/AdminCourseFilter.php +++ b/lib/classes/AdminCourseFilter.php @@ -173,7 +173,7 @@ class AdminCourseFilter * Also saves the settings in the session. * Note that a notification AdminCourseFilterWillQuery will be posted, before the result is computed. * Plugins may register at this event to fully alter this AdminCourseFilter-object and so the resultset. - * @return array associative array with seminar_ids as keys and seminar-data-arrays as values. + * @return Course[] */ public function getCourses() { diff --git a/lib/classes/CourseDateList.php b/lib/classes/CourseDateList.php index 5aa1a02..0b9854f 100644 --- a/lib/classes/CourseDateList.php +++ b/lib/classes/CourseDateList.php @@ -236,11 +236,16 @@ class CourseDateList implements Stringable return $template->render(); } - public function toStringArray(bool $group_by_rooms = false, bool $with_room_names = false, bool $with_cancelled_dates = false) : array + public function toStringArray( + bool $group_by_rooms = false, + bool $with_room_names = false, + bool $with_cancelled_dates = false, + bool $as_html = true + ) : array { $output = []; foreach ($this->regular_dates as $regular_date) { - $date_line = $regular_date->toString('long-start'); + $date_line = $regular_date->toString('long-start', $as_html); if ($with_room_names || $group_by_rooms) { $room = $regular_date->getMostBookedRoom(); if ($room instanceof Room) { diff --git a/lib/models/SeminarCycleDate.php b/lib/models/SeminarCycleDate.php index e400665..9293faf 100644 --- a/lib/models/SeminarCycleDate.php +++ b/lib/models/SeminarCycleDate.php @@ -214,7 +214,7 @@ class SeminarCycleDate extends SimpleORMap * * @returns string The formatted string. */ - public function toString(string $format = 'short') : string + public function toString(string $format = 'short', bool $as_html = true) : string { if (!in_array($format, ['short', 'long', 'long-start', 'full'])) { //Invalid format: @@ -245,18 +245,20 @@ class SeminarCycleDate extends SimpleORMap $text = _('%{weekday}, %{beginning} - %{end}, %{interval}'); $room = $this->getMostBookedRoom(); - if ($room) { + if (!$room) { + //Use the freetext room name: + $room = $this->getMostUsedFreetextRoomName(); + if ($room) { + $parameters['room_name'] = $room; + } + } elseif ($as_html) { $parameters['room_name'] = sprintf( '%2$s', $room->getActionLink(), htmlReady($room->name) ); } else { - //Use the freetext room name: - $room = $this->getMostUsedFreetextRoomName(); - if ($room) { - $parameters['room_name'] = $room; - } + $parameters['room_name'] = $room->name; } $first_date = $this->getFirstDate(); if ($first_date) { -- cgit v1.0