From 2ed83fcd95deb8fc41b40b7ae4fe4b9cde0003be Mon Sep 17 00:00:00 2001 From: Kriss Andsten Date: Sat, 27 Nov 2010 05:36:25 +0800 Subject: Patch from ticket 1503, making rest/items behaviour consisten with rest/item behaviour. --- modules/gallery/helpers/items_rest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'modules/gallery/helpers/items_rest.php') diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index f0b68d63..a5f7a067 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -45,7 +45,7 @@ class items_rest_Core { if (access::can("view", $item)) { if (isset($types)) { if (in_array($item->type, $types)) { - $items[] = items_rest::_format_restful_item($item); + $items[] = items_rest::_format_restful_item($item, $types); } } else { $items[] = items_rest::_format_restful_item($item); @@ -74,14 +74,16 @@ class items_rest_Core { return $item; } - private static function _format_restful_item($item) { + private static function _format_restful_item($item, $types = null) { $item_rest = array("url" => rest::url("item", $item), "entity" => $item->as_restful_array(), "relationships" => rest::relationships("item", $item)); if ($item->type == "album") { $members = array(); foreach ($item->viewable()->children() as $child) { - $members[] = rest::url("item", $child); + if ($types == null || in_array($child->type, $types)) { + $members[] = rest::url("item", $child); + } } $item_rest["members"] = $members; } -- cgit v1.2.3 From d2be26e407aeb620082bcad2d5a45272868b38a1 Mon Sep 17 00:00:00 2001 From: Kriss Andsten Date: Sun, 28 Nov 2010 10:56:58 +0800 Subject: Slightly more invasive version, but cleaner on the eyes. --- modules/gallery/helpers/items_rest.php | 38 ++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'modules/gallery/helpers/items_rest.php') diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index a5f7a067..da062819 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -25,7 +25,7 @@ class items_rest_Core { * filter the results based on the specified type. Using the type parameter with the * ancestors_for parameter makes no sense and will be ignored. * - * urls=url1,url2,url3 + * urls=["url1","url2","url3"] * return items that match the specified urls. Typically used to return the member detail * * ancestors_for=url @@ -33,23 +33,29 @@ class items_rest_Core { * * type= * limit the type to types in this list. eg, "type=photo,movie" + * + * also limits the types returned in the member collections (same + * behaviour as item_rest) + * + * ignored if ancestors_for is set. */ static function get($request) { $items = array(); + $types = array(); + if (isset($request->params->urls)) { + if (isset($request->params->type)) { + $types = explode(",", $request->params->type); + } + foreach (json_decode($request->params->urls) as $url) { - if (isset($request->params->type)) { - $types = explode(",", $request->params->type); - } $item = rest::resolve($url); - if (access::can("view", $item)) { - if (isset($types)) { - if (in_array($item->type, $types)) { - $items[] = items_rest::_format_restful_item($item, $types); - } - } else { - $items[] = items_rest::_format_restful_item($item); - } + if (!access::can("view", $item)) { + continue; + } + + if (empty($types) || in_array($item->type, $types)) { + $items[] = items_rest::_format_restful_item($item, $types); } } } else if (isset($request->params->ancestors_for)) { @@ -57,9 +63,9 @@ class items_rest_Core { if (!access::can("view", $item)) { throw new Kohana_404_Exception(); } - $items[] = items_rest::_format_restful_item($item); + $items[] = items_rest::_format_restful_item($item, $types); while (($item = $item->parent()) != null) { - array_unshift($items, items_rest::_format_restful_item($item)); + array_unshift($items, items_rest::_format_restful_item($item, $types)); }; } @@ -74,14 +80,14 @@ class items_rest_Core { return $item; } - private static function _format_restful_item($item, $types = null) { + private static function _format_restful_item($item, $types) { $item_rest = array("url" => rest::url("item", $item), "entity" => $item->as_restful_array(), "relationships" => rest::relationships("item", $item)); if ($item->type == "album") { $members = array(); foreach ($item->viewable()->children() as $child) { - if ($types == null || in_array($child->type, $types)) { + if (empty($types) || in_array($child->type, $types)) { $members[] = rest::url("item", $child); } } -- cgit v1.2.3 From f91819441c0f899f34c02264f9cbfdc6281980b9 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 27 Nov 2010 19:48:16 -0800 Subject: Tighten up the phpDoc for get(). --- modules/gallery/helpers/items_rest.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'modules/gallery/helpers/items_rest.php') diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index da062819..dd190e9d 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -33,11 +33,9 @@ class items_rest_Core { * * type= * limit the type to types in this list. eg, "type=photo,movie" - * - * also limits the types returned in the member collections (same - * behaviour as item_rest) - * - * ignored if ancestors_for is set. + * Also limits the types returned in the member collections (same + * behaviour as item_rest). + * Ignored if ancestors_for is set. */ static function get($request) { $items = array(); @@ -53,8 +51,8 @@ class items_rest_Core { if (!access::can("view", $item)) { continue; } - - if (empty($types) || in_array($item->type, $types)) { + + if (empty($types) || in_array($item->type, $types)) { $items[] = items_rest::_format_restful_item($item, $types); } } -- cgit v1.2.3 From 76b6daefaa4009fdd8de72b8f25259200a66d477 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Sat, 27 Nov 2010 20:42:53 -0800 Subject: Clean up phpDoc on get() a little more --- modules/gallery/helpers/item_rest.php | 11 ++++++----- modules/gallery/helpers/items_rest.php | 9 ++++----- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'modules/gallery/helpers/items_rest.php') diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 10f9e16a..a8bc36ad 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.php @@ -23,18 +23,19 @@ class item_rest_Core { * query the collection. You can specify them in any combination. * * scope=direct - * only return items that are immediately under this one + * Only return items that are immediately under this one * scope=all - * return items anywhere under this one + * Return items anywhere under this one * * name= - * only return items where the name contains this substring + * Only return items where the name contains this substring * * random=true - * return a single random item + * Return a single random item * * type= - * limit the type to types in this list. eg, "type=photo,movie" + * Limit the type to types in this list, eg: "type=photo,movie". + * Also limits the types returned in the member collections (same behaviour as item_rest). */ static function get($request) { $item = rest::resolve($request->url); diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php index dd190e9d..08aa3279 100644 --- a/modules/gallery/helpers/items_rest.php +++ b/modules/gallery/helpers/items_rest.php @@ -26,15 +26,14 @@ class items_rest_Core { * ancestors_for parameter makes no sense and will be ignored. * * urls=["url1","url2","url3"] - * return items that match the specified urls. Typically used to return the member detail + * Return items that match the specified urls. Typically used to return the member detail * * ancestors_for=url - * return the ancestors of the specified item + * Return the ancestors of the specified item * * type= - * limit the type to types in this list. eg, "type=photo,movie" - * Also limits the types returned in the member collections (same - * behaviour as item_rest). + * Limit the type to types in this list, eg: "type=photo,movie". + * Also limits the types returned in the member collections (same behaviour as item_rest). * Ignored if ancestors_for is set. */ static function get($request) { -- cgit v1.2.3