Enable displaying total rows in player statistics
This commit is contained in:
@@ -36,11 +36,6 @@ class SP_Meta_Box_Player_Statistics {
|
||||
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0 );
|
||||
$i ++;
|
||||
endforeach;
|
||||
?>
|
||||
<p><strong><?php _e( 'Career Total', 'sportspress' ); ?></strong></p>
|
||||
<?php
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( 0, true );
|
||||
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams );
|
||||
} else {
|
||||
// Determine order of sections
|
||||
if ( 1 == $sections ) {
|
||||
@@ -60,6 +55,7 @@ class SP_Meta_Box_Player_Statistics {
|
||||
|
||||
$columns = get_posts( $args );
|
||||
|
||||
$s = 0;
|
||||
foreach ( $section_order as $section_id => $section_label ) {
|
||||
// Loop through statistics for each league
|
||||
$i = 0;
|
||||
@@ -68,14 +64,10 @@ class SP_Meta_Box_Player_Statistics {
|
||||
<p><strong><?php echo $league->name; ?> — <?php echo $section_label; ?></strong></p>
|
||||
<?php
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true, $section_id );
|
||||
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0 );
|
||||
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0 && $s == 0 );
|
||||
$i ++;
|
||||
endforeach;
|
||||
?>
|
||||
<p><strong><?php _e( 'Career Total', 'sportspress' ); ?> — <?php echo $section_label; ?></strong></p>
|
||||
<?php
|
||||
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( 0, true, $section_id );
|
||||
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams );
|
||||
$s ++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,24 +118,17 @@ class SP_Meta_Box_Player_Statistics {
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td>
|
||||
<?php if ( 0 !== $div_id ): ?>
|
||||
<label>
|
||||
<?php if ( ! apply_filters( 'sportspress_player_team_statistics', $league_id ) ): ?>
|
||||
<?php $value = sp_array_value( $leagues, $div_id, '-1' ); ?>
|
||||
<input type="hidden" name="sp_leagues[<?php echo $league_id; ?>][<?php echo $div_id; ?>]" value="-1">
|
||||
<input type="checkbox" name="sp_leagues[<?php echo $league_id; ?>][<?php echo $div_id; ?>]" value="1" <?php checked( $value ); ?>>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
if ( 'WP_Error' == get_class( $div ) ) _e( 'Total', 'sportspress' );
|
||||
else echo $div->name;
|
||||
?>
|
||||
</label>
|
||||
<?php else: ?>
|
||||
<label>
|
||||
<?php if ( ! apply_filters( 'sportspress_player_team_statistics', $league_id ) ): ?>
|
||||
<?php $value = sp_array_value( $leagues, $div_id, '-1' ); ?>
|
||||
<input type="hidden" name="sp_leagues[<?php echo $league_id; ?>][<?php echo $div_id; ?>]" value="-1">
|
||||
<input type="checkbox" name="sp_leagues[<?php echo $league_id; ?>][<?php echo $div_id; ?>]" value="1" <?php checked( $value ); ?>>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
if ( 'WP_Error' == get_class( $div ) ) _e( 'Total', 'sportspress' );
|
||||
else echo $div->name;
|
||||
if ( 0 === $div_id ) _e( 'Total', 'sportspress' );
|
||||
elseif ( 'WP_Error' != get_class( $div ) ) echo $div->name;
|
||||
?>
|
||||
<?php endif; ?>
|
||||
</label>
|
||||
</td>
|
||||
<?php if ( apply_filters( 'sportspress_player_team_statistics', $league_id ) ): ?>
|
||||
<?php if ( $div_id == 0 ): ?>
|
||||
|
||||
@@ -73,6 +73,14 @@ class SP_Settings_Players extends SP_Settings_Page {
|
||||
'id' => 'sportspress_player_show_statistics',
|
||||
'default' => 'yes',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => '',
|
||||
),
|
||||
|
||||
array(
|
||||
'desc' => __( 'Total', 'sportspress' ),
|
||||
'id' => 'sportspress_player_show_total',
|
||||
'default' => 'no',
|
||||
'type' => 'checkbox',
|
||||
'checkboxgroup' => 'end',
|
||||
),
|
||||
|
||||
|
||||
@@ -539,10 +539,29 @@ class SP_Player extends SP_Custom_Post {
|
||||
unset( $columns[ $key ] );
|
||||
endif;
|
||||
endforeach;
|
||||
$labels = array( 'name' => __( 'Season', 'sportspress' ) );
|
||||
if ( in_array( 'team', $this->columns ) )
|
||||
$labels['team'] = __( 'Team', 'sportspress' );
|
||||
|
||||
$labels = array();
|
||||
|
||||
if ( 'no' === get_option( 'sportspress_player_show_statistics', 'yes' ) ) {
|
||||
$merged = array();
|
||||
} else {
|
||||
$labels['name'] = __( 'Season', 'sportspress' );
|
||||
if ( in_array( 'team', $this->columns ) ) {
|
||||
$labels['team'] = __( 'Team', 'sportspress' );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'yes' === get_option( 'sportspress_player_show_total', 'no' ) ) {
|
||||
$total_placeholders = sp_array_value( $placeholders, 0, array() );
|
||||
$total_data = sp_array_value( $data, 0, array() );
|
||||
$total_data = array_filter( $total_data );
|
||||
$total = array_merge( $total_placeholders, $total_data );
|
||||
$merged[-1] = $total;
|
||||
$merged[-1]['name'] = __( 'Total', 'sportspress' );
|
||||
}
|
||||
|
||||
$merged[0] = array_merge( $labels, $columns );
|
||||
|
||||
return $merged;
|
||||
endif;
|
||||
}
|
||||
|
||||
@@ -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>';
|
||||
|
||||
|
||||
@@ -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, '—' ) . '</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>
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user