$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) {
return $tournament->toJson();
}
+ public function discordSettings(Request $request, Tournament $tournament) {
+ $this->authorize('update', $tournament);
+ $validatedData = $request->validate([
+ 'round_category' => 'string|nullable',
+ 'round_template' => 'string|nullable',
+ ]);
+ if (array_key_exists('round_category', $validatedData)) {
+ $tournament->discord_round_category = $validatedData['round_category'];
+ }
+ if (array_key_exists('round_template', $validatedData)) {
+ $tournament->discord_round_template = $validatedData['round_template'];
+ }
+ $tournament->save();
+ if ($tournament->wasChanged()) {
+ TournamentChanged::dispatch($tournament);
+ Protocol::tournamentDiscordSettings($tournament, $request->user());
+ }
+ 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;
$tournament->save();
TournamentChanged::dispatch($tournament);
- Protocol::tournamentOpenen($tournament, $request->user());
+ Protocol::tournamentOpened($tournament, $request->user());
return $tournament->toJson();
}