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, $request, $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;
             default:
                 throw new InvalidArgumentException('Unknown Subrequest', 404);
                 break;
         }
     } else {
         $mapper = new EventMapper($db, $request);
         if ($event_id) {
             $list = $mapper->getEventById($event_id, $verbose);
         } else {
             // check if we're filtering
             if (isset($request->parameters['filter'])) {
                 switch ($request->parameters['filter']) {
                     case "hot":
                         $list = $mapper->getHotEventList($resultsperpage, $start, $verbose);
                         break;
                     case "upcoming":
                         $list = $mapper->getUpcomingEventList($resultsperpage, $start, $verbose);
                         break;
                     case "past":
                         $list = $mapper->getPastEventList($resultsperpage, $start, $verbose);
                         break;
                     case "cfp":
                         $list = $mapper->getOpenCfPEventList($resultsperpage, $start, $verbose);
                         break;
                     default:
                         throw new InvalidArgumentException('Unknown event filter', 404);
                         break;
                 }
             } else {
                 $list = $mapper->getEventList($resultsperpage, $start, $verbose);
             }
         }
     }
     return $list;
 }
 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;
 }