A comments vote should not be counted when it is not approved.

Comments

ezra-g’s picture

Version: 6.x-1.13 » 6.x-1.19

Just bumping the version here. Agreed, would be nice to get this fixed and would be fairly trivial to do so.

jsims281’s picture

I had to get this working quickly, so I hacked at the fivestar_get_votes function in fivestar.module.

There might be some bits I have ignored, but this seems to correctly display the right star rating now, and disregards comments which are not published.

This is what works for me (please shout out if you see any mistakes or improvements!):

<?php
function fivestar_get_votes($type, $cid, $tag = 'vote', $uid = NULL) {
  global $user;

  if (!isset($uid)) {
    $uid = $user->uid;
  }

  $criteria = array(
    'content_type' => $type,
    'content_id' => $cid,
    'value_type' => 'percent',
    'tag' => $tag,
  );

  $votes = array(
    'average' => array(),
    'count' => array(),
    'user' => array(),
  );

  $results = votingapi_select_results($criteria);
  foreach ($results as $result) {   
    //get correct node id
    if ( arg(0) == 'node' && is_numeric(arg(1)) && ! arg(2) ) {
      $nid = arg(1);
    }
    
    //select all published comments from this node
    $results = db_query('SELECT cid FROM {comments} WHERE nid = %d and status = 0',$nid);    
    while ($row = db_fetch_object($results)) {
      $comments[] = $row->cid;
      //get all the vote values for this comment
      $fivestar_comment_results = db_query('SELECT value FROM {fivestar_comment} WHERE cid = %d',$row->cid);
      while ($comment_row = db_fetch_object($fivestar_comment_results)) {
        $votes_values[$row->cid] = $comment_row->value;
      }
    }                                                                             
    
    if ($result['function'] == 'average') {
      $votes['average'] = $result;
    }
    if ($result['function'] == 'count') {
      $votes['count'] = $result;
    }                                
  }
  if ($uid) {
    $user_vote = votingapi_select_votes($criteria += array('uid' => $uid));
    if ($user_vote) {
      $votes['user'] = $user_vote[0];
      $votes['user']['function'] = 'user';
    }
  }
  else {
    // If the user is anonymous, we never bother loading their existing votes.
    // Not only would it be hit-or-miss, it would break page caching. Safer to always
    // show the 'fresh' version to anon users.
    $votes['user'] = array('value' => 0);
  }

  if(is_array($votes_values)){
    //quick sum and average of the values we gathered
    $sum = @array_sum($votes_values);
    $average = $sum/@count($votes_values);
  } 
    
  //overwrite the average value from above
  $votes[average][value] = $average;  
  
                                   
  return $votes;
}
?>
codexmas’s picture

Is this still an issue?

MiMe’s picture

I don't know actually... haven't tried the module in a while

halloffame’s picture

Still an issue for me... Not comfortable with editing core but will try @jsims281's function.

halloffame’s picture

@jsims281 function does not work for me...

halloffame’s picture

@jsims281 applied against what version of fivestar?

halloffame’s picture

Applied against 6.x-1.20. Not working...

halloffame’s picture

Version: 6.x-1.19 » 6.x-1.20
whiteph’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

We can no longer support the Drupal 6 version of Fivestar. It is in security maintenance mode only. When the Drupal 8 version of Fivestar is released, the Drupal 6 version will be officially deprecated.

whiteph’s picture