summaryrefslogtreecommitdiff
path: root/modules/gallery/models
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-01-30 23:36:11 -0800
committerBharat Mediratta <bharat@menalto.com>2010-01-30 23:36:11 -0800
commitd29028c4ea9002ac036a89a4478fb4640c86fedb (patch)
tree809277c1750f97c4625242d2e881b30df5554ad4 /modules/gallery/models
parent69636955695476622b7f3019922afff14ea66380 (diff)
Add Item_Model::as_restful_array() for convenience.
Diffstat (limited to 'modules/gallery/models')
-rw-r--r--modules/gallery/models/item.php17
1 files changed, 17 insertions, 0 deletions
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;
+ }
}