Advertisement
ClanIT

updated code

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