Allow for reuse of entry select form to choose entry by ID

This commit is contained in:
Matt Young 2024-07-07 17:18:03 -05:00
parent c8ce16e7e6
commit 87f091ee5b
2 changed files with 31 additions and 15 deletions

View File

@ -7,36 +7,44 @@ use App\Models\Entry;
use App\Models\ScoreSheet;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
class ScoreController extends Controller
{
public function chooseEntry(Request $request)
{
return view('tabulation.choose_entry');
$method = 'GET';
$formRoute = 'scores.entryScoreSheet';
return view('tabulation.choose_entry', compact('method', 'formRoute'));
}
public function destroyScore(ScoreSheet $score) {
public function destroyScore(ScoreSheet $score)
{
$score->delete();
return redirect()->back()->with('success','Score Deleted');
return redirect()->back()->with('success', 'Score Deleted');
}
public function entryScoreSheet(Request $request)
{
$existing_sheets = [];
$entry = Entry::with(['student','audition.room.judges'])->find($request->input('entry_id'));
$entry = Entry::with(['student', 'audition.room.judges'])->find($request->input('entry_id'));
$judges = $entry->audition->room->judges;
foreach ($judges as $judge) {
$scoreSheet = ScoreSheet::where('entry_id',$entry->id)->where('user_id',$judge->id)->first();
$scoreSheet = ScoreSheet::where('entry_id', $entry->id)->where('user_id', $judge->id)->first();
if ($scoreSheet) {
Session::flash('caution','Scores exist for this entry. Now editing existing scores');
Session::flash('caution', 'Scores exist for this entry. Now editing existing scores');
$existing_sheets[$judge->id] = $scoreSheet;
}
}
$scoring_guide = $entry->audition->scoringGuide;
$subscores = $entry->audition->scoringGuide->subscores->sortBy('display_order');
if (!$entry) {
return redirect()->route('tabulation.chooseEntry')->with('error','Entry not found');
if (! $entry) {
return redirect()->route('tabulation.chooseEntry')->with('error', 'Entry not found');
}
return view('tabulation.entry_score_sheet', compact('entry','judges','scoring_guide','subscores','existing_sheets'));
return view('tabulation.entry_score_sheet',
compact('entry', 'judges', 'scoring_guide', 'subscores', 'existing_sheets'));
}
public function saveEntryScoreSheet(Request $request, Entry $entry)
@ -52,16 +60,17 @@ class ScoreController extends Controller
$scoreValidation = $scoringGuide->validateScores($request->input('judge'.$judge->id));
if ($scoreValidation != 'success') {
return redirect(url()->previous())->with('error', $judge->full_name() . ': ' . $scoreValidation)->with('oldScores',$request->all());
return redirect(url()->previous())->with('error',
$judge->full_name().': '.$scoreValidation)->with('oldScores', $request->all());
}
$scoreSubmission = $request->input('judge'.$judge->id);
$scoresToSave = [];
foreach ($subscores as $subscore) {
$scoresToSave[$subscore->id] = [
'subscore_id'=>$subscore->id,
'subscore_id' => $subscore->id,
'subscore_name' => $subscore->name,
'score' => intval($scoreSubmission[$subscore->id])
'score' => intval($scoreSubmission[$subscore->id]),
];
}
$preparedScoreSheets[$judge->id]['scores'] = $scoresToSave;
@ -72,7 +81,7 @@ class ScoreController extends Controller
['subscores' => $sheet['scores']]
);
}
return redirect()->route('scores.chooseEntry')->with('success',count($preparedScoreSheets) . " Scores saved");
}
return redirect()->route('scores.chooseEntry')->with('success', count($preparedScoreSheets).' Scores saved');
}
}

View File

@ -1,9 +1,16 @@
@php
/**
* @var string $method Method for the select form
* @var string $formRoute Route for the form action. Should be a route name
*/
@endphp
<x-layout.app>
<x-slot:page_title>Choose Entry</x-slot:page_title>
<x-card.card class="mx-auto max-w-sm">
<x-card.heading>Choose Entry</x-card.heading>
<div class="">
<x-form.form method="GET" action="{{ route('scores.entryScoreSheet') }}" class="mb-4 mt-3">
<x-form.form method="{{ $method }}" action="{{ route($formRoute) }}" class="mb-4 mt-3">
<x-form.field name="entry_id" label_text="Entry ID"></x-form.field>
<x-form.footer >
<x-form.button>Select</x-form.button>