125 lines
4.3 KiB
PHP
125 lines
4.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Tabulation;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Audition;
|
|
use App\Models\Seat;
|
|
use App\Services\AuditionCacheService;
|
|
use App\Services\DoublerService;
|
|
use App\Services\SeatingService;
|
|
use App\Services\TabulationService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use function compact;
|
|
|
|
class TabulationController extends Controller
|
|
{
|
|
protected $tabulationService;
|
|
|
|
protected $doublerService;
|
|
|
|
protected $seatingService;
|
|
|
|
protected $auditionCacheService;
|
|
|
|
public function __construct(TabulationService $tabulationService,
|
|
DoublerService $doublerService,
|
|
SeatingService $seatingService,
|
|
AuditionCacheService $auditionCacheService)
|
|
{
|
|
$this->tabulationService = $tabulationService;
|
|
$this->doublerService = $doublerService;
|
|
$this->seatingService = $seatingService;
|
|
$this->auditionCacheService = $auditionCacheService;
|
|
}
|
|
|
|
public function status()
|
|
{
|
|
$auditions = $this->tabulationService->getAuditionsWithStatus('seating');
|
|
|
|
return view('tabulation.status', compact('auditions'));
|
|
}
|
|
|
|
public function auditionSeating(Request $request, Audition $audition)
|
|
{
|
|
if ($request->method() == 'POST') {
|
|
$requestedEnsembleAccepts = $request->input('ensembleAccept');
|
|
} else {
|
|
$requestedEnsembleAccepts = false;
|
|
}
|
|
|
|
$entries = $this->tabulationService->auditionEntries($audition->id);
|
|
$entries = $entries->filter(function ($entry) {
|
|
return $entry->for_seating;
|
|
});
|
|
|
|
$doublerComplete = true;
|
|
foreach ($entries as $entry) {
|
|
|
|
if ($this->doublerService->studentIsDoubler($entry->student_id)) { // If this entry is a doubler
|
|
if ($this->doublerService->getDoublerInfo($entry->student_id)[$entry->id]['status'] === 'undecided') { // If there is no decision for this entry
|
|
$doublerComplete = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
$scoringComplete = $entries->every(function ($entry) {
|
|
return $entry->scoring_complete;
|
|
});
|
|
$ensembleLimits = $this->seatingService->getLimitForAudition($audition->id);
|
|
$auditionComplete = $scoringComplete && $doublerComplete;
|
|
|
|
$seatableEntries = $this->seatingService->getSeatableEntries($audition->id);
|
|
$seatableEntries = $seatableEntries->filter(function ($entry) {
|
|
return $entry->for_seating;
|
|
});
|
|
|
|
return view('tabulation.auditionSeating', compact('audition',
|
|
'entries',
|
|
'scoringComplete',
|
|
'doublerComplete',
|
|
'auditionComplete',
|
|
'ensembleLimits',
|
|
'seatableEntries',
|
|
'requestedEnsembleAccepts'));
|
|
}
|
|
|
|
public function publishSeats(Request $request, Audition $audition)
|
|
{
|
|
// TODO move this to SeatingService
|
|
$sessionKey = 'audition'.$audition->id.'seatingProposal';
|
|
$seats = $request->session()->get($sessionKey);
|
|
foreach ($seats as $seat) {
|
|
Seat::create([
|
|
'ensemble_id' => $seat['ensemble_id'],
|
|
'audition_id' => $seat['audition_id'],
|
|
'seat' => $seat['seat'],
|
|
'entry_id' => $seat['entry_id'],
|
|
]);
|
|
}
|
|
$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();
|
|
|
|
return redirect()->route('tabulation.audition.seat', ['audition' => $audition->id]);
|
|
}
|
|
}
|