Allow event performance tables to be split by position

This commit is contained in:
Brian Miyaji
2015-03-03 17:20:44 +11:00
parent 91171b9b95
commit 7cf5946880
12 changed files with 638 additions and 245 deletions

View File

@@ -148,6 +148,9 @@ class SP_Admin_Sports {
$post = self::get_post_array( $performance, $post_type );
if ( empty( $post ) ) continue;
$id = self::insert_preset_post( $post, $index );
if ( isset( $performance['position'] ) ) {
wp_set_object_terms( $id, $performance['position'], 'sp_position', false );
}
$i ++;
}
@@ -187,6 +190,15 @@ class SP_Admin_Sports {
update_post_meta( $id, 'sp_equation', sp_array_value( $statistic, 'equation', null ) );
update_post_meta( $id, 'sp_precision', sp_array_value( $statistic, 'precision', 0 ) );
}
// Options
$options = sp_array_value( $preset, 'options', array() );
foreach ( $options as $option => $value ) {
update_option( 'sportspress_' . $option, $value );
}
// Primary Result
update_option( 'sportspress_primary_result', $primary_result );
}

View File

@@ -29,8 +29,27 @@ class SP_Meta_Box_Event_Performance {
// Get results for players in the team
$players = sp_array_between( (array)get_post_meta( $post->ID, 'sp_player', false ), 0, $key );
$players[] = -1;
$data = sp_array_combine( $players, sp_array_value( $stats, $team_id, array() ) );
// Determine if we need checkboxes
if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) && $i == 0 )
$has_checkboxes = true;
else
$has_checkboxes = false;
// Determine if we need extras
if ( 'yes' == get_option( 'sportspress_event_show_extras', 'no' ) )
$show_extras = true;
else
$show_extras = false;
// Determine if we are splitting positions
if ( 'yes' == get_option( 'sportspress_event_split_players_by_position', 'no' ) )
$split_positions = true;
else
$split_positions = false;
?>
<div>
<?php if ( $team_id ): ?>
@@ -38,7 +57,7 @@ class SP_Meta_Box_Event_Performance {
<?php elseif ( $i ): ?>
<br>
<?php endif; ?>
<?php self::table( $labels, $columns, $data, $team_id, $i == 0 ); ?>
<?php self::table( $labels, $columns, $data, $team_id, $has_checkboxes, $show_extras, $split_positions ); ?>
</div>
<?php
$i ++;
@@ -56,7 +75,7 @@ class SP_Meta_Box_Event_Performance {
/**
* Admin edit table
*/
public static function table( $labels = array(), $columns = array(), $data = array(), $team_id, $has_checkboxes = false ) {
public static function table( $labels = array(), $columns = array(), $data = array(), $team_id, $has_checkboxes = false, $show_extras = false, $split_positions = false ) {
?>
<div class="sp-data-table-container">
<table class="widefat sp-data-table sp-performance-table sp-sortable-table">
@@ -65,7 +84,7 @@ class SP_Meta_Box_Event_Performance {
<th class="icon">&nbsp;</th>
<th>#</th>
<th><?php _e( 'Player', 'sportspress' ); ?></th>
<th>
<th class="column-position">
<?php if ( $has_checkboxes ): ?>
<label for="sp_columns_position">
<input type="checkbox" name="sp_columns[]" value="position" id="sp_columns_position" <?php checked( ! is_array( $columns ) || in_array( 'position', $columns ) ); ?>>
@@ -99,6 +118,22 @@ class SP_Meta_Box_Event_Performance {
</tr>
</thead>
<tfoot>
<?php if ( $show_extras ) { ?>
<tr class="sp-row sp-post sp-extras">
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><strong><?php _e( 'Extras', 'sportspress' ); ?></strong></td>
<td>&nbsp;</td>
<?php foreach( $labels as $column => $label ):
$player_id = -1;
$player_performance = sp_array_value( $data, $player_id, array() );
$value = sp_array_value( $player_performance, $column, '' );
?>
<td><input type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" /></td>
<?php endforeach; ?>
<td>&nbsp;</td>
</tr>
<?php } ?>
<tr class="sp-row sp-total">
<td>&nbsp;</td>
<td>&nbsp;</td>
@@ -106,10 +141,10 @@ class SP_Meta_Box_Event_Performance {
<td>&nbsp;</td>
<?php foreach( $labels as $column => $label ):
$player_id = 0;
$player_performance = sp_array_value( $data, 0, array() );
$player_performance = sp_array_value( $data, $player_id, array() );
$value = sp_array_value( $player_performance, $column, '' );
?>
<td><input type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="0" /></td>
<td><input type="text" name="sp_players[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" placeholder="0" <?php if ( $split_positions ) { ?>readonly="readonly"<?php } else { ?>value="<?php echo $value; ?>"<?php } ?> /></td>
<?php endforeach; ?>
<td>&nbsp;</td>
</tr>
@@ -117,7 +152,7 @@ class SP_Meta_Box_Event_Performance {
<tbody>
<?php
foreach ( $data as $player_id => $player_performance ):
if ( !$player_id ) continue;
if ( $player_id <= 0 ) continue;
$number = get_post_meta( $player_id, 'sp_number', true );
$value = sp_array_value( $player_performance, 'number', '' );
?>
@@ -129,16 +164,19 @@ class SP_Meta_Box_Event_Performance {
<td><?php echo get_the_title( $player_id ); ?></td>
<td>
<?php
$selected = sp_array_value( $player_performance, 'position', null );
$selected = (array) sp_array_value( $player_performance, 'position', null );
if ( $selected == null ):
$selected = sp_get_the_term_id( $player_id, 'sp_position', 0 );
$selected = (array) sp_get_the_term_id( $player_id, 'sp_position', 0 );
endif;
$args = array(
'taxonomy' => 'sp_position',
'name' => 'sp_players[' . $team_id . '][' . $player_id . '][position]',
'name' => 'sp_players[' . $team_id . '][' . $player_id . '][position][]',
'values' => 'term_id',
'orderby' => 'slug',
'selected' => $selected,
'class' => 'sp-position',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?>

View File

@@ -40,7 +40,7 @@ class SP_Settings_Events extends SP_Settings_Page {
$settings = array_merge(
array(
array( 'title' => __( 'Event Options', 'sportspress' ), 'type' => 'title','desc' => '', 'id' => 'event_options' ),
array( 'title' => __( 'Event Options', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'event_options' ),
),
apply_filters( 'sportspress_event_options', array(
@@ -86,24 +86,8 @@ class SP_Settings_Events extends SP_Settings_Page {
),
array(
'desc' => __( 'Players', 'sportspress' ),
'id' => 'sportspress_event_show_players',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Staff', 'sportspress' ),
'id' => 'sportspress_event_show_staff',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Total', 'sportspress' ),
'id' => 'sportspress_event_show_total',
'desc' => __( 'Player Performance', 'sportspress' ),
'id' => 'sportspress_event_show_performance',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
@@ -124,17 +108,6 @@ class SP_Settings_Events extends SP_Settings_Page {
array( 'type' => 'delimiter' ),
array(
'title' => __( 'Player Performance', 'sportspress' ),
'id' => 'sportspress_event_performance_mode',
'default' => 'values',
'type' => 'radio',
'options' => array(
'values' => __( 'Values', 'sportspress' ),
'icons' => __( 'Icons', 'sportspress' ),
),
),
array(
'title' => __( 'Venues', 'sportspress' ),
'desc' => __( 'Display maps', 'sportspress' ),
@@ -185,10 +158,103 @@ class SP_Settings_Events extends SP_Settings_Page {
'default' => 'no',
'type' => 'checkbox',
),
)),
) ),
array(
array( 'type' => 'sectionend', 'id' => 'event_options' ),
),
array(
array( 'title' => __( 'Player Performance', 'sportspress' ), 'type' => 'title', 'desc' => '', 'id' => 'performance_options' ),
),
apply_filters( 'sportspress_performance_options', array(
array(
'title' => __( 'Rows', 'sportspress' ),
'desc' => __( 'Staff', 'sportspress' ),
'id' => 'sportspress_event_show_staff',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Players', 'sportspress' ),
'id' => 'sportspress_event_show_players',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Extras', 'sportspress' ),
'id' => 'sportspress_event_show_extras',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => '',
),
array(
'desc' => __( 'Total', 'sportspress' ),
'id' => 'sportspress_event_show_total',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Columns', 'sportspress' ),
'id' => 'sportspress_event_performance_columns',
'default' => 'auto',
'type' => 'radio',
'options' => array(
'auto' => __( 'Auto', 'sportspress' ),
'manual' => __( 'Manual', 'sportspress' ),
),
),
array(
'title' => __( 'Mode', 'sportspress' ),
'id' => 'sportspress_event_performance_mode',
'default' => 'values',
'type' => 'radio',
'options' => array(
'values' => __( 'Values', 'sportspress' ),
'icons' => __( 'Icons', 'sportspress' ),
),
),
array(
'title' => __( 'Players', 'sportspress' ),
'desc' => __( 'Display squad numbers', 'sportspress' ),
'id' => 'sportspress_event_show_player_numbers',
'default' => 'yes',
'type' => 'checkbox',
'checkboxgroup' => 'start',
),
array(
'desc' => __( 'Split players by position', 'sportspress' ),
'id' => 'sportspress_event_split_players_by_position',
'default' => 'false',
'type' => 'checkbox',
'checkboxgroup' => 'end',
),
array(
'title' => __( 'Total', 'sportspress' ),
'id' => 'sportspress_event_total_performance',
'default' => 'all',
'type' => 'radio',
'options' => array(
'all' => __( 'All', 'sportspress' ),
'primary' => __( 'Primary', 'sportspress' ),
),
),
) ),
array(
array( 'type' => 'sectionend', 'id' => 'performance_options' ),
)
);

View File

@@ -77,7 +77,7 @@
<td class="forminp">
<legend class="screen-reader-text"><span><?php _e( 'Event Results', 'sportspress' ) ?></span></legend>
<form>
<?php wp_nonce_field( 'sp-save-primary-result', 'sp-config-nonce', false ); ?>
<?php wp_nonce_field( 'sp-save-primary-result', 'sp-primary-result-nonce', false ); ?>
<table class="widefat sp-admin-config-table">
<thead>
<tr>
@@ -131,6 +131,8 @@
<table class="form-table">
<tbody>
<?php
$selection = get_option( 'sportspress_primary_performance', 0 );
$args = array(
'post_type' => 'sp_performance',
'numberposts' => -1,
@@ -146,30 +148,61 @@
<p class="description"><?php _e( 'Used for events.', 'sportspress' ); ?></p>
</th>
<td class="forminp">
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th class="icon" scope="col"><?php _e( 'Icon', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Variable', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Description', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
</thead>
<?php if ( $data ): $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="icon"><?php if ( has_post_thumbnail( $row->ID ) ) echo get_the_post_thumbnail( $row->ID, 'sportspress-fit-mini' ); ?></td>
<td class="row-title"><?php echo $row->post_title; ?></td>
<td><?php echo $row->post_name; ?></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>
<?php $i++; endforeach; else: ?>
<tr class="alternate">
<td colspan="5"><?php _e( 'No results found.', 'sportspress' ); ?></td>
</tr>
<?php endif; ?>
</table>
<legend class="screen-reader-text"><span><?php _e( 'Event Results', 'sportspress' ) ?></span></legend>
<form>
<?php wp_nonce_field( 'sp-save-primary-performance', 'sp-primary-performance-nonce', false ); ?>
<table class="widefat sp-admin-config-table">
<thead>
<tr>
<th class="radio" scope="col"><?php _e( 'Primary', 'sportspress' ); ?></th>
<th class="icon" scope="col"><?php _e( 'Icon', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Variable', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Position', 'sportspress' ); ?></th>
<th scope="col"><?php _e( 'Description', 'sportspress' ); ?></th>
<th scope="col" class="edit"></th>
</tr>
</thead>
<tfoot>
<tr>
<th class="radio"><input type="radio" class="sp-primary-performance-option" id="sportspress_primary_performance_0" name="sportspress_primary_performance" value="0" <?php checked( $selection, 0 ); ?>></th>
<th class="icon">&nbsp;</td>
<th colspan="5"><label for="sportspress_primary_performance_0">
<?php
if ( sizeof( $data ) > 0 ):
$default = reset( $data );
printf( __( 'Default (%s)', 'sportspress' ), $default->post_title );
else:
_e( 'Default', 'sportspress' );
endif;
?>
</label></th>
</tr>
</tfoot>
<?php if ( $data ): $i = 0; foreach ( $data as $row ): ?>
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
<td class="radio"><input type="radio" class="sp-primary-performance-option" id="sportspress_primary_performance_<?php echo $row->post_name; ?>" name="sportspress_primary_performance" value="<?php echo $row->post_name; ?>" <?php checked( $selection, $row->post_name ); ?>></td>
<td class="icon">
<?php
if ( has_post_thumbnail( $row->ID ) )
echo get_the_post_thumbnail( $row->ID, 'sportspress-fit-mini' );
else
echo '&nbsp;';
?>
</td>
<td class="row-title"><?php echo $row->post_title; ?></td>
<td><?php echo $row->post_name; ?></td>
<td><?php echo get_the_terms ( $row->ID, 'sp_position' ) ? the_terms( $row->ID, 'sp_position' ) : __( 'All', 'sportspress' );; ?></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>
<?php $i++; endforeach; else: ?>
<tr class="alternate">
<td colspan="7"><?php _e( 'No results found.', 'sportspress' ); ?></td>
</tr>
<?php endif; ?>
</table>
</form>
<div class="tablenav bottom">
<a class="button alignleft" href="<?php echo admin_url( 'edit.php?post_type=sp_performance' ); ?>"><?php _e( 'View All', 'sportspress' ); ?></a>
<a class="button button-primary alignright" href="<?php echo admin_url( 'post-new.php?post_type=sp_performance' ); ?>"><?php _e( 'Add New', 'sportspress' ); ?></a>

View File

@@ -99,7 +99,7 @@ class SP_Event extends SP_Custom_Post{
else:
// Add position to performance labels
$labels = array_merge( array( 'position' => __( 'Position', 'sportspress' ) ), $labels );
if ( is_array( $columns ) ):
if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) && is_array( $columns ) ):
foreach ( $labels as $key => $label ):
if ( ! in_array( $key, $columns ) ):
unset( $labels[ $key ] );

View File

@@ -142,7 +142,7 @@ class SP_Post_types {
'hierarchical' => true,
'rewrite' => array( 'slug' => get_option( 'sportspress_position_slug', 'position' ) ),
);
$object_types = apply_filters( 'sportspress_position_object_types', array( 'sp_player' ) );
$object_types = apply_filters( 'sportspress_position_object_types', array( 'sp_player', 'sp_performance' ) );
register_taxonomy( 'sp_position', $object_types, $args );
foreach ( $object_types as $object_type ):
register_taxonomy_for_object_type( 'sp_position', $object_type );

View File

@@ -13,6 +13,7 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
// Include core functions
include( 'sp-option-filters.php' );
include( 'sp-conditional-functions.php' );
include( 'sp-formatting-functions.php' );
include( 'sp-deprecated-functions.php' );

View File

@@ -0,0 +1,22 @@
<?php
/**
* SportsPress Option Filters
*
* Filters for SportsPress options.
*
* @author ThemeBoy
* @category Core
* @package SportsPress/Functions
* @version 1.7
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
function sportspress_primary_performance_filter( $option ) {
if ( $option ) return $option;
$performance_posts = get_posts( array( 'posts_per_page' => 1, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'sp_performance' ) );
if ( ! $performance_posts ) return $option;
$post = reset( $performance_posts );
return $post->post_name;
}
add_filter( 'option_sportspress_primary_performance', 'sportspress_primary_performance_filter' );

View File

@@ -56,7 +56,7 @@ class SportsPress_Individual_Mode {
add_filter( 'sportspress_player_teams', '__return_false' );
add_filter( 'sportspress_staff_teams', '__return_false' );
add_filter( 'sportspress_list_team_selector', '__return_false' );
add_filter( 'sportspress_split_performance_tables', '__return_false' );
add_filter( 'option_sportspress_event_split_players_by_team', '__return_false' );
// Remove templates
//remove_action( 'sportspress_single_event_content', 'sportspress_output_event_performance', 50 );

View File

@@ -2,9 +2,7 @@
"name": "Cricket",
"positions": [
"Batsman",
"Bowler",
"Keeper",
"All-rounder"
"Bowler"
],
"outcomes": [
{ "name" : "Win", "condition" : ">" },
@@ -21,8 +19,14 @@
{ "name" : "Points", "description" : "Total points", "primary" : 1 }
],
"performance": [
"Runs",
"Wickets taken"
{ "name" : "R", "id" : "runs", "position" : "Batsman", "description" : "Runs" },
{ "name" : "B", "position" : "Batsman", "description" : "Balls" },
{ "name" : "4s", "position" : "Batsman", "description" : "Fours" },
{ "name" : "6s", "position" : "Batsman", "description" : "Sixes" },
{ "name" : "O", "position" : "Bowler", "description" : "Overs Bowled" },
{ "name" : "M", "position" : "Bowler", "description" : "Maidens" },
{ "name" : "R", "position" : "Bowler", "description" : "Runs" },
{ "name" : "W", "position" : "Bowler", "description" : "Wickets" }
],
"columns": [
{ "name" : "P", "equation" : "$eventsplayed", "description" : "Matches played" },
@@ -36,9 +40,22 @@
"metrics": [
"Height",
"Weight",
"Bat brand"
"Bat Brand"
],
"statistics": [
{ "name" : "Appearances", "equation" : "$eventsplayed", "description" : "Matches played" }
]
{ "name" : "Mat", "equation" : "$eventsplayed", "description" : "Matches played" },
{ "name" : "Avg", "equation" : "$eventsplayed", "description" : "Average" },
{ "name" : "SR", "equation" : "$runs / $b * 100", "precision" : 2, "description" : "Strike Rate" }
],
"options": {
"load_individual_mode_module" : "no",
"event_teams" : "2",
"event_show_players" : "yes",
"event_show_extras" : "yes",
"event_show_total" : "yes",
"sportspress_event_performance_mode" : "values",
"event_show_player_numbers" : "no",
"event_split_players_by_position" : "yes",
"sportspress_event_total_performance" : "primary"
}
}

View File

@@ -0,0 +1,254 @@
<?php
/**
* Event Performance Table
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 1.6
*/
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; ?>">
<div class="sp-table-wrapper">
<table class="sp-event-performance sp-data-table <?php if ( $scrollable ) { ?> sp-scrollable-table<?php } ?>">
<thead>
<tr>
<?php if ( $show_team_players ): ?>
<?php if ( $show_numbers ) { ?>
<th class="data-number">#</th>
<?php } ?>
<th class="data-name">
<?php if ( isset( $position ) ) { ?>
<?php echo $position; ?>
<?php } else { ?>
<?php _e( 'Player', 'sportspress' ); ?>
<?php } ?>
</th>
<?php endif; ?>
<?php if ( $mode == 'values' ): foreach ( $labels as $key => $label ): ?>
<?php if ( isset( $position ) && 'position' == $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>
<?php if ( $show_team_players ): ?>
<tbody>
<?php
$lineups = array_filter( $data, array( $event, 'lineup_filter' ) );
$subs = array_filter( $data, array( $event, 'sub_filter' ) );
$lineup_sub_relation = array();
foreach ( $subs as $sub_id => $sub ):
if ( ! $sub_id )
continue;
$lineup_sub_relation[ sp_array_value( $sub, 'sub', 0 ) ] = $sub_id;
endforeach;
$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 ( $show_numbers ) {
$number = sp_array_value( $row, 'number', '&nbsp;' );
// Player number
echo '<td class="data-number">' . $number . '</td>';
}
if ( $link_posts ):
$permalink = get_post_permalink( $player_id );
$name = '<a href="' . $permalink . '">' . $name . '</a>';
if ( isset( $row['status'] ) && $row['status'] == 'sub' ):
$name = '(' . $name . ')';
endif;
endif;
if ( array_key_exists( $player_id, $lineup_sub_relation ) ):
$name .= ' <span class="sub-in" title="' . get_the_title( $lineup_sub_relation[ $player_id ] ) . '">' . sp_array_value( sp_array_value( $data, $lineup_sub_relation[ $player_id ], array() ), 'number', null ) . '</span>';
elseif ( isset( $row['sub'] ) && $row['sub'] ):
$name .= ' <span class="sub-out" title="' . get_the_title( $row[ 'sub' ] ) . '">' . sp_array_value( sp_array_value( $data, $row['sub'], array() ), 'number', null ) . '</span>';
endif;
echo '<td class="data-name">' . $name . '</td>';
if ( $mode == 'icons' ) echo '<td class="sp-performance-icons">';
foreach ( $labels as $key => $label ):
if ( 'name' == $key )
continue;
if ( isset( $position ) && 'position' == $key )
continue;
$value = '&mdash;';
if ( $key == 'position' ):
$positions = array();
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$position_ids = (array) $row[ $key ];
else:
$position_ids = (array) sp_get_the_term_id( $player_id, 'sp_position' );
endif;
foreach ( $position_ids as $position_id ) {
$player_position = get_term_by( 'id', $position_id, 'sp_position' );
if ( $player_position ) $positions[] = $player_position->name;
}
if ( sizeof( $positions ) ):
$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 endif; ?>
<?php if ( $show_total || $show_extras ): ?>
<<?php echo ( $show_team_players ? 'tfoot' : 'tbody' ); ?>>
<?php
if ( $show_extras ) {
$row = sp_array_value( $data, -1, array() );
$row = array_filter( $row );
$row = array_intersect_key( $row, $labels );
if ( ! empty( $row ) ) {
?>
<tr class="sp-extras-row <?php echo ( $i % 2 == 0 ? 'odd' : 'even' ); ?>">
<?php
if ( $show_team_players ):
if ( $show_numbers ) {
echo '<td class="data-number">&nbsp;</td>';
}
echo '<td class="data-name">' . __( 'Extras', 'sportspress' ) . '</td>';
endif;
$row = sp_array_value( $data, -1, array() );
if ( $mode == 'icons' ) echo '<td class="sp-performance-icons">';
foreach ( $labels as $key => $label ):
if ( 'name' == $key )
continue;
if ( isset( $position ) && 'position' == $key )
continue;
if ( $key == 'position' ):
$value = '&nbsp;';
elseif ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = '&nbsp;';
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>
<?php
$i++;
}
}
if ( $show_total ) {
if ( ! $primary || sizeof( array_intersect_key( $totals, array_flip( (array) $primary ) ) ) ) {
?>
<tr class="sp-total-row <?php echo ( $i % 2 == 0 ? 'odd' : 'even' ); ?>">
<?php
if ( $show_team_players ):
if ( $show_numbers ) {
echo '<td class="data-number">&nbsp;</td>';
}
echo '<td class="data-name">' . __( 'Total', 'sportspress' ) . '</td>';
endif;
$row = sp_array_value( $data, 0, array() );
if ( $mode == 'icons' ) echo '<td class="sp-performance-icons">';
foreach ( $labels as $key => $label ):
if ( 'name' == $key )
continue;
if ( isset( $position ) && 'position' == $key )
continue;
if ( $key == 'position' ):
$value = '&nbsp;';
else:
if ( $primary && $key !== $primary ):
$value = '&nbsp;';
elseif ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$value = $row[ $key ];
else:
$value = sp_array_value( $totals, $key, 0 );
if ( $show_extras ) {
$value += sp_array_value( sp_array_value( $data, -1, array() ), $key, 0 );
}
endif;
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>
<?php } ?>
<?php } ?>
</<?php echo ( $show_team_players ? 'tfoot' : 'tbody' ); ?>>
<?php endif; ?>
</table>
</div>
</div>

View File

@@ -11,10 +11,15 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$show_players = get_option( 'sportspress_event_show_players', 'yes' ) === 'yes' ? true : false;
$show_staff = get_option( 'sportspress_event_show_staff', 'yes' ) === 'yes' ? true : false;
$show_extras = get_option( 'sportspress_event_show_extras', 'no' ) === 'yes' ? true : false;
$show_total = get_option( 'sportspress_event_show_total', 'yes' ) === 'yes' ? true : false;
$split_tables = apply_filters( 'sportspress_split_performance_tables', true );
$show_numbers = get_option( 'sportspress_event_show_player_numbers', 'yes' ) === 'yes' ? true : false;
$split_positions = get_option( 'sportspress_event_split_players_by_position', 'no' ) === 'yes' ? true : false;
$split_teams = get_option( 'sportspress_event_split_players_by_team', 'yes' ) === 'yes' ? true : false;
$primary = get_option( 'sportspress_primary_performance', null );
$total = get_option( 'sportspress_event_total_performance', 'all');
if ( ! $show_players && ! $show_staff && ! $show_total ) return;
if ( ! $show_players && ! $show_staff && ! $show_extras && ! $show_total ) return;
if ( ! isset( $id ) )
$id = get_the_ID();
@@ -49,7 +54,7 @@ if ( is_array( $teams ) ):
endforeach;
endif;
if ( $split_tables ) {
if ( $split_teams ) {
// Split tables
foreach( $teams as $index => $team_id ):
if ( -1 == $team_id ) continue;
@@ -58,9 +63,11 @@ if ( is_array( $teams ) ):
$players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $index );
$has_players = sizeof( $players ) > 1;
$show_team_players = $show_players && $has_players;
if ( $show_extras ) {
$players[] = -1;
}
$totals = array();
$show_team_players = $show_players && $has_players;
if ( 0 < $team_id ) {
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
@@ -75,167 +82,98 @@ if ( is_array( $teams ) ):
$data = sp_array_value( array_values( $performance ), $index );
}
if ( ! $show_team_players && ! $show_staff && ! $show_total ) continue;
if ( ! $show_team_players && ! $show_staff && ! $show_extras && ! $show_total ) continue;
?>
<div class="sp-template sp-template-event-performance sp-template-event-performance-<?php echo $mode; ?>">
<?php if ( $team_id ): ?>
<h4 class="sp-table-caption"><?php echo get_the_title( $team_id ); ?></h4>
<?php endif; ?>
<?php
if ( $show_staff ):
sp_get_template( 'event-staff.php', array( 'id' => $id, 'index' => $index ) );
endif;
?>
<?php if ( $show_team_players || $show_total ): ?>
<div class="sp-table-wrapper">
<table class="sp-event-performance sp-data-table <?php if ( $scrollable ) { ?> sp-scrollable-table<?php } ?>">
<thead>
<tr>
<?php if ( $show_team_players ): ?>
<th class="data-number">#</th>
<th class="data-name"><?php _e( 'Player', 'sportspress' ); ?></th>
<?php endif; ?>
<?php if ( $mode == 'values' ): foreach( $labels as $key => $label ): ?>
<th class="data-<?php echo $key; ?>"><?php echo $label; ?></th>
<?php endforeach; else: ?>
<th class="sp-performance-icons">&nbsp;</th>
<?php endif; ?>
</tr>
</thead>
<?php if ( $show_team_players ): ?>
<tbody>
<?php
<?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 ( $split_positions ) {
$positions = get_terms( 'sp_position', array(
'orderby' => 'slug',
) );
$lineups = array_filter( $data, array( $event, 'lineup_filter' ) );
$subs = array_filter( $data, array( $event, 'sub_filter' ) );
foreach ( $positions as $position ) {
$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 ];
}
}
$lineup_sub_relation = array();
foreach ( $subs as $sub_id => $sub ):
if ( ! $sub_id )
continue;
$lineup_sub_relation[ sp_array_value( $sub, 'sub', 0 ) ] = $sub_id;
endforeach;
// Initialize Sublabels
$sublabels = $labels;
$i = 0;
foreach( $data as $player_id => $row ):
$performance_labels = get_posts( array(
'post_type' => 'sp_performance',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'sp_position',
'terms' => $position->term_id,
),
),
) );
if ( ! $player_id )
continue;
$allowed_labels = array();
if ( ! empty( $performance_labels ) ) {
foreach ( $performance_labels as $label ) {
$allowed_labels[ $label->post_name ] = $label->post_title;
}
$name = get_the_title( $player_id );
$sublabels = array_intersect_key( $sublabels, $allowed_labels );
}
if ( ! $name )
continue;
if ( sizeof( $subdata ) ) {
if ( $show_extras ) {
$subdata[-1] = sp_array_value( $data, -1 );
}
echo '<tr class="' . sp_array_value( $row, 'status', 'lineup' ) . ' ' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
sp_get_template( 'event-performance-table.php', array(
'position' => $position->name,
'scrollable' => $scrollable,
'show_team_players' => $show_team_players,
'show_numbers' => $show_numbers,
'show_extras' => $show_extras,
'show_total' => $show_total,
'labels' => $sublabels,
'mode' => $mode,
'data' => $subdata,
'event' => $event,
'link_posts' => $link_posts,
'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
'primary' => 'primary' == $total ? $primary : null,
) );
}
}
} else {
sp_get_template( 'event-performance-table.php', array(
'scrollable' => $scrollable,
'show_team_players' => $show_team_players,
'show_numbers' => $show_numbers,
'show_extras' => $show_extras,
'show_total' => $show_total,
'labels' => $labels,
'mode' => $mode,
'data' => $data,
'event' => $event,
'link_posts' => $link_posts,
'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
'primary' => 'primary' == $total ? $primary : null,
$number = sp_array_value( $row, 'number', '&nbsp;' );
// Player number
echo '<td class="data-number">' . $number . '</td>';
if ( $link_posts ):
$permalink = get_post_permalink( $player_id );
$name = '<a href="' . $permalink . '">' . $name . '</a>';
if ( isset( $row['status'] ) && $row['status'] == 'sub' ):
$name = '(' . $name . ')';
endif;
endif;
if ( array_key_exists( $player_id, $lineup_sub_relation ) ):
$name .= ' <span class="sub-in" title="' . get_the_title( $lineup_sub_relation[ $player_id ] ) . '">' . sp_array_value( sp_array_value( $data, $lineup_sub_relation[ $player_id ], array() ), 'number', null ) . '</span>';
elseif ( isset( $row['sub'] ) && $row['sub'] ):
$name .= ' <span class="sub-out" title="' . get_the_title( $row[ 'sub' ] ) . '">' . sp_array_value( sp_array_value( $data, $row['sub'], array() ), 'number', null ) . '</span>';
endif;
echo '<td class="data-name">' . $name . '</td>';
if ( $mode == 'icons' ) echo '<td class="sp-performance-icons">';
foreach( $labels as $key => $label ):
if ( $key == 'name' )
continue;
$value = '&mdash;';
if ( $key == 'position' ):
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
$position = get_term_by( 'id', $row[ $key ], 'sp_position' );
if ( $position ) $value = $position->name;
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 endif; ?>
<?php if ( $show_total ): ?>
<<?php echo ( $show_team_players ? 'tfoot' : 'tbody' ); ?>>
<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">
<?php
if ( $show_team_players ):
echo '<td class="data-number">&nbsp;</td>';
echo '<td class="data-name">' . __( 'Total', 'sportspress' ) . '</td>';
endif;
$row = sp_array_value( $data, 0, array() );
if ( $mode == 'icons' ) echo '<td class="sp-performance-icons">';
foreach( $labels as $key => $label ):
if ( $key == '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>
</<?php echo ( $show_team_players ? 'tfoot' : 'tbody' ); ?>>
<?php endif; ?>
</table>
</div>
<?php endif; ?>
</div>
) );
}
}
if ( $show_staff ):
sp_get_template( 'event-staff.php', array( 'id' => $id, 'index' => $index ) );
endif;
?>
<?php
endforeach;
} else {
@@ -247,9 +185,12 @@ if ( is_array( $teams ) ):
<table class="sp-event-performance sp-data-table <?php if ( $scrollable ) { ?> sp-scrollable-table<?php } ?>">
<thead>
<tr>
<th class="data-number">#</th>
<?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>
@@ -286,7 +227,7 @@ if ( is_array( $teams ) ):
if ( $show_team_players ) {
$i = 0;
foreach( $data as $player_id => $row ):
foreach ( $data as $player_id => $row ):
if ( ! $player_id )
continue;
@@ -298,10 +239,12 @@ if ( is_array( $teams ) ):
echo '<tr class="' . sp_array_value( $row, 'status', 'lineup' ) . ' ' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
$number = sp_array_value( $row, 'number', '&nbsp;' );
if ( isset( $labels['number'] ) ):
$number = sp_array_value( $row, 'number', '&nbsp;' );
// Player number
echo '<td class="data-number">' . $number . '</td>';
// Player number
echo '<td class="data-number">' . $number . '</td>';
endif;
if ( $link_posts ):
$permalink = get_post_permalink( $player_id );
@@ -312,14 +255,19 @@ if ( is_array( $teams ) ):
if ( $mode == 'icons' ) echo '<td class="sp-performance-icons">';
foreach( $labels as $key => $label ):
if ( $key == 'name' )
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 ] != '' ):
$position = get_term_by( 'id', $row[ $key ], 'sp_position' );
if ( $position ) $value = $position->name;
$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 ] != '' ):
@@ -359,15 +307,17 @@ if ( is_array( $teams ) ):
<tfoot>
<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">
<?php
echo '<td class="data-number">&nbsp;</td>';
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 ( $key == 'name' )
foreach ( $labels as $key => $label ):
if ( in_array( $key, array( 'number', 'name' ) ) )
continue;
if ( $key == 'position' ):
$value = '&mdash;';