Changeset 603 for trunk


Ignore:
Timestamp:
Nov 15, 2004, 10:42:08 PM (20 years ago)
Author:
plg
Message:
  • 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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_category.inc.php

    r602 r603  
    307307function get_cat_info( $id )
    308308{
    309   $infos = array( 'nb_images','id_uppercat','comment','site_id','galleries_url'
    310                   ,'dir','date_last','uploadable','status','visible'
    311                   ,'representative_picture_id','uppercats','commentable' );
    312 
    313   $query = 'SELECT '.implode( ',', $infos );
    314   $query.= ' FROM '.CATEGORIES_TABLE.' AS a';
    315   $query.= ', '.SITES_TABLE.' AS b';
    316   $query.= ' WHERE a.id = '.$id;
    317   $query.= ' AND a.site_id = b.id';
    318   $query.= ';';
    319   $row = mysql_fetch_array( pwg_query( $query ) );
     309  $infos = array('nb_images','id_uppercat','comment','site_id'
     310                 ,'dir','date_last','uploadable','status','visible'
     311                 ,'representative_picture_id','uppercats','commentable');
     312 
     313  $query = '
     314SELECT '.implode(',', $infos).'
     315  FROM '.CATEGORIES_TABLE.'
     316  WHERE id = '.$id.'
     317;';
     318  $row = mysql_fetch_array(pwg_query($query));
    320319
    321320  $cat = array();
    322   // affectation of each field of the table "config" to an information of the
    323   // array $cat.
    324   foreach ( $infos as $info ) {
    325     if ( isset( $row[$info] ) ) $cat[$info] = $row[$info];
    326     else                        $cat[$info] = '';
     321  foreach ($infos as $info)
     322  {
     323    if (isset($row[$info]))
     324    {
     325      $cat[$info] = $row[$info];
     326    }
     327    else
     328    {
     329      $cat[$info] = '';
     330    }
    327331    // If the field is true or false, the variable is transformed into a
    328332    // boolean value.
    329     if ( $cat[$info] == 'true' or $cat[$info] == 'false' )
     333    if ($cat[$info] == 'true' or $cat[$info] == 'false')
    330334    {
    331335      $cat[$info] = get_boolean( $cat[$info] );
    332336    }
    333337  }
    334   $cat['comment'] = nl2br( $cat['comment'] );
     338  $cat['comment'] = nl2br($cat['comment']);
    335339
    336340  $cat['name'] = array();
    337341
    338   $query = 'SELECT name,id FROM '.CATEGORIES_TABLE;
    339   $query.= ' WHERE id IN ('.$cat['uppercats'].')';
    340   $query.= ' ORDER BY id ASC';
    341   $query.= ';';
    342   $result = pwg_query( $query );
    343   while( $row = mysql_fetch_array( $result ) )
     342  $query = '
     343SELECT name,id
     344  FROM '.CATEGORIES_TABLE.'
     345  WHERE id IN ('.$cat['uppercats'].')
     346  ORDER BY id ASC
     347;';
     348  $result = pwg_query($query);
     349  while($row = mysql_fetch_array($result))
    344350  {
    345351    $cat['name'][$row['id']] = $row['name'];
     
    953959  }
    954960}
     961
     962/**
     963 * returns all subcategory identifiers of given category ids
     964 *
     965 * @param array ids
     966 * @return array
     967 */
     968function get_subcat_ids($ids)
     969{
     970  $query = '
     971SELECT DISTINCT(id)
     972  FROM '.CATEGORIES_TABLE.'
     973  WHERE ';
     974  foreach ($ids as $num => $category_id)
     975  {
     976    if ($num > 0)
     977    {
     978      $query.= '
     979    OR ';
     980    }
     981    $query.= 'uppercats REGEXP \'(^|,)'.$category_id.'(,|$)\'';
     982  }
     983  $query.= '
     984;';
     985  $result = pwg_query($query);
     986
     987  $subcats = array();
     988  while ($row = mysql_fetch_array($result))
     989  {
     990    array_push($subcats, $row['id']);
     991  }
     992  return $subcats;
     993}
    955994?>
Note: See TracChangeset for help on using the changeset viewer.