the browser-facing portion of osu!
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 106 lines 2.6 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 string|null $build 10 * @property string $category 11 * @property int $changelog_id 12 * @property string $checksum 13 * @property \Carbon\Carbon $date 14 * @property Build $gameBuild 15 * @property bool $major 16 * @property string $message 17 * @property string $prefix 18 * @property bool $private 19 * @property int|null $stream_id 20 * @property int|null $thread_id 21 * @property int $tweet 22 * @property UpdateStream $updateStream 23 * @property string|null $url 24 * @property User $user 25 * @property int $user_id 26 */ 27class Changelog extends Model 28{ 29 const PREFIXES = [ 30 'add' => '+', 31 'fix' => '*', 32 'misc' => '?', 33 ]; 34 35 public $timestamps = false; 36 protected $table = 'osu_changelog'; 37 protected $primaryKey = 'changelog_id'; 38 39 protected $casts = [ 40 'private' => 'boolean', 41 'major' => 'boolean', 42 'date' => 'datetime', 43 ]; 44 45 public function scopeDefault($query) 46 { 47 return $query 48 ->where('private', 0) 49 ->orderBy('date', 'desc') 50 ->orderBy('major', 'desc'); 51 } 52 53 public function scopeListing($query, $offset = 20) 54 { 55 $limit = $GLOBALS['cfg']['osu']['changelog']['max'] ?? 20; 56 57 return $query 58 ->where('private', 0) 59 ->take($limit) 60 ->skip($offset) 61 ->orderBy('changelog_id', 'desc'); 62 } 63 64 public function scopeVisibleOnBuilds($query) 65 { 66 return $query->whereNotIn('category', ['Code', 'Web']); 67 } 68 69 public function user() 70 { 71 return $this->belongsTo(User::class, 'user_id'); 72 } 73 74 public function updateStream() 75 { 76 return $this->belongsTo(UpdateStream::class, 'stream_id'); 77 } 78 79 public function gameBuild() 80 { 81 return $this->belongsTo(Build::class, 'build', 'version'); 82 } 83 84 public function getPrefixAttribute($value) 85 { 86 return array_search_null($value, static::PREFIXES); 87 } 88 89 public static function placeholder() 90 { 91 $user = new User([ 92 // not sure if those should be put in config 93 'user_id' => 2, 94 'username' => 'peppy', 95 ]); 96 97 $change = new static([ 98 'user' => $user, 99 'user_id' => $user->user_id, 100 'prefix' => '*', 101 'message' => osu_trans('changelog.generic'), 102 ]); 103 104 return $change; 105 } 106}