PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.5.21
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.5.21
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
fluent-booking / app / Services / Integrations / FluentCRM / BookingRescheduledTrigger.php

BookingRescheduledTrigger.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution 1.5.21, at app/Services/Integrations/FluentCRM/BookingRescheduledTrigger.php

149 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBooking\App\Services\Integrations\FluentCRM;
4
5 use FluentBooking\Framework\Support\Arr;
6 use FluentCrm\App\Services\Funnel\FunnelHelper;
7 use FluentCrm\App\Services\Funnel\FunnelProcessor;
8 use FluentCrm\App\Services\Funnel\BaseTrigger;
9 use FluentBooking\App\Services\CalendarService;
10
11 class BookingRescheduledTrigger extends BaseTrigger
12 {
13 public function __construct()
14 {
15 $this->triggerName = 'fluent_booking/after_booking_rescheduled';
16 $this->actionArgNum = 2;
17 $this->priority = 20;
18 parent::__construct();
19 }
20
21 public function getCalendarOptions()
22 {
23 $calendarOptions = CalendarService::getCalendarOptionsByTitle();
24
25 return apply_filters('fluent_booking/crm_trigger_calendar_options', $calendarOptions);
26 }
27
28 public function getTrigger()
29 {
30 return [
31 'category' => __('Booking', 'fluent-booking'),
32 'label' => __('Booking Rescheduled', 'fluent-booking'),
33 'description' => __('This Funnel will be initiated when a booking has been rescheduled', 'fluent-booking')
34 ];
35 }
36
37 public function getFunnelSettingsDefaults()
38 {
39 return [
40 'subscription_status' => 'subscribed'
41 ];
42 }
43
44 public function getFunnelConditionDefaults($funnel)
45 {
46 return [
47 'run_only_one' => 'no'
48 ];
49 }
50
51 public function getConditionFields($funnel)
52 {
53 return [
54 'run_only_one' => [
55 'type' => 'yes_no_check',
56 'label' => '',
57 'check_label' => __('Run this automation only once per contact. If unchecked then it will over-write existing flow', 'fluent-booking'),
58 'help' => __('If you enable this then this will run only once per customer otherwise, It will delete the existing automation flow and start new', 'fluent-booking'),
59 'options' => FunnelHelper::getUpdateOptions()
60 ],
61 ];
62 }
63
64 public function getSettingsFields($funnel)
65 {
66 return [
67 'title' => __('Booking Rescheduled Funnel', 'fluent-booking'),
68 'sub_title' => __('This Funnel will be initiated when a booking has been rescheduled.', 'fluent-booking'),
69 'fields' => [
70 'event_id' => [
71 'type' => 'grouped-select',
72 'label' => __('Booking Calendar', 'fluent-booking'),
73 'placeholder' => __('Select Calendar', 'fluent-booking'),
74 'is_multiple' => false,
75 'options' => $this->getCalendarOptions()
76 ],
77 'subscription_status' => [
78 'type' => 'option_selectors',
79 'option_key' => 'editable_statuses',
80 'is_multiple' => false,
81 'label' => __('Subscription Status', 'fluent-booking'),
82 'placeholder' => __('Select Status', 'fluent-booking')
83 ],
84 'subscription_status_info' => [
85 'type' => 'html',
86 'info' => '<b>'.__('An Automated double-optin email will be sent for new subscribers', 'fluent-booking').'</b>',
87 'dependency' => [
88 'depends_on' => 'subscription_status',
89 'operator' => '=',
90 'value' => 'pending'
91 ]
92 ]
93 ]
94 ];
95 }
96
97 public function handle($funnel, $originalArgs)
98 {
99 $booking = $originalArgs[0];
100
101 $willProcess = $this->isProcessable($funnel, $booking);
102
103 $willProcess = apply_filters('fluentcrm_funnel_will_process_' . $this->triggerName, $willProcess, $funnel, $originalArgs);
104
105 if (!$willProcess) {
106 return;
107 }
108
109 $subscriberData = array_filter([
110 'first_name' => $booking->first_name,
111 'last_name' => $booking->last_name,
112 'email' => $booking->email,
113 'phone' => $booking->phone,
114 'user_id' => $booking->person_user_id,
115 'timezone' => $booking->person_time_zone,
116 'status' => Arr::get($funnel->settings, 'subscription_status'),
117 ]);
118
119 (new FunnelProcessor())->startFunnelSequence($funnel, $subscriberData, [
120 'source_trigger_name' => $this->triggerName,
121 'source_ref_id' => $booking->id
122 ]);
123 }
124
125 private function isProcessable($funnel, $booking)
126 {
127 $slotId = Arr::get($funnel->settings, 'event_id');
128
129 if ($slotId != $booking->event_id) {
130 return false;
131 }
132
133 $subscriber = FunnelHelper::getSubscriber($booking->email);
134
135 if ($subscriber && FunnelHelper::ifAlreadyInFunnel($funnel->id, $subscriber->id)) {
136
137 $runMultiple = Arr::get($funnel->conditions, 'run_only_one') == 'no';
138
139 if ($runMultiple) {
140 FunnelHelper::removeSubscribersFromFunnel($funnel->id, [$subscriber->id]);
141 }
142
143 return $runMultiple;
144 }
145
146 return true;
147 }
148 }
149