diff --git a/includes/admin/class-sp-admin-sports.php b/includes/admin/class-sp-admin-sports.php index 4609853a..33576416 100644 --- a/includes/admin/class-sp-admin-sports.php +++ b/includes/admin/class-sp-admin-sports.php @@ -143,7 +143,7 @@ class SP_Admin_Sports { update_post_meta( $id, 'sp_equation', sp_array_value( $result, 'equation', null ) ); } - // Make sure statistics and metrics have greater menu order than performance + // Make sure statistics, metrics and specs have greater menu order than performance $i = 0; // Performance @@ -192,6 +192,17 @@ class SP_Admin_Sports { $id = self::insert_preset_post( $post, $i + $index ); $i ++; } + + // Event Specs + $post_type = 'sp_spec'; + $specs = sp_array_value( $preset, 'specs', array() ); + self::delete_preset_posts( $post_type ); + foreach ( $specs as $index => $spec ) { + $post = self::get_post_array( $spec, $post_type ); + if ( empty( $post ) ) continue; + $id = self::insert_preset_post( $post, $i + $index ); + $i ++; + } // Statistics $post_type = 'sp_statistic'; diff --git a/includes/admin/post-types/class-sp-admin-cpt-spec.php b/includes/admin/post-types/class-sp-admin-cpt-spec.php new file mode 100644 index 00000000..8318949d --- /dev/null +++ b/includes/admin/post-types/class-sp-admin-cpt-spec.php @@ -0,0 +1,70 @@ +type = 'sp_spec'; + + // Admin Columns + add_filter( 'manage_edit-sp_spec_columns', array( $this, 'edit_columns' ) ); + add_action( 'manage_sp_spec_posts_custom_column', array( $this, 'custom_columns' ), 2, 2 ); + + // Call SP_Admin_CPT constructor + parent::__construct(); + } + + /** + * Change the columns shown in admin. + */ + public function edit_columns( $existing_columns ) { + $columns = array( + 'cb' => '', + 'title' => __( 'Label', 'sportspress' ), + 'sp_key' => __( 'Variable', 'sportspress' ), + 'sp_description' => __( 'Description', 'sportspress' ), + ); + return apply_filters( 'sportspress_spec_admin_columns', $columns ); + } + + /** + * Define our custom columns shown in admin. + * @param string $column + */ + public function custom_columns( $column, $post_id ) { + switch ( $column ): + case 'sp_key': + global $post; + echo $post->post_name; + break; + case 'sp_description': + global $post; + echo '' . $post->post_excerpt . ''; + break; + endswitch; + } +} + +endif; + +return new SP_Admin_CPT_Spec(); diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-specs.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-specs.php new file mode 100644 index 00000000..1e4e17c2 --- /dev/null +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-specs.php @@ -0,0 +1,53 @@ +ID, 'sp_specs', true ); + + $args = array( + 'post_type' => 'sp_spec', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC', + ); + + $vars = get_posts( $args ); + + if ( $vars ): + foreach ( $vars as $var ): + ?> +

post_title; ?>

+

+ ID, 'sp_visible', true ); + if ( '' === $visible ) $visible = 1; + ?> +

+

+ + +

+

+ + +

+ + - + ID, 'sp_specs', true ); + $spec_labels = (array)sp_get_var_labels( 'sp_spec', $neg, false ); + $data = array(); + + foreach ( $spec_labels as $key => $value ): + $spec = sp_array_value( $specs, $key, null ); + if ( $spec == null ) + continue; + $data[ $value ] = sp_array_value( $specs, $key, ' ' ); + endforeach; + return $data; + } } diff --git a/includes/class-sp-post-types.php b/includes/class-sp-post-types.php index f1d3c624..7a3a78e1 100644 --- a/includes/class-sp-post-types.php +++ b/includes/class-sp-post-types.php @@ -342,7 +342,7 @@ class SP_Post_types { ) ) ); - + register_post_type( 'sp_performance', apply_filters( 'sportspress_register_post_type_performance', array( diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index 5ffa1522..8a5e9726 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -1295,6 +1295,9 @@ if ( !function_exists( 'sp_solve' ) ) { // Add a hook to alter $equation $equation = apply_filters( 'sportspress_equation_alter', $equation, $vars ); + // Add a hook to alter $equation + $equation = apply_filters( 'sportspress_equation_alter', $equation, $vars ); + if ( $equation == null ) return $default; diff --git a/includes/sp-template-hooks.php b/includes/sp-template-hooks.php index a3d36f88..0a8aed14 100644 --- a/includes/sp-template-hooks.php +++ b/includes/sp-template-hooks.php @@ -257,7 +257,7 @@ function sportspress_post_updated_messages( $messages ) { global $typenow, $post; - if ( in_array( $typenow, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_metric', 'sp_performance' ) ) ): + if ( in_array( $typenow, array( 'sp_result', 'sp_outcome', 'sp_column', 'sp_metric', 'sp_spec', 'sp_performance' ) ) ): $obj = get_post_type_object( $typenow ); for ( $i = 0; $i <= 10; $i++ ): diff --git a/modules/sportspress-event-specs.php b/modules/sportspress-event-specs.php new file mode 100644 index 00000000..56164b3d --- /dev/null +++ b/modules/sportspress-event-specs.php @@ -0,0 +1,303 @@ +define_constants(); + + // Actions + add_action( 'init', array( $this, 'register_post_type' ) ); + add_action( 'sportspress_config_page', array( $this, 'sp_specs_config' ), 9 ); + add_action( 'sportspress_include_post_type_handlers', array( $this, 'include_post_type_handler' ) ); + add_action( 'sportspress_event_list_head_row', array( $this, 'event_list_head_row' ), 11 ); + add_action( 'sportspress_event_list_row', array( $this, 'event_list_row' ), 11, 2 ); + + // Filters + add_filter( 'sportspress_meta_boxes', array( $this, 'add_meta_boxes' ) ); + add_filter( 'sportspress_screen_ids', array( $this, 'screen_ids' ) ); + add_filter( 'sportspress_config_types', array( $this, 'add_post_type' ) ); + add_filter( 'sportspress_event_details', array( $this, 'event_details' ), 10, 2 ); + add_filter( 'sportspress_calendar_columns', array( $this, 'calendar_columns' ) ); + add_filter( 'sportspress_equation_options', array( $this, 'add_options' ) ); + add_filter( 'sportspress_equation_alter', array( $this, 'alter_equation' ), 11, 2 ); + } + + /** + * Define constants. + */ + private function define_constants() { + if ( !defined( 'SP_EVENT_SPECS_VERSION' ) ) + define( 'SP_EVENT_SPECS_VERSION', '2.5.10' ); + + if ( !defined( 'SP_EVENT_SPECS_URL' ) ) + define( 'SP_EVENT_SPECS_URL', plugin_dir_url( __FILE__ ) ); + + if ( !defined( 'SP_EVENT_SPECS_DIR' ) ) + define( 'SP_EVENT_SPECS_DIR', plugin_dir_path( __FILE__ ) ); + } + + /** + * Register event specs post type + */ + public static function register_post_type() { + register_post_type( 'sp_spec', + apply_filters( 'sportspress_register_post_type_spec', + array( + 'labels' => array( + 'name' => __( 'Event Specs', 'sportspress' ), + 'singular_name' => __( 'Event Spec', 'sportspress' ), + 'add_new_item' => __( 'Add New Event Spec', 'sportspress' ), + 'edit_item' => __( 'Edit Event Spec', 'sportspress' ), + 'new_item' => __( 'New', 'sportspress' ), + 'view_item' => __( 'View', 'sportspress' ), + 'search_items' => __( 'Search', 'sportspress' ), + 'not_found' => __( 'No results found.', 'sportspress' ), + 'not_found_in_trash' => __( 'No results found.', 'sportspress' ), + ), + 'public' => false, + 'show_ui' => true, + 'capability_type' => 'sp_config', + 'map_meta_cap' => true, + 'publicly_queryable' => false, + 'exclude_from_search' => true, + 'hierarchical' => false, + 'supports' => array( 'title', 'page-attributes', 'excerpt' ), + 'has_archive' => false, + 'show_in_nav_menus' => false, + 'can_export' => false, + 'show_in_menu' => false, + ) + ) + ); + } + + /** + * Add screen ids. + * + * @return array + */ + public function screen_ids( $ids ) { + return array_merge( $ids, array( + 'edit-sp_spec', + 'sp_spec', + ) ); + } + + public static function add_post_type( $post_types = array() ) { + $post_types[] = 'sp_spec'; + return $post_types; + } + + /** + * Conditonally load the class and functions only needed when viewing this post type. + */ + public function include_post_type_handler() { + include_once( SP()->plugin_path() . '/includes/admin/post-types/class-sp-admin-cpt-spec.php' ); + } + + /** + * Display Event Specs Table at Config Page + * @return null + */ + public function sp_specs_config() { + ?> +
+ + 'sp_spec', + 'numberposts' => -1, + 'posts_per_page' => -1, + 'orderby' => 'menu_order', + 'order' => 'ASC' + ); + $data = get_posts( $args ); + ?> + + + + + +
+ +

+
+ + + + + + + + + + + > + + + + + + + + + + +
post_title; ?>post_name; ?>

post_excerpt; ?>

+
+ + +
+
+
+ array( + 'title' => __( 'Specs', 'sportspress' ), + 'save' => 'SP_Meta_Box_Spec_Details::save', + 'output' => 'SP_Meta_Box_Spec_Details::output', + 'context' => 'normal', + 'priority' => 'high', + ), + ); + $meta_boxes['sp_event']['specs'] = array( + 'title' => __( 'Specs', 'sportspress' ), + 'save' => 'SP_Meta_Box_Event_Specs::save', + 'output' => 'SP_Meta_Box_Event_Specs::output', + 'context' => 'side', + 'priority' => 'default', + ); + return $meta_boxes; + } + + /** + * Add event details. + * + * @return array + */ + public function event_details ( $data, $id ) { + + $event = new SP_Event( $id ); + + $specs_before = $event->specs( true ); + $specs_after = $event->specs( false ); + + $data = array_merge( $specs_before, $data, $specs_after ); + + return $data; + } + + /** + * Add calendar columns. + * + * @return array + */ + public function calendar_columns( $columns = array() ) { + $columns['event_specs'] = __( 'Event Specs', 'sportspress' ); + return $columns; + } + + /** + * Event list head row. + */ + public function event_list_head_row( $usecolumns = array() ) { + if ( is_array( $usecolumns ) && in_array( 'event_specs', $usecolumns ) ) { + $spec_labels = (array)sp_get_var_labels( 'sp_spec', null, false ); + + if ( empty( $spec_labels ) ) return; + + foreach ( $spec_labels as $spec_label ) { + ?> + + + + specs( false ); + $spec_labels = (array)sp_get_var_labels( 'sp_spec', null, false ); + + foreach ( $spec_labels as $spec_label ) { + ?> + + + + $value ) { + $options[ 'Event Specs' ]['$spec'.$key] = $value; + } + return $options; + } + + /** + * Alter. + * + * @return array + */ + public function alter_equation( $equation, $vars ) { + //var_dump($equation); + //var_dump($vars); + // Remove space between equation parts + $equation = str_replace( ' ', '', $equation ); + + return $equation; + } +} + +endif; + +new SportsPress_Event_Specs();