diff options
author | rvelices <rv-github@modusoptimus.com> | 2006-02-15 02:29:26 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2006-02-15 02:29:26 +0000 |
commit | 33485fa91b5f4849c4cd3122a8e4a544990f34f1 (patch) | |
tree | f1b3ae40ec028075258ea321d1329a89148d1708 /admin/include/functions.php | |
parent | f328dd14bba142c256dbd2ff47713ec6813c07c2 (diff) |
feature 288: manage rates for administrators
git-svn-id: http://piwigo.org/svn/trunk@1042 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin/include/functions.php')
-rw-r--r-- | admin/include/functions.php | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php index 7a82ae3ec..25bbadf84 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -1311,19 +1311,23 @@ UPDATE '.IMAGES_TABLE.' /** * update images.average_rate field - * + * param int $element_id optional, otherwise applies to all * @return void */ -function update_average_rate() +function update_average_rate( $element_id=-1 ) { $average_rates = array(); $query = ' SELECT element_id, ROUND(AVG(rate),2) AS average_rate - FROM '.RATE_TABLE.' - GROUP BY element_id -;'; + FROM '.RATE_TABLE; + if ( $element_id != -1 ) + { + $query .= ' WHERE element_id=' . $element_id; + } + $query .= ' GROUP BY element_id;'; + $result = pwg_query($query); while ($row = mysql_fetch_array($result)) { @@ -1343,6 +1347,17 @@ SELECT element_id, } $fields = array('primary' => array('id'), 'update' => array('average_rate')); mass_updates(IMAGES_TABLE, $fields, $datas); + + $query=' +UPDATE '.IMAGES_TABLE .' + LEFT JOIN '.RATE_TABLE.' ON id=element_id + SET average_rate=NULL + WHERE element_id IS NULL'; + if ( $element_id != -1 ) + { + $query .= ' AND id=' . $element_id; + } + pwg_query($query); } /** |