From d29028c4ea9002ac036a89a4478fb4640c86fedb Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 30 Jan 2010 23:36:11 -0800 Subject: Add Item_Model::as_restful_array() for convenience. --- modules/gallery/models/item.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index ae6e4cc9..fd121a5a 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -914,4 +914,21 @@ class Item_Model extends ORM_MPTT { $v->add_error($field, "read_only"); } } + + /** + * Same as ORM::as_array() but convert id fields into their RESTful form. + */ + public function as_restful_array() { + // Convert item ids to rest URLs for consistency + $data = $this->as_array(); + if ($tmp = $this->parent()) { + $data["parent"] = rest::url("item", $tmp); + } + unset($data["parent_id"]); + if ($tmp = $this->album_cover()) { + $data["album_cover"] = rest::url("item", $tmp); + } + unset($data["album_cover_item_id"]); + return $data; + } } -- cgit v1.2.3