Ejemplo n.º 1
0
 /**
  * Approve a pending event by POSTing to /events/{id}/approval
  *
  * The body of this request is completely irrelevant, simply POSTing to this
  * endpoint is all that's needed to approve an pending event
  *
  * @param  Request $request
  * @param  PDO $db
  *
  * @return void
  */
 public function approveAction($request, $db)
 {
     if (!isset($request->user_id)) {
         throw new Exception("You must be logged in to create data", 400);
     }
     $event_id = $this->getItemId($request);
     $event_mapper = new EventMapper($db, $request);
     if (!$event_mapper->thisUserCanApproveEvents()) {
         throw new Exception("You are not allowed to approve this event", 403);
     }
     $result = $event_mapper->approve($event_id);
     if (!$result) {
         throw new Exception("This event cannot be approved", 400);
     }
     if ($result) {
         // Send a notification email as we have approved
         $event = $event_mapper->getEventById($event_id, true)['events'][0];
         $recipients = $event_mapper->getHostsEmailAddresses($event_id);
         $emailService = new EventApprovedEmailService($this->config, $recipients, $event);
         $emailService->sendEmail();
     }
     $location = $request->base . '/' . $request->version . '/events/' . $event_id;
     header('Location: ' . $location, null, 204);
     return;
 }