Apply league and season order to player statistics

This commit is contained in:
Brian Miyaji
2018-05-05 20:08:58 +10:00
parent 8cb92b35d9
commit 61c468fa8b
2 changed files with 39 additions and 7 deletions

View File

@@ -20,7 +20,20 @@ class SP_Meta_Box_Player_Statistics {
*/ */
public static function output( $post ) { public static function output( $post ) {
$player = new SP_Player( $post ); $player = new SP_Player( $post );
$leagues = get_the_terms( $post->ID, 'sp_league' ); $args = array(
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'sp_order',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'sp_order',
'compare' => 'EXISTS',
),
),
);
$leagues = get_the_terms( $post->ID, 'sp_league', $args );
$league_num = sizeof( $leagues ); $league_num = sizeof( $leagues );
$sections = get_option( 'sportspress_player_performance_sections', -1 ); $sections = get_option( 'sportspress_player_performance_sections', -1 );
$show_career_totals = 'yes' === get_option( 'sportspress_player_show_career_total', 'no' ) ? true : false; $show_career_totals = 'yes' === get_option( 'sportspress_player_show_career_total', 'no' ) ? true : false;
@@ -106,9 +119,7 @@ class SP_Meta_Box_Player_Statistics {
<?php foreach ( $columns as $key => $label ): if ( $key == 'team' ) continue; ?> <?php foreach ( $columns as $key => $label ): if ( $key == 'team' ) continue; ?>
<th><?php echo $label; ?></th> <th><?php echo $label; ?></th>
<?php endforeach; ?> <?php endforeach; ?>
<?php if ( $league_id > 0 ) { ?> <?php do_action( 'sportspress_meta_box_player_statistics_table_header_row', $id, $league_id ); ?>
<th>&plus;&minus;</th>
<?php } ?>
</tr> </tr>
</thead> </thead>
<tfoot> <tfoot>
@@ -144,6 +155,7 @@ class SP_Meta_Box_Player_Statistics {
} }
?></td> ?></td>
<?php endforeach; ?> <?php endforeach; ?>
<?php do_action( 'sportspress_meta_box_player_statistics_table_footer_row', $id, $league_id ); ?>
</tr> </tr>
</tfoot> </tfoot>
<tbody> <tbody>

View File

@@ -110,13 +110,33 @@ class SP_Player extends SP_Custom_Post {
* @return array * @return array
*/ */
public function data( $league_id, $admin = false, $section = -1 ) { public function data( $league_id, $admin = false, $section = -1 ) {
$args = array(
$seasons = (array)get_the_terms( $this->ID, 'sp_season' ); 'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'sp_order',
'compare' => 'NOT EXISTS',
),
array(
'key' => 'sp_order',
'compare' => 'EXISTS',
),
),
);
$seasons = (array)get_the_terms( $this->ID, 'sp_season', $args );
$metrics = (array)get_post_meta( $this->ID, 'sp_metrics', true ); $metrics = (array)get_post_meta( $this->ID, 'sp_metrics', true );
$stats = (array)get_post_meta( $this->ID, 'sp_statistics', true ); $stats = (array)get_post_meta( $this->ID, 'sp_statistics', true );
$leagues = sp_array_value( (array)get_post_meta( $this->ID, 'sp_leagues', true ), $league_id, array() ); $leagues = sp_array_value( (array)get_post_meta( $this->ID, 'sp_leagues', true ), $league_id, array() );
$manual_columns = 'manual' == get_option( 'sportspress_player_columns', 'auto' ) ? true : false; $manual_columns = 'manual' == get_option( 'sportspress_player_columns', 'auto' ) ? true : false;
$season_ids = wp_list_pluck( $seasons, 'term_id' );
$season_order = array_flip( $season_ids );
foreach ( $season_order as $season_id => $val ) {
$season_order[ $season_id ] = null;
}
$leagues = array_replace( $season_order, $leagues );
// Get performance labels // Get performance labels
$args = array( $args = array(
'post_type' => array( 'sp_performance' ), 'post_type' => array( 'sp_performance' ),
@@ -237,7 +257,7 @@ class SP_Player extends SP_Custom_Post {
$data = array(); $data = array();
// Get all seasons populated with data where available // Get all seasons populated with data where available
$data = sp_array_combine( $div_ids, sp_array_value( $stats, $league_id, array() ) ); $data = sp_array_combine( $div_ids, sp_array_value( $stats, $league_id, array() ), true );
// Get equations from statistic variables // Get equations from statistic variables
$equations = sp_get_var_equations( 'sp_statistic' ); $equations = sp_get_var_equations( 'sp_statistic' );