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 );
// Get results for all teams
$data = sp_array_combine( $teams, $results );
$data = sp_array_combine( $teams, $results, true );
if ( $admin ):
return array( $columns, $usecolumns, $data );

View File

@@ -260,23 +260,31 @@ if ( !function_exists( 'sp_array_value' ) ) {
}
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( $values ) ) $values = array();
$output = array();
foreach ( $values as $key => $value ):
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;
if ( $key_order ):
foreach( $keys as $key ):
if ( array_key_exists( $key, $values ) )
$output[ $key ] = $values[ $key ];
else
$output[ $key ] = array();
endforeach;
else:
foreach ( $values as $key => $value ):
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;
}
}