75 lines
3.0 KiB
PHP
75 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
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;
|
|
|
|
class ResultsPage extends Controller
|
|
{
|
|
protected $auditionService;
|
|
|
|
protected $seatingService;
|
|
|
|
public function __construct(AuditionService $auditionService, SeatingService $seatingService)
|
|
{
|
|
$this->auditionService = $auditionService;
|
|
$this->seatingService = $seatingService;
|
|
}
|
|
|
|
/**
|
|
* Handle the incoming request.
|
|
*/
|
|
public function __invoke(Request $request)
|
|
{
|
|
$publishedAuditions = $this->auditionService->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);
|
|
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 $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);
|
|
});
|
|
}
|
|
|
|
return $qualifierList;
|
|
});
|
|
|
|
return view('results.index', compact('publishedAuditions', 'resultsSeatList', 'resultsAdvancementList', 'publishedAdvancementAuditions'));
|
|
}
|
|
}
|