Adjust minutes calculation in player statistics for substitution time

This commit is contained in:
Brian Miyaji
2017-01-11 15:14:09 +11:00
parent a30fa206bc
commit bb66ed2e07
2 changed files with 34 additions and 0 deletions

View File

@@ -336,6 +336,7 @@ class SP_Player extends SP_Custom_Post {
foreach( $events as $i => $event ):
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
$team_performance = (array)get_post_meta( $event->ID, 'sp_players', true );
$timeline = (array)get_post_meta( $event->ID, 'sp_timeline', true );
$minutes = get_post_meta( $event->ID, 'sp_minutes', true );
if ( $minutes === '' ) $minutes = get_option( 'sportspress_event_minutes', 90 );
@@ -405,6 +406,22 @@ class SP_Player extends SP_Custom_Post {
$totals['eventsplayed'] ++;
$totals['eventminutes'] += $minutes;
// Adjust for substitution time
if ( sp_array_value( $player_performance, 'status' ) === 'sub' ):
$totals['eventminutes'] -= sp_array_value( sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $this->ID ), 'sub' ), 0, 0 );
else:
foreach ( $timeline as $timeline_team => $timeline_players ):
foreach ( $timeline_players as $timeline_player => $timeline_performance ):
if ( 'sub' === sp_array_value( sp_array_value( $players, $timeline_player, array() ), 'status' ) && $this->ID === (int) sp_array_value( sp_array_value( $players, $timeline_player, array() ), 'sub', 0 ) ):
$substitution_time = sp_array_value( sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $timeline_player ), 'sub' ), 0, 0 );
if ( $substitution_time ):
$totals['eventminutes'] += $substitution_time - $minutes;
endif;
endif;
endforeach;
endforeach;
endif;
if ( sp_array_value( $player_performance, 'status' ) == 'lineup' ):
$totals['eventsstarted'] ++;
elseif ( sp_array_value( $player_performance, 'status' ) == 'sub' && sp_array_value( $player_performance, 'sub', 0 ) ):