aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorz0rglub <z0rglub@piwigo.org>2003-09-06 07:22:59 +0000
committerz0rglub <z0rglub@piwigo.org>2003-09-06 07:22:59 +0000
commit377042a27d9d2de8bcadf77ffcfd1e7d48b64add (patch)
tree5fcf0d3b13dde952c1c6e547cc054bcb418e87d7 /include
parent62b25e9118d3377b9cdda37c0a83c88c4e6bcc00 (diff)
- Creation of plain structure if not existing in several functions
- Change in SQL request about restrictions : using "AND category_id NOT IN (x,y,z)" instead of "AND category_id != x AND category_id != y AND category_id != z" - For search and most recent category, using "COUNT(DISTINCT(id))" instead of "COUNT(*)" and using JOIN with image_category table git-svn-id: http://piwigo.org/svn/trunk@67 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/functions_category.inc.php34
1 files changed, 29 insertions, 5 deletions
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index 33b3f92fc..38f9d1408 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -128,6 +128,9 @@ function create_structure( $id_uppercat, $restrictions )
{
global $page;
+ if ( !isset( $page['plain_structure'] ) )
+ $page['plain_structure'] = get_plain_structure();
+
$structure = array();
$ids = get_subcat_ids( $id_uppercat );
foreach ( $ids as $id ) {
@@ -302,6 +305,10 @@ function get_cat_info( $id )
$cat['visible'] = get_boolean( $row['visible'] );
$cat['name'] = array();
+
+ if ( !isset( $page['plain_structure'] ) )
+ $page['plain_structure'] = get_plain_structure();
+
array_push( $cat['name'], $page['plain_structure'][$id]['name'] );
while ( $page['plain_structure'][$id]['id_uppercat'] != '' )
{
@@ -329,6 +336,9 @@ function get_local_dir( $category_id )
{
global $page;
+ if ( !isset( $page['plain_structure'] ) )
+ $page['plain_structure'] = get_plain_structure();
+
// creating the local path : "root_cat/sub_cat/sub_sub_cat/"
$dir = $page['plain_structure'][$category_id]['dir'].'/';
while ( $page['plain_structure'][$category_id]['id_uppercat'] != '' )
@@ -345,6 +355,9 @@ function get_site_url( $category_id )
{
global $page;
+ if ( !isset( $page['plain_structure'] ) )
+ $page['plain_structure'] = get_plain_structure();
+
$query = 'SELECT galleries_url';
$query.= ' FROM '.PREFIX_TABLE.'sites';
$query.= ' WHERE id = '.$page['plain_structure'][$category_id]['site_id'];
@@ -433,8 +446,14 @@ function initialize_category( $calling_page = 'category' )
{
// we must not show pictures of a forbidden category
$restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
- foreach ( $restricted_cats as $restricted_cat ) {
- $where_append.= ' AND category_id != '.$restricted_cat;
+ if ( count( $restricted_cats ) > 0 )
+ {
+ $where_append.= ' AND category_id NOT IN (';
+ foreach ( $restricted_cats as $i => $restricted_cat ) {
+ if ( $i > 0 ) $where_append.= ',';
+ $where_append.= $restricted_cat;
+ }
+ $where_append.= ')';
}
}
// search result
@@ -481,8 +500,10 @@ function initialize_category( $calling_page = 'category' )
$page['where'].= ' )';
$page['where'].= $where_append;
- $query = 'SELECT COUNT(*) AS nb_total_images';
+ $query = 'SELECT COUNT(DISTINCT(id)) AS nb_total_images';
$query.= ' FROM '.PREFIX_TABLE.'images';
+ $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic';
+ $query.= ' ON id = ic.image_id';
$query.= $page['where'];
$query.= ';';
@@ -513,8 +534,10 @@ function initialize_category( $calling_page = 'category' )
$page['where'].= date( 'Y-m-d', $date )."'";
$page['where'].= $where_append;
- $query = 'SELECT COUNT(*) AS nb_total_images';
+ $query = 'SELECT COUNT(DISTINCT(id)) AS nb_total_images';
$query.= ' FROM '.PREFIX_TABLE.'images';
+ $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic';
+ $query.= ' ON id = ic.image_id';
$query.= $page['where'];
$query.= ';';
}
@@ -530,9 +553,10 @@ function initialize_category( $calling_page = 'category' )
$page['nb_image_page'] = $conf['top_number'] - $page['start'];
}
}
-
+
if ( $query != '' )
{
+ echo $query;
$result = mysql_query( $query );
$row = mysql_fetch_array( $result );
$page['cat_nb_images'] = $row['nb_total_images'];