diff --git a/actions.php b/actions.php
index 6648d791..6054264f 100644
--- a/actions.php
+++ b/actions.php
@@ -103,7 +103,7 @@ function sp_save_post( $post_id ) {
foreach ( $sportspress as $key => $value ):
delete_post_meta( $post_id, $key );
if ( is_array( $value ) ):
- if ( sp_array_depth( $value ) >= 3 ):
+ if ( sp_get_array_depth( $value ) >= 3 ):
add_post_meta( $post_id, $key, $value, false );
else:
$values = new RecursiveIteratorIterator( new RecursiveArrayIterator( $value ) );
diff --git a/event.php b/event.php
index 8f60567f..9f2e5acd 100644
--- a/event.php
+++ b/event.php
@@ -77,24 +77,14 @@ function sp_event_stats_meta( $post ) {
$teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 );
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
foreach ( $teams as $key => $value ):
+ $players = sp_array_between( (array)get_post_meta( $post->ID, 'sp_player', false ), 0, $key );
+ $data = sp_array_combine( $players, sp_array_value( $stats, $value, array() ) );
?>
- ID, 'sp_player', false ), 0, $key );
- if ( array_key_exists( $value, $stats ) )
- $team_stats = (array)$stats[ $value ];
- $data = array();
- foreach ( $ids as $id ):
- if ( array_key_exists( $id, $team_stats ) )
- $data[ $id ] = $team_stats[ $id ];
- else
- $data[ $id ] = array();
- endforeach;
- sp_data_table( $data, $value, array( 'Player', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ), true, false );
- ?>
+
$max_depth )
$max_depth = $depth;
endif;
@@ -17,7 +17,45 @@ if ( ! function_exists( 'sp_array_depth' ) ) {
}
}
-if ( ! function_exists( 'sp_get_cpt_labels' ) ) {
+if ( !function_exists( 'sp_array_between' ) ) {
+ function sp_array_between ( $array = array(), $delimiter = 0, $index = 0 ) {
+ $keys = array_keys( $array, $delimiter );
+ if ( array_key_exists( $index, $keys ) ):
+ $offset = $keys[ $index ];
+ $end = sizeof( $array );
+ if ( array_key_exists( $index + 1, $keys ) )
+ $end = $keys[ $index + 1 ];
+ $length = $end - $offset;
+ $array = array_slice( $array, $offset, $length );
+ endif;
+ return $array;
+ }
+}
+
+if ( !function_exists( 'sp_array_value' ) ) {
+ function sp_array_value( $arr = array(), $key = 0, $default = null ) {
+ if ( array_key_exists( $key, $arr ) )
+ $subset = $arr[ $key ];
+ else
+ $subset = $default;
+ return $subset;
+ }
+}
+
+if ( !function_exists( 'sp_array_combine' ) ) {
+ function sp_array_combine( $keys = array(), $values = array() ) {
+ $output = array();
+ foreach ( $keys as $key ):
+ if ( array_key_exists( $key, $values ) )
+ $output[ $key ] = $values[ $key ];
+ else
+ $output[ $key ] = array();
+ endforeach;
+ return $output;
+ }
+}
+
+if ( !function_exists( 'sp_get_cpt_labels' ) ) {
function sp_get_cpt_labels( $name, $singular_name ) {
$labels = array(
'name' => $name,
@@ -36,7 +74,7 @@ if ( ! function_exists( 'sp_get_cpt_labels' ) ) {
}
}
-if ( ! function_exists( 'sp_get_tax_labels' ) ) {
+if ( !function_exists( 'sp_get_tax_labels' ) ) {
function sp_get_tax_labels( $name, $singular_name ) {
$labels = array(
'name' => $name,
@@ -56,7 +94,7 @@ if ( ! function_exists( 'sp_get_tax_labels' ) ) {
}
}
-if ( ! function_exists( 'sp_dropdown_taxonomies' ) ) {
+if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
function sp_dropdown_taxonomies( $args = array() ) {
$defaults = array(
'show_option_all' => false,
@@ -84,7 +122,7 @@ if ( ! function_exists( 'sp_dropdown_taxonomies' ) ) {
}
}
-if ( ! function_exists( 'sp_the_posts' ) ) {
+if ( !function_exists( 'sp_the_posts' ) ) {
function sp_the_posts( $post_id = null, $meta = 'post', $before = '', $sep = ', ', $after = '', $delimiter = ' - ' ) {
if ( ! isset( $post_id ) )
global $post_id;
@@ -121,20 +159,7 @@ if ( ! function_exists( 'sp_the_posts' ) ) {
}
}
-function sp_array_between ( $array = array(), $delimiter = 0, $index = 0 ) {
- $keys = array_keys( $array, $delimiter );
- if ( array_key_exists( $index, $keys ) ):
- $offset = $keys[ $index ];
- $end = sizeof( $array );
- if ( array_key_exists( $index + 1, $keys ) )
- $end = $keys[ $index + 1 ];
- $length = $end - $offset;
- $array = array_slice( $array, $offset, $length );
- endif;
- return $array;
-}
-
-if ( ! function_exists( 'sp_post_checklist' ) ) {
+if ( !function_exists( 'sp_post_checklist' ) ) {
function sp_post_checklist( $post_id = null, $meta = 'post', $display = 'block', $filter = null, $index = null ) {
if ( ! isset( $post_id ) )
global $post_id;
@@ -176,7 +201,7 @@ if ( ! function_exists( 'sp_post_checklist' ) ) {
}
}
-if ( ! function_exists( 'sp_data_table' ) ) {
+if ( !function_exists( 'sp_data_table' ) ) {
function sp_data_table( $data = array(), $index = 0, $columns = array( 'Name' ), $total = true, $auto = true ) {
if ( !is_array( $data ) )
$data = array();
@@ -250,7 +275,7 @@ if ( ! function_exists( 'sp_data_table' ) ) {
}
}
-if ( ! function_exists( 'sp_post_adder' ) ) {
+if ( !function_exists( 'sp_post_adder' ) ) {
function sp_post_adder( $meta = 'post' ) {
$obj = get_post_type_object( $meta );
?>
diff --git a/player.php b/player.php
index d857cca2..83435cac 100644
--- a/player.php
+++ b/player.php
@@ -33,17 +33,23 @@ function sp_player_team_meta( $post ) {
}
function sp_player_stats_meta( $post ) {
- $ids = (array)get_post_meta( $post->ID, 'sp_team', false );
+ $teams = (array)get_post_meta( $post->ID, 'sp_team', false );
+ $leagues = (array)get_the_terms( $post->ID, 'sp_league' );
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
- $stats = $stats[0];
- $data = array();
- foreach ( $ids as $id ):
- if ( is_array( $stats ) && array_key_exists( $id, $stats ) )
- $data[ $id ] = $stats[ $id ];
- else
- $data[ $id ] = array();
+ foreach ( $leagues as $league ):
+ if ( !$league ) continue;
+ $data = sp_array_combine( $teams, sp_array_value( $stats, $league->term_id, array() ) );
+ ?>
+
+
+ name; ?>
+
+ term_id, array( 'Team', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ) );
+ ?>
+
+ ID, 'sp_team', false );
+ $teams = (array)get_post_meta( $post->ID, 'sp_team', false );
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
- $stats = $stats[0];
- $data = array();
- foreach ( $ids as $id ):
- if ( is_array( $stats ) && array_key_exists( $id, $stats ) )
- $data[ $id ] = $stats[ $id ];
- else
- $data[ $id ] = array();
- endforeach;
+ $data = sp_array_combine( $teams, sp_array_value( $stats, 0, array() ) );
sp_data_table( $data, 0, array( 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), false );
}
?>
\ No newline at end of file