<commit_before><?php
namespace Kordy\Ticketit\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Kordy\Ticketit\Models\Agent;

class AgentsController extends Controller {

	public function __construct() {
		$this->middleware('auth');
	}

	public function index() {
		$agents = Agent::where('ticketit_agent', 1)->get();
		return view('Ticketit::admin.agent.index', compact('agents'));
	}

	public function create() {
		$users = Agent::all();
		return view('Ticketit::admin.agent.create', compact('users'));
	}

	public function store(Request $request) {
		$agents_list = $this->addAgents($request->input('agents'));
		$agents_names = implode(',', $agents_list);

		Session::flash('status', "Agents $agents_names are added to agents");

		return redirect()->action('\Kordy\Ticketit\Controllers\AgentsController@index');
	}

	public function update($id, Request $request) {
		$form_cats = ($request->input('agent_cats') == null) ? [] : $request->input('agent_cats');
		$agent = Agent::find($id);
		$agent->categories()->sync($form_cats);

		Session::flash('status', "Joint categories successfully");

		return redirect()->action('\Kordy\Ticketit\Controllers\AgentsController@index');
	}

	public function destroy($id) {
		$agent = $this->removeAgent($id);

		Session::flash('status', "Agents $agent->name is removed from agents team");

		return redirect()->action('\Kordy\Ticketit\Controllers\AgentsController@index');
	}

	/**
	 * Assign users as agents
	 *
	 * @param $user_ids
	 * @return array
	 */
	public function addAgents($user_ids) {
		$users = Agent::find($user_ids);
		foreach ($users as $user) {
			$user->ticketit_agent = true;
			$user->save();
			$users_list[] = $user->name;
		}
		return $users_list;
	}

	/**
	 * Remove user from the agents
	 * @param $id
	 * @return mixed
	 */
	public function removeAgent($id) {
		$agent = Agent::find($id);
		$agent->ticketit_agent = false;
		$agent->save();

		return $agent;
	}

}<commit_msg>Sync Agent Categories method extracted<commit_after><?php
namespace Kordy\Ticketit\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Kordy\Ticketit\Models\Agent;

class AgentsController extends Controller {

	public function __construct() {
		$this->middleware('auth');
	}

	public function index() {
		$agents = Agent::where('ticketit_agent', 1)->get();
		return view('Ticketit::admin.agent.index', compact('agents'));
	}

	public function create() {
		$users = Agent::all();
		return view('Ticketit::admin.agent.create', compact('users'));
	}

	public function store(Request $request) {
		$agents_list = $this->addAgents($request->input('agents'));
		$agents_names = implode(',', $agents_list);

		Session::flash('status', "Agents $agents_names are added to agents");

		return redirect()->action('\Kordy\Ticketit\Controllers\AgentsController@index');
	}

	public function update($id, Request $request) {
		$this->syncAgentCategories($id, $request);

		Session::flash('status', "Joint categories successfully");

		return redirect()->action('\Kordy\Ticketit\Controllers\AgentsController@index');
	}

	public function destroy($id) {
		$agent = $this->removeAgent($id);

		Session::flash('status', "Agents $agent->name is removed from agents team");

		return redirect()->action('\Kordy\Ticketit\Controllers\AgentsController@index');
	}

	/**
	 * Assign users as agents
	 *
	 * @param $user_ids
	 * @return array
	 */
	public function addAgents($user_ids) {
		$users = Agent::find($user_ids);
		foreach ($users as $user) {
			$user->ticketit_agent = true;
			$user->save();
			$users_list[] = $user->name;
		}
		return $users_list;
	}

	/**
	 * Remove user from the agents
	 * @param $id
	 * @return mixed
	 */
	public function removeAgent($id) {
		$agent = Agent::find($id);
		$agent->ticketit_agent = false;
		$agent->save();

		return $agent;
	}

	/**
	 * @param $id
	 * @param Request $request
	 */
	public function syncAgentCategories($id, Request $request)
	{
		$form_cats = ($request->input('agent_cats') == null) ? [] : $request->input('agent_cats');
		$agent = Agent::find($id);
		$agent->categories()->sync($form_cats);
	}

}
{'fraction_non_alphanumeric': 0.173841059602649, 'fraction_numerical': 0.0004730368968779565, 'mean_word_length': 4.881780250347705, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7374508', 'n_tokens_mistral': 1485, 'n_tokens_neox': 1358, 'n_words': 276}