Enable league table adjustments

This commit is contained in:
Brian Miyaji
2014-03-29 13:45:20 +11:00
parent bc37b259d3
commit b6ca212ed1
4 changed files with 116 additions and 35 deletions

View File

@@ -937,12 +937,16 @@ if ( !function_exists( 'sp_edit_calendar_table' ) ) {
}
if ( !function_exists( 'sp_edit_league_table' ) ) {
function sp_edit_league_table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array() ) {
function sp_edit_league_table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array() ) {
if ( is_array( $usecolumns ) )
$usecolumns = array_filter( $usecolumns );
$show_team_logo = get_option( 'sportspress_table_show_logos', false );
?>
<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-league-table">
<thead>
<tr>
@@ -963,7 +967,6 @@ if ( !function_exists( 'sp_edit_league_table' ) ) {
if ( !$team_id )
continue;
$div = get_term( $team_id, 'sp_season' );
$default_name = sp_array_value( $team_stats, 'name', '' );
if ( $default_name == null )
$default_name = get_the_title( $team_id );
@@ -971,12 +974,12 @@ if ( !function_exists( 'sp_edit_league_table' ) ) {
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php if ( $show_team_logo ) echo get_the_post_thumbnail( $team_id, 'sportspress-fit-icon' ); ?>
<span class="sp-default-name">
<span class="sp-default-name-input"><?php echo $default_name; ?></span>
<a class="dashicons dashicons-edit sp-edit-name" title="<?php _e( 'Edit', 'sportspress' ); ?>"></a>
<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-name">
<input type="text" name="sp_teams[<?php echo $team_id; ?>][name]" class="name sp-custom-name-input" value="<?php echo sp_array_value( $team_stats, 'name', '' ); ?>" placeholder="<?php echo get_the_title( $team_id ); ?>" size="6">
<span class="hidden sp-custom-value">
<input type="text" name="sp_teams[<?php echo $team_id; ?>][name]" class="name sp-custom-value-input" value="<?php echo sp_array_value( $team_stats, 'name', '' ); ?>" placeholder="<?php echo get_the_title( $team_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>
@@ -985,7 +988,51 @@ if ( !function_exists( 'sp_edit_league_table' ) ) {
$value = sp_array_value( $team_stats, $column, '' );
$placeholder = sp_array_value( sp_array_value( $placeholders, $team_id, array() ), $column, 0 );
?>
<td><input type="text" name="sp_teams[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" /></td>
<td><input type="text" name="sp_teams[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="<?php echo $placeholder; ?>" data-placeholder="<?php echo $placeholder; ?>" data-matrix="<?php echo $team_id; ?>_<?php echo $column; ?>" data-adjustment="<?php echo sp_array_value( sp_array_value( $adjustments, $team_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' ), __( 'Teams', '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-league-table">
<thead>
<tr>
<th><?php _e( 'Team', '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 ):
$i = 0;
foreach ( $data as $team_id => $team_stats ):
if ( !$team_id )
continue;
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php echo get_the_title( $team_id ); ?>
</td>
<?php foreach( $columns as $column => $label ):
$value = sp_array_value( sp_array_value( $adjustments, $team_id, array() ), $column, '' );
?>
<td><input type="text" name="sp_adjustments[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" placeholder="0" data-matrix="<?php echo $team_id; ?>_<?php echo $column; ?>" /></td>
<?php endforeach; ?>
</tr>
<?php
@@ -1829,6 +1876,7 @@ if ( !function_exists( 'sp_get_league_table_data' ) ) {
$team_ids = (array)get_post_meta( $post_id, 'sp_team', false );
$table_stats = (array)get_post_meta( $post_id, 'sp_teams', true );
$usecolumns = get_post_meta( $post_id, 'sp_columns', true );
$adjustments = get_post_meta( $post_id, 'sp_adjustments', true );
// Get labels from result variables
$result_labels = (array)sp_get_var_labels( 'sp_result' );
@@ -2053,7 +2101,14 @@ if ( !function_exists( 'sp_get_league_table_data' ) ) {
foreach ( $stats as $stat ):
if ( sp_array_value( $placeholders[ $team_id ], $stat->post_name, '' ) == '' ):
$placeholders[ $team_id ][ $stat->post_name ] = sp_solve( $stat->equation, sp_array_value( $totals, $team_id, array() ), $stat->precision );
// 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 );
$placeholders[ $team_id ][ $stat->post_name ] = $placeholder;
endif;
endforeach;
endforeach;