Skip to content

Commit

Permalink
Merge pull request #11864 from nanaya/ranking-user-team
Browse files Browse the repository at this point in the history
Include user team in ranking json
  • Loading branch information
notbakaneko authored Feb 18, 2025
2 parents 21497c6 + 09f3717 commit 491abf1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
11 changes: 8 additions & 3 deletions app/Http/Controllers/RankingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use App\Models\UserStatistics;
use App\Transformers\SelectOptionTransformer;
use App\Transformers\UserCompactTransformer;
use App\Transformers\UserStatisticsTransformer;
use DB;
use Illuminate\Pagination\LengthAwarePaginator;

Expand Down Expand Up @@ -242,7 +243,7 @@ public function index($mode, $type)
break;

default:
$includes = ['user', 'user.cover', 'user.country'];
$includes = UserStatisticsTransformer::RANKING_INCLUDES;

if ($this->country !== null) {
$includes[] = 'country_rank';
Expand All @@ -256,7 +257,7 @@ public function index($mode, $type)
$includes[] = 'rank_change_since_30_days';
}

$ranking = json_collection($stats, 'UserStatistics', $includes);
$ranking = json_collection($stats, new UserStatisticsTransformer(), $includes);
break;
}

Expand Down Expand Up @@ -346,7 +347,11 @@ public function spotlight($mode)
// transformer can't do nested includes with params properly.
// https://github.com/thephpleague/fractal/issues/239
'beatmapsets' => json_collection($beatmapsets, 'Beatmapset', ['beatmaps']),
'ranking' => json_collection($scores->get(), 'UserStatistics', ['user', 'user.cover', 'user.country']),
'ranking' => json_collection(
$scores->get(),
new UserStatisticsTransformer(),
UserStatisticsTransformer::RANKING_INCLUDES,
),
'spotlight' => json_item($spotlight, 'Spotlight', ["participant_count:mode({$mode})"]),
];
} else {
Expand Down
12 changes: 8 additions & 4 deletions app/Transformers/UserStatisticsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@

class UserStatisticsTransformer extends TransformerAbstract
{
const RANKING_INCLUDES = [
'user.country',
'user.cover',
'user.team',
];

protected array $availableIncludes = [
'country_rank',
'rank',
Expand All @@ -19,11 +25,9 @@ class UserStatisticsTransformer extends TransformerAbstract
'variants',
];

public function transform(UserStatistics\Model $stats = null)
public function transform(?UserStatistics\Model $stats = null)
{
if ($stats === null) {
$stats = new UserStatistics\Osu();
}
$stats ??= new UserStatistics\Osu();

if (!$GLOBALS['cfg']['osu']['scores']['experimental_rank_as_default'] && $GLOBALS['cfg']['osu']['scores']['experimental_rank_as_extra']) {
$globalRankExp = $stats->globalRankExp();
Expand Down

0 comments on commit 491abf1

Please sign in to comment.