2

I have installed the rate module, and set the emotion widget. I like this module but after I vote successfully, I can click the vote button again. Instead I want to popup a window which says" you have voted. don't vote again", to prevent people from voting multiple times.

4

The rate module hasn't built support for this. If you wanted to do this, your best option would be to

  • Deny duplicate votes, it's up to you to decide how, but you could check the voting api table which stores the IP addresses of all who have voted then use rate_vote_alter hook. Doing it this way would make it impossible to change the vote.
  • The other option is to use rate_vote_alter to stop the rate module from saving votes and do it yourself with votingapi_set_votes. That would make it possible to set criterias for which (old) votes should be deleted.

This could have been done easier if the rate module was built more flexible. You could consider making an issue and a patch for the rate module, to add this feature for others to use.

Update:
The alter hook is not defined anywhere, but done with drupal_alter('rate_vote', $votes, $context). This means you should be able to do:

function my_module_rate_vote_alter(&$votes, $context) {
  ..
}
|improve this answer|||||
  • i have found the table that stores the IP addresses . but i don't how to do the next. and didn't find rate_vote_alter hook. – enjoylife Mar 22 '11 at 2:43
  • thanks for the correct answer, best to ask these kind of questions on the drupal rate project page though – user752 Mar 26 '11 at 9:15
  • it there a way to use javascript get that? – enjoylife Apr 16 '11 at 12:03
  • the way your said is hard to me. i can't follow it well :( – enjoylife Apr 16 '11 at 12:10
0

This is an example on how not saving the vote in the database.

function my_module_rate_vote_alter(&$votes, $context) {
  // Check the database.

  $context['save'] = FALSE;
}
|improve this answer|||||
0

Working code for folks:

/**
 * Implements hook_rate_vote_alter().
 */
function mymodule_rate_vote_alter(&$votes, &$context) {
  $cookie = $votes['tag'] . '_' . $votes['entity_type'] . '_' . $votes['entity_id'];
  // If the cookie is already set.
  if (isset($_COOKIE["$cookie"])) {
    // Indicating not to accept this vote.
    $context['save'] = FALSE;
  }
  else {
    // Set cookie and make sure that its valid for next 30 days.
    // This will populate the $_COOKIE["$cookie"] and make sure to block the
    // vote if user is trying to vote it more than once.
    setcookie("$cookie", 'ratevote', time() + (60 * 60 * 24 * 30), '/');
  }
}

hook_rate_vote_alter() is available at rate.hooks.inc

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.