Enable deletion of nominations by users

This commit is contained in:
Matt Young 2025-02-13 12:07:49 -06:00
parent ac5c4cb53b
commit d7da1d4b7f
2 changed files with 33 additions and 2 deletions

View File

@ -58,6 +58,9 @@ class MeobdaNominationEnsembleEntryController extends Controller implements Nomi
}
$availableStudents[$ensemble->id] = $students;
$nominationsAvailable[$ensemble->id] = $existingNominations[$ensemble->id]->count() < $ensemble->data['max_nominations'];
if ($currentDate > $ensemble->entry_deadline) {
$nominationsAvailable[$ensemble->id] = false;
}
}
return view('nomination_ensembles.meobda.entries.index',
@ -167,6 +170,20 @@ class MeobdaNominationEnsembleEntryController extends Controller implements Nomi
public function destroy(NominationEnsembleEntry $entry)
{
// TODO: Implement destroy() method.
if ($entry->student->school_id !== auth()->user()->school_id) {
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');
}
}

View File

@ -22,9 +22,23 @@
<x-table.body>
@foreach($existingNominations[$ensemble->id] as $nom)
<tr>
<x-table.td>{{ $nom->student->full_name() }}</x-table.td>
<x-table.td class="flex">
{{ $nom->student->full_name() }}
</x-table.td>
<x-table.td>{{ $nom->student->grade }}</x-table.td>
<x-table.td>{{ $nom->data['instrument'] }}</x-table.td>
@if($nominationsAvailable[$ensemble->id])
<x-table.td>
<x-delete-resource-modal
title="Delete Nomination"
method="DELETE"
action="{{ route('nomination.entry.destroy', [$nom]) }}">
Confirm you wish to delete the nomination
of {{ $nom->student->full_name() }}<br>
for the {{ $ensemble->name }} ensemble.
</x-delete-resource-modal>
</x-table.td>
@endif
</tr>
@endforeach
</x-table.body>