diff options
author | plegall <plg@piwigo.org> | 2004-12-04 17:42:07 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2004-12-04 17:42:07 +0000 |
commit | b3336f57d5d61eaa5d465b816962b12ea16c24ae (patch) | |
tree | fcaba01eccc65bfdec84fce49c6c4faf54a0fad1 /admin/include | |
parent | a383f3148cb7c9a23dadbdcd12ede4e1de274af5 (diff) |
- shows the element representing a non empty category in cat_modify
- possibility to set a random representing element for a category
- bug fixed : update_category function could not update nb_images
- bug fixed : mass_updates was inserting in the wrong table
git-svn-id: http://piwigo.org/svn/trunk@633 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin/include')
-rw-r--r-- | admin/include/functions.php | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php index 7a12be755..8ae7929ae 100644 --- a/admin/include/functions.php +++ b/admin/include/functions.php @@ -453,7 +453,9 @@ function update_category($id = 'all') $cat_ids = array(); $query = ' -SELECT category_id, COUNT(image_id) AS count, max(date_available) AS date_last +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)) @@ -471,10 +473,10 @@ SELECT category_id, COUNT(image_id) AS count, max(date_available) AS date_last array_push($cat_ids, $row['category_id']); array_push($datas, array('id' => $row['category_id'], 'date_last' => $row['date_last'], - 'count' => $row['count'])); + 'nb_images' => $row['nb_images'])); } $fields = array('primary' => array('id'), - 'update' => array('date_last', 'count')); + 'update' => array('date_last', 'nb_images')); mass_updates(CATEGORIES_TABLE, $fields, $datas); if (count($cat_ids) > 0) @@ -839,11 +841,10 @@ function mass_updates($tablename, $dbfields, $datas) // update queries $query = 'SELECT VERSION() AS version;'; $row = mysql_fetch_array(pwg_query($query)); - if (version_compare($row['version'],'4.0.4') < 0) + if (count($datas) < 10 or version_compare($row['version'],'4.0.4') < 0) { // MySQL is prior to version 4.0.4, multi table update feature is not // available - echo 'MySQL is prior to version 4.0.4, multi table update feature is not available<br />'; foreach ($datas as $data) { $query = ' @@ -914,7 +915,7 @@ PRIMARY KEY (id) ) ;'; pwg_query($query); - mass_inserts($tablename, $all_fields, $datas); + mass_inserts($tablename.'_temporary', $all_fields, $datas); // update of images table by joining with temporary table $query = ' UPDATE '.$tablename.' AS t1, '.$tablename.'_temporary AS t2 @@ -1092,4 +1093,32 @@ UPDATE '.CATEGORIES_TABLE.' pwg_query($query); } } + +/** + * set a new random representant to the categories + * + * @param array categories + */ +function set_random_representant($categories) +{ + $datas = array(); + foreach ($categories as $category_id) + { + $query = ' +SELECT image_id + FROM '.IMAGE_CATEGORY_TABLE.' + WHERE category_id = '.$category_id.' + ORDER BY RAND() + LIMIT 0,1 +;'; + list($representative) = mysql_fetch_array(pwg_query($query)); + $data = array('id' => $category_id, + 'representative_picture_id' => $representative); + array_push($datas, $data); + } + + $fields = array('primary' => array('id'), + 'update' => array('representative_picture_id')); + mass_updates(CATEGORIES_TABLE, $fields, $datas); +} ?> |