diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/comment/controllers/comments.php | 18 | ||||
-rw-r--r-- | modules/comment/helpers/comment.php | 12 | ||||
-rw-r--r-- | modules/user/controllers/users.php | 8 |
3 files changed, 28 insertions, 10 deletions
diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php index b51e7e4e..34557a83 100644 --- a/modules/comment/controllers/comments.php +++ b/modules/comment/controllers/comments.php @@ -22,10 +22,17 @@ class Comments_Controller extends REST_Controller { /** * Display comments based on criteria. - * @see Rest_Controller::_delete($resource) + * @see Rest_Controller::_index() */ - public function _index($query) { - throw new Exception("@todo Comment_Controller::_index NOT IMPLEMENTED"); + public function _index() { + $item_id = $this->input->get('item_id'); + + if (empty($item_id)) { + /* We currently do not support getting all comments from the entire gallery. */ + header("HTTP/1.1 400 Bad Request"); + return; + } + print comment::get_comments($item_id, $this->get_output_format()); } /** @@ -51,15 +58,18 @@ class Comments_Controller extends REST_Controller { /** * Display an existing comment. - * @see Rest_Controller::_show($resource, $format) + * @todo Set proper Content-Type in a central place (REST_Controller::dispatch?). + * @see Rest_Controller::_show($resource, $output_format) */ public function _show($comment, $output_format) { switch ($output_format) { case "xml": + header("Content-Type: application/xml"); print xml::to_xml($comment->as_array(), array("comment")); break; case "json": + header("Content-Type: application/json"); print json_encode($comment->as_array()); break; diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php index e474bf65..e9628a01 100644 --- a/modules/comment/helpers/comment.php +++ b/modules/comment/helpers/comment.php @@ -105,17 +105,25 @@ class Comment_Core { return $block; } - static function get_comments($item, $output_format) { - $comments = ORM::factory('comment')->where('item_id', $item->id) + // @todo Set proper Content-Type in a central place (REST_Controller::dispatch?). + static function get_comments($item_id, $output_format) { + $comments = ORM::factory('comment')->where('item_id', $item_id) ->orderby('datetime', 'asc') ->find_all(); + if (!$comments->count()) { + header("HTTP/1.1 400 Bad Request"); + return; + } + switch ($output_format) { case "xml": + header("Content-Type: application/xml"); return xml::to_xml($comments, array("comments", "comment")); break; case "json": + header("Content-Type: application/json"); foreach ($comments as $comment) { $data[] = $comment->as_array(); } diff --git a/modules/user/controllers/users.php b/modules/user/controllers/users.php index ea3a4c8b..d381d399 100644 --- a/modules/user/controllers/users.php +++ b/modules/user/controllers/users.php @@ -22,9 +22,9 @@ class Users_Controller extends REST_Controller { /** * Display comments based on criteria. - * @see Rest_Controller::_delete($resource) + * @see Rest_Controller::_index() */ - public function _index($query) { + public function _index() { throw new Exception("@todo Comment_Controller::_index NOT IMPLEMENTED"); } @@ -36,9 +36,9 @@ class Users_Controller extends REST_Controller { } /** - * @see Rest_Controller::_show($resource, $format) + * @see Rest_Controller::_show($resource, $output_format) */ - public function _show($user, $format) { + public function _show($user, $output_format) { throw new Exception("@todo User_Controller::_show NOT IMPLEMENTED"); } |