PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.2
Booking for Appointments and Events Calendar – Amelia v2.2
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 / Application / Services / Notification / ApplicationNotificationService.php
ameliabooking / src / Application / Services / Notification Last commit date
AbstractNotificationService.php 3 months ago AbstractWhatsAppNotificationService.php 3 months ago ApplicationNotificationService.php 3 months ago AppointmentNotificationService.php 3 months ago BasicWhatsAppNotificationService.php 6 months ago EmailNotificationService.php 6 months ago NotificationHelperService.php 6 months ago SMSAPIService.php 3 months ago SMSNotificationService.php 3 months ago
ApplicationNotificationService.php
377 lines
1 <?php
2
3 /**
4 * @copyright © Melograno Ventures. All rights reserved.
5 * @licence See LICENCE.md for license details.
6 */
7
8 namespace AmeliaBooking\Application\Services\Notification;
9
10 use AmeliaBooking\Application\Common\Exceptions\AccessDeniedException;
11 use AmeliaBooking\Domain\Collection\Collection;
12 use AmeliaBooking\Domain\Common\Exceptions\InvalidArgumentException;
13 use AmeliaBooking\Domain\Entity\Booking\Appointment\Appointment;
14 use AmeliaBooking\Domain\Entity\Booking\Event\Event;
15 use AmeliaBooking\Domain\Services\Settings\SettingsService;
16 use AmeliaBooking\Domain\ValueObjects\Number\Integer\Id;
17 use AmeliaBooking\Infrastructure\Common\Container;
18 use AmeliaBooking\Infrastructure\Common\Exceptions\NotFoundException;
19 use AmeliaBooking\Infrastructure\Common\Exceptions\QueryExecutionException;
20
21 /**
22 * Class ApplicationNotificationService
23 *
24 * @package AmeliaBooking\Application\Services\Notification
25 */
26 class ApplicationNotificationService
27 {
28 protected $container;
29
30 /**
31 * ApplicationNotificationService constructor.
32 *
33 * @param Container $container
34 */
35 public function __construct(Container $container)
36 {
37 $this->container = $container;
38 }
39
40 /**
41 * @param Appointment $appointment
42 * @param bool $logNotification
43 *
44 * @throws InvalidArgumentException
45 * @throws QueryExecutionException
46 */
47 public function sendAppointmentProviderStatusNotifications(
48 $appointment,
49 $logNotification = true
50 ) {
51 /** @var SettingsService $settingsService */
52 $settingsService = $this->container->get('domain.settings.service');
53
54 /** @var AppointmentNotificationService $appointmentNotificationService */
55 $appointmentNotificationService = $this->container->get('application.notification.appointment.service');
56
57 /** @var EmailNotificationService $emailNotificationService */
58 $emailNotificationService = $this->container->get('application.emailNotification.service');
59
60 /** @var SMSNotificationService $smsNotificationService */
61 $smsNotificationService = $this->container->get('application.smsNotification.service');
62
63 /** @var AbstractWhatsAppNotificationService $whatsAppNotificationService */
64 $whatsAppNotificationService = $this->container->get('application.whatsAppNotification.service');
65
66 $appointmentNotificationService->sendProviderStatusNotifications(
67 $emailNotificationService,
68 $appointment,
69 $logNotification
70 );
71
72 if ($settingsService->getSetting('notifications', 'smsSignedIn') === true) {
73 $appointmentNotificationService->sendProviderStatusNotifications(
74 $smsNotificationService,
75 $appointment,
76 $logNotification
77 );
78 }
79
80 if ($whatsAppNotificationService->checkRequiredFields()) {
81 $appointmentNotificationService->sendProviderStatusNotifications(
82 $whatsAppNotificationService,
83 $appointment,
84 $logNotification
85 );
86 }
87 }
88
89 /**
90 * @param Appointment $appointment
91 * @param Collection $bookings
92 * @param bool $logNotification
93 * @param bool $isBackend
94 * @param bool $sendInvoice
95 *
96 * @throws InvalidArgumentException
97 * @throws QueryExecutionException
98 * @throws NotFoundException
99 * @throws AccessDeniedException
100 */
101 public function sendAppointmentCustomersStatusNotifications(
102 $appointment,
103 $bookings,
104 $logNotification = true,
105 $isBackend = true,
106 $sendInvoice = false,
107 $notifyCustomers = true
108 ) {
109 /** @var SettingsService $settingsService */
110 $settingsService = $this->container->get('domain.settings.service');
111
112 /** @var AppointmentNotificationService $appointmentNotificationService */
113 $appointmentNotificationService = $this->container->get('application.notification.appointment.service');
114
115 /** @var EmailNotificationService $emailNotificationService */
116 $emailNotificationService = $this->container->get('application.emailNotification.service');
117
118 /** @var SMSNotificationService $smsNotificationService */
119 $smsNotificationService = $this->container->get('application.smsNotification.service');
120
121 /** @var AbstractWhatsAppNotificationService $whatsAppNotificationService */
122 $whatsAppNotificationService = $this->container->get('application.whatsAppNotification.service');
123
124 $appointmentNotificationService->sendCustomersStatusNotifications(
125 $emailNotificationService,
126 $appointment,
127 $bookings,
128 $logNotification,
129 $isBackend,
130 $sendInvoice,
131 $notifyCustomers
132 );
133
134 if ($settingsService->getSetting('notifications', 'smsSignedIn') === true) {
135 $appointmentNotificationService->sendCustomersStatusNotifications(
136 $smsNotificationService,
137 $appointment,
138 $bookings,
139 $logNotification,
140 $isBackend,
141 $sendInvoice
142 );
143 }
144
145 if ($whatsAppNotificationService->checkRequiredFields()) {
146 $appointmentNotificationService->sendCustomersStatusNotifications(
147 $whatsAppNotificationService,
148 $appointment,
149 $bookings,
150 $logNotification,
151 $isBackend,
152 $sendInvoice
153 );
154 }
155 }
156
157 /**
158 * @param Appointment $appointment
159 * @param bool $notifyProvider
160 * @param bool $notifyCustomers
161 *
162 * @throws QueryExecutionException
163 * @throws InvalidArgumentException
164 */
165 public function sendAppointmentRescheduleNotifications(
166 $appointment,
167 $notifyProvider = true,
168 $notifyCustomers = true
169 ) {
170 /** @var SettingsService $settingsService */
171 $settingsService = $this->container->get('domain.settings.service');
172
173 /** @var AppointmentNotificationService $appointmentNotificationService */
174 $appointmentNotificationService = $this->container->get('application.notification.appointment.service');
175
176 /** @var EmailNotificationService $emailNotificationService */
177 $emailNotificationService = $this->container->get('application.emailNotification.service');
178
179 /** @var SMSNotificationService $smsNotificationService */
180 $smsNotificationService = $this->container->get('application.smsNotification.service');
181
182 /** @var AbstractWhatsAppNotificationService $whatsAppNotificationService */
183 $whatsAppNotificationService = $this->container->get('application.whatsAppNotification.service');
184
185 $appointmentNotificationService->sendRescheduledNotifications(
186 $emailNotificationService,
187 $appointment,
188 $notifyProvider,
189 $notifyCustomers
190 );
191
192 if ($settingsService->getSetting('notifications', 'smsSignedIn') === true) {
193 $appointmentNotificationService->sendRescheduledNotifications(
194 $smsNotificationService,
195 $appointment,
196 $notifyProvider,
197 $notifyCustomers
198 );
199 }
200
201 if ($whatsAppNotificationService->checkRequiredFields()) {
202 $appointmentNotificationService->sendRescheduledNotifications(
203 $whatsAppNotificationService,
204 $appointment,
205 $notifyProvider,
206 $notifyCustomers
207 );
208 }
209 }
210
211 /**
212 * Wrapper for sending waiting list available spot notifications through all active channels.
213 *
214 * @param Appointment $appointment
215 * @param Collection $waitingBookings
216 *
217 * @throws InvalidArgumentException
218 * @throws QueryExecutionException
219 */
220 public function sendWaitingListAvailableSpotNotifications(
221 $appointment,
222 $waitingBookings
223 ) {
224 /** @var SettingsService $settingsService */
225 $settingsService = $this->container->get('domain.settings.service');
226
227 /** @var AppointmentNotificationService $appointmentNotificationService */
228 $appointmentNotificationService = $this->container->get('application.notification.appointment.service');
229
230 /** @var EmailNotificationService $emailNotificationService */
231 $emailNotificationService = $this->container->get('application.emailNotification.service');
232
233 /** @var SMSNotificationService $smsNotificationService */
234 $smsNotificationService = $this->container->get('application.smsNotification.service');
235
236 /** @var AbstractWhatsAppNotificationService $whatsAppNotificationService */
237 $whatsAppNotificationService = $this->container->get('application.whatsAppNotification.service');
238
239 $appointmentNotificationService->sendWaitingListAvailableSpotNotification(
240 $emailNotificationService,
241 $appointment,
242 $waitingBookings
243 );
244
245 if ($settingsService->getSetting('notifications', 'smsSignedIn') === true) {
246 $appointmentNotificationService->sendWaitingListAvailableSpotNotification(
247 $smsNotificationService,
248 $appointment,
249 $waitingBookings
250 );
251 }
252
253 if ($whatsAppNotificationService->checkRequiredFields()) {
254 $appointmentNotificationService->sendWaitingListAvailableSpotNotification(
255 $whatsAppNotificationService,
256 $appointment,
257 $waitingBookings
258 );
259 }
260 }
261
262 /**
263 * @param Appointment $appointment
264 * @param int|null $changedProviderId
265 * @param bool $notifyProvider
266 * @param bool $notifyCustomers
267 *
268 * @throws QueryExecutionException
269 * @throws InvalidArgumentException
270 */
271 public function sendAppointmentUpdatedNotifications(
272 $appointment,
273 $changedProviderId,
274 $notifyProvider = true,
275 $notifyCustomers = true
276 ) {
277 $this->sendAppointmentUpdatedNotificationsForUserType(
278 $appointment,
279 false,
280 $notifyCustomers
281 );
282
283 if ($changedProviderId) {
284 $newProviderId = $appointment->getProviderId()->getValue();
285
286 $appointment->setProviderId(new Id($changedProviderId));
287 }
288
289 $this->sendAppointmentUpdatedNotificationsForUserType(
290 $appointment,
291 $notifyProvider,
292 false
293 );
294
295 if ($changedProviderId) {
296 $appointment->setProviderId(new Id($newProviderId));
297 }
298 }
299
300 /**
301 * @param Appointment $appointment
302 * @param bool $notifyProvider
303 * @param bool $notifyCustomers
304 *
305 * @throws QueryExecutionException
306 * @throws InvalidArgumentException
307 */
308 private function sendAppointmentUpdatedNotificationsForUserType(
309 $appointment,
310 $notifyProvider = true,
311 $notifyCustomers = true
312 ) {
313 /** @var SettingsService $settingsService */
314 $settingsService = $this->container->get('domain.settings.service');
315
316 /** @var AppointmentNotificationService $appointmentNotificationService */
317 $appointmentNotificationService = $this->container->get('application.notification.appointment.service');
318
319 /** @var EmailNotificationService $emailNotificationService */
320 $emailNotificationService = $this->container->get('application.emailNotification.service');
321
322 /** @var SMSNotificationService $smsNotificationService */
323 $smsNotificationService = $this->container->get('application.smsNotification.service');
324
325 /** @var AbstractWhatsAppNotificationService $whatsAppNotificationService */
326 $whatsAppNotificationService = $this->container->get('application.whatsAppNotification.service');
327
328 $appointmentNotificationService->sendUpdatedNotifications(
329 $emailNotificationService,
330 $appointment,
331 $notifyProvider,
332 $notifyCustomers
333 );
334
335 if ($settingsService->getSetting('notifications', 'smsSignedIn') === true) {
336 $appointmentNotificationService->sendUpdatedNotifications(
337 $smsNotificationService,
338 $appointment,
339 $notifyProvider,
340 $notifyCustomers
341 );
342 }
343
344 if ($whatsAppNotificationService->checkRequiredFields()) {
345 $appointmentNotificationService->sendUpdatedNotifications(
346 $whatsAppNotificationService,
347 $appointment,
348 $notifyProvider,
349 $notifyCustomers
350 );
351 }
352 }
353
354 /**
355 * @param Event $event
356 * @param string $bookingKey
357 *
358 * @throws InvalidArgumentException
359 * @throws QueryExecutionException
360 */
361 public function sendEventQrNotification($event, $bookingKey)
362 {
363 /** @var AppointmentNotificationService $appointmentNotificationService */
364 $appointmentNotificationService = $this->container->get('application.notification.appointment.service');
365
366 /** @var EmailNotificationService $emailNotificationService */
367 $emailNotificationService = $this->container->get('application.emailNotification.service');
368
369 $appointmentNotificationService->sendQrNotifications(
370 $emailNotificationService,
371 $event,
372 $bookingKey,
373 true
374 );
375 }
376 }
377