From 917f570c4264bc6ba572172d5f40b054c701be52 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Tue, 25 Mar 2025 08:59:59 -0500 Subject: [PATCH] Add export option to MEOBDA nomination rules --- .../MeobdaNominationExportController.php | 43 +++++++++++++++++++ .../meobda/admin/seating.blade.php | 13 ++++-- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/NominationEnsembles/MeobdaNominationExportController.php b/app/Http/Controllers/NominationEnsembles/MeobdaNominationExportController.php index 2823331..cd7c7c4 100644 --- a/app/Http/Controllers/NominationEnsembles/MeobdaNominationExportController.php +++ b/app/Http/Controllers/NominationEnsembles/MeobdaNominationExportController.php @@ -3,11 +3,54 @@ namespace App\Http\Controllers\NominationEnsembles; use App\Http\Controllers\Controller; +use App\Models\NominationEnsembleEntry; +use Illuminate\Support\Facades\Response; class MeobdaNominationExportController extends Controller implements NominationExportController { public function __invoke() { + $data = $this->getData(); + // Create a callback to write the CSV data + $callback = function () use ($data) { + $file = fopen('php://output', 'w'); + foreach ($data as $line) { + // Convert the string into an array + $fields = explode(',', $line); + // Write the array to the CSV file + fputcsv($file, $fields); + } + + fclose($file); + }; + + // Return a response with the CSV content + return Response::stream($callback, 200, [ + 'Content-Type' => 'text/csv', + 'Content-Disposition' => 'attachment; filename="audition_entries_export.csv"', + ]); + dd($this->getData()); + } + + private function getData() + { + // Room, Audition, Draw Number, Name, School + $exportRows = [ + 'Ensemble,Split,Instrument,Seat,First Name, Last Name,School', + ]; + $nominations = NominationEnsembleEntry::with('ensemble')->with('student.school')->get(); + foreach ($nominations as $nomination) { + $ensemble = $nomination->ensemble->name; + $split = $nomination->data['split']; + $instrument = $nomination->data['instrument']; + $seat = $nomination->data['seat']; + $firstName = $nomination->student->first_name; + $lastName = $nomination->student->last_name; + $schoolName = $nomination->student->school->name; + $exportRows[] = "$ensemble, $split, $instrument, $seat, $firstName, $lastName, $schoolName"; + } + + return $exportRows; } } diff --git a/resources/views/nomination_ensembles/meobda/admin/seating.blade.php b/resources/views/nomination_ensembles/meobda/admin/seating.blade.php index f1024d3..49b4222 100644 --- a/resources/views/nomination_ensembles/meobda/admin/seating.blade.php +++ b/resources/views/nomination_ensembles/meobda/admin/seating.blade.php @@ -14,6 +14,11 @@ @endforeach +

+ + Export Nominations + +

@@ -46,10 +51,12 @@ {{ $instrument['name'] }} - @foreach($nominations[$split][$instrument['name']] as $thisNomination) - {{ $thisNomination->data['seat'] }} - {{ $thisNomination->student->full_name() }}, {{ $thisNomination->student->school->name }} + @foreach($nominations[$split][$instrument['name']] as $thisNomination) + {{ $thisNomination->data['seat'] }} + - {{ $thisNomination->student->full_name() }} + , {{ $thisNomination->student->school->name }} - @endforeach + @endforeach @endforeach