diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index e5fd27ef..206a1586 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -37,8 +37,18 @@ function user_shifts() { * The shiftfilter to update. */ function update_ShiftsFilter_timerange(ShiftsFilter $shiftsFilter, $days) { - $shiftsFilter->setStartTime(check_request_datetime('start_day', 'start_time', $days, time())); - $shiftsFilter->setEndTime(check_request_datetime('end_day', 'end_time', $days, time() + 24 * 60 * 60)); + $start_time = $shiftsFilter->getStartTime(); + if ($start_time == null) { + $start_time = time(); + } + + $end_time = $shiftsFilter->getEndTime(); + if ($end_time == null) { + $end_time = $start_time + 24 * 60 * 60; + } + + $shiftsFilter->setStartTime(check_request_datetime('start_day', 'start_time', $days, $start_time)); + $shiftsFilter->setEndTime(check_request_datetime('end_day', 'end_time', $days, $end_time)); if ($shiftsFilter->getStartTime() > $shiftsFilter->getEndTime()) { $shiftsFilter->setEndTime($shiftsFilter->getStartTime() + 24 * 60 * 60); @@ -57,18 +67,10 @@ function update_ShiftsFilter_timerange(ShiftsFilter $shiftsFilter, $days) { */ function update_ShiftsFilter(ShiftsFilter $shiftsFilter, $user_shifts_admin, $days) { $shiftsFilter->setUserShiftsAdmin($user_shifts_admin); - if (isset($_REQUEST['filled'])) { - $shiftsFilter->setFilled(check_request_int_array('filled')); - } - if (isset($_REQUEST['rooms'])) { - $shiftsFilter->setRooms(check_request_int_array('rooms')); - } - if (isset($_REQUEST['types'])) { - $shiftsFilter->setTypes(check_request_int_array('types')); - } - if ((isset($_REQUEST['start_time']) && isset($_REQUEST['start_day']) && isset($_REQUEST['end_time']) && isset($_REQUEST['end_day'])) || $shiftsFilter->getStartTime() == null || $shiftsFilter->getEndTime() == null) { - update_ShiftsFilter_timerange($shiftsFilter, $days); - } + $shiftsFilter->setFilled(check_request_int_array('filled', $shiftsFilter->getFilled())); + $shiftsFilter->setRooms(check_request_int_array('rooms', $shiftsFilter->getRooms())); + $shiftsFilter->setTypes(check_request_int_array('types', $shiftsFilter->getTypes())); + update_ShiftsFilter_timerange($shiftsFilter, $days); } function load_rooms() { diff --git a/includes/sys_page.php b/includes/sys_page.php index 713dd33b..102be926 100644 --- a/includes/sys_page.php +++ b/includes/sys_page.php @@ -89,12 +89,14 @@ function select_array($data, $key_name, $value_name) { * * @param String $name * Name of the request param + * @param array $default + * Default return value, if param is not set */ -function check_request_int_array($name) { +function check_request_int_array($name, $default = []) { if (isset($_REQUEST[$name]) && is_array($_REQUEST[$name])) { return array_filter($_REQUEST[$name], 'is_numeric'); } - return []; + return $default; } /** diff --git a/includes/view/ShiftCalendarRenderer.php b/includes/view/ShiftCalendarRenderer.php index 151a39e0..d25f4048 100644 --- a/includes/view/ShiftCalendarRenderer.php +++ b/includes/view/ShiftCalendarRenderer.php @@ -19,7 +19,7 @@ class ShiftCalendarRenderer { * Distance between two shifts in pixels */ const MARGIN = 5; - + /** * Seconds added to the start and end time */ @@ -56,12 +56,12 @@ class ShiftCalendarRenderer { foreach ($shifts as $shift) { $room_id = $shift['RID']; + $header = Room_name_render([ + 'RID' => $room_id, + 'Name' => $shift['room_name'] + ]); if (! isset($lanes[$room_id])) { // initialize room with one lane - $header = Room_name_render([ - 'RID' => $room_id, - 'Name' => $shift['room_name'] - ]); $lanes[$room_id] = [ new ShiftCalendarLane($header, $this->getFirstBlockStartTime(), $this->getBlocksPerSlot()) ]; @@ -108,6 +108,9 @@ class ShiftCalendarRenderer { * @return the generated html */ public function render() { + if (count($this->lanes) == 0) { + return ''; + } return div('shift-calendar', [ $this->renderTimeLane(), $this->renderShiftLanes()