Shifts filter: Only show rooms with shifts
This commit is contained in:
parent
983fb988b4
commit
8bb8837e38
|
@ -4,6 +4,8 @@ use Engelsystem\Database\Db;
|
|||
use Engelsystem\Helpers\Carbon;
|
||||
use Engelsystem\Models\AngelType;
|
||||
use Engelsystem\Models\Room;
|
||||
use Engelsystem\Models\Shifts\NeededAngelType;
|
||||
use Engelsystem\Models\Shifts\Shift;
|
||||
use Engelsystem\Models\UserAngelType;
|
||||
use Engelsystem\ShiftsFilter;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
@ -113,9 +115,26 @@ function update_ShiftsFilter(ShiftsFilter $shiftsFilter, $user_shifts_admin, $da
|
|||
/**
|
||||
* @return Room[]|Collection
|
||||
*/
|
||||
function load_rooms()
|
||||
function load_rooms(bool $onlyWithActiveShifts = false)
|
||||
{
|
||||
$rooms = Room::orderBy('name')->get();
|
||||
$rooms = Room::orderBy('name');
|
||||
|
||||
if ($onlyWithActiveShifts) {
|
||||
$roomIdsFromAngelType = NeededAngelType::query()
|
||||
->whereNotNull('room_id')
|
||||
->select('room_id');
|
||||
|
||||
$roomIdsFromShift = Shift::query()
|
||||
->leftJoin('needed_angel_types', 'shifts.id', 'needed_angel_types.shift_id')
|
||||
->whereNotNull('needed_angel_types.shift_id')
|
||||
->select('shifts.room_id');
|
||||
|
||||
$rooms->whereIn('id', $roomIdsFromAngelType)
|
||||
->orWhereIn('id', $roomIdsFromShift);
|
||||
}
|
||||
|
||||
$rooms = $rooms->get();
|
||||
|
||||
if ($rooms->isEmpty()) {
|
||||
error(__('The administration has not configured any rooms yet.'));
|
||||
throw_redirect(page_link_to('/'));
|
||||
|
@ -210,7 +229,7 @@ function view_user_shifts()
|
|||
|
||||
$session = session();
|
||||
$days = load_days();
|
||||
$rooms = load_rooms();
|
||||
$rooms = load_rooms(true);
|
||||
$types = load_types();
|
||||
$ownAngelTypes = [];
|
||||
|
||||
|
|
Loading…
Reference in New Issue