Closed (fixed)
Project:
Fivestar
Version:
5.x-1.12
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
5 Apr 2008 at 14:34 UTC
Updated:
5 Oct 2008 at 22:27 UTC
Hey there,
I'm using nodereference and fivestar module to create a 'review' site. I added the widget to the 'review' type and I'm trying to pass the NID of the parent node to the voting widget, so that when you vote on the review node, it actually affects the parent node.
what I tried is inserting this :
$node->field_commerce_reli_0[0]['nid']
This string contains the NID for the parent node according to devel module. I tried with and without php tags and there is nothing to do, the value will not get passed.
Is there anything you would have to suggest to fix this? Maybe I'm not adding the right info to get the variable??
Thanks for any advice,
Patchak
Comments
Comment #1
patchak commentedAccording to devel module the target is not passed to the module's variables, not sure where it happens exactly, I'll try to debug and add details on exactly where the passing of the value fails??
One question : I'm I using the right variable to pass the target? Should I use the whole array as a reference or the $node->field_commerce_reli_0[0]['nid'] should be enough??
Thanks,
Patchak
Comment #2
quicksketchYou need to actually return the result, not just put it in the field.
Comment #3
patchak commentedHey there, thanks for the tip.. but are you sure this is supposed to work??
I tried the string you suggest without success. I printed it with and without php tags and still the target vote is not recognized.
The target is still empty when I check the node with devel... IS there anything I'm missing here? It should be simple to pass the NID, IMO this should work.. maybe it's really a bug then?
Patchak
Comment #4
michelleDid you ever try the debugging code I suggested on IRC? That will clearly show you what is getting passed to the eval function and what it returns.
Michelle
Comment #5
flevour commentedYou may try
Otherwise you contact with me and we may debug it in real time.
Cheers,
Francesco
Comment #6
michelleSome further info. I've been working with him on IRC and the correct nid _is_ getting passed to
$items[$delta]['target']so the failure is farther down the line. I'm trying to trace it now but figured I'd post in case quicksketch is around and has any ideas.Michelle
Comment #7
michelleOk, I've gotten to:
and that is passing the correct values. It seems like the problem is in votingapi. I'm going to leave the issue here for the moment but will move it if we find the problem there.
Michelle
Comment #8
michelleAnother update... The vote is being correctly stored in the table by voting api. But the node is still saying there's no votes. So it's something on the retrieval end going wrong. Will dig some more.
Michelle
Comment #9
michelleOk, I think I found the problem.
function fivestar_field() calls _fivestar_cast_vote() directly instead of fivestar_vote(). _fivestar_cast_vote calls votingapi_add_vote which says "In most cases, this should not be called directly by external modules." I think it should be calling votingapi_set_vote() instead. fivestar_vote() compensates for calling the "wrong" function by manually calling votingapi_recalculate_results() but this never happens when _fivestar_cast_vote() is called directly.
The end result of this is that when you vote from a widget, it gets stored in votingapi_vote but the average never gets updated in votingapi_cache. Displaying the stars on the target node is done via this code:
And that code pulls out of the cache table.
I'm not sure if simply having fivestar_field() call fivestar_vote() instead would fix it. Will have to try that. Was there some reason that it wasn't done that way?
Michelle
Comment #10
quicksketchVotingAPI had several critical issues that were only just patched 2 days ago that caused the sort of behavior you're describing. Have you tried updating to the latest version since then?
Comment #11
michelleHe said he was on the latest stable, I believe. He had to go and said we'd pick up the debugging on Monday. I'll ask him, then, to try the dev, if he doesn't see this first.
Thanks,
Michelle
Comment #12
patchak commentedWill try the latest dev version ASAP, thanks michelle for the help and follow-ups here!
Comment #13
quicksketchOh sorry, I had been referring to the 6.x version of VotingAPI which needed to be updated. I don't think there have been changed in 5.x that would have caused this problem. Thanks for the bug hunting. If we can find out what's causing it I'll patch the module to fix it.
Comment #14
patchak commentedMichelle, what are the changes I shoudl try in the module?? If I understood correctly we should try to call another function on the vote??
Patchak
Comment #15
michellePatchak - I thought you already tried adding the code on IRC? Maybe I'm remembering wrong. Ok... In fivestar_field.inc, right after:
put:
votingapi_recalculate_results('node', $items[$delta]['target'])That should, hopefully, get the vote average put in the cache like it's suppsed to be. If it's still not working, go to the .tpl file and right after:
$current_rating = votingapi_get_voting_result('node', $nid, 'percent', 'vote', 'average');put
dsm($current_rating)to see if it's actually returning the rating. If it's not then that didn't work.I'll be back in a few hours if you want to work on IRC some more.
Michelle
Comment #16
patchak commentedI added this on the node, and nothing happens, the dsm($current_rating) returns nothing.
Thanks,
Patchak
Comment #17
michelleI guess he forgot to update the issue. #15 did, in fact, fix it for him. Something else got mixed up along the way so at first it looked like it didn't.
quicksketch - Can that be added to the module?
Michelle
Comment #18
quicksketchMichelle, thanks I added the line to the field handler like you suggested. I just ran up against this exact problem in Drupal 6, so I'm glad you mentioned it here so I can solve the same problem there. Thanks! This'll be fixed in 1.13.
Comment #19
michelleYay! Thanks, Quicksketch!
Michelle
Comment #20
patchak commentedthanks michelle and quicksketch for looking into this!
Patchak
Comment #21
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #22
harry slaughterjust ran into this same problem with 5.1.1.12
can't wait for the fix! :)
tks
Comment #23
harry slaughterreopening this since no fix has been created (tested CVS version and it still has same problem).
Comment #24
quicksketchHarry, this should already be fixed. Here's the commit patch:
http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/fivestar/fi...
Comment #25
harry slaughteryou're right it is.
i tested every step and all was good. finally, when i got to the actual call to _fivestar_cast_vote(), I realized that if the target node type does not have voting enabled, the vote will be disregarded entirely. I had turned off the voting on the node itself so that all votes would be contained entirely in the review node.
it would be ***extremely*** useful if a comment could be added to the 'target node id' config area that makes it crystal clear that the target node type must have fivestar enabled. i'd use blink tags ;)
so it was pilot error, but still a very difficult problem to track down because there's no indication that anything went wrong. i might suggest logging a watchdog warning when a vote is cast that is going to be disregarded. at least this would bring such problems to light sooner.
tks
Comment #26
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #27
patchak commentedI'm inserting this code to publish my stars directly into a panel's pane... Do you think it can work when embedded into a panel page, or it only works on node.tpl.php files??
I need to display the stars for that node directly into a panel so i tried like this, is there any other way to do this??
thanks,
Patchak
Comment #28
michelleIt will work as long as you're able to set $nid to the node ID. If the panel is for a node/XX page, you can get it from arg(1). Otherwise, we need more info to be able to answer that.
Michelle
Comment #29
patchak commentedMichelle, yep exactly the panel is at node/% what code would I need to add to get the nid??
thanks!
patchak
Comment #30
michelle$nid = arg(1);
right before your existing code.
Michelle
Comment #31
patchak commentedHey there sorry for the delay in the answer, but it does not work, the value is not passed this way...
The code I have on the field is the same as before :
and the code I have in the panel-mini pane is the following :
Since this code is in mini panel, my guess is that the arg(1) might not be accessible, but I still have the context available, is it possible to pass directly the node ID from the context of panels ??
Thanks
Comment #32
patchak commentedI'm trying now to get the results into views. I'm using the following fields:
VotingAPI percent vote result (average)
and
VotingAPI percent vote value
and in both cases I don't have any results displayed... It seems there may still be a bug on voting API so that the votes are not calculated properly?? Any idea how to debug this?? Should work with views no ?
Patchak
Comment #33
msielskiI would like to follow up to #25, which thankfully saved me. It's true that the target node type, even if using indirect voting (like multi-axis voting via a 'review' node type) has to have fivestar enabled on it for the vote to get passed into voting api. This should at least be made clear to the user somewhere in the UI, and like Mr. Slaughter suggested maybe via watchdog.
Should this be made a new issue, or a feature request? Another nice feature would to not require fivestar be turned on on the target node, for those using an indirect method. Thanks!
Comment #34
quicksketchYes, please open a separate issue for the request. I'm closing this issue as it turned out not to be a bug.