PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.10.0
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.10.0
2.5.0 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 All 34 releases
fluent-booking / app / Services / Integrations / FluentCRM / FluentCrmInit.php

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

151 lines 4.5 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\App\Models\Booking;
6 use FluentBooking\App\Services\DateTimeHelper;
7
8 class FluentCrmInit
9 {
10 public function __construct()
11 {
12 $this->registerHooks();
13 $this->registerIntegrations();
14
15 // Contextual SmartCodes
16 (new CrmSmartCode())->register();
17
18 add_filter('fluent_crm_asset_listed_slugs', function ($lists) {
19 $lists[] = 'fluent-booking';
20 return $lists;
21 });
22 }
23
24 /**
25 * Register all the CRM integrations from here
26 * @return void
27 */
28 public function registerIntegrations()
29 {
30 $this->addContactMenuSection();
31 $this->addAutomations();
32 }
33
34 public function registerHooks()
35 {
36 add_filter('fluentcrm_profile_sections', [$this, 'addProfileSection'], 10, 1);
37 add_filter('fluentcrm_get_form_submissions_fluent_booking', [$this, 'getScheduledMeetings'], 10, 2);
38 }
39
40 /**
41 * load Assets for to Fluent CRM contact section
42 * @return void
43 */
44 public function addContactMenuSection()
45 {
46 add_action('fluent_crm/global_appjs_loaded', function () {
47 wp_enqueue_script('fluent_booking_in_crm', FLUENT_BOOKING_URL . 'assets/admin/fluent-crm-in-calendar.js', [], FLUENT_BOOKING_ASSETS_VERSION, true);
48 });
49 }
50
51 public function addAutomations()
52 {
53 new NewBookingTrigger();
54 new CancelBookingTrigger();
55 new BookingCompletedTrigger();
56 new BookingRescheduledTrigger();
57 }
58
59 private function getSubscriberId($email)
60 {
61 $contact = FluentCrmApi('contacts')->getContact($email);
62 return $contact ? $contact->id : null;
63 }
64
65 public function addProfileSection($sections)
66 {
67 $sections['booking'] = [
68 'name' => 'booking',
69 'title' => __('Bookings', 'fluent-booking'),
70 'handler' => 'route'
71 ];
72
73 return $sections;
74 }
75
76 private function getActionUrl($meeting)
77 {
78 $url = admin_url('admin.php?page=fluent-booking#/scheduled-events?booking_id=' . $meeting->id);
79
80 $link = '<a target="_blank" href="' . esc_url($url) . '">' . 'view' . '</a>';
81
82 return $link;
83 }
84
85 private function getFormattedTime($meeting)
86 {
87 $formattedTime = DateTimeHelper::convertToTimeZone($meeting->start_time, 'utc', $meeting->calendar->author_timezone, 'j M Y, g:i A');
88
89 return $formattedTime;
90 }
91
92 private function getBookingTitle($meeting)
93 {
94 $host = $meeting->calendar->getAuthorProfile();
95 $title = $meeting->slot->title . ' with ' . $host['name'];
96
97 return $title;
98 }
99
100 public function getScheduledMeetings($data, $subsriber)
101 {
102 $meetings = Booking::with(['slot', 'calendar'])
103 ->where('email', $subsriber->email)
104 ->distinct('group_id')
105 ->orderBy('start_time', 'DESC')
106 ->paginate();
107
108 $formattedMeetings = [];
109
110 foreach ($meetings->items() as $meeting) {
111 if (!$meeting->calendar || !$meeting->slot) {
112 continue;
113 }
114
115 $formattedMeetings[] = apply_filters('fluent_booking/crm_meeting_data', [
116 'id' => '#' . $meeting->group_id,
117 'title' => $this->getBookingTitle($meeting),
118 'status' => $meeting->status,
119 'meeting_at' => $this->getFormattedTime($meeting),
120 'action' => $this->getActionUrl($meeting)
121 ], $meeting);
122 }
123
124 return apply_filters('fluent_booking/crm_meetings_response', [
125 'total' => $meetings->total(),
126 'data' => $formattedMeetings,
127 'columns_config' => [
128 'id' => [
129 'label' => __('ID', 'fluent-booking'),
130 'width' => '100px'
131 ],
132 'title' => [
133 'label' => __('Event', 'fluent-booking'),
134 ],
135 'status' => [
136 'label' => __('Status', 'fluent-booking'),
137 'width' => '150px'
138 ],
139 'meeting_at' => [
140 'label' => __('Meeting At', 'fluent-booking'),
141 'width' => '200px'
142 ],
143 'action' => [
144 'label' => __('Action', 'fluent-booking'),
145 'width' => '100px'
146 ]
147 ]
148 ], $meetings, $subsriber);
149 }
150 }
151