Add date selectors to player lists and league tables
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
?>
|
||||
<div>
|
||||
<p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p>
|
||||
<p><input type="text" id="sp_caption" name="sp_caption" value="<?php echo esc_attr( $caption ); ?>" placeholder="<?php echo esc_attr( get_the_title() ); ?>"></p>
|
||||
|
||||
<div class="sp-date-selector">
|
||||
<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>
|
||||
<div class="sp-date-range">
|
||||
<p class="sp-date-range-absolute">
|
||||
<input type="text" class="sp-datepicker-from" name="sp_date_from" value="<?php echo $date_from ? $date_from : date_i18n( 'Y-m-d' ); ?>" size="10">
|
||||
:
|
||||
<input type="text" class="sp-datepicker-to" name="sp_date_to" value="<?php echo $date_to ? $date_to : date_i18n( 'Y-m-d' ); ?>" size="10">
|
||||
</p>
|
||||
|
||||
<p class="sp-date-range-relative">
|
||||
<?php _e( 'Past', 'sportspress' ); ?>
|
||||
<input type="number" min="0" step="1" class="tiny-text" name="sp_date_past" value="<?php echo '' !== $date_past ? $date_past : 7; ?>">
|
||||
<?php _e( 'days', 'sportspress' ); ?>
|
||||
</p>
|
||||
|
||||
<p class="sp-date-relative">
|
||||
<label>
|
||||
<input type="checkbox" name="sp_date_relative" value="1" id="sp_date_relative" <?php checked( $date_relative ); ?>>
|
||||
<?php _e( 'Relative', 'sportspress' ); ?>
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
sp_taxonomy_field( $taxonomy, $post, true );
|
||||
@@ -122,6 +161,11 @@ class SP_Meta_Box_List_Details {
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_caption', esc_attr( sp_array_value( $_POST, 'sp_caption', 0 ) ) );
|
||||
update_post_meta( $post_id, 'sp_date', sp_array_value( $_POST, 'sp_date', 0 ) );
|
||||
update_post_meta( $post_id, 'sp_date_from', sp_array_value( $_POST, 'sp_date_from', null ) );
|
||||
update_post_meta( $post_id, 'sp_date_to', sp_array_value( $_POST, 'sp_date_to', null ) );
|
||||
update_post_meta( $post_id, 'sp_date_past', sp_array_value( $_POST, 'sp_date_past', 0 ) );
|
||||
update_post_meta( $post_id, 'sp_date_relative', sp_array_value( $_POST, 'sp_date_relative', 0 ) );
|
||||
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
||||
update_post_meta( $post_id, 'sp_era', sp_array_value( $_POST, 'sp_era', array() ) );
|
||||
update_post_meta( $post_id, 'sp_grouping', sp_array_value( $_POST, 'sp_grouping', array() ) );
|
||||
|
||||
@@ -24,11 +24,50 @@ class SP_Meta_Box_Table_Details {
|
||||
$caption = get_post_meta( $post->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 );
|
||||
?>
|
||||
<div>
|
||||
<p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p>
|
||||
<p><input type="text" id="sp_caption" name="sp_caption" value="<?php echo esc_attr( $caption ); ?>" placeholder="<?php echo esc_attr( get_the_title() ); ?>"></p>
|
||||
|
||||
<div class="sp-date-selector">
|
||||
<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>
|
||||
<div class="sp-date-range">
|
||||
<p class="sp-date-range-absolute">
|
||||
<input type="text" class="sp-datepicker-from" name="sp_date_from" value="<?php echo $date_from ? $date_from : date_i18n( 'Y-m-d' ); ?>" size="10">
|
||||
:
|
||||
<input type="text" class="sp-datepicker-to" name="sp_date_to" value="<?php echo $date_to ? $date_to : date_i18n( 'Y-m-d' ); ?>" size="10">
|
||||
</p>
|
||||
|
||||
<p class="sp-date-range-relative">
|
||||
<?php _e( 'Past', 'sportspress' ); ?>
|
||||
<input type="number" min="0" step="1" class="tiny-text" name="sp_date_past" value="<?php echo '' !== $date_past ? $date_past : 7; ?>">
|
||||
<?php _e( 'days', 'sportspress' ); ?>
|
||||
</p>
|
||||
|
||||
<p class="sp-date-relative">
|
||||
<label>
|
||||
<input type="checkbox" name="sp_date_relative" value="1" id="sp_date_relative" <?php checked( $date_relative ); ?>>
|
||||
<?php _e( 'Relative', 'sportspress' ); ?>
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
sp_taxonomy_field( $taxonomy, $post, true );
|
||||
@@ -58,6 +97,11 @@ class SP_Meta_Box_Table_Details {
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_caption', esc_attr( sp_array_value( $_POST, 'sp_caption', 0 ) ) );
|
||||
update_post_meta( $post_id, 'sp_date', sp_array_value( $_POST, 'sp_date', 0 ) );
|
||||
update_post_meta( $post_id, 'sp_date_from', sp_array_value( $_POST, 'sp_date_from', null ) );
|
||||
update_post_meta( $post_id, 'sp_date_to', sp_array_value( $_POST, 'sp_date_to', null ) );
|
||||
update_post_meta( $post_id, 'sp_date_past', sp_array_value( $_POST, 'sp_date_past', 0 ) );
|
||||
update_post_meta( $post_id, 'sp_date_relative', sp_array_value( $_POST, 'sp_date_relative', 0 ) );
|
||||
update_post_meta( $post_id, 'sp_select', sp_array_value( $_POST, 'sp_select', array() ) );
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
* @category Class
|
||||
* @author ThemeBoy
|
||||
*/
|
||||
class SP_League_Table extends SP_Custom_Post{
|
||||
class SP_League_Table extends SP_Secondary_Post {
|
||||
|
||||
/** @var array The sort priorities array. */
|
||||
public $priorities;
|
||||
@@ -42,9 +42,35 @@ class SP_League_Table extends SP_Custom_Post{
|
||||
$link_events = get_option( 'sportspress_link_events', 'yes' ) === 'yes' ? true : false;
|
||||
$form_limit = (int) get_option( 'sportspress_form_limit', 5 );
|
||||
|
||||
$this->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
|
||||
|
||||
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user