diff --git a/app/controllers/resources/room_request.php b/app/controllers/resources/room_request.php index b12da6b0c45e4a5f44d1fbb7624bfb5a643b8116..0d3b3a100f49cba47153753fb0a19244b70f6c62 100644 --- a/app/controllers/resources/room_request.php +++ b/app/controllers/resources/room_request.php @@ -300,23 +300,21 @@ class Resources_RoomRequestController extends AuthenticatedController $sql .= ' AND '; } $sql .= "( - (resource_requests.termin_id <> '' AND EXISTS (SELECT * FROM termine WHERE termine.termin_id=resource_requests.termin_id AND termine.date BETWEEN :semester_begin AND :semester_end)) + (resource_requests.termin_id <> '' AND EXISTS (SELECT * FROM termine WHERE termine.termin_id=resource_requests.termin_id AND termine.date BETWEEN :begin AND :semester_end)) OR - (resource_requests.metadate_id <> '' AND EXISTS (SELECT * FROM termine WHERE termine.metadate_id=resource_requests.metadate_id AND termine.date BETWEEN :semester_begin AND :semester_end)) + (resource_requests.metadate_id <> '' AND EXISTS (SELECT * FROM termine WHERE termine.metadate_id=resource_requests.metadate_id AND termine.date BETWEEN :begin AND :semester_end)) OR - (resource_requests.termin_id = '' AND resource_requests.metadate_id = '' AND EXISTS (SELECT * FROM termine WHERE termine.range_id=resource_requests.course_id AND termine.date BETWEEN :semester_begin AND :semester_end)) + (resource_requests.termin_id = '' AND resource_requests.metadate_id = '' AND EXISTS (SELECT * FROM termine WHERE termine.range_id=resource_requests.course_id AND termine.date BETWEEN :begin AND :semester_end)) "; if (!$this->filter['request_periods']) { $sql .= ' OR ( - ((CAST(resource_requests.begin AS SIGNED) - resource_requests.preparation_time) - BETWEEN :semester_begin AND :semester_end) - OR - (resource_requests.end BETWEEN :semester_begin AND :semester_end) + CAST(resource_requests.begin AS SIGNED) - resource_requests.preparation_time < :semester_end + AND resource_requests.end > :begin )'; } $sql .= ') '; - $sql_params['semester_begin'] = $semester->beginn; + $sql_params['begin'] = max($semester->beginn, time()); $sql_params['semester_end'] = $semester->ende; } } @@ -577,6 +575,7 @@ class Resources_RoomRequestController extends AuthenticatedController 'get' ); $semester_selector->setSelection($this->filter['semester']); + $semester_selector->setRange(time(), PHP_INT_MAX); $sidebar->addWidget($semester_selector); $request_status_selector = new SelectWidget( @@ -1471,12 +1470,12 @@ class Resources_RoomRequestController extends AuthenticatedController $this->request_time_intervals = [ '' => [ 'metadate' => null, - 'intervals' => $this->request->getTimeIntervals(true, true) + 'intervals' => $this->request->getTimeIntervals(true, true, false) ] ]; } else { //Get dates grouped by metadates. - $this->request_time_intervals = $this->request->getGroupedTimeIntervals(true); + $this->request_time_intervals = $this->request->getGroupedTimeIntervals(true, false); } $this->request_semester_string = ''; diff --git a/app/views/resources/room_request/resolve.php b/app/views/resources/room_request/resolve.php index 2347698c0e1f0b598eada9d0010cff9b3dd8389c..19bffc40efee52ba94f0479d05d7808926fc70ad 100644 --- a/app/views/resources/room_request/resolve.php +++ b/app/views/resources/room_request/resolve.php @@ -98,9 +98,11 @@ <? endif ?> <dt><?= _('Angeforderte Belegungszeiten') ?></dt> <dd> - <? $dates = $request->getDateString(true) ?> + <? $dates = $request->getDateString(true, false) ?> <? if ($dates) : ?> <?= implode('<br>', $dates) ?> + <? else : ?> + <?= _('Keine') ?> <? endif ?> </dd> <? if ($request->preparation_time) : ?> diff --git a/lib/classes/Seminar.class.php b/lib/classes/Seminar.class.php index 7f8886ca42b1e629d844faa968ecb03fe593e501..86546ceac075387d2184355b82723c4f41dcea42 100644 --- a/lib/classes/Seminar.class.php +++ b/lib/classes/Seminar.class.php @@ -330,6 +330,7 @@ class Seminar } $cycles[$id]['first_date'] = CycleDataDB::getFirstDate($id); + $cycles[$id]['last_date'] = CycleDataDB::getLastDate($id); if (!empty($cycles[$id]['assigned_rooms'])) { foreach ($cycles[$id]['assigned_rooms'] as $room_id => $count) { $rooms[$room_id] += $count; diff --git a/lib/models/resources/ResourceRequest.class.php b/lib/models/resources/ResourceRequest.class.php index bf882533eaf1e046e2c04c760a60158286353b94..beeff2a5902aaba2b1dd790e6512be15004eddd8 100644 --- a/lib/models/resources/ResourceRequest.class.php +++ b/lib/models/resources/ResourceRequest.class.php @@ -896,8 +896,9 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen * 'range_id' => The ID of the single date or ResourceRequestAppointment. * ] */ - public function getGroupedTimeIntervals($with_preparation_time = false) + public function getGroupedTimeIntervals($with_preparation_time = false, $with_past_intervals = true) { + $now = time(); if (count($this->appointments)) { $time_intervals = [ '' => [ @@ -906,6 +907,9 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen ] ]; foreach ($this->appointments as $appointment) { + if (!$with_past_intervals && $appointment->appointment->end_time < $now) { + continue; + } if ($with_preparation_time) { $interval = [ 'begin' => $appointment->appointment->date - $this->preparation_time, @@ -932,6 +936,9 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen return $time_intervals; } } elseif ($this->termin_id) { + if (!$with_past_intervals && $this->date->end_time < $now) { + return []; + } if ($with_preparation_time) { $interval = [ 'begin' => $this->date->date - $this->preparation_time, @@ -968,6 +975,9 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen ] ]; foreach ($this->cycle->dates as $date) { + if (!$with_past_intervals && $date->end_time < $now) { + continue; + } if ($with_preparation_time) { $interval = [ 'begin' => $date->date - $this->preparation_time, @@ -996,6 +1006,9 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen ]; if ($cycle->dates) { foreach ($cycle->dates as $date) { + if (!$with_past_intervals && $date->end_time < $now) { + continue; + } if ($with_preparation_time) { $interval = [ 'begin' => $date->date - $this->preparation_time, @@ -1022,6 +1035,9 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen 'intervals' => [] ]; foreach ($this->course->dates as $date) { + if (!$with_past_intervals && $date->end_time < $now) { + continue; + } if ($date->cycle instanceof SeminarCycleDate) { //Metadates are already handled above. continue; @@ -1050,6 +1066,9 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen } return $time_intervals; } elseif ($this->begin && $this->end) { + if (!$with_past_intervals && $this->end < $now) { + return []; + } if ($with_preparation_time) { $interval = [ 'begin' => $this->begin - $this->preparation_time, @@ -1087,6 +1106,10 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen * and its corresponding ID to the request (true) or not (false). * Defaults to false. * + * @param bool $with_past_intervals Whether to include past intervals (true) + * or only include intervals from the current time and the future (false). + * Defaults to true. + * * @return string[][] A two-dimensional array of unix timestamps. * The first dimension contains one entry for each date, * the second dimension contains the start and end timestamp @@ -1102,11 +1125,15 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen * that are not bound to a course. The range "CourseDate" * can only occur on course-bound requests. */ - public function getTimeIntervals($with_preparation_time = false, $with_range = false) + public function getTimeIntervals($with_preparation_time = false, $with_range = false, $with_past_intervals = true) { + $now = time(); if (count($this->appointments)) { $time_intervals = []; foreach ($this->appointments as $appointment) { + if (!$with_past_intervals && $appointment->appointment->end_time < $now) { + continue; + } if ($with_preparation_time) { $interval = [ 'begin' => $appointment->appointment->date - $this->preparation_time, @@ -1131,6 +1158,9 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen } return $time_intervals; } elseif ($this->termin_id) { + if (!$with_past_intervals && $this->date->end_time < $now) { + return []; + } if ($with_preparation_time) { $interval = [ 'begin' => $this->date->date - $this->preparation_time, @@ -1152,6 +1182,9 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen } elseif ($this->metadate_id) { $time_intervals = []; foreach ($this->cycle->dates as $date) { + if (!$with_past_intervals && $date->end_time < $now) { + continue; + } if ($with_preparation_time) { $interval = [ 'begin' => $date->date - $this->preparation_time, @@ -1176,6 +1209,9 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen $time_intervals = []; if ($this->course->dates) { foreach ($this->course->dates as $date) { + if (!$with_past_intervals && $date->end_time < $now) { + continue; + } if ($with_preparation_time) { $interval = [ 'begin' => $date->date - $this->preparation_time, @@ -1198,6 +1234,9 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen } return $time_intervals; } elseif ($this->begin && $this->end) { + if (!$with_past_intervals && $this->end < $now) { + return []; + } if ($with_preparation_time) { $interval = [ 'begin' => $this->begin - $this->preparation_time, @@ -1357,12 +1396,16 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen * is returned as one string or as an array of strings for each date * (single or cycle date). */ - public function getDateString($as_array = false) + public function getDateString($as_array = false, $with_past_intervals = true) { + $now = time(); $strings = []; if (count($this->appointments)) { $parts = []; foreach ($this->appointments as $rra) { + if (!$with_past_intervals && $rra->appointment->end_time < $now) { + continue; + } if ($rra->appointment) { $parts[] = $rra->appointment->getFullname('include-room'); } @@ -1370,11 +1413,15 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen $strings[] = implode('; ', $parts); } elseif ($this->termin_id) { if ($this->date) { - $strings[] = $this->date->getFullname('include-room'); + if ($with_past_intervals || $this->date->end_time >= $now) { + $strings[] = $this->date->getFullname('include-room'); + } } } elseif ($this->metadate_id) { if ($this->cycle) { - $this->cycle->dates->map(function($date) use(&$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'); }); } @@ -1384,7 +1431,8 @@ class ResourceRequest extends SimpleORMap implements PrivacyObject, Studip\Calen $strings[] = $course->getDatesTemplate('dates/seminar_html_roomplanning', [ 'shrink' => false, - 'show_room' => true + 'show_room' => true, + 'with_past_intervals' => $with_past_intervals ] ); } diff --git a/lib/raumzeit/CycleDataDB.class.php b/lib/raumzeit/CycleDataDB.class.php index ea32a70d3ca4cf053d2c3656248c9c62c4c8e2fc..020919c047d1e32f39c19f3fc1f24b67262fd7c7 100644 --- a/lib/raumzeit/CycleDataDB.class.php +++ b/lib/raumzeit/CycleDataDB.class.php @@ -249,4 +249,24 @@ class CycleDataDB $statement->execute([$metadate_id]); return $statement->fetch(PDO::FETCH_ASSOC); } + + + /** + * returns the last date for a given metadate_id as array + * + * @param string $metadate_id + * + * @return array + */ + public static function getLastDate($metadate_id) + { + $query = "SELECT * + FROM termine + WHERE metadate_id = ? + ORDER BY `date` DESC + LIMIT 1"; + $statement = DBManager::get()->prepare($query); + $statement->execute([$metadate_id]); + return $statement->fetch(PDO::FETCH_ASSOC); + } } diff --git a/templates/dates/seminar_html_roomplanning.php b/templates/dates/seminar_html_roomplanning.php index f95ccbbc2fb8e100d39d57e06af925cf3f962e04..60beec2311b88293167e7e1a680b364ddee29711 100644 --- a/templates/dates/seminar_html_roomplanning.php +++ b/templates/dates/seminar_html_roomplanning.php @@ -8,10 +8,16 @@ if (!isset($show_room)) : endif; endif; +$now = time(); + if (!empty($dates['regular']['turnus_data']) || !empty($dates['irregular'])) : $output = []; if (is_array($dates['regular']['turnus_data'])) foreach ($dates['regular']['turnus_data'] as $cycle) : $first_date = sprintf(_("ab %s"), strftime('%x', $cycle['first_date']['date'])); + $last_date = $cycle['last_date']['date']; + if (empty($with_past_intervals) && $last_date < $now) { + continue; + } if ($cycle['cycle'] == 1) : $cycle_output = $cycle['tostring_short'] . ' (' . sprintf(_("zweiwöchentlich, %s"), $first_date) . ')'; elseif ($cycle['cycle'] == 2) : @@ -41,6 +47,9 @@ if (!empty($dates['regular']['turnus_data']) || !empty($dates['irregular'])) : if (is_array($dates['irregular'])): foreach ($dates['irregular'] as $date) : + if (empty($with_past_intervals) && $date->end_time < $now) { + continue; + } $irregular[] = $date; $irregular_strings[] = $date['tostring']; if ($date['resource_id']) : @@ -57,6 +66,9 @@ if (!empty($dates['regular']['turnus_data']) || !empty($dates['irregular'])) : if (is_array($irregular) && count($irregular)) : if (isset($shrink) && !$shrink && count($irregular) < 20) : foreach ($irregular as $date) : + if (empty($with_past_intervals) && $date->end_time < $now) { + continue; + } echo $date['tostring']; if ($show_room && $date['resource_id']) :