diff options
author | Bharat Mediratta <bharat@menalto.com> | 2010-02-12 04:53:26 -0800 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2010-02-12 04:53:26 -0800 |
commit | ce71ea6aa7eac72e54b1a9d7722c87beb61327de (patch) | |
tree | 408e96382d1cdf782ea6e2a0afbfd92770cfb9ad | |
parent | 3439671bcfb99c1884285e4b4e53295f044e688f (diff) |
Revert "1) Add a depth parameter to retrieving an item thru the rest api"
This reverts commit 3439671bcfb99c1884285e4b4e53295f044e688f.
-rw-r--r-- | modules/gallery/helpers/item_rest.php | 14 | ||||
-rw-r--r-- | modules/gallery/models/item.php | 41 |
2 files changed, 17 insertions, 38 deletions
diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php index 72230d8b..c0fc422a 100644 --- a/modules/gallery/helpers/item_rest.php +++ b/modules/gallery/helpers/item_rest.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 @@ class item_rest_Core { $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) { diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index a1be4fbc..dbd56fa2 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -918,49 +918,22 @@ class Item_Model extends ORM_MPTT { /** * 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; } } |