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;
|
namespace App\Http\Controllers\NominationEnsembles;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Models\NominationEnsembleEntry;
|
||||||
|
use Illuminate\Support\Facades\Response;
|
||||||
|
|
||||||
class MeobdaNominationExportController extends Controller implements NominationExportController
|
class MeobdaNominationExportController extends Controller implements NominationExportController
|
||||||
{
|
{
|
||||||
public function __invoke()
|
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>
|
</a>
|
||||||
@endforeach
|
@endforeach
|
||||||
</ul>
|
</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>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -47,7 +52,9 @@
|
||||||
</x-card.heading>
|
</x-card.heading>
|
||||||
<x-card.list.body class="ml-10">
|
<x-card.list.body class="ml-10">
|
||||||
@foreach($nominations[$split][$instrument['name']] as $thisNomination)
|
@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>
|
<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>
|
</x-card.list.body>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue