From 71ac76ddf67ff6a4f7a20730935befa23f10eab0 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Wed, 8 Nov 2017 18:57:09 +1100 Subject: [PATCH] Add date selectors to player lists and league tables --- includes/admin/class-sp-admin-assets.php | 2 +- .../class-sp-meta-box-list-details.php | 44 +++++++++++++++++ .../class-sp-meta-box-table-details.php | 44 +++++++++++++++++ includes/class-sp-league-table.php | 49 ++++++++++++++++++- includes/class-sp-player-list.php | 49 ++++++++++++++++++- 5 files changed, 185 insertions(+), 3 deletions(-) diff --git a/includes/admin/class-sp-admin-assets.php b/includes/admin/class-sp-admin-assets.php index 7ed33850..25cc8406 100755 --- a/includes/admin/class-sp-admin-assets.php +++ b/includes/admin/class-sp-admin-assets.php @@ -59,7 +59,7 @@ class SP_Admin_Assets { wp_enqueue_style( 'sportspress-admin-equation-styles', SP()->plugin_url() . '/assets/css/equation.css', array(), SP_VERSION ); } - if ( in_array( $screen->id, array( 'sp_calendar', 'widgets' ) ) ) { + if ( in_array( $screen->id, apply_filters( 'sportspress_admin_datepicker_screen_ids', array( 'sp_calendar', 'sp_table', 'sp_list', 'widgets' ) ) ) ) { wp_enqueue_style( 'jquery-ui-style' , '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css' ); wp_enqueue_style( 'sportspress-admin-datepicker-styles', SP()->plugin_url() . '/assets/css/datepicker.css', array( 'jquery-ui-style' ), SP_VERSION ); } diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-details.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-details.php index 6f8716e9..67f8298f 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-details.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-list-details.php @@ -29,11 +29,50 @@ class SP_Meta_Box_List_Details { $select = get_post_meta( $post->ID, 'sp_select', true ); $number = get_post_meta( $post->ID, 'sp_number', true ); $crop = get_post_meta( $post->ID, 'sp_crop', true ); + $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 ); + $date_past = get_post_meta( $post->ID, 'sp_date_past', true ); + $date_relative = get_post_meta( $post->ID, 'sp_date_relative', true ); ?>

+
+

+

+ 'sp_date', + 'id' => 'sp_date', + 'selected' => $date, + ); + sp_dropdown_dates( $args ); + ?> +

+
+

+ + : + +

+ +

+ + + +

+ +

+ +

+
+
+ ID, 'sp_caption', true ); $select = get_post_meta( $post->ID, 'sp_select', true ); $post_type = sp_get_post_mode_type( $post->ID ); + $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 ); + $date_past = get_post_meta( $post->ID, 'sp_date_past', true ); + $date_relative = get_post_meta( $post->ID, 'sp_date_relative', true ); ?>

+
+

+

+ 'sp_date', + 'id' => 'sp_date', + 'selected' => $date, + ); + sp_dropdown_dates( $args ); + ?> +

+
+

+ + : + +

+ +

+ + + +

+ +

+ +

+
+
+ date = $this->__get( 'date' ); + + if ( ! $this->date ) + $this->date = 0; + // Apply defaults if ( empty( $select ) ) $select = 'auto'; + if ( 'range' == $this->date ) { + + $this->relative = get_post_meta( $this->ID, 'sp_date_relative', true ); + + if ( $this->relative ) { + + if ( ! $this->past ) + $this->past = get_post_meta( $this->ID, 'sp_date_past', true ); + + } else { + + if ( ! $this->from ) + $this->from = get_post_meta( $this->ID, 'sp_date_from', true ); + + if ( ! $this->to ) + $this->to = get_post_meta( $this->ID, 'sp_date_to', true ); + + } + + } + // Get labels from result variables $result_labels = (array)sp_get_var_labels( 'sp_result' ); @@ -237,6 +263,23 @@ class SP_League_Table extends SP_Custom_Post{ ); endif; + if ( $this->date !== 0 ): + if ( $this->date == 'w' ): + $args['year'] = date_i18n('Y'); + $args['w'] = date_i18n('W'); + elseif ( $this->date == 'day' ): + $args['year'] = date_i18n('Y'); + $args['day'] = date_i18n('j'); + $args['monthnum'] = date_i18n('n'); + elseif ( $this->date == 'range' ): + if ( $this->relative ): + add_filter( 'posts_where', array( $this, 'relative' ) ); + else: + add_filter( 'posts_where', array( $this, 'range' ) ); + endif; + endif; + endif; + $args = apply_filters( 'sportspress_table_data_event_args', $args ); if ( ! $is_main_loop ): @@ -251,6 +294,10 @@ class SP_League_Table extends SP_Custom_Post{ $events = get_posts( $args ); + // Remove range filters + remove_filter( 'posts_where', array( $this, 'range' ) ); + remove_filter( 'posts_where', array( $this, 'relative' ) ); + $e = 0; // Event loop diff --git a/includes/class-sp-player-list.php b/includes/class-sp-player-list.php index f613f199..e70c4547 100644 --- a/includes/class-sp-player-list.php +++ b/includes/class-sp-player-list.php @@ -10,7 +10,7 @@ * @category Class * @author ThemeBoy */ -class SP_Player_List extends SP_Custom_Post { +class SP_Player_List extends SP_Secondary_Post { /** @var array The columns array. */ public $columns; @@ -48,11 +48,37 @@ class SP_Player_List extends SP_Custom_Post { $order = get_post_meta( $this->ID, 'sp_order', true ); $select = get_post_meta( $this->ID, 'sp_select', true ); + $this->date = $this->__get( 'date' ); + + if ( ! $this->date ) + $this->date = 0; + // Apply defaults if ( empty( $orderby ) ) $orderby = 'number'; if ( empty( $order ) ) $order = 'ASC'; if ( empty( $select ) ) $select = 'auto'; + if ( 'range' == $this->date ) { + + $this->relative = get_post_meta( $this->ID, 'sp_date_relative', true ); + + if ( $this->relative ) { + + if ( ! $this->past ) + $this->past = get_post_meta( $this->ID, 'sp_date_past', true ); + + } else { + + if ( ! $this->from ) + $this->from = get_post_meta( $this->ID, 'sp_date_from', true ); + + if ( ! $this->to ) + $this->to = get_post_meta( $this->ID, 'sp_date_to', true ); + + } + + } + // Get labels from performance variables $performance_labels = (array)sp_get_var_labels( 'sp_performance' ); @@ -309,10 +335,31 @@ class SP_Player_List extends SP_Custom_Post { ); endif; + if ( $this->date !== 0 ): + if ( $this->date == 'w' ): + $args['year'] = date_i18n('Y'); + $args['w'] = date_i18n('W'); + elseif ( $this->date == 'day' ): + $args['year'] = date_i18n('Y'); + $args['day'] = date_i18n('j'); + $args['monthnum'] = date_i18n('n'); + elseif ( $this->date == 'range' ): + if ( $this->relative ): + add_filter( 'posts_where', array( $this, 'relative' ) ); + else: + add_filter( 'posts_where', array( $this, 'range' ) ); + endif; + endif; + endif; + $args = apply_filters( 'sportspress_list_data_event_args', $args ); $events = get_posts( $args ); + // Remove range filters + remove_filter( 'posts_where', array( $this, 'range' ) ); + remove_filter( 'posts_where', array( $this, 'relative' ) ); + // Event loop foreach ( $events as $i => $event ): $results = (array)get_post_meta( $event->ID, 'sp_results', true );