source: src/mvc/event.cpp @ 4693fa6

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

changed 'Activity' -> 'Track'

  • Property mode set to 100644
File size: 3.9 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_track", 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, QString orderBy)
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.%2").arg(sTable1Name).arg(orderBy));
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
68QString Event::room() const
69{
70    QSqlQuery query;
71    // TODO: conference ID isn't used here
72    query.prepare("SELECT name FROM room WHERE id = (SELECT xid_room FROM event_room WHERE xid_event = :id)");
73    query.bindValue(":id", id());
74    query.exec();
75    // TODO: handle qeury error
76    //qDebug() << query.lastError();
77    if(query.next())
78        return query.record().value("name").toString();
79    else
80        return QString("not-available");
81}
82
83QStringList Event::persons() const
84{
85    QSqlQuery query;
86    // TODO: conference ID isn't used here
87    query.prepare("SELECT person.name FROM person INNER JOIN event_person ON person.id = event_person.xid_person AND event_person.xid_event = :id");
88    query.bindValue(":id", id());
89    query.exec();
90    // TODO: handle qeury error
91    //qDebug() << query.lastError();
92
93    QStringList persons;
94    while(query.next())
95        persons.append(query.record().value("name").toString());
96
97    return persons;
98}
99
100void Event::setRoom(const QString &room)
101{
102    Q_UNUSED(room);
103
104    qWarning("WARINING: setRoom() is NOT IMPLEMENTED YET");
105    // TODO: implement
106}
107
108void Event::setPersons(const QStringList &persons)
109{
110    Q_UNUSED(persons);
111
112    qWarning("WARINING: setPersons() is NOT IMPLEMENTED YET");
113    // TODO: implement
114}
115
Note: See TracBrowser for help on using the repository browser.