+Room* Event::room()
+{
+ if (room_ == NULL)
+ {
+ QSqlQuery query;
+ query.prepare("SELECT xid_room FROM event_room WHERE xid_event = :id AND xid_conference = :conf");
+ query.bindValue(":id", id());
+ query.bindValue(":conf", conferenceId());
+ if (!query.isActive())
+ if (!query.exec())
+ throw OrmSqlException(query.lastError().text());
+ if (!query.next())
+ {
+ qDebug() << "No room found for event id: " << id();
+ throw OrmNoObjectException();
+ }
+ int id = query.record().value("xid_room").toInt();
+ room_ = new Room(Room::retrieve(id));
+ }
+ return room_;
+}
+
+QString Event::roomName()
+{
+ return room()->name();
+}
+
+int Event::roomId()
+{
+ return room()->id();
+}
+
+QStringList Event::persons()
+{
+ if( mPersonsList.isEmpty() )
+ {
+ QSqlQuery query;
+ query.prepare("SELECT person.name FROM person INNER JOIN event_person ON person.id = event_person.xid_person AND event_person.xid_event = :id AND event_person.xid_conference = :conf1 AND person.xid_conference = :conf2");
+ query.bindValue(":id", id());
+ query.bindValue(":conf1", conferenceId());
+ query.bindValue(":conf2", conferenceId());
+ if (!query.exec()) qDebug() << query.lastError();
+
+ while(query.next())
+ mPersonsList.append(query.record().value("name").toString());
+ }
+
+ return mPersonsList;
+}
+
+QMap<QString,QString> Event::links()
+{
+ if ( mLinksList.isEmpty() )
+ {
+ QSqlQuery query;
+ query.prepare("SELECT name,url FROM link WHERE xid_event = :id AND xid_conference = :conf");
+ query.bindValue(":id", id());
+ query.bindValue(":conf", conferenceId());
+ query.exec();
+ // TODO: handle qeury error
+ //qDebug() << query.lastError();
+
+ while(query.next())
+ mLinksList.insert(query.record().value("name").toString(), query.record().value("url").toString());
+ }
+ return mLinksList;
+}
+
+bool Event::hasTimeConflict() const
+{
+ if(!isFavourite()) // if it's not favourite, it can't have time-conflict
+ return false;
+
+ return conflictEvents(id(),conferenceId()).count() > 0 ? true : false;
+}
+
+void Event::setRoom(const QString &room)
+{
+ Q_UNUSED(room);
+
+ qWarning("WARINING: setRoom() is NOT IMPLEMENTED YET");
+ // TODO: implement
+}
+
+void Event::setPersons(const QStringList &persons)
+{
+ Q_UNUSED(persons);
+
+ qWarning("WARINING: setPersons() is NOT IMPLEMENTED YET");
+ // TODO: implement
+}
+
+void Event::setLinks(const QMap<QString,QString> &aLinks)
+{
+ Q_UNUSED(aLinks);
+
+ qWarning("WARINING: setLinks() is NOT IMPLEMENTED YET");
+ // TODO: implement
+}
+
+QList<Event> Event::getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy)
+{
+ QString strQuery = QString("SELECT %1 FROM EVENT INNER JOIN SEARCH_EVENT USING (xid_conference, id) ").arg(columnsForSelect());
+ strQuery += QString("WHERE xid_conference = :conf AND start >= :start AND start < :end ORDER BY %1").arg(orderBy);
+
+ QList<Event> list;
+ QSqlQuery query;
+ try{
+ if( !query.prepare( strQuery ) ){
+ qDebug() << "QSqlQuery.prepare error";
+ throw OrmSqlException( query.lastError().text() );
+ }
+
+ query.bindValue(":conf", conferenceId);
+ query.bindValue(":start", convertToDb(date, QVariant::DateTime));
+ query.bindValue(":end", convertToDb(date.addDays(1), QVariant::DateTime));
+
+ list = load(query);
+ }
+ catch(OrmException &e)
+ {
+ qDebug() << "getSearchResultByDate error: " << e.text();
+ }
+ catch(...){
+ qDebug() << "getSearchResultByDate failed ...";
+ }
+ return list;
+}