Add Home and Away subsets to Table Column Equation Builder

This commit is contained in:
Brian Miyaji
2015-09-27 15:28:16 +10:00
parent 5c555a53a9
commit 612fcd43c4
5 changed files with 100 additions and 12 deletions

View File

@@ -132,15 +132,31 @@ class SP_League_Table extends SP_Custom_Post{
endforeach;
// Initialize team totals
$totals[ $team_id ] = array( 'eventsplayed' => 0, 'eventminutes' => 0, 'streak' => 0 );
$totals[ $team_id ] = array(
'eventsplayed' => 0,
'eventsplayed_home' => 0,
'eventsplayed_away' => 0,
'eventminutes' => 0,
'eventminutes_home' => 0,
'eventminutes_away' => 0,
'streak' => 0,
'streak_home' => 0,
'streak_away' => 0,
);
foreach ( $result_labels as $key => $value ):
$totals[ $team_id ][ $key . 'for' ] = 0;
$totals[ $team_id ][ $key . 'for_home' ] = 0;
$totals[ $team_id ][ $key . 'for_away' ] = 0;
$totals[ $team_id ][ $key . 'against' ] = 0;
$totals[ $team_id ][ $key . 'against_home' ] = 0;
$totals[ $team_id ][ $key . 'against_away' ] = 0;
endforeach;
foreach ( $outcome_labels as $key => $value ):
$totals[ $team_id ][ $key ] = 0;
$totals[ $team_id ][ $key . '_home' ] = 0;
$totals[ $team_id ][ $key . '_away' ] = 0;
endforeach;
// Get static stats
@@ -227,6 +243,16 @@ class SP_League_Table extends SP_Custom_Post{
$totals[ $team_id ]['eventsplayed'] ++;
$totals[ $team_id ]['eventminutes'] += $minutes;
$totals[ $team_id ][ $outcome ] ++;
if ( sp_is_home_venue( $team_id, $event->ID ) ):
$totals[ $team_id ]['eventsplayed_home'] ++;
$totals[ $team_id ]['eventminutes_home'] += $minutes;
$totals[ $team_id ][ $outcome . '_home' ] ++;
else:
$totals[ $team_id ]['eventsplayed_away'] ++;
$totals[ $team_id ]['eventminutes_away'] += $minutes;
$totals[ $team_id ][ $outcome . '_away' ] ++;
endif;
endif;
if ( $outcome && $outcome != '-1' ):
@@ -268,10 +294,23 @@ class SP_League_Table extends SP_Custom_Post{
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' . ( $e + 1 ) ] = $value;
if ( sp_is_home_venue( $team_id, $event->ID ) ):
$totals[ $team_id ][ $key . 'for_home' ] += $value;
else:
$totals[ $team_id ][ $key . 'for_away' ] += $value;
endif;
foreach( $results as $other_team_id => $other_result ):
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' . ( $e + 1 ) ] = sp_array_value( $other_result, $key, 0 );
if ( sp_is_home_venue( $team_id, $event->ID ) ):
$totals[ $team_id ][ $key . 'against_home' ] += sp_array_value( $other_result, $key, 0 );
else:
$totals[ $team_id ][ $key . 'against_away' ] += sp_array_value( $other_result, $key, 0 );
endif;
endif;
endforeach;
endif;