X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FTournamentController.php;h=2dc7e51a84ae104597626dd05950b4383c55e873;hb=e1ecc76c1c6d527502d6576ee19be06df2a15bb7;hp=2bb258efb0be4de7cba36804cd8021b4e4bd8027;hpb=a58382451a425ebb828ee27c348013de5d4aca67;p=alttp.git diff --git a/app/Http/Controllers/TournamentController.php b/app/Http/Controllers/TournamentController.php index 2bb258e..2dc7e51 100644 --- a/app/Http/Controllers/TournamentController.php +++ b/app/Http/Controllers/TournamentController.php @@ -28,20 +28,21 @@ class TournamentController extends Controller $tournament = Tournament::with( 'applications', 'applications.user', - 'rounds', - 'rounds.results', 'participants', 'participants.user', )->findOrFail($id); $this->authorize('view', $tournament); - foreach ($tournament->rounds as $round) { + $rounds = $tournament->rounds()->with(['results', 'results.user'])->limit(25)->get(); + foreach ($rounds as $round) { try { $this->authorize('seeResults', $round); } catch (AuthorizationException) { $round->hideResults(); } } - return $tournament->toJson(); + $json = $tournament->toArray(); + $json['rounds'] = $rounds->toArray(); + return $json; } public function discord(Request $request, Tournament $tournament) { @@ -80,6 +81,43 @@ class TournamentController extends Controller return $tournament->toJson(); } + public function moreRounds(Request $request, Tournament $tournament) { + $this->authorize('view', $tournament); + + $validatedData = $request->validate([ + 'last_known' => 'integer|required', + ]); + + $rounds = $tournament->rounds() + ->where('number', '<', $validatedData['last_known']) + ->with(['results', 'results.user']) + ->limit(25)->get(); + foreach ($rounds as $round) { + try { + $this->authorize('seeResults', $round); + } catch (AuthorizationException) { + $round->hideResults(); + } + } + return $rounds->toArray(); + } + + public function settings(Request $request, Tournament $tournament) { + $this->authorize('update', $tournament); + $validatedData = $request->validate([ + 'show_numbers' => 'boolean|nullable', + ]); + if (array_key_exists('show_numbers', $validatedData)) { + $tournament->show_numbers = $validatedData['show_numbers']; + } + $tournament->save(); + if ($tournament->wasChanged()) { + TournamentChanged::dispatch($tournament); + Protocol::tournamentSettings($tournament, $request->user()); + } + return $tournament->toJson(); + } + public function open(Request $request, Tournament $tournament) { $this->authorize('update', $tournament); $tournament->accept_applications = true;