Skip to content
Snippets Groups Projects
Commit fb156f20 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms
Browse files

sort resource request appointments when converting to readable strings, fixes #4856

Closes #4856

Merge request studip/studip!3639
parent 72907756
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @var ResourceRequest $request
*/
?>
<dl> <dl>
<dt><?= _('Termine') ?>:</dt> <dt><?= _('Termine') ?>:</dt>
<dd><?= $request->getDateString() ?></dd> <dd><?= $request->getDateString() ?></dd>
......
...@@ -1452,17 +1452,31 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen ...@@ -1452,17 +1452,31 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen
$now = time(); $now = time();
$strings = []; $strings = [];
$resource_name = ''; $resource_name = '';
if (count($this->appointments)) { if (count($this->appointments) > 0) {
$parts = []; // Filter invalid/not matching items
foreach ($this->appointments as $rra) { $appointments = $this->appointments->filter(
if (!$with_past_intervals && $rra->appointment->end_time < $now) { function (ResourceRequestAppointment $appointment) use ($with_past_intervals, $now): bool {
continue; 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) { } elseif ($this->termin_id) {
if ($this->date) { if ($this->date) {
if ($with_past_intervals || $this->date->end_time >= $now) { if ($with_past_intervals || $this->date->end_time >= $now) {
...@@ -1471,10 +1485,10 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen ...@@ -1471,10 +1485,10 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen
} }
} elseif ($this->metadate_id) { } elseif ($this->metadate_id) {
if ($this->cycle) { 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; return $with_past_intervals || $date->end_time >= $now;
})->map(function($date) use(&$strings) { })->map(function($date) {
$strings[] = $date->getFullName('include-room'); return $date->getFullName('include-room');
}); });
} }
} elseif ($this->course_id) { } elseif ($this->course_id) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment