Save outcomes using slugs instead of IDs

This commit is contained in:
ThemeBoy
2013-12-01 17:39:36 +11:00
parent 2f78cc585d
commit 8afe065696
7 changed files with 75 additions and 45 deletions

View File

@@ -13,7 +13,7 @@ function sp_metric_cpt_init() {
'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ),
'register_meta_box_cb' => 'sp_metric_meta_init',
'show_in_menu' => 'edit.php?post_type=sp_player'
'show_in_menu' => 'edit.php?post_type=sp_event'
);
register_post_type( 'sp_metric', $args );
}

View File

@@ -12,7 +12,6 @@ function sp_outcome_cpt_init() {
'show_in_nav_menus' => false,
'hierarchical' => false,
'supports' => array( 'title', 'page-attributes' ),
'register_meta_box_cb' => 'sp_outcome_meta_init',
'show_in_menu' => 'edit.php?post_type=sp_event'
);
register_post_type( 'sp_outcome', $args );
@@ -22,30 +21,9 @@ add_action( 'init', 'sp_outcome_cpt_init' );
function sp_outcome_edit_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => __( 'Label', 'sportspress' ),
'sp_equation' => __( 'Equation', 'sportspress' ),
'title' => __( 'Label', '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

@@ -7,7 +7,7 @@ function sp_result_cpt_init() {
$args = array(
'label' => $name,
'labels' => $labels,
'public' => true,
'public' => false,
'show_ui' => true,
'show_in_nav_menus' => false,
'hierarchical' => false,

View File

@@ -14,7 +14,7 @@ function sp_stat_cpt_init() {
'supports' => array( 'title', 'page-attributes' ),
'register_meta_box_cb' => 'sp_stat_meta_init',
'rewrite' => array( 'slug' => 'stat' ),
'show_in_menu' => 'edit.php?post_type=sp_team'
'show_in_menu' => 'edit.php?post_type=sp_event'
);
register_post_type( 'sp_stat', $args );
}

View File

@@ -45,7 +45,7 @@ add_filter('the_content', 'sportspress_the_content');
function sp_sanitize_title( $title ) {
if ( in_array( $_POST['post_type'], array( 'sp_result', 'sp_outcome', 'sp_stat', 'sp_metric' ) ) ):
if ( isset( $_POST ) && in_array( 'post_type', $_POST ) && in_array( $_POST['post_type'], array( 'sp_result', 'sp_outcome', 'sp_stat', 'sp_metric' ) ) ):
// Get post title
$title = $_POST['post_title'];

View File

@@ -63,7 +63,7 @@ if ( !function_exists( 'sp_numbers_to_words' ) ) {
}
if ( !function_exists( 'sp_cpt_labels' ) ) {
function sp_cpt_labels( $name, $singular_name, $lowercase_name = null, $is_submenu = false ) {
function sp_cpt_labels( $name, $singular_name, $lowercase_name = null ) {
if ( !$lowercase_name ) $lowercase_name = $name;
$labels = array(
'name' => $name,
@@ -147,6 +147,57 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
}
}
if ( !function_exists( 'sp_dropdown_pages' ) ) {
/*
<select name="sp_results[60][outcome]" id="sp_results[60][outcome]">
<option value="0">Select Outcome</option>
<option class="level-0" value="138">W</option>
<option class="level-0" value="139" selected="selected">L</option>
<option class="level-0" value="141">D</option>
</select>
*/
function sp_dropdown_pages( $args = array() ) {
$defaults = array(
'show_option_all' => false,
'show_option_none' => false,
'name' => 'page_id',
'selected' => null,
'numberposts' => -1,
'posts_per_page' => -1,
'child_of' => 0,
'sort_order' => 'ASC',
'sort_column' => 'post_title',
'hierarchical' => 1,
'exclude' => null,
'include' => null,
'meta_key' => null,
'meta_value' => null,
'authors' => null,
'exclude_tree' => null,
'post_type' => 'page'
);
$args = array_merge( $defaults, $args );
$name = $args['name'];
unset( $args['name'] );
$posts = get_posts( $args );
if ( $posts ) {
printf( '<select name="%s" class="postform">', $name );
if ( $args['show_option_all'] ) {
printf( '<option value="0">%s</option>', $args['show_option_all'] );
}
if ( $args['show_option_none'] ) {
printf( '<option value="-1">%s</option>', $args['show_option_none'] );
}
foreach ( $posts as $post ) {
printf( '<option value="%s" %s>%s</option>', $post->post_name, selected( true, $args['selected'] == $post->post_name, false ), $post->post_title );
}
print( '</select>' );
}
}
}
if ( !function_exists( 'sp_the_posts' ) ) {
function sp_the_posts( $post_id = null, $meta = 'post', $before = '', $sep = ', ', $after = '', $delimiter = ' - ' ) {
if ( ! isset( $post_id ) )
@@ -678,6 +729,7 @@ if ( !function_exists( 'sp_event_results_table' ) ) {
<?php foreach ( $columns as $label ): ?>
<th><?php echo $label; ?></th>
<?php endforeach; ?>
<th><?php _e( 'Outcome', 'sportspress' ); ?></th>
</tr>
</thead>
<tbody>
@@ -695,6 +747,21 @@ if ( !function_exists( 'sp_event_results_table' ) ) {
?>
<td><input type="text" name="sp_results[<?php echo $team_id; ?>][<?php echo $column; ?>]" value="<?php echo $value; ?>" /></td>
<?php endforeach; ?>
<td>
<?php
$value = sp_array_value( $team_results, 'outcome', '' );
$args = array(
'post_type' => 'sp_outcome',
'name' => 'sp_results[' . $team_id . '][outcome]',
'show_option_none' => __( '-- Not set --', 'sportspress' ),
'option_none_value' => 0,
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'selected' => $value
);
sp_dropdown_pages( $args );
?>
</td>
</tr>
<?php
$i++;
@@ -804,21 +871,6 @@ if ( !function_exists( 'sp_someother_table' ) ) {
}
}
/*
if ( !function_exists( 'sp_team_stats_sport_choice' ) ) {
function sp_team_stats_sport_choice( $selected = null ) {
global $sportspress_sports;
?>
<select id="sp_team_stats_sport" name="sp_team_stats_sport">
<?php foreach ( $sportspress_sports as $key => $value ): ?>
<option value="<?php echo $key; ?>" data-sp-preset="<?php echo sp_array_value( $value, 'team' ); ?>"<?php if ( $selected == $key ) echo ' selected="selected"'; ?>><?php echo sp_array_value( $value, 'name' ); ?></option>
<?php endforeach; ?>
</select>
<?php
}
}
*/
if ( !function_exists( 'sp_post_adder' ) ) {
function sp_post_adder( $meta = 'post' ) {
$obj = get_post_type_object( $meta );

View File

@@ -37,12 +37,12 @@ include dirname( __FILE__ ) . '/sportspress-settings.php' ;
require_once dirname( __FILE__ ) . '/admin/post-types/event.php';
require_once dirname( __FILE__ ) . '/admin/post-types/result.php';
require_once dirname( __FILE__ ) . '/admin/post-types/outcome.php';
require_once dirname( __FILE__ ) . '/admin/post-types/stat.php';
require_once dirname( __FILE__ ) . '/admin/post-types/metric.php';
require_once dirname( __FILE__ ) . '/admin/post-types/team.php';
require_once dirname( __FILE__ ) . '/admin/post-types/table.php';
require_once dirname( __FILE__ ) . '/admin/post-types/stat.php';
require_once dirname( __FILE__ ) . '/admin/post-types/player.php';
require_once dirname( __FILE__ ) . '/admin/post-types/list.php';
require_once dirname( __FILE__ ) . '/admin/post-types/metric.php';
require_once dirname( __FILE__ ) . '/admin/post-types/staff.php';
// Terms