I added a fivestar field to a CCK content type. The Fivestar rating displays the actual rating when I go to an individual node but in a table view for that CCK type it always shows 5 stars rather than the actual rating.

Comments

quicksketch’s picture

I can't reproduce, could you provide a sample URL or provide more information about your configuration? A list of the exact steps you used to create your type and view (maybe just an export of the view) would be helpful. Thanks!

henrrrik’s picture

Version: 5.x-1.5 » 5.x-1.7

fivestar_value_display_handler use the fivestar_stars_? setting when it calls theme_fivestar_static, so it always defaults to 5 stars.

I made a few changes to the function that fixes the problem. Is this a "proper" way to grab the node type in this context? I'm new to Drupal.

function fivestar_views_value_display_handler($op, $filter, $value, &$query) {
  if ($value === NULL) {
    return $value;
  }
  else {
    $mysql = "SELECT type FROM {node} WHERE nid=%d";
    $type = db_result(db_query($mysql, $query->nid));
    $stars = variable_get('fivestar_stars_'. (!isset($type) ? 'default' : $type), 5);
    return theme('fivestar_static', $value, $stars);
  }
}
henrrrik’s picture

What I meant to say was that fivestar_value_display_handler DOESN'T use the fivestar_stars_* settings...

quicksketch’s picture

Thanks henrrrik, I see the problem now with your explanation.

I'm a little nervous about a SQL query per row, just for the number of stars. I'm suggesting this change (http://drupal.org/node/167781) to VotingAPI's views integration which would allow you to enter into the 'option' field the number of stars you wish to display. If the option is not set, we could fall back on doing the SQL queries as you suggest. What do you think?

henrrrik’s picture

That sounds reasonable.

quicksketch’s picture

Status: Active » Fixed

I committed this fix a while ago but didn't wire up the necessary line to actually display the new stars! Here's the code I settled on:

    // Determine number of stars to display
    if (is_numeric($query->options)) {
      $stars = $query->options;
    }
    elseif (isset($query->node_type)) {
      $stars = variable_get('fivestar_stars_'. $query->node_type, 5);
    }
    else {
      $type = db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $query->nid));
      $stars = variable_get('fivestar_stars_'. (!isset($type) ? 'default' : $type), 5);
    }
    return theme('fivestar_static', $value, $stars);

So it will look first for an option (the VotingAPI patch finally got the green light I believe), then if you've included the node_type field it will use that if available. Finally, if nothing else it'll make the SQL query per row as a last-ditch effort to find the node type. Thanks for your help henrrrik on this and sorry it took so long. It'll be in the 1.9 release, which is growing closer every day.

henrrrik’s picture

Excellent. Thanks!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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