From 74fc377858d4a11d351dd6c40f7f5ca64e745bbd Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sat, 24 Aug 2024 08:07:53 -0500 Subject: [PATCH 1/5] Initial card printing setup Work on #53 --- app/Http/Controllers/Admin/PrintCards.php | 10 ++++++++++ routes/admin.php | 6 ++++++ 2 files changed, 16 insertions(+) create mode 100644 app/Http/Controllers/Admin/PrintCards.php diff --git a/app/Http/Controllers/Admin/PrintCards.php b/app/Http/Controllers/Admin/PrintCards.php new file mode 100644 index 0000000..2373927 --- /dev/null +++ b/app/Http/Controllers/Admin/PrintCards.php @@ -0,0 +1,10 @@ +prefix('admin/')-> Route::patch('/{user}', 'update')->name('admin.users.update'); Route::delete('/{user}', 'destroy')->name('admin.users.destroy'); }); + + // Admin Card Routes + Route::prefix('cards')->controller(PrintCards::class)->group(function () { + Route::get('/', 'index')->name('admin.cards.index'); + }); }); -- 2.39.5 From 8dad9cb53ed418dfc180232c8c0048f644b689be Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sat, 24 Aug 2024 08:12:02 -0500 Subject: [PATCH 2/5] Create view and add menu item Work on #53 --- app/Http/Controllers/Admin/PrintCards.php | 5 ++++- resources/views/admin/printcards/index.blade.php | 3 +++ .../views/components/layout/navbar/menus/setup.blade.php | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 resources/views/admin/printcards/index.blade.php diff --git a/app/Http/Controllers/Admin/PrintCards.php b/app/Http/Controllers/Admin/PrintCards.php index 2373927..a50eb3f 100644 --- a/app/Http/Controllers/Admin/PrintCards.php +++ b/app/Http/Controllers/Admin/PrintCards.php @@ -6,5 +6,8 @@ use App\Http\Controllers\Controller; class PrintCards extends Controller { - // + public function index() // Display a form to select which cards to print + { + return view('admin.printcards.index'); + } } diff --git a/resources/views/admin/printcards/index.blade.php b/resources/views/admin/printcards/index.blade.php new file mode 100644 index 0000000..7e414a4 --- /dev/null +++ b/resources/views/admin/printcards/index.blade.php @@ -0,0 +1,3 @@ + + Select Cards to Print + diff --git a/resources/views/components/layout/navbar/menus/setup.blade.php b/resources/views/components/layout/navbar/menus/setup.blade.php index 92a3191..3f51ab8 100644 --- a/resources/views/components/layout/navbar/menus/setup.blade.php +++ b/resources/views/components/layout/navbar/menus/setup.blade.php @@ -30,6 +30,7 @@ Rooms Judges Run Draw + Print Cards -- 2.39.5 From 68bd915de70962d3063ec213fe29b86da6ac8111 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sat, 24 Aug 2024 17:44:17 -0500 Subject: [PATCH 3/5] Controller correctly selects auditions Work on #53 --- app/Http/Controllers/Admin/PrintCards.php | 40 ++++++++++++- .../views/admin/print_cards/index.blade.php | 58 +++++++++++++++++++ .../views/admin/print_cards/print.blade.php | 28 +++++++++ .../views/admin/printcards/index.blade.php | 3 - routes/admin.php | 1 + 5 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 resources/views/admin/print_cards/index.blade.php create mode 100644 resources/views/admin/print_cards/print.blade.php delete mode 100644 resources/views/admin/printcards/index.blade.php diff --git a/app/Http/Controllers/Admin/PrintCards.php b/app/Http/Controllers/Admin/PrintCards.php index a50eb3f..428c3fc 100644 --- a/app/Http/Controllers/Admin/PrintCards.php +++ b/app/Http/Controllers/Admin/PrintCards.php @@ -3,11 +3,49 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use App\Models\Entry; +use App\Models\Event; class PrintCards extends Controller { public function index() // Display a form to select which cards to print { - return view('admin.printcards.index'); + $events = Event::with('auditions.flags')->get(); + $sortOptions = [ + 'name' => 'Student Name', + 'school' => 'School Name', + 'audition' => 'Audition', + 'room' => 'Room', + 'drawNumber' => 'Draw Number', + ]; + + return view('admin.print_cards.index', compact('events', 'sortOptions')); + } + + public function print() + { + //dump(request()->all()); + + $selectedAuditionIds = array_keys(request()->audition); + $cards = Entry::whereIn('audition_id', $selectedAuditionIds)->get(); + $sorts = []; + // Process submitted sort criteria + foreach (request()->sort as $sortField) { + // continue if nothing to sort by + if ($sortField === null) { + continue; + } + // set appropriate sort parameters for later processing + $sorts[] = match ($sortField) { + 'name' => fn (Entry $a, Entry $b) => $a->student->full_name(true) <=> $b->student->full_name(true), + 'school' => fn (Entry $a, Entry $b) => $a->student->school->name <=> $b->student->school->name, + 'audition' => fn (Entry $a, Entry $b) => $a->audition->score_order <=> $b->audition->score_order, + 'room' => fn (Entry $a, Entry $b) => $a->audition->room->name <=> $b->audition->room->name, + 'drawNumber' => fn (Entry $a, Entry $b) => $a->draw_number <=> $b->draw_number, + }; + } + $cards = $cards->sortBy($sorts); + + return view('admin.print_cards.print', compact('cards')); } } diff --git a/resources/views/admin/print_cards/index.blade.php b/resources/views/admin/print_cards/index.blade.php new file mode 100644 index 0000000..7be40bd --- /dev/null +++ b/resources/views/admin/print_cards/index.blade.php @@ -0,0 +1,58 @@ + + Select Cards to Print + + {{--Audition Select--}} + @foreach($events as $event) + @continue($event->auditions->isEmpty()) + + + {{ $event->name }} + + + + + +
+ @foreach($event->auditions as $audition) +
+ + {{$audition->name}} {{ $audition->hasFlag('drawn') ? '':'(*)' }} +
+ @endforeach +
+
+ (*): Draw has not been run for this audition +
+
+ + {{--Sort Options--}} + + Card Sorting +
+ + Primary Sort: + + @foreach($sortOptions as $value => $label) + + @endforeach + + + Secondary Slot: + + @foreach($sortOptions as $value => $label) + + @endforeach + + + Tertiary Slot: + + @foreach($sortOptions as $value => $label) + + @endforeach + +
+
+ Print Cards + @endforeach +
+
diff --git a/resources/views/admin/print_cards/print.blade.php b/resources/views/admin/print_cards/print.blade.php new file mode 100644 index 0000000..1a88522 --- /dev/null +++ b/resources/views/admin/print_cards/print.blade.php @@ -0,0 +1,28 @@ +@php + dump($cards); +@endphp + + + + + + Room + Audition + Draw Number + Student + School + + + + @foreach($cards as $card) + + {{$card->audition->room->name}} + {{ $card->audition->name }} + {{ $card->draw_number }} + {{ $card->student->full_name(true) }} + {{ $card->student->school->name }} + + @endforeach + + + diff --git a/resources/views/admin/printcards/index.blade.php b/resources/views/admin/printcards/index.blade.php deleted file mode 100644 index 7e414a4..0000000 --- a/resources/views/admin/printcards/index.blade.php +++ /dev/null @@ -1,3 +0,0 @@ - - Select Cards to Print - diff --git a/routes/admin.php b/routes/admin.php index 13bc4c3..53de58b 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -168,5 +168,6 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')-> // Admin Card Routes Route::prefix('cards')->controller(PrintCards::class)->group(function () { Route::get('/', 'index')->name('admin.cards.index'); + Route::post('/print', 'print')->name('admin.cards.print'); }); }); -- 2.39.5 From d28a41efd87cfbb907a78e678e08e3feb0f30428 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sat, 24 Aug 2024 17:44:53 -0500 Subject: [PATCH 4/5] Set up print cards interface and start sample implementation Work on #53 --- app/Actions/Print/PrintCards.php | 10 +++++++++ app/Actions/Print/QuarterPageCards.php | 15 +++++++++++++ app/Providers/PrintCardActionProvider.php | 26 +++++++++++++++++++++++ bootstrap/providers.php | 1 + 4 files changed, 52 insertions(+) create mode 100644 app/Actions/Print/PrintCards.php create mode 100644 app/Actions/Print/QuarterPageCards.php create mode 100644 app/Providers/PrintCardActionProvider.php diff --git a/app/Actions/Print/PrintCards.php b/app/Actions/Print/PrintCards.php new file mode 100644 index 0000000..521eceb --- /dev/null +++ b/app/Actions/Print/PrintCards.php @@ -0,0 +1,10 @@ +app->singleton(PrintCards::class, QuarterPageCards::class); + } + + /** + * Bootstrap services. + */ + public function boot(): void + { + // + } +} diff --git a/bootstrap/providers.php b/bootstrap/providers.php index 6b20b30..eeeccb0 100644 --- a/bootstrap/providers.php +++ b/bootstrap/providers.php @@ -4,5 +4,6 @@ return [ App\Providers\AppServiceProvider::class, App\Providers\FortifyServiceProvider::class, App\Providers\InvoiceDataServiceProvider::class, + App\Providers\PrintCardActionProvider::class, Barryvdh\Debugbar\ServiceProvider::class, ]; -- 2.39.5 From 0d5a11130e821b76b79f229b7b2c0a07ecd12d04 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sat, 24 Aug 2024 20:55:26 -0500 Subject: [PATCH 5/5] 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')); } } -- 2.39.5