Create an aggregated score

arthurf - September 21, 2007 - 16:52
Project:NodeReview
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

I have a use case where I want each of the review axes, but I also want an aggregated score for the node. This is helpful for sorting, etc. I'm not providing a patch here as I'm guessing the quick way I went about this is maybe not the prefered way, however, I am including the code. In nodereview_save_reviews() in nodereview_node_nodereview.inc

<?php
 
foreach ($node->reviews as $aid => $review) {
   
// Save the text review
   
db_query("INSERT INTO {nodereview_reviews} (nid, aid, review) VALUES (%d, %d, '%s')", $node->nid, $aid, $review['review']);

   
// And use the votingapi to save the score
   
$votes[] = (object)array('value'=>$review['score'], 'tag'=>$axes[$aid]);
   
   
// build total score
   
$total_score = $total_score + $review['score'];
  }
 
 
$total_score = intval( $total_score / count($node->reviews));
 
 
$votes[] = (object) array('value'=>$total_score, 'tag' => t('vote'));
 
 
votingapi_set_vote('node', $node->reviewed_nid, $votes, $node->uid);
}
?>

All this code does is add each review axes value together and then divide by the total number. The "total" value is stored in the "vote" container which seems to be standard in votingapi, so no other code needs to be written.

#1

Fayna - June 25, 2008 - 14:59

Maybe you can help in this issue:
http://drupal.org/node/104997

There is already a patch there.

 
 

Drupal is a registered trademark of Dries Buytaert.