From 61c468fa8bb06f92b8301a28602e2d22599c9226 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sat, 5 May 2018 20:08:58 +1000 Subject: [PATCH] Apply league and season order to player statistics --- .../class-sp-meta-box-player-statistics.php | 20 +++++++++++--- includes/class-sp-player.php | 26 ++++++++++++++++--- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-statistics.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-statistics.php index 4241d574..5e7f5bde 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-statistics.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-statistics.php @@ -20,7 +20,20 @@ class SP_Meta_Box_Player_Statistics { */ public static function output( $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 ); $sections = get_option( 'sportspress_player_performance_sections', -1 ); $show_career_totals = 'yes' === get_option( 'sportspress_player_show_career_total', 'no' ) ? true : false; @@ -106,9 +119,7 @@ class SP_Meta_Box_Player_Statistics { $label ): if ( $key == 'team' ) continue; ?> - 0 ) { ?> - +− - + @@ -144,6 +155,7 @@ class SP_Meta_Box_Player_Statistics { } ?> + diff --git a/includes/class-sp-player.php b/includes/class-sp-player.php index 99082754..12d9f735 100644 --- a/includes/class-sp-player.php +++ b/includes/class-sp-player.php @@ -110,12 +110,32 @@ class SP_Player extends SP_Custom_Post { * @return array */ public function data( $league_id, $admin = false, $section = -1 ) { - - $seasons = (array)get_the_terms( $this->ID, 'sp_season' ); + $args = array( + '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 ); $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() ); $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 $args = array( @@ -237,7 +257,7 @@ class SP_Player extends SP_Custom_Post { $data = array(); // 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 $equations = sp_get_var_equations( 'sp_statistic' );