Add option to show career totals close #82

This commit is contained in:
Brian Miyaji
2014-12-10 04:27:03 +11:00
parent 46cd25d73d
commit c62d765d05
4 changed files with 63 additions and 2 deletions

View File

@@ -36,7 +36,7 @@ class SP_Meta_Box_Player_Statistics {
endforeach; endforeach;
endif; endif;
?> ?>
<p><strong><?php _e( 'Total', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Career Total', 'sportspress' ); ?></strong></p>
<?php <?php
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( 0, true ); list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( 0, true );
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams ); self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams );

View File

@@ -60,6 +60,14 @@ class SP_Settings_Players extends SP_Settings_Page {
'id' => 'sportspress_player_show_details', 'id' => 'sportspress_player_show_details',
'default' => 'yes', 'default' => 'yes',
'type' => 'checkbox', 'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Career Total', 'sportspress' ),
'id' => 'sportspress_player_show_total',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end', 'checkboxgroup' => 'end',
), ),

View File

@@ -1148,6 +1148,7 @@ if ( !function_exists( 'sp_get_next_event' ) ) {
function sp_get_text_options() { function sp_get_text_options() {
$strings = apply_filters( 'sportspress_text', array( $strings = apply_filters( 'sportspress_text', array(
__( 'Article', 'sportspress' ), __( 'Article', 'sportspress' ),
__( 'Career Total', 'sportspress' ),
__( 'Current Team', 'sportspress' ), __( 'Current Team', 'sportspress' ),
__( 'Current Teams', 'sportspress' ), __( 'Current Teams', 'sportspress' ),
__( 'Date', 'sportspress' ), __( 'Date', 'sportspress' ),

View File

@@ -16,6 +16,7 @@ $player = new SP_Player( $id );
$scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false; $scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false;
$responsive = get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false; $responsive = get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false;
$show_total = get_option( 'sportspress_player_show_total', 'no' ) == 'yes' ? true : false;
$leagues = get_the_terms( $id, 'sp_league' ); $leagues = get_the_terms( $id, 'sp_league' );
// Loop through statistics for each league // Loop through statistics for each league
@@ -31,7 +32,7 @@ if ( is_array( $leagues ) ):
// Skip if there are no rows in the table // Skip if there are no rows in the table
if ( empty( $data ) ) if ( empty( $data ) )
return false; continue;
$output = '<h4 class="sp-table-caption">' . $league->name . '</h4>' . $output = '<h4 class="sp-table-caption">' . $league->name . '</h4>' .
'<div class="sp-table-wrapper' . ( $scrollable ? ' sp-scrollable-table-wrapper' : '' ) . '">' . '<div class="sp-table-wrapper' . ( $scrollable ? ' sp-scrollable-table-wrapper' : '' ) . '">' .
@@ -67,3 +68,54 @@ if ( is_array( $leagues ) ):
<?php <?php
endforeach; endforeach;
endif; endif;
if ( $show_total ):
$data = $player->data( 0 );
// The first row should be column labels
$labels = $data[0];
// Remove the first row to leave us with the actual data
unset( $data[0] );
// Skip if there are no rows in the table
if ( empty( $data ) )
return false;
$output = '<h4 class="sp-table-caption">' . __( 'Career Total', 'sportspress' ) . '</h4>' .
'<div class="sp-table-wrapper' . ( $scrollable ? ' sp-scrollable-table-wrapper' : '' ) . '">' .
'<table class="sp-player-statistics sp-data-table' . ( $responsive ? ' sp-responsive-table' : '' ) . '">' . '<thead>' . '<tr>';
foreach( $labels as $key => $label ):
if ( 'team' == $key )
continue;
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
endforeach;
$output .= '</tr>' . '</thead>' . '<tbody>';
$i = 0;
foreach( $data as $season_id => $row ):
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
foreach( $labels as $key => $value ):
if ( 'team' == $key )
continue;
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '&mdash;' ) . '</td>';
endforeach;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>' . '</table>' . '</div>';
?>
<div class="sp-template sp-template-player-statistics sp-template-player-total">
<?php echo $output; ?>
</div>
<?php
endif;