I want to have multiple axis comment reviews for nodes.
Example - rate a restaurant by the following criteria: food, drinks, atmosphere, location.
I want to order the nodes in a view according to the average vote.
Questions:
- How can I setup the views relationship and fields to order nodes by total rating?
- Should I create a separate vote tag in fivestar settings for each axis?
- Is this possible out of the box with fivestar for D7?
UPDATE
To illustrate better the problem, here are the screenshots and exact numbers I'm getting.
Views settings
Views output
Calculations from reviews
UPDATE 2
Thanks to everyone who posted here.
I'm still not able to aggregate the votes correctly but I think it's due to some settings in views.
I will award the bounty and post the code/solution I used as soon as I solve it completely. I think Ayesh and junedkazi gave the correct answer saying almost the same thing. Will confirm when I solve it completely.
FINAL UPDATE
The votes are not aggregated on the nodes properly. Custom module is calculating the "overall" value for each comment and that works as it should. But when the fivestar/votingapi calculates the votes for parent node on node view page and on views listing page, it does not work. It takes into consideration only the last review, and not the rest.
Just in case, here's the calculating code I'm using in a custom module:
/**
* Implements hook_comment_presave().
*/
function MYMODULE_comment_presave($comment) {
// Keep these as separate variables so the code doesn't have to be
// updated if the number of axis has been changed from admin.
$axis_count = 0;
$rating_sum = 0;
// Go through all elements and check if this is a rating field.
// Avoid hardcoding the field names (except the overall field).
foreach ($comment as $element_id => $element) {
if (is_array($element) && isset($element[LANGUAGE_NONE][0]['rating'])) {
$rating_sum += $element[LANGUAGE_NONE][0]['rating'];
$axis_count++;
}
}
// Trim out eventual weird decimals
$overall = number_format($rating_sum / $axis_count, 0);
// Save the value in the overall field
$comment->field_overall[LANGUAGE_NONE][0]['rating'] = $overall;
}
Please if anyone has any ideas I'd be really thankful. Even though the bounty expired, I will award it for a working solution (I don't care about the points).