auditionadmin/app/Actions/Print/QuarterPageCards.php

123 lines
4.1 KiB
PHP

<?php
namespace App\Actions\Print;
use App\Models\Entry;
use Codedge\Fpdf\Fpdf\Fpdf;
use Illuminate\Support\Collection;
use function auditionSetting;
class QuarterPageCards implements PrintCards
{
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');
}
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);
}
}
}