PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / trunk
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution vtrunk
2.4.0 2.3.0 2.2.5 2.2.0 2.1.2 2.1.1 trunk 1.10.0 1.10.01 1.10.02 1.5.0 1.5.01 1.5.02 1.5.1 1.5.10 1.5.20 1.5.21 1.5.22 1.5.23 1.5.24 1.5.25 1.6.0 1.7.0 1.7.1 1.7.2 All 33 releases
← All changes | app/Hooks/Handlers/NotificationHandler.php +57 -16 1.5.21trunk View file →
@@ -3,8 +3,9 @@
3 3 namespace FluentBooking\App\Hooks\Handlers;
4 4
5 5 use FluentBooking\App\Models\Booking;
6 6 use FluentBooking\App\Services\EmailNotificationService;
7 +use FluentBooking\App\Services\NotificationGate;
7 8 use FluentBooking\Framework\Support\Arr;
8 9
9 10 class NotificationHandler
10 11 {
@@ -35,8 +36,10 @@
35 36 }
36 37
37 38 private function pushRemindersToQueue($booking, $reminderTimes, $emailTo)
38 39 {
40 + $this->clearGroupRemindersForHost($booking, $emailTo);
41 +
39 42 foreach ($reminderTimes as $time) {
40 43 $reminderTimestamp = $this->getReminderTime($time);
41 44
42 45 $happeningTimestamp = strtotime($booking->start_time);
@@ -51,19 +54,25 @@
51 54 }
52 55 }
53 56 }
54 57
58 + private function clearGroupRemindersForHost($booking, $emailTo)
59 + {
60 + if (!$booking->isMultiGuestBooking() || $emailTo != 'host') {
61 + return;
62 + }
63 +
64 + $otherBookingIds = Booking::where('group_id', $booking->group_id)->where('id', '!=', $booking->id)->pluck('id')->toArray();
65 +
66 + foreach ($otherBookingIds as $otherBookingId) {
67 + \as_unschedule_all_actions('fluent_booking/booking_schedule_reminder', [$otherBookingId, 'host'], 'fluent-booking');
68 + }
69 + }
70 +
55 71 public function pushBookingScheduledToQueue($booking, $bookingEvent)
56 72 {
57 73 $notifications = $bookingEvent->getNotifications();
58 74
59 - if (Arr::isTrue($notifications, 'booking_conf_attendee.enabled') || (Arr::isTrue($notifications, 'booking_conf_host.enabled'))) {
60 - as_enqueue_async_action('fluent_booking/after_booking_scheduled_async', [
61 - $booking->id,
62 - $bookingEvent->id
63 - ], 'fluent-booking');
64 - }
65 -
66 75 if (Arr::isTrue($notifications, 'reminder_to_attendee.enabled')) {
67 76 $reminderTimes = Arr::get($notifications, 'reminder_to_attendee.email.times', []);
68 77 $this->pushRemindersToQueue($booking, $reminderTimes, 'guest');
69 78 }
@@ -71,12 +80,31 @@
71 80 if (Arr::isTrue($notifications, 'reminder_to_host.enabled')) {
72 81 $reminderTimes = Arr::get($notifications, 'reminder_to_host.email.times', []);
73 82 $this->pushRemindersToQueue($booking, $reminderTimes, 'host');
74 83 }
84 +
85 + if (!is_null($booking->parent_id) && $booking->isRecurringBooking()) {
86 + return;
87 + }
88 +
89 + if (NotificationGate::isSuppressed('booking_scheduled', $booking)) {
90 + return;
91 + }
92 +
93 + if (Arr::isTrue($notifications, 'booking_conf_attendee.enabled') || (Arr::isTrue($notifications, 'booking_conf_host.enabled'))) {
94 + as_enqueue_async_action('fluent_booking/after_booking_scheduled_async', [
95 + $booking->id,
96 + $bookingEvent->id
97 + ], 'fluent-booking');
98 + }
75 99 }
76 100
77 101 public function pushBookingPendingToQueue($booking, $bookingEvent)
78 102 {
103 + if (NotificationGate::isSuppressed('booking_pending', $booking)) {
104 + return;
105 + }
106 +
79 107 if (!$bookingEvent->isConfirmationEnabled() || $bookingEvent->isMultiGuestEvent()) {
80 108 return;
81 109 }
82 110
@@ -83,8 +111,12 @@
83 111 if ($booking->payment_method && $booking->payment_status != 'paid') {
84 112 return;
85 113 }
86 114
115 + if (!is_null($booking->parent_id) && $booking->isRecurringBooking()) {
116 + return;
117 + }
118 +
87 119 $notifications = $bookingEvent->getNotifications();
88 120
89 121 if (Arr::isTrue($notifications, 'booking_request_host.enabled') || (Arr::isTrue($notifications, 'booking_request_attendee.enabled'))) {
90 122 as_enqueue_async_action('fluent_booking/after_booking_pending_async', [
@@ -95,8 +127,12 @@
95 127 }
96 128
97 129 public function emailToUpdatedEmail($booking, $calendarEvent)
98 130 {
131 + if (NotificationGate::isSuppressed('booking_email_changed', $booking)) {
132 + return;
133 + }
134 +
99 135 $notifications = $calendarEvent->getNotifications();
100 136
101 137 if (Arr::isTrue($notifications, 'booking_conf_attendee.enabled') || (Arr::isTrue($notifications, 'booking_conf_host.enabled'))) {
102 138 as_enqueue_async_action('fluent_booking/after_booking_scheduled_async', [
@@ -194,19 +230,20 @@
194 230 }
195 231
196 232 public function getAdditionalRecipients($additionalRecipients)
197 233 {
198 - if ($additionalRecipients) {
199 - $recipients = explode(',', $additionalRecipients);
200 - $recipients = array_map('trim', $recipients);
201 - return array_unique($recipients);
234 + if (!$additionalRecipients) {
235 + return [];
202 236 }
203 - return [];
237 +
238 + $recipients = explode(',', $additionalRecipients);
239 + $recipients = array_map('trim', $recipients);
240 + return array_unique($recipients);
204 241 }
205 242
206 243 public function emailOnBookingCancelled(Booking $booking, $calendarEvent)
207 244 {
208 - if (!$calendarEvent) {
245 + if (!$calendarEvent || NotificationGate::isSuppressed('booking_cancelled', $booking)) {
209 246 return;
210 247 }
211 248
212 249 $notifications = $calendarEvent->getNotifications();
@@ -246,10 +283,10 @@
246 283 return;
247 284 }
248 285
249 286 // Remove all reminders
250 - as_unschedule_all_actions('fluent_booking/booking_schedule_reminder', [$oldBooking->id, 'host'], 'fluent-booking');
251 - as_unschedule_all_actions('fluent_booking/booking_schedule_reminder', [$oldBooking->id, 'guest'], 'fluent-booking');
287 + \as_unschedule_all_actions('fluent_booking/booking_schedule_reminder', [$oldBooking->id, 'host'], 'fluent-booking');
288 + \as_unschedule_all_actions('fluent_booking/booking_schedule_reminder', [$oldBooking->id, 'guest'], 'fluent-booking');
252 289
253 290 if (Arr::isTrue($notifications, 'reminder_to_attendee.enabled')) {
254 291 $reminderTimes = Arr::get($notifications, 'reminder_to_attendee.email.times', []);
255 292 $this->pushRemindersToQueue($booking, $reminderTimes, 'guest');
@@ -259,8 +296,12 @@
259 296 $reminderTimes = Arr::get($notifications, 'reminder_to_host.email.times', []);
260 297 $this->pushRemindersToQueue($booking, $reminderTimes, 'host');
261 298 }
262 299
300 + if (NotificationGate::isSuppressed('booking_rescheduled', $booking)) {
301 + return;
302 + }
303 +
263 304 $rescheduledBy = $booking->getMeta('rescheduled_by_type', 'host');
264 305
265 306 if ($rescheduledBy == 'host') {
266 307 if (Arr::isTrue($notifications, 'rescheduled_by_host.enabled')) {
@@ -282,9 +323,9 @@
282 323 }
283 324
284 325 public function emailOnBookingRejected(Booking $booking, $calendarEvent)
285 326 {
286 - if (!$calendarEvent) {
327 + if (!$calendarEvent || NotificationGate::isSuppressed('booking_rejected', $booking)) {
287 328 return;
288 329 }
289 330
290 331 $notifications = $calendarEvent->getNotifications();