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\Libraries\Commentable;
9use App\Models\Beatmapset;
10
11class CommentableMetaTransformer extends TransformerAbstract
12{
13 public function transform(?Commentable $commentable)
14 {
15 if (isset($commentable)) {
16 if ($commentable instanceof Beatmapset) {
17 $ownerId = $commentable->user_id;
18 $ownerTitle = 'MAPPER';
19 }
20
21 return [
22 'current_user_attributes' => [
23 'can_new_comment_reason' => priv_check('CommentStore', $commentable)->message(),
24 ],
25 'id' => $commentable->getKey(),
26 'type' => $commentable->getMorphClass(),
27 'title' => $commentable->commentableTitle(),
28 'url' => $commentable->url(),
29 'owner_id' => $ownerId ?? null,
30 'owner_title' => $ownerTitle ?? null,
31 ];
32 } else {
33 return [
34 'title' => osu_trans('comments.commentable_name._deleted'),
35 ];
36 }
37 }
38}