diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-04-29 15:57:29 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-04-29 15:57:29 +0000 |
commit | 820cbdf1c3a4810a1f00c16beee729e28a0d3056 (patch) | |
tree | e06191232a3b42fcf83abe089cf15905ee5109d7 /core | |
parent | 33122e8968e2d7890f7fabe45ce168aa0d217bbb (diff) |
Refactor the creation and removal of the album covers into
make_album_cover and remove_album_cover methods in Item_Model.
Usage: $photo->make_album_cover() $album->remove_album_cover()
Diffstat (limited to 'core')
-rw-r--r-- | core/controllers/quick.php | 15 | ||||
-rw-r--r-- | core/helpers/core.php | 11 | ||||
-rw-r--r-- | core/models/item.php | 24 |
3 files changed, 29 insertions, 21 deletions
diff --git a/core/controllers/quick.php b/core/controllers/quick.php index cb43a50f..48245144 100644 --- a/core/controllers/quick.php +++ b/core/controllers/quick.php @@ -83,20 +83,7 @@ class Quick_Controller extends Controller { public function make_album_cover($id) { access::verify_csrf(); $item = ORM::factory("item", $id); - access::required("edit", $item); - - $parent = $item->parent(); - access::required("edit", $parent); - - if ($item->is_photo()) { - $parent->album_cover_item_id = $item->id; - } else if ($item->is_album()) { - $parent->album_cover_item_id = $item->album_cover_item_id; - } - - $parent->thumb_dirty = 1; - $parent->save(); - graphics::generate($parent); + $item->make_album_cover(); print json_encode(array("result" => "success")); } diff --git a/core/helpers/core.php b/core/helpers/core.php index f8c08ca9..4c73f148 100644 --- a/core/helpers/core.php +++ b/core/helpers/core.php @@ -31,14 +31,17 @@ class core_Core { static function move_item($source, $target) { access::required("edit", $source); access::required("edit", $target); + + $parent = $source->parent(); + if ($parent->album_cover_item_id == $source->id) { + $parent->remove_album_cover(); + } + $source->move_to($target); // If the target has no cover item, make this it. if ($target->album_cover_item_id == null) { - $target->album_cover_item_id = - $source->is_album() ? $source->album_cover_item_id : $source->id; - $target->save(); - graphics::generate($target); + $source->make_album_cover(); } } }
\ No newline at end of file diff --git a/core/models/item.php b/core/models/item.php index 34b8a8dd..0d5e6e11 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -98,9 +98,7 @@ class Item_Model extends ORM_MPTT { $parent = $this->parent(); if ($parent->album_cover_item_id == $this->id) { - // @todo change the album cover to some other random image inside the album - $parent->album_cover_item_id = null; - $parent->save(); + $parent->remove_album_cover(); } $original_path = $this->file_path(); @@ -158,6 +156,26 @@ class Item_Model extends ORM_MPTT { return $this; } + function make_album_cover() { + $parent = $this->parent(); + access::required("edit", $parent); + + $parent->album_cover_item_id = $this->is_photo() ? $this->id : $this->album_cover_item_id; + $parent->thumb_dirty = 1; + $parent->save(); + graphics::generate($parent); + } + + function remove_album_cover() { + @unlink($this->thumb_path()); + + // @todo change the album cover to some other random image inside the album + $this->album_cover_item_id = null; + $this->thumb_dirty = 1; + $this->save(); + graphics::generate($this); + } + /** * album: url::site("albums/2") * photo: url::site("photos/3") |