79 lines
2.2 KiB
PHP
79 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Observers;
|
|
|
|
use App\Exceptions\AuditionAdminException;
|
|
use App\Models\Doubler;
|
|
use App\Models\EntryFlag;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class EntryFlagObserver
|
|
{
|
|
/**
|
|
* Handle the EntryFlag "created" event.
|
|
*/
|
|
public function creating(EntryFlag $entryFlag): void
|
|
{
|
|
if (in_array($entryFlag->flag_name, ['declined', 'no_show', 'failed_prelim'])) {
|
|
if ($entryFlag->entry->audition->hasFlag('seats_published') || $entryFlag->entry->audition->hasFlag('advancement_published')) {
|
|
throw new AuditionAdminException('Cannot change flag for published auditions.');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function created(EntryFlag $entryFlag): void
|
|
{
|
|
Doubler::syncDoublers();
|
|
Cache::forget('rank_advancement_'.$entryFlag->entry->audition_id);
|
|
Cache::forget('rank_seating_'.$entryFlag->entry->audition_id);
|
|
|
|
}
|
|
|
|
/**
|
|
* Handle the EntryFlag "updated" event.
|
|
*/
|
|
public function updated(EntryFlag $entryFlag): void
|
|
{
|
|
Doubler::syncDoublers();
|
|
Cache::forget('rank_advancement_'.$entryFlag->entry->audition_id);
|
|
Cache::forget('rank_seating_'.$entryFlag->entry->audition_id);
|
|
|
|
}
|
|
|
|
/**
|
|
* Handle the EntryFlag "deleted" event.
|
|
*/
|
|
public function deleting(EntryFlag $entryFlag): void
|
|
{
|
|
if (in_array($entryFlag->flag_name, ['declined', 'no_show', 'failed_prelim'])) {
|
|
if ($entryFlag->entry->audition->hasFlag('seats_published') || $entryFlag->entry->audition->hasFlag('advancement_published')) {
|
|
throw new AuditionAdminException('Cannot change flag for published auditions.');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function deleted(EntryFlag $entryFlag): void
|
|
{
|
|
Doubler::syncDoublers();
|
|
Cache::forget('rank_advancement_'.$entryFlag->entry->audition_id);
|
|
Cache::forget('rank_seating_'.$entryFlag->entry->audition_id);
|
|
|
|
}
|
|
|
|
/**
|
|
* Handle the EntryFlag "restored" event.
|
|
*/
|
|
public function restored(EntryFlag $entryFlag): void
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Handle the EntryFlag "force deleted" event.
|
|
*/
|
|
public function forceDeleted(EntryFlag $entryFlag): void
|
|
{
|
|
//
|
|
}
|
|
}
|