getAuditionsWithStatus functin of TaultionService working

This commit is contained in:
Matt Young 2024-06-13 17:36:29 -05:00
parent 44cde39c16
commit b970828b31
2 changed files with 16 additions and 14 deletions

View File

@ -31,28 +31,31 @@ class TabulationService
public function getAuditionsWithStatus() public function getAuditionsWithStatus()
{ {
// Create an array with the number of scores for each entry
$scoreCountByEntry = DB::table('score_sheets') $scoreCountByEntry = DB::table('score_sheets')
->select('entry_id', DB::raw('count(*) as count')) ->select('entry_id', DB::raw('count(*) as count'))
->groupBy('entry_id') ->groupBy('entry_id')
->get() ->get()
->pluck('count','entry_id'); ->pluck('count','entry_id');
// Retrieve auditions from the cache and load entry IDs
$auditions = $this->auditionCacheService->getAuditions(); $auditions = $this->auditionCacheService->getAuditions();
$auditions->load(['entries' => function ($query) { $auditions->load('entries');
$query->select('id');
}]);
$auditions->loadCount('judges'); $auditions->loadCount('judges');
$auditions->loadCount('entries'); $auditions->loadCount('entries');
foreach ($auditions as $audition) foreach ($auditions as $audition) {
{ $audition->scored_entries_count = 0;
// Get the count of entries that have been scored foreach ($audition->entries as $entry) {
$audition->scored_entries = $audition->entries->filter(function ($entry) use ($scoreCountByEntry) { if ($audition->judges_count == $scoreCountByEntry[$entry->id]) {
return $entry->score_sheets_count == $scoreCountByEntry[$entry->id]; $entry->fully_scored = true;
}); $audition->scored_entries_count++;
// WHY WILL THIS NOT WORK????? } else {
$entry->fully_scored = false;
}
}
} }
return $auditions; return $auditions;
} }
} }

View File

@ -19,9 +19,8 @@
@foreach($auditions as $audition) @foreach($auditions as $audition)
@php @php
dd($audition->scored_entries);
@endphp @endphp
{{ $audition->name }} has {{ $audition->entries_count }} entries. {{ $audition->scored_entry_count }} are fully scored.<br> {{ $audition->name }} has {{ $audition->entries_count }} entries. {{ $audition->scored_entries_count }} are fully scored.<br>
@endforeach @endforeach