diff --git a/app/Actions/Tabulation/CheckPrelimResult.php b/app/Actions/Tabulation/CheckPrelimResult.php new file mode 100644 index 0000000..3317196 --- /dev/null +++ b/app/Actions/Tabulation/CheckPrelimResult.php @@ -0,0 +1,61 @@ +removeFlag('passed_prelim'); + $entry->removeFlag('failed_prelim'); + } + + if (! $entry->exists) { + throw new AuditionAdminException('Entry does not exist'); + } + + if (! $entry->audition->prelimDefinition) { + throw new AuditionAdminException('Entry does not have a prelim'); + } + + if ($entry->hasFlag('failed_prelim') || $entry->hasFlag('passed_prelim')) { + return 'noChange'; + } + + if (! $entry->audition->prelimDefinition->room || $entry->audition->prelimDefinition->room->judges()->count() == 0) { + return 'noJudgesAssigned'; + } + + $scoresRequired = $entry->audition->prelimDefinition->room->judges()->count(); + $scoresAssigned = $entry->prelimScoreSheets()->count(); + if ($scoresAssigned < $scoresRequired) { + return 'missing'.$scoresRequired - $scoresAssigned.'scores'; + } + + $totalScore = 0; + foreach ($entry->prelimScoreSheets as $scoreSheet) { + $totalScore += $scoreSheet->total; + } + $averageScore = $totalScore / $scoresAssigned; + if ($averageScore >= $entry->audition->prelimDefinition->passing_score) { + $entry->addFlag('passed_prelim'); + + return 'markedPassed'; + } else { + $entry->addFlag('failed_prelim'); + + return 'markedFailed'; + } + } +} diff --git a/app/Actions/Tabulation/EnterPrelimScore.php b/app/Actions/Tabulation/EnterPrelimScore.php new file mode 100644 index 0000000..76536e3 --- /dev/null +++ b/app/Actions/Tabulation/EnterPrelimScore.php @@ -0,0 +1,137 @@ +id)->exists()) { + throw new AuditionAdminException('User does not exist'); + } + if (! Entry::where('id', $entry->id)->exists()) { + throw new AuditionAdminException('Entry does not exist'); + } + if ($entry->audition->hasFlag('seats_published')) { + throw new AuditionAdminException('Cannot score an entry in an audition where seats are published'); + } + + // Check if the entries audition has a prelim definition + if (! PrelimDefinition::where('audition_id', $entry->audition->id)->exists()) { + throw new AuditionAdminException('The entries audition does not have a prelim'); + } + $prelimDefinition = PrelimDefinition::where('audition_id', $entry->audition->id)->first(); + + // Don't allow changes to prelims scores if the entry has a finals score + if ($entry->scoreSheets()->count() > 0) { + throw new AuditionAdminException('Cannot change prelims scores for an entry that has finals scores'); + } + + // Check that the specified user is assigned to judge this entry in prelims + $check = DB::table('room_user') + ->where('user_id', $user->id) + ->where('room_id', $prelimDefinition->room_id)->exists(); + if (! $check) { + throw new AuditionAdminException('This judge is not assigned to judge this entry in prelims'); + } + + // Check if a score already exists + if (! $prelimScoreSheet) { + if (PrelimScoreSheet::where('user_id', $user->id)->where('entry_id', $entry->id)->exists()) { + throw new AuditionAdminException('That judge has already entered a prelim score for that entry'); + } + } else { + if ($prelimScoreSheet->user_id != $user->id) { + throw new AuditionAdminException('Existing score sheet is from a different judge'); + } + if ($prelimScoreSheet->entry_id != $entry->id) { + throw new AuditionAdminException('Existing score sheet is for a different entry'); + } + } + + // Check the validity of submitted subscores, format array for storage, and sum score + $subscoresRequired = $prelimDefinition->scoringGuide->subscores; + $subscoresStorageArray = []; + $totalScore = 0; + $maxPossibleTotal = 0; + if ($scores->count() !== $subscoresRequired->count()) { + throw new AuditionAdminException('Invalid number of scores'); + } + + foreach ($subscoresRequired as $subscore) { + // check that there is an element in the $scores collection with the key = $subscore->id + if (! $scores->keys()->contains($subscore->id)) { + throw new AuditionAdminException('Invalid Score Submission'); + } + + if ($scores[$subscore->id] > $subscore->max_score) { + throw new AuditionAdminException('Supplied subscore exceeds maximum allowed'); + } + + // Add subscore to the storage array + $subscoresStorageArray[$subscore->id] = [ + 'score' => $scores[$subscore->id], + 'subscore_id' => $subscore->id, + 'subscore_name' => $subscore->name, + ]; + + // Multiply subscore by weight then add to total + $totalScore += ($subscore->weight * $scores[$subscore->id]); + $maxPossibleTotal += ($subscore->weight * $subscore->max_score); + } + $finalTotalScore = ($maxPossibleTotal === 0) ? 0 : (($totalScore / $maxPossibleTotal) * 100); + + $entry->removeFlag('no_show'); + if ($prelimScoreSheet instanceof PrelimScoreSheet) { + $prelimScoreSheet->update([ + 'user_id' => $user->id, + 'entry_id' => $entry->id, + 'subscores' => $subscoresStorageArray, + 'total' => $finalTotalScore, + ]); + } else { + $prelimScoreSheet = PrelimScoreSheet::create([ + 'user_id' => $user->id, + 'entry_id' => $entry->id, + 'subscores' => $subscoresStorageArray, + 'total' => $finalTotalScore, + ]); + } + + // Log the prelim score entry + $log_message = 'Entered prelim score for entry id '.$entry->id.'.
'; + $log_message .= 'Judge: '.$user->full_name().'
'; + foreach ($prelimScoreSheet->subscores as $subscore) { + $log_message .= $subscore['subscore_name'].': '.$subscore['score'].'
'; + } + $log_message .= 'Total :'.$prelimScoreSheet->total.'
'; + auditionLog($log_message, [ + 'entries' => [$entry->id], + 'users' => [$user->id], + 'auditions' => [$entry->audition_id], + 'students' => [$entry->student_id], + ]); + + // Check if we can make a status decision + $checker = app(CheckPrelimResult::class); + $checker($entry, true); + + return $prelimScoreSheet; + } +} diff --git a/app/Console/Commands/fictionalize.php b/app/Console/Commands/fictionalize.php index 4ad0984..cc1e0c4 100644 --- a/app/Console/Commands/fictionalize.php +++ b/app/Console/Commands/fictionalize.php @@ -8,48 +8,80 @@ use App\Models\User; use Faker\Factory; use Illuminate\Console\Command; -/** - * @codeCoverageIgnore - */ class fictionalize extends Command { - /** - * The name and signature of the console command. - * - * @var string - */ - protected $signature = 'audition:fictionalize'; + protected $signature = 'audition:fictionalize + {--students : Fictionalize student names} + {--schools : Fictionalize school names} + {--users : Fictionalize user data} + {--all : Fictionalize all data types}'; - /** - * The console command description. - * - * @var string - */ - protected $description = 'Command description'; + protected $description = 'Replace real names with fictional data for specified entity types'; - /** - * Execute the console command. - */ public function handle() { $faker = Factory::create(); - foreach (Student::all() as $student) { - $student->first_name = $faker->firstName(); - $student->last_name = $faker->lastName(); - $student->save(); + + // If no options are specified or --all is used, process everything + $processAll = $this->option('all') || + (! $this->option('students') && ! $this->option('schools') && ! $this->option('users')); + + if ($processAll || $this->option('students')) { + $this->info('Fictionalizing students...'); + $bar = $this->output->createProgressBar(Student::count()); + + Student::chunk(100, function ($students) use ($faker, $bar) { + foreach ($students as $student) { + $student->update([ + 'first_name' => $faker->firstName(), + 'last_name' => $faker->lastName(), + ]); + $bar->advance(); + } + }); + + $bar->finish(); + $this->newLine(); } - foreach (School::all() as $school) { - $school->name = $faker->city().' High School'; - $school->save(); + if ($processAll || $this->option('schools')) { + $this->info('Fictionalizing schools...'); + $bar = $this->output->createProgressBar(School::count()); + + School::chunk(100, function ($schools) use ($faker, $bar) { + foreach ($schools as $school) { + $school->update([ + 'name' => $faker->city().' High School', + ]); + $bar->advance(); + } + }); + + $bar->finish(); + $this->newLine(); } - foreach (User::where('email', '!=', 'matt@mattyoung.us')->get() as $user) { - $user->email = $faker->email(); - $user->first_name = $faker->firstName(); - $user->last_name = $faker->lastName(); - $user->cell_phone = $faker->phoneNumber(); - $user->save(); + if ($processAll || $this->option('users')) { + $this->info('Fictionalizing users...'); + $bar = $this->output->createProgressBar(User::where('email', '!=', 'matt@mattyoung.us')->count()); + + User::where('email', '!=', 'matt@mattyoung.us') + ->chunk(100, function ($users) use ($faker, $bar) { + foreach ($users as $user) { + $user->update([ + 'email' => $faker->unique()->email(), + 'first_name' => $faker->firstName(), + 'last_name' => $faker->lastName(), + 'cell_phone' => $faker->phoneNumber(), + ]); + $bar->advance(); + } + }); + + $bar->finish(); + $this->newLine(); } + + $this->info('Fictionalization complete!'); } } diff --git a/app/Enums/EntryFlags.php b/app/Enums/EntryFlags.php index bb87b0d..5129f35 100644 --- a/app/Enums/EntryFlags.php +++ b/app/Enums/EntryFlags.php @@ -8,5 +8,6 @@ enum EntryFlags: string case DECLINED = 'declined'; case NO_SHOW = 'no_show'; case FAILED_PRELIM = 'failed_prelim'; + case PASSED_PRELIM = 'passed_prelim'; case LATE_FEE_WAIVED = 'late_fee_waived'; } diff --git a/app/Http/Controllers/Admin/EntryController.php b/app/Http/Controllers/Admin/EntryController.php index c7b8cdb..dbd2fd3 100644 --- a/app/Http/Controllers/Admin/EntryController.php +++ b/app/Http/Controllers/Admin/EntryController.php @@ -7,6 +7,7 @@ use App\Actions\Entries\UpdateEntry; use App\Http\Controllers\Controller; use App\Http\Requests\EntryStoreRequest; use App\Models\Audition; +use App\Models\AuditLogEntry; use App\Models\Entry; use App\Models\School; use App\Models\Seat; @@ -139,7 +140,9 @@ class EntryController extends Controller // TODO: When updating Laravel, can we use the chaperone method I heard about ot load the entry back into the score $scores = $entry->scoreSheets()->with('audition', 'judge', 'entry')->get(); - return view('admin.entries.edit', compact('entry', 'students', 'auditions', 'scores')); + $logEntries = AuditLogEntry::whereJsonContains('affected->entries', $entry->id)->orderBy('created_at', 'desc')->get(); + + return view('admin.entries.edit', compact('entry', 'students', 'auditions', 'scores', 'logEntries')); } public function update(Request $request, Entry $entry, UpdateEntry $updater) diff --git a/app/Http/Controllers/Admin/PrelimDefinitionController.php b/app/Http/Controllers/Admin/PrelimDefinitionController.php new file mode 100644 index 0000000..a71b272 --- /dev/null +++ b/app/Http/Controllers/Admin/PrelimDefinitionController.php @@ -0,0 +1,70 @@ +get(); + $rooms = Room::all(); + $guides = ScoringGuide::all(); + $method = 'POST'; + $action = route('admin.prelim_definitions.store'); + $prelim = false; + + return view('admin.prelim_definitions.createOrUpdate', compact('auditions', 'rooms', 'guides', 'method', 'action', 'prelim')); + } + + public function store(PrelimDefinitionStoreOrUpdateRequest $request) + { + $validated = $request->validated(); + PrelimDefinition::create($validated); + + return redirect()->route('admin.prelim_definitions.index')->with('success', 'Prelim definition created'); + } + + public function edit(PrelimDefinition $prelimDefinition) + { + $auditions = Audition::doesntHave('prelimDefinition')->get(); + $rooms = Room::all(); + $guides = ScoringGuide::all(); + $method = 'PATCH'; + $action = route('admin.prelim_definitions.update', $prelimDefinition); + $prelim = $prelimDefinition; + + return view('admin.prelim_definitions.createOrUpdate', compact('auditions', 'rooms', 'guides', 'method', 'action', 'prelim')); + + } + + public function update(PrelimDefinition $prelimDefinition, PrelimDefinitionStoreOrUpdateRequest $request) + { + $validated = $request->validated(); + $prelimDefinition->update($validated); + + return redirect()->route('admin.prelim_definitions.index')->with('success', 'Prelim definition updated'); + } + + public function destroy(PrelimDefinition $prelimDefinition) + { + $prelimDefinition->delete(); + + return redirect()->route('admin.prelim_definitions.index')->with('success', 'Prelim definition deleted'); + } +} diff --git a/app/Http/Controllers/Admin/RoomController.php b/app/Http/Controllers/Admin/RoomController.php index df5f31a..0754cf9 100644 --- a/app/Http/Controllers/Admin/RoomController.php +++ b/app/Http/Controllers/Admin/RoomController.php @@ -19,6 +19,8 @@ class RoomController extends Controller { $rooms = Room::with('auditions.entries', 'entries')->orderBy('name')->get(); + + // Check if room id 0 exists, if not, create it and assign all unassigned auditions to it if (! $rooms->contains('id', 0)) { $unassignedRoom = Room::create([ 'id' => 0, diff --git a/app/Http/Controllers/Admin/SchoolController.php b/app/Http/Controllers/Admin/SchoolController.php index d3fbca9..c8b411f 100644 --- a/app/Http/Controllers/Admin/SchoolController.php +++ b/app/Http/Controllers/Admin/SchoolController.php @@ -6,6 +6,7 @@ use App\Actions\Schools\CreateSchool; use App\Actions\Schools\SetHeadDirector; use App\Http\Controllers\Controller; use App\Http\Requests\SchoolStoreRequest; +use App\Models\AuditLogEntry; use App\Models\School; use App\Models\SchoolEmailDomain; use App\Models\User; @@ -37,8 +38,9 @@ class SchoolController extends Controller public function show(School $school) { + $logEntries = AuditLogEntry::whereJsonContains('affected->schools', $school->id)->orderBy('created_at', 'desc')->get(); - return view('admin.schools.show', ['school' => $school]); + return view('admin.schools.show', compact('school', 'logEntries')); } public function edit(School $school) diff --git a/app/Http/Controllers/Admin/ScoringGuideController.php b/app/Http/Controllers/Admin/ScoringGuideController.php index 657e9ae..a357c79 100644 --- a/app/Http/Controllers/Admin/ScoringGuideController.php +++ b/app/Http/Controllers/Admin/ScoringGuideController.php @@ -9,6 +9,7 @@ use App\Models\SubscoreDefinition; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; +use function auditionSetting; use function request; use function response; @@ -81,6 +82,10 @@ class ScoringGuideController extends Controller // Put the new subscore at the end of the list for both display and tiebreak order $display_order = SubscoreDefinition::where('scoring_guide_id', '=', $guide->id)->max('display_order') + 1; $tiebreak_order = SubscoreDefinition::where('scoring_guide_id', '=', $guide->id)->max('tiebreak_order') + 1; + if (! auditionSetting('advanceTo')) { + $validateData['for_advance'] = 0; + $validateData['for_seating'] = 1; + } SubscoreDefinition::create([ 'scoring_guide_id' => $guide->id, diff --git a/app/Http/Controllers/Admin/StudentController.php b/app/Http/Controllers/Admin/StudentController.php index 5fd2514..def4519 100644 --- a/app/Http/Controllers/Admin/StudentController.php +++ b/app/Http/Controllers/Admin/StudentController.php @@ -81,8 +81,11 @@ class StudentController extends Controller $event_entries = $student->entries()->with('audition.flags')->get()->groupBy('audition.event_id'); $events = Event::all(); + $logEntries = AuditLogEntry::whereJsonContains('affected->students', $student->id)->orderBy('created_at', + 'desc')->get(); + return view('admin.students.edit', - compact('student', 'schools', 'minGrade', 'maxGrade', 'events', 'event_entries')); + compact('student', 'schools', 'minGrade', 'maxGrade', 'events', 'event_entries', 'logEntries')); } public function update(StudentStoreRequest $request, Student $student) diff --git a/app/Http/Controllers/Admin/UserController.php b/app/Http/Controllers/Admin/UserController.php index 2c79a2d..6d7ce3b 100644 --- a/app/Http/Controllers/Admin/UserController.php +++ b/app/Http/Controllers/Admin/UserController.php @@ -31,8 +31,10 @@ class UserController extends Controller { $schools = School::orderBy('name')->get(); + $logEntries = AuditLogEntry::whereJsonContains('affected->users', $user->id)->orderBy('created_at', 'desc')->get(); + $userActions = AuditLogEntry::where('user', $user->email)->orderBy('created_at', 'desc')->get(); - return view('admin.users.edit', ['user' => $user, 'schools' => $schools]); + return view('admin.users.edit', compact('user', 'schools', 'logEntries', 'userActions')); } public function create() diff --git a/app/Http/Controllers/Judging/JudgingController.php b/app/Http/Controllers/Judging/JudgingController.php index 2b2b506..4ca72eb 100644 --- a/app/Http/Controllers/Judging/JudgingController.php +++ b/app/Http/Controllers/Judging/JudgingController.php @@ -27,7 +27,7 @@ class JudgingController extends Controller public function index() { - $rooms = Auth::user()->judgingAssignments()->with('auditions')->get(); + $rooms = Auth::user()->judgingAssignments()->with('auditions')->with('prelimAuditions')->get(); $bonusScoresToJudge = Auth::user()->bonusJudgingAssignments()->with('auditions')->get(); //$rooms->load('auditions'); @@ -41,6 +41,11 @@ class JudgingController extends Controller return redirect()->route('judging.index')->with('error', 'You are not assigned to judge that audition'); } $entries = Entry::where('audition_id', '=', $audition->id)->orderBy('draw_number')->with('audition')->get(); + + // If there is a prelim audition, only show entries that have passed the prelim + if ($audition->prelimDefinition) { + $entries = $entries->reject(fn ($entry) => ! $entry->hasFlag('passed_prelim')); + } $subscores = $audition->scoringGuide->subscores()->orderBy('display_order')->get(); $votes = JudgeAdvancementVote::where('user_id', Auth::id())->get(); diff --git a/app/Http/Controllers/Judging/PrelimJudgingController.php b/app/Http/Controllers/Judging/PrelimJudgingController.php new file mode 100644 index 0000000..21fd1e0 --- /dev/null +++ b/app/Http/Controllers/Judging/PrelimJudgingController.php @@ -0,0 +1,103 @@ +user()->cannot('judge', $prelimDefinition)) { + return redirect()->route('dashboard')->with('error', 'You are not assigned to judge that prelim audition.'); + } + $entries = $prelimDefinition->audition->entries; + $subscores = $prelimDefinition->scoringGuide->subscores()->orderBy('display_order')->get(); + $published = $prelimDefinition->audition->hasFlag('seats_published'); + + $prelimScoresheets = PrelimScoreSheet::where('user_id', Auth::id())->get()->keyBy('entry_id'); + + return view('judging.prelim_entry_list', + compact('prelimDefinition', 'entries', 'subscores', 'published', 'prelimScoresheets')); + } + + public function prelimScoreEntryForm(Entry $entry) + { + if (auth()->user()->cannot('judge', $entry->audition->prelimDefinition)) { + return redirect()->route('dashboard')->with('error', 'You are not assigned to judge that prelim audition.'); + } + if ($entry->audition->hasFlag('seats_published')) { + return redirect()->route('dashboard')->with('error', + 'Scores for entries in published auditions cannot be modified.'); + } + if ($entry->hasFlag('no_show')) { + return redirect()->route('judging.prelimEntryList', $entry->audition->prelimDefinition)->with('error', + 'The requested entry is marked as a no-show. Scores cannot be entered.'); + } + + $oldSheet = PrelimScoreSheet::where('user_id', Auth::id())->where('entry_id', + $entry->id)->value('subscores') ?? null; + + return view('judging.prelim_entry_form', compact('entry', 'oldSheet')); + } + + /** + * @throws AuditionAdminException + */ + public function savePrelimScoreSheet(Entry $entry, Request $request, EnterPrelimScore $scribe) + { + if (auth()->user()->cannot('judge', $entry->audition->prelimDefinition)) { + return redirect()->route('dashboard')->with('error', 'You are not assigned to judge that prelim audition.'); + } + + // Validate form data + $subscores = $entry->audition->prelimDefinition->scoringGuide->subscores; + $validationChecks = []; + foreach ($subscores as $subscore) { + $validationChecks['score'.'.'.$subscore->id] = 'required|integer|max:'.$subscore->max_score; + } + $validatedData = $request->validate($validationChecks); + + // Enter the score + $scribe(auth()->user(), $entry, $validatedData['score']); + + return redirect()->route('judging.prelimEntryList', $entry->audition->prelimDefinition)->with('success', + 'Entered prelim scores for '.$entry->audition->name.' '.$entry->draw_number); + } + + public function updatePrelimScoreSheet(Entry $entry, Request $request, EnterPrelimScore $scribe) + { + if (auth()->user()->cannot('judge', $entry->audition->prelimDefinition)) { + return redirect()->route('dashboard')->with('error', 'You are not assigned to judge that prelim audition.'); + } + + // Validate form data + $subscores = $entry->audition->prelimDefinition->scoringGuide->subscores; + $validationChecks = []; + foreach ($subscores as $subscore) { + $validationChecks['score'.'.'.$subscore->id] = 'required|integer|max:'.$subscore->max_score; + } + $validatedData = $request->validate($validationChecks); + + // Get the existing score + $scoreSheet = PrelimScoreSheet::where('user_id', auth()->user()->id)->where('entry_id', $entry->id)->first(); + + if (! $scoreSheet) { + return redirect()->back()->with('error', 'No score sheet exists.'); + } + + // Update the score + $scribe(auth()->user(), $entry, $validatedData['score'], $scoreSheet); + + return redirect()->route('judging.prelimEntryList', $entry->audition->prelimDefinition)->with('success', + 'Updated prelim scores for '.$entry->audition->name.' '.$entry->draw_number); + + } +} diff --git a/app/Http/Controllers/MonitorController.php b/app/Http/Controllers/MonitorController.php index 68d93f6..93414eb 100644 --- a/app/Http/Controllers/MonitorController.php +++ b/app/Http/Controllers/MonitorController.php @@ -2,8 +2,11 @@ namespace App\Http\Controllers; +use App\Models\Audition; use App\Models\Entry; +use function compact; + class MonitorController extends Controller { public function index() @@ -11,86 +14,44 @@ class MonitorController extends Controller if (! auth()->user()->hasFlag('monitor')) { abort(403); } - $method = 'POST'; - $formRoute = 'monitor.enterFlag'; - $title = 'Flag Entry'; - return view('tabulation.choose_entry', compact('method', 'formRoute', 'title')); + $auditions = Audition::orderBy('score_order')->with('flags')->get(); + $audition = null; + return view('monitor.index', compact('audition', 'auditions')); } - public function flagForm() + public function auditionStatus(Audition $audition) { if (! auth()->user()->hasFlag('monitor')) { abort(403); } - $validData = request()->validate([ - 'entry_id' => ['required', 'integer', 'exists:entries,id'], - ]); - - $entry = Entry::find($validData['entry_id']); - - // If the entries audition is published, bounce out - if ($entry->audition->hasFlag('seats_published') || $entry->audition->hasFlag('advancement_published')) { - return redirect()->route('monitor.index')->with('error', 'Cannot set flags while results are published'); + if ($audition->hasFlag('seats_published') || $audition->hasFlag('advancement_published')) { + return redirect()->route('monitor.index')->with('error', 'Results for that audition are published'); } - // If entry has scores, bounce on out - if ($entry->scoreSheets()->count() > 0) { - return redirect()->route('monitor.index')->with('error', 'That entry has existing scores'); - } + $auditions = Audition::orderBy('score_order')->with('flags')->get(); + $entries = $audition->entries()->with('flags')->with('student.school')->withCount([ + 'prelimScoreSheets', 'scoreSheets', + ])->orderBy('draw_number')->get(); - return view('monitor_entry_flag_form', compact('entry')); + return view('monitor.index', compact('audition', 'auditions', 'entries')); } - public function storeFlag(Entry $entry) + public function toggleNoShow(Entry $entry) { - if (! auth()->user()->hasFlag('monitor')) { - abort(403); - } - - // If the entries audition is published, bounce out if ($entry->audition->hasFlag('seats_published') || $entry->audition->hasFlag('advancement_published')) { - return redirect()->route('monitor.index')->with('error', 'Cannot set flags while results are published'); + return redirect()->route('monitor.index')->with('error', 'Results for that audition are published'); } - // If entry has scores, bounce on out - if ($entry->scoreSheets()->count() > 0) { - return redirect()->route('monitor.index')->with('error', 'That entry has existing scores'); - } - - $action = request()->input('action'); - $result = match ($action) { - 'failed-prelim' => $this->setFlag($entry, 'failed_prelim'), - 'no-show' => $this->setFlag($entry, 'no_show'), - 'clear' => $this->setFlag($entry, 'clear'), - default => redirect()->route('monitor.index')->with('error', 'Invalid action requested'), - }; - - return redirect()->route('monitor.index')->with('success', 'Flag set for entry #'.$entry->id); - } - - private function setFlag(Entry $entry, string $flag) - { - if ($flag === 'no_show') { - $entry->removeFlag('failed_prelim'); - $entry->addFlag('no_show'); - - return true; - } - if ($flag === 'failed_prelim') { - $entry->addFlag('failed_prelim'); - $entry->addFlag('no_show'); - - return true; - } - if ($flag === 'clear') { - $entry->removeFlag('failed_prelim'); + if ($entry->hasFlag('no_show')) { $entry->removeFlag('no_show'); - return true; + return redirect()->back()->with('success', 'No Show Flag Cleared'); } + $entry->addFlag('no_show'); + return redirect()->back()->with('success', 'No Show Entered'); } } diff --git a/app/Http/Controllers/Tabulation/ScoreController.php b/app/Http/Controllers/Tabulation/ScoreController.php index d506b47..b25509a 100644 --- a/app/Http/Controllers/Tabulation/ScoreController.php +++ b/app/Http/Controllers/Tabulation/ScoreController.php @@ -2,11 +2,13 @@ namespace App\Http\Controllers\Tabulation; +use App\Actions\Tabulation\EnterPrelimScore; use App\Actions\Tabulation\EnterScore; use App\Exceptions\AuditionAdminException; use App\Http\Controllers\Controller; use App\Models\Entry; use App\Models\EntryTotalScore; +use App\Models\PrelimScoreSheet; use App\Models\ScoreSheet; use App\Models\User; use Illuminate\Http\Request; @@ -67,8 +69,25 @@ class ScoreController extends Controller 'This entry is marked as a no-show. Entering a score will remove the no-show flag'); } + if ($entry->audition->prelimDefinition) { + $existing_prelim_sheets = []; + $prelim_subscores = $entry->audition->prelimDefinition->scoringGuide->subscores->sortBy('display_order'); + $prelim_judges = $entry->audition->prelimDefinition->room->judges; + foreach ($prelim_judges as $judge) { + $prelim_scoreSheet = PrelimScoreSheet::where('entry_id', $entry->id)->where('user_id', $judge->id)->first(); + if ($prelim_scoreSheet) { + Session::flash('caution', 'Prelim scores exist for this entry. Now editing existing scores'); + $existing_prelim_sheets[$judge->id] = $prelim_scoreSheet; + } + } + } else { + $prelim_subscores = null; + $prelim_judges = null; + $existing_prelim_sheets = null; + } + return view('tabulation.entry_score_sheet', - compact('entry', 'judges', 'scoring_guide', 'subscores', 'existing_sheets')); + compact('entry', 'judges', 'scoring_guide', 'subscores', 'existing_sheets', 'prelim_subscores', 'prelim_judges', 'existing_prelim_sheets')); } public function saveEntryScoreSheet(Request $request, Entry $entry, EnterScore $scoreRecorder) @@ -85,7 +104,7 @@ class ScoreController extends Controller * The array should have a key for each subscore and the value of the score submitted */ foreach ($request->all() as $key => $value) { - // We're not interested in submission values that don't ahve judge in the name + // We're not interested in submission values that don't have judge in the name if (! str_contains($key, 'judge')) { continue; } @@ -114,6 +133,50 @@ class ScoreController extends Controller return redirect()->route('scores.chooseEntry')->with('success', 'Scores saved'); } + public function savePrelimEntryScoreSheet(Request $request, Entry $entry, EnterPrelimScore $scoreRecorder) + { + $publishedCheck = $this->checkIfPublished($entry); + if ($publishedCheck) { + return $publishedCheck; + } + + /** + * Here we process the submission from the scoring form. + * We're expecting submitted data to include an array for each judge. + * Each array should be called judge+ the judges ID number + * The array should have a key for each subscore and the value of the score submitted + */ + foreach ($request->all() as $key => $value) { + // We're not interested in submission values that don't have judge in the name + if (! str_contains($key, 'judge')) { + continue; + } + // Extract the judge ID from the field name and load the user + $judge_id = str_replace('judge', '', $key); + $judge = User::find($judge_id); + + // Check for existing scores, if so, tell EnterScores action that we're updating it, otherwise a new score + $existingScore = PrelimScoreSheet::where('entry_id', $entry->id) + ->where('user_id', $judge->id)->first(); + if ($existingScore === null) { + $existingScore = false; + } + + try { + $scoreRecorder($judge, $entry, $value, $existingScore); + } catch (AuditionAdminException $e) { + return redirect()->route('scores.entryScoreSheet', ['entry_id' => $entry->id]) + ->with('error', $e->getMessage()); + } + } + + // Since we're entering a score, this apparently isn't a no show. + $entry->removeFlag('no_show'); + + return redirect()->route('scores.chooseEntry')->with('success', 'Prelim Scores Saved'); + + } + protected function checkIfPublished($entry) { // We're not going to enter scores if seats are published diff --git a/app/Http/Controllers/Tabulation/Seating/ShowAuditionSeatingPage.php b/app/Http/Controllers/Tabulation/Seating/ShowAuditionSeatingPage.php index 79d6b52..7f92acf 100644 --- a/app/Http/Controllers/Tabulation/Seating/ShowAuditionSeatingPage.php +++ b/app/Http/Controllers/Tabulation/Seating/ShowAuditionSeatingPage.php @@ -69,9 +69,14 @@ class ShowAuditionSeatingPage extends Controller $query->where('flag_name', 'failed_prelim'); }) ->with('student.school') + ->with('PrelimScoreSheets') ->orderBy('draw_number') ->get(); + $failed_prelim_entries = $failed_prelim_entries->sortByDesc(function ($entry) { + return $entry->prelimTotalScore(); + }); + // Get Doublers $doublerData = Doubler::where('event_id', $audition->event_id) ->whereIn('student_id', $scored_entries->pluck('student_id')) diff --git a/app/Http/Requests/PrelimDefinitionStoreOrUpdateRequest.php b/app/Http/Requests/PrelimDefinitionStoreOrUpdateRequest.php new file mode 100644 index 0000000..d2cef01 --- /dev/null +++ b/app/Http/Requests/PrelimDefinitionStoreOrUpdateRequest.php @@ -0,0 +1,28 @@ + [ + 'required', + 'exists:auditions,id', + Rule::unique('prelim_definitions', 'audition_id')->ignore($this->prelimDefinition), + ], + 'room_id' => ['nullable', 'exists:rooms,id'], + 'scoring_guide_id' => ['nullable', 'exists:scoring_guides,id'], + 'passing_score' => ['required', 'integer', 'min:0', 'max:100'], + ]; + } + + public function authorize(): bool + { + return auth()->user()->is_admin; + } +} diff --git a/app/Models/Audition.php b/app/Models/Audition.php index 6c86d5f..9ae5c8a 100644 --- a/app/Models/Audition.php +++ b/app/Models/Audition.php @@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Support\Collection; use function in_array; @@ -165,6 +166,11 @@ class Audition extends Model return $this->hasMany(Seat::class); } + public function prelimDefinition(): HasOne + { + return $this->hasOne(PrelimDefinition::class); + } + /** * @codeCoverageIgnoreStart */ diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 9cbc7c3..a64e1cf 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -136,6 +136,35 @@ class Entry extends Model } + public function prelimScoreSheets(): HasMany + { + return $this->hasMany(PrelimScoreSheet::class); + } + + public function prelimTotalScore() + { + return once(function () { + $total = 0; + foreach ($this->prelimScoreSheets as $sheet) { + $total += $sheet->total; + } + + return $total / $this->prelimScoreSheets->count(); + }); + } + + public function prelimResult() + { + if ($this->hasFlag('passed_prelim')) { + return 'passed'; + } + if ($this->hasFlag('failed_prelim')) { + return 'failed'; + } + + return null; + } + public function bonusScores(): HasMany { return $this->hasMany(BonusScore::class); @@ -172,6 +201,7 @@ class Entry extends Model 'declined' => EntryFlags::DECLINED, 'no_show' => EntryFlags::NO_SHOW, 'failed_prelim' => EntryFlags::FAILED_PRELIM, + 'passed_prelim' => EntryFlags::PASSED_PRELIM, 'late_fee_waived' => EntryFlags::LATE_FEE_WAIVED, }; $this->flags()->create(['flag_name' => $enum]); diff --git a/app/Models/PrelimDefinition.php b/app/Models/PrelimDefinition.php new file mode 100644 index 0000000..dfa7f47 --- /dev/null +++ b/app/Models/PrelimDefinition.php @@ -0,0 +1,32 @@ +belongsTo(Audition::class); + } + + public function room(): BelongsTo + { + return $this->belongsTo(Room::class); + } + + public function scoringGuide(): BelongsTo + { + return $this->belongsTo(ScoringGuide::class); + } +} diff --git a/app/Models/PrelimScoreSheet.php b/app/Models/PrelimScoreSheet.php new file mode 100644 index 0000000..67ff953 --- /dev/null +++ b/app/Models/PrelimScoreSheet.php @@ -0,0 +1,34 @@ + 'json']; + + public function user(): HasOne + { + return $this->hasOne(User::class); + } + + public function entry(): HasOne + { + return $this->hasOne(Entry::class); + } + + public function getSubscore($id) + { + return $this->subscores[$id]['score'] ?? false; + // this function is used at resources/views/tabulation/entry_score_sheet.blade.php + } +} diff --git a/app/Models/Room.php b/app/Models/Room.php index ce615ad..aa4de9a 100644 --- a/app/Models/Room.php +++ b/app/Models/Room.php @@ -19,6 +19,11 @@ class Room extends Model return $this->hasMany(Audition::class)->orderBy('order_in_room')->orderBy('score_order'); } + public function prelimAuditions(): HasMany + { + return $this->hasMany(PrelimDefinition::class); + } + public function entries(): HasManyThrough { return $this->hasManyThrough( diff --git a/app/Observers/PrelimDefinitionObserver.php b/app/Observers/PrelimDefinitionObserver.php new file mode 100644 index 0000000..e66a915 --- /dev/null +++ b/app/Observers/PrelimDefinitionObserver.php @@ -0,0 +1,51 @@ +audition->name.'.'; + $affected = ['auditions' => [$prelimDefinition->audition_id]]; + auditionLog($message, $affected); + } + + /** + * Handle the PrelimDefinition "updated" event. + */ + public function updated(PrelimDefinition $prelimDefinition): void + { + $message = 'Updated Prelim for '.$prelimDefinition->audition->name.'.'; + if ($prelimDefinition->getOriginal('room_id') !== $prelimDefinition->room_id) { + $oldRoom = Room::find($prelimDefinition->getOriginal('room_id')); + $message .= '
Room: '.$oldRoom->name.' -> '.$prelimDefinition->room->name; + } + + if ($prelimDefinition->getOriginal('scoring_guide_id') !== $prelimDefinition->scoring_guide_id) { + $oldScoringGuide = ScoringGuide::find($prelimDefinition->getOriginal('scoring_guide_id')); + $message .= '
Scoring Guide: '.$oldScoringGuide->name.' -> '.$prelimDefinition->scoringGuide->name; + } + + if ($prelimDefinition->getOriginal('passing_score') !== $prelimDefinition->passing_score) { + $message .= '
Passing Score: '.$prelimDefinition->getOriginal('passing_score').' -> '.$prelimDefinition->passing_score; + } + auditionLog($message, ['auditions' => [$prelimDefinition->audition_id]]); + } + + /** + * Handle the PrelimDefinition "deleted" event. + */ + public function deleted(PrelimDefinition $prelimDefinition): void + { + $message = 'Deleted Prelim for '.$prelimDefinition->audition->name.'.'; + auditionLog($message, ['auditions' => [$prelimDefinition->audition_id]]); + } +} diff --git a/app/Policies/PrelimDefinitionPolicy.php b/app/Policies/PrelimDefinitionPolicy.php new file mode 100644 index 0000000..e8d63e1 --- /dev/null +++ b/app/Policies/PrelimDefinitionPolicy.php @@ -0,0 +1,50 @@ +is_admin; + } + + public function view(User $user, PrelimDefinition $prelimDefinition): bool + { + return $user->is_admin; + } + + public function create(User $user): bool + { + return $user->is_admin; + } + + public function update(User $user, PrelimDefinition $prelimDefinition): bool + { + return $user->is_admin; + } + + public function delete(User $user, PrelimDefinition $prelimDefinition): bool + { + return $user->is_admin; + } + + public function judge(User $user, PrelimDefinition $prelimDefinition): bool + { + return $user->judgingAssignments->contains($prelimDefinition->room_id); + } + + public function restore(User $user, PrelimDefinition $prelimDefinition): bool + { + } + + public function forceDelete(User $user, PrelimDefinition $prelimDefinition): bool + { + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 398ee75..c7288e0 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -12,6 +12,7 @@ use App\Models\BonusScore; use App\Models\Entry; use App\Models\EntryFlag; use App\Models\Event; +use App\Models\PrelimDefinition; use App\Models\School; use App\Models\SchoolEmailDomain; use App\Models\ScoreSheet; @@ -23,6 +24,7 @@ use App\Observers\BonusScoreObserver; use App\Observers\EntryFlagObserver; use App\Observers\EntryObserver; use App\Observers\EventObserver; +use App\Observers\PrelimDefinitionObserver; use App\Observers\SchoolEmailDomainObserver; use App\Observers\SchoolObserver; use App\Observers\ScoreSheetObserver; @@ -69,6 +71,7 @@ class AppServiceProvider extends ServiceProvider EntryFlag::observe(EntryFlagObserver::class); Event::observe(EventObserver::class); School::observe(SchoolObserver::class); + PrelimDefinition::observe(PrelimDefinitionObserver::class); SchoolEmailDomain::observe(SchoolEmailDomainObserver::class); ScoreSheet::observe(ScoreSheetObserver::class); ScoringGuide::observe(ScoringGuideObserver::class); diff --git a/database/migrations/2025_09_11_141701_create_prelim_definitions_table.php b/database/migrations/2025_09_11_141701_create_prelim_definitions_table.php new file mode 100644 index 0000000..fbb61a6 --- /dev/null +++ b/database/migrations/2025_09_11_141701_create_prelim_definitions_table.php @@ -0,0 +1,29 @@ +id(); + $table->foreignIdFor(Audition::class)->unique()->constrained()->cascadeOnDelete()->cascadeOnUpdate(); + $table->foreignIdFor(Room::class)->nullable()->constrained()->nullOnDelete()->cascadeOnUpdate(); + $table->integer('order_in_room')->nullable(); + $table->foreignIdFor(ScoringGuide::class)->nullable()->constrained()->nullOnDelete()->cascadeOnUpdate(); + $table->float('passing_score'); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('prelim_definitions'); + } +}; diff --git a/database/migrations/2025_09_23_020626_create_prelim_score_sheets_table.php b/database/migrations/2025_09_23_020626_create_prelim_score_sheets_table.php new file mode 100644 index 0000000..a1cc58a --- /dev/null +++ b/database/migrations/2025_09_23_020626_create_prelim_score_sheets_table.php @@ -0,0 +1,34 @@ +id(); + $table->foreignIdFor(User::class)->constrained()->cascadeOnDelete()->cascadeOnUpdate(); + $table->foreignIdFor(Entry::class)->constrained()->cascadeOnDelete()->cascadeOnUpdate(); + $table->json('subscores'); + $table->decimal('total', 9, 6); + $table->timestamps(); + $table->unique(['user_id', 'entry_id']); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('prelim_score_sheets'); + } +}; diff --git a/resources/views/admin/entries/edit.blade.php b/resources/views/admin/entries/edit.blade.php index a2b6912..9fcce7e 100644 --- a/resources/views/admin/entries/edit.blade.php +++ b/resources/views/admin/entries/edit.blade.php @@ -127,4 +127,29 @@ + + + Log Entries + + + + Timestamp + IP + User + Message + + + + + @foreach($logEntries as $logEntry) + + {{ $logEntry->created_at }} + {{ $logEntry->ip_address }} + {{ $logEntry->user }} + {!! $logEntry->message !!} + + @endforeach + + + diff --git a/resources/views/admin/prelim_definitions/createOrUpdate.blade.php b/resources/views/admin/prelim_definitions/createOrUpdate.blade.php new file mode 100644 index 0000000..d512595 --- /dev/null +++ b/resources/views/admin/prelim_definitions/createOrUpdate.blade.php @@ -0,0 +1,66 @@ + + Manage Prelim Auditions +
+ + + @if($prelim) + Modify Prelim - {{ $prelim->audition->name }} + + + Confirm that you'd like to delete prelim auditions for {{ $prelim->audition->name }}. +{{-- TODO: Block deleting a prelim audition if there are prelim scores --}} + + + @else + Create Prelim Audition + @endif + + + + + + Audition + @if($prelim) + + @else + + @foreach($auditions as $audition) + + @endforeach + @endif + + + @error('audition_id') +
{{ $message }}
+ @enderror + + + Room + @foreach($rooms as $room) + + @endforeach + + @error('room_id') +
{{ $message }}
+ @enderror + + + Scoring Guide + @foreach($guides as $guide) + + @endforeach + + @error('scoring_guide_id') +
{{ $message }}
+ @enderror + + + + + +
+
+
+
diff --git a/resources/views/admin/prelim_definitions/index.blade.php b/resources/views/admin/prelim_definitions/index.blade.php new file mode 100644 index 0000000..7334222 --- /dev/null +++ b/resources/views/admin/prelim_definitions/index.blade.php @@ -0,0 +1,33 @@ + + Prelim Audition Setup + + + Preliminary Auditions + Click to edit or delete + + Add Prelim + + + + + + Audition + Passing Score + Room + Scoring Guide + + + + @foreach ($prelims as $prelim) + + {{ $prelim->audition->name }} + {{ $prelim->passing_score }} + {{ $prelim->room->name }} + {{ $prelim->scoringGuide->name }} + + @endforeach + + + + diff --git a/resources/views/admin/schools/show.blade.php b/resources/views/admin/schools/show.blade.php index 6ae3d6f..ed08931 100644 --- a/resources/views/admin/schools/show.blade.php +++ b/resources/views/admin/schools/show.blade.php @@ -62,4 +62,30 @@ + + + Log Entries + + + + Timestamp + IP + User + Message + + + + + @foreach($logEntries as $logEntry) + + {{ $logEntry->created_at }} + {{ $logEntry->ip_address }} + {{ $logEntry->user }} + {!! $logEntry->message !!} + + @endforeach + + + + diff --git a/resources/views/admin/students/edit.blade.php b/resources/views/admin/students/edit.blade.php index cdc76be..0e85759 100644 --- a/resources/views/admin/students/edit.blade.php +++ b/resources/views/admin/students/edit.blade.php @@ -80,4 +80,29 @@ @endforeach + + + Log Entries + + + + Timestamp + IP + User + Message + + + + + @foreach($logEntries as $logEntry) + + {{ $logEntry->created_at }} + {{ $logEntry->ip_address }} + {{ $logEntry->user }} + {!! $logEntry->message !!} + + @endforeach + + + diff --git a/resources/views/admin/users/edit.blade.php b/resources/views/admin/users/edit.blade.php index 9ac2c34..be2a031 100644 --- a/resources/views/admin/users/edit.blade.php +++ b/resources/views/admin/users/edit.blade.php @@ -53,4 +53,54 @@ + + + User Actions + + + + Timestamp + IP + User + Message + + + + + @foreach($userActions as $logEntry) + + {{ $logEntry->created_at }} + {{ $logEntry->ip_address }} + {{ $logEntry->user }} + {!! $logEntry->message !!} + + @endforeach + + + + + + Log Entries Affecting User + + + + Timestamp + IP + User + Message + + + + + @foreach($logEntries as $logEntry) + + {{ $logEntry->created_at }} + {{ $logEntry->ip_address }} + {{ $logEntry->user }} + {!! $logEntry->message !!} + + @endforeach + + + diff --git a/resources/views/components/index.blade.php b/resources/views/components/index.blade.php new file mode 100644 index 0000000..b80e6e0 --- /dev/null +++ b/resources/views/components/index.blade.php @@ -0,0 +1,3 @@ +
+ +
diff --git a/resources/views/components/layout/navbar/menus/setup.blade.php b/resources/views/components/layout/navbar/menus/setup.blade.php index 807811d..5e226d6 100644 --- a/resources/views/components/layout/navbar/menus/setup.blade.php +++ b/resources/views/components/layout/navbar/menus/setup.blade.php @@ -23,6 +23,7 @@ Audition Settings Events Auditions + Prelim Auditions Ensembles Seating Limits Scoring diff --git a/resources/views/judging/index.blade.php b/resources/views/judging/index.blade.php index 5d371f4..36b6b72 100644 --- a/resources/views/judging/index.blade.php +++ b/resources/views/judging/index.blade.php @@ -13,6 +13,11 @@ {{ $audition->name }} @endforeach + @foreach($room->prelimAuditions as $prelimAudition) + + {{ $prelimAudition->audition->name }} Prelims + + @endforeach @endforeach diff --git a/resources/views/judging/prelim_entry_form.blade.php b/resources/views/judging/prelim_entry_form.blade.php new file mode 100644 index 0000000..58ca75b --- /dev/null +++ b/resources/views/judging/prelim_entry_form.blade.php @@ -0,0 +1,58 @@ + + @php + $oldScores = session()->get('oldScores') ?? null; + @endphp + + Prelim Score Entry + + + {{ $entry->audition->name }} {{ $entry->draw_number }} + +
    +
  • All Scores must be complete
  • +
  • You may enter zero
  • +
  • Whole numbers only
  • +
+
+
+ + @if($oldSheet) + {{-- if there are existing scores, make this a patch request --}} + @method('PATCH') + @endif + + @foreach($entry->audition->prelimDefinition->scoringGuide->subscores()->orderBy('display_order')->get() as $subscore) + @php + if($oldScores) { + $value = $oldScores['score'][$subscore->id]; + } elseif ($oldSheet) { + $value = $oldSheet[$subscore->id]['score']; + } else { + $value = ''; + } + @endphp + +
  • + + + {{ $subscore->name }} max: {{$subscore->max_score}} + + + +
  • + + @endforeach +
    + + Save Scores + +
    +
    +
    diff --git a/resources/views/judging/prelim_entry_list.blade.php b/resources/views/judging/prelim_entry_list.blade.php new file mode 100644 index 0000000..1c308ad --- /dev/null +++ b/resources/views/judging/prelim_entry_list.blade.php @@ -0,0 +1,58 @@ +@php use Illuminate\Support\Facades\Auth; @endphp + + Judging Dashboard + + + {{ $prelimDefinition->audition->name }} Prelims + @if($published) + Results are published. Scores cannot be changed. + + @endif + + + + + Entry + @foreach($subscores as $subscore) + + @endforeach + Timestamp + + + + @foreach($entries as $entry) + {{-- @continue($entry->hasFlag('no_show'))--}} + + + @if(! $published && ! $entry->hasFlag('no_show') && $entry->scoreSheets()->count() < 1) + + @endif + {{ $prelimDefinition->audition->name }} {{ $entry->draw_number }} + @if($entry->hasFlag('no_show')) +

    No Show

    + @endif + @if($entry->scoreSheets()->count() > 0) +

    Has Finals Scores

    + @endif + @if(! $published && ! $entry->hasFlag('no_show') && $entry->scoreSheets()->count() < 1) +
    + @endif +
    + @foreach($subscores as $subscore) + + @endforeach + + @if($prelimScoresheets->has($entry->id)) + {{ $prelimScoresheets[$entry->id]->created_at->setTimezone('America/Chicago')->format('m/d/y H:i') }} + @endif + + + @endforeach +
    +
    +
    +
    diff --git a/resources/views/monitor/index.blade.php b/resources/views/monitor/index.blade.php new file mode 100644 index 0000000..1103f8c --- /dev/null +++ b/resources/views/monitor/index.blade.php @@ -0,0 +1,76 @@ + + Monitor Dashboard + + + Audition Status + + + + @foreach ($auditions as $menuAudition) + @continue($menuAudition->hasFlag('seats_published') || $menuAudition->hasFlag('advance_published')) + + @endforeach + + + + @if($audition) + + + + Entry + @if($audition->prelimDefinition) + Prelim
    Scores
    + @endif + Finals
    Scores
    + + + + + @foreach($entries as $entry) + + + {{ $audition->name }} {{ $entry->draw_number }}
    + @if($audition->prelimDefinition && ! $entry->hasFlag('no_show')) + @if($entry->hasFlag('failed_prelim')) + Failed + @elseif($entry->hasFlag('passed_prelim')) + Passed + @else + Pending + @endif + @elseif($entry->hasFlag('no_show')) + No-Show + @endif +
    + @if($audition->prelimDefinition) + + {{ $entry->prelim_score_sheets_count }} + + @endif + + {{ $entry->score_sheets_count }} + + + + @if($entry->prelim_score_sheets_count < 1 && $entry->score_sheets_count < 1 && ! $entry->hasFlag('no_show') && ! $audition->hasFlag('seats_published')) + @include('monitor.noshow_modal') + @endif + + @if($entry->hasFlag('no_show') && ! $audition->hasFlag('seats_published')) + @include('monitor.remove_nowshow_modal') + @endif + + + @endforeach +
    +
    + @endif +
    + + +
    diff --git a/resources/views/monitor/noshow_modal.blade.php b/resources/views/monitor/noshow_modal.blade.php new file mode 100644 index 0000000..bf0dd97 --- /dev/null +++ b/resources/views/monitor/noshow_modal.blade.php @@ -0,0 +1,19 @@ + + + Mark No-Show + + Mark {{ $audition->name }} {{ $entry->draw_number }} + as a no-show + + Confirm that you would like to mark this entry as a no-show
    + {{ $audition->name }} {{ $entry->draw_number }}
    + Entry ID: {{ $entry->id }}
    + Name: {{ $entry->student->full_name() }}
    + School: {{ $entry->student->school->name }} +
    + + Confirm + No-Show
    {{ $audition->name }} {{ $entry->draw_number }} +
    +
    +
    diff --git a/resources/views/monitor/remove_nowshow_modal.blade.php b/resources/views/monitor/remove_nowshow_modal.blade.php new file mode 100644 index 0000000..9071722 --- /dev/null +++ b/resources/views/monitor/remove_nowshow_modal.blade.php @@ -0,0 +1,18 @@ + + + Undo No-Show + + Remove No-Show Flag for {{ $audition->name }} {{ $entry->draw_number }} + + Confirm that you would like to remove the no-show flag for this entry
    + {{ $audition->name }} {{ $entry->draw_number }}
    + Entry ID: {{ $entry->id }}
    + Name: {{ $entry->student->full_name() }}
    + School: {{ $entry->student->school->name }} +
    + + Remove + No-Show Flag
    {{ $audition->name }} {{ $entry->draw_number }} +
    +
    +
    diff --git a/resources/views/tabulation/entry_score_sheet.blade.php b/resources/views/tabulation/entry_score_sheet.blade.php index 248b417..6f25d0f 100644 --- a/resources/views/tabulation/entry_score_sheet.blade.php +++ b/resources/views/tabulation/entry_score_sheet.blade.php @@ -3,7 +3,17 @@ Entry Score Sheet - {{ $entry->audition->name }} #{{ $entry->draw_number }} + {{ $entry->audition->name }} #{{ $entry->draw_number }} FINALS SCORES + @if($entry->hasFlag('failed_prelim')) + Failed Prelim + @elseif($entry->hasFlag('passed_prelim')) + Passed Prelim + @elseif($entry->audition->prelimDefinition) + Prelim Pending + @endif ID #{{ $entry->id }}

    {{ $entry->student->full_name() }}

    @@ -11,7 +21,8 @@
    - + @@ -33,7 +44,7 @@ @foreach($judges as $judge) @php($existingSheet = $existing_sheets[$judge->id] ?? null) - + {{ $judge->full_name() }} @foreach($subscores as $subscore) @@ -48,11 +59,11 @@ value="{{ $existingSheet->getSubscore($subscore->id) }}" @endif required -{{-- onchange="judge{{$judge->id}}sum()"--}} + {{-- onchange="judge{{$judge->id}}sum()"--}} > @endforeach - +

    0.000

    @@ -67,35 +78,145 @@
    + + @if($entry->audition->prelimDefinition) + + + {{ $entry->audition->name }} #{{ $entry->draw_number }} PRELIM SCORES + ID #{{ $entry->id }} + +

    {{ $entry->student->full_name() }}

    +

    {{ $entry->student->school->name }}

    +
    +
    + + + + + + Judges + @foreach($prelim_subscores as $subscore) + +
    +
    {{ $subscore->name }}
    +
    + Max: {{ $subscore->max_score }} + Weight: {{ $subscore->weight }} +
    +
    +
    + @endforeach + Total + + + + @foreach($prelim_judges as $judge) + @php($existingSheet = $existing_prelim_sheets[$judge->id] ?? null) + + {{ $judge->full_name() }} + @foreach($prelim_subscores as $subscore) + + + + @endforeach + +

    + 0.000 +

    +
    + + @endforeach +
    +
    + + Save Scores + +
    + +
    + @endif + + + + @if($entry->audition->prelimDefinition) + + @endif + diff --git a/resources/views/tabulation/seating-page/failed-prelim-entries.blade.php b/resources/views/tabulation/seating-page/failed-prelim-entries.blade.php index 6f76da6..669a390 100644 --- a/resources/views/tabulation/seating-page/failed-prelim-entries.blade.php +++ b/resources/views/tabulation/seating-page/failed-prelim-entries.blade.php @@ -6,6 +6,7 @@ Draw # ID Student + Score @@ -17,6 +18,7 @@ {{ $entry->student->full_name() }} {{ $entry->student->school->name }} + {{ $entry->prelimTotalScore() }} @endforeach diff --git a/routes/admin.php b/routes/admin.php index ee9c6bb..54bee53 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -11,6 +11,7 @@ use App\Http\Controllers\Admin\EntryController; use App\Http\Controllers\Admin\EventController; use App\Http\Controllers\Admin\ExportEntriesController; use App\Http\Controllers\Admin\ExportResultsController; +use App\Http\Controllers\Admin\PrelimDefinitionController; use App\Http\Controllers\Admin\PrintCards; use App\Http\Controllers\Admin\PrintRoomAssignmentsController; use App\Http\Controllers\Admin\PrintSignInSheetsController; @@ -203,4 +204,14 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')-> // Print Room and Judge Assignment Report Route::get('room_assignment_report', PrintRoomAssignmentsController::class)->name('admin.print_room_assignment_report'); + + // PrelimDefinition Routes + Route::prefix('prelim_definitions')->controller(PrelimDefinitionController::class)->group(function () { + Route::get('/', 'index')->name('admin.prelim_definitions.index'); + Route::get('/new', 'create')->name('admin.prelim_definitions.create'); + Route::post('/', 'store')->name('admin.prelim_definitions.store'); + Route::get('/{prelimDefinition}', 'edit')->name('admin.prelim_definitions.edit'); + Route::patch('/{prelimDefinition}', 'update')->name('admin.prelim_definitions.update'); + Route::delete('/{prelimDefinition}', 'destroy')->name('admin.prelim_definitions.destroy'); + }); }); diff --git a/routes/judging.php b/routes/judging.php index f5b59ab..b4b6d78 100644 --- a/routes/judging.php +++ b/routes/judging.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Judging\BonusScoreEntryController; use App\Http\Controllers\Judging\BonusScoreEntryListController; use App\Http\Controllers\Judging\BonusScoreRecordController; use App\Http\Controllers\Judging\JudgingController; +use App\Http\Controllers\Judging\PrelimJudgingController; use App\Http\Middleware\CheckIfCanJudge; use Illuminate\Support\Facades\Route; @@ -16,6 +17,14 @@ Route::middleware(['auth', 'verified', CheckIfCanJudge::class])->prefix('judging Route::patch('/entry/{entry}', 'updateScoreSheet')->name('judging.updateScoreSheet'); }); +// Prelim Audition Related Routes +Route::middleware(['auth', 'verified', CheckIfCanJudge::class])->prefix('judging/prelims')->controller(PrelimJudgingController::class)->group(function () { + Route::get('/{prelimDefinition}', 'prelimEntryList')->name('judging.prelimEntryList'); + route::get('/enterScore/{entry}', 'prelimScoreEntryForm')->name('judging.prelimScoreEntryForm'); + route::post('/enterScore/{entry}', 'savePrelimScoreSheet')->name('judging.savePrelimScoreSheet'); + route::patch('/enterScore/{entry}', 'updatePrelimScoreSheet')->name('judging.savePrelimScoreSheet'); +}); + // Bonus score judging routes Route::middleware(['auth', 'verified', CheckIfCanJudge::class])->prefix('judging/bonus_scores')->group(function () { Route::get('/{audition}', BonusScoreEntryListController::class)->name('judging.bonusScore.EntryList'); // List of entries in an audition diff --git a/routes/tabulation.php b/routes/tabulation.php index d2e5ab1..bf1acfe 100644 --- a/routes/tabulation.php +++ b/routes/tabulation.php @@ -21,6 +21,7 @@ Route::middleware(['auth', 'verified', CheckIfCanTab::class])->group(function () Route::get('/choose_entry', 'chooseEntry')->name('scores.chooseEntry'); Route::get('/entry', 'entryScoreSheet')->name('scores.entryScoreSheet'); Route::post('/entry/{entry}', 'saveEntryScoreSheet')->name('scores.saveEntryScoreSheet'); + Route::post('/entry/prelim/{entry}', 'savePrelimEntryScoreSheet')->name('scores.savePrelimEntryScoreSheet'); Route::delete('/{score}', 'destroyScore')->name('scores.destroy'); }); diff --git a/routes/web.php b/routes/web.php index 102f0e8..6b98d95 100644 --- a/routes/web.php +++ b/routes/web.php @@ -31,8 +31,8 @@ Route::prefix('filters')->middleware(['auth', 'verified'])->controller(FilterCon // Monitor Related Routes Route::prefix('monitor')->middleware(['auth', 'verified'])->controller(MonitorController::class)->group(function () { Route::get('/', 'index')->name('monitor.index'); - Route::post('/enter_flag', 'flagForm')->name('monitor.enterFlag'); - Route::post('enter_flag/{entry}', 'storeFlag')->name('monitor.storeFlag'); + Route::get('/audition/{audition}', 'auditionStatus')->name('monitor.auditionStatus'); + Route::post('/toggleNoShow/{entry}', 'toggleNoShow')->name('monitor.toggleNoShow'); }); //Route::get('/my_school', [SchoolController::class, 'my_school'])->middleware('auth','verified'); diff --git a/tests/Feature/app/Actions/Tabulation/ChekPrelimResultTest.php b/tests/Feature/app/Actions/Tabulation/ChekPrelimResultTest.php new file mode 100644 index 0000000..3594379 --- /dev/null +++ b/tests/Feature/app/Actions/Tabulation/ChekPrelimResultTest.php @@ -0,0 +1,174 @@ +tabulator = app(CheckPrelimResult::class); +}); + +it('throws an exception if the provided entry does not exist', function () { + $entry = Entry::factory()->make(); + ($this->tabulator)($entry); +})->throws(AuditionAdminException::class, 'Entry does not exist'); + +it('throws an exception if the entries audition does not have a prelim', function () { + $entry = Entry::factory()->create(); + ($this->tabulator)($entry); +})->throws(AuditionAdminException::class, 'Entry does not have a prelim'); + +it('does not change an existing decision unless forced', function () { + $entry = Entry::factory()->create(); + PrelimDefinition::create([ + 'audition_id' => $entry->audition_id, + 'passing_score' => 80, + ]); + $entry->addFlag('failed_prelim'); + $result = ($this->tabulator)($entry); + expect($result)->toBe('noChange'); + + $entry2 = Entry::factory()->create(['audition_id' => $entry->audition_id]); + $entry2->addFlag('passed_prelim'); + $result = ($this->tabulator)($entry); + expect($result)->toBe('noChange'); +}); + +it('doesnt make a decision if there are no judges assigned', function () { + $entry = Entry::factory()->create(); + PrelimDefinition::create([ + 'audition_id' => $entry->audition_id, + 'passing_score' => 80, + ]); + $result = ($this->tabulator)($entry); + expect($result)->toBe('noJudgesAssigned'); +}); + +it('doesnt make a decision if there are insufficient scores', function () { + $prelimRoom = Room::factory()->create(); + $judge1 = User::factory()->create(); + $judge2 = User::factory()->create(); + $prelimRoom->addJudge($judge1); + $prelimRoom->addJudge($judge2); + $prelimScoringGuide = ScoringGuide::factory()->create(); + $entry = Entry::factory()->create(); + PrelimDefinition::create([ + 'audition_id' => $entry->audition_id, + 'passing_score' => 80, + 'room_id' => $prelimRoom->id, + 'scoring_guide_id' => $prelimScoringGuide->id, + ]); + $result = ($this->tabulator)($entry); + expect($result)->toBe('missing2scores'); + app(EnterPrelimScore::class)($judge1, $entry, [ + 1 => 50, + 2 => 50, + 3 => 50, + 4 => 50, + 5 => 50, + ]); + $result = ($this->tabulator)($entry); + expect($result)->toBe('missing1scores'); +}); + +it('correctly identifies passing entries', function () { + $prelimRoom = Room::factory()->create(); + $judge1 = User::factory()->create(); + $judge2 = User::factory()->create(); + $prelimRoom->addJudge($judge1); + $prelimRoom->addJudge($judge2); + $prelimScoringGuide = ScoringGuide::factory()->create(); + $entry = Entry::factory()->create(); + PrelimDefinition::create([ + 'audition_id' => $entry->audition_id, + 'passing_score' => 80, + 'room_id' => $prelimRoom->id, + 'scoring_guide_id' => $prelimScoringGuide->id, + ]); + PrelimScoreSheet::create([ + 'entry_id' => $entry->id, + 'user_id' => $judge1->id, + 'subscores' => [], + 'total' => 85, + ]); + PrelimScoreSheet::create([ + 'entry_id' => $entry->id, + 'user_id' => $judge2->id, + 'subscores' => [], + 'total' => 75, + ]); + $result = ($this->tabulator)($entry); + expect($result)->toBe('markedPassed'); +}); + +it('correctly identifies failing entries', function () { + $prelimRoom = Room::factory()->create(); + $judge1 = User::factory()->create(); + $judge2 = User::factory()->create(); + $prelimRoom->addJudge($judge1); + $prelimRoom->addJudge($judge2); + $prelimScoringGuide = ScoringGuide::factory()->create(); + $entry = Entry::factory()->create(); + PrelimDefinition::create([ + 'audition_id' => $entry->audition_id, + 'passing_score' => 81, + 'room_id' => $prelimRoom->id, + 'scoring_guide_id' => $prelimScoringGuide->id, + ]); + PrelimScoreSheet::create([ + 'entry_id' => $entry->id, + 'user_id' => $judge1->id, + 'subscores' => [], + 'total' => 85, + ]); + PrelimScoreSheet::create([ + 'entry_id' => $entry->id, + 'user_id' => $judge2->id, + 'subscores' => [], + 'total' => 75, + ]); + $result = ($this->tabulator)($entry); + expect($result)->toBe('markedFailed'); +}); + +it('can force a recalculation', function () { + $prelimRoom = Room::factory()->create(); + $judge1 = User::factory()->create(); + $judge2 = User::factory()->create(); + $prelimRoom->addJudge($judge1); + $prelimRoom->addJudge($judge2); + $prelimScoringGuide = ScoringGuide::factory()->create(); + $entry = Entry::factory()->create(); + $entry->addFlag('failed_prelim'); + PrelimDefinition::create([ + 'audition_id' => $entry->audition_id, + 'passing_score' => 80, + 'room_id' => $prelimRoom->id, + 'scoring_guide_id' => $prelimScoringGuide->id, + ]); + PrelimScoreSheet::create([ + 'entry_id' => $entry->id, + 'user_id' => $judge1->id, + 'subscores' => [], + 'total' => 85, + ]); + PrelimScoreSheet::create([ + 'entry_id' => $entry->id, + 'user_id' => $judge2->id, + 'subscores' => [], + 'total' => 75, + ]); + $result = ($this->tabulator)($entry); + expect($result)->toBe('noChange'); + $result = ($this->tabulator)($entry, true); + expect($result)->toBe('markedPassed'); +}); diff --git a/tests/Feature/app/Actions/Tabulation/EnterPrelimScoreTest.php b/tests/Feature/app/Actions/Tabulation/EnterPrelimScoreTest.php new file mode 100644 index 0000000..bc4587d --- /dev/null +++ b/tests/Feature/app/Actions/Tabulation/EnterPrelimScoreTest.php @@ -0,0 +1,166 @@ +prelimScoringGuide = ScoringGuide::factory()->create(['id' => 1000]); + SubscoreDefinition::create([ + 'id' => 1001, + 'scoring_guide_id' => $this->prelimScoringGuide->id, + 'name' => 'Scale', + 'max_score' => 100, + 'weight' => 1, + 'display_order' => 1, + 'tiebreak_order' => 3, + 'for_seating' => '1', + 'for_advance' => '0', + ]); + SubscoreDefinition::create([ + 'id' => 1002, + 'scoring_guide_id' => $this->prelimScoringGuide->id, + 'name' => 'Etude 1', + 'max_score' => 100, + 'weight' => 2, + 'display_order' => 2, + 'tiebreak_order' => 1, + 'for_seating' => '1', + 'for_advance' => '1', + ]); + SubscoreDefinition::create([ + 'id' => 1003, + 'scoring_guide_id' => $this->prelimScoringGuide->id, + 'name' => 'Etude 2', + 'max_score' => 100, + 'weight' => 2, + 'display_order' => 3, + 'tiebreak_order' => 2, + 'for_seating' => '0', + 'for_advance' => '1', + ]); + SubscoreDefinition::where('id', '<', 900)->delete(); + $this->finalsRoom = Room::factory()->create(); + $this->prelimRoom = Room::factory()->create(); + $this->audition = Audition::factory()->create(['room_id' => $this->finalsRoom->id]); + $this->prelimDefinition = PrelimDefinition::create([ + 'room_id' => $this->prelimRoom->id, + 'audition_id' => $this->audition->id, + 'scoring_guide_id' => $this->prelimScoringGuide->id, + 'passing_score' => 60, + ]); + + $this->judge1 = User::factory()->create(); + $this->judge2 = User::factory()->create(); + $this->prelimRoom->judges()->attach($this->judge1->id); + $this->prelimRoom->judges()->attach($this->judge2->id); + $this->entry1 = Entry::factory()->create(['audition_id' => $this->audition->id]); + $this->entry2 = Entry::factory()->create(['audition_id' => $this->audition->id]); + $this->scribe = app(EnterPrelimScore::class); + $this->possibleScoreArray = [ + 1001 => 10, + 1002 => 11, + 1003 => 12, + ]; + $this->anotherPossibleScoreArray = [ + 1001 => 20, + 1002 => 21, + 1003 => 22, + ]; + +}); + +it('can enter a prelim score', function () { + ($this->scribe)($this->judge1, $this->entry1, $this->possibleScoreArray); + expect($this->entry1->prelimScoreSheets()->count())->toBe(1) + ->and($this->entry1->prelimScoreSheets()->first()->total)->toBe(11.2); + + ($this->scribe)($this->judge1, $this->entry2, $this->anotherPossibleScoreArray); + expect($this->entry2->prelimScoreSheets()->count())->toBe(1) + ->and($this->entry2->prelimScoreSheets()->first()->total)->toBe(21.2); +}); + +it('will not enter a score for a judge that does not exist', function () { + $fakeJudge = User::factory()->make(); + ($this->scribe)($fakeJudge, $this->entry1, $this->possibleScoreArray); +})->throws(AuditionAdminException::class, 'User does not exist'); + +it('will not enter a score for an entry that does not exist', function () { + $fakeEntry = Entry::factory()->make(); + ($this->scribe)($this->judge1, $fakeEntry, $this->possibleScoreArray); +})->throws(AuditionAdminException::class, 'Entry does not exist'); + +it('will not score an entry if the audition seats are published', function () { + $this->audition->addFlag('seats_published'); + ($this->scribe)($this->judge1, $this->entry1, $this->possibleScoreArray); +})->throws(AuditionAdminException::class, 'Cannot score an entry in an audition where seats are published'); + +it('will not score an entry if the judge is not assigned to judge the entry', function () { + $fakeJudge = User::factory()->create(); + ($this->scribe)($fakeJudge, $this->entry1, $this->possibleScoreArray); +})->throws(AuditionAdminException::class, 'This judge is not assigned to judge this entry'); + +it('can modify an existing score sheet', function () { + ($this->scribe)($this->judge1, $this->entry1, $this->possibleScoreArray); + $scoreSheet = PrelimScoreSheet::first(); + ($this->scribe)($this->judge1, $this->entry1, $this->anotherPossibleScoreArray, $scoreSheet); + expect($this->entry1->prelimScoreSheets()->count())->toBe(1) + ->and($this->entry1->prelimScoreSheets()->first()->total)->toBe(21.2); +}); + +it('will not change the judge on a score sheet', function () { + ($this->scribe)($this->judge1, $this->entry1, $this->possibleScoreArray); + $scoreSheet = PrelimScoreSheet::first(); + ($this->scribe)($this->judge2, $this->entry1, $this->anotherPossibleScoreArray, $scoreSheet); +})->throws(AuditionAdminException::class, 'Existing score sheet is from a different judge'); + +it('will not accept a second score sheet for a judge ane entry', function () { + ($this->scribe)($this->judge1, $this->entry1, $this->possibleScoreArray); + ($this->scribe)($this->judge1, $this->entry1, $this->anotherPossibleScoreArray); +})->throws(AuditionAdminException::class, 'That judge has already entered a prelim score for that entry'); + +it('will not change the entry on a score sheet', function () { + ($this->scribe)($this->judge1, $this->entry1, $this->possibleScoreArray); + $scoreSheet = PrelimScoreSheet::first(); + ($this->scribe)($this->judge1, $this->entry2, $this->anotherPossibleScoreArray, $scoreSheet); +})->throws(AuditionAdminException::class, 'Existing score sheet is for a different entry'); + +it('will not accept an incorrect number of subscores', function () { + array_pop($this->possibleScoreArray); + ($this->scribe)($this->judge1, $this->entry1, $this->possibleScoreArray); +})->throws(AuditionAdminException::class, 'Invalid number of scores'); + +it('will not accept an invalid subscores', function () { + array_pop($this->possibleScoreArray); + $this->possibleScoreArray[3001] = 100; + ($this->scribe)($this->judge1, $this->entry1, $this->possibleScoreArray); +})->throws(AuditionAdminException::class, 'Invalid Score Submission'); + +it('will. not accept a subscore in excess of its maximum', function () { + $this->possibleScoreArray[1001] = 1500; + ($this->scribe)($this->judge1, $this->entry1, $this->possibleScoreArray); +})->throws(AuditionAdminException::class, 'Supplied subscore exceeds maximum allowed'); + +it('removes a no-show flag from an entry', function () { + $this->entry1->addFlag('no_show'); + ($this->scribe)($this->judge1, $this->entry1, $this->possibleScoreArray); + expect($this->entry1->hasFlag('no_show'))->toBeFalse(); +}); + +it('logs score entry', function () { + ($this->scribe)($this->judge1, $this->entry1, $this->possibleScoreArray); + $logEntry = AuditLogEntry::orderBy('id', 'desc')->first(); + expect($logEntry->message)->toStartWith('Entered prelim score for entry id '); +}); diff --git a/tests/Feature/app/Http/Controllers/Admin/PrelimDefinitionControllerTest.php b/tests/Feature/app/Http/Controllers/Admin/PrelimDefinitionControllerTest.php new file mode 100644 index 0000000..4b56333 --- /dev/null +++ b/tests/Feature/app/Http/Controllers/Admin/PrelimDefinitionControllerTest.php @@ -0,0 +1,175 @@ +get(route('admin.prelim_definitions.index'))->assertRedirect(route('home')); + actAsNormal(); + $this->get(route('admin.prelim_definitions.index'))->assertRedirect(route('dashboard')); + actAsTab(); + $this->get(route('admin.prelim_definitions.index'))->assertRedirect(route('dashboard')); + actAsAdmin(); + $this->get(route('admin.prelim_definitions.index'))->assertViewIs('admin.prelim_definitions.index'); + }); + it('lists existing prelim definitions', function () { + $audition = Audition::factory()->create(); + $prelim = PrelimDefinition::create([ + 'audition_id' => $audition->id, + 'room_id' => 0, + 'scoring_guide_id' => 0, + 'passing_score' => 75, + ]); + actAsAdmin(); + $this->get(route('admin.prelim_definitions.index')) + ->assertViewIs('admin.prelim_definitions.index') + ->assertSee($audition->name); + }); +}); + +describe('PrelimDefinitionController::create', function () { + it('denies access to a non-admin user', function () { + $this->get(route('admin.prelim_definitions.create'))->assertRedirect(route('home')); + actAsNormal(); + $this->get(route('admin.prelim_definitions.create'))->assertRedirect(route('dashboard')); + actAsTab(); + $this->get(route('admin.prelim_definitions.create'))->assertRedirect(route('dashboard')); + actAsAdmin(); + $this->get(route('admin.prelim_definitions.create'))->assertViewIs('admin.prelim_definitions.createOrUpdate'); + }); +}); + +describe('PrelimDefinitionController::store', function () { + beforeEach(function () { + $this->audition = Audition::factory()->create(); + }); + it('denies access to a non-admin user', function () { + $this->post(route('admin.prelim_definitions.store'))->assertRedirect(route('home')); + actAsNormal(); + $this->post(route('admin.prelim_definitions.store'))->assertRedirect(route('dashboard')); + actAsTab(); + $this->post(route('admin.prelim_definitions.store'))->assertRedirect(route('dashboard')); + + }); + it('can store a new prelim audition', function () { + actAsAdmin(); + $response = $this->post(route('admin.prelim_definitions.store'), [ + 'audition_id' => $this->audition->id, + 'room_id' => 0, + 'scoring_guide_id' => 0, + 'passing_score' => 75, + ]); + + $response + ->assertRedirect(route('admin.prelim_definitions.index')) + ->assertSessionDoesntHaveErrors(); + }); + it('will not allow us to create two prelims for the same audition', function () { + actAsAdmin(); + PrelimDefinition::create([ + 'audition_id' => $this->audition->id, + 'room_id' => 0, + 'scoring_guide_id' => 0, + 'passing_score' => 75, + ]); + + $response = $this->from(route('admin.prelim_definitions.create')) + ->post(route('admin.prelim_definitions.store'), [ + 'audition_id' => $this->audition->id, + 'room_id' => 0, + 'scoring_guide_id' => 0, + 'passing_score' => 75, + ]); + $response->assertSessionHasErrors('audition_id') + ->assertRedirect(route('admin.prelim_definitions.create')); + }); +}); + +describe('PrelimDefinitionController::edit', function () { + beforeEach(function () { + $this->audition = Audition::factory()->create(); + $this->prelim = PrelimDefinition::create([ + 'audition_id' => $this->audition->id, + 'room_id' => 0, + 'scoring_guide_id' => 0, + 'passing_score' => 75, + ]); + }); + it('denies access to a non-admin user', function () { + $this->get(route('admin.prelim_definitions.edit', $this->prelim))->assertRedirect(route('home')); + actAsNormal(); + $this->get(route('admin.prelim_definitions.edit', $this->prelim))->assertRedirect(route('dashboard')); + actAsTab(); + $this->get(route('admin.prelim_definitions.edit', $this->prelim))->assertRedirect(route('dashboard')); + }); + it('shows a form to edit a prelim definition', function () { + actAsAdmin(); + $response = $this->get(route('admin.prelim_definitions.edit', $this->prelim)) + ->assertViewIs('admin.prelim_definitions.createOrUpdate') + ->assertSee($this->audition->name) + ->assertSee('PATCH') + ->assertSee(route('admin.prelim_definitions.update', $this->prelim)); + }); +}); + +describe('PrelimDefinitionController::update', function () { + beforeEach(function () { + $this->audition = Audition::factory()->create(); + $this->prelim = PrelimDefinition::create([ + 'audition_id' => $this->audition->id, + 'room_id' => 0, + 'scoring_guide_id' => 0, + 'passing_score' => 75, + ]); + }); + it('denies access to a non-admin user', function () { + $this->patch(route('admin.prelim_definitions.update', $this->prelim))->assertRedirect(route('home')); + actAsNormal(); + $this->patch(route('admin.prelim_definitions.update', $this->prelim))->assertRedirect(route('dashboard')); + actAsTab(); + $this->patch(route('admin.prelim_definitions.update', $this->prelim))->assertRedirect(route('dashboard')); + }); + it('can update a prelim definition', function () { + actAsAdmin(); + $response = $this->patch(route('admin.prelim_definitions.update', $this->prelim), [ + 'audition_id' => $this->audition->id, + 'room_id' => 0, + 'scoring_guide_id' => 0, + 'passing_score' => 90, + ]); + $response + ->assertRedirect(route('admin.prelim_definitions.index')); + expect($this->prelim->fresh()->passing_score)->toEqual(90); + }); +}); + +describe('PrelimDefinitionController::destroy', function () { + beforeEach(function () { + $this->audition = Audition::factory()->create(); + $this->prelim = PrelimDefinition::create([ + 'audition_id' => $this->audition->id, + 'room_id' => 0, + 'scoring_guide_id' => 0, + 'passing_score' => 75, + ]); + }); + it('denies access to a non-admin user', function () { + $this->delete(route('admin.prelim_definitions.destroy', $this->prelim))->assertRedirect(route('home')); + actAsNormal(); + $this->delete(route('admin.prelim_definitions.destroy', $this->prelim))->assertRedirect(route('dashboard')); + actAsTab(); + $this->delete(route('admin.prelim_definitions.destroy', $this->prelim))->assertRedirect(route('dashboard')); + }); + + it('deletes a prelim definition', function () { + actAsAdmin(); + $response = $this->delete(route('admin.prelim_definitions.destroy', $this->prelim)); + $response + ->assertRedirect(route('admin.prelim_definitions.index')); + expect(PrelimDefinition::count())->toEqual(0); + }); +}); diff --git a/tests/Feature/app/Http/Controllers/Judging/JudgingControllerTest.php b/tests/Feature/app/Http/Controllers/Judging/JudgingControllerTest.php index 38a855d..65f03f0 100644 --- a/tests/Feature/app/Http/Controllers/Judging/JudgingControllerTest.php +++ b/tests/Feature/app/Http/Controllers/Judging/JudgingControllerTest.php @@ -4,6 +4,7 @@ use App\Models\Audition; use App\Models\BonusScoreDefinition; use App\Models\Entry; use App\Models\JudgeAdvancementVote; +use App\Models\PrelimDefinition; use App\Models\Room; use App\Models\ScoreSheet; use App\Models\ScoringGuide; @@ -31,6 +32,21 @@ describe('JudgingController::index', function () { $response->assertSee($room->name); $response->assertSee($bonusScoreDefinition->name); }); + it('shows prelim auditions the user is assigned to judge', function () { + $judge = User::factory()->create(); + $room = Room::factory()->create(); + $room->judges()->attach($judge); + $audition = Audition::factory()->create(); + $prelimAudition = PrelimDefinition::create([ + 'audition_id' => $audition->id, + 'room_id' => $room->id, + 'passing_score' => 75, + ]); + $response = $this->actingAs($judge)->get(route('judging.index')); + $response->assertOk(); + $response->assertSee($room->name); + $response->assertSee($audition->name.' Prelims'); + }); }); describe('JudgingController::auditionEntryList', function () { diff --git a/tests/Feature/app/Http/Controllers/Judging/PrelimJudgingControllerTest.php b/tests/Feature/app/Http/Controllers/Judging/PrelimJudgingControllerTest.php new file mode 100644 index 0000000..7388f9b --- /dev/null +++ b/tests/Feature/app/Http/Controllers/Judging/PrelimJudgingControllerTest.php @@ -0,0 +1,196 @@ +create(); + $notJudgeUser = User::factory()->create(); + $finalsRoom = Room::factory()->create(); + $audition = Audition::factory()->create(['room_id' => $finalsRoom->id]); + $room = Room::factory()->create(); + $finalsRoom = Room::factory()->create(); + $prelimDefinition = PrelimDefinition::create([ + 'audition_id' => $audition->id, + 'room_id' => $room->id, + 'scoring_guide_id' => 0, + 'passing_score' => 75, + ]); + $room->addJudge($judgeUser); + $finalsRoom->addJudge($notJudgeUser); + + $this->actingAs($notJudgeUser); + $this->get(route('judging.prelimEntryList', $prelimDefinition)) + ->assertRedirect(route('dashboard')) + ->assertSessionHas('error', 'You are not assigned to judge that prelim audition.'); + $this->actingAs($judgeUser); + $this->get(route('judging.prelimEntryList', $prelimDefinition)) + ->assertOk(); + + }); + + it('shows all auditions entered in the given audition', function () { + $judgeUser = User::factory()->create(); + $finalsRoom = Room::factory()->create(); + $audition = Audition::factory()->create(['room_id' => $finalsRoom->id, 'name' => 'Euphonium']); + $room = Room::factory()->create(); + $prelimDefinition = PrelimDefinition::create([ + 'audition_id' => $audition->id, + 'room_id' => $room->id, + 'scoring_guide_id' => 0, + 'passing_score' => 75, + ]); + $room->addJudge($judgeUser); + + $entries = Entry::factory()->count(5)->create(['audition_id' => $audition->id]); + app(RunDraw::class)($audition); + + $this->actingAs($judgeUser); + $response = $this->get(route('judging.prelimEntryList', $prelimDefinition)); + $response->assertOk(); + foreach ($entries as $entry) { + + $entry->refresh(); + $identifierString = $entry->audition->name.' '.$entry->draw_number; + $response->assertSee($identifierString); + } + }); + + it('shows scores for previously judged entries', function () { + + }); + + it('has links to enter scores for each entry', function () { + + }); + + it('does not allow modifications to an entry that has finals scores', function () { + + }); +}); + +describe('PrelimJudgingController:prelimScoreEntryForm', function () { + beforeEach(function () { + $this->room = Room::factory()->create(); + $this->finalsRoom = Room::factory()->create(); + $this->scoringGuide = ScoringGuide::factory()->create(); + $this->audition = Audition::factory()->create(['room_id' => $this->finalsRoom->id]); + $this->prelimDefinition = PrelimDefinition::create([ + 'audition_id' => $this->audition->id, + 'room_id' => $this->room->id, + 'scoring_guide_id' => $this->scoringGuide->id, + 'passing_score' => 75, + ]); + $this->prelimJudge = User::factory()->create(['judging_preference' => 'Prelims']); + $this->finalsJudge = User::factory()->create(['judging_preference' => 'Finals']); + $this->room->addJudge($this->prelimJudge); + $this->finalsRoom->addJudge($this->finalsJudge); + $this->entry = Entry::factory()->create(['audition_id' => $this->audition->id]); + + }); + it('denies access to non-judges', function () { + actAsNormal(); + $entry = Entry::factory()->create(); + $response = $this->get(route('judging.prelimScoreEntryForm', $this->entry)); + $response->assertRedirect(route('dashboard')); + $response->assertSessionHas('error', 'You are not assigned to judge.'); + }); + + it('denies access if the judge is not assigned to the room', function () { + $this->actingAs($this->finalsJudge); + $response = $this->get(route('judging.prelimScoreEntryForm', $this->entry)); + $response->assertRedirect(route('dashboard')); + $response->assertSessionHas('error', 'You are not assigned to judge that prelim audition.'); + }); + + it('denies access if the audition is published', function () { + $this->actingAs($this->prelimJudge); + $this->entry->audition->addFlag('seats_published'); + $response = $this->get(route('judging.prelimScoreEntryForm', $this->entry)); + $response->assertRedirect(route('dashboard')); + $response->assertSessionHas('error', 'Scores for entries in published auditions cannot be modified.'); + }); + + it('denies access if the entry is flagged as a no-show', function () { + $this->entry->addFlag('no_show'); + $this->actingAs($this->prelimJudge); + $response = $this->get(route('judging.prelimScoreEntryForm', $this->entry)); + $response->assertRedirect(route('judging.prelimEntryList', $this->prelimDefinition)); + $response->assertSessionHas('error', 'The requested entry is marked as a no-show. Scores cannot be entered.'); + }); + + it('gives us a form to enter a score for an entry', function () { + $this->actingAs($this->prelimJudge); + $response = $this->get(route('judging.prelimScoreEntryForm', $this->entry)); + $response->assertOk(); + $response->assertDontSee($this->entry->student->last_name) + ->assertDontSee($this->entry->student->first_name); + foreach (SubscoreDefinition::all() as $subscore) { + $response->assertSee($subscore->name); + $response->assertSee('score['.$subscore->id.']'); + } + }); +}); + +describe('PrelimJudgingController:savePrelimEntryForm', function () { + beforeEach(function () { + $this->room = Room::factory()->create(); + $this->finalsRoom = Room::factory()->create(); + $this->scoringGuide = ScoringGuide::factory()->create(); + $this->audition = Audition::factory()->create(['room_id' => $this->finalsRoom->id]); + $this->prelimDefinition = PrelimDefinition::create([ + 'audition_id' => $this->audition->id, + 'room_id' => $this->room->id, + 'scoring_guide_id' => $this->scoringGuide->id, + 'passing_score' => 75, + ]); + $this->prelimJudge = User::factory()->create(['judging_preference' => 'Prelims']); + $this->finalsJudge = User::factory()->create(['judging_preference' => 'Finals']); + $this->room->addJudge($this->prelimJudge); + $this->finalsRoom->addJudge($this->finalsJudge); + $this->entry = Entry::factory()->create(['audition_id' => $this->audition->id]); + + }); + it('denies access to non-judges', function () { + actAsNormal(); + $response = $this->post(route('judging.savePrelimScoreSheet', $this->entry)); + $response->assertRedirect(route('dashboard')); + $response->assertSessionHas('error', 'You are not assigned to judge.'); + }); + + it('denies access if the judge is not assigned to the room', function () { + $this->actingAs($this->finalsJudge); + $response = $this->post(route('judging.savePrelimScoreSheet', $this->entry)); + $response->assertRedirect(route('dashboard')); + $response->assertSessionHas('error', 'You are not assigned to judge that prelim audition.'); + }); + + it('saves a score sheet', function () { + $subscoreIds = SubscoreDefinition::all()->pluck('id')->toArray(); + $submitData = [ + 'score' => [ + $subscoreIds[0] => 10, + $subscoreIds[1] => 20, + $subscoreIds[2] => 30, + $subscoreIds[3] => 40, + $subscoreIds[4] => 50, + ], + ]; + $this->actingAs($this->prelimJudge); + $response = $this->post(route('judging.savePrelimScoreSheet', $this->entry), $submitData); + $response->assertRedirect(route('judging.prelimEntryList', $this->prelimDefinition)); + $response->assertSessionHas('success'); + expect(PrelimScoreSheet::where('entry_id', $this->entry->id)->count())->toBe(1); + }); +}); diff --git a/tests/Feature/app/Models/AuditionTest.php b/tests/Feature/app/Models/AuditionTest.php index 786dc1b..9c7346c 100644 --- a/tests/Feature/app/Models/AuditionTest.php +++ b/tests/Feature/app/Models/AuditionTest.php @@ -3,6 +3,7 @@ use App\Models\Audition; use App\Models\Ensemble; use App\Models\Entry; +use App\Models\PrelimDefinition; use App\Models\Room; use App\Models\ScoringGuide; use App\Models\Seat; @@ -198,3 +199,16 @@ it('can return its seats if any exits', function () { expect($this->audition->seats()->count())->toBe(5) ->and($this->audition->seats->first())->toBeInstanceOf(Seat::class); }); + +it('returns null if a prelim definition is requested and none exists', function () { + expect($this->audition->prelimDefinition)->toBeNull(); +}); + +it('can return its prelim definition if one exists', function () { + + $prelimDefinition = PrelimDefinition::create([ + 'audition_id' => $this->audition->id, + 'passing_score' => 72, + ]); + expect($this->audition->prelimDefinition->passing_score)->toEqual(72); +}); diff --git a/tests/Feature/app/Models/PrelimDefinitionTest.php b/tests/Feature/app/Models/PrelimDefinitionTest.php new file mode 100644 index 0000000..27c10cf --- /dev/null +++ b/tests/Feature/app/Models/PrelimDefinitionTest.php @@ -0,0 +1,41 @@ +audition = Audition::factory()->create(); + $this->prelim = PrelimDefinition::create([ + 'audition_id' => $this->audition->id, + 'passing_score' => 80, + ]); +}); + +it('can provide its audition', function () { + expect($this->prelim->audition->name)->toEqual($this->audition->name); +}); + +it('can return its room if one is set', function () { + $room = Room::factory()->create(); + $this->prelim->room()->associate($room); + expect($this->prelim->room->name)->toEqual($room->name); +}); + +it('returns null if no room is set', function () { + expect($this->prelim->room)->toBeNull(); +}); + +it('returns its scoring guide if one is set', function () { + $guide = ScoringGuide::factory()->create(); + $this->prelim->scoringGuide()->associate($guide); + expect($this->prelim->scoringGuide->name)->toEqual($guide->name); +}); + +it('returns null if no scoring guide is set', function () { + expect($this->prelim->scoringGuide)->toBeNull(); +});