Changeset 22879


Ignore:
Timestamp:
May 26, 2013, 9:56:31 PM (11 years ago)
Author:
rvelices
Message:

bug 2097: wrong number of sub-albums
bug 2098: make number of direct sub-albums available for each user

Location:
trunk
Files:
1 added
3 edited

Legend:

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

    r21802 r22879  
    3838    max_date_last,
    3939    count_images,
     40    nb_categories,
    4041    count_categories
    4142  FROM '.CATEGORIES_TABLE.' c
     
    120121    if ($conf['representative_cache_on_subcats'] and $row['user_representative_picture_id'] != $image_id)
    121122    {
    122       $user_representative_updates_for[ $user['id'].'#'.$row['id'] ] = $image_id;
     123      $user_representative_updates_for[ $row['id'] ] = $image_id;
    123124    }
    124125
     
    212213          if ($conf['representative_cache_on_level'])
    213214          {
    214             $user_representative_updates_for[ $user['id'].'#'.$category['id'] ] = $image_id;
     215            $user_representative_updates_for[ $category['id'] ] = $image_id;
    215216          }
    216217
     
    247248  $updates = array();
    248249
    249   foreach ($user_representative_updates_for as $user_cat => $image_id)
    250   {
    251     list($user_id, $cat_id) = explode('#', $user_cat);
    252 
    253     array_push(
    254       $updates,
     250  foreach ($user_representative_updates_for as $cat_id => $image_id)
     251  {
     252    $updates[] =
    255253      array(
    256         'user_id' => $user_id,
     254        'user_id' => $user['id'],
    257255        'cat_id' => $cat_id,
    258256        'user_representative_picture_id' => $image_id,
    259         )
    260       );
     257        );
    261258  }
    262259
  • trunk/include/functions_user.inc.php

    r22005 r22879  
    411411          {
    412412            $forbidden_ids[] = $cat['cat_id'];
    413             unset( $user_cache_cats[$cat['cat_id']] );
     413            remove_computed_category($user_cache_cats, $cat);
    414414          }
    415415        }
     
    442442        (
    443443          'user_id', 'cat_id',
    444           'date_last', 'max_date_last', 'nb_images', 'count_images', 'count_categories'
     444          'date_last', 'max_date_last', 'nb_images', 'count_images', 'nb_categories', 'count_categories'
    445445        ),
    446446        $user_cache_cats,
     
    603603}
    604604
    605 /**
    606  * compute data of categories branches (one branch only)
    607  */
    608 function compute_branch_cat_data(&$cats, &$list_cat_id, &$level, &$ref_level)
    609 {
    610   $date = '';
    611   $count_images = 0;
    612   $count_categories = 0;
    613   do
    614   {
    615     $cat_id = array_pop($list_cat_id);
    616     if (!is_null($cat_id))
    617     {
    618       // Count images and categories
    619       $cats[$cat_id]['count_images'] += $count_images;
    620       $cats[$cat_id]['count_categories'] += $count_categories;
    621       $count_images = $cats[$cat_id]['count_images'];
    622       $count_categories = $cats[$cat_id]['count_categories'] + 1;
    623 
    624       if ((empty($cats[$cat_id]['max_date_last'])) or ($cats[$cat_id]['max_date_last'] < $date))
    625       {
    626         $cats[$cat_id]['max_date_last'] = $date;
    627       }
    628       else
    629       {
    630         $date = $cats[$cat_id]['max_date_last'];
    631       }
    632       $ref_level = substr_count($cats[$cat_id]['global_rank'], '.') + 1;
    633     }
    634     else
    635     {
    636       $ref_level = 0;
    637     }
    638   } while ($level <= $ref_level);
    639 
    640   // Last cat updating must be added to list for next branch
    641   if ($ref_level <> 0)
    642   {
    643     $list_cat_id[] = $cat_id;
    644   }
    645 }
    646 
    647 /**
    648  * compute data of categories branches
    649  */
    650 function compute_categories_data(&$cats)
    651 {
    652   $ref_level = 0;
    653   $level = 0;
    654   $list_cat_id = array();
    655 
    656   foreach ($cats as $id => $category)
    657   {
    658     // Compute
    659     $level = substr_count($category['global_rank'], '.') + 1;
    660     if ($level > $ref_level)
    661     {
    662       $list_cat_id[] = $id;
    663     }
    664     else
    665     {
    666       compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level);
    667       $list_cat_id[] = $id;
    668     }
    669     $ref_level = $level;
    670   }
    671 
    672   $level = 1;
    673   compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level);
     605
     606/*update counters with a category removal*/
     607function remove_computed_category(&$cats, $cat)
     608{
     609  if ( isset( $cats[$cat['id_uppercat']] ) )
     610  {
     611    $parent = & $cats[ $cat['id_uppercat'] ];
     612    $parent['nb_categories']--;
     613
     614    do
     615    {
     616
     617      $parent['count_images'] -= $cat['nb_images'];
     618      $parent['count_categories'] -= 1+$cat['count_categories'];
     619
     620      if ( !isset( $cats[$parent['id_uppercat']] ) )
     621        break;
     622      $parent = & $cats[$parent['id_uppercat']];
     623    }
     624    while (true);
     625  }
     626
     627  unset($cats[$cat['cat_id']]);
    674628}
    675629
     
    683637function get_computed_categories(&$userdata, $filter_days=null)
    684638{
    685   $query = 'SELECT c.id AS cat_id, global_rank';
     639  $query = 'SELECT c.id AS cat_id, id_uppercat';
    686640  // Count by date_available to avoid count null
    687641  $query .= ',
     
    714668  {
    715669    $row['user_id'] = $userdata['id'];
     670    $row['nb_categories'] = 0;
    716671    $row['count_categories'] = 0;
    717672    $row['count_images'] = (int)$row['nb_images'];
     
    722677    }
    723678
    724     $cats += array($row['cat_id'] => $row);
    725   }
    726   uasort($cats, 'global_rank_compare');
    727 
    728   compute_categories_data($cats);
     679    $cats[$row['cat_id']] = $row;
     680  }
     681
     682  foreach ($cats as $cat)
     683  {
     684    if ( !isset( $cat['id_uppercat'] ) )
     685      continue;
     686
     687    $parent = & $cats[ $cat['id_uppercat'] ];
     688    $parent['nb_categories']++;
     689
     690    do
     691    {
     692      $parent['count_images'] += $cat['nb_images'];
     693      $parent['count_categories']++;
     694
     695      if ((empty($parent['max_date_last'])) or ($parent['max_date_last'] < $cat['date_last']))
     696      {
     697        $parent['max_date_last'] = $cat['date_last'];
     698      }
     699
     700      if ( !isset( $parent['id_uppercat'] ) )
     701        break;
     702      $parent = & $cats[$parent['id_uppercat']];
     703    }
     704    while (true);
     705    unset($parent);
     706  }
    729707
    730708  if ( isset($filter_days) )
    731709  {
    732     $cat_tmp = $cats;
    733     $cats = array();
    734 
    735     foreach ($cat_tmp as $category)
    736     {
    737       if (!empty($category['max_date_last']))
    738       {
    739         // Re-init counters
    740         $category['count_categories'] = 0;
    741         $category['count_images'] = (int)$category['nb_images'];
    742         // Keep category
    743         $cats[$category['cat_id']] = $category;
    744       }
    745     }
    746     // Compute a second time
    747     compute_categories_data($cats);
     710    foreach ($cats as $category)
     711    {
     712      if (empty($category['max_date_last']))
     713      {
     714        remove_computed_category($cats, $category);
     715      }
     716    }
    748717  }
    749718  return $cats;
  • trunk/install/piwigo_structure-mysql.sql

    r22134 r22879  
    373373  `nb_images` mediumint(8) unsigned NOT NULL default '0',
    374374  `count_images` mediumint(8) unsigned default '0',
     375  `nb_categories` mediumint(8) unsigned default '0',
    375376  `count_categories` mediumint(8) unsigned default '0',
    376377  `user_representative_picture_id` mediumint(8) unsigned default NULL,
Note: See TracChangeset for help on using the changeset viewer.