the browser-facing portion of osu!
at master 48 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 PollTransformer extends TransformerAbstract 13{ 14 protected array $availableIncludes = [ 15 'options', 16 ]; 17 18 protected array $defaultIncludes = [ 19 'options', 20 ]; 21 22 public function transform(Topic $topic): array 23 { 24 return [ 25 'allow_vote_change' => $topic->poll_vote_change, 26 'ended_at' => json_time($topic->pollEnd()), 27 'hide_incomplete_results' => $topic->poll_hide_results, 28 'last_vote_at' => json_time($topic->poll_last_vote), 29 'max_votes' => $topic->poll_max_options, 30 'started_at' => json_time($topic->poll_start), 31 'title' => [ 32 'bbcode' => $topic->pollTitleRaw(), 33 'html' => $topic->pollTitleHTML(), 34 ], 35 'total_vote_count' => $topic->poll()->totalVoteCount(), 36 ]; 37 } 38 39 public function includeOptions(Topic $topic): ResourceInterface 40 { 41 foreach ($topic->pollOptions as $pollOption) { 42 $pollOption->setRelation('post', $topic->firstPost); 43 $pollOption->setRelation('topic', $topic); 44 } 45 46 return $this->collection($topic->pollOptions, new PollOptionTransformer()); 47 } 48}