Browse Source

Merge pull request #340 from rhurling/feature/166-merge-albums

Merge Albums feature
Tobias Reich 9 years ago
parent
commit
e2399a1794
6 changed files with 82 additions and 0 deletions
  1. 0 0
      dist/main.js
  2. 0 0
      dist/view.js
  3. 7 0
      php/access/Admin.php
  4. 34 0
      php/modules/Album.php
  5. 40 0
      src/scripts/album.js
  6. 1 0
      src/scripts/contextMenu.js

File diff suppressed because it is too large
+ 0 - 0
dist/main.js


File diff suppressed because it is too large
+ 0 - 0
dist/view.js


+ 7 - 0
php/access/Admin.php

@@ -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() {

+ 34 - 0
php/modules/Album.php

@@ -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());
+
+		$albumIDs          = explode(',', $this->albumIDs);
+		$albumID           = array_splice($albumIDs, 0, 1)[0];
+
+		$inQuery = implode(',', array_fill(0, count($albumIDs), '?'));
+		$data    = array_merge(array(LYCHEE_TABLE_PHOTOS, $albumID), $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_merge( array(LYCHEE_TABLE_ALBUMS), $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;
+	}
+
 }
 
 ?>

+ 40 - 0
src/scripts/album.js

@@ -567,4 +567,44 @@ album.getArchive = function(albumID) {
 
 	location.href = link;
 
+}
+
+album.merge = function(albumIDs) {
+    var action = {}
+
+    action.fn = function() {
+
+        var params;
+
+        basicModal.close();
+
+        params = {
+            albumIDs: albumIDs.join()
+        }
+
+        api.post('Album::merge', params, function(data) {
+            if (data!==true) {
+                lychee.error(null, params, data);
+            } else {
+                albums.json = null
+                albums.load()
+            }
+        })
+
+    }
+
+    basicModal.show({
+        body: '<p>Are you sure you want to merge all selected albums?</p>',
+        buttons: {
+            action: {
+                title: 'Merge Albums',
+                fn: action.fn,
+                class: 'red'
+            },
+            cancel: {
+                title: "Don't merge",
+                fn: basicModal.close
+            }
+        }
+    });
 }

+ 1 - 0
src/scripts/contextMenu.js

@@ -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) } }
 	];

Some files were not shown because too many files changed in this diff