PluginProbe
The Innovative Form Builder – IvyForms / 1.4
The Innovative Form Builder – IvyForms v1.4
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Repository / Amelia / AmeliaRepository.php

AmeliaRepository.php in The Innovative Form Builder – IvyForms 1.4, at backend/src/Repository/Amelia/AmeliaRepository.php

73 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @copyright © Melograno Venture Studio. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace IvyForms\Repository\Amelia;
9
10 /**
11 * Repository for Amelia booking data linked to IvyForms entries.
12 */
13 class AmeliaRepository
14 {
15 /** @var \wpdb */
16 private $wpdb;
17
18 public function __construct()
19 {
20 global $wpdb;
21 $this->wpdb = $wpdb;
22 }
23
24 /**
25 * Fetch Amelia bookings linked to an IvyForms entry.
26 *
27 * @return array<int, array{
28 * appointmentId: int|string|null,
29 * id: int|string|null,
30 * purchaseId: int|string|null
31 * }>
32 */
33 public function getBookingsByEntryId(int $entryId): array
34 {
35 $prefix = $this->wpdb->prefix;
36 $customerBookingsTable = $prefix . 'amelia_customer_bookings';
37 $packagesToCustomersTable = $prefix . 'amelia_packages_to_customers';
38
39 if (
40 !$this->tableExists($customerBookingsTable)
41 || !$this->tableExists($packagesToCustomersTable)
42 ) {
43 return [];
44 }
45
46 $query = $this->wpdb->prepare(
47 "SELECT appointmentId, id, NULL AS purchaseId
48 FROM {$customerBookingsTable}
49 WHERE ivyEntryId = %d
50 UNION ALL
51 SELECT NULL AS appointmentId, NULL AS id, id AS purchaseId
52 FROM {$packagesToCustomersTable}
53 WHERE ivyEntryId = %d",
54 $entryId,
55 $entryId
56 );
57
58 $rows = $this->wpdb->get_results($query, ARRAY_A);
59
60 return is_array($rows) ? $rows : [];
61 }
62
63 private function tableExists(string $tableName): bool
64 {
65 $like = $this->wpdb->esc_like($tableName);
66 $result = $this->wpdb->get_var(
67 $this->wpdb->prepare('SHOW TABLES LIKE %s', $like)
68 );
69
70 return $result === $tableName;
71 }
72 }
73