Add date selector to calendars
This commit is contained in:
@@ -80,82 +80,92 @@ class SP_Meta_Box_Calendar_Data {
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
if ( is_array( $data ) && sizeof( $data ) > 0 ):
|
||||
$main_result = get_option( 'sportspress_primary_result', null );
|
||||
$i = 0;
|
||||
foreach ( $data as $event ):
|
||||
$teams = get_post_meta( $event->ID, 'sp_team' );
|
||||
$results = get_post_meta( $event->ID, 'sp_results', true );
|
||||
$video = get_post_meta( $event->ID, 'sp_video', true );
|
||||
$main_results = array();
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td><?php echo get_post_time( get_option( 'date_format' ), false, $event ); ?></td>
|
||||
<td><?php echo $event->post_title; ?></td>
|
||||
<td>
|
||||
<?php
|
||||
if ( $teams ): foreach ( $teams as $team ):
|
||||
$name = get_the_title( $team );
|
||||
if ( $name ):
|
||||
$team_results = sp_array_value( $results, $team, null );
|
||||
|
||||
if ( $main_result ):
|
||||
$team_result = sp_array_value( $team_results, $main_result, null );
|
||||
else:
|
||||
if ( is_array( $team_results ) ):
|
||||
end( $team_results );
|
||||
$team_result = prev( $team_results );
|
||||
else:
|
||||
$team_result = null;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $team_result != null ):
|
||||
$main_results[] = $team_result;
|
||||
unset( $team_results['outcome'] );
|
||||
$team_results = implode( ' | ', $team_results );
|
||||
echo '<a class="result tips" title="' . $team_results . '" href="' . get_edit_post_link( $event->ID ) . '">' . $team_result . '</a> ';
|
||||
endif;
|
||||
|
||||
echo $name . '<br>';
|
||||
endif;
|
||||
endforeach; else:
|
||||
echo '—';
|
||||
endif;
|
||||
?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
if ( ! empty( $main_results ) ):
|
||||
echo implode( ' - ', $main_results );
|
||||
else:
|
||||
echo get_post_time( get_option( 'time_format' ), false, $event );
|
||||
endif;
|
||||
?>
|
||||
</td>
|
||||
<td><?php the_terms( $event->ID, 'sp_venue' ); ?></td>
|
||||
<td>
|
||||
<a href="<?php echo get_edit_post_link( $event->ID ); ?>#sp_articlediv">
|
||||
<?php if ( $video ): ?>
|
||||
<div class="dashicons dashicons-video-alt"></div>
|
||||
<?php elseif ( has_post_thumbnail( $event->ID ) ): ?>
|
||||
<div class="dashicons dashicons-camera"></div>
|
||||
<?php endif; ?>
|
||||
if ( is_array( $data ) ):
|
||||
if ( sizeof( $data ) > 0 ):
|
||||
$main_result = get_option( 'sportspress_primary_result', null );
|
||||
$i = 0;
|
||||
foreach ( $data as $event ):
|
||||
$teams = get_post_meta( $event->ID, 'sp_team' );
|
||||
$results = get_post_meta( $event->ID, 'sp_results', true );
|
||||
$video = get_post_meta( $event->ID, 'sp_video', true );
|
||||
$main_results = array();
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td><?php echo get_post_time( get_option( 'date_format' ), false, $event ); ?></td>
|
||||
<td><?php echo $event->post_title; ?></td>
|
||||
<td>
|
||||
<?php
|
||||
if ( $event->post_content == null ):
|
||||
_e( 'None', 'sportspress' );
|
||||
elseif ( $event->post_status == 'publish' ):
|
||||
_e( 'Recap', 'sportspress' );
|
||||
else:
|
||||
_e( 'Preview', 'sportspress' );
|
||||
if ( $teams ): foreach ( $teams as $team ):
|
||||
$name = get_the_title( $team );
|
||||
if ( $name ):
|
||||
$team_results = sp_array_value( $results, $team, null );
|
||||
|
||||
if ( $main_result ):
|
||||
$team_result = sp_array_value( $team_results, $main_result, null );
|
||||
else:
|
||||
if ( is_array( $team_results ) ):
|
||||
end( $team_results );
|
||||
$team_result = prev( $team_results );
|
||||
else:
|
||||
$team_result = null;
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $team_result != null ):
|
||||
$main_results[] = $team_result;
|
||||
unset( $team_results['outcome'] );
|
||||
$team_results = implode( ' | ', $team_results );
|
||||
echo '<a class="result tips" title="' . $team_results . '" href="' . get_edit_post_link( $event->ID ) . '">' . $team_result . '</a> ';
|
||||
endif;
|
||||
|
||||
echo $name . '<br>';
|
||||
endif;
|
||||
endforeach; else:
|
||||
echo '—';
|
||||
endif;
|
||||
?>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
if ( ! empty( $main_results ) ):
|
||||
echo implode( ' - ', $main_results );
|
||||
else:
|
||||
echo get_post_time( get_option( 'time_format' ), false, $event );
|
||||
endif;
|
||||
?>
|
||||
</td>
|
||||
<td><?php the_terms( $event->ID, 'sp_venue' ); ?></td>
|
||||
<td>
|
||||
<a href="<?php echo get_edit_post_link( $event->ID ); ?>#sp_articlediv">
|
||||
<?php if ( $video ): ?>
|
||||
<div class="dashicons dashicons-video-alt"></div>
|
||||
<?php elseif ( has_post_thumbnail( $event->ID ) ): ?>
|
||||
<div class="dashicons dashicons-camera"></div>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
if ( $event->post_content == null ):
|
||||
_e( 'None', 'sportspress' );
|
||||
elseif ( $event->post_status == 'publish' ):
|
||||
_e( 'Recap', 'sportspress' );
|
||||
else:
|
||||
_e( 'Preview', 'sportspress' );
|
||||
endif;
|
||||
?>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$i++;
|
||||
endforeach;
|
||||
else:
|
||||
?>
|
||||
<tr class="sp-row alternate">
|
||||
<td colspan="6">
|
||||
<?php _e( 'No results found.', 'sportspress' ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
$i++;
|
||||
endforeach;
|
||||
endif;
|
||||
else:
|
||||
?>
|
||||
<tr class="sp-row alternate">
|
||||
|
||||
@@ -20,6 +20,7 @@ class SP_Meta_Box_Calendar_Details {
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
$status = get_post_meta( $post->ID, 'sp_status', true );
|
||||
$date = get_post_meta( $post->ID, 'sp_date', true );
|
||||
$league_id = sp_get_the_term_id( $post->ID, 'sp_league', 0 );
|
||||
$season_id = sp_get_the_term_id( $post->ID, 'sp_season', 0 );
|
||||
$venue_id = sp_get_the_term_id( $post->ID, 'sp_venue', 0 );
|
||||
@@ -38,6 +39,17 @@ class SP_Meta_Box_Calendar_Details {
|
||||
sp_dropdown_statuses( $args );
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Date', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
$args = array(
|
||||
'name' => 'sp_date',
|
||||
'id' => 'sp_date',
|
||||
'selected' => $date,
|
||||
);
|
||||
sp_dropdown_dates( $args );
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'League', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<?php
|
||||
@@ -117,6 +129,7 @@ class SP_Meta_Box_Calendar_Details {
|
||||
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_season', 0 ), 'sp_season' );
|
||||
wp_set_post_terms( $post_id, sp_array_value( $_POST, 'sp_venue', 0 ), 'sp_venue' );
|
||||
update_post_meta( $post_id, 'sp_status', sp_array_value( $_POST, 'sp_status', 0 ) );
|
||||
update_post_meta( $post_id, 'sp_date', sp_array_value( $_POST, 'sp_date', 0 ) );
|
||||
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', 0 ) );
|
||||
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) );
|
||||
}
|
||||
|
||||
@@ -12,10 +12,13 @@
|
||||
*/
|
||||
class SP_Calendar extends SP_Custom_Post {
|
||||
|
||||
/** @var array The events status. */
|
||||
/** @var string The events status. */
|
||||
public $status;
|
||||
|
||||
/** @var array The events order. */
|
||||
/** @var string The date filter for events. */
|
||||
public $date;
|
||||
|
||||
/** @var string The events order. */
|
||||
public $order;
|
||||
|
||||
/**
|
||||
@@ -34,11 +37,15 @@ class SP_Calendar extends SP_Custom_Post {
|
||||
endif;
|
||||
|
||||
$this->status = $this->__get( 'status' );
|
||||
$this->date = $this->__get( 'date' );
|
||||
$this->order = $this->__get( 'order' );
|
||||
|
||||
if ( ! $this->status )
|
||||
$this->status = 'any';
|
||||
|
||||
if ( ! $this->date )
|
||||
$this->date = 0;
|
||||
|
||||
if ( ! $this->order )
|
||||
$this->order = 'ASC';
|
||||
}
|
||||
@@ -64,6 +71,16 @@ class SP_Calendar extends SP_Custom_Post {
|
||||
),
|
||||
);
|
||||
|
||||
if ( $this->date !== 0 ):
|
||||
$args['year'] = date('Y');
|
||||
if ( $this->date == 'w' ):
|
||||
$args['w'] = date('W');
|
||||
elseif ( $this->date == 'day' ):
|
||||
$args['day'] = date('j');
|
||||
$args['monthnum'] = date('n');
|
||||
endif;
|
||||
endif;
|
||||
|
||||
if ( $pagenow != 'post-new.php' ):
|
||||
if ( $this->ID ):
|
||||
$leagues = get_the_terms( $this->ID, 'sp_league' );
|
||||
@@ -121,7 +138,7 @@ class SP_Calendar extends SP_Custom_Post {
|
||||
$events = get_posts( $args );
|
||||
|
||||
else:
|
||||
$events = array();
|
||||
$events = null;
|
||||
endif;
|
||||
|
||||
return $events;
|
||||
|
||||
@@ -389,6 +389,37 @@ if ( !function_exists( 'sp_dropdown_statuses' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_dropdown_dates' ) ) {
|
||||
function sp_dropdown_dates( $args = array() ) {
|
||||
$defaults = array(
|
||||
'show_option_default' => false,
|
||||
'name' => 'sp_date',
|
||||
'id' => null,
|
||||
'selected' => null,
|
||||
'class' => null,
|
||||
);
|
||||
$args = array_merge( $defaults, $args );
|
||||
|
||||
printf( '<select name="%s" class="postform %s">', $args['name'], $args['class'] );
|
||||
|
||||
if ( $args['show_option_default'] ):
|
||||
printf( '<option value="default">%s</option>', $args['show_option_default'] );
|
||||
endif;
|
||||
|
||||
$dates = apply_filters( 'sportspress_dates', array(
|
||||
0 => __( 'All', 'sportspress' ),
|
||||
'w' => __( 'This week', 'sportspress' ),
|
||||
'day' => __( 'Today', 'sportspress' )
|
||||
));
|
||||
|
||||
foreach ( $dates as $value => $label ):
|
||||
printf( '<option value="%s" %s>%s</option>', $value, selected( $value, $args['selected'], false ), $label );
|
||||
endforeach;
|
||||
print( '</select>' );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
|
||||
function sp_dropdown_taxonomies( $args = array() ) {
|
||||
$defaults = array(
|
||||
|
||||
@@ -34,7 +34,10 @@ if ( isset( $id ) ):
|
||||
foreach ( $events as $event ):
|
||||
$event_ids[] = $event->ID;
|
||||
endforeach;
|
||||
$in = 'AND ID IN (' . implode( ', ', $event_ids ) . ')';
|
||||
if ( empty( $event_ids ) )
|
||||
$in = 'AND 1 = 0'; // False logic to prevent SQL error
|
||||
else
|
||||
$in = 'AND ID IN (' . implode( ', ', $event_ids ) . ')';
|
||||
else:
|
||||
$in = '';
|
||||
endif;
|
||||
|
||||
Reference in New Issue
Block a user