Add yesterday, tomorrow, last week, and next week options to calendar date selector

This commit is contained in:
Brian Miyaji
2017-11-09 00:10:19 +11:00
parent 3817fcbf33
commit 563135264d
3 changed files with 52 additions and 15 deletions

View File

@@ -71,6 +71,7 @@ class SP_Meta_Box_Calendar_Details {
<p class="sp-date-range-relative"> <p class="sp-date-range-relative">
<?php _e( 'Past', 'sportspress' ); ?> <?php _e( 'Past', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="sp_date_past" value="<?php echo '' !== $date_past ? $date_past : 7; ?>"> <input type="number" min="0" step="1" class="tiny-text" name="sp_date_past" value="<?php echo '' !== $date_past ? $date_past : 7; ?>">
<?php _e( 'days', 'sportspress' ); ?>
&rarr; &rarr;
<?php _e( 'Next', 'sportspress' ); ?> <?php _e( 'Next', 'sportspress' ); ?>
<input type="number" min="0" step="1" class="tiny-text" name="sp_date_future" value="<?php echo '' !== $date_future ? $date_future : 7; ?>"> <input type="number" min="0" step="1" class="tiny-text" name="sp_date_future" value="<?php echo '' !== $date_future ? $date_future : 7; ?>">

View File

@@ -134,21 +134,53 @@ class SP_Calendar extends SP_Secondary_Post {
); );
if ( $this->date !== 0 ): if ( $this->date !== 0 ):
if ( $this->date == 'w' ): switch ( $this->date ):
$args['year'] = date_i18n('Y'); case '-day':
$args['w'] = date_i18n('W'); $date = new DateTime( date_i18n('Y-m-d') );
elseif ( $this->date == 'day' ): $date->modify( '-1 day' );
$args['year'] = $date->format('Y');
$args['day'] = $date->format('j');
$args['monthnum'] = $date->format('n');
break;
case 'day':
$args['year'] = date_i18n('Y'); $args['year'] = date_i18n('Y');
$args['day'] = date_i18n('j'); $args['day'] = date_i18n('j');
$args['monthnum'] = date_i18n('n'); $args['monthnum'] = date_i18n('n');
elseif ( $this->date == 'range' ): break;
case '+day':
$date = new DateTime( date_i18n('Y-m-d') );
$date->modify( '+1 day' );
$args['year'] = $date->format('Y');
$args['day'] = $date->format('j');
$args['monthnum'] = $date->format('n');
break;
case '-w':
$date = new DateTime( date_i18n('Y-m-d') );
$date->modify( '-1 week' );
$args['year'] = $date->format('Y');
$args['w'] = $date->format('W');
break;
case 'w':
$args['year'] = date_i18n('Y');
$args['w'] = date_i18n('W');
break;
case '+w':
$date = new DateTime( date_i18n('Y-m-d') );
$date->modify( '+1 week' );
$args['year'] = $date->format('Y');
$args['w'] = $date->format('W');
break;
case 'range':
if ( $this->relative ): if ( $this->relative ):
add_filter( 'posts_where', array( $this, 'relative' ) ); add_filter( 'posts_where', array( $this, 'relative' ) );
else: else:
add_filter( 'posts_where', array( $this, 'range' ) ); add_filter( 'posts_where', array( $this, 'range' ) );
endif; endif;
break;
endswitch;
endif; endif;
endif;
pr( $args );
if ( $this->league ): if ( $this->league ):
$league_ids = array( $this->league ); $league_ids = array( $this->league );

View File

@@ -615,8 +615,12 @@ if ( !function_exists( 'sp_dropdown_dates' ) ) {
$dates = apply_filters( 'sportspress_dates', array( $dates = apply_filters( 'sportspress_dates', array(
0 => __( 'All', 'sportspress' ), 0 => __( 'All', 'sportspress' ),
'w' => __( 'This week', 'sportspress' ), '-day' => __( 'Yesterday', 'sportspress' ),
'day' => __( 'Today', 'sportspress' ), 'day' => __( 'Today', 'sportspress' ),
'+day' => __( 'Tomorrow', 'sportspress' ),
'-w' => __( 'Last week', 'sportspress' ),
'w' => __( 'This week', 'sportspress' ),
'+w' => __( 'Next week', 'sportspress' ),
'range' => __( 'Date range:', 'sportspress' ), 'range' => __( 'Date range:', 'sportspress' ),
)); ));