mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-06-02 04:15:05 +02:00
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
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user