public function validateAttend(\Club\EventBundle\Entity\Event $event, \Club\UserBundle\Entity\User $user) { if (!$event->isOpen()) { throw new \Club\EventBundle\Exception\AttendNotAvailableException($this->trans->trans('Subscription to event is not open')); } $this->attend = new \Club\EventBundle\Entity\Attend(); $this->attend->setUser($user); $this->attend->setEvent($event); $errors = $this->validator->validate($this->attend); if (count($errors) > 0) { foreach ($errors as $error) { throw new EventException($error->getMessage()); } } }
/** * @Route("/unattend/{id}", name="event_event_unattend") */ public function unattendAction(\Club\EventBundle\Entity\Event $event) { if (!$event->isOpen()) { $this->get('session')->getFlashBag()->add('error', $this->get('translator')->trans('Subscription to event is not open')); } else { $em = $this->getDoctrine()->getManager(); $attend = $em->getRepository('ClubEventBundle:Attend')->findOneBy(array('user' => $this->getUser()->getId(), 'event' => $event->getId())); $em->remove($attend); $em->flush(); $this->get('session')->getFlashBag()->add('notice', $this->get('translator')->trans('Your changes are saved.')); $e = new \Club\EventBundle\Event\FilterAttendEvent($attend); $this->get('event_dispatcher')->dispatch(\Club\EventBundle\Event\Events::onEventUnattend, $e); } return $this->redirect($this->generateUrl('event_event')); }