2026-05-20 18:25:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
2026-06-02 20:54:10 +02:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2026-05-20 18:25:15 +02:00
|
|
|
|
|
|
|
|
class Entry extends Model
|
|
|
|
|
{
|
|
|
|
|
|
2026-06-02 20:54:10 +02:00
|
|
|
use SoftDeletes;
|
|
|
|
|
|
2026-05-20 18:25:15 +02:00
|
|
|
/**
|
|
|
|
|
* @var string[]
|
|
|
|
|
*/
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'type',
|
|
|
|
|
'title',
|
|
|
|
|
'slug',
|
|
|
|
|
'description',
|
|
|
|
|
'main_image',
|
|
|
|
|
'state',
|
|
|
|
|
'featured',
|
|
|
|
|
'game_id',
|
|
|
|
|
'platform_id',
|
|
|
|
|
'status_id',
|
|
|
|
|
'version',
|
|
|
|
|
'release_date',
|
|
|
|
|
'staff_credits',
|
|
|
|
|
'relevant_link',
|
|
|
|
|
'youtube_link',
|
|
|
|
|
'user_id',
|
|
|
|
|
'complete_title',
|
2026-05-27 21:24:38 +02:00
|
|
|
'comments_thread_id',
|
2026-06-02 20:54:10 +02:00
|
|
|
'staff_comment',
|
|
|
|
|
'rejected_at',
|
2026-05-20 18:25:15 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @var string[]
|
|
|
|
|
*/
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'featured' => 'boolean',
|
|
|
|
|
'release_date' => 'date',
|
2026-06-02 20:54:10 +02:00
|
|
|
'rejected_at' => 'datetime',
|
2026-05-20 18:25:15 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
public function scopePublished( Builder $query ): Builder {
|
|
|
|
|
return $query->where( 'state', 'published' );
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-02 20:54:10 +02:00
|
|
|
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) );
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 18:25:15 +02:00
|
|
|
/**
|
|
|
|
|
* Return game link.
|
|
|
|
|
* @return BelongsTo
|
|
|
|
|
*/
|
|
|
|
|
public function game(): BelongsTo {
|
|
|
|
|
return $this->belongsTo(Game::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function platform(): BelongsTo {
|
|
|
|
|
return $this->belongsTo(Platform::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getRealPlatform(): ?Platform {
|
|
|
|
|
return $this->game?->platform ?? $this->platform;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function status(): BelongsTo {
|
|
|
|
|
return $this->belongsTo(Status::class );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function authors(): BelongsToMany {
|
|
|
|
|
return $this->belongsToMany(Author::class, 'entry_authors');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function languages(): BelongsToMany {
|
|
|
|
|
return $this->belongsToMany(Language::class, 'entry_languages');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function modifications(): BelongsToMany {
|
|
|
|
|
return $this->belongsToMany( Modification::class, 'entry_modifications');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function files(): HasMany {
|
|
|
|
|
return $this->hasMany(EntryFile::class)->orderBy('filename');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function gallery(): HasMany {
|
|
|
|
|
return $this->hasMany(EntryGallery::class)->orderBy('id');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function hashes(): HasMany {
|
|
|
|
|
return $this->hasMany(EntryHash::class);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-02 20:54:10 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-20 18:25:15 +02:00
|
|
|
}
|