Enable player list adjustments
This commit is contained in:
@@ -146,6 +146,7 @@
|
||||
}
|
||||
|
||||
.sp-data-table-container {
|
||||
clear: both;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
|
||||
@@ -145,6 +145,7 @@ jQuery(document).ready(function($){
|
||||
placeholder = parseFloat($el.attr("data-placeholder"));
|
||||
current_adjustment = parseFloat($el.attr("data-adjustment"));
|
||||
adjustment = parseFloat($(this).val());
|
||||
if(isNaN(placeholder)) placeholder = 0;
|
||||
if(isNaN(current_adjustment)) current_adjustment = 0;
|
||||
if(isNaN(adjustment)) adjustment = 0;
|
||||
placeholder += adjustment - current_adjustment;
|
||||
|
||||
@@ -21,7 +21,7 @@ class SP_Meta_Box_List_Data {
|
||||
public static function output( $post ) {
|
||||
$list = new SP_Player_List( $post );
|
||||
list( $columns, $usecolumns, $data, $placeholders, $merged ) = $list->data( true );
|
||||
$adjustments = get_post_meta( $post->ID, 'sp_adjustments', true );
|
||||
$adjustments = $list->adjustments;
|
||||
self::table( $columns, $usecolumns, $data, $placeholders, $adjustments );
|
||||
}
|
||||
|
||||
@@ -37,11 +37,15 @@ class SP_Meta_Box_List_Data {
|
||||
/**
|
||||
* Admin edit table
|
||||
*/
|
||||
public static function table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array() ) {
|
||||
public static function table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array() ) {
|
||||
if ( is_array( $usecolumns ) )
|
||||
$usecolumns = array_filter( $usecolumns );
|
||||
?>
|
||||
<div class="sp-data-table-container">
|
||||
<ul class="subsubsub sp-table-bar">
|
||||
<li><a href="#sp-table-values" class="current"><?php _e( 'Values', 'sportspress' ); ?></a></li> |
|
||||
<li><a href="#sp-table-adjustments" class=""><?php _e( 'Adjustments', 'sportspress' ); ?></a></li>
|
||||
</ul>
|
||||
<div class="sp-data-table-container sp-table-panel sp-table-values" id="sp-table-values">
|
||||
<table class="widefat sp-data-table sp-player-list-table">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -55,6 +59,66 @@ class SP_Meta_Box_List_Data {
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
if ( is_array( $data ) && sizeof( $data ) > 0 ):
|
||||
$i = 0;
|
||||
foreach ( $data as $player_id => $player_stats ):
|
||||
if ( !$player_id ) continue;
|
||||
$div = get_term( $player_id, 'sp_season' );
|
||||
$number = get_post_meta( $player_id, 'sp_number', true );
|
||||
|
||||
$default_name = sp_array_value( $player_stats, 'name', '' );
|
||||
if ( $default_name == null )
|
||||
$default_name = get_the_title( $player_id );
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<td><?php echo ( $number ? $number : ' ' ); ?></td>
|
||||
<td>
|
||||
<span class="sp-default-value">
|
||||
<span class="sp-default-value-input"><?php echo $default_name; ?></span>
|
||||
<a class="dashicons dashicons-edit sp-edit" title="<?php _e( 'Edit', 'sportspress' ); ?>"></a>
|
||||
</span>
|
||||
<span class="hidden sp-custom-value">
|
||||
<input type="text" name="sp_players[<?php echo $player_id; ?>][name]" class="name sp-custom-value-input" value="<?php echo sp_array_value( $player_stats, 'name', '' ); ?>" placeholder="<?php echo get_the_title( $player_id ); ?>" size="6">
|
||||
<a class="button button-secondary sp-cancel"><?php _e( 'Cancel', 'sportspress' ); ?></a>
|
||||
<a class="button button-primary sp-save"><?php _e( 'Save', 'sportspress' ); ?></a>
|
||||
</span>
|
||||
</td>
|
||||
<?php foreach( $columns as $column => $label ):
|
||||
$value = sp_array_value( $player_stats, $column, '' );
|
||||
$placeholder = sp_array_value( sp_array_value( $placeholders, $player_id, array() ), $column, 0 );
|
||||
?>
|
||||
<td><input type="text" name="sp_players[<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" data-placeholder="<?php echo $placeholder; ?>" data-matrix="<?php echo $player_id; ?>_<?php echo $column; ?>" data-adjustment="<?php echo sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $column, 0 ); ?>" /></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
<?php
|
||||
$i++;
|
||||
endforeach;
|
||||
else:
|
||||
?>
|
||||
<tr class="sp-row alternate">
|
||||
<td colspan="<?php $colspan = sizeof( $columns ) + 1; echo $colspan; ?>">
|
||||
<?php printf( __( 'Select %s', 'sportspress' ), __( 'Players', 'sportspress' ) ); ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="sp-data-table-container sp-table-panel sp-table-adjustments hidden" id="sp-table-adjustments">
|
||||
<table class="widefat sp-data-table sp-player-list-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th><?php _e( 'Player', 'sportspress' ); ?></th>
|
||||
<?php foreach ( $columns as $key => $label ): ?>
|
||||
<th><?php echo $label; ?></th>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
if ( is_array( $data ) && sizeof( $data ) > 0 ):
|
||||
@@ -70,10 +134,9 @@ class SP_Meta_Box_List_Data {
|
||||
<?php echo get_the_title( $player_id ); ?>
|
||||
</td>
|
||||
<?php foreach( $columns as $column => $label ):
|
||||
$value = sp_array_value( $player_stats, $column, '' );
|
||||
$placeholder = sp_array_value( sp_array_value( $placeholders, $player_id, array() ), $column, 0 );
|
||||
$value = sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $column, '' );
|
||||
?>
|
||||
<td><input type="text" name="sp_players[<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
|
||||
<td><input type="text" name="sp_adjustments[<?php echo $player_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="0" data-matrix="<?php echo $player_id; ?>_<?php echo $column; ?>" /></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
@@ -225,7 +225,7 @@ class SP_League_Table extends SP_Custom_Post{
|
||||
$meta = get_post_meta( $stat->ID );
|
||||
|
||||
// Add equation to object
|
||||
$stat->equation = sp_array_value( sp_array_value( $meta, 'sp_equation', array() ), 0, 0 );
|
||||
$stat->equation = sp_array_value( sp_array_value( $meta, 'sp_equation', array() ), 0, null );
|
||||
$stat->precision = sp_array_value( sp_array_value( $meta, 'sp_precision', array() ), 0, 0 );
|
||||
|
||||
// Add column name to columns
|
||||
@@ -253,11 +253,18 @@ class SP_League_Table extends SP_Custom_Post{
|
||||
foreach ( $stats as $stat ):
|
||||
if ( sp_array_value( $placeholders[ $team_id ], $stat->post_name, '' ) == '' ):
|
||||
|
||||
// Solve
|
||||
$placeholder = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision );
|
||||
if ( $stat->equation == null ):
|
||||
$placeholder += sp_array_value( sp_array_value( $adjustments, $team_id, array() ), $stat->post_name, null );
|
||||
if ( $placeholder == null ):
|
||||
$placeholder = '-';
|
||||
endif;
|
||||
else:
|
||||
// Solve
|
||||
$placeholder = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision );
|
||||
|
||||
// Adjustments
|
||||
$placeholder += sp_array_value( sp_array_value( $adjustments, $team_id, array() ), $stat->post_name, 0 );
|
||||
// Adjustments
|
||||
$placeholder += sp_array_value( sp_array_value( $adjustments, $team_id, array() ), $stat->post_name, 0 );
|
||||
endif;
|
||||
|
||||
$placeholders[ $team_id ][ $stat->post_name ] = $placeholder;
|
||||
endif;
|
||||
|
||||
@@ -83,6 +83,11 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
|
||||
// Get metrics
|
||||
$metrics = get_post_meta( $player_id, 'sp_metrics', true );
|
||||
foreach ( $metrics as $key => $value ):
|
||||
$adjustment = sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $key, null );
|
||||
if ( $adjustment != null )
|
||||
$metrics[ $key ] += $adjustment;
|
||||
endforeach;
|
||||
|
||||
// Get static stats
|
||||
$static = get_post_meta( $player_id, 'sp_statistics', true );
|
||||
@@ -255,7 +260,10 @@ class SP_Player_List extends SP_Custom_Post {
|
||||
if ( sp_array_value( $placeholders[ $player_id ], $stat->post_name, '' ) == '' ):
|
||||
|
||||
if ( $stat->equation == null ):
|
||||
$placeholder = '-';
|
||||
$placeholder = sp_array_value( sp_array_value( $adjustments, $player_id, array() ), $stat->post_name, null );
|
||||
if ( $placeholder == null ):
|
||||
$placeholder = '-';
|
||||
endif;
|
||||
else:
|
||||
// Solve
|
||||
$placeholder = sp_solve( $stat->equation, sp_array_value( $totals, $player_id, array() ), $stat->precision );
|
||||
|
||||
Reference in New Issue
Block a user