I am using FiveStar voting module and I would like to add a limit to the number of votes a user can make. Anybody know how to do that?
Drupal FiveStar module voting limit
657 Views Asked by Remus At
2
There are 2 best solutions below
0

function YOURMODULENAME_print_rating($nid, $fivestar_widget) {
$path = drupal_get_path('module', 'fivestar');
drupal_add_js($path . '/js/fivestar.js');
drupal_add_css($path . '/css/fivestar.css');
$voting_message = '';
$output = '';
$is_login = user_is_logged_in();
$rating = votingapi_select_single_result_value(array(
'entity_id' => $nid,
'entity_type' => 'node',
'tag' => 'vote',
'function' => 'average',
));
if ($is_login) {
if (isset($rating)) {
$voting_message = "<div>You have already rated this.</div>";
$output = theme('fivestar_static', array('rating' => $rating, 'stars' => 5, 'tag' => 'vote')) . $voting_message;
}
else {
$output = render($fivestar_widget);
}
}
else {
$fivestar_links = l('Login', 'user/login') . ' or ' . l('Register', 'user/register');
$voting_message = "<div>Only registered user can rate this content type.<br/>$fivestar_links to rate this content type.</div>";
$output = theme('fivestar_static', array('rating' => $rating, 'stars' => 5, 'tag' => 'vote')) . $voting_message;
}
return $output;
}
You can try doing it with this custom module, or something like this, it is checking if the user is voted or not. Add the following code to your node template file:
hide($content['field_fivestar_rating']);// This line will hide the stars which are coming from the fivestar module.
print YOURMODULENAME_print_rating($node->nid, $content['field_fivestar_rating']);// This will print the fivestar.
The fivestar module uses the voting API. The voting API has a configuration page which specifically allows you to do this without any other intervention such as custom modules. You can set a time which must pass before computer (for anonymous users) and (separately) a registered user identity can be regarded as being different. Below this time repeat votes are disallowed. The time in each case can be set between "Immediately" and "Never".