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

Media: Split sorting request generation in a separate function

parent f38fca0c
......@@ -461,14 +461,10 @@ void Media::removeFile( File& file )
}));
}
std::vector<MediaPtr> Media::listAll( MediaLibraryPtr ml, IMedia::Type type, SortingCriteria sort, bool desc )
std::string Media::sortRequest( SortingCriteria sort, bool desc )
{
std::string req = "SELECT m.* FROM " + policy::MediaTable::Name + " m INNER JOIN "
+ policy::FileTable::Name + " f ON m.id_media = f.media_id"
" WHERE m.type = ?"
" AND f.type = ?"
" AND f.is_present != 0"
" ORDER BY ";
std::string req = " ORDER BY ";
switch ( sort )
{
case SortingCriteria::Duration:
......@@ -499,7 +495,18 @@ std::vector<MediaPtr> Media::listAll( MediaLibraryPtr ml, IMedia::Type type, Sor
}
if ( desc == true )
req += " DESC";
return req;
}
std::vector<MediaPtr> Media::listAll( MediaLibraryPtr ml, IMedia::Type type,
SortingCriteria sort, bool desc )
{
std::string req = "SELECT m.* FROM " + policy::MediaTable::Name + " m INNER JOIN "
+ policy::FileTable::Name + " f ON m.id_media = f.media_id"
" WHERE m.type = ?"
" AND f.type = ?"
" AND f.is_present != 0";
req += sortRequest( sort, desc );
return fetchAll<IMedia>( ml, req, type, File::Type::Main );
}
......
......@@ -147,6 +147,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
static std::vector<MediaPtr> fetchHistory( MediaLibraryPtr ml );
static void clearHistory( MediaLibraryPtr ml );
private:
static std::string sortRequest( SortingCriteria sort, bool desc );
private:
MediaLibraryPtr m_ml;
......
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