Adjust officials table in events

This commit is contained in:
Brian Miyaji
2017-11-09 14:04:49 +11:00
parent 0c06fe656a
commit 62bee2e482
3 changed files with 66 additions and 38 deletions

View File

@@ -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>