Ignore:
Timestamp:
Jan 2, 2014, 12:51:58 PM (10 years ago)
Author:
plg
Message:

bug 3015 fixed: remove "manage album photos" from cat_list to avoid
misunderstanding with "photos sort order".

Add infos on album manager: number of photos and sub-albums

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/cat_list.php

    r25975 r26399  
    252252// get the categories containing images directly
    253253$categories_with_images = array();
    254 if ( count($categories) )
     254if (count($categories))
    255255{
    256256  $query = '
    257 SELECT DISTINCT category_id
     257SELECT
     258    category_id,
     259    COUNT(*) AS nb_photos
    258260  FROM '.IMAGE_CATEGORY_TABLE.'
    259   WHERE category_id IN ('.implode(',', array_keys($categories)).')';
    260   $categories_with_images = array_flip( array_from_query($query, 'category_id') );
     261  GROUP BY category_id
     262;';
     263  // WHERE category_id IN ('.implode(',', array_keys($categories)).')
     264
     265  $nb_photos_in = query2array($query, 'category_id', 'nb_photos');
     266
     267  $query = '
     268SELECT
     269    id,
     270    uppercats
     271  FROM '.CATEGORIES_TABLE.'
     272;';
     273  $all_categories = query2array($query, 'id', 'uppercats');
     274  $subcats_of = array();
     275
     276  foreach (array_keys($categories) as $cat_id)
     277  {
     278    foreach ($all_categories as $id => $uppercats)
     279    {
     280      if (preg_match('/(^|,)'.$cat_id.',/', $uppercats))
     281      {
     282        @$subcats_of[$cat_id][] = $id;
     283      }
     284    }
     285  }
     286
     287  $nb_sub_photos = array();
     288  foreach ($subcats_of as $cat_id => $subcat_ids)
     289  {
     290    $nb_photos = 0;
     291    foreach ($subcat_ids as $id)
     292    {
     293      if (isset($nb_photos_in[$id]))
     294      {
     295        $nb_photos+= $nb_photos_in[$id];
     296      }
     297    }
     298
     299    $nb_sub_photos[$cat_id] = $nb_photos;
     300  }
    261301}
    262302
     
    290330          'admin_cat_list'
    291331          ),
     332      'NB_PHOTOS' => isset($nb_photos_in[$category['id']]) ? $nb_photos_in[$category['id']] : 0,
     333      'NB_SUB_PHOTOS' => isset($nb_sub_photos[$category['id']]) ? $nb_sub_photos[$category['id']] : 0,
     334      'NB_SUB_ALBUMS' => isset($subcats_of[$category['id']]) ? count($subcats_of[$category['id']]) : 0,
    292335      'ID'         => $category['id'],
    293336      'RANK'       => $category['rank']*10,
     
    318361  }
    319362
    320   if ( array_key_exists($category['id'], $categories_with_images) )
    321   {
    322     $tpl_cat['U_MANAGE_ELEMENTS']=
    323       $base_url.'batch_manager&filter=album-'.$category['id'];
    324   }
    325 
    326363  $template->append('categories', $tpl_cat);
    327364}
Note: See TracChangeset for help on using the changeset viewer.