Display events in custom calendar

This commit is contained in:
Brian Miyaji
2014-01-25 17:51:30 +11:00
parent 84233c4d8b
commit 0ef0831ec2
7 changed files with 82 additions and 61 deletions

View File

@@ -97,17 +97,11 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
case 'sp_sponsor':
echo get_the_terms ( $post_id, 'sp_sponsor' ) ? the_terms( $post_id, 'sp_sponsor' ) : '—';
break;
case 'sp_kickoff':
if ( $post->post_status == 'future' ):
_e( 'Scheduled', 'sportspress' );
elseif( $post->post_status == 'publish' ):
_e( 'Played', 'sportspress' );
elseif( $post->post_status == 'draft' ):
_e( 'Draft', 'sportspress' );
else:
_e( 'Pending Review', 'sportspress' );
endif;
echo '<br />' . date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) );
case 'sp_datetime':
echo sportspress_get_post_datetime( $post );
break;
case 'sp_events':
echo sizeof( sportspress_get_calendar_data( $post_id ) );
break;
case 'sp_address':
echo get_post_meta( $post_id, 'sp_address', true ) ? get_post_meta( $post_id, 'sp_address', true ) : '&mdash;';

View File

@@ -77,11 +77,12 @@ function sportspress_activation_hook() {
);
// Flush rewrite rules
sportspress_event_post_init();
sportspress_result_post_init();
sportspress_outcome_post_init();
sportspress_column_post_init();
sportspress_statistic_post_init();
sportspress_event_post_init();
sportspress_calendar_post_init();
sportspress_team_post_init();
sportspress_table_post_init();
sportspress_player_post_init();
@@ -89,6 +90,7 @@ function sportspress_activation_hook() {
sportspress_staff_post_init();
sportspress_position_term_init();
sportspress_season_term_init();
sportspress_league_term_init();
flush_rewrite_rules();
}
register_activation_hook( SPORTSPRESS_PLUGIN_FILE, 'sportspress_activation_hook' );

View File

@@ -28,6 +28,7 @@ function sportspress_calendar_edit_columns() {
'sp_league' => __( 'Leagues', 'sportspress' ),
'sp_season' => __( 'Seasons', 'sportspress' ),
'sp_venue' => __( 'Venues', 'sportspress' ),
'sp_events' => __( 'Events', 'sportspress' ),
'sp_views' => __( 'Views', 'sportspress' ),
);
return $columns;
@@ -44,7 +45,7 @@ function sportspress_calendar_meta_init( $post ) {
function sportspress_calendar_events_meta( $post ) {
$seasons = get_the_terms( $post->ID, 'sp_season' );
$data = sportspress_get_calendar_data( $post->ID, true );
$data = sportspress_get_calendar_data( $post->ID );
sportspress_edit_calendar_table( $data );

View File

@@ -198,7 +198,7 @@ function sportspress_event_edit_columns() {
'sp_league' => __( 'League', 'sportspress' ),
'sp_season' => __( 'Season', 'sportspress' ),
'sp_venue' => __( 'Venue', 'sportspress' ),
'sp_kickoff' => __( 'Date/Time', 'sportspress' ),
'sp_datetime' => __( 'Date/Time', 'sportspress' ),
'sp_views' => __( 'Views', 'sportspress' ),
);
return $columns;
@@ -206,7 +206,7 @@ function sportspress_event_edit_columns() {
add_filter( 'manage_edit-sp_event_columns', 'sportspress_event_edit_columns' );
function sportspress_event_edit_sortable_columns( $columns ) {
$columns['sp_kickoff'] = 'sp_kickoff';
$columns['sp_datetime'] = 'sp_datetime';
return $columns;
}
add_filter( 'manage_edit-sp_event_sortable_columns', 'sportspress_event_edit_sortable_columns' );

View File

@@ -5,7 +5,8 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
if ( ! $id )
$id = get_the_ID();
global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
global $wpdb, $m, $wp_locale, $posts;
$initial = false;
$echo = 1;
@@ -16,6 +17,10 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
// week_begins = 0 stands for Sunday
$week_begins = intval(get_option('start_of_week'));
// Get year and month from query vars
$year = isset( $_GET['sp_year'] ) ? $_GET['sp_year'] : 0;
$monthnum = isset( $_GET['sp_month'] ) ? $_GET['sp_month'] : 0;
// Let's figure out when we are
if ( !empty($monthnum) && !empty($year) ) {
$thismonth = ''.zeroise(intval($monthnum), 2);
@@ -43,20 +48,20 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
$previous = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
FROM $wpdb->posts
WHERE post_date < '$thisyear-$thismonth-01'
AND post_type = 'sp_event' AND post_status = 'publish'
AND post_type = 'sp_event' AND ( post_status = 'publish' OR post_status = 'future' )
ORDER BY post_date DESC
LIMIT 1");
$next = $wpdb->get_row("SELECT MONTH(post_date) AS month, YEAR(post_date) AS year
FROM $wpdb->posts
WHERE post_date > '$thisyear-$thismonth-{$last_day} 23:59:59'
AND post_type = 'sp_event' AND post_status = 'publish'
AND post_type = 'sp_event' AND ( post_status = 'publish' OR post_status = 'future' )
ORDER BY post_date ASC
LIMIT 1");
/* translators: Calendar caption: 1: month name, 2: 4-digit year */
$calendar_caption = _x('%1$s %2$s', 'calendar caption', 'sportspress');
$calendar_output = '<table id="wp-calendar">
<caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
$calendar_output = '<h4 class="sp-table-caption">' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</h4>
<table id="wp-calendar">
<thead>
<tr>';
@@ -80,7 +85,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
<tr>';
if ( $previous ) {
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . get_month_link($previous->year, $previous->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s', 'sportspress'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev"><a href="' . add_query_arg( array( 'sp_year' => $previous->year, 'sp_month' => $previous->month ), get_permalink() ) . '" title="' . esc_attr( sprintf(__('View events for %1$s %2$s', 'sportspress'), $wp_locale->get_month($previous->month), date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year)))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
} else {
$calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
}
@@ -88,7 +93,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
$calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
if ( $next ) {
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s', 'sportspress'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
$calendar_output .= "\n\t\t".'<td colspan="3" id="next"><a href="' . add_query_arg( array( 'sp_year' => $next->year, 'sp_month' => $next->month ), get_permalink() ) . '" title="' . esc_attr( sprintf(__('View events for %1$s %2$s', 'sportspress'), $wp_locale->get_month($next->month), date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
} else {
$calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
}
@@ -103,7 +108,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
// Get days with posts
$dayswithposts = $wpdb->get_results("SELECT DISTINCT DAYOFMONTH(post_date)
FROM $wpdb->posts WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00'
AND post_type = 'sp_event' AND post_status = 'publish'
AND post_type = 'sp_event' AND ( post_status = 'publish' OR post_status = 'future' )
AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59'", ARRAY_N);
if ( $dayswithposts ) {
foreach ( (array) $dayswithposts as $daywith ) {
@@ -123,7 +128,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
."FROM $wpdb->posts "
."WHERE post_date >= '{$thisyear}-{$thismonth}-01 00:00:00' "
."AND post_date <= '{$thisyear}-{$thismonth}-{$last_day} 23:59:59' "
."AND post_type = 'sp_event' AND post_status = 'publish'"
."AND post_type = 'sp_event' AND ( post_status = 'publish' OR post_status = 'future' )"
);
if ( $ak_post_titles ) {
foreach ( (array) $ak_post_titles as $ak_post_title ) {
@@ -157,7 +162,7 @@ if ( !function_exists( 'sportspress_events_calendar' ) ) {
$calendar_output .= '<td>';
if ( in_array($day, $daywithpost) ) // any posts today?
$calendar_output .= '<a href="' . get_day_link( $thisyear, $thismonth, $day ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
$calendar_output .= '<a href="' . add_query_arg( array( 'yr' => $thisyear, 'mo' => $thismonth, 'day' => $day ), get_post_type_archive_link( 'sp_event' ) ) . '" title="' . esc_attr( $ak_titles_for_day[ $day ] ) . "\">$day</a>";
else
$calendar_output .= $day;
$calendar_output .= '</td>';

View File

@@ -135,6 +135,21 @@ if ( !function_exists( 'sportspress_set_post_views' ) ) {
}
}
if ( !function_exists( 'sportspress_get_post_datetime' ) ) {
function sportspress_get_post_datetime( $post ) {
if ( $post->post_status == 'future' ):
$status = __( 'Scheduled', 'sportspress' );
elseif( $post->post_status == 'publish' ):
$status = __( 'Played', 'sportspress' );
elseif( $post->post_status == 'draft' ):
$status = __( 'Draft', 'sportspress' );
else:
$status = __( 'Pending Review', 'sportspress' );
endif;
return $status . '<br />' . date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) );
}
}
if ( !function_exists( 'sportspress_get_post_precision' ) ) {
function sportspress_get_post_precision( $post_id ) {
$precision = get_post_meta ( $post_id, 'sp_precision', true );
@@ -594,7 +609,7 @@ if ( !function_exists( 'sportspress_edit_calendar_table' ) ) {
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php echo $event->post_title; ?>
<?php edit_post_link( $event->post_title, null, null, $event->ID ); ?>
</td>
<td>
<?php echo get_the_time( get_option('date_format'), $event->ID ); ?>
@@ -1161,24 +1176,6 @@ if ( !function_exists( 'sportspress_get_calendar_data' ) ) {
$seasons = get_the_terms( $post_id, 'sp_season' );
$venues = get_the_terms( $post_id, 'sp_venue' );
if ( ! $leagues || ! $seasons || ! $venues )
return array();
$league_ids = array();
foreach( $leagues as $league ):
$league_ids[] = $league->term_id;
endforeach;
$season_ids = array();
foreach( $seasons as $season ):
$season_ids[] = $season->term_id;
endforeach;
$venue_ids = array();
foreach( $venues as $venue ):
$venue_ids[] = $venue->term_id;
endforeach;
$args = array(
'post_type' => 'sp_event',
'numberposts' => -1,
@@ -1187,24 +1184,46 @@ if ( !function_exists( 'sportspress_get_calendar_data' ) ) {
'order' => 'ASC',
'post_status' => 'any',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'sp_league',
'field' => 'id',
'terms' => $league_ids
),
array(
'taxonomy' => 'sp_season',
'field' => 'id',
'terms' => $season_ids
),
array(
'taxonomy' => 'sp_venue',
'field' => 'id',
'terms' => $venue_ids
),
'relation' => 'AND'
),
);
if ( $leagues ):
$league_ids = array();
foreach( $leagues as $league ):
$league_ids[] = $league->term_id;
endforeach;
$args['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'id',
'terms' => $league_ids
);
endif;
if ( $seasons ):
$season_ids = array();
foreach( $seasons as $season ):
$season_ids[] = $season->term_id;
endforeach;
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'id',
'terms' => $season_ids
);
endif;
if ( $venues ):
$venue_ids = array();
foreach( $venues as $venue ):
$venue_ids[] = $venue->term_id;
endforeach;
$args['tax_query'][] = array(
'taxonomy' => 'sp_venue',
'field' => 'id',
'terms' => $venue_ids
);
endif;
$events = get_posts( $args );
return $events;

View File

@@ -59,7 +59,7 @@ require_once dirname( __FILE__ ) . '/admin/post-types/metric.php';
require_once dirname( __FILE__ ) . '/admin/post-types/result.php';
require_once dirname( __FILE__ ) . '/admin/post-types/outcome.php';
require_once dirname( __FILE__ ) . '/admin/post-types/event.php';
#require_once dirname( __FILE__ ) . '/admin/post-types/calendar.php';
require_once dirname( __FILE__ ) . '/admin/post-types/calendar.php';
require_once dirname( __FILE__ ) . '/admin/post-types/team.php';
require_once dirname( __FILE__ ) . '/admin/post-types/table.php';
require_once dirname( __FILE__ ) . '/admin/post-types/player.php';