102 lines
3.4 KiB
PHP
102 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Enums\EntryFlags;
|
|
use App\Models\Audition;
|
|
use App\Models\Ensemble;
|
|
use App\Models\Entry;
|
|
use App\Models\Seat;
|
|
use App\Services\AuditionService;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\View;
|
|
|
|
use function auditionSetting;
|
|
|
|
class ResultsPage extends Controller
|
|
{
|
|
protected $auditionService;
|
|
|
|
public function __construct(AuditionService $auditionService)
|
|
{
|
|
$this->auditionService = $auditionService;
|
|
}
|
|
|
|
/**
|
|
* Handle the incoming request.
|
|
*/
|
|
public function __invoke(Request $request)
|
|
{
|
|
Model::preventLazyLoading(false);
|
|
$cacheKey = 'publicResultsPage';
|
|
|
|
if (Cache::has($cacheKey)) {
|
|
return response(Cache::get($cacheKey));
|
|
}
|
|
|
|
$publishedAdvancementAuditions = [];
|
|
$resultsAdvancementList = [];
|
|
$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 = $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;
|
|
}
|
|
foreach ($seats[$ensemble->id] as $seat) {
|
|
/** @var Seat $seat */
|
|
$seatList[$audition->id][] = [
|
|
'seat' => $ensemble->name.' '.$seat->seat,
|
|
'student' => $seat->entry->student,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
return $seatList;
|
|
});
|
|
|
|
if (auditionSetting('advanceTo')) {
|
|
$publishedAdvancementAuditions = Audition::advancementPublished()->orderBy('score_order')->get();
|
|
|
|
// get entries with a related flag of will_advance
|
|
$advancingEntries = Entry::forAdvancement()->with('student.school')
|
|
->whereHas('flags', function ($query) {
|
|
$query->where('flag_name', EntryFlags::WILL_ADVANCE);
|
|
})
|
|
->get();
|
|
$advancingEntries = $advancingEntries->sortBy(function ($entry) {
|
|
return $entry->student->full_name(true);
|
|
});
|
|
|
|
$resultsAdvancementList = $advancingEntries->groupBy('audition_id');
|
|
|
|
}
|
|
|
|
$content = View::make('results.index',
|
|
compact('publishedAuditions', 'resultsSeatList', 'publishedAdvancementAuditions',
|
|
'resultsAdvancementList'))->render();
|
|
|
|
Cache::forever($cacheKey, $content);
|
|
|
|
return response($content);
|
|
}
|
|
|
|
private function generateResultsPage()
|
|
{
|
|
|
|
}
|
|
}
|