Force event team result order
This commit is contained in:
@@ -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 );
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user