Enable displaying total rows in player statistics

This commit is contained in:
Brian Miyaji
2016-03-31 03:07:45 +11:00
parent 3547303c6f
commit d62683ee89
6 changed files with 51 additions and 84 deletions

View File

@@ -9,7 +9,7 @@ unset( $data[0] );
if ( empty( $data ) )
return;
$output = '<h4 class="sp-table-caption">' . $league->name . '</h4>' .
$output = '<h4 class="sp-table-caption">' . $caption . '</h4>' .
'<div class="sp-table-wrapper">' .
'<table class="sp-player-statistics sp-data-table' . ( $scrollable ? ' sp-scrollable-table' : '' ) . '">' . '<thead>' . '<tr>';

View File

@@ -1,46 +0,0 @@
<?php
// 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">' .
'<table class="sp-player-statistics sp-data-table' . ( $scrollable ? ' sp-scrollable-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>

View File

@@ -8,7 +8,7 @@
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( get_option( 'sportspress_player_show_statistics', 'yes' ) === 'no' ) return;
if ( 'no' === get_option( 'sportspress_player_show_statistics', 'yes' ) && 'no' === get_option( 'sportspress_player_show_total', 'no' ) ) return;
if ( ! isset( $id ) )
$id = get_the_ID();
@@ -40,18 +40,19 @@ if ( is_array( $leagues ) ):
foreach ( $leagues as $league ):
if ( null !== $section_label ) {
printf( '<h3 class="sp-post-caption sp-player-statistics-section">%s</h3>', $section_label );
if ( sizeof( $leagues ) > 1 ) {
printf( '<h3 class="sp-post-caption sp-player-statistics-section">%s</h3>', $section_label );
$caption = $league->name;
} else {
$caption = $section_label;
}
}
sp_get_template( 'player-statistics-league.php', array(
'data' => $player->data( $league->term_id, false, $section_id ),
'league' => $league,
'caption' => $caption,
'scrollable' => $scrollable,
) );
endforeach;
sp_get_template( 'player-statistics-total.php', array(
'data' => $player->data( 0, false, $section_id ),
'scrollable' => $scrollable,
) );
}
endif;