source: src/mvc/event.cpp @ b8a3ad1

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

implemented NOW tab

  • Property mode set to 100644
File size: 4.4 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::nowEvents(int conferenceId, QString orderBy)
43{
44    //uint curTime_t =  QDateTime(QDate::currentDate(),QTime::currentTime(),Qt::UTC).toTime_t();
45    uint curTime_t = 1265457610; // for testing
46
47    QSqlQuery query;
48    query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start <= :now1 AND ( start + duration ) > :now2 ORDER BY %1").arg(orderBy));
49    query.bindValue(":conf", conferenceId);
50    query.bindValue(":now1", convertToDb(curTime_t, QVariant::DateTime));
51    query.bindValue(":now2", convertToDb(curTime_t, QVariant::DateTime));
52
53    return load(query);
54}
55
56QList<Event> Event::getFavByDate(const QDate& date, int conferenceId)
57{
58    QSqlQuery query;
59    query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start >= :start AND start < :end AND favourite = 1 ORDER BY start"));
60    query.bindValue(":conf", conferenceId);
61    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
62    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
63
64    return load(query);
65}
66
67QString Event::room() const
68{
69    QSqlQuery query;
70    // TODO: conference ID isn't used here
71    query.prepare("SELECT name FROM room WHERE id = (SELECT xid_room FROM event_room WHERE xid_event = :id)");
72    query.bindValue(":id", id());
73    query.exec();
74    // TODO: handle qeury error
75    //qDebug() << query.lastError();
76    if(query.next())
77        return query.record().value("name").toString();
78    else
79        return QString("not-available");
80}
81
82QStringList Event::persons() const
83{
84    QSqlQuery query;
85    // TODO: conference ID isn't used here
86    query.prepare("SELECT person.name FROM person INNER JOIN event_person ON person.id = event_person.xid_person AND event_person.xid_event = :id");
87    query.bindValue(":id", id());
88    query.exec();
89    // TODO: handle qeury error
90    //qDebug() << query.lastError();
91
92    QStringList persons;
93    while(query.next())
94        persons.append(query.record().value("name").toString());
95
96    return persons;
97}
98
99void Event::setRoom(const QString &room)
100{
101    Q_UNUSED(room);
102
103    qWarning("WARINING: setRoom() is NOT IMPLEMENTED YET");
104    // TODO: implement
105}
106
107void Event::setPersons(const QStringList &persons)
108{
109    Q_UNUSED(persons);
110
111    qWarning("WARINING: setPersons() is NOT IMPLEMENTED YET");
112    // TODO: implement
113}
114
115QList<Event> Event::getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy)
116{
117
118    QString strQuery = QString("SELECT %1 FROM EVENT INNER JOIN SEARCH_EVENT USING (xid_conference, id) ").arg(columnsForSelect());
119    strQuery += QString("WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY %1").arg(orderBy);
120    qDebug() << strQuery;
121    QSqlQuery query;
122    query.prepare( strQuery );
123    query.bindValue(":conf", conferenceId);
124    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
125    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
126
127    return load(query);
128}
129
Note: See TracBrowser for help on using the repository browser.