Add per-league statistics editor to team
This commit is contained in:
@@ -76,6 +76,8 @@ function sp_event_stats_meta( $post ) {
|
|||||||
$limit = get_option( 'sp_event_team_count' );
|
$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 );
|
||||||
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
|
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
|
||||||
|
|
||||||
|
// Teams
|
||||||
foreach ( $teams as $key => $value ):
|
foreach ( $teams as $key => $value ):
|
||||||
$players = sp_array_between( (array)get_post_meta( $post->ID, 'sp_player', false ), 0, $key );
|
$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() ) );
|
$data = sp_array_combine( $players, sp_array_value( $stats, $value, array() ) );
|
||||||
@@ -86,7 +88,7 @@ function sp_event_stats_meta( $post ) {
|
|||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
endforeach;
|
endforeach;
|
||||||
sp_post_adder( 'sp_player' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sp_event_edit_columns() {
|
function sp_event_edit_columns() {
|
||||||
|
|||||||
51
helpers.php
51
helpers.php
@@ -46,7 +46,7 @@ if ( !function_exists( 'sp_array_combine' ) ) {
|
|||||||
function sp_array_combine( $keys = array(), $values = array() ) {
|
function sp_array_combine( $keys = array(), $values = array() ) {
|
||||||
$output = array();
|
$output = array();
|
||||||
foreach ( $keys as $key ):
|
foreach ( $keys as $key ):
|
||||||
if ( array_key_exists( $key, $values ) )
|
if ( is_array( $values ) && array_key_exists( $key, $values ) )
|
||||||
$output[ $key ] = $values[ $key ];
|
$output[ $key ] = $values[ $key ];
|
||||||
else
|
else
|
||||||
$output[ $key ] = array();
|
$output[ $key ] = array();
|
||||||
@@ -127,9 +127,11 @@ if ( !function_exists( 'sp_the_posts' ) ) {
|
|||||||
if ( ! isset( $post_id ) )
|
if ( ! isset( $post_id ) )
|
||||||
global $post_id;
|
global $post_id;
|
||||||
$ids = get_post_meta( $post_id, $meta, false );
|
$ids = get_post_meta( $post_id, $meta, false );
|
||||||
|
if ( ( $key = array_search( 0, $ids ) ) !== false )
|
||||||
|
unset( $ids[ $key ] );
|
||||||
$i = 0;
|
$i = 0;
|
||||||
$count = count( $ids );
|
$count = count( $ids );
|
||||||
if ( isset( $ids ) && $ids && is_array( $ids ) ):
|
if ( isset( $ids ) && $ids && is_array( $ids ) && !empty( $ids ) ):
|
||||||
foreach ( $ids as $id ):
|
foreach ( $ids as $id ):
|
||||||
if ( !$id ) continue;
|
if ( !$id ) continue;
|
||||||
if ( !empty( $before ) ):
|
if ( !empty( $before ) ):
|
||||||
@@ -145,7 +147,10 @@ if ( !function_exists( 'sp_the_posts' ) ) {
|
|||||||
edit_post_link( get_the_title( $parent ), '', '', $parent );
|
edit_post_link( get_the_title( $parent ), '', '', $parent );
|
||||||
echo $delimiter;
|
echo $delimiter;
|
||||||
endforeach;
|
endforeach;
|
||||||
edit_post_link( get_the_title( $id ), '', '', $id );
|
$title = get_the_title( $id );
|
||||||
|
if ( empty( $title ) )
|
||||||
|
$title = __( '(no title)' );
|
||||||
|
edit_post_link( $title, '', '', $id );
|
||||||
if ( !empty( $after ) ):
|
if ( !empty( $after ) ):
|
||||||
if ( is_array( $after ) && array_key_exists( $i, $after ) )
|
if ( is_array( $after ) && array_key_exists( $i, $after ) )
|
||||||
echo ' - ' . $after[ $i ];
|
echo ' - ' . $after[ $i ];
|
||||||
@@ -188,7 +193,12 @@ if ( !function_exists( 'sp_post_checklist' ) ) {
|
|||||||
<?php echo str_repeat( '<ul><li>', sizeof( $parents ) ); ?>
|
<?php echo str_repeat( '<ul><li>', sizeof( $parents ) ); ?>
|
||||||
<label class="selectit">
|
<label class="selectit">
|
||||||
<input type="checkbox" value="<?php echo $post->ID; ?>" name="sportspress[<?php echo $meta; ?>]<?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]"<?php if ( in_array( $post->ID, $selected ) ) echo ' checked="checked"'; ?>>
|
<input type="checkbox" value="<?php echo $post->ID; ?>" name="sportspress[<?php echo $meta; ?>]<?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]"<?php if ( in_array( $post->ID, $selected ) ) echo ' checked="checked"'; ?>>
|
||||||
<?php echo $post->post_title; ?>
|
<?php
|
||||||
|
$title = $post->post_title;
|
||||||
|
if ( empty( $title ) )
|
||||||
|
$title = __( '(no title)' );
|
||||||
|
echo $title;
|
||||||
|
?>
|
||||||
</label>
|
</label>
|
||||||
<?php echo str_repeat( '</li></ul>', sizeof( $parents ) ); ?>
|
<?php echo str_repeat( '</li></ul>', sizeof( $parents ) ); ?>
|
||||||
</li>
|
</li>
|
||||||
@@ -202,7 +212,8 @@ 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 ) {
|
function sp_data_table( $data = array(), $index = 0, $columns = array( 'Name' ), $total = true, $auto = true, $rowtype = 'post' ) {
|
||||||
|
global $pagenow;
|
||||||
if ( !is_array( $data ) )
|
if ( !is_array( $data ) )
|
||||||
$data = array();
|
$data = array();
|
||||||
?>
|
?>
|
||||||
@@ -222,20 +233,32 @@ if ( !function_exists( 'sp_data_table' ) ) {
|
|||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ( $data as $key => $values ):
|
foreach ( $data as $key => $values ):
|
||||||
if ( !$key ) continue;
|
if ( !$key ) continue;
|
||||||
$is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : 0;
|
$is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : $pagenow == 'post-new.php';
|
||||||
?>
|
?>
|
||||||
<tr class="sp-post<?php
|
<tr class="sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||||
if ( $i % 2 == 0 )
|
<td>
|
||||||
echo ' alternate';
|
<?php
|
||||||
?>">
|
switch( $rowtype ):
|
||||||
<td><?php echo get_the_title( $key ); ?></td>
|
case 'post':
|
||||||
|
$title = get_the_title( $key );
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$term = get_term( $key, $rowtype );
|
||||||
|
$title = $term->name;;
|
||||||
|
break;
|
||||||
|
endswitch;
|
||||||
|
if ( empty( $title ) )
|
||||||
|
$title = __( '(no title)' );
|
||||||
|
echo $title;
|
||||||
|
?>
|
||||||
|
</td>
|
||||||
<?php for ( $j = 0; $j < sizeof( $columns ) - 1; $j ++ ):
|
<?php for ( $j = 0; $j < sizeof( $columns ) - 1; $j ++ ):
|
||||||
if ( array_key_exists( $j, $values ) )
|
if ( array_key_exists( $j, $values ) )
|
||||||
$value = (int)$values[ $j ];
|
$value = (int)$values[ $j ];
|
||||||
else
|
else
|
||||||
$value = 0;
|
$value = 0;
|
||||||
?>
|
?>
|
||||||
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][]" value="<?php echo $value; ?>"<?php if ( $is_auto ) echo ' readonly="readonly"'; ?> /></td>
|
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][]" value="<?php echo $value; ?>" /></td>
|
||||||
<?php endfor; ?>
|
<?php endfor; ?>
|
||||||
<?php if ( $auto ): ?>
|
<?php if ( $auto ): ?>
|
||||||
<td><input type="checkbox" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][auto]" value="1"<?php if ( $is_auto ) echo ' checked="checked"'; ?> /></td>
|
<td><input type="checkbox" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][auto]" value="1"<?php if ( $is_auto ) echo ' checked="checked"'; ?> /></td>
|
||||||
@@ -247,7 +270,7 @@ if ( !function_exists( 'sp_data_table' ) ) {
|
|||||||
if ( $total ):
|
if ( $total ):
|
||||||
$values = array_key_exists( 0, $data ) ? $data[0] : array();
|
$values = array_key_exists( 0, $data ) ? $data[0] : array();
|
||||||
if ( $auto )
|
if ( $auto )
|
||||||
$is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : 0;
|
$is_auto = array_key_exists( 'auto', $values ) ? (int)$values[ 'auto' ] : $pagenow == 'post-new.php';
|
||||||
else
|
else
|
||||||
$is_auto = $i;
|
$is_auto = $i;
|
||||||
?>
|
?>
|
||||||
@@ -262,7 +285,7 @@ if ( !function_exists( 'sp_data_table' ) ) {
|
|||||||
else
|
else
|
||||||
$value = 0;
|
$value = 0;
|
||||||
?>
|
?>
|
||||||
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][0][]" value="<?php echo $value; ?>"<?php if ( $is_auto ) echo ' readonly="readonly"'; ?> /></td>
|
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][0][]" value="<?php echo $value; ?>" /></td>
|
||||||
<?php endfor; ?>
|
<?php endfor; ?>
|
||||||
<?php if ( $auto ): ?>
|
<?php if ( $auto ): ?>
|
||||||
<td><input type="checkbox" name="sportspress[sp_stats][<?php echo $index; ?>][0][auto]" value="1"<?php if ( $is_auto ) echo ' checked="checked"'; ?> /></td>
|
<td><input type="checkbox" name="sportspress[sp_stats][<?php echo $index; ?>][0][auto]" value="1"<?php if ( $is_auto ) echo ' checked="checked"'; ?> /></td>
|
||||||
|
|||||||
16
player.php
16
player.php
@@ -36,16 +36,24 @@ function sp_player_stats_meta( $post ) {
|
|||||||
$teams = (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' );
|
$leagues = (array)get_the_terms( $post->ID, 'sp_league' );
|
||||||
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
|
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
|
||||||
|
|
||||||
|
// Overall
|
||||||
|
$data = sp_array_combine( $teams, sp_array_value( $stats, 0, array() ) );
|
||||||
|
?>
|
||||||
|
<p><strong><?php _e( 'Overall', 'sportspress' ); ?></strong></p>
|
||||||
|
<?php sp_data_table( $data, 0, array( 'Team', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ) ); ?>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
// Leagues
|
||||||
foreach ( $leagues as $league ):
|
foreach ( $leagues as $league ):
|
||||||
if ( !$league ) continue;
|
if ( !$league ) continue;
|
||||||
$data = sp_array_combine( $teams, sp_array_value( $stats, $league->term_id, array() ) );
|
$data = sp_array_combine( $teams, sp_array_value( $stats, $league->term_id, array() ) );
|
||||||
?>
|
?>
|
||||||
<div>
|
<p><strong><?php echo $league->name; ?></strong></p>
|
||||||
<p><strong><?php echo $league->name; ?></strong></p>
|
<?php sp_data_table( $data, $league->term_id, array( 'Team', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ) ); ?>
|
||||||
<?php sp_data_table( $data, $league->term_id, array( 'Team', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ) ); ?>
|
|
||||||
</div>
|
|
||||||
<?php
|
<?php
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sp_player_profile_meta( $post ) {
|
function sp_player_profile_meta( $post ) {
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ jQuery(document).ready(function($){
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Activate checkboxes
|
||||||
|
$('.sp-data-table tr input[type=checkbox]').change();
|
||||||
|
|
||||||
// Change title
|
// Change title
|
||||||
$('.sp-title-generator select').change(function() {
|
$('.sp-title-generator select').change(function() {
|
||||||
title = $('.sp-title-generator select[value!=0]').map(function(){
|
title = $('.sp-title-generator select[value!=0]').map(function(){
|
||||||
|
|||||||
18
team.php
18
team.php
@@ -21,6 +21,7 @@ function sp_team_meta_init() {
|
|||||||
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_team', 'side', 'high' );
|
add_meta_box( 'submitdiv', __( 'Publish' ), 'post_submit_meta_box', 'sp_team', 'side', 'high' );
|
||||||
remove_meta_box( 'postimagediv', 'sp_team', 'side' );
|
remove_meta_box( 'postimagediv', 'sp_team', 'side' );
|
||||||
add_meta_box( 'postimagediv', __( 'Logo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_team', 'side', 'high' );
|
add_meta_box( 'postimagediv', __( 'Logo', 'sportspress' ), 'post_thumbnail_meta_box', 'sp_team', 'side', 'high' );
|
||||||
|
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_team_stats_meta', 'sp_team', 'normal', 'high' );
|
||||||
}
|
}
|
||||||
|
|
||||||
function sp_team_edit_columns() {
|
function sp_team_edit_columns() {
|
||||||
@@ -34,4 +35,21 @@ function sp_team_edit_columns() {
|
|||||||
return $columns;
|
return $columns;
|
||||||
}
|
}
|
||||||
add_filter( 'manage_edit-sp_team_columns', 'sp_team_edit_columns' );
|
add_filter( 'manage_edit-sp_team_columns', 'sp_team_edit_columns' );
|
||||||
|
|
||||||
|
function sp_team_stats_meta( $post ) {
|
||||||
|
$leagues = (array)get_the_terms( $post->ID, 'sp_league' );
|
||||||
|
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
|
||||||
|
|
||||||
|
$keys = array( 0 );
|
||||||
|
foreach ( $leagues as $key => $value ):
|
||||||
|
if ( is_object( $value ) && property_exists( $value, 'term_id' ) )
|
||||||
|
$keys[] = $value->term_id;
|
||||||
|
endforeach;
|
||||||
|
|
||||||
|
$data = sp_array_combine( $keys, sp_array_value( $stats, 0, array() ) );
|
||||||
|
?>
|
||||||
|
<?php sp_data_table( $data, 0, array( 'Team', 'Played', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ), true, true, 'sp_league' );
|
||||||
|
|
||||||
|
sp_nonce();
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user