Add static option to sp_get_stats_row function
This commit is contained in:
32
helpers.php
32
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ function sp_player_stats_meta( $post ) {
|
||||
endforeach;
|
||||
?>
|
||||
<p><strong><?php _e( 'Overall', 'sportspress' ); ?></strong></p>
|
||||
<?php sp_stats_table( $data, $placeholders, 0, array( 'Team', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ), true, 'sp_league' ); ?>
|
||||
<?php sp_stats_table( $data, $placeholders, 0, array( 'League', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ), true, 'sp_league' ); ?>
|
||||
<?php
|
||||
|
||||
// Leagues
|
||||
@@ -109,7 +109,7 @@ function sp_player_stats_meta( $post ) {
|
||||
endforeach;
|
||||
?>
|
||||
<p><strong><?php echo get_the_title( $team ); ?></strong></p>
|
||||
<?php sp_stats_table( $data, $placeholders, $team, array( 'Team', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ), true, 'sp_league' ); ?>
|
||||
<?php sp_stats_table( $data, $placeholders, $team, array( 'League', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ), true, 'sp_league' ); ?>
|
||||
<?php
|
||||
endforeach;
|
||||
|
||||
|
||||
10
table.php
10
table.php
@@ -69,8 +69,12 @@ function sp_table_stats_meta( $post ) {
|
||||
foreach ( $teams as $team ):
|
||||
$args = array(
|
||||
'post_type' => '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 );
|
||||
|
||||
10
team.php
10
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',
|
||||
|
||||
Reference in New Issue
Block a user