Skip to content

Commit 0eecb06

Browse files
authored
Merge pull request #11944 from nanaya/team-ranking-page
Add team ranking page
2 parents 7cd38c2 + 74b3aeb commit 0eecb06

File tree

7 files changed

+140
-2
lines changed

7 files changed

+140
-2
lines changed

app/Http/Controllers/RankingController.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
use App\Models\CountryStatistics;
1111
use App\Models\Model;
1212
use App\Models\Spotlight;
13+
use App\Models\TeamStatistics;
1314
use App\Models\User;
1415
use App\Models\UserStatistics;
1516
use App\Transformers\SelectOptionTransformer;
17+
use App\Transformers\TeamStatisticsTransformer;
1618
use App\Transformers\UserCompactTransformer;
1719
use App\Transformers\UserStatisticsTransformer;
1820
use DB;
@@ -31,13 +33,14 @@ class RankingController extends Controller
3133

3234
const MAX_RESULTS = 10000;
3335
const PAGE_SIZE = Model::PER_PAGE;
34-
const RANKING_TYPES = ['performance', 'charts', 'score', 'country'];
36+
const RANKING_TYPES = ['performance', 'charts', 'score', 'country', 'team'];
3537
const SPOTLIGHT_TYPES = ['charts'];
3638
// in display order
3739
const TYPES = [
3840
'performance',
3941
'score',
4042
'country',
43+
'team',
4144
'multiplayer',
4245
'daily_challenge',
4346
'seasons',
@@ -170,6 +173,12 @@ public function index($mode, $type)
170173
->with('country')
171174
->where('mode', $modeInt)
172175
->orderBy('performance', 'desc');
176+
} elseif ($type === 'team') {
177+
$stats = TeamStatistics::where('ranked_score', '>', 0)
178+
->where('ruleset_id', $modeInt)
179+
->withCount('members')
180+
->with('team')
181+
->orderBy('performance', 'desc');
173182
} else {
174183
$class = UserStatistics\Model::getClass($mode, $this->params['variant']);
175184
$table = (new $class())->getTable();
@@ -242,6 +251,10 @@ public function index($mode, $type)
242251
$ranking = json_collection($stats, 'CountryStatistics', ['country']);
243252
break;
244253

254+
case 'team':
255+
$ranking = json_collection($stats, new TeamStatisticsTransformer(), ['member_count', 'team']);
256+
break;
257+
245258
default:
246259
$includes = UserStatisticsTransformer::RANKING_INCLUDES;
247260

@@ -399,6 +412,10 @@ private function maxResults($modeInt, $stats)
399412
->count();
400413
}
401414

415+
if ($this->params['type'] === 'team') {
416+
return TeamStatistics::where('ruleset_id', $modeInt)->where('ranked_score', '>', 0)->count();
417+
}
418+
402419
$maxResults = static::MAX_RESULTS;
403420

404421
if ($this->params['variant'] !== null) {

app/Models/TeamStatistics.php

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace App\Models;
99

1010
use Illuminate\Database\Eloquent\Relations\BelongsTo;
11+
use Illuminate\Database\Eloquent\Relations\HasMany;
1112

1213
class TeamStatistics extends Model
1314
{
@@ -21,6 +22,11 @@ public function team(): BelongsTo
2122
return $this->belongsTo(Team::class);
2223
}
2324

25+
public function members(): HasMany
26+
{
27+
return $this->hasMany(TeamMember::class, 'team_id', 'team_id');
28+
}
29+
2430
public function recalculate(): void
2531
{
2632
$userIdsQuery = TeamMember
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4+
// See the LICENCE file in the repository root for full licence text.
5+
6+
namespace App\Transformers;
7+
8+
use App\Models\TeamStatistics;
9+
10+
class TeamStatisticsTransformer extends TransformerAbstract
11+
{
12+
protected array $availableIncludes = ['member_count', 'team'];
13+
14+
public function transform(TeamStatistics $stat)
15+
{
16+
return [
17+
'team_id' => $stat->team_id,
18+
'ruleset_id' => $stat->ruleset_id,
19+
'play_count' => $stat->play_count,
20+
'ranked_score' => $stat->ranked_score,
21+
'performance' => $stat->performance,
22+
];
23+
}
24+
25+
public function includeTeam(TeamStatistics $stat)
26+
{
27+
return $this->item($stat->team, new TeamTransformer());
28+
}
29+
30+
public function includeMemberCount(TeamStatistics $stat)
31+
{
32+
return $this->primitive($stat->members_count);
33+
}
34+
}

resources/css/bem/ranking-page-table.less

+6
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@
7777
padding-right: 10px;
7878
}
7979

80+
&--value {
81+
padding-left: 10px;
82+
padding-right: $padding-left;
83+
}
84+
8085
&:first-child {
8186
border-top-left-radius: @border-radius-base;
8287
border-bottom-left-radius: @border-radius-base;
@@ -122,5 +127,6 @@
122127

123128
&__user-link-text {
124129
margin-left: 10px;
130+
max-width: 350px;
125131
}
126132
}

resources/css/variables.less

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
@nav2-height: 90px;
4545
@nav2-height--pinned: 50px;
4646
@nav2-header-height: 360px;
47-
@nav2-header-image-height: 310px;
47+
@nav2-header-image-height: 340px;
4848

4949
// mobile nav
5050
// TODO: un-bootstrap names

resources/lang/en/rankings.php

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
'performance' => 'performance',
4343
'score' => 'score',
4444
'seasons' => 'seasons',
45+
'team' => 'team',
4546
],
4647

4748
'seasons' => [
@@ -66,6 +67,7 @@
6667
'active_users' => 'Active Users',
6768
'country' => 'Country',
6869
'division' => 'Division',
70+
'members' => 'Members',
6971
'play_count' => 'Play Count',
7072
'performance' => 'Performance',
7173
'total_score' => 'Total Score',
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{{--
2+
Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
3+
See the LICENCE file in the repository root for full licence text.
4+
--}}
5+
@extends('rankings.index', ['hasFilter' => false])
6+
7+
@section("scores")
8+
<table class="ranking-page-table">
9+
<thead>
10+
<tr>
11+
<th class="ranking-page-table__heading"></th>
12+
<th class="ranking-page-table__heading ranking-page-table__heading--main"></th>
13+
<th class="ranking-page-table__heading">
14+
{{ osu_trans('rankings.stat.members') }}
15+
</th>
16+
<th class="ranking-page-table__heading">
17+
{{ osu_trans('rankings.stat.play_count') }}
18+
</th>
19+
<th class="ranking-page-table__heading">
20+
{{ osu_trans('rankings.stat.ranked_score') }}
21+
</th>
22+
<th class="ranking-page-table__heading">
23+
{{ osu_trans('rankings.stat.average_score') }}
24+
</th>
25+
<th class="ranking-page-table__heading ranking-page-table__heading--focused">
26+
{{ osu_trans('rankings.stat.performance') }}
27+
</th>
28+
</tr>
29+
</thead>
30+
<tbody>
31+
@foreach ($scores as $index => $score)
32+
<tr class="ranking-page-table__row">
33+
<td class="ranking-page-table__column ranking-page-table__column--rank">
34+
#{{ $scores->firstItem() + $index }}
35+
</td>
36+
<td class="ranking-page-table__column">
37+
<div class="ranking-page-table__user-link">
38+
@php
39+
$url = route('teams.leaderboard', [
40+
'ruleset' => $mode,
41+
'team' => $score->team->getKey(),
42+
]);
43+
@endphp
44+
<div class="ranking-page-table__flags">
45+
<a class="u-contents" href="{{ $url }}">
46+
@include('objects._flag_team', ['team' => $score->team])
47+
</a>
48+
</div>
49+
<a class="ranking-page-table__user-link-text u-ellipsis-overflow" href="{{ $url }}">
50+
{{ $score->team->name }}
51+
</a>
52+
</div>
53+
</td>
54+
<td class="ranking-page-table__column ranking-page-table__column--value ranking-page-table__column--dimmed">
55+
{{ i18n_number_format($score->members_count) }}
56+
</td>
57+
<td class="ranking-page-table__column ranking-page-table__column--value ranking-page-table__column--dimmed">
58+
{{ i18n_number_format($score->play_count) }}
59+
</td>
60+
<td class="ranking-page-table__column ranking-page-table__column--value ranking-page-table__column--dimmed">
61+
{{ i18n_number_format($score->ranked_score) }}
62+
</td>
63+
<td class="ranking-page-table__column ranking-page-table__column--value ranking-page-table__column--dimmed">
64+
{{ i18n_number_format(round($score->ranked_score / max($score->members_count, 1))) }}
65+
</td>
66+
<td class="ranking-page-table__column ranking-page-table__column--value ranking-page-table__column--focused">
67+
{{ i18n_number_format(round($score->performance)) }}
68+
</td>
69+
</tr>
70+
@endforeach
71+
</tbody>
72+
</table>
73+
@endsection

0 commit comments

Comments
 (0)