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 @@ + [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); + + } + } +} diff --git a/app/Http/Controllers/Admin/PrintCards.php b/app/Http/Controllers/Admin/PrintCards.php new file mode 100644 index 0000000..36510f4 --- /dev/null +++ b/app/Http/Controllers/Admin/PrintCards.php @@ -0,0 +1,51 @@ +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(\App\Actions\Print\PrintCards $printer) + { + //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); + $printer->print($cards); + //return view('admin.print_cards.print', compact('cards')); + } +} diff --git a/app/Providers/PrintCardActionProvider.php b/app/Providers/PrintCardActionProvider.php new file mode 100644 index 0000000..0fb6e5b --- /dev/null +++ b/app/Providers/PrintCardActionProvider.php @@ -0,0 +1,26 @@ +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, ]; 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 }} + + id}} = true" class="rounded bg-indigo-50 px-2 py-1 text-xs font-semibold text-indigo-600 shadow-sm hover:bg-indigo-100 mr-3" type="button">Check All + id}} = false" class="rounded bg-indigo-50 px-2 py-1 text-xs font-semibold text-indigo-600 shadow-sm hover:bg-indigo-100" type="button">Uncheck All + + + + @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: + Choose Sort Criteria + @foreach($sortOptions as $value => $label) + {{ $label }} + @endforeach + + + Secondary Slot: + Choose Sort Criteria + @foreach($sortOptions as $value => $label) + {{ $label }} + @endforeach + + + Tertiary Slot: + Choose Sort Criteria + @foreach($sortOptions as $value => $label) + {{ $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/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 diff --git a/routes/admin.php b/routes/admin.php index 87de676..53de58b 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -8,6 +8,7 @@ use App\Http\Controllers\Admin\DrawController; use App\Http\Controllers\Admin\EnsembleController; use App\Http\Controllers\Admin\EntryController; use App\Http\Controllers\Admin\EventController; +use App\Http\Controllers\Admin\PrintCards; use App\Http\Controllers\Admin\RoomController; use App\Http\Controllers\Admin\SchoolController; use App\Http\Controllers\Admin\ScoringGuideController; @@ -163,4 +164,10 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->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'); + Route::post('/print', 'print')->name('admin.cards.print'); + }); });