diff --git a/admin-functions.php b/admin-functions.php
index 8f6b6dcd..25617a78 100644
--- a/admin-functions.php
+++ b/admin-functions.php
@@ -141,7 +141,7 @@ if ( !function_exists( 'sportspress_get_post_equation' ) ) {
if ( $equation ):
return str_replace(
array( '$', '+', '-', '*', '/' ),
- array( '', '+', '−', '×', '÷' ),
+ array( 'Σ ', '+', '−', '×', '÷' ),
$equation
);
else:
@@ -402,7 +402,7 @@ if ( !function_exists( 'sportspress_get_equation_selector' ) ) {
$options[ __( 'Columns', 'sportspress' ) ] = sportspress_get_equation_optgroup_array( $postid, 'sp_column' );
break;
case 'statistic':
- $options[ __( 'Statistics', 'sportspress' ) ] = sportspress_get_equation_optgroup_array( $postid, 'sp_statistic' );
+ $options[ __( 'Player Statistics', 'sportspress' ) ] = sportspress_get_equation_optgroup_array( $postid, 'sp_statistic' );
break;
endswitch;
endforeach;
@@ -445,32 +445,19 @@ if ( !function_exists( 'sportspress_get_equation_selector' ) ) {
}
if ( !function_exists( 'sportspress_get_var_labels' ) ) {
- function sportspress_get_var_labels( $post_type, $independent = false ) {
+ function sportspress_get_var_labels( $post_type ) {
$args = array(
'post_type' => $post_type,
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
- 'meta_query' => array(
- array(
- 'key' => 'sp_format',
- 'value' => 'custom',
- 'compare' => '!=',
- ),
- ),
);
$vars = get_posts( $args );
$output = array();
foreach ( $vars as $var ):
- if ( $independent ):
- $equation = get_post_meta( $var->ID, 'sp_equation', true );
- if ( $equation && $equation != '' ):
- continue;
- endif;
- endif;
$output[ $var->post_name ] = $var->post_title;
endforeach;
@@ -1003,13 +990,8 @@ if ( !function_exists( 'sportspress_get_table' ) ) {
// Get static stats
$static = get_post_meta( $team_id, 'sp_columns', true );
- // Create placeholders entry for the team
- $placeholders[ $team_id ] = array();
-
// Add static stats to placeholders
- if ( array_key_exists( $div_id, $static ) ):
- $placeholders[ $team_id ] = $static[ $div_id ];
- endif;
+ $placeholders[ $team_id ] = sportspress_array_value( $static, $div_id, array() );
endforeach;
@@ -1289,13 +1271,6 @@ if ( !function_exists( 'sportspress_get_list' ) ) {
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
- 'meta_query' => array(
- array(
- 'key' => 'sp_format',
- 'value' => 'custom',
- 'compare' => '!=',
- ),
- ),
);
$statistics = get_posts( $args );
diff --git a/admin/actions/manage-posts-custom-column.php b/admin/actions/manage-posts-custom-column.php
index 3548e18c..5750fb04 100644
--- a/admin/actions/manage-posts-custom-column.php
+++ b/admin/actions/manage-posts-custom-column.php
@@ -18,14 +18,19 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
$team = get_post( $team_id );
$outcome_slug = sportspress_array_value( sportspress_array_value( $results, $team_id, null ), 'outcome', null );
- $args=array(
- 'name' => $outcome_slug,
- 'post_type' => 'sp_outcome',
- 'post_status' => 'publish',
- 'posts_per_page' => 1
- );
- $outcomes = get_posts( $args );
- echo $team->post_title . ( $outcomes ? ' — ' . $outcomes[0]->post_title : '' ) . '
';
+ if ( $outcome_slug && $outcome_slug != '-1' ):
+ $args=array(
+ 'name' => $outcome_slug,
+ 'post_type' => 'sp_outcome',
+ 'post_status' => 'publish',
+ 'posts_per_page' => 1
+ );
+ $outcomes = get_posts( $args );
+
+ echo $team->post_title . ( $outcomes ? ' — ' . $outcomes[0]->post_title : '' ) . '
';
+ else:
+ echo $team->post_title . '
';
+ endif;
endforeach;
elseif ( $post_type == 'sp_player' ):
$results = get_post_meta( $post_id, 'sp_results', true );
@@ -33,15 +38,7 @@ function sportspress_manage_posts_custom_column( $column, $post_id ) {
if ( ! $team_id ) continue;
$team = get_post( $team_id );
$outcome_slug = sportspress_array_value( sportspress_array_value( $results, $team_id, null ), 'outcome', null );
-
- $args=array(
- 'name' => $outcome_slug,
- 'post_type' => 'sp_outcome',
- 'post_status' => 'publish',
- 'posts_per_page' => 1
- );
- $outcomes = get_posts( $args );
- echo $team->post_title . ( $outcomes ? ' — ' . $outcomes[0]->post_title : '' ) . '
';
+ echo $team->post_title . '
';
endforeach;
else:
foreach( $teams as $team_id ):
diff --git a/admin/actions/save-post.php b/admin/actions/save-post.php
index f810a795..a77aadef 100644
--- a/admin/actions/save-post.php
+++ b/admin/actions/save-post.php
@@ -60,9 +60,6 @@ function sportspress_save_post( $post_id ) {
// Update precision as integer
update_post_meta( $post_id, 'sp_precision', (int) sportspress_array_value( $_POST, 'sp_precision', 1 ) );
-
- // Update equation as string
- update_post_meta( $post_id, 'sp_equation', implode( ' ', sportspress_array_value( $_POST, 'sp_equation', array() ) ) );
// Update sort order as string
update_post_meta( $post_id, 'sp_priority', sportspress_array_value( $_POST, 'sp_priority', '0' ) );
@@ -90,8 +87,8 @@ function sportspress_save_post( $post_id ) {
// Update player number
update_post_meta( $post_id, 'sp_number', sportspress_array_value( $_POST, 'sp_number', '' ) );
- // Update player details array
- update_post_meta( $post_id, 'sp_details', sportspress_array_value( $_POST, 'sp_details', array() ) );
+ // Update player metrics array
+ update_post_meta( $post_id, 'sp_metrics', sportspress_array_value( $_POST, 'sp_metrics', array() ) );
break;
diff --git a/admin/post-types/event.php b/admin/post-types/event.php
index 475cd774..7a0d5e2a 100644
--- a/admin/post-types/event.php
+++ b/admin/post-types/event.php
@@ -94,7 +94,7 @@ function sportspress_event_players_meta( $post ) {
$stats = (array)get_post_meta( $post->ID, 'sp_players', true );
// Get columns from result variables
- $columns = sportspress_get_var_labels( 'sp_statistic', true );
+ $columns = sportspress_get_var_labels( 'sp_statistic' );
foreach ( $teams as $key => $team_id ):
if ( ! $team_id ) continue;
diff --git a/admin/post-types/metric.php b/admin/post-types/metric.php
new file mode 100644
index 00000000..6e5b7cb6
--- /dev/null
+++ b/admin/post-types/metric.php
@@ -0,0 +1,97 @@
+ $name,
+ 'labels' => $labels,
+ 'public' => false,
+ 'show_ui' => true,
+ 'show_in_menu' => false,
+ 'hierarchical' => false,
+ 'supports' => array( 'title', 'page-attributes' ),
+ 'register_meta_box_cb' => 'sportspress_metric_meta_init',
+ 'capability_type' => 'sp_config'
+ );
+ register_post_type( 'sp_metric', $args );
+}
+add_action( 'init', 'sportspress_metric_post_init' );
+
+function sportspress_metric_edit_columns() {
+ $columns = array(
+ 'cb' => '',
+ 'title' => __( 'Label', 'sportspress' ),
+ 'sp_key' => __( 'Key', 'sportspress' ),
+ 'sp_format' => __( 'Format', 'sportspress' ),
+ 'sp_equation' => __( 'Equation', 'sportspress' ),
+ 'sp_order' => __( 'Sort Order', 'sportspress' ),
+ );
+ return $columns;
+}
+add_filter( 'manage_edit-sp_metric_columns', 'sportspress_metric_edit_columns' );
+
+function sportspress_metric_meta_init() {
+ add_meta_box( 'sp_equationdiv', __( 'Details', 'sportspress' ), 'sportspress_metric_equation_meta', 'sp_metric', 'normal', 'high' );
+}
+
+function sportspress_metric_equation_meta( $post ) {
+ $formats = sportspress_get_config_formats();
+
+ $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 );
+ $precision = get_post_meta( $post->ID, 'sp_precision', true );
+
+ // Defaults
+ if ( $precision == '' ) $precision = 1;
+ ?>
+
+
+ +
++
+ +
++
+ +
++
+ ID, $piece, array( 'player_event' ) ); + endforeach; + ?> +
++
+ + +
+ post_content, 'content' ); } -function sportspress_player_details_meta( $post ) { +function sportspress_player_metrics_meta( $post ) { $number = get_post_meta( $post->ID, 'sp_number', true ); - $details = get_post_meta( $post->ID, 'sp_details', true ); + $details = get_post_meta( $post->ID, 'sp_metrics', true ); ?>@@ -202,17 +202,11 @@ function sportspress_player_details_meta( $post ) { 'sp_statistic', + 'post_type' => 'sp_metric', 'numberposts' => -1, 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order' => 'ASC', - 'meta_query' => array( - array( - 'key' => 'sp_format', - 'value' => 'custom', - ), - ), ); $vars = get_posts( $args ); @@ -222,7 +216,7 @@ function sportspress_player_details_meta( $post ) { ?>
post_title; ?>
- +
$name, diff --git a/admin/presets/soccer.php b/admin/presets/soccer.php index ff118b4b..9ed167b3 100644 --- a/admin/presets/soccer.php +++ b/admin/presets/soccer.php @@ -85,17 +85,8 @@ $sportspress_sports['soccer'] = array( ), ), ), - // Statistics + // Player Statistics 'sp_statistic' => array( - array( - 'post_title' => 'Appearances', - 'post_name' => 'appearances', - 'meta' => array( - 'sp_equation' => '$eventsplayed', - 'sp_format' => 'integer', - 'sp_precision' => 1, - ), - ), array( 'post_title' => 'Goals', 'post_name' => 'goals', @@ -134,12 +125,24 @@ $sportspress_sports['soccer'] = array( 'sp_precision' => 1, ), ), + ), + // Player Metrics + 'sp_metric' => array( + array( + 'post_title' => 'Appearances', + 'post_name' => 'appearances', + 'meta' => array( + 'sp_equation' => '$eventsplayed', + 'sp_format' => 'integer', + 'sp_precision' => 1, + ), + ), array( 'post_title' => 'Height', 'post_name' => 'height', 'meta' => array( 'sp_equation' => '', - 'sp_format' => 'custom', + 'sp_format' => 'integer', 'sp_precision' => 1, ), ), @@ -148,7 +151,7 @@ $sportspress_sports['soccer'] = array( 'post_name' => 'weight', 'meta' => array( 'sp_equation' => '', - 'sp_format' => 'custom', + 'sp_format' => 'integer', 'sp_precision' => 1, ), ), diff --git a/admin/settings/config.php b/admin/settings/config.php index f76fc6de..a1974383 100644 --- a/admin/settings/config.php +++ b/admin/settings/config.php @@ -45,7 +45,44 @@ ); $data = get_posts( $args ); ?> - + +| + | + | + | + | + |
|---|---|---|---|---|
| post_title; ?> | +post_name; ?> | +ID ); ?> | +Σ post_name; ?> | +ID ); ?> | +
| + | ||||
| + |
|---|