source: src/mvc/event.cpp @ 0d4ecc2

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

search update

  • Property mode set to 100644
File size: 5.0 KB
RevLine 
[e5bc908]1#include "event.h"
2
[7d7659d]3QString const Event::sTableName = QString("event");
[c790268]4
[20a6010]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)
[4693fa6]10    << QSqlField("xid_track", QVariant::Int)
[20a6010]11    << QSqlField("type", QVariant::String)
[680a4da]12    << QSqlField("language", QVariant::String)
[c790268]13    << QSqlField("favourite", QVariant::Bool)
[b6cd05c]14    << QSqlField("alarm", QVariant::Bool)
[c790268]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));
[5a73d27]20
[20a6010]21
22Event Event::getById(int id, int conferenceId)
23{
[d0d0a66]24    QSqlQuery query;
[7d7659d]25    query.prepare(selectQuery() + "WHERE id = :id AND xid_conference = :conf");
[d0d0a66]26    query.bindValue(":id", id);
27    query.bindValue(":conf", conferenceId);
28    return loadOne(query);
29}
30
[64122f1]31QList<Event> Event::getByDate(const QDate& date, int conferenceId, QString orderBy)
[d0d0a66]32{
33    QSqlQuery query;
[7d7659d]34    query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY %1").arg(orderBy));
[d0d0a66]35    query.bindValue(":conf", conferenceId);
36    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
37    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
[20a6010]38
[d0d0a66]39    return load(query);
[20a6010]40}
[680a4da]41
[b8a3ad1]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
[6f39595]56QList<Event> Event::getFavByDate(const QDate& date, int conferenceId)
57{
58    QSqlQuery query;
[7d7659d]59    query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start >= :start AND start < :end AND favourite = 1 ORDER BY start"));
[6f39595]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
[005e2b7]67QList<Event> Event::getByTrack(int trackId)
68{
69    QSqlQuery query;
70    query.prepare(selectQuery() + QString("WHERE xid_track = :trackId ORDER BY start"));
71    query.bindValue(":trackId", trackId);
72
73    return load(query);
74}
75
[f9db452]76QString Event::room() const
77{
78    QSqlQuery query;
[395d6d3]79    // TODO: conference ID isn't used here
[f9db452]80    query.prepare("SELECT name FROM room WHERE id = (SELECT xid_room FROM event_room WHERE xid_event = :id)");
81    query.bindValue(":id", id());
82    query.exec();
83    // TODO: handle qeury error
84    //qDebug() << query.lastError();
85    if(query.next())
[9afc0ee]86        return query.record().value("name").toString();
[f9db452]87    else
88        return QString("not-available");
89}
90
[395d6d3]91QStringList Event::persons() const
92{
93    QSqlQuery query;
94    // TODO: conference ID isn't used here
95    query.prepare("SELECT person.name FROM person INNER JOIN event_person ON person.id = event_person.xid_person AND event_person.xid_event = :id");
96    query.bindValue(":id", id());
97    query.exec();
98    // TODO: handle qeury error
99    //qDebug() << query.lastError();
100
101    QStringList persons;
102    while(query.next())
103        persons.append(query.record().value("name").toString());
104
105    return persons;
106}
107
[f9db452]108void Event::setRoom(const QString &room)
109{
[395d6d3]110    Q_UNUSED(room);
111
[f9db452]112    qWarning("WARINING: setRoom() is NOT IMPLEMENTED YET");
113    // TODO: implement
114}
[27102d5]115
[395d6d3]116void Event::setPersons(const QStringList &persons)
117{
118    Q_UNUSED(persons);
119
120    qWarning("WARINING: setPersons() is NOT IMPLEMENTED YET");
121    // TODO: implement
122}
123
[e662750]124QList<Event> Event::getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy)
125{
126
[7d7659d]127    QString strQuery = QString("SELECT %1 FROM EVENT INNER JOIN SEARCH_EVENT USING (xid_conference, id) ").arg(columnsForSelect());
128    strQuery += QString("WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY %1").arg(orderBy);
[e662750]129    qDebug() << strQuery;
[0d4ecc2]130    QList<Event> list;
[e662750]131    QSqlQuery query;
[0d4ecc2]132    try{
133        if( !query.prepare( strQuery ) ){
134            qDebug() << "QSqlQuery.prepare error";
135            throw OrmSqlException( query.lastError().text() );
136        }
137
138        query.bindValue(":conf", conferenceId);
139        query.bindValue(":start", convertToDb(date, QVariant::DateTime));
140        query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
141
142        list = load(query);
143    }
144    catch(OrmException &e)
145    {
146        qDebug() << "getSearchResultByDate error: " << e.text();
147    }
148    catch(...){
149        qDebug() << "getSearchResultByDate failed ...";
150    }
151    return list;
[e662750]152}
153
Note: See TracBrowser for help on using the repository browser.