aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include/functions.php
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2004-11-20 17:23:42 +0000
committerplegall <plg@piwigo.org>2004-11-20 17:23:42 +0000
commit13cd251e63232e88069759e8396b0c35b991088b (patch)
treeabf65955235f108908dc95e37678e2404ff87115 /admin/include/functions.php
parentf39c3af29b7d44fa11b0670bb8ad6f7e9b7c53d0 (diff)
- 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
Diffstat (limited to '')
-rw-r--r--admin/include/functions.php32
1 files changed, 27 insertions, 5 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 63f59471b..2b28f6784 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -486,8 +486,8 @@ SELECT id, representative_picture_id
WHERE representative_picture_id IS NOT NULL
AND id IN ('.implode(',', $cat_ids).')
;';
- $result = pwg_query( $query );
- while ( $row = mysql_fetch_array( $result ) )
+ $result = pwg_query($query);
+ while ($row = mysql_fetch_array($result))
{
$query = '
SELECT image_id
@@ -495,15 +495,37 @@ SELECT image_id
WHERE category_id = '.$row['id'].'
AND image_id = '.$row['representative_picture_id'].'
;';
- $result = pwg_query( $query );
- if (mysql_num_rows($result) == 0)
+ $sub_result = pwg_query($query);
+ if (mysql_num_rows($sub_result) == 0)
{
+ // set a new representative element for this category
$query = '
+SELECT image_id
+ FROM '.IMAGE_CATEGORY_TABLE.'
+ WHERE category_id = '.$row['id'].'
+ ORDER BY RAND()
+ LIMIT 0,1
+;';
+ $sub_sub_result = pwg_query($query);
+ if (mysql_num_rows($sub_sub_result) > 0)
+ {
+ list($representative) = mysql_fetch_array(pwg_query($query));
+ $query = '
+UPDATE '.CATEGORIES_TABLE.'
+ SET representative_picture_id = '.$representative.'
+ WHERE id = '.$row['id'].'
+;';
+ pwg_query($query);
+ }
+ else
+ {
+ $query = '
UPDATE '.CATEGORIES_TABLE.'
SET representative_picture_id = NULL
WHERE id = '.$row['id'].'
;';
- pwg_query( $query );
+ pwg_query($query);
+ }
}
}
}