12-05-2026 admin, Panel Displays
This commit is contained in:
parent
0762e3beac
commit
6a65354f4c
43 changed files with 3273 additions and 410 deletions
|
|
@ -5,6 +5,9 @@ namespace App\Models;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Display extends Model
|
||||
{
|
||||
|
|
@ -15,19 +18,85 @@ class Display extends Model
|
|||
'name',
|
||||
'location',
|
||||
'is_active',
|
||||
'is_test',
|
||||
'preview_token',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'is_active' => 'boolean',
|
||||
'is_test' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Wird in Phase 7 entfernt. Nutze stattdessen liveModules()
|
||||
* oder die Playlist-Relationen (livePlaylist, draftPlaylist).
|
||||
*/
|
||||
public function versions(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(DisplayVersion::class, 'display_display_version')
|
||||
->withPivot('sort_order')
|
||||
->orderByPivot('sort_order');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<DisplayPlaylist, $this>
|
||||
*/
|
||||
public function playlists(): HasMany
|
||||
{
|
||||
return $this->hasMany(DisplayPlaylist::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasOne<DisplayPlaylist, $this>
|
||||
*/
|
||||
public function livePlaylist(): HasOne
|
||||
{
|
||||
return $this->hasOne(DisplayPlaylist::class)
|
||||
->where('status', DisplayPlaylist::STATUS_PUBLISHED);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasOne<DisplayPlaylist, $this>
|
||||
*/
|
||||
public function draftPlaylist(): HasOne
|
||||
{
|
||||
return $this->hasOne(DisplayPlaylist::class)
|
||||
->where('status', DisplayPlaylist::STATUS_DRAFT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Liefert die Module der aktuell veröffentlichten Bespielung in Reihenfolge.
|
||||
*/
|
||||
public function liveModules(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(
|
||||
DisplayVersion::class,
|
||||
'display_playlist_items',
|
||||
'display_playlist_id',
|
||||
'display_version_id'
|
||||
)
|
||||
->wherePivotIn(
|
||||
'display_playlist_id',
|
||||
DisplayPlaylist::query()
|
||||
->where('display_id', $this->id ?? 0)
|
||||
->where('status', DisplayPlaylist::STATUS_PUBLISHED)
|
||||
->select('id')
|
||||
)
|
||||
->withPivot(['sort_order', 'id'])
|
||||
->withTimestamps()
|
||||
->orderByPivot('sort_order');
|
||||
}
|
||||
|
||||
public function ensurePreviewToken(): string
|
||||
{
|
||||
if (! $this->preview_token) {
|
||||
$this->preview_token = Str::random(40);
|
||||
$this->save();
|
||||
}
|
||||
|
||||
return $this->preview_token;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
89
app/Models/DisplayPlaylist.php
Normal file
89
app/Models/DisplayPlaylist.php
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class DisplayPlaylist extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\DisplayPlaylistFactory> */
|
||||
use HasFactory;
|
||||
|
||||
public const STATUS_PUBLISHED = 'published';
|
||||
|
||||
public const STATUS_DRAFT = 'draft';
|
||||
|
||||
protected $fillable = [
|
||||
'display_id',
|
||||
'status',
|
||||
'published_at',
|
||||
'published_by',
|
||||
'notes',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'published_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function display(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Display::class);
|
||||
}
|
||||
|
||||
public function publisher(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'published_by');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany<DisplayPlaylistItem, $this>
|
||||
*/
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(DisplayPlaylistItem::class)->orderBy('sort_order');
|
||||
}
|
||||
|
||||
/**
|
||||
* Die der Bespielung zugeordneten Module in korrekter Reihenfolge.
|
||||
*/
|
||||
public function modules(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(
|
||||
DisplayVersion::class,
|
||||
'display_playlist_items',
|
||||
'display_playlist_id',
|
||||
'display_version_id'
|
||||
)
|
||||
->withPivot(['sort_order', 'id'])
|
||||
->withTimestamps()
|
||||
->orderByPivot('sort_order');
|
||||
}
|
||||
|
||||
public function isPublished(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_PUBLISHED;
|
||||
}
|
||||
|
||||
public function isDraft(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_DRAFT;
|
||||
}
|
||||
|
||||
public function scopePublished(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', self::STATUS_PUBLISHED);
|
||||
}
|
||||
|
||||
public function scopeDraft(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', self::STATUS_DRAFT);
|
||||
}
|
||||
}
|
||||
36
app/Models/DisplayPlaylistItem.php
Normal file
36
app/Models/DisplayPlaylistItem.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class DisplayPlaylistItem extends Model
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\DisplayPlaylistItemFactory> */
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'display_playlist_id',
|
||||
'display_version_id',
|
||||
'sort_order',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function playlist(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DisplayPlaylist::class, 'display_playlist_id');
|
||||
}
|
||||
|
||||
public function module(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DisplayVersion::class, 'display_version_id');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue