From 84e80d642a137d40e00a89539a187e224d472acf Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Mon, 22 Aug 2016 01:14:32 +1000 Subject: [PATCH] Add match day field to events and calendars --- .../class-sp-meta-box-calendar-details.php | 19 ++++++++++++- .../class-sp-meta-box-event-details.php | 8 ++++++ includes/class-sp-ajax.php | 11 ++++++++ includes/class-sp-calendar.php | 28 +++++++++++++++++-- .../widgets/class-sp-widget-event-blocks.php | 10 +++++-- .../class-sp-widget-event-calendar.php | 10 +++++-- .../widgets/class-sp-widget-event-list.php | 10 +++++-- templates/event-blocks.php | 14 ++++++++++ templates/event-calendar.php | 3 ++ templates/event-list.php | 3 ++ 10 files changed, 107 insertions(+), 9 deletions(-) diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php index 79a8b690..4de15aa8 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-calendar-details.php @@ -25,8 +25,10 @@ class SP_Meta_Box_Calendar_Details { $date = get_post_meta( $post->ID, 'sp_date', true ); $date_from = get_post_meta( $post->ID, 'sp_date_from', true ); $date_to = get_post_meta( $post->ID, 'sp_date_to', true ); + $day = get_post_meta( $post->ID, 'sp_day', true ); $teams = get_post_meta( $post->ID, 'sp_team', false ); $table_id = get_post_meta( $post->ID, 'sp_table', true ); + $orderby = get_post_meta( $post->ID, 'sp_orderby', true ); $order = get_post_meta( $post->ID, 'sp_order', true ); ?>
@@ -62,6 +64,12 @@ class SP_Meta_Box_Calendar_Details {

+
+

+

+ +

+

+

+

+ +

+

+

@@ -66,6 +73,7 @@ class SP_Meta_Box_Event_Details { * Save meta box data */ public static function save( $post_id, $post ) { + update_post_meta( $post_id, 'sp_day', sp_array_value( $_POST, 'sp_day', null ) ); update_post_meta( $post_id, 'sp_minutes', sp_array_value( $_POST, 'sp_minutes', get_option( 'sportspress_event_minutes', 90 ) ) ); $venues = array_filter( sp_array_value( sp_array_value( $_POST, 'tax_input', array() ), 'sp_venue', array() ) ); if ( empty( $venues ) ) { diff --git a/includes/class-sp-ajax.php b/includes/class-sp-ajax.php index cf976820..9451d53f 100644 --- a/includes/class-sp-ajax.php +++ b/includes/class-sp-ajax.php @@ -554,6 +554,16 @@ class SP_AJAX {

+

+ +

+

+

+

diff --git a/includes/widgets/class-sp-widget-event-calendar.php b/includes/widgets/class-sp-widget-event-calendar.php index 91c855a6..369f26b3 100644 --- a/includes/widgets/class-sp-widget-event-calendar.php +++ b/includes/widgets/class-sp-widget-event-calendar.php @@ -20,6 +20,7 @@ class SP_Widget_Event_Calendar extends WP_Widget { $date = empty($instance['date']) ? 'default' : $instance['date']; $date_from = empty($instance['date_from']) ? 'default' : $instance['date_from']; $date_to = empty($instance['date_to']) ? 'default' : $instance['date_to']; + $day = empty($instance['day']) ? 'default' : $instance['day']; $show_all_events_link = empty($instance['show_all_events_link']) ? false : $instance['show_all_events_link']; do_action( 'sportspress_before_widget', $args, $instance, 'event-calendar' ); @@ -31,7 +32,7 @@ class SP_Widget_Event_Calendar extends WP_Widget { // Action to hook into do_action( 'sportspress_before_widget_template', $args, $instance, 'event-calendar' ); - sp_get_template( 'event-calendar.php', array( 'id' => $id, 'status' => $status, 'date' => $date, 'date_from' => $date_from, 'date_to' => $date_to, 'caption_tag' => 'caption', 'show_all_events_link' => $show_all_events_link ) ); + sp_get_template( 'event-calendar.php', array( 'id' => $id, 'status' => $status, 'date' => $date, 'date_from' => $date_from, 'date_to' => $date_to, 'caption_tag' => 'caption', 'day' => $day, 'show_all_events_link' => $show_all_events_link ) ); // Action to hook into do_action( 'sportspress_after_widget_template', $args, $instance, 'event-calendar' ); @@ -48,6 +49,7 @@ class SP_Widget_Event_Calendar extends WP_Widget { $instance['date'] = $new_instance['date']; $instance['date_from'] = $new_instance['date_from']; $instance['date_to'] = $new_instance['date_to']; + $instance['day'] = $new_instance['day']; $instance['show_all_events_link'] = $new_instance['show_all_events_link']; // Filter to hook into @@ -57,13 +59,14 @@ class SP_Widget_Event_Calendar extends WP_Widget { } function form( $instance ) { - $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'status' => 'default', 'date' => 'default', 'date_from' => date_i18n( 'Y-m-d' ), 'date_to' => date_i18n( 'Y-m-d' ), 'show_all_events_link' => false ) ); + $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'status' => 'default', 'date' => 'default', 'date_from' => date_i18n( 'Y-m-d' ), 'date_to' => date_i18n( 'Y-m-d' ), 'day' => '', 'show_all_events_link' => false ) ); $title = strip_tags($instance['title']); $id = intval($instance['id']); $status = $instance['status']; $date = $instance['date']; $date_from = $instance['date_from']; $date_to = $instance['date_to']; + $day = $instance['day']; $show_all_events_link = $instance['show_all_events_link']; // Action to hook into @@ -122,6 +125,9 @@ class SP_Widget_Event_Calendar extends WP_Widget {

+

+

+

>

diff --git a/includes/widgets/class-sp-widget-event-list.php b/includes/widgets/class-sp-widget-event-list.php index 33f14f28..8f5a02c9 100644 --- a/includes/widgets/class-sp-widget-event-list.php +++ b/includes/widgets/class-sp-widget-event-list.php @@ -21,6 +21,7 @@ class SP_Widget_Event_List extends WP_Widget { $date = empty($instance['date']) ? 'default' : $instance['date']; $date_from = empty($instance['date_from']) ? 'default' : $instance['date_from']; $date_to = empty($instance['date_to']) ? 'default' : $instance['date_to']; + $day = empty($instance['day']) ? 'default' : $instance['day']; $number = empty($instance['number']) ? null : $instance['number']; $columns = empty($instance['columns']) ? null : $instance['columns']; $order = empty($instance['order']) ? 'default' : $instance['order']; @@ -35,7 +36,7 @@ class SP_Widget_Event_List extends WP_Widget { // Action to hook into do_action( 'sportspress_before_widget_template', $args, $instance, 'event-list' ); - sp_get_template( 'event-list.php', array( 'id' => $id, 'title' => $caption, 'status' => $status, 'date' => $date, 'date_from' => $date_from, 'date_to' => $date_to, 'number' => $number, 'columns' => $columns, 'order' => $order, 'show_all_events_link' => $show_all_events_link ) ); + sp_get_template( 'event-list.php', array( 'id' => $id, 'title' => $caption, 'status' => $status, 'date' => $date, 'date_from' => $date_from, 'date_to' => $date_to, 'day' => $day, 'number' => $number, 'columns' => $columns, 'order' => $order, 'show_all_events_link' => $show_all_events_link ) ); // Action to hook into do_action( 'sportspress_after_widget_template', $args, $instance, 'event-list' ); @@ -53,6 +54,7 @@ class SP_Widget_Event_List extends WP_Widget { $instance['date'] = $new_instance['date']; $instance['date_from'] = $new_instance['date_from']; $instance['date_to'] = $new_instance['date_to']; + $instance['day'] = $new_instance['day']; $instance['number'] = intval($new_instance['number']); $instance['columns'] = (array)$new_instance['columns']; $instance['order'] = strip_tags($new_instance['order']); @@ -65,7 +67,7 @@ class SP_Widget_Event_List extends WP_Widget { } function form( $instance ) { - $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'caption' => '', 'status' => 'default', 'date' => 'default', 'date_from' => date_i18n( 'Y-m-d' ), 'date_to' => date_i18n( 'Y-m-d' ), 'number' => 5, 'columns' => null, 'order' => 'default', 'show_all_events_link' => true ) ); + $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'id' => null, 'caption' => '', 'status' => 'default', 'date' => 'default', 'date_from' => date_i18n( 'Y-m-d' ), 'date_to' => date_i18n( 'Y-m-d' ), 'day' => '', 'number' => 5, 'columns' => null, 'order' => 'default', 'show_all_events_link' => true ) ); $title = strip_tags($instance['title']); $id = intval($instance['id']); $caption = strip_tags($instance['caption']); @@ -73,6 +75,7 @@ class SP_Widget_Event_List extends WP_Widget { $date = $instance['date']; $date_from = $instance['date_from']; $date_to = $instance['date_to']; + $day = $instance['day']; $number = intval($instance['number']); $columns = $instance['columns']; $order = strip_tags($instance['order']); @@ -137,6 +140,9 @@ class SP_Widget_Event_List extends WP_Widget {

+

+

+

diff --git a/templates/event-blocks.php b/templates/event-blocks.php index 3b515e56..5bab56b5 100644 --- a/templates/event-blocks.php +++ b/templates/event-blocks.php @@ -16,6 +16,7 @@ $defaults = array( 'date' => 'default', 'date_from' => 'default', 'date_to' => 'default', + 'day' => 'default', 'league' => null, 'season' => null, 'venue' => null, @@ -27,6 +28,7 @@ $defaults = array( 'link_events' => get_option( 'sportspress_link_events', 'yes' ) == 'yes' ? true : false, 'paginated' => get_option( 'sportspress_event_blocks_paginated', 'yes' ) == 'yes' ? true : false, 'rows' => get_option( 'sportspress_event_blocks_rows', 5 ), + 'orderby' => 'default', 'order' => 'default', 'show_all_events_link' => false, 'show_title' => get_option( 'sportspress_event_blocks_show_title', 'no' ) == 'yes' ? true : false, @@ -59,6 +61,10 @@ if ( $player ) $calendar->player = $player; if ( $order != 'default' ) $calendar->order = $order; +if ( $orderby != 'default' ) + $calendar->orderby = $orderby; +if ( $day != 'default' ) + $calendar->day = $day; $data = $calendar->data(); if ( $hide_if_empty && empty( $data ) ) return; @@ -109,6 +115,14 @@ if ( $title ) endif; endforeach; endif; + + if ( 'day' === $calendar->orderby ): + $event_group = get_post_meta( $event->ID, 'sp_day', true ); + if ( ! isset( $group ) || $event_group !== $group ): + $group = $event_group; + echo '', __( 'Match Day', 'sportspress' ), ' ', $group, ''; + endif; + endif; ?> diff --git a/templates/event-calendar.php b/templates/event-calendar.php index 2e11b029..a4c41a29 100644 --- a/templates/event-calendar.php +++ b/templates/event-calendar.php @@ -17,6 +17,7 @@ $defaults = array( 'date' => 'default', 'date_from' => 'default', 'date_to' => 'default', + 'day' => 'default', 'league' => null, 'season' => null, 'venue' => null, @@ -39,6 +40,8 @@ if ( $date_from != 'default' ) $calendar->from = $date_from; if ( $date_to != 'default' ) $calendar->to = $date_to; +if ( $day != 'default' ) + $calendar->day = $day; if ( $league ) $calendar->league = $league; if ( $season ) diff --git a/templates/event-list.php b/templates/event-list.php index a7fd336c..825dc5cf 100644 --- a/templates/event-list.php +++ b/templates/event-list.php @@ -16,6 +16,7 @@ $defaults = array( 'date' => 'default', 'date_from' => 'default', 'date_to' => 'default', + 'day' => 'default', 'league' => null, 'season' => null, 'venue' => null, @@ -60,6 +61,8 @@ if ( $player ) $calendar->player = $player; if ( $order != 'default' ) $calendar->order = $order; +if ( $day != 'default' ) + $calendar->day = $day; $data = $calendar->data(); $usecolumns = $calendar->columns; $title_format = get_option( 'sportspress_event_list_title_format', 'title' );