diff --git a/app/Http/Controllers/InviteController.php b/app/Http/Controllers/InviteController.php index c7c5e415..7b45766d 100644 --- a/app/Http/Controllers/InviteController.php +++ b/app/Http/Controllers/InviteController.php @@ -8,9 +8,9 @@ use App\Actions\UnassignFromQuizAction; use App\Helpers\SortHelper; use App\Http\Requests\InviteQuizRequest; +use App\Http\Resources\QuizResource; use App\Http\Resources\UserResource; use App\Models\Quiz; -use App\Models\School; use App\Models\User; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\RedirectResponse; @@ -31,9 +31,17 @@ public function index(Quiz $quiz, SortHelper $sort, Request $request): Response $query = $this->filterByMode($query, $request); $query = $this->filterBySchool($query, $request); + $quizzes = Quiz::query() + ->select("id", "title") + ->whereNotNull("scheduled_at") + ->where("scheduled_at", ">", now()) + ->whereNotNull("locked_at") + ->get(); + return Inertia::render("Admin/Invite", [ "users" => UserResource::collection($sort->paginate($query)), - "quiz" => $quiz, + "quiz" => QuizResource::make($quiz), + "quizzes" => $quizzes, "assigned" => $quiz->assignedUsers->pluck("id"), ]); } @@ -60,24 +68,6 @@ 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"); diff --git a/database/seeders/AdminSeeder.php b/database/seeders/AdminSeeder.php index 1a523be5..497d6064 100644 --- a/database/seeders/AdminSeeder.php +++ b/database/seeders/AdminSeeder.php @@ -35,7 +35,7 @@ public function run(): void "firstname" => "Example", "surname" => "Super Admin", "email_verified_at" => Carbon::now(), - "password" => Hash::make("interns2024b"), + "password" => Hash::make("password"), "remember_token" => Str::random(10), "school_id" => $school->id, ], @@ -48,7 +48,7 @@ public function run(): void "firstname" => "Example", "surname" => "Admin", "email_verified_at" => Carbon::now(), - "password" => Hash::make("interns2024b"), + "password" => Hash::make("password"), "remember_token" => Str::random(10), "school_id" => $school->id, ], @@ -61,7 +61,7 @@ public function run(): void "firstname" => "Example", "surname" => "User", "email_verified_at" => Carbon::now(), - "password" => Hash::make("interns2024b"), + "password" => Hash::make("password"), "remember_token" => Str::random(10), "school_id" => School::factory()->create()->id, ], diff --git a/resources/js/Pages/Admin/Invite.vue b/resources/js/Pages/Admin/Invite.vue index a275cff9..09a0d7eb 100644 --- a/resources/js/Pages/Admin/Invite.vue +++ b/resources/js/Pages/Admin/Invite.vue @@ -1,20 +1,22 @@ -