Skip to content
Browse files

Slightly more invasive version, but cleaner on the eyes.

  • Loading branch information...
1 parent 3f0d54c commit d10ece5a6f9c9cf13d7879937219b051d4965d44 @kandsten kandsten committed with bharat Nov 28, 2010
Showing with 22 additions and 16 deletions.
  1. +22 −16 modules/gallery/helpers/items_rest.php
View
38 modules/gallery/helpers/items_rest.php
@@ -25,41 +25,47 @@ 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
* return the ancestors of the specified item
*
* type=<comma separate list of photo, movie or album>
* 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)) {
$item = rest::resolve($request->params->ancestors_for);
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 @@ static function resolve($id) {
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);
}
}

0 comments on commit d10ece5

Please sign in to comment.
Something went wrong with that request. Please try again.