Add "Next Team" preset to league tables

This commit is contained in:
Brian Miyaji
2018-05-02 13:53:19 +10:00
parent 52f96851b1
commit 0722a9fb49
4 changed files with 140 additions and 7 deletions

View File

@@ -618,12 +618,12 @@ class SP_League_Table extends SP_Secondary_Post {
endif;
else:
// Solve
$placeholder = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision );
$placeholder = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision, 0, $team_id );
if ( '$gamesback' == $stat->equation )
$gb_column = $stat->post_name;
if ( ! in_array( $stat->equation, array( '$gamesback', '$streak', '$form', '$last5', '$last10', '$homerecord', '$awayrecord' ) ) ):
if ( ! in_array( $stat->equation, apply_filters( 'sportspress_equation_presets', array( '$gamesback', '$streak', '$form', '$last5', '$last10', '$homerecord', '$awayrecord' ) ) ) ):
// Adjustments
$adjustment = sp_array_value( $adjustments, $team_id, array() );

View File

@@ -1290,10 +1290,10 @@ if ( !function_exists( 'sp_get_eos_safe_slug' ) ) {
}
if ( !function_exists( 'sp_solve' ) ) {
function sp_solve( $equation, $vars, $precision = 0, $default = 0 ) {
function sp_solve( $equation, $vars, $precision = 0, $default = 0, $post_id = 0 ) {
// Add a hook to alter $equation
$equation = apply_filters( 'sportspress_equation_alter', $equation, $vars );
$equation = apply_filters( 'sportspress_equation_alter', $equation, $vars, $precision, $default );
if ( $equation == null )
return $default;
@@ -1347,6 +1347,10 @@ if ( !function_exists( 'sp_solve' ) ) {
endif;
if ( $solution = apply_filters( 'sportspress_equation_solve_for_presets', null, $equation, $post_id ) ):
return $solution;
endif;
// Remove unnecessary variables from vars before calculating
unset( $vars['gamesback'] );
unset( $vars['streak'] );