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\DeletedUser;
9use App\Models\UserContestEntry;
10
11class UserContestEntryTransformer extends TransformerAbstract
12{
13 protected array $availableIncludes = [
14 'user',
15 ];
16
17 public function transform(UserContestEntry $entry)
18 {
19 $url = $entry->file()->url();
20
21 return [
22 'id' => $entry->id,
23 'filename' => $entry->original_filename,
24 'filesize' => $entry->filesize,
25 'url' => $url,
26 'thumb' => mini_asset($url),
27 'created_at' => json_time($entry->created_at),
28 'deleted' => $entry->deleted_at !== null,
29 ];
30 }
31
32 public function includeUser(UserContestEntry $entry)
33 {
34 return $this->item(
35 $entry->user ?? (new DeletedUser()),
36 new UserCompactTransformer()
37 );
38 }
39}