When i set the output to percentage i'l get this error when viewing the node;

warning: Division by zero in C:\wamp\www\ashladan2\sites\all\modules\fivestar\fivestar_field.inc on line 297.

don't think this is good :)

Files: 
CommentFileSizeAuthor
#7 fivestar-531200-a.patch901 bytesezra-g
#2 fivestar-531200.patch901 bytesezra-g

Comments

I've got exactly the same problem. Any ideas?

line 297 is "}"...

Status:Active» Needs review
StatusFileSize
new901 bytes

We can't do any of the calculations without both the rating and # of stars values, so we should probably return 0. Does this patch help?

ezra-g, can you make a simple find an replace for non coder users? thx!

@demon326 -- Check out http://drupal.org/node/323498 for instructions on applying a patch ;). It's not too hard :).

ezra-g, it's not working.. you also forget to add a "}" after the return round(100/$element['#item']['rating'], 1)/$element['#field']['stars']; line, and it stays saying that the above line is the problem..

the full code block:

/* * Theme function for 'percentage' fivestar field formatter.
  */
function theme_fivestar_formatter_percentage($element) {
if (empty($element['#item']['rating']) || empty($element['#item']['stars'])) {
    return 0;
   }
   return round(100/$element['#item']['rating'], 1)/$element['#field']['stars'];
   }

@demon326: Did you actually apply and review this patch? It resolves the issue for me, and there is no missing bracket in the code once it is applied.

StatusFileSize
new901 bytes

Turns out this needed a slight change - to check for empty($element['#field']['stars']) instead of empty($element['#item']['stars'])) .

Status:Needs review» Fixed

This is now committed.

This bug also showed up for me on the search results page when a fivestar-enabled content type was included in the results

however, in my testing on the search results page, the '$element['#field']['stars']' is always empty but '$element['#item']['stars']' always has a value

are there cases where '$element['#field']['stars']' has a value?

maybe if the function is entered in some other page other than search results?

Are you getting this error on the same line as reported in this issue, with the latest dev release?

Status:Fixed» Closed (fixed)

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