Commit f38fca0c authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Media: Use the same request for all type of sorts

This has the extra benefits of reducing our use of Media.is_present
parent 597865bf
...@@ -463,50 +463,44 @@ void Media::removeFile( File& file ) ...@@ -463,50 +463,44 @@ void Media::removeFile( File& file )
std::vector<MediaPtr> Media::listAll( MediaLibraryPtr ml, IMedia::Type type, SortingCriteria sort, bool desc ) std::vector<MediaPtr> Media::listAll( MediaLibraryPtr ml, IMedia::Type type, SortingCriteria sort, bool desc )
{ {
std::string req; std::string req = "SELECT m.* FROM " + policy::MediaTable::Name + " m INNER JOIN "
if ( sort == SortingCriteria::LastModificationDate || sort == SortingCriteria::FileSize ) + policy::FileTable::Name + " f ON m.id_media = f.media_id"
{ " WHERE m.type = ?"
req = "SELECT m.* FROM " + policy::MediaTable::Name + " m INNER JOIN " " AND f.type = ?"
+ policy::FileTable::Name + " f ON m.id_media = f.media_id" " AND f.is_present != 0"
" WHERE m.type = ?" " ORDER BY ";
" AND f.type = ?"
" AND f.is_present != 0";
if ( sort == SortingCriteria::LastModificationDate )
req += " ORDER BY f.last_modification_date";
else
req += " ORDER BY f.size";
if ( desc == true )
req += " DESC";
return fetchAll<IMedia>( ml, req, type, File::Type::Main );
}
req = "SELECT * FROM " + policy::MediaTable::Name + " WHERE type = ? AND "
"is_present != 0 ORDER BY ";
switch ( sort ) switch ( sort )
{ {
case SortingCriteria::Duration: case SortingCriteria::Duration:
req += "duration"; req += "m.duration";
break; break;
case SortingCriteria::InsertionDate: case SortingCriteria::InsertionDate:
req += "insertion_date"; req += "m.insertion_date";
break; break;
case SortingCriteria::ReleaseDate: case SortingCriteria::ReleaseDate:
req += "release_date"; req += "m.release_date";
break; break;
case SortingCriteria::PlayCount: case SortingCriteria::PlayCount:
req += "play_count"; req += "m.play_count";
desc = !desc; // Make decreasing order default for play count sorting desc = !desc; // Make decreasing order default for play count sorting
break; break;
case SortingCriteria::Filename: case SortingCriteria::Filename:
req += "filename"; req += "m.filename";
break;
case SortingCriteria::LastModificationDate:
req += "f.last_modification_date";
break;
case SortingCriteria::FileSize:
req += "f.size";
break; break;
default: default:
req += "title"; req += "m.title";
break; break;
} }
if ( desc == true ) if ( desc == true )
req += " DESC"; req += " DESC";
return fetchAll<IMedia>( ml, req, type ); return fetchAll<IMedia>( ml, req, type, File::Type::Main );
} }
int64_t Media::id() const int64_t Media::id() const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment