PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.10.2
Fluent Support – Helpdesk & Customer Support Ticket System v1.10.2
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Services / Integrations / FluentCrm / FluentCRMWidgets.php

FluentCRMWidgets.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.10.2, at app/Services/Integrations/FluentCrm/FluentCRMWidgets.php

137 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Services\Integrations\FluentCrm;
4
5 use FluentCrm\App\Models\Subscriber;
6 use FluentSupport\App\Models\Customer;
7 use FluentSupport\App\Models\Ticket;
8 use FluentSupport\App\Services\Helper;
9
10 class FluentCRMWidgets
11 {
12 public function boot()
13 {
14 add_action('fluent_support/customer_created', array($this, 'maybeCreateContact'), 10, 1);
15 add_filter('fluentcrm-support_tickets_providers', array($this, 'pushProvider'));
16 add_filter('fluentcrm-get_support_tickets_fluent_support', array($this, 'getSupportTickets'), 10, 2);
17
18 new CreateTicketAction();
19 }
20
21 public function pushProvider($providers)
22 {
23 $providers['fluent_support'] = [
24 'title' => __('Support Tickets by Fluent Support', 'fluent-support'),
25 'name' => __('Fluent Support', 'fluent-support')
26 ];
27
28 return $providers;
29 }
30
31 public function getSupportTickets($data, $subscriber)
32 {
33 $supportPerson = Customer::where('email', $subscriber->email)->first();
34
35 if (!$supportPerson) {
36 return $data;
37 }
38
39 $tickets = Ticket::where('customer_id', $supportPerson->id)
40 ->latest('id')
41 ->paginate();
42
43 $formattedTickets = [];
44 foreach ($tickets as $ticket) {
45 $ticketUrl = Helper::getPortalAdminBaseUrl() . 'tickets/' . $ticket->id . '/view';
46 $actionHTML = '<a target="_blank" href="' . $ticketUrl . '">' . __('View Ticket', 'fluent-support') . '</a>';
47 $formattedTickets[] = [
48 'id' => '#' . $ticket->id,
49 'title' => $ticket->title,
50 'status' => '<span class="el-tag">' . $ticket->status . '</span>',
51 'Submitted at' => human_time_diff(strtotime($ticket->created_at), current_time('timestamp')) . __(' ago', 'fluent-support'),
52 'action' => $actionHTML
53 ];
54 }
55
56 return [
57 'total' => $tickets->total(),
58 'data' => $formattedTickets
59 ];
60 }
61
62 public function maybeCreateContact($customer)
63 {
64 $syncSettings = $this->getSyncSettings();
65 if ($syncSettings['enabled'] != 'yes') {
66 return false;
67 }
68
69 $email = $customer->email;
70
71 if (!class_exists('\FluentCrm\App\Models\Subscriber')) {
72 error_log('FluentCRM: Subscriber class not found.');
73 return false;
74 }
75
76 $subscriber = Subscriber::where('email', $email)->first();
77
78 $customerData = array_filter([
79 'first_name' => $customer->first_name,
80 'last_name' => $customer->last_name,
81 'email' => $customer->email,
82 'address_line_1' => $customer->address_line_1,
83 'address_line_2' => $customer->address_line_2,
84 'postal_code' => $customer->zip,
85 'city' => $customer->city,
86 'state' => $customer->state,
87 'country' => $customer->country,
88 ]);
89
90
91 if ($subscriber) {
92 unset($customerData['email']);
93 $subscriber->fill($customerData);
94 $subscriber->save();
95 } else {
96 $customerData['status'] = $syncSettings['default_status'];
97 $subscriber = FluentCrmApi('contacts')->createOrUpdate($customerData);
98
99 if (!$subscriber) {
100 return false;
101 }
102
103 if ($customerData['status'] == 'pending' && $subscriber->status == 'pending') {
104 $subscriber->sendDoubleOptinEmail();
105 }
106 }
107
108 if ($syncSettings['assigned_list']) {
109 $subscriber->attachLists([$syncSettings['assigned_list']]);
110 }
111
112 if ($syncSettings['assigned_tags']) {
113 $subscriber->attachTags($syncSettings['assigned_tags']);
114 }
115
116 return true;
117 }
118
119 private function getSyncSettings()
120 {
121 $settings = Helper::getOption('_fluentcrm_intergration_settings');
122
123 $settingDefault = [
124 'enabled' => 'no',
125 'default_status' => 'subscribed',
126 'assigned_list' => '',
127 'assigned_tags' => []
128 ];
129
130 if (!$settings) {
131 return $settingDefault;
132 }
133
134 return wp_parse_args($settings, $settingDefault);
135 }
136 }
137