if (!scheduleElement.isNull())
{
- // TODO: assign conferenceID based on eg. title
- int conferenceID = 1; // HARD-WIRED for now to '1' - only one Conference
-
+ int confId = 0;
QDomElement conferenceElement = scheduleElement.firstChildElement("conference");
if (!conferenceElement.isNull())
{
QHash<QString,QString> conference;
- conference["id"] = QString::number(conferenceID,10);
+ conference["id"] = QString::number(0); // conference ID is assigned automatically, or obtained from the DB
conference["title"] = conferenceElement.firstChildElement("title").text();
conference["subtitle"] = conferenceElement.firstChildElement("subtitle").text();
conference["venue"] = conferenceElement.firstChildElement("venue").text();
conference["day_change"] = conferenceElement.firstChildElement("day_change").text(); // time
conference["timeslot_duration"] = conferenceElement.firstChildElement("timeslot_duration").text(); // time
aDBEngine->addConferenceToDB(conference);
+ confId = conference["id"].toInt();
}
// we need to get count of all events in order to emit 'progressStatus' signal
QHash<QString,QString> room;
room["name"] = roomElement.attribute("name");
room["event_id"] = eventElement.attribute("id");
- room["conference_id"] = QString::number(conferenceID,10);
+ room["conference_id"] = QString::number(confId,10);
room["picture"] = "NOT DEFINED YET"; // TODO: implement some mapping to assign correct picture to specified room_name
aDBEngine->addRoomToDB(room);
// process event's nodes
QHash<QString,QString> event;
event["id"] = eventElement.attribute("id");;
- event["conference_id"] = QString::number(conferenceID, 10);
+ event["conference_id"] = QString::number(confId, 10);
event["start"] = eventElement.firstChildElement("start").text(); // time eg. 10:00
event["date"] = dayElement.attribute("date"); // date eg. 2009-02-07
event["duration"] = eventElement.firstChildElement("duration").text(); // time eg. 00:30
person["id"] = personList.at(i).toElement().attribute("id");
person["name"] = personList.at(i).toElement().text();
person["event_id"] = eventElement.attribute("id");
- person["conference_id"] = QString::number(conferenceID, 10);
+ person["conference_id"] = QString::number(confId, 10);
//qDebug() << "adding Person: " << person["name"];
aDBEngine->addPersonToDB(person);
}
link["name"] = linkList.at(i).toElement().text();
link["url"] = linkList.at(i).toElement().attribute("href");
link["event_id"] = eventElement.attribute("id");
- link["conference_id"] = QString::number(conferenceID, 10);
+ link["conference_id"] = QString::number(confId, 10);
aDBEngine->addLinkToDB(link);
}
// emit signal to inform the user about the current status (how many events are parsed so far - expressed in %)
#include <QDateTime>
#include <QDir>
+#include <appsettings.h>
#include "sqlengine.h"
#include <track.h>
+#include <conference.h>
#include <QDebug>
if (db.isValid() && db.isOpen())
{
- QString values = QString("'%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8', '%9', '%10'") \
- .arg(aConference["id"]) \
- .arg(aConference["title"]) \
- .arg(aConference["subtitle"]) \
- .arg(aConference["venue"]) \
- .arg(aConference["city"]) \
- .arg(QDateTime(QDate::fromString(aConference["start"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t()) \
- .arg(QDateTime(QDate::fromString(aConference["end"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t()) \
- .arg(aConference["days"]) \
- .arg(-QTime::fromString(aConference["day_change"],TIME_FORMAT).secsTo(QTime(0,0))) \
- .arg(-QTime::fromString(aConference["timeslot_duration"],TIME_FORMAT).secsTo(QTime(0,0)));
-
- QString query = QString("INSERT INTO CONFERENCE (id,title,subtitle,venue,city,start,end,days,day_change,timeslot_duration) VALUES (%1)").arg(values);
- QSqlQuery result (query, db);
- //LOG_AUTOTEST(query);
+ int confId = 0;
+ QList<Conference> confsList = Conference::getAll();
+ if(confsList.count())
+ {
+ QListIterator<Conference> i(confsList);
+ while (i.hasNext())
+ {
+ Conference conf = i.next();
+ if( aConference["title"] == conf.title() )
+ {
+ confId = conf.id();
+ aConference["id"] = QString::number(confId);
+ break;
+ }
+ }
+ }
+
+ if(!confId) // conference 'aConference' isn't in the table => insert
+ {
+ QString values = QString("'%1', '%2', '%3', '%4', '%5', '%6', '%7', '%8', '%9'") \
+ .arg(aConference["title"]) \
+ .arg(aConference["subtitle"]) \
+ .arg(aConference["venue"]) \
+ .arg(aConference["city"]) \
+ .arg(QDateTime(QDate::fromString(aConference["start"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t()) \
+ .arg(QDateTime(QDate::fromString(aConference["end"],DATE_FORMAT),QTime(0,0),Qt::UTC).toTime_t()) \
+ .arg(aConference["days"]) \
+ .arg(-QTime::fromString(aConference["day_change"],TIME_FORMAT).secsTo(QTime(0,0))) \
+ .arg(-QTime::fromString(aConference["timeslot_duration"],TIME_FORMAT).secsTo(QTime(0,0)));
+
+ QString query = QString("INSERT INTO CONFERENCE (title,subtitle,venue,city,start,end,days,day_change,timeslot_duration) VALUES (%1)").arg(values);
+ QSqlQuery result (query, db);
+ aConference["id"] = result.lastInsertId().toString(); // 'id' is assigned automatically
+
+ if(!AppSettings::confId()) // default conf Id isn't set yet => set it up
+ AppSettings::setConfId(confId);
+ }
}
}