Feature_1255:

- bug fix : function pwg_db_get_recent_period_expression
- add extra fields for select based on "order by"

git-svn-id: http://piwigo.org/svn/trunk@4387 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
nikrou 2009-11-29 14:06:16 +00:00
commit ad796f152f
4 changed files with 24 additions and 27 deletions

View file

@ -458,23 +458,14 @@ function do_maintenance_all_tables()
}
}
function pwg_db_get_recent_period_expression($period, $date='CURRENT_DATE')
function pwg_db_concat_ws($string, $separaor)
{
if ($date!='CURRENT_DATE')
{
$date = '\''.$date.'\'';
}
return 'SUBDATE('.$date.',INTERVAL '.$period.' DAY)';
return 'CONCAT_WS(\''.$separaor.'\','. $string.')';
}
function pwg_db_get_recent_period($period, $date='CURRENT_DATE')
function pwg_db_cast_to_text($string)
{
$query = '
SELECT '.pwg_db_get_recent_period_expression($period);
list($d) = pwg_db_fetch_row(pwg_query($query));
return $d;
return 'CAST('.$string.' AS CHAR)';
}
/**

View file

@ -32,6 +32,18 @@ include_once( PHPWG_ROOT_PATH .'include/functions_url.inc.php' );
include_once( PHPWG_ROOT_PATH .'include/functions_plugins.inc.php' );
//----------------------------------------------------------- generic functions
function get_extra_fiels($order_by_fields)
{
$fields = str_ireplace(array(' order by ', ' desc', ' asc'),
array('', '', ''),
$order_by_fields
);
if (!empty($fields))
{
$fields = ','.$fields;
}
return $fields;
}
// The function get_moment returns a float value coresponding to the number
// of seconds since the unix epoch (1st January 1970) and the microseconds

View file

@ -49,8 +49,7 @@ SELECT tag_id, COUNT(DISTINCT(it.image_id)) counter
'
WHERE'
).'
GROUP BY tag_id
ORDER BY NULL';
GROUP BY tag_id';
$tag_counters = simple_hash_from_query($query, 'tag_id', 'counter');
if ( empty($tag_counters) )
@ -234,18 +233,13 @@ SELECT t.*, count(*) counter
AND tag_id NOT IN ('.implode(',', $excluded_tag_ids).')';
}
$query .='
GROUP BY tag_id';
GROUP BY tag_id, t.id, t.name, t.url_name';
if ($max_tags>0)
{
$query .= '
ORDER BY counter DESC
LIMIT '.$max_tags;
}
else
{
$query .= '
ORDER BY NULL';
}
$result = pwg_query($query);
$tags = array();

View file

@ -292,7 +292,7 @@ SELECT id
// Main query
$query = '
SELECT DISTINCT(image_id)
SELECT DISTINCT(image_id)'.get_extra_fields($conf['order_by']).'
FROM '.IMAGE_CATEGORY_TABLE.'
INNER JOIN '.IMAGES_TABLE.' ON id = image_id
WHERE
@ -326,7 +326,7 @@ else
if (!empty($items) )
{
$query = '
SELECT DISTINCT image_id
SELECT DISTINCT image_id'.get_extra_fields($conf['order_by']).'
FROM '.IMAGE_CATEGORY_TABLE.' INNER JOIN '.IMAGES_TABLE.' ON image_id=id
WHERE image_id IN ('.implode(',', $items).')
'.$forbidden.
@ -443,7 +443,7 @@ SELECT image_id
}
$query = '
SELECT DISTINCT(id)
SELECT DISTINCT(id)'.get_extra_fields($conf['order_by'].'
FROM '.IMAGES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
WHERE
@ -481,7 +481,7 @@ SELECT DISTINCT(id)
$page['super_order_by'] = true;
$conf['order_by'] = ' ORDER BY hit DESC, file ASC';
$query = '
SELECT DISTINCT(id)
SELECT DISTINCT(id), hit, file
FROM '.IMAGES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
WHERE hit > 0
@ -508,7 +508,7 @@ SELECT DISTINCT(id)
$conf['order_by'] = ' ORDER BY average_rate DESC, id ASC';
$query ='
SELECT DISTINCT(id)
SELECT DISTINCT(id), average_rate
FROM '.IMAGES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
WHERE average_rate IS NOT NULL
@ -531,7 +531,7 @@ SELECT DISTINCT(id)
else if ($page['section'] == 'list')
{
$query ='
SELECT DISTINCT(id)
SELECT DISTINCT(id)'.get_extra_fields($conf['order_by'].'
FROM '.IMAGES_TABLE.'
INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
WHERE image_id IN ('.implode(',', $page['list']).')