Advertisement
ClanIT

Child theme espresso-events-table-template.template.php

Oct 9th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.42 KB | None | 0 0
  1. <?php
  2. // Options
  3. $date_format = get_option( 'date_format' );
  4. $time_format = get_option( 'time_format' );
  5. // Load Venue View Helper
  6. EE_Registry::instance()->load_helper('Venue_View');
  7. //Defaults
  8. $reg_button_text = !isset($reg_button_text) ? __('Book Now', 'event_espresso') : $reg_button_text;
  9. $alt_button_text = !isset($alt_button_text) ? __('View Details', 'event_espresso') : $alt_button_text;//For alternate registration pages
  10. $sold_out_button_text = !isset($sold_out_button_text) ? __('Sold Out', 'event_espresso') : $sold_out_button_text;//For sold out events
  11. $category_filter_text = !isset($category_filter_text) ? __('Training Course', 'event_espresso') : $category_filter_text;
  12.  
  13.  
  14. if ( have_posts() ) :
  15. // allow other stuff
  16. do_action( 'AHEE__espresso_events_table_template_template__before_loop' );
  17. ?>
  18.  
  19. <?php if ($category_filter != 'false'){ ?>
  20. <p class="category-filter cat-filter-selector">
  21. <label><?php echo $category_filter_text; ?></label>
  22. <select class="" id="ee_filter_category">
  23. <option class="ee_filter_show_all"><?php echo __('Show All', 'event_espresso'); ?></option>
  24. <?php
  25. $taxonomy = array('espresso_event_categories');
  26. $args = array('orderby'=>'name','hide_empty'=>true);
  27. $ee_terms = get_terms($taxonomy, $args);
  28.  
  29. foreach($ee_terms as $term){
  30. echo '<option class="' . $term->slug . '">'. $term->name . '</option>';
  31. }
  32. ?>
  33. </select>
  34. </p>
  35. <?php } ?>
  36. <?php if ($venue_filter != 'false'){ ?>
  37. <p class="category-filter loc-filter-selector">
  38. <label><?php echo 'Location'; ?></label>
  39. <select class="" id="ee_filter_venue">
  40. <option class="ee_filter_venue_show_all"><?php echo __('Show All', 'event_espresso'); ?></option>
  41. <?php
  42. $taxonomy = array('espresso_event_venues');
  43. $args = array('orderby'=>'name','hide_empty'=>true);
  44. $ee_terms = get_terms($taxonomy, $args);
  45. ?>
  46. <?php
  47. while ( have_posts() ) : the_post();
  48. global $post;
  49. $event = EEH_Event_View::get_event();
  50. $venue_city = '';
  51. // get first related venue and convert to CSV string
  52. $venue = $event->venues(array('limit' => 1));
  53. if (is_array($venue) && ! empty($venue)) {
  54. $venue = array_shift($venue);
  55. if ($venue instanceof EE_Venue) {
  56. $venue_city = $venue->city();
  57. }
  58. }
  59. echo'<option value="'. $venue_city .'">'. $venue_city .'</option>';
  60. endwhile;
  61. ?>
  62. </select>
  63. </p>
  64. <?php } ?>
  65.  
  66. <?php if ($footable != 'false' && $table_search != 'false'){ ?>
  67. <p>
  68. <?php echo __('Search:', 'event_espresso'); ?> <input id="filter" type="text"/>
  69. </p>
  70. <?php } ?>
  71.  
  72. <table id="ee_filter_table" class="espresso-table footable table" data-page-size="<?php echo $table_pages; ?>" data-filter="#filter">
  73. <thead class="espresso-table-header-row">
  74. <tr>
  75. <th class="th-group"><?php _e('Event','event_espresso'); ?></th>
  76. <?php if( $show_venues ) { ?>
  77. <th class="th-group"><?php _e('Location','event_espresso'); ?></th>
  78. <?php } ?>
  79. <th class="th-group"><?php _e('Start Date','event_espresso'); ?></th>
  80. <th class="th-group" data-sort-ignore="true"><?php _e('Trainer','event_espresso'); ?></th>
  81. <th class="th-group" data-sort-ignore="true"><?php _e('Price','event_espresso'); ?></th>
  82. <th class="th-group" data-sort-ignore="true"></th>
  83. </tr>
  84. </thead>
  85. <?php if ($footable != 'false' && $table_paging != 'false'){ ?>
  86. <tfoot>
  87. <tr>
  88. <?php echo '<td colspan="' . ($show_venues ? '6' : '5') . '">'; ?>
  89. <div class="pagination pagination-centered"></div>
  90. </tr>
  91. </tfoot>
  92. <?php } ?>
  93. <tbody>
  94.  
  95. <?php
  96. // Start the Loop.
  97. while ( have_posts() ) : the_post();
  98. // Include the post TYPE-specific template for the content.
  99. global $post;
  100.  
  101. //Debug
  102. //d( $post );
  103.  
  104. //Get the category for this event
  105. $event = EEH_Event_View::get_event();
  106. if ( $event instanceof EE_Event ) {
  107. if ( $event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' )) {
  108. // loop thru terms and create links
  109. $category_slugs = array();
  110. foreach ( $event_categories as $term ) {
  111. $category_slugs[] = $term->slug;
  112. }
  113. $category_slugs = implode(' ', $category_slugs);
  114. } else {
  115. // event has no terms
  116. $category_slugs = '';
  117. }
  118. $venue_city = '';
  119. // get first related venue and convert to CSV string
  120. $venue = $event->venues(array('limit' => 1));
  121. if (is_array($venue) && ! empty($venue)) {
  122. $venue = array_shift($venue);
  123. if ($venue instanceof EE_Venue) {
  124. $venue_city = $venue->city();
  125. }
  126. }
  127. }
  128. //Create the event link
  129. $external_url = $post->EE_Event->external_url();
  130. $button_text = !empty($external_url) ? $alt_button_text : $reg_button_text;
  131. $registration_url = !empty($external_url) ? $post->EE_Event->external_url() : $post->EE_Event->get_permalink();
  132.  
  133. //Create the register now button
  134. $live_button = '<a id="a_register_link-'.$post->ID.'" class="a_register_link" href="'.$registration_url.'">'.$button_text.'</a>';
  135.  
  136. if ( $event->is_sold_out() || $event->is_sold_out(TRUE ) ) {
  137. $live_button = '<a id="a_register_link-'.$post->ID.'" class="a_register_link_sold_out a_register_link" href="'.$registration_url.'">'.$sold_out_button_text.'</a>';
  138. }
  139.  
  140. // If the show_all_datetimes parameter is set set the limit to NULL to pull them all,
  141. // if not default to only display a single datetime.
  142. $datetime_limit = $show_all_datetimes ? NULL : 1;
  143.  
  144. // Pull the datetimes for this event order by start_date/time
  145. // $datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, $show_expired, false, $datetime_limit );
  146.  
  147. // Reset the datetimes pointer to the earliest datetime and use that one.
  148. //$datetime = reset( $datetimes );
  149. $datetimes = EEM_Datetime::instance()->get_datetimes_for_event_ordered_by_start_time( $post->ID, $show_expired, false, 1 );
  150.  
  151. $datetime = end( $datetimes );
  152.  
  153. if ( ! $event->is_sold_out() ) {
  154.  
  155. // grab array of EE_Ticket objects for event
  156. $tickets = EEH_Event_View::event_tickets_available( $post->ID );
  157.  
  158. // grab first ticket from array
  159. $ticket = reset( $tickets );
  160. //check if the ticket is free, if set the ticket price to 'Free'
  161. if ( $ticket instanceof EE_Ticket ) {
  162. $ticket_price = $ticket->pretty_price();
  163. $ticket_price_data_value = $ticket->price();
  164. $ticket_price = $ticket_price_data_value == 0 ? __( 'Free', 'event_espresso' ) : $ticket_price;
  165. }
  166.  
  167. //Get the remaining ticket values for the next datetime.
  168. $tickets_remaining = $datetime->tickets_remaining() === EE_INF ? __('Unlimited','event_espresso') : $datetime->tickets_remaining();
  169. } else {
  170.  
  171. //The event is sold out, set the ticket price to 'N/A'
  172. $ticket_price = __( 'N/A', 'event_espresso');
  173. }
  174.  
  175. // Pull trainer for this event
  176. $people = EEM_Person::instance()->get_people_for_event_and_type($event_id = $post->ID, $people_type_id = 24);
  177.  
  178.  
  179.  
  180.  
  181. if ($datetime instanceof EE_Datetime) {
  182. ?>
  183. <tr class="espresso-table-row <?php echo $category_slugs; ?> <?php echo $venue_city; ?>">
  184. <td class="event_title event-<?php echo $post->ID; ?>"><a href="<?php echo $registration_url; ?>"><?php echo $post->post_title; ?></a></td>
  185. <?php if( $show_venues ) { ?>
  186. <td class="venue_title event-<?php echo $post->ID; ?>"><?php echo $venue_city; ?></td>
  187. <?php } ?>
  188. <td class="start_date event-<?php echo $post->ID; ?>" data-value="<?php echo $datetime->get_raw( 'DTT_EVT_start' ); ?>-<?php echo $datetime->get_raw( 'DTT_EVT_end' ); ?>">
  189. <ul class="ee-table-view-datetime-list">
  190. <?php
  191. // Loop over each datetime we have pulled from the database and output
  192. foreach ($datetimes as $datetime) {
  193. $startDateTime = $datetime->get_raw( 'DTT_EVT_start' );
  194. $endDateTime = $datetime->get_raw( 'DTT_EVT_end' );
  195.  
  196. $start = new DateTime();
  197. $start->setTimestamp($startDateTime);
  198.  
  199. $end = new DateTime();
  200. $end->setTimestamp($endDateTime);
  201.  
  202. $interval = $start->diff($end);
  203.  
  204. $intervalInteger = $interval->format('%d');
  205. $intervalInteger += 1;
  206.  
  207.  
  208. ?>
  209. <li class="datetime-id-<?php echo $datetime->ID(); ?>">
  210.  
  211.  
  212. <?php echo date_i18n( $date_format, strtotime( $datetime->start_date_and_time('Y-m-d', 'H:i:s') ) ); ?>
  213. <!-- to <?php echo date_i18n( $date_format, strtotime( $datetime->end_date_and_time('Y-m-d', 'H:i:s') ) ); ?> -->
  214.  
  215. - <?php echo $intervalInteger ?> <?php echo $intervalInteger > 1 ? 'days' : 'day' ?>
  216.  
  217.  
  218.  
  219.  
  220. </li>
  221. <?php
  222. //end foreach $datetimes
  223. }
  224. ?>
  225. </ul>
  226. </td>
  227. <td class="trainer"><?php
  228. // Loop over each datetime we have pulled from the database and output
  229. foreach ($people as $people) {
  230. ?><a href="<?php echo get_permalink( $people->ID() ); ?>" target="_blank"><?php echo $people->full_name(); ?></a><br />
  231. <?php
  232. //end foreach $people
  233. }
  234. ?>
  235. </td>
  236.  
  237. <td class="price"><?php echo $ticket_price; ?>
  238. </td>
  239.  
  240.  
  241. </th>
  242. <td class="td-group reg-col" nowrap="nowrap"><?php echo $live_button; ?></td>
  243. </tr>
  244. <?php
  245. }
  246. endwhile;
  247. echo '</table>';
  248. // allow moar other stuff
  249. do_action( 'AHEE__espresso_events_table_template_template__after_loop' );
  250.  
  251. else :
  252. // If no content, include the "No posts found" template.
  253. espresso_get_template_part( 'content', 'none' );
  254.  
  255. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement