@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | use EEM_Ticket; |
| 16 | 16 | use WP_Post; |
| 17 | 17 | |
| 18 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 19 | - exit( 'No direct script access allowed' ); |
|
| 18 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 19 | + exit('No direct script access allowed'); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -87,9 +87,9 @@ discard block |
||
| 87 | 87 | /** |
| 88 | 88 | * @param boolean $iframe |
| 89 | 89 | */ |
| 90 | - public function setIframe( $iframe = true ) |
|
| 90 | + public function setIframe($iframe = true) |
|
| 91 | 91 | { |
| 92 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
| 92 | + $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
@@ -100,28 +100,28 @@ discard block |
||
| 100 | 100 | * @return bool |
| 101 | 101 | * @throws EE_Error |
| 102 | 102 | */ |
| 103 | - protected function setEvent( $event = null ) |
|
| 103 | + protected function setEvent($event = null) |
|
| 104 | 104 | { |
| 105 | - if ( $event === null ) { |
|
| 105 | + if ($event === null) { |
|
| 106 | 106 | global $post; |
| 107 | 107 | $event = $post; |
| 108 | 108 | } |
| 109 | - if ( $event instanceof EE_Event ) { |
|
| 109 | + if ($event instanceof EE_Event) { |
|
| 110 | 110 | $this->event = $event; |
| 111 | - } else if ( $event instanceof WP_Post ) { |
|
| 112 | - if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
| 111 | + } else if ($event instanceof WP_Post) { |
|
| 112 | + if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
| 113 | 113 | $this->event = $event->EE_Event; |
| 114 | - } else if ( $event->post_type === 'espresso_events' ) { |
|
| 115 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
| 114 | + } else if ($event->post_type === 'espresso_events') { |
|
| 115 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
| 116 | 116 | $this->event = $event->EE_Event; |
| 117 | 117 | } |
| 118 | 118 | } else { |
| 119 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
| 120 | - $dev_msg = $user_msg . __( |
|
| 119 | + $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
| 120 | + $dev_msg = $user_msg.__( |
|
| 121 | 121 | 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
| 122 | 122 | 'event_espresso' |
| 123 | 123 | ); |
| 124 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 124 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 125 | 125 | return false; |
| 126 | 126 | } |
| 127 | 127 | return true; |
@@ -162,17 +162,17 @@ discard block |
||
| 162 | 162 | * @return string |
| 163 | 163 | * @throws EE_Error |
| 164 | 164 | */ |
| 165 | - public function display( $event = null, $view_details = false ) |
|
| 165 | + public function display($event = null, $view_details = false) |
|
| 166 | 166 | { |
| 167 | 167 | // reset filter for displaying submit button |
| 168 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
| 168 | + remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 169 | 169 | // poke and prod incoming event till it tells us what it is |
| 170 | - if ( ! $this->setEvent( $event ) ) { |
|
| 170 | + if ( ! $this->setEvent($event)) { |
|
| 171 | 171 | return false; |
| 172 | 172 | } |
| 173 | 173 | // begin gathering template arguments by getting event status |
| 174 | - $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
| 175 | - if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
| 174 | + $template_args = array('event_status' => $this->event->get_active_status()); |
|
| 175 | + if ($this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details)) { |
|
| 176 | 176 | return ! is_single() ? $this->displayViewDetailsButton() : ''; |
| 177 | 177 | } |
| 178 | 178 | // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | // is the event expired ? |
| 184 | 184 | $template_args['event_is_expired'] = $this->event->is_expired(); |
| 185 | - if ( $template_args[ 'event_is_expired' ] ) { |
|
| 185 | + if ($template_args['event_is_expired']) { |
|
| 186 | 186 | return $this->expiredEventMessage(); |
| 187 | 187 | } |
| 188 | 188 | // get all tickets for this event ordered by the datetime |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | if (count($tickets) < 1) { |
| 191 | 191 | return $this->noTicketAvailableMessage(); |
| 192 | 192 | } |
| 193 | - if (EED_Events_Archive::is_iframe()){ |
|
| 193 | + if (EED_Events_Archive::is_iframe()) { |
|
| 194 | 194 | $this->setIframe(); |
| 195 | 195 | } |
| 196 | 196 | // redirecting to another site for registration ?? |
@@ -198,10 +198,10 @@ discard block |
||
| 198 | 198 | // if redirecting to another site for registration, then we don't load the TS |
| 199 | 199 | $ticket_selector = $external_url |
| 200 | 200 | ? $this->externalEventRegistration() |
| 201 | - : $this->loadTicketSelector($tickets,$template_args); |
|
| 201 | + : $this->loadTicketSelector($tickets, $template_args); |
|
| 202 | 202 | // now set up the form (but not for the admin) |
| 203 | 203 | $ticket_selector = ! is_admin() |
| 204 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
| 204 | + ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector |
|
| 205 | 205 | : $ticket_selector; |
| 206 | 206 | // submit button and form close tag |
| 207 | 207 | $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : ''; |
@@ -251,10 +251,10 @@ discard block |
||
| 251 | 251 | */ |
| 252 | 252 | protected function expiredEventMessage() |
| 253 | 253 | { |
| 254 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
| 254 | + return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__( |
|
| 255 | 255 | 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
| 256 | 256 | 'event_espresso' |
| 257 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
| 257 | + ).'</span></div><!-- .ee-event-expired-notice -->'; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | */ |
| 269 | 269 | protected function noTicketAvailableMessage() |
| 270 | 270 | { |
| 271 | - $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
| 271 | + $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); |
|
| 272 | 272 | if (current_user_can('edit_post', $this->event->ID())) { |
| 273 | 273 | $no_ticket_available_msg .= sprintf( |
| 274 | 274 | esc_html__( |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | } |
| 284 | 284 | return ' |
| 285 | 285 | <div class="ee-event-expired-notice"> |
| 286 | - <span class="important-notice">' . $no_ticket_available_msg . '</span> |
|
| 286 | + <span class="important-notice">' . $no_ticket_available_msg.'</span> |
|
| 287 | 287 | </div><!-- .ee-event-expired-notice -->'; |
| 288 | 288 | } |
| 289 | 289 | |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
| 315 | 315 | ); |
| 316 | 316 | } |
| 317 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
| 317 | + return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>'; |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | |
@@ -376,12 +376,12 @@ discard block |
||
| 376 | 376 | */ |
| 377 | 377 | $template_args['anchor_id'] = apply_filters( |
| 378 | 378 | 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
| 379 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
| 379 | + '#tkt-slctr-tbl-'.$this->event->ID(), |
|
| 380 | 380 | $this->event->ID() |
| 381 | 381 | ); |
| 382 | 382 | $template_args['tickets'] = $tickets; |
| 383 | 383 | $template_args['ticket_count'] = count($tickets); |
| 384 | - $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
| 384 | + $ticket_selector = $this->simpleTicketSelector($tickets, $template_args); |
|
| 385 | 385 | return $ticket_selector instanceof TicketSelectorSimple |
| 386 | 386 | ? $ticket_selector |
| 387 | 387 | : new TicketSelectorStandard( |
@@ -462,11 +462,11 @@ discard block |
||
| 462 | 462 | * @param string $external_url |
| 463 | 463 | * @return string |
| 464 | 464 | */ |
| 465 | - public function formOpen( $ID = 0, $external_url = '' ) |
|
| 465 | + public function formOpen($ID = 0, $external_url = '') |
|
| 466 | 466 | { |
| 467 | 467 | // if redirecting, we don't need any anything else |
| 468 | - if ( $external_url ) { |
|
| 469 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
| 468 | + if ($external_url) { |
|
| 469 | + $html = '<form method="GET" action="'.EEH_URL::refactor_url($external_url).'"'; |
|
| 470 | 470 | // open link in new window ? |
| 471 | 471 | $html .= apply_filters( |
| 472 | 472 | 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
@@ -475,21 +475,21 @@ discard block |
||
| 475 | 475 | ? ' target="_blank"' |
| 476 | 476 | : ''; |
| 477 | 477 | $html .= '>'; |
| 478 | - $query_args = EEH_URL::get_query_string( $external_url ); |
|
| 479 | - foreach ( (array)$query_args as $query_arg => $value ) { |
|
| 480 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
| 478 | + $query_args = EEH_URL::get_query_string($external_url); |
|
| 479 | + foreach ((array) $query_args as $query_arg => $value) { |
|
| 480 | + $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">'; |
|
| 481 | 481 | } |
| 482 | 482 | return $html; |
| 483 | 483 | } |
| 484 | 484 | // if there is no submit button, then don't start building a form |
| 485 | 485 | // because the "View Details" button will build its own form |
| 486 | - if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
| 486 | + if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 487 | 487 | return ''; |
| 488 | 488 | } |
| 489 | - $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
| 490 | - if ( ! $checkout_url ) { |
|
| 489 | + $checkout_url = EEH_Event_View::event_link_url($ID); |
|
| 490 | + if ( ! $checkout_url) { |
|
| 491 | 491 | EE_Error::add_error( |
| 492 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 492 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
| 493 | 493 | __FILE__, |
| 494 | 494 | __FUNCTION__, |
| 495 | 495 | __LINE__ |
@@ -498,9 +498,9 @@ discard block |
||
| 498 | 498 | // set no cache headers and constants |
| 499 | 499 | EE_System::do_not_cache(); |
| 500 | 500 | $extra_params = $this->iframe ? ' target="_blank"' : ''; |
| 501 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
| 501 | + $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>'; |
|
| 502 | 502 | $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
| 503 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
| 503 | + $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
| 504 | 504 | return $html; |
| 505 | 505 | } |
| 506 | 506 | |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | $html .= empty($external_url) |
| 524 | 524 | ? $this->ticketSelectorEndDiv() |
| 525 | 525 | : $this->clearTicketSelector(); |
| 526 | - $html .= '<br/>' . $this->formClose(); |
|
| 526 | + $html .= '<br/>'.$this->formClose(); |
|
| 527 | 527 | } else if ($this->getMaxAttendees() === 1) { |
| 528 | 528 | // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
| 529 | 529 | if ($this->event->is_sold_out()) { |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | $html .= $this->displayRegisterNowButton(); |
| 553 | 553 | } |
| 554 | 554 | // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
| 555 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 555 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 556 | 556 | } else if ( |
| 557 | 557 | apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
| 558 | 558 | && ! is_single() |
@@ -603,13 +603,13 @@ discard block |
||
| 603 | 603 | ); |
| 604 | 604 | $external_url = $this->event->external_url(); |
| 605 | 605 | $html = EEH_HTML::div( |
| 606 | - '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
| 606 | + '', 'ticket-selector-submit-'.$this->event->ID().'-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
| 607 | 607 | ); |
| 608 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
| 608 | + $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"'; |
|
| 609 | 609 | $html .= ' class="ticket-selector-submit-btn '; |
| 610 | 610 | $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
| 611 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
| 612 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
| 611 | + $html .= ' type="submit" value="'.$btn_text.'" />'; |
|
| 612 | + $html .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->'; |
|
| 613 | 613 | $html .= apply_filters( |
| 614 | 614 | 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
| 615 | 615 | '', |
@@ -629,11 +629,11 @@ discard block |
||
| 629 | 629 | * @return string |
| 630 | 630 | * @throws EE_Error |
| 631 | 631 | */ |
| 632 | - public function displayViewDetailsButton( $DWMTS = false ) |
|
| 632 | + public function displayViewDetailsButton($DWMTS = false) |
|
| 633 | 633 | { |
| 634 | - if ( ! $this->event->get_permalink() ) { |
|
| 634 | + if ( ! $this->event->get_permalink()) { |
|
| 635 | 635 | EE_Error::add_error( |
| 636 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 636 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
| 637 | 637 | __FILE__, __FUNCTION__, __LINE__ |
| 638 | 638 | ); |
| 639 | 639 | } |
@@ -651,7 +651,7 @@ discard block |
||
| 651 | 651 | ) |
| 652 | 652 | ? ' target="_blank"' |
| 653 | 653 | : ''; |
| 654 | - $view_details_btn .='>'; |
|
| 654 | + $view_details_btn .= '>'; |
|
| 655 | 655 | $btn_text = apply_filters( |
| 656 | 656 | 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
| 657 | 657 | esc_html__('View Details', 'event_espresso'), |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
| 663 | 663 | . $btn_text |
| 664 | 664 | . '" />'; |
| 665 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
| 665 | + $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
| 666 | 666 | if ($DWMTS) { |
| 667 | 667 | $view_details_btn .= $this->formClose(); |
| 668 | 668 | $view_details_btn .= $this->ticketSelectorEndDiv(); |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | */ |
| 683 | 683 | public function ticketSelectorEndDiv() |
| 684 | 684 | { |
| 685 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
| 685 | + return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->'; |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | use WP_Post; |
| 17 | 17 | |
| 18 | 18 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
| 19 | - exit( 'No direct script access allowed' ); |
|
| 19 | + exit( 'No direct script access allowed' ); |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -33,683 +33,683 @@ discard block |
||
| 33 | 33 | class DisplayTicketSelector |
| 34 | 34 | { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * event that ticket selector is being generated for |
|
| 38 | - * |
|
| 39 | - * @access protected |
|
| 40 | - * @var EE_Event $event |
|
| 41 | - */ |
|
| 42 | - protected $event; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Used to flag when the ticket selector is being called from an external iframe. |
|
| 46 | - * |
|
| 47 | - * @var bool $iframe |
|
| 48 | - */ |
|
| 49 | - protected $iframe = false; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * max attendees that can register for event at one time |
|
| 53 | - * |
|
| 54 | - * @var int $max_attendees |
|
| 55 | - */ |
|
| 56 | - private $max_attendees = EE_INF; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - *@var string $date_format |
|
| 60 | - */ |
|
| 61 | - private $date_format; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - *@var string $time_format |
|
| 65 | - */ |
|
| 66 | - private $time_format; |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * DisplayTicketSelector constructor. |
|
| 72 | - */ |
|
| 73 | - public function __construct() |
|
| 74 | - { |
|
| 75 | - $this->date_format = apply_filters( |
|
| 76 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
| 77 | - get_option('date_format') |
|
| 78 | - ); |
|
| 79 | - $this->time_format = apply_filters( |
|
| 80 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
| 81 | - get_option('time_format') |
|
| 82 | - ); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param boolean $iframe |
|
| 89 | - */ |
|
| 90 | - public function setIframe( $iframe = true ) |
|
| 91 | - { |
|
| 92 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * finds and sets the \EE_Event object for use throughout class |
|
| 98 | - * |
|
| 99 | - * @param mixed $event |
|
| 100 | - * @return bool |
|
| 101 | - * @throws EE_Error |
|
| 102 | - */ |
|
| 103 | - protected function setEvent( $event = null ) |
|
| 104 | - { |
|
| 105 | - if ( $event === null ) { |
|
| 106 | - global $post; |
|
| 107 | - $event = $post; |
|
| 108 | - } |
|
| 109 | - if ( $event instanceof EE_Event ) { |
|
| 110 | - $this->event = $event; |
|
| 111 | - } else if ( $event instanceof WP_Post ) { |
|
| 112 | - if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
| 113 | - $this->event = $event->EE_Event; |
|
| 114 | - } else if ( $event->post_type === 'espresso_events' ) { |
|
| 115 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
| 116 | - $this->event = $event->EE_Event; |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
| 120 | - $dev_msg = $user_msg . __( |
|
| 121 | - 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
| 122 | - 'event_espresso' |
|
| 123 | - ); |
|
| 124 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 125 | - return false; |
|
| 126 | - } |
|
| 127 | - return true; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @return int |
|
| 134 | - */ |
|
| 135 | - public function getMaxAttendees() |
|
| 136 | - { |
|
| 137 | - return $this->max_attendees; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param int $max_attendees |
|
| 144 | - */ |
|
| 145 | - public function setMaxAttendees($max_attendees) |
|
| 146 | - { |
|
| 147 | - $this->max_attendees = absint( |
|
| 148 | - apply_filters( |
|
| 149 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
| 150 | - $max_attendees |
|
| 151 | - ) |
|
| 152 | - ); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * creates buttons for selecting number of attendees for an event |
|
| 159 | - * |
|
| 160 | - * @param WP_Post|int $event |
|
| 161 | - * @param bool $view_details |
|
| 162 | - * @return string |
|
| 163 | - * @throws EE_Error |
|
| 164 | - */ |
|
| 165 | - public function display( $event = null, $view_details = false ) |
|
| 166 | - { |
|
| 167 | - // reset filter for displaying submit button |
|
| 168 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
| 169 | - // poke and prod incoming event till it tells us what it is |
|
| 170 | - if ( ! $this->setEvent( $event ) ) { |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - // begin gathering template arguments by getting event status |
|
| 174 | - $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
| 175 | - if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
| 176 | - return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
| 177 | - } |
|
| 178 | - // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
| 179 | - $this->setMaxAttendees($this->event->additional_limit()); |
|
| 180 | - if ($this->getMaxAttendees() < 1) { |
|
| 181 | - return $this->ticketSalesClosedMessage(); |
|
| 182 | - } |
|
| 183 | - // is the event expired ? |
|
| 184 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
| 185 | - if ( $template_args[ 'event_is_expired' ] ) { |
|
| 186 | - return $this->expiredEventMessage(); |
|
| 187 | - } |
|
| 188 | - // get all tickets for this event ordered by the datetime |
|
| 189 | - $tickets = $this->getTickets(); |
|
| 190 | - if (count($tickets) < 1) { |
|
| 191 | - return $this->noTicketAvailableMessage(); |
|
| 192 | - } |
|
| 193 | - if (EED_Events_Archive::is_iframe()){ |
|
| 194 | - $this->setIframe(); |
|
| 195 | - } |
|
| 196 | - // redirecting to another site for registration ?? |
|
| 197 | - $external_url = (string) $this->event->external_url(); |
|
| 198 | - // if redirecting to another site for registration, then we don't load the TS |
|
| 199 | - $ticket_selector = $external_url |
|
| 200 | - ? $this->externalEventRegistration() |
|
| 201 | - : $this->loadTicketSelector($tickets,$template_args); |
|
| 202 | - // now set up the form (but not for the admin) |
|
| 203 | - $ticket_selector = ! is_admin() |
|
| 204 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
| 205 | - : $ticket_selector; |
|
| 206 | - // submit button and form close tag |
|
| 207 | - $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : ''; |
|
| 208 | - return $ticket_selector; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * displayTicketSelector |
|
| 215 | - * examines the event properties and determines whether a Ticket Selector should be displayed |
|
| 216 | - * |
|
| 217 | - * @param WP_Post|int $event |
|
| 218 | - * @param string $_event_active_status |
|
| 219 | - * @param bool $view_details |
|
| 220 | - * @return bool |
|
| 221 | - * @throws EE_Error |
|
| 222 | - */ |
|
| 223 | - protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
| 224 | - { |
|
| 225 | - $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
| 226 | - return ! is_admin() |
|
| 227 | - && ( |
|
| 228 | - ! $this->event->display_ticket_selector() |
|
| 229 | - || $view_details |
|
| 230 | - || post_password_required($event_post) |
|
| 231 | - || ( |
|
| 232 | - $_event_active_status !== EE_Datetime::active |
|
| 233 | - && $_event_active_status !== EE_Datetime::upcoming |
|
| 234 | - && $_event_active_status !== EE_Datetime::sold_out |
|
| 235 | - && ! ( |
|
| 236 | - $_event_active_status === EE_Datetime::inactive |
|
| 237 | - && is_user_logged_in() |
|
| 238 | - ) |
|
| 239 | - ) |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * noTicketAvailableMessage |
|
| 247 | - * notice displayed if event is expired |
|
| 248 | - * |
|
| 249 | - * @return string |
|
| 250 | - * @throws EE_Error |
|
| 251 | - */ |
|
| 252 | - protected function expiredEventMessage() |
|
| 253 | - { |
|
| 254 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
| 255 | - 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
| 256 | - 'event_espresso' |
|
| 257 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * noTicketAvailableMessage |
|
| 264 | - * notice displayed if event has no more tickets available |
|
| 265 | - * |
|
| 266 | - * @return string |
|
| 267 | - * @throws EE_Error |
|
| 268 | - */ |
|
| 269 | - protected function noTicketAvailableMessage() |
|
| 270 | - { |
|
| 271 | - $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
| 272 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
| 273 | - $no_ticket_available_msg .= sprintf( |
|
| 274 | - esc_html__( |
|
| 275 | - '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
| 276 | - 'event_espresso' |
|
| 277 | - ), |
|
| 278 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 279 | - '</b><br />', |
|
| 280 | - '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
| 281 | - '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
| 282 | - ); |
|
| 283 | - } |
|
| 284 | - return ' |
|
| 36 | + /** |
|
| 37 | + * event that ticket selector is being generated for |
|
| 38 | + * |
|
| 39 | + * @access protected |
|
| 40 | + * @var EE_Event $event |
|
| 41 | + */ |
|
| 42 | + protected $event; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Used to flag when the ticket selector is being called from an external iframe. |
|
| 46 | + * |
|
| 47 | + * @var bool $iframe |
|
| 48 | + */ |
|
| 49 | + protected $iframe = false; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * max attendees that can register for event at one time |
|
| 53 | + * |
|
| 54 | + * @var int $max_attendees |
|
| 55 | + */ |
|
| 56 | + private $max_attendees = EE_INF; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + *@var string $date_format |
|
| 60 | + */ |
|
| 61 | + private $date_format; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + *@var string $time_format |
|
| 65 | + */ |
|
| 66 | + private $time_format; |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * DisplayTicketSelector constructor. |
|
| 72 | + */ |
|
| 73 | + public function __construct() |
|
| 74 | + { |
|
| 75 | + $this->date_format = apply_filters( |
|
| 76 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
| 77 | + get_option('date_format') |
|
| 78 | + ); |
|
| 79 | + $this->time_format = apply_filters( |
|
| 80 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
| 81 | + get_option('time_format') |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param boolean $iframe |
|
| 89 | + */ |
|
| 90 | + public function setIframe( $iframe = true ) |
|
| 91 | + { |
|
| 92 | + $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * finds and sets the \EE_Event object for use throughout class |
|
| 98 | + * |
|
| 99 | + * @param mixed $event |
|
| 100 | + * @return bool |
|
| 101 | + * @throws EE_Error |
|
| 102 | + */ |
|
| 103 | + protected function setEvent( $event = null ) |
|
| 104 | + { |
|
| 105 | + if ( $event === null ) { |
|
| 106 | + global $post; |
|
| 107 | + $event = $post; |
|
| 108 | + } |
|
| 109 | + if ( $event instanceof EE_Event ) { |
|
| 110 | + $this->event = $event; |
|
| 111 | + } else if ( $event instanceof WP_Post ) { |
|
| 112 | + if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
| 113 | + $this->event = $event->EE_Event; |
|
| 114 | + } else if ( $event->post_type === 'espresso_events' ) { |
|
| 115 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
| 116 | + $this->event = $event->EE_Event; |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
| 120 | + $dev_msg = $user_msg . __( |
|
| 121 | + 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
| 122 | + 'event_espresso' |
|
| 123 | + ); |
|
| 124 | + EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 127 | + return true; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @return int |
|
| 134 | + */ |
|
| 135 | + public function getMaxAttendees() |
|
| 136 | + { |
|
| 137 | + return $this->max_attendees; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param int $max_attendees |
|
| 144 | + */ |
|
| 145 | + public function setMaxAttendees($max_attendees) |
|
| 146 | + { |
|
| 147 | + $this->max_attendees = absint( |
|
| 148 | + apply_filters( |
|
| 149 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
| 150 | + $max_attendees |
|
| 151 | + ) |
|
| 152 | + ); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * creates buttons for selecting number of attendees for an event |
|
| 159 | + * |
|
| 160 | + * @param WP_Post|int $event |
|
| 161 | + * @param bool $view_details |
|
| 162 | + * @return string |
|
| 163 | + * @throws EE_Error |
|
| 164 | + */ |
|
| 165 | + public function display( $event = null, $view_details = false ) |
|
| 166 | + { |
|
| 167 | + // reset filter for displaying submit button |
|
| 168 | + remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
| 169 | + // poke and prod incoming event till it tells us what it is |
|
| 170 | + if ( ! $this->setEvent( $event ) ) { |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + // begin gathering template arguments by getting event status |
|
| 174 | + $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
| 175 | + if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
| 176 | + return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
| 177 | + } |
|
| 178 | + // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
| 179 | + $this->setMaxAttendees($this->event->additional_limit()); |
|
| 180 | + if ($this->getMaxAttendees() < 1) { |
|
| 181 | + return $this->ticketSalesClosedMessage(); |
|
| 182 | + } |
|
| 183 | + // is the event expired ? |
|
| 184 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
| 185 | + if ( $template_args[ 'event_is_expired' ] ) { |
|
| 186 | + return $this->expiredEventMessage(); |
|
| 187 | + } |
|
| 188 | + // get all tickets for this event ordered by the datetime |
|
| 189 | + $tickets = $this->getTickets(); |
|
| 190 | + if (count($tickets) < 1) { |
|
| 191 | + return $this->noTicketAvailableMessage(); |
|
| 192 | + } |
|
| 193 | + if (EED_Events_Archive::is_iframe()){ |
|
| 194 | + $this->setIframe(); |
|
| 195 | + } |
|
| 196 | + // redirecting to another site for registration ?? |
|
| 197 | + $external_url = (string) $this->event->external_url(); |
|
| 198 | + // if redirecting to another site for registration, then we don't load the TS |
|
| 199 | + $ticket_selector = $external_url |
|
| 200 | + ? $this->externalEventRegistration() |
|
| 201 | + : $this->loadTicketSelector($tickets,$template_args); |
|
| 202 | + // now set up the form (but not for the admin) |
|
| 203 | + $ticket_selector = ! is_admin() |
|
| 204 | + ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
| 205 | + : $ticket_selector; |
|
| 206 | + // submit button and form close tag |
|
| 207 | + $ticket_selector .= ! is_admin() ? $this->displaySubmitButton($external_url) : ''; |
|
| 208 | + return $ticket_selector; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * displayTicketSelector |
|
| 215 | + * examines the event properties and determines whether a Ticket Selector should be displayed |
|
| 216 | + * |
|
| 217 | + * @param WP_Post|int $event |
|
| 218 | + * @param string $_event_active_status |
|
| 219 | + * @param bool $view_details |
|
| 220 | + * @return bool |
|
| 221 | + * @throws EE_Error |
|
| 222 | + */ |
|
| 223 | + protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
| 224 | + { |
|
| 225 | + $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
| 226 | + return ! is_admin() |
|
| 227 | + && ( |
|
| 228 | + ! $this->event->display_ticket_selector() |
|
| 229 | + || $view_details |
|
| 230 | + || post_password_required($event_post) |
|
| 231 | + || ( |
|
| 232 | + $_event_active_status !== EE_Datetime::active |
|
| 233 | + && $_event_active_status !== EE_Datetime::upcoming |
|
| 234 | + && $_event_active_status !== EE_Datetime::sold_out |
|
| 235 | + && ! ( |
|
| 236 | + $_event_active_status === EE_Datetime::inactive |
|
| 237 | + && is_user_logged_in() |
|
| 238 | + ) |
|
| 239 | + ) |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * noTicketAvailableMessage |
|
| 247 | + * notice displayed if event is expired |
|
| 248 | + * |
|
| 249 | + * @return string |
|
| 250 | + * @throws EE_Error |
|
| 251 | + */ |
|
| 252 | + protected function expiredEventMessage() |
|
| 253 | + { |
|
| 254 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
| 255 | + 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
| 256 | + 'event_espresso' |
|
| 257 | + ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * noTicketAvailableMessage |
|
| 264 | + * notice displayed if event has no more tickets available |
|
| 265 | + * |
|
| 266 | + * @return string |
|
| 267 | + * @throws EE_Error |
|
| 268 | + */ |
|
| 269 | + protected function noTicketAvailableMessage() |
|
| 270 | + { |
|
| 271 | + $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
| 272 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
| 273 | + $no_ticket_available_msg .= sprintf( |
|
| 274 | + esc_html__( |
|
| 275 | + '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
| 276 | + 'event_espresso' |
|
| 277 | + ), |
|
| 278 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 279 | + '</b><br />', |
|
| 280 | + '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
| 281 | + '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
| 282 | + ); |
|
| 283 | + } |
|
| 284 | + return ' |
|
| 285 | 285 | <div class="ee-event-expired-notice"> |
| 286 | 286 | <span class="important-notice">' . $no_ticket_available_msg . '</span> |
| 287 | 287 | </div><!-- .ee-event-expired-notice -->'; |
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * ticketSalesClosed |
|
| 294 | - * notice displayed if event ticket sales are turned off |
|
| 295 | - * |
|
| 296 | - * @return string |
|
| 297 | - * @throws EE_Error |
|
| 298 | - */ |
|
| 299 | - protected function ticketSalesClosedMessage() |
|
| 300 | - { |
|
| 301 | - $sales_closed_msg = esc_html__( |
|
| 302 | - 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
| 303 | - 'event_espresso' |
|
| 304 | - ); |
|
| 305 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
| 306 | - $sales_closed_msg .= sprintf( |
|
| 307 | - esc_html__( |
|
| 308 | - '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
| 309 | - 'event_espresso' |
|
| 310 | - ), |
|
| 311 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 312 | - '</b><br />', |
|
| 313 | - '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
| 314 | - '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
| 315 | - ); |
|
| 316 | - } |
|
| 317 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * getTickets |
|
| 324 | - * |
|
| 325 | - * @return \EE_Base_Class[]|\EE_Ticket[] |
|
| 326 | - * @throws EE_Error |
|
| 327 | - */ |
|
| 328 | - protected function getTickets() |
|
| 329 | - { |
|
| 330 | - $ticket_query_args = array( |
|
| 331 | - array('Datetime.EVT_ID' => $this->event->ID()), |
|
| 332 | - 'order_by' => array( |
|
| 333 | - 'TKT_order' => 'ASC', |
|
| 334 | - 'TKT_required' => 'DESC', |
|
| 335 | - 'TKT_start_date' => 'ASC', |
|
| 336 | - 'TKT_end_date' => 'ASC', |
|
| 337 | - 'Datetime.DTT_EVT_start' => 'DESC', |
|
| 338 | - ), |
|
| 339 | - ); |
|
| 340 | - if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) { |
|
| 341 | - //use the correct applicable time query depending on what version of core is being run. |
|
| 342 | - $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
| 343 | - ? time() |
|
| 344 | - : current_time('timestamp'); |
|
| 345 | - $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
| 346 | - } |
|
| 347 | - return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * loadTicketSelector |
|
| 354 | - * begins to assemble template arguments |
|
| 355 | - * and decides whether to load a "simple" ticket selector, or the standard |
|
| 356 | - * |
|
| 357 | - * @param \EE_Ticket[] $tickets |
|
| 358 | - * @param array $template_args |
|
| 359 | - * @return string |
|
| 360 | - * @throws EE_Error |
|
| 361 | - */ |
|
| 362 | - protected function loadTicketSelector(array $tickets, array $template_args) |
|
| 363 | - { |
|
| 364 | - $template_args['event'] = $this->event; |
|
| 365 | - $template_args['EVT_ID'] = $this->event->ID(); |
|
| 366 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
| 367 | - $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
| 368 | - $template_args['date_format'] = $this->date_format; |
|
| 369 | - $template_args['time_format'] = $this->time_format; |
|
| 370 | - /** |
|
| 371 | - * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
| 372 | - * |
|
| 373 | - * @since 4.9.13 |
|
| 374 | - * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
| 375 | - * @param int $EVT_ID The Event ID |
|
| 376 | - */ |
|
| 377 | - $template_args['anchor_id'] = apply_filters( |
|
| 378 | - 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
| 379 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
| 380 | - $this->event->ID() |
|
| 381 | - ); |
|
| 382 | - $template_args['tickets'] = $tickets; |
|
| 383 | - $template_args['ticket_count'] = count($tickets); |
|
| 384 | - $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
| 385 | - return $ticket_selector instanceof TicketSelectorSimple |
|
| 386 | - ? $ticket_selector |
|
| 387 | - : new TicketSelectorStandard( |
|
| 388 | - $this->event, |
|
| 389 | - $tickets, |
|
| 390 | - $this->getMaxAttendees(), |
|
| 391 | - $template_args, |
|
| 392 | - $this->date_format, |
|
| 393 | - $this->time_format |
|
| 394 | - ); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * simpleTicketSelector |
|
| 401 | - * there's one ticket, and max attendees is set to one, |
|
| 402 | - * so if the event is free, then this is a "simple" ticket selector |
|
| 403 | - * a.k.a. "Dude Where's my Ticket Selector?" |
|
| 404 | - * |
|
| 405 | - * @param \EE_Ticket[] $tickets |
|
| 406 | - * @param array $template_args |
|
| 407 | - * @return string |
|
| 408 | - * @throws EE_Error |
|
| 409 | - */ |
|
| 410 | - protected function simpleTicketSelector($tickets, array $template_args) |
|
| 411 | - { |
|
| 412 | - // if there is only ONE ticket with a max qty of ONE |
|
| 413 | - if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
| 414 | - return ''; |
|
| 415 | - } |
|
| 416 | - /** @var \EE_Ticket $ticket */ |
|
| 417 | - $ticket = reset($tickets); |
|
| 418 | - // if the ticket is free... then not much need for the ticket selector |
|
| 419 | - if ( |
|
| 420 | - apply_filters( |
|
| 421 | - 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
| 422 | - $ticket->is_free(), |
|
| 423 | - $this->event->ID() |
|
| 424 | - ) |
|
| 425 | - ) { |
|
| 426 | - return new TicketSelectorSimple( |
|
| 427 | - $this->event, |
|
| 428 | - $ticket, |
|
| 429 | - $this->getMaxAttendees(), |
|
| 430 | - $template_args |
|
| 431 | - ); |
|
| 432 | - } |
|
| 433 | - return ''; |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * externalEventRegistration |
|
| 440 | - * |
|
| 441 | - * @return string |
|
| 442 | - */ |
|
| 443 | - public function externalEventRegistration() |
|
| 444 | - { |
|
| 445 | - // if not we still need to trigger the display of the submit button |
|
| 446 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 447 | - //display notice to admin that registration is external |
|
| 448 | - return is_admin() |
|
| 449 | - ? esc_html__( |
|
| 450 | - 'Registration is at an external URL for this event.', |
|
| 451 | - 'event_espresso' |
|
| 452 | - ) |
|
| 453 | - : ''; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * formOpen |
|
| 460 | - * |
|
| 461 | - * @param int $ID |
|
| 462 | - * @param string $external_url |
|
| 463 | - * @return string |
|
| 464 | - */ |
|
| 465 | - public function formOpen( $ID = 0, $external_url = '' ) |
|
| 466 | - { |
|
| 467 | - // if redirecting, we don't need any anything else |
|
| 468 | - if ( $external_url ) { |
|
| 469 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
| 470 | - // open link in new window ? |
|
| 471 | - $html .= apply_filters( |
|
| 472 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
| 473 | - EED_Events_Archive::is_iframe() |
|
| 474 | - ) |
|
| 475 | - ? ' target="_blank"' |
|
| 476 | - : ''; |
|
| 477 | - $html .= '>'; |
|
| 478 | - $query_args = EEH_URL::get_query_string( $external_url ); |
|
| 479 | - foreach ( (array)$query_args as $query_arg => $value ) { |
|
| 480 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
| 481 | - } |
|
| 482 | - return $html; |
|
| 483 | - } |
|
| 484 | - // if there is no submit button, then don't start building a form |
|
| 485 | - // because the "View Details" button will build its own form |
|
| 486 | - if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
| 487 | - return ''; |
|
| 488 | - } |
|
| 489 | - $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
| 490 | - if ( ! $checkout_url ) { |
|
| 491 | - EE_Error::add_error( |
|
| 492 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 493 | - __FILE__, |
|
| 494 | - __FUNCTION__, |
|
| 495 | - __LINE__ |
|
| 496 | - ); |
|
| 497 | - } |
|
| 498 | - // set no cache headers and constants |
|
| 499 | - EE_System::do_not_cache(); |
|
| 500 | - $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
| 501 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
| 502 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
| 503 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
| 504 | - return $html; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - |
|
| 509 | - /** |
|
| 510 | - * displaySubmitButton |
|
| 511 | - * |
|
| 512 | - * @param string $external_url |
|
| 513 | - * @return string |
|
| 514 | - * @throws EE_Error |
|
| 515 | - */ |
|
| 516 | - public function displaySubmitButton($external_url = '') |
|
| 517 | - { |
|
| 518 | - $html = ''; |
|
| 519 | - if ( ! is_admin()) { |
|
| 520 | - // standard TS displayed with submit button, ie: "Register Now" |
|
| 521 | - if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 522 | - $html .= $this->displayRegisterNowButton(); |
|
| 523 | - $html .= empty($external_url) |
|
| 524 | - ? $this->ticketSelectorEndDiv() |
|
| 525 | - : $this->clearTicketSelector(); |
|
| 526 | - $html .= '<br/>' . $this->formClose(); |
|
| 527 | - } else if ($this->getMaxAttendees() === 1) { |
|
| 528 | - // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
| 529 | - if ($this->event->is_sold_out()) { |
|
| 530 | - // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
| 531 | - $html .= apply_filters( |
|
| 532 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
| 533 | - sprintf( |
|
| 534 | - __( |
|
| 535 | - '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
| 536 | - 'event_espresso' |
|
| 537 | - ), |
|
| 538 | - '<p class="no-ticket-selector-msg clear-float">', |
|
| 539 | - $this->event->name(), |
|
| 540 | - '</p>', |
|
| 541 | - '<br />' |
|
| 542 | - ), |
|
| 543 | - $this->event |
|
| 544 | - ); |
|
| 545 | - if ( |
|
| 546 | - apply_filters( |
|
| 547 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 548 | - false, |
|
| 549 | - $this->event |
|
| 550 | - ) |
|
| 551 | - ) { |
|
| 552 | - $html .= $this->displayRegisterNowButton(); |
|
| 553 | - } |
|
| 554 | - // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
| 555 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 556 | - } else if ( |
|
| 557 | - apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
| 558 | - && ! is_single() |
|
| 559 | - ) { |
|
| 560 | - // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
| 561 | - // but no tickets are available, so display event's "View Details" button. |
|
| 562 | - // it is being viewed via somewhere other than a single post |
|
| 563 | - $html .= $this->displayViewDetailsButton(true); |
|
| 564 | - } else { |
|
| 565 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 566 | - } |
|
| 567 | - } else if (is_archive()) { |
|
| 568 | - // event list, no tickets available so display event's "View Details" button |
|
| 569 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 570 | - $html .= $this->displayViewDetailsButton(); |
|
| 571 | - } else { |
|
| 572 | - if ( |
|
| 573 | - apply_filters( |
|
| 574 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 575 | - false, |
|
| 576 | - $this->event |
|
| 577 | - ) |
|
| 578 | - ) { |
|
| 579 | - $html .= $this->displayRegisterNowButton(); |
|
| 580 | - } |
|
| 581 | - // no submit or view details button, and no additional content |
|
| 582 | - $html .= $this->ticketSelectorEndDiv(); |
|
| 583 | - } |
|
| 584 | - if ( ! $this->iframe && ! is_archive()) { |
|
| 585 | - $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - return apply_filters( |
|
| 589 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
| 590 | - $html, |
|
| 591 | - $this->event |
|
| 592 | - ); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - |
|
| 597 | - /** |
|
| 598 | - * @return string |
|
| 599 | - * @throws EE_Error |
|
| 600 | - */ |
|
| 601 | - public function displayRegisterNowButton() |
|
| 602 | - { |
|
| 603 | - $btn_text = apply_filters( |
|
| 604 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
| 605 | - __('Register Now', 'event_espresso'), |
|
| 606 | - $this->event |
|
| 607 | - ); |
|
| 608 | - $external_url = $this->event->external_url(); |
|
| 609 | - $html = EEH_HTML::div( |
|
| 610 | - '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
| 611 | - ); |
|
| 612 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
| 613 | - $html .= ' class="ticket-selector-submit-btn '; |
|
| 614 | - $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
| 615 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
| 616 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
| 617 | - $html .= apply_filters( |
|
| 618 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
| 619 | - '', |
|
| 620 | - $this->event |
|
| 621 | - ); |
|
| 622 | - return $html; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * displayViewDetailsButton |
|
| 628 | - * |
|
| 629 | - * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
| 630 | - * (ie: $_max_atndz === 1) where there are no available tickets, |
|
| 631 | - * either because they are sold out, expired, or not yet on sale. |
|
| 632 | - * In this case, we need to close the form BEFORE adding any closing divs |
|
| 633 | - * @return string |
|
| 634 | - * @throws EE_Error |
|
| 635 | - */ |
|
| 636 | - public function displayViewDetailsButton( $DWMTS = false ) |
|
| 637 | - { |
|
| 638 | - if ( ! $this->event->get_permalink() ) { |
|
| 639 | - EE_Error::add_error( |
|
| 640 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 641 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 642 | - ); |
|
| 643 | - } |
|
| 644 | - $view_details_btn = '<form method="POST" action="'; |
|
| 645 | - $view_details_btn .= apply_filters( |
|
| 646 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
| 647 | - $this->event->get_permalink(), |
|
| 648 | - $this->event |
|
| 649 | - ); |
|
| 650 | - $view_details_btn .= '"'; |
|
| 651 | - // open link in new window ? |
|
| 652 | - $view_details_btn .= apply_filters( |
|
| 653 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
| 654 | - EED_Events_Archive::is_iframe() |
|
| 655 | - ) |
|
| 656 | - ? ' target="_blank"' |
|
| 657 | - : ''; |
|
| 658 | - $view_details_btn .='>'; |
|
| 659 | - $btn_text = apply_filters( |
|
| 660 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
| 661 | - esc_html__('View Details', 'event_espresso'), |
|
| 662 | - $this->event |
|
| 663 | - ); |
|
| 664 | - $view_details_btn .= '<input id="ticket-selector-submit-' |
|
| 665 | - . $this->event->ID() |
|
| 666 | - . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
| 667 | - . $btn_text |
|
| 668 | - . '" />'; |
|
| 669 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
| 670 | - if ($DWMTS) { |
|
| 671 | - $view_details_btn .= $this->formClose(); |
|
| 672 | - $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
| 673 | - $view_details_btn .= '<br/>'; |
|
| 674 | - } else { |
|
| 675 | - $view_details_btn .= $this->clearTicketSelector(); |
|
| 676 | - $view_details_btn .= '<br/>'; |
|
| 677 | - $view_details_btn .= $this->formClose(); |
|
| 678 | - } |
|
| 679 | - return $view_details_btn; |
|
| 680 | - } |
|
| 681 | - |
|
| 682 | - |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * @return string |
|
| 686 | - */ |
|
| 687 | - public function ticketSelectorEndDiv() |
|
| 688 | - { |
|
| 689 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * @return string |
|
| 696 | - */ |
|
| 697 | - public function clearTicketSelector() |
|
| 698 | - { |
|
| 699 | - // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
| 700 | - return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * @access public |
|
| 707 | - * @return string |
|
| 708 | - */ |
|
| 709 | - public function formClose() |
|
| 710 | - { |
|
| 711 | - return '</form>'; |
|
| 712 | - } |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * ticketSalesClosed |
|
| 294 | + * notice displayed if event ticket sales are turned off |
|
| 295 | + * |
|
| 296 | + * @return string |
|
| 297 | + * @throws EE_Error |
|
| 298 | + */ |
|
| 299 | + protected function ticketSalesClosedMessage() |
|
| 300 | + { |
|
| 301 | + $sales_closed_msg = esc_html__( |
|
| 302 | + 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
| 303 | + 'event_espresso' |
|
| 304 | + ); |
|
| 305 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
| 306 | + $sales_closed_msg .= sprintf( |
|
| 307 | + esc_html__( |
|
| 308 | + '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
| 309 | + 'event_espresso' |
|
| 310 | + ), |
|
| 311 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
| 312 | + '</b><br />', |
|
| 313 | + '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
| 314 | + '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
| 315 | + ); |
|
| 316 | + } |
|
| 317 | + return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * getTickets |
|
| 324 | + * |
|
| 325 | + * @return \EE_Base_Class[]|\EE_Ticket[] |
|
| 326 | + * @throws EE_Error |
|
| 327 | + */ |
|
| 328 | + protected function getTickets() |
|
| 329 | + { |
|
| 330 | + $ticket_query_args = array( |
|
| 331 | + array('Datetime.EVT_ID' => $this->event->ID()), |
|
| 332 | + 'order_by' => array( |
|
| 333 | + 'TKT_order' => 'ASC', |
|
| 334 | + 'TKT_required' => 'DESC', |
|
| 335 | + 'TKT_start_date' => 'ASC', |
|
| 336 | + 'TKT_end_date' => 'ASC', |
|
| 337 | + 'Datetime.DTT_EVT_start' => 'DESC', |
|
| 338 | + ), |
|
| 339 | + ); |
|
| 340 | + if ( ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets) { |
|
| 341 | + //use the correct applicable time query depending on what version of core is being run. |
|
| 342 | + $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
| 343 | + ? time() |
|
| 344 | + : current_time('timestamp'); |
|
| 345 | + $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
| 346 | + } |
|
| 347 | + return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * loadTicketSelector |
|
| 354 | + * begins to assemble template arguments |
|
| 355 | + * and decides whether to load a "simple" ticket selector, or the standard |
|
| 356 | + * |
|
| 357 | + * @param \EE_Ticket[] $tickets |
|
| 358 | + * @param array $template_args |
|
| 359 | + * @return string |
|
| 360 | + * @throws EE_Error |
|
| 361 | + */ |
|
| 362 | + protected function loadTicketSelector(array $tickets, array $template_args) |
|
| 363 | + { |
|
| 364 | + $template_args['event'] = $this->event; |
|
| 365 | + $template_args['EVT_ID'] = $this->event->ID(); |
|
| 366 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
| 367 | + $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
| 368 | + $template_args['date_format'] = $this->date_format; |
|
| 369 | + $template_args['time_format'] = $this->time_format; |
|
| 370 | + /** |
|
| 371 | + * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
| 372 | + * |
|
| 373 | + * @since 4.9.13 |
|
| 374 | + * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
| 375 | + * @param int $EVT_ID The Event ID |
|
| 376 | + */ |
|
| 377 | + $template_args['anchor_id'] = apply_filters( |
|
| 378 | + 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
| 379 | + '#tkt-slctr-tbl-' . $this->event->ID(), |
|
| 380 | + $this->event->ID() |
|
| 381 | + ); |
|
| 382 | + $template_args['tickets'] = $tickets; |
|
| 383 | + $template_args['ticket_count'] = count($tickets); |
|
| 384 | + $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
| 385 | + return $ticket_selector instanceof TicketSelectorSimple |
|
| 386 | + ? $ticket_selector |
|
| 387 | + : new TicketSelectorStandard( |
|
| 388 | + $this->event, |
|
| 389 | + $tickets, |
|
| 390 | + $this->getMaxAttendees(), |
|
| 391 | + $template_args, |
|
| 392 | + $this->date_format, |
|
| 393 | + $this->time_format |
|
| 394 | + ); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * simpleTicketSelector |
|
| 401 | + * there's one ticket, and max attendees is set to one, |
|
| 402 | + * so if the event is free, then this is a "simple" ticket selector |
|
| 403 | + * a.k.a. "Dude Where's my Ticket Selector?" |
|
| 404 | + * |
|
| 405 | + * @param \EE_Ticket[] $tickets |
|
| 406 | + * @param array $template_args |
|
| 407 | + * @return string |
|
| 408 | + * @throws EE_Error |
|
| 409 | + */ |
|
| 410 | + protected function simpleTicketSelector($tickets, array $template_args) |
|
| 411 | + { |
|
| 412 | + // if there is only ONE ticket with a max qty of ONE |
|
| 413 | + if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
| 414 | + return ''; |
|
| 415 | + } |
|
| 416 | + /** @var \EE_Ticket $ticket */ |
|
| 417 | + $ticket = reset($tickets); |
|
| 418 | + // if the ticket is free... then not much need for the ticket selector |
|
| 419 | + if ( |
|
| 420 | + apply_filters( |
|
| 421 | + 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
| 422 | + $ticket->is_free(), |
|
| 423 | + $this->event->ID() |
|
| 424 | + ) |
|
| 425 | + ) { |
|
| 426 | + return new TicketSelectorSimple( |
|
| 427 | + $this->event, |
|
| 428 | + $ticket, |
|
| 429 | + $this->getMaxAttendees(), |
|
| 430 | + $template_args |
|
| 431 | + ); |
|
| 432 | + } |
|
| 433 | + return ''; |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * externalEventRegistration |
|
| 440 | + * |
|
| 441 | + * @return string |
|
| 442 | + */ |
|
| 443 | + public function externalEventRegistration() |
|
| 444 | + { |
|
| 445 | + // if not we still need to trigger the display of the submit button |
|
| 446 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
| 447 | + //display notice to admin that registration is external |
|
| 448 | + return is_admin() |
|
| 449 | + ? esc_html__( |
|
| 450 | + 'Registration is at an external URL for this event.', |
|
| 451 | + 'event_espresso' |
|
| 452 | + ) |
|
| 453 | + : ''; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * formOpen |
|
| 460 | + * |
|
| 461 | + * @param int $ID |
|
| 462 | + * @param string $external_url |
|
| 463 | + * @return string |
|
| 464 | + */ |
|
| 465 | + public function formOpen( $ID = 0, $external_url = '' ) |
|
| 466 | + { |
|
| 467 | + // if redirecting, we don't need any anything else |
|
| 468 | + if ( $external_url ) { |
|
| 469 | + $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
| 470 | + // open link in new window ? |
|
| 471 | + $html .= apply_filters( |
|
| 472 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
| 473 | + EED_Events_Archive::is_iframe() |
|
| 474 | + ) |
|
| 475 | + ? ' target="_blank"' |
|
| 476 | + : ''; |
|
| 477 | + $html .= '>'; |
|
| 478 | + $query_args = EEH_URL::get_query_string( $external_url ); |
|
| 479 | + foreach ( (array)$query_args as $query_arg => $value ) { |
|
| 480 | + $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
| 481 | + } |
|
| 482 | + return $html; |
|
| 483 | + } |
|
| 484 | + // if there is no submit button, then don't start building a form |
|
| 485 | + // because the "View Details" button will build its own form |
|
| 486 | + if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
| 487 | + return ''; |
|
| 488 | + } |
|
| 489 | + $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
| 490 | + if ( ! $checkout_url ) { |
|
| 491 | + EE_Error::add_error( |
|
| 492 | + esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 493 | + __FILE__, |
|
| 494 | + __FUNCTION__, |
|
| 495 | + __LINE__ |
|
| 496 | + ); |
|
| 497 | + } |
|
| 498 | + // set no cache headers and constants |
|
| 499 | + EE_System::do_not_cache(); |
|
| 500 | + $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
| 501 | + $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
| 502 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
| 503 | + $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
| 504 | + return $html; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + |
|
| 509 | + /** |
|
| 510 | + * displaySubmitButton |
|
| 511 | + * |
|
| 512 | + * @param string $external_url |
|
| 513 | + * @return string |
|
| 514 | + * @throws EE_Error |
|
| 515 | + */ |
|
| 516 | + public function displaySubmitButton($external_url = '') |
|
| 517 | + { |
|
| 518 | + $html = ''; |
|
| 519 | + if ( ! is_admin()) { |
|
| 520 | + // standard TS displayed with submit button, ie: "Register Now" |
|
| 521 | + if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
| 522 | + $html .= $this->displayRegisterNowButton(); |
|
| 523 | + $html .= empty($external_url) |
|
| 524 | + ? $this->ticketSelectorEndDiv() |
|
| 525 | + : $this->clearTicketSelector(); |
|
| 526 | + $html .= '<br/>' . $this->formClose(); |
|
| 527 | + } else if ($this->getMaxAttendees() === 1) { |
|
| 528 | + // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
| 529 | + if ($this->event->is_sold_out()) { |
|
| 530 | + // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
| 531 | + $html .= apply_filters( |
|
| 532 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
| 533 | + sprintf( |
|
| 534 | + __( |
|
| 535 | + '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
| 536 | + 'event_espresso' |
|
| 537 | + ), |
|
| 538 | + '<p class="no-ticket-selector-msg clear-float">', |
|
| 539 | + $this->event->name(), |
|
| 540 | + '</p>', |
|
| 541 | + '<br />' |
|
| 542 | + ), |
|
| 543 | + $this->event |
|
| 544 | + ); |
|
| 545 | + if ( |
|
| 546 | + apply_filters( |
|
| 547 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 548 | + false, |
|
| 549 | + $this->event |
|
| 550 | + ) |
|
| 551 | + ) { |
|
| 552 | + $html .= $this->displayRegisterNowButton(); |
|
| 553 | + } |
|
| 554 | + // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
| 555 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 556 | + } else if ( |
|
| 557 | + apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
| 558 | + && ! is_single() |
|
| 559 | + ) { |
|
| 560 | + // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
| 561 | + // but no tickets are available, so display event's "View Details" button. |
|
| 562 | + // it is being viewed via somewhere other than a single post |
|
| 563 | + $html .= $this->displayViewDetailsButton(true); |
|
| 564 | + } else { |
|
| 565 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 566 | + } |
|
| 567 | + } else if (is_archive()) { |
|
| 568 | + // event list, no tickets available so display event's "View Details" button |
|
| 569 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 570 | + $html .= $this->displayViewDetailsButton(); |
|
| 571 | + } else { |
|
| 572 | + if ( |
|
| 573 | + apply_filters( |
|
| 574 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
| 575 | + false, |
|
| 576 | + $this->event |
|
| 577 | + ) |
|
| 578 | + ) { |
|
| 579 | + $html .= $this->displayRegisterNowButton(); |
|
| 580 | + } |
|
| 581 | + // no submit or view details button, and no additional content |
|
| 582 | + $html .= $this->ticketSelectorEndDiv(); |
|
| 583 | + } |
|
| 584 | + if ( ! $this->iframe && ! is_archive()) { |
|
| 585 | + $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + return apply_filters( |
|
| 589 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
| 590 | + $html, |
|
| 591 | + $this->event |
|
| 592 | + ); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + |
|
| 597 | + /** |
|
| 598 | + * @return string |
|
| 599 | + * @throws EE_Error |
|
| 600 | + */ |
|
| 601 | + public function displayRegisterNowButton() |
|
| 602 | + { |
|
| 603 | + $btn_text = apply_filters( |
|
| 604 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
| 605 | + __('Register Now', 'event_espresso'), |
|
| 606 | + $this->event |
|
| 607 | + ); |
|
| 608 | + $external_url = $this->event->external_url(); |
|
| 609 | + $html = EEH_HTML::div( |
|
| 610 | + '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
| 611 | + ); |
|
| 612 | + $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
| 613 | + $html .= ' class="ticket-selector-submit-btn '; |
|
| 614 | + $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
| 615 | + $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
| 616 | + $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
| 617 | + $html .= apply_filters( |
|
| 618 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
| 619 | + '', |
|
| 620 | + $this->event |
|
| 621 | + ); |
|
| 622 | + return $html; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * displayViewDetailsButton |
|
| 628 | + * |
|
| 629 | + * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
| 630 | + * (ie: $_max_atndz === 1) where there are no available tickets, |
|
| 631 | + * either because they are sold out, expired, or not yet on sale. |
|
| 632 | + * In this case, we need to close the form BEFORE adding any closing divs |
|
| 633 | + * @return string |
|
| 634 | + * @throws EE_Error |
|
| 635 | + */ |
|
| 636 | + public function displayViewDetailsButton( $DWMTS = false ) |
|
| 637 | + { |
|
| 638 | + if ( ! $this->event->get_permalink() ) { |
|
| 639 | + EE_Error::add_error( |
|
| 640 | + esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
| 641 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 642 | + ); |
|
| 643 | + } |
|
| 644 | + $view_details_btn = '<form method="POST" action="'; |
|
| 645 | + $view_details_btn .= apply_filters( |
|
| 646 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
| 647 | + $this->event->get_permalink(), |
|
| 648 | + $this->event |
|
| 649 | + ); |
|
| 650 | + $view_details_btn .= '"'; |
|
| 651 | + // open link in new window ? |
|
| 652 | + $view_details_btn .= apply_filters( |
|
| 653 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
| 654 | + EED_Events_Archive::is_iframe() |
|
| 655 | + ) |
|
| 656 | + ? ' target="_blank"' |
|
| 657 | + : ''; |
|
| 658 | + $view_details_btn .='>'; |
|
| 659 | + $btn_text = apply_filters( |
|
| 660 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
| 661 | + esc_html__('View Details', 'event_espresso'), |
|
| 662 | + $this->event |
|
| 663 | + ); |
|
| 664 | + $view_details_btn .= '<input id="ticket-selector-submit-' |
|
| 665 | + . $this->event->ID() |
|
| 666 | + . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
| 667 | + . $btn_text |
|
| 668 | + . '" />'; |
|
| 669 | + $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
| 670 | + if ($DWMTS) { |
|
| 671 | + $view_details_btn .= $this->formClose(); |
|
| 672 | + $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
| 673 | + $view_details_btn .= '<br/>'; |
|
| 674 | + } else { |
|
| 675 | + $view_details_btn .= $this->clearTicketSelector(); |
|
| 676 | + $view_details_btn .= '<br/>'; |
|
| 677 | + $view_details_btn .= $this->formClose(); |
|
| 678 | + } |
|
| 679 | + return $view_details_btn; |
|
| 680 | + } |
|
| 681 | + |
|
| 682 | + |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * @return string |
|
| 686 | + */ |
|
| 687 | + public function ticketSelectorEndDiv() |
|
| 688 | + { |
|
| 689 | + return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * @return string |
|
| 696 | + */ |
|
| 697 | + public function clearTicketSelector() |
|
| 698 | + { |
|
| 699 | + // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
| 700 | + return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * @access public |
|
| 707 | + * @return string |
|
| 708 | + */ |
|
| 709 | + public function formClose() |
|
| 710 | + { |
|
| 711 | + return '</form>'; |
|
| 712 | + } |
|
| 713 | 713 | |
| 714 | 714 | |
| 715 | 715 | |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | namespace EventEspresso\modules\ticket_selector; |
| 3 | 3 | |
| 4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 5 | - exit('No direct script access allowed'); |
|
| 5 | + exit('No direct script access allowed'); |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | |
@@ -19,570 +19,570 @@ discard block |
||
| 19 | 19 | class ProcessTicketSelector |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * array of datetimes and the spaces available for them |
|
| 24 | - * |
|
| 25 | - * @access private |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - private static $_available_spaces = array(); |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * cancelTicketSelections |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - public function cancelTicketSelections() |
|
| 38 | - { |
|
| 39 | - // check nonce |
|
| 40 | - if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
| 41 | - return false; |
|
| 42 | - } |
|
| 43 | - \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 44 | - if (\EE_Registry::instance()->REQ->is_set('event_id')) { |
|
| 45 | - wp_safe_redirect( |
|
| 46 | - \EEH_Event_View::event_link_url( |
|
| 47 | - \EE_Registry::instance()->REQ->get('event_id') |
|
| 48 | - ) |
|
| 49 | - ); |
|
| 50 | - } else { |
|
| 51 | - wp_safe_redirect( |
|
| 52 | - site_url('/' . \EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
| 53 | - ); |
|
| 54 | - } |
|
| 55 | - exit(); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * processTicketSelectorNonce |
|
| 62 | - * |
|
| 63 | - * @param string $nonce_name |
|
| 64 | - * @param string $id |
|
| 65 | - * @return bool |
|
| 66 | - */ |
|
| 67 | - private function processTicketSelectorNonce($nonce_name, $id = '') |
|
| 68 | - { |
|
| 69 | - $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
| 70 | - if ( |
|
| 71 | - ! is_admin() |
|
| 72 | - && ( |
|
| 73 | - ! \EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
| 74 | - || ! wp_verify_nonce( |
|
| 75 | - \EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
| 76 | - $nonce_name |
|
| 77 | - ) |
|
| 78 | - ) |
|
| 79 | - ) { |
|
| 80 | - \EE_Error::add_error( |
|
| 81 | - sprintf( |
|
| 82 | - __( |
|
| 83 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
| 84 | - 'event_espresso' |
|
| 85 | - ), |
|
| 86 | - '<br/>' |
|
| 87 | - ), |
|
| 88 | - __FILE__, |
|
| 89 | - __FUNCTION__, |
|
| 90 | - __LINE__ |
|
| 91 | - ); |
|
| 92 | - return false; |
|
| 93 | - } |
|
| 94 | - return true; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * process_ticket_selections |
|
| 101 | - * |
|
| 102 | - * @return array|bool |
|
| 103 | - * @throws \EE_Error |
|
| 104 | - */ |
|
| 105 | - public function processTicketSelections() |
|
| 106 | - { |
|
| 107 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
| 108 | - // do we have an event id? |
|
| 109 | - if ( ! \EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
| 110 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
| 111 | - \EE_Error::add_error( |
|
| 112 | - sprintf( |
|
| 113 | - __( |
|
| 114 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
| 115 | - 'event_espresso' |
|
| 116 | - ), |
|
| 117 | - '<br/>' |
|
| 118 | - ), |
|
| 119 | - __FILE__, |
|
| 120 | - __FUNCTION__, |
|
| 121 | - __LINE__ |
|
| 122 | - ); |
|
| 123 | - } |
|
| 124 | - //if event id is valid |
|
| 125 | - $id = absint(\EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
| 126 | - // d( \EE_Registry::instance()->REQ ); |
|
| 127 | - self::$_available_spaces = array( |
|
| 128 | - 'tickets' => array(), |
|
| 129 | - 'datetimes' => array(), |
|
| 130 | - ); |
|
| 131 | - //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
| 132 | - // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
| 133 | - \EE_Registry::instance()->load_core('Session'); |
|
| 134 | - // unless otherwise requested, clear the session |
|
| 135 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
| 136 | - \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 137 | - } |
|
| 138 | - //d( \EE_Registry::instance()->SSN ); |
|
| 139 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 140 | - // validate/sanitize data |
|
| 141 | - $valid = $this->validatePostData($id); |
|
| 142 | - //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
| 143 | - //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
| 144 | - //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
| 145 | - //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
| 146 | - //check total tickets ordered vs max number of attendees that can register |
|
| 147 | - if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
| 148 | - // ordering too many tickets !!! |
|
| 149 | - $total_tickets_string = _n( |
|
| 150 | - 'You have attempted to purchase %s ticket.', |
|
| 151 | - 'You have attempted to purchase %s tickets.', |
|
| 152 | - $valid['total_tickets'], |
|
| 153 | - 'event_espresso' |
|
| 154 | - ); |
|
| 155 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
| 156 | - // dev only message |
|
| 157 | - $max_atndz_string = _n( |
|
| 158 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 159 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 160 | - $valid['max_atndz'], |
|
| 161 | - 'event_espresso' |
|
| 162 | - ); |
|
| 163 | - $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 164 | - \EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 165 | - } else { |
|
| 166 | - // all data appears to be valid |
|
| 167 | - $tckts_slctd = false; |
|
| 168 | - $tickets_added = 0; |
|
| 169 | - $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid); |
|
| 170 | - if ($valid['total_tickets'] > 0) { |
|
| 171 | - // load cart |
|
| 172 | - \EE_Registry::instance()->load_core('Cart'); |
|
| 173 | - // cycle thru the number of data rows sent from the event listing |
|
| 174 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
| 175 | - // does this row actually contain a ticket quantity? |
|
| 176 | - if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
| 177 | - // YES we have a ticket quantity |
|
| 178 | - $tckts_slctd = true; |
|
| 179 | - // d( $valid['ticket_obj'][$x] ); |
|
| 180 | - if ($valid['ticket_obj'][$x] instanceof \EE_Ticket) { |
|
| 181 | - // then add ticket to cart |
|
| 182 | - $tickets_added += $this->addTicketToCart( |
|
| 183 | - $valid['ticket_obj'][$x], |
|
| 184 | - $valid['qty'][$x] |
|
| 185 | - ); |
|
| 186 | - if (\EE_Error::has_error()) { |
|
| 187 | - break; |
|
| 188 | - } |
|
| 189 | - } else { |
|
| 190 | - // nothing added to cart retrieved |
|
| 191 | - \EE_Error::add_error( |
|
| 192 | - sprintf( |
|
| 193 | - __( |
|
| 194 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
| 195 | - 'event_espresso' |
|
| 196 | - ), |
|
| 197 | - '<br/>' |
|
| 198 | - ), |
|
| 199 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - do_action( |
|
| 206 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 207 | - \EE_Registry::instance()->CART, |
|
| 208 | - $this |
|
| 209 | - ); |
|
| 210 | - //d( \EE_Registry::instance()->CART ); |
|
| 211 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
| 212 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
| 213 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
| 214 | - do_action( |
|
| 215 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
| 216 | - \EE_Registry::instance()->CART, |
|
| 217 | - $this |
|
| 218 | - ); |
|
| 219 | - \EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
| 220 | - \EE_Registry::instance()->CART->save_cart(false); |
|
| 221 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
| 222 | - // just return TRUE for registrations being made from admin |
|
| 223 | - if (is_admin()) { |
|
| 224 | - return true; |
|
| 225 | - } |
|
| 226 | - \EE_Error::get_notices(false, true); |
|
| 227 | - wp_safe_redirect( |
|
| 228 | - apply_filters( |
|
| 229 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 230 | - \EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 233 | - exit(); |
|
| 234 | - } else { |
|
| 235 | - if ( ! \EE_Error::has_error() && ! \EE_Error::has_error(true, 'attention')) { |
|
| 236 | - // nothing added to cart |
|
| 237 | - \EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
| 238 | - __FILE__, __FUNCTION__, __LINE__); |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - } else { |
|
| 242 | - // no ticket quantities were selected |
|
| 243 | - \EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
| 244 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
| 248 | - // at this point, just return if registration is being made from admin |
|
| 249 | - if (is_admin()) { |
|
| 250 | - return false; |
|
| 251 | - } |
|
| 252 | - if ($valid['return_url']) { |
|
| 253 | - \EE_Error::get_notices(false, true); |
|
| 254 | - wp_safe_redirect($valid['return_url']); |
|
| 255 | - exit(); |
|
| 256 | - } elseif (isset($event_to_add['id'])) { |
|
| 257 | - \EE_Error::get_notices(false, true); |
|
| 258 | - wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
| 259 | - exit(); |
|
| 260 | - } else { |
|
| 261 | - echo \EE_Error::get_notices(); |
|
| 262 | - } |
|
| 263 | - return false; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * validate_post_data |
|
| 270 | - * |
|
| 271 | - * @param int $id |
|
| 272 | - * @return array|FALSE |
|
| 273 | - */ |
|
| 274 | - private function validatePostData($id = 0) |
|
| 275 | - { |
|
| 276 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 277 | - if ( ! $id) { |
|
| 278 | - \EE_Error::add_error( |
|
| 279 | - __('The event id provided was not valid.', 'event_espresso'), |
|
| 280 | - __FILE__, |
|
| 281 | - __FUNCTION__, |
|
| 282 | - __LINE__ |
|
| 283 | - ); |
|
| 284 | - return false; |
|
| 285 | - } |
|
| 286 | - // start with an empty array() |
|
| 287 | - $valid_data = array(); |
|
| 288 | - // grab valid id |
|
| 289 | - $valid_data['id'] = $id; |
|
| 290 | - // array of other form names |
|
| 291 | - $inputs_to_clean = array( |
|
| 292 | - 'event_id' => 'tkt-slctr-event-id', |
|
| 293 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
| 294 | - 'rows' => 'tkt-slctr-rows-', |
|
| 295 | - 'qty' => 'tkt-slctr-qty-', |
|
| 296 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
| 297 | - 'return_url' => 'tkt-slctr-return-url-', |
|
| 298 | - ); |
|
| 299 | - // let's track the total number of tickets ordered.' |
|
| 300 | - $valid_data['total_tickets'] = 0; |
|
| 301 | - // cycle through $inputs_to_clean array |
|
| 302 | - foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
| 303 | - // check for POST data |
|
| 304 | - if (\EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
| 305 | - // grab value |
|
| 306 | - $input_value = \EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
| 307 | - switch ($what) { |
|
| 308 | - // integers |
|
| 309 | - case 'event_id': |
|
| 310 | - $valid_data[$what] = absint($input_value); |
|
| 311 | - // get event via the event id we put in the form |
|
| 312 | - $valid_data['event'] = \EE_Registry::instance() |
|
| 313 | - ->load_model('Event') |
|
| 314 | - ->get_one_by_ID($valid_data['event_id']); |
|
| 315 | - break; |
|
| 316 | - case 'rows': |
|
| 317 | - case 'max_atndz': |
|
| 318 | - $valid_data[$what] = absint($input_value); |
|
| 319 | - break; |
|
| 320 | - // arrays of integers |
|
| 321 | - case 'qty': |
|
| 322 | - /** @var array $row_qty */ |
|
| 323 | - $row_qty = $input_value; |
|
| 324 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
| 325 | - if ( ! is_array($row_qty)) { |
|
| 326 | - // get number of rows |
|
| 327 | - $rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
| 328 | - ? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
| 329 | - : 1; |
|
| 330 | - // explode ints by the dash |
|
| 331 | - $row_qty = explode('-', $row_qty); |
|
| 332 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
| 333 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
| 334 | - $row_qty = array($row => $qty); |
|
| 335 | - for ($x = 1; $x <= $rows; $x++) { |
|
| 336 | - if ( ! isset($row_qty[$x])) { |
|
| 337 | - $row_qty[$x] = 0; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - ksort($row_qty); |
|
| 342 | - // cycle thru values |
|
| 343 | - foreach ($row_qty as $qty) { |
|
| 344 | - $qty = absint($qty); |
|
| 345 | - // sanitize as integers |
|
| 346 | - $valid_data[$what][] = $qty; |
|
| 347 | - $valid_data['total_tickets'] += $qty; |
|
| 348 | - } |
|
| 349 | - break; |
|
| 350 | - // array of integers |
|
| 351 | - case 'ticket_id': |
|
| 352 | - $value_array = array(); |
|
| 353 | - // cycle thru values |
|
| 354 | - foreach ((array)$input_value as $key => $value) { |
|
| 355 | - // allow only numbers, letters, spaces, commas and dashes |
|
| 356 | - $value_array[$key] = wp_strip_all_tags($value); |
|
| 357 | - // get ticket via the ticket id we put in the form |
|
| 358 | - $ticket_obj = \EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value); |
|
| 359 | - $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
| 360 | - } |
|
| 361 | - $valid_data[$what] = $value_array; |
|
| 362 | - break; |
|
| 363 | - case 'return_url' : |
|
| 364 | - // grab and sanitize return-url |
|
| 365 | - $input_value = esc_url_raw($input_value); |
|
| 366 | - // was the request coming from an iframe ? if so, then: |
|
| 367 | - if (strpos($input_value, 'event_list=iframe')) { |
|
| 368 | - // get anchor fragment |
|
| 369 | - $input_value = explode('#', $input_value); |
|
| 370 | - $input_value = end($input_value); |
|
| 371 | - // use event list url instead, but append anchor |
|
| 372 | - $input_value = \EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
| 373 | - } |
|
| 374 | - $valid_data[$what] = $input_value; |
|
| 375 | - break; |
|
| 376 | - } // end switch $what |
|
| 377 | - } |
|
| 378 | - } // end foreach $inputs_to_clean |
|
| 379 | - return $valid_data; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * adds a ticket to the cart |
|
| 386 | - * |
|
| 387 | - * @param \EE_Ticket $ticket |
|
| 388 | - * @param int $qty |
|
| 389 | - * @return TRUE on success, FALSE on fail |
|
| 390 | - * @throws \EE_Error |
|
| 391 | - */ |
|
| 392 | - private function addTicketToCart(\EE_Ticket $ticket = null, $qty = 1) |
|
| 393 | - { |
|
| 394 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 395 | - // get the number of spaces left for this datetime ticket |
|
| 396 | - $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
| 397 | - // compare available spaces against the number of tickets being purchased |
|
| 398 | - if ($available_spaces >= $qty) { |
|
| 399 | - // allow addons to prevent a ticket from being added to cart |
|
| 400 | - if ( |
|
| 401 | - ! apply_filters( |
|
| 402 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
| 403 | - true, |
|
| 404 | - $ticket, |
|
| 405 | - $qty, |
|
| 406 | - $available_spaces |
|
| 407 | - ) |
|
| 408 | - ) { |
|
| 409 | - return false; |
|
| 410 | - } |
|
| 411 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
| 412 | - // add event to cart |
|
| 413 | - if (\EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
| 414 | - $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
| 415 | - return true; |
|
| 416 | - } |
|
| 417 | - return false; |
|
| 418 | - } |
|
| 419 | - // tickets can not be purchased but let's find the exact number left |
|
| 420 | - // for the last ticket selected PRIOR to subtracting tickets |
|
| 421 | - $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
| 422 | - // greedy greedy greedy eh? |
|
| 423 | - if ($available_spaces > 0) { |
|
| 424 | - if ( |
|
| 425 | - apply_filters( |
|
| 426 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
| 427 | - true, |
|
| 428 | - $ticket, |
|
| 429 | - $qty, |
|
| 430 | - $available_spaces |
|
| 431 | - ) |
|
| 432 | - ) { |
|
| 433 | - $this->displayAvailabilityError($available_spaces); |
|
| 434 | - } |
|
| 435 | - } else { |
|
| 436 | - \EE_Error::add_error( |
|
| 437 | - __( |
|
| 438 | - 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
| 439 | - 'event_espresso' |
|
| 440 | - ), |
|
| 441 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 442 | - ); |
|
| 443 | - } |
|
| 444 | - return false; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * @param int $available_spaces |
|
| 451 | - * @throws \EE_Error |
|
| 452 | - */ |
|
| 453 | - private function displayAvailabilityError($available_spaces = 1) |
|
| 454 | - { |
|
| 455 | - // add error messaging - we're using the _n function that will generate |
|
| 456 | - // the appropriate singular or plural message based on the number of $available_spaces |
|
| 457 | - if (\EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
| 458 | - $msg = sprintf( |
|
| 459 | - _n( |
|
| 460 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
| 461 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
| 462 | - $available_spaces, |
|
| 463 | - 'event_espresso' |
|
| 464 | - ), |
|
| 465 | - $available_spaces, |
|
| 466 | - '<br />' |
|
| 467 | - ); |
|
| 468 | - } else { |
|
| 469 | - $msg = sprintf( |
|
| 470 | - _n( |
|
| 471 | - 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
| 472 | - 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
| 473 | - $available_spaces, |
|
| 474 | - 'event_espresso' |
|
| 475 | - ), |
|
| 476 | - $available_spaces, |
|
| 477 | - '<br />' |
|
| 478 | - ); |
|
| 479 | - } |
|
| 480 | - \EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * ticketDatetimeAvailability |
|
| 487 | - * creates an array of tickets plus all of the datetimes available to each ticket |
|
| 488 | - * and tracks the spaces remaining for each of those datetimes |
|
| 489 | - * |
|
| 490 | - * @param \EE_Ticket $ticket - selected ticket |
|
| 491 | - * @param bool $get_original_ticket_spaces |
|
| 492 | - * @return int |
|
| 493 | - * @throws \EE_Error |
|
| 494 | - */ |
|
| 495 | - private function ticketDatetimeAvailability(\EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
| 496 | - { |
|
| 497 | - // if the $_available_spaces array has not been set up yet... |
|
| 498 | - if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 499 | - $this->setInitialTicketDatetimeAvailability($ticket); |
|
| 500 | - } |
|
| 501 | - $available_spaces = $ticket->qty() - $ticket->sold(); |
|
| 502 | - if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 503 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
| 504 | - foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
| 505 | - // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
| 506 | - if ($get_original_ticket_spaces) { |
|
| 507 | - // then grab the available spaces from the "tickets" array |
|
| 508 | - // and compare with the above to get the lowest number |
|
| 509 | - $available_spaces = min( |
|
| 510 | - $available_spaces, |
|
| 511 | - self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID] |
|
| 512 | - ); |
|
| 513 | - } else { |
|
| 514 | - // we want the updated ticket availability as stored in the "datetimes" array |
|
| 515 | - $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - return $available_spaces; |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * @param \EE_Ticket $ticket |
|
| 526 | - * @return void |
|
| 527 | - * @throws \EE_Error |
|
| 528 | - */ |
|
| 529 | - private function setInitialTicketDatetimeAvailability(\EE_Ticket $ticket) |
|
| 530 | - { |
|
| 531 | - // first, get all of the datetimes that are available to this ticket |
|
| 532 | - $datetimes = $ticket->get_many_related( |
|
| 533 | - 'Datetime', |
|
| 534 | - array( |
|
| 535 | - array( |
|
| 536 | - 'DTT_EVT_end' => array( |
|
| 537 | - '>=', |
|
| 538 | - \EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 539 | - ), |
|
| 540 | - ), |
|
| 541 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 542 | - ) |
|
| 543 | - ); |
|
| 544 | - if ( ! empty($datetimes)) { |
|
| 545 | - // now loop thru all of the datetimes |
|
| 546 | - foreach ($datetimes as $datetime) { |
|
| 547 | - if ($datetime instanceof \EE_Datetime) { |
|
| 548 | - // the number of spaces available for the datetime without considering individual ticket quantities |
|
| 549 | - $spaces_remaining = $datetime->spaces_remaining(); |
|
| 550 | - // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
| 551 | - // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
| 552 | - self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
| 553 | - $ticket->qty() - $ticket->sold(), |
|
| 554 | - $spaces_remaining |
|
| 555 | - ); |
|
| 556 | - // if the remaining spaces for this datetime is already set, |
|
| 557 | - // then compare that against the datetime spaces remaining, and take the lowest number, |
|
| 558 | - // else just take the datetime spaces remaining, and assign to the datetimes array |
|
| 559 | - self::$_available_spaces['datetimes'][$datetime->ID()] = isset( |
|
| 560 | - self::$_available_spaces['datetimes'][$datetime->ID()] |
|
| 561 | - ) |
|
| 562 | - ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
| 563 | - : $spaces_remaining; |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - /** |
|
| 572 | - * @param \EE_Ticket $ticket |
|
| 573 | - * @param int $qty |
|
| 574 | - * @return void |
|
| 575 | - */ |
|
| 576 | - private function recalculateTicketDatetimeAvailability(\EE_Ticket $ticket, $qty = 0) |
|
| 577 | - { |
|
| 578 | - if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 579 | - // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
| 580 | - foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
| 581 | - // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
| 582 | - self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
| 583 | - } |
|
| 584 | - } |
|
| 585 | - } |
|
| 22 | + /** |
|
| 23 | + * array of datetimes and the spaces available for them |
|
| 24 | + * |
|
| 25 | + * @access private |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + private static $_available_spaces = array(); |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * cancelTicketSelections |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + public function cancelTicketSelections() |
|
| 38 | + { |
|
| 39 | + // check nonce |
|
| 40 | + if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 43 | + \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 44 | + if (\EE_Registry::instance()->REQ->is_set('event_id')) { |
|
| 45 | + wp_safe_redirect( |
|
| 46 | + \EEH_Event_View::event_link_url( |
|
| 47 | + \EE_Registry::instance()->REQ->get('event_id') |
|
| 48 | + ) |
|
| 49 | + ); |
|
| 50 | + } else { |
|
| 51 | + wp_safe_redirect( |
|
| 52 | + site_url('/' . \EE_Registry::instance()->CFG->core->event_cpt_slug . '/') |
|
| 53 | + ); |
|
| 54 | + } |
|
| 55 | + exit(); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * processTicketSelectorNonce |
|
| 62 | + * |
|
| 63 | + * @param string $nonce_name |
|
| 64 | + * @param string $id |
|
| 65 | + * @return bool |
|
| 66 | + */ |
|
| 67 | + private function processTicketSelectorNonce($nonce_name, $id = '') |
|
| 68 | + { |
|
| 69 | + $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
| 70 | + if ( |
|
| 71 | + ! is_admin() |
|
| 72 | + && ( |
|
| 73 | + ! \EE_Registry::instance()->REQ->is_set($nonce_name_with_id) |
|
| 74 | + || ! wp_verify_nonce( |
|
| 75 | + \EE_Registry::instance()->REQ->get($nonce_name_with_id), |
|
| 76 | + $nonce_name |
|
| 77 | + ) |
|
| 78 | + ) |
|
| 79 | + ) { |
|
| 80 | + \EE_Error::add_error( |
|
| 81 | + sprintf( |
|
| 82 | + __( |
|
| 83 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
| 84 | + 'event_espresso' |
|
| 85 | + ), |
|
| 86 | + '<br/>' |
|
| 87 | + ), |
|
| 88 | + __FILE__, |
|
| 89 | + __FUNCTION__, |
|
| 90 | + __LINE__ |
|
| 91 | + ); |
|
| 92 | + return false; |
|
| 93 | + } |
|
| 94 | + return true; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * process_ticket_selections |
|
| 101 | + * |
|
| 102 | + * @return array|bool |
|
| 103 | + * @throws \EE_Error |
|
| 104 | + */ |
|
| 105 | + public function processTicketSelections() |
|
| 106 | + { |
|
| 107 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
| 108 | + // do we have an event id? |
|
| 109 | + if ( ! \EE_Registry::instance()->REQ->is_set('tkt-slctr-event-id')) { |
|
| 110 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
| 111 | + \EE_Error::add_error( |
|
| 112 | + sprintf( |
|
| 113 | + __( |
|
| 114 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
| 115 | + 'event_espresso' |
|
| 116 | + ), |
|
| 117 | + '<br/>' |
|
| 118 | + ), |
|
| 119 | + __FILE__, |
|
| 120 | + __FUNCTION__, |
|
| 121 | + __LINE__ |
|
| 122 | + ); |
|
| 123 | + } |
|
| 124 | + //if event id is valid |
|
| 125 | + $id = absint(\EE_Registry::instance()->REQ->get('tkt-slctr-event-id')); |
|
| 126 | + // d( \EE_Registry::instance()->REQ ); |
|
| 127 | + self::$_available_spaces = array( |
|
| 128 | + 'tickets' => array(), |
|
| 129 | + 'datetimes' => array(), |
|
| 130 | + ); |
|
| 131 | + //we should really only have 1 registration in the works now (ie, no MER) so clear any previous items in the cart. |
|
| 132 | + // When MER happens this will probably need to be tweaked, possibly wrapped in a conditional checking for some constant defined in MER etc. |
|
| 133 | + \EE_Registry::instance()->load_core('Session'); |
|
| 134 | + // unless otherwise requested, clear the session |
|
| 135 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
| 136 | + \EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 137 | + } |
|
| 138 | + //d( \EE_Registry::instance()->SSN ); |
|
| 139 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 140 | + // validate/sanitize data |
|
| 141 | + $valid = $this->validatePostData($id); |
|
| 142 | + //EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
| 143 | + //EEH_Debug_Tools::printr( $valid, '$valid', __FILE__, __LINE__ ); |
|
| 144 | + //EEH_Debug_Tools::printr( $valid[ 'total_tickets' ], 'total_tickets', __FILE__, __LINE__ ); |
|
| 145 | + //EEH_Debug_Tools::printr( $valid[ 'max_atndz' ], 'max_atndz', __FILE__, __LINE__ ); |
|
| 146 | + //check total tickets ordered vs max number of attendees that can register |
|
| 147 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
| 148 | + // ordering too many tickets !!! |
|
| 149 | + $total_tickets_string = _n( |
|
| 150 | + 'You have attempted to purchase %s ticket.', |
|
| 151 | + 'You have attempted to purchase %s tickets.', |
|
| 152 | + $valid['total_tickets'], |
|
| 153 | + 'event_espresso' |
|
| 154 | + ); |
|
| 155 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
| 156 | + // dev only message |
|
| 157 | + $max_atndz_string = _n( |
|
| 158 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 159 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
| 160 | + $valid['max_atndz'], |
|
| 161 | + 'event_espresso' |
|
| 162 | + ); |
|
| 163 | + $limit_error_2 = sprintf($max_atndz_string, $valid['max_atndz'], $valid['max_atndz']); |
|
| 164 | + \EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
| 165 | + } else { |
|
| 166 | + // all data appears to be valid |
|
| 167 | + $tckts_slctd = false; |
|
| 168 | + $tickets_added = 0; |
|
| 169 | + $valid = apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', $valid); |
|
| 170 | + if ($valid['total_tickets'] > 0) { |
|
| 171 | + // load cart |
|
| 172 | + \EE_Registry::instance()->load_core('Cart'); |
|
| 173 | + // cycle thru the number of data rows sent from the event listing |
|
| 174 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
| 175 | + // does this row actually contain a ticket quantity? |
|
| 176 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
| 177 | + // YES we have a ticket quantity |
|
| 178 | + $tckts_slctd = true; |
|
| 179 | + // d( $valid['ticket_obj'][$x] ); |
|
| 180 | + if ($valid['ticket_obj'][$x] instanceof \EE_Ticket) { |
|
| 181 | + // then add ticket to cart |
|
| 182 | + $tickets_added += $this->addTicketToCart( |
|
| 183 | + $valid['ticket_obj'][$x], |
|
| 184 | + $valid['qty'][$x] |
|
| 185 | + ); |
|
| 186 | + if (\EE_Error::has_error()) { |
|
| 187 | + break; |
|
| 188 | + } |
|
| 189 | + } else { |
|
| 190 | + // nothing added to cart retrieved |
|
| 191 | + \EE_Error::add_error( |
|
| 192 | + sprintf( |
|
| 193 | + __( |
|
| 194 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
| 195 | + 'event_espresso' |
|
| 196 | + ), |
|
| 197 | + '<br/>' |
|
| 198 | + ), |
|
| 199 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + do_action( |
|
| 206 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 207 | + \EE_Registry::instance()->CART, |
|
| 208 | + $this |
|
| 209 | + ); |
|
| 210 | + //d( \EE_Registry::instance()->CART ); |
|
| 211 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
| 212 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tckts_slctd)) { |
|
| 213 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
| 214 | + do_action( |
|
| 215 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
| 216 | + \EE_Registry::instance()->CART, |
|
| 217 | + $this |
|
| 218 | + ); |
|
| 219 | + \EE_Registry::instance()->CART->recalculate_all_cart_totals(); |
|
| 220 | + \EE_Registry::instance()->CART->save_cart(false); |
|
| 221 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
| 222 | + // just return TRUE for registrations being made from admin |
|
| 223 | + if (is_admin()) { |
|
| 224 | + return true; |
|
| 225 | + } |
|
| 226 | + \EE_Error::get_notices(false, true); |
|
| 227 | + wp_safe_redirect( |
|
| 228 | + apply_filters( |
|
| 229 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
| 230 | + \EE_Registry::instance()->CFG->core->reg_page_url() |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | + exit(); |
|
| 234 | + } else { |
|
| 235 | + if ( ! \EE_Error::has_error() && ! \EE_Error::has_error(true, 'attention')) { |
|
| 236 | + // nothing added to cart |
|
| 237 | + \EE_Error::add_attention(__('No tickets were added for the event', 'event_espresso'), |
|
| 238 | + __FILE__, __FUNCTION__, __LINE__); |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + } else { |
|
| 242 | + // no ticket quantities were selected |
|
| 243 | + \EE_Error::add_error(__('You need to select a ticket quantity before you can proceed.', |
|
| 244 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + //die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
| 248 | + // at this point, just return if registration is being made from admin |
|
| 249 | + if (is_admin()) { |
|
| 250 | + return false; |
|
| 251 | + } |
|
| 252 | + if ($valid['return_url']) { |
|
| 253 | + \EE_Error::get_notices(false, true); |
|
| 254 | + wp_safe_redirect($valid['return_url']); |
|
| 255 | + exit(); |
|
| 256 | + } elseif (isset($event_to_add['id'])) { |
|
| 257 | + \EE_Error::get_notices(false, true); |
|
| 258 | + wp_safe_redirect(get_permalink($event_to_add['id'])); |
|
| 259 | + exit(); |
|
| 260 | + } else { |
|
| 261 | + echo \EE_Error::get_notices(); |
|
| 262 | + } |
|
| 263 | + return false; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * validate_post_data |
|
| 270 | + * |
|
| 271 | + * @param int $id |
|
| 272 | + * @return array|FALSE |
|
| 273 | + */ |
|
| 274 | + private function validatePostData($id = 0) |
|
| 275 | + { |
|
| 276 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 277 | + if ( ! $id) { |
|
| 278 | + \EE_Error::add_error( |
|
| 279 | + __('The event id provided was not valid.', 'event_espresso'), |
|
| 280 | + __FILE__, |
|
| 281 | + __FUNCTION__, |
|
| 282 | + __LINE__ |
|
| 283 | + ); |
|
| 284 | + return false; |
|
| 285 | + } |
|
| 286 | + // start with an empty array() |
|
| 287 | + $valid_data = array(); |
|
| 288 | + // grab valid id |
|
| 289 | + $valid_data['id'] = $id; |
|
| 290 | + // array of other form names |
|
| 291 | + $inputs_to_clean = array( |
|
| 292 | + 'event_id' => 'tkt-slctr-event-id', |
|
| 293 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
| 294 | + 'rows' => 'tkt-slctr-rows-', |
|
| 295 | + 'qty' => 'tkt-slctr-qty-', |
|
| 296 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
| 297 | + 'return_url' => 'tkt-slctr-return-url-', |
|
| 298 | + ); |
|
| 299 | + // let's track the total number of tickets ordered.' |
|
| 300 | + $valid_data['total_tickets'] = 0; |
|
| 301 | + // cycle through $inputs_to_clean array |
|
| 302 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
| 303 | + // check for POST data |
|
| 304 | + if (\EE_Registry::instance()->REQ->is_set($input_to_clean . $id)) { |
|
| 305 | + // grab value |
|
| 306 | + $input_value = \EE_Registry::instance()->REQ->get($input_to_clean . $id); |
|
| 307 | + switch ($what) { |
|
| 308 | + // integers |
|
| 309 | + case 'event_id': |
|
| 310 | + $valid_data[$what] = absint($input_value); |
|
| 311 | + // get event via the event id we put in the form |
|
| 312 | + $valid_data['event'] = \EE_Registry::instance() |
|
| 313 | + ->load_model('Event') |
|
| 314 | + ->get_one_by_ID($valid_data['event_id']); |
|
| 315 | + break; |
|
| 316 | + case 'rows': |
|
| 317 | + case 'max_atndz': |
|
| 318 | + $valid_data[$what] = absint($input_value); |
|
| 319 | + break; |
|
| 320 | + // arrays of integers |
|
| 321 | + case 'qty': |
|
| 322 | + /** @var array $row_qty */ |
|
| 323 | + $row_qty = $input_value; |
|
| 324 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
| 325 | + if ( ! is_array($row_qty)) { |
|
| 326 | + // get number of rows |
|
| 327 | + $rows = \EE_Registry::instance()->REQ->is_set('tkt-slctr-rows-' . $id) |
|
| 328 | + ? absint(\EE_Registry::instance()->REQ->get('tkt-slctr-rows-' . $id)) |
|
| 329 | + : 1; |
|
| 330 | + // explode ints by the dash |
|
| 331 | + $row_qty = explode('-', $row_qty); |
|
| 332 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
| 333 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
| 334 | + $row_qty = array($row => $qty); |
|
| 335 | + for ($x = 1; $x <= $rows; $x++) { |
|
| 336 | + if ( ! isset($row_qty[$x])) { |
|
| 337 | + $row_qty[$x] = 0; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + ksort($row_qty); |
|
| 342 | + // cycle thru values |
|
| 343 | + foreach ($row_qty as $qty) { |
|
| 344 | + $qty = absint($qty); |
|
| 345 | + // sanitize as integers |
|
| 346 | + $valid_data[$what][] = $qty; |
|
| 347 | + $valid_data['total_tickets'] += $qty; |
|
| 348 | + } |
|
| 349 | + break; |
|
| 350 | + // array of integers |
|
| 351 | + case 'ticket_id': |
|
| 352 | + $value_array = array(); |
|
| 353 | + // cycle thru values |
|
| 354 | + foreach ((array)$input_value as $key => $value) { |
|
| 355 | + // allow only numbers, letters, spaces, commas and dashes |
|
| 356 | + $value_array[$key] = wp_strip_all_tags($value); |
|
| 357 | + // get ticket via the ticket id we put in the form |
|
| 358 | + $ticket_obj = \EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($value); |
|
| 359 | + $valid_data['ticket_obj'][$key] = $ticket_obj; |
|
| 360 | + } |
|
| 361 | + $valid_data[$what] = $value_array; |
|
| 362 | + break; |
|
| 363 | + case 'return_url' : |
|
| 364 | + // grab and sanitize return-url |
|
| 365 | + $input_value = esc_url_raw($input_value); |
|
| 366 | + // was the request coming from an iframe ? if so, then: |
|
| 367 | + if (strpos($input_value, 'event_list=iframe')) { |
|
| 368 | + // get anchor fragment |
|
| 369 | + $input_value = explode('#', $input_value); |
|
| 370 | + $input_value = end($input_value); |
|
| 371 | + // use event list url instead, but append anchor |
|
| 372 | + $input_value = \EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
| 373 | + } |
|
| 374 | + $valid_data[$what] = $input_value; |
|
| 375 | + break; |
|
| 376 | + } // end switch $what |
|
| 377 | + } |
|
| 378 | + } // end foreach $inputs_to_clean |
|
| 379 | + return $valid_data; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * adds a ticket to the cart |
|
| 386 | + * |
|
| 387 | + * @param \EE_Ticket $ticket |
|
| 388 | + * @param int $qty |
|
| 389 | + * @return TRUE on success, FALSE on fail |
|
| 390 | + * @throws \EE_Error |
|
| 391 | + */ |
|
| 392 | + private function addTicketToCart(\EE_Ticket $ticket = null, $qty = 1) |
|
| 393 | + { |
|
| 394 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 395 | + // get the number of spaces left for this datetime ticket |
|
| 396 | + $available_spaces = $this->ticketDatetimeAvailability($ticket); |
|
| 397 | + // compare available spaces against the number of tickets being purchased |
|
| 398 | + if ($available_spaces >= $qty) { |
|
| 399 | + // allow addons to prevent a ticket from being added to cart |
|
| 400 | + if ( |
|
| 401 | + ! apply_filters( |
|
| 402 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
| 403 | + true, |
|
| 404 | + $ticket, |
|
| 405 | + $qty, |
|
| 406 | + $available_spaces |
|
| 407 | + ) |
|
| 408 | + ) { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 411 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
| 412 | + // add event to cart |
|
| 413 | + if (\EE_Registry::instance()->CART->add_ticket_to_cart($ticket, $qty)) { |
|
| 414 | + $this->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
| 415 | + return true; |
|
| 416 | + } |
|
| 417 | + return false; |
|
| 418 | + } |
|
| 419 | + // tickets can not be purchased but let's find the exact number left |
|
| 420 | + // for the last ticket selected PRIOR to subtracting tickets |
|
| 421 | + $available_spaces = $this->ticketDatetimeAvailability($ticket, true); |
|
| 422 | + // greedy greedy greedy eh? |
|
| 423 | + if ($available_spaces > 0) { |
|
| 424 | + if ( |
|
| 425 | + apply_filters( |
|
| 426 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_display_availability_error', |
|
| 427 | + true, |
|
| 428 | + $ticket, |
|
| 429 | + $qty, |
|
| 430 | + $available_spaces |
|
| 431 | + ) |
|
| 432 | + ) { |
|
| 433 | + $this->displayAvailabilityError($available_spaces); |
|
| 434 | + } |
|
| 435 | + } else { |
|
| 436 | + \EE_Error::add_error( |
|
| 437 | + __( |
|
| 438 | + 'We\'re sorry, but there are no available spaces left for this event at this particular date and time.', |
|
| 439 | + 'event_espresso' |
|
| 440 | + ), |
|
| 441 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 442 | + ); |
|
| 443 | + } |
|
| 444 | + return false; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * @param int $available_spaces |
|
| 451 | + * @throws \EE_Error |
|
| 452 | + */ |
|
| 453 | + private function displayAvailabilityError($available_spaces = 1) |
|
| 454 | + { |
|
| 455 | + // add error messaging - we're using the _n function that will generate |
|
| 456 | + // the appropriate singular or plural message based on the number of $available_spaces |
|
| 457 | + if (\EE_Registry::instance()->CART->all_ticket_quantity_count()) { |
|
| 458 | + $msg = sprintf( |
|
| 459 | + _n( |
|
| 460 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
| 461 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets by cancelling the current selection and choosing again, or proceed to registration.', |
|
| 462 | + $available_spaces, |
|
| 463 | + 'event_espresso' |
|
| 464 | + ), |
|
| 465 | + $available_spaces, |
|
| 466 | + '<br />' |
|
| 467 | + ); |
|
| 468 | + } else { |
|
| 469 | + $msg = sprintf( |
|
| 470 | + _n( |
|
| 471 | + 'We\'re sorry, but there is only %1$s available space left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
| 472 | + 'We\'re sorry, but there are only %1$s available spaces left for this event at this particular date and time. Please select a different number (or different combination) of tickets.', |
|
| 473 | + $available_spaces, |
|
| 474 | + 'event_espresso' |
|
| 475 | + ), |
|
| 476 | + $available_spaces, |
|
| 477 | + '<br />' |
|
| 478 | + ); |
|
| 479 | + } |
|
| 480 | + \EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * ticketDatetimeAvailability |
|
| 487 | + * creates an array of tickets plus all of the datetimes available to each ticket |
|
| 488 | + * and tracks the spaces remaining for each of those datetimes |
|
| 489 | + * |
|
| 490 | + * @param \EE_Ticket $ticket - selected ticket |
|
| 491 | + * @param bool $get_original_ticket_spaces |
|
| 492 | + * @return int |
|
| 493 | + * @throws \EE_Error |
|
| 494 | + */ |
|
| 495 | + private function ticketDatetimeAvailability(\EE_Ticket $ticket, $get_original_ticket_spaces = false) |
|
| 496 | + { |
|
| 497 | + // if the $_available_spaces array has not been set up yet... |
|
| 498 | + if ( ! isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 499 | + $this->setInitialTicketDatetimeAvailability($ticket); |
|
| 500 | + } |
|
| 501 | + $available_spaces = $ticket->qty() - $ticket->sold(); |
|
| 502 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 503 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
| 504 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
| 505 | + // if we want the original datetime availability BEFORE we started subtracting tickets ? |
|
| 506 | + if ($get_original_ticket_spaces) { |
|
| 507 | + // then grab the available spaces from the "tickets" array |
|
| 508 | + // and compare with the above to get the lowest number |
|
| 509 | + $available_spaces = min( |
|
| 510 | + $available_spaces, |
|
| 511 | + self::$_available_spaces['tickets'][$ticket->ID()][$DTD_ID] |
|
| 512 | + ); |
|
| 513 | + } else { |
|
| 514 | + // we want the updated ticket availability as stored in the "datetimes" array |
|
| 515 | + $available_spaces = min($available_spaces, self::$_available_spaces['datetimes'][$DTD_ID]); |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + return $available_spaces; |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * @param \EE_Ticket $ticket |
|
| 526 | + * @return void |
|
| 527 | + * @throws \EE_Error |
|
| 528 | + */ |
|
| 529 | + private function setInitialTicketDatetimeAvailability(\EE_Ticket $ticket) |
|
| 530 | + { |
|
| 531 | + // first, get all of the datetimes that are available to this ticket |
|
| 532 | + $datetimes = $ticket->get_many_related( |
|
| 533 | + 'Datetime', |
|
| 534 | + array( |
|
| 535 | + array( |
|
| 536 | + 'DTT_EVT_end' => array( |
|
| 537 | + '>=', |
|
| 538 | + \EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
| 539 | + ), |
|
| 540 | + ), |
|
| 541 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
| 542 | + ) |
|
| 543 | + ); |
|
| 544 | + if ( ! empty($datetimes)) { |
|
| 545 | + // now loop thru all of the datetimes |
|
| 546 | + foreach ($datetimes as $datetime) { |
|
| 547 | + if ($datetime instanceof \EE_Datetime) { |
|
| 548 | + // the number of spaces available for the datetime without considering individual ticket quantities |
|
| 549 | + $spaces_remaining = $datetime->spaces_remaining(); |
|
| 550 | + // save the total available spaces ( the lesser of the ticket qty minus the number of tickets sold |
|
| 551 | + // or the datetime spaces remaining) to this ticket using the datetime ID as the key |
|
| 552 | + self::$_available_spaces['tickets'][$ticket->ID()][$datetime->ID()] = min( |
|
| 553 | + $ticket->qty() - $ticket->sold(), |
|
| 554 | + $spaces_remaining |
|
| 555 | + ); |
|
| 556 | + // if the remaining spaces for this datetime is already set, |
|
| 557 | + // then compare that against the datetime spaces remaining, and take the lowest number, |
|
| 558 | + // else just take the datetime spaces remaining, and assign to the datetimes array |
|
| 559 | + self::$_available_spaces['datetimes'][$datetime->ID()] = isset( |
|
| 560 | + self::$_available_spaces['datetimes'][$datetime->ID()] |
|
| 561 | + ) |
|
| 562 | + ? min(self::$_available_spaces['datetimes'][$datetime->ID()], $spaces_remaining) |
|
| 563 | + : $spaces_remaining; |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + /** |
|
| 572 | + * @param \EE_Ticket $ticket |
|
| 573 | + * @param int $qty |
|
| 574 | + * @return void |
|
| 575 | + */ |
|
| 576 | + private function recalculateTicketDatetimeAvailability(\EE_Ticket $ticket, $qty = 0) |
|
| 577 | + { |
|
| 578 | + if (isset(self::$_available_spaces['tickets'][$ticket->ID()])) { |
|
| 579 | + // loop thru tickets, which will ALSO include individual ticket records AND a total |
|
| 580 | + foreach (self::$_available_spaces['tickets'][$ticket->ID()] as $DTD_ID => $spaces) { |
|
| 581 | + // subtract the qty of selected tickets from each datetime's available spaces this ticket has access to, |
|
| 582 | + self::$_available_spaces['datetimes'][$DTD_ID] -= $qty; |
|
| 583 | + } |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | 586 | |
| 587 | 587 | |
| 588 | 588 | } |
@@ -34,139 +34,139 @@ |
||
| 34 | 34 | |
| 35 | 35 | |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * the actual shortcode tag that gets registered with WordPress |
|
| 39 | - * |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public function getTag() |
|
| 43 | - { |
|
| 44 | - return 'ESPRESSO_EVENTS'; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * the time in seconds to cache the results of the processShortcode() method |
|
| 51 | - * 0 means the processShortcode() results will NOT be cached at all |
|
| 52 | - * |
|
| 53 | - * @return int |
|
| 54 | - */ |
|
| 55 | - public function cacheExpiration() |
|
| 56 | - { |
|
| 57 | - return 0; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
| 64 | - * this may be required for shortcodes that utilize a corresponding module, |
|
| 65 | - * and need to enqueue assets for that module |
|
| 66 | - * |
|
| 67 | - * @return void |
|
| 68 | - */ |
|
| 69 | - public function initializeShortcode() |
|
| 70 | - { |
|
| 71 | - EED_Events_Archive::instance()->event_list(); |
|
| 72 | - $this->shortcodeHasBeenInitialized(); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * callback that runs when the shortcode is encountered in post content. |
|
| 79 | - * IMPORTANT !!! |
|
| 80 | - * remember that shortcode content should be RETURNED and NOT echoed out |
|
| 81 | - * |
|
| 82 | - * @param array $attributes |
|
| 83 | - * @return string |
|
| 84 | - */ |
|
| 85 | - public function processShortcode($attributes = array()) |
|
| 86 | - { |
|
| 87 | - // grab attributes and merge with defaults |
|
| 88 | - $attributes = $this->getAttributes($attributes); |
|
| 89 | - // make sure we use the_excerpt() |
|
| 90 | - add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
| 91 | - // apply query filters |
|
| 92 | - add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
| 93 | - // run the query |
|
| 94 | - global $wp_query; |
|
| 95 | - // yes we have to overwrite the main wp query, but it's ok... |
|
| 96 | - // we're going to reset it again below, so everything will be Hunky Dory (amazing album) |
|
| 97 | - $wp_query = new EventListQuery($attributes); |
|
| 98 | - // check what template is loaded and load filters accordingly |
|
| 99 | - EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
| 100 | - // load our template |
|
| 101 | - $event_list = EEH_Template::locate_template( |
|
| 102 | - 'loop-espresso_events.php', |
|
| 103 | - array(), |
|
| 104 | - true, |
|
| 105 | - true |
|
| 106 | - ); |
|
| 107 | - // now reset the query and post data |
|
| 108 | - wp_reset_query(); |
|
| 109 | - wp_reset_postdata(); |
|
| 110 | - EED_Events_Archive::remove_all_events_archive_filters(); |
|
| 111 | - // remove query filters |
|
| 112 | - remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
| 113 | - // pull our content from the output buffer and return it |
|
| 114 | - return $event_list; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * merge incoming attributes with filtered defaults |
|
| 121 | - * |
|
| 122 | - * @param array $attributes |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - private function getAttributes(array $attributes) |
|
| 126 | - { |
|
| 127 | - return array_merge( |
|
| 128 | - (array)apply_filters( |
|
| 129 | - 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', |
|
| 130 | - array( |
|
| 131 | - 'title' => '', |
|
| 132 | - 'limit' => 10, |
|
| 133 | - 'css_class' => '', |
|
| 134 | - 'show_expired' => false, |
|
| 135 | - 'month' => '', |
|
| 136 | - 'category_slug' => '', |
|
| 137 | - 'order_by' => 'start_date', |
|
| 138 | - 'sort' => 'ASC', |
|
| 139 | - 'show_title' => true, |
|
| 140 | - ) |
|
| 141 | - ), |
|
| 142 | - $attributes |
|
| 143 | - ); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * array for defining custom attribute sanitization callbacks, |
|
| 150 | - * where keys match keys in your attributes array, |
|
| 151 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
| 152 | - * So for example, if you had an integer attribute named "event_id" |
|
| 153 | - * that you wanted to be sanitized using absint(), |
|
| 154 | - * then you would pass the following for your $custom_sanitization array: |
|
| 155 | - * array('event_id' => 'absint') |
|
| 156 | - * |
|
| 157 | - * @return array |
|
| 158 | - */ |
|
| 159 | - protected function customAttributeSanitizationMap() |
|
| 160 | - { |
|
| 161 | - // the following get sanitized/whitelisted in EEH_Event_Query |
|
| 162 | - return array( |
|
| 163 | - 'category_slug' => 'skip_sanitization', |
|
| 164 | - 'show_expired' => 'skip_sanitization', |
|
| 165 | - 'order_by' => 'skip_sanitization', |
|
| 166 | - 'month' => 'skip_sanitization', |
|
| 167 | - 'sort' => 'skip_sanitization', |
|
| 168 | - ); |
|
| 169 | - } |
|
| 37 | + /** |
|
| 38 | + * the actual shortcode tag that gets registered with WordPress |
|
| 39 | + * |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public function getTag() |
|
| 43 | + { |
|
| 44 | + return 'ESPRESSO_EVENTS'; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * the time in seconds to cache the results of the processShortcode() method |
|
| 51 | + * 0 means the processShortcode() results will NOT be cached at all |
|
| 52 | + * |
|
| 53 | + * @return int |
|
| 54 | + */ |
|
| 55 | + public function cacheExpiration() |
|
| 56 | + { |
|
| 57 | + return 0; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
| 64 | + * this may be required for shortcodes that utilize a corresponding module, |
|
| 65 | + * and need to enqueue assets for that module |
|
| 66 | + * |
|
| 67 | + * @return void |
|
| 68 | + */ |
|
| 69 | + public function initializeShortcode() |
|
| 70 | + { |
|
| 71 | + EED_Events_Archive::instance()->event_list(); |
|
| 72 | + $this->shortcodeHasBeenInitialized(); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * callback that runs when the shortcode is encountered in post content. |
|
| 79 | + * IMPORTANT !!! |
|
| 80 | + * remember that shortcode content should be RETURNED and NOT echoed out |
|
| 81 | + * |
|
| 82 | + * @param array $attributes |
|
| 83 | + * @return string |
|
| 84 | + */ |
|
| 85 | + public function processShortcode($attributes = array()) |
|
| 86 | + { |
|
| 87 | + // grab attributes and merge with defaults |
|
| 88 | + $attributes = $this->getAttributes($attributes); |
|
| 89 | + // make sure we use the_excerpt() |
|
| 90 | + add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true'); |
|
| 91 | + // apply query filters |
|
| 92 | + add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
| 93 | + // run the query |
|
| 94 | + global $wp_query; |
|
| 95 | + // yes we have to overwrite the main wp query, but it's ok... |
|
| 96 | + // we're going to reset it again below, so everything will be Hunky Dory (amazing album) |
|
| 97 | + $wp_query = new EventListQuery($attributes); |
|
| 98 | + // check what template is loaded and load filters accordingly |
|
| 99 | + EED_Events_Archive::instance()->template_include('loop-espresso_events.php'); |
|
| 100 | + // load our template |
|
| 101 | + $event_list = EEH_Template::locate_template( |
|
| 102 | + 'loop-espresso_events.php', |
|
| 103 | + array(), |
|
| 104 | + true, |
|
| 105 | + true |
|
| 106 | + ); |
|
| 107 | + // now reset the query and post data |
|
| 108 | + wp_reset_query(); |
|
| 109 | + wp_reset_postdata(); |
|
| 110 | + EED_Events_Archive::remove_all_events_archive_filters(); |
|
| 111 | + // remove query filters |
|
| 112 | + remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true'); |
|
| 113 | + // pull our content from the output buffer and return it |
|
| 114 | + return $event_list; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * merge incoming attributes with filtered defaults |
|
| 121 | + * |
|
| 122 | + * @param array $attributes |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + private function getAttributes(array $attributes) |
|
| 126 | + { |
|
| 127 | + return array_merge( |
|
| 128 | + (array)apply_filters( |
|
| 129 | + 'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts', |
|
| 130 | + array( |
|
| 131 | + 'title' => '', |
|
| 132 | + 'limit' => 10, |
|
| 133 | + 'css_class' => '', |
|
| 134 | + 'show_expired' => false, |
|
| 135 | + 'month' => '', |
|
| 136 | + 'category_slug' => '', |
|
| 137 | + 'order_by' => 'start_date', |
|
| 138 | + 'sort' => 'ASC', |
|
| 139 | + 'show_title' => true, |
|
| 140 | + ) |
|
| 141 | + ), |
|
| 142 | + $attributes |
|
| 143 | + ); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * array for defining custom attribute sanitization callbacks, |
|
| 150 | + * where keys match keys in your attributes array, |
|
| 151 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
| 152 | + * So for example, if you had an integer attribute named "event_id" |
|
| 153 | + * that you wanted to be sanitized using absint(), |
|
| 154 | + * then you would pass the following for your $custom_sanitization array: |
|
| 155 | + * array('event_id' => 'absint') |
|
| 156 | + * |
|
| 157 | + * @return array |
|
| 158 | + */ |
|
| 159 | + protected function customAttributeSanitizationMap() |
|
| 160 | + { |
|
| 161 | + // the following get sanitized/whitelisted in EEH_Event_Query |
|
| 162 | + return array( |
|
| 163 | + 'category_slug' => 'skip_sanitization', |
|
| 164 | + 'show_expired' => 'skip_sanitization', |
|
| 165 | + 'order_by' => 'skip_sanitization', |
|
| 166 | + 'month' => 'skip_sanitization', |
|
| 167 | + 'sort' => 'skip_sanitization', |
|
| 168 | + ); |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | 172 | |
@@ -14,115 +14,115 @@ |
||
| 14 | 14 | { |
| 15 | 15 | |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * EE_Message_Template_Group_Collection constructor. |
|
| 19 | - */ |
|
| 20 | - public function __construct() |
|
| 21 | - { |
|
| 22 | - $this->interface = 'EE_Message_Template_Group'; |
|
| 23 | - } |
|
| 17 | + /** |
|
| 18 | + * EE_Message_Template_Group_Collection constructor. |
|
| 19 | + */ |
|
| 20 | + public function __construct() |
|
| 21 | + { |
|
| 22 | + $this->interface = 'EE_Message_Template_Group'; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Adds the Message Template Group object to the repository. |
|
| 28 | - * |
|
| 29 | - * @param $message_template_group |
|
| 30 | - * @param array|int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
| 31 | - * indexing the template by key. If this template is shared among multiple events then |
|
| 32 | - * include the events as an array. |
|
| 33 | - * @return bool |
|
| 34 | - */ |
|
| 35 | - public function add($message_template_group, $EVT_ID = array()) |
|
| 36 | - { |
|
| 37 | - $EVT_ID = is_array($EVT_ID) ? $EVT_ID : (array) $EVT_ID; |
|
| 38 | - if ($message_template_group instanceof $this->interface) { |
|
| 39 | - $data['key'] = $this->getKey( |
|
| 40 | - $message_template_group->messenger(), |
|
| 41 | - $message_template_group->message_type(), |
|
| 42 | - $EVT_ID |
|
| 43 | - ); |
|
| 44 | - return parent::add($message_template_group, $data); |
|
| 45 | - } |
|
| 46 | - return false; |
|
| 47 | - } |
|
| 26 | + /** |
|
| 27 | + * Adds the Message Template Group object to the repository. |
|
| 28 | + * |
|
| 29 | + * @param $message_template_group |
|
| 30 | + * @param array|int $EVT_ID Some templates are specific to EVT, so this is provided as a way of |
|
| 31 | + * indexing the template by key. If this template is shared among multiple events then |
|
| 32 | + * include the events as an array. |
|
| 33 | + * @return bool |
|
| 34 | + */ |
|
| 35 | + public function add($message_template_group, $EVT_ID = array()) |
|
| 36 | + { |
|
| 37 | + $EVT_ID = is_array($EVT_ID) ? $EVT_ID : (array) $EVT_ID; |
|
| 38 | + if ($message_template_group instanceof $this->interface) { |
|
| 39 | + $data['key'] = $this->getKey( |
|
| 40 | + $message_template_group->messenger(), |
|
| 41 | + $message_template_group->message_type(), |
|
| 42 | + $EVT_ID |
|
| 43 | + ); |
|
| 44 | + return parent::add($message_template_group, $data); |
|
| 45 | + } |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
| 52 | - * |
|
| 53 | - * @param $GRP_ID |
|
| 54 | - * @return EE_Message_Template_Group | null |
|
| 55 | - */ |
|
| 56 | - public function get_by_ID($GRP_ID) |
|
| 57 | - { |
|
| 58 | - $this->rewind(); |
|
| 59 | - while ($this->valid()) { |
|
| 60 | - if ($this->current()->ID() === $GRP_ID) { |
|
| 61 | - /** @var EE_Message_Template_Group $message_template_group */ |
|
| 62 | - $message_template_group = $this->current(); |
|
| 63 | - $this->rewind(); |
|
| 64 | - return $message_template_group; |
|
| 65 | - } |
|
| 66 | - $this->next(); |
|
| 67 | - } |
|
| 68 | - return null; |
|
| 69 | - } |
|
| 50 | + /** |
|
| 51 | + * This retrieves any EE_Message_Template_Group in the repo by its ID. |
|
| 52 | + * |
|
| 53 | + * @param $GRP_ID |
|
| 54 | + * @return EE_Message_Template_Group | null |
|
| 55 | + */ |
|
| 56 | + public function get_by_ID($GRP_ID) |
|
| 57 | + { |
|
| 58 | + $this->rewind(); |
|
| 59 | + while ($this->valid()) { |
|
| 60 | + if ($this->current()->ID() === $GRP_ID) { |
|
| 61 | + /** @var EE_Message_Template_Group $message_template_group */ |
|
| 62 | + $message_template_group = $this->current(); |
|
| 63 | + $this->rewind(); |
|
| 64 | + return $message_template_group; |
|
| 65 | + } |
|
| 66 | + $this->next(); |
|
| 67 | + } |
|
| 68 | + return null; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Generates a hash used to identify a given Message Template Group. |
|
| 74 | - * |
|
| 75 | - * @param string $messenger The EE_messenger->name |
|
| 76 | - * @param string $message_type The EE_message_type->name |
|
| 77 | - * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
| 78 | - * @deprecated 4.9.40.rc.017 Use getKey instead. |
|
| 79 | - * @return string |
|
| 80 | - */ |
|
| 81 | - public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
| 82 | - { |
|
| 83 | - $EVT_ID = (array) $EVT_ID; |
|
| 84 | - return $this->getKey($messenger, $message_type, $EVT_ID); |
|
| 85 | - } |
|
| 72 | + /** |
|
| 73 | + * Generates a hash used to identify a given Message Template Group. |
|
| 74 | + * |
|
| 75 | + * @param string $messenger The EE_messenger->name |
|
| 76 | + * @param string $message_type The EE_message_type->name |
|
| 77 | + * @param int $EVT_ID Optional. If the template is for a specific EVT then that should be included. |
|
| 78 | + * @deprecated 4.9.40.rc.017 Use getKey instead. |
|
| 79 | + * @return string |
|
| 80 | + */ |
|
| 81 | + public function get_key($messenger, $message_type, $EVT_ID = 0) |
|
| 82 | + { |
|
| 83 | + $EVT_ID = (array) $EVT_ID; |
|
| 84 | + return $this->getKey($messenger, $message_type, $EVT_ID); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Generates a hash used to identify a given Message Template Group |
|
| 90 | - * @param string $messenger The EE_messenger->name |
|
| 91 | - * @param string $message_type The EE_message_type->name |
|
| 92 | - * @param array $EVT_ID Optional. If the template is for a specific EVT_ID (or events) then that should |
|
| 93 | - * be included. |
|
| 94 | - * @since 4.9.40.rc.017 |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function getKey($messenger, $message_type, array $EVT_ID = array()) |
|
| 98 | - { |
|
| 99 | - sort($EVT_ID); |
|
| 100 | - $EVT_ID = implode(',', array_unique($EVT_ID)); |
|
| 101 | - return md5($messenger . $message_type . $EVT_ID); |
|
| 102 | - } |
|
| 88 | + /** |
|
| 89 | + * Generates a hash used to identify a given Message Template Group |
|
| 90 | + * @param string $messenger The EE_messenger->name |
|
| 91 | + * @param string $message_type The EE_message_type->name |
|
| 92 | + * @param array $EVT_ID Optional. If the template is for a specific EVT_ID (or events) then that should |
|
| 93 | + * be included. |
|
| 94 | + * @since 4.9.40.rc.017 |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function getKey($messenger, $message_type, array $EVT_ID = array()) |
|
| 98 | + { |
|
| 99 | + sort($EVT_ID); |
|
| 100 | + $EVT_ID = implode(',', array_unique($EVT_ID)); |
|
| 101 | + return md5($messenger . $message_type . $EVT_ID); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
| 107 | - * the given string. |
|
| 108 | - * |
|
| 109 | - * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
| 110 | - * @return null|EE_Message_Template_Group |
|
| 111 | - */ |
|
| 112 | - public function get_by_key($key) |
|
| 113 | - { |
|
| 114 | - $this->rewind(); |
|
| 115 | - while ($this->valid()) { |
|
| 116 | - $data = $this->getInfo(); |
|
| 117 | - if (isset($data['key']) && $data['key'] === $key) { |
|
| 118 | - /** @var EE_Message_Template_Group $message_template_group */ |
|
| 119 | - $message_template_group = $this->current(); |
|
| 120 | - $this->rewind(); |
|
| 121 | - return $message_template_group; |
|
| 122 | - } |
|
| 123 | - $this->next(); |
|
| 124 | - } |
|
| 125 | - return null; |
|
| 126 | - } |
|
| 105 | + /** |
|
| 106 | + * This returns a saved EE_Message_Template_Group object if there is one in the repository indexed by a key matching |
|
| 107 | + * the given string. |
|
| 108 | + * |
|
| 109 | + * @param string $key @see EE_Message_Template_Group::get_key() to setup a key formatted for searching. |
|
| 110 | + * @return null|EE_Message_Template_Group |
|
| 111 | + */ |
|
| 112 | + public function get_by_key($key) |
|
| 113 | + { |
|
| 114 | + $this->rewind(); |
|
| 115 | + while ($this->valid()) { |
|
| 116 | + $data = $this->getInfo(); |
|
| 117 | + if (isset($data['key']) && $data['key'] === $key) { |
|
| 118 | + /** @var EE_Message_Template_Group $message_template_group */ |
|
| 119 | + $message_template_group = $this->current(); |
|
| 120 | + $this->rewind(); |
|
| 121 | + return $message_template_group; |
|
| 122 | + } |
|
| 123 | + $this->next(); |
|
| 124 | + } |
|
| 125 | + return null; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | 128 | } |
@@ -98,7 +98,7 @@ |
||
| 98 | 98 | { |
| 99 | 99 | sort($EVT_ID); |
| 100 | 100 | $EVT_ID = implode(',', array_unique($EVT_ID)); |
| 101 | - return md5($messenger . $message_type . $EVT_ID); |
|
| 101 | + return md5($messenger.$message_type.$EVT_ID); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | //need the MER plugin active for this test (we'll deactivate it after). |
| 16 | 16 | $I->ensurePluginActive( |
| 17 | - 'event-espresso-mer-multi-event-registration', |
|
| 18 | - 'activated' |
|
| 17 | + 'event-espresso-mer-multi-event-registration', |
|
| 18 | + 'activated' |
|
| 19 | 19 | ); |
| 20 | 20 | |
| 21 | 21 | //k now we need to make sure the registration multi-status message type is active because it isn't by default |
@@ -76,38 +76,38 @@ discard block |
||
| 76 | 76 | $I->loginAsAdmin(); |
| 77 | 77 | $I->amOnMessagesActivityListTablePage(); |
| 78 | 78 | $I->see( |
| 79 | - '[email protected]', |
|
| 80 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 81 | - 'to', |
|
| 82 | - 'Registration Multi-status Summary', |
|
| 83 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 84 | - '', |
|
| 85 | - 'Primary Registrant' |
|
| 86 | - ) |
|
| 79 | + '[email protected]', |
|
| 80 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 81 | + 'to', |
|
| 82 | + 'Registration Multi-status Summary', |
|
| 83 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 84 | + '', |
|
| 85 | + 'Primary Registrant' |
|
| 86 | + ) |
|
| 87 | 87 | ); |
| 88 | 88 | $I->see( |
| 89 | - '[email protected]', |
|
| 90 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 91 | - 'to', |
|
| 92 | - 'Registration Multi-status Summary', |
|
| 93 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
| 94 | - ) |
|
| 89 | + '[email protected]', |
|
| 90 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 91 | + 'to', |
|
| 92 | + 'Registration Multi-status Summary', |
|
| 93 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
| 94 | + ) |
|
| 95 | 95 | ); |
| 96 | 96 | //verify count |
| 97 | 97 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
| 98 | - 1, |
|
| 99 | - '[email protected]', |
|
| 100 | - 'to', |
|
| 101 | - 'Registration Multi-status Summary', |
|
| 102 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 103 | - 'Email', |
|
| 104 | - 'Primary Registrant' |
|
| 98 | + 1, |
|
| 99 | + '[email protected]', |
|
| 100 | + 'to', |
|
| 101 | + 'Registration Multi-status Summary', |
|
| 102 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 103 | + 'Email', |
|
| 104 | + 'Primary Registrant' |
|
| 105 | 105 | ); |
| 106 | 106 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
| 107 | - 1, |
|
| 108 | - '[email protected]', |
|
| 109 | - 'to', |
|
| 110 | - 'Registration Multi-status Summary' |
|
| 107 | + 1, |
|
| 108 | + '[email protected]', |
|
| 109 | + 'to', |
|
| 110 | + 'Registration Multi-status Summary' |
|
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | 113 | //okay now let's do some registrations for just the first event and verify that registration multi-status summary is NOT |
@@ -137,25 +137,25 @@ discard block |
||
| 137 | 137 | $I->loginAsAdmin(); |
| 138 | 138 | $I->amOnMessagesActivityListTablePage(); |
| 139 | 139 | $I->dontSee( |
| 140 | - '[email protected]', |
|
| 141 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 142 | - 'to', |
|
| 143 | - 'Registration Multi-status Summary', |
|
| 144 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 145 | - '', |
|
| 146 | - 'Primary Registrant' |
|
| 147 | - ) |
|
| 140 | + '[email protected]', |
|
| 141 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
| 142 | + 'to', |
|
| 143 | + 'Registration Multi-status Summary', |
|
| 144 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
| 145 | + '', |
|
| 146 | + 'Primary Registrant' |
|
| 147 | + ) |
|
| 148 | 148 | ); |
| 149 | 149 | //there should still only be one admin multi-status summary thing. |
| 150 | 150 | $I->verifyMatchingCountofTextInMessageActivityListTableFor( |
| 151 | - 1, |
|
| 152 | - '[email protected]', |
|
| 153 | - 'to', |
|
| 154 | - 'Registration Multi-status Summary' |
|
| 151 | + 1, |
|
| 152 | + '[email protected]', |
|
| 153 | + 'to', |
|
| 154 | + 'Registration Multi-status Summary' |
|
| 155 | 155 | ); |
| 156 | 156 | |
| 157 | 157 | //deactivate MER plugin so its not active for future tests |
| 158 | 158 | $I->ensurePluginDeactivated( |
| 159 | - 'event-espresso-mer-multi-event-registration', |
|
| 160 | - 'Plugin deactivated' |
|
| 159 | + 'event-espresso-mer-multi-event-registration', |
|
| 160 | + 'Plugin deactivated' |
|
| 161 | 161 | ); |
| 162 | 162 | \ No newline at end of file |
@@ -13,1086 +13,1086 @@ |
||
| 13 | 13 | class EED_Messages extends EED_Module |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * This holds the EE_messages controller |
|
| 18 | - * |
|
| 19 | - * @deprecated 4.9.0 |
|
| 20 | - * @var EE_messages $_EEMSG |
|
| 21 | - */ |
|
| 22 | - protected static $_EEMSG; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 26 | - */ |
|
| 27 | - protected static $_message_resource_manager; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * This holds the EE_Messages_Processor business class. |
|
| 31 | - * |
|
| 32 | - * @type EE_Messages_Processor |
|
| 33 | - */ |
|
| 34 | - protected static $_MSG_PROCESSOR; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * holds all the paths for various messages components. |
|
| 38 | - * Utilized by autoloader registry |
|
| 39 | - * |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - protected static $_MSG_PATHS; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * This will hold an array of messages template packs that are registered in the messages system. |
|
| 47 | - * Format is: |
|
| 48 | - * array( |
|
| 49 | - * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 50 | - * ) |
|
| 51 | - * |
|
| 52 | - * @var EE_Messages_Template_Pack[] |
|
| 53 | - */ |
|
| 54 | - protected static $_TMP_PACKS = array(); |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @return EED_Messages |
|
| 59 | - */ |
|
| 60 | - public static function instance() |
|
| 61 | - { |
|
| 62 | - return parent::get_instance(__CLASS__); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 68 | - * |
|
| 69 | - * @since 4.5.0 |
|
| 70 | - * @return void |
|
| 71 | - */ |
|
| 72 | - public static function set_hooks() |
|
| 73 | - { |
|
| 74 | - //actions |
|
| 75 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 76 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 77 | - array('EED_Messages', 'maybe_registration'), 10, 2); |
|
| 78 | - //filters |
|
| 79 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 80 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 81 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 82 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 83 | - //register routes |
|
| 84 | - self::_register_routes(); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 89 | - * |
|
| 90 | - * @access public |
|
| 91 | - * @return void |
|
| 92 | - */ |
|
| 93 | - public static function set_hooks_admin() |
|
| 94 | - { |
|
| 95 | - //actions |
|
| 96 | - add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 97 | - add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 98 | - array('EED_Messages', 'payment_reminder'), 10); |
|
| 99 | - add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 100 | - array('EED_Messages', 'maybe_registration'), 10, 3); |
|
| 101 | - add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 102 | - array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
| 103 | - add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 104 | - array('EED_Messages', 'cancelled_registration'), 10); |
|
| 105 | - add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 106 | - array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
| 107 | - //filters |
|
| 108 | - add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 109 | - array('EED_Messages', 'process_resend'), 10, 2); |
|
| 110 | - add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 111 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 112 | - add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 113 | - array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * All the message triggers done by route go in here. |
|
| 119 | - * |
|
| 120 | - * @since 4.5.0 |
|
| 121 | - * @return void |
|
| 122 | - */ |
|
| 123 | - protected static function _register_routes() |
|
| 124 | - { |
|
| 125 | - EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 126 | - EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 127 | - EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 128 | - EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 129 | - do_action('AHEE__EED_Messages___register_routes'); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * This is called when a browser display trigger is executed. |
|
| 135 | - * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 136 | - * browser. |
|
| 137 | - * |
|
| 138 | - * @since 4.9.0 |
|
| 139 | - * @param WP $WP |
|
| 140 | - */ |
|
| 141 | - public function browser_trigger($WP) |
|
| 142 | - { |
|
| 143 | - //ensure controller is loaded |
|
| 144 | - self::_load_controller(); |
|
| 145 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 146 | - try { |
|
| 147 | - $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 148 | - self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 149 | - } catch (EE_Error $e) { |
|
| 150 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 151 | - 'event_espresso'); |
|
| 152 | - // add specific message for developers if WP_DEBUG in on |
|
| 153 | - $error_msg .= '||' . $e->getMessage(); |
|
| 154 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * This is called when a browser error trigger is executed. |
|
| 161 | - * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 162 | - * message and display it. |
|
| 163 | - * |
|
| 164 | - * @since 4.9.0 |
|
| 165 | - * @param $WP |
|
| 166 | - */ |
|
| 167 | - public function browser_error_trigger($WP) |
|
| 168 | - { |
|
| 169 | - $token = EE_Registry::instance()->REQ->get('token'); |
|
| 170 | - if ($token) { |
|
| 171 | - $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 172 | - if ($message instanceof EE_Message) { |
|
| 173 | - header('HTTP/1.1 200 OK'); |
|
| 174 | - $error_msg = nl2br($message->error_message()); |
|
| 175 | - ?> |
|
| 16 | + /** |
|
| 17 | + * This holds the EE_messages controller |
|
| 18 | + * |
|
| 19 | + * @deprecated 4.9.0 |
|
| 20 | + * @var EE_messages $_EEMSG |
|
| 21 | + */ |
|
| 22 | + protected static $_EEMSG; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
| 26 | + */ |
|
| 27 | + protected static $_message_resource_manager; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * This holds the EE_Messages_Processor business class. |
|
| 31 | + * |
|
| 32 | + * @type EE_Messages_Processor |
|
| 33 | + */ |
|
| 34 | + protected static $_MSG_PROCESSOR; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * holds all the paths for various messages components. |
|
| 38 | + * Utilized by autoloader registry |
|
| 39 | + * |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + protected static $_MSG_PATHS; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * This will hold an array of messages template packs that are registered in the messages system. |
|
| 47 | + * Format is: |
|
| 48 | + * array( |
|
| 49 | + * 'template_pack_dbref' => EE_Messages_Template_Pack (instance) |
|
| 50 | + * ) |
|
| 51 | + * |
|
| 52 | + * @var EE_Messages_Template_Pack[] |
|
| 53 | + */ |
|
| 54 | + protected static $_TMP_PACKS = array(); |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @return EED_Messages |
|
| 59 | + */ |
|
| 60 | + public static function instance() |
|
| 61 | + { |
|
| 62 | + return parent::get_instance(__CLASS__); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 68 | + * |
|
| 69 | + * @since 4.5.0 |
|
| 70 | + * @return void |
|
| 71 | + */ |
|
| 72 | + public static function set_hooks() |
|
| 73 | + { |
|
| 74 | + //actions |
|
| 75 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 76 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 77 | + array('EED_Messages', 'maybe_registration'), 10, 2); |
|
| 78 | + //filters |
|
| 79 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 80 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 81 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 82 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 83 | + //register routes |
|
| 84 | + self::_register_routes(); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 89 | + * |
|
| 90 | + * @access public |
|
| 91 | + * @return void |
|
| 92 | + */ |
|
| 93 | + public static function set_hooks_admin() |
|
| 94 | + { |
|
| 95 | + //actions |
|
| 96 | + add_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', array('EED_Messages', 'payment'), 10, 2); |
|
| 97 | + add_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 98 | + array('EED_Messages', 'payment_reminder'), 10); |
|
| 99 | + add_action('AHEE__EE_Registration_Processor__trigger_registration_update_notifications', |
|
| 100 | + array('EED_Messages', 'maybe_registration'), 10, 3); |
|
| 101 | + add_action('AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 102 | + array('EED_Messages', 'send_newsletter_message'), 10, 2); |
|
| 103 | + add_action('AHEE__EES_Espresso_Cancelled__process_shortcode__transaction', |
|
| 104 | + array('EED_Messages', 'cancelled_registration'), 10); |
|
| 105 | + add_action('AHEE__EE_Admin_Page___process_admin_payment_notification', |
|
| 106 | + array('EED_Messages', 'process_admin_payment'), 10, 1); |
|
| 107 | + //filters |
|
| 108 | + add_filter('FHEE__EE_Admin_Page___process_resend_registration__success', |
|
| 109 | + array('EED_Messages', 'process_resend'), 10, 2); |
|
| 110 | + add_filter('FHEE__EE_Registration__receipt_url__receipt_url', |
|
| 111 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 112 | + add_filter('FHEE__EE_Registration__invoice_url__invoice_url', |
|
| 113 | + array('EED_Messages', 'registration_message_trigger_url'), 10, 4); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * All the message triggers done by route go in here. |
|
| 119 | + * |
|
| 120 | + * @since 4.5.0 |
|
| 121 | + * @return void |
|
| 122 | + */ |
|
| 123 | + protected static function _register_routes() |
|
| 124 | + { |
|
| 125 | + EE_Config::register_route('msg_url_trigger', 'Messages', 'run'); |
|
| 126 | + EE_Config::register_route('msg_cron_trigger', 'Messages', 'execute_batch_request'); |
|
| 127 | + EE_Config::register_route('msg_browser_trigger', 'Messages', 'browser_trigger'); |
|
| 128 | + EE_Config::register_route('msg_browser_error_trigger', 'Messages', 'browser_error_trigger'); |
|
| 129 | + do_action('AHEE__EED_Messages___register_routes'); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * This is called when a browser display trigger is executed. |
|
| 135 | + * The browser display trigger is typically used when a already generated message is displayed directly in the |
|
| 136 | + * browser. |
|
| 137 | + * |
|
| 138 | + * @since 4.9.0 |
|
| 139 | + * @param WP $WP |
|
| 140 | + */ |
|
| 141 | + public function browser_trigger($WP) |
|
| 142 | + { |
|
| 143 | + //ensure controller is loaded |
|
| 144 | + self::_load_controller(); |
|
| 145 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 146 | + try { |
|
| 147 | + $mtg = new EE_Message_Generated_From_Token($token, 'html', self::$_message_resource_manager); |
|
| 148 | + self::$_MSG_PROCESSOR->generate_and_send_now($mtg); |
|
| 149 | + } catch (EE_Error $e) { |
|
| 150 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 151 | + 'event_espresso'); |
|
| 152 | + // add specific message for developers if WP_DEBUG in on |
|
| 153 | + $error_msg .= '||' . $e->getMessage(); |
|
| 154 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * This is called when a browser error trigger is executed. |
|
| 161 | + * When triggered this will grab the EE_Message matching the token in the request and use that to get the error |
|
| 162 | + * message and display it. |
|
| 163 | + * |
|
| 164 | + * @since 4.9.0 |
|
| 165 | + * @param $WP |
|
| 166 | + */ |
|
| 167 | + public function browser_error_trigger($WP) |
|
| 168 | + { |
|
| 169 | + $token = EE_Registry::instance()->REQ->get('token'); |
|
| 170 | + if ($token) { |
|
| 171 | + $message = EEM_Message::instance()->get_one_by_token($token); |
|
| 172 | + if ($message instanceof EE_Message) { |
|
| 173 | + header('HTTP/1.1 200 OK'); |
|
| 174 | + $error_msg = nl2br($message->error_message()); |
|
| 175 | + ?> |
|
| 176 | 176 | <!DOCTYPE html> |
| 177 | 177 | <html> |
| 178 | 178 | <head></head> |
| 179 | 179 | <body> |
| 180 | 180 | <?php echo empty($error_msg) |
| 181 | - ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
| 182 | - 'event_espresso') |
|
| 183 | - : wp_kses( |
|
| 184 | - $error_msg, |
|
| 185 | - array( |
|
| 186 | - 'a' => array( |
|
| 187 | - 'href' => array(), |
|
| 188 | - 'title' => array(), |
|
| 189 | - ), |
|
| 190 | - 'span' => array(), |
|
| 191 | - 'div' => array(), |
|
| 192 | - 'p' => array(), |
|
| 193 | - 'strong' => array(), |
|
| 194 | - 'em' => array(), |
|
| 195 | - 'br' => array(), |
|
| 196 | - ) |
|
| 197 | - ); ?> |
|
| 181 | + ? esc_html__('Unfortunately, we were unable to capture the error message for this message.', |
|
| 182 | + 'event_espresso') |
|
| 183 | + : wp_kses( |
|
| 184 | + $error_msg, |
|
| 185 | + array( |
|
| 186 | + 'a' => array( |
|
| 187 | + 'href' => array(), |
|
| 188 | + 'title' => array(), |
|
| 189 | + ), |
|
| 190 | + 'span' => array(), |
|
| 191 | + 'div' => array(), |
|
| 192 | + 'p' => array(), |
|
| 193 | + 'strong' => array(), |
|
| 194 | + 'em' => array(), |
|
| 195 | + 'br' => array(), |
|
| 196 | + ) |
|
| 197 | + ); ?> |
|
| 198 | 198 | </body> |
| 199 | 199 | </html> |
| 200 | 200 | <?php |
| 201 | - exit; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - return; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * This runs when the msg_url_trigger route has initiated. |
|
| 210 | - * |
|
| 211 | - * @since 4.5.0 |
|
| 212 | - * @param WP $WP |
|
| 213 | - * @throws EE_Error |
|
| 214 | - * @return void |
|
| 215 | - */ |
|
| 216 | - public function run($WP) |
|
| 217 | - { |
|
| 218 | - //ensure controller is loaded |
|
| 219 | - self::_load_controller(); |
|
| 220 | - // attempt to process message |
|
| 221 | - try { |
|
| 222 | - /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 223 | - $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 224 | - self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 225 | - } catch (EE_Error $e) { |
|
| 226 | - $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 227 | - 'event_espresso'); |
|
| 228 | - // add specific message for developers if WP_DEBUG in on |
|
| 229 | - $error_msg .= '||' . $e->getMessage(); |
|
| 230 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * This is triggered by the 'msg_cron_trigger' route. |
|
| 237 | - * |
|
| 238 | - * @param WP $WP |
|
| 239 | - */ |
|
| 240 | - public function execute_batch_request($WP) |
|
| 241 | - { |
|
| 242 | - $this->run_cron(); |
|
| 243 | - header('HTTP/1.1 200 OK'); |
|
| 244 | - exit(); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 250 | - * request. |
|
| 251 | - */ |
|
| 252 | - public function run_cron() |
|
| 253 | - { |
|
| 254 | - self::_load_controller(); |
|
| 255 | - //get required vars |
|
| 256 | - $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 257 | - $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 258 | - |
|
| 259 | - //now let's verify transient, if not valid exit immediately |
|
| 260 | - if (! get_transient($transient_key)) { |
|
| 261 | - /** |
|
| 262 | - * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
| 263 | - */ |
|
| 264 | - trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - //if made it here, lets' delete the transient to keep the db clean |
|
| 268 | - delete_transient($transient_key); |
|
| 269 | - |
|
| 270 | - if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 271 | - |
|
| 272 | - $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 273 | - if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 274 | - self::$_MSG_PROCESSOR->$method(); |
|
| 275 | - } else { |
|
| 276 | - //no matching task |
|
| 277 | - /** |
|
| 278 | - * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
| 279 | - */ |
|
| 280 | - trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 281 | - $cron_type))); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * This is used to retrieve the template pack for the given name. |
|
| 291 | - * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 292 | - * the default template pack is returned. |
|
| 293 | - * |
|
| 294 | - * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 295 | - * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 296 | - * in generating the Pack class name). |
|
| 297 | - * @return EE_Messages_Template_Pack |
|
| 298 | - */ |
|
| 299 | - public static function get_template_pack($template_pack_name) |
|
| 300 | - { |
|
| 301 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 302 | - return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Retrieves an array of all template packs. |
|
| 308 | - * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 309 | - * |
|
| 310 | - * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 311 | - * @return EE_Messages_Template_Pack[] |
|
| 312 | - */ |
|
| 313 | - public static function get_template_packs() |
|
| 314 | - { |
|
| 315 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 316 | - |
|
| 317 | - //for backward compat, let's make sure this returns in the same format as originally. |
|
| 318 | - $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 319 | - $template_pack_collection->rewind(); |
|
| 320 | - $template_packs = array(); |
|
| 321 | - while ($template_pack_collection->valid()) { |
|
| 322 | - $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
| 323 | - $template_pack_collection->next(); |
|
| 324 | - } |
|
| 325 | - return $template_packs; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 331 | - * |
|
| 332 | - * @since 4.5.0 |
|
| 333 | - * @return void |
|
| 334 | - */ |
|
| 335 | - public static function set_autoloaders() |
|
| 336 | - { |
|
| 337 | - if (empty(self::$_MSG_PATHS)) { |
|
| 338 | - self::_set_messages_paths(); |
|
| 339 | - foreach (self::$_MSG_PATHS as $path) { |
|
| 340 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 341 | - } |
|
| 342 | - // add aliases |
|
| 343 | - EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 344 | - EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 351 | - * for use by the Messages Autoloaders |
|
| 352 | - * |
|
| 353 | - * @since 4.5.0 |
|
| 354 | - * @return void. |
|
| 355 | - */ |
|
| 356 | - protected static function _set_messages_paths() |
|
| 357 | - { |
|
| 358 | - $dir_ref = array( |
|
| 359 | - 'messages/message_type', |
|
| 360 | - 'messages/messenger', |
|
| 361 | - 'messages/defaults', |
|
| 362 | - 'messages/defaults/email', |
|
| 363 | - 'messages/data_class', |
|
| 364 | - 'messages/validators', |
|
| 365 | - 'messages/validators/email', |
|
| 366 | - 'messages/validators/html', |
|
| 367 | - 'shortcodes', |
|
| 368 | - ); |
|
| 369 | - $paths = array(); |
|
| 370 | - foreach ($dir_ref as $index => $dir) { |
|
| 371 | - $paths[$index] = EE_LIBRARIES . $dir; |
|
| 372 | - } |
|
| 373 | - self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * Takes care of loading dependencies |
|
| 379 | - * |
|
| 380 | - * @since 4.5.0 |
|
| 381 | - * @return void |
|
| 382 | - */ |
|
| 383 | - protected static function _load_controller() |
|
| 384 | - { |
|
| 385 | - if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 386 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
| 387 | - self::set_autoloaders(); |
|
| 388 | - self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 389 | - self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 390 | - self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * @param EE_Transaction $transaction |
|
| 397 | - */ |
|
| 398 | - public static function payment_reminder(EE_Transaction $transaction) |
|
| 399 | - { |
|
| 400 | - self::_load_controller(); |
|
| 401 | - $data = array($transaction, null); |
|
| 402 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Any messages triggers for after successful gateway payments should go in here. |
|
| 408 | - * |
|
| 409 | - * @param EE_Transaction object |
|
| 410 | - * @param EE_Payment object |
|
| 411 | - * @return void |
|
| 412 | - */ |
|
| 413 | - public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
| 414 | - { |
|
| 415 | - self::_load_controller(); |
|
| 416 | - $data = array($transaction, $payment); |
|
| 417 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 418 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 419 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 420 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 421 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * @param EE_Transaction $transaction |
|
| 427 | - */ |
|
| 428 | - public static function cancelled_registration(EE_Transaction $transaction) |
|
| 429 | - { |
|
| 430 | - self::_load_controller(); |
|
| 431 | - $data = array($transaction, null); |
|
| 432 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Trigger for Registration messages |
|
| 438 | - * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 439 | - * incoming transaction. |
|
| 440 | - * |
|
| 441 | - * @param EE_Registration $registration |
|
| 442 | - * @param array $extra_details |
|
| 443 | - * @return void |
|
| 444 | - */ |
|
| 445 | - public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 446 | - { |
|
| 447 | - |
|
| 448 | - if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 449 | - //no messages please |
|
| 450 | - return; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - |
|
| 454 | - //get all registrations so we make sure we send messages for the right status. |
|
| 455 | - $all_registrations = $registration->transaction()->registrations(); |
|
| 456 | - |
|
| 457 | - //cached array of statuses so we only trigger messages once per status. |
|
| 458 | - $statuses_sent = array(); |
|
| 459 | - self::_load_controller(); |
|
| 460 | - $mtgs = array(); |
|
| 461 | - |
|
| 462 | - //loop through registrations and trigger messages once per status. |
|
| 463 | - foreach ($all_registrations as $reg) { |
|
| 464 | - |
|
| 465 | - //already triggered? |
|
| 466 | - if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 467 | - continue; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 471 | - $mtgs = array_merge( |
|
| 472 | - $mtgs, |
|
| 473 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 474 | - $message_type, |
|
| 475 | - array($registration->transaction(), null, $reg->status_ID()) |
|
| 476 | - ) |
|
| 477 | - ); |
|
| 478 | - $statuses_sent[] = $reg->status_ID(); |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - if (count($statuses_sent) > 1) { |
|
| 482 | - $mtgs = array_merge( |
|
| 483 | - $mtgs, |
|
| 484 | - self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 485 | - 'registration_summary', |
|
| 486 | - array($registration->transaction(), null) |
|
| 487 | - ) |
|
| 488 | - ); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - //batch queue and initiate request |
|
| 492 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 493 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * This is a helper method used to very whether a registration notification should be sent or |
|
| 499 | - * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 500 | - * |
|
| 501 | - * @param EE_Registration $registration [description] |
|
| 502 | - * @param array $extra_details [description] |
|
| 503 | - * @return bool true = send away, false = nope halt the presses. |
|
| 504 | - */ |
|
| 505 | - protected static function _verify_registration_notification_send( |
|
| 506 | - EE_Registration $registration, |
|
| 507 | - $extra_details = array() |
|
| 508 | - ) { |
|
| 509 | - //self::log( |
|
| 510 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
| 511 | - // $registration->transaction(), |
|
| 512 | - // array( '$extra_details' => $extra_details ) |
|
| 513 | - //); |
|
| 514 | - // currently only using this to send messages for the primary registrant |
|
| 515 | - if (! $registration->is_primary_registrant()) { |
|
| 516 | - return false; |
|
| 517 | - } |
|
| 518 | - // first we check if we're in admin and not doing front ajax |
|
| 519 | - if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 520 | - //make sure appropriate admin params are set for sending messages |
|
| 521 | - if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
| 522 | - //no messages sent please. |
|
| 523 | - return false; |
|
| 524 | - } |
|
| 525 | - } else { |
|
| 526 | - // frontend request (either regular or via AJAX) |
|
| 527 | - // TXN is NOT finalized ? |
|
| 528 | - if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 529 | - return false; |
|
| 530 | - } |
|
| 531 | - // return visit but nothing changed ??? |
|
| 532 | - if ( |
|
| 533 | - isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 534 | - $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 535 | - ) { |
|
| 536 | - return false; |
|
| 537 | - } |
|
| 538 | - // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 539 | - if ( |
|
| 540 | - ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 541 | - $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 542 | - ) { |
|
| 543 | - return false; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - // release the kraken |
|
| 547 | - return true; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 553 | - * status id. |
|
| 554 | - * |
|
| 555 | - * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 556 | - * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 557 | - * @param string $reg_status |
|
| 558 | - * @return array |
|
| 559 | - */ |
|
| 560 | - protected static function _get_reg_status_array($reg_status = '') |
|
| 561 | - { |
|
| 562 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 563 | - return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 564 | - ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 565 | - : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Simply returns the payment message type for the given payment status. |
|
| 571 | - * |
|
| 572 | - * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 573 | - * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 574 | - * @param string $payment_status The payment status being matched. |
|
| 575 | - * @return string|bool The payment message type slug matching the status or false if no match. |
|
| 576 | - */ |
|
| 577 | - protected static function _get_payment_message_type($payment_status) |
|
| 578 | - { |
|
| 579 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 580 | - return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 581 | - ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 582 | - : false; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 588 | - * |
|
| 589 | - * @access public |
|
| 590 | - * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 591 | - * @return bool success/fail |
|
| 592 | - */ |
|
| 593 | - public static function process_resend($req_data) |
|
| 594 | - { |
|
| 595 | - self::_load_controller(); |
|
| 596 | - |
|
| 597 | - //if $msgID in this request then skip to the new resend_message |
|
| 598 | - if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 599 | - return self::resend_message(); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 603 | - $req_data = (array)$req_data; |
|
| 604 | - foreach ($req_data as $request_key => $request_value) { |
|
| 605 | - EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
| 609 | - return false; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - try { |
|
| 613 | - self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 614 | - self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 615 | - } catch (EE_Error $e) { |
|
| 616 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 617 | - return false; |
|
| 618 | - } |
|
| 619 | - EE_Error::add_success( |
|
| 620 | - __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 621 | - ); |
|
| 622 | - return true; //everything got queued. |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - /** |
|
| 627 | - * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 628 | - * |
|
| 629 | - * @return bool |
|
| 630 | - */ |
|
| 631 | - public static function resend_message() |
|
| 632 | - { |
|
| 633 | - self::_load_controller(); |
|
| 634 | - |
|
| 635 | - $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 636 | - if (! $msgID) { |
|
| 637 | - EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
| 638 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 639 | - return false; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
| 643 | - |
|
| 644 | - //setup success message. |
|
| 645 | - $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 646 | - EE_Error::add_success(sprintf( |
|
| 647 | - _n( |
|
| 648 | - 'There was %d message queued for resending.', |
|
| 649 | - 'There were %d messages queued for resending.', |
|
| 650 | - $count_ready_for_resend, |
|
| 651 | - 'event_espresso' |
|
| 652 | - ), |
|
| 653 | - $count_ready_for_resend |
|
| 654 | - )); |
|
| 655 | - return true; |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Message triggers for manual payment applied by admin |
|
| 661 | - * |
|
| 662 | - * @param EE_Payment $payment EE_payment object |
|
| 663 | - * @return bool success/fail |
|
| 664 | - */ |
|
| 665 | - public static function process_admin_payment(EE_Payment $payment) |
|
| 666 | - { |
|
| 667 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 668 | - //we need to get the transaction object |
|
| 669 | - $transaction = $payment->transaction(); |
|
| 670 | - if ($transaction instanceof EE_Transaction) { |
|
| 671 | - $data = array($transaction, $payment); |
|
| 672 | - $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 673 | - |
|
| 674 | - //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 675 | - $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 676 | - |
|
| 677 | - //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 678 | - $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
| 679 | - |
|
| 680 | - self::_load_controller(); |
|
| 681 | - |
|
| 682 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 683 | - |
|
| 684 | - //get count of queued for generation |
|
| 685 | - $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
| 686 | - EEM_Message::status_incomplete, |
|
| 687 | - EEM_Message::status_idle, |
|
| 688 | - )); |
|
| 689 | - |
|
| 690 | - if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 691 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 692 | - return true; |
|
| 693 | - } else { |
|
| 694 | - $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
| 695 | - /** |
|
| 696 | - * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 697 | - * IMMEDIATE generation. |
|
| 698 | - */ |
|
| 699 | - if ($count_failed > 0) { |
|
| 700 | - EE_Error::add_error(sprintf( |
|
| 701 | - _n( |
|
| 702 | - 'The payment notification generation failed.', |
|
| 703 | - '%d payment notifications failed being sent.', |
|
| 704 | - $count_failed, |
|
| 705 | - 'event_espresso' |
|
| 706 | - ), |
|
| 707 | - $count_failed |
|
| 708 | - ), __FILE__, __FUNCTION__, __LINE__); |
|
| 709 | - |
|
| 710 | - return false; |
|
| 711 | - } else { |
|
| 712 | - add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 713 | - return true; |
|
| 714 | - } |
|
| 715 | - } |
|
| 716 | - } else { |
|
| 717 | - EE_Error::add_error( |
|
| 718 | - 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 719 | - 'event_espresso' |
|
| 720 | - ); |
|
| 721 | - return false; |
|
| 722 | - } |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - |
|
| 726 | - /** |
|
| 727 | - * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 728 | - * |
|
| 729 | - * @since 4.3.0 |
|
| 730 | - * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 731 | - * @param int $grp_id a specific message template group id. |
|
| 732 | - * @return void |
|
| 733 | - */ |
|
| 734 | - public static function send_newsletter_message($registrations, $grp_id) |
|
| 735 | - { |
|
| 736 | - //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 737 | - EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
| 738 | - self::_load_controller(); |
|
| 739 | - self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - |
|
| 743 | - /** |
|
| 744 | - * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 745 | - * |
|
| 746 | - * @since 4.3.0 |
|
| 747 | - * @param string $registration_message_trigger_url |
|
| 748 | - * @param EE_Registration $registration |
|
| 749 | - * @param string $messenger |
|
| 750 | - * @param string $message_type |
|
| 751 | - * @return string |
|
| 752 | - */ |
|
| 753 | - public static function registration_message_trigger_url( |
|
| 754 | - $registration_message_trigger_url, |
|
| 755 | - EE_Registration $registration, |
|
| 756 | - $messenger = 'html', |
|
| 757 | - $message_type = 'invoice' |
|
| 758 | - ) { |
|
| 759 | - // whitelist $messenger |
|
| 760 | - switch ($messenger) { |
|
| 761 | - case 'pdf' : |
|
| 762 | - $sending_messenger = 'pdf'; |
|
| 763 | - $generating_messenger = 'html'; |
|
| 764 | - break; |
|
| 765 | - case 'html' : |
|
| 766 | - default : |
|
| 767 | - $sending_messenger = 'html'; |
|
| 768 | - $generating_messenger = 'html'; |
|
| 769 | - break; |
|
| 770 | - } |
|
| 771 | - // whitelist $message_type |
|
| 772 | - switch ($message_type) { |
|
| 773 | - case 'receipt' : |
|
| 774 | - $message_type = 'receipt'; |
|
| 775 | - break; |
|
| 776 | - case 'invoice' : |
|
| 777 | - default : |
|
| 778 | - $message_type = 'invoice'; |
|
| 779 | - break; |
|
| 780 | - } |
|
| 781 | - // verify that both the messenger AND the message type are active |
|
| 782 | - if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
| 783 | - //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 784 | - $template_query_params = array( |
|
| 785 | - 'MTP_is_active' => true, |
|
| 786 | - 'MTP_messenger' => $generating_messenger, |
|
| 787 | - 'MTP_message_type' => $message_type, |
|
| 788 | - 'Event.EVT_ID' => $registration->event_ID(), |
|
| 789 | - ); |
|
| 790 | - //get the message template group. |
|
| 791 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 792 | - //if we don't have an EE_Message_Template_Group then return |
|
| 793 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 794 | - // remove EVT_ID from query params so that global templates get picked up |
|
| 795 | - unset($template_query_params['Event.EVT_ID']); |
|
| 796 | - //get global template as the fallback |
|
| 797 | - $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 798 | - } |
|
| 799 | - //if we don't have an EE_Message_Template_Group then return |
|
| 800 | - if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 801 | - return ''; |
|
| 802 | - } |
|
| 803 | - // generate the URL |
|
| 804 | - $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 805 | - $sending_messenger, |
|
| 806 | - $generating_messenger, |
|
| 807 | - 'purchaser', |
|
| 808 | - $message_type, |
|
| 809 | - $registration, |
|
| 810 | - $msg_template_group->ID(), |
|
| 811 | - $registration->transaction_ID() |
|
| 812 | - ); |
|
| 813 | - |
|
| 814 | - } |
|
| 815 | - return $registration_message_trigger_url; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - |
|
| 819 | - /** |
|
| 820 | - * Use to generate and return a message preview! |
|
| 821 | - * |
|
| 822 | - * @param string $type This should correspond with a valid message type |
|
| 823 | - * @param string $context This should correspond with a valid context for the message type |
|
| 824 | - * @param string $messenger This should correspond with a valid messenger. |
|
| 825 | - * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 826 | - * preview |
|
| 827 | - * @return string|bool The body of the message or if send is requested, sends. |
|
| 828 | - */ |
|
| 829 | - public static function preview_message($type, $context, $messenger, $send = false) |
|
| 830 | - { |
|
| 831 | - self::_load_controller(); |
|
| 832 | - $mtg = new EE_Message_To_Generate( |
|
| 833 | - $messenger, |
|
| 834 | - $type, |
|
| 835 | - array(), |
|
| 836 | - $context, |
|
| 837 | - true |
|
| 838 | - ); |
|
| 839 | - $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 840 | - if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 841 | - return $generated_preview_queue->get_message_repository()->current()->content(); |
|
| 842 | - } else { |
|
| 843 | - return $generated_preview_queue; |
|
| 844 | - } |
|
| 845 | - } |
|
| 846 | - |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 850 | - * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 851 | - * content found in the EE_Message objects in the queue. |
|
| 852 | - * |
|
| 853 | - * @since 4.9.0 |
|
| 854 | - * @param string $messenger a string matching a valid active messenger in the system |
|
| 855 | - * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 856 | - * type name is still required to send along the message type to the |
|
| 857 | - * messenger because this is used for determining what specific |
|
| 858 | - * variations might be loaded for the generated message. |
|
| 859 | - * @param EE_Messages_Queue $queue |
|
| 860 | - * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 861 | - * aggregate EE_Message object. |
|
| 862 | - * @return bool success or fail. |
|
| 863 | - */ |
|
| 864 | - public static function send_message_with_messenger_only( |
|
| 865 | - $messenger, |
|
| 866 | - $message_type, |
|
| 867 | - EE_Messages_Queue $queue, |
|
| 868 | - $custom_subject = '' |
|
| 869 | - ) { |
|
| 870 | - self::_load_controller(); |
|
| 871 | - /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 872 | - $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 873 | - 'Message_To_Generate_From_Queue', |
|
| 874 | - array( |
|
| 875 | - $messenger, |
|
| 876 | - $message_type, |
|
| 877 | - $queue, |
|
| 878 | - $custom_subject, |
|
| 879 | - ) |
|
| 880 | - ); |
|
| 881 | - return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - |
|
| 885 | - /** |
|
| 886 | - * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 887 | - * |
|
| 888 | - * @since 4.9.0 |
|
| 889 | - * @param array $message_ids An array of message ids |
|
| 890 | - * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 891 | - * messages. |
|
| 892 | - */ |
|
| 893 | - public static function generate_now($message_ids) |
|
| 894 | - { |
|
| 895 | - self::_load_controller(); |
|
| 896 | - $messages = EEM_Message::instance()->get_all( |
|
| 897 | - array( |
|
| 898 | - 0 => array( |
|
| 899 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 900 | - 'STS_ID' => EEM_Message::status_incomplete, |
|
| 901 | - ), |
|
| 902 | - ) |
|
| 903 | - ); |
|
| 904 | - $generated_queue = false; |
|
| 905 | - if ($messages) { |
|
| 906 | - $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 910 | - EE_Error::add_error( |
|
| 911 | - __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 912 | - 'event_espresso'), |
|
| 913 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 914 | - ); |
|
| 915 | - } |
|
| 916 | - return $generated_queue; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 922 | - * EEM_Message::status_idle |
|
| 923 | - * |
|
| 924 | - * @since 4.9.0 |
|
| 925 | - * @param $message_ids |
|
| 926 | - * @return bool | EE_Messages_Queue false if no messages sent. |
|
| 927 | - */ |
|
| 928 | - public static function send_now($message_ids) |
|
| 929 | - { |
|
| 930 | - self::_load_controller(); |
|
| 931 | - $messages = EEM_Message::instance()->get_all( |
|
| 932 | - array( |
|
| 933 | - 0 => array( |
|
| 934 | - 'MSG_ID' => array('IN', $message_ids), |
|
| 935 | - 'STS_ID' => array( |
|
| 936 | - 'IN', |
|
| 937 | - array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 938 | - ), |
|
| 939 | - ), |
|
| 940 | - ) |
|
| 941 | - ); |
|
| 942 | - $sent_queue = false; |
|
| 943 | - if ($messages) { |
|
| 944 | - $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 948 | - EE_Error::add_error( |
|
| 949 | - __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 950 | - 'event_espresso'), |
|
| 951 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 952 | - ); |
|
| 953 | - } else { |
|
| 954 | - //can count how many sent by using the messages in the queue |
|
| 955 | - $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 956 | - if ($sent_count > 0) { |
|
| 957 | - EE_Error::add_success( |
|
| 958 | - sprintf( |
|
| 959 | - _n( |
|
| 960 | - 'There was %d message successfully sent.', |
|
| 961 | - 'There were %d messages successfully sent.', |
|
| 962 | - $sent_count, |
|
| 963 | - 'event_espresso' |
|
| 964 | - ), |
|
| 965 | - $sent_count |
|
| 966 | - ) |
|
| 967 | - ); |
|
| 968 | - } else { |
|
| 969 | - EE_Error::overwrite_errors(); |
|
| 970 | - EE_Error::add_error( |
|
| 971 | - __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 201 | + exit; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * This runs when the msg_url_trigger route has initiated. |
|
| 210 | + * |
|
| 211 | + * @since 4.5.0 |
|
| 212 | + * @param WP $WP |
|
| 213 | + * @throws EE_Error |
|
| 214 | + * @return void |
|
| 215 | + */ |
|
| 216 | + public function run($WP) |
|
| 217 | + { |
|
| 218 | + //ensure controller is loaded |
|
| 219 | + self::_load_controller(); |
|
| 220 | + // attempt to process message |
|
| 221 | + try { |
|
| 222 | + /** @type EE_Message_To_Generate_From_Request $message_to_generate */ |
|
| 223 | + $message_to_generate = EE_Registry::instance()->load_lib('Message_To_Generate_From_Request'); |
|
| 224 | + self::$_MSG_PROCESSOR->generate_and_send_now($message_to_generate); |
|
| 225 | + } catch (EE_Error $e) { |
|
| 226 | + $error_msg = __('Please note that a system message failed to send due to a technical issue.', |
|
| 227 | + 'event_espresso'); |
|
| 228 | + // add specific message for developers if WP_DEBUG in on |
|
| 229 | + $error_msg .= '||' . $e->getMessage(); |
|
| 230 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * This is triggered by the 'msg_cron_trigger' route. |
|
| 237 | + * |
|
| 238 | + * @param WP $WP |
|
| 239 | + */ |
|
| 240 | + public function execute_batch_request($WP) |
|
| 241 | + { |
|
| 242 | + $this->run_cron(); |
|
| 243 | + header('HTTP/1.1 200 OK'); |
|
| 244 | + exit(); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * This gets executed on wp_cron jobs or when a batch request is initiated on its own separate non regular wp |
|
| 250 | + * request. |
|
| 251 | + */ |
|
| 252 | + public function run_cron() |
|
| 253 | + { |
|
| 254 | + self::_load_controller(); |
|
| 255 | + //get required vars |
|
| 256 | + $cron_type = EE_Registry::instance()->REQ->get('type'); |
|
| 257 | + $transient_key = EE_Registry::instance()->REQ->get('key'); |
|
| 258 | + |
|
| 259 | + //now let's verify transient, if not valid exit immediately |
|
| 260 | + if (! get_transient($transient_key)) { |
|
| 261 | + /** |
|
| 262 | + * trigger error so this gets in the error logs. This is important because it happens on a non-user request. |
|
| 263 | + */ |
|
| 264 | + trigger_error(esc_attr__('Invalid Request (Transient does not exist)', 'event_espresso')); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + //if made it here, lets' delete the transient to keep the db clean |
|
| 268 | + delete_transient($transient_key); |
|
| 269 | + |
|
| 270 | + if (apply_filters('FHEE__EED_Messages__run_cron__use_wp_cron', true)) { |
|
| 271 | + |
|
| 272 | + $method = 'batch_' . $cron_type . '_from_queue'; |
|
| 273 | + if (method_exists(self::$_MSG_PROCESSOR, $method)) { |
|
| 274 | + self::$_MSG_PROCESSOR->$method(); |
|
| 275 | + } else { |
|
| 276 | + //no matching task |
|
| 277 | + /** |
|
| 278 | + * trigger error so this gets in the error logs. This is important because it happens on a non user request. |
|
| 279 | + */ |
|
| 280 | + trigger_error(esc_attr(sprintf(__('There is no task corresponding to this route %s', 'event_espresso'), |
|
| 281 | + $cron_type))); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + do_action('FHEE__EED_Messages__run_cron__end'); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * This is used to retrieve the template pack for the given name. |
|
| 291 | + * Retrieved packs are cached on the static $_TMP_PACKS array. If there is no class matching the given name then |
|
| 292 | + * the default template pack is returned. |
|
| 293 | + * |
|
| 294 | + * @deprecated 4.9.0 @see EEH_MSG_Template::get_template_pack() |
|
| 295 | + * @param string $template_pack_name This should correspond to the dbref of the template pack (which is also used |
|
| 296 | + * in generating the Pack class name). |
|
| 297 | + * @return EE_Messages_Template_Pack |
|
| 298 | + */ |
|
| 299 | + public static function get_template_pack($template_pack_name) |
|
| 300 | + { |
|
| 301 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 302 | + return EEH_MSG_Template::get_template_pack($template_pack_name); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Retrieves an array of all template packs. |
|
| 308 | + * Array is in the format array( 'dbref' => EE_Messages_Template_Pack ) |
|
| 309 | + * |
|
| 310 | + * @deprecated 4.9.0 @see EEH_MSG_Template_Pack::get_template_pack_collection |
|
| 311 | + * @return EE_Messages_Template_Pack[] |
|
| 312 | + */ |
|
| 313 | + public static function get_template_packs() |
|
| 314 | + { |
|
| 315 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 316 | + |
|
| 317 | + //for backward compat, let's make sure this returns in the same format as originally. |
|
| 318 | + $template_pack_collection = EEH_MSG_Template::get_template_pack_collection(); |
|
| 319 | + $template_pack_collection->rewind(); |
|
| 320 | + $template_packs = array(); |
|
| 321 | + while ($template_pack_collection->valid()) { |
|
| 322 | + $template_packs[$template_pack_collection->current()->dbref] = $template_pack_collection->current(); |
|
| 323 | + $template_pack_collection->next(); |
|
| 324 | + } |
|
| 325 | + return $template_packs; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * This simply makes sure the autoloaders are registered for the EE_messages system. |
|
| 331 | + * |
|
| 332 | + * @since 4.5.0 |
|
| 333 | + * @return void |
|
| 334 | + */ |
|
| 335 | + public static function set_autoloaders() |
|
| 336 | + { |
|
| 337 | + if (empty(self::$_MSG_PATHS)) { |
|
| 338 | + self::_set_messages_paths(); |
|
| 339 | + foreach (self::$_MSG_PATHS as $path) { |
|
| 340 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($path); |
|
| 341 | + } |
|
| 342 | + // add aliases |
|
| 343 | + EEH_Autoloader::add_alias('EE_messages', 'EE_messages'); |
|
| 344 | + EEH_Autoloader::add_alias('EE_messenger', 'EE_messenger'); |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * Take care of adding all the paths for the messages components to the $_MSG_PATHS property |
|
| 351 | + * for use by the Messages Autoloaders |
|
| 352 | + * |
|
| 353 | + * @since 4.5.0 |
|
| 354 | + * @return void. |
|
| 355 | + */ |
|
| 356 | + protected static function _set_messages_paths() |
|
| 357 | + { |
|
| 358 | + $dir_ref = array( |
|
| 359 | + 'messages/message_type', |
|
| 360 | + 'messages/messenger', |
|
| 361 | + 'messages/defaults', |
|
| 362 | + 'messages/defaults/email', |
|
| 363 | + 'messages/data_class', |
|
| 364 | + 'messages/validators', |
|
| 365 | + 'messages/validators/email', |
|
| 366 | + 'messages/validators/html', |
|
| 367 | + 'shortcodes', |
|
| 368 | + ); |
|
| 369 | + $paths = array(); |
|
| 370 | + foreach ($dir_ref as $index => $dir) { |
|
| 371 | + $paths[$index] = EE_LIBRARIES . $dir; |
|
| 372 | + } |
|
| 373 | + self::$_MSG_PATHS = apply_filters('FHEE__EED_Messages___set_messages_paths___MSG_PATHS', $paths); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * Takes care of loading dependencies |
|
| 379 | + * |
|
| 380 | + * @since 4.5.0 |
|
| 381 | + * @return void |
|
| 382 | + */ |
|
| 383 | + protected static function _load_controller() |
|
| 384 | + { |
|
| 385 | + if (! self::$_MSG_PROCESSOR instanceof EE_Messages_Processor) { |
|
| 386 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
| 387 | + self::set_autoloaders(); |
|
| 388 | + self::$_EEMSG = EE_Registry::instance()->load_lib('messages'); |
|
| 389 | + self::$_MSG_PROCESSOR = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
| 390 | + self::$_message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * @param EE_Transaction $transaction |
|
| 397 | + */ |
|
| 398 | + public static function payment_reminder(EE_Transaction $transaction) |
|
| 399 | + { |
|
| 400 | + self::_load_controller(); |
|
| 401 | + $data = array($transaction, null); |
|
| 402 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('payment_reminder', $data); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Any messages triggers for after successful gateway payments should go in here. |
|
| 408 | + * |
|
| 409 | + * @param EE_Transaction object |
|
| 410 | + * @param EE_Payment object |
|
| 411 | + * @return void |
|
| 412 | + */ |
|
| 413 | + public static function payment(EE_Transaction $transaction, EE_Payment $payment) |
|
| 414 | + { |
|
| 415 | + self::_load_controller(); |
|
| 416 | + $data = array($transaction, $payment); |
|
| 417 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 418 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 419 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 420 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 421 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * @param EE_Transaction $transaction |
|
| 427 | + */ |
|
| 428 | + public static function cancelled_registration(EE_Transaction $transaction) |
|
| 429 | + { |
|
| 430 | + self::_load_controller(); |
|
| 431 | + $data = array($transaction, null); |
|
| 432 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('cancelled_registration', $data); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * Trigger for Registration messages |
|
| 438 | + * Note that what registration message type is sent depends on what the reg status is for the registrations on the |
|
| 439 | + * incoming transaction. |
|
| 440 | + * |
|
| 441 | + * @param EE_Registration $registration |
|
| 442 | + * @param array $extra_details |
|
| 443 | + * @return void |
|
| 444 | + */ |
|
| 445 | + public static function maybe_registration(EE_Registration $registration, $extra_details = array()) |
|
| 446 | + { |
|
| 447 | + |
|
| 448 | + if (! self::_verify_registration_notification_send($registration, $extra_details)) { |
|
| 449 | + //no messages please |
|
| 450 | + return; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + |
|
| 454 | + //get all registrations so we make sure we send messages for the right status. |
|
| 455 | + $all_registrations = $registration->transaction()->registrations(); |
|
| 456 | + |
|
| 457 | + //cached array of statuses so we only trigger messages once per status. |
|
| 458 | + $statuses_sent = array(); |
|
| 459 | + self::_load_controller(); |
|
| 460 | + $mtgs = array(); |
|
| 461 | + |
|
| 462 | + //loop through registrations and trigger messages once per status. |
|
| 463 | + foreach ($all_registrations as $reg) { |
|
| 464 | + |
|
| 465 | + //already triggered? |
|
| 466 | + if (in_array($reg->status_ID(), $statuses_sent)) { |
|
| 467 | + continue; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($reg->status_ID()); |
|
| 471 | + $mtgs = array_merge( |
|
| 472 | + $mtgs, |
|
| 473 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 474 | + $message_type, |
|
| 475 | + array($registration->transaction(), null, $reg->status_ID()) |
|
| 476 | + ) |
|
| 477 | + ); |
|
| 478 | + $statuses_sent[] = $reg->status_ID(); |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + if (count($statuses_sent) > 1) { |
|
| 482 | + $mtgs = array_merge( |
|
| 483 | + $mtgs, |
|
| 484 | + self::$_MSG_PROCESSOR->setup_mtgs_for_all_active_messengers( |
|
| 485 | + 'registration_summary', |
|
| 486 | + array($registration->transaction(), null) |
|
| 487 | + ) |
|
| 488 | + ); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + //batch queue and initiate request |
|
| 492 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($mtgs); |
|
| 493 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * This is a helper method used to very whether a registration notification should be sent or |
|
| 499 | + * not. Prevents duplicate notifications going out for registration context notifications. |
|
| 500 | + * |
|
| 501 | + * @param EE_Registration $registration [description] |
|
| 502 | + * @param array $extra_details [description] |
|
| 503 | + * @return bool true = send away, false = nope halt the presses. |
|
| 504 | + */ |
|
| 505 | + protected static function _verify_registration_notification_send( |
|
| 506 | + EE_Registration $registration, |
|
| 507 | + $extra_details = array() |
|
| 508 | + ) { |
|
| 509 | + //self::log( |
|
| 510 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
| 511 | + // $registration->transaction(), |
|
| 512 | + // array( '$extra_details' => $extra_details ) |
|
| 513 | + //); |
|
| 514 | + // currently only using this to send messages for the primary registrant |
|
| 515 | + if (! $registration->is_primary_registrant()) { |
|
| 516 | + return false; |
|
| 517 | + } |
|
| 518 | + // first we check if we're in admin and not doing front ajax |
|
| 519 | + if (is_admin() && ! EE_FRONT_AJAX) { |
|
| 520 | + //make sure appropriate admin params are set for sending messages |
|
| 521 | + if (empty($_REQUEST['txn_reg_status_change']['send_notifications']) || ! absint($_REQUEST['txn_reg_status_change']['send_notifications'])) { |
|
| 522 | + //no messages sent please. |
|
| 523 | + return false; |
|
| 524 | + } |
|
| 525 | + } else { |
|
| 526 | + // frontend request (either regular or via AJAX) |
|
| 527 | + // TXN is NOT finalized ? |
|
| 528 | + if (! isset($extra_details['finalized']) || $extra_details['finalized'] === false) { |
|
| 529 | + return false; |
|
| 530 | + } |
|
| 531 | + // return visit but nothing changed ??? |
|
| 532 | + if ( |
|
| 533 | + isset($extra_details['revisit'], $extra_details['status_updates']) && |
|
| 534 | + $extra_details['revisit'] && ! $extra_details['status_updates'] |
|
| 535 | + ) { |
|
| 536 | + return false; |
|
| 537 | + } |
|
| 538 | + // NOT sending messages && reg status is something other than "Not-Approved" |
|
| 539 | + if ( |
|
| 540 | + ! apply_filters('FHEE__EED_Messages___maybe_registration__deliver_notifications', false) && |
|
| 541 | + $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
| 542 | + ) { |
|
| 543 | + return false; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + // release the kraken |
|
| 547 | + return true; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * Simply returns an array indexed by Registration Status ID and the related message_type name associated with that |
|
| 553 | + * status id. |
|
| 554 | + * |
|
| 555 | + * @deprecated 4.9.0 Use EEH_MSG_Template::reg_status_to_message_type_array() |
|
| 556 | + * or EEH_MSG_Template::convert_reg_status_to_message_type |
|
| 557 | + * @param string $reg_status |
|
| 558 | + * @return array |
|
| 559 | + */ |
|
| 560 | + protected static function _get_reg_status_array($reg_status = '') |
|
| 561 | + { |
|
| 562 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 563 | + return EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 564 | + ? EEH_MSG_Template::convert_reg_status_to_message_type($reg_status) |
|
| 565 | + : EEH_MSG_Template::reg_status_to_message_type_array(); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Simply returns the payment message type for the given payment status. |
|
| 571 | + * |
|
| 572 | + * @deprecated 4.9.0 Use EEH_MSG_Template::payment_status_to_message_type_array |
|
| 573 | + * or EEH_MSG_Template::convert_payment_status_to_message_type |
|
| 574 | + * @param string $payment_status The payment status being matched. |
|
| 575 | + * @return string|bool The payment message type slug matching the status or false if no match. |
|
| 576 | + */ |
|
| 577 | + protected static function _get_payment_message_type($payment_status) |
|
| 578 | + { |
|
| 579 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 580 | + return EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 581 | + ? EEH_MSG_Template::convert_payment_status_to_message_type($payment_status) |
|
| 582 | + : false; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 588 | + * |
|
| 589 | + * @access public |
|
| 590 | + * @param array $req_data This is the $_POST & $_GET data sent from EE_Admin Pages |
|
| 591 | + * @return bool success/fail |
|
| 592 | + */ |
|
| 593 | + public static function process_resend($req_data) |
|
| 594 | + { |
|
| 595 | + self::_load_controller(); |
|
| 596 | + |
|
| 597 | + //if $msgID in this request then skip to the new resend_message |
|
| 598 | + if (EE_Registry::instance()->REQ->get('MSG_ID')) { |
|
| 599 | + return self::resend_message(); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + //make sure any incoming request data is set on the REQ so that it gets picked up later. |
|
| 603 | + $req_data = (array)$req_data; |
|
| 604 | + foreach ($req_data as $request_key => $request_value) { |
|
| 605 | + EE_Registry::instance()->REQ->set($request_key, $request_value); |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + if (! $messages_to_send = self::$_MSG_PROCESSOR->setup_messages_to_generate_from_registration_ids_in_request()) { |
|
| 609 | + return false; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + try { |
|
| 613 | + self::$_MSG_PROCESSOR->batch_queue_for_generation_and_persist($messages_to_send); |
|
| 614 | + self::$_MSG_PROCESSOR->get_queue()->initiate_request_by_priority(); |
|
| 615 | + } catch (EE_Error $e) { |
|
| 616 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 617 | + return false; |
|
| 618 | + } |
|
| 619 | + EE_Error::add_success( |
|
| 620 | + __('Messages have been successfully queued for generation and sending.', 'event_espresso') |
|
| 621 | + ); |
|
| 622 | + return true; //everything got queued. |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + /** |
|
| 627 | + * Message triggers for a resending already sent message(s) (via EE_Message list table) |
|
| 628 | + * |
|
| 629 | + * @return bool |
|
| 630 | + */ |
|
| 631 | + public static function resend_message() |
|
| 632 | + { |
|
| 633 | + self::_load_controller(); |
|
| 634 | + |
|
| 635 | + $msgID = EE_Registry::instance()->REQ->get('MSG_ID'); |
|
| 636 | + if (! $msgID) { |
|
| 637 | + EE_Error::add_error(__('Something went wrong because there is no "MSG_ID" value in the request', |
|
| 638 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 639 | + return false; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send((array)$msgID); |
|
| 643 | + |
|
| 644 | + //setup success message. |
|
| 645 | + $count_ready_for_resend = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 646 | + EE_Error::add_success(sprintf( |
|
| 647 | + _n( |
|
| 648 | + 'There was %d message queued for resending.', |
|
| 649 | + 'There were %d messages queued for resending.', |
|
| 650 | + $count_ready_for_resend, |
|
| 651 | + 'event_espresso' |
|
| 652 | + ), |
|
| 653 | + $count_ready_for_resend |
|
| 654 | + )); |
|
| 655 | + return true; |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Message triggers for manual payment applied by admin |
|
| 661 | + * |
|
| 662 | + * @param EE_Payment $payment EE_payment object |
|
| 663 | + * @return bool success/fail |
|
| 664 | + */ |
|
| 665 | + public static function process_admin_payment(EE_Payment $payment) |
|
| 666 | + { |
|
| 667 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 668 | + //we need to get the transaction object |
|
| 669 | + $transaction = $payment->transaction(); |
|
| 670 | + if ($transaction instanceof EE_Transaction) { |
|
| 671 | + $data = array($transaction, $payment); |
|
| 672 | + $message_type = EEH_MSG_Template::convert_payment_status_to_message_type($payment->STS_ID()); |
|
| 673 | + |
|
| 674 | + //if payment amount is less than 0 then switch to payment_refund message type. |
|
| 675 | + $message_type = $payment->amount() < 0 ? 'payment_refund' : $message_type; |
|
| 676 | + |
|
| 677 | + //if payment_refund is selected, but the status is NOT accepted. Then change message type to false so NO message notification goes out. |
|
| 678 | + $message_type = $message_type == 'payment_refund' && $payment->STS_ID() != EEM_Payment::status_id_approved ? false : $message_type; |
|
| 679 | + |
|
| 680 | + self::_load_controller(); |
|
| 681 | + |
|
| 682 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers($message_type, $data); |
|
| 683 | + |
|
| 684 | + //get count of queued for generation |
|
| 685 | + $count_to_generate = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(array( |
|
| 686 | + EEM_Message::status_incomplete, |
|
| 687 | + EEM_Message::status_idle, |
|
| 688 | + )); |
|
| 689 | + |
|
| 690 | + if ($count_to_generate > 0 && self::$_MSG_PROCESSOR->get_queue()->get_message_repository()->count() !== 0) { |
|
| 691 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 692 | + return true; |
|
| 693 | + } else { |
|
| 694 | + $count_failed = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::instance()->stati_indicating_failed_sending()); |
|
| 695 | + /** |
|
| 696 | + * Verify that there are actually errors. If not then we return a success message because the queue might have been emptied due to successful |
|
| 697 | + * IMMEDIATE generation. |
|
| 698 | + */ |
|
| 699 | + if ($count_failed > 0) { |
|
| 700 | + EE_Error::add_error(sprintf( |
|
| 701 | + _n( |
|
| 702 | + 'The payment notification generation failed.', |
|
| 703 | + '%d payment notifications failed being sent.', |
|
| 704 | + $count_failed, |
|
| 705 | + 'event_espresso' |
|
| 706 | + ), |
|
| 707 | + $count_failed |
|
| 708 | + ), __FILE__, __FUNCTION__, __LINE__); |
|
| 709 | + |
|
| 710 | + return false; |
|
| 711 | + } else { |
|
| 712 | + add_filter('FHEE__EE_Admin_Page___process_admin_payment_notification__success', '__return_true'); |
|
| 713 | + return true; |
|
| 714 | + } |
|
| 715 | + } |
|
| 716 | + } else { |
|
| 717 | + EE_Error::add_error( |
|
| 718 | + 'Unable to generate the payment notification because the given value for the transaction is invalid.', |
|
| 719 | + 'event_espresso' |
|
| 720 | + ); |
|
| 721 | + return false; |
|
| 722 | + } |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + |
|
| 726 | + /** |
|
| 727 | + * Callback for AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send_with_registrations trigger |
|
| 728 | + * |
|
| 729 | + * @since 4.3.0 |
|
| 730 | + * @param EE_Registration[] $registrations an array of EE_Registration objects |
|
| 731 | + * @param int $grp_id a specific message template group id. |
|
| 732 | + * @return void |
|
| 733 | + */ |
|
| 734 | + public static function send_newsletter_message($registrations, $grp_id) |
|
| 735 | + { |
|
| 736 | + //make sure mtp is id and set it in the EE_Request Handler later messages setup. |
|
| 737 | + EE_Registry::instance()->REQ->set('GRP_ID', (int)$grp_id); |
|
| 738 | + self::_load_controller(); |
|
| 739 | + self::$_MSG_PROCESSOR->generate_for_all_active_messengers('newsletter', $registrations); |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + |
|
| 743 | + /** |
|
| 744 | + * Callback for FHEE__EE_Registration__invoice_url__invoice_url or FHEE__EE_Registration__receipt_url__receipt_url |
|
| 745 | + * |
|
| 746 | + * @since 4.3.0 |
|
| 747 | + * @param string $registration_message_trigger_url |
|
| 748 | + * @param EE_Registration $registration |
|
| 749 | + * @param string $messenger |
|
| 750 | + * @param string $message_type |
|
| 751 | + * @return string |
|
| 752 | + */ |
|
| 753 | + public static function registration_message_trigger_url( |
|
| 754 | + $registration_message_trigger_url, |
|
| 755 | + EE_Registration $registration, |
|
| 756 | + $messenger = 'html', |
|
| 757 | + $message_type = 'invoice' |
|
| 758 | + ) { |
|
| 759 | + // whitelist $messenger |
|
| 760 | + switch ($messenger) { |
|
| 761 | + case 'pdf' : |
|
| 762 | + $sending_messenger = 'pdf'; |
|
| 763 | + $generating_messenger = 'html'; |
|
| 764 | + break; |
|
| 765 | + case 'html' : |
|
| 766 | + default : |
|
| 767 | + $sending_messenger = 'html'; |
|
| 768 | + $generating_messenger = 'html'; |
|
| 769 | + break; |
|
| 770 | + } |
|
| 771 | + // whitelist $message_type |
|
| 772 | + switch ($message_type) { |
|
| 773 | + case 'receipt' : |
|
| 774 | + $message_type = 'receipt'; |
|
| 775 | + break; |
|
| 776 | + case 'invoice' : |
|
| 777 | + default : |
|
| 778 | + $message_type = 'invoice'; |
|
| 779 | + break; |
|
| 780 | + } |
|
| 781 | + // verify that both the messenger AND the message type are active |
|
| 782 | + if (EEH_MSG_Template::is_messenger_active($sending_messenger) && EEH_MSG_Template::is_mt_active($message_type)) { |
|
| 783 | + //need to get the correct message template group for this (i.e. is there a custom invoice for the event this registration is registered for?) |
|
| 784 | + $template_query_params = array( |
|
| 785 | + 'MTP_is_active' => true, |
|
| 786 | + 'MTP_messenger' => $generating_messenger, |
|
| 787 | + 'MTP_message_type' => $message_type, |
|
| 788 | + 'Event.EVT_ID' => $registration->event_ID(), |
|
| 789 | + ); |
|
| 790 | + //get the message template group. |
|
| 791 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 792 | + //if we don't have an EE_Message_Template_Group then return |
|
| 793 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 794 | + // remove EVT_ID from query params so that global templates get picked up |
|
| 795 | + unset($template_query_params['Event.EVT_ID']); |
|
| 796 | + //get global template as the fallback |
|
| 797 | + $msg_template_group = EEM_Message_Template_Group::instance()->get_one(array($template_query_params)); |
|
| 798 | + } |
|
| 799 | + //if we don't have an EE_Message_Template_Group then return |
|
| 800 | + if (! $msg_template_group instanceof EE_Message_Template_Group) { |
|
| 801 | + return ''; |
|
| 802 | + } |
|
| 803 | + // generate the URL |
|
| 804 | + $registration_message_trigger_url = EEH_MSG_Template::generate_url_trigger( |
|
| 805 | + $sending_messenger, |
|
| 806 | + $generating_messenger, |
|
| 807 | + 'purchaser', |
|
| 808 | + $message_type, |
|
| 809 | + $registration, |
|
| 810 | + $msg_template_group->ID(), |
|
| 811 | + $registration->transaction_ID() |
|
| 812 | + ); |
|
| 813 | + |
|
| 814 | + } |
|
| 815 | + return $registration_message_trigger_url; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + |
|
| 819 | + /** |
|
| 820 | + * Use to generate and return a message preview! |
|
| 821 | + * |
|
| 822 | + * @param string $type This should correspond with a valid message type |
|
| 823 | + * @param string $context This should correspond with a valid context for the message type |
|
| 824 | + * @param string $messenger This should correspond with a valid messenger. |
|
| 825 | + * @param bool $send true we will do a test send using the messenger delivery, false we just do a regular |
|
| 826 | + * preview |
|
| 827 | + * @return string|bool The body of the message or if send is requested, sends. |
|
| 828 | + */ |
|
| 829 | + public static function preview_message($type, $context, $messenger, $send = false) |
|
| 830 | + { |
|
| 831 | + self::_load_controller(); |
|
| 832 | + $mtg = new EE_Message_To_Generate( |
|
| 833 | + $messenger, |
|
| 834 | + $type, |
|
| 835 | + array(), |
|
| 836 | + $context, |
|
| 837 | + true |
|
| 838 | + ); |
|
| 839 | + $generated_preview_queue = self::$_MSG_PROCESSOR->generate_for_preview($mtg, $send); |
|
| 840 | + if ($generated_preview_queue instanceof EE_Messages_Queue) { |
|
| 841 | + return $generated_preview_queue->get_message_repository()->current()->content(); |
|
| 842 | + } else { |
|
| 843 | + return $generated_preview_queue; |
|
| 844 | + } |
|
| 845 | + } |
|
| 846 | + |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * This is a method that allows for sending a message using a messenger matching the string given and the provided |
|
| 850 | + * EE_Message_Queue object. The EE_Message_Queue object is used to create a single aggregate EE_Message via the |
|
| 851 | + * content found in the EE_Message objects in the queue. |
|
| 852 | + * |
|
| 853 | + * @since 4.9.0 |
|
| 854 | + * @param string $messenger a string matching a valid active messenger in the system |
|
| 855 | + * @param string $message_type Although it seems contrary to the name of the method, a message |
|
| 856 | + * type name is still required to send along the message type to the |
|
| 857 | + * messenger because this is used for determining what specific |
|
| 858 | + * variations might be loaded for the generated message. |
|
| 859 | + * @param EE_Messages_Queue $queue |
|
| 860 | + * @param string $custom_subject Can be used to set what the custom subject string will be on the |
|
| 861 | + * aggregate EE_Message object. |
|
| 862 | + * @return bool success or fail. |
|
| 863 | + */ |
|
| 864 | + public static function send_message_with_messenger_only( |
|
| 865 | + $messenger, |
|
| 866 | + $message_type, |
|
| 867 | + EE_Messages_Queue $queue, |
|
| 868 | + $custom_subject = '' |
|
| 869 | + ) { |
|
| 870 | + self::_load_controller(); |
|
| 871 | + /** @type EE_Message_To_Generate_From_Queue $message_to_generate */ |
|
| 872 | + $message_to_generate = EE_Registry::instance()->load_lib( |
|
| 873 | + 'Message_To_Generate_From_Queue', |
|
| 874 | + array( |
|
| 875 | + $messenger, |
|
| 876 | + $message_type, |
|
| 877 | + $queue, |
|
| 878 | + $custom_subject, |
|
| 879 | + ) |
|
| 880 | + ); |
|
| 881 | + return self::$_MSG_PROCESSOR->queue_for_sending($message_to_generate); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + |
|
| 885 | + /** |
|
| 886 | + * Generates Messages immediately for EE_Message IDs (but only for the correct status for generation) |
|
| 887 | + * |
|
| 888 | + * @since 4.9.0 |
|
| 889 | + * @param array $message_ids An array of message ids |
|
| 890 | + * @return bool | EE_Messages_Queue false if nothing was generated, EE_Messages_Queue containing generated |
|
| 891 | + * messages. |
|
| 892 | + */ |
|
| 893 | + public static function generate_now($message_ids) |
|
| 894 | + { |
|
| 895 | + self::_load_controller(); |
|
| 896 | + $messages = EEM_Message::instance()->get_all( |
|
| 897 | + array( |
|
| 898 | + 0 => array( |
|
| 899 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 900 | + 'STS_ID' => EEM_Message::status_incomplete, |
|
| 901 | + ), |
|
| 902 | + ) |
|
| 903 | + ); |
|
| 904 | + $generated_queue = false; |
|
| 905 | + if ($messages) { |
|
| 906 | + $generated_queue = self::$_MSG_PROCESSOR->batch_generate_from_queue($messages); |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + if (! $generated_queue instanceof EE_Messages_Queue) { |
|
| 910 | + EE_Error::add_error( |
|
| 911 | + __('The messages were not generated. This could mean there is already a batch being generated on a separate request, or because the selected messages are not ready for generation. Please wait a minute or two and try again.', |
|
| 912 | + 'event_espresso'), |
|
| 913 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 914 | + ); |
|
| 915 | + } |
|
| 916 | + return $generated_queue; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * Sends messages immediately for the incoming message_ids that have the status of EEM_Message::status_resend or, |
|
| 922 | + * EEM_Message::status_idle |
|
| 923 | + * |
|
| 924 | + * @since 4.9.0 |
|
| 925 | + * @param $message_ids |
|
| 926 | + * @return bool | EE_Messages_Queue false if no messages sent. |
|
| 927 | + */ |
|
| 928 | + public static function send_now($message_ids) |
|
| 929 | + { |
|
| 930 | + self::_load_controller(); |
|
| 931 | + $messages = EEM_Message::instance()->get_all( |
|
| 932 | + array( |
|
| 933 | + 0 => array( |
|
| 934 | + 'MSG_ID' => array('IN', $message_ids), |
|
| 935 | + 'STS_ID' => array( |
|
| 936 | + 'IN', |
|
| 937 | + array(EEM_Message::status_idle, EEM_Message::status_resend, EEM_Message::status_retry), |
|
| 938 | + ), |
|
| 939 | + ), |
|
| 940 | + ) |
|
| 941 | + ); |
|
| 942 | + $sent_queue = false; |
|
| 943 | + if ($messages) { |
|
| 944 | + $sent_queue = self::$_MSG_PROCESSOR->batch_send_from_queue($messages); |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + if (! $sent_queue instanceof EE_Messages_Queue) { |
|
| 948 | + EE_Error::add_error( |
|
| 949 | + __('The messages were not sent. This could mean there is already a batch being sent on a separate request, or because the selected messages are not sendable. Please wait a minute or two and try again.', |
|
| 950 | + 'event_espresso'), |
|
| 951 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 952 | + ); |
|
| 953 | + } else { |
|
| 954 | + //can count how many sent by using the messages in the queue |
|
| 955 | + $sent_count = $sent_queue->count_STS_in_queue(EEM_Message::instance()->stati_indicating_sent()); |
|
| 956 | + if ($sent_count > 0) { |
|
| 957 | + EE_Error::add_success( |
|
| 958 | + sprintf( |
|
| 959 | + _n( |
|
| 960 | + 'There was %d message successfully sent.', |
|
| 961 | + 'There were %d messages successfully sent.', |
|
| 962 | + $sent_count, |
|
| 963 | + 'event_espresso' |
|
| 964 | + ), |
|
| 965 | + $sent_count |
|
| 966 | + ) |
|
| 967 | + ); |
|
| 968 | + } else { |
|
| 969 | + EE_Error::overwrite_errors(); |
|
| 970 | + EE_Error::add_error( |
|
| 971 | + __('No message was sent because of problems with sending. Either all the messages you selected were not a sendable message, they were ALREADY sent on a different scheduled task, or there was an error. |
|
| 972 | 972 | If there was an error, you can look at the messages in the message activity list table for any error messages.', |
| 973 | - 'event_espresso'), |
|
| 974 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 975 | - ); |
|
| 976 | - } |
|
| 977 | - } |
|
| 978 | - return $sent_queue; |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * This will queue the incoming message ids for resending. |
|
| 984 | - * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 985 | - * |
|
| 986 | - * @since 4.9.0 |
|
| 987 | - * @param array $message_ids An array of EE_Message IDs |
|
| 988 | - * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 989 | - * resending. |
|
| 990 | - */ |
|
| 991 | - public static function queue_for_resending($message_ids) |
|
| 992 | - { |
|
| 993 | - self::_load_controller(); |
|
| 994 | - self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 995 | - |
|
| 996 | - //get queue and count |
|
| 997 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 998 | - |
|
| 999 | - if ( |
|
| 1000 | - $queue_count > 0 |
|
| 1001 | - ) { |
|
| 1002 | - EE_Error::add_success( |
|
| 1003 | - sprintf( |
|
| 1004 | - _n( |
|
| 1005 | - '%d message successfully queued for resending.', |
|
| 1006 | - '%d messages successfully queued for resending.', |
|
| 1007 | - $queue_count, |
|
| 1008 | - 'event_espresso' |
|
| 1009 | - ), |
|
| 1010 | - $queue_count |
|
| 1011 | - ) |
|
| 1012 | - ); |
|
| 1013 | - /** |
|
| 1014 | - * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1015 | - */ |
|
| 1016 | - } elseif ( |
|
| 1017 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1018 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1019 | - ) { |
|
| 1020 | - $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1021 | - if ($queue_count > 0) { |
|
| 1022 | - EE_Error::add_success( |
|
| 1023 | - sprintf( |
|
| 1024 | - _n( |
|
| 1025 | - '%d message successfully sent.', |
|
| 1026 | - '%d messages successfully sent.', |
|
| 1027 | - $queue_count, |
|
| 1028 | - 'event_espresso' |
|
| 1029 | - ), |
|
| 1030 | - $queue_count |
|
| 1031 | - ) |
|
| 1032 | - ); |
|
| 1033 | - } else { |
|
| 1034 | - EE_Error::add_error( |
|
| 1035 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1036 | - 'event_espresso'), |
|
| 1037 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1038 | - ); |
|
| 1039 | - } |
|
| 1040 | - } else { |
|
| 1041 | - EE_Error::add_error( |
|
| 1042 | - __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1043 | - 'event_espresso'), |
|
| 1044 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1045 | - ); |
|
| 1046 | - } |
|
| 1047 | - return (bool)$queue_count; |
|
| 1048 | - } |
|
| 1049 | - |
|
| 1050 | - |
|
| 1051 | - /** |
|
| 1052 | - * debug |
|
| 1053 | - * |
|
| 1054 | - * @param string $class |
|
| 1055 | - * @param string $func |
|
| 1056 | - * @param string $line |
|
| 1057 | - * @param \EE_Transaction $transaction |
|
| 1058 | - * @param array $info |
|
| 1059 | - * @param bool $display_request |
|
| 1060 | - */ |
|
| 1061 | - protected static function log( |
|
| 1062 | - $class = '', |
|
| 1063 | - $func = '', |
|
| 1064 | - $line = '', |
|
| 1065 | - EE_Transaction $transaction, |
|
| 1066 | - $info = array(), |
|
| 1067 | - $display_request = false |
|
| 1068 | - ) { |
|
| 1069 | - if (WP_DEBUG && false) { |
|
| 1070 | - if ($transaction instanceof EE_Transaction) { |
|
| 1071 | - // don't serialize objects |
|
| 1072 | - $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1073 | - $info['TXN_status'] = $transaction->status_ID(); |
|
| 1074 | - $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1075 | - if ($transaction->ID()) { |
|
| 1076 | - $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1077 | - EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1078 | - } |
|
| 1079 | - } |
|
| 1080 | - } |
|
| 1081 | - |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * Resets all the static properties in this class when called. |
|
| 1087 | - */ |
|
| 1088 | - public static function reset() |
|
| 1089 | - { |
|
| 1090 | - self::$_EEMSG = null; |
|
| 1091 | - self::$_message_resource_manager = null; |
|
| 1092 | - self::$_MSG_PROCESSOR = null; |
|
| 1093 | - self::$_MSG_PATHS = null; |
|
| 1094 | - self::$_TMP_PACKS = array(); |
|
| 1095 | - } |
|
| 973 | + 'event_espresso'), |
|
| 974 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 975 | + ); |
|
| 976 | + } |
|
| 977 | + } |
|
| 978 | + return $sent_queue; |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * This will queue the incoming message ids for resending. |
|
| 984 | + * Note, only message_ids corresponding to messages with the status of EEM_Message::sent will be queued. |
|
| 985 | + * |
|
| 986 | + * @since 4.9.0 |
|
| 987 | + * @param array $message_ids An array of EE_Message IDs |
|
| 988 | + * @return bool true means messages were successfully queued for resending, false means none were queued for |
|
| 989 | + * resending. |
|
| 990 | + */ |
|
| 991 | + public static function queue_for_resending($message_ids) |
|
| 992 | + { |
|
| 993 | + self::_load_controller(); |
|
| 994 | + self::$_MSG_PROCESSOR->setup_messages_from_ids_and_send($message_ids); |
|
| 995 | + |
|
| 996 | + //get queue and count |
|
| 997 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_resend); |
|
| 998 | + |
|
| 999 | + if ( |
|
| 1000 | + $queue_count > 0 |
|
| 1001 | + ) { |
|
| 1002 | + EE_Error::add_success( |
|
| 1003 | + sprintf( |
|
| 1004 | + _n( |
|
| 1005 | + '%d message successfully queued for resending.', |
|
| 1006 | + '%d messages successfully queued for resending.', |
|
| 1007 | + $queue_count, |
|
| 1008 | + 'event_espresso' |
|
| 1009 | + ), |
|
| 1010 | + $queue_count |
|
| 1011 | + ) |
|
| 1012 | + ); |
|
| 1013 | + /** |
|
| 1014 | + * @see filter usage in EE_Messages_Queue::initiate_request_by_priority |
|
| 1015 | + */ |
|
| 1016 | + } elseif ( |
|
| 1017 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', true) |
|
| 1018 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
| 1019 | + ) { |
|
| 1020 | + $queue_count = self::$_MSG_PROCESSOR->get_queue()->count_STS_in_queue(EEM_Message::status_sent); |
|
| 1021 | + if ($queue_count > 0) { |
|
| 1022 | + EE_Error::add_success( |
|
| 1023 | + sprintf( |
|
| 1024 | + _n( |
|
| 1025 | + '%d message successfully sent.', |
|
| 1026 | + '%d messages successfully sent.', |
|
| 1027 | + $queue_count, |
|
| 1028 | + 'event_espresso' |
|
| 1029 | + ), |
|
| 1030 | + $queue_count |
|
| 1031 | + ) |
|
| 1032 | + ); |
|
| 1033 | + } else { |
|
| 1034 | + EE_Error::add_error( |
|
| 1035 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1036 | + 'event_espresso'), |
|
| 1037 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1038 | + ); |
|
| 1039 | + } |
|
| 1040 | + } else { |
|
| 1041 | + EE_Error::add_error( |
|
| 1042 | + __('No messages were queued for resending. This usually only happens when all the messages flagged for resending are not a status that can be resent.', |
|
| 1043 | + 'event_espresso'), |
|
| 1044 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1045 | + ); |
|
| 1046 | + } |
|
| 1047 | + return (bool)$queue_count; |
|
| 1048 | + } |
|
| 1049 | + |
|
| 1050 | + |
|
| 1051 | + /** |
|
| 1052 | + * debug |
|
| 1053 | + * |
|
| 1054 | + * @param string $class |
|
| 1055 | + * @param string $func |
|
| 1056 | + * @param string $line |
|
| 1057 | + * @param \EE_Transaction $transaction |
|
| 1058 | + * @param array $info |
|
| 1059 | + * @param bool $display_request |
|
| 1060 | + */ |
|
| 1061 | + protected static function log( |
|
| 1062 | + $class = '', |
|
| 1063 | + $func = '', |
|
| 1064 | + $line = '', |
|
| 1065 | + EE_Transaction $transaction, |
|
| 1066 | + $info = array(), |
|
| 1067 | + $display_request = false |
|
| 1068 | + ) { |
|
| 1069 | + if (WP_DEBUG && false) { |
|
| 1070 | + if ($transaction instanceof EE_Transaction) { |
|
| 1071 | + // don't serialize objects |
|
| 1072 | + $info = EEH_Debug_Tools::strip_objects($info); |
|
| 1073 | + $info['TXN_status'] = $transaction->status_ID(); |
|
| 1074 | + $info['TXN_reg_steps'] = $transaction->reg_steps(); |
|
| 1075 | + if ($transaction->ID()) { |
|
| 1076 | + $index = 'EE_Transaction: ' . $transaction->ID(); |
|
| 1077 | + EEH_Debug_Tools::log($class, $func, $line, $info, $display_request, $index); |
|
| 1078 | + } |
|
| 1079 | + } |
|
| 1080 | + } |
|
| 1081 | + |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * Resets all the static properties in this class when called. |
|
| 1087 | + */ |
|
| 1088 | + public static function reset() |
|
| 1089 | + { |
|
| 1090 | + self::$_EEMSG = null; |
|
| 1091 | + self::$_message_resource_manager = null; |
|
| 1092 | + self::$_MSG_PROCESSOR = null; |
|
| 1093 | + self::$_MSG_PATHS = null; |
|
| 1094 | + self::$_TMP_PACKS = array(); |
|
| 1095 | + } |
|
| 1096 | 1096 | |
| 1097 | 1097 | } |
| 1098 | 1098 | // End of file EED_Messages.module.php |
@@ -17,254 +17,252 @@ |
||
| 17 | 17 | class TableManager extends \EE_Base |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var TableAnalysis $table_analysis |
|
| 22 | - */ |
|
| 23 | - private $table_analysis; |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * TableManager constructor. |
|
| 29 | - * |
|
| 30 | - * @param TableAnalysis $TableAnalysis |
|
| 31 | - */ |
|
| 32 | - public function __construct(TableAnalysis $TableAnalysis) |
|
| 33 | - { |
|
| 34 | - $this->table_analysis = $TableAnalysis; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Gets the injected table analyzer, or throws an exception |
|
| 41 | - * |
|
| 42 | - * @return TableAnalysis |
|
| 43 | - * @throws \EE_Error |
|
| 44 | - */ |
|
| 45 | - protected function getTableAnalysis() |
|
| 46 | - { |
|
| 47 | - if ($this->table_analysis instanceof TableAnalysis) { |
|
| 48 | - return $this->table_analysis; |
|
| 49 | - } else { |
|
| 50 | - throw new \EE_Error( |
|
| 51 | - sprintf( |
|
| 52 | - __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 53 | - get_class($this) |
|
| 54 | - ) |
|
| 55 | - ); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @param string $table_name which can optionally start with $wpdb->prefix or not |
|
| 63 | - * @param string $column_name |
|
| 64 | - * @param string $column_info |
|
| 65 | - * @return bool|false|int |
|
| 66 | - */ |
|
| 67 | - public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL') |
|
| 68 | - { |
|
| 69 | - if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) { |
|
| 70 | - return false; |
|
| 71 | - } |
|
| 72 | - global $wpdb; |
|
| 73 | - $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 74 | - $columns = $this->getTableColumns($table_name); |
|
| 75 | - if ( ! in_array($column_name, $columns)) { |
|
| 76 | - $alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}"; |
|
| 77 | - return $wpdb->query($alter_query); |
|
| 78 | - } |
|
| 79 | - return true; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Gets the name of all columns on the table. $table_name can |
|
| 86 | - * optionally start with $wpdb->prefix or not |
|
| 87 | - * |
|
| 88 | - * @global \wpdb $wpdb |
|
| 89 | - * @param string $table_name |
|
| 90 | - * @return array |
|
| 91 | - */ |
|
| 92 | - public function getTableColumns($table_name) |
|
| 93 | - { |
|
| 94 | - global $wpdb; |
|
| 95 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 96 | - $field_array = array(); |
|
| 97 | - if ( ! empty($table_name)) { |
|
| 98 | - $columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} "); |
|
| 99 | - if ($columns !== false) { |
|
| 100 | - foreach ($columns as $column) { |
|
| 101 | - $field_array[] = $column->Field; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - return $field_array; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Drops the specified table from the database. $table_name can |
|
| 112 | - * optionally start with $wpdb->prefix or not |
|
| 113 | - * |
|
| 114 | - * @global \wpdb $wpdb |
|
| 115 | - * @param string $table_name |
|
| 116 | - * @return int |
|
| 117 | - */ |
|
| 118 | - public function dropTable($table_name) |
|
| 119 | - { |
|
| 120 | - global $wpdb; |
|
| 121 | - if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
| 122 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 123 | - return $wpdb->query("DROP TABLE IF EXISTS {$table_name}"); |
|
| 124 | - } |
|
| 125 | - return 0; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 132 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 133 | - * Returns the list actually deleted |
|
| 134 | - * |
|
| 135 | - * @global WPDB $wpdb |
|
| 136 | - * @param array $table_names |
|
| 137 | - * @return array of table names which we deleted |
|
| 138 | - */ |
|
| 139 | - public function dropTables($table_names) |
|
| 140 | - { |
|
| 141 | - $tables_to_delete = array(); |
|
| 142 | - foreach ($table_names as $table_name) { |
|
| 143 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 144 | - if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
| 145 | - $tables_to_delete[$table_name] = $table_name; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - if( ! empty( $tables_to_delete ) ) { |
|
| 149 | - global $wpdb; |
|
| 150 | - //make sure we only have a unique strings in the array. |
|
| 151 | - $tables_to_delete = array_unique($tables_to_delete); |
|
| 152 | - $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
| 153 | - } |
|
| 154 | - return $tables_to_delete; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Drops the specified index from the specified table. $table_name can |
|
| 161 | - * optionally start with $wpdb->prefix or not |
|
| 162 | - |
|
| 163 | - * |
|
| 20 | + /** |
|
| 21 | + * @var TableAnalysis $table_analysis |
|
| 22 | + */ |
|
| 23 | + private $table_analysis; |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * TableManager constructor. |
|
| 29 | + * |
|
| 30 | + * @param TableAnalysis $TableAnalysis |
|
| 31 | + */ |
|
| 32 | + public function __construct(TableAnalysis $TableAnalysis) |
|
| 33 | + { |
|
| 34 | + $this->table_analysis = $TableAnalysis; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Gets the injected table analyzer, or throws an exception |
|
| 41 | + * |
|
| 42 | + * @return TableAnalysis |
|
| 43 | + * @throws \EE_Error |
|
| 44 | + */ |
|
| 45 | + protected function getTableAnalysis() |
|
| 46 | + { |
|
| 47 | + if ($this->table_analysis instanceof TableAnalysis) { |
|
| 48 | + return $this->table_analysis; |
|
| 49 | + } else { |
|
| 50 | + throw new \EE_Error( |
|
| 51 | + sprintf( |
|
| 52 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
| 53 | + get_class($this) |
|
| 54 | + ) |
|
| 55 | + ); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @param string $table_name which can optionally start with $wpdb->prefix or not |
|
| 63 | + * @param string $column_name |
|
| 64 | + * @param string $column_info |
|
| 65 | + * @return bool|false|int |
|
| 66 | + */ |
|
| 67 | + public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL') |
|
| 68 | + { |
|
| 69 | + if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | + global $wpdb; |
|
| 73 | + $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 74 | + $columns = $this->getTableColumns($table_name); |
|
| 75 | + if ( ! in_array($column_name, $columns)) { |
|
| 76 | + $alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}"; |
|
| 77 | + return $wpdb->query($alter_query); |
|
| 78 | + } |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Gets the name of all columns on the table. $table_name can |
|
| 86 | + * optionally start with $wpdb->prefix or not |
|
| 87 | + * |
|
| 88 | + * @global \wpdb $wpdb |
|
| 89 | + * @param string $table_name |
|
| 90 | + * @return array |
|
| 91 | + */ |
|
| 92 | + public function getTableColumns($table_name) |
|
| 93 | + { |
|
| 94 | + global $wpdb; |
|
| 95 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 96 | + $field_array = array(); |
|
| 97 | + if ( ! empty($table_name)) { |
|
| 98 | + $columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} "); |
|
| 99 | + if ($columns !== false) { |
|
| 100 | + foreach ($columns as $column) { |
|
| 101 | + $field_array[] = $column->Field; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + return $field_array; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Drops the specified table from the database. $table_name can |
|
| 112 | + * optionally start with $wpdb->prefix or not |
|
| 113 | + * |
|
| 114 | + * @global \wpdb $wpdb |
|
| 115 | + * @param string $table_name |
|
| 116 | + * @return int |
|
| 117 | + */ |
|
| 118 | + public function dropTable($table_name) |
|
| 119 | + { |
|
| 120 | + global $wpdb; |
|
| 121 | + if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
| 122 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 123 | + return $wpdb->query("DROP TABLE IF EXISTS {$table_name}"); |
|
| 124 | + } |
|
| 125 | + return 0; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 132 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 133 | + * Returns the list actually deleted |
|
| 134 | + * |
|
| 135 | + * @global WPDB $wpdb |
|
| 136 | + * @param array $table_names |
|
| 137 | + * @return array of table names which we deleted |
|
| 138 | + */ |
|
| 139 | + public function dropTables($table_names) |
|
| 140 | + { |
|
| 141 | + $tables_to_delete = array(); |
|
| 142 | + foreach ($table_names as $table_name) { |
|
| 143 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 144 | + if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
| 145 | + $tables_to_delete[$table_name] = $table_name; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + if( ! empty( $tables_to_delete ) ) { |
|
| 149 | + global $wpdb; |
|
| 150 | + //make sure we only have a unique strings in the array. |
|
| 151 | + $tables_to_delete = array_unique($tables_to_delete); |
|
| 152 | + $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
| 153 | + } |
|
| 154 | + return $tables_to_delete; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Drops the specified index from the specified table. $table_name can |
|
| 161 | + * optionally start with $wpdb->prefix or not |
|
| 162 | + * |
|
| 164 | 163 | *@global \wpdb $wpdb |
| 165 | - * @param string $table_name |
|
| 166 | - * @param string $index_name |
|
| 167 | - * @return int the number of indexes dropped. False if there was a datbase error |
|
| 168 | - */ |
|
| 169 | - public function dropIndex($table_name, $index_name) |
|
| 170 | - { |
|
| 171 | - if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) { |
|
| 172 | - return 0; |
|
| 173 | - } |
|
| 174 | - global $wpdb; |
|
| 175 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 176 | - $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE key_name = '{$index_name}'"; |
|
| 177 | - if ( |
|
| 178 | - $this->getTableAnalysis()->tableExists($table_name) |
|
| 179 | - && $wpdb->get_var($index_exists_query) |
|
| 180 | - === $table_name //using get_var with the $index_exists_query returns the table's name |
|
| 181 | - ) { |
|
| 182 | - return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}"); |
|
| 183 | - } |
|
| 184 | - return 0; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Just creates the requested table. $table_name can |
|
| 191 | - * optionally start with $wpdb->prefix or not |
|
| 192 | - |
|
| 193 | - * |
|
| 164 | + * @param string $table_name |
|
| 165 | + * @param string $index_name |
|
| 166 | + * @return int the number of indexes dropped. False if there was a datbase error |
|
| 167 | + */ |
|
| 168 | + public function dropIndex($table_name, $index_name) |
|
| 169 | + { |
|
| 170 | + if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) { |
|
| 171 | + return 0; |
|
| 172 | + } |
|
| 173 | + global $wpdb; |
|
| 174 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 175 | + $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE key_name = '{$index_name}'"; |
|
| 176 | + if ( |
|
| 177 | + $this->getTableAnalysis()->tableExists($table_name) |
|
| 178 | + && $wpdb->get_var($index_exists_query) |
|
| 179 | + === $table_name //using get_var with the $index_exists_query returns the table's name |
|
| 180 | + ) { |
|
| 181 | + return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}"); |
|
| 182 | + } |
|
| 183 | + return 0; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Just creates the requested table. $table_name can |
|
| 190 | + * optionally start with $wpdb->prefix or not |
|
| 191 | + * |
|
| 194 | 192 | *@param string $table_name |
| 195 | - * @param string $create_sql defining the table's columns and indexes |
|
| 196 | - * @param string $engine (no need to specify "ENGINE=", that's implied) |
|
| 197 | - * @return void |
|
| 198 | - * @throws \EE_Error |
|
| 199 | - */ |
|
| 200 | - public function createTable($table_name, $create_sql, $engine = 'MyISAM') |
|
| 201 | - { |
|
| 202 | - // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns ) |
|
| 203 | - if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) { |
|
| 204 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 205 | - /** @var \wpdb $wpdb */ |
|
| 206 | - global $wpdb; |
|
| 207 | - $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate(); |
|
| 208 | - |
|
| 209 | - //get $wpdb to echo errors, but buffer them. This way at least WE know an error |
|
| 210 | - //happened. And then we can choose to tell the end user |
|
| 211 | - $old_show_errors_policy = $wpdb->show_errors(true); |
|
| 212 | - $old_error_suppression_policy = $wpdb->suppress_errors(false); |
|
| 213 | - ob_start(); |
|
| 214 | - dbDelta($SQL); |
|
| 215 | - $output = ob_get_contents(); |
|
| 216 | - ob_end_clean(); |
|
| 217 | - $wpdb->show_errors($old_show_errors_policy); |
|
| 218 | - $wpdb->suppress_errors($old_error_suppression_policy); |
|
| 219 | - if ( ! empty($output)) { |
|
| 220 | - throw new \EE_Error($output); |
|
| 221 | - } |
|
| 222 | - } else { |
|
| 223 | - throw new \EE_Error( |
|
| 224 | - sprintf( |
|
| 225 | - __('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', |
|
| 226 | - 'event_espresso'), |
|
| 227 | - '<br />', |
|
| 228 | - $create_sql |
|
| 229 | - ) |
|
| 230 | - ); |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * Drops the specified index if it's size differs from $desired_index_size. |
|
| 238 | - * WordPress' dbdelta method doesn't automatically change index sizes, so this |
|
| 239 | - * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal. |
|
| 240 | - * If the table doesn't exist, or it exists but the index does not, or returns false |
|
| 241 | - * |
|
| 242 | - * @param string $table_name |
|
| 243 | - * @param string $index_name |
|
| 244 | - * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE) |
|
| 245 | - * @param string|int $desired_index_size defaults to TableAnalysis::index_col_size, the max for utf8mb4. |
|
| 246 | - * @return bool whether an index was dropped or not |
|
| 247 | - * @throws /EE_Error if table analysis object isn't defined |
|
| 248 | - */ |
|
| 249 | - public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE) |
|
| 250 | - { |
|
| 251 | - if($column_name === null){ |
|
| 252 | - $column_name = $index_name; |
|
| 253 | - } |
|
| 254 | - if(!$this->getTableAnalysis()->tableExists($table_name)){ |
|
| 255 | - return false; |
|
| 256 | - } |
|
| 257 | - $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name); |
|
| 258 | - if(empty($index_entries)){ |
|
| 259 | - return false; |
|
| 260 | - } |
|
| 261 | - foreach($index_entries as $index_entry){ |
|
| 262 | - if( $column_name === $index_entry->Column_name |
|
| 263 | - && (string)$desired_index_size !== $index_entry->Sub_part){ |
|
| 264 | - return $this->dropIndex($table_name,$index_name); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - return false; |
|
| 268 | - } |
|
| 193 | + * @param string $create_sql defining the table's columns and indexes |
|
| 194 | + * @param string $engine (no need to specify "ENGINE=", that's implied) |
|
| 195 | + * @return void |
|
| 196 | + * @throws \EE_Error |
|
| 197 | + */ |
|
| 198 | + public function createTable($table_name, $create_sql, $engine = 'MyISAM') |
|
| 199 | + { |
|
| 200 | + // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns ) |
|
| 201 | + if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) { |
|
| 202 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 203 | + /** @var \wpdb $wpdb */ |
|
| 204 | + global $wpdb; |
|
| 205 | + $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate(); |
|
| 206 | + |
|
| 207 | + //get $wpdb to echo errors, but buffer them. This way at least WE know an error |
|
| 208 | + //happened. And then we can choose to tell the end user |
|
| 209 | + $old_show_errors_policy = $wpdb->show_errors(true); |
|
| 210 | + $old_error_suppression_policy = $wpdb->suppress_errors(false); |
|
| 211 | + ob_start(); |
|
| 212 | + dbDelta($SQL); |
|
| 213 | + $output = ob_get_contents(); |
|
| 214 | + ob_end_clean(); |
|
| 215 | + $wpdb->show_errors($old_show_errors_policy); |
|
| 216 | + $wpdb->suppress_errors($old_error_suppression_policy); |
|
| 217 | + if ( ! empty($output)) { |
|
| 218 | + throw new \EE_Error($output); |
|
| 219 | + } |
|
| 220 | + } else { |
|
| 221 | + throw new \EE_Error( |
|
| 222 | + sprintf( |
|
| 223 | + __('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', |
|
| 224 | + 'event_espresso'), |
|
| 225 | + '<br />', |
|
| 226 | + $create_sql |
|
| 227 | + ) |
|
| 228 | + ); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Drops the specified index if it's size differs from $desired_index_size. |
|
| 236 | + * WordPress' dbdelta method doesn't automatically change index sizes, so this |
|
| 237 | + * method can be used to only drop the index if needed, and afterwards dbdelta can be used as normal. |
|
| 238 | + * If the table doesn't exist, or it exists but the index does not, or returns false |
|
| 239 | + * |
|
| 240 | + * @param string $table_name |
|
| 241 | + * @param string $index_name |
|
| 242 | + * @param string $column_name if none is provided, we assume the column name matches the index (often true in EE) |
|
| 243 | + * @param string|int $desired_index_size defaults to TableAnalysis::index_col_size, the max for utf8mb4. |
|
| 244 | + * @return bool whether an index was dropped or not |
|
| 245 | + * @throws /EE_Error if table analysis object isn't defined |
|
| 246 | + */ |
|
| 247 | + public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE) |
|
| 248 | + { |
|
| 249 | + if($column_name === null){ |
|
| 250 | + $column_name = $index_name; |
|
| 251 | + } |
|
| 252 | + if(!$this->getTableAnalysis()->tableExists($table_name)){ |
|
| 253 | + return false; |
|
| 254 | + } |
|
| 255 | + $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name); |
|
| 256 | + if(empty($index_entries)){ |
|
| 257 | + return false; |
|
| 258 | + } |
|
| 259 | + foreach($index_entries as $index_entry){ |
|
| 260 | + if( $column_name === $index_entry->Column_name |
|
| 261 | + && (string)$desired_index_size !== $index_entry->Sub_part){ |
|
| 262 | + return $this->dropIndex($table_name,$index_name); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + return false; |
|
| 266 | + } |
|
| 269 | 267 | |
| 270 | 268 | } |
@@ -145,11 +145,11 @@ discard block |
||
| 145 | 145 | $tables_to_delete[$table_name] = $table_name; |
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | - if( ! empty( $tables_to_delete ) ) { |
|
| 148 | + if ( ! empty($tables_to_delete)) { |
|
| 149 | 149 | global $wpdb; |
| 150 | 150 | //make sure we only have a unique strings in the array. |
| 151 | 151 | $tables_to_delete = array_unique($tables_to_delete); |
| 152 | - $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
| 152 | + $wpdb->query('DROP TABLE '.implode(', ', $tables_to_delete)); |
|
| 153 | 153 | } |
| 154 | 154 | return $tables_to_delete; |
| 155 | 155 | } |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
| 205 | 205 | /** @var \wpdb $wpdb */ |
| 206 | 206 | global $wpdb; |
| 207 | - $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate(); |
|
| 207 | + $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} ".$wpdb->get_charset_collate(); |
|
| 208 | 208 | |
| 209 | 209 | //get $wpdb to echo errors, but buffer them. This way at least WE know an error |
| 210 | 210 | //happened. And then we can choose to tell the end user |
@@ -248,20 +248,20 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | public function dropIndexIfSizeNot($table_name, $index_name, $column_name = null, $desired_index_size = TableAnalysis::INDEX_COLUMN_SIZE) |
| 250 | 250 | { |
| 251 | - if($column_name === null){ |
|
| 251 | + if ($column_name === null) { |
|
| 252 | 252 | $column_name = $index_name; |
| 253 | 253 | } |
| 254 | - if(!$this->getTableAnalysis()->tableExists($table_name)){ |
|
| 254 | + if ( ! $this->getTableAnalysis()->tableExists($table_name)) { |
|
| 255 | 255 | return false; |
| 256 | 256 | } |
| 257 | - $index_entries = $this->getTableAnalysis()->showIndexes($table_name,$index_name); |
|
| 258 | - if(empty($index_entries)){ |
|
| 257 | + $index_entries = $this->getTableAnalysis()->showIndexes($table_name, $index_name); |
|
| 258 | + if (empty($index_entries)) { |
|
| 259 | 259 | return false; |
| 260 | 260 | } |
| 261 | - foreach($index_entries as $index_entry){ |
|
| 262 | - if( $column_name === $index_entry->Column_name |
|
| 263 | - && (string)$desired_index_size !== $index_entry->Sub_part){ |
|
| 264 | - return $this->dropIndex($table_name,$index_name); |
|
| 261 | + foreach ($index_entries as $index_entry) { |
|
| 262 | + if ($column_name === $index_entry->Column_name |
|
| 263 | + && (string) $desired_index_size !== $index_entry->Sub_part) { |
|
| 264 | + return $this->dropIndex($table_name, $index_name); |
|
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | return false; |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -14,244 +14,244 @@ discard block |
||
| 14 | 14 | class EEH_Activation |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * constant used to indicate a cron task is no longer in use |
|
| 19 | - */ |
|
| 20 | - const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * option name that will indicate whether or not we still |
|
| 24 | - * need to create EE's folders in the uploads directory |
|
| 25 | - * (because if EE was installed without file system access, |
|
| 26 | - * we need to request credentials before we can create them) |
|
| 27 | - */ |
|
| 28 | - const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * WP_User->ID |
|
| 32 | - * |
|
| 33 | - * @var int |
|
| 34 | - */ |
|
| 35 | - private static $_default_creator_id; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * indicates whether or not we've already verified core's default data during this request, |
|
| 39 | - * because after migrations are done, any addons activated while in maintenance mode |
|
| 40 | - * will want to setup their own default data, and they might hook into core's default data |
|
| 41 | - * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 42 | - * This prevents doing that for EVERY single addon. |
|
| 43 | - * |
|
| 44 | - * @var boolean |
|
| 45 | - */ |
|
| 46 | - protected static $_initialized_db_content_already_in_this_request = false; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 50 | - */ |
|
| 51 | - private static $table_analysis; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 55 | - */ |
|
| 56 | - private static $table_manager; |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 61 | - */ |
|
| 62 | - public static function getTableAnalysis() |
|
| 63 | - { |
|
| 64 | - if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 65 | - self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 66 | - } |
|
| 67 | - return self::$table_analysis; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return \EventEspresso\core\services\database\TableManager |
|
| 73 | - */ |
|
| 74 | - public static function getTableManager() |
|
| 75 | - { |
|
| 76 | - if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 77 | - self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 78 | - } |
|
| 79 | - return self::$table_manager; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * _ensure_table_name_has_prefix |
|
| 85 | - * |
|
| 86 | - * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 87 | - * @access public |
|
| 88 | - * @static |
|
| 89 | - * @param $table_name |
|
| 90 | - * @return string |
|
| 91 | - */ |
|
| 92 | - public static function ensure_table_name_has_prefix($table_name) |
|
| 93 | - { |
|
| 94 | - return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * system_initialization |
|
| 100 | - * ensures the EE configuration settings are loaded with at least default options set |
|
| 101 | - * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 102 | - * |
|
| 103 | - * @access public |
|
| 104 | - * @static |
|
| 105 | - * @return void |
|
| 106 | - */ |
|
| 107 | - public static function system_initialization() |
|
| 108 | - { |
|
| 109 | - EEH_Activation::reset_and_update_config(); |
|
| 110 | - //which is fired BEFORE activation of plugin anyways |
|
| 111 | - EEH_Activation::verify_default_pages_exist(); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Sets the database schema and creates folders. This should |
|
| 117 | - * be called on plugin activation and reactivation |
|
| 118 | - * |
|
| 119 | - * @return boolean success, whether the database and folders are setup properly |
|
| 120 | - * @throws \EE_Error |
|
| 121 | - */ |
|
| 122 | - public static function initialize_db_and_folders() |
|
| 123 | - { |
|
| 124 | - $good_filesystem = EEH_Activation::create_upload_directories(); |
|
| 125 | - $good_db = EEH_Activation::create_database_tables(); |
|
| 126 | - return $good_filesystem && $good_db; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * assuming we have an up-to-date database schema, this will populate it |
|
| 132 | - * with default and initial data. This should be called |
|
| 133 | - * upon activation of a new plugin, reactivation, and at the end |
|
| 134 | - * of running migration scripts |
|
| 135 | - * |
|
| 136 | - * @throws \EE_Error |
|
| 137 | - */ |
|
| 138 | - public static function initialize_db_content() |
|
| 139 | - { |
|
| 140 | - //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 141 | - if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 142 | - return; |
|
| 143 | - } |
|
| 144 | - EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 145 | - |
|
| 146 | - EEH_Activation::initialize_system_questions(); |
|
| 147 | - EEH_Activation::insert_default_status_codes(); |
|
| 148 | - EEH_Activation::generate_default_message_templates(); |
|
| 149 | - EEH_Activation::create_no_ticket_prices_array(); |
|
| 150 | - EE_Registry::instance()->CAP->init_caps(); |
|
| 151 | - |
|
| 152 | - EEH_Activation::validate_messages_system(); |
|
| 153 | - EEH_Activation::insert_default_payment_methods(); |
|
| 154 | - //in case we've |
|
| 155 | - EEH_Activation::remove_cron_tasks(); |
|
| 156 | - EEH_Activation::create_cron_tasks(); |
|
| 157 | - // remove all TXN locks since that is being done via extra meta now |
|
| 158 | - delete_option('ee_locked_transactions'); |
|
| 159 | - //also, check for CAF default db content |
|
| 160 | - do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 161 | - //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 162 | - //which users really won't care about on initial activation |
|
| 163 | - EE_Error::overwrite_success(); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 169 | - * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 170 | - * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 171 | - * (null) |
|
| 172 | - * |
|
| 173 | - * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 174 | - * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 175 | - * @return array |
|
| 176 | - * @throws \EE_Error |
|
| 177 | - */ |
|
| 178 | - public static function get_cron_tasks($which_to_include) |
|
| 179 | - { |
|
| 180 | - $cron_tasks = apply_filters( |
|
| 181 | - 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 182 | - array( |
|
| 183 | - 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 17 | + /** |
|
| 18 | + * constant used to indicate a cron task is no longer in use |
|
| 19 | + */ |
|
| 20 | + const cron_task_no_longer_in_use = 'no_longer_in_use'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * option name that will indicate whether or not we still |
|
| 24 | + * need to create EE's folders in the uploads directory |
|
| 25 | + * (because if EE was installed without file system access, |
|
| 26 | + * we need to request credentials before we can create them) |
|
| 27 | + */ |
|
| 28 | + const upload_directories_incomplete_option_name = 'ee_upload_directories_incomplete'; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * WP_User->ID |
|
| 32 | + * |
|
| 33 | + * @var int |
|
| 34 | + */ |
|
| 35 | + private static $_default_creator_id; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * indicates whether or not we've already verified core's default data during this request, |
|
| 39 | + * because after migrations are done, any addons activated while in maintenance mode |
|
| 40 | + * will want to setup their own default data, and they might hook into core's default data |
|
| 41 | + * and trigger core to setup its default data. In which case they might all ask for core to init its default data. |
|
| 42 | + * This prevents doing that for EVERY single addon. |
|
| 43 | + * |
|
| 44 | + * @var boolean |
|
| 45 | + */ |
|
| 46 | + protected static $_initialized_db_content_already_in_this_request = false; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @var \EventEspresso\core\services\database\TableAnalysis $table_analysis |
|
| 50 | + */ |
|
| 51 | + private static $table_analysis; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @var \EventEspresso\core\services\database\TableManager $table_manager |
|
| 55 | + */ |
|
| 56 | + private static $table_manager; |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @return \EventEspresso\core\services\database\TableAnalysis |
|
| 61 | + */ |
|
| 62 | + public static function getTableAnalysis() |
|
| 63 | + { |
|
| 64 | + if (! self::$table_analysis instanceof \EventEspresso\core\services\database\TableAnalysis) { |
|
| 65 | + self::$table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
| 66 | + } |
|
| 67 | + return self::$table_analysis; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return \EventEspresso\core\services\database\TableManager |
|
| 73 | + */ |
|
| 74 | + public static function getTableManager() |
|
| 75 | + { |
|
| 76 | + if (! self::$table_manager instanceof \EventEspresso\core\services\database\TableManager) { |
|
| 77 | + self::$table_manager = EE_Registry::instance()->create('TableManager', array(), true); |
|
| 78 | + } |
|
| 79 | + return self::$table_manager; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * _ensure_table_name_has_prefix |
|
| 85 | + * |
|
| 86 | + * @deprecated instead use TableAnalysis::ensureTableNameHasPrefix() |
|
| 87 | + * @access public |
|
| 88 | + * @static |
|
| 89 | + * @param $table_name |
|
| 90 | + * @return string |
|
| 91 | + */ |
|
| 92 | + public static function ensure_table_name_has_prefix($table_name) |
|
| 93 | + { |
|
| 94 | + return \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * system_initialization |
|
| 100 | + * ensures the EE configuration settings are loaded with at least default options set |
|
| 101 | + * and that all critical EE pages have been generated with the appropriate shortcodes in place |
|
| 102 | + * |
|
| 103 | + * @access public |
|
| 104 | + * @static |
|
| 105 | + * @return void |
|
| 106 | + */ |
|
| 107 | + public static function system_initialization() |
|
| 108 | + { |
|
| 109 | + EEH_Activation::reset_and_update_config(); |
|
| 110 | + //which is fired BEFORE activation of plugin anyways |
|
| 111 | + EEH_Activation::verify_default_pages_exist(); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Sets the database schema and creates folders. This should |
|
| 117 | + * be called on plugin activation and reactivation |
|
| 118 | + * |
|
| 119 | + * @return boolean success, whether the database and folders are setup properly |
|
| 120 | + * @throws \EE_Error |
|
| 121 | + */ |
|
| 122 | + public static function initialize_db_and_folders() |
|
| 123 | + { |
|
| 124 | + $good_filesystem = EEH_Activation::create_upload_directories(); |
|
| 125 | + $good_db = EEH_Activation::create_database_tables(); |
|
| 126 | + return $good_filesystem && $good_db; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * assuming we have an up-to-date database schema, this will populate it |
|
| 132 | + * with default and initial data. This should be called |
|
| 133 | + * upon activation of a new plugin, reactivation, and at the end |
|
| 134 | + * of running migration scripts |
|
| 135 | + * |
|
| 136 | + * @throws \EE_Error |
|
| 137 | + */ |
|
| 138 | + public static function initialize_db_content() |
|
| 139 | + { |
|
| 140 | + //let's avoid doing all this logic repeatedly, especially when addons are requesting it |
|
| 141 | + if (EEH_Activation::$_initialized_db_content_already_in_this_request) { |
|
| 142 | + return; |
|
| 143 | + } |
|
| 144 | + EEH_Activation::$_initialized_db_content_already_in_this_request = true; |
|
| 145 | + |
|
| 146 | + EEH_Activation::initialize_system_questions(); |
|
| 147 | + EEH_Activation::insert_default_status_codes(); |
|
| 148 | + EEH_Activation::generate_default_message_templates(); |
|
| 149 | + EEH_Activation::create_no_ticket_prices_array(); |
|
| 150 | + EE_Registry::instance()->CAP->init_caps(); |
|
| 151 | + |
|
| 152 | + EEH_Activation::validate_messages_system(); |
|
| 153 | + EEH_Activation::insert_default_payment_methods(); |
|
| 154 | + //in case we've |
|
| 155 | + EEH_Activation::remove_cron_tasks(); |
|
| 156 | + EEH_Activation::create_cron_tasks(); |
|
| 157 | + // remove all TXN locks since that is being done via extra meta now |
|
| 158 | + delete_option('ee_locked_transactions'); |
|
| 159 | + //also, check for CAF default db content |
|
| 160 | + do_action('AHEE__EEH_Activation__initialize_db_content'); |
|
| 161 | + //also: EEM_Gateways::load_all_gateways() outputs a lot of success messages |
|
| 162 | + //which users really won't care about on initial activation |
|
| 163 | + EE_Error::overwrite_success(); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Returns an array of cron tasks. Array values are the actions fired by the cron tasks (the "hooks"), |
|
| 169 | + * values are the frequency (the "recurrence"). See http://codex.wordpress.org/Function_Reference/wp_schedule_event |
|
| 170 | + * If the cron task should NO longer be used, it should have a value of EEH_Activation::cron_task_no_longer_in_use |
|
| 171 | + * (null) |
|
| 172 | + * |
|
| 173 | + * @param string $which_to_include can be 'current' (ones that are currently in use), |
|
| 174 | + * 'old' (only returns ones that should no longer be used),or 'all', |
|
| 175 | + * @return array |
|
| 176 | + * @throws \EE_Error |
|
| 177 | + */ |
|
| 178 | + public static function get_cron_tasks($which_to_include) |
|
| 179 | + { |
|
| 180 | + $cron_tasks = apply_filters( |
|
| 181 | + 'FHEE__EEH_Activation__get_cron_tasks', |
|
| 182 | + array( |
|
| 183 | + 'AHEE__EE_Cron_Tasks__clean_up_junk_transactions' => 'hourly', |
|
| 184 | 184 | // 'AHEE__EE_Cron_Tasks__finalize_abandoned_transactions' => EEH_Activation::cron_task_no_longer_in_use, actually this is still in use |
| 185 | - 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 186 | - //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 187 | - 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 188 | - ) |
|
| 189 | - ); |
|
| 190 | - if ($which_to_include === 'old') { |
|
| 191 | - $cron_tasks = array_filter( |
|
| 192 | - $cron_tasks, |
|
| 193 | - function ($value) { |
|
| 194 | - return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 195 | - } |
|
| 196 | - ); |
|
| 197 | - } elseif ($which_to_include === 'current') { |
|
| 198 | - $cron_tasks = array_filter($cron_tasks); |
|
| 199 | - } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 200 | - throw new EE_Error( |
|
| 201 | - sprintf( |
|
| 202 | - __( |
|
| 203 | - 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 204 | - 'event_espresso' |
|
| 205 | - ), |
|
| 206 | - $which_to_include |
|
| 207 | - ) |
|
| 208 | - ); |
|
| 209 | - } |
|
| 210 | - return $cron_tasks; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 216 | - * |
|
| 217 | - * @throws \EE_Error |
|
| 218 | - */ |
|
| 219 | - public static function create_cron_tasks() |
|
| 220 | - { |
|
| 221 | - |
|
| 222 | - foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 223 | - if (! wp_next_scheduled($hook_name)) { |
|
| 224 | - /** |
|
| 225 | - * This allows client code to define the initial start timestamp for this schedule. |
|
| 226 | - */ |
|
| 227 | - if (is_array($frequency) |
|
| 228 | - && count($frequency) === 2 |
|
| 229 | - && isset($frequency[0], $frequency[1]) |
|
| 230 | - ) { |
|
| 231 | - $start_timestamp = $frequency[0]; |
|
| 232 | - $frequency = $frequency[1]; |
|
| 233 | - } else { |
|
| 234 | - $start_timestamp = time(); |
|
| 235 | - } |
|
| 236 | - wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Remove the currently-existing and now-removed cron tasks. |
|
| 245 | - * |
|
| 246 | - * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 247 | - * @throws \EE_Error |
|
| 248 | - */ |
|
| 249 | - public static function remove_cron_tasks($remove_all = true) |
|
| 250 | - { |
|
| 251 | - $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 252 | - $crons = _get_cron_array(); |
|
| 253 | - $crons = is_array($crons) ? $crons : array(); |
|
| 254 | - /* reminder of what $crons look like: |
|
| 185 | + 'AHEE__EE_Cron_Tasks__update_transaction_with_payment' => EEH_Activation::cron_task_no_longer_in_use, |
|
| 186 | + //there may have been a bug which prevented from these cron tasks from getting unscheduled, so we might want to remove these for a few updates |
|
| 187 | + 'AHEE_EE_Cron_Tasks__clean_out_old_gateway_logs' => 'daily', |
|
| 188 | + ) |
|
| 189 | + ); |
|
| 190 | + if ($which_to_include === 'old') { |
|
| 191 | + $cron_tasks = array_filter( |
|
| 192 | + $cron_tasks, |
|
| 193 | + function ($value) { |
|
| 194 | + return $value === EEH_Activation::cron_task_no_longer_in_use; |
|
| 195 | + } |
|
| 196 | + ); |
|
| 197 | + } elseif ($which_to_include === 'current') { |
|
| 198 | + $cron_tasks = array_filter($cron_tasks); |
|
| 199 | + } elseif (WP_DEBUG && $which_to_include !== 'all') { |
|
| 200 | + throw new EE_Error( |
|
| 201 | + sprintf( |
|
| 202 | + __( |
|
| 203 | + 'Invalid argument of "%1$s" passed to EEH_Activation::get_cron_tasks. Valid values are "all", "old" and "current".', |
|
| 204 | + 'event_espresso' |
|
| 205 | + ), |
|
| 206 | + $which_to_include |
|
| 207 | + ) |
|
| 208 | + ); |
|
| 209 | + } |
|
| 210 | + return $cron_tasks; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Ensure cron tasks are setup (the removal of crons should be done by remove_crons()) |
|
| 216 | + * |
|
| 217 | + * @throws \EE_Error |
|
| 218 | + */ |
|
| 219 | + public static function create_cron_tasks() |
|
| 220 | + { |
|
| 221 | + |
|
| 222 | + foreach (EEH_Activation::get_cron_tasks('current') as $hook_name => $frequency) { |
|
| 223 | + if (! wp_next_scheduled($hook_name)) { |
|
| 224 | + /** |
|
| 225 | + * This allows client code to define the initial start timestamp for this schedule. |
|
| 226 | + */ |
|
| 227 | + if (is_array($frequency) |
|
| 228 | + && count($frequency) === 2 |
|
| 229 | + && isset($frequency[0], $frequency[1]) |
|
| 230 | + ) { |
|
| 231 | + $start_timestamp = $frequency[0]; |
|
| 232 | + $frequency = $frequency[1]; |
|
| 233 | + } else { |
|
| 234 | + $start_timestamp = time(); |
|
| 235 | + } |
|
| 236 | + wp_schedule_event($start_timestamp, $frequency, $hook_name); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Remove the currently-existing and now-removed cron tasks. |
|
| 245 | + * |
|
| 246 | + * @param boolean $remove_all whether to only remove the old ones, or remove absolutely ALL the EE ones |
|
| 247 | + * @throws \EE_Error |
|
| 248 | + */ |
|
| 249 | + public static function remove_cron_tasks($remove_all = true) |
|
| 250 | + { |
|
| 251 | + $cron_tasks_to_remove = $remove_all ? 'all' : 'old'; |
|
| 252 | + $crons = _get_cron_array(); |
|
| 253 | + $crons = is_array($crons) ? $crons : array(); |
|
| 254 | + /* reminder of what $crons look like: |
|
| 255 | 255 | * Top-level keys are timestamps, and their values are arrays. |
| 256 | 256 | * The 2nd level arrays have keys with each of the cron task hook names to run at that time |
| 257 | 257 | * and their values are arrays. |
@@ -268,912 +268,912 @@ discard block |
||
| 268 | 268 | * ... |
| 269 | 269 | * ... |
| 270 | 270 | */ |
| 271 | - $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 272 | - foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 273 | - if (is_array($hooks_to_fire_at_time)) { |
|
| 274 | - foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 275 | - if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 276 | - && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 277 | - ) { |
|
| 278 | - unset($crons[$timestamp][$hook_name]); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - //also take care of any empty cron timestamps. |
|
| 282 | - if (empty($hooks_to_fire_at_time)) { |
|
| 283 | - unset($crons[$timestamp]); |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - _set_cron_array($crons); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - |
|
| 291 | - /** |
|
| 292 | - * CPT_initialization |
|
| 293 | - * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 294 | - * |
|
| 295 | - * @access public |
|
| 296 | - * @static |
|
| 297 | - * @return void |
|
| 298 | - */ |
|
| 299 | - public static function CPT_initialization() |
|
| 300 | - { |
|
| 301 | - // register Custom Post Types |
|
| 302 | - EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 303 | - flush_rewrite_rules(); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * reset_and_update_config |
|
| 310 | - * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 311 | - * If there is old calendar config data saved, then it will get converted on activation. |
|
| 312 | - * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 313 | - * |
|
| 314 | - * @access public |
|
| 315 | - * @static |
|
| 316 | - * @return void |
|
| 317 | - */ |
|
| 318 | - public static function reset_and_update_config() |
|
| 319 | - { |
|
| 320 | - do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 321 | - add_filter( |
|
| 322 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 323 | - array('EEH_Activation', 'migrate_old_config_data'), |
|
| 324 | - 10, |
|
| 325 | - 3 |
|
| 326 | - ); |
|
| 327 | - //EE_Config::reset(); |
|
| 328 | - if (! EE_Config::logging_enabled()) { |
|
| 329 | - delete_option(EE_Config::LOG_NAME); |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - /** |
|
| 335 | - * load_calendar_config |
|
| 336 | - * |
|
| 337 | - * @access public |
|
| 338 | - * @return void |
|
| 339 | - */ |
|
| 340 | - public static function load_calendar_config() |
|
| 341 | - { |
|
| 342 | - // grab array of all plugin folders and loop thru it |
|
| 343 | - $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 344 | - if (empty($plugins)) { |
|
| 345 | - return; |
|
| 346 | - } |
|
| 347 | - foreach ($plugins as $plugin_path) { |
|
| 348 | - // grab plugin folder name from path |
|
| 349 | - $plugin = basename($plugin_path); |
|
| 350 | - // drill down to Espresso plugins |
|
| 351 | - // then to calendar related plugins |
|
| 352 | - if ( |
|
| 353 | - strpos($plugin, 'espresso') !== false |
|
| 354 | - || strpos($plugin, 'Espresso') !== false |
|
| 355 | - || strpos($plugin, 'ee4') !== false |
|
| 356 | - || strpos($plugin, 'EE4') !== false |
|
| 357 | - || strpos($plugin, 'calendar') !== false |
|
| 358 | - ) { |
|
| 359 | - // this is what we are looking for |
|
| 360 | - $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 361 | - // does it exist in this folder ? |
|
| 362 | - if (is_readable($calendar_config)) { |
|
| 363 | - // YEAH! let's load it |
|
| 364 | - require_once($calendar_config); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * _migrate_old_config_data |
|
| 374 | - * |
|
| 375 | - * @access public |
|
| 376 | - * @param array|stdClass $settings |
|
| 377 | - * @param string $config |
|
| 378 | - * @param \EE_Config $EE_Config |
|
| 379 | - * @return \stdClass |
|
| 380 | - */ |
|
| 381 | - public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 382 | - { |
|
| 383 | - $convert_from_array = array('addons'); |
|
| 384 | - // in case old settings were saved as an array |
|
| 385 | - if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 386 | - // convert existing settings to an object |
|
| 387 | - $config_array = $settings; |
|
| 388 | - $settings = new stdClass(); |
|
| 389 | - foreach ($config_array as $key => $value) { |
|
| 390 | - if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 391 | - $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 392 | - } else { |
|
| 393 | - $settings->{$key} = $value; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 397 | - } |
|
| 398 | - return $settings; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * deactivate_event_espresso |
|
| 404 | - * |
|
| 405 | - * @access public |
|
| 406 | - * @static |
|
| 407 | - * @return void |
|
| 408 | - */ |
|
| 409 | - public static function deactivate_event_espresso() |
|
| 410 | - { |
|
| 411 | - // check permissions |
|
| 412 | - if (current_user_can('activate_plugins')) { |
|
| 413 | - deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * verify_default_pages_exist |
|
| 423 | - * |
|
| 424 | - * @access public |
|
| 425 | - * @static |
|
| 426 | - * @return void |
|
| 427 | - */ |
|
| 428 | - public static function verify_default_pages_exist() |
|
| 429 | - { |
|
| 430 | - $critical_page_problem = false; |
|
| 431 | - $critical_pages = array( |
|
| 432 | - array( |
|
| 433 | - 'id' => 'reg_page_id', |
|
| 434 | - 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 435 | - 'post' => null, |
|
| 436 | - 'code' => 'ESPRESSO_CHECKOUT', |
|
| 437 | - ), |
|
| 438 | - array( |
|
| 439 | - 'id' => 'txn_page_id', |
|
| 440 | - 'name' => __('Transactions', 'event_espresso'), |
|
| 441 | - 'post' => null, |
|
| 442 | - 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 443 | - ), |
|
| 444 | - array( |
|
| 445 | - 'id' => 'thank_you_page_id', |
|
| 446 | - 'name' => __('Thank You', 'event_espresso'), |
|
| 447 | - 'post' => null, |
|
| 448 | - 'code' => 'ESPRESSO_THANK_YOU', |
|
| 449 | - ), |
|
| 450 | - array( |
|
| 451 | - 'id' => 'cancel_page_id', |
|
| 452 | - 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 453 | - 'post' => null, |
|
| 454 | - 'code' => 'ESPRESSO_CANCELLED', |
|
| 455 | - ), |
|
| 456 | - ); |
|
| 457 | - $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 458 | - foreach ($critical_pages as $critical_page) { |
|
| 459 | - // is critical page ID set in config ? |
|
| 460 | - if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 461 | - // attempt to find post by ID |
|
| 462 | - $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 463 | - } |
|
| 464 | - // no dice? |
|
| 465 | - if ($critical_page['post'] === null) { |
|
| 466 | - // attempt to find post by title |
|
| 467 | - $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 468 | - // still nothing? |
|
| 469 | - if ($critical_page['post'] === null) { |
|
| 470 | - $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 471 | - // REALLY? Still nothing ??!?!? |
|
| 472 | - if ($critical_page['post'] === null) { |
|
| 473 | - $msg = __( |
|
| 474 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 475 | - 'event_espresso' |
|
| 476 | - ); |
|
| 477 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 478 | - break; |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - // check that Post ID matches critical page ID in config |
|
| 483 | - if ( |
|
| 484 | - isset($critical_page['post']->ID) |
|
| 485 | - && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 486 | - ) { |
|
| 487 | - //update Config with post ID |
|
| 488 | - $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 489 | - if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 490 | - $msg = __( |
|
| 491 | - 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 492 | - 'event_espresso' |
|
| 493 | - ); |
|
| 494 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - $critical_page_problem = |
|
| 498 | - ! isset($critical_page['post']->post_status) |
|
| 499 | - || $critical_page['post']->post_status !== 'publish' |
|
| 500 | - || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 501 | - ? true |
|
| 502 | - : $critical_page_problem; |
|
| 503 | - } |
|
| 504 | - if ($critical_page_problem) { |
|
| 505 | - $msg = sprintf( |
|
| 506 | - __( |
|
| 507 | - 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 508 | - 'event_espresso' |
|
| 509 | - ), |
|
| 510 | - '<a href="' |
|
| 511 | - . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
| 512 | - . '">' |
|
| 513 | - . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 514 | - . '</a>' |
|
| 515 | - ); |
|
| 516 | - EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 517 | - } |
|
| 518 | - if (EE_Error::has_notices()) { |
|
| 519 | - EE_Error::get_notices(false, true, true); |
|
| 520 | - } |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * Returns the first post which uses the specified shortcode |
|
| 527 | - * |
|
| 528 | - * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 529 | - * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 530 | - * "[ESPRESSO_THANK_YOU" |
|
| 531 | - * (we don't search for the closing shortcode bracket because they might have added |
|
| 532 | - * parameter to the shortcode |
|
| 533 | - * @return WP_Post or NULl |
|
| 534 | - */ |
|
| 535 | - public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 536 | - { |
|
| 537 | - global $wpdb; |
|
| 538 | - $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 539 | - $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 540 | - if ($post_id) { |
|
| 541 | - return get_post($post_id); |
|
| 542 | - } else { |
|
| 543 | - return null; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * This function generates a post for critical espresso pages |
|
| 550 | - * |
|
| 551 | - * @access public |
|
| 552 | - * @static |
|
| 553 | - * @param array $critical_page |
|
| 554 | - * @return array |
|
| 555 | - */ |
|
| 556 | - public static function create_critical_page($critical_page) |
|
| 557 | - { |
|
| 558 | - |
|
| 559 | - $post_args = array( |
|
| 560 | - 'post_title' => $critical_page['name'], |
|
| 561 | - 'post_status' => 'publish', |
|
| 562 | - 'post_type' => 'page', |
|
| 563 | - 'comment_status' => 'closed', |
|
| 564 | - 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 565 | - ); |
|
| 566 | - |
|
| 567 | - $post_id = wp_insert_post($post_args); |
|
| 568 | - if (! $post_id) { |
|
| 569 | - $msg = sprintf( |
|
| 570 | - __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 571 | - $critical_page['name'] |
|
| 572 | - ); |
|
| 573 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 574 | - return $critical_page; |
|
| 575 | - } |
|
| 576 | - // get newly created post's details |
|
| 577 | - if (! $critical_page['post'] = get_post($post_id)) { |
|
| 578 | - $msg = sprintf( |
|
| 579 | - __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 580 | - $critical_page['name'] |
|
| 581 | - ); |
|
| 582 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - return $critical_page; |
|
| 586 | - |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 594 | - * The role being used to check is filterable. |
|
| 595 | - * |
|
| 596 | - * @since 4.6.0 |
|
| 597 | - * @global WPDB $wpdb |
|
| 598 | - * @return mixed null|int WP_user ID or NULL |
|
| 599 | - */ |
|
| 600 | - public static function get_default_creator_id() |
|
| 601 | - { |
|
| 602 | - global $wpdb; |
|
| 603 | - if ( ! empty(self::$_default_creator_id)) { |
|
| 604 | - return self::$_default_creator_id; |
|
| 605 | - }/**/ |
|
| 606 | - $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 607 | - //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 608 | - $pre_filtered_id = apply_filters( |
|
| 609 | - 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 610 | - false, |
|
| 611 | - $role_to_check |
|
| 612 | - ); |
|
| 613 | - if ($pre_filtered_id !== false) { |
|
| 614 | - return (int)$pre_filtered_id; |
|
| 615 | - } |
|
| 616 | - $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 617 | - $query = $wpdb->prepare( |
|
| 618 | - "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 619 | - '%' . $role_to_check . '%' |
|
| 620 | - ); |
|
| 621 | - $user_id = $wpdb->get_var($query); |
|
| 622 | - $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 623 | - if ($user_id && (int)$user_id) { |
|
| 624 | - self::$_default_creator_id = (int)$user_id; |
|
| 625 | - return self::$_default_creator_id; |
|
| 626 | - } else { |
|
| 627 | - return null; |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * used by EE and EE addons during plugin activation to create tables. |
|
| 635 | - * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 636 | - * but includes extra logic regarding activations. |
|
| 637 | - * |
|
| 638 | - * @access public |
|
| 639 | - * @static |
|
| 640 | - * @param string $table_name without the $wpdb->prefix |
|
| 641 | - * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 642 | - * table query) |
|
| 643 | - * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 644 | - * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 645 | - * and new once this function is done (ie, you really do want to CREATE a |
|
| 646 | - * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 647 | - * you just want to verify the table exists and matches this definition |
|
| 648 | - * (and if it HAS data in it you want to leave it be) |
|
| 649 | - * @return void |
|
| 650 | - * @throws EE_Error if there are database errors |
|
| 651 | - */ |
|
| 652 | - public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 653 | - { |
|
| 654 | - if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 655 | - return; |
|
| 656 | - } |
|
| 657 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 658 | - if ( ! function_exists('dbDelta')) { |
|
| 659 | - require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 660 | - } |
|
| 661 | - $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 662 | - $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 663 | - // do we need to first delete an existing version of this table ? |
|
| 664 | - if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 665 | - // ok, delete the table... but ONLY if it's empty |
|
| 666 | - $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 667 | - // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 668 | - if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 669 | - \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 670 | - } else if ( ! $deleted_safely) { |
|
| 671 | - // so we should be more cautious rather than just dropping tables so easily |
|
| 672 | - error_log( |
|
| 673 | - sprintf( |
|
| 674 | - __( |
|
| 675 | - 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 676 | - 'event_espresso' |
|
| 677 | - ), |
|
| 678 | - $wp_table_name, |
|
| 679 | - '<br/>', |
|
| 680 | - 'espresso_db_update' |
|
| 681 | - ) |
|
| 682 | - ); |
|
| 683 | - } |
|
| 684 | - } |
|
| 685 | - $engine = str_replace('ENGINE=', '', $engine); |
|
| 686 | - \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * add_column_if_it_doesn't_exist |
|
| 693 | - * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 694 | - * |
|
| 695 | - * @access public |
|
| 696 | - * @static |
|
| 697 | - * @deprecated instead use TableManager::addColumn() |
|
| 698 | - * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 699 | - * @param string $column_name |
|
| 700 | - * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 701 | - * 'VARCHAR(10)' |
|
| 702 | - * @return bool|int |
|
| 703 | - */ |
|
| 704 | - public static function add_column_if_it_doesnt_exist( |
|
| 705 | - $table_name, |
|
| 706 | - $column_name, |
|
| 707 | - $column_info = 'INT UNSIGNED NOT NULL' |
|
| 708 | - ) { |
|
| 709 | - return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * get_fields_on_table |
|
| 715 | - * Gets all the fields on the database table. |
|
| 716 | - * |
|
| 717 | - * @access public |
|
| 718 | - * @deprecated instead use TableManager::getTableColumns() |
|
| 719 | - * @static |
|
| 720 | - * @param string $table_name , without prefixed $wpdb->prefix |
|
| 721 | - * @return array of database column names |
|
| 722 | - */ |
|
| 723 | - public static function get_fields_on_table($table_name = null) |
|
| 724 | - { |
|
| 725 | - return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * db_table_is_empty |
|
| 731 | - * |
|
| 732 | - * @access public\ |
|
| 733 | - * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 734 | - * @static |
|
| 735 | - * @param string $table_name |
|
| 736 | - * @return bool |
|
| 737 | - */ |
|
| 738 | - public static function db_table_is_empty($table_name) |
|
| 739 | - { |
|
| 740 | - return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - |
|
| 744 | - /** |
|
| 745 | - * delete_db_table_if_empty |
|
| 746 | - * |
|
| 747 | - * @access public |
|
| 748 | - * @static |
|
| 749 | - * @param string $table_name |
|
| 750 | - * @return bool | int |
|
| 751 | - */ |
|
| 752 | - public static function delete_db_table_if_empty($table_name) |
|
| 753 | - { |
|
| 754 | - if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 755 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 756 | - } |
|
| 757 | - return false; |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - |
|
| 761 | - /** |
|
| 762 | - * delete_unused_db_table |
|
| 763 | - * |
|
| 764 | - * @access public |
|
| 765 | - * @static |
|
| 766 | - * @deprecated instead use TableManager::dropTable() |
|
| 767 | - * @param string $table_name |
|
| 768 | - * @return bool | int |
|
| 769 | - */ |
|
| 770 | - public static function delete_unused_db_table($table_name) |
|
| 771 | - { |
|
| 772 | - return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - |
|
| 776 | - /** |
|
| 777 | - * drop_index |
|
| 778 | - * |
|
| 779 | - * @access public |
|
| 780 | - * @static |
|
| 781 | - * @deprecated instead use TableManager::dropIndex() |
|
| 782 | - * @param string $table_name |
|
| 783 | - * @param string $index_name |
|
| 784 | - * @return bool | int |
|
| 785 | - */ |
|
| 786 | - public static function drop_index($table_name, $index_name) |
|
| 787 | - { |
|
| 788 | - return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * create_database_tables |
|
| 795 | - * |
|
| 796 | - * @access public |
|
| 797 | - * @static |
|
| 798 | - * @throws EE_Error |
|
| 799 | - * @return boolean success (whether database is setup properly or not) |
|
| 800 | - */ |
|
| 801 | - public static function create_database_tables() |
|
| 802 | - { |
|
| 803 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 804 | - //find the migration script that sets the database to be compatible with the code |
|
| 805 | - $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 806 | - if ($dms_name) { |
|
| 807 | - $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 808 | - $current_data_migration_script->set_migrating(false); |
|
| 809 | - $current_data_migration_script->schema_changes_before_migration(); |
|
| 810 | - $current_data_migration_script->schema_changes_after_migration(); |
|
| 811 | - if ($current_data_migration_script->get_errors()) { |
|
| 812 | - if (WP_DEBUG) { |
|
| 813 | - foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 814 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 815 | - } |
|
| 816 | - } else { |
|
| 817 | - EE_Error::add_error( |
|
| 818 | - __( |
|
| 819 | - 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 271 | + $ee_cron_tasks_to_remove = EEH_Activation::get_cron_tasks($cron_tasks_to_remove); |
|
| 272 | + foreach ($crons as $timestamp => $hooks_to_fire_at_time) { |
|
| 273 | + if (is_array($hooks_to_fire_at_time)) { |
|
| 274 | + foreach ($hooks_to_fire_at_time as $hook_name => $hook_actions) { |
|
| 275 | + if (isset($ee_cron_tasks_to_remove[$hook_name]) |
|
| 276 | + && is_array($ee_cron_tasks_to_remove[$hook_name]) |
|
| 277 | + ) { |
|
| 278 | + unset($crons[$timestamp][$hook_name]); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + //also take care of any empty cron timestamps. |
|
| 282 | + if (empty($hooks_to_fire_at_time)) { |
|
| 283 | + unset($crons[$timestamp]); |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + _set_cron_array($crons); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + |
|
| 291 | + /** |
|
| 292 | + * CPT_initialization |
|
| 293 | + * registers all EE CPTs ( Custom Post Types ) then flushes rewrite rules so that all endpoints exist |
|
| 294 | + * |
|
| 295 | + * @access public |
|
| 296 | + * @static |
|
| 297 | + * @return void |
|
| 298 | + */ |
|
| 299 | + public static function CPT_initialization() |
|
| 300 | + { |
|
| 301 | + // register Custom Post Types |
|
| 302 | + EE_Registry::instance()->load_core('Register_CPTs'); |
|
| 303 | + flush_rewrite_rules(); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * reset_and_update_config |
|
| 310 | + * The following code was moved over from EE_Config so that it will no longer run on every request. |
|
| 311 | + * If there is old calendar config data saved, then it will get converted on activation. |
|
| 312 | + * This was basically a DMS before we had DMS's, and will get removed after a few more versions. |
|
| 313 | + * |
|
| 314 | + * @access public |
|
| 315 | + * @static |
|
| 316 | + * @return void |
|
| 317 | + */ |
|
| 318 | + public static function reset_and_update_config() |
|
| 319 | + { |
|
| 320 | + do_action('AHEE__EE_Config___load_core_config__start', array('EEH_Activation', 'load_calendar_config')); |
|
| 321 | + add_filter( |
|
| 322 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
| 323 | + array('EEH_Activation', 'migrate_old_config_data'), |
|
| 324 | + 10, |
|
| 325 | + 3 |
|
| 326 | + ); |
|
| 327 | + //EE_Config::reset(); |
|
| 328 | + if (! EE_Config::logging_enabled()) { |
|
| 329 | + delete_option(EE_Config::LOG_NAME); |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + /** |
|
| 335 | + * load_calendar_config |
|
| 336 | + * |
|
| 337 | + * @access public |
|
| 338 | + * @return void |
|
| 339 | + */ |
|
| 340 | + public static function load_calendar_config() |
|
| 341 | + { |
|
| 342 | + // grab array of all plugin folders and loop thru it |
|
| 343 | + $plugins = glob(WP_PLUGIN_DIR . DS . '*', GLOB_ONLYDIR); |
|
| 344 | + if (empty($plugins)) { |
|
| 345 | + return; |
|
| 346 | + } |
|
| 347 | + foreach ($plugins as $plugin_path) { |
|
| 348 | + // grab plugin folder name from path |
|
| 349 | + $plugin = basename($plugin_path); |
|
| 350 | + // drill down to Espresso plugins |
|
| 351 | + // then to calendar related plugins |
|
| 352 | + if ( |
|
| 353 | + strpos($plugin, 'espresso') !== false |
|
| 354 | + || strpos($plugin, 'Espresso') !== false |
|
| 355 | + || strpos($plugin, 'ee4') !== false |
|
| 356 | + || strpos($plugin, 'EE4') !== false |
|
| 357 | + || strpos($plugin, 'calendar') !== false |
|
| 358 | + ) { |
|
| 359 | + // this is what we are looking for |
|
| 360 | + $calendar_config = $plugin_path . DS . 'EE_Calendar_Config.php'; |
|
| 361 | + // does it exist in this folder ? |
|
| 362 | + if (is_readable($calendar_config)) { |
|
| 363 | + // YEAH! let's load it |
|
| 364 | + require_once($calendar_config); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * _migrate_old_config_data |
|
| 374 | + * |
|
| 375 | + * @access public |
|
| 376 | + * @param array|stdClass $settings |
|
| 377 | + * @param string $config |
|
| 378 | + * @param \EE_Config $EE_Config |
|
| 379 | + * @return \stdClass |
|
| 380 | + */ |
|
| 381 | + public static function migrate_old_config_data($settings = array(), $config = '', EE_Config $EE_Config) |
|
| 382 | + { |
|
| 383 | + $convert_from_array = array('addons'); |
|
| 384 | + // in case old settings were saved as an array |
|
| 385 | + if (is_array($settings) && in_array($config, $convert_from_array)) { |
|
| 386 | + // convert existing settings to an object |
|
| 387 | + $config_array = $settings; |
|
| 388 | + $settings = new stdClass(); |
|
| 389 | + foreach ($config_array as $key => $value) { |
|
| 390 | + if ($key === 'calendar' && class_exists('EE_Calendar_Config')) { |
|
| 391 | + $EE_Config->set_config('addons', 'EE_Calendar', 'EE_Calendar_Config', $value); |
|
| 392 | + } else { |
|
| 393 | + $settings->{$key} = $value; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + add_filter('FHEE__EE_Config___load_core_config__update_espresso_config', '__return_true'); |
|
| 397 | + } |
|
| 398 | + return $settings; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * deactivate_event_espresso |
|
| 404 | + * |
|
| 405 | + * @access public |
|
| 406 | + * @static |
|
| 407 | + * @return void |
|
| 408 | + */ |
|
| 409 | + public static function deactivate_event_espresso() |
|
| 410 | + { |
|
| 411 | + // check permissions |
|
| 412 | + if (current_user_can('activate_plugins')) { |
|
| 413 | + deactivate_plugins(EE_PLUGIN_BASENAME, true); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * verify_default_pages_exist |
|
| 423 | + * |
|
| 424 | + * @access public |
|
| 425 | + * @static |
|
| 426 | + * @return void |
|
| 427 | + */ |
|
| 428 | + public static function verify_default_pages_exist() |
|
| 429 | + { |
|
| 430 | + $critical_page_problem = false; |
|
| 431 | + $critical_pages = array( |
|
| 432 | + array( |
|
| 433 | + 'id' => 'reg_page_id', |
|
| 434 | + 'name' => __('Registration Checkout', 'event_espresso'), |
|
| 435 | + 'post' => null, |
|
| 436 | + 'code' => 'ESPRESSO_CHECKOUT', |
|
| 437 | + ), |
|
| 438 | + array( |
|
| 439 | + 'id' => 'txn_page_id', |
|
| 440 | + 'name' => __('Transactions', 'event_espresso'), |
|
| 441 | + 'post' => null, |
|
| 442 | + 'code' => 'ESPRESSO_TXN_PAGE', |
|
| 443 | + ), |
|
| 444 | + array( |
|
| 445 | + 'id' => 'thank_you_page_id', |
|
| 446 | + 'name' => __('Thank You', 'event_espresso'), |
|
| 447 | + 'post' => null, |
|
| 448 | + 'code' => 'ESPRESSO_THANK_YOU', |
|
| 449 | + ), |
|
| 450 | + array( |
|
| 451 | + 'id' => 'cancel_page_id', |
|
| 452 | + 'name' => __('Registration Cancelled', 'event_espresso'), |
|
| 453 | + 'post' => null, |
|
| 454 | + 'code' => 'ESPRESSO_CANCELLED', |
|
| 455 | + ), |
|
| 456 | + ); |
|
| 457 | + $EE_Core_Config = EE_Registry::instance()->CFG->core; |
|
| 458 | + foreach ($critical_pages as $critical_page) { |
|
| 459 | + // is critical page ID set in config ? |
|
| 460 | + if ($EE_Core_Config->{$critical_page['id']} !== false) { |
|
| 461 | + // attempt to find post by ID |
|
| 462 | + $critical_page['post'] = get_post($EE_Core_Config->{$critical_page['id']}); |
|
| 463 | + } |
|
| 464 | + // no dice? |
|
| 465 | + if ($critical_page['post'] === null) { |
|
| 466 | + // attempt to find post by title |
|
| 467 | + $critical_page['post'] = self::get_page_by_ee_shortcode($critical_page['code']); |
|
| 468 | + // still nothing? |
|
| 469 | + if ($critical_page['post'] === null) { |
|
| 470 | + $critical_page = EEH_Activation::create_critical_page($critical_page); |
|
| 471 | + // REALLY? Still nothing ??!?!? |
|
| 472 | + if ($critical_page['post'] === null) { |
|
| 473 | + $msg = __( |
|
| 474 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 475 | + 'event_espresso' |
|
| 476 | + ); |
|
| 477 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 478 | + break; |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + // check that Post ID matches critical page ID in config |
|
| 483 | + if ( |
|
| 484 | + isset($critical_page['post']->ID) |
|
| 485 | + && $critical_page['post']->ID !== $EE_Core_Config->{$critical_page['id']} |
|
| 486 | + ) { |
|
| 487 | + //update Config with post ID |
|
| 488 | + $EE_Core_Config->{$critical_page['id']} = $critical_page['post']->ID; |
|
| 489 | + if (! EE_Config::instance()->update_espresso_config(false, false)) { |
|
| 490 | + $msg = __( |
|
| 491 | + 'The Event Espresso critical page configuration settings could not be updated.', |
|
| 492 | + 'event_espresso' |
|
| 493 | + ); |
|
| 494 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + $critical_page_problem = |
|
| 498 | + ! isset($critical_page['post']->post_status) |
|
| 499 | + || $critical_page['post']->post_status !== 'publish' |
|
| 500 | + || strpos($critical_page['post']->post_content, $critical_page['code']) === false |
|
| 501 | + ? true |
|
| 502 | + : $critical_page_problem; |
|
| 503 | + } |
|
| 504 | + if ($critical_page_problem) { |
|
| 505 | + $msg = sprintf( |
|
| 506 | + __( |
|
| 507 | + 'A potential issue has been detected with one or more of your Event Espresso pages. Go to %s to view your Event Espresso pages.', |
|
| 508 | + 'event_espresso' |
|
| 509 | + ), |
|
| 510 | + '<a href="' |
|
| 511 | + . admin_url('admin.php?page=espresso_general_settings&action=critical_pages') |
|
| 512 | + . '">' |
|
| 513 | + . __('Event Espresso Critical Pages Settings', 'event_espresso') |
|
| 514 | + . '</a>' |
|
| 515 | + ); |
|
| 516 | + EE_Error::add_persistent_admin_notice('critical_page_problem', $msg); |
|
| 517 | + } |
|
| 518 | + if (EE_Error::has_notices()) { |
|
| 519 | + EE_Error::get_notices(false, true, true); |
|
| 520 | + } |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * Returns the first post which uses the specified shortcode |
|
| 527 | + * |
|
| 528 | + * @param string $ee_shortcode usually one of the critical pages shortcodes, eg |
|
| 529 | + * ESPRESSO_THANK_YOU. So we will search fora post with the content |
|
| 530 | + * "[ESPRESSO_THANK_YOU" |
|
| 531 | + * (we don't search for the closing shortcode bracket because they might have added |
|
| 532 | + * parameter to the shortcode |
|
| 533 | + * @return WP_Post or NULl |
|
| 534 | + */ |
|
| 535 | + public static function get_page_by_ee_shortcode($ee_shortcode) |
|
| 536 | + { |
|
| 537 | + global $wpdb; |
|
| 538 | + $shortcode_and_opening_bracket = '[' . $ee_shortcode; |
|
| 539 | + $post_id = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE post_content LIKE '%$shortcode_and_opening_bracket%' LIMIT 1"); |
|
| 540 | + if ($post_id) { |
|
| 541 | + return get_post($post_id); |
|
| 542 | + } else { |
|
| 543 | + return null; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * This function generates a post for critical espresso pages |
|
| 550 | + * |
|
| 551 | + * @access public |
|
| 552 | + * @static |
|
| 553 | + * @param array $critical_page |
|
| 554 | + * @return array |
|
| 555 | + */ |
|
| 556 | + public static function create_critical_page($critical_page) |
|
| 557 | + { |
|
| 558 | + |
|
| 559 | + $post_args = array( |
|
| 560 | + 'post_title' => $critical_page['name'], |
|
| 561 | + 'post_status' => 'publish', |
|
| 562 | + 'post_type' => 'page', |
|
| 563 | + 'comment_status' => 'closed', |
|
| 564 | + 'post_content' => '[' . $critical_page['code'] . ']', |
|
| 565 | + ); |
|
| 566 | + |
|
| 567 | + $post_id = wp_insert_post($post_args); |
|
| 568 | + if (! $post_id) { |
|
| 569 | + $msg = sprintf( |
|
| 570 | + __('The Event Espresso critical page entitled "%s" could not be created.', 'event_espresso'), |
|
| 571 | + $critical_page['name'] |
|
| 572 | + ); |
|
| 573 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 574 | + return $critical_page; |
|
| 575 | + } |
|
| 576 | + // get newly created post's details |
|
| 577 | + if (! $critical_page['post'] = get_post($post_id)) { |
|
| 578 | + $msg = sprintf( |
|
| 579 | + __('The Event Espresso critical page entitled "%s" could not be retrieved.', 'event_espresso'), |
|
| 580 | + $critical_page['name'] |
|
| 581 | + ); |
|
| 582 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + return $critical_page; |
|
| 586 | + |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Tries to find the oldest admin for this site. If there are no admins for this site then return NULL. |
|
| 594 | + * The role being used to check is filterable. |
|
| 595 | + * |
|
| 596 | + * @since 4.6.0 |
|
| 597 | + * @global WPDB $wpdb |
|
| 598 | + * @return mixed null|int WP_user ID or NULL |
|
| 599 | + */ |
|
| 600 | + public static function get_default_creator_id() |
|
| 601 | + { |
|
| 602 | + global $wpdb; |
|
| 603 | + if ( ! empty(self::$_default_creator_id)) { |
|
| 604 | + return self::$_default_creator_id; |
|
| 605 | + }/**/ |
|
| 606 | + $role_to_check = apply_filters('FHEE__EEH_Activation__get_default_creator_id__role_to_check', 'administrator'); |
|
| 607 | + //let's allow pre_filtering for early exits by alternative methods for getting id. We check for truthy result and if so then exit early. |
|
| 608 | + $pre_filtered_id = apply_filters( |
|
| 609 | + 'FHEE__EEH_Activation__get_default_creator_id__pre_filtered_id', |
|
| 610 | + false, |
|
| 611 | + $role_to_check |
|
| 612 | + ); |
|
| 613 | + if ($pre_filtered_id !== false) { |
|
| 614 | + return (int)$pre_filtered_id; |
|
| 615 | + } |
|
| 616 | + $capabilities_key = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('capabilities'); |
|
| 617 | + $query = $wpdb->prepare( |
|
| 618 | + "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$capabilities_key' AND meta_value LIKE %s ORDER BY user_id ASC LIMIT 0,1", |
|
| 619 | + '%' . $role_to_check . '%' |
|
| 620 | + ); |
|
| 621 | + $user_id = $wpdb->get_var($query); |
|
| 622 | + $user_id = apply_filters('FHEE__EEH_Activation_Helper__get_default_creator_id__user_id', $user_id); |
|
| 623 | + if ($user_id && (int)$user_id) { |
|
| 624 | + self::$_default_creator_id = (int)$user_id; |
|
| 625 | + return self::$_default_creator_id; |
|
| 626 | + } else { |
|
| 627 | + return null; |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * used by EE and EE addons during plugin activation to create tables. |
|
| 635 | + * Its a wrapper for EventEspresso\core\services\database\TableManager::createTable, |
|
| 636 | + * but includes extra logic regarding activations. |
|
| 637 | + * |
|
| 638 | + * @access public |
|
| 639 | + * @static |
|
| 640 | + * @param string $table_name without the $wpdb->prefix |
|
| 641 | + * @param string $sql SQL for creating the table (contents between brackets in an SQL create |
|
| 642 | + * table query) |
|
| 643 | + * @param string $engine like 'ENGINE=MyISAM' or 'ENGINE=InnoDB' |
|
| 644 | + * @param boolean $drop_pre_existing_table set to TRUE when you want to make SURE the table is completely empty |
|
| 645 | + * and new once this function is done (ie, you really do want to CREATE a |
|
| 646 | + * table, and expect it to be empty once you're done) leave as FALSE when |
|
| 647 | + * you just want to verify the table exists and matches this definition |
|
| 648 | + * (and if it HAS data in it you want to leave it be) |
|
| 649 | + * @return void |
|
| 650 | + * @throws EE_Error if there are database errors |
|
| 651 | + */ |
|
| 652 | + public static function create_table($table_name, $sql, $engine = 'ENGINE=MyISAM ', $drop_pre_existing_table = false) |
|
| 653 | + { |
|
| 654 | + if (apply_filters('FHEE__EEH_Activation__create_table__short_circuit', false, $table_name, $sql)) { |
|
| 655 | + return; |
|
| 656 | + } |
|
| 657 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 658 | + if ( ! function_exists('dbDelta')) { |
|
| 659 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
| 660 | + } |
|
| 661 | + $tableAnalysis = \EEH_Activation::getTableAnalysis(); |
|
| 662 | + $wp_table_name = $tableAnalysis->ensureTableNameHasPrefix($table_name); |
|
| 663 | + // do we need to first delete an existing version of this table ? |
|
| 664 | + if ($drop_pre_existing_table && $tableAnalysis->tableExists($wp_table_name)) { |
|
| 665 | + // ok, delete the table... but ONLY if it's empty |
|
| 666 | + $deleted_safely = EEH_Activation::delete_db_table_if_empty($wp_table_name); |
|
| 667 | + // table is NOT empty, are you SURE you want to delete this table ??? |
|
| 668 | + if ( ! $deleted_safely && defined('EE_DROP_BAD_TABLES') && EE_DROP_BAD_TABLES) { |
|
| 669 | + \EEH_Activation::getTableManager()->dropTable($wp_table_name); |
|
| 670 | + } else if ( ! $deleted_safely) { |
|
| 671 | + // so we should be more cautious rather than just dropping tables so easily |
|
| 672 | + error_log( |
|
| 673 | + sprintf( |
|
| 674 | + __( |
|
| 675 | + 'It appears that database table "%1$s" exists when it shouldn\'t, and therefore may contain erroneous data. If you have previously restored your database from a backup that didn\'t remove the old tables, then we recommend: %2$s 1. create a new COMPLETE backup of your database, %2$s 2. delete ALL tables from your database, %2$s 3. restore to your previous backup. %2$s If, however, you have not restored to a backup, then somehow your "%3$s" WordPress option could not be read. You can probably ignore this message, but should investigate why that option is being removed.', |
|
| 676 | + 'event_espresso' |
|
| 677 | + ), |
|
| 678 | + $wp_table_name, |
|
| 679 | + '<br/>', |
|
| 680 | + 'espresso_db_update' |
|
| 681 | + ) |
|
| 682 | + ); |
|
| 683 | + } |
|
| 684 | + } |
|
| 685 | + $engine = str_replace('ENGINE=', '', $engine); |
|
| 686 | + \EEH_Activation::getTableManager()->createTable($table_name, $sql, $engine); |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * add_column_if_it_doesn't_exist |
|
| 693 | + * Checks if this column already exists on the specified table. Handy for addons which want to add a column |
|
| 694 | + * |
|
| 695 | + * @access public |
|
| 696 | + * @static |
|
| 697 | + * @deprecated instead use TableManager::addColumn() |
|
| 698 | + * @param string $table_name (without "wp_", eg "esp_attendee" |
|
| 699 | + * @param string $column_name |
|
| 700 | + * @param string $column_info if your SQL were 'ALTER TABLE table_name ADD price VARCHAR(10)', this would be |
|
| 701 | + * 'VARCHAR(10)' |
|
| 702 | + * @return bool|int |
|
| 703 | + */ |
|
| 704 | + public static function add_column_if_it_doesnt_exist( |
|
| 705 | + $table_name, |
|
| 706 | + $column_name, |
|
| 707 | + $column_info = 'INT UNSIGNED NOT NULL' |
|
| 708 | + ) { |
|
| 709 | + return \EEH_Activation::getTableManager()->addColumn($table_name, $column_name, $column_info); |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * get_fields_on_table |
|
| 715 | + * Gets all the fields on the database table. |
|
| 716 | + * |
|
| 717 | + * @access public |
|
| 718 | + * @deprecated instead use TableManager::getTableColumns() |
|
| 719 | + * @static |
|
| 720 | + * @param string $table_name , without prefixed $wpdb->prefix |
|
| 721 | + * @return array of database column names |
|
| 722 | + */ |
|
| 723 | + public static function get_fields_on_table($table_name = null) |
|
| 724 | + { |
|
| 725 | + return \EEH_Activation::getTableManager()->getTableColumns($table_name); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * db_table_is_empty |
|
| 731 | + * |
|
| 732 | + * @access public\ |
|
| 733 | + * @deprecated instead use TableAnalysis::tableIsEmpty() |
|
| 734 | + * @static |
|
| 735 | + * @param string $table_name |
|
| 736 | + * @return bool |
|
| 737 | + */ |
|
| 738 | + public static function db_table_is_empty($table_name) |
|
| 739 | + { |
|
| 740 | + return \EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name); |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + |
|
| 744 | + /** |
|
| 745 | + * delete_db_table_if_empty |
|
| 746 | + * |
|
| 747 | + * @access public |
|
| 748 | + * @static |
|
| 749 | + * @param string $table_name |
|
| 750 | + * @return bool | int |
|
| 751 | + */ |
|
| 752 | + public static function delete_db_table_if_empty($table_name) |
|
| 753 | + { |
|
| 754 | + if (\EEH_Activation::getTableAnalysis()->tableIsEmpty($table_name)) { |
|
| 755 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 756 | + } |
|
| 757 | + return false; |
|
| 758 | + } |
|
| 759 | + |
|
| 760 | + |
|
| 761 | + /** |
|
| 762 | + * delete_unused_db_table |
|
| 763 | + * |
|
| 764 | + * @access public |
|
| 765 | + * @static |
|
| 766 | + * @deprecated instead use TableManager::dropTable() |
|
| 767 | + * @param string $table_name |
|
| 768 | + * @return bool | int |
|
| 769 | + */ |
|
| 770 | + public static function delete_unused_db_table($table_name) |
|
| 771 | + { |
|
| 772 | + return \EEH_Activation::getTableManager()->dropTable($table_name); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + |
|
| 776 | + /** |
|
| 777 | + * drop_index |
|
| 778 | + * |
|
| 779 | + * @access public |
|
| 780 | + * @static |
|
| 781 | + * @deprecated instead use TableManager::dropIndex() |
|
| 782 | + * @param string $table_name |
|
| 783 | + * @param string $index_name |
|
| 784 | + * @return bool | int |
|
| 785 | + */ |
|
| 786 | + public static function drop_index($table_name, $index_name) |
|
| 787 | + { |
|
| 788 | + return \EEH_Activation::getTableManager()->dropIndex($table_name, $index_name); |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * create_database_tables |
|
| 795 | + * |
|
| 796 | + * @access public |
|
| 797 | + * @static |
|
| 798 | + * @throws EE_Error |
|
| 799 | + * @return boolean success (whether database is setup properly or not) |
|
| 800 | + */ |
|
| 801 | + public static function create_database_tables() |
|
| 802 | + { |
|
| 803 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
| 804 | + //find the migration script that sets the database to be compatible with the code |
|
| 805 | + $dms_name = EE_Data_Migration_Manager::instance()->get_most_up_to_date_dms(); |
|
| 806 | + if ($dms_name) { |
|
| 807 | + $current_data_migration_script = EE_Registry::instance()->load_dms($dms_name); |
|
| 808 | + $current_data_migration_script->set_migrating(false); |
|
| 809 | + $current_data_migration_script->schema_changes_before_migration(); |
|
| 810 | + $current_data_migration_script->schema_changes_after_migration(); |
|
| 811 | + if ($current_data_migration_script->get_errors()) { |
|
| 812 | + if (WP_DEBUG) { |
|
| 813 | + foreach ($current_data_migration_script->get_errors() as $error) { |
|
| 814 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 815 | + } |
|
| 816 | + } else { |
|
| 817 | + EE_Error::add_error( |
|
| 818 | + __( |
|
| 819 | + 'There were errors creating the Event Espresso database tables and Event Espresso has been |
|
| 820 | 820 | deactivated. To view the errors, please enable WP_DEBUG in your wp-config.php file.', |
| 821 | - 'event_espresso' |
|
| 822 | - ) |
|
| 823 | - ); |
|
| 824 | - } |
|
| 825 | - return false; |
|
| 826 | - } |
|
| 827 | - EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 828 | - } else { |
|
| 829 | - EE_Error::add_error( |
|
| 830 | - __( |
|
| 831 | - 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 821 | + 'event_espresso' |
|
| 822 | + ) |
|
| 823 | + ); |
|
| 824 | + } |
|
| 825 | + return false; |
|
| 826 | + } |
|
| 827 | + EE_Data_Migration_Manager::instance()->update_current_database_state_to(); |
|
| 828 | + } else { |
|
| 829 | + EE_Error::add_error( |
|
| 830 | + __( |
|
| 831 | + 'Could not determine most up-to-date data migration script from which to pull database schema |
|
| 832 | 832 | structure. So database is probably not setup properly', |
| 833 | - 'event_espresso' |
|
| 834 | - ), |
|
| 835 | - __FILE__, |
|
| 836 | - __FUNCTION__, |
|
| 837 | - __LINE__ |
|
| 838 | - ); |
|
| 839 | - return false; |
|
| 840 | - } |
|
| 841 | - return true; |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - /** |
|
| 847 | - * initialize_system_questions |
|
| 848 | - * |
|
| 849 | - * @access public |
|
| 850 | - * @static |
|
| 851 | - * @return void |
|
| 852 | - */ |
|
| 853 | - public static function initialize_system_questions() |
|
| 854 | - { |
|
| 855 | - // QUESTION GROUPS |
|
| 856 | - global $wpdb; |
|
| 857 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 858 | - $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 859 | - // what we have |
|
| 860 | - $question_groups = $wpdb->get_col($SQL); |
|
| 861 | - // check the response |
|
| 862 | - $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 863 | - // what we should have |
|
| 864 | - $QSG_systems = array(1, 2); |
|
| 865 | - // loop thru what we should have and compare to what we have |
|
| 866 | - foreach ($QSG_systems as $QSG_system) { |
|
| 867 | - // reset values array |
|
| 868 | - $QSG_values = array(); |
|
| 869 | - // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 870 | - if (! in_array("$QSG_system", $question_groups)) { |
|
| 871 | - // add it |
|
| 872 | - switch ($QSG_system) { |
|
| 873 | - case 1: |
|
| 874 | - $QSG_values = array( |
|
| 875 | - 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 876 | - 'QSG_identifier' => 'personal-information-' . time(), |
|
| 877 | - 'QSG_desc' => '', |
|
| 878 | - 'QSG_order' => 1, |
|
| 879 | - 'QSG_show_group_name' => 1, |
|
| 880 | - 'QSG_show_group_desc' => 1, |
|
| 881 | - 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 882 | - 'QSG_deleted' => 0, |
|
| 883 | - ); |
|
| 884 | - break; |
|
| 885 | - case 2: |
|
| 886 | - $QSG_values = array( |
|
| 887 | - 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 888 | - 'QSG_identifier' => 'address-information-' . time(), |
|
| 889 | - 'QSG_desc' => '', |
|
| 890 | - 'QSG_order' => 2, |
|
| 891 | - 'QSG_show_group_name' => 1, |
|
| 892 | - 'QSG_show_group_desc' => 1, |
|
| 893 | - 'QSG_system' => EEM_Question_Group::system_address, |
|
| 894 | - 'QSG_deleted' => 0, |
|
| 895 | - ); |
|
| 896 | - break; |
|
| 897 | - } |
|
| 898 | - // make sure we have some values before inserting them |
|
| 899 | - if (! empty($QSG_values)) { |
|
| 900 | - // insert system question |
|
| 901 | - $wpdb->insert( |
|
| 902 | - $table_name, |
|
| 903 | - $QSG_values, |
|
| 904 | - array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 905 | - ); |
|
| 906 | - $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 907 | - } |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - // QUESTIONS |
|
| 911 | - global $wpdb; |
|
| 912 | - $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 913 | - $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 914 | - // what we have |
|
| 915 | - $questions = $wpdb->get_col($SQL); |
|
| 916 | - // what we should have |
|
| 917 | - $QST_systems = array( |
|
| 918 | - 'fname', |
|
| 919 | - 'lname', |
|
| 920 | - 'email', |
|
| 921 | - 'address', |
|
| 922 | - 'address2', |
|
| 923 | - 'city', |
|
| 924 | - 'country', |
|
| 925 | - 'state', |
|
| 926 | - 'zip', |
|
| 927 | - 'phone', |
|
| 928 | - ); |
|
| 929 | - $order_for_group_1 = 1; |
|
| 930 | - $order_for_group_2 = 1; |
|
| 931 | - // loop thru what we should have and compare to what we have |
|
| 932 | - foreach ($QST_systems as $QST_system) { |
|
| 933 | - // reset values array |
|
| 934 | - $QST_values = array(); |
|
| 935 | - // if we don't have what we should have |
|
| 936 | - if (! in_array($QST_system, $questions)) { |
|
| 937 | - // add it |
|
| 938 | - switch ($QST_system) { |
|
| 939 | - case 'fname': |
|
| 940 | - $QST_values = array( |
|
| 941 | - 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 942 | - 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 943 | - 'QST_system' => 'fname', |
|
| 944 | - 'QST_type' => 'TEXT', |
|
| 945 | - 'QST_required' => 1, |
|
| 946 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 947 | - 'QST_order' => 1, |
|
| 948 | - 'QST_admin_only' => 0, |
|
| 949 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 950 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 951 | - 'QST_deleted' => 0, |
|
| 952 | - ); |
|
| 953 | - break; |
|
| 954 | - case 'lname': |
|
| 955 | - $QST_values = array( |
|
| 956 | - 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 957 | - 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 958 | - 'QST_system' => 'lname', |
|
| 959 | - 'QST_type' => 'TEXT', |
|
| 960 | - 'QST_required' => 1, |
|
| 961 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 962 | - 'QST_order' => 2, |
|
| 963 | - 'QST_admin_only' => 0, |
|
| 964 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 965 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 966 | - 'QST_deleted' => 0, |
|
| 967 | - ); |
|
| 968 | - break; |
|
| 969 | - case 'email': |
|
| 970 | - $QST_values = array( |
|
| 971 | - 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 972 | - 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 973 | - 'QST_system' => 'email', |
|
| 974 | - 'QST_type' => 'EMAIL', |
|
| 975 | - 'QST_required' => 1, |
|
| 976 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 977 | - 'QST_order' => 3, |
|
| 978 | - 'QST_admin_only' => 0, |
|
| 979 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 980 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 981 | - 'QST_deleted' => 0, |
|
| 982 | - ); |
|
| 983 | - break; |
|
| 984 | - case 'address': |
|
| 985 | - $QST_values = array( |
|
| 986 | - 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 987 | - 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 988 | - 'QST_system' => 'address', |
|
| 989 | - 'QST_type' => 'TEXT', |
|
| 990 | - 'QST_required' => 0, |
|
| 991 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 992 | - 'QST_order' => 4, |
|
| 993 | - 'QST_admin_only' => 0, |
|
| 994 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 995 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 996 | - 'QST_deleted' => 0, |
|
| 997 | - ); |
|
| 998 | - break; |
|
| 999 | - case 'address2': |
|
| 1000 | - $QST_values = array( |
|
| 1001 | - 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 1002 | - 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 1003 | - 'QST_system' => 'address2', |
|
| 1004 | - 'QST_type' => 'TEXT', |
|
| 1005 | - 'QST_required' => 0, |
|
| 1006 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1007 | - 'QST_order' => 5, |
|
| 1008 | - 'QST_admin_only' => 0, |
|
| 1009 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1010 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1011 | - 'QST_deleted' => 0, |
|
| 1012 | - ); |
|
| 1013 | - break; |
|
| 1014 | - case 'city': |
|
| 1015 | - $QST_values = array( |
|
| 1016 | - 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1017 | - 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1018 | - 'QST_system' => 'city', |
|
| 1019 | - 'QST_type' => 'TEXT', |
|
| 1020 | - 'QST_required' => 0, |
|
| 1021 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1022 | - 'QST_order' => 6, |
|
| 1023 | - 'QST_admin_only' => 0, |
|
| 1024 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1025 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1026 | - 'QST_deleted' => 0, |
|
| 1027 | - ); |
|
| 1028 | - break; |
|
| 1029 | - case 'country': |
|
| 1030 | - $QST_values = array( |
|
| 1031 | - 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1032 | - 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1033 | - 'QST_system' => 'country', |
|
| 1034 | - 'QST_type' => 'COUNTRY', |
|
| 1035 | - 'QST_required' => 0, |
|
| 1036 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1037 | - 'QST_order' => 7, |
|
| 1038 | - 'QST_admin_only' => 0, |
|
| 1039 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1040 | - 'QST_deleted' => 0, |
|
| 1041 | - ); |
|
| 1042 | - break; |
|
| 1043 | - case 'state': |
|
| 1044 | - $QST_values = array( |
|
| 1045 | - 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1046 | - 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1047 | - 'QST_system' => 'state', |
|
| 1048 | - 'QST_type' => 'STATE', |
|
| 1049 | - 'QST_required' => 0, |
|
| 1050 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1051 | - 'QST_order' => 8, |
|
| 1052 | - 'QST_admin_only' => 0, |
|
| 1053 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1054 | - 'QST_deleted' => 0, |
|
| 1055 | - ); |
|
| 1056 | - break; |
|
| 1057 | - case 'zip': |
|
| 1058 | - $QST_values = array( |
|
| 1059 | - 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1060 | - 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1061 | - 'QST_system' => 'zip', |
|
| 1062 | - 'QST_type' => 'TEXT', |
|
| 1063 | - 'QST_required' => 0, |
|
| 1064 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1065 | - 'QST_order' => 9, |
|
| 1066 | - 'QST_admin_only' => 0, |
|
| 1067 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1068 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1069 | - 'QST_deleted' => 0, |
|
| 1070 | - ); |
|
| 1071 | - break; |
|
| 1072 | - case 'phone': |
|
| 1073 | - $QST_values = array( |
|
| 1074 | - 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1075 | - 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1076 | - 'QST_system' => 'phone', |
|
| 1077 | - 'QST_type' => 'TEXT', |
|
| 1078 | - 'QST_required' => 0, |
|
| 1079 | - 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1080 | - 'QST_order' => 10, |
|
| 1081 | - 'QST_admin_only' => 0, |
|
| 1082 | - 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1083 | - 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1084 | - 'QST_deleted' => 0, |
|
| 1085 | - ); |
|
| 1086 | - break; |
|
| 1087 | - } |
|
| 1088 | - if (! empty($QST_values)) { |
|
| 1089 | - // insert system question |
|
| 1090 | - $wpdb->insert( |
|
| 1091 | - $table_name, |
|
| 1092 | - $QST_values, |
|
| 1093 | - array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1094 | - ); |
|
| 1095 | - $QST_ID = $wpdb->insert_id; |
|
| 1096 | - // QUESTION GROUP QUESTIONS |
|
| 1097 | - if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1098 | - $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1099 | - } else { |
|
| 1100 | - $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1101 | - } |
|
| 1102 | - if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1103 | - $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1104 | - } else { |
|
| 1105 | - $id_col = EEM_Question_Group::instance() |
|
| 1106 | - ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1107 | - if (is_array($id_col)) { |
|
| 1108 | - $QSG_ID = reset($id_col); |
|
| 1109 | - } else { |
|
| 1110 | - //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1111 | - EE_Log::instance()->log( |
|
| 1112 | - __FILE__, |
|
| 1113 | - __FUNCTION__, |
|
| 1114 | - sprintf( |
|
| 1115 | - __( |
|
| 1116 | - 'Could not associate question %1$s to a question group because no system question |
|
| 833 | + 'event_espresso' |
|
| 834 | + ), |
|
| 835 | + __FILE__, |
|
| 836 | + __FUNCTION__, |
|
| 837 | + __LINE__ |
|
| 838 | + ); |
|
| 839 | + return false; |
|
| 840 | + } |
|
| 841 | + return true; |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + /** |
|
| 847 | + * initialize_system_questions |
|
| 848 | + * |
|
| 849 | + * @access public |
|
| 850 | + * @static |
|
| 851 | + * @return void |
|
| 852 | + */ |
|
| 853 | + public static function initialize_system_questions() |
|
| 854 | + { |
|
| 855 | + // QUESTION GROUPS |
|
| 856 | + global $wpdb; |
|
| 857 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group'); |
|
| 858 | + $SQL = "SELECT QSG_system FROM $table_name WHERE QSG_system != 0"; |
|
| 859 | + // what we have |
|
| 860 | + $question_groups = $wpdb->get_col($SQL); |
|
| 861 | + // check the response |
|
| 862 | + $question_groups = is_array($question_groups) ? $question_groups : array(); |
|
| 863 | + // what we should have |
|
| 864 | + $QSG_systems = array(1, 2); |
|
| 865 | + // loop thru what we should have and compare to what we have |
|
| 866 | + foreach ($QSG_systems as $QSG_system) { |
|
| 867 | + // reset values array |
|
| 868 | + $QSG_values = array(); |
|
| 869 | + // if we don't have what we should have (but use $QST_system as as string because that's what we got from the db) |
|
| 870 | + if (! in_array("$QSG_system", $question_groups)) { |
|
| 871 | + // add it |
|
| 872 | + switch ($QSG_system) { |
|
| 873 | + case 1: |
|
| 874 | + $QSG_values = array( |
|
| 875 | + 'QSG_name' => __('Personal Information', 'event_espresso'), |
|
| 876 | + 'QSG_identifier' => 'personal-information-' . time(), |
|
| 877 | + 'QSG_desc' => '', |
|
| 878 | + 'QSG_order' => 1, |
|
| 879 | + 'QSG_show_group_name' => 1, |
|
| 880 | + 'QSG_show_group_desc' => 1, |
|
| 881 | + 'QSG_system' => EEM_Question_Group::system_personal, |
|
| 882 | + 'QSG_deleted' => 0, |
|
| 883 | + ); |
|
| 884 | + break; |
|
| 885 | + case 2: |
|
| 886 | + $QSG_values = array( |
|
| 887 | + 'QSG_name' => __('Address Information', 'event_espresso'), |
|
| 888 | + 'QSG_identifier' => 'address-information-' . time(), |
|
| 889 | + 'QSG_desc' => '', |
|
| 890 | + 'QSG_order' => 2, |
|
| 891 | + 'QSG_show_group_name' => 1, |
|
| 892 | + 'QSG_show_group_desc' => 1, |
|
| 893 | + 'QSG_system' => EEM_Question_Group::system_address, |
|
| 894 | + 'QSG_deleted' => 0, |
|
| 895 | + ); |
|
| 896 | + break; |
|
| 897 | + } |
|
| 898 | + // make sure we have some values before inserting them |
|
| 899 | + if (! empty($QSG_values)) { |
|
| 900 | + // insert system question |
|
| 901 | + $wpdb->insert( |
|
| 902 | + $table_name, |
|
| 903 | + $QSG_values, |
|
| 904 | + array('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d') |
|
| 905 | + ); |
|
| 906 | + $QSG_IDs[$QSG_system] = $wpdb->insert_id; |
|
| 907 | + } |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + // QUESTIONS |
|
| 911 | + global $wpdb; |
|
| 912 | + $table_name = \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question'); |
|
| 913 | + $SQL = "SELECT QST_system FROM $table_name WHERE QST_system != ''"; |
|
| 914 | + // what we have |
|
| 915 | + $questions = $wpdb->get_col($SQL); |
|
| 916 | + // what we should have |
|
| 917 | + $QST_systems = array( |
|
| 918 | + 'fname', |
|
| 919 | + 'lname', |
|
| 920 | + 'email', |
|
| 921 | + 'address', |
|
| 922 | + 'address2', |
|
| 923 | + 'city', |
|
| 924 | + 'country', |
|
| 925 | + 'state', |
|
| 926 | + 'zip', |
|
| 927 | + 'phone', |
|
| 928 | + ); |
|
| 929 | + $order_for_group_1 = 1; |
|
| 930 | + $order_for_group_2 = 1; |
|
| 931 | + // loop thru what we should have and compare to what we have |
|
| 932 | + foreach ($QST_systems as $QST_system) { |
|
| 933 | + // reset values array |
|
| 934 | + $QST_values = array(); |
|
| 935 | + // if we don't have what we should have |
|
| 936 | + if (! in_array($QST_system, $questions)) { |
|
| 937 | + // add it |
|
| 938 | + switch ($QST_system) { |
|
| 939 | + case 'fname': |
|
| 940 | + $QST_values = array( |
|
| 941 | + 'QST_display_text' => __('First Name', 'event_espresso'), |
|
| 942 | + 'QST_admin_label' => __('First Name - System Question', 'event_espresso'), |
|
| 943 | + 'QST_system' => 'fname', |
|
| 944 | + 'QST_type' => 'TEXT', |
|
| 945 | + 'QST_required' => 1, |
|
| 946 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 947 | + 'QST_order' => 1, |
|
| 948 | + 'QST_admin_only' => 0, |
|
| 949 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 950 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 951 | + 'QST_deleted' => 0, |
|
| 952 | + ); |
|
| 953 | + break; |
|
| 954 | + case 'lname': |
|
| 955 | + $QST_values = array( |
|
| 956 | + 'QST_display_text' => __('Last Name', 'event_espresso'), |
|
| 957 | + 'QST_admin_label' => __('Last Name - System Question', 'event_espresso'), |
|
| 958 | + 'QST_system' => 'lname', |
|
| 959 | + 'QST_type' => 'TEXT', |
|
| 960 | + 'QST_required' => 1, |
|
| 961 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 962 | + 'QST_order' => 2, |
|
| 963 | + 'QST_admin_only' => 0, |
|
| 964 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 965 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 966 | + 'QST_deleted' => 0, |
|
| 967 | + ); |
|
| 968 | + break; |
|
| 969 | + case 'email': |
|
| 970 | + $QST_values = array( |
|
| 971 | + 'QST_display_text' => __('Email Address', 'event_espresso'), |
|
| 972 | + 'QST_admin_label' => __('Email Address - System Question', 'event_espresso'), |
|
| 973 | + 'QST_system' => 'email', |
|
| 974 | + 'QST_type' => 'EMAIL', |
|
| 975 | + 'QST_required' => 1, |
|
| 976 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 977 | + 'QST_order' => 3, |
|
| 978 | + 'QST_admin_only' => 0, |
|
| 979 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 980 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 981 | + 'QST_deleted' => 0, |
|
| 982 | + ); |
|
| 983 | + break; |
|
| 984 | + case 'address': |
|
| 985 | + $QST_values = array( |
|
| 986 | + 'QST_display_text' => __('Address', 'event_espresso'), |
|
| 987 | + 'QST_admin_label' => __('Address - System Question', 'event_espresso'), |
|
| 988 | + 'QST_system' => 'address', |
|
| 989 | + 'QST_type' => 'TEXT', |
|
| 990 | + 'QST_required' => 0, |
|
| 991 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 992 | + 'QST_order' => 4, |
|
| 993 | + 'QST_admin_only' => 0, |
|
| 994 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 995 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 996 | + 'QST_deleted' => 0, |
|
| 997 | + ); |
|
| 998 | + break; |
|
| 999 | + case 'address2': |
|
| 1000 | + $QST_values = array( |
|
| 1001 | + 'QST_display_text' => __('Address2', 'event_espresso'), |
|
| 1002 | + 'QST_admin_label' => __('Address2 - System Question', 'event_espresso'), |
|
| 1003 | + 'QST_system' => 'address2', |
|
| 1004 | + 'QST_type' => 'TEXT', |
|
| 1005 | + 'QST_required' => 0, |
|
| 1006 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1007 | + 'QST_order' => 5, |
|
| 1008 | + 'QST_admin_only' => 0, |
|
| 1009 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1010 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1011 | + 'QST_deleted' => 0, |
|
| 1012 | + ); |
|
| 1013 | + break; |
|
| 1014 | + case 'city': |
|
| 1015 | + $QST_values = array( |
|
| 1016 | + 'QST_display_text' => __('City', 'event_espresso'), |
|
| 1017 | + 'QST_admin_label' => __('City - System Question', 'event_espresso'), |
|
| 1018 | + 'QST_system' => 'city', |
|
| 1019 | + 'QST_type' => 'TEXT', |
|
| 1020 | + 'QST_required' => 0, |
|
| 1021 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1022 | + 'QST_order' => 6, |
|
| 1023 | + 'QST_admin_only' => 0, |
|
| 1024 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1025 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1026 | + 'QST_deleted' => 0, |
|
| 1027 | + ); |
|
| 1028 | + break; |
|
| 1029 | + case 'country': |
|
| 1030 | + $QST_values = array( |
|
| 1031 | + 'QST_display_text' => __('Country', 'event_espresso'), |
|
| 1032 | + 'QST_admin_label' => __('Country - System Question', 'event_espresso'), |
|
| 1033 | + 'QST_system' => 'country', |
|
| 1034 | + 'QST_type' => 'COUNTRY', |
|
| 1035 | + 'QST_required' => 0, |
|
| 1036 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1037 | + 'QST_order' => 7, |
|
| 1038 | + 'QST_admin_only' => 0, |
|
| 1039 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1040 | + 'QST_deleted' => 0, |
|
| 1041 | + ); |
|
| 1042 | + break; |
|
| 1043 | + case 'state': |
|
| 1044 | + $QST_values = array( |
|
| 1045 | + 'QST_display_text' => __('State/Province', 'event_espresso'), |
|
| 1046 | + 'QST_admin_label' => __('State/Province - System Question', 'event_espresso'), |
|
| 1047 | + 'QST_system' => 'state', |
|
| 1048 | + 'QST_type' => 'STATE', |
|
| 1049 | + 'QST_required' => 0, |
|
| 1050 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1051 | + 'QST_order' => 8, |
|
| 1052 | + 'QST_admin_only' => 0, |
|
| 1053 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1054 | + 'QST_deleted' => 0, |
|
| 1055 | + ); |
|
| 1056 | + break; |
|
| 1057 | + case 'zip': |
|
| 1058 | + $QST_values = array( |
|
| 1059 | + 'QST_display_text' => __('Zip/Postal Code', 'event_espresso'), |
|
| 1060 | + 'QST_admin_label' => __('Zip/Postal Code - System Question', 'event_espresso'), |
|
| 1061 | + 'QST_system' => 'zip', |
|
| 1062 | + 'QST_type' => 'TEXT', |
|
| 1063 | + 'QST_required' => 0, |
|
| 1064 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1065 | + 'QST_order' => 9, |
|
| 1066 | + 'QST_admin_only' => 0, |
|
| 1067 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1068 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1069 | + 'QST_deleted' => 0, |
|
| 1070 | + ); |
|
| 1071 | + break; |
|
| 1072 | + case 'phone': |
|
| 1073 | + $QST_values = array( |
|
| 1074 | + 'QST_display_text' => __('Phone Number', 'event_espresso'), |
|
| 1075 | + 'QST_admin_label' => __('Phone Number - System Question', 'event_espresso'), |
|
| 1076 | + 'QST_system' => 'phone', |
|
| 1077 | + 'QST_type' => 'TEXT', |
|
| 1078 | + 'QST_required' => 0, |
|
| 1079 | + 'QST_required_text' => __('This field is required', 'event_espresso'), |
|
| 1080 | + 'QST_order' => 10, |
|
| 1081 | + 'QST_admin_only' => 0, |
|
| 1082 | + 'QST_max' => EEM_Question::instance()->absolute_max_for_system_question($QST_system), |
|
| 1083 | + 'QST_wp_user' => self::get_default_creator_id(), |
|
| 1084 | + 'QST_deleted' => 0, |
|
| 1085 | + ); |
|
| 1086 | + break; |
|
| 1087 | + } |
|
| 1088 | + if (! empty($QST_values)) { |
|
| 1089 | + // insert system question |
|
| 1090 | + $wpdb->insert( |
|
| 1091 | + $table_name, |
|
| 1092 | + $QST_values, |
|
| 1093 | + array('%s', '%s', '%s', '%s', '%d', '%s', '%d', '%d', '%d', '%d') |
|
| 1094 | + ); |
|
| 1095 | + $QST_ID = $wpdb->insert_id; |
|
| 1096 | + // QUESTION GROUP QUESTIONS |
|
| 1097 | + if (in_array($QST_system, array('fname', 'lname', 'email'))) { |
|
| 1098 | + $system_question_we_want = EEM_Question_Group::system_personal; |
|
| 1099 | + } else { |
|
| 1100 | + $system_question_we_want = EEM_Question_Group::system_address; |
|
| 1101 | + } |
|
| 1102 | + if (isset($QSG_IDs[$system_question_we_want])) { |
|
| 1103 | + $QSG_ID = $QSG_IDs[$system_question_we_want]; |
|
| 1104 | + } else { |
|
| 1105 | + $id_col = EEM_Question_Group::instance() |
|
| 1106 | + ->get_col(array(array('QSG_system' => $system_question_we_want))); |
|
| 1107 | + if (is_array($id_col)) { |
|
| 1108 | + $QSG_ID = reset($id_col); |
|
| 1109 | + } else { |
|
| 1110 | + //ok so we didn't find it in the db either?? that's weird because we should have inserted it at the start of this method |
|
| 1111 | + EE_Log::instance()->log( |
|
| 1112 | + __FILE__, |
|
| 1113 | + __FUNCTION__, |
|
| 1114 | + sprintf( |
|
| 1115 | + __( |
|
| 1116 | + 'Could not associate question %1$s to a question group because no system question |
|
| 1117 | 1117 | group existed', |
| 1118 | - 'event_espresso' |
|
| 1119 | - ), |
|
| 1120 | - $QST_ID), |
|
| 1121 | - 'error'); |
|
| 1122 | - continue; |
|
| 1123 | - } |
|
| 1124 | - } |
|
| 1125 | - // add system questions to groups |
|
| 1126 | - $wpdb->insert( |
|
| 1127 | - \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1128 | - array( |
|
| 1129 | - 'QSG_ID' => $QSG_ID, |
|
| 1130 | - 'QST_ID' => $QST_ID, |
|
| 1131 | - 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1132 | - ), |
|
| 1133 | - array('%d', '%d', '%d') |
|
| 1134 | - ); |
|
| 1135 | - } |
|
| 1136 | - } |
|
| 1137 | - } |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - |
|
| 1141 | - /** |
|
| 1142 | - * Makes sure the default payment method (Invoice) is active. |
|
| 1143 | - * This used to be done automatically as part of constructing the old gateways config |
|
| 1144 | - * |
|
| 1145 | - * @throws \EE_Error |
|
| 1146 | - */ |
|
| 1147 | - public static function insert_default_payment_methods() |
|
| 1148 | - { |
|
| 1149 | - if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1150 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1151 | - EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1152 | - } else { |
|
| 1153 | - EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1154 | - } |
|
| 1155 | - } |
|
| 1156 | - |
|
| 1157 | - /** |
|
| 1158 | - * insert_default_status_codes |
|
| 1159 | - * |
|
| 1160 | - * @access public |
|
| 1161 | - * @static |
|
| 1162 | - * @return void |
|
| 1163 | - */ |
|
| 1164 | - public static function insert_default_status_codes() |
|
| 1165 | - { |
|
| 1166 | - |
|
| 1167 | - global $wpdb; |
|
| 1168 | - |
|
| 1169 | - if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1170 | - |
|
| 1171 | - $table_name = EEM_Status::instance()->table(); |
|
| 1172 | - |
|
| 1173 | - $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1174 | - $wpdb->query($SQL); |
|
| 1175 | - |
|
| 1176 | - $SQL = "INSERT INTO $table_name |
|
| 1118 | + 'event_espresso' |
|
| 1119 | + ), |
|
| 1120 | + $QST_ID), |
|
| 1121 | + 'error'); |
|
| 1122 | + continue; |
|
| 1123 | + } |
|
| 1124 | + } |
|
| 1125 | + // add system questions to groups |
|
| 1126 | + $wpdb->insert( |
|
| 1127 | + \EEH_Activation::getTableAnalysis()->ensureTableNameHasPrefix('esp_question_group_question'), |
|
| 1128 | + array( |
|
| 1129 | + 'QSG_ID' => $QSG_ID, |
|
| 1130 | + 'QST_ID' => $QST_ID, |
|
| 1131 | + 'QGQ_order' => ($QSG_ID === 1) ? $order_for_group_1++ : $order_for_group_2++, |
|
| 1132 | + ), |
|
| 1133 | + array('%d', '%d', '%d') |
|
| 1134 | + ); |
|
| 1135 | + } |
|
| 1136 | + } |
|
| 1137 | + } |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + |
|
| 1141 | + /** |
|
| 1142 | + * Makes sure the default payment method (Invoice) is active. |
|
| 1143 | + * This used to be done automatically as part of constructing the old gateways config |
|
| 1144 | + * |
|
| 1145 | + * @throws \EE_Error |
|
| 1146 | + */ |
|
| 1147 | + public static function insert_default_payment_methods() |
|
| 1148 | + { |
|
| 1149 | + if (! EEM_Payment_Method::instance()->count_active(EEM_Payment_Method::scope_cart)) { |
|
| 1150 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
| 1151 | + EE_Payment_Method_Manager::instance()->activate_a_payment_method_of_type('Invoice'); |
|
| 1152 | + } else { |
|
| 1153 | + EEM_Payment_Method::instance()->verify_button_urls(); |
|
| 1154 | + } |
|
| 1155 | + } |
|
| 1156 | + |
|
| 1157 | + /** |
|
| 1158 | + * insert_default_status_codes |
|
| 1159 | + * |
|
| 1160 | + * @access public |
|
| 1161 | + * @static |
|
| 1162 | + * @return void |
|
| 1163 | + */ |
|
| 1164 | + public static function insert_default_status_codes() |
|
| 1165 | + { |
|
| 1166 | + |
|
| 1167 | + global $wpdb; |
|
| 1168 | + |
|
| 1169 | + if (\EEH_Activation::getTableAnalysis()->tableExists(EEM_Status::instance()->table())) { |
|
| 1170 | + |
|
| 1171 | + $table_name = EEM_Status::instance()->table(); |
|
| 1172 | + |
|
| 1173 | + $SQL = "DELETE FROM $table_name WHERE STS_ID IN ( 'ACT', 'NAC', 'NOP', 'OPN', 'CLS', 'PND', 'ONG', 'SEC', 'DRF', 'DEL', 'DEN', 'EXP', 'RPP', 'RCN', 'RDC', 'RAP', 'RNA', 'RWL', 'TAB', 'TIN', 'TFL', 'TCM', 'TOP', 'PAP', 'PCN', 'PFL', 'PDC', 'EDR', 'ESN', 'PPN', 'RIC', 'MSN', 'MFL', 'MID', 'MRS', 'MIC', 'MDO', 'MEX' );"; |
|
| 1174 | + $wpdb->query($SQL); |
|
| 1175 | + |
|
| 1176 | + $SQL = "INSERT INTO $table_name |
|
| 1177 | 1177 | (STS_ID, STS_code, STS_type, STS_can_edit, STS_desc, STS_open) VALUES |
| 1178 | 1178 | ('ACT', 'ACTIVE', 'event', 0, NULL, 1), |
| 1179 | 1179 | ('NAC', 'NOT_ACTIVE', 'event', 0, NULL, 0), |
@@ -1213,521 +1213,521 @@ discard block |
||
| 1213 | 1213 | ('MID', 'IDLE', 'message', 0, NULL, 1), |
| 1214 | 1214 | ('MRS', 'RESEND', 'message', 0, NULL, 1), |
| 1215 | 1215 | ('MIC', 'INCOMPLETE', 'message', 0, NULL, 0);"; |
| 1216 | - $wpdb->query($SQL); |
|
| 1217 | - |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - } |
|
| 1221 | - |
|
| 1222 | - |
|
| 1223 | - /** |
|
| 1224 | - * create_upload_directories |
|
| 1225 | - * Creates folders in the uploads directory to facilitate addons and templates |
|
| 1226 | - * |
|
| 1227 | - * @access public |
|
| 1228 | - * @static |
|
| 1229 | - * @return boolean success of verifying upload directories exist |
|
| 1230 | - */ |
|
| 1231 | - public static function create_upload_directories() |
|
| 1232 | - { |
|
| 1233 | - // Create the required folders |
|
| 1234 | - $folders = array( |
|
| 1235 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 1236 | - EVENT_ESPRESSO_GATEWAY_DIR, |
|
| 1237 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1238 | - EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1239 | - EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1240 | - ); |
|
| 1241 | - foreach ($folders as $folder) { |
|
| 1242 | - try { |
|
| 1243 | - EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1244 | - @ chmod($folder, 0755); |
|
| 1245 | - } catch (EE_Error $e) { |
|
| 1246 | - EE_Error::add_error( |
|
| 1247 | - sprintf( |
|
| 1248 | - __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1249 | - $folder, |
|
| 1250 | - '<br />' . $e->getMessage() |
|
| 1251 | - ), |
|
| 1252 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1253 | - ); |
|
| 1254 | - //indicate we'll need to fix this later |
|
| 1255 | - update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1256 | - return false; |
|
| 1257 | - } |
|
| 1258 | - } |
|
| 1259 | - //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
| 1260 | - //is disabled, there might be activation errors recorded in there |
|
| 1261 | - EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1262 | - //remember EE's folders are all good |
|
| 1263 | - delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1264 | - return true; |
|
| 1265 | - } |
|
| 1266 | - |
|
| 1267 | - /** |
|
| 1268 | - * Whether the upload directories need to be fixed or not. |
|
| 1269 | - * If EE is installed but filesystem access isn't initially available, |
|
| 1270 | - * we need to get the user's filesystem credentials and THEN create them, |
|
| 1271 | - * so there might be period of time when EE is installed but its |
|
| 1272 | - * upload directories aren't available. This indicates such a state |
|
| 1273 | - * |
|
| 1274 | - * @return boolean |
|
| 1275 | - */ |
|
| 1276 | - public static function upload_directories_incomplete() |
|
| 1277 | - { |
|
| 1278 | - return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - |
|
| 1282 | - /** |
|
| 1283 | - * generate_default_message_templates |
|
| 1284 | - * |
|
| 1285 | - * @static |
|
| 1286 | - * @throws EE_Error |
|
| 1287 | - * @return bool true means new templates were created. |
|
| 1288 | - * false means no templates were created. |
|
| 1289 | - * This is NOT an error flag. To check for errors you will want |
|
| 1290 | - * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1291 | - */ |
|
| 1292 | - public static function generate_default_message_templates() |
|
| 1293 | - { |
|
| 1294 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1295 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1296 | - /* |
|
| 1216 | + $wpdb->query($SQL); |
|
| 1217 | + |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + } |
|
| 1221 | + |
|
| 1222 | + |
|
| 1223 | + /** |
|
| 1224 | + * create_upload_directories |
|
| 1225 | + * Creates folders in the uploads directory to facilitate addons and templates |
|
| 1226 | + * |
|
| 1227 | + * @access public |
|
| 1228 | + * @static |
|
| 1229 | + * @return boolean success of verifying upload directories exist |
|
| 1230 | + */ |
|
| 1231 | + public static function create_upload_directories() |
|
| 1232 | + { |
|
| 1233 | + // Create the required folders |
|
| 1234 | + $folders = array( |
|
| 1235 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
| 1236 | + EVENT_ESPRESSO_GATEWAY_DIR, |
|
| 1237 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs/', |
|
| 1238 | + EVENT_ESPRESSO_UPLOAD_DIR . 'css/', |
|
| 1239 | + EVENT_ESPRESSO_UPLOAD_DIR . 'tickets/', |
|
| 1240 | + ); |
|
| 1241 | + foreach ($folders as $folder) { |
|
| 1242 | + try { |
|
| 1243 | + EEH_File::ensure_folder_exists_and_is_writable($folder); |
|
| 1244 | + @ chmod($folder, 0755); |
|
| 1245 | + } catch (EE_Error $e) { |
|
| 1246 | + EE_Error::add_error( |
|
| 1247 | + sprintf( |
|
| 1248 | + __('Could not create the folder at "%1$s" because: %2$s', 'event_espresso'), |
|
| 1249 | + $folder, |
|
| 1250 | + '<br />' . $e->getMessage() |
|
| 1251 | + ), |
|
| 1252 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1253 | + ); |
|
| 1254 | + //indicate we'll need to fix this later |
|
| 1255 | + update_option(EEH_Activation::upload_directories_incomplete_option_name, true); |
|
| 1256 | + return false; |
|
| 1257 | + } |
|
| 1258 | + } |
|
| 1259 | + //just add the .htaccess file to the logs directory to begin with. Even if logging |
|
| 1260 | + //is disabled, there might be activation errors recorded in there |
|
| 1261 | + EEH_File::add_htaccess_deny_from_all(EVENT_ESPRESSO_UPLOAD_DIR . 'logs/'); |
|
| 1262 | + //remember EE's folders are all good |
|
| 1263 | + delete_option(EEH_Activation::upload_directories_incomplete_option_name); |
|
| 1264 | + return true; |
|
| 1265 | + } |
|
| 1266 | + |
|
| 1267 | + /** |
|
| 1268 | + * Whether the upload directories need to be fixed or not. |
|
| 1269 | + * If EE is installed but filesystem access isn't initially available, |
|
| 1270 | + * we need to get the user's filesystem credentials and THEN create them, |
|
| 1271 | + * so there might be period of time when EE is installed but its |
|
| 1272 | + * upload directories aren't available. This indicates such a state |
|
| 1273 | + * |
|
| 1274 | + * @return boolean |
|
| 1275 | + */ |
|
| 1276 | + public static function upload_directories_incomplete() |
|
| 1277 | + { |
|
| 1278 | + return get_option(EEH_Activation::upload_directories_incomplete_option_name, false); |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + |
|
| 1282 | + /** |
|
| 1283 | + * generate_default_message_templates |
|
| 1284 | + * |
|
| 1285 | + * @static |
|
| 1286 | + * @throws EE_Error |
|
| 1287 | + * @return bool true means new templates were created. |
|
| 1288 | + * false means no templates were created. |
|
| 1289 | + * This is NOT an error flag. To check for errors you will want |
|
| 1290 | + * to use either EE_Error or a try catch for an EE_Error exception. |
|
| 1291 | + */ |
|
| 1292 | + public static function generate_default_message_templates() |
|
| 1293 | + { |
|
| 1294 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1295 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1296 | + /* |
|
| 1297 | 1297 | * This first method is taking care of ensuring any default messengers |
| 1298 | 1298 | * that should be made active and have templates generated are done. |
| 1299 | 1299 | */ |
| 1300 | - $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1301 | - $message_resource_manager |
|
| 1302 | - ); |
|
| 1303 | - /** |
|
| 1304 | - * This method is verifying there are no NEW default message types |
|
| 1305 | - * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1306 | - */ |
|
| 1307 | - $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1308 | - $message_resource_manager |
|
| 1309 | - ); |
|
| 1310 | - //after all is done, let's persist these changes to the db. |
|
| 1311 | - $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1312 | - $message_resource_manager->update_active_messengers_option(); |
|
| 1313 | - // will return true if either of these are true. Otherwise will return false. |
|
| 1314 | - return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - |
|
| 1318 | - |
|
| 1319 | - /** |
|
| 1320 | - * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1321 | - * @return array|bool |
|
| 1322 | - * @throws \EE_Error |
|
| 1323 | - */ |
|
| 1324 | - protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1325 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1326 | - ) { |
|
| 1327 | - /** @type EE_messenger[] $active_messengers */ |
|
| 1328 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1329 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1330 | - $templates_created = false; |
|
| 1331 | - foreach ($active_messengers as $active_messenger) { |
|
| 1332 | - $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1333 | - $default_message_type_names_to_activate = array(); |
|
| 1334 | - // looping through each default message type reported by the messenger |
|
| 1335 | - // and setup the actual message types to activate. |
|
| 1336 | - foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1337 | - // if already active or has already been activated before we skip |
|
| 1338 | - // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1339 | - // we also skip if the message type is not installed. |
|
| 1340 | - if ( |
|
| 1341 | - $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1342 | - $default_message_type_name_for_messenger, |
|
| 1343 | - $active_messenger->name |
|
| 1344 | - ) |
|
| 1345 | - || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1346 | - $active_messenger->name, |
|
| 1347 | - $default_message_type_name_for_messenger |
|
| 1348 | - ) |
|
| 1349 | - || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1350 | - ) { |
|
| 1351 | - continue; |
|
| 1352 | - } |
|
| 1353 | - $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1354 | - } |
|
| 1355 | - //let's activate! |
|
| 1356 | - $message_resource_manager->ensure_message_types_are_active( |
|
| 1357 | - $default_message_type_names_to_activate, |
|
| 1358 | - $active_messenger->name, |
|
| 1359 | - false |
|
| 1360 | - ); |
|
| 1361 | - //activate the templates for these message types |
|
| 1362 | - if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1363 | - $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1364 | - $active_messenger->name, |
|
| 1365 | - $default_message_type_names_for_messenger, |
|
| 1366 | - '', |
|
| 1367 | - true |
|
| 1368 | - ); |
|
| 1369 | - } |
|
| 1370 | - } |
|
| 1371 | - return $templates_created; |
|
| 1372 | - } |
|
| 1373 | - |
|
| 1374 | - |
|
| 1375 | - |
|
| 1376 | - /** |
|
| 1377 | - * This will activate and generate default messengers and default message types for those messengers. |
|
| 1378 | - * |
|
| 1379 | - * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1380 | - * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1381 | - * False means that there were no templates generated |
|
| 1382 | - * (which could simply mean there are no default message types for a messenger). |
|
| 1383 | - * @throws EE_Error |
|
| 1384 | - */ |
|
| 1385 | - protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1386 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1387 | - ) { |
|
| 1388 | - /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1389 | - $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1390 | - $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1391 | - $templates_generated = false; |
|
| 1392 | - foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1393 | - $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1394 | - //verify the default message types match an installed message type. |
|
| 1395 | - foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1396 | - if ( |
|
| 1397 | - ! isset($installed_message_types[$name]) |
|
| 1398 | - || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1399 | - $name, |
|
| 1400 | - $messenger_to_generate->name |
|
| 1401 | - ) |
|
| 1402 | - ) { |
|
| 1403 | - unset($default_message_type_names_for_messenger[$key]); |
|
| 1404 | - } |
|
| 1405 | - } |
|
| 1406 | - // in previous iterations, the active_messengers option in the db |
|
| 1407 | - // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1408 | - // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1409 | - // passing off to create templates (after the refactor is done). |
|
| 1410 | - // @todo remove this comment when determined not necessary. |
|
| 1411 | - $message_resource_manager->activate_messenger( |
|
| 1412 | - $messenger_to_generate->name, |
|
| 1413 | - $default_message_type_names_for_messenger, |
|
| 1414 | - false |
|
| 1415 | - ); |
|
| 1416 | - //create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1417 | - if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1418 | - $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1419 | - $messenger_to_generate->name, |
|
| 1420 | - $default_message_type_names_for_messenger, |
|
| 1421 | - '', |
|
| 1422 | - true |
|
| 1423 | - ); |
|
| 1424 | - } |
|
| 1425 | - } |
|
| 1426 | - return $templates_generated; |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - |
|
| 1430 | - /** |
|
| 1431 | - * This returns the default messengers to generate templates for on activation of EE. |
|
| 1432 | - * It considers: |
|
| 1433 | - * - whether a messenger is already active in the db. |
|
| 1434 | - * - whether a messenger has been made active at any time in the past. |
|
| 1435 | - * |
|
| 1436 | - * @static |
|
| 1437 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1438 | - * @return EE_messenger[] |
|
| 1439 | - */ |
|
| 1440 | - protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1441 | - EE_Message_Resource_Manager $message_resource_manager |
|
| 1442 | - ) { |
|
| 1443 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1444 | - $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1445 | - $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1446 | - |
|
| 1447 | - $messengers_to_generate = array(); |
|
| 1448 | - foreach ($installed_messengers as $installed_messenger) { |
|
| 1449 | - //if installed messenger is a messenger that should be activated on install |
|
| 1450 | - //and is not already active |
|
| 1451 | - //and has never been activated |
|
| 1452 | - if ( |
|
| 1453 | - ! $installed_messenger->activate_on_install |
|
| 1454 | - || isset($active_messengers[$installed_messenger->name]) |
|
| 1455 | - || isset($has_activated[$installed_messenger->name]) |
|
| 1456 | - ) { |
|
| 1457 | - continue; |
|
| 1458 | - } |
|
| 1459 | - $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1460 | - } |
|
| 1461 | - return $messengers_to_generate; |
|
| 1462 | - } |
|
| 1463 | - |
|
| 1464 | - |
|
| 1465 | - /** |
|
| 1466 | - * This simply validates active message types to ensure they actually match installed |
|
| 1467 | - * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1468 | - * rows are set inactive. |
|
| 1469 | - * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1470 | - * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1471 | - * are still handled in here. |
|
| 1472 | - * |
|
| 1473 | - * @since 4.3.1 |
|
| 1474 | - * @return void |
|
| 1475 | - */ |
|
| 1476 | - public static function validate_messages_system() |
|
| 1477 | - { |
|
| 1478 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1479 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1480 | - $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1481 | - do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - |
|
| 1485 | - /** |
|
| 1486 | - * create_no_ticket_prices_array |
|
| 1487 | - * |
|
| 1488 | - * @access public |
|
| 1489 | - * @static |
|
| 1490 | - * @return void |
|
| 1491 | - */ |
|
| 1492 | - public static function create_no_ticket_prices_array() |
|
| 1493 | - { |
|
| 1494 | - // this creates an array for tracking events that have no active ticket prices created |
|
| 1495 | - // this allows us to warn admins of the situation so that it can be corrected |
|
| 1496 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1497 | - if (! $espresso_no_ticket_prices) { |
|
| 1498 | - add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1499 | - } |
|
| 1500 | - } |
|
| 1501 | - |
|
| 1502 | - |
|
| 1503 | - /** |
|
| 1504 | - * plugin_deactivation |
|
| 1505 | - * |
|
| 1506 | - * @access public |
|
| 1507 | - * @static |
|
| 1508 | - * @return void |
|
| 1509 | - */ |
|
| 1510 | - public static function plugin_deactivation() |
|
| 1511 | - { |
|
| 1512 | - } |
|
| 1513 | - |
|
| 1514 | - |
|
| 1515 | - /** |
|
| 1516 | - * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1517 | - * (like post meta or term relations) |
|
| 1518 | - * |
|
| 1519 | - * @global wpdb $wpdb |
|
| 1520 | - * @throws \EE_Error |
|
| 1521 | - */ |
|
| 1522 | - public static function delete_all_espresso_cpt_data() |
|
| 1523 | - { |
|
| 1524 | - global $wpdb; |
|
| 1525 | - //get all the CPT post_types |
|
| 1526 | - $ee_post_types = array(); |
|
| 1527 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1528 | - if (method_exists($model_name, 'instance')) { |
|
| 1529 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1530 | - if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1531 | - $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1532 | - } |
|
| 1533 | - } |
|
| 1534 | - } |
|
| 1535 | - //get all our CPTs |
|
| 1536 | - $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1537 | - $cpt_ids = $wpdb->get_col($query); |
|
| 1538 | - //delete each post meta and term relations too |
|
| 1539 | - foreach ($cpt_ids as $post_id) { |
|
| 1540 | - wp_delete_post($post_id, true); |
|
| 1541 | - } |
|
| 1542 | - } |
|
| 1543 | - |
|
| 1544 | - /** |
|
| 1545 | - * Deletes all EE custom tables |
|
| 1546 | - * |
|
| 1547 | - * @return array |
|
| 1548 | - */ |
|
| 1549 | - public static function drop_espresso_tables() |
|
| 1550 | - { |
|
| 1551 | - $tables = array(); |
|
| 1552 | - // load registry |
|
| 1553 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1554 | - if (method_exists($model_name, 'instance')) { |
|
| 1555 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1556 | - if ($model_obj instanceof EEM_Base) { |
|
| 1557 | - foreach ($model_obj->get_tables() as $table) { |
|
| 1558 | - if (strpos($table->get_table_name(), 'esp_') |
|
| 1559 | - && |
|
| 1560 | - ( |
|
| 1561 | - is_main_site()//main site? nuke them all |
|
| 1562 | - || ! $table->is_global()//not main site,but not global either. nuke it |
|
| 1563 | - ) |
|
| 1564 | - ) { |
|
| 1565 | - $tables[$table->get_table_name()] = $table->get_table_name(); |
|
| 1566 | - } |
|
| 1567 | - } |
|
| 1568 | - } |
|
| 1569 | - } |
|
| 1570 | - } |
|
| 1571 | - |
|
| 1572 | - //there are some tables whose models were removed. |
|
| 1573 | - //they should be removed when removing all EE core's data |
|
| 1574 | - $tables_without_models = array( |
|
| 1575 | - 'esp_promotion', |
|
| 1576 | - 'esp_promotion_applied', |
|
| 1577 | - 'esp_promotion_object', |
|
| 1578 | - 'esp_promotion_rule', |
|
| 1579 | - 'esp_rule', |
|
| 1580 | - ); |
|
| 1581 | - foreach ($tables_without_models as $table) { |
|
| 1582 | - $tables[$table] = $table; |
|
| 1583 | - } |
|
| 1584 | - return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - |
|
| 1588 | - |
|
| 1589 | - /** |
|
| 1590 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1591 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1592 | - * Returns the list actually deleted |
|
| 1593 | - * |
|
| 1594 | - * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1595 | - * @global WPDB $wpdb |
|
| 1596 | - * @param array $table_names |
|
| 1597 | - * @return array of table names which we deleted |
|
| 1598 | - */ |
|
| 1599 | - public static function drop_tables($table_names) |
|
| 1600 | - { |
|
| 1601 | - return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - |
|
| 1605 | - |
|
| 1606 | - /** |
|
| 1607 | - * plugin_uninstall |
|
| 1608 | - * |
|
| 1609 | - * @access public |
|
| 1610 | - * @static |
|
| 1611 | - * @param bool $remove_all |
|
| 1612 | - * @return void |
|
| 1613 | - */ |
|
| 1614 | - public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1615 | - { |
|
| 1616 | - global $wpdb; |
|
| 1617 | - self::drop_espresso_tables(); |
|
| 1618 | - $wp_options_to_delete = array( |
|
| 1619 | - 'ee_no_ticket_prices' => true, |
|
| 1620 | - 'ee_active_messengers' => true, |
|
| 1621 | - 'ee_has_activated_messenger' => true, |
|
| 1622 | - 'ee_flush_rewrite_rules' => true, |
|
| 1623 | - 'ee_config' => false, |
|
| 1624 | - 'ee_data_migration_current_db_state' => true, |
|
| 1625 | - 'ee_data_migration_mapping_' => false, |
|
| 1626 | - 'ee_data_migration_script_' => false, |
|
| 1627 | - 'ee_data_migrations' => true, |
|
| 1628 | - 'ee_dms_map' => false, |
|
| 1629 | - 'ee_notices' => true, |
|
| 1630 | - 'lang_file_check_' => false, |
|
| 1631 | - 'ee_maintenance_mode' => true, |
|
| 1632 | - 'ee_ueip_optin' => true, |
|
| 1633 | - 'ee_ueip_has_notified' => true, |
|
| 1634 | - 'ee_plugin_activation_errors' => true, |
|
| 1635 | - 'ee_id_mapping_from' => false, |
|
| 1636 | - 'espresso_persistent_admin_notices' => true, |
|
| 1637 | - 'ee_encryption_key' => true, |
|
| 1638 | - 'pue_force_upgrade_' => false, |
|
| 1639 | - 'pue_json_error_' => false, |
|
| 1640 | - 'pue_install_key_' => false, |
|
| 1641 | - 'pue_verification_error_' => false, |
|
| 1642 | - 'pu_dismissed_upgrade_' => false, |
|
| 1643 | - 'external_updates-' => false, |
|
| 1644 | - 'ee_extra_data' => true, |
|
| 1645 | - 'ee_ssn_' => false, |
|
| 1646 | - 'ee_rss_' => false, |
|
| 1647 | - 'ee_rte_n_tx_' => false, |
|
| 1648 | - 'ee_pers_admin_notices' => true, |
|
| 1649 | - 'ee_job_parameters_' => false, |
|
| 1650 | - 'ee_upload_directories_incomplete' => true, |
|
| 1651 | - 'ee_verified_db_collations' => true, |
|
| 1652 | - ); |
|
| 1653 | - if (is_main_site()) { |
|
| 1654 | - $wp_options_to_delete['ee_network_config'] = true; |
|
| 1655 | - } |
|
| 1656 | - $undeleted_options = array(); |
|
| 1657 | - foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1658 | - if ($no_wildcard) { |
|
| 1659 | - if ( ! delete_option($option_name)) { |
|
| 1660 | - $undeleted_options[] = $option_name; |
|
| 1661 | - } |
|
| 1662 | - } else { |
|
| 1663 | - $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1664 | - foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1665 | - if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1666 | - $undeleted_options[] = $option_name_from_wildcard; |
|
| 1667 | - } |
|
| 1668 | - } |
|
| 1669 | - } |
|
| 1670 | - } |
|
| 1671 | - //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1672 | - remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1673 | - if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1674 | - $db_update_sans_ee4 = array(); |
|
| 1675 | - foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1676 | - if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1677 | - $db_update_sans_ee4[$version] = $times_activated; |
|
| 1678 | - } |
|
| 1679 | - } |
|
| 1680 | - update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1681 | - } |
|
| 1682 | - $errors = ''; |
|
| 1683 | - if ( ! empty($undeleted_options)) { |
|
| 1684 | - $errors .= sprintf( |
|
| 1685 | - __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1686 | - '<br/>', |
|
| 1687 | - implode(',<br/>', $undeleted_options) |
|
| 1688 | - ); |
|
| 1689 | - } |
|
| 1690 | - if ( ! empty($errors)) { |
|
| 1691 | - EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1692 | - } |
|
| 1693 | - } |
|
| 1694 | - |
|
| 1695 | - /** |
|
| 1696 | - * Gets the mysql error code from the last used query by wpdb |
|
| 1697 | - * |
|
| 1698 | - * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1699 | - */ |
|
| 1700 | - public static function last_wpdb_error_code() |
|
| 1701 | - { |
|
| 1702 | - global $wpdb; |
|
| 1703 | - if ($wpdb->use_mysqli) { |
|
| 1704 | - return mysqli_errno($wpdb->dbh); |
|
| 1705 | - } else { |
|
| 1706 | - return mysql_errno($wpdb->dbh); |
|
| 1707 | - } |
|
| 1708 | - } |
|
| 1709 | - |
|
| 1710 | - /** |
|
| 1711 | - * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1712 | - * |
|
| 1713 | - * @global wpdb $wpdb |
|
| 1714 | - * @deprecated instead use TableAnalysis::tableExists() |
|
| 1715 | - * @param string $table_name with or without $wpdb->prefix |
|
| 1716 | - * @return boolean |
|
| 1717 | - */ |
|
| 1718 | - public static function table_exists($table_name) |
|
| 1719 | - { |
|
| 1720 | - return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1721 | - } |
|
| 1722 | - |
|
| 1723 | - /** |
|
| 1724 | - * Resets the cache on EEH_Activation |
|
| 1725 | - */ |
|
| 1726 | - public static function reset() |
|
| 1727 | - { |
|
| 1728 | - self::$_default_creator_id = null; |
|
| 1729 | - self::$_initialized_db_content_already_in_this_request = false; |
|
| 1730 | - } |
|
| 1300 | + $new_templates_created_for_messenger = self::_activate_and_generate_default_messengers_and_message_templates( |
|
| 1301 | + $message_resource_manager |
|
| 1302 | + ); |
|
| 1303 | + /** |
|
| 1304 | + * This method is verifying there are no NEW default message types |
|
| 1305 | + * for ACTIVE messengers that need activated (and corresponding templates setup). |
|
| 1306 | + */ |
|
| 1307 | + $new_templates_created_for_message_type = self::_activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1308 | + $message_resource_manager |
|
| 1309 | + ); |
|
| 1310 | + //after all is done, let's persist these changes to the db. |
|
| 1311 | + $message_resource_manager->update_has_activated_messengers_option(); |
|
| 1312 | + $message_resource_manager->update_active_messengers_option(); |
|
| 1313 | + // will return true if either of these are true. Otherwise will return false. |
|
| 1314 | + return $new_templates_created_for_message_type || $new_templates_created_for_messenger; |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + |
|
| 1318 | + |
|
| 1319 | + /** |
|
| 1320 | + * @param \EE_Message_Resource_Manager $message_resource_manager |
|
| 1321 | + * @return array|bool |
|
| 1322 | + * @throws \EE_Error |
|
| 1323 | + */ |
|
| 1324 | + protected static function _activate_new_message_types_for_active_messengers_and_generate_default_templates( |
|
| 1325 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1326 | + ) { |
|
| 1327 | + /** @type EE_messenger[] $active_messengers */ |
|
| 1328 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1329 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1330 | + $templates_created = false; |
|
| 1331 | + foreach ($active_messengers as $active_messenger) { |
|
| 1332 | + $default_message_type_names_for_messenger = $active_messenger->get_default_message_types(); |
|
| 1333 | + $default_message_type_names_to_activate = array(); |
|
| 1334 | + // looping through each default message type reported by the messenger |
|
| 1335 | + // and setup the actual message types to activate. |
|
| 1336 | + foreach ($default_message_type_names_for_messenger as $default_message_type_name_for_messenger) { |
|
| 1337 | + // if already active or has already been activated before we skip |
|
| 1338 | + // (otherwise we might reactivate something user's intentionally deactivated.) |
|
| 1339 | + // we also skip if the message type is not installed. |
|
| 1340 | + if ( |
|
| 1341 | + $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1342 | + $default_message_type_name_for_messenger, |
|
| 1343 | + $active_messenger->name |
|
| 1344 | + ) |
|
| 1345 | + || $message_resource_manager->is_message_type_active_for_messenger( |
|
| 1346 | + $active_messenger->name, |
|
| 1347 | + $default_message_type_name_for_messenger |
|
| 1348 | + ) |
|
| 1349 | + || ! isset($installed_message_types[$default_message_type_name_for_messenger]) |
|
| 1350 | + ) { |
|
| 1351 | + continue; |
|
| 1352 | + } |
|
| 1353 | + $default_message_type_names_to_activate[] = $default_message_type_name_for_messenger; |
|
| 1354 | + } |
|
| 1355 | + //let's activate! |
|
| 1356 | + $message_resource_manager->ensure_message_types_are_active( |
|
| 1357 | + $default_message_type_names_to_activate, |
|
| 1358 | + $active_messenger->name, |
|
| 1359 | + false |
|
| 1360 | + ); |
|
| 1361 | + //activate the templates for these message types |
|
| 1362 | + if ( ! empty($default_message_type_names_to_activate)) { |
|
| 1363 | + $templates_created = EEH_MSG_Template::generate_new_templates( |
|
| 1364 | + $active_messenger->name, |
|
| 1365 | + $default_message_type_names_for_messenger, |
|
| 1366 | + '', |
|
| 1367 | + true |
|
| 1368 | + ); |
|
| 1369 | + } |
|
| 1370 | + } |
|
| 1371 | + return $templates_created; |
|
| 1372 | + } |
|
| 1373 | + |
|
| 1374 | + |
|
| 1375 | + |
|
| 1376 | + /** |
|
| 1377 | + * This will activate and generate default messengers and default message types for those messengers. |
|
| 1378 | + * |
|
| 1379 | + * @param EE_message_Resource_Manager $message_resource_manager |
|
| 1380 | + * @return array|bool True means there were default messengers and message type templates generated. |
|
| 1381 | + * False means that there were no templates generated |
|
| 1382 | + * (which could simply mean there are no default message types for a messenger). |
|
| 1383 | + * @throws EE_Error |
|
| 1384 | + */ |
|
| 1385 | + protected static function _activate_and_generate_default_messengers_and_message_templates( |
|
| 1386 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1387 | + ) { |
|
| 1388 | + /** @type EE_messenger[] $messengers_to_generate */ |
|
| 1389 | + $messengers_to_generate = self::_get_default_messengers_to_generate_on_activation($message_resource_manager); |
|
| 1390 | + $installed_message_types = $message_resource_manager->installed_message_types(); |
|
| 1391 | + $templates_generated = false; |
|
| 1392 | + foreach ($messengers_to_generate as $messenger_to_generate) { |
|
| 1393 | + $default_message_type_names_for_messenger = $messenger_to_generate->get_default_message_types(); |
|
| 1394 | + //verify the default message types match an installed message type. |
|
| 1395 | + foreach ($default_message_type_names_for_messenger as $key => $name) { |
|
| 1396 | + if ( |
|
| 1397 | + ! isset($installed_message_types[$name]) |
|
| 1398 | + || $message_resource_manager->has_message_type_been_activated_for_messenger( |
|
| 1399 | + $name, |
|
| 1400 | + $messenger_to_generate->name |
|
| 1401 | + ) |
|
| 1402 | + ) { |
|
| 1403 | + unset($default_message_type_names_for_messenger[$key]); |
|
| 1404 | + } |
|
| 1405 | + } |
|
| 1406 | + // in previous iterations, the active_messengers option in the db |
|
| 1407 | + // needed updated before calling create templates. however with the changes this may not be necessary. |
|
| 1408 | + // This comment is left here just in case we discover that we _do_ need to update before |
|
| 1409 | + // passing off to create templates (after the refactor is done). |
|
| 1410 | + // @todo remove this comment when determined not necessary. |
|
| 1411 | + $message_resource_manager->activate_messenger( |
|
| 1412 | + $messenger_to_generate->name, |
|
| 1413 | + $default_message_type_names_for_messenger, |
|
| 1414 | + false |
|
| 1415 | + ); |
|
| 1416 | + //create any templates needing created (or will reactivate templates already generated as necessary). |
|
| 1417 | + if ( ! empty($default_message_type_names_for_messenger)) { |
|
| 1418 | + $templates_generated = EEH_MSG_Template::generate_new_templates( |
|
| 1419 | + $messenger_to_generate->name, |
|
| 1420 | + $default_message_type_names_for_messenger, |
|
| 1421 | + '', |
|
| 1422 | + true |
|
| 1423 | + ); |
|
| 1424 | + } |
|
| 1425 | + } |
|
| 1426 | + return $templates_generated; |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + |
|
| 1430 | + /** |
|
| 1431 | + * This returns the default messengers to generate templates for on activation of EE. |
|
| 1432 | + * It considers: |
|
| 1433 | + * - whether a messenger is already active in the db. |
|
| 1434 | + * - whether a messenger has been made active at any time in the past. |
|
| 1435 | + * |
|
| 1436 | + * @static |
|
| 1437 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
| 1438 | + * @return EE_messenger[] |
|
| 1439 | + */ |
|
| 1440 | + protected static function _get_default_messengers_to_generate_on_activation( |
|
| 1441 | + EE_Message_Resource_Manager $message_resource_manager |
|
| 1442 | + ) { |
|
| 1443 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
| 1444 | + $installed_messengers = $message_resource_manager->installed_messengers(); |
|
| 1445 | + $has_activated = $message_resource_manager->get_has_activated_messengers_option(); |
|
| 1446 | + |
|
| 1447 | + $messengers_to_generate = array(); |
|
| 1448 | + foreach ($installed_messengers as $installed_messenger) { |
|
| 1449 | + //if installed messenger is a messenger that should be activated on install |
|
| 1450 | + //and is not already active |
|
| 1451 | + //and has never been activated |
|
| 1452 | + if ( |
|
| 1453 | + ! $installed_messenger->activate_on_install |
|
| 1454 | + || isset($active_messengers[$installed_messenger->name]) |
|
| 1455 | + || isset($has_activated[$installed_messenger->name]) |
|
| 1456 | + ) { |
|
| 1457 | + continue; |
|
| 1458 | + } |
|
| 1459 | + $messengers_to_generate[$installed_messenger->name] = $installed_messenger; |
|
| 1460 | + } |
|
| 1461 | + return $messengers_to_generate; |
|
| 1462 | + } |
|
| 1463 | + |
|
| 1464 | + |
|
| 1465 | + /** |
|
| 1466 | + * This simply validates active message types to ensure they actually match installed |
|
| 1467 | + * message types. If there's a mismatch then we deactivate the message type and ensure all related db |
|
| 1468 | + * rows are set inactive. |
|
| 1469 | + * Note: Messengers are no longer validated here as of 4.9.0 because they get validated automatically whenever |
|
| 1470 | + * EE_Messenger_Resource_Manager is constructed. Message Types are a bit more resource heavy for validation so they |
|
| 1471 | + * are still handled in here. |
|
| 1472 | + * |
|
| 1473 | + * @since 4.3.1 |
|
| 1474 | + * @return void |
|
| 1475 | + */ |
|
| 1476 | + public static function validate_messages_system() |
|
| 1477 | + { |
|
| 1478 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 1479 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 1480 | + $message_resource_manager->validate_active_message_types_are_installed(); |
|
| 1481 | + do_action('AHEE__EEH_Activation__validate_messages_system'); |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + |
|
| 1485 | + /** |
|
| 1486 | + * create_no_ticket_prices_array |
|
| 1487 | + * |
|
| 1488 | + * @access public |
|
| 1489 | + * @static |
|
| 1490 | + * @return void |
|
| 1491 | + */ |
|
| 1492 | + public static function create_no_ticket_prices_array() |
|
| 1493 | + { |
|
| 1494 | + // this creates an array for tracking events that have no active ticket prices created |
|
| 1495 | + // this allows us to warn admins of the situation so that it can be corrected |
|
| 1496 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', false); |
|
| 1497 | + if (! $espresso_no_ticket_prices) { |
|
| 1498 | + add_option('ee_no_ticket_prices', array(), '', false); |
|
| 1499 | + } |
|
| 1500 | + } |
|
| 1501 | + |
|
| 1502 | + |
|
| 1503 | + /** |
|
| 1504 | + * plugin_deactivation |
|
| 1505 | + * |
|
| 1506 | + * @access public |
|
| 1507 | + * @static |
|
| 1508 | + * @return void |
|
| 1509 | + */ |
|
| 1510 | + public static function plugin_deactivation() |
|
| 1511 | + { |
|
| 1512 | + } |
|
| 1513 | + |
|
| 1514 | + |
|
| 1515 | + /** |
|
| 1516 | + * Finds all our EE4 custom post types, and deletes them and their associated data |
|
| 1517 | + * (like post meta or term relations) |
|
| 1518 | + * |
|
| 1519 | + * @global wpdb $wpdb |
|
| 1520 | + * @throws \EE_Error |
|
| 1521 | + */ |
|
| 1522 | + public static function delete_all_espresso_cpt_data() |
|
| 1523 | + { |
|
| 1524 | + global $wpdb; |
|
| 1525 | + //get all the CPT post_types |
|
| 1526 | + $ee_post_types = array(); |
|
| 1527 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1528 | + if (method_exists($model_name, 'instance')) { |
|
| 1529 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1530 | + if ($model_obj instanceof EEM_CPT_Base) { |
|
| 1531 | + $ee_post_types[] = $wpdb->prepare("%s", $model_obj->post_type()); |
|
| 1532 | + } |
|
| 1533 | + } |
|
| 1534 | + } |
|
| 1535 | + //get all our CPTs |
|
| 1536 | + $query = "SELECT ID FROM {$wpdb->posts} WHERE post_type IN (" . implode(",", $ee_post_types) . ")"; |
|
| 1537 | + $cpt_ids = $wpdb->get_col($query); |
|
| 1538 | + //delete each post meta and term relations too |
|
| 1539 | + foreach ($cpt_ids as $post_id) { |
|
| 1540 | + wp_delete_post($post_id, true); |
|
| 1541 | + } |
|
| 1542 | + } |
|
| 1543 | + |
|
| 1544 | + /** |
|
| 1545 | + * Deletes all EE custom tables |
|
| 1546 | + * |
|
| 1547 | + * @return array |
|
| 1548 | + */ |
|
| 1549 | + public static function drop_espresso_tables() |
|
| 1550 | + { |
|
| 1551 | + $tables = array(); |
|
| 1552 | + // load registry |
|
| 1553 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
| 1554 | + if (method_exists($model_name, 'instance')) { |
|
| 1555 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
| 1556 | + if ($model_obj instanceof EEM_Base) { |
|
| 1557 | + foreach ($model_obj->get_tables() as $table) { |
|
| 1558 | + if (strpos($table->get_table_name(), 'esp_') |
|
| 1559 | + && |
|
| 1560 | + ( |
|
| 1561 | + is_main_site()//main site? nuke them all |
|
| 1562 | + || ! $table->is_global()//not main site,but not global either. nuke it |
|
| 1563 | + ) |
|
| 1564 | + ) { |
|
| 1565 | + $tables[$table->get_table_name()] = $table->get_table_name(); |
|
| 1566 | + } |
|
| 1567 | + } |
|
| 1568 | + } |
|
| 1569 | + } |
|
| 1570 | + } |
|
| 1571 | + |
|
| 1572 | + //there are some tables whose models were removed. |
|
| 1573 | + //they should be removed when removing all EE core's data |
|
| 1574 | + $tables_without_models = array( |
|
| 1575 | + 'esp_promotion', |
|
| 1576 | + 'esp_promotion_applied', |
|
| 1577 | + 'esp_promotion_object', |
|
| 1578 | + 'esp_promotion_rule', |
|
| 1579 | + 'esp_rule', |
|
| 1580 | + ); |
|
| 1581 | + foreach ($tables_without_models as $table) { |
|
| 1582 | + $tables[$table] = $table; |
|
| 1583 | + } |
|
| 1584 | + return \EEH_Activation::getTableManager()->dropTables($tables); |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + |
|
| 1588 | + |
|
| 1589 | + /** |
|
| 1590 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
| 1591 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
| 1592 | + * Returns the list actually deleted |
|
| 1593 | + * |
|
| 1594 | + * @deprecated in 4.9.13. Instead use TableManager::dropTables() |
|
| 1595 | + * @global WPDB $wpdb |
|
| 1596 | + * @param array $table_names |
|
| 1597 | + * @return array of table names which we deleted |
|
| 1598 | + */ |
|
| 1599 | + public static function drop_tables($table_names) |
|
| 1600 | + { |
|
| 1601 | + return \EEH_Activation::getTableManager()->dropTables($table_names); |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + |
|
| 1605 | + |
|
| 1606 | + /** |
|
| 1607 | + * plugin_uninstall |
|
| 1608 | + * |
|
| 1609 | + * @access public |
|
| 1610 | + * @static |
|
| 1611 | + * @param bool $remove_all |
|
| 1612 | + * @return void |
|
| 1613 | + */ |
|
| 1614 | + public static function delete_all_espresso_tables_and_data($remove_all = true) |
|
| 1615 | + { |
|
| 1616 | + global $wpdb; |
|
| 1617 | + self::drop_espresso_tables(); |
|
| 1618 | + $wp_options_to_delete = array( |
|
| 1619 | + 'ee_no_ticket_prices' => true, |
|
| 1620 | + 'ee_active_messengers' => true, |
|
| 1621 | + 'ee_has_activated_messenger' => true, |
|
| 1622 | + 'ee_flush_rewrite_rules' => true, |
|
| 1623 | + 'ee_config' => false, |
|
| 1624 | + 'ee_data_migration_current_db_state' => true, |
|
| 1625 | + 'ee_data_migration_mapping_' => false, |
|
| 1626 | + 'ee_data_migration_script_' => false, |
|
| 1627 | + 'ee_data_migrations' => true, |
|
| 1628 | + 'ee_dms_map' => false, |
|
| 1629 | + 'ee_notices' => true, |
|
| 1630 | + 'lang_file_check_' => false, |
|
| 1631 | + 'ee_maintenance_mode' => true, |
|
| 1632 | + 'ee_ueip_optin' => true, |
|
| 1633 | + 'ee_ueip_has_notified' => true, |
|
| 1634 | + 'ee_plugin_activation_errors' => true, |
|
| 1635 | + 'ee_id_mapping_from' => false, |
|
| 1636 | + 'espresso_persistent_admin_notices' => true, |
|
| 1637 | + 'ee_encryption_key' => true, |
|
| 1638 | + 'pue_force_upgrade_' => false, |
|
| 1639 | + 'pue_json_error_' => false, |
|
| 1640 | + 'pue_install_key_' => false, |
|
| 1641 | + 'pue_verification_error_' => false, |
|
| 1642 | + 'pu_dismissed_upgrade_' => false, |
|
| 1643 | + 'external_updates-' => false, |
|
| 1644 | + 'ee_extra_data' => true, |
|
| 1645 | + 'ee_ssn_' => false, |
|
| 1646 | + 'ee_rss_' => false, |
|
| 1647 | + 'ee_rte_n_tx_' => false, |
|
| 1648 | + 'ee_pers_admin_notices' => true, |
|
| 1649 | + 'ee_job_parameters_' => false, |
|
| 1650 | + 'ee_upload_directories_incomplete' => true, |
|
| 1651 | + 'ee_verified_db_collations' => true, |
|
| 1652 | + ); |
|
| 1653 | + if (is_main_site()) { |
|
| 1654 | + $wp_options_to_delete['ee_network_config'] = true; |
|
| 1655 | + } |
|
| 1656 | + $undeleted_options = array(); |
|
| 1657 | + foreach ($wp_options_to_delete as $option_name => $no_wildcard) { |
|
| 1658 | + if ($no_wildcard) { |
|
| 1659 | + if ( ! delete_option($option_name)) { |
|
| 1660 | + $undeleted_options[] = $option_name; |
|
| 1661 | + } |
|
| 1662 | + } else { |
|
| 1663 | + $option_names_to_delete_from_wildcard = $wpdb->get_col("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '%$option_name%'"); |
|
| 1664 | + foreach ($option_names_to_delete_from_wildcard as $option_name_from_wildcard) { |
|
| 1665 | + if ( ! delete_option($option_name_from_wildcard)) { |
|
| 1666 | + $undeleted_options[] = $option_name_from_wildcard; |
|
| 1667 | + } |
|
| 1668 | + } |
|
| 1669 | + } |
|
| 1670 | + } |
|
| 1671 | + //also, let's make sure the "ee_config_option_names" wp option stays out by removing the action that adds it |
|
| 1672 | + remove_action('shutdown', array(EE_Config::instance(), 'shutdown'), 10); |
|
| 1673 | + if ($remove_all && $espresso_db_update = get_option('espresso_db_update')) { |
|
| 1674 | + $db_update_sans_ee4 = array(); |
|
| 1675 | + foreach ($espresso_db_update as $version => $times_activated) { |
|
| 1676 | + if ((string)$version[0] === '3') {//if its NON EE4 |
|
| 1677 | + $db_update_sans_ee4[$version] = $times_activated; |
|
| 1678 | + } |
|
| 1679 | + } |
|
| 1680 | + update_option('espresso_db_update', $db_update_sans_ee4); |
|
| 1681 | + } |
|
| 1682 | + $errors = ''; |
|
| 1683 | + if ( ! empty($undeleted_options)) { |
|
| 1684 | + $errors .= sprintf( |
|
| 1685 | + __('The following wp-options could not be deleted: %s%s', 'event_espresso'), |
|
| 1686 | + '<br/>', |
|
| 1687 | + implode(',<br/>', $undeleted_options) |
|
| 1688 | + ); |
|
| 1689 | + } |
|
| 1690 | + if ( ! empty($errors)) { |
|
| 1691 | + EE_Error::add_attention($errors, __FILE__, __FUNCTION__, __LINE__); |
|
| 1692 | + } |
|
| 1693 | + } |
|
| 1694 | + |
|
| 1695 | + /** |
|
| 1696 | + * Gets the mysql error code from the last used query by wpdb |
|
| 1697 | + * |
|
| 1698 | + * @return int mysql error code, see https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html |
|
| 1699 | + */ |
|
| 1700 | + public static function last_wpdb_error_code() |
|
| 1701 | + { |
|
| 1702 | + global $wpdb; |
|
| 1703 | + if ($wpdb->use_mysqli) { |
|
| 1704 | + return mysqli_errno($wpdb->dbh); |
|
| 1705 | + } else { |
|
| 1706 | + return mysql_errno($wpdb->dbh); |
|
| 1707 | + } |
|
| 1708 | + } |
|
| 1709 | + |
|
| 1710 | + /** |
|
| 1711 | + * Checks that the database table exists. Also works on temporary tables (for unit tests mostly). |
|
| 1712 | + * |
|
| 1713 | + * @global wpdb $wpdb |
|
| 1714 | + * @deprecated instead use TableAnalysis::tableExists() |
|
| 1715 | + * @param string $table_name with or without $wpdb->prefix |
|
| 1716 | + * @return boolean |
|
| 1717 | + */ |
|
| 1718 | + public static function table_exists($table_name) |
|
| 1719 | + { |
|
| 1720 | + return \EEH_Activation::getTableAnalysis()->tableExists($table_name); |
|
| 1721 | + } |
|
| 1722 | + |
|
| 1723 | + /** |
|
| 1724 | + * Resets the cache on EEH_Activation |
|
| 1725 | + */ |
|
| 1726 | + public static function reset() |
|
| 1727 | + { |
|
| 1728 | + self::$_default_creator_id = null; |
|
| 1729 | + self::$_initialized_db_content_already_in_this_request = false; |
|
| 1730 | + } |
|
| 1731 | 1731 | } |
| 1732 | 1732 | // End of file EEH_Activation.helper.php |
| 1733 | 1733 | // Location: /helpers/EEH_Activation.core.php |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | // when adding a new registration... |
| 70 | 70 | if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
| 71 | 71 | EE_System::do_not_cache(); |
| 72 | - if (! isset($this->_req_data['processing_registration']) |
|
| 72 | + if ( ! isset($this->_req_data['processing_registration']) |
|
| 73 | 73 | || absint($this->_req_data['processing_registration']) !== 1 |
| 74 | 74 | ) { |
| 75 | 75 | // and it's NOT the attendee information reg step |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | //style |
| 578 | 578 | wp_register_style( |
| 579 | 579 | 'espresso_reg', |
| 580 | - REG_ASSETS_URL . 'espresso_registrations_admin.css', |
|
| 580 | + REG_ASSETS_URL.'espresso_registrations_admin.css', |
|
| 581 | 581 | array('ee-admin-css'), |
| 582 | 582 | EVENT_ESPRESSO_VERSION |
| 583 | 583 | ); |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | //script |
| 586 | 586 | wp_register_script( |
| 587 | 587 | 'espresso_reg', |
| 588 | - REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 588 | + REG_ASSETS_URL.'espresso_registrations_admin.js', |
|
| 589 | 589 | array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), |
| 590 | 590 | EVENT_ESPRESSO_VERSION, |
| 591 | 591 | true |
@@ -623,7 +623,7 @@ discard block |
||
| 623 | 623 | wp_deregister_style('espresso_reg'); |
| 624 | 624 | wp_register_style( |
| 625 | 625 | 'espresso_att', |
| 626 | - REG_ASSETS_URL . 'espresso_attendees_admin.css', |
|
| 626 | + REG_ASSETS_URL.'espresso_attendees_admin.css', |
|
| 627 | 627 | array('ee-admin-css'), |
| 628 | 628 | EVENT_ESPRESSO_VERSION |
| 629 | 629 | ); |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | { |
| 636 | 636 | wp_register_script( |
| 637 | 637 | 'ee-spco-for-admin', |
| 638 | - REG_ASSETS_URL . 'spco_for_admin.js', |
|
| 638 | + REG_ASSETS_URL.'spco_for_admin.js', |
|
| 639 | 639 | array('underscore', 'jquery'), |
| 640 | 640 | EVENT_ESPRESSO_VERSION, |
| 641 | 641 | true |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
| 769 | 769 | ), |
| 770 | 770 | ); |
| 771 | - $this->_views['trash'] = array( |
|
| 771 | + $this->_views['trash'] = array( |
|
| 772 | 772 | 'slug' => 'trash', |
| 773 | 773 | 'label' => esc_html__('Trash', 'event_espresso'), |
| 774 | 774 | 'count' => 0, |
@@ -857,7 +857,7 @@ discard block |
||
| 857 | 857 | } |
| 858 | 858 | $sc_items = array( |
| 859 | 859 | 'approved_status' => array( |
| 860 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 860 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved, |
|
| 861 | 861 | 'desc' => EEH_Template::pretty_status( |
| 862 | 862 | EEM_Registration::status_id_approved, |
| 863 | 863 | false, |
@@ -865,7 +865,7 @@ discard block |
||
| 865 | 865 | ), |
| 866 | 866 | ), |
| 867 | 867 | 'pending_status' => array( |
| 868 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 868 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment, |
|
| 869 | 869 | 'desc' => EEH_Template::pretty_status( |
| 870 | 870 | EEM_Registration::status_id_pending_payment, |
| 871 | 871 | false, |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | ), |
| 874 | 874 | ), |
| 875 | 875 | 'wait_list' => array( |
| 876 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 876 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list, |
|
| 877 | 877 | 'desc' => EEH_Template::pretty_status( |
| 878 | 878 | EEM_Registration::status_id_wait_list, |
| 879 | 879 | false, |
@@ -881,7 +881,7 @@ discard block |
||
| 881 | 881 | ), |
| 882 | 882 | ), |
| 883 | 883 | 'incomplete_status' => array( |
| 884 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
| 884 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_incomplete, |
|
| 885 | 885 | 'desc' => EEH_Template::pretty_status( |
| 886 | 886 | EEM_Registration::status_id_incomplete, |
| 887 | 887 | false, |
@@ -889,7 +889,7 @@ discard block |
||
| 889 | 889 | ), |
| 890 | 890 | ), |
| 891 | 891 | 'not_approved' => array( |
| 892 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 892 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved, |
|
| 893 | 893 | 'desc' => EEH_Template::pretty_status( |
| 894 | 894 | EEM_Registration::status_id_not_approved, |
| 895 | 895 | false, |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | ), |
| 898 | 898 | ), |
| 899 | 899 | 'declined_status' => array( |
| 900 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 900 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined, |
|
| 901 | 901 | 'desc' => EEH_Template::pretty_status( |
| 902 | 902 | EEM_Registration::status_id_declined, |
| 903 | 903 | false, |
@@ -905,7 +905,7 @@ discard block |
||
| 905 | 905 | ), |
| 906 | 906 | ), |
| 907 | 907 | 'cancelled_status' => array( |
| 908 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 908 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled, |
|
| 909 | 909 | 'desc' => EEH_Template::pretty_status( |
| 910 | 910 | EEM_Registration::status_id_cancelled, |
| 911 | 911 | false, |
@@ -934,7 +934,7 @@ discard block |
||
| 934 | 934 | 'espresso_registrations_new_registration', |
| 935 | 935 | $EVT_ID |
| 936 | 936 | )) { |
| 937 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 937 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
| 938 | 938 | 'new_registration', |
| 939 | 939 | 'add-registrant', |
| 940 | 940 | array('event_id' => $EVT_ID), |
@@ -974,7 +974,7 @@ discard block |
||
| 974 | 974 | $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
| 975 | 975 | $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
| 976 | 976 | $this->_template_args['admin_page_header'] .= $datetime->name(); |
| 977 | - $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
| 977 | + $this->_template_args['admin_page_header'] .= ' ( '.$datetime->start_date().' )'; |
|
| 978 | 978 | $this->_template_args['admin_page_header'] .= '</span></h3>'; |
| 979 | 979 | } |
| 980 | 980 | } |
@@ -1074,7 +1074,7 @@ discard block |
||
| 1074 | 1074 | 'caps' => EEM_Registration::caps_read_admin, |
| 1075 | 1075 | 'default_where_conditions' => 'this_model_only', |
| 1076 | 1076 | ); |
| 1077 | - if (! $count) { |
|
| 1077 | + if ( ! $count) { |
|
| 1078 | 1078 | $query_params = array_merge( |
| 1079 | 1079 | $query_params, |
| 1080 | 1080 | $this->_get_orderby_for_registrations_query(), |
@@ -1095,7 +1095,7 @@ discard block |
||
| 1095 | 1095 | protected function _add_event_id_to_where_conditions(array $request) |
| 1096 | 1096 | { |
| 1097 | 1097 | $where = array(); |
| 1098 | - if (! empty($request['event_id'])) { |
|
| 1098 | + if ( ! empty($request['event_id'])) { |
|
| 1099 | 1099 | $where['EVT_ID'] = absint($request['event_id']); |
| 1100 | 1100 | } |
| 1101 | 1101 | return $where; |
@@ -1111,7 +1111,7 @@ discard block |
||
| 1111 | 1111 | protected function _add_category_id_to_where_conditions(array $request) |
| 1112 | 1112 | { |
| 1113 | 1113 | $where = array(); |
| 1114 | - if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) { |
|
| 1114 | + if ( ! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) { |
|
| 1115 | 1115 | $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
| 1116 | 1116 | } |
| 1117 | 1117 | return $where; |
@@ -1127,10 +1127,10 @@ discard block |
||
| 1127 | 1127 | protected function _add_datetime_id_to_where_conditions(array $request) |
| 1128 | 1128 | { |
| 1129 | 1129 | $where = array(); |
| 1130 | - if (! empty($request['datetime_id'])) { |
|
| 1130 | + if ( ! empty($request['datetime_id'])) { |
|
| 1131 | 1131 | $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
| 1132 | 1132 | } |
| 1133 | - if (! empty($request['DTT_ID'])) { |
|
| 1133 | + if ( ! empty($request['DTT_ID'])) { |
|
| 1134 | 1134 | $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
| 1135 | 1135 | } |
| 1136 | 1136 | return $where; |
@@ -1156,7 +1156,7 @@ discard block |
||
| 1156 | 1156 | * If not filtering by specified status, then we show all registrations excluding incomplete registrations |
| 1157 | 1157 | * UNLESS viewing trashed registrations. |
| 1158 | 1158 | */ |
| 1159 | - if (! empty($registration_status)) { |
|
| 1159 | + if ( ! empty($registration_status)) { |
|
| 1160 | 1160 | $where['STS_ID'] = $registration_status; |
| 1161 | 1161 | } else { |
| 1162 | 1162 | //make sure we exclude incomplete registrations, but only if not trashed. |
@@ -1196,12 +1196,12 @@ discard block |
||
| 1196 | 1196 | array( |
| 1197 | 1197 | EEM_Registration::instance()->convert_datetime_for_query( |
| 1198 | 1198 | 'REG_date', |
| 1199 | - $now . ' 00:00:00', |
|
| 1199 | + $now.' 00:00:00', |
|
| 1200 | 1200 | 'Y-m-d H:i:s' |
| 1201 | 1201 | ), |
| 1202 | 1202 | EEM_Registration::instance()->convert_datetime_for_query( |
| 1203 | 1203 | 'REG_date', |
| 1204 | - $now . ' 23:59:59', |
|
| 1204 | + $now.' 23:59:59', |
|
| 1205 | 1205 | 'Y-m-d H:i:s' |
| 1206 | 1206 | ), |
| 1207 | 1207 | ), |
@@ -1214,12 +1214,12 @@ discard block |
||
| 1214 | 1214 | array( |
| 1215 | 1215 | EEM_Registration::instance()->convert_datetime_for_query( |
| 1216 | 1216 | 'REG_date', |
| 1217 | - $current_year_and_month . '-01 00:00:00', |
|
| 1217 | + $current_year_and_month.'-01 00:00:00', |
|
| 1218 | 1218 | 'Y-m-d H:i:s' |
| 1219 | 1219 | ), |
| 1220 | 1220 | EEM_Registration::instance()->convert_datetime_for_query( |
| 1221 | 1221 | 'REG_date', |
| 1222 | - $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 1222 | + $current_year_and_month.'-'.$days_this_month.' 23:59:59', |
|
| 1223 | 1223 | 'Y-m-d H:i:s' |
| 1224 | 1224 | ), |
| 1225 | 1225 | ), |
@@ -1234,18 +1234,18 @@ discard block |
||
| 1234 | 1234 | : ''; |
| 1235 | 1235 | //if there is not a month or year then we can't go further |
| 1236 | 1236 | if ($month_requested && $year_requested) { |
| 1237 | - $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 1237 | + $days_in_month = date('t', strtotime($year_requested.'-'.$month_requested.'-'.'01')); |
|
| 1238 | 1238 | $where['REG_date'] = array( |
| 1239 | 1239 | 'BETWEEN', |
| 1240 | 1240 | array( |
| 1241 | 1241 | EEM_Registration::instance()->convert_datetime_for_query( |
| 1242 | 1242 | 'REG_date', |
| 1243 | - $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 1243 | + $year_requested.'-'.$month_requested.'-01 00:00:00', |
|
| 1244 | 1244 | 'Y-m-d H:i:s' |
| 1245 | 1245 | ), |
| 1246 | 1246 | EEM_Registration::instance()->convert_datetime_for_query( |
| 1247 | 1247 | 'REG_date', |
| 1248 | - $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 1248 | + $year_requested.'-'.$month_requested.'-'.$days_in_month.' 23:59:59', |
|
| 1249 | 1249 | 'Y-m-d H:i:s' |
| 1250 | 1250 | ), |
| 1251 | 1251 | ), |
@@ -1265,8 +1265,8 @@ discard block |
||
| 1265 | 1265 | protected function _add_search_to_where_conditions(array $request) |
| 1266 | 1266 | { |
| 1267 | 1267 | $where = array(); |
| 1268 | - if (! empty($request['s'])) { |
|
| 1269 | - $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
| 1268 | + if ( ! empty($request['s'])) { |
|
| 1269 | + $search_string = '%'.sanitize_text_field($request['s']).'%'; |
|
| 1270 | 1270 | $where['OR*search_conditions'] = array( |
| 1271 | 1271 | 'Event.EVT_name' => array('LIKE', $search_string), |
| 1272 | 1272 | 'Event.EVT_desc' => array('LIKE', $search_string), |
@@ -1379,7 +1379,7 @@ discard block |
||
| 1379 | 1379 | : $per_page; |
| 1380 | 1380 | |
| 1381 | 1381 | //-1 means return all results so get out if that's set. |
| 1382 | - if ((int)$per_page === -1) { |
|
| 1382 | + if ((int) $per_page === -1) { |
|
| 1383 | 1383 | return array(); |
| 1384 | 1384 | } |
| 1385 | 1385 | $per_page = absint($per_page); |
@@ -1432,7 +1432,7 @@ discard block |
||
| 1432 | 1432 | ), |
| 1433 | 1433 | REG_ADMIN_URL |
| 1434 | 1434 | ); |
| 1435 | - $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1435 | + $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1436 | 1436 | array( |
| 1437 | 1437 | 'action' => 'default', |
| 1438 | 1438 | 'EVT_ID' => $event_id, |
@@ -1440,7 +1440,7 @@ discard block |
||
| 1440 | 1440 | ), |
| 1441 | 1441 | admin_url('admin.php') |
| 1442 | 1442 | ); |
| 1443 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1443 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1444 | 1444 | array( |
| 1445 | 1445 | 'page' => 'espresso_events', |
| 1446 | 1446 | 'action' => 'edit', |
@@ -1449,12 +1449,12 @@ discard block |
||
| 1449 | 1449 | admin_url('admin.php') |
| 1450 | 1450 | ); |
| 1451 | 1451 | //next and previous links |
| 1452 | - $next_reg = $this->_registration->next( |
|
| 1452 | + $next_reg = $this->_registration->next( |
|
| 1453 | 1453 | null, |
| 1454 | 1454 | array(), |
| 1455 | 1455 | 'REG_ID' |
| 1456 | 1456 | ); |
| 1457 | - $this->_template_args['next_registration'] = $next_reg |
|
| 1457 | + $this->_template_args['next_registration'] = $next_reg |
|
| 1458 | 1458 | ? $this->_next_link( |
| 1459 | 1459 | EE_Admin_Page::add_query_args_and_nonce( |
| 1460 | 1460 | array( |
@@ -1466,7 +1466,7 @@ discard block |
||
| 1466 | 1466 | 'dashicons dashicons-arrow-right ee-icon-size-22' |
| 1467 | 1467 | ) |
| 1468 | 1468 | : ''; |
| 1469 | - $previous_reg = $this->_registration->previous( |
|
| 1469 | + $previous_reg = $this->_registration->previous( |
|
| 1470 | 1470 | null, |
| 1471 | 1471 | array(), |
| 1472 | 1472 | 'REG_ID' |
@@ -1484,7 +1484,7 @@ discard block |
||
| 1484 | 1484 | ) |
| 1485 | 1485 | : ''; |
| 1486 | 1486 | // grab header |
| 1487 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1487 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_header.template.php'; |
|
| 1488 | 1488 | $this->_template_args['REG_ID'] = $this->_registration->ID(); |
| 1489 | 1489 | $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
| 1490 | 1490 | $template_path, |
@@ -1599,7 +1599,7 @@ discard block |
||
| 1599 | 1599 | EEH_HTML::strong( |
| 1600 | 1600 | $this->_registration->pretty_status(), |
| 1601 | 1601 | '', |
| 1602 | - 'status-' . $this->_registration->status_ID(), |
|
| 1602 | + 'status-'.$this->_registration->status_ID(), |
|
| 1603 | 1603 | 'line-height: 1em; font-size: 1.5em; font-weight: bold;' |
| 1604 | 1604 | ) |
| 1605 | 1605 | ) |
@@ -1669,9 +1669,9 @@ discard block |
||
| 1669 | 1669 | { |
| 1670 | 1670 | if (isset($this->_req_data['reg_status_change_form'])) { |
| 1671 | 1671 | $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
| 1672 | - ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
| 1672 | + ? (array) $this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
| 1673 | 1673 | } else { |
| 1674 | - $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array(); |
|
| 1674 | + $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array) $this->_req_data['_REG_ID'] : array(); |
|
| 1675 | 1675 | } |
| 1676 | 1676 | $success = $this->_set_registration_status($REG_IDs, $status); |
| 1677 | 1677 | //notify? |
@@ -1703,7 +1703,7 @@ discard block |
||
| 1703 | 1703 | { |
| 1704 | 1704 | $success = false; |
| 1705 | 1705 | // typecast $REG_IDs |
| 1706 | - $REG_IDs = (array)$REG_IDs; |
|
| 1706 | + $REG_IDs = (array) $REG_IDs; |
|
| 1707 | 1707 | if ( ! empty($REG_IDs)) { |
| 1708 | 1708 | $success = true; |
| 1709 | 1709 | // set default status if none is passed |
@@ -1933,7 +1933,7 @@ discard block |
||
| 1933 | 1933 | $filtered_line_item_tree, |
| 1934 | 1934 | array('EE_Registration' => $this->_registration) |
| 1935 | 1935 | ); |
| 1936 | - $attendee = $this->_registration->attendee(); |
|
| 1936 | + $attendee = $this->_registration->attendee(); |
|
| 1937 | 1937 | if (EE_Registry::instance()->CAP->current_user_can( |
| 1938 | 1938 | 'ee_read_transaction', |
| 1939 | 1939 | 'espresso_transactions_view_transaction' |
@@ -2012,7 +2012,7 @@ discard block |
||
| 2012 | 2012 | 'Payment method response', |
| 2013 | 2013 | 'event_espresso' |
| 2014 | 2014 | ); |
| 2015 | - $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 2015 | + $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 2016 | 2016 | } |
| 2017 | 2017 | $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
| 2018 | 2018 | $this->_template_args['reg_details']['registration_session']['label'] = esc_html__( |
@@ -2040,7 +2040,7 @@ discard block |
||
| 2040 | 2040 | $this->_template_args['REG_ID'] = $this->_registration->ID(); |
| 2041 | 2041 | $this->_template_args['event_id'] = $this->_registration->event_ID(); |
| 2042 | 2042 | $template_path = |
| 2043 | - REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 2043 | + REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 2044 | 2044 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 2045 | 2045 | } |
| 2046 | 2046 | |
@@ -2069,7 +2069,7 @@ discard block |
||
| 2069 | 2069 | $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
| 2070 | 2070 | $this->_template_args['REG_ID'] = $this->_registration->ID(); |
| 2071 | 2071 | $template_path = |
| 2072 | - REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 2072 | + REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 2073 | 2073 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 2074 | 2074 | } |
| 2075 | 2075 | } |
@@ -2086,7 +2086,7 @@ discard block |
||
| 2086 | 2086 | public function form_before_question_group($output) |
| 2087 | 2087 | { |
| 2088 | 2088 | EE_Error::doing_it_wrong( |
| 2089 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2089 | + __CLASS__.'::'.__FUNCTION__, |
|
| 2090 | 2090 | esc_html__( |
| 2091 | 2091 | 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
| 2092 | 2092 | 'event_espresso' |
@@ -2111,7 +2111,7 @@ discard block |
||
| 2111 | 2111 | public function form_after_question_group($output) |
| 2112 | 2112 | { |
| 2113 | 2113 | EE_Error::doing_it_wrong( |
| 2114 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2114 | + __CLASS__.'::'.__FUNCTION__, |
|
| 2115 | 2115 | esc_html__( |
| 2116 | 2116 | 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
| 2117 | 2117 | 'event_espresso' |
@@ -2149,7 +2149,7 @@ discard block |
||
| 2149 | 2149 | public function form_form_field_label_wrap($label) |
| 2150 | 2150 | { |
| 2151 | 2151 | EE_Error::doing_it_wrong( |
| 2152 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2152 | + __CLASS__.'::'.__FUNCTION__, |
|
| 2153 | 2153 | esc_html__( |
| 2154 | 2154 | 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
| 2155 | 2155 | 'event_espresso' |
@@ -2159,7 +2159,7 @@ discard block |
||
| 2159 | 2159 | return ' |
| 2160 | 2160 | <tr> |
| 2161 | 2161 | <th> |
| 2162 | - ' . $label . ' |
|
| 2162 | + ' . $label.' |
|
| 2163 | 2163 | </th>'; |
| 2164 | 2164 | } |
| 2165 | 2165 | |
@@ -2175,7 +2175,7 @@ discard block |
||
| 2175 | 2175 | public function form_form_field_input__wrap($input) |
| 2176 | 2176 | { |
| 2177 | 2177 | EE_Error::doing_it_wrong( |
| 2178 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2178 | + __CLASS__.'::'.__FUNCTION__, |
|
| 2179 | 2179 | esc_html__( |
| 2180 | 2180 | 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
| 2181 | 2181 | 'event_espresso' |
@@ -2184,7 +2184,7 @@ discard block |
||
| 2184 | 2184 | ); |
| 2185 | 2185 | return ' |
| 2186 | 2186 | <td class="reg-admin-attendee-questions-input-td disabled-input"> |
| 2187 | - ' . $input . ' |
|
| 2187 | + ' . $input.' |
|
| 2188 | 2188 | </td> |
| 2189 | 2189 | </tr>'; |
| 2190 | 2190 | } |
@@ -2226,7 +2226,7 @@ discard block |
||
| 2226 | 2226 | protected function _get_reg_custom_questions_form($REG_ID) |
| 2227 | 2227 | { |
| 2228 | 2228 | if ( ! $this->_reg_custom_questions_form) { |
| 2229 | - require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 2229 | + require_once(REG_ADMIN.'form_sections'.DS.'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 2230 | 2230 | $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
| 2231 | 2231 | EEM_Registration::instance()->get_one_by_ID($REG_ID) |
| 2232 | 2232 | ); |
@@ -2259,7 +2259,7 @@ discard block |
||
| 2259 | 2259 | if ($form->is_valid()) { |
| 2260 | 2260 | foreach ($form->subforms() as $question_group_id => $question_group_form) { |
| 2261 | 2261 | foreach ($question_group_form->inputs() as $question_id => $input) { |
| 2262 | - $where_conditions = array( |
|
| 2262 | + $where_conditions = array( |
|
| 2263 | 2263 | 'QST_ID' => $question_id, |
| 2264 | 2264 | 'REG_ID' => $REG_ID, |
| 2265 | 2265 | ); |
@@ -2297,7 +2297,7 @@ discard block |
||
| 2297 | 2297 | $REG = EEM_Registration::instance(); |
| 2298 | 2298 | //get all other registrations on this transaction, and cache |
| 2299 | 2299 | //the attendees for them so we don't have to run another query using force_join |
| 2300 | - $registrations = $REG->get_all(array( |
|
| 2300 | + $registrations = $REG->get_all(array( |
|
| 2301 | 2301 | array( |
| 2302 | 2302 | 'TXN_ID' => $this->_registration->transaction_ID(), |
| 2303 | 2303 | 'REG_ID' => array('!=', $this->_registration->ID()), |
@@ -2321,7 +2321,7 @@ discard block |
||
| 2321 | 2321 | $att_nmbr = 1; |
| 2322 | 2322 | foreach ($registrations as $registration) { |
| 2323 | 2323 | /* @var $registration EE_Registration */ |
| 2324 | - $attendee = $registration->attendee() |
|
| 2324 | + $attendee = $registration->attendee() |
|
| 2325 | 2325 | ? $registration->attendee() |
| 2326 | 2326 | : EEM_Attendee::instance() |
| 2327 | 2327 | ->create_default_object(); |
@@ -2334,19 +2334,19 @@ discard block |
||
| 2334 | 2334 | ', ', |
| 2335 | 2335 | $attendee->full_address_as_array() |
| 2336 | 2336 | ); |
| 2337 | - $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce( |
|
| 2337 | + $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce( |
|
| 2338 | 2338 | array( |
| 2339 | 2339 | 'action' => 'edit_attendee', |
| 2340 | 2340 | 'post' => $attendee->ID(), |
| 2341 | 2341 | ), |
| 2342 | 2342 | REG_ADMIN_URL |
| 2343 | 2343 | ); |
| 2344 | - $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
| 2344 | + $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
| 2345 | 2345 | $att_nmbr++; |
| 2346 | 2346 | } |
| 2347 | 2347 | $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
| 2348 | 2348 | } |
| 2349 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2349 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2350 | 2350 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 2351 | 2351 | } |
| 2352 | 2352 | |
@@ -2386,20 +2386,20 @@ discard block |
||
| 2386 | 2386 | $this->_template_args['phone'] = $attendee->phone(); |
| 2387 | 2387 | $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
| 2388 | 2388 | //edit link |
| 2389 | - $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2389 | + $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2390 | 2390 | 'action' => 'edit_attendee', |
| 2391 | 2391 | 'post' => $attendee->ID(), |
| 2392 | 2392 | ), REG_ADMIN_URL); |
| 2393 | 2393 | $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso'); |
| 2394 | 2394 | //create link |
| 2395 | - $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2395 | + $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2396 | 2396 | ? EE_Admin_Page::add_query_args_and_nonce(array( |
| 2397 | 2397 | 'action' => 'duplicate_attendee', |
| 2398 | 2398 | '_REG_ID' => $this->_registration->ID(), |
| 2399 | 2399 | ), REG_ADMIN_URL) : ''; |
| 2400 | 2400 | $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso'); |
| 2401 | 2401 | $this->_template_args['att_check'] = $att_check; |
| 2402 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2402 | + $template_path = REG_TEMPLATE_PATH.'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2403 | 2403 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 2404 | 2404 | } |
| 2405 | 2405 | |
@@ -2441,7 +2441,7 @@ discard block |
||
| 2441 | 2441 | /** @var EE_Registration $REG */ |
| 2442 | 2442 | $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
| 2443 | 2443 | $payments = $REG->registration_payments(); |
| 2444 | - if (! empty($payments)) { |
|
| 2444 | + if ( ! empty($payments)) { |
|
| 2445 | 2445 | $name = $REG->attendee() instanceof EE_Attendee |
| 2446 | 2446 | ? $REG->attendee()->full_name() |
| 2447 | 2447 | : esc_html__('Unknown Attendee', 'event_espresso'); |
@@ -2634,7 +2634,7 @@ discard block |
||
| 2634 | 2634 | 'action' => 'edit', |
| 2635 | 2635 | 'post' => $this->_reg_event->ID(), |
| 2636 | 2636 | ), EVENTS_ADMIN_URL); |
| 2637 | - $edit_event_lnk = '<a href="' |
|
| 2637 | + $edit_event_lnk = '<a href="' |
|
| 2638 | 2638 | . $edit_event_url |
| 2639 | 2639 | . '" title="' |
| 2640 | 2640 | . esc_attr__('Edit ', 'event_espresso') |
@@ -2652,7 +2652,7 @@ discard block |
||
| 2652 | 2652 | } |
| 2653 | 2653 | // grab header |
| 2654 | 2654 | $template_path = |
| 2655 | - REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2655 | + REG_TEMPLATE_PATH.'reg_admin_register_new_attendee.template.php'; |
|
| 2656 | 2656 | $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
| 2657 | 2657 | $this->_template_args, true); |
| 2658 | 2658 | //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
@@ -2687,7 +2687,7 @@ discard block |
||
| 2687 | 2687 | '</b>' |
| 2688 | 2688 | ); |
| 2689 | 2689 | return ' |
| 2690 | - <div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div> |
|
| 2690 | + <div id="ee-add-reg-back-button-dv"><p>' . $warning_msg.'</p></div> |
|
| 2691 | 2691 | <script > |
| 2692 | 2692 | // WHOAH !!! it appears that someone is using the back button from the Transaction admin page |
| 2693 | 2693 | // after just adding a new registration... we gotta try to put a stop to that !!! |
@@ -2755,7 +2755,7 @@ discard block |
||
| 2755 | 2755 | //we come back to the process_registration_step route. |
| 2756 | 2756 | $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields); |
| 2757 | 2757 | return EEH_Template::display_template( |
| 2758 | - REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 2758 | + REG_TEMPLATE_PATH.'reg_admin_register_new_attendee_step_content.template.php', |
|
| 2759 | 2759 | $template_args, |
| 2760 | 2760 | true |
| 2761 | 2761 | ); |
@@ -2774,7 +2774,7 @@ discard block |
||
| 2774 | 2774 | if (is_object($this->_reg_event)) { |
| 2775 | 2775 | return true; |
| 2776 | 2776 | } |
| 2777 | - $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
| 2777 | + $EVT_ID = ( ! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
| 2778 | 2778 | if ( ! $EVT_ID) { |
| 2779 | 2779 | return false; |
| 2780 | 2780 | } |
@@ -2840,7 +2840,7 @@ discard block |
||
| 2840 | 2840 | } |
| 2841 | 2841 | break; |
| 2842 | 2842 | case 'questions' : |
| 2843 | - if (! isset( |
|
| 2843 | + if ( ! isset( |
|
| 2844 | 2844 | $this->_req_data['txn_reg_status_change'], |
| 2845 | 2845 | $this->_req_data['txn_reg_status_change']['send_notifications']) |
| 2846 | 2846 | ) { |
@@ -2954,7 +2954,7 @@ discard block |
||
| 2954 | 2954 | public function get_attendees($per_page, $count = false, $trash = false) |
| 2955 | 2955 | { |
| 2956 | 2956 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
| 2957 | - require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 2957 | + require_once(REG_ADMIN.'EE_Attendee_Contact_List_Table.class.php'); |
|
| 2958 | 2958 | $ATT_MDL = EEM_Attendee::instance(); |
| 2959 | 2959 | $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
| 2960 | 2960 | switch ($this->_req_data['orderby']) { |
@@ -2991,7 +2991,7 @@ discard block |
||
| 2991 | 2991 | : $per_page; |
| 2992 | 2992 | $_where = array(); |
| 2993 | 2993 | if ( ! empty($this->_req_data['s'])) { |
| 2994 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2994 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
| 2995 | 2995 | $_where['OR'] = array( |
| 2996 | 2996 | 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
| 2997 | 2997 | 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
@@ -3067,9 +3067,9 @@ discard block |
||
| 3067 | 3067 | * the query parameters from the request |
| 3068 | 3068 | * @return void ends the request with a redirect or download |
| 3069 | 3069 | */ |
| 3070 | - public function _registrations_report_base( $method_name_for_getting_query_params ) |
|
| 3070 | + public function _registrations_report_base($method_name_for_getting_query_params) |
|
| 3071 | 3071 | { |
| 3072 | - if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3072 | + if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3073 | 3073 | wp_redirect(EE_Admin_Page::add_query_args_and_nonce( |
| 3074 | 3074 | array( |
| 3075 | 3075 | 'page' => 'espresso_batch', |
@@ -3078,7 +3078,7 @@ discard block |
||
| 3078 | 3078 | 'filters' => urlencode( |
| 3079 | 3079 | serialize( |
| 3080 | 3080 | call_user_func( |
| 3081 | - array( $this, $method_name_for_getting_query_params ), |
|
| 3081 | + array($this, $method_name_for_getting_query_params), |
|
| 3082 | 3082 | EEH_Array::is_set( |
| 3083 | 3083 | $this->_req_data, |
| 3084 | 3084 | 'filters', |
@@ -3098,8 +3098,8 @@ discard block |
||
| 3098 | 3098 | 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
| 3099 | 3099 | ); |
| 3100 | 3100 | $this->_req_data = array_merge($this->_req_data, $new_request_args); |
| 3101 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3102 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3101 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 3102 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 3103 | 3103 | $EE_Export = EE_Export::instance($this->_req_data); |
| 3104 | 3104 | $EE_Export->export(); |
| 3105 | 3105 | } |
@@ -3120,8 +3120,8 @@ discard block |
||
| 3120 | 3120 | |
| 3121 | 3121 | public function _contact_list_export() |
| 3122 | 3122 | { |
| 3123 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3124 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3123 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 3124 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 3125 | 3125 | $EE_Export = EE_Export::instance($this->_req_data); |
| 3126 | 3126 | $EE_Export->export_attendees(); |
| 3127 | 3127 | } |
@@ -3138,8 +3138,8 @@ discard block |
||
| 3138 | 3138 | 'return_url' => urlencode($this->_req_data['return_url']), |
| 3139 | 3139 | ))); |
| 3140 | 3140 | } else { |
| 3141 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3142 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3141 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
| 3142 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
| 3143 | 3143 | $EE_Export = EE_Export::instance($this->_req_data); |
| 3144 | 3144 | $EE_Export->report_attendees(); |
| 3145 | 3145 | } |
@@ -3205,7 +3205,7 @@ discard block |
||
| 3205 | 3205 | $updated_fields = array( |
| 3206 | 3206 | 'ATT_fname' => $this->_req_data['ATT_fname'], |
| 3207 | 3207 | 'ATT_lname' => $this->_req_data['ATT_lname'], |
| 3208 | - 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
| 3208 | + 'ATT_full_name' => $this->_req_data['ATT_fname'].' '.$this->_req_data['ATT_lname'], |
|
| 3209 | 3209 | 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
| 3210 | 3210 | 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
| 3211 | 3211 | 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
@@ -3338,7 +3338,7 @@ discard block |
||
| 3338 | 3338 | { |
| 3339 | 3339 | //get attendee object ( should already have it ) |
| 3340 | 3340 | $this->_template_args['attendee'] = $this->_cpt_model_obj; |
| 3341 | - $template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php'; |
|
| 3341 | + $template = REG_TEMPLATE_PATH.'attendee_contact_info_metabox_content.template.php'; |
|
| 3342 | 3342 | EEH_Template::display_template($template, $this->_template_args); |
| 3343 | 3343 | } |
| 3344 | 3344 | |
@@ -3400,8 +3400,8 @@ discard block |
||
| 3400 | 3400 | ) |
| 3401 | 3401 | ) |
| 3402 | 3402 | ); |
| 3403 | - $template = |
|
| 3404 | - REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 3403 | + $template = |
|
| 3404 | + REG_TEMPLATE_PATH.'attendee_address_details_metabox_content.template.php'; |
|
| 3405 | 3405 | EEH_Template::display_template($template, $this->_template_args); |
| 3406 | 3406 | } |
| 3407 | 3407 | |
@@ -3420,7 +3420,7 @@ discard block |
||
| 3420 | 3420 | $this->_template_args['attendee'] = $this->_cpt_model_obj; |
| 3421 | 3421 | $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
| 3422 | 3422 | $template = |
| 3423 | - REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 3423 | + REG_TEMPLATE_PATH.'attendee_registrations_main_meta_box.template.php'; |
|
| 3424 | 3424 | EEH_Template::display_template($template, $this->_template_args); |
| 3425 | 3425 | } |
| 3426 | 3426 | |
@@ -3435,7 +3435,7 @@ discard block |
||
| 3435 | 3435 | public function after_title_form_fields($post) |
| 3436 | 3436 | { |
| 3437 | 3437 | if ($post->post_type == 'espresso_attendees') { |
| 3438 | - $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 3438 | + $template = REG_TEMPLATE_PATH.'attendee_details_after_title_form_fields.template.php'; |
|
| 3439 | 3439 | $template_args['attendee'] = $this->_cpt_model_obj; |
| 3440 | 3440 | EEH_Template::display_template($template, $template_args); |
| 3441 | 3441 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
| 2 | - exit('No direct script access allowed'); |
|
| 2 | + exit('No direct script access allowed'); |
|
| 3 | 3 | } |
| 4 | 4 | |
| 5 | 5 | |
@@ -23,2113 +23,2113 @@ discard block |
||
| 23 | 23 | class Registrations_Admin_Page extends EE_Admin_Page_CPT |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var EE_Registration |
|
| 28 | - */ |
|
| 29 | - private $_registration; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var EE_Event |
|
| 33 | - */ |
|
| 34 | - private $_reg_event; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var EE_Session |
|
| 38 | - */ |
|
| 39 | - private $_session; |
|
| 40 | - |
|
| 41 | - private static $_reg_status; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Form for displaying the custom questions for this registration. |
|
| 45 | - * This gets used a few times throughout the request so its best to cache it |
|
| 46 | - * |
|
| 47 | - * @var EE_Registration_Custom_Questions_Form |
|
| 48 | - */ |
|
| 49 | - protected $_reg_custom_questions_form = null; |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * constructor |
|
| 54 | - * |
|
| 55 | - * @Constructor |
|
| 56 | - * @access public |
|
| 57 | - * @param bool $routing |
|
| 58 | - * @return Registrations_Admin_Page |
|
| 59 | - */ |
|
| 60 | - public function __construct($routing = true) |
|
| 61 | - { |
|
| 62 | - parent::__construct($routing); |
|
| 63 | - add_action('wp_loaded', array($this, 'wp_loaded')); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - public function wp_loaded() |
|
| 68 | - { |
|
| 69 | - // when adding a new registration... |
|
| 70 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
|
| 71 | - EE_System::do_not_cache(); |
|
| 72 | - if (! isset($this->_req_data['processing_registration']) |
|
| 73 | - || absint($this->_req_data['processing_registration']) !== 1 |
|
| 74 | - ) { |
|
| 75 | - // and it's NOT the attendee information reg step |
|
| 76 | - // force cookie expiration by setting time to last week |
|
| 77 | - setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
| 78 | - // and update the global |
|
| 79 | - $_COOKIE['ee_registration_added'] = 0; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - protected function _init_page_props() |
|
| 86 | - { |
|
| 87 | - $this->page_slug = REG_PG_SLUG; |
|
| 88 | - $this->_admin_base_url = REG_ADMIN_URL; |
|
| 89 | - $this->_admin_base_path = REG_ADMIN; |
|
| 90 | - $this->page_label = esc_html__('Registrations', 'event_espresso'); |
|
| 91 | - $this->_cpt_routes = array( |
|
| 92 | - 'add_new_attendee' => 'espresso_attendees', |
|
| 93 | - 'edit_attendee' => 'espresso_attendees', |
|
| 94 | - 'insert_attendee' => 'espresso_attendees', |
|
| 95 | - 'update_attendee' => 'espresso_attendees', |
|
| 96 | - ); |
|
| 97 | - $this->_cpt_model_names = array( |
|
| 98 | - 'add_new_attendee' => 'EEM_Attendee', |
|
| 99 | - 'edit_attendee' => 'EEM_Attendee', |
|
| 100 | - ); |
|
| 101 | - $this->_cpt_edit_routes = array( |
|
| 102 | - 'espresso_attendees' => 'edit_attendee', |
|
| 103 | - ); |
|
| 104 | - $this->_pagenow_map = array( |
|
| 105 | - 'add_new_attendee' => 'post-new.php', |
|
| 106 | - 'edit_attendee' => 'post.php', |
|
| 107 | - 'trash' => 'post.php', |
|
| 108 | - ); |
|
| 109 | - add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10); |
|
| 110 | - //add filters so that the comment urls don't take users to a confusing 404 page |
|
| 111 | - add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - public function clear_comment_link($link, $comment, $args) |
|
| 116 | - { |
|
| 117 | - //gotta make sure this only happens on this route |
|
| 118 | - $post_type = get_post_type($comment->comment_post_ID); |
|
| 119 | - if ($post_type === 'espresso_attendees') { |
|
| 120 | - return '#commentsdiv'; |
|
| 121 | - } |
|
| 122 | - return $link; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - protected function _ajax_hooks() |
|
| 127 | - { |
|
| 128 | - //todo: all hooks for registrations ajax goes in here |
|
| 129 | - add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status')); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - protected function _define_page_props() |
|
| 134 | - { |
|
| 135 | - $this->_admin_page_title = $this->page_label; |
|
| 136 | - $this->_labels = array( |
|
| 137 | - 'buttons' => array( |
|
| 138 | - 'add-registrant' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 139 | - 'add-attendee' => esc_html__('Add Contact', 'event_espresso'), |
|
| 140 | - 'edit' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 141 | - 'report' => esc_html__("Event Registrations CSV Report", "event_espresso"), |
|
| 142 | - 'report_all' => esc_html__('All Registrations CSV Report', 'event_espresso'), |
|
| 143 | - 'report_filtered' => esc_html__('Filtered CSV Report', 'event_espresso'), |
|
| 144 | - 'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'), |
|
| 145 | - 'contact_list_export' => esc_html__("Export Data", "event_espresso"), |
|
| 146 | - ), |
|
| 147 | - 'publishbox' => array( |
|
| 148 | - 'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'), |
|
| 149 | - 'edit_attendee' => esc_html__("Update Contact Record", 'event_espresso'), |
|
| 150 | - ), |
|
| 151 | - 'hide_add_button_on_cpt_route' => array( |
|
| 152 | - 'edit_attendee' => true, |
|
| 153 | - ), |
|
| 154 | - ); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * grab url requests and route them |
|
| 160 | - * |
|
| 161 | - * @access private |
|
| 162 | - * @return void |
|
| 163 | - */ |
|
| 164 | - public function _set_page_routes() |
|
| 165 | - { |
|
| 166 | - $this->_get_registration_status_array(); |
|
| 167 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 168 | - ? $this->_req_data['_REG_ID'] : 0; |
|
| 169 | - $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID']) |
|
| 170 | - ? $this->_req_data['ATT_ID'] : 0; |
|
| 171 | - $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) |
|
| 172 | - ? $this->_req_data['post'] |
|
| 173 | - : $att_id; |
|
| 174 | - $this->_page_routes = array( |
|
| 175 | - 'default' => array( |
|
| 176 | - 'func' => '_registrations_overview_list_table', |
|
| 177 | - 'capability' => 'ee_read_registrations', |
|
| 178 | - ), |
|
| 179 | - 'view_registration' => array( |
|
| 180 | - 'func' => '_registration_details', |
|
| 181 | - 'capability' => 'ee_read_registration', |
|
| 182 | - 'obj_id' => $reg_id, |
|
| 183 | - ), |
|
| 184 | - 'edit_registration' => array( |
|
| 185 | - 'func' => '_update_attendee_registration_form', |
|
| 186 | - 'noheader' => true, |
|
| 187 | - 'headers_sent_route' => 'view_registration', |
|
| 188 | - 'capability' => 'ee_edit_registration', |
|
| 189 | - 'obj_id' => $reg_id, |
|
| 190 | - '_REG_ID' => $reg_id, |
|
| 191 | - ), |
|
| 192 | - 'trash_registrations' => array( |
|
| 193 | - 'func' => '_trash_or_restore_registrations', |
|
| 194 | - 'args' => array('trash' => true), |
|
| 195 | - 'noheader' => true, |
|
| 196 | - 'capability' => 'ee_delete_registrations', |
|
| 197 | - ), |
|
| 198 | - 'restore_registrations' => array( |
|
| 199 | - 'func' => '_trash_or_restore_registrations', |
|
| 200 | - 'args' => array('trash' => false), |
|
| 201 | - 'noheader' => true, |
|
| 202 | - 'capability' => 'ee_delete_registrations', |
|
| 203 | - ), |
|
| 204 | - 'delete_registrations' => array( |
|
| 205 | - 'func' => '_delete_registrations', |
|
| 206 | - 'noheader' => true, |
|
| 207 | - 'capability' => 'ee_delete_registrations', |
|
| 208 | - ), |
|
| 209 | - 'new_registration' => array( |
|
| 210 | - 'func' => 'new_registration', |
|
| 211 | - 'capability' => 'ee_edit_registrations', |
|
| 212 | - ), |
|
| 213 | - 'process_reg_step' => array( |
|
| 214 | - 'func' => 'process_reg_step', |
|
| 215 | - 'noheader' => true, |
|
| 216 | - 'capability' => 'ee_edit_registrations', |
|
| 217 | - ), |
|
| 218 | - 'redirect_to_txn' => array( |
|
| 219 | - 'func' => 'redirect_to_txn', |
|
| 220 | - 'noheader' => true, |
|
| 221 | - 'capability' => 'ee_edit_registrations', |
|
| 222 | - ), |
|
| 223 | - 'change_reg_status' => array( |
|
| 224 | - 'func' => '_change_reg_status', |
|
| 225 | - 'noheader' => true, |
|
| 226 | - 'capability' => 'ee_edit_registration', |
|
| 227 | - 'obj_id' => $reg_id, |
|
| 228 | - ), |
|
| 229 | - 'approve_registration' => array( |
|
| 230 | - 'func' => 'approve_registration', |
|
| 231 | - 'noheader' => true, |
|
| 232 | - 'capability' => 'ee_edit_registration', |
|
| 233 | - 'obj_id' => $reg_id, |
|
| 234 | - ), |
|
| 235 | - 'approve_and_notify_registration' => array( |
|
| 236 | - 'func' => 'approve_registration', |
|
| 237 | - 'noheader' => true, |
|
| 238 | - 'args' => array(true), |
|
| 239 | - 'capability' => 'ee_edit_registration', |
|
| 240 | - 'obj_id' => $reg_id, |
|
| 241 | - ), |
|
| 242 | - 'decline_registration' => array( |
|
| 243 | - 'func' => 'decline_registration', |
|
| 244 | - 'noheader' => true, |
|
| 245 | - 'capability' => 'ee_edit_registration', |
|
| 246 | - 'obj_id' => $reg_id, |
|
| 247 | - ), |
|
| 248 | - 'decline_and_notify_registration' => array( |
|
| 249 | - 'func' => 'decline_registration', |
|
| 250 | - 'noheader' => true, |
|
| 251 | - 'args' => array(true), |
|
| 252 | - 'capability' => 'ee_edit_registration', |
|
| 253 | - 'obj_id' => $reg_id, |
|
| 254 | - ), |
|
| 255 | - 'pending_registration' => array( |
|
| 256 | - 'func' => 'pending_registration', |
|
| 257 | - 'noheader' => true, |
|
| 258 | - 'capability' => 'ee_edit_registration', |
|
| 259 | - 'obj_id' => $reg_id, |
|
| 260 | - ), |
|
| 261 | - 'pending_and_notify_registration' => array( |
|
| 262 | - 'func' => 'pending_registration', |
|
| 263 | - 'noheader' => true, |
|
| 264 | - 'args' => array(true), |
|
| 265 | - 'capability' => 'ee_edit_registration', |
|
| 266 | - 'obj_id' => $reg_id, |
|
| 267 | - ), |
|
| 268 | - 'no_approve_registration' => array( |
|
| 269 | - 'func' => 'not_approve_registration', |
|
| 270 | - 'noheader' => true, |
|
| 271 | - 'capability' => 'ee_edit_registration', |
|
| 272 | - 'obj_id' => $reg_id, |
|
| 273 | - ), |
|
| 274 | - 'no_approve_and_notify_registration' => array( |
|
| 275 | - 'func' => 'not_approve_registration', |
|
| 276 | - 'noheader' => true, |
|
| 277 | - 'args' => array(true), |
|
| 278 | - 'capability' => 'ee_edit_registration', |
|
| 279 | - 'obj_id' => $reg_id, |
|
| 280 | - ), |
|
| 281 | - 'cancel_registration' => array( |
|
| 282 | - 'func' => 'cancel_registration', |
|
| 283 | - 'noheader' => true, |
|
| 284 | - 'capability' => 'ee_edit_registration', |
|
| 285 | - 'obj_id' => $reg_id, |
|
| 286 | - ), |
|
| 287 | - 'cancel_and_notify_registration' => array( |
|
| 288 | - 'func' => 'cancel_registration', |
|
| 289 | - 'noheader' => true, |
|
| 290 | - 'args' => array(true), |
|
| 291 | - 'capability' => 'ee_edit_registration', |
|
| 292 | - 'obj_id' => $reg_id, |
|
| 293 | - ), |
|
| 294 | - 'wait_list_registration' => array( |
|
| 295 | - 'func' => 'wait_list_registration', |
|
| 296 | - 'noheader' => true, |
|
| 297 | - 'capability' => 'ee_edit_registration', |
|
| 298 | - 'obj_id' => $reg_id, |
|
| 299 | - ), |
|
| 300 | - 'contact_list' => array( |
|
| 301 | - 'func' => '_attendee_contact_list_table', |
|
| 302 | - 'capability' => 'ee_read_contacts', |
|
| 303 | - ), |
|
| 304 | - 'add_new_attendee' => array( |
|
| 305 | - 'func' => '_create_new_cpt_item', |
|
| 306 | - 'args' => array( |
|
| 307 | - 'new_attendee' => true, |
|
| 308 | - 'capability' => 'ee_edit_contacts', |
|
| 309 | - ), |
|
| 310 | - ), |
|
| 311 | - 'edit_attendee' => array( |
|
| 312 | - 'func' => '_edit_cpt_item', |
|
| 313 | - 'capability' => 'ee_edit_contacts', |
|
| 314 | - 'obj_id' => $att_id, |
|
| 315 | - ), |
|
| 316 | - 'duplicate_attendee' => array( |
|
| 317 | - 'func' => '_duplicate_attendee', |
|
| 318 | - 'noheader' => true, |
|
| 319 | - 'capability' => 'ee_edit_contacts', |
|
| 320 | - 'obj_id' => $att_id, |
|
| 321 | - ), |
|
| 322 | - 'insert_attendee' => array( |
|
| 323 | - 'func' => '_insert_or_update_attendee', |
|
| 324 | - 'args' => array( |
|
| 325 | - 'new_attendee' => true, |
|
| 326 | - ), |
|
| 327 | - 'noheader' => true, |
|
| 328 | - 'capability' => 'ee_edit_contacts', |
|
| 329 | - ), |
|
| 330 | - 'update_attendee' => array( |
|
| 331 | - 'func' => '_insert_or_update_attendee', |
|
| 332 | - 'args' => array( |
|
| 333 | - 'new_attendee' => false, |
|
| 334 | - ), |
|
| 335 | - 'noheader' => true, |
|
| 336 | - 'capability' => 'ee_edit_contacts', |
|
| 337 | - 'obj_id' => $att_id, |
|
| 338 | - ), |
|
| 339 | - 'trash_attendee' => array( |
|
| 340 | - 'func' => '_trash_or_restore_attendees', |
|
| 341 | - 'args' => array( |
|
| 342 | - 'trash' => true, |
|
| 343 | - ), |
|
| 344 | - 'noheader' => true, |
|
| 345 | - 'capability' => 'ee_delete_contacts', |
|
| 346 | - 'obj_id' => $att_id, |
|
| 347 | - ), |
|
| 348 | - 'restore_attendees' => array( |
|
| 349 | - 'func' => '_trash_or_restore_attendees', |
|
| 350 | - 'args' => array( |
|
| 351 | - 'trash' => false, |
|
| 352 | - ), |
|
| 353 | - 'noheader' => true, |
|
| 354 | - 'capability' => 'ee_delete_contacts', |
|
| 355 | - 'obj_id' => $att_id, |
|
| 356 | - ), |
|
| 357 | - 'resend_registration' => array( |
|
| 358 | - 'func' => '_resend_registration', |
|
| 359 | - 'noheader' => true, |
|
| 360 | - 'capability' => 'ee_send_message', |
|
| 361 | - ), |
|
| 362 | - 'registrations_report' => array( |
|
| 363 | - 'func' => '_registrations_report', |
|
| 364 | - 'noheader' => true, |
|
| 365 | - 'capability' => 'ee_read_registrations', |
|
| 366 | - ), |
|
| 367 | - 'contact_list_export' => array( |
|
| 368 | - 'func' => '_contact_list_export', |
|
| 369 | - 'noheader' => true, |
|
| 370 | - 'capability' => 'export', |
|
| 371 | - ), |
|
| 372 | - 'contact_list_report' => array( |
|
| 373 | - 'func' => '_contact_list_report', |
|
| 374 | - 'noheader' => true, |
|
| 375 | - 'capability' => 'ee_read_contacts', |
|
| 376 | - ), |
|
| 377 | - ); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - |
|
| 381 | - protected function _set_page_config() |
|
| 382 | - { |
|
| 383 | - $this->_page_config = array( |
|
| 384 | - 'default' => array( |
|
| 385 | - 'nav' => array( |
|
| 386 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 387 | - 'order' => 5, |
|
| 388 | - ), |
|
| 389 | - 'help_tabs' => array( |
|
| 390 | - 'registrations_overview_help_tab' => array( |
|
| 391 | - 'title' => esc_html__('Registrations Overview', 'event_espresso'), |
|
| 392 | - 'filename' => 'registrations_overview', |
|
| 393 | - ), |
|
| 394 | - 'registrations_overview_table_column_headings_help_tab' => array( |
|
| 395 | - 'title' => esc_html__('Registrations Table Column Headings', 'event_espresso'), |
|
| 396 | - 'filename' => 'registrations_overview_table_column_headings', |
|
| 397 | - ), |
|
| 398 | - 'registrations_overview_filters_help_tab' => array( |
|
| 399 | - 'title' => esc_html__('Registration Filters', 'event_espresso'), |
|
| 400 | - 'filename' => 'registrations_overview_filters', |
|
| 401 | - ), |
|
| 402 | - 'registrations_overview_views_help_tab' => array( |
|
| 403 | - 'title' => esc_html__('Registration Views', 'event_espresso'), |
|
| 404 | - 'filename' => 'registrations_overview_views', |
|
| 405 | - ), |
|
| 406 | - 'registrations_regoverview_other_help_tab' => array( |
|
| 407 | - 'title' => esc_html__('Registrations Other', 'event_espresso'), |
|
| 408 | - 'filename' => 'registrations_overview_other', |
|
| 409 | - ), |
|
| 410 | - ), |
|
| 411 | - 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
| 412 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
| 413 | - 'list_table' => 'EE_Registrations_List_Table', |
|
| 414 | - 'require_nonce' => false, |
|
| 415 | - ), |
|
| 416 | - 'view_registration' => array( |
|
| 417 | - 'nav' => array( |
|
| 418 | - 'label' => esc_html__('REG Details', 'event_espresso'), |
|
| 419 | - 'order' => 15, |
|
| 420 | - 'url' => isset($this->_req_data['_REG_ID']) |
|
| 421 | - ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url) |
|
| 422 | - : $this->_admin_base_url, |
|
| 423 | - 'persistent' => false, |
|
| 424 | - ), |
|
| 425 | - 'help_tabs' => array( |
|
| 426 | - 'registrations_details_help_tab' => array( |
|
| 427 | - 'title' => esc_html__('Registration Details', 'event_espresso'), |
|
| 428 | - 'filename' => 'registrations_details', |
|
| 429 | - ), |
|
| 430 | - 'registrations_details_table_help_tab' => array( |
|
| 431 | - 'title' => esc_html__('Registration Details Table', 'event_espresso'), |
|
| 432 | - 'filename' => 'registrations_details_table', |
|
| 433 | - ), |
|
| 434 | - 'registrations_details_form_answers_help_tab' => array( |
|
| 435 | - 'title' => esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 436 | - 'filename' => 'registrations_details_form_answers', |
|
| 437 | - ), |
|
| 438 | - 'registrations_details_registrant_details_help_tab' => array( |
|
| 439 | - 'title' => esc_html__('Contact Details', 'event_espresso'), |
|
| 440 | - 'filename' => 'registrations_details_registrant_details', |
|
| 441 | - ), |
|
| 442 | - ), |
|
| 443 | - 'help_tour' => array('Registration_Details_Help_Tour'), |
|
| 444 | - 'metaboxes' => array_merge( |
|
| 445 | - $this->_default_espresso_metaboxes, |
|
| 446 | - array('_registration_details_metaboxes') |
|
| 447 | - ), |
|
| 448 | - 'require_nonce' => false, |
|
| 449 | - ), |
|
| 450 | - 'new_registration' => array( |
|
| 451 | - 'nav' => array( |
|
| 452 | - 'label' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 453 | - 'url' => '#', |
|
| 454 | - 'order' => 15, |
|
| 455 | - 'persistent' => false, |
|
| 456 | - ), |
|
| 457 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 458 | - 'labels' => array( |
|
| 459 | - 'publishbox' => esc_html__('Save Registration', 'event_espresso'), |
|
| 460 | - ), |
|
| 461 | - 'require_nonce' => false, |
|
| 462 | - ), |
|
| 463 | - 'add_new_attendee' => array( |
|
| 464 | - 'nav' => array( |
|
| 465 | - 'label' => esc_html__('Add Contact', 'event_espresso'), |
|
| 466 | - 'order' => 15, |
|
| 467 | - 'persistent' => false, |
|
| 468 | - ), |
|
| 469 | - 'metaboxes' => array_merge( |
|
| 470 | - $this->_default_espresso_metaboxes, |
|
| 471 | - array('_publish_post_box', 'attendee_editor_metaboxes') |
|
| 472 | - ), |
|
| 473 | - 'require_nonce' => false, |
|
| 474 | - ), |
|
| 475 | - 'edit_attendee' => array( |
|
| 476 | - 'nav' => array( |
|
| 477 | - 'label' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 478 | - 'order' => 15, |
|
| 479 | - 'persistent' => false, |
|
| 480 | - 'url' => isset($this->_req_data['ATT_ID']) |
|
| 481 | - ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url) |
|
| 482 | - : $this->_admin_base_url, |
|
| 483 | - ), |
|
| 484 | - 'metaboxes' => array('attendee_editor_metaboxes'), |
|
| 485 | - 'require_nonce' => false, |
|
| 486 | - ), |
|
| 487 | - 'contact_list' => array( |
|
| 488 | - 'nav' => array( |
|
| 489 | - 'label' => esc_html__('Contact List', 'event_espresso'), |
|
| 490 | - 'order' => 20, |
|
| 491 | - ), |
|
| 492 | - 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
| 493 | - 'help_tabs' => array( |
|
| 494 | - 'registrations_contact_list_help_tab' => array( |
|
| 495 | - 'title' => esc_html__('Registrations Contact List', 'event_espresso'), |
|
| 496 | - 'filename' => 'registrations_contact_list', |
|
| 497 | - ), |
|
| 498 | - 'registrations_contact-list_table_column_headings_help_tab' => array( |
|
| 499 | - 'title' => esc_html__('Contact List Table Column Headings', 'event_espresso'), |
|
| 500 | - 'filename' => 'registrations_contact_list_table_column_headings', |
|
| 501 | - ), |
|
| 502 | - 'registrations_contact_list_views_help_tab' => array( |
|
| 503 | - 'title' => esc_html__('Contact List Views', 'event_espresso'), |
|
| 504 | - 'filename' => 'registrations_contact_list_views', |
|
| 505 | - ), |
|
| 506 | - 'registrations_contact_list_other_help_tab' => array( |
|
| 507 | - 'title' => esc_html__('Contact List Other', 'event_espresso'), |
|
| 508 | - 'filename' => 'registrations_contact_list_other', |
|
| 509 | - ), |
|
| 510 | - ), |
|
| 511 | - 'help_tour' => array('Contact_List_Help_Tour'), |
|
| 512 | - 'metaboxes' => array(), |
|
| 513 | - 'require_nonce' => false, |
|
| 514 | - ), |
|
| 515 | - //override default cpt routes |
|
| 516 | - 'create_new' => '', |
|
| 517 | - 'edit' => '', |
|
| 518 | - ); |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * The below methods aren't used by this class currently |
|
| 524 | - */ |
|
| 525 | - protected function _add_screen_options() |
|
| 526 | - { |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - protected function _add_feature_pointers() |
|
| 531 | - { |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - public function admin_init() |
|
| 536 | - { |
|
| 537 | - EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__( |
|
| 538 | - 'click "Update Registration Questions" to save your changes', |
|
| 539 | - 'event_espresso' |
|
| 540 | - ); |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - |
|
| 544 | - public function admin_notices() |
|
| 545 | - { |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - |
|
| 549 | - public function admin_footer_scripts() |
|
| 550 | - { |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * get list of registration statuses |
|
| 556 | - * |
|
| 557 | - * @access private |
|
| 558 | - * @return void |
|
| 559 | - */ |
|
| 560 | - private function _get_registration_status_array() |
|
| 561 | - { |
|
| 562 | - self::$_reg_status = EEM_Registration::reg_status_array(array(), true); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - protected function _add_screen_options_default() |
|
| 567 | - { |
|
| 568 | - $this->_per_page_screen_option(); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - protected function _add_screen_options_contact_list() |
|
| 573 | - { |
|
| 574 | - $page_title = $this->_admin_page_title; |
|
| 575 | - $this->_admin_page_title = esc_html__("Contacts", 'event_espresso'); |
|
| 576 | - $this->_per_page_screen_option(); |
|
| 577 | - $this->_admin_page_title = $page_title; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - public function load_scripts_styles() |
|
| 582 | - { |
|
| 583 | - //style |
|
| 584 | - wp_register_style( |
|
| 585 | - 'espresso_reg', |
|
| 586 | - REG_ASSETS_URL . 'espresso_registrations_admin.css', |
|
| 587 | - array('ee-admin-css'), |
|
| 588 | - EVENT_ESPRESSO_VERSION |
|
| 589 | - ); |
|
| 590 | - wp_enqueue_style('espresso_reg'); |
|
| 591 | - //script |
|
| 592 | - wp_register_script( |
|
| 593 | - 'espresso_reg', |
|
| 594 | - REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 595 | - array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), |
|
| 596 | - EVENT_ESPRESSO_VERSION, |
|
| 597 | - true |
|
| 598 | - ); |
|
| 599 | - wp_enqueue_script('espresso_reg'); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - public function load_scripts_styles_edit_attendee() |
|
| 604 | - { |
|
| 605 | - //stuff to only show up on our attendee edit details page. |
|
| 606 | - $attendee_details_translations = array( |
|
| 607 | - 'att_publish_text' => sprintf( |
|
| 608 | - esc_html__('Created on: <b>%1$s</b>', 'event_espresso'), |
|
| 609 | - $this->_cpt_model_obj->get_datetime('ATT_created') |
|
| 610 | - ), |
|
| 611 | - ); |
|
| 612 | - wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
| 613 | - wp_enqueue_script('jquery-validate'); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - public function load_scripts_styles_view_registration() |
|
| 618 | - { |
|
| 619 | - //styles |
|
| 620 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 621 | - //scripts |
|
| 622 | - $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 623 | - $this->_reg_custom_questions_form->wp_enqueue_scripts(true); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - public function load_scripts_styles_contact_list() |
|
| 628 | - { |
|
| 629 | - wp_deregister_style('espresso_reg'); |
|
| 630 | - wp_register_style( |
|
| 631 | - 'espresso_att', |
|
| 632 | - REG_ASSETS_URL . 'espresso_attendees_admin.css', |
|
| 633 | - array('ee-admin-css'), |
|
| 634 | - EVENT_ESPRESSO_VERSION |
|
| 635 | - ); |
|
| 636 | - wp_enqueue_style('espresso_att'); |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - public function load_scripts_styles_new_registration() |
|
| 641 | - { |
|
| 642 | - wp_register_script( |
|
| 643 | - 'ee-spco-for-admin', |
|
| 644 | - REG_ASSETS_URL . 'spco_for_admin.js', |
|
| 645 | - array('underscore', 'jquery'), |
|
| 646 | - EVENT_ESPRESSO_VERSION, |
|
| 647 | - true |
|
| 648 | - ); |
|
| 649 | - wp_enqueue_script('ee-spco-for-admin'); |
|
| 650 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 651 | - EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
| 652 | - EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
| 653 | - EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
| 658 | - { |
|
| 659 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
| 664 | - { |
|
| 665 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - |
|
| 669 | - protected function _set_list_table_views_default() |
|
| 670 | - { |
|
| 671 | - //for notification related bulk actions we need to make sure only active messengers have an option. |
|
| 672 | - EED_Messages::set_autoloaders(); |
|
| 673 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 674 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 675 | - $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
| 676 | - //key= bulk_action_slug, value= message type. |
|
| 677 | - $match_array = array( |
|
| 678 | - 'approve_registration' => 'registration', |
|
| 679 | - 'decline_registration' => 'declined_registration', |
|
| 680 | - 'pending_registration' => 'pending_approval', |
|
| 681 | - 'no_approve_registration' => 'not_approved_registration', |
|
| 682 | - 'cancel_registration' => 'cancelled_registration', |
|
| 683 | - ); |
|
| 684 | - $can_send = EE_Registry::instance()->CAP->current_user_can( |
|
| 685 | - 'ee_send_message', |
|
| 686 | - 'batch_send_messages' |
|
| 687 | - ); |
|
| 688 | - /** setup reg status bulk actions **/ |
|
| 689 | - $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso'); |
|
| 690 | - if ($can_send && in_array($match_array['approve_registration'], $active_mts, true)) { |
|
| 691 | - $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations', |
|
| 692 | - 'event_espresso'); |
|
| 693 | - } |
|
| 694 | - $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso'); |
|
| 695 | - if ($can_send && in_array($match_array['decline_registration'], $active_mts, true)) { |
|
| 696 | - $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations', |
|
| 697 | - 'event_espresso'); |
|
| 698 | - } |
|
| 699 | - $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso'); |
|
| 700 | - if ($can_send && in_array($match_array['pending_registration'], $active_mts, true)) { |
|
| 701 | - $def_reg_status_actions['pending_and_notify_registration'] = __( |
|
| 702 | - 'Set Registrations to Pending Payment and Notify', |
|
| 703 | - 'event_espresso' |
|
| 704 | - ); |
|
| 705 | - } |
|
| 706 | - $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso'); |
|
| 707 | - if ($can_send && in_array($match_array['no_approve_registration'], $active_mts, true)) { |
|
| 708 | - $def_reg_status_actions['no_approve_and_notify_registration'] = __( |
|
| 709 | - 'Set Registrations to Not Approved and Notify', |
|
| 710 | - 'event_espresso' |
|
| 711 | - ); |
|
| 712 | - } |
|
| 713 | - $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso'); |
|
| 714 | - if ($can_send && in_array($match_array['cancel_registration'], $active_mts, true)) { |
|
| 715 | - $def_reg_status_actions['cancel_and_notify_registration'] = __( |
|
| 716 | - 'Cancel Registrations and Notify', |
|
| 717 | - 'event_espresso' |
|
| 718 | - ); |
|
| 719 | - } |
|
| 720 | - $def_reg_status_actions = apply_filters( |
|
| 721 | - 'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array', |
|
| 722 | - $def_reg_status_actions, |
|
| 723 | - $active_mts |
|
| 724 | - ); |
|
| 725 | - |
|
| 726 | - $this->_views = array( |
|
| 727 | - 'all' => array( |
|
| 728 | - 'slug' => 'all', |
|
| 729 | - 'label' => esc_html__('View All Registrations', 'event_espresso'), |
|
| 730 | - 'count' => 0, |
|
| 731 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 732 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 733 | - )), |
|
| 734 | - ), |
|
| 735 | - 'month' => array( |
|
| 736 | - 'slug' => 'month', |
|
| 737 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 738 | - 'count' => 0, |
|
| 739 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 740 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 741 | - )), |
|
| 742 | - ), |
|
| 743 | - 'today' => array( |
|
| 744 | - 'slug' => 'today', |
|
| 745 | - 'label' => sprintf( |
|
| 746 | - esc_html__('Today - %s', 'event_espresso'), |
|
| 747 | - date('M d, Y', current_time('timestamp')) |
|
| 748 | - ), |
|
| 749 | - 'count' => 0, |
|
| 750 | - 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 751 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 752 | - )), |
|
| 753 | - ), |
|
| 754 | - ); |
|
| 755 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 756 | - 'ee_delete_registrations', |
|
| 757 | - 'espresso_registrations_delete_registration' |
|
| 758 | - )) { |
|
| 759 | - $this->_views['incomplete'] = array( |
|
| 760 | - 'slug' => 'incomplete', |
|
| 761 | - 'label' => esc_html__('Incomplete', 'event_espresso'), |
|
| 762 | - 'count' => 0, |
|
| 763 | - 'bulk_action' => array( |
|
| 764 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 765 | - ), |
|
| 766 | - ); |
|
| 767 | - $this->_views['trash'] = array( |
|
| 768 | - 'slug' => 'trash', |
|
| 769 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 770 | - 'count' => 0, |
|
| 771 | - 'bulk_action' => array( |
|
| 772 | - 'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'), |
|
| 773 | - 'delete_registrations' => esc_html__('Delete Registrations Permanently', 'event_espresso'), |
|
| 774 | - ), |
|
| 775 | - ); |
|
| 776 | - } |
|
| 777 | - } |
|
| 778 | - |
|
| 779 | - |
|
| 780 | - protected function _set_list_table_views_contact_list() |
|
| 781 | - { |
|
| 782 | - $this->_views = array( |
|
| 783 | - 'in_use' => array( |
|
| 784 | - 'slug' => 'in_use', |
|
| 785 | - 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 786 | - 'count' => 0, |
|
| 787 | - 'bulk_action' => array( |
|
| 788 | - 'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 789 | - ), |
|
| 790 | - ), |
|
| 791 | - ); |
|
| 792 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', |
|
| 793 | - 'espresso_registrations_trash_attendees') |
|
| 794 | - ) { |
|
| 795 | - $this->_views['trash'] = array( |
|
| 796 | - 'slug' => 'trash', |
|
| 797 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 798 | - 'count' => 0, |
|
| 799 | - 'bulk_action' => array( |
|
| 800 | - 'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 801 | - ), |
|
| 802 | - ); |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - |
|
| 807 | - protected function _registration_legend_items() |
|
| 808 | - { |
|
| 809 | - $fc_items = array( |
|
| 810 | - 'star-icon' => array( |
|
| 811 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 812 | - 'desc' => esc_html__('This is the Primary Registrant', 'event_espresso'), |
|
| 813 | - ), |
|
| 814 | - 'view_details' => array( |
|
| 815 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 816 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 817 | - ), |
|
| 818 | - 'edit_attendee' => array( |
|
| 819 | - 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
|
| 820 | - 'desc' => esc_html__('Edit Contact Details', 'event_espresso'), |
|
| 821 | - ), |
|
| 822 | - 'view_transaction' => array( |
|
| 823 | - 'class' => 'dashicons dashicons-cart', |
|
| 824 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 825 | - ), |
|
| 826 | - 'view_invoice' => array( |
|
| 827 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 828 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 829 | - ), |
|
| 830 | - ); |
|
| 831 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 832 | - 'ee_send_message', |
|
| 833 | - 'espresso_registrations_resend_registration' |
|
| 834 | - )) { |
|
| 835 | - $fc_items['resend_registration'] = array( |
|
| 836 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 837 | - 'desc' => esc_html__('Resend Registration Details', 'event_espresso'), |
|
| 838 | - ); |
|
| 839 | - } else { |
|
| 840 | - $fc_items['blank'] = array('class' => 'blank', 'desc' => ''); |
|
| 841 | - } |
|
| 842 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 843 | - 'ee_read_global_messages', |
|
| 844 | - 'view_filtered_messages' |
|
| 845 | - )) { |
|
| 846 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 847 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 848 | - $fc_items['view_related_messages'] = array( |
|
| 849 | - 'class' => $related_for_icon['css_class'], |
|
| 850 | - 'desc' => $related_for_icon['label'], |
|
| 851 | - ); |
|
| 852 | - } |
|
| 853 | - } |
|
| 854 | - $sc_items = array( |
|
| 855 | - 'approved_status' => array( |
|
| 856 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 857 | - 'desc' => EEH_Template::pretty_status( |
|
| 858 | - EEM_Registration::status_id_approved, |
|
| 859 | - false, |
|
| 860 | - 'sentence' |
|
| 861 | - ), |
|
| 862 | - ), |
|
| 863 | - 'pending_status' => array( |
|
| 864 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 865 | - 'desc' => EEH_Template::pretty_status( |
|
| 866 | - EEM_Registration::status_id_pending_payment, |
|
| 867 | - false, |
|
| 868 | - 'sentence' |
|
| 869 | - ), |
|
| 870 | - ), |
|
| 871 | - 'wait_list' => array( |
|
| 872 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 873 | - 'desc' => EEH_Template::pretty_status( |
|
| 874 | - EEM_Registration::status_id_wait_list, |
|
| 875 | - false, |
|
| 876 | - 'sentence' |
|
| 877 | - ), |
|
| 878 | - ), |
|
| 879 | - 'incomplete_status' => array( |
|
| 880 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
| 881 | - 'desc' => EEH_Template::pretty_status( |
|
| 882 | - EEM_Registration::status_id_incomplete, |
|
| 883 | - false, |
|
| 884 | - 'sentence' |
|
| 885 | - ), |
|
| 886 | - ), |
|
| 887 | - 'not_approved' => array( |
|
| 888 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 889 | - 'desc' => EEH_Template::pretty_status( |
|
| 890 | - EEM_Registration::status_id_not_approved, |
|
| 891 | - false, |
|
| 892 | - 'sentence' |
|
| 893 | - ), |
|
| 894 | - ), |
|
| 895 | - 'declined_status' => array( |
|
| 896 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 897 | - 'desc' => EEH_Template::pretty_status( |
|
| 898 | - EEM_Registration::status_id_declined, |
|
| 899 | - false, |
|
| 900 | - 'sentence' |
|
| 901 | - ), |
|
| 902 | - ), |
|
| 903 | - 'cancelled_status' => array( |
|
| 904 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 905 | - 'desc' => EEH_Template::pretty_status( |
|
| 906 | - EEM_Registration::status_id_cancelled, |
|
| 907 | - false, |
|
| 908 | - 'sentence' |
|
| 909 | - ), |
|
| 910 | - ), |
|
| 911 | - ); |
|
| 912 | - return array_merge($fc_items, $sc_items); |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - |
|
| 916 | - |
|
| 917 | - /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
| 918 | - /** |
|
| 919 | - * @throws \EE_Error |
|
| 920 | - */ |
|
| 921 | - protected function _registrations_overview_list_table() |
|
| 922 | - { |
|
| 923 | - $this->_template_args['admin_page_header'] = ''; |
|
| 924 | - $EVT_ID = ! empty($this->_req_data['event_id']) |
|
| 925 | - ? absint($this->_req_data['event_id']) |
|
| 926 | - : 0; |
|
| 927 | - if ($EVT_ID) { |
|
| 928 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 929 | - 'ee_edit_registrations', |
|
| 930 | - 'espresso_registrations_new_registration', |
|
| 931 | - $EVT_ID |
|
| 932 | - )) { |
|
| 933 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 934 | - 'new_registration', |
|
| 935 | - 'add-registrant', |
|
| 936 | - array('event_id' => $EVT_ID), |
|
| 937 | - 'add-new-h2' |
|
| 938 | - ); |
|
| 939 | - } |
|
| 940 | - $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 941 | - if ($event instanceof EE_Event) { |
|
| 942 | - $this->_template_args['admin_page_header'] = sprintf( |
|
| 943 | - esc_html__( |
|
| 944 | - '%s Viewing registrations for the event: %s%s', |
|
| 945 | - 'event_espresso' |
|
| 946 | - ), |
|
| 947 | - '<h3 style="line-height:1.5em;">', |
|
| 948 | - '<br /><a href="' |
|
| 949 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
| 950 | - array( |
|
| 951 | - 'action' => 'edit', |
|
| 952 | - 'post' => $event->ID(), |
|
| 953 | - ), |
|
| 954 | - EVENTS_ADMIN_URL |
|
| 955 | - ) |
|
| 956 | - . '"> ' |
|
| 957 | - . $event->get('EVT_name') |
|
| 958 | - . ' </a> ', |
|
| 959 | - '</h3>' |
|
| 960 | - ); |
|
| 961 | - } |
|
| 962 | - $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
|
| 963 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 964 | - if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') { |
|
| 965 | - $this->_template_args['admin_page_header'] = substr( |
|
| 966 | - $this->_template_args['admin_page_header'], |
|
| 967 | - 0, |
|
| 968 | - -5 |
|
| 969 | - ); |
|
| 970 | - $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
|
| 971 | - $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 972 | - $this->_template_args['admin_page_header'] .= $datetime->name(); |
|
| 973 | - $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
| 974 | - $this->_template_args['admin_page_header'] .= '</span></h3>'; |
|
| 975 | - } |
|
| 976 | - } |
|
| 977 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
| 978 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * This sets the _registration property for the registration details screen |
|
| 984 | - * |
|
| 985 | - * @access private |
|
| 986 | - * @return bool |
|
| 987 | - */ |
|
| 988 | - private function _set_registration_object() |
|
| 989 | - { |
|
| 990 | - //get out if we've already set the object |
|
| 991 | - if (is_object($this->_registration)) { |
|
| 992 | - return true; |
|
| 993 | - } |
|
| 994 | - $REG = EEM_Registration::instance(); |
|
| 995 | - $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 996 | - if ($this->_registration = $REG->get_one_by_ID($REG_ID)) { |
|
| 997 | - return true; |
|
| 998 | - } else { |
|
| 999 | - $error_msg = sprintf( |
|
| 1000 | - esc_html__( |
|
| 1001 | - 'An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
| 1002 | - 'event_espresso' |
|
| 1003 | - ), |
|
| 1004 | - $REG_ID |
|
| 1005 | - ); |
|
| 1006 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1007 | - $this->_registration = null; |
|
| 1008 | - return false; |
|
| 1009 | - } |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - |
|
| 1013 | - /** |
|
| 1014 | - * Used to retrieve registrations for the list table. |
|
| 1015 | - * |
|
| 1016 | - * @param int $per_page |
|
| 1017 | - * @param bool $count |
|
| 1018 | - * @param bool $this_month |
|
| 1019 | - * @param bool $today |
|
| 1020 | - * @return EE_Registration[]|int |
|
| 1021 | - * @throws EE_Error |
|
| 1022 | - */ |
|
| 1023 | - public function get_registrations( |
|
| 1024 | - $per_page = 10, |
|
| 1025 | - $count = false, |
|
| 1026 | - $this_month = false, |
|
| 1027 | - $today = false |
|
| 1028 | - ) { |
|
| 1029 | - if ($this_month) { |
|
| 1030 | - $this->_req_data['status'] = 'month'; |
|
| 1031 | - } |
|
| 1032 | - if ($today) { |
|
| 1033 | - $this->_req_data['status'] = 'today'; |
|
| 1034 | - } |
|
| 1035 | - $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
|
| 1036 | - /** |
|
| 1037 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1038 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1039 | - * @see EEM_Base::get_all() |
|
| 1040 | - */ |
|
| 1041 | - $query_params['group_by'] = ''; |
|
| 1042 | - |
|
| 1043 | - return $count |
|
| 1044 | - ? EEM_Registration::instance()->count($query_params) |
|
| 1045 | - /** @type EE_Registration[] */ |
|
| 1046 | - : EEM_Registration::instance()->get_all($query_params); |
|
| 1047 | - } |
|
| 1048 | - |
|
| 1049 | - |
|
| 1050 | - |
|
| 1051 | - /** |
|
| 1052 | - * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
| 1053 | - * Note: this listens to values on the request for some of the query parameters. |
|
| 1054 | - * |
|
| 1055 | - * @param array $request |
|
| 1056 | - * @param int $per_page |
|
| 1057 | - * @param bool $count |
|
| 1058 | - * @return array |
|
| 1059 | - */ |
|
| 1060 | - protected function _get_registration_query_parameters( |
|
| 1061 | - $request = array(), |
|
| 1062 | - $per_page = 10, |
|
| 1063 | - $count = false |
|
| 1064 | - ) { |
|
| 1065 | - |
|
| 1066 | - $query_params = array( |
|
| 1067 | - 0 => $this->_get_where_conditions_for_registrations_query( |
|
| 1068 | - $request |
|
| 1069 | - ), |
|
| 1070 | - 'caps' => EEM_Registration::caps_read_admin, |
|
| 1071 | - 'default_where_conditions' => 'this_model_only', |
|
| 1072 | - ); |
|
| 1073 | - if (! $count) { |
|
| 1074 | - $query_params = array_merge( |
|
| 1075 | - $query_params, |
|
| 1076 | - $this->_get_orderby_for_registrations_query(), |
|
| 1077 | - $this->_get_limit($per_page) |
|
| 1078 | - ); |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - return $query_params; |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - |
|
| 1085 | - /** |
|
| 1086 | - * This will add EVT_ID to the provided $where array for EE model query parameters. |
|
| 1087 | - * |
|
| 1088 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1089 | - * @return array |
|
| 1090 | - */ |
|
| 1091 | - protected function _add_event_id_to_where_conditions(array $request) |
|
| 1092 | - { |
|
| 1093 | - $where = array(); |
|
| 1094 | - if (! empty($request['event_id'])) { |
|
| 1095 | - $where['EVT_ID'] = absint($request['event_id']); |
|
| 1096 | - } |
|
| 1097 | - return $where; |
|
| 1098 | - } |
|
| 1099 | - |
|
| 1100 | - |
|
| 1101 | - /** |
|
| 1102 | - * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
| 1103 | - * |
|
| 1104 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1105 | - * @return array |
|
| 1106 | - */ |
|
| 1107 | - protected function _add_category_id_to_where_conditions(array $request) |
|
| 1108 | - { |
|
| 1109 | - $where = array(); |
|
| 1110 | - if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) { |
|
| 1111 | - $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
|
| 1112 | - } |
|
| 1113 | - return $where; |
|
| 1114 | - } |
|
| 1115 | - |
|
| 1116 | - |
|
| 1117 | - /** |
|
| 1118 | - * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
| 1119 | - * |
|
| 1120 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1121 | - * @return array |
|
| 1122 | - */ |
|
| 1123 | - protected function _add_datetime_id_to_where_conditions(array $request) |
|
| 1124 | - { |
|
| 1125 | - $where = array(); |
|
| 1126 | - if (! empty($request['datetime_id'])) { |
|
| 1127 | - $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
|
| 1128 | - } |
|
| 1129 | - if (! empty($request['DTT_ID'])) { |
|
| 1130 | - $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
|
| 1131 | - } |
|
| 1132 | - return $where; |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - |
|
| 1136 | - /** |
|
| 1137 | - * Adds the correct registration status to the where conditions for the registrations query. |
|
| 1138 | - * |
|
| 1139 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1140 | - * @return array |
|
| 1141 | - */ |
|
| 1142 | - protected function _add_registration_status_to_where_conditions(array $request) |
|
| 1143 | - { |
|
| 1144 | - $where = array(); |
|
| 1145 | - $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1146 | - $registration_status = ! empty($request['_reg_status']) |
|
| 1147 | - ? sanitize_text_field($request['_reg_status']) |
|
| 1148 | - : ''; |
|
| 1149 | - |
|
| 1150 | - /* |
|
| 26 | + /** |
|
| 27 | + * @var EE_Registration |
|
| 28 | + */ |
|
| 29 | + private $_registration; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var EE_Event |
|
| 33 | + */ |
|
| 34 | + private $_reg_event; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var EE_Session |
|
| 38 | + */ |
|
| 39 | + private $_session; |
|
| 40 | + |
|
| 41 | + private static $_reg_status; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Form for displaying the custom questions for this registration. |
|
| 45 | + * This gets used a few times throughout the request so its best to cache it |
|
| 46 | + * |
|
| 47 | + * @var EE_Registration_Custom_Questions_Form |
|
| 48 | + */ |
|
| 49 | + protected $_reg_custom_questions_form = null; |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * constructor |
|
| 54 | + * |
|
| 55 | + * @Constructor |
|
| 56 | + * @access public |
|
| 57 | + * @param bool $routing |
|
| 58 | + * @return Registrations_Admin_Page |
|
| 59 | + */ |
|
| 60 | + public function __construct($routing = true) |
|
| 61 | + { |
|
| 62 | + parent::__construct($routing); |
|
| 63 | + add_action('wp_loaded', array($this, 'wp_loaded')); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + public function wp_loaded() |
|
| 68 | + { |
|
| 69 | + // when adding a new registration... |
|
| 70 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
|
| 71 | + EE_System::do_not_cache(); |
|
| 72 | + if (! isset($this->_req_data['processing_registration']) |
|
| 73 | + || absint($this->_req_data['processing_registration']) !== 1 |
|
| 74 | + ) { |
|
| 75 | + // and it's NOT the attendee information reg step |
|
| 76 | + // force cookie expiration by setting time to last week |
|
| 77 | + setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
| 78 | + // and update the global |
|
| 79 | + $_COOKIE['ee_registration_added'] = 0; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + protected function _init_page_props() |
|
| 86 | + { |
|
| 87 | + $this->page_slug = REG_PG_SLUG; |
|
| 88 | + $this->_admin_base_url = REG_ADMIN_URL; |
|
| 89 | + $this->_admin_base_path = REG_ADMIN; |
|
| 90 | + $this->page_label = esc_html__('Registrations', 'event_espresso'); |
|
| 91 | + $this->_cpt_routes = array( |
|
| 92 | + 'add_new_attendee' => 'espresso_attendees', |
|
| 93 | + 'edit_attendee' => 'espresso_attendees', |
|
| 94 | + 'insert_attendee' => 'espresso_attendees', |
|
| 95 | + 'update_attendee' => 'espresso_attendees', |
|
| 96 | + ); |
|
| 97 | + $this->_cpt_model_names = array( |
|
| 98 | + 'add_new_attendee' => 'EEM_Attendee', |
|
| 99 | + 'edit_attendee' => 'EEM_Attendee', |
|
| 100 | + ); |
|
| 101 | + $this->_cpt_edit_routes = array( |
|
| 102 | + 'espresso_attendees' => 'edit_attendee', |
|
| 103 | + ); |
|
| 104 | + $this->_pagenow_map = array( |
|
| 105 | + 'add_new_attendee' => 'post-new.php', |
|
| 106 | + 'edit_attendee' => 'post.php', |
|
| 107 | + 'trash' => 'post.php', |
|
| 108 | + ); |
|
| 109 | + add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10); |
|
| 110 | + //add filters so that the comment urls don't take users to a confusing 404 page |
|
| 111 | + add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + public function clear_comment_link($link, $comment, $args) |
|
| 116 | + { |
|
| 117 | + //gotta make sure this only happens on this route |
|
| 118 | + $post_type = get_post_type($comment->comment_post_ID); |
|
| 119 | + if ($post_type === 'espresso_attendees') { |
|
| 120 | + return '#commentsdiv'; |
|
| 121 | + } |
|
| 122 | + return $link; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + protected function _ajax_hooks() |
|
| 127 | + { |
|
| 128 | + //todo: all hooks for registrations ajax goes in here |
|
| 129 | + add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status')); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + protected function _define_page_props() |
|
| 134 | + { |
|
| 135 | + $this->_admin_page_title = $this->page_label; |
|
| 136 | + $this->_labels = array( |
|
| 137 | + 'buttons' => array( |
|
| 138 | + 'add-registrant' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 139 | + 'add-attendee' => esc_html__('Add Contact', 'event_espresso'), |
|
| 140 | + 'edit' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 141 | + 'report' => esc_html__("Event Registrations CSV Report", "event_espresso"), |
|
| 142 | + 'report_all' => esc_html__('All Registrations CSV Report', 'event_espresso'), |
|
| 143 | + 'report_filtered' => esc_html__('Filtered CSV Report', 'event_espresso'), |
|
| 144 | + 'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'), |
|
| 145 | + 'contact_list_export' => esc_html__("Export Data", "event_espresso"), |
|
| 146 | + ), |
|
| 147 | + 'publishbox' => array( |
|
| 148 | + 'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'), |
|
| 149 | + 'edit_attendee' => esc_html__("Update Contact Record", 'event_espresso'), |
|
| 150 | + ), |
|
| 151 | + 'hide_add_button_on_cpt_route' => array( |
|
| 152 | + 'edit_attendee' => true, |
|
| 153 | + ), |
|
| 154 | + ); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * grab url requests and route them |
|
| 160 | + * |
|
| 161 | + * @access private |
|
| 162 | + * @return void |
|
| 163 | + */ |
|
| 164 | + public function _set_page_routes() |
|
| 165 | + { |
|
| 166 | + $this->_get_registration_status_array(); |
|
| 167 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 168 | + ? $this->_req_data['_REG_ID'] : 0; |
|
| 169 | + $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID']) |
|
| 170 | + ? $this->_req_data['ATT_ID'] : 0; |
|
| 171 | + $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) |
|
| 172 | + ? $this->_req_data['post'] |
|
| 173 | + : $att_id; |
|
| 174 | + $this->_page_routes = array( |
|
| 175 | + 'default' => array( |
|
| 176 | + 'func' => '_registrations_overview_list_table', |
|
| 177 | + 'capability' => 'ee_read_registrations', |
|
| 178 | + ), |
|
| 179 | + 'view_registration' => array( |
|
| 180 | + 'func' => '_registration_details', |
|
| 181 | + 'capability' => 'ee_read_registration', |
|
| 182 | + 'obj_id' => $reg_id, |
|
| 183 | + ), |
|
| 184 | + 'edit_registration' => array( |
|
| 185 | + 'func' => '_update_attendee_registration_form', |
|
| 186 | + 'noheader' => true, |
|
| 187 | + 'headers_sent_route' => 'view_registration', |
|
| 188 | + 'capability' => 'ee_edit_registration', |
|
| 189 | + 'obj_id' => $reg_id, |
|
| 190 | + '_REG_ID' => $reg_id, |
|
| 191 | + ), |
|
| 192 | + 'trash_registrations' => array( |
|
| 193 | + 'func' => '_trash_or_restore_registrations', |
|
| 194 | + 'args' => array('trash' => true), |
|
| 195 | + 'noheader' => true, |
|
| 196 | + 'capability' => 'ee_delete_registrations', |
|
| 197 | + ), |
|
| 198 | + 'restore_registrations' => array( |
|
| 199 | + 'func' => '_trash_or_restore_registrations', |
|
| 200 | + 'args' => array('trash' => false), |
|
| 201 | + 'noheader' => true, |
|
| 202 | + 'capability' => 'ee_delete_registrations', |
|
| 203 | + ), |
|
| 204 | + 'delete_registrations' => array( |
|
| 205 | + 'func' => '_delete_registrations', |
|
| 206 | + 'noheader' => true, |
|
| 207 | + 'capability' => 'ee_delete_registrations', |
|
| 208 | + ), |
|
| 209 | + 'new_registration' => array( |
|
| 210 | + 'func' => 'new_registration', |
|
| 211 | + 'capability' => 'ee_edit_registrations', |
|
| 212 | + ), |
|
| 213 | + 'process_reg_step' => array( |
|
| 214 | + 'func' => 'process_reg_step', |
|
| 215 | + 'noheader' => true, |
|
| 216 | + 'capability' => 'ee_edit_registrations', |
|
| 217 | + ), |
|
| 218 | + 'redirect_to_txn' => array( |
|
| 219 | + 'func' => 'redirect_to_txn', |
|
| 220 | + 'noheader' => true, |
|
| 221 | + 'capability' => 'ee_edit_registrations', |
|
| 222 | + ), |
|
| 223 | + 'change_reg_status' => array( |
|
| 224 | + 'func' => '_change_reg_status', |
|
| 225 | + 'noheader' => true, |
|
| 226 | + 'capability' => 'ee_edit_registration', |
|
| 227 | + 'obj_id' => $reg_id, |
|
| 228 | + ), |
|
| 229 | + 'approve_registration' => array( |
|
| 230 | + 'func' => 'approve_registration', |
|
| 231 | + 'noheader' => true, |
|
| 232 | + 'capability' => 'ee_edit_registration', |
|
| 233 | + 'obj_id' => $reg_id, |
|
| 234 | + ), |
|
| 235 | + 'approve_and_notify_registration' => array( |
|
| 236 | + 'func' => 'approve_registration', |
|
| 237 | + 'noheader' => true, |
|
| 238 | + 'args' => array(true), |
|
| 239 | + 'capability' => 'ee_edit_registration', |
|
| 240 | + 'obj_id' => $reg_id, |
|
| 241 | + ), |
|
| 242 | + 'decline_registration' => array( |
|
| 243 | + 'func' => 'decline_registration', |
|
| 244 | + 'noheader' => true, |
|
| 245 | + 'capability' => 'ee_edit_registration', |
|
| 246 | + 'obj_id' => $reg_id, |
|
| 247 | + ), |
|
| 248 | + 'decline_and_notify_registration' => array( |
|
| 249 | + 'func' => 'decline_registration', |
|
| 250 | + 'noheader' => true, |
|
| 251 | + 'args' => array(true), |
|
| 252 | + 'capability' => 'ee_edit_registration', |
|
| 253 | + 'obj_id' => $reg_id, |
|
| 254 | + ), |
|
| 255 | + 'pending_registration' => array( |
|
| 256 | + 'func' => 'pending_registration', |
|
| 257 | + 'noheader' => true, |
|
| 258 | + 'capability' => 'ee_edit_registration', |
|
| 259 | + 'obj_id' => $reg_id, |
|
| 260 | + ), |
|
| 261 | + 'pending_and_notify_registration' => array( |
|
| 262 | + 'func' => 'pending_registration', |
|
| 263 | + 'noheader' => true, |
|
| 264 | + 'args' => array(true), |
|
| 265 | + 'capability' => 'ee_edit_registration', |
|
| 266 | + 'obj_id' => $reg_id, |
|
| 267 | + ), |
|
| 268 | + 'no_approve_registration' => array( |
|
| 269 | + 'func' => 'not_approve_registration', |
|
| 270 | + 'noheader' => true, |
|
| 271 | + 'capability' => 'ee_edit_registration', |
|
| 272 | + 'obj_id' => $reg_id, |
|
| 273 | + ), |
|
| 274 | + 'no_approve_and_notify_registration' => array( |
|
| 275 | + 'func' => 'not_approve_registration', |
|
| 276 | + 'noheader' => true, |
|
| 277 | + 'args' => array(true), |
|
| 278 | + 'capability' => 'ee_edit_registration', |
|
| 279 | + 'obj_id' => $reg_id, |
|
| 280 | + ), |
|
| 281 | + 'cancel_registration' => array( |
|
| 282 | + 'func' => 'cancel_registration', |
|
| 283 | + 'noheader' => true, |
|
| 284 | + 'capability' => 'ee_edit_registration', |
|
| 285 | + 'obj_id' => $reg_id, |
|
| 286 | + ), |
|
| 287 | + 'cancel_and_notify_registration' => array( |
|
| 288 | + 'func' => 'cancel_registration', |
|
| 289 | + 'noheader' => true, |
|
| 290 | + 'args' => array(true), |
|
| 291 | + 'capability' => 'ee_edit_registration', |
|
| 292 | + 'obj_id' => $reg_id, |
|
| 293 | + ), |
|
| 294 | + 'wait_list_registration' => array( |
|
| 295 | + 'func' => 'wait_list_registration', |
|
| 296 | + 'noheader' => true, |
|
| 297 | + 'capability' => 'ee_edit_registration', |
|
| 298 | + 'obj_id' => $reg_id, |
|
| 299 | + ), |
|
| 300 | + 'contact_list' => array( |
|
| 301 | + 'func' => '_attendee_contact_list_table', |
|
| 302 | + 'capability' => 'ee_read_contacts', |
|
| 303 | + ), |
|
| 304 | + 'add_new_attendee' => array( |
|
| 305 | + 'func' => '_create_new_cpt_item', |
|
| 306 | + 'args' => array( |
|
| 307 | + 'new_attendee' => true, |
|
| 308 | + 'capability' => 'ee_edit_contacts', |
|
| 309 | + ), |
|
| 310 | + ), |
|
| 311 | + 'edit_attendee' => array( |
|
| 312 | + 'func' => '_edit_cpt_item', |
|
| 313 | + 'capability' => 'ee_edit_contacts', |
|
| 314 | + 'obj_id' => $att_id, |
|
| 315 | + ), |
|
| 316 | + 'duplicate_attendee' => array( |
|
| 317 | + 'func' => '_duplicate_attendee', |
|
| 318 | + 'noheader' => true, |
|
| 319 | + 'capability' => 'ee_edit_contacts', |
|
| 320 | + 'obj_id' => $att_id, |
|
| 321 | + ), |
|
| 322 | + 'insert_attendee' => array( |
|
| 323 | + 'func' => '_insert_or_update_attendee', |
|
| 324 | + 'args' => array( |
|
| 325 | + 'new_attendee' => true, |
|
| 326 | + ), |
|
| 327 | + 'noheader' => true, |
|
| 328 | + 'capability' => 'ee_edit_contacts', |
|
| 329 | + ), |
|
| 330 | + 'update_attendee' => array( |
|
| 331 | + 'func' => '_insert_or_update_attendee', |
|
| 332 | + 'args' => array( |
|
| 333 | + 'new_attendee' => false, |
|
| 334 | + ), |
|
| 335 | + 'noheader' => true, |
|
| 336 | + 'capability' => 'ee_edit_contacts', |
|
| 337 | + 'obj_id' => $att_id, |
|
| 338 | + ), |
|
| 339 | + 'trash_attendee' => array( |
|
| 340 | + 'func' => '_trash_or_restore_attendees', |
|
| 341 | + 'args' => array( |
|
| 342 | + 'trash' => true, |
|
| 343 | + ), |
|
| 344 | + 'noheader' => true, |
|
| 345 | + 'capability' => 'ee_delete_contacts', |
|
| 346 | + 'obj_id' => $att_id, |
|
| 347 | + ), |
|
| 348 | + 'restore_attendees' => array( |
|
| 349 | + 'func' => '_trash_or_restore_attendees', |
|
| 350 | + 'args' => array( |
|
| 351 | + 'trash' => false, |
|
| 352 | + ), |
|
| 353 | + 'noheader' => true, |
|
| 354 | + 'capability' => 'ee_delete_contacts', |
|
| 355 | + 'obj_id' => $att_id, |
|
| 356 | + ), |
|
| 357 | + 'resend_registration' => array( |
|
| 358 | + 'func' => '_resend_registration', |
|
| 359 | + 'noheader' => true, |
|
| 360 | + 'capability' => 'ee_send_message', |
|
| 361 | + ), |
|
| 362 | + 'registrations_report' => array( |
|
| 363 | + 'func' => '_registrations_report', |
|
| 364 | + 'noheader' => true, |
|
| 365 | + 'capability' => 'ee_read_registrations', |
|
| 366 | + ), |
|
| 367 | + 'contact_list_export' => array( |
|
| 368 | + 'func' => '_contact_list_export', |
|
| 369 | + 'noheader' => true, |
|
| 370 | + 'capability' => 'export', |
|
| 371 | + ), |
|
| 372 | + 'contact_list_report' => array( |
|
| 373 | + 'func' => '_contact_list_report', |
|
| 374 | + 'noheader' => true, |
|
| 375 | + 'capability' => 'ee_read_contacts', |
|
| 376 | + ), |
|
| 377 | + ); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + |
|
| 381 | + protected function _set_page_config() |
|
| 382 | + { |
|
| 383 | + $this->_page_config = array( |
|
| 384 | + 'default' => array( |
|
| 385 | + 'nav' => array( |
|
| 386 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 387 | + 'order' => 5, |
|
| 388 | + ), |
|
| 389 | + 'help_tabs' => array( |
|
| 390 | + 'registrations_overview_help_tab' => array( |
|
| 391 | + 'title' => esc_html__('Registrations Overview', 'event_espresso'), |
|
| 392 | + 'filename' => 'registrations_overview', |
|
| 393 | + ), |
|
| 394 | + 'registrations_overview_table_column_headings_help_tab' => array( |
|
| 395 | + 'title' => esc_html__('Registrations Table Column Headings', 'event_espresso'), |
|
| 396 | + 'filename' => 'registrations_overview_table_column_headings', |
|
| 397 | + ), |
|
| 398 | + 'registrations_overview_filters_help_tab' => array( |
|
| 399 | + 'title' => esc_html__('Registration Filters', 'event_espresso'), |
|
| 400 | + 'filename' => 'registrations_overview_filters', |
|
| 401 | + ), |
|
| 402 | + 'registrations_overview_views_help_tab' => array( |
|
| 403 | + 'title' => esc_html__('Registration Views', 'event_espresso'), |
|
| 404 | + 'filename' => 'registrations_overview_views', |
|
| 405 | + ), |
|
| 406 | + 'registrations_regoverview_other_help_tab' => array( |
|
| 407 | + 'title' => esc_html__('Registrations Other', 'event_espresso'), |
|
| 408 | + 'filename' => 'registrations_overview_other', |
|
| 409 | + ), |
|
| 410 | + ), |
|
| 411 | + 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
| 412 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
| 413 | + 'list_table' => 'EE_Registrations_List_Table', |
|
| 414 | + 'require_nonce' => false, |
|
| 415 | + ), |
|
| 416 | + 'view_registration' => array( |
|
| 417 | + 'nav' => array( |
|
| 418 | + 'label' => esc_html__('REG Details', 'event_espresso'), |
|
| 419 | + 'order' => 15, |
|
| 420 | + 'url' => isset($this->_req_data['_REG_ID']) |
|
| 421 | + ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url) |
|
| 422 | + : $this->_admin_base_url, |
|
| 423 | + 'persistent' => false, |
|
| 424 | + ), |
|
| 425 | + 'help_tabs' => array( |
|
| 426 | + 'registrations_details_help_tab' => array( |
|
| 427 | + 'title' => esc_html__('Registration Details', 'event_espresso'), |
|
| 428 | + 'filename' => 'registrations_details', |
|
| 429 | + ), |
|
| 430 | + 'registrations_details_table_help_tab' => array( |
|
| 431 | + 'title' => esc_html__('Registration Details Table', 'event_espresso'), |
|
| 432 | + 'filename' => 'registrations_details_table', |
|
| 433 | + ), |
|
| 434 | + 'registrations_details_form_answers_help_tab' => array( |
|
| 435 | + 'title' => esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 436 | + 'filename' => 'registrations_details_form_answers', |
|
| 437 | + ), |
|
| 438 | + 'registrations_details_registrant_details_help_tab' => array( |
|
| 439 | + 'title' => esc_html__('Contact Details', 'event_espresso'), |
|
| 440 | + 'filename' => 'registrations_details_registrant_details', |
|
| 441 | + ), |
|
| 442 | + ), |
|
| 443 | + 'help_tour' => array('Registration_Details_Help_Tour'), |
|
| 444 | + 'metaboxes' => array_merge( |
|
| 445 | + $this->_default_espresso_metaboxes, |
|
| 446 | + array('_registration_details_metaboxes') |
|
| 447 | + ), |
|
| 448 | + 'require_nonce' => false, |
|
| 449 | + ), |
|
| 450 | + 'new_registration' => array( |
|
| 451 | + 'nav' => array( |
|
| 452 | + 'label' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 453 | + 'url' => '#', |
|
| 454 | + 'order' => 15, |
|
| 455 | + 'persistent' => false, |
|
| 456 | + ), |
|
| 457 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 458 | + 'labels' => array( |
|
| 459 | + 'publishbox' => esc_html__('Save Registration', 'event_espresso'), |
|
| 460 | + ), |
|
| 461 | + 'require_nonce' => false, |
|
| 462 | + ), |
|
| 463 | + 'add_new_attendee' => array( |
|
| 464 | + 'nav' => array( |
|
| 465 | + 'label' => esc_html__('Add Contact', 'event_espresso'), |
|
| 466 | + 'order' => 15, |
|
| 467 | + 'persistent' => false, |
|
| 468 | + ), |
|
| 469 | + 'metaboxes' => array_merge( |
|
| 470 | + $this->_default_espresso_metaboxes, |
|
| 471 | + array('_publish_post_box', 'attendee_editor_metaboxes') |
|
| 472 | + ), |
|
| 473 | + 'require_nonce' => false, |
|
| 474 | + ), |
|
| 475 | + 'edit_attendee' => array( |
|
| 476 | + 'nav' => array( |
|
| 477 | + 'label' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 478 | + 'order' => 15, |
|
| 479 | + 'persistent' => false, |
|
| 480 | + 'url' => isset($this->_req_data['ATT_ID']) |
|
| 481 | + ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url) |
|
| 482 | + : $this->_admin_base_url, |
|
| 483 | + ), |
|
| 484 | + 'metaboxes' => array('attendee_editor_metaboxes'), |
|
| 485 | + 'require_nonce' => false, |
|
| 486 | + ), |
|
| 487 | + 'contact_list' => array( |
|
| 488 | + 'nav' => array( |
|
| 489 | + 'label' => esc_html__('Contact List', 'event_espresso'), |
|
| 490 | + 'order' => 20, |
|
| 491 | + ), |
|
| 492 | + 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
| 493 | + 'help_tabs' => array( |
|
| 494 | + 'registrations_contact_list_help_tab' => array( |
|
| 495 | + 'title' => esc_html__('Registrations Contact List', 'event_espresso'), |
|
| 496 | + 'filename' => 'registrations_contact_list', |
|
| 497 | + ), |
|
| 498 | + 'registrations_contact-list_table_column_headings_help_tab' => array( |
|
| 499 | + 'title' => esc_html__('Contact List Table Column Headings', 'event_espresso'), |
|
| 500 | + 'filename' => 'registrations_contact_list_table_column_headings', |
|
| 501 | + ), |
|
| 502 | + 'registrations_contact_list_views_help_tab' => array( |
|
| 503 | + 'title' => esc_html__('Contact List Views', 'event_espresso'), |
|
| 504 | + 'filename' => 'registrations_contact_list_views', |
|
| 505 | + ), |
|
| 506 | + 'registrations_contact_list_other_help_tab' => array( |
|
| 507 | + 'title' => esc_html__('Contact List Other', 'event_espresso'), |
|
| 508 | + 'filename' => 'registrations_contact_list_other', |
|
| 509 | + ), |
|
| 510 | + ), |
|
| 511 | + 'help_tour' => array('Contact_List_Help_Tour'), |
|
| 512 | + 'metaboxes' => array(), |
|
| 513 | + 'require_nonce' => false, |
|
| 514 | + ), |
|
| 515 | + //override default cpt routes |
|
| 516 | + 'create_new' => '', |
|
| 517 | + 'edit' => '', |
|
| 518 | + ); |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * The below methods aren't used by this class currently |
|
| 524 | + */ |
|
| 525 | + protected function _add_screen_options() |
|
| 526 | + { |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + protected function _add_feature_pointers() |
|
| 531 | + { |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + public function admin_init() |
|
| 536 | + { |
|
| 537 | + EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__( |
|
| 538 | + 'click "Update Registration Questions" to save your changes', |
|
| 539 | + 'event_espresso' |
|
| 540 | + ); |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + |
|
| 544 | + public function admin_notices() |
|
| 545 | + { |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + |
|
| 549 | + public function admin_footer_scripts() |
|
| 550 | + { |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * get list of registration statuses |
|
| 556 | + * |
|
| 557 | + * @access private |
|
| 558 | + * @return void |
|
| 559 | + */ |
|
| 560 | + private function _get_registration_status_array() |
|
| 561 | + { |
|
| 562 | + self::$_reg_status = EEM_Registration::reg_status_array(array(), true); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + protected function _add_screen_options_default() |
|
| 567 | + { |
|
| 568 | + $this->_per_page_screen_option(); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + protected function _add_screen_options_contact_list() |
|
| 573 | + { |
|
| 574 | + $page_title = $this->_admin_page_title; |
|
| 575 | + $this->_admin_page_title = esc_html__("Contacts", 'event_espresso'); |
|
| 576 | + $this->_per_page_screen_option(); |
|
| 577 | + $this->_admin_page_title = $page_title; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + public function load_scripts_styles() |
|
| 582 | + { |
|
| 583 | + //style |
|
| 584 | + wp_register_style( |
|
| 585 | + 'espresso_reg', |
|
| 586 | + REG_ASSETS_URL . 'espresso_registrations_admin.css', |
|
| 587 | + array('ee-admin-css'), |
|
| 588 | + EVENT_ESPRESSO_VERSION |
|
| 589 | + ); |
|
| 590 | + wp_enqueue_style('espresso_reg'); |
|
| 591 | + //script |
|
| 592 | + wp_register_script( |
|
| 593 | + 'espresso_reg', |
|
| 594 | + REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 595 | + array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), |
|
| 596 | + EVENT_ESPRESSO_VERSION, |
|
| 597 | + true |
|
| 598 | + ); |
|
| 599 | + wp_enqueue_script('espresso_reg'); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + public function load_scripts_styles_edit_attendee() |
|
| 604 | + { |
|
| 605 | + //stuff to only show up on our attendee edit details page. |
|
| 606 | + $attendee_details_translations = array( |
|
| 607 | + 'att_publish_text' => sprintf( |
|
| 608 | + esc_html__('Created on: <b>%1$s</b>', 'event_espresso'), |
|
| 609 | + $this->_cpt_model_obj->get_datetime('ATT_created') |
|
| 610 | + ), |
|
| 611 | + ); |
|
| 612 | + wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
| 613 | + wp_enqueue_script('jquery-validate'); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + public function load_scripts_styles_view_registration() |
|
| 618 | + { |
|
| 619 | + //styles |
|
| 620 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 621 | + //scripts |
|
| 622 | + $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 623 | + $this->_reg_custom_questions_form->wp_enqueue_scripts(true); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + public function load_scripts_styles_contact_list() |
|
| 628 | + { |
|
| 629 | + wp_deregister_style('espresso_reg'); |
|
| 630 | + wp_register_style( |
|
| 631 | + 'espresso_att', |
|
| 632 | + REG_ASSETS_URL . 'espresso_attendees_admin.css', |
|
| 633 | + array('ee-admin-css'), |
|
| 634 | + EVENT_ESPRESSO_VERSION |
|
| 635 | + ); |
|
| 636 | + wp_enqueue_style('espresso_att'); |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + public function load_scripts_styles_new_registration() |
|
| 641 | + { |
|
| 642 | + wp_register_script( |
|
| 643 | + 'ee-spco-for-admin', |
|
| 644 | + REG_ASSETS_URL . 'spco_for_admin.js', |
|
| 645 | + array('underscore', 'jquery'), |
|
| 646 | + EVENT_ESPRESSO_VERSION, |
|
| 647 | + true |
|
| 648 | + ); |
|
| 649 | + wp_enqueue_script('ee-spco-for-admin'); |
|
| 650 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 651 | + EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
| 652 | + EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
| 653 | + EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
| 658 | + { |
|
| 659 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
| 664 | + { |
|
| 665 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + |
|
| 669 | + protected function _set_list_table_views_default() |
|
| 670 | + { |
|
| 671 | + //for notification related bulk actions we need to make sure only active messengers have an option. |
|
| 672 | + EED_Messages::set_autoloaders(); |
|
| 673 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 674 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 675 | + $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
| 676 | + //key= bulk_action_slug, value= message type. |
|
| 677 | + $match_array = array( |
|
| 678 | + 'approve_registration' => 'registration', |
|
| 679 | + 'decline_registration' => 'declined_registration', |
|
| 680 | + 'pending_registration' => 'pending_approval', |
|
| 681 | + 'no_approve_registration' => 'not_approved_registration', |
|
| 682 | + 'cancel_registration' => 'cancelled_registration', |
|
| 683 | + ); |
|
| 684 | + $can_send = EE_Registry::instance()->CAP->current_user_can( |
|
| 685 | + 'ee_send_message', |
|
| 686 | + 'batch_send_messages' |
|
| 687 | + ); |
|
| 688 | + /** setup reg status bulk actions **/ |
|
| 689 | + $def_reg_status_actions['approve_registration'] = __('Approve Registrations', 'event_espresso'); |
|
| 690 | + if ($can_send && in_array($match_array['approve_registration'], $active_mts, true)) { |
|
| 691 | + $def_reg_status_actions['approve_and_notify_registration'] = __('Approve and Notify Registrations', |
|
| 692 | + 'event_espresso'); |
|
| 693 | + } |
|
| 694 | + $def_reg_status_actions['decline_registration'] = __('Decline Registrations', 'event_espresso'); |
|
| 695 | + if ($can_send && in_array($match_array['decline_registration'], $active_mts, true)) { |
|
| 696 | + $def_reg_status_actions['decline_and_notify_registration'] = __('Decline and Notify Registrations', |
|
| 697 | + 'event_espresso'); |
|
| 698 | + } |
|
| 699 | + $def_reg_status_actions['pending_registration'] = __('Set Registrations to Pending Payment', 'event_espresso'); |
|
| 700 | + if ($can_send && in_array($match_array['pending_registration'], $active_mts, true)) { |
|
| 701 | + $def_reg_status_actions['pending_and_notify_registration'] = __( |
|
| 702 | + 'Set Registrations to Pending Payment and Notify', |
|
| 703 | + 'event_espresso' |
|
| 704 | + ); |
|
| 705 | + } |
|
| 706 | + $def_reg_status_actions['no_approve_registration'] = __('Set Registrations to Not Approved', 'event_espresso'); |
|
| 707 | + if ($can_send && in_array($match_array['no_approve_registration'], $active_mts, true)) { |
|
| 708 | + $def_reg_status_actions['no_approve_and_notify_registration'] = __( |
|
| 709 | + 'Set Registrations to Not Approved and Notify', |
|
| 710 | + 'event_espresso' |
|
| 711 | + ); |
|
| 712 | + } |
|
| 713 | + $def_reg_status_actions['cancel_registration'] = __('Cancel Registrations', 'event_espresso'); |
|
| 714 | + if ($can_send && in_array($match_array['cancel_registration'], $active_mts, true)) { |
|
| 715 | + $def_reg_status_actions['cancel_and_notify_registration'] = __( |
|
| 716 | + 'Cancel Registrations and Notify', |
|
| 717 | + 'event_espresso' |
|
| 718 | + ); |
|
| 719 | + } |
|
| 720 | + $def_reg_status_actions = apply_filters( |
|
| 721 | + 'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array', |
|
| 722 | + $def_reg_status_actions, |
|
| 723 | + $active_mts |
|
| 724 | + ); |
|
| 725 | + |
|
| 726 | + $this->_views = array( |
|
| 727 | + 'all' => array( |
|
| 728 | + 'slug' => 'all', |
|
| 729 | + 'label' => esc_html__('View All Registrations', 'event_espresso'), |
|
| 730 | + 'count' => 0, |
|
| 731 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 732 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 733 | + )), |
|
| 734 | + ), |
|
| 735 | + 'month' => array( |
|
| 736 | + 'slug' => 'month', |
|
| 737 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 738 | + 'count' => 0, |
|
| 739 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 740 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 741 | + )), |
|
| 742 | + ), |
|
| 743 | + 'today' => array( |
|
| 744 | + 'slug' => 'today', |
|
| 745 | + 'label' => sprintf( |
|
| 746 | + esc_html__('Today - %s', 'event_espresso'), |
|
| 747 | + date('M d, Y', current_time('timestamp')) |
|
| 748 | + ), |
|
| 749 | + 'count' => 0, |
|
| 750 | + 'bulk_action' => array_merge($def_reg_status_actions, array( |
|
| 751 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 752 | + )), |
|
| 753 | + ), |
|
| 754 | + ); |
|
| 755 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 756 | + 'ee_delete_registrations', |
|
| 757 | + 'espresso_registrations_delete_registration' |
|
| 758 | + )) { |
|
| 759 | + $this->_views['incomplete'] = array( |
|
| 760 | + 'slug' => 'incomplete', |
|
| 761 | + 'label' => esc_html__('Incomplete', 'event_espresso'), |
|
| 762 | + 'count' => 0, |
|
| 763 | + 'bulk_action' => array( |
|
| 764 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 765 | + ), |
|
| 766 | + ); |
|
| 767 | + $this->_views['trash'] = array( |
|
| 768 | + 'slug' => 'trash', |
|
| 769 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 770 | + 'count' => 0, |
|
| 771 | + 'bulk_action' => array( |
|
| 772 | + 'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'), |
|
| 773 | + 'delete_registrations' => esc_html__('Delete Registrations Permanently', 'event_espresso'), |
|
| 774 | + ), |
|
| 775 | + ); |
|
| 776 | + } |
|
| 777 | + } |
|
| 778 | + |
|
| 779 | + |
|
| 780 | + protected function _set_list_table_views_contact_list() |
|
| 781 | + { |
|
| 782 | + $this->_views = array( |
|
| 783 | + 'in_use' => array( |
|
| 784 | + 'slug' => 'in_use', |
|
| 785 | + 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 786 | + 'count' => 0, |
|
| 787 | + 'bulk_action' => array( |
|
| 788 | + 'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 789 | + ), |
|
| 790 | + ), |
|
| 791 | + ); |
|
| 792 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_contacts', |
|
| 793 | + 'espresso_registrations_trash_attendees') |
|
| 794 | + ) { |
|
| 795 | + $this->_views['trash'] = array( |
|
| 796 | + 'slug' => 'trash', |
|
| 797 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 798 | + 'count' => 0, |
|
| 799 | + 'bulk_action' => array( |
|
| 800 | + 'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 801 | + ), |
|
| 802 | + ); |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + |
|
| 807 | + protected function _registration_legend_items() |
|
| 808 | + { |
|
| 809 | + $fc_items = array( |
|
| 810 | + 'star-icon' => array( |
|
| 811 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 812 | + 'desc' => esc_html__('This is the Primary Registrant', 'event_espresso'), |
|
| 813 | + ), |
|
| 814 | + 'view_details' => array( |
|
| 815 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 816 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 817 | + ), |
|
| 818 | + 'edit_attendee' => array( |
|
| 819 | + 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
|
| 820 | + 'desc' => esc_html__('Edit Contact Details', 'event_espresso'), |
|
| 821 | + ), |
|
| 822 | + 'view_transaction' => array( |
|
| 823 | + 'class' => 'dashicons dashicons-cart', |
|
| 824 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 825 | + ), |
|
| 826 | + 'view_invoice' => array( |
|
| 827 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 828 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 829 | + ), |
|
| 830 | + ); |
|
| 831 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 832 | + 'ee_send_message', |
|
| 833 | + 'espresso_registrations_resend_registration' |
|
| 834 | + )) { |
|
| 835 | + $fc_items['resend_registration'] = array( |
|
| 836 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 837 | + 'desc' => esc_html__('Resend Registration Details', 'event_espresso'), |
|
| 838 | + ); |
|
| 839 | + } else { |
|
| 840 | + $fc_items['blank'] = array('class' => 'blank', 'desc' => ''); |
|
| 841 | + } |
|
| 842 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 843 | + 'ee_read_global_messages', |
|
| 844 | + 'view_filtered_messages' |
|
| 845 | + )) { |
|
| 846 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 847 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 848 | + $fc_items['view_related_messages'] = array( |
|
| 849 | + 'class' => $related_for_icon['css_class'], |
|
| 850 | + 'desc' => $related_for_icon['label'], |
|
| 851 | + ); |
|
| 852 | + } |
|
| 853 | + } |
|
| 854 | + $sc_items = array( |
|
| 855 | + 'approved_status' => array( |
|
| 856 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 857 | + 'desc' => EEH_Template::pretty_status( |
|
| 858 | + EEM_Registration::status_id_approved, |
|
| 859 | + false, |
|
| 860 | + 'sentence' |
|
| 861 | + ), |
|
| 862 | + ), |
|
| 863 | + 'pending_status' => array( |
|
| 864 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 865 | + 'desc' => EEH_Template::pretty_status( |
|
| 866 | + EEM_Registration::status_id_pending_payment, |
|
| 867 | + false, |
|
| 868 | + 'sentence' |
|
| 869 | + ), |
|
| 870 | + ), |
|
| 871 | + 'wait_list' => array( |
|
| 872 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 873 | + 'desc' => EEH_Template::pretty_status( |
|
| 874 | + EEM_Registration::status_id_wait_list, |
|
| 875 | + false, |
|
| 876 | + 'sentence' |
|
| 877 | + ), |
|
| 878 | + ), |
|
| 879 | + 'incomplete_status' => array( |
|
| 880 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
| 881 | + 'desc' => EEH_Template::pretty_status( |
|
| 882 | + EEM_Registration::status_id_incomplete, |
|
| 883 | + false, |
|
| 884 | + 'sentence' |
|
| 885 | + ), |
|
| 886 | + ), |
|
| 887 | + 'not_approved' => array( |
|
| 888 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 889 | + 'desc' => EEH_Template::pretty_status( |
|
| 890 | + EEM_Registration::status_id_not_approved, |
|
| 891 | + false, |
|
| 892 | + 'sentence' |
|
| 893 | + ), |
|
| 894 | + ), |
|
| 895 | + 'declined_status' => array( |
|
| 896 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 897 | + 'desc' => EEH_Template::pretty_status( |
|
| 898 | + EEM_Registration::status_id_declined, |
|
| 899 | + false, |
|
| 900 | + 'sentence' |
|
| 901 | + ), |
|
| 902 | + ), |
|
| 903 | + 'cancelled_status' => array( |
|
| 904 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 905 | + 'desc' => EEH_Template::pretty_status( |
|
| 906 | + EEM_Registration::status_id_cancelled, |
|
| 907 | + false, |
|
| 908 | + 'sentence' |
|
| 909 | + ), |
|
| 910 | + ), |
|
| 911 | + ); |
|
| 912 | + return array_merge($fc_items, $sc_items); |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + |
|
| 916 | + |
|
| 917 | + /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
| 918 | + /** |
|
| 919 | + * @throws \EE_Error |
|
| 920 | + */ |
|
| 921 | + protected function _registrations_overview_list_table() |
|
| 922 | + { |
|
| 923 | + $this->_template_args['admin_page_header'] = ''; |
|
| 924 | + $EVT_ID = ! empty($this->_req_data['event_id']) |
|
| 925 | + ? absint($this->_req_data['event_id']) |
|
| 926 | + : 0; |
|
| 927 | + if ($EVT_ID) { |
|
| 928 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 929 | + 'ee_edit_registrations', |
|
| 930 | + 'espresso_registrations_new_registration', |
|
| 931 | + $EVT_ID |
|
| 932 | + )) { |
|
| 933 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 934 | + 'new_registration', |
|
| 935 | + 'add-registrant', |
|
| 936 | + array('event_id' => $EVT_ID), |
|
| 937 | + 'add-new-h2' |
|
| 938 | + ); |
|
| 939 | + } |
|
| 940 | + $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 941 | + if ($event instanceof EE_Event) { |
|
| 942 | + $this->_template_args['admin_page_header'] = sprintf( |
|
| 943 | + esc_html__( |
|
| 944 | + '%s Viewing registrations for the event: %s%s', |
|
| 945 | + 'event_espresso' |
|
| 946 | + ), |
|
| 947 | + '<h3 style="line-height:1.5em;">', |
|
| 948 | + '<br /><a href="' |
|
| 949 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
| 950 | + array( |
|
| 951 | + 'action' => 'edit', |
|
| 952 | + 'post' => $event->ID(), |
|
| 953 | + ), |
|
| 954 | + EVENTS_ADMIN_URL |
|
| 955 | + ) |
|
| 956 | + . '"> ' |
|
| 957 | + . $event->get('EVT_name') |
|
| 958 | + . ' </a> ', |
|
| 959 | + '</h3>' |
|
| 960 | + ); |
|
| 961 | + } |
|
| 962 | + $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
|
| 963 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 964 | + if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') { |
|
| 965 | + $this->_template_args['admin_page_header'] = substr( |
|
| 966 | + $this->_template_args['admin_page_header'], |
|
| 967 | + 0, |
|
| 968 | + -5 |
|
| 969 | + ); |
|
| 970 | + $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
|
| 971 | + $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 972 | + $this->_template_args['admin_page_header'] .= $datetime->name(); |
|
| 973 | + $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
| 974 | + $this->_template_args['admin_page_header'] .= '</span></h3>'; |
|
| 975 | + } |
|
| 976 | + } |
|
| 977 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
| 978 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * This sets the _registration property for the registration details screen |
|
| 984 | + * |
|
| 985 | + * @access private |
|
| 986 | + * @return bool |
|
| 987 | + */ |
|
| 988 | + private function _set_registration_object() |
|
| 989 | + { |
|
| 990 | + //get out if we've already set the object |
|
| 991 | + if (is_object($this->_registration)) { |
|
| 992 | + return true; |
|
| 993 | + } |
|
| 994 | + $REG = EEM_Registration::instance(); |
|
| 995 | + $REG_ID = ( ! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 996 | + if ($this->_registration = $REG->get_one_by_ID($REG_ID)) { |
|
| 997 | + return true; |
|
| 998 | + } else { |
|
| 999 | + $error_msg = sprintf( |
|
| 1000 | + esc_html__( |
|
| 1001 | + 'An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
| 1002 | + 'event_espresso' |
|
| 1003 | + ), |
|
| 1004 | + $REG_ID |
|
| 1005 | + ); |
|
| 1006 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1007 | + $this->_registration = null; |
|
| 1008 | + return false; |
|
| 1009 | + } |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + |
|
| 1013 | + /** |
|
| 1014 | + * Used to retrieve registrations for the list table. |
|
| 1015 | + * |
|
| 1016 | + * @param int $per_page |
|
| 1017 | + * @param bool $count |
|
| 1018 | + * @param bool $this_month |
|
| 1019 | + * @param bool $today |
|
| 1020 | + * @return EE_Registration[]|int |
|
| 1021 | + * @throws EE_Error |
|
| 1022 | + */ |
|
| 1023 | + public function get_registrations( |
|
| 1024 | + $per_page = 10, |
|
| 1025 | + $count = false, |
|
| 1026 | + $this_month = false, |
|
| 1027 | + $today = false |
|
| 1028 | + ) { |
|
| 1029 | + if ($this_month) { |
|
| 1030 | + $this->_req_data['status'] = 'month'; |
|
| 1031 | + } |
|
| 1032 | + if ($today) { |
|
| 1033 | + $this->_req_data['status'] = 'today'; |
|
| 1034 | + } |
|
| 1035 | + $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
|
| 1036 | + /** |
|
| 1037 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1038 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1039 | + * @see EEM_Base::get_all() |
|
| 1040 | + */ |
|
| 1041 | + $query_params['group_by'] = ''; |
|
| 1042 | + |
|
| 1043 | + return $count |
|
| 1044 | + ? EEM_Registration::instance()->count($query_params) |
|
| 1045 | + /** @type EE_Registration[] */ |
|
| 1046 | + : EEM_Registration::instance()->get_all($query_params); |
|
| 1047 | + } |
|
| 1048 | + |
|
| 1049 | + |
|
| 1050 | + |
|
| 1051 | + /** |
|
| 1052 | + * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
| 1053 | + * Note: this listens to values on the request for some of the query parameters. |
|
| 1054 | + * |
|
| 1055 | + * @param array $request |
|
| 1056 | + * @param int $per_page |
|
| 1057 | + * @param bool $count |
|
| 1058 | + * @return array |
|
| 1059 | + */ |
|
| 1060 | + protected function _get_registration_query_parameters( |
|
| 1061 | + $request = array(), |
|
| 1062 | + $per_page = 10, |
|
| 1063 | + $count = false |
|
| 1064 | + ) { |
|
| 1065 | + |
|
| 1066 | + $query_params = array( |
|
| 1067 | + 0 => $this->_get_where_conditions_for_registrations_query( |
|
| 1068 | + $request |
|
| 1069 | + ), |
|
| 1070 | + 'caps' => EEM_Registration::caps_read_admin, |
|
| 1071 | + 'default_where_conditions' => 'this_model_only', |
|
| 1072 | + ); |
|
| 1073 | + if (! $count) { |
|
| 1074 | + $query_params = array_merge( |
|
| 1075 | + $query_params, |
|
| 1076 | + $this->_get_orderby_for_registrations_query(), |
|
| 1077 | + $this->_get_limit($per_page) |
|
| 1078 | + ); |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + return $query_params; |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + |
|
| 1085 | + /** |
|
| 1086 | + * This will add EVT_ID to the provided $where array for EE model query parameters. |
|
| 1087 | + * |
|
| 1088 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1089 | + * @return array |
|
| 1090 | + */ |
|
| 1091 | + protected function _add_event_id_to_where_conditions(array $request) |
|
| 1092 | + { |
|
| 1093 | + $where = array(); |
|
| 1094 | + if (! empty($request['event_id'])) { |
|
| 1095 | + $where['EVT_ID'] = absint($request['event_id']); |
|
| 1096 | + } |
|
| 1097 | + return $where; |
|
| 1098 | + } |
|
| 1099 | + |
|
| 1100 | + |
|
| 1101 | + /** |
|
| 1102 | + * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
| 1103 | + * |
|
| 1104 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1105 | + * @return array |
|
| 1106 | + */ |
|
| 1107 | + protected function _add_category_id_to_where_conditions(array $request) |
|
| 1108 | + { |
|
| 1109 | + $where = array(); |
|
| 1110 | + if (! empty($request['EVT_CAT']) && (int)$request['EVT_CAT'] !== -1) { |
|
| 1111 | + $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
|
| 1112 | + } |
|
| 1113 | + return $where; |
|
| 1114 | + } |
|
| 1115 | + |
|
| 1116 | + |
|
| 1117 | + /** |
|
| 1118 | + * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
| 1119 | + * |
|
| 1120 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1121 | + * @return array |
|
| 1122 | + */ |
|
| 1123 | + protected function _add_datetime_id_to_where_conditions(array $request) |
|
| 1124 | + { |
|
| 1125 | + $where = array(); |
|
| 1126 | + if (! empty($request['datetime_id'])) { |
|
| 1127 | + $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
|
| 1128 | + } |
|
| 1129 | + if (! empty($request['DTT_ID'])) { |
|
| 1130 | + $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
|
| 1131 | + } |
|
| 1132 | + return $where; |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + |
|
| 1136 | + /** |
|
| 1137 | + * Adds the correct registration status to the where conditions for the registrations query. |
|
| 1138 | + * |
|
| 1139 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1140 | + * @return array |
|
| 1141 | + */ |
|
| 1142 | + protected function _add_registration_status_to_where_conditions(array $request) |
|
| 1143 | + { |
|
| 1144 | + $where = array(); |
|
| 1145 | + $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1146 | + $registration_status = ! empty($request['_reg_status']) |
|
| 1147 | + ? sanitize_text_field($request['_reg_status']) |
|
| 1148 | + : ''; |
|
| 1149 | + |
|
| 1150 | + /* |
|
| 1151 | 1151 | * If filtering by registration status, then we show registrations matching that status. |
| 1152 | 1152 | * If not filtering by specified status, then we show all registrations excluding incomplete registrations |
| 1153 | 1153 | * UNLESS viewing trashed registrations. |
| 1154 | 1154 | */ |
| 1155 | - if (! empty($registration_status)) { |
|
| 1156 | - $where['STS_ID'] = $registration_status; |
|
| 1157 | - } else { |
|
| 1158 | - //make sure we exclude incomplete registrations, but only if not trashed. |
|
| 1159 | - if ($view === 'trash') { |
|
| 1160 | - $where['REG_deleted'] = true; |
|
| 1161 | - } elseif ($view === 'incomplete') { |
|
| 1162 | - $where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 1163 | - } else { |
|
| 1164 | - $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 1165 | - } |
|
| 1166 | - } |
|
| 1167 | - return $where; |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - |
|
| 1171 | - /** |
|
| 1172 | - * Adds any provided date restraints to the where conditions for the registrations query. |
|
| 1173 | - * |
|
| 1174 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1175 | - * @return array |
|
| 1176 | - * @throws EE_Error |
|
| 1177 | - */ |
|
| 1178 | - protected function _add_date_to_where_conditions(array $request) |
|
| 1179 | - { |
|
| 1180 | - $where = array(); |
|
| 1181 | - $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1182 | - $month_range = ! empty($request['month_range']) |
|
| 1183 | - ? sanitize_text_field($request['month_range']) |
|
| 1184 | - : ''; |
|
| 1185 | - $retrieve_for_today = $view === 'today'; |
|
| 1186 | - $retrieve_for_this_month = $view === 'month'; |
|
| 1187 | - |
|
| 1188 | - if ($retrieve_for_today) { |
|
| 1189 | - $now = date('Y-m-d', current_time('timestamp')); |
|
| 1190 | - $where['REG_date'] = array( |
|
| 1191 | - 'BETWEEN', |
|
| 1192 | - array( |
|
| 1193 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1194 | - 'REG_date', |
|
| 1195 | - $now . ' 00:00:00', |
|
| 1196 | - 'Y-m-d H:i:s' |
|
| 1197 | - ), |
|
| 1198 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1199 | - 'REG_date', |
|
| 1200 | - $now . ' 23:59:59', |
|
| 1201 | - 'Y-m-d H:i:s' |
|
| 1202 | - ), |
|
| 1203 | - ), |
|
| 1204 | - ); |
|
| 1205 | - } elseif ($retrieve_for_this_month) { |
|
| 1206 | - $current_year_and_month = date('Y-m', current_time('timestamp')); |
|
| 1207 | - $days_this_month = date('t', current_time('timestamp')); |
|
| 1208 | - $where['REG_date'] = array( |
|
| 1209 | - 'BETWEEN', |
|
| 1210 | - array( |
|
| 1211 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1212 | - 'REG_date', |
|
| 1213 | - $current_year_and_month . '-01 00:00:00', |
|
| 1214 | - 'Y-m-d H:i:s' |
|
| 1215 | - ), |
|
| 1216 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1217 | - 'REG_date', |
|
| 1218 | - $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 1219 | - 'Y-m-d H:i:s' |
|
| 1220 | - ), |
|
| 1221 | - ), |
|
| 1222 | - ); |
|
| 1223 | - } elseif ($month_range) { |
|
| 1224 | - $pieces = explode(' ', $month_range, 3); |
|
| 1225 | - $month_requested = ! empty($pieces[0]) |
|
| 1226 | - ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
| 1227 | - : ''; |
|
| 1228 | - $year_requested = ! empty($pieces[1]) |
|
| 1229 | - ? $pieces[1] |
|
| 1230 | - : ''; |
|
| 1231 | - //if there is not a month or year then we can't go further |
|
| 1232 | - if ($month_requested && $year_requested) { |
|
| 1233 | - $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 1234 | - $where['REG_date'] = array( |
|
| 1235 | - 'BETWEEN', |
|
| 1236 | - array( |
|
| 1237 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1238 | - 'REG_date', |
|
| 1239 | - $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 1240 | - 'Y-m-d H:i:s' |
|
| 1241 | - ), |
|
| 1242 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1243 | - 'REG_date', |
|
| 1244 | - $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 1245 | - 'Y-m-d H:i:s' |
|
| 1246 | - ), |
|
| 1247 | - ), |
|
| 1248 | - ); |
|
| 1249 | - } |
|
| 1250 | - } |
|
| 1251 | - return $where; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - |
|
| 1255 | - /** |
|
| 1256 | - * Adds any provided search restraints to the where conditions for the registrations query |
|
| 1257 | - * |
|
| 1258 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1259 | - * @return array |
|
| 1260 | - */ |
|
| 1261 | - protected function _add_search_to_where_conditions(array $request) |
|
| 1262 | - { |
|
| 1263 | - $where = array(); |
|
| 1264 | - if (! empty($request['s'])) { |
|
| 1265 | - $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
| 1266 | - $where['OR*search_conditions'] = array( |
|
| 1267 | - 'Event.EVT_name' => array('LIKE', $search_string), |
|
| 1268 | - 'Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1269 | - 'Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1270 | - 'Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1271 | - 'Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1272 | - 'Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1273 | - 'Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1274 | - 'Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1275 | - 'Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1276 | - 'Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1277 | - 'Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1278 | - 'REG_final_price' => array('LIKE', $search_string), |
|
| 1279 | - 'REG_code' => array('LIKE', $search_string), |
|
| 1280 | - 'REG_count' => array('LIKE', $search_string), |
|
| 1281 | - 'REG_group_size' => array('LIKE', $search_string), |
|
| 1282 | - 'Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1283 | - 'Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1284 | - 'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 1285 | - ); |
|
| 1286 | - } |
|
| 1287 | - return $where; |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - |
|
| 1291 | - /** |
|
| 1292 | - * Sets up the where conditions for the registrations query. |
|
| 1293 | - * |
|
| 1294 | - * @param array $request |
|
| 1295 | - * @return array |
|
| 1296 | - * @throws EE_Error |
|
| 1297 | - */ |
|
| 1298 | - protected function _get_where_conditions_for_registrations_query($request) |
|
| 1299 | - { |
|
| 1300 | - return apply_filters( |
|
| 1301 | - 'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', |
|
| 1302 | - array_merge( |
|
| 1303 | - $this->_add_event_id_to_where_conditions($request), |
|
| 1304 | - $this->_add_category_id_to_where_conditions($request), |
|
| 1305 | - $this->_add_datetime_id_to_where_conditions($request), |
|
| 1306 | - $this->_add_registration_status_to_where_conditions($request), |
|
| 1307 | - $this->_add_date_to_where_conditions($request), |
|
| 1308 | - $this->_add_search_to_where_conditions($request) |
|
| 1309 | - ), |
|
| 1310 | - $request |
|
| 1311 | - ); |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - |
|
| 1315 | - /** |
|
| 1316 | - * Sets up the orderby for the registrations query. |
|
| 1317 | - * |
|
| 1318 | - * @return array |
|
| 1319 | - */ |
|
| 1320 | - protected function _get_orderby_for_registrations_query() |
|
| 1321 | - { |
|
| 1322 | - $orderby_field = ! empty($this->_req_data['orderby']) |
|
| 1323 | - ? sanitize_text_field($this->_req_data['orderby']) |
|
| 1324 | - : ''; |
|
| 1325 | - switch ($orderby_field) { |
|
| 1326 | - case '_REG_ID': |
|
| 1327 | - $orderby_field = 'REG_ID'; |
|
| 1328 | - break; |
|
| 1329 | - case '_Reg_status': |
|
| 1330 | - $orderby_field = 'STS_ID'; |
|
| 1331 | - break; |
|
| 1332 | - case 'ATT_fname': |
|
| 1333 | - $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname'); |
|
| 1334 | - break; |
|
| 1335 | - case 'ATT_lname': |
|
| 1336 | - $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname'); |
|
| 1337 | - break; |
|
| 1338 | - case 'event_name': |
|
| 1339 | - $orderby_field = 'Event.EVT_name'; |
|
| 1340 | - break; |
|
| 1341 | - case 'DTT_EVT_start': |
|
| 1342 | - $orderby_field = 'Event.Datetime.DTT_EVT_start'; |
|
| 1343 | - break; |
|
| 1344 | - default: //'REG_date' |
|
| 1345 | - $orderby_field = 'REG_date'; |
|
| 1346 | - } |
|
| 1347 | - |
|
| 1348 | - //order |
|
| 1349 | - $order = ! empty($this->_req_data['order']) |
|
| 1350 | - ? sanitize_text_field($this->_req_data['order']) |
|
| 1351 | - : 'DESC'; |
|
| 1352 | - |
|
| 1353 | - //mutate orderby_field |
|
| 1354 | - $orderby_field = array_combine( |
|
| 1355 | - (array) $orderby_field, |
|
| 1356 | - array_fill(0, count($orderby_field), $order) |
|
| 1357 | - ); |
|
| 1358 | - return array('order_by' => $orderby_field); |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - |
|
| 1362 | - /** |
|
| 1363 | - * Sets up the limit for the registrations query. |
|
| 1364 | - * |
|
| 1365 | - * @param $per_page |
|
| 1366 | - * @return array |
|
| 1367 | - */ |
|
| 1368 | - protected function _get_limit($per_page) |
|
| 1369 | - { |
|
| 1370 | - $current_page = ! empty($this->_req_data['paged']) |
|
| 1371 | - ? absint($this->_req_data['paged']) |
|
| 1372 | - : 1; |
|
| 1373 | - $per_page = ! empty($this->_req_data['perpage']) |
|
| 1374 | - ? $this->_req_data['perpage'] |
|
| 1375 | - : $per_page; |
|
| 1376 | - |
|
| 1377 | - //-1 means return all results so get out if that's set. |
|
| 1378 | - if ((int)$per_page === -1) { |
|
| 1379 | - return array(); |
|
| 1380 | - } |
|
| 1381 | - $per_page = absint($per_page); |
|
| 1382 | - $offset = ($current_page - 1) * $per_page; |
|
| 1383 | - return array('limit' => array($offset, $per_page)); |
|
| 1384 | - } |
|
| 1385 | - |
|
| 1386 | - |
|
| 1387 | - public function get_registration_status_array() |
|
| 1388 | - { |
|
| 1389 | - return self::$_reg_status; |
|
| 1390 | - } |
|
| 1391 | - |
|
| 1392 | - |
|
| 1393 | - |
|
| 1394 | - |
|
| 1395 | - /*************************************** REGISTRATION DETAILS ***************************************/ |
|
| 1396 | - /** |
|
| 1397 | - * generates HTML for the View Registration Details Admin page |
|
| 1398 | - * |
|
| 1399 | - * @access protected |
|
| 1400 | - * @return void |
|
| 1401 | - * @throws DomainException |
|
| 1402 | - * @throws EE_Error |
|
| 1403 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1404 | - */ |
|
| 1405 | - protected function _registration_details() |
|
| 1406 | - { |
|
| 1407 | - $this->_template_args = array(); |
|
| 1408 | - $this->_set_registration_object(); |
|
| 1409 | - if (is_object($this->_registration)) { |
|
| 1410 | - $transaction = $this->_registration->transaction() |
|
| 1411 | - ? $this->_registration->transaction() |
|
| 1412 | - : EE_Transaction::new_instance(); |
|
| 1413 | - $this->_session = $transaction->session_data(); |
|
| 1414 | - $event_id = $this->_registration->event_ID(); |
|
| 1415 | - $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
| 1416 | - $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso'); |
|
| 1417 | - $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
| 1418 | - $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 1419 | - $this->_template_args['grand_total'] = $transaction->total(); |
|
| 1420 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1421 | - // link back to overview |
|
| 1422 | - $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
| 1423 | - $this->_template_args['registration'] = $this->_registration; |
|
| 1424 | - $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1425 | - array( |
|
| 1426 | - 'action' => 'default', |
|
| 1427 | - 'event_id' => $event_id, |
|
| 1428 | - ), |
|
| 1429 | - REG_ADMIN_URL |
|
| 1430 | - ); |
|
| 1431 | - $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1432 | - array( |
|
| 1433 | - 'action' => 'default', |
|
| 1434 | - 'EVT_ID' => $event_id, |
|
| 1435 | - 'page' => 'espresso_transactions', |
|
| 1436 | - ), |
|
| 1437 | - admin_url('admin.php') |
|
| 1438 | - ); |
|
| 1439 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1440 | - array( |
|
| 1441 | - 'page' => 'espresso_events', |
|
| 1442 | - 'action' => 'edit', |
|
| 1443 | - 'post' => $event_id, |
|
| 1444 | - ), |
|
| 1445 | - admin_url('admin.php') |
|
| 1446 | - ); |
|
| 1447 | - //next and previous links |
|
| 1448 | - $next_reg = $this->_registration->next( |
|
| 1449 | - null, |
|
| 1450 | - array(), |
|
| 1451 | - 'REG_ID' |
|
| 1452 | - ); |
|
| 1453 | - $this->_template_args['next_registration'] = $next_reg |
|
| 1454 | - ? $this->_next_link( |
|
| 1455 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 1456 | - array( |
|
| 1457 | - 'action' => 'view_registration', |
|
| 1458 | - '_REG_ID' => $next_reg['REG_ID'], |
|
| 1459 | - ), |
|
| 1460 | - REG_ADMIN_URL |
|
| 1461 | - ), |
|
| 1462 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 1463 | - ) |
|
| 1464 | - : ''; |
|
| 1465 | - $previous_reg = $this->_registration->previous( |
|
| 1466 | - null, |
|
| 1467 | - array(), |
|
| 1468 | - 'REG_ID' |
|
| 1469 | - ); |
|
| 1470 | - $this->_template_args['previous_registration'] = $previous_reg |
|
| 1471 | - ? $this->_previous_link( |
|
| 1472 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 1473 | - array( |
|
| 1474 | - 'action' => 'view_registration', |
|
| 1475 | - '_REG_ID' => $previous_reg['REG_ID'], |
|
| 1476 | - ), |
|
| 1477 | - REG_ADMIN_URL |
|
| 1478 | - ), |
|
| 1479 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 1480 | - ) |
|
| 1481 | - : ''; |
|
| 1482 | - // grab header |
|
| 1483 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1484 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1485 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 1486 | - $template_path, |
|
| 1487 | - $this->_template_args, |
|
| 1488 | - true |
|
| 1489 | - ); |
|
| 1490 | - } else { |
|
| 1491 | - $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
|
| 1492 | - } |
|
| 1493 | - // the details template wrapper |
|
| 1494 | - $this->display_admin_page_with_sidebar(); |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - |
|
| 1498 | - protected function _registration_details_metaboxes() |
|
| 1499 | - { |
|
| 1500 | - do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
| 1501 | - $this->_set_registration_object(); |
|
| 1502 | - $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
| 1503 | - add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'), |
|
| 1504 | - array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1505 | - add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'), |
|
| 1506 | - array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1507 | - if ($attendee instanceof EE_Attendee |
|
| 1508 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 1509 | - 'ee_edit_registration', |
|
| 1510 | - 'edit-reg-questions-mbox' |
|
| 1511 | - ) |
|
| 1512 | - ) { |
|
| 1513 | - add_meta_box( |
|
| 1514 | - 'edit-reg-questions-mbox', |
|
| 1515 | - esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 1516 | - array($this, '_reg_questions_meta_box'), |
|
| 1517 | - $this->wp_page_slug, |
|
| 1518 | - 'normal', |
|
| 1519 | - 'high' |
|
| 1520 | - ); |
|
| 1521 | - } |
|
| 1522 | - add_meta_box( |
|
| 1523 | - 'edit-reg-registrant-mbox', |
|
| 1524 | - esc_html__('Contact Details', 'event_espresso'), |
|
| 1525 | - array($this, '_reg_registrant_side_meta_box'), |
|
| 1526 | - $this->wp_page_slug, |
|
| 1527 | - 'side', |
|
| 1528 | - 'high' |
|
| 1529 | - ); |
|
| 1530 | - if ($this->_registration->group_size() > 1) { |
|
| 1531 | - add_meta_box( |
|
| 1532 | - 'edit-reg-attendees-mbox', |
|
| 1533 | - esc_html__('Other Registrations in this Transaction', 'event_espresso'), |
|
| 1534 | - array($this, '_reg_attendees_meta_box'), |
|
| 1535 | - $this->wp_page_slug, |
|
| 1536 | - 'normal', |
|
| 1537 | - 'high' |
|
| 1538 | - ); |
|
| 1539 | - } |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - |
|
| 1543 | - /** |
|
| 1544 | - * set_reg_status_buttons_metabox |
|
| 1545 | - * |
|
| 1546 | - * @access protected |
|
| 1547 | - * @return string |
|
| 1548 | - * @throws \EE_Error |
|
| 1549 | - */ |
|
| 1550 | - public function set_reg_status_buttons_metabox() |
|
| 1551 | - { |
|
| 1552 | - $this->_set_registration_object(); |
|
| 1553 | - $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
| 1554 | - echo $change_reg_status_form->form_open( |
|
| 1555 | - self::add_query_args_and_nonce( |
|
| 1556 | - array( |
|
| 1557 | - 'action' => 'change_reg_status', |
|
| 1558 | - ), |
|
| 1559 | - REG_ADMIN_URL |
|
| 1560 | - ) |
|
| 1561 | - ); |
|
| 1562 | - echo $change_reg_status_form->get_html(); |
|
| 1563 | - echo $change_reg_status_form->form_close(); |
|
| 1564 | - } |
|
| 1565 | - |
|
| 1566 | - |
|
| 1567 | - |
|
| 1568 | - /** |
|
| 1569 | - * @return EE_Form_Section_Proper |
|
| 1570 | - * @throws EE_Error |
|
| 1571 | - */ |
|
| 1572 | - protected function _generate_reg_status_change_form() |
|
| 1573 | - { |
|
| 1574 | - return new EE_Form_Section_Proper(array( |
|
| 1575 | - 'name' => 'reg_status_change_form', |
|
| 1576 | - 'html_id' => 'reg-status-change-form', |
|
| 1577 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1578 | - 'subsections' => array( |
|
| 1579 | - 'return' => new EE_Hidden_Input(array( |
|
| 1580 | - 'name' => 'return', |
|
| 1581 | - 'default' => 'view_registration', |
|
| 1582 | - )), |
|
| 1583 | - 'REG_ID' => new EE_Hidden_Input(array( |
|
| 1584 | - 'name' => 'REG_ID', |
|
| 1585 | - 'default' => $this->_registration->ID(), |
|
| 1586 | - )), |
|
| 1587 | - 'current_status' => new EE_Form_Section_HTML( |
|
| 1588 | - EEH_HTML::tr( |
|
| 1589 | - EEH_HTML::th( |
|
| 1590 | - EEH_HTML::label( |
|
| 1591 | - EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso') |
|
| 1592 | - ) |
|
| 1593 | - ) |
|
| 1594 | - ) |
|
| 1595 | - . EEH_HTML::td( |
|
| 1596 | - EEH_HTML::strong( |
|
| 1597 | - $this->_registration->pretty_status(), |
|
| 1598 | - '', |
|
| 1599 | - 'status-' . $this->_registration->status_ID(), |
|
| 1600 | - 'line-height: 1em; font-size: 1.5em; font-weight: bold;' |
|
| 1601 | - ) |
|
| 1602 | - ) |
|
| 1603 | - ) |
|
| 1604 | - ), |
|
| 1605 | - 'reg_status' => new EE_Select_Input( |
|
| 1606 | - $this->_get_reg_statuses(), |
|
| 1607 | - array( |
|
| 1608 | - 'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'), |
|
| 1609 | - 'default' => $this->_registration->status_ID(), |
|
| 1610 | - ) |
|
| 1611 | - ), |
|
| 1612 | - 'send_notifications' => new EE_Yes_No_Input( |
|
| 1613 | - array( |
|
| 1614 | - 'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'), |
|
| 1615 | - 'default' => false, |
|
| 1616 | - 'html_help_text' => esc_html__( |
|
| 1617 | - 'If set to "Yes", then the related messages will be sent to the registrant.', |
|
| 1618 | - 'event_espresso' |
|
| 1619 | - ), |
|
| 1620 | - ) |
|
| 1621 | - ), |
|
| 1622 | - 'submit' => new EE_Submit_Input( |
|
| 1623 | - array( |
|
| 1624 | - 'html_class' => 'button-primary', |
|
| 1625 | - 'html_label_text' => ' ', |
|
| 1626 | - 'default' => esc_html__('Update Registration Status', 'event_espresso'), |
|
| 1627 | - ) |
|
| 1628 | - ), |
|
| 1629 | - ), |
|
| 1630 | - )); |
|
| 1631 | - } |
|
| 1632 | - |
|
| 1633 | - |
|
| 1634 | - /** |
|
| 1635 | - * Returns an array of all the buttons for the various statuses and switch status actions |
|
| 1636 | - * |
|
| 1637 | - * @return array |
|
| 1638 | - * @throws EE_Error |
|
| 1639 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1640 | - */ |
|
| 1641 | - protected function _get_reg_statuses() |
|
| 1642 | - { |
|
| 1643 | - $reg_status_array = EEM_Registration::instance()->reg_status_array(); |
|
| 1644 | - unset ($reg_status_array[EEM_Registration::status_id_incomplete]); |
|
| 1645 | - // get current reg status |
|
| 1646 | - $current_status = $this->_registration->status_ID(); |
|
| 1647 | - // is registration for free event? This will determine whether to display the pending payment option |
|
| 1648 | - if ( |
|
| 1649 | - $current_status !== EEM_Registration::status_id_pending_payment |
|
| 1650 | - && $this->_registration->transaction()->is_free() |
|
| 1651 | - ) { |
|
| 1652 | - unset($reg_status_array[EEM_Registration::status_id_pending_payment]); |
|
| 1653 | - } |
|
| 1654 | - return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence'); |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - |
|
| 1658 | - |
|
| 1659 | - /** |
|
| 1660 | - * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
| 1661 | - * |
|
| 1662 | - * @param bool $status REG status given for changing registrations to. |
|
| 1663 | - * @param bool $notify Whether to send messages notifications or not. |
|
| 1664 | - * @return array (array with reg_id(s) updated and whether update was successful. |
|
| 1665 | - * @throws \EE_Error |
|
| 1666 | - */ |
|
| 1667 | - protected function _set_registration_status_from_request($status = false, $notify = false) |
|
| 1668 | - { |
|
| 1669 | - if (isset($this->_req_data['reg_status_change_form'])) { |
|
| 1670 | - $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 1671 | - ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
| 1672 | - } else { |
|
| 1673 | - $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array(); |
|
| 1674 | - } |
|
| 1675 | - $success = $this->_set_registration_status($REG_IDs, $status); |
|
| 1676 | - //notify? |
|
| 1677 | - if ($success |
|
| 1678 | - && $notify |
|
| 1679 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 1680 | - 'ee_send_message', |
|
| 1681 | - 'espresso_registrations_resend_registration' |
|
| 1682 | - ) |
|
| 1683 | - ) { |
|
| 1684 | - $this->_process_resend_registration(); |
|
| 1685 | - } |
|
| 1686 | - return $success; |
|
| 1687 | - } |
|
| 1688 | - |
|
| 1689 | - |
|
| 1690 | - |
|
| 1691 | - /** |
|
| 1692 | - * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
| 1693 | - * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
| 1694 | - * |
|
| 1695 | - * @param array $REG_IDs |
|
| 1696 | - * @param bool $status |
|
| 1697 | - * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
| 1698 | - * @throws \RuntimeException |
|
| 1699 | - * @throws \EE_Error |
|
| 1700 | - * the array of updated registrations). |
|
| 1701 | - * @throws EE_Error |
|
| 1702 | - * @throws RuntimeException |
|
| 1703 | - */ |
|
| 1704 | - protected function _set_registration_status($REG_IDs = array(), $status = false) |
|
| 1705 | - { |
|
| 1706 | - $success = false; |
|
| 1707 | - // typecast $REG_IDs |
|
| 1708 | - $REG_IDs = (array)$REG_IDs; |
|
| 1709 | - if ( ! empty($REG_IDs)) { |
|
| 1710 | - $success = true; |
|
| 1711 | - // set default status if none is passed |
|
| 1712 | - $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
|
| 1713 | - // sanitize $REG_IDs |
|
| 1714 | - $REG_IDs = array_filter($REG_IDs, 'absint'); |
|
| 1715 | - //loop through REG_ID's and change status |
|
| 1716 | - foreach ($REG_IDs as $REG_ID) { |
|
| 1717 | - $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 1718 | - if ($registration instanceof EE_Registration) { |
|
| 1719 | - $registration->set_status($status); |
|
| 1720 | - $result = $registration->save(); |
|
| 1721 | - // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
| 1722 | - $success = $result !== false ? $success : false; |
|
| 1723 | - } |
|
| 1724 | - } |
|
| 1725 | - } |
|
| 1726 | - //reset _req_data['_REG_ID'] for any potential future messages notifications |
|
| 1727 | - $this->_req_data['_REG_ID'] = $REG_IDs; |
|
| 1728 | - //return $success and processed registrations |
|
| 1729 | - return array('REG_ID' => $REG_IDs, 'success' => $success); |
|
| 1730 | - } |
|
| 1731 | - |
|
| 1732 | - |
|
| 1733 | - /** |
|
| 1734 | - * Common logic for setting up success message and redirecting to appropriate route |
|
| 1735 | - * |
|
| 1736 | - * @param string $STS_ID status id for the registration changed to |
|
| 1737 | - * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
| 1738 | - * @return void |
|
| 1739 | - */ |
|
| 1740 | - protected function _reg_status_change_return($STS_ID, $notify = false) |
|
| 1741 | - { |
|
| 1742 | - $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
| 1743 | - : array('success' => false); |
|
| 1744 | - $success = isset($result['success']) && $result['success']; |
|
| 1745 | - //setup success message |
|
| 1746 | - if ($success) { |
|
| 1747 | - if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
| 1748 | - $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'), |
|
| 1749 | - EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1750 | - } else { |
|
| 1751 | - $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'), |
|
| 1752 | - EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1753 | - } |
|
| 1754 | - EE_Error::add_success($msg); |
|
| 1755 | - } else { |
|
| 1756 | - EE_Error::add_error( |
|
| 1757 | - esc_html__( |
|
| 1758 | - 'Something went wrong, and the status was not changed', |
|
| 1759 | - 'event_espresso' |
|
| 1760 | - ), __FILE__, __LINE__, __FUNCTION__ |
|
| 1761 | - ); |
|
| 1762 | - } |
|
| 1763 | - if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') { |
|
| 1764 | - $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
|
| 1765 | - } else { |
|
| 1766 | - $route = array('action' => 'default'); |
|
| 1767 | - } |
|
| 1768 | - //unset nonces |
|
| 1769 | - foreach ($this->_req_data as $ref => $value) { |
|
| 1770 | - if (strpos($ref, 'nonce') !== false) { |
|
| 1771 | - unset($this->_req_data[$ref]); |
|
| 1772 | - continue; |
|
| 1773 | - } |
|
| 1774 | - $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 1775 | - $this->_req_data[$ref] = $value; |
|
| 1776 | - } |
|
| 1777 | - //merge request vars so that the reloaded list table contains any existing filter query params |
|
| 1778 | - $route = array_merge($this->_req_data, $route); |
|
| 1779 | - $this->_redirect_after_action($success, '', '', $route, true); |
|
| 1780 | - } |
|
| 1781 | - |
|
| 1782 | - |
|
| 1783 | - /** |
|
| 1784 | - * incoming reg status change from reg details page. |
|
| 1785 | - * |
|
| 1786 | - * @return void |
|
| 1787 | - */ |
|
| 1788 | - protected function _change_reg_status() |
|
| 1789 | - { |
|
| 1790 | - $this->_req_data['return'] = 'view_registration'; |
|
| 1791 | - //set notify based on whether the send notifications toggle is set or not |
|
| 1792 | - $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
|
| 1793 | - //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
|
| 1794 | - $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
|
| 1795 | - ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
|
| 1796 | - switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
|
| 1797 | - case EEM_Registration::status_id_approved : |
|
| 1798 | - case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') : |
|
| 1799 | - $this->approve_registration($notify); |
|
| 1800 | - break; |
|
| 1801 | - case EEM_Registration::status_id_pending_payment : |
|
| 1802 | - case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') : |
|
| 1803 | - $this->pending_registration($notify); |
|
| 1804 | - break; |
|
| 1805 | - case EEM_Registration::status_id_not_approved : |
|
| 1806 | - case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') : |
|
| 1807 | - $this->not_approve_registration($notify); |
|
| 1808 | - break; |
|
| 1809 | - case EEM_Registration::status_id_declined : |
|
| 1810 | - case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') : |
|
| 1811 | - $this->decline_registration($notify); |
|
| 1812 | - break; |
|
| 1813 | - case EEM_Registration::status_id_cancelled : |
|
| 1814 | - case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') : |
|
| 1815 | - $this->cancel_registration($notify); |
|
| 1816 | - break; |
|
| 1817 | - case EEM_Registration::status_id_wait_list : |
|
| 1818 | - case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') : |
|
| 1819 | - $this->wait_list_registration($notify); |
|
| 1820 | - break; |
|
| 1821 | - case EEM_Registration::status_id_incomplete : |
|
| 1822 | - default : |
|
| 1823 | - $result['success'] = false; |
|
| 1824 | - unset($this->_req_data['return']); |
|
| 1825 | - $this->_reg_status_change_return('', false); |
|
| 1826 | - break; |
|
| 1827 | - } |
|
| 1828 | - } |
|
| 1829 | - |
|
| 1830 | - |
|
| 1831 | - /** |
|
| 1832 | - * approve_registration |
|
| 1833 | - * |
|
| 1834 | - * @access protected |
|
| 1835 | - * @param bool $notify whether or not to notify the registrant about their approval. |
|
| 1836 | - * @return void |
|
| 1837 | - */ |
|
| 1838 | - protected function approve_registration($notify = false) |
|
| 1839 | - { |
|
| 1840 | - $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - |
|
| 1844 | - /** |
|
| 1845 | - * decline_registration |
|
| 1846 | - * |
|
| 1847 | - * @access protected |
|
| 1848 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1849 | - * @return void |
|
| 1850 | - */ |
|
| 1851 | - protected function decline_registration($notify = false) |
|
| 1852 | - { |
|
| 1853 | - $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
| 1854 | - } |
|
| 1855 | - |
|
| 1856 | - |
|
| 1857 | - /** |
|
| 1858 | - * cancel_registration |
|
| 1859 | - * |
|
| 1860 | - * @access protected |
|
| 1861 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1862 | - * @return void |
|
| 1863 | - */ |
|
| 1864 | - protected function cancel_registration($notify = false) |
|
| 1865 | - { |
|
| 1866 | - $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
| 1867 | - } |
|
| 1868 | - |
|
| 1869 | - |
|
| 1870 | - /** |
|
| 1871 | - * not_approve_registration |
|
| 1872 | - * |
|
| 1873 | - * @access protected |
|
| 1874 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1875 | - * @return void |
|
| 1876 | - */ |
|
| 1877 | - protected function not_approve_registration($notify = false) |
|
| 1878 | - { |
|
| 1879 | - $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
| 1880 | - } |
|
| 1881 | - |
|
| 1882 | - |
|
| 1883 | - /** |
|
| 1884 | - * decline_registration |
|
| 1885 | - * |
|
| 1886 | - * @access protected |
|
| 1887 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1888 | - * @return void |
|
| 1889 | - */ |
|
| 1890 | - protected function pending_registration($notify = false) |
|
| 1891 | - { |
|
| 1892 | - $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
| 1893 | - } |
|
| 1894 | - |
|
| 1895 | - |
|
| 1896 | - /** |
|
| 1897 | - * waitlist_registration |
|
| 1898 | - * |
|
| 1899 | - * @access protected |
|
| 1900 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1901 | - * @return void |
|
| 1902 | - */ |
|
| 1903 | - protected function wait_list_registration($notify = false) |
|
| 1904 | - { |
|
| 1905 | - $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
| 1906 | - } |
|
| 1907 | - |
|
| 1908 | - |
|
| 1909 | - /** |
|
| 1910 | - * generates HTML for the Registration main meta box |
|
| 1911 | - * |
|
| 1912 | - * @access public |
|
| 1913 | - * @return void |
|
| 1914 | - * @throws DomainException |
|
| 1915 | - * @throws EE_Error |
|
| 1916 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1917 | - */ |
|
| 1918 | - public function _reg_details_meta_box() |
|
| 1919 | - { |
|
| 1920 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1921 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 1922 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
| 1923 | - $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 1924 | - : EE_Transaction::new_instance(); |
|
| 1925 | - $this->_session = $transaction->session_data(); |
|
| 1926 | - $filters = new EE_Line_Item_Filter_Collection(); |
|
| 1927 | - //$filters->add( new EE_Non_Zero_Line_Item_Filter() ); |
|
| 1928 | - $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
| 1929 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, |
|
| 1930 | - $transaction->total_line_item()); |
|
| 1931 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 1932 | - $line_item_display = new EE_Line_Item_Display('reg_admin_table', |
|
| 1933 | - 'EE_Admin_Table_Registration_Line_Item_Display_Strategy'); |
|
| 1934 | - $this->_template_args['line_item_table'] = $line_item_display->display_line_item( |
|
| 1935 | - $filtered_line_item_tree, |
|
| 1936 | - array('EE_Registration' => $this->_registration) |
|
| 1937 | - ); |
|
| 1938 | - $attendee = $this->_registration->attendee(); |
|
| 1939 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 1940 | - 'ee_read_transaction', |
|
| 1941 | - 'espresso_transactions_view_transaction' |
|
| 1942 | - )) { |
|
| 1943 | - $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link( |
|
| 1944 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 1945 | - array( |
|
| 1946 | - 'action' => 'view_transaction', |
|
| 1947 | - 'TXN_ID' => $transaction->ID(), |
|
| 1948 | - ), |
|
| 1949 | - TXN_ADMIN_URL |
|
| 1950 | - ), |
|
| 1951 | - esc_html__(' View Transaction', 'event_espresso'), |
|
| 1952 | - 'button secondary-button right', |
|
| 1953 | - 'dashicons dashicons-cart' |
|
| 1954 | - ); |
|
| 1955 | - } else { |
|
| 1956 | - $this->_template_args['view_transaction_button'] = ''; |
|
| 1957 | - } |
|
| 1958 | - if ($attendee instanceof EE_Attendee |
|
| 1959 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 1960 | - 'ee_send_message', |
|
| 1961 | - 'espresso_registrations_resend_registration' |
|
| 1962 | - ) |
|
| 1963 | - ) { |
|
| 1964 | - $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link( |
|
| 1965 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 1966 | - array( |
|
| 1967 | - 'action' => 'resend_registration', |
|
| 1968 | - '_REG_ID' => $this->_registration->ID(), |
|
| 1969 | - 'redirect_to' => 'view_registration', |
|
| 1970 | - ), |
|
| 1971 | - REG_ADMIN_URL |
|
| 1972 | - ), |
|
| 1973 | - esc_html__(' Resend Registration', 'event_espresso'), |
|
| 1974 | - 'button secondary-button right', |
|
| 1975 | - 'dashicons dashicons-email-alt' |
|
| 1976 | - ); |
|
| 1977 | - } else { |
|
| 1978 | - $this->_template_args['resend_registration_button'] = ''; |
|
| 1979 | - } |
|
| 1980 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1981 | - $payment = $transaction->get_first_related('Payment'); |
|
| 1982 | - $payment = ! $payment instanceof EE_Payment |
|
| 1983 | - ? EE_Payment::new_instance() |
|
| 1984 | - : $payment; |
|
| 1985 | - $payment_method = $payment->get_first_related('Payment_Method'); |
|
| 1986 | - $payment_method = ! $payment_method instanceof EE_Payment_Method |
|
| 1987 | - ? EE_Payment_Method::new_instance() |
|
| 1988 | - : $payment_method; |
|
| 1989 | - $reg_details = array( |
|
| 1990 | - 'payment_method' => $payment_method->name(), |
|
| 1991 | - 'response_msg' => $payment->gateway_response(), |
|
| 1992 | - 'registration_id' => $this->_registration->get('REG_code'), |
|
| 1993 | - 'registration_session' => $this->_registration->session_ID(), |
|
| 1994 | - 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
| 1995 | - 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
| 1996 | - ); |
|
| 1997 | - if (isset($reg_details['registration_id'])) { |
|
| 1998 | - $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
| 1999 | - $this->_template_args['reg_details']['registration_id']['label'] = esc_html__( |
|
| 2000 | - 'Registration ID', |
|
| 2001 | - 'event_espresso' |
|
| 2002 | - ); |
|
| 2003 | - $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
| 2004 | - } |
|
| 2005 | - if (isset($reg_details['payment_method'])) { |
|
| 2006 | - $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
| 2007 | - $this->_template_args['reg_details']['payment_method']['label'] = esc_html__( |
|
| 2008 | - 'Most Recent Payment Method', |
|
| 2009 | - 'event_espresso' |
|
| 2010 | - ); |
|
| 2011 | - $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
| 2012 | - $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
| 2013 | - $this->_template_args['reg_details']['response_msg']['label'] = esc_html__( |
|
| 2014 | - 'Payment method response', |
|
| 2015 | - 'event_espresso' |
|
| 2016 | - ); |
|
| 2017 | - $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 2018 | - } |
|
| 2019 | - $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
| 2020 | - $this->_template_args['reg_details']['registration_session']['label'] = esc_html__( |
|
| 2021 | - 'Registration Session', |
|
| 2022 | - 'event_espresso' |
|
| 2023 | - ); |
|
| 2024 | - $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
| 2025 | - $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
| 2026 | - $this->_template_args['reg_details']['ip_address']['label'] = esc_html__( |
|
| 2027 | - 'Registration placed from IP', |
|
| 2028 | - 'event_espresso' |
|
| 2029 | - ); |
|
| 2030 | - $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
| 2031 | - $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
| 2032 | - $this->_template_args['reg_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
| 2033 | - 'event_espresso'); |
|
| 2034 | - $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
| 2035 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2036 | - array( |
|
| 2037 | - 'action' => 'default', |
|
| 2038 | - 'event_id' => $this->_registration->event_ID(), |
|
| 2039 | - ), |
|
| 2040 | - REG_ADMIN_URL |
|
| 2041 | - ); |
|
| 2042 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2043 | - $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
| 2044 | - $template_path = |
|
| 2045 | - REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 2046 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2047 | - } |
|
| 2048 | - |
|
| 2049 | - |
|
| 2050 | - /** |
|
| 2051 | - * generates HTML for the Registration Questions meta box. |
|
| 2052 | - * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
| 2053 | - * otherwise uses new forms system |
|
| 2054 | - * |
|
| 2055 | - * @access public |
|
| 2056 | - * @return void |
|
| 2057 | - * @throws DomainException |
|
| 2058 | - * @throws EE_Error |
|
| 2059 | - */ |
|
| 2060 | - public function _reg_questions_meta_box() |
|
| 2061 | - { |
|
| 2062 | - //allow someone to override this method entirely |
|
| 2063 | - if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this, |
|
| 2064 | - $this->_registration)) { |
|
| 2065 | - $form = $this->_get_reg_custom_questions_form( |
|
| 2066 | - $this->_registration->ID() |
|
| 2067 | - ); |
|
| 2068 | - $this->_template_args['att_questions'] = count($form->subforms()) > 0 |
|
| 2069 | - ? $form->get_html_and_js() |
|
| 2070 | - : ''; |
|
| 2071 | - $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
| 2072 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2073 | - $template_path = |
|
| 2074 | - REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 2075 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2076 | - } |
|
| 2077 | - } |
|
| 2078 | - |
|
| 2079 | - |
|
| 2080 | - /** |
|
| 2081 | - * form_before_question_group |
|
| 2082 | - * |
|
| 2083 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2084 | - * @access public |
|
| 2085 | - * @param string $output |
|
| 2086 | - * @return string |
|
| 2087 | - */ |
|
| 2088 | - public function form_before_question_group($output) |
|
| 2089 | - { |
|
| 2090 | - EE_Error::doing_it_wrong( |
|
| 2091 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2092 | - esc_html__( |
|
| 2093 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2094 | - 'event_espresso' |
|
| 2095 | - ), |
|
| 2096 | - '4.8.32.rc.000' |
|
| 2097 | - ); |
|
| 2098 | - return ' |
|
| 1155 | + if (! empty($registration_status)) { |
|
| 1156 | + $where['STS_ID'] = $registration_status; |
|
| 1157 | + } else { |
|
| 1158 | + //make sure we exclude incomplete registrations, but only if not trashed. |
|
| 1159 | + if ($view === 'trash') { |
|
| 1160 | + $where['REG_deleted'] = true; |
|
| 1161 | + } elseif ($view === 'incomplete') { |
|
| 1162 | + $where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 1163 | + } else { |
|
| 1164 | + $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 1165 | + } |
|
| 1166 | + } |
|
| 1167 | + return $where; |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + |
|
| 1171 | + /** |
|
| 1172 | + * Adds any provided date restraints to the where conditions for the registrations query. |
|
| 1173 | + * |
|
| 1174 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1175 | + * @return array |
|
| 1176 | + * @throws EE_Error |
|
| 1177 | + */ |
|
| 1178 | + protected function _add_date_to_where_conditions(array $request) |
|
| 1179 | + { |
|
| 1180 | + $where = array(); |
|
| 1181 | + $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1182 | + $month_range = ! empty($request['month_range']) |
|
| 1183 | + ? sanitize_text_field($request['month_range']) |
|
| 1184 | + : ''; |
|
| 1185 | + $retrieve_for_today = $view === 'today'; |
|
| 1186 | + $retrieve_for_this_month = $view === 'month'; |
|
| 1187 | + |
|
| 1188 | + if ($retrieve_for_today) { |
|
| 1189 | + $now = date('Y-m-d', current_time('timestamp')); |
|
| 1190 | + $where['REG_date'] = array( |
|
| 1191 | + 'BETWEEN', |
|
| 1192 | + array( |
|
| 1193 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1194 | + 'REG_date', |
|
| 1195 | + $now . ' 00:00:00', |
|
| 1196 | + 'Y-m-d H:i:s' |
|
| 1197 | + ), |
|
| 1198 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1199 | + 'REG_date', |
|
| 1200 | + $now . ' 23:59:59', |
|
| 1201 | + 'Y-m-d H:i:s' |
|
| 1202 | + ), |
|
| 1203 | + ), |
|
| 1204 | + ); |
|
| 1205 | + } elseif ($retrieve_for_this_month) { |
|
| 1206 | + $current_year_and_month = date('Y-m', current_time('timestamp')); |
|
| 1207 | + $days_this_month = date('t', current_time('timestamp')); |
|
| 1208 | + $where['REG_date'] = array( |
|
| 1209 | + 'BETWEEN', |
|
| 1210 | + array( |
|
| 1211 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1212 | + 'REG_date', |
|
| 1213 | + $current_year_and_month . '-01 00:00:00', |
|
| 1214 | + 'Y-m-d H:i:s' |
|
| 1215 | + ), |
|
| 1216 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1217 | + 'REG_date', |
|
| 1218 | + $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 1219 | + 'Y-m-d H:i:s' |
|
| 1220 | + ), |
|
| 1221 | + ), |
|
| 1222 | + ); |
|
| 1223 | + } elseif ($month_range) { |
|
| 1224 | + $pieces = explode(' ', $month_range, 3); |
|
| 1225 | + $month_requested = ! empty($pieces[0]) |
|
| 1226 | + ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
| 1227 | + : ''; |
|
| 1228 | + $year_requested = ! empty($pieces[1]) |
|
| 1229 | + ? $pieces[1] |
|
| 1230 | + : ''; |
|
| 1231 | + //if there is not a month or year then we can't go further |
|
| 1232 | + if ($month_requested && $year_requested) { |
|
| 1233 | + $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 1234 | + $where['REG_date'] = array( |
|
| 1235 | + 'BETWEEN', |
|
| 1236 | + array( |
|
| 1237 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1238 | + 'REG_date', |
|
| 1239 | + $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 1240 | + 'Y-m-d H:i:s' |
|
| 1241 | + ), |
|
| 1242 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1243 | + 'REG_date', |
|
| 1244 | + $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 1245 | + 'Y-m-d H:i:s' |
|
| 1246 | + ), |
|
| 1247 | + ), |
|
| 1248 | + ); |
|
| 1249 | + } |
|
| 1250 | + } |
|
| 1251 | + return $where; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + |
|
| 1255 | + /** |
|
| 1256 | + * Adds any provided search restraints to the where conditions for the registrations query |
|
| 1257 | + * |
|
| 1258 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1259 | + * @return array |
|
| 1260 | + */ |
|
| 1261 | + protected function _add_search_to_where_conditions(array $request) |
|
| 1262 | + { |
|
| 1263 | + $where = array(); |
|
| 1264 | + if (! empty($request['s'])) { |
|
| 1265 | + $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
| 1266 | + $where['OR*search_conditions'] = array( |
|
| 1267 | + 'Event.EVT_name' => array('LIKE', $search_string), |
|
| 1268 | + 'Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1269 | + 'Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1270 | + 'Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1271 | + 'Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1272 | + 'Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1273 | + 'Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1274 | + 'Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1275 | + 'Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1276 | + 'Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1277 | + 'Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1278 | + 'REG_final_price' => array('LIKE', $search_string), |
|
| 1279 | + 'REG_code' => array('LIKE', $search_string), |
|
| 1280 | + 'REG_count' => array('LIKE', $search_string), |
|
| 1281 | + 'REG_group_size' => array('LIKE', $search_string), |
|
| 1282 | + 'Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1283 | + 'Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1284 | + 'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 1285 | + ); |
|
| 1286 | + } |
|
| 1287 | + return $where; |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + |
|
| 1291 | + /** |
|
| 1292 | + * Sets up the where conditions for the registrations query. |
|
| 1293 | + * |
|
| 1294 | + * @param array $request |
|
| 1295 | + * @return array |
|
| 1296 | + * @throws EE_Error |
|
| 1297 | + */ |
|
| 1298 | + protected function _get_where_conditions_for_registrations_query($request) |
|
| 1299 | + { |
|
| 1300 | + return apply_filters( |
|
| 1301 | + 'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', |
|
| 1302 | + array_merge( |
|
| 1303 | + $this->_add_event_id_to_where_conditions($request), |
|
| 1304 | + $this->_add_category_id_to_where_conditions($request), |
|
| 1305 | + $this->_add_datetime_id_to_where_conditions($request), |
|
| 1306 | + $this->_add_registration_status_to_where_conditions($request), |
|
| 1307 | + $this->_add_date_to_where_conditions($request), |
|
| 1308 | + $this->_add_search_to_where_conditions($request) |
|
| 1309 | + ), |
|
| 1310 | + $request |
|
| 1311 | + ); |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + |
|
| 1315 | + /** |
|
| 1316 | + * Sets up the orderby for the registrations query. |
|
| 1317 | + * |
|
| 1318 | + * @return array |
|
| 1319 | + */ |
|
| 1320 | + protected function _get_orderby_for_registrations_query() |
|
| 1321 | + { |
|
| 1322 | + $orderby_field = ! empty($this->_req_data['orderby']) |
|
| 1323 | + ? sanitize_text_field($this->_req_data['orderby']) |
|
| 1324 | + : ''; |
|
| 1325 | + switch ($orderby_field) { |
|
| 1326 | + case '_REG_ID': |
|
| 1327 | + $orderby_field = 'REG_ID'; |
|
| 1328 | + break; |
|
| 1329 | + case '_Reg_status': |
|
| 1330 | + $orderby_field = 'STS_ID'; |
|
| 1331 | + break; |
|
| 1332 | + case 'ATT_fname': |
|
| 1333 | + $orderby_field = array('Attendee.ATT_fname', 'Attendee.ATT_lname'); |
|
| 1334 | + break; |
|
| 1335 | + case 'ATT_lname': |
|
| 1336 | + $orderby_field = array('Attendee.ATT_lname', 'Attendee.ATT_fname'); |
|
| 1337 | + break; |
|
| 1338 | + case 'event_name': |
|
| 1339 | + $orderby_field = 'Event.EVT_name'; |
|
| 1340 | + break; |
|
| 1341 | + case 'DTT_EVT_start': |
|
| 1342 | + $orderby_field = 'Event.Datetime.DTT_EVT_start'; |
|
| 1343 | + break; |
|
| 1344 | + default: //'REG_date' |
|
| 1345 | + $orderby_field = 'REG_date'; |
|
| 1346 | + } |
|
| 1347 | + |
|
| 1348 | + //order |
|
| 1349 | + $order = ! empty($this->_req_data['order']) |
|
| 1350 | + ? sanitize_text_field($this->_req_data['order']) |
|
| 1351 | + : 'DESC'; |
|
| 1352 | + |
|
| 1353 | + //mutate orderby_field |
|
| 1354 | + $orderby_field = array_combine( |
|
| 1355 | + (array) $orderby_field, |
|
| 1356 | + array_fill(0, count($orderby_field), $order) |
|
| 1357 | + ); |
|
| 1358 | + return array('order_by' => $orderby_field); |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + |
|
| 1362 | + /** |
|
| 1363 | + * Sets up the limit for the registrations query. |
|
| 1364 | + * |
|
| 1365 | + * @param $per_page |
|
| 1366 | + * @return array |
|
| 1367 | + */ |
|
| 1368 | + protected function _get_limit($per_page) |
|
| 1369 | + { |
|
| 1370 | + $current_page = ! empty($this->_req_data['paged']) |
|
| 1371 | + ? absint($this->_req_data['paged']) |
|
| 1372 | + : 1; |
|
| 1373 | + $per_page = ! empty($this->_req_data['perpage']) |
|
| 1374 | + ? $this->_req_data['perpage'] |
|
| 1375 | + : $per_page; |
|
| 1376 | + |
|
| 1377 | + //-1 means return all results so get out if that's set. |
|
| 1378 | + if ((int)$per_page === -1) { |
|
| 1379 | + return array(); |
|
| 1380 | + } |
|
| 1381 | + $per_page = absint($per_page); |
|
| 1382 | + $offset = ($current_page - 1) * $per_page; |
|
| 1383 | + return array('limit' => array($offset, $per_page)); |
|
| 1384 | + } |
|
| 1385 | + |
|
| 1386 | + |
|
| 1387 | + public function get_registration_status_array() |
|
| 1388 | + { |
|
| 1389 | + return self::$_reg_status; |
|
| 1390 | + } |
|
| 1391 | + |
|
| 1392 | + |
|
| 1393 | + |
|
| 1394 | + |
|
| 1395 | + /*************************************** REGISTRATION DETAILS ***************************************/ |
|
| 1396 | + /** |
|
| 1397 | + * generates HTML for the View Registration Details Admin page |
|
| 1398 | + * |
|
| 1399 | + * @access protected |
|
| 1400 | + * @return void |
|
| 1401 | + * @throws DomainException |
|
| 1402 | + * @throws EE_Error |
|
| 1403 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1404 | + */ |
|
| 1405 | + protected function _registration_details() |
|
| 1406 | + { |
|
| 1407 | + $this->_template_args = array(); |
|
| 1408 | + $this->_set_registration_object(); |
|
| 1409 | + if (is_object($this->_registration)) { |
|
| 1410 | + $transaction = $this->_registration->transaction() |
|
| 1411 | + ? $this->_registration->transaction() |
|
| 1412 | + : EE_Transaction::new_instance(); |
|
| 1413 | + $this->_session = $transaction->session_data(); |
|
| 1414 | + $event_id = $this->_registration->event_ID(); |
|
| 1415 | + $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
| 1416 | + $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso'); |
|
| 1417 | + $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
| 1418 | + $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 1419 | + $this->_template_args['grand_total'] = $transaction->total(); |
|
| 1420 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1421 | + // link back to overview |
|
| 1422 | + $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
| 1423 | + $this->_template_args['registration'] = $this->_registration; |
|
| 1424 | + $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1425 | + array( |
|
| 1426 | + 'action' => 'default', |
|
| 1427 | + 'event_id' => $event_id, |
|
| 1428 | + ), |
|
| 1429 | + REG_ADMIN_URL |
|
| 1430 | + ); |
|
| 1431 | + $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1432 | + array( |
|
| 1433 | + 'action' => 'default', |
|
| 1434 | + 'EVT_ID' => $event_id, |
|
| 1435 | + 'page' => 'espresso_transactions', |
|
| 1436 | + ), |
|
| 1437 | + admin_url('admin.php') |
|
| 1438 | + ); |
|
| 1439 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1440 | + array( |
|
| 1441 | + 'page' => 'espresso_events', |
|
| 1442 | + 'action' => 'edit', |
|
| 1443 | + 'post' => $event_id, |
|
| 1444 | + ), |
|
| 1445 | + admin_url('admin.php') |
|
| 1446 | + ); |
|
| 1447 | + //next and previous links |
|
| 1448 | + $next_reg = $this->_registration->next( |
|
| 1449 | + null, |
|
| 1450 | + array(), |
|
| 1451 | + 'REG_ID' |
|
| 1452 | + ); |
|
| 1453 | + $this->_template_args['next_registration'] = $next_reg |
|
| 1454 | + ? $this->_next_link( |
|
| 1455 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 1456 | + array( |
|
| 1457 | + 'action' => 'view_registration', |
|
| 1458 | + '_REG_ID' => $next_reg['REG_ID'], |
|
| 1459 | + ), |
|
| 1460 | + REG_ADMIN_URL |
|
| 1461 | + ), |
|
| 1462 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 1463 | + ) |
|
| 1464 | + : ''; |
|
| 1465 | + $previous_reg = $this->_registration->previous( |
|
| 1466 | + null, |
|
| 1467 | + array(), |
|
| 1468 | + 'REG_ID' |
|
| 1469 | + ); |
|
| 1470 | + $this->_template_args['previous_registration'] = $previous_reg |
|
| 1471 | + ? $this->_previous_link( |
|
| 1472 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 1473 | + array( |
|
| 1474 | + 'action' => 'view_registration', |
|
| 1475 | + '_REG_ID' => $previous_reg['REG_ID'], |
|
| 1476 | + ), |
|
| 1477 | + REG_ADMIN_URL |
|
| 1478 | + ), |
|
| 1479 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 1480 | + ) |
|
| 1481 | + : ''; |
|
| 1482 | + // grab header |
|
| 1483 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1484 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1485 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 1486 | + $template_path, |
|
| 1487 | + $this->_template_args, |
|
| 1488 | + true |
|
| 1489 | + ); |
|
| 1490 | + } else { |
|
| 1491 | + $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
|
| 1492 | + } |
|
| 1493 | + // the details template wrapper |
|
| 1494 | + $this->display_admin_page_with_sidebar(); |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + |
|
| 1498 | + protected function _registration_details_metaboxes() |
|
| 1499 | + { |
|
| 1500 | + do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
| 1501 | + $this->_set_registration_object(); |
|
| 1502 | + $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
| 1503 | + add_meta_box('edit-reg-status-mbox', esc_html__('Registration Status', 'event_espresso'), |
|
| 1504 | + array($this, 'set_reg_status_buttons_metabox'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1505 | + add_meta_box('edit-reg-details-mbox', esc_html__('Registration Details', 'event_espresso'), |
|
| 1506 | + array($this, '_reg_details_meta_box'), $this->wp_page_slug, 'normal', 'high'); |
|
| 1507 | + if ($attendee instanceof EE_Attendee |
|
| 1508 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 1509 | + 'ee_edit_registration', |
|
| 1510 | + 'edit-reg-questions-mbox' |
|
| 1511 | + ) |
|
| 1512 | + ) { |
|
| 1513 | + add_meta_box( |
|
| 1514 | + 'edit-reg-questions-mbox', |
|
| 1515 | + esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 1516 | + array($this, '_reg_questions_meta_box'), |
|
| 1517 | + $this->wp_page_slug, |
|
| 1518 | + 'normal', |
|
| 1519 | + 'high' |
|
| 1520 | + ); |
|
| 1521 | + } |
|
| 1522 | + add_meta_box( |
|
| 1523 | + 'edit-reg-registrant-mbox', |
|
| 1524 | + esc_html__('Contact Details', 'event_espresso'), |
|
| 1525 | + array($this, '_reg_registrant_side_meta_box'), |
|
| 1526 | + $this->wp_page_slug, |
|
| 1527 | + 'side', |
|
| 1528 | + 'high' |
|
| 1529 | + ); |
|
| 1530 | + if ($this->_registration->group_size() > 1) { |
|
| 1531 | + add_meta_box( |
|
| 1532 | + 'edit-reg-attendees-mbox', |
|
| 1533 | + esc_html__('Other Registrations in this Transaction', 'event_espresso'), |
|
| 1534 | + array($this, '_reg_attendees_meta_box'), |
|
| 1535 | + $this->wp_page_slug, |
|
| 1536 | + 'normal', |
|
| 1537 | + 'high' |
|
| 1538 | + ); |
|
| 1539 | + } |
|
| 1540 | + } |
|
| 1541 | + |
|
| 1542 | + |
|
| 1543 | + /** |
|
| 1544 | + * set_reg_status_buttons_metabox |
|
| 1545 | + * |
|
| 1546 | + * @access protected |
|
| 1547 | + * @return string |
|
| 1548 | + * @throws \EE_Error |
|
| 1549 | + */ |
|
| 1550 | + public function set_reg_status_buttons_metabox() |
|
| 1551 | + { |
|
| 1552 | + $this->_set_registration_object(); |
|
| 1553 | + $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
| 1554 | + echo $change_reg_status_form->form_open( |
|
| 1555 | + self::add_query_args_and_nonce( |
|
| 1556 | + array( |
|
| 1557 | + 'action' => 'change_reg_status', |
|
| 1558 | + ), |
|
| 1559 | + REG_ADMIN_URL |
|
| 1560 | + ) |
|
| 1561 | + ); |
|
| 1562 | + echo $change_reg_status_form->get_html(); |
|
| 1563 | + echo $change_reg_status_form->form_close(); |
|
| 1564 | + } |
|
| 1565 | + |
|
| 1566 | + |
|
| 1567 | + |
|
| 1568 | + /** |
|
| 1569 | + * @return EE_Form_Section_Proper |
|
| 1570 | + * @throws EE_Error |
|
| 1571 | + */ |
|
| 1572 | + protected function _generate_reg_status_change_form() |
|
| 1573 | + { |
|
| 1574 | + return new EE_Form_Section_Proper(array( |
|
| 1575 | + 'name' => 'reg_status_change_form', |
|
| 1576 | + 'html_id' => 'reg-status-change-form', |
|
| 1577 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1578 | + 'subsections' => array( |
|
| 1579 | + 'return' => new EE_Hidden_Input(array( |
|
| 1580 | + 'name' => 'return', |
|
| 1581 | + 'default' => 'view_registration', |
|
| 1582 | + )), |
|
| 1583 | + 'REG_ID' => new EE_Hidden_Input(array( |
|
| 1584 | + 'name' => 'REG_ID', |
|
| 1585 | + 'default' => $this->_registration->ID(), |
|
| 1586 | + )), |
|
| 1587 | + 'current_status' => new EE_Form_Section_HTML( |
|
| 1588 | + EEH_HTML::tr( |
|
| 1589 | + EEH_HTML::th( |
|
| 1590 | + EEH_HTML::label( |
|
| 1591 | + EEH_HTML::strong(esc_html__('Current Registration Status', 'event_espresso') |
|
| 1592 | + ) |
|
| 1593 | + ) |
|
| 1594 | + ) |
|
| 1595 | + . EEH_HTML::td( |
|
| 1596 | + EEH_HTML::strong( |
|
| 1597 | + $this->_registration->pretty_status(), |
|
| 1598 | + '', |
|
| 1599 | + 'status-' . $this->_registration->status_ID(), |
|
| 1600 | + 'line-height: 1em; font-size: 1.5em; font-weight: bold;' |
|
| 1601 | + ) |
|
| 1602 | + ) |
|
| 1603 | + ) |
|
| 1604 | + ), |
|
| 1605 | + 'reg_status' => new EE_Select_Input( |
|
| 1606 | + $this->_get_reg_statuses(), |
|
| 1607 | + array( |
|
| 1608 | + 'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'), |
|
| 1609 | + 'default' => $this->_registration->status_ID(), |
|
| 1610 | + ) |
|
| 1611 | + ), |
|
| 1612 | + 'send_notifications' => new EE_Yes_No_Input( |
|
| 1613 | + array( |
|
| 1614 | + 'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'), |
|
| 1615 | + 'default' => false, |
|
| 1616 | + 'html_help_text' => esc_html__( |
|
| 1617 | + 'If set to "Yes", then the related messages will be sent to the registrant.', |
|
| 1618 | + 'event_espresso' |
|
| 1619 | + ), |
|
| 1620 | + ) |
|
| 1621 | + ), |
|
| 1622 | + 'submit' => new EE_Submit_Input( |
|
| 1623 | + array( |
|
| 1624 | + 'html_class' => 'button-primary', |
|
| 1625 | + 'html_label_text' => ' ', |
|
| 1626 | + 'default' => esc_html__('Update Registration Status', 'event_espresso'), |
|
| 1627 | + ) |
|
| 1628 | + ), |
|
| 1629 | + ), |
|
| 1630 | + )); |
|
| 1631 | + } |
|
| 1632 | + |
|
| 1633 | + |
|
| 1634 | + /** |
|
| 1635 | + * Returns an array of all the buttons for the various statuses and switch status actions |
|
| 1636 | + * |
|
| 1637 | + * @return array |
|
| 1638 | + * @throws EE_Error |
|
| 1639 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1640 | + */ |
|
| 1641 | + protected function _get_reg_statuses() |
|
| 1642 | + { |
|
| 1643 | + $reg_status_array = EEM_Registration::instance()->reg_status_array(); |
|
| 1644 | + unset ($reg_status_array[EEM_Registration::status_id_incomplete]); |
|
| 1645 | + // get current reg status |
|
| 1646 | + $current_status = $this->_registration->status_ID(); |
|
| 1647 | + // is registration for free event? This will determine whether to display the pending payment option |
|
| 1648 | + if ( |
|
| 1649 | + $current_status !== EEM_Registration::status_id_pending_payment |
|
| 1650 | + && $this->_registration->transaction()->is_free() |
|
| 1651 | + ) { |
|
| 1652 | + unset($reg_status_array[EEM_Registration::status_id_pending_payment]); |
|
| 1653 | + } |
|
| 1654 | + return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence'); |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + |
|
| 1658 | + |
|
| 1659 | + /** |
|
| 1660 | + * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
| 1661 | + * |
|
| 1662 | + * @param bool $status REG status given for changing registrations to. |
|
| 1663 | + * @param bool $notify Whether to send messages notifications or not. |
|
| 1664 | + * @return array (array with reg_id(s) updated and whether update was successful. |
|
| 1665 | + * @throws \EE_Error |
|
| 1666 | + */ |
|
| 1667 | + protected function _set_registration_status_from_request($status = false, $notify = false) |
|
| 1668 | + { |
|
| 1669 | + if (isset($this->_req_data['reg_status_change_form'])) { |
|
| 1670 | + $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 1671 | + ? (array)$this->_req_data['reg_status_change_form']['REG_ID'] : array(); |
|
| 1672 | + } else { |
|
| 1673 | + $REG_IDs = isset($this->_req_data['_REG_ID']) ? (array)$this->_req_data['_REG_ID'] : array(); |
|
| 1674 | + } |
|
| 1675 | + $success = $this->_set_registration_status($REG_IDs, $status); |
|
| 1676 | + //notify? |
|
| 1677 | + if ($success |
|
| 1678 | + && $notify |
|
| 1679 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 1680 | + 'ee_send_message', |
|
| 1681 | + 'espresso_registrations_resend_registration' |
|
| 1682 | + ) |
|
| 1683 | + ) { |
|
| 1684 | + $this->_process_resend_registration(); |
|
| 1685 | + } |
|
| 1686 | + return $success; |
|
| 1687 | + } |
|
| 1688 | + |
|
| 1689 | + |
|
| 1690 | + |
|
| 1691 | + /** |
|
| 1692 | + * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
| 1693 | + * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
| 1694 | + * |
|
| 1695 | + * @param array $REG_IDs |
|
| 1696 | + * @param bool $status |
|
| 1697 | + * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
| 1698 | + * @throws \RuntimeException |
|
| 1699 | + * @throws \EE_Error |
|
| 1700 | + * the array of updated registrations). |
|
| 1701 | + * @throws EE_Error |
|
| 1702 | + * @throws RuntimeException |
|
| 1703 | + */ |
|
| 1704 | + protected function _set_registration_status($REG_IDs = array(), $status = false) |
|
| 1705 | + { |
|
| 1706 | + $success = false; |
|
| 1707 | + // typecast $REG_IDs |
|
| 1708 | + $REG_IDs = (array)$REG_IDs; |
|
| 1709 | + if ( ! empty($REG_IDs)) { |
|
| 1710 | + $success = true; |
|
| 1711 | + // set default status if none is passed |
|
| 1712 | + $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
|
| 1713 | + // sanitize $REG_IDs |
|
| 1714 | + $REG_IDs = array_filter($REG_IDs, 'absint'); |
|
| 1715 | + //loop through REG_ID's and change status |
|
| 1716 | + foreach ($REG_IDs as $REG_ID) { |
|
| 1717 | + $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 1718 | + if ($registration instanceof EE_Registration) { |
|
| 1719 | + $registration->set_status($status); |
|
| 1720 | + $result = $registration->save(); |
|
| 1721 | + // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
| 1722 | + $success = $result !== false ? $success : false; |
|
| 1723 | + } |
|
| 1724 | + } |
|
| 1725 | + } |
|
| 1726 | + //reset _req_data['_REG_ID'] for any potential future messages notifications |
|
| 1727 | + $this->_req_data['_REG_ID'] = $REG_IDs; |
|
| 1728 | + //return $success and processed registrations |
|
| 1729 | + return array('REG_ID' => $REG_IDs, 'success' => $success); |
|
| 1730 | + } |
|
| 1731 | + |
|
| 1732 | + |
|
| 1733 | + /** |
|
| 1734 | + * Common logic for setting up success message and redirecting to appropriate route |
|
| 1735 | + * |
|
| 1736 | + * @param string $STS_ID status id for the registration changed to |
|
| 1737 | + * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
| 1738 | + * @return void |
|
| 1739 | + */ |
|
| 1740 | + protected function _reg_status_change_return($STS_ID, $notify = false) |
|
| 1741 | + { |
|
| 1742 | + $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
| 1743 | + : array('success' => false); |
|
| 1744 | + $success = isset($result['success']) && $result['success']; |
|
| 1745 | + //setup success message |
|
| 1746 | + if ($success) { |
|
| 1747 | + if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
| 1748 | + $msg = sprintf(esc_html__('Registration status has been set to %s', 'event_espresso'), |
|
| 1749 | + EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1750 | + } else { |
|
| 1751 | + $msg = sprintf(esc_html__('Registrations have been set to %s.', 'event_espresso'), |
|
| 1752 | + EEH_Template::pretty_status($STS_ID, false, 'lower')); |
|
| 1753 | + } |
|
| 1754 | + EE_Error::add_success($msg); |
|
| 1755 | + } else { |
|
| 1756 | + EE_Error::add_error( |
|
| 1757 | + esc_html__( |
|
| 1758 | + 'Something went wrong, and the status was not changed', |
|
| 1759 | + 'event_espresso' |
|
| 1760 | + ), __FILE__, __LINE__, __FUNCTION__ |
|
| 1761 | + ); |
|
| 1762 | + } |
|
| 1763 | + if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') { |
|
| 1764 | + $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
|
| 1765 | + } else { |
|
| 1766 | + $route = array('action' => 'default'); |
|
| 1767 | + } |
|
| 1768 | + //unset nonces |
|
| 1769 | + foreach ($this->_req_data as $ref => $value) { |
|
| 1770 | + if (strpos($ref, 'nonce') !== false) { |
|
| 1771 | + unset($this->_req_data[$ref]); |
|
| 1772 | + continue; |
|
| 1773 | + } |
|
| 1774 | + $value = is_array($value) ? array_map('urlencode', $value) : urlencode($value); |
|
| 1775 | + $this->_req_data[$ref] = $value; |
|
| 1776 | + } |
|
| 1777 | + //merge request vars so that the reloaded list table contains any existing filter query params |
|
| 1778 | + $route = array_merge($this->_req_data, $route); |
|
| 1779 | + $this->_redirect_after_action($success, '', '', $route, true); |
|
| 1780 | + } |
|
| 1781 | + |
|
| 1782 | + |
|
| 1783 | + /** |
|
| 1784 | + * incoming reg status change from reg details page. |
|
| 1785 | + * |
|
| 1786 | + * @return void |
|
| 1787 | + */ |
|
| 1788 | + protected function _change_reg_status() |
|
| 1789 | + { |
|
| 1790 | + $this->_req_data['return'] = 'view_registration'; |
|
| 1791 | + //set notify based on whether the send notifications toggle is set or not |
|
| 1792 | + $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
|
| 1793 | + //$notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
|
| 1794 | + $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
|
| 1795 | + ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
|
| 1796 | + switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
|
| 1797 | + case EEM_Registration::status_id_approved : |
|
| 1798 | + case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence') : |
|
| 1799 | + $this->approve_registration($notify); |
|
| 1800 | + break; |
|
| 1801 | + case EEM_Registration::status_id_pending_payment : |
|
| 1802 | + case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence') : |
|
| 1803 | + $this->pending_registration($notify); |
|
| 1804 | + break; |
|
| 1805 | + case EEM_Registration::status_id_not_approved : |
|
| 1806 | + case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence') : |
|
| 1807 | + $this->not_approve_registration($notify); |
|
| 1808 | + break; |
|
| 1809 | + case EEM_Registration::status_id_declined : |
|
| 1810 | + case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence') : |
|
| 1811 | + $this->decline_registration($notify); |
|
| 1812 | + break; |
|
| 1813 | + case EEM_Registration::status_id_cancelled : |
|
| 1814 | + case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence') : |
|
| 1815 | + $this->cancel_registration($notify); |
|
| 1816 | + break; |
|
| 1817 | + case EEM_Registration::status_id_wait_list : |
|
| 1818 | + case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence') : |
|
| 1819 | + $this->wait_list_registration($notify); |
|
| 1820 | + break; |
|
| 1821 | + case EEM_Registration::status_id_incomplete : |
|
| 1822 | + default : |
|
| 1823 | + $result['success'] = false; |
|
| 1824 | + unset($this->_req_data['return']); |
|
| 1825 | + $this->_reg_status_change_return('', false); |
|
| 1826 | + break; |
|
| 1827 | + } |
|
| 1828 | + } |
|
| 1829 | + |
|
| 1830 | + |
|
| 1831 | + /** |
|
| 1832 | + * approve_registration |
|
| 1833 | + * |
|
| 1834 | + * @access protected |
|
| 1835 | + * @param bool $notify whether or not to notify the registrant about their approval. |
|
| 1836 | + * @return void |
|
| 1837 | + */ |
|
| 1838 | + protected function approve_registration($notify = false) |
|
| 1839 | + { |
|
| 1840 | + $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + |
|
| 1844 | + /** |
|
| 1845 | + * decline_registration |
|
| 1846 | + * |
|
| 1847 | + * @access protected |
|
| 1848 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1849 | + * @return void |
|
| 1850 | + */ |
|
| 1851 | + protected function decline_registration($notify = false) |
|
| 1852 | + { |
|
| 1853 | + $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
| 1854 | + } |
|
| 1855 | + |
|
| 1856 | + |
|
| 1857 | + /** |
|
| 1858 | + * cancel_registration |
|
| 1859 | + * |
|
| 1860 | + * @access protected |
|
| 1861 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1862 | + * @return void |
|
| 1863 | + */ |
|
| 1864 | + protected function cancel_registration($notify = false) |
|
| 1865 | + { |
|
| 1866 | + $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
| 1867 | + } |
|
| 1868 | + |
|
| 1869 | + |
|
| 1870 | + /** |
|
| 1871 | + * not_approve_registration |
|
| 1872 | + * |
|
| 1873 | + * @access protected |
|
| 1874 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1875 | + * @return void |
|
| 1876 | + */ |
|
| 1877 | + protected function not_approve_registration($notify = false) |
|
| 1878 | + { |
|
| 1879 | + $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
| 1880 | + } |
|
| 1881 | + |
|
| 1882 | + |
|
| 1883 | + /** |
|
| 1884 | + * decline_registration |
|
| 1885 | + * |
|
| 1886 | + * @access protected |
|
| 1887 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1888 | + * @return void |
|
| 1889 | + */ |
|
| 1890 | + protected function pending_registration($notify = false) |
|
| 1891 | + { |
|
| 1892 | + $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
| 1893 | + } |
|
| 1894 | + |
|
| 1895 | + |
|
| 1896 | + /** |
|
| 1897 | + * waitlist_registration |
|
| 1898 | + * |
|
| 1899 | + * @access protected |
|
| 1900 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 1901 | + * @return void |
|
| 1902 | + */ |
|
| 1903 | + protected function wait_list_registration($notify = false) |
|
| 1904 | + { |
|
| 1905 | + $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
| 1906 | + } |
|
| 1907 | + |
|
| 1908 | + |
|
| 1909 | + /** |
|
| 1910 | + * generates HTML for the Registration main meta box |
|
| 1911 | + * |
|
| 1912 | + * @access public |
|
| 1913 | + * @return void |
|
| 1914 | + * @throws DomainException |
|
| 1915 | + * @throws EE_Error |
|
| 1916 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1917 | + */ |
|
| 1918 | + public function _reg_details_meta_box() |
|
| 1919 | + { |
|
| 1920 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1921 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 1922 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
| 1923 | + $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 1924 | + : EE_Transaction::new_instance(); |
|
| 1925 | + $this->_session = $transaction->session_data(); |
|
| 1926 | + $filters = new EE_Line_Item_Filter_Collection(); |
|
| 1927 | + //$filters->add( new EE_Non_Zero_Line_Item_Filter() ); |
|
| 1928 | + $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
| 1929 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor($filters, |
|
| 1930 | + $transaction->total_line_item()); |
|
| 1931 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 1932 | + $line_item_display = new EE_Line_Item_Display('reg_admin_table', |
|
| 1933 | + 'EE_Admin_Table_Registration_Line_Item_Display_Strategy'); |
|
| 1934 | + $this->_template_args['line_item_table'] = $line_item_display->display_line_item( |
|
| 1935 | + $filtered_line_item_tree, |
|
| 1936 | + array('EE_Registration' => $this->_registration) |
|
| 1937 | + ); |
|
| 1938 | + $attendee = $this->_registration->attendee(); |
|
| 1939 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 1940 | + 'ee_read_transaction', |
|
| 1941 | + 'espresso_transactions_view_transaction' |
|
| 1942 | + )) { |
|
| 1943 | + $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link( |
|
| 1944 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 1945 | + array( |
|
| 1946 | + 'action' => 'view_transaction', |
|
| 1947 | + 'TXN_ID' => $transaction->ID(), |
|
| 1948 | + ), |
|
| 1949 | + TXN_ADMIN_URL |
|
| 1950 | + ), |
|
| 1951 | + esc_html__(' View Transaction', 'event_espresso'), |
|
| 1952 | + 'button secondary-button right', |
|
| 1953 | + 'dashicons dashicons-cart' |
|
| 1954 | + ); |
|
| 1955 | + } else { |
|
| 1956 | + $this->_template_args['view_transaction_button'] = ''; |
|
| 1957 | + } |
|
| 1958 | + if ($attendee instanceof EE_Attendee |
|
| 1959 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 1960 | + 'ee_send_message', |
|
| 1961 | + 'espresso_registrations_resend_registration' |
|
| 1962 | + ) |
|
| 1963 | + ) { |
|
| 1964 | + $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link( |
|
| 1965 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 1966 | + array( |
|
| 1967 | + 'action' => 'resend_registration', |
|
| 1968 | + '_REG_ID' => $this->_registration->ID(), |
|
| 1969 | + 'redirect_to' => 'view_registration', |
|
| 1970 | + ), |
|
| 1971 | + REG_ADMIN_URL |
|
| 1972 | + ), |
|
| 1973 | + esc_html__(' Resend Registration', 'event_espresso'), |
|
| 1974 | + 'button secondary-button right', |
|
| 1975 | + 'dashicons dashicons-email-alt' |
|
| 1976 | + ); |
|
| 1977 | + } else { |
|
| 1978 | + $this->_template_args['resend_registration_button'] = ''; |
|
| 1979 | + } |
|
| 1980 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1981 | + $payment = $transaction->get_first_related('Payment'); |
|
| 1982 | + $payment = ! $payment instanceof EE_Payment |
|
| 1983 | + ? EE_Payment::new_instance() |
|
| 1984 | + : $payment; |
|
| 1985 | + $payment_method = $payment->get_first_related('Payment_Method'); |
|
| 1986 | + $payment_method = ! $payment_method instanceof EE_Payment_Method |
|
| 1987 | + ? EE_Payment_Method::new_instance() |
|
| 1988 | + : $payment_method; |
|
| 1989 | + $reg_details = array( |
|
| 1990 | + 'payment_method' => $payment_method->name(), |
|
| 1991 | + 'response_msg' => $payment->gateway_response(), |
|
| 1992 | + 'registration_id' => $this->_registration->get('REG_code'), |
|
| 1993 | + 'registration_session' => $this->_registration->session_ID(), |
|
| 1994 | + 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
| 1995 | + 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
| 1996 | + ); |
|
| 1997 | + if (isset($reg_details['registration_id'])) { |
|
| 1998 | + $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
| 1999 | + $this->_template_args['reg_details']['registration_id']['label'] = esc_html__( |
|
| 2000 | + 'Registration ID', |
|
| 2001 | + 'event_espresso' |
|
| 2002 | + ); |
|
| 2003 | + $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
| 2004 | + } |
|
| 2005 | + if (isset($reg_details['payment_method'])) { |
|
| 2006 | + $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
| 2007 | + $this->_template_args['reg_details']['payment_method']['label'] = esc_html__( |
|
| 2008 | + 'Most Recent Payment Method', |
|
| 2009 | + 'event_espresso' |
|
| 2010 | + ); |
|
| 2011 | + $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
| 2012 | + $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
| 2013 | + $this->_template_args['reg_details']['response_msg']['label'] = esc_html__( |
|
| 2014 | + 'Payment method response', |
|
| 2015 | + 'event_espresso' |
|
| 2016 | + ); |
|
| 2017 | + $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 2018 | + } |
|
| 2019 | + $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
| 2020 | + $this->_template_args['reg_details']['registration_session']['label'] = esc_html__( |
|
| 2021 | + 'Registration Session', |
|
| 2022 | + 'event_espresso' |
|
| 2023 | + ); |
|
| 2024 | + $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
| 2025 | + $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
| 2026 | + $this->_template_args['reg_details']['ip_address']['label'] = esc_html__( |
|
| 2027 | + 'Registration placed from IP', |
|
| 2028 | + 'event_espresso' |
|
| 2029 | + ); |
|
| 2030 | + $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
| 2031 | + $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
| 2032 | + $this->_template_args['reg_details']['user_agent']['label'] = esc_html__('Registrant User Agent', |
|
| 2033 | + 'event_espresso'); |
|
| 2034 | + $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
| 2035 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2036 | + array( |
|
| 2037 | + 'action' => 'default', |
|
| 2038 | + 'event_id' => $this->_registration->event_ID(), |
|
| 2039 | + ), |
|
| 2040 | + REG_ADMIN_URL |
|
| 2041 | + ); |
|
| 2042 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2043 | + $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
| 2044 | + $template_path = |
|
| 2045 | + REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 2046 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2047 | + } |
|
| 2048 | + |
|
| 2049 | + |
|
| 2050 | + /** |
|
| 2051 | + * generates HTML for the Registration Questions meta box. |
|
| 2052 | + * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
| 2053 | + * otherwise uses new forms system |
|
| 2054 | + * |
|
| 2055 | + * @access public |
|
| 2056 | + * @return void |
|
| 2057 | + * @throws DomainException |
|
| 2058 | + * @throws EE_Error |
|
| 2059 | + */ |
|
| 2060 | + public function _reg_questions_meta_box() |
|
| 2061 | + { |
|
| 2062 | + //allow someone to override this method entirely |
|
| 2063 | + if (apply_filters('FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', true, $this, |
|
| 2064 | + $this->_registration)) { |
|
| 2065 | + $form = $this->_get_reg_custom_questions_form( |
|
| 2066 | + $this->_registration->ID() |
|
| 2067 | + ); |
|
| 2068 | + $this->_template_args['att_questions'] = count($form->subforms()) > 0 |
|
| 2069 | + ? $form->get_html_and_js() |
|
| 2070 | + : ''; |
|
| 2071 | + $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
| 2072 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2073 | + $template_path = |
|
| 2074 | + REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 2075 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2076 | + } |
|
| 2077 | + } |
|
| 2078 | + |
|
| 2079 | + |
|
| 2080 | + /** |
|
| 2081 | + * form_before_question_group |
|
| 2082 | + * |
|
| 2083 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2084 | + * @access public |
|
| 2085 | + * @param string $output |
|
| 2086 | + * @return string |
|
| 2087 | + */ |
|
| 2088 | + public function form_before_question_group($output) |
|
| 2089 | + { |
|
| 2090 | + EE_Error::doing_it_wrong( |
|
| 2091 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2092 | + esc_html__( |
|
| 2093 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2094 | + 'event_espresso' |
|
| 2095 | + ), |
|
| 2096 | + '4.8.32.rc.000' |
|
| 2097 | + ); |
|
| 2098 | + return ' |
|
| 2099 | 2099 | <table class="form-table ee-width-100"> |
| 2100 | 2100 | <tbody> |
| 2101 | 2101 | '; |
| 2102 | - } |
|
| 2103 | - |
|
| 2104 | - |
|
| 2105 | - /** |
|
| 2106 | - * form_after_question_group |
|
| 2107 | - * |
|
| 2108 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2109 | - * @access public |
|
| 2110 | - * @param string $output |
|
| 2111 | - * @return string |
|
| 2112 | - */ |
|
| 2113 | - public function form_after_question_group($output) |
|
| 2114 | - { |
|
| 2115 | - EE_Error::doing_it_wrong( |
|
| 2116 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2117 | - esc_html__( |
|
| 2118 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2119 | - 'event_espresso' |
|
| 2120 | - ), |
|
| 2121 | - '4.8.32.rc.000' |
|
| 2122 | - ); |
|
| 2123 | - return ' |
|
| 2102 | + } |
|
| 2103 | + |
|
| 2104 | + |
|
| 2105 | + /** |
|
| 2106 | + * form_after_question_group |
|
| 2107 | + * |
|
| 2108 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2109 | + * @access public |
|
| 2110 | + * @param string $output |
|
| 2111 | + * @return string |
|
| 2112 | + */ |
|
| 2113 | + public function form_after_question_group($output) |
|
| 2114 | + { |
|
| 2115 | + EE_Error::doing_it_wrong( |
|
| 2116 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2117 | + esc_html__( |
|
| 2118 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2119 | + 'event_espresso' |
|
| 2120 | + ), |
|
| 2121 | + '4.8.32.rc.000' |
|
| 2122 | + ); |
|
| 2123 | + return ' |
|
| 2124 | 2124 | <tr class="hide-if-no-js"> |
| 2125 | 2125 | <th> </th> |
| 2126 | 2126 | <td class="reg-admin-edit-attendee-question-td"> |
| 2127 | 2127 | <a class="reg-admin-edit-attendee-question-lnk" href="#" title="' |
| 2128 | - . esc_attr__('click to edit question', 'event_espresso') |
|
| 2129 | - . '"> |
|
| 2128 | + . esc_attr__('click to edit question', 'event_espresso') |
|
| 2129 | + . '"> |
|
| 2130 | 2130 | <span class="reg-admin-edit-question-group-spn lt-grey-txt">' |
| 2131 | - . esc_html__('edit the above question group', 'event_espresso') |
|
| 2132 | - . '</span> |
|
| 2131 | + . esc_html__('edit the above question group', 'event_espresso') |
|
| 2132 | + . '</span> |
|
| 2133 | 2133 | <div class="dashicons dashicons-edit"></div> |
| 2134 | 2134 | </a> |
| 2135 | 2135 | </td> |
@@ -2137,558 +2137,558 @@ discard block |
||
| 2137 | 2137 | </tbody> |
| 2138 | 2138 | </table> |
| 2139 | 2139 | '; |
| 2140 | - } |
|
| 2141 | - |
|
| 2142 | - |
|
| 2143 | - /** |
|
| 2144 | - * form_form_field_label_wrap |
|
| 2145 | - * |
|
| 2146 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2147 | - * @access public |
|
| 2148 | - * @param string $label |
|
| 2149 | - * @return string |
|
| 2150 | - */ |
|
| 2151 | - public function form_form_field_label_wrap($label) |
|
| 2152 | - { |
|
| 2153 | - EE_Error::doing_it_wrong( |
|
| 2154 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2155 | - esc_html__( |
|
| 2156 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2157 | - 'event_espresso' |
|
| 2158 | - ), |
|
| 2159 | - '4.8.32.rc.000' |
|
| 2160 | - ); |
|
| 2161 | - return ' |
|
| 2140 | + } |
|
| 2141 | + |
|
| 2142 | + |
|
| 2143 | + /** |
|
| 2144 | + * form_form_field_label_wrap |
|
| 2145 | + * |
|
| 2146 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2147 | + * @access public |
|
| 2148 | + * @param string $label |
|
| 2149 | + * @return string |
|
| 2150 | + */ |
|
| 2151 | + public function form_form_field_label_wrap($label) |
|
| 2152 | + { |
|
| 2153 | + EE_Error::doing_it_wrong( |
|
| 2154 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2155 | + esc_html__( |
|
| 2156 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2157 | + 'event_espresso' |
|
| 2158 | + ), |
|
| 2159 | + '4.8.32.rc.000' |
|
| 2160 | + ); |
|
| 2161 | + return ' |
|
| 2162 | 2162 | <tr> |
| 2163 | 2163 | <th> |
| 2164 | 2164 | ' . $label . ' |
| 2165 | 2165 | </th>'; |
| 2166 | - } |
|
| 2167 | - |
|
| 2168 | - |
|
| 2169 | - /** |
|
| 2170 | - * form_form_field_input__wrap |
|
| 2171 | - * |
|
| 2172 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2173 | - * @access public |
|
| 2174 | - * @param string $input |
|
| 2175 | - * @return string |
|
| 2176 | - */ |
|
| 2177 | - public function form_form_field_input__wrap($input) |
|
| 2178 | - { |
|
| 2179 | - EE_Error::doing_it_wrong( |
|
| 2180 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2181 | - esc_html__( |
|
| 2182 | - 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2183 | - 'event_espresso' |
|
| 2184 | - ), |
|
| 2185 | - '4.8.32.rc.000' |
|
| 2186 | - ); |
|
| 2187 | - return ' |
|
| 2166 | + } |
|
| 2167 | + |
|
| 2168 | + |
|
| 2169 | + /** |
|
| 2170 | + * form_form_field_input__wrap |
|
| 2171 | + * |
|
| 2172 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2173 | + * @access public |
|
| 2174 | + * @param string $input |
|
| 2175 | + * @return string |
|
| 2176 | + */ |
|
| 2177 | + public function form_form_field_input__wrap($input) |
|
| 2178 | + { |
|
| 2179 | + EE_Error::doing_it_wrong( |
|
| 2180 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2181 | + esc_html__( |
|
| 2182 | + 'This method would have been protected but was used on a filter callback so needed to be public. Please discontinue usage as it will be removed soon.', |
|
| 2183 | + 'event_espresso' |
|
| 2184 | + ), |
|
| 2185 | + '4.8.32.rc.000' |
|
| 2186 | + ); |
|
| 2187 | + return ' |
|
| 2188 | 2188 | <td class="reg-admin-attendee-questions-input-td disabled-input"> |
| 2189 | 2189 | ' . $input . ' |
| 2190 | 2190 | </td> |
| 2191 | 2191 | </tr>'; |
| 2192 | - } |
|
| 2193 | - |
|
| 2194 | - |
|
| 2195 | - /** |
|
| 2196 | - * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
| 2197 | - * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
| 2198 | - * to display the page |
|
| 2199 | - * |
|
| 2200 | - * @access protected |
|
| 2201 | - * @return void |
|
| 2202 | - * @throws EE_Error |
|
| 2203 | - */ |
|
| 2204 | - protected function _update_attendee_registration_form() |
|
| 2205 | - { |
|
| 2206 | - do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
| 2207 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 2208 | - $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 2209 | - $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
| 2210 | - if ($success) { |
|
| 2211 | - $what = esc_html__('Registration Form', 'event_espresso'); |
|
| 2212 | - $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
|
| 2213 | - : array('action' => 'default'); |
|
| 2214 | - $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route); |
|
| 2215 | - } |
|
| 2216 | - } |
|
| 2217 | - } |
|
| 2218 | - |
|
| 2219 | - |
|
| 2220 | - /** |
|
| 2221 | - * Gets the form for saving registrations custom questions (if done |
|
| 2222 | - * previously retrieves the cached form object, which may have validation errors in it) |
|
| 2223 | - * |
|
| 2224 | - * @param int $REG_ID |
|
| 2225 | - * @return EE_Registration_Custom_Questions_Form |
|
| 2226 | - * @throws EE_Error |
|
| 2227 | - */ |
|
| 2228 | - protected function _get_reg_custom_questions_form($REG_ID) |
|
| 2229 | - { |
|
| 2230 | - if ( ! $this->_reg_custom_questions_form) { |
|
| 2231 | - require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 2232 | - $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
| 2233 | - EEM_Registration::instance()->get_one_by_ID($REG_ID) |
|
| 2234 | - ); |
|
| 2235 | - $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
| 2236 | - } |
|
| 2237 | - return $this->_reg_custom_questions_form; |
|
| 2238 | - } |
|
| 2239 | - |
|
| 2240 | - |
|
| 2241 | - /** |
|
| 2242 | - * Saves |
|
| 2243 | - * |
|
| 2244 | - * @access private |
|
| 2245 | - * @param bool $REG_ID |
|
| 2246 | - * @return bool |
|
| 2247 | - * @throws EE_Error |
|
| 2248 | - */ |
|
| 2249 | - private function _save_reg_custom_questions_form($REG_ID = false) |
|
| 2250 | - { |
|
| 2251 | - if ( ! $REG_ID) { |
|
| 2252 | - EE_Error::add_error( |
|
| 2253 | - esc_html__( |
|
| 2254 | - 'An error occurred. No registration ID was received.', 'event_espresso'), |
|
| 2255 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2256 | - ); |
|
| 2257 | - } |
|
| 2258 | - $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
| 2259 | - $form->receive_form_submission($this->_req_data); |
|
| 2260 | - $success = false; |
|
| 2261 | - if ($form->is_valid()) { |
|
| 2262 | - foreach ($form->subforms() as $question_group_id => $question_group_form) { |
|
| 2263 | - foreach ($question_group_form->inputs() as $question_id => $input) { |
|
| 2264 | - $where_conditions = array( |
|
| 2265 | - 'QST_ID' => $question_id, |
|
| 2266 | - 'REG_ID' => $REG_ID, |
|
| 2267 | - ); |
|
| 2268 | - $possibly_new_values = array( |
|
| 2269 | - 'ANS_value' => $input->normalized_value(), |
|
| 2270 | - ); |
|
| 2271 | - $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
|
| 2272 | - if ($answer instanceof EE_Answer) { |
|
| 2273 | - $success = $answer->save($possibly_new_values); |
|
| 2274 | - } else { |
|
| 2275 | - //insert it then |
|
| 2276 | - $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
| 2277 | - $answer = EE_Answer::new_instance($cols_n_vals); |
|
| 2278 | - $success = $answer->save(); |
|
| 2279 | - } |
|
| 2280 | - } |
|
| 2281 | - } |
|
| 2282 | - } else { |
|
| 2283 | - EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2284 | - } |
|
| 2285 | - return $success; |
|
| 2286 | - } |
|
| 2287 | - |
|
| 2288 | - |
|
| 2289 | - /** |
|
| 2290 | - * generates HTML for the Registration main meta box |
|
| 2291 | - * |
|
| 2292 | - * @access public |
|
| 2293 | - * @return void |
|
| 2294 | - * @throws DomainException |
|
| 2295 | - * @throws EE_Error |
|
| 2296 | - */ |
|
| 2297 | - public function _reg_attendees_meta_box() |
|
| 2298 | - { |
|
| 2299 | - $REG = EEM_Registration::instance(); |
|
| 2300 | - //get all other registrations on this transaction, and cache |
|
| 2301 | - //the attendees for them so we don't have to run another query using force_join |
|
| 2302 | - $registrations = $REG->get_all(array( |
|
| 2303 | - array( |
|
| 2304 | - 'TXN_ID' => $this->_registration->transaction_ID(), |
|
| 2305 | - 'REG_ID' => array('!=', $this->_registration->ID()), |
|
| 2306 | - ), |
|
| 2307 | - 'force_join' => array('Attendee'), |
|
| 2308 | - )); |
|
| 2309 | - $this->_template_args['attendees'] = array(); |
|
| 2310 | - $this->_template_args['attendee_notice'] = ''; |
|
| 2311 | - if (empty($registrations) |
|
| 2312 | - || (is_array($registrations) |
|
| 2313 | - && ! EEH_Array::get_one_item_from_array($registrations)) |
|
| 2314 | - ) { |
|
| 2315 | - EE_Error::add_error( |
|
| 2316 | - esc_html__( |
|
| 2317 | - 'There are no records attached to this registration. Something may have gone wrong with the registration', |
|
| 2318 | - 'event_espresso' |
|
| 2319 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
| 2320 | - ); |
|
| 2321 | - $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
| 2322 | - } else { |
|
| 2323 | - $att_nmbr = 1; |
|
| 2324 | - foreach ($registrations as $registration) { |
|
| 2325 | - /* @var $registration EE_Registration */ |
|
| 2326 | - $attendee = $registration->attendee() |
|
| 2327 | - ? $registration->attendee() |
|
| 2328 | - : EEM_Attendee::instance() |
|
| 2329 | - ->create_default_object(); |
|
| 2330 | - $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID(); |
|
| 2331 | - $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname(); |
|
| 2332 | - $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname(); |
|
| 2333 | - $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email(); |
|
| 2334 | - $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price(); |
|
| 2335 | - $this->_template_args['attendees'][$att_nmbr]['address'] = implode( |
|
| 2336 | - ', ', |
|
| 2337 | - $attendee->full_address_as_array() |
|
| 2338 | - ); |
|
| 2339 | - $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce( |
|
| 2340 | - array( |
|
| 2341 | - 'action' => 'edit_attendee', |
|
| 2342 | - 'post' => $attendee->ID(), |
|
| 2343 | - ), |
|
| 2344 | - REG_ADMIN_URL |
|
| 2345 | - ); |
|
| 2346 | - $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
| 2347 | - $att_nmbr++; |
|
| 2348 | - } |
|
| 2349 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2350 | - } |
|
| 2351 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2352 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2353 | - } |
|
| 2354 | - |
|
| 2355 | - |
|
| 2356 | - /** |
|
| 2357 | - * generates HTML for the Edit Registration side meta box |
|
| 2358 | - * |
|
| 2359 | - * @access public |
|
| 2360 | - * @return void |
|
| 2361 | - * @throws DomainException |
|
| 2362 | - * @throws EE_Error |
|
| 2363 | - */ |
|
| 2364 | - public function _reg_registrant_side_meta_box() |
|
| 2365 | - { |
|
| 2366 | - /*@var $attendee EE_Attendee */ |
|
| 2367 | - $att_check = $this->_registration->attendee(); |
|
| 2368 | - $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object(); |
|
| 2369 | - //now let's determine if this is not the primary registration. If it isn't then we set the |
|
| 2370 | - //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the |
|
| 2371 | - //primary registration object (that way we know if we need to show create button or not) |
|
| 2372 | - if ( ! $this->_registration->is_primary_registrant()) { |
|
| 2373 | - $primary_registration = $this->_registration->get_primary_registration(); |
|
| 2374 | - $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
| 2375 | - : null; |
|
| 2376 | - if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
| 2377 | - //in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own |
|
| 2378 | - //custom attendee object so let's not worry about the primary reg. |
|
| 2379 | - $primary_registration = null; |
|
| 2380 | - } |
|
| 2381 | - } else { |
|
| 2382 | - $primary_registration = null; |
|
| 2383 | - } |
|
| 2384 | - $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
| 2385 | - $this->_template_args['fname'] = $attendee->fname(); |
|
| 2386 | - $this->_template_args['lname'] = $attendee->lname(); |
|
| 2387 | - $this->_template_args['email'] = $attendee->email(); |
|
| 2388 | - $this->_template_args['phone'] = $attendee->phone(); |
|
| 2389 | - $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
| 2390 | - //edit link |
|
| 2391 | - $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2392 | - 'action' => 'edit_attendee', |
|
| 2393 | - 'post' => $attendee->ID(), |
|
| 2394 | - ), REG_ADMIN_URL); |
|
| 2395 | - $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso'); |
|
| 2396 | - //create link |
|
| 2397 | - $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2398 | - ? EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2399 | - 'action' => 'duplicate_attendee', |
|
| 2400 | - '_REG_ID' => $this->_registration->ID(), |
|
| 2401 | - ), REG_ADMIN_URL) : ''; |
|
| 2402 | - $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso'); |
|
| 2403 | - $this->_template_args['att_check'] = $att_check; |
|
| 2404 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2405 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2406 | - } |
|
| 2407 | - |
|
| 2408 | - |
|
| 2409 | - /** |
|
| 2410 | - * trash or restore registrations |
|
| 2411 | - * |
|
| 2412 | - * @param boolean $trash whether to archive or restore |
|
| 2413 | - * @return void |
|
| 2414 | - * @throws EE_Error |
|
| 2415 | - * @throws RuntimeException |
|
| 2416 | - * @access protected |
|
| 2417 | - */ |
|
| 2418 | - protected function _trash_or_restore_registrations($trash = true) |
|
| 2419 | - { |
|
| 2420 | - //if empty _REG_ID then get out because there's nothing to do |
|
| 2421 | - if (empty($this->_req_data['_REG_ID'])) { |
|
| 2422 | - EE_Error::add_error( |
|
| 2423 | - sprintf( |
|
| 2424 | - esc_html__( |
|
| 2425 | - 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
|
| 2426 | - 'event_espresso' |
|
| 2427 | - ), |
|
| 2428 | - $trash ? 'trash' : 'restore' |
|
| 2429 | - ), |
|
| 2430 | - __FILE__, __LINE__, __FUNCTION__ |
|
| 2431 | - ); |
|
| 2432 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 2433 | - } |
|
| 2434 | - $success = 0; |
|
| 2435 | - $overwrite_msgs = false; |
|
| 2436 | - //Checkboxes |
|
| 2437 | - if ( ! is_array($this->_req_data['_REG_ID'])) { |
|
| 2438 | - $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']); |
|
| 2439 | - } |
|
| 2440 | - $reg_count = count($this->_req_data['_REG_ID']); |
|
| 2441 | - // cycle thru checkboxes |
|
| 2442 | - foreach ($this->_req_data['_REG_ID'] as $REG_ID) { |
|
| 2443 | - /** @var EE_Registration $REG */ |
|
| 2444 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 2445 | - $payments = $REG->registration_payments(); |
|
| 2446 | - if (! empty($payments)) { |
|
| 2447 | - $name = $REG->attendee() instanceof EE_Attendee |
|
| 2448 | - ? $REG->attendee()->full_name() |
|
| 2449 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 2450 | - $overwrite_msgs = true; |
|
| 2451 | - EE_Error::add_error( |
|
| 2452 | - sprintf( |
|
| 2453 | - esc_html__( |
|
| 2454 | - 'The registration for %s could not be trashed because it has payments attached to the related transaction. If you wish to trash this registration you must first delete the payments on the related transaction.', |
|
| 2455 | - 'event_espresso' |
|
| 2456 | - ), |
|
| 2457 | - $name |
|
| 2458 | - ), |
|
| 2459 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2460 | - ); |
|
| 2461 | - //can't trash this registration because it has payments. |
|
| 2462 | - continue; |
|
| 2463 | - } |
|
| 2464 | - $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2465 | - if ($updated) { |
|
| 2466 | - $success++; |
|
| 2467 | - } |
|
| 2468 | - } |
|
| 2469 | - $this->_redirect_after_action( |
|
| 2470 | - $success === $reg_count, // were ALL registrations affected? |
|
| 2471 | - $success > 1 |
|
| 2472 | - ? esc_html__('Registrations', 'event_espresso') |
|
| 2473 | - : esc_html__('Registration', 'event_espresso'), |
|
| 2474 | - $trash |
|
| 2475 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 2476 | - : esc_html__('restored', 'event_espresso'), |
|
| 2477 | - array('action' => 'default'), |
|
| 2478 | - $overwrite_msgs |
|
| 2479 | - ); |
|
| 2480 | - } |
|
| 2481 | - |
|
| 2482 | - |
|
| 2483 | - /** |
|
| 2484 | - * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
| 2485 | - * registration but also. |
|
| 2486 | - * 1. Removing relations to EE_Attendee |
|
| 2487 | - * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
| 2488 | - * ALSO trashed. |
|
| 2489 | - * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
| 2490 | - * 4. Removing relationships between all tickets and the related registrations |
|
| 2491 | - * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
| 2492 | - * 6. Deleting permanently any related Checkins. |
|
| 2493 | - * |
|
| 2494 | - * @return void |
|
| 2495 | - * @throws EE_Error |
|
| 2496 | - */ |
|
| 2497 | - protected function _delete_registrations() |
|
| 2498 | - { |
|
| 2499 | - $REG_MDL = EEM_Registration::instance(); |
|
| 2500 | - $success = 1; |
|
| 2501 | - //Checkboxes |
|
| 2502 | - if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
| 2503 | - // if array has more than one element than success message should be plural |
|
| 2504 | - $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
| 2505 | - // cycle thru checkboxes |
|
| 2506 | - while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
| 2507 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2508 | - if ( ! $REG instanceof EE_Registration) { |
|
| 2509 | - continue; |
|
| 2510 | - } |
|
| 2511 | - $deleted = $this->_delete_registration($REG); |
|
| 2512 | - if ( ! $deleted) { |
|
| 2513 | - $success = 0; |
|
| 2514 | - } |
|
| 2515 | - } |
|
| 2516 | - } else { |
|
| 2517 | - // grab single id and delete |
|
| 2518 | - $REG_ID = $this->_req_data['_REG_ID']; |
|
| 2519 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2520 | - $deleted = $this->_delete_registration($REG); |
|
| 2521 | - if ( ! $deleted) { |
|
| 2522 | - $success = 0; |
|
| 2523 | - } |
|
| 2524 | - } |
|
| 2525 | - $what = $success > 1 |
|
| 2526 | - ? esc_html__('Registrations', 'event_espresso') |
|
| 2527 | - : esc_html__('Registration', 'event_espresso'); |
|
| 2528 | - $action_desc = esc_html__('permanently deleted.', 'event_espresso'); |
|
| 2529 | - $this->_redirect_after_action( |
|
| 2530 | - $success, |
|
| 2531 | - $what, |
|
| 2532 | - $action_desc, |
|
| 2533 | - array('action' => 'default'), |
|
| 2534 | - true |
|
| 2535 | - ); |
|
| 2536 | - } |
|
| 2537 | - |
|
| 2538 | - |
|
| 2539 | - /** |
|
| 2540 | - * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
| 2541 | - * models get affected. |
|
| 2542 | - * |
|
| 2543 | - * @param EE_Registration $REG registration to be deleted permenantly |
|
| 2544 | - * @return bool true = successful deletion, false = fail. |
|
| 2545 | - * @throws EE_Error |
|
| 2546 | - */ |
|
| 2547 | - protected function _delete_registration(EE_Registration $REG) |
|
| 2548 | - { |
|
| 2549 | - //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related |
|
| 2550 | - //registrations on the transaction that are NOT trashed. |
|
| 2551 | - $TXN = $REG->get_first_related('Transaction'); |
|
| 2552 | - $REGS = $TXN->get_many_related('Registration'); |
|
| 2553 | - $all_trashed = true; |
|
| 2554 | - foreach ($REGS as $registration) { |
|
| 2555 | - if ( ! $registration->get('REG_deleted')) { |
|
| 2556 | - $all_trashed = false; |
|
| 2557 | - } |
|
| 2558 | - } |
|
| 2559 | - if ( ! $all_trashed) { |
|
| 2560 | - EE_Error::add_error( |
|
| 2561 | - esc_html__( |
|
| 2562 | - 'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well. These registrations will be permanently deleted in the same action.', |
|
| 2563 | - 'event_espresso' |
|
| 2564 | - ), |
|
| 2565 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2566 | - ); |
|
| 2567 | - return false; |
|
| 2568 | - } |
|
| 2569 | - //k made it here so that means we can delete all the related transactions and their answers (but let's do them |
|
| 2570 | - //separately from THIS one). |
|
| 2571 | - foreach ($REGS as $registration) { |
|
| 2572 | - //delete related answers |
|
| 2573 | - $registration->delete_related_permanently('Answer'); |
|
| 2574 | - //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
| 2575 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 2576 | - if ($attendee instanceof EE_Attendee) { |
|
| 2577 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2578 | - } |
|
| 2579 | - //now remove relationships to tickets on this registration. |
|
| 2580 | - $registration->_remove_relations('Ticket'); |
|
| 2581 | - //now delete permanently the checkins related to this registration. |
|
| 2582 | - $registration->delete_related_permanently('Checkin'); |
|
| 2583 | - if ($registration->ID() === $REG->ID()) { |
|
| 2584 | - continue; |
|
| 2585 | - } //we don't want to delete permanently the existing registration just yet. |
|
| 2586 | - //remove relation to transaction for these registrations if NOT the existing registrations |
|
| 2587 | - $registration->_remove_relations('Transaction'); |
|
| 2588 | - //delete permanently any related messages. |
|
| 2589 | - $registration->delete_related_permanently('Message'); |
|
| 2590 | - //now delete this registration permanently |
|
| 2591 | - $registration->delete_permanently(); |
|
| 2592 | - } |
|
| 2593 | - //now all related registrations on the transaction are handled. So let's just handle this registration itself |
|
| 2594 | - // (the transaction and line items should be all that's left). |
|
| 2595 | - // delete the line items related to the transaction for this registration. |
|
| 2596 | - $TXN->delete_related_permanently('Line_Item'); |
|
| 2597 | - //we need to remove all the relationships on the transaction |
|
| 2598 | - $TXN->delete_related_permanently('Payment'); |
|
| 2599 | - $TXN->delete_related_permanently('Extra_Meta'); |
|
| 2600 | - $TXN->delete_related_permanently('Message'); |
|
| 2601 | - //now we can delete this REG permanently (and the transaction of course) |
|
| 2602 | - $REG->delete_related_permanently('Transaction'); |
|
| 2603 | - return $REG->delete_permanently(); |
|
| 2604 | - } |
|
| 2605 | - |
|
| 2606 | - |
|
| 2607 | - /** |
|
| 2608 | - * generates HTML for the Register New Attendee Admin page |
|
| 2609 | - * |
|
| 2610 | - * @access private |
|
| 2611 | - * @throws DomainException |
|
| 2612 | - * @throws EE_Error |
|
| 2613 | - */ |
|
| 2614 | - public function new_registration() |
|
| 2615 | - { |
|
| 2616 | - if ( ! $this->_set_reg_event()) { |
|
| 2617 | - throw new EE_Error( |
|
| 2618 | - esc_html__( |
|
| 2619 | - 'Unable to continue with registering because there is no Event ID in the request', |
|
| 2620 | - 'event_espresso' |
|
| 2621 | - ) |
|
| 2622 | - ); |
|
| 2623 | - } |
|
| 2624 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2625 | - // gotta start with a clean slate if we're not coming here via ajax |
|
| 2626 | - if ( ! defined('DOING_AJAX') |
|
| 2627 | - && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error'])) |
|
| 2628 | - ) { |
|
| 2629 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2630 | - } |
|
| 2631 | - $this->_template_args['event_name'] = ''; |
|
| 2632 | - // event name |
|
| 2633 | - if ($this->_reg_event) { |
|
| 2634 | - $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
| 2635 | - $edit_event_url = self::add_query_args_and_nonce(array( |
|
| 2636 | - 'action' => 'edit', |
|
| 2637 | - 'post' => $this->_reg_event->ID(), |
|
| 2638 | - ), EVENTS_ADMIN_URL); |
|
| 2639 | - $edit_event_lnk = '<a href="' |
|
| 2640 | - . $edit_event_url |
|
| 2641 | - . '" title="' |
|
| 2642 | - . esc_attr__('Edit ', 'event_espresso') |
|
| 2643 | - . $this->_reg_event->name() |
|
| 2644 | - . '">' |
|
| 2645 | - . esc_html__('Edit Event', 'event_espresso') |
|
| 2646 | - . '</a>'; |
|
| 2647 | - $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 2648 | - . $edit_event_lnk |
|
| 2649 | - . '</span>'; |
|
| 2650 | - } |
|
| 2651 | - $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
| 2652 | - if (defined('DOING_AJAX')) { |
|
| 2653 | - $this->_return_json(); |
|
| 2654 | - } |
|
| 2655 | - // grab header |
|
| 2656 | - $template_path = |
|
| 2657 | - REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2658 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
| 2659 | - $this->_template_args, true); |
|
| 2660 | - //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 2661 | - // the details template wrapper |
|
| 2662 | - $this->display_admin_page_with_sidebar(); |
|
| 2663 | - } |
|
| 2664 | - |
|
| 2665 | - |
|
| 2666 | - /** |
|
| 2667 | - * This returns the content for a registration step |
|
| 2668 | - * |
|
| 2669 | - * @access protected |
|
| 2670 | - * @return string html |
|
| 2671 | - * @throws DomainException |
|
| 2672 | - * @throws EE_Error |
|
| 2673 | - */ |
|
| 2674 | - protected function _get_registration_step_content() |
|
| 2675 | - { |
|
| 2676 | - if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
| 2677 | - $warning_msg = sprintf( |
|
| 2678 | - esc_html__( |
|
| 2679 | - '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s', |
|
| 2680 | - 'event_espresso' |
|
| 2681 | - ), |
|
| 2682 | - '<br />', |
|
| 2683 | - '<h3 class="important-notice">', |
|
| 2684 | - '</h3>', |
|
| 2685 | - '<div class="float-right">', |
|
| 2686 | - '<span id="redirect_timer" class="important-notice">30</span>', |
|
| 2687 | - '</div>', |
|
| 2688 | - '<b>', |
|
| 2689 | - '</b>' |
|
| 2690 | - ); |
|
| 2691 | - return ' |
|
| 2192 | + } |
|
| 2193 | + |
|
| 2194 | + |
|
| 2195 | + /** |
|
| 2196 | + * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
| 2197 | + * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
| 2198 | + * to display the page |
|
| 2199 | + * |
|
| 2200 | + * @access protected |
|
| 2201 | + * @return void |
|
| 2202 | + * @throws EE_Error |
|
| 2203 | + */ |
|
| 2204 | + protected function _update_attendee_registration_form() |
|
| 2205 | + { |
|
| 2206 | + do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
| 2207 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 2208 | + $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 2209 | + $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
| 2210 | + if ($success) { |
|
| 2211 | + $what = esc_html__('Registration Form', 'event_espresso'); |
|
| 2212 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
|
| 2213 | + : array('action' => 'default'); |
|
| 2214 | + $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route); |
|
| 2215 | + } |
|
| 2216 | + } |
|
| 2217 | + } |
|
| 2218 | + |
|
| 2219 | + |
|
| 2220 | + /** |
|
| 2221 | + * Gets the form for saving registrations custom questions (if done |
|
| 2222 | + * previously retrieves the cached form object, which may have validation errors in it) |
|
| 2223 | + * |
|
| 2224 | + * @param int $REG_ID |
|
| 2225 | + * @return EE_Registration_Custom_Questions_Form |
|
| 2226 | + * @throws EE_Error |
|
| 2227 | + */ |
|
| 2228 | + protected function _get_reg_custom_questions_form($REG_ID) |
|
| 2229 | + { |
|
| 2230 | + if ( ! $this->_reg_custom_questions_form) { |
|
| 2231 | + require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 2232 | + $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
| 2233 | + EEM_Registration::instance()->get_one_by_ID($REG_ID) |
|
| 2234 | + ); |
|
| 2235 | + $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
| 2236 | + } |
|
| 2237 | + return $this->_reg_custom_questions_form; |
|
| 2238 | + } |
|
| 2239 | + |
|
| 2240 | + |
|
| 2241 | + /** |
|
| 2242 | + * Saves |
|
| 2243 | + * |
|
| 2244 | + * @access private |
|
| 2245 | + * @param bool $REG_ID |
|
| 2246 | + * @return bool |
|
| 2247 | + * @throws EE_Error |
|
| 2248 | + */ |
|
| 2249 | + private function _save_reg_custom_questions_form($REG_ID = false) |
|
| 2250 | + { |
|
| 2251 | + if ( ! $REG_ID) { |
|
| 2252 | + EE_Error::add_error( |
|
| 2253 | + esc_html__( |
|
| 2254 | + 'An error occurred. No registration ID was received.', 'event_espresso'), |
|
| 2255 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2256 | + ); |
|
| 2257 | + } |
|
| 2258 | + $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
| 2259 | + $form->receive_form_submission($this->_req_data); |
|
| 2260 | + $success = false; |
|
| 2261 | + if ($form->is_valid()) { |
|
| 2262 | + foreach ($form->subforms() as $question_group_id => $question_group_form) { |
|
| 2263 | + foreach ($question_group_form->inputs() as $question_id => $input) { |
|
| 2264 | + $where_conditions = array( |
|
| 2265 | + 'QST_ID' => $question_id, |
|
| 2266 | + 'REG_ID' => $REG_ID, |
|
| 2267 | + ); |
|
| 2268 | + $possibly_new_values = array( |
|
| 2269 | + 'ANS_value' => $input->normalized_value(), |
|
| 2270 | + ); |
|
| 2271 | + $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
|
| 2272 | + if ($answer instanceof EE_Answer) { |
|
| 2273 | + $success = $answer->save($possibly_new_values); |
|
| 2274 | + } else { |
|
| 2275 | + //insert it then |
|
| 2276 | + $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
| 2277 | + $answer = EE_Answer::new_instance($cols_n_vals); |
|
| 2278 | + $success = $answer->save(); |
|
| 2279 | + } |
|
| 2280 | + } |
|
| 2281 | + } |
|
| 2282 | + } else { |
|
| 2283 | + EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2284 | + } |
|
| 2285 | + return $success; |
|
| 2286 | + } |
|
| 2287 | + |
|
| 2288 | + |
|
| 2289 | + /** |
|
| 2290 | + * generates HTML for the Registration main meta box |
|
| 2291 | + * |
|
| 2292 | + * @access public |
|
| 2293 | + * @return void |
|
| 2294 | + * @throws DomainException |
|
| 2295 | + * @throws EE_Error |
|
| 2296 | + */ |
|
| 2297 | + public function _reg_attendees_meta_box() |
|
| 2298 | + { |
|
| 2299 | + $REG = EEM_Registration::instance(); |
|
| 2300 | + //get all other registrations on this transaction, and cache |
|
| 2301 | + //the attendees for them so we don't have to run another query using force_join |
|
| 2302 | + $registrations = $REG->get_all(array( |
|
| 2303 | + array( |
|
| 2304 | + 'TXN_ID' => $this->_registration->transaction_ID(), |
|
| 2305 | + 'REG_ID' => array('!=', $this->_registration->ID()), |
|
| 2306 | + ), |
|
| 2307 | + 'force_join' => array('Attendee'), |
|
| 2308 | + )); |
|
| 2309 | + $this->_template_args['attendees'] = array(); |
|
| 2310 | + $this->_template_args['attendee_notice'] = ''; |
|
| 2311 | + if (empty($registrations) |
|
| 2312 | + || (is_array($registrations) |
|
| 2313 | + && ! EEH_Array::get_one_item_from_array($registrations)) |
|
| 2314 | + ) { |
|
| 2315 | + EE_Error::add_error( |
|
| 2316 | + esc_html__( |
|
| 2317 | + 'There are no records attached to this registration. Something may have gone wrong with the registration', |
|
| 2318 | + 'event_espresso' |
|
| 2319 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
| 2320 | + ); |
|
| 2321 | + $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
| 2322 | + } else { |
|
| 2323 | + $att_nmbr = 1; |
|
| 2324 | + foreach ($registrations as $registration) { |
|
| 2325 | + /* @var $registration EE_Registration */ |
|
| 2326 | + $attendee = $registration->attendee() |
|
| 2327 | + ? $registration->attendee() |
|
| 2328 | + : EEM_Attendee::instance() |
|
| 2329 | + ->create_default_object(); |
|
| 2330 | + $this->_template_args['attendees'][$att_nmbr]['STS_ID'] = $registration->status_ID(); |
|
| 2331 | + $this->_template_args['attendees'][$att_nmbr]['fname'] = $attendee->fname(); |
|
| 2332 | + $this->_template_args['attendees'][$att_nmbr]['lname'] = $attendee->lname(); |
|
| 2333 | + $this->_template_args['attendees'][$att_nmbr]['email'] = $attendee->email(); |
|
| 2334 | + $this->_template_args['attendees'][$att_nmbr]['final_price'] = $registration->final_price(); |
|
| 2335 | + $this->_template_args['attendees'][$att_nmbr]['address'] = implode( |
|
| 2336 | + ', ', |
|
| 2337 | + $attendee->full_address_as_array() |
|
| 2338 | + ); |
|
| 2339 | + $this->_template_args['attendees'][$att_nmbr]['att_link'] = self::add_query_args_and_nonce( |
|
| 2340 | + array( |
|
| 2341 | + 'action' => 'edit_attendee', |
|
| 2342 | + 'post' => $attendee->ID(), |
|
| 2343 | + ), |
|
| 2344 | + REG_ADMIN_URL |
|
| 2345 | + ); |
|
| 2346 | + $this->_template_args['attendees'][$att_nmbr]['event_name'] = $registration->event_obj()->name(); |
|
| 2347 | + $att_nmbr++; |
|
| 2348 | + } |
|
| 2349 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2350 | + } |
|
| 2351 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2352 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2353 | + } |
|
| 2354 | + |
|
| 2355 | + |
|
| 2356 | + /** |
|
| 2357 | + * generates HTML for the Edit Registration side meta box |
|
| 2358 | + * |
|
| 2359 | + * @access public |
|
| 2360 | + * @return void |
|
| 2361 | + * @throws DomainException |
|
| 2362 | + * @throws EE_Error |
|
| 2363 | + */ |
|
| 2364 | + public function _reg_registrant_side_meta_box() |
|
| 2365 | + { |
|
| 2366 | + /*@var $attendee EE_Attendee */ |
|
| 2367 | + $att_check = $this->_registration->attendee(); |
|
| 2368 | + $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object(); |
|
| 2369 | + //now let's determine if this is not the primary registration. If it isn't then we set the |
|
| 2370 | + //primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the |
|
| 2371 | + //primary registration object (that way we know if we need to show create button or not) |
|
| 2372 | + if ( ! $this->_registration->is_primary_registrant()) { |
|
| 2373 | + $primary_registration = $this->_registration->get_primary_registration(); |
|
| 2374 | + $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
| 2375 | + : null; |
|
| 2376 | + if ( ! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
| 2377 | + //in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own |
|
| 2378 | + //custom attendee object so let's not worry about the primary reg. |
|
| 2379 | + $primary_registration = null; |
|
| 2380 | + } |
|
| 2381 | + } else { |
|
| 2382 | + $primary_registration = null; |
|
| 2383 | + } |
|
| 2384 | + $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
| 2385 | + $this->_template_args['fname'] = $attendee->fname(); |
|
| 2386 | + $this->_template_args['lname'] = $attendee->lname(); |
|
| 2387 | + $this->_template_args['email'] = $attendee->email(); |
|
| 2388 | + $this->_template_args['phone'] = $attendee->phone(); |
|
| 2389 | + $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
| 2390 | + //edit link |
|
| 2391 | + $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2392 | + 'action' => 'edit_attendee', |
|
| 2393 | + 'post' => $attendee->ID(), |
|
| 2394 | + ), REG_ADMIN_URL); |
|
| 2395 | + $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso'); |
|
| 2396 | + //create link |
|
| 2397 | + $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2398 | + ? EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 2399 | + 'action' => 'duplicate_attendee', |
|
| 2400 | + '_REG_ID' => $this->_registration->ID(), |
|
| 2401 | + ), REG_ADMIN_URL) : ''; |
|
| 2402 | + $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso'); |
|
| 2403 | + $this->_template_args['att_check'] = $att_check; |
|
| 2404 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2405 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2406 | + } |
|
| 2407 | + |
|
| 2408 | + |
|
| 2409 | + /** |
|
| 2410 | + * trash or restore registrations |
|
| 2411 | + * |
|
| 2412 | + * @param boolean $trash whether to archive or restore |
|
| 2413 | + * @return void |
|
| 2414 | + * @throws EE_Error |
|
| 2415 | + * @throws RuntimeException |
|
| 2416 | + * @access protected |
|
| 2417 | + */ |
|
| 2418 | + protected function _trash_or_restore_registrations($trash = true) |
|
| 2419 | + { |
|
| 2420 | + //if empty _REG_ID then get out because there's nothing to do |
|
| 2421 | + if (empty($this->_req_data['_REG_ID'])) { |
|
| 2422 | + EE_Error::add_error( |
|
| 2423 | + sprintf( |
|
| 2424 | + esc_html__( |
|
| 2425 | + 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
|
| 2426 | + 'event_espresso' |
|
| 2427 | + ), |
|
| 2428 | + $trash ? 'trash' : 'restore' |
|
| 2429 | + ), |
|
| 2430 | + __FILE__, __LINE__, __FUNCTION__ |
|
| 2431 | + ); |
|
| 2432 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 2433 | + } |
|
| 2434 | + $success = 0; |
|
| 2435 | + $overwrite_msgs = false; |
|
| 2436 | + //Checkboxes |
|
| 2437 | + if ( ! is_array($this->_req_data['_REG_ID'])) { |
|
| 2438 | + $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']); |
|
| 2439 | + } |
|
| 2440 | + $reg_count = count($this->_req_data['_REG_ID']); |
|
| 2441 | + // cycle thru checkboxes |
|
| 2442 | + foreach ($this->_req_data['_REG_ID'] as $REG_ID) { |
|
| 2443 | + /** @var EE_Registration $REG */ |
|
| 2444 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 2445 | + $payments = $REG->registration_payments(); |
|
| 2446 | + if (! empty($payments)) { |
|
| 2447 | + $name = $REG->attendee() instanceof EE_Attendee |
|
| 2448 | + ? $REG->attendee()->full_name() |
|
| 2449 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 2450 | + $overwrite_msgs = true; |
|
| 2451 | + EE_Error::add_error( |
|
| 2452 | + sprintf( |
|
| 2453 | + esc_html__( |
|
| 2454 | + 'The registration for %s could not be trashed because it has payments attached to the related transaction. If you wish to trash this registration you must first delete the payments on the related transaction.', |
|
| 2455 | + 'event_espresso' |
|
| 2456 | + ), |
|
| 2457 | + $name |
|
| 2458 | + ), |
|
| 2459 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2460 | + ); |
|
| 2461 | + //can't trash this registration because it has payments. |
|
| 2462 | + continue; |
|
| 2463 | + } |
|
| 2464 | + $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2465 | + if ($updated) { |
|
| 2466 | + $success++; |
|
| 2467 | + } |
|
| 2468 | + } |
|
| 2469 | + $this->_redirect_after_action( |
|
| 2470 | + $success === $reg_count, // were ALL registrations affected? |
|
| 2471 | + $success > 1 |
|
| 2472 | + ? esc_html__('Registrations', 'event_espresso') |
|
| 2473 | + : esc_html__('Registration', 'event_espresso'), |
|
| 2474 | + $trash |
|
| 2475 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 2476 | + : esc_html__('restored', 'event_espresso'), |
|
| 2477 | + array('action' => 'default'), |
|
| 2478 | + $overwrite_msgs |
|
| 2479 | + ); |
|
| 2480 | + } |
|
| 2481 | + |
|
| 2482 | + |
|
| 2483 | + /** |
|
| 2484 | + * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
| 2485 | + * registration but also. |
|
| 2486 | + * 1. Removing relations to EE_Attendee |
|
| 2487 | + * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
| 2488 | + * ALSO trashed. |
|
| 2489 | + * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
| 2490 | + * 4. Removing relationships between all tickets and the related registrations |
|
| 2491 | + * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
| 2492 | + * 6. Deleting permanently any related Checkins. |
|
| 2493 | + * |
|
| 2494 | + * @return void |
|
| 2495 | + * @throws EE_Error |
|
| 2496 | + */ |
|
| 2497 | + protected function _delete_registrations() |
|
| 2498 | + { |
|
| 2499 | + $REG_MDL = EEM_Registration::instance(); |
|
| 2500 | + $success = 1; |
|
| 2501 | + //Checkboxes |
|
| 2502 | + if ( ! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
| 2503 | + // if array has more than one element than success message should be plural |
|
| 2504 | + $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
| 2505 | + // cycle thru checkboxes |
|
| 2506 | + while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
| 2507 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2508 | + if ( ! $REG instanceof EE_Registration) { |
|
| 2509 | + continue; |
|
| 2510 | + } |
|
| 2511 | + $deleted = $this->_delete_registration($REG); |
|
| 2512 | + if ( ! $deleted) { |
|
| 2513 | + $success = 0; |
|
| 2514 | + } |
|
| 2515 | + } |
|
| 2516 | + } else { |
|
| 2517 | + // grab single id and delete |
|
| 2518 | + $REG_ID = $this->_req_data['_REG_ID']; |
|
| 2519 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2520 | + $deleted = $this->_delete_registration($REG); |
|
| 2521 | + if ( ! $deleted) { |
|
| 2522 | + $success = 0; |
|
| 2523 | + } |
|
| 2524 | + } |
|
| 2525 | + $what = $success > 1 |
|
| 2526 | + ? esc_html__('Registrations', 'event_espresso') |
|
| 2527 | + : esc_html__('Registration', 'event_espresso'); |
|
| 2528 | + $action_desc = esc_html__('permanently deleted.', 'event_espresso'); |
|
| 2529 | + $this->_redirect_after_action( |
|
| 2530 | + $success, |
|
| 2531 | + $what, |
|
| 2532 | + $action_desc, |
|
| 2533 | + array('action' => 'default'), |
|
| 2534 | + true |
|
| 2535 | + ); |
|
| 2536 | + } |
|
| 2537 | + |
|
| 2538 | + |
|
| 2539 | + /** |
|
| 2540 | + * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
| 2541 | + * models get affected. |
|
| 2542 | + * |
|
| 2543 | + * @param EE_Registration $REG registration to be deleted permenantly |
|
| 2544 | + * @return bool true = successful deletion, false = fail. |
|
| 2545 | + * @throws EE_Error |
|
| 2546 | + */ |
|
| 2547 | + protected function _delete_registration(EE_Registration $REG) |
|
| 2548 | + { |
|
| 2549 | + //first we start with the transaction... ultimately, we WILL not delete permanently if there are any related |
|
| 2550 | + //registrations on the transaction that are NOT trashed. |
|
| 2551 | + $TXN = $REG->get_first_related('Transaction'); |
|
| 2552 | + $REGS = $TXN->get_many_related('Registration'); |
|
| 2553 | + $all_trashed = true; |
|
| 2554 | + foreach ($REGS as $registration) { |
|
| 2555 | + if ( ! $registration->get('REG_deleted')) { |
|
| 2556 | + $all_trashed = false; |
|
| 2557 | + } |
|
| 2558 | + } |
|
| 2559 | + if ( ! $all_trashed) { |
|
| 2560 | + EE_Error::add_error( |
|
| 2561 | + esc_html__( |
|
| 2562 | + 'Unable to permanently delete this registration. Before this registration can be permanently deleted, all registrations made in the same transaction must be trashed as well. These registrations will be permanently deleted in the same action.', |
|
| 2563 | + 'event_espresso' |
|
| 2564 | + ), |
|
| 2565 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2566 | + ); |
|
| 2567 | + return false; |
|
| 2568 | + } |
|
| 2569 | + //k made it here so that means we can delete all the related transactions and their answers (but let's do them |
|
| 2570 | + //separately from THIS one). |
|
| 2571 | + foreach ($REGS as $registration) { |
|
| 2572 | + //delete related answers |
|
| 2573 | + $registration->delete_related_permanently('Answer'); |
|
| 2574 | + //remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
| 2575 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 2576 | + if ($attendee instanceof EE_Attendee) { |
|
| 2577 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2578 | + } |
|
| 2579 | + //now remove relationships to tickets on this registration. |
|
| 2580 | + $registration->_remove_relations('Ticket'); |
|
| 2581 | + //now delete permanently the checkins related to this registration. |
|
| 2582 | + $registration->delete_related_permanently('Checkin'); |
|
| 2583 | + if ($registration->ID() === $REG->ID()) { |
|
| 2584 | + continue; |
|
| 2585 | + } //we don't want to delete permanently the existing registration just yet. |
|
| 2586 | + //remove relation to transaction for these registrations if NOT the existing registrations |
|
| 2587 | + $registration->_remove_relations('Transaction'); |
|
| 2588 | + //delete permanently any related messages. |
|
| 2589 | + $registration->delete_related_permanently('Message'); |
|
| 2590 | + //now delete this registration permanently |
|
| 2591 | + $registration->delete_permanently(); |
|
| 2592 | + } |
|
| 2593 | + //now all related registrations on the transaction are handled. So let's just handle this registration itself |
|
| 2594 | + // (the transaction and line items should be all that's left). |
|
| 2595 | + // delete the line items related to the transaction for this registration. |
|
| 2596 | + $TXN->delete_related_permanently('Line_Item'); |
|
| 2597 | + //we need to remove all the relationships on the transaction |
|
| 2598 | + $TXN->delete_related_permanently('Payment'); |
|
| 2599 | + $TXN->delete_related_permanently('Extra_Meta'); |
|
| 2600 | + $TXN->delete_related_permanently('Message'); |
|
| 2601 | + //now we can delete this REG permanently (and the transaction of course) |
|
| 2602 | + $REG->delete_related_permanently('Transaction'); |
|
| 2603 | + return $REG->delete_permanently(); |
|
| 2604 | + } |
|
| 2605 | + |
|
| 2606 | + |
|
| 2607 | + /** |
|
| 2608 | + * generates HTML for the Register New Attendee Admin page |
|
| 2609 | + * |
|
| 2610 | + * @access private |
|
| 2611 | + * @throws DomainException |
|
| 2612 | + * @throws EE_Error |
|
| 2613 | + */ |
|
| 2614 | + public function new_registration() |
|
| 2615 | + { |
|
| 2616 | + if ( ! $this->_set_reg_event()) { |
|
| 2617 | + throw new EE_Error( |
|
| 2618 | + esc_html__( |
|
| 2619 | + 'Unable to continue with registering because there is no Event ID in the request', |
|
| 2620 | + 'event_espresso' |
|
| 2621 | + ) |
|
| 2622 | + ); |
|
| 2623 | + } |
|
| 2624 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2625 | + // gotta start with a clean slate if we're not coming here via ajax |
|
| 2626 | + if ( ! defined('DOING_AJAX') |
|
| 2627 | + && ( ! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error'])) |
|
| 2628 | + ) { |
|
| 2629 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2630 | + } |
|
| 2631 | + $this->_template_args['event_name'] = ''; |
|
| 2632 | + // event name |
|
| 2633 | + if ($this->_reg_event) { |
|
| 2634 | + $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
| 2635 | + $edit_event_url = self::add_query_args_and_nonce(array( |
|
| 2636 | + 'action' => 'edit', |
|
| 2637 | + 'post' => $this->_reg_event->ID(), |
|
| 2638 | + ), EVENTS_ADMIN_URL); |
|
| 2639 | + $edit_event_lnk = '<a href="' |
|
| 2640 | + . $edit_event_url |
|
| 2641 | + . '" title="' |
|
| 2642 | + . esc_attr__('Edit ', 'event_espresso') |
|
| 2643 | + . $this->_reg_event->name() |
|
| 2644 | + . '">' |
|
| 2645 | + . esc_html__('Edit Event', 'event_espresso') |
|
| 2646 | + . '</a>'; |
|
| 2647 | + $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 2648 | + . $edit_event_lnk |
|
| 2649 | + . '</span>'; |
|
| 2650 | + } |
|
| 2651 | + $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
| 2652 | + if (defined('DOING_AJAX')) { |
|
| 2653 | + $this->_return_json(); |
|
| 2654 | + } |
|
| 2655 | + // grab header |
|
| 2656 | + $template_path = |
|
| 2657 | + REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2658 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template($template_path, |
|
| 2659 | + $this->_template_args, true); |
|
| 2660 | + //$this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 2661 | + // the details template wrapper |
|
| 2662 | + $this->display_admin_page_with_sidebar(); |
|
| 2663 | + } |
|
| 2664 | + |
|
| 2665 | + |
|
| 2666 | + /** |
|
| 2667 | + * This returns the content for a registration step |
|
| 2668 | + * |
|
| 2669 | + * @access protected |
|
| 2670 | + * @return string html |
|
| 2671 | + * @throws DomainException |
|
| 2672 | + * @throws EE_Error |
|
| 2673 | + */ |
|
| 2674 | + protected function _get_registration_step_content() |
|
| 2675 | + { |
|
| 2676 | + if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
| 2677 | + $warning_msg = sprintf( |
|
| 2678 | + esc_html__( |
|
| 2679 | + '%2$sWARNING!!!%3$s%1$sPlease do not use the back button to return to this page for the purpose of adding another registration.%1$sThis can result in lost and/or corrupted data.%1$sIf you wish to add another registration, then please click the%1$s%7$s"Add Another New Registration to Event"%8$s button%1$son the Transaction details page, after you are redirected.%1$s%1$s%4$s redirecting in %5$s seconds %6$s', |
|
| 2680 | + 'event_espresso' |
|
| 2681 | + ), |
|
| 2682 | + '<br />', |
|
| 2683 | + '<h3 class="important-notice">', |
|
| 2684 | + '</h3>', |
|
| 2685 | + '<div class="float-right">', |
|
| 2686 | + '<span id="redirect_timer" class="important-notice">30</span>', |
|
| 2687 | + '</div>', |
|
| 2688 | + '<b>', |
|
| 2689 | + '</b>' |
|
| 2690 | + ); |
|
| 2691 | + return ' |
|
| 2692 | 2692 | <div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div> |
| 2693 | 2693 | <script > |
| 2694 | 2694 | // WHOAH !!! it appears that someone is using the back button from the Transaction admin page |
@@ -2701,792 +2701,792 @@ discard block |
||
| 2701 | 2701 | } |
| 2702 | 2702 | }, 800 ); |
| 2703 | 2703 | </script >'; |
| 2704 | - } |
|
| 2705 | - $template_args = array( |
|
| 2706 | - 'title' => '', |
|
| 2707 | - 'content' => '', |
|
| 2708 | - 'step_button_text' => '', |
|
| 2709 | - 'show_notification_toggle' => false, |
|
| 2710 | - ); |
|
| 2711 | - //to indicate we're processing a new registration |
|
| 2712 | - $hidden_fields = array( |
|
| 2713 | - 'processing_registration' => array( |
|
| 2714 | - 'type' => 'hidden', |
|
| 2715 | - 'value' => 0, |
|
| 2716 | - ), |
|
| 2717 | - 'event_id' => array( |
|
| 2718 | - 'type' => 'hidden', |
|
| 2719 | - 'value' => $this->_reg_event->ID(), |
|
| 2720 | - ), |
|
| 2721 | - ); |
|
| 2722 | - //if the cart is empty then we know we're at step one so we'll display ticket selector |
|
| 2723 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2724 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2725 | - switch ($step) { |
|
| 2726 | - case 'ticket' : |
|
| 2727 | - $hidden_fields['processing_registration']['value'] = 1; |
|
| 2728 | - $template_args['title'] = esc_html__( |
|
| 2729 | - 'Step One: Select the Ticket for this registration', |
|
| 2730 | - 'event_espresso' |
|
| 2731 | - ); |
|
| 2732 | - $template_args['content'] = |
|
| 2733 | - EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
| 2734 | - $template_args['step_button_text'] = esc_html__( |
|
| 2735 | - 'Add Tickets and Continue to Registrant Details', |
|
| 2736 | - 'event_espresso' |
|
| 2737 | - ); |
|
| 2738 | - $template_args['show_notification_toggle'] = false; |
|
| 2739 | - break; |
|
| 2740 | - case 'questions' : |
|
| 2741 | - $hidden_fields['processing_registration']['value'] = 2; |
|
| 2742 | - $template_args['title'] = esc_html__( |
|
| 2743 | - 'Step Two: Add Registrant Details for this Registration', |
|
| 2744 | - 'event_espresso' |
|
| 2745 | - ); |
|
| 2746 | - //in theory we should be able to run EED_SPCO at this point because the cart should have been setup |
|
| 2747 | - // properly by the first process_reg_step run. |
|
| 2748 | - $template_args['content'] = |
|
| 2749 | - EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
| 2750 | - $template_args['step_button_text'] = esc_html__( |
|
| 2751 | - 'Save Registration and Continue to Details', |
|
| 2752 | - 'event_espresso' |
|
| 2753 | - ); |
|
| 2754 | - $template_args['show_notification_toggle'] = true; |
|
| 2755 | - break; |
|
| 2756 | - } |
|
| 2757 | - //we come back to the process_registration_step route. |
|
| 2758 | - $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields); |
|
| 2759 | - return EEH_Template::display_template( |
|
| 2760 | - REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 2761 | - $template_args, |
|
| 2762 | - true |
|
| 2763 | - ); |
|
| 2764 | - } |
|
| 2765 | - |
|
| 2766 | - |
|
| 2767 | - /** |
|
| 2768 | - * set_reg_event |
|
| 2769 | - * |
|
| 2770 | - * @access private |
|
| 2771 | - * @return bool |
|
| 2772 | - * @throws EE_Error |
|
| 2773 | - */ |
|
| 2774 | - private function _set_reg_event() |
|
| 2775 | - { |
|
| 2776 | - if (is_object($this->_reg_event)) { |
|
| 2777 | - return true; |
|
| 2778 | - } |
|
| 2779 | - $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
| 2780 | - if ( ! $EVT_ID) { |
|
| 2781 | - return false; |
|
| 2782 | - } |
|
| 2783 | - $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2784 | - return true; |
|
| 2785 | - } |
|
| 2786 | - |
|
| 2787 | - |
|
| 2788 | - /** |
|
| 2789 | - * process_reg_step |
|
| 2790 | - * |
|
| 2791 | - * @access public |
|
| 2792 | - * @return string |
|
| 2793 | - * @throws DomainException |
|
| 2794 | - * @throws EE_Error |
|
| 2795 | - * @throws RuntimeException |
|
| 2796 | - */ |
|
| 2797 | - public function process_reg_step() |
|
| 2798 | - { |
|
| 2799 | - EE_System::do_not_cache(); |
|
| 2800 | - $this->_set_reg_event(); |
|
| 2801 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2802 | - EE_Registry::instance()->REQ->set('uts', time()); |
|
| 2803 | - //what step are we on? |
|
| 2804 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2805 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2806 | - //if doing ajax then we need to verify the nonce |
|
| 2807 | - if (defined('DOING_AJAX')) { |
|
| 2808 | - $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 2809 | - ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : ''; |
|
| 2810 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 2811 | - } |
|
| 2812 | - switch ($step) { |
|
| 2813 | - case 'ticket' : |
|
| 2814 | - //process ticket selection |
|
| 2815 | - $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
| 2816 | - if ($success) { |
|
| 2817 | - EE_Error::add_success( |
|
| 2818 | - esc_html__( |
|
| 2819 | - 'Tickets Selected. Now complete the registration.', |
|
| 2820 | - 'event_espresso' |
|
| 2821 | - ) |
|
| 2822 | - ); |
|
| 2823 | - } else { |
|
| 2824 | - $query_args['step_error'] = $this->_req_data['step_error'] = true; |
|
| 2825 | - } |
|
| 2826 | - if (defined('DOING_AJAX')) { |
|
| 2827 | - $this->new_registration(); //display next step |
|
| 2828 | - } else { |
|
| 2829 | - $query_args = array( |
|
| 2830 | - 'action' => 'new_registration', |
|
| 2831 | - 'processing_registration' => 1, |
|
| 2832 | - 'event_id' => $this->_reg_event->ID(), |
|
| 2833 | - 'uts' => time(), |
|
| 2834 | - ); |
|
| 2835 | - $this->_redirect_after_action( |
|
| 2836 | - false, |
|
| 2837 | - '', |
|
| 2838 | - '', |
|
| 2839 | - $query_args, |
|
| 2840 | - true |
|
| 2841 | - ); |
|
| 2842 | - } |
|
| 2843 | - break; |
|
| 2844 | - case 'questions' : |
|
| 2845 | - if (! isset( |
|
| 2846 | - $this->_req_data['txn_reg_status_change'], |
|
| 2847 | - $this->_req_data['txn_reg_status_change']['send_notifications']) |
|
| 2848 | - ) { |
|
| 2849 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
| 2850 | - } |
|
| 2851 | - //process registration |
|
| 2852 | - $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
| 2853 | - if ($cart instanceof EE_Cart) { |
|
| 2854 | - $grand_total = $cart->get_cart_grand_total(); |
|
| 2855 | - if ($grand_total instanceof EE_Line_Item) { |
|
| 2856 | - $grand_total->save_this_and_descendants_to_txn(); |
|
| 2857 | - } |
|
| 2858 | - } |
|
| 2859 | - if ( ! $transaction instanceof EE_Transaction) { |
|
| 2860 | - $query_args = array( |
|
| 2861 | - 'action' => 'new_registration', |
|
| 2862 | - 'processing_registration' => 2, |
|
| 2863 | - 'event_id' => $this->_reg_event->ID(), |
|
| 2864 | - 'uts' => time(), |
|
| 2865 | - ); |
|
| 2866 | - if (defined('DOING_AJAX')) { |
|
| 2867 | - //display registration form again because there are errors (maybe validation?) |
|
| 2868 | - $this->new_registration(); |
|
| 2869 | - return; |
|
| 2870 | - } else { |
|
| 2871 | - $this->_redirect_after_action( |
|
| 2872 | - false, |
|
| 2873 | - '', |
|
| 2874 | - '', |
|
| 2875 | - $query_args, |
|
| 2876 | - true |
|
| 2877 | - ); |
|
| 2878 | - return; |
|
| 2879 | - } |
|
| 2880 | - } |
|
| 2881 | - // maybe update status, and make sure to save transaction if not done already |
|
| 2882 | - if ( ! $transaction->update_status_based_on_total_paid()) { |
|
| 2883 | - $transaction->save(); |
|
| 2884 | - } |
|
| 2885 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2886 | - $this->_req_data = array(); |
|
| 2887 | - $query_args = array( |
|
| 2888 | - 'action' => 'redirect_to_txn', |
|
| 2889 | - 'TXN_ID' => $transaction->ID(), |
|
| 2890 | - 'EVT_ID' => $this->_reg_event->ID(), |
|
| 2891 | - 'event_name' => urlencode($this->_reg_event->name()), |
|
| 2892 | - 'redirect_from' => 'new_registration', |
|
| 2893 | - ); |
|
| 2894 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2895 | - break; |
|
| 2896 | - } |
|
| 2897 | - //what are you looking here for? Should be nothing to do at this point. |
|
| 2898 | - } |
|
| 2899 | - |
|
| 2900 | - |
|
| 2901 | - /** |
|
| 2902 | - * redirect_to_txn |
|
| 2903 | - * |
|
| 2904 | - * @access public |
|
| 2905 | - * @return void |
|
| 2906 | - * @throws EE_Error |
|
| 2907 | - */ |
|
| 2908 | - public function redirect_to_txn() |
|
| 2909 | - { |
|
| 2910 | - EE_System::do_not_cache(); |
|
| 2911 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2912 | - $query_args = array( |
|
| 2913 | - 'action' => 'view_transaction', |
|
| 2914 | - 'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0, |
|
| 2915 | - 'page' => 'espresso_transactions', |
|
| 2916 | - ); |
|
| 2917 | - if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) { |
|
| 2918 | - $query_args['EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2919 | - $query_args['event_name'] = urlencode($this->_req_data['event_name']); |
|
| 2920 | - $query_args['redirect_from'] = $this->_req_data['redirect_from']; |
|
| 2921 | - } |
|
| 2922 | - EE_Error::add_success( |
|
| 2923 | - esc_html__( |
|
| 2924 | - 'Registration Created. Please review the transaction and add any payments as necessary', |
|
| 2925 | - 'event_espresso' |
|
| 2926 | - ) |
|
| 2927 | - ); |
|
| 2928 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2929 | - } |
|
| 2930 | - |
|
| 2931 | - |
|
| 2932 | - /** |
|
| 2933 | - * generates HTML for the Attendee Contact List |
|
| 2934 | - * |
|
| 2935 | - * @access protected |
|
| 2936 | - * @return void |
|
| 2937 | - */ |
|
| 2938 | - protected function _attendee_contact_list_table() |
|
| 2939 | - { |
|
| 2940 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2941 | - $this->_search_btn_label = esc_html__('Contacts', 'event_espresso'); |
|
| 2942 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 2943 | - } |
|
| 2944 | - |
|
| 2945 | - |
|
| 2946 | - /** |
|
| 2947 | - * get_attendees |
|
| 2948 | - * |
|
| 2949 | - * @param $per_page |
|
| 2950 | - * @param bool $count whether to return count or data. |
|
| 2951 | - * @param bool $trash |
|
| 2952 | - * @return array |
|
| 2953 | - * @throws EE_Error |
|
| 2954 | - * @access public |
|
| 2955 | - */ |
|
| 2956 | - public function get_attendees($per_page, $count = false, $trash = false) |
|
| 2957 | - { |
|
| 2958 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2959 | - require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 2960 | - $ATT_MDL = EEM_Attendee::instance(); |
|
| 2961 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2962 | - switch ($this->_req_data['orderby']) { |
|
| 2963 | - case 'ATT_ID': |
|
| 2964 | - $orderby = 'ATT_ID'; |
|
| 2965 | - break; |
|
| 2966 | - case 'ATT_fname': |
|
| 2967 | - $orderby = 'ATT_fname'; |
|
| 2968 | - break; |
|
| 2969 | - case 'ATT_email': |
|
| 2970 | - $orderby = 'ATT_email'; |
|
| 2971 | - break; |
|
| 2972 | - case 'ATT_city': |
|
| 2973 | - $orderby = 'ATT_city'; |
|
| 2974 | - break; |
|
| 2975 | - case 'STA_ID': |
|
| 2976 | - $orderby = 'STA_ID'; |
|
| 2977 | - break; |
|
| 2978 | - case 'CNT_ID': |
|
| 2979 | - $orderby = 'CNT_ID'; |
|
| 2980 | - break; |
|
| 2981 | - default: |
|
| 2982 | - $orderby = 'ATT_lname'; |
|
| 2983 | - } |
|
| 2984 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 2985 | - ? $this->_req_data['order'] |
|
| 2986 | - : 'ASC'; |
|
| 2987 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 2988 | - ? $this->_req_data['paged'] |
|
| 2989 | - : 1; |
|
| 2990 | - $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
| 2991 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 2992 | - ? $this->_req_data['perpage'] |
|
| 2993 | - : $per_page; |
|
| 2994 | - $_where = array(); |
|
| 2995 | - if ( ! empty($this->_req_data['s'])) { |
|
| 2996 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2997 | - $_where['OR'] = array( |
|
| 2998 | - 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
|
| 2999 | - 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
|
| 3000 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $sstr), |
|
| 3001 | - 'ATT_fname' => array('LIKE', $sstr), |
|
| 3002 | - 'ATT_lname' => array('LIKE', $sstr), |
|
| 3003 | - 'ATT_short_bio' => array('LIKE', $sstr), |
|
| 3004 | - 'ATT_email' => array('LIKE', $sstr), |
|
| 3005 | - 'ATT_address' => array('LIKE', $sstr), |
|
| 3006 | - 'ATT_address2' => array('LIKE', $sstr), |
|
| 3007 | - 'ATT_city' => array('LIKE', $sstr), |
|
| 3008 | - 'Country.CNT_name' => array('LIKE', $sstr), |
|
| 3009 | - 'State.STA_name' => array('LIKE', $sstr), |
|
| 3010 | - 'ATT_phone' => array('LIKE', $sstr), |
|
| 3011 | - 'Registration.REG_final_price' => array('LIKE', $sstr), |
|
| 3012 | - 'Registration.REG_code' => array('LIKE', $sstr), |
|
| 3013 | - 'Registration.REG_count' => array('LIKE', $sstr), |
|
| 3014 | - 'Registration.REG_group_size' => array('LIKE', $sstr), |
|
| 3015 | - ); |
|
| 3016 | - } |
|
| 3017 | - $offset = ($current_page - 1) * $per_page; |
|
| 3018 | - $limit = $count ? null : array($offset, $per_page); |
|
| 3019 | - if ($trash) { |
|
| 3020 | - $_where['status'] = array('!=', 'publish'); |
|
| 3021 | - $all_attendees = $count |
|
| 3022 | - ? $ATT_MDL->count(array( |
|
| 3023 | - $_where, |
|
| 3024 | - 'order_by' => array($orderby => $sort), |
|
| 3025 | - 'limit' => $limit, |
|
| 3026 | - ), 'ATT_ID', true) |
|
| 3027 | - : $ATT_MDL->get_all(array( |
|
| 3028 | - $_where, |
|
| 3029 | - 'order_by' => array($orderby => $sort), |
|
| 3030 | - 'limit' => $limit, |
|
| 3031 | - )); |
|
| 3032 | - } else { |
|
| 3033 | - $_where['status'] = array('IN', array('publish')); |
|
| 3034 | - $all_attendees = $count |
|
| 3035 | - ? $ATT_MDL->count(array( |
|
| 3036 | - $_where, |
|
| 3037 | - 'order_by' => array($orderby => $sort), |
|
| 3038 | - 'limit' => $limit, |
|
| 3039 | - ), 'ATT_ID', true) |
|
| 3040 | - : $ATT_MDL->get_all(array( |
|
| 3041 | - $_where, |
|
| 3042 | - 'order_by' => array($orderby => $sort), |
|
| 3043 | - 'limit' => $limit, |
|
| 3044 | - )); |
|
| 3045 | - } |
|
| 3046 | - return $all_attendees; |
|
| 3047 | - } |
|
| 3048 | - |
|
| 3049 | - |
|
| 3050 | - /** |
|
| 3051 | - * This is just taking care of resending the registration confirmation |
|
| 3052 | - * |
|
| 3053 | - * @access protected |
|
| 3054 | - * @return void |
|
| 3055 | - */ |
|
| 3056 | - protected function _resend_registration() |
|
| 3057 | - { |
|
| 3058 | - $this->_process_resend_registration(); |
|
| 3059 | - $query_args = isset($this->_req_data['redirect_to']) |
|
| 3060 | - ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID']) |
|
| 3061 | - : array('action' => 'default'); |
|
| 3062 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3063 | - } |
|
| 3064 | - |
|
| 3065 | - /** |
|
| 3066 | - * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
| 3067 | - * to use when selecting registrations |
|
| 3068 | - * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
| 3069 | - * the query parameters from the request |
|
| 3070 | - * @return void ends the request with a redirect or download |
|
| 3071 | - */ |
|
| 3072 | - public function _registrations_report_base( $method_name_for_getting_query_params ) |
|
| 3073 | - { |
|
| 3074 | - if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3075 | - wp_redirect(EE_Admin_Page::add_query_args_and_nonce( |
|
| 3076 | - array( |
|
| 3077 | - 'page' => 'espresso_batch', |
|
| 3078 | - 'batch' => 'file', |
|
| 3079 | - 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 3080 | - 'filters' => urlencode( |
|
| 3081 | - serialize( |
|
| 3082 | - call_user_func( |
|
| 3083 | - array( $this, $method_name_for_getting_query_params ), |
|
| 3084 | - EEH_Array::is_set( |
|
| 3085 | - $this->_req_data, |
|
| 3086 | - 'filters', |
|
| 3087 | - array() |
|
| 3088 | - ) |
|
| 3089 | - ) |
|
| 3090 | - ) |
|
| 3091 | - ), |
|
| 3092 | - 'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false), |
|
| 3093 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
| 3094 | - 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 3095 | - ))); |
|
| 3096 | - } else { |
|
| 3097 | - $new_request_args = array( |
|
| 3098 | - 'export' => 'report', |
|
| 3099 | - 'action' => 'registrations_report_for_event', |
|
| 3100 | - 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 3101 | - ); |
|
| 3102 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 3103 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3104 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3105 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3106 | - $EE_Export->export(); |
|
| 3107 | - } |
|
| 3108 | - } |
|
| 3109 | - } |
|
| 3110 | - |
|
| 3111 | - |
|
| 3112 | - |
|
| 3113 | - /** |
|
| 3114 | - * Creates a registration report using only query parameters in the request |
|
| 3115 | - * @return void |
|
| 3116 | - */ |
|
| 3117 | - public function _registrations_report() |
|
| 3118 | - { |
|
| 3119 | - $this->_registrations_report_base('_get_registration_query_parameters'); |
|
| 3120 | - } |
|
| 3121 | - |
|
| 3122 | - |
|
| 3123 | - public function _contact_list_export() |
|
| 3124 | - { |
|
| 3125 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3126 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3127 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3128 | - $EE_Export->export_attendees(); |
|
| 3129 | - } |
|
| 3130 | - } |
|
| 3131 | - |
|
| 3132 | - |
|
| 3133 | - public function _contact_list_report() |
|
| 3134 | - { |
|
| 3135 | - if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3136 | - wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 3137 | - 'page' => 'espresso_batch', |
|
| 3138 | - 'batch' => 'file', |
|
| 3139 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
| 3140 | - 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 3141 | - ))); |
|
| 3142 | - } else { |
|
| 3143 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3144 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3145 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3146 | - $EE_Export->report_attendees(); |
|
| 3147 | - } |
|
| 3148 | - } |
|
| 3149 | - } |
|
| 3150 | - |
|
| 3151 | - |
|
| 3152 | - |
|
| 3153 | - |
|
| 3154 | - |
|
| 3155 | - /*************************************** ATTENDEE DETAILS ***************************************/ |
|
| 3156 | - /** |
|
| 3157 | - * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
| 3158 | - * |
|
| 3159 | - * @return void |
|
| 3160 | - * @throws EE_Error |
|
| 3161 | - */ |
|
| 3162 | - protected function _duplicate_attendee() |
|
| 3163 | - { |
|
| 3164 | - $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default'; |
|
| 3165 | - //verify we have necessary info |
|
| 3166 | - if (empty($this->_req_data['_REG_ID'])) { |
|
| 3167 | - EE_Error::add_error( |
|
| 3168 | - esc_html__( |
|
| 3169 | - 'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
| 3170 | - 'event_espresso' |
|
| 3171 | - ), __FILE__, __LINE__, __FUNCTION__ |
|
| 3172 | - ); |
|
| 3173 | - $query_args = array('action' => $action); |
|
| 3174 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3175 | - } |
|
| 3176 | - //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
| 3177 | - $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']); |
|
| 3178 | - $attendee = $registration->attendee(); |
|
| 3179 | - //remove relation of existing attendee on registration |
|
| 3180 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 3181 | - //new attendee |
|
| 3182 | - $new_attendee = clone $attendee; |
|
| 3183 | - $new_attendee->set('ATT_ID', 0); |
|
| 3184 | - $new_attendee->save(); |
|
| 3185 | - //add new attendee to reg |
|
| 3186 | - $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
| 3187 | - EE_Error::add_success( |
|
| 3188 | - esc_html__( |
|
| 3189 | - 'New Contact record created. Now make any edits you wish to make for this contact.', |
|
| 3190 | - 'event_espresso' |
|
| 3191 | - ) |
|
| 3192 | - ); |
|
| 3193 | - //redirect to edit page for attendee |
|
| 3194 | - $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee'); |
|
| 3195 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3196 | - } |
|
| 3197 | - |
|
| 3198 | - |
|
| 3199 | - //related to cpt routes |
|
| 3200 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 3201 | - { |
|
| 3202 | - $success = true; |
|
| 3203 | - $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id); |
|
| 3204 | - //for attendee updates |
|
| 3205 | - if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) { |
|
| 3206 | - //note we should only be UPDATING attendees at this point. |
|
| 3207 | - $updated_fields = array( |
|
| 3208 | - 'ATT_fname' => $this->_req_data['ATT_fname'], |
|
| 3209 | - 'ATT_lname' => $this->_req_data['ATT_lname'], |
|
| 3210 | - 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
| 3211 | - 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
|
| 3212 | - 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
|
| 3213 | - 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
|
| 3214 | - 'STA_ID' => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '', |
|
| 3215 | - 'CNT_ISO' => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '', |
|
| 3216 | - 'ATT_zip' => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '', |
|
| 3217 | - 'ATT_email' => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '', |
|
| 3218 | - 'ATT_phone' => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '', |
|
| 3219 | - ); |
|
| 3220 | - foreach ($updated_fields as $field => $value) { |
|
| 3221 | - $attendee->set($field, $value); |
|
| 3222 | - } |
|
| 3223 | - $success = $attendee->save(); |
|
| 3224 | - $attendee_update_callbacks = apply_filters( |
|
| 3225 | - 'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
| 3226 | - array() |
|
| 3227 | - ); |
|
| 3228 | - foreach ($attendee_update_callbacks as $a_callback) { |
|
| 3229 | - if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) { |
|
| 3230 | - throw new EE_Error( |
|
| 3231 | - sprintf( |
|
| 3232 | - esc_html__( |
|
| 3233 | - 'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback. Please check the spelling.', |
|
| 3234 | - 'event_espresso' |
|
| 3235 | - ), |
|
| 3236 | - $a_callback |
|
| 3237 | - ) |
|
| 3238 | - ); |
|
| 3239 | - } |
|
| 3240 | - } |
|
| 3241 | - } |
|
| 3242 | - if ($success === false) { |
|
| 3243 | - EE_Error::add_error( |
|
| 3244 | - esc_html__( |
|
| 3245 | - 'Something went wrong with updating the meta table data for the registration.', |
|
| 3246 | - 'event_espresso' |
|
| 3247 | - ), |
|
| 3248 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 3249 | - ); |
|
| 3250 | - } |
|
| 3251 | - } |
|
| 3252 | - |
|
| 3253 | - |
|
| 3254 | - public function trash_cpt_item($post_id) |
|
| 3255 | - { |
|
| 3256 | - } |
|
| 3257 | - |
|
| 3258 | - |
|
| 3259 | - public function delete_cpt_item($post_id) |
|
| 3260 | - { |
|
| 3261 | - } |
|
| 3262 | - |
|
| 3263 | - |
|
| 3264 | - public function restore_cpt_item($post_id) |
|
| 3265 | - { |
|
| 3266 | - } |
|
| 3267 | - |
|
| 3268 | - |
|
| 3269 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 3270 | - { |
|
| 3271 | - } |
|
| 3272 | - |
|
| 3273 | - |
|
| 3274 | - public function attendee_editor_metaboxes() |
|
| 3275 | - { |
|
| 3276 | - $this->verify_cpt_object(); |
|
| 3277 | - remove_meta_box( |
|
| 3278 | - 'postexcerpt', |
|
| 3279 | - esc_html__('Excerpt', 'event_espresso'), |
|
| 3280 | - 'post_excerpt_meta_box', |
|
| 3281 | - $this->_cpt_routes[$this->_req_action], |
|
| 3282 | - 'normal', |
|
| 3283 | - 'core' |
|
| 3284 | - ); |
|
| 3285 | - remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 3286 | - if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
| 3287 | - add_meta_box( |
|
| 3288 | - 'postexcerpt', |
|
| 3289 | - esc_html__('Short Biography', 'event_espresso'), |
|
| 3290 | - 'post_excerpt_meta_box', |
|
| 3291 | - $this->_cpt_routes[$this->_req_action], |
|
| 3292 | - 'normal' |
|
| 3293 | - ); |
|
| 3294 | - } |
|
| 3295 | - if (post_type_supports('espresso_attendees', 'comments')) { |
|
| 3296 | - add_meta_box( |
|
| 3297 | - 'commentsdiv', |
|
| 3298 | - esc_html__('Notes on the Contact', 'event_espresso'), |
|
| 3299 | - 'post_comment_meta_box', |
|
| 3300 | - $this->_cpt_routes[$this->_req_action], |
|
| 3301 | - 'normal', |
|
| 3302 | - 'core' |
|
| 3303 | - ); |
|
| 3304 | - } |
|
| 3305 | - add_meta_box( |
|
| 3306 | - 'attendee_contact_info', |
|
| 3307 | - esc_html__('Contact Info', 'event_espresso'), |
|
| 3308 | - array($this, 'attendee_contact_info'), |
|
| 3309 | - $this->_cpt_routes[$this->_req_action], |
|
| 3310 | - 'side', |
|
| 3311 | - 'core' |
|
| 3312 | - ); |
|
| 3313 | - add_meta_box( |
|
| 3314 | - 'attendee_details_address', |
|
| 3315 | - esc_html__('Address Details', 'event_espresso'), |
|
| 3316 | - array($this, 'attendee_address_details'), |
|
| 3317 | - $this->_cpt_routes[$this->_req_action], |
|
| 3318 | - 'normal', |
|
| 3319 | - 'core' |
|
| 3320 | - ); |
|
| 3321 | - add_meta_box( |
|
| 3322 | - 'attendee_registrations', |
|
| 3323 | - esc_html__('Registrations for this Contact', 'event_espresso'), |
|
| 3324 | - array($this, 'attendee_registrations_meta_box'), |
|
| 3325 | - $this->_cpt_routes[$this->_req_action], |
|
| 3326 | - 'normal', |
|
| 3327 | - 'high' |
|
| 3328 | - ); |
|
| 3329 | - } |
|
| 3330 | - |
|
| 3331 | - |
|
| 3332 | - /** |
|
| 3333 | - * Metabox for attendee contact info |
|
| 3334 | - * |
|
| 3335 | - * @param WP_Post $post wp post object |
|
| 3336 | - * @return string attendee contact info ( and form ) |
|
| 3337 | - * @throws DomainException |
|
| 3338 | - */ |
|
| 3339 | - public function attendee_contact_info($post) |
|
| 3340 | - { |
|
| 3341 | - //get attendee object ( should already have it ) |
|
| 3342 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3343 | - $template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php'; |
|
| 3344 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 3345 | - } |
|
| 3346 | - |
|
| 3347 | - |
|
| 3348 | - /** |
|
| 3349 | - * Metabox for attendee details |
|
| 3350 | - * |
|
| 3351 | - * @param WP_Post $post wp post object |
|
| 3352 | - * @return string attendee address details (and form) |
|
| 3353 | - * @throws DomainException |
|
| 3354 | - */ |
|
| 3355 | - public function attendee_address_details($post) |
|
| 3356 | - { |
|
| 3357 | - //get attendee object (should already have it) |
|
| 3358 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3359 | - $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3360 | - new EE_Question_Form_Input( |
|
| 3361 | - EE_Question::new_instance( |
|
| 3362 | - array( |
|
| 3363 | - 'QST_ID' => 0, |
|
| 3364 | - 'QST_display_text' => esc_html__('State/Province', 'event_espresso'), |
|
| 3365 | - 'QST_system' => 'admin-state', |
|
| 3366 | - ) |
|
| 3367 | - ), |
|
| 3368 | - EE_Answer::new_instance( |
|
| 3369 | - array( |
|
| 3370 | - 'ANS_ID' => 0, |
|
| 3371 | - 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
| 3372 | - ) |
|
| 3373 | - ), |
|
| 3374 | - array( |
|
| 3375 | - 'input_id' => 'STA_ID', |
|
| 3376 | - 'input_name' => 'STA_ID', |
|
| 3377 | - 'input_prefix' => '', |
|
| 3378 | - 'append_qstn_id' => false, |
|
| 3379 | - ) |
|
| 3380 | - ) |
|
| 3381 | - ); |
|
| 3382 | - $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3383 | - new EE_Question_Form_Input( |
|
| 3384 | - EE_Question::new_instance( |
|
| 3385 | - array( |
|
| 3386 | - 'QST_ID' => 0, |
|
| 3387 | - 'QST_display_text' => esc_html__('Country', 'event_espresso'), |
|
| 3388 | - 'QST_system' => 'admin-country', |
|
| 3389 | - ) |
|
| 3390 | - ), |
|
| 3391 | - EE_Answer::new_instance( |
|
| 3392 | - array( |
|
| 3393 | - 'ANS_ID' => 0, |
|
| 3394 | - 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
| 3395 | - ) |
|
| 3396 | - ), |
|
| 3397 | - array( |
|
| 3398 | - 'input_id' => 'CNT_ISO', |
|
| 3399 | - 'input_name' => 'CNT_ISO', |
|
| 3400 | - 'input_prefix' => '', |
|
| 3401 | - 'append_qstn_id' => false, |
|
| 3402 | - ) |
|
| 3403 | - ) |
|
| 3404 | - ); |
|
| 3405 | - $template = |
|
| 3406 | - REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 3407 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 3408 | - } |
|
| 3409 | - |
|
| 3410 | - |
|
| 3411 | - /** |
|
| 3412 | - * _attendee_details |
|
| 3413 | - * |
|
| 3414 | - * @access protected |
|
| 3415 | - * @param $post |
|
| 3416 | - * @return void |
|
| 3417 | - * @throws DomainException |
|
| 3418 | - * @throws EE_Error |
|
| 3419 | - */ |
|
| 3420 | - public function attendee_registrations_meta_box($post) |
|
| 3421 | - { |
|
| 3422 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3423 | - $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
| 3424 | - $template = |
|
| 3425 | - REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 3426 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 3427 | - } |
|
| 3428 | - |
|
| 3429 | - |
|
| 3430 | - /** |
|
| 3431 | - * add in the form fields for the attendee edit |
|
| 3432 | - * |
|
| 3433 | - * @param WP_Post $post wp post object |
|
| 3434 | - * @return string html for new form. |
|
| 3435 | - * @throws DomainException |
|
| 3436 | - */ |
|
| 3437 | - public function after_title_form_fields($post) |
|
| 3438 | - { |
|
| 3439 | - if ($post->post_type == 'espresso_attendees') { |
|
| 3440 | - $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 3441 | - $template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3442 | - EEH_Template::display_template($template, $template_args); |
|
| 3443 | - } |
|
| 3444 | - } |
|
| 3445 | - |
|
| 3446 | - |
|
| 3447 | - /** |
|
| 3448 | - * _trash_or_restore_attendee |
|
| 3449 | - * |
|
| 3450 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 3451 | - * @return void |
|
| 3452 | - * @throws EE_Error |
|
| 3453 | - * @access protected |
|
| 3454 | - */ |
|
| 3455 | - protected function _trash_or_restore_attendees($trash = true) |
|
| 3456 | - { |
|
| 3457 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3458 | - $ATT_MDL = EEM_Attendee::instance(); |
|
| 3459 | - $success = 1; |
|
| 3460 | - //Checkboxes |
|
| 3461 | - if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3462 | - // if array has more than one element than success message should be plural |
|
| 3463 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3464 | - // cycle thru checkboxes |
|
| 3465 | - while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3466 | - $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID) |
|
| 3467 | - : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID); |
|
| 3468 | - if ( ! $updated) { |
|
| 3469 | - $success = 0; |
|
| 3470 | - } |
|
| 3471 | - } |
|
| 3472 | - } else { |
|
| 3473 | - // grab single id and delete |
|
| 3474 | - $ATT_ID = absint($this->_req_data['ATT_ID']); |
|
| 3475 | - //get attendee |
|
| 3476 | - $att = $ATT_MDL->get_one_by_ID($ATT_ID); |
|
| 3477 | - $updated = $trash ? $att->set_status('trash') : $att->set_status('publish'); |
|
| 3478 | - $updated = $att->save(); |
|
| 3479 | - if ( ! $updated) { |
|
| 3480 | - $success = 0; |
|
| 3481 | - } |
|
| 3482 | - } |
|
| 3483 | - $what = $success > 1 |
|
| 3484 | - ? esc_html__('Contacts', 'event_espresso') |
|
| 3485 | - : esc_html__('Contact', 'event_espresso'); |
|
| 3486 | - $action_desc = $trash |
|
| 3487 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3488 | - : esc_html__('restored', 'event_espresso'); |
|
| 3489 | - $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list')); |
|
| 3490 | - } |
|
| 2704 | + } |
|
| 2705 | + $template_args = array( |
|
| 2706 | + 'title' => '', |
|
| 2707 | + 'content' => '', |
|
| 2708 | + 'step_button_text' => '', |
|
| 2709 | + 'show_notification_toggle' => false, |
|
| 2710 | + ); |
|
| 2711 | + //to indicate we're processing a new registration |
|
| 2712 | + $hidden_fields = array( |
|
| 2713 | + 'processing_registration' => array( |
|
| 2714 | + 'type' => 'hidden', |
|
| 2715 | + 'value' => 0, |
|
| 2716 | + ), |
|
| 2717 | + 'event_id' => array( |
|
| 2718 | + 'type' => 'hidden', |
|
| 2719 | + 'value' => $this->_reg_event->ID(), |
|
| 2720 | + ), |
|
| 2721 | + ); |
|
| 2722 | + //if the cart is empty then we know we're at step one so we'll display ticket selector |
|
| 2723 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2724 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2725 | + switch ($step) { |
|
| 2726 | + case 'ticket' : |
|
| 2727 | + $hidden_fields['processing_registration']['value'] = 1; |
|
| 2728 | + $template_args['title'] = esc_html__( |
|
| 2729 | + 'Step One: Select the Ticket for this registration', |
|
| 2730 | + 'event_espresso' |
|
| 2731 | + ); |
|
| 2732 | + $template_args['content'] = |
|
| 2733 | + EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
| 2734 | + $template_args['step_button_text'] = esc_html__( |
|
| 2735 | + 'Add Tickets and Continue to Registrant Details', |
|
| 2736 | + 'event_espresso' |
|
| 2737 | + ); |
|
| 2738 | + $template_args['show_notification_toggle'] = false; |
|
| 2739 | + break; |
|
| 2740 | + case 'questions' : |
|
| 2741 | + $hidden_fields['processing_registration']['value'] = 2; |
|
| 2742 | + $template_args['title'] = esc_html__( |
|
| 2743 | + 'Step Two: Add Registrant Details for this Registration', |
|
| 2744 | + 'event_espresso' |
|
| 2745 | + ); |
|
| 2746 | + //in theory we should be able to run EED_SPCO at this point because the cart should have been setup |
|
| 2747 | + // properly by the first process_reg_step run. |
|
| 2748 | + $template_args['content'] = |
|
| 2749 | + EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
| 2750 | + $template_args['step_button_text'] = esc_html__( |
|
| 2751 | + 'Save Registration and Continue to Details', |
|
| 2752 | + 'event_espresso' |
|
| 2753 | + ); |
|
| 2754 | + $template_args['show_notification_toggle'] = true; |
|
| 2755 | + break; |
|
| 2756 | + } |
|
| 2757 | + //we come back to the process_registration_step route. |
|
| 2758 | + $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields); |
|
| 2759 | + return EEH_Template::display_template( |
|
| 2760 | + REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 2761 | + $template_args, |
|
| 2762 | + true |
|
| 2763 | + ); |
|
| 2764 | + } |
|
| 2765 | + |
|
| 2766 | + |
|
| 2767 | + /** |
|
| 2768 | + * set_reg_event |
|
| 2769 | + * |
|
| 2770 | + * @access private |
|
| 2771 | + * @return bool |
|
| 2772 | + * @throws EE_Error |
|
| 2773 | + */ |
|
| 2774 | + private function _set_reg_event() |
|
| 2775 | + { |
|
| 2776 | + if (is_object($this->_reg_event)) { |
|
| 2777 | + return true; |
|
| 2778 | + } |
|
| 2779 | + $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
| 2780 | + if ( ! $EVT_ID) { |
|
| 2781 | + return false; |
|
| 2782 | + } |
|
| 2783 | + $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 2784 | + return true; |
|
| 2785 | + } |
|
| 2786 | + |
|
| 2787 | + |
|
| 2788 | + /** |
|
| 2789 | + * process_reg_step |
|
| 2790 | + * |
|
| 2791 | + * @access public |
|
| 2792 | + * @return string |
|
| 2793 | + * @throws DomainException |
|
| 2794 | + * @throws EE_Error |
|
| 2795 | + * @throws RuntimeException |
|
| 2796 | + */ |
|
| 2797 | + public function process_reg_step() |
|
| 2798 | + { |
|
| 2799 | + EE_System::do_not_cache(); |
|
| 2800 | + $this->_set_reg_event(); |
|
| 2801 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2802 | + EE_Registry::instance()->REQ->set('uts', time()); |
|
| 2803 | + //what step are we on? |
|
| 2804 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
| 2805 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 2806 | + //if doing ajax then we need to verify the nonce |
|
| 2807 | + if (defined('DOING_AJAX')) { |
|
| 2808 | + $nonce = isset($this->_req_data[$this->_req_nonce]) |
|
| 2809 | + ? sanitize_text_field($this->_req_data[$this->_req_nonce]) : ''; |
|
| 2810 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 2811 | + } |
|
| 2812 | + switch ($step) { |
|
| 2813 | + case 'ticket' : |
|
| 2814 | + //process ticket selection |
|
| 2815 | + $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
| 2816 | + if ($success) { |
|
| 2817 | + EE_Error::add_success( |
|
| 2818 | + esc_html__( |
|
| 2819 | + 'Tickets Selected. Now complete the registration.', |
|
| 2820 | + 'event_espresso' |
|
| 2821 | + ) |
|
| 2822 | + ); |
|
| 2823 | + } else { |
|
| 2824 | + $query_args['step_error'] = $this->_req_data['step_error'] = true; |
|
| 2825 | + } |
|
| 2826 | + if (defined('DOING_AJAX')) { |
|
| 2827 | + $this->new_registration(); //display next step |
|
| 2828 | + } else { |
|
| 2829 | + $query_args = array( |
|
| 2830 | + 'action' => 'new_registration', |
|
| 2831 | + 'processing_registration' => 1, |
|
| 2832 | + 'event_id' => $this->_reg_event->ID(), |
|
| 2833 | + 'uts' => time(), |
|
| 2834 | + ); |
|
| 2835 | + $this->_redirect_after_action( |
|
| 2836 | + false, |
|
| 2837 | + '', |
|
| 2838 | + '', |
|
| 2839 | + $query_args, |
|
| 2840 | + true |
|
| 2841 | + ); |
|
| 2842 | + } |
|
| 2843 | + break; |
|
| 2844 | + case 'questions' : |
|
| 2845 | + if (! isset( |
|
| 2846 | + $this->_req_data['txn_reg_status_change'], |
|
| 2847 | + $this->_req_data['txn_reg_status_change']['send_notifications']) |
|
| 2848 | + ) { |
|
| 2849 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
| 2850 | + } |
|
| 2851 | + //process registration |
|
| 2852 | + $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
| 2853 | + if ($cart instanceof EE_Cart) { |
|
| 2854 | + $grand_total = $cart->get_cart_grand_total(); |
|
| 2855 | + if ($grand_total instanceof EE_Line_Item) { |
|
| 2856 | + $grand_total->save_this_and_descendants_to_txn(); |
|
| 2857 | + } |
|
| 2858 | + } |
|
| 2859 | + if ( ! $transaction instanceof EE_Transaction) { |
|
| 2860 | + $query_args = array( |
|
| 2861 | + 'action' => 'new_registration', |
|
| 2862 | + 'processing_registration' => 2, |
|
| 2863 | + 'event_id' => $this->_reg_event->ID(), |
|
| 2864 | + 'uts' => time(), |
|
| 2865 | + ); |
|
| 2866 | + if (defined('DOING_AJAX')) { |
|
| 2867 | + //display registration form again because there are errors (maybe validation?) |
|
| 2868 | + $this->new_registration(); |
|
| 2869 | + return; |
|
| 2870 | + } else { |
|
| 2871 | + $this->_redirect_after_action( |
|
| 2872 | + false, |
|
| 2873 | + '', |
|
| 2874 | + '', |
|
| 2875 | + $query_args, |
|
| 2876 | + true |
|
| 2877 | + ); |
|
| 2878 | + return; |
|
| 2879 | + } |
|
| 2880 | + } |
|
| 2881 | + // maybe update status, and make sure to save transaction if not done already |
|
| 2882 | + if ( ! $transaction->update_status_based_on_total_paid()) { |
|
| 2883 | + $transaction->save(); |
|
| 2884 | + } |
|
| 2885 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2886 | + $this->_req_data = array(); |
|
| 2887 | + $query_args = array( |
|
| 2888 | + 'action' => 'redirect_to_txn', |
|
| 2889 | + 'TXN_ID' => $transaction->ID(), |
|
| 2890 | + 'EVT_ID' => $this->_reg_event->ID(), |
|
| 2891 | + 'event_name' => urlencode($this->_reg_event->name()), |
|
| 2892 | + 'redirect_from' => 'new_registration', |
|
| 2893 | + ); |
|
| 2894 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2895 | + break; |
|
| 2896 | + } |
|
| 2897 | + //what are you looking here for? Should be nothing to do at this point. |
|
| 2898 | + } |
|
| 2899 | + |
|
| 2900 | + |
|
| 2901 | + /** |
|
| 2902 | + * redirect_to_txn |
|
| 2903 | + * |
|
| 2904 | + * @access public |
|
| 2905 | + * @return void |
|
| 2906 | + * @throws EE_Error |
|
| 2907 | + */ |
|
| 2908 | + public function redirect_to_txn() |
|
| 2909 | + { |
|
| 2910 | + EE_System::do_not_cache(); |
|
| 2911 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2912 | + $query_args = array( |
|
| 2913 | + 'action' => 'view_transaction', |
|
| 2914 | + 'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0, |
|
| 2915 | + 'page' => 'espresso_transactions', |
|
| 2916 | + ); |
|
| 2917 | + if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) { |
|
| 2918 | + $query_args['EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2919 | + $query_args['event_name'] = urlencode($this->_req_data['event_name']); |
|
| 2920 | + $query_args['redirect_from'] = $this->_req_data['redirect_from']; |
|
| 2921 | + } |
|
| 2922 | + EE_Error::add_success( |
|
| 2923 | + esc_html__( |
|
| 2924 | + 'Registration Created. Please review the transaction and add any payments as necessary', |
|
| 2925 | + 'event_espresso' |
|
| 2926 | + ) |
|
| 2927 | + ); |
|
| 2928 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 2929 | + } |
|
| 2930 | + |
|
| 2931 | + |
|
| 2932 | + /** |
|
| 2933 | + * generates HTML for the Attendee Contact List |
|
| 2934 | + * |
|
| 2935 | + * @access protected |
|
| 2936 | + * @return void |
|
| 2937 | + */ |
|
| 2938 | + protected function _attendee_contact_list_table() |
|
| 2939 | + { |
|
| 2940 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2941 | + $this->_search_btn_label = esc_html__('Contacts', 'event_espresso'); |
|
| 2942 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 2943 | + } |
|
| 2944 | + |
|
| 2945 | + |
|
| 2946 | + /** |
|
| 2947 | + * get_attendees |
|
| 2948 | + * |
|
| 2949 | + * @param $per_page |
|
| 2950 | + * @param bool $count whether to return count or data. |
|
| 2951 | + * @param bool $trash |
|
| 2952 | + * @return array |
|
| 2953 | + * @throws EE_Error |
|
| 2954 | + * @access public |
|
| 2955 | + */ |
|
| 2956 | + public function get_attendees($per_page, $count = false, $trash = false) |
|
| 2957 | + { |
|
| 2958 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 2959 | + require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 2960 | + $ATT_MDL = EEM_Attendee::instance(); |
|
| 2961 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2962 | + switch ($this->_req_data['orderby']) { |
|
| 2963 | + case 'ATT_ID': |
|
| 2964 | + $orderby = 'ATT_ID'; |
|
| 2965 | + break; |
|
| 2966 | + case 'ATT_fname': |
|
| 2967 | + $orderby = 'ATT_fname'; |
|
| 2968 | + break; |
|
| 2969 | + case 'ATT_email': |
|
| 2970 | + $orderby = 'ATT_email'; |
|
| 2971 | + break; |
|
| 2972 | + case 'ATT_city': |
|
| 2973 | + $orderby = 'ATT_city'; |
|
| 2974 | + break; |
|
| 2975 | + case 'STA_ID': |
|
| 2976 | + $orderby = 'STA_ID'; |
|
| 2977 | + break; |
|
| 2978 | + case 'CNT_ID': |
|
| 2979 | + $orderby = 'CNT_ID'; |
|
| 2980 | + break; |
|
| 2981 | + default: |
|
| 2982 | + $orderby = 'ATT_lname'; |
|
| 2983 | + } |
|
| 2984 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 2985 | + ? $this->_req_data['order'] |
|
| 2986 | + : 'ASC'; |
|
| 2987 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 2988 | + ? $this->_req_data['paged'] |
|
| 2989 | + : 1; |
|
| 2990 | + $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
| 2991 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 2992 | + ? $this->_req_data['perpage'] |
|
| 2993 | + : $per_page; |
|
| 2994 | + $_where = array(); |
|
| 2995 | + if ( ! empty($this->_req_data['s'])) { |
|
| 2996 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 2997 | + $_where['OR'] = array( |
|
| 2998 | + 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
|
| 2999 | + 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
|
| 3000 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $sstr), |
|
| 3001 | + 'ATT_fname' => array('LIKE', $sstr), |
|
| 3002 | + 'ATT_lname' => array('LIKE', $sstr), |
|
| 3003 | + 'ATT_short_bio' => array('LIKE', $sstr), |
|
| 3004 | + 'ATT_email' => array('LIKE', $sstr), |
|
| 3005 | + 'ATT_address' => array('LIKE', $sstr), |
|
| 3006 | + 'ATT_address2' => array('LIKE', $sstr), |
|
| 3007 | + 'ATT_city' => array('LIKE', $sstr), |
|
| 3008 | + 'Country.CNT_name' => array('LIKE', $sstr), |
|
| 3009 | + 'State.STA_name' => array('LIKE', $sstr), |
|
| 3010 | + 'ATT_phone' => array('LIKE', $sstr), |
|
| 3011 | + 'Registration.REG_final_price' => array('LIKE', $sstr), |
|
| 3012 | + 'Registration.REG_code' => array('LIKE', $sstr), |
|
| 3013 | + 'Registration.REG_count' => array('LIKE', $sstr), |
|
| 3014 | + 'Registration.REG_group_size' => array('LIKE', $sstr), |
|
| 3015 | + ); |
|
| 3016 | + } |
|
| 3017 | + $offset = ($current_page - 1) * $per_page; |
|
| 3018 | + $limit = $count ? null : array($offset, $per_page); |
|
| 3019 | + if ($trash) { |
|
| 3020 | + $_where['status'] = array('!=', 'publish'); |
|
| 3021 | + $all_attendees = $count |
|
| 3022 | + ? $ATT_MDL->count(array( |
|
| 3023 | + $_where, |
|
| 3024 | + 'order_by' => array($orderby => $sort), |
|
| 3025 | + 'limit' => $limit, |
|
| 3026 | + ), 'ATT_ID', true) |
|
| 3027 | + : $ATT_MDL->get_all(array( |
|
| 3028 | + $_where, |
|
| 3029 | + 'order_by' => array($orderby => $sort), |
|
| 3030 | + 'limit' => $limit, |
|
| 3031 | + )); |
|
| 3032 | + } else { |
|
| 3033 | + $_where['status'] = array('IN', array('publish')); |
|
| 3034 | + $all_attendees = $count |
|
| 3035 | + ? $ATT_MDL->count(array( |
|
| 3036 | + $_where, |
|
| 3037 | + 'order_by' => array($orderby => $sort), |
|
| 3038 | + 'limit' => $limit, |
|
| 3039 | + ), 'ATT_ID', true) |
|
| 3040 | + : $ATT_MDL->get_all(array( |
|
| 3041 | + $_where, |
|
| 3042 | + 'order_by' => array($orderby => $sort), |
|
| 3043 | + 'limit' => $limit, |
|
| 3044 | + )); |
|
| 3045 | + } |
|
| 3046 | + return $all_attendees; |
|
| 3047 | + } |
|
| 3048 | + |
|
| 3049 | + |
|
| 3050 | + /** |
|
| 3051 | + * This is just taking care of resending the registration confirmation |
|
| 3052 | + * |
|
| 3053 | + * @access protected |
|
| 3054 | + * @return void |
|
| 3055 | + */ |
|
| 3056 | + protected function _resend_registration() |
|
| 3057 | + { |
|
| 3058 | + $this->_process_resend_registration(); |
|
| 3059 | + $query_args = isset($this->_req_data['redirect_to']) |
|
| 3060 | + ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID']) |
|
| 3061 | + : array('action' => 'default'); |
|
| 3062 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3063 | + } |
|
| 3064 | + |
|
| 3065 | + /** |
|
| 3066 | + * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
| 3067 | + * to use when selecting registrations |
|
| 3068 | + * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
| 3069 | + * the query parameters from the request |
|
| 3070 | + * @return void ends the request with a redirect or download |
|
| 3071 | + */ |
|
| 3072 | + public function _registrations_report_base( $method_name_for_getting_query_params ) |
|
| 3073 | + { |
|
| 3074 | + if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3075 | + wp_redirect(EE_Admin_Page::add_query_args_and_nonce( |
|
| 3076 | + array( |
|
| 3077 | + 'page' => 'espresso_batch', |
|
| 3078 | + 'batch' => 'file', |
|
| 3079 | + 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 3080 | + 'filters' => urlencode( |
|
| 3081 | + serialize( |
|
| 3082 | + call_user_func( |
|
| 3083 | + array( $this, $method_name_for_getting_query_params ), |
|
| 3084 | + EEH_Array::is_set( |
|
| 3085 | + $this->_req_data, |
|
| 3086 | + 'filters', |
|
| 3087 | + array() |
|
| 3088 | + ) |
|
| 3089 | + ) |
|
| 3090 | + ) |
|
| 3091 | + ), |
|
| 3092 | + 'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false), |
|
| 3093 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
| 3094 | + 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 3095 | + ))); |
|
| 3096 | + } else { |
|
| 3097 | + $new_request_args = array( |
|
| 3098 | + 'export' => 'report', |
|
| 3099 | + 'action' => 'registrations_report_for_event', |
|
| 3100 | + 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 3101 | + ); |
|
| 3102 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 3103 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3104 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3105 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3106 | + $EE_Export->export(); |
|
| 3107 | + } |
|
| 3108 | + } |
|
| 3109 | + } |
|
| 3110 | + |
|
| 3111 | + |
|
| 3112 | + |
|
| 3113 | + /** |
|
| 3114 | + * Creates a registration report using only query parameters in the request |
|
| 3115 | + * @return void |
|
| 3116 | + */ |
|
| 3117 | + public function _registrations_report() |
|
| 3118 | + { |
|
| 3119 | + $this->_registrations_report_base('_get_registration_query_parameters'); |
|
| 3120 | + } |
|
| 3121 | + |
|
| 3122 | + |
|
| 3123 | + public function _contact_list_export() |
|
| 3124 | + { |
|
| 3125 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3126 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3127 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3128 | + $EE_Export->export_attendees(); |
|
| 3129 | + } |
|
| 3130 | + } |
|
| 3131 | + |
|
| 3132 | + |
|
| 3133 | + public function _contact_list_report() |
|
| 3134 | + { |
|
| 3135 | + if ( ! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3136 | + wp_redirect(EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 3137 | + 'page' => 'espresso_batch', |
|
| 3138 | + 'batch' => 'file', |
|
| 3139 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
| 3140 | + 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 3141 | + ))); |
|
| 3142 | + } else { |
|
| 3143 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3144 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3145 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3146 | + $EE_Export->report_attendees(); |
|
| 3147 | + } |
|
| 3148 | + } |
|
| 3149 | + } |
|
| 3150 | + |
|
| 3151 | + |
|
| 3152 | + |
|
| 3153 | + |
|
| 3154 | + |
|
| 3155 | + /*************************************** ATTENDEE DETAILS ***************************************/ |
|
| 3156 | + /** |
|
| 3157 | + * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
| 3158 | + * |
|
| 3159 | + * @return void |
|
| 3160 | + * @throws EE_Error |
|
| 3161 | + */ |
|
| 3162 | + protected function _duplicate_attendee() |
|
| 3163 | + { |
|
| 3164 | + $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default'; |
|
| 3165 | + //verify we have necessary info |
|
| 3166 | + if (empty($this->_req_data['_REG_ID'])) { |
|
| 3167 | + EE_Error::add_error( |
|
| 3168 | + esc_html__( |
|
| 3169 | + 'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
| 3170 | + 'event_espresso' |
|
| 3171 | + ), __FILE__, __LINE__, __FUNCTION__ |
|
| 3172 | + ); |
|
| 3173 | + $query_args = array('action' => $action); |
|
| 3174 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3175 | + } |
|
| 3176 | + //okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
| 3177 | + $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']); |
|
| 3178 | + $attendee = $registration->attendee(); |
|
| 3179 | + //remove relation of existing attendee on registration |
|
| 3180 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 3181 | + //new attendee |
|
| 3182 | + $new_attendee = clone $attendee; |
|
| 3183 | + $new_attendee->set('ATT_ID', 0); |
|
| 3184 | + $new_attendee->save(); |
|
| 3185 | + //add new attendee to reg |
|
| 3186 | + $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
| 3187 | + EE_Error::add_success( |
|
| 3188 | + esc_html__( |
|
| 3189 | + 'New Contact record created. Now make any edits you wish to make for this contact.', |
|
| 3190 | + 'event_espresso' |
|
| 3191 | + ) |
|
| 3192 | + ); |
|
| 3193 | + //redirect to edit page for attendee |
|
| 3194 | + $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee'); |
|
| 3195 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3196 | + } |
|
| 3197 | + |
|
| 3198 | + |
|
| 3199 | + //related to cpt routes |
|
| 3200 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 3201 | + { |
|
| 3202 | + $success = true; |
|
| 3203 | + $attendee = EEM_Attendee::instance()->get_one_by_ID($post_id); |
|
| 3204 | + //for attendee updates |
|
| 3205 | + if ($post->post_type = 'espresso_attendees' && ! empty($attendee)) { |
|
| 3206 | + //note we should only be UPDATING attendees at this point. |
|
| 3207 | + $updated_fields = array( |
|
| 3208 | + 'ATT_fname' => $this->_req_data['ATT_fname'], |
|
| 3209 | + 'ATT_lname' => $this->_req_data['ATT_lname'], |
|
| 3210 | + 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
| 3211 | + 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
|
| 3212 | + 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
|
| 3213 | + 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
|
| 3214 | + 'STA_ID' => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '', |
|
| 3215 | + 'CNT_ISO' => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '', |
|
| 3216 | + 'ATT_zip' => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '', |
|
| 3217 | + 'ATT_email' => isset($this->_req_data['ATT_email']) ? $this->_req_data['ATT_email'] : '', |
|
| 3218 | + 'ATT_phone' => isset($this->_req_data['ATT_phone']) ? $this->_req_data['ATT_phone'] : '', |
|
| 3219 | + ); |
|
| 3220 | + foreach ($updated_fields as $field => $value) { |
|
| 3221 | + $attendee->set($field, $value); |
|
| 3222 | + } |
|
| 3223 | + $success = $attendee->save(); |
|
| 3224 | + $attendee_update_callbacks = apply_filters( |
|
| 3225 | + 'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
| 3226 | + array() |
|
| 3227 | + ); |
|
| 3228 | + foreach ($attendee_update_callbacks as $a_callback) { |
|
| 3229 | + if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) { |
|
| 3230 | + throw new EE_Error( |
|
| 3231 | + sprintf( |
|
| 3232 | + esc_html__( |
|
| 3233 | + 'The %s callback given for the "FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update" filter is not a valid callback. Please check the spelling.', |
|
| 3234 | + 'event_espresso' |
|
| 3235 | + ), |
|
| 3236 | + $a_callback |
|
| 3237 | + ) |
|
| 3238 | + ); |
|
| 3239 | + } |
|
| 3240 | + } |
|
| 3241 | + } |
|
| 3242 | + if ($success === false) { |
|
| 3243 | + EE_Error::add_error( |
|
| 3244 | + esc_html__( |
|
| 3245 | + 'Something went wrong with updating the meta table data for the registration.', |
|
| 3246 | + 'event_espresso' |
|
| 3247 | + ), |
|
| 3248 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 3249 | + ); |
|
| 3250 | + } |
|
| 3251 | + } |
|
| 3252 | + |
|
| 3253 | + |
|
| 3254 | + public function trash_cpt_item($post_id) |
|
| 3255 | + { |
|
| 3256 | + } |
|
| 3257 | + |
|
| 3258 | + |
|
| 3259 | + public function delete_cpt_item($post_id) |
|
| 3260 | + { |
|
| 3261 | + } |
|
| 3262 | + |
|
| 3263 | + |
|
| 3264 | + public function restore_cpt_item($post_id) |
|
| 3265 | + { |
|
| 3266 | + } |
|
| 3267 | + |
|
| 3268 | + |
|
| 3269 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 3270 | + { |
|
| 3271 | + } |
|
| 3272 | + |
|
| 3273 | + |
|
| 3274 | + public function attendee_editor_metaboxes() |
|
| 3275 | + { |
|
| 3276 | + $this->verify_cpt_object(); |
|
| 3277 | + remove_meta_box( |
|
| 3278 | + 'postexcerpt', |
|
| 3279 | + esc_html__('Excerpt', 'event_espresso'), |
|
| 3280 | + 'post_excerpt_meta_box', |
|
| 3281 | + $this->_cpt_routes[$this->_req_action], |
|
| 3282 | + 'normal', |
|
| 3283 | + 'core' |
|
| 3284 | + ); |
|
| 3285 | + remove_meta_box('commentstatusdiv', $this->_cpt_routes[$this->_req_action], 'normal', 'core'); |
|
| 3286 | + if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
| 3287 | + add_meta_box( |
|
| 3288 | + 'postexcerpt', |
|
| 3289 | + esc_html__('Short Biography', 'event_espresso'), |
|
| 3290 | + 'post_excerpt_meta_box', |
|
| 3291 | + $this->_cpt_routes[$this->_req_action], |
|
| 3292 | + 'normal' |
|
| 3293 | + ); |
|
| 3294 | + } |
|
| 3295 | + if (post_type_supports('espresso_attendees', 'comments')) { |
|
| 3296 | + add_meta_box( |
|
| 3297 | + 'commentsdiv', |
|
| 3298 | + esc_html__('Notes on the Contact', 'event_espresso'), |
|
| 3299 | + 'post_comment_meta_box', |
|
| 3300 | + $this->_cpt_routes[$this->_req_action], |
|
| 3301 | + 'normal', |
|
| 3302 | + 'core' |
|
| 3303 | + ); |
|
| 3304 | + } |
|
| 3305 | + add_meta_box( |
|
| 3306 | + 'attendee_contact_info', |
|
| 3307 | + esc_html__('Contact Info', 'event_espresso'), |
|
| 3308 | + array($this, 'attendee_contact_info'), |
|
| 3309 | + $this->_cpt_routes[$this->_req_action], |
|
| 3310 | + 'side', |
|
| 3311 | + 'core' |
|
| 3312 | + ); |
|
| 3313 | + add_meta_box( |
|
| 3314 | + 'attendee_details_address', |
|
| 3315 | + esc_html__('Address Details', 'event_espresso'), |
|
| 3316 | + array($this, 'attendee_address_details'), |
|
| 3317 | + $this->_cpt_routes[$this->_req_action], |
|
| 3318 | + 'normal', |
|
| 3319 | + 'core' |
|
| 3320 | + ); |
|
| 3321 | + add_meta_box( |
|
| 3322 | + 'attendee_registrations', |
|
| 3323 | + esc_html__('Registrations for this Contact', 'event_espresso'), |
|
| 3324 | + array($this, 'attendee_registrations_meta_box'), |
|
| 3325 | + $this->_cpt_routes[$this->_req_action], |
|
| 3326 | + 'normal', |
|
| 3327 | + 'high' |
|
| 3328 | + ); |
|
| 3329 | + } |
|
| 3330 | + |
|
| 3331 | + |
|
| 3332 | + /** |
|
| 3333 | + * Metabox for attendee contact info |
|
| 3334 | + * |
|
| 3335 | + * @param WP_Post $post wp post object |
|
| 3336 | + * @return string attendee contact info ( and form ) |
|
| 3337 | + * @throws DomainException |
|
| 3338 | + */ |
|
| 3339 | + public function attendee_contact_info($post) |
|
| 3340 | + { |
|
| 3341 | + //get attendee object ( should already have it ) |
|
| 3342 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3343 | + $template = REG_TEMPLATE_PATH . 'attendee_contact_info_metabox_content.template.php'; |
|
| 3344 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 3345 | + } |
|
| 3346 | + |
|
| 3347 | + |
|
| 3348 | + /** |
|
| 3349 | + * Metabox for attendee details |
|
| 3350 | + * |
|
| 3351 | + * @param WP_Post $post wp post object |
|
| 3352 | + * @return string attendee address details (and form) |
|
| 3353 | + * @throws DomainException |
|
| 3354 | + */ |
|
| 3355 | + public function attendee_address_details($post) |
|
| 3356 | + { |
|
| 3357 | + //get attendee object (should already have it) |
|
| 3358 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3359 | + $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3360 | + new EE_Question_Form_Input( |
|
| 3361 | + EE_Question::new_instance( |
|
| 3362 | + array( |
|
| 3363 | + 'QST_ID' => 0, |
|
| 3364 | + 'QST_display_text' => esc_html__('State/Province', 'event_espresso'), |
|
| 3365 | + 'QST_system' => 'admin-state', |
|
| 3366 | + ) |
|
| 3367 | + ), |
|
| 3368 | + EE_Answer::new_instance( |
|
| 3369 | + array( |
|
| 3370 | + 'ANS_ID' => 0, |
|
| 3371 | + 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
| 3372 | + ) |
|
| 3373 | + ), |
|
| 3374 | + array( |
|
| 3375 | + 'input_id' => 'STA_ID', |
|
| 3376 | + 'input_name' => 'STA_ID', |
|
| 3377 | + 'input_prefix' => '', |
|
| 3378 | + 'append_qstn_id' => false, |
|
| 3379 | + ) |
|
| 3380 | + ) |
|
| 3381 | + ); |
|
| 3382 | + $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3383 | + new EE_Question_Form_Input( |
|
| 3384 | + EE_Question::new_instance( |
|
| 3385 | + array( |
|
| 3386 | + 'QST_ID' => 0, |
|
| 3387 | + 'QST_display_text' => esc_html__('Country', 'event_espresso'), |
|
| 3388 | + 'QST_system' => 'admin-country', |
|
| 3389 | + ) |
|
| 3390 | + ), |
|
| 3391 | + EE_Answer::new_instance( |
|
| 3392 | + array( |
|
| 3393 | + 'ANS_ID' => 0, |
|
| 3394 | + 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
| 3395 | + ) |
|
| 3396 | + ), |
|
| 3397 | + array( |
|
| 3398 | + 'input_id' => 'CNT_ISO', |
|
| 3399 | + 'input_name' => 'CNT_ISO', |
|
| 3400 | + 'input_prefix' => '', |
|
| 3401 | + 'append_qstn_id' => false, |
|
| 3402 | + ) |
|
| 3403 | + ) |
|
| 3404 | + ); |
|
| 3405 | + $template = |
|
| 3406 | + REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 3407 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 3408 | + } |
|
| 3409 | + |
|
| 3410 | + |
|
| 3411 | + /** |
|
| 3412 | + * _attendee_details |
|
| 3413 | + * |
|
| 3414 | + * @access protected |
|
| 3415 | + * @param $post |
|
| 3416 | + * @return void |
|
| 3417 | + * @throws DomainException |
|
| 3418 | + * @throws EE_Error |
|
| 3419 | + */ |
|
| 3420 | + public function attendee_registrations_meta_box($post) |
|
| 3421 | + { |
|
| 3422 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3423 | + $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
| 3424 | + $template = |
|
| 3425 | + REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 3426 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 3427 | + } |
|
| 3428 | + |
|
| 3429 | + |
|
| 3430 | + /** |
|
| 3431 | + * add in the form fields for the attendee edit |
|
| 3432 | + * |
|
| 3433 | + * @param WP_Post $post wp post object |
|
| 3434 | + * @return string html for new form. |
|
| 3435 | + * @throws DomainException |
|
| 3436 | + */ |
|
| 3437 | + public function after_title_form_fields($post) |
|
| 3438 | + { |
|
| 3439 | + if ($post->post_type == 'espresso_attendees') { |
|
| 3440 | + $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 3441 | + $template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3442 | + EEH_Template::display_template($template, $template_args); |
|
| 3443 | + } |
|
| 3444 | + } |
|
| 3445 | + |
|
| 3446 | + |
|
| 3447 | + /** |
|
| 3448 | + * _trash_or_restore_attendee |
|
| 3449 | + * |
|
| 3450 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 3451 | + * @return void |
|
| 3452 | + * @throws EE_Error |
|
| 3453 | + * @access protected |
|
| 3454 | + */ |
|
| 3455 | + protected function _trash_or_restore_attendees($trash = true) |
|
| 3456 | + { |
|
| 3457 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3458 | + $ATT_MDL = EEM_Attendee::instance(); |
|
| 3459 | + $success = 1; |
|
| 3460 | + //Checkboxes |
|
| 3461 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3462 | + // if array has more than one element than success message should be plural |
|
| 3463 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3464 | + // cycle thru checkboxes |
|
| 3465 | + while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3466 | + $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID) |
|
| 3467 | + : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID); |
|
| 3468 | + if ( ! $updated) { |
|
| 3469 | + $success = 0; |
|
| 3470 | + } |
|
| 3471 | + } |
|
| 3472 | + } else { |
|
| 3473 | + // grab single id and delete |
|
| 3474 | + $ATT_ID = absint($this->_req_data['ATT_ID']); |
|
| 3475 | + //get attendee |
|
| 3476 | + $att = $ATT_MDL->get_one_by_ID($ATT_ID); |
|
| 3477 | + $updated = $trash ? $att->set_status('trash') : $att->set_status('publish'); |
|
| 3478 | + $updated = $att->save(); |
|
| 3479 | + if ( ! $updated) { |
|
| 3480 | + $success = 0; |
|
| 3481 | + } |
|
| 3482 | + } |
|
| 3483 | + $what = $success > 1 |
|
| 3484 | + ? esc_html__('Contacts', 'event_espresso') |
|
| 3485 | + : esc_html__('Contact', 'event_espresso'); |
|
| 3486 | + $action_desc = $trash |
|
| 3487 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3488 | + : esc_html__('restored', 'event_espresso'); |
|
| 3489 | + $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list')); |
|
| 3490 | + } |
|
| 3491 | 3491 | |
| 3492 | 3492 | } |