Add checkboxes to player statistics columns
This commit is contained in:
@@ -20,9 +20,10 @@ class SP_Meta_Box_Player_Statistics {
|
|||||||
*/
|
*/
|
||||||
public static function output( $post ) {
|
public static function output( $post ) {
|
||||||
$leagues = get_the_terms( $post->ID, 'sp_league' );
|
$leagues = get_the_terms( $post->ID, 'sp_league' );
|
||||||
|
|
||||||
$league_num = sizeof( $leagues );
|
$league_num = sizeof( $leagues );
|
||||||
|
|
||||||
|
$usecolumns = get_post_meta( $post->ID, 'sp_columns', true );
|
||||||
|
|
||||||
// Loop through statistics for each league
|
// Loop through statistics for each league
|
||||||
if ( $leagues ): foreach ( $leagues as $league ):
|
if ( $leagues ): foreach ( $leagues as $league ):
|
||||||
|
|
||||||
@@ -34,8 +35,7 @@ class SP_Meta_Box_Player_Statistics {
|
|||||||
|
|
||||||
$player = new SP_Player( $post );
|
$player = new SP_Player( $post );
|
||||||
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true );
|
list( $columns, $data, $placeholders, $merged, $seasons_teams ) = $player->data( $league->term_id, true );
|
||||||
|
self::table( $post->ID, $league->term_id, $columns, $usecolumns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_player_statistics' ) );
|
||||||
self::table( $post->ID, $league->term_id, $columns, $data, $placeholders, $merged, $seasons_teams, ! current_user_can( 'edit_sp_player_statistics' ) );
|
|
||||||
|
|
||||||
endforeach; else:
|
endforeach; else:
|
||||||
|
|
||||||
@@ -48,6 +48,7 @@ class SP_Meta_Box_Player_Statistics {
|
|||||||
* Save meta box data
|
* Save meta box data
|
||||||
*/
|
*/
|
||||||
public static function save( $post_id, $post ) {
|
public static function save( $post_id, $post ) {
|
||||||
|
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
|
||||||
update_post_meta( $post_id, 'sp_leagues', sp_array_value( $_POST, 'sp_leagues', array() ) );
|
update_post_meta( $post_id, 'sp_leagues', sp_array_value( $_POST, 'sp_leagues', array() ) );
|
||||||
if ( current_user_can( 'edit_sp_player_statistics' ) )
|
if ( current_user_can( 'edit_sp_player_statistics' ) )
|
||||||
update_post_meta( $post_id, 'sp_statistics', sp_array_value( $_POST, 'sp_statistics', array() ) );
|
update_post_meta( $post_id, 'sp_statistics', sp_array_value( $_POST, 'sp_statistics', array() ) );
|
||||||
@@ -56,8 +57,10 @@ class SP_Meta_Box_Player_Statistics {
|
|||||||
/**
|
/**
|
||||||
* Admin edit table
|
* Admin edit table
|
||||||
*/
|
*/
|
||||||
public static function table( $id = null, $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $readonly = true ) {
|
public static function table( $id = null, $league_id, $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $merged = array(), $leagues = array(), $readonly = true ) {
|
||||||
$teams = array_filter( get_post_meta( $id, 'sp_team', false ) );
|
$teams = array_filter( get_post_meta( $id, 'sp_team', false ) );
|
||||||
|
if ( is_array( $usecolumns ) )
|
||||||
|
$usecolumns = array_filter( $usecolumns );
|
||||||
?>
|
?>
|
||||||
<div class="sp-data-table-container">
|
<div class="sp-data-table-container">
|
||||||
<table class="widefat sp-data-table">
|
<table class="widefat sp-data-table">
|
||||||
@@ -65,8 +68,11 @@ class SP_Meta_Box_Player_Statistics {
|
|||||||
<tr>
|
<tr>
|
||||||
<th><?php _e( 'Season', 'sportspress' ); ?></th>
|
<th><?php _e( 'Season', 'sportspress' ); ?></th>
|
||||||
<th><?php _e( 'Team', 'sportspress' ); ?></th>
|
<th><?php _e( 'Team', 'sportspress' ); ?></th>
|
||||||
<?php foreach ( $columns as $label ): ?>
|
<?php foreach ( $columns as $key => $label ): ?>
|
||||||
<th><?php echo $label; ?></th>
|
<th><label for="sp_columns_<?php echo $key; ?>">
|
||||||
|
<input type="checkbox" name="sp_columns[]" value="<?php echo $key; ?>" id="sp_columns_<?php echo $key; ?>" <?php checked( ! is_array( $usecolumns ) || in_array( $key, $usecolumns ) ); ?>>
|
||||||
|
<?php echo $label; ?>
|
||||||
|
</label></th>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
$metrics = (array)get_post_meta( $this->ID, 'sp_metrics', true );
|
$metrics = (array)get_post_meta( $this->ID, 'sp_metrics', true );
|
||||||
$stats = (array)get_post_meta( $this->ID, 'sp_statistics', true );
|
$stats = (array)get_post_meta( $this->ID, 'sp_statistics', true );
|
||||||
$leagues = sp_array_value( (array)get_post_meta( $this->ID, 'sp_leagues', true ), $league_id, array() );
|
$leagues = sp_array_value( (array)get_post_meta( $this->ID, 'sp_leagues', true ), $league_id, array() );
|
||||||
|
$usecolumns = get_post_meta( $this->ID, 'sp_columns', true );
|
||||||
|
|
||||||
// Get labels from performance variables
|
// Get labels from performance variables
|
||||||
$performance_labels = (array)sp_get_var_labels( 'sp_performance' );
|
$performance_labels = (array)sp_get_var_labels( 'sp_performance' );
|
||||||
@@ -298,6 +299,13 @@ class SP_Player extends SP_Custom_Post {
|
|||||||
if ( $admin ):
|
if ( $admin ):
|
||||||
return array( $columns, $data, $placeholders, $merged, $leagues );
|
return array( $columns, $data, $placeholders, $merged, $leagues );
|
||||||
else:
|
else:
|
||||||
|
if ( ! is_array( $usecolumns ) )
|
||||||
|
$usecolumns = array();
|
||||||
|
foreach ( $columns as $key => $label ):
|
||||||
|
if ( ! in_array( $key, $usecolumns ) ):
|
||||||
|
unset( $columns[ $key ] );
|
||||||
|
endif;
|
||||||
|
endforeach;
|
||||||
$labels = array_merge( array( 'name' => SP()->text->string('Season'), 'team' => SP()->text->string('Team') ), $columns );
|
$labels = array_merge( array( 'name' => SP()->text->string('Season'), 'team' => SP()->text->string('Team') ), $columns );
|
||||||
$merged[0] = $labels;
|
$merged[0] = $labels;
|
||||||
return $merged;
|
return $merged;
|
||||||
|
|||||||
Reference in New Issue
Block a user