changeset 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 a17b7fdd03c0
children cd53828bb724
files config.quotedb.example quotedb.tcl
diffstat 2 files changed, 18 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/config.quotedb.example	Tue Feb 07 10:35:11 2017 +0200
+++ b/config.quotedb.example	Wed Apr 26 15:20:11 2017 +0300
@@ -59,8 +59,8 @@
 
 set qdb_msg_no_matches "Ei löydy!"
 
-set qdb_msg_you_voted "Äänestit %1 -> %2"
-set qdb_msg_vote_updated "Ääni päivitetty #%1 -> %2"
+set qdb_msg_you_voted "Äänestit #%1 -> %2, nyt yhteensä %3"
+set qdb_msg_vote_updated "Äänesi #%1 päivitetty -> %2, nyt yhteensä %3"
 
 set qdb_msg_sql_error "Virhe sörkittäessä tietokantaa. uliskaa."
 set qdb_msg_add_success "Tietokantaa %1 sörkitty (#%2), kiitos."
@@ -78,7 +78,7 @@
 set qdb_msg_not_found "%1 #%2 ei löydy, tai se ei kuulu käyttäjälle '%3'."
 
 
-set qdb_msg_help "%1 add <teksti>|update <id> <teksti>|del <id>|find <parametrit>|vote|top3"
+set qdb_msg_help "%1 add <teksti>|update <id> <teksti>|del <id>|find <parametrit>|vote \[<id> <1|-1>\]|top3"
 
 
 ###
--- a/quotedb.tcl	Tue Feb 07 10:35:11 2017 +0200
+++ b/quotedb.tcl	Wed Apr 26 15:20:11 2017 +0300
@@ -226,6 +226,15 @@
 
 
 #-------------------------------------------------------------------------
+proc qdb_get_rating_for_id {utable uid} {
+  set usql "SELECT total(${utable}_votes.vote) AS qrating FROM ${utable}_votes WHERE urlid=${uid}"
+  set qrating 0
+  qdb_handle eval $usql { set urating $qrating }
+  return $qrating
+}
+
+
+#-------------------------------------------------------------------------
 proc qdb_vote {ucmd utable unick uhand uchan utext upublic} {
   global qdb_handle qdb_msg_you_voted qdb_msg_quote_does_not_exist qdb_msg_vote_updated
 
@@ -259,8 +268,9 @@
     # Yes, update the previous vote
     set usql "UPDATE ${utable}_votes SET vote=$uvote WHERE id=$qid"
     if {[qdb_sql_exec $upublic $unick $uchan $usql]} {
-      qdb_log "$uhand changed vote to $uvote on #$uid / $utable"
-      qdb_msg $upublic $unick $uchan $qdb_msg_vote_updated [list $uid $uvote]
+      set urating [qdb_get_rating_for_id $utable $uid]
+      qdb_log "$uhand changed vote to $uvote on #$uid / $utable, total $urating"
+      qdb_msg $upublic $unick $uchan $qdb_msg_vote_updated [list $uid $uvote $urating]
       return 1
     } else {
       return 0
@@ -270,8 +280,9 @@
   # No previous votes, insert new
   set usql "INSERT INTO ${utable}_votes (user,urlid,vote) VALUES ('[utl_escape $uhand]',$uid,$uvote)"
   if {[qdb_sql_exec $upublic $unick $uchan $usql]} {
-    qdb_log "$uhand voted $uvote on #$uid / $utable"
-    qdb_msg $upublic $unick $uchan $qdb_msg_you_voted [list $uid $uvote]
+    set urating [qdb_get_rating_for_id $utable $uid]
+    qdb_log "$uhand voted $uvote on #$uid / $utable, total $urating"
+    qdb_msg $upublic $unick $uchan $qdb_msg_you_voted [list $uid $uvote $urating]
   }
 }