diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-column-equation.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-column-equation.php
index 677dc423..a79e7961 100644
--- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-column-equation.php
+++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-column-equation.php
@@ -23,6 +23,6 @@ class SP_Meta_Box_Column_Equation extends SP_Meta_Box_Equation {
*/
public static function output( $post ) {
$equation = get_post_meta( $post->ID, 'sp_equation', true );
- self::builder( $post->post_title, $equation, array( 'team_event', 'outcome', 'result' ) );
+ self::builder( $post->post_title, $equation, array( 'team_event', 'outcome', 'result', 'subset', 'preset' ) );
}
}
\ No newline at end of file
diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-equation.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-equation.php
index b129a4c4..9c8fb6b3 100644
--- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-equation.php
+++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-equation.php
@@ -41,12 +41,12 @@ class SP_Meta_Box_Equation {
break;
case 'outcome':
$options[ 'Outcomes' ] = self::optgroup( 'sp_outcome' );
- $options[ 'Outcomes' ]['$gamesback'] = __( 'Games Back', 'sportspress' );
- $options[ 'Outcomes' ]['$homerecord'] = __( 'Home Record', 'sportspress' );
- $options[ 'Outcomes' ]['$awayrecord'] = __( 'Away Record', 'sportspress' );
- $options[ 'Outcomes' ]['$streak'] = __( 'Streak', 'sportspress' );
- $options[ 'Outcomes' ]['$last5'] = __( 'Last 5', 'sportspress' );
- $options[ 'Outcomes' ]['$last10'] = __( 'Last 10', 'sportspress' );
+ break;
+ case 'preset':
+ $options[ 'Presets' ] = array( '$gamesback' => __( 'Games Back', 'sportspress' ), '$homerecord' => __( 'Home Record', 'sportspress' ), '$awayrecord' => __( 'Away Record', 'sportspress' ), '$streak' => __( 'Streak', 'sportspress' ), '$last5' => __( 'Last 5', 'sportspress' ), '$last10' => __( 'Last 10', 'sportspress' ) );
+ break;
+ case 'subset':
+ $options[ 'Subsets' ] = array( '_home' => '@' . __( 'Home', 'sportspress' ), '_away' => '@' . __( 'Away', 'sportspress' ) );
break;
case 'performance':
$options[ 'Performance' ] = self::optgroup( 'sp_performance' );
@@ -151,7 +151,9 @@ class SP_Meta_Box_Equation {
* @return null
*/
public static function equation_part_labels() {
+ __( 'Presets', 'sportspress' );
__( 'Operators', 'sportspress' );
+ __( 'Subsets', 'sportspress' );
__( 'Constants', 'sportspress' );
}
}
\ No newline at end of file
diff --git a/includes/class-sp-league-table.php b/includes/class-sp-league-table.php
index d7466060..90d3fec4 100644
--- a/includes/class-sp-league-table.php
+++ b/includes/class-sp-league-table.php
@@ -132,15 +132,31 @@ class SP_League_Table extends SP_Custom_Post{
endforeach;
// Initialize team totals
- $totals[ $team_id ] = array( 'eventsplayed' => 0, 'eventminutes' => 0, 'streak' => 0 );
+ $totals[ $team_id ] = array(
+ 'eventsplayed' => 0,
+ 'eventsplayed_home' => 0,
+ 'eventsplayed_away' => 0,
+ 'eventminutes' => 0,
+ 'eventminutes_home' => 0,
+ 'eventminutes_away' => 0,
+ 'streak' => 0,
+ 'streak_home' => 0,
+ 'streak_away' => 0,
+ );
foreach ( $result_labels as $key => $value ):
$totals[ $team_id ][ $key . 'for' ] = 0;
+ $totals[ $team_id ][ $key . 'for_home' ] = 0;
+ $totals[ $team_id ][ $key . 'for_away' ] = 0;
$totals[ $team_id ][ $key . 'against' ] = 0;
+ $totals[ $team_id ][ $key . 'against_home' ] = 0;
+ $totals[ $team_id ][ $key . 'against_away' ] = 0;
endforeach;
foreach ( $outcome_labels as $key => $value ):
$totals[ $team_id ][ $key ] = 0;
+ $totals[ $team_id ][ $key . '_home' ] = 0;
+ $totals[ $team_id ][ $key . '_away' ] = 0;
endforeach;
// Get static stats
@@ -227,6 +243,16 @@ class SP_League_Table extends SP_Custom_Post{
$totals[ $team_id ]['eventsplayed'] ++;
$totals[ $team_id ]['eventminutes'] += $minutes;
$totals[ $team_id ][ $outcome ] ++;
+
+ if ( sp_is_home_venue( $team_id, $event->ID ) ):
+ $totals[ $team_id ]['eventsplayed_home'] ++;
+ $totals[ $team_id ]['eventminutes_home'] += $minutes;
+ $totals[ $team_id ][ $outcome . '_home' ] ++;
+ else:
+ $totals[ $team_id ]['eventsplayed_away'] ++;
+ $totals[ $team_id ]['eventminutes_away'] += $minutes;
+ $totals[ $team_id ][ $outcome . '_away' ] ++;
+ endif;
endif;
if ( $outcome && $outcome != '-1' ):
@@ -268,10 +294,23 @@ class SP_League_Table extends SP_Custom_Post{
if ( array_key_exists( $team_id, $totals ) && is_array( $totals[ $team_id ] ) && array_key_exists( $key . 'for', $totals[ $team_id ] ) ):
$totals[ $team_id ][ $key . 'for' ] += $value;
$totals[ $team_id ][ $key . 'for' . ( $e + 1 ) ] = $value;
+
+ if ( sp_is_home_venue( $team_id, $event->ID ) ):
+ $totals[ $team_id ][ $key . 'for_home' ] += $value;
+ else:
+ $totals[ $team_id ][ $key . 'for_away' ] += $value;
+ endif;
+
foreach( $results as $other_team_id => $other_result ):
if ( $other_team_id != $team_id && array_key_exists( $key . 'against', $totals[ $team_id ] ) ):
$totals[ $team_id ][ $key . 'against' ] += sp_array_value( $other_result, $key, 0 );
$totals[ $team_id ][ $key . 'against' . ( $e + 1 ) ] = sp_array_value( $other_result, $key, 0 );
+
+ if ( sp_is_home_venue( $team_id, $event->ID ) ):
+ $totals[ $team_id ][ $key . 'against_home' ] += sp_array_value( $other_result, $key, 0 );
+ else:
+ $totals[ $team_id ][ $key . 'against_away' ] += sp_array_value( $other_result, $key, 0 );
+ endif;
endif;
endforeach;
endif;
diff --git a/includes/class-sp-team.php b/includes/class-sp-team.php
index 2bf97a0c..4aeb478e 100644
--- a/includes/class-sp-team.php
+++ b/includes/class-sp-team.php
@@ -77,15 +77,35 @@ class SP_Team extends SP_Custom_Post {
foreach ( $div_ids as $div_id ):
- $totals = array( 'eventsplayed' => 0, 'eventminutes' => 0, 'streak' => 0, 'last5' => null, 'last10' => null, 'homerecord' => null, 'awayrecord' => null );
+ $totals = array(
+ 'eventsplayed' => 0,
+ 'eventsplayed_home' => 0,
+ 'eventsplayed_away' => 0,
+ 'eventminutes' => 0,
+ 'eventminutes_home' => 0,
+ 'eventminutes_away' => 0,
+ 'streak' => 0,
+ 'streak_home' => 0,
+ 'streak_away' => 0,
+ 'last5' => null,
+ 'last10' => null,
+ 'homerecord' => null,
+ 'awayrecord' => null
+ );
foreach ( $result_labels as $key => $value ):
$totals[ $key . 'for' ] = 0;
+ $totals[ $key . 'for_home' ] = 0;
+ $totals[ $key . 'for_away' ] = 0;
$totals[ $key . 'against' ] = 0;
+ $totals[ $key . 'against_home' ] = 0;
+ $totals[ $key . 'against_away' ] = 0;
endforeach;
foreach ( $outcome_labels as $key => $value ):
$totals[ $key ] = 0;
+ $totals[ $key . '_home' ] = 0;
+ $totals[ $key . '_away' ] = 0;
endforeach;
// Initialize streaks counter
@@ -151,6 +171,8 @@ class SP_Team extends SP_Custom_Post {
$events = get_posts( $args );
+ $e = 0;
+
foreach( $events as $event ):
$results = (array)get_post_meta( $event->ID, 'sp_results', true );
$minutes = get_post_meta( $event->ID, 'sp_minutes', true );
@@ -175,6 +197,16 @@ class SP_Team extends SP_Custom_Post {
$totals['eventsplayed'] ++;
$totals['eventminutes'] += $minutes;
$totals[ $outcome ] ++;
+
+ if ( sp_is_home_venue( $team_id, $event->ID ) ):
+ $totals['eventsplayed_home'] ++;
+ $totals['eventminutes_home'] += $minutes;
+ $totals[ $outcome . '_home' ] ++;
+ else:
+ $totals['eventsplayed_away'] ++;
+ $totals['eventminutes_away'] += $minutes;
+ $totals[ $outcome . '_away' ] ++;
+ endif;
endif;
if ( $outcome && $outcome != '-1' ):
@@ -215,18 +247,33 @@ class SP_Team extends SP_Custom_Post {
else:
if ( array_key_exists( $key . 'for', $totals ) ):
$totals[ $key . 'for' ] += $value;
+ $totals[ $key . 'for' . ( $e + 1 ) ] = $value;
+
+ if ( sp_is_home_venue( $team_id, $event->ID ) ):
+ $totals[ $key . 'for_home' ] += $value;
+ else:
+ $totals[ $key . 'for_away' ] += $value;
+ endif;
endif;
endif;
else:
if ( $key != 'outcome' ):
if ( array_key_exists( $key . 'against', $totals ) ):
$totals[ $key . 'against' ] += $value;
+ $totals[ $key . 'against' . ( $e + 1 ) ] = $value;
+
+ if ( sp_is_home_venue( $team_id, $event->ID ) ):
+ $totals[ $key . 'against_home' ] += $value;
+ else:
+ $totals[ $key . 'against_away' ] += $value;
+ endif;
endif;
endif;
endif;
endforeach; endif;
$i++;
endforeach;
+ $e++;
endforeach;
// Compile streaks counter and add to totals
diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php
index 57334afe..63372c11 100644
--- a/includes/sp-core-functions.php
+++ b/includes/sp-core-functions.php
@@ -416,8 +416,8 @@ if ( !function_exists( 'sp_get_post_equation' ) ) {
$equation = get_post_meta ( $post_id, 'sp_equation', true );
if ( $equation ):
$equation = str_replace(
- array( '/', '(', ')', '+', '-', '*', '$' ),
- array( '÷', '(', ')', '+', '−', '×', '' ),
+ array( '/', '(', ')', '+', '-', '*', '_', '$' ),
+ array( '÷', '(', ')', '+', '−', '×', '@', '' ),
trim( $equation )
);
return '' . implode( ' ', explode( ' ', $equation ) ) . '';
@@ -1126,7 +1126,7 @@ if ( !function_exists( 'sp_solve' ) ) {
$parts = explode( ' ', $temp );
foreach( $parts as $key => $value ):
if ( substr( $value, 0, 1 ) == '$' ):
- if ( ! array_key_exists( preg_replace( "/[^a-z0-9]/", '', $value ), $vars ) )
+ if ( ! array_key_exists( preg_replace( "/[^a-z0-9_]/", '', $value ), $vars ) )
return 0;
endif;
endforeach;