Skip to content

Instantly share code, notes, and snippets.

@mpurse
Last active July 11, 2018 18:10
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 mpurse/a49a1f50fa01a82877f435582bc09a61 to your computer and use it in GitHub Desktop.
Save mpurse/a49a1f50fa01a82877f435582bc09a61 to your computer and use it in GitHub Desktop.
<?php
// Template for table display of events - Ivan
// Load Venue View Helper
EE_Registry::instance()->load_helper('Venue_View');
//Defaults
$button_text = !isset($button_text) ? __('Register', 'event_espresso') : $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' );
?>
<div class="ee-table-overflow">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Start day</th>
<th>Date</th>
<th>Start time</th>
<th>End time</th>
<th>Course name</th>
<th>Course length</th>
<th>Price</th>
<th>Good to Know</th>
<th>Details</th>
<th>Register</th>
</tr>
</thead>
<?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 : $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 id="a_register_link-'.$post->ID.'" class="ee_add_item_to_cart " href="'.$registration_url.'">'.$button_text.'</a>';
if ( $event->is_sold_out() || $event->is_sold_out(TRUE ) ) {
$live_button = '<a id="a_register_link-'.$post->ID.'" class="a_register_link_sold_out" href="'.$registration_url.'">'.$sold_out_button_text.'</a>';
}
//Get the first datetime that's not expired
$datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, false, false, 1 );
foreach ( $datetimes as $datetime ) {
$startdat = $datetime->start_date_and_time();
}
// Get just the date for event
$day = explode(' ', espresso_event_date('D', '', false, false));
$date = explode(' ', espresso_event_date('d/m/Y', 'H:i', false, false));
$end = explode(' ', espresso_event_end_date('d/m/Y', 'H:i', false, false));
/*$event = EEH_Event_View::get_event( $EVT_ID );
$tickets_available_for_purchase = array();
if( $event instanceof EE_Event ) {
$datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, FALSE );
foreach( $datetimes as $datetime ) {
$tickets_available_for_purchase = array_merge( $tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase() );
}
}*/
/*foreach ( $datetimes as $datetime ) {
$startdat = $datetime->start_date_and_time();
}*/
// grab array of EE_Ticket objects for event
$tickets = espresso_event_tickets_available( $post->ID, FALSE, FALSE );
// grab first ticket from array
$ticket = array_shift( $tickets );
$ticket_price = $ticket instanceof EE_Ticket ? $ticket->pretty_price() : '';
$ticket_price_data_value = $ticket instanceof EE_Ticket ? $ticket->price() : '';
$event_id = $post->ID;
?>
<tr class="espresso-table-row <?php echo $category_slugs; ?>">
<!-- Start day -->
<td id="event_time-<?php echo $event_id ?>"> <?php echo $day[0]; ?> </td>
<!-- Start date -->
<td id="event_time-<?php echo $event_id ?>"> <?php echo $date[0]; ?> </td>
<!-- Start time -->
<td id="event_time-<?php echo $event_id ?>"> <?php echo $date[1]; ?> </td>
<!-- End time -->
<td id="event_time-<?php echo $event_id ?>"> <?php echo $end[1]; ?> </td>
<!-- Title -->
<td class="event_title event-<?php echo $post->ID; ?>"><a href="<?php the_permalink(); ?>" class="a_event_title"><?php echo $post->post_title; ?></a></td>
<!-- Course lenght -->
<td class="venue_title event-<?php echo $post->ID; ?>"><?php echo do_shortcode('[EE_META type="event_meta" name="course_length"]'); ?></td>
<!-- Price -->
<td id="p_event_price-<?php echo $event_id ?>" class="event_price"><?php
$display_price_meta = do_shortcode('[EE_META type="event_meta" name="display_price"]');
if( $display_price_meta ){
echo $display_price_meta;
} elseif($ticket_price_data_value != '') {
echo "£".$ticket_price_data_value;
}
?></td>
<!-- Good to Know -->
<td id="p_event_len-<?php echo $event_id ?>" class="event_len"><?php echo do_shortcode('[EE_META type="event_meta" name="comments"]'); ?></td>
<!-- Details -->
<td class="event_title td-group reg-col" nowrap="nowrap"><a href="<?php the_permalink(); ?>" class="a_event_title">Details</a></td>
<!-- Register -->
<td class="td-group reg-col" nowrap="nowrap"><?php //espresso_ticket_selector( $post ); ?><?php echo $live_button; ?></td>
</tr>
<?php
endwhile;
echo '</table></div>';
// 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