Hi, I'm trying to print average from comment ratings in node-tpl.php, but dunno how, could someone help?

print fivestar_widget_form($node);

prints average node rating, but not average from comments rating

Thanx

Comments

sedmi’s picture

I would also like to be able to print average from comment rating.

czeky’s picture

Anyone? There has to be a way how to do this..

sedmi’s picture

It is possible by using nodecomment module. great tutorial: http://drupal.org/node/234681

virtualdrupal’s picture

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>';
?>
czeky’s picture

would be great to achieve this, can't believe that this is not possible

quicksketch’s picture

prints average node rating, but not average from comments rating

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.

czeky’s picture

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

print 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

quicksketch’s picture

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

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.

quicksketch’s picture

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.

czeky’s picture

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%)

quicksketch’s picture

czeky: Yes this is the way Fivestar works, as long as each comment is from a different user.

ericduran’s picture

Status: Active » Fixed

I'm going to close this issue because of previous comments. Feel free to reopen if needed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.