Ejemplo n.º 1
0
 public function reportComment($request, $db)
 {
     // must be logged in to report a comment
     if (!isset($request->user_id) || empty($request->user_id)) {
         throw new Exception('You must log in to report a comment');
     }
     $comment_mapper = new TalkCommentMapper($db, $request);
     $commentId = $this->getItemId($request);
     $commentInfo = $comment_mapper->getCommentInfo($commentId);
     if (false === $commentInfo) {
         throw new Exception('Comment not found', 404);
     }
     $talkId = $commentInfo['talk_id'];
     $eventId = $commentInfo['event_id'];
     $comment_mapper->userReportedComment($commentId, $request->user_id);
     // notify event admins
     $comment = $comment_mapper->getCommentById($commentId, true, true);
     $event_mapper = new EventMapper($db, $request);
     $recipients = $event_mapper->getHostsEmailAddresses($eventId);
     $emailService = new CommentReportedEmailService($this->config, $recipients, $comment);
     $emailService->sendEmail();
     // send them to the comments collection
     $uri = $request->base . '/' . $request->version . '/talks/' . $talkId . "/comments";
     header("Location: " . $uri, true, 202);
     exit;
 }
Ejemplo n.º 2
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;
 }