Add default outcome condition
This commit is contained in:
@@ -74,40 +74,54 @@ class SP_Meta_Box_Event_Results {
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Get default outcomes
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => 'else',
|
||||
);
|
||||
$default_outcomes = get_posts( $args );
|
||||
|
||||
end( $primary_results );
|
||||
$min = key( $primary_results );
|
||||
if ( ! array_key_exists( 'outcome', $results[ $min ] ) ) {
|
||||
$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[ $min ][ 'outcome' ] = array();
|
||||
// Get greater than outcomes
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => '>',
|
||||
);
|
||||
$gt_outcomes = get_posts( $args );
|
||||
if ( empty ( $gt_outcomes ) ) $gt_outcomes = $default_outcomes;
|
||||
|
||||
// Get less than outcomes
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => '<',
|
||||
);
|
||||
$lt_outcomes = get_posts( $args );
|
||||
if ( empty ( $lt_outcomes ) ) $lt_outcomes = $default_outcomes;
|
||||
|
||||
// Get min and max values
|
||||
$min = min( $primary_results );
|
||||
$max = max( $primary_results );
|
||||
|
||||
foreach ( $primary_results as $key => $value ) {
|
||||
if ( ! array_key_exists( 'outcome', $results[ $key ] ) ) {
|
||||
if ( $min == $value ) {
|
||||
$outcomes = $lt_outcomes;
|
||||
} elseif ( $max == $value ) {
|
||||
$outcomes = $gt_outcomes;
|
||||
} else {
|
||||
$outcomes = $default_outcomes;
|
||||
}
|
||||
$results[ $key ][ 'outcome' ] = array();
|
||||
foreach ( $outcomes as $outcome ) {
|
||||
$results[ $min ][ 'outcome' ][] = $outcome->post_name;
|
||||
$results[ $key ][ 'outcome' ][] = $outcome->post_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ class SP_Meta_Box_Outcome_Details extends SP_Meta_Box_Config {
|
||||
'>' => sprintf( __( 'Most %s', 'sportspress' ), $label ),
|
||||
'<' => sprintf( __( 'Least %s', 'sportspress' ), $label ),
|
||||
'=' => sprintf( __( 'Equal %s', 'sportspress' ), $label ),
|
||||
'else' => sprintf( __( 'Default', 'sportspress' ), $label ),
|
||||
);
|
||||
for( $i = 1; $i <= $count->publish; $i++ ):
|
||||
$options[ $i ] = $i;
|
||||
|
||||
@@ -298,8 +298,17 @@ class SP_Event extends SP_Custom_Post{
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reset( $primary_results );
|
||||
$max = key( $primary_results );
|
||||
// Get default outcomes
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => 'else',
|
||||
);
|
||||
$default_outcomes = get_posts( $args );
|
||||
|
||||
// Get greater than outcomes
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
@@ -307,16 +316,10 @@ class SP_Event extends SP_Custom_Post{
|
||||
'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;
|
||||
}
|
||||
}
|
||||
$gt_outcomes = get_posts( $args );
|
||||
if ( empty ( $gt_outcomes ) ) $gt_outcomes = $default_outcomes;
|
||||
|
||||
end( $primary_results );
|
||||
$min = key( $primary_results );
|
||||
// Get less than outcomes
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
@@ -324,11 +327,24 @@ class SP_Event extends SP_Custom_Post{
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => '<',
|
||||
);
|
||||
$outcomes = get_posts( $args );
|
||||
if ( $outcomes ) {
|
||||
$meta[ $min ][ 'outcome' ] = array();
|
||||
$lt_outcomes = get_posts( $args );
|
||||
if ( empty ( $lt_outcomes ) ) $lt_outcomes = $default_outcomes;
|
||||
|
||||
// Get min and max values
|
||||
$min = min( $primary_results );
|
||||
$max = max( $primary_results );
|
||||
|
||||
foreach ( $primary_results as $key => $value ) {
|
||||
if ( $min == $value ) {
|
||||
$outcomes = $lt_outcomes;
|
||||
} elseif ( $max == $value ) {
|
||||
$outcomes = $gt_outcomes;
|
||||
} else {
|
||||
$outcomes = $default_outcomes;
|
||||
}
|
||||
$meta[ $key ][ 'outcome' ] = array();
|
||||
foreach ( $outcomes as $outcome ) {
|
||||
$meta[ $min ][ 'outcome' ][] = $outcome->post_name;
|
||||
$meta[ $key ][ 'outcome' ][] = $outcome->post_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,6 +376,7 @@ if ( !function_exists( 'sp_get_post_condition' ) ) {
|
||||
'>' => sprintf( __( 'Most %s', 'sportspress' ), $label ),
|
||||
'<' => sprintf( __( 'Least %s', 'sportspress' ), $label ),
|
||||
'=' => sprintf( __( 'Equal %s', 'sportspress' ), $label ),
|
||||
'else' => sprintf( __( 'Default', 'sportspress' ), $label ),
|
||||
);
|
||||
return sp_array_value( $conditions, $condition, '—' );
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user