PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.10.3
Fluent Support – Helpdesk & Customer Support Ticket System v1.10.3
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 / ProfileInfoService.php

ProfileInfoService.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.10.3, at app/Services/ProfileInfoService.php

106 lines 3.0 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;
4
5 use FluentSupport\App\Models\Customer;
6 use FluentSupport\App\Models\Product;
7 use FluentSupport\App\Modules\PermissionManager;
8 use FluentSupport\App\Services\EmailNotification\Settings;
9
10 class ProfileInfoService
11 {
12 public static function getProfileExtraWidgets( $customer )
13 {
14 $widgets = [];
15 /*
16 * Filter customer profile widgets
17 *
18 * @since v1.0.0
19 * @param array $widgets
20 * @param object|array $customer
21 *
22 * @return void
23 */
24 $widgets = apply_filters('fluent_support/customer_extra_widgets', $widgets, $customer);
25 return $widgets;
26 }
27
28 // This method is linked with 'profile_update' action & it will trigger when user update profile
29 public function onWPProfileUpdate( $userId, $userOldData, $userUpdatedData )
30 {
31 if ( !$userId ) {
32 return false;
33 }
34
35 $customer = Customer::where( 'user_id', $userId );
36
37 if ( $customer->count() == 0 ) {
38 return false;
39 }
40
41 $keys = ['first_name', 'last_name', 'user_email'];
42 $data = [];
43
44 if( !array_diff_key( array_flip($keys), $userUpdatedData ) ) {
45 $data = [
46 'first_name' => $userUpdatedData['first_name'],
47 'last_name' => $userUpdatedData['last_name'],
48 'email' => $userUpdatedData['user_email'],
49 ];
50 };
51
52 if ( count($data) > 0 ) {
53 $customer->update($data);
54 }
55
56 }
57
58
59 /**
60 * This `me` method will return the current user profile info
61 * @param array $settings
62 * @param arrau withPortalSettings
63 * @return array $settings
64 */
65 public function me( $settings, $withPortalSettings )
66 {
67 if ( $withPortalSettings ) {
68 $this->portalSettings( $settings );
69 }
70
71 return $settings;
72 }
73
74 /**
75 * This `portalSettings` method is supporting the `me` method
76 * @param array $settings
77 * @return array $settings
78 */
79 private function portalSettings ( $settings )
80 {
81 $mimeHeadings = Helper::getAcceptedMimeHeadings();
82 $businessSettings = (new Settings())->globalBusinessSettings();
83 $maxFileSize = absint($businessSettings['max_file_size']);
84
85 $portalSettings = [
86 'support_products' => Product::select(['id', 'title'])->get(),
87 'customer_ticket_priorities' => Helper::customerTicketPriorities(),
88 'has_file_upload' => !!Helper::ticketAcceptedFileMiles(),
89 'has_rich_text_editor' => true,
90 'max_file_size' => $maxFileSize,
91 'mime_headings' => $mimeHeadings
92 ];
93 /**
94 * Filter customer portal settings
95 *
96 * @since v1.0.0
97 * @param array $portalSettings
98 */
99 $portalSettings = apply_filters('fluent_support/customer_portal_vars', $portalSettings);
100
101 $settings['portal_settings'] = $portalSettings;
102
103 return $settings;
104 }
105 }
106