Add player statistics placeholder in event

This commit is contained in:
Takumi
2013-07-29 01:13:02 +10:00
parent 0a67204b35
commit 44dba72251
3 changed files with 98 additions and 2 deletions

View File

@@ -30,12 +30,12 @@ function sp_event_meta_init() {
add_meta_box( 'submitdiv', __( 'Event', 'sportspress' ), 'post_submit_meta_box', 'sp_event', 'side', 'high' );
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_event_team_meta', 'sp_event', 'side', 'high' );
add_meta_box( 'sp_articlediv', __( 'Article', 'sportspress' ), 'sp_event_article_meta', 'sp_event', 'normal', 'high' );
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_event_stats_meta', 'sp_event', 'normal', 'high' );
}
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);
$scores = array_pad( array_slice( (array)get_post_meta( $post->ID, 'sp_score', false ), 0, $limit ), $limit, 0);
$players = (array)get_post_meta( $post->ID, 'sp_player', false );
for ( $i = 0; $i < $limit; $i++ ):
?>
@@ -52,7 +52,6 @@ function sp_event_team_meta( $post ) {
);
wp_dropdown_pages( $args );
?>
<input name="sportspress[sp_score][]" type="text" placeholder="<?php _e( 'Score', 'sportspress' ); ?>" size="4" value="<?php echo $scores[ $i ]; ?>" />
</p>
<ul id="sp_team-tabs" class="wp-tab-bar sp-tab-bar">
<li class="wp-tab-active"><a href="#sp_player-all"><?php _e( 'Players', 'sportspress' ); ?></a></li>
@@ -73,6 +72,23 @@ function sp_event_article_meta( $post ) {
wp_editor( $post->post_content, 'content' );
}
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++ ):
?>
<div>
<p>
<strong><?php echo $teams[ $i ] ? get_the_title( $teams[ $i ] ) : sprintf( __( 'Select %s' ), 'Team' ); ?></strong>
</p>
<?php sp_post_table( $post->ID, 'sp_player', 'block', 'sp_team', $i ); ?>
</div>
<?php
endfor;
sp_post_adder( 'sp_player' );
}
function sp_event_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',

View File

@@ -157,6 +157,75 @@ 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 );
?>
<table class="widefat">
<thead>
<tr>
<th>Player</th>
<th>Goals</th>
<th>Assists</th>
<th>Yellow Cards</th>
<th>Red Cards</th>
</tr>
</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;
foreach ( $ids as $id ):
if ( !$id ) continue;
if ( $data )
$data_values = (array)get_post_meta( $id, $data, false )
?>
<tr class="sp-post<?php
if ( $data ):
echo ' sp-filter-0';
foreach ( $data_values as $data_value ):
echo ' sp-filter-' . $data_value;
endforeach;
endif;
?>">
<td>
<label class="selectit">
<?php echo get_the_title( $id ); ?>
</label>
</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>
</tr>
<?php
endforeach;
?>
<tr>
<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>
</tr>
</tbody>
</table>
<?php
}
}
if ( ! function_exists( 'sp_post_adder' ) ) {
function sp_post_adder( $meta = 'post' ) {
$obj = get_post_type_object( $meta );

View File

@@ -97,6 +97,17 @@
#sp_profilediv .wp-editor-container {
background-color:#fff;
}
#sp_statsdiv .widefat td {
padding: 4px 7px;
line-height: 2;
}
#sp_statsdiv .widefat td:first-child {
white-space: nowrap;
}
#sp_statsdiv .widefat input[type="text"],
#sp_statsdiv .widefat input[type="number"] {
width: 100%;
}
.widefat th.column-sp_icon,
.widefat td.column-sp_icon {
width: 32px;