Reorganize and add statistics post types

This commit is contained in:
ThemeBoy
2013-11-25 23:29:04 +11:00
parent 3d492f4d80
commit 7aeec083b8
24 changed files with 330 additions and 89 deletions

148
admin/post-types/event.php Normal file
View File

@@ -0,0 +1,148 @@
<?php
function sp_event_cpt_init() {
$name = __( 'Events', 'sportspress' );
$singular_name = __( 'Event', 'sportspress' );
$lowercase_name = __( 'events', 'sportspress' );
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name );
$args = array(
'label' => $name,
'labels' => $labels,
'public' => true,
'hierarchical' => false,
'supports' => array( 'title', 'author', 'comments' ),
'register_meta_box_cb' => 'sp_event_meta_init',
'rewrite' => array( 'slug' => 'event' ),
'menu_position' => 42
);
$args['labels']['menu_name'] = __( 'SportsPress', 'sportspress' );
register_post_type( 'sp_event', $args );
}
add_action( 'init', 'sp_event_cpt_init' );
function sp_event_display_scheduled( $posts ) {
global $wp_query, $wpdb;
if ( is_single() && $wp_query->post_count == 0 && isset( $wp_query->query_vars['sp_event'] )) {
$posts = $wpdb->get_results( $wp_query->request );
}
return $posts;
}
add_filter( 'the_posts', 'sp_event_display_scheduled' );
function sp_event_meta_init() {
remove_meta_box( 'submitdiv', 'sp_event', 'side' );
add_meta_box( 'submitdiv', __( 'Event', 'sportspress' ), 'post_submit_meta_box', 'sp_event', 'side', 'high' );
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_event_team_meta', 'sp_event', 'side', 'high' );
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_event_stats_meta', 'sp_event', 'normal', 'high' );
add_meta_box( 'sp_resultsdiv', __( 'Results', 'sportspress' ), 'sp_event_results_meta', 'sp_event', 'normal', 'high' );
add_meta_box( 'sp_articlediv', __( 'Article', 'sportspress' ), 'sp_event_article_meta', 'sp_event', 'normal', 'high' );
}
function sp_event_team_meta( $post ) {
$limit = get_option( 'sp_event_team_count' );
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
$players = (array)get_post_meta( $post->ID, 'sp_player', false );
for ( $i = 0; $i < $limit; $i++ ):
?>
<div>
<p class="sp-tab-select sp-title-generator">
<?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_team[]',
'class' => 'sportspress-pages',
'show_option_none' => sprintf( __( 'Select %s' ), 'Team' ),
'option_none_value' => 0,
'selected' => $teams[ $i ]
);
wp_dropdown_pages( $args );
?>
</p>
<ul id="sp_team-tabs" class="wp-tab-bar sp-tab-bar">
<li class="wp-tab-active"><a href="#sp_player-all"><?php _e( 'Players', 'sportspress' ); ?></a></li>
<li class="wp-tab"><a href="#sp_staff-all"><?php _e( 'Staff', 'sportspress' ); ?></a></li>
</ul>
<?php
sp_post_checklist( $post->ID, 'sp_player', 'block', 'sp_team', $i );
sp_post_checklist( $post->ID, 'sp_staff', 'none', 'sp_team', $i );
?>
</div>
<?php
endfor;
sp_post_adder( 'sp_team' );
sp_nonce();
}
function sp_event_article_meta( $post ) {
wp_editor( $post->post_content, 'content' );
}
function sp_event_results_meta( $post ) {
$limit = get_option( 'sp_event_team_count' );
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
$results = (array)get_post_meta( $post->ID, 'sp_results', true );
// Get results for all teams
$data = sp_array_combine( $teams, sp_array_value( $results, 0, array() ) );
// Get column names from settings
$stats_settings = get_option( 'sportspress_stats' );
$columns = sp_get_eos_keys( $stats_settings['event'] );
// Add first column label
array_unshift( $columns, __( 'Team', 'sportspress' ) );
?>
<div>
<?php sp_stats_table( $data, array(), 0, $columns, false, 'post', 'sp_results' ); ?>
</div>
<?php
}
function sp_event_stats_meta( $post ) {
$limit = get_option( 'sp_event_team_count' );
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
// Get column names from settings
$stats_settings = get_option( 'sportspress_stats' );
$columns = sp_get_eos_keys( $stats_settings['player'] );
// Add first column label
array_unshift( $columns, __( 'Player', 'sportspress' ) );
// Teams
foreach ( $teams as $key => $value ):
// Get results for players in the team
$players = sp_array_between( (array)get_post_meta( $post->ID, 'sp_player', false ), 0, $key );
$data = sp_array_combine( $players, sp_array_value( $stats, $value, array() ) );
?>
<div>
<p><strong><?php echo $value ? get_the_title( $value ) : sprintf( __( 'Select %s' ), 'Team' ); ?></strong></p>
<?php sp_stats_table( $data, array(), $value, $columns, true ); ?>
</div>
<?php
endforeach;
}
function sp_event_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Event', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_div' => __( 'Divisions', 'sportspress' ),
'sp_kickoff' => __( 'Kick-off', 'sportspress' )
);
return $columns;
}
add_filter( 'manage_edit-sp_event_columns', 'sp_event_edit_columns' );
function sp_event_edit_sortable_columns( $columns ) {
$columns['sp_kickoff'] = 'sp_kickoff';
return $columns;
}
add_filter( 'manage_edit-sp_event_sortable_columns', 'sp_event_edit_sortable_columns' );
?>

113
admin/post-types/list.php Normal file
View File

@@ -0,0 +1,113 @@
<?php
function sp_list_cpt_init() {
$name = __( 'Player Lists', 'sportspress' );
$singular_name = __( 'Player List', 'sportspress' );
$lowercase_name = __( 'player lists', 'sportspress' );
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name, true );
$args = array(
'label' => $name,
'labels' => $labels,
'public' => true,
'hierarchical' => false,
'supports' => array( 'title', 'author' ),
'register_meta_box_cb' => 'sp_list_meta_init',
'rewrite' => array( 'slug' => 'list' ),
'show_in_menu' => 'edit.php?post_type=sp_player'
);
register_post_type( 'sp_list', $args );
}
add_action( 'init', 'sp_list_cpt_init' );
function sp_list_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title' ),
'sp_player' => __( 'Players', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_div' => __( 'Divisions', 'sportspress' )
);
return $columns;
}
add_filter( 'manage_edit-sp_list_columns', 'sp_list_edit_columns' );
function sp_list_meta_init() {
add_meta_box( 'sp_playerdiv', __( 'Players', 'sportspress' ), 'sp_list_player_meta', 'sp_list', 'side', 'high' );
add_meta_box( 'sp_statsdiv', __( 'Player List', 'sportspress' ), 'sp_list_stats_meta', 'sp_list', 'normal', 'high' );
}
function sp_list_player_meta( $post ) {
$division_id = sp_get_the_term_id( $post->ID, 'sp_div', 0 );
$team_id = get_post_meta( $post->ID, 'sp_team', true );
?>
<div>
<p class="sp-tab-select">
<?php
$args = array(
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Divisions', 'sportspress' ) ),
'taxonomy' => 'sp_div',
'name' => 'sp_div',
'selected' => $division_id
);
sp_dropdown_taxonomies( $args );
?>
</p>
<p class="sp-tab-select">
<?php
$args = array(
'show_option_none' => sprintf( __( 'All %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'option_none_value' => '0',
'post_type' => 'sp_team',
'name' => 'sp_team',
'selected' => $team_id
);
wp_dropdown_pages( $args );
?>
</p>
<?php
sp_post_checklist( $post->ID, 'sp_player', 'block', 'sp_team' );
sp_post_adder( 'sp_player' );
?>
</div>
<?php
sp_nonce();
}
function sp_list_stats_meta( $post ) {
$players = (array)get_post_meta( $post->ID, 'sp_player', false );
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
$division_id = sp_get_the_term_id( $post->ID, 'sp_div', 0 );
$team_id = get_post_meta( $post->ID, 'sp_team', true );
$data = sp_array_combine( $players, sp_array_value( $stats, $division_id, array() ) );
// Generate array of placeholder values for each player
$placeholders = array();
foreach ( $players as $player ):
$args = array(
'post_type' => 'sp_event',
'meta_query' => array(
array(
'key' => 'sp_player',
'value' => $player
)
),
'tax_query' => array(
array(
'taxonomy' => 'sp_div',
'field' => 'id',
'terms' => $division_id
)
)
);
$placeholders[ $player ] = sp_get_stats_row( 'sp_player', $args, true );
endforeach;
// Get column names from settings
$stats_settings = get_option( 'sportspress_stats' );
$columns = sp_get_eos_keys( $stats_settings['player'] );
// Add first column label
array_unshift( $columns, __( 'Player', 'sportspress' ) );
sp_stats_table( $data, $placeholders, $division_id, $columns, false );
}
?>

View File

@@ -0,0 +1,24 @@
<?php
function sp_metric_cpt_init() {
$name = __( 'Metrics', 'sportspress' );
$singular_name = __( 'Metric', 'sportspress' );
$lowercase_name = __( 'metrics', 'sportspress' );
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name, true );
$args = array(
'label' => $name,
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => false,
'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ),
'register_meta_box_cb' => 'sp_metric_meta_init',
'rewrite' => array( 'slug' => 'metric' ),
'show_in_menu' => 'edit.php?post_type=sp_player'
);
register_post_type( 'sp_metric', $args );
}
add_action( 'init', 'sp_metric_cpt_init' );
function sp_metric_meta_init() {
}
?>

147
admin/post-types/player.php Normal file
View File

@@ -0,0 +1,147 @@
<?php
function sp_player_cpt_init() {
$name = __( 'Players', 'sportspress' );
$singular_name = __( 'Player', 'sportspress' );
$lowercase_name = __( 'players', 'sportspress' );
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name );
$args = array(
'label' => $name,
'labels' => $labels,
'public' => true,
'hierarchical' => false,
'supports' => array( 'title', 'author', 'thumbnail' ),
'register_meta_box_cb' => 'sp_player_meta_init',
'rewrite' => array( 'slug' => 'player' ),
'menu_position' => 44
);
register_post_type( 'sp_player', $args );
}
add_action( 'init', 'sp_player_cpt_init' );
function sp_player_meta_init() {
remove_meta_box( 'submitdiv', 'sp_player', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_player', 'side', 'high' );
remove_meta_box( 'postimagediv', 'sp_player', 'side' );
add_meta_box( 'postimagediv', __( 'Photo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_player', 'side', 'high' );
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_player_team_meta', 'sp_player', 'side', 'high' );
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_player_stats_meta', 'sp_player', 'normal', 'high' );
add_meta_box( 'sp_profilediv', __( 'Profile' ), 'sp_player_profile_meta', 'sp_player', 'normal', 'high' );
}
function sp_player_team_meta( $post ) {
sp_post_checklist( $post->ID, 'sp_team' );
sp_post_adder( 'sp_team' );
sp_nonce();
}
function sp_player_stats_meta( $post ) {
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
$divisions = (array)get_the_terms( $post->ID, 'sp_div' );
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
// Get column names from settings
$stats_settings = get_option( 'sportspress_stats' );
$columns = sp_get_eos_keys( $stats_settings['player'] );
// Add first column label
array_unshift( $columns, __( 'Division', 'sportspress' ) );
// Generate array of all division ids
$division_ids = array( 0 );
foreach ( $divisions as $key => $value ):
if ( is_object( $value ) && property_exists( $value, 'term_id' ) )
$division_ids[] = $value->term_id;
endforeach;
// Get all teams populated with overall stats where availabled
$data = sp_array_combine( $division_ids, sp_array_value( $stats, 0, array() ) );
// Generate array of placeholder values for each division
$placeholders = array();
foreach ( $division_ids as $division_id ):
$args = array(
'post_type' => 'sp_event',
'meta_query' => array(
array(
'key' => 'sp_player',
'value' => $post->ID
)
)
);
if ( $division_id ):
$args['tax_query'] = array(
array(
'taxonomy' => 'sp_div',
'field' => 'id',
'terms' => $division_id
)
);
endif;
$placeholders[ $division_id ] = sp_get_stats_row( 'sp_player', $args );
endforeach;
?>
<p><strong><?php _e( 'Overall', 'sportspress' ); ?></strong></p>
<?php
sp_stats_table( $data, $placeholders, 0, $columns, true, 'sp_div' );
// Divisions
foreach ( $teams as $team ):
if ( !$team ) continue;
// Get all divisions populated with stats where availabled
$data = sp_array_combine( $division_ids, sp_array_value( $stats, $team, array() ) );
// Generate array of placeholder values for each division
$placeholders = array();
foreach ( $division_ids as $division_id ):
$args = array(
'post_type' => 'sp_event',
'meta_query' => array(
array(
'key' => 'sp_player',
'value' => $post->ID
),
array(
'key' => 'sp_team',
'value' => $team
)
),
'tax_query' => array(
array(
'taxonomy' => 'sp_div',
'field' => 'id',
'terms' => $division_id
)
)
);
$placeholders[ $division_id ] = sp_get_stats_row( 'sp_player', $args );
endforeach;
?>
<p><strong><?php echo get_the_title( $team ); ?></strong></p>
<?php
sp_stats_table( $data, $placeholders, $team, $columns, true, 'sp_div' );
?>
<?php
endforeach;
}
function sp_player_profile_meta( $post ) {
wp_editor( $post->post_content, 'content' );
}
function sp_player_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Name', 'sportspress' ),
'sp_pos' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_div' => __( 'Divisions', 'sportspress' )
);
return $columns;
}
add_filter( 'manage_edit-sp_player_columns', 'sp_player_edit_columns' );
?>

View File

@@ -0,0 +1,50 @@
<?php
function sp_staff_cpt_init() {
$name = __( 'Staff', 'sportspress' );
$singular_name = __( 'Staff', 'sportspress' );
$lowercase_name = __( 'staff', 'sportspress' );
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name );
$args = array(
'label' => $name,
'labels' => $labels,
'public' => true,
'hierarchical' => false,
'supports' => array( 'title', 'author', 'thumbnail' ),
'register_meta_box_cb' => 'sp_staff_meta_init',
'rewrite' => array( 'slug' => 'staff' ),
'menu_position' => 45
);
register_post_type( 'sp_staff', $args );
}
add_action( 'init', 'sp_staff_cpt_init' );
function sp_staff_meta_init() {
remove_meta_box( 'submitdiv', 'sp_staff', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_staff', 'side', 'high' );
remove_meta_box( 'postimagediv', 'sp_staff', 'side' );
add_meta_box( 'postimagediv', __( 'Photo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_staff', 'side', 'high' );
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_staff_team_meta', 'sp_staff', 'side', 'high' );
add_meta_box( 'sp_profilediv', __( 'Profile' ), 'sp_staff_profile_meta', 'sp_staff', 'normal', 'high' );
}
function sp_staff_team_meta( $post ) {
sp_post_checklist( $post->ID, 'sp_team' );
sp_post_adder( 'sp_team' );
sp_nonce();
}
function sp_staff_profile_meta( $post ) {
wp_editor( $post->post_content, 'content' );
}
function sp_staff_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Name', 'sportspress' ),
'sp_pos' => __( 'Positions', 'sportspress' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_div' => __( 'Divisions', 'sportspress' ),
);
return $columns;
}
add_filter( 'manage_edit-sp_staff_columns', 'sp_staff_edit_columns' );
?>

100
admin/post-types/stat.php Normal file
View File

@@ -0,0 +1,100 @@
<?php
function sp_stat_cpt_init() {
$name = __( 'Statistics', 'sportspress' );
$singular_name = __( 'Statistic', 'sportspress' );
$lowercase_name = __( 'statistics', 'sportspress' );
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name, true );
$args = array(
'label' => $name,
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => false,
'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ),
'register_meta_box_cb' => 'sp_stat_meta_init',
'rewrite' => array( 'slug' => 'stat' ),
'show_in_menu' => 'edit.php?post_type=sp_team'
);
register_post_type( 'sp_stat', $args );
}
add_action( 'init', 'sp_stat_cpt_init' );
function sp_stat_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_sport' => __( 'Sport', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
);
return $columns;
}
add_filter( 'manage_edit-sp_stat_columns', 'sp_stat_edit_columns' );
function sp_stat_meta_init() {
add_meta_box( 'sp_equationdiv', __( 'Equation', 'sportspress' ), 'sp_stat_equation_meta', 'sp_stat', 'normal', 'high' );
}
function sp_stat_equation_meta( $post ) {
$args = array(
'post_type' => 'sp_stat',
'numberposts' => -1,
'posts_per_page' => -1,
'exclude' => $post->ID
);
$sports = get_the_terms( $post->ID, 'sp_sport' );
if ( ! empty( $sports ) ):
$terms = array();
foreach ( $sports as $sport ):
$terms[] = $sport->slug;
endforeach;
$args['tax_query'] = array(
array(
'taxonomy' => 'sp_sport',
'field' => 'slug',
'terms' => $terms
)
);
endif;
$stats = get_posts( $args );
?>
<div>
<p class="sp-equation-selector">
<select data-remove-text="<?php _e( 'Remove', 'sportspress' ); ?>">
<option value=""><?php _e( 'Select', 'sportspress' ); ?></option>
<optgroup label="<?php _e( 'Events', 'sportspress' ); ?>">
<option value="wins"><?php _e( 'Wins', 'sportspress' ); ?></option>
<option value="draws"><?php _e( 'Draws', 'sportspress' ); ?></option>
<option value="ties"><?php _e( 'Ties', 'sportspress' ); ?></option>
<option value="losses"><?php _e( 'Losses', 'sportspress' ); ?></option>
</optgroup>
<optgroup label="<?php _e( 'Statistics', 'sportspress' ); ?>">
<?php foreach ( $stats as $stat ): ?>
<option value="<?php echo $stat->post_name; ?>"><?php echo $stat->post_title; ?></option>
<?php endforeach; ?>
</optgroup>
<optgroup label="<?php _e( 'Operators', 'sportspress' ); ?>">
<option value="+">&plus;</option>
<option value="-">&minus;</option>
<option value="X">&times;</option>
<option value="/">&divide;</option>
<option value="(">(</option>
<option value=")">)</option>
</optgroup>
<optgroup label="<?php _e( 'Constants', 'sportspress' ); ?>">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</optgroup>
</select>
</p>
</div>
<?php
}
?>

View File

@@ -0,0 +1,98 @@
<?php
function sp_table_cpt_init() {
$name = __( 'League Tables', 'sportspress' );
$singular_name = __( 'League Table', 'sportspress' );
$lowercase_name = __( 'league tables', 'sportspress' );
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name, true );
$args = array(
'label' => $name,
'labels' => $labels,
'public' => true,
'hierarchical' => false,
'supports' => array( 'title', 'author' ),
'register_meta_box_cb' => 'sp_table_meta_init',
'rewrite' => array( 'slug' => 'table' ),
'show_in_menu' => 'edit.php?post_type=sp_team'
);
register_post_type( 'sp_table', $args );
}
add_action( 'init', 'sp_table_cpt_init' );
function sp_table_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Title' ),
'sp_team' => __( 'Teams', 'sportspress' ),
'sp_div' => __( 'Divisions', 'sportspress' ),
);
return $columns;
}
add_filter( 'manage_edit-sp_table_columns', 'sp_table_edit_columns' );
function sp_table_meta_init() {
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_table_team_meta', 'sp_table', 'side', 'high' );
add_meta_box( 'sp_statsdiv', __( 'League Table', 'sportspress' ), 'sp_table_stats_meta', 'sp_table', 'normal', 'high' );
}
function sp_table_team_meta( $post ) {
$division_id = sp_get_the_term_id( $post->ID, 'sp_div', 0 );
?>
<div>
<p class="sp-tab-select">
<?php
$args = array(
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Divisions', 'sportspress' ) ),
'taxonomy' => 'sp_div',
'name' => 'sp_div',
'selected' => $division_id
);
sp_dropdown_taxonomies( $args );
?>
</p>
<?php
sp_post_checklist( $post->ID, 'sp_team', 'block', 'sp_div' );
sp_post_adder( 'sp_team' );
?>
</div>
<?php
sp_nonce();
}
function sp_table_stats_meta( $post ) {
$teams = (array)get_post_meta( $post->ID, 'sp_team', false );
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
$division_id = sp_get_the_term_id( $post->ID, 'sp_div', 0 );
$data = sp_array_combine( $teams, sp_array_value( $stats, $division_id, array() ) );
// Generate array of placeholder values for each team
$placeholders = array();
foreach ( $teams as $team ):
$args = array(
'post_type' => 'sp_event',
'meta_query' => array(
array(
'key' => 'sp_team',
'value' => $team
)
),
'tax_query' => array(
array(
'taxonomy' => 'sp_div',
'field' => 'id',
'terms' => $division_id
)
)
);
$placeholders[ $team ] = sp_get_stats_row( 'sp_team', $args, true );
endforeach;
// Get column names from settings
$stats_settings = get_option( 'sportspress_stats' );
$columns = sp_get_eos_keys( $stats_settings['team'] );
// Add first column label
array_unshift( $columns, __( 'Team', 'sportspress' ) );
sp_stats_table( $data, $placeholders, $division_id, $columns, false );
}
?>

86
admin/post-types/team.php Normal file
View File

@@ -0,0 +1,86 @@
<?php
function sp_team_cpt_init() {
$name = __( 'Teams', 'sportspress' );
$singular_name = __( 'Team', 'sportspress' );
$lowercase_name = __( 'teams', 'sportspress' );
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name );
$args = array(
'label' => $name,
'labels' => $labels,
'public' => true,
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
'register_meta_box_cb' => 'sp_team_meta_init',
'rewrite' => array( 'slug' => 'team' ),
'menu_position' => 43
);
register_post_type( 'sp_team', $args );
}
add_action( 'init', 'sp_team_cpt_init' );
function sp_team_meta_init() {
remove_meta_box( 'submitdiv', 'sp_team', 'side' );
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_team', 'side', 'high' );
remove_meta_box( 'postimagediv', 'sp_team', 'side' );
add_meta_box( 'postimagediv', __( 'Logo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_team', 'side', 'high' );
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_team_stats_meta', 'sp_team', 'normal', 'high' );
}
function sp_team_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'sp_logo' => '&nbsp;',
'title' => __( 'Team', 'sportspress' ),
'sp_div' => __( 'Divisions', 'sportspress' )
);
return $columns;
}
add_filter( 'manage_edit-sp_team_columns', 'sp_team_edit_columns' );
function sp_team_stats_meta( $post ) {
$divisions = (array)get_the_terms( $post->ID, 'sp_div' );
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
// Generate array of all division ids
$division_ids = array( 0 );
foreach ( $divisions as $key => $value ):
if ( is_object( $value ) && property_exists( $value, 'term_id' ) )
$division_ids[] = $value->term_id;
endforeach;
// Get all divisions populated with stats where available
$data = sp_array_combine( $division_ids, sp_array_value( $stats, 0, array() ) );
// Generate array of placeholder values for each division
$placeholders = array();
foreach ( $division_ids as $division_id ):
$args = array(
'post_type' => 'sp_event',
'meta_query' => array(
array(
'key' => 'sp_team',
'value' => $post->ID
)
),
'tax_query' => array(
array(
'taxonomy' => 'sp_div',
'field' => 'id',
'terms' => $division_id
)
)
);
$placeholders[ $division_id ] = sp_get_stats_row( 'sp_team', $args );
endforeach;
// Get column names from settings
$stats_settings = get_option( 'sportspress_stats' );
$columns = sp_get_eos_keys( $stats_settings['team'] );
// Add first column label
array_unshift( $columns, __( 'Division', 'sportspress' ) );
sp_stats_table( $data, $placeholders, 0, $columns, false, 'sp_div' );
sp_nonce();
}
?>