From 73f9584b291ed026ef9ee81801717406ab8458ab Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 17 Feb 2016 03:14:15 +1100 Subject: [PATCH] Add ability to sort defensive players in box score --- .../class-sp-meta-box-event-performance.php | 28 +++++++++++++------ includes/class-sp-event.php | 4 ++- templates/event-performance.php | 10 +++++++ 3 files changed, 33 insertions(+), 9 deletions(-) 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 f307fcc2..c1ec02cf 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,7 +20,7 @@ class SP_Meta_Box_Event_Performance { */ public static function output( $post ) { $event = new SP_Event( $post ); - list( $labels, $columns, $stats, $teams, $formats ) = $event->performance( true ); + list( $labels, $columns, $stats, $teams, $formats, $order ) = $event->performance( true ); // Determine if columns are auto or manual if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) ) @@ -54,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, $positions, $status, $formats ); + self::tables( $post->ID, $stats, $labels, $columns, $teams, $has_checkboxes, $positions, $status, $formats, $order ); } /** @@ -63,12 +63,13 @@ class SP_Meta_Box_Event_Performance { public static function save( $post_id, $post ) { update_post_meta( $post_id, 'sp_players', sp_array_value( $_POST, 'sp_players', array() ) ); update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) ); + update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) ); } /** * Admin edit tables */ - public static function tables( $post_id, $stats = array(), $labels = array(), $columns = array(), $teams = array(), $has_checkboxes = false, $positions = array(), $status = true, $formats = array() ) { + public static function tables( $post_id, $stats = array(), $labels = array(), $columns = array(), $teams = array(), $has_checkboxes = false, $positions = array(), $status = true, $formats = array(), $order = array() ) { $sections = get_option( 'sportspress_event_performance_sections', -1 ); $i = 0; @@ -84,7 +85,7 @@ class SP_Meta_Box_Event_Performance { ?>

- +
@@ -131,12 +132,12 @@ class SP_Meta_Box_Event_Performance { ?>

- +

- +
@@ -156,6 +157,12 @@ class SP_Meta_Box_Event_Performance { $player_performance ): self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, true, true, $section, $formats ); endforeach; @@ -260,7 +267,12 @@ class SP_Meta_Box_Event_Performance { - +
+ + + + + post_name ] = $format; } + $order = (array)get_post_meta( $this->ID, 'sp_order', true ); + $labels = apply_filters( 'sportspress_event_performance_labels', $labels, $this ); $columns = get_post_meta( $this->ID, 'sp_columns', true ); if ( is_array( $teams ) ): @@ -132,7 +134,7 @@ class SP_Event extends SP_Custom_Post{ endif; if ( $admin ): - return array( $labels, $columns, $performance, $teams, $formats ); + return array( $labels, $columns, $performance, $teams, $formats, $order ); else: // Add position to performance labels if ( taxonomy_exists( 'sp_position' ) ): diff --git a/templates/event-performance.php b/templates/event-performance.php index 9b6a8dea..810de742 100644 --- a/templates/event-performance.php +++ b/templates/event-performance.php @@ -150,6 +150,16 @@ if ( is_array( $teams ) ): foreach ( $section_order as $section_id => $section_label ) { if ( sizeof( $data[ $section_id ] ) ) { + if ( 1 == $section_id ) { + $order = (array)get_post_meta( $id, 'sp_order', true ); + if ( is_array( $order ) && sizeof( $order ) ) { + $player_order = sp_array_value( $order, $team_id, array() ); + if ( is_array( $player_order ) ) { + $data[1] = sp_array_combine( $player_order, $data[1], true ); + } + } + } + sp_get_template( 'event-performance-table.php', array( 'section' => $section_label, 'scrollable' => $scrollable,