source: src/mvc/event.cpp @ 9d8946b

qt5
Last change on this file since 9d8946b was 9d8946b, checked in by timkoma <timkoma@…>, 12 years ago

update for the 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    QSqlQuery query;
25    query.prepare(selectQuery() + "WHERE id = :id AND xid_conference = :conf");
26    query.bindValue(":id", id);
27    query.bindValue(":conf", conferenceId);
28    return loadOne(query);
29}
30
31QList<Event> Event::getByDate(const QDate& date, int conferenceId, QString orderBy)
32{
33    QSqlQuery query;
34    query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY %1").arg(orderBy));
35    query.bindValue(":conf", conferenceId);
36    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
37    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
38
39    return load(query);
40}
41
42QList<Event> Event::getFavByDate(const QDate& date, int conferenceId)
43{
44    QSqlQuery query;
45    query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start >= :start AND start < :end AND favourite = 1 ORDER BY start"));
46    query.bindValue(":conf", conferenceId);
47    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
48    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
49
50    return load(query);
51}
52
53QString Event::room() const
54{
55    QSqlQuery query;
56    // TODO: conference ID isn't used here
57    query.prepare("SELECT name FROM room WHERE id = (SELECT xid_room FROM event_room WHERE xid_event = :id)");
58    query.bindValue(":id", id());
59    query.exec();
60    // TODO: handle qeury error
61    //qDebug() << query.lastError();
62    if(query.next())
63        return query.record().value("name").toString();
64    else
65        return QString("not-available");
66}
67
68QStringList Event::persons() const
69{
70    QSqlQuery query;
71    // TODO: conference ID isn't used here
72    query.prepare("SELECT person.name FROM person INNER JOIN event_person ON person.id = event_person.xid_person AND event_person.xid_event = :id");
73    query.bindValue(":id", id());
74    query.exec();
75    // TODO: handle qeury error
76    //qDebug() << query.lastError();
77
78    QStringList persons;
79    while(query.next())
80        persons.append(query.record().value("name").toString());
81
82    return persons;
83}
84
85void Event::setRoom(const QString &room)
86{
87    Q_UNUSED(room);
88
89    qWarning("WARINING: setRoom() is NOT IMPLEMENTED YET");
90    // TODO: implement
91}
92
93void Event::setPersons(const QStringList &persons)
94{
95    Q_UNUSED(persons);
96
97    qWarning("WARINING: setPersons() is NOT IMPLEMENTED YET");
98    // TODO: implement
99}
100
101QList<Event> Event::getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy)
102{
103
104    QString strQuery = QString("SELECT %1 FROM EVENT INNER JOIN SEARCH_EVENT USING (xid_conference, id) ").arg(columnsForSelect());
105    strQuery += QString("WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY %1").arg(orderBy);
106    qDebug() << strQuery;
107    QSqlQuery query;
108    query.prepare( strQuery );
109    query.bindValue(":conf", conferenceId);
110    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
111    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
112
113    return load(query);
114}
115
Note: See TracBrowser for help on using the repository browser.