Option to hide rank column in player lists fix #52

This commit is contained in:
Brian Miyaji
2014-10-19 12:41:52 +11:00
parent 7746f8396f
commit adb7324349
3 changed files with 40 additions and 22 deletions

View File

@@ -20,9 +20,9 @@ class SP_Meta_Box_List_Data {
*/ */
public static function output( $post ) { public static function output( $post ) {
$list = new SP_Player_List( $post ); $list = new SP_Player_List( $post );
list( $columns, $data, $placeholders, $merged ) = $list->data( true ); list( $columns, $data, $placeholders, $merged, $orderby ) = $list->data( true );
$adjustments = $list->adjustments; $adjustments = $list->adjustments;
self::table( $columns, $data, $placeholders, $adjustments ); self::table( $columns, $data, $placeholders, $adjustments, $orderby );
} }
/** /**
@@ -36,7 +36,7 @@ class SP_Meta_Box_List_Data {
/** /**
* Admin edit table * Admin edit table
*/ */
public static function table( $columns = array(), $data = array(), $placeholders = array(), $adjustments = array() ) { public static function table( $columns = array(), $data = array(), $placeholders = array(), $adjustments = array(), $orderby = 'number' ) {
$show_player_photo = get_option( 'sportspress_list_show_photos', 'no' ) == 'yes' ? true : false; $show_player_photo = get_option( 'sportspress_list_show_photos', 'no' ) == 'yes' ? true : false;
?> ?>
<ul class="subsubsub sp-table-bar"> <ul class="subsubsub sp-table-bar">
@@ -47,14 +47,17 @@ class SP_Meta_Box_List_Data {
<table class="widefat sp-data-table sp-player-list-table"> <table class="widefat sp-data-table sp-player-list-table">
<thead> <thead>
<tr> <tr>
<th>#</th> <th><label for="sp_columns_number">
<input type="checkbox" name="sp_columns[]" value="number" id="sp_columns_number" <?php checked( ! is_array( $columns ) || array_key_exists( 'number', $columns ) ); ?>>
<?php echo 'number' == $orderby ? '#' : __( 'Rank', 'sportspress' ); ?>
</label></th>
<th><?php _e( 'Player', 'sportspress' ); ?></th> <th><?php _e( 'Player', 'sportspress' ); ?></th>
<th><label for="sp_columns_team"> <th><label for="sp_columns_team">
<input type="checkbox" name="sp_columns[]" value="team" id="sp_columns_team" <?php checked( ! is_array( $columns ) || array_key_exists( 'team', $columns ) ); ?>> <input type="checkbox" name="sp_columns[]" value="team" id="sp_columns_team" <?php checked( ! is_array( $columns ) || array_key_exists( 'team', $columns ) ); ?>>
<?php _e( 'Team', 'sportspress' ); ?> <?php _e( 'Team', 'sportspress' ); ?>
</label></th> </label></th>
<?php foreach ( $columns as $key => $label ): ?> <?php foreach ( $columns as $key => $label ): ?>
<?php if ( $key == 'team' ) continue; ?> <?php if ( in_array( $key, array( 'number', 'team' ) ) ) continue; ?>
<th><label for="sp_columns_<?php echo $key; ?>"> <th><label for="sp_columns_<?php echo $key; ?>">
<?php echo $label; ?> <?php echo $label; ?>
</label></th> </label></th>
@@ -76,7 +79,15 @@ class SP_Meta_Box_List_Data {
$default_name = get_the_title( $player_id ); $default_name = get_the_title( $player_id );
?> ?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>"> <tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td><?php echo ( $number ? $number : '&nbsp;' ); ?></td> <td>
<?php
if ( 'number' == $orderby ) {
echo ( $number ? $number : '&nbsp;' );
} else {
echo $i + 1;
}
?>
</td>
<td> <td>
<?php if ( $show_player_photo ) echo get_the_post_thumbnail( $player_id, 'sportspress-fit-mini' ); ?> <?php if ( $show_player_photo ) echo get_the_post_thumbnail( $player_id, 'sportspress-fit-mini' ); ?>
<span class="sp-default-value"> <span class="sp-default-value">
@@ -105,7 +116,7 @@ class SP_Meta_Box_List_Data {
?> ?>
</td> </td>
<?php foreach( $columns as $column => $label ): <?php foreach( $columns as $column => $label ):
if ( $column == 'team' ) continue; if ( in_array( $column, array( 'number', 'team' ) ) ) continue;
$value = sp_array_value( $player_stats, $column, '' ); $value = sp_array_value( $player_stats, $column, '' );
$placeholder = sp_array_value( sp_array_value( $placeholders, $player_id, array() ), $column, 0 ); $placeholder = sp_array_value( sp_array_value( $placeholders, $player_id, array() ), $column, 0 );
?> ?>

View File

@@ -357,13 +357,15 @@ class SP_Player_List extends SP_Custom_Post {
if ( $admin ): if ( $admin ):
$labels = array(); $labels = array();
foreach( $this->columns as $key ): foreach( $this->columns as $key ):
if ( $key == 'team' ): if ( $key == 'number' ):
$labels[ $key ] = '#';
elseif ( $key == 'team' ):
$labels[ $key ] = __( 'Team', 'sportspress' ); $labels[ $key ] = __( 'Team', 'sportspress' );
elseif ( array_key_exists( $key, $columns ) ): elseif ( array_key_exists( $key, $columns ) ):
$labels[ $key ] = $columns[ $key ]; $labels[ $key ] = $columns[ $key ];
endif; endif;
endforeach; endforeach;
return array( $labels, $data, $placeholders, $merged ); return array( $labels, $data, $placeholders, $merged, $orderby );
else: else:
if ( ! is_array( $this->columns ) ) if ( ! is_array( $this->columns ) )
$this->columns = array(); $this->columns = array();
@@ -373,9 +375,10 @@ class SP_Player_List extends SP_Custom_Post {
endif; endif;
endforeach; endforeach;
$labels = array( 'name' => __( 'Player', 'sportspress' ) ); $labels = array();
if ( in_array( 'team', $this->columns ) ) if ( in_array( 'number', $this->columns ) ) $labels['number'] = '#';
$labels['team'] = __( 'Team', 'sportspress' ); $labels['name'] = __( 'Player', 'sportspress' );
if ( in_array( 'team', $this->columns ) ) $labels['team'] = __( 'Team', 'sportspress' );
$merged[0] = array_merge( $labels, $columns ); $merged[0] = array_merge( $labels, $columns );
return $merged; return $merged;

View File

@@ -84,14 +84,16 @@ foreach ( $groups as $group ):
$output .= '<div class="sp-table-wrapper' . ( $scrollable ? ' sp-scrollable-table-wrapper' : '' ) . '">' . $output .= '<div class="sp-table-wrapper' . ( $scrollable ? ' sp-scrollable-table-wrapper' : '' ) . '">' .
'<table class="sp-player-list sp-data-table' . ( $responsive ? ' sp-responsive-table' : '' ) . ( $sortable ? ' sp-sortable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>'; '<table class="sp-player-list sp-data-table' . ( $responsive ? ' sp-responsive-table' : '' ) . ( $sortable ? ' sp-sortable-table' : '' ) . ( $paginated ? ' sp-paginated-table' : '' ) . '" data-sp-rows="' . $rows . '">' . '<thead>' . '<tr>';
if ( in_array( $orderby, array( 'number', 'name' ) ) ): if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ):
$output .= '<th class="data-number">#</th>'; if ( in_array( $orderby, array( 'number', 'name' ) ) ):
else: $output .= '<th class="data-number">#</th>';
$output .= '<th class="data-rank">' . __( 'Rank', 'sportspress' ) . '</th>'; else:
$output .= '<th class="data-rank">' . __( 'Rank', 'sportspress' ) . '</th>';
endif;
endif; endif;
foreach( $labels as $key => $label ): foreach( $labels as $key => $label ):
if ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) ) if ( $key !== 'number' && ( ! is_array( $columns ) || $key == 'name' || in_array( $key, $columns ) ) )
$output .= '<th class="data-' . $key . '">'. $label . '</th>'; $output .= '<th class="data-' . $key . '">'. $label . '</th>';
endforeach; endforeach;
@@ -112,10 +114,12 @@ foreach ( $groups as $group ):
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">'; $output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
// Rank or number // Rank or number
if ( isset( $orderby ) && $orderby != 'number' ): if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ):
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>'; if ( isset( $orderby ) && $orderby != 'number' ):
else: $output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
$output .= '<td class="data-number">' . sp_array_value( $row, 'number', '&nbsp;' ) . '</td>'; else:
$output .= '<td class="data-number">' . sp_array_value( $row, 'number', '&nbsp;' ) . '</td>';
endif;
endif; endif;
$name_class = ''; $name_class = '';
@@ -145,7 +149,7 @@ foreach ( $groups as $group ):
endif; endif;
foreach( $labels as $key => $value ): foreach( $labels as $key => $value ):
if ( in_array( $key, array( 'name', 'team' ) ) ) if ( in_array( $key, array( 'number', 'name', 'team' ) ) )
continue; continue;
if ( ! is_array( $columns ) || in_array( $key, $columns ) ) if ( ! is_array( $columns ) || in_array( $key, $columns ) )
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '&mdash;' ) . '</td>'; $output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '&mdash;' ) . '</td>';