From e715dd243506455c4fe0f04daa719188f0d914e9 Mon Sep 17 00:00:00 2001 From: ThemeBoy Date: Mon, 2 Dec 2013 17:44:16 +1100 Subject: [PATCH] Override team event stats with static stats in league table --- admin/post-types/list.php | 2 +- admin/post-types/table.php | 23 ++++++++++++++++++----- admin/post-types/team.php | 28 ++++++++++++++++------------ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/admin/post-types/list.php b/admin/post-types/list.php index 4115bf2c..1d893dd7 100644 --- a/admin/post-types/list.php +++ b/admin/post-types/list.php @@ -12,7 +12,7 @@ function sp_list_cpt_init() { 'supports' => array( 'title', 'author' ), 'register_meta_box_cb' => 'sp_list_meta_init', 'rewrite' => array( 'slug' => 'list' ), - 'show_in_menu' => 'edit.php?post_type=sp_player' + 'show_in_menu' => 'edit.php?post_type=sp_event' ); register_post_type( 'sp_list', $args ); } diff --git a/admin/post-types/table.php b/admin/post-types/table.php index 240f6e2d..612e3c0c 100644 --- a/admin/post-types/table.php +++ b/admin/post-types/table.php @@ -12,7 +12,7 @@ function sp_table_cpt_init() { 'supports' => array( 'title', 'author' ), 'register_meta_box_cb' => 'sp_table_meta_init', 'rewrite' => array( 'slug' => 'table' ), - 'show_in_menu' => 'edit.php?post_type=sp_team' + 'show_in_menu' => 'edit.php?post_type=sp_event' ); register_post_type( 'sp_table', $args ); } @@ -80,6 +80,8 @@ function sp_table_stats_meta( $post ) { // Create entry for each team in totals $totals = array(); + $placeholders = array(); + foreach ( $team_ids as $team_id ): $totals[ $team_id ] = array( 'eventsplayed' => 0 ); @@ -91,6 +93,17 @@ function sp_table_stats_meta( $post ) { foreach ( $outcome_labels as $key => $value ): $totals[ $team_id ][ $key ] = 0; endforeach; + + $static = get_post_meta( $team_id, 'sp_stats', true ); + + // Create placeholders entry for the team + $placeholders[ $team_id ] = array(); + + // Add static stats to placeholders + if ( array_key_exists( $div_id, $static ) ): + $placeholders[ $team_id ] = $static[ $div_id ]; + endif; + endforeach; $args = array( @@ -135,12 +148,12 @@ function sp_table_stats_meta( $post ) { endforeach; - // Generate placeholder values for each team - $placeholders = array(); + // Fill in empty placeholder values for each team foreach ( $team_ids as $team_id ): - $placeholders[ $team_id ] = array(); foreach ( $equations as $key => $value ): - $placeholders[ $team_id ][ $key ] = $eos->solveIF( str_replace( ' ', '', $value ), $totals[ $team_id ] ); + if ( sp_array_value( $placeholders[ $team_id ], $key, '' ) == '' ): + $placeholders[ $team_id ][ $key ] = $eos->solveIF( str_replace( ' ', '', $value ), $totals[ $team_id ] ); + endif; endforeach; endforeach; diff --git a/admin/post-types/team.php b/admin/post-types/team.php index 587bf326..ea19eed6 100644 --- a/admin/post-types/team.php +++ b/admin/post-types/team.php @@ -50,18 +50,6 @@ function sp_team_stats_meta( $post ) { // Get labels from outcome variables $outcome_labels = (array)sp_get_var_labels( 'sp_outcome' ); - $totals = array( 'eventsplayed' => 0 ); - $placeholders = array(); - - foreach ( $result_labels as $key => $value ): - $totals[ $key . 'for' ] = 0; - $totals[ $key . 'against' ] = 0; - endforeach; - - foreach ( $outcome_labels as $key => $value ): - $totals[ $key ] = 0; - endforeach; - // Generate array of all division ids $div_ids = array(); foreach ( $divisions as $key => $value ): @@ -75,7 +63,22 @@ function sp_team_stats_meta( $post ) { // Get equations from statistics variables $equations = sp_get_var_equations( 'sp_stat' ); + // Initialize placeholders array + $placeholders = array(); + foreach ( $div_ids as $div_id ): + + $totals = array( 'eventsplayed' => 0 ); + + foreach ( $result_labels as $key => $value ): + $totals[ $key . 'for' ] = 0; + $totals[ $key . 'against' ] = 0; + endforeach; + + foreach ( $outcome_labels as $key => $value ): + $totals[ $key ] = 0; + endforeach; + $args = array( 'post_type' => 'sp_event', 'numberposts' => -1, @@ -95,6 +98,7 @@ function sp_team_stats_meta( $post ) { ) ); $events = get_posts( $args ); + foreach( $events as $event ): $totals['eventsplayed']++; $results = (array)get_post_meta( $event->ID, 'sp_results', true );