Add ability to display player statistics by category

This commit is contained in:
Brian Miyaji
2016-03-31 01:52:21 +11:00
parent 29b4460040
commit 3547303c6f
9 changed files with 317 additions and 130 deletions

View File

@@ -132,9 +132,15 @@ class SP_Admin_Taxonomies {
public function add_position_fields() {
?>
<div class="form-field">
<label for="term_meta[sp_caption]"><?php _e( 'Heading', 'sportspress' ); ?></label>
<input type="text" name="term_meta[sp_caption]" id="term_meta[sp_caption]" value="">
<p class="description"><?php _e( 'Used for events.', 'sportspress' ); ?></p>
<label><?php _e( 'Statistics', 'sportspress' ); ?></label>
<select name="term_meta[sp_sections][]" id="term_meta[sp_sections][]" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple">
<?php
$options = apply_filters( 'sportspress_performance_sections', array( 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
printf( '<option value="%s" %s>%s</option>', $key, selected( true ), $value );
endforeach;
?>
</select>
</div>
<?php
}
@@ -147,14 +153,24 @@ class SP_Admin_Taxonomies {
*/
public function edit_position_fields( $term ) {
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" ); ?>
$sections = sp_get_term_sections( $t_id );
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[sp_caption]"><?php _e( 'Heading', 'sportspress' ); ?></label></th>
<th scope="row" valign="top"><label for="term_meta[sp_sections]"><?php _e( 'Statistics', 'sportspress' ); ?></label></th>
<input type="hidden" name="term_meta[sp_sections]" value="">
<td>
<input type="text" name="term_meta[sp_caption]" id="term_meta[sp_caption]" value="<?php echo esc_attr( $term_meta['sp_caption'] ) ? esc_attr( $term_meta['sp_caption'] ) : ''; ?>">
<p class="description"><?php _e( 'Used for events.', 'sportspress' ); ?></p>
<select name="term_meta[sp_sections][]" id="term_meta[sp_sections][]" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple">
<?php
$options = apply_filters( 'sportspress_performance_sections', array( 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
foreach ( $options as $key => $value ):
printf( '<option value="%s" %s>%s</option>', $key, selected( in_array( $key, $sections ), true, false ), $value );
endforeach;
?>
</select>
</td>
</tr>
</div>
<?php
}
@@ -219,7 +235,7 @@ class SP_Admin_Taxonomies {
*/
public function position_columns( $columns ) {
$new_columns = array();
$new_columns['sp_caption'] = __( 'Heading', 'sportspress' );
$new_columns['sp_sections'] = __( 'Statistics', 'sportspress' );
$new_columns['posts'] = __( 'Players', 'sportspress' );
unset( $columns['description'] );
@@ -260,13 +276,23 @@ class SP_Admin_Taxonomies {
$columns .= $address;
} elseif ( $column == 'sp_caption' ) {
} elseif ( $column == 'sp_sections' ) {
$options = apply_filters( 'sportspress_performance_sections', array( 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
$term_meta = get_option( "taxonomy_$id" );
$caption = ( isset( $term_meta['sp_caption'] ) ? $term_meta['sp_caption'] : '&mdash;' );
$columns .= $caption;
$sections = sp_get_term_sections( $id );
$section_names = array();
if ( is_array( $sections ) ) {
foreach ( $sections as $section ) {
if ( array_key_exists( $section, $options ) ) {
$section_names[] = $options[ $section ];
}
}
}
$columns .= implode( ', ', $section_names );
}

View File

@@ -22,24 +22,63 @@ class SP_Meta_Box_Player_Statistics {
$player = new SP_Player( $post );
$leagues = get_the_terms( $post->ID, 'sp_league' );
$league_num = sizeof( $leagues );
$sections = get_option( 'sportspress_player_performance_sections', -1 );
// Loop through statistics for each league
if ( $leagues ):
$i = 0;
foreach ( $leagues as $league ):
if ( $leagues ) {
if ( -1 == $sections ) {
// Loop through statistics for each league
$i = 0;
foreach ( $leagues as $league ):
?>
<p><strong><?php echo $league->name; ?></strong></p>
<?php
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true );
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0 );
$i ++;
endforeach;
?>
<p><strong><?php echo $league->name; ?></strong></p>
<p><strong><?php _e( 'Career Total', 'sportspress' ); ?></strong></p>
<?php
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true );
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0 );
$i ++;
endforeach;
endif;
?>
<p><strong><?php _e( 'Career Total', 'sportspress' ); ?></strong></p>
<?php
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( 0, true );
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams );
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( 0, true );
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams );
} else {
// Determine order of sections
if ( 1 == $sections ) {
$section_order = array( 1 => __( 'Defense', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ) );
} else {
$section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) );
}
// Get labels by section
$args = array(
'post_type' => 'sp_performance',
'numberposts' => 100,
'posts_per_page' => 100,
'orderby' => 'menu_order',
'order' => 'ASC',
);
$columns = get_posts( $args );
foreach ( $section_order as $section_id => $section_label ) {
// Loop through statistics for each league
$i = 0;
foreach ( $leagues as $league ):
?>
<p><strong><?php echo $league->name; ?> &mdash; <?php echo $section_label; ?></strong></p>
<?php
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true, $section_id );
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0 );
$i ++;
endforeach;
?>
<p><strong><?php _e( 'Career Total', 'sportspress' ); ?> &mdash; <?php echo $section_label; ?></strong></p>
<?php
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( 0, true, $section_id );
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams );
}
}
}
}
/**

View File

@@ -125,6 +125,18 @@ class SP_Settings_Players extends SP_Settings_Page {
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Statistics', 'sportspress' ),
'id' => 'sportspress_player_performance_sections',
'default' => -1,
'type' => 'radio',
'options' => array(
-1 => __( 'Combined', 'sportspress' ),
0 => __( 'Offense', 'sportspress' ) . ' &rarr; ' . __( 'Defense', 'sportspress' ),
1 => __( 'Defense', 'sportspress' ) . ' &rarr; ' . __( 'Offense', 'sportspress' ),
),
),
array(
'title' => __( 'Nationality', 'sportspress' ),
'desc' => __( 'Display national flags', 'sportspress' ),

View File

@@ -347,6 +347,7 @@
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Equation', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Decimal Places', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Category', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Description', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
@@ -356,6 +357,7 @@
<td class="row-title"><?php echo $row->post_title; ?></td>
<td><?php echo sp_get_post_equation( $row->ID ); ?></td>
<td><?php echo sp_get_post_precision( $row->ID ); ?></td>
<td><?php echo sp_get_post_section( $row->ID ); ?></td>
<td><p class="description"><?php echo $row->post_excerpt; ?></p></td>
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
</tr>