示例#1
0
 public function deleteTrack($request, $db)
 {
     // Check for login
     if (!isset($request->user_id)) {
         throw new Exception("You must be logged in to delete this track", 401);
     }
     $track_id = $this->getItemId($request);
     $track_mapper = new TrackMapper($db, $request);
     $tracks = $track_mapper->getTrackById($track_id, true);
     if (!$tracks) {
         throw new Exception("Track not found", 404);
     }
     $event_mapper = new EventMapper($db, $request);
     $events = $event_mapper->getEventByTrackId($track_id, true, false, false);
     if (!$events || !$events[0]['ID']) {
         throw new Exception("Associated event not found", 404);
     }
     $event_id = $events[0]['ID'];
     if (!$event_mapper->thisUserHasAdminOn($event_id)) {
         throw new Exception('You do not have permission to delete this track', 403);
     }
     $track_mapper->deleteEventTrack($track_id);
     header("Content-Length: 0", null, 204);
     exit;
 }
 public function getAction($request, $db)
 {
     $track_id = $this->getItemId($request);
     // verbosity
     $verbose = $this->getVerbosity($request);
     if ($track_id) {
         $mapper = new TrackMapper($db, $request);
         $list = $mapper->getTrackById($track_id, $verbose);
         if (false === $list) {
             throw new Exception('Track not found', 404);
         }
     } else {
         // listing makes no sense
         throw new Exception('Generic tracks listing not supported', 405);
     }
     return $list;
 }
示例#3
0
 public function getAction($request, $db)
 {
     $event_id = $this->getItemId($request);
     // verbosity
     $verbose = $this->getVerbosity($request);
     // pagination settings
     $start = $this->getStart($request);
     $resultsperpage = $this->getResultsPerPage($request);
     if (isset($request->url_elements[4])) {
         switch ($request->url_elements[4]) {
             case 'talks':
                 $talk_mapper = new TalkMapper($db, $request);
                 $list = $talk_mapper->getTalksByEventId($event_id, $resultsperpage, $start, $verbose);
                 break;
             case 'comments':
                 $event_comment_mapper = new EventCommentMapper($db, $request);
                 $list = $event_comment_mapper->getEventCommentsByEventId($event_id, $resultsperpage, $start, $verbose);
                 break;
             case 'talk_comments':
                 $sort = $this->getSort($request);
                 $talk_comment_mapper = new TalkCommentMapper($db, $request);
                 $list = $talk_comment_mapper->getCommentsByEventId($event_id, $resultsperpage, $start, $verbose, $sort);
                 break;
             case 'attendees':
                 $user_mapper = new UserMapper($db, $request);
                 $list = $user_mapper->getUsersAttendingEventId($event_id, $resultsperpage, $start, $verbose);
                 break;
             case 'attending':
                 $mapper = new EventMapper($db, $request);
                 $list = $mapper->getUserAttendance($event_id, $request->user_id);
                 break;
             case 'tracks':
                 $mapper = new TrackMapper($db, $request);
                 $list = $mapper->getTracksByEventId($event_id, $resultsperpage, $start, $verbose);
                 break;
             default:
                 throw new InvalidArgumentException('Unknown Subrequest', 404);
                 break;
         }
     } else {
         $mapper = new EventMapper($db, $request);
         $user_mapper = new UserMapper($db, $request);
         $isSiteAdmin = $user_mapper->isSiteAdmin($request->user_id);
         $activeEventsOnly = $isSiteAdmin ? false : true;
         if ($event_id) {
             $list = $mapper->getEventById($event_id, $verbose, $activeEventsOnly);
             if (count($list['events']) == 0) {
                 throw new Exception('Event not found', 404);
             }
         } else {
             // handle the filter parameters
             $params = array();
             // collection type filter
             $filters = array("hot", "upcoming", "past", "cfp", "pending");
             if (isset($request->parameters['filter']) && in_array($request->parameters['filter'], $filters)) {
                 $params["filter"] = $request->parameters['filter'];
                 // for pending events we need a logged in user with the correct permissions
                 if ($params["filter"] == 'pending') {
                     if (!isset($request->user_id)) {
                         throw new Exception("You must be logged in to view pending events", 400);
                     }
                     $user_mapper = new UserMapper($db, $request);
                     $canApproveEvents = $user_mapper->isSiteAdmin($request->user_id);
                     if (!$canApproveEvents) {
                         throw new Exception("You don't have permission to view pending events", 403);
                     }
                 }
             }
             if (isset($request->parameters['title'])) {
                 $title = filter_var($request->parameters['title'], FILTER_SANITIZE_STRING);
                 $params["title"] = $title;
             }
             if (isset($request->parameters['stub'])) {
                 $stub = filter_var($request->parameters['stub'], FILTER_SANITIZE_STRING);
                 $params["stub"] = $stub;
             }
             if (isset($request->parameters['tags'])) {
                 // if it isn't an array, make it one
                 if (is_array($request->parameters['tags'])) {
                     foreach ($request->parameters['tags'] as $t) {
                         $tags[] = filter_var(trim($t), FILTER_SANITIZE_STRING);
                     }
                 } else {
                     $tags = array(filter_var(trim($request->parameters['tags']), FILTER_SANITIZE_STRING));
                 }
                 $params["tags"] = $tags;
             }
             if (isset($request->parameters['startdate'])) {
                 $start_datetime = new DateTime($request->parameters['startdate']);
                 if ($start_datetime) {
                     $params["startdate"] = $start_datetime->format("U");
                 }
             }
             if (isset($request->parameters['enddate'])) {
                 $end_datetime = new DateTime($request->parameters['enddate']);
                 if ($end_datetime) {
                     $params["enddate"] = $end_datetime->format("U");
                 }
             }
             $list = $mapper->getEventList($resultsperpage, $start, $params, $verbose);
         }
     }
     return $list;
 }
示例#4
0
 /**
  * Create track
  *
  * @param  Request $request
  * @param  PDO $db
  *
  * @return void
  */
 public function createTrack($request, $db)
 {
     // Check for login
     if (!isset($request->user_id)) {
         throw new Exception("You must be logged in to create a track", 401);
     }
     $track = array();
     $event_id = $this->getItemId($request);
     $track['event_id'] = $event_id;
     if (empty($track['event_id'])) {
         throw new Exception("POST expects a track representation sent to a specific event URL", 400);
     }
     $event_mapper = new EventMapper($db, $request);
     $events = $event_mapper->getEventById($event_id, true);
     if (!$events || $events['meta']['count'] == 0) {
         throw new Exception("Associated event not found", 404);
     }
     if (!$event_mapper->thisUserHasAdminOn($event_id)) {
         throw new Exception('You do not have permission to edit this track', 403);
     }
     // validate fields
     $errors = [];
     $track['track_name'] = filter_var($request->getParameter("track_name"), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
     if (empty($track['track_name'])) {
         $errors[] = "'track_name' is a required field";
     }
     $track['track_description'] = filter_var($request->getParameter("track_description"), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
     if (empty($track['track_description'])) {
         $errors[] = "'track_description' is a required field";
     }
     if ($errors) {
         throw new Exception(implode(". ", $errors), 400);
     }
     $track_mapper = new TrackMapper($db, $request);
     $track_id = $track_mapper->createEventTrack($track, $event_id);
     $uri = $request->base . '/' . $request->version . '/tracks/' . $track_id;
     header("Location: " . $uri, null, 201);
     exit;
 }