Add sendoff option to player performance variables
This commit is contained in:
@@ -161,6 +161,7 @@ class SP_Player extends SP_Custom_Post {
|
||||
|
||||
$performance_labels = array();
|
||||
$formats = array();
|
||||
$sendoffs = array();
|
||||
|
||||
foreach ( $posts as $post ):
|
||||
if ( -1 === $section ) {
|
||||
@@ -182,6 +183,11 @@ class SP_Player extends SP_Custom_Post {
|
||||
$format = 'number';
|
||||
}
|
||||
$formats[ $post->post_name ] = $format;
|
||||
|
||||
$sendoff = get_post_meta( $post->ID, 'sp_sendoff', true );
|
||||
if ( $sendoff ) {
|
||||
$sendoffs[] = $post->post_name;
|
||||
}
|
||||
endforeach;
|
||||
|
||||
// Get statistic labels
|
||||
@@ -358,7 +364,19 @@ class SP_Player extends SP_Custom_Post {
|
||||
// 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 );
|
||||
|
||||
$timeline_performance = sp_array_value( sp_array_value( $timeline, $team_id, array() ), $this->ID, array() );
|
||||
if ( empty( $timeline_performance ) ) continue;
|
||||
foreach ( $sendoffs as $sendoff_key ):
|
||||
if ( ! array_key_exists( $sendoff_key, $timeline_performance ) ) continue;
|
||||
$sendoff_times = sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $this->ID ), $sendoff_key );
|
||||
$sendoff_times = array_filter( $sendoff_times );
|
||||
$sendoff_time = end( $sendoff_times );
|
||||
if ( ! $sendoff_time ) $sendoff_time = 0;
|
||||
$totals['eventminutes'] += $sendoff_time - $minutes;
|
||||
endforeach;
|
||||
else:
|
||||
$subbed_out = false;
|
||||
foreach ( $timeline as $timeline_team => $timeline_players ):
|
||||
if ( ! is_array( $timeline_players ) ) continue;
|
||||
foreach ( $timeline_players as $timeline_player => $timeline_performance ):
|
||||
@@ -366,9 +384,22 @@ class SP_Player extends SP_Custom_Post {
|
||||
$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;
|
||||
$subbed_out = true;
|
||||
endif;
|
||||
endif;
|
||||
endforeach;
|
||||
|
||||
if ( $subbed_out ) continue;
|
||||
$timeline_performance = sp_array_value( $timeline_players, $this->ID, array() );
|
||||
if ( empty( $timeline_performance ) ) continue;
|
||||
foreach ( $sendoffs as $sendoff_key ):
|
||||
if ( ! array_key_exists( $sendoff_key, $timeline_performance ) ) continue;
|
||||
$sendoff_times = sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $this->ID ), $sendoff_key );
|
||||
$sendoff_times = array_filter( $sendoff_times );
|
||||
$sendoff_time = end( $sendoff_times );
|
||||
if ( ! $sendoff_time ) $sendoff_time = 0;
|
||||
$totals['eventminutes'] += $sendoff_time - $minutes;
|
||||
endforeach;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user