コード例 #1
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);
}
コード例 #2
0
 /**
  * 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_Member_Agent($user_id);
     if (true !== $agent->is_agent()) {
         return 'N/A';
     }
     if (false === $agent->can_be_assigned()) {
         return '&#10005;';
     }
     return '&#10003;';
 }