/**
  * @param CreateEventCommand $command
  */
 public function handle(CreateEventCommand $command)
 {
     $dojo = $this->doctrine->getRepository('CoderDojoWebsiteBundle:Dojo')->find($command->getDojoId());
     $event = new DojoEvent();
     $event->setName($command->getName());
     $event->setDate($command->getDate());
     $event->setType($command->getType());
     $event->setZenId($command->getZenId());
     $event->setUrl($command->getUrl());
     $event->setDojo($dojo);
     $dojo->addEvent($event);
     $this->doctrine->persist($event);
     $this->doctrine->flush();
     $event = new EventCreatedEvent($command->getDojoId(), $command->getName(), $command->getDate(), $command->getUrl(), $command->getZenId(), $command->getType());
     $this->eventRecorder->record($event);
 }
 /**
  * @Route("/events/{id}/add", name="dashboard-dojo-events-add")
  */
 public function addEventAction(Request $request, $id)
 {
     /** @var User $user */
     $user = $this->getUser();
     $dojo = $this->getDoctrine()->getRepository('CoderDojoWebsiteBundle:Dojo')->find($id);
     if (false === $dojo->isOwner($user)) {
         $this->get('session')->getFlashBag()->add('error', 'Zo te zien heb je geen rechten om aan deze dojo een event toe te voegen.');
         return $this->redirectToRoute('dashboard');
     }
     $form = $this->createForm(EventFormType::class);
     if ($request->isMethod('POST')) {
         $form->handleRequest($request);
         if ($form->isValid()) {
             $event = new DojoEvent();
             $event->setName($form->get('name')->getData());
             $event->setDate($form->get('date')->getData());
             $event->setUrl($form->get('url')->getData());
             $event->setType(DojoEvent::TYPE_CUSTOM);
             $event->setDojo($dojo);
             $dojo->addEvent($event);
             $this->getDoctrine()->getManager()->persist($event);
             $this->getDoctrine()->getManager()->flush();
             $this->get('session')->getFlashBag()->add('success', 'Dit event is toegevoegd!');
             return $this->redirectToRoute('dashboard-dojo-events', ['id' => $dojo->getId()]);
         } else {
             return $this->render('CoderDojoWebsiteBundle:Dashboard:Pages/events-add.html.twig', ['form' => $form->createView(), 'dojo' => $dojo]);
         }
     }
     return $this->render('CoderDojoWebsiteBundle:Dashboard:Pages/events-add.html.twig', ['form' => $form->createView(), 'dojo' => $dojo]);
 }