How to print average from comment ratings?
czeky - September 10, 2009 - 07:24
| Project: | Fivestar |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Hi, I'm trying to print average from comment ratings in node-tpl.php, but dunno how, could someone help?
<?php
print fivestar_widget_form($node);
?>prints average node rating, but not average from comments rating
Thanx

#1
I would also like to be able to print average from comment rating.
#2
Anyone? There has to be a way how to do this..
#3
It is possible by using nodecomment module. great tutorial: http://drupal.org/node/234681
#4
That link above seems like overkill for this task.. isn't there a shortcut to tally up the average of all the comment ratings by the nodeid, and output the results with something like this?
<?php$current_rating = votingapi_select_results(array('content_id' => $node->nid, 'function' => 'average'));
print '<div><strong>Rating:</strong>';
print theme('fivestar_static', $current_rating[0]['value'], '5'); //this is for 5 stars, enter 10 (or whatever) instead as appropriate
print '</div>';
?>
#5
would be great to achieve this, can't believe that this is not possible
#6
You might be misunderstanding the way Fivestar works. The "average node rating" and the "average from comments" is essentially the same. When you allow a user to rate from a comment, it's the same as if they had clicked on the star rating widget within the node. Generally you probably won't want to have both the direct-rating and the comment-rating enabled on the same node, since they both do the same thing.
#7
Hi, thanx for a reply, I thought so, but when I comment node (in my case profile node) say 1 star from 10 and second vote 3 stars from 10, I'd expect average rating to be 2 from 10, but this is not what it shows, I'd like to show this value, now it shows something different, dunno what (in my case 5 from 10, doesn't matter what rating was added in comment), I know, it should work, just searching for the right php
<?phpprint fivestar_widget_form($node);
?>
is not displaying what I need - the average from comment ratings
EDIT: average prints only the last value of the vote, so when I vote 2, then 4, then 6, I would expect 4, but 6 is displayed
#8
Yes, this is correct because Fivestar (or VotingAPI more accurately) only allows one rating per-user. So if you leave 100 comments all as the same user, only the last rating actually affects the average. If you rate as a different user each time, then the average is taken from each user's last rating.
#9
A related feature request is to not allow users to post (or at least submit a rating through) multiple comments. See #211517: Prevent a user from rating through multiple comments.
#10
Hi, thanx for explanation, it's clear.. anyway what I'm trying to achieve is in this example
3 voting on node ‚nid‘ = 10, first vote ‚cid‘ = 5 and ‚value‘ = 10, second vote ‚cid‘ = 8 and ‚value‘ = 3, third vote ‚cid‘ = 20 and ‚value‘ = 5
value calculation 10+3+5 = 18 / 3 votes = 6 … average rating is 6 from10 (60%)
#11
czeky: Yes this is the way Fivestar works, as long as each comment is from a different user.