Check deadlines on nominations for SCOBDA rules

This commit is contained in:
Matt Young 2025-02-12 14:53:59 -06:00
parent 66016fb2ec
commit e112e3be89
2 changed files with 69 additions and 26 deletions

View File

@ -7,11 +7,16 @@ use App\Models\NominationEnsemble;
use App\Models\NominationEnsembleEntry;
use App\Models\School;
use App\Models\Student;
use Illuminate\Support\Carbon;
class ScobdaNominationEnsembleEntryController extends Controller implements NominationEnsembleEntryController
{
public function index()
{
// Get current date for checking deadlines
$currentDate = Carbon::now('America/Chicago');
$currentDate = $currentDate->format('Y-m-d');
$ensembles = NominationEnsemble::all();
// populate an array with each ensemble id as a key. Each item will be a collection of students available to be nominated
$availableStudents = [];
@ -51,7 +56,7 @@ class ScobdaNominationEnsembleEntryController extends Controller implements Nomi
return view('nomination_ensembles.scobda.entries.index',
compact('ensembles', 'availableStudents', 'availableInstruments', 'nominatedStudents',
'nominationsAvailable'));
'nominationsAvailable', 'currentDate'));
}
public function show(NominationEnsembleEntry $entry)
@ -87,6 +92,13 @@ class ScobdaNominationEnsembleEntryController extends Controller implements Nomi
$proposedEnsemble = NominationEnsemble::find($validData['ensemble']);
$currentDate = Carbon::now('America/Chicago');
$currentDate = $currentDate->format('Y-m-d');
if ($proposedEnsemble->entry_deadline < $currentDate) {
return redirect()->route('nomination.entry.index')->with('error',
'The nomination deadline for that ensemble has passed');
}
if (! in_array($validData['new_instrument'], $proposedEnsemble->data['instruments'])) {
return redirect()->route('nomination.entry.index')->with('error',
'Invalid Instrument specified');
@ -132,6 +144,14 @@ class ScobdaNominationEnsembleEntryController extends Controller implements Nomi
return redirect()->route('nomination.entry.index')->with('error',
'You may only delete nominations from your school');
}
$currentDate = Carbon::now('America/Chicago');
$currentDate = $currentDate->format('Y-m-d');
if ($entry->ensemble->entry_deadline < $currentDate) {
return redirect()->route('nomination.entry.index')->with('error',
'You cannot delete nominations after the deadline');
}
$entry->delete();
return redirect()->route('nomination.entry.index')->with('success', 'Nomination Deleted');
@ -167,13 +187,27 @@ class ScobdaNominationEnsembleEntryController extends Controller implements Nomi
public function move()
{
// TODO: Verify the student being moved is from the users school
$validData = request()->validate([
'direction' => 'required|in:up,down',
'nominationId' => 'required|exists:App\Models\NominationEnsembleEntry,id',
]);
$direction = $validData['direction'];
$nomination = NominationEnsembleEntry::findOrFail($validData['nominationId']);
// Verify the entry deadline for the ensemble has not passed
$currentDate = Carbon::now('America/Chicago');
$currentDate = $currentDate->format('Y-m-d');
if ($nomination->ensemble->entry_deadline < $currentDate) {
return redirect()->route('nomination.entry.index')->with('error',
'The entry deadline for that nomination ensemble has passed');
}
// Verify the student being moved is from the users school
if (auth()->user()->school_id !== $nomination->student_id) {
return redirect()->route('nomination.entry.index')->with('error',
'You cannot modify nominations of another school');
}
$data = $nomination->data;
if ($validData['direction'] == 'up') {
$data['rank'] = $nomination->data['rank'] - 1.5;

View File

@ -1,4 +1,5 @@
@php($n=1)
<x-layout.app>
<x-slot:page_title>Nomination Entries</x-slot:page_title>
@ -7,7 +8,8 @@
@foreach($ensembles as $ensemble)
<x-layout.page-section>
<x-slot:section_name>{{ $ensemble->name }}</x-slot:section_name>
<x-slot:section_description>{{ $ensemble->data['max_nominations'] }} nominations accepted</x-slot:section_description>
<x-slot:section_description>{{ $ensemble->data['max_nominations'] }} nominations accepted
</x-slot:section_description>
<x-table.table>
<thead>
<tr>
@ -17,38 +19,45 @@
</tr>
</thead>
<x-table.body>
{{-- List existing nominations--}}
{{-- List existing nominations--}}
@foreach($nominatedStudents[$ensemble->id] as $nomination)
<tr>
<x-table.td>{{ $nomination->data['rank'] }}</x-table.td>
<x-table.td>{{ $nomination->student->full_name() }}</x-table.td>
<x-table.td>{{ $nomination->data['instrument'] }}</x-table.td>
@if($currentDate <= $ensemble->entry_deadline)
<x-table.td class="flex">
<x-delete-resource-modal
title="Delete Nomination"
method="DELETE"
action="{{ route('nomination.entry.destroy', [$nomination]) }}">
Confirm you wish to delete the nomination of {{ $nomination->student->full_name() }}<br>
Confirm you wish to delete the nomination
of {{ $nomination->student->full_name() }}<br>
for the {{ $ensemble->name }} ensemble.
</x-delete-resource-modal>
<form method="POST" action="{{ route('nomination.entry.move') }}">
@csrf
<input type="hidden" name="direction" value="up">
<input type="hidden" name="nominationId" value="{{ $nomination->id }}">
<button class="ml-3" type="submit"><x-icons.up-arrow /></button>
<button class="ml-3" type="submit">
<x-icons.up-arrow/>
</button>
</form>
<form method="POST" action="{{ route('nomination.entry.move') }}">
@csrf
<input type="hidden" name="direction" value="down">
<input type="hidden" name="nominationId" value="{{ $nomination->id }}">
<button class="ml-3" type="submit"><x-icons.down-arrow /></button>
<button class="ml-3" type="submit">
<x-icons.down-arrow/>
</button>
</form>
</x-table.td>
@endif
</tr>
@endforeach
{{-- LINE TO ADD A NOMINATION--}}
@if($nominationsAvailable[$ensemble->id] && $availableStudents[$ensemble->id]->count() > 0)
@if($currentDate <= $ensemble->entry_deadline && $nominationsAvailable[$ensemble->id] && $availableStudents[$ensemble->id]->count() > 0)
<tr>
<x-form.form method="POST" action="{{ route('nomination.entry.store') }}">
<input type="hidden" name="ensemble" value="{{ $ensemble->id }}"/>