[Remote] Added genre filter on artist searches
This commit is contained in:
@@ -17,8 +17,12 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
#include "AudioTypes.hpp"
|
||||
|
||||
#include "SqlQuery.hpp"
|
||||
|
||||
namespace Database
|
||||
{
|
||||
|
||||
@@ -63,5 +67,40 @@ Artist::getAllOrphans(Wt::Dbo::Session& session)
|
||||
return session.query< Wt::Dbo::ptr<Artist> >("select a from artist a LEFT OUTER JOIN Track t ON a.id = t.artist_id WHERE t.id IS NULL");
|
||||
}
|
||||
|
||||
Wt::Dbo::collection<Artist::pointer>
|
||||
Artist::getAll(Wt::Dbo::Session& session,
|
||||
const std::vector<Genre::id_type>& genreIds,
|
||||
int offset, int size)
|
||||
{
|
||||
std::string sqlQuery = "SELECT a FROM artist a";
|
||||
|
||||
if (!genreIds.empty())
|
||||
{
|
||||
sqlQuery += " INNER JOIN genre g ON g.id = t_g.genre_id";
|
||||
sqlQuery += " INNER JOIN track t ON t.id = t_g.track_id AND t.artist_id = a.id";
|
||||
sqlQuery += " INNER JOIN track_genre t_g ON t_g.track_id = t.id AND t_g.genre_id = g.id";
|
||||
}
|
||||
|
||||
WhereClause where;
|
||||
{
|
||||
WhereClause genreWhere;
|
||||
|
||||
for (std::size_t i = 0; i < genreIds.size(); ++i)
|
||||
genreWhere.Or( WhereClause("g.id = ?") );
|
||||
|
||||
where.And(genreWhere);
|
||||
}
|
||||
|
||||
Wt::Dbo::Query<Artist::pointer> query = session.query<Artist::pointer>( sqlQuery + " " + where.get() ).offset(offset).limit(size);
|
||||
|
||||
BOOST_FOREACH(const Genre::id_type genreId, genreIds)
|
||||
query.bind(genreId);
|
||||
|
||||
query.groupBy("a");
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
|
||||
} // namespace Database
|
||||
|
||||
|
||||
+41
-37
@@ -36,6 +36,44 @@ class Track;
|
||||
class Release;
|
||||
class Artist;
|
||||
|
||||
class Genre
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Wt::Dbo::ptr<Genre> pointer;
|
||||
typedef Wt::Dbo::dbo_traits<Genre>::IdType id_type;
|
||||
|
||||
Genre();
|
||||
Genre(const std::string& name);
|
||||
|
||||
// Find utility
|
||||
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
|
||||
static pointer getNone(Wt::Dbo::Session& session);
|
||||
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::size_t offset = -1, std::size_t size = -1);
|
||||
|
||||
// Create utility
|
||||
static pointer create(Wt::Dbo::Session& session, const std::string& name);
|
||||
|
||||
// Accessors
|
||||
const std::string& getName(void) const { return _name; }
|
||||
bool isNone(void) const;
|
||||
const Wt::Dbo::collection< Wt::Dbo::ptr<Track> >& getTracks() const { return _tracks;}
|
||||
|
||||
template<class Action>
|
||||
void persist(Action& a)
|
||||
{
|
||||
Wt::Dbo::field(a, _name, "name");
|
||||
Wt::Dbo::hasMany(a, _tracks, Wt::Dbo::ManyToMany, "track_genre", "", Wt::Dbo::OnDeleteCascade);
|
||||
}
|
||||
|
||||
private:
|
||||
static const std::size_t _maxNameLength = 128;
|
||||
std::string _name;
|
||||
|
||||
Wt::Dbo::collection< Wt::Dbo::ptr<Track> > _tracks;
|
||||
};
|
||||
|
||||
|
||||
class Artist
|
||||
{
|
||||
public:
|
||||
@@ -50,6 +88,9 @@ class Artist
|
||||
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
|
||||
static pointer getNone(Wt::Dbo::Session& session);
|
||||
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, int offset = -1, int size = -1);
|
||||
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session,
|
||||
const std::vector<Genre::id_type>& genreIds,
|
||||
int offset = -1, int size = -1);
|
||||
static Wt::Dbo::collection<pointer> getAllOrphans(Wt::Dbo::Session& session);
|
||||
|
||||
const std::string& getName(void) const { return _name; }
|
||||
@@ -122,43 +163,6 @@ class Release
|
||||
};
|
||||
|
||||
|
||||
class Genre
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Wt::Dbo::ptr<Genre> pointer;
|
||||
typedef Wt::Dbo::dbo_traits<Genre>::IdType id_type;
|
||||
|
||||
Genre();
|
||||
Genre(const std::string& name);
|
||||
|
||||
// Find utility
|
||||
static pointer getByName(Wt::Dbo::Session& session, const std::string& name);
|
||||
static pointer getNone(Wt::Dbo::Session& session);
|
||||
static Wt::Dbo::collection<pointer> getAll(Wt::Dbo::Session& session, std::size_t offset = -1, std::size_t size = -1);
|
||||
|
||||
// Create utility
|
||||
static pointer create(Wt::Dbo::Session& session, const std::string& name);
|
||||
|
||||
// Accessors
|
||||
const std::string& getName(void) const { return _name; }
|
||||
bool isNone(void) const;
|
||||
const Wt::Dbo::collection< Wt::Dbo::ptr<Track> >& getTracks() const { return _tracks;}
|
||||
|
||||
template<class Action>
|
||||
void persist(Action& a)
|
||||
{
|
||||
Wt::Dbo::field(a, _name, "name");
|
||||
Wt::Dbo::hasMany(a, _tracks, Wt::Dbo::ManyToMany, "track_genre", "", Wt::Dbo::OnDeleteCascade);
|
||||
}
|
||||
|
||||
private:
|
||||
static const std::size_t _maxNameLength = 128;
|
||||
std::string _name;
|
||||
|
||||
Wt::Dbo::collection< Wt::Dbo::ptr<Track> > _tracks;
|
||||
};
|
||||
|
||||
class Track
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user