Addition of managing officials

Added incorrectly missing includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php
This commit is contained in:
Rob Tucker
2017-06-11 13:13:12 +00:00
parent 72fc479809
commit dc3e152ead
8 changed files with 176 additions and 19 deletions

View File

@@ -26,6 +26,7 @@ class SP_Admin_Menus {
add_action( 'admin_menu', array( $this, 'config_menu' ), 7 );
add_action( 'admin_menu', array( $this, 'leagues_menu' ), 20 );
add_action( 'admin_menu', array( $this, 'seasons_menu' ), 21 );
add_action( 'admin_menu', array( $this, 'officials_menu' ), 22 );
add_action( 'admin_head', array( $this, 'menu_highlight' ) );
add_action( 'admin_head', array( $this, 'menu_rename' ) );
@@ -68,6 +69,13 @@ class SP_Admin_Menus {
add_submenu_page( 'sportspress', __( 'Seasons', 'sportspress' ), __( 'Seasons', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_season');
}
/**
* Add menu item
*/
public function officials_menu() {
add_submenu_page( 'sportspress', __( 'Officials', 'sportspress' ), __( 'Officials', 'sportspress' ), 'manage_sportspress', 'edit-tags.php?taxonomy=sp_officials');
}
/**
* Highlights the correct top level admin menu item for post type add screens.
*
@@ -130,6 +138,7 @@ class SP_Admin_Menus {
$sportspress_team = array_search( 'edit.php?post_type=sp_team', $menu_order );
$sportspress_player = array_search( 'edit.php?post_type=sp_player', $menu_order );
$sportspress_staff = array_search( 'edit.php?post_type=sp_staff', $menu_order );
$sportspress_official = array_search( 'edit.php?post_type=sp_official', $menu_order );
// Loop through menu order and do some rearranging
foreach ( $menu_order as $index => $item ):
@@ -141,11 +150,13 @@ class SP_Admin_Menus {
$sportspress_menu_order[] = 'edit.php?post_type=sp_team';
$sportspress_menu_order[] = 'edit.php?post_type=sp_player';
$sportspress_menu_order[] = 'edit.php?post_type=sp_staff';
$sportspress_menu_order[] = 'edit.php?post_type=sp_official';
unset( $menu_order[ $sportspress_separator ] );
unset( $menu_order[ $sportspress_event ] );
unset( $menu_order[ $sportspress_team ] );
unset( $menu_order[ $sportspress_player ] );
unset( $menu_order[ $sportspress_staff ] );
unset( $menu_order[ $sportspress_official ] );
// Apply to added menu items
$menu_items = apply_filters( 'sportspress_menu_items', array() );
@@ -217,6 +228,11 @@ class SP_Admin_Menus {
$submenu['edit.php?post_type=sp_staff'] = array_filter( $submenu['edit.php?post_type=sp_staff'], array( $this, 'remove_seasons' ) );
endif;
if ( isset( $submenu['edit.php?post_type=sp_official'] ) ):
$submenu['edit.php?post_type=sp_official'] = array_filter( $submenu['edit.php?post_type=sp_official'], array( $this, 'remove_leagues' ) );
$submenu['edit.php?post_type=sp_official'] = array_filter( $submenu['edit.php?post_type=sp_official'], array( $this, 'remove_seasons' ) );
endif;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
@@ -281,4 +297,4 @@ class SP_Admin_Menus {
endif;
return new SP_Admin_Menus();
return new SP_Admin_Menus();

View File

@@ -130,6 +130,13 @@ class SP_Admin_Meta_Boxes {
'context' => 'side',
'priority' => 'default',
),
'officials' => array(
'title' => __( 'Officials', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Officials::save',
'output' => 'SP_Meta_Box_Event_Officials::output',
'context' => 'side',
'priority' => 'default',
),
'details' => array(
'title' => __( 'Details', 'sportspress' ),
'save' => 'SP_Meta_Box_Event_Details::save',

View File

@@ -35,4 +35,4 @@ class SP_Meta_Box_Event_Mode {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_mode', sp_array_value( $_POST, 'sp_mode', 'team' ) );
}
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* Event Officials
*
* @author Rob Tucker <rtucker-scs>
* @category Admin
* @package SportsPress/Admin/Meta_Boxes
* @version 2.3
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* SP_Meta_Box_Event_Officials
*/
class SP_Meta_Box_Event_Officials {
/**
* Output the metabox
*/
public static function output( $post ) {
wp_nonce_field( 'sportspress_save_data', 'sportspress_meta_nonce' );
$abbreviation = get_post_meta( $post->ID, 'sp_abbreviation', true );
$redirect = get_post_meta( $post->ID, 'sp_redirect', true );
$url = get_post_meta( $post->ID, 'sp_url', true );
if ( taxonomy_exists( 'sp_officials' ) ):
$officials = get_the_terms( $post->ID, 'sp_officials' );
$official_ids = array();
if ( $officials ):
foreach ( $officials as $official ):
$official_ids[] = $official->term_id;
endforeach;
endif;
endif;
?>
<?php if ( taxonomy_exists( 'sp_officials' ) ) { ?>
<p><strong><?php _e( 'Officials', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'taxonomy' => 'sp_officials',
'name' => 'tax_input[sp_officials][]',
'selected' => $official_ids,
'values' => 'term_id',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Officials', 'sportspress' ) ),
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_taxonomies( $args );
?></p>
<?php } ?>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_officials', sp_array_value( $_POST, 'sp_officials', 'official' ) );
}
}

View File

@@ -67,6 +67,23 @@ class SP_Meta_Box_Player_Details {
$past_teams = array_filter( get_post_meta( $post->ID, 'sp_past_team', false ) );
$current_teams = array_filter( get_post_meta( $post->ID, 'sp_current_team', false ) );
?>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team[]',
'selected' => $current_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-current-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
<p><strong><?php _e( 'Squad Number', 'sportspress' ); ?></strong></p>
<p><input type="text" size="4" id="sp_number" name="sp_number" value="<?php echo $number; ?>"></p>
@@ -99,20 +116,6 @@ class SP_Meta_Box_Player_Details {
?></p>
<?php } ?>
<p><strong><?php _e( 'Current Teams', 'sportspress' ); ?></strong></p>
<p><?php
$args = array(
'post_type' => 'sp_team',
'name' => 'sp_current_team[]',
'selected' => $current_teams,
'values' => 'ID',
'placeholder' => sprintf( __( 'Select %s', 'sportspress' ), __( 'Teams', 'sportspress' ) ),
'class' => 'sp-current-teams widefat',
'property' => 'multiple',
'chosen' => true,
);
sp_dropdown_pages( $args );
?></p>
<p><strong><?php _e( 'Past Teams', 'sportspress' ); ?></strong></p>
<p><?php
@@ -175,4 +178,4 @@ class SP_Meta_Box_Player_Details {
sp_update_post_meta_recursive( $post_id, 'sp_past_team', sp_array_value( $_POST, 'sp_past_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', array_merge( array( sp_array_value( $_POST, 'sp_current_team', array() ) ), sp_array_value( $_POST, 'sp_past_team', array() ) ) );
}
}
}

View File

@@ -124,4 +124,4 @@ class SP_Meta_Box_Team_Details {
update_post_meta( $post_id, 'sp_redirect', sp_array_value( $_POST, 'sp_redirect', 0 ) );
update_post_meta( $post_id, 'sp_abbreviation', esc_attr( sp_array_value( $_POST, 'sp_abbreviation', '' ) ) );
}
}
}

View File

@@ -178,6 +178,43 @@ class SP_Post_types {
endforeach;
endif;
if ( apply_filters( 'sportspress_has_officials', true ) ):
$labels = array(
'name' => __( 'Officials', 'sportspress' ),
'singular_name' => __( 'Official', 'sportspress' ),
'all_items' => __( 'All', 'sportspress' ),
'edit_item' => __( 'Edit Official', 'sportspress' ),
'view_item' => __( 'View', 'sportspress' ),
'update_item' => __( 'Update', 'sportspress' ),
'add_new_item' => __( 'Add New', 'sportspress' ),
'new_item_name' => __( 'Name', 'sportspress' ),
'parent_item' => __( 'Parent', 'sportspress' ),
'parent_item_colon' => __( 'Parent:', 'sportspress' ),
'search_items' => __( 'Search', 'sportspress' ),
'not_found' => __( 'No results found.', 'sportspress' ),
);
$args = apply_filters( 'sportspress_register_taxonomy_role', array(
'label' => __( 'Officials', 'sportspress' ),
'labels' => $labels,
'public' => true,
'show_ui' => $show,
'show_in_menu' => $show,
'show_in_nav_menus' => false,
'show_tagcloud' => false,
'hierarchical' => true,
'rewrite' => array( 'slug' => get_option( 'sportspress_official_slug', 'official' ) ),
'show_in_rest' => true,
'rest_controller_class' => 'SP_REST_Terms_Controller',
'rest_base' => 'officials',
) );
$object_types = apply_filters( 'sportspress_official_object_types', array( 'sp_officials' ) );
register_taxonomy( 'sp_officials', $object_types, $args );
foreach ( $object_types as $object_type ):
register_taxonomy_for_object_type( 'sp_official', $object_type );
endforeach;
endif;
if ( apply_filters( 'sportspress_has_roles', true ) ):
$labels = array(
'name' => __( 'Jobs', 'sportspress' ),

View File

@@ -114,4 +114,37 @@ endif;
?>
<div class="sp-template sp-template-event-results">
<?php echo $output; ?>
</div>
</div>
<?php
$officials = get_the_terms( $post->ID, 'sp_officials' );
$official_ids = array();
if ( $officials ):
foreach ( $officials as $official ):
$official_ids[] = $official->term_id;
endforeach;
endif;
if(sizeof($official_ids) > 0 ){
?>
<h4 class="sp-table-caption">Umpires</h4>
<div class="sp-template sp-template-event-results">
<?php
$i=0;
echo '<table class="sp-event-results sp-data-table sp-scrollable-table">';
echo '<thead><th class="data-name"></th></thead>';
echo '<tbody>';
foreach($officials as $official) {
echo '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
echo '<td class="data-name">' . $official->name . '</td>';
echo '</tr>';
$i++;
}
echo '</tbody>';
echo '</table>';
?>
</div>
<?php
}
?>
</div>