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

demon326 - July 26, 2009 - 11:13
Project:Fivestar
Version:6.x-1.18
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:closed
Description

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 :)

#1

FL4PJ4CK - August 12, 2009 - 19:05

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

line 297 is "}"...

#2

ezra-g - August 27, 2009 - 21:11
Status:active» needs review

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?

AttachmentSize
fivestar-531200.patch 901 bytes

#3

demon326 - August 29, 2009 - 14:51

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

#4

ezra-g - August 31, 2009 - 17:03

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

#5

demon326 - August 31, 2009 - 20:42

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'];
   }

#6

ezra-g - September 10, 2009 - 13:55

@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.

#7

ezra-g - October 4, 2009 - 15:27

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

AttachmentSize
fivestar-531200-a.patch 901 bytes

#8

ezra-g - October 5, 2009 - 01:06
Status:needs review» fixed

This is now committed.

#9

pescobar - October 16, 2009 - 19:19

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?

#10

ezra-g - October 16, 2009 - 20:35

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

#11

System Message - October 30, 2009 - 20:40
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.