Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Last active January 31, 2019 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshfeck/fb2e40b80294d3f12144 to your computer and use it in GitHub Desktop.
Save joshfeck/fb2e40b80294d3f12144 to your computer and use it in GitHub Desktop.
<?php
// Options
$date_format = get_option( 'date_format' );
$time_format = get_option( 'time_format' );
// Load Venue View Helper
EE_Registry::instance()->load_helper('Venue_View');
//Defaults
$reg_button_text = !isset($reg_button_text) ? __('Register', 'event_espresso') : $reg_button_text;
$alt_button_text = !isset($alt_button_text) ? __('View Details', 'event_espresso') : $alt_button_text;//For alternate registration pages
$sold_out_button_text = !isset($sold_out_button_text) ? __('Sold Out', 'event_espresso') : $sold_out_button_text;//For sold out events
if ( have_posts() ) :
// allow other stuff
do_action( 'AHEE__espresso_events_table_template_template__before_loop' );
?>
<?php if ($category_filter != 'false'){ ?>
<p class="category-filter">
<label><?php echo __('Category Filter', 'event_espresso'); ?></label>
<select class="" id="ee_filter_cat">
<option class="ee_filter_show_all"><?php echo __('Show All', 'event_espresso'); ?></option>
<?php
$taxonomy = array('espresso_event_categories');
$args = array('orderby'=>'name','hide_empty'=>true);
$ee_terms = get_terms($taxonomy, $args);
foreach($ee_terms as $term){
echo '<option class="' . $term->slug . '">'. $term->name . '</option>';
}
?>
</select>
</p>
<?php } ?>
<?php if ($footable != 'false' && $table_search != 'false'){ ?>
<p>
<?php echo __('Search:', 'event_espresso'); ?> <input id="filter" type="text"/>
</p>
<?php } ?>
<table id="ee_filter_table" class="espresso-table footable table" data-page-size="<?php echo $table_pages; ?>" data-filter="#filter">
<thead class="espresso-table-header-row">
<tr>
<th class="th-group"><?php _e('Date','event_espresso'); ?></th>
<th class="th-group"><?php _e('Day','event_espresso'); ?></th>
<th class="th-group"><?php _e('Time','event_espresso'); ?></th>
<th class="th-group"><?php _e('Course','event_espresso'); ?></th>
<th class="th-group"><?php _e('Price','event_espresso'); ?></th>
<th class="th-group" data-sort-ignore="true"></th>
</tr>
</thead>
<?php if ($footable != 'false' && $table_paging != 'false'){ ?>
<tfoot>
<tr>
<td colspan="4">
<div class="pagination pagination-centered"></div>
</td>
</tr>
</tfoot>
<?php } ?>
<tbody>
<?php
// Start the Loop.
while ( have_posts() ) : the_post();
// Include the post TYPE-specific template for the content.
global $post;
//Debug
//d( $post );
//Get the category for this event
$event = EEH_Event_View::get_event();
if ( $event instanceof EE_Event ) {
if ( $event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' )) {
// loop thru terms and create links
$category_slugs = '';
foreach ( $event_categories as $term ) {
$category_slugs[] = $term->slug;
}
$category_slugs = implode(' ', $category_slugs);
} else {
// event has no terms
$category_slugs = '';
}
}
//Create the event link
$external_url = $post->EE_Event->external_url();
$button_text = !empty($external_url) ? $alt_button_text : $reg_button_text;
$registration_url = !empty($external_url) ? $post->EE_Event->external_url() : $post->EE_Event->get_permalink();
//Create the register now button
$live_button = '<a class="register-button" id="a_register_link-'.$post->ID.'" href="'.$registration_url.'">'.$button_text.'</a>';
if ( $event->is_sold_out() ) {
$live_button = '<a id="a_register_link-'.$post->ID.'" class="soldout-button" href="'.$registration_url.'">'.$sold_out_button_text.'</a>';
}
$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, $show_expired, false, 1 );
$datetime = end( $datetimes );
$startdate = date_i18n( $date_format, strtotime( $datetime->start_date_and_time('Y-m-d', 'H:i:s') ) );
$starttime = date_i18n( 'G:i', strtotime( $datetime->start_time('H:i:s') ) );
// grab array of EE_Ticket objects for event
$tickets = EEH_Event_View::event_tickets_available( $post->ID );
// grab first ticket from array
$ticket = array_shift( $tickets );
$ticket_price = $ticket instanceof EE_Ticket ? sprintf("%0.2f",$ticket->ticket_price()) . '<span class="currency-code"> (CHF)</span>' : '';
$ticket_price_data_value = $ticket instanceof EE_Ticket ? $ticket->price() : '';
$tickets_price_free_check = $ticket_price_data_value == 0 ? __('Free','event_espresso') : $ticket_price;
// OA Add so that it doesn't show free for full events
$tickets_price_free_check = (string)$ticket_price_data_value == '' ? __('Sold Out','event_espresso') : $tickets_price_free_check;
// grab primary datetime for event
$first_datetime = espresso_event_date_obj( $post->ID );
$tickets_left = $first_datetime instanceof EE_Datetime ? $first_datetime->tickets_remaining() : 0;
$tickets_left = $tickets_left === INF ? __('unlimited','event_espresso') : $tickets_left;
?>
<tr class="espresso-table-row <?php echo $category_slugs; ?>">
<td class="start_date event-<?php echo $post->ID; ?>" data-value="<?php echo strtotime( $startdate ); ?>"><?php echo $startdate; ?></td>
<td class="day_of_week event-<?php echo $post->ID; ?>"><?php espresso_event_date_range( 'l', ' ', 'l', ' ', $event->ID() ); ?></td>
<td class="time event-<?php echo $post->ID; ?>"><?php echo $starttime ; ?></td>
<td class="event_title event-<?php echo $post->ID; ?>"><?php echo $post->post_title; ?></td>
<td style="text-align:center" class="starting_from_pricing event-<?php echo $post->ID; ?>"><?php echo $tickets_price_free_check; ?></td>
<td style="text-align:center" class="td-group reg-col" nowrap="nowrap"><?php echo $live_button; ?></td>
</tr>
<?php
endwhile;
echo '</table>';
// allow moar other stuff
do_action( 'AHEE__espresso_events_table_template_template__after_loop' );
else :
// If no content, include the "No posts found" template.
espresso_get_template_part( 'content', 'none' );
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment