diff --git a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php index 4b8858ef..2d06c814 100644 --- a/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php +++ b/includes/admin/post-types/meta-boxes/class-sp-meta-box-event-officials.php @@ -23,6 +23,7 @@ class SP_Meta_Box_Event_Officials { $duties = get_terms( array( 'taxonomy' => 'sp_duty', 'hide_empty' => false, + 'orderby' => 'slug', ) ); $officials = (array) get_post_meta( $post->ID, 'sp_officials', true ); diff --git a/includes/class-sp-event.php b/includes/class-sp-event.php index 0024954a..7561147a 100644 --- a/includes/class-sp-event.php +++ b/includes/class-sp-event.php @@ -541,6 +541,42 @@ class SP_Event extends SP_Custom_Post{ // Return if no teams meet criteria return null; } + + public function appointments() { + $officials = (array) get_post_meta( $this->ID, 'sp_officials', true ); + $officials = array_filter( $officials ); + + if ( empty( $officials ) ) return null; + + $duties = get_terms( array( + 'taxonomy' => 'sp_duty', + 'hide_empty' => false, + 'orderby' => 'slug', + ) ); + + if ( empty( $duties ) ) return null; + + $labels = array(); + $appointments = array(); + + foreach ( $duties as $duty ) { + $duty_appointments = sp_array_value( $officials, $duty->term_id, null ); + + if ( empty( $duty_appointments ) ) continue; + + $appointed_officials = array(); + foreach ( $duty_appointments as $duty_appointment ) { + $appointed_officials[ $duty_appointment ] = get_the_title( $duty_appointment ); + } + + $appointments[ $duty->slug ] = $appointed_officials; + $labels[ $duty->slug ] = $duty->name; + } + + $appointments[0] = $labels; + + return $appointments; + } public function update_main_results( $results ) { $main_result = sp_get_main_result_option(); diff --git a/templates/event-officials.php b/templates/event-officials.php index 9287e2c4..66e9b473 100644 --- a/templates/event-officials.php +++ b/templates/event-officials.php @@ -12,49 +12,20 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly if ( ! isset( $id ) ) $id = get_the_ID(); -$officials = (array) get_post_meta( $id, 'sp_officials', true ); -$officials = array_filter( $officials ); +$event = new SP_Event( $id ); -if ( empty( $officials ) ) return; +// Get appointed officials from event +$data = $event->appointments(); -$duties = get_terms( array( - 'taxonomy' => 'sp_duty', - 'hide_empty' => false, -) ); +// Return if no officials are in event +if ( empty( $data ) ) return; -if ( empty( $duties ) ) return; +// The first row should be column labels +$labels = $data[0]; +unset( $data[0] ); $scrollable = get_option( 'sportspress_enable_scrollable_tables', 'yes' ) == 'yes' ? true : false; $link_officials = get_option( 'sportspress_link_officials', 'no' ) == 'yes' ? true : false; - -$rows = ''; -$i = 0; - -foreach ( $duties as $duty ) { - $officials_on_duty = sp_array_value( $officials, $duty->term_id, array() ); - - if ( empty( $officials_on_duty ) ) continue; - - foreach ( $officials_on_duty as $official ) { - $rows .= ''; - - $name = get_the_title( $official ); - - if ( $link_officials && sp_post_exists( $official ) ) { - $name = '' . $name . ''; - } - - $rows .= '' . $name . ''; - - $rows .= '' . $duty->name . ''; - - $rows .= ''; - - $i++; - } -} - -if ( empty( $rows ) ) return; ?>
@@ -62,8 +33,28 @@ if ( empty( $rows ) ) return;
+ + + ' . $label . ''; + } + ?> + + - + + $official_name ) { + if ( $link_officials && sp_post_exists( $official_id ) ) { + $appointed_officials[ $official_id ] = '' . $official_name . ''; + } + } + echo ''; + } + ?> +
' . implode( ', ', $appointed_officials ) . '