Mercurial > hg > egg-tcls
comparison quotedb.tcl @ 439:ac66900fd066
quotedb: Add display of current quote rating when voting for it.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 26 Apr 2017 15:20:11 +0300 |
parents | 86f39989df4b |
children | 6acd372d36da |
comparison
equal
deleted
inserted
replaced
438:a17b7fdd03c0 | 439:ac66900fd066 |
---|---|
224 return 0 | 224 return 0 |
225 } | 225 } |
226 | 226 |
227 | 227 |
228 #------------------------------------------------------------------------- | 228 #------------------------------------------------------------------------- |
229 proc qdb_get_rating_for_id {utable uid} { | |
230 set usql "SELECT total(${utable}_votes.vote) AS qrating FROM ${utable}_votes WHERE urlid=${uid}" | |
231 set qrating 0 | |
232 qdb_handle eval $usql { set urating $qrating } | |
233 return $qrating | |
234 } | |
235 | |
236 | |
237 #------------------------------------------------------------------------- | |
229 proc qdb_vote {ucmd utable unick uhand uchan utext upublic} { | 238 proc qdb_vote {ucmd utable unick uhand uchan utext upublic} { |
230 global qdb_handle qdb_msg_you_voted qdb_msg_quote_does_not_exist qdb_msg_vote_updated | 239 global qdb_handle qdb_msg_you_voted qdb_msg_quote_does_not_exist qdb_msg_vote_updated |
231 | 240 |
232 if {![qdb_valid_user $upublic $unick $uchan $uhand]} { | 241 if {![qdb_valid_user $upublic $unick $uchan $uhand]} { |
233 return 0 | 242 return 0 |
257 set usql "SELECT id AS qid FROM ${utable}_votes WHERE user='[utl_escape $uhand]' AND urlid=$uid" | 266 set usql "SELECT id AS qid FROM ${utable}_votes WHERE user='[utl_escape $uhand]' AND urlid=$uid" |
258 qdb_handle eval $usql { | 267 qdb_handle eval $usql { |
259 # Yes, update the previous vote | 268 # Yes, update the previous vote |
260 set usql "UPDATE ${utable}_votes SET vote=$uvote WHERE id=$qid" | 269 set usql "UPDATE ${utable}_votes SET vote=$uvote WHERE id=$qid" |
261 if {[qdb_sql_exec $upublic $unick $uchan $usql]} { | 270 if {[qdb_sql_exec $upublic $unick $uchan $usql]} { |
262 qdb_log "$uhand changed vote to $uvote on #$uid / $utable" | 271 set urating [qdb_get_rating_for_id $utable $uid] |
263 qdb_msg $upublic $unick $uchan $qdb_msg_vote_updated [list $uid $uvote] | 272 qdb_log "$uhand changed vote to $uvote on #$uid / $utable, total $urating" |
273 qdb_msg $upublic $unick $uchan $qdb_msg_vote_updated [list $uid $uvote $urating] | |
264 return 1 | 274 return 1 |
265 } else { | 275 } else { |
266 return 0 | 276 return 0 |
267 } | 277 } |
268 } | 278 } |
269 | 279 |
270 # No previous votes, insert new | 280 # No previous votes, insert new |
271 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[utl_escape $uhand]',$uid,$uvote)" | 281 set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[utl_escape $uhand]',$uid,$uvote)" |
272 if {[qdb_sql_exec $upublic $unick $uchan $usql]} { | 282 if {[qdb_sql_exec $upublic $unick $uchan $usql]} { |
273 qdb_log "$uhand voted $uvote on #$uid / $utable" | 283 set urating [qdb_get_rating_for_id $utable $uid] |
274 qdb_msg $upublic $unick $uchan $qdb_msg_you_voted [list $uid $uvote] | 284 qdb_log "$uhand voted $uvote on #$uid / $utable, total $urating" |
285 qdb_msg $upublic $unick $uchan $qdb_msg_you_voted [list $uid $uvote $urating] | |
275 } | 286 } |
276 } | 287 } |
277 | 288 |
278 | 289 |
279 #------------------------------------------------------------------------- | 290 #------------------------------------------------------------------------- |