예제 #1
0
 public function reservationAction()
 {
     $em = $this->getDoctrine()->getManager();
     $request = $this->getRequest();
     $user = $this->get('security.context')->getToken()->getUser();
     if ($this->container->get('security.context')->isGranted('IS_AUTHENTICATED_FULLY') && !is_null($user->getClient())) {
         $client = $user->getClient();
     } else {
         $client = $this->container->get('users')->getPassager();
     }
     $reservation = new MaritimeReservation();
     $reservation->setClient($client)->setNomPrenom($client->getNomPrenom())->setTel($client->getTel1());
     if (!is_null($client->getUser())) {
         $reservation->setEmail($client->getUser()->getEmail());
     }
     $form = $this->createForm(new MaritimeReservationType(), $reservation);
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             $reservation = $form->getData();
             $em->persist($reservation->setEtat(1)->setFrontOffice(1));
             $em->flush();
             return $this->redirect($this->generateUrl('front_maritime_succees', array('id' => $reservation->getId())));
         }
     }
     return $this->render('FrontGeneralBundle:maritime:reservation.html.twig', array('csrf_token' => $this->container->get('form.csrf_provider')->generateCsrfToken('authenticate'), 'form' => $form->createView()));
 }