Live Show data model + workflow
This commit is contained in:
12
app/Enums/PhotoLiveStatus.php
Normal file
12
app/Enums/PhotoLiveStatus.php
Normal 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';
|
||||
}
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user