public function add2Action($id, Request $request)
 {
     // On récupère l'EntityManager
     $em = $this->getDoctrine()->getManager();
     // Pour récupérer une annonce unique : on utilise find()
     $festival = $em->getRepository('GSFestivalBundle:Festival')->find($id);
     if ($festival === null) {
         throw $this->createNotFoundException("Le festival d'id " . $id . " n'existe pas.");
     }
     $registration = new Registration();
     $email = $request->getSession()->get('email');
     $person = $em->getRepository('GSPersonBundle:Person')->findOneByEmail($email);
     if ($person === null) {
         $person = new Person();
         $person->setEmail($email);
     }
     $registration->setPerson($person);
     $form = $this->createForm(RegistrationType::class, $registration, array('festival' => $festival));
     if ($form->handleRequest($request)->isValid()) {
         $form->get('level')->getData()->addRegistration($registration);
         $partner = $em->getRepository('GSFestivalBundle:Registration')->getPartner($registration);
         if (count($partner) == 1) {
             $registration->setPartner($partner[0]);
         }
         $em->persist($registration);
         $em->flush();
         $request->getSession()->getFlashBag()->add('success', 'Inscription bien enregistrée.');
         $request->getSession()->remove('email');
         return $this->redirectToRoute('gs_registration_preview', array('id' => $registration->getId()));
     }
     return $this->render('GSFestivalBundle:Registration:add.html.twig', array('festival' => $festival, 'form' => $form->createView()));
 }
Esempio n. 2
0
 /**
  * Add registration
  *
  * @param \GS\FestivalBundle\Entity\Registration $registration
  *
  * @return Person
  */
 public function addRegistration(\GS\FestivalBundle\Entity\Registration $registration)
 {
     $this->registrations[] = $registration;
     $registration->setPerson($this);
     return $this;
 }