From 1aeaa7daabf2c00df45088f4a90615b463fb9f90 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 16 Jun 2010 18:05:15 -0700 Subject: Add REST support for comments. You can view, add, edit and delete comments. --- modules/comment/models/comment.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'modules/comment/models') diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php index fb70c79a..772e8b60 100644 --- a/modules/comment/models/comment.php +++ b/modules/comment/models/comment.php @@ -175,4 +175,20 @@ class Comment_Model extends ORM { static function valid_state($value) { return in_array($value, array("published", "unpublished", "spam", "deleted")); } + + /** + * Same as ORM::as_array() but convert id fields into their RESTful form. + */ + public function as_restful_array() { + $data = array(); + foreach ($this->as_array() as $key => $value) { + if (strncmp($key, "server_", 7)) { + $data[$key] = $value; + } + } + $data["item"] = rest::url("item", $this->item()); + unset($data["item_id"]); + + return $data; + } } -- cgit v1.2.3