Printing cards works for 4x4 pages

Closes #53
This commit is contained in:
Matt Young 2024-08-24 20:55:26 -05:00
parent d28a41efd8
commit 0d5a11130e
2 changed files with 114 additions and 7 deletions

View File

@ -2,14 +2,121 @@
namespace App\Actions\Print; 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);
}
} }
} }

View File

@ -22,7 +22,7 @@ class PrintCards extends Controller
return view('admin.print_cards.index', compact('events', 'sortOptions')); return view('admin.print_cards.index', compact('events', 'sortOptions'));
} }
public function print() public function print(\App\Actions\Print\PrintCards $printer)
{ {
//dump(request()->all()); //dump(request()->all());
@ -45,7 +45,7 @@ class PrintCards extends Controller
}; };
} }
$cards = $cards->sortBy($sorts); $cards = $cards->sortBy($sorts);
$printer->print($cards);
return view('admin.print_cards.print', compact('cards')); //return view('admin.print_cards.print', compact('cards'));
} }
} }