public function manageAddAction()
 {
     $eid = $this->getRequest()->query->get('eid');
     $url = "https://www.eventbriteapi.com/v3/events/" . $eid . "/?token=CT3M6TIFGKYO5CM7QWOK";
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_URL, $url);
     $result = curl_exec($ch);
     curl_close($ch);
     $result = json_decode($result);
     if (isset($result->error)) {
         $msg = "Er is iets mis gegaan. Wellicht klopt de Eventbrite id niet?";
     } else {
         if ($result->organizer_id == $this->getUser()->getOrganiser()) {
             $em = $this->getDoctrine()->getManager();
             $dojo = new DojoEvent();
             $dojo->setName($result->name->text)->setDate(new \DateTime($result->start->local))->setUrl($result->url)->setDojo($this->getUser());
             $this->getUser()->addDojo($dojo);
             $em->persist($dojo);
             $em->flush();
             $msg = "ok";
         } else {
             $msg = "Deze dojo hoort niet bij jouw organizer id";
         }
     }
     return new Response($msg);
 }
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $dojo = new DojoEvent();
     $dojo->setName('CoderDojo #12')->setDojoDate(new \DateTime('12-12-2025 12:00:00'))->setUrl('http://www.eventbrite.nl/e/registratie-19-vrije-editie-zondag-18482884806')->setDojo($this->getReference('user'));
     $this->getReference('user')->addDojo($dojo);
     $manager->persist($dojo);
     $manager->flush();
 }
예제 #3
0
 /**
  * @Route("/mijn-dojo/beheren/toevoegen", name="new-dojo")
  * @param Request $request
  * @return Response
  */
 public function manageAddAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $eid = $request->query->get('eid');
     if (0 === preg_match('/^[0-9]{9,15}$/', $eid)) {
         return new Response('Dit is geen geldig ID. Een id bestaat uit 10 cijfers, bijv. 11528212193.');
     }
     $url = "https://www.eventbriteapi.com/v3/events/" . $eid . "/?token=" . $this->container->getParameter('eventbrite_api_token');
     $dojoEvent = $em->getRepository('CoderDojoWebsiteBundle:DojoEvent')->findOneBy(['eventbriteId' => $eid]);
     if (null !== $dojoEvent) {
         return new Response('Dit event is al toegevoegd!');
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_URL, $url);
     $result = curl_exec($ch);
     curl_close($ch);
     $result = json_decode($result);
     if (isset($result->error)) {
         $this->get('logger')->addError('Error with EventBrite API for ' . $this->getUser()->getCity() . ' : ' . $result->error);
         $msg = "Er is iets mis gegaan. Wellicht klopt de Eventbrite id niet?";
     } else {
         if ($result->organizer_id == $this->getUser()->getOrganiser()) {
             $dojo = new DojoEvent();
             $dojo->setName($result->name->text)->setDate(new \DateTime($result->start->local))->setUrl($result->url)->setUser($this->getUser())->setEventbriteId($eid);
             $this->getUser()->addDojo($dojo);
             $em->persist($dojo);
             $em->flush();
             $msg = sprintf("%s heeft een nieuwe dojo toegevoegd voor %s\n<%s|Registreer op Eventbrite>", $this->getUser()->getName(), $dojo->getDate()->format('d F Y'), $dojo->getUrl());
             try {
                 $this->get('coder_dojo.website_bundle.slack_service')->sendToChannel('#general', $msg);
             } catch (\Exception $exception) {
                 // Fail silently so dojo's can still be added
                 $this->get('logger')->addError('Error with Slack for dojo ' . $this->getUser()->getCity() . ': ' . $exception->getMessage());
             }
             $msg = "ok";
         } else {
             $msg = "Deze dojo hoort niet bij jouw organizer id";
         }
     }
     return new Response($msg);
 }
예제 #4
0
 /**
  * @test
  */
 public function it_should_return_constructor_data()
 {
     $this->assertSame('url', $this->dojoEvent->getUrl());
     $this->assertSame('dojo', $this->dojoEvent->getName());
     $this->assertSame($this->dojo, $this->dojoEvent->getDojo());
     $this->assertNull($this->dojoEvent->getId());
     $this->assertSame(\DateTime::class, get_class($this->dojoEvent->getDate()));
 }
 /**
  * @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]);
 }