From ff94df53d69234ae2625462a76926e131ade05b7 Mon Sep 17 00:00:00 2001 From: msquare Date: Tue, 12 Dec 2017 21:57:57 +0100 Subject: finish basic public dashboard --- includes/model/Shifts_model.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'includes/model/Shifts_model.php') diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php index 1fc7fe89..b0d82a5b 100644 --- a/includes/model/Shifts_model.php +++ b/includes/model/Shifts_model.php @@ -26,6 +26,29 @@ function Shifts_by_angeltype($angeltype) { ', [$angeltype['id'], $angeltype['id']]); } +/** + * Returns every shift with needed angels in the given time range. + */ +function Shifts_free($start, $end) +{ + $shifts = Db::select(" + SELECT * + FROM `Shifts` + WHERE (`end` > ? AND `start` < ?) + AND (SELECT SUM(`count`) FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`) + > (SELECT COUNT(*) FROM `ShiftEntry` WHERE `ShiftEntry`.`SID`=`Shifts`.`SID` AND `freeloaded`=0) + ORDER BY `start` + ", [ + $start, + $end + ]); + $free_shifts = []; + foreach ($shifts as $shift) { + $free_shifts[] = Shift($shift['SID']); + } + return $free_shifts; +} + /** * Returns all shifts with a PSID (from frab import) */ -- cgit v1.2.3-54-g00ecf