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())); }
public function load(ObjectManager $manager) { $festival = new Festival(); $festival->setName('GSDF'); $festival->setDescription('test'); $festival->setLocation('Grenoble'); $festival->setDate(new \Datetime('2016-11-10')); $level1 = new Level(); $level1->setName('Flocon'); $level1->setDescription('toto'); $level1->setCapacity(15); $level1->setExtraPerson(2); $level1->setPrice(80.0); $level2 = new Level(); $level2->setName('1ere Etoile'); $level2->setDescription('titi'); $level2->setCapacity(17); $level2->setExtraPerson(2); $level2->setPrice(150.0); for ($i = 0; $i < 15; $i++) { $phoneNumber = $this->container->get('libphonenumber.phone_number_util')->parse('0380581981', 'FR'); $person = new Person(); $person->setFirstName('Toto' . $i); $person->setLastName('Titi' . $i); $person->setEmail('bibi' . $i . '@gmail.com'); $person->setPhoneNumber($phoneNumber); $registration = new Registration(); if ($i % 2 || $i > 10) { $registration->setRole(True); } else { $registration->setRole(False); } $person->addRegistration($registration); $level1->addRegistration($registration); } for ($i = 0; $i < 15; $i++) { $person = new Person(); $person->setFirstName('Tata' . $i); $person->setLastName('Tutu' . $i); $person->setEmail('baba' . $i . '@gmail.com'); $registration = new Registration(); if ($i % 2 && $i < 11) { $registration->setRole(True); } else { $registration->setRole(False); } $person->addRegistration($registration); $level2->addRegistration($registration); } $festival->addLevel($level1); $festival->addLevel($level2); $manager->persist($festival); $manager->flush(); }