Clean up spaces, tabs, indentation, and bracket formatting
This commit is contained in:
@@ -4,19 +4,19 @@
|
||||
*
|
||||
* The SportsPress event class handles individual event data.
|
||||
*
|
||||
* @class SP_Event
|
||||
* @version 2.7.9
|
||||
* @package SportsPress/Classes
|
||||
* @category Class
|
||||
* @author ThemeBoy
|
||||
* @class SP_Event
|
||||
* @version 2.7.9
|
||||
* @package SportsPress/Classes
|
||||
* @category Class
|
||||
* @author ThemeBoy
|
||||
*/
|
||||
class SP_Event extends SP_Custom_Post{
|
||||
|
||||
class SP_Event extends SP_Custom_Post {
|
||||
|
||||
public function status() {
|
||||
$post_status = $this->post->post_status;
|
||||
$results = get_post_meta( $this->ID, 'sp_results', true );
|
||||
$results = get_post_meta( $this->ID, 'sp_results', true );
|
||||
if ( is_array( $results ) ) {
|
||||
foreach( $results as $result ) {
|
||||
foreach ( $results as $result ) {
|
||||
$result = is_array( $result ) ? array_filter( $result ) : array();
|
||||
if ( count( $result ) > 0 ) {
|
||||
return 'results';
|
||||
@@ -35,21 +35,23 @@ class SP_Event extends SP_Custom_Post{
|
||||
$day = get_post_meta( $this->ID, 'sp_day', true );
|
||||
return $day;
|
||||
}
|
||||
|
||||
|
||||
public function mode() {
|
||||
$mode = get_post_meta( $this->ID, 'sp_mode', true );
|
||||
return $mode;
|
||||
}
|
||||
|
||||
|
||||
public function minutes() {
|
||||
$minutes = get_post_meta( $this->ID, 'sp_minutes', true );
|
||||
if ( '' === $minutes ) $minutes = get_option( 'sportspress_event_minutes', 90 );
|
||||
if ( '' === $minutes ) {
|
||||
$minutes = get_option( 'sportspress_event_minutes', 90 );
|
||||
}
|
||||
return $minutes;
|
||||
}
|
||||
|
||||
public function results( $admin = false ) {
|
||||
$teams = (array)get_post_meta( $this->ID, 'sp_team', false );
|
||||
$results = (array)get_post_meta( $this->ID, 'sp_results', true );
|
||||
$teams = (array) get_post_meta( $this->ID, 'sp_team', false );
|
||||
$results = (array) get_post_meta( $this->ID, 'sp_results', true );
|
||||
|
||||
// Get columns from result variables
|
||||
$columns = sp_get_var_labels( 'sp_result' );
|
||||
@@ -60,23 +62,23 @@ class SP_Event extends SP_Custom_Post{
|
||||
// Get results for all teams
|
||||
$data = sp_array_combine( $teams, $results, true );
|
||||
|
||||
if ( $admin ):
|
||||
if ( $admin ) :
|
||||
return array( $columns, $usecolumns, $data );
|
||||
else:
|
||||
else :
|
||||
// Add outcome to result columns
|
||||
$columns['outcome'] = __( 'Outcome', 'sportspress' );
|
||||
if ( is_array( $usecolumns ) ):
|
||||
if ( 'manual' == get_option( 'sportspress_event_result_columns', 'auto' ) ):
|
||||
foreach ( $columns as $key => $label ):
|
||||
if ( ! in_array( $key, $usecolumns ) ):
|
||||
if ( is_array( $usecolumns ) ) :
|
||||
if ( 'manual' == get_option( 'sportspress_event_result_columns', 'auto' ) ) :
|
||||
foreach ( $columns as $key => $label ) :
|
||||
if ( ! in_array( $key, $usecolumns ) ) :
|
||||
unset( $columns[ $key ] );
|
||||
endif;
|
||||
endforeach;
|
||||
else:
|
||||
else :
|
||||
$active_columns = array();
|
||||
foreach ( $data as $team_results ):
|
||||
foreach ( $team_results as $key => $result ):
|
||||
if ( is_string( $result ) && strlen( $result ) ):
|
||||
foreach ( $data as $team_results ) :
|
||||
foreach ( $team_results as $key => $result ) :
|
||||
if ( is_string( $result ) && strlen( $result ) ) :
|
||||
$active_columns[ $key ] = $key;
|
||||
endif;
|
||||
endforeach;
|
||||
@@ -84,7 +86,7 @@ class SP_Event extends SP_Custom_Post{
|
||||
$columns = array_intersect_key( $columns, $active_columns );
|
||||
endif;
|
||||
|
||||
if ( 'yes' == get_option( 'sportspress_event_show_outcome', 'no' ) ):
|
||||
if ( 'yes' == get_option( 'sportspress_event_show_outcome', 'no' ) ) :
|
||||
$columns['outcome'] = __( 'Outcome', 'sportspress' );
|
||||
endif;
|
||||
endif;
|
||||
@@ -94,23 +96,23 @@ class SP_Event extends SP_Custom_Post{
|
||||
}
|
||||
|
||||
public function performance( $admin = false ) {
|
||||
$teams = get_post_meta( $this->ID, 'sp_team', false );
|
||||
$performance = (array)get_post_meta( $this->ID, 'sp_players', true );
|
||||
|
||||
$teams = get_post_meta( $this->ID, 'sp_team', false );
|
||||
$performance = (array) get_post_meta( $this->ID, 'sp_players', true );
|
||||
|
||||
$args = array(
|
||||
'post_type' => 'sp_performance',
|
||||
'numberposts' => 100,
|
||||
'post_type' => 'sp_performance',
|
||||
'numberposts' => 100,
|
||||
'posts_per_page' => 100,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC',
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC',
|
||||
);
|
||||
|
||||
$vars = get_posts( $args );
|
||||
|
||||
$labels = array();
|
||||
$formats = array();
|
||||
$timed = array();
|
||||
$stars = array();
|
||||
|
||||
$labels = array();
|
||||
$formats = array();
|
||||
$timed = array();
|
||||
$stars = array();
|
||||
$equations = array();
|
||||
foreach ( $vars as $var ) {
|
||||
$labels[ $var->post_name ] = $var->post_title;
|
||||
@@ -127,84 +129,96 @@ class SP_Event extends SP_Custom_Post{
|
||||
$timed[] = $var->post_name;
|
||||
}
|
||||
} elseif ( 'equation' === $format ) {
|
||||
$equation = get_post_meta( $var->ID, 'sp_equation', true );
|
||||
$equation = get_post_meta( $var->ID, 'sp_equation', true );
|
||||
$precision = get_post_meta( $var->ID, 'sp_precision', true );
|
||||
|
||||
if ( empty( $equation ) ) $equation = 0;
|
||||
if ( empty( $precision ) ) $precision = 0;
|
||||
|
||||
|
||||
if ( empty( $equation ) ) {
|
||||
$equation = 0;
|
||||
}
|
||||
if ( empty( $precision ) ) {
|
||||
$precision = 0;
|
||||
}
|
||||
|
||||
$equations[ $var->post_name ] = array(
|
||||
'equation' => $equation,
|
||||
'equation' => $equation,
|
||||
'precision' => $precision,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$order = (array)get_post_meta( $this->ID, 'sp_order', true );
|
||||
|
||||
$order = (array) get_post_meta( $this->ID, 'sp_order', true );
|
||||
|
||||
if ( get_option( 'sportspress_event_performance_stars_type', 0 ) ) {
|
||||
$stars = (array)get_post_meta( $this->ID, 'sp_stars', true );
|
||||
$stars = (array) get_post_meta( $this->ID, 'sp_stars', true );
|
||||
}
|
||||
|
||||
$labels = apply_filters( 'sportspress_event_performance_labels', $labels, $this );
|
||||
|
||||
$labels = apply_filters( 'sportspress_event_performance_labels', $labels, $this );
|
||||
$columns = get_post_meta( $this->ID, 'sp_columns', true );
|
||||
if ( is_array( $teams ) ):
|
||||
foreach( $teams as $i => $team_id ):
|
||||
$players = sp_array_between( (array)get_post_meta( $this->ID, 'sp_player', false ), 0, $i );
|
||||
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
|
||||
if ( is_array( $teams ) ) :
|
||||
foreach ( $teams as $i => $team_id ) :
|
||||
$players = sp_array_between( (array) get_post_meta( $this->ID, 'sp_player', false ), 0, $i );
|
||||
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
|
||||
|
||||
foreach( $data as $player_id => $player_performance ):
|
||||
if ( ! $player_id ) continue;
|
||||
foreach ( $data as $player_id => $player_performance ) :
|
||||
if ( ! $player_id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! array_key_exists( 'number', $player_performance ) ):
|
||||
if ( ! array_key_exists( 'number', $player_performance ) ) :
|
||||
$performance[ $team_id ][ $player_id ]['number'] = apply_filters( 'sportspress_event_performance_default_squad_number', get_post_meta( $player_id, 'sp_number', true ) );
|
||||
endif;
|
||||
if ( ! array_key_exists( 'position', $player_performance ) || $player_performance['position'] == null ):
|
||||
if ( ! array_key_exists( 'position', $player_performance ) || $player_performance['position'] == null ) :
|
||||
$performance[ $team_id ][ $player_id ]['position'] = sp_get_the_term_id( $player_id, 'sp_position', null );
|
||||
endif;
|
||||
endforeach;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
if ( $admin ):
|
||||
if ( $admin ) :
|
||||
return array( $labels, $columns, $performance, $teams, $formats, $order, $timed, $stars );
|
||||
else:
|
||||
else :
|
||||
// Add position to performance labels
|
||||
if ( taxonomy_exists( 'sp_position' ) ):
|
||||
$labels = array_merge( array( 'position' => __( 'Position', 'sportspress' ) ), $labels );
|
||||
if ( taxonomy_exists( 'sp_position' ) ) :
|
||||
$labels = array_merge( array( 'position' => __( 'Position', 'sportspress' ) ), $labels );
|
||||
endif;
|
||||
if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) && is_array( $columns ) ):
|
||||
foreach ( $labels as $key => $label ):
|
||||
if ( ! in_array( $key, $columns ) ):
|
||||
if ( 'manual' == get_option( 'sportspress_event_performance_columns', 'auto' ) && is_array( $columns ) ) :
|
||||
foreach ( $labels as $key => $label ) :
|
||||
if ( ! in_array( $key, $columns ) ) :
|
||||
unset( $labels[ $key ] );
|
||||
endif;
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
if ( 'no' == get_option( 'sportspress_event_show_position', 'yes' ) ):
|
||||
if ( 'no' == get_option( 'sportspress_event_show_position', 'yes' ) ) :
|
||||
unset( $labels['position'] );
|
||||
endif;
|
||||
if ( 'no' == get_option( 'sportspress_event_show_player_numbers', 'yes' ) ):
|
||||
if ( 'no' == get_option( 'sportspress_event_show_player_numbers', 'yes' ) ) :
|
||||
unset( $labels['number'] );
|
||||
endif;
|
||||
|
||||
// Calculate equation-based performance
|
||||
if ( sizeof( $equations ) ):
|
||||
foreach ( $performance as $team => $players ):
|
||||
if ( ! is_array( $players ) ) continue;
|
||||
if ( sizeof( $equations ) ) :
|
||||
foreach ( $performance as $team => $players ) :
|
||||
if ( ! is_array( $players ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $players as $player => $player_performance ):
|
||||
if ( ! is_array( $player_performance ) ) continue;
|
||||
foreach ( $players as $player => $player_performance ) :
|
||||
if ( ! is_array( $player_performance ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Prepare existing values for equation calculation
|
||||
$vars = $player_performance;
|
||||
|
||||
foreach ( $vars as $key => $var ):
|
||||
if ( empty( $var ) ) $vars[ $key ] = 0;
|
||||
foreach ( $vars as $key => $var ) :
|
||||
if ( empty( $var ) ) {
|
||||
$vars[ $key ] = 0;
|
||||
}
|
||||
endforeach;
|
||||
$vars = array_merge( $vars, array( 'eventsplayed' => 1 ) );
|
||||
|
||||
foreach ( $equations as $key => $equation ):
|
||||
foreach ( $equations as $key => $equation ) :
|
||||
$performance[ $team ][ $player ][ $key ] = sp_solve( $equation['equation'], $vars, $equation['precision'] );
|
||||
endforeach;
|
||||
endforeach;
|
||||
@@ -212,24 +226,31 @@ class SP_Event extends SP_Custom_Post{
|
||||
endif;
|
||||
|
||||
// Convert to time notation
|
||||
if ( in_array( 'time', $formats ) ):
|
||||
foreach ( $performance as $team => $players ):
|
||||
if ( ! is_array( $players ) ) continue;
|
||||
if ( in_array( 'time', $formats ) ) :
|
||||
foreach ( $performance as $team => $players ) :
|
||||
if ( ! is_array( $players ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $players as $player => $player_performance ):
|
||||
if ( ! $player ) continue;
|
||||
foreach ( $players as $player => $player_performance ) :
|
||||
if ( ! $player ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $player_performance as $performance_key => $performance_value ):
|
||||
foreach ( $player_performance as $performance_key => $performance_value ) :
|
||||
|
||||
// Continue if not time format
|
||||
if ( 'time' !== sp_array_value( $formats, $performance_key ) ) continue;
|
||||
if ( 'time' !== sp_array_value( $formats, $performance_key ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$intval = intval( $performance_value );
|
||||
$intval = intval( $performance_value );
|
||||
$timeval = gmdate( 'i:s', $intval );
|
||||
$hours = floor( $intval / 3600 );
|
||||
$hours = floor( $intval / 3600 );
|
||||
|
||||
if ( '00' != $hours )
|
||||
if ( '00' != $hours ) {
|
||||
$timeval = $hours . ':' . $timeval;
|
||||
}
|
||||
|
||||
$timeval = preg_replace( '/^0/', '', $timeval );
|
||||
|
||||
@@ -240,31 +261,41 @@ class SP_Event extends SP_Custom_Post{
|
||||
endif;
|
||||
|
||||
// Add minutes to box score values
|
||||
if ( in_array( 'number', $formats ) && 'yes' == get_option( 'sportspress_event_performance_show_minutes', 'no' ) ):
|
||||
if ( in_array( 'number', $formats ) && 'yes' == get_option( 'sportspress_event_performance_show_minutes', 'no' ) ) :
|
||||
$timeline = $this->timeline();
|
||||
if ( ! empty( $timeline ) ):
|
||||
foreach ( $performance as $team => $players ):
|
||||
if ( ! empty( $timeline ) ) :
|
||||
foreach ( $performance as $team => $players ) :
|
||||
|
||||
// Get team timeline
|
||||
$team_timeline = sp_array_value( $timeline, $team, array() );
|
||||
if ( empty( $team_timeline ) ) continue;
|
||||
if ( empty( $team_timeline ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $players as $player => $player_performance ):
|
||||
if ( ! $player ) continue;
|
||||
foreach ( $players as $player => $player_performance ) :
|
||||
if ( ! $player ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get player timeline
|
||||
$player_timeline = sp_array_value( $team_timeline, $player, array() );
|
||||
if ( empty( $player_timeline ) ) continue;
|
||||
if ( empty( $player_timeline ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $player_performance as $performance_key => $performance_value ):
|
||||
foreach ( $player_performance as $performance_key => $performance_value ) :
|
||||
|
||||
// Continue if not timed
|
||||
if ( ! in_array( $performance_key, $timed ) ) continue;
|
||||
if ( ! in_array( $performance_key, $timed ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get performance times
|
||||
$times = sp_array_value( $player_timeline, $performance_key, array() );
|
||||
$times = array_filter( $times );
|
||||
if ( empty( $times ) ) continue;
|
||||
if ( empty( $times ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$performance[ $team ][ $player ][ $performance_key ] .= ' (' . implode( '\', ', $times ) . '\')';
|
||||
endforeach;
|
||||
@@ -275,29 +306,37 @@ class SP_Event extends SP_Custom_Post{
|
||||
|
||||
// Add labels to box score
|
||||
$performance[0] = $labels;
|
||||
|
||||
|
||||
return apply_filters( 'sportspress_get_event_performance', $performance );
|
||||
endif;
|
||||
}
|
||||
|
||||
|
||||
public function timeline( $admin = false, $linear = false ) {
|
||||
$timeline = (array) get_post_meta( $this->ID, 'sp_timeline', true );
|
||||
|
||||
if ( ! $linear ) return $timeline;
|
||||
if ( ! $linear ) {
|
||||
return $timeline;
|
||||
}
|
||||
|
||||
$performance = (array) get_post_meta( $this->ID, 'sp_players', true );
|
||||
if ( empty( $timeline ) ) return array();
|
||||
if ( empty( $timeline ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$stats = array();
|
||||
$player_ids = array();
|
||||
$stats = array();
|
||||
$player_ids = array();
|
||||
$performance_keys = array();
|
||||
|
||||
// Clean up timeline
|
||||
foreach ( $timeline as $team => $players ) {
|
||||
if ( ! $team ) continue;
|
||||
if ( ! $team ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Set home team
|
||||
if ( ! isset( $home_team ) ) $home_team = $team;
|
||||
if ( ! isset( $home_team ) ) {
|
||||
$home_team = $team;
|
||||
}
|
||||
|
||||
// Determine side
|
||||
if ( $home_team === $team ) {
|
||||
@@ -308,36 +347,46 @@ class SP_Event extends SP_Custom_Post{
|
||||
|
||||
$stats[] = array(
|
||||
'time' => -1,
|
||||
'id' => $team,
|
||||
'id' => $team,
|
||||
'team' => $team,
|
||||
'side' => $side,
|
||||
'key' => 'team',
|
||||
'key' => 'team',
|
||||
);
|
||||
|
||||
if ( ! is_array( $players ) ) continue;
|
||||
if ( ! is_array( $players ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $players as $player => $keys ) {
|
||||
if ( ! $player ) continue;
|
||||
if ( ! is_array( $keys ) ) continue;
|
||||
if ( ! $player ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! is_array( $keys ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$player_ids[] = $player;
|
||||
|
||||
foreach ( $keys as $key => $times ) {
|
||||
if ( ! is_array( $times ) || empty( $times ) ) continue;
|
||||
if ( ! is_array( $times ) || empty( $times ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $times as $time ) {
|
||||
if ( '' === $time ) continue;
|
||||
if ( '' === $time ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$entry = array(
|
||||
'time' => $time,
|
||||
'id' => $player,
|
||||
'id' => $player,
|
||||
'team' => $team,
|
||||
'side' => $side,
|
||||
'key' => $key,
|
||||
'key' => $key,
|
||||
);
|
||||
|
||||
if ( 'sub' === $key ) {
|
||||
$sub = sp_array_value( sp_array_value( sp_array_value( $performance, $team ), $player ), 'sub', 0 );
|
||||
$sub = sp_array_value( sp_array_value( sp_array_value( $performance, $team ), $player ), 'sub', 0 );
|
||||
$entry['sub'] = $sub;
|
||||
$player_ids[] = $sub;
|
||||
}
|
||||
@@ -351,35 +400,39 @@ class SP_Event extends SP_Custom_Post{
|
||||
}
|
||||
|
||||
// Filter out duplicate player IDs and performance keys
|
||||
$player_ids = array_unique( $player_ids );
|
||||
$player_ids = array_unique( $player_ids );
|
||||
$performance_keys = array_unique( $performance_keys );
|
||||
|
||||
// Get player names and numbers
|
||||
$posts = get_posts( array(
|
||||
'post_type' => 'sp_player',
|
||||
'posts_per_page' => -1,
|
||||
'post__in' => $player_ids
|
||||
) );
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'post_type' => 'sp_player',
|
||||
'posts_per_page' => -1,
|
||||
'post__in' => $player_ids,
|
||||
)
|
||||
);
|
||||
|
||||
$player_names = array();
|
||||
$player_names = array();
|
||||
$player_numbers = array();
|
||||
|
||||
if ( $posts ) {
|
||||
foreach ( $posts as $post ) {
|
||||
$player_names[ $post->ID ] = $post->post_title;
|
||||
$player_names[ $post->ID ] = $post->post_title;
|
||||
$player_numbers[ $post->ID ] = get_post_meta( $post->ID, 'sp_number', true );
|
||||
}
|
||||
}
|
||||
|
||||
// Get performance labels and icons
|
||||
$posts = get_posts( array(
|
||||
'post_type' => 'sp_performance',
|
||||
'posts_per_page' => -1,
|
||||
'post_name__in' => $performance_keys
|
||||
) );
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'post_type' => 'sp_performance',
|
||||
'posts_per_page' => -1,
|
||||
'post_name__in' => $performance_keys,
|
||||
)
|
||||
);
|
||||
|
||||
$performance_labels = array();
|
||||
$performance_icons = array();
|
||||
$performance_icons = array();
|
||||
|
||||
if ( $posts ) {
|
||||
foreach ( $posts as $post ) {
|
||||
@@ -395,16 +448,16 @@ class SP_Event extends SP_Custom_Post{
|
||||
|
||||
// Add missing info to stats
|
||||
foreach ( $stats as $index => $details ) {
|
||||
$stats[ $index ]['name'] = sp_array_value( $player_names, $details['id'] );
|
||||
$stats[ $index ]['name'] = sp_array_value( $player_names, $details['id'] );
|
||||
$stats[ $index ]['number'] = sp_array_value( $player_numbers, $details['id'] );
|
||||
|
||||
if ( 'team' === $details['key'] ) {
|
||||
$name = sp_team_short_name( $details['team'] );
|
||||
$stats[ $index ]['name'] = $name;
|
||||
$name = sp_team_short_name( $details['team'] );
|
||||
$stats[ $index ]['name'] = $name;
|
||||
$stats[ $index ]['label'] = $name;
|
||||
$stats[ $index ]['icon'] = sp_get_logo( $details['team'] );
|
||||
$stats[ $index ]['icon'] = sp_get_logo( $details['team'] );
|
||||
} elseif ( 'sub' === $details['key'] ) {
|
||||
$sub_name = sp_array_value( $player_names, $details['sub'], __( 'Substitute', 'sportspress' ) );
|
||||
$sub_name = sp_array_value( $player_names, $details['sub'], __( 'Substitute', 'sportspress' ) );
|
||||
$sub_number = sp_array_value( $player_numbers, $details['sub'] );
|
||||
|
||||
if ( '' !== $sub_number ) {
|
||||
@@ -413,13 +466,13 @@ class SP_Event extends SP_Custom_Post{
|
||||
$icon_title = $sub_name;
|
||||
}
|
||||
|
||||
$stats[ $index ]['sub_name'] = $sub_name;
|
||||
$stats[ $index ]['sub_name'] = $sub_name;
|
||||
$stats[ $index ]['sub_number'] = $sub_number;
|
||||
$stats[ $index ]['label'] = __( 'Substitute', 'sportspress' );
|
||||
$stats[ $index ]['icon'] = '<i class="sp-icon-sub" title="' . $icon_title . '"></i>';
|
||||
$stats[ $index ]['label'] = __( 'Substitute', 'sportspress' );
|
||||
$stats[ $index ]['icon'] = '<i class="sp-icon-sub" title="' . $icon_title . '"></i>';
|
||||
} else {
|
||||
$stats[ $index ]['label'] = sp_array_value( $performance_labels, $details['key'] );
|
||||
$stats[ $index ]['icon'] = sp_array_value( $performance_icons, $details['key'] );
|
||||
$stats[ $index ]['icon'] = sp_array_value( $performance_icons, $details['key'] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,28 +487,32 @@ class SP_Event extends SP_Custom_Post{
|
||||
|
||||
// Get teams from event
|
||||
$teams = get_post_meta( $this->ID, 'sp_team', false );
|
||||
|
||||
|
||||
// Initialize output
|
||||
$output = array();
|
||||
|
||||
// Return empty array if there are no teams
|
||||
if ( ! $teams ) return $output;
|
||||
if ( ! $teams ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Get results from event
|
||||
$results = get_post_meta( $this->ID, 'sp_results', true );
|
||||
|
||||
// Loop through teams
|
||||
// Loop through teams
|
||||
foreach ( $teams as $team_id ) {
|
||||
|
||||
// Skip if not a team
|
||||
if ( ! $team_id ) continue;
|
||||
if ( ! $team_id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get team results from all results
|
||||
$team_results = sp_array_value( $results, $team_id, null );
|
||||
|
||||
// Get main or last result
|
||||
if ( $main_result ) {
|
||||
|
||||
|
||||
// Get main result from team results
|
||||
$team_result = sp_array_value( $team_results, $main_result, null );
|
||||
} else {
|
||||
@@ -484,21 +541,25 @@ class SP_Event extends SP_Custom_Post{
|
||||
public function outcome( $single = true ) {
|
||||
// Get teams from event
|
||||
$teams = get_post_meta( $this->ID, 'sp_team', false );
|
||||
|
||||
|
||||
// Initialize output
|
||||
$output = array();
|
||||
|
||||
// Return empty array if there are no teams
|
||||
if ( ! $teams ) return $output;
|
||||
if ( ! $teams ) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
// Get results from event
|
||||
$results = get_post_meta( $this->ID, 'sp_results', true );
|
||||
|
||||
// Loop through teams
|
||||
// Loop through teams
|
||||
foreach ( $teams as $team_id ) {
|
||||
|
||||
// Skip if not a team
|
||||
if ( ! $team_id ) continue;
|
||||
if ( ! $team_id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get team results from all results
|
||||
$team_results = sp_array_value( $results, $team_id, null );
|
||||
@@ -526,16 +587,20 @@ class SP_Event extends SP_Custom_Post{
|
||||
|
||||
public function winner() {
|
||||
// Get the first configured outcome
|
||||
$outcome = get_posts( array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC',
|
||||
) );
|
||||
$outcome = get_posts(
|
||||
array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => 1,
|
||||
'orderby' => 'menu_order',
|
||||
'order' => 'ASC',
|
||||
)
|
||||
);
|
||||
|
||||
// Return if no outcomes available
|
||||
if ( ! $outcome ) return null;
|
||||
if ( ! $outcome ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$outcome = reset( $outcome );
|
||||
|
||||
@@ -552,53 +617,63 @@ class SP_Event extends SP_Custom_Post{
|
||||
// Return if no teams meet criteria
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function appointments( $include_empty = false, $placeholder = '-' ) {
|
||||
$officials = (array) get_post_meta( $this->ID, 'sp_officials', true );
|
||||
$officials = array_filter( $officials );
|
||||
|
||||
if ( ! $include_empty && empty( $officials ) ) return null;
|
||||
if ( ! $include_empty && empty( $officials ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$duties = get_terms( array(
|
||||
'taxonomy' => 'sp_duty',
|
||||
'hide_empty' => false,
|
||||
'orderby' => 'meta_value_num',
|
||||
'meta_query' => array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => 'sp_order',
|
||||
'compare' => 'NOT EXISTS'
|
||||
$duties = get_terms(
|
||||
array(
|
||||
'taxonomy' => 'sp_duty',
|
||||
'hide_empty' => false,
|
||||
'orderby' => 'meta_value_num',
|
||||
'meta_query' => array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => 'sp_order',
|
||||
'compare' => 'NOT EXISTS',
|
||||
),
|
||||
array(
|
||||
'key' => 'sp_order',
|
||||
'compare' => 'EXISTS',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'key' => 'sp_order',
|
||||
'compare' => 'EXISTS'
|
||||
),
|
||||
),
|
||||
) );
|
||||
)
|
||||
);
|
||||
if ( ! is_array( $duties ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if ( ! $include_empty && empty( $duties ) ) return null;
|
||||
if ( ! $include_empty && empty( $duties ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$labels = array();
|
||||
$labels = array();
|
||||
$appointments = array();
|
||||
|
||||
foreach ( $duties as $duty ) {
|
||||
$duty_appointments = sp_array_value( $officials, $duty->term_id, array() );
|
||||
|
||||
if ( ! $include_empty && empty( $duty_appointments ) ) continue;
|
||||
if ( ! $include_empty && empty( $duty_appointments ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$appointed_officials = array();
|
||||
|
||||
|
||||
foreach ( $duty_appointments as $duty_appointment ) {
|
||||
$appointed_officials[ $duty_appointment ] = get_the_title( $duty_appointment );
|
||||
}
|
||||
|
||||
if ( $include_empty && empty( $appointed_officials ) ) $appointed_officials[] = $placeholder;
|
||||
if ( $include_empty && empty( $appointed_officials ) ) {
|
||||
$appointed_officials[] = $placeholder;
|
||||
}
|
||||
|
||||
$appointments[ $duty->slug ] = $appointed_officials;
|
||||
$labels[ $duty->slug ] = $duty->name;
|
||||
$labels[ $duty->slug ] = $duty->name;
|
||||
}
|
||||
|
||||
$appointments[0] = $labels;
|
||||
@@ -614,13 +689,15 @@ class SP_Event extends SP_Custom_Post{
|
||||
}
|
||||
|
||||
// Get current results meta
|
||||
$meta =(array) get_post_meta( $this->ID, 'sp_results', true );
|
||||
$meta = (array) get_post_meta( $this->ID, 'sp_results', true );
|
||||
|
||||
$primary_results = array();
|
||||
foreach ( $results as $id => $result ) {
|
||||
$primary_results[ $id ] = $result;
|
||||
|
||||
if ( ! $id ) continue;
|
||||
if ( ! $id ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$meta[ $id ][ $main_result ] = $result;
|
||||
}
|
||||
@@ -629,12 +706,12 @@ class SP_Event extends SP_Custom_Post{
|
||||
|
||||
if ( count( $primary_results ) && ! in_array( null, $primary_results ) ) {
|
||||
if ( count( array_unique( $primary_results ) ) === 1 ) {
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => '=',
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => '=',
|
||||
);
|
||||
$outcomes = get_posts( $args );
|
||||
foreach ( $meta as $team => $team_results ) {
|
||||
@@ -642,44 +719,48 @@ class SP_Event extends SP_Custom_Post{
|
||||
if ( empty( $meta[ $team ] ) ) {
|
||||
$meta[ $team ] = array();
|
||||
}
|
||||
$meta[ $team ][ 'outcome' ] = array();
|
||||
$meta[ $team ]['outcome'] = array();
|
||||
foreach ( $outcomes as $outcome ) {
|
||||
$meta[ $team ][ 'outcome' ][] = $outcome->post_name;
|
||||
$meta[ $team ]['outcome'][] = $outcome->post_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Get default outcomes
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => 'else',
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => 'else',
|
||||
);
|
||||
$default_outcomes = get_posts( $args );
|
||||
|
||||
// Get greater than outcomes
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => '>',
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => '>',
|
||||
);
|
||||
$gt_outcomes = get_posts( $args );
|
||||
if ( empty ( $gt_outcomes ) ) $gt_outcomes = $default_outcomes;
|
||||
if ( empty( $gt_outcomes ) ) {
|
||||
$gt_outcomes = $default_outcomes;
|
||||
}
|
||||
|
||||
// Get less than outcomes
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
$args = array(
|
||||
'post_type' => 'sp_outcome',
|
||||
'numberposts' => -1,
|
||||
'posts_per_page' => -1,
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => '<',
|
||||
'meta_key' => 'sp_condition',
|
||||
'meta_value' => '<',
|
||||
);
|
||||
$lt_outcomes = get_posts( $args );
|
||||
if ( empty ( $lt_outcomes ) ) $lt_outcomes = $default_outcomes;
|
||||
if ( empty( $lt_outcomes ) ) {
|
||||
$lt_outcomes = $default_outcomes;
|
||||
}
|
||||
|
||||
// Get min and max values
|
||||
$min = min( $primary_results );
|
||||
@@ -693,9 +774,9 @@ class SP_Event extends SP_Custom_Post{
|
||||
} else {
|
||||
$outcomes = $default_outcomes;
|
||||
}
|
||||
$meta[ $key ][ 'outcome' ] = array();
|
||||
$meta[ $key ]['outcome'] = array();
|
||||
foreach ( $outcomes as $outcome ) {
|
||||
$meta[ $key ][ 'outcome' ][] = $outcome->post_name;
|
||||
$meta[ $key ]['outcome'][] = $outcome->post_name;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -720,7 +801,7 @@ class SP_Event extends SP_Custom_Post{
|
||||
public function sort_timeline( $a, $b ) {
|
||||
return (float) $a['time'] - (float) $b['time'];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns formatted event specs
|
||||
*
|
||||
@@ -728,14 +809,15 @@ class SP_Event extends SP_Custom_Post{
|
||||
* @return array
|
||||
*/
|
||||
public function specs( $neg = null ) {
|
||||
$specs = (array)get_post_meta( $this->ID, 'sp_specs', true );
|
||||
$spec_labels = (array)sp_get_var_labels( 'sp_spec', $neg, false );
|
||||
$data = array();
|
||||
|
||||
foreach ( $spec_labels as $key => $value ):
|
||||
$specs = (array) get_post_meta( $this->ID, 'sp_specs', true );
|
||||
$spec_labels = (array) sp_get_var_labels( 'sp_spec', $neg, false );
|
||||
$data = array();
|
||||
|
||||
foreach ( $spec_labels as $key => $value ) :
|
||||
$spec = sp_array_value( $specs, $key, null );
|
||||
if ( $spec == null )
|
||||
if ( $spec == null ) {
|
||||
continue;
|
||||
}
|
||||
$data[ $value ] = sp_array_value( $specs, $key, ' ' );
|
||||
endforeach;
|
||||
return $data;
|
||||
|
||||
Reference in New Issue
Block a user