Add ability to view and edit player stats
This commit is contained in:
10
actions.php
10
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;
|
||||
|
||||
27
event.php
27
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 ):
|
||||
?>
|
||||
<div>
|
||||
<p>
|
||||
<strong><?php echo $teams[ $i ] ? get_the_title( $teams[ $i ] ) : sprintf( __( 'Select %s' ), 'Team' ); ?></strong>
|
||||
<strong><?php echo $value ? get_the_title( $value ) : sprintf( __( 'Select %s' ), 'Team' ); ?></strong>
|
||||
</p>
|
||||
<?php sp_post_table( $post->ID, 'sp_player', 'block', 'sp_team', $i ); ?>
|
||||
<?php
|
||||
$ids = sp_array_between( (array)get_post_meta( $post->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 );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
endfor;
|
||||
endforeach;
|
||||
sp_post_adder( 'sp_player' );
|
||||
}
|
||||
|
||||
|
||||
119
helpers.php
119
helpers.php
@@ -1,4 +1,22 @@
|
||||
<?php
|
||||
if ( ! function_exists( 'sp_array_depth' ) ) {
|
||||
function sp_array_depth( $array ) {
|
||||
$max_depth = 1;
|
||||
if ( is_array( $array ) ):
|
||||
foreach ( $array as $value ):
|
||||
if ( is_array( $value ) ):
|
||||
$depth = sp_array_depth( $value ) + 1;
|
||||
if ( $depth > $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 );
|
||||
?>
|
||||
<div id="<?php echo $meta; ?>-all" class="posttypediv wp-tab-panel sp-tab-panel" style="display: <?php echo $display; ?>;">
|
||||
<input type="hidden" value="0" name="sportspress[<?php echo $meta; ?>]<?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]" />
|
||||
<ul class="categorychecklist form-no-clear">
|
||||
<?php
|
||||
$selected = (array)get_post_meta( $post_id, $meta, false );
|
||||
if ( isset( $index ) ):
|
||||
$keys = array_keys( $selected, 0 );
|
||||
if ( array_key_exists( $index, $keys ) ):
|
||||
$offset = $keys[ $index ];
|
||||
$end = sizeof( $selected );
|
||||
if ( array_key_exists( $index + 1, $keys ) )
|
||||
$end = $keys[ $index + 1 ];
|
||||
$length = $end - $offset;
|
||||
$selected = array_slice( $selected, $offset, $length );
|
||||
endif;
|
||||
endif;
|
||||
$selected = sp_array_between( (array)get_post_meta( $post_id, $meta, false ), 0, $index );
|
||||
$posts = get_pages( array( 'post_type' => $meta, 'number' => 0 ) );
|
||||
if ( empty( $posts ) )
|
||||
$posts = get_posts( array( 'post_type' => $meta, 'numberposts' => 0 ) );
|
||||
foreach ( $posts as $post ):
|
||||
$parents = get_post_ancestors( $post );
|
||||
if ( $data )
|
||||
$data_values = (array)get_post_meta( $post->ID, $data, false )
|
||||
if ( $filter )
|
||||
$filter_values = (array)get_post_meta( $post->ID, $filter, false )
|
||||
?>
|
||||
<li class="sp-post<?php
|
||||
if ( $data ):
|
||||
if ( $filter ):
|
||||
echo ' sp-filter-0';
|
||||
foreach ( $data_values as $data_value ):
|
||||
echo ' sp-filter-' . $data_value;
|
||||
foreach ( $filter_values as $filter_value ):
|
||||
echo ' sp-filter-' . $filter_value;
|
||||
endforeach;
|
||||
endif;
|
||||
?>">
|
||||
@@ -157,11 +176,10 @@ if ( ! function_exists( 'sp_post_checklist' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sp_post_table' ) ) {
|
||||
function sp_post_table( $post_id = null, $meta = 'post', $display = 'block', $data = null, $index = null ) {
|
||||
if ( ! isset( $post_id ) )
|
||||
global $post_id;
|
||||
$obj = get_post_type_object( $meta );
|
||||
if ( ! function_exists( 'sp_data_table' ) ) {
|
||||
function sp_data_table( $data = array(), $index = 0 ) {
|
||||
if ( !is_array( $data ) )
|
||||
$data = array();
|
||||
?>
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
@@ -175,53 +193,42 @@ if ( ! function_exists( 'sp_post_table' ) ) {
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$ids = (array)get_post_meta( $post_id, $meta, false );
|
||||
if ( isset( $index ) ):
|
||||
$keys = array_keys( $ids, 0 );
|
||||
if ( array_key_exists( $index, $keys ) ):
|
||||
$offset = $keys[ $index ];
|
||||
$end = sizeof( $ids );
|
||||
if ( array_key_exists( $index + 1, $keys ) )
|
||||
$end = $keys[ $index + 1 ];
|
||||
$length = $end - $offset;
|
||||
$ids = array_slice( $ids, $offset, $length );
|
||||
endif;
|
||||
endif;
|
||||
$i = 0;
|
||||
foreach ( $ids as $id ):
|
||||
if ( !$id ) continue;
|
||||
if ( $data )
|
||||
$data_values = (array)get_post_meta( $id, $data, false )
|
||||
foreach ( $data as $key => $values ):
|
||||
if ( !$key ) continue;
|
||||
?>
|
||||
<tr class="sp-post<?php
|
||||
if ( $i % 2 == 0 )
|
||||
echo ' alternate';
|
||||
if ( $data ):
|
||||
echo ' sp-filter-0';
|
||||
foreach ( $data_values as $data_value ):
|
||||
echo ' sp-filter-' . $data_value;
|
||||
endforeach;
|
||||
endif;
|
||||
?>">
|
||||
<td><?php echo get_the_title( $id ); ?></td>
|
||||
<td><input type="number" value="1" /></td>
|
||||
<td><input type="number" value="2" /></td>
|
||||
<td><input type="number" value="3" /></td>
|
||||
<td><input type="number" value="4" /></td>
|
||||
<td><?php echo get_the_title( $key ); ?></td>
|
||||
<?php for ( $j = 0; $j < 4; $j ++ ):
|
||||
if ( array_key_exists( $j, $values ) )
|
||||
$value = (int)$values[ $j ];
|
||||
else
|
||||
$value = 0;
|
||||
?>
|
||||
<td><input type="number" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][]" value="<?php echo $value; ?>" /></td>
|
||||
<?php endfor; ?>
|
||||
</tr>
|
||||
<?php
|
||||
$i++;
|
||||
endforeach;
|
||||
?>
|
||||
<tr<?php
|
||||
$values = $data[0];
|
||||
if ( $i % 2 == 0 )
|
||||
echo ' class="alternate"';
|
||||
?>>
|
||||
<td><strong>Total</strong></td>
|
||||
<td><input type="number" value="1" /></td>
|
||||
<td><input type="number" value="2" /></td>
|
||||
<td><input type="number" value="3" /></td>
|
||||
<td><input type="number" value="4" /></td>
|
||||
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
|
||||
<?php for ( $j = 0; $j < 4; $j ++ ):
|
||||
if ( array_key_exists( $j, $values ) )
|
||||
$value = (int)$values[ $j ];
|
||||
else
|
||||
$value = 0;
|
||||
?>
|
||||
<td><input type="number" name="sportspress[sp_stats][<?php echo $index; ?>][0][]" value="<?php echo $value; ?>" /></td>
|
||||
<?php endfor; ?>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user