summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-01-22 00:27:00 -0800
committerBharat Mediratta <bharat@menalto.com>2010-01-22 00:27:00 -0800
commitbcf1caad1459a458a7923335a4a6bc521816de40 (patch)
treefc3815c13e079d0b1b25f3929dcb73f2de7ca927 /modules/gallery/helpers
parent3665391f8bbf40aa27acc816dc546237461e1cba (diff)
Reshape the rest code to be more consistent with regards to
relationships. Now when you view a resource, it has 4 top level elements: url: the url of this resource resource: array of key value pairs describing the resource members: array of urls to members of this collection relationships: array of array of members. Relationships are a special type of collection that links two different resources together. To remove a relationship, just DELETE its url. To create a relationship, POST to its collection. Individual modules can add their own relationships to any resource via a callback mechanism. Example: Array( [url] => http://g3.com/rest/item/1 [resource] => Array ( [id] => 1 [album_cover_item_id] => 4 [captured] => [created] => 1264056417 [description] => [height] => ... ) [members] => Array( [0] => http://g3.com/rest/item/2 [1] => http://g3.com/rest/item/3 [2] => http://g3.com/rest/item/4 [3] => http://g3.com/rest/item/5 ... ) [relationships] => Array( [tags] => Array ( [0] => http://g3.com/rest/tag_item/2,1 [1] => http://g3.com/rest/tag_item/23,1 ) ) )
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/item_rest.php (renamed from modules/gallery/helpers/gallery_rest.php)28
1 files changed, 17 insertions, 11 deletions
diff --git a/modules/gallery/helpers/gallery_rest.php b/modules/gallery/helpers/item_rest.php
index c5838ea5..edc44c45 100644
--- a/modules/gallery/helpers/gallery_rest.php
+++ b/modules/gallery/helpers/item_rest.php
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
-class gallery_rest_Core {
+class item_rest_Core {
/**
* For items that are collections, you can specify the following additional query parameters to
* query the collection. You can specify them in any combination.
@@ -72,10 +72,14 @@ class gallery_rest_Core {
$members = array();
foreach ($orm->find_all() as $child) {
- $members[] = rest::url("gallery", $child);
+ $members[] = rest::url("item", $child);
}
- return array("resource" => $item->as_array(), "members" => $members);
+ return array(
+ "url" => $request->url,
+ "resource" => $item->as_array(),
+ "members" => $members,
+ "relationships" => rest::relationships("item", $item));
}
static function put($request) {
@@ -94,9 +98,9 @@ class gallery_rest_Core {
$item->$key = $request->params->$key;
}
}
- $item->save();
-
- return array("url" => rest::url("gallery", $item));
+ if ($item->changed) {
+ $item->save();
+ }
}
static function post($request) {
@@ -131,8 +135,6 @@ class gallery_rest_Core {
default:
throw new Rest_Exception("Invalid type: $params->type", 400);
}
-
- return array("url" => rest::url("gallery", $item));
}
static function delete($request) {
@@ -142,11 +144,15 @@ class gallery_rest_Core {
$item->delete();
}
- static function resolve($path) {
- return url::get_item_from_uri($path);
+ static function resolve($id) {
+ $item = ORM::factory("item")->where("id", "=", $id)->find();
+ if (!access::can("view", $item)) {
+ throw new Kohana_404_Exception();
+ }
+ return $item;
}
static function url($item) {
- return url::abs_site("rest/gallery/" . $item->relative_url());
+ return url::abs_site("rest/item/{$item->id}");
}
}