Skip to content

Commit

Permalink
Feature_1255:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
nikrou committed Nov 29, 2009
1 parent c960975 commit ad796f1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
17 changes: 4 additions & 13 deletions include/dblayer/functions_mysql.inc.php
Expand Up @@ -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)';
}

/**
Expand Down
12 changes: 12 additions & 0 deletions include/functions.inc.php
Expand Up @@ -32,6 +32,18 @@
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
Expand Down
10 changes: 2 additions & 8 deletions include/functions_tag.inc.php
Expand Up @@ -49,8 +49,7 @@ function get_available_tags()
'
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) )
Expand Down Expand Up @@ -234,18 +233,13 @@ function get_common_tags($items, $max_tags, $excluded_tag_ids=null)
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();
Expand Down
12 changes: 6 additions & 6 deletions include/section_init.inc.php
Expand Up @@ -292,7 +292,7 @@

// 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
Expand Down Expand Up @@ -326,7 +326,7 @@
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.
Expand Down Expand Up @@ -443,7 +443,7 @@
}

$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
Expand Down Expand Up @@ -481,7 +481,7 @@
$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
Expand All @@ -508,7 +508,7 @@
$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
Expand All @@ -531,7 +531,7 @@
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']).')
Expand Down

0 comments on commit ad796f1

Please sign in to comment.