From 27d20312e4d3acc2ab9b30b54ecefcff8fa615f7 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Mon, 27 Mar 2017 21:25:28 +1100 Subject: [PATCH] Revert "Disconnect manually entered player stats from dynamic player list values" This reverts commit 5870d4769e362e0c67482566f822808dda3b7339. --- includes/class-sp-player-list.php | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/includes/class-sp-player-list.php b/includes/class-sp-player-list.php index 41c220b1..4b05a74c 100644 --- a/includes/class-sp-player-list.php +++ b/includes/class-sp-player-list.php @@ -266,8 +266,33 @@ class SP_Player_List extends SP_Custom_Post { $metrics[ $key ] += $adjustment; endforeach; + // Get static stats + $static = get_post_meta( $player_id, 'sp_statistics', true ); + + // Get league and season arrays for static stats + $static_league_ids = ( empty( $league_ids ) ? array( 0 ) : $league_ids ); + $static_season_ids = ( empty( $season_ids ) ? array( 0 ) : $season_ids ); + + // Add static stats to placeholders + if ( $static_league_ids && $static_season_ids ): + foreach ( $static_league_ids as $league_id ): + foreach ( $static_season_ids as $season_id ): + $player_league_season_stats = sp_array_value( sp_array_value( $static, $league_id, array() ), $season_id, array() ); + if ( is_array( $player_league_season_stats ) ): + foreach ( $player_league_season_stats as $key => $value ): + $current_value = sp_array_value( sp_array_value( $placeholders, $player_id, array() ), $key, 0 ); + $value = floatval( $value ); + $placeholders[ $player_id ][ $key ] = $current_value + $value; + endforeach; + endif; + endforeach; + endforeach; + else: + $placeholders[ $player_id ] = sp_array_value( sp_array_value( $static, 0, array() ), 0, array() ); + endif; + // Add metrics to placeholders - $placeholders[ $player_id ] = $metrics; + $placeholders[ $player_id ] = array_merge( $metrics, sp_array_value( $placeholders, $player_id, array() ) ); endforeach; $args = array( @@ -561,8 +586,7 @@ class SP_Player_List extends SP_Custom_Post { if ( ! $player_id ) continue; - // Add calculated totals to placeholders - $placeholders[ $player_id ] = array_merge( sp_array_value( $placeholders, $player_id, array() ), sp_array_value( $totals, $player_id, array() ), array() ); + $placeholders[ $player_id ] = array_merge( sp_array_value( $totals, $player_id, array() ), array_filter( sp_array_value( $placeholders, $player_id, array() ) ) ); // Player adjustments $player_adjustments = sp_array_value( $adjustments, $player_id, array() );