PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 2.2.1
Fluent Support – Helpdesk & Customer Support Ticket System v2.2.1
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 2.2.1, at app/Services/Integrations/FluentCrm/FluentCRMWidgets.php

136 lines 4.2 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 return false;
73 }
74
75 $subscriber = Subscriber::where('email', $email)->first();
76
77 $customerData = array_filter([
78 'first_name' => $customer->first_name,
79 'last_name' => $customer->last_name,
80 'email' => $customer->email,
81 'address_line_1' => $customer->address_line_1,
82 'address_line_2' => $customer->address_line_2,
83 'postal_code' => $customer->zip,
84 'city' => $customer->city,
85 'state' => $customer->state,
86 'country' => $customer->country,
87 ]);
88
89
90 if ($subscriber) {
91 unset($customerData['email']);
92 $subscriber->fill($customerData);
93 $subscriber->save();
94 } else {
95 $customerData['status'] = $syncSettings['default_status'];
96 $subscriber = FluentCrmApi('contacts')->createOrUpdate($customerData);
97
98 if (!$subscriber) {
99 return false;
100 }
101
102 if ($customerData['status'] == 'pending' && $subscriber->status == 'pending') {
103 $subscriber->sendDoubleOptinEmail();
104 }
105 }
106
107 if ($syncSettings['assigned_list']) {
108 $subscriber->attachLists([$syncSettings['assigned_list']]);
109 }
110
111 if ($syncSettings['assigned_tags']) {
112 $subscriber->attachTags($syncSettings['assigned_tags']);
113 }
114
115 return true;
116 }
117
118 private function getSyncSettings()
119 {
120 $settings = Helper::getOption('_fluentcrm_intergration_settings');
121
122 $settingDefault = [
123 'enabled' => 'no',
124 'default_status' => 'subscribed',
125 'assigned_list' => '',
126 'assigned_tags' => []
127 ];
128
129 if (!$settings) {
130 return $settingDefault;
131 }
132
133 return wp_parse_args($settings, $settingDefault);
134 }
135 }
136