Merge branch 'feature-player-assignments'
This commit is contained in:
@@ -47,6 +47,18 @@ class SP_Player_List extends SP_Secondary_Post {
|
|||||||
$crop = get_post_meta( $this->ID, 'sp_crop', true );
|
$crop = get_post_meta( $this->ID, 'sp_crop', true );
|
||||||
$order = get_post_meta( $this->ID, 'sp_order', true );
|
$order = get_post_meta( $this->ID, 'sp_order', true );
|
||||||
$select = get_post_meta( $this->ID, 'sp_select', true );
|
$select = get_post_meta( $this->ID, 'sp_select', true );
|
||||||
|
//Player Assignments
|
||||||
|
$enable_assignments = get_option( 'sportspress_load_player_assignments_module', 'yes' );
|
||||||
|
$assignments = array();
|
||||||
|
if ( $enable_assignments == 'yes' ) {
|
||||||
|
foreach ( $league_ids as $l_id ) {
|
||||||
|
foreach ( $season_ids as $s_id ) {
|
||||||
|
if ( $team != '0' ) {
|
||||||
|
$assignments[] = $l_id.'_'.$s_id.'_'.$team;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->date = $this->__get( 'date' );
|
$this->date = $this->__get( 'date' );
|
||||||
|
|
||||||
@@ -99,7 +111,17 @@ class SP_Player_List extends SP_Secondary_Post {
|
|||||||
'relation' => 'AND',
|
'relation' => 'AND',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
//Use the Player Assignments to filter players
|
||||||
|
if ( !empty( $assignments ) ) {
|
||||||
|
$args['meta_query'] = array(
|
||||||
|
array(
|
||||||
|
'key' => 'sp_player_assignments',
|
||||||
|
'value' => $assignments,
|
||||||
|
'compare' => 'IN'
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}else{
|
||||||
|
//Use the legacy way to filter players
|
||||||
if ( $league_ids ):
|
if ( $league_ids ):
|
||||||
$args['tax_query'][] = array(
|
$args['tax_query'][] = array(
|
||||||
'taxonomy' => 'sp_league',
|
'taxonomy' => 'sp_league',
|
||||||
@@ -115,15 +137,7 @@ class SP_Player_List extends SP_Secondary_Post {
|
|||||||
'terms' => $season_ids
|
'terms' => $season_ids
|
||||||
);
|
);
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
if ( $position_ids ):
|
|
||||||
$args['tax_query'][] = array(
|
|
||||||
'taxonomy' => 'sp_position',
|
|
||||||
'field' => 'term_id',
|
|
||||||
'terms' => $position_ids
|
|
||||||
);
|
|
||||||
endif;
|
|
||||||
|
|
||||||
if ( $team ):
|
if ( $team ):
|
||||||
$team_key = 'sp_team';
|
$team_key = 'sp_team';
|
||||||
switch ( $era ):
|
switch ( $era ):
|
||||||
@@ -141,6 +155,16 @@ class SP_Player_List extends SP_Secondary_Post {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $position_ids ):
|
||||||
|
$args['tax_query'][] = array(
|
||||||
|
'taxonomy' => 'sp_position',
|
||||||
|
'field' => 'term_id',
|
||||||
|
'terms' => $position_ids
|
||||||
|
);
|
||||||
|
endif;
|
||||||
|
|
||||||
$players = get_posts( $args );
|
$players = get_posts( $args );
|
||||||
|
|
||||||
|
|||||||
102
modules/sportspress-player-assignments.php
Normal file
102
modules/sportspress-player-assignments.php
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
Plugin Name: SportsPress Player Assignments
|
||||||
|
Plugin URI: http://themeboy.com/
|
||||||
|
Description: Add player assignments support to SportsPress.
|
||||||
|
Author: Savvas
|
||||||
|
Author URI: http://themeboy.com/
|
||||||
|
Version: 2.6.0
|
||||||
|
*/
|
||||||
|
// Exit if accessed directly
|
||||||
|
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||||
|
if ( ! class_exists( 'SportsPress_Player_Assignments' ) ) :
|
||||||
|
/**
|
||||||
|
* Main SportsPress Player Assignments Class
|
||||||
|
*
|
||||||
|
* @class SportsPress_Player_Assignments
|
||||||
|
* @version 2.6.0
|
||||||
|
*/
|
||||||
|
class SportsPress_Player_Assignments {
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public function __construct() {
|
||||||
|
// Define constants
|
||||||
|
$this->define_constants();
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
add_action( 'sportspress_save_meta_player_statistics', array( $this, 'save_additional_statistics' ), 10, 2 );
|
||||||
|
|
||||||
|
// Filters
|
||||||
|
add_filter( 'sportspress_player_list_options', array( $this, 'add_settings' ) );
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Define constants.
|
||||||
|
*/
|
||||||
|
private function define_constants() {
|
||||||
|
if ( !defined( 'SP_PLAYER_ASSIGNMENTS_VERSION' ) )
|
||||||
|
define( 'SP_PLAYER_ASSIGNMENTS_VERSION', '2.6.0' );
|
||||||
|
if ( !defined( 'SP_PLAYER_ASSIGNMENTS_URL' ) )
|
||||||
|
define( 'SP_PLAYER_ASSIGNMENTS_URL', plugin_dir_url( __FILE__ ) );
|
||||||
|
if ( !defined( 'SP_PLAYER_ASSIGNMENTS_DIR' ) )
|
||||||
|
define( 'SP_PLAYER_ASSIGNMENTS_DIR', plugin_dir_path( __FILE__ ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save Additional Statistics
|
||||||
|
*/
|
||||||
|
public function save_additional_statistics( $post_id, $post_data ) {
|
||||||
|
$old = (array) get_post_custom_values( 'sp_player_assignments', $post_id );
|
||||||
|
|
||||||
|
$leagues = $post_data['sp_leagues'];
|
||||||
|
$transfers = get_post_meta($post_id, 'sp_player_assignments', true);
|
||||||
|
|
||||||
|
foreach ( $leagues as $l_id => $season ) {
|
||||||
|
foreach ( $season as $s_id => $team_id ) {
|
||||||
|
if ( $team_id != '-1' ) {
|
||||||
|
$serialized = $l_id.'_'.$s_id.'_'.$team_id;
|
||||||
|
if( !in_array( $serialized, $old ) ){
|
||||||
|
add_post_meta( $post_id, 'sp_player_assignments', $serialized, false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Check if there are any Mid-Season transfers
|
||||||
|
if ( isset( $transfers[$l_id][$s_id] ) ){
|
||||||
|
foreach ( $transfers[$l_id][$s_id] as $t_id => $performance ) {
|
||||||
|
$serialized = $l_id.'_'.$s_id.'_'.$t_id;
|
||||||
|
if( !in_array( $serialized, $old ) ){
|
||||||
|
add_post_meta( $post_id, 'sp_player_assignments', $serialized, false );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add settings.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function add_settings( $settings ) {
|
||||||
|
|
||||||
|
$settings = array_merge( $settings,
|
||||||
|
array(
|
||||||
|
array(
|
||||||
|
'title' => __( 'Filter by player assignment', 'sportspress' ),
|
||||||
|
'desc' => __( 'Use a stronger connection between leagues, seasons and teams', 'sportspress' ),
|
||||||
|
'id' => 'sportspress_list_player_assignments',
|
||||||
|
'default' => 'yes',
|
||||||
|
'type' => 'checkbox',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
array( 'type' => 'sectionend', 'id' => 'timelines_options' ),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return $settings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endif;
|
||||||
|
if ( get_option( 'sportspress_load_player_assignments_module', 'yes' ) == 'yes' ) { //Is it needed?
|
||||||
|
new SportsPress_Player_Assignments();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user