summaryrefslogtreecommitdiff
path: root/includes/model/Shifts_model.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/model/Shifts_model.php')
-rw-r--r--includes/model/Shifts_model.php23
1 files changed, 23 insertions, 0 deletions
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
@@ -27,6 +27,29 @@ function Shifts_by_angeltype($angeltype) {
}
/**
+ * 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)
*/
function Shifts_from_frab() {