Add offense and defense option to player performance
This commit is contained in:
@@ -166,6 +166,7 @@ class SP_Admin_Sports {
|
|||||||
}
|
}
|
||||||
update_post_meta( $id, 'sp_icon', sp_array_value( $performance, 'icon', null ) );
|
update_post_meta( $id, 'sp_icon', sp_array_value( $performance, 'icon', null ) );
|
||||||
update_post_meta( $id, 'sp_color', sp_array_value( $performance, 'color', null ) );
|
update_post_meta( $id, 'sp_color', sp_array_value( $performance, 'color', null ) );
|
||||||
|
update_post_meta( $id, 'sp_section', sp_array_value( $performance, 'section', -1 ) );
|
||||||
$i ++;
|
$i ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,19 +62,58 @@ class SP_Meta_Box_Event_Teams {
|
|||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</p>
|
</p>
|
||||||
<?php $tabs = apply_filters( 'sportspress_event_team_tabs', array( 'sp_player', 'sp_staff' ) ); ?>
|
<?php
|
||||||
|
$tabs = array();
|
||||||
|
$sections = get_option( 'sportspress_event_performance_sections', -1 );
|
||||||
|
if ( 0 == $sections ) {
|
||||||
|
$tabs['sp_offense'] = array(
|
||||||
|
'label' => __( 'Offense', 'sportspress' ),
|
||||||
|
'post_type' => 'sp_player',
|
||||||
|
);
|
||||||
|
$tabs['sp_defense'] = array(
|
||||||
|
'label' => __( 'Defense', 'sportspress' ),
|
||||||
|
'post_type' => 'sp_player',
|
||||||
|
);
|
||||||
|
} elseif ( 1 == $sections ) {
|
||||||
|
$tabs['sp_defense'] = array(
|
||||||
|
'label' => __( 'Defense', 'sportspress' ),
|
||||||
|
'post_type' => 'sp_player',
|
||||||
|
);
|
||||||
|
$tabs['sp_offense'] = array(
|
||||||
|
'label' => __( 'Offense', 'sportspress' ),
|
||||||
|
'post_type' => 'sp_player',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
$tabs['sp_player'] = array(
|
||||||
|
'label' => __( 'Players', 'sportspress' ),
|
||||||
|
'post_type' => 'sp_player',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$tabs['sp_staff'] = array(
|
||||||
|
'label' => __( 'Staff', 'sportspress' ),
|
||||||
|
'post_type' => 'sp_staff',
|
||||||
|
);
|
||||||
|
?>
|
||||||
<?php if ( $tabs ) { ?>
|
<?php if ( $tabs ) { ?>
|
||||||
<ul id="sp_team-tabs" class="wp-tab-bar sp-tab-bar">
|
<ul id="sp_team-tabs" class="wp-tab-bar sp-tab-bar">
|
||||||
<?php foreach ( $tabs as $index => $post_type ) { $object = get_post_type_object( $post_type ); ?>
|
<?php
|
||||||
<li class="wp-tab<?php if ( 0 == $index ) { ?>-active<?php } ?>"><a href="#<?php echo $post_type; ?>-all"><?php echo $object->labels->name; ?></a></li>
|
$j = 0;
|
||||||
<?php } ?>
|
foreach ( $tabs as $slug => $tab ) {
|
||||||
|
?>
|
||||||
|
<li class="wp-tab<?php if ( 0 == $j ) { ?>-active<?php } ?>"><a href="#<?php echo $slug; ?>-all"><?php echo $tab['label']; ?></a></li>
|
||||||
|
<?php
|
||||||
|
$j++;
|
||||||
|
}
|
||||||
|
?>
|
||||||
</ul>
|
</ul>
|
||||||
<?php
|
<?php
|
||||||
foreach ( $tabs as $index => $post_type ) {
|
$j = 0;
|
||||||
do_action( 'sportspress_event_teams_meta_box_checklist', $post->ID, $post_type, ( 0 == $index ? 'block' : 'none' ), $team, $i );
|
foreach ( $tabs as $slug => $tab ) {
|
||||||
|
do_action( 'sportspress_event_teams_meta_box_checklist', $post->ID, $tab['post_type'], ( 0 == $j ? 'block' : 'none' ), $team, $i, $slug );
|
||||||
if ( apply_filters( 'sportspress_event_teams_meta_box_default_checklist', true ) ) {
|
if ( apply_filters( 'sportspress_event_teams_meta_box_default_checklist', true ) ) {
|
||||||
sp_post_checklist( $post->ID, $post_type, ( 0 == $index ? 'block' : 'none' ), array( 'sp_league', 'sp_season', 'sp_current_team' ), $i );
|
sp_post_checklist( $post->ID, $tab['post_type'], ( 0 == $j ? 'block' : 'none' ), array( 'sp_league', 'sp_season', 'sp_current_team' ), $i, $slug );
|
||||||
}
|
}
|
||||||
|
$j++;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
@@ -107,11 +146,16 @@ class SP_Meta_Box_Event_Teams {
|
|||||||
*/
|
*/
|
||||||
public static function save( $post_id, $post ) {
|
public static function save( $post_id, $post ) {
|
||||||
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
|
||||||
$tabs = apply_filters( 'sportspress_event_team_tabs', array( 'sp_player', 'sp_staff' ) );
|
$tabs = array();
|
||||||
if ( $tabs ) {
|
$sections = get_option( 'sportspress_event_performance_sections', -1 );
|
||||||
foreach ( $tabs as $post_type ) {
|
if ( -1 == $sections ) {
|
||||||
sp_update_post_meta_recursive( $post_id, $post_type, sp_array_value( $_POST, $post_type, array() ) );
|
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() ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,12 +29,51 @@ class SP_Meta_Box_Performance_Details extends SP_Meta_Box_Config {
|
|||||||
} else {
|
} else {
|
||||||
$readonly = false;
|
$readonly = false;
|
||||||
}
|
}
|
||||||
|
$section = get_post_meta( $post->ID, 'sp_section', true );
|
||||||
|
if ( '' === $section ) {
|
||||||
|
$section = -1;
|
||||||
|
}
|
||||||
|
$format = get_post_meta( $post->ID, 'sp_format', true );
|
||||||
|
if ( '' === $format ) {
|
||||||
|
$format = 'number';
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
|
<p><strong><?php _e( 'Variable', 'sportspress' ); ?></strong></p>
|
||||||
<p>
|
<p>
|
||||||
<input name="sp_default_key" type="hidden" id="sp_default_key" value="<?php echo $post->post_name; ?>">
|
<input name="sp_default_key" type="hidden" id="sp_default_key" value="<?php echo $post->post_name; ?>">
|
||||||
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>"<?php if ( $readonly ) { ?> readonly="readonly"<?php } ?>>
|
<input name="sp_key" type="text" id="sp_key" value="<?php echo $post->post_name; ?>"<?php if ( $readonly ) { ?> readonly="readonly"<?php } ?>>
|
||||||
</p>
|
</p>
|
||||||
|
<p><strong><?php _e( 'Category', 'sportspress' ); ?></strong></p>
|
||||||
|
<p class="sp-section-selector">
|
||||||
|
<select name="sp_section">
|
||||||
|
<?php
|
||||||
|
$options = apply_filters( 'sportspress_performance_sections', array( -1 => __( 'All', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
|
||||||
|
foreach ( $options as $key => $value ):
|
||||||
|
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $section ), $value );
|
||||||
|
endforeach;
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
<p><strong><?php _e( 'Format', 'sportspress' ); ?></strong></p>
|
||||||
|
<p class="sp-format-selector">
|
||||||
|
<select name="sp_format">
|
||||||
|
<?php
|
||||||
|
$options = apply_filters( 'sportspress_performance_formats', array( 'number' => __( 'Number', 'sportspress' ), 'text' => __( 'Text', 'sportspress' ) ) );
|
||||||
|
foreach ( $options as $key => $value ):
|
||||||
|
printf( '<option value="%s" %s>%s</option>', $key, selected( $key == $format ), $value );
|
||||||
|
endforeach;
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save meta box data
|
||||||
|
*/
|
||||||
|
public static function save( $post_id, $post ) {
|
||||||
|
self::delete_duplicate( $_POST );
|
||||||
|
update_post_meta( $post_id, 'sp_section', (int) sp_array_value( $_POST, 'sp_section', -1 ) );
|
||||||
|
update_post_meta( $post_id, 'sp_format', sp_array_value( $_POST, 'sp_format', 'number' ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -371,19 +371,15 @@ class SP_Settings_Events extends SP_Settings_Page {
|
|||||||
),
|
),
|
||||||
|
|
||||||
array(
|
array(
|
||||||
'desc' => __( 'Split players by team', 'sportspress' ),
|
'title' => __( 'Performance', 'sportspress' ),
|
||||||
'id' => 'sportspress_event_split_players_by_team',
|
'id' => 'sportspress_event_performance_sections',
|
||||||
'default' => 'yes',
|
'default' => -1,
|
||||||
'type' => 'checkbox',
|
'type' => 'radio',
|
||||||
'checkboxgroup' => '',
|
'options' => array(
|
||||||
),
|
-1 => __( 'Combined', 'sportspress' ),
|
||||||
|
0 => __( 'Offense', 'sportspress' ) . ' → ' . __( 'Defense', 'sportspress' ),
|
||||||
array(
|
1 => __( 'Defense', 'sportspress' ) . ' → ' . __( 'Offense', 'sportspress' ),
|
||||||
'desc' => __( 'Split players by position', 'sportspress' ),
|
),
|
||||||
'id' => 'sportspress_event_split_players_by_position',
|
|
||||||
'default' => 'no',
|
|
||||||
'type' => 'checkbox',
|
|
||||||
'checkboxgroup' => 'end',
|
|
||||||
),
|
),
|
||||||
|
|
||||||
array(
|
array(
|
||||||
|
|||||||
@@ -449,6 +449,41 @@ if ( !function_exists( 'sp_get_post_order' ) ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( !function_exists( 'sp_get_post_section' ) ) {
|
||||||
|
function sp_get_post_section( $post_id ) {
|
||||||
|
$section = get_post_meta ( $post_id, 'sp_section', true );
|
||||||
|
if ( isset( $section ) ):
|
||||||
|
$options = apply_filters( 'sportspress_performance_sections', array( -1 => __( 'All', 'sportspress' ), 0 => __( 'Offense', 'sportspress' ), 1 => __( 'Defense', 'sportspress' ) ) );
|
||||||
|
return sp_array_value( $options, $section, __( 'All', 'sportspress' ) );
|
||||||
|
else:
|
||||||
|
return __( 'All', 'sportspress' );
|
||||||
|
endif;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !function_exists( 'sp_get_post_format' ) ) {
|
||||||
|
function sp_get_post_format( $post_id ) {
|
||||||
|
$format = get_post_meta ( $post_id, 'sp_format', true );
|
||||||
|
if ( isset( $format ) ):
|
||||||
|
$options = apply_filters( 'sportspress_performance_formats', array( 'number' => __( 'Number', 'sportspress' ), 'time' => __( 'Time', 'sportspress' ), 'text' => __( 'Text', 'sportspress' ) ) );
|
||||||
|
return sp_array_value( $options, $format, __( 'Number', 'sportspress' ) );
|
||||||
|
else:
|
||||||
|
return __( 'Number', 'sportspress' );
|
||||||
|
endif;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !function_exists( 'sp_get_format_placeholder' ) ) {
|
||||||
|
function sp_get_format_placeholder( $key = 'number' ) {
|
||||||
|
$placeholders = apply_filters( 'sportspress_format_placeholders', array(
|
||||||
|
'number' => 0,
|
||||||
|
'time' => '0:00',
|
||||||
|
'text' => '',
|
||||||
|
) );
|
||||||
|
return sp_array_value( $placeholders, $key, 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ( !function_exists( 'sp_dropdown_statuses' ) ) {
|
if ( !function_exists( 'sp_dropdown_statuses' ) ) {
|
||||||
function sp_dropdown_statuses( $args = array() ) {
|
function sp_dropdown_statuses( $args = array() ) {
|
||||||
$defaults = array(
|
$defaults = array(
|
||||||
@@ -786,12 +821,14 @@ if ( !function_exists( 'sp_posts' ) ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( !function_exists( 'sp_post_checklist' ) ) {
|
if ( !function_exists( 'sp_post_checklist' ) ) {
|
||||||
function sp_post_checklist( $post_id = null, $meta = 'post', $display = 'block', $filters = null, $index = null ) {
|
function sp_post_checklist( $post_id = null, $meta = 'post', $display = 'block', $filters = null, $index = null, $slug = null ) {
|
||||||
if ( ! isset( $post_id ) )
|
if ( ! isset( $post_id ) )
|
||||||
global $post_id;
|
global $post_id;
|
||||||
|
if ( ! isset( $slug ) )
|
||||||
|
$slug = $meta;
|
||||||
?>
|
?>
|
||||||
<div id="<?php echo $meta; ?>-all" class="posttypediv wp-tab-panel sp-tab-panel sp-tab-filter-panel sp-select-all-range" style="display: <?php echo $display; ?>;">
|
<div id="<?php echo $slug; ?>-all" class="posttypediv wp-tab-panel sp-tab-panel sp-tab-filter-panel sp-select-all-range" style="display: <?php echo $display; ?>;">
|
||||||
<input type="hidden" value="0" name="<?php echo $meta; ?><?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]" />
|
<input type="hidden" value="0" name="<?php echo $slug; ?><?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]" />
|
||||||
<ul class="categorychecklist form-no-clear">
|
<ul class="categorychecklist form-no-clear">
|
||||||
<li class="sp-select-all-container"><label class="selectit"><input type="checkbox" class="sp-select-all"> <strong><?php _e( 'Select All', 'sportspress' ); ?></strong></label></li>
|
<li class="sp-select-all-container"><label class="selectit"><input type="checkbox" class="sp-select-all"> <strong><?php _e( 'Select All', 'sportspress' ); ?></strong></label></li>
|
||||||
<?php
|
<?php
|
||||||
@@ -844,7 +881,7 @@ if ( !function_exists( 'sp_post_checklist' ) ) {
|
|||||||
?>">
|
?>">
|
||||||
<?php echo str_repeat( '<ul><li>', sizeof( $parents ) ); ?>
|
<?php echo str_repeat( '<ul><li>', sizeof( $parents ) ); ?>
|
||||||
<label class="selectit">
|
<label class="selectit">
|
||||||
<input type="checkbox" value="<?php echo $post->ID; ?>" name="<?php echo $meta; ?><?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]"<?php if ( in_array( $post->ID, $selected ) ) echo ' checked="checked"'; ?>>
|
<input type="checkbox" value="<?php echo $post->ID; ?>" name="<?php echo $slug; ?><?php if ( isset( $index ) ) echo '[' . $index . ']'; ?>[]"<?php if ( in_array( $post->ID, $selected ) ) echo ' checked="checked"'; ?>>
|
||||||
<?php echo sp_get_player_name_with_number( $post->ID ); ?>
|
<?php echo sp_get_player_name_with_number( $post->ID ); ?>
|
||||||
</label>
|
</label>
|
||||||
<?php echo str_repeat( '</li></ul>', sizeof( $parents ) ); ?>
|
<?php echo str_repeat( '</li></ul>', sizeof( $parents ) ); ?>
|
||||||
@@ -854,10 +891,10 @@ if ( !function_exists( 'sp_post_checklist' ) ) {
|
|||||||
?>
|
?>
|
||||||
<li class="sp-not-found-container">
|
<li class="sp-not-found-container">
|
||||||
<?php _e( 'No results found.', 'sportspress' ); ?>
|
<?php _e( 'No results found.', 'sportspress' ); ?>
|
||||||
<?php if ( sizeof( $posts ) ): ?><a class="sp-show-all" href="#show-all-<?php echo $meta; ?>s"><?php _e( 'Show all', 'sportspress' ); ?></a><?php endif; ?>
|
<?php if ( sizeof( $posts ) ): ?><a class="sp-show-all" href="#show-all-<?php echo $slug; ?>s"><?php _e( 'Show all', 'sportspress' ); ?></a><?php endif; ?>
|
||||||
</li>
|
</li>
|
||||||
<?php if ( sizeof( $posts ) ): ?>
|
<?php if ( sizeof( $posts ) ): ?>
|
||||||
<li class="sp-show-all-container"><a class="sp-show-all" href="#show-all-<?php echo $meta; ?>s"><?php _e( 'Show all', 'sportspress' ); ?></a></li>
|
<li class="sp-show-all-container"><a class="sp-show-all" href="#show-all-<?php echo $slug; ?>s"><?php _e( 'Show all', 'sportspress' ); ?></a></li>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
@@ -882,6 +919,10 @@ if ( !function_exists( 'sp_column_checklist' ) ) {
|
|||||||
endif;
|
endif;
|
||||||
if ( sizeof( $posts ) ):
|
if ( sizeof( $posts ) ):
|
||||||
foreach ( $posts as $post ):
|
foreach ( $posts as $post ):
|
||||||
|
if ( 'sp_performance' == $meta ) {
|
||||||
|
$format = get_post_meta( $post->ID, 'sp_format', true );
|
||||||
|
if ( 'text' === $format ) continue;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<li class="sp-post">
|
<li class="sp-post">
|
||||||
<label class="selectit">
|
<label class="selectit">
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Plugin URI: http://themeboy.com/
|
|||||||
Description: Add player lists to SportsPress.
|
Description: Add player lists to SportsPress.
|
||||||
Author: ThemeBoy
|
Author: ThemeBoy
|
||||||
Author URI: http://themeboy.com/
|
Author URI: http://themeboy.com/
|
||||||
Version: 1.9
|
Version: 1.9.17
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Exit if accessed directly
|
// Exit if accessed directly
|
||||||
@@ -94,6 +94,7 @@ class SportsPress_Player_Lists {
|
|||||||
* Remove meta boxes.
|
* Remove meta boxes.
|
||||||
*/
|
*/
|
||||||
public function remove_meta_boxes() {
|
public function remove_meta_boxes() {
|
||||||
|
remove_meta_box( 'sp_positiondiv', 'sp_list', 'side' );
|
||||||
remove_meta_box( 'sp_seasondiv', 'sp_list', 'side' );
|
remove_meta_box( 'sp_seasondiv', 'sp_list', 'side' );
|
||||||
remove_meta_box( 'sp_leaguediv', 'sp_list', 'side' );
|
remove_meta_box( 'sp_leaguediv', 'sp_list', 'side' );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|||||||
$totals = array();
|
$totals = array();
|
||||||
|
|
||||||
// Set null
|
// Set null
|
||||||
if ( ! isset( $position ) ) $position = null;
|
if ( ! isset( $section ) ) $section = null;
|
||||||
if ( ! isset( $class ) ) $class = null;
|
if ( ! isset( $class ) ) $class = null;
|
||||||
|
|
||||||
// Initialize arrays
|
// Initialize arrays
|
||||||
@@ -33,15 +33,14 @@ if ( ! isset( $subs ) ) $subs = array();
|
|||||||
<th class="data-number">#</th>
|
<th class="data-number">#</th>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<th class="data-name">
|
<th class="data-name">
|
||||||
<?php if ( isset( $position ) ) { ?>
|
<?php if ( isset( $section ) ) { ?>
|
||||||
<?php echo $position; ?>
|
<?php echo $section; ?>
|
||||||
<?php } else { ?>
|
<?php } else { ?>
|
||||||
<?php _e( 'Player', 'sportspress' ); ?>
|
<?php _e( 'Player', 'sportspress' ); ?>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</th>
|
</th>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php if ( $mode == 'values' ): foreach ( $labels as $key => $label ): ?>
|
<?php if ( $mode == 'values' ): foreach ( $labels as $key => $label ): ?>
|
||||||
<?php if ( isset( $position ) && 'position' == $key ) continue; ?>
|
|
||||||
<th class="data-<?php echo $key; ?>"><?php echo $label; ?></th>
|
<th class="data-<?php echo $key; ?>"><?php echo $label; ?></th>
|
||||||
<?php endforeach; else: ?>
|
<?php endforeach; else: ?>
|
||||||
<th class="sp-performance-icons"> </th>
|
<th class="sp-performance-icons"> </th>
|
||||||
@@ -102,8 +101,9 @@ if ( ! isset( $subs ) ) $subs = array();
|
|||||||
foreach ( $labels as $key => $label ):
|
foreach ( $labels as $key => $label ):
|
||||||
if ( 'name' == $key )
|
if ( 'name' == $key )
|
||||||
continue;
|
continue;
|
||||||
if ( isset( $position ) && 'position' == $key )
|
|
||||||
continue;
|
$format = sp_array_value( $formats, $key, 'number' );
|
||||||
|
$placeholder = sp_get_format_placeholder( $format );
|
||||||
|
|
||||||
$value = '—';
|
$value = '—';
|
||||||
if ( $key == 'position' ):
|
if ( $key == 'position' ):
|
||||||
@@ -119,6 +119,8 @@ if ( ! isset( $subs ) ) $subs = array();
|
|||||||
if ( $player_position ) $positions[] = $player_position->name;
|
if ( $player_position ) $positions[] = $player_position->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$positions = array_unique( $positions );
|
||||||
|
|
||||||
if ( sizeof( $positions ) ):
|
if ( sizeof( $positions ) ):
|
||||||
$value = implode( ', ', $positions );
|
$value = implode( ', ', $positions );
|
||||||
endif;
|
endif;
|
||||||
@@ -126,13 +128,16 @@ if ( ! isset( $subs ) ) $subs = array();
|
|||||||
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
|
if ( array_key_exists( $key, $row ) && $row[ $key ] != '' ):
|
||||||
$value = $row[ $key ];
|
$value = $row[ $key ];
|
||||||
else:
|
else:
|
||||||
$value = 0;
|
$value = $placeholder;
|
||||||
endif;
|
endif;
|
||||||
endif;
|
endif;
|
||||||
if ( ! array_key_exists( $key, $totals ) ):
|
if ( ! array_key_exists( $key, $totals ) ):
|
||||||
$totals[ $key ] = 0;
|
$totals[ $key ] = $placeholder;
|
||||||
endif;
|
endif;
|
||||||
$totals[ $key ] += $value;
|
|
||||||
|
if ( 'text' !== $format ) {
|
||||||
|
$totals[ $key ] += $value;
|
||||||
|
}
|
||||||
|
|
||||||
if ( $mode == 'values' ):
|
if ( $mode == 'values' ):
|
||||||
echo '<td class="data-' . $key . '">' . $value . '</td>';
|
echo '<td class="data-' . $key . '">' . $value . '</td>';
|
||||||
@@ -159,7 +164,7 @@ if ( ! isset( $subs ) ) $subs = array();
|
|||||||
<?php if ( apply_filters( 'sportspress_event_performance_show_footer', $show_total ) ): ?>
|
<?php if ( apply_filters( 'sportspress_event_performance_show_footer', $show_total ) ): ?>
|
||||||
<<?php echo ( $show_players ? 'tfoot' : 'tbody' ); ?>>
|
<<?php echo ( $show_players ? 'tfoot' : 'tbody' ); ?>>
|
||||||
<?php
|
<?php
|
||||||
do_action( 'sportspress_event_performance_table_footer', $data, $labels, $position, $performance_ids );
|
do_action( 'sportspress_event_performance_table_footer', $data, $labels, $section, $performance_ids );
|
||||||
if ( $show_total && ( ! $primary || sizeof( array_intersect_key( $totals, array_flip( (array) $primary ) ) ) ) ) {
|
if ( $show_total && ( ! $primary || sizeof( array_intersect_key( $totals, array_flip( (array) $primary ) ) ) ) ) {
|
||||||
?>
|
?>
|
||||||
<tr class="sp-total-row <?php echo ( $i % 2 == 0 ? 'odd' : 'even' ); ?>">
|
<tr class="sp-total-row <?php echo ( $i % 2 == 0 ? 'odd' : 'even' ); ?>">
|
||||||
@@ -178,8 +183,6 @@ if ( ! isset( $subs ) ) $subs = array();
|
|||||||
foreach ( $labels as $key => $label ):
|
foreach ( $labels as $key => $label ):
|
||||||
if ( 'name' == $key )
|
if ( 'name' == $key )
|
||||||
continue;
|
continue;
|
||||||
if ( isset( $position ) && 'position' == $key )
|
|
||||||
continue;
|
|
||||||
if ( $key == 'position' ):
|
if ( $key == 'position' ):
|
||||||
$value = ' ';
|
$value = ' ';
|
||||||
else:
|
else:
|
||||||
@@ -212,6 +215,6 @@ if ( ! isset( $subs ) ) $subs = array();
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<?php do_action( 'sportspress_after_event_performance_table', $data, $lineups, $subs, $class ); ?>
|
<?php do_action( 'sportspress_after_event_performance_table', $data, $lineups, $subs, $class ); ?>
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ $show_players = get_option( 'sportspress_event_show_players', 'yes' ) === 'yes'
|
|||||||
$show_staff = get_option( 'sportspress_event_show_staff', 'yes' ) === 'yes' ? true : false;
|
$show_staff = get_option( 'sportspress_event_show_staff', 'yes' ) === 'yes' ? true : false;
|
||||||
$show_total = get_option( 'sportspress_event_show_total', 'yes' ) === 'yes' ? true : false;
|
$show_total = get_option( 'sportspress_event_show_total', 'yes' ) === 'yes' ? true : false;
|
||||||
$show_numbers = get_option( 'sportspress_event_show_player_numbers', 'yes' ) === 'yes' ? true : false;
|
$show_numbers = get_option( 'sportspress_event_show_player_numbers', 'yes' ) === 'yes' ? true : false;
|
||||||
$split_positions = get_option( 'sportspress_event_split_players_by_position', 'no' ) === 'yes' ? true : false;
|
$sections = get_option( 'sportspress_event_performance_sections', -1 );
|
||||||
$split_teams = get_option( 'sportspress_event_split_players_by_team', 'yes' ) === 'yes' ? true : false;
|
|
||||||
$reverse_teams = get_option( 'sportspress_event_performance_reverse_teams', 'no' ) === 'yes' ? true : false;
|
$reverse_teams = get_option( 'sportspress_event_performance_reverse_teams', 'no' ) === 'yes' ? true : false;
|
||||||
$primary = sp_get_main_performance_option();
|
$primary = sp_get_main_performance_option();
|
||||||
$total = get_option( 'sportspress_event_total_performance', 'all');
|
$total = get_option( 'sportspress_event_total_performance', 'all');
|
||||||
@@ -28,7 +27,7 @@ $teams = get_post_meta( $id, 'sp_team', false );
|
|||||||
|
|
||||||
if ( is_array( $teams ) ):
|
if ( is_array( $teams ) ):
|
||||||
?>
|
?>
|
||||||
<div class="sp-event-performance-tables sp-event-performance-<?php echo $split_positions ? 'positions' : 'teams'; ?>">
|
<div class="sp-event-performance-tables sp-event-performance-teams">
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$event = new SP_Event( $id );
|
$event = new SP_Event( $id );
|
||||||
@@ -62,194 +61,154 @@ if ( is_array( $teams ) ):
|
|||||||
$teams = array_reverse( $teams, true );
|
$teams = array_reverse( $teams, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $split_teams ) {
|
// Get performance columns
|
||||||
// Split tables
|
$args = array(
|
||||||
foreach( $teams as $index => $team_id ):
|
'post_type' => 'sp_performance',
|
||||||
if ( -1 == $team_id ) continue;
|
'numberposts' => 100,
|
||||||
|
'posts_per_page' => 100,
|
||||||
|
'orderby' => 'menu_order',
|
||||||
|
'order' => 'ASC',
|
||||||
|
);
|
||||||
|
|
||||||
// Get results for players in the team
|
$columns = get_posts( $args );
|
||||||
$players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $index );
|
|
||||||
$has_players = sizeof( $players ) > 1;
|
|
||||||
|
|
||||||
$players = apply_filters( 'sportspress_event_performance_split_team_players', $players );
|
// Get formats
|
||||||
|
$formats = array();
|
||||||
|
|
||||||
$show_team_players = $show_players && $has_players;
|
// Add to formats
|
||||||
|
foreach ( $columns as $column ) {
|
||||||
|
$format = get_post_meta( $column->ID, 'sp_format', true );
|
||||||
|
if ( '' === $format ) {
|
||||||
|
$format = 'number';
|
||||||
|
}
|
||||||
|
$formats[ $column->post_name ] = $format;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepare for offense and defense sections
|
||||||
|
if ( -1 != $sections ) {
|
||||||
|
|
||||||
|
// Determine order of sections
|
||||||
|
if ( 1 == $sections ) {
|
||||||
|
$section_order = array( __( 'Defense', 'sportspress' ), __( 'Offense', 'sportspress' ) );
|
||||||
|
} else {
|
||||||
|
$section_order = array( __( 'Offense', 'sportspress' ), __( 'Defense', 'sportspress' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize labels
|
||||||
|
$labels = array( array(), array() );
|
||||||
|
|
||||||
|
// Add positions if applicable
|
||||||
|
if ( 'yes' == get_option( 'sportspress_event_show_position', 'yes' ) ) {
|
||||||
|
$labels[0]['position'] = $labels[1]['position'] = __( 'Position', 'sportspress' );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get labels by section
|
||||||
|
foreach ( $columns as $column ):
|
||||||
|
$section = get_post_meta( $column->ID, 'sp_section', true );
|
||||||
|
if ( '' === $section ) {
|
||||||
|
$section = -1;
|
||||||
|
}
|
||||||
|
switch ( $section ):
|
||||||
|
case 1:
|
||||||
|
$labels[1][ $column->post_name ] = $column->post_title;
|
||||||
|
break;
|
||||||
|
case 0:
|
||||||
|
$labels[0][ $column->post_name ] = $column->post_title;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$labels[0][ $column->post_name ] = $column->post_title;
|
||||||
|
$labels[1][ $column->post_name ] = $column->post_title;
|
||||||
|
endswitch;
|
||||||
|
endforeach;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach( $teams as $index => $team_id ):
|
||||||
|
if ( -1 == $team_id ) continue;
|
||||||
|
|
||||||
|
// Get results for players in the team
|
||||||
|
$players = sp_array_between( (array)get_post_meta( $id, 'sp_player', false ), 0, $index );
|
||||||
|
$has_players = sizeof( $players ) > 1;
|
||||||
|
|
||||||
|
$players = apply_filters( 'sportspress_event_performance_split_team_players', $players );
|
||||||
|
|
||||||
|
$show_team_players = $show_players && $has_players;
|
||||||
|
|
||||||
|
if ( ! $show_team_players && ! $show_staff && ! $show_total ) continue;
|
||||||
|
|
||||||
|
if ( $show_team_players || $show_total ) {
|
||||||
|
if ( -1 != $sections ) {
|
||||||
|
|
||||||
if ( 0 < $team_id ) {
|
|
||||||
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
|
|
||||||
} elseif ( 0 == $team_id ) {
|
|
||||||
$data = array();
|
$data = array();
|
||||||
foreach ( $players as $player_id ) {
|
|
||||||
if ( isset( $performance[ $player_id ][ $player_id ] ) ) {
|
// Get results for offensive players in the team
|
||||||
$data[ $player_id ] = $performance[ $player_id ][ $player_id ];
|
$offense = sp_array_between( (array)get_post_meta( $id, 'sp_offense', false ), 0, $index );
|
||||||
|
$data[0] = sp_array_combine( $offense, sp_array_value( $performance, $team_id, array() ) );
|
||||||
|
|
||||||
|
// Get results for defensive players in the team
|
||||||
|
$defense = sp_array_between( (array)get_post_meta( $id, 'sp_defense', false ), 0, $index );
|
||||||
|
$data[1] = sp_array_combine( $defense, sp_array_value( $performance, $team_id, array() ) );
|
||||||
|
|
||||||
|
foreach ( $section_order as $section_id => $section_label ) {
|
||||||
|
if ( sizeof( $data[ $section_id ] ) ) {
|
||||||
|
sp_get_template( 'event-performance-table.php', array(
|
||||||
|
'section' => $section_label,
|
||||||
|
'scrollable' => $scrollable,
|
||||||
|
'sortable' => $sortable,
|
||||||
|
'show_players' => $show_team_players,
|
||||||
|
'show_numbers' => $show_numbers,
|
||||||
|
'show_total' => $show_total,
|
||||||
|
'caption' => 0 == $section_id && $team_id ? get_the_title( $team_id ) : null,
|
||||||
|
'labels' => $labels[ $section_id ],
|
||||||
|
'formats' => $formats,
|
||||||
|
'mode' => $mode,
|
||||||
|
'data' => $data[ $section_id ],
|
||||||
|
'event' => $event,
|
||||||
|
'link_posts' => $link_posts,
|
||||||
|
'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
|
||||||
|
'primary' => 'primary' == $total ? $primary : null,
|
||||||
|
'class' => 'sp-template-event-performance-team-' . $index . '-section-' . $section_id,
|
||||||
|
) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$data = sp_array_value( array_values( $performance ), $index );
|
if ( 0 < $team_id ) {
|
||||||
}
|
$data = sp_array_combine( $players, sp_array_value( $performance, $team_id, array() ) );
|
||||||
|
} elseif ( 0 == $team_id ) {
|
||||||
if ( ! $show_team_players && ! $show_staff && ! $show_total ) continue;
|
$data = array();
|
||||||
|
foreach ( $players as $player_id ) {
|
||||||
if ( $show_team_players || $show_total ) {
|
if ( isset( $performance[ $player_id ][ $player_id ] ) ) {
|
||||||
if ( $split_positions ) {
|
$data[ $player_id ] = $performance[ $player_id ][ $player_id ];
|
||||||
$positions = get_terms( 'sp_position', array(
|
|
||||||
'orderby' => 'slug',
|
|
||||||
'hide_empty' => 0,
|
|
||||||
) );
|
|
||||||
|
|
||||||
foreach ( $positions as $position_index => $position ) {
|
|
||||||
$subdata = array();
|
|
||||||
foreach ( $data as $player_id => $player ) {
|
|
||||||
$player_positions = (array) sp_array_value( $player, 'position' );
|
|
||||||
$player_positions = array_filter( $player_positions );
|
|
||||||
if ( empty( $player_positions ) ) {
|
|
||||||
$player_positions = (array) sp_get_the_term_id( $player_id, 'sp_position' );
|
|
||||||
}
|
|
||||||
if ( in_array( $position->term_id, $player_positions ) ) {
|
|
||||||
$subdata[ $player_id ] = $data[ $player_id ];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize Sublabels
|
|
||||||
$sublabels = $labels;
|
|
||||||
|
|
||||||
// Get performance with position
|
|
||||||
$performance_labels = get_posts( array(
|
|
||||||
'post_type' => 'sp_performance',
|
|
||||||
'posts_per_page' => -1,
|
|
||||||
'tax_query' => array(
|
|
||||||
array(
|
|
||||||
'taxonomy' => 'sp_position',
|
|
||||||
'terms' => $position->term_id,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
) );
|
|
||||||
|
|
||||||
$allowed_labels = array();
|
|
||||||
if ( ! empty( $performance_labels ) ) {
|
|
||||||
foreach ( $performance_labels as $label ) {
|
|
||||||
$allowed_labels[ $label->post_name ] = $label->post_title;
|
|
||||||
}
|
|
||||||
|
|
||||||
$allowed_labels = apply_filters( 'sportspress_event_performance_allowed_labels', $allowed_labels, $position_index );
|
|
||||||
|
|
||||||
$sublabels = array_intersect_key( $sublabels, $allowed_labels );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( sizeof( $subdata ) ) {
|
|
||||||
$subdata = apply_filters( 'sportspress_event_performance_split_team_split_position_subdata', $subdata, $data, $position_index );
|
|
||||||
|
|
||||||
sp_get_template( 'event-performance-table.php', array(
|
|
||||||
'position' => sp_get_position_caption( $position->term_id ),
|
|
||||||
'scrollable' => $scrollable,
|
|
||||||
'sortable' => $sortable,
|
|
||||||
'show_players' => $show_team_players,
|
|
||||||
'show_numbers' => $show_numbers,
|
|
||||||
'show_total' => $show_total,
|
|
||||||
'caption' => 0 == $position_index && $team_id ? get_the_title( $team_id ) : null,
|
|
||||||
'labels' => $sublabels,
|
|
||||||
'mode' => $mode,
|
|
||||||
'data' => $subdata,
|
|
||||||
'event' => $event,
|
|
||||||
'link_posts' => $link_posts,
|
|
||||||
'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
|
|
||||||
'primary' => 'primary' == $total ? $primary : null,
|
|
||||||
'class' => 'sp-template-event-performance-team-' . $index . '-position-' . $position_index,
|
|
||||||
) );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sp_get_template( 'event-performance-table.php', array(
|
$data = sp_array_value( array_values( $performance ), $index );
|
||||||
'scrollable' => $scrollable,
|
|
||||||
'sortable' => $sortable,
|
|
||||||
'show_players' => $show_team_players,
|
|
||||||
'show_numbers' => $show_numbers,
|
|
||||||
'show_total' => $show_total,
|
|
||||||
'caption' => $team_id ? get_the_title( $team_id ) : null,
|
|
||||||
'labels' => $labels,
|
|
||||||
'mode' => $mode,
|
|
||||||
'data' => $data,
|
|
||||||
'event' => $event,
|
|
||||||
'link_posts' => $link_posts,
|
|
||||||
'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
|
|
||||||
'primary' => 'primary' == $total ? $primary : null,
|
|
||||||
|
|
||||||
) );
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if ( $show_staff ):
|
sp_get_template( 'event-performance-table.php', array(
|
||||||
sp_get_template( 'event-staff.php', array( 'id' => $id, 'index' => $index ) );
|
'scrollable' => $scrollable,
|
||||||
endif;
|
'sortable' => $sortable,
|
||||||
?>
|
'show_players' => $show_team_players,
|
||||||
<?php
|
'show_numbers' => $show_numbers,
|
||||||
endforeach;
|
'show_total' => $show_total,
|
||||||
} else {
|
'caption' => $team_id ? get_the_title( $team_id ) : null,
|
||||||
// Combined table
|
'labels' => $labels,
|
||||||
$data = array();
|
'formats' => $formats,
|
||||||
foreach ( $performance as $players ) {
|
'mode' => $mode,
|
||||||
foreach ( $players as $player_id => $player ) {
|
'data' => $data,
|
||||||
if ( $player_id == 0 ) continue;
|
'event' => $event,
|
||||||
$data[ $player_id ] = $player;
|
'link_posts' => $link_posts,
|
||||||
|
'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
|
||||||
|
'primary' => 'primary' == $total ? $primary : null,
|
||||||
|
|
||||||
|
) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( $show_staff ):
|
||||||
if ( $split_positions ) {
|
sp_get_template( 'event-staff.php', array( 'id' => $id, 'index' => $index ) );
|
||||||
$positions = get_terms( 'sp_position', array(
|
endif;
|
||||||
'orderby' => 'slug',
|
?>
|
||||||
'hide_empty' => 0,
|
<?php
|
||||||
) );
|
endforeach;
|
||||||
|
|
||||||
foreach ( $positions as $position_index => $position ) {
|
|
||||||
$subdata = array();
|
|
||||||
foreach ( $data as $player_id => $player ) {
|
|
||||||
$player_positions = (array) sp_array_value( $player, 'position' );
|
|
||||||
$player_positions = array_filter( $player_positions );
|
|
||||||
if ( empty( $player_positions ) ) {
|
|
||||||
$player_positions = (array) sp_get_the_term_id( $player_id, 'sp_position' );
|
|
||||||
}
|
|
||||||
if ( in_array( $position->term_id, $player_positions ) ) {
|
|
||||||
$subdata[ $player_id ] = $data[ $player_id ];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$subdata = apply_filters( 'sportspress_event_performance_split_position_subdata', $subdata, $data, $position_index );
|
|
||||||
|
|
||||||
if ( sizeof( $subdata ) ) {
|
|
||||||
sp_get_template( 'event-performance-table-combined.php', array(
|
|
||||||
'scrollable' => $scrollable,
|
|
||||||
'sortable' => $sortable,
|
|
||||||
'show_players' => $show_players,
|
|
||||||
'show_numbers' => $show_numbers,
|
|
||||||
'show_total' => $show_total,
|
|
||||||
'caption' => sp_get_position_caption( $position->term_id ),
|
|
||||||
'labels' => $labels,
|
|
||||||
'mode' => $mode,
|
|
||||||
'data' => $subdata,
|
|
||||||
'event' => $event,
|
|
||||||
'link_posts' => $link_posts,
|
|
||||||
'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
|
|
||||||
'primary' => 'primary' == $total ? $primary : null,
|
|
||||||
) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sp_get_template( 'event-performance-table-combined.php', array(
|
|
||||||
'scrollable' => $scrollable,
|
|
||||||
'sortable' => $sortable,
|
|
||||||
'show_players' => $show_players,
|
|
||||||
'show_numbers' => $show_numbers,
|
|
||||||
'show_total' => $show_total,
|
|
||||||
'caption' => __( 'Scorecard', 'sportspress' ),
|
|
||||||
'labels' => $labels,
|
|
||||||
'mode' => $mode,
|
|
||||||
'data' => $data,
|
|
||||||
'event' => $event,
|
|
||||||
'link_posts' => $link_posts,
|
|
||||||
'performance_ids' => isset( $performance_ids ) ? $performance_ids : null,
|
|
||||||
'primary' => 'primary' == $total ? $primary : null,
|
|
||||||
) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
do_action( 'sportspress_event_performance' );
|
do_action( 'sportspress_event_performance' );
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user