summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/gallery/models/item.php20
-rw-r--r--modules/gallery/tests/Item_Model_Test.php12
-rw-r--r--modules/rest/helpers/rest.php6
3 files changed, 11 insertions, 27 deletions
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 009457c1..e42430bf 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -924,21 +924,17 @@ class Item_Model extends ORM_MPTT {
/**
* Same as ORM::as_array() but convert id fields into their RESTful form.
*/
- public function as_restful_array($convert_ids=true) {
+ public function as_restful_array() {
// Convert item ids to rest URLs for consistency
$data = $this->as_array();
-
- 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"]);
+ 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"]);
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 f9e6a4e3..907cfe24 100644
--- a/modules/gallery/tests/Item_Model_Test.php
+++ b/modules/gallery/tests/Item_Model_Test.php
@@ -368,18 +368,6 @@ 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 as_restful_array_with_edit_bit_test() {
$response = item::root()->as_restful_array(true);
$this->assert_true($response["can_edit"]);
diff --git a/modules/rest/helpers/rest.php b/modules/rest/helpers/rest.php
index 3229330a..b382cb29 100644
--- a/modules/rest/helpers/rest.php
+++ b/modules/rest/helpers/rest.php
@@ -137,9 +137,9 @@ class rest_Core {
foreach (glob(MODPATH . "{$module->name}/helpers/*_rest.php") as $filename) {
$class = str_replace(".php", "", basename($filename));
if (method_exists($class, "relationships")) {
- $results = array_merge(
- $results,
- call_user_func(array($class, "relationships"), $resource_type, $resource));
+ if ($tmp = call_user_func(array($class, "relationships"), $resource_type, $resource)) {
+ $results = array_merge($results, $tmp);
+ }
}
}
}