74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Actions\Entries;
|
|
|
|
use App\Exceptions\AuditionAdminException;
|
|
use App\Models\Entry;
|
|
use App\Services\DoublerService;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
class DoublerDecision
|
|
{
|
|
protected DoublerService $doublerService;
|
|
|
|
public function __construct(DoublerService $doublerService)
|
|
{
|
|
$this->doublerService = $doublerService;
|
|
}
|
|
|
|
/**
|
|
* @throws AuditionAdminException
|
|
*/
|
|
public function __invoke(Entry $entry, string $decision): void
|
|
{
|
|
$this->doublerDecision($entry, $decision);
|
|
}
|
|
|
|
/**
|
|
* @throws AuditionAdminException
|
|
*/
|
|
public function doublerDecision(Entry $entry, string $decision): void
|
|
{
|
|
match ($decision) {
|
|
'accept' => $this->accept($entry),
|
|
'decline' => $this->decline($entry),
|
|
default => throw new AuditionAdminException('Invalid decision specified')
|
|
};
|
|
|
|
if ($decision != 'accept' && $decision != 'decline') {
|
|
throw new AuditionAdminException('Invalid decision specified');
|
|
}
|
|
|
|
}
|
|
|
|
public function accept(Entry $entry): void
|
|
{
|
|
Cache::forget('audition'.$entry->audition_id.'seating');
|
|
Cache::forget('audition'.$entry->audition_id.'advancement');
|
|
|
|
// Decline all other entries and clear rank cache
|
|
$doublerInfo = $this->doublerService->simpleDoubleInfo($entry);
|
|
foreach ($doublerInfo as $doublerEntry) {
|
|
Cache::forget('audition'.$doublerEntry->audition_id.'seating');
|
|
/** @var Entry $doublerEntry */
|
|
if ($doublerEntry->id !== $entry->id) {
|
|
$doublerEntry->addFlag('declined');
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @throws AuditionAdminException
|
|
*/
|
|
public function decline($entry): void
|
|
{
|
|
Cache::forget('audition'.$entry->audition_id.'seating');
|
|
Cache::forget('audition'.$entry->audition_id.'advancement');
|
|
if ($entry->hasFlag('declined')) {
|
|
throw new AuditionAdminException('Entry is already declined');
|
|
}
|
|
Cache::forget('audition'.$entry->audition_id.'seating');
|
|
$entry->addFlag('declined');
|
|
}
|
|
}
|