diff --git a/app/Actions/Tabulation/AllJudgesCount.php b/app/Actions/Tabulation/AllJudgesCount.php index aa76b98..e154359 100644 --- a/app/Actions/Tabulation/AllJudgesCount.php +++ b/app/Actions/Tabulation/AllJudgesCount.php @@ -13,7 +13,9 @@ use Illuminate\Support\Facades\Cache; class AllJudgesCount implements CalculateEntryScore { protected CalculateScoreSheetTotal $calculator; + protected AuditionService $auditionService; + protected EntryService $entryService; public function __construct(CalculateScoreSheetTotal $calculator, AuditionService $auditionService, EntryService $entryService) @@ -27,6 +29,7 @@ class AllJudgesCount implements CalculateEntryScore { $cacheKey = 'entryScore-'.$entry->id.'-'.$mode; + return Cache::remember($cacheKey, 10, function () use ($mode, $entry) { $this->basicValidation($mode, $entry); $this->areAllJudgesIn($entry); @@ -54,6 +57,7 @@ class AllJudgesCount implements CalculateEntryScore $index++; } } + return $sums; } @@ -78,8 +82,8 @@ class AllJudgesCount implements CalculateEntryScore protected function areAllJudgesValid(Entry $entry): void { - $validJudgeIds = $this->auditionService->getJudges($entry->audition)->sort()->pluck('id')->toArray(); - $existingJudgeIds = $entry->scoreSheets->sort()->pluck('user_id')->toArray(); + $validJudgeIds = $this->auditionService->getJudges($entry->audition)->pluck('id')->sort()->toArray(); + $existingJudgeIds = $entry->scoreSheets->pluck('user_id')->sort()->toArray(); if ($validJudgeIds !== $existingJudgeIds) { throw new TabulationException('Score exists from a judge not assigned to this audition'); } diff --git a/app/Actions/Tabulation/AllowForOlympicScoring.php b/app/Actions/Tabulation/AllowForOlympicScoring.php index 82bfecc..16f2451 100644 --- a/app/Actions/Tabulation/AllowForOlympicScoring.php +++ b/app/Actions/Tabulation/AllowForOlympicScoring.php @@ -10,6 +10,7 @@ use App\Models\Entry; use App\Services\AuditionService; use App\Services\EntryService; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Log; use function auditionSetting; @@ -124,9 +125,12 @@ class AllowForOlympicScoring implements CalculateEntryScore protected function areAllJudgesValid(Entry $entry): void { - $validJudgeIds = $this->auditionService->getJudges($entry->audition)->sort()->pluck('id')->toArray(); - $existingJudgeIds = $entry->scoreSheets->sort()->pluck('user_id')->toArray(); - if ($validJudgeIds !== $existingJudgeIds) { + $validJudgeIds = $this->auditionService->getJudges($entry->audition)->pluck('id')->toArray(); + $existingJudgeIds = $entry->scoreSheets->pluck('user_id')->toArray(); + if (array_diff($existingJudgeIds, $validJudgeIds)) { + Log::debug('EntryID: '.$entry->id); + Log::debug('Valid judge ids: ('.gettype($validJudgeIds).') '.json_encode($validJudgeIds)); + Log::debug('Existing judge ids: ('.gettype($existingJudgeIds).') '.json_encode($existingJudgeIds)); throw new TabulationException('Score exists from a judge not assigned to this audition'); } } diff --git a/app/Http/Controllers/ResultsPage.php b/app/Http/Controllers/ResultsPage.php index d06c7fd..d6fdd2f 100644 --- a/app/Http/Controllers/ResultsPage.php +++ b/app/Http/Controllers/ResultsPage.php @@ -2,10 +2,11 @@ namespace App\Http\Controllers; +use App\Models\Audition; +use App\Models\Ensemble; use App\Models\Entry; use App\Models\Seat; use App\Services\AuditionService; -use App\Services\SeatingService; use Illuminate\Http\Request; use Illuminate\Support\Facades\Cache; @@ -13,12 +14,9 @@ class ResultsPage extends Controller { protected $auditionService; - protected $seatingService; - - public function __construct(AuditionService $auditionService, SeatingService $seatingService) + public function __construct(AuditionService $auditionService) { $this->auditionService = $auditionService; - $this->seatingService = $seatingService; } /** @@ -26,14 +24,18 @@ class ResultsPage extends Controller */ public function __invoke(Request $request) { - $publishedAuditions = $this->auditionService->getPublishedAuditions(); + $publishedAuditions = Audition::seatsPublished() + ->with('seats.ensemble') + ->with('seats.entry.student') + ->with('event.ensembles') + ->orderBy('score_order')->get(); $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); + $seats = $audition->seats->groupBy('ensemble_id'); + $ensembles = $audition->event->ensembles; foreach ($ensembles as $ensemble) { if (! $seats->has($ensemble->id)) { // If there are no students seated in this ensemble, skip it continue; @@ -51,24 +53,24 @@ class ResultsPage extends Controller return $seatList; }); - $publishedAdvancementAuditions = $this->auditionService->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); - }); - } + // $publishedAdvancementAuditions = $this->auditionService->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 $qualifierList; - }); - - return view('results.index', compact('publishedAuditions', 'resultsSeatList', 'resultsAdvancementList', 'publishedAdvancementAuditions')); + return view('results.index', compact('publishedAuditions', 'resultsSeatList')); } } diff --git a/app/Models/Audition.php b/app/Models/Audition.php index e7a243b..8531885 100644 --- a/app/Models/Audition.php +++ b/app/Models/Audition.php @@ -121,6 +121,11 @@ class Audition extends Model $this->load('flags'); } + public function seats(): HasMany + { + return $this->hasMany(Seat::class); + } + public function scopeOpen(Builder $query): void { $query->where('entry_deadline', '>=', Carbon::now()); diff --git a/resources/views/results/index.blade.php b/resources/views/results/index.blade.php index f2383ce..9623662 100644 --- a/resources/views/results/index.blade.php +++ b/resources/views/results/index.blade.php @@ -13,20 +13,21 @@ @endforeach - @if( auditionSetting('advanceTo') ) -
-

{{ auditionSetting('advanceTo') }} Qualifiers

- @foreach($publishedAdvancementAuditions as $audition) - - @foreach($resultsAdvancementList[$audition->id] as $entry) - - @endforeach - - @endforeach -
- @endif + +{{-- @if( auditionSetting('advanceTo') )--}} +{{--
--}} +{{--

{{ auditionSetting('advanceTo') }} Qualifiers

--}} +{{-- @foreach($publishedAdvancementAuditions as $audition)--}} +{{-- --}} +{{-- @foreach($resultsAdvancementList[$audition->id] as $entry)--}} +{{-- --}} +{{-- @endforeach--}} +{{-- --}} +{{-- @endforeach--}} +{{--
--}} +{{-- @endif--}} diff --git a/routes/web.php b/routes/web.php index 12ee04b..6b1a9f7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,8 +11,8 @@ require __DIR__.'/user.php'; Route::get('/test', [TestController::class, 'flashTest'])->middleware('auth', 'verified'); -Route::view('/home', 'welcome')->middleware('guest')->name('home'); -Route::view('/', 'landing')->name('landing'); +Route::view('/home', 'welcome')->middleware('guest')->name('landing'); +Route::view('/', 'landing')->name('home'); Route::get('/results', [App\Http\Controllers\ResultsPage::class, '__invoke'])->name('results'); // Filter Related Routes diff --git a/tests/Feature/PagesResponseTest.php b/tests/Feature/PagesResponseTest.php index 66b1c50..424a225 100644 --- a/tests/Feature/PagesResponseTest.php +++ b/tests/Feature/PagesResponseTest.php @@ -10,7 +10,7 @@ uses(RefreshDatabase::class); it('shows appropriate screens when not logged in', function () { // Act & Assert - get(route('home')) + get(route('landing')) ->assertStatus(200) ->assertSeeText([ 'Login',