PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.1.3
Booking for Appointments and Events Calendar – Amelia v2.1.3
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 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 9 months ago QrCodeInfrastructureService.php 8 months ago StarterQrCodeInfrastructureService.php 9 months ago
QrCodeInfrastructureService.php
92 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 Endroid\QrCode\Builder\Builder;
11 use Endroid\QrCode\Writer\PngWriter;
12
13 /**
14 * Class QrCodeInfrastructureService
15 *
16 * @package AmeliaBooking\Infrastructure\Services\QrCode
17 */
18 class QrCodeInfrastructureService extends AbstractQrCodeInfrastructureService
19 {
20 /**
21 * @param array $qrData
22 * @return array
23 * @throws InvalidArgumentException
24 * @throws NotFoundException
25 * @throws QueryExecutionException
26 */
27 public function generateQrCode($qrData)
28 {
29 /** @var SettingsService $settingsService */
30 $settingsService = $this->container->get('domain.settings.service');
31
32 $dateFormat = $settingsService->getSetting('wordpress', 'dateFormat');
33 $timeFormat = $settingsService->getSetting('wordpress', 'timeFormat');
34
35 $eventStart = strtotime($qrData['eventStartDateTime']);
36
37 if (!$eventStart) {
38 throw new InvalidArgumentException('Invalid eventStartDateTime provided.');
39 }
40
41 $result = Builder::create()
42 ->writer(new PngWriter())
43 ->data($qrData['qrCodeData'])
44 ->size(300)
45 ->margin(10)
46 ->build();
47
48 $qrDataItem = [
49 'type' => $qrData['type'],
50 'data' => base64_encode($result->getString()),
51 'mimeType' => $result->getMimeType(),
52 'ticketManualCode' => $qrData['ticketManualCode'],
53 'bookingId' => $qrData['bookingId'],
54 'eventName' => $qrData['eventName'],
55 'eventStartDateTime' => date_i18n(
56 $dateFormat . ' ' . $timeFormat,
57 $eventStart
58 ),
59 ];
60
61 if (array_key_exists('eventLocation', $qrData)) {
62 $qrDataItem['eventLocation'] = $qrData['eventLocation'];
63 }
64
65 if (array_key_exists('eventTicketName', $qrData)) {
66 $qrDataItem['eventTicketName'] = $qrData['eventTicketName'];
67 }
68
69 ob_start();
70 include AMELIA_PATH . '/templates/qrCode/qrCode.inc';
71 $html = ob_get_clean();
72
73 $dompdf = new Dompdf();
74
75 $dompdf->setPaper('A4');
76
77 $dompdf->loadHtml($html);
78
79 $dompdf->render();
80
81 $ticketPdfName = ($qrDataItem['type'] === 'ticket'
82 ? 'Single Ticket' : 'Group Ticket') . (array_key_exists('eventTicketName', $qrDataItem) ? '-' . $qrDataItem['eventTicketName']
83 : '') . ' - ' . $qrDataItem['eventName'] . '.pdf';
84
85 return [
86 'name' => $ticketPdfName,
87 'type' => 'application/pdf',
88 'content' => $dompdf->output(),
89 ];
90 }
91 }
92