Adjust officials table in events
This commit is contained in:
@@ -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 );
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 .= '<tr class="' . ( $i % 2 == 0 ? 'odd' : 'even' ) . '">';
|
||||
|
||||
$name = get_the_title( $official );
|
||||
|
||||
if ( $link_officials && sp_post_exists( $official ) ) {
|
||||
$name = '<a href="' . get_post_permalink( $official ) . '">' . $name . '</a>';
|
||||
}
|
||||
|
||||
$rows .= '<th class="data-name">' . $name . '</th>';
|
||||
|
||||
$rows .= '<td class="data-duty">' . $duty->name . '</td>';
|
||||
|
||||
$rows .= '</tr>';
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $rows ) ) return;
|
||||
?>
|
||||
|
||||
<div class="sp-template sp-template-event-officials">
|
||||
@@ -62,8 +33,28 @@ if ( empty( $rows ) ) return;
|
||||
|
||||
<div class="sp-table-wrapper">
|
||||
<table class="sp-event-officials sp-data-table<?php echo $scrollable ? ' sp-scrollable-table' : ''; ?>">
|
||||
<thead>
|
||||
<tr>
|
||||
<?php
|
||||
foreach ( $labels as $label ) {
|
||||
echo '<th class="data-name">' . $label . '</th>';
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php echo $rows; ?>
|
||||
<tr>
|
||||
<?php
|
||||
foreach ( $data as $appointed_officials ) {
|
||||
foreach ( $appointed_officials as $official_id => $official_name ) {
|
||||
if ( $link_officials && sp_post_exists( $official_id ) ) {
|
||||
$appointed_officials[ $official_id ] = '<a href="' . get_post_permalink( $official_id ) . '">' . $official_name . '</a>';
|
||||
}
|
||||
}
|
||||
echo '<td class="data-name">' . implode( ', ', $appointed_officials ) . '</td>';
|
||||
}
|
||||
?>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user