From 1e57d60e0864edde82f35f009cb5b054d7998986 Mon Sep 17 00:00:00 2001 From: Takumi Date: Mon, 29 Jul 2013 17:10:49 +1000 Subject: [PATCH] Add ability to view and edit player stats --- actions.php | 10 +++-- event.php | 27 ++++++++---- helpers.php | 119 +++++++++++++++++++++++++++------------------------- 3 files changed, 90 insertions(+), 66 deletions(-) diff --git a/actions.php b/actions.php index 93b3da5f..35e4b33d 100644 --- a/actions.php +++ b/actions.php @@ -103,10 +103,14 @@ function sp_save_post( $post_id ) { foreach ( $sportspress as $key => $value ): delete_post_meta( $post_id, $key ); if ( is_array( $value ) ): - $values = new RecursiveIteratorIterator( new RecursiveArrayIterator( $value ) ); - foreach ( $values as $value ): + if ( sp_array_depth( $value ) >= 3 ): add_post_meta( $post_id, $key, $value, false ); - endforeach; + else: + $values = new RecursiveIteratorIterator( new RecursiveArrayIterator( $value ) ); + foreach ( $values as $value ): + add_post_meta( $post_id, $key, $value, false ); + endforeach; + endif; else: update_post_meta( $post_id, $key, $value ); endif; diff --git a/event.php b/event.php index a2449cb9..78b24f5e 100644 --- a/event.php +++ b/event.php @@ -35,7 +35,7 @@ function sp_event_meta_init() { function sp_event_team_meta( $post ) { $limit = get_option( 'sp_event_team_count' ); - $teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0); + $teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0 ); $players = (array)get_post_meta( $post->ID, 'sp_player', false ); for ( $i = 0; $i < $limit; $i++ ): ?> @@ -74,18 +74,31 @@ function sp_event_article_meta( $post ) { function sp_event_stats_meta( $post ) { $limit = get_option( 'sp_event_team_count' ); - $teams = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_team', false ), 0, $limit ), $limit, 0); - $players = (array)get_post_meta( $post->ID, 'sp_player', false ); - for ( $i = 0; $i < $limit; $i++ ): + $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 ): ?>

- +

- ID, 'sp_player', 'block', 'sp_team', $i ); ?> + ID, 'sp_player', false ), 0, $key ); + $size = sizeof( $ids ); + 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 ); + ?>
$max_depth ) + $max_depth = $depth; + endif; + endforeach; + return $max_depth; + else: + return 0; + endif; + } +} + if ( ! function_exists( 'sp_get_cpt_labels' ) ) { function sp_get_cpt_labels( $name, $singular_name ) { $labels = array( @@ -103,41 +121,42 @@ 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' ) ) { - function sp_post_checklist( $post_id = null, $meta = 'post', $display = 'block', $data = null, $index = null ) { + function sp_post_checklist( $post_id = null, $meta = 'post', $display = 'block', $filter = null, $index = null ) { if ( ! isset( $post_id ) ) global $post_id; - $obj = get_post_type_object( $meta ); ?>