From 0d5a11130e821b76b79f229b7b2c0a07ecd12d04 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sat, 24 Aug 2024 20:55:26 -0500 Subject: [PATCH] Printing cards works for 4x4 pages Closes #53 --- app/Actions/Print/QuarterPageCards.php | 115 +++++++++++++++++++++- app/Http/Controllers/Admin/PrintCards.php | 6 +- 2 files changed, 114 insertions(+), 7 deletions(-) diff --git a/app/Actions/Print/QuarterPageCards.php b/app/Actions/Print/QuarterPageCards.php index 4f61515..deaac40 100644 --- a/app/Actions/Print/QuarterPageCards.php +++ b/app/Actions/Print/QuarterPageCards.php @@ -2,14 +2,121 @@ namespace App\Actions\Print; -class QuarterPageCards +use App\Models\Entry; +use Codedge\Fpdf\Fpdf\Fpdf; +use Illuminate\Support\Collection; + +use function auditionSetting; + +class QuarterPageCards implements PrintCards { - public function __construct() + protected $pdf; + + protected $margin = .3; + + protected $quadOn = 1; + + protected $offset = [ + 1 => [0, 0], + 2 => [5.5, 0], + 3 => [0, 4.25], + 4 => [5.5, 4.25], + ]; + + public function print(Collection $entries): void { + $this->pdf = new Fpdf('L', 'in', 'letter'); + $this->pdf->setMargins($this->margin, $this->margin); + $this->pdf->SetAutoPageBreak(false); + $this->addPage(); + foreach ($entries as $entry) { + $this->addCard($entry); + } + $this->pdf->Output('D', auditionSetting('auditionAbbreviation').'cards.pdf'); } - public function __invoke(): void + protected function addCard(Entry $entry) { - // + // Reset to first slot if we're out of slots + if ($this->quadOn > 4) { + $this->addPage(); + $this->quadOn = 1; + } + + // Fill in Entry ID + $this->pdf->setXY($this->offset[$this->quadOn][0] + 3.85, $this->offset[$this->quadOn][1] + $this->margin); + $this->pdf->SetFont('Arial', '', 12); + $this->pdf->Cell(1.17, .25, $entry->id); + + // Fill in Audition Name + $this->pdf->setXY($this->offset[$this->quadOn][0] + $this->margin + .1, $this->offset[$this->quadOn][1] + 1.55); + $this->pdf->SetFont('Arial', 'B', 18); + $this->pdf->Cell(4.5, .5, $entry->audition->name.' #'.$entry->draw_number); + + // Fill in student information + $this->pdf->SetFont('Arial', '', 10); + $xLoc = $this->offset[$this->quadOn][0] + 1; + $yLoc = $this->offset[$this->quadOn][1] + 3.1; + $this->pdf->setXY($xLoc, $yLoc); + $this->pdf->Cell(4.5, .25, $entry->student->full_name()); + $this->pdf->setXY($xLoc, $yLoc + .25); + $this->pdf->Cell(4.5, .25, $entry->student->school->name); + $this->pdf->setXY($xLoc, $yLoc + .5); + if (! is_null($entry->audition->room_id)) { + $this->pdf->Cell(4.5, .25, $entry->audition->room->name); + } + $this->quadOn++; + } + + protected function addPage() + { + // Create a new page + $this->pdf->AddPage(); + + // Draw dividing lines + $this->pdf->line(5.5, 0, 5.5, 8.5); + $this->pdf->line(0, 4.25, 11, 4.25); + + // Format card areas + foreach ($this->offset as $thisOffset) { + // Organization Abbreviation + $topLeftX = 0 + $thisOffset[0] + $this->margin; + $topLeftY = $thisOffset[1] + $this->margin; + $this->pdf->SetXY($topLeftX, $topLeftY); + $this->pdf->SetFont('Arial', 'B', 16); + $this->pdf->Cell(2, .25, auditionSetting('auditionAbbreviation'), 0); + + // Entry ID Block + $topLeftX = 3.5 + $thisOffset[0] - $this->margin; + $topLeftY = $thisOffset[1] + $this->margin; + $this->pdf->SetXY($topLeftX, $topLeftY); + $this->pdf->SetFont('Arial', 'B', 10); + $this->pdf->Cell(2, .25, 'Entry ID:', 1); + + // Audition Name Block + $topLeftX = $thisOffset[0] + $this->margin; + $topLeftY = $thisOffset[1] + 1.25 + $this->margin; + $this->pdf->SetFont('Arial', 'B', 9); + $this->pdf->SetXY($topLeftX, $topLeftY - .2); + $this->pdf->Cell(1, .2, 'Audition (monitor use this to introduce)'); + $this->pdf->Rect($topLeftX, $topLeftY, 4.5, .5); + + // Student Info Block + $topLeftX = $thisOffset[0] + $this->margin; + $topLeftY = 2.8 + $thisOffset[1] + $this->margin; + + $this->pdf->SetXY($topLeftX, $topLeftY); + $this->pdf->SetFont('Arial', 'B', 10); + $this->pdf->Cell(4.5, .25, 'Name:', 1); + + $this->pdf->SetXY($topLeftX, $topLeftY + .25); + $this->pdf->SetFont('Arial', 'B', 10); + $this->pdf->Cell(4.5, .25, 'School:', 1); + + $this->pdf->SetXY($topLeftX, $topLeftY + .5); + $this->pdf->SetFont('Arial', 'B', 10); + $this->pdf->Cell(4.5, .25, 'Room:', 1); + + } } } diff --git a/app/Http/Controllers/Admin/PrintCards.php b/app/Http/Controllers/Admin/PrintCards.php index 428c3fc..36510f4 100644 --- a/app/Http/Controllers/Admin/PrintCards.php +++ b/app/Http/Controllers/Admin/PrintCards.php @@ -22,7 +22,7 @@ class PrintCards extends Controller return view('admin.print_cards.index', compact('events', 'sortOptions')); } - public function print() + public function print(\App\Actions\Print\PrintCards $printer) { //dump(request()->all()); @@ -45,7 +45,7 @@ class PrintCards extends Controller }; } $cards = $cards->sortBy($sorts); - - return view('admin.print_cards.print', compact('cards')); + $printer->print($cards); + //return view('admin.print_cards.print', compact('cards')); } }