Option to split time and results in event list

This commit is contained in:
Brian Miyaji
2014-12-09 18:07:05 +11:00
parent 4cd103d81c
commit ecb3d02eb3
5 changed files with 225 additions and 75 deletions

View File

@@ -101,7 +101,7 @@ class SP_Admin_CPT_List extends SP_Admin_CPT {
$selected = isset( $_REQUEST['sp_league'] ) ? $_REQUEST['sp_league'] : null;
$args = array(
'show_option_all' => __( 'Show all leagues', 'sportspress' ),
'show_option_all' => __( 'Show all competitions', 'sportspress' ),
'taxonomy' => 'sp_league',
'name' => 'sp_league',
'selected' => $selected

View File

@@ -22,22 +22,23 @@ class SP_Meta_Box_Calendar_Data {
$calendar = new SP_Calendar( $post );
$data = $calendar->data();
$usecolumns = $calendar->columns;
$title_format = $calendar->title_format;
self::table( $data, $usecolumns, $title_format );
self::table( $data, $usecolumns );
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_title_format', sp_array_value( $_POST, 'sp_title_format', 'title' ) );
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
}
/**
* Admin edit table
*/
public static function table( $data = array(), $usecolumns = null, $title_format = null ) {
public static function table( $data = array(), $usecolumns = null ) {
$title_format = get_option( 'sportspress_event_list_title_format', 'title' );
$time_format = get_option( 'sportspress_event_list_time_format', 'combined' );
if ( is_array( $usecolumns ) )
$usecolumns = array_filter( $usecolumns );
?>
@@ -51,19 +52,37 @@ class SP_Meta_Box_Calendar_Data {
<th class="column-event">
<label for="sp_columns_event">
<input type="checkbox" name="sp_columns[]" value="event" id="sp_columns_event" <?php checked( ! is_array( $usecolumns ) || in_array( 'event', $usecolumns ) ); ?>>
<select name="sp_title_format" class="sp-title-format-select">
<option value="title" <?php selected( $title_format, 'title' ); ?>><?php _e( 'Title', 'sportspress' ); ?></option>
<option value="teams" <?php selected( $title_format, 'teams' ); ?>><?php _e( 'Teams', 'sportspress' ); ?></option>
<option value="homeaway" <?php selected( $title_format, 'homeaway' ); ?>><?php _e( 'Home', 'sportspress' ); ?> | <?php _e( 'Away', 'sportspress' ); ?></option>
</select>
<?php
if ( 'teams' == $title_format ) {
_e( 'Home', 'sportspress' ); ?> | <?php _e( 'Away', 'sportspress' );
} elseif ( 'homeaway' == $title_format ) {
_e( 'Teams', 'sportspress' );
} else {
_e( 'Title', 'sportspress' );
}
?>
</label>
</th>
<th class="column-time">
<label for="sp_columns_time">
<input type="checkbox" name="sp_columns[]" value="time" id="sp_columns_time" <?php checked( ! is_array( $usecolumns ) || in_array( 'time', $usecolumns ) ); ?>>
<?php _e( 'Time/Results', 'sportspress' ); ?>
<?php
if ( 'time' == $time_format || 'separate' == $time_format ) {
_e( 'Time', 'sportspress' );
} else {
_e( 'Time/Results', 'sportspress' );
}
?>
</label>
</th>
<?php if ( in_array( $time_format, array( 'separate', 'results' ) ) ) { ?>
<th class="column-results">
<label for="sp_columns_results">
<input type="checkbox" name="sp_columns[]" value="results" id="sp_columns_results" <?php checked( ! is_array( $usecolumns ) || in_array( 'results', $usecolumns ) ); ?>>
<?php _e( 'Results', 'sportspress' ); ?>
</label>
</th>
<?php } ?>
<th class="column-league">
<label for="sp_columns_league">
<input type="checkbox" name="sp_columns[]" value="league" id="sp_columns_league" <?php checked( ! is_array( $usecolumns ) || in_array( 'league', $usecolumns ) ); ?>>
@@ -139,15 +158,30 @@ class SP_Meta_Box_Calendar_Data {
?>
</div>
</td>
<td>
<?php
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo get_post_time( get_option( 'time_format' ), false, $event, true );
endif;
?>
</td>
<?php if ( 'separate' == $time_format ) { ?>
<td>
<?php echo get_post_time( get_option( 'time_format' ), false, $event, true ); ?>
</td>
<td>
<?php
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo '-';
endif;
?>
</td>
<?php } else { ?>
<td>
<?php
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo get_post_time( get_option( 'time_format' ), false, $event, true );
endif;
?>
</td>
<?php } ?>
<td><?php the_terms( $event->ID, 'sp_league' ); ?></td>
<td><?php the_terms( $event->ID, 'sp_season' ); ?></td>
<td><?php the_terms( $event->ID, 'sp_venue' ); ?></td>

View File

@@ -7,7 +7,7 @@
* @author ThemeBoy
* @category Core
* @package SportsPress/Functions
* @version 1.4.4
* @version 1.5
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -297,6 +297,12 @@ if ( !function_exists( 'sp_numbers_to_words' ) ) {
}
}
if ( !function_exists( 'sp_column_active' ) ) {
function sp_column_active( $array = null, $value = null ) {
return $array == null || in_array( $value, $array );
}
}
if ( !function_exists( 'sp_get_the_term_id' ) ) {
function sp_get_the_term_id( $post_id, $taxonomy ) {
$terms = get_the_terms( $post_id, $taxonomy );
@@ -477,10 +483,11 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
'selected' => null,
'hide_empty' => false,
'values' => 'slug',
'class' => null,
'property' => null,
'placeholder' => null,
'chosen' => false,
'class' => null,
'property' => null,
'placeholder' => null,
'chosen' => false,
'parent' => 0,
);
$args = array_merge( $defaults, $args );
if ( ! $args['taxonomy'] ) return false;
@@ -539,6 +546,26 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
endif;
printf( '<option value="%s" %s>%s</option>', $this_value, $selected_prop, $term->name );
$term_children = get_term_children( $term->term_id, $args['taxonomy'] );
foreach ( $term_children as $term_child_id ):
$term_child = get_term_by( 'id', $term_child_id, $args['taxonomy'] );
if ( $args['values'] == 'term_id' ):
$this_value = $term_child->term_id;
else:
$this_value = $term_child->slug;
endif;
if ( strpos( $property, 'multiple' ) !== false ):
$selected_prop = in_array( $this_value, $selected ) ? 'selected' : '';
else:
$selected_prop = selected( $this_value, $selected, false );
endif;
printf( '<option value="%s" %s>%s</option>', $this_value, $selected_prop, '— ' . $term_child->name );
endforeach;
endforeach;
print( '</select>' );
return true;

View File

@@ -136,7 +136,7 @@ class SP_Widget_Event_List extends WP_Widget {
<?php
$the_columns = array(
'event' => __( 'Event', 'sportspress' ),
'time' => __( 'Time', 'sportspress' ),
'time' => __( 'Time/Results', 'sportspress' ),
'venue' => __( 'Venue', 'sportspress' ),
'article' => __( 'Article', 'sportspress' ),
);