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\Entry;
|
||||||
use App\Models\ScoreSheet;
|
use App\Models\ScoreSheet;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Session;
|
||||||
use function dump;
|
use function dump;
|
||||||
use function redirect;
|
use function redirect;
|
||||||
|
|
||||||
|
|
@ -19,26 +20,28 @@ class TabulationController extends Controller
|
||||||
|
|
||||||
public function entryScoreSheet(Request $request)
|
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;
|
$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;
|
$scoring_guide = $entry->audition->scoringGuide;
|
||||||
$subscores = $entry->audition->scoringGuide->subscores->sortBy('display_order');
|
$subscores = $entry->audition->scoringGuide->subscores->sortBy('display_order');
|
||||||
if (!$entry) {
|
if (!$entry) {
|
||||||
return redirect()->route('tabulation.chooseEntry')->with('error','Entry not found');
|
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)
|
public function saveEntryScoreSheet(Request $request, Entry $entry)
|
||||||
{
|
{
|
||||||
$judges = $entry->audition->room->judges;
|
$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');
|
$subscores = $entry->audition->scoringGuide->subscores->sortBy('tiebreak_order');
|
||||||
$scoringGuide = $entry->audition->scoringGuide;
|
$scoringGuide = $entry->audition->scoringGuide;
|
||||||
$preparedScoreSheets = [];
|
$preparedScoreSheets = [];
|
||||||
|
|
@ -64,8 +67,8 @@ class TabulationController extends Controller
|
||||||
}
|
}
|
||||||
foreach ($preparedScoreSheets as $sheet) {
|
foreach ($preparedScoreSheets as $sheet) {
|
||||||
ScoreSheet::updateOrCreate(
|
ScoreSheet::updateOrCreate(
|
||||||
['entry_id' => $entry->id, 'user_id' => $judge->id],
|
['entry_id' => $sheet['entry_id'], 'user_id' => $sheet['user_id']],
|
||||||
['subscores' => json_encode($scoresToSave)]
|
['subscores' => $sheet['scores']]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return redirect()->route('tabulation.chooseEntry')->with('success',count($preparedScoreSheets) . " Scores created");
|
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\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
class ScoreSheet extends Model
|
class ScoreSheet extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
protected $fillable = [
|
||||||
protected $guarded = [];
|
'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>
|
</thead>
|
||||||
<x-table.body :sortable="false">
|
<x-table.body :sortable="false">
|
||||||
@foreach($judges as $judge)
|
@foreach($judges as $judge)
|
||||||
|
@php($existingSheet = $existing_sheets[$judge->id] ?? null)
|
||||||
<tr >
|
<tr >
|
||||||
<x-table.td>{{ $judge->full_name() }}</x-table.td>
|
<x-table.td>{{ $judge->full_name() }}</x-table.td>
|
||||||
@foreach($subscores as $subscore)
|
@foreach($subscores as $subscore)
|
||||||
|
|
@ -41,7 +42,11 @@
|
||||||
id="j{{ $judge->id }}ss{{ $subscore->id }}"
|
id="j{{ $judge->id }}ss{{ $subscore->id }}"
|
||||||
name="judge{{ $judge->id }}[{{ $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"
|
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
|
required
|
||||||
{{-- onchange="judge{{$judge->id}}sum()"--}}
|
{{-- onchange="judge{{$judge->id}}sum()"--}}
|
||||||
>
|
>
|
||||||
|
|
@ -85,5 +90,12 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@endforeach
|
@endforeach
|
||||||
|
|
||||||
|
window.onload = function() {
|
||||||
|
// Call the function for each judge
|
||||||
|
@foreach($judges as $judge)
|
||||||
|
calculateTotal({{ $judge->id }});
|
||||||
|
@endforeach
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
</x-layout.app>
|
</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-layout.app>
|
||||||
<x-slot:page_title>Test Page</x-slot:page_title>
|
<x-slot:page_title>Test Page</x-slot:page_title>
|
||||||
|
|
||||||
@php
|
@php($scoreSheet = ScoreSheet::find(11))
|
||||||
$auditions = Audition::with('entries')->get();
|
@php(dump($scoreSheet->subscores[1]['score']))
|
||||||
@endphp
|
@php(dump($scoreSheet->getSubscore(1)))
|
||||||
@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
|
|
||||||
|
|
||||||
</x-layout.app>
|
</x-layout.app>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue