<commit_before><?php 

namespace M2L\AnnoncesBundle\Controller;

use M2L\AnnoncesBundle\Entity\annonces;
use M2L\AnnoncesBundle\Form\annoncesType;
use M2L\UserBundle\Entity\User;
use M2L\LigueBundle\Entity\ligue;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class AnnoncesController extends Controller {

	public function indexAction(){
		$em = $this->getDoctrine()->getManager();

		$users = $em->getRepository("M2LUserBundle:User")->findAll();
		$ligues = $em->getRepository("M2LLigueBundle:ligue")->findAll();

		$listeAnnonces = $em->getRepository("M2LAnnoncesBundle:annonces")->findBy(array("user"	=>	$users, "ligue"	=>	$ligues));
		
		return $this->render("M2LAnnoncesBundle:Annonces:index.html.twig", array(
			"listeAnnonces"	=>	$listeAnnonces
			));
	}

	public function viewAction($id) {
		$em = $this->getDoctrine()->getManager();

		$annonce = $em->getRepository("M2LAnnoncesBundle:annonces")->find($id);

		$user = $annonce->getUser();
		$ligue = $annonce->getLigue();

		if (null === $annonce) {
	    	throw new NotFoundHttpException("L'annonce d'id ".$id." n'existe pas.");
	    }

		return $this->render("M2LAnnoncesBundle:Annonces:viewAnnonce.html.twig", array(
			"annonce"	=>	$annonce,
			"user"		=>	$user,
			"ligue"		=>	$ligue
			));
	}

	public function addAction(Request $request) {
		$annonce = new Annonces();
		$user = $this->getUser();

		$form = $this->get("form.factory")->create(new annoncesType(), $annonce);

		if ($user != null) {
			if ($request->isMethod("POST")) {
				if ($form->handleRequest($request)) {

					$em = $this->getDoctrine()->getManager();
					$em->persist($annonce);
					$em->flush();

					return $this->redirect($this->generateUrl("m2l_annonces_view", array(
						"id"	=>	$annonce->getId()
						)));
				}
			} else {
				return $this->redirect($this->generateUrl("login"));
			}
		}

		return $this->render("M2LAnnoncesBundle:Annonces:addAnnonce.html.twig", array(
			"form"	=>	$form->createView()
			));
	}

	public function userAnnoncesAction() {

		$user = $this->getUser();

		if ($user != null) {

			$em = $this->getDoctrine()->getManager();
         	$listeAnnonces = $em->getRepository("M2LAnnoncesBundle:annonces")->findBy(array("user"	=>	$user));

			return $this->render("M2LAnnoncesBundle:Annonces:userAnnonces.html.twig", array(
				"listeAnnonces"	=>	$listeAnnonces,
				"user"			=>	$user
				));

        } else {
            return $this->redirect($this->generateUrl("login"));
        }

	}

}

?><commit_msg>securité ajout annonce<commit_after><?php 

namespace M2L\AnnoncesBundle\Controller;

use M2L\AnnoncesBundle\Entity\annonces;
use M2L\AnnoncesBundle\Form\annoncesType;
use M2L\UserBundle\Entity\User;
use M2L\LigueBundle\Entity\ligue;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class AnnoncesController extends Controller {

	public function indexAction(){
		$em = $this->getDoctrine()->getManager();

		$users = $em->getRepository("M2LUserBundle:User")->findAll();
		$ligues = $em->getRepository("M2LLigueBundle:ligue")->findAll();

		$listeAnnonces = $em->getRepository("M2LAnnoncesBundle:annonces")->findBy(array("user"	=>	$users, "ligue"	=>	$ligues));
		
		return $this->render("M2LAnnoncesBundle:Annonces:index.html.twig", array(
			"listeAnnonces"	=>	$listeAnnonces
			));
	}

	public function viewAction($id) {
		$em = $this->getDoctrine()->getManager();

		$annonce = $em->getRepository("M2LAnnoncesBundle:annonces")->find($id);

		$user = $annonce->getUser();
		$ligue = $annonce->getLigue();

		if (null === $annonce) {
	    	throw new NotFoundHttpException("L'annonce d'id ".$id." n'existe pas.");
	    }

		return $this->render("M2LAnnoncesBundle:Annonces:viewAnnonce.html.twig", array(
			"annonce"	=>	$annonce,
			"user"		=>	$user,
			"ligue"		=>	$ligue
			));
	}

	public function addAction(Request $request) {
		$annonce = new Annonces();
		$user = $this->getUser();

		$form = $this->get("form.factory")->create(new annoncesType(), $annonce);

		if ($user != null) {
			return $this->render("M2LAnnoncesBundle:Annonces:addAnnonce.html.twig", array(
				"form"	=>	$form->createView()
				));			
		} else {
			return $this->redirect($this->generateUrl("login"));
		}

		if ($request->isMethod("POST")) {
			if ($form->handleRequest($request)) {

				$em = $this->getDoctrine()->getManager();
				$em->persist($annonce);
				$em->flush();

				return $this->redirect($this->generateUrl("m2l_annonces_view", array(
					"id"	=>	$annonce->getId()
					)));
			}
		}
	}

	public function userAnnoncesAction() {

		$user = $this->getUser();

		if ($user != null) {

			$em = $this->getDoctrine()->getManager();
         	$listeAnnonces = $em->getRepository("M2LAnnoncesBundle:annonces")->findBy(array("user"	=>	$user));

			return $this->render("M2LAnnoncesBundle:Annonces:userAnnonces.html.twig", array(
				"listeAnnonces"	=>	$listeAnnonces,
				"user"			=>	$user
				));

        } else {
            return $this->redirect($this->generateUrl("login"));
        }

	}

}

?>
{'fraction_non_alphanumeric': 0.18927940310229727, 'fraction_numerical': 0.005890437855880621, 'mean_word_length': 4.300728407908429, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 107, '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': '11186', 'n_tokens_mistral': 2081, 'n_tokens_neox': 1859, 'n_words': 258}