Calculate subset results
This commit is contained in:
@@ -163,7 +163,7 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'orderby' => 'post_date',
|
'orderby' => 'post_date',
|
||||||
'order' => 'DESC',
|
'order' => 'ASC',
|
||||||
'meta_query' => array(
|
'meta_query' => array(
|
||||||
array(
|
array(
|
||||||
'key' => 'sp_format',
|
'key' => 'sp_format',
|
||||||
@@ -196,6 +196,8 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
|
|
||||||
$events = get_posts( $args );
|
$events = get_posts( $args );
|
||||||
|
|
||||||
|
$e = 0;
|
||||||
|
|
||||||
// Event loop
|
// Event loop
|
||||||
foreach ( $events as $event ):
|
foreach ( $events as $event ):
|
||||||
|
|
||||||
@@ -265,9 +267,11 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
else:
|
else:
|
||||||
if ( array_key_exists( $team_id, $totals ) && is_array( $totals[ $team_id ] ) && array_key_exists( $key . 'for', $totals[ $team_id ] ) ):
|
if ( array_key_exists( $team_id, $totals ) && is_array( $totals[ $team_id ] ) && array_key_exists( $key . 'for', $totals[ $team_id ] ) ):
|
||||||
$totals[ $team_id ][ $key . 'for' ] += $value;
|
$totals[ $team_id ][ $key . 'for' ] += $value;
|
||||||
|
$totals[ $team_id ][ $key . 'for' . ( $e + 1 ) ] = $value;
|
||||||
foreach( $results as $other_team_id => $other_result ):
|
foreach( $results as $other_team_id => $other_result ):
|
||||||
if ( $other_team_id != $team_id && array_key_exists( $key . 'against', $totals[ $team_id ] ) ):
|
if ( $other_team_id != $team_id && array_key_exists( $key . 'against', $totals[ $team_id ] ) ):
|
||||||
$totals[ $team_id ][ $key . 'against' ] += sp_array_value( $other_result, $key, 0 );
|
$totals[ $team_id ][ $key . 'against' ] += sp_array_value( $other_result, $key, 0 );
|
||||||
|
$totals[ $team_id ][ $key . 'against' . ( $e + 1 ) ] = sp_array_value( $other_result, $key, 0 );
|
||||||
endif;
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
endif;
|
endif;
|
||||||
@@ -279,6 +283,8 @@ class SP_League_Table extends SP_Custom_Post{
|
|||||||
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
|
$e++;
|
||||||
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
foreach ( $streaks as $team_id => $streak ):
|
foreach ( $streaks as $team_id => $streak ):
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
);
|
);
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
if ( $team ):
|
if ( $team && apply_filters( 'sportspress_has_teams', true ) ):
|
||||||
$args['meta_query'] = array(
|
$args['meta_query'] = array(
|
||||||
array(
|
array(
|
||||||
'key' => 'sp_team',
|
'key' => 'sp_team',
|
||||||
@@ -158,8 +158,7 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
foreach ( $result_labels as $key => $value ):
|
foreach ( $result_labels as $key => $value ):
|
||||||
$totals[ $player_id ][ $key . 'for' ] = 0;
|
$totals[ $player_id ][ $key . 'for' ] = $totals[ $player_id ][ $key . 'against' ] = 0;
|
||||||
$totals[ $player_id ][ $key . 'against' ] = 0;
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
// Get metrics
|
// Get metrics
|
||||||
@@ -221,7 +220,7 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
$events = get_posts( $args );
|
$events = get_posts( $args );
|
||||||
|
|
||||||
// Event loop
|
// Event loop
|
||||||
foreach ( $events as $event ):
|
foreach ( $events as $i => $event ):
|
||||||
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
|
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
|
||||||
$team_performance = get_post_meta( $event->ID, 'sp_players', true );
|
$team_performance = get_post_meta( $event->ID, 'sp_players', true );
|
||||||
$minutes = get_post_meta( $event->ID, 'sp_minutes', true );
|
$minutes = get_post_meta( $event->ID, 'sp_minutes', true );
|
||||||
@@ -338,9 +337,14 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
endforeach;
|
endforeach;
|
||||||
endif;
|
endif;
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
// Add to total
|
||||||
$value = sp_array_value( $totals[ $player_id ], $result_slug . 'for', 0 );
|
$value = sp_array_value( $totals[ $player_id ], $result_slug . 'for', 0 );
|
||||||
$value += $team_result;
|
$value += $team_result;
|
||||||
$totals[ $player_id ][ $result_slug . 'for' ] = $value;
|
$totals[ $player_id ][ $result_slug . 'for' ] = $value;
|
||||||
|
|
||||||
|
// Add subset
|
||||||
|
$totals[ $player_id ][ $result_slug . 'for' . ( $i + 1 ) ] = $team_result;
|
||||||
endif;
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
@@ -349,15 +353,21 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
foreach ( $results as $team_results ):
|
foreach ( $results as $team_results ):
|
||||||
unset( $team_results['outcome'] );
|
unset( $team_results['outcome'] );
|
||||||
foreach ( $team_results as $result_slug => $team_result ):
|
foreach ( $team_results as $result_slug => $team_result ):
|
||||||
|
|
||||||
|
// Add to total
|
||||||
$value = sp_array_value( $totals[ $player_id ], $result_slug . 'against', 0 );
|
$value = sp_array_value( $totals[ $player_id ], $result_slug . 'against', 0 );
|
||||||
$value += $team_result;
|
$value += $team_result;
|
||||||
$totals[ $player_id ][ $result_slug . 'against' ] = $value;
|
$totals[ $player_id ][ $result_slug . 'against' ] = $value;
|
||||||
|
|
||||||
|
// Add subset
|
||||||
|
$totals[ $player_id ][ $result_slug . 'against' . ( $i + 1 ) ] = $team_result;
|
||||||
endforeach;
|
endforeach;
|
||||||
endforeach;
|
endforeach;
|
||||||
endif;
|
endif;
|
||||||
endif;
|
endif;
|
||||||
endforeach; endif;
|
endforeach; endif;
|
||||||
endforeach; endif;
|
endforeach; endif;
|
||||||
|
$i++;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
foreach ( $streaks as $player_id => $streak ):
|
foreach ( $streaks as $player_id => $streak ):
|
||||||
@@ -501,7 +511,7 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
foreach( $this->columns as $key ):
|
foreach( $this->columns as $key ):
|
||||||
if ( $key == 'number' ):
|
if ( $key == 'number' ):
|
||||||
$labels[ $key ] = '#';
|
$labels[ $key ] = '#';
|
||||||
elseif ( $key == 'team' ):
|
elseif ( $key == 'team' && apply_filters( 'sportspress_has_teams', true ) ):
|
||||||
$labels[ $key ] = __( 'Team', 'sportspress' );
|
$labels[ $key ] = __( 'Team', 'sportspress' );
|
||||||
elseif ( array_key_exists( $key, $columns ) ):
|
elseif ( array_key_exists( $key, $columns ) ):
|
||||||
$labels[ $key ] = $columns[ $key ];
|
$labels[ $key ] = $columns[ $key ];
|
||||||
@@ -520,7 +530,7 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
$labels = array();
|
$labels = array();
|
||||||
if ( in_array( 'number', $this->columns ) ) $labels['number'] = '#';
|
if ( in_array( 'number', $this->columns ) ) $labels['number'] = '#';
|
||||||
$labels['name'] = __( 'Player', 'sportspress' );
|
$labels['name'] = __( 'Player', 'sportspress' );
|
||||||
if ( in_array( 'team', $this->columns ) ) $labels['team'] = __( 'Team', 'sportspress' );
|
if ( in_array( 'team', $this->columns ) && apply_filters( 'sportspress_has_teams', true ) ) $labels['team'] = __( 'Team', 'sportspress' );
|
||||||
|
|
||||||
$merged[0] = array_merge( $labels, $columns );
|
$merged[0] = array_merge( $labels, $columns );
|
||||||
return $merged;
|
return $merged;
|
||||||
|
|||||||
@@ -93,6 +93,9 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
// Get labels from outcome variables
|
// Get labels from outcome variables
|
||||||
$outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
|
$outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
|
||||||
|
|
||||||
|
// Get labels from result variables
|
||||||
|
$result_labels = (array)sp_get_var_labels( 'sp_result' );
|
||||||
|
|
||||||
// Generate array of all season ids and season names
|
// Generate array of all season ids and season names
|
||||||
$div_ids = array();
|
$div_ids = array();
|
||||||
$season_names = array();
|
$season_names = array();
|
||||||
@@ -129,6 +132,10 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
$totals[ $key ] = 0;
|
$totals[ $key ] = 0;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
|
foreach ( $result_labels as $key => $value ):
|
||||||
|
$totals[ $key . 'for' ] = $totals[ $key . 'against' ] = 0;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
// Initialize streaks counter
|
// Initialize streaks counter
|
||||||
$streak = array( 'name' => '', 'count' => 0, 'fire' => 1 );
|
$streak = array( 'name' => '', 'count' => 0, 'fire' => 1 );
|
||||||
|
|
||||||
@@ -186,7 +193,7 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
$events = get_posts( $args );
|
$events = get_posts( $args );
|
||||||
|
|
||||||
// Event loop
|
// Event loop
|
||||||
foreach( $events as $event ):
|
foreach( $events as $i => $event ):
|
||||||
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
|
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
|
||||||
$team_performance = (array)get_post_meta( $event->ID, 'sp_players', true );
|
$team_performance = (array)get_post_meta( $event->ID, 'sp_players', true );
|
||||||
$minutes = get_post_meta( $event->ID, 'sp_minutes', true );
|
$minutes = get_post_meta( $event->ID, 'sp_minutes', true );
|
||||||
@@ -300,9 +307,14 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
endforeach;
|
endforeach;
|
||||||
endif;
|
endif;
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
// Add to total
|
||||||
$value = sp_array_value( $totals, $result_slug . 'for', 0 );
|
$value = sp_array_value( $totals, $result_slug . 'for', 0 );
|
||||||
$value += $team_result;
|
$value += $team_result;
|
||||||
$totals[ $result_slug . 'for' ] = $value;
|
$totals[ $result_slug . 'for' ] = $value;
|
||||||
|
|
||||||
|
// Add subset
|
||||||
|
$totals[ $result_slug . 'for' . ( $i + 1 ) ] = $team_result;
|
||||||
endif;
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
@@ -311,14 +323,20 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
foreach ( $results as $team_results ):
|
foreach ( $results as $team_results ):
|
||||||
unset( $team_results['outcome'] );
|
unset( $team_results['outcome'] );
|
||||||
foreach ( $team_results as $result_slug => $team_result ):
|
foreach ( $team_results as $result_slug => $team_result ):
|
||||||
|
|
||||||
|
// Add to total
|
||||||
$value = sp_array_value( $totals, $result_slug . 'against', 0 );
|
$value = sp_array_value( $totals, $result_slug . 'against', 0 );
|
||||||
$value += $team_result;
|
$value += $team_result;
|
||||||
$totals[ $result_slug . 'against' ] = $value;
|
$totals[ $result_slug . 'against' ] = $value;
|
||||||
|
|
||||||
|
// Add subset
|
||||||
|
$totals[ $result_slug . 'against' . ( $i + 1 ) ] = $team_result;
|
||||||
endforeach;
|
endforeach;
|
||||||
endforeach;
|
endforeach;
|
||||||
endif;
|
endif;
|
||||||
endif;
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
$i++;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
// Compile streaks counter and add to totals
|
// Compile streaks counter and add to totals
|
||||||
|
|||||||
Reference in New Issue
Block a user