source: src/mvc/event.cpp @ 6f39595

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

started work on 'favourities'

  • created tavourities tree view in the MainWindow? 'Favourities' tab
  • listed some testing 'fav' events
  • TODO: list isn't updated dynamically, which means that the list isn't updated if the user adds/removes an event(s) to/from the 'favourities' list
  • Property mode set to 100644
File size: 2.4 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(selectQueryJoin2T("id") + "WHERE event.id = :id AND event.xid_conference = :conf");
33    query.bindValue(":id", id);
34    query.bindValue(":conf", conferenceId);
35
36    return loadOne(query);
37}
38
39QList<Event> Event::getByDate(const QDate& date, int conferenceId)
40{
41    QSqlQuery query;
42    query.prepare(selectQueryJoin2T("id") + "WHERE event.xid_conference = :conf AND event.start >= :start AND event.start < :end ORDER BY event.start");
43    query.bindValue(":conf", conferenceId);
44    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
45    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
46
47    return load(query);
48}
49
50QList<Event> Event::getFavByDate(const QDate& date, int conferenceId)
51{
52    QSqlQuery query;
53    query.prepare(selectQueryJoin2T("id") + "WHERE event.xid_conference = :conf AND event.start >= :start AND event.start < :end AND event.favourite = 1 ORDER BY event.start");
54    query.bindValue(":conf", conferenceId);
55    query.bindValue(":start", convertToDb(date, QVariant::DateTime));
56    query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
57
58    return load(query);
59}
60
Note: See TracBrowser for help on using the repository browser.