From 3439671bcfb99c1884285e4b4e53295f044e688f Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 12 Feb 2010 09:52:57 -0800 Subject: 1) Add a depth parameter to retrieving an item thru the rest api 2) Standardize the structure of members so that client programs can consistently parse the return information. 3) Added a summary parameter so that client programs can easily determine if the information returned is summary (item type, item title) or the full meal deal --- modules/gallery/models/item.php | 41 ++++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index dbd56fa2..a1be4fbc 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -918,22 +918,49 @@ class Item_Model extends ORM_MPTT { /** * Same as ORM::as_array() but convert id fields into their RESTful form. */ - public function as_restful_array() { + public function as_restful_array($depth=0, $level=0) { // Convert item ids to rest URLs for consistency - $data = $this->as_array(); + $data = array("url" => rest::url("item", $this), + "entity" => $this->as_array(), + "members" => array(), + "relationships" => array()); + if ($tmp = $this->parent()) { - $data["parent"] = rest::url("item", $tmp); + $data["entity"]["parent"] = rest::url("item", $tmp); } - unset($data["parent_id"]); + unset($data["entity"]["parent_id"]); if ($tmp = $this->album_cover()) { - $data["album_cover"] = rest::url("item", $tmp); + $data["entity"]["album_cover"] = rest::url("item", $tmp); } - unset($data["album_cover_item_id"]); + unset($data["entity"]["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[$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); + } } + $data["summary"] = $summarize; return $data; } } -- cgit v1.2.3 From ce71ea6aa7eac72e54b1a9d7722c87beb61327de Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 12 Feb 2010 04:53:26 -0800 Subject: Revert "1) Add a depth parameter to retrieving an item thru the rest api" This reverts commit 3439671bcfb99c1884285e4b4e53295f044e688f. --- modules/gallery/helpers/item_rest.php | 14 ++++++++---- modules/gallery/models/item.php | 41 ++++++----------------------------- 2 files changed, 17 insertions(+), 38 deletions(-) (limited to 'modules/gallery/models') 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= * only return items where the name contains this substring * - * depth= - * 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; } } -- cgit v1.2.3 From 897215689c3b85e6df9085291b3a5b60b7e69b08 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sun, 14 Feb 2010 07:32:35 -0800 Subject: Remove the dirty flags from the information returned from the rest request for an item. In addition, add links to the images. --- modules/gallery/models/item.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index dbd56fa2..283654c7 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -930,8 +930,18 @@ class Item_Model extends ORM_MPTT { } unset($data["album_cover_item_id"]); + if (access::can("view_fillsize", $this) && $this->is_photo()) { + $data["fullsize_url"] = $this->abs_url(); + } + + if ($tmp = $this->resize_url() && $this->is_photo()) { + $data["resize_url"] = $tmp; + } + $data["thumb_url"] = $this->thumb_url(); + // 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) { + foreach (array("relative_path_cache", "relative_url_cache", "left_ptr", "right_ptr", + "thumb_dirty", "resize_dirty") as $key) { unset($data[$key]); } return $data; -- cgit v1.2.3 From a597b57210b48241781f31d3f277e274d3ca6874 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 15 Feb 2010 12:29:49 -0800 Subject: return the absolute url not the relative for the full size, resize and thumb images. --- modules/gallery/models/item.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 283654c7..a64bcb49 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -931,13 +931,13 @@ class Item_Model extends ORM_MPTT { unset($data["album_cover_item_id"]); if (access::can("view_fillsize", $this) && $this->is_photo()) { - $data["fullsize_url"] = $this->abs_url(); + $data["fullsize_url"] = $this->abs_url(true); } - if ($tmp = $this->resize_url() && $this->is_photo()) { + if ($tmp = $this->resize_url(true) && $this->is_photo()) { $data["resize_url"] = $tmp; } - $data["thumb_url"] = $this->thumb_url(); + $data["thumb_url"] = $this->thumb_url(true); // 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", -- cgit v1.2.3 From 10c06989493bdded5f15880baadbc93c5d8ee296 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 19 Feb 2010 11:48:54 -0800 Subject: Correct the view_fillsize permission to view_full. In addition, change the name of the field containing the url to the fullsize image to file_url instead of fullzie_url --- modules/gallery/models/item.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index a64bcb49..d80e2bc4 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -930,11 +930,11 @@ class Item_Model extends ORM_MPTT { } unset($data["album_cover_item_id"]); - if (access::can("view_fillsize", $this) && $this->is_photo()) { - $data["fullsize_url"] = $this->abs_url(true); + if (access::can("view_full", $this) && $this->is_photo()) { + $data["file_url"] = $this->abs_url(true); } - if ($tmp = $this->resize_url(true) && $this->is_photo()) { + if ($tmp = $this->resize_url(true) && $this->is_photo()) { $data["resize_url"] = $tmp; } $data["thumb_url"] = $this->thumb_url(true); -- cgit v1.2.3 From 5fbc472300ce6b19a2694a5f91b1fe0b2cc470f3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 19 Feb 2010 11:54:03 -0800 Subject: Fix the resize_url and file_url in as_restful_array() --- modules/gallery/models/item.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'modules/gallery/models') diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index d80e2bc4..d747b84d 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -931,10 +931,10 @@ class Item_Model extends ORM_MPTT { unset($data["album_cover_item_id"]); if (access::can("view_full", $this) && $this->is_photo()) { - $data["file_url"] = $this->abs_url(true); + $data["file_url"] = $this->file_url(true); } - if ($tmp = $this->resize_url(true) && $this->is_photo()) { + if (($tmp = $this->resize_url(true)) && $this->is_photo()) { $data["resize_url"] = $tmp; } $data["thumb_url"] = $this->thumb_url(true); -- cgit v1.2.3