auditionadmin/app/Actions/Reports/GetExportData.php

69 lines
2.1 KiB
PHP

<?php
namespace App\Actions\Reports;
use App\Actions\Tabulation\RankAuditionEntries;
use App\Models\Event;
use App\Models\Seat;
use Illuminate\Support\Facades\App;
/**
* @codeCoverageIgnore
*/
// TODO figure out testing for GetExportData
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,Grade,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->student->grade.',';
$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;
}
}