summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-11-16 07:14:12 +0000
committerBharat Mediratta <bharat@menalto.com>2008-11-16 07:14:12 +0000
commit140736a1e49d47376ebc893aa2da250ba3d836a3 (patch)
tree994c4ef0103c15352f0cc059274b462475a9c49c /core
parentb8b60df391637ff21bb79ba64f820749ef324ee9 (diff)
Several large changes:
1) Changed the way that we get forms. Now, if you want to get a form for a REST resource you prefix /form to the resource id. So: /form/photo/1 : returns a form for editing photo id 1 /form/comments/1 : returns a form for adding a comment to photo id 1 /form/comment/1 : returns a form for editing comment id 1 2) Changed the comment module to have two controllers: comment: deals with a single comment resource comments: deal with collections of comments attached to an item Related stuff: - Moved the comments js into the theme - Reworked Comment_Helper for clarity - Moved form generation code down into Comment_Helper - Cleaned up routes (eliminating new comment ones added in recent rev) - Added form() function to all REST controllers - Changed comment module to use a block instead of an arbitrary helper call from the theme - Comment controller only returns HTML currently, but returns a 201 Created status code when a new comment is added, which the Ajax code can catch and act upon. - Got rid of a lot of extra views in comment module
Diffstat (limited to 'core')
-rw-r--r--core/config/routes.php6
-rw-r--r--core/controllers/album.php10
-rw-r--r--core/controllers/item.php7
-rw-r--r--core/controllers/photo.php10
-rw-r--r--core/controllers/rest.php24
5 files changed, 52 insertions, 5 deletions
diff --git a/core/config/routes.php b/core/config/routes.php
index de66b8fb..465fb885 100644
--- a/core/config/routes.php
+++ b/core/config/routes.php
@@ -24,11 +24,7 @@
$config['^rest'] = null;
$config['^rest/.*'] = null;
$config['^(\w+)/(\d+)$'] = '$1/dispatch/$2';
+$config['^form/(\w+)/(.*)$'] = '$1/form/$2';
// For now our default page is the scaffolding.
$config['_default'] = 'welcome';
-
-// Special routes for the comment module.
-// @todo Dynamically load this.
-$config['photo/(\d+)/comments/add$'] = 'comment/add/$1';
-$config['photo/(\d+)/comments$'] = 'comment/get_item_comments/$1';
diff --git a/core/controllers/album.php b/core/controllers/album.php
index 63290853..87e27ac5 100644
--- a/core/controllers/album.php
+++ b/core/controllers/album.php
@@ -19,6 +19,16 @@
*/
class Album_Controller extends Item_Controller {
+ /**
+ * @see Rest_Controller::_form($resource)
+ */
+ public function _form($comment) {
+ throw new Exception("@todo Comment_Controller::_get NOT IMPLEMENTED");
+ }
+
+ /**
+ * @see Rest_Controller::_get($resource)
+ */
public function _get($item) {
// @todo: these need to be pulled from the database
$theme_name = "default";
diff --git a/core/controllers/item.php b/core/controllers/item.php
index e9ff03e6..027dcada 100644
--- a/core/controllers/item.php
+++ b/core/controllers/item.php
@@ -20,6 +20,13 @@
class Item_Controller extends REST_Controller {
protected $resource_type = "item";
+ /**
+ * @see Rest_Controller::_form($resource)
+ */
+ public function _form($comment) {
+ throw new Exception("@todo Comment_Controller::_get NOT IMPLEMENTED");
+ }
+
public function _get($item) {
// Redirect to the more specific resource type, since it will render
// differently. We could also just delegate here, but it feels more appropriate
diff --git a/core/controllers/photo.php b/core/controllers/photo.php
index 78287afa..4c3154bd 100644
--- a/core/controllers/photo.php
+++ b/core/controllers/photo.php
@@ -19,6 +19,16 @@
*/
class Photo_Controller extends Item_Controller {
+ /**
+ * @see Rest_Controller::_form($resource)
+ */
+ public function _form($comment) {
+ throw new Exception("@todo Comment_Controller::_get NOT IMPLEMENTED");
+ }
+
+ /**
+ * @see Rest_Controller::_get($resource)
+ */
public function _get($item) {
$template = new View("page.html");
diff --git a/core/controllers/rest.php b/core/controllers/rest.php
index 09c85653..4a6c4eb4 100644
--- a/core/controllers/rest.php
+++ b/core/controllers/rest.php
@@ -39,6 +39,10 @@
* public function _delete(ORM $comment) {
* // Handle DELETE request
* }
+ *
+ * public function form(ORM $comment) {
+ * // Show a form for creating a new comment
+ * }
* }
*
* A request to http://example.com/gallery3/comment/3 will result in a call to
@@ -85,6 +89,20 @@ abstract class REST_Controller extends Controller {
}
}
+ public function form($id) {
+ if ($this->resource_type == null) {
+ throw new Exception("@todo ERROR_MISSING_RESOURCE_TYPE");
+ }
+
+ // @todo this needs security checks
+ $resource = ORM::factory($this->resource_type, $id);
+ if (!$resource->loaded) {
+ return Kohana::show_404();
+ }
+
+ return $this->_form($resource);
+ }
+
/**
* Perform a GET request on this resource
* @param ORM $resource the instance of this resource type
@@ -108,4 +126,10 @@ abstract class REST_Controller extends Controller {
* @param ORM $resource the instance of this resource type
*/
abstract public function _delete($resource);
+
+ /**
+ * Present a form for adding a new resource
+ * @param ORM $resource the resource container for instances of this resource type
+ */
+ abstract public function _form($resource);
}