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
RevLine 
[e5bc908]1#include "event.h"
2
[c790268]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");
[b6cd05c]8int const Event::sTable1ColCount = 9; // see 'toRecord()' for more details
[c790268]9int const Event::sTable2ColCount = 5; // see 'toRecord()' for more details
10
[20a6010]11QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
[c790268]12    /* 'columns from Table 1 */
[20a6010]13    << QSqlField("id", QVariant::Int)
14    << QSqlField("xid_conference", QVariant::Int)
15    << QSqlField("start", QVariant::DateTime)
16    << QSqlField("duration", QVariant::Int)
[4693fa6]17    << QSqlField("xid_track", QVariant::Int)
[20a6010]18    << QSqlField("type", QVariant::String)
[680a4da]19    << QSqlField("language", QVariant::String)
[c790268]20    << QSqlField("favourite", QVariant::Bool)
[b6cd05c]21    << QSqlField("alarm", QVariant::Bool)
[c790268]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));
[5a73d27]28
[20a6010]29
30Event Event::getById(int id, int conferenceId)
31{
[d0d0a66]32    QSqlQuery query;
[9f473ba]33    query.prepare(
34            selectQueryJoin2T("id")
35            + QString("WHERE %1.id = :id AND %1.xid_conference = :conf").arg(sTable1Name));
[d0d0a66]36    query.bindValue(":id", id);
37    query.bindValue(":conf", conferenceId);
[c790268]38
[d0d0a66]39    return loadOne(query);
40}
41
[64122f1]42QList<Event> Event::getByDate(const QDate& date, int conferenceId, QString orderBy)
[d0d0a66]43{
44    QSqlQuery query;
[9f473ba]45    query.prepare(
46            selectQueryJoin2T("id")
[64122f1]47            + QString("WHERE %1.xid_conference = :conf AND %1.start >= :start AND %1.start < :end ORDER BY %1.%2").arg(sTable1Name).arg(orderBy));
[d0d0a66]48    query.bindValue(":conf", conferenceId);
49    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
50    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
[20a6010]51
[d0d0a66]52    return load(query);
[20a6010]53}
[680a4da]54
[6f39595]55QList<Event> Event::getFavByDate(const QDate& date, int conferenceId)
56{
57    QSqlQuery query;
[9f473ba]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));
[6f39595]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
[f9db452]68QString Event::room() const
69{
70    QSqlQuery query;
[395d6d3]71    // TODO: conference ID isn't used here
[f9db452]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())
[9afc0ee]78        return query.record().value("name").toString();
[f9db452]79    else
80        return QString("not-available");
81}
82
[395d6d3]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
[f9db452]100void Event::setRoom(const QString &room)
101{
[395d6d3]102    Q_UNUSED(room);
103
[f9db452]104    qWarning("WARINING: setRoom() is NOT IMPLEMENTED YET");
105    // TODO: implement
106}
[27102d5]107
[395d6d3]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.