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
6declare(strict_types=1);
7
8namespace App\Libraries\User;
9
10use App\Models\Beatmapset;
11use App\Models\User;
12
13class ProfileBeatmapset
14{
15 public static function countByGroupedStatus(User $user): array
16 {
17 return $user
18 ->beatmapsets()
19 ->active()
20 ->selectRaw('COUNT(*) as beatmapset_count, approved')
21 ->groupBy('approved')
22 ->get()
23 ->reduce(function ($carry, $item) {
24 static $profileStatus = [
25 Beatmapset::STATES['graveyard'] => 'graveyard',
26
27 Beatmapset::STATES['loved'] => 'loved',
28
29 Beatmapset::STATES['pending'] => 'pending',
30 Beatmapset::STATES['wip'] => 'pending',
31
32 Beatmapset::STATES['approved'] => 'ranked',
33 Beatmapset::STATES['qualified'] => 'ranked',
34 Beatmapset::STATES['ranked'] => 'ranked',
35 ];
36 $attrs = $item->getAttributes();
37 $carry[$profileStatus[$attrs['approved']]] ??= 0;
38 $carry[$profileStatus[$attrs['approved']]] += $attrs['beatmapset_count'];
39
40 return $carry;
41 }, []);
42 }
43}