From bbaf3104657ecd8c5bcfff3e132ed73982cf3651 Mon Sep 17 00:00:00 2001 From: Takumi Date: Mon, 19 Aug 2013 20:35:33 +1000 Subject: [PATCH] Add static option to sp_get_stats_row function --- helpers.php | 32 ++++++++++++++++++++++++++++---- player.php | 4 ++-- table.php | 10 +++++++--- team.php | 10 +++++++--- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/helpers.php b/helpers.php index fbab2c13..50436bd0 100644 --- a/helpers.php +++ b/helpers.php @@ -253,7 +253,7 @@ if ( !function_exists( 'sp_get_eos_array' ) ) { } if ( !function_exists( 'sp_get_stats_row' ) ) { - function sp_get_stats_row( $post_type = 'post', $args = array() ) { + function sp_get_stats_row( $post_type = 'post', $args = array(), $static = false ) { $args = array_merge( array( 'posts_per_page' => -1 @@ -266,13 +266,15 @@ if ( !function_exists( 'sp_get_stats_row' ) ) { $eos = new eqEOS(); $vars = array(); + + // Get dynamic stats switch ($post_type): case 'sp_team': // Add object properties needed for retreiving event stats foreach( $posts as $post ): $post->sp_team = get_post_meta( $post->ID, 'sp_team', false ); - $post->sp_team_index = array_search( $args['meta_value'], $post->sp_team ); + $post->sp_team_index = array_search( $args['meta_query'][0]['value'], $post->sp_team ); $post->sp_result = get_post_meta( $post->ID, 'sp_result', false ); endforeach; @@ -327,12 +329,34 @@ if ( !function_exists( 'sp_get_stats_row' ) ) { endswitch; - $output = array(); + // Get dynamic stats + $dynamic = array(); foreach ( $rows as $key => $value ): $row = explode( ':', $value ); - $output[] = $eos->solveIF( sp_array_value( $row, 1, '$played'), $vars ); + $dynamic[] = $eos->solveIF( sp_array_value( $row, 1, '$played'), $vars ); endforeach; + if ( $static ): + + // Get static stats + $static = (array)get_post_meta( $args['meta_query'][0]['value'], 'sp_stats', true ); + $table = sp_array_value( $static, 0, array() ); + if ( array_key_exists( 'tax_query', $args ) ) + $row_id = $args['tax_query'][0]['terms']; + else + $row_id = 0; + $static = sp_array_value( $table, $row_id, array() ); + + // Combine static and dynamic stats + $output = array_filter( $static ) + $dynamic; + ksort( $output ); + + else: + + $output = $dynamic; + + endif; + return $output; } } diff --git a/player.php b/player.php index 1d827dd2..d57ba0e1 100644 --- a/player.php +++ b/player.php @@ -72,7 +72,7 @@ function sp_player_stats_meta( $post ) { endforeach; ?>

- +

- + 'sp_event', - 'meta_key' => 'sp_team', - 'meta_value' => $team, + 'meta_query' => array( + array( + 'key' => 'sp_team', + 'value' => $team + ) + ), 'tax_query' => array( array( 'taxonomy' => 'sp_league', @@ -79,7 +83,7 @@ function sp_table_stats_meta( $post ) { ) ) ); - $placeholders[ $team ] = sp_get_stats_row( 'sp_team', $args ); + $placeholders[ $team ] = sp_get_stats_row( 'sp_team', $args, true ); endforeach; sp_stats_table( $data, $placeholders, $league_id, array( 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), false ); diff --git a/team.php b/team.php index 3d396601..51df8cc0 100644 --- a/team.php +++ b/team.php @@ -47,7 +47,7 @@ function sp_team_stats_meta( $post ) { $league_ids[] = $value->term_id; endforeach; - // Get all leagues populated with stats where availabled + // Get all leagues populated with stats where available $data = sp_array_combine( $league_ids, sp_array_value( $stats, 0, array() ) ); // Generate array of placeholder values for each league @@ -55,8 +55,12 @@ function sp_team_stats_meta( $post ) { foreach ( $league_ids as $league_id ): $args = array( 'post_type' => 'sp_event', - 'meta_key' => 'sp_team', - 'meta_value' => $post->ID, + 'meta_query' => array( + array( + 'key' => 'sp_team', + 'value' => $post->ID + ) + ), 'tax_query' => array( array( 'taxonomy' => 'sp_league',