- Timestamp:
- 02/03/10 15:08:05 (13 years ago)
- Branches:
- master, qt5
- Children:
- fe88470
- Parents:
- 78e3575
- Location:
- src/mvc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mvc/event.cpp
r78e3575 ra1755df 38 38 << QSqlField("description", QVariant::String)); 39 39 40 Event::Event() : 41 mRoomId( 0 ) 42 { 43 } 40 44 41 45 Event Event::getById(int id, int conferenceId) … … 116 120 } 117 121 118 QString Event::room() const 119 { 120 QSqlQuery query; 121 // TODO: conference ID isn't used here 122 query.prepare("SELECT name FROM room WHERE id = (SELECT xid_room FROM event_room WHERE xid_event = :id)"); 123 query.bindValue(":id", id()); 124 query.exec(); 125 // TODO: handle qeury error 126 //qDebug() << query.lastError(); 127 if(query.next()) 128 return query.record().value("name").toString(); 129 else 130 return QString("not-available"); 131 } 132 133 int Event::roomId() const 134 { 135 QSqlQuery query; 136 query.prepare("SELECT xid_room FROM event_room WHERE xid_event = :id"); 137 query.bindValue(":id", id()); 138 if (!query.isActive()) 139 if (!query.exec()) 140 throw OrmSqlException(query.lastError().text()); 141 if (!query.next()) 142 throw OrmNoObjectException(); 143 return query.record().value("xid_room").toInt(); 122 QString Event::room() 123 { 124 if ( mRoomName.isEmpty() ) 125 { 126 QSqlQuery query; 127 // TODO: conference ID isn't used here 128 query.prepare("SELECT name FROM room WHERE id = :roomId"); 129 query.bindValue(":roomId", roomId()); 130 query.exec(); 131 // TODO: handle qeury error 132 //qDebug() << query.lastError(); 133 if(query.next()) 134 mRoomName = query.record().value("name").toString(); 135 else 136 mRoomName = QString("not-available"); 137 } 138 return mRoomName; 139 } 140 141 int Event::roomId() 142 { 143 if ( mRoomId == 0 ) 144 { 145 QSqlQuery query; 146 query.prepare("SELECT xid_room FROM event_room WHERE xid_event = :id"); 147 query.bindValue(":id", id()); 148 if (!query.isActive()) 149 if (!query.exec()) 150 throw OrmSqlException(query.lastError().text()); 151 if (!query.next()) 152 { 153 qDebug() << "No room found for event id: " << id(); 154 throw OrmNoObjectException(); 155 } 156 mRoomId = query.record().value("xid_room").toInt(); 157 } 158 return mRoomId; 144 159 } 145 160 146 161 QStringList Event::persons() 147 162 { 148 if( personsList.isEmpty() )163 if( mPersonsList.isEmpty() ) 149 164 { 150 165 QSqlQuery query; … … 157 172 158 173 while(query.next()) 159 personsList.append(query.record().value("name").toString()); 160 } 161 162 return personsList; 163 } 164 165 QMap<QString,QString> Event::links() const 166 { 167 QSqlQuery query; 168 query.prepare("SELECT name,url FROM link WHERE xid_event = :id AND xid_conference = :conf"); 169 query.bindValue(":id", id()); 170 query.bindValue(":conf", conferenceId()); 171 query.exec(); 172 // TODO: handle qeury error 173 //qDebug() << query.lastError(); 174 175 QMap<QString,QString> links; 176 while(query.next()) 177 links.insert(query.record().value("name").toString(), query.record().value("url").toString()); 178 179 return links; 174 mPersonsList.append(query.record().value("name").toString()); 175 } 176 177 return mPersonsList; 178 } 179 180 QMap<QString,QString> Event::links() 181 { 182 if ( mLinksList.isEmpty() ) 183 { 184 QSqlQuery query; 185 query.prepare("SELECT name,url FROM link WHERE xid_event = :id AND xid_conference = :conf"); 186 query.bindValue(":id", id()); 187 query.bindValue(":conf", conferenceId()); 188 query.exec(); 189 // TODO: handle qeury error 190 //qDebug() << query.lastError(); 191 192 while(query.next()) 193 mLinksList.insert(query.record().value("name").toString(), query.record().value("url").toString()); 194 } 195 return mLinksList; 180 196 } 181 197 -
src/mvc/event.h
r78e3575 ra1755df 36 36 { 37 37 public: 38 Event(); 38 39 static const QSqlRecord sColumns; 39 40 static QString const sTableName; … … 64 65 QString description() const { return value("description").toString(); } 65 66 // records from other tables associated with 'id' 66 QString room() const;67 int roomId() const;67 QString room(); 68 int roomId(); 68 69 QStringList persons(); 69 QMap<QString,QString> links() const;70 QMap<QString,QString> links(); 70 71 71 72 void setId(int id) { setValue("id", id); } … … 91 92 92 93 private: 93 QStringList personsList; 94 QStringList mPersonsList; 95 QMap<QString,QString> mLinksList; 96 int mRoomId; 97 QString mRoomName; 94 98 }; 95 99
Note: See TracChangeset
for help on using the changeset viewer.