aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authornikrou <nikrou@piwigo.org>2009-11-29 14:06:16 +0000
committernikrou <nikrou@piwigo.org>2009-11-29 14:06:16 +0000
commitad796f152f38a37c3c9be438ee9a79ba7b307ebd (patch)
tree4862e6895ff5bee4f38914d942cda31ffa66b7c1 /include
parentc96097529e49943eddba78d70e23e38c0eac494d (diff)
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
Diffstat (limited to '')
-rw-r--r--include/dblayer/functions_mysql.inc.php17
-rw-r--r--include/functions.inc.php12
-rw-r--r--include/functions_tag.inc.php10
-rw-r--r--include/section_init.inc.php12
4 files changed, 24 insertions, 27 deletions
diff --git a/include/dblayer/functions_mysql.inc.php b/include/dblayer/functions_mysql.inc.php
index e47119535..cc5ca3081 100644
--- a/include/dblayer/functions_mysql.inc.php
+++ b/include/dblayer/functions_mysql.inc.php
@@ -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)';
}
/**
diff --git a/include/functions.inc.php b/include/functions.inc.php
index cbf47b50d..8a7c7285c 100644
--- a/include/functions.inc.php
+++ b/include/functions.inc.php
@@ -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
diff --git a/include/functions_tag.inc.php b/include/functions_tag.inc.php
index a05174159..e3018f792 100644
--- a/include/functions_tag.inc.php
+++ b/include/functions_tag.inc.php
@@ -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();
diff --git a/include/section_init.inc.php b/include/section_init.inc.php
index c6576f1ea..e9bb7730a 100644
--- a/include/section_init.inc.php
+++ b/include/section_init.inc.php
@@ -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']).')