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\BeatmapPack;
9
10class BeatmapPackTransformer extends TransformerAbstract
11{
12 protected array $availableIncludes = [
13 'beatmapsets',
14 'user_completion_data',
15 ];
16
17 private $userCompletionData;
18
19 public function __construct($userCompletionData = null)
20 {
21 $this->userCompletionData = $userCompletionData;
22 }
23
24 public function transform(BeatmapPack $pack)
25 {
26 return [
27 'author' => $pack->author,
28 'date' => $pack->date,
29 'name' => $pack->name,
30 'no_diff_reduction' => $pack->no_diff_reduction,
31 'ruleset_id' => $pack->playmode,
32 'tag' => $pack->tag,
33 'url' => $pack->url,
34 ];
35 }
36
37 public function includeBeatmapsets(BeatmapPack $pack)
38 {
39 return $this->collection($pack->beatmapsets, new BeatmapsetTransformer());
40 }
41
42 public function includeUserCompletionData(BeatmapPack $pack)
43 {
44 return $this->primitive([
45 'completed' => $this->userCompletionData['completed'],
46 'beatmapset_ids' => $this->userCompletionData['beatmapset_ids'],
47 ]);
48 }
49}