-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathMatchmakingController.php
More file actions
65 lines (51 loc) · 1.94 KB
/
Copy pathMatchmakingController.php
File metadata and controls
65 lines (51 loc) · 1.94 KB
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
<?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.
declare(strict_types=1);
namespace App\Http\Controllers\Ranking;
use App\Http\Controllers\Controller;
use App\Models\Beatmap;
use App\Models\MatchmakingPool;
class MatchmakingController extends Controller
{
const SORTS = [
'points' => [['total_points', 'DESC'], ['rating', 'DESC']],
'rating' => [['rating', 'DESC'], ['total_points', 'DESC']],
];
public function show(?string $poolType = null, ?string $rulesetName = null, ?string $poolId = null)
{
$poolType ??= MatchmakingPool::TYPES[0];
$rulesetName ??= default_mode();
$rulesetId = Beatmap::MODES[$rulesetName] ?? abort(422, 'invalid ruleset parameter');
$poolsQuery = MatchmakingPool::where([
'type' => $poolType,
'ruleset_id' => $rulesetId,
])->orderByDesc('active')->orderByDesc('id');
if ($poolId === null) {
$pool = $poolsQuery->firstOrFail();
return ujs_redirect(route('rankings.matchmaking', [
'poolType' => $poolType,
'mode' => $rulesetName,
'pool' => $pool->getKey(),
]));
}
$pools = $poolsQuery->get();
$pool = $pools->findOrFail($poolId);
$query = $pool->allUserStats()->with('user.team')->default();
$sort = get_string(request('sort'));
if (!array_key_exists($sort, static::SORTS) || !$pool->hasPoints()) {
$sort = 'rating';
}
foreach (static::SORTS[$sort] as $dbSort) {
$query->orderBy(...$dbSort);
}
$scores = $query->paginate()->withQueryString();
return ext_view('rankings.matchmaking', compact(
'pool',
'pools',
'rulesetName',
'scores',
'sort',
));
}
}