Change Statistics (sp_stat) to Table Columns (sp_column)

This commit is contained in:
ThemeBoy
2013-12-27 15:37:04 +11:00
parent 3e99dc70a2
commit aae424aa4f
9 changed files with 45 additions and 46 deletions

View File

@@ -1,8 +1,8 @@
<?php
function sp_stat_cpt_init() {
$name = __( 'Statistics', 'sportspress' );
$singular_name = __( 'Statistic', 'sportspress' );
$lowercase_name = __( 'statistics', 'sportspress' );
function sp_column_cpt_init() {
$name = __( 'Table Columns', 'sportspress' );
$singular_name = __( 'Table Column', 'sportspress' );
$lowercase_name = __( 'table columns', 'sportspress' );
$labels = sp_cpt_labels( $name, $singular_name, $lowercase_name, true );
$args = array(
'label' => $name,
@@ -12,15 +12,14 @@ function sp_stat_cpt_init() {
'show_in_nav_menus' => false,
'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ),
'register_meta_box_cb' => 'sp_stat_meta_init',
'rewrite' => array( 'slug' => 'stat' ),
'register_meta_box_cb' => 'sp_column_meta_init',
'show_in_menu' => 'edit.php?post_type=sp_event'
);
register_post_type( 'sp_stat', $args );
register_post_type( 'sp_column', $args );
}
add_action( 'init', 'sp_stat_cpt_init' );
add_action( 'init', 'sp_column_cpt_init' );
function sp_stat_edit_columns() {
function sp_column_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
@@ -29,13 +28,13 @@ function sp_stat_edit_columns() {
);
return $columns;
}
add_filter( 'manage_edit-sp_stat_columns', 'sp_stat_edit_columns' );
add_filter( 'manage_edit-sp_column_columns', 'sp_column_edit_columns' );
function sp_stat_meta_init() {
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sp_stat_details_meta', 'sp_stat', 'normal', 'high' );
function sp_column_meta_init() {
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sp_column_details_meta', 'sp_column', 'normal', 'high' );
}
function sp_stat_details_meta( $post ) {
function sp_column_details_meta( $post ) {
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
$order = get_post_meta( $post->ID, 'sp_order', true );
$priority = get_post_meta( $post->ID, 'sp_priority', true );

View File

@@ -35,7 +35,7 @@ function sp_table_meta_init( $post ) {
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_table_team_meta', 'sp_table', 'side', 'high' );
if ( $teams && $teams != array(0) ):
add_meta_box( 'sp_statsdiv', __( 'League Table', 'sportspress' ), 'sp_table_stats_meta', 'sp_table', 'normal', 'high' );
add_meta_box( 'sp_columnsdiv', __( 'League Table', 'sportspress' ), 'sp_table_columns_meta', 'sp_table', 'normal', 'high' );
endif;
}
@@ -63,7 +63,7 @@ function sp_table_team_meta( $post, $test ) {
sp_nonce();
}
function sp_table_stats_meta( $post ) {
function sp_table_columns_meta( $post ) {
list( $columns, $data, $placeholders, $merged ) = sp_get_table( $post->ID, true );

View File

@@ -27,7 +27,7 @@ function sp_team_meta_init( $post ) {
add_meta_box( 'postimagediv', __( 'Logo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_team', 'side', 'high' );
if ( $leagues && $leagues != array(0) ):
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_team_stats_meta', 'sp_team', 'normal', 'high' );
add_meta_box( 'sp_columnssdiv', __( 'Table Columns', 'sportspress' ), 'sp_team_columns_meta', 'sp_team', 'normal', 'high' );
endif;
}
@@ -42,9 +42,9 @@ function sp_team_edit_columns() {
}
add_filter( 'manage_edit-sp_team_columns', 'sp_team_edit_columns' );
function sp_team_stats_meta( $post ) {
function sp_team_columns_meta( $post ) {
$leagues = (array)get_the_terms( $post->ID, 'sp_league' );
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
$columns = (array)get_post_meta( $post->ID, 'sp_columns', true );
// Equation Operating System
$eos = new eqEOS();
@@ -62,11 +62,11 @@ function sp_team_stats_meta( $post ) {
$div_ids[] = $value->term_id;
endforeach;
// Get all leagues populated with stats where available
$data = sp_array_combine( $div_ids, $stats );
// Get all leagues populated with columns where available
$data = sp_array_combine( $div_ids, $columns );
// Get equations from statistics variables
$equations = sp_get_var_equations( 'sp_stat' );
// Get equations from column variables
$equations = sp_get_var_equations( 'sp_column' );
// Initialize placeholders array
$placeholders = array();
@@ -139,9 +139,9 @@ function sp_team_stats_meta( $post ) {
endforeach;
// Get columns from statistics variables
$columns = sp_get_var_labels( 'sp_stat' );
$columns = sp_get_var_labels( 'sp_column' );
sp_team_stats_table( $columns, $data, $placeholders );
sp_team_columns_table( $columns, $data, $placeholders );
sp_nonce();
}
?>

View File

@@ -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_stat, .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_metric').find('input[name=post_name]').closest('label').remove();
});

View File

@@ -136,7 +136,7 @@ function sp_save_post( $post_id ) {
case ( 'sp_team' ):
// Update stats
update_post_meta( $post_id, 'sp_stats', sp_array_value( $_POST, 'sp_stats', array() ) );
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
break;
@@ -173,7 +173,7 @@ function sp_save_post( $post_id ) {
break;
case ( 'sp_stat' ):
case ( 'sp_column' ):
// Update equation as string
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );

View File

@@ -17,14 +17,14 @@ if ( !function_exists( 'sp_install_defaults' ) ) {
array( 'post_title' => 'Loss', 'post_name' => 'loss', 'post_status' => 'publish', 'post_type' => 'sp_outcome' ),
// Statistics
array( 'post_title' => 'P', 'post_name' => 'p', 'post_status' => 'publish', 'post_type' => 'sp_stat', 'meta' => array( 'sp_equation' => '$eventsplayed' ) ),
array( 'post_title' => 'W', 'post_name' => 'w', 'post_status' => 'publish', 'post_type' => 'sp_stat', 'meta' => array( 'sp_equation' => '$win' ) ),
array( 'post_title' => 'D', 'post_name' => 'd', 'post_status' => 'publish', 'post_type' => 'sp_stat', 'meta' => array( 'sp_equation' => '$draw' ) ),
array( 'post_title' => 'L', 'post_name' => 'l', 'post_status' => 'publish', 'post_type' => 'sp_stat', 'meta' => array( 'sp_equation' => '$loss' ) ),
array( 'post_title' => 'F', 'post_name' => 'f', 'post_status' => 'publish', 'post_type' => 'sp_stat', 'meta' => array( 'sp_equation' => '$goalsfor', 'sp_priority' => '3', 'sp_order' => 'DESC' ) ),
array( 'post_title' => 'A', 'post_name' => 'a', 'post_status' => 'publish', 'post_type' => 'sp_stat', 'meta' => array( 'sp_equation' => '$goalsagainst' ) ),
array( 'post_title' => 'GD', 'post_name' => 'gd', 'post_status' => 'publish', 'post_type' => 'sp_stat', '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_stat', 'meta' => array( 'sp_equation' => '$win x 3 + $draw', 'sp_priority' => '1', 'sp_order' => 'DESC' ) ),
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' ) ),
array( 'post_title' => 'L', 'post_name' => 'l', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$loss' ) ),
array( 'post_title' => 'F', 'post_name' => 'f', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$goalsfor', 'sp_priority' => '3', 'sp_order' => 'DESC' ) ),
array( 'post_title' => 'A', 'post_name' => 'a', 'post_status' => 'publish', 'post_type' => 'sp_column', 'meta' => array( 'sp_equation' => '$goalsagainst' ) ),
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' ) ),

View File

@@ -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_stat', 'sp_metric' ) ) ):
if ( isset( $_POST ) && array_key_exists( 'post_type', $_POST ) && in_array( $_POST['post_type'], array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_metric' ) ) ):
// 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_stat', 'sp_metric' ) ) ):
if ( in_array( $post_type, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_metric' ) ) ):
$wp_query->set( 'orderby', 'menu_order' );
$wp_query->set( 'order', 'ASC' );
endif;

View File

@@ -283,7 +283,7 @@ if ( !function_exists( 'sp_get_equation_optgroup_array' ) ) {
function sp_get_equation_optgroup_array( $postid, $type = null, $variations = null, $defaults = null, $totals = true ) {
$arr = array();
// Get stats within the sports that the current stat is in ### TODO: should be for sport selected
// Get posts
$args = array(
'post_type' => $type,
'numberposts' => -1,
@@ -343,8 +343,8 @@ if ( !function_exists( 'sp_get_equation_selector' ) ) {
case 'outcome':
$options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '&uarr;', 'min' => '&darr;' ) );
break;
case 'stat':
$options[ __( 'Statistics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_stat' );
case 'column':
$options[ __( 'Statistics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_column' );
break;
case 'metric':
$options[ __( 'Metrics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_metric' );
@@ -520,8 +520,8 @@ if ( !function_exists( 'sp_player_table' ) ) {
}
}
if ( !function_exists( 'sp_team_stats_table' ) ) {
function sp_team_stats_table( $columns = array(), $data = array(), $placeholders = array() ) {
if ( !function_exists( 'sp_team_columns_table' ) ) {
function sp_team_columns_table( $columns = array(), $data = array(), $placeholders = array() ) {
?>
<table class="widefat sp-data-table">
<thead>
@@ -554,7 +554,7 @@ if ( !function_exists( 'sp_team_stats_table' ) ) {
$value = sp_array_value( $div_stats, $column, '' );
$placeholder = sp_array_value( sp_array_value( $placeholders, $div_id, array() ), $column, 0 );
?>
<td><input type="text" name="sp_stats[<?php echo $div_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
<td><input type="text" name="sp_columns[<?php echo $div_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
<?php endforeach; ?>
</tr>
<?php
@@ -813,7 +813,7 @@ if ( !function_exists( 'sp_get_table' ) ) {
endforeach;
// Get statis stats
$static = get_post_meta( $team_id, 'sp_stats', true );
$static = get_post_meta( $team_id, 'sp_columns', true );
// Create placeholders entry for the team
$placeholders[ $team_id ] = array();
@@ -868,7 +868,7 @@ if ( !function_exists( 'sp_get_table' ) ) {
endforeach;
$args = array(
'post_type' => 'sp_stat',
'post_type' => 'sp_column',
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',

View File

@@ -37,7 +37,7 @@ include dirname( __FILE__ ) . '/sportspress-settings.php' ;
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/stat.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/team.php';
require_once dirname( __FILE__ ) . '/admin/post-types/table.php';