summaryrefslogtreecommitdiff
path: root/src/SemanticScuttle/Service/Vote.php
diff options
context:
space:
mode:
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2009-11-02 09:35:38 +0000
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2009-11-02 09:35:38 +0000
commitd05aebe54e02ab4a8362088ca09caaff265fa670 (patch)
tree03f1a01fcc7470f59b52f335708ba0fd8e10d114 /src/SemanticScuttle/Service/Vote.php
parentb569921136030a5030731abe2c9e4b8d0712a249 (diff)
downloadsemanticscuttle-d05aebe54e02ab4a8362088ca09caaff265fa670.tar.gz
semanticscuttle-d05aebe54e02ab4a8362088ca09caaff265fa670.tar.bz2
allow changing of votes
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@493 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'src/SemanticScuttle/Service/Vote.php')
-rw-r--r--src/SemanticScuttle/Service/Vote.php41
1 files changed, 38 insertions, 3 deletions
diff --git a/src/SemanticScuttle/Service/Vote.php b/src/SemanticScuttle/Service/Vote.php
index 89088f0..c0c4995 100644
--- a/src/SemanticScuttle/Service/Vote.php
+++ b/src/SemanticScuttle/Service/Vote.php
@@ -225,12 +225,12 @@ class SemanticScuttle_Service_Vote extends SemanticScuttle_DbService
return false;
}
- if ($this->hasVoted($bookmark, $user)) {
+ if ($vote != -1 && $vote != 1) {
return false;
}
- if ($vote != -1 && $vote != 1) {
- return false;
+ if ($this->hasVoted($bookmark, $user)) {
+ $this->removeVote($bookmark, $user);
}
$res = $this->db->sql_query(
@@ -258,6 +258,41 @@ class SemanticScuttle_Service_Vote extends SemanticScuttle_DbService
/**
+ * Removes a vote from the database
+ *
+ * @param integer $bookmark Bookmark ID
+ * @param integer $user User ID
+ *
+ * @return boolean True if all went well, false if not
+ */
+ protected function removeVote($bookmark, $user)
+ {
+ $vote = $this->getVote($bookmark, $user);
+ if ($vote === null) {
+ return false;
+ }
+
+ //remove from votes table
+ $query = 'DELETE FROM ' . $this->getTableName()
+ . ' WHERE bId = ' . (int)$bookmark
+ . ' AND uId = ' . (int)$user;
+ $this->db->sql_query($query);
+
+ //change voting sum in bookmarks table
+ $bm = SemanticScuttle_Service_Factory::get('Bookmark');
+ $res = $this->db->sql_query(
+ $sql='UPDATE ' . $bm->getTableName()
+ . ' SET bVoting = bVoting - ' . (int)$vote
+ . ' WHERE bId = ' . (int)$bookmark
+ );
+ $this->db->sql_freeresult($res);
+
+ return true;
+ }
+
+
+
+ /**
* Re-calculates all votings for all bookmarks
* and updates the voting values in the bookmarks
* table.