summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers/item_rest.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-01-30 15:46:31 -0800
committerBharat Mediratta <bharat@menalto.com>2010-01-30 15:46:35 -0800
commita161436015364a039107e767f8c4af91dbec89ed (patch)
treed91ad25738219f441d65fbd06d66bddb5dccc18c /modules/gallery/helpers/item_rest.php
parent923a515ffb33d0ba15730ef4716f8ffe45cf19fa (diff)
Remap parent_id and album_cover_item_id to and from RESTful urls.
Diffstat (limited to 'modules/gallery/helpers/item_rest.php')
-rw-r--r--modules/gallery/helpers/item_rest.php39
1 files changed, 34 insertions, 5 deletions
diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php
index d5ca1456..f5056bc1 100644
--- a/modules/gallery/helpers/item_rest.php
+++ b/modules/gallery/helpers/item_rest.php
@@ -75,9 +75,20 @@ class item_rest_Core {
$members[] = rest::url("item", $child);
}
+ // Convert item ids to rest URLs for consistency
+ $entity = $item->as_array();
+ if ($tmp = $item->parent()) {
+ $entity["parent"] = rest::url("item", $tmp);
+ }
+ unset($entity["parent_id"]);
+ if ($tmp = $item->album_cover()) {
+ $entity["album_cover"] = rest::url("item", $tmp);
+ }
+ unset($entity["album_cover_id"]);
+
return array(
"url" => $request->url,
- "entity" => $item->as_array(),
+ "entity" => $entity,
"members" => $members,
"relationships" => rest::relationships("item", $item));
}
@@ -89,13 +100,31 @@ class item_rest_Core {
$params = $request->params;
// Only change fields from a whitelist.
- foreach (array("album_cover_item_id", "captured", "description",
- "height", "mime_type", "name", "parent_id", "rand_key", "resize_dirty",
+ foreach (array("album_cover", "captured", "description",
+ "height", "mime_type", "name", "parent", "rand_key", "resize_dirty",
"resize_height", "resize_width", "slug", "sort_column", "sort_order",
"thumb_dirty", "thumb_height", "thumb_width", "title", "view_count",
"weight", "width") as $key) {
- if (property_exists($request->params, $key)) {
- $item->$key = $request->params->$key;
+ switch ($key) {
+ case "album_cover":
+ if (property_exists($request->params, "album_cover")) {
+ $album_cover_item = rest::resolve($request->params->album_cover);
+ access::required("view", $album_cover_item);
+ $item->album_cover_item_id = $album_cover_item->id;
+ }
+ break;
+
+ case "parent":
+ if (property_exists($request->params, "parent")) {
+ $parent = rest::resolve($request->params->parent);
+ access::required("edit", $parent);
+ $item->parent_id = $parent->id;
+ }
+ break;
+ default:
+ if (property_exists($request->params, $key)) {
+ $item->$key = $request->params->$key;
+ }
}
}
$item->save();