Okay, got that, but now I need to return a percentage based overall_avg, say “percent_avg”, based on the scale parameter. I’ve spent the last 45 min going through the rating stats() but not quite wanting to break it…
... 1 hour later…
I mustered the following change of the rating module:
EDIT: The parts that I changed are commented with //WM
// ----------------------------------------
// Parse graphics
// ----------------------------------------
if ( $scale AND stristr( $key, '_avg' ) )
{
$standard = preg_replace( "/^stars_|^circles_|^bar_|^percent_/", "", $key ); //WM
if ( isset( $this->fields_stats[$this->entry_id][$standard] ) )
{
// ----------------------------------------
// Do some quasi math
// ----------------------------------------
// Get array
$num = explode( ".", number_format( $this->fields_stats[$this->entry_id][$standard], 2, '.', '' ) );
$filler = 0;
// Handle remainder
if ( $num['1'] < 25 )
{
$num['1'] = 0;
}
elseif ( $num['1'] >= 25 AND $num['1'] < 50 )
{
$num['1'] = 25;
}
elseif ( $num['1'] >= 50 AND $num['1'] < 75 )
{
$num['1'] = 50;
}
else
{
$num['1'] = 75;
}
/*
// Handle filler
if ( $num['1'] != 0 AND ( ( $num['0'] + 1 ) > $scale ) )
{
$filler = $scale - 1 - $num['0'];
}
else
{
$filler = $scale - $num['0'];
}
*/
// Handle filler
if ( $num['1'] == 0 )
{
$filler = $scale - $num['0'];
}
else
{
$filler = $scale - 1 - $num['0'];
}
// ----------------------------------------
// Determine type
// ----------------------------------------
if ( eregi( "^circles_", $key ) )
{
$img = '';
$ext = '.gif';
$urlfull = $image_url.'circle-100'.$ext;
$urlrem = $image_url.'circle-'.$num['1'].$ext;
$urlfill = $image_url.'circle-0'.$ext;
$w = '12';
$h = '12';
$type = 'circle';
}
elseif ( eregi( "^bar_", $key ) )
{
$img = '';
$ext = '.gif';
$urlfull = $image_url.'bar-100'.$ext;
$urlrem = $image_url.'bar-'.$num['1'].$ext;
$urlfill = $image_url.'bar-0'.$ext;
$w = '12';
$h = '12';
$type = 'bar';
}
elseif ( eregi( "^percent_", $key ) ) //WM
{
$avg = round($this->fields_stats[$this->entry_id][$standard],2);
$img = round(100 / $scale * $avg);
}
else
{
$img = '';
$ext = '.gif';
$urlfull = $image_url.'star-100'.$ext;
$urlrem = $image_url.'star-'.$num['1'].$ext;
$urlfill = $image_url.'star-0'.$ext;
$w = '12';
$h = '12';
$type = 'star';
}
// ----------------------------------------
// Parse images
// ----------------------------------------
if ( eregi( "^percent_", $key ) ) //WM
{
}else
{
for ( $i = $num['0']; $i > 0; $i-- )
{
$img .= $this->_img( $urlfull, $w, $h, $i, $type );
}
$img .= ( $num['1'] == 0 ) ? '': $this->_img( $urlrem, $w, $h, $i, $type );
for ( $i = $filler; $i > 0; $i-- )
{
$img .= $this->_img( $urlfill, $w, $h, $i, $type );
}
}
$tagdata = $TMPL->swap_var_single( $key, $img, $tagdata );
}
}
}
It works though!!! It takes a scale of (currently only) 7 (just because I added it to your scale check).
I’m quite pleased, but I’m sure there’s an easier way to hack this into the module. Suggestions? Ideas? Thanks Mitchell!