diff --git a/app/Actions/Tabulation/EnterScore.php b/app/Actions/Tabulation/EnterScore.php index 17b87fa..e38faa8 100644 --- a/app/Actions/Tabulation/EnterScore.php +++ b/app/Actions/Tabulation/EnterScore.php @@ -9,6 +9,7 @@ namespace App\Actions\Tabulation; use App\Exceptions\ScoreEntryException; use App\Models\AuditLogEntry; use App\Models\Entry; +use App\Models\EntryTotalScore; use App\Models\ScoreSheet; use App\Models\User; use Illuminate\Support\Facades\DB; @@ -28,8 +29,7 @@ class EnterScore */ public function __invoke(User $user, Entry $entry, array $scores, ScoreSheet|false $scoreSheet = false): ScoreSheet { - // TODO: Remove the CalculatedScore model and table when rewrite is complete, they'll be obsolete - // CalculatedScore::where('entry_id', $entry->id)->delete(); + EntryTotalScore::where('entry_id', $entry->id)->delete(); $scores = collect($scores); // Basic Validity Checks diff --git a/app/Actions/Tabulation/RankAuditionEntries.php b/app/Actions/Tabulation/RankAuditionEntries.php index 5e18fb7..77fd90d 100644 --- a/app/Actions/Tabulation/RankAuditionEntries.php +++ b/app/Actions/Tabulation/RankAuditionEntries.php @@ -42,7 +42,7 @@ class RankAuditionEntries private function get_seating_ranks(Audition $audition): Collection { - return $audition->entries() + $sortedEntries = $audition->entries() ->whereHas('totalScore') ->with('totalScore') ->with('student.school') @@ -61,6 +61,18 @@ class RankAuditionEntries ->orderByRaw('COALESCE(JSON_EXTRACT(entry_total_scores.seating_subscore_totals, "$[9]"), -999999) DESC') ->select('entries.*') ->get(); + + $rankOn = 1; + foreach ($sortedEntries as $entry) { + if ($entry->hasFlag('declined')) { + $entry->seatingRank = 'declined'; + } else { + $entry->seatingRank = $rankOn; + $rankOn++; + } + } + + return $sortedEntries; } private function get_advancement_ranks(Audition $audition): Collection diff --git a/app/Http/Controllers/Tabulation/ScoreController.php b/app/Http/Controllers/Tabulation/ScoreController.php index b7e2013..b4863a8 100644 --- a/app/Http/Controllers/Tabulation/ScoreController.php +++ b/app/Http/Controllers/Tabulation/ScoreController.php @@ -5,8 +5,8 @@ namespace App\Http\Controllers\Tabulation; use App\Actions\Tabulation\EnterScore; use App\Exceptions\ScoreEntryException; use App\Http\Controllers\Controller; -use App\Models\CalculatedScore; use App\Models\Entry; +use App\Models\EntryTotalScore; use App\Models\ScoreSheet; use App\Models\User; use Illuminate\Http\Request; @@ -25,7 +25,7 @@ class ScoreController extends Controller public function destroyScore(ScoreSheet $score) { - CalculatedScore::where('entry_id', $score->entry_id)->delete(); + EntryTotalScore::where('entry_id', $score->entry_id)->delete(); if ($score->entry->audition->hasFlag('seats_published')) { return redirect()->back()->with('error', 'Cannot delete scores for an entry where seats are published'); } diff --git a/app/Http/Controllers/Tabulation/SeatAuditionFormController.php b/app/Http/Controllers/Tabulation/SeatAuditionFormController.php index c83b59d..f0bb00c 100644 --- a/app/Http/Controllers/Tabulation/SeatAuditionFormController.php +++ b/app/Http/Controllers/Tabulation/SeatAuditionFormController.php @@ -10,6 +10,9 @@ use App\Models\Audition; use App\Models\Doubler; use App\Models\Entry; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Cache; + +use function PHPUnit\Framework\isNull; class SeatAuditionFormController extends Controller { @@ -58,19 +61,38 @@ class SeatAuditionFormController extends Controller ->get() ->keyBy('student_id'); + $auditionHasUnresolvedDoublers = false; + foreach ($doublerData as $doubler) { + if (! isNull($doubler->accepted_entry)) { + continue; + } + foreach ($doubler->entries() as $entry) { + if ($entry->audition_id === $audition->id && $entry->hasFlag('declined')) { + continue 2; + } + } + $auditionHasUnresolvedDoublers = true; + } + + $canSeat = ! $auditionHasUnresolvedDoublers && $unscored_entries->count() === 0; + return view('tabulation.auditionSeating', compact('audition', 'scored_entries', 'unscored_entries', 'noshow_entries', 'failed_prelim_entries', - 'doublerData') + 'doublerData', + 'auditionHasUnresolvedDoublers', + 'canSeat', + ) ); } public function declineSeat(Audition $audition, Entry $entry) { $entry->addFlag('declined'); + Cache::forget('rank_seating_'.$entry->audition_id); return redirect()->route('seating.audition', ['audition' => $audition->id])->with('success', $entry->student->full_name().' has declined '.$audition->name); @@ -86,6 +108,7 @@ class SeatAuditionFormController extends Controller } } foreach ($doublerData->entries() as $doublerEntry) { + Cache::forget('rank_seating_'.$doublerEntry->audition_id); if ($doublerEntry->id !== $entry->id && ! $doublerEntry->hasFlag('no_show') && ! $doublerEntry->hasFlag('failed_prelim') && ! $doublerEntry->hasFlag('declined')) { $doublerEntry->addFlag('declined'); } diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 4b1cc64..b7c0e82 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -45,6 +45,11 @@ class Entry extends Model // Get the ranked entries for this entries audition $rankedEntries = $ranker($this->audition, $type); + // If we're looking for seating rank, return the rank from the list of ranked entries + if ($type === 'seating') { + return $rankedEntries->where('id', $this->id)->first()->seatingRank; + } + // Find position of current entry in the ranked entries (1-based index) $position = $rankedEntries->search(fn ($entry) => $entry->id === $this->id); diff --git a/app/Observers/EntryFlagObserver.php b/app/Observers/EntryFlagObserver.php index e66d8cc..7747ca1 100644 --- a/app/Observers/EntryFlagObserver.php +++ b/app/Observers/EntryFlagObserver.php @@ -13,6 +13,7 @@ class EntryFlagObserver public function created(EntryFlag $entryFlag): void { Doubler::syncDoublers(); + } /** diff --git a/app/Observers/ScoreSheetObserver.php b/app/Observers/ScoreSheetObserver.php index ceb8711..0b419af 100644 --- a/app/Observers/ScoreSheetObserver.php +++ b/app/Observers/ScoreSheetObserver.php @@ -2,7 +2,7 @@ namespace App\Observers; -use App\Events\ScoreSheetChange; +use App\Actions\Tabulation\TotalEntryScores; use App\Models\ScoreSheet; class ScoreSheetObserver @@ -12,7 +12,8 @@ class ScoreSheetObserver */ public function created(ScoreSheet $scoreSheet): void { - // + $calculator = app(TotalEntryScores::class); + $calculator($scoreSheet->entry, true); } /** diff --git a/resources/views/admin/students/edit.blade.php b/resources/views/admin/students/edit.blade.php index c908aa4..e7df592 100644 --- a/resources/views/admin/students/edit.blade.php +++ b/resources/views/admin/students/edit.blade.php @@ -55,7 +55,7 @@ @foreach($event_entries[$event->id] as $entry)