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\BeatmapPlaycount;
9
10class BeatmapPlaycountTransformer extends TransformerAbstract
11{
12 protected array $defaultIncludes = [
13 'beatmap',
14 'beatmapset',
15 ];
16
17 protected array $availableIncludes = [
18 'beatmap',
19 'beatmapset',
20 ];
21
22 public function transform(BeatmapPlaycount $playcount)
23 {
24 return [
25 'beatmap_id' => $playcount->beatmap_id,
26 'count' => $playcount->playcount,
27 ];
28 }
29
30 public function includeBeatmap(BeatmapPlaycount $playcount)
31 {
32 if ($playcount->beatmap === null) {
33 return;
34 }
35
36 return $this->item(
37 $playcount->beatmap,
38 new BeatmapCompactTransformer()
39 );
40 }
41
42 public function includeBeatmapset(BeatmapPlaycount $playcount)
43 {
44 if ($playcount->beatmap === null) {
45 return;
46 }
47
48 return $this->item(
49 $playcount->beatmap->beatmapset,
50 new BeatmapsetCompactTransformer()
51 );
52 }
53}