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