Пример #1
0
/**
 * Adds a new ticket.
 *
 * @since	1.0
 * @param	arr		$ticket_data	Ticket data.
 * @return	mixed	Ticket ID on success, false on failure.
 */
function kbs_add_ticket($ticket_data)
{
    if (!empty($ticket_data['attachments']) && !is_array($ticket_data['attachments'])) {
        $ticket_data['attachments'] = array($ticket_data['attachments']);
    }
    $ticket_data = apply_filters('kbs_add_ticket_data', $ticket_data);
    $attachments = apply_filters('kbs_add_ticket_attachments', $ticket_data['attachments']);
    $ticket = new KBS_Ticket();
    $ticket->status = !empty($ticket_data['status']) ? $ticket_data['status'] : 'new';
    $ticket->ticket_title = $ticket_data['post_title'];
    $ticket->ticket_content = $ticket_data['post_content'];
    $ticket->agent = !empty($ticket_data['agent']) ? $ticket_data['agent'] : '';
    $ticket->user_info = $ticket_data['user_info'];
    $ticket->user_id = !empty($ticket_data['user_info']['id']) ? $ticket_data['user_info']['id'] : '';
    $ticket->email = $ticket_data['user_email'];
    $ticket->first_name = $ticket_data['user_info']['first_name'];
    $ticket->last_name = $ticket_data['user_info']['last_name'];
    $ticket->email = $ticket_data['user_info']['email'];
    $ticket->ip = kbs_get_ip();
    $ticket->sla = array('target_respond' => kbs_calculate_sla_target_response(), 'target_resolve' => kbs_calculate_sla_target_resolution());
    $ticket->source = '';
    $ticket->new_files = $ticket_data['attachments'];
    $ticket->form_data = !empty($ticket_data['form_data']) ? $ticket_data['form_data'] : '';
    if (isset($ticket_data['post_date'])) {
        $ticket->date = $ticket_data['post_date'];
    }
    do_action('kbs_before_add_ticket', $ticket->ID, $ticket_data);
    $ticket->save();
    do_action('kbs_add_ticket', $ticket->ID, $ticket_data);
    if (!empty($ticket->ID)) {
        return $ticket->ID;
    }
    // Return false if no ticket was inserted
    return false;
}
Пример #2
0
/**
 * Output the SLA data for the ticket.
 *
 * @since	1.0
 * @global	obj		$kbs_ticket			KBS_Ticket class object
 * @global	bool	$kbs_ticket_update	True if this ticket is being updated, false if new.
 * @param	int		$ticket_id			The ticket post ID.
 * @return	str
 */
function kbs_ticket_metabox_sla_row($ticket_id)
{
    global $kbs_ticket, $kbs_ticket_update;
    if (!kbs_get_option('sla_tracking') || !$kbs_ticket_update) {
        return;
    }
    $sla_respond_class = '';
    $sla_resolve_class = '';
    $sla_respond_remain = '';
    $sla_resolve_remain = '';
    if ($kbs_ticket_update) {
        $respond = $kbs_ticket->ticket_meta['sla']['target_respond'];
        $resolve = $kbs_ticket->ticket_meta['sla']['target_resolve'];
        $sla_respond_class = kbs_sla_has_passed($kbs_ticket->ID) ? '_over' : '';
        $sla_resolve_class = kbs_sla_has_passed($kbs_ticket->ID, 'resolve') ? '_over' : '';
        $sla_respond_remain = ' ' . $kbs_ticket->get_sla_remain();
        $sla_resolve_remain = ' ' . $kbs_ticket->get_sla_remain('resolve');
    } else {
        $respond = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime(kbs_calculate_sla_target_response()));
        $resolve = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime(kbs_calculate_sla_target_resolution()));
    }
    ?>
    <p><strong><?php 
    _e('SLA Status', 'kb-support');
    ?>
</strong></p>
    <p>&nbsp;<i class="fa fa-dot-circle-o fa-lg" aria-hidden="true"></i>&nbsp;&nbsp;<label><?php 
    _e('Respond:', 'kb-support');
    ?>
</label>
    	&nbsp;<span class="dashicons dashicons-flag kbs_sla_status<?php 
    echo $sla_respond_class;
    ?>
" title="<?php 
    echo $respond;
    ?>
"></span><?php 
    echo $sla_respond_remain;
    ?>
</p>
        
    <p>&nbsp;<i class="fa fa-clock-o fa-lg" aria-hidden="true"></i>&nbsp;&nbsp;<label><?php 
    _e('Resolve:', 'kb-support');
    ?>
</label>
    	&nbsp;<span class="dashicons dashicons-flag kbs_sla_status<?php 
    echo $sla_resolve_class;
    ?>
" title="<?php 
    echo $resolve;
    ?>
"></span><?php 
    echo $sla_resolve_remain;
    ?>
</p>
    
    <?php 
}
Пример #3
0
 /**
  * Creates a ticket
  *
  * @since 	1.0
  * @param 	arr		$data Array of attributes for a ticket. See $defaults aswell as wp_insert_post.
  * @param 	arr		$meta Array of attributes for a ticket's meta data. See $default_meta.
  * @return	mixed	false if data isn't passed and class not instantiated for creation, or New Ticket ID
  */
 public function create($data = array(), $meta = array())
 {
     if ($this->id != 0) {
         return false;
     }
     add_action('save_post_kbs_ticket', 'kbs_ticket_post_save', 10, 3);
     $defaults = array('post_type' => 'kbs_ticket', 'post_author' => is_user_logged_in() ? get_current_user_id() : 1, 'post_content' => '', 'post_status' => 'new', 'post_title' => sprintf(__('New %s', 'kb-support'), kbs_get_ticket_label_singular()));
     $default_meta = array('__agent' => 0, '__target_sla_respond' => kbs_calculate_sla_target_response(), '__target_sla_resolve' => kbs_calculate_sla_target_resolution(), '__source' => 1);
     $data = wp_parse_args($data, $defaults);
     $meta = wp_parse_args($meta, $default_meta);
     $data['meta_input'] = array('_ticket_data' => $meta);
     do_action('kbs_pre_create_ticket', $data, $meta);
     $id = wp_insert_post($data, true);
     $ticket = WP_Post::get_instance($id);
     do_action('kbs_post_create_ticket', $id, $data);
     add_action('save_post_kbs_ticket', 'kbs_ticket_post_save', 10, 3);
     return $this->setup_ticket($ticket);
 }