133 lines
5.1 KiB
PHP
133 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Tabulation;
|
|
|
|
use App\Exceptions\AuditionAdminException;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\BonusScore;
|
|
use App\Models\Entry;
|
|
use App\Models\EntryTotalScore;
|
|
use App\Models\ScoreSheet;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use function to_route;
|
|
|
|
class EntryFlagController extends Controller
|
|
{
|
|
public function noShowSelect()
|
|
{
|
|
$method = 'GET';
|
|
$formRoute = 'entry-flags.confirmNoShow';
|
|
$title = 'No Show';
|
|
|
|
return view('tabulation.choose_entry', compact('method', 'formRoute', 'title'));
|
|
}
|
|
|
|
public function noShowConfirm(Request $request)
|
|
{
|
|
$validData = $request->validate([
|
|
'entry_id' => 'required|exists:entries,id',
|
|
]);
|
|
$entry = Entry::with('flags')->withCount('scoreSheets')->find($validData['entry_id']);
|
|
|
|
// If any results are published, get gone
|
|
if ($entry->audition->hasFlag('seats_published')) {
|
|
return to_route('entry-flags.noShowSelect')->with('error',
|
|
'Cannot enter a no-show for an entry in an audition where seats are published');
|
|
}
|
|
if ($entry->audition->hasFlag('advancement_published')) {
|
|
return to_route('entry-flags.noShowSelect')->with('error',
|
|
'Cannot enter a no-show for an entry in an audition where advancement is published');
|
|
}
|
|
|
|
if ($entry->hasFlag('no_show')) {
|
|
$formId = 'no-show-cancellation-form';
|
|
$buttonName = 'Remove No Show';
|
|
$submitRouteName = 'entry-flags.undoNoShow';
|
|
$cardHeading = 'Undo No-Show';
|
|
$method = 'DELETE';
|
|
} else {
|
|
$formId = 'no-show-confirmation-form';
|
|
$buttonName = 'Confirm No Show';
|
|
$submitRouteName = 'entry-flags.enterNoShow';
|
|
$cardHeading = 'Confirm No-Show';
|
|
$method = 'POST';
|
|
}
|
|
$scores = [];
|
|
if ($entry->score_sheets_count > 0) {
|
|
$scores = $entry->scoreSheets;
|
|
$scores->load('judge');
|
|
}
|
|
|
|
return view('tabulation.no_show_confirm',
|
|
compact('entry',
|
|
'formId',
|
|
'buttonName',
|
|
'submitRouteName',
|
|
'cardHeading',
|
|
'method',
|
|
'scores'));
|
|
}
|
|
|
|
/**
|
|
* @throws AuditionAdminException
|
|
*/
|
|
public function enterNoShow(Entry $entry)
|
|
{
|
|
$recorder = app('App\Actions\Tabulation\EnterNoShow');
|
|
try {
|
|
$msg = $recorder($entry, request()->input('noshow-type'));
|
|
} catch (AuditionAdminException $e) {
|
|
return to_route('entry-flags.noShowSelect')->with('error', $e->getMessage());
|
|
}
|
|
|
|
// if ($entry->audition->hasFlag('seats_published')) {
|
|
// return to_route('entry-flags.noShowSelect')->with('error',
|
|
// 'Cannot enter a no-show for an entry in an audition where seats are published');
|
|
// }
|
|
// if ($entry->audition->hasFlag('advancement_published')) {
|
|
// return to_route('entry-flags.noShowSelect')->with('error',
|
|
// 'Cannot enter a no-show for an entry in an audition where advancement is published');
|
|
// }
|
|
// DB::table('score_sheets')->where('entry_id', $entry->id)->delete();
|
|
//
|
|
// ScoreSheet::where('entry_id', $entry->id)->delete();
|
|
// BonusScore::where('entry_id', $entry->id)->delete();
|
|
// EntryTotalScore::where('entry_id', $entry->id)->delete();
|
|
// if (request()->input('noshow-type') == 'failprelim') {
|
|
// $msg = 'Failed prelim has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').';
|
|
// $entry->addFlag('failed_prelim');
|
|
// } else {
|
|
// $entry->addFlag('no_show');
|
|
// $msg = 'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').';
|
|
// }
|
|
|
|
return to_route('entry-flags.noShowSelect')->with('success', $msg);
|
|
}
|
|
|
|
public function undoNoShow(Entry $entry)
|
|
{
|
|
if ($entry->audition->hasFlag('seats_published')) {
|
|
return to_route('entry-flags.noShowSelect')->with('error',
|
|
'Cannot undo a no-show for an entry in an audition where seats are published');
|
|
}
|
|
if ($entry->audition->hasFlag('advancement_published')) {
|
|
return to_route('entry-flags.noShowSelect')->with('error',
|
|
'Cannot undo a no-show for an entry in an audition where advancement is published');
|
|
}
|
|
|
|
$entry->removeFlag('no_show');
|
|
|
|
return to_route('entry-flags.noShowSelect')->with('success',
|
|
'No Show status has been removed for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').');
|
|
}
|
|
|
|
public function undoDecline(Entry $entry)
|
|
{
|
|
$entry->removeFlag('declined');
|
|
|
|
return redirect()->back()->with('success', 'Decline cleared');
|
|
}
|
|
}
|