Merge pull request #74 from okorpheus/auditionadmin-53
Auditionadmin 53 - Card Printing
This commit is contained in:
commit
02b154cdb4
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Actions\Print;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
interface PrintCards
|
||||||
|
{
|
||||||
|
public function print(Collection $entries);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,122 @@
|
||||||
|
<?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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
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
|
||||||
|
{
|
||||||
|
$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(\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'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Actions\Print\PrintCards;
|
||||||
|
use App\Actions\Print\QuarterPageCards;
|
||||||
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
|
class PrintCardActionProvider extends ServiceProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Register services.
|
||||||
|
*/
|
||||||
|
public function register(): void
|
||||||
|
{
|
||||||
|
$this->app->singleton(PrintCards::class, QuarterPageCards::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstrap services.
|
||||||
|
*/
|
||||||
|
public function boot(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,5 +4,6 @@ return [
|
||||||
App\Providers\AppServiceProvider::class,
|
App\Providers\AppServiceProvider::class,
|
||||||
App\Providers\FortifyServiceProvider::class,
|
App\Providers\FortifyServiceProvider::class,
|
||||||
App\Providers\InvoiceDataServiceProvider::class,
|
App\Providers\InvoiceDataServiceProvider::class,
|
||||||
|
App\Providers\PrintCardActionProvider::class,
|
||||||
Barryvdh\Debugbar\ServiceProvider::class,
|
Barryvdh\Debugbar\ServiceProvider::class,
|
||||||
];
|
];
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
<x-layout.app>
|
||||||
|
<x-slot:page_title>Select Cards to Print</x-slot:page_title>
|
||||||
|
<x-form.form method="POST" action="{{route('admin.cards.print')}}">
|
||||||
|
{{--Audition Select--}}
|
||||||
|
@foreach($events as $event)
|
||||||
|
@continue($event->auditions->isEmpty())
|
||||||
|
<x-card.card class="mb-5 mx-auto max-w-3xl" id="event-section-{{$event->id}}" x-data="{ checked{{$event->id}}: false }">
|
||||||
|
<x-card.heading>
|
||||||
|
{{ $event->name }}
|
||||||
|
<x-slot:right_side>
|
||||||
|
<button @click="checked{{$event->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</button>
|
||||||
|
<button @click="checked{{$event->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</button>
|
||||||
|
</x-slot:right_side>
|
||||||
|
</x-card.heading>
|
||||||
|
<div class="grid gap-y-3 md:grid-cols-2 lg:grid-cols-3 px-5 my-3 pb-3 border-b border-gray-100">
|
||||||
|
@foreach($event->auditions as $audition)
|
||||||
|
<div id="auditiongroup-{{$audition->id}}" class="flex align-middle">
|
||||||
|
<x-form.checkbox id="auditionCheckbox-{{$audition->id}}" name="audition[{{$audition->id}}]" x-bind:checked="checked{{$event->id}}"/>
|
||||||
|
{{$audition->name}} {{ $audition->hasFlag('drawn') ? '':'(*)' }}
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
<div class="ml-5 mb-3">
|
||||||
|
(*): Draw has not been run for this audition
|
||||||
|
</div>
|
||||||
|
</x-card.card>
|
||||||
|
|
||||||
|
{{--Sort Options--}}
|
||||||
|
<x-card.card class="mx-auto max-w-3xl">
|
||||||
|
<x-card.heading>Card Sorting</x-card.heading>
|
||||||
|
<div class="px-5 pb-5 pt-1">
|
||||||
|
<x-form.select name="sort[1]">
|
||||||
|
<x-slot:label>Primary Sort: </x-slot:label>
|
||||||
|
<option value="">Choose Sort Criteria</option>
|
||||||
|
@foreach($sortOptions as $value => $label)
|
||||||
|
<option value="{{$value}}">{{ $label }}</option>
|
||||||
|
@endforeach
|
||||||
|
</x-form.select>
|
||||||
|
<x-form.select name="sort[2]">
|
||||||
|
<x-slot:label>Secondary Slot: </x-slot:label>
|
||||||
|
<option value="">Choose Sort Criteria</option>
|
||||||
|
@foreach($sortOptions as $value => $label)
|
||||||
|
<option value="{{$value}}">{{ $label }}</option>
|
||||||
|
@endforeach
|
||||||
|
</x-form.select>
|
||||||
|
<x-form.select name="sort[3]">
|
||||||
|
<x-slot:label>Tertiary Slot: </x-slot:label>
|
||||||
|
<option value="">Choose Sort Criteria</option>
|
||||||
|
@foreach($sortOptions as $value => $label)
|
||||||
|
<option value="{{$value}}">{{ $label }}</option>
|
||||||
|
@endforeach
|
||||||
|
</x-form.select>
|
||||||
|
</div>
|
||||||
|
</x-card.card>
|
||||||
|
<x-form.button class="mt-5 mx-auto max-w-3xl" type="submit">Print Cards</x-form.button>
|
||||||
|
@endforeach
|
||||||
|
</x-form.form>
|
||||||
|
</x-layout.app>
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
@php
|
||||||
|
dump($cards);
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
<x-layout.app>
|
||||||
|
<x-table.table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<x-table.th>Room</x-table.th>
|
||||||
|
<x-table.th>Audition</x-table.th>
|
||||||
|
<x-table.th>Draw Number</x-table.th>
|
||||||
|
<x-table.th>Student</x-table.th>
|
||||||
|
<x-table.th>School</x-table.th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<x-table.body>
|
||||||
|
@foreach($cards as $card)
|
||||||
|
<tr>
|
||||||
|
<td>{{$card->audition->room->name}}</td>
|
||||||
|
<td>{{ $card->audition->name }}</td>
|
||||||
|
<td>{{ $card->draw_number }}</td>
|
||||||
|
<td>{{ $card->student->full_name(true) }}</td>
|
||||||
|
<td>{{ $card->student->school->name }}</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</x-table.body>
|
||||||
|
</x-table.table>
|
||||||
|
</x-layout.app>
|
||||||
|
|
@ -30,6 +30,7 @@
|
||||||
<x-layout.navbar.menus.menu-item :href="route('admin.rooms.index')">Rooms</x-layout.navbar.menus.menu-item>
|
<x-layout.navbar.menus.menu-item :href="route('admin.rooms.index')">Rooms</x-layout.navbar.menus.menu-item>
|
||||||
<x-layout.navbar.menus.menu-item :href="route('admin.rooms.judgingAssignment')">Judges</x-layout.navbar.menus.menu-item>
|
<x-layout.navbar.menus.menu-item :href="route('admin.rooms.judgingAssignment')">Judges</x-layout.navbar.menus.menu-item>
|
||||||
<x-layout.navbar.menus.menu-item :href="route('admin.draw.index')">Run Draw</x-layout.navbar.menus.menu-item>
|
<x-layout.navbar.menus.menu-item :href="route('admin.draw.index')">Run Draw</x-layout.navbar.menus.menu-item>
|
||||||
|
<x-layout.navbar.menus.menu-item :href="route('admin.cards.index')">Print Cards</x-layout.navbar.menus.menu-item>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use App\Http\Controllers\Admin\DrawController;
|
||||||
use App\Http\Controllers\Admin\EnsembleController;
|
use App\Http\Controllers\Admin\EnsembleController;
|
||||||
use App\Http\Controllers\Admin\EntryController;
|
use App\Http\Controllers\Admin\EntryController;
|
||||||
use App\Http\Controllers\Admin\EventController;
|
use App\Http\Controllers\Admin\EventController;
|
||||||
|
use App\Http\Controllers\Admin\PrintCards;
|
||||||
use App\Http\Controllers\Admin\RoomController;
|
use App\Http\Controllers\Admin\RoomController;
|
||||||
use App\Http\Controllers\Admin\SchoolController;
|
use App\Http\Controllers\Admin\SchoolController;
|
||||||
use App\Http\Controllers\Admin\ScoringGuideController;
|
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::patch('/{user}', 'update')->name('admin.users.update');
|
||||||
Route::delete('/{user}', 'destroy')->name('admin.users.destroy');
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue