Adjust player meta box for auto columns and split statistics

This commit is contained in:
Brian Miyaji
2016-04-02 03:57:53 +11:00
parent f7e345ec99
commit 1b2b8c1111
3 changed files with 16 additions and 13 deletions

View File

@@ -32,8 +32,8 @@ class SP_Meta_Box_Player_Statistics {
?>
<p><strong><?php echo $league->name; ?></strong></p>
<?php
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true );
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0 );
list( $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes ) = $player->data( $league->term_id, true );
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes && $i == 0 );
$i ++;
endforeach;
} else {
@@ -52,8 +52,8 @@ class SP_Meta_Box_Player_Statistics {
?>
<p><strong><?php echo $league->name; ?> &mdash; <?php echo $section_label; ?></strong></p>
<?php
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true, $section_id );
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0 && $s == 0 );
list( $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes ) = $player->data( $league->term_id, true, $section_id );
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $has_checkboxes && $i == 0 && $s == 0, $s == 0 );
$i ++;
endforeach;
$s ++;
@@ -73,7 +73,8 @@ class SP_Meta_Box_Player_Statistics {
/**
* Admin edit table
*/
public static function table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $has_checkboxes = false, $readonly = false ) {
public static function table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $has_checkboxes = false, $team_select = false ) {
$readonly = false;
$teams = array_filter( get_post_meta( $id, 'sp_team', false ) );
?>
<div class="sp-data-table-container">
@@ -81,7 +82,7 @@ class SP_Meta_Box_Player_Statistics {
<thead>
<tr>
<th><?php _e( 'Season', 'sportspress' ); ?></th>
<?php if ( apply_filters( 'sportspress_player_team_statistics', $league_id ) ): ?>
<?php if ( $team_select && apply_filters( 'sportspress_player_team_statistics', $league_id ) ): ?>
<th>
<?php if ( $has_checkboxes ): ?>
<label for="sp_columns_team">
@@ -104,7 +105,9 @@ class SP_Meta_Box_Player_Statistics {
<td>
<label><strong><?php _e( 'Total', 'sportspress' ); ?></strong></label>
</td>
<td>&nbsp;</td>
<?php if ( $team_select ) { ?>
<td>&nbsp;</td>
<?php } ?>
<?php foreach ( $columns as $column => $label ): if ( $column == 'team' ) continue;
?>
<td><?php
@@ -140,7 +143,7 @@ class SP_Meta_Box_Player_Statistics {
?>
</label>
</td>
<?php if ( apply_filters( 'sportspress_player_team_statistics', $league_id ) ): ?>
<?php if ( $team_select && apply_filters( 'sportspress_player_team_statistics', $league_id ) ): ?>
<?php if ( $div_id == 0 ): ?>
<td>&nbsp;</td>
<?php else: ?>

View File

@@ -128,6 +128,7 @@ class SP_Player extends SP_Custom_Post {
if ( 'manual' == get_option( 'sportspress_player_columns', 'auto' ) ) {
$usecolumns = get_post_meta( $this->ID, 'sp_columns', true );
$has_checkboxes = true;
} else {
$usecolumns = array();
if ( is_array( $posts ) ) {
@@ -139,6 +140,7 @@ class SP_Player extends SP_Custom_Post {
}
}
}
$has_checkboxes = false;
}
// Get labels by section
@@ -536,7 +538,7 @@ class SP_Player extends SP_Custom_Post {
$labels[ $key ] = $columns[ $key ];
endif;
endforeach; endif;
return array( $labels, $data, $placeholders, $merged, $leagues );
return array( $labels, $data, $placeholders, $merged, $leagues, $has_checkboxes );
else:
if ( is_array( $usecolumns ) ):
foreach ( $columns as $key => $label ):
@@ -552,9 +554,7 @@ class SP_Player extends SP_Custom_Post {
$merged = array();
} else {
$labels['name'] = __( 'Season', 'sportspress' );
if ( in_array( 'team', $this->columns ) ) {
$labels['team'] = __( 'Team', 'sportspress' );
}
$labels['team'] = __( 'Team', 'sportspress' );
}
if ( 'yes' === get_option( 'sportspress_player_show_total', 'no' ) ) {

View File

@@ -26,7 +26,7 @@ foreach( $data as $season_id => $row ):
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
foreach( $labels as $key => $value ):
$output .= '<td class="data-' . $key . ( -1 === $season_id ? ' sp-highlight' : '' ) . '">' . sp_array_value( $row, $key, '&mdash;' ) . '</td>';
$output .= '<td class="data-' . $key . ( -1 === $season_id ? ' sp-highlight' : '' ) . '">' . sp_array_value( $row, $key, '' ) . '</td>';
endforeach;
$output .= '</tr>';