mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-07-06 09:52:29 +02:00
- image rating on picture page done through ajax (tested safari/ie 6&7/ff)
git-svn-id: http://piwigo.org/svn/trunk@2435 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
@@ -36,14 +36,14 @@ function rate_picture($image_id, $rate)
|
||||
or !$conf['rate']
|
||||
or !in_array($rate, $conf['rate_items']))
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$user_anonymous = is_autorize_status(ACCESS_CLASSIC) ? false : true;
|
||||
|
||||
if ($user_anonymous and !$conf['rate_anonymous'])
|
||||
{
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
$ip_components = explode('.', $_SERVER["REMOTE_ADDR"]);
|
||||
@@ -118,17 +118,20 @@ INSERT
|
||||
|
||||
// update of images.average_rate field
|
||||
$query = '
|
||||
SELECT ROUND(AVG(rate),2) AS average_rate
|
||||
SELECT COUNT(rate) AS count
|
||||
, ROUND(AVG(rate),2) AS average
|
||||
, ROUND(STD(rate),2) AS stdev
|
||||
FROM '.RATE_TABLE.'
|
||||
WHERE element_id = '.$image_id.'
|
||||
;';
|
||||
$row = mysql_fetch_array(pwg_query($query));
|
||||
$row = mysql_fetch_assoc(pwg_query($query));
|
||||
$query = '
|
||||
UPDATE '.IMAGES_TABLE.'
|
||||
SET average_rate = '.$row['average_rate'].'
|
||||
SET average_rate = '.$row['average'].'
|
||||
WHERE id = '.$image_id.'
|
||||
;';
|
||||
pwg_query($query);
|
||||
return $row;
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -775,6 +775,41 @@ SELECT id, date, author, content
|
||||
return new PwgNamedStruct('image',$ret, null, array('name','comment') );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* rates the image_id in the parameter
|
||||
*/
|
||||
function ws_images_Rate($params, &$service)
|
||||
{
|
||||
$image_id = (int)$params['image_id'];
|
||||
$query = '
|
||||
SELECT DISTINCT id FROM '.IMAGES_TABLE.'
|
||||
INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
|
||||
WHERE id='.$image_id
|
||||
.get_sql_condition_FandF(
|
||||
array(
|
||||
'forbidden_categories' => 'category_id',
|
||||
'forbidden_images' => 'id',
|
||||
),
|
||||
' AND'
|
||||
).'
|
||||
LIMIT 1';
|
||||
if ( mysql_num_rows( pwg_query($query) )==0 )
|
||||
{
|
||||
return new PwgError(404, "Invalid image_id or access denied" );
|
||||
}
|
||||
$rate = (int)$params['rate'];
|
||||
include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
|
||||
$res = rate_picture( $image_id, $rate );
|
||||
if ($res==false)
|
||||
{
|
||||
global $conf;
|
||||
return new PwgError( 403, "Forbidden or rate not in ". implode(',',$conf['rate_items']));
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns a list of elements corresponding to a query search
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user