summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2010-06-07 22:23:46 -0700
committerBharat Mediratta <bharat@menalto.com>2010-06-07 22:23:46 -0700
commit98fce83de5f772482382bfabdbcd94c25ecdbb1a (patch)
tree35ac9fb925fdd25ef181d776b1211e19ea5346a6 /modules
parent5151f0b86526f619cb171a599f79a883addcf343 (diff)
Add a "convert_ids" parameter to Item_Model::as_restful_array(), which
we can turn on with a query parameter.
Diffstat (limited to 'modules')
-rw-r--r--modules/gallery/models/item.php20
-rw-r--r--modules/gallery/tests/Item_Model_Test.php12
2 files changed, 24 insertions, 8 deletions
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 409ed3cc..dfcbdd70 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -924,17 +924,21 @@ 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($convert_ids=true) {
// Convert item ids to rest URLs for consistency
$data = $this->as_array();
- if ($tmp = $this->parent()) {
- $data["parent"] = rest::url("item", $tmp);
- }
- unset($data["parent_id"]);
- if ($tmp = $this->album_cover()) {
- $data["album_cover"] = rest::url("item", $tmp);
+
+ if ($convert_ids) {
+ if ($tmp = $this->parent()) {
+ $data["parent"] = rest::url("item", $tmp);
+ }
+ unset($data["parent_id"]);
+
+ if ($tmp = $this->album_cover()) {
+ $data["album_cover"] = rest::url("item", $tmp);
+ }
+ unset($data["album_cover_item_id"]);
}
- unset($data["album_cover_item_id"]);
if (access::can("view_full", $this) && $this->is_photo()) {
$data["file_url"] = $this->file_url(true);
diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php
index 15aa2d8c..9d3f54f2 100644
--- a/modules/gallery/tests/Item_Model_Test.php
+++ b/modules/gallery/tests/Item_Model_Test.php
@@ -364,6 +364,18 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {
$this->assert_true(!array_key_exists("album_cover_item_id", $result));
}
+ public function as_restful_array_with_ids_test() {
+ $album = test::random_album();
+ $photo = test::random_photo($album);
+ $album->reload();
+
+ $result = $album->as_restful_array(false);
+ $this->assert_same(item::root()->id, $result["parent_id"]);
+ $this->assert_same($photo->id, $result["album_cover_item_id"]);
+ $this->assert_true(!array_key_exists("parent", $result));
+ $this->assert_true(!array_key_exists("album_cover_item", $result));
+ }
+
public function first_photo_becomes_album_cover() {
$album = test::random_album();
$photo = test::random_photo($album);