__CLASS__,
'save-key' => 'id',
);
return $classes;
}
/**
* Add default custom field type to list
*
* @param array $default_cf_types - default custom field types array.
* @return array
*/
public static function default_cf_types( $default_cf_types ) {
$default_cf_types[ self::$slug ] = array(
'label' => esc_attr__( 'Source', 'supportcandy' ),
'class' => __CLASS__,
);
return $default_cf_types;
}
/**
* Load source list
*
* @return void
*/
public static function load_sources() {
self::$sources = apply_filters(
'wpsc_source_list',
array(
'browser' => __( 'Browser', 'supportcandy' ),
'rest-api' => 'REST API',
)
);
}
/**
* Print operators for ticket form filter
*
* @param WPSC_Custom_Field $cf - custom field object.
* @param array $filter - Existing filters (if any).
* @return void
*/
public static function get_operators( $cf, $filter = array() ) {
?>
slug ) ? trim( $cf->slug ) : '';
if ( $slug === '' || ! preg_match( '/^[a-zA-Z0-9_]+$/', $slug ) ) {
return '1=0';
}
$column = 'CONVERT(t.' . $slug . ' USING utf8)';
switch ( $compare ) {
case '=':
if ( ! is_scalar( $val ) ) {
return '1=0';
}
return 't.' . $slug . "='" . esc_sql( (string) $val ) . "'";
case 'IN':
case 'NOT IN':
$values = is_array( $val ) ? $val : array( $val );
$clean = array();
foreach ( $values as $v ) {
if ( is_scalar( $v ) && $v !== '' ) {
$clean[] = "'" . esc_sql( (string) $v ) . "'";
}
}
if ( empty( $clean ) ) {
return '1=0';
}
return $column . ' ' . $compare . ' (' . implode( ', ', $clean ) . ')';
default:
return '1=1';
}
}
/**
* Check ticket condition
*
* @param array $condition - array with condition data.
* @param WPSC_Custom_Field $cf - custom field object.
* @param WPSC_Ticket $ticket - ticket object.
* @return boolean
*/
public static function is_valid_ticket_condition( $condition, $cf, $ticket ) {
$flag = true;
switch ( $condition['operator'] ) {
case '=':
$flag = $ticket->{$cf->slug} == $condition['operand_val_1'] ? true : false;
break;
case 'IN':
$flag = in_array( $ticket->{$cf->slug}, $condition['operand_val_1'] );
break;
case 'NOT IN':
$flag = ! in_array( $ticket->{$cf->slug}, $condition['operand_val_1'] );
break;
default:
$flag = true;
}
return $flag;
}
/**
* Check and return custom field value for new ticket to be created.
* This function is used by filter for set create ticket form and called directly by my-profile for each applicable custom fields.
* Ignore phpcs nonce issue as we already checked where it is called from.
*
* @param array $data - Array of values to to stored in ticket in an insert function.
* @param array $custom_fields - Array containing all applicable custom fields indexed by unique custom field types.
* @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.
* @return array
*/
public static function set_create_ticket_data( $data, $custom_fields, $is_my_profile ) {
$data['source'] = 'browser';
return $data;
}
/**
* Set create ticket data for rest api request
*
* @param array $data - create ticket data array.
* @param WP_REST_Request $request - rest request object.
* @param array $custom_fields - custom field objects indexed by unique custom field types.
* @return array
*/
public static function set_rest_ticket_data( $data, $request, $custom_fields ) {
$data['source'] = 'rest-api';
return $data;
}
/**
* Return val field for meta query of this type of custom field
*
* @param array $condition - condition data.
* @return mixed
*/
public static function get_meta_value( $condition ) {
$operator = $condition['operator'];
switch ( $operator ) {
case '=':
case 'IN':
case 'NOT IN':
return $condition['operand_val_1'];
}
return false;
}
/**
* Return data for this custom field while creating duplicate ticket
*
* @param WPSC_Custom_Field $cf - custom field object.
* @param WPSC_Ticket $ticket - ticket object.
* @return mixed
*/
public static function get_duplicate_ticket_data( $cf, $ticket ) {
return '#' . $ticket->id;
}
/**
* Print edit custom field properties
*
* @param WPSC_Custom_Fields $cf - custom field object.
* @param string $field_class - class name of field category.
* @return void
*/
public static function get_edit_custom_field_properties( $cf, $field_class ) {
if ( in_array( 'tl_width', $field_class::$allowed_properties ) ) :
?>
tl_width = $tl_width ? $tl_width : 100;
}
// save!
$cf->save();
}
/**
* Returns printable ticket value for custom field. Can be used in export tickets, replace macros etc.
*
* @param WPSC_Custom_Field $cf - custom field object.
* @param WPSC_Ticket $ticket - ticket object.
* @param string $module - module name.
* @return string
*/
public static function get_ticket_field_val( $cf, $ticket, $module = '' ) {
$value = $ticket->{$cf->slug} && isset( self::$sources[ $ticket->{$cf->slug} ] ) ? self::$sources[ $ticket->{$cf->slug} ] : '';
return apply_filters( 'wpsc_ticket_field_val_source', $value, $cf, $ticket, $module );
}
/**
* Print ticket value for given custom field on ticket list
*
* @param WPSC_Custom_Field $cf - custom field object.
* @param WPSC_Ticket $ticket - ticket object.
* @return void
*/
public static function print_tl_ticket_field_val( $cf, $ticket ) {
echo $ticket->{$cf->slug} && isset( self::$sources[ $ticket->{$cf->slug} ] ) ? esc_attr( self::$sources[ $ticket->{$cf->slug} ] ) : '';
}
/**
* Print ticket value for given custom field on widget
*
* @param WPSC_Custom_Field $cf - custom field object.
* @param WPSC_Ticket $ticket - ticket object.
* @return void
*/
public static function print_widget_ticket_field_val( $cf, $ticket ) {
echo $ticket->{$cf->slug} && isset( self::$sources[ $ticket->{$cf->slug} ] ) ? esc_attr( self::$sources[ $ticket->{$cf->slug} ] ) : esc_attr__( 'Not Applicable', 'supportcandy' );
}
}
endif;
WPSC_DF_Source::init();