From 71d9077a03671bafd3d81be04d61ad0af17fe96c Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Mon, 4 Oct 2021 01:44:02 +0200 Subject: [PATCH] Admin free: Only generate query on search --- includes/pages/admin_free.php | 55 ++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/includes/pages/admin_free.php b/includes/pages/admin_free.php index fcfd7323..5c767c06 100644 --- a/includes/pages/admin_free.php +++ b/includes/pages/admin_free.php @@ -33,37 +33,38 @@ function admin_free() } $angelType = $request->input('angeltype', ''); - $query = User::with('personalData') - ->select('users.*') - ->leftJoin('ShiftEntry', 'users.id', 'ShiftEntry.UID') - ->leftJoin('users_state', 'users.id', 'users_state.user_id') - ->leftJoin('Shifts', function ($join) { - /** @var JoinClause $join */ - $join->on('ShiftEntry.SID', '=', 'Shifts.SID') - ->where('Shifts.start', '<', time()) - ->where('Shifts.end', '>', time()); - }) - ->where('users_state.arrived', '=', 1) - ->whereNull('Shifts.SID') - ->orderBy('users.name') - ->groupBy('users.id'); - - if (!empty($angelType)) { - $query->join('UserAngelTypes', function ($join) use ($angelType) { - /** @var JoinClause $join */ - $join->on('UserAngelTypes.user_id', '=', 'users.id') - ->where('UserAngelTypes.angeltype_id', '=', $angelType); - }); - $query->join('AngelTypes', 'UserAngelTypes.angeltype_id', 'AngelTypes.id') - ->whereNotNull('UserAngelTypes.confirm_user_id') - ->orWhere('AngelTypes.restricted', '=', '0'); - } + $users = []; if ($request->has('submit')) { + $query = User::with('personalData') + ->select('users.*') + ->leftJoin('ShiftEntry', 'users.id', 'ShiftEntry.UID') + ->leftJoin('users_state', 'users.id', 'users_state.user_id') + ->leftJoin('Shifts', function ($join) { + /** @var JoinClause $join */ + $join->on('ShiftEntry.SID', '=', 'Shifts.SID') + ->where('Shifts.start', '<', time()) + ->where('Shifts.end', '>', time()); + }) + ->where('users_state.arrived', '=', 1) + ->whereNull('Shifts.SID') + ->orderBy('users.name') + ->groupBy('users.id'); + + if (!empty($angelType)) { + $query->join('UserAngelTypes', function ($join) use ($angelType) { + /** @var JoinClause $join */ + $join->on('UserAngelTypes.user_id', '=', 'users.id') + ->where('UserAngelTypes.angeltype_id', '=', $angelType); + }); + $query->join('AngelTypes', 'UserAngelTypes.angeltype_id', 'AngelTypes.id') + ->whereNotNull('UserAngelTypes.confirm_user_id') + ->orWhere('AngelTypes.restricted', '=', '0'); + } + $users = $query->get(); - } else { - $users = []; } + $free_users_table = []; if ($search == '') { $tokens = [];