<commit_before><?php

namespace TomGud\FoosLeader\CoreBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use TomGud\FoosLeader\CoreBundle\Entity\Result;
use TomGud\FoosLeader\CoreBundle\Entity\ELOHistory;

class ResultController extends Controller
{
    public function newAction()
    {
    	// Show all users in a drop down
    	$user_repo = $this->get('doctrine.orm.entity_manager')->getRepository('FoosLeaderUserBundle:User');
    	$users = $user_repo->findAll();

        $result = new Result();
        $form = $this->createFormBuilder($result)
            ->getForm();

        if (count($users) < 2) {
            $this->get('session')->getFlashBag()->add('error', "There aren't enough players to register a result.
                Please wait for more users to join");
        } else if (count($users) < 4) {
            $this->get('session')->getFlashBag()->add('warning', "There aren't enough players to register a team result.
                Please wait for more users to join");
        }

        return $this->render('FoosLeaderCoreBundle:Result:new.html.twig',
        	array(
        		'users' => $users,
        		'form' => $form->createView()
        		)
        	);
    }

    public function createAction(Request $request)
    {

    	$p_player_1 = $request->get('player_1');
		$p_player_2 = $request->get('player_2');
		$p_player_3 = $request->get('player_3');
		$p_player_4 = $request->get('player_4');
		$p_score_1 = $request->get('score_1');
		$p_score_2 = $request->get('score_2');

		// Validation
		if (intval($p_score_1) < 0 || intval($p_score_1) > 10  ||
			intval($p_score_2) < 0 || intval($p_score_2) > 10) {
			// Not a valid score was entered
			// Set flash bag error message
			$this->get('session')->getFlashBag()->add(
		        'error',
		        'Scores must be positive integers between 0 and 10 (inclusive)'
		    );
			return $this->redirect($this->generateUrl('new_result'));
		}
		if ($p_player_1 === $p_player_2 || $p_player_1 === $p_player_3 || $p_player_1 === $p_player_4 ||
			$p_player_2 === $p_player_3 || $p_player_2 === $p_player_4 ||
			($p_player_3 === $p_player_4 && $p_player_3 !== 'null')) {
			// Player 1 and Player 2 are the same player
			// Player 1 and Player 3 or Player 4 are the same player
			// Player 2 and Player 3 or Player 4 are the same player
			// Player 3 and Player 4 are the same player if they have been set
			// Set flash bag error message
			$this->get('session')->getFlashBag()->add(
		        'error',
		        'You can not choose the same player twice.'
		    );
			return $this->redirect($this->generateUrl('new_result'));
		}
		// Create the Result
		$new_result = new Result();

		// Find the users
		$user_repo = $this->getDoctrine()->getManager()->getRepository('FoosLeaderUserBundle:User');
    	$player_1 = $user_repo->find($p_player_1);
    	$player_2 = $user_repo->find($p_player_2);
    	$player_3 = $player_4 = null;
    	if ($p_player_3 !== 'none-3' && $p_player_4 !== 'none-4') {
    		$player_3 = $user_repo->find($p_player_3);
    		$player_4 = $user_repo->find($p_player_4);
    		if ($player_3 === null || $player_4 === null) {
    			// Set flash bag error message
    			$this->get('session')->getFlashBag()->add(
			        'error',
			        'Could not find player 3 or player 4.'
			    );
    			return $this->redirect($this->generateUrl('new_result'));
    		} else {
    			$new_result->setPlayer3($player_3);
    			$new_result->setPlayer4($player_4);
    		}
    	}
    	if ($player_1 === null || $player_2 === null) {
   			// Set flash bag error message
   			$this->get('session')->getFlashBag()->add(
		        'error',
		        'Could not find player 1 or 2.'
		    );
    		return $this->redirect($this->generateUrl('new_result'));
    	}

		// Set the values for the Result
		$new_result->setPlayer1($player_1);
		$new_result->setPlayer2($player_2);
		$new_result->setTeam1Score($p_score_1);
		$new_result->setTeam2Score($p_score_2);
		$new_result->setSubmitted(new \Datetime('now', new \DateTimeZone('UTC')));
        $new_result->setTeam1Confirmed(true);
        $new_result->setTeam2Confirmed(true);
        $this->getDoctrine()->getManager()->persist($new_result);
        $this->getDoctrine()->getManager()->flush();
        $this->createEloHistory($new_result);

		// Redirect to detail page for Result
		return $this->redirect($this->generateUrl('detail_result', array('id' => $new_result->getId())));
    }
<commit_msg>Validating new results for user participation<commit_after><?php

namespace TomGud\FoosLeader\CoreBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use TomGud\FoosLeader\CoreBundle\Entity\Result;
use TomGud\FoosLeader\CoreBundle\Entity\ELOHistory;

class ResultController extends Controller
{
    public function newAction()
    {
    	// Show all users in a drop down
    	$user_repo = $this->get('doctrine.orm.entity_manager')->getRepository('FoosLeaderUserBundle:User');
    	$users = $user_repo->findAll();

        $result = new Result();
        $form = $this->createFormBuilder($result)
            ->getForm();

        if (count($users) < 2) {
            $this->get('session')->getFlashBag()->add('error', "There aren't enough players to register a result.
                Please wait for more users to join");
        } else if (count($users) < 4) {
            $this->get('session')->getFlashBag()->add('warning', "There aren't enough players to register a team result.
                Please wait for more users to join");
        }

        return $this->render('FoosLeaderCoreBundle:Result:new.html.twig',
        	array(
        		'users' => $users,
        		'form' => $form->createView()
        		)
        	);
    }

    public function createAction(Request $request)
    {

    	$p_player_1 = $request->get('player_1');
		$p_player_2 = $request->get('player_2');
		$p_player_3 = $request->get('player_3');
		$p_player_4 = $request->get('player_4');
		$p_score_1 = $request->get('score_1');
		$p_score_2 = $request->get('score_2');

		// Validation
		if (intval($p_score_1) < 0 || intval($p_score_1) > 10  ||
			intval($p_score_2) < 0 || intval($p_score_2) > 10) {
			// Not a valid score was entered
			// Set flash bag error message
			$this->get('session')->getFlashBag()->add(
		        'error',
		        'Scores must be positive integers between 0 and 10 (inclusive)'
		    );
			return $this->redirect($this->generateUrl('new_result'));
		}
		if ($p_player_1 === $p_player_2 || $p_player_1 === $p_player_3 || $p_player_1 === $p_player_4 ||
			$p_player_2 === $p_player_3 || $p_player_2 === $p_player_4 ||
			($p_player_3 === $p_player_4 && $p_player_3 !== 'null')) {
			// Player 1 and Player 2 are the same player
			// Player 1 and Player 3 or Player 4 are the same player
			// Player 2 and Player 3 or Player 4 are the same player
			// Player 3 and Player 4 are the same player if they have been set
			// Set flash bag error message
			$this->get('session')->getFlashBag()->add(
		        'error',
		        'You can not choose the same player twice.'
		    );
			return $this->redirect($this->generateUrl('new_result'));
		}
		// Create the Result
		$new_result = new Result();

		// Find the users
		$user_repo = $this->getDoctrine()->getManager()->getRepository('FoosLeaderUserBundle:User');
    	$player_1 = $user_repo->find($p_player_1);
    	$player_2 = $user_repo->find($p_player_2);
    	$player_3 = $player_4 = null;
    	if ($p_player_3 !== 'none-3' && $p_player_4 !== 'none-4') {
    		$player_3 = $user_repo->find($p_player_3);
    		$player_4 = $user_repo->find($p_player_4);
    		if ($player_3 === null || $player_4 === null) {
    			// Set flash bag error message
    			$this->get('session')->getFlashBag()->add(
			        'error',
			        'Could not find player 3 or player 4.'
			    );
    			return $this->redirect($this->generateUrl('new_result'));
    		} else {
    			$new_result->setPlayer3($player_3);
    			$new_result->setPlayer4($player_4);
    		}
    	}
    	if ($player_1 === null || $player_2 === null) {
   			// Set flash bag error message
   			$this->get('session')->getFlashBag()->add(
		        'error',
		        'Could not find player 1 or 2.'
		    );
    		return $this->redirect($this->generateUrl('new_result'));
    	}

        $user = $this->getUser();
        if ($player_1 !== $user && $player_2 !== $user && $player_3 !== $user && $player_4 !== $user) {
            $this->get('session')->getFlashBag()->add(
                'error',
                'Can not create a match which you (' . $user->getUsername() . ') did not participate in.'
            );
            return $this->redirect($this->generateUrl('new_result'));
        }

		// Set the values for the Result
		$new_result->setPlayer1($player_1);
		$new_result->setPlayer2($player_2);
		$new_result->setTeam1Score($p_score_1);
		$new_result->setTeam2Score($p_score_2);
		$new_result->setSubmitted(new \Datetime('now', new \DateTimeZone('UTC')));
        $new_result->setTeam1Confirmed(true);
        $new_result->setTeam2Confirmed(true);
        $this->getDoctrine()->getManager()->persist($new_result);
        $this->getDoctrine()->getManager()->flush();
        $this->createEloHistory($new_result);

		// Redirect to detail page for Result
		return $this->redirect($this->generateUrl('detail_result', array('id' => $new_result->getId())));
    }

{'fraction_non_alphanumeric': 0.1600486223662885, 'fraction_numerical': 0.017828200972447326, 'mean_word_length': 3.1154647769904127, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 150, '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': '5325053', 'n_tokens_mistral': 3456, 'n_tokens_neox': 3179, 'n_words': 672}