Add auto events to calendar

This commit is contained in:
Brian Miyaji
2016-04-23 20:39:59 +10:00
parent 0b6bddf356
commit 2c61d35ed9

View File

@@ -37,6 +37,9 @@ class SP_Calendar extends SP_Custom_Post {
/** @var int The team ID. */ /** @var int The team ID. */
public $team; public $team;
/** @var int Number of events. */
public $number;
/** /**
* __construct function. * __construct function.
* *
@@ -55,6 +58,7 @@ class SP_Calendar extends SP_Custom_Post {
$this->status = $this->__get( 'status' ); $this->status = $this->__get( 'status' );
$this->date = $this->__get( 'date' ); $this->date = $this->__get( 'date' );
$this->order = $this->__get( 'order' ); $this->order = $this->__get( 'order' );
$this->number = $this->__get( 'number' );
if ( ! $this->status ) if ( ! $this->status )
$this->status = 'any'; $this->status = 'any';
@@ -70,6 +74,9 @@ class SP_Calendar extends SP_Custom_Post {
if ( ! $this->to ) if ( ! $this->to )
$this->to = get_post_meta( $this->ID, 'sp_date_to', true ); $this->to = get_post_meta( $this->ID, 'sp_date_to', true );
if ( ! $this->number )
$this->number = 500;
} }
/** /**
@@ -83,8 +90,7 @@ class SP_Calendar extends SP_Custom_Post {
$args = array( $args = array(
'post_type' => 'sp_event', 'post_type' => 'sp_event',
'numberposts' => -1, 'posts_per_page' => $this->number,
'posts_per_page' => -1,
'orderby' => 'date', 'orderby' => 'date',
'order' => $this->order, 'order' => $this->order,
'post_status' => $this->status, 'post_status' => $this->status,
@@ -186,7 +192,24 @@ class SP_Calendar extends SP_Custom_Post {
endif; endif;
$events = get_posts( $args ); if ( 'auto' === $this->date ) {
if ( 'any' === $this->status ) {
$args['post_status'] = 'publish';
$args['order'] = 'DESC';
$args['posts_per_page'] = ceil( $this->number / 2 );
$results = get_posts( $args );
$results = array_reverse( $results, true );
$args['post_status'] = 'future';
$args['order'] = 'ASC';
$args['posts_per_page'] = floor( $this->number / 2 );
$fixtures = get_posts( $args );
$events = array_merge_recursive( $results, $fixtures );
}
} else {
$events = get_posts( $args );
}
else: else:
$events = null; $events = null;