Add prepend and append options to player metrics
This commit is contained in:
@@ -42,6 +42,8 @@ class SP_Admin_CPT_Metric extends SP_Admin_CPT {
|
||||
'cb' => '<input type="checkbox" />',
|
||||
'title' => __( 'Label', 'sportspress' ),
|
||||
'sp_key' => __( 'Variable', 'sportspress' ),
|
||||
'sp_prepend' => __( 'Prepend', 'sportspress' ),
|
||||
'sp_append' => __( 'Append', 'sportspress' ),
|
||||
'sp_description' => __( 'Description', 'sportspress' ),
|
||||
);
|
||||
return apply_filters( 'sportspress_metric_admin_columns', $columns );
|
||||
@@ -57,6 +59,12 @@ class SP_Admin_CPT_Metric extends SP_Admin_CPT {
|
||||
global $post;
|
||||
echo $post->post_name;
|
||||
break;
|
||||
case 'sp_prepend':
|
||||
echo sp_get_post_prepend( $post_id );
|
||||
break;
|
||||
case 'sp_append':
|
||||
echo sp_get_post_append( $post_id );
|
||||
break;
|
||||
case 'sp_description':
|
||||
global $post;
|
||||
echo '<span class="description">' . $post->post_excerpt . '</span>';
|
||||
|
||||
@@ -23,12 +23,30 @@ class SP_Meta_Box_Metric_Details extends SP_Meta_Box_Config {
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
|
||||
$prepend = get_post_meta( $post->ID, 'sp_prepend', true );
|
||||
$append = get_post_meta( $post->ID, 'sp_append', true );
|
||||
?>
|
||||
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<input name="sp_default_key" type="hidden" id="sp_default_key" value="<?php echo $post->post_name; ?>">
|
||||
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>">
|
||||
</p>
|
||||
<p><strong><?php _e( 'Prepend', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<input name="sp_prepend" type="text" id="sp_prepend" value="<?php echo $prepend; ?>">
|
||||
</p>
|
||||
<p><strong><?php _e( 'Append', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<input name="sp_append" type="text" id="sp_append" value="<?php echo $append; ?>">
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_prepend', sp_array_value( $_POST, 'sp_prepend', array() ) );
|
||||
update_post_meta( $post_id, 'sp_append', sp_array_value( $_POST, 'sp_append', array() ) );
|
||||
}
|
||||
}
|
||||
@@ -34,9 +34,15 @@ class SP_Meta_Box_Player_Metrics {
|
||||
|
||||
if ( $vars ):
|
||||
foreach ( $vars as $var ):
|
||||
$prepend = get_post_meta( $var->ID, 'sp_prepend', true );
|
||||
$append = get_post_meta( $var->ID, 'sp_append', true );
|
||||
?>
|
||||
<p><strong><?php echo $var->post_title; ?></strong></p>
|
||||
<p><input type="text" name="sp_metrics[<?php echo $var->post_name; ?>]" value="<?php echo esc_attr( sp_array_value( $metrics, $var->post_name, '' ) ); ?>" /></p>
|
||||
<p>
|
||||
<?php echo ( $prepend ? '<span class="description">' . $prepend . '</span>' : '' ); ?>
|
||||
<input type="text" name="sp_metrics[<?php echo $var->post_name; ?>]" value="<?php echo esc_attr( sp_array_value( $metrics, $var->post_name, '' ) ); ?>" />
|
||||
<?php echo ( $append ? '<span class="description">' . $append . '</span>' : '' ); ?>
|
||||
</p>
|
||||
<?php
|
||||
endforeach;
|
||||
else:
|
||||
|
||||
@@ -295,6 +295,8 @@
|
||||
<tr>
|
||||
<th scope="col"><?php _e( 'Label', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Variable', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Prepend', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Append', 'sportspress' ); ?></th>
|
||||
<th scope="col"><?php _e( 'Description', 'sportspress' ); ?></th>
|
||||
<th scope="col" class="edit"></th>
|
||||
</tr>
|
||||
@@ -303,12 +305,14 @@
|
||||
<tr<?php if ( $i % 2 == 0 ) echo ' class="alternate"'; ?>>
|
||||
<td class="row-title"><?php echo $row->post_title; ?></td>
|
||||
<td><code><?php echo $row->post_name; ?></code></td>
|
||||
<td><?php echo sp_get_post_prepend( $row->ID ); ?></td>
|
||||
<td><?php echo sp_get_post_append( $row->ID ); ?></td>
|
||||
<td><p class="description"><?php echo $row->post_excerpt; ?></p></td>
|
||||
<td class="edit"><a class="button" href="<?php echo get_edit_post_link( $row->ID ); ?>"><?php _e( 'Edit', 'sportspress' ); ?></s></td>
|
||||
</tr>
|
||||
<?php $i++; endforeach; else: ?>
|
||||
<tr class="alternate">
|
||||
<td colspan="4"><?php _e( 'No results found.', 'sportspress' ); ?></td>
|
||||
<td colspan="6"><?php _e( 'No results found.', 'sportspress' ); ?></td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
|
||||
@@ -53,6 +53,24 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
|
||||
// Get labels from result variables
|
||||
$result_labels = (array)sp_get_var_labels( 'sp_result' );
|
||||
|
||||
// Get prepend and append from metric variables
|
||||
$args = array(
|
||||
'post_type' => 'sp_metric',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC',
|
||||
);
|
||||
|
||||
$vars = get_posts( $args );
|
||||
|
||||
$pa = array();
|
||||
foreach ( $vars as $var ) {
|
||||
$prepend = get_post_meta( $var->ID, 'sp_prepend', true );
|
||||
$append = get_post_meta( $var->ID, 'sp_append', true );
|
||||
$pa[ $var->post_name ] = array( $prepend, $append );
|
||||
}
|
||||
|
||||
// Get players automatically if set to auto
|
||||
if ( 'auto' == $select ) {
|
||||
@@ -169,6 +187,13 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
$adjustment = sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $key, null );
|
||||
if ( $adjustment != null )
|
||||
$metrics[ $key ] += $adjustment;
|
||||
|
||||
if ( '' !== $metrics[ $key ] ) {
|
||||
$prepend = sp_array_value( sp_array_value( $pa, $key, array() ), 0, null );
|
||||
$append = sp_array_value( sp_array_value( $pa, $key, array() ), 1, null );
|
||||
|
||||
$metrics[ $key ] = ( $prepend ? '<span class="sp-prepend">' . $prepend . '</span> ' : '' ) . $metrics[ $key ] . ( $append ? ' <span class="sp-append">' . $append . '</span>' : '' );
|
||||
}
|
||||
endforeach;
|
||||
|
||||
// Get static stats
|
||||
|
||||
@@ -88,14 +88,39 @@ class SP_Player extends SP_Custom_Post {
|
||||
* @return array
|
||||
*/
|
||||
public function metrics( $neg = null ) {
|
||||
$args = array(
|
||||
'post_type' => 'sp_metric',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC',
|
||||
);
|
||||
|
||||
$vars = get_posts( $args );
|
||||
|
||||
$data = array();
|
||||
|
||||
if ( ! $vars ) return $data;
|
||||
|
||||
$pa = array();
|
||||
foreach ( $vars as $var ) {
|
||||
$prepend = get_post_meta( $var->ID, 'sp_prepend', true );
|
||||
$append = get_post_meta( $var->ID, 'sp_append', true );
|
||||
$pa[ $var->post_name ] = array( $prepend, $append );
|
||||
}
|
||||
|
||||
$metrics = (array)get_post_meta( $this->ID, 'sp_metrics', true );
|
||||
$metric_labels = (array)sp_get_var_labels( 'sp_metric', $neg );
|
||||
$data = array();
|
||||
|
||||
foreach( $metric_labels as $key => $value ):
|
||||
$metric = sp_array_value( $metrics, $key, null );
|
||||
if ( $metric == null )
|
||||
continue;
|
||||
$data[ $value ] = sp_array_value( $metrics, $key, ' ' );
|
||||
|
||||
$prepend = sp_array_value( sp_array_value( $pa, $key, array() ), 0, null );
|
||||
$append = sp_array_value( sp_array_value( $pa, $key, array() ), 1, null );
|
||||
|
||||
$data[ $value ] = ( $prepend ? '<span class="sp-prepend">' . $prepend . '</span> ' : '' ) . sp_array_value( $metrics, $key, ' ' ) . ( $append ? ' <span class="sp-append">' . $append . '</span>' : '' );
|
||||
endforeach;
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -449,6 +449,28 @@ if ( !function_exists( 'sp_get_post_order' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_get_post_prepend' ) ) {
|
||||
function sp_get_post_prepend( $post_id ) {
|
||||
$prepend = get_post_meta ( $post_id, 'sp_prepend', true );
|
||||
if ( $prepend ):
|
||||
return $prepend;
|
||||
else:
|
||||
return '—';
|
||||
endif;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_get_post_append' ) ) {
|
||||
function sp_get_post_append( $post_id ) {
|
||||
$append = get_post_meta ( $post_id, 'sp_append', true );
|
||||
if ( $append ):
|
||||
return $append;
|
||||
else:
|
||||
return '—';
|
||||
endif;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_dropdown_statuses' ) ) {
|
||||
function sp_dropdown_statuses( $args = array() ) {
|
||||
$defaults = array(
|
||||
|
||||
Reference in New Issue
Block a user