$this->printShirtDistributionLists(), default => $this->invalidAction(), }; } private function printShirtDistributionLists() { $output = ''; $schools = School::with('nominations.student')->orderBy('name')->get(); $pdf = new Fpdf('P', 'in', 'letter'); foreach ($schools as $school) { if ($school->nominations->count() < 1) { continue; } $pdf->AddPage(); $pdf->SetFont('Arial', 'B', 16); $pdf->Cell(0, .3, $school->name, 1, 1, 'L'); $director_text = 'Directors: '; $first_director = true; foreach ($school->users as $user) { if (! $first_director) { $director_text .= ', '; } $director_text .= $user->full_name(); $first_director = false; } $pdf->SetFont('Arial', 'B', 12); $pdf->MultiCell(0, .3, $director_text, 0, 'L', 0); $pdf->SetFont('Arial', '', 10); $nominations = $school->nominations; $nominations = $nominations->sortBy(function ($entry) { return $entry->student->full_name(true); }); foreach ($nominations as $nomination) { $accepted = $nomination->data['accepted'] ?? false; if (! $accepted) { continue; } $text = $nomination->student->full_name().' - '; if ($nomination->student->optional_data && array_key_exists('shirt_size', $nomination->student->optional_data)) { $text .= $nomination->student->optional_data['shirt_size']; } else { $text .= 'No size provided'; } $pdf->Cell(0, .25, $text, 0, 1, 'L'); } } $pdf->Output('D', 'ShirtRosters.pdf'); } }