]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/TournamentController.php
option to hide round numbers
[alttp.git] / app / Http / Controllers / TournamentController.php
index 2bb258efb0be4de7cba36804cd8021b4e4bd8027..2dc7e51a84ae104597626dd05950b4383c55e873 100644 (file)
@@ -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;