diff --git a/includes/admin/class-sp-admin-sports.php b/includes/admin/class-sp-admin-sports.php index 91d0c0e3..27708915 100644 --- a/includes/admin/class-sp-admin-sports.php +++ b/includes/admin/class-sp-admin-sports.php @@ -77,6 +77,7 @@ class SP_Admin_Sports { $post = self::get_post_array( $outcome, $post_type ); if ( empty( $post ) ) continue; $id = self::insert_preset_post( $post, $index ); + update_post_meta( $id, 'sp_abbreviation', sp_array_value( $outcome, 'abbreviation', null ) ); } // Results diff --git a/includes/admin/post-types/class-sp-admin-cpt-outcome.php b/includes/admin/post-types/class-sp-admin-cpt-outcome.php index 12c1dc22..1c097c9c 100644 --- a/includes/admin/post-types/class-sp-admin-cpt-outcome.php +++ b/includes/admin/post-types/class-sp-admin-cpt-outcome.php @@ -42,6 +42,7 @@ class SP_Admin_CPT_Outcome extends SP_Admin_CPT { 'cb' => '', 'title' => __( 'Label', 'sportspress' ), 'sp_key' => __( 'Variable', 'sportspress' ), + 'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ), 'sp_description' => __( 'Description', 'sportspress' ), ); return apply_filters( 'sportspress_outcome_admin_columns', $columns ); @@ -57,6 +58,10 @@ class SP_Admin_CPT_Outcome extends SP_Admin_CPT { global $post; echo $post->post_name; break; + case 'sp_abbreviation': + global $post; + echo sp_get_post_abbreviation( $post->ID ); + break; case 'sp_description': global $post; echo '' . $post->post_excerpt . ''; diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-outcome-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-outcome-details.php index 36166b39..669f082b 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-outcome-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-outcome-details.php @@ -23,12 +23,24 @@ class SP_Meta_Box_Outcome_Details extends SP_Meta_Box_Config { */ public static function output( $post ) { wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' ); + $abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true ); ?>

+

+

+ +

+ @@ -114,6 +115,7 @@ class SP_Settings_Config extends SP_Settings_Page { > post_title; ?> post_name; ?> + ID ); ?>

post_excerpt; ?>

diff --git a/includes/class-sp-league-table.php b/includes/class-sp-league-table.php index ed371d47..7182c97c 100644 --- a/includes/class-sp-league-table.php +++ b/includes/class-sp-league-table.php @@ -5,7 +5,7 @@ * The SportsPress league table class handles individual league table data. * * @class SP_League_Table - * @version 1.1 + * @version 1.1.2 * @package SportsPress/Classes * @category Class * @author ThemeBoy @@ -182,13 +182,18 @@ class SP_League_Table extends SP_Custom_Post{ 'name' => $streak['name'], 'post_type' => 'sp_outcome', 'post_status' => 'publish', - 'posts_per_page' => 1 + 'posts_per_page' => 1, + 'orderby' => 'menu_order', + 'order' => 'ASC', ); $outcomes = get_posts( $args ); if ( $outcomes ): $outcome = reset( $outcomes ); - $totals[ $team_id ]['streak'] = $outcome->post_title . $streak['count']; + $abbreviation = get_post_meta( $outcome->ID, 'sp_abbreviation', true ); + if ( ! $abbreviation ) + $abbreviation = substr( $outcome->post_title, 0, 1 ); + $totals[ $team_id ]['streak'] = $abbreviation . $streak['count']; else: $totals[ $team_id ]['streak'] = null; endif; @@ -262,12 +267,14 @@ class SP_League_Table extends SP_Custom_Post{ // Solve $placeholder = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision ); - // Adjustments - $adjustment = sp_array_value( $adjustments, $team_id, array() ); + if ( ! in_array( $stat->equation, array( '$streak', '$last5', '$last10' ) ) ): + // Adjustments + $adjustment = sp_array_value( $adjustments, $team_id, array() ); - if ( $adjustment != 0 ): - $placeholder += sp_array_value( $adjustment, $stat->post_name, 0 ); - $placeholder = number_format( $placeholder, $stat->precision ); + if ( $adjustment != 0 ): + $placeholder += sp_array_value( $adjustment, $stat->post_name, 0 ); + $placeholder = number_format( $placeholder, $stat->precision ); + endif; endif; endif; diff --git a/includes/class-sp-team.php b/includes/class-sp-team.php index d59cc59f..f6e6138e 100644 --- a/includes/class-sp-team.php +++ b/includes/class-sp-team.php @@ -197,13 +197,18 @@ class SP_Team extends SP_Custom_Post { 'name' => $streak['name'], 'post_type' => 'sp_outcome', 'post_status' => 'publish', - 'posts_per_page' => 1 + 'posts_per_page' => 1, + 'orderby' => 'menu_order', + 'order' => 'ASC', ); $outcomes = get_posts( $args ); if ( $outcomes ): $outcome = reset( $outcomes ); - $totals['streak'] = $outcome->post_title . $streak['count']; + $abbreviation = get_post_meta( $outcome->ID, 'sp_abbreviation', true ); + if ( ! $abbreviation ) + $abbreviation = substr( $outcome->post_title, 0, 1 ); + $totals['streak'] = $abbreviation . $streak['count']; endif; // Add last counters to totals diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index 99c437ec..549dbbb1 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -283,7 +283,7 @@ if ( !function_exists( 'sp_array_combine' ) ) { if ( !function_exists( 'sp_numbers_to_words' ) ) { function sp_numbers_to_words( $str ) { - $output = str_replace( array( '1st', '2nd', '3rd', '5th', '8th', '9th', '10', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ), array( 'first', 'second', 'third', 'fifth', 'eight', 'ninth', 'ten', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine' ), $str ); + $output = str_replace( array( '%', '1st', '2nd', '3rd', '5th', '8th', '9th', '10', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' ), array( 'percent', 'first', 'second', 'third', 'fifth', 'eight', 'ninth', 'ten', 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine' ), $str ); return $output; } } @@ -311,6 +311,17 @@ if ( !function_exists( 'sp_get_url' ) ) { } } +if ( !function_exists( 'sp_get_post_abbreviation' ) ) { + function sp_get_post_abbreviation( $post_id ) { + $abbreviation = get_post_meta ( $post_id, 'sp_abbreviation', true ); + if ( $abbreviation ): + return $abbreviation; + else: + return substr( get_the_title( $post_id ), 0, 1 ); + endif; + } +} + if ( !function_exists( 'sp_get_post_precision' ) ) { function sp_get_post_precision( $post_id ) { $precision = get_post_meta ( $post_id, 'sp_precision', true ); @@ -975,14 +986,19 @@ if ( !function_exists( 'sp_solve' ) ) { if ( ! array_key_exists( preg_replace( "/[^a-z]/", '', $value ), $vars ) ) return 0; endif; - - $pos = strpos( $equation, '/' ); - if ( $pos ): - if ( $eos->solveIF( substr( $equation, $pos + 2 ), $vars ) == 0 ) - return 0; - endif; endforeach; + // Remove space between equation parts + $equation = str_replace( ' ', '', $equation ); + + // Check if denominator is zero + $pos = strpos( $equation, '/' ); + if ( $pos ): + if ( $eos->solveIF( substr( $equation, $pos + 1 ), $vars ) == 0 ) + return 0; + endif; + + // Return solution return number_format( $eos->solveIF( str_replace( ' ', '', $equation ), $vars ), $precision ); } diff --git a/presets/hockey.json b/presets/hockey.json index 31a5b209..9b3213ad 100644 --- a/presets/hockey.json +++ b/presets/hockey.json @@ -3,7 +3,7 @@ "outcomes": [ "Win", "Loss", - "Overtime Loss" + { "name" : "Overtime loss", "abbreviation" : "OT" } ], "results": [ { "name" : "1st", "description" : "1st period goals" },