aboutsummaryrefslogtreecommitdiff
path: root/lib/models/resources
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2024-11-13 15:36:27 +0000
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2024-11-13 16:39:55 +0100
commit83f3e31b37024bab5fc2b29434e648192ebd6e3a (patch)
tree1862302bcc102a22a2baf5028576ccc0e09906cd /lib/models/resources
parent79c4b2993856e617a3d48eab086a3d278adda9ae (diff)
sort resource request appointments when converting to readable strings, fixes #4856
Closes #4856 Merge request studip/studip!3639
Diffstat (limited to 'lib/models/resources')
-rw-r--r--lib/models/resources/ResourceRequest.class.php38
1 files changed, 26 insertions, 12 deletions
diff --git a/lib/models/resources/ResourceRequest.class.php b/lib/models/resources/ResourceRequest.class.php
index beda227..d7d0b45 100644
--- a/lib/models/resources/ResourceRequest.class.php
+++ b/lib/models/resources/ResourceRequest.class.php
@@ -1452,17 +1452,31 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen
$now = time();
$strings = [];
$resource_name = '';
- if (count($this->appointments)) {
- $parts = [];
- foreach ($this->appointments as $rra) {
- if (!$with_past_intervals && $rra->appointment->end_time < $now) {
- continue;
+ if (count($this->appointments) > 0) {
+ // Filter invalid/not matching items
+ $appointments = $this->appointments->filter(
+ function (ResourceRequestAppointment $appointment) use ($with_past_intervals, $now): bool {
+ if (!$appointment->appointment) {
+ return false;
+ }
+ return $with_past_intervals
+ || $appointment->appointment->end_time > $now;
}
- if ($rra->appointment) {
- $parts[] = $rra->appointment->getFullname('include-room');
+ );
+
+ // Sort by appointment date
+ $appointments->uasort(
+ function (ResourceRequestAppointment $a, ResourceRequestAppointment $b): int {
+ return $a->appointment->date - $b->appointment->date;
}
- }
- $strings[] = implode('; ', $parts);
+ );
+
+ // Get readable string for each appointment
+ $strings = $appointments->map(
+ function (ResourceRequestAppointment $appointment): string {
+ return $appointment->appointment->getFullName('include-room');
+ },
+ );
} elseif ($this->termin_id) {
if ($this->date) {
if ($with_past_intervals || $this->date->end_time >= $now) {
@@ -1471,10 +1485,10 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen
}
} elseif ($this->metadate_id) {
if ($this->cycle) {
- $this->cycle->dates->filter(function($date) use($with_past_intervals, $now) {
+ $strings = $this->cycle->dates->filter(function ($date) use($with_past_intervals, $now) {
return $with_past_intervals || $date->end_time >= $now;
- })->map(function($date) use(&$strings) {
- $strings[] = $date->getFullname('include-room');
+ })->map(function($date) {
+ return $date->getFullName('include-room');
});
}
} elseif ($this->course_id) {