diff --git a/app/Services/TabulationService.php b/app/Services/TabulationService.php index ed674ec..d6e736e 100644 --- a/app/Services/TabulationService.php +++ b/app/Services/TabulationService.php @@ -31,28 +31,31 @@ class TabulationService public function getAuditionsWithStatus() { + // Create an array with the number of scores for each entry $scoreCountByEntry = DB::table('score_sheets') ->select('entry_id', DB::raw('count(*) as count')) ->groupBy('entry_id') ->get() ->pluck('count','entry_id'); + + // Retrieve auditions from the cache and load entry IDs $auditions = $this->auditionCacheService->getAuditions(); - $auditions->load(['entries' => function ($query) { - $query->select('id'); - }]); + $auditions->load('entries'); + $auditions->loadCount('judges'); $auditions->loadCount('entries'); - foreach ($auditions as $audition) - { - // Get the count of entries that have been scored - $audition->scored_entries = $audition->entries->filter(function ($entry) use ($scoreCountByEntry) { - return $entry->score_sheets_count == $scoreCountByEntry[$entry->id]; - }); - // WHY WILL THIS NOT WORK????? - + foreach ($auditions as $audition) { + $audition->scored_entries_count = 0; + foreach ($audition->entries as $entry) { + if ($audition->judges_count == $scoreCountByEntry[$entry->id]) { + $entry->fully_scored = true; + $audition->scored_entries_count++; + } else { + $entry->fully_scored = false; + } + } } - return $auditions; } } diff --git a/resources/views/test.blade.php b/resources/views/test.blade.php index 004afd5..1b23bf3 100644 --- a/resources/views/test.blade.php +++ b/resources/views/test.blade.php @@ -19,9 +19,8 @@ @foreach($auditions as $audition) @php - dd($audition->scored_entries); @endphp - {{ $audition->name }} has {{ $audition->entries_count }} entries. {{ $audition->scored_entry_count }} are fully scored.
+ {{ $audition->name }} has {{ $audition->entries_count }} entries. {{ $audition->scored_entries_count }} are fully scored.
@endforeach