Force event team result order

This commit is contained in:
Brian Miyaji
2014-07-21 15:02:58 +10:00
parent 06221321b5
commit 8d8ef87c96
2 changed files with 20 additions and 12 deletions

View File

@@ -36,7 +36,7 @@ class SP_Event extends SP_Custom_Post{
$usecolumns = get_post_meta( $this->ID, 'sp_result_columns', true ); $usecolumns = get_post_meta( $this->ID, 'sp_result_columns', true );
// Get results for all teams // Get results for all teams
$data = sp_array_combine( $teams, $results ); $data = sp_array_combine( $teams, $results, true );
if ( $admin ): if ( $admin ):
return array( $columns, $usecolumns, $data ); return array( $columns, $usecolumns, $data );

View File

@@ -260,23 +260,31 @@ if ( !function_exists( 'sp_array_value' ) ) {
} }
if ( !function_exists( 'sp_array_combine' ) ) { if ( !function_exists( 'sp_array_combine' ) ) {
function sp_array_combine( $keys = array(), $values = array() ) { function sp_array_combine( $keys = array(), $values = array(), $key_order = false ) {
if ( ! is_array( $keys ) ) return array(); if ( ! is_array( $keys ) ) return array();
if ( ! is_array( $values ) ) $values = array(); if ( ! is_array( $values ) ) $values = array();
$output = array(); $output = array();
foreach ( $values as $key => $value ): if ( $key_order ):
if ( in_array( $key, $keys ) ): foreach( $keys as $key ):
$output[ $key ] = $value; if ( array_key_exists( $key, $values ) )
endif; $output[ $key ] = $values[ $key ];
endforeach; else
$output[ $key ] = array();
foreach ( $keys as $key ): endforeach;
if ( $key !== false && ! array_key_exists( $key, $output ) ) else:
$output[ $key ] = array(); foreach ( $values as $key => $value ):
endforeach; if ( in_array( $key, $keys ) ):
$output[ $key ] = $value;
endif;
endforeach;
foreach ( $keys as $key ):
if ( $key !== false && ! array_key_exists( $key, $output ) )
$output[ $key ] = array();
endforeach;
endif;
return $output; return $output;
} }
} }