1 | #include "conference.h" |
---|
2 | |
---|
3 | QSqlRecord const Conference::sColumns = Conference::toRecord(QList<QSqlField>() |
---|
4 | << QSqlField("id", QVariant::Int) |
---|
5 | << QSqlField("title", QVariant::String) |
---|
6 | << QSqlField("subtitle", QVariant::String) |
---|
7 | << QSqlField("venue", QVariant::String) |
---|
8 | << QSqlField("city", QVariant::String) |
---|
9 | << QSqlField("start", QVariant::DateTime) |
---|
10 | << QSqlField("end", QVariant::DateTime) |
---|
11 | << QSqlField("days", QVariant::Int) |
---|
12 | << QSqlField("day_change", QVariant::Int) |
---|
13 | << QSqlField("timeslot_duration", QVariant::Int) |
---|
14 | << QSqlField("active", QVariant::Bool)); |
---|
15 | |
---|
16 | QString const Conference::sTableName = QString("conference"); |
---|
17 | |
---|
18 | Conference Conference::getById(int id) |
---|
19 | { |
---|
20 | QSqlQuery query; |
---|
21 | query.prepare(selectQuery() + "WHERE id = :id"); |
---|
22 | query.bindValue(":id", id); |
---|
23 | return loadOne(query); |
---|
24 | } |
---|
25 | |
---|
26 | QList<Conference> Conference::getAll() |
---|
27 | { |
---|
28 | QSqlQuery query; |
---|
29 | query.prepare(selectQuery()); |
---|
30 | return load(query); |
---|
31 | } |
---|
32 | |
---|
33 | int Conference::activeConference() |
---|
34 | { |
---|
35 | QSqlQuery query("SELECT id FROM conference WHERE active = 1"); |
---|
36 | query.exec(); |
---|
37 | |
---|
38 | QList<int> activeConfs; |
---|
39 | while(query.next()) |
---|
40 | activeConfs.append(query.record().value("id").toInt()); |
---|
41 | |
---|
42 | if(activeConfs.count()==0) // no active DB |
---|
43 | return 1; |
---|
44 | else // even if there are more active confs, the first from the list is confidered active |
---|
45 | return activeConfs[0]; |
---|
46 | } |
---|
47 | |
---|