source: src/mvc/event.cpp @ 699d5b8

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

combined EVENT and VIRTUAL_EVENT => 'EVENT' now

  • Maemo sqlite doesn't support Full-Text-Search
  • Property mode set to 100644
File size: 3.8 KB
Line 
1#include "event.h"
2
3QString const Event::sTableName = QString("event");
4
5QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
6    << QSqlField("id", QVariant::Int)
7    << QSqlField("xid_conference", QVariant::Int)
8    << QSqlField("start", QVariant::DateTime)
9    << QSqlField("duration", QVariant::Int)
10    << QSqlField("xid_track", QVariant::Int)
11    << QSqlField("type", QVariant::String)
12    << QSqlField("language", QVariant::String)
13    << QSqlField("favourite", QVariant::Bool)
14    << QSqlField("alarm", QVariant::Bool)
15    << QSqlField("tag", QVariant::String)
16    << QSqlField("title", QVariant::String)
17    << QSqlField("subtitle", QVariant::String)
18    << QSqlField("abstract", QVariant::String)
19    << QSqlField("description", QVariant::String));
20
21
22Event Event::getById(int id, int conferenceId)
23{
24
25    QSqlQuery query;
26    query.prepare(selectQuery() + "WHERE id = :id AND xid_conference = :conf");
27    query.bindValue(":id", id);
28    query.bindValue(":conf", conferenceId);
29    return loadOne(query);
30}
31
32QList<Event> Event::getByDate(const QDate& date, int conferenceId, QString orderBy)
33{
34    QSqlQuery query;
35    query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY %1").arg(orderBy));
36    query.bindValue(":conf", conferenceId);
37    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
38    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
39
40    return load(query);
41}
42
43QList<Event> Event::getFavByDate(const QDate& date, int conferenceId)
44{
45    QSqlQuery query;
46    query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start >= :start AND start < :end AND favourite = 1 ORDER BY start"));
47    query.bindValue(":conf", conferenceId);
48    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
49    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
50
51    return load(query);
52}
53
54QString Event::room() const
55{
56    QSqlQuery query;
57    // TODO: conference ID isn't used here
58    query.prepare("SELECT name FROM room WHERE id = (SELECT xid_room FROM event_room WHERE xid_event = :id)");
59    query.bindValue(":id", id());
60    query.exec();
61    // TODO: handle qeury error
62    //qDebug() << query.lastError();
63    if(query.next())
64        return query.record().value("name").toString();
65    else
66        return QString("not-available");
67}
68
69QStringList Event::persons() const
70{
71    QSqlQuery query;
72    // TODO: conference ID isn't used here
73    query.prepare("SELECT person.name FROM person INNER JOIN event_person ON person.id = event_person.xid_person AND event_person.xid_event = :id");
74    query.bindValue(":id", id());
75    query.exec();
76    // TODO: handle qeury error
77    //qDebug() << query.lastError();
78
79    QStringList persons;
80    while(query.next())
81        persons.append(query.record().value("name").toString());
82
83    return persons;
84}
85
86void Event::setRoom(const QString &room)
87{
88    Q_UNUSED(room);
89
90    qWarning("WARINING: setRoom() is NOT IMPLEMENTED YET");
91    // TODO: implement
92}
93
94void Event::setPersons(const QStringList &persons)
95{
96    Q_UNUSED(persons);
97
98    qWarning("WARINING: setPersons() is NOT IMPLEMENTED YET");
99    // TODO: implement
100}
101
102QList<Event> Event::getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy)
103{
104
105    QString strQuery = QString("SELECT %1 FROM EVENT INNER JOIN SEARCH_EVENT USING (xid_conference, id) ").arg(columnsForSelect());
106    strQuery += QString("WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY %1").arg(orderBy);
107    qDebug() << strQuery;
108    QSqlQuery query;
109    query.prepare( strQuery );
110    query.bindValue(":conf", conferenceId);
111    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
112    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
113
114    return load(query);
115}
116
Note: See TracBrowser for help on using the repository browser.