diff --git a/assets/js/admin/sportspress-admin.js b/assets/js/admin/sportspress-admin.js index 3772c516..7902341e 100644 --- a/assets/js/admin/sportspress-admin.js +++ b/assets/js/admin/sportspress-admin.js @@ -364,21 +364,27 @@ jQuery(document).ready(function($){ // Format selector $(".sp-format-selector select:first").change(function() { - $precisionselector = $(".sp-precision-selector input:first"); + $precisiondiv = $("#sp_precisiondiv"); + $precisioninput = $("#sp_precision"); + $timeddiv = $("#sp_timeddiv"); $equationdiv = $("#sp_equationdiv"); - // Precision settings - if($(this).val() == "decimal" || $(this).val() == "time") { - $precisionselector.prop( "disabled", false ); - } else { - $precisionselector.prop( "disabled", true ) - } - // Equation settings - if($(this).val() == "equation") { + if ($(this).val() == "equation") { $equationdiv.show(); + $precisiondiv.show(); + $timeddiv.hide(); + $precisioninput.prop( "disabled", false ); + } else if ($(this).val() == "number") { + $equationdiv.hide(); + $precisiondiv.hide(); + $timeddiv.show(); + $precisioninput.prop( "disabled", true ); } else { $equationdiv.hide(); + $precisiondiv.hide(); + $timeddiv.hide(); + $precisioninput.prop( "disabled", true ); } }); diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php index c03324b0..0a21b7a8 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php @@ -20,7 +20,7 @@ class SP_Meta_Box_Event_Performance { */ public static function output( $post ) { $event = new SP_Event( $post ); - list( $labels, $columns, $stats, $teams, $formats, $order ) = $event->performance( true ); + list( $labels, $columns, $stats, $teams, $formats, $order, $timed ) = $event->performance( true ); if ( 'yes' == get_option( 'sportspress_event_performance_show_minutes', 'yes' ) ) $timeline = $event->timeline( true ); @@ -65,7 +65,7 @@ class SP_Meta_Box_Event_Performance { // Check if individual mode $is_individual = get_option( 'sportspress_load_individual_mode_module', 'no' ) === 'yes' ? true : false; - self::tables( $post->ID, $stats, $labels, $columns, $teams, $has_checkboxes, $positions, $status, $formats, $order, $numbers, $is_individual, $timeline ); + self::tables( $post->ID, $stats, $labels, $columns, $teams, $has_checkboxes, $positions, $status, $formats, $order, $numbers, $is_individual, $timeline, $timed ); } /** @@ -81,7 +81,7 @@ class SP_Meta_Box_Event_Performance { /** * Admin edit tables */ - public static function tables( $post_id, $stats = array(), $labels = array(), $columns = array(), $teams = array(), $has_checkboxes = false, $positions = array(), $status = true, $formats = array(), $order = array(), $numbers = true, $is_individual = false, $timeline = array() ) { + public static function tables( $post_id, $stats = array(), $labels = array(), $columns = array(), $teams = array(), $has_checkboxes = false, $positions = array(), $status = true, $formats = array(), $order = array(), $numbers = true, $is_individual = false, $timeline = array(), $timed = array() ) { $sections = get_option( 'sportspress_event_performance_sections', -1 ); if ( $is_individual ) { @@ -116,7 +116,7 @@ class SP_Meta_Box_Event_Performance { $player_timeline = false; endif; - self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, false, $numbers, -1, $formats, $player_timeline ); + self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, false, $numbers, -1, $formats, $player_timeline, $timed ); endforeach; endforeach; ?> @@ -145,7 +145,7 @@ class SP_Meta_Box_Event_Performance { ?>

- +
@@ -227,7 +227,7 @@ class SP_Meta_Box_Event_Performance { ?>

- +
@@ -276,7 +276,7 @@ class SP_Meta_Box_Event_Performance { $player_timeline = false; endif; - self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, true, $numbers, $section, $formats, $player_timeline ); + self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, true, $numbers, $section, $formats, $player_timeline, $timed ); endforeach; ?> @@ -369,7 +369,7 @@ class SP_Meta_Box_Event_Performance { /** * Admin edit table row */ - public static function row( $labels = array(), $player_id = 0, $player_performance = array(), $team_id = 0, $data = array(), $positions = true, $status = true, $sortable = true, $numbers = true, $section = -1, $formats = array(), $player_timeline = array() ) { + public static function row( $labels = array(), $player_id = 0, $player_performance = array(), $team_id = 0, $data = array(), $positions = true, $status = true, $sortable = true, $numbers = true, $section = -1, $formats = array(), $player_timeline = array(), $timed = array() ) { if ( $player_id <= 0 ) return; $value = sp_array_value( $player_performance, 'number', '' ); @@ -419,7 +419,7 @@ class SP_Meta_Box_Event_Performance { ?>
- + ID, 'sp_precision', true ); + if ( '' === $precision ) { + $precision = 0; + } + $timed = get_post_meta( $post->ID, 'sp_timed', true ); + if ( '' === $timed ) { + $timed = false; + } ?>

@@ -68,10 +75,32 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config { ?>

-

-

- -

+
+

+

+ +

+
+
+

+ + +

+
    +
  • + +
  • +
  • + +
  • +
+
ID, 'sp_visible', true ); @@ -109,6 +138,7 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config { update_post_meta( $post_id, 'sp_section', (int) sp_array_value( $_POST, 'sp_section', -1 ) ); update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'number' ) ); update_post_meta( $post_id, 'sp_precision', sp_array_value( $_POST, 'sp_precision', 0 ) ); + update_post_meta( $post_id, 'sp_timed', sp_array_value( $_POST, 'sp_timed', 0 ) ); if ( 'auto' === get_option( 'sportspress_player_columns', 'auto' ) ) { update_post_meta( $post_id, 'sp_visible', sp_array_value( $_POST, 'sp_visible', 1 ) ); } diff --git a/includes/class-sp-event.php b/includes/class-sp-event.php index 082a96f5..b6f5f50e 100644 --- a/includes/class-sp-event.php +++ b/includes/class-sp-event.php @@ -98,15 +98,24 @@ class SP_Event extends SP_Custom_Post{ $labels = array(); $formats = array(); + $timed = array(); $equations = array(); foreach ( $vars as $var ) { $labels[ $var->post_name ] = $var->post_title; + $format = get_post_meta( $var->ID, 'sp_format', true ); if ( '' === $format ) { $format = 'number'; } $formats[ $var->post_name ] = $format; - + + if ( 'number' === $format ) { + $is_timed = get_post_meta( $var->ID, 'sp_timed', true ); + if ( $is_timed ) { + $timed[] = $var->post_name; + } + } + if ( 'equation' === $format ) { $equation = get_post_meta( $var->ID, 'sp_equation', true ); $precision = get_post_meta( $var->ID, 'sp_precision', true ); @@ -162,7 +171,7 @@ class SP_Event extends SP_Custom_Post{ endif; if ( $admin ): - return array( $labels, $columns, $performance, $teams, $formats, $order ); + return array( $labels, $columns, $performance, $teams, $formats, $order, $timed ); else: // Add position to performance labels if ( taxonomy_exists( 'sp_position' ) ): @@ -220,6 +229,9 @@ class SP_Event extends SP_Custom_Post{ foreach ( $player_performance as $performance_key => $performance_value ): + // Continue if not timed + if ( ! in_array( $performance_key, $timed ) ) continue; + // Get performance times $times = sp_array_value( $player_timeline, $performance_key, array() ); $times = array_filter( $times );