source: src/mvc/event.cpp @ ffd878f

qt5
Last change on this file since ffd878f was 27102d5, checked in by fortefr <fortefr@…>, 13 years ago

Temporal virtual_event change

  • Property mode set to 100644
File size: 2.5 KB
Line 
1#include "event.h"
2
3// 'event' record is splitted into two separate tables 'event' and 'virtual_event'
4// for the FTS (Full-Text-Search) support and so, it is necessary to provide/use
5// two table names + corresponding parameters/methods, see bellow
6QString const Event::sTable1Name = QString("event");
7QString const Event::sTable2Name = QString("virtual_event");
8int const Event::sTable1ColCount = 8; // see 'toRecord()' for more details
9int const Event::sTable2ColCount = 5; // see 'toRecord()' for more details
10
11QSqlRecord const Event::sColumns = Event::toRecord(QList<QSqlField>()
12    /* 'columns from Table 1 */
13    << QSqlField("id", QVariant::Int)
14    << QSqlField("xid_conference", QVariant::Int)
15    << QSqlField("start", QVariant::DateTime)
16    << QSqlField("duration", QVariant::Int)
17    << QSqlField("xid_activity", QVariant::Int)
18    << QSqlField("type", QVariant::String)
19    << QSqlField("language", QVariant::String)
20    << QSqlField("favourite", QVariant::Bool)
21    /* 'columns' from Table2 */
22    << QSqlField("tag", QVariant::String)
23    << QSqlField("title", QVariant::String)
24    << QSqlField("subtitle", QVariant::String)
25    << QSqlField("abstract", QVariant::String)
26    << QSqlField("description", QVariant::String));
27
28
29Event Event::getById(int id, int conferenceId)
30{
31    QSqlQuery query;
32    query.prepare(
33            selectQueryJoin2T("id")
34            + QString("WHERE %1.id = :id AND %1.xid_conference = :conf").arg(sTable1Name));
35    query.bindValue(":id", id);
36    query.bindValue(":conf", conferenceId);
37
38    return loadOne(query);
39}
40
41QList<Event> Event::getByDate(const QDate& date, int conferenceId)
42{
43    QSqlQuery query;
44    query.prepare(
45            selectQueryJoin2T("id")
46            + QString("WHERE %1.xid_conference = :conf AND %1.start >= :start AND %1.start < :end ORDER BY %1.start").arg(sTable1Name));
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
54QList<Event> Event::getFavByDate(const QDate& date, int conferenceId)
55{
56    QSqlQuery query;
57    query.prepare(
58            selectQueryJoin2T("id")
59            + QString("WHERE %1.xid_conference = :conf AND %1.start >= :start AND %1.start < :end AND %1.favourite = 1 ORDER BY %1.start").arg(sTable1Name));
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
Note: See TracBrowser for help on using the repository browser.