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\ForumCover;
9use App\Transformers\TransformerAbstract;
10
11class ForumCoverTransformer extends TransformerAbstract
12{
13 public function transform(?ForumCover $cover = null)
14 {
15 $fileUrl = $cover === null ? null : $cover->file()->url();
16
17 if ($fileUrl === null) {
18 $data = [
19 'method' => 'post',
20 'url' => route('forum.forum-covers.store', ['forum_id' => $cover->forum_id]),
21 ];
22 } else {
23 $data = [
24 'method' => 'patch',
25 'url' => route('forum.forum-covers.update', [$cover, 'forum_id' => $cover->forum_id]),
26
27 'id' => $cover->id,
28 'fileUrl' => $fileUrl,
29 ];
30 }
31
32 $data['dimensions'] = $cover::MAX_DIMENSIONS;
33
34 return $data;
35 }
36}