calc = $calc; $this->ranker = $ranker; $this->doublerService = $doublerService; $this->entryService = $entryService; $this->auditionService = $auditionService; $this->decider = $decider; } public function __invoke(Request $request, Audition $audition) { // If a seating proposal was posted, deal wth it if ($request->method() == 'POST' && $request->input('ensembleAccept')) { $requestedEnsembleAccepts = $request->input('ensembleAccept'); } else { $requestedEnsembleAccepts = false; } // Deal with a mass no-show request if ($request->input('mass-no-show')) { $entries = $audition->entries()->forSeating()->withCount('scoreSheets')->with('flags')->get(); foreach ($entries as $entry) { if ($entry->scoreSheets_count == 0 && ! $entry->hasFlag('no_show')) { $entry->addFlag('no_show'); } } } $entryData = []; $entries = $this->ranker->rank('seating', $audition); // Deal with mass decline doubler request if ($request->input('decline-below')) { $changes_made = false; foreach ($entries as $entry) { $doublerData = $this->doublerService->entryDoublerData($entry); if ($doublerData && ! $entry->hasFlag('declined') && $entry->rank > $request->input('decline-below')) { try { $this->decider->decline($entry); $changes_made = true; } catch (AuditionAdminException $e) { return redirect()->back()->with('error', $e->getMessage()); } } } if ($changes_made) { return redirect()->back(); } } $entries->load('student.school'); $entries->load('student.doublerRequests'); $seatable = [ 'allScored' => true, 'doublersResolved' => true, ]; foreach ($entries as $entry) { $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; } // No Shows are fully scored if ($entry->hasFlag('no_show')) { $fullyScored = true; } $doublerData = $this->doublerService->entryDoublerData($entry); $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, 'doubleData' => $doublerData, 'doublerRequest' => $entry->student->doublerRequests()->where('event_id', $audition->event_id)->first()?->request, ]; // If this entries double decision isn't made, block seating if ($doublerData && $doublerData[$entry->id]['status'] == 'undecided') { $seatable['doublersResolved'] = false; } // If entry is unscored, block seating if (! $fullyScored) { $seatable['allScored'] = false; } } $rightPanel = $this->pickRightPanel($audition, $seatable); $seatableEntries = []; if ($seatable['doublersResolved'] && $seatable['allScored']) { $seatableEntries = $entries->reject(function ($entry) { if ($entry->hasFlag('declined')) { return true; } if ($entry->hasFlag('no_show')) { return true; } if ($entry->hasFlag('failed_prelim')) { return true; } return false; }); } return view('tabulation.auditionSeating', compact('entryData', 'audition', 'rightPanel', 'seatableEntries', 'requestedEnsembleAccepts')); } 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; } }