Add ability to sort defensive players in box score

This commit is contained in:
Brian Miyaji
2016-02-17 03:14:15 +11:00
parent f7aaf4f16a
commit 73f9584b29
3 changed files with 33 additions and 9 deletions

View File

@@ -20,7 +20,7 @@ class SP_Meta_Box_Event_Performance {
*/ */
public static function output( $post ) { public static function output( $post ) {
$event = new SP_Event( $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 // Determine if columns are auto or manual
if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) ) if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) )
@@ -54,7 +54,7 @@ class SP_Meta_Box_Event_Performance {
// Apply filters to labels // Apply filters to labels
$labels = apply_filters( 'sportspress_event_performance_labels_admin', $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 ) { 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_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_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 * 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 ); $sections = get_option( 'sportspress_event_performance_sections', -1 );
$i = 0; $i = 0;
@@ -84,7 +85,7 @@ class SP_Meta_Box_Event_Performance {
?> ?>
<div> <div>
<p><strong><?php echo get_the_title( $team_id ); ?></strong></p> <p><strong><?php echo get_the_title( $team_id ); ?></strong></p>
<?php self::table( $labels, $columns, $data, $team_id, $has_checkboxes, $positions, $status, -1, $formats ); ?> <?php self::table( $labels, $columns, $data, $team_id, $has_checkboxes, $positions, $status, -1, $formats, $order ); ?>
<?php do_action( 'sportspress_after_event_performance_table_admin', $labels, $columns, $data, $team_id ); ?> <?php do_action( 'sportspress_after_event_performance_table_admin', $labels, $columns, $data, $team_id ); ?>
</div> </div>
<?php } else { ?> <?php } else { ?>
@@ -131,12 +132,12 @@ class SP_Meta_Box_Event_Performance {
?> ?>
<div> <div>
<p><strong><?php echo get_the_title( $team_id ); ?> &mdash; <?php _e( 'Offense', 'sportspress' ); ?></strong></p> <p><strong><?php echo get_the_title( $team_id ); ?> &mdash; <?php _e( 'Offense', 'sportspress' ); ?></strong></p>
<?php self::table( $offense_labels, $columns, $offense_data, $team_id, $has_checkboxes, $positions, $status, 0, $formats ); ?> <?php self::table( $offense_labels, $columns, $offense_data, $team_id, $has_checkboxes, $positions, $status, 0, $formats, $order ); ?>
<?php do_action( 'sportspress_after_event_performance_table_admin', $offense_labels, $columns, $offense_data, $team_id ); ?> <?php do_action( 'sportspress_after_event_performance_table_admin', $offense_labels, $columns, $offense_data, $team_id ); ?>
</div> </div>
<div> <div>
<p><strong><?php echo get_the_title( $team_id ); ?> &mdash; <?php _e( 'Defense', 'sportspress' ); ?></strong></p> <p><strong><?php echo get_the_title( $team_id ); ?> &mdash; <?php _e( 'Defense', 'sportspress' ); ?></strong></p>
<?php self::table( $defense_labels, $columns, $defense_data, $team_id, $has_checkboxes, $positions, $status, 1, $formats ); ?> <?php self::table( $defense_labels, $columns, $defense_data, $team_id, $has_checkboxes, $positions, $status, 1, $formats, $order ); ?>
<?php do_action( 'sportspress_after_event_performance_table_admin', $defense_labels, $columns, $defense_data, $team_id ); ?> <?php do_action( 'sportspress_after_event_performance_table_admin', $defense_labels, $columns, $defense_data, $team_id ); ?>
</div> </div>
<?php <?php
@@ -148,7 +149,7 @@ class SP_Meta_Box_Event_Performance {
/** /**
* Admin edit table * Admin edit table
*/ */
public static function table( $labels = array(), $columns = array(), $data = array(), $team_id, $has_checkboxes = false, $positions = array(), $status = true, $section = -1, $formats = array() ) { public static function table( $labels = array(), $columns = array(), $data = array(), $team_id, $has_checkboxes = false, $positions = array(), $status = true, $section = -1, $formats = array(), $order = array() ) {
?> ?>
<div class="sp-data-table-container"> <div class="sp-data-table-container">
<table class="widefat sp-data-table sp-performance-table sp-sortable-table"> <table class="widefat sp-data-table sp-performance-table sp-sortable-table">
@@ -156,6 +157,12 @@ class SP_Meta_Box_Event_Performance {
<?php self::footer( $data, $labels, $team_id, $positions, $status, true, true, $section, $formats ); ?> <?php self::footer( $data, $labels, $team_id, $positions, $status, true, true, $section, $formats ); ?>
<tbody> <tbody>
<?php <?php
if ( 1 == $section && is_array( $order ) && sizeof( $order ) ) {
$player_order = sp_array_value( $order, $team_id, array() );
if ( is_array( $player_order ) ) {
$data = sp_array_combine( $player_order, $data, true );
}
}
foreach ( $data as $player_id => $player_performance ): foreach ( $data as $player_id => $player_performance ):
self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, true, true, $section, $formats ); self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, true, true, $section, $formats );
endforeach; endforeach;
@@ -260,7 +267,12 @@ class SP_Meta_Box_Event_Performance {
<input class="small-text sp-player-number-input" type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][number]" value="<?php echo esc_attr( $value ); ?>" /> <input class="small-text sp-player-number-input" type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][number]" value="<?php echo esc_attr( $value ); ?>" />
</td> </td>
<?php } ?> <?php } ?>
<td><?php echo get_the_title( $player_id ); ?></td> <td>
<?php echo get_the_title( $player_id ); ?>
<?php if ( 1 == $section ) { ?>
<input type="hidden" name="sp_order[<?php echo $team_id; ?>][]" value="<?php echo $player_id; ?>">
<?php } ?>
</td>
<?php if ( $positions ) { ?> <?php if ( $positions ) { ?>
<td> <td>
<?php <?php

View File

@@ -96,6 +96,8 @@ class SP_Event extends SP_Custom_Post{
$formats[ $var->post_name ] = $format; $formats[ $var->post_name ] = $format;
} }
$order = (array)get_post_meta( $this->ID, 'sp_order', true );
$labels = apply_filters( 'sportspress_event_performance_labels', $labels, $this ); $labels = apply_filters( 'sportspress_event_performance_labels', $labels, $this );
$columns = get_post_meta( $this->ID, 'sp_columns', true ); $columns = get_post_meta( $this->ID, 'sp_columns', true );
if ( is_array( $teams ) ): if ( is_array( $teams ) ):
@@ -132,7 +134,7 @@ class SP_Event extends SP_Custom_Post{
endif; endif;
if ( $admin ): if ( $admin ):
return array( $labels, $columns, $performance, $teams, $formats ); return array( $labels, $columns, $performance, $teams, $formats, $order );
else: else:
// Add position to performance labels // Add position to performance labels
if ( taxonomy_exists( 'sp_position' ) ): if ( taxonomy_exists( 'sp_position' ) ):

View File

@@ -150,6 +150,16 @@ if ( is_array( $teams ) ):
foreach ( $section_order as $section_id => $section_label ) { foreach ( $section_order as $section_id => $section_label ) {
if ( sizeof( $data[ $section_id ] ) ) { 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( sp_get_template( 'event-performance-table.php', array(
'section' => $section_label, 'section' => $section_label,
'scrollable' => $scrollable, 'scrollable' => $scrollable,