Add Layout Selection and modify the Event Filtering

This commit is contained in:
savvasha
2018-09-07 11:48:42 +03:00
parent cfc62c93c4
commit 013383fb2d
4 changed files with 78 additions and 8 deletions

View File

@@ -39,6 +39,12 @@ class SP_Calendar extends SP_Secondary_Post {
/** @var int The team ID. */
public $team;
/** @var array The teams IDs. */
public $teams_past;
/** @var string The event date. */
public $date_before;
/** @var int The player ID. */
public $player;
@@ -203,6 +209,23 @@ class SP_Calendar extends SP_Secondary_Post {
);
endif;
if ( $this->teams_past ):
foreach ( $this->teams_past as $team_past ):
$args['meta_query'][] = array(
'key' => 'sp_team',
'value' => $team_past,
'compare' => 'IN',
);
endforeach;
$args['date_query'] = array(
array(
'before' => $this->date_before,
'inclusive' => false,
)
);
endif;
if ( $this->player ):
$args['meta_query'][] = array(
'key' => 'sp_player',

View File

@@ -33,6 +33,7 @@ class SportsPress_Event_Past_Meetings {
// 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' ) );
}
/**
@@ -73,21 +74,23 @@ class SportsPress_Event_Past_Meetings {
*/
public function output() {
// Get timelines format option
$format = get_option( 'sportspress_team_events_format', 'blocks' );
if ( 'calendar' === $format ):
sp_get_template( 'event-calendar.php', array( 'team' => $id ) );
elseif ( 'list' === $format ):
$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(
'team' => $id,
'league' => apply_filters( 'sp_team_events_league', 0 ),
'season' => apply_filters( 'sp_team_events_season', 0 ),
'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-fixtures-results.php', array( 'team' => $id ) );
sp_get_template( 'event-blocks.php', array(
'teams_past' => $teams,
'date_before' => get_post_time('Y-m-d', true),
'order' => 'DESC',
) );
endif;
}
@@ -99,6 +102,38 @@ class SportsPress_Event_Past_Meetings {
__( '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;
}
}

View File

@@ -26,6 +26,8 @@ $defaults = array(
'season' => null,
'venue' => null,
'team' => null,
'teams_past' => null,
'date_before' => null,
'player' => null,
'number' => -1,
'show_team_logo' => get_option( 'sportspress_event_blocks_show_logos', 'yes' ) == 'yes' ? true : false,
@@ -73,6 +75,10 @@ if ( $venue )
$calendar->venue = $venue;
if ( $team )
$calendar->team = $team;
if ( $teams_past )
$calendar->teams_past = $teams_past;
if ( $date_before )
$calendar->date_before = $date_before;
if ( $player )
$calendar->player = $player;
if ( $order != 'default' )

View File

@@ -25,6 +25,8 @@ $defaults = array(
'season' => null,
'venue' => null,
'team' => null,
'teams_past' => null,
'date_before' => null,
'player' => null,
'number' => -1,
'show_team_logo' => get_option( 'sportspress_event_list_show_logos', 'no' ) == 'yes' ? true : false,
@@ -71,6 +73,10 @@ if ( $venue )
$calendar->venue = $venue;
if ( $team )
$calendar->team = $team;
if ( $teams_past )
$calendar->teams_past = $teams_past;
if ( $date_before )
$calendar->date_before = $date_before;
if ( $player )
$calendar->player = $player;
if ( $order != 'default' )