Drupal FiveStar 模块投票限制



我正在使用五星投票模块,我想为用户可以投票的数量添加限制。有人知道该怎么做吗?

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.

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

最新更新