<commit_before><?php
/**
 * Created by PhpStorm.
 * User: axel
 * Date: 30/12/2016
 * Time: 14:56
 */

namespace AppBundle\Controller;


use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\AppBundle;
use AppBundle\Entity\Travel;
use AppBundle\Entity\City;
use AppBundle\Forms\addTravelType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TimeType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;

class AddTravelController extends Controller
{
    /**
     * @Route("/newTravelForm", name = "newTravelForm")
     */

    public function createTravelFormAction(Request $request)
    {


        $city = $this->getDoctrine()->getRepository('AppBundle:City')->findAll();


        $em = $this->getDoctrine()->getManager();
        $query = $em->createQuery('SELECT name FROM AppBundle\Entity\City name');
        $tests = $query->getArrayResult();



        dump($city);
        if ($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
            $user = $this->container->get('security.token_storage')->getToken()->getUser();

        }

        $travel = new Travel();

        $form = $this->createFormBuilder($travel)


            ->add('date',DateTimeType::class, array(
            'date_widget' => "single_text",
            'time_widget' => "single_text",
            'label' => 'Date',
        ))
            ->add('time', TimeType::class, array(
                'label' => 'temps estimé',
                'widget' => 'single_text',
                'attr' => ['class' => 'range-field']

            ))
            ->add('emptySeat',ChoiceType::class, array(
                'label' => 'Nombre de passagers',
                'choices' => array(
                    '1' => '1',
                    '2' => '2',
                    '3' => '3',
                    '4' => '4'),
                'choice_label' => function ($value) {return strtoupper($value);},
                'attr' => ['class' => 'browser-default']
            ))

            ->add('start',ChoiceType::class, array(
                'label' => 'Départ',
                'choices' => $this->getCities($tests),
                'choice_label' => function ($value) {return strtoupper($value);},
                'attr' => ['class' => 'browser-default']
            ))

            ->add('end',ChoiceType::class, array(
                'label' => 'Arrivée',
                'choices' => $this->getCities($tests),
                'choice_label' => function ($value) {return strtoupper($value);},
                'attr' => ['class' => 'browser-default']
            ))


            ->add('description',TextType::class)
            ->add('valider', SubmitType::class, array('label' => 'Proposer le trajet', 'attr' => ['class' => 'btn waves-effect waves-light']))->getForm();

        dump(array_values($tests));
        $form->handleRequest($request);


        if ($form->isSubmitted() && $form->isValid()) {
            $travel->setDriver($user);
            dump($travel);
            
            // Ca se passe ici Beeeeeeeen
           $travel->setStart($this->getDoctrine()->getRepository('AppBundle:Travel')->find($travel->getStart()));
            $travel->setEnd($this->getDoctrine()->getRepository('AppBundle:Travel')->find($travel->getEnd()));

            $em = $this->getDoctrine()->getManager();<commit_msg>EntityType -> addTravel fonctionne a 100%<commit_after><?php
/**
 * Created by PhpStorm.
 * User: axel
 * Date: 30/12/2016
 * Time: 14:56
 */

namespace AppBundle\Controller;


use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\AppBundle;
use AppBundle\Entity\Travel;
use AppBundle\Entity\City;
use AppBundle\Forms\addTravelType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TimeType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;

class AddTravelController extends Controller
{
    /**
     * @Route("/newTravelForm", name = "newTravelForm")
     */

    public function createTravelFormAction(Request $request)
    {


        $city = $this->getDoctrine()->getRepository('AppBundle:City')->findAll();


        $em = $this->getDoctrine()->getManager();
        $query = $em->createQuery('SELECT name FROM AppBundle\Entity\City name');
        $tests = $query->getArrayResult();



        dump($city);
        if ($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
            $user = $this->container->get('security.token_storage')->getToken()->getUser();

        }

        $travel = new Travel();

        $form = $this->createFormBuilder($travel)


            ->add('date',DateTimeType::class, array(
            'date_widget' => "single_text",
            'time_widget' => "single_text",
            'label' => 'Date',
        ))
            ->add('time', TimeType::class, array(
                'label' => 'temps estimé',
                'widget' => 'single_text',
                'attr' => ['class' => 'range-field']

            ))
            ->add('emptySeat',ChoiceType::class, array(
                'label' => 'Nombre de passagers',
                'choices' => array(
                    '1' => '1',
                    '2' => '2',
                    '3' => '3',
                    '4' => '4'),
                'choice_label' => function ($value) {return strtoupper($value);},
                'attr' => ['class' => 'browser-default']
            ))

            ->add('start', EntityType::class, array(
                'class' => 'AppBundle:City',
                'choice_label' => 'name',
                'attr' => ['class' => 'browser-default']
            ))

            ->add('end', EntityType::class, array(
                'class' => 'AppBundle:City',
                'choice_label' => 'name',
                'attr' => ['class' => 'browser-default']
            ))


            ->add('description',TextType::class)
            ->add('valider', SubmitType::class, array('label' => 'Proposer le trajet', 'attr' => ['class' => 'btn waves-effect waves-light']))->getForm();

        dump(array_values($tests));
        $form->handleRequest($request);


        if ($form->isSubmitted() && $form->isValid()) {
            $travel->setDriver($user);
           // dump($travel);
            
            // Ca se passe ici Beeeeeeeen
          // $travel->setStart($this->getDoctrine()->getRepository('AppBundle:Travel')->find($travel->getStart()));
           // $travel->setEnd($this->getDoctrine()->getRepository('AppBundle:Travel')->find($travel->getEnd()));

            $em = $this->getDoctrine()->getManager();
{'fraction_non_alphanumeric': 0.17056043214044564, 'fraction_numerical': 0.005806887238352465, 'mean_word_length': 2.4446511627906977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 140, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '668617', 'n_tokens_mistral': 2201, 'n_tokens_neox': 2055, 'n_words': 341}