Organize event performance tables

This commit is contained in:
Brian Miyaji
2015-03-05 19:11:26 +11:00
parent e57a67bbb3
commit 97390e129b
4 changed files with 251 additions and 184 deletions

View File

@@ -5,7 +5,7 @@ Plugin URI: http://themeboy.com/
Description: Modify SportsPress to work with individual (player vs player) sports. Description: Modify SportsPress to work with individual (player vs player) sports.
Author: ThemeBoy Author: ThemeBoy
Author URI: http://themeboy.com/ Author URI: http://themeboy.com/
Version: 1.6 Version: 1.7
*/ */
// Exit if accessed directly // Exit if accessed directly
@@ -17,7 +17,7 @@ if ( ! class_exists( 'SportsPress_Individual_Mode' ) ) :
* Main SportsPress Individual Mode Class * Main SportsPress Individual Mode Class
* *
* @class SportsPress_Individual_Mode * @class SportsPress_Individual_Mode
* @version 1.6 * @version 1.7
*/ */
class SportsPress_Individual_Mode { class SportsPress_Individual_Mode {
@@ -38,6 +38,7 @@ class SportsPress_Individual_Mode {
add_filter( 'sportspress_register_post_type_table', array( $this, 'move_table_post_type' ), 99 ); add_filter( 'sportspress_register_post_type_table', array( $this, 'move_table_post_type' ), 99 );
add_filter( 'sportspress_settings_tabs_array', array( $this, 'remove_team_settings_tab' ), 99 ); add_filter( 'sportspress_settings_tabs_array', array( $this, 'remove_team_settings_tab' ), 99 );
add_filter( 'sportspress_get_settings_pages', array( $this, 'remove_team_settings' ), 99 ); add_filter( 'sportspress_get_settings_pages', array( $this, 'remove_team_settings' ), 99 );
add_filter( 'sportspress_performance_options', array( $this, 'remove_performance_options' ), 99 );
add_filter( 'sportspress_player_options', array( $this, 'add_player_options' ), 99 ); add_filter( 'sportspress_player_options', array( $this, 'add_player_options' ), 99 );
add_filter( 'sportspress_player_settings', array( $this, 'add_player_settings' ), 99 ); add_filter( 'sportspress_player_settings', array( $this, 'add_player_settings' ), 99 );
add_filter( 'sportspress_next_steps', array( $this, 'remove_team_step' ), 99 ); add_filter( 'sportspress_next_steps', array( $this, 'remove_team_step' ), 99 );
@@ -67,7 +68,7 @@ class SportsPress_Individual_Mode {
*/ */
private function define_constants() { private function define_constants() {
if ( !defined( 'SP_INDIVIDUAL_MODE_VERSION' ) ) if ( !defined( 'SP_INDIVIDUAL_MODE_VERSION' ) )
define( 'SP_INDIVIDUAL_MODE_VERSION', '1.6' ); define( 'SP_INDIVIDUAL_MODE_VERSION', '1.7' );
if ( !defined( 'SP_INDIVIDUAL_MODE_URL' ) ) if ( !defined( 'SP_INDIVIDUAL_MODE_URL' ) )
define( 'SP_INDIVIDUAL_MODE_URL', plugin_dir_url( __FILE__ ) ); define( 'SP_INDIVIDUAL_MODE_URL', plugin_dir_url( __FILE__ ) );
@@ -171,6 +172,18 @@ class SportsPress_Individual_Mode {
return $settings; return $settings;
} }
/**
* Remove option to split players by team.
*/
public function remove_performance_options( $options ) {
foreach ( $options as $index => $option ) {
if ( 'sportspress_event_split_players_by_team' == sp_array_value( $option, 'id' ) ) {
unset( $options[ $index ] );
}
}
return $options;
}
/** /**
* Add options from teams to players tab. * Add options from teams to players tab.
*/ */

View File

@@ -0,0 +1,155 @@
<?php
/**
* Event Performance Table Combined
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 1.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
// Initialize totals
$totals = array();
?>
<div class="sp-template sp-template-event-performance sp-template-event-performance-<?php echo $mode; ?>">
<?php if ( $caption ): ?>
<h4 class="sp-table-caption"><?php echo $caption; ?></h4>
<?php endif; ?>
<div class="sp-table-wrapper">
<table class="sp-event-performance sp-data-table<?php if ( $scrollable ) { ?> sp-scrollable-table<?php } ?><?php if ( $sortable ) { ?> sp-sortable-table<?php } ?>">
<thead>
<tr>
<?php if ( isset( $labels['number'] ) ): ?>
<th class="data-number">#</th>
<?php endif; ?>
<th class="data-name"><?php _e( 'Player', 'sportspress' ); ?></th>
<?php if ( $mode == 'values' ): foreach( $labels as $key => $label ): ?>
<?php if ( 'number' == $key ) continue; ?>
<th class="data-<?php echo $key; ?>"><?php echo $label; ?></th>
<?php endforeach; else: ?>
<th class="sp-performance-icons">&nbsp;</th>
<?php endif; ?>
</tr>
</thead>
<tbody>
<?php
if ( $show_players ) {
$i = 0;
foreach ( $data as $player_id => $row ):
if ( ! $player_id )
continue;
$name = get_the_title( $player_id );
if ( ! $name )
continue;
echo '<tr class="' . sp_array_value( $row, 'status', 'lineup' ) . ' ' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
if ( isset( $labels['number'] ) ):
$number = sp_array_value( $row, 'number', '&nbsp;' );
// Player number
echo '<td class="data-number">' . $number . '</td>';
endif;
if ( $link_posts ):
$permalink = get_post_permalink( $player_id );
$name = '<a href="' . $permalink . '">' . $name . '</a>';
endif;
echo '<td class="data-name">' . $name . '</td>';
if ( $mode == 'icons' ) echo '<td class="sp-performance-icons">';
foreach ( $labels as $key => $label ):
if ( in_array( $key, array( 'number', 'name' ) ) )
continue;
$value = '&mdash;';
if ( $key == 'position' ):
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$positions = array();
$position_ids = (array) $row[ $key ];
foreach ( $position_ids as $position_id ) {
$player_position = get_term_by( 'id', $position_id, 'sp_position' );
if ( $player_position ) $positions[] = $player_position->name;
}
$value = implode( ', ', $positions );
endif;
else:
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = 0;
endif;
endif;
if ( ! array_key_exists( $key, $totals ) ):
$totals[ $key ] = 0;
endif;
$totals[ $key ] += $value;
if ( $mode == 'values' ):
echo '<td class="data-' . $key . '">' . $value . '</td>';
elseif ( intval( $value ) && $mode == 'icons' ):
$performance_id = sp_array_value( $performance_ids, $key, null );
if ( $performance_id && has_post_thumbnail( $performance_id ) ):
echo str_repeat( get_the_post_thumbnail( $performance_id, 'sportspress-fit-mini' ) . ' ', $value );
endif;
endif;
endforeach;
if ( $mode == 'icons' ) echo '</td>';
echo '</tr>';
$i++;
endforeach;
}
?>
</tbody>
<?php if ( $show_total ): ?>
<tfoot>
<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">
<?php
if ( isset( $labels['number'] ) ):
echo '<td class="data-number">&nbsp;</td>';
endif;
echo '<td class="data-name">' . __( 'Total', 'sportspress' ) . '</td>';
$row = sp_array_value( $data, 0, array() );
if ( $mode == 'icons' ) echo '<td class="sp-performance-icons">';
foreach ( $labels as $key => $label ):
if ( in_array( $key, array( 'number', 'name' ) ) )
continue;
if ( $key == 'position' ):
$value = '&mdash;';
elseif ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = sp_array_value( $totals, $key, 0 );
endif;
if ( $mode == 'values' ):
echo '<td class="data-' . $key . '">' . $value . '</td>';
elseif ( intval( $value ) && $mode == 'icons' ):
$performance_id = sp_array_value( $performance_ids, $key, null );
if ( $performance_id && has_post_thumbnail( $performance_id ) ):
echo str_repeat( get_the_post_thumbnail( $performance_id, 'sportspress-fit-mini' ) . ' ', $value );
endif;
endif;
endforeach;
if ( $mode == 'icons' ) echo '</td>';
?>
</tr>
</tfoot>
<?php endif; ?>
</table>
</div>
</div>

View File

@@ -4,7 +4,7 @@
* *
* @author ThemeBoy * @author ThemeBoy
* @package SportsPress/Templates * @package SportsPress/Templates
* @version 1.6 * @version 1.7
*/ */
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
@@ -13,11 +13,14 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$totals = array(); $totals = array();
?> ?>
<div class="sp-template sp-template-event-performance sp-template-event-performance-<?php echo $mode; ?>"> <div class="sp-template sp-template-event-performance sp-template-event-performance-<?php echo $mode; ?>">
<?php if ( $caption ): ?>
<h4 class="sp-table-caption"><?php echo $caption; ?></h4>
<?php endif; ?>
<div class="sp-table-wrapper"> <div class="sp-table-wrapper">
<table class="sp-event-performance sp-data-table <?php if ( $scrollable ) { ?> sp-scrollable-table<?php } ?>"> <table class="sp-event-performance sp-data-table<?php if ( $scrollable ) { ?> sp-scrollable-table<?php } ?><?php if ( $sortable ) { ?> sp-sortable-table<?php } ?>">
<thead> <thead>
<tr> <tr>
<?php if ( $show_team_players ): ?> <?php if ( $show_players ): ?>
<?php if ( $show_numbers ) { ?> <?php if ( $show_numbers ) { ?>
<th class="data-number">#</th> <th class="data-number">#</th>
<?php } ?> <?php } ?>
@@ -37,7 +40,7 @@ $totals = array();
<?php endif; ?> <?php endif; ?>
</tr> </tr>
</thead> </thead>
<?php if ( $show_team_players ): ?> <?php if ( $show_players ): ?>
<tbody> <tbody>
<?php <?php
@@ -145,7 +148,7 @@ $totals = array();
</tbody> </tbody>
<?php endif; ?> <?php endif; ?>
<?php if ( $show_total || $show_extras ): ?> <?php if ( $show_total || $show_extras ): ?>
<<?php echo ( $show_team_players ? 'tfoot' : 'tbody' ); ?>> <<?php echo ( $show_players ? 'tfoot' : 'tbody' ); ?>>
<?php <?php
if ( $show_extras ) { if ( $show_extras ) {
$row = sp_array_value( $data, -1, array() ); $row = sp_array_value( $data, -1, array() );
@@ -155,7 +158,7 @@ $totals = array();
?> ?>
<tr class="sp-extras-row <?php echo ( $i % 2 == 0 ? 'odd' : 'even' ); ?>"> <tr class="sp-extras-row <?php echo ( $i % 2 == 0 ? 'odd' : 'even' ); ?>">
<?php <?php
if ( $show_team_players ): if ( $show_players ):
if ( $show_numbers ) { if ( $show_numbers ) {
echo '<td class="data-number">&nbsp;</td>'; echo '<td class="data-number">&nbsp;</td>';
} }
@@ -201,7 +204,7 @@ $totals = array();
?> ?>
<tr class="sp-total-row <?php echo ( $i % 2 == 0 ? 'odd' : 'even' ); ?>"> <tr class="sp-total-row <?php echo ( $i % 2 == 0 ? 'odd' : 'even' ); ?>">
<?php <?php
if ( $show_team_players ): if ( $show_players ):
if ( $show_numbers ) { if ( $show_numbers ) {
echo '<td class="data-number">&nbsp;</td>'; echo '<td class="data-number">&nbsp;</td>';
} }
@@ -247,7 +250,7 @@ $totals = array();
</tr> </tr>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
</<?php echo ( $show_team_players ? 'tfoot' : 'tbody' ); ?>> </<?php echo ( $show_players ? 'tfoot' : 'tbody' ); ?>>
<?php endif; ?> <?php endif; ?>
</table> </table>
</div> </div>

View File

@@ -43,6 +43,7 @@ if ( is_array( $teams ) ):
$link_posts = get_option( 'sportspress_link_players', 'yes' ) == 'yes' ? true : false; $link_posts = get_option( 'sportspress_link_players', 'yes' ) == 'yes' ? true : false;
$scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false; $scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false;
$sortable = get_option( 'sportspress_enable_sortable_tables', 'yes' ) == 'yes' ? true : false;
$mode = get_option( 'sportspress_event_performance_mode', 'values' ); $mode = get_option( 'sportspress_event_performance_mode', 'values' );
// Get performance ids for icons // Get performance ids for icons
@@ -83,18 +84,14 @@ if ( is_array( $teams ) ):
} }
if ( ! $show_team_players && ! $show_staff && ! $show_extras && ! $show_total ) continue; if ( ! $show_team_players && ! $show_staff && ! $show_extras && ! $show_total ) continue;
?>
<?php if ( $team_id ): ?>
<h4 class="sp-table-caption"><?php echo get_the_title( $team_id ); ?></h4>
<?php endif; ?>
<?php
if ( $show_team_players || $show_extras || $show_total ) { if ( $show_team_players || $show_extras || $show_total ) {
if ( $split_positions ) { if ( $split_positions ) {
$positions = get_terms( 'sp_position', array( $positions = get_terms( 'sp_position', array(
'orderby' => 'slug', 'orderby' => 'slug',
) ); ) );
foreach ( $positions as $position ) { foreach ( $positions as $position_index => $position ) {
$subdata = array(); $subdata = array();
foreach ( $data as $player_id => $player ) { foreach ( $data as $player_id => $player ) {
$player_positions = (array) sp_array_value( $player, 'position' ); $player_positions = (array) sp_array_value( $player, 'position' );
@@ -138,10 +135,12 @@ if ( is_array( $teams ) ):
sp_get_template( 'event-performance-table.php', array( sp_get_template( 'event-performance-table.php', array(
'position' => $position->name, 'position' => $position->name,
'scrollable' => $scrollable, 'scrollable' => $scrollable,
'show_team_players' => $show_team_players, 'sortable' => $sortable,
'show_players' => $show_team_players,
'show_numbers' => $show_numbers, 'show_numbers' => $show_numbers,
'show_extras' => $show_extras, 'show_extras' => $show_extras,
'show_total' => $show_total, 'show_total' => $show_total,
'caption' => 0 == $position_index && $team_id ? get_the_title( $team_id ) : null,
'labels' => $sublabels, 'labels' => $sublabels,
'mode' => $mode, 'mode' => $mode,
'data' => $subdata, 'data' => $subdata,
@@ -155,10 +154,12 @@ if ( is_array( $teams ) ):
} else { } else {
sp_get_template( 'event-performance-table.php', array( sp_get_template( 'event-performance-table.php', array(
'scrollable' => $scrollable, 'scrollable' => $scrollable,
'show_team_players' => $show_team_players, 'sortable' => $sortable,
'show_players' => $show_team_players,
'show_numbers' => $show_numbers, 'show_numbers' => $show_numbers,
'show_extras' => $show_extras, 'show_extras' => $show_extras,
'show_total' => $show_total, 'show_total' => $show_total,
'caption' => $team_id ? get_the_title( $team_id ) : null,
'labels' => $labels, 'labels' => $labels,
'mode' => $mode, 'mode' => $mode,
'data' => $data, 'data' => $data,
@@ -178,173 +179,68 @@ if ( is_array( $teams ) ):
endforeach; endforeach;
} else { } else {
// Combined table // Combined table
?> $data = array();
<h4 class="sp-table-caption"><?php _e( 'Performance', 'sportspress' ); ?></h4> foreach ( $performance as $players ) {
<div class="sp-template sp-template-event-performance sp-template-event-performance-<?php echo $mode; ?>"> foreach ( $players as $player_id => $player ) {
<div class="sp-table-wrapper"> if ( $player_id <= 0 ) continue;
<table class="sp-event-performance sp-data-table <?php if ( $scrollable ) { ?> sp-scrollable-table<?php } ?>"> $data[ $player_id ] = $player;
<thead> }
<tr> }
<?php if ( isset( $labels['number'] ) ): ?>
<th class="data-number">#</th>
<?php endif; ?>
<th class="data-name"><?php _e( 'Player', 'sportspress' ); ?></th>
<?php if ( $mode == 'values' ): foreach( $labels as $key => $label ): ?>
<?php if ( 'number' == $key ) continue; ?>
<th class="data-<?php echo $key; ?>"><?php echo $label; ?></th>
<?php endforeach; else: ?>
<th class="sp-performance-icons">&nbsp;</th>
<?php endif; ?>
</tr>
</thead>
<tbody>
<?php
foreach ( $teams as $index => $team_id ) {
if ( -1 == $team_id ) continue;
// Get results for players in the team if ( $split_positions ) {
$players = sp_array_between( (array) get_post_meta( $id, 'sp_player', false ), 0, $index ); $positions = get_terms( 'sp_position', array(
$has_players = sizeof( $players ) > 1; 'orderby' => 'slug',
) );
$show_team_players = $show_players && $has_players; foreach ( $positions as $position_index => $position ) {
if ( ! $show_team_players && ! $show_total ) continue; $subdata = array();
foreach ( $data as $player_id => $player ) {
$player_positions = (array) sp_array_value( $player, 'position' );
$player_positions = array_filter( $player_positions );
if ( empty( $player_positions ) ) {
$player_positions = (array) sp_get_the_term_id( $player_id, 'sp_position' );
}
if ( in_array( $position->term_id, $player_positions ) ) {
$subdata[ $player_id ] = $data[ $player_id ];
}
}
$totals = array(); if ( sizeof( $subdata ) ) {
sp_get_template( 'event-performance-table-combined.php', array(
if ( 0 < $team_id ) { 'scrollable' => $scrollable,
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) ); 'sortable' => $sortable,
} elseif ( 0 == $team_id ) { 'show_players' => $show_players,
$data = array(); 'show_numbers' => $show_numbers,
foreach ( $players as $player_id ) { 'show_extras' => $show_extras,
if ( isset( $performance[ $player_id ][ $player_id ] ) ) { 'show_total' => $show_total,
$data[ $player_id ] = $performance[ $player_id ][ $player_id ]; 'caption' => $position->name,
} 'labels' => $labels,
} 'mode' => $mode,
} else { 'data' => $subdata,
$data = sp_array_value( array_values( $performance ), $index ); 'event' => $event,
} 'link_posts' => $link_posts,
'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
if ( $show_team_players ) { 'primary' => 'primary' == $total ? $primary : null,
) );
$i = 0; }
foreach ( $data as $player_id => $row ): }
} else {
if ( ! $player_id ) sp_get_template( 'event-performance-table-combined.php', array(
continue; 'scrollable' => $scrollable,
'sortable' => $sortable,
$name = get_the_title( $player_id ); 'show_players' => $show_players,
'show_numbers' => $show_numbers,
if ( ! $name ) 'show_extras' => $show_extras,
continue; 'show_total' => $show_total,
'caption' => __( 'Performance', 'sportspress' ),
echo '<tr class="' . sp_array_value( $row, 'status', 'lineup' ) . ' ' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">'; 'labels' => $labels,
'mode' => $mode,
if ( isset( $labels['number'] ) ): 'data' => $data,
$number = sp_array_value( $row, 'number', '&nbsp;' ); 'event' => $event,
'link_posts' => $link_posts,
// Player number 'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
echo '<td class="data-number">' . $number . '</td>'; 'primary' => 'primary' == $total ? $primary : null,
endif; ) );
}
if ( $link_posts ):
$permalink = get_post_permalink( $player_id );
$name = '<a href="' . $permalink . '">' . $name . '</a>';
endif;
echo '<td class="data-name">' . $name . '</td>';
if ( $mode == 'icons' ) echo '<td class="sp-performance-icons">';
foreach ( $labels as $key => $label ):
if ( in_array( $key, array( 'number', 'name' ) ) )
continue;
$value = '&mdash;';
if ( $key == 'position' ):
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$positions = array();
$position_ids = (array) $row[ $key ];
foreach ( $position_ids as $position_id ) {
$player_position = get_term_by( 'id', $position_id, 'sp_position' );
if ( $player_position ) $positions[] = $player_position->name;
}
$value = implode( ', ', $positions );
endif;
else:
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = 0;
endif;
endif;
if ( ! array_key_exists( $key, $totals ) ):
$totals[ $key ] = 0;
endif;
$totals[ $key ] += $value;
if ( $mode == 'values' ):
echo '<td class="data-' . $key . '">' . $value . '</td>';
elseif ( intval( $value ) && $mode == 'icons' ):
$performance_id = sp_array_value( $performance_ids, $key, null );
if ( $performance_id && has_post_thumbnail( $performance_id ) ):
echo str_repeat( get_the_post_thumbnail( $performance_id, 'sportspress-fit-mini' ) . ' ', $value );
endif;
endif;
endforeach;
if ( $mode == 'icons' ) echo '</td>';
echo '</tr>';
$i++;
endforeach;
}
}
?>
</tbody>
<?php if ( $show_total ): ?>
<tfoot>
<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">
<?php
if ( isset( $labels['number'] ) ):
echo '<td class="data-number">&nbsp;</td>';
endif;
echo '<td class="data-name">' . __( 'Total', 'sportspress' ) . '</td>';
$row = sp_array_value( $data, 0, array() );
if ( $mode == 'icons' ) echo '<td class="sp-performance-icons">';
foreach ( $labels as $key => $label ):
if ( in_array( $key, array( 'number', 'name' ) ) )
continue;
if ( $key == 'position' ):
$value = '&mdash;';
elseif ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = sp_array_value( $totals, $key, 0 );
endif;
if ( $mode == 'values' ):
echo '<td class="data-' . $key . '">' . $value . '</td>';
elseif ( intval( $value ) && $mode == 'icons' ):
$performance_id = sp_array_value( $performance_ids, $key, null );
if ( $performance_id && has_post_thumbnail( $performance_id ) ):
echo str_repeat( get_the_post_thumbnail( $performance_id, 'sportspress-fit-mini' ) . ' ', $value );
endif;
endif;
endforeach;
if ( $mode == 'icons' ) echo '</td>';
?>
</tr>
</tfoot>
<?php endif; ?>
</table>
</div>
</div>
<?php
} }
endif; endif;