Hi folks, I'm trying to figure out if there is a way to use the rating of the comment itself (vs. the rating of the node) in a View, for filtering/sorting? Does anyone know if this is possible?

Thanks!

DD

Comments

Richard Blackborder’s picture

I can tell you that Fivestar Extra uses the same votingapi backend that Fivestar uses, so you might get best results checking the votingapi module to see if it has support for views.

dubitable’s picture

Hi Likeless,

Sorry, I should have mentioned what I've already tried. First of all, yeah, I can confirm for a fact that you can connect the Voting API stuff to Views; but it seems like there is no ability to pull out the voting *just* for comments and filter/sort on those. So, I guess what I'm really asking is: is there a way to just utilize the ratings on comments in Views, apart from the ratings on Nodes (which I have confirmed I have access to via Views)?

Am I making sense? I know this is a bit convoluted...if it makes it any more clear, what I'm basically trying to do is create a view for "top-rated comments."

Thanks!

Best,
Dave

Richard Blackborder’s picture

I know a fair bit about votingapi, but I'm a long way from being an expert on views. I don't know the answer to your question, sorry.

dubitable’s picture

No problemo. I figured you may know more than I do, just 'cause you've programmed the interface. I'll dig further and see what I can figure out, if I learn anything substantial I'll post it. Thanks for your response, in any case!

Best,
Dave

mr.andrey’s picture

I'm looking for this functionality as well. Node votes are accessible to views through Vote API, but comments do not seem to be. There needs to be a relationship definition that ties them together.

Fivestar module has various views functions:

function fivestar_votingapi_views_formatters($details = array()) {
function fivestar_views_value_display_handler($value, $field, $columns) {
function fivestar_views_widget_compact_handler($value, $field, $columns) {
function fivestar_views_widget_normal_handler($value, $field, $columns) {
function fivestar_views_widget_handler($value, $field, $columns, $summary) {

In particular, the following one defines the relationship:

function fivestar_views_value_display_handler($value, $field, $columns) {
  // Determine number of stars to display
  if ($field->view->base_table == 'node') {
    if (isset($columns->node_type)) {
      $stars = variable_get('fivestar_stars_'. $columns->node_type, 5);
    }
    else {
      $node_type = db_result(db_query("SELECT type FROM {node} WHERE nid = %d", $columns->nid));
      $stars = variable_get('fivestar_stars_'. (!isset($node_type) ? 'default' : $node_type), 5);
    }

    // Find the VotingAPI tag for this field.
    foreach ($field->query->table_queue[$field->relationship]['join']->extra as $votingapi_setting) 
{
      if ($votingapi_setting['field'] == 'tag') {
        $tag = $votingapi_setting['value'];
      }
    }
  }
  else {
    $stars = 5;
    $tag = 'vote';
  }

  return theme('fivestar_static', $value, $stars, $tag);
}

I think this somehow needs to be changed and ported into the Fivestar Extra module to have comments accessible to views.

Best,
Andrey.

Richard Blackborder’s picture

Status: Active » Closed (duplicate)