From: korrco Date: Mon, 18 Jan 2010 18:38:55 +0000 (+0000) Subject: sorting by activity id added X-Git-Tag: 0.5.0~282 X-Git-Url: https://git.toastfreeware.priv.at/toast/confclerk.git/commitdiff_plain/64122f178291e7c3e5c6f20ef4bcb3bf93ad9280 sorting by activity id added --- diff --git a/src/mvc/event.cpp b/src/mvc/event.cpp index fa062ac..0a196f5 100644 --- a/src/mvc/event.cpp +++ b/src/mvc/event.cpp @@ -7,6 +7,10 @@ QString const Event::sTable1Name = QString("event"); QString const Event::sTable2Name = QString("virtual_event"); int const Event::sTable1ColCount = 9; // see 'toRecord()' for more details int const Event::sTable2ColCount = 5; // see 'toRecord()' for more details +const QString Event::XID_ACTIVITY = "xid_activity"; +const QString Event::START = "start"; + + QSqlRecord const Event::sColumns = Event::toRecord(QList() /* 'columns from Table 1 */ @@ -39,12 +43,12 @@ Event Event::getById(int id, int conferenceId) return loadOne(query); } -QList Event::getByDate(const QDate& date, int conferenceId) +QList Event::getByDate(const QDate& date, int conferenceId, QString orderBy) { QSqlQuery query; query.prepare( selectQueryJoin2T("id") - + QString("WHERE %1.xid_conference = :conf AND %1.start >= :start AND %1.start < :end ORDER BY %1.start").arg(sTable1Name)); + + QString("WHERE %1.xid_conference = :conf AND %1.start >= :start AND %1.start < :end ORDER BY %1.%2").arg(sTable1Name).arg(orderBy)); query.bindValue(":conf", conferenceId); query.bindValue(":start", convertToDb(date, QVariant::DateTime)); query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime)); diff --git a/src/mvc/event.h b/src/mvc/event.h index 30f0110..edf5ada 100644 --- a/src/mvc/event.h +++ b/src/mvc/event.h @@ -17,46 +17,135 @@ class NoSuchEventException class Event : public OrmRecord { public: - static QSqlRecord const sColumns; + static const QSqlRecord sColumns; //static QString const sTableName; - static QString const sTable1Name; - static QString const sTable2Name; - static int const sTable1ColCount; - static int const sTable2ColCount; - + static const QString sTable1Name; + static const QString sTable2Name; + static const int sTable1ColCount; + static const int sTable2ColCount; + static const QString XID_ACTIVITY; + static const QString START; public: static Event getById(int id, int conferenceId); - static QList getByDate(const QDate& date, int conferenceId); - static QList getFavByDate(const QDate& date, int conferenceId); // get Favourities by Date - + static QList getByDate(const QDate & date, int conferenceId, QString orderBy); + static QList getFavByDate(const QDate & date, int conferenceId); // get Favourities by Date public: // Table 1 - int id() const { return value("id").toInt(); } - int conferenceId() const { return value("xid_conference").toInt(); } - QDateTime start() const { return value("start").toDateTime(); } - int duration() const { return value("duration").toInt(); } - int activityId() const { return value("xid_activity").toInt(); } - QString type() const { return value("type").toString(); } - QString language() const { return value("language").toString(); } - bool isFavourite() const { return value("favourite").toBool(); } - bool hasAlarm() const { return value("alarm").toBool(); } + int id() const + { + return value("id").toInt(); + } + + int conferenceId() const + { + return value("xid_conference").toInt(); + } + + QDateTime start() const + { + return value(START).toDateTime(); + } + + int duration() const + { + return value("duration").toInt(); + } + + int activityId() const + { + return value(XID_ACTIVITY).toInt(); + } + + QString type() const + { + return value("type").toString(); + } + + QString language() const + { + return value("language").toString(); + } + + bool isFavourite() const + { + return value("favourite").toBool(); + } + + bool hasAlarm() const + { + return value("alarm").toBool(); + } + // Table 2 : virtual table for FTS (Full Text Search) - QString tag() const { return value("tag").toString(); } - QString title() const { return value("title").toString(); } - QString subtitle() const { return value("subtitle").toString(); } - QString abstract() const { return value("abstract").toString(); } - QString description() const { return value("description").toString(); } + QString tag() const + { + return value("tag").toString(); + } + + QString title() const + { + return value("title").toString(); + } + + QString subtitle() const + { + return value("subtitle").toString(); + } + + QString abstract() const + { + return value("abstract").toString(); + } + + QString description() const + { + return value("description").toString(); + } // Table 1 - void setId(int id) { setValue("id", id); } - void setConferenceId(int conferenceId) { setValue("xid_conference", conferenceId); } - void setStart(const QDateTime& start) { setValue("start", start); } - void setDuration(int duration) { setValue("duration", duration); } - void setActivityId(int activityId) { setValue("xid_activity", activityId); } - void setType(const QString& type) { setValue("type", type); } - void setLanguage(const QString& language) { setValue("language", language); } - void setFavourite(bool favourite) { setValue("favourite", (int)favourite); } - void setHasAlarm(bool alarm) { setValue("alarm", (int)alarm); } + void setId(int id) + { + setValue("id", id); + } + + void setConferenceId(int conferenceId) + { + setValue("xid_conference", conferenceId); + } + + void setStart(const QDateTime & start) + { + setValue(START, start); + } + + void setDuration(int duration) + { + setValue("duration", duration); + } + + void setActivityId(int activityId) + { + setValue(XID_ACTIVITY, activityId); + } + + void setType(const QString & type) + { + setValue("type", type); + } + + void setLanguage(const QString & language) + { + setValue("language", language); + } + + void setFavourite(bool favourite) + { + setValue("favourite", (int)((favourite))); + } + + void setHasAlarm(bool alarm) + { + setValue("alarm", (int)((alarm))); } // Table 2 : virtual table for FTS (Full Text Search) void setTag(const QString& tag) { setValue("tag", tag); } void setTitle(const QString& title) { setValue("title", title); } diff --git a/src/mvc/eventmodel.cpp b/src/mvc/eventmodel.cpp index 2753223..a9801f9 100644 --- a/src/mvc/eventmodel.cpp +++ b/src/mvc/eventmodel.cpp @@ -164,7 +164,7 @@ void EventModel::loadEvents(const QDate &aDate, int aConferenceId) if(Conference::getAll().count()) { qDebug() << "Loading Conference Data: [" << Conference::getById(aConferenceId).title() << "] " << aDate; - mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId); + mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, Event::START); } createTimeGroups(); } @@ -187,7 +187,7 @@ void EventModel::loadEventsByActivities(const QDate &aDate, int aConferenceId) if(Conference::getAll().count()) { qDebug() << "Loading Conference Data (by Activities): [" << Conference::getById(aConferenceId).title() << "] " << aDate; - mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId); + mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, Event::XID_ACTIVITY); } createActivityGroups(); }