Changeset 9f367eb for src/mvc/event.cpp
- Timestamp:
- 01/27/10 07:41:47 (13 years ago)
- Branches:
- master, qt5
- Children:
- 001c8cf
- Parents:
- 336fa33
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mvc/event.cpp
r336fa33 r9f367eb 125 125 } 126 126 127 QList<int> Event::conflicts() const 128 { 129 QSqlQuery query; 130 // TODO: conference ID isn't used here 131 query.prepare("SELECT conflict_event FROM event_conflict WHERE xid_event = :id AND xid_conference = :conf"); 132 query.bindValue(":id", id()); 133 query.bindValue(":conf", conferenceId()); 134 query.exec(); 135 // TODO: handle qeury error 136 //qDebug() << query.lastError(); 137 138 QList<int> conflicts; 139 while(query.next()) 140 conflicts.append(query.record().value("conflict_event").toInt()); 141 142 return conflicts; 143 } 144 145 bool Event::hasTimeConflict() const 146 { 147 return conflicts().count() > 0 ? true : false; 148 } 149 150 void Event::updateConflicts() 151 { 152 qDebug() << "updating conflicts"; 153 QSqlQuery query; 154 query.prepare("SELECT id FROM event WHERE xid_conference = :conf AND ( \ 155 ( start <= :start1 AND ( start + duration ) >= :start2 ) \ 156 OR ( start >= :start3 AND ( start + duration ) <= :end1 ) \ 157 OR ( start <= :end2 AND ( start + duration ) >= :end3 ) ) AND favourite = 1 ORDER BY start"); 158 query.bindValue(":conf", conferenceId()); 159 query.bindValue(":start1", convertToDb(start(), QVariant::DateTime)); 160 query.bindValue(":start2", convertToDb(start(), QVariant::DateTime)); 161 query.bindValue(":start3", convertToDb(start(), QVariant::DateTime)); 162 query.bindValue(":end1", convertToDb(start().toTime_t()+duration(), QVariant::DateTime)); 163 query.bindValue(":end2", convertToDb(start().toTime_t()+duration(), QVariant::DateTime)); 164 query.bindValue(":end3", convertToDb(start().toTime_t()+duration(), QVariant::DateTime)); 165 query.exec(); 166 167 QList<int> conflicts; 168 while(query.next()) 169 { 170 int idx = query.record().value("id").toInt(); 171 if(idx != id()) 172 conflicts.append(idx); 173 } 174 175 if(isFavourite()) // event became favourite 176 { 177 for(int i=0; i<conflicts.count(); i++) 178 { 179 QSqlQuery query; 180 query.prepare("INSERT INTO event_conflict (xid_conference, xid_event, conflict_event) VALUES ( ? , ? , ? )"); 181 query.bindValue(0, conferenceId()); 182 query.bindValue(1, id()); 183 query.bindValue(2, conflicts[i]); 184 query.exec(); 185 186 QSqlQuery query2; 187 query2.prepare("INSERT INTO event_conflict (xid_conference, xid_event, conflict_event) VALUES ( ? , ? , ? )"); 188 query2.bindValue(0, conferenceId()); 189 query2.bindValue(1, conflicts[i]); 190 query2.bindValue(2, id()); 191 query2.exec(); 192 } 193 } 194 else // event removed from favourities 195 { 196 qDebug() << "removing"; 197 198 QSqlQuery queryRemove; 199 queryRemove.prepare("DELETE FROM event_conflict WHERE xid_event = :id AND xid_conference = :conf"); 200 queryRemove.bindValue(":id",id()); 201 queryRemove.bindValue(":conf",conferenceId()); 202 queryRemove.exec(); 203 204 for(int i=0; i<conflicts.count(); i++) 205 { 206 qDebug() << "removing: " << id() << " -> " << conflicts[i]; 207 208 QSqlQuery queryRemove; 209 queryRemove.prepare("DELETE FROM event_conflict WHERE xid_event = :id1 AND xid_conference = :conf AND conflict_event = :id2"); 210 queryRemove.bindValue(":id1",conflicts[i]); 211 queryRemove.bindValue(":conf",conferenceId()); 212 queryRemove.bindValue(":id2",id()); 213 queryRemove.exec(); 214 } 215 } 216 } 217 127 218 void Event::setRoom(const QString &room) 128 219 {
Note: See TracChangeset
for help on using the changeset viewer.