PluginProbe ʕ •ᴥ•ʔ
OttoKit: All-in-One Automation Platform / 1.1.33
OttoKit: All-in-One Automation Platform v1.1.33
1.1.33 1.1.32 1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.47 1.0.48 1.0.49 1.0.50 1.0.51 1.0.52 1.0.53 1.0.54 1.0.55 1.0.56 1.0.57 1.0.58 1.0.59 1.0.60 1.0.61 1.0.62 1.0.63 1.0.64 1.0.65 1.0.66 1.0.67 1.0.68 1.0.69 1.0.7 1.0.70 1.0.71 1.0.72 1.0.73 1.0.74 1.0.75 1.0.76 1.0.77 1.0.78 1.0.79 1.0.8 1.0.80 1.0.81 1.0.82 1.0.83 1.0.84 1.0.85 1.0.86 1.0.87 1.0.88 1.0.89 1.0.9 1.0.90 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.20 1.1.21 1.1.22 1.1.23 1.1.24 1.1.25 1.1.26 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8
suretriggers / src / Integrations / support-genix / support-genix.php
suretriggers / src / Integrations / support-genix Last commit date
actions 2 months ago triggers 2 months ago support-genix.php 2 months ago
support-genix.php
217 lines
1 <?php
2 /**
3 * Support Genix core integration file.
4 *
5 * @since 1.0.0
6 * @package SureTrigger
7 */
8
9 namespace SureTriggers\Integrations\SupportGenix;
10
11 use SureTriggers\Controllers\IntegrationsController;
12 use SureTriggers\Integrations\Integrations;
13 use SureTriggers\Traits\SingletonLoader;
14
15 /**
16 * Class SupportGenix
17 *
18 * @package SureTriggers\Integrations\SupportGenix
19 */
20 class SupportGenix extends Integrations {
21
22 use SingletonLoader;
23
24 /**
25 * ID
26 *
27 * @var string
28 */
29 protected $id = 'SupportGenix';
30
31 /**
32 * Status code → label map used by Mapbd_wps_ticket::GetPropertyRawOptions.
33 *
34 * @var array<string, string>
35 */
36 protected static $status_labels = [
37 'N' => 'New',
38 'C' => 'Closed',
39 'P' => 'In-progress',
40 'R' => 'Re-open',
41 'A' => 'Active',
42 'I' => 'Inactive',
43 'D' => 'Deleted',
44 ];
45
46 /**
47 * Priority code → label map.
48 *
49 * @var array<string, string>
50 */
51 protected static $priority_labels = [
52 'N' => 'Normal',
53 'M' => 'Medium',
54 'H' => 'High',
55 ];
56
57 /**
58 * User type code → label map.
59 *
60 * @var array<string, string>
61 */
62 protected static $user_type_labels = [
63 'A' => 'Agent',
64 'U' => 'User',
65 'G' => 'Guest',
66 ];
67
68 /**
69 * SureTrigger constructor.
70 */
71 public function __construct() {
72 $this->name = __( 'Support Genix', 'suretriggers' );
73 $this->description = __( 'Support Genix is a WordPress helpdesk and support ticketing plugin.', 'suretriggers' );
74 $this->icon_url = SURE_TRIGGERS_URL . 'assets/icons/supportgenix.svg';
75
76 parent::__construct();
77 }
78
79 /**
80 * Is plugin dependency installed or not.
81 *
82 * @return bool
83 */
84 public function is_plugin_installed() {
85 return defined( 'SUPPORT_GENIX_LITE_VERSION' )
86 || defined( 'SUPPORT_GENIX_VERSION' )
87 || class_exists( 'Mapbd_wps_ticket' );
88 }
89
90 /**
91 * Flatten a Mapbd_wps_ticket (or similar) object into an associative array
92 * with human readable status / priority / user type labels appended.
93 *
94 * @param object|array $ticket Ticket model or array.
95 * @return array
96 */
97 public static function prepare_ticket_context( $ticket ) {
98 $data = self::object_to_array( $ticket );
99
100 if ( ! is_array( $data ) ) {
101 return [];
102 }
103
104 if ( isset( $data['status'] ) && isset( self::$status_labels[ $data['status'] ] ) ) {
105 $data['status_label'] = self::$status_labels[ $data['status'] ];
106 }
107
108 if ( isset( $data['priority'] ) && isset( self::$priority_labels[ $data['priority'] ] ) ) {
109 $data['priority_label'] = self::$priority_labels[ $data['priority'] ];
110 }
111
112 if ( isset( $data['user_type'] ) && isset( self::$user_type_labels[ $data['user_type'] ] ) ) {
113 $data['user_type_label'] = self::$user_type_labels[ $data['user_type'] ];
114 }
115
116 $ticket_user_id = isset( $data['ticket_user'] ) ? (int) $data['ticket_user'] : 0;
117 if ( $ticket_user_id > 0 ) {
118 $user = get_userdata( $ticket_user_id );
119 if ( $user ) {
120 $data['ticket_user_email'] = $user->user_email;
121 $data['ticket_user_name'] = $user->display_name;
122 $data['ticket_user_login'] = $user->user_login;
123 }
124 }
125
126 return $data;
127 }
128
129 /**
130 * Flatten a reply object.
131 *
132 * @param object|array $reply Reply object.
133 * @return array
134 */
135 public static function prepare_reply_context( $reply ) {
136 $data = self::object_to_array( $reply );
137
138 if ( ! is_array( $data ) ) {
139 return [];
140 }
141
142 if ( isset( $data['replied_by_type'] ) && isset( self::$user_type_labels[ $data['replied_by_type'] ] ) ) {
143 $data['replied_by_type_label'] = self::$user_type_labels[ $data['replied_by_type'] ];
144 }
145
146 if ( isset( $data['ticket_status'] ) && isset( self::$status_labels[ $data['ticket_status'] ] ) ) {
147 $data['ticket_status_label'] = self::$status_labels[ $data['ticket_status'] ];
148 }
149
150 $replied_by = isset( $data['replied_by'] ) ? (int) $data['replied_by'] : 0;
151 if ( $replied_by > 0 && isset( $data['replied_by_type'] ) && 'G' !== $data['replied_by_type'] ) {
152 $user = get_userdata( $replied_by );
153 if ( $user ) {
154 $data['replied_by_email'] = $user->user_email;
155 $data['replied_by_name'] = $user->display_name;
156 }
157 }
158
159 return $data;
160 }
161
162 /**
163 * Resolve an agent user id for making replies. Falls back to the first
164 * administrator if the requested user isn't available.
165 *
166 * @param int $agent_id Requested agent id.
167 * @return int
168 */
169 public static function resolve_agent_id( $agent_id ) {
170 $agent_id = (int) $agent_id;
171 if ( $agent_id > 0 && get_userdata( $agent_id ) ) {
172 return $agent_id;
173 }
174
175 $admins = get_users(
176 [
177 'role' => 'administrator',
178 'number' => 1,
179 'fields' => 'ID',
180 ]
181 );
182
183 return ! empty( $admins ) ? (int) $admins[0] : 0;
184 }
185
186 /**
187 * Safely cast an object / model to array.
188 *
189 * @param object|array $value Value to cast.
190 * @return array
191 */
192 protected static function object_to_array( $value ) {
193 if ( is_array( $value ) ) {
194 return $value;
195 }
196
197 if ( is_object( $value ) ) {
198 if ( method_exists( $value, 'toArray' ) ) {
199 $maybe = $value->toArray();
200 if ( is_array( $maybe ) ) {
201 return $maybe;
202 }
203 }
204
205 $vars = get_object_vars( $value );
206 if ( is_array( $vars ) ) {
207 return $vars;
208 }
209 }
210
211 return [];
212 }
213
214 }
215
216 IntegrationsController::register( SupportGenix::class );
217