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;
|
||||
|
||||
Reference in New Issue
Block a user