From 1fb727c2103c919cd4bc463ded17fbcc23e6648f Mon Sep 17 00:00:00 2001 From: ThemeBoy Date: Fri, 27 Dec 2013 16:14:22 +1100 Subject: [PATCH] Change Metrics (sp_metric) to Statistics (sp_statistic) --- admin/post-types/event.php | 2 +- admin/post-types/player.php | 24 ++++---- .../post-types/{metric.php => statistic.php} | 24 ++++---- assets/js/admin.js | 2 +- sportspress-actions.php | 10 ++-- sportspress-defaults.php | 14 ++--- sportspress-filters.php | 4 +- sportspress-functions.php | 60 +++++++++---------- sportspress.php | 2 +- 9 files changed, 71 insertions(+), 71 deletions(-) rename admin/post-types/{metric.php => statistic.php} (59%) diff --git a/admin/post-types/event.php b/admin/post-types/event.php index a39adcc4..3500286d 100644 --- a/admin/post-types/event.php +++ b/admin/post-types/event.php @@ -83,7 +83,7 @@ function sp_event_players_meta( $post ) { $stats = (array)get_post_meta( $post->ID, 'sp_players', true ); // 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 ): if ( ! $team_id ) continue; diff --git a/admin/post-types/player.php b/admin/post-types/player.php index c26c47b6..5bd80a6e 100644 --- a/admin/post-types/player.php +++ b/admin/post-types/player.php @@ -44,13 +44,13 @@ function sp_player_team_meta( $post ) { function sp_player_stats_meta( $post ) { $team_ids = (array)get_post_meta( $post->ID, 'sp_team', false ); $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 $eos = new eqEOS(); - // Get labels from metric variables - $metric_labels = (array)sp_get_var_labels( 'sp_metric' ); + // Get labels from statistic variables + $statistic_labels = (array)sp_get_var_labels( 'sp_statistic' ); // Generate array of all league ids $div_ids = array(); @@ -82,13 +82,13 @@ function sp_player_stats_meta( $post ) { $data[ $team_id ] = sp_array_combine( $div_ids, $stats[ $team_id ] ); // 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 ): $totals = array( 'eventsattended' => 0, 'eventsplayed' => 0 ); - foreach ( $metric_labels as $key => $value ): + foreach ( $statistic_labels as $key => $value ): $totals[ $key ] = 0; endforeach; @@ -119,12 +119,12 @@ function sp_player_stats_meta( $post ) { foreach( $events as $event ): $totals['eventsattended']++; $totals['eventsplayed']++; // TODO: create tab for substitutes in sidebar - $team_metrics = (array)get_post_meta( $event->ID, 'sp_players', true ); - if ( array_key_exists( $team_id, $team_metrics ) ): - $players = sp_array_value( $team_metrics, $team_id, array() ); + $team_statistics = (array)get_post_meta( $event->ID, 'sp_players', true ); + if ( array_key_exists( $team_id, $team_statistics ) ): + $players = sp_array_value( $team_statistics, $team_id, array() ); if ( array_key_exists( $post->ID, $players ) ): - $player_metrics = sp_array_value( $players, $post->ID, array() ); - foreach ( $player_metrics as $key => $value ): + $player_statistics = sp_array_value( $players, $post->ID, array() ); + foreach ( $player_statistics as $key => $value ): if ( array_key_exists( $key, $totals ) ): $totals[ $key ] += $value; endif; @@ -154,7 +154,7 @@ function sp_player_stats_meta( $post ) { endforeach; // Get columns from statistics variables - $columns = sp_get_var_labels( 'sp_metric' ); + $columns = sp_get_var_labels( 'sp_statistic' ); if ( $team_num > 1 ): ?> @@ -162,7 +162,7 @@ function sp_player_stats_meta( $post ) { $name, @@ -12,14 +12,14 @@ function sp_metric_cpt_init() { 'show_in_nav_menus' => false, 'hierarchical' => false, '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' ); - 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( 'cb' => '', 'title' => __( 'Label', 'sportspress' ), @@ -27,13 +27,13 @@ function sp_metric_edit_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() { - add_meta_box( 'sp_equationdiv', __( 'Equation', 'sportspress' ), 'sp_metric_equation_meta', 'sp_metric', 'normal', 'high' ); +function sp_statistic_meta_init() { + 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 ) ); ?>
diff --git a/assets/js/admin.js b/assets/js/admin.js index ee4aa766..e19626ad 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -86,6 +86,6 @@ jQuery(document).ready(function($){ $('.sp-equation-selector select:last').change().siblings().change(); // 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(); }); \ No newline at end of file diff --git a/sportspress-actions.php b/sportspress-actions.php index f2cb3f77..87924d29 100644 --- a/sportspress-actions.php +++ b/sportspress-actions.php @@ -135,7 +135,7 @@ function sp_save_post( $post_id ) { switch ( $_POST['post_type'] ): case ( 'sp_team' ): - // Update stats + // Update columns update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) ); break; @@ -148,7 +148,7 @@ function sp_save_post( $post_id ) { // Update 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 team array @@ -186,7 +186,7 @@ function sp_save_post( $post_id ) { break; - case ( 'sp_metric' ): + case ( 'sp_statistic' ): // Update equation as string 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' ): - // Update player metrics - update_post_meta( $post_id, 'sp_metrics', sp_array_value( $_POST, 'sp_metrics', array() ) ); + // Update player statistics + update_post_meta( $post_id, 'sp_statistics', sp_array_value( $_POST, 'sp_statistics', array() ) ); // Update team array sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) ); diff --git a/sportspress-defaults.php b/sportspress-defaults.php index 6a910eac..4b54dc99 100644 --- a/sportspress-defaults.php +++ b/sportspress-defaults.php @@ -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' => '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' => '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' ) ), @@ -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' => '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 - array( 'post_title' => 'Appearances', 'post_name' => 'appearances', 'post_status' => 'publish', 'post_type' => 'sp_metric', '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' => 'Assists', 'post_name' => 'assists', '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_metric', 'meta' => array( 'sp_equation' => '' ) ), - array( 'post_title' => 'Red Cards', 'post_name' => 'redcards', 'post_status' => 'publish', 'post_type' => 'sp_metric', 'meta' => array( 'sp_equation' => '' ) ) + // Statistics + 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_statistic', '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_statistic', '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; diff --git a/sportspress-filters.php b/sportspress-filters.php index 81f0aa10..62df055e 100644 --- a/sportspress-filters.php +++ b/sportspress-filters.php @@ -59,7 +59,7 @@ add_filter('the_content', 'sportspress_the_content'); 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 $title = $_POST['post_title']; @@ -86,7 +86,7 @@ function sp_pre_get_posts( $wp_query ) { if ( is_admin() ): $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( 'order', 'ASC' ); endif; diff --git a/sportspress-functions.php b/sportspress-functions.php index cd71d0a3..8c1d46b1 100644 --- a/sportspress-functions.php +++ b/sportspress-functions.php @@ -344,10 +344,10 @@ if ( !function_exists( 'sp_get_equation_selector' ) ) { $options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '↑', 'min' => '↓' ) ); break; 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; - case 'metric': - $options[ __( 'Metrics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_metric' ); + case 'statistic': + $options[ __( 'Statistics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_statistic' ); break; endswitch; endforeach; @@ -568,8 +568,8 @@ if ( !function_exists( 'sp_team_columns_table' ) ) { } } -if ( !function_exists( 'sp_player_metrics_table' ) ) { - function sp_player_metrics_table( $columns = array(), $data = array(), $placeholders = array() ) { +if ( !function_exists( 'sp_player_statistics_table' ) ) { + function sp_player_statistics_table( $columns = array(), $data = array(), $placeholders = array() ) { ?> @@ -602,7 +602,7 @@ if ( !function_exists( 'sp_player_metrics_table' ) ) { $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 ); ?> - + $player_metrics ): + foreach ( $data as $player_id => $player_statistics ): if ( !$player_id ) continue; ?> @@ -693,7 +693,7 @@ if ( !function_exists( 'sp_event_players_table' ) ) { $label ): - $value = sp_array_value( $player_metrics, $column, '' ); + $value = sp_array_value( $player_statistics, $column, '' ); ?> @@ -706,8 +706,8 @@ if ( !function_exists( 'sp_event_players_table' ) ) { $label ): $player_id = 0; - $player_metrics = $data[0]; - $value = sp_array_value( $player_metrics, $column, '' ); + $player_statistics = $data[0]; + $value = sp_array_value( $player_statistics, $column, '' ); ?> @@ -812,7 +812,7 @@ if ( !function_exists( 'sp_get_table' ) ) { $totals[ $team_id ][ $key ] = 0; endforeach; - // Get statis stats + // Get static stats $static = get_post_meta( $team_id, 'sp_columns', true ); // Create placeholders entry for the team @@ -987,13 +987,13 @@ if ( !function_exists( 'sp_get_list' ) ) { $eos = new eqEOS(); // 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 $tempdata = sp_array_combine( $player_ids, $stats ); // 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 $totals = array(); @@ -1009,13 +1009,13 @@ if ( !function_exists( 'sp_get_list' ) ) { $totals[ $player_id ][ $key ] = 0; endforeach; - // Get static metrics - $static = get_post_meta( $player_id, 'sp_metrics', true ); + // Get static statistics + $static = get_post_meta( $player_id, 'sp_statistics', true ); // Create placeholders entry for the player $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 ] ) ): $placeholders[ $player_id ] = $static[ $team_id ][ $div_id ]; endif; @@ -1051,12 +1051,12 @@ if ( !function_exists( 'sp_get_list' ) ) { $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 $totals[ $player_id ]['eventsplayed']++; - foreach ( $player_metrics as $key => $value ): + foreach ( $player_statistics as $key => $value ): if ( array_key_exists( $key, $totals[ $player_id ] ) ): $totals[ $player_id ][ $key ] += $value; @@ -1069,33 +1069,33 @@ if ( !function_exists( 'sp_get_list' ) ) { endforeach; $args = array( - 'post_type' => 'sp_metric', + 'post_type' => 'sp_statistic', 'numberposts' => -1, 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC' ); - $metrics = get_posts( $args ); + $statistics = get_posts( $args ); $columns = array(); $priorities = array(); - foreach ( $metrics as $metric ): + foreach ( $statistics as $statistic ): // Get post meta - $meta = get_post_meta( $metric->ID ); + $meta = get_post_meta( $statistic->ID ); // 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 - $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 $priority = sp_array_value( sp_array_value( $meta, 'sp_priority', array() ), 0, 0 ); if ( $priority && ! array_key_exists( $priorities, $priority ) ): $priorities[ $priority ] = array( - 'column' => $metric->post_name, + 'column' => $statistic->post_name, 'order' => sp_array_value( sp_array_value( $meta, 'sp_order', array() ), 0, 'DESC' ) ); endif; @@ -1111,18 +1111,18 @@ if ( !function_exists( 'sp_get_list' ) ) { if ( ! $player_id ) continue; - foreach ( $metrics as $metric ): - if ( sp_array_value( $placeholders[ $player_id ], $metric->post_name, '' ) == '' ): + foreach ( $statistics as $statistic ): + if ( sp_array_value( $placeholders[ $player_id ], $statistic->post_name, '' ) == '' ): - if ( empty( $metric->equation ) ): + if ( empty( $statistic->equation ) ): // 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: // 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; diff --git a/sportspress.php b/sportspress.php index 10751d26..cf0140c6 100644 --- a/sportspress.php +++ b/sportspress.php @@ -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/outcome.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/table.php'; require_once dirname( __FILE__ ) . '/admin/post-types/player.php';