| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentBooking\App\Services\Integrations\FluentCRM; |
| 4 |
|
| 5 |
use FluentBooking\App\Models\Booking; |
| 6 |
use FluentBooking\App\Services\EditorShortCodeParser; |
| 7 |
use FluentCrm\App\Models\FunnelSubscriber; |
| 8 |
|
| 9 |
class CrmSmartCode |
| 10 |
{ |
| 11 |
public function register() |
| 12 |
{ |
| 13 |
add_filter('fluent_crm_funnel_context_smart_codes', array($this, 'pushContextCodes'), 10, 2); |
| 14 |
add_filter('fluent_crm/smartcode_group_callback_fcal', array($this, 'parseBookingData'), 10, 4); |
| 15 |
} |
| 16 |
|
| 17 |
public function pushContextCodes($codes, $context) |
| 18 |
{ |
| 19 |
|
| 20 |
$triggers = [ |
| 21 |
'fluent_booking/after_booking_scheduled', |
| 22 |
'fluent_booking/booking_schedule_cancelled', |
| 23 |
'fluent_booking/booking_schedule_completed' |
| 24 |
]; |
| 25 |
|
| 26 |
if (!in_array($context, $triggers)) { |
| 27 |
return $codes; |
| 28 |
} |
| 29 |
|
| 30 |
$codes[] = [ |
| 31 |
'key' => 'fcal', |
| 32 |
'title' => 'Booking Data', |
| 33 |
'shortcodes' => $this->getSmartCodes() |
| 34 |
]; |
| 35 |
|
| 36 |
return $codes; |
| 37 |
} |
| 38 |
|
| 39 |
public function parseBookingData($code, $valueKey, $defaultValue, $subscriber) |
| 40 |
{ |
| 41 |
$booking = $this->getBooking($subscriber); |
| 42 |
|
| 43 |
if (!$booking) { |
| 44 |
$booking = Booking::where('email', $subscriber->email)->orderBy('id', 'desc')->first(); |
| 45 |
} |
| 46 |
|
| 47 |
if (!$booking) { |
| 48 |
return $defaultValue; |
| 49 |
} |
| 50 |
|
| 51 |
$value = EditorShortCodeParser::parse('{{' . $valueKey . '}}', $booking, true); |
| 52 |
|
| 53 |
if (!$value) { |
| 54 |
return $defaultValue; |
| 55 |
} |
| 56 |
|
| 57 |
return $value; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
private function getBooking($subscriber) |
| 62 |
{ |
| 63 |
if (empty($subscriber->funnel_subscriber_id)) { |
| 64 |
return null; |
| 65 |
} |
| 66 |
|
| 67 |
$funnelSub = FunnelSubscriber::where('id', $subscriber->funnel_subscriber_id)->first(); |
| 68 |
|
| 69 |
if (!$funnelSub) { |
| 70 |
return null; |
| 71 |
} |
| 72 |
|
| 73 |
return Booking::where('id', $funnelSub->source_ref_id)->first(); |
| 74 |
} |
| 75 |
|
| 76 |
private function getSmartCodes() |
| 77 |
{ |
| 78 |
return [ |
| 79 |
'{{fcal.guest.first_name}}' => __('Guest First Name', 'fluent-booking'), |
| 80 |
'{{fcal.guest.last_name}}' => __('Guest Last Name', 'fluent-booking'), |
| 81 |
'{{fcal.guest.full_name}}' => __('Guest Full Name', 'fluent-booking'), |
| 82 |
'{{fcal.guest.email}}' => __('Guest Email', 'fluent-booking'), |
| 83 |
'{{fcal.booking.phone}}' => __('Guest Main Phone Number (if provided)', 'fluent-booking'), |
| 84 |
'{{fcal.guest.note}}' => __('Guest Note', 'fluent-booking'), |
| 85 |
'{{fcal.guest.timezone}}' => __('Guest Timezone', 'fluent-booking'), |
| 86 |
'{{fcal.guest.form_data_html}}' => __('Guest Form Submitted Data (HTML)', 'fluent-booking'), |
| 87 |
'{{fcal.booking.event_name}}' => __('Event Name', 'fluent-booking'), |
| 88 |
'{{fcal.booking.description}}' => __('Event Description', 'fluent-booking'), |
| 89 |
'{{fcal.booking.full_start_end_guest_timezone}}' => __('Full Start & End Time (with guest timezone)', 'fluent-booking'), |
| 90 |
'{{fcal.booking.full_start_end_host_timezone}}' => __('Full Start & End Time (with host timezone)', 'fluent-booking'), |
| 91 |
'{{fcal.booking.start_date_time}}' => __('Event Date Time (UTC)', 'fluent-booking'), |
| 92 |
'{{fcal.booking.start_date_time_for_attendee}}' => __('Event Date time (with guest timezone)', 'fluent-booking'), |
| 93 |
'{{fcal.booking.start_date_time_for_host}}' => __('Event Date time (with host timezone)', 'fluent-booking'), |
| 94 |
'{{fcal.booking.location_details_html}}' => __('Event Location Details (HTML)', 'fluent-booking'), |
| 95 |
'{{fcal.booking.cancel_reason}}' => __('Event Cancel Reason', 'fluent-booking'), |
| 96 |
'{{fcal.booking.start_time_human_format}}' => __('Event Start Time (ex: 2 hours from now)', 'fluent-booking'), |
| 97 |
'##fcal.booking.cancelation_url##' => __('Booking Cancellation URL', 'fluent-booking'), |
| 98 |
'##fcal.booking.reschedule_url##' => __('Booking Reschedule URL', 'fluent-booking'), |
| 99 |
'##fcal.booking.admin_booking_url##' => __('Booking Details Admin URL', 'fluent-booking'), |
| 100 |
'{{fcal.booking.booking_hash}}' => __('Unique Booking Hash', 'fluent-booking'), |
| 101 |
'{{fcal.booking.reschedule_reason}}' => __('Event Reschedule Reason', 'fluent-booking'), |
| 102 |
'{{fcal.host.name}}' => __('Host Name', 'fluent-booking'), |
| 103 |
'{{fcal.host.email}}' => __('Host Email', 'fluent-booking'), |
| 104 |
'{{fcal.host.timezone}}' => __('Host Timezone', 'fluent-booking'), |
| 105 |
'{{fcal.event.id}}' => __('Event ID', 'fluent-booking'), |
| 106 |
'{{fcal.event.calendar_id}}' => __('Calendar ID', 'fluent-booking'), |
| 107 |
'{{fcal.calendar.title}}' => __('Calendar Title', 'fluent-booking'), |
| 108 |
'{{fcal.calendar.description}}' => __('Calendar Description', 'fluent-booking') |
| 109 |
]; |
| 110 |
} |
| 111 |
} |
| 112 |
|