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

81 lines
2.9 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\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;
public function __construct(
CalculateEntryScore $calc,
RankAuditionEntries $ranker,
DoublerService $doublerService,
EntryService $entryService
) {
$this->calc = $calc;
$this->ranker = $ranker;
$this->doublerService = $doublerService;
$this->entryService = $entryService;
}
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) {
Log::debug('doubler check for entry ' . $doublerEntry->id);
log::debug('Rank: ' . $this->entryService->rankOfEntry('seating', $doublerEntry));
$doubleData[] = [
'name' => $doublerEntry->audition->name,
'entryId' => $doublerEntry->id,
'rank' => $this->entryService->rankOfEntry('seating', $doublerEntry),
];
}
}
$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'));
}
}