22
33namespace App \Filament \Pages ;
44
5- use App \Badges \EF28_Badge ;
6- use App \Badges \EF29_Badge ;
75use App \Models \Badge \Badge ;
86use Filament \Forms \Components \TextInput ;
97use Filament \Forms \Concerns \InteractsWithForms ;
108use Filament \Forms \Contracts \HasForms ;
119use Filament \Forms \Form ;
1210use Filament \Notifications \Notification ;
1311use Filament \Pages \Page ;
14- use Illuminate \Support \Facades \Response ;
1512
1613class 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}
0 commit comments