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

patchak’s picture

According 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

quicksketch’s picture

You need to actually return the result, not just put it in the field.

return $node->field_commerce_reli_0[0]['nid'];
patchak’s picture

Hey 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

michelle’s picture

Did 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

flevour’s picture

You may try

echo $node->field_commerce_reli_0[0]['nid'];

Otherwise you contact with me and we may debug it in real time.
Cheers,
Francesco

michelle’s picture

Some 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

michelle’s picture

Ok, I've gotten to:

$vote = votingapi_add_vote($type, $cid, $value, 'percent', $tag, $uid);

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

michelle’s picture

Another 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

michelle’s picture

Ok, 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:

   $current_rating = votingapi_get_voting_result('node', $nid, 'percent', 'vote', 'average');
   $numstars = 5; // Change this to how many stars you want
   print theme('fivestar_static', $current_rating->value, $numstars);  

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

quicksketch’s picture

VotingAPI 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?

michelle’s picture

He 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

patchak’s picture

Will try the latest dev version ASAP, thanks michelle for the help and follow-ups here!

quicksketch’s picture

Oh 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.

patchak’s picture

Michelle, 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

michelle’s picture

Patchak - I thought you already tried adding the code on IRC? Maybe I'm remembering wrong. Ok... In fivestar_field.inc, right after:

_fivestar_cast_vote('node', $items[$delta]['target'], $item['rating'], $items[$delta]['axis'], $node->uid);

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

patchak’s picture

I added this on the node, and nothing happens, the dsm($current_rating) returns nothing.

Thanks,
Patchak

michelle’s picture

I 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

quicksketch’s picture

Version: 5.x-1.11 » 5.x-1.12
Status: Active » Fixed

Michelle, 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.

michelle’s picture

Yay! Thanks, Quicksketch!

Michelle

patchak’s picture

thanks michelle and quicksketch for looking into this!
Patchak

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

harry slaughter’s picture

just ran into this same problem with 5.1.1.12

can't wait for the fix! :)

tks

harry slaughter’s picture

Status: Closed (fixed) » Active

reopening this since no fix has been created (tested CVS version and it still has same problem).

quicksketch’s picture

Harry, this should already be fixed. Here's the commit patch:

http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/fivestar/fi...

harry slaughter’s picture

Status: Active » Fixed

you'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

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

patchak’s picture

Status: Closed (fixed) » Active

I'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??

       $current_rating = votingapi_get_voting_result('node', $nid, 'percent', 'vote', 'average');
       $numstars = 6; // Change this to how many stars you want
       print theme('fivestar_static', $current_rating->value, $numstars);
     

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

michelle’s picture

It 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

patchak’s picture

Michelle, yep exactly the panel is at node/% what code would I need to add to get the nid??
thanks!

patchak

michelle’s picture

$nid = arg(1);

right before your existing code.

Michelle

patchak’s picture

Hey 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 :

return $node->field_commerce_reli_0[0]['nid'];

and the code I have in the panel-mini pane is the following :

       $nid = arg(1);
       $current_rating = votingapi_get_voting_result('node', $nid, 'percent', 'vote', 'average');
       $numstars = 6; // Change this to how many stars you want
       print theme('fivestar_static', $current_rating->value, $numstars);
     

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

patchak’s picture

I'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

msielski’s picture

I 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!

quicksketch’s picture

Category: bug » support
Status: Active » Closed (fixed)

Yes, please open a separate issue for the request. I'm closing this issue as it turned out not to be a bug.