33namespace App \Controller ;
44
55use App \Service \Poll \PollService ;
6+ use App \Service \Qr \QrService ;
67use Symfony \Bundle \FrameworkBundle \Controller \AbstractController ;
78use Symfony \Component \HttpFoundation \Response ;
89use Symfony \Component \Routing \Attribute \Route ;
10+ use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
911
1012class ObsController extends AbstractController
1113{
1214 public function __construct (
1315 private readonly PollService $ pollService ,
16+ private readonly QrService $ qrService ,
1417 ) {
1518 }
1619
1720 #[Route('/obs ' , name: 'app_obs ' )]
1821 public function index (): Response
1922 {
20- $ poll = $ this ->pollService ->getActivePoll ();
23+ return $ this ->render ('obs/index.html.twig ' );
24+ }
2125
22- return $ this ->render ('obs/index.html.twig ' , [
23- 'poll ' => $ poll ,
24- ]);
26+ #[Route('/obs/qr ' , name: 'app_obs_qr ' )]
27+ public function qr (): Response
28+ {
29+ return $ this ->render ('obs/qr.html.twig ' );
2530 }
2631
2732 #[Route('/obs/results ' , name: 'app_obs_results ' )]
@@ -33,4 +38,26 @@ public function results(): Response
3338 'poll ' => $ poll ,
3439 ]);
3540 }
41+
42+ #[Route('/obs/qr/results ' , name: 'app_obs_qr_results ' )]
43+ public function qrResults (): Response
44+ {
45+ $ poll = $ this ->pollService ->getActivePoll ();
46+
47+ if (null === $ poll ) {
48+ return new Response ();
49+ }
50+
51+ $ url = $ this ->generateUrl (
52+ 'app_poll_show ' ,
53+ ['shortCode ' => $ poll ->getShortCode ()],
54+ UrlGeneratorInterface::ABSOLUTE_URL
55+ );
56+
57+ $ qrCode = $ this ->qrService ->generateQrCode ($ url );
58+
59+ return $ this ->render ('obs/_qr_results.html.twig ' , [
60+ 'qrCode ' => $ qrCode ,
61+ ]);
62+ }
3663}
0 commit comments