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' ),
);

View File

@@ -43,7 +43,8 @@ if ( $order != 'default' )
$calendar->order = $order;
$data = $calendar->data();
$usecolumns = $calendar->columns;
$title_format = $calendar->title_format;
$title_format = get_option( 'sportspress_event_list_title_format', 'title' );
$time_format = get_option( 'sportspress_event_list_time_format', 'combined' );
if ( isset( $columns ) ):
if ( is_array( $columns ) )
@@ -51,6 +52,10 @@ if ( isset( $columns ) ):
else
$usecolumns = explode( ',', $columns );
endif;
if ( $id ) {
echo '<h4 class="sp-table-caption">' . get_the_title( $id ) . '</h4>';
}
?>
<div class="sp-template sp-template-event-list">
<div class="sp-table-wrapper<?php if ( $scrollable ) { ?> sp-scrollable-table-wrapper<?php } ?>">
@@ -60,25 +65,47 @@ endif;
<?php
echo '<th class="data-date">' . __( 'Date', 'sportspress' ) . '</th>';
if ( $usecolumns == null || in_array( 'event', $usecolumns ) ):
if ( $title_format == 'homeaway' ):
echo '<th class="data-home">' . __( 'Home', 'sportspress' ) . '</th>';
elseif ( $title_format == 'teams' ):
echo '<th class="data-teams">' . __( 'Teams', 'sportspress' ) . '</th>';
else:
echo '<th class="data-event">' . __( 'Event', 'sportspress' ) . '</th>';
endif;
endif;
switch ( $title_format ) {
case 'homeaway':
if ( sp_column_active( $usecolumns, 'event' ) ) {
echo '<th class="data-home">' . __( 'Home', 'sportspress' ) . '</th>';
if ( $usecolumns == null || in_array( 'time', $usecolumns ) ):
if ( $usecolumns == null || in_array( 'event', $usecolumns ) && $title_format == 'homeaway' )
echo '<th class="data-time">&nbsp;</th>';
else
echo '<th class="data-time">' . __( 'Time/Results', 'sportspress' ) . '</th>';
endif;
if ( 'combined' == $time_format && sp_column_active( $usecolumns, 'time' ) ) {
echo '<th class="data-time">&nbsp;</th>';
} elseif ( in_array( $time_format, array( 'separate', 'results' ) ) && sp_column_active( $usecolumns, 'results' ) ) {
echo '<th class="data-results">&nbsp;</th>';
}
if ( $usecolumns == null || in_array( 'event', $usecolumns ) && $title_format == 'homeaway' )
echo '<th class="data-away">' . __( 'Away', 'sportspress' ) . '</th>';
echo '<th class="data-away">' . __( 'Away', 'sportspress' ) . '</th>';
if ( in_array( $time_format, array( 'separate', 'time' ) ) && sp_column_active( $usecolumns, 'time' ) ) {
echo '<th class="data-time">' . __( 'Time', 'sportspress' ) . '</th>';
}
}
break;
default:
if ( sp_column_active( $usecolumns, 'event' ) ) {
if ( $title_format == 'teams' )
echo '<th class="data-teams">' . __( 'Teams', 'sportspress' ) . '</th>';
else
echo '<th class="data-event">' . __( 'Event', 'sportspress' ) . '</th>';
}
switch ( $time_format ) {
case 'separate':
echo '<th class="data-time">' . __( 'Time', 'sportspress' ) . '</th>';
echo '<th class="data-results">' . __( 'Results', 'sportspress' ) . '</th>';
break;
case 'time':
echo '<th class="data-time">' . __( 'Time', 'sportspress' ) . '</th>';
break;
case 'results':
echo '<th class="data-results">' . __( 'Results', 'sportspress' ) . '</th>';
break;
default:
echo '<th class="data-time">' . __( 'Time/Results', 'sportspress' ) . '</th>';
}
}
if ( $usecolumns == null || in_array( 'league', $usecolumns ) )
echo '<th class="data-league">' . __( 'Competition', 'sportspress' ) . '</th>';
@@ -110,7 +137,7 @@ endif;
$main_results = sp_get_main_results( $event );
$teams_output = '';
$teams_array = '';
$teams_array = array();
if ( $teams ):
foreach ( $teams as $team ):
@@ -143,33 +170,95 @@ endif;
echo '<td class="data-date"><a href="' . get_permalink( $event->ID ) . '"><date>' . get_post_time( 'Y-m-d H:i:s', false, $event ) . '</date>' . get_post_time( get_option( 'date_format' ), false, $event, true ) . '</a></td>';
if ( $usecolumns == null || in_array( 'event', $usecolumns ) ):
if ( $title_format == 'homeaway' ):
$team = array_shift( $teams_array );
echo '<td class="data-home">' . $team . '</td>';
else:
if ( $title_format == 'teams' ):
echo '<td class="data-event">' . $teams_output . '</td>';
else:
echo '<td class="data-event"><a href="' . get_permalink( $event->ID ) . '">' . $event->post_title . '</a></td>';
endif;
endif;
endif;
switch ( $title_format ) {
case 'homeaway':
if ( sp_column_active( $usecolumns, 'event' ) ) {
$team = array_shift( $teams_array );
echo '<td class="data-home">' . $team . '</td>';
if ( $usecolumns == null || in_array( 'time', $usecolumns ) ):
echo '<td class="data-time"><a href="' . get_permalink( $event->ID ) . '">';
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . sp_get_time( $event );
endif;
echo '</a></td>';
endif;
if ( 'combined' == $time_format && sp_column_active( $usecolumns, 'time' ) ) {
echo '<td class="data-time"><a href="' . get_permalink( $event->ID ) . '">';
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . sp_get_time( $event );
endif;
echo '</a></td>';
} elseif ( in_array( $time_format, array( 'separate', 'results' ) ) && sp_column_active( $usecolumns, 'results' ) ) {
echo '<td class="data-results"><a href="' . get_permalink( $event->ID ) . '">';
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo '-';
endif;
echo '</a></td>';
}
if ( $usecolumns == null || in_array( 'event', $usecolumns ) && $title_format == 'homeaway' ):
$team = array_shift( $teams_array );
echo '<td class="data-away">' . $team . '</td>';
endif;
$team = array_shift( $teams_array );
echo '<td class="data-away">' . $team . '</td>';
if ( in_array( $time_format, array( 'separate', 'time' ) ) && sp_column_active( $usecolumns, 'time' ) ) {
echo '<td class="data-time"><a href="' . get_permalink( $event->ID ) . '">';
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . sp_get_time( $event );
echo '</a></td>';
}
}
break;
default:
if ( sp_column_active( $usecolumns, 'event' ) ) {
if ( $title_format == 'teams' )
echo '<td class="data-event">' . $teams_output . '</td>';
else
echo '<td class="data-event"><a href="' . get_permalink( $event->ID ) . '">' . $event->post_title . '</a></td>';
}
switch ( $time_format ) {
case 'separate':
if ( sp_column_active( $usecolumns, 'time' ) ) {
echo '<td class="data-time"><a href="' . get_permalink( $event->ID ) . '">';
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . sp_get_time( $event );
echo '</a></td>';
}
if ( sp_column_active( $usecolumns, 'results' ) ) {
echo '<td class="data-results"><a href="' . get_permalink( $event->ID ) . '">';
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo '-';
endif;
echo '</a></td>';
}
break;
case 'time':
if ( sp_column_active( $usecolumns, 'time' ) ) {
echo '<td class="data-time"><a href="' . get_permalink( $event->ID ) . '">';
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . sp_get_time( $event );
echo '</a></td>';
}
break;
case 'results':
if ( sp_column_active( $usecolumns, 'results' ) ) {
echo '<td class="data-results"><a href="' . get_permalink( $event->ID ) . '">';
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo '-';
endif;
echo '</a></td>';
}
break;
default:
if ( sp_column_active( $usecolumns, 'time' ) ) {
echo '<td class="data-time"><a href="' . get_permalink( $event->ID ) . '">';
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo '<date>&nbsp;' . get_post_time( 'H:i:s', false, $event ) . '</date>' . sp_get_time( $event );
endif;
echo '</a></td>';
}
}
}
if ( $usecolumns == null || in_array( 'league', $usecolumns ) ):
echo '<td class="data-league">';
@@ -231,8 +320,8 @@ endif;
</tbody>
</table>
</div>
</div>
<?php
if ( $id && $show_all_events_link )
echo '<a class="sp-calendar-link sp-view-all-link" href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a>';
?>
<?php
if ( $id && $show_all_events_link )
echo '<a class="sp-calendar-link sp-view-all-link" href="' . get_permalink( $id ) . '">' . __( 'View all events', 'sportspress' ) . '</a>';
?>
</div>