Remove sport taxonomy and improve equation selectors

This commit is contained in:
ThemeBoy
2013-11-27 17:31:35 +11:00
parent 68fa7f30d4
commit 388e5283b4
10 changed files with 105 additions and 125 deletions

View File

@@ -23,7 +23,6 @@ function sp_metric_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_sport' => __( 'Sports', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
);
return $columns;
@@ -31,5 +30,22 @@ function sp_metric_edit_columns() {
add_filter( 'manage_edit-sp_metric_columns', 'sp_metric_edit_columns' );
function sp_metric_meta_init() {
add_meta_box( 'sp_equationdiv', __( 'Equation', 'sportspress' ), 'sp_metric_equation_meta', 'sp_metric', 'normal', 'high' );
}
function sp_metric_equation_meta( $post ) {
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
?>
<div>
<p class="sp-equation-selector">
<?php
foreach ( $equation as $piece ):
sp_get_equation_selector( $post->ID, $piece, array( 'event' ) );
endforeach;
?>
</p>
</div>
<?php
sp_nonce();
}
?>

View File

@@ -23,13 +23,29 @@ function sp_outcome_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_sport' => __( 'Sports', 'sportspress' ),
'sp_equation' => __( 'Conditions', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
);
return $columns;
}
add_filter( 'manage_edit-sp_outcome_columns', 'sp_outcome_edit_columns' );
function sp_outcome_meta_init() {
add_meta_box( 'sp_equationdiv', __( 'Equation', 'sportspress' ), 'sp_outcome_equation_meta', 'sp_outcome', 'normal', 'high' );
}
function sp_outcome_equation_meta( $post ) {
$equation = explode( ' ', get_post_meta( $post->ID, 'sp_equation', true ) );
?>
<div>
<p class="sp-equation-selector">
<?php
foreach ( $equation as $piece ):
sp_get_equation_selector( $post->ID, $piece, array( 'result' ) );
endforeach;
?>
</p>
</div>
<?php
sp_nonce();
}
?>

View File

@@ -12,7 +12,6 @@ function sp_result_cpt_init() {
'show_in_nav_menus' => false,
'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ),
'register_meta_box_cb' => 'sp_result_meta_init',
'show_in_menu' => 'edit.php?post_type=sp_event'
);
register_post_type( 'sp_result', $args );
@@ -22,14 +21,9 @@ add_action( 'init', 'sp_result_cpt_init' );
function sp_result_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_sport' => __( 'Sports', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
'title' => __( 'Label', 'sportspress' )
);
return $columns;
}
add_filter( 'manage_edit-sp_result_columns', 'sp_result_edit_columns' );
function sp_result_meta_init() {
}
?>

View File

@@ -24,7 +24,6 @@ function sp_stat_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_sport' => __( 'Sports', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
);
return $columns;
@@ -42,7 +41,7 @@ function sp_stat_equation_meta( $post ) {
<p class="sp-equation-selector">
<?php
foreach ( $equation as $piece ):
sp_get_equation_selector( $post->ID, 'stat', $piece );
sp_get_equation_selector( $post->ID, $piece, array( 'event', 'result', 'outcome' ) );
endforeach;
?>
</p>

View File

@@ -1,20 +0,0 @@
<?php
function sp_sport_term_init() {
$name = __( 'Sports', 'sportspress' );
$singular_name = __( 'Sport', 'sportspress' );
$lowercase_name = __( 'sport', 'sportspress' );
$object_type = array( 'sp_result', 'sp_outcome', 'sp_stat', 'sp_metric' );
$labels = sp_tax_labels( $name, $singular_name, $lowercase_name );
$args = array(
'label' => $name,
'labels' => $labels,
'public' => false,
'show_ui' => true,
'show_in_nav_menus' => false,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'sport' )
);
register_taxonomy( 'sp_sport', $object_type, $args );
}
add_action( 'init', 'sp_sport_term_init' );
?>

View File

@@ -74,6 +74,9 @@ jQuery(document).ready(function($){
});
// Trigger equation selector
$('.sp-equation-selector select:last').change();
$('.sp-equation-selector select:last').change().siblings().change();
// Remove slug editor in quick edit for slug-sensitive post types
$('.inline-edit-sp_result, .inline-edit-sp_outcome, .inline-edit-sp_stat, .inline-edit-sp_metric').find('input[name=post_name]').closest('label').remove();
});

View File

@@ -46,9 +46,6 @@ function sp_manage_posts_custom_column( $column, $post_id ) {
$result = get_post_meta( $post_id, 'sp_result', false );
echo get_post_meta ( $post_id, 'sp_team' ) ? sp_the_posts( $post_id, 'sp_team', '', '<br />', $result, ( empty( $result ) ? ' — ' : ' ' ) ) : '—';
break;
case 'sp_sport':
echo get_the_terms ( $post_id, 'sp_sport' ) ? preg_replace('#<a.*?>.*?</a>#i', '', sp_the_plain_terms( $post_id, 'sp_sport' ) ) : '—';
break;
case 'sp_equation':
echo get_post_meta ( $post_id, 'sp_equation', true );
break;
@@ -107,16 +104,6 @@ function sp_restrict_manage_posts() {
);
sp_dropdown_taxonomies( $args );
endif;
if ( in_array( $typenow, array( 'sp_stat', 'sp_metric' ) ) ):
$selected = isset( $_REQUEST['sp_sport'] ) ? $_REQUEST['sp_sport'] : null;
$args = array(
'show_option_all' => sprintf( __( 'All %s', 'sportspress' ), __( 'Sports', 'sportspress' ) ),
'taxonomy' => 'sp_sport',
'name' => 'sp_sport',
'selected' => $selected
);
sp_dropdown_taxonomies( $args );
endif;
}
add_action( 'restrict_manage_posts', 'sp_restrict_manage_posts' );
@@ -161,6 +148,20 @@ function sp_save_post( $post_id ) {
break;
case ( 'sp_result' ):
// Update equation as string
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
break;
case ( 'sp_outcome' ):
// Update equation as string
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
break;
case ( 'sp_stat' ):
// Update equation as string
@@ -168,6 +169,13 @@ function sp_save_post( $post_id ) {
break;
case ( 'sp_metric' ):
// Update equation as string
update_post_meta( $post_id, 'sp_equation', implode( ' ', sp_array_value( $_POST, 'sp_equation', array() ) ) );
break;
case ( 'sp_player' ):
update_post_meta( $post_id, 'sp_stats', sp_array_value( $_POST, 'sp_stats', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );

View File

@@ -59,9 +59,24 @@ function sp_sanitize_title( $title ) {
// Remove all other non-alphabet characters
$title = preg_replace( "/[^a-z]/", '', $title );
// Convert post ID to words if title is empty
if ( $title == '' ) $title = sp_numbers_to_words( $_POST['ID'] );
endif;
return $title;
}
add_filter( 'sanitize_title', 'sp_sanitize_title' );
function sp_pre_get_posts( $wp_query ) {
if ( is_admin() ):
$post_type = $wp_query->query['post_type'];
if ( in_array( $post_type, array( 'sp_result', 'sp_outcome', 'sp_stat', 'sp_metric' ) ) ):
$wp_query->set( 'orderby', 'menu_order' );
$wp_query->set( 'order', 'ASC' );
endif;
endif;
}
add_filter('pre_get_posts', 'sp_pre_get_posts');
?>

View File

@@ -257,7 +257,7 @@ if ( !function_exists( 'sp_post_checklist' ) ) {
}
if ( !function_exists( 'sp_get_equation_optgroup_array' ) ) {
function sp_get_equation_optgroup_array( $postid, $type = null, $variations = null, $defaults = null ) {
function sp_get_equation_optgroup_array( $postid, $type = null, $variations = null, $defaults = null, $plain = true ) {
$arr = array();
// Get stats within the sports that the current stat is in ### TODO: should be for sport selected
@@ -265,22 +265,10 @@ if ( !function_exists( 'sp_get_equation_optgroup_array' ) ) {
'post_type' => $type,
'numberposts' => -1,
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
'exclude' => $postid
);
$sports = get_the_terms( $postid, 'sp_sport' );
if ( ! empty( $sports ) ):
$terms = array();
foreach ( $sports as $sport ):
$terms[] = $sport->slug;
endforeach;
$args['tax_query'] = array(
array(
'taxonomy' => 'sp_sport',
'field' => 'slug',
'terms' => $terms
)
);
endif;
$vars = get_posts( $args );
// Add extra vars to the array
@@ -293,6 +281,7 @@ if ( !function_exists( 'sp_get_equation_optgroup_array' ) ) {
// Add vars to the array
if ( isset( $variations ) && is_array( $variations ) ):
foreach ( $vars as $var ):
if ( $plain ) $arr[ $var->post_name ] = $var->post_title;
foreach ( $variations as $key => $value ):
$arr[ $var->post_name . '_' . $key ] = $var->post_title . ' ' . $value;
endforeach;
@@ -308,7 +297,7 @@ if ( !function_exists( 'sp_get_equation_optgroup_array' ) ) {
}
if ( !function_exists( 'sp_get_equation_selector' ) ) {
function sp_get_equation_selector( $postid, $type = null, $selected = null ) {
function sp_get_equation_selector( $postid, $selected = null, $groups = array() ) {
if ( ! isset( $postid ) )
return;
@@ -316,66 +305,37 @@ if ( !function_exists( 'sp_get_equation_selector' ) ) {
// Initialize options array
$options = array();
// Create array of variables
if ( $type == 'stat' ):
// Add events to options
$options[ __( 'Results', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_result', array( 'for' => '&rarr;', 'against' => '&larr;' ) );
// Add events to options
$options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( '' => '', 'max' => '&uarr;', 'min' => '&darr;' ), array( 'played' => __( 'Played', 'sportspress' ) ) );
// Add stats to options
$options[ __( 'Statistics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_stat' );
elseif ( $type == 'metric' ):
$vars = array();
// Get metrics within the sports that the current metric is in
$args = array(
'post_type' => 'sp_metric',
'numberposts' => -1,
'posts_per_page' => -1,
'exclude' => $postid
);
$sports = get_the_terms( $postid, 'sp_sport' );
if ( ! empty( $sports ) ):
$terms = array();
foreach ( $sports as $sport ):
$terms[] = $sport->slug;
endforeach;
$args['tax_query'] = array(
array(
'taxonomy' => 'sp_sport',
'field' => 'slug',
'terms' => $terms
)
);
endif;
$metrics = get_posts( $args );
// Add vars to the array
foreach ( $metrics as $metric ):
$vars[ $metric->post_name ] = $metric->post_title;
endforeach;
// Add metrics to options
$options[ __( 'Metrics', 'sportspress' ) ] = (array) $vars;
endif;
// Add groups to options
foreach ( $groups as $group ):
switch ( $group ):
case 'event':
$options[ __( 'Events', 'sportspress' ) ] = array( 'events_scheduled' => __( 'Scheduled', 'sportspress' ), 'events_attended' => __( 'Attended', 'sportspress' ), 'events_played' => __( 'Played', 'sportspress' ) );
break;
case 'result':
$options[ __( 'Results', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_result', array( 'for' => '&rarr;', 'against' => '&larr;' ), null, false );
break;
case 'outcome':
$options[ __( 'Outcomes', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_outcome', array( 'max' => '&uarr;', 'min' => '&darr;' ) );
break;
case 'stat':
$options[ __( 'Statistics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_stat' );
break;
case 'metric':
$options[ __( 'Metrics', 'sportspress' ) ] = sp_get_equation_optgroup_array( $postid, 'sp_metric' );
break;
endswitch;
endforeach;
// Create array of operators
$operators = array( '+' => '&plus;', '-' => '&minus;', '*' => '&times;', '/' => '&divide;', '(' => '(', ')' => ')' );
$operators = array( '+' => '&plus;', '-' => '&minus;', '*' => '&times;', '/' => '&divide;', '==' => '=', '!=' => '&ne;', '<' => '<', '<=' => '&le;', '>' => '>', '>=' => '&ge;', '(' => '(', ')' => ')' );
// Add operators to options
$options[ __( 'Operators', 'sportspress' ) ] = (array) $operators;
$options[ __( 'Operators', 'sportspress' ) ] = $operators;
// Create array of constants
$max = 10;
$constants = array();
for ( $i = 1; $i < $max; $i ++ ):
for ( $i = 1; $i <= $max; $i ++ ):
$constants[$i] = $i;
endfor;
@@ -705,16 +665,6 @@ if ( !function_exists( 'sportspress_render_option_field' ) ) {
case 'checkbox':
echo '<input type="checkbox" id="' . $name . '" name="' . $group . '[' . $name . ']" value="1" ' . checked( 1, isset( $value ) ? $value : 0, false ) . '/>';
break;
case 'sport':
$terms = get_terms( 'sp_sport' );
if ( $terms ) {
printf( '<select id="%s" name="%s[%s]">', $name, $group, $name );
foreach ( $terms as $term ) {
printf( '<option value="%s" %s>%s</option>', $term->slug, selected( true, $value == $term->slug, false ), $term->name );
}
print( '</select>' );
}
break;
default:
echo '<input type="text" id="' . $name . '" name="' . $group . '[' . $name . ']" value="' . $value . '" />';
break;

View File

@@ -48,7 +48,6 @@ require_once dirname( __FILE__ ) . '/admin/post-types/staff.php';
// Terms
require_once dirname( __FILE__ ) . '/admin/terms/div.php';
require_once dirname( __FILE__ ) . '/admin/terms/pos.php';
require_once dirname( __FILE__ ) . '/admin/terms/sport.php';
// Shortcodes
// require_once dirname( __FILE__ ) . '/classes/shortcodes/table.php';