From 069a23e81192578f5f02f6a52a07536ceb6c0bcd Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 19 Jan 2010 01:16:59 -0800 Subject: Make scope default to direct. Add slug to the post params. Fix minor output bug. --- modules/gallery/helpers/gallery_rest.php | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'modules') diff --git a/modules/gallery/helpers/gallery_rest.php b/modules/gallery/helpers/gallery_rest.php index 7f93bd38..827da122 100644 --- a/modules/gallery/helpers/gallery_rest.php +++ b/modules/gallery/helpers/gallery_rest.php @@ -65,17 +65,19 @@ class gallery_rest_Core { $orm = ORM::factory("item")->viewable(); } - if (!empty($p->scope) && !in_array($p->scope, array("direct", "all"))) { + if (empty($p->scope)) { + $p->scope = "direct"; + } + + if (!in_array($p->scope, array("direct", "all"))) { throw new Exception("Bad Request", 400); } - if (!empty($p->scope)) { - if ($p->scope == "direct") { - $orm->where("parent_id", "=", $item->id); - } else { - $orm->where("left_ptr", ">=", $item->left_ptr); - $orm->where("right_ptr", "<=", $item->left_ptr); - $orm->where("id", "<>", $item->id); - } + + if ($p->scope == "direct") { + $orm->where("parent_id", "=", $item->id); + } else { + $orm->where("left_ptr", ">", $item->left_ptr); + $orm->where("right_ptr", "<", $item->right_ptr); } if (isset($p->name)) { @@ -128,6 +130,7 @@ class gallery_rest_Core { $item->name = $params->name; $item->title = isset($params->title) ? $params->title : $name; $item->description = isset($params->description) ? $params->description : null; + $item->slug = isset($params->slug) ? $params->slug : null; $item->save(); break; @@ -137,13 +140,14 @@ class gallery_rest_Core { $item->parent_id = $parent->id; $item->set_data_file($request->file); $item->name = $params->name; - $item->title = isset($params->title) ? $params->title : $name; + $item->title = isset($params->title) ? $params->title : $params->name; $item->description = isset($params->description) ? $params->description : null; + $item->slug = isset($params->slug) ? $params->slug : null; $item->save(); break; default: - throw new Rest_Exception("Invalid type: $args->type", 400); + throw new Rest_Exception("Invalid type: $params->type", 400); } return array("url" => url::abs_site("/rest/gallery/" . $item->relative_url())); -- cgit v1.2.3