diff --git a/app/Actions/Entries/DoublerDecision.php b/app/Actions/Entries/DoublerDecision.php new file mode 100644 index 0000000..2390925 --- /dev/null +++ b/app/Actions/Entries/DoublerDecision.php @@ -0,0 +1,66 @@ +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): void + { + // Decline all other entries + $doublerInfo = $this->doublerService->simpleDoubleInfo($entry); + foreach ($doublerInfo as $doublerEntry) { + /** @var Entry $doublerEntry */ + if ($doublerEntry->id !== $entry->id) { + $doublerEntry->addFlag('declined'); + } + } + } + + /** + * @throws AuditionAdminException + */ + public function decline($entry): void + { + if ($entry->hasFlag('declined')) { + throw new AuditionAdminException('Entry is already declined'); + } + + $entry->addFlag('declined'); + } +} diff --git a/app/Http/Controllers/Tabulation/DoublerDecisionController.php b/app/Http/Controllers/Tabulation/DoublerDecisionController.php index 4bc67ad..b9f876f 100644 --- a/app/Http/Controllers/Tabulation/DoublerDecisionController.php +++ b/app/Http/Controllers/Tabulation/DoublerDecisionController.php @@ -2,6 +2,8 @@ namespace App\Http\Controllers\Tabulation; +use App\Actions\Entries\DoublerDecision; +use App\Exceptions\AuditionAdminException; use App\Http\Controllers\Controller; use App\Models\Entry; use App\Services\DoublerService; @@ -14,21 +16,25 @@ class DoublerDecisionController extends Controller protected $entryService; - public function __construct(DoublerService $doublerService, EntryService $entryService) + protected $decider; + + public function __construct(DoublerService $doublerService, EntryService $entryService, DoublerDecision $decider) { $this->doublerService = $doublerService; $this->entryService = $entryService; + $this->decider = $decider; } public function accept(Entry $entry) { - $doublerInfo = $this->doublerService->simpleDoubleInfo($entry); - foreach ($doublerInfo as $doublerEntry) { - /** @var Entry $doublerEntry */ - if ($doublerEntry->id !== $entry->id) { - $doublerEntry->addFlag('declined'); - } - } + // $doublerInfo = $this->doublerService->simpleDoubleInfo($entry); + // foreach ($doublerInfo as $doublerEntry) { + // /** @var Entry $doublerEntry */ + // if ($doublerEntry->id !== $entry->id) { + // $doublerEntry->addFlag('declined'); + // } + // } + $this->decider->accept($entry); $returnMessage = $entry->student->full_name().' accepted seating in '.$entry->audition->name; $this->clearCache($entry); @@ -39,12 +45,16 @@ class DoublerDecisionController extends Controller public function decline(Entry $entry) { - if ($entry->hasFlag('declined')) { - return redirect()->back()->with('caution', 'Entry is already declined'); + // if ($entry->hasFlag('declined')) { + // return redirect()->back()->with('caution', 'Entry is already declined'); + // } + // + // $entry->addFlag('declined'); + try { + $this->decider->decline($entry); + } catch (AuditionAdminException $e) { + return redirect()->back()->with('error', $e->getMessage()); } - - $entry->addFlag('declined'); - $returnMessage = $entry->student->full_name().' declined seating in '.$entry->audition->name; $this->clearCache($entry); diff --git a/app/Http/Controllers/Tabulation/SeatAuditionFormController.php b/app/Http/Controllers/Tabulation/SeatAuditionFormController.php index b7f90f0..03b8a09 100644 --- a/app/Http/Controllers/Tabulation/SeatAuditionFormController.php +++ b/app/Http/Controllers/Tabulation/SeatAuditionFormController.php @@ -2,9 +2,11 @@ namespace App\Http\Controllers\Tabulation; +use App\Actions\Entries\DoublerDecision; use App\Actions\Tabulation\CalculateEntryScore; use App\Actions\Tabulation\GetAuditionSeats; use App\Actions\Tabulation\RankAuditionEntries; +use App\Exceptions\AuditionAdminException; use App\Http\Controllers\Controller; use App\Models\Audition; use App\Services\AuditionService; @@ -12,6 +14,8 @@ use App\Services\DoublerService; use App\Services\EntryService; use Illuminate\Http\Request; +use function redirect; + class SeatAuditionFormController extends Controller { protected CalculateEntryScore $calc; @@ -24,24 +28,28 @@ class SeatAuditionFormController extends Controller protected AuditionService $auditionService; + protected DoublerDecision $decider; + public function __construct( CalculateEntryScore $calc, RankAuditionEntries $ranker, DoublerService $doublerService, EntryService $entryService, AuditionService $auditionService, + DoublerDecision $decider, ) { $this->calc = $calc; $this->ranker = $ranker; $this->doublerService = $doublerService; $this->entryService = $entryService; $this->auditionService = $auditionService; + $this->decider = $decider; } public function __invoke(Request $request, Audition $audition) { // If a seating proposal was posted, deal wth it - if ($request->method() == 'POST') { + if ($request->method() == 'POST' && $request->input('ensembleAccept')) { $requestedEnsembleAccepts = $request->input('ensembleAccept'); } else { $requestedEnsembleAccepts = false; @@ -60,6 +68,23 @@ class SeatAuditionFormController extends Controller $entryData = []; $entries = $this->ranker->rank('seating', $audition); + if ($request->input('decline-below')) { + $changes_made = false; + foreach ($entries as $entry) { + $doublerData = $this->doublerService->entryDoublerData($entry); + if ($doublerData && ! $entry->hasFlag('declined') && $entry->rank > $request->input('decline-below')) { + try { + $this->decider->decline($entry); + $changes_made = true; + } catch (AuditionAdminException $e) { + return redirect()->back()->with('error', $e->getMessage()); + } + } + } + if ($changes_made) { + return redirect()->back(); + } + } $entries->load('student.school'); $entries->load('student.doublerRequests'); $seatable = [ @@ -78,6 +103,7 @@ class SeatAuditionFormController extends Controller $fullyScored = true; } $doublerData = $this->doublerService->entryDoublerData($entry); + $entryData[] = [ 'rank' => $entry->rank, 'id' => $entry->id, diff --git a/resources/views/tabulation/auditionSeating-unable-to-seat-card.blade.php b/resources/views/tabulation/auditionSeating-unable-to-seat-card.blade.php index a8d2ddf..cca0ef8 100644 --- a/resources/views/tabulation/auditionSeating-unable-to-seat-card.blade.php +++ b/resources/views/tabulation/auditionSeating-unable-to-seat-card.blade.php @@ -12,5 +12,9 @@ @endif @if(! $rightPanel['data']['doublersResolved'])

The audition cannot be seated while it has unresolved doublers.

+ + + Decline Doublers + @endif