Add ability to display player statistics by category
This commit is contained in:
@@ -132,9 +132,15 @@ class SP_Admin_Taxonomies {
|
|||||||
public function add_position_fields() {
|
public function add_position_fields() {
|
||||||
?>
|
?>
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<label for="term_meta[sp_caption]"><?php _e( 'Heading', 'sportspress' ); ?></label>
|
<label><?php _e( 'Statistics', 'sportspress' ); ?></label>
|
||||||
<input type="text" name="term_meta[sp_caption]" id="term_meta[sp_caption]" value="">
|
<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">
|
||||||
<p class="description"><?php _e( 'Used for events.', 'sportspress' ); ?></p>
|
<?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>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
@@ -147,14 +153,24 @@ class SP_Admin_Taxonomies {
|
|||||||
*/
|
*/
|
||||||
public function edit_position_fields( $term ) {
|
public function edit_position_fields( $term ) {
|
||||||
$t_id = $term->term_id;
|
$t_id = $term->term_id;
|
||||||
$term_meta = get_option( "taxonomy_$t_id" ); ?>
|
$sections = sp_get_term_sections( $t_id );
|
||||||
|
?>
|
||||||
<tr class="form-field">
|
<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>
|
<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'] ) : ''; ?>">
|
<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">
|
||||||
<p class="description"><?php _e( 'Used for events.', 'sportspress' ); ?></p>
|
<?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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,7 +235,7 @@ class SP_Admin_Taxonomies {
|
|||||||
*/
|
*/
|
||||||
public function position_columns( $columns ) {
|
public function position_columns( $columns ) {
|
||||||
$new_columns = array();
|
$new_columns = array();
|
||||||
$new_columns['sp_caption'] = __( 'Heading', 'sportspress' );
|
$new_columns['sp_sections'] = __( 'Statistics', 'sportspress' );
|
||||||
$new_columns['posts'] = __( 'Players', 'sportspress' );
|
$new_columns['posts'] = __( 'Players', 'sportspress' );
|
||||||
|
|
||||||
unset( $columns['description'] );
|
unset( $columns['description'] );
|
||||||
@@ -260,13 +276,23 @@ class SP_Admin_Taxonomies {
|
|||||||
|
|
||||||
$columns .= $address;
|
$columns .= $address;
|
||||||
|
|
||||||
} elseif ( $column == 'sp_caption' ) {
|
} elseif ( $column == 'sp_sections' ) {
|
||||||
|
|
||||||
$term_meta = get_option( "taxonomy_$id" );
|
$options = apply_filters( 'sportspress_performance_sections', array( 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
|
||||||
|
|
||||||
$caption = ( isset( $term_meta['sp_caption'] ) ? $term_meta['sp_caption'] : '—' );
|
$sections = sp_get_term_sections( $id );
|
||||||
|
|
||||||
$columns .= $caption;
|
$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 );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,24 +22,63 @@ class SP_Meta_Box_Player_Statistics {
|
|||||||
$player = new SP_Player( $post );
|
$player = new SP_Player( $post );
|
||||||
$leagues = get_the_terms( $post->ID, 'sp_league' );
|
$leagues = get_the_terms( $post->ID, 'sp_league' );
|
||||||
$league_num = sizeof( $leagues );
|
$league_num = sizeof( $leagues );
|
||||||
|
$sections = get_option( 'sportspress_player_performance_sections', -1 );
|
||||||
|
|
||||||
// Loop through statistics for each league
|
if ( $leagues ) {
|
||||||
if ( $leagues ):
|
if ( -1 == $sections ) {
|
||||||
$i = 0;
|
// Loop through statistics for each league
|
||||||
foreach ( $leagues as $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
|
<?php
|
||||||
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true );
|
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( 0, true );
|
||||||
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, $i == 0 );
|
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams );
|
||||||
$i ++;
|
} else {
|
||||||
endforeach;
|
// Determine order of sections
|
||||||
endif;
|
if ( 1 == $sections ) {
|
||||||
?>
|
$section_order = array( 1 => __( 'Defense', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ) );
|
||||||
<p><strong><?php _e( 'Career Total', 'sportspress' ); ?></strong></p>
|
} else {
|
||||||
<?php
|
$section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) );
|
||||||
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( 0, true );
|
}
|
||||||
self::table( $post->ID, 0, $columns, $data, $placeholders, $merged, $seasons_teams );
|
|
||||||
|
// 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; ?> — <?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' ); ?> — <?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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -125,6 +125,18 @@ class SP_Settings_Players extends SP_Settings_Page {
|
|||||||
'checkboxgroup' => 'end',
|
'checkboxgroup' => 'end',
|
||||||
),
|
),
|
||||||
|
|
||||||
|
array(
|
||||||
|
'title' => __( 'Statistics', 'sportspress' ),
|
||||||
|
'id' => 'sportspress_player_performance_sections',
|
||||||
|
'default' => -1,
|
||||||
|
'type' => 'radio',
|
||||||
|
'options' => array(
|
||||||
|
-1 => __( 'Combined', 'sportspress' ),
|
||||||
|
0 => __( 'Offense', 'sportspress' ) . ' → ' . __( 'Defense', 'sportspress' ),
|
||||||
|
1 => __( 'Defense', 'sportspress' ) . ' → ' . __( 'Offense', 'sportspress' ),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
array(
|
array(
|
||||||
'title' => __( 'Nationality', 'sportspress' ),
|
'title' => __( 'Nationality', 'sportspress' ),
|
||||||
'desc' => __( 'Display national flags', 'sportspress' ),
|
'desc' => __( 'Display national flags', 'sportspress' ),
|
||||||
|
|||||||
@@ -347,6 +347,7 @@
|
|||||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||||
<th scope="col"><?php _e( 'Equation', 'sportspress' ); ?></th>
|
<th scope="col"><?php _e( 'Equation', 'sportspress' ); ?></th>
|
||||||
<th scope="col"><?php _e( 'Decimal Places', '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"><?php _e( 'Description', 'sportspress' ); ?></th>
|
||||||
<th scope="col" class="edit"></th>
|
<th scope="col" class="edit"></th>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -356,6 +357,7 @@
|
|||||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
<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_equation( $row->ID ); ?></td>
|
||||||
<td><?php echo sp_get_post_precision( $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><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>
|
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
* @param bool $admin
|
* @param bool $admin
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function data( $league_id, $admin = false ) {
|
public function data( $league_id, $admin = false, $section = -1 ) {
|
||||||
|
|
||||||
$seasons = (array)get_the_terms( $this->ID, 'sp_season' );
|
$seasons = (array)get_the_terms( $this->ID, 'sp_season' );
|
||||||
$metrics = (array)get_post_meta( $this->ID, 'sp_metrics', true );
|
$metrics = (array)get_post_meta( $this->ID, 'sp_metrics', true );
|
||||||
@@ -117,8 +117,35 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
$leagues = sp_array_value( (array)get_post_meta( $this->ID, 'sp_leagues', true ), $league_id, array() );
|
$leagues = sp_array_value( (array)get_post_meta( $this->ID, 'sp_leagues', true ), $league_id, array() );
|
||||||
$usecolumns = get_post_meta( $this->ID, 'sp_columns', true );
|
$usecolumns = get_post_meta( $this->ID, 'sp_columns', true );
|
||||||
|
|
||||||
// Get labels from performance variables
|
// Get labels by section
|
||||||
$performance_labels = (array)sp_get_var_labels( 'sp_performance' );
|
$args = array(
|
||||||
|
'post_type' => 'sp_performance',
|
||||||
|
'numberposts' => 100,
|
||||||
|
'posts_per_page' => 100,
|
||||||
|
'orderby' => 'menu_order',
|
||||||
|
'order' => 'ASC',
|
||||||
|
);
|
||||||
|
|
||||||
|
$posts = get_posts( $args );
|
||||||
|
|
||||||
|
$performance_labels = array();
|
||||||
|
|
||||||
|
foreach ( $posts as $post ):
|
||||||
|
if ( -1 === $section ) {
|
||||||
|
$performance_labels[ $post->post_name ] = $post->post_title;
|
||||||
|
} else {
|
||||||
|
$post_section = get_post_meta( $post->ID, 'sp_section', true );
|
||||||
|
|
||||||
|
if ( '' === $post_section ) {
|
||||||
|
$post_section = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $section == $post_section || -1 == $post_section ) {
|
||||||
|
$performance_labels[ $post->post_name ] = $post->post_title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endforeach;
|
||||||
|
|
||||||
// Get labels from outcome variables
|
// Get labels from outcome variables
|
||||||
$outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
|
$outcome_labels = (array)sp_get_var_labels( 'sp_outcome' );
|
||||||
@@ -404,8 +431,44 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
// Get stats from statistic variables
|
// Get labels by section
|
||||||
$stats = sp_get_var_labels( 'sp_statistic' );
|
$args = array(
|
||||||
|
'post_type' => 'sp_statistic',
|
||||||
|
'numberposts' => 100,
|
||||||
|
'posts_per_page' => 100,
|
||||||
|
'orderby' => 'menu_order',
|
||||||
|
'order' => 'ASC',
|
||||||
|
);
|
||||||
|
|
||||||
|
$posts = get_posts( $args );
|
||||||
|
|
||||||
|
$stats = array();
|
||||||
|
|
||||||
|
foreach ( $posts as $post ):
|
||||||
|
if ( -1 === $section ) {
|
||||||
|
$stats[ $post->post_name ] = $post->post_title;
|
||||||
|
} else {
|
||||||
|
$post_section = get_post_meta( $post->ID, 'sp_section', true );
|
||||||
|
|
||||||
|
if ( '' === $post_section ) {
|
||||||
|
$post_section = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $admin ) {
|
||||||
|
if ( 1 == $section ) {
|
||||||
|
if ( 1 == $post_section ) {
|
||||||
|
$stats[ $post->post_name ] = $post->post_title;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ( 1 != $post_section ) {
|
||||||
|
$stats[ $post->post_name ] = $post->post_title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ( $section == $post_section || -1 == $post_section ) {
|
||||||
|
$stats[ $post->post_name ] = $post->post_title;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endforeach;
|
||||||
|
|
||||||
// Merge the data and placeholders arrays
|
// Merge the data and placeholders arrays
|
||||||
$merged = array();
|
$merged = array();
|
||||||
|
|||||||
@@ -484,6 +484,24 @@ if ( !function_exists( 'sp_get_format_placeholder' ) ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !function_exists( 'sp_get_term_sections' ) ) {
|
||||||
|
function sp_get_term_sections( $t_id ) {
|
||||||
|
$term_meta = get_option( "taxonomy_$t_id" );
|
||||||
|
if ( isset( $term_meta['sp_sections'] ) ) {
|
||||||
|
$sections = $term_meta['sp_sections'];
|
||||||
|
} else {
|
||||||
|
$sections = apply_filters( 'sportspress_performance_sections', array( 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
|
||||||
|
$sections = array_keys( $sections );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( '' === $sections ) {
|
||||||
|
$sections = array();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sections;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( !function_exists( 'sp_dropdown_statuses' ) ) {
|
if ( !function_exists( 'sp_dropdown_statuses' ) ) {
|
||||||
function sp_dropdown_statuses( $args = array() ) {
|
function sp_dropdown_statuses( $args = array() ) {
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
|
|||||||
42
templates/player-statistics-league.php
Normal file
42
templates/player-statistics-league.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
// The first row should be column labels
|
||||||
|
$labels = $data[0];
|
||||||
|
|
||||||
|
// Remove the first row to leave us with the actual data
|
||||||
|
unset( $data[0] );
|
||||||
|
|
||||||
|
// Skip if there are no rows in the table
|
||||||
|
if ( empty( $data ) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
$output = '<h4 class="sp-table-caption">' . $league->name . '</h4>' .
|
||||||
|
'<div class="sp-table-wrapper">' .
|
||||||
|
'<table class="sp-player-statistics sp-data-table' . ( $scrollable ? ' sp-scrollable-table' : '' ) . '">' . '<thead>' . '<tr>';
|
||||||
|
|
||||||
|
foreach( $labels as $key => $label ):
|
||||||
|
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
|
||||||
|
foreach( $data as $season_id => $row ):
|
||||||
|
|
||||||
|
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||||
|
|
||||||
|
foreach( $labels as $key => $value ):
|
||||||
|
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
$output .= '</tr>';
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
$output .= '</tbody>' . '</table>' . '</div>';
|
||||||
|
?>
|
||||||
|
<div class="sp-template sp-template-player-statistics">
|
||||||
|
<?php echo $output; ?>
|
||||||
|
</div>
|
||||||
46
templates/player-statistics-total.php
Normal file
46
templates/player-statistics-total.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
// The first row should be column labels
|
||||||
|
$labels = $data[0];
|
||||||
|
|
||||||
|
// Remove the first row to leave us with the actual data
|
||||||
|
unset( $data[0] );
|
||||||
|
|
||||||
|
// Skip if there are no rows in the table
|
||||||
|
if ( empty( $data ) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
$output = '<h4 class="sp-table-caption">' . __( 'Career Total', 'sportspress' ) . '</h4>' .
|
||||||
|
'<div class="sp-table-wrapper">' .
|
||||||
|
'<table class="sp-player-statistics sp-data-table' . ( $scrollable ? ' sp-scrollable-table' : '' ) . '">' . '<thead>' . '<tr>';
|
||||||
|
|
||||||
|
foreach( $labels as $key => $label ):
|
||||||
|
if ( 'team' == $key )
|
||||||
|
continue;
|
||||||
|
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
$output .= '</tr>' . '</thead>' . '<tbody>';
|
||||||
|
|
||||||
|
$i = 0;
|
||||||
|
|
||||||
|
foreach( $data as $season_id => $row ):
|
||||||
|
|
||||||
|
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||||
|
|
||||||
|
foreach( $labels as $key => $value ):
|
||||||
|
if ( 'team' == $key )
|
||||||
|
continue;
|
||||||
|
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
$output .= '</tr>';
|
||||||
|
|
||||||
|
$i++;
|
||||||
|
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
$output .= '</tbody>' . '</table>' . '</div>';
|
||||||
|
?>
|
||||||
|
<div class="sp-template sp-template-player-statistics sp-template-player-total">
|
||||||
|
<?php echo $output; ?>
|
||||||
|
</div>
|
||||||
@@ -16,103 +16,42 @@ if ( ! isset( $id ) )
|
|||||||
$player = new SP_Player( $id );
|
$player = new SP_Player( $id );
|
||||||
|
|
||||||
$scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false;
|
$scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false;
|
||||||
|
$sections = get_option( 'sportspress_player_performance_sections', -1 );
|
||||||
$leagues = get_the_terms( $id, 'sp_league' );
|
$leagues = get_the_terms( $id, 'sp_league' );
|
||||||
|
$positions = $player->positions();
|
||||||
|
$player_sections = array();
|
||||||
|
foreach ( $positions as $position ) {
|
||||||
|
$player_sections = array_merge( $player_sections, sp_get_term_sections( $position->term_id ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine order of sections
|
||||||
|
if ( 1 == $sections ) {
|
||||||
|
$section_order = array( 1 => __( 'Defense', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ) );
|
||||||
|
} elseif ( 0 == $sections ) {
|
||||||
|
$section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) );
|
||||||
|
} else {
|
||||||
|
$section_order = array( -1 => null );
|
||||||
|
}
|
||||||
|
|
||||||
// Loop through statistics for each league
|
// Loop through statistics for each league
|
||||||
if ( is_array( $leagues ) ):
|
if ( is_array( $leagues ) ):
|
||||||
foreach ( $leagues as $league ):
|
foreach ( $section_order as $section_id => $section_label ) {
|
||||||
$data = $player->data( $league->term_id );
|
if ( -1 !== $section_id && ! in_array( $section_id, $player_sections ) ) continue;
|
||||||
|
|
||||||
// The first row should be column labels
|
foreach ( $leagues as $league ):
|
||||||
$labels = $data[0];
|
if ( null !== $section_label ) {
|
||||||
|
printf( '<h3 class="sp-post-caption sp-player-statistics-section">%s</h3>', $section_label );
|
||||||
// Remove the first row to leave us with the actual data
|
}
|
||||||
unset( $data[0] );
|
sp_get_template( 'player-statistics-league.php', array(
|
||||||
|
'data' => $player->data( $league->term_id, false, $section_id ),
|
||||||
// Skip if there are no rows in the table
|
'league' => $league,
|
||||||
if ( empty( $data ) )
|
'scrollable' => $scrollable,
|
||||||
continue;
|
) );
|
||||||
|
|
||||||
$output = '<h4 class="sp-table-caption">' . $league->name . '</h4>' .
|
|
||||||
'<div class="sp-table-wrapper">' .
|
|
||||||
'<table class="sp-player-statistics sp-data-table' . ( $scrollable ? ' sp-scrollable-table' : '' ) . '">' . '<thead>' . '<tr>';
|
|
||||||
|
|
||||||
foreach( $labels as $key => $label ):
|
|
||||||
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
sp_get_template( 'player-statistics-total.php', array(
|
||||||
|
'data' => $player->data( 0, false, $section_id ),
|
||||||
$i = 0;
|
'scrollable' => $scrollable,
|
||||||
|
) );
|
||||||
foreach( $data as $season_id => $row ):
|
}
|
||||||
|
|
||||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
|
||||||
|
|
||||||
foreach( $labels as $key => $value ):
|
|
||||||
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
|
||||||
endforeach;
|
|
||||||
|
|
||||||
$output .= '</tr>';
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
|
|
||||||
endforeach;
|
|
||||||
|
|
||||||
$output .= '</tbody>' . '</table>' . '</div>';
|
|
||||||
?>
|
|
||||||
<div class="sp-template sp-template-player-statistics">
|
|
||||||
<?php echo $output; ?>
|
|
||||||
</div>
|
|
||||||
<?php
|
|
||||||
endforeach;
|
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
// Career total
|
|
||||||
$data = $player->data( 0 );
|
|
||||||
|
|
||||||
// The first row should be column labels
|
|
||||||
$labels = $data[0];
|
|
||||||
|
|
||||||
// Remove the first row to leave us with the actual data
|
|
||||||
unset( $data[0] );
|
|
||||||
|
|
||||||
// Skip if there are no rows in the table
|
|
||||||
if ( empty( $data ) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
$output = '<h4 class="sp-table-caption">' . __( 'Career Total', 'sportspress' ) . '</h4>' .
|
|
||||||
'<div class="sp-table-wrapper">' .
|
|
||||||
'<table class="sp-player-statistics sp-data-table' . ( $scrollable ? ' sp-scrollable-table' : '' ) . '">' . '<thead>' . '<tr>';
|
|
||||||
|
|
||||||
foreach( $labels as $key => $label ):
|
|
||||||
if ( 'team' == $key )
|
|
||||||
continue;
|
|
||||||
$output .= '<th class="data-' . $key . '">' . $label . '</th>';
|
|
||||||
endforeach;
|
|
||||||
|
|
||||||
$output .= '</tr>' . '</thead>' . '<tbody>';
|
|
||||||
|
|
||||||
$i = 0;
|
|
||||||
|
|
||||||
foreach( $data as $season_id => $row ):
|
|
||||||
|
|
||||||
$output .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
|
||||||
|
|
||||||
foreach( $labels as $key => $value ):
|
|
||||||
if ( 'team' == $key )
|
|
||||||
continue;
|
|
||||||
$output .= '<td class="data-' . $key . '">' . sp_array_value( $row, $key, '—' ) . '</td>';
|
|
||||||
endforeach;
|
|
||||||
|
|
||||||
$output .= '</tr>';
|
|
||||||
|
|
||||||
$i++;
|
|
||||||
|
|
||||||
endforeach;
|
|
||||||
|
|
||||||
$output .= '</tbody>' . '</table>' . '</div>';
|
|
||||||
?>
|
|
||||||
<div class="sp-template sp-template-player-statistics sp-template-player-total">
|
|
||||||
<?php echo $output; ?>
|
|
||||||
</div>
|
|
||||||
Reference in New Issue
Block a user