I have a content type with a fivestar field attached. Anonymous users don't have the 'rate content' permission and cannot see the rating of the content when they should be able to.

The theme_fivestar_function gets passed a rating of 'f' which is obviously not correct and without knowing the module it's hard to know where that's coming from and why it isn't even a number!

CommentFileSizeAuthor
#5 fivestar-see-avarage-1247368-5.diff804 bytesjm.federico

Comments

iajay’s picture

subscribe

alonk27’s picture

subscribe

Toxid’s picture

I've Identified the function where the numbers are supposed to come from. In fivestar.field.inc line 347 there's a function called fivestar_field_formatter_view. At line 376 it calls drupal_get_form('fivestar_custom_widget', $values, $settings);. If the user doesn't have rate content permission, the drupal_get_form isn't called and therefore no rating value is loaded.
That's how far I got, but I'm not very familiar with the theme functions so I don't know how to make a static display.

jm.federico’s picture

The solution to this problem is to add

  if ($instance['widget']['type'] == 'exposed') {
    $tag = (isset($field['settings']['axis'])) ? $field['settings']['axis'] : 'vote';
    list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
    $votes = fivestar_get_votes($entity_type, $id, $tag);
    $element[0]['#item'] = array(
      0 => array(
        'rating' => $values['average'] = isset($votes['average']['value']) ? $votes['average']['value'] : 0,
      ),
    );
  }

in line 386, just before the return.

jm.federico’s picture

Status: Active » Needs review
StatusFileSize
new804 bytes

attachign patch

alonk27’s picture

Works!!! Thanks!!!

Toxid’s picture

Great! Now it's just the matter of getting the text to show as well. I tried to add this code just before the closing tag:

<?php
$element[0]['vote']['#description'] = $settings['style'] == 'dual' ? NULL : theme('fivestar_summary', array(
    'average_rating' => $values['average'],
    'votes' => $values['count'],
    'stars' => $instance['settings']['stars']
  )
);
?>

It generates the right output, but I think I placed it in the wrong key. Unfortunately I can't seem to find the right one. The authenticated fivestar form uses that key so I thought it would be right.

ericduran’s picture

tagging

mjpa’s picture

Status: Needs review » Needs work

This issue appears to be fixed in the -dev release as of today (and I guess the alpha1 release).

However, the value displayed is different depending on if you have the rate content permission or not.

The average vote for a node I have is 66.667. With the rate content permission, I see 4/5 stars - which is wrong. Without the rate content permission, I see 3 and a bit stars - which is correct.

whiteph’s picture

Issue summary: View changes
Status: Needs work » Closed (works as designed)