Added ordering logic to media file selection criteria.

This commit is contained in:
Jonathan Bernard 2016-03-05 21:32:45 -06:00
parent 13b0fa5bc4
commit a4013ed365

View File

@ -353,6 +353,7 @@ public class ORM {
public List<MediaFile> getMediaFilesWhere(Map params) { public List<MediaFile> getMediaFilesWhere(Map params) {
def query = new StringBuilder() def query = new StringBuilder()
def sqlParams = [] def sqlParams = []
def orderClauses = [] as LinkedList
query.append("SELECT mf.* FROM media_files mf ") query.append("SELECT mf.* FROM media_files mf ")
@ -360,18 +361,23 @@ public class ORM {
query.append(" JOIN artists_media_files armf ON ") query.append(" JOIN artists_media_files armf ON ")
.append(" mf.id = armf.media_file_id ") .append(" mf.id = armf.media_file_id ")
query.append(" AND armf.artist_id = ? ") query.append(" AND armf.artist_id = ? ")
sqlParams << params.artistId } sqlParams << params.artistId
orderClauses << "armf.artist_id" }
if (params.albumId) { if (params.albumId) {
query.append(" JOIN albums_media_files almf ON ") query.append(" JOIN albums_media_files almf ON ")
.append(" al.id = almf.album_id ") .append(" mf.id = almf.media_file_id ")
.append(" mf.album_id = almf.album_id ")
query.append(" AND almf.album_id = ? ") query.append(" AND almf.album_id = ? ")
sqlParams << params.albumId } sqlParams << params.albumId
orderClauses << "almf.album_id ASC"
orderClauses << "mf.track_number ASC" }
if (params.playlistId) { if (params.playlistId) {
query.append(" JOIN playlists_media_files pmf ON ") query.append(" JOIN playlists_media_files pmf ON ")
query.append(" pmf.media_file_id = mf.id AND ") query.append(" pmf.media_file_id = mf.id AND ")
query.append(" pmf.playlist_id = ?") query.append(" pmf.playlist_id = ?")
orderClauses.addFirst("pmf.position")
sqlParams << params.playlistId } sqlParams << params.playlistId }
if (params.name || params.fileHash || params.filePath || if (params.name || params.fileHash || params.filePath ||