110 lines
4.0 KiB
PHP
110 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Tabulation\Seating;
|
|
|
|
use App\Actions\Entries\DoublerDecision;
|
|
use App\Actions\Tabulation\RankAuditionEntries;
|
|
use App\Exceptions\AuditionAdminException;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use Debugbar;
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use function redirect;
|
|
|
|
class EnterDoublerDecisionsController extends Controller
|
|
{
|
|
public function noshow(
|
|
Audition $audition,
|
|
Entry $entry
|
|
) {
|
|
$recorder = app('App\Actions\Tabulation\EnterNoShow');
|
|
try {
|
|
$msg = $recorder($entry);
|
|
} catch (AuditionAdminException $e) {
|
|
return redirect()->back()->with('error', $e->getMessage());
|
|
}
|
|
|
|
return redirect()->route('seating.audition', [$audition])->with('success', $msg);
|
|
}
|
|
|
|
public function declineSeat(Audition $audition, Entry $entry)
|
|
{
|
|
$decider = app(DoublerDecision::class);
|
|
try {
|
|
$decider->decline($entry);
|
|
} catch (AuditionAdminException $e) {
|
|
return redirect()->route('seating.audition', ['audition' => $audition->id])
|
|
->with('error', $e->getMessage());
|
|
}
|
|
|
|
return redirect()->route('seating.audition', ['audition' => $audition->id])->with('success',
|
|
$entry->student->full_name().' has declined '.$audition->name);
|
|
}
|
|
|
|
public function massDecline(Audition $audition)
|
|
{
|
|
$decider = app(DoublerDecision::class);
|
|
$validData = request()->validate([
|
|
'decline-below' => ['required', 'integer', 'min:0'],
|
|
]);
|
|
$ranker = app(RankAuditionEntries::class);
|
|
// Get scored entries in order
|
|
try {
|
|
$scored_entries = $ranker($audition, 'seating');
|
|
} catch (AuditionAdminException $e) {
|
|
return redirect()->route('seating.audition', ['audition' => $audition->id])
|
|
->with('error', $e->getMessage());
|
|
}
|
|
$scored_entries->load(['student.doublers', 'student.school']);
|
|
foreach ($scored_entries as $entry) {
|
|
Debugbar::info('Starting entry '.$entry->student->full_name());
|
|
if ($entry->seatingRank < $validData['decline-below']) {
|
|
Debugbar::info('Skipping '.$entry->student->full_name().' because they are ranked above decline threshold');
|
|
|
|
continue;
|
|
}
|
|
if ($entry->hasFlag('declined')) {
|
|
Debugbar::info('Skipping '.$entry->student->full_name().' because they have already been declined');
|
|
|
|
continue;
|
|
}
|
|
if (! $entry->student->isDoublerInEvent($audition->event_id)) {
|
|
Debugbar::info('Skipping '.$entry->student->full_name().' because they are not a doubler');
|
|
|
|
continue;
|
|
}
|
|
if ($entry->student->doublers->where('event_id', $audition->event_id)->first()->accepted_entry) {
|
|
Debugbar::info('Skipping '.$entry->student->full_name().' because they have already accepted a seat');
|
|
|
|
continue;
|
|
}
|
|
try {
|
|
$decider->decline($entry);
|
|
} catch (AuditionAdminException $e) {
|
|
return redirect()->route('seating.audition', ['audition' => $audition->id])
|
|
->with('error', $e->getMessage());
|
|
}
|
|
}
|
|
Cache::forget('rank_seating_'.$audition->id);
|
|
|
|
return redirect()->route('seating.audition', ['audition' => $audition->id]);
|
|
|
|
}
|
|
|
|
public function acceptSeat(Audition $audition, Entry $entry)
|
|
{
|
|
$decider = app(DoublerDecision::class);
|
|
try {
|
|
$decider->accept($entry);
|
|
} catch (AuditionAdminException $e) {
|
|
return redirect()->route('seating.audition', ['audition' => $audition->id])
|
|
->with('error', $e->getMessage());
|
|
}
|
|
|
|
return redirect()->route('seating.audition', ['audition' => $audition->id])->with('success',
|
|
$entry->student->full_name().' has accepted '.$audition->name);
|
|
}
|
|
}
|