Adjust team columns meta box
This commit is contained in:
@@ -140,9 +140,9 @@ class SP_Admin_Meta_Boxes {
|
||||
add_meta_box( 'sp_shortcodediv', __( 'Shortcodes', 'sportspress' ), 'SP_Meta_Box_Team_Shortcode::output', 'sp_team', 'side', 'default' );
|
||||
add_meta_box( 'sp_detailsdiv', __( 'Details', 'sportspress' ), 'SP_Meta_Box_Team_Details::output', 'sp_team', 'side', 'default' );
|
||||
if ( isset( $post ) && isset( $post->ID ) ):
|
||||
add_meta_box( 'sp_columnssdiv', __( 'Table Columns', 'sportspress' ), 'SP_Meta_Box_Team_Columns::output', 'sp_team', 'normal', 'high' );
|
||||
add_meta_box( 'sp_listsdiv', __( 'Player Lists', 'sportspress' ), 'SP_Meta_Box_Team_Lists::output', 'sp_team', 'normal', 'high' );
|
||||
add_meta_box( 'sp_tablesdiv', __( 'League Tables', 'sportspress' ), 'SP_Meta_Box_Team_Tables::output', 'sp_team', 'normal', 'high' );
|
||||
add_meta_box( 'sp_columnssdiv', __( 'Table Columns', 'sportspress' ), 'SP_Meta_Box_Team_Columns::output', 'sp_team', 'normal', 'high' );
|
||||
endif;
|
||||
add_meta_box( 'sp_editordiv', __( 'Profile', 'sportspress' ), 'SP_Meta_Box_Team_Editor::output', 'sp_team', 'normal', 'low' );
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta_Boxes
|
||||
* @version 0.8
|
||||
* @version 1.3
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
@@ -30,43 +30,33 @@ class SP_Meta_Box_Team_Columns {
|
||||
?>
|
||||
<p><strong><?php echo $league->name; ?></strong></p>
|
||||
<?php
|
||||
list( $columns, $data, $placeholders, $merged, $leagues_seasons ) = $team->columns( $league_id, true );
|
||||
self::table( $league_id, $columns, $data, $placeholders, $merged, $leagues_seasons );
|
||||
list( $columns, $data, $placeholders ) = $team->columns( $league_id );
|
||||
self::table( $league_id, $columns, $data, $placeholders );
|
||||
|
||||
endforeach; endif;
|
||||
?>
|
||||
<p><strong><?php _e( 'Total', 'sportspress' ); ?></strong></p>
|
||||
<?php
|
||||
list( $columns, $data, $placeholders, $merged, $leagues_seasons ) = $team->columns( 0, true );
|
||||
self::table( 0, $columns, $data, $placeholders, $merged, $leagues_seasons );
|
||||
list( $columns, $data, $placeholders ) = $team->columns( 0 );
|
||||
self::table( 0, $columns, $data, $placeholders );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_leagues', sp_array_value( $_POST, 'sp_leagues', array() ) );
|
||||
update_post_meta( $post_id, 'sp_columns', sp_array_value( $_POST, 'sp_columns', array() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin edit table
|
||||
*/
|
||||
public static function table( $league_id, $columns = array(), $data = array(), $placeholders = array(), $merged = array(), $seasons = array(), $readonly = false ) {
|
||||
public static function table( $league_id, $columns = array(), $data = array(), $placeholders = array() ) {
|
||||
?>
|
||||
<div class="sp-data-table-container">
|
||||
<table class="widefat sp-data-table sp-team-column-table sp-select-all-range">
|
||||
<thead>
|
||||
<tr>
|
||||
<?php if ( $league_id ): ?>
|
||||
<th class="check-column">
|
||||
<?php if ( sizeof( $data ) > 1 ): ?>
|
||||
<input class="sp-select-all" type="checkbox">
|
||||
<?php else: ?>
|
||||
<input class="sp-select-all" type="checkbox" disabled>
|
||||
<?php endif; ?>
|
||||
</th>
|
||||
<?php endif; ?>
|
||||
<th><?php _e( 'Season', 'sportspress' ); ?></th>
|
||||
<?php foreach ( $columns as $label ): ?>
|
||||
<th><?php echo $label; ?></th>
|
||||
@@ -80,15 +70,6 @@ class SP_Meta_Box_Team_Columns {
|
||||
$div = get_term( $div_id, 'sp_season' );
|
||||
?>
|
||||
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
|
||||
<?php if ( $league_id ): ?>
|
||||
<td>
|
||||
<?php if ( $div_id ): ?>
|
||||
<input type="checkbox" name="sp_leagues[<?php echo $league_id; ?>][<?php echo $div_id; ?>]" id="sp_leagues_<?php echo $league_id; ?>_<?php echo $div_id; ?>" value="1" <?php checked( sp_array_value( $seasons, $div_id, 0 ), 1 ); ?>>
|
||||
<?php else: ?>
|
||||
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<?php endif; ?>
|
||||
<td>
|
||||
<label for="sp_leagues_<?php echo $league_id; ?>_<?php echo $div_id; ?>">
|
||||
<?php
|
||||
@@ -103,10 +84,7 @@ class SP_Meta_Box_Team_Columns {
|
||||
<td><?php
|
||||
$value = sp_array_value( sp_array_value( $data, $div_id, array() ), $column, null );
|
||||
$placeholder = sp_array_value( sp_array_value( $placeholders, $div_id, array() ), $column, 0 );
|
||||
if ( $readonly )
|
||||
echo $value ? $value : $placeholder;
|
||||
else
|
||||
echo '<input type="text" name="sp_columns[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . $value . '" placeholder="' . $placeholder . '"' . ( $readonly ? ' disabled="disabled"' : '' ) . ' />';
|
||||
echo '<input type="text" name="sp_columns[' . $league_id . '][' . $div_id . '][' . $column . ']" value="' . $value . '" placeholder="' . $placeholder . '" />';
|
||||
?></td>
|
||||
<?php endforeach; ?>
|
||||
</tr>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The SportsPress team class handles individual team data.
|
||||
*
|
||||
* @class SP_Team
|
||||
* @version 1.2.3
|
||||
* @version 1.3
|
||||
* @package SportsPress/Classes
|
||||
* @category Class
|
||||
* @author ThemeBoy
|
||||
@@ -41,10 +41,9 @@ class SP_Team extends SP_Custom_Post {
|
||||
* @param bool $admin
|
||||
* @return array
|
||||
*/
|
||||
public function columns( $league_id, $admin = false ) {
|
||||
public function columns( $league_id ) {
|
||||
$seasons = (array)get_the_terms( $this->ID, 'sp_season' );
|
||||
$columns = (array)get_post_meta( $this->ID, 'sp_columns', true );
|
||||
$leagues_seasons = sp_array_value( (array)get_post_meta( $this->ID, 'sp_leagues', true ), $league_id, array() );
|
||||
|
||||
// Get labels from result variables
|
||||
$result_labels = (array)sp_get_var_labels( 'sp_result' );
|
||||
@@ -241,41 +240,7 @@ class SP_Team extends SP_Custom_Post {
|
||||
// Get columns from column variables
|
||||
$columns = sp_get_var_labels( 'sp_column' );
|
||||
|
||||
// Merge the data and placeholders arrays
|
||||
$merged = array();
|
||||
|
||||
foreach( $placeholders as $season_id => $season_data ):
|
||||
|
||||
if ( ! sp_array_value( $leagues_seasons, $season_id, 0 ) )
|
||||
continue;
|
||||
|
||||
$season_name = sp_array_value( $season_names, $season_id, ' ' );
|
||||
|
||||
// Add season name to row
|
||||
$merged[ $season_id ] = array(
|
||||
'name' => $season_name
|
||||
);
|
||||
|
||||
foreach( $season_data as $key => $value ):
|
||||
|
||||
// Use static data if key exists and value is not empty, else use placeholder
|
||||
if ( array_key_exists( $season_id, $data ) && array_key_exists( $key, $data[ $season_id ] ) && $data[ $season_id ][ $key ] != '' ):
|
||||
$merged[ $season_id ][ $key ] = $data[ $season_id ][ $key ];
|
||||
else:
|
||||
$merged[ $season_id ][ $key ] = $value;
|
||||
endif;
|
||||
|
||||
endforeach;
|
||||
|
||||
endforeach;
|
||||
|
||||
if ( $admin ):
|
||||
return array( $columns, $data, $placeholders, $merged, $leagues_seasons );
|
||||
else:
|
||||
$labels = array_merge( array( 'name' => __( 'Season', 'sportspress' ) ), $columns );
|
||||
$merged[0] = $labels;
|
||||
return $merged;
|
||||
endif;
|
||||
return array( $columns, $data, $placeholders );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user