Live Show data model + workflow
This commit is contained in:
@@ -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