From d62683ee8915edab453c9fc6e1db510acc5c1806 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Thu, 31 Mar 2016 03:07:45 +1100 Subject: [PATCH] Enable displaying total rows in player statistics --- .../class-sp-meta-box-player-statistics.php | 39 +++++----------- .../settings/class-sp-settings-players.php | 8 ++++ includes/class-sp-player.php | 25 ++++++++-- templates/player-statistics-league.php | 2 +- templates/player-statistics-total.php | 46 ------------------- templates/player-statistics.php | 15 +++--- 6 files changed, 51 insertions(+), 84 deletions(-) delete mode 100644 templates/player-statistics-total.php diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-statistics.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-statistics.php index f42e81a8..81cda616 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-statistics.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-player-statistics.php @@ -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; - ?> -

- 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 {

name; ?> —

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; - ?> -

- 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 { ?> - - - + diff --git a/includes/admin/settings/class-sp-settings-players.php b/includes/admin/settings/class-sp-settings-players.php index fbe093c8..18084e96 100644 --- a/includes/admin/settings/class-sp-settings-players.php +++ b/includes/admin/settings/class-sp-settings-players.php @@ -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', ), diff --git a/includes/class-sp-player.php b/includes/class-sp-player.php index 4977ef8f..3eb17542 100644 --- a/includes/class-sp-player.php +++ b/includes/class-sp-player.php @@ -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; } diff --git a/templates/player-statistics-league.php b/templates/player-statistics-league.php index 15120c52..ee2fbc14 100644 --- a/templates/player-statistics-league.php +++ b/templates/player-statistics-league.php @@ -9,7 +9,7 @@ unset( $data[0] ); if ( empty( $data ) ) return; -$output = '

' . $league->name . '

' . +$output = '

' . $caption . '

' . '
' . '' . '' . ''; diff --git a/templates/player-statistics-total.php b/templates/player-statistics-total.php deleted file mode 100644 index fd63243b..00000000 --- a/templates/player-statistics-total.php +++ /dev/null @@ -1,46 +0,0 @@ -' . __( 'Career Total', 'sportspress' ) . '' . - '
' . - '
' . '' . ''; - -foreach( $labels as $key => $label ): - if ( 'team' == $key ) - continue; - $output .= ''; -endforeach; - -$output .= '' . '' . ''; - -$i = 0; - -foreach( $data as $season_id => $row ): - - $output .= ''; - - foreach( $labels as $key => $value ): - if ( 'team' == $key ) - continue; - $output .= ''; - endforeach; - - $output .= ''; - - $i++; - -endforeach; - -$output .= '' . '
' . $label . '
' . sp_array_value( $row, $key, '—' ) . '
' . '
'; -?> -
- -
\ No newline at end of file diff --git a/templates/player-statistics.php b/templates/player-statistics.php index fa787371..060ae606 100644 --- a/templates/player-statistics.php +++ b/templates/player-statistics.php @@ -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( '

%s

', $section_label ); + if ( sizeof( $leagues ) > 1 ) { + printf( '

%s

', $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; \ No newline at end of file