diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/controllers/albums.php | 38 | ||||
-rw-r--r-- | core/controllers/items.php | 33 | ||||
-rw-r--r-- | core/controllers/photos.php | 10 | ||||
-rw-r--r-- | core/controllers/rest.php | 32 | ||||
-rw-r--r-- | core/helpers/core_menu.php | 5 |
5 files changed, 54 insertions, 64 deletions
diff --git a/core/controllers/albums.php b/core/controllers/albums.php index 10887592..47412dfc 100644 --- a/core/controllers/albums.php +++ b/core/controllers/albums.php @@ -82,10 +82,15 @@ class Albums_Controller extends Items_Controller { log::add("content", "Created an album", log::INFO, html::anchor("albums/$new_album->id", "view album")); message::add(_("Successfully created album")); - rest::http_status(rest::CREATED); - rest::http_location(url::site("albums/$new_album->id")); + + print json_encode( + array("result" => "success", + "location" => url::site("albums/$new_album->id"), + "resource" => url::site("albums/$new_album->id"))); } else { - print $form; + print json_encode( + array("result" => "error", + "form" => $form->__toString())); } } @@ -105,11 +110,15 @@ class Albums_Controller extends Items_Controller { log::add("content", "Added a photo", log::INFO, html::anchor("photos/$photo->id", "view photo")); message::add(_("Successfully added photo")); - //rest::http_status(rest::CREATED); - //rest::http_location(url::site("photos/$photo->id")); - print "<h1>this is a response</h1>"; + + print json_encode( + array("result" => "success", + "resource" => url::site("photos/$photo->id"), + "location" => url::site("photos/$photo->id"))); } else { - print $form; + print json_encode( + array("result" => "error", + "form" => $form->__toString())); } } @@ -132,12 +141,15 @@ class Albums_Controller extends Items_Controller { log::add("content", "Updated album", log::INFO, "<a href=\"albums/$album->id\">view</a>"); message::add(_("Successfully saved album")); - rest::http_status(rest::CREATED); - rest::http_location(url::site("albums/$album->id")); + + print json_encode( + array("result" => "success", + "location" => url::site("albums/$album->id"))); } else { - rest::html($form); + print json_encode( + array("result" => "error", + "form" => $form->__toString())); } - rest::respond(); } /** @@ -149,11 +161,11 @@ class Albums_Controller extends Items_Controller { switch ($this->input->get("type")) { case "album": - print album::get_add_form($album)->render(); + print album::get_add_form($album); break; case "photo": - print photo::get_add_form($album)->render(); + print photo::get_add_form($album); break; default: diff --git a/core/controllers/items.php b/core/controllers/items.php index ab63889e..60b2762f 100644 --- a/core/controllers/items.php +++ b/core/controllers/items.php @@ -20,27 +20,6 @@ class Items_Controller extends REST_Controller { protected $resource_type = "item"; - /** - * @see REST_Controller::_index() - */ - public function _index() { - throw new Exception("@todo Item_Controller::_index NOT IMPLEMENTED"); - } - - /** - * @see REST_Controller::_form_add($parameters) - */ - public function _form_add($parameters) { - throw new Exception("@todo Items_Controller::_form_add NOT IMPLEMENTED"); - } - - /** - * @see REST_Controller::_form_edit($resource) - */ - public function _form_edit($item) { - throw new Exception("@todo Items_Controller::_form_edit NOT IMPLEMENTED"); - } - public function _show($item) { // Redirect to the more specific resource type, since it will render // differently. We could also just delegate here, but it feels more appropriate @@ -48,16 +27,4 @@ class Items_Controller extends REST_Controller { access::required("view", $item); return url::redirect("{$item->type}s/$item->id"); } - - public function _delete($item) { - throw new Exception("@todo Item_Controller::_delete NOT IMPLEMENTED"); - } - - public function _create($item) { - throw new Exception("@todo Item_Controller::_create NOT IMPLEMENTED"); - } - - public function _update($item) { - throw new Exception("@todo Item_Controller::_update NOT IMPLEMENTED"); - } } diff --git a/core/controllers/photos.php b/core/controllers/photos.php index a8282f36..04553bd1 100644 --- a/core/controllers/photos.php +++ b/core/controllers/photos.php @@ -59,12 +59,14 @@ class Photos_Controller extends Items_Controller { log::add("content", "Updated photo", log::INFO, "<a href=\"photos/$photo->id\">view</a>"); message::add(_("Successfully saved photo")); - rest::http_status(rest::FOUND); - rest::http_location(url::site("photos/$photo->id")); + print json_encode( + array("result" => "success", + "location" => url::site("photos/$photo->id"))); } else { - rest::html($form); + print json_encode( + array("result" => "error", + "form" => $form->__toString())); } - rest::respond(); } /** diff --git a/core/controllers/rest.php b/core/controllers/rest.php index 0ac7a1c9..ceca321e 100644 --- a/core/controllers/rest.php +++ b/core/controllers/rest.php @@ -55,11 +55,11 @@ * } * * A request to http://example.com/gallery3/comments/3 will result in a call to - * REST_Controller::dispatch(3) which will load up the comment associated with id 3. If there's + * REST_Controller::__call(3) which will load up the comment associated with id 3. If there's * no such comment, it returns a 404. Otherwise, it will then delegate to * Comment_Controller::get() with the ORM instance as an argument. */ -abstract class REST_Controller extends Controller { +class REST_Controller extends Controller { protected $resource_type = null; public function __construct() { @@ -125,41 +125,55 @@ abstract class REST_Controller extends Controller { * Perform a GET request on the controller root * (e.g. http://www.example.com/gallery3/comments) */ - abstract public function _index(); + public function _index() { + throw new Exception("@todo _create NOT IMPLEMENTED"); + } /** * Perform a POST request on this resource * @param ORM $resource the instance of this resource type */ - abstract public function _create($resource); + public function _create($resource) { + throw new Exception("@todo _create NOT IMPLEMENTED"); + } /** * Perform a GET request on this resource * @param ORM $resource the instance of this resource type */ - abstract public function _show($resource); + public function _show($resource) { + throw new Exception("@todo _show NOT IMPLEMENTED"); + } /** * Perform a PUT request on this resource * @param ORM $resource the instance of this resource type */ - abstract public function _update($resource); + public function _update($resource) { + throw new Exception("@todo _update NOT IMPLEMENTED"); + } /** * Perform a DELETE request on this resource * @param ORM $resource the instance of this resource type */ - abstract public function _delete($resource); + public function _delete($resource) { + throw new Exception("@todo _delete NOT IMPLEMENTED"); + } /** * Present a form for adding a new resource * @param string part of the URI after the controller name */ - abstract public function _form_add($parameter); + public function _form_add($parameter) { + throw new Exception("@todo _form_add NOT IMPLEMENTED"); + } /** * Present a form for editing an existing resource * @param ORM $resource the resource container for instances of this resource type */ - abstract public function _form_edit($resource); + public function _form_edit($resource) { + throw new Exception("@todo _form_edit NOT IMPLEMENTED"); + } } diff --git a/core/helpers/core_menu.php b/core/helpers/core_menu.php index 685ccf64..0a28f21f 100644 --- a/core/helpers/core_menu.php +++ b/core/helpers/core_menu.php @@ -57,11 +57,6 @@ class core_menu_Core { ->label(_("Add an album")) ->url(url::site("form/add/albums/$item->id?type=album"))); } - - $admin_menu->append(Menu::factory("dialog") - ->id("edit") - ->label(_("Edit")) - ->url(url::site("form/edit/{$item->type}s/$item->id"))); } if (user::active()->admin) { |