[UI/MOBILE] Handling year in release
This commit is contained in:
@@ -140,4 +140,28 @@ Release::getByFilter(Wt::Dbo::Session& session, SearchFilter filter, int offset,
|
||||
return std::vector<pointer>(res.begin(), res.end());
|
||||
}
|
||||
|
||||
int
|
||||
Release::getReleaseYear(bool original) const
|
||||
{
|
||||
assert(session());
|
||||
|
||||
// TODO something better
|
||||
auto tracks = Track::getByFilter(*session(), SearchFilter::ById(SearchFilter::Field::Release, this->id()), -1, 1);
|
||||
|
||||
if (tracks.empty())
|
||||
return 0;
|
||||
|
||||
boost::gregorian::date date;
|
||||
|
||||
if (original)
|
||||
date = tracks.front()->getOriginalDate().date();
|
||||
else
|
||||
date = tracks.front()->getDate().date();
|
||||
|
||||
if (date.is_special())
|
||||
return 0;
|
||||
|
||||
return date.year();
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
|
||||
@@ -53,6 +53,9 @@ class Release : public Wt::Dbo::Dbo<Release>
|
||||
// Create
|
||||
static pointer create(Wt::Dbo::Session& session, const std::string& name, const std::string& MBID = "");
|
||||
|
||||
// Utility functions
|
||||
int getReleaseYear(bool originalDate = false) const; // 0 if unknown or various
|
||||
|
||||
// MVC models for the user interface
|
||||
// ID, Release name, year, track counts
|
||||
typedef boost::tuple<id_type, std::string, boost::posix_time::ptime, int> UIQueryResult;
|
||||
|
||||
Reference in New Issue
Block a user