72 lines
3.0 KiB
PHP
72 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Judging;
|
|
|
|
use App\Actions\Tabulation\EnterPrelimScore;
|
|
use App\Exceptions\AuditionAdminException;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Entry;
|
|
use App\Models\PrelimDefinition;
|
|
use App\Models\PrelimScoreSheet;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class PrelimJudgingController extends Controller
|
|
{
|
|
public function prelimEntryList(PrelimDefinition $prelimDefinition)
|
|
{
|
|
if (auth()->user()->cannot('judge', $prelimDefinition)) {
|
|
return redirect()->route('dashboard')->with('error', 'You are not assigned to judge that prelim audition.');
|
|
}
|
|
$entries = $prelimDefinition->audition->entries;
|
|
$subscores = $prelimDefinition->scoringGuide->subscores()->orderBy('display_order')->get();
|
|
$published = $prelimDefinition->audition->hasFlag('seats_published');
|
|
|
|
return view('judging.prelim_entry_list', compact('prelimDefinition', 'entries', 'subscores', 'published'));
|
|
}
|
|
|
|
public function prelimScoreEntryForm(Entry $entry)
|
|
{
|
|
if (auth()->user()->cannot('judge', $entry->audition->prelimDefinition)) {
|
|
return redirect()->route('dashboard')->with('error', 'You are not assigned to judge that prelim audition.');
|
|
}
|
|
if ($entry->audition->hasFlag('seats_published')) {
|
|
return redirect()->route('dashboard')->with('error',
|
|
'Scores for entries in published auditions cannot be modified.');
|
|
}
|
|
if ($entry->hasFlag('no_show')) {
|
|
return redirect()->route('judging.prelimEntryList', $entry->audition->prelimDefinition)->with('error',
|
|
'The requested entry is marked as a no-show. Scores cannot be entered.');
|
|
}
|
|
|
|
$oldSheet = PrelimScoreSheet::where('user_id', Auth::id())->where('entry_id',
|
|
$entry->id)->value('subscores') ?? null;
|
|
|
|
return view('judging.prelim_entry_form', compact('entry', 'oldSheet'));
|
|
}
|
|
|
|
/**
|
|
* @throws AuditionAdminException
|
|
*/
|
|
public function savePrelimScoreSheet(Entry $entry, Request $request, EnterPrelimScore $scribe)
|
|
{
|
|
if (auth()->user()->cannot('judge', $entry->audition->prelimDefinition)) {
|
|
return redirect()->route('dashboard')->with('error', 'You are not assigned to judge that prelim audition.');
|
|
}
|
|
|
|
// Validate form data
|
|
$subscores = $entry->audition->prelimDefinition->scoringGuide->subscores;
|
|
$validationChecks = [];
|
|
foreach ($subscores as $subscore) {
|
|
$validationChecks['score'.'.'.$subscore->id] = 'required|integer|max:'.$subscore->max_score;
|
|
}
|
|
$validatedData = $request->validate($validationChecks);
|
|
|
|
// Enter the score
|
|
$scribe(auth()->user(), $entry, $validatedData['score']);
|
|
|
|
return redirect()->route('judging.prelimEntryList', $entry->audition->prelimDefinition)->with('success',
|
|
'Entered prelim scores for '.$entry->audition->name.' '.$entry->draw_number);
|
|
}
|
|
}
|