summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2016-12-28 00:16:59 +0100
committermsquare <msquare@notrademark.de>2016-12-28 00:16:59 +0100
commit84527c22526b97ba1e84b200056a0c4f8e8ac0bc (patch)
tree66d9ef4ca2b5409c48e5211da08286b8bf95639f
parent65a665ee4919e6783fb9475f3acf652c0ff45b81 (diff)
redo
-rw-r--r--includes/model/Shifts_model.php34
1 files changed, 20 insertions, 14 deletions
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index eee8d9e9..5da15733 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -70,17 +70,15 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
}
function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
- $SQL = "SELECT `Shifts`.`SID` as `shift_id`,
- COALESCE(
- (SELECT `count` FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID` AND `NeededAngelTypes`.`angel_type_id`=`AngelTypes`.`id`),
- (SELECT `count` FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID` AND `NeededAngelTypes`.`angel_type_id`=`AngelTypes`.`id`)
- ) as `count`,
- `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
+ $SQL = "SELECT `NeededAngelTypes`.*, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
FROM `Shifts`
- JOIN `AngelTypes`
+ JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
+ JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
+ JOIN `NeededAngelTypes` AS nat_room ON `NeededAngelTypes`.`room_id`=`Shifts`.`RID`
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
ORDER BY `Shifts`.`start`";
+ // FIXME: Use needed angeltypes on rooms!
$result = sql_select($SQL);
if ($result === false) {
engelsystem_error("Unable to load needed angeltypes by filter.");
@@ -89,20 +87,28 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
}
function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) {
- $result = sql_select("SELECT `Shifts`.`SID` as `shift_id`,
- COALESCE(
- (SELECT `count` FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`shift_id`=`Shifts`.`SID` AND `NeededAngelTypes`.`angel_type_id`=`AngelTypes`.`id`),
- (SELECT `count` FROM `NeededAngelTypes` WHERE `NeededAngelTypes`.`room_id`=`Shifts`.`RID` AND `NeededAngelTypes`.`angel_type_id`=`AngelTypes`.`id`)
- ) as `count`,
- `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
+ $result = sql_select("SELECT `NeededAngelTypes`.*, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
FROM `Shifts`
- JOIN `AngelTypes`
+ JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
+ JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
WHERE `Shifts`.`SID`=" . sql_escape($shift['SID']) . "
AND `AngelTypes`.`id`=" . sql_escape($angeltype['id']) . "
ORDER BY `Shifts`.`start`");
if ($result === false) {
engelsystem_error("Unable to load needed angeltypes by filter.");
}
+ if (count($result) == 0) {
+ $result = sql_select("SELECT `NeededAngelTypes`.*, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
+ FROM `Shifts`
+ JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`room_id`=`Shifts`.`RID`
+ JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
+ WHERE `Shifts`.`SID`=" . sql_escape($shift['SID']) . "
+ AND `AngelTypes`.`id`=" . sql_escape($angeltype['id']) . "
+ ORDER BY `Shifts`.`start`");
+ if ($result === false) {
+ engelsystem_error("Unable to load needed angeltypes by filter.");
+ }
+ }
if(count($result) == 0) {
return null;
}