From 4e4dc79e5162a7d1315b12e94153443552530b9e Mon Sep 17 00:00:00 2001 From: rvelices Date: Mon, 25 Jul 2011 18:04:50 +0000 Subject: 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 --- admin/include/functions.php | 61 --------------------------------------------- 1 file changed, 61 deletions(-) (limited to 'admin/include/functions.php') diff --git a/admin/include/functions.php b/admin/include/functions.php index cd03a662e..2c9c9df39 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -1050,67 +1050,6 @@ UPDATE '.IMAGES_TABLE.' } } -/** - * update images.average_rate field - * param int $element_id optional, otherwise applies to all - * @return void - */ -function update_average_rate( $element_id=-1 ) -{ - $query = ' -SELECT element_id, - ROUND(AVG(rate),2) AS average_rate - FROM '.RATE_TABLE; - if ( $element_id != -1 ) - { - $query .= ' WHERE element_id=' . $element_id; - } - $query .= ' GROUP BY element_id;'; - - $result = pwg_query($query); - - $datas = array(); - - while ($row = pwg_db_fetch_assoc($result)) - { - array_push( - $datas, - array( - 'id' => $row['element_id'], - 'average_rate' => $row['average_rate'] - ) - ); - } - - mass_updates( - IMAGES_TABLE, - array( - 'primary' => array('id'), - 'update' => array('average_rate') - ), - $datas - ); - - $query=' -SELECT id FROM '.IMAGES_TABLE .' - LEFT JOIN '.RATE_TABLE.' ON id=element_id - WHERE element_id IS NULL AND average_rate IS NOT NULL'; - if ( $element_id != -1 ) - { - $query .= ' AND id=' . $element_id; - } - $to_update = array_from_query( $query, 'id'); - - if ( !empty($to_update) ) - { - $query=' -UPDATE '.IMAGES_TABLE .' - SET average_rate=NULL - WHERE id IN (' . implode(',',$to_update) . ')'; - pwg_query($query); - } -} - /** * change the parent category of the given categories. The categories are * supposed virtual. -- cgit v1.2.3