diff options
-rw-r--r-- | core/controllers/quick.php | 15 | ||||
-rw-r--r-- | core/helpers/core.php | 11 | ||||
-rw-r--r-- | core/models/item.php | 24 | ||||
-rw-r--r-- | modules/organize/helpers/organize_task.php | 12 |
4 files changed, 30 insertions, 32 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") diff --git a/modules/organize/helpers/organize_task.php b/modules/organize/helpers/organize_task.php index c0315aba..e617a0a1 100644 --- a/modules/organize/helpers/organize_task.php +++ b/modules/organize/helpers/organize_task.php @@ -54,17 +54,7 @@ class organize_task_Core { break; case "albumCover": $item = ORM::factory("item", $id); - $parent = $item->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(); break; case "delete": $item = ORM::factory("item", $id); |