From 3290687ba7bebf0c89d0dcfe2374433c54397476 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Tue, 18 Jun 2024 02:34:51 -0500 Subject: [PATCH] Doubler blocks displaying on seating page --- app/Services/DoublerService.php | 41 ++++++++++++++----- app/Services/ScoreService.php | 4 +- app/Services/TabulationService.php | 16 ++++++++ .../views/components/doubler-block.blade.php | 8 +--- .../tabulation/auditionSeating.blade.php | 8 +++- 5 files changed, 58 insertions(+), 19 deletions(-) diff --git a/app/Services/DoublerService.php b/app/Services/DoublerService.php index 9d47876..5406419 100644 --- a/app/Services/DoublerService.php +++ b/app/Services/DoublerService.php @@ -20,29 +20,43 @@ class DoublerService $this->tabulationService = $tabulationService; } + /** + * Returns a collection of students that have more than one entry + * @return \Illuminate\Database\Eloquent\Collection + */ public function getDoublers(): \Illuminate\Database\Eloquent\Collection { - return Cache::remember($this->doublersCacheKey, 10, function () { - $students = Student::withCount('entries') + // TODO creating or destroying an entry should refresh the doubler cache + return Cache::remember($this->doublersCacheKey, 3600, function () { + return Student::withCount('entries') ->with('entries') ->havingRaw('entries_count > ?', [1]) ->get(); - return $students; }); } - public function getDoublerInfo($id): Array + /** + * Returns an array of information about each entry for a specific doubler. Info for each entry includes + * auditionID + * auditionName + * rank => This student's rank in the given audition + * unscored => How many entries remain to be scored in this audition + * + * @param int $studentId The ID of the doubler + * @return array + */ + public function getDoublerInfo($studentId): array { // When getting a doubler we need to know - // 1) What their entrires are + // 1) What their entries 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 + // 3) For each audition they're entered in, how many entries are unscored // 4) How many are accepted on that instrument - $doubler = $this->getDoublers()->firstWhere('id',$id); + $doubler = $this->getDoublers()->firstWhere('id',$studentId); $info = []; foreach ($doubler->entries as $entry) { - $info[] = [ + $info[$entry->id] = [ 'auditionID' => $entry->audition_id, 'auditionName' => $this->auditionCacheService->getAudition($entry->audition_id)->name, 'rank' => $this->tabulationService->entryRank($entry), @@ -55,9 +69,14 @@ class DoublerService } - public function entryIsDoubler(Entry $entry): bool + /** + * Checks if a student is a doubler based on the given student ID + * + * @param int $studentId The ID of the student to check + * @return bool Returns true if the student is a doubler, false otherwise + */ + public function studentIsDoubler($studentId): 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); + return $this->getDoublers()->contains('id', $studentId); } } diff --git a/app/Services/ScoreService.php b/app/Services/ScoreService.php index 4cc71b7..8b9970d 100644 --- a/app/Services/ScoreService.php +++ b/app/Services/ScoreService.php @@ -99,7 +99,9 @@ class ScoreService { $audition = $this->auditionCache->getAudition($auditionId); $scoringGuideId = $audition->scoring_guide_id; - $entries = Entry::where('audition_id',$auditionId)->with('scoreSheets')->get(); +// $entries = Entry::where('audition_id',$auditionId)->with('scoreSheets')->get(); + $entries = $this->entryCache->getEntriesForAudition($auditionId); + $entries->load('scoreSheets'); foreach ($entries as $entry) { $cacheKey = 'entry' . $entry->id . 'totalScores'; diff --git a/app/Services/TabulationService.php b/app/Services/TabulationService.php index fed5744..e622290 100644 --- a/app/Services/TabulationService.php +++ b/app/Services/TabulationService.php @@ -28,10 +28,21 @@ class TabulationService $this->entryCacheService = $entryCacheService; } + /** + * Returns the rank of the entry in its audition + * @param Entry $entry + * @return mixed + */ public function entryRank(Entry $entry) { return $this->auditionEntries($entry->audition_id)[$entry->id]->rank; } + /** + * Returns a collection of entries including their calculated final_score_array and ranked + * based upon their scores. + * @param Int $auditionId + * @return \Illuminate\Support\Collection|mixed + */ public function auditionEntries(Int $auditionId) { static $cache = []; @@ -81,6 +92,11 @@ class TabulationService return true; } + /** + * Returns the number of un-scored entries for the audition with the given ID. + * @param $auditionId + * @return mixed + */ public function remainingEntriesForAudition($auditionId) { $audition = $this->getAuditionsWithStatus()[$auditionId]; diff --git a/resources/views/components/doubler-block.blade.php b/resources/views/components/doubler-block.blade.php index e3e4c90..ba301df 100644 --- a/resources/views/components/doubler-block.blade.php +++ b/resources/views/components/doubler-block.blade.php @@ -1,9 +1,5 @@ -@inject('doublers','\App\Services\DoublerService') -@inject('tabulation','\App\Services\TabulationService') -@props(['studentID']) -@php - $doublerEntryInfo = $doublers->getDoublerInfo($studentID); -@endphp +@props(['doublerEntryInfo']) +