/**
  * Add link to agent's tickets.
  *
  * @since  3.0.0
  * @param  object $wp_admin_bar The WordPress toolbar object
  * @return void
  */
 public function toolbar_tickets_link($wp_admin_bar)
 {
     if (!current_user_can('edit_ticket')) {
         return;
     }
     $hide = (bool) wpas_get_option('hide_closed');
     $agent_see_all = (bool) wpas_get_option('agent_see_all');
     $admin_see_all = (bool) wpas_get_option('admin_see_all');
     $args = array('post_type' => 'ticket');
     $tickets_count = 0;
     // In case the current user can only see his own tickets
     if (current_user_can('administrator') && false === $admin_see_all || !current_user_can('administrator') && false === $agent_see_all) {
         global $current_user;
         $agent = new WPAS_Agent($current_user->ID);
         $tickets_count = $agent->open_tickets();
     } else {
         $tickets_count = count(wpas_get_tickets('open', $args));
     }
     if (true === $hide) {
         $args['wpas_status'] = 'open';
     }
     $node = array('id' => 'wpas_tickets', 'parent' => null, 'group' => null, 'title' => '<span class="ab-icon"></span> ' . $tickets_count, 'href' => add_query_arg($args, admin_url('edit.php')), 'meta' => array('target' => '_self', 'title' => esc_html__('Open tickets assigned to you', 'awesome-support'), 'class' => 'wpas-my-tickets'));
     $wp_admin_bar->add_node($node);
 }
Example #2
0
 /**
  * Delete ticket dependencies.
  *
  * Delete all ticket dependencies when a ticket is deleted. This includes
  * ticket replies and ticket history. Ticket attachments are deleted by
  * WPAS_File_Upload::delete_attachments()
  * 
  * @param  integer $post_id ID of the post to be deleted
  * @return void
  */
 public function delete_ticket_dependencies($post_id)
 {
     /* First of all we remove this action to avoid creating a loop */
     remove_action('before_delete_post', array($this, 'delete_ticket_replies'), 10, 1);
     $args = array('post_parent' => $post_id, 'post_type' => apply_filters('wpas_replies_post_type', array('ticket_history', 'ticket_reply')), 'post_status' => 'any', 'posts_per_page' => -1, 'no_found_rows' => true, 'cache_results' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false);
     $posts = new WP_Query($args);
     foreach ($posts->posts as $id => $post) {
         do_action('wpas_before_delete_dependency', $post->ID, $post);
         wp_delete_post($post->ID, true);
         do_action('wpas_after_delete_dependency', $post->ID, $post);
     }
     /* Decrement the number of tickets open for this agent */
     $agent_id = get_post_meta($post_id, '_wpas_assignee', true);
     $agent = new WPAS_Agent($agent_id);
     $agent->ticket_minus();
 }
/**
 * Change a ticket status to closed.
 *
 * @since  3.0.2
 *
 * @param  integer $ticket_id ID of the ticket to close
 * @param int      $user_id   ID of the user who closed the ticket
 *
 * @return integer|boolean            ID of the post meta if exists, true on success or false on failure
 */
function wpas_close_ticket($ticket_id, $user_id = 0)
{
    global $current_user;
    // Set the user who closed the ticket to the current user if nothing is specified
    if (0 === $user_id) {
        $user_id = $current_user->ID;
    }
    if (!current_user_can('close_ticket')) {
        wp_die(__('You do not have the capacity to close this ticket', 'wpas'), __('Can’t close ticket', 'wpas'), array('back_link' => true));
    }
    $ticket_id = intval($ticket_id);
    if ('ticket' == get_post_type($ticket_id)) {
        $update = update_post_meta(intval($ticket_id), '_wpas_status', 'closed');
        /* Decrement the number of tickets open for this agent */
        $agent_id = get_post_meta($ticket_id, '_wpas_assignee', true);
        $agent = new WPAS_Agent($agent_id);
        $agent->ticket_minus();
        /* Log the action */
        wpas_log($ticket_id, __('The ticket was closed.', 'wpas'));
        /**
         * wpas_after_close_ticket hook
         *
         * @since  3.0.0
         */
        do_action('wpas_after_close_ticket', $ticket_id, $update, $user_id);
        if (is_admin()) {
            /**
             * Fires after the ticket was closed in the admin only.
             *
             * @since  3.1.2
             *
             * @param integer $ticket_id ID of the ticket we just closed
             * @param integer $user_id   ID of the user who did the action
             * @param boolean $update    True on success, false on fialure
             */
            do_action('wpas_after_close_ticket_admin', $ticket_id, $user_id, $update);
        } else {
            /**
             * Fires after the ticket was closed in the front-end only.
             *
             * @since  3.1.2
             *
             * @param integer $ticket_id ID of the ticket we just closed
             * @param integer $user_id   ID of the user who did the action
             * @param boolean $update    True on success, false on fialure
             */
            do_action('wpas_after_close_ticket_public', $ticket_id, $user_id, $update);
        }
        return $update;
    } else {
        return false;
    }
}
 /**
  * Add auto-assignment user column content
  *
  * @since 3.2
  *
  * @param mixed  $value       Column value
  * @param string $column_name Column name
  * @param int    $user_id     Current user ID
  *
  * @return string
  */
 public function auto_assignment_user_column_content($value, $column_name, $user_id)
 {
     if ('wpas_auto_assignment' !== $column_name) {
         return $value;
     }
     $agent = new WPAS_Agent($user_id);
     if (true !== $agent->is_agent() || false === $agent->can_be_assigned()) {
         return '&#10005;';
     }
     return '&#10003;';
 }
Example #5
0
/**
 * Update the open agent tickets count when a ticket is transferred from one agent to another
 *
 * We do not need to add a new ticket to the new agent because it is automatically done in wpas_assign_ticket()
 *
 * @since 3.2.8
 *
 * @param int $agent_id          ID of the current ticket assignee
 * @param int $previous_agent_id ID of the previous assignee
 *
 * @return void
 */
function wpas_update_ticket_count_on_transfer($agent_id, $previous_agent_id)
{
    $agent_prev = new WPAS_Agent($previous_agent_id);
    $agent_prev->ticket_minus();
}