auditionadmin/app/Actions/Print/PrintSignInSheets.php

101 lines
3.4 KiB
PHP

<?php
namespace App\Actions\Print;
use App\Models\Entry;
use App\Models\Room;
use Illuminate\Support\Collection;
/**
* @codeCoverageIgnore
*/
// TODO figure out testing for PrintSignInSheets
class PrintSignInSheets
{
protected $pdf;
protected $margin = .5;
protected $roomOn;
protected $columnWidth = [
'id' => .5,
'instrument' => 1.25,
'drawNumber' => .3,
'name' => 1.8,
'school' => 1.4,
];
protected $headerRowHeight = .25;
protected $bodyRowHeight = .3125;
protected $blankLinesPerRoom = 10;
protected $addBlankLinesAuditionFactor = .1;
public function __construct()
{
}
public function __invoke(Collection $rooms): void
{
$this->print($rooms);
}
/**
* @param Collection|Room[] $rooms
*/
public function print(Collection $rooms)
{
$this->pdf = new signInPDF('P', 'in', 'letter');
$this->pdf->columnWidth = $this->columnWidth;
$this->pdf->headerRowHeight = $this->headerRowHeight;
$this->pdf->SetMargins($this->margin, $this->margin);
$this->pdf->SetAutoPageBreak(true, .5);
//$this->pdf->SetFont('arial', '', '10');
foreach ($rooms as $room) {
$this->pdf->roomOn = $room->name;
$auditions = $room->auditions;
$this->pdf->AddPage();
foreach ($auditions as $audition) {
$entries = $audition->entries()->orderBy('draw_number')->get();
foreach ($entries as $entry) {
$this->addEntryRow($entry);
}
// Add extra rows for audition
$extraRowCount = ceil($audition->entries()->count() * $this->addBlankLinesAuditionFactor);
for ($n = 0; $n < $extraRowCount; $n++) {
$this->addBlankRow($audition);
}
}
for ($n = 0; $n < $this->blankLinesPerRoom; $n++) {
$this->addBlankRow();
}
}
$this->pdf->Output('D', 'SignInSheets.pdf');
}
public function addEntryRow(Entry $entry)
{
$this->pdf->Cell($this->columnWidth['id'], $this->bodyRowHeight, $entry->id, 1, 0, 'L');
$this->pdf->Cell($this->columnWidth['instrument'], $this->bodyRowHeight, $entry->audition->name, 1, 0,
'L');
$this->pdf->Cell($this->columnWidth['drawNumber'], $this->bodyRowHeight, $entry->draw_number, 1, 0, 'L');
$this->pdf->Cell($this->columnWidth['name'], $this->bodyRowHeight, $entry->student->full_name(), 1, 0, 'L');
$this->pdf->Cell($this->columnWidth['school'], $this->bodyRowHeight, $entry->student->school->name, 1, 0, 'L');
$this->pdf->Cell(0, $this->bodyRowHeight, ' ', 1, 1, 'L');
}
public function addBlankRow($audition = null)
{
$a = ($audition ? $audition->name : ' ');
$this->pdf->Cell($this->columnWidth['id'], $this->bodyRowHeight, ' ', 1, 0, 'L');
$this->pdf->Cell($this->columnWidth['instrument'], $this->bodyRowHeight, $a, 1, 0, 'L');
$this->pdf->Cell($this->columnWidth['drawNumber'], $this->bodyRowHeight, ' ', 1, 0, 'L');
$this->pdf->Cell($this->columnWidth['name'], $this->bodyRowHeight, ' ', 1, 0, 'L');
$this->pdf->Cell($this->columnWidth['school'], $this->bodyRowHeight, ' ', 1, 0, 'L');
$this->pdf->Cell(0, $this->bodyRowHeight, ' ', 1, 1, 'L');
}
}