Exemple #1
0
 public function dispatch(Request $request, Response $response, $args)
 {
     if (isset($args['callback']) && $args['callback'] === 'joindin') {
         // if logged in
         if ($this->auth->isLoggedIn() && strlen($request->getParam('access_token', '')) > 0) {
             // store token
             $this->fileRepository->save($this->auth->getUserId() . '_joindin', $request->getParam('access_token'));
         }
     }
     return $response->withStatus(302)->withHeader('Location', '/');
 }
 public function dispatch(Request $request, Response $response, $args)
 {
     $meetupID = $request->getAttribute('meetup_id', null);
     $eventInfo = $this->eventService->getInfoByMeetupID($meetupID);
     if ($eventInfo->eventExists()) {
         $this->flash->addMessage('event', 'Event already exists. Check its status.');
         return $response->withStatus(302)->withHeader('Location', 'event-details/' . $meetupID);
     }
     if (!$eventInfo->isRegistered() && !is_null($meetupID)) {
         $this->flash->addMessage('event', 'No event found for meetupID provided. Please create a new event.');
         return $response->withStatus(302)->withHeader('Location', 'create-event');
     }
     $form = new CreateEventForm($this->eventManager, $this->eventService);
     if ($eventInfo->isRegistered()) {
         $form->setEventInfo($eventInfo);
     }
     $data = ['form' => $form, 'errors' => $this->flash->getMessage('event') ?? [], 'defaultTime' => $this->eventsConfig->defaultStartTime];
     if ($request->isPost()) {
         $form->populate($request->getParams());
         if (!$form->isValid()) {
             // return response
             $data['errors'] = $form->getErrors();
             $data = array_merge($data, $this->getCsrfValues($request));
             $response->withStatus(304);
             $this->view->render($response, 'admin/create-event.twig', $data);
             return $response;
         }
         try {
             $event = EventFactory::getEvent($form->getTalkTitle(), $form->getTalkDescription(), $form->getEventDate(), $form->getSpeaker(), $form->getVenue(), $form->getSupporter(), $this->eventsConfig->title, $this->eventsConfig->description);
             $createEventInfo = $this->eventService->createMainEvents($event, $this->auth->getUserId(), $meetupID);
             if (!is_null($createEventInfo['joindin_message'])) {
                 $this->flash->addMessage('event', $createEventInfo['joindin_message']);
             }
             return $response->withStatus(302)->withHeader('Location', 'event-details?meetup_id=' . $createEventInfo['meetup_id']);
         } catch (\Exception $e) {
             $this->logger->debug($e->getMessage());
             $this->logger->debug(print_r($data['errors'], true));
             $data['errors'] = array_merge($data['errors'], [$e->getMessage()]);
         }
     }
     $data = array_merge($data, $this->getCsrfValues($request));
     $this->view->render($response, 'admin/create-event.twig', $data);
     return $response;
 }