93 lines
3.4 KiB
PHP
93 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Tabulation;
|
|
|
|
use App\Actions\Tabulation\CalculateEntryScore;
|
|
use App\Actions\Tabulation\RankAuditionEntries;
|
|
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\Log;
|
|
|
|
class SeatAuditionController extends Controller
|
|
{
|
|
protected CalculateEntryScore $calc;
|
|
|
|
protected DoublerService $doublerService;
|
|
|
|
protected RankAuditionEntries $ranker;
|
|
|
|
protected EntryService $entryService;
|
|
|
|
protected AuditionService $auditionService;
|
|
|
|
public function __construct(
|
|
CalculateEntryScore $calc,
|
|
RankAuditionEntries $ranker,
|
|
DoublerService $doublerService,
|
|
EntryService $entryService,
|
|
AuditionService $auditionService,
|
|
) {
|
|
$this->calc = $calc;
|
|
$this->ranker = $ranker;
|
|
$this->doublerService = $doublerService;
|
|
$this->entryService = $entryService;
|
|
$this->auditionService = $auditionService;
|
|
}
|
|
|
|
public function __invoke(Request $request, Audition $audition)
|
|
{
|
|
$doublers = $this->doublerService->doublersForEvent($audition->event);
|
|
$entryData = [];
|
|
$entries = $this->ranker->rank('seating', $audition);
|
|
$entries->load('student.school');
|
|
|
|
foreach ($entries as $entry) {
|
|
$isDoubler = false;
|
|
if (array_key_exists($entry->student->id, $doublers)) {
|
|
$isDoubler = true;
|
|
$doubleData = [];
|
|
$doublerEntries = $doublers[$entry->student->id]['entries'];
|
|
|
|
foreach ($doublerEntries as $doublerEntry) {
|
|
$limits = $this->auditionService->getSeatingLimits($doublerEntry->audition);
|
|
$limits = $limits->reject(function ($lim) {
|
|
return $lim['limit'] === 0;
|
|
});
|
|
$doubleData[] = [
|
|
'audition' => $doublerEntry->audition,
|
|
'name' => $doublerEntry->audition->name,
|
|
'entryId' => $doublerEntry->id,
|
|
'rank' => $this->entryService->rankOfEntry('seating', $doublerEntry),
|
|
'limits' => $limits,
|
|
'status' => 'undecided', // Will be undecided, accepted, or declined
|
|
'unscored_in_audition' => $doublerEntry->audition->unscoredEntries()->count(),
|
|
];
|
|
}
|
|
}
|
|
$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;
|
|
}
|
|
$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,
|
|
'isDoubler' => $isDoubler,
|
|
'doubleData' => $doubleData ?? [],
|
|
];
|
|
}
|
|
|
|
return view('tabulation.auditionSeating', compact('entryData', 'audition', 'doublers'));
|
|
}
|
|
}
|