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 */
if (viewport().width > 640) {
$(".sp-league-table, .sp-event-performance, .sp-player-list").each(function() {
sort = $(this).hasClass("sp-sortable-table");
$(".sp-sortable-table").each(function() {
$(this).dataTable({
"aaSorting": [],
"bAutoWidth": false,
"bFilter": false,
"bInfo": false,
"bPaginate": false,
"bSort": sort,
"bSort": true,
"oLanguage": {
"oAria": {
"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;
$responsive = get_option( 'sportspress_enable_responsive_tables', 'yes' ) == 'yes' ? true : false;
$output = '';
foreach( $teams as $key => $team_id ):
if ( ! $team_id ) continue;
@@ -19,104 +17,103 @@ foreach( $teams as $key => $team_id ):
// Get results for players in the team
$players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $key );
if ( sizeof( $players ) <= 1 ) continue;
$has_players = sizeof( $players ) > 1;
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
?>
<h3><?php echo get_the_title( $team_id ); ?></h3>
<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 } ?>">
<thead>
<tr>
<?php if ( $has_players ): ?>
<th class="data-number">#</th>
<th class="data-name"><?php echo SP()->text->string('Player', 'event'); ?></th>
<?php endif; foreach( $performance_labels as $key => $label ): ?>
<th class="data-<?php echo $key; ?>"><?php echo $label; ?></th>
<?php endforeach; ?>
</tr>
</thead>
<?php if ( $has_players ): ?>
<tbody>
<?php
$i = 0;
foreach( $data as $player_id => $row ):
$output .= '<h3>' . get_the_title( $team_id ) . '</h3>';
if ( ! $player_id )
continue;
$output .= '<div class="sp-table-wrapper">' .
'<table class="sp-event-performance sp-data-table' . ( $responsive ? ' sp-responsive-table' : '' ) . ( $sortable ? ' sp-sortable-table' : '' ) . '">' . '<thead>' . '<tr>';
$name = get_the_title( $player_id );
$output .= '<th class="data-number">#</th>';
$output .= '<th class="data-name">' . SP()->text->string('Player', 'event') . '</th>';
if ( ! $name )
continue;
foreach( $performance_labels as $key => $label ):
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
endforeach;
echo '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$output .= '</tr>' . '</thead>' . '<tbody>';
$number = get_post_meta( $player_id, 'sp_number', true );
$i = 0;
// Player number
echo '<td class="data-number">' . $number . '</td>';
foreach( $data as $player_id => $row ):
if ( $link_posts ):
$permalink = get_post_permalink( $player_id );
$name = '<a href="' . $permalink . '">' . $name . '</a>';
endif;
if ( ! $player_id )
continue;
echo '<td class="data-name">' . $name . '</td>';
$name = get_the_title( $player_id );
if ( ! $name )
continue;
foreach( $performance_labels as $key => $label ):
if ( $key == 'name' )
continue;
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = 0;
endif;
if ( ! array_key_exists( $key, $totals ) ):
$totals[ $key ] = 0;
endif;
$totals[ $key ] += $value;
echo '<td class="data-' . $key . '">' . $value . '</td>';
endforeach;
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
echo '</tr>';
$number = get_post_meta( $player_id, 'sp_number', true );
$i++;
// Player number
$output .= '<td class="data-number">' . $number . '</td>';
endforeach;
?>
</tbody>
<?php endif; ?>
<?php if ( array_key_exists( 0, $data ) ): ?>
<<?php echo ( $has_players ? 'tfoot' : 'tbody' ); ?>>
<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">
<?php
$number = get_post_meta( $player_id, 'sp_number', true );
if ( $link_posts ):
$permalink = get_post_permalink( $player_id );
$name = '<a href="' . $permalink . '">' . $name . '</a>';
endif;
if ( $has_players ):
echo '<td class="data-number">&nbsp;</td>';
echo '<td class="data-name">' . SP()->text->string('Total', 'event') . '</td>';
endif;
$output .= '<td class="data-name">' . $name . '</td>';
$row = $data[0];
foreach( $performance_labels as $key => $label ):
if ( $key == 'name' )
continue;
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = 0;
endif;
if ( ! array_key_exists( $key, $totals ) ):
$totals[ $key ] = 0;
endif;
$totals[ $key ] += $value;
$output .= '<td class="data-' . $key . '">' . $value . '</td>';
endforeach;
$output .= '</tr>';
$i++;
endforeach;
$output .= '</tbody>';
if ( array_key_exists( 0, $data ) ):
$output .= '<tfoot><tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$number = get_post_meta( $player_id, 'sp_number', true );
// Player number
$output .= '<td class="data-number">&nbsp;</td>';
$output .= '<td class="data-name">' . SP()->text->string('Total', 'event') . '</td>';
$row = $data[0];
foreach( $performance_labels as $key => $label ):
if ( $key == 'name' ):
continue;
endif;
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = sp_array_value( $totals, $key, 0 );
endif;
$output .= '<td class="data-' . $key . '">' . $value . '</td>';
endforeach;
$output .= '</tr></tfoot>';
endif;
$output .= '</table>' . '</div>';
endforeach;
echo apply_filters( 'sportspress_event_performance', $output );
foreach( $performance_labels as $key => $label ):
if ( $key == 'name' ):
continue;
endif;
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = sp_array_value( $totals, $key, 0 );
endif;
echo '<td class="data-' . $key . '">' . $value . '</td>';
endforeach;
?>
</tr>
</<?php echo ( $has_players ? 'tfoot' : 'tbody' ); ?>>
<?php endif; ?>
</table>
</div>
<?php endforeach;