From f067dfbe84d039d326255345bf40c7b211d8c1bf Mon Sep 17 00:00:00 2001 From: Matt Young Date: Fri, 28 Jun 2024 20:54:08 -0500 Subject: [PATCH] Add advancement results to results page --- app/Http/Controllers/ResultsPage.php | 23 +++++++++- app/Models/Student.php | 3 +- app/Services/AuditionCacheService.php | 12 ++++++ .../views/components/results/layout.blade.php | 2 +- .../results/table-audition-section.blade.php | 2 +- .../results/table-qualifier-row.blade.php | 7 ++++ .../results/table-seat-row.blade.php | 4 +- resources/views/results/index.blade.php | 42 +++++++++++++------ 8 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 resources/views/components/results/table-qualifier-row.blade.php diff --git a/app/Http/Controllers/ResultsPage.php b/app/Http/Controllers/ResultsPage.php index 326d5f6..c00f5e5 100644 --- a/app/Http/Controllers/ResultsPage.php +++ b/app/Http/Controllers/ResultsPage.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\Entry; use App\Models\Seat; use App\Services\AuditionCacheService; use App\Services\SeatingService; @@ -28,6 +29,8 @@ class ResultsPage extends Controller $publishedAuditions = $this->auditionCacheService->getPublishedAuditions(); $resultsSeatList = Cache::rememberForever('resultsSeatList', function () use ($publishedAuditions) { $seatList = []; + // Load the $seatList in the form of $seatlist[audition_id] is an array of seats for that audition + // each $seatList[audition_id][] will contain a string with ensemble and seat number and the student object filling it foreach ($publishedAuditions as $audition) { $seats = $this->seatingService->getSeatsForAudition($audition->id); $ensembles = $this->seatingService->getEnsemblesForEvent($audition->event_id); @@ -48,6 +51,24 @@ class ResultsPage extends Controller return $seatList; }); - return view('results.index', compact('publishedAuditions', 'resultsSeatList')); + $publishedAdvancementAuditions = $this->auditionCacheService->getPublishedAdvancementAuditions(); + $resultsAdvancementList = Cache::rememberForever('resultsAdvancementList', function () use ($publishedAdvancementAuditions) { + $qualifierList = []; + foreach ($publishedAdvancementAuditions as $audition) { + $qualifierList[$audition->id] = Entry::with('flags', 'student.school') + ->where('audition_id', $audition->id) + ->where('for_advancement', true) + ->get()->filter(function (Entry $entry) { + return $entry->hasFlag('will_advance'); + }) + ->sortBy(function (Entry $entry) { + return $entry->student->full_name(true); + }); + } + + return $qualifierList; + }); + + return view('results.index', compact('publishedAuditions', 'resultsSeatList', 'resultsAdvancementList', 'publishedAdvancementAuditions')); } } diff --git a/app/Models/Student.php b/app/Models/Student.php index 454cfb9..f93465b 100644 --- a/app/Models/Student.php +++ b/app/Models/Student.php @@ -32,9 +32,8 @@ class Student extends Model public function full_name(bool $last_name_first = false): string { if ($last_name_first) { - return $this->last_name.', '.$this->first_name; + return ($this->last_name.', '.$this->first_name); } - return $this->first_name.' '.$this->last_name; } } diff --git a/app/Services/AuditionCacheService.php b/app/Services/AuditionCacheService.php index 12968cc..46e5b32 100644 --- a/app/Services/AuditionCacheService.php +++ b/app/Services/AuditionCacheService.php @@ -87,6 +87,18 @@ class AuditionCacheService }); } + public function getPublishedAdvancementAuditions() + { + $cacheKey = 'publishedAdvancementAuditions'; + return Cache::remember( + $cacheKey, + now()->addHour(), + function () { + return Audition::with('flags')->orderBy('score_order')->get()->filter(fn ($audition) => $audition->hasFlag('advancement_published')); + }); + + } + public function clearPublishedAuditionsCache(): void { Cache::forget('publishedAuditions'); diff --git a/resources/views/components/results/layout.blade.php b/resources/views/components/results/layout.blade.php index de256c0..2d2e67c 100644 --- a/resources/views/components/results/layout.blade.php +++ b/resources/views/components/results/layout.blade.php @@ -35,7 +35,7 @@ -
+
{{ $slot }} diff --git a/resources/views/components/results/table-audition-section.blade.php b/resources/views/components/results/table-audition-section.blade.php index 2f33821..2f92546 100644 --- a/resources/views/components/results/table-audition-section.blade.php +++ b/resources/views/components/results/table-audition-section.blade.php @@ -7,7 +7,7 @@

Click to open

-
diff --git a/resources/views/components/results/table-qualifier-row.blade.php b/resources/views/components/results/table-qualifier-row.blade.php new file mode 100644 index 0000000..a883e6d --- /dev/null +++ b/resources/views/components/results/table-qualifier-row.blade.php @@ -0,0 +1,7 @@ +@props(['student_name','school']) +
  • class(['flex gap-x-4 px-3 py-2 justify-between bg-gray-50 border-x border-b shadow']) }}> + +

    {{ htmlspecialchars_decode($student_name) }}

    +

    {{ $school }}

    + +
  • diff --git a/resources/views/components/results/table-seat-row.blade.php b/resources/views/components/results/table-seat-row.blade.php index 017166b..903502d 100644 --- a/resources/views/components/results/table-seat-row.blade.php +++ b/resources/views/components/results/table-seat-row.blade.php @@ -1,8 +1,10 @@ -@props(['seat','student_name','school']) +@props(['seat', 'student_name','school'])
  • class(['flex gap-x-4 px-3 py-2 justify-between bg-gray-50 border-x border-b shadow']) }}> +
    {{ $seat }}
    +

    {{ $student_name }}

    {{ $school }}

    diff --git a/resources/views/results/index.blade.php b/resources/views/results/index.blade.php index 3f252ca..f2383ce 100644 --- a/resources/views/results/index.blade.php +++ b/resources/views/results/index.blade.php @@ -1,16 +1,34 @@ - - +
    + @endif + + +