aboutsummaryrefslogtreecommitdiffstats
path: root/include/ws_functions.inc.php
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2011-07-25 18:04:50 +0000
committerrvelices <rv-github@modusoptimus.com>2011-07-25 18:04:50 +0000
commit4e4dc79e5162a7d1315b12e94153443552530b9e (patch)
treefeec6972f3ff9eb108ce87fe672414b98da69a85 /include/ws_functions.inc.php
parent86bc4d1143474dcb5b9a65c1affd62d7e1b14c0c (diff)
feature 2384: improve average rating calculation (still need to update language files)
git-svn-id: http://piwigo.org/svn/trunk@11827 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/ws_functions.inc.php12
1 files changed, 9 insertions, 3 deletions
diff --git a/include/ws_functions.inc.php b/include/ws_functions.inc.php
index 68e90f81a..04e0dbbf3 100644
--- a/include/ws_functions.inc.php
+++ b/include/ws_functions.inc.php
@@ -781,14 +781,20 @@ SELECT id, name, permalink, uppercats, global_rank, commentable
$related_tags[$i]=$tag;
}
//------------------------------------------------------------- related rates
- $query = '
+ $rating = array('score'=>$image_row['average_rate'], 'count'=>0, 'average'=>null);
+ if (isset($rating['score']))
+ {
+ $query = '
SELECT COUNT(rate) AS count
, ROUND(AVG(rate),2) AS average
FROM '.RATE_TABLE.'
WHERE element_id = '.$image_row['id'].'
;';
- $rating = pwg_db_fetch_assoc(pwg_query($query));
- $rating['count'] = (int)$rating['count'];
+ $row = pwg_db_fetch_assoc(pwg_query($query));
+ $rating['score'] = (float)$rating['score'];
+ $rating['average'] = (float)$row['average'];
+ $rating['count'] = (int)$row['count'];
+ }
//---------------------------------------------------------- related comments
$related_comments = array();