summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2016-12-28 00:02:55 +0100
committermsquare <msquare@notrademark.de>2016-12-28 00:02:55 +0100
commitaed9f2c96c922d7a0c6b3515d0f89d25e567e5cd (patch)
treedf1dd5bcefe2f84c0c020515018553fe8c3e9ee7 /includes
parent860252bce80f1e0b030b951c51a56f33a5a6b6b3 (diff)
bring back needed angeltypes from rooms
Diffstat (limited to 'includes')
-rw-r--r--includes/model/Shifts_model.php27
1 files changed, 16 insertions, 11 deletions
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index 5565ba92..eee8d9e9 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -70,14 +70,17 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
}
function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
- $SQL = "SELECT `NeededAngelTypes`.*, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
+ $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`
FROM `Shifts`
- JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
- JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
+ JOIN `AngelTypes`
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.");
@@ -86,19 +89,21 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
}
function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) {
- $SQL = "SELECT `NeededAngelTypes`.*, `AngelTypes`.`id`, `AngelTypes`.`name`, `AngelTypes`.`restricted`, `AngelTypes`.`no_self_signup`
+ $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`
FROM `Shifts`
- JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID`
- JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
+ JOIN `AngelTypes`
WHERE `Shifts`.`SID`=" . sql_escape($shift['SID']) . "
AND `AngelTypes`.`id`=" . sql_escape($angeltype['id']) . "
- ORDER BY `Shifts`.`start`";
- // FIXME: Use needed angeltypes on rooms!
- $result = sql_select($SQL);
+ ORDER BY `Shifts`.`start`");
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];