diff options
author | plegall <plg@piwigo.org> | 2004-12-05 21:28:40 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2004-12-05 21:28:40 +0000 |
commit | 9064686d9990b6830c0cd6a00d95745d3841eb9e (patch) | |
tree | 0d2bc6ee0564041f1836fb63c30cfe00738f211b /admin/include/functions.php | |
parent | e4ce82fc27e1e10d697815928ef06c692a3f56da (diff) |
- on picture.php, related categories under the element are displayed in
global_rank order
- when adding a new virtual category, initializes its global_rank
- bug fixed : in admin/cat_list, false next rank
- in admin/cat_modify, complete directory is calculated only if category is
not virtual
- admin/picture_modify rewritten : graphically nearer to admin/cat_modify,
virtual associations are back
- update_category partially rewritten : take an array of categories in
parameter, becomes optionnaly recursive, use the set_random_representant
function, set a random representant for categories with elements and no
representant
- bug fixed : on a search results screen, elements belonging to more than 1
category were shown more than once
- bug fixed : in admin/cat_modify, changing a value in a textefield and
hitting enter was setting a new random representant
git-svn-id: http://piwigo.org/svn/trunk@635 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | admin/include/functions.php | 114 |
1 files changed, 74 insertions, 40 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php index 8ae7929ae..0d2972740 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -441,36 +441,74 @@ function check_favorites( $user_id ) } /** - * updates calculated informations about a category : date_last and + * updates calculated informations about a set of categories : date_last and * nb_images. It also verifies that the representative picture is really - * linked to the category. Recursive. + * linked to the category. Optionnaly recursive. * * @param mixed category id + * @param boolean recursive * @returns void */ -function update_category($id = 'all') +function update_category($ids = 'all', $recursive = false) { + // retrieving all categories to update $cat_ids = array(); $query = ' -SELECT category_id, - COUNT(image_id) AS nb_images, - MAX(date_available) AS date_last - FROM '.IMAGES_TABLE.' - INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; - if (is_numeric($id)) +SELECT id + FROM '.CATEGORIES_TABLE; + if (is_array($ids)) { - $query.= ' - WHERE uppercats REGEXP \'(^|,)'.$id.'(,|$)\''; + if ($recursive) + { + foreach ($ids as $num => $id) + { + if ($num == 0) + { + $query.= ' + WHERE '; + } + else + { + $query.= ' + OR '; + } + $query.= 'uppercats REGEXP \'(^|,)'.$id.'(,|$)\''; + } + } + else + { + $query.= ' + WHERE id IN ('.implode(',', $ids).')'; + } } $query.= ' - GROUP BY category_id ;'; $result = pwg_query( $query ); + while ( $row = mysql_fetch_array( $result ) ) + { + array_push($cat_ids, $row['id']); + } + $cat_ids = array_unique($cat_ids); + + if (count($cat_ids) == 0) + { + return false; + } + + // calculate informations about categories retrieved + $query = ' +SELECT category_id, + COUNT(image_id) AS nb_images, + MAX(date_available) AS date_last + FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id + WHERE category_id IN ('.implode(',', $cat_ids).') + GROUP BY category_id +'; + $result = pwg_query($query); $datas = array(); while ( $row = mysql_fetch_array( $result ) ) { - array_push($cat_ids, $row['category_id']); array_push($datas, array('id' => $row['category_id'], 'date_last' => $row['date_last'], 'nb_images' => $row['nb_images'])); @@ -479,8 +517,16 @@ SELECT category_id, 'update' => array('date_last', 'nb_images')); mass_updates(CATEGORIES_TABLE, $fields, $datas); + $query = ' +UPDATE '.CATEGORIES_TABLE.' + SET representative_picture_id = NULL + WHERE nb_images = 0 +;'; + pwg_query($query); + if (count($cat_ids) > 0) { + $categories = array(); // find all categories where the setted representative is not possible $query = ' SELECT id @@ -493,35 +539,23 @@ SELECT id $result = pwg_query($query); while ($row = mysql_fetch_array($result)) { - // 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_result = pwg_query($query); - if (mysql_num_rows($sub_result) > 0) - { - list($representative) = mysql_fetch_array($sub_result); - $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'].' + array_push($categories, $row['id']); + } + // find categories with elements and with no representant + $query = ' +SELECT id + FROM '.CATEGORIES_TABLE.' + WHERE representative_picture_id IS NULL + AND nb_images != 0 ;'; - pwg_query($query); - } + $result = pwg_query($query); + while ($row = mysql_fetch_array($result)) + { + array_push($categories, $row['id']); } + + $categories = array_unique($categories); + set_random_representant($categories); } } |