View Single Post
Old 07-23-2014, 04:51 PM   #943
micster
Enthusiast
micster began at the beginning.
 
Posts: 39
Karma: 10
Join Date: May 2012
Device: none
Half Star Ratings

I don't think this has been mentioned before, but half-star ratings do not display correctly. It rounds the ".5" value up and then you get a rating out of six stars instead of five i.e. ★★★★☆☆

I'm using an older version of COPS but the bug appears to be in the latest cops-1.0.0RC1 also. The culprit seems to be the getRating() function around line 250 of book.php

Find this...
PHP Code:
public function getRating () {
    if (
is_null ($this->rating) || $this->rating == 0) {
        return 
"";
    }
    
$retour "";
    for (
$i 0$i $this->rating 2$i++) {
        
$retour .= "★";
    }
    for (
$i 0$i $this->rating 2$i++) {
        
$retour .= "☆";
    }
    return 
$retour;

I added my own variable that rounds all ratings down...
PHP Code:
public function getRating () {
    
$myrating floor(($this->rating)/2);
    
    if (
is_null ($myrating) || $myrating == 0) {
        return 
"";
    }
    
$retour "";
    for (
$i 0$i $myrating$i++) {
        
$retour .= "★";
    }
    for (
$i 0$i $myrating$i++) {
        
$retour .= "☆";
    }
    return 
$retour;

There is probably some clever PHP way for dealing with floats that would give you a half-star rating, but I'm not a programmer. I'm not even sure that my hack is a good fix.

I just wanted a five star rating and I don't mind if my ratings get rounded down (they could just as easily be rounded up instead) so this works for me.
micster is offline   Reply With Quote