From 820cbdf1c3a4810a1f00c16beee729e28a0d3056 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 29 Apr 2009 15:57:29 +0000 Subject: 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() --- core/models/item.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'core/models') 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") -- cgit v1.2.3