-
Notifications
You must be signed in to change notification settings - Fork 393
/
Copy pathContestsController.php
67 lines (56 loc) · 1.98 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
<?php
// Copyright (c) ppy Pty Ltd <[email protected]>. 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 Auth;
class ContestsController extends Controller
{
public function index()
{
$contests = Contest::orderBy('id', 'desc');
if (!Auth::check() || !Auth::user()->isGroup('admin')) {
$contests->where('visible', true);
}
return ext_view('contests.index', [
'contests' => $contests->get(),
]);
}
public function show($id)
{
$contest = Contest::findOrFail($id);
$user = Auth::user();
if (!$contest->visible && (!$user || !$user->isGroup('admin'))) {
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]);
}
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(),
]);
}
}
}