Add officials columns to event lists
This commit is contained in:
@@ -49,7 +49,7 @@ class SP_Meta_Box_Calendar_Data {
|
||||
<th class="column-date">
|
||||
<?php _e( 'Date', 'sportspress' ); ?>
|
||||
</th>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'event', $usecolumns ) ) { ?>
|
||||
<?php if ( is_array( $usecolumns ) && in_array( 'event', $usecolumns ) ) { ?>
|
||||
<th class="column-event">
|
||||
<label for="sp_columns_event">
|
||||
<?php
|
||||
@@ -64,7 +64,7 @@ class SP_Meta_Box_Calendar_Data {
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<?php if ( ( ! is_array( $usecolumns ) || in_array( 'time', $usecolumns ) ) && in_array( $time_format, array( 'combined', 'separate', 'time' ) ) ) { ?>
|
||||
<?php if ( ( is_array( $usecolumns ) && in_array( 'time', $usecolumns ) ) && in_array( $time_format, array( 'combined', 'separate', 'time' ) ) ) { ?>
|
||||
<th class="column-time">
|
||||
<label for="sp_columns_time">
|
||||
<?php
|
||||
@@ -77,48 +77,49 @@ class SP_Meta_Box_Calendar_Data {
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<?php if ( ( ! is_array( $usecolumns ) || in_array( 'results', $usecolumns ) ) && 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">
|
||||
<label for="sp_columns_results">
|
||||
<?php _e( 'Results', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'league', $usecolumns ) ) { ?>
|
||||
<?php if ( is_array( $usecolumns ) && in_array( 'league', $usecolumns ) ) { ?>
|
||||
<th class="column-league">
|
||||
<label for="sp_columns_league">
|
||||
<?php _e( 'League', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'season', $usecolumns ) ) { ?>
|
||||
<?php if ( is_array( $usecolumns ) && in_array( 'season', $usecolumns ) ) { ?>
|
||||
<th class="column-season">
|
||||
<label for="sp_columns_season">
|
||||
<?php _e( 'Season', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'venue', $usecolumns ) ) { ?>
|
||||
<?php if ( is_array( $usecolumns ) && in_array( 'venue', $usecolumns ) ) { ?>
|
||||
<th class="column-venue">
|
||||
<label for="sp_columns_venue">
|
||||
<?php _e( 'Venue', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'article', $usecolumns ) ) { ?>
|
||||
<?php if ( is_array( $usecolumns ) && in_array( 'article', $usecolumns ) ) { ?>
|
||||
<th class="column-article">
|
||||
<label for="sp_columns_article">
|
||||
<?php _e( 'Article', 'sportspress' ); ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'day', $usecolumns ) ) { ?>
|
||||
<?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 } ?>
|
||||
<?php do_action( 'sportspress_calendar_data_meta_box_table_head_row', $usecolumns ); ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -135,7 +136,7 @@ class SP_Meta_Box_Calendar_Data {
|
||||
?>
|
||||
<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>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'event', $usecolumns ) ) { ?>
|
||||
<?php if ( is_array( $usecolumns ) && in_array( 'event', $usecolumns ) ) { ?>
|
||||
<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-teams sp-title-format-homeaway<?php if ( ! in_array( $title_format, array( 'teams', 'homeaway' ) ) ): ?> hidden<?php endif; ?>">
|
||||
@@ -173,7 +174,7 @@ class SP_Meta_Box_Calendar_Data {
|
||||
</div>
|
||||
</td>
|
||||
<?php } ?>
|
||||
<?php if ( ( ! is_array( $usecolumns ) || in_array( 'time', $usecolumns ) ) && in_array( $time_format, array( 'combined', 'separate', 'time' ) ) ) { ?>
|
||||
<?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>
|
||||
<?php echo apply_filters( 'sportspress_event_time_admin', get_post_time( get_option( 'time_format' ), false, $event, true ), $event->ID ); ?>
|
||||
@@ -190,7 +191,7 @@ class SP_Meta_Box_Calendar_Data {
|
||||
</td>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
<?php if ( ( ! is_array( $usecolumns ) || in_array( 'results', $usecolumns ) ) && in_array( $time_format, array( 'separate', 'results' ) ) ) { ?>
|
||||
<?php if ( ( is_array( $usecolumns ) && in_array( 'results', $usecolumns ) ) && in_array( $time_format, array( 'separate', 'results' ) ) ) { ?>
|
||||
<td>
|
||||
<?php
|
||||
if ( ! empty( $main_results ) ):
|
||||
@@ -201,16 +202,16 @@ class SP_Meta_Box_Calendar_Data {
|
||||
?>
|
||||
</td>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'league', $usecolumns ) ) { ?>
|
||||
<?php if ( is_array( $usecolumns ) && in_array( 'league', $usecolumns ) ) { ?>
|
||||
<td><?php the_terms( $event->ID, 'sp_league' ); ?></td>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'season', $usecolumns ) ) { ?>
|
||||
<?php if ( is_array( $usecolumns ) && in_array( 'season', $usecolumns ) ) { ?>
|
||||
<td><?php the_terms( $event->ID, 'sp_season' ); ?></td>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'venue', $usecolumns ) ) { ?>
|
||||
<?php if ( is_array( $usecolumns ) && in_array( 'venue', $usecolumns ) ) { ?>
|
||||
<td><?php the_terms( $event->ID, 'sp_venue' ); ?></td>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'article', $usecolumns ) ) { ?>
|
||||
<?php if ( is_array( $usecolumns ) && in_array( 'article', $usecolumns ) ) { ?>
|
||||
<td>
|
||||
<a href="<?php echo get_edit_post_link( $event->ID ); ?>#sp_articlediv">
|
||||
<?php if ( $video ): ?>
|
||||
@@ -230,7 +231,7 @@ class SP_Meta_Box_Calendar_Data {
|
||||
</a>
|
||||
</td>
|
||||
<?php } ?>
|
||||
<?php if ( ! is_array( $usecolumns ) || in_array( 'day', $usecolumns ) ) { ?>
|
||||
<?php if ( is_array( $usecolumns ) && in_array( 'day', $usecolumns ) ) { ?>
|
||||
<td>
|
||||
<?php
|
||||
$day = get_post_meta( $event->ID, 'sp_day', true );
|
||||
@@ -242,6 +243,7 @@ class SP_Meta_Box_Calendar_Data {
|
||||
?>
|
||||
</td>
|
||||
<?php } ?>
|
||||
<?php do_action( 'sportspress_calendar_data_meta_box_table_row', $event, $usecolumns ); ?>
|
||||
</tr>
|
||||
<?php
|
||||
$i++;
|
||||
@@ -249,7 +251,7 @@ class SP_Meta_Box_Calendar_Data {
|
||||
else:
|
||||
?>
|
||||
<tr class="sp-row alternate">
|
||||
<td colspan="7">
|
||||
<td colspan="<?php echo sizeof( $usecolumns ); ?>">
|
||||
<?php _e( 'No results found.', 'sportspress' ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -258,7 +260,7 @@ class SP_Meta_Box_Calendar_Data {
|
||||
else:
|
||||
?>
|
||||
<tr class="sp-row alternate">
|
||||
<td colspan="7">
|
||||
<td colspan="<?php echo sizeof( $usecolumns ); ?>">
|
||||
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Details', 'sportspress' ) ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -542,11 +542,11 @@ class SP_Event extends SP_Custom_Post{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function appointments() {
|
||||
public function appointments( $include_empty = false, $placeholder = '-' ) {
|
||||
$officials = (array) get_post_meta( $this->ID, 'sp_officials', true );
|
||||
$officials = array_filter( $officials );
|
||||
|
||||
if ( empty( $officials ) ) return null;
|
||||
if ( ! $include_empty && empty( $officials ) ) return null;
|
||||
|
||||
$duties = get_terms( array(
|
||||
'taxonomy' => 'sp_duty',
|
||||
@@ -554,7 +554,7 @@ class SP_Event extends SP_Custom_Post{
|
||||
'orderby' => 'slug',
|
||||
) );
|
||||
|
||||
if ( empty( $duties ) ) return null;
|
||||
if ( ! $include_empty && empty( $duties ) ) return null;
|
||||
|
||||
$labels = array();
|
||||
$appointments = array();
|
||||
@@ -562,13 +562,15 @@ class SP_Event extends SP_Custom_Post{
|
||||
foreach ( $duties as $duty ) {
|
||||
$duty_appointments = sp_array_value( $officials, $duty->term_id, null );
|
||||
|
||||
if ( empty( $duty_appointments ) ) continue;
|
||||
if ( ! $include_empty && empty( $duty_appointments ) ) continue;
|
||||
|
||||
$appointed_officials = array();
|
||||
foreach ( $duty_appointments as $duty_appointment ) {
|
||||
$appointed_officials[ $duty_appointment ] = get_the_title( $duty_appointment );
|
||||
}
|
||||
|
||||
if ( $include_empty && empty( $appointed_officials ) ) $appointed_officials[] = $placeholder;
|
||||
|
||||
$appointments[ $duty->slug ] = $appointed_officials;
|
||||
$labels[ $duty->slug ] = $duty->name;
|
||||
}
|
||||
|
||||
@@ -35,9 +35,14 @@ class SportsPress_Officials {
|
||||
add_action( 'sportspress_include_post_type_handlers', array( $this, 'include_post_type_handler' ) );
|
||||
add_action( 'sportspress_create_rest_routes', array( $this, 'create_rest_routes' ) );
|
||||
add_action( 'sportspress_register_rest_fields', array( $this, 'register_rest_fields' ) );
|
||||
add_action( 'sportspress_event_list_head_row', array( $this, 'event_list_head_row' ) );
|
||||
add_action( 'sportspress_event_list_row', array( $this, 'event_list_row' ), 10, 2 );
|
||||
add_action( 'sportspress_calendar_data_meta_box_table_head_row', array( $this, 'calendar_meta_head_row' ) );
|
||||
add_action( 'sportspress_calendar_data_meta_box_table_row', array( $this, 'calendar_meta_row' ), 10, 2 );
|
||||
|
||||
// Filters
|
||||
add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) );
|
||||
add_filter( 'sportspress_calendar_columns', array( $this, 'calendar_columns' ) );
|
||||
add_filter( 'sportspress_after_event_template', array( $this, 'add_event_template' ), 30 );
|
||||
add_filter( 'sportspress_screen_ids', array( $this, 'screen_ids' ) );
|
||||
add_filter( 'sportspress_post_types', array( $this, 'add_post_type' ) );
|
||||
@@ -183,6 +188,92 @@ class SportsPress_Officials {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event list head row.
|
||||
*/
|
||||
public function event_list_head_row( $usecolumns = array() ) {
|
||||
if ( is_array( $usecolumns ) && in_array( 'officials', $usecolumns ) ) {
|
||||
$duties = get_terms( array(
|
||||
'taxonomy' => 'sp_duty',
|
||||
'hide_empty' => false,
|
||||
'orderby' => 'slug',
|
||||
) );
|
||||
|
||||
if ( empty( $duties ) ) return;
|
||||
|
||||
foreach ( $duties as $duty ) {
|
||||
?>
|
||||
<th class="data-officials">
|
||||
<?php echo $duty->name; ?>
|
||||
</th>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event list row.
|
||||
*/
|
||||
public function event_list_row( $event, $usecolumns = array() ) {
|
||||
if ( is_array( $usecolumns ) && in_array( 'officials', $usecolumns ) ) {
|
||||
$event = new SP_Event( $event );
|
||||
$appointments = $event->appointments( true );
|
||||
unset( $appointments[0] );
|
||||
|
||||
foreach ( $appointments as $officials ) {
|
||||
?>
|
||||
<td class="data-officials">
|
||||
<?php echo implode( '<br>', $officials ); ?>
|
||||
</td>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calendar meta box table head row.
|
||||
*/
|
||||
public function calendar_meta_head_row( $usecolumns = array() ) {
|
||||
if ( is_array( $usecolumns ) && in_array( 'officials', $usecolumns ) ) {
|
||||
$duties = get_terms( array(
|
||||
'taxonomy' => 'sp_duty',
|
||||
'hide_empty' => false,
|
||||
'orderby' => 'slug',
|
||||
) );
|
||||
|
||||
if ( empty( $duties ) ) return;
|
||||
|
||||
foreach ( $duties as $duty ) {
|
||||
?>
|
||||
<th class="column-officials">
|
||||
<label for="sp_columns_officials">
|
||||
<?php echo $duty->name; ?>
|
||||
</label>
|
||||
</th>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calendar meta box table row.
|
||||
*/
|
||||
public function calendar_meta_row( $event, $usecolumns = array() ) {
|
||||
if ( is_array( $usecolumns ) && in_array( 'officials', $usecolumns ) ) {
|
||||
$event = new SP_Event( $event );
|
||||
$appointments = $event->appointments( true, '—' );
|
||||
unset( $appointments[0] );
|
||||
|
||||
foreach ( $appointments as $officials ) {
|
||||
?>
|
||||
<td>
|
||||
<?php echo implode( '<br>', $officials ); ?>
|
||||
</td>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add meta boxes.
|
||||
*
|
||||
@@ -208,6 +299,16 @@ class SportsPress_Officials {
|
||||
return $meta_boxes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add calendar columns.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function calendar_columns( $columns = array() ) {
|
||||
$columns['officials'] = __( 'Officials', 'sportspress' );
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add settings.
|
||||
*
|
||||
|
||||
@@ -166,6 +166,8 @@ endif;
|
||||
|
||||
if ( sp_column_active( $usecolumns, 'day' ) )
|
||||
echo '<th class="data-day">' . __( 'Match Day', 'sportspress' ) . '</th>';
|
||||
|
||||
do_action( 'sportspress_event_list_head_row', $usecolumns );
|
||||
?>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -413,6 +415,8 @@ endif;
|
||||
echo '</td>';
|
||||
endif;
|
||||
|
||||
do_action( 'sportspress_event_list_row', $event, $usecolumns );
|
||||
|
||||
echo '</tr>';
|
||||
|
||||
$i++;
|
||||
|
||||
@@ -51,7 +51,7 @@ $link_officials = get_option( 'sportspress_link_officials', 'no' ) == 'yes' ? tr
|
||||
$appointed_officials[ $official_id ] = '<a href="' . get_post_permalink( $official_id ) . '">' . $official_name . '</a>';
|
||||
}
|
||||
}
|
||||
echo '<td class="data-name">' . implode( ', ', $appointed_officials ) . '</td>';
|
||||
echo '<td class="data-name">' . implode( '<br>', $appointed_officials ) . '</td>';
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user