From 344ee8e22f64ba0678ead2065ea0ecc017a6a077 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Thu, 31 Oct 2024 14:46:05 -0500 Subject: [PATCH] Add ability to change doubler decision from student screen. Closes #44 --- .../Controllers/Admin/StudentController.php | 46 ++++++++++++++++- .../Tabulation/EntryFlagController.php | 7 +++ resources/views/admin/students/edit.blade.php | 50 +++++++++++++++++-- routes/tabulation.php | 1 + 4 files changed, 100 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Admin/StudentController.php b/app/Http/Controllers/Admin/StudentController.php index 015071f..9c0d9e3 100644 --- a/app/Http/Controllers/Admin/StudentController.php +++ b/app/Http/Controllers/Admin/StudentController.php @@ -5,6 +5,8 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Audition; use App\Models\AuditLogEntry; +use App\Models\Entry; +use App\Models\Event; use App\Models\School; use App\Models\Student; use Illuminate\Support\Facades\Auth; @@ -107,9 +109,51 @@ class StudentController extends Controller $maxGrade = Audition::max('maximum_grade'); $schools = School::orderBy('name')->get(); $student->loadCount('entries'); + $entries = $student->entries; + $events = Event::all(); + $event_entries = []; + foreach ($events as $event) { + $event_entries[$event->id] = $entries->filter(function ($entry) use ($event) { + return $event->id === $entry->audition->event_id; + }); + // Check if doubler status can change + foreach ($event_entries[$event->id] as $entry) { + $entry->doubler_decision_frozen = $this->isDoublerStatusFrozen($entry, $event_entries[$event->id]); + } + } return view('admin.students.edit', - ['student' => $student, 'schools' => $schools, 'minGrade' => $minGrade, 'maxGrade' => $maxGrade]); + compact('student', 'schools', 'minGrade', 'maxGrade', 'events', 'event_entries')); + } + + private function isDoublerStatusFrozen(Entry $entry, $entries) + { + // Can't change decision if results are published + if ($entry->audition->hasFlag('seats_published')) { + return true; + } + + // Can't change decision if this is the only entry + if ($entries->count() === 1) { + return true; + } + + // Can't change decision if this is the only entry with results not published + $unpublished = $entries->reject(function ($entry) { + return $entry->audition->hasFlag('seats_published'); + }); + if ($unpublished->count() < 2) { + return true; + } + + // Can't change decision if we've accepted another audition + foreach ($entries as $checkEntry) { + if ($checkEntry->audition->hasFlag('seats_published') && ! $checkEntry->hasFlag('declined')) { + return true; + } + } + + return false; } public function update(Student $student) diff --git a/app/Http/Controllers/Tabulation/EntryFlagController.php b/app/Http/Controllers/Tabulation/EntryFlagController.php index fdbe9fe..611aef1 100644 --- a/app/Http/Controllers/Tabulation/EntryFlagController.php +++ b/app/Http/Controllers/Tabulation/EntryFlagController.php @@ -104,4 +104,11 @@ class EntryFlagController extends Controller return to_route('entry-flags.noShowSelect')->with('success', 'No Show status has been removed for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').'); } + + public function undoDecline(Entry $entry) + { + $entry->removeFlag('declined'); + + return redirect()->back()->with('success', 'Decline cleared'); + } } diff --git a/resources/views/admin/students/edit.blade.php b/resources/views/admin/students/edit.blade.php index d8acda4..555a41d 100644 --- a/resources/views/admin/students/edit.blade.php +++ b/resources/views/admin/students/edit.blade.php @@ -4,7 +4,9 @@ Edit Student @if($student->entries_count === 0) - + Please confirm you'd like to delete this student. This action cannot be undone. @@ -12,8 +14,8 @@ - - + + Grade @php($n = $minGrade) @@ -36,4 +38,46 @@ + + @foreach($events as $event) + + Entries for {{ $event->name }} + + + + ID + Audition + Draw # + Doubler Status + + + + @foreach($event_entries[$event->id] as $entry) + + {{ $entry->id }} {{ $entry->doubler_decision_frozen ? 'FROZEN':'FLEXIBLE' }} + {{ $entry->audition->name }} + {{ $entry->draw_number }} + + @if($entry->doubler_decision_frozen) +

{{ $entry->hasFlag('declined') ? 'DECLINED':'' }}

+ @else + @if($entry->hasFlag('declined')) + + {{ $entry->hasFlag('declined') ? 'DECLINED':'' }} + +
+ @csrf + @method('DELETE') + +
+ + @endif + @endif +
+ + @endforeach + +
+
+ @endforeach diff --git a/routes/tabulation.php b/routes/tabulation.php index 2a8fe42..fe60a38 100644 --- a/routes/tabulation.php +++ b/routes/tabulation.php @@ -36,6 +36,7 @@ Route::middleware(['auth', 'verified', CheckIfCanTab::class])->group(function () Route::get('/propose-no-show', 'noShowConfirm')->name('entry-flags.confirmNoShow'); Route::post('/no-show/{entry}', 'enterNoShow')->name('entry-flags.enterNoShow'); Route::delete('/no-show/{entry}', 'undoNoShow')->name('entry-flags.undoNoShow'); + Route::delete('/decline/{entry}', 'undoDecline')->name('entry-flags.undoDecline'); }); // Seating Routes