I am currently using nodecomments which replaces the default comments and makes comments actual nodes. The reason being I need to add a lot of custom fields to my comments including Fivestar. This is for a review site and I was not happy with the current state of drup's review modules, so I decided nodecomments would actually be the best.
Now it works and looks fine with Fivestar with one large expection. Say I create a page that has a photo on it and 10 user comments (reviews). Each users comment on that page had fivestar showing what that user rated the photo at, but I also want to show the overall tally or average vote on top of the page ( or anywhere for that matter).
I think this is possible using the votingapi but since every comment rating is a seperate node I might be up the creek?
Any ideas on how I can tally results from differant nodes ( even though they are a part of the same node)?
Comments
Comment #1
quicksketchYep! You're actually reproducing the exact situation fivestar was originally written for. Check out
http://www.goodcharlotte.com/music for an example.
The comments on the page are of 'review' type, which contain a fivestar rating widget (you'd need to register to post a review though).
The trick is setting the target Node ID in the fivestar field settings. Go to 'Manage fields' for your content type, click edit on your fivestar field. Then use the following PHP code in the Node ID field:
Note that you'll need to set 'field_rating' to whatever the name of your fivestar field is.
To display the combined rating on the target node, display the static theme function:
Comment #2
quicksketchComment #3
teamrob CreditAttribution: teamrob commentedThats great thanks a lot, I cant get the votes to tally per node though.
My setup is the following ( using node comments).... Created new content type called Review with new field for the Fivestar, set options to 10 stars and pasted your code into the node ID.
Then create a page and set the node type for comments to Review.
I can make page and add reviews no problem but the tally doesn't work. I copy/pasted your static theme function right into the page body ( using php input format) as well as hard coding it into the themes tpl.php but I just get 5 empty stars.
Comment #4
teamrob CreditAttribution: teamrob commentedIf youd like to have a look at test site login test/test http://dotnature.com/reviews/test/
Comment #5
sbandyopadhyay CreditAttribution: sbandyopadhyay commentedTo echo teamrob, thanks for the code snippets quicksketch! But... I have the same exact problem as teamrob. Namely, the votingapi_get_voting_result function is not returning a valid rating. I poked around for a bit, and I've figured out a possible reason why: the votingapi_cache table is empty. This probably means that, for some reason, the vote averages are not getting tallied and cached properly.
Any help in addressing this would be greatly appreciated!
Comment #6
sbandyopadhyay CreditAttribution: sbandyopadhyay commentedAnd i'm using Fivestar 1.7, and I believe teamrob may be using the same version as well
Comment #7
Will White CreditAttribution: Will White commentedSame issue. Subscribing.
Comment #8
Will White CreditAttribution: Will White commentedAfter a little debugging I found my problem. I hadn't enabled fivestar on my target content type. I just turned it on and set both "widget location" dropdowns to "hidden" so that the only way to vote is through a comment. Does that fix your problem as well?
Comment #9
teamrob CreditAttribution: teamrob commentedNo this did not work for me:( Still getting blanks when turned on and set to hidden.
What did you put for the target in
return $node->field_rating[0]['target'];
I have mine set to "Star" which is the field name I made , is that correct?Would love to get this to work.
Comment #10
lolabean CreditAttribution: lolabean commentedHi Teamrob,
We're having the same kind of problem but I was hoping you could clarify your issue. Quickstretch pointed to a setup --
http://www.goodcharlotte.com/music -- which seems more or less like what we want to do. You may be doing what we're trying but I need some conceptual help.
If I get this correctly there is a difference between your setup and the goodcharlotte.com view. Yours is a node with a series of user comments (as nodes) created with node comment. The user comments all have ONE fivestar rating in them but you want the total for all that appear on that page only to tally on the page.? OR do you want all user reviews of that node to tally?
The goodcharlotte.com view is a series of stacked nodes -- either by views or custom code -- that are of a custom content type called reviews. So each song in the list is in fact a 'review' which is actually displaying just the song title. Users are able to rate the 'review' which is the song. This view does not need to have the total tallied as it would have no real meaning in this context. .
So you want to tally the reviews that the users have already entered that are displaying on the page. The Goodcharlotte view needs to allow on the spot ratings to the entered for each node. In other words rather than collecting the already entered ratings as in your scenario the user rates the nodes on that page.
Does this accurately reflect what you want and what is occurring on the Goodcharollte page?
My question to Goodstretch is exactly how is the content type and fivestar created for the songs that are listed on the page? Is it as you said a really simple CCK content type called 'review' that allows the admin to enter the song title and reveals the fivestar and the song title in the node?
I think I have this straight. Probably not.
Comment #11
teamrob CreditAttribution: teamrob commentedWell simply put the user review ( or comment) will show what the user rated for that node in thier comments and an average tally for them all will appear in the parent node, exectly like on the good charlotte website. This just shows a relation between the commenters review and the overall review, which can be useful for a more detailed scenario.
It doesn't make any difference if the its a custom content type, a page, a post .. or if its using default comments ,nodecomments, or any custom code. I don't think you fully understand how this works. I'm using nodecomments because its allows for a lot of customization, most of which is unrelated to fivestar.
The code posted above works great but there is a problem with the voting api that is either not storing the vote or displaying them when they are called, unfortuntly I haven't had time to look futher into why this is happening.
Comment #12
quicksketchHahahaha, "goodstretch" I like that.
The list of tracks on that page is a teaser list of tracks, built with the views module. So it is actually the teaser display of each of the track nodes. node-track.tpl.php file is setup to output the voting widget for each node.
Comment #13
maxparm CreditAttribution: maxparm commentedHello!
Can you say us how to do the same things as http://www.goodcharlotte.com/music or http://www.daughtryofficial.com/music/album/daughtry step by step because I don't understand your previous messages.
Thanks in advance!
Comment #14
Kuldip Gohil CreditAttribution: Kuldip Gohil commentedhi
i have to print fivestar voting in my .tpl file
i am using jquery to node in custom view
i am print by using
$output= fivestar_widget_form($node);
print $output;
but it not working properly.. i cant do voting.
please give me solution
Comment #15
quicksketchPlease do not hijack the issue with an unrelated request. I'm closing this issue again as we've solved the original request.
Comment #16
Minoo CreditAttribution: Minoo commentedComment #17
Anonymous (not verified) CreditAttribution: Anonymous commentedHow would I use this with several fivestar fields (multi-axis)?
Comment #18
quicksketchtxcrew, once again this would be a new support request. Though related to the original question, it's certainly different. Open a new issue and link to this one if necessary.
Comment #19
greg.harveyWas a separate bug report raised about the empty votingapi_cache table? I can't find it - if not, I'll raise one. Not sure if it's a Fivestar issue or a VotingAPI issue though! =(
Comment #20
greg.harveyOff original topic, but related to other content in the thread so worth posting:
While the Voting API team sort this out, if you set your Voting API settings to "Tally when cron runs" then the votingapi_cache table is populated correctly.
Comment #21
rimma CreditAttribution: rimma commentedI have same problem. It looks like not working very well, just not sure what reasons. I have checked all possible reason, such as enable targeted content type five star, run cron. anything else.
Comment #22
swortis CreditAttribution: swortis commentedRunning cron does not work for me.
Anyone have any new suggestions for this issue?
Comment #23
greg.harveyTry calling the function in question directly from your module - I can't remember what it is off the top of my head, but a quick review of the votingapi.module file should reveal it. It will have a sensible name, I'm sure. You could do it in a hook_nodeapi implementation just as a test.
Comment #24
swortis CreditAttribution: swortis commentedThat would be this?
Comment #25
JStarcher CreditAttribution: JStarcher commentedDid anyone ever figure this one out? I've run into the exact same scenario.
Comment #26
smanes CreditAttribution: smanes commentedMaybe I can help a little but I'll explain the circumstances and you figure out if it's useful to you. I'm building a dependent module for FeedAPI that provides a more structured view of RSS feeds. One of my content types displays a paged, formatted (i.e. banner image) list of teasers for the latest incoming feed posts. I want users to be able to vote on those posts, with the results aggregating back to the feed's "home page". In other words, the feed's home page (a FeedAPI "feed" type) will collect the average of all the votes for all of its feed items.
With the latest FiveStar and VotingAPI modules for v6, it was actually cake. In the theme preprocessing function for the feed teaser:
Works great.
Comment #27
pdenoeud CreditAttribution: pdenoeud commentedI have one question related to this issue.
quicksketch said:
"To display the combined rating on the target node, display the static theme function:
"
With Drupal 7, can we display this combined rating in a view that would list the target nodes, so that we can display in the view the five star widget for each row, and eventualy sort the list by rating value?
The use case is to allow reviews of hotels, and display the list of all reviewed hotels, with their rating. Users could then sort the hotels by rating to see first the one with the best rates.
I guess it depends if each hotel's combined rating is stored in database (and updated each time a review is added/edited/removed), or if it is caculated on the fly when we call the votingapi_get_voting_result method.