예제 #1
0
 public function getAction($request, $db)
 {
     $talk_id = $this->getItemId($request);
     // verbosity
     $verbose = $this->getVerbosity($request);
     // pagination settings
     $start = $this->getStart($request);
     $resultsperpage = $this->getResultsPerPage($request);
     $list = array();
     if (isset($request->url_elements[4])) {
         switch ($request->url_elements[4]) {
             case 'comments':
                 $comment_mapper = new TalkCommentMapper($db, $request);
                 $list = $comment_mapper->getCommentsByTalkId($talk_id, $resultsperpage, $start, $verbose);
                 break;
             case 'starred':
                 $mapper = new TalkMapper($db, $request);
                 $list = $mapper->getUserStarred($talk_id, $request->user_id);
                 break;
         }
     } else {
         if ($talk_id) {
             $list = $this->getTalkById($db, $request, $talk_id, $verbose);
             if (false === $list) {
                 throw new Exception('Talk not found', 404);
             }
         } else {
             if (isset($request->parameters['title'])) {
                 $keyword = filter_var($request->parameters['title'], FILTER_SANITIZE_STRING);
                 $mapper = new TalkMapper($db, $request);
                 $list = $mapper->getTalksByTitleSearch($keyword, $resultsperpage, $start, $verbose);
             } else {
                 // listing makes no sense
                 throw new Exception('Generic talks listing not supported', 405);
             }
         }
     }
     return $list;
 }