Display totals only when players are not available fix #16

This commit is contained in:
Brian Miyaji
2014-03-29 00:31:44 +11:00
parent 3734e53826
commit 64e620443b
2 changed files with 84 additions and 88 deletions

View File

@@ -24,15 +24,14 @@ function viewport() {
/* Data Tables */ /* Data Tables */
if (viewport().width > 640) { if (viewport().width > 640) {
$(".sp-league-table, .sp-event-performance, .sp-player-list").each(function() { $(".sp-sortable-table").each(function() {
sort = $(this).hasClass("sp-sortable-table");
$(this).dataTable({ $(this).dataTable({
"aaSorting": [], "aaSorting": [],
"bAutoWidth": false, "bAutoWidth": false,
"bFilter": false, "bFilter": false,
"bInfo": false, "bInfo": false,
"bPaginate": false, "bPaginate": false,
"bSort": sort, "bSort": true,
"oLanguage": { "oLanguage": {
"oAria": { "oAria": {
"sSortAscending": "", "sSortAscending": "",

View File

@@ -10,8 +10,6 @@ $link_posts = get_option( 'sportspress_event_link_players', 'yes' ) == 'yes' ? t
$sortable = get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false; $sortable = get_option( 'sportspress_enable_sortable_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;
$output = '';
foreach( $teams as $key => $team_id ): foreach( $teams as $key => $team_id ):
if ( ! $team_id ) continue; if ( ! $team_id ) continue;
@@ -19,27 +17,27 @@ foreach( $teams as $key => $team_id ):
// Get results for players in the team // Get results for players in the team
$players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key ); $players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key );
$has_players = sizeof( $players ) > 1;
if ( sizeof( $players ) <= 1 ) continue;
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) ); $data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
?>
$output .= '<h3>' . get_the_title( $team_id ) . '</h3>'; <h3><?php echo get_the_title( $team_id ); ?></h3>
<div class="sp-table-wrapper">
$output .= '<div class="sp-table-wrapper">' . <table class="sp-event-performance sp-data-table <?php if ( $responsive ) { ?> sp-responsive-table<?php } if ( $has_players && $sortable ) { ?> sp-sortable-table<?php } ?>">
'<table class="sp-event-performance sp-data-table' . ( $responsive ? ' sp-responsive-table' : '' ) . ( $sortable ? ' sp-sortable-table' : '' ) . '">' . '<thead>' . '<tr>'; <thead>
<tr>
$output .= '<th class="data-number">#</th>'; <?php if ( $has_players ): ?>
$output .= '<th class="data-name">' . SP()->text->string('Player', 'event') . '</th>'; <th class="data-number">#</th>
<th class="data-name"><?php echo SP()->text->string('Player', 'event'); ?></th>
foreach( $performance_labels as $key => $label ): <?php endif; foreach( $performance_labels as $key => $label ): ?>
$output .= '<th class="data-' . $key . '">' . $label . '</th>'; <th class="data-<?php echo $key; ?>"><?php echo $label; ?></th>
endforeach; <?php endforeach; ?>
</tr>
$output .= '</tr>' . '</thead>' . '<tbody>'; </thead>
<?php if ( $has_players ): ?>
<tbody>
<?php
$i = 0; $i = 0;
foreach( $data as $player_id => $row ): foreach( $data as $player_id => $row ):
if ( ! $player_id ) if ( ! $player_id )
@@ -50,19 +48,20 @@ foreach( $teams as $key => $team_id ):
if ( ! $name ) if ( ! $name )
continue; continue;
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">'; echo '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$number = get_post_meta( $player_id, 'sp_number', true ); $number = get_post_meta( $player_id, 'sp_number', true );
// Player number // Player number
$output .= '<td class="data-number">' . $number . '</td>'; echo '<td class="data-number">' . $number . '</td>';
if ( $link_posts ): if ( $link_posts ):
$permalink = get_post_permalink( $player_id ); $permalink = get_post_permalink( $player_id );
$name = '<a href="' . $permalink . '">' . $name . '</a>'; $name = '<a href="' . $permalink . '">' . $name . '</a>';
endif; endif;
$output .= '<td class="data-name">' . $name . '</td>'; echo '<td class="data-name">' . $name . '</td>';
foreach( $performance_labels as $key => $label ): foreach( $performance_labels as $key => $label ):
if ( $key == 'name' ) if ( $key == 'name' )
@@ -76,26 +75,27 @@ foreach( $teams as $key => $team_id ):
$totals[ $key ] = 0; $totals[ $key ] = 0;
endif; endif;
$totals[ $key ] += $value; $totals[ $key ] += $value;
$output .= '<td class="data-' . $key . '">' . $value . '</td>'; echo '<td class="data-' . $key . '">' . $value . '</td>';
endforeach; endforeach;
$output .= '</tr>'; echo '</tr>';
$i++; $i++;
endforeach; endforeach;
?>
$output .= '</tbody>'; </tbody>
<?php endif; ?>
if ( array_key_exists( 0, $data ) ): <?php if ( array_key_exists( 0, $data ) ): ?>
<<?php echo ( $has_players ? 'tfoot' : 'tbody' ); ?>>
$output .= '<tfoot><tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">'; <tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">
<?php
$number = get_post_meta( $player_id, 'sp_number', true ); $number = get_post_meta( $player_id, 'sp_number', true );
// Player number if ( $has_players ):
$output .= '<td class="data-number">&nbsp;</td>'; echo '<td class="data-number">&nbsp;</td>';
$output .= '<td class="data-name">' . SP()->text->string('Total', 'event') . '</td>'; echo '<td class="data-name">' . SP()->text->string('Total', 'event') . '</td>';
endif;
$row = $data[0]; $row = $data[0];
@@ -108,15 +108,12 @@ foreach( $teams as $key => $team_id ):
else: else:
$value = sp_array_value( $totals, $key, 0 ); $value = sp_array_value( $totals, $key, 0 );
endif; endif;
$output .= '<td class="data-' . $key . '">' . $value . '</td>'; echo '<td class="data-' . $key . '">' . $value . '</td>';
endforeach; endforeach;
?>
$output .= '</tr></tfoot>'; </tr>
</<?php echo ( $has_players ? 'tfoot' : 'tbody' ); ?>>
endif; <?php endif; ?>
</table>
$output .= '</table>' . '</div>'; </div>
<?php endforeach;
endforeach;
echo apply_filters( 'sportspress_event_performance', $output );