【问题标题】:Drupal FiveStar module voting limitDrupal FiveStar 模块投票限制
【发布时间】:2014-04-03 07:21:03
【问题描述】:

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

【问题讨论】:

    标签: drupal drupal-fivestar


    【解决方案1】:
    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.
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多