Move range methods to abstract secondary class
This commit is contained in:
36
includes/abstracts/abstract-sp-secondary-post.php
Normal file
36
includes/abstracts/abstract-sp-secondary-post.php
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Abstract Secondary Post Class
|
||||||
|
*
|
||||||
|
* The SportsPress secondary post class extends custom posts with handling of secondary post types.
|
||||||
|
*
|
||||||
|
* @class SP_Secondary_Post
|
||||||
|
* @version 2.5
|
||||||
|
* @package SportsPress/Abstracts
|
||||||
|
* @category Abstract Class
|
||||||
|
* @author ThemeBoy
|
||||||
|
*/
|
||||||
|
abstract class SP_Secondary_Post extends SP_Custom_Post {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* @author ThemeBoy
|
* @author ThemeBoy
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class SP_Calendar extends SP_Custom_Post {
|
class SP_Calendar extends SP_Secondary_Post {
|
||||||
|
|
||||||
/** @var string The events status. */
|
/** @var string The events status. */
|
||||||
public $status;
|
public $status;
|
||||||
@@ -71,7 +71,7 @@ class SP_Calendar extends SP_Custom_Post {
|
|||||||
* @param mixed $post
|
* @param mixed $post
|
||||||
*/
|
*/
|
||||||
public function __construct( $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->ID = absint( $post->ID );
|
||||||
$this->post = $post;
|
$this->post = $post;
|
||||||
else:
|
else:
|
||||||
@@ -299,27 +299,4 @@ class SP_Calendar extends SP_Custom_Post {
|
|||||||
|
|
||||||
return $events;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -222,7 +222,8 @@ final class SportsPress {
|
|||||||
include_once( 'includes/class-sp-post-types.php' ); // Registers post types
|
include_once( 'includes/class-sp-post-types.php' ); // Registers post types
|
||||||
|
|
||||||
// Include abstract classes
|
// 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)
|
// Classes (used on all pages)
|
||||||
include_once( 'includes/class-sp-modules.php' ); // Defines available modules
|
include_once( 'includes/class-sp-modules.php' ); // Defines available modules
|
||||||
|
|||||||
Reference in New Issue
Block a user