auditionCacheService = $auditionCacheService; $this->tabulationService = $tabulationService; } public function getDoublers(): \Illuminate\Database\Eloquent\Collection { return Cache::remember($this->doublersCacheKey, 10, function () { $students = Student::withCount('entries') ->with('entries') ->havingRaw('entries_count > ?', [1]) ->get(); return $students; }); } public function getDoublerInfo($id): Array { // When getting a doubler we need to know // 1) What their entrires are // 2) For each audition they're entered in, what is their rank // 3) For each audition they'er entered in, how many entries are unscored // 4) How many are accepted on that instrument $doubler = $this->getDoublers()->firstWhere('id',$id); $info = []; foreach ($doubler->entries as $entry) { $info[] = [ 'auditionID' => $entry->audition_id, 'auditionName' => $this->auditionCacheService->getAudition($entry->audition_id)->name, 'rank' => $this->tabulationService->entryRank($entry), 'unscored' => $this->tabulationService->remainingEntriesForAudition($entry->audition_id) ]; $entry->audition = $this->auditionCacheService->getAudition($entry->audition_id); } return $info; } public function entryIsDoubler(Entry $entry): bool { // Return true if $entry->student_id is associated with a student in the collection from $this->getDoublers() return $this->getDoublers()->contains('id', $entry->student_id); } }