Permalink
Browse files

Revert "1) Add a depth parameter to retrieving an item thru the rest …

…api"

This reverts commit 3439671.
  • Loading branch information...
1 parent 3439671 commit ce71ea6aa7eac72e54b1a9d7722c87beb61327de @bharat bharat committed Feb 12, 2010
Showing with 17 additions and 38 deletions.
  1. +10 −4 modules/gallery/helpers/item_rest.php
  2. +7 −34 modules/gallery/models/item.php
@@ -30,9 +30,6 @@ class item_rest_Core {
* name=<substring>
* only return items where the name contains this substring
*
- * depth=<number>
- * return the children to the depth specified.
- *
* random=true
* return a single random item
*
@@ -73,7 +70,16 @@ static function get($request) {
$orm->where("type", "IN", explode(",", $p->type));
}
- return $item->as_restful_array(isset($p->depth) ? $p->depth : 0);
+ $members = array();
+ foreach ($orm->find_all() as $child) {
+ $members[] = rest::url("item", $child);
+ }
+
+ return array(
+ "url" => $request->url,
+ "entity" => $item->as_restful_array(),
+ "members" => $members,
+ "relationships" => rest::relationships("item", $item));
}
static function put($request) {
@@ -918,49 +918,22 @@ public function read_only(Validation $v, $field) {
/**
* Same as ORM::as_array() but convert id fields into their RESTful form.
*/
- public function as_restful_array($depth=0, $level=0) {
+ public function as_restful_array() {
// Convert item ids to rest URLs for consistency
- $data = array("url" => rest::url("item", $this),
- "entity" => $this->as_array(),
- "members" => array(),
- "relationships" => array());
-
+ $data = $this->as_array();
if ($tmp = $this->parent()) {
- $data["entity"]["parent"] = rest::url("item", $tmp);
+ $data["parent"] = rest::url("item", $tmp);
}
- unset($data["entity"]["parent_id"]);
+ unset($data["parent_id"]);
if ($tmp = $this->album_cover()) {
- $data["entity"]["album_cover"] = rest::url("item", $tmp);
+ $data["album_cover"] = rest::url("item", $tmp);
}
- unset($data["entity"]["album_cover_item_id"]);
+ unset($data["album_cover_item_id"]);
// Elide some internal-only data that is going to cause confusion in the client.
foreach (array("relative_path_cache", "relative_url_cache", "left_ptr", "right_ptr") as $key) {
- unset($data["entity"][$key]);
- }
-
- // check that we have given enough information. At this point we don't
- // return relationships and we give enough information to determine how to handle
- // the children.
- $summarize = $depth < $level;
- if (!$summarize) {
- $data["relationships"] = rest::relationships("item", $this);
- }
-
- $next_level = $level + 1;
- foreach ($this->children() as $child) {
- if ($summarize) {
- $data["members"][] = array("url" => rest::url("item", $child),
- "entity" => array("title" => $child->title,
- "type" => $child->type),
- "members" => array(),
- "summary" => true,
- "relationships" => array());
- } else {
- $data["members"][] = $child->as_restful_array($depth, $next_level);
- }
+ unset($data[$key]);
}
- $data["summary"] = $summarize;
return $data;
}
}

0 comments on commit ce71ea6

Please sign in to comment.