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

  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.

CommentFileSizeAuthor
#4 Another Story | test6.com_.png19.79 KBdanielhonrade

Comments

Fayna’s picture

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

There is already a patch there.

danielhonrade’s picture

Status: Active » Closed (won't fix)

This won't be fixed anymore or replicate to verify this issue, we just have to move forward and making version 6 stable and create version 7 dev.

Crell’s picture

Version: 5.x-1.x-dev » 6.x-1.x-dev
Status: Closed (won't fix) » Active

This is still a valid feature request for later versions.

danielhonrade’s picture

Status: Active » Needs review
StatusFileSize
new19.79 KB

Hi Crell,

I added this feature already on the recent dev

<?php
/**
* Implementation of hook_nodeapi().
*/
function nodereview_nodeapi(&$node, $op, $teaser, $page) {
  global $user;
  switch ($op) {
  // The 'view' operation means the node is about to be displayed.
  case 'view':
  
    // Abort if it's not a page
    if (!$page) { 
      break; 
    }

    // Should only appear and process on content type with review.
    if (variable_get('nodereview_use_' . $node->type, 0)) { 
    
      //Get node id, tags and value for this node
      $result = db_query("SELECT content_id, tag, value FROM {votingapi_vote} WHERE content_id = %d", $node->nid);  
    
      $votes = array();   
      $total_value = '';                                               
      
      while ($record = db_fetch_object($result)) {
        $thisnode[] = $record->content_id;
        $total_value += $record->value;
        $all_tags[$record->tag] = 1;
      } 
      if (!empty($total_value)) {   
        $total = round($total_value / count($thisnode));

        if (NODEREVIEW_FIVESTAR_ENABLE) {
          $total = $total . '%';
        }
        else {
          $total = $total / 10;
        }
        $node->content['review_total'] = array(
          '#prefix' => '<div class="box nodereview-average-rating"><h2><span class="label">Average Review Rating:</span> ',
          '#suffix' => '</h2><h3>Total Reviews: ' . count($thisnode) / count($all_tags) . '</h3></div> ',
          '#value' => $total, 
          '#weight' => 0,
        );
 
        break; 
      }
    }   
    break;
  }
}
?>
danielhonrade’s picture

this is probably a duplicate of this issue http://drupal.org/node/104997

danielhonrade’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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