Convert player profile statistics to time format as needed
This commit is contained in:
@@ -832,6 +832,10 @@ jQuery(document).ready(function($){
|
||||
$('.sp-convert-time-input').change(function() {
|
||||
var s = 0;
|
||||
var val = $(this).val();
|
||||
if (val === '') {
|
||||
$(this).siblings('.sp-convert-time-output').val('');
|
||||
return;
|
||||
}
|
||||
var a = val.split(':').reverse();
|
||||
$.each(a, function( index, value ) {
|
||||
s += parseInt(value) * Math.pow(60, index);
|
||||
|
||||
@@ -32,8 +32,8 @@ class SP_Meta_Box_Player_Statistics {
|
||||
?>
|
||||
<p><strong><?php echo $league->name; ?></strong></p>
|
||||
<?php
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes ) = $player->data( $league->term_id, true );
|
||||
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes && $i == 0, true );
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes, $formats ) = $player->data( $league->term_id, true );
|
||||
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes && $i == 0, true, $formats );
|
||||
$i ++;
|
||||
endforeach;
|
||||
?>
|
||||
@@ -83,7 +83,7 @@ class SP_Meta_Box_Player_Statistics {
|
||||
/**
|
||||
* Admin edit table
|
||||
*/
|
||||
public static function table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $has_checkboxes = false, $team_select = false ) {
|
||||
public static function table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $has_checkboxes = false, $team_select = false, $formats = array() ) {
|
||||
$readonly = false;
|
||||
$teams = array_filter( get_post_meta( $id, 'sp_team', false ) );
|
||||
?>
|
||||
@@ -188,10 +188,41 @@ class SP_Meta_Box_Player_Statistics {
|
||||
<td><?php
|
||||
$value = sp_array_value( sp_array_value( $data, $div_id, array() ), $column, null );
|
||||
$placeholder = sp_array_value( sp_array_value( $placeholders, $div_id, array() ), $column, 0 );
|
||||
if ( $readonly )
|
||||
echo $value ? $value : $placeholder;
|
||||
else
|
||||
|
||||
// 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 = gmdate( 'H', $intval );
|
||||
|
||||
if ( '00' != $hours )
|
||||
$timeval = $hours . ':' . $timeval;
|
||||
|
||||
$timeval = ereg_replace( '^0', '', $timeval );
|
||||
|
||||
// Convert placeholder
|
||||
$intval = intval( $placeholder );
|
||||
$placeholder = gmdate( 'i:s', $intval );
|
||||
$hours = gmdate( 'H', $intval );
|
||||
|
||||
if ( '00' != $hours )
|
||||
$placeholder = $hours . ':' . $placeholder;
|
||||
|
||||
$placeholder = ereg_replace( '^0', '', $placeholder );
|
||||
}
|
||||
|
||||
if ( $readonly ) {
|
||||
echo $timeval ? $timeval : $placeholder;
|
||||
} else {
|
||||
if ( 'time' === sp_array_value( $formats, $column, 'number' ) ) {
|
||||
echo '<input class="sp-convert-time-input" type="text" name="sp_times[' . $league_id . '][' . $div_id . '][' . $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 . '][' . $div_id . '][' . $column . ']" value="' . esc_attr( $value ) . '" />';
|
||||
} else {
|
||||
echo '<input type="text" name="sp_statistics[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . esc_attr( $value ) . '" placeholder="' . esc_attr( $placeholder ) . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' />';
|
||||
}
|
||||
}
|
||||
?></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
|
||||
@@ -160,6 +160,7 @@ class SP_Player extends SP_Custom_Post {
|
||||
}
|
||||
|
||||
$performance_labels = array();
|
||||
$formats = array();
|
||||
|
||||
foreach ( $posts as $post ):
|
||||
if ( -1 === $section ) {
|
||||
@@ -175,6 +176,12 @@ class SP_Player extends SP_Custom_Post {
|
||||
$performance_labels[ $post->post_name ] = $post->post_title;
|
||||
}
|
||||
}
|
||||
|
||||
$format = get_post_meta( $post->ID, 'sp_format', true );
|
||||
if ( '' === $format ) {
|
||||
$format = 'number';
|
||||
}
|
||||
$formats[ $post->post_name ] = $format;
|
||||
endforeach;
|
||||
|
||||
// Get statistic labels
|
||||
@@ -590,6 +597,8 @@ class SP_Player extends SP_Custom_Post {
|
||||
|
||||
$columns = array_merge( $performance_labels, $stats );
|
||||
|
||||
$formats = array();
|
||||
|
||||
$args = array(
|
||||
'post_type' => array( 'sp_performance', 'sp_statistic' ),
|
||||
'numberposts' => 100,
|
||||
@@ -610,6 +619,12 @@ class SP_Player extends SP_Custom_Post {
|
||||
if ( in_array( $post->post_name, $usecolumns ) ) {
|
||||
$usecolumn_order[] = $post->post_name;
|
||||
}
|
||||
|
||||
$format = get_post_meta( $post->ID, 'sp_format', true );
|
||||
if ( '' === $format ) {
|
||||
$format = 'number';
|
||||
}
|
||||
$formats[ $post->post_name ] = $format;
|
||||
}
|
||||
$columns = array_merge( $column_order, $columns );
|
||||
$usecolumns = array_merge( $usecolumn_order, $usecolumns );
|
||||
@@ -624,7 +639,7 @@ class SP_Player extends SP_Custom_Post {
|
||||
$labels[ $key ] = $columns[ $key ];
|
||||
endif;
|
||||
endforeach; endif;
|
||||
return array( $labels, $data, $placeholders, $merged, $leagues, $has_checkboxes );
|
||||
return array( $labels, $data, $placeholders, $merged, $leagues, $has_checkboxes, $formats );
|
||||
else:
|
||||
if ( is_array( $usecolumns ) ):
|
||||
foreach ( $columns as $key => $label ):
|
||||
@@ -671,6 +686,30 @@ class SP_Player extends SP_Custom_Post {
|
||||
$merged[-1]['name'] = __( 'Total', 'sportspress' );
|
||||
}
|
||||
|
||||
// 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 = gmdate( 'H', $intval );
|
||||
|
||||
if ( '00' != $hours )
|
||||
$timeval = $hours . ':' . $timeval;
|
||||
|
||||
$timeval = ereg_replace( '^0', '', $timeval );
|
||||
|
||||
$merged[ $season ][ $performance_key ] = $timeval;
|
||||
endforeach;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
$merged[0] = array_merge( $labels, $columns );
|
||||
|
||||
return $merged;
|
||||
|
||||
Reference in New Issue
Block a user