Reflect mixed column order in player list admin
This commit is contained in:
@@ -24,7 +24,8 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
public function __construct( $post ) {
|
public function __construct( $post ) {
|
||||||
parent::__construct( $post );
|
parent::__construct( $post );
|
||||||
$this->columns = get_post_meta( $this->ID, 'sp_columns', true );
|
$this->columns = get_post_meta( $this->ID, 'sp_columns', true );
|
||||||
if ( ! is_array( $this->columns ) ) $this->columns = array();
|
if ( is_array( $this->columns ) ) $this->columns = array_filter( $this->columns );
|
||||||
|
else $this->columns = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -474,6 +475,13 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
$stats = get_posts( $args );
|
$stats = get_posts( $args );
|
||||||
|
|
||||||
$formats = array();
|
$formats = array();
|
||||||
|
$data = array();
|
||||||
|
$merged = array();
|
||||||
|
$ordered_columns = array();
|
||||||
|
|
||||||
|
if ( $stats ):
|
||||||
|
|
||||||
|
$column_order = array();
|
||||||
|
|
||||||
foreach ( $stats as $stat ):
|
foreach ( $stats as $stat ):
|
||||||
|
|
||||||
@@ -500,8 +508,21 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
}
|
}
|
||||||
$formats[ $stat->post_name ] = $format;
|
$formats[ $stat->post_name ] = $format;
|
||||||
|
|
||||||
|
$column_order[] = $stat->post_name;
|
||||||
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
|
foreach ( $column_order as $slug ):
|
||||||
|
|
||||||
|
if ( ! in_array( $slug, $this->columns ) ) continue;
|
||||||
|
|
||||||
|
$ordered_columns[] = $slug;
|
||||||
|
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
$diff = array_diff( $this->columns, $ordered_columns );
|
||||||
|
$this->columns = array_merge( $diff, $ordered_columns );
|
||||||
|
|
||||||
// Fill in empty placeholder values for each player
|
// Fill in empty placeholder values for each player
|
||||||
foreach ( $player_ids as $player_id ):
|
foreach ( $player_ids as $player_id ):
|
||||||
if ( ! $player_id )
|
if ( ! $player_id )
|
||||||
@@ -542,10 +563,11 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
// Merge the data and placeholders arrays
|
// Merge the data and placeholders arrays
|
||||||
$merged = array();
|
|
||||||
|
|
||||||
foreach( $placeholders as $player_id => $player_data ):
|
foreach( $placeholders as $player_id => $player_data ):
|
||||||
|
|
||||||
|
$player_data = array_merge( $column_order, $player_data );
|
||||||
|
$placeholders[ $player_id ] = $player_data;
|
||||||
|
|
||||||
// Add player number and name to row
|
// Add player number and name to row
|
||||||
$merged[ $player_id ] = array();
|
$merged[ $player_id ] = array();
|
||||||
if ( in_array( 'number', $this->columns ) ):
|
if ( in_array( 'number', $this->columns ) ):
|
||||||
@@ -585,10 +607,10 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
endif;
|
endif;
|
||||||
|
|
||||||
// Rearrange data array to reflect values
|
// Rearrange data array to reflect values
|
||||||
$data = array();
|
|
||||||
foreach( $merged as $key => $value ):
|
foreach( $merged as $key => $value ):
|
||||||
$data[ $key ] = $tempdata[ $key ];
|
$data[ $key ] = $tempdata[ $key ];
|
||||||
endforeach;
|
endforeach;
|
||||||
|
endif;
|
||||||
|
|
||||||
if ( $admin ):
|
if ( $admin ):
|
||||||
|
|
||||||
@@ -628,6 +650,7 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
$labels[ $key ] = $columns[ $key ];
|
$labels[ $key ] = $columns[ $key ];
|
||||||
endif;
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
return array( $labels, $data, $placeholders, $merged, $orderby );
|
return array( $labels, $data, $placeholders, $merged, $orderby );
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user