9caf2aba97a961b505692cf4ee718e8eee1a8980
[toast/confclerk.git] / src / mvc / event.cpp
1 #include "event.h"
2
3 QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
4     << QSqlField("id", QVariant::Int)
5     << QSqlField("xid_conference", QVariant::Int)
6     << QSqlField("start", QVariant::DateTime)
7     << QSqlField("duration", QVariant::Int)
8     << QSqlField("xid_activity", QVariant::Int)
9     << QSqlField("type", QVariant::String)
10     << QSqlField("language", QVariant::String)
11     << QSqlField("favourite", QVariant::Bool));
12
13 QString const Event::sTableName = QString("event");
14
15 Event Event::getById(int id, int conferenceId)
16 {
17     QSqlQuery query;
18     query.prepare(selectQuery() + "WHERE id = :id AND xid_conference = :conf");
19     query.bindValue(":id", id);
20     query.bindValue(":conf", conferenceId);
21     return loadOne(query);
22 }
23
24 QList<Event> Event::getByDate(const QDate& date, int conferenceId)
25 {
26     QSqlQuery query;
27     query.prepare(selectQuery() + "WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY start");
28     query.bindValue(":conf", conferenceId);
29     query.bindValue(":start", convertToDb(date, QVariant::DateTime));
30     query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
31
32     return load(query);
33 }
34