-
Notifications
You must be signed in to change notification settings - Fork 379
/
ContestsController.php
91 lines (74 loc) · 2.63 KB
/
ContestsController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.
namespace App\Http\Controllers;
use App\Exceptions\InvariantException;
use App\Models\Contest;
use App\Transformers\ContestTransformer;
use Auth;
class ContestsController extends Controller
{
public function index()
{
$contests = Contest::orderBy('id', 'desc');
if (!Auth::check() || !Auth::user()->isAdmin()) {
$contests->where('visible', true);
}
return ext_view('contests.index', [
'contests' => $contests->get(),
]);
}
public function judge($id)
{
$contest = Contest::with('entries.judgeVotes')
->with('entries.judgeVotes.scores')
->with('scoringCategories')
->findOrFail($id);
abort_if(!$contest->isJudged(), 404);
priv_check('ContestJudgeShow', $contest)->ensureCan();
$contestJson = json_item($contest, new ContestTransformer(), [
'entries.current_user_judge_vote.scores',
'scoring_categories',
]);
return ext_view('contests.judge', [
'contestJson' => $contestJson,
]);
}
public function show($id)
{
$contest = Contest::findOrFail($id);
$user = Auth::user();
if (!$contest->visible && (!$user || !$user->isAdmin())) {
abort(404);
}
if ($contest->isVotingStarted() && isset($contest->getExtraOptions()['children'])) {
$contestIds = $contest->getExtraOptions()['children'];
$contests = Contest::whereIn('id', $contestIds)
->orderByField('id', $contestIds)
->get();
} else {
$contests = collect([$contest]);
}
set_opengraph($contest);
if ($contest->isVotingStarted()) {
if ($contest->isVotingOpen()) {
// TODO: add support for $contests requirement instead of at parent
try {
$contest->assertVoteRequirement($user);
} catch (InvariantException $e) {
$noVoteReason = $e->getMessage();
}
}
return ext_view('contests.voting', [
'contestMeta' => $contest,
'contests' => $contests,
'noVoteReason' => $noVoteReason ?? null,
]);
} else {
return ext_view('contests.enter', [
'contestMeta' => $contest,
'contest' => $contests->first(),
]);
}
}
}