Move sports presets class

This commit is contained in:
Brian Miyaji
2014-05-01 16:31:21 +10:00
parent 8344fa2748
commit b2cc43c134
10 changed files with 253 additions and 11 deletions

View File

@@ -28,6 +28,7 @@ class SP_Admin_Settings {
if ( empty( self::$settings ) ) {
$settings = array();
include_once( 'class-sp-admin-sports.php' );
include_once( 'settings/class-sp-settings-page.php' );
$settings[] = include( 'settings/class-sp-settings-general.php' );

View File

@@ -0,0 +1,74 @@
<?php
/**
* SportsPress Admin Sports Class.
*
* The SportsPress admin sports class stores preset sport data.
*
* @class SP_Admin_Sports
* @version 0.8
* @package SportsPress/Admin
* @category Class
* @author ThemeBoy
*/
class SP_Admin_Sports {
private static $presets = array();
/**
* Include the preset classes
*/
public static function get_presets() {
if ( empty( self::$presets ) ) {
$presets = array();
include( 'presets/class-sp-preset-sport.php' );
$dir = scandir( SP()->plugin_path() . '/presets' );
$files = array();
if ( $dir ) {
foreach ( $dir as $key => $value ) {
if ( ! in_array( $value, array( ".",".." ) ) ) {
$files[] = $value;
}
}
}
foreach( $files as $file ) {
$json_data = file_get_contents( SP()->plugin_path() . '/presets/' . $file );
$data = json_decode( $json_data, true );
pr( $data );
}
//$presets[] = include( 'presets/class-sp-preset-soccer.php' );
//$presets[] = include( 'presets/class-sp-preset-baseball.php' );SP_TEMPLATE_PATH
self::$presets = apply_filters( 'sportspress_get_presets', $presets );
}
return self::$presets;
}
public static function get_preset_options() {
$presets = self::get_presets();
$options = apply_filters( 'sportspress_sport_presets_array', array() );
return $options;
}
/** @var array Array of sports */
private $data;
/**
* Constructor for the sports class - defines all preset sports.
*
* @access public
* @return void
*/
public function __construct() {
$this->data = sp_get_sport_presets();
}
public function __get( $key ) {
return ( array_key_exists( $key, $this->data ) ? $this->data[ $key ] : null );
}
public function __set( $key, $value ){
$this->data[ $key ] = $value;
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* SportsPress Baseball Preset
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Preset_Baseball' ) ) :
/**
* SP_Preset_Baseball
*/
class SP_Preset_Baseball extends SP_Preset_Sport {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'baseball';
$this->label = __( 'Baseball', 'sportspress' );
add_filter( 'sportspress_sport_presets_array', array( $this, 'add_sport_preset' ), 20 );
}
}
endif;
return new SP_Preset_Baseball();

View File

@@ -0,0 +1,33 @@
<?php
/**
* SportsPress Soccer Preset
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Preset_Soccer' ) ) :
/**
* SP_Preset_Soccer
*/
class SP_Preset_Soccer extends SP_Preset_Sport {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'soccer';
$this->label = __( 'Association Football (Soccer)', 'sportspress' );
add_filter( 'sportspress_sport_presets_array', array( $this, 'add_sport_preset' ), 20 );
}
}
endif;
return new SP_Preset_Soccer();

View File

@@ -0,0 +1,33 @@
<?php
/**
* SportsPress Sport Preset
*
* @author ThemeBoy
* @category Admin
* @package SportsPress/Admin
* @version 0.8
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'SP_Preset_Sport' ) ) :
/**
* SP_Preset_Sport
*/
class SP_Preset_Sport {
protected $id = '';
protected $label = '';
/**
* Add this page to settings
*/
public function add_sport_preset( $presets ) {
$presets[ $this->id ] = $this->label;
return $presets;
}
}
endif;

View File

@@ -39,7 +39,10 @@ class SP_Settings_General extends SP_Settings_Page {
* @return array
*/
public function get_settings() {
$sports = sp_get_sport_options();
$sports = new SP_Admin_Sports();
$presets = $sports->get_preset_options();
return apply_filters( 'sportspress_general_settings', array(
@@ -52,7 +55,7 @@ class SP_Settings_General extends SP_Settings_Page {
'id' => 'sportspress_sport',
'default' => 'soccer',
'type' => 'select',
'options' => $sports,
'options' => $presets,
),
array( 'type' => 'sectionend', 'id' => 'general_options' ),

View File

@@ -1,16 +1,33 @@
<?php
/**
* SportsPress sports
* SportsPress Admin Sports Class.
*
* The SportsPress sports class stores preset sport data.
* The SportsPress admin sports class stores preset sport data.
*
* @class SP_Sports
* @version 0.7
* @package SportsPress/Classes
* @version 0.8
* @package SportsPress/Admin
* @category Class
* @author ThemeBoy
*/
class SP_Sports {
private static $presets = array();
/**
* Include the preset classes
*/
public static function get_presets() {
if ( empty( self::$presets ) ) {
$presets = array();
include_once( 'preset/class-sp-preset-sport.php' );
$presets[] = include( 'preset/class-sp-preset-soccer.php' );
self::$presets = apply_filters( 'sportspress_get_presets', $presets );
}
return self::$presets;
}
/** @var array Array of sports */
private $data;

46
presets/soccer.json Normal file
View File

@@ -0,0 +1,46 @@
{
"sport": "soccer",
"id": "premier-league",
"name": "Premier League",
"outcomes": [
"W",
"D",
"L"
],
"results": [
"1st Half",
"2nd Half",
"Goals"
],
"performance": [
"Goals",
"Assists",
"Fouls",
"Yellow Cards",
"Red Cards"
],
"columns": [
{ "name" : "P", "equation" : "$events" },
{ "name" : "W", "equation" : "$w" },
{ "name" : "D", "equation" : "$d" },
{ "name" : "L", "equation" : "$l" },
{ "name" : "GF", "equation" : "$goalsfor" },
{ "name" : "GA", "equation" : "$goalsagainst" },
{ "name" : "GD", "equation" : "$goalsfor - $goalsagainst" },
{ "name" : "Pts", "equation" : "$w * 3 + $d" }
],
"metrics": [
"Height",
"Weight"
],
"statistics": [
{ "name" : "Appearances", "equation" : "$events" }
{ "name" : "Average Goals per Match", "equation" : "$goals / $events" }
{ "name" : "Win Ratio", "equation" : "$w / $events" }
{ "name" : "Played", "equation" : "$eventsplayed" }
{ "name" : "Played", "equation" : "$eventsplayed" }
{ "name" : "Played", "equation" : "$eventsplayed" }
{ "name" : "Played", "equation" : "$eventsplayed" }
{ "name" : "Played", "equation" : "$eventsplayed" }
]
}

View File

@@ -4,7 +4,7 @@ Tags: sports, press, sports journalism, teams, team management, fixtures, result
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=support@themeboy.com&item_name=Donation+for+SportsPress
Requires at least: 3.8
Tested up to: 3.9
Stable tag: 0.8.1
Stable tag: 0.8.3
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -164,10 +164,12 @@ Yes, CSV importers are included with the plugin. Go to Tools > Import and choose
== Changelog ==
= 0.8.2 =
* Fix - Add content in main loop only.
= 0.8.1 =
* Tweak - Output player statistics in system status.
* Tweak - Prepend templates to content instead of outputting directly.
* Fix - Add content in main loop only.
* Fix - Enable metrics usage in individual player statistics.
= 0.8 =

View File

@@ -3,7 +3,7 @@
* Plugin Name: SportsPress
* Plugin URI: http://wordpress.org/plugins/sportspress
* Description: Manage your club and its players, staff, events, league tables, and player lists.
* Version: 0.8.1
* Version: 0.8.3
* Author: ThemeBoy
* Author URI: http://themeboy.com
* Requires at least: 3.8
@@ -26,14 +26,14 @@ if ( ! class_exists( 'SportsPress' ) ) :
* Main SportsPress Class
*
* @class SportsPress
* @version 0.8.1
* @version 0.8.3
*/
final class SportsPress {
/**
* @var string
*/
public $version = '0.8.1';
public $version = '0.8.3';
/**
* @var SporsPress The single instance of the class