__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__( 'User Type', 'supportcandy' ),
'class' => __CLASS__,
);
return $default_cf_types;
}
/**
* 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';
}
switch ( $compare ) {
case '=':
if ( is_array( $val ) || is_object( $val ) ) {
return '1=0';
}
return 't.' . $slug . " = '" . esc_sql( (string) $val ) . "'";
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 = $condition['operand_val_1'] == $ticket->{$cf->slug} ? true : false;
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 ) {
$customer = new WPSC_Customer( $data['customer'] );
$data['user_type'] = $customer->user ? 'registered' : 'guest';
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 ) {
$customer = new WPSC_Customer( $data['customer'] );
$data['user_type'] = $customer->user ? 'registered' : 'guest';
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 ) {
return $condition['operand_val_1'];
}
/**
* Change user type from "guest" to "registered" for all his exising guest tickets (if any)
*
* @param int $user_id - user id of user being registered.
* @param array $user_data - user data such as name, email, etc.
* @return void
*/
public static function wp_user_register( $user_id, $user_data ) {
global $wpdb;
$customer = WPSC_Customer::get_by_user_id( $user_id );
// update customer_type in all of his tickets.
$success = $wpdb->update(
$wpdb->prefix . 'psmsc_tickets',
array( 'user_type' => 'registered' ),
array( 'customer' => $customer->id )
);
}
/**
* Change user type from "registered" to "guest" for all his exising guest tickets (if any)
*
* @param int $user_id - user id of user being deleted.
* @param int $reassign - user id of user this user being reassigned to.
* @param WP_User $user - wp user object.
* @return void
*/
public static function wp_user_delete( $user_id, $reassign, $user ) {
global $wpdb;
$customer = WPSC_Customer::get_by_email( $user->user_email );
if ( $customer->id ) {
$customer->user = 0;
$customer->save();
// update customer_type in all of his tickets.
$success = $wpdb->update(
$wpdb->prefix . 'psmsc_tickets',
array( 'user_type' => 'guest' ),
array( 'customer' => $customer->id )
);
}
}
/**
* 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->user_type;
}
/**
* 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} == 'registered' ? esc_attr__( 'Registered', 'supportcandy' ) : esc_attr__( 'Guest', 'supportcandy' );
return apply_filters( 'wpsc_ticket_field_val_user_type', $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 esc_attr( self::get_ticket_field_val( $cf, $ticket ) );
}
}
endif;
WPSC_DF_User_Type::init();