source: src/mvc/event.cpp @ cfd615d

qt5
Last change on this file since cfd615d was 9afc0ee, checked in by pavelpa <pavelpa@…>, 13 years ago

set MapDialog? title

  • Property mode set to 100644
File size: 3.2 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
10const QString Event::XID_ACTIVITY = "xid_activity";
11const QString Event::START = "start";
12
13
14
15QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
16    /* 'columns from Table 1 */
17    << QSqlField("id", QVariant::Int)
18    << QSqlField("xid_conference", QVariant::Int)
19    << QSqlField("start", QVariant::DateTime)
20    << QSqlField("duration", QVariant::Int)
21    << QSqlField("xid_activity", QVariant::Int)
22    << QSqlField("type", QVariant::String)
23    << QSqlField("language", QVariant::String)
24    << QSqlField("favourite", QVariant::Bool)
25    << QSqlField("alarm", QVariant::Bool)
26    /* 'columns' from Table2 */
27    << QSqlField("tag", QVariant::String)
28    << QSqlField("title", QVariant::String)
29    << QSqlField("subtitle", QVariant::String)
30    << QSqlField("abstract", QVariant::String)
31    << QSqlField("description", QVariant::String));
32
33
34Event Event::getById(int id, int conferenceId)
35{
36    QSqlQuery query;
37    query.prepare(
38            selectQueryJoin2T("id")
39            + QString("WHERE %1.id = :id AND %1.xid_conference = :conf").arg(sTable1Name));
40    query.bindValue(":id", id);
41    query.bindValue(":conf", conferenceId);
42
43    return loadOne(query);
44}
45
46QList<Event> Event::getByDate(const QDate& date, int conferenceId, QString orderBy)
47{
48    QSqlQuery query;
49    query.prepare(
50            selectQueryJoin2T("id")
51            + QString("WHERE %1.xid_conference = :conf AND %1.start >= :start AND %1.start < :end ORDER BY %1.%2").arg(sTable1Name).arg(orderBy));
52    query.bindValue(":conf", conferenceId);
53    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
54    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
55
56    return load(query);
57}
58
59QList<Event> Event::getFavByDate(const QDate& date, int conferenceId)
60{
61    QSqlQuery query;
62    query.prepare(
63            selectQueryJoin2T("id")
64            + QString("WHERE %1.xid_conference = :conf AND %1.start >= :start AND %1.start < :end AND %1.favourite = 1 ORDER BY %1.start").arg(sTable1Name));
65    query.bindValue(":conf", conferenceId);
66    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
67    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
68
69    return load(query);
70}
71
72QString Event::room() const
73{
74    QSqlQuery query;
75    query.prepare("SELECT name FROM room WHERE id = (SELECT xid_room FROM event_room WHERE xid_event = :id)");
76    query.bindValue(":id", id());
77    query.exec();
78    // TODO: handle qeury error
79    //qDebug() << query.lastError();
80    if(query.next())
81        return query.record().value("name").toString();
82    else
83        return QString("not-available");
84}
85
86void Event::setRoom(const QString &room)
87{
88    qWarning("WARINING: setRoom() is NOT IMPLEMENTED YET");
89    // TODO: implement
90}
91
Note: See TracBrowser for help on using the repository browser.