Live Show data model + workflow
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-05 12:31:54 +01:00
parent c07687102e
commit 4718998e07
6 changed files with 317 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
<?php
namespace App\Enums;
enum PhotoLiveStatus: string
{
case NONE = 'none';
case PENDING = 'pending';
case APPROVED = 'approved';
case REJECTED = 'rejected';
case EXPIRED = 'expired';
}

View File

@@ -23,6 +23,7 @@ class Event extends Model
'is_active' => 'boolean',
'name' => 'array',
'description' => 'array',
'live_show_token_rotated_at' => 'datetime',
];
protected static function booted(): void
@@ -152,6 +153,29 @@ class Event extends Model
return $this->eventPackage->canUploadPhoto();
}
public function ensureLiveShowToken(): string
{
if (is_string($this->live_show_token) && $this->live_show_token !== '') {
return $this->live_show_token;
}
return $this->rotateLiveShowToken();
}
public function rotateLiveShowToken(): string
{
do {
$token = bin2hex(random_bytes(32));
} while (self::query()->where('live_show_token', $token)->exists());
$this->forceFill([
'live_show_token' => $token,
'live_show_token_rotated_at' => now(),
])->save();
return $token;
}
public function getSettingsAttribute($value): array
{
if (is_array($value)) {

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use App\Enums\PhotoLiveStatus;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -37,6 +38,10 @@ class Photo extends Model
'security_meta' => 'array',
'security_scanned_at' => 'datetime',
'moderated_at' => 'datetime',
'live_status' => PhotoLiveStatus::class,
'live_submitted_at' => 'datetime',
'live_approved_at' => 'datetime',
'live_reviewed_at' => 'datetime',
];
protected $attributes = [
@@ -79,6 +84,49 @@ class Photo extends Model
return $this->belongsTo(User::class, 'moderated_by');
}
public function liveReviewer(): BelongsTo
{
return $this->belongsTo(User::class, 'live_reviewed_by');
}
public function markLivePending(): void
{
$this->forceFill([
'live_status' => PhotoLiveStatus::PENDING,
'live_submitted_at' => now(),
'live_approved_at' => null,
'live_reviewed_at' => null,
'live_reviewed_by' => null,
'live_rejection_reason' => null,
])->save();
}
public function approveForLiveShow(?User $reviewer = null): void
{
$now = now();
$this->forceFill([
'live_status' => PhotoLiveStatus::APPROVED,
'live_approved_at' => $now,
'live_reviewed_at' => $now,
'live_reviewed_by' => $reviewer?->id,
'live_rejection_reason' => null,
])->save();
}
public function rejectForLiveShow(?User $reviewer = null, ?string $reason = null): void
{
$now = now();
$this->forceFill([
'live_status' => PhotoLiveStatus::REJECTED,
'live_approved_at' => null,
'live_reviewed_at' => $now,
'live_reviewed_by' => $reviewer?->id,
'live_rejection_reason' => $reason,
])->save();
}
public function likes(): HasMany
{
return $this->hasMany(PhotoLike::class);