From 7c3d623f98ed8786d43b139279edff4589b1065c Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 17 Feb 2016 01:59:26 +1100 Subject: [PATCH] Add format option to player performance --- .../class-sp-admin-cpt-performance.php | 10 ++ .../class-sp-meta-box-event-performance.php | 160 ++++++++---------- includes/admin/views/html-admin-config.php | 10 +- includes/class-sp-event.php | 25 ++- 4 files changed, 114 insertions(+), 91 deletions(-) diff --git a/includes/admin/post-types/class-sp-admin-cpt-performance.php b/includes/admin/post-types/class-sp-admin-cpt-performance.php index e17bd12f..72a836e5 100644 --- a/includes/admin/post-types/class-sp-admin-cpt-performance.php +++ b/includes/admin/post-types/class-sp-admin-cpt-performance.php @@ -43,6 +43,8 @@ class SP_Admin_CPT_Performance extends SP_Admin_CPT { 'sp_icon' => __( 'Icon', 'sportspress' ), 'title' => __( 'Label', 'sportspress' ), 'sp_key' => __( 'Variable', 'sportspress' ), + 'sp_section' => __( 'Category', 'sportspress' ), + 'sp_config_format' => __( 'Format', 'sportspress' ), 'sp_description' => __( 'Description', 'sportspress' ), ); return apply_filters( 'sportspress_performance_admin_columns', $columns ); @@ -61,6 +63,14 @@ class SP_Admin_CPT_Performance extends SP_Admin_CPT { global $post; echo $post->post_name; break; + case 'sp_section': + global $post; + echo sp_get_post_section( $post->ID ); + break; + case 'sp_config_format': + global $post; + echo sp_get_post_format( $post->ID ); + break; case 'sp_description': global $post; echo '' . $post->post_excerpt . ''; 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 bdda9245..f307fcc2 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 @@ -20,19 +20,7 @@ class SP_Meta_Box_Event_Performance { */ public static function output( $post ) { $event = new SP_Event( $post ); - list( $labels, $columns, $stats, $teams ) = $event->performance( true ); - - // Determine if we are splitting positions - if ( 'yes' == get_option( 'sportspress_event_split_players_by_position', 'no' ) ) - $split_positions = true; - else - $split_positions = false; - - // Determine if we are splitting teams - if ( 'yes' == get_option( 'sportspress_event_split_players_by_team', 'yes' ) ) - $split_teams = true; - else - $split_teams = false; + list( $labels, $columns, $stats, $teams, $formats ) = $event->performance( true ); // Determine if columns are auto or manual if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) ) @@ -48,7 +36,7 @@ class SP_Meta_Box_Event_Performance { // Get positions $positions = array(); - if ( taxonomy_exists( 'sp_position' ) ): + if ( 'yes' == get_option( 'sportspress_event_show_position', 'yes' ) && taxonomy_exists( 'sp_position' ) ): $args = array( 'hide_empty' => false, 'parent' => 0, @@ -66,7 +54,7 @@ class SP_Meta_Box_Event_Performance { // Apply filters to labels $labels = apply_filters( 'sportspress_event_performance_labels_admin', $labels ); - self::tables( $post->ID, $stats, $labels, $columns, $teams, $has_checkboxes, $split_positions, $split_teams, $positions, $status ); + self::tables( $post->ID, $stats, $labels, $columns, $teams, $has_checkboxes, $positions, $status, $formats ); } /** @@ -80,95 +68,96 @@ class SP_Meta_Box_Event_Performance { /** * Admin edit tables */ - public static function tables( $post_id, $stats = array(), $labels = array(), $columns = array(), $teams = array(), $has_checkboxes = false, $split_positions = false, $split_teams = true, $positions = array(), $status = true ) { + public static function tables( $post_id, $stats = array(), $labels = array(), $columns = array(), $teams = array(), $has_checkboxes = false, $positions = array(), $status = true, $formats = array() ) { + $sections = get_option( 'sportspress_event_performance_sections', -1 ); + $i = 0; - if ( $split_teams ) { - foreach ( $teams as $key => $team_id ): - if ( -1 == $team_id ) continue; - + foreach ( $teams as $key => $team_id ): + if ( -1 == $team_id ) continue; + + if ( -1 == $sections ) { // 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() ) ); - - $tabs = array(); - - if ( $team_id ): - $tabs['values'] = get_the_title( $team_id ); - elseif ( $i ): - echo '
'; - endif; - - $tabs = apply_filters( 'sportspress_event_performance_tabs_admin', $tabs ); ?>
- - 1 ): ?> - - - -

- - - +

+
+ -
- - - - - $team_id ): - if ( -1 == $team_id ) continue; + // Get labels by section + $args = array( + 'post_type' => 'sp_performance', + 'numberposts' => 100, + 'posts_per_page' => 100, + 'orderby' => 'menu_order', + 'order' => 'ASC', + ); - // 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() ) ); + $columns = get_posts( $args ); - foreach ( $data as $player_id => $player_performance ): - self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, false, false ); - endforeach; - endforeach; - ?> - -
-
+ $offense_labels = $defense_labels = array(); + foreach ( $columns as $column ): + $section = get_post_meta( $column->ID, 'sp_section', true ); + if ( '' === $section ) { + $section = -1; + } + switch ( $section ): + case 1: + $defense_labels[ $column->post_name ] = $column->post_title; + break; + case 0: + $offense_labels[ $column->post_name ] = $column->post_title; + break; + default: + $defense_labels[ $column->post_name ] = $column->post_title; + $offense_labels[ $column->post_name ] = $column->post_title; + endswitch; + endforeach; + + // Get results for offensive players in the team + $offense = sp_array_between( (array)get_post_meta( $post_id, 'sp_offense', false ), 0, $key ); + $offense[] = -1; + $offense_data = sp_array_combine( $offense, sp_array_value( $stats, $team_id, array() ) ); + + // Get results for defensive players in the team + $defense = sp_array_between( (array)get_post_meta( $post_id, 'sp_defense', false ), 0, $key ); + $defense[] = -1; + $defense_data = sp_array_combine( $defense, sp_array_value( $stats, $team_id, array() ) ); + ?> +
+

+ + +
+
+

+ + +
- - + + $player_performance ): - self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status ); + self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, true, true, $section, $formats ); endforeach; ?> @@ -180,7 +169,7 @@ class SP_Meta_Box_Event_Performance { /** * Admin edit table header */ - public static function header( $columns = array(), $labels = array(), $positions = array(), $has_checkboxes = false, $status = true, $sortable = true, $numbers = true ) { + public static function header( $columns = array(), $labels = array(), $positions = array(), $has_checkboxes = false, $status = true, $sortable = true, $numbers = true, $section = -1, $formats = array() ) { ?> @@ -221,10 +210,10 @@ class SP_Meta_Box_Event_Performance { /** * Admin edit table footer */ - public static function footer( $data = array(), $labels = array(), $team_id = 0, $positions = array(), $split_positions = false, $status = true, $sortable = true, $numbers = true ) { + public static function footer( $data = array(), $labels = array(), $team_id = 0, $positions = array(), $status = true, $sortable = true, $numbers = true, $section = -1, $formats = array() ) { ?> - + @@ -242,7 +231,7 @@ class SP_Meta_Box_Event_Performance { $player_performance = sp_array_value( $data, $player_id, array() ); $value = sp_array_value( $player_performance, $column, '' ); ?> - + @@ -256,7 +245,7 @@ class SP_Meta_Box_Event_Performance { /** * Admin edit table row */ - public static function row( $labels = array(), $player_id = 0, $player_performance = array(), $team_id = 0, $data = array(), $positions = true, $status = true, $sortable = true, $numbers = true ) { + public static function row( $labels = array(), $player_id = 0, $player_performance = array(), $team_id = 0, $data = array(), $positions = true, $status = true, $sortable = true, $numbers = true, $section = -1, $formats = array() ) { if ( $player_id <= 0 ) return; $number = get_post_meta( $player_id, 'sp_number', true ); @@ -296,9 +285,10 @@ class SP_Meta_Box_Event_Performance { $label ): $value = sp_array_value( $player_performance, $column, '' ); + $placeholder = sp_get_format_placeholder( sp_array_value( $formats, $column, 'number' ) ); ?> diff --git a/includes/admin/views/html-admin-config.php b/includes/admin/views/html-admin-config.php index 0f418e6c..fc84324a 100644 --- a/includes/admin/views/html-admin-config.php +++ b/includes/admin/views/html-admin-config.php @@ -162,7 +162,8 @@ - + + @@ -171,7 +172,7 @@ - + + - +
readonly="readonly"value="" />   - +
>   - post_title; ?> post_name; ?>ID, 'sp_position' ) ? the_terms( $row->ID, 'sp_position' ) : __( 'All', 'sportspress' );; ?>ID ); ?>ID ); ?>

post_excerpt; ?>

diff --git a/includes/class-sp-event.php b/includes/class-sp-event.php index d101365a..8c519ec5 100644 --- a/includes/class-sp-event.php +++ b/includes/class-sp-event.php @@ -75,7 +75,28 @@ class SP_Event extends SP_Custom_Post{ public function performance( $admin = false ) { $teams = get_post_meta( $this->ID, 'sp_team', false ); $performance = (array)get_post_meta( $this->ID, 'sp_players', true ); - $labels = apply_filters( 'sportspress_event_performance_labels', sp_get_var_labels( 'sp_performance' ), $this ); + + $args = array( + 'post_type' => 'sp_performance', + 'numberposts' => 100, + 'posts_per_page' => 100, + 'orderby' => 'menu_order', + 'order' => 'ASC', + ); + + $vars = get_posts( $args ); + + $labels = array(); + foreach ( $vars as $var ) { + $labels[ $var->post_name ] = $var->post_title; + $format = get_post_meta( $var->ID, 'sp_format', true ); + if ( '' === $format ) { + $format = 'number'; + } + $formats[ $var->post_name ] = $format; + } + + $labels = apply_filters( 'sportspress_event_performance_labels', $labels, $this ); $columns = get_post_meta( $this->ID, 'sp_columns', true ); if ( is_array( $teams ) ): foreach( $teams as $i => $team_id ): @@ -111,7 +132,7 @@ class SP_Event extends SP_Custom_Post{ endif; if ( $admin ): - return array( $labels, $columns, $performance, $teams ); + return array( $labels, $columns, $performance, $teams, $formats ); else: // Add position to performance labels if ( taxonomy_exists( 'sp_position' ) ):