Add time format to player performance and reflect in box scores

This commit is contained in:
Brian Miyaji
2016-12-20 23:16:25 +11:00
parent b0adfc1177
commit 3cd240937d
5 changed files with 62 additions and 7 deletions

View File

@@ -827,4 +827,18 @@ jQuery(document).ready(function($){
$select.find('input[value='+val+']').attr('checked', true);
$select.slideUp('fast').siblings('.sp-edit-event-status').show();
});
// Box score time converter
$('.sp-convert-time-input').change(function() {
var s = 0;
var val = $(this).val();
var a = val.split(':').reverse();
$.each(a, function( index, value ) {
s += parseInt(value) * Math.pow(60, index);
});
$(this).siblings('.sp-convert-time-output').val(s);
});
// Trigger box score time converter
$('.sp-convert-time-input').change();
});

View File

@@ -418,7 +418,24 @@ class SP_Meta_Box_Event_Performance {
$placeholder = sp_get_format_placeholder( sp_array_value( $formats, $column, 'number' ) );
?>
<td>
<?php if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) { ?>
<?php
$intval = intval( $value );
$timeval = gmdate( 'i:s', $intval );
$hours = gmdate( 'H', $intval );
if ( '00' != $hours )
$timeval = $hours . ':' . $timeval;
$timeval = ereg_replace( '^0', '', $timeval );
?>
<input class="sp-player-<?php echo $column; ?>-input sp-convert-time-input sp-sync-input" type="text" name="sp_times[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo esc_attr( $timeval ); ?>" placeholder="<?php echo $placeholder; ?>" />
<input class="sp-convert-time-output" type="hidden" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo esc_attr( $value ); ?>" />
<?php } else { ?>
<input class="sp-player-<?php echo $column; ?>-input sp-sync-input" type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php echo $placeholder; ?>" />
<?php } ?>
<?php if ( $intval && in_array( $column, $timed ) ) { ?>
<?php
// Get performance times

View File

@@ -68,7 +68,7 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
<p class="sp-format-selector">
<select name="sp_format">
<?php
$options = apply_filters( 'sportspress_performance_formats', array( 'number' => __( 'Number', 'sportspress' ), 'text' => __( 'Text', 'sportspress' ), 'equation' => __( 'Equation', 'sportspress' ) ) );
$options = apply_filters( 'sportspress_performance_formats', array( 'number' => __( 'Number', 'sportspress' ), 'time' => __( 'Time', 'sportspress' ), 'text' => __( 'Text', 'sportspress' ), 'equation' => __( 'Equation', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $format, true, false ), $value );
endforeach;

View File

@@ -114,9 +114,7 @@ class SP_Event extends SP_Custom_Post{
if ( $is_timed ) {
$timed[] = $var->post_name;
}
}
if ( 'equation' === $format ) {
} elseif ( 'equation' === $format ) {
$equation = get_post_meta( $var->ID, 'sp_equation', true );
$precision = get_post_meta( $var->ID, 'sp_precision', true );
@@ -210,8 +208,34 @@ class SP_Event extends SP_Custom_Post{
endforeach;
endif;
// Convert to time notation
if ( in_array( 'time', $formats ) ):
foreach ( $performance as $team => $players ):
foreach ( $players as $player => $player_performance ):
if ( ! $player ) continue;
foreach ( $player_performance as $performance_key => $performance_value ):
// Continue if not time format
if ( 'time' !== sp_array_value( $formats, $performance_key ) ) continue;
$intval = intval( $performance_value );
$timeval = gmdate( 'i:s', $intval );
$hours = gmdate( 'H', $intval );
if ( '00' != $hours )
$timeval = $hours . ':' . $timeval;
$timeval = ereg_replace( '^0', '', $timeval );
$performance[ $team ][ $player ][ $performance_key ] = $timeval;
endforeach;
endforeach;
endforeach;
endif;
// Add minutes to box score values
if ( 'yes' == get_option( 'sportspress_event_performance_show_minutes', 'yes' ) ):
if ( in_array( 'number', $formats ) && 'yes' == get_option( 'sportspress_event_performance_show_minutes', 'yes' ) ):
$timeline = $this->timeline();
if ( ! empty( $timeline ) ):
foreach ( $performance as $team => $players ):

View File

@@ -465,7 +465,7 @@ if ( !function_exists( 'sp_get_post_format' ) ) {
function sp_get_post_format( $post_id ) {
$format = get_post_meta ( $post_id, 'sp_format', true );
if ( isset( $format ) ):
$options = apply_filters( 'sportspress_performance_formats', array( 'number' => __( 'Number', 'sportspress' ), 'text' => __( 'Text', 'sportspress' ), 'equation' => __( 'Equation', 'sportspress' ) ) );
$options = apply_filters( 'sportspress_performance_formats', array( 'number' => __( 'Number', 'sportspress' ), 'time' => __( 'Time', 'sportspress' ), 'text' => __( 'Text', 'sportspress' ), 'equation' => __( 'Equation', 'sportspress' ) ) );
return sp_array_value( $options, $format, __( 'Number', 'sportspress' ) );
else:
return __( 'Number', 'sportspress' );