/*
* Copyright (C) 2010 Ixonos Plc.
+ * Copyright (C) 2011 Philipp Spitzer, gregor herrmann
*
- * This file is part of fosdem-schedule.
+ * This file is part of ConfClerk.
*
- * fosdem-schedule is free software: you can redistribute it and/or modify it
+ * ConfClerk is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 2 of the License, or (at your option)
* any later version.
*
- * fosdem-schedule is distributed in the hope that it will be useful, but
+ * ConfClerk is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
- * fosdem-schedule. If not, see <http://www.gnu.org/licenses/>.
+ * ConfClerk. If not, see <http://www.gnu.org/licenses/>.
*/
#include "event.h"
#include "room.h"
<< QSqlField("description", QVariant::String));
Event::Event() :
- mRoomId( 0 )
+ room_(NULL)
{
}
return load(query);
}
-QList<Event> Event::nowEvents(int conferenceId, QString orderBy)
-{
- uint curTime_t = QDateTime(QDate::currentDate(),QTime::currentTime(),Qt::UTC).toTime_t();
- //uint curTime_t = 1265457610; // for testing
-
- QSqlQuery query;
- query.prepare(selectQuery() + QString("WHERE xid_conference = :conf AND start <= :now1 AND ( start + duration ) > :now2 ORDER BY %1").arg(orderBy));
- query.bindValue(":conf", conferenceId);
- query.bindValue(":now1", convertToDb(curTime_t, QVariant::DateTime));
- query.bindValue(":now2", convertToDb(curTime_t, QVariant::DateTime));
-
- return load(query);
-}
-QList<Event> Event::conflictEvents(int aEventId, int conferenceId)
-{
+QList<Event> Event::conflictEvents(int aEventId, int conferenceId) {
QSqlQuery query;
Event event = Event::getById(aEventId,conferenceId);
query.prepare(selectQuery() + "WHERE xid_conference = :conf AND ( \
return load(query);
}
+
QList<Event> Event::getFavByDate(const QDate& date, int conferenceId)
{
QSqlQuery query;
return load(query);
}
-QString Event::room()
-{
- if ( mRoomName.isEmpty() )
- {
- QSqlQuery query;
- // TODO: conference ID isn't used here
- query.prepare("SELECT name FROM room WHERE id = :roomId");
- query.bindValue(":roomId", roomId());
- query.exec();
- // TODO: handle qeury error
- //qDebug() << query.lastError();
- if(query.next())
- mRoomName = query.record().value("name").toString();
- else
- mRoomName = QString("not-available");
- }
- return mRoomName;
-}
-
-int Event::roomId()
+Room* Event::room()
{
- if ( mRoomId == 0 )
+ if (room_ == NULL)
{
QSqlQuery query;
query.prepare("SELECT xid_room FROM event_room WHERE xid_event = :id AND xid_conference = :conf");
qDebug() << "No room found for event id: " << id();
throw OrmNoObjectException();
}
- mRoomId = query.record().value("xid_room").toInt();
+ int id = query.record().value("xid_room").toInt();
+ room_ = new Room(Room::retrieve(id));
}
- return mRoomId;
+ return room_;
+}
+
+QString Event::roomName()
+{
+ return room()->name();
+}
+
+int Event::roomId()
+{
+ return room()->id();
}
QStringList Event::persons()
if( mPersonsList.isEmpty() )
{
QSqlQuery query;
- // TODO: conference ID isn't used here
- 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 = :conf");
+ 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(":conf", conferenceId());
- query.exec();
- // TODO: handle qeury error
- //qDebug() << query.lastError();
+ query.bindValue(":conf1", conferenceId());
+ query.bindValue(":conf2", conferenceId());
+ if (!query.exec()) qDebug() << query.lastError();
while(query.next())
mPersonsList.append(query.record().value("name").toString());
// TODO: implement
}
-QList<Event> Event::getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy)
-{
+QList<Event> Event::getSearchResultByDate(const QDate& date, int conferenceId, QString orderBy) {
+ QList<Event> list;
+
+ // Check whether the temporary table SEARCH_EVENT exists (http://www.sqlite.org/faq.html#q7)
+ QSqlQuery query("SELECT count(*) FROM sqlite_temp_master WHERE type='table' and name='SEARCH_EVENT'");
+ if (!query.exec()) {
+ qDebug() << "SQL Error: " << query.lastError().text();
+ return list;
+ }
+ query.first();
+ QVariant v = query.value(0);
+ if (v.toInt() != 1) return list;
+
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);
- //qDebug() << strQuery;
- QList<Event> list;
- QSqlQuery query;
- try{
+ query = QSqlQuery();
+ try {
if( !query.prepare( strQuery ) ){
qDebug() << "QSqlQuery.prepare error";
throw OrmSqlException( query.lastError().text() );