Change Metrics (sp_metric) to Statistics (sp_statistic)

This commit is contained in:
ThemeBoy
2013-12-27 16:14:22 +11:00
parent aae424aa4f
commit 1fb727c210
9 changed files with 71 additions and 71 deletions

View File

@@ -83,7 +83,7 @@ function sp_event_players_meta( $post ) {
$stats = (array)get_post_meta( $post->ID, 'sp_players', true ); $stats = (array)get_post_meta( $post->ID, 'sp_players', true );
// Get columns from result variables // Get columns from result variables
$columns = sp_get_var_labels( 'sp_metric', true ); $columns = sp_get_var_labels( 'sp_statistic', true );
foreach ( $teams as $key => $team_id ): foreach ( $teams as $key => $team_id ):
if ( ! $team_id ) continue; if ( ! $team_id ) continue;

View File

@@ -44,13 +44,13 @@ function sp_player_team_meta( $post ) {
function sp_player_stats_meta( $post ) { function sp_player_stats_meta( $post ) {
$team_ids = (array)get_post_meta( $post->ID, 'sp_team', false ); $team_ids = (array)get_post_meta( $post->ID, 'sp_team', false );
$leagues = (array)get_the_terms( $post->ID, 'sp_league' ); $leagues = (array)get_the_terms( $post->ID, 'sp_league' );
$stats = (array)get_post_meta( $post->ID, 'sp_metrics', true ); $stats = (array)get_post_meta( $post->ID, 'sp_statistics', true );
// Equation Operating System // Equation Operating System
$eos = new eqEOS(); $eos = new eqEOS();
// Get labels from metric variables // Get labels from statistic variables
$metric_labels = (array)sp_get_var_labels( 'sp_metric' ); $statistic_labels = (array)sp_get_var_labels( 'sp_statistic' );
// Generate array of all league ids // Generate array of all league ids
$div_ids = array(); $div_ids = array();
@@ -82,13 +82,13 @@ function sp_player_stats_meta( $post ) {
$data[ $team_id ] = sp_array_combine( $div_ids, $stats[ $team_id ] ); $data[ $team_id ] = sp_array_combine( $div_ids, $stats[ $team_id ] );
// Get equations from statistics variables // Get equations from statistics variables
$equations = sp_get_var_equations( 'sp_metric' ); $equations = sp_get_var_equations( 'sp_statistic' );
foreach ( $div_ids as $div_id ): foreach ( $div_ids as $div_id ):
$totals = array( 'eventsattended' => 0, 'eventsplayed' => 0 ); $totals = array( 'eventsattended' => 0, 'eventsplayed' => 0 );
foreach ( $metric_labels as $key => $value ): foreach ( $statistic_labels as $key => $value ):
$totals[ $key ] = 0; $totals[ $key ] = 0;
endforeach; endforeach;
@@ -119,12 +119,12 @@ function sp_player_stats_meta( $post ) {
foreach( $events as $event ): foreach( $events as $event ):
$totals['eventsattended']++; $totals['eventsattended']++;
$totals['eventsplayed']++; // TODO: create tab for substitutes in sidebar $totals['eventsplayed']++; // TODO: create tab for substitutes in sidebar
$team_metrics = (array)get_post_meta( $event->ID, 'sp_players', true ); $team_statistics = (array)get_post_meta( $event->ID, 'sp_players', true );
if ( array_key_exists( $team_id, $team_metrics ) ): if ( array_key_exists( $team_id, $team_statistics ) ):
$players = sp_array_value( $team_metrics, $team_id, array() ); $players = sp_array_value( $team_statistics, $team_id, array() );
if ( array_key_exists( $post->ID, $players ) ): if ( array_key_exists( $post->ID, $players ) ):
$player_metrics = sp_array_value( $players, $post->ID, array() ); $player_statistics = sp_array_value( $players, $post->ID, array() );
foreach ( $player_metrics as $key => $value ): foreach ( $player_statistics as $key => $value ):
if ( array_key_exists( $key, $totals ) ): if ( array_key_exists( $key, $totals ) ):
$totals[ $key ] += $value; $totals[ $key ] += $value;
endif; endif;
@@ -154,7 +154,7 @@ function sp_player_stats_meta( $post ) {
endforeach; endforeach;
// Get columns from statistics variables // Get columns from statistics variables
$columns = sp_get_var_labels( 'sp_metric' ); $columns = sp_get_var_labels( 'sp_statistic' );
if ( $team_num > 1 ): if ( $team_num > 1 ):
?> ?>
@@ -162,7 +162,7 @@ function sp_player_stats_meta( $post ) {
<?php <?php
endif; endif;
sp_player_metrics_table( $columns, $data, $placeholders ); sp_player_statistics_table( $columns, $data, $placeholders );
endforeach; endforeach;
} }

View File

@@ -1,8 +1,8 @@
<?php <?php
function sp_metric_cpt_init() { function sp_statistic_cpt_init() {
$name = __( 'Metrics', 'sportspress' ); $name = __( 'Statistics', 'sportspress' );
$singular_name = __( 'Metric', 'sportspress' ); $singular_name = __( 'Statistic', 'sportspress' );
$lowercase_name = __( 'metrics', 'sportspress' ); $lowercase_name = __( 'statistics', 'sportspress' );
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name, true ); $labels = sp_cpt_labels( $name, $singular_name, $lowercase_name, true );
$args = array( $args = array(
'label' => $name, 'label' => $name,
@@ -12,14 +12,14 @@ function sp_metric_cpt_init() {
'show_in_nav_menus' => false, 'show_in_nav_menus' => false,
'hierarchical' => false, 'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ), 'supports' => array( 'title', 'page-attributes' ),
'register_meta_box_cb' => 'sp_metric_meta_init', 'register_meta_box_cb' => 'sp_statistic_meta_init',
'show_in_menu' => 'edit.php?post_type=sp_event' 'show_in_menu' => 'edit.php?post_type=sp_event'
); );
register_post_type( 'sp_metric', $args ); register_post_type( 'sp_statistic', $args );
} }
add_action( 'init', 'sp_metric_cpt_init' ); add_action( 'init', 'sp_statistic_cpt_init' );
function sp_metric_edit_columns() { function sp_statistic_edit_columns() {
$columns = array( $columns = array(
'cb' => '<input type="checkbox" />', 'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ), 'title' => __( 'Label', 'sportspress' ),
@@ -27,13 +27,13 @@ function sp_metric_edit_columns() {
); );
return $columns; return $columns;
} }
add_filter( 'manage_edit-sp_metric_columns', 'sp_metric_edit_columns' ); add_filter( 'manage_edit-sp_statistic_columns', 'sp_statistic_edit_columns' );
function sp_metric_meta_init() { function sp_statistic_meta_init() {
add_meta_box( 'sp_equationdiv', __( 'Equation', 'sportspress' ), 'sp_metric_equation_meta', 'sp_metric', 'normal', 'high' ); add_meta_box( 'sp_equationdiv', __( 'Equation', 'sportspress' ), 'sp_statistic_equation_meta', 'sp_statistic', 'normal', 'high' );
} }
function sp_metric_equation_meta( $post ) { function sp_statistic_equation_meta( $post ) {
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) ); $equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
?> ?>
<div> <div>

View File

@@ -86,6 +86,6 @@ jQuery(document).ready(function($){
$('.sp-equation-selector select:last').change().siblings().change(); $('.sp-equation-selector select:last').change().siblings().change();
// Remove slug editor in quick edit for slug-sensitive post types // Remove slug editor in quick edit for slug-sensitive post types
$('.inline-edit-sp_result, .inline-edit-sp_outcome, .inline-edit-sp_column, .inline-edit-sp_metric').find('input[name=post_name]').closest('label').remove(); $('.inline-edit-sp_result, .inline-edit-sp_outcome, .inline-edit-sp_column, .inline-edit-sp_statistic').find('input[name=post_name]').closest('label').remove();
}); });

View File

@@ -135,7 +135,7 @@ function sp_save_post( $post_id ) {
switch ( $_POST['post_type'] ): switch ( $_POST['post_type'] ):
case ( 'sp_team' ): case ( 'sp_team' ):
// Update stats // Update columns
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) ); update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
break; break;
@@ -148,7 +148,7 @@ function sp_save_post( $post_id ) {
// Update results // Update results
update_post_meta( $post_id, 'sp_results', $results ); update_post_meta( $post_id, 'sp_results', $results );
// Update player metrics // Update player statistics
update_post_meta( $post_id, 'sp_players', sp_array_value( $_POST, 'sp_players', array() ) ); update_post_meta( $post_id, 'sp_players', sp_array_value( $_POST, 'sp_players', array() ) );
// Update team array // Update team array
@@ -186,7 +186,7 @@ function sp_save_post( $post_id ) {
break; break;
case ( 'sp_metric' ): case ( 'sp_statistic' ):
// Update equation as string // Update equation as string
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) ); update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
@@ -195,8 +195,8 @@ function sp_save_post( $post_id ) {
case ( 'sp_player' ): case ( 'sp_player' ):
// Update player metrics // Update player statistics
update_post_meta( $post_id, 'sp_metrics', sp_array_value( $_POST, 'sp_metrics', array() ) ); update_post_meta( $post_id, 'sp_statistics', sp_array_value( $_POST, 'sp_statistics', array() ) );
// Update team array // Update team array
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) ); sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );

View File

@@ -16,7 +16,7 @@ if ( !function_exists( 'sp_install_defaults' ) ) {
array( 'post_title' => 'Draw', 'post_name' => 'draw', 'post_status' => 'publish', 'post_type' => 'sp_outcome' ), array( 'post_title' => 'Draw', 'post_name' => 'draw', 'post_status' => 'publish', 'post_type' => 'sp_outcome' ),
array( 'post_title' => 'Loss', 'post_name' => 'loss', 'post_status' => 'publish', 'post_type' => 'sp_outcome' ), array( 'post_title' => 'Loss', 'post_name' => 'loss', 'post_status' => 'publish', 'post_type' => 'sp_outcome' ),
// Statistics // Columns
array( 'post_title' => 'P', 'post_name' => 'p', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$eventsplayed' ) ), array( 'post_title' => 'P', 'post_name' => 'p', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$eventsplayed' ) ),
array( 'post_title' => 'W', 'post_name' => 'w', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$win' ) ), array( 'post_title' => 'W', 'post_name' => 'w', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$win' ) ),
array( 'post_title' => 'D', 'post_name' => 'd', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$draw' ) ), array( 'post_title' => 'D', 'post_name' => 'd', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$draw' ) ),
@@ -26,12 +26,12 @@ if ( !function_exists( 'sp_install_defaults' ) ) {
array( 'post_title' => 'GD', 'post_name' => 'gd', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$goalsfor - $goalsagainst', 'sp_priority' => '2', 'sp_order' => 'DESC' ) ), array( 'post_title' => 'GD', 'post_name' => 'gd', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$goalsfor - $goalsagainst', 'sp_priority' => '2', 'sp_order' => 'DESC' ) ),
array( 'post_title' => 'PTS', 'post_name' => 'pts', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$win x 3 + $draw', 'sp_priority' => '1', 'sp_order' => 'DESC' ) ), array( 'post_title' => 'PTS', 'post_name' => 'pts', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$win x 3 + $draw', 'sp_priority' => '1', 'sp_order' => 'DESC' ) ),
// Metrics // Statistics
array( 'post_title' => 'Appearances', 'post_name' => 'appearances', 'post_status' => 'publish', 'post_type' => 'sp_metric', 'meta' => array( 'sp_equation' => '$eventsplayed' ) ), array( 'post_title' => 'Appearances', 'post_name' => 'appearances', 'post_status' => 'publish', 'post_type' => 'sp_statistic', 'meta' => array( 'sp_equation' => '$eventsplayed' ) ),
array( 'post_title' => 'Goals', 'post_name' => 'goals', 'post_status' => 'publish', 'post_type' => 'sp_metric', 'meta' => array( 'sp_equation' => '' ) ), array( 'post_title' => 'Goals', 'post_name' => 'goals', 'post_status' => 'publish', 'post_type' => 'sp_statistic', 'meta' => array( 'sp_equation' => '' ) ),
array( 'post_title' => 'Assists', 'post_name' => 'assists', 'post_status' => 'publish', 'post_type' => 'sp_metric', 'meta' => array( 'sp_equation' => '' ) ), array( 'post_title' => 'Assists', 'post_name' => 'assists', 'post_status' => 'publish', 'post_type' => 'sp_statistic', 'meta' => array( 'sp_equation' => '' ) ),
array( 'post_title' => 'Yellow Cards', 'post_name' => 'yellowcards', 'post_status' => 'publish', 'post_type' => 'sp_metric', 'meta' => array( 'sp_equation' => '' ) ), array( 'post_title' => 'Yellow Cards', 'post_name' => 'yellowcards', 'post_status' => 'publish', 'post_type' => 'sp_statistic', 'meta' => array( 'sp_equation' => '' ) ),
array( 'post_title' => 'Red Cards', 'post_name' => 'redcards', 'post_status' => 'publish', 'post_type' => 'sp_metric', 'meta' => array( 'sp_equation' => '' ) ) array( 'post_title' => 'Red Cards', 'post_name' => 'redcards', 'post_status' => 'publish', 'post_type' => 'sp_statistic', 'meta' => array( 'sp_equation' => '' ) )
); );
$i = 1; $i = 1;

View File

@@ -59,7 +59,7 @@ add_filter('the_content', 'sportspress_the_content');
function sp_sanitize_title( $title ) { function sp_sanitize_title( $title ) {
if ( isset( $_POST ) && array_key_exists( 'post_type', $_POST ) && in_array( $_POST['post_type'], array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_metric' ) ) ): if ( isset( $_POST ) && array_key_exists( 'post_type', $_POST ) && in_array( $_POST['post_type'], array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
// Get post title // Get post title
$title = $_POST['post_title']; $title = $_POST['post_title'];
@@ -86,7 +86,7 @@ function sp_pre_get_posts( $wp_query ) {
if ( is_admin() ): if ( is_admin() ):
$post_type = $wp_query->query['post_type']; $post_type = $wp_query->query['post_type'];
if ( in_array( $post_type, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_metric' ) ) ): if ( in_array( $post_type, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_statistic' ) ) ):
$wp_query->set( 'orderby', 'menu_order' ); $wp_query->set( 'orderby', 'menu_order' );
$wp_query->set( 'order', 'ASC' ); $wp_query->set( 'order', 'ASC' );
endif; endif;

View File

@@ -344,10 +344,10 @@ if ( !function_exists( 'sp_get_equation_selector' ) ) {
$options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '&uarr;', 'min' => '&darr;' ) ); $options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '&uarr;', 'min' => '&darr;' ) );
break; break;
case 'column': case 'column':
$options[ __( 'Statistics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_column' ); $options[ __( 'Columns', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_column' );
break; break;
case 'metric': case 'statistic':
$options[ __( 'Metrics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_metric' ); $options[ __( 'Statistics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_statistic' );
break; break;
endswitch; endswitch;
endforeach; endforeach;
@@ -568,8 +568,8 @@ if ( !function_exists( 'sp_team_columns_table' ) ) {
} }
} }
if ( !function_exists( 'sp_player_metrics_table' ) ) { if ( !function_exists( 'sp_player_statistics_table' ) ) {
function sp_player_metrics_table( $columns = array(), $data = array(), $placeholders = array() ) { function sp_player_statistics_table( $columns = array(), $data = array(), $placeholders = array() ) {
?> ?>
<table class="widefat sp-data-table"> <table class="widefat sp-data-table">
<thead> <thead>
@@ -602,7 +602,7 @@ if ( !function_exists( 'sp_player_metrics_table' ) ) {
$value = sp_array_value( $div_stats, $column, '' ); $value = sp_array_value( $div_stats, $column, '' );
$placeholder = sp_array_value( sp_array_value( sp_array_value( $placeholders, $team_id, array() ), $div_id, array() ), $column, 0 ); $placeholder = sp_array_value( sp_array_value( sp_array_value( $placeholders, $team_id, array() ), $div_id, array() ), $column, 0 );
?> ?>
<td><input type="text" name="sp_metrics[<?php echo $team_id; ?>][<?php echo $div_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td> <td><input type="text" name="sp_statistics[<?php echo $team_id; ?>][<?php echo $div_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
<?php endforeach; ?> <?php endforeach; ?>
</tr> </tr>
<?php <?php
@@ -685,7 +685,7 @@ if ( !function_exists( 'sp_event_players_table' ) ) {
<tbody> <tbody>
<?php <?php
$i = 0; $i = 0;
foreach ( $data as $player_id => $player_metrics ): foreach ( $data as $player_id => $player_statistics ):
if ( !$player_id ) continue; if ( !$player_id ) continue;
?> ?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>"> <tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
@@ -693,7 +693,7 @@ if ( !function_exists( 'sp_event_players_table' ) ) {
<?php echo get_the_title( $player_id ); ?> <?php echo get_the_title( $player_id ); ?>
</td> </td>
<?php foreach( $columns as $column => $label ): <?php foreach( $columns as $column => $label ):
$value = sp_array_value( $player_metrics, $column, '' ); $value = sp_array_value( $player_statistics, $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; ?>]" value="<?php echo $value; ?>" placeholder="0" /></td>
<?php endforeach; ?> <?php endforeach; ?>
@@ -706,8 +706,8 @@ if ( !function_exists( 'sp_event_players_table' ) ) {
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td> <td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
<?php foreach( $columns as $column => $label ): <?php foreach( $columns as $column => $label ):
$player_id = 0; $player_id = 0;
$player_metrics = $data[0]; $player_statistics = $data[0];
$value = sp_array_value( $player_metrics, $column, '' ); $value = sp_array_value( $player_statistics, $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; ?>]" value="<?php echo $value; ?>" placeholder="0" /></td>
<?php endforeach; ?> <?php endforeach; ?>
@@ -812,7 +812,7 @@ if ( !function_exists( 'sp_get_table' ) ) {
$totals[ $team_id ][ $key ] = 0; $totals[ $team_id ][ $key ] = 0;
endforeach; endforeach;
// Get statis stats // Get static stats
$static = get_post_meta( $team_id, 'sp_columns', true ); $static = get_post_meta( $team_id, 'sp_columns', true );
// Create placeholders entry for the team // Create placeholders entry for the team
@@ -987,13 +987,13 @@ if ( !function_exists( 'sp_get_list' ) ) {
$eos = new eqEOS(); $eos = new eqEOS();
// Get labels from result variables // Get labels from result variables
$columns = (array)sp_get_var_labels( 'sp_metric' ); $columns = (array)sp_get_var_labels( 'sp_statistic' );
// Get all leagues populated with stats where available // Get all leagues populated with stats where available
$tempdata = sp_array_combine( $player_ids, $stats ); $tempdata = sp_array_combine( $player_ids, $stats );
// Get equations from statistics variables // Get equations from statistics variables
$equations = sp_get_var_equations( 'sp_metric' ); $equations = sp_get_var_equations( 'sp_statistic' );
// Create entry for each player in totals // Create entry for each player in totals
$totals = array(); $totals = array();
@@ -1009,13 +1009,13 @@ if ( !function_exists( 'sp_get_list' ) ) {
$totals[ $player_id ][ $key ] = 0; $totals[ $player_id ][ $key ] = 0;
endforeach; endforeach;
// Get static metrics // Get static statistics
$static = get_post_meta( $player_id, 'sp_metrics', true ); $static = get_post_meta( $player_id, 'sp_statistics', true );
// Create placeholders entry for the player // Create placeholders entry for the player
$placeholders[ $player_id ] = array(); $placeholders[ $player_id ] = array();
// Add static metrics to placeholders // Add static statistics to placeholders
if ( array_key_exists( $team_id, $static ) && array_key_exists( $div_id, $static[ $team_id ] ) ): if ( array_key_exists( $team_id, $static ) && array_key_exists( $div_id, $static[ $team_id ] ) ):
$placeholders[ $player_id ] = $static[ $team_id ][ $div_id ]; $placeholders[ $player_id ] = $static[ $team_id ][ $div_id ];
endif; endif;
@@ -1051,12 +1051,12 @@ if ( !function_exists( 'sp_get_list' ) ) {
$players = sp_array_value( $teams, $team_id, array() ); $players = sp_array_value( $teams, $team_id, array() );
foreach ( $players as $player_id => $player_metrics ): foreach ( $players as $player_id => $player_statistics ):
// Increment events played // Increment events played
$totals[ $player_id ]['eventsplayed']++; $totals[ $player_id ]['eventsplayed']++;
foreach ( $player_metrics as $key => $value ): foreach ( $player_statistics as $key => $value ):
if ( array_key_exists( $key, $totals[ $player_id ] ) ): if ( array_key_exists( $key, $totals[ $player_id ] ) ):
$totals[ $player_id ][ $key ] += $value; $totals[ $player_id ][ $key ] += $value;
@@ -1069,33 +1069,33 @@ if ( !function_exists( 'sp_get_list' ) ) {
endforeach; endforeach;
$args = array( $args = array(
'post_type' => 'sp_metric', 'post_type' => 'sp_statistic',
'numberposts' => -1, 'numberposts' => -1,
'posts_per_page' => -1, 'posts_per_page' => -1,
'orderby' => 'menu_order', 'orderby' => 'menu_order',
'order' => 'ASC' 'order' => 'ASC'
); );
$metrics = get_posts( $args ); $statistics = get_posts( $args );
$columns = array(); $columns = array();
$priorities = array(); $priorities = array();
foreach ( $metrics as $metric ): foreach ( $statistics as $statistic ):
// Get post meta // Get post meta
$meta = get_post_meta( $metric->ID ); $meta = get_post_meta( $statistic->ID );
// Add equation to object // Add equation to object
$metric->equation = sp_array_value( sp_array_value( $meta, 'sp_equation', array() ), 0, 0 ); $statistic->equation = sp_array_value( sp_array_value( $meta, 'sp_equation', array() ), 0, 0 );
// Add column name to columns // Add column name to columns
$columns[ $metric->post_name ] = $metric->post_title; $columns[ $statistic->post_name ] = $statistic->post_title;
// Add order to priorities if priority is set and does not exist in array already // Add order to priorities if priority is set and does not exist in array already
$priority = sp_array_value( sp_array_value( $meta, 'sp_priority', array() ), 0, 0 ); $priority = sp_array_value( sp_array_value( $meta, 'sp_priority', array() ), 0, 0 );
if ( $priority && ! array_key_exists( $priorities, $priority ) ): if ( $priority && ! array_key_exists( $priorities, $priority ) ):
$priorities[ $priority ] = array( $priorities[ $priority ] = array(
'column' => $metric->post_name, 'column' => $statistic->post_name,
'order' => sp_array_value( sp_array_value( $meta, 'sp_order', array() ), 0, 'DESC' ) 'order' => sp_array_value( sp_array_value( $meta, 'sp_order', array() ), 0, 'DESC' )
); );
endif; endif;
@@ -1111,18 +1111,18 @@ if ( !function_exists( 'sp_get_list' ) ) {
if ( ! $player_id ) if ( ! $player_id )
continue; continue;
foreach ( $metrics as $metric ): foreach ( $statistics as $statistic ):
if ( sp_array_value( $placeholders[ $player_id ], $metric->post_name, '' ) == '' ): if ( sp_array_value( $placeholders[ $player_id ], $statistic->post_name, '' ) == '' ):
if ( empty( $metric->equation ) ): if ( empty( $statistic->equation ) ):
// Reflect totals // Reflect totals
$placeholders[ $player_id ][ $metric->post_name ] = sp_array_value( sp_array_value( $totals, $player_id, array() ), $key, 0 ); $placeholders[ $player_id ][ $statistic->post_name ] = sp_array_value( sp_array_value( $totals, $player_id, array() ), $key, 0 );
else: else:
// Calculate value // Calculate value
$placeholders[ $player_id ][ $metric->post_name ] = $eos->solveIF( str_replace( ' ', '', $metric->equation ), sp_array_value( $totals, $player_id, array() ) ); $placeholders[ $player_id ][ $statistic->post_name ] = $eos->solveIF( str_replace( ' ', '', $statistic->equation ), sp_array_value( $totals, $player_id, array() ) );
endif; endif;
endif; endif;

View File

@@ -38,7 +38,7 @@ require_once dirname( __FILE__ ) . '/admin/post-types/event.php';
require_once dirname( __FILE__ ) . '/admin/post-types/result.php'; require_once dirname( __FILE__ ) . '/admin/post-types/result.php';
require_once dirname( __FILE__ ) . '/admin/post-types/outcome.php'; require_once dirname( __FILE__ ) . '/admin/post-types/outcome.php';
require_once dirname( __FILE__ ) . '/admin/post-types/column.php'; require_once dirname( __FILE__ ) . '/admin/post-types/column.php';
require_once dirname( __FILE__ ) . '/admin/post-types/metric.php'; require_once dirname( __FILE__ ) . '/admin/post-types/statistic.php';
require_once dirname( __FILE__ ) . '/admin/post-types/team.php'; require_once dirname( __FILE__ ) . '/admin/post-types/team.php';
require_once dirname( __FILE__ ) . '/admin/post-types/table.php'; require_once dirname( __FILE__ ) . '/admin/post-types/table.php';
require_once dirname( __FILE__ ) . '/admin/post-types/player.php'; require_once dirname( __FILE__ ) . '/admin/post-types/player.php';