parent
b69ffb8d96
commit
abbf6d155b
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
namespace App\Actions\Reports;
|
||||
|
||||
use App\Actions\Tabulation\RankAuditionEntries;
|
||||
use App\Models\Event;
|
||||
use App\Models\Seat;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class GetExportData
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function __invoke(): void
|
||||
{
|
||||
$this->getData();
|
||||
}
|
||||
|
||||
public function getData()
|
||||
{
|
||||
// Audition, Rank, Name, School, Score, Flags or Seat
|
||||
$ranker = App::make(RankAuditionEntries::class);
|
||||
$exportRows = [
|
||||
'Audition,Rank,Student Name,School,Score,Seat or Flag',
|
||||
];
|
||||
$events = Event::all();
|
||||
foreach ($events as $event) {
|
||||
$auditions = $event->auditions;
|
||||
foreach ($auditions as $audition) {
|
||||
$entries = $ranker->rank('seating', $audition);
|
||||
foreach ($entries as $entry) {
|
||||
$thisRow = $audition->name.',';
|
||||
$thisRow .= $entry->raw_rank ?? '';
|
||||
$thisRow .= ',';
|
||||
$thisRow .= $entry->student->full_name().',';
|
||||
$thisRow .= $entry->student->school->name.',';
|
||||
$thisRow .= $entry->score_totals[0] ?? '';
|
||||
$thisRow .= ',';
|
||||
if ($entry->hasFlag('failed_prelim')) {
|
||||
$thisRow .= 'Failed Prelim';
|
||||
} elseif ($entry->hasFlag('no_show')) {
|
||||
$thisRow .= 'No Show';
|
||||
} elseif ($entry->hasFlag('declined')) {
|
||||
$thisRow .= 'Declined';
|
||||
} else {
|
||||
$seat = Seat::where('entry_id', $entry->id)->first();
|
||||
if ($seat) {
|
||||
$thisRow .= $seat->ensemble->name.' '.$seat->seat;
|
||||
} else {
|
||||
$thisRow .= ' ';
|
||||
}
|
||||
}
|
||||
$exportRows[] = $thisRow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//dd($exportRows);
|
||||
return $exportRows;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Actions\Reports\GetExportData;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
|
||||
class ExportResultsController extends Controller
|
||||
{
|
||||
public function __invoke()
|
||||
{
|
||||
$exporter = App::make(GetExportData::class);
|
||||
$data = $exporter->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_export.csv"',
|
||||
]);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
<a href="{{route('admin.students.index')}}" class="block p-2 hover:text-indigo-600">Students</a>
|
||||
<a href="{{route('admin.entries.index')}}" class="block p-2 hover:text-indigo-600">Entries</a>
|
||||
<a href="{{route('admin.view_logs')}}" class="block p-2 hover:text-indigo-600">View Logs</a>
|
||||
<a href="{{route('admin.export_results')}}" class="block p-2 hover:text-indigo-600">Export Results</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use App\Http\Controllers\Admin\DrawController;
|
|||
use App\Http\Controllers\Admin\EnsembleController;
|
||||
use App\Http\Controllers\Admin\EntryController;
|
||||
use App\Http\Controllers\Admin\EventController;
|
||||
use App\Http\Controllers\Admin\ExportResultsController;
|
||||
use App\Http\Controllers\Admin\PrintCards;
|
||||
use App\Http\Controllers\Admin\PrintRoomAssignmentsController;
|
||||
use App\Http\Controllers\Admin\PrintSignInSheetsController;
|
||||
|
|
@ -23,6 +24,7 @@ use Illuminate\Support\Facades\Route;
|
|||
Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->group(function () {
|
||||
Route::view('/', 'admin.dashboard')->name('admin.dashboard');
|
||||
Route::get('/logs', App\Http\Controllers\Admin\LogViewer::class)->name('admin.view_logs');
|
||||
Route::get('/export_results', ExportResultsController::class)->name('admin.export_results');
|
||||
|
||||
Route::post('/auditions/roomUpdate', [
|
||||
AuditionController::class, 'roomUpdate',
|
||||
|
|
|
|||
Loading…
Reference in New Issue