Add event results to equation builder
This commit is contained in:
@@ -23,7 +23,7 @@ class SP_Meta_Box_Statistic_Equation extends SP_Meta_Box_Equation {
|
|||||||
*/
|
*/
|
||||||
public static function output( $post ) {
|
public static function output( $post ) {
|
||||||
$equation = get_post_meta( $post->ID, 'sp_equation', true );
|
$equation = get_post_meta( $post->ID, 'sp_equation', true );
|
||||||
$groups = array( 'player_event', 'outcome', 'performance', 'metric' );
|
$groups = array( 'player_event', 'outcome', 'result', 'performance', 'metric' );
|
||||||
self::builder( $post->post_title, $equation, $groups );
|
self::builder( $post->post_title, $equation, $groups );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
// Get labels from outcome variables
|
// Get labels from outcome variables
|
||||||
$outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
|
$outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
|
||||||
|
|
||||||
|
// Get labels from result variables
|
||||||
|
$result_labels = (array)sp_get_var_labels( 'sp_result' );
|
||||||
|
|
||||||
// Get players automatically if set to auto
|
// Get players automatically if set to auto
|
||||||
if ( 'auto' == $select ) {
|
if ( 'auto' == $select ) {
|
||||||
$player_ids = array();
|
$player_ids = array();
|
||||||
@@ -148,13 +151,17 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
|
|
||||||
foreach ( $performance_labels as $key => $value ):
|
foreach ( $performance_labels as $key => $value ):
|
||||||
$totals[ $player_id ][ $key ] = 0;
|
$totals[ $player_id ][ $key ] = 0;
|
||||||
$totals[ $player_id ][ $key ] = 0;
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
foreach ( $outcome_labels as $key => $value ):
|
foreach ( $outcome_labels as $key => $value ):
|
||||||
$totals[ $player_id ][ $key ] = 0;
|
$totals[ $player_id ][ $key ] = 0;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
|
foreach ( $result_labels as $key => $value ):
|
||||||
|
$totals[ $player_id ][ $key . 'for' ] = 0;
|
||||||
|
$totals[ $player_id ][ $key . 'against' ] = 0;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
// Get metrics
|
// Get metrics
|
||||||
$metrics = (array) get_post_meta( $player_id, 'sp_metrics', true );
|
$metrics = (array) get_post_meta( $player_id, 'sp_metrics', true );
|
||||||
foreach ( $metrics as $key => $value ):
|
foreach ( $metrics as $key => $value ):
|
||||||
@@ -274,9 +281,11 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
$team_results = sp_array_value( $results, $team_id, array() );
|
$team_results = sp_array_value( $results, $team_id, array() );
|
||||||
|
unset( $results[ $team_id ] );
|
||||||
|
|
||||||
// Find the outcome
|
// Loop through home team
|
||||||
if ( array_key_exists( 'outcome', $team_results ) ):
|
foreach ( $team_results as $result_slug => $team_result ):
|
||||||
|
if ( 'outcome' == $result_slug ):
|
||||||
|
|
||||||
// Increment events attended
|
// Increment events attended
|
||||||
$totals[ $player_id ]['eventsattended'] ++;
|
$totals[ $player_id ]['eventsattended'] ++;
|
||||||
@@ -292,7 +301,7 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
$totals[ $player_id ]['eventssubbed'] ++;
|
$totals[ $player_id ]['eventssubbed'] ++;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
$value = $team_results['outcome'];
|
$value = $team_result;
|
||||||
|
|
||||||
// Convert to array
|
// Convert to array
|
||||||
if ( ! is_array( $value ) ):
|
if ( ! is_array( $value ) ):
|
||||||
@@ -328,6 +337,23 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
endif;
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
endif;
|
endif;
|
||||||
|
else:
|
||||||
|
$value = sp_array_value( $totals[ $player_id ], $result_slug . 'for', 0 );
|
||||||
|
$value += $team_result;
|
||||||
|
$totals[ $player_id ][ $result_slug . 'for' ] = $value;
|
||||||
|
endif;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
// Loop through away teams
|
||||||
|
if ( sizeof( $results ) ):
|
||||||
|
foreach ( $results as $team_results ):
|
||||||
|
unset( $team_results['outcome'] );
|
||||||
|
foreach ( $team_results as $result_slug => $team_result ):
|
||||||
|
$value = sp_array_value( $totals[ $player_id ], $result_slug . 'against', 0 );
|
||||||
|
$value += $team_result;
|
||||||
|
$totals[ $player_id ][ $result_slug . 'against' ] = $value;
|
||||||
|
endforeach;
|
||||||
|
endforeach;
|
||||||
endif;
|
endif;
|
||||||
endif;
|
endif;
|
||||||
endforeach; endif;
|
endforeach; endif;
|
||||||
@@ -347,7 +373,9 @@ class SP_Player_List extends SP_Custom_Post {
|
|||||||
|
|
||||||
if ( $outcomes ):
|
if ( $outcomes ):
|
||||||
$outcome = reset( $outcomes );
|
$outcome = reset( $outcomes );
|
||||||
$totals[ $player_id ]['streak'] = $outcome->post_title . $streak['count'];
|
$abbreviation = sp_get_abbreviation( $outcome->ID );
|
||||||
|
if ( empty( $abbreviation ) ) $abbreviation = strtoupper( substr( $outcome->post_title, 0, 1 ) );
|
||||||
|
$totals[ $player_id ]['streak'] = $abbreviation . $streak['count'];
|
||||||
else:
|
else:
|
||||||
$totals[ $player_id ]['streak'] = null;
|
$totals[ $player_id ]['streak'] = null;
|
||||||
endif;
|
endif;
|
||||||
|
|||||||
@@ -244,9 +244,11 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
$team_results = sp_array_value( $results, $team_id, array() );
|
$team_results = sp_array_value( $results, $team_id, array() );
|
||||||
|
unset( $results[ $team_id ] );
|
||||||
|
|
||||||
// Find the outcome
|
// Loop through home team
|
||||||
if ( array_key_exists( 'outcome', $team_results ) ):
|
foreach ( $team_results as $result_slug => $team_result ):
|
||||||
|
if ( 'outcome' == $result_slug ):
|
||||||
|
|
||||||
// Increment events attended
|
// Increment events attended
|
||||||
$totals['eventsattended'] ++;
|
$totals['eventsattended'] ++;
|
||||||
@@ -262,7 +264,7 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
$totals['eventssubbed'] ++;
|
$totals['eventssubbed'] ++;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
$value = $team_results['outcome'];
|
$value = $team_result;
|
||||||
|
|
||||||
// Convert to array
|
// Convert to array
|
||||||
if ( ! is_array( $value ) ):
|
if ( ! is_array( $value ) ):
|
||||||
@@ -297,6 +299,23 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
endif;
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
endif;
|
endif;
|
||||||
|
else:
|
||||||
|
$value = sp_array_value( $totals, $result_slug . 'for', 0 );
|
||||||
|
$value += $team_result;
|
||||||
|
$totals[ $result_slug . 'for' ] = $value;
|
||||||
|
endif;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
// Loop through away teams
|
||||||
|
if ( sizeof( $results ) ):
|
||||||
|
foreach ( $results as $team_results ):
|
||||||
|
unset( $team_results['outcome'] );
|
||||||
|
foreach ( $team_results as $result_slug => $team_result ):
|
||||||
|
$val = sp_array_value( $totals, $result_slug . 'against', 0 );
|
||||||
|
$val += $team_result;
|
||||||
|
$totals[ $result_slug . 'against' ] = $val;
|
||||||
|
endforeach;
|
||||||
|
endforeach;
|
||||||
endif;
|
endif;
|
||||||
endif;
|
endif;
|
||||||
endforeach;
|
endforeach;
|
||||||
@@ -313,7 +332,9 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
|
|
||||||
if ( $outcomes ):
|
if ( $outcomes ):
|
||||||
$outcome = reset( $outcomes );
|
$outcome = reset( $outcomes );
|
||||||
$totals['streak'] = $outcome->post_title . $streak['count'];
|
$abbreviation = sp_get_abbreviation( $outcome->ID );
|
||||||
|
if ( empty( $abbreviation ) ) $abbreviation = strtoupper( substr( $outcome->post_title, 0, 1 ) );
|
||||||
|
$totals['streak'] = $abbreviation . $streak['count'];
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
// Add last counters to totals
|
// Add last counters to totals
|
||||||
|
|||||||
Reference in New Issue
Block a user