diff options
author | cweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f> | 2009-11-03 09:14:30 +0000 |
---|---|---|
committer | cweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f> | 2009-11-03 09:14:30 +0000 |
commit | b80df612d5453a44fff473ad9fe8be86a17c6516 (patch) | |
tree | 1120300ce9c72f168c1a32cd037b71378a939e36 /src/SemanticScuttle/Service/Vote.php | |
parent | 02051fcf67d47ac44d9dee457ff4a2098ffae963 (diff) | |
download | semanticscuttle-b80df612d5453a44fff473ad9fe8be86a17c6516.tar.gz semanticscuttle-b80df612d5453a44fff473ad9fe8be86a17c6516.tar.bz2 |
add new "votes" field in bookmarks database with the total sum of votes
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@509 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'src/SemanticScuttle/Service/Vote.php')
-rw-r--r-- | src/SemanticScuttle/Service/Vote.php | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/SemanticScuttle/Service/Vote.php b/src/SemanticScuttle/Service/Vote.php index c0c4995..53bebdc 100644 --- a/src/SemanticScuttle/Service/Vote.php +++ b/src/SemanticScuttle/Service/Vote.php @@ -21,10 +21,10 @@ * * @internal * Votes are saved in a separate "votes" table. - * Additionally to that, the voting of a bookmark is also - * stored in the bookmarks table. This is done to make - * sure lookups are really fast, since every bookmarks - * in a list shows its voting. + * Additionally to that, the voting and number of votes + * of a bookmark is also stored in the bookmarks table. + * This is done to make sure lookups are really fast, since + * every bookmark in a list shows its voting. * * @category Bookmarking * @package SemanticScuttle @@ -104,6 +104,12 @@ class SemanticScuttle_Service_Vote extends SemanticScuttle_DbService * Returns the number of users that voted for or * against the given bookmark. * + * @internal + * This method uses the votes table to calculate the + * number of votes for a bookmark. In normal life, it + * is more efficient to use the "bVotes" field in the + * bookmarks table. + * * @param integer $bookmark Bookmark ID * * @return integer Number of votes @@ -248,6 +254,7 @@ class SemanticScuttle_Service_Vote extends SemanticScuttle_DbService $res = $this->db->sql_query( $sql='UPDATE ' . $bm->getTableName() . ' SET bVoting = bVoting + ' . (int)$vote + . ' , bVotes = bVotes + 1' . ' WHERE bId = ' . (int)$bookmark ); $this->db->sql_freeresult($res); @@ -283,6 +290,7 @@ class SemanticScuttle_Service_Vote extends SemanticScuttle_DbService $res = $this->db->sql_query( $sql='UPDATE ' . $bm->getTableName() . ' SET bVoting = bVoting - ' . (int)$vote + . ' , bVotes = bVotes - 1' . ' WHERE bId = ' . (int)$bookmark ); $this->db->sql_freeresult($res); @@ -306,6 +314,9 @@ class SemanticScuttle_Service_Vote extends SemanticScuttle_DbService $bm = SemanticScuttle_Service_Factory::get('Bookmark'); $query = 'UPDATE ' . $bm->getTableName() . ' as B SET bVoting = ' . '(SELECT SUM(vote) FROM ' . $this->getTableName() . ' as V' + . ' WHERE V.bId = B.bId GROUP BY bid)' + . ', bVotes = ' + . '(SELECT COUNT(vote) FROM ' . $this->getTableName() . ' as V' . ' WHERE V.bId = B.bId GROUP BY bid)'; $this->db->sql_query($query); } |