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