public function createEventAction(Request $request) { if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) { // Sinon on redirige vers le formulaire de création de compte $session = $request->getSession(); $session->getFlashBag()->add('info', 'Vous devez être connecté pour créer un événement! '); return $this->redirectToRoute("fos_user_security_login"); } // On crée un objet Event $event = new Event(); // formulaire de création d'événement $form = $this->createFormBuilder($event)->add('startdate', DateType::class)->add('name', TextType::class)->add('save', SubmitType::class)->getForm(); $event->setOwner($this->getUser()); $form->handleRequest($request); // On vérifie que les valeurs entrées sont correctes if ($form->isValid()) { // On l'enregistre notre objet $user dans la base de données, par exemple $em = $this->getDoctrine()->getManager(); $em->persist($event); $em->flush(); $session = $request->getSession()->getFlashBag()->add('notice', "L'événement a bien été créé."); //ajout dans la base user event pour la répartition $userEvent = new UserEvent(); $userEvent->setUser($this->getUser()); $userEvent->setEvent($event); $em->persist($userEvent); $em->flush(); // On redirige vers la page de visualisation du compte nouvellement créé return $this->redirect($this->generateUrl('gift_invitation', array('id' => $event->getId(), 'token' => $event->getToken()))); } return $this->render('giftBundle:Default:createEvent.html.twig', array('form' => $form->createView())); }
public function createUserEventAction(Request $request, $sharedToken) { if (!$this->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_REMEMBERED')) { return $this->redirectToRoute('fos_user_security_login', array("sharedToken" => $sharedToken)); } $em = $this->getDoctrine()->getManager(); $event = $em->getRepository('giftBundle:Event')->findOneBy(array('sharedToken' => $sharedToken)); // On crée un objet UserEvent $userEvent = new UserEvent(); $userEvent->setUser($this->getUser()); $userEvent->setEvent($event); $em->persist($userEvent); $em->flush(); $session = $request->getSession(); $session->getFlashBag()->add('notice', "Vous avez été ajouté à l'événement."); // On redirige vers la page de visualisation des event return $this->redirect($this->generateUrl('gift_myAccount', array('session' => $session))); }
public function load(ObjectManager $manager) { $user = new User(); $user->setUsername('user'); $user->setPassword('$2a$04$KO68Ijmly1ibMcAfxQfv7uCs71JdAiUvkWxpc/NwaFVgmpwHERL8W'); $user->setLastname('Chaks'); $user->setFirstname('Alex'); $user->setEmail('*****@*****.**'); $user->setEnabled(true); $event = new Event(); $event->setName('Party'); $event->setIsDistributed(false); $event->setStartDate(new \DateTime("2020-12-31 12:13:40")); $event->setToken('aa'); $event->setSharedToken('bb'); $userEvent = new UserEvent(); $userEvent->setEvent($event); $userEvent->setUser($user); $manager->persist($user); $manager->persist($event); $manager->persist($userEvent); $manager->flush(); }
public function load(ObjectManager $manager) { $userAdmin = new User(); $userAdmin->setUsername('admin'); //$userAdmin->setPassword('$2a$04$m3JSssF2nmcdtcij/6qsLOgd7tXTSHDmJi0.nFGPoSUVQpcosIwqa'); $userAdmin->setPlainPassword('admin'); $userAdmin->setEmail('*****@*****.**'); $userAdmin->setFirstname('Mathieu'); $userAdmin->setLastname('Chabas'); $userAdmin->setEnabled(true); $visitor = new User(); $visitor->setUsername('visitor'); $visitor->setPlainPassword('visitor'); $visitor->setEmail('*****@*****.**'); $visitor->setFirstname('Dupont'); $visitor->setLastname('Dupont'); $visitor->setEnabled(true); $manager->persist($userAdmin); $manager->persist($visitor); $event = new Event(); $event->setName('Anniversaire'); $date = new \DateTime('2018-10-10 08:00:00'); $event->setStartDate($date); $event->setOwner($userAdmin); $userEvent = new UserEvent(); $userEvent->setUser($userAdmin); $userEvent->setEvent($event); $manager->persist($event); $manager->persist($userEvent); $event = new Event(); $event->setName('Marathon'); $date = new \DateTime('2016-10-10 10:00:00'); $event->setStartDate($date); $event->setOwner($visitor); $userEvent = new UserEvent(); $userEvent->setUser($visitor); $userEvent->setEvent($event); $manager->persist($event); $manager->persist($userEvent); $visitor = new User(); $visitor->setUsername('visitor2'); $visitor->setPlainPassword('visitor2'); $visitor->setEmail('*****@*****.**'); $visitor->setFirstname('Dupont2'); $visitor->setLastname('Dupont2'); $visitor->setEnabled(true); $manager->persist($visitor); $visitor = new User(); $visitor->setUsername('visitor3'); $visitor->setPlainPassword('visitor3'); $visitor->setEmail('*****@*****.**'); $visitor->setFirstname('Dupont3'); $visitor->setLastname('Dupont3'); $visitor->setEnabled(true); $manager->persist($visitor); $visitor = new User(); $visitor->setUsername('visitor4'); $visitor->setPlainPassword('visitor4'); $visitor->setEmail('*****@*****.**'); $visitor->setFirstname('Dupont4'); $visitor->setLastname('Dupont4'); $visitor->setEnabled(true); $manager->persist($visitor); $visitor = new User(); $visitor->setUsername('visitor5'); $visitor->setPlainPassword('visitor5'); $visitor->setEmail('*****@*****.**'); $visitor->setFirstname('Dupont5'); $visitor->setLastname('Dupont5'); $visitor->setEnabled(true); $manager->persist($visitor); $manager->flush(); }
/** * @Route("/event/{shared_token}") */ public function registerNewParticipantAction(Request $request) { $repository = $this->getDoctrine()->getManager()->getRepository('GiftBundle:Event'); $em = $this->getDoctrine()->getManager(); $event = $repository->findBy(array('sharedToken' => $request->get("shared_token"))); $user = $this->getUser(); $userEvent = new UserEvent(); $userEvent->setEvent($event[0]); $userEvent->setUser($user); $UserEventFromDatabase = $em->getRepository('GiftBundle:UserEvent')->findBy(array('user' => $user, 'event' => $event)); if ($UserEventFromDatabase === null) { $em->persist($userEvent); $em->flush(); } return $this->redirect($this->generateUrl('gift_default_singleevent', array('eventId' => $event[0]->getId()))); }