diff options
author | Bharat Mediratta <bharat@menalto.com> | 2009-05-16 04:32:00 +0000 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2009-05-16 04:32:00 +0000 |
commit | 930452aa6b93755003d4ce28143fccb4f23801b0 (patch) | |
tree | e0c6c39f70ccd9a04024a32e75fa313852ea8f4c /core | |
parent | 33f1187220404bca6597de5368048316ece5139a (diff) |
Support renaming albums, photos and movies.
Fixes ticket #278.
Diffstat (limited to 'core')
-rw-r--r-- | core/controllers/albums.php | 24 | ||||
-rw-r--r-- | core/controllers/movies.php | 19 | ||||
-rw-r--r-- | core/controllers/photos.php | 21 | ||||
-rw-r--r-- | core/helpers/album.php | 8 | ||||
-rw-r--r-- | core/helpers/item.php | 6 | ||||
-rw-r--r-- | core/helpers/photo.php | 4 |
6 files changed, 66 insertions, 16 deletions
diff --git a/core/controllers/albums.php b/core/controllers/albums.php index 41a7810d..5b4d5979 100644 --- a/core/controllers/albums.php +++ b/core/controllers/albums.php @@ -155,16 +155,30 @@ class Albums_Controller extends Items_Controller { access::required("edit", $album); $form = album::get_edit_form($album); - 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. + if ($valid = $form->validate()) { + // Make sure that there's not a conflict + if (Database::instance() + ->from("items") + ->where("parent_id", $album->parent_id) + ->where("id <>", $album->id) + ->where("name", $form->edit_album->dirname->value) + ->count_records()) { + $form->edit_album->dirname->add_error("conflict", 1); + $valid = false; + } + } + + // @todo + // @todo we need to make sure that filename / dirname components can't contain a / + // @todo + + if ($valid) { $orig = clone $album; $album->title = $form->edit_album->title->value; $album->description = $form->edit_album->description->value; $album->sort_column = $form->edit_album->sort_order->column->value; $album->sort_order = $form->edit_album->sort_order->direction->value; - + $album->rename($form->edit_album->dirname->value); $album->save(); module::event("item_updated", $orig, $album); diff --git a/core/controllers/movies.php b/core/controllers/movies.php index 3d820506..55bbb0e5 100644 --- a/core/controllers/movies.php +++ b/core/controllers/movies.php @@ -69,13 +69,24 @@ class Movies_Controller extends Items_Controller { 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. + if ($valid = $form->validate()) { + // Make sure that there's not a conflict + if (Database::instance() + ->from("items") + ->where("parent_id", $photo->parent_id) + ->where("id <>", $photo->id) + ->where("name", $form->edit_photo->filename->value) + ->count_records()) { + $form->edit_photo->filename->add_error("conflict", 1); + $valid = false; + } + } + + if ($valid) { $orig = clone $photo; $photo->title = $form->edit_photo->title->value; $photo->description = $form->edit_photo->description->value; + $photo->rename($form->edit_photo->filename->value); $photo->save(); module::event("item_updated", $orig, $photo); diff --git a/core/controllers/photos.php b/core/controllers/photos.php index eb6ff569..5d4040cf 100644 --- a/core/controllers/photos.php +++ b/core/controllers/photos.php @@ -69,13 +69,26 @@ class Photos_Controller extends Items_Controller { 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. + if ($valid = $form->validate()) { + if ($form->edit_photo->filename->value != $photo->name) { + // Make sure that there's not a conflict + if (Database::instance() + ->from("items") + ->where("parent_id", $photo->parent_id) + ->where("id <>", $photo->id) + ->where("name", $form->edit_photo->filename->value) + ->count_records()) { + $form->edit_photo->filename->add_error("conflict", 1); + $valid = false; + } + } + } + + if ($valid) { $orig = clone $photo; $photo->title = $form->edit_photo->title->value; $photo->description = $form->edit_photo->description->value; + $photo->rename($form->edit_photo->filename->value); $photo->save(); module::event("item_updated", $orig, $photo); diff --git a/core/helpers/album.php b/core/helpers/album.php index 7c667751..c60527b2 100644 --- a/core/helpers/album.php +++ b/core/helpers/album.php @@ -76,7 +76,9 @@ class album_Core { ->label(t("Add an album to %album_title", array("album_title" => $parent->title))); $group->input("title")->label(t("Title")); $group->textarea("description")->label(t("Description")); - $group->input("name")->label(t("Directory Name")); + $group->input("name")->label(t("Directory Name")) + ->callback("item::validate_no_slashes") + ->error_messages("no_slashes", t("The directory name can't contain the \"/\" character")); $group->hidden("type")->value("album"); $group->submit("")->value(t("Create")); $form->add_rules_from(ORM::factory("item")); @@ -91,7 +93,9 @@ class album_Core { $group->input("title")->label(t("Title"))->value($parent->title); $group->textarea("description")->label(t("Description"))->value($parent->description); if ($parent->id != 1) { - $group->dirname->label(t("Directory Name"))->value($parent->name); + $group->input("dirname")->label(t("Directory Name"))->value($parent->name) + ->callback("item::validate_no_slashes") + ->error_messages("no_slashes", t("The directory name can't contain the \"/\" character")); } $sort_order = $group->group("sort_order", array("id" => "gAlbumSortOrder")) diff --git a/core/helpers/item.php b/core/helpers/item.php index b051bb0e..bd54f2b1 100644 --- a/core/helpers/item.php +++ b/core/helpers/item.php @@ -72,4 +72,10 @@ class item_Core { $album->save(); graphics::generate($album); } + + static function validate_no_slashes($input) { + if (strpos($input->value, "/") !== false) { + $input->add_error("no_slashes", 1); + } + } }
\ No newline at end of file diff --git a/core/helpers/photo.php b/core/helpers/photo.php index 6467e797..0015bd99 100644 --- a/core/helpers/photo.php +++ b/core/helpers/photo.php @@ -129,7 +129,9 @@ class photo_Core { $group->input("title")->label(t("Title"))->value($photo->title); $group->textarea("description")->label(t("Description"))->value($photo->description); $group->input("filename")->label(t("Filename"))->value($photo->name) - ->error_messages("conflict", t("There is already a file with this name")); + ->callback("item::validate_no_slashes") + ->error_messages("conflict", t("There is already a file with this name")) + ->error_messages("no_slashes", t("The directory name can't contain the \"/\" character")); $group->submit("")->value(t("Modify")); $form->add_rules_from(ORM::factory("item")); return $form; |