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