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/models | |
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/models')
-rw-r--r-- | core/models/item.php | 24 |
1 files changed, 21 insertions, 3 deletions
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") |