Changeset 41c4ceb in confclerk_git


Ignore:
Timestamp:
04/30/13 23:42:38 (9 years ago)
Author:
Philipp Spitzer <philipp@…>
Branches:
master, qt5
Children:
5130dc7
Parents:
83481c6
Message:

Now the dayChange time is taken into account. This fixes #43.

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/mvc/conference.h

    r83481c6 r41c4ceb  
    5050    QDate end() const { return value("end").toDate(); }
    5151    int dayChange() const { return value("day_change").toInt(); } // in seconds from 00:00
     52    QTime dayChangeTime() const {QTime dayChangeTime(0, 0); return dayChangeTime.addSecs(dayChange());}
    5253    int timeslotDuration() const { return value("timeslot_duration").toInt(); } // in seconds
    5354    bool isActive() const { return value("active").toBool(); }
  • src/mvc/event.cpp

    r83481c6 r41c4ceb  
    1818 * ConfClerk.  If not, see <http://www.gnu.org/licenses/>.
    1919 */
     20#include "conference.h"
    2021#include "event.h"
    2122#include "room.h"
     
    5455
    5556QList<Event> Event::getByDate(const QDate& date, int conferenceId, QString orderBy) {
     57    Q_ASSERT(conferenceId > 0);
     58    Conference conference = Conference::getById(conferenceId);
     59    QDateTime dayStart(date, conference.dayChangeTime(), Qt::UTC);
    5660    QSqlQuery query;
    5761    query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY %1").arg(orderBy));
    5862    query.bindValue(":conf", conferenceId);
    59     query.bindValue(":start", convertToDb(date, QVariant::DateTime));
    60     query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
    61     return load(query);
    62 }
    63 
    64 QList<Event> Event::getByDateAndRoom(const QDate& date, int conferenceId)
    65 {
     63    query.bindValue(":start", dayStart.toTime_t());
     64    query.bindValue(":end", dayStart.addDays(1).toTime_t());
     65    return load(query);
     66}
     67
     68
     69QList<Event> Event::getByDateAndRoom(const QDate& date, int conferenceId) {
     70    Q_ASSERT(conferenceId > 0);
     71    Conference conference = Conference::getById(conferenceId);
     72    QDateTime dayStart(date, conference.dayChangeTime(), Qt::UTC);
    6673    QSqlQuery query;
    6774    QString aliasEvent("E");
     
    7077                    columnsForSelect(aliasEvent), Event::sTableName, aliasEvent, "EVENT_ROOM", aliasEventRoom));
    7178    query.bindValue(":conf", conferenceId);
    72     query.bindValue(":start", convertToDb(date, QVariant::DateTime));
    73     query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
     79    query.bindValue(":start", dayStart.toTime_t());
     80    query.bindValue(":end", dayStart.addDays(1).toTime_t());
    7481
    7582    return load(query);
     
    104111
    105112
    106 QList<Event> Event::getFavByDate(const QDate& date, int conferenceId)
    107 {
     113QList<Event> Event::getFavByDate(const QDate& date, int conferenceId) {
     114    Q_ASSERT(conferenceId > 0);
     115    Conference conference = Conference::getById(conferenceId);
     116    QDateTime dayStart(date, conference.dayChangeTime(), Qt::UTC);
    108117    QSqlQuery query;
    109118    query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start >= :start AND start < :end AND favourite = 1 ORDER BY start, duration"));
    110119    query.bindValue(":conf", conferenceId);
    111     query.bindValue(":start", convertToDb(date, QVariant::DateTime));
    112     query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
     120    query.bindValue(":start", dayStart.toTime_t());
     121    query.bindValue(":end", dayStart.addDays(1).toTime_t());
    113122
    114123    return load(query);
     
    237246        }
    238247
     248        Q_ASSERT(conferenceId > 0);
     249        Conference conference = Conference::getById(conferenceId);
     250        QDateTime dayStart(date, conference.dayChangeTime(), Qt::UTC);
     251
    239252        query.bindValue(":conf", conferenceId);
    240         query.bindValue(":start", convertToDb(date, QVariant::DateTime));
    241         query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
     253        query.bindValue(":start", dayStart.toTime_t());
     254        query.bindValue(":end", dayStart.addDays(1).toTime_t());
    242255
    243256        list = load(query);
  • src/mvc/eventmodel.cpp

    r83481c6 r41c4ceb  
    3030
    3131void EventModel::Group::setTitle(const QList<Event>& mEvents) {
    32     QTime startTime = mEvents.at(mFirstEventIndex).start().time();
    33     QTime endTime(0, 0);
     32    QDateTime startTime = mEvents.at(mFirstEventIndex).start();
     33    QDateTime endTime(startTime);
    3434    for (int i = mFirstEventIndex; i != mFirstEventIndex + mChildCount; ++i) {
    35         endTime = qMax(mEvents.at(i).start().time().addSecs(mEvents.at(i).duration()), endTime);
     35        endTime = qMax(mEvents.at(i).start().addSecs(mEvents.at(i).duration()), endTime);
    3636    }
    3737    mTitle = QString("%1 - %2").arg(startTime.toString("HH:mm")).arg(endTime.toString("HH:mm"));
     
    236236}
    237237
    238 void EventModel::loadEvents(const QDate &aDate, int aConferenceId)
    239 {
    240     clearModel();
    241     // check for existence of the conference in the DB
    242     if(Conference::getAll().count())
    243     {
    244         mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start, duration");
    245     }
     238
     239void EventModel::loadEvents(const QDate &aDate, int aConferenceId) {
     240    clearModel();
     241    mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start, duration");
    246242    createTimeGroups();
    247243}
    248244
    249 void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId)
    250 {
    251     clearModel();
    252     // check for existence of the conference in the DB
    253     if(Conference::getAll().count())
    254     {
    255         mEvents = Event::getFavByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
    256     }
     245
     246void EventModel::loadFavEvents(const QDate &aDate, int aConferenceId) {
     247    clearModel();
     248    mEvents = Event::getFavByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
    257249    createTimeGroups();
    258250}
    259251
    260 int EventModel::loadSearchResultEvents(const QDate &aDate, int aConferenceId)
    261 {
    262     clearModel();
    263     // check for existence of the conference in the DB
    264     if(Conference::getAll().count())
    265     {
    266         try{
    267             mEvents = Event::getSearchResultByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start, duration");
    268         }
    269         catch( OrmException &e  ){
    270             qDebug() << "Event::getSearchResultByDate failed: " << e.text();
    271         }
    272         catch(...){
    273             qDebug() << "Event::getSearchResultByDate failed";
    274         }
    275 
     252
     253int EventModel::loadSearchResultEvents(const QDate &aDate, int aConferenceId) {
     254    clearModel();
     255    try {
     256        mEvents = Event::getSearchResultByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "start, duration");
     257    }
     258    catch( OrmException &e  ){
     259        qDebug() << "Event::getSearchResultByDate failed: " << e.text();
     260    }
     261    catch(...){
     262        qDebug() << "Event::getSearchResultByDate failed";
    276263    }
    277264
     
    281268}
    282269
    283 void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId)
    284 {
    285     clearModel();
    286     if (Conference::getAll().count())
    287     {
    288         mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "xid_track, start, duration");
    289     }
     270
     271void EventModel::loadEventsByTrack(const QDate &aDate, int aConferenceId) {
     272    clearModel();
     273    mEvents = Event::getByDate(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId, "xid_track, start, duration");
    290274    createTrackGroups();
    291275}
    292276
    293 void EventModel::loadEventsByRoom(const QDate &aDate, int aConferenceId)
    294 {
    295     clearModel();
    296     if (Conference::getAll().count())
    297     {
    298         mEvents = Event::getByDateAndRoom(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
    299     }
     277
     278void EventModel::loadEventsByRoom(const QDate &aDate, int aConferenceId) {
     279    clearModel();
     280    mEvents = Event::getByDateAndRoom(QDate(aDate.year(), aDate.month(), aDate.day()), aConferenceId);
    300281    createRoomGroups();
    301282}
     
    304285void EventModel::loadConflictEvents(int aEventId, int aConferenceId) {
    305286    clearModel();
    306     // check for existence of the conference in the DB
    307     if(Conference::getAll().count())
    308     {
    309         mEvents = Event::conflictEvents(aEventId, aConferenceId);
    310     }
     287    mEvents = Event::conflictEvents(aEventId, aConferenceId);
    311288    createTimeGroups();
    312289}
     290
    313291
    314292void EventModel::updateModel(int aEventId)
  • src/sql/sqlengine.cpp

    r83481c6 r41c4ceb  
    173173
    174174void SqlEngine::addEventToDB(QHash<QString,QString> &aEvent) {
    175     //insert event track to table and get track id
    176     int conference = aEvent["conference_id"].toInt();
    177     QString name = aEvent["track"];
     175    int conferenceId = aEvent["conference_id"].toInt();
     176    Conference conference = Conference::getById(conferenceId);
     177
     178    // insert event track to table and get track id
    178179    Track track;
    179180    int trackId;
     181    QString trackName = aEvent["track"];
    180182    try
    181183    {
    182         track = Track::retrieveByName(conference, name);
     184        track = Track::retrieveByName(conferenceId, trackName);
    183185        trackId = track.id();
    184186    }
    185187    catch (OrmNoObjectException &e) {
    186         track.setConference(conference);
    187         track.setName(name);
     188        track.setConference(conferenceId);
     189        track.setName(trackName);
    188190        trackId = track.insert();
    189191    }
     192    QDate startDate = QDate::fromString(aEvent["date"], DATE_FORMAT);
     193    QTime startTime = QTime::fromString(aEvent["start"], TIME_FORMAT);
     194    // consider day_change (note that if day_change is e.g. at 04:00 AM, an event starting at 02:00 AM has the previous date in the XML file)
     195    if (startTime < conference.dayChangeTime()) startDate = startDate.addDays(1);
    190196    QDateTime startDateTime;
    191197    startDateTime.setTimeSpec(Qt::UTC);
    192     startDateTime = QDateTime(QDate::fromString(aEvent["date"],DATE_FORMAT),QTime::fromString(aEvent["start"],TIME_FORMAT),Qt::UTC);
     198    startDateTime = QDateTime(startDate, startTime, Qt::UTC);
    193199
    194200    bool event_exists = false;
Note: See TracChangeset for help on using the changeset viewer.