Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include user team in ranking json #11864

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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