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
6namespace App\Transformers;
7
8use App\Models\Beatmap;
9use App\Models\User;
10
11class UserStatisticsRulesetsTransformer extends TransformerAbstract
12{
13 protected $gameModeIncludes;
14
15 public function __construct()
16 {
17 foreach (Beatmap::MODES as $modeStr => $modeInt) {
18 $this->availableIncludes[] = $modeStr;
19 $this->gameModeIncludes[camel_case("include_{$modeStr}")] = $modeStr;
20 }
21 }
22
23 public function transform()
24 {
25 return [];
26 }
27
28 public function __call($name, $arguments)
29 {
30 $mode = $this->gameModeIncludes[$name] ?? null;
31 if ($mode !== null) {
32 return $this->gameModeInclude($arguments[0], $mode);
33 }
34 }
35
36 private function gameModeInclude(User $user, string $mode)
37 {
38 $statistics = $user->statistics($mode);
39
40 if ($statistics !== null) {
41 return $this->item($statistics, new UserStatisticsTransformer());
42 }
43 }
44}