Sanity check in function vud_vote() in vud.theme.inc checks for voting with the same value. The code for the check is as following:

// Do not allow vote with the same value
if ( ($casted_vote > 0 && $value > 0) || ($casted_vote < 0 && $value < 0) ) {
  $value = FALSE;
}

When voting results are altered in a hook or set from different place, they do not need to contain the original +1/-1 value. In our case, votes are set from voting widget (and multiplied by user's reputation = any positive integer) and from nodeapi hook when node is viewed in detail. That means vote result is mainly influenced by users voting in widget and a little bit influenced by users viewing the node.

We set the node's vote to 1, when user is viewing the node, and to 15*reputation*voteRequest (+1/-1) when user is voting for the node. When the user first views the node (and therefore silently votes +1 for the node) and then wants to vote for the node (votes +15*reputation, let's say his reputation is 1, so he votes +15), the vote is ignored because of the check mention above.

Because vote up/down's results are meant to be altered in hooks, I would suggest to change the check to the following:

$value = ( $casted_vote === $value ) ? FALSE : $value;

This also deals with initial NULL value for $casted_vote, FALSE value for $value from previous sanity check and does not allow voting with the same value again, but allows to "revote" with different value, either positive or negative. When vote results are not altered, the behaviour is the same as in the original code.

Another approach would be to create a hook that is launched before those checks.

CommentFileSizeAuthor
#1 vud.theme_.inc_.patch193 bytesaleshaczech
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

aleshaczech’s picture

FileSize
193 bytes
aleshaczech’s picture

I would also suggest one more thing.

What is the real purpose of the check mentioned above? Is it to avoid unnecessary calls to voting API? I don't see a different reason as voting API should update previous votes with no problems.

If so, the check IMHO should be placed after drupal_alter( 'vud_votes', $votes ); call as 3rd party modules may change the vote's real value.

marvil07’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, vud.theme_.inc_.patch, failed testing.

marvil07’s picture

Title: Voting with the same value » Let vote in the same direction with a different value
Category: feature » bug
Status: Needs work » Fixed

@aleshaczech: Thanks for the suggestions.

It's on all branches: 6.x-3.x, 6.x-2.x and 7.x-1.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.