Add option to choose individual/team mode per event
This commit is contained in:
@@ -123,6 +123,13 @@ class SP_Admin_Meta_Boxes {
|
||||
'context' => 'side',
|
||||
'priority' => 'default',
|
||||
),
|
||||
'mode' => array(
|
||||
'title' => __( 'Mode', 'sportspress' ),
|
||||
'save' => 'SP_Meta_Box_Event_Mode::save',
|
||||
'output' => 'SP_Meta_Box_Event_Mode::output',
|
||||
'context' => 'side',
|
||||
'priority' => 'default',
|
||||
),
|
||||
'details' => array(
|
||||
'title' => __( 'Details', 'sportspress' ),
|
||||
'save' => 'SP_Meta_Box_Event_Details::save',
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* Event Mode
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta_Boxes
|
||||
* @version 2.2.11
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* SP_Meta_Box_Event_Mode
|
||||
*/
|
||||
class SP_Meta_Box_Event_Mode {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
$the_mode = sp_get_post_mode( $post->ID );
|
||||
?>
|
||||
<div id="post-formats-select">
|
||||
<?php foreach ( array( 'team' => __( 'Team vs team', 'sportspress' ), 'player' => __( 'Player vs player', 'sportspress' ) ) as $key => $mode ): ?>
|
||||
<input type="radio" name="sp_mode" class="post-format" id="post-format-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( $the_mode, $key ); ?>> <label for="post-format-<?php echo $key; ?>" class="post-format-icon post-format-<?php echo $key; ?>"><?php echo $mode; ?></label><br>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_mode', sp_array_value( $_POST, 'sp_mode', 'team' ) );
|
||||
}
|
||||
}
|
||||
@@ -53,17 +53,14 @@ class SP_Meta_Box_Event_Performance {
|
||||
$positions = get_terms( 'sp_position', $args );
|
||||
endif;
|
||||
|
||||
// Get status option
|
||||
if ( 'yes' == get_option( 'sportspress_event_show_status', 'yes' ) )
|
||||
$status = true;
|
||||
else
|
||||
$status = false;
|
||||
|
||||
// Apply filters to labels
|
||||
$labels = apply_filters( 'sportspress_event_performance_labels_admin', $labels );
|
||||
|
||||
// Check if individual mode
|
||||
$is_individual = get_option( 'sportspress_load_individual_mode_module', 'no' ) === 'yes' ? true : false;
|
||||
$is_individual = 'player' === sp_get_post_mode( $post->ID );
|
||||
|
||||
// Get status option
|
||||
$status = ! $is_individual;
|
||||
|
||||
self::tables( $post->ID, $stats, $labels, $columns, $teams, $has_checkboxes, $positions, $status, $formats, $order, $numbers, $is_individual, $timeline, $timed );
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ class SP_Meta_Box_Event_Teams {
|
||||
public static function output( $post ) {
|
||||
$limit = get_option( 'sportspress_event_teams', 2 );
|
||||
$teams = (array) get_post_meta( $post->ID, 'sp_team', false );
|
||||
if ( $limit ) {
|
||||
$post_type = sp_get_post_mode_type( $post->ID );
|
||||
if ( $limit && 'sp_player' !== $post_type ) {
|
||||
for ( $i = 0; $i < $limit; $i ++ ):
|
||||
$team = array_shift( $teams );
|
||||
?>
|
||||
@@ -29,7 +30,7 @@ class SP_Meta_Box_Event_Teams {
|
||||
<p class="sp-tab-select sp-title-generator">
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'post_type' => $post_type,
|
||||
'name' => 'sp_team[]',
|
||||
'class' => 'sportspress-pages',
|
||||
'show_option_none' => __( '— None —', 'sportspress' ),
|
||||
@@ -119,10 +120,10 @@ class SP_Meta_Box_Event_Teams {
|
||||
endfor;
|
||||
} else {
|
||||
?>
|
||||
<p><strong><?php printf( __( 'Select %s:', 'sportspress' ), __( 'Teams', 'sportspress' ) ); ?></strong></p>
|
||||
<p><strong><?php printf( __( 'Select %s:', 'sportspress' ), sp_get_post_mode_label( $post->ID ) ); ?></strong></p>
|
||||
<?php
|
||||
$args = array(
|
||||
'post_type' => 'sp_team',
|
||||
'post_type' => $post_type,
|
||||
'name' => 'sp_team[]',
|
||||
'selected' => $teams,
|
||||
'values' => 'ID',
|
||||
@@ -132,7 +133,7 @@ class SP_Meta_Box_Event_Teams {
|
||||
'placeholder' => __( 'None', 'sportspress' ),
|
||||
);
|
||||
if ( ! sp_dropdown_pages( $args ) ):
|
||||
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
sp_post_adder( $post_type, __( 'Add New', 'sportspress' ) );
|
||||
endif;
|
||||
}
|
||||
wp_nonce_field( 'sp-get-players', 'sp-get-players-nonce', false );
|
||||
@@ -142,17 +143,30 @@ class SP_Meta_Box_Event_Teams {
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
||||
$tabs = array();
|
||||
$sections = get_option( 'sportspress_event_performance_sections', -1 );
|
||||
if ( -1 == $sections ) {
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
|
||||
} else {
|
||||
$players = array_merge( sp_array_value( $_POST, 'sp_offense', array() ), sp_array_value( $_POST, 'sp_defense', array() ) );
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_offense', sp_array_value( $_POST, 'sp_offense', array() ) );
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_defense', sp_array_value( $_POST, 'sp_defense', array() ) );
|
||||
$teams = sp_array_value( $_POST, 'sp_team', array() );
|
||||
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_team', $teams );
|
||||
|
||||
$post_type = sp_get_post_mode_type( $post->ID );
|
||||
|
||||
if ( 'sp_player' === $post_type ) {
|
||||
$players = array();
|
||||
foreach ( $teams as $player ) {
|
||||
$players[] = array( 0, $player );
|
||||
}
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_player', $players );
|
||||
} else {
|
||||
$tabs = array();
|
||||
$sections = get_option( 'sportspress_event_performance_sections', -1 );
|
||||
if ( -1 == $sections ) {
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
|
||||
} else {
|
||||
$players = array_merge( sp_array_value( $_POST, 'sp_offense', array() ), sp_array_value( $_POST, 'sp_defense', array() ) );
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_offense', sp_array_value( $_POST, 'sp_offense', array() ) );
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_defense', sp_array_value( $_POST, 'sp_defense', array() ) );
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_player', $players );
|
||||
}
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_staff', sp_array_value( $_POST, 'sp_staff', array() ) );
|
||||
}
|
||||
sp_update_post_meta_recursive( $post_id, 'sp_staff', sp_array_value( $_POST, 'sp_staff', array() ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class SP_Meta_Box_List_Data {
|
||||
<th><?php echo in_array( $orderby, array( 'number', 'name' ) ) ? '#' : __( 'Rank', 'sportspress' ); ?></th>
|
||||
<?php } ?>
|
||||
<th><?php _e( 'Player', 'sportspress' ); ?></th>
|
||||
<?php if ( array_key_exists( 'team', $columns ) && apply_filters( 'sportspress_has_teams', true ) ) { ?>
|
||||
<?php if ( array_key_exists( 'team', $columns ) ) { ?>
|
||||
<th><?php _e( 'Team', 'sportspress' ); ?></th>
|
||||
<?php } ?>
|
||||
<?php if ( array_key_exists( 'position', $columns ) ) { ?>
|
||||
@@ -103,7 +103,7 @@ class SP_Meta_Box_List_Data {
|
||||
<a class="button button-primary sp-save"><?php _e( 'Save', 'sportspress' ); ?></a>
|
||||
</span>
|
||||
</td>
|
||||
<?php if ( array_key_exists( 'team', $columns ) && apply_filters( 'sportspress_has_teams', true ) ) { ?>
|
||||
<?php if ( array_key_exists( 'team', $columns ) ) { ?>
|
||||
<td>
|
||||
<?php
|
||||
$selected = sp_array_value( $player_stats, 'team', get_post_meta( get_the_ID(), 'sp_team', true ) );
|
||||
|
||||
@@ -42,7 +42,6 @@ class SP_Meta_Box_List_Details {
|
||||
sp_taxonomy_field( $taxonomy, $post, true );
|
||||
}
|
||||
?>
|
||||
<?php if ( apply_filters( 'sportspress_list_team_selector', true ) ) { ?>
|
||||
<p><strong><?php _e( 'Team', 'sportspress' ); ?></strong></p>
|
||||
<p class="sp-tab-select sp-team-era-selector">
|
||||
<?php
|
||||
@@ -63,7 +62,6 @@ class SP_Meta_Box_List_Details {
|
||||
<option value="past" <?php selected( 'past', $era ); ?>><?php _e( 'Past', 'sportspress' ); ?></option>
|
||||
</select>
|
||||
</p>
|
||||
<?php } ?>
|
||||
<p><strong><?php _e( 'Grouping', 'sportspress' ); ?></strong></p>
|
||||
<p>
|
||||
<select name="sp_grouping">
|
||||
|
||||
@@ -99,7 +99,6 @@ class SP_Meta_Box_Player_Details {
|
||||
?></p>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ( apply_filters( 'sportspress_player_teams', true ) ) { ?>
|
||||
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
|
||||
<p><?php
|
||||
$args = array(
|
||||
@@ -129,7 +128,6 @@ class SP_Meta_Box_Player_Details {
|
||||
);
|
||||
sp_dropdown_pages( $args );
|
||||
?></p>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ( taxonomy_exists( 'sp_league' ) ) { ?>
|
||||
<p><strong><?php _e( 'Competitions', 'sportspress' ); ?></strong></p>
|
||||
|
||||
@@ -89,7 +89,6 @@ class SP_Meta_Box_Staff_Details {
|
||||
<?php endforeach; ?>
|
||||
</select></p>
|
||||
|
||||
<?php if ( apply_filters( 'sportspress_staff_teams', true ) ) { ?>
|
||||
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
|
||||
<p><?php
|
||||
$args = array(
|
||||
@@ -119,7 +118,6 @@ class SP_Meta_Box_Staff_Details {
|
||||
);
|
||||
sp_dropdown_pages( $args );
|
||||
?></p>
|
||||
<?php } ?>
|
||||
|
||||
<p><strong><?php _e( 'Competitions', 'sportspress' ); ?></strong></p>
|
||||
<p><?php
|
||||
|
||||
@@ -23,7 +23,7 @@ class SP_Meta_Box_Table_Data {
|
||||
list( $columns, $usecolumns, $data, $placeholders, $merged ) = $table->data( true );
|
||||
$adjustments = $table->adjustments;
|
||||
$highlight = get_post_meta( $table->ID, 'sp_highlight', true );
|
||||
self::table( $columns, $usecolumns, $data, $placeholders, $adjustments, $highlight );
|
||||
self::table( $table->ID, $columns, $usecolumns, $data, $placeholders, $adjustments, $highlight );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,10 +39,19 @@ class SP_Meta_Box_Table_Data {
|
||||
/**
|
||||
* Admin edit table
|
||||
*/
|
||||
public static function table( $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array(), $highlight = null ) {
|
||||
public static function table( $id, $columns = array(), $usecolumns = null, $data = array(), $placeholders = array(), $adjustments = array(), $highlight = null ) {
|
||||
if ( is_array( $usecolumns ) )
|
||||
$usecolumns = array_filter( $usecolumns );
|
||||
|
||||
$mode = sp_get_post_mode( $id );
|
||||
|
||||
if ( 'player' === $mode ) {
|
||||
$show_team_logo = get_option( 'sportspress_list_show_photos', 'no' ) == 'yes' ? true : false;
|
||||
$icon_class = 'sp-icon-tshirt';
|
||||
} else {
|
||||
$show_team_logo = get_option( 'sportspress_table_show_logos', 'no' ) == 'yes' ? true : false;
|
||||
$icon_class = 'sp-icon-shield';
|
||||
}
|
||||
?>
|
||||
<input type="hidden" name="sp_highlight" value="0">
|
||||
<ul class="subsubsub sp-table-bar">
|
||||
@@ -53,7 +62,7 @@ class SP_Meta_Box_Table_Data {
|
||||
<table class="widefat sp-data-table sp-league-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="radio"><span class="dashicons sp-icon-shield sp-tip" title="<?php _e( 'Highlight', 'sportspress' ); ?>"></span></th>
|
||||
<th class="radio"><span class="dashicons <?php echo $icon_class; ?> sp-tip" title="<?php _e( 'Highlight', 'sportspress' ); ?>"></span></th>
|
||||
<th><?php _e( 'Team', 'sportspress' ); ?></th>
|
||||
<?php foreach ( $columns as $key => $label ): ?>
|
||||
<th><label for="sp_columns_<?php echo $key; ?>">
|
||||
|
||||
@@ -23,6 +23,7 @@ class SP_Meta_Box_Table_Details {
|
||||
$taxonomies = get_object_taxonomies( 'sp_table' );
|
||||
$caption = get_post_meta( $post->ID, 'sp_caption', true );
|
||||
$select = get_post_meta( $post->ID, 'sp_select', true );
|
||||
$post_type = sp_get_post_mode_type( $post->ID );
|
||||
if ( ! $select ) {
|
||||
global $pagenow;
|
||||
$select = ( 'post-new.php' ? 'auto' : 'manual' );
|
||||
@@ -38,7 +39,7 @@ class SP_Meta_Box_Table_Details {
|
||||
}
|
||||
?>
|
||||
<p><strong>
|
||||
<?php _e( 'Teams', 'sportspress' ); ?>
|
||||
<?php echo sp_get_post_mode_label( $post->ID ); ?>
|
||||
</strong></p>
|
||||
<p class="sp-select-setting">
|
||||
<select name="sp_select">
|
||||
@@ -48,8 +49,8 @@ class SP_Meta_Box_Table_Details {
|
||||
</p>
|
||||
<?php
|
||||
if ( 'manual' == $select ) {
|
||||
sp_post_checklist( $post->ID, 'sp_team', ( 'auto' == $select ? 'none' : 'block' ), array( 'sp_league', 'sp_season' ) );
|
||||
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
|
||||
sp_post_checklist( $post->ID, $post_type, ( 'auto' == $select ? 'none' : 'block' ), array( 'sp_league', 'sp_season' ), null, 'sp_team' );
|
||||
sp_post_adder( $post_type, __( 'Add New', 'sportspress' ) );
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
* League Table Mode
|
||||
*
|
||||
* @author ThemeBoy
|
||||
* @category Admin
|
||||
* @package SportsPress/Admin/Meta_Boxes
|
||||
* @version 2.2.11
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
||||
|
||||
/**
|
||||
* SP_Meta_Box_Table_Mode
|
||||
*/
|
||||
class SP_Meta_Box_Table_Mode {
|
||||
|
||||
/**
|
||||
* Output the metabox
|
||||
*/
|
||||
public static function output( $post ) {
|
||||
$the_mode = sp_get_post_mode( $post->ID );
|
||||
?>
|
||||
<div id="post-formats-select">
|
||||
<?php foreach ( array( 'team' => __( 'Team vs team', 'sportspress' ), 'player' => __( 'Player vs player', 'sportspress' ) ) as $key => $mode ): ?>
|
||||
<input type="radio" name="sp_mode" class="post-format" id="post-format-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( $the_mode, $key ); ?>> <label for="post-format-<?php echo $key; ?>" class="post-format-icon post-format-<?php echo $key; ?>"><?php echo $mode; ?></label><br>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Save meta box data
|
||||
*/
|
||||
public static function save( $post_id, $post ) {
|
||||
update_post_meta( $post_id, 'sp_mode', sp_array_value( $_POST, 'sp_mode', 'team' ) );
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ class SP_Settings_Events extends SP_Settings_Page {
|
||||
|
||||
add_filter( 'sportspress_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
|
||||
add_action( 'sportspress_settings_' . $this->id, array( $this, 'output' ) );
|
||||
add_action( 'sportspress_admin_field_current_mode', array( $this, 'current_mode_setting' ) );
|
||||
add_action( 'sportspress_admin_field_delimiter', array( $this, 'delimiter_setting' ) );
|
||||
add_action( 'sportspress_admin_field_event_layout', array( $this, 'layout_setting' ) );
|
||||
add_action( 'sportspress_admin_field_event_tabs', array( $this, 'tabs_setting' ) );
|
||||
@@ -98,18 +97,16 @@ class SP_Settings_Events extends SP_Settings_Page {
|
||||
|
||||
array(
|
||||
array(
|
||||
'title' => __( 'Mode', 'sportspress' ),
|
||||
'id' => 'sportspress_load_individual_mode_module',
|
||||
'default' => 'no',
|
||||
'title' => __( 'Default mode', 'sportspress' ),
|
||||
'id' => 'sportspress_mode',
|
||||
'default' => 'team',
|
||||
'type' => 'radio',
|
||||
'options' => array(
|
||||
'no' => __( 'Team vs team', 'sportspress' ),
|
||||
'yes' => __( 'Player vs player', 'sportspress' ),
|
||||
'team' => __( 'Team vs team', 'sportspress' ),
|
||||
'player' => __( 'Player vs player', 'sportspress' ),
|
||||
),
|
||||
'desc_tip' => _x( 'Who competes in events?', 'mode setting description', 'sportspress' ),
|
||||
),
|
||||
|
||||
array( 'type' => 'current_mode' ),
|
||||
|
||||
array(
|
||||
'title' => __( 'Limit', 'sportspress' ),
|
||||
@@ -476,21 +473,6 @@ class SP_Settings_Events extends SP_Settings_Page {
|
||||
</tr>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Output script to refresh page when mode is changed.
|
||||
*/
|
||||
function current_mode_setting() {
|
||||
?>
|
||||
<input type="hidden" name="sportspress_individual_mode_module_loaded" value="<?php echo get_option( 'sportspress_load_individual_mode_module', 'no' ); ?>">
|
||||
<?php if ( sp_array_value( $_POST, 'sportspress_load_individual_mode_module', 'no' ) !== sp_array_value( $_POST, 'sportspress_individual_mode_module_loaded', 'no' ) ) { ?>
|
||||
<script type="text/javascript">
|
||||
window.onload = function() {
|
||||
window.location = window.location.href;
|
||||
}
|
||||
</script>
|
||||
<?php }
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
Reference in New Issue
Block a user