69 lines
2.3 KiB
PHP
69 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use App\Models\ScoreSheet;
|
|
use App\Models\SubscoreDefinition;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use function compact;
|
|
use function redirect;
|
|
use function url;
|
|
|
|
class JudgingController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$rooms = Auth::user()->judgingAssignments;
|
|
return view('judging.index', compact('rooms'));
|
|
}
|
|
|
|
public function auditionEntryList(Audition $audition)
|
|
{
|
|
// TODO verify user is assigned to judge this audition
|
|
$entries = Entry::where('audition_id','=',$audition->id)->orderBy('draw_number')->with('audition')->get();
|
|
$subscores = $audition->scoringGuide->subscores()->orderBy('display_order')->get();
|
|
return view('judging.audition_entry_list', compact('audition','entries','subscores'));
|
|
}
|
|
|
|
public function entryScoreSheet(Entry $entry)
|
|
{
|
|
// TODO verify user is assigned to judge this audition
|
|
return view('judging.entry_score_sheet',compact('entry'));
|
|
}
|
|
|
|
public function saveScoreSheet(Request $request, Entry $entry)
|
|
{
|
|
Gate::authorize('create',[ScoreSheet::class,$entry]);
|
|
// TODO verify user is assigned to judge this audition
|
|
$scoringGuide = $entry->audition->scoringGuide()->with('subscores')->first();
|
|
$scoreValidation = $scoringGuide->validateScores($request->input('score'));
|
|
if ($scoreValidation != 'success') {
|
|
return redirect(url()->previous())->with('error', $scoreValidation)->with('oldScores',$request->all());
|
|
}
|
|
$scoreSheetArray = [];
|
|
foreach($scoringGuide->subscores as $subscore) {
|
|
$scoreSheetArray[$subscore->id] = [
|
|
'score' => $request->input('score')[$subscore->id],
|
|
'subscore_id' => $subscore->id,
|
|
'subscore_name' => $subscore->name
|
|
];
|
|
}
|
|
|
|
ScoreSheet::create([
|
|
'user_id' => Auth::user()->id,
|
|
'entry_id' => $entry->id,
|
|
'subscores' => $scoreSheetArray
|
|
]);
|
|
|
|
return redirect('/judging/audition/' . $entry->audition_id)->with('success','Entered scores for ' . $entry->audition->name . ' ' . $entry->draw_number);
|
|
|
|
}
|
|
|
|
|
|
}
|