If this is answered elsewhere or supposed to be in another forum, please let me know and I'll move the question, but I've googled and searched for the last 5 hours and haven't found an answer yet.
I have a custom form I built which works fine, but when I save the fivestar rating, it overwrites the last vote so the average always shows as the last vote, and it claims that there's only one vote, even though when I look at the node with the children listed, there are several votes (all the ones from before).
The form field is:
$form['name']['vote'] = array(
'#type' => 'fivestar',
'#title' => t('Rating'),
'#required' => TRUE,
);
The field where the rating is set in the node object before saving to the system (and creating the node) is:
$reviewValues['values']['field_fivestar'] = array(array('rating' => $form_state['values']['vote']));
When I go to load the average rating in the template, I'm using
$current_rating = votingapi_select_results(array('content_id' => $node->nid, 'function' => 'average'));
print '<div><strong>Average Star Rating:</strong>';
print theme('fivestar_static', $current_rating[0]['value'], '5'); //this is for 5 stars, enter 10 (or whatever) instead as appropriate
print $node->nid.'</div>';
print fivestar_widget_form($node);
I'm using print fivestar_widget_form($node); in addition which is what's showing that only the last saved review rating is being used, and that there's apparently only one review.
I'm sure I'll need to clarify what I said, but can anyone see anything that I'm doing wrong?
Comments
Same issue
I've having the exact same issue, it seemed to have happened after i deleted some tags and made new ones. clueless as well.
My problem seems to be...
That when I added new tags I did not enable them in my content type. Maybe your issue has to do with the fact no tags are declared. But I'm not too familiar with the API and that might be how to code it with the vote tag.
Same here...
I'm seeing the exact same behavior, and I'm only using the user interface to create everything, that is, I just have a content type with the fivestars widget and I'm sending votes to another content type's nodes, specified by a Node reference in the 'review' node. Everytime I save a review node referencing the same 'voted' node, the votingapi_vote table ovewrites the last one, leaving just one vote for each voted entity.
I also have a view showing the average votes for the voted nodes and the average only reflects the last voted given to that node. You can see that on the votingapi_cache table. I think this might be a bug as it's a pretty straightforward scenario not working out as expected. I don't think it has anything to do with your code.
If you or anyone finds what's the problem please post!
Thanks.
Same issue with me as well
Same issue with me as well
Same here. Very frustrating.
Same here. Very frustrating.
print fivestar_static('node', $node->nid);Displays the last vote cast, not the average vote! :(
Hi I hope this will answer
Hi
I hope this will answer the question:
"IMPORTANT NOTE: if you create a new comment as the same user on the same album, your previous vote will be over-written, not added to. If you wish to test the 'average' function by creating more reviews, you must do so as different users. This behaviour is BY DESIGN. If you don't like it, create a patch and publish it back to the community. =)"
I cannot tell you where exactly I found it (I think it was in the Voting API documentation) but it definitely helped.
User is defferent
I've got plenty of users voting and the relative node stores only the last vote!
It worked just fine but after upgrade or something got broken! Someone, please, any ideas? Using 7th drupal with latest version of voting api and fivestars.
drupal 8 version is doing this
i'm with drupal 8.9 and it does the same with me.
it showes only the last vote with different user and override all votes.
any idea to how to resolve this?