the browser-facing portion of osu!
at master 74 lines 1.9 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 8/** 9 * @property int $achievement_id 10 * @property string|null $description 11 * @property bool $enabled 12 * @property string $grouping 13 * @property string|null $image 14 * @property string|null $mode 15 * @property string $name 16 * @property int $ordering 17 * @property int $progression 18 * @property string|null $quest_instructions 19 * @property int|null $quest_ordering 20 * @property string $slug 21 * @method static \Illuminate\Database\Eloquent\Builder achievable() 22 */ 23class Achievement extends Model 24{ 25 protected $table = 'osu_achievements'; 26 protected $primaryKey = 'achievement_id'; 27 28 protected $casts = [ 29 'enabled' => 'boolean', 30 ]; 31 public $timestamps = false; 32 public $incrementing = false; 33 34 public function scopeAchievable($query) 35 { 36 return $query 37 ->where('enabled', true) 38 ->where('slug', '<>', ''); 39 } 40 41 public function iconUrl() 42 { 43 return $GLOBALS['cfg']['osu']['achievement']['icon_prefix'].e($this->slug).'.png'; 44 } 45 46 public function getAttribute($key) 47 { 48 return match ($key) { 49 'achievement_id', 50 'description', 51 'grouping', 52 'image', 53 'name', 54 'ordering', 55 'progression', 56 'quest_instructions', 57 'quest_ordering', 58 'slug' => $this->getRawAttribute($key), 59 60 'enabled' => (bool) $this->getRawAttribute($key), 61 62 'mode' => $this->getMode(), 63 }; 64 } 65 66 private function getMode(): ?string 67 { 68 $value = $this->getRawAttribute('mode'); 69 70 return $value === null 71 ? null 72 : Beatmap::modeStr($value); 73 } 74}