diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-performance-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-performance-details.php index 0c421f03..d0150e61 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-performance-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-performance-details.php @@ -48,6 +48,10 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config { if ( '' === $timed ) { $timed = true; } + $sendoff = get_post_meta( $post->ID, 'sp_sendoff', true ); + if ( '' === $sendoff ) { + $sendoff = false; + } ?>

@@ -106,6 +110,26 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config { +

+

+ + "> +

+ +
ID, 'sp_visible', true ); @@ -145,6 +169,7 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config { update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'number' ) ); update_post_meta( $post_id, 'sp_precision', sp_array_value( $_POST, 'sp_precision', 0 ) ); update_post_meta( $post_id, 'sp_timed', sp_array_value( $_POST, 'sp_timed', 0 ) ); + update_post_meta( $post_id, 'sp_sendoff', sp_array_value( $_POST, 'sp_sendoff', 0 ) ); if ( 'auto' === get_option( 'sportspress_player_columns', 'auto' ) ) { update_post_meta( $post_id, 'sp_visible', sp_array_value( $_POST, 'sp_visible', 1 ) ); } diff --git a/includes/class-sp-player-list.php b/includes/class-sp-player-list.php index c69779b3..5beb23ae 100644 --- a/includes/class-sp-player-list.php +++ b/includes/class-sp-player-list.php @@ -147,6 +147,85 @@ class SP_Player_List extends SP_Custom_Post { $last5s = array(); $last10s = array(); + $args = array( + 'post_type' => array( 'sp_performance', 'sp_metric', 'sp_statistic' ), + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC', + 'meta_query' => array( + 'relation' => 'OR', + array( + 'key' => 'sp_format', + 'value' => 'number', + 'compare' => 'NOT EXISTS', + ), + array( + 'key' => 'sp_format', + 'value' => array( 'equation', 'text' ), + 'compare' => 'NOT IN', + ), + ), + ); + $stats = get_posts( $args ); + + $formats = array(); + $sendoffs = array(); + $data = array(); + $merged = array(); + $column_order = array(); + $ordered_columns = array(); + + if ( $stats ): + + foreach ( $stats as $stat ): + + // Get post meta + $meta = get_post_meta( $stat->ID ); + + // Add equation to object + if ( $stat->post_type == 'sp_metric' ): + $stat->equation = null; + else: + $stat->equation = sp_array_value( sp_array_value( $meta, 'sp_equation', array() ), 0, 0 ); + endif; + + // Add precision to object + $stat->precision = sp_array_value( sp_array_value( $meta, 'sp_precision', array() ), 0, 0 ) + 0; + + // Add column name to columns + $columns[ $stat->post_name ] = $stat->post_title; + + // Add format + $format = get_post_meta( $stat->ID, 'sp_format', true ); + if ( '' === $format ) { + $format = 'number'; + } + $formats[ $stat->post_name ] = $format; + + // Add sendoffs + $sendoff = get_post_meta( $stat->ID, 'sp_sendoff', true ); + if ( $sendoff ) { + $sendoffs[] = $stat->post_name; + } + + $column_order[] = $stat->post_name; + + endforeach; + + endif; + + foreach ( $column_order as $slug ): + + if ( ! in_array( $slug, $this->columns ) ) continue; + + $ordered_columns[] = $slug; + + endforeach; + + $diff = array_diff( $this->columns, $ordered_columns ); + $this->columns = array_merge( $diff, $ordered_columns ); + foreach ( $player_ids as $player_id ): if ( ! $player_id ) continue; @@ -332,7 +411,19 @@ class SP_Player_List extends SP_Custom_Post { // Adjust for substitution time if ( sp_array_value( $player_performance, 'status' ) === 'sub' ): $totals[ $player_id ]['eventminutes'] -= sp_array_value( sp_array_value( sp_array_value( sp_array_value( $timeline, $team_id ), $player_id ), 'sub' ), 0, 0 ); + + $timeline_performance = sp_array_value( sp_array_value( $timeline, $team_id, array() ), $player_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 ), $player_id ), $sendoff_key ); + $sendoff_times = array_filter( $sendoff_times ); + $sendoff_time = end( $sendoff_times ); + if ( ! $sendoff_time ) $sendoff_time = 0; + $totals[ $player_id ]['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 ): @@ -340,9 +431,22 @@ class SP_Player_List 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[ $player_id ]['eventminutes'] += $substitution_time - $minutes; + $subbed_out = true; endif; endif; endforeach; + + if ( $subbed_out ) continue; + $timeline_performance = sp_array_value( $timeline_players, $player_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 ), $player_id ), $sendoff_key ); + $sendoff_times = array_filter( $sendoff_times ); + $sendoff_time = end( $sendoff_times ); + if ( ! $sendoff_time ) $sendoff_time = 0; + $totals[ $player_id ]['eventminutes'] += $sendoff_time - $minutes; + endforeach; endforeach; endif; @@ -457,78 +561,6 @@ class SP_Player_List extends SP_Custom_Post { $totals[ $player_id ]['last10'] = $last10; endforeach; - $args = array( - 'post_type' => array( 'sp_performance', 'sp_metric', 'sp_statistic' ), - 'numberposts' => -1, - 'posts_per_page' => -1, - 'orderby' => 'menu_order', - 'order' => 'ASC', - 'meta_query' => array( - 'relation' => 'OR', - array( - 'key' => 'sp_format', - 'value' => 'number', - 'compare' => 'NOT EXISTS', - ), - array( - 'key' => 'sp_format', - 'value' => array( 'equation', 'text' ), - 'compare' => 'NOT IN', - ), - ), - ); - $stats = get_posts( $args ); - - $formats = array(); - $data = array(); - $merged = array(); - $column_order = array(); - $ordered_columns = array(); - - if ( $stats ): - - foreach ( $stats as $stat ): - - // Get post meta - $meta = get_post_meta( $stat->ID ); - - // Add equation to object - if ( $stat->post_type == 'sp_metric' ): - $stat->equation = null; - else: - $stat->equation = sp_array_value( sp_array_value( $meta, 'sp_equation', array() ), 0, 0 ); - endif; - - // Add precision to object - $stat->precision = sp_array_value( sp_array_value( $meta, 'sp_precision', array() ), 0, 0 ) + 0; - - // Add column name to columns - $columns[ $stat->post_name ] = $stat->post_title; - - // Add format - $format = get_post_meta( $stat->ID, 'sp_format', true ); - if ( '' === $format ) { - $format = 'number'; - } - $formats[ $stat->post_name ] = $format; - - $column_order[] = $stat->post_name; - - endforeach; - - endif; - - foreach ( $column_order as $slug ): - - if ( ! in_array( $slug, $this->columns ) ) continue; - - $ordered_columns[] = $slug; - - endforeach; - - $diff = array_diff( $this->columns, $ordered_columns ); - $this->columns = array_merge( $diff, $ordered_columns ); - // Fill in empty placeholder values for each player foreach ( $player_ids as $player_id ): if ( ! $player_id ) diff --git a/includes/class-sp-player.php b/includes/class-sp-player.php index daa393ba..ff6beefd 100644 --- a/includes/class-sp-player.php +++ b/includes/class-sp-player.php @@ -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;