diff --git a/includes/admin/class-sp-admin-taxonomies.php b/includes/admin/class-sp-admin-taxonomies.php index 9c5d4fb5..2c70bdd5 100644 --- a/includes/admin/class-sp-admin-taxonomies.php +++ b/includes/admin/class-sp-admin-taxonomies.php @@ -132,9 +132,15 @@ class SP_Admin_Taxonomies { public function add_position_fields() { ?>
- - -

+ +
term_id; - $term_meta = get_option( "taxonomy_$t_id" ); ?> + $sections = sp_get_term_sections( $t_id ); + ?> - + + - -

+ + + __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) ); - $term_meta = get_option( "taxonomy_$id" ); - - $caption = ( isset( $term_meta['sp_caption'] ) ? $term_meta['sp_caption'] : '—' ); - - $columns .= $caption; + $sections = sp_get_term_sections( $id ); + + $section_names = array(); + + if ( is_array( $sections ) ) { + foreach ( $sections as $section ) { + if ( array_key_exists( $section, $options ) ) { + $section_names[] = $options[ $section ]; + } + } + } + + $columns .= implode( ', ', $section_names ); } 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 466db079..f42e81a8 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 @@ -22,24 +22,63 @@ class SP_Meta_Box_Player_Statistics { $player = new SP_Player( $post ); $leagues = get_the_terms( $post->ID, 'sp_league' ); $league_num = sizeof( $leagues ); + $sections = get_option( 'sportspress_player_performance_sections', -1 ); - // Loop through statistics for each league - if ( $leagues ): - $i = 0; - foreach ( $leagues as $league ): + if ( $leagues ) { + if ( -1 == $sections ) { + // Loop through statistics for each league + $i = 0; + foreach ( $leagues as $league ): + ?> +

name; ?>

+ data( $league->term_id, true ); + self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0 ); + $i ++; + endforeach; ?> -

name; ?>

+

data( $league->term_id, true ); - self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0 ); - $i ++; - endforeach; - endif; - ?> -

- data( 0, true ); - self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams ); + 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 ) { + $section_order = array( 1 => __( 'Defense', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ) ); + } else { + $section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) ); + } + + // Get labels by section + $args = array( + 'post_type' => 'sp_performance', + 'numberposts' => 100, + 'posts_per_page' => 100, + 'orderby' => 'menu_order', + 'order' => 'ASC', + ); + + $columns = get_posts( $args ); + + foreach ( $section_order as $section_id => $section_label ) { + // Loop through statistics for each league + $i = 0; + foreach ( $leagues as $league ): + ?> +

name; ?> —

+ data( $league->term_id, true, $section_id ); + self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0 ); + $i ++; + endforeach; + ?> +

+ data( 0, true, $section_id ); + self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams ); + } + } + } } /** diff --git a/includes/admin/settings/class-sp-settings-players.php b/includes/admin/settings/class-sp-settings-players.php index 15f2b150..fbe093c8 100644 --- a/includes/admin/settings/class-sp-settings-players.php +++ b/includes/admin/settings/class-sp-settings-players.php @@ -125,6 +125,18 @@ class SP_Settings_Players extends SP_Settings_Page { 'checkboxgroup' => 'end', ), + array( + 'title' => __( 'Statistics', 'sportspress' ), + 'id' => 'sportspress_player_performance_sections', + 'default' => -1, + 'type' => 'radio', + 'options' => array( + -1 => __( 'Combined', 'sportspress' ), + 0 => __( 'Offense', 'sportspress' ) . ' → ' . __( 'Defense', 'sportspress' ), + 1 => __( 'Defense', 'sportspress' ) . ' → ' . __( 'Offense', 'sportspress' ), + ), + ), + array( 'title' => __( 'Nationality', 'sportspress' ), 'desc' => __( 'Display national flags', 'sportspress' ), diff --git a/includes/admin/views/html-admin-config.php b/includes/admin/views/html-admin-config.php index fc84324a..83ec3fb8 100644 --- a/includes/admin/views/html-admin-config.php +++ b/includes/admin/views/html-admin-config.php @@ -347,6 +347,7 @@ + @@ -356,6 +357,7 @@ post_title; ?> ID ); ?> ID ); ?> + ID ); ?>

post_excerpt; ?>

diff --git a/includes/class-sp-player.php b/includes/class-sp-player.php index e91a21be..4977ef8f 100644 --- a/includes/class-sp-player.php +++ b/includes/class-sp-player.php @@ -109,7 +109,7 @@ class SP_Player extends SP_Custom_Post { * @param bool $admin * @return array */ - public function data( $league_id, $admin = false ) { + public function data( $league_id, $admin = false, $section = -1 ) { $seasons = (array)get_the_terms( $this->ID, 'sp_season' ); $metrics = (array)get_post_meta( $this->ID, 'sp_metrics', true ); @@ -117,8 +117,35 @@ class SP_Player extends SP_Custom_Post { $leagues = sp_array_value( (array)get_post_meta( $this->ID, 'sp_leagues', true ), $league_id, array() ); $usecolumns = get_post_meta( $this->ID, 'sp_columns', true ); - // Get labels from performance variables - $performance_labels = (array)sp_get_var_labels( 'sp_performance' ); + // Get labels by section + $args = array( + 'post_type' => 'sp_performance', + 'numberposts' => 100, + 'posts_per_page' => 100, + 'orderby' => 'menu_order', + 'order' => 'ASC', + ); + + $posts = get_posts( $args ); + + $performance_labels = array(); + + foreach ( $posts as $post ): + if ( -1 === $section ) { + $performance_labels[ $post->post_name ] = $post->post_title; + } else { + $post_section = get_post_meta( $post->ID, 'sp_section', true ); + + if ( '' === $post_section ) { + $post_section = -1; + } + + if ( $section == $post_section || -1 == $post_section ) { + $performance_labels[ $post->post_name ] = $post->post_title; + } + } + + endforeach; // Get labels from outcome variables $outcome_labels = (array)sp_get_var_labels( 'sp_outcome' ); @@ -404,8 +431,44 @@ class SP_Player extends SP_Custom_Post { endforeach; - // Get stats from statistic variables - $stats = sp_get_var_labels( 'sp_statistic' ); + // Get labels by section + $args = array( + 'post_type' => 'sp_statistic', + 'numberposts' => 100, + 'posts_per_page' => 100, + 'orderby' => 'menu_order', + 'order' => 'ASC', + ); + + $posts = get_posts( $args ); + + $stats = array(); + + foreach ( $posts as $post ): + if ( -1 === $section ) { + $stats[ $post->post_name ] = $post->post_title; + } else { + $post_section = get_post_meta( $post->ID, 'sp_section', true ); + + if ( '' === $post_section ) { + $post_section = -1; + } + + if ( $admin ) { + if ( 1 == $section ) { + if ( 1 == $post_section ) { + $stats[ $post->post_name ] = $post->post_title; + } + } else { + if ( 1 != $post_section ) { + $stats[ $post->post_name ] = $post->post_title; + } + } + } elseif ( $section == $post_section || -1 == $post_section ) { + $stats[ $post->post_name ] = $post->post_title; + } + } + endforeach; // Merge the data and placeholders arrays $merged = array(); diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index 541619a7..f791e447 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -482,7 +482,25 @@ if ( !function_exists( 'sp_get_format_placeholder' ) ) { ) ); return sp_array_value( $placeholders, $key, 0 ); } -} +} + +if ( !function_exists( 'sp_get_term_sections' ) ) { + function sp_get_term_sections( $t_id ) { + $term_meta = get_option( "taxonomy_$t_id" ); + if ( isset( $term_meta['sp_sections'] ) ) { + $sections = $term_meta['sp_sections']; + } else { + $sections = apply_filters( 'sportspress_performance_sections', array( 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) ); + $sections = array_keys( $sections ); + } + + if ( '' === $sections ) { + $sections = array(); + } + + return $sections; + } +} if ( !function_exists( 'sp_dropdown_statuses' ) ) { function sp_dropdown_statuses( $args = array() ) { diff --git a/templates/player-statistics-league.php b/templates/player-statistics-league.php new file mode 100644 index 00000000..15120c52 --- /dev/null +++ b/templates/player-statistics-league.php @@ -0,0 +1,42 @@ +' . $league->name . '' . + '
' . + '' . '' . ''; + +foreach( $labels as $key => $label ): + $output .= ''; +endforeach; + +$output .= '' . '' . ''; + +$i = 0; + +foreach( $data as $season_id => $row ): + + $output .= ''; + + foreach( $labels as $key => $value ): + $output .= ''; + endforeach; + + $output .= ''; + + $i++; + +endforeach; + +$output .= '' . '
' . $label . '
' . sp_array_value( $row, $key, '—' ) . '
' . '
'; +?> +
+ +
diff --git a/templates/player-statistics-total.php b/templates/player-statistics-total.php new file mode 100644 index 00000000..fd63243b --- /dev/null +++ b/templates/player-statistics-total.php @@ -0,0 +1,46 @@ +' . __( '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 5757dcbf..fa787371 100644 --- a/templates/player-statistics.php +++ b/templates/player-statistics.php @@ -16,103 +16,42 @@ if ( ! isset( $id ) ) $player = new SP_Player( $id ); $scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false; +$sections = get_option( 'sportspress_player_performance_sections', -1 ); $leagues = get_the_terms( $id, 'sp_league' ); +$positions = $player->positions(); +$player_sections = array(); +foreach ( $positions as $position ) { + $player_sections = array_merge( $player_sections, sp_get_term_sections( $position->term_id ) ); +} + +// Determine order of sections +if ( 1 == $sections ) { + $section_order = array( 1 => __( 'Defense', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ) ); +} elseif ( 0 == $sections ) { + $section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) ); +} else { + $section_order = array( -1 => null ); +} // Loop through statistics for each league if ( is_array( $leagues ) ): - foreach ( $leagues as $league ): - $data = $player->data( $league->term_id ); - - // 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 ) ) - continue; - - $output = '

' . $league->name . '

' . - '
' . - '' . '' . ''; - - foreach( $labels as $key => $label ): - $output .= ''; + foreach ( $section_order as $section_id => $section_label ) { + if ( -1 !== $section_id && ! in_array( $section_id, $player_sections ) ) continue; + + foreach ( $leagues as $league ): + if ( null !== $section_label ) { + printf( '

%s

', $section_label ); + } + sp_get_template( 'player-statistics-league.php', array( + 'data' => $player->data( $league->term_id, false, $section_id ), + 'league' => $league, + 'scrollable' => $scrollable, + ) ); endforeach; - - $output .= '' . '' . ''; - - $i = 0; - - foreach( $data as $season_id => $row ): - - $output .= ''; - - foreach( $labels as $key => $value ): - $output .= ''; - endforeach; - - $output .= ''; - - $i++; - - endforeach; - - $output .= '' . '
' . $label . '
' . sp_array_value( $row, $key, '—' ) . '
' . '
'; - ?> -
- -
- data( 0 ); - -// 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 = '

' . __( '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 + + sp_get_template( 'player-statistics-total.php', array( + 'data' => $player->data( 0, false, $section_id ), + 'scrollable' => $scrollable, + ) ); + } +endif; \ No newline at end of file