1 | #include "event.h" |
---|
2 | |
---|
3 | QString const Event::sTableName = QString("event"); |
---|
4 | |
---|
5 | QSqlRecord 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 | |
---|
22 | Event 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 | |
---|
31 | QList<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 | |
---|
42 | QList<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 | |
---|
56 | QList<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 | |
---|
67 | QList<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 | |
---|
76 | QString Event::room() const |
---|
77 | { |
---|
78 | QSqlQuery query; |
---|
79 | // TODO: conference ID isn't used here |
---|
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()) |
---|
86 | return query.record().value("name").toString(); |
---|
87 | else |
---|
88 | return QString("not-available"); |
---|
89 | } |
---|
90 | |
---|
91 | QStringList 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 | |
---|
108 | void Event::setRoom(const QString &room) |
---|
109 | { |
---|
110 | Q_UNUSED(room); |
---|
111 | |
---|
112 | qWarning("WARINING: setRoom() is NOT IMPLEMENTED YET"); |
---|
113 | // TODO: implement |
---|
114 | } |
---|
115 | |
---|
116 | void Event::setPersons(const QStringList &persons) |
---|
117 | { |
---|
118 | Q_UNUSED(persons); |
---|
119 | |
---|
120 | qWarning("WARINING: setPersons() is NOT IMPLEMENTED YET"); |
---|
121 | // TODO: implement |
---|
122 | } |
---|
123 | |
---|
124 | QList<Event> Event::getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy) |
---|
125 | { |
---|
126 | |
---|
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); |
---|
129 | qDebug() << strQuery; |
---|
130 | QList<Event> list; |
---|
131 | QSqlQuery query; |
---|
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; |
---|
152 | } |
---|
153 | |
---|