Several ratings for the node with fivestar module.

Fivestar is a popular drupal module for node ratings setup. Unfortunately, it’s unable to rate node by several parameters, multiple axis. It can be still used to create reviews, and you can setup several ratings in a review. But you will need whole pack of modules: fivestar, cck, node comments, node limit or something like that. Last dev-version 6.x-1.x-dev from 28 january fix this disappointing imperfection. But it’s in completely mess! It’s simply ignore settings you set.

So, I’ve found this topic and caught this snippet:

  1. <?php
  2. $nid = arg(1);
  3. $output = '';
  4. $tags = array(
  5. 'quality' => t('Quality'),
  6. 'color' => t('Color'),
  7. 'vote' => t('Overall'),
  8. );
  9.  
  10. foreach ($tags as $tag => $title) {
  11. $votes = fivestar_get_votes('node', $nid, $tag);
  12.  
  13. $values = array(
  14. 'user' => isset($votes['user']['value']) ? $votes['user']['value'] : NULL,
  15. 'average' => isset($votes['average']['value']) ? $votes['average']['value'] : NULL,
  16. 'count' => isset($votes['count']['value']) ? $votes['count']['value'] : NULL,
  17. );
  18.  
  19. $settings = array(
  20. 'stars' => 5,
  21. 'allow_clear' => TRUE,
  22. 'style' => 'average',
  23. 'text' => 'dual',
  24. 'content_type' => 'node',
  25. 'content_id' => $nid,
  26. 'tag' => $tag,
  27. 'autosubmit' => TRUE,
  28. 'title' => $title,
  29. 'feedback_enable' => TRUE,
  30. 'labels_enable' => TRUE,
  31. 'labels' => array(t('Poor'), t('Okay'), t('Good'), t('Great'), t('Awesome')),
  32. );
  33.  
  34. $output .= drupal_get_form('fivestar_custom_widget', $values, $settings);
  35. }
  36.  
  37. print $output;
  38. ?>

Also fivestar module is supposed to be patched to use the snippet. But it’s look like last stable module version 6.x-1.19 already have all necessary modifications, so everything working as is.

Khe-khe. There is still a problem. Now I have multiple ratings, but I can not setup different widgets(one rating with red stars and another one with blue, for example)!
 

Comments

Post new comment

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.