Auto calculate outcomes from event quick edit
This commit is contained in:
@@ -579,7 +579,8 @@ jQuery(document).ready(function($){
|
|||||||
nonce: $("#sp-inline-nonce").val()
|
nonce: $("#sp-inline-nonce").val()
|
||||||
}, function(response) {
|
}, function(response) {
|
||||||
$column.find(".sp-edit-result").each(function() {
|
$column.find(".sp-edit-result").each(function() {
|
||||||
$column.find(".sp-result[data-team='"+$(this).data("team")+"']").html($(this).val());
|
val = $(this).val();
|
||||||
|
$column.find(".sp-result[data-team='"+$(this).data("team")+"']").html(val==''?'-':val);
|
||||||
});
|
});
|
||||||
$column.find(".sp-edit-result, .sp-inline-edit-save").hide();
|
$column.find(".sp-edit-result, .sp-inline-edit-save").hide();
|
||||||
$column.find(".sp-result, .sp-row-actions").show();
|
$column.find(".sp-result, .sp-row-actions").show();
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class SP_Admin_AJAX {
|
|||||||
|
|
||||||
$post_id = sp_array_value( $_POST, 'post_id' );
|
$post_id = sp_array_value( $_POST, 'post_id' );
|
||||||
$results = sp_array_value( $_POST, 'results' );
|
$results = sp_array_value( $_POST, 'results' );
|
||||||
|
$main_result = get_option( 'sportspress_primary_result', null );
|
||||||
|
|
||||||
if ( ! $post_id || ! is_array( $results ) ) {
|
if ( ! $post_id || ! is_array( $results ) ) {
|
||||||
// Return error
|
// Return error
|
||||||
@@ -55,14 +56,75 @@ class SP_Admin_AJAX {
|
|||||||
// Get current results meta
|
// Get current results meta
|
||||||
$meta = get_post_meta( $post_id, 'sp_results', true );
|
$meta = get_post_meta( $post_id, 'sp_results', true );
|
||||||
|
|
||||||
|
$primary_results = array();
|
||||||
foreach ( $results as $result ) {
|
foreach ( $results as $result ) {
|
||||||
$id = sp_array_value( $result, 'id' );
|
$id = sp_array_value( $result, 'id' );
|
||||||
$key = sp_array_value( $result, 'key' );
|
$key = sp_array_value( $result, 'key' );
|
||||||
|
|
||||||
|
$primary_results[ $id ] = sp_array_value( $result, 'result', null );
|
||||||
|
|
||||||
if ( ! $id || ! $key ) continue;
|
if ( ! $id || ! $key ) continue;
|
||||||
|
|
||||||
$meta[ $id ][ $key ] = sp_array_value( $result, 'result' );
|
$meta[ $id ][ $key ] = sp_array_value( $result, 'result' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
arsort( $primary_results );
|
||||||
|
|
||||||
|
if ( count( $primary_results ) && ! in_array( null, $primary_results ) ) {
|
||||||
|
if ( count( array_unique( $primary_results ) ) === 1 ) {
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'sp_outcome',
|
||||||
|
'numberposts' => -1,
|
||||||
|
'posts_per_page' => -1,
|
||||||
|
'meta_key' => 'sp_condition',
|
||||||
|
'meta_value' => '=',
|
||||||
|
);
|
||||||
|
$outcomes = get_posts( $args );
|
||||||
|
foreach ( $meta as $team => $team_results ) {
|
||||||
|
if ( $outcomes ) {
|
||||||
|
$meta[ $team ][ 'outcome' ] = array();
|
||||||
|
foreach ( $outcomes as $outcome ) {
|
||||||
|
$meta[ $team ][ 'outcome' ][] = $outcome->post_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reset( $primary_results );
|
||||||
|
$max = key( $primary_results );
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'sp_outcome',
|
||||||
|
'numberposts' => -1,
|
||||||
|
'posts_per_page' => -1,
|
||||||
|
'meta_key' => 'sp_condition',
|
||||||
|
'meta_value' => '>',
|
||||||
|
);
|
||||||
|
$outcomes = get_posts( $args );
|
||||||
|
if ( $outcomes ) {
|
||||||
|
$meta[ $max ][ 'outcome' ] = array();
|
||||||
|
foreach ( $outcomes as $outcome ) {
|
||||||
|
$meta[ $max ][ 'outcome' ][] = $outcome->post_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
end( $primary_results );
|
||||||
|
$min = key( $primary_results );
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'sp_outcome',
|
||||||
|
'numberposts' => -1,
|
||||||
|
'posts_per_page' => -1,
|
||||||
|
'meta_key' => 'sp_condition',
|
||||||
|
'meta_value' => '<',
|
||||||
|
);
|
||||||
|
$outcomes = get_posts( $args );
|
||||||
|
if ( $outcomes ) {
|
||||||
|
$meta[ $min ][ 'outcome' ] = array();
|
||||||
|
foreach ( $outcomes as $outcome ) {
|
||||||
|
$meta[ $min ][ 'outcome' ][] = $outcome->post_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update results
|
// Update results
|
||||||
update_post_meta( $post_id, 'sp_results', $meta );
|
update_post_meta( $post_id, 'sp_results', $meta );
|
||||||
|
|
||||||
|
|||||||
@@ -153,8 +153,7 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT {
|
|||||||
$team_results = implode( ' | ', $team_results );
|
$team_results = implode( ' | ', $team_results );
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
if ( $team_result == null ) $team_result = '-';
|
echo '<a class="sp-result tips" tabindex="10" title="' . $team_results . '" data-team="' . $team_id . '" href="#">' . ( $team_result == '' ? '-' : $team_result ) . '</a>';
|
||||||
echo '<a class="sp-result tips" tabindex="10" title="' . $team_results . '" data-team="' . $team_id . '" href="#">' . $team_result . '</a>';
|
|
||||||
echo '<input type="text" tabindex="10" class="sp-edit-result hidden small-text" data-team="' . $team_id . '" data-key="' . $main_result . '" value="' . $team_result . '"> ';
|
echo '<input type="text" tabindex="10" class="sp-edit-result hidden small-text" data-team="' . $team_id . '" data-key="' . $main_result . '" value="' . $team_result . '"> ';
|
||||||
echo $team->post_title;
|
echo $team->post_title;
|
||||||
echo '<br>';
|
echo '<br>';
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class SP_Meta_Box_Event_Results {
|
|||||||
$primary_results = array();
|
$primary_results = array();
|
||||||
foreach ( $results as $team => $team_results ) {
|
foreach ( $results as $team => $team_results ) {
|
||||||
if ( $main_result ) {
|
if ( $main_result ) {
|
||||||
$primary_results[ $team ] = sportspress_array_value( $team_results, $main_result, null );
|
$primary_results[ $team ] = sp_array_value( $team_results, $main_result, null );
|
||||||
} else {
|
} else {
|
||||||
if ( is_array( $team_results ) ) {
|
if ( is_array( $team_results ) ) {
|
||||||
end( $team_results );
|
end( $team_results );
|
||||||
@@ -48,56 +48,61 @@ class SP_Meta_Box_Event_Results {
|
|||||||
|
|
||||||
arsort( $primary_results );
|
arsort( $primary_results );
|
||||||
|
|
||||||
if ( count( $primary_results ) && ! in_array( null, $primary_results ) && count( array_unique( $primary_results ) ) === 1 ) {
|
if ( count( $primary_results ) && ! in_array( null, $primary_results ) ) {
|
||||||
$args = array(
|
if ( count( array_unique( $primary_results ) ) === 1 ) {
|
||||||
'post_type' => 'sp_outcome',
|
|
||||||
'numberposts' => -1,
|
|
||||||
'posts_per_page' => -1,
|
|
||||||
'meta_key' => 'sp_condition',
|
|
||||||
'meta_value' => '=',
|
|
||||||
);
|
|
||||||
$outcomes = get_posts( $args );
|
|
||||||
foreach ( $results as $team => $team_results ) {
|
|
||||||
if ( array_key_exists( 'outcome', $team_results ) ) continue;
|
|
||||||
if ( $outcomes ) {
|
|
||||||
foreach ( $outcomes as $outcome ) {
|
|
||||||
$results[ $team ][ 'outcome' ] = $outcome->post_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
reset( $primary_results );
|
|
||||||
$max = key( $primary_results );
|
|
||||||
if ( ! array_key_exists( 'outcome', $results[ $max ] ) ) {
|
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_type' => 'sp_outcome',
|
'post_type' => 'sp_outcome',
|
||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'meta_key' => 'sp_condition',
|
'meta_key' => 'sp_condition',
|
||||||
'meta_value' => '>',
|
'meta_value' => '=',
|
||||||
);
|
);
|
||||||
$outcomes = get_posts( $args );
|
$outcomes = get_posts( $args );
|
||||||
if ( $outcomes ) {
|
foreach ( $results as $team => $team_results ) {
|
||||||
foreach ( $outcomes as $outcome ) {
|
if ( array_key_exists( 'outcome', $team_results ) ) continue;
|
||||||
$results[ $max ][ 'outcome' ] = $outcome->post_name;
|
if ( $outcomes ) {
|
||||||
|
$results[ $team ][ 'outcome' ] = array();
|
||||||
|
foreach ( $outcomes as $outcome ) {
|
||||||
|
$results[ $team ][ 'outcome' ][] = $outcome->post_name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reset( $primary_results );
|
||||||
|
$max = key( $primary_results );
|
||||||
|
if ( ! array_key_exists( 'outcome', $results[ $max ] ) ) {
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'sp_outcome',
|
||||||
|
'numberposts' => -1,
|
||||||
|
'posts_per_page' => -1,
|
||||||
|
'meta_key' => 'sp_condition',
|
||||||
|
'meta_value' => '>',
|
||||||
|
);
|
||||||
|
$outcomes = get_posts( $args );
|
||||||
|
if ( $outcomes ) {
|
||||||
|
$results[ $max ][ 'outcome' ] = array();
|
||||||
|
foreach ( $outcomes as $outcome ) {
|
||||||
|
$results[ $max ][ 'outcome' ][] = $outcome->post_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
end( $primary_results );
|
end( $primary_results );
|
||||||
$min = key( $primary_results );
|
$min = key( $primary_results );
|
||||||
if ( ! array_key_exists( 'outcome', $results[ $min ] ) ) {
|
if ( ! array_key_exists( 'outcome', $results[ $min ] ) ) {
|
||||||
$args = array(
|
$args = array(
|
||||||
'post_type' => 'sp_outcome',
|
'post_type' => 'sp_outcome',
|
||||||
'numberposts' => -1,
|
'numberposts' => -1,
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'meta_key' => 'sp_condition',
|
'meta_key' => 'sp_condition',
|
||||||
'meta_value' => '<',
|
'meta_value' => '<',
|
||||||
);
|
);
|
||||||
$outcomes = get_posts( $args );
|
$outcomes = get_posts( $args );
|
||||||
if ( $outcomes ) {
|
if ( $outcomes ) {
|
||||||
foreach ( $outcomes as $outcome ) {
|
$results[ $min ][ 'outcome' ] = array();
|
||||||
$results[ $min ][ 'outcome' ] = $outcome->post_name;
|
foreach ( $outcomes as $outcome ) {
|
||||||
|
$results[ $min ][ 'outcome' ][] = $outcome->post_name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user