PluginProbe
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent / 3.3.9
SupportCandy – AI Customer Support Ticket System & Live Chatbot Agent v3.3.9
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.3.9, at includes/custom-field-types/class-wpsc-df-status.php

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