add Album::merge via Multiselection ContextMenu
This commit is contained in:
parent
ec4842cad5
commit
c69fe33df3
@ -22,6 +22,7 @@ class Admin extends Access {
|
||||
case 'Album::setDescription': $this->setAlbumDescription(); break;
|
||||
case 'Album::setPublic': $this->setAlbumPublic(); break;
|
||||
case 'Album::delete': $this->deleteAlbum(); break;
|
||||
case 'Album::merge': $this->mergeAlbums(); break;
|
||||
|
||||
# Photo functions
|
||||
case 'Photo::get': $this->getPhoto(); break;
|
||||
@ -123,6 +124,12 @@ class Admin extends Access {
|
||||
|
||||
}
|
||||
|
||||
private function mergeAlbums() {
|
||||
Module::dependencies(isset($_POST['albumIDs']));
|
||||
$album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumIDs']);
|
||||
echo $album->merge();
|
||||
}
|
||||
|
||||
# Photo functions
|
||||
|
||||
private function getPhoto() {
|
||||
|
@ -715,6 +715,40 @@ class Album extends Module {
|
||||
|
||||
}
|
||||
|
||||
public function merge() {
|
||||
|
||||
# Check dependencies
|
||||
self::dependencies(isset($this->database, $this->albumIDs));
|
||||
|
||||
# Call plugins
|
||||
$this->plugins(__METHOD__, 0, func_get_args());
|
||||
|
||||
$albumID = reset($this->albumIDs);
|
||||
$mergable_albumIDs = array_slice($this->albumIDs, 1);
|
||||
|
||||
$inQuery = implode(',', array_fill(0, count($this->albumIDs) - 1, '?'));
|
||||
$data = array(LYCHEE_TABLE_PHOTOS, $albumID) + $mergable_albumIDs;
|
||||
|
||||
$merge_query = Database::prepare($this->database, "UPDATE ? SET album = ? WHERE album IN ($inQuery)", $data);
|
||||
$merge_result = $this->database->query($merge_query);
|
||||
|
||||
if (!$merge_result) {
|
||||
Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = array(LYCHEE_TABLE_ALBUMS) + $mergable_albumIDs;
|
||||
$delete_query = Database::prepare($this->database, "DELETE FROM ? WHERE id IN ($inQuery)", $data);
|
||||
$delete_result = $this->database->query($delete_query);
|
||||
|
||||
if (!$delete_result) {
|
||||
Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -567,4 +567,14 @@ album.getArchive = function(albumID) {
|
||||
|
||||
location.href = link;
|
||||
|
||||
}
|
||||
|
||||
album.merge = function(albumIDs) {
|
||||
var params = {
|
||||
albumIDs: albumIDs.join()
|
||||
}
|
||||
|
||||
api.post('Album::merge', params, function(data) {
|
||||
if (data!==true) lychee.error(null, params, data);
|
||||
})
|
||||
}
|
@ -61,6 +61,7 @@ contextMenu.albumMulti = function(albumIDs, e) {
|
||||
multiselect.stopResize();
|
||||
|
||||
var items = [
|
||||
{ type: 'item', title: 'Merge All', fn: function () { album.merge(albumIDs) } },
|
||||
{ type: 'item', title: build.iconic('pencil') + 'Rename All', fn: function() { album.setTitle(albumIDs) } },
|
||||
{ type: 'item', title: build.iconic('trash') + 'Delete All', fn: function() { album.delete(albumIDs) } }
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user