diff --git a/app/Actions/Tabulation/EnterScore.php b/app/Actions/Tabulation/EnterScore.php index bb5646e..7d55ac8 100644 --- a/app/Actions/Tabulation/EnterScore.php +++ b/app/Actions/Tabulation/EnterScore.php @@ -12,6 +12,7 @@ use App\Models\AuditLogEntry; use App\Models\Entry; use App\Models\EntryTotalScore; use App\Models\ScoreSheet; +use App\Models\SubscoreDefinition; use App\Models\User; use Illuminate\Support\Facades\DB; @@ -70,7 +71,12 @@ class EnterScore } // Check the validity of submitted subscores, format array for storage, and sum score - $subscoresRequired = $entry->audition->scoringGuide->subscores; + if ($entry->audition->splitScoreDefinition) { + $subscoreIDs = $entry->audition->splitScoreDefinition->subscoresForJudge($user); + $subscoresRequired = SubscoreDefinition::findMany($subscoreIDs); + } else { + $subscoresRequired = $entry->audition->scoringGuide->subscores; + } $subscoresStorageArray = []; $seatingTotal = 0; $seatingMaxPossible = 0; diff --git a/app/Http/Controllers/Judging/JudgingController.php b/app/Http/Controllers/Judging/JudgingController.php index 4ca72eb..ddf59af 100644 --- a/app/Http/Controllers/Judging/JudgingController.php +++ b/app/Http/Controllers/Judging/JudgingController.php @@ -8,6 +8,7 @@ use App\Models\Audition; use App\Models\Entry; use App\Models\JudgeAdvancementVote; use App\Models\ScoreSheet; +use App\Models\SubscoreDefinition; use App\Services\AuditionService; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -46,7 +47,12 @@ class JudgingController extends Controller if ($audition->prelimDefinition) { $entries = $entries->reject(fn ($entry) => ! $entry->hasFlag('passed_prelim')); } - $subscores = $audition->scoringGuide->subscores()->orderBy('display_order')->get(); + if ($audition->splitScoreDefinition) { + $subscoreIds = $audition->splitScoreDefinition->subscoresForJudge($request->user()); + $subscores = SubscoreDefinition::findMany($subscoreIds)->sortBy('display_order'); + } else { + $subscores = $audition->scoringGuide->subscores()->orderBy('display_order')->get(); + } $votes = JudgeAdvancementVote::where('user_id', Auth::id())->get(); $published = $audition->hasFlag('advancement_published') || $audition->hasFlag('seats_published'); @@ -76,12 +82,17 @@ class JudgingController extends Controller return redirect()->route('judging.auditionEntryList', $entry->audition)->with('error', 'The requested entry is marked as having failed a prelim. Scores cannot be entered.'); } + if ($entry->audition->splitScoreDefinition) { + $limitedSubscores = $entry->audition->splitScoreDefinition->subscoresForJudge($request->user()); + } else { + $limitedSubscores = false; + } $oldSheet = ScoreSheet::where('user_id', Auth::id())->where('entry_id', $entry->id)->value('subscores') ?? null; $oldVote = JudgeAdvancementVote::where('user_id', Auth::id())->where('entry_id', $entry->id)->first(); $oldVote = $oldVote ? $oldVote->vote : 'noVote'; - return view('judging.entry_score_sheet', compact('entry', 'oldSheet', 'oldVote')); + return view('judging.entry_score_sheet', compact('entry', 'oldSheet', 'oldVote', 'limitedSubscores')); } public function saveScoreSheet(Request $request, Entry $entry, EnterScore $enterScore) @@ -91,7 +102,13 @@ class JudgingController extends Controller } // Validate form data - $subscores = $entry->audition->subscoreDefinitions; + if ($entry->audition->splitScoreDefinition) { + $subscoreIDs = $entry->audition->splitScoreDefinition->subscoresForJudge($request->user()); + $subscores = SubscoreDefinition::findMany($subscoreIDs); + + } else { + $subscores = $entry->audition->subscoreDefinitions; + } $validationChecks = []; foreach ($subscores as $subscore) { $validationChecks['score'.'.'.$subscore->id] = 'required|integer|max:'.$subscore->max_score; diff --git a/app/Models/SplitScoreDefinition.php b/app/Models/SplitScoreDefinition.php index 37efa63..1cde9ea 100644 --- a/app/Models/SplitScoreDefinition.php +++ b/app/Models/SplitScoreDefinition.php @@ -19,4 +19,18 @@ class SplitScoreDefinition extends Model { return $this->belongsTo(Audition::class); } + + public function subscoresForJudge(User $judge): array + { + $validSubscores = []; + foreach ($this->splits as $split) { + if (in_array($judge->id, $split['judges'])) { + foreach ($split['subscores'] as $subscore) { + $validSubscores[] = $subscore; + } + } + } + + return $validSubscores; + } } diff --git a/resources/views/judging/entry_score_sheet.blade.php b/resources/views/judging/entry_score_sheet.blade.php index e4ef21a..5e8068c 100644 --- a/resources/views/judging/entry_score_sheet.blade.php +++ b/resources/views/judging/entry_score_sheet.blade.php @@ -21,6 +21,7 @@ @endif @foreach($entry->audition->scoringGuide->subscores()->orderBy('display_order')->get() as $subscore) + @continue($limitedSubscores && ! in_array($subscore->id, $limitedSubscores)) @php if($oldScores) { $value = $oldScores['score'][$subscore->id];