the browser-facing portion of osu!
at master 1.7 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\Models; 7 8use Illuminate\Database\Eloquent\Collection; 9use Illuminate\Database\Eloquent\Relations\HasMany; 10use Illuminate\Database\Eloquent\Relations\HasManyThrough; 11 12/** 13 * @property-read Contest $contest 14 * @property int $contest_id 15 * @property \Carbon\Carbon|null $created_at 16 * @property string|null $entry_url 17 * @property string|null $thumbnail_url 18 * @property int $id 19 * @property-read Collection<ContestJudgeVote> $judgeVotes 20 * @property string $masked_name 21 * @property string $name 22 * @property-read Collection<ContestJudgeScore> $scores 23 * @property \Carbon\Carbon|null $updated_at 24 * @property-read User $user 25 * @property int|null $user_id 26 * @property-read Collection<ContestVote> $votes 27 */ 28class ContestEntry extends Model 29{ 30 public function scores(): HasManyThrough 31 { 32 return $this->hasManyThrough(ContestJudgeScore::class, ContestJudgeVote::class); 33 } 34 35 public function contest() 36 { 37 return $this->belongsTo(Contest::class); 38 } 39 40 public function judgeVotes(): HasMany 41 { 42 return $this->hasMany(ContestJudgeVote::class); 43 } 44 45 public function user() 46 { 47 return $this->belongsTo(User::class, 'user_id'); 48 } 49 50 public function votes() 51 { 52 return $this->hasMany(ContestVote::class); 53 } 54 55 public function thumbnail(): ?string 56 { 57 if (!$this->contest->hasThumbnails()) { 58 return null; 59 } 60 61 return presence($this->thumbnail_url) ?? $this->entry_url; 62 } 63}