summaryrefslogtreecommitdiff
path: root/includes/model/Shifts_model.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2016-12-29 14:16:00 +0100
committermsquare <msquare@notrademark.de>2016-12-29 14:16:00 +0100
commit68aeb14edbcefc66e49865df2665cbca0a135e3b (patch)
tree1ea08f3a0ea8692ca46cb46553a0b1916d161386 /includes/model/Shifts_model.php
parent5600476c5649a79a8c6f385b58df3bf7888535d0 (diff)
bring back filtering by angeltype
Diffstat (limited to 'includes/model/Shifts_model.php')
-rw-r--r--includes/model/Shifts_model.php26
1 files changed, 23 insertions, 3 deletions
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index e7a93345..07467103 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -11,13 +11,33 @@ function Shifts_by_room($room) {
}
function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter) {
- $SQL = "SELECT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`
+ $SQL = "SELECT * FROM (
+ SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`
FROM `Shifts`
JOIN `Room` USING (`RID`)
JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id`
+ JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
- ORDER BY `Shifts`.`start`";
+ AND `NeededAngelTypes`.`angel_type_id` IN (" . implode(',', $shiftsFilter->getTypes()) . ")
+ AND `NeededAngelTypes`.`count` > 0
+ AND `Shifts`.`PSID` IS NULL
+
+ UNION
+
+ SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`
+ FROM `Shifts`
+ JOIN `Room` USING (`RID`)
+ JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id`
+ JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`room_id`=`Shifts`.`RID`
+ WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
+ AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
+ AND `NeededAngelTypes`.`angel_type_id` IN (" . implode(',', $shiftsFilter->getTypes()) . ")
+ AND `NeededAngelTypes`.`count` > 0
+ AND NOT `Shifts`.`PSID` IS NULL) as tmp_shifts
+
+ ORDER BY `start`
+ ";
/**
* $SQL = "SELECT DISTINCT `Shifts`.*, `ShiftTypes`.`name`, `Room`.`Name` as `room_name`
* FROM `Shifts`
@@ -115,7 +135,7 @@ function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) {
if ($result === false) {
engelsystem_error("Unable to load needed angeltypes by filter.");
}
- if(count($result) == 0) {
+ if (count($result) == 0) {
return null;
}
return $result[0];