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')); } }