Changeset 2307
- Timestamp:
- Apr 21, 2008, 12:25:40 AM (16 years ago)
- Location:
- branches/branch-1_7
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/branch-1_7/admin/cat_list.php
r2202 r2307 61 61 mass_updates(CATEGORIES_TABLE, $fields, $datas); 62 62 63 update_global_rank( @$_GET['parent_id']);63 update_global_rank(); 64 64 } 65 65 … … 83 83 delete_categories(array($_GET['delete'])); 84 84 array_push($page['infos'], l10n('cat_virtual_deleted')); 85 ordering();86 85 update_global_rank(); 87 86 } … … 295 294 } 296 295 // Add a link to Page bottom only if needed (10 or more categories) 297 if ( isset($category['rank']) and $category['rank'] > 9 ) 296 if ( isset($category['rank']) and $category['rank'] > 9 ) 298 297 { 299 298 $template->assign_block_vars('eop_link', array('ICON'=>'Displayed')); -
branches/branch-1_7/admin/include/functions.php
r2303 r2307 684 684 685 685 /** 686 * updates the global_rank of categories under the given id_uppercat 687 * 688 * @param int id_uppercat 686 * order categories (update categories.rank and global_rank database fields) 687 * so that rank field are consecutive integers starting at 1 for each child 689 688 * @return void 690 689 */ 691 function update_global_rank( $id_uppercat = 'all')692 { 693 $query = ' 694 SELECT id, rank690 function update_global_rank() 691 { 692 $query = ' 693 SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat, uppercats, rank, global_rank 695 694 FROM '.CATEGORIES_TABLE.' 696 ;'; 697 $result = pwg_query($query); 698 $ranks_array = array(); 699 while ($row = mysql_fetch_array($result)) 700 { 701 $ranks_array[$row['id']] = $row['rank']; 702 } 703 704 // which categories to update ? 705 $uppercats_array = array(); 706 707 $query = ' 708 SELECT id,uppercats 709 FROM '.CATEGORIES_TABLE; 710 if (is_numeric($id_uppercat)) 711 { 712 $query.= ' 713 WHERE uppercats REGEXP \'(^|,)'.$id_uppercat.'(,|$)\' 714 AND id != '.$id_uppercat.' 715 '; 716 } 717 $query.= ' 718 ;'; 695 ORDER BY id_uppercat,rank,name 696 ;'; 697 698 $cat_map = array(); 699 700 $current_rank = 0; 701 $current_uppercat = ''; 702 719 703 $result = pwg_query($query); 720 704 while ($row = mysql_fetch_array($result)) 721 705 { 722 $uppercats_array[$row['id']] = $row['uppercats']; 706 if ($row['id_uppercat'] != $current_uppercat) 707 { 708 $current_rank = 0; 709 $current_uppercat = $row['id_uppercat']; 710 } 711 ++$current_rank; 712 $cat = 713 array( 714 'rank' => $current_rank, 715 'rank_changed' =>$current_rank!=$row['rank'], 716 'global_rank' => $row['global_rank'], 717 'uppercats' => $row['uppercats'], 718 ); 719 $cat_map[ $row['id'] ] = $cat; 723 720 } 724 721 725 722 $datas = array(); 726 foreach ($uppercats_array as $id => $uppercats) 727 { 728 array_push( 729 $datas, 730 array( 731 'id' => $id, 732 'global_rank' => preg_replace( 723 724 foreach( $cat_map as $id=>$cat ) 725 { 726 $new_global_rank = preg_replace( 733 727 '/(\d+)/e', 734 "\$ranks_array['$1']", 735 str_replace(',', '.', $uppercats) 736 ), 737 ) 738 ); 728 "\$cat_map['$1']['rank']", 729 str_replace(',', '.', $cat['uppercats'] ) 730 ); 731 if ( $cat['rank_changed'] 732 or $new_global_rank!=$cat['global_rank'] 733 ) 734 { 735 $datas[] = array( 736 'id' => $id, 737 'rank' => $cat['rank'], 738 'global_rank' => $new_global_rank, 739 ); 740 } 739 741 } 740 742 … … 743 745 array( 744 746 'primary' => array('id'), 745 'update' => array(' global_rank')747 'update' => array('rank', 'global_rank') 746 748 ), 747 749 $datas 748 750 ); 751 return count($datas); 749 752 } 750 753 … … 892 895 $datas 893 896 ); 894 }895 896 /**897 * order categories (update categories.rank and global_rank database fields)898 *899 * the purpose of this function is to give a rank for all categories900 * (insides its sub-category), even the newer that have none at te901 * beginning. For this, ordering function selects all categories ordered by902 * rank ASC then name ASC for each uppercat.903 *904 * @returns void905 */906 function ordering()907 {908 $current_rank = 0;909 $current_uppercat = '';910 911 $query = '912 SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat913 FROM '.CATEGORIES_TABLE.'914 ORDER BY id_uppercat,rank,name915 ;';916 $result = pwg_query($query);917 $datas = array();918 while ($row = mysql_fetch_array($result))919 {920 if ($row['id_uppercat'] != $current_uppercat)921 {922 $current_rank = 0;923 $current_uppercat = $row['id_uppercat'];924 }925 $data = array('id' => $row['id'], 'rank' => ++$current_rank);926 array_push($datas, $data);927 }928 929 $fields = array('primary' => array('id'), 'update' => array('rank'));930 mass_updates(CATEGORIES_TABLE, $fields, $datas);931 897 } 932 898 … … 1371 1337 1372 1338 update_uppercats(); 1373 ordering();1374 1339 update_global_rank(); 1375 1340 -
branches/branch-1_7/admin/maintenance.php
r2061 r2307 49 49 update_uppercats(); 50 50 update_category('all'); 51 ordering();52 51 update_global_rank(); 53 52 invalidate_user_cache(); -
branches/branch-1_7/admin/site_update.php
r2193 r2307 243 243 // If $_POST['subcats-included'] != 1 ("Search in subcategories" is unchecked) 244 244 // $db_fulldirs doesn't include any subdirectories and $fs_fulldirs does 245 // So $fs_fulldirs will be limited to the selected basedir 245 // So $fs_fulldirs will be limited to the selected basedir 246 246 // (if that one is in $fs_fulldirs) 247 247 if (!isset($_POST['subcats-included']) or $_POST['subcats-included'] != 1) … … 254 254 // die('That\'s why dirs or files synchronizations were duplicating cats.'); 255 255 256 $inserts = array(); 256 $inserts = array(); 257 257 // new categories are the directories not present yet in the database 258 258 foreach (array_diff($fs_fulldirs, array_keys($db_fulldirs)) as $fulldir) … … 671 671 echo ' -->'."\n"; 672 672 $start = get_moment(); 673 ordering();674 673 update_global_rank(); 675 674 echo '<!-- ordering categories : '; … … 829 828 } 830 829 } 831 830 832 831 foreach ( $files as $id=>$file ) 833 832 { … … 836 835 in_array($id, $has_high_images) 837 836 ); 838 837 839 838 if ( is_array($data) ) 840 839 { … … 873 872 { 874 873 // echo '<pre>', print_r($datas); echo '</pre>'; 875 874 876 875 mass_updates( 877 876 IMAGES_TABLE, -
branches/branch-1_7/install/upgrade_1.3.1.php
r1932 r2307 72 72 ADD COLUMN commentable enum('true','false') NOT NULL default 'true' 73 73 ;", 74 74 75 75 " 76 76 ALTER TABLE phpwebgallery_categories … … 92 92 SET date_temp = date 93 93 ;", 94 94 95 95 " 96 96 ALTER TABLE phpwebgallery_comments … … 127 127 SET date_temp = date 128 128 ;", 129 129 130 130 " 131 131 ALTER TABLE phpwebgallery_history … … 208 208 ADD INDEX images_i5 (date_creation) 209 209 ;", 210 210 211 211 " 212 212 ALTER TABLE phpwebgallery_sessions … … 223 223 SET expiration_temp = expiration 224 224 ;", 225 225 226 226 " 227 227 ALTER TABLE phpwebgallery_sessions … … 238 238 DROP COLUMN expiration_temp 239 239 ;", 240 240 241 241 " 242 242 ALTER TABLE phpwebgallery_sites … … 252 252 DROP TABLE phpwebgallery_user_category 253 253 ;", 254 254 255 255 " 256 256 ALTER TABLE phpwebgallery_users … … 277 277 ADD UNIQUE users_ui1 (username) 278 278 ;", 279 279 280 280 " 281 281 CREATE TABLE phpwebgallery_rate ( … … 343 343 { 344 344 $existing_indexes = array(); 345 345 346 346 $query = ' 347 347 SHOW INDEX … … 530 530 531 531 // refresh calculated datas 532 ordering();533 532 update_global_rank(); 534 533 update_category(); … … 588 587 array( 589 588 'all sub-categories of private categories become private', 590 589 591 590 'user permissions and group permissions have been erased', 592 591
Note: See TracChangeset
for help on using the changeset viewer.