Convert time format values into time notation in players and lists
This commit is contained in:
@@ -470,6 +470,8 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
);
|
||||
$stats = get_posts( $args );
|
||||
|
||||
$formats = array();
|
||||
|
||||
foreach ( $stats as $stat ):
|
||||
|
||||
// Get post meta
|
||||
@@ -488,6 +490,13 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
// Add column name to columns
|
||||
$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;
|
||||
|
||||
// Fill in empty placeholder values for each player
|
||||
@@ -573,6 +582,31 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
endforeach;
|
||||
|
||||
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();
|
||||
foreach( $this->columns as $key ):
|
||||
if ( $key == 'number' ):
|
||||
@@ -587,6 +621,31 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
endforeach;
|
||||
return array( $labels, $data, $placeholders, $merged, $orderby );
|
||||
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 ) )
|
||||
$this->columns = array();
|
||||
foreach ( $columns as $key => $label ):
|
||||
|
||||
@@ -647,6 +647,30 @@ 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 = ereg_replace( '^0', '', $timeval );
|
||||
|
||||
$placeholders[ $season ][ $key ] = $timeval;
|
||||
endforeach;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
if ( $admin ):
|
||||
$labels = array();
|
||||
if ( is_array( $usecolumns ) ): foreach ( $usecolumns as $key ):
|
||||
|
||||
Reference in New Issue
Block a user