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