I'm currently troubleshooting an issue (#1940644: Vote sum not displayed until page is refreshed) with an up/down widget with the 'points' value type.
The problem is that after the user votes, the widget appears to show only the value of the vote she cast, regardless of the sum, until the page is refreshed. When the page is refreshed, the correct sum is displayed (matching the VotingAPI cache table value for the 'sum' function for the entity being rated).
I'm still getting familiar with Rate module, but I noticed this block of code in rate_get_results(), which is called from rate_vote_ahah() via rate_generate_widget():
foreach ($results as $result) {
if ($widget->value_type == 'percent' && $result['function'] == 'average') {
$output['rating'] = $result['value'];
}
elseif ($widget->value_type == 'points' && $result['function'] == 'sum') {
$output['rating'] = $result['value'];
}
elseif ($result['function'] == 'count') {
$output['count'] = $result['value'];
}
elseif (preg_match('/^option\\-([\\-0-9]+)$/', $result['function'], $match)) {
$output['options'][$match[1]] = $result['value'];
$output['count'] += $result['value'];
}
}2 issues with this block of core are:
A) With the criteria specified here, VotingAPI returns 3 results: One for each value type (sum, count, average).
B) Since we're looping through doing $output['rating'] = $result['value']; each time, we're just overwriting the value.
My sense is we should store the desired default vote result function in the widget definition. Based on the README and the code flow, it appears that Rate intends to support the VotingAPI 'sum' function, however, "Average" is the only VotingAPI function listed for the "Which rating should be displayed" setting.
It would be great to get some validation from the Rate maintainer that this is in fact a bug and that we're not dealing with misconfiguration here :).
Comments
Comment #0.0
ezra-g commentedUse php format.
Comment #1
japerryI'm fairly certain we're dealing with a configuration issue here. One of the issues is that the administrative options says 'average' and 'user' when displaying points. What it should mean is "aggregated points" and "user points". The widget itself dictates whether we're summing, averaging, or counting the votes.
The code snippet above does a loop through the different resultset from votingapi cache. There is usually 3 results for each, the sum, count, avg. Only one of these if functions should fire since we have the commons widget set to 'points'. There is no overriding here.
To fix the issue for commons, we need to re-export the feature with the configuration set to average instead of users vote. Also, I suggest that the maintainers of Rate change the description from average to something more inclusive of the other voteapi options that could be set.
Comment #1.0
japerryMissing B ;).
Comment #2
ivnishDrupal 7 is EOL. Issue will be closed