From 115bd9b320d52e475f9f092a8601e06f576d9577 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Mon, 30 Jun 2025 17:58:04 -0500 Subject: [PATCH] Fix error in SeatAuditionFormController that resulted in all unresolved doublers being declined when doing mass declines. --- .../Tabulation/SeatAuditionFormController.php | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/Tabulation/SeatAuditionFormController.php b/app/Http/Controllers/Tabulation/SeatAuditionFormController.php index 5fde077..a212aa2 100644 --- a/app/Http/Controllers/Tabulation/SeatAuditionFormController.php +++ b/app/Http/Controllers/Tabulation/SeatAuditionFormController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Tabulation; +use App\Actions\Entries\DoublerDecision; use App\Actions\Tabulation\RankAuditionEntries; use App\Exceptions\AuditionAdminException; use App\Http\Controllers\Controller; @@ -19,7 +20,7 @@ use function redirect; class SeatAuditionFormController extends Controller { - public function showForm(Request $request, Audition $audition) + public function showForm(Audition $audition) { $seatingProposal = (session('proposedSeatingArray-'.$audition->id)); if ($audition->hasFlag('seats_published')) { @@ -36,7 +37,13 @@ class SeatAuditionFormController extends Controller $ranker = app(RankAuditionEntries::class); // Get scored entries in order - $scored_entries = $ranker($audition, 'seating'); + try { + $scored_entries = $ranker($audition, 'seating'); + } catch (AuditionAdminException $e) { + return redirect()->route('seating.audition', ['audition' => $audition->id]) + ->with('error', $e->getMessage()); + } + $scored_entries->load(['student.doublers', 'student.school']); // Get unscored entries sorted by draw number $unscored_entries = $audition->entries() @@ -49,7 +56,7 @@ class SeatAuditionFormController extends Controller }) ->with('student.school') ->withCount('scoreSheets') - ->orderBy('draw_number', 'asc') + ->orderBy('draw_number') ->get(); // Get no show entries sorted by draw number @@ -59,7 +66,7 @@ class SeatAuditionFormController extends Controller $query->where('flag_name', 'no_show'); }) ->with('student.school') - ->orderBy('draw_number', 'asc') + ->orderBy('draw_number') ->get(); // Get failed prelim entries sorted by draw number @@ -69,7 +76,7 @@ class SeatAuditionFormController extends Controller $query->where('flag_name', 'failed_prelim'); }) ->with('student.school') - ->orderBy('draw_number', 'asc') + ->orderBy('draw_number') ->get(); // Get Doublers @@ -110,8 +117,13 @@ class SeatAuditionFormController extends Controller public function declineSeat(Audition $audition, Entry $entry) { - $entry->addFlag('declined'); - Cache::forget('rank_seating_'.$entry->audition_id); + $decider = app(DoublerDecision::class); + try { + $decider->decline($entry); + } catch (AuditionAdminException $e) { + return redirect()->route('seating.audition', ['audition' => $audition->id]) + ->with('error', $e->getMessage()); + } return redirect()->route('seating.audition', ['audition' => $audition->id])->with('success', $entry->student->full_name().' has declined '.$audition->name); @@ -128,6 +140,11 @@ class SeatAuditionFormController extends Controller $scored_entries->load(['student.doublers', 'student.school']); foreach ($scored_entries as $entry) { Debugbar::info('Starting entry '.$entry->student->full_name()); + if ($entry->seatingRank < $validData['decline-below']) { + Debugbar::info('Skipping '.$entry->student->full_name().' because they are ranked above decline threshold'); + + continue; + } if ($entry->hasFlag('declined')) { Debugbar::info('Skipping '.$entry->student->full_name().' because they have already been declined');