Enable selecting columns to use in league table
This commit is contained in:
@@ -128,6 +128,9 @@ function sportspress_save_post( $post_id ) {
|
|||||||
|
|
||||||
case ( 'sp_table' ):
|
case ( 'sp_table' ):
|
||||||
|
|
||||||
|
// Update columns array
|
||||||
|
update_post_meta( $post_id, 'sp_columns', sportspress_array_value( $_POST, 'sp_columns', array() ) );
|
||||||
|
|
||||||
// Update teams array
|
// Update teams array
|
||||||
update_post_meta( $post_id, 'sp_teams', sportspress_array_value( $_POST, 'sp_teams', array() ) );
|
update_post_meta( $post_id, 'sp_teams', sportspress_array_value( $_POST, 'sp_teams', array() ) );
|
||||||
|
|
||||||
|
|||||||
@@ -100,9 +100,9 @@ function sportspress_table_team_meta( $post, $test ) {
|
|||||||
|
|
||||||
function sportspress_table_columns_meta( $post ) {
|
function sportspress_table_columns_meta( $post ) {
|
||||||
|
|
||||||
list( $columns, $data, $placeholders, $merged ) = sportspress_get_league_table_data( $post->ID, true );
|
list( $columns, $usecolumns, $data, $placeholders, $merged ) = sportspress_get_league_table_data( $post->ID, true );
|
||||||
|
|
||||||
sportspress_edit_league_table( $columns, $data, $placeholders );
|
sportspress_edit_league_table( $columns, $usecolumns, $data, $placeholders );
|
||||||
|
|
||||||
sportspress_nonce();
|
sportspress_nonce();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,7 +190,7 @@ if ( !function_exists( 'sportspress_get_post_datetime' ) ) {
|
|||||||
if ( $post->post_status == 'future' ):
|
if ( $post->post_status == 'future' ):
|
||||||
$status = __( 'Scheduled', 'sportspress' );
|
$status = __( 'Scheduled', 'sportspress' );
|
||||||
elseif( $post->post_status == 'publish' ):
|
elseif( $post->post_status == 'publish' ):
|
||||||
$status = __( 'Played', 'sportspress' );
|
$status = __( 'Published', 'sportspress' );
|
||||||
elseif( $post->post_status == 'draft' ):
|
elseif( $post->post_status == 'draft' ):
|
||||||
$status = __( 'Draft', 'sportspress' );
|
$status = __( 'Draft', 'sportspress' );
|
||||||
else:
|
else:
|
||||||
@@ -772,15 +772,18 @@ if ( !function_exists( 'sportspress_get_var_calculates' ) ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( !function_exists( 'sportspress_edit_league_table' ) ) {
|
if ( !function_exists( 'sportspress_edit_league_table' ) ) {
|
||||||
function sportspress_edit_league_table( $columns = array(), $data = array(), $placeholders = array() ) {
|
function sportspress_edit_league_table( $columns = array(), $usecolumns = array(), $data = array(), $placeholders = array() ) {
|
||||||
?>
|
?>
|
||||||
<div class="sp-data-table-container">
|
<div class="sp-data-table-container">
|
||||||
<table class="widefat sp-data-table sp-league-table">
|
<table class="widefat sp-data-table sp-league-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th><?php _e( 'Team', 'sportspress' ); ?></th>
|
<th><?php _e( 'Team', 'sportspress' ); ?></th>
|
||||||
<?php foreach ( $columns as $label ): ?>
|
<?php foreach ( $columns as $key => $label ): ?>
|
||||||
<th><?php echo $label; ?></th>
|
<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( array_filter( $usecolumns ) ) || in_array( $key, $usecolumns ) ); ?>>
|
||||||
|
<?php echo $label; ?>
|
||||||
|
</label></th>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -1638,6 +1641,7 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
|
|||||||
$div_id = sportspress_get_the_term_id( $post_id, 'sp_season', 0 );
|
$div_id = sportspress_get_the_term_id( $post_id, 'sp_season', 0 );
|
||||||
$team_ids = (array)get_post_meta( $post_id, 'sp_team', false );
|
$team_ids = (array)get_post_meta( $post_id, 'sp_team', false );
|
||||||
$table_stats = (array)get_post_meta( $post_id, 'sp_teams', true );
|
$table_stats = (array)get_post_meta( $post_id, 'sp_teams', true );
|
||||||
|
$usecolumns = get_post_meta( $post_id, 'sp_columns', true );
|
||||||
|
|
||||||
// Get labels from result variables
|
// Get labels from result variables
|
||||||
$result_labels = (array)sportspress_get_var_labels( 'sp_result' );
|
$result_labels = (array)sportspress_get_var_labels( 'sp_result' );
|
||||||
@@ -1890,8 +1894,13 @@ if ( !function_exists( 'sportspress_get_league_table_data' ) ) {
|
|||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
if ( $breakdown ):
|
if ( $breakdown ):
|
||||||
return array( $columns, $data, $placeholders, $merged );
|
return array( $columns, $usecolumns, $data, $placeholders, $merged );
|
||||||
else:
|
else:
|
||||||
|
foreach( $columns as $key => $label ):
|
||||||
|
if ( ! in_array( $key, $usecolumns ) ):
|
||||||
|
unset( $columns[ $key ] );
|
||||||
|
endif;
|
||||||
|
endforeach;
|
||||||
$labels = array_merge( array( 'name' => __( 'Team', 'sportspress' ) ), $columns );
|
$labels = array_merge( array( 'name' => __( 'Team', 'sportspress' ) ), $columns );
|
||||||
$merged[0] = $labels;
|
$merged[0] = $labels;
|
||||||
return $merged;
|
return $merged;
|
||||||
|
|||||||
Reference in New Issue
Block a user