Change Statistics (sp_stat) to Table Columns (sp_column)
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
function sp_stat_cpt_init() {
|
function sp_column_cpt_init() {
|
||||||
$name = __( 'Statistics', 'sportspress' );
|
$name = __( 'Table Columns', 'sportspress' );
|
||||||
$singular_name = __( 'Statistic', 'sportspress' );
|
$singular_name = __( 'Table Column', 'sportspress' );
|
||||||
$lowercase_name = __( 'statistics', 'sportspress' );
|
$lowercase_name = __( 'table columns', '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,15 +12,14 @@ function sp_stat_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_stat_meta_init',
|
'register_meta_box_cb' => 'sp_column_meta_init',
|
||||||
'rewrite' => array( 'slug' => 'stat' ),
|
|
||||||
'show_in_menu' => 'edit.php?post_type=sp_event'
|
'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(
|
$columns = array(
|
||||||
'cb' => '<input type="checkbox" />',
|
'cb' => '<input type="checkbox" />',
|
||||||
'title' => __( 'Label', 'sportspress' ),
|
'title' => __( 'Label', 'sportspress' ),
|
||||||
@@ -29,13 +28,13 @@ function sp_stat_edit_columns() {
|
|||||||
);
|
);
|
||||||
return $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() {
|
function sp_column_meta_init() {
|
||||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sp_stat_details_meta', 'sp_stat', 'normal', 'high' );
|
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 ) );
|
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
|
||||||
$order = get_post_meta( $post->ID, 'sp_order', true );
|
$order = get_post_meta( $post->ID, 'sp_order', true );
|
||||||
$priority = get_post_meta( $post->ID, 'sp_priority', true );
|
$priority = get_post_meta( $post->ID, 'sp_priority', true );
|
||||||
@@ -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' );
|
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_table_team_meta', 'sp_table', 'side', 'high' );
|
||||||
|
|
||||||
if ( $teams && $teams != array(0) ):
|
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;
|
endif;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ function sp_table_team_meta( $post, $test ) {
|
|||||||
sp_nonce();
|
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 );
|
list( $columns, $data, $placeholders, $merged ) = sp_get_table( $post->ID, true );
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ function sp_team_meta_init( $post ) {
|
|||||||
add_meta_box( 'postimagediv', __( 'Logo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_team', 'side', 'high' );
|
add_meta_box( 'postimagediv', __( 'Logo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_team', 'side', 'high' );
|
||||||
|
|
||||||
if ( $leagues && $leagues != array(0) ):
|
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;
|
endif;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,9 +42,9 @@ function sp_team_edit_columns() {
|
|||||||
}
|
}
|
||||||
add_filter( 'manage_edit-sp_team_columns', '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' );
|
$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
|
// Equation Operating System
|
||||||
$eos = new eqEOS();
|
$eos = new eqEOS();
|
||||||
@@ -62,11 +62,11 @@ function sp_team_stats_meta( $post ) {
|
|||||||
$div_ids[] = $value->term_id;
|
$div_ids[] = $value->term_id;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
// Get all leagues populated with stats where available
|
// Get all leagues populated with columns where available
|
||||||
$data = sp_array_combine( $div_ids, $stats );
|
$data = sp_array_combine( $div_ids, $columns );
|
||||||
|
|
||||||
// Get equations from statistics variables
|
// Get equations from column variables
|
||||||
$equations = sp_get_var_equations( 'sp_stat' );
|
$equations = sp_get_var_equations( 'sp_column' );
|
||||||
|
|
||||||
// Initialize placeholders array
|
// Initialize placeholders array
|
||||||
$placeholders = array();
|
$placeholders = array();
|
||||||
@@ -139,9 +139,9 @@ function sp_team_stats_meta( $post ) {
|
|||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
// Get columns from statistics variables
|
// 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();
|
sp_nonce();
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@@ -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_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();
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -136,7 +136,7 @@ function sp_save_post( $post_id ) {
|
|||||||
case ( 'sp_team' ):
|
case ( 'sp_team' ):
|
||||||
|
|
||||||
// Update stats
|
// 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;
|
break;
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ function sp_save_post( $post_id ) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ( 'sp_stat' ):
|
case ( 'sp_column' ):
|
||||||
|
|
||||||
// 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() ) ) );
|
||||||
|
|||||||
@@ -17,14 +17,14 @@ if ( !function_exists( 'sp_install_defaults' ) ) {
|
|||||||
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
|
// Statistics
|
||||||
array( 'post_title' => 'P', 'post_name' => 'p', 'post_status' => 'publish', 'post_type' => 'sp_stat', '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_stat', '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_stat', 'meta' => array( 'sp_equation' => '$draw' ) ),
|
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_stat', 'meta' => array( 'sp_equation' => '$loss' ) ),
|
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_stat', 'meta' => array( 'sp_equation' => '$goalsfor', 'sp_priority' => '3', 'sp_order' => 'DESC' ) ),
|
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_stat', 'meta' => array( 'sp_equation' => '$goalsagainst' ) ),
|
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_stat', '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_stat', '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
|
// Metrics
|
||||||
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_metric', 'meta' => array( 'sp_equation' => '$eventsplayed' ) ),
|
||||||
|
|||||||
@@ -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_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
|
// 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_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( 'orderby', 'menu_order' );
|
||||||
$wp_query->set( 'order', 'ASC' );
|
$wp_query->set( 'order', 'ASC' );
|
||||||
endif;
|
endif;
|
||||||
|
|||||||
@@ -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 ) {
|
function sp_get_equation_optgroup_array( $postid, $type = null, $variations = null, $defaults = null, $totals = true ) {
|
||||||
$arr = array();
|
$arr = array();
|
||||||
|
|
||||||
// Get stats within the sports that the current stat is in ### TODO: should be for sport selected
|
// Get posts
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_type' => $type,
|
'post_type' => $type,
|
||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
@@ -343,8 +343,8 @@ if ( !function_exists( 'sp_get_equation_selector' ) ) {
|
|||||||
case 'outcome':
|
case 'outcome':
|
||||||
$options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '↑', 'min' => '↓' ) );
|
$options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '↑', 'min' => '↓' ) );
|
||||||
break;
|
break;
|
||||||
case 'stat':
|
case 'column':
|
||||||
$options[ __( 'Statistics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_stat' );
|
$options[ __( 'Statistics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_column' );
|
||||||
break;
|
break;
|
||||||
case 'metric':
|
case 'metric':
|
||||||
$options[ __( 'Metrics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_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' ) ) {
|
if ( !function_exists( 'sp_team_columns_table' ) ) {
|
||||||
function sp_team_stats_table( $columns = array(), $data = array(), $placeholders = array() ) {
|
function sp_team_columns_table( $columns = array(), $data = array(), $placeholders = array() ) {
|
||||||
?>
|
?>
|
||||||
<table class="widefat sp-data-table">
|
<table class="widefat sp-data-table">
|
||||||
<thead>
|
<thead>
|
||||||
@@ -554,7 +554,7 @@ if ( !function_exists( 'sp_team_stats_table' ) ) {
|
|||||||
$value = sp_array_value( $div_stats, $column, '' );
|
$value = sp_array_value( $div_stats, $column, '' );
|
||||||
$placeholder = sp_array_value( sp_array_value( $placeholders, $div_id, array() ), $column, 0 );
|
$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; ?>
|
<?php endforeach; ?>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
@@ -813,7 +813,7 @@ if ( !function_exists( 'sp_get_table' ) ) {
|
|||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
// Get statis stats
|
// 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
|
// Create placeholders entry for the team
|
||||||
$placeholders[ $team_id ] = array();
|
$placeholders[ $team_id ] = array();
|
||||||
@@ -868,7 +868,7 @@ if ( !function_exists( 'sp_get_table' ) ) {
|
|||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_type' => 'sp_stat',
|
'post_type' => 'sp_column',
|
||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'orderby' => 'menu_order',
|
'orderby' => 'menu_order',
|
||||||
|
|||||||
@@ -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/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/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/metric.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';
|
||||||
|
|||||||
Reference in New Issue
Block a user