the browser-facing portion of osu!
at master 50 lines 1.4 kB view raw
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\ArtistTrack; 9 10class ArtistTrackTransformer extends TransformerAbstract 11{ 12 protected array $availableIncludes = [ 13 'album', 14 'artist', 15 ]; 16 17 public function transform(ArtistTrack $track) 18 { 19 return [ 20 'album_id' => $track->album_id, 21 'artist_id' => $track->artist_id, 22 'bpm' => $track->bpm, 23 'cover_url' => $track->cover_url, 24 'exclusive' => $track->exclusive, 25 'genre' => $track->genre, 26 'id' => $track->id, 27 'is_new' => $track->isNew(), 28 'length' => format_duration_for_display($track->length), 29 'osz' => $track->osz, 30 'preview' => $track->preview, 31 'title' => $track->title, 32 'updated_at' => json_time($track->updated_at), 33 'version' => $track->version, 34 ]; 35 } 36 37 public function includeAlbum(ArtistTrack $track) 38 { 39 $album = $track->album; 40 41 return $album === null 42 ? null 43 : $this->item($track->album, new ArtistAlbumTransformer()); 44 } 45 46 public function includeArtist(ArtistTrack $track) 47 { 48 return $this->item($track->artist, new ArtistTransformer()); 49 } 50}