Changeset 2306
- Timestamp:
- Apr 21, 2008, 12:20:20 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/cat_list.php
r2299 r2306 58 58 mass_updates(CATEGORIES_TABLE, $fields, $datas); 59 59 60 update_global_rank( @$_GET['parent_id']);60 update_global_rank(); 61 61 } 62 62 … … 67 67 $categories = array(); 68 68 69 $base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list';70 $navigation = '<a class=""href="'.$base_url.'">';69 $base_url = get_root_url().'admin.php?page=cat_list'; 70 $navigation = '<a href="'.$base_url.'">'; 71 71 $navigation.= l10n('home'); 72 72 $navigation.= '</a>'; … … 80 80 delete_categories(array($_GET['delete'])); 81 81 array_push($page['infos'], l10n('cat_virtual_deleted')); 82 ordering();83 82 update_global_rank(); 84 83 } … … 237 236 'U_CHILDREN' => $cat_list_url.'&parent_id='.$category['id'], 238 237 'U_EDIT' => $base_url.'cat_modify&cat_id='.$category['id'], 239 238 240 239 'IS_VIRTUAL' => empty($category['dir']) 241 240 ); -
trunk/admin/include/functions.php
r2304 r2306 666 666 667 667 /** 668 * updates the global_rank of categories under the given id_uppercat 669 * 670 * @param int id_uppercat 668 * order categories (update categories.rank and global_rank database fields) 669 * so that rank field are consecutive integers starting at 1 for each child 671 670 * @return void 672 671 */ 673 function update_global_rank( $id_uppercat = 'all')674 { 675 $query = ' 676 SELECT id, rank672 function update_global_rank() 673 { 674 $query = ' 675 SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat, uppercats, rank, global_rank 677 676 FROM '.CATEGORIES_TABLE.' 678 ;'; 679 $result = pwg_query($query); 680 $ranks_array = array(); 681 while ($row = mysql_fetch_array($result)) 682 { 683 $ranks_array[$row['id']] = $row['rank']; 684 } 685 686 // which categories to update ? 687 $uppercats_array = array(); 688 689 $query = ' 690 SELECT id,uppercats 691 FROM '.CATEGORIES_TABLE; 692 if (is_numeric($id_uppercat)) 693 { 694 $query.= ' 695 WHERE uppercats REGEXP \'(^|,)'.$id_uppercat.'(,|$)\' 696 AND id != '.$id_uppercat.' 697 '; 698 } 699 $query.= ' 700 ;'; 677 ORDER BY id_uppercat,rank,name 678 ;'; 679 680 $cat_map = array(); 681 682 $current_rank = 0; 683 $current_uppercat = ''; 684 701 685 $result = pwg_query($query); 702 686 while ($row = mysql_fetch_array($result)) 703 687 { 704 $uppercats_array[$row['id']] = $row['uppercats']; 688 if ($row['id_uppercat'] != $current_uppercat) 689 { 690 $current_rank = 0; 691 $current_uppercat = $row['id_uppercat']; 692 } 693 ++$current_rank; 694 $cat = 695 array( 696 'rank' => $current_rank, 697 'rank_changed' =>$current_rank!=$row['rank'], 698 'global_rank' => $row['global_rank'], 699 'uppercats' => $row['uppercats'], 700 ); 701 $cat_map[ $row['id'] ] = $cat; 705 702 } 706 703 707 704 $datas = array(); 708 foreach ($uppercats_array as $id => $uppercats) 709 { 710 array_push( 711 $datas, 712 array( 713 'id' => $id, 714 'global_rank' => preg_replace( 705 706 foreach( $cat_map as $id=>$cat ) 707 { 708 $new_global_rank = preg_replace( 715 709 '/(\d+)/e', 716 "\$ranks_array['$1']", 717 str_replace(',', '.', $uppercats) 718 ), 719 ) 720 ); 710 "\$cat_map['$1']['rank']", 711 str_replace(',', '.', $cat['uppercats'] ) 712 ); 713 if ( $cat['rank_changed'] 714 or $new_global_rank!=$cat['global_rank'] 715 ) 716 { 717 $datas[] = array( 718 'id' => $id, 719 'rank' => $cat['rank'], 720 'global_rank' => $new_global_rank, 721 ); 722 } 721 723 } 722 724 … … 725 727 array( 726 728 'primary' => array('id'), 727 'update' => array(' global_rank')729 'update' => array('rank', 'global_rank') 728 730 ), 729 731 $datas 730 732 ); 733 return count($datas); 731 734 } 732 735 … … 874 877 $datas 875 878 ); 876 }877 878 /**879 * order categories (update categories.rank and global_rank database fields)880 *881 * the purpose of this function is to give a rank for all categories882 * (insides its sub-category), even the newer that have none at te883 * beginning. For this, ordering function selects all categories ordered by884 * rank ASC then name ASC for each uppercat.885 *886 * @returns void887 */888 function ordering()889 {890 $current_rank = 0;891 $current_uppercat = '';892 893 $query = '894 SELECT id, if(id_uppercat is null,\'\',id_uppercat) AS id_uppercat895 FROM '.CATEGORIES_TABLE.'896 ORDER BY id_uppercat,rank,name897 ;';898 $result = pwg_query($query);899 $datas = array();900 while ($row = mysql_fetch_array($result))901 {902 if ($row['id_uppercat'] != $current_uppercat)903 {904 $current_rank = 0;905 $current_uppercat = $row['id_uppercat'];906 }907 $data = array('id' => $row['id'], 'rank' => ++$current_rank);908 array_push($datas, $data);909 }910 911 $fields = array('primary' => array('id'), 'update' => array('rank'));912 mass_updates(CATEGORIES_TABLE, $fields, $datas);913 879 } 914 880 … … 1353 1319 1354 1320 update_uppercats(); 1355 ordering();1356 1321 update_global_rank(); 1357 1322 -
trunk/admin/maintenance.php
r2299 r2306 46 46 update_uppercats(); 47 47 update_category('all'); 48 ordering();49 48 update_global_rank(); 50 49 invalidate_user_cache(); -
trunk/admin/site_update.php
r2299 r2306 447 447 } 448 448 449 if ( isset( $conf['flip_picture_ext'][get_extension($filename)] ) 449 if ( isset( $conf['flip_picture_ext'][get_extension($filename)] ) 450 450 and !isset($fs[$path]['tn_ext']) ) 451 { // For a picture thumbnail is mandatory and for non picture element, 451 { // For a picture thumbnail is mandatory and for non picture element, 452 452 // thumbnail and representative are optionnal 453 453 array_push( … … 471 471 'storage_category_id' => $db_fulldirs[$dirname], 472 472 ); 473 473 474 474 if ( $_POST['privacy_level']!=0 ) 475 475 { … … 622 622 . ' -->' ); 623 623 $start = get_moment(); 624 ordering();625 624 update_global_rank(); 626 625 $template->append('footer_elements', '<!-- ordering categories : ' -
trunk/install/upgrade_1.3.1.php
r2299 r2306 68 68 ADD COLUMN commentable enum('true','false') NOT NULL default 'true' 69 69 ;", 70 70 71 71 " 72 72 ALTER TABLE phpwebgallery_categories … … 88 88 SET date_temp = date 89 89 ;", 90 90 91 91 " 92 92 ALTER TABLE phpwebgallery_comments … … 123 123 SET date_temp = date 124 124 ;", 125 125 126 126 " 127 127 ALTER TABLE phpwebgallery_history … … 204 204 ADD INDEX images_i5 (date_creation) 205 205 ;", 206 206 207 207 " 208 208 ALTER TABLE phpwebgallery_sessions … … 219 219 SET expiration_temp = expiration 220 220 ;", 221 221 222 222 " 223 223 ALTER TABLE phpwebgallery_sessions … … 234 234 DROP COLUMN expiration_temp 235 235 ;", 236 236 237 237 " 238 238 ALTER TABLE phpwebgallery_sites … … 248 248 DROP TABLE phpwebgallery_user_category 249 249 ;", 250 250 251 251 " 252 252 ALTER TABLE phpwebgallery_users … … 273 273 ADD UNIQUE users_ui1 (username) 274 274 ;", 275 275 276 276 " 277 277 CREATE TABLE phpwebgallery_rate ( … … 339 339 { 340 340 $existing_indexes = array(); 341 341 342 342 $query = ' 343 343 SHOW INDEX … … 526 526 527 527 // refresh calculated datas 528 ordering();529 528 update_global_rank(); 530 529 update_category(); … … 584 583 array( 585 584 'all sub-categories of private categories become private', 586 585 587 586 'user permissions and group permissions have been erased', 588 587
Note: See TracChangeset
for help on using the changeset viewer.