Scobda nomination ensembles #106

Merged
okorpheus merged 25 commits from scobda_first_year into master 2025-02-12 21:51:10 +00:00
2 changed files with 69 additions and 26 deletions
Showing only changes of commit e112e3be89 - Show all commits

View File

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

View File

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