From ead2b1582b2a5a2de7f3fec82284f2c35cafb4d4 Mon Sep 17 00:00:00 2001 From: msquare Date: Sat, 17 Aug 2019 18:46:03 +0200 Subject: add overnight shift creation feature flag --- includes/pages/admin_shifts.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) (limited to 'includes/pages/admin_shifts.php') diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index 511dc5ca..30ea4773 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -28,6 +28,8 @@ function admin_shifts() $change_hours = []; $title = ''; $shifttype_id = null; + // When true: creates a shift beginning at the last shift change hour and ending at the first shift change hour + $shift_over_midnight = true; // Locations laden $rooms = Rooms(); @@ -127,6 +129,7 @@ function admin_shifts() $valid = false; error(__('Please split the shift-change hours by colons.')); } + $shift_over_midnight = $request->has('shift_over_midnight'); } } else { $valid = false; @@ -220,7 +223,7 @@ function admin_shifts() } }); - // Chronologisch absteigend sortieren + // Chronologisch absteigend sortieren (WHY???) usort($change_hours, function ($a, $b) { return str_replace(':', '', $a) > str_replace(':', '', $b) ? -1 : 1; }); @@ -263,16 +266,21 @@ function admin_shifts() } } - $shifts[] = [ - 'start' => $shift_start, - 'end' => $shift_end, - 'RID' => $rid, - 'title' => $title, - 'shifttype_id' => $shifttype_id - ]; + if($shift_over_midnight || $day == parse_date('Y-m-d H:i', date('Y-m-d', $shift_end) . ' 00:00')) { + $shifts[] = [ + 'start' => $shift_start, + 'end' => $shift_end, + 'RID' => $rid, + 'title' => $title, + 'shifttype_id' => $shifttype_id + ]; + } $shift_start = $shift_end; - $change_index = ($change_index + count($change_hours) - 1) % count($change_hours); + $change_index--; + if($change_index < 0) { + $change_index = count($change_hours) - 1; + } } while ($shift_end < $end); } @@ -431,6 +439,11 @@ function admin_shifts() $request->has('change_hours') ? $request->input('input') : '00, 04, 08, 10, 12, 14, 16, 18, 20, 22' + ), + form_checkbox( + 'shift_over_midnight', + __('Create a shift over midnight.'), + $shift_over_midnight ) ]), div('col-md-6', [ -- cgit v1.2.3-54-g00ecf