Initial work on seating page rewrite

This commit is contained in:
Matt Young 2025-06-12 23:28:31 -05:00
parent fd198a9972
commit 727d4d7048
8 changed files with 393 additions and 194 deletions

View File

@ -81,14 +81,14 @@ class EntryFlagController extends Controller
} }
DB::table('score_sheets')->where('entry_id', $entry->id)->delete(); DB::table('score_sheets')->where('entry_id', $entry->id)->delete();
$entry->addFlag('no_show');
ScoreSheet::where('entry_id', $entry->id)->delete(); ScoreSheet::where('entry_id', $entry->id)->delete();
CalculatedScore::where('entry_id', $entry->id)->delete();
BonusScore::where('entry_id', $entry->id)->delete(); BonusScore::where('entry_id', $entry->id)->delete();
if (request()->input('noshow-type') == 'failprelim') { if (request()->input('noshow-type') == 'failprelim') {
$msg = 'Failed prelim has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').'; $msg = 'Failed prelim has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').';
$entry->addFlag('failed_prelim'); $entry->addFlag('failed_prelim');
} else { } else {
$entry->addFlag('no_show');
$msg = 'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').'; $msg = 'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').';
} }

View File

@ -2,163 +2,75 @@
namespace App\Http\Controllers\Tabulation; namespace App\Http\Controllers\Tabulation;
use App\Actions\Entries\DoublerDecision;
use App\Actions\Tabulation\CalculateEntryScore;
use App\Actions\Tabulation\GetAuditionSeats; use App\Actions\Tabulation\GetAuditionSeats;
use App\Actions\Tabulation\RankAuditionEntries;
use App\Exceptions\AuditionAdminException;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Audition; use App\Models\Audition;
use App\Services\AuditionService;
use App\Services\DoublerService;
use App\Services\EntryService;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use function redirect;
class SeatAuditionFormController extends Controller class SeatAuditionFormController extends Controller
{ {
protected CalculateEntryScore $calc;
protected DoublerService $doublerService;
protected RankAuditionEntries $ranker;
protected EntryService $entryService;
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) public function __invoke(Request $request, Audition $audition)
{ {
// If a seating proposal was posted, deal wth it // Get scored entries in order
if ($request->method() == 'POST' && $request->input('ensembleAccept')) { $scored_entries = $audition->entries()
$requestedEnsembleAccepts = $request->input('ensembleAccept'); ->whereHas('totalScore')
} else { ->with('totalScore')
$requestedEnsembleAccepts = false; ->with('student.school')
} ->join('entry_total_scores', 'entries.id', '=', 'entry_total_scores.entry_id')
->orderBy('entry_total_scores.seating_total', 'desc')
->orderByRaw('COALESCE(JSON_EXTRACT(entry_total_scores.seating_subscore_totals, "$[0]"), -999999) DESC')
->orderByRaw('COALESCE(JSON_EXTRACT(entry_total_scores.seating_subscore_totals, "$[1]"), -999999) DESC')
->orderByRaw('COALESCE(JSON_EXTRACT(entry_total_scores.seating_subscore_totals, "$[2]"), -999999) DESC')
->orderByRaw('COALESCE(JSON_EXTRACT(entry_total_scores.seating_subscore_totals, "$[3]"), -999999) DESC')
->orderByRaw('COALESCE(JSON_EXTRACT(entry_total_scores.seating_subscore_totals, "$[4]"), -999999) DESC')
->orderByRaw('COALESCE(JSON_EXTRACT(entry_total_scores.seating_subscore_totals, "$[5]"), -999999) DESC')
->orderByRaw('COALESCE(JSON_EXTRACT(entry_total_scores.seating_subscore_totals, "$[6]"), -999999) DESC')
->orderByRaw('COALESCE(JSON_EXTRACT(entry_total_scores.seating_subscore_totals, "$[7]"), -999999) DESC')
->orderByRaw('COALESCE(JSON_EXTRACT(entry_total_scores.seating_subscore_totals, "$[8]"), -999999) DESC')
->orderByRaw('COALESCE(JSON_EXTRACT(entry_total_scores.seating_subscore_totals, "$[9]"), -999999) DESC')
->select('entries.*')
->get();
// Deal with a mass no-show request // Get unscored entries sorted by draw number
if ($request->input('mass-no-show')) { $unscored_entries = $audition->entries()
$entries = $audition->entries()->forSeating()->withCount('scoreSheets')->with('flags')->get(); ->whereDoesntHave('totalScore')
foreach ($entries as $entry) { ->whereDoesntHave('flags', function ($query) {
if ($entry->scoreSheets_count == 0 && ! $entry->hasFlag('no_show')) { $query->where('flag_name', 'no_show');
$entry->addFlag('no_show'); })
} ->whereDoesntHave('flags', function ($query) {
Cache::forget('entryScore-'.$entry->id.'-seating'); $query->where('flag_name', 'failed_prelim');
Cache::forget('entryScore-'.$entry->id.'-advancement'); })
} ->with('student.school')
Cache::forget('audition'.$audition->id.'seating'); ->orderBy('draw_number', 'asc')
Cache::forget('audition'.$audition->id.'advancement'); ->get();
}
$entryData = []; // Get no show entries sorted by draw number
$entries = $this->ranker->rank('seating', $audition); $noshow_entries = $audition->entries()
->whereDoesntHave('totalScore')
->whereHas('flags', function ($query) {
$query->where('flag_name', 'no_show');
})
->with('student.school')
->orderBy('draw_number', 'asc')
->get();
// Deal with mass decline doubler request // Get failed prelim entries sorted by draw number
if ($request->input('decline-below')) { $failed_prelim_entries = $audition->entries()
Cache::forget('audition'.$audition->id.'seating'); ->whereDoesntHave('totalScore')
->whereHas('flags', function ($query) {
$changes_made = false; $query->where('flag_name', 'failed_prelim');
foreach ($entries as $entry) { })
$doublerData = $this->doublerService->entryDoublerData($entry); ->with('student.school')
if ($doublerData && ! $entry->hasFlag('declined') && $entry->rank > $request->input('decline-below')) { ->orderBy('draw_number', 'asc')
try { ->get();
$this->decider->decline($entry);
$changes_made = true;
} catch (AuditionAdminException $e) {
return redirect()->back()->with('error', $e->getMessage());
}
}
}
if ($changes_made) {
$cache_key = 'event'.$audition->event_id.'doublers-seating';
Cache::forget($cache_key);
return redirect()->back();
}
}
$entries->load('student.school');
$entries->load('student.doublerRequests');
$seatable = [
'allScored' => true,
'doublersResolved' => true,
];
foreach ($entries as $entry) {
$totalScoreColumn = 'No Score';
$fullyScored = false;
if ($entry->score_totals) {
$totalScoreColumn = $entry->score_totals[0] >= 0 ? $entry->score_totals[0] : $entry->score_message;
$fullyScored = $entry->score_totals[0] >= 0;
}
// No Shows are fully scored
if ($entry->hasFlag('no_show')) {
$fullyScored = true;
}
$doublerData = $this->doublerService->entryDoublerData($entry);
$entryData[] = [
'rank' => $entry->rank,
'id' => $entry->id,
'studentName' => $entry->student->full_name(),
'schoolName' => $entry->student->school->name,
'drawNumber' => $entry->draw_number,
'totalScore' => $totalScoreColumn,
'fullyScored' => $fullyScored,
'hasBonusScores' => $entry->bonus_scores_count > 0,
'doubleData' => $doublerData,
'doublerRequest' => $entry->student->doublerRequests()->where('event_id',
$audition->event_id)->first()?->request,
];
// If this entries double decision isn't made, block seating
if ($doublerData && $doublerData[$entry->id]['status'] == 'undecided') {
$seatable['doublersResolved'] = false;
}
// If entry is unscored, block seating
if (! $fullyScored) {
$seatable['allScored'] = false;
}
}
$rightPanel = $this->pickRightPanel($audition, $seatable);
$seatableEntries = [];
if ($seatable['doublersResolved'] && $seatable['allScored']) {
$seatableEntries = $entries->reject(function ($entry) {
if ($entry->hasFlag('declined')) {
return true;
}
if ($entry->hasFlag('no_show')) {
return true;
}
if ($entry->hasFlag('failed_prelim')) {
return true;
}
return false;
});
}
return view('tabulation.auditionSeating', return view('tabulation.auditionSeating',
compact('entryData', 'audition', 'rightPanel', 'seatableEntries', 'requestedEnsembleAccepts')); compact('audition',
'scored_entries',
'unscored_entries',
'noshow_entries',
'failed_prelim_entries')
);
} }
protected function pickRightPanel(Audition $audition, array $seatable) protected function pickRightPanel(Audition $audition, array $seatable)

View File

@ -0,0 +1,180 @@
<?php
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;
use App\Services\DoublerService;
use App\Services\EntryService;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use function redirect;
class SeatAuditionFormControllerOLD extends Controller
{
protected CalculateEntryScore $calc;
protected DoublerService $doublerService;
protected RankAuditionEntries $ranker;
protected EntryService $entryService;
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' && $request->input('ensembleAccept')) {
$requestedEnsembleAccepts = $request->input('ensembleAccept');
} else {
$requestedEnsembleAccepts = false;
}
// Deal with a mass no-show request
if ($request->input('mass-no-show')) {
$entries = $audition->entries()->forSeating()->withCount('scoreSheets')->with('flags')->get();
foreach ($entries as $entry) {
if ($entry->scoreSheets_count == 0 && ! $entry->hasFlag('no_show')) {
$entry->addFlag('no_show');
}
Cache::forget('entryScore-'.$entry->id.'-seating');
Cache::forget('entryScore-'.$entry->id.'-advancement');
}
Cache::forget('audition'.$audition->id.'seating');
Cache::forget('audition'.$audition->id.'advancement');
}
$entryData = [];
$entries = $this->ranker->rank('seating', $audition);
// Deal with mass decline doubler request
if ($request->input('decline-below')) {
Cache::forget('audition'.$audition->id.'seating');
$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) {
$cache_key = 'event'.$audition->event_id.'doublers-seating';
Cache::forget($cache_key);
return redirect()->back();
}
}
$entries->load('student.school');
$entries->load('student.doublerRequests');
$seatable = [
'allScored' => true,
'doublersResolved' => true,
];
foreach ($entries as $entry) {
$totalScoreColumn = 'No Score';
$fullyScored = false;
if ($entry->score_totals) {
$totalScoreColumn = $entry->score_totals[0] >= 0 ? $entry->score_totals[0] : $entry->score_message;
$fullyScored = $entry->score_totals[0] >= 0;
}
// No Shows are fully scored
if ($entry->hasFlag('no_show')) {
$fullyScored = true;
}
$doublerData = $this->doublerService->entryDoublerData($entry);
$entryData[] = [
'rank' => $entry->rank,
'id' => $entry->id,
'studentName' => $entry->student->full_name(),
'schoolName' => $entry->student->school->name,
'drawNumber' => $entry->draw_number,
'totalScore' => $totalScoreColumn,
'fullyScored' => $fullyScored,
'hasBonusScores' => $entry->bonus_scores_count > 0,
'doubleData' => $doublerData,
'doublerRequest' => $entry->student->doublerRequests()->where('event_id',
$audition->event_id)->first()?->request,
];
// If this entries double decision isn't made, block seating
if ($doublerData && $doublerData[$entry->id]['status'] == 'undecided') {
$seatable['doublersResolved'] = false;
}
// If entry is unscored, block seating
if (! $fullyScored) {
$seatable['allScored'] = false;
}
}
$rightPanel = $this->pickRightPanel($audition, $seatable);
$seatableEntries = [];
if ($seatable['doublersResolved'] && $seatable['allScored']) {
$seatableEntries = $entries->reject(function ($entry) {
if ($entry->hasFlag('declined')) {
return true;
}
if ($entry->hasFlag('no_show')) {
return true;
}
if ($entry->hasFlag('failed_prelim')) {
return true;
}
return false;
});
}
return view('tabulation.auditionSeating',
compact('entryData', 'audition', 'rightPanel', 'seatableEntries', 'requestedEnsembleAccepts'));
}
protected function pickRightPanel(Audition $audition, array $seatable)
{
if ($audition->hasFlag('seats_published')) {
$resultsWindow = new GetAuditionSeats;
$rightPanel['view'] = 'tabulation.auditionSeating-show-published-seats';
$rightPanel['data'] = $resultsWindow($audition);
return $rightPanel;
}
if ($seatable['allScored'] == false || $seatable['doublersResolved'] == false) {
$rightPanel['view'] = 'tabulation.auditionSeating-unable-to-seat-card';
$rightPanel['data'] = $seatable;
return $rightPanel;
}
$rightPanel['view'] = 'tabulation.auditionSeating-right-complete-not-published';
$rightPanel['data'] = $this->auditionService->getSeatingLimits($audition);
return $rightPanel;
}
}

View File

@ -35,7 +35,7 @@ class Audition extends Model
public function unscoredEntries(): HasMany public function unscoredEntries(): HasMany
{ {
return $this->hasMany(Entry::class) return $this->hasMany(Entry::class)
->whereDoesntHave('scoreSheets') ->whereDoesntHave('totalScore')
->whereDoesntHave('flags', function ($query) { ->whereDoesntHave('flags', function ($query) {
$query->where('flag_name', 'no_show'); $query->where('flag_name', 'no_show');
}); });

View File

@ -15,36 +15,8 @@ class EntryFlag extends Model
'flag_name' => EntryFlags::class, 'flag_name' => EntryFlags::class,
]; ];
protected static function boot()
{
parent::boot();
static::created(function ($flag) {
$flag->deleteRelatedCalculatedScores();
});
static::updated(function ($flag) {
$flag->deleteRelatedCalculatedScores();
});
static::deleted(function ($flag) {
$flag->deleteRelatedCalculatedScores();
});
}
public function entry(): BelongsTo public function entry(): BelongsTo
{ {
return $this->belongsTo(Entry::class); return $this->belongsTo(Entry::class);
} }
public function deleteRelatedCalculatedScores(): void
{
$entry = $this->entry;
if ($entry) {
$entry->calculatedScores()->delete();
Cache::forget('entryScore-'.$entry->id.'-seating');
Cache::forget('entryScore-'.$entry->id.'-advancement');
Cache::forget('audition'.$entry->audition_id.'seating');
Cache::forget('audition'.$entry->audition_id.'advancement');
}
}
} }

View File

@ -127,7 +127,11 @@ class User extends Authenticatable implements MustVerifyEmail
public function isJudge(): bool public function isJudge(): bool
{ {
return $this->judgingAssignments()->count() > 0 || $this->bonusJudgingAssignments()->count() > 0; return once(function () {
return $this->judgingAssignments()->count() > 0
|| $this->bonusJudgingAssignments()->count() > 0;
});
} }
public function possibleSchools(): Collection public function possibleSchools(): Collection

View File

@ -1,29 +1,130 @@
@inject('doublerService','App\Services\DoublerService')
@php
$blockSeating = []
@endphp
<x-layout.app> <x-layout.app>
<x-slot:page_title>Audition Seating - {{ $audition->name }}</x-slot:page_title> <x-slot:page_title>Audition Seating - {{ $audition->name }}</x-slot:page_title>
<div class="grid grid-cols-4"></div> <div class="grid grid-cols-4"></div>
<div class="grid grid-cols-4"> <div class="grid grid-cols-4">
<div class="col-span-3">
@include('tabulation.auditionSeating-results-table') <div class="col-span-3"> {{-- Entry Ranking Table --}}
<x-card.card class="px-3"> {{-- Scored Entries --}}
<x-card.heading class="-ml-3">Scored Entries</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th>Rank</x-table.th>
<x-table.th>ID</x-table.th>
<x-table.th>Draw #</x-table.th>
<x-table.th>Student</x-table.th>
<x-table.th>Doubler</x-table.th>
<x-table.th>Total Score
@if($audition->bonusScore()->count() > 0)
<br>
<div class="display: flex">
<x-icons.checkmark color="green"/>
Has Bonus
</div> </div>
@endif
</x-table.th>
</tr>
</thead>
<tbody>
@foreach($scored_entries as $entry)
<tr>
<x-table.td>{{ $loop->iteration }}</x-table.td>
<x-table.td>{{ $entry->id }}</x-table.td>
<x-table.td>{{ $entry->draw_number }}</x-table.td>
<x-table.td class="flex flex-col">
<span>{{ $entry->student->full_name() }}</span>
<span class="text-xs text-gray-400">{{ $entry->student->school->name }}</span>
</x-table.td>
<x-table.td>Doubler to Come</x-table.td>
<x-table.td>{{ $entry->totalScore->seating_total }}</x-table.td>
</tr>
@endforeach
</tbody>
</x-table.table>
</x-card.card>
<x-card.card class="mt-3"> {{-- Unscored Entries --}}
<x-card.heading class="-ml-3">Unscored Entries</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th>Draw #</x-table.th>
<x-table.th>ID</x-table.th>
<x-table.th>Student</x-table.th>
</tr>
</thead>
<tbody>
@foreach($unscored_entries as $entry)
<tr>
<x-table.td>{{ $entry->draw_number }}</x-table.td>
<x-table.td>{{ $entry->id }}</x-table.td>
<x-table.td class="flex flex-col">
<span>{{ $entry->student->full_name() }}</span>
<span class="text-xs text-gray-400">{{ $entry->student->school->name }}</span>
</x-table.td>
</tr>
@endforeach
</tbody>
</x-table.table>
</x-card.card>
<x-card.card class="mt-3"> {{-- No Show Entries --}}
<x-card.heading class="-ml-3">No Show Entries</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th>Draw #</x-table.th>
<x-table.th>ID</x-table.th>
<x-table.th>Student</x-table.th>
</tr>
</thead>
<tbody>
@foreach($noshow_entries as $entry)
<tr>
<x-table.td>{{ $entry->draw_number }}</x-table.td>
<x-table.td>{{ $entry->id }}</x-table.td>
<x-table.td class="flex flex-col">
<span>{{ $entry->student->full_name() }}</span>
<span class="text-xs text-gray-400">{{ $entry->student->school->name }}</span>
</x-table.td>
</tr>
@endforeach
</tbody>
</x-table.table>
</x-card.card>
<x-card.card class="mt-3"> {{-- Failed Prelim Entries --}}
<x-card.heading class="-ml-3">Failed Prelim Entries</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th>Draw #</x-table.th>
<x-table.th>ID</x-table.th>
<x-table.th>Student</x-table.th>
</tr>
</thead>
<tbody>
@foreach($failed_prelim_entries as $entry)
<tr>
<x-table.td>{{ $entry->draw_number }}</x-table.td>
<x-table.td>{{ $entry->id }}</x-table.td>
<x-table.td class="flex flex-col">
<span>{{ $entry->student->full_name() }}</span>
<span class="text-xs text-gray-400">{{ $entry->student->school->name }}</span>
</x-table.td>
</tr>
@endforeach
</tbody>
</x-table.table>
</x-card.card>
</div>
<div class="ml-4"> <div class="ml-4">
@include($rightPanel['view']) Controls
</div> </div>
{{-- <div class="ml-4">--}}
{{-- @if($audition->hasFlag('seats_published'))--}}
{{-- @include('tabulation.auditionSeating-show-published-seats')--}}
{{-- @elseif(! $auditionComplete)--}}
{{-- @include('tabulation.auditionSeating-unable-to-seat-card')--}}
{{-- @else--}}
{{-- @include('tabulation.auditionSeating-fill-seats-form')--}}
{{-- @include('tabulation.auditionSeating-show-proposed-seats')--}}
{{-- @endif--}}
{{-- </div>--}}
</div> </div>

View File

@ -0,0 +1,30 @@
@inject('doublerService','App\Services\DoublerService')
@php
$blockSeating = []
@endphp
<x-layout.app>
<x-slot:page_title>Audition Seating - {{ $audition->name }}</x-slot:page_title>
<div class="grid grid-cols-4"></div>
<div class="grid grid-cols-4">
<div class="col-span-3">
@include('tabulation.auditionSeating-results-table')
</div>
<div class="ml-4">
@include($rightPanel['view'])
</div>
{{-- <div class="ml-4">--}}
{{-- @if($audition->hasFlag('seats_published'))--}}
{{-- @include('tabulation.auditionSeating-show-published-seats')--}}
{{-- @elseif(! $auditionComplete)--}}
{{-- @include('tabulation.auditionSeating-unable-to-seat-card')--}}
{{-- @else--}}
{{-- @include('tabulation.auditionSeating-fill-seats-form')--}}
{{-- @include('tabulation.auditionSeating-show-proposed-seats')--}}
{{-- @endif--}}
{{-- </div>--}}
</div>
</x-layout.app>