From d4c32b92c91fcb2a660990b6a9bce9b3301f3c6f Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Tue, 14 Jan 2014 19:31:15 +1100 Subject: [PATCH] Calendar post type basic functionality --- admin-functions.php | 93 +++++++++++++++++++++++++++++++++-- admin/post-types/calendar.php | 42 +++------------- 2 files changed, 98 insertions(+), 37 deletions(-) diff --git a/admin-functions.php b/admin-functions.php index 4b2cee4b..7d337f59 100644 --- a/admin-functions.php +++ b/admin-functions.php @@ -63,8 +63,8 @@ if ( !function_exists( 'sportspress_get_post_labels' ) ) { 'new_item' => sprintf( __( 'New %s', 'sportspress' ), $singular_name ), 'view_item' => sprintf( __( 'View %s', 'sportspress' ), $singular_name ), 'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ), - 'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name ), - 'not_found_in_trash' => sprintf( __( 'No %s found in trash', 'sportspress' ), $lowercase_name ), + 'not_found' => sprintf( __( 'No %s found.', 'sportspress' ), $lowercase_name ), + 'not_found_in_trash' => sprintf( __( 'No %s found in trash.', 'sportspress' ), $lowercase_name ), 'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':' ); return $labels; @@ -86,7 +86,7 @@ if ( !function_exists( 'sportspress_get_term_labels' ) ) { 'parent_item' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ), 'parent_item_colon' => sprintf( __( 'Parent %s', 'sportspress' ), $singular_name ) . ':', 'search_items' => sprintf( __( 'Search %s', 'sportspress' ), $name ), - 'not_found' => sprintf( __( 'No %s found', 'sportspress' ), $lowercase_name ) + 'not_found' => sprintf( __( 'No %s found.', 'sportspress' ), $lowercase_name ) ); return $labels; } @@ -493,6 +493,49 @@ if ( !function_exists( 'sportspress_get_var_equations' ) ) { } } +if ( !function_exists( 'sportspress_edit_calendar_table' ) ) { + function sportspress_edit_calendar_table( $data = array() ) { + if ( empty( $data ) ): + printf( __( 'No %s found.', 'sportspress' ), __( 'events', 'sportspress' ) ); + return false; + endif; + ?> +
+ + + + + + + + + + + + + + + + + +
+ post_title; ?> + + post_date ); ?> + + post_date ); ?> +
+
+ @@ -986,6 +1029,50 @@ if ( !function_exists( 'sportspress_solve' ) ) { } +if ( !function_exists( 'sportspress_get_calendar_data' ) ) { + function sportspress_get_calendar_data( $post_id ) { + $seasons = get_the_terms( $post_id, 'sp_season' ); + $venues = get_the_terms( $post_id, 'sp_venue' ); + + if ( ! $seasons || ! $venues ) + return array(); + + $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, + 'posts_per_page' => -1, + 'orderby' => 'post_date', + 'order' => 'ASC', + 'tax_query' => array( + array( + 'taxonomy' => 'sp_season', + 'field' => 'id', + 'terms' => $season_ids + ), + array( + 'taxonomy' => 'sp_venue', + 'field' => 'id', + 'terms' => $venue_ids + ), + ), + ); + $events = get_posts( $args ); + + return $events; + + } +} + if ( !function_exists( 'sportspress_get_league_table_data' ) ) { function sportspress_get_league_table_data( $post_id, $breakdown = false ) { $div_id = sportspress_get_the_term_id( $post_id, 'sp_season', 0 ); diff --git a/admin/post-types/calendar.php b/admin/post-types/calendar.php index 89049640..d78a262f 100644 --- a/admin/post-types/calendar.php +++ b/admin/post-types/calendar.php @@ -9,7 +9,7 @@ function sportspress_calendar_post_init() { 'labels' => $labels, 'public' => true, 'hierarchical' => false, - 'supports' => array( 'title', 'author', 'excerpt' ), + 'supports' => array( 'title', 'author', 'thumbnail', 'excerpt' ), 'register_meta_box_cb' => 'sportspress_calendar_meta_init', 'rewrite' => array( 'slug' => get_option( 'sp_calendar_slug', 'calendars' ) ), 'show_in_menu' => 'edit.php?post_type=sp_event', @@ -32,44 +32,18 @@ function sportspress_calendar_edit_columns() { add_filter( 'manage_edit-sp_calendar_columns', 'sportspress_calendar_edit_columns' ); function sportspress_calendar_meta_init( $post ) { - $teams = (array)get_post_meta( $post->ID, 'sp_team', false ); + $seasons = get_the_terms( $post->ID, 'sp_season' ); + $venues = get_the_terms( $post->ID, 'sp_venue' ); - add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sportspress_calendar_team_meta', 'sp_calendar', 'side', 'high' ); - - if ( $teams && $teams != array(0) ): - add_meta_box( 'sp_columnsdiv', __( 'League Table', 'sportspress' ), 'sportspress_calendar_columns_meta', 'sp_calendar', 'normal', 'high' ); - endif; + add_meta_box( 'sp_eventsdiv', __( 'Events', 'sportspress' ), 'sportspress_calendar_events_meta', 'sp_calendar', 'normal', 'high' ); } -function sportspress_calendar_team_meta( $post, $test ) { - $league_id = sportspress_get_the_term_id( $post->ID, 'sp_season', 0 ); - ?> -
-

- 'sp_season', - 'name' => 'sp_season', - 'selected' => $league_id, - 'value' => 'term_id' - ); - sportspress_dropdown_taxonomies( $args ); - ?> -

- ID, 'sp_team', 'block', 'sp_season' ); - sportspress_post_adder( 'sp_team' ); - ?> -
- ID, 'sp_season' ); -function sportspress_calendar_columns_meta( $post ) { + $data = sportspress_get_calendar_data( $post->ID, true ); -// list( $columns, $data, $placeholders, $merged ) = sportspress_get_league_calendar_data( $post->ID, true ); - -// sportspress_edit_league_calendar( $columns, $data, $placeholders ); + sportspress_edit_calendar_table( $data ); sportspress_nonce(); }