diff --git a/app/Http/Controllers/InviteController.php b/app/Http/Controllers/InviteController.php index a3882e1e..3cc693cb 100644 --- a/app/Http/Controllers/InviteController.php +++ b/app/Http/Controllers/InviteController.php @@ -15,8 +15,6 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; -use Illuminate\Pagination\LengthAwarePaginator; -use Illuminate\Pagination\Paginator; use Inertia\Inertia; use Inertia\Response; @@ -27,7 +25,6 @@ public function index(Quiz $quiz, SortHelper $sort, Request $request): Response $this->authorize("invite", $quiz); $query = User::query()->role("user")->with("school")->whereNotNull("email_verified_at"); - $query = $this->groupBySchool($query, $request); $query = $sort->sort($query, ["id"], ["name", "school"]); $query = $this->sortByName($query, $sort); $query = $this->sortBySchool($query, $sort); @@ -41,23 +38,6 @@ public function index(Quiz $quiz, SortHelper $sort, Request $request): Response ]); } - protected function groupBySchool(Builder $query, Request $request): Builder { - $groupBySchool = $request->query('groupBySchool', 'false'); - - if ($groupBySchool !== 'true') { - return $query; - } - - $schoolIds = School::query() - ->select('id') - ->join('users', 'schools.id', '=', 'users.school_id') - ->groupBy('schools.id') - ->orderBy('schools.id') - ->pluck('id'); - - return $query->whereIn('school_id', $schoolIds)->orderBy('school_id'); - } - public function assign(Quiz $quiz, InviteQuizRequest $request, AssignToQuizAction $assignAction): RedirectResponse { $this->authorize("invite", $quiz); @@ -80,6 +60,24 @@ public function unassign(Quiz $quiz, InviteQuizRequest $request, UnassignFromQui ->with("status", "Użytkownicy zostali wypisani z testu."); } + protected function groupBySchool(Builder $query, Request $request): Builder + { + $groupBySchool = $request->query("groupBySchool", "false"); + + if ($groupBySchool !== "true") { + return $query; + } + + $schoolIds = School::query() + ->select("id") + ->join("users", "schools.id", "=", "users.school_id") + ->groupBy("schools.id") + ->orderBy("schools.id") + ->pluck("id"); + + return $query->whereIn("school_id", $schoolIds)->orderBy("school_id"); + } + private function filterByMode(Builder $query, Request $request) { $mode = $request->query("mode", "user");