Merge pull request #305 from ThemeBoy/feature-past-meetings
Feature past meetings
This commit is contained in:
@@ -40,6 +40,12 @@ class SP_Calendar extends SP_Secondary_Post {
|
|||||||
/** @var int The team ID. */
|
/** @var int The team ID. */
|
||||||
public $team;
|
public $team;
|
||||||
|
|
||||||
|
/** @var array The teams IDs. */
|
||||||
|
public $teams_past;
|
||||||
|
|
||||||
|
/** @var string The event date. */
|
||||||
|
public $date_before;
|
||||||
|
|
||||||
/** @var int The player ID. */
|
/** @var int The player ID. */
|
||||||
public $player;
|
public $player;
|
||||||
|
|
||||||
@@ -282,6 +288,24 @@ class SP_Calendar extends SP_Secondary_Post {
|
|||||||
);
|
);
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
// If we are showing past meetings filter by team's id and current event date
|
||||||
|
if ( $this->teams_past ):
|
||||||
|
foreach ( $this->teams_past as $team_past ):
|
||||||
|
$args['meta_query'][] = array(
|
||||||
|
'key' => 'sp_team',
|
||||||
|
'value' => $team_past,
|
||||||
|
'compare' => '=',
|
||||||
|
);
|
||||||
|
endforeach;
|
||||||
|
$args['date_query'] = array(
|
||||||
|
array(
|
||||||
|
'before' => $this->date_before,
|
||||||
|
'inclusive' => false,
|
||||||
|
)
|
||||||
|
|
||||||
|
);
|
||||||
|
endif;
|
||||||
|
|
||||||
if ( $this->player ):
|
if ( $this->player ):
|
||||||
$args['meta_query'][] = array(
|
$args['meta_query'][] = array(
|
||||||
'key' => 'sp_player',
|
'key' => 'sp_player',
|
||||||
@@ -402,6 +426,17 @@ class SP_Calendar extends SP_Secondary_Post {
|
|||||||
$events = null;
|
$events = null;
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
// Filter out unessecary events if we are showing past meetings
|
||||||
|
if ( $this->teams_past ){
|
||||||
|
$events_past = array();
|
||||||
|
foreach ( $events as $single_event ) {
|
||||||
|
if ( get_post_meta( $single_event->ID,'sp_team' ) === $this->teams_past ){
|
||||||
|
$events_past[] = $single_event;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$events = $events_past;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove any calendar selection filters
|
// Remove any calendar selection filters
|
||||||
remove_filter( 'posts_where', array( $this, 'range' ) );
|
remove_filter( 'posts_where', array( $this, 'range' ) );
|
||||||
remove_filter( 'posts_where', array( $this, 'relative' ) );
|
remove_filter( 'posts_where', array( $this, 'relative' ) );
|
||||||
|
|||||||
142
modules/sportspress-event-past-meetings.php
Normal file
142
modules/sportspress-event-past-meetings.php
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Plugin Name: SportsPress Event Past Meetings
|
||||||
|
Plugin URI: http://themeboy.com/
|
||||||
|
Description: Show past meetings between two teams of a SportsPress Event.
|
||||||
|
Author: ThemeBoy
|
||||||
|
Author URI: http://themeboy.com/
|
||||||
|
Version: 2.7.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Exit if accessed directly
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||||
|
|
||||||
|
if ( ! class_exists( 'SportsPress_Event_Past_Meetings' ) ) :
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main SportsPress Event Past Meetings Class
|
||||||
|
*
|
||||||
|
* @class SportsPress_Event_Past_Meetings
|
||||||
|
* @version 2.7.0
|
||||||
|
*/
|
||||||
|
class SportsPress_Event_Past_Meetings {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
// Define constants
|
||||||
|
$this->define_constants();
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
|
// Filters
|
||||||
|
add_filter( 'sportspress_event_templates', array( $this, 'templates' ) );
|
||||||
|
add_filter( 'sportspress_text', array( $this, 'add_text_options' ) );
|
||||||
|
add_filter( 'sportspress_event_settings', array( $this, 'add_settings' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define constants.
|
||||||
|
*/
|
||||||
|
private function define_constants() {
|
||||||
|
if ( !defined( 'SP_EVENT_PAST_MEETINGS_VERSION' ) )
|
||||||
|
define( 'SP_EVENT_PAST_MEETINGS_VERSION', '2.7.0' );
|
||||||
|
|
||||||
|
if ( !defined( 'SP_EVENT_PAST_MEETINGS_URL' ) )
|
||||||
|
define( 'SP_EVENT_PAST_MEETINGS_URL', plugin_dir_url( __FILE__ ) );
|
||||||
|
|
||||||
|
if ( !defined( 'SP_EVENT_PAST_MEETINGS_DIR' ) )
|
||||||
|
define( 'SP_EVENT_PAST_MEETINGS_DIR', plugin_dir_path( __FILE__ ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add templates to event layout.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function templates( $templates = array() ) {
|
||||||
|
$templates['past_meetings'] = array(
|
||||||
|
'title' => __( 'Past Meetings', 'sportspress' ),
|
||||||
|
'option' => 'sportspress_event_show_past_meetings',
|
||||||
|
'action' => array( $this, 'output' ),
|
||||||
|
'default' => 'yes',
|
||||||
|
);
|
||||||
|
|
||||||
|
return $templates;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Output Past Meetings.
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function output() {
|
||||||
|
// Get timelines format option
|
||||||
|
$format = get_option( 'sportspress_past_meetings_format', 'blocks' );
|
||||||
|
$teams = get_post_meta( get_the_ID(),'sp_team' );
|
||||||
|
if ( 'list' === $format ):
|
||||||
|
sp_get_template( 'event-list.php', array(
|
||||||
|
'teams_past' => $teams,
|
||||||
|
'date_before' => get_post_time('Y-m-d', true),
|
||||||
|
'title_format' => 'homeaway',
|
||||||
|
'time_format' => 'separate',
|
||||||
|
'columns' => array( 'event', 'time', 'results' ),
|
||||||
|
'order' => 'DESC',
|
||||||
|
) );
|
||||||
|
else:
|
||||||
|
sp_get_template( 'event-blocks.php', array(
|
||||||
|
'teams_past' => $teams,
|
||||||
|
'date_before' => get_post_time('Y-m-d', true),
|
||||||
|
'order' => 'DESC',
|
||||||
|
) );
|
||||||
|
endif;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add text options
|
||||||
|
*/
|
||||||
|
public function add_text_options( $options = array() ) {
|
||||||
|
return array_merge( $options, array(
|
||||||
|
__( 'Past Meetings', 'sportspress' ),
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add settings.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function add_settings( $settings ) {
|
||||||
|
|
||||||
|
$settings = array_merge( $settings,
|
||||||
|
array(
|
||||||
|
array( 'title' => __( 'Past Meetings', 'sportspress' ), 'type' => 'title', 'id' => 'past_meetings_options' ),
|
||||||
|
),
|
||||||
|
|
||||||
|
apply_filters( 'sportspress_past_meetings_options', array(
|
||||||
|
array(
|
||||||
|
'title' => __( 'Layout', 'sportspress' ),
|
||||||
|
'id' => 'sportspress_past_meetings_format',
|
||||||
|
'default' => 'horizontal',
|
||||||
|
'type' => 'radio',
|
||||||
|
'options' => array(
|
||||||
|
'blocks'=> __( 'Blocks', 'sportspress' ),
|
||||||
|
'list' => __( 'List', 'sportspress' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
) ),
|
||||||
|
|
||||||
|
array(
|
||||||
|
array( 'type' => 'sectionend', 'id' => 'past_meetings_options' ),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
endif;
|
||||||
|
|
||||||
|
new SportsPress_Event_Past_Meetings();
|
||||||
@@ -26,6 +26,8 @@ $defaults = array(
|
|||||||
'season' => null,
|
'season' => null,
|
||||||
'venue' => null,
|
'venue' => null,
|
||||||
'team' => null,
|
'team' => null,
|
||||||
|
'teams_past' => null,
|
||||||
|
'date_before' => null,
|
||||||
'player' => null,
|
'player' => null,
|
||||||
'number' => -1,
|
'number' => -1,
|
||||||
'show_team_logo' => get_option( 'sportspress_event_blocks_show_logos', 'yes' ) == 'yes' ? true : false,
|
'show_team_logo' => get_option( 'sportspress_event_blocks_show_logos', 'yes' ) == 'yes' ? true : false,
|
||||||
@@ -73,6 +75,10 @@ if ( $venue )
|
|||||||
$calendar->venue = $venue;
|
$calendar->venue = $venue;
|
||||||
if ( $team )
|
if ( $team )
|
||||||
$calendar->team = $team;
|
$calendar->team = $team;
|
||||||
|
if ( $teams_past )
|
||||||
|
$calendar->teams_past = $teams_past;
|
||||||
|
if ( $date_before )
|
||||||
|
$calendar->date_before = $date_before;
|
||||||
if ( $player )
|
if ( $player )
|
||||||
$calendar->player = $player;
|
$calendar->player = $player;
|
||||||
if ( $order != 'default' )
|
if ( $order != 'default' )
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ $defaults = array(
|
|||||||
'season' => null,
|
'season' => null,
|
||||||
'venue' => null,
|
'venue' => null,
|
||||||
'team' => null,
|
'team' => null,
|
||||||
|
'teams_past' => null,
|
||||||
|
'date_before' => null,
|
||||||
'player' => null,
|
'player' => null,
|
||||||
'number' => -1,
|
'number' => -1,
|
||||||
'show_team_logo' => get_option( 'sportspress_event_list_show_logos', 'no' ) == 'yes' ? true : false,
|
'show_team_logo' => get_option( 'sportspress_event_list_show_logos', 'no' ) == 'yes' ? true : false,
|
||||||
@@ -71,6 +73,10 @@ if ( $venue )
|
|||||||
$calendar->venue = $venue;
|
$calendar->venue = $venue;
|
||||||
if ( $team )
|
if ( $team )
|
||||||
$calendar->team = $team;
|
$calendar->team = $team;
|
||||||
|
if ( $teams_past )
|
||||||
|
$calendar->teams_past = $teams_past;
|
||||||
|
if ( $date_before )
|
||||||
|
$calendar->date_before = $date_before;
|
||||||
if ( $player )
|
if ( $player )
|
||||||
$calendar->player = $player;
|
$calendar->player = $player;
|
||||||
if ( $order != 'default' )
|
if ( $order != 'default' )
|
||||||
|
|||||||
Reference in New Issue
Block a user