Filter by event_status (published or/and scheduled) the League Tables

This commit is contained in:
savvasha
2019-09-20 11:47:17 +03:00
parent 7bc3e645c8
commit bc609c245f
4 changed files with 69 additions and 2 deletions

View File

@@ -29,6 +29,10 @@ class SP_Meta_Box_Table_Details {
$date_to = get_post_meta( $post->ID, 'sp_date_to', true );
$date_past = get_post_meta( $post->ID, 'sp_date_past', true );
$date_relative = get_post_meta( $post->ID, 'sp_date_relative', true );
$event_status = get_post_meta( $post->ID, 'sp_event_status', true );
if ( empty( $event_status ) ) {
$event_status = array( 'publish', 'future' );
}
?>
<div>
<p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p>
@@ -89,6 +93,11 @@ class SP_Meta_Box_Table_Details {
sp_post_adder( $post_type, __( 'Add New', 'sportspress' ) );
}
?>
<p><strong><?php _e( 'Event Status (with results)', 'sportspress' ); ?></strong></p>
<p>
<input type="checkbox" name="sp_event_status[]" value="publish" <?php echo ( in_array( "publish" , $event_status) ) ? 'checked' : false; ?>> Published/Played<br>
<input type="checkbox" name="sp_event_status[]" value="future" <?php echo ( in_array( "future" , $event_status) ) ? 'checked' : false; ?>> Scheduled/Future<br>
</p>
</div>
<?php
}
@@ -108,5 +117,6 @@ class SP_Meta_Box_Table_Details {
update_post_meta( $post_id, 'sp_current_season', in_array( 'auto', sp_array_value( $tax_input, 'sp_season' ) ) );
update_post_meta( $post_id, 'sp_select', sp_array_value( $_POST, 'sp_select', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
update_post_meta( $post_id, 'sp_event_status', sp_array_value( $_POST, 'sp_event_status', array() ) );
}
}

View File

@@ -913,6 +913,18 @@ class SP_AJAX {
<?php _e( 'Display link to view full table', 'sportspress' ); ?>
</label>
</p>
<p>
<?php _e( 'Event Status:', 'sportspress' ); ?><br/>
<label>
<input type="checkbox" name="show_published_events" id="show_published_events" checked>
<?php _e( 'Include Published/Played Events with results', 'sportspress' ); ?>
</label>
<br/>
<label>
<input type="checkbox" name="show_future_events" id="show_future_events" checked>
<?php _e( 'Include Scheduled/Future Events with results', 'sportspress' ); ?>
</label>
</p>
<?php do_action( 'sportspress_ajax_shortcode_form', 'league-table' ); ?>
<p class="submit">
<input type="button" class="button-primary" value="<?php _e( 'Insert Shortcode', 'sportspress' ); ?>" onclick="insertSportsPress('team_standings');" />
@@ -1349,6 +1361,8 @@ class SP_AJAX {
args.number = $div.find('[name=number]').val();
args.columns = $div.find('[name="columns[]"]:checked').map(function() { return this.value; }).get().join(',');
args.show_team_logo = $div.find('[name=show_team_logo]:checked').length;
args.show_published_events = $div.find('[name=show_published_events]:checked').length;
args.show_future_events = $div.find('[name=show_future_events]:checked').length;
args.show_full_table_link = $div.find('[name=show_full_table_link]:checked').length;
} else if ( 'team_gallery' == type ) {
args.title = $div.find('[name=title]').val();

View File

@@ -23,6 +23,12 @@ class SP_League_Table extends SP_Secondary_Post {
/** @var array Teams to check for tiebreakers. */
public $tiebreakers = array();
/** @var int Show Published events. */
public $show_published_events;
/** @var int Show Scheduled events. */
public $show_future_events;
/**
* Returns formatted data
@@ -222,10 +228,40 @@ class SP_League_Table extends SP_Secondary_Post {
endif;
endforeach;
// Get which event status to include
$event_status = get_post_meta( $this->ID, 'sp_event_status', true );
if ( empty( $event_status ) ) {
$event_status = array( 'publish', 'future' );
}
if ( isset( $this->show_published_events ) ) { // If an attribute was pass through shortcode
if ( $this->show_published_events == '1' ) {
$event_status[] = 'publish';
}else{
if ( ( $status_key = array_search( 'publish', $event_status ) ) !== false ) {
unset( $event_status[ $status_key ] );
}
}
}
if ( isset( $this->show_future_events ) ) { // If an attribute was pass through shortcode
if ( $this->show_future_events == '1' ) {
$event_status[] = 'future';
}else{
if ( ( $status_key = array_search('future', $event_status) ) !== false ) {
unset( $event_status[ $status_key ] );
}
}
}
// Make sure to have unique values in the array
$event_status = array_unique( $event_status );
$args = array(
'post_type' => 'sp_event',
'post_status' => array( 'publish', 'future' ),
'post_status' => $event_status,
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'post_date',

View File

@@ -48,6 +48,13 @@ if ( $show_title && false === $title && $id ):
$title = get_the_title( $id );
endif;
//Check if we have event status sent from shortcode
if ( isset( $show_published_events ) )
$table->show_published_events = $show_published_events ;
if ( isset( $show_future_events ) )
$table->show_future_events = $show_future_events ;
//Create a unique identifier based on the current time in microseconds
$identifier = uniqid( 'table_' );