Use slugs to save event players stats

This commit is contained in:
ThemeBoy
2013-11-28 03:22:07 +11:00
parent 1c99143b7e
commit 2f78cc585d
2 changed files with 105 additions and 55 deletions

View File

@@ -72,8 +72,30 @@ function sp_event_team_meta( $post ) {
sp_nonce();
}
function sp_event_article_meta( $post ) {
wp_editor( $post->post_content, 'content' );
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 columns from result variables
$columns = sp_get_var_columns( 'sp_metric', true );
// Teams
foreach ( $teams as $key => $team_id ):
// 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, $team_id, array() ) );
?>
<div>
<p><strong><?php echo $team_id ? get_the_title( $team_id ) : sprintf( __( 'Select %s' ), 'Team' ); ?></strong></p>
<?php sp_event_players_table( $columns, $data, $team_id ); ?>
</div>
<?php
endforeach;
}
function sp_event_results_meta( $post ) {
@@ -81,48 +103,21 @@ function sp_event_results_meta( $post ) {
$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 columns from result variables
$columns = sp_get_var_columns( 'sp_result' );
// Get results for all teams
$data = sp_array_combine( $teams, $results );
// Get column names from settings
$stats_settings = get_option( 'sportspress_stats' );
$columns = sp_get_var_columns( 'sp_result', $post->ID );
?>
<div>
<?php sp_results_table( $columns, $data, array() ); ?>
<?php sp_event_results_table( $columns, $data ); ?>
</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_article_meta( $post ) {
wp_editor( $post->post_content, 'content' );
}
function sp_event_edit_columns() {

View File

@@ -385,15 +385,23 @@ if ( !function_exists( 'sp_get_eos_keys' ) ) {
if ( !function_exists( 'sp_get_var_columns' ) ) {
function sp_get_var_columns( $post_type, $exclude ) {
function sp_get_var_columns( $post_type, $indies = false ) {
$args = array(
'post_type' => $post_type,
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'exclude' => $exclude
'order' => 'ASC'
);
if ( $indies ):
$args['meta_query'] = array(
array(
'key' => 'sp_equation',
'value'=>''
)
);
endif;
$vars = get_posts( $args );
$output = array();
@@ -660,8 +668,8 @@ if ( !function_exists( 'sp_stats_table' ) ) {
}
}
if ( !function_exists( 'sp_results_table' ) ) {
function sp_results_table( $columns = array(), $data = array(), $placeholders = array() ) {
if ( !function_exists( 'sp_event_results_table' ) ) {
function sp_event_results_table( $columns = array(), $data = array() ) {
?>
<table class="widefat sp-stats-table">
<thead>
@@ -684,9 +692,8 @@ if ( !function_exists( 'sp_results_table' ) ) {
</td>
<?php foreach( $columns as $column => $label ):
$value = sp_array_value( $team_results, $column, '' );
$placeholder = (int)sp_array_value( sp_array_value( $placeholders, $team_id, 0), $column, 0 );
?>
<td><input type="text" name="sp_results[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
<td><input type="text" name="sp_results[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" /></td>
<?php endforeach; ?>
</tr>
<?php
@@ -699,13 +706,13 @@ if ( !function_exists( 'sp_results_table' ) ) {
}
}
if ( !function_exists( 'sp_players_table' ) ) {
function sp_players_table( $columns = array(), $data = array(), $placeholders = array() ) {
if ( !function_exists( 'sp_event_players_table' ) ) {
function sp_event_players_table( $columns = array(), $data = array(), $team_id ) {
?>
<table class="widefat sp-stats-table">
<thead>
<tr>
<th><?php _e( 'Team', 'sportspress' ); ?></th>
<th><?php _e( 'Player', 'sportspress' ); ?></th>
<?php foreach ( $columns as $label ): ?>
<th><?php echo $label; ?></th>
<?php endforeach; ?>
@@ -714,18 +721,66 @@ if ( !function_exists( 'sp_players_table' ) ) {
<tbody>
<?php
$i = 0;
foreach ( $data as $team_id => $team_results ):
if ( !$team_id ) continue;
foreach ( $data as $player_id => $player_metrics ):
if ( !$player_id ) continue;
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php echo get_the_title( $team_id ); ?>
<?php echo get_the_title( $player_id ); ?>
</td>
<?php foreach( $columns as $column => $label ):
$value = sp_array_value( $team_results, $column, '' );
$placeholder = (int)sp_array_value( sp_array_value( $placeholders, $team_id, 0), $column, 0 );
$value = sp_array_value( $player_metrics, $column, '' );
?>
<td><input type="text" name="sp_results[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
<td><input type="text" name="sp_stats[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="0" /></td>
<?php endforeach; ?>
</tr>
<?php
$i++;
endforeach;
?>
<tr class="sp-row sp-total<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
<?php foreach( $columns as $column => $label ):
$player_id = 0;
$player_metrics = $data[0];
$value = sp_array_value( $player_metrics, $column, '' );
?>
<td><input type="text" name="sp_stats[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="0" /></td>
<?php endforeach; ?>
</tr>
</tbody>
</table>
<?php
}
}
if ( !function_exists( 'sp_someother_table' ) ) {
function sp_someother_table( $columns = array(), $data = array(), $placeholders = array(), $team_id ) {
?>
<table class="widefat sp-stats-table">
<thead>
<tr>
<th><?php _e( 'Player', 'sportspress' ); ?></th>
<?php foreach ( $columns as $label ): ?>
<th><?php echo $label; ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ( $data as $player_id => $player_metrics ):
if ( !$player_id ) continue;
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php echo get_the_title( $player_id ); ?>
</td>
<?php foreach( $columns as $column => $label ):
$value = sp_array_value( $player_metrics, $column, '' );
$placeholder = (int)sp_array_value( sp_array_value( $placeholders, $player_id, 0), $column, 0 );
?>
<td><input type="text" name="sp_stats[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
<?php endforeach; ?>
</tr>
<?php
@@ -736,11 +791,11 @@ if ( !function_exists( 'sp_players_table' ) ) {
<tr class="sp-row sp-total<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
<?php foreach( $columns as $column => $label ):
$team_id = 0;
$value = sp_array_value( $team_results, $column, '' );
$placeholder = (int)sp_array_value( sp_array_value( $placeholders, $team_id, 0), $column, 0 );
$player_id = 0;
$value = sp_array_value( $player_metrics, $column, '' );
$placeholder = (int)sp_array_value( sp_array_value( $placeholders, $player_id, 0), $column, 0 );
?>
<td><input type="text" name="sp_results[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
<td><input type="text" name="sp_stats[<?php echo $team_id; ?>][<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
<?php endforeach; ?>
</tr>
</tbody>