PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 / WP / InstallActions / DB / Notification / NotificationsTableInsertRows.php
ameliabooking / src / Infrastructure / WP / InstallActions / DB / Notification Last commit date
NotificationsLogTable.php 1 month ago NotificationsSMSHistoryTable.php 2 months ago NotificationsTable.php 2 months ago NotificationsTableInsertRows.php 6 months ago NotificationsToEntitiesTable.php 2 months ago
NotificationsTableInsertRows.php
269 lines
1 <?php
2
3 namespace AmeliaBooking\Infrastructure\WP\InstallActions\DB\Notification;
4
5 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
6 use AmeliaBooking\Infrastructure\WP\InstallActions\DB\AbstractDatabaseTable;
7 use AmeliaBooking\Infrastructure\WP\Translations\NotificationsStrings;
8
9 /**
10 * Class NotificationsTableInsertRows
11 *
12 * @package AmeliaBooking\Infrastructure\WP\InstallActions\DB\Notification
13 */
14 class NotificationsTableInsertRows extends AbstractDatabaseTable
15 {
16 public const TABLE = 'notifications';
17
18 /**
19 * @return array
20 * @throws InvalidArgumentException
21 */
22 public static function buildTable()
23 {
24 global $wpdb;
25
26 $table = self::getTableName();
27 $rows = [];
28
29 $addEmail = !(int)$wpdb->get_row("SELECT COUNT(*) AS count FROM {$table} WHERE type = 'email'")->count;
30
31 if ($addEmail) {
32 $rows = array_merge($rows, NotificationsStrings::getAppointmentCustomerNonTimeBasedEmailNotifications());
33 $rows = array_merge($rows, NotificationsStrings::getAppointmentCustomerTimeBasedEmailNotifications());
34 $rows = array_merge($rows, NotificationsStrings::getAppointmentProviderNonTimeBasedEmailNotifications());
35 $rows = array_merge($rows, NotificationsStrings::getAppointmentProviderTimeBasedEmailNotifications());
36 }
37
38 $addSMS = !(int)$wpdb->get_row("SELECT COUNT(*) AS count FROM {$table} WHERE type = 'sms'")->count;
39
40 if ($addSMS) {
41 $rows = array_merge($rows, NotificationsStrings::getAppointmentCustomerNonTimeBasedSMSNotifications());
42 $rows = array_merge($rows, NotificationsStrings::getAppointmentCustomerTimeBasedSMSNotifications());
43 $rows = array_merge($rows, NotificationsStrings::getAppointmentProviderNonTimeBasedSMSNotifications());
44 $rows = array_merge($rows, NotificationsStrings::getAppointmentProviderTimeBasedSMSNotifications());
45 }
46
47 $addEvent = !(int)$wpdb->get_row("SELECT COUNT(*) AS count FROM {$table} WHERE entity = 'event'")->count;
48
49 if ($addEvent) {
50 $rows = array_merge($rows, NotificationsStrings::getEventCustomerNonTimeBasedEmailNotifications());
51 $rows = array_merge($rows, NotificationsStrings::getEventCustomerTimeBasedEmailNotifications());
52 $rows = array_merge($rows, NotificationsStrings::getEventProviderNonTimeBasedEmailNotifications());
53 $rows = array_merge($rows, NotificationsStrings::getEventProviderTimeBasedEmailNotifications());
54
55 $rows = array_merge($rows, NotificationsStrings::getEventCustomerNonTimeBasedSMSNotifications());
56 $rows = array_merge($rows, NotificationsStrings::getEventCustomerTimeBasedSMSNotifications());
57 $rows = array_merge($rows, NotificationsStrings::getEventProviderNonTimeBasedSMSNotifications());
58 $rows = array_merge($rows, NotificationsStrings::getEventProviderTimeBasedSMSNotifications());
59 }
60
61 $addAccountRecovery = !(int)$wpdb->get_row(
62 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_account_recovery'"
63 )->count;
64
65 if ($addAccountRecovery) {
66 $rows = array_merge($rows, [NotificationsStrings::getAccountRecoveryNotification()]);
67 }
68
69 $addEmployeePanelAccess = !(int)$wpdb->get_row(
70 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_panel_access'"
71 )->count;
72
73 if ($addEmployeePanelAccess) {
74 $rows = array_merge($rows, [NotificationsStrings::getEmployeePanelAccessNotification()]);
75 }
76
77 $addEmployeePanelRecovery = !(int)$wpdb->get_row(
78 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_panel_recovery'"
79 )->count;
80
81 if ($addEmployeePanelRecovery) {
82 $rows = array_merge($rows, [NotificationsStrings::getEmployeeAccountRecoveryNotification()]);
83 }
84
85 $customerPackagePurchased = !(int)$wpdb->get_row(
86 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_package_purchased'"
87 )->count;
88
89 if ($customerPackagePurchased) {
90 $rows = array_merge($rows, [NotificationsStrings::getCustomerPackagePurchasedEmailNotification()]);
91 $rows = array_merge($rows, [NotificationsStrings::getCustomerPackagePurchasedSmsNotification()]);
92 }
93
94 $providerPackagePurchased = !(int)$wpdb->get_row(
95 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_package_purchased'"
96 )->count;
97
98 if ($providerPackagePurchased) {
99 $rows = array_merge($rows, [NotificationsStrings::getProviderPackagePurchasedEmailNotification()]);
100 $rows = array_merge($rows, [NotificationsStrings::getProviderPackagePurchasedSmsNotification()]);
101 }
102
103 $customerPackageCanceled = !(int)$wpdb->get_row(
104 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_package_canceled'"
105 )->count;
106
107 if ($customerPackageCanceled) {
108 $rows = array_merge($rows, [NotificationsStrings::getCustomerPackageCanceledEmailNotification()]);
109 $rows = array_merge($rows, [NotificationsStrings::getCustomerPackageCanceledSmsNotification()]);
110 }
111
112 $providerPackageCanceled = !(int)$wpdb->get_row(
113 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_package_canceled'"
114 )->count;
115
116 if ($providerPackageCanceled) {
117 $rows = array_merge($rows, [NotificationsStrings::getProviderPackageCanceledEmailNotification()]);
118 $rows = array_merge($rows, [NotificationsStrings::getProviderPackageCanceledSmsNotification()]);
119 }
120
121 $customerCart = !(int)$wpdb->get_row(
122 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_cart'"
123 )->count;
124
125 if ($customerCart) {
126 $rows = array_merge($rows, [NotificationsStrings::getCustomerCartEmailNotification()]);
127 $rows = array_merge($rows, [NotificationsStrings::getCustomerCartSmsNotification()]);
128 }
129
130 $providerCart = !(int)$wpdb->get_row(
131 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_cart'"
132 )->count;
133
134 if ($providerCart) {
135 $rows = array_merge($rows, [NotificationsStrings::getProviderCartEmailNotification()]);
136 $rows = array_merge($rows, [NotificationsStrings::getProviderCartSmsNotification()]);
137 }
138
139 $customerWaitingList = !(int)$wpdb->get_row(
140 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_event_waiting'"
141 )->count;
142
143 if ($customerWaitingList) {
144 $rows = array_merge($rows, [NotificationsStrings::getCustomerWaitingListEmailNotification()]);
145 $rows = array_merge($rows, [NotificationsStrings::getCustomerWaitingListSmsNotification()]);
146 }
147
148 $customerAppointmentWaitingList = !(int)$wpdb->get_row(
149 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_appointment_waiting'"
150 )->count;
151
152 if ($customerAppointmentWaitingList) {
153 $rows = array_merge($rows, [NotificationsStrings::getCustomerAppointmentWaitingListEmailNotification()]);
154 $rows = array_merge($rows, [NotificationsStrings::getCustomerAppointmentWaitingListSmsNotification()]);
155 $rows = array_merge($rows, [NotificationsStrings::getCustomerAppointmentWaitingListAvailableSpotEmailNotification()]);
156 $rows = array_merge($rows, [NotificationsStrings::getCustomerAppointmentWaitingListAvailableSpotSmsNotification()]);
157 }
158
159 $providerWaitingList = !(int)$wpdb->get_row(
160 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_event_waiting'"
161 )->count;
162
163 if ($providerWaitingList) {
164 $rows = array_merge($rows, [NotificationsStrings::getProviderWaitingListEmailNotification()]);
165 $rows = array_merge($rows, [NotificationsStrings::getProviderWaitingListSmsNotification()]);
166 }
167
168 $customerQrCode = !(int)$wpdb->get_row(
169 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_event_qr_code'"
170 )->count;
171
172 if ($customerQrCode) {
173 $rows = array_merge($rows, [NotificationsStrings::getCustomerQrCodeEmailNotification()]);
174 }
175
176 $providerAppointmentWaitingList = !(int)$wpdb->get_row(
177 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_appointment_waiting'"
178 )->count;
179
180 if ($providerAppointmentWaitingList) {
181 $rows = array_merge($rows, [NotificationsStrings::getProviderAppointmentWaitingListEmailNotification()]);
182 $rows = array_merge($rows, [NotificationsStrings::getProviderAppointmentWaitingListSmsNotification()]);
183 }
184
185 $addWhatsApp = !(int)$wpdb->get_row("SELECT COUNT(*) AS count FROM {$table} WHERE type = 'whatsapp'")->count;
186
187 if ($addWhatsApp) {
188 $rows = array_merge($rows, NotificationsStrings::getWhatsAppNotifications());
189 }
190
191 $whatsAppCart = !(int)$wpdb->get_row(
192 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_cart' AND type = 'whatsapp'"
193 )->count;
194
195 if ($whatsAppCart) {
196 $rows = array_merge($rows, NotificationsStrings::getWhatsAppCartNotifications());
197 }
198
199 $whatsAppWaitingList = !(int)$wpdb->get_row(
200 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_event_waiting' AND type = 'whatsapp'"
201 )->count;
202
203 if ($whatsAppWaitingList) {
204 $rows = array_merge($rows, NotificationsStrings::getWhatsAppWaitingListNotifications());
205 }
206
207 $whatsAppAppointmentWaitingList = !(int)$wpdb->get_row(
208 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_appointment_waiting' AND type = 'whatsapp'"
209 )->count;
210
211 if ($whatsAppAppointmentWaitingList) {
212 $rows = array_merge($rows, NotificationsStrings::getWhatsAppAppointmentWaitingListNotifications());
213 $rows = array_merge($rows, NotificationsStrings::getWhatsAppAppointmentWaitingListAvailableSpotNotifications());
214 }
215
216 $appointmentUpdated = !(int)$wpdb->get_row("SELECT COUNT(*) AS count FROM {$table} WHERE name LIKE '%appointment_updated'")->count;
217 if ($appointmentUpdated) {
218 $rows = array_merge($rows, NotificationsStrings::getAppointmentUpdatedNotifications($addEmail));
219 }
220
221 $eventUpdated = !(int)$wpdb->get_row("SELECT COUNT(*) AS count FROM {$table} WHERE name LIKE '%event_updated'")->count;
222 if ($eventUpdated) {
223 $rows = array_merge($rows, NotificationsStrings::getEventUpdatedNotifications($addEmail));
224 }
225
226 $invoiceNotifications = !(int)$wpdb->get_row(
227 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_invoice'"
228 )->count;
229
230 if ($invoiceNotifications) {
231 $rows = array_merge($rows, NotificationsStrings::getInvoiceNotification());
232 }
233
234 $result = [];
235
236 foreach ($rows as $row) {
237 $status = !empty($row['status']) ? $row['status'] : 'enabled';
238 $result[] = "INSERT INTO {$table}
239 (
240 `name`,
241 `type`,
242 `time`,
243 `timeBefore`,
244 `timeAfter`,
245 `sendTo`,
246 `subject`,
247 `content`,
248 `entity`,
249 `status`
250 )
251 VALUES
252 (
253 '{$row['name']}',
254 '{$row['type']}',
255 {$row['time']},
256 {$row['timeBefore']},
257 {$row['timeAfter']},
258 '{$row['sendTo']}',
259 '{$row['subject']}',
260 '{$row['content']}',
261 '{$row['entity']}',
262 '{$status}'
263 )";
264 }
265
266 return $result;
267 }
268 }
269