From fdca8e72b3af26d86b5a03f32472fc3942cf010c Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 10 Dec 2014 10:01:59 +1100 Subject: [PATCH] Enable individual player outcomes --- .../class-sp-meta-box-event-performance.php | 34 +++++++++++++-- includes/class-sp-player-list.php | 42 +++++++++++++++++- includes/class-sp-player.php | 43 ++++++++++++++++++- 3 files changed, 112 insertions(+), 7 deletions(-) diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php index 0e66064c..435bbf87 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php @@ -88,7 +88,13 @@ class SP_Meta_Box_Event_Performance { - + + + + + + + @@ -105,9 +111,7 @@ class SP_Meta_Box_Event_Performance { ?> - -   - +   @@ -151,6 +155,28 @@ class SP_Meta_Box_Event_Performance { + + + 'sp_outcome', + 'name' => 'sp_players[' . $team_id . '][' . $player_id . '][outcome][]', + 'option_none_value' => '', + 'sort_order' => 'ASC', + 'sort_column' => 'menu_order', + 'selected' => $values, + 'class' => 'sp-outcome', + 'property' => 'multiple', + 'chosen' => true, + 'placeholder' => __( 'None', 'sportspress' ), + ); + sp_dropdown_pages( $args ); + ?> + $value ): - if ( array_key_exists( $key, $totals[ $player_id ] ) ): + if ( 'outcome' == $key ): + // Increment events attended, played, and started + $totals[ $player_id ]['eventsattended'] ++; + $totals[ $player_id ]['eventsplayed'] ++; + $totals[ $player_id ]['eventsstarted'] ++; + $totals[ $player_id ]['eventminutes'] += $minutes; + + // Convert to array + if ( ! is_array( $value ) ): + $value = array( $value ); + endif; + + foreach ( $value as $outcome ): + + if ( $outcome && $outcome != '-1' ): + + // Increment events attended and outcome count + if ( array_key_exists( $outcome, $totals[ $player_id ] ) ): + $totals[ $player_id ][ $outcome ] ++; + endif; + + // Add to streak counter + if ( $streaks[ $player_id ]['fire'] && ( $streaks[ $player_id ]['name'] == '' || $streaks[ $player_id ]['name'] == $outcome ) ): + $streaks[ $player_id ]['name'] = $outcome; + $streaks[ $player_id ]['count'] ++; + else: + $streaks[ $player_id ]['fire'] = 0; + endif; + + // Add to last 5 counter if sum is less than 5 + if ( array_key_exists( $player_id, $last5s ) && array_key_exists( $outcome, $last5s[ $player_id ] ) && array_sum( $last5s[ $player_id ] ) < 5 ): + $last5s[ $player_id ][ $outcome ] ++; + endif; + + // Add to last 10 counter if sum is less than 10 + if ( array_key_exists( $player_id, $last10s ) && array_key_exists( $outcome, $last10s[ $player_id ] ) && array_sum( $last10s[ $player_id ] ) < 10 ): + $last10s[ $player_id ][ $outcome ] ++; + endif; + endif; + endforeach; + elseif ( array_key_exists( $key, $totals[ $player_id ] ) ): $totals[ $player_id ][ $key ] += $value; endif; endforeach; diff --git a/includes/class-sp-player.php b/includes/class-sp-player.php index ce9ea682..d1dc720e 100644 --- a/includes/class-sp-player.php +++ b/includes/class-sp-player.php @@ -176,7 +176,46 @@ class SP_Player extends SP_Custom_Post { $player_performance = sp_array_value( $players, $this->ID, array() ); foreach ( $player_performance as $key => $value ): - if ( array_key_exists( $key, $totals ) ): + if ( 'outcome' == $key ): + // Increment events attended, played, and started + $totals['eventsattended'] ++; + $totals['eventsplayed'] ++; + $totals['eventsstarted'] ++; + $totals['eventminutes'] += $minutes; + + // Convert to array + if ( ! is_array( $value ) ): + $value = array( $value ); + endif; + + foreach ( $value as $outcome ): + if ( $outcome && $outcome != '-1' ): + + // Increment outcome count + if ( array_key_exists( $outcome, $totals ) ): + $totals[ $outcome ] ++; + endif; + + // Add to streak counter + if ( $streak['fire'] && ( $streak['name'] == '' || $streak['name'] == $outcome ) ): + $streak['name'] = $outcome; + $streak['count'] ++; + else: + $streak['fire'] = 0; + endif; + + // Add to last 5 counter if sum is less than 5 + if ( array_key_exists( $outcome, $last5 ) && array_sum( $last5 ) < 5 ): + $last5[ $outcome ] ++; + endif; + + // Add to last 10 counter if sum is less than 10 + if ( array_key_exists( $outcome, $last10 ) && array_sum( $last10 ) < 10 ): + $last10[ $outcome ] ++; + endif; + endif; + endforeach; + elseif ( array_key_exists( $key, $totals ) ): $totals[ $key ] += $value; endif; endforeach; @@ -207,7 +246,7 @@ class SP_Player extends SP_Custom_Post { $value = array( $value ); endif; - foreach( $value as $outcome ): + foreach ( $value as $outcome ): if ( $outcome && $outcome != '-1' ): // Increment outcome count