Add time format to player performance and reflect in box scores
This commit is contained in:
@@ -827,4 +827,18 @@ jQuery(document).ready(function($){
|
|||||||
$select.find('input[value='+val+']').attr('checked', true);
|
$select.find('input[value='+val+']').attr('checked', true);
|
||||||
$select.slideUp('fast').siblings('.sp-edit-event-status').show();
|
$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();
|
||||||
});
|
});
|
||||||
@@ -418,7 +418,24 @@ class SP_Meta_Box_Event_Performance {
|
|||||||
$placeholder = sp_get_format_placeholder( sp_array_value( $formats, $column, 'number' ) );
|
$placeholder = sp_get_format_placeholder( sp_array_value( $formats, $column, 'number' ) );
|
||||||
?>
|
?>
|
||||||
<td>
|
<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; ?>" />
|
<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 if ( $intval && in_array( $column, $timed ) ) { ?>
|
||||||
<?php
|
<?php
|
||||||
// Get performance times
|
// Get performance times
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
|
|||||||
<p class="sp-format-selector">
|
<p class="sp-format-selector">
|
||||||
<select name="sp_format">
|
<select name="sp_format">
|
||||||
<?php
|
<?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 ):
|
foreach ( $options as $key => $value ):
|
||||||
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $format, true, false ), $value );
|
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $format, true, false ), $value );
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|||||||
@@ -114,9 +114,7 @@ class SP_Event extends SP_Custom_Post{
|
|||||||
if ( $is_timed ) {
|
if ( $is_timed ) {
|
||||||
$timed[] = $var->post_name;
|
$timed[] = $var->post_name;
|
||||||
}
|
}
|
||||||
}
|
} elseif ( 'equation' === $format ) {
|
||||||
|
|
||||||
if ( 'equation' === $format ) {
|
|
||||||
$equation = get_post_meta( $var->ID, 'sp_equation', true );
|
$equation = get_post_meta( $var->ID, 'sp_equation', true );
|
||||||
$precision = get_post_meta( $var->ID, 'sp_precision', true );
|
$precision = get_post_meta( $var->ID, 'sp_precision', true );
|
||||||
|
|
||||||
@@ -210,8 +208,34 @@ class SP_Event extends SP_Custom_Post{
|
|||||||
endforeach;
|
endforeach;
|
||||||
endif;
|
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
|
// 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();
|
$timeline = $this->timeline();
|
||||||
if ( ! empty( $timeline ) ):
|
if ( ! empty( $timeline ) ):
|
||||||
foreach ( $performance as $team => $players ):
|
foreach ( $performance as $team => $players ):
|
||||||
|
|||||||
@@ -465,7 +465,7 @@ if ( !function_exists( 'sp_get_post_format' ) ) {
|
|||||||
function sp_get_post_format( $post_id ) {
|
function sp_get_post_format( $post_id ) {
|
||||||
$format = get_post_meta ( $post_id, 'sp_format', true );
|
$format = get_post_meta ( $post_id, 'sp_format', true );
|
||||||
if ( isset( $format ) ):
|
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' ) );
|
return sp_array_value( $options, $format, __( 'Number', 'sportspress' ) );
|
||||||
else:
|
else:
|
||||||
return __( 'Number', 'sportspress' );
|
return __( 'Number', 'sportspress' );
|
||||||
|
|||||||
Reference in New Issue
Block a user