Results page is working
This commit is contained in:
parent
f3a8eca8b4
commit
b005aed129
|
|
@ -2,14 +2,18 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Seat;
|
||||
use App\Services\AuditionCacheService;
|
||||
use App\Services\SeatingService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ResultsPage extends Controller
|
||||
{
|
||||
protected $auditionCacheService;
|
||||
|
||||
protected $seatingService;
|
||||
|
||||
public function __construct(AuditionCacheService $auditionCacheService, SeatingService $seatingService)
|
||||
{
|
||||
$this->auditionCacheService = $auditionCacheService;
|
||||
|
|
@ -22,11 +26,28 @@ class ResultsPage extends Controller
|
|||
public function __invoke(Request $request)
|
||||
{
|
||||
$publishedAuditions = $this->auditionCacheService->getPublishedAuditions();
|
||||
|
||||
$resultsSeatList = Cache::rememberForever('resultsSeatList', function () use ($publishedAuditions) {
|
||||
$seatList = [];
|
||||
foreach ($publishedAuditions as $audition) {
|
||||
$audition->seats = $this->seatingService->getSeatsForAudition($audition->id);
|
||||
$seats = $this->seatingService->getSeatsForAudition($audition->id);
|
||||
$ensembles = $this->seatingService->getEnsemblesForEvent($audition->event_id);
|
||||
foreach ($ensembles as $ensemble) {
|
||||
if (! $seats->has($ensemble->id)) { // If there are no students seated in this ensemble, skip it
|
||||
continue;
|
||||
}
|
||||
foreach ($seats[$ensemble->id] as $seat) {
|
||||
/** @var Seat $seat */
|
||||
$seatList[$audition->id][] = [
|
||||
'seat' => $ensemble->name.' '.$seat->seat,
|
||||
'student' => $seat->entry->student,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return view('results.index', compact('publishedAuditions'));
|
||||
return $seatList;
|
||||
});
|
||||
|
||||
return view('results.index', compact('publishedAuditions', 'resultsSeatList'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use App\Services\DoublerService;
|
|||
use App\Services\SeatingService;
|
||||
use App\Services\TabulationService;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
use function compact;
|
||||
|
||||
|
|
@ -93,16 +94,22 @@ class TabulationController extends Controller
|
|||
}
|
||||
$audition->addFlag('seats_published');
|
||||
$request->session()->forget($sessionKey);
|
||||
Cache::forget('resultsSeatList');
|
||||
Cache::forget('publishedAuditions');
|
||||
Cache::forget('audition'.$audition->id.'seats');
|
||||
// TODO move the previous Cache functions here and in unplublish to the services, need to add an event for publishing an audition as well
|
||||
return redirect()->route('tabulation.audition.seat', ['audition' => $audition->id]);
|
||||
}
|
||||
|
||||
public function unpublishSeats(Request $request, Audition $audition)
|
||||
{
|
||||
// TODO move this to SeatingService
|
||||
$audition->removeFlag('seats_published');
|
||||
Cache::forget('resultsSeatList');
|
||||
Cache::forget('publishedAuditions');
|
||||
Cache::forget('audition'.$audition->id.'seats');
|
||||
$this->seatingService->forgetSeatsForAudition($audition->id);
|
||||
Seat::where('audition_id', $audition->id)->delete();
|
||||
$audition->removeFlag('seats_published');
|
||||
|
||||
return redirect()->route('tabulation.audition.seat', ['audition' => $audition->id]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ class Audition extends Model
|
|||
return $this->flags->contains('flag_name', $flag);
|
||||
}
|
||||
|
||||
public function addFlag($flag)
|
||||
public function addFlag($flag): void
|
||||
{
|
||||
if ($this->hasFlag($flag)) {
|
||||
return;
|
||||
|
|
@ -180,7 +180,7 @@ class Audition extends Model
|
|||
$this->flags()->create(['flag_name' => $flag]);
|
||||
}
|
||||
|
||||
public function removeFlag($flag)
|
||||
public function removeFlag($flag): void
|
||||
{
|
||||
// remove related auditionFlag where flag_name = $flag
|
||||
$this->flags()->where('flag_name', $flag)->delete();
|
||||
|
|
|
|||
|
|
@ -70,4 +70,9 @@ class AuditionCacheService
|
|||
return Audition::orderBy('score_order')->get()->filter(fn ($audition) => $audition->hasFlag('seats_published'));
|
||||
});
|
||||
}
|
||||
|
||||
public function clearPublishedAuditionsCache()
|
||||
{
|
||||
Cache::forget('publishedAuditions');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\Models\Seat;
|
||||
use App\Models\SeatingLimit;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
|
@ -25,7 +26,7 @@ class SeatingService
|
|||
// TODO modifying audition limits should refresh this cache
|
||||
return Cache::remember($this->limitsCacheKey, now()->addDay(), function () {
|
||||
$limits = SeatingLimit::with('ensemble')->get();
|
||||
// Sort limits by ensemlbe->rank
|
||||
// Sort limits by ensemble->rank
|
||||
$limits = $limits->sortBy(function ($limit) {
|
||||
return $limit->ensemble->rank;
|
||||
});
|
||||
|
|
@ -56,9 +57,9 @@ class SeatingService
|
|||
public function getSeatsForAudition($auditionId)
|
||||
{
|
||||
$cacheKey = 'audition'.$auditionId.'seats';
|
||||
|
||||
// TODO rework to pull entry info from cache
|
||||
return Cache::remember($cacheKey, now()->addHour(), function () use ($auditionId) {
|
||||
return Seat::with('entry.student')
|
||||
return Seat::with('entry.student.school')
|
||||
->where('audition_id', $auditionId)
|
||||
->orderBy('seat')
|
||||
->get()
|
||||
|
|
@ -71,4 +72,17 @@ class SeatingService
|
|||
$cacheKey = 'audition'.$auditionId.'seats';
|
||||
Cache::forget($cacheKey);
|
||||
}
|
||||
|
||||
public function getEnsemblesForEvent($eventId)
|
||||
{
|
||||
static $eventEnsembles = [];
|
||||
|
||||
if (array_key_exists($eventId, $eventEnsembles)) {
|
||||
return $eventEnsembles[$eventId];
|
||||
}
|
||||
$event = Event::find($eventId);
|
||||
$eventEnsembles[$eventId] = $event->ensembles;
|
||||
|
||||
return $eventEnsembles[$eventId];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mx-auto max-w-7xl">
|
||||
<div class="mx-auto max-w-sm">
|
||||
|
||||
{{ $slot }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,16 @@
|
|||
<x-results.layout>
|
||||
@php
|
||||
dump($publishedAuditions);
|
||||
@endphp
|
||||
|
||||
<nav class="h-full overflow-y-auto mt-3" aria-label="Directory">
|
||||
@foreach($publishedAuditions as $audition)
|
||||
<x-results.table-audition-section :auditionName="$audition->name">
|
||||
@foreach($audition->seats as $seat)
|
||||
@foreach($resultsSeatList[$audition->id] as $seat)
|
||||
<x-results.table-seat-row
|
||||
seat="d"
|
||||
student_name="name"
|
||||
school="school" />
|
||||
:seat="$seat['seat']"
|
||||
:student_name="$seat['student']->full_name()"
|
||||
:school="$seat['student']->school->name" />
|
||||
@endforeach
|
||||
</x-results.table-audition-section>
|
||||
@endforeach
|
||||
<x-results.table-audition-section audition-name="HS Flute">
|
||||
<x-results.table-seat-row seat="Wind Ensemble 1" student_name="Matt Young" school="Chelsea"/>
|
||||
</x-results.table-audition-section>
|
||||
|
||||
</nav>
|
||||
|
||||
</x-results.layout>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
@foreach($ensembleLimits as $ensembleLimit)
|
||||
@php
|
||||
$ensembleSeats = $seatingService->getSeatsForAudition($audition->id)[$ensembleLimit->ensemble->id];
|
||||
$ensembleSeats = $seatingService->getSeatsForAudition($audition->id)[$ensembleLimit->ensemble->id] ?? array();
|
||||
@endphp
|
||||
<x-card.card class="mb-3">
|
||||
<x-card.heading>{{ $ensembleLimit->ensemble->name }}</x-card.heading>
|
||||
|
|
|
|||
Loading…
Reference in New Issue