Add match days to event lists and move columns into dedicated meta box

This commit is contained in:
Brian Miyaji
2017-01-11 23:07:24 +11:00
parent 90533c42e5
commit ca8f1099bf
4 changed files with 233 additions and 94 deletions

View File

@@ -0,0 +1,82 @@
<?php
/**
* Calendar Columns
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.1.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Calendar_Columns
*/
class SP_Meta_Box_Calendar_Columns {
/**
* Output the metabox
*/
public static function output( $post ) {
$selected = (array) get_post_meta( $post->ID, 'sp_columns', true );
$title_format = get_option( 'sportspress_event_list_title_format', 'title' );
$time_format = get_option( 'sportspress_event_list_time_format', 'combined' );
if ( is_array( $selected ) ) {
$selected = array_filter( $selected );
}
$columns = array();
if ( 'teams' === $title_format ) {
$columns[ 'event' ] = __( 'Home', 'sportspress' ) . ' | ' . __( 'Away', 'sportspress' );
} elseif ( 'homeaway' === $title_format ) {
$columns[ 'event' ] = __( 'Teams', 'sportspress' );
} else {
$columns[ 'event' ] = __( 'Title', 'sportspress' );
}
if ( 'time' === $time_format || 'separate' === $time_format ) {
$columns['time'] = __( 'Time', 'sportspress' );
} elseif ( 'combined' === $time_format ) {
$columns['time'] = __( 'Time/Results', 'sportspress' );
}
if ( 'results' === $time_format || 'separate' === $time_format ) {
$columns['results'] = __( 'Results', 'sportspress' );
}
$columns['league'] = __( 'Competition', 'sportspress' );
$columns['season'] = __( 'Season', 'sportspress' );
$columns['venue'] = __( 'Venue', 'sportspress' );
$columns['article'] = __( 'Article', 'sportspress' );
$columns['day'] = __( 'Match Day', 'sportspress' );
$columns = apply_filters( 'sportspress_calendar_columns', $columns );
?>
<div class="sp-instance">
<ul class="categorychecklist form-no-clear">
<?php
foreach ( $columns as $key => $label ) {
?>
<li>
<label>
<input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! is_array( $selected ) || in_array( $key, $selected ) ); ?>>
<?php echo $label; ?>
</label>
</li>
<?php
}
?>
</div>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
}
}

View File

@@ -49,9 +49,9 @@ class SP_Meta_Box_Calendar_Data {
<th class="column-date"> <th class="column-date">
<?php _e( 'Date', 'sportspress' ); ?> <?php _e( 'Date', 'sportspress' ); ?>
</th> </th>
<?php if ( ! is_array( $usecolumns ) || in_array( 'event', $usecolumns ) ) { ?>
<th class="column-event"> <th class="column-event">
<label for="sp_columns_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 ) ); ?>>
<?php <?php
if ( 'teams' == $title_format ) { if ( 'teams' == $title_format ) {
_e( 'Home', 'sportspress' ); ?> | <?php _e( 'Away', 'sportspress' ); _e( 'Home', 'sportspress' ); ?> | <?php _e( 'Away', 'sportspress' );
@@ -63,10 +63,10 @@ class SP_Meta_Box_Calendar_Data {
?> ?>
</label> </label>
</th> </th>
<?php if ( in_array( $time_format, array( 'combined', 'separate', 'time' ) ) ) { ?> <?php } ?>
<?php if ( ( ! is_array( $usecolumns ) || in_array( 'time', $usecolumns ) ) && in_array( $time_format, array( 'combined', 'separate', 'time' ) ) ) { ?>
<th class="column-time"> <th class="column-time">
<label for="sp_columns_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 <?php
if ( 'time' == $time_format || 'separate' == $time_format ) { if ( 'time' == $time_format || 'separate' == $time_format ) {
_e( 'Time', 'sportspress' ); _e( 'Time', 'sportspress' );
@@ -77,38 +77,48 @@ class SP_Meta_Box_Calendar_Data {
</label> </label>
</th> </th>
<?php } ?> <?php } ?>
<?php if ( in_array( $time_format, array( 'separate', 'results' ) ) ) { ?> <?php if ( ( ! is_array( $usecolumns ) || in_array( 'results', $usecolumns ) ) && in_array( $time_format, array( 'separate', 'results' ) ) ) { ?>
<th class="column-results"> <th class="column-results">
<label for="sp_columns_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' ); ?> <?php _e( 'Results', 'sportspress' ); ?>
</label> </label>
</th> </th>
<?php } ?> <?php } ?>
<?php if ( ! is_array( $usecolumns ) || in_array( 'league', $usecolumns ) ) { ?>
<th class="column-league"> <th class="column-league">
<label for="sp_columns_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 ) ); ?>>
<?php _e( 'Competition', 'sportspress' ); ?> <?php _e( 'Competition', 'sportspress' ); ?>
</label> </label>
</th> </th>
<?php } ?>
<?php if ( ! is_array( $usecolumns ) || in_array( 'season', $usecolumns ) ) { ?>
<th class="column-season"> <th class="column-season">
<label for="sp_columns_season"> <label for="sp_columns_season">
<input type="checkbox" name="sp_columns[]" value="season" id="sp_columns_season" <?php checked( ! is_array( $usecolumns ) || in_array( 'season', $usecolumns ) ); ?>>
<?php _e( 'Season', 'sportspress' ); ?> <?php _e( 'Season', 'sportspress' ); ?>
</label> </label>
</th> </th>
<?php } ?>
<?php if ( ! is_array( $usecolumns ) || in_array( 'venue', $usecolumns ) ) { ?>
<th class="column-venue"> <th class="column-venue">
<label for="sp_columns_venue"> <label for="sp_columns_venue">
<input type="checkbox" name="sp_columns[]" value="venue" id="sp_columns_venue" <?php checked( ! is_array( $usecolumns ) || in_array( 'venue', $usecolumns ) ); ?>>
<?php _e( 'Venue', 'sportspress' ); ?> <?php _e( 'Venue', 'sportspress' ); ?>
</label> </label>
</th> </th>
<?php } ?>
<?php if ( ! is_array( $usecolumns ) || in_array( 'article', $usecolumns ) ) { ?>
<th class="column-article"> <th class="column-article">
<label for="sp_columns_article"> <label for="sp_columns_article">
<input type="checkbox" name="sp_columns[]" value="article" id="sp_columns_article" <?php checked( ! is_array( $usecolumns ) || in_array( 'article', $usecolumns ) ); ?>>
<?php _e( 'Article', 'sportspress' ); ?> <?php _e( 'Article', 'sportspress' ); ?>
</label> </label>
</th> </th>
<?php } ?>
<?php if ( ! is_array( $usecolumns ) || in_array( 'day', $usecolumns ) ) { ?>
<th class="column-day">
<label for="sp_columns_day">
<?php _e( 'Match Day', 'sportspress' ); ?>
</label>
</th>
<?php } ?>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -125,6 +135,7 @@ class SP_Meta_Box_Calendar_Data {
?> ?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>"> <tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td><?php echo get_post_time( get_option( 'date_format' ), false, $event, true ); ?></td> <td><?php echo get_post_time( get_option( 'date_format' ), false, $event, true ); ?></td>
<?php if ( ! is_array( $usecolumns ) || in_array( 'event', $usecolumns ) ) { ?>
<td> <td>
<div class="sp-title-format sp-title-format-title<?php if ( $title_format && $title_format != 'title' ): ?> hidden<?php endif; ?>"><?php echo $event->post_title; ?></div> <div class="sp-title-format sp-title-format-title<?php if ( $title_format && $title_format != 'title' ): ?> hidden<?php endif; ?>"><?php echo $event->post_title; ?></div>
<div class="sp-title-format sp-title-format-teams sp-title-format-homeaway<?php if ( ! in_array( $title_format, array( 'teams', 'homeaway' ) ) ): ?> hidden<?php endif; ?>"> <div class="sp-title-format sp-title-format-teams sp-title-format-homeaway<?php if ( ! in_array( $title_format, array( 'teams', 'homeaway' ) ) ): ?> hidden<?php endif; ?>">
@@ -161,19 +172,12 @@ class SP_Meta_Box_Calendar_Data {
?> ?>
</div> </div>
</td> </td>
<?php if ( 'separate' == $time_format ) { ?> <?php } ?>
<?php if ( ( ! is_array( $usecolumns ) || in_array( 'time', $usecolumns ) ) && in_array( $time_format, array( 'combined', 'separate', 'time' ) ) ) { ?>
<?php if ( 'time' == $time_format || 'separate' == $time_format ) { ?>
<td> <td>
<?php echo apply_filters( 'sportspress_event_time_admin', get_post_time( get_option( 'time_format' ), false, $event, true ), $event->ID ); ?> <?php echo apply_filters( 'sportspress_event_time_admin', get_post_time( get_option( 'time_format' ), false, $event, true ), $event->ID ); ?>
</td> </td>
<td>
<?php
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo '-';
endif;
?>
</td>
<?php } else { ?> <?php } else { ?>
<td> <td>
<?php <?php
@@ -185,9 +189,28 @@ class SP_Meta_Box_Calendar_Data {
?> ?>
</td> </td>
<?php } ?> <?php } ?>
<?php } ?>
<?php if ( ( ! is_array( $usecolumns ) || in_array( 'results', $usecolumns ) ) && in_array( $time_format, array( 'separate', 'results' ) ) ) { ?>
<td>
<?php
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
echo '-';
endif;
?>
</td>
<?php } ?>
<?php if ( ! is_array( $usecolumns ) || in_array( 'league', $usecolumns ) ) { ?>
<td><?php the_terms( $event->ID, 'sp_league' ); ?></td> <td><?php the_terms( $event->ID, 'sp_league' ); ?></td>
<?php } ?>
<?php if ( ! is_array( $usecolumns ) || in_array( 'season', $usecolumns ) ) { ?>
<td><?php the_terms( $event->ID, 'sp_season' ); ?></td> <td><?php the_terms( $event->ID, 'sp_season' ); ?></td>
<?php } ?>
<?php if ( ! is_array( $usecolumns ) || in_array( 'venue', $usecolumns ) ) { ?>
<td><?php the_terms( $event->ID, 'sp_venue' ); ?></td> <td><?php the_terms( $event->ID, 'sp_venue' ); ?></td>
<?php } ?>
<?php if ( ! is_array( $usecolumns ) || in_array( 'article', $usecolumns ) ) { ?>
<td> <td>
<a href="<?php echo get_edit_post_link( $event->ID ); ?>#sp_articlediv"> <a href="<?php echo get_edit_post_link( $event->ID ); ?>#sp_articlediv">
<?php if ( $video ): ?> <?php if ( $video ): ?>
@@ -206,6 +229,19 @@ class SP_Meta_Box_Calendar_Data {
?> ?>
</a> </a>
</td> </td>
<?php } ?>
<?php if ( ! is_array( $usecolumns ) || in_array( 'day', $usecolumns ) ) { ?>
<td>
<?php
$day = get_post_meta( $event->ID, 'sp_day', true );
if ( '' == $day ) {
echo '&mdash;';
} else {
echo $day;
}
?>
</td>
<?php } ?>
</tr> </tr>
<?php <?php
$i++; $i++;

View File

@@ -194,6 +194,13 @@ class SportsPress_Calendars {
'context' => 'side', 'context' => 'side',
'priority' => 'default', 'priority' => 'default',
), ),
'columns' => array(
'title' => __( 'Columns', 'sportspress' ),
'save' => 'SP_Meta_Box_Calendar_Columns::save',
'output' => 'SP_Meta_Box_Calendar_Columns::output',
'context' => 'side',
'priority' => 'default',
),
'details' => array( 'details' => array(
'title' => __( 'Details', 'sportspress' ), 'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Calendar_Details::save', 'save' => 'SP_Meta_Box_Calendar_Details::save',

View File

@@ -154,6 +154,9 @@ endif;
if ( sp_column_active( $usecolumns, 'article' ) ) if ( sp_column_active( $usecolumns, 'article' ) )
echo '<th class="data-article">' . __( 'Article', 'sportspress' ) . '</th>'; echo '<th class="data-article">' . __( 'Article', 'sportspress' ) . '</th>';
if ( sp_column_active( $usecolumns, 'day' ) )
echo '<th class="data-day">' . __( 'Match Day', 'sportspress' ) . '</th>';
?> ?>
</tr> </tr>
</thead> </thead>
@@ -390,6 +393,17 @@ endif;
echo '</td>'; echo '</td>';
endif; endif;
if ( sp_column_active( $usecolumns, 'day' ) ):
echo '<td class="data-day">';
$day = get_post_meta( $event->ID, 'sp_day', true );
if ( '' == $day ) {
echo '-';
} else {
echo $day;
}
echo '</td>';
endif;
echo '</tr>'; echo '</tr>';
$i++; $i++;