Enable average-based timed career totals
This commit is contained in:
@@ -121,10 +121,23 @@ class SP_Meta_Box_Player_Statistics {
|
||||
<td><?php
|
||||
$value = sp_array_value( sp_array_value( $data, 0, array() ), $column, null );
|
||||
$placeholder = sp_array_value( sp_array_value( $placeholders, 0, array() ), $column, 0 );
|
||||
if ( $readonly )
|
||||
|
||||
// Convert value and placeholder to time format
|
||||
if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) {
|
||||
$timeval = sp_time_value( $value );
|
||||
$placeholder = sp_time_value( $placeholder );
|
||||
}
|
||||
|
||||
if ( $readonly ) {
|
||||
echo $value ? $value : $placeholder;
|
||||
else
|
||||
echo '<input type="text" name="sp_statistics[' . $league_id . '][0][' . $column . ']" value="' . esc_attr( $value ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' data-sp-format="number" data-sp-total-type="' . sp_array_value( $total_types, $column, 'total' ) . '" />';
|
||||
} else {
|
||||
if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) {
|
||||
echo '<input class="sp-convert-time-input" type="text" name="sp_times[' . $league_id . '][0][' . $column . ']" value="' . ( '' === $value ? '' : esc_attr( $timeval ) ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' />';
|
||||
echo '<input class="sp-convert-time-output" type="hidden" name="sp_statistics[' . $league_id . '][0][' . $column . ']" value="' . esc_attr( $value ) . '" data-sp-format="' . sp_array_value( $formats, $column, 'number' ) . '" data-sp-total-type="' . sp_array_value( $total_types, $column, 'total' ) . '" />';
|
||||
} else {
|
||||
echo '<input type="text" name="sp_statistics[' . $league_id . '][0][' . $column . ']" value="' . esc_attr( $value ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' data-sp-format="' . sp_array_value( $formats, $column, 'number' ) . '" data-sp-total-type="' . sp_array_value( $total_types, $column, 'total' ) . '" />';
|
||||
}
|
||||
}
|
||||
?></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
@@ -196,26 +209,8 @@ class SP_Meta_Box_Player_Statistics {
|
||||
|
||||
// Convert value and placeholder to time format
|
||||
if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) {
|
||||
|
||||
// Convert value
|
||||
$intval = intval( $value );
|
||||
$timeval = gmdate( 'i:s', $intval );
|
||||
$hours = floor( $intval / 3600 );
|
||||
|
||||
if ( '00' != $hours )
|
||||
$timeval = $hours . ':' . $timeval;
|
||||
|
||||
$timeval = preg_replace( '/^0/', '', $timeval );
|
||||
|
||||
// Convert placeholder
|
||||
$intval = intval( $placeholder );
|
||||
$placeholder = gmdate( 'i:s', $intval );
|
||||
$hours = floor( $intval / 3600 );
|
||||
|
||||
if ( '00' != $hours )
|
||||
$placeholder = $hours . ':' . $placeholder;
|
||||
|
||||
$placeholder = preg_replace( '/^0/', '', $placeholder );
|
||||
$timeval = sp_time_value( $value );
|
||||
$placeholder = sp_time_value( $placeholder );
|
||||
}
|
||||
|
||||
if ( $readonly ) {
|
||||
|
||||
@@ -66,11 +66,11 @@ class SP_Meta_Box_Statistic_Details extends SP_Meta_Box_Config {
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Career Total', 'sportspress' ); ?></strong></p>
|
||||
<p><strong><?php _e( 'Type', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<select name="sp_total_type">
|
||||
<?php
|
||||
$options = apply_filters( 'sportspress_statistic_totals', array( 'total' => __( 'Total', 'sportspress' ), 'average' => __( 'Average', 'sportspress' ) ) );
|
||||
$options = apply_filters( 'sportspress_statistic_total_types', array( 'total' => __( 'Total', 'sportspress' ), 'average' => __( 'Average', 'sportspress' ) ) );
|
||||
foreach ( $options as $key => $value ):
|
||||
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $total, true, false ), $value );
|
||||
endforeach;
|
||||
|
||||
@@ -652,30 +652,6 @@ class SP_Player extends SP_Custom_Post {
|
||||
$usecolumns = array_merge( $usecolumn_order, $usecolumns );
|
||||
}
|
||||
|
||||
// Convert to time notation
|
||||
if ( in_array( 'time', $formats ) ):
|
||||
foreach ( $placeholders as $season => $stats ):
|
||||
if ( ! is_array( $stats ) ) continue;
|
||||
|
||||
foreach ( $stats as $key => $value ):
|
||||
|
||||
// Continue if not time format
|
||||
if ( 'time' !== sp_array_value( $formats, $key ) ) continue;
|
||||
|
||||
$intval = intval( $value );
|
||||
$timeval = gmdate( 'i:s', $intval );
|
||||
$hours = floor( $intval / 3600 );
|
||||
|
||||
if ( '00' != $hours )
|
||||
$timeval = $hours . ':' . $timeval;
|
||||
|
||||
$timeval = preg_replace( '/^0/', '', $timeval );
|
||||
|
||||
$placeholders[ $season ][ $key ] = $timeval;
|
||||
endforeach;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
// Calculate total statistics
|
||||
$career = array(
|
||||
'name' => __( 'Total', 'sportspress' ),
|
||||
@@ -702,9 +678,11 @@ class SP_Player extends SP_Custom_Post {
|
||||
$career[ $post->post_name ] = sp_solve( $value['equation'], $totals, $precision );
|
||||
}
|
||||
|
||||
// Add career totals to merged array
|
||||
// Get manually entered career totals
|
||||
$manual_career = sp_array_value( $data, 0, array() );
|
||||
$manual_career = array_filter( $manual_career, 'sp_filter_non_empty' );
|
||||
|
||||
// Add career totals to merged array
|
||||
$merged[-1] = array_merge( $career, $manual_career );
|
||||
|
||||
if ( $admin ):
|
||||
@@ -743,23 +721,13 @@ class SP_Player extends SP_Custom_Post {
|
||||
// Convert to time notation
|
||||
if ( in_array( 'time', $formats ) ):
|
||||
foreach ( $merged as $season => $season_performance ):
|
||||
if ( $season <= 0 ) continue;
|
||||
|
||||
foreach ( $season_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 = floor( $intval / 3600 );
|
||||
$merged[ $season ][ $performance_key ] = sp_time_value( $performance_value );
|
||||
|
||||
if ( '00' != $hours )
|
||||
$timeval = $hours . ':' . $timeval;
|
||||
|
||||
$timeval = preg_replace( '/^0/', '', $timeval );
|
||||
|
||||
$merged[ $season ][ $performance_key ] = $timeval;
|
||||
endforeach;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
@@ -154,6 +154,27 @@ function sp_time_format() {
|
||||
return apply_filters( 'sportspress_time_format', get_option( 'time_format' ) );
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sp_time_from_int' ) ) {
|
||||
|
||||
/**
|
||||
* Convert number of seconds to formatted time
|
||||
*
|
||||
* @access public
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
function sp_time_value( $value = 0 ) {
|
||||
$intval = intval( $value );
|
||||
$timeval = gmdate( 'i:s', $intval );
|
||||
$hours = floor( $intval / 3600 );
|
||||
|
||||
if ( '00' != $hours )
|
||||
$timeval = $hours . ':' . $timeval;
|
||||
|
||||
return preg_replace( '/^0/', '', $timeval );
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sp_rgb_from_hex' ) ) {
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user