slug . '=\'' . esc_sql( $val ) . '\'';
break;
case 'IN':
$str = 'CONVERT(t.' . $cf->slug . ' USING utf8) IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
break;
case 'NOT IN':
$str = 'CONVERT(t.' . $cf->slug . ' USING utf8) NOT IN(\'' . implode( '\', \'', esc_sql( $val ) ) . '\')';
break;
default:
$str = '1=1';
}
return $str;
}
/**
* 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();