diff --git a/includes/model/NeededAngelTypes_model.php b/includes/model/NeededAngelTypes_model.php index 8cd857b6..9e86c5a6 100644 --- a/includes/model/NeededAngelTypes_model.php +++ b/includes/model/NeededAngelTypes_model.php @@ -10,20 +10,29 @@ function NeededAngelTypes_by_shift($shift) { SELECT `NeededAngelTypes`.*, `AngelTypes`.`name`, `AngelTypes`.`restricted` FROM `NeededAngelTypes` JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id` - WHERE (`shift_id`=" . sql_escape($shift['SID']) . " - OR `room_id`=" . sql_escape($shift['RID']) . ") + WHERE `shift_id`=" . sql_escape($shift['SID']) . " AND `count` > 0 ORDER BY `room_id` DESC "); if ($needed_angeltypes_source === false) return false; - - $needed_angeltypes_merged = array(); - foreach ($needed_angeltypes_source as $angeltype) - $needed_angeltypes_merged[$angeltype['id']] = $angeltype; + + // Use settings from room + if (count($needed_angeltypes_source) == 0) { + $needed_angeltypes_source = sql_select(" + SELECT `NeededAngelTypes`.*, `AngelTypes`.`name`, `AngelTypes`.`restricted` + FROM `NeededAngelTypes` + JOIN `AngelTypes` ON `AngelTypes`.`id` = `NeededAngelTypes`.`angel_type_id` + WHERE `room_id`=" . sql_escape($shift['RID']) . " + AND `count` > 0 + ORDER BY `room_id` DESC + "); + if ($needed_angeltypes_source === false) + return false; + } $needed_angeltypes = array(); - foreach ($needed_angeltypes_merged as $angeltype) { + foreach ($needed_angeltypes_source as $angeltype) { $shift_entries = ShiftEntries_by_shift_and_angeltype($shift['SID'], $angeltype['id']); if ($shift_entries === false) return false;