source: src/mvc/event.cpp @ 9208bdb

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

event-dialog - displayed persons/presenters names

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