PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.2
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.2
3.5.4 3.5.3 3.5.2 3.5.1 3.4.9 3.5.0 3.4.8 3.4.7 trunk 2.3.1 3.3.6 3.3.7 3.3.8 3.3.9 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6
supportcandy / includes / custom-field-types / class-wpsc-df-last-reply-by.php

class-wpsc-df-last-reply-by.php in SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent 3.4.2, at includes/custom-field-types/class-wpsc-df-last-reply-by.php

449 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly!
4 }
5
6 if ( ! class_exists( 'WPSC_DF_Last_Reply_By' ) ) :
7
8 final class WPSC_DF_Last_Reply_By {
9
10 /**
11 * Slug for this custom field type
12 *
13 * @var string
14 */
15 public static $slug = 'df_last_reply_by';
16
17 /**
18 * Set whether this custom field type is of type date
19 *
20 * @var boolean
21 */
22 public static $is_date = false;
23
24 /**
25 * Set whether this custom field type has applicable to date range
26 *
27 * @var boolean
28 */
29 public static $has_date_range = false;
30
31 /**
32 * Set whether this custom field type has multiple values
33 *
34 * @var boolean
35 */
36 public static $has_multiple_val = false;
37
38 /**
39 * Data type for column created in tickets table
40 *
41 * @var string
42 */
43 public static $data_type = 'BIGINT NOT NULL';
44
45 /**
46 * Set whether this custom field type has reference to other class
47 *
48 * @var boolean
49 */
50 public static $has_ref = true;
51
52 /**
53 * Reference class for this custom field type so that its value(s) return with object or array of objects automatically. Empty string indicate no reference.
54 *
55 * @var string
56 */
57 public static $ref_class = 'wpsc_customer';
58
59 /**
60 * Set whether this custom field field type is system default (no fields can be created from it).
61 *
62 * @var boolean
63 */
64 public static $is_default = true;
65
66 /**
67 * Set whether this field type has extra information that can be used in ticket form, edit custom fields, etc.
68 *
69 * @var boolean
70 */
71 public static $has_extra_info = false;
72
73 /**
74 * Set whether this custom field type can accept personal info.
75 *
76 * @var boolean
77 */
78 public static $has_personal_info = false;
79
80 /**
81 * Set whether fields created from this custom field type is allowed in create ticket form
82 *
83 * @var boolean
84 */
85 public static $is_ctf = false;
86
87 /**
88 * Set whether fields created from this custom field type is allowed in ticket list
89 *
90 * @var boolean
91 */
92 public static $is_list = true;
93
94 /**
95 * Set whether fields created from this custom field type is allowed in ticket filter
96 *
97 * @var boolean
98 */
99 public static $is_filter = true;
100
101 /**
102 * Set whether fields created from this custom field type can be given character limits
103 *
104 * @var boolean
105 */
106 public static $has_char_limit = false;
107
108 /**
109 * Set whether fields created from this custom field type has custom options set in options table
110 *
111 * @var boolean
112 */
113 public static $has_options = false;
114
115 /**
116 * Set whether fields created from this custom field type can be auto-filled
117 *
118 * @var boolean
119 */
120 public static $is_auto_fill = false;
121
122 /**
123 * Set whether fields created from this custom field type can be available for ticket list sorting
124 *
125 * @var boolean
126 */
127 public static $is_sort = false;
128
129 /**
130 * Set whether fields created from this custom field type can have placeholder
131 *
132 * @var boolean
133 */
134 public static $is_placeholder = false;
135
136 /**
137 * Set whether fields created from this custom field type is applicable for visibility conditions in create ticket form
138 *
139 * @var boolean
140 */
141 public static $is_visibility_conditions = false;
142
143 /**
144 * Set whether fields created from this custom field type is applicable for macros
145 *
146 * @var boolean
147 */
148 public static $has_macro = true;
149
150 /**
151 * Set whether fields of this custom field type is applicalbe for search on ticket list page.
152 *
153 * @var boolean
154 */
155 public static $is_search = false;
156
157 /**
158 * Initialize the class
159 *
160 * @return void
161 */
162 public static function init() {
163
164 // Get object of this class.
165 add_filter( 'wpsc_load_ref_classes', array( __CLASS__, 'load_ref_class' ) );
166 }
167
168 /**
169 * Load current class to reference classes
170 *
171 * @param array $classes - Associative array of class names indexed by its slug.
172 * @return array
173 */
174 public static function load_ref_class( $classes ) {
175
176 $classes[ self::$slug ] = array(
177 'class' => __CLASS__,
178 'save-key' => 'id',
179 );
180 return $classes;
181 }
182
183 /**
184 * Print operators for ticket form filter
185 *
186 * @param WPSC_Custom_Field $cf - custom field object.
187 * @param array $filter - Existing filters (if any).
188 * @return void
189 */
190 public static function get_operators( $cf, $filter = array() ) {
191 ?>
192
193 <div class="item conditional">
194 <select class="operator" onchange="wpsc_tc_get_operand(this, '<?php echo esc_attr( $cf->slug ); ?>', '<?php echo esc_attr( wp_create_nonce( 'wpsc_tc_get_operand' ) ); ?>');">
195 <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
196 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
197 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'IN' ); ?> value="IN"><?php esc_attr_e( 'Matches', 'supportcandy' ); ?></option>
198 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'NOT IN' ); ?> value="NOT IN"><?php esc_attr_e( 'Not Matches', 'supportcandy' ); ?></option>
199 </select>
200 </div>
201 <?php
202 }
203
204 /**
205 * Print operators for ticket form filter
206 *
207 * @param string $operator - condition operator on which operands should be returned.
208 * @param WPSC_Custom_Field $cf - custom field object.
209 * @param array $filter - Exising functions (if any).
210 * @return void
211 */
212 public static function get_operands( $operator, $cf, $filter = array() ) {
213
214 $is_multiple = $operator !== '=' ? true : false;
215 $unique_id = uniqid( 'wpsc_' );
216 ?>
217 <div class="item conditional operand single">
218 <select class="operand_val_1 <?php echo esc_attr( $unique_id ); ?>" <?php echo $is_multiple ? 'multiple' : ''; ?>>
219 <?php
220
221 if ( $is_multiple && isset( $filter['operand_val_1'] ) ) {
222
223 foreach ( $filter['operand_val_1'] as $customer_id ) {
224 $customer = new WPSC_Customer( intval( $customer_id ) )
225 ?>
226 <option selected="selected" value="<?php echo esc_attr( $customer->id ); ?>"><?php echo esc_attr( $customer->name ); ?></option>
227 <?php
228 }
229 }
230
231 if ( ! $is_multiple && isset( $filter['operand_val_1'] ) ) {
232
233 $customer = new WPSC_Customer( intval( $filter['operand_val_1'] ) )
234 ?>
235 <option selected="selected" value="<?php echo esc_attr( $customer->id ); ?>"><?php echo esc_attr( $customer->name ); ?></option>
236 <?php
237 }
238 ?>
239
240 </select>
241 </div>
242 <script>
243 jQuery('.operand_val_1.<?php echo esc_attr( $unique_id ); ?>').selectWoo({
244 ajax: {
245 url: supportcandy.ajax_url,
246 dataType: 'json',
247 delay: 250,
248 data: function (params) {
249 return {
250 q: params.term, // search term
251 page: params.page,
252 action: 'wpsc_customer_filter_autocomplete',
253 _ajax_nonce: '<?php echo esc_attr( wp_create_nonce( 'wpsc_customer_filter_autocomplete' ) ); ?>'
254 };
255 },
256 processResults: function (data, params) {
257 var terms = [];
258 if ( data ) {
259 jQuery.each( data, function( id, text ) {
260 terms.push( { id: text.id, text: text.title } );
261 });
262 }
263 return {
264 results: terms
265 };
266 },
267 cache: true
268 },
269 escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
270 minimumInputLength: 1
271 });
272 </script>
273 <?php
274 }
275
276 /**
277 * Parse filter and return sql query to be merged in ticket model query builder
278 *
279 * @param WPSC_Custom_Field $cf - custom field of this type.
280 * @param mixed $compare - comparison operator.
281 * @param mixed $val - value to compare.
282 * @return string
283 */
284 public static function parse_filter( $cf, $compare, $val ) {
285
286 $str = '';
287
288 switch ( $compare ) {
289
290 case '=':
291 $str = 't.' . $cf->slug . '=\'' . esc_sql( $val ) . '\'';
292 break;
293
294 case 'IN':
295 $str = 't.' . $cf->slug . ' IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
296 break;
297
298 case 'NOT IN':
299 $str = 't.' . $cf->slug . ' NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
300 break;
301
302 default:
303 $str = '1=1';
304 }
305
306 return $str;
307 }
308
309 /**
310 * Check ticket condition
311 *
312 * @param array $condition - array with condition data.
313 * @param WPSC_Custom_Field $cf - custom field object.
314 * @param WPSC_Ticket $ticket - ticket object.
315 * @return boolean
316 */
317 public static function is_valid_ticket_condition( $condition, $cf, $ticket ) {
318
319 if ( ! is_object( $ticket->{$cf->slug} ) ) {
320 return false;
321 }
322
323 $flag = true;
324
325 switch ( $condition['operator'] ) {
326
327 case '=':
328 $flag = $ticket->{$cf->slug}->id == $condition['operand_val_1'] ? true : false;
329 break;
330
331 case 'IN':
332 $flag = in_array( $ticket->{$cf->slug}->id, $condition['operand_val_1'] );
333 break;
334
335 case 'NOT IN':
336 $flag = ! in_array( $ticket->{$cf->slug}->id, $condition['operand_val_1'] );
337 break;
338
339 default:
340 $flag = true;
341 }
342
343 return $flag;
344 }
345
346 /**
347 * Return val field for meta query of this type of custom field
348 *
349 * @param array $condition - condition data.
350 * @return mixed
351 */
352 public static function get_meta_value( $condition ) {
353
354 $operator = $condition['operator'];
355 switch ( $operator ) {
356
357 case '=':
358 case 'IN':
359 case 'NOT IN':
360 return $condition['operand_val_1'];
361 }
362 return false;
363 }
364
365 /**
366 * Print edit custom field properties
367 *
368 * @param WPSC_Custom_Fields $cf - custom field object.
369 * @param string $field_class - class name of field category.
370 * @return void
371 */
372 public static function get_edit_custom_field_properties( $cf, $field_class ) {
373
374 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) :
375 ?>
376 <div data-type="number" data-required="false" class="wpsc-input-group tl_width">
377 <div class="label-container">
378 <label for="">
379 <?php esc_attr_e( 'Ticket list width (pixels)', 'supportcandy' ); ?>
380 </label>
381 </div>
382 <input type="number" name="tl_width" value="<?php echo esc_attr( intval( $cf->tl_width ) ); ?>" autocomplete="off">
383 </div>
384 <?php
385 endif;
386 }
387
388 /**
389 * Set custom field properties. Can be used by add/edit custom field.
390 * Ignore phpcs nonce issue as we already checked where it is called from.
391 *
392 * @param WPSC_Custom_Field $cf - custom field object.
393 * @param string $field_class - class of field category.
394 * @return void
395 */
396 public static function set_cf_properties( $cf, $field_class ) {
397
398 // tl_width!
399 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) {
400 $tl_width = isset( $_POST['tl_width'] ) ? intval( $_POST['tl_width'] ) : 0; // phpcs:ignore
401 $cf->tl_width = $tl_width ? $tl_width : 100;
402 }
403
404 // save!
405 $cf->save();
406 }
407
408 /**
409 * Returns printable ticket value for custom field. Can be used in export tickets, replace macros etc.
410 *
411 * @param WPSC_Custom_Field $cf - custom field object.
412 * @param WPSC_Ticket $ticket - ticket object.
413 * @param string $module - module name.
414 * @return string
415 */
416 public static function get_ticket_field_val( $cf, $ticket, $module = '' ) {
417
418 $value = $ticket->last_reply_by->id ? esc_attr( $ticket->last_reply_by->name ) : '';
419 return apply_filters( 'wpsc_ticket_field_val_last_reply_by', $value, $cf, $ticket, $module );
420 }
421
422 /**
423 * Print ticket value for given custom field on ticket list
424 *
425 * @param WPSC_Custom_Field $cf - custom field object.
426 * @param WPSC_Ticket $ticket - ticket object.
427 * @return void
428 */
429 public static function print_tl_ticket_field_val( $cf, $ticket ) {
430
431 echo $ticket->last_reply_by->id ? esc_attr( $ticket->last_reply_by->name ) : '';
432 }
433
434 /**
435 * Print ticket value for given custom field on widget
436 *
437 * @param WPSC_Custom_Field $cf - custom field object.
438 * @param WPSC_Ticket $ticket - ticket object.
439 * @return void
440 */
441 public static function print_widget_ticket_field_val( $cf, $ticket ) {
442
443 self::print_tl_ticket_field_val( $cf, $ticket );
444 }
445 }
446 endif;
447
448 WPSC_DF_Last_Reply_By::init();
449