Enable individual player outcomes

This commit is contained in:
Brian Miyaji
2014-12-10 10:01:59 +11:00
parent 949c143ab9
commit fdca8e72b3
3 changed files with 112 additions and 7 deletions

View File

@@ -154,7 +154,47 @@ class SP_Player_List extends SP_Custom_Post {
$player_performance = sp_array_value( $players, $player_id, array() );
foreach ( $player_performance as $key => $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;