source: src/mvc/event.cpp @ f9db452

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

map-name to map-path implemented

  • correct map is displayed
  • Property mode set to 100644
File size: 3.4 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
[64122f1]10const QString Event::XID_ACTIVITY = "xid_activity";
11const QString Event::START = "start";
12
13
[c790268]14
[20a6010]15QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
[c790268]16    /* 'columns from Table 1 */
[20a6010]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)
[680a4da]23    << QSqlField("language", QVariant::String)
[c790268]24    << QSqlField("favourite", QVariant::Bool)
[b6cd05c]25    << QSqlField("alarm", QVariant::Bool)
[c790268]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));
[5a73d27]32
[20a6010]33
34Event Event::getById(int id, int conferenceId)
35{
[d0d0a66]36    QSqlQuery query;
[9f473ba]37    query.prepare(
38            selectQueryJoin2T("id")
39            + QString("WHERE %1.id = :id AND %1.xid_conference = :conf").arg(sTable1Name));
[d0d0a66]40    query.bindValue(":id", id);
41    query.bindValue(":conf", conferenceId);
[c790268]42
[d0d0a66]43    return loadOne(query);
44}
45
[64122f1]46QList<Event> Event::getByDate(const QDate& date, int conferenceId, QString orderBy)
[d0d0a66]47{
48    QSqlQuery query;
[9f473ba]49    query.prepare(
50            selectQueryJoin2T("id")
[64122f1]51            + QString("WHERE %1.xid_conference = :conf AND %1.start >= :start AND %1.start < :end ORDER BY %1.%2").arg(sTable1Name).arg(orderBy));
[d0d0a66]52    query.bindValue(":conf", conferenceId);
53    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
54    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
[20a6010]55
[d0d0a66]56    return load(query);
[20a6010]57}
[680a4da]58
[6f39595]59QList<Event> Event::getFavByDate(const QDate& date, int conferenceId)
60{
61    QSqlQuery query;
[9f473ba]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));
[6f39595]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
[f9db452]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    {
82        QString map = query.record().value("name").toString();
83        map=map.toLower(); // room names are stored in lower-case format
84        map=map.remove("."); // room names are stored without dots in the name, eg. "aw.1124.png" -> "aw1124.png"
85        return map;
86    }
87    else
88        return QString("not-available");
89}
90
91void Event::setRoom(const QString &room)
92{
93    qWarning("WARINING: setRoom() is NOT IMPLEMENTED YET");
94    // TODO: implement
95}
[27102d5]96
Note: See TracBrowser for help on using the repository browser.