I am trying to create a view page that user can list all nodes that they have voted on. This view will show the node title, the users vote, the average user vote and the number of votes.
I created the view and it worked fine, except that all nodes are duplicated by the number of votes, because the “VotingAPI percent vote user” filter is not working correctly. I had a look at the SQL being generated for the view and then started hacking at the votingapi_views.inc file. Now I don’t know the views api at all and I know just as much about the votingapi, but I think I found the problem.
The filter is not adding a where clause for the user (eg uid = 1).
The following is what I added at the end of my votingapi_handler_filter_uid_voted() function, and now it seems to work.
I don’t want to use this in a production system before somebody more knowledgeable tells it’s correct.
votingapi_views.inc,v 1.11.2.5
function votingapi_handler_filter_uid_voted($op, $filter, $filterinfo, &$query) {
...
...
if ($filter['value'] == '***CURRENT_USER***') {
$query->add_where('votingapi_vote_'. $filterinfo['tag'] .'_'. $filterinfo['value_type'] .'.uid = ***CURRENT_USER***');
}
}
Comments
Comment #1
ShutterFreak commentedSubscribing to this issue, as I experience the same behavior. Your patch however doesn't seem to work on my system (I use VotingAPI + jRating), so I have set the status to "active".
I am not sure whether it is a VotingAPI or a jRating issue.
If you import the followign view (without the opening and closing PHP tags), you'll see that when other people also rated a given page you have rated, you'll see duplicate entries:
The problem disappears when I decide to not show the vote for the current user, like in the following view:
My guess is that something's wrong at the level of a JOIN in a SQL query.
Best regards,
Olivier
Comment #2
ShutterFreak commentedThe problem was fixed in my situation by adding the "Node: distinct" filter to the view.
When adding this filter, make sure you click once on the "distinct" option or you'll get an error message when saving the view.
Best regards,
Olivier
Comment #3
keithorama commentedI tried the Node: Distinct fix and it didn't work - it showed only one row per node, yes, but the score given was not the correct one for the current user.
Looks like this is fixed in 5.x-1.x-dev. There is a new field type called 'VotingAPI points vote value (current user only)', which solves the problem.
Comment #4
ShutterFreak commentedYou are right - my fix does not show the correct ratings for the users.
Comment #5
timb commenteduid = 1 will always give you the admin user! You want to load the current user number $user->uid
Comment #6
eaton commentedSupport for the 5.x branch of VotingAPI has ended with the release of Drupal 7 and the upcoming release of VotingAPI 7.x-2.4.