I thought about this afterwards - I think you could do this without modifying the code if you keep the review ratings as 1 to 5 but I just thought this was a bit inconsistent. I wanted to make them all equivalent so I changed all the review ratings to 1 - 10.
To change these you need to:
1. Change the regex in the properties of the rating field for the Reviews table
^\d{1,2}$
2. In Review.pm change all the 5s to 10.
3. In Review.pm find this line and change the * to {1,2}
# Make sure we have a valid rating.
unless (($input->{Review_Rating} =~ /^\d
{1,2}$/) and ($input->{Review_Rating} >= 1) and ($input->{Review_Rating} <= 10))
4. Add this global called average_rating
sub {
my $rec = shift;
my $reviews = $DB->table('Reviews');
my ($review_stats,$review_count);
%$review_stats = map {$_ => $reviews->count({ Review_LinkID => $rec->{ID}, Review_Rating => $_, Review_Validated => 'Yes'})} (1..10);
$review_count = $reviews->count({ Review_LinkID => $rec->{ID}, Review_Validated => 'Yes'} );
my $average=0;
if ($review_count) {
for (1..10) {
$average=($average+($review_stats->{$_}*$_));
}
$rec->{'Rating'}=(($rec->{'Rating'}*$rec->{'Votes'})+ $average)/($review_count + $rec->{'Votes'});
$rec->{'Votes'}=($rec->{'Votes'}+$review_count);
}
return $rec;
}
5. In your link and detailed templates (and any others you might have created which show the rating) add <%average_rating%> somewhere in the template before you use <%Rating%> or <%Votes%>.
I think that's about it but I may have forgotten something.
Edit: I did forget! Obviously you need to change the review templates to allow the user to choose a rating of 1 to 10.
Edit2: There's also an error message which needs changing at
Build>Language>Reviews Laura.
The UK High Street