Display performance column only if positions exist

This commit is contained in:
Brian Miyaji
2015-09-17 17:03:20 +10:00
parent 93e9a2e18f
commit af7dea5ac0
2 changed files with 43 additions and 27 deletions

View File

@@ -79,6 +79,14 @@ 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, $split_positions = false ) { public static function table( $labels = array(), $columns = array(), $data = array(), $team_id, $has_checkboxes = false, $split_positions = false ) {
if ( taxonomy_exists( 'sp_position' ) ) {
$args = array(
'hide_empty' => false,
'parent' => 0,
'include_children' => true,
);
$positions = get_terms( 'sp_position', $args );
}
?> ?>
<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">
@@ -87,9 +95,11 @@ class SP_Meta_Box_Event_Performance {
<th class="icon">&nbsp;</th> <th class="icon">&nbsp;</th>
<th>#</th> <th>#</th>
<th><?php _e( 'Player', 'sportspress' ); ?></th> <th><?php _e( 'Player', 'sportspress' ); ?></th>
<?php if ( ! empty( $positions ) ) { ?>
<th class="column-position"> <th class="column-position">
<?php _e( 'Position', 'sportspress' ); ?> <?php _e( 'Position', 'sportspress' ); ?>
</th> </th>
<?php } ?>
<?php foreach ( $labels as $key => $label ): ?> <?php foreach ( $labels as $key => $label ): ?>
<th> <th>
<?php if ( $has_checkboxes ): ?> <?php if ( $has_checkboxes ): ?>
@@ -119,7 +129,9 @@ class SP_Meta_Box_Event_Performance {
<td>&nbsp;</td> <td>&nbsp;</td>
<td>&nbsp;</td> <td>&nbsp;</td>
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td> <td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
<?php if ( ! empty( $positions ) ) { ?>
<td>&nbsp;</td> <td>&nbsp;</td>
<?php } ?>
<?php foreach( $labels as $column => $label ): <?php foreach( $labels as $column => $label ):
$player_id = 0; $player_id = 0;
$player_performance = sp_array_value( $data, $player_id, array() ); $player_performance = sp_array_value( $data, $player_id, array() );
@@ -133,7 +145,7 @@ class SP_Meta_Box_Event_Performance {
<tbody> <tbody>
<?php <?php
foreach ( $data as $player_id => $player_performance ): foreach ( $data as $player_id => $player_performance ):
self::row( $labels, $player_id, $player_performance, $team_id, $data ); self::row( $labels, $player_id, $player_performance, $team_id, $data, ! empty( $positions ) );
endforeach; endforeach;
?> ?>
</tbody> </tbody>
@@ -145,7 +157,7 @@ class SP_Meta_Box_Event_Performance {
/** /**
* Admin edit table row * Admin edit table row
*/ */
public static function row( $labels = array(), $player_id = 0, $player_performance = array(), $team_id = 0, $data = array() ) { public static function row( $labels = array(), $player_id = 0, $player_performance = array(), $team_id = 0, $data = array(), $positions = true ) {
if ( $player_id <= 0 ) return; if ( $player_id <= 0 ) return;
$number = get_post_meta( $player_id, 'sp_number', true ); $number = get_post_meta( $player_id, 'sp_number', true );
@@ -157,6 +169,7 @@ 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 $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 $value; ?>" />
</td> </td>
<td><?php echo get_the_title( $player_id ); ?></td> <td><?php echo get_the_title( $player_id ); ?></td>
<?php if ( $positions ) { ?>
<td> <td>
<?php <?php
$selected = (array) sp_array_value( $player_performance, 'position', null ); $selected = (array) sp_array_value( $player_performance, 'position', null );
@@ -177,6 +190,7 @@ class SP_Meta_Box_Event_Performance {
sp_dropdown_taxonomies( $args ); sp_dropdown_taxonomies( $args );
?> ?>
</td> </td>
<?php } ?>
<?php foreach( $labels as $column => $label ): <?php foreach( $labels as $column => $label ):
$value = sp_array_value( $player_performance, $column, '' ); $value = sp_array_value( $player_performance, $column, '' );
?> ?>

View File

@@ -114,7 +114,9 @@ class SP_Event extends SP_Custom_Post{
return array( $labels, $columns, $performance, $teams ); return array( $labels, $columns, $performance, $teams );
else: else:
// Add position to performance labels // Add position to performance labels
if ( taxonomy_exists( 'sp_position' ) ):
$labels = array_merge( array( 'position' => __( 'Position', 'sportspress' ) ), $labels ); $labels = array_merge( array( 'position' => __( 'Position', 'sportspress' ) ), $labels );
endif;
if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) && is_array( $columns ) ): if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) && is_array( $columns ) ):
foreach ( $labels as $key => $label ): foreach ( $labels as $key => $label ):
if ( ! in_array( $key, $columns ) ): if ( ! in_array( $key, $columns ) ):