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 ) {
$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;
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
*/
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;
?>
<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">
<thead>
<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><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 ) ); ?>>
<?php _e( 'Team', 'sportspress' ); ?>
</label></th>
<?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; ?>">
<?php echo $label; ?>
</label></th>
@@ -76,7 +79,15 @@ class SP_Meta_Box_List_Data {
$default_name = get_the_title( $player_id );
?>
<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>
<?php if ( $show_player_photo ) echo get_the_post_thumbnail( $player_id, 'sportspress-fit-mini' ); ?>
<span class="sp-default-value">
@@ -105,7 +116,7 @@ class SP_Meta_Box_List_Data {
?>
</td>
<?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, '' );
$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 ):
$labels = array();
foreach( $this->columns as $key ):
if ( $key == 'team' ):
if ( $key == 'number' ):
$labels[ $key ] = '#';
elseif ( $key == 'team' ):
$labels[ $key ] = __( 'Team', 'sportspress' );
elseif ( array_key_exists( $key, $columns ) ):
$labels[ $key ] = $columns[ $key ];
endif;
endforeach;
return array( $labels, $data, $placeholders, $merged );
return array( $labels, $data, $placeholders, $merged, $orderby );
else:
if ( ! is_array( $this->columns ) )
$this->columns = array();
@@ -373,9 +375,10 @@ class SP_Player_List extends SP_Custom_Post {
endif;
endforeach;
$labels = array( 'name' => __( 'Player', 'sportspress' ) );
if ( in_array( 'team', $this->columns ) )
$labels['team'] = __( 'Team', 'sportspress' );
$labels = array();
if ( in_array( 'number', $this->columns ) ) $labels['number'] = '#';
$labels['name'] = __( 'Player', 'sportspress' );
if ( in_array( 'team', $this->columns ) ) $labels['team'] = __( 'Team', 'sportspress' );
$merged[0] = array_merge( $labels, $columns );
return $merged;

View File

@@ -84,14 +84,16 @@ foreach ( $groups as $group ):
$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>';
if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ):
if ( in_array( $orderby, array( 'number', 'name' ) ) ):
$output .= '<th class="data-number">#</th>';
else:
$output .= '<th class="data-rank">' . __( 'Rank', 'sportspress' ) . '</th>';
endif;
endif;
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>';
endforeach;
@@ -112,11 +114,13 @@ foreach ( $groups as $group ):
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
// Rank or number
if ( ! is_array( $labels ) || array_key_exists( 'number', $labels ) ):
if ( isset( $orderby ) && $orderby != 'number' ):
$output .= '<td class="data-rank">' . ( $i + 1 ) . '</td>';
else:
$output .= '<td class="data-number">' . sp_array_value( $row, 'number', '&nbsp;' ) . '</td>';
endif;
endif;
$name_class = '';
@@ -145,7 +149,7 @@ foreach ( $groups as $group ):
endif;
foreach( $labels as $key => $value ):
if ( in_array( $key, array( 'name', 'team' ) ) )
if ( in_array( $key, array( 'number', 'name', 'team' ) ) )
continue;
if ( ! is_array( $columns ) || in_array( $key, $columns ) )
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '&mdash;' ) . '</td>';