PluginProbe
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution / 1.5.23
Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution v1.5.23
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 / FluentCrmInit.php

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

155 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 $app = fluentCrm();
103 $page = intval($app->request->get('page', 1));
104 $perPage = intval($app->request->get('per_page', 10));
105
106 $meetings = Booking::with(['slot', 'calendar'])
107 ->where('email', $subsriber->email)
108 ->distinct('group_id')
109 ->orderBy('start_time', 'DESC')
110 ->paginate();
111
112 $formattedMeetings = [];
113
114 foreach ($meetings->items() as $meeting) {
115 if (!$meeting->calendar || !$meeting->slot) {
116 continue;
117 }
118
119 $formattedMeetings[] = [
120 'id' => '#' . $meeting->group_id,
121 'title' => $this->getBookingTitle($meeting),
122 'status' => $meeting->status,
123 'meeting_at' => $this->getFormattedTime($meeting),
124 'action' => $this->getActionUrl($meeting)
125 ];
126 }
127
128 return [
129 'total' => $meetings->total(),
130 'data' => $formattedMeetings,
131 'columns_config' => [
132 'id' => [
133 'label' => __('ID', 'fluent-booking'),
134 'width' => '100px'
135 ],
136 'title' => [
137 'label' => __('Event', 'fluent-booking'),
138 ],
139 'status' => [
140 'label' => __('Status', 'fluent-booking'),
141 'width' => '150px'
142 ],
143 'meeting_at' => [
144 'label' => __('Meeting At', 'fluent-booking'),
145 'width' => '200px'
146 ],
147 'action' => [
148 'label' => __('Action', 'fluent-booking'),
149 'width' => '100px'
150 ]
151 ]
152 ];
153 }
154 }
155