Merge branch 'refs/heads/pass_fail_prelims'

This commit is contained in:
Matt Young 2025-10-20 22:33:34 -05:00
commit 0ca239d297
54 changed files with 2258 additions and 112 deletions

View File

@ -0,0 +1,61 @@
<?php
namespace App\Actions\Tabulation;
use App\Exceptions\AuditionAdminException;
use App\Models\Entry;
class CheckPrelimResult
{
public function __construct()
{
}
/**
* @throws AuditionAdminException
*/
public function __invoke(Entry $entry, bool $recalc = false): string
{
if ($recalc) {
$entry->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';
}
}
}

View File

@ -0,0 +1,137 @@
<?php
namespace App\Actions\Tabulation;
use App\Exceptions\AuditionAdminException;
use App\Models\Entry;
use App\Models\PrelimDefinition;
use App\Models\PrelimScoreSheet;
use App\Models\User;
use DB;
use function auditionLog;
class EnterPrelimScore
{
public function __invoke(
User $user,
Entry $entry,
array $scores,
PrelimScoreSheet|false $prelimScoreSheet = false
): PrelimScoreSheet {
$scores = collect($scores);
// Basic Validity Checks
if (! User::where('id', $user->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.'.<br />';
$log_message .= 'Judge: '.$user->full_name().'<br />';
foreach ($prelimScoreSheet->subscores as $subscore) {
$log_message .= $subscore['subscore_name'].': '.$subscore['score'].'<br />';
}
$log_message .= 'Total :'.$prelimScoreSheet->total.'<br />';
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;
}
}

View File

@ -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!');
}
}

View File

@ -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';
}

View File

@ -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)

View File

@ -0,0 +1,70 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\PrelimDefinitionStoreOrUpdateRequest;
use App\Models\Audition;
use App\Models\PrelimDefinition;
use App\Models\Room;
use App\Models\ScoringGuide;
use function view;
class PrelimDefinitionController extends Controller
{
public function index()
{
$prelims = PrelimDefinition::all();
return view('admin.prelim_definitions.index', compact('prelims'));
}
public function create()
{
$auditions = Audition::doesntHave('prelimDefinition')->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');
}
}

View File

@ -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,

View File

@ -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)

View File

@ -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,

View File

@ -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)

View File

@ -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()

View File

@ -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();

View File

@ -0,0 +1,103 @@
<?php
namespace App\Http\Controllers\Judging;
use App\Actions\Tabulation\EnterPrelimScore;
use App\Exceptions\AuditionAdminException;
use App\Http\Controllers\Controller;
use App\Models\Entry;
use App\Models\PrelimDefinition;
use App\Models\PrelimScoreSheet;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class PrelimJudgingController extends Controller
{
public function prelimEntryList(PrelimDefinition $prelimDefinition)
{
if (auth()->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);
}
}

View File

@ -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.index', compact('audition', 'auditions', 'entries'));
}
return view('monitor_entry_flag_form', compact('entry'));
}
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');
}
}

View File

@ -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

View File

@ -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'))

View File

@ -0,0 +1,28 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class PrelimDefinitionStoreOrUpdateRequest extends FormRequest
{
public function rules(): array
{
return [
'audition_id' => [
'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;
}
}

View File

@ -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
*/

View File

@ -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]);

View File

@ -0,0 +1,32 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class PrelimDefinition extends Model
{
protected $fillable = [
'audition_id',
'room_id',
'order_in_room',
'scoring_guide_id',
'passing_score',
];
public function audition(): BelongsTo
{
return $this->belongsTo(Audition::class);
}
public function room(): BelongsTo
{
return $this->belongsTo(Room::class);
}
public function scoringGuide(): BelongsTo
{
return $this->belongsTo(ScoringGuide::class);
}
}

View File

@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne;
class PrelimScoreSheet extends Model
{
protected $fillable = [
'user_id',
'entry_id',
'subscores',
'total',
];
protected $casts = ['subscores' => '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
}
}

View File

@ -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(

View File

@ -0,0 +1,51 @@
<?php
namespace App\Observers;
use App\Models\PrelimDefinition;
use App\Models\Room;
use App\Models\ScoringGuide;
class PrelimDefinitionObserver
{
/**
* Handle the PrelimDefinition "created" event.
*/
public function created(PrelimDefinition $prelimDefinition): void
{
$message = 'Created Prelim for '.$prelimDefinition->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 .= '<br>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 .= '<br>Scoring Guide: '.$oldScoringGuide->name.' -> '.$prelimDefinition->scoringGuide->name;
}
if ($prelimDefinition->getOriginal('passing_score') !== $prelimDefinition->passing_score) {
$message .= '<br>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]]);
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace App\Policies;
use App\Models\PrelimDefinition;
use App\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
class PrelimDefinitionPolicy
{
use HandlesAuthorization;
public function viewAny(User $user): bool
{
return $user->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
{
}
}

View File

@ -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);

View File

@ -0,0 +1,29 @@
<?php
use App\Models\Audition;
use App\Models\Room;
use App\Models\ScoringGuide;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('prelim_definitions', function (Blueprint $table) {
$table->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');
}
};

View File

@ -0,0 +1,34 @@
<?php
use App\Models\Entry;
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('prelim_score_sheets', function (Blueprint $table) {
$table->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');
}
};

View File

@ -127,4 +127,29 @@
</x-card.list.body>
</x-card.card>
<x-card.card class="mt-5">
<x-card.heading>Log Entries</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th>Timestamp</x-table.th>
<x-table.th>IP</x-table.th>
<x-table.th>User</x-table.th>
<x-table.th>Message</x-table.th>
</tr>
</thead>
<x-table.body>
@foreach($logEntries as $logEntry)
<tr>
<x-table.td>{{ $logEntry->created_at }}</x-table.td>
<x-table.td>{{ $logEntry->ip_address }}</x-table.td>
<x-table.td>{{ $logEntry->user }}</x-table.td>
<x-table.td>{!! $logEntry->message !!}</x-table.td>
</tr>
@endforeach
</x-table.body>
</x-table.table>
</x-card.card>
</x-layout.app>

View File

@ -0,0 +1,66 @@
<x-layout.app>
<x-slot:page_title>Manage Prelim Auditions</x-slot:page_title>
<div class="max-w-lg mx-auto">
<x-card.card class="pb-5">
<x-card.heading>
@if($prelim)
Modify Prelim - {{ $prelim->audition->name }}
<x-slot:right_side>
<x-delete-resource-modal title="Delete {{ $prelim->audition->name }} Prelim" action="{{ route('admin.prelim_definitions.destroy', $prelim->id)}}">
Confirm that you'd like to delete prelim auditions for {{ $prelim->audition->name }}.
{{-- TODO: Block deleting a prelim audition if there are prelim scores --}}
</x-delete-resource-modal>
</x-slot:right_side>
@else
Create Prelim Audition
@endif
</x-card.heading>
<x-form.form method="{{ $method }}" action="{{ $action }}"
x-data="{ canSubmit: {{ ! $prelim ? 'false':'true' }} }">
<x-form.select name="audition_id" @change="canSubmit = true">
<x-slot:label>Audition</x-slot:label>
@if($prelim)
<option value="{{ $prelim->audition_id }}">{{ $prelim->audition->name }}</option>
@else
<option value="" :disabled="canSubmit">Choose Audition</option>
@foreach($auditions as $audition)
<option value="{{ $audition->id }}">{{ $audition->name }}</option>
@endforeach
@endif
</x-form.select>
@error('audition_id')
<div class="text-red-500 text-sm">{{ $message }}</div>
@enderror
<x-form.select name="room_id">
<x-slot:label>Room</x-slot:label>
@foreach($rooms as $room)
<option value="{{ $room->id }}" @if($prelim && $prelim->room_id == $room->id) SELECTED @endif>{{ $room->name }} - {{ $room->description }}</option>
@endforeach
</x-form.select>
@error('room_id')
<div class="text-red-500 text-sm">{{ $message }}</div>
@enderror
<x-form.select name="scoring_guide_id">
<x-slot:label>Scoring Guide</x-slot:label>
@foreach($guides as $guide)
<option value="{{ $guide->id }}" @if($prelim && $prelim->scoring_guide_id == $guide->id) SELECTED @endif>{{ $guide->name }}</option>
@endforeach
</x-form.select>
@error('scoring_guide_id')
<div class="text-red-500 text-sm">{{ $message }}</div>
@enderror
<x-form.field name="passing_score" type="number" max="100" min="0" step="0.1" :value=" $prelim ? $prelim->passing_score : 60"
label_text="Passing Score"/>
<x-form.footer submit-button-text="{{ ! $prelim ? 'Create Prelim Audition':'Modify Prelim Audition' }}" x-show="canSubmit" x-cloak></x-form.footer>
</x-form.form>
</x-card.card>
</div>
</x-layout.app>

View File

@ -0,0 +1,33 @@
<x-layout.app>
<x-slot:page_title>Prelim Audition Setup</x-slot:page_title>
<x-card.card>
<x-card.heading>
Preliminary Auditions
<x-slot:subheading>Click to edit or delete</x-slot:subheading>
<x-slot:right_side>
<x-form.button href="{{ route('admin.prelim_definitions.create') }}">Add Prelim</x-form.button>
</x-slot:right_side>
</x-card.heading>
<x-table.table class="mt-3 mb-3">
<thead>
<tr>
<x-table.th>Audition</x-table.th>
<x-table.th>Passing Score</x-table.th>
<x-table.th>Room</x-table.th>
<x-table.th>Scoring Guide</x-table.th>
</tr>
</thead>
<x-table.body>
@foreach ($prelims as $prelim)
<tr onclick="window.location='{{ route('admin.prelim_definitions.edit', $prelim) }}';"
style="cursor:pointer;">
<x-table.td>{{ $prelim->audition->name }}</x-table.td>
<x-table.td>{{ $prelim->passing_score }}</x-table.td>
<x-table.td>{{ $prelim->room->name }}</x-table.td>
<x-table.td>{{ $prelim->scoringGuide->name }}</x-table.td>
</tr>
@endforeach
</x-table.body>
</x-table.table>
</x-card.card>
</x-layout.app>

View File

@ -62,4 +62,30 @@
</div>
</div>
</div>
<x-card.card class="mt-5">
<x-card.heading>Log Entries</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th>Timestamp</x-table.th>
<x-table.th>IP</x-table.th>
<x-table.th>User</x-table.th>
<x-table.th>Message</x-table.th>
</tr>
</thead>
<x-table.body>
@foreach($logEntries as $logEntry)
<tr>
<x-table.td>{{ $logEntry->created_at }}</x-table.td>
<x-table.td>{{ $logEntry->ip_address }}</x-table.td>
<x-table.td>{{ $logEntry->user }}</x-table.td>
<x-table.td>{!! $logEntry->message !!}</x-table.td>
</tr>
@endforeach
</x-table.body>
</x-table.table>
</x-card.card>
</x-layout.app>

View File

@ -80,4 +80,29 @@
</x-table.table>
</x-card.card>
@endforeach
<x-card.card class="mt-5">
<x-card.heading>Log Entries</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th>Timestamp</x-table.th>
<x-table.th>IP</x-table.th>
<x-table.th>User</x-table.th>
<x-table.th>Message</x-table.th>
</tr>
</thead>
<x-table.body>
@foreach($logEntries as $logEntry)
<tr>
<x-table.td>{{ $logEntry->created_at }}</x-table.td>
<x-table.td>{{ $logEntry->ip_address }}</x-table.td>
<x-table.td>{{ $logEntry->user }}</x-table.td>
<x-table.td>{!! $logEntry->message !!}</x-table.td>
</tr>
@endforeach
</x-table.body>
</x-table.table>
</x-card.card>
</x-layout.app>

View File

@ -53,4 +53,54 @@
</x-form.footer>
</x-form.form>
</x-card.card>
<x-card.card class="mt-5">
<x-card.heading>User Actions</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th>Timestamp</x-table.th>
<x-table.th>IP</x-table.th>
<x-table.th>User</x-table.th>
<x-table.th>Message</x-table.th>
</tr>
</thead>
<x-table.body>
@foreach($userActions as $logEntry)
<tr>
<x-table.td>{{ $logEntry->created_at }}</x-table.td>
<x-table.td>{{ $logEntry->ip_address }}</x-table.td>
<x-table.td>{{ $logEntry->user }}</x-table.td>
<x-table.td>{!! $logEntry->message !!}</x-table.td>
</tr>
@endforeach
</x-table.body>
</x-table.table>
</x-card.card>
<x-card.card class="mt-5">
<x-card.heading>Log Entries Affecting User</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th>Timestamp</x-table.th>
<x-table.th>IP</x-table.th>
<x-table.th>User</x-table.th>
<x-table.th>Message</x-table.th>
</tr>
</thead>
<x-table.body>
@foreach($logEntries as $logEntry)
<tr>
<x-table.td>{{ $logEntry->created_at }}</x-table.td>
<x-table.td>{{ $logEntry->ip_address }}</x-table.td>
<x-table.td>{{ $logEntry->user }}</x-table.td>
<x-table.td>{!! $logEntry->message !!}</x-table.td>
</tr>
@endforeach
</x-table.body>
</x-table.table>
</x-card.card>
</x-layout.app>

View File

@ -0,0 +1,3 @@
<div>
</div>

View File

@ -23,6 +23,7 @@
<x-layout.navbar.menus.menu-item :href="route('audition-settings')">Audition Settings</x-layout.navbar.menus.menu-item>
<x-layout.navbar.menus.menu-item :href="route('admin.events.index')">Events</x-layout.navbar.menus.menu-item>
<x-layout.navbar.menus.menu-item :href="route('admin.auditions.index')">Auditions</x-layout.navbar.menus.menu-item>
<x-layout.navbar.menus.menu-item :href="route('admin.prelim_definitions.index')">Prelim Auditions</x-layout.navbar.menus.menu-item>
<x-layout.navbar.menus.menu-item :href="route('admin.ensembles.index')">Ensembles</x-layout.navbar.menus.menu-item>
<x-layout.navbar.menus.menu-item :href="route('admin.ensembles.seatingLimits')">Seating Limits</x-layout.navbar.menus.menu-item>
<x-layout.navbar.menus.menu-item :href="route('admin.scoring.index')">Scoring</x-layout.navbar.menus.menu-item>

View File

@ -13,6 +13,11 @@
<x-card.list.row class="!py-3 ml-3">{{ $audition->name }}</x-card.list.row>
</a>
@endforeach
@foreach($room->prelimAuditions as $prelimAudition)
<a href="{{ route('judging.prelimEntryList', $prelimAudition) }}">
<x-card.list.row class="!py-3 ml-3">{{ $prelimAudition->audition->name }} Prelims</x-card.list.row>
</a>
@endforeach
</x-card.list.body>
</x-card.card>
@endforeach

View File

@ -0,0 +1,58 @@
<x-layout.app>
@php
$oldScores = session()->get('oldScores') ?? null;
@endphp
<x-slot:page_title>Prelim Score Entry</x-slot:page_title>
<x-card.card class="mx-auto max-w-md">
<x-card.heading>
{{ $entry->audition->name }} {{ $entry->draw_number }}
<x-slot:subheading>
<ul class="mt-.5 max-w-2xl text-sm leading-6 text-gray-500">
<li>All Scores must be complete</li>
<li>You may enter zero</li>
<li>Whole numbers only</li>
</ul>
</x-slot:subheading>
</x-card.heading>
<x-form.form method="POST" action="{{ route('judging.savePrelimScoreSheet', $entry) }}">
@if($oldSheet)
{{-- if there are existing scores, make this a patch request --}}
@method('PATCH')
@endif
<x-card.list.body class="mt-1">
@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
<li class="py-2">
<x-form.field
name="score[{{$subscore->id}}]"
type="number"
placeholder="{{$subscore->name}}"
:value="$value"
max="{{ $subscore->max_score }}"
required
>
<x-slot:label>{{ $subscore->name }} <span class="text-xs text-base text-gray-400 pl-3">max: {{$subscore->max_score}}</span></x-slot:label>
</x-form.field>
</li>
@endforeach
</x-card.list.body>
<x-form.footer>
<x-form.button class="mb-5">Save Scores</x-form.button>
</x-form.footer>
</x-form.form>
</x-card.card>
</x-layout.app>

View File

@ -0,0 +1,58 @@
@php use Illuminate\Support\Facades\Auth; @endphp
<x-layout.app>
<x-slot:page_title>Judging Dashboard</x-slot:page_title>
<x-card.card>
<x-card.heading>
{{ $prelimDefinition->audition->name }} Prelims
@if($published)
<x-slot:subheading class="text-red-500">Results are published. Scores cannot be changed.
</x-slot:subheading>
@endif
</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th :sortable="false"><a href="{{ url()->current() }}">Entry</a></x-table.th>
@foreach($subscores as $subscore)
<x-table.th :sortable="false" class="hidden md:table-cell">{{ $subscore->name }}</x-table.th>
@endforeach
<x-table.th :sortable="true">Timestamp</x-table.th>
</tr>
</thead>
<x-table.body>
@foreach($entries as $entry)
{{-- @continue($entry->hasFlag('no_show'))--}}
<tr>
<x-table.td>
@if(! $published && ! $entry->hasFlag('no_show') && $entry->scoreSheets()->count() < 1)
<a href="{{ route('judging.prelimScoreEntryForm', $entry) }}">
@endif
{{ $prelimDefinition->audition->name }} {{ $entry->draw_number }}
@if($entry->hasFlag('no_show'))
<p class="text-red-600">No Show</p>
@endif
@if($entry->scoreSheets()->count() > 0)
<p class="text-green-600">Has Finals Scores</p>
@endif
@if(! $published && ! $entry->hasFlag('no_show') && $entry->scoreSheets()->count() < 1)
</a>
@endif
</x-table.td>
@foreach($subscores as $subscore)
<x-table.td class="hidden md:table-cell">
@if($prelimScoresheets->has($entry->id))
{{ $prelimScoresheets[$entry->id]->subscores[$subscore->id]['score'] }}
@endif
</x-table.td>
@endforeach
<x-table.td>
@if($prelimScoresheets->has($entry->id))
{{ $prelimScoresheets[$entry->id]->created_at->setTimezone('America/Chicago')->format('m/d/y H:i') }}
@endif
</x-table.td>
</tr>
@endforeach
</x-table.body>
</x-table.table>
</x-card.card>
</x-layout.app>

View File

@ -0,0 +1,76 @@
<x-layout.app>
<x-slot:page_title>Monitor Dashboard</x-slot:page_title>
<x-card.card class="max-w-lg mx-auto mb-5">
<x-card.heading>
Audition Status
<x-slot:right_side>
<x-form.select name="audition_id" onchange="if (this.value) window.location.href = this.value">
<option value="" disabled hidden @if(! $audition) selected @endif>Choose Audition...</option>
@foreach ($auditions as $menuAudition)
@continue($menuAudition->hasFlag('seats_published') || $menuAudition->hasFlag('advance_published'))
<option @if($audition && $audition->id === $menuAudition->id) selected @endif
value="{{ route('monitor.auditionStatus', $menuAudition) }}">{{$menuAudition->name}}</option>
@endforeach
</x-form.select>
</x-slot:right_side>
</x-card.heading>
@if($audition)
<x-table.table>
<thead>
<tr>
<x-table.th>Entry</x-table.th>
@if($audition->prelimDefinition)
<x-table.th>Prelim<br/>Scores</x-table.th>
@endif
<x-table.th>Finals<br/>Scores</x-table.th>
<x-table.th></x-table.th>
</tr>
</thead>
<x-table.body>
@foreach($entries as $entry)
<tr>
<x-table.td>
{{ $audition->name }} {{ $entry->draw_number }}<br class="md:hidden">
@if($audition->prelimDefinition && ! $entry->hasFlag('no_show'))
@if($entry->hasFlag('failed_prelim'))
<span
class="inline-flex items-center rounded-md bg-red-100 px-2 py-1 text-sm font-medium text-red-700 ">Failed</span>
@elseif($entry->hasFlag('passed_prelim'))
<span
class="inline-flex items-center rounded-md bg-green-100 px-2 py-1 text-sm font-medium text-green-700">Passed</span>
@else
<span
class="inline-flex items-center rounded-md bg-yellow-100 px-2 py-1 text-sm font-medium text-yellow-800 ">Pending</span>
@endif
@elseif($entry->hasFlag('no_show'))
<span
class="inline-flex items-center rounded-md bg-red-100 px-2 py-1 text-sm font-medium text-red-700 ">No-Show</span>
@endif
</x-table.td>
@if($audition->prelimDefinition)
<x-table.td>
{{ $entry->prelim_score_sheets_count }}
</x-table.td>
@endif
<x-table.td>
{{ $entry->score_sheets_count }}
</x-table.td>
<x-table.td>
@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
</x-table.td>
</tr>
@endforeach
</x-table.body>
</x-table.table>
@endif
</x-card.card>
</x-layout.app>

View File

@ -0,0 +1,19 @@
<x-modal>
<x-slot:button_text>
<x-form.button href="#">Mark No-Show</x-form.button>
</x-slot:button_text>
<x-slot:title>Mark {{ $audition->name }} {{ $entry->draw_number }}
as a no-show
</x-slot:title>
Confirm that you would like to mark this entry as a no-show<br>
{{ $audition->name }} {{ $entry->draw_number }}<br>
Entry ID: {{ $entry->id }}<br>
Name: {{ $entry->student->full_name() }}<br>
School: {{ $entry->student->school->name }}
<hr class="mt-3">
<x-form.form method="POST" action="{{ route('monitor.toggleNoShow', $entry) }}">
<x-form.button class="mt-3" type="submit">Confirm
No-Show<br>{{ $audition->name }} {{ $entry->draw_number }}
</x-form.button>
</x-form.form>
</x-modal>

View File

@ -0,0 +1,18 @@
<x-modal>
<x-slot:button_text>
<x-form.button href="#">Undo No-Show</x-form.button>
</x-slot:button_text>
<x-slot:title>Remove No-Show Flag for {{ $audition->name }} {{ $entry->draw_number }}
</x-slot:title>
Confirm that you would like to remove the no-show flag for this entry<br>
{{ $audition->name }} {{ $entry->draw_number }}<br>
Entry ID: {{ $entry->id }}<br>
Name: {{ $entry->student->full_name() }}<br>
School: {{ $entry->student->school->name }}
<hr class="mt-3">
<x-form.form method="POST" action="{{ route('monitor.toggleNoShow', $entry) }}">
<x-form.button class="mt-3" type="submit">Remove
No-Show Flag<br>{{ $audition->name }} {{ $entry->draw_number }}
</x-form.button>
</x-form.form>
</x-modal>

View File

@ -3,7 +3,17 @@
<x-slot:page_title>Entry Score Sheet</x-slot:page_title>
<x-card.card class="mx-auto max-w-7xl">
<x-card.heading>
{{ $entry->audition->name }} #{{ $entry->draw_number }}
{{ $entry->audition->name }} #{{ $entry->draw_number }} FINALS SCORES
@if($entry->hasFlag('failed_prelim'))
<span
class="inline-flex items-center rounded-md bg-red-100 px-2 py-1 text-sm font-medium text-red-700 ">Failed Prelim</span>
@elseif($entry->hasFlag('passed_prelim'))
<span
class="inline-flex items-center rounded-md bg-green-100 px-2 py-1 text-sm font-medium text-green-700">Passed Prelim</span>
@elseif($entry->audition->prelimDefinition)
<span
class="inline-flex items-center rounded-md bg-yellow-100 px-2 py-1 text-sm font-medium text-yellow-800 ">Prelim Pending</span>
@endif
<x-slot:subheading>ID #{{ $entry->id }}</x-slot:subheading>
<x-slot:right_side class="text-right">
<p>{{ $entry->student->full_name() }}</p>
@ -11,7 +21,8 @@
</x-slot:right_side>
</x-card.heading>
<x-form.form method="POST" id='scoreForm' action="{{ route('scores.saveEntryScoreSheet',[ 'entry' => $entry->id]) }}">
<x-form.form method="POST" id='scoreForm'
action="{{ route('scores.saveEntryScoreSheet',[ 'entry' => $entry->id]) }}">
<x-table.table>
<thead>
<tr>
@ -67,10 +78,83 @@
</x-form.form>
</x-card.card>
@if($entry->audition->prelimDefinition)
<x-card.card class="mx-auto max-w-7xl mt-5">
<x-card.heading>
{{ $entry->audition->name }} #{{ $entry->draw_number }} PRELIM SCORES
<x-slot:subheading>ID #{{ $entry->id }}</x-slot:subheading>
<x-slot:right_side class="text-right">
<p>{{ $entry->student->full_name() }}</p>
<p>{{ $entry->student->school->name }}</p>
</x-slot:right_side>
</x-card.heading>
<x-form.form method="POST" id='scoreForm'
action="{{ route('scores.savePrelimEntryScoreSheet',[ 'entry' => $entry->id]) }}">
<x-table.table>
<thead>
<tr>
<x-table.th>Judges</x-table.th>
@foreach($prelim_subscores as $subscore)
<x-table.th>
<div class="">
<div>{{ $subscore->name }}</div>
<div class="text-xs text-gray-500">
<span>Max: {{ $subscore->max_score }}</span>
<span class="pl-2">Weight: {{ $subscore->weight }}</span>
</div>
</div>
</x-table.th>
@endforeach
<x-table.th>Total</x-table.th>
</tr>
</thead>
<x-table.body :sortable="false">
@foreach($prelim_judges as $judge)
@php($existingSheet = $existing_prelim_sheets[$judge->id] ?? null)
<tr>
<x-table.td>{{ $judge->full_name() }}</x-table.td>
@foreach($prelim_subscores as $subscore)
<x-table.td>
<input type="number"
max="{{ $subscore->max_score }}"
id="j{{ $judge->id }}ss{{ $subscore->id }}"
name="judge{{ $judge->id }}[{{ $subscore->id }}]"
class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6 judge{{$judge->id}}score"
@if($oldScores)
value="{{ $oldScores['judge'.$judge->id][$subscore->id] }}"
@elseif($existingSheet)
value="{{ $existingSheet->getSubscore($subscore->id) }}"
@endif
required
{{-- onchange="judge{{$judge->id}}sum()"--}}
>
</x-table.td>
@endforeach
<x-table.td>
<p id="judge{{ $judge->id }}total" class="pr-3">
0.000
</p>
</x-table.td>
</tr>
@endforeach
</x-table.body>
</x-table.table>
<x-form.footer class="mb-3">
<x-form.button>Save Scores</x-form.button>
</x-form.footer>
</x-form.form>
</x-card.card>
@endif
<script>
function calculateTotal(judgeId) {
let total = 0;
let totalWeights = 0;
let maxPossible = 0;
let thisSubscore
@foreach($subscores as $subscore)
thisSubscore = parseFloat(document.getElementById("j" + judgeId + "ss{{ $subscore->id }}").value) * {{ $subscore->weight }};
@ -78,8 +162,9 @@
total += thisSubscore;
}
totalWeights += {{ $subscore->weight }};
maxPossible += {{ $subscore->weight * $subscore->max_score }};
@endforeach
let finalTotal = (total / totalWeights).toFixed(3);
let finalTotal = ((total / maxPossible) * 100).toFixed(3);
document.getElementById('judge' + judgeId + 'total').innerHTML = finalTotal;
}
@ -95,7 +180,43 @@
// Call the function for each judge
@foreach($judges as $judge)
calculateTotal({{ $judge->id }});
@if($entry->audition->prelimDefinition)
@foreach($prelim_judges as $judge)
calculatePrelimTotal({{ $judge->id }});
@endforeach
@endif
@endforeach
};
</script>
@if($entry->audition->prelimDefinition)
<script>
function calculatePrelimTotal(judgeId) {
let total = 0;
let totalWeights = 0;
let maxPossible = 0;
let thisSubscore
@foreach($prelim_subscores as $subscore)
thisSubscore = parseFloat(document.getElementById("j" + judgeId + "ss{{ $subscore->id }}").value) * {{ $subscore->weight }};
if (!isNaN(thisSubscore)) {
total += thisSubscore;
}
totalWeights += {{ $subscore->weight }};
maxPossible += {{ $subscore->weight * $subscore->max_score }};
@endforeach
let finalTotal = ((total / maxPossible) * 100).toFixed(3);
document.getElementById('judge' + judgeId + 'total').innerHTML = finalTotal;
}
@foreach($prelim_judges as $judge)
document.querySelectorAll('.judge' + {{ $judge->id }} + 'score').forEach(function (el) {
el.addEventListener('change', function () {
calculatePrelimTotal({{ $judge->id }});
});
});
@endforeach
</script>
@endif
</x-layout.app>

View File

@ -6,6 +6,7 @@
<x-table.th>Draw #</x-table.th>
<x-table.th>ID</x-table.th>
<x-table.th>Student</x-table.th>
<x-table.th>Score</x-table.th>
</tr>
</thead>
<tbody>
@ -17,6 +18,7 @@
<span>{{ $entry->student->full_name() }}</span>
<span class="text-xs text-gray-400">{{ $entry->student->school->name }}</span>
</x-table.td>
<x-table.td>{{ $entry->prelimTotalScore() }}</x-table.td>
</tr>
@endforeach
</tbody>

View File

@ -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');
});
});

View File

@ -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

View File

@ -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');
});

View File

@ -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');

View File

@ -0,0 +1,174 @@
<?php
use App\Actions\Tabulation\CheckPrelimResult;
use App\Actions\Tabulation\EnterPrelimScore;
use App\Exceptions\AuditionAdminException;
use App\Models\Entry;
use App\Models\PrelimDefinition;
use App\Models\PrelimScoreSheet;
use App\Models\Room;
use App\Models\ScoringGuide;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->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');
});

View File

@ -0,0 +1,166 @@
<?php
use App\Actions\Tabulation\EnterPrelimScore;
use App\Exceptions\AuditionAdminException;
use App\Models\Audition;
use App\Models\AuditLogEntry;
use App\Models\Entry;
use App\Models\PrelimDefinition;
use App\Models\PrelimScoreSheet;
use App\Models\Room;
use App\Models\ScoringGuide;
use App\Models\SubscoreDefinition;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
// Generate Scoring Guide
$this->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 ');
});

View File

@ -0,0 +1,175 @@
<?php
use App\Models\Audition;
use App\Models\PrelimDefinition;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
describe('PrelimDefinitionController::index', function () {
it('denies access to a non-admin user', function () {
$this->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);
});
});

View File

@ -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 () {

View File

@ -0,0 +1,196 @@
<?php
use App\Actions\Draw\RunDraw;
use App\Models\Audition;
use App\Models\Entry;
use App\Models\PrelimDefinition;
use App\Models\PrelimScoreSheet;
use App\Models\Room;
use App\Models\ScoringGuide;
use App\Models\SubscoreDefinition;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
describe('PrelimJudgingController:prelimEntryList', function () {
it('only allows access to an assigned judge', function () {
$judgeUser = User::factory()->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);
});
});

View File

@ -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);
});

View File

@ -0,0 +1,41 @@
<?php
use App\Models\Audition;
use App\Models\PrelimDefinition;
use App\Models\Room;
use App\Models\ScoringGuide;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->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();
});