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
fluent-booking / app / Services / LocationService.php

LocationService.php in Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution trunk, at app/Services/LocationService.php

230 lines 9.4 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;
4
5 use FluentBooking\App\App;
6 use FluentBooking\App\Models\Booking;
7 use FluentBooking\Framework\Support\Arr;
8
9 class LocationService
10 {
11 public static function getLocationIconHeadingHtml($details = [], $calendarEvent = null)
12 {
13 $html = '';
14 $app = App::getInstance();
15
16 foreach ($details as $location) {
17 $locationType = Arr::get($location, 'type', '');
18 $displayOnBooking = Arr::get($location, 'display_on_booking') === 'yes';
19 $meetingLink = esc_html(Arr::get($location, 'meeting_link', ''));
20 $description = esc_html(Arr::get($location, 'description', ''));
21 $title = esc_html(Arr::get($location, 'title', ''));
22 $hostPhoneNumber = esc_html(Arr::get($location, 'host_phone_number', ''));
23
24 $html .= '<div class="slot_location fcal_icon_item fcal_img_item fcal_loc_google_meet">';
25 if ($locationType == 'google_meet') {
26 $html .= '<img class="fcal_loc_icon" src="' . $app['url.assets'] . 'images/g-meet.svg" alt="Google Meet" />';
27 $html .= '<span class="fcal_loc_text">' . __('Google Meet', 'fluent-booking') . '</span>';
28 } else if ($locationType == 'ms_teams') {
29 $html .= '<img class="fcal_loc_icon" src="' . $app['url.assets'] . 'images/ms-teams.svg" alt="MS Teams" />';
30 $html .= '<span class="fcal_loc_text">' . __('MS Teams', 'fluent-booking') . '</span>';
31 } else if ($locationType == 'zoom_meeting') {
32 $html .= '<img class="fcal_loc_icon zoom_icon" src="' . $app['url.assets'] . 'images/zoom.svg" alt="Zoom Icon" />';
33 $html .= '<span class="fcal_loc_text">' . __('Zoom Video', 'fluent-booking') . '</span>';
34 } else if ($locationType == 'online_meeting') {
35 $html .= '<img class="fcal_loc_icon link_icon" src="' . $app['url.assets'] . 'images/link.svg" alt="Online Meeting" />';
36 if ($displayOnBooking) {
37 $html .= '<span class="fcal_loc_text"><span class="fcal_loc_title">' . $meetingLink . '</span>';
38 } else {
39 $html .= '<span class="fcal_loc_text">' . __('Online Meeting', 'fluent-booking') . '</span>';
40 }
41 } else if ($locationType == 'in_person_guest') {
42 $html .= '<img class="fcal_loc_icon location_icon" src="' . $app['url.assets'] . 'images/physical_location.svg" alt="' . __('In Person', 'fluent-booking') . '" />';
43 $html .= '<span class="fcal_loc_text">' . __('In Person (Attendee Address)', 'fluent-booking') . '</span>';
44 } else if ($locationType == 'custom') {
45 $html .= '<img class="fcal_loc_icon location_icon" src="' . $app['url.assets'] . 'images/physical_location.svg" alt="' . __('Custom Icon', 'fluent-booking') . '" />';
46 if ($displayOnBooking) {
47 $html .= '<span class="fcal_loc_text">' . $description . '</span>';
48 } else {
49 $html .= '<span class="fcal_loc_text">' . $title . '</span>';
50 }
51 } else if ($locationType == 'in_person_organizer') {
52 $html .= '<img class="fcal_loc_icon location_icon" src="' . $app['url.assets'] . 'images/physical_location.svg" alt="' . __('In Person', 'fluent-booking') . '" />';
53 if ($displayOnBooking) {
54 $html .= '<span class="fcal_loc_text">' . $description . '</span>';
55 } else {
56 $html .= '<span class="fcal_loc_text">' . __('In Person (Organizer Address)', 'fluent-booking') . '</span>';
57 }
58 } else if ($locationType == 'phone_guest') {
59 $html .= '<img class="fcal_loc_icon phone_icon" src="' . $app['url.assets'] . 'images/phone_call.svg" alt="' . __('Phone', 'fluent-booking') . '" />';
60 $html .= '<span class="fcal_loc_text">' . __('Attendee Phone Number', 'fluent-booking') . '</span>';
61 } else if ($locationType == 'phone_organizer') {
62 $html .= '<img class="fcal_loc_icon phone_icon" src="' . $app['url.assets'] . 'images/phone_call.svg" alt="' . __('Phone', 'fluent-booking') . '" />';
63 if ($displayOnBooking) {
64 $html .= '<span class="fcal_loc_text">' . $hostPhoneNumber . '</span>';
65 } else {
66 $html .= '<span class="fcal_loc_text">' . __('Phone Call', 'fluent-booking') . '</span>';
67 }
68 }
69 $html .= '</div>';
70
71 }
72
73 return apply_filters('fluent_booking/location_icon_heading_html', $html, $details, $calendarEvent);
74
75 }
76
77 public static function getBookingLocationUrl(Booking $booking)
78 {
79 $details = $booking->location_details;
80
81 if (!$details || empty($details['type'])) {
82 return $booking->getConfirmationUrl();
83 }
84
85 if (!empty($details['online_platform_link'])) {
86 return Arr::get($details, 'online_platform_link');
87 }
88
89 return $booking->getConfirmationUrl();
90 }
91
92 public static function getLocationDetails($calendarEvent, $userInput = [], $allInput = [])
93 {
94 $locations = $calendarEvent->location_settings;
95
96 if (empty($locations)) {
97 return [
98 'type' => 'custom',
99 'description' => ''
100 ];
101 }
102
103 if (empty($allInput)) {
104 $locations = [$locations[0]];
105 }
106
107 if (count($locations) == 1) {
108 // return the first location
109 $defaultLocation = $locations[0];
110
111 $type = Arr::get($defaultLocation, 'type');
112
113 $userInput = [
114 'driver' => $type . '__:__0'
115 ];
116
117 if ($type == 'phone_guest') {
118 $userInput['user_location_input'] = sanitize_text_field(Arr::get($allInput, 'phone_number'));
119 } else if ($type == 'in_person_guest') {
120 $userInput['user_location_input'] = sanitize_textarea_field(Arr::get($allInput, 'address'));
121 }
122 }
123
124 $keyedLocations = [];
125 foreach ($locations as $index => $location) {
126 $keyedLocations[$location['type'] . '__:__' . $index] = $location;
127 }
128
129 $driver = sanitize_text_field(Arr::get($userInput, 'driver'));
130
131 if (empty($keyedLocations[$driver])) {
132 return [
133 'type' => 'custom',
134 'description' => ''
135 ];
136 }
137
138 $selectedLocation = $keyedLocations[$driver];
139
140 $selectedType = $selectedLocation['type'];
141
142 // custom user input location types
143 if ($selectedType === 'phone_guest') {
144 return [
145 'type' => $selectedType,
146 'description' => sanitize_text_field(Arr::get($userInput, 'user_location_input'))
147 ];
148 } else if ($selectedType === 'in_person_guest') {
149 return [
150 'type' => $selectedType,
151 'description' => sanitize_textarea_field(Arr::get($userInput, 'user_location_input'))
152 ];
153 }
154
155 // Check provided description location type to store as description
156 if (in_array($selectedType, ['custom', 'phone_organizer', 'in_person_organizer'])) {
157 $fieldMaps = [
158 'custom' => 'description',
159 'in_person_organizer' => 'description',
160 'phone_organizer' => 'host_phone_number'
161 ];
162
163 $key = $fieldMaps[$selectedType];
164
165 return [
166 'type' => $selectedType,
167 'description' => Arr::get($selectedLocation, $key)
168 ];
169 }
170
171 if ($selectedType == 'online_meeting') {
172 return [
173 'type' => $selectedType,
174 'online_platform_link' => Arr::get($selectedLocation, 'meeting_link')
175 ];
176 }
177
178 return [
179 'type' => $selectedType,
180 'description' => ''
181 ];
182 }
183
184 public static function getLocationsConfig()
185 {
186 return [];
187 }
188
189 public static function getLocationOptions($calendarEvent, $keyed = false)
190 {
191 $locationSettings = $calendarEvent->location_settings;
192
193 $locationOptions = [];
194 foreach ($locationSettings as $index => $location) {
195 $title = Arr::get($location, 'title');
196
197 $locationType = (string) Arr::get($location, 'type', '');
198
199 if ($locationType == 'custom') {
200 if (Arr::get($location, 'display_on_booking') == 'yes') {
201 $title = Arr::get($location, 'description');
202 } else {
203 $title = Arr::get($location, 'title');
204 }
205 }
206
207 if (!$title) {
208 $title = $locationType === '' ? '' : str_replace('_', ' ', ucfirst($locationType));
209 }
210
211 $slug = Arr::get($location, 'type') . '__:__' . $index;
212
213 if ($keyed) {
214 $locationOptions[$slug] = [
215 'type' => Arr::get($location, 'type'),
216 'title' => $title,
217 'slug' => $slug
218 ];
219 } else {
220 $locationOptions[] = [
221 'type' => Arr::get($location, 'type'),
222 'title' => $title,
223 'slug' => $slug
224 ];
225 }
226 }
227 return $locationOptions;
228 }
229 }
230