Skip to content

Commit 9cbcaeb

Browse files
committed
add badge preview print
1 parent 9f3e800 commit 9cbcaeb

3 files changed

Lines changed: 75 additions & 33 deletions

File tree

app/Filament/Pages/BadgePreview.php

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
namespace App\Filament\Pages;
44

5-
use App\Badges\EF28_Badge;
6-
use App\Badges\EF29_Badge;
75
use App\Models\Badge\Badge;
86
use Filament\Forms\Components\TextInput;
97
use Filament\Forms\Concerns\InteractsWithForms;
108
use Filament\Forms\Contracts\HasForms;
119
use Filament\Forms\Form;
1210
use Filament\Notifications\Notification;
1311
use Filament\Pages\Page;
14-
use Illuminate\Support\Facades\Response;
1512

1613
class BadgePreview extends Page implements HasForms
1714
{
@@ -52,7 +49,9 @@ public function loadBadge(): void
5249
{
5350
$this->validate();
5451

55-
$this->badge = Badge::where('custom_id', $this->customId)->first();
52+
$this->badge = Badge::with(['fursuit.user', 'fursuit.species', 'fursuit.event'])
53+
->where('custom_id', $this->customId)
54+
->first();
5655

5756
if (!$this->badge) {
5857
Notification::make()
@@ -63,10 +62,13 @@ public function loadBadge(): void
6362
return;
6463
}
6564

65+
// Sanitize the fursuit name for display
66+
$fursuitName = mb_convert_encoding($this->badge->fursuit->name, 'UTF-8', 'UTF-8');
67+
6668
Notification::make()
6769
->title('Badge loaded')
6870
->success()
69-
->body('Badge found for: ' . $this->badge->fursuit->name)
71+
->body('Badge found for: ' . $fursuitName)
7072
->send();
7173
}
7274

@@ -81,20 +83,7 @@ public function downloadPdf()
8183
return;
8284
}
8385

84-
$badgeClass = $this->badge->fursuit->event->badge_class ?? 'EF28_Badge';
85-
86-
$printer = match ($badgeClass) {
87-
'EF29_Badge' => new EF29_Badge,
88-
'EF28_Badge' => new EF28_Badge,
89-
default => new EF28_Badge,
90-
};
91-
92-
$pdfContent = $printer->getPdf($this->badge);
93-
94-
return Response::make($pdfContent, 200, [
95-
'Content-Type' => 'application/pdf',
96-
'Content-Disposition' => 'attachment; filename="badge-' . $this->customId . '.pdf"',
97-
]);
86+
return redirect()->route('admin.badge-pdf.download', ['customId' => $this->customId]);
9887
}
9988

10089
public function viewPdf()
@@ -108,19 +97,6 @@ public function viewPdf()
10897
return;
10998
}
11099

111-
$badgeClass = $this->badge->fursuit->event->badge_class ?? 'EF28_Badge';
112-
113-
$printer = match ($badgeClass) {
114-
'EF29_Badge' => new EF29_Badge,
115-
'EF28_Badge' => new EF28_Badge,
116-
default => new EF28_Badge,
117-
};
118-
119-
$pdfContent = $printer->getPdf($this->badge);
120-
121-
return Response::make($pdfContent, 200, [
122-
'Content-Type' => 'application/pdf',
123-
'Content-Disposition' => 'inline; filename="badge-' . $this->customId . '.pdf"',
124-
]);
100+
return redirect()->route('admin.badge-pdf.view', ['customId' => $this->customId]);
125101
}
126102
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Http\Controllers\Controller;
6+
use App\Badges\EF28_Badge;
7+
use App\Badges\EF29_Badge;
8+
use App\Models\Badge\Badge;
9+
use Illuminate\Http\Response;
10+
11+
class BadgePdfController extends Controller
12+
{
13+
public function view(string $customId): Response
14+
{
15+
$badge = Badge::with(['fursuit.user', 'fursuit.species', 'fursuit.event'])
16+
->where('custom_id', $customId)
17+
->firstOrFail();
18+
19+
$badgeClass = $badge->fursuit->event->badge_class ?? 'EF28_Badge';
20+
21+
$printer = match ($badgeClass) {
22+
'EF29_Badge' => new EF29_Badge,
23+
'EF28_Badge' => new EF28_Badge,
24+
default => new EF28_Badge,
25+
};
26+
27+
$pdfContent = $printer->getPdf($badge);
28+
29+
$filename = 'badge-' . preg_replace('/[^a-zA-Z0-9-_]/', '', $customId) . '.pdf';
30+
31+
return response($pdfContent, 200)
32+
->header('Content-Type', 'application/pdf')
33+
->header('Content-Disposition', 'inline; filename="' . $filename . '"');
34+
}
35+
36+
public function download(string $customId): Response
37+
{
38+
$badge = Badge::with(['fursuit.user', 'fursuit.species', 'fursuit.event'])
39+
->where('custom_id', $customId)
40+
->firstOrFail();
41+
42+
$badgeClass = $badge->fursuit->event->badge_class ?? 'EF28_Badge';
43+
44+
$printer = match ($badgeClass) {
45+
'EF29_Badge' => new EF29_Badge,
46+
'EF28_Badge' => new EF28_Badge,
47+
default => new EF28_Badge,
48+
};
49+
50+
$pdfContent = $printer->getPdf($badge);
51+
52+
$filename = 'badge-' . preg_replace('/[^a-zA-Z0-9-_]/', '', $customId) . '.pdf';
53+
54+
return response($pdfContent, 200)
55+
->header('Content-Type', 'application/pdf')
56+
->header('Content-Disposition', 'attachment; filename="' . $filename . '"');
57+
}
58+
}

routes/web.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@
3838
Route::get('/statistics', [\App\Http\Controllers\StatisticsController::class, 'index'])->name('statistics');
3939
});
4040
});
41+
42+
// Admin badge PDF routes (used by Filament)
43+
Route::middleware(['auth'])->prefix('admin')->group(function () {
44+
Route::get('/badge-pdf/{customId}/view', [\App\Http\Controllers\Admin\BadgePdfController::class, 'view'])
45+
->name('admin.badge-pdf.view');
46+
Route::get('/badge-pdf/{customId}/download', [\App\Http\Controllers\Admin\BadgePdfController::class, 'download'])
47+
->name('admin.badge-pdf.download');
48+
});

0 commit comments

Comments
 (0)