Changeset 1624 for trunk/include


Ignore:
Timestamp:
Dec 2, 2006, 12:31:19 AM (18 years ago)
Author:
rub
Message:

Resolved Issue ID 0000299:

o Add (new) icon of parent category with children categories including new images
o Improved display text for images count
o Improved (a little) mass_* functions

More explications on the forum.
You must call directly upgrade_feep.php (http://127.0.0.1/BSF/upgrade_feed.php for example)

Location:
trunk/include
Files:
5 edited

Legend:

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

    r1597 r1624  
    3434if ($page['section']=='recent_cats')
    3535{
     36  // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
    3637  $query = '
    37 SELECT id,name,date_last,representative_picture_id,comment,nb_images,uppercats
    38   FROM '.CATEGORIES_TABLE.'
     38SELECT
     39  id,name, representative_picture_id, comment, nb_images, uppercats,
     40  max_date_last, is_child_date_last, count_images, count_categories
     41  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
     42  ON id = cat_id and user_id = '.$user['id'].'
    3943  WHERE date_last > SUBDATE(
    4044    CURRENT_DATE,INTERVAL '.$user['recent_period'].' DAY
    41   )
    42   AND id NOT IN ('.$user['forbidden_categories'].')';
     45  );';
    4346}
    4447else
    4548{
     49  // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
    4650  $query = '
    47 SELECT id,name,date_last,representative_picture_id,comment,nb_images
    48   FROM '.CATEGORIES_TABLE.'
     51SELECT
     52  id,name, representative_picture_id, comment, nb_images,
     53  max_date_last, is_child_date_last, count_images, count_categories
     54  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
     55  ON id = cat_id and user_id = '.$user['id'].'
    4956  WHERE id_uppercat '.
    5057  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).'
    51     AND id NOT IN ('.$user['forbidden_categories'].')
    5258  ORDER BY rank
    5359;';
     
    6066while ($row = mysql_fetch_assoc($result))
    6167{
     68  $row['is_child_date_last'] = get_boolean($row['is_child_date_last']);
     69
    6270  if (isset($row['representative_picture_id'])
    6371      and is_numeric($row['representative_picture_id']))
     
    146154      {
    147155        $name = $category['name'];
    148         $icon_ts = get_icon(@$category['date_last']);
     156        $icon_ts = get_icon($category['max_date_last'], $category['is_child_date_last']);
    149157      }
    150158
     
    163171              )
    164172            ),
    165           'CAPTION_NB_IMAGES' => (($category['nb_images'] == 0) ? '' : sprintf("%d ".l10n('pictures'), $category['nb_images'])),
     173          'CAPTION_NB_IMAGES' => get_display_images_count
     174                                  (
     175                                    $category['nb_images'],
     176                                    $category['count_images'],
     177                                    $category['count_categories']
     178                                  ),
    166179          'DESCRIPTION' => @$comment,
    167180          'NAME'  => $name,
     
    214227          'thumbnails.line.thumbnail',
    215228          array(
    216             'IMAGE_TS'    => get_icon(@$category['date_last']),
     229            'IMAGE_TS'    => get_icon($category['max_date_last'], $category['is_child_date_last']),
    217230           )
    218231         );
  • trunk/include/constants.php

    r1584 r1624  
    6666define('RATE_TABLE', $prefixeTable.'rate');
    6767define('USER_CACHE_TABLE', $prefixeTable.'user_cache');
     68define('USER_CACHE_CATEGORIES_TABLE', $prefixeTable.'user_cache_categories');
    6869define('CADDIE_TABLE', $prefixeTable.'caddie');
    6970define('UPGRADE_TABLE', $prefixeTable.'upgrade');
  • trunk/include/functions_category.inc.php

    r1573 r1624  
    5353function get_categories_menu()
    5454{
    55   global $page,$user;
    56 
    57   $infos = array('');
    58 
    59   $query = '
    60 SELECT name,id,date_last,nb_images,global_rank
    61   FROM '.CATEGORIES_TABLE.'
    62   WHERE 1 = 1'; // stupid but permit using AND after it !
     55  global $page, $user;
     56
     57  $query = '
     58SELECT ';
     59  // From CATEGORIES_TABLE
     60  $query.= '
     61  name, id, nb_images, global_rank,';
     62  // From USER_CACHE_CATEGORIES_TABLE
     63  $query.= '
     64  max_date_last, is_child_date_last, count_images, count_categories';
     65
     66  // $user['forbidden_categories'] including with USER_CACHE_CATEGORIES_TABLE
     67  $query.= '
     68  FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
     69  ON id = cat_id and user_id = '.$user['id'];
    6370  if (!$user['expand'])
    6471  {
    6572    $query.= '
    66     AND (id_uppercat is NULL';
     73    WHERE (id_uppercat is NULL';
    6774    if (isset($page['category']))
    6875    {
     
    7077    }
    7178    $query.= ')';
    72   }
    73   if ($user['forbidden_categories'] != '')
    74   {
    75     $query.= '
    76     AND id NOT IN ('.$user['forbidden_categories'].')';
    7779  }
    7880  $query.= '
     
    8385  while ($row = mysql_fetch_array($result))
    8486  {
     87    $row['is_child_date_last'] = get_boolean($row['is_child_date_last']);
    8588    array_push($cats, $row);
    8689  }
     
    8992  return get_html_menu_category($cats);
    9093}
     94
    9195
    9296/**
     
    353357  return ($a['rank'] < $b['rank']) ? -1 : 1;
    354358}
     359
     360/**
     361 * returns display text for information images of category
     362 *
     363 * @param array categories
     364 * @return string
     365 */
     366function get_display_images_count($cat_nb_images, $cat_count_images, $cat_count_categories, $short_message = true)
     367{
     368  $display_text = '';
     369
     370  // Count of category is main
     371  // if not picture on categorie, test on sub-categories
     372  $count = ($cat_nb_images > 0 ? $cat_nb_images : $cat_count_images);
     373
     374  if ($count > 0)
     375  {
     376    $display_text.= sprintf(l10n(($count > 1 ? 'images_available' : 'image_available')), $count);
     377
     378    if ($cat_nb_images > 0)
     379    {
     380      if (! $short_message)
     381      {
     382        $display_text.= ' '.l10n('images_available_cpl');
     383      }
     384    }
     385    else
     386    {
     387      $display_text.= ' '.sprintf(l10n(($cat_count_categories > 1 ? 'images_available_cats' : 'images_available_cat')), $cat_count_categories);
     388    }
     389  }
     390
     391  return $display_text;
     392}
     393
    355394?>
  • trunk/include/functions_html.inc.php

    r1606 r1624  
    2525// +-----------------------------------------------------------------------+
    2626
    27 function get_icon($date)
     27function get_icon($date, $is_child_date = false)
    2828{
    2929  global $page, $user, $conf, $lang;
     
    3434  }
    3535
    36   if (isset($page['get_icon_cache'][$date]))
    37   {
    38     return $page['get_icon_cache'][$date];
     36  if (isset($page['get_icon_cache'][$is_child_date][$date]))
     37  {
     38    return $page['get_icon_cache'][$is_child_date][$date];
    3939  }
    4040
     
    4242  {
    4343    // date can be empty, no icon to display
    44     $page['get_icon_cache'][$date] = '';
    45     return $page['get_icon_cache'][$date];
     44    $page['get_icon_cache'][$is_child_date][$date] = '';
     45    return $page['get_icon_cache'][$is_child_date][$date];
    4646  }
    4747
     
    5252      or $unixtime === -1) // PHP prior to 5.1.0
    5353  {
    54     $page['get_icon_cache'][$date] = '';
    55     return $page['get_icon_cache'][$date];
     54    $page['get_icon_cache'][$is_child_date][$date] = '';
     55    return $page['get_icon_cache'][$is_child_date][$date];
    5656  }
    5757
     
    6262  if ( $diff < $user['recent_period'] * $day_in_seconds )
    6363  {
    64     $icon_url = get_themeconf('icon_dir').'/recent.png';
     64    $icon_url = get_themeconf('icon_dir').'/'.($is_child_date ? 'recent_by_child.png' : 'recent.png');
    6565    $title .= $user['recent_period'];
    6666    $title .=  '&nbsp;'.$lang['days'];
     
    7171  }
    7272
    73   $page['get_icon_cache'][$date] = $output;
    74 
    75   return $page['get_icon_cache'][$date];
     73  $page['get_icon_cache'][$is_child_date][$date] = $output;
     74
     75  return $page['get_icon_cache'][$is_child_date][$date];
    7676}
    7777
     
    393393 * HTML code generated uses logical list tags ul and each category is an
    394394 * item li. The paramter given is the category informations as an array,
    395  * used keys are : id, name, nb_images, date_last
     395 * used keys are : id, name, nb_images, max_date_last, is_child_date_last,
     396 * count_images, count_categories
    396397 *
    397398 * @param array categories
     
    454455    $menu.= '>'.$category['name'].'</a>';
    455456
    456     if ($category['nb_images'] > 0)
    457     {
    458       $menu.= "\n".'<span class="menuInfoCat"';
    459       $menu.= ' title="'.$category['nb_images'];
    460       $menu.= ' '.$lang['images_available'].'">';
    461       $menu.= '['.$category['nb_images'].']';
     457    // Count of category is main
     458    // if not picture on categorie, test on sub-categories
     459    if (($category['nb_images'] > 0) or ($category['count_images'] > 0))
     460    {
     461      $menu.= "\n".'<span class="';
     462      $menu.= ($category['nb_images'] > 0 ? "menuInfoCat"
     463                                          : "menuInfoCatByChild").'"';
     464      $menu.= ' title="';
     465      $menu.= ' '.get_display_images_count
     466                  (
     467                    $category['nb_images'],
     468                    $category['count_images'],
     469                    $category['count_categories'],
     470                    false
     471                  ).'">';
     472      $menu.= '['.($category['nb_images'] > 0 ? $category['nb_images']
     473                                              : $category['count_images']).']';
    462474      $menu.= '</span>';
    463       $menu.= get_icon($category['date_last']);
    464     }
     475    }
     476
     477    $menu.= get_icon($category['max_date_last'], $category['is_child_date_last']);
    465478  }
    466479
  • trunk/include/functions_user.inc.php

    r1622 r1624  
    273273        calculate_permissions($userdata['id'], $userdata['status']);
    274274
     275      update_user_cache_categorie($userdata['id'], $userdata['forbidden_categories']);
     276
     277      // Set need update are done
     278      $userdata['need_update'] = false;
     279
    275280      $query = '
    276281SELECT COUNT(DISTINCT(image_id)) as total
     
    289294      $query = '
    290295INSERT INTO '.USER_CACHE_TABLE.'
    291   (user_id,need_update,forbidden_categories,nb_total_images)
     296  (user_id, need_update, forbidden_categories, nb_total_images)
    292297  VALUES
    293   ('.$userdata['id'].',\'false\',\''
     298  ('.$userdata['id'].',\''.boolean_to_string($userdata['need_update']).'\',\''
    294299  .$userdata['forbidden_categories'].'\','.$userdata['nb_total_images'].')
    295300;';
    296301      pwg_query($query);
     302    }
     303
     304    {
    297305    }
    298306  }
     
    438446
    439447  return implode(',', $forbidden_array);
     448}
     449
     450/**
     451 * update data of user_cache_categorie
     452 *
     453 * @param int user_id
     454 * @return null
     455 */
     456function update_user_cache_categorie($user_id, $user_forbidden_categories)
     457{
     458  function compute_branch_cat_data(&$cats, &$list_cat_id, &$level, &$ref_level)
     459  {
     460    $date = '';
     461    $count_images = 0;
     462    $count_categories = 0;
     463    do
     464    {
     465      $cat_id = array_pop($list_cat_id);
     466      if (!is_null($cat_id))
     467      {
     468        // Count images and categories
     469        $cats[$cat_id]['count_images'] += $count_images;
     470        $cats[$cat_id]['count_categories'] += $count_categories;
     471        $count_images = $cats[$cat_id]['count_images'];
     472        $count_categories = $cats[$cat_id]['count_categories'] + 1;
     473
     474        if ((empty($cats[$cat_id]['max_date_last'])) or ($cats[$cat_id]['max_date_last'] < $date))
     475        {
     476          $cats[$cat_id]['max_date_last'] = $date;
     477          $cats[$cat_id]['is_child_date_last'] = true;
     478        }
     479        else
     480        {
     481          $date = $cats[$cat_id]['max_date_last'];
     482        }
     483        $ref_level = substr_count($cats[$cat_id]['global_rank'], '.') + 1;
     484      }
     485      else
     486      {
     487        $ref_level = 0;
     488      }
     489    } while ($level <= $ref_level);
     490
     491    // Last cat updating must be added to list for next branch
     492    if ($ref_level <> 0)
     493    {
     494      array_push($list_cat_id, $cat_id);
     495    }
     496  }
     497
     498  // delete user cache
     499  $query = '
     500  delete from '.USER_CACHE_CATEGORIES_TABLE.'
     501  where user_id = '.$user_id.'
     502;';
     503  pwg_query($query);
     504
     505  $query = '
     506    select
     507      id cat_id, date_last,
     508      nb_images, global_rank
     509    from '.CATEGORIES_TABLE;
     510  if ($user_forbidden_categories != '')
     511  {
     512    $query.= '
     513    where id not in ('.$user_forbidden_categories.')';
     514  }
     515  $query.= ';';
     516
     517  $result = pwg_query($query);
     518
     519  $cats = array();
     520  while ($row = mysql_fetch_array($result))
     521  {
     522    $cats += array($row['cat_id'] => $row);
     523  }
     524  usort($cats, 'global_rank_compare');
     525
     526  $ref_level = 0;
     527  $level = 0;
     528  $list_cat_id = array();
     529
     530  foreach ($cats as $id => $category)
     531  {
     532    // Update field
     533    $cats[$id]['user_id'] = $user_id;
     534    $cats[$id]['is_child_date_last'] = false;
     535    $cats[$id]['max_date_last'] = $cats[$id]['date_last'];
     536    $cats[$id]['count_images'] = $cats[$id]['nb_images'];
     537    $cats[$id]['count_categories'] = 0;
     538
     539    // Compute
     540    $level = substr_count($category['global_rank'], '.') + 1;
     541    if ($level > $ref_level)
     542    {
     543      array_push($list_cat_id, $id);
     544    }
     545    else
     546    {
     547      compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level);
     548      array_push($list_cat_id, $id);
     549    }
     550    $ref_level = $level;
     551  }
     552
     553  $level = 1;
     554  compute_branch_cat_data($cats, $list_cat_id, $level, $ref_level);
     555
     556  foreach ($cats as $id => $category)
     557  {
     558    // Convert field
     559    $cats[$id]['is_child_date_last'] = boolean_to_string($cats[$id]['is_child_date_last']);
     560  }
     561
     562  include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     563  mass_inserts
     564  (
     565    USER_CACHE_CATEGORIES_TABLE,
     566    array
     567    (
     568      'user_id', 'cat_id',
     569      'is_child_date_last', 'max_date_last',
     570      'count_images', 'count_categories'
     571    ),
     572    $cats
     573  );
    440574}
    441575
Note: See TracChangeset for help on using the changeset viewer.