コード例 #1
1
/**
 * Add ticket count in admin menu item.
 *
 * @return boolean True if the ticket count was added, false otherwise
 * @since  1.0.0
 */
function wpas_tickets_count()
{
    if (false === (bool) wpas_get_option('show_count')) {
        return false;
    }
    global $menu, $current_user;
    if (current_user_can('administrator') && false === boolval(wpas_get_option('admin_see_all')) || !current_user_can('administrator') && current_user_can('edit_ticket') && false === boolval(wpas_get_option('agent_see_all'))) {
        $agent = new WPAS_Member_Agent($current_user->ID);
        $count = $agent->open_tickets();
    } else {
        $count = count(wpas_get_tickets('open'));
    }
    if (0 === $count) {
        return false;
    }
    foreach ($menu as $key => $value) {
        if ($menu[$key][2] == 'edit.php?post_type=ticket') {
            $menu[$key][0] .= ' <span class="awaiting-mod count-' . $count . '"><span class="pending-count">' . $count . '</span></span>';
        }
    }
    return true;
}
コード例 #2
0
/**
 * Add link to agent's tickets.
 *
 * @since  3.0.0
 *
 * @param  object $wp_admin_bar The WordPress toolbar object
 *
 * @return void
 */
function wpas_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');
    // 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_Member_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);
}
コード例 #3
0
/**
 * Find an available agent to assign a ticket to.
 *
 * This is a super basic attribution system. It just finds the agent
 * with the less tickets currently open.
 *
 * @since  3.0.0
 *
 * @param  boolean|integer $ticket_id The ticket that needs an agent
 *
 * @return integer         ID of the best agent for the job
 */
function wpas_find_agent($ticket_id = false)
{
    if (defined('WPAS_DISABLE_AUTO_ASSIGN') && true === WPAS_DISABLE_AUTO_ASSIGN) {
        return apply_filters('wpas_find_available_agent', wpas_get_option('assignee_default'), $ticket_id);
    }
    $users = shuffle_assoc(wpas_get_users(apply_filters('wpas_find_agent_get_users_args', array('cap' => 'edit_ticket'))));
    $agent = array();
    foreach ($users->members as $user) {
        $wpas_agent = new WPAS_Member_Agent($user);
        /**
         * Make sure the user really is an agent and that he can currently be assigned
         */
        if (true !== $wpas_agent->is_agent() || false === $wpas_agent->can_be_assigned()) {
            continue;
        }
        $count = $wpas_agent->open_tickets();
        // Total number of open tickets for this agent
        if (empty($agent)) {
            $agent = array('tickets' => $count, 'user_id' => $user->ID);
        } else {
            if ($count < $agent['tickets']) {
                $agent = array('tickets' => $count, 'user_id' => $user->ID);
            }
        }
    }
    if (is_array($agent) && isset($agent['user_id'])) {
        $agent_id = $agent['user_id'];
    } else {
        $default_id = wpas_get_option('assignee_default', 1);
        if (empty($default_id)) {
            $default_id = 1;
        }
        $agent_id = $default_id;
    }
    return apply_filters('wpas_find_available_agent', (int) $agent_id, $ticket_id);
}