From c8601d2f8d6c181763d388c8aab372abdb28ff8d Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 8 Nov 2017 18:36:13 +1100 Subject: [PATCH] Move range methods to abstract secondary class --- .../abstracts/abstract-sp-secondary-post.php | 36 +++++++++++++++++++ includes/class-sp-calendar.php | 27 ++------------ sportspress.php | 3 +- 3 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 includes/abstracts/abstract-sp-secondary-post.php diff --git a/includes/abstracts/abstract-sp-secondary-post.php b/includes/abstracts/abstract-sp-secondary-post.php new file mode 100644 index 00000000..71e2d178 --- /dev/null +++ b/includes/abstracts/abstract-sp-secondary-post.php @@ -0,0 +1,36 @@ +from, new DateTimeZone( get_option( 'timezone_string' ) ) ); + $to = new DateTime( $this->to, new DateTimeZone( get_option( 'timezone_string' ) ) ); + $to->modify( '+1 day' ); + $where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'"; + return $where; + } + + public function relative( $where = '', $format = 'Y-m-d' ) { + $datetimezone = new DateTimeZone( get_option( 'timezone_string' ) ); + $from = new DateTime( 'now', $datetimezone ); + $to = new DateTime( 'now', $datetimezone ); + + $from->modify( '-' . abs( (int) $this->past ) . ' day' ); + $to->modify( '+' . abs( (int) $this->future ) . ' day' ); + + $to->modify( '+1 day' ); + + $where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'"; + + return $where; + } +} diff --git a/includes/class-sp-calendar.php b/includes/class-sp-calendar.php index cdc99432..c03c7fae 100644 --- a/includes/class-sp-calendar.php +++ b/includes/class-sp-calendar.php @@ -14,7 +14,7 @@ * @author ThemeBoy */ -class SP_Calendar extends SP_Custom_Post { +class SP_Calendar extends SP_Secondary_Post { /** @var string The events status. */ public $status; @@ -71,7 +71,7 @@ class SP_Calendar extends SP_Custom_Post { * @param mixed $post */ public function __construct( $post ) { - if ( $post instanceof WP_Post || $post instanceof SP_Custom_Post ): + if ( $post instanceof WP_Post || $post instanceof SP_Secondary_Post ): $this->ID = absint( $post->ID ); $this->post = $post; else: @@ -299,27 +299,4 @@ class SP_Calendar extends SP_Custom_Post { return $events; } - - public function range( $where = '', $format = 'Y-m-d' ) { - $from = new DateTime( $this->from, new DateTimeZone( get_option( 'timezone_string' ) ) ); - $to = new DateTime( $this->to, new DateTimeZone( get_option( 'timezone_string' ) ) ); - $to->modify( '+1 day' ); - $where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'"; - return $where; - } - - public function relative( $where = '', $format = 'Y-m-d' ) { - $datetimezone = new DateTimeZone( get_option( 'timezone_string' ) ); - $from = new DateTime( 'now', $datetimezone ); - $to = new DateTime( 'now', $datetimezone ); - - $from->modify( '-' . abs( (int) $this->past ) . ' day' ); - $to->modify( '+' . abs( (int) $this->future ) . ' day' ); - - $to->modify( '+1 day' ); - - $where .= " AND post_date BETWEEN '" . $from->format( $format ) . "' AND '" . $to->format( $format ) . "'"; - - return $where; - } } diff --git a/sportspress.php b/sportspress.php index f1ad8251..a24c783a 100644 --- a/sportspress.php +++ b/sportspress.php @@ -222,7 +222,8 @@ final class SportsPress { include_once( 'includes/class-sp-post-types.php' ); // Registers post types // Include abstract classes - include_once( 'includes/abstracts/abstract-sp-custom-post.php' ); // Custom posts + include_once( 'includes/abstracts/abstract-sp-custom-post.php' ); // Custom posts + include_once( 'includes/abstracts/abstract-sp-secondary-post.php' ); // Secondary posts // Classes (used on all pages) include_once( 'includes/class-sp-modules.php' ); // Defines available modules