the browser-facing portion of osu!
at master 46 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\Forum; 7 8use App\Models\Forum\Topic; 9use App\Transformers\TransformerAbstract; 10use League\Fractal\Resource\ResourceInterface; 11 12class TopicTransformer extends TransformerAbstract 13{ 14 protected array $availableIncludes = [ 15 'poll', 16 ]; 17 18 protected array $defaultIncludes = [ 19 'poll', 20 ]; 21 22 public function transform(Topic $topic): array 23 { 24 return [ 25 'created_at' => json_time($topic->topic_time), 26 'deleted_at' => json_time($topic->deleted_at), 27 'first_post_id' => $topic->topic_first_post_id, 28 'forum_id' => $topic->forum_id, 29 'id' => $topic->getKey(), 30 'is_locked' => $topic->isLocked(), 31 'last_post_id' => $topic->topic_last_post_id, 32 'post_count' => $topic->postCount(), 33 'title' => $topic->topic_title, 34 'type' => $topic->typeStr($topic->topic_type), 35 'updated_at' => json_time($topic->topic_last_post_time), 36 'user_id' => $topic->topic_poster, 37 ]; 38 } 39 40 public function includePoll(Topic $topic): ResourceInterface 41 { 42 return $topic->poll()->exists() 43 ? $this->item($topic, new PollTransformer()) 44 : $this->null(); 45 } 46}