Add multiple league tables
This commit is contained in:
@@ -84,7 +84,6 @@ function sp_event_stats_meta( $post ) {
|
||||
</p>
|
||||
<?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();
|
||||
@@ -94,7 +93,7 @@ function sp_event_stats_meta( $post ) {
|
||||
else
|
||||
$data[ $id ] = array();
|
||||
endforeach;
|
||||
sp_data_table( $data, $value );
|
||||
sp_data_table( $data, $value, array( 'Player', 'Goals', 'Assists', 'Yellow Cards', 'Red Cards' ) );
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
18
helpers.php
18
helpers.php
@@ -177,18 +177,16 @@ if ( ! function_exists( 'sp_post_checklist' ) ) {
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'sp_data_table' ) ) {
|
||||
function sp_data_table( $data = array(), $index = 0 ) {
|
||||
function sp_data_table( $data = array(), $index = 0, $columns = array( 'Name' ) ) {
|
||||
if ( !is_array( $data ) )
|
||||
$data = array();
|
||||
?>
|
||||
<table class="widefat">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Player</th>
|
||||
<th>Goals</th>
|
||||
<th>Assists</th>
|
||||
<th>Yellow Cards</th>
|
||||
<th>Red Cards</th>
|
||||
<?php foreach ( $columns as $column ): ?>
|
||||
<th><?php echo $column; ?></th>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -202,13 +200,13 @@ if ( ! function_exists( 'sp_data_table' ) ) {
|
||||
echo ' alternate';
|
||||
?>">
|
||||
<td><?php echo get_the_title( $key ); ?></td>
|
||||
<?php for ( $j = 0; $j < 4; $j ++ ):
|
||||
<?php for ( $j = 0; $j < sizeof( $columns ) - 1; $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>
|
||||
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][<?php echo $key; ?>][]" value="<?php echo $value; ?>" /></td>
|
||||
<?php endfor; ?>
|
||||
</tr>
|
||||
<?php
|
||||
@@ -221,13 +219,13 @@ if ( ! function_exists( 'sp_data_table' ) ) {
|
||||
echo ' class="alternate"';
|
||||
?>>
|
||||
<td><strong><?php _e( 'Total', 'sportspress' ); ?></strong></td>
|
||||
<?php for ( $j = 0; $j < 4; $j ++ ):
|
||||
<?php for ( $j = 0; $j < sizeof( $columns ) - 1; $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>
|
||||
<td><input type="text" name="sportspress[sp_stats][<?php echo $index; ?>][0][]" value="<?php echo $value; ?>" /></td>
|
||||
<?php endfor; ?>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
31
table.php
31
table.php
@@ -8,7 +8,8 @@ function sp_table_cpt_init() {
|
||||
'labels' => $labels,
|
||||
'public' => true,
|
||||
'hierarchical' => false,
|
||||
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'page-attributes' ),
|
||||
'supports' => array( 'title', 'author', 'thumbnail', 'page-attributes' ),
|
||||
'register_meta_box_cb' => 'sp_table_meta_init',
|
||||
'rewrite' => array( 'slug' => 'table' )
|
||||
);
|
||||
register_post_type( 'sp_table', $args );
|
||||
@@ -25,4 +26,32 @@ function sp_table_edit_columns() {
|
||||
return $columns;
|
||||
}
|
||||
add_filter( 'manage_edit-sp_table_columns', 'sp_table_edit_columns' );
|
||||
|
||||
function sp_table_meta_init() {
|
||||
remove_meta_box( 'submitdiv', 'sp_table', 'side' );
|
||||
add_meta_box( 'submitdiv', __( 'Event', 'sportspress' ), 'post_submit_meta_box', 'sp_table', 'side', 'high' );
|
||||
add_meta_box( 'sp_teamdiv', __( 'Teams', 'sportspress' ), 'sp_table_team_meta', 'sp_table', 'side', 'high' );
|
||||
add_meta_box( 'sp_statsdiv', __( 'Statistics', 'sportspress' ), 'sp_table_stats_meta', 'sp_table', 'normal', 'high' );
|
||||
}
|
||||
|
||||
function sp_table_team_meta( $post ) {
|
||||
sp_post_checklist( $post->ID, 'sp_team' );
|
||||
sp_post_adder( 'sp_team' );
|
||||
sp_nonce();
|
||||
}
|
||||
|
||||
function sp_table_stats_meta( $post ) {
|
||||
$ids = (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 ( array_key_exists( $id, $stats ) )
|
||||
$data[ $id ] = $stats[ $id ];
|
||||
else
|
||||
$data[ $id ] = array();
|
||||
endforeach;
|
||||
sp_data_table( $data, 0, array( 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ) );
|
||||
sp_post_adder( 'sp_team' );
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user