Beispiel #1
0
 /**
  * @Route("/event/event/attend/{id}", name="event_event_attend")
  */
 public function attendAction($id)
 {
     $em = $this->getDoctrine()->getEntityManager();
     $event = $em->find('ClubEventBundle:Event', $id);
     $attend = new \Club\EventBundle\Entity\Attend();
     $attend->setUser($this->get('security.context')->getToken()->getUser());
     $attend->setEvent($event);
     if ($event->getPrice() == 0) {
         $attend->setPaid(1);
     } else {
         $attend->setPaid(0);
     }
     $errors = $this->get('validator')->validate($attend);
     if (count($errors) > 0) {
         foreach ($errors as $error) {
             $this->get('session')->setFlash('error', $error->getMessage());
         }
     } else {
         $em->persist($attend);
         $em->flush();
         $this->get('session')->setFlash('notice', $this->get('translator')->trans('Your changes are saved.'));
         $e = new \Club\EventBundle\Event\FilterEventEvent($event);
         $this->get('event_dispatcher')->dispatch(\Club\EventBundle\Event\Events::onEventAttend, $e);
     }
     return $this->redirect($this->generateUrl('event_event'));
 }
 /**
  * @Route("/{id}/attend")
  * @Method("POST")
  */
 public function attendAction($id)
 {
     if (false === $this->get('security.context')->isGranted('ROLE_USER')) {
         throw new AccessDeniedException();
     }
     $em = $this->getDoctrine()->getManager();
     $event = $em->find('ClubEventBundle:Event', $id);
     $user = $this->getUser();
     $attend = new \Club\EventBundle\Entity\Attend();
     $attend->setUser($user);
     $attend->setEvent($event);
     $event->addAttends($attend);
     $em->persist($event);
     $em->flush();
     $response = new Response();
     return $response;
 }