用户登录

Drupal资源链接

http://zhupou.cn
drupal布道者,改成了"老葛的Drupal培训班",专心于培训事业
http://drupal.org
官方网站
http://drupalchina.org
中文的官方网站
http://acquia.com/
本站就是用这个版本构建的

用fivestar进行多轴投票

在drupal中进行投票时,可以有多种模块进行选择,如fivestar,Plus 1,等模块,但这些模块要进行多项投票时,却没有一个现成的模块,原来有一个NodeReview是可以进行多项投票选择的,但主要是针对drupal5的,对于drupal6版本的只有一个开发版本,那么fivestar能不能进行多项投票选择?

官方文档中,有一种方法可以解决这个问题:需要用CCK建立另一个投票节点来解决。下面来说说我的解决方法。

启用fivestar模块

对要进行多项投票的节点启用fivestar

在显示设置中隐藏fivestar元素(Teaser display: 与Full node display: 都选择hidden)

在节点模板文件中加入多项投票选择的显示

$aa=fivestar_get_votes("node", $node->nid, "reliability");//其中reliability是投票的标志,在数据库中的一个字段内容,fivestar_get_votes是取得当前节点投票的值
$values = array(
      'user' => $aa['user']['value'],
      'average' => $aa['average']['value'],
      'count' =>  $aa['count']['value'],
    );
$settings = array(
      'stars' => variable_get('fivestar_stars_'. $node->type, 5),
      'allow_clear' => variable_get('fivestar_unvote_'. $node->type, FALSE),
      'text' => variable_get('fivestar_text_'. $node->type, 'dual'),
      'content_type' => 'node',
      'content_id' => $node->nid,
      'tag' => 'reliability',
      'autosubmit' => TRUE,
      'title' => "显示标题",
       'style'=>'average',
      'feedback_enable' =>  variable_get('fivestar_feedback_'. $node->type, 1) ,
      'labels_enable' => variable_get('fivestar_labels_enable_'. $node->type, 1) ,
      'labels' => variable_get('fivestar_labels_'. $node->type, array()) ,
    );
$aa=fivestar_get_votes("node", $node->nid, "aaa");//第二个投票的选项
$values1 = array(
      'user' => $aa['user']['value'],
      'average' => $aa['average']['value'],
      'count' =>  $aa['count']['value'],
    );
$settings1 = array(
      'stars' => variable_get('fivestar_stars_'. $node->type, 5),
     'allow_clear' => variable_get('fivestar_unvote_'. $node->type, FALSE),
     'text' => variable_get('fivestar_text_'. $node->type, 'dual'),
      'content_type' => 'node',
      'content_id' => $node->nid,
      'tag' => 'aaa',
      'autosubmit' => TRUE,
      'title' => "可用性",  
      'style'=>'average',
      'feedback_enable' =>  variable_get('fivestar_feedback_'. $node->type, 1) ,
      'labels_enable' => variable_get('fivestar_labels_enable_'. $node->type, 1) ,
      'labels' => variable_get('fivestar_labels_'. $node->type, array()) ,
    );
    print  '<div id="rr"><div id="aa">'.drupal_get_form('fivestar_custom_widget', $values, $settings).'</div>';  
    print  '<div id="bb">'.drupal_get_form('fivestar_custom_widget', $values1, $settings1).'</div></div>';//打印出要投票的内容,放在DIV中可进行自定义的CSS设置这部分内容可放在节点模板文件中。

<?php
$value_rating = votingapi_select_results(array('content_id' => $node->nid, 'tag' =>'reliability', 'function' => 'average'));
$value_rating1 = votingapi_select_results(array('content_id' => $node->nid, 'tag' =>'aaa', 'function' => 'average'));     ?>
 <div style="float:right" >  <img src="/draw.php?a=<?php print $value_rating[0]['value']/20; ?>&b=<?php print $value_rating1[0]['value']/20; ?>"/></div>//这部分内容可以放在缩略显示中,可用直方图来显示投票的结果(类似于drupalmodules.com)

 

评论

这个方法我对我很有用,在此先谢谢了。 不过在发表评论的地方

这个方法我对我很有用,在此先谢谢了。

不过在发表评论的地方如何也加上这个多轴投票呢?

像fivestar 的Comment widget那样。

我想道理应该一样

不过我没有试过,这段时间比较忙,没空看那个组件