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 +
@@ -46,10 +51,12 @@ {{ $instrument['name'] }}