diff --git a/app/Http/Controllers/Tabulation/DoublerDecisionController.php b/app/Http/Controllers/Tabulation/DoublerDecisionController.php index 7d95056..73141e5 100644 --- a/app/Http/Controllers/Tabulation/DoublerDecisionController.php +++ b/app/Http/Controllers/Tabulation/DoublerDecisionController.php @@ -36,7 +36,6 @@ class DoublerDecisionController extends Controller } } - $this->doublerService->refreshDoublerCache(); $returnMessage = $entry->student->full_name().' accepted seating in '.$entry->audition->name; @@ -52,8 +51,6 @@ class DoublerDecisionController extends Controller $entry->addFlag('declined'); - $this->doublerService->refreshDoublerCache(); - $returnMessage = $entry->student->full_name().' declined seating in '.$entry->audition->name; return redirect()->back()->with('success', $returnMessage); diff --git a/app/Http/Controllers/Tabulation/SeatAuditionController.php b/app/Http/Controllers/Tabulation/SeatAuditionController.php index fe1ced3..1dea67c 100644 --- a/app/Http/Controllers/Tabulation/SeatAuditionController.php +++ b/app/Http/Controllers/Tabulation/SeatAuditionController.php @@ -10,7 +10,6 @@ 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 { @@ -46,28 +45,6 @@ class SeatAuditionController extends Controller $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) { @@ -82,8 +59,7 @@ class SeatAuditionController extends Controller 'drawNumber' => $entry->draw_number, 'totalScore' => $totalScoreColumn, 'fullyScored' => $fullyScored, - 'isDoubler' => $isDoubler, - 'doubleData' => $doubleData ?? [], + 'doubleData' => $this->doublerService->entryDoublerData($entry), ]; } diff --git a/app/Services/AuditionService.php b/app/Services/AuditionService.php index 1e16873..09edccf 100644 --- a/app/Services/AuditionService.php +++ b/app/Services/AuditionService.php @@ -98,15 +98,15 @@ class AuditionService $limits = SeatingLimit::all(); foreach ($limits as $limit) { - $lims[$limit->audition_id][$limit->ensemble_id] = collect([ + $lims[$limit->audition_id][$limit->ensemble_id] = [ 'ensemble' => $ensembles->find($limit->ensemble_id), 'limit' =>$limit->maximum_accepted, - ]); + ]; } - return collect($lims); + return $lims; }); - return collect($allLimits[$audition->id]) ?? []; + return $allLimits[$audition->id] ?? []; } protected function validateAudition($audition) diff --git a/app/Services/DoublerService.php b/app/Services/DoublerService.php index 6601da8..bc97006 100644 --- a/app/Services/DoublerService.php +++ b/app/Services/DoublerService.php @@ -6,17 +6,29 @@ use App\Exceptions\TabulationException; use App\Models\Entry; use App\Models\Event; use App\Models\Student; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Cache; -/** - * returns a collection of doublers for the event in the form of - * [studentId => [student=>student, entries=>[entries]] - */ class DoublerService { + protected EntryService $entryService; + + protected AuditionService $auditionService; + + public function __construct(EntryService $entryService, AuditionService $auditionService) + { + $this->entryService = $entryService; + $this->auditionService = $auditionService; + } + + /** + * returns a collection of doublers for the event in the form of + * [studentId => [student=>student, entries=>[entries]] + */ public function doublersForEvent(Event $event, string $mode = 'seating') { $cacheKey = 'event'.$event->id.'doublers-'.$mode; + return Cache::remember($cacheKey, 60, function () use ($event, $mode) { return $this->findDoublersForEvent($event, $mode); }); @@ -25,7 +37,7 @@ class DoublerService /** * @throws TabulationException */ - protected function findDoublersForEvent(Event $event, string $mode): array + protected function findDoublersForEvent(Event $event, string $mode = 'seating'): array { $this->validateEvent($event); $entries = $event->entries; @@ -49,6 +61,59 @@ class DoublerService return $doubler_array; } + public function entryDoublerData(Entry $primaryEntry) + { + if (! isset($this->findDoublersForEvent($primaryEntry->audition->event)[$primaryEntry->student_id])) { + return false; + } + $entries = $this->findDoublersForEvent($primaryEntry->audition->event)[$primaryEntry->student_id]['entries']; + $entryData = collect([]); + /** @var Collection $entries */ + foreach ($entries as $entry) { + $status = 'undecided'; + if ($entry->hasFlag('declined')) { + $status = 'declined'; + } + if ($entry->hasFlag('no_show')) { + $status = 'no_show'; + } + + $lims = $this->auditionService->getSeatingLimits($entry->audition); + $limits = []; + foreach ($lims as $lim) { + $limits[] = [ + 'ensemble_name' => $lim['ensemble']->name, + 'accepts' => $lim['limit'], + 'ensemble' => $lim['ensemble'], + ]; + } + + $entryData[$entry->id] = [ + 'entry' => $entry, + 'audition' => $entry->audition, + 'auditionName' => $entry->audition->name, + 'status' => $status, + 'rank' => $this->entryService->rankOfEntry('seating', $entry), + 'unscored_entries' => $entry->audition->unscoredEntries()->count(), + 'seating_limits' => $limits, + ]; + } + // find out how many items in the collection $entryData have a status of 'undecided' + $undecided_count = $entryData->filter(fn ($entry) => $entry['status'] === 'undecided')->count(); + // if $undecided_count is 1 set the item where status is 'undecided' to 'accepted' + if ($undecided_count === 1) { + $entryData->transform(function ($entry) { + if ($entry['status'] === 'undecided') { + $entry['status'] = 'accepted'; + } + + return $entry; + }); + } + + return $entryData; + } + /** * @throws TabulationException */ diff --git a/app/Services/EntryService.php b/app/Services/EntryService.php index aa9ba17..0f719e0 100644 --- a/app/Services/EntryService.php +++ b/app/Services/EntryService.php @@ -40,6 +40,10 @@ class EntryService { $ranker = App::make(RankAuditionEntries::class); $rankings = $ranker->rank($mode, $entry->audition); + $rankedEntry = $rankings->find($entry->id); + if (isset($rankedEntry->score_message)) { + return $rankedEntry->score_message; + } return $rankings->find($entry->id)->rank ?? 'No Rank'; } } diff --git a/resources/views/tabulation/auditionSeating-doubler-block.blade.php b/resources/views/tabulation/auditionSeating-doubler-block.blade.php index 85ddbfa..9f7635d 100644 --- a/resources/views/tabulation/auditionSeating-doubler-block.blade.php +++ b/resources/views/tabulation/auditionSeating-doubler-block.blade.php @@ -6,9 +6,8 @@
- {{-- TODO put in link --}} - {{ $double['name'] }} - {{ $double['status'] }} + {{ $double['auditionName'] }} - {{ $double['status'] }}
Ranked {{ $double['rank'] }}
- -{{ $double['unscored_in_audition'] }} Unscored
+{{ $double['unscored_entries'] }} Unscored