PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / Services / QrCode / QrCodeInfrastructureService.php
ameliabooking / src / Infrastructure / Services / QrCode Last commit date
AbstractQrCodeInfrastructureService.php 2 months ago QrCodeInfrastructureService.php 2 months ago StarterQrCodeInfrastructureService.php 2 months ago
QrCodeInfrastructureService.php
90 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\Services\QrCode;
4
5 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
6 use AmeliaBooking\Domain\Services\Settings\SettingsService;
7 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
8 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
9 use AmeliaVendor\Dompdf\Dompdf;
10 use BaconQrCode\Renderer\ImageRenderer;
11 use BaconQrCode\Renderer\Image\SvgImageBackEnd;
12 use BaconQrCode\Renderer\RendererStyle\RendererStyle;
13 use BaconQrCode\Writer;
14
15 /**
16 * Class QrCodeInfrastructureService
17 *
18 * @package AmeliaBooking\Infrastructure\Services\QrCode
19 */
20 class QrCodeInfrastructureService extends AbstractQrCodeInfrastructureService
21 {
22 /**
23 * @throws InvalidArgumentException
24 * @throws NotFoundException
25 * @throws QueryExecutionException
26 */
27 public function generateQrCode(array $qrData): array
28 {
29 $eventStart = strtotime($qrData['eventStartDateTime']);
30
31 if (!$eventStart) {
32 throw new InvalidArgumentException('Invalid eventStartDateTime provided.');
33 }
34
35 /** @var SettingsService $settingsService */
36 $settingsService = $this->container->get('domain.settings.service');
37
38 $dateFormat = $settingsService->getSetting('wordpress', 'dateFormat');
39 $timeFormat = $settingsService->getSetting('wordpress', 'timeFormat');
40
41 $renderer = new ImageRenderer(
42 new RendererStyle(300, 2),
43 new SvgImageBackEnd()
44 );
45
46 $qrDataItem = [
47 'type' => $qrData['type'],
48 'data' => base64_encode((new Writer($renderer))->writeString($qrData['qrCodeData'])),
49 'mimeType' => 'image/svg+xml',
50 'ticketManualCode' => $qrData['ticketManualCode'],
51 'bookingId' => $qrData['bookingId'],
52 'eventName' => $qrData['eventName'],
53 'eventStartDateTime' => date_i18n(
54 $dateFormat . ' ' . $timeFormat,
55 $eventStart
56 ),
57 ];
58
59 if (array_key_exists('eventLocation', $qrData)) {
60 $qrDataItem['eventLocation'] = $qrData['eventLocation'];
61 }
62
63 if (array_key_exists('eventTicketName', $qrData)) {
64 $qrDataItem['eventTicketName'] = $qrData['eventTicketName'];
65 }
66
67 ob_start();
68 include AMELIA_PATH . '/templates/qrCode/qrCode.inc';
69 $html = ob_get_clean();
70
71 $dompdf = new Dompdf();
72
73 $dompdf->setPaper('A4');
74
75 $dompdf->loadHtml($html);
76
77 $dompdf->render();
78
79 $ticketPdfName = ($qrDataItem['type'] === 'ticket'
80 ? 'Single Ticket' : 'Group Ticket') . (array_key_exists('eventTicketName', $qrDataItem) ? '-' . $qrDataItem['eventTicketName']
81 : '') . ' - ' . $qrDataItem['eventName'] . '.pdf';
82
83 return [
84 'name' => $ticketPdfName,
85 'type' => 'application/pdf',
86 'content' => $dompdf->output(),
87 ];
88 }
89 }
90