Refactor officials as custom post type

This commit is contained in:
Brian Miyaji
2017-11-01 16:44:28 +11:00
parent 80cdb3c228
commit 70dd825ba7
14 changed files with 1020 additions and 120 deletions

View File

@@ -0,0 +1,70 @@
<?php
/**
* Event Officials
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 1.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! isset( $id ) )
$id = get_the_ID();
$officials = (array) get_post_meta( $id, 'sp_officials', true );
$officials = array_filter( $officials );
if ( empty( $officials ) ) return;
$duties = get_terms( array(
'taxonomy' => 'sp_duty',
'hide_empty' => false,
) );
if ( empty( $duties ) ) return;
$scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false;
$link_officials = get_option( 'sportspress_link_officials', 'no' ) == 'yes' ? true : false;
$rows = '';
$i = 0;
foreach ( $duties as $duty ) {
$officials_on_duty = sp_array_value( $officials, $duty->term_id, array() );
if ( empty( $officials_on_duty ) ) continue;
foreach ( $officials_on_duty as $official ) {
$rows .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$name = get_the_title( $official );
if ( $link_officials && sp_post_exists( $official ) ) {
$name = '<a href="' . get_post_permalink( $official ) . '">' . $name . '</a>';
}
$rows .= '<th class="data-name">' . $name . '</th>';
$rows .= '<td class="data-duty">' . $duty->name . '</td>';
$rows .= '</tr>';
$i++;
}
}
if ( empty( $rows ) ) return;
?>
<div class="sp-template sp-template-event-officials">
<h4 class="sp-table-caption"><?php _e( 'Officials', 'sportspress' ); ?></h4>
<div class="sp-table-wrapper">
<table class="sp-event-officials sp-data-table<?php echo $scrollable ? ' sp-scrollable-table' : ''; ?>">
<tbody>
<?php echo $rows; ?>
</tbody>
</table>
</div>
</div>

View File

@@ -115,36 +115,3 @@ endif;
<div class="sp-template sp-template-event-results">
<?php echo $output; ?>
</div>
<?php
$officials = get_the_terms( $post->ID, 'sp_officials' );
$official_ids = array();
if ( $officials ):
foreach ( $officials as $official ):
$official_ids[] = $official->term_id;
endforeach;
endif;
if(sizeof($official_ids) > 0 ){
?>
<h4 class="sp-table-caption">Umpires</h4>
<div class="sp-template sp-template-event-results">
<?php
$i=0;
echo '<table class="sp-event-results sp-data-table sp-scrollable-table">';
echo '<thead><th class="data-name"></th></thead>';
echo '<tbody>';
foreach($officials as $official) {
echo '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
echo '<td class="data-name">' . $official->name . '</td>';
echo '</tr>';
$i++;
}
echo '</tbody>';
echo '</table>';
?>
</div>
<?php
}
?>
</div>

View File

@@ -0,0 +1,137 @@
<?php
/**
* Official Details
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 2.5
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( get_option( 'sportspress_official_show_details', 'yes' ) === 'no' ) return;
if ( ! isset( $id ) )
$id = get_the_ID();
$defaults = array(
'show_number' => get_option( 'sportspress_official_show_number', 'no' ) == 'yes' ? true : false,
'show_name' => get_option( 'sportspress_official_show_name', 'no' ) == 'yes' ? true : false,
'show_nationality' => get_option( 'sportspress_official_show_nationality', 'yes' ) == 'yes' ? true : false,
'show_positions' => get_option( 'sportspress_official_show_positions', 'yes' ) == 'yes' ? true : false,
'show_current_teams' => get_option( 'sportspress_official_show_current_teams', 'yes' ) == 'yes' ? true : false,
'show_past_teams' => get_option( 'sportspress_official_show_past_teams', 'yes' ) == 'yes' ? true : false,
'show_leagues' => get_option( 'sportspress_official_show_leagues', 'no' ) == 'yes' ? true : false,
'show_seasons' => get_option( 'sportspress_official_show_seasons', 'no' ) == 'yes' ? true : false,
'show_nationality_flags' => get_option( 'sportspress_official_show_flags', 'yes' ) == 'yes' ? true : false,
'abbreviate_teams' => get_option( 'sportspress_abbreviate_teams', 'yes' ) === 'yes' ? true : false,
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
);
extract( $defaults, EXTR_SKIP );
$countries = SP()->countries->countries;
$official = new SP_Official( $id );
$metrics_before = $official->metrics( true );
$metrics_after = $official->metrics( false );
$common = array();
if ( $show_number ):
$common[ '#' ] = $official->number;
endif;
if ( $show_name ):
$common[ __( 'Name', 'sportspress' ) ] = $official->post->post_title;
endif;
if ( $show_nationality ):
$nationalities = $official->nationalities();
if ( $nationalities && is_array( $nationalities ) ):
$values = array();
foreach ( $nationalities as $nationality ):
$country_name = sp_array_value( $countries, $nationality, null );
$values[] = $country_name ? ( $show_nationality_flags ? '<img src="' . plugin_dir_url( SP_PLUGIN_FILE ) . 'assets/images/flags/' . strtolower( $nationality ) . '.png" alt="' . $nationality . '"> ' : '' ) . $country_name : '&mdash;';
endforeach;
$common[ __( 'Nationality', 'sportspress' ) ] = implode( '<br>', $values );
endif;
endif;
if ( $show_positions ):
$positions = $official->positions();
if ( $positions && is_array( $positions ) ):
$position_names = array();
foreach ( $positions as $position ):
$position_names[] = $position->name;
endforeach;
$common[ __( 'Position', 'sportspress' ) ] = implode( ', ', $position_names );
endif;
endif;
$data = array_merge( $metrics_before, $common, $metrics_after );
if ( $show_current_teams ):
$current_teams = $official->current_teams();
if ( $current_teams ):
$teams = array();
foreach ( $current_teams as $team ):
$team_name = sp_get_team_name( $team, $abbreviate_teams );
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
$teams[] = $team_name;
endforeach;
$data[ __( 'Current Team', 'sportspress' ) ] = implode( ', ', $teams );
endif;
endif;
if ( $show_past_teams ):
$past_teams = $official->past_teams();
if ( $past_teams ):
$teams = array();
foreach ( $past_teams as $team ):
$team_name = sp_get_team_name( $team, $abbreviate_teams );
if ( $link_teams ) $team_name = '<a href="' . get_post_permalink( $team ) . '">' . $team_name . '</a>';
$teams[] = $team_name;
endforeach;
$data[ __( 'Past Teams', 'sportspress' ) ] = implode( ', ', $teams );
endif;
endif;
if ( $show_leagues ):
$leagues = $official->leagues();
if ( $leagues && ! is_wp_error( $leagues ) ):
$terms = array();
foreach ( $leagues as $league ) {
$terms[] = $league->name;
}
$data[ __( 'Competitions', 'sportspress' ) ] = implode( ', ', $terms );
endif;
endif;
if ( $show_seasons ):
$seasons = $official->seasons();
if ( $seasons && ! is_wp_error( $seasons ) ):
$terms = array();
foreach ( $seasons as $season ) {
$terms[] = $season->name;
}
$data[ __( 'Seasons', 'sportspress' ) ] = implode( ', ', $terms );
endif;
endif;
$data = apply_filters( 'sportspress_official_details', $data, $id );
if ( empty( $data ) )
return;
$output = '<div class="sp-template sp-template-official-details sp-template-details"><div class="sp-list-wrapper"><dl class="sp-official-details">';
foreach( $data as $label => $value ):
$output .= '<dt>' . $label . '</dt><dd>' . $value . '</dd>';
endforeach;
$output .= '</dl></div></div>';
echo $output;