A lot of things

This commit is contained in:
2026-06-16 16:21:43 +02:00
parent 4f9f6c63b3
commit 7e1e26f20b
126 changed files with 7917 additions and 204 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use App\Helpers\EntryHelpers;
use App\Traits\HasGallery;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -10,6 +11,8 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Monolog\Level;
use Spatie\Activitylog\Models\Concerns\LogsActivity;
use Spatie\Activitylog\Support\LogOptions;
/**
* @property int $id
@@ -22,6 +25,7 @@ use Monolog\Level;
* @property string|null $staff_comment
* @property \Illuminate\Support\Carbon|null $rejected_at
* @property bool $featured
* @property \Illuminate\Support\Carbon|null $featured_at
* @property int|null $game_id
* @property int|null $platform_id
* @property int|null $status_id
@@ -69,6 +73,7 @@ use Monolog\Level;
* @method static Builder<static>|Entry whereDeletedAt($value)
* @method static Builder<static>|Entry whereDescription($value)
* @method static Builder<static>|Entry whereFeatured($value)
* @method static Builder<static>|Entry whereFeaturedAt($value)
* @method static Builder<static>|Entry whereGameId($value)
* @method static Builder<static>|Entry whereId($value)
* @method static Builder<static>|Entry whereLevelId($value)
@@ -90,12 +95,14 @@ use Monolog\Level;
* @method static Builder<static>|Entry whereYoutubeLink($value)
* @method static Builder<static>|Entry withTrashed(bool $withTrashed = true)
* @method static Builder<static>|Entry withoutTrashed()
* @property-read \Illuminate\Database\Eloquent\Collection<int, \Spatie\Activitylog\Models\Activity> $activitiesAsSubject
* @property-read int|null $activities_as_subject_count
* @mixin \Eloquent
*/
class Entry extends Model
{
use SoftDeletes, HasGallery;
use SoftDeletes, HasGallery, LogsActivity;
/**
* @var string[]
@@ -108,6 +115,7 @@ class Entry extends Model
'main_image',
'state',
'featured',
'featured_at',
'game_id',
'platform_id',
'status_id',
@@ -121,7 +129,8 @@ class Entry extends Model
'comments_thread_id',
'staff_comment',
'rejected_at',
'level_id'
'level_id',
'created_at'
];
/**
@@ -131,6 +140,7 @@ class Entry extends Model
'featured' => 'boolean',
'release_date' => 'date',
'rejected_at' => 'datetime',
'featured_at' => 'datetime',
];
public function scopePublished( Builder $query ): Builder {
@@ -197,7 +207,7 @@ class Entry extends Model
return $this->hasMany(EntryHash::class);
}
public function parseStaffCredits(): array {
public function parseStaffCredits(): ?array {
return json_decode( $this->staff_credits ?? "", true );
}
@@ -205,10 +215,17 @@ class Entry extends Model
if( !$this->youtube_link )
return null;
$pattern = '%(?:https?://)?(?:www\.|m\.)?(?:youtu\.be/|youtube(?:-nocookie)?\.com/(?:watch\?.*v=|embed/|v/|shorts/|live/))([\w-]{11})%i';
return EntryHelpers::getYoutubeVideoId( $this->youtube_link );
}
preg_match($pattern, $this->youtube_link, $matches);
return $matches[1] ?? null;
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->useLogName('entry')
->logAll()
->logOnlyDirty()
->dontLogEmptyChanges()
->setDescriptionForEvent(fn(string $eventName) => "Entry {$eventName}");
}
}