PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.4.4
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.4.4
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-status.php

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

761 lines 22.5 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_Status' ) ) :
7
8 final class WPSC_DF_Status {
9
10 /**
11 * Slug for this custom field type
12 *
13 * @var string
14 */
15 public static $slug = 'df_status';
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 = 'INT 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_status';
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 = true;
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 available for ticket list sorting
117 *
118 * @var boolean
119 */
120 public static $is_sort = true;
121
122 /**
123 * Set whether fields created from this custom field type can be auto-filled
124 *
125 * @var boolean
126 */
127 public static $is_auto_fill = 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 // ticket form.
168 add_filter( 'wpsc_create_ticket_data', array( __CLASS__, 'set_create_ticket_data' ), 10, 3 );
169
170 // create ticket data for rest api.
171 add_filter( 'wpsc_rest_create_ticket', array( __CLASS__, 'set_rest_ticket_data' ), 10, 3 );
172
173 // Ticket model.
174 add_filter( 'wpsc_ticket_joins', array( __CLASS__, 'ticket_join' ), 10, 2 );
175 add_filter( 'wpsc_archive_ticket_joins', array( __CLASS__, 'ticket_join' ), 10, 2 );
176
177 // Individual ticket.
178 add_action( 'wp_ajax_wpsc_it_close_ticket', array( __CLASS__, 'it_close_ticket' ) );
179 add_action( 'wp_ajax_nopriv_wpsc_it_close_ticket', array( __CLASS__, 'it_close_ticket' ) );
180 }
181
182 /**
183 * Load current class to reference classes
184 *
185 * @param array $classes - Associative array of class names indexed by its slug.
186 * @return array
187 */
188 public static function load_ref_class( $classes ) {
189
190 $classes[ self::$slug ] = array(
191 'class' => __CLASS__,
192 'save-key' => 'id',
193 );
194 return $classes;
195 }
196
197 /**
198 * Print operators for ticket form filter
199 *
200 * @param WPSC_Custom_Field $cf - custom field object.
201 * @param array $filter - Existing filters (if any).
202 * @return void
203 */
204 public static function get_operators( $cf, $filter = array() ) {
205 ?>
206
207 <div class="item conditional">
208 <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' ) ); ?>');">
209 <option value=""><?php esc_attr_e( 'Compare As', 'supportcandy' ); ?></option>
210 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], '=' ); ?> value="="><?php esc_attr_e( 'Equals', 'supportcandy' ); ?></option>
211 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'IN' ); ?> value="IN"><?php esc_attr_e( 'Matches', 'supportcandy' ); ?></option>
212 <option <?php isset( $filter['operator'] ) && selected( $filter['operator'], 'NOT IN' ); ?> value="NOT IN"><?php esc_attr_e( 'Not Matches', 'supportcandy' ); ?></option>
213 </select>
214 </div>
215 <?php
216 }
217
218 /**
219 * Check condition for this type
220 *
221 * @param array $condition - condition data.
222 * @param WPSC_Custom_Field $cf - custom field object.
223 * @param mixed $status - value to compare.
224 * @return boolean
225 */
226 public static function is_valid( $condition, $cf, $status ) {
227
228 $response = false;
229 switch ( $condition['operator'] ) {
230
231 case '=':
232 $response = $condition['operand_val_1'] == $status ? true : false;
233 break;
234
235 case 'IN':
236 $response = in_array( $status, $condition['operand_val_1'] ) ? true : false;
237 break;
238
239 case 'NOT IN':
240 $response = ! in_array( $status, $condition['operand_val_1'] ) ? true : false;
241 break;
242 }
243 return $response;
244 }
245
246 /**
247 * Print operators for ticket form filter
248 *
249 * @param string $operator - condition operator on which operands should be returned.
250 * @param WPSC_Custom_Field $cf - custom field object.
251 * @param array $filter - Exising functions (if any).
252 * @return void
253 */
254 public static function get_operands( $operator, $cf, $filter = array() ) {
255
256 $is_multiple = $operator !== '=' ? true : false;
257 $statuses = WPSC_Status::find( array( 'items_per_page' => 0 ) )['results'];
258 $unique_id = uniqid( 'wpsc_' );
259 ?>
260 <div class="item conditional operand single">
261 <select class="operand_val_1 <?php echo esc_attr( $unique_id ); ?>" <?php echo $is_multiple ? 'multiple' : ''; ?>>
262 <?php
263 foreach ( $statuses as $status ) {
264 $selected = '';
265 if ( isset( $filter['operand_val_1'] ) && ( ( $is_multiple && in_array( $status->id, $filter['operand_val_1'] ) ) || ( ! $is_multiple && $status->id == $filter['operand_val_1'] ) ) ) {
266 $selected = 'selected="selected"';
267 }
268 ?>
269 <option <?php echo esc_attr( $selected ); ?> value="<?php echo esc_attr( $status->id ); ?>"><?php echo esc_attr( $status->name ); ?></option>
270 <?php
271 }
272 ?>
273 </select>
274 </div>
275 <script>jQuery('.operand_val_1.<?php echo esc_attr( $unique_id ); ?>').selectWoo();</script>
276 <?php
277 }
278
279 /**
280 * Parse filter and return sql query to be merged in ticket model query builder
281 *
282 * @param WPSC_Custom_Field $cf - custom field of this type.
283 * @param mixed $compare - comparison operator.
284 * @param mixed $val - value to compare.
285 * @return string
286 */
287 public static function parse_filter( $cf, $compare, $val ) {
288
289 $str = '';
290
291 switch ( $compare ) {
292
293 case '=':
294 $str = 't.' . $cf->slug . '=\'' . esc_sql( $val ) . '\'';
295 break;
296
297 case 'IN':
298 $str = 't.' . $cf->slug . ' IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
299 break;
300
301 case 'NOT IN':
302 $str = 't.' . $cf->slug . ' NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
303 break;
304
305 default:
306 $str = '1=1';
307 }
308
309 return $str;
310 }
311
312 /**
313 * Check ticket condition
314 *
315 * @param array $condition - array with condition data.
316 * @param WPSC_Custom_Field $cf - custom field object.
317 * @param WPSC_Ticket $ticket - ticket object.
318 * @return boolean
319 */
320 public static function is_valid_ticket_condition( $condition, $cf, $ticket ) {
321
322 if ( ! is_object( $ticket->{$cf->slug} ) ) {
323 return false;
324 }
325
326 $flag = true;
327
328 switch ( $condition['operator'] ) {
329
330 case '=':
331 $flag = $ticket->{$cf->slug}->id == $condition['operand_val_1'] ? true : false;
332 break;
333
334 case 'IN':
335 $flag = in_array( $ticket->{$cf->slug}->id, $condition['operand_val_1'] );
336 break;
337
338 case 'NOT IN':
339 $flag = ! in_array( $ticket->{$cf->slug}->id, $condition['operand_val_1'] );
340 break;
341
342 default:
343 $flag = true;
344 }
345
346 return $flag;
347 }
348
349 /**
350 * Return default value for custom field of this type
351 *
352 * @param WPSC_Custom_Field $cf - custom field object.
353 * @return mixed
354 */
355 public static function get_default_value( $cf ) {
356
357 return $cf->default_value[0];
358 }
359
360 /**
361 * Check and return custom field value for new ticket to be created.
362 * This function is used by filter for set create ticket form and called directly by my-profile for each applicable custom fields.
363 * Ignore phpcs nonce issue as we already checked where it is called from.
364 *
365 * @param array $data - Array of values to to stored in ticket in an insert function.
366 * @param array $custom_fields - Array containing all applicable custom fields indexed by unique custom field types.
367 * @param boolean $is_my_profile - Whether it or not it is created from my-profile. This function is used by create ticket as well as my-profile. Due to customer fields handling is done same way, this flag gives apportunity to identify where it being called.
368 * @return array
369 */
370 public static function set_create_ticket_data( $data, $custom_fields, $is_my_profile ) {
371
372 $data['status'] = self::get_default_value( $custom_fields[ self::$slug ][0] );
373 return $data;
374 }
375
376 /**
377 * Set create ticket data for rest api request
378 *
379 * @param array $data - create ticket data array.
380 * @param WP_REST_Request $request - rest request object.
381 * @param array $custom_fields - custom field objects indexed by unique custom field types.
382 * @return array
383 */
384 public static function set_rest_ticket_data( $data, $request, $custom_fields ) {
385
386 $cf = WPSC_Custom_Field::get_cf_by_slug( 'status' );
387 $data['status'] = self::get_default_value( $cf );
388 return $data;
389 }
390
391 /**
392 * Add SQL joins to ticket model for this field type
393 *
394 * @param array $joins - array of join string that can be imploded later.
395 * @param array $filter - user filter.
396 * @return array
397 */
398 public static function ticket_join( $joins, $filter ) {
399
400 global $wpdb;
401 if ( $filter['orderby_slug'] == 'status' ) {
402 $joins[] = 'LEFT JOIN ' . $wpdb->prefix . 'psmsc_statuses st ON t.status = st.id';
403 }
404 return $joins;
405 }
406
407 /**
408 * Return val field for meta query of this type of custom field
409 *
410 * @param array $condition - condition data.
411 * @return mixed
412 */
413 public static function get_meta_value( $condition ) {
414
415 $operator = $condition['operator'];
416 switch ( $operator ) {
417
418 case '=':
419 case 'IN':
420 case 'NOT IN':
421 return $condition['operand_val_1'];
422 }
423 return false;
424 }
425
426 /**
427 * Close ticket
428 *
429 * @return void
430 */
431 public static function it_close_ticket() {
432
433 if ( check_ajax_referer( 'wpsc_it_close_ticket', '_ajax_nonce', false ) != 1 ) {
434 wp_send_json_error( 'Unauthorized request!', 401 );
435 }
436
437 WPSC_Individual_Ticket::load_current_ticket();
438 $current_user = WPSC_Current_User::$current_user;
439 $ticket = WPSC_Individual_Ticket::$ticket;
440
441 if ( ! $ticket->is_active ) {
442 wp_send_json_error( 'Unauthorized!', 401 );
443 }
444
445 $gs = get_option( 'wpsc-gs-general' );
446 $tl_advanced = get_option( 'wpsc-tl-ms-advanced' );
447
448 $close_flag = false;
449 if (
450 ( $current_user->customer->id == $ticket->customer->id && in_array( 'customer', $gs['allow-close-ticket'] ) ) ||
451 ( $current_user->is_agent && WPSC_Individual_Ticket::has_ticket_cap( 'cs' ) && in_array( $current_user->agent->role, $gs['allow-close-ticket'] ) )
452 ) {
453 $close_flag = true;
454 }
455
456 $close_flag = apply_filters( 'wpsc_it_action_close_flag', $close_flag, $ticket );
457
458 if ( ! (
459 $close_flag &&
460 ! (
461 $ticket->status->id == $gs['close-ticket-status'] ||
462 in_array( $ticket->status->id, $tl_advanced['closed-ticket-statuses'] )
463 )
464 ) ) {
465 wp_send_json_error( 'Unauthorized!', 401 );
466 }
467
468 WPSC_Individual_Ticket::change_status( $ticket->status->id, $gs['close-ticket-status'], $current_user->customer->id );
469 wp_die();
470 }
471
472 /**
473 * Return data for this custom field while creating duplicate ticket
474 *
475 * @param WPSC_Custom_Field $cf - custom field object.
476 * @param WPSC_Ticket $ticket - ticket object.
477 * @return mixed
478 */
479 public static function get_duplicate_ticket_data( $cf, $ticket ) {
480
481 return $cf->default_value[0];
482 }
483
484 /**
485 * Print generic input field for this type.
486 *
487 * @param WPSC_Custom_Field $cf - custom field object.
488 * @param WPSC_Status $value - optional. Input field will be printed with given value.
489 * @return void
490 */
491 public static function print_cf_input( $cf, $value ) {
492
493 if ( ! is_object( $value ) ) {
494
495 $status = $value ? new WPSC_Status( $value ) : 0;
496 if ( $status && $status->id ) {
497 $value = $status;
498 }
499 }
500
501 $statuses = WPSC_Status::find( array( 'items_per_page' => 0 ) )['results'];
502 $unique_id = uniqid( 'wpsc_' );
503 ?>
504 <div class="wpsc-tff wpsc-sm-12 wpsc-md-12 wpsc-lg-12 wpsc-visible wpsc-xs-12" data-cft="<?php echo esc_attr( self::$slug ); ?>">
505 <div class="wpsc-tff-label">
506 <span class="name"><?php echo esc_attr( $cf->name ); ?></span>
507 </div>
508 <?php
509 $extra_info = stripslashes( $cf->extra_info );
510 if ( $extra_info ) :
511 ?>
512 <span class="extra-info"><?php echo esc_attr( $cf->extra_info ); ?></span>
513 <?php
514 endif
515 ?>
516 <select class="<?php echo esc_attr( $unique_id ); ?>" name="<?php echo esc_attr( $cf->slug ); ?>">
517 <option value=""></option>
518 <?php
519 foreach ( $statuses as $status ) {
520 ?>
521 <option <?php $value && selected( $status->id, $value->id ); ?> value="<?php echo esc_attr( $status->id ); ?>"><?php echo esc_attr( $status->name ); ?></option>
522 <?php
523 }
524 ?>
525 </select>
526 <script>
527 jQuery('select.<?php echo esc_attr( $unique_id ); ?>').selectWoo({
528 allowClear: true,
529 placeholder: "<?php echo esc_attr( $cf->placeholder_text ); ?>"
530 });
531 </script>
532 </div>
533 <?php
534 }
535
536 /**
537 * Get value for generic field from post.
538 * Ignore phpcs nonce issue as we already checked where it is called from.
539 *
540 * @param WPSC_Custom_Field $cf - custom field object.
541 * @return string
542 */
543 public static function get_cf_input_val( $cf ) {
544
545 $value = isset( $_POST[ $cf->slug ] ) ? intval( $_POST[ $cf->slug ] ) : 0; // phpcs:ignore
546 $status = $value ? new WPSC_Status( $value ) : 0;
547 return $status && $status->id ? $value : '';
548 }
549
550 /**
551 * Print edit custom field properties
552 *
553 * @param WPSC_Custom_Fields $cf - custom field object.
554 * @param string $field_class - class name of field category.
555 * @return void
556 */
557 public static function get_edit_custom_field_properties( $cf, $field_class ) {
558
559 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) :
560 ?>
561 <div data-type="textfield" data-required="false" class="wpsc-input-group extra-info">
562 <div class="label-container">
563 <label for=""><?php esc_attr_e( 'Extra info', 'supportcandy' ); ?></label>
564 </div>
565 <input name="extra_info" type="text" value="<?php echo esc_attr( $cf->extra_info ); ?>" autocomplete="off" />
566 </div>
567 <?php
568 endif;
569
570 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) :
571 $default_val = $cf->default_value ? $cf->default_value[0] : '';
572 ?>
573 <div data-type="single-select" data-required="false" class="wpsc-input-group default_value">
574 <div class="label-container">
575 <label for="">
576 <?php esc_attr_e( 'Default value', 'supportcandy' ); ?>
577 <span class="required-char">*</span>
578 </label>
579 </div>
580 <select id="wpsc-default-ts" name="default_value">
581 <?php
582 $statuses = WPSC_Status::find( array( 'items_per_page' => 0 ) )['results'];
583 foreach ( $statuses as $status ) :
584 ?>
585 <option <?php selected( $status->id, $default_val ); ?> value="<?php echo esc_attr( $status->id ); ?>"><?php echo esc_attr( $status->name ); ?></option>
586 <?php
587 endforeach;
588 ?>
589 </select>
590 <script>
591 jQuery('#wpsc-default-ts').selectWoo({
592 allowClear: true,
593 placeholder: ""
594 });
595 </script>
596 </div>
597 <?php
598 endif;
599
600 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) :
601 ?>
602 <div data-type="number" data-required="false" class="wpsc-input-group tl_width">
603 <div class="label-container">
604 <label for="">
605 <?php esc_attr_e( 'Ticket list width (pixels)', 'supportcandy' ); ?>
606 </label>
607 </div>
608 <input type="number" name="tl_width" value="<?php echo intval( $cf->tl_width ); ?>" autocomplete="off">
609 </div>
610 <?php
611 endif;
612 }
613
614 /**
615 * Set custom field properties. Can be used by add/edit custom field.
616 * Ignore phpcs nonce issue as we already checked where it is called from.
617 *
618 * @param WPSC_Custom_Field $cf - custom field object.
619 * @param string $field_class - class of field category.
620 * @return void
621 */
622 public static function set_cf_properties( $cf, $field_class ) {
623
624 // extra info.
625 if ( in_array( 'extra_info', $field_class::$allowed_properties ) ) {
626 $cf->extra_info = isset( $_POST['extra_info'] ) ? sanitize_text_field( wp_unslash( $_POST['extra_info'] ) ) : ''; // phpcs:ignore
627 }
628
629 // default value.
630 if ( in_array( 'default_value', $field_class::$allowed_properties ) ) {
631 $default_value = isset( $_POST['default_value'] ) ? intval( $_POST['default_value'] ) : 0; // phpcs:ignore
632 if ( $default_value ) {
633 $cf->default_value = array( $default_value );
634 }
635 }
636
637 // tl_width!
638 if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) {
639 $tl_width = isset( $_POST['tl_width'] ) ? intval( $_POST['tl_width'] ) : 0; // phpcs:ignore
640 $cf->tl_width = $tl_width ? $tl_width : 100;
641 }
642
643 // save!
644 $cf->save();
645 }
646
647 /**
648 * Return orderby string
649 *
650 * @param WPSC_Custom_Field $cf - custom field object.
651 * @return string
652 */
653 public static function get_orderby_string( $cf ) {
654
655 $statuses = implode(
656 ',',
657 array_map(
658 fn( $status ) => $status->id,
659 WPSC_Status::find( array( 'items_per_page' => 0 ) )['results']
660 )
661 );
662 return 'FIELD( t.status, ' . $statuses . ' )';
663 }
664
665 /**
666 * Returns printable ticket value for custom field. Can be used in export tickets, replace macros etc.
667 *
668 * @param WPSC_Custom_Field $cf - custom field object.
669 * @param WPSC_Ticket $ticket - ticket object.
670 * @param string $module - module name.
671 * @return string
672 */
673 public static function get_ticket_field_val( $cf, $ticket, $module = '' ) {
674
675 return apply_filters( 'wpsc_ticket_field_val_status', $ticket->status->name, $cf, $ticket, $module );
676 }
677
678 /**
679 * Print ticket value for given custom field on ticket list
680 *
681 * @param WPSC_Custom_Field $cf - custom field object.
682 * @param WPSC_Ticket $ticket - ticket object.
683 * @return void
684 */
685 public static function print_tl_ticket_field_val( $cf, $ticket ) {
686
687 $status = $ticket->status;
688 ?>
689 <div class="wpsc-tag" style="background-color: <?php echo esc_attr( $status->bg_color ); ?>; color:<?php echo esc_attr( $status->color ); ?>;"><?php echo esc_attr( $status->name ); ?></div>
690 <?php
691 }
692
693 /**
694 * Print ticket value for given custom field on widget
695 *
696 * @param WPSC_Custom_Field $cf - custom field object.
697 * @param WPSC_Ticket $ticket - ticket object.
698 * @return void
699 */
700 public static function print_widget_ticket_field_val( $cf, $ticket ) {
701
702 self::print_tl_ticket_field_val( $cf, $ticket );
703 }
704
705 /**
706 * Print given value for custom field
707 *
708 * @param WPSC_Custom_Field $cf - custom field object.
709 * @param mixed $val - value to convert and print.
710 * @return void
711 */
712 public static function print_val( $cf, $val ) {
713
714 $status = is_object( $val ) ? $val : new WPSC_Status( $val );
715 if ( $status->id ) {
716 ?>
717 <div class="wpsc-tag" style="background-color: <?php echo esc_attr( $status->bg_color ); ?>; color:<?php echo esc_attr( $status->color ); ?>;"><?php echo esc_attr( $status->name ); ?></div>
718 <?php
719 } else {
720 esc_attr_e( 'None', 'supportcandy' );
721 }
722 }
723
724 /**
725 * Return printable value for history log macro
726 *
727 * @param WPSC_Custom_Field $cf - custom field object.
728 * @param mixed $val - value to convert and return.
729 * @return string
730 */
731 public static function get_history_log_val( $cf, $val ) {
732
733 $status = is_object( $val ) ? $val : new WPSC_Status( $val );
734 return $status->id ? $status->name : esc_attr__( 'None', 'supportcandy' );
735 }
736
737 /**
738 * Print dashboard activity function
739 *
740 * @param WPSC_Custom_Field $cf - custom field object.
741 * @param array $recent_logs - recent_logs object.
742 * @param array $body - body object.
743 * @param int $view - check if frontend.
744 * @return string
745 */
746 public static function print_activity( $cf, $recent_logs, $body, $view ) {
747
748 $url = WPSC_Functions::get_ticket_url( $recent_logs->ticket->id, $view );
749 $new_status = new WPSC_Status( $body->new );
750 if ( $new_status->id ) {
751 $status_value = $new_status->name;
752 } else {
753 $status_value = 'None';
754 }
755 return esc_attr( $recent_logs->customer->name ) . ' updated the ' . esc_attr( $cf->name ) . ' of <a href="' . esc_attr( $url ) . '" target="_blank">#' . esc_attr( $recent_logs->ticket->id ) . '</a> to ' . esc_attr( $status_value );
756 }
757 }
758 endif;
759
760 WPSC_DF_Status::init();
761