bring back needed angeltypes from rooms

main
msquare 8 years ago
parent 860252bce8
commit aed9f2c96c

@ -70,14 +70,17 @@ function Shifts_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
} }
function NeededAngeltypes_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` FROM `Shifts`
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID` JOIN `AngelTypes`
JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ") WHERE `Shifts`.`RID` IN (" . implode(',', $shiftsFilter->getRooms()) . ")
AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . " AND `start` BETWEEN " . $shiftsFilter->getStartTime() . " AND " . $shiftsFilter->getEndTime() . "
ORDER BY `Shifts`.`start`"; ORDER BY `Shifts`.`start`";
// FIXME: Use needed angeltypes on rooms!
$result = sql_select($SQL); $result = sql_select($SQL);
if ($result === false) { if ($result === false) {
engelsystem_error("Unable to load needed angeltypes by filter."); engelsystem_error("Unable to load needed angeltypes by filter.");
@ -86,15 +89,17 @@ function NeededAngeltypes_by_ShiftsFilter(ShiftsFilter $shiftsFilter, $user) {
} }
function NeededAngeltype_by_Shift_and_Angeltype($shift, $angeltype) { 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` FROM `Shifts`
JOIN `NeededAngelTypes` ON `NeededAngelTypes`.`shift_id`=`Shifts`.`SID` JOIN `AngelTypes`
JOIN `AngelTypes` ON `AngelTypes`.`id`= `NeededAngelTypes`.`angel_type_id`
WHERE `Shifts`.`SID`=" . sql_escape($shift['SID']) . " WHERE `Shifts`.`SID`=" . sql_escape($shift['SID']) . "
AND `AngelTypes`.`id`=" . sql_escape($angeltype['id']) . " AND `AngelTypes`.`id`=" . sql_escape($angeltype['id']) . "
ORDER BY `Shifts`.`start`"; ORDER BY `Shifts`.`start`");
// FIXME: Use needed angeltypes on rooms!
$result = sql_select($SQL);
if ($result === false) { if ($result === false) {
engelsystem_error("Unable to load needed angeltypes by filter."); engelsystem_error("Unable to load needed angeltypes by filter.");
} }

Loading…
Cancel
Save