-1

我正在使用 FiveStar 投票模块,我想对用户可以进行的投票数量进行限制。有人知道该怎么做吗?

4

2 回答 2

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;
}

您可以尝试使用此自定义模块或类似的方法来执行此操作,它正在检查用户是否被投票。将以下代码添加到您的节点模板文件中:

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.
于 2014-04-11T10:06:24.700 回答
0

Fivestar 模块使用投票 API。投票 API 有一个配置页面,专门允许您在没有任何其他干预(例如自定义模块)的情况下执行此操作。您可以设置计算机(对于匿名用户)和(分别)注册用户身份被视为不同之前必须经过的时间。低于此时间重复投票是不允许的。每种情况下的时间都可以在“立即”和“从不”之间设置。

于 2014-04-30T21:54:21.503 回答