Fix PHP warning when no columns are selected in table

This commit is contained in:
Brian Miyaji
2014-03-11 10:28:47 +11:00
parent dfd4ff7904
commit f839dfe76b
2 changed files with 49 additions and 40 deletions

View File

@@ -47,11 +47,7 @@ function sportspress_table_meta_init( $post ) {
remove_meta_box( 'sp_seasondiv', 'sp_table', 'side' );
remove_meta_box( 'sp_leaguediv', 'sp_table', 'side' );
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sportspress_table_team_meta', 'sp_table', 'side', 'default' );
if ( $teams && $teams != array(0) ):
add_meta_box( 'sp_columnsdiv', __( 'League Table', 'sportspress' ), 'sportspress_table_columns_meta', 'sp_table', 'normal', 'high' );
endif;
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_table_details_meta', 'sp_table', 'normal', 'high' );
}

View File

@@ -772,7 +772,8 @@ if ( !function_exists( 'sportspress_get_var_calculates' ) ) {
}
if ( !function_exists( 'sportspress_edit_league_table' ) ) {
function sportspress_edit_league_table( $columns = array(), $usecolumns = array(), $data = array(), $placeholders = array() ) {
function sportspress_edit_league_table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array() ) {
if ( is_array( $usecolumns ) )
$usecolumns = array_filter( $usecolumns );
?>
<div class="sp-data-table-container">
@@ -782,7 +783,7 @@ if ( !function_exists( 'sportspress_edit_league_table' ) ) {
<th><?php _e( 'Team', 'sportspress' ); ?></th>
<?php foreach ( $columns as $key => $label ): ?>
<th><label for="sp_columns_<?php echo $key; ?>">
<input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! $usecolumns || empty( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
<input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns) || in_array( $key, $usecolumns ) ); ?>>
<?php echo $label; ?>
</label></th>
<?php endforeach; ?>
@@ -790,6 +791,7 @@ if ( !function_exists( 'sportspress_edit_league_table' ) ) {
</thead>
<tbody>
<?php
if ( is_array( $data ) && sizeof( $data ) > 0 ):
$i = 0;
foreach ( $data as $team_id => $team_stats ):
if ( !$team_id )
@@ -822,6 +824,15 @@ if ( !function_exists( 'sportspress_edit_league_table' ) ) {
<?php
$i++;
endforeach;
else:
?>
<tr class="sp-row alternate">
<td colspan="<?php $colspan = sizeof( $columns ) + 1; echo $colspan; ?>">
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ); ?>
</td>
</tr>
<?php
endif;
?>
</tbody>
</table>
@@ -1897,6 +1908,8 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
if ( $breakdown ):
return array( $columns, $usecolumns, $data, $placeholders, $merged );
else:
if ( ! is_array( $usecolumns ) )
$usecolumns = array();
foreach ( $columns as $key => $label ):
if ( ! in_array( $key, $usecolumns ) ):
unset( $columns[ $key ] );