aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2004-11-15 21:42:08 +0000
committerplegall <plg@piwigo.org>2004-11-15 21:42:08 +0000
commit2d0f0f03ba9d467c314f7ef7f06b5cb52f88c3d2 (patch)
treea9ceef3352103455690f6802c1252cb727e9ddfe
parent88e4e1e60adf660651f9276ab2b19bffcc72d9d3 (diff)
- since categories.site_id can be NULL (for virtual categories), virtual
categories could not be displayed because of a join query with sites table - get_cat_info function refactored - new function get_subcat_ids based on regular expression query git-svn-id: http://piwigo.org/svn/trunk@603 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--include/functions_category.inc.php87
1 files changed, 63 insertions, 24 deletions
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index ffbabbe35..15cb21d16 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -306,41 +306,47 @@ function count_user_total_images()
*/
function get_cat_info( $id )
{
- $infos = array( 'nb_images','id_uppercat','comment','site_id','galleries_url'
- ,'dir','date_last','uploadable','status','visible'
- ,'representative_picture_id','uppercats','commentable' );
-
- $query = 'SELECT '.implode( ',', $infos );
- $query.= ' FROM '.CATEGORIES_TABLE.' AS a';
- $query.= ', '.SITES_TABLE.' AS b';
- $query.= ' WHERE a.id = '.$id;
- $query.= ' AND a.site_id = b.id';
- $query.= ';';
- $row = mysql_fetch_array( pwg_query( $query ) );
+ $infos = array('nb_images','id_uppercat','comment','site_id'
+ ,'dir','date_last','uploadable','status','visible'
+ ,'representative_picture_id','uppercats','commentable');
+
+ $query = '
+SELECT '.implode(',', $infos).'
+ FROM '.CATEGORIES_TABLE.'
+ WHERE id = '.$id.'
+;';
+ $row = mysql_fetch_array(pwg_query($query));
$cat = array();
- // affectation of each field of the table "config" to an information of the
- // array $cat.
- foreach ( $infos as $info ) {
- if ( isset( $row[$info] ) ) $cat[$info] = $row[$info];
- else $cat[$info] = '';
+ foreach ($infos as $info)
+ {
+ if (isset($row[$info]))
+ {
+ $cat[$info] = $row[$info];
+ }
+ else
+ {
+ $cat[$info] = '';
+ }
// If the field is true or false, the variable is transformed into a
// boolean value.
- if ( $cat[$info] == 'true' or $cat[$info] == 'false' )
+ if ($cat[$info] == 'true' or $cat[$info] == 'false')
{
$cat[$info] = get_boolean( $cat[$info] );
}
}
- $cat['comment'] = nl2br( $cat['comment'] );
+ $cat['comment'] = nl2br($cat['comment']);
$cat['name'] = array();
- $query = 'SELECT name,id FROM '.CATEGORIES_TABLE;
- $query.= ' WHERE id IN ('.$cat['uppercats'].')';
- $query.= ' ORDER BY id ASC';
- $query.= ';';
- $result = pwg_query( $query );
- while( $row = mysql_fetch_array( $result ) )
+ $query = '
+SELECT name,id
+ FROM '.CATEGORIES_TABLE.'
+ WHERE id IN ('.$cat['uppercats'].')
+ ORDER BY id ASC
+;';
+ $result = pwg_query($query);
+ while($row = mysql_fetch_array($result))
{
$cat['name'][$row['id']] = $row['name'];
}
@@ -952,4 +958,37 @@ function display_select_categories($categories,
}
}
}
+
+/**
+ * returns all subcategory identifiers of given category ids
+ *
+ * @param array ids
+ * @return array
+ */
+function get_subcat_ids($ids)
+{
+ $query = '
+SELECT DISTINCT(id)
+ FROM '.CATEGORIES_TABLE.'
+ WHERE ';
+ foreach ($ids as $num => $category_id)
+ {
+ if ($num > 0)
+ {
+ $query.= '
+ OR ';
+ }
+ $query.= 'uppercats REGEXP \'(^|,)'.$category_id.'(,|$)\'';
+ }
+ $query.= '
+;';
+ $result = pwg_query($query);
+
+ $subcats = array();
+ while ($row = mysql_fetch_array($result))
+ {
+ array_push($subcats, $row['id']);
+ }
+ return $subcats;
+}
?>