- optimization : representative picture becomes mandatory for a non empty

category. So, at each insertion in images table for a category, a new
  representative element is elected (by rand). This must be improved by not
  reelcting a random picture admin set an element as representative
  manually.

- optimization : recent cats page only needs 2 queries instead of 3*N (N
  categories to display). The bad point is that it shows representative
  element of recent cat and not a random element among recently added.

- optimization : empty cats page only needs 1 query per non empty sub
  category instead of... a lot. For each sub category, PhpWebGallery shows
  the representative element of a category chosen randomly in sub
  cats. Thus, get_non_empty_subcat_ids and get_first_non_empty_cat_id
  becomes obsolete.

- new function get_cat_display_name_cache to show category names with a
  caching for all gallery categories names. This function, to the contrary
  of get_cat_display_name shows names in the correct order...


git-svn-id: http://piwigo.org/svn/trunk@610 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
plegall 2004-11-20 17:23:42 +00:00
parent f39c3af29b
commit 13cd251e63
7 changed files with 170 additions and 154 deletions

View file

@ -196,6 +196,76 @@ function get_cat_display_name($cat_informations,
}
}
/**
* returns the list of categories as a HTML string, with cache of names
*
* categories string returned contains categories as given in the input
* array $cat_informations. $uppercats is the list of category ids to
* display in the right order. If url input parameter is empty, returns only
* the categories name without links.
*
* @param string uppercats
* @param string separator
* @param string url
* @param boolean replace_space
* @return string
*/
function get_cat_display_name_cache($uppercats,
$separator,
$url = 'category.php?cat=',
$replace_space = true)
{
global $cat_names;
if (!isset($cat_names))
{
$query = '
SELECT id,name
FROM '.CATEGORIES_TABLE.'
;';
$result = pwg_query($query);
while ($row = mysql_fetch_array($result))
{
$cat_names[$row['id']] = $row['name'];
}
}
$output = '';
$is_first = true;
foreach (explode(',', $uppercats) as $category_id)
{
$name = $cat_names[$category_id];
if ($is_first)
{
$is_first = false;
}
else
{
$output.= $separator;
}
if ($url == '')
{
$output.= $name;
}
else
{
$output.= '
<a class=""
href="'.add_session_id(PHPWG_ROOT_PATH.$url.$category_id).'">'.$name.'</a>';
}
}
if ($replace_space)
{
return replace_space($output);
}
else
{
return $output;
}
}
/**
* returns the HTML code for a category item in the menu (for category.php)
*