auditionadmin/app/Http/Controllers/Tabulation/SeatAuditionFormController.php

108 lines
3.9 KiB
PHP

<?php
namespace App\Http\Controllers\Tabulation;
use App\Actions\Tabulation\GetAuditionSeats;
use App\Actions\Tabulation\RankAuditionEntries;
use App\Http\Controllers\Controller;
use App\Models\Audition;
use Illuminate\Http\Request;
class SeatAuditionFormController extends Controller
{
public function showForm(Request $request, Audition $audition)
{
$ranker = app(RankAuditionEntries::class);
// Get scored entries in order
$scored_entries = $ranker($audition, 'seating');
// 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')
->orderBy('draw_number', 'asc')
->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', 'asc')
->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')
->orderBy('draw_number', 'asc')
->get();
// Get Doubler Data
$doubler_data = [];
foreach ($scored_entries as $e) {
if ($e->student->isDoublerInEvent($audition->event_id)) {
// get the other entries for this student
$doubler_data[$e->id]['entries'] = $e->student->entriesForEvent($e->audition->event_id);
// How many of this student's entries have been declined
$declined_count = $doubler_data[$e->id]['entries']->filter(function ($entry) {
return $entry->hasFlag('declined');
})->count();
// set status
// declined status is easy
if ($e->hasFlag('declined')) {
$doubler_data[$e->id]['status'] = 'declined';
} elseif ($doubler_data[$e->id]['entries']->count() - $declined_count == 1) {
$doubler_data[$e->id]['status'] = 'accepted';
} else {
$doubler_data[$e->id]['status'] = 'undecided';
}
}
}
return view('tabulation.auditionSeating',
compact('audition',
'scored_entries',
'unscored_entries',
'noshow_entries',
'failed_prelim_entries',
'doubler_data', )
);
}
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;
}
}