From 7cf5946880c79fcd4c67faad6fcd8ddf75e557c8 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Tue, 3 Mar 2015 17:20:44 +1100 Subject: [PATCH] Allow event performance tables to be split by position --- includes/admin/class-sp-admin-sports.php | 12 + .../class-sp-meta-box-event-performance.php | 56 +++- .../settings/class-sp-settings-events.php | 128 ++++++-- includes/admin/views/html-admin-config.php | 83 +++-- includes/class-sp-event.php | 2 +- includes/class-sp-post-types.php | 2 +- includes/sp-core-functions.php | 1 + includes/sp-option-filters.php | 22 ++ modules/sportspress-individual-mode.php | 2 +- presets/cricket.json | 33 +- templates/event-performance-table.php | 254 +++++++++++++++ templates/event-performance.php | 288 ++++++++---------- 12 files changed, 638 insertions(+), 245 deletions(-) create mode 100644 includes/sp-option-filters.php create mode 100644 templates/event-performance-table.php diff --git a/includes/admin/class-sp-admin-sports.php b/includes/admin/class-sp-admin-sports.php index 0918cd80..a516cfe4 100644 --- a/includes/admin/class-sp-admin-sports.php +++ b/includes/admin/class-sp-admin-sports.php @@ -148,6 +148,9 @@ class SP_Admin_Sports { $post = self::get_post_array( $performance, $post_type ); if ( empty( $post ) ) continue; $id = self::insert_preset_post( $post, $index ); + if ( isset( $performance['position'] ) ) { + wp_set_object_terms( $id, $performance['position'], 'sp_position', false ); + } $i ++; } @@ -187,6 +190,15 @@ class SP_Admin_Sports { update_post_meta( $id, 'sp_equation', sp_array_value( $statistic, 'equation', null ) ); update_post_meta( $id, 'sp_precision', sp_array_value( $statistic, 'precision', 0 ) ); } + + + // Options + $options = sp_array_value( $preset, 'options', array() ); + foreach ( $options as $option => $value ) { + update_option( 'sportspress_' . $option, $value ); + } + + // Primary Result update_option( 'sportspress_primary_result', $primary_result ); } diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php index db24564c..e0b1227e 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-performance.php @@ -29,8 +29,27 @@ class SP_Meta_Box_Event_Performance { // Get results for players in the team $players = sp_array_between( (array)get_post_meta( $post->ID, 'sp_player', false ), 0, $key ); + $players[] = -1; $data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) ); + // Determine if we need checkboxes + if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) && $i == 0 ) + $has_checkboxes = true; + else + $has_checkboxes = false; + + // Determine if we need extras + if ( 'yes' == get_option( 'sportspress_event_show_extras', 'no' ) ) + $show_extras = true; + else + $show_extras = false; + + // Determine if we are splitting positions + if ( 'yes' == get_option( 'sportspress_event_split_players_by_position', 'no' ) ) + $split_positions = true; + else + $split_positions = false; + ?>
@@ -38,7 +57,7 @@ class SP_Meta_Box_Event_Performance {
- +
@@ -65,7 +84,7 @@ class SP_Meta_Box_Event_Performance { - + + + + + + + $label ): + $player_id = -1; + $player_performance = sp_array_value( $data, $player_id, array() ); + $value = sp_array_value( $player_performance, $column, '' ); + ?> + + + + + @@ -106,10 +141,10 @@ class SP_Meta_Box_Event_Performance { $label ): $player_id = 0; - $player_performance = sp_array_value( $data, 0, array() ); + $player_performance = sp_array_value( $data, $player_id, array() ); $value = sp_array_value( $player_performance, $column, '' ); ?> - + @@ -117,7 +152,7 @@ class SP_Meta_Box_Event_Performance { $player_performance ): - if ( !$player_id ) continue; + if ( $player_id <= 0 ) continue; $number = get_post_meta( $player_id, 'sp_number', true ); $value = sp_array_value( $player_performance, 'number', '' ); ?> @@ -129,16 +164,19 @@ class SP_Meta_Box_Event_Performance {
  # +
    
     readonly="readonly"value="" />  
'sp_position', - 'name' => 'sp_players[' . $team_id . '][' . $player_id . '][position]', + 'name' => 'sp_players[' . $team_id . '][' . $player_id . '][position][]', 'values' => 'term_id', 'orderby' => 'slug', 'selected' => $selected, + 'class' => 'sp-position', + 'property' => 'multiple', + 'chosen' => true, ); sp_dropdown_taxonomies( $args ); ?> diff --git a/includes/admin/settings/class-sp-settings-events.php b/includes/admin/settings/class-sp-settings-events.php index 8d03c2bf..242cbe9b 100644 --- a/includes/admin/settings/class-sp-settings-events.php +++ b/includes/admin/settings/class-sp-settings-events.php @@ -40,7 +40,7 @@ class SP_Settings_Events extends SP_Settings_Page { $settings = array_merge( array( - array( 'title' => __( 'Event Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'event_options' ), + array( 'title' => __( 'Event Options', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'event_options' ), ), apply_filters( 'sportspress_event_options', array( @@ -86,24 +86,8 @@ class SP_Settings_Events extends SP_Settings_Page { ), array( - 'desc' => __( 'Players', 'sportspress' ), - 'id' => 'sportspress_event_show_players', - 'default' => 'yes', - 'type' => 'checkbox', - 'checkboxgroup' => '', - ), - - array( - 'desc' => __( 'Staff', 'sportspress' ), - 'id' => 'sportspress_event_show_staff', - 'default' => 'yes', - 'type' => 'checkbox', - 'checkboxgroup' => '', - ), - - array( - 'desc' => __( 'Total', 'sportspress' ), - 'id' => 'sportspress_event_show_total', + 'desc' => __( 'Player Performance', 'sportspress' ), + 'id' => 'sportspress_event_show_performance', 'default' => 'yes', 'type' => 'checkbox', 'checkboxgroup' => 'end', @@ -124,17 +108,6 @@ class SP_Settings_Events extends SP_Settings_Page { array( 'type' => 'delimiter' ), - array( - 'title' => __( 'Player Performance', 'sportspress' ), - 'id' => 'sportspress_event_performance_mode', - 'default' => 'values', - 'type' => 'radio', - 'options' => array( - 'values' => __( 'Values', 'sportspress' ), - 'icons' => __( 'Icons', 'sportspress' ), - ), - ), - array( 'title' => __( 'Venues', 'sportspress' ), 'desc' => __( 'Display maps', 'sportspress' ), @@ -185,10 +158,103 @@ class SP_Settings_Events extends SP_Settings_Page { 'default' => 'no', 'type' => 'checkbox', ), - )), + ) ), array( array( 'type' => 'sectionend', 'id' => 'event_options' ), + ), + + array( + array( 'title' => __( 'Player Performance', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'performance_options' ), + ), + + apply_filters( 'sportspress_performance_options', array( + array( + 'title' => __( 'Rows', 'sportspress' ), + 'desc' => __( 'Staff', 'sportspress' ), + 'id' => 'sportspress_event_show_staff', + 'default' => 'yes', + 'type' => 'checkbox', + 'checkboxgroup' => 'start', + ), + + array( + 'desc' => __( 'Players', 'sportspress' ), + 'id' => 'sportspress_event_show_players', + 'default' => 'yes', + 'type' => 'checkbox', + 'checkboxgroup' => '', + ), + + array( + 'desc' => __( 'Extras', 'sportspress' ), + 'id' => 'sportspress_event_show_extras', + 'default' => 'no', + 'type' => 'checkbox', + 'checkboxgroup' => '', + ), + + array( + 'desc' => __( 'Total', 'sportspress' ), + 'id' => 'sportspress_event_show_total', + 'default' => 'yes', + 'type' => 'checkbox', + 'checkboxgroup' => 'end', + ), + + array( + 'title' => __( 'Columns', 'sportspress' ), + 'id' => 'sportspress_event_performance_columns', + 'default' => 'auto', + 'type' => 'radio', + 'options' => array( + 'auto' => __( 'Auto', 'sportspress' ), + 'manual' => __( 'Manual', 'sportspress' ), + ), + ), + + array( + 'title' => __( 'Mode', 'sportspress' ), + 'id' => 'sportspress_event_performance_mode', + 'default' => 'values', + 'type' => 'radio', + 'options' => array( + 'values' => __( 'Values', 'sportspress' ), + 'icons' => __( 'Icons', 'sportspress' ), + ), + ), + + array( + 'title' => __( 'Players', 'sportspress' ), + 'desc' => __( 'Display squad numbers', 'sportspress' ), + 'id' => 'sportspress_event_show_player_numbers', + 'default' => 'yes', + 'type' => 'checkbox', + 'checkboxgroup' => 'start', + ), + + array( + 'desc' => __( 'Split players by position', 'sportspress' ), + 'id' => 'sportspress_event_split_players_by_position', + 'default' => 'false', + 'type' => 'checkbox', + 'checkboxgroup' => 'end', + ), + + array( + 'title' => __( 'Total', 'sportspress' ), + 'id' => 'sportspress_event_total_performance', + 'default' => 'all', + 'type' => 'radio', + 'options' => array( + 'all' => __( 'All', 'sportspress' ), + 'primary' => __( 'Primary', 'sportspress' ), + ), + ), + ) ), + + array( + array( 'type' => 'sectionend', 'id' => 'performance_options' ), ) ); diff --git a/includes/admin/views/html-admin-config.php b/includes/admin/views/html-admin-config.php index 97458a09..69739f99 100644 --- a/includes/admin/views/html-admin-config.php +++ b/includes/admin/views/html-admin-config.php @@ -77,7 +77,7 @@
- + @@ -131,6 +131,8 @@
'sp_performance', 'numberposts' => -1, @@ -146,30 +148,61 @@

- + + + $label ): ?> + @@ -286,7 +227,7 @@ if ( is_array( $teams ) ): if ( $show_team_players ) { $i = 0; - foreach( $data as $player_id => $row ): + foreach ( $data as $player_id => $row ): if ( ! $player_id ) continue; @@ -298,10 +239,12 @@ if ( is_array( $teams ) ): echo ''; - $number = sp_array_value( $row, 'number', ' ' ); + if ( isset( $labels['number'] ) ): + $number = sp_array_value( $row, 'number', ' ' ); - // Player number - echo ''; + // Player number + echo ''; + endif; if ( $link_posts ): $permalink = get_post_permalink( $player_id ); @@ -312,14 +255,19 @@ if ( is_array( $teams ) ): if ( $mode == 'icons' ) echo ' '; + if ( isset( $labels['number'] ) ): + echo ''; + endif; echo ''; $row = sp_array_value( $data, 0, array() ); if ( $mode == 'icons' ) echo '
- - - - - - - - - - - - > - - - - - - - - - - - -
ID ) ) echo get_the_post_thumbnail( $row->ID, 'sportspress-fit-mini' ); ?>post_title; ?>post_name; ?>

post_excerpt; ?>

+ + + + + + + + + + + + + + + + + + + + + + + > + + + + + + + + + + + + + +
>  +
post_name ); ?>> + ID ) ) + echo get_the_post_thumbnail( $row->ID, 'sportspress-fit-mini' ); + else + echo ' '; + ?> + post_title; ?>post_name; ?>ID, 'sp_position' ) ? the_terms( $row->ID, 'sp_position' ) : __( 'All', 'sportspress' );; ?>

post_excerpt; ?>

+
diff --git a/includes/class-sp-event.php b/includes/class-sp-event.php index 79cb61ef..739dcdc2 100644 --- a/includes/class-sp-event.php +++ b/includes/class-sp-event.php @@ -99,7 +99,7 @@ class SP_Event extends SP_Custom_Post{ else: // Add position to performance labels $labels = array_merge( array( 'position' => __( 'Position', 'sportspress' ) ), $labels ); - if ( is_array( $columns ) ): + if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) && is_array( $columns ) ): foreach ( $labels as $key => $label ): if ( ! in_array( $key, $columns ) ): unset( $labels[ $key ] ); diff --git a/includes/class-sp-post-types.php b/includes/class-sp-post-types.php index 419886fd..ce3c1745 100644 --- a/includes/class-sp-post-types.php +++ b/includes/class-sp-post-types.php @@ -142,7 +142,7 @@ class SP_Post_types { 'hierarchical' => true, 'rewrite' => array( 'slug' => get_option( 'sportspress_position_slug', 'position' ) ), ); - $object_types = apply_filters( 'sportspress_position_object_types', array( 'sp_player' ) ); + $object_types = apply_filters( 'sportspress_position_object_types', array( 'sp_player', 'sp_performance' ) ); register_taxonomy( 'sp_position', $object_types, $args ); foreach ( $object_types as $object_type ): register_taxonomy_for_object_type( 'sp_position', $object_type ); diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index 07da9d5f..c710482b 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -13,6 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly // Include core functions +include( 'sp-option-filters.php' ); include( 'sp-conditional-functions.php' ); include( 'sp-formatting-functions.php' ); include( 'sp-deprecated-functions.php' ); diff --git a/includes/sp-option-filters.php b/includes/sp-option-filters.php new file mode 100644 index 00000000..f09ac5d2 --- /dev/null +++ b/includes/sp-option-filters.php @@ -0,0 +1,22 @@ + 1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'sp_performance' ) ); + if ( ! $performance_posts ) return $option; + $post = reset( $performance_posts ); + return $post->post_name; +} +add_filter( 'option_sportspress_primary_performance', 'sportspress_primary_performance_filter' ); diff --git a/modules/sportspress-individual-mode.php b/modules/sportspress-individual-mode.php index 977c81e1..fa453ffe 100644 --- a/modules/sportspress-individual-mode.php +++ b/modules/sportspress-individual-mode.php @@ -56,7 +56,7 @@ class SportsPress_Individual_Mode { add_filter( 'sportspress_player_teams', '__return_false' ); add_filter( 'sportspress_staff_teams', '__return_false' ); add_filter( 'sportspress_list_team_selector', '__return_false' ); - add_filter( 'sportspress_split_performance_tables', '__return_false' ); + add_filter( 'option_sportspress_event_split_players_by_team', '__return_false' ); // Remove templates //remove_action( 'sportspress_single_event_content', 'sportspress_output_event_performance', 50 ); diff --git a/presets/cricket.json b/presets/cricket.json index 91bf754b..db9b7b1f 100644 --- a/presets/cricket.json +++ b/presets/cricket.json @@ -2,9 +2,7 @@ "name": "Cricket", "positions": [ "Batsman", - "Bowler", - "Keeper", - "All-rounder" + "Bowler" ], "outcomes": [ { "name" : "Win", "condition" : ">" }, @@ -21,8 +19,14 @@ { "name" : "Points", "description" : "Total points", "primary" : 1 } ], "performance": [ - "Runs", - "Wickets taken" + { "name" : "R", "id" : "runs", "position" : "Batsman", "description" : "Runs" }, + { "name" : "B", "position" : "Batsman", "description" : "Balls" }, + { "name" : "4s", "position" : "Batsman", "description" : "Fours" }, + { "name" : "6s", "position" : "Batsman", "description" : "Sixes" }, + { "name" : "O", "position" : "Bowler", "description" : "Overs Bowled" }, + { "name" : "M", "position" : "Bowler", "description" : "Maidens" }, + { "name" : "R", "position" : "Bowler", "description" : "Runs" }, + { "name" : "W", "position" : "Bowler", "description" : "Wickets" } ], "columns": [ { "name" : "P", "equation" : "$eventsplayed", "description" : "Matches played" }, @@ -36,9 +40,22 @@ "metrics": [ "Height", "Weight", - "Bat brand" + "Bat Brand" ], "statistics": [ - { "name" : "Appearances", "equation" : "$eventsplayed", "description" : "Matches played" } - ] + { "name" : "Mat", "equation" : "$eventsplayed", "description" : "Matches played" }, + { "name" : "Avg", "equation" : "$eventsplayed", "description" : "Average" }, + { "name" : "SR", "equation" : "$runs / $b * 100", "precision" : 2, "description" : "Strike Rate" } + ], + "options": { + "load_individual_mode_module" : "no", + "event_teams" : "2", + "event_show_players" : "yes", + "event_show_extras" : "yes", + "event_show_total" : "yes", + "sportspress_event_performance_mode" : "values", + "event_show_player_numbers" : "no", + "event_split_players_by_position" : "yes", + "sportspress_event_total_performance" : "primary" + } } \ No newline at end of file diff --git a/templates/event-performance-table.php b/templates/event-performance-table.php new file mode 100644 index 00000000..f89e6428 --- /dev/null +++ b/templates/event-performance-table.php @@ -0,0 +1,254 @@ + +
+
+ + + + + + + + + + $label ): ?> + + + + + + + + + + $sub ): + if ( ! $sub_id ) + continue; + $lineup_sub_relation[ sp_array_value( $sub, 'sub', 0 ) ] = $sub_id; + endforeach; + + $i = 0; + foreach ( $data as $player_id => $row ): + + if ( ! $player_id ) + continue; + + $name = get_the_title( $player_id ); + + if ( ! $name ) + continue; + + echo ''; + + if ( $show_numbers ) { + $number = sp_array_value( $row, 'number', ' ' ); + + // Player number + echo ''; + } + + if ( $link_posts ): + $permalink = get_post_permalink( $player_id ); + $name = '' . $name . ''; + if ( isset( $row['status'] ) && $row['status'] == 'sub' ): + $name = '(' . $name . ')'; + endif; + endif; + + if ( array_key_exists( $player_id, $lineup_sub_relation ) ): + $name .= ' ' . sp_array_value( sp_array_value( $data, $lineup_sub_relation[ $player_id ], array() ), 'number', null ) . ''; + elseif ( isset( $row['sub'] ) && $row['sub'] ): + $name .= ' ' . sp_array_value( sp_array_value( $data, $row['sub'], array() ), 'number', null ) . ''; + endif; + + echo ''; + + if ( $mode == 'icons' ) echo ''; + elseif ( intval( $value ) && $mode == 'icons' ): + $performance_id = sp_array_value( $performance_ids, $key, null ); + if ( $performance_id && has_post_thumbnail( $performance_id ) ): + echo str_repeat( get_the_post_thumbnail( $performance_id, 'sportspress-fit-mini' ) . ' ', $value ); + endif; + endif; + endforeach; + + if ( $mode == 'icons' ) echo ''; + + echo ''; + + $i++; + + endforeach; + ?> + + + + <> + + +  '; + } + echo ''; + endif; + + $row = sp_array_value( $data, -1, array() ); + + if ( $mode == 'icons' ) echo ''; + elseif ( intval( $value ) && $mode == 'icons' ): + $performance_id = sp_array_value( $performance_ids, $key, null ); + if ( $performance_id && has_post_thumbnail( $performance_id ) ): + echo str_repeat( get_the_post_thumbnail( $performance_id, 'sportspress-fit-mini' ) . ' ', $value ); + endif; + endif; + endforeach; + + if ( $mode == 'icons' ) echo ''; + ?> + + + +  '; + } + echo ''; + endif; + + $row = sp_array_value( $data, 0, array() ); + + if ( $mode == 'icons' ) echo ''; + elseif ( intval( $value ) && $mode == 'icons' ): + $performance_id = sp_array_value( $performance_ids, $key, null ); + if ( $performance_id && has_post_thumbnail( $performance_id ) ): + echo str_repeat( get_the_post_thumbnail( $performance_id, 'sportspress-fit-mini' ) . ' ', $value ); + endif; + endif; + endforeach; + + if ( $mode == 'icons' ) echo ''; + ?> + + + + > + +
# + + + + + +  
' . $number . '' . $name . ''; + + foreach ( $labels as $key => $label ): + if ( 'name' == $key ) + continue; + if ( isset( $position ) && 'position' == $key ) + continue; + + $value = '—'; + if ( $key == 'position' ): + $positions = array(); + if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): + $position_ids = (array) $row[ $key ]; + else: + $position_ids = (array) sp_get_the_term_id( $player_id, 'sp_position' ); + endif; + + foreach ( $position_ids as $position_id ) { + $player_position = get_term_by( 'id', $position_id, 'sp_position' ); + if ( $player_position ) $positions[] = $player_position->name; + } + + if ( sizeof( $positions ) ): + $value = implode( ', ', $positions ); + endif; + else: + if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): + $value = $row[ $key ]; + else: + $value = 0; + endif; + endif; + if ( ! array_key_exists( $key, $totals ) ): + $totals[ $key ] = 0; + endif; + $totals[ $key ] += $value; + + if ( $mode == 'values' ): + echo '' . $value . '
' . __( 'Extras', 'sportspress' ) . ''; + + foreach ( $labels as $key => $label ): + if ( 'name' == $key ) + continue; + if ( isset( $position ) && 'position' == $key ) + continue; + if ( $key == 'position' ): + $value = ' '; + elseif ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): + $value = $row[ $key ]; + else: + $value = ' '; + endif; + + if ( $mode == 'values' ): + echo '' . $value . '
' . __( 'Total', 'sportspress' ) . ''; + + foreach ( $labels as $key => $label ): + if ( 'name' == $key ) + continue; + if ( isset( $position ) && 'position' == $key ) + continue; + if ( $key == 'position' ): + $value = ' '; + else: + if ( $primary && $key !== $primary ): + $value = ' '; + elseif ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): + $value = $row[ $key ]; + else: + $value = sp_array_value( $totals, $key, 0 ); + if ( $show_extras ) { + $value += sp_array_value( sp_array_value( $data, -1, array() ), $key, 0 ); + } + endif; + endif; + + if ( $mode == 'values' ): + echo '' . $value . '
+
+
\ No newline at end of file diff --git a/templates/event-performance.php b/templates/event-performance.php index cabf0c6d..6670e9c4 100644 --- a/templates/event-performance.php +++ b/templates/event-performance.php @@ -11,10 +11,15 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly $show_players = get_option( 'sportspress_event_show_players', 'yes' ) === 'yes' ? true : false; $show_staff = get_option( 'sportspress_event_show_staff', 'yes' ) === 'yes' ? true : false; +$show_extras = get_option( 'sportspress_event_show_extras', 'no' ) === 'yes' ? true : false; $show_total = get_option( 'sportspress_event_show_total', 'yes' ) === 'yes' ? true : false; -$split_tables = apply_filters( 'sportspress_split_performance_tables', true ); +$show_numbers = get_option( 'sportspress_event_show_player_numbers', 'yes' ) === 'yes' ? true : false; +$split_positions = get_option( 'sportspress_event_split_players_by_position', 'no' ) === 'yes' ? true : false; +$split_teams = get_option( 'sportspress_event_split_players_by_team', 'yes' ) === 'yes' ? true : false; +$primary = get_option( 'sportspress_primary_performance', null ); +$total = get_option( 'sportspress_event_total_performance', 'all'); -if ( ! $show_players && ! $show_staff && ! $show_total ) return; +if ( ! $show_players && ! $show_staff && ! $show_extras && ! $show_total ) return; if ( ! isset( $id ) ) $id = get_the_ID(); @@ -49,7 +54,7 @@ if ( is_array( $teams ) ): endforeach; endif; - if ( $split_tables ) { + if ( $split_teams ) { // Split tables foreach( $teams as $index => $team_id ): if ( -1 == $team_id ) continue; @@ -58,9 +63,11 @@ if ( is_array( $teams ) ): $players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $index ); $has_players = sizeof( $players ) > 1; - $show_team_players = $show_players && $has_players; + if ( $show_extras ) { + $players[] = -1; + } - $totals = array(); + $show_team_players = $show_players && $has_players; if ( 0 < $team_id ) { $data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) ); @@ -75,167 +82,98 @@ if ( is_array( $teams ) ): $data = sp_array_value( array_values( $performance ), $index ); } - if ( ! $show_team_players && ! $show_staff && ! $show_total ) continue; + if ( ! $show_team_players && ! $show_staff && ! $show_extras && ! $show_total ) continue; ?> -
- -

- - $id, 'index' => $index ) ); - endif; - ?> - -
- - - - - - - - $label ): ?> - - - - - - - - - +

+ + 'slug', + ) ); - $lineups = array_filter( $data, array( $event, 'lineup_filter' ) ); - $subs = array_filter( $data, array( $event, 'sub_filter' ) ); + foreach ( $positions as $position ) { + $subdata = array(); + foreach ( $data as $player_id => $player ) { + $player_positions = (array) sp_array_value( $player, 'position' ); + $player_positions = array_filter( $player_positions ); + if ( empty( $player_positions ) ) { + $player_positions = (array) sp_get_the_term_id( $player_id, 'sp_position' ); + } + if ( in_array( $position->term_id, $player_positions ) ) { + $subdata[ $player_id ] = $data[ $player_id ]; + } + } - $lineup_sub_relation = array(); - foreach ( $subs as $sub_id => $sub ): - if ( ! $sub_id ) - continue; - $lineup_sub_relation[ sp_array_value( $sub, 'sub', 0 ) ] = $sub_id; - endforeach; + // Initialize Sublabels + $sublabels = $labels; - $i = 0; - foreach( $data as $player_id => $row ): + $performance_labels = get_posts( array( + 'post_type' => 'sp_performance', + 'posts_per_page' => -1, + 'tax_query' => array( + array( + 'taxonomy' => 'sp_position', + 'terms' => $position->term_id, + ), + ), + ) ); - if ( ! $player_id ) - continue; + $allowed_labels = array(); + if ( ! empty( $performance_labels ) ) { + foreach ( $performance_labels as $label ) { + $allowed_labels[ $label->post_name ] = $label->post_title; + } - $name = get_the_title( $player_id ); + $sublabels = array_intersect_key( $sublabels, $allowed_labels ); + } - if ( ! $name ) - continue; + if ( sizeof( $subdata ) ) { + if ( $show_extras ) { + $subdata[-1] = sp_array_value( $data, -1 ); + } - echo ''; + sp_get_template( 'event-performance-table.php', array( + 'position' => $position->name, + 'scrollable' => $scrollable, + 'show_team_players' => $show_team_players, + 'show_numbers' => $show_numbers, + 'show_extras' => $show_extras, + 'show_total' => $show_total, + 'labels' => $sublabels, + 'mode' => $mode, + 'data' => $subdata, + 'event' => $event, + 'link_posts' => $link_posts, + 'performance_ids' => isset( $performance_ids ) ? $performance_ids : null, + 'primary' => 'primary' == $total ? $primary : null, + ) ); + } + } + } else { + sp_get_template( 'event-performance-table.php', array( + 'scrollable' => $scrollable, + 'show_team_players' => $show_team_players, + 'show_numbers' => $show_numbers, + 'show_extras' => $show_extras, + 'show_total' => $show_total, + 'labels' => $labels, + 'mode' => $mode, + 'data' => $data, + 'event' => $event, + 'link_posts' => $link_posts, + 'performance_ids' => isset( $performance_ids ) ? $performance_ids : null, + 'primary' => 'primary' == $total ? $primary : null, - $number = sp_array_value( $row, 'number', ' ' ); - - // Player number - echo ''; - - if ( $link_posts ): - $permalink = get_post_permalink( $player_id ); - $name = '' . $name . ''; - if ( isset( $row['status'] ) && $row['status'] == 'sub' ): - $name = '(' . $name . ')'; - endif; - endif; - - if ( array_key_exists( $player_id, $lineup_sub_relation ) ): - $name .= ' ' . sp_array_value( sp_array_value( $data, $lineup_sub_relation[ $player_id ], array() ), 'number', null ) . ''; - elseif ( isset( $row['sub'] ) && $row['sub'] ): - $name .= ' ' . sp_array_value( sp_array_value( $data, $row['sub'], array() ), 'number', null ) . ''; - endif; - - echo ''; - - if ( $mode == 'icons' ) echo ''; - elseif ( intval( $value ) && $mode == 'icons' ): - $performance_id = sp_array_value( $performance_ids, $key, null ); - if ( $performance_id && has_post_thumbnail( $performance_id ) ): - echo str_repeat( get_the_post_thumbnail( $performance_id, 'sportspress-fit-mini' ) . ' ', $value ); - endif; - endif; - endforeach; - - if ( $mode == 'icons' ) echo ''; - - echo ''; - - $i++; - - endforeach; - ?> - - - - <> - -  '; - echo ''; - endif; - - $row = sp_array_value( $data, 0, array() ); - - if ( $mode == 'icons' ) echo ''; - elseif ( intval( $value ) && $mode == 'icons' ): - $performance_id = sp_array_value( $performance_ids, $key, null ); - if ( $performance_id && has_post_thumbnail( $performance_id ) ): - echo str_repeat( get_the_post_thumbnail( $performance_id, 'sportspress-fit-mini' ) . ' ', $value ); - endif; - endif; - endforeach; - - if ( $mode == 'icons' ) echo ''; - ?> - - > - -
# 
' . $number . '' . $name . ''; - - foreach( $labels as $key => $label ): - if ( $key == 'name' ) - continue; - $value = '—'; - if ( $key == 'position' ): - if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): - $position = get_term_by( 'id', $row[ $key ], 'sp_position' ); - if ( $position ) $value = $position->name; - endif; - else: - if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): - $value = $row[ $key ]; - else: - $value = 0; - endif; - endif; - if ( ! array_key_exists( $key, $totals ) ): - $totals[ $key ] = 0; - endif; - $totals[ $key ] += $value; - - if ( $mode == 'values' ): - echo '' . $value . '
' . __( 'Total', 'sportspress' ) . ''; - - foreach( $labels as $key => $label ): - if ( $key == 'name' ) - continue; - if ( $key == 'position' ): - $value = '—'; - elseif ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): - $value = $row[ $key ]; - else: - $value = sp_array_value( $totals, $key, 0 ); - endif; - - if ( $mode == 'values' ): - echo '' . $value . '
-
- -
+ ) ); + } + } + if ( $show_staff ): + sp_get_template( 'event-staff.php', array( 'id' => $id, 'index' => $index ) ); + endif; + ?> sp-scrollable-table">
##  
' . $number . '' . $number . ''; - foreach( $labels as $key => $label ): - if ( $key == 'name' ) + foreach ( $labels as $key => $label ): + if ( in_array( $key, array( 'number', 'name' ) ) ) continue; $value = '—'; if ( $key == 'position' ): if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): - $position = get_term_by( 'id', $row[ $key ], 'sp_position' ); - if ( $position ) $value = $position->name; + $positions = array(); + $position_ids = (array) $row[ $key ]; + foreach ( $position_ids as $position_id ) { + $player_position = get_term_by( 'id', $position_id, 'sp_position' ); + if ( $player_position ) $positions[] = $player_position->name; + } + $value = implode( ', ', $positions ); endif; else: if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ): @@ -359,15 +307,17 @@ if ( is_array( $teams ) ):
 ' . __( 'Total', 'sportspress' ) . ''; - foreach( $labels as $key => $label ): - if ( $key == 'name' ) + foreach ( $labels as $key => $label ): + if ( in_array( $key, array( 'number', 'name' ) ) ) continue; if ( $key == 'position' ): $value = '—';