PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
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 / WP / InstallActions / DB / Notification / NotificationsTableInsertRows.php
ameliabooking / src / Infrastructure / WP / InstallActions / DB / Notification Last commit date
NotificationsLogTable.php 3 months ago NotificationsSMSHistoryTable.php 4 months ago NotificationsTable.php 4 months ago NotificationsTableInsertRows.php 1 week ago NotificationsToEntitiesTable.php 4 months ago
NotificationsTableInsertRows.php
317 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 * Normalizes a notification row before SQL insert.
20 * Copy is translated in NotificationsStrings::notificationTxt() after loadNotificationTextdomain() in buildTable().
21 *
22 * @param array<string, mixed> $row
23 *
24 * @return array<string, mixed>
25 */
26 private static function localizeNotificationRow(array $row)
27 {
28 return $row;
29 }
30
31 /**
32 * Load Amelia translations for notification seeding.
33 * load_plugin_textdomain() does not load MO files during the activation hook.
34 */
35 private static function loadNotificationTextdomain()
36 {
37 if (!defined('AMELIA_PATH') || !defined('AMELIA_DOMAIN')) {
38 return;
39 }
40
41 $locale = get_locale();
42 $mo = AMELIA_PATH . '/languages/' . $locale . '/wpamelia-' . $locale . '.mo';
43
44 if (!file_exists($mo)) {
45 return;
46 }
47
48 unload_textdomain(AMELIA_DOMAIN);
49 load_textdomain(AMELIA_DOMAIN, $mo);
50 }
51
52 /**
53 * @return array
54 * @throws InvalidArgumentException
55 */
56 public static function buildTable()
57 {
58 global $wpdb;
59
60 if (defined('AMELIA_PATH') && defined('AMELIA_DOMAIN')) {
61 self::loadNotificationTextdomain();
62 }
63
64 $table = self::getTableName();
65 $rows = [];
66
67 $addEmail = !(int)$wpdb->get_row("SELECT COUNT(*) AS count FROM {$table} WHERE type = 'email'")->count;
68
69 if ($addEmail) {
70 $rows = array_merge($rows, NotificationsStrings::getAppointmentCustomerNonTimeBasedEmailNotifications());
71 $rows = array_merge($rows, NotificationsStrings::getAppointmentCustomerTimeBasedEmailNotifications());
72 $rows = array_merge($rows, NotificationsStrings::getAppointmentProviderNonTimeBasedEmailNotifications());
73 $rows = array_merge($rows, NotificationsStrings::getAppointmentProviderTimeBasedEmailNotifications());
74 }
75
76 $addSMS = !(int)$wpdb->get_row("SELECT COUNT(*) AS count FROM {$table} WHERE type = 'sms'")->count;
77
78 if ($addSMS) {
79 $rows = array_merge($rows, NotificationsStrings::getAppointmentCustomerNonTimeBasedSMSNotifications());
80 $rows = array_merge($rows, NotificationsStrings::getAppointmentCustomerTimeBasedSMSNotifications());
81 $rows = array_merge($rows, NotificationsStrings::getAppointmentProviderNonTimeBasedSMSNotifications());
82 $rows = array_merge($rows, NotificationsStrings::getAppointmentProviderTimeBasedSMSNotifications());
83 }
84
85 $addEvent = !(int)$wpdb->get_row("SELECT COUNT(*) AS count FROM {$table} WHERE entity = 'event'")->count;
86
87 if ($addEvent) {
88 $rows = array_merge($rows, NotificationsStrings::getEventCustomerNonTimeBasedEmailNotifications());
89 $rows = array_merge($rows, NotificationsStrings::getEventCustomerTimeBasedEmailNotifications());
90 $rows = array_merge($rows, NotificationsStrings::getEventProviderNonTimeBasedEmailNotifications());
91 $rows = array_merge($rows, NotificationsStrings::getEventProviderTimeBasedEmailNotifications());
92
93 $rows = array_merge($rows, NotificationsStrings::getEventCustomerNonTimeBasedSMSNotifications());
94 $rows = array_merge($rows, NotificationsStrings::getEventCustomerTimeBasedSMSNotifications());
95 $rows = array_merge($rows, NotificationsStrings::getEventProviderNonTimeBasedSMSNotifications());
96 $rows = array_merge($rows, NotificationsStrings::getEventProviderTimeBasedSMSNotifications());
97 }
98
99 $addAccountRecovery = !(int)$wpdb->get_row(
100 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_account_recovery'"
101 )->count;
102
103 if ($addAccountRecovery) {
104 $rows = array_merge($rows, [NotificationsStrings::getAccountRecoveryNotification()]);
105 }
106
107 $addEmployeePanelAccess = !(int)$wpdb->get_row(
108 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_panel_access'"
109 )->count;
110
111 if ($addEmployeePanelAccess) {
112 $rows = array_merge($rows, [NotificationsStrings::getEmployeePanelAccessNotification()]);
113 }
114
115 $addEmployeePanelRecovery = !(int)$wpdb->get_row(
116 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_panel_recovery'"
117 )->count;
118
119 if ($addEmployeePanelRecovery) {
120 $rows = array_merge($rows, [NotificationsStrings::getEmployeeAccountRecoveryNotification()]);
121 }
122
123 $customerPackagePurchased = !(int)$wpdb->get_row(
124 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_package_purchased'"
125 )->count;
126
127 if ($customerPackagePurchased) {
128 $rows = array_merge($rows, [NotificationsStrings::getCustomerPackagePurchasedEmailNotification()]);
129 $rows = array_merge($rows, [NotificationsStrings::getCustomerPackagePurchasedSmsNotification()]);
130 }
131
132 $providerPackagePurchased = !(int)$wpdb->get_row(
133 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_package_purchased'"
134 )->count;
135
136 if ($providerPackagePurchased) {
137 $rows = array_merge($rows, [NotificationsStrings::getProviderPackagePurchasedEmailNotification()]);
138 $rows = array_merge($rows, [NotificationsStrings::getProviderPackagePurchasedSmsNotification()]);
139 }
140
141 $customerPackageCanceled = !(int)$wpdb->get_row(
142 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_package_canceled'"
143 )->count;
144
145 if ($customerPackageCanceled) {
146 $rows = array_merge($rows, [NotificationsStrings::getCustomerPackageCanceledEmailNotification()]);
147 $rows = array_merge($rows, [NotificationsStrings::getCustomerPackageCanceledSmsNotification()]);
148 }
149
150 $providerPackageCanceled = !(int)$wpdb->get_row(
151 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_package_canceled'"
152 )->count;
153
154 if ($providerPackageCanceled) {
155 $rows = array_merge($rows, [NotificationsStrings::getProviderPackageCanceledEmailNotification()]);
156 $rows = array_merge($rows, [NotificationsStrings::getProviderPackageCanceledSmsNotification()]);
157 }
158
159 $customerCart = !(int)$wpdb->get_row(
160 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_cart'"
161 )->count;
162
163 if ($customerCart) {
164 $rows = array_merge($rows, [NotificationsStrings::getCustomerCartEmailNotification()]);
165 $rows = array_merge($rows, [NotificationsStrings::getCustomerCartSmsNotification()]);
166 }
167
168 $providerCart = !(int)$wpdb->get_row(
169 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_cart'"
170 )->count;
171
172 if ($providerCart) {
173 $rows = array_merge($rows, [NotificationsStrings::getProviderCartEmailNotification()]);
174 $rows = array_merge($rows, [NotificationsStrings::getProviderCartSmsNotification()]);
175 }
176
177 $customerWaitingList = !(int)$wpdb->get_row(
178 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_event_waiting'"
179 )->count;
180
181 if ($customerWaitingList) {
182 $rows = array_merge($rows, [NotificationsStrings::getCustomerWaitingListEmailNotification()]);
183 $rows = array_merge($rows, [NotificationsStrings::getCustomerWaitingListSmsNotification()]);
184 }
185
186 $customerAppointmentWaitingList = !(int)$wpdb->get_row(
187 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_appointment_waiting'"
188 )->count;
189
190 if ($customerAppointmentWaitingList) {
191 $rows = array_merge($rows, [NotificationsStrings::getCustomerAppointmentWaitingListEmailNotification()]);
192 $rows = array_merge($rows, [NotificationsStrings::getCustomerAppointmentWaitingListSmsNotification()]);
193 $rows = array_merge($rows, [NotificationsStrings::getCustomerAppointmentWaitingListAvailableSpotEmailNotification()]);
194 $rows = array_merge($rows, [NotificationsStrings::getCustomerAppointmentWaitingListAvailableSpotSmsNotification()]);
195 }
196
197 $providerWaitingList = !(int)$wpdb->get_row(
198 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_event_waiting'"
199 )->count;
200
201 if ($providerWaitingList) {
202 $rows = array_merge($rows, [NotificationsStrings::getProviderWaitingListEmailNotification()]);
203 $rows = array_merge($rows, [NotificationsStrings::getProviderWaitingListSmsNotification()]);
204 }
205
206 $customerQrCode = !(int)$wpdb->get_row(
207 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_event_qr_code'"
208 )->count;
209
210 if ($customerQrCode) {
211 $rows = array_merge($rows, [NotificationsStrings::getCustomerQrCodeEmailNotification()]);
212 }
213
214 $providerAppointmentWaitingList = !(int)$wpdb->get_row(
215 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_appointment_waiting'"
216 )->count;
217
218 if ($providerAppointmentWaitingList) {
219 $rows = array_merge($rows, [NotificationsStrings::getProviderAppointmentWaitingListEmailNotification()]);
220 $rows = array_merge($rows, [NotificationsStrings::getProviderAppointmentWaitingListSmsNotification()]);
221 }
222
223 $addWhatsApp = !(int)$wpdb->get_row("SELECT COUNT(*) AS count FROM {$table} WHERE type = 'whatsapp'")->count;
224
225 if ($addWhatsApp) {
226 $rows = array_merge($rows, NotificationsStrings::getWhatsAppNotifications());
227 }
228
229 $whatsAppCart = !(int)$wpdb->get_row(
230 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_cart' AND type = 'whatsapp'"
231 )->count;
232
233 if ($whatsAppCart) {
234 $rows = array_merge($rows, NotificationsStrings::getWhatsAppCartNotifications());
235 }
236
237 $whatsAppWaitingList = !(int)$wpdb->get_row(
238 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_event_waiting' AND type = 'whatsapp'"
239 )->count;
240
241 if ($whatsAppWaitingList) {
242 $rows = array_merge($rows, NotificationsStrings::getWhatsAppWaitingListNotifications());
243 }
244
245 $whatsAppAppointmentWaitingList = !(int)$wpdb->get_row(
246 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'provider_appointment_waiting' AND type = 'whatsapp'"
247 )->count;
248
249 if ($whatsAppAppointmentWaitingList) {
250 $rows = array_merge($rows, NotificationsStrings::getWhatsAppAppointmentWaitingListNotifications());
251 $rows = array_merge($rows, NotificationsStrings::getWhatsAppAppointmentWaitingListAvailableSpotNotifications());
252 }
253
254 $appointmentUpdated = !(int)$wpdb->get_row("SELECT COUNT(*) AS count FROM {$table} WHERE name LIKE '%appointment_updated'")->count;
255 if ($appointmentUpdated) {
256 $rows = array_merge($rows, NotificationsStrings::getAppointmentUpdatedNotifications($addEmail));
257 }
258
259 $eventUpdated = !(int)$wpdb->get_row("SELECT COUNT(*) AS count FROM {$table} WHERE name LIKE '%event_updated'")->count;
260 if ($eventUpdated) {
261 $rows = array_merge($rows, NotificationsStrings::getEventUpdatedNotifications($addEmail));
262 }
263
264 $invoiceNotifications = !(int)$wpdb->get_row(
265 "SELECT COUNT(*) AS count FROM {$table} WHERE name = 'customer_invoice'"
266 )->count;
267
268 if ($invoiceNotifications) {
269 $rows = array_merge($rows, NotificationsStrings::getInvoiceNotification());
270 }
271
272 $result = [];
273
274 foreach ($rows as $row) {
275 $row = self::localizeNotificationRow($row);
276 $status = !empty($row['status']) ? $row['status'] : 'enabled';
277
278 $escapedName = esc_sql($row['name']);
279 $escapedType = esc_sql($row['type']);
280 $escapedSendTo = esc_sql($row['sendTo']);
281 $escapedSubject = esc_sql($row['subject']);
282 $escapedContent = esc_sql($row['content']);
283 $escapedEntity = esc_sql($row['entity']);
284 $escapedStatus = esc_sql($status);
285
286 $result[] = "INSERT INTO {$table}
287 (
288 `name`,
289 `type`,
290 `time`,
291 `timeBefore`,
292 `timeAfter`,
293 `sendTo`,
294 `subject`,
295 `content`,
296 `entity`,
297 `status`
298 )
299 VALUES
300 (
301 '{$escapedName}',
302 '{$escapedType}',
303 {$row['time']},
304 {$row['timeBefore']},
305 {$row['timeAfter']},
306 '{$escapedSendTo}',
307 '{$escapedSubject}',
308 '{$escapedContent}',
309 '{$escapedEntity}',
310 '{$escapedStatus}'
311 )";
312 }
313
314 return $result;
315 }
316 }
317