Club System
This commit is contained in:
@@ -7,10 +7,13 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Entry extends Model
|
||||
{
|
||||
|
||||
use SoftDeletes;
|
||||
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
@@ -33,6 +36,8 @@ class Entry extends Model
|
||||
'user_id',
|
||||
'complete_title',
|
||||
'comments_thread_id',
|
||||
'staff_comment',
|
||||
'rejected_at',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -41,12 +46,21 @@ class Entry extends Model
|
||||
protected $casts = [
|
||||
'featured' => 'boolean',
|
||||
'release_date' => 'date',
|
||||
'rejected_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function scopePublished( Builder $query ): Builder {
|
||||
return $query->where( 'state', 'published' );
|
||||
}
|
||||
|
||||
public function scopeInQueue( Builder $query, int $daysRejected = 7 ): Builder {
|
||||
return $query->withTrashed()->where(function($q) use($daysRejected) {
|
||||
$q->where('state', 'pending')->whereNull('deleted_at');
|
||||
})->orWhere(function($q) use($daysRejected) {
|
||||
$q->where('state', 'rejected')->whereNotNull('rejected_at')->where('rejected_at', '>=', now()->subDays($daysRejected) );
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Return game link.
|
||||
* @return BelongsTo
|
||||
@@ -91,4 +105,18 @@ class Entry extends Model
|
||||
return $this->hasMany(EntryHash::class);
|
||||
}
|
||||
|
||||
public function parseStaffCredits(): array {
|
||||
return json_decode( $this->staff_credits ?? "", true );
|
||||
}
|
||||
|
||||
public function getYoutubeVideoId(): ?string {
|
||||
if( !$this->youtube_link )
|
||||
return null;
|
||||
|
||||
$pattern = '%(?:https?://)?(?:www\.|m\.)?(?:youtu\.be/|youtube(?:-nocookie)?\.com/(?:watch\?.*v=|embed/|v/|shorts/|live/))([\w-]{11})%i';
|
||||
|
||||
preg_match($pattern, $this->youtube_link, $matches);
|
||||
return $matches[1] ?? null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user