summaryrefslogtreecommitdiff
path: root/core/controllers/photos.php
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2008-12-24 00:20:26 +0000
committerBharat Mediratta <bharat@menalto.com>2008-12-24 00:20:26 +0000
commit672eca53371b131484d00cbe6a069092d0b7f6b3 (patch)
tree507cce76fc6dc9d022455eed9075e039fa779da2 /core/controllers/photos.php
parentc76d730a7c07253e7cc3224a78c616ce63989f40 (diff)
Lots of deltas rolled up into a bigger change. Sorry for the mess.
1) Deleted in-place-editing. We'll be replacing this with a real edit system that groups settings together and is more coherent. 2) Tweaked the way that dialog boxes work to get the ajax stuff working again. It's imperfect and does not work properly for uploading images. This is going to get redone also, but this is a good resting point. 3) Created edit forms for albums and photos. Moved _update and _create out of Items_Controller and into the individual subclasses. 4) Created access::required which is a shorthand for: if (!access::can(...)) { access::forbidden(); } 5) Added validation rules to Items_Model 6) Converted login to use the regular modal dialog approach in the theme.
Diffstat (limited to 'core/controllers/photos.php')
-rw-r--r--core/controllers/photos.php53
1 files changed, 39 insertions, 14 deletions
diff --git a/core/controllers/photos.php b/core/controllers/photos.php
index 465c291d..730cfd2c 100644
--- a/core/controllers/photos.php
+++ b/core/controllers/photos.php
@@ -22,34 +22,59 @@ class Photos_Controller extends Items_Controller {
/**
* @see Rest_Controller::_show($resource)
*/
- public function _show($item) {
- if (!access::can("view", $item)) {
- return Kohana::show_404();
- }
+ public function _show($photo) {
+ access::required("view", $photo);
$theme_name = module::get_var("core", "active_theme", "default");
$template = new Theme_View("page.html", "photo", $theme_name);
- $template->set_global('item', $item);
- $template->set_global('children', $item->children());
- $template->set_global('children_count', $item->children_count());
- $template->set_global('parents', $item->parents());
+ $template->set_global('item', $photo);
+ $template->set_global('children', array());
+ $template->set_global('children_count', $photo->children_count());
+ $template->set_global('parents', $photo->parents());
$template->content = new View("photo.html");
- $item->view_count++;
- $item->save();
+ $photo->view_count++;
+ $photo->save();
print $template;
}
/**
- * @see Rest_Controller::_form_add($parameters)
+ * @see Rest_Controller::_update($resource)
*/
- public function _form_add($parent_id) {
- $parent = ORM::factory("item", $parent_id);
+ public function _update($photo) {
+ access::required("edit", $photo);
+
+ $form = photo::get_edit_form($photo);
+ if ($form->validate()) {
+ // @todo implement changing the name. This is not trivial, we have
+ // to check for conflicts and rename the album itself, etc. Needs an
+ // api method.
+ $photo->title = $form->edit_photo->title->value;
+ $photo->description = $form->edit_photo->description->value;
+ $photo->save();
+
+ module::event("photo_changed", $photo);
- print photo::get_add_form($parent)->render();
+ 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"));
+ } else {
+ rest::html($form);
+ }
+ rest::respond();
+ }
+
+ /**
+ * @see Rest_Controller::_form_edit($resource)
+ */
+ public function _form_edit($photo) {
+ access::required("edit", $photo);
+ print photo::get_edit_form($photo);
}
}