Add Home and Away subsets to Table Column Equation Builder
This commit is contained in:
@@ -77,15 +77,35 @@ class SP_Team extends SP_Custom_Post {
|
||||
|
||||
foreach ( $div_ids as $div_id ):
|
||||
|
||||
$totals = array( 'eventsplayed' => 0, 'eventminutes' => 0, 'streak' => 0, 'last5' => null, 'last10' => null, 'homerecord' => null, 'awayrecord' => null );
|
||||
$totals = 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,
|
||||
'last5' => null,
|
||||
'last10' => null,
|
||||
'homerecord' => null,
|
||||
'awayrecord' => null
|
||||
);
|
||||
|
||||
foreach ( $result_labels as $key => $value ):
|
||||
$totals[ $key . 'for' ] = 0;
|
||||
$totals[ $key . 'for_home' ] = 0;
|
||||
$totals[ $key . 'for_away' ] = 0;
|
||||
$totals[ $key . 'against' ] = 0;
|
||||
$totals[ $key . 'against_home' ] = 0;
|
||||
$totals[ $key . 'against_away' ] = 0;
|
||||
endforeach;
|
||||
|
||||
foreach ( $outcome_labels as $key => $value ):
|
||||
$totals[ $key ] = 0;
|
||||
$totals[ $key . '_home' ] = 0;
|
||||
$totals[ $key . '_away' ] = 0;
|
||||
endforeach;
|
||||
|
||||
// Initialize streaks counter
|
||||
@@ -151,6 +171,8 @@ class SP_Team extends SP_Custom_Post {
|
||||
|
||||
$events = get_posts( $args );
|
||||
|
||||
$e = 0;
|
||||
|
||||
foreach( $events as $event ):
|
||||
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
|
||||
$minutes = get_post_meta( $event->ID, 'sp_minutes', true );
|
||||
@@ -175,6 +197,16 @@ class SP_Team extends SP_Custom_Post {
|
||||
$totals['eventsplayed'] ++;
|
||||
$totals['eventminutes'] += $minutes;
|
||||
$totals[ $outcome ] ++;
|
||||
|
||||
if ( sp_is_home_venue( $team_id, $event->ID ) ):
|
||||
$totals['eventsplayed_home'] ++;
|
||||
$totals['eventminutes_home'] += $minutes;
|
||||
$totals[ $outcome . '_home' ] ++;
|
||||
else:
|
||||
$totals['eventsplayed_away'] ++;
|
||||
$totals['eventminutes_away'] += $minutes;
|
||||
$totals[ $outcome . '_away' ] ++;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $outcome && $outcome != '-1' ):
|
||||
@@ -215,18 +247,33 @@ class SP_Team extends SP_Custom_Post {
|
||||
else:
|
||||
if ( array_key_exists( $key . 'for', $totals ) ):
|
||||
$totals[ $key . 'for' ] += $value;
|
||||
$totals[ $key . 'for' . ( $e + 1 ) ] = $value;
|
||||
|
||||
if ( sp_is_home_venue( $team_id, $event->ID ) ):
|
||||
$totals[ $key . 'for_home' ] += $value;
|
||||
else:
|
||||
$totals[ $key . 'for_away' ] += $value;
|
||||
endif;
|
||||
endif;
|
||||
endif;
|
||||
else:
|
||||
if ( $key != 'outcome' ):
|
||||
if ( array_key_exists( $key . 'against', $totals ) ):
|
||||
$totals[ $key . 'against' ] += $value;
|
||||
$totals[ $key . 'against' . ( $e + 1 ) ] = $value;
|
||||
|
||||
if ( sp_is_home_venue( $team_id, $event->ID ) ):
|
||||
$totals[ $key . 'against_home' ] += $value;
|
||||
else:
|
||||
$totals[ $key . 'against_away' ] += $value;
|
||||
endif;
|
||||
endif;
|
||||
endif;
|
||||
endif;
|
||||
endforeach; endif;
|
||||
$i++;
|
||||
endforeach;
|
||||
$e++;
|
||||
endforeach;
|
||||
|
||||
// Compile streaks counter and add to totals
|
||||
|
||||
Reference in New Issue
Block a user