Add Player Metric (sp_metric) post type and behaviour
This commit is contained in:
@@ -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 );
|
||||
|
||||
|
||||
@@ -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 : '' ) . '<br>';
|
||||
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 : '' ) . '<br>';
|
||||
else:
|
||||
echo $team->post_title . '<br>';
|
||||
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 : '' ) . '<br>';
|
||||
echo $team->post_title . '<br>';
|
||||
endforeach;
|
||||
else:
|
||||
foreach( $teams as $team_id ):
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
97
admin/post-types/metric.php
Normal file
97
admin/post-types/metric.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
function sportspress_metric_post_init() {
|
||||
$name = __( 'Player Metrics', 'sportspress' );
|
||||
$singular_name = __( 'Player Metric', 'sportspress' );
|
||||
$lowercase_name = __( 'player metrics', 'sportspress' );
|
||||
$labels = sportspress_get_post_labels( $name, $singular_name, $lowercase_name, true );
|
||||
$args = array(
|
||||
'label' => $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' => '<input type="checkbox" />',
|
||||
'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;
|
||||
?>
|
||||
<p><strong><?php _e( 'Key', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>">
|
||||
</p>
|
||||
<p><strong><?php _e( 'Format', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-format-selector">
|
||||
<select name="sp_format">
|
||||
<?php
|
||||
foreach ( $formats as $key => $value ):
|
||||
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $priority, false ), $value );
|
||||
endforeach;
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Precision', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-precision-selector">
|
||||
<input name="sp_precision" type="text" size="4" id="sp_precision" value="<?php echo $precision; ?>" placeholder="1">
|
||||
</p>
|
||||
<p><strong><?php _e( 'Equation', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-equation-selector">
|
||||
<?php
|
||||
foreach ( $equation as $piece ):
|
||||
sportspress_get_equation_selector( $post->ID, $piece, array( 'player_event' ) );
|
||||
endforeach;
|
||||
?>
|
||||
</p>
|
||||
<p><strong><?php _e( 'Sort Order', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-order-selector">
|
||||
<select name="sp_priority">
|
||||
<?php
|
||||
$options = array( '0' => __( 'Disable', 'sportspress' ), '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10', );
|
||||
foreach ( $options as $key => $value ):
|
||||
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $priority, false ), $value );
|
||||
endforeach;
|
||||
?>
|
||||
</select>
|
||||
<select name="sp_order"<?php if ( ! $priority ): ?> disabled="disabled;"<?php endif; ?>>
|
||||
<?php
|
||||
$options = array( 'DESC' => __( 'Descending', 'sportspress' ), 'ASC' => __( 'Ascending', 'sportspress' ) );
|
||||
foreach ( $options as $key => $value ):
|
||||
printf( '<option value="%s" %s>%s</option>', $key, selected( true, $key == $order, false ), $value );
|
||||
endforeach;
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
<?php
|
||||
sportspress_nonce();
|
||||
}
|
||||
@@ -42,10 +42,10 @@ function sportspress_player_meta_init( $post ) {
|
||||
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sportspress_player_team_meta', 'sp_player', 'side', 'high' );
|
||||
|
||||
if ( $teams && $teams != array(0) && $seasons && is_array( $seasons ) && is_object( $seasons[0] ) ):
|
||||
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sportspress_player_stats_meta', 'sp_player', 'normal', 'high' );
|
||||
add_meta_box( 'sp_statsdiv', __( 'Player Statistics', 'sportspress' ), 'sportspress_player_stats_meta', 'sp_player', 'normal', 'high' );
|
||||
endif;
|
||||
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'sportspress_player_details_meta', 'sp_player', 'normal', 'high' );
|
||||
add_meta_box( 'sp_metricsdiv', __( 'Player Metrics', 'sportspress' ), 'sportspress_player_metrics_meta', 'sp_player', 'normal', 'high' );
|
||||
add_meta_box( 'sp_profilediv', __( 'Profile' ), 'sportspress_player_profile_meta', 'sp_player', 'normal', 'high' );
|
||||
|
||||
}
|
||||
@@ -189,10 +189,10 @@ function sportspress_player_profile_meta( $post ) {
|
||||
wp_editor( $post->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 );
|
||||
|
||||
?>
|
||||
<p><strong><?php _e( 'Player Number', 'sportspress' ); ?></strong></p>
|
||||
@@ -202,17 +202,11 @@ function sportspress_player_details_meta( $post ) {
|
||||
<?php
|
||||
|
||||
$args = array(
|
||||
'post_type' => '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 ) {
|
||||
?>
|
||||
<p><strong><?php echo $var->post_title; ?></strong></p>
|
||||
<p>
|
||||
<input name="sp_details[<?php echo $var->post_name; ?>]" type="text" value="<?php echo sportspress_array_value( $details, $var->post_name, ''); ?>">
|
||||
<input name="sp_metrics[<?php echo $var->post_name; ?>]" type="text" value="<?php echo sportspress_array_value( $details, $var->post_name, ''); ?>">
|
||||
</p>
|
||||
<?php
|
||||
endforeach;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
function sportspress_statistic_post_init() {
|
||||
$name = __( 'Statistics', 'sportspress' );
|
||||
$singular_name = __( 'Statistic', 'sportspress' );
|
||||
$lowercase_name = __( 'statistics', 'sportspress' );
|
||||
$name = __( 'Player Statistics', 'sportspress' );
|
||||
$singular_name = __( 'Player Statistic', 'sportspress' );
|
||||
$lowercase_name = __( 'player statistics', 'sportspress' );
|
||||
$labels = sportspress_get_post_labels( $name, $singular_name, $lowercase_name, true );
|
||||
$args = array(
|
||||
'label' => $name,
|
||||
|
||||
@@ -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,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -45,7 +45,44 @@
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<h3 class="title"><?php _e( 'Statistics', 'sportspress' ); ?></h3>
|
||||
<h3 class="title"><?php _e( 'Player Statistics', 'sportspress' ); ?></h3>
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th><?php _e( 'Key', 'sportspress' ); ?></th>
|
||||
<th><?php _e( 'Format', 'sportspress' ); ?></th>
|
||||
<th><?php _e( 'Equation', 'sportspress' ); ?></th>
|
||||
<th><?php _e( 'Sort Order', 'sportspress' ); ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||
<td><?php echo $row->post_name; ?></td>
|
||||
<td><?php echo sportspress_get_post_format( $row->ID ); ?></td>
|
||||
<td>Σ <?php echo $row->post_name; ?></td>
|
||||
<td><?php echo sportspress_get_post_order( $row->ID ); ?></td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; ?>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="5"><a href="<?php echo admin_url( 'edit.php?post_type=sp_statistic' ); ?>"><?php printf( __( 'Edit %s', 'sportspress' ), __( 'Player Statistics', 'sportspress' ) ); ?></a></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_metric',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC'
|
||||
);
|
||||
$data = get_posts( $args );
|
||||
?>
|
||||
<h3 class="title"><?php _e( 'Player Metrics', 'sportspress' ); ?></h3>
|
||||
<table class="widefat sp-admin-config-table">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -67,7 +104,7 @@
|
||||
<?php $i++; endforeach; ?>
|
||||
<tfoot>
|
||||
<tr>
|
||||
<th colspan="5"><a href="<?php echo admin_url( 'edit.php?post_type=sp_statistic' ); ?>"><?php printf( __( 'Edit %s', 'sportspress' ), __( 'Statistics', 'sportspress' ) ); ?></a></th>
|
||||
<th colspan="5"><a href="<?php echo admin_url( 'edit.php?post_type=sp_metric' ); ?>"><?php printf( __( 'Edit %s', 'sportspress' ), __( 'Player Metrics', 'sportspress' ) ); ?></a></th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
</table>
|
||||
@@ -96,7 +133,7 @@
|
||||
<?php $i = 0; foreach ( $data as $row ): ?>
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||
<td><?php echo $row->post_name; ?></td>
|
||||
<td><?php echo $row->post_name; ?>for / <?php echo $row->post_name; ?>against</td>
|
||||
<td><?php echo sportspress_get_post_format( $row->ID ); ?></td>
|
||||
<td>—</td>
|
||||
<td>—</td>
|
||||
|
||||
@@ -114,7 +114,7 @@ jQuery(document).ready(function($){
|
||||
if($(this).val() == 'custom') {
|
||||
$equationselector.prop( 'disabled', true );
|
||||
} else {
|
||||
$equationselector.prop( 'disabled', false )
|
||||
$equationselector.prop( 'disabled', false );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -37,11 +37,12 @@ include dirname( __FILE__ ) . '/admin/settings/settings.php' ;
|
||||
|
||||
// Custom post types
|
||||
require_once dirname( __FILE__ ) . '/admin/post-types/separator.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/column.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/post-types/statistic.php';
|
||||
require_once dirname( __FILE__ ) . '/admin/post-types/metric.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/event.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';
|
||||
|
||||
Reference in New Issue
Block a user