diff --git a/admin/options/config.php b/admin/options/config.php index f879c3c1..b0e1ea20 100644 --- a/admin/options/config.php +++ b/admin/options/config.php @@ -132,17 +132,28 @@ + > post_title; ?> post_name; ?> + + ID, 'sp_abbreviation', true ); + if ( $abbreviation ): + echo $abbreviation; + else: + echo $row->post_title; + endif; + ?> + - + @@ -163,17 +174,28 @@ + > post_title; ?> post_name; ?> + + ID, 'sp_abbreviation', true ); + if ( $abbreviation ): + echo $abbreviation; + else: + echo $row->post_title; + endif; + ?> + - + \ No newline at end of file diff --git a/admin/post-types/column.php b/admin/post-types/column.php index 3ff8b393..15122581 100644 --- a/admin/post-types/column.php +++ b/admin/post-types/column.php @@ -25,7 +25,8 @@ function sp_column_edit_columns() { 'title' => __( 'Label', 'sportspress' ), 'sp_equation' => __( 'Equation', 'sportspress' ), 'sp_order' => __( 'Sort Order', 'sportspress' ), - 'sp_key' => __( 'Key', 'sportspress' ) + 'sp_key' => __( 'Key', 'sportspress' ), + 'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ) ); return $columns; } @@ -39,6 +40,7 @@ function sp_column_details_meta( $post ) { $equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) ); $order = get_post_meta( $post->ID, 'sp_order', true ); $priority = get_post_meta( $post->ID, 'sp_priority', true ); + $abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true ); ?>

@@ -67,6 +69,10 @@ function sp_column_details_meta( $post ) { ?>

+

+

+ +

'', 'title' => __( 'Label', 'sportspress' ), - 'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ), - 'sp_key' => __( 'Key', 'sportspress' ) + 'sp_key' => __( 'Key', 'sportspress' ), + 'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ) ); return $columns; } @@ -39,7 +39,7 @@ function sp_outcome_details_meta( $post ) { ?>

- +

false, 'hierarchical' => false, 'supports' => array( 'title', 'page-attributes' ), + 'register_meta_box_cb' => 'sp_result_meta_init', 'capability_type' => 'sp_config' ); register_post_type( 'sp_result', $args ); @@ -22,9 +23,25 @@ function sp_result_edit_columns() { $columns = array( 'cb' => '', 'title' => __( 'Label', 'sportspress' ), - 'sp_key' => __( 'Key', 'sportspress' ) + 'sp_key' => __( 'Key', 'sportspress' ), + 'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ) ); return $columns; } add_filter( 'manage_edit-sp_result_columns', 'sp_result_edit_columns' ); + +function sp_result_meta_init() { + add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sp_result_details_meta', 'sp_result', 'normal', 'high' ); +} + +function sp_result_details_meta( $post ) { + $abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true ); + ?> +

+

+ +

+ \ No newline at end of file diff --git a/admin/post-types/statistic.php b/admin/post-types/statistic.php index 05d8b777..a683f4d3 100644 --- a/admin/post-types/statistic.php +++ b/admin/post-types/statistic.php @@ -24,7 +24,8 @@ function sp_statistic_edit_columns() { 'cb' => '', 'title' => __( 'Label', 'sportspress' ), 'sp_equation' => __( 'Equation', 'sportspress' ), - 'sp_key' => __( 'Key', 'sportspress' ) + 'sp_key' => __( 'Key', 'sportspress' ), + 'sp_abbreviation' => __( 'Abbreviation', 'sportspress' ) ); return $columns; } @@ -36,16 +37,19 @@ function sp_statistic_meta_init() { function sp_statistic_equation_meta( $post ) { $equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) ); + $abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true ); ?> -
-

- ID, $piece, array( 'player_event' ) ); - endforeach; - ?> -

-
+

+ ID, $piece, array( 'player_event' ) ); + endforeach; + ?> +

+

+

+ +

0 ); + $totals = array( 'eventsplayed' => 0, 'streak' => 0 ); foreach ( $result_labels as $key => $value ): $totals[ $key . 'for' ] = 0; @@ -89,6 +89,7 @@ function sp_team_columns_meta( $post ) { 'post_type' => 'sp_event', 'numberposts' => -1, 'posts_per_page' => -1, + 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'sp_team', @@ -105,6 +106,9 @@ function sp_team_columns_meta( $post ) { ); $events = get_posts( $args ); + // Initialize streaks counter + $streak = array( 'name' => '', 'count' => 0 ); + foreach( $events as $event ): $results = (array)get_post_meta( $event->ID, 'sp_results', true ); foreach ( $results as $team_id => $team_result ): @@ -115,6 +119,14 @@ function sp_team_columns_meta( $post ) { $totals['eventsplayed']++; $totals[ $value ]++; endif; + if ( $value && $value != '-1' ): + if ( $streak['name'] == $value ): + $streak['count'] ++; + else: + $streak['name'] = $value; + $streak['count'] = 1; + endif; + endif; else: if ( array_key_exists( $key . 'for', $totals ) ): $totals[ $key . 'for' ] += $value; @@ -131,6 +143,21 @@ function sp_team_columns_meta( $post ) { endforeach; endforeach; + // Compile streaks counter and add to totals + $args=array( + 'name' => $streak['name'], + 'post_type' => 'sp_outcome', + 'post_status' => 'publish', + 'posts_per_page' => 1 + ); + $outcomes = get_posts( $args ); + + if ( $outcomes ): + $outcome = $outcomes[0]; + $abbreviation = get_post_meta( $outcome->ID, 'sp_abbreviation', true ); + $totals['streak'] = ( $abbreviation ? $abbreviation : $outcome->post_title ) . $streak['count']; + endif; + // Generate array of placeholder values for each league $placeholders[ $div_id ] = array(); foreach ( $equations as $key => $value ): diff --git a/sportspress-actions.php b/sportspress-actions.php index 69f4f825..7c40d73f 100644 --- a/sportspress-actions.php +++ b/sportspress-actions.php @@ -207,8 +207,8 @@ function sp_save_post( $post_id ) { case ( 'sp_result' ): - // Update equation as string - update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) ); + // Update abbreviation as string + update_post_meta( $post_id, 'sp_abbreviation', sp_array_value( $_POST, 'sp_abbreviation', '' ) ); break; @@ -230,6 +230,9 @@ function sp_save_post( $post_id ) { // Update sort order as string update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', 'DESC' ) ); + // Update abbreviation as string + update_post_meta( $post_id, 'sp_abbreviation', sp_array_value( $_POST, 'sp_abbreviation', '' ) ); + break; case ( 'sp_statistic' ): @@ -237,6 +240,9 @@ function sp_save_post( $post_id ) { // Update equation as string update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) ); + // Update abbreviation as string + update_post_meta( $post_id, 'sp_abbreviation', sp_array_value( $_POST, 'sp_abbreviation', '' ) ); + break; case ( 'sp_player' ): diff --git a/sportspress-functions.php b/sportspress-functions.php index 4ccdb7fe..c9556336 100644 --- a/sportspress-functions.php +++ b/sportspress-functions.php @@ -331,6 +331,7 @@ if ( !function_exists( 'sp_get_equation_selector' ) ) { break; case 'outcome': $options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '↑', 'min' => '↓' ) ); + $options[ __( 'Outcomes', 'sportspress' ) ]['$streak'] = __( 'Streak', 'sportspress' ); break; case 'column': $options[ __( 'Columns', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_column' ); @@ -767,6 +768,10 @@ if ( !function_exists( 'sportspress_render_option_field' ) ) { if ( !function_exists( 'sp_solve' ) ) { function sp_solve( $equation, $vars ) { + // Return direct value if streak + if ( str_replace( ' ', '', $equation ) == '$streak' ) + return sp_array_value( $vars, 'streak', 0 ); + // Clearance to begin calculating remains true if all equation variables are in vars $clearance = true; @@ -784,7 +789,7 @@ if ( !function_exists( 'sp_solve' ) ) { $eos = new eqEOS(); // Solve using EOS - return $eos->solveIF( str_replace( ' ', '', $equation ), $vars ); + return round( $eos->solveIF( str_replace( ' ', '', $equation ), $vars ), 3 ); // TODO: add precision setting to each column with default set to 3 else: return 0; endif; @@ -812,11 +817,16 @@ if ( !function_exists( 'sp_get_table' ) ) { $totals = array(); $placeholders = array(); + // Initialize streaks counter + $streaks = array(); + foreach ( $team_ids as $team_id ): if ( ! $team_id ) continue; - $totals[ $team_id ] = array( 'eventsplayed' => 0 ); + $streaks[ $team_id ] = array( 'name' => '', 'count' => 0 ); + + $totals[ $team_id ] = array( 'eventsplayed' => 0, 'streak' => 0 ); foreach ( $result_labels as $key => $value ): $totals[ $team_id ][ $key . 'for' ] = 0; @@ -844,6 +854,7 @@ if ( !function_exists( 'sp_get_table' ) ) { 'post_type' => 'sp_event', 'numberposts' => -1, 'posts_per_page' => -1, + 'order' => 'ASC', 'tax_query' => array( array( 'taxonomy' => 'sp_league', @@ -855,21 +866,27 @@ if ( !function_exists( 'sp_get_table' ) ) { $events = get_posts( $args ); // Event loop - foreach( $events as $event ): + foreach ( $events as $event ): $results = (array)get_post_meta( $event->ID, 'sp_results', true ); foreach ( $results as $team_id => $team_result ): - // Increment events played - $totals[ $team_id ]['eventsplayed']++; - foreach ( $team_result as $key => $value ): if ( $key == 'outcome' ): if ( array_key_exists( $value, $totals[ $team_id ] ) ): + $totals[ $team_id ]['eventsplayed']++; $totals[ $team_id ][ $value ]++; endif; + if ( $value && $value != '-1' ): + if ( $streaks[ $team_id ]['name'] == $value ): + $streaks[ $team_id ]['count'] ++; + else: + $streaks[ $team_id ]['name'] = $value; + $streaks[ $team_id ]['count'] = 1; + endif; + endif; else: if ( array_key_exists( $key . 'for', $totals[ $team_id ] ) ): $totals[ $team_id ][ $key . 'for' ] += $value; @@ -882,6 +899,23 @@ if ( !function_exists( 'sp_get_table' ) ) { endforeach; + foreach ( $streaks as $team_id => $streak ): + // Compile streaks counter and add to totals + $args=array( + 'name' => $streak['name'], + 'post_type' => 'sp_outcome', + 'post_status' => 'publish', + 'posts_per_page' => 1 + ); + $outcomes = get_posts( $args ); + + if ( $outcomes ): + $outcome = $outcomes[0]; + $abbreviation = get_post_meta( $outcome->ID, 'sp_abbreviation', true ); + $totals[ $team_id ]['streak'] = ( $abbreviation ? $abbreviation : $outcome->post_title ) . $streak['count']; + endif; + endforeach; + $args = array( 'post_type' => 'sp_column', 'numberposts' => -1,