source: src/mvc/event.cpp @ b6cd05c

qt5
Last change on this file since b6cd05c was b6cd05c, checked in by pavelpa <pavelpa@…>, 12 years ago

added 'alarm' columnt to the 'EVENT' table to signalize
that the event has/hasn't alarm set

  • Property mode set to 100644
File size: 2.6 KB
Line 
1#include "event.h"
2
3// 'event' record is splitted into two separate tables 'event' and 'virtual_event'
4// for the FTS (Full-Text-Search) support and so, it is necessary to provide/use
5// two table names + corresponding parameters/methods, see bellow
6QString const Event::sTable1Name = QString("event");
7QString const Event::sTable2Name = QString("virtual_event");
8int const Event::sTable1ColCount = 9; // see 'toRecord()' for more details
9int const Event::sTable2ColCount = 5; // see 'toRecord()' for more details
10
11QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
12    /* 'columns from Table 1 */
13    << QSqlField("id", QVariant::Int)
14    << QSqlField("xid_conference", QVariant::Int)
15    << QSqlField("start", QVariant::DateTime)
16    << QSqlField("duration", QVariant::Int)
17    << QSqlField("xid_activity", QVariant::Int)
18    << QSqlField("type", QVariant::String)
19    << QSqlField("language", QVariant::String)
20    << QSqlField("favourite", QVariant::Bool)
21    << QSqlField("alarm", QVariant::Bool)
22    /* 'columns' from Table2 */
23    << QSqlField("tag", QVariant::String)
24    << QSqlField("title", QVariant::String)
25    << QSqlField("subtitle", QVariant::String)
26    << QSqlField("abstract", QVariant::String)
27    << QSqlField("description", QVariant::String));
28
29
30Event Event::getById(int id, int conferenceId)
31{
32    QSqlQuery query;
33    query.prepare(
34            selectQueryJoin2T("id")
35            + QString("WHERE %1.id = :id AND %1.xid_conference = :conf").arg(sTable1Name));
36    query.bindValue(":id", id);
37    query.bindValue(":conf", conferenceId);
38
39    return loadOne(query);
40}
41
42QList<Event> Event::getByDate(const QDate& date, int conferenceId)
43{
44    QSqlQuery query;
45    query.prepare(
46            selectQueryJoin2T("id")
47            + QString("WHERE %1.xid_conference = :conf AND %1.start >= :start AND %1.start < :end ORDER BY %1.start").arg(sTable1Name));
48    query.bindValue(":conf", conferenceId);
49    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
50    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
51
52    return load(query);
53}
54
55QList<Event> Event::getFavByDate(const QDate& date, int conferenceId)
56{
57    QSqlQuery query;
58    query.prepare(
59            selectQueryJoin2T("id")
60            + QString("WHERE %1.xid_conference = :conf AND %1.start >= :start AND %1.start < :end AND %1.favourite = 1 ORDER BY %1.start").arg(sTable1Name));
61    query.bindValue(":conf", conferenceId);
62    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
63    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
64
65    return load(query);
66}
67
68
Note: See TracBrowser for help on using the repository browser.