Convert time format values into time notation in players and lists

This commit is contained in:
Brian Miyaji
2017-01-11 16:03:29 +11:00
parent bb66ed2e07
commit 3228f1dbc9
2 changed files with 83 additions and 0 deletions

View File

@@ -470,6 +470,8 @@ class SP_Player_List extends SP_Custom_Post {
); );
$stats = get_posts( $args ); $stats = get_posts( $args );
$formats = array();
foreach ( $stats as $stat ): foreach ( $stats as $stat ):
// Get post meta // Get post meta
@@ -488,6 +490,13 @@ class SP_Player_List extends SP_Custom_Post {
// Add column name to columns // Add column name to columns
$columns[ $stat->post_name ] = $stat->post_title; $columns[ $stat->post_name ] = $stat->post_title;
// Add format
$format = get_post_meta( $stat->ID, 'sp_format', true );
if ( '' === $format ) {
$format = 'number';
}
$formats[ $stat->post_name ] = $format;
endforeach; endforeach;
// Fill in empty placeholder values for each player // Fill in empty placeholder values for each player
@@ -573,6 +582,31 @@ class SP_Player_List extends SP_Custom_Post {
endforeach; endforeach;
if ( $admin ): if ( $admin ):
// Convert to time notation
if ( in_array( 'time', $formats ) ):
foreach ( $placeholders as $player => $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 = ereg_replace( '^0', '', $timeval );
$placeholders[ $player ][ $key ] = $timeval;
endforeach;
endforeach;
endif;
$labels = array(); $labels = array();
foreach( $this->columns as $key ): foreach( $this->columns as $key ):
if ( $key == 'number' ): if ( $key == 'number' ):
@@ -587,6 +621,31 @@ class SP_Player_List extends SP_Custom_Post {
endforeach; endforeach;
return array( $labels, $data, $placeholders, $merged, $orderby ); return array( $labels, $data, $placeholders, $merged, $orderby );
else: else:
// Convert to time notation
if ( in_array( 'time', $formats ) ):
foreach ( $merged as $player => $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 = ereg_replace( '^0', '', $timeval );
$merged[ $player ][ $key ] = $timeval;
endforeach;
endforeach;
endif;
if ( ! is_array( $this->columns ) ) if ( ! is_array( $this->columns ) )
$this->columns = array(); $this->columns = array();
foreach ( $columns as $key => $label ): foreach ( $columns as $key => $label ):

View File

@@ -647,6 +647,30 @@ class SP_Player extends SP_Custom_Post {
$usecolumns = array_merge( $usecolumn_order, $usecolumns ); $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 = ereg_replace( '^0', '', $timeval );
$placeholders[ $season ][ $key ] = $timeval;
endforeach;
endforeach;
endif;
if ( $admin ): if ( $admin ):
$labels = array(); $labels = array();
if ( is_array( $usecolumns ) ): foreach ( $usecolumns as $key ): if ( is_array( $usecolumns ) ): foreach ( $usecolumns as $key ):