<commit_before><?php

namespace Administrator\Administration\AdminBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use BDD\BddClientBundle\Entity\Marches;

class MarchesController extends Controller
{
    /* Page administration marché */
    public function indexAction(){
      $session = $this->getRequest()->getSession();
      if ($session->get('pren') != NULL) {
          if (strtolower($session->get('typ')) == 'administrateur') {
            $marches = $this->getDoctrine()
                          ->getRepository('BDDBddClientBundle:Marches')
                          ->findAll();
            return $this->render('AdministratorAdministrationAdminBundle:Marches:marchesAdmin.html.twig', array(
              'marches' => $marches
            ));
          }else{
            return $this->redirect($this->generateUrl('accueil_accueil_homepage'));
          }
      }else{
        return $this->redirect($this->generateUrl('accueil_accueil_homepage'));
      }
    }

    /* Ajout d'un nouveau marché */
    public function ajoutAction(Request $request){
      $session = $this->getRequest()->getSession();
      if ($session->get('pren') != NULL) {
          if (strtolower($session->get('typ')) == 'administrateur') {
        $marche = new Marches();
        $form = $this->createFormBuilder($marche)
           ->add('lieu','text')
           ->add('jourSemaine', 'choice', array(
                  'choices'   => array(
                    'lundi' => 'Lundi',
                    'mardi' => 'Mardi',
                    'mercredi' => 'Mercredi',
                    'jeudi' => 'Jeudi',
                    'vendredi' => 'Vendredi',
                    'samedi' => 'Samedi',
                    'dimanche' => 'Dimanche'),
                    'multiple'  => true,
                    'expanded'  => true))
           ->add('info','textarea')
           ->add('valider','submit')
           ->add('annuler','reset')
           ->getForm();
        $form->handleRequest($request);

        if($form->isValid()) {
          $marche = $form -> getData();
          $message = "";
          if ($marche->getLieu() == "" || strpos(htmlentities($marche->getLieu(), ENT_QUOTES), '&gt;') || strpos(htmlentities($marche->getLieu(), ENT_QUOTES), '&lt;')){
            $message .= "Lieu incorrect. ";
          }
          if ($marche->getJourSemaine() == null || $marche->getJourSemaine() == "" ){
            $message .= "Jour de Semaine incorrect. ";
          }
          if ($marche->getInfo() == "" || strpos(htmlentities($marche->getInfo(), ENT_QUOTES), '&gt;') || strpos(htmlentities($marche->getInfo(), ENT_QUOTES), '&lt;')){
            $message .= "Informations incorrect. ";
          }

          if ($message == ""){
            $jour = $marche->getJourSemaine();
            $j = "";
            foreach($jour as $a){
              $j .= $a." ";
            }
            $marche->setJourSemaine($j);
            $em = $this->getDoctrine()->getManager();
            $em->persist($marche);
            $em->flush();
            return $this->redirect($this->generateUrl('administrator_marches_index'));
          }else{
            $request->getSession()->getFlashBag()->add('notice', $message);
          }
        }
        return $this->render('AdministratorAdministrationAdminBundle:Marches:marchesAjout.html.twig',
              array('form' => $form->createView()) );
          }else{
            return $this->redirect($this->generateUrl('accueil_accueil_homepage'));
          }
      }else{
        return $this->redirect($this->generateUrl('accueil_accueil_homepage'));
      }
    }

    /* Supprimer un marché */
    public function suppAction($id){
      $session = $this->getRequest()->getSession();
      if ($session->get('pren') != NULL) {
          if (strtolower($session->get('typ')) == 'administrateur') {
          $marche = $this->getDoctrine()
            ->getRepository('BDDBddClientBundle:Marches')->find($id);
          $em = $this->getDoctrine()->getManager();
          $em->remove($marche);
          $em->flush();
          return $this->redirect($this->generateUrl('administrator_marches_index'));<commit_msg>Reponse au dernier bug de mon code<commit_after><?php

namespace Administrator\Administration\AdminBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use BDD\BddClientBundle\Entity\Marches;

class MarchesController extends Controller
{
    /* Page administration marché */
    public function indexAction(){
      $session = $this->getRequest()->getSession();
      if ($session->get('pren') != NULL) {
          if (strtolower($session->get('typ')) == 'administrateur') {
            $marches = $this->getDoctrine()
                          ->getRepository('BDDBddClientBundle:Marches')
                          ->findAll();
            return $this->render('AdministratorAdministrationAdminBundle:Marches:marchesAdmin.html.twig', array(
              'marches' => $marches
            ));
          }else{
            return $this->redirect($this->generateUrl('accueil_accueil_homepage'));
          }
      }else{
        return $this->redirect($this->generateUrl('accueil_accueil_homepage'));
      }
    }

    /* Ajout d'un nouveau marché */
    public function ajoutAction(Request $request){
      $session = $this->getRequest()->getSession();
      if ($session->get('pren') != NULL) {
          if (strtolower($session->get('typ')) == 'administrateur') {
        $marche = new Marches();
        $form = $this->createFormBuilder($marche)
           ->add('lieu','text')
           ->add('jourSemaine', 'choice', array(
                  'choices'   => array(
                    'lundi' => 'Lundi',
                    'mardi' => 'Mardi',
                    'mercredi' => 'Mercredi',
                    'jeudi' => 'Jeudi',
                    'vendredi' => 'Vendredi',
                    'samedi' => 'Samedi',
                    'dimanche' => 'Dimanche'),
                    'multiple'  => true,
                    'expanded'  => true))
           ->add('info','textarea')
           ->add('valider','submit')
           ->add('annuler','reset')
           ->getForm();
        $form->handleRequest($request);

        if($form->isValid()) {
          $marche = $form -> getData();
          $message = "";
          if ($marche->getLieu() == "" || strpos(htmlentities($marche->getLieu(), ENT_QUOTES), '&gt;') || strpos(htmlentities($marche->getLieu(), ENT_QUOTES), '&lt;')){
            $message .= "Lieu incorrect. ";
          }
          if ($marche->getJourSemaine() == null || $marche->getJourSemaine() == "" ){
            $message .= "Jour de Semaine incorrect. ";
          }
          if ($marche->getInfo() == "" || strpos(htmlentities($marche->getInfo(), ENT_QUOTES), '&gt;') || strpos(htmlentities($marche->getInfo(), ENT_QUOTES), '&lt;')){
            $message .= "Informations incorrect. ";
          }

          if ($message == ""){
            $jour = $marche->getJourSemaine();
            $j = "";
            foreach($jour as $a){
              $j .= $a." ";
            }
            $marche->setJourSemaine($j);
            $em = $this->getDoctrine()->getManager();
            $em->persist($marche);
            $em->flush();
            return $this->redirect($this->generateUrl('administrator_marches_index'));
          }else{
            $request->getSession()->getFlashBag()->add('notice', $message);
          }
        }
        return $this->render('AdministratorAdministrationAdminBundle:Marches:marchesAjout.html.twig',
              array('form' => $form->createView()) );
          }else{
            return $this->redirect($this->generateUrl('accueil_accueil_homepage'));
          }
      }else{
        return $this->redirect($this->generateUrl('accueil_accueil_homepage'));
      }
    }

    /* Supprimer un marché */
    public function suppAction($id){
      $session = $this->getRequest()->getSession();
      if ($session->get('pren') != NULL) {
          if (strtolower($session->get('typ')) == 'administrateur') {
          $marche = $this->getDoctrine()
            ->getRepository('BDDBddClientBundle:Marches')->find($id);
          $em = $this->getDoctrine()->getManager();

          $commandes = $this->getDoctrine()
            ->getRepository('BDDBddClientBundle:Commande')->findByRetirerMarches($marche);
          foreach($commandes as $com){
            $em->remove($com);
          }

          $em->remove($marche);
          $em->flush();
          return $this->redirect($this->generateUrl('administrator_marches_index'));
{'fraction_non_alphanumeric': 0.17631518492993337, 'fraction_numerical': 0.0, 'mean_word_length': 2.1524257784214336, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 159, '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': '6205453', 'n_tokens_mistral': 2536, 'n_tokens_neox': 2497, 'n_words': 374}