Add export option to MEOBDA nomination rules
This commit is contained in:
parent
077fea8166
commit
917f570c42
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@
|
|||
</a>
|
||||
@endforeach
|
||||
</ul>
|
||||
<p class="text-md/6 font-semibold text-gray-800 mb-3 mt-3">
|
||||
<a href="{{ route('nomination.admin.export') }}">
|
||||
Export Nominations
|
||||
</a>
|
||||
</p>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
|
|
@ -46,10 +51,12 @@
|
|||
{{ $instrument['name'] }}
|
||||
</x-card.heading>
|
||||
<x-card.list.body class="ml-10">
|
||||
@foreach($nominations[$split][$instrument['name']] as $thisNomination)
|
||||
<x-card.list.row>{{ $thisNomination->data['seat'] }} - {{ $thisNomination->student->full_name() }}, {{ $thisNomination->student->school->name }}</x-card.list.row>
|
||||
@foreach($nominations[$split][$instrument['name']] as $thisNomination)
|
||||
<x-card.list.row>{{ $thisNomination->data['seat'] }}
|
||||
- {{ $thisNomination->student->full_name() }}
|
||||
, {{ $thisNomination->student->school->name }}</x-card.list.row>
|
||||
|
||||
@endforeach
|
||||
@endforeach
|
||||
</x-card.list.body>
|
||||
@endforeach
|
||||
</x-card.card>
|
||||
|
|
|
|||
Loading…
Reference in New Issue