/** * 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 '✕'; } return '✓'; }
/** * 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(array('cap' => 'edit_ticket'))); $agent = array(); foreach ($users as $user) { $wpas_agent = new WPAS_Agent($user->ID); /** * 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); } } } $agent_id = !empty($agent) ? $agent['user_id'] : wpas_get_option('assignee_default'); return apply_filters('wpas_find_available_agent', $agent_id, $ticket_id); }