116 lines
4.0 KiB
PHP
116 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Tabulation\Seating;
|
|
|
|
use App\Actions\Tabulation\RankAuditionEntries;
|
|
use App\Exceptions\AuditionAdminException;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Audition;
|
|
use App\Models\Doubler;
|
|
use App\Models\Seat;
|
|
|
|
use function redirect;
|
|
|
|
class ShowAuditionSeatingPage extends Controller
|
|
{
|
|
public function __invoke(Audition $audition)
|
|
{
|
|
$seatingProposal = (session('proposedSeatingArray-'.$audition->id));
|
|
if ($audition->hasFlag('seats_published')) {
|
|
$publishedSeats = Seat::where('audition_id', $audition->id)
|
|
->join('ensembles', 'seats.ensemble_id', '=', 'ensembles.id')
|
|
->orderBy('ensembles.rank')
|
|
->orderBy('seats.seat')
|
|
->select('seats.*')
|
|
->with(['ensemble', 'student.school'])
|
|
->get();
|
|
} else {
|
|
$publishedSeats = false;
|
|
}
|
|
|
|
$ranker = app(RankAuditionEntries::class);
|
|
// Get scored entries in order
|
|
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()
|
|
->whereDoesntHave('totalScore')
|
|
->whereDoesntHave('flags', function ($query) {
|
|
$query->where('flag_name', 'no_show');
|
|
})
|
|
->whereDoesntHave('flags', function ($query) {
|
|
$query->where('flag_name', 'failed_prelim');
|
|
})
|
|
->with('student.school')
|
|
->withCount('scoreSheets')
|
|
->orderBy('draw_number')
|
|
->get();
|
|
|
|
// Get no show entries sorted by draw number
|
|
$noshow_entries = $audition->entries()
|
|
->whereDoesntHave('totalScore')
|
|
->whereHas('flags', function ($query) {
|
|
$query->where('flag_name', 'no_show');
|
|
})
|
|
->with('student.school')
|
|
->orderBy('draw_number')
|
|
->get();
|
|
|
|
// Get failed prelim entries sorted by draw number
|
|
$failed_prelim_entries = $audition->entries()
|
|
->whereDoesntHave('totalScore')
|
|
->whereHas('flags', function ($query) {
|
|
$query->where('flag_name', 'failed_prelim');
|
|
})
|
|
->with('student.school')
|
|
->with('PrelimScoreSheets')
|
|
->orderBy('draw_number')
|
|
->get();
|
|
|
|
$failed_prelim_entries = $failed_prelim_entries->sortByDesc(function ($entry) {
|
|
return $entry->prelimTotalScore();
|
|
});
|
|
|
|
// Get Doublers
|
|
$doublerData = Doubler::where('event_id', $audition->event_id)
|
|
->whereIn('student_id', $scored_entries->pluck('student_id'))
|
|
->get()
|
|
->keyBy('student_id');
|
|
|
|
$auditionHasUnresolvedDoublers = false;
|
|
foreach ($doublerData as $doubler) {
|
|
if (! is_null($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.seating-page.auditionSeating',
|
|
compact('audition',
|
|
'scored_entries',
|
|
'unscored_entries',
|
|
'noshow_entries',
|
|
'failed_prelim_entries',
|
|
'doublerData',
|
|
'auditionHasUnresolvedDoublers',
|
|
'canSeat',
|
|
'seatingProposal',
|
|
'publishedSeats',
|
|
)
|
|
);
|
|
}
|
|
}
|