Updating score sheets now works
This commit is contained in:
parent
c06e22abdd
commit
3f59e13ef7
|
|
@ -7,6 +7,7 @@ use App\Models\Audition;
|
|||
use App\Models\Entry;
|
||||
use App\Models\ScoreSheet;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use function dump;
|
||||
use function redirect;
|
||||
|
||||
|
|
@ -19,26 +20,28 @@ class TabulationController extends Controller
|
|||
|
||||
public function entryScoreSheet(Request $request)
|
||||
{
|
||||
$existing_sheets = [];
|
||||
$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();
|
||||
if ($scoreSheet) {
|
||||
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');
|
||||
}
|
||||
return view('tabulation.entry_score_sheet', compact('entry','judges','scoring_guide','subscores'));
|
||||
return view('tabulation.entry_score_sheet', compact('entry','judges','scoring_guide','subscores','existing_sheets'));
|
||||
}
|
||||
|
||||
public function saveEntryScoreSheet(Request $request, Entry $entry)
|
||||
{
|
||||
$judges = $entry->audition->room->judges;
|
||||
// Check if there is already a ScoreSheet for the entry $entry by judge $judge ( replaced this by making the last function updateOrCreate instead of Create)
|
||||
// foreach ($judges as $judge) {
|
||||
// $scoreSheet = ScoreSheet::where('entry_id',$entry->id)->where('user_id',$judge->id)->first();
|
||||
// if ($scoreSheet) {
|
||||
// return redirect(url()->previous())->with('error', $judge->full_name() . ' already scored this entry');
|
||||
// }
|
||||
// }
|
||||
|
||||
$subscores = $entry->audition->scoringGuide->subscores->sortBy('tiebreak_order');
|
||||
$scoringGuide = $entry->audition->scoringGuide;
|
||||
$preparedScoreSheets = [];
|
||||
|
|
@ -64,8 +67,8 @@ class TabulationController extends Controller
|
|||
}
|
||||
foreach ($preparedScoreSheets as $sheet) {
|
||||
ScoreSheet::updateOrCreate(
|
||||
['entry_id' => $entry->id, 'user_id' => $judge->id],
|
||||
['subscores' => json_encode($scoresToSave)]
|
||||
['entry_id' => $sheet['entry_id'], 'user_id' => $sheet['user_id']],
|
||||
['subscores' => $sheet['scores']]
|
||||
);
|
||||
}
|
||||
return redirect()->route('tabulation.chooseEntry')->with('success',count($preparedScoreSheets) . " Scores created");
|
||||
|
|
|
|||
|
|
@ -4,9 +4,30 @@ namespace App\Models;
|
|||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ScoreSheet extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $guarded = [];
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'entry_id',
|
||||
'subscores'
|
||||
];
|
||||
|
||||
protected $casts = ['subscores' => 'json'];
|
||||
|
||||
public function entry(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Entry::class);
|
||||
}
|
||||
|
||||
public function judge(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function getSubscore($id)
|
||||
{
|
||||
return $this->subscores[$id]['score'] ?? false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
</thead>
|
||||
<x-table.body :sortable="false">
|
||||
@foreach($judges as $judge)
|
||||
@php($existingSheet = $existing_sheets[$judge->id] ?? null)
|
||||
<tr >
|
||||
<x-table.td>{{ $judge->full_name() }}</x-table.td>
|
||||
@foreach($subscores as $subscore)
|
||||
|
|
@ -41,7 +42,11 @@
|
|||
id="j{{ $judge->id }}ss{{ $subscore->id }}"
|
||||
name="judge{{ $judge->id }}[{{ $subscore->id }}]"
|
||||
class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 judge{{$judge->id}}score"
|
||||
@if($oldScores) value="{{ $oldScores['judge'.$judge->id][$subscore->id] }}" @endif
|
||||
@if($oldScores)
|
||||
value="{{ $oldScores['judge'.$judge->id][$subscore->id] }}"
|
||||
@elseif($existingSheet)
|
||||
value="{{ $existingSheet->getSubscore($subscore->id) }}"
|
||||
@endif
|
||||
required
|
||||
{{-- onchange="judge{{$judge->id}}sum()"--}}
|
||||
>
|
||||
|
|
@ -85,5 +90,12 @@
|
|||
});
|
||||
});
|
||||
@endforeach
|
||||
|
||||
window.onload = function() {
|
||||
// Call the function for each judge
|
||||
@foreach($judges as $judge)
|
||||
calculateTotal({{ $judge->id }});
|
||||
@endforeach
|
||||
};
|
||||
</script>
|
||||
</x-layout.app>
|
||||
|
|
|
|||
|
|
@ -1,24 +1,9 @@
|
|||
@php use App\Models\Audition;use App\Models\School;use App\Models\SchoolEmailDomain;use App\Models\ScoringGuide;use App\Models\User;use App\Settings;use Illuminate\Support\Facades\Auth;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Session; @endphp
|
||||
@php use App\Models\Audition;use App\Models\School;use App\Models\SchoolEmailDomain;use App\Models\ScoreSheet;use App\Models\ScoringGuide;use App\Models\User;use App\Settings;use Illuminate\Support\Facades\Auth;use Illuminate\Support\Facades\DB;use Illuminate\Support\Facades\Session; @endphp
|
||||
<x-layout.app>
|
||||
<x-slot:page_title>Test Page</x-slot:page_title>
|
||||
|
||||
@php
|
||||
$auditions = Audition::with('entries')->get();
|
||||
@endphp
|
||||
@foreach($auditions as $audition)
|
||||
{{ $audition->name }} has {{ $audition->entries->count() }} entries.<br>
|
||||
@if($audition->has_complete_draw())
|
||||
<strong class="text-green-600">Draw is complete.</strong>
|
||||
@endif
|
||||
|
||||
@if($audition->has_partial_draw())
|
||||
<strong class="text-yellow-600">Has a partial draw.</strong>
|
||||
@endif
|
||||
|
||||
@if($audition->has_no_draw())
|
||||
<strong class="text-red-600">Has no draw.</strong>
|
||||
@endif
|
||||
<hr><hr>
|
||||
@endforeach
|
||||
@php($scoreSheet = ScoreSheet::find(11))
|
||||
@php(dump($scoreSheet->subscores[1]['score']))
|
||||
@php(dump($scoreSheet->getSubscore(1)))
|
||||
|
||||
</x-layout.app>
|
||||
|
|
|
|||
Loading…
Reference in New Issue