the browser-facing portion of osu!
at master 63 lines 1.5 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\BeatmapsetEvent; 9 10class BeatmapsetEventTransformer extends TransformerAbstract 11{ 12 protected array $availableIncludes = [ 13 'beatmapset', 14 'discussion', 15 ]; 16 17 protected array $defaultIncludes = [ 18 'user_id', 19 ]; 20 21 protected $permissions = [ 22 'user_id' => 'BeatmapsetEventViewUserId', 23 ]; 24 25 public function transform(BeatmapsetEvent $event = null) 26 { 27 return [ 28 'id' => $event->id, 29 'type' => $event->type, 30 'comment' => $event->comment, 31 'created_at' => json_time($event->created_at), 32 ]; 33 } 34 35 public function includeBeatmapset(BeatmapsetEvent $event) 36 { 37 if ($event->beatmapset === null) { 38 return; 39 } 40 41 return $this->item( 42 $event->beatmapset, 43 new BeatmapsetCompactTransformer() 44 ); 45 } 46 47 public function includeDiscussion(BeatmapsetEvent $event) 48 { 49 if ($event->beatmapDiscussion === null) { 50 return; 51 } 52 53 return $this->item( 54 $event->beatmapDiscussion, 55 new BeatmapDiscussionTransformer() 56 ); 57 } 58 59 public function includeUserId(BeatmapsetEvent $event) 60 { 61 return $this->primitive($event->user_id); 62 } 63}