Add player performance format selector

This commit is contained in:
Brian Miyaji
2016-03-02 23:09:43 +11:00
parent 6bf57e27b9
commit 2b26d1166f
4 changed files with 22 additions and 9 deletions

View File

@@ -167,6 +167,7 @@ class SP_Admin_Sports {
update_post_meta( $id, 'sp_icon', sp_array_value( $performance, 'icon', null ) );
update_post_meta( $id, 'sp_color', sp_array_value( $performance, 'color', null ) );
update_post_meta( $id, 'sp_section', sp_array_value( $performance, 'section', -1 ) );
update_post_meta( $id, 'sp_format', sp_array_value( $performance, 'format', 'number' ) );
$i ++;
}

View File

@@ -202,11 +202,22 @@ class SP_Meta_Box_Event_Performance {
<tbody>
<?php
if ( 1 == $section && is_array( $order ) && sizeof( $order ) ) {
$players = array();
$player_order = sp_array_value( $order, $team_id, array() );
if ( is_array( $player_order ) && sizeof( $player_order ) ) {
$data = sp_array_combine( $player_order, $data, true );
foreach ( $player_order as $key ) {
if ( array_key_exists( $key, $data ) ):
$players[ $key ] = $data[ $key ];
endif;
}
}
foreach ( $data as $key => $player ) {
if ( ! array_key_exists( $key, $players ) ) {
$players[ $key ] = $player;
}
}
$data = $players;
}
foreach ( $data as $player_id => $player_performance ):
self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ), $status, true, $numbers, $section, $formats );
endforeach;
@@ -248,7 +259,7 @@ class SP_Meta_Box_Event_Performance {
<?php endif; ?>
</th>
<?php endforeach; ?>
<?php if ( $status ) { ?>
<?php if ( $status && 1 !== $section ) { ?>
<th>
<?php _e( 'Status', 'sportspress' ); ?>
</th>
@@ -286,7 +297,7 @@ class SP_Meta_Box_Event_Performance {
?>
<td><input type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" placeholder="<?php echo trim( $placeholder ); ?>" value="<?php echo esc_attr( $value ); ?>" data-sp-format="<?php echo $format; ?>" /></td>
<?php endforeach; ?>
<?php if ( $status ) { ?>
<?php if ( $status && 1 !== $section ) { ?>
<td>&nbsp;</td>
<?php } ?>
</tr>
@@ -349,7 +360,7 @@ class SP_Meta_Box_Event_Performance {
<input class="sp-player-<?php echo $column; ?>-input" type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo esc_attr( $value ); ?>" placeholder="<?php echo $placeholder; ?>" />
</td>
<?php endforeach; ?>
<?php if ( $status ) { ?>
<?php if ( $status && 1 !== $section ) { ?>
<td class="sp-status-selector">
<?php echo self::status_select( $team_id, $player_id, sp_array_value( $player_performance, 'status', null ) ); ?>
<?php echo self::sub_select( $team_id, $player_id, sp_array_value( $player_performance, 'sub', null ), $data ); ?>

View File

@@ -49,7 +49,7 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
<?php
$options = apply_filters( 'sportspress_performance_sections', array( -1 => __( 'All', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $section ), $value );
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $section, true, false ), $value );
endforeach;
?>
</select>
@@ -60,7 +60,7 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
<?php
$options = apply_filters( 'sportspress_performance_formats', array( 'number' => __( 'Number', 'sportspress' ), 'text' => __( 'Text', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $format ), $value );
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $format, true, false ), $value );
endforeach;
?>
</select>

View File

@@ -13,7 +13,8 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$totals = array();
// Set null
if ( ! isset( $section ) ) $section = null;
if ( ! isset( $section ) ) $section = -1;
if ( ! isset( $section_label ) ) $section_label = null;
if ( ! isset( $class ) ) $class = null;
// Initialize arrays
@@ -33,8 +34,8 @@ if ( ! isset( $subs ) ) $subs = array();
<th class="data-number">#</th>
<?php } ?>
<th class="data-name">
<?php if ( isset( $section ) ) { ?>
<?php echo $section; ?>
<?php if ( isset( $section_label ) ) { ?>
<?php echo $section_label; ?>
<?php } else { ?>
<?php _e( 'Player', 'sportspress' ); ?>
<?php } ?>