@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | { |
| 37 | 37 | if (isset($input_settings['value_field_name'])) { |
| 38 | 38 | $this->valueFieldName = $input_settings['value_field_name']; |
| 39 | - if (! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
|
| 39 | + if ( ! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
|
| 40 | 40 | throw new InvalidArgumentException( |
| 41 | 41 | sprintf( |
| 42 | 42 | esc_html__('An invalid state field "%1$s" was specified for the state input\'s option values.', 'event_espresso'), |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $this |
| 54 | 54 | ); |
| 55 | 55 | $input_settings['html_class'] = isset($input_settings['html_class']) |
| 56 | - ? $input_settings['html_class'] . ' ee-state-select-js' |
|
| 56 | + ? $input_settings['html_class'].' ee-state-select-js' |
|
| 57 | 57 | : 'ee-state-select-js'; |
| 58 | 58 | parent::__construct($state_options, $input_settings); |
| 59 | 59 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | public function get_state_answer_options($state_options = null) |
| 84 | 84 | { |
| 85 | 85 | // if passed something that is NOT an array |
| 86 | - if (! is_array($state_options) || empty($state_options)) { |
|
| 86 | + if ( ! is_array($state_options) || empty($state_options)) { |
|
| 87 | 87 | // get possibly cached list of states |
| 88 | 88 | $states = EEM_State::instance()->get_all_active_states(); |
| 89 | 89 | } |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | $states = $state_options; |
| 92 | 92 | $state_options = array(); |
| 93 | 93 | } |
| 94 | - if (! empty($states)) { |
|
| 94 | + if ( ! empty($states)) { |
|
| 95 | 95 | // set the default |
| 96 | 96 | $state_options[''][''] = ''; |
| 97 | 97 | foreach ($states as $state) { |
| 98 | 98 | if ($state instanceof EE_State) { |
| 99 | - $state_options[ $state->country()->name() ][ $state->get($this->valueFieldName()) ] = $state->name(); |
|
| 99 | + $state_options[$state->country()->name()][$state->get($this->valueFieldName())] = $state->name(); |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -12,94 +12,94 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class EE_State_Select_Input extends EE_Select_Input |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var string the name of the EE_State field to use for option values in the HTML form input. |
|
| 17 | - */ |
|
| 18 | - protected $valueFieldName; |
|
| 15 | + /** |
|
| 16 | + * @var string the name of the EE_State field to use for option values in the HTML form input. |
|
| 17 | + */ |
|
| 18 | + protected $valueFieldName; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @param EE_State[]|array|null $state_options. If a flat array of string is provided, |
|
| 22 | - * $input_settings['value_field_name'] is ignored. If an array of states is passed, that field will be used for |
|
| 23 | - * the keys (which will become the option values). If null or empty is passed, all active states will be used, |
|
| 24 | - * and $input_settings['value_field_name'] will again be used. * |
|
| 25 | - * @param array $input_settings same as parent, but also { |
|
| 26 | - * @type string $value_field_name the name of the field to use |
|
| 27 | - * for the HTML option values, ie, `STA_ID`, `STA_abbrev`, or `STA_name`. |
|
| 28 | - * } |
|
| 29 | - * @throws EE_Error |
|
| 30 | - * @throws InvalidArgumentException |
|
| 31 | - * @throws InvalidDataTypeException |
|
| 32 | - * @throws InvalidInterfaceException |
|
| 33 | - * @throws ReflectionException |
|
| 34 | - */ |
|
| 35 | - public function __construct($state_options, $input_settings = array()) |
|
| 36 | - { |
|
| 37 | - if (isset($input_settings['value_field_name'])) { |
|
| 38 | - $this->valueFieldName = $input_settings['value_field_name']; |
|
| 39 | - if (! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
|
| 40 | - throw new InvalidArgumentException( |
|
| 41 | - sprintf( |
|
| 42 | - esc_html__('An invalid state field "%1$s" was specified for the state input\'s option values.', 'event_espresso'), |
|
| 43 | - $this->valueFieldName() |
|
| 44 | - ) |
|
| 45 | - ); |
|
| 46 | - } |
|
| 47 | - } else { |
|
| 48 | - $this->valueFieldName = 'STA_ID'; |
|
| 49 | - } |
|
| 50 | - $state_options = apply_filters( |
|
| 51 | - 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 52 | - $this->get_state_answer_options($state_options), |
|
| 53 | - $this |
|
| 54 | - ); |
|
| 55 | - $input_settings['html_class'] = isset($input_settings['html_class']) |
|
| 56 | - ? $input_settings['html_class'] . ' ee-state-select-js' |
|
| 57 | - : 'ee-state-select-js'; |
|
| 58 | - parent::__construct($state_options, $input_settings); |
|
| 59 | - } |
|
| 20 | + /** |
|
| 21 | + * @param EE_State[]|array|null $state_options. If a flat array of string is provided, |
|
| 22 | + * $input_settings['value_field_name'] is ignored. If an array of states is passed, that field will be used for |
|
| 23 | + * the keys (which will become the option values). If null or empty is passed, all active states will be used, |
|
| 24 | + * and $input_settings['value_field_name'] will again be used. * |
|
| 25 | + * @param array $input_settings same as parent, but also { |
|
| 26 | + * @type string $value_field_name the name of the field to use |
|
| 27 | + * for the HTML option values, ie, `STA_ID`, `STA_abbrev`, or `STA_name`. |
|
| 28 | + * } |
|
| 29 | + * @throws EE_Error |
|
| 30 | + * @throws InvalidArgumentException |
|
| 31 | + * @throws InvalidDataTypeException |
|
| 32 | + * @throws InvalidInterfaceException |
|
| 33 | + * @throws ReflectionException |
|
| 34 | + */ |
|
| 35 | + public function __construct($state_options, $input_settings = array()) |
|
| 36 | + { |
|
| 37 | + if (isset($input_settings['value_field_name'])) { |
|
| 38 | + $this->valueFieldName = $input_settings['value_field_name']; |
|
| 39 | + if (! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
|
| 40 | + throw new InvalidArgumentException( |
|
| 41 | + sprintf( |
|
| 42 | + esc_html__('An invalid state field "%1$s" was specified for the state input\'s option values.', 'event_espresso'), |
|
| 43 | + $this->valueFieldName() |
|
| 44 | + ) |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | + } else { |
|
| 48 | + $this->valueFieldName = 'STA_ID'; |
|
| 49 | + } |
|
| 50 | + $state_options = apply_filters( |
|
| 51 | + 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 52 | + $this->get_state_answer_options($state_options), |
|
| 53 | + $this |
|
| 54 | + ); |
|
| 55 | + $input_settings['html_class'] = isset($input_settings['html_class']) |
|
| 56 | + ? $input_settings['html_class'] . ' ee-state-select-js' |
|
| 57 | + : 'ee-state-select-js'; |
|
| 58 | + parent::__construct($state_options, $input_settings); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Returns the name of the state field used for the HTML option values. |
|
| 63 | - * @since $VID:$ |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - public function valueFieldName() |
|
| 67 | - { |
|
| 68 | - return $this->valueFieldName; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Returns the name of the state field used for the HTML option values. |
|
| 63 | + * @since $VID:$ |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + public function valueFieldName() |
|
| 67 | + { |
|
| 68 | + return $this->valueFieldName; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * get_state_answer_options |
|
| 74 | - * |
|
| 75 | - * @param array $state_options |
|
| 76 | - * @return array |
|
| 77 | - * @throws EE_Error |
|
| 78 | - * @throws InvalidArgumentException |
|
| 79 | - * @throws ReflectionException |
|
| 80 | - * @throws InvalidDataTypeException |
|
| 81 | - * @throws InvalidInterfaceException |
|
| 82 | - */ |
|
| 83 | - public function get_state_answer_options($state_options = null) |
|
| 84 | - { |
|
| 85 | - // if passed something that is NOT an array |
|
| 86 | - if (! is_array($state_options) || empty($state_options)) { |
|
| 87 | - // get possibly cached list of states |
|
| 88 | - $states = EEM_State::instance()->get_all_active_states(); |
|
| 89 | - } |
|
| 90 | - if (is_array($state_options) && reset($state_options) instanceof EE_State) { |
|
| 91 | - $states = $state_options; |
|
| 92 | - $state_options = array(); |
|
| 93 | - } |
|
| 94 | - if (! empty($states)) { |
|
| 95 | - // set the default |
|
| 96 | - $state_options[''][''] = ''; |
|
| 97 | - foreach ($states as $state) { |
|
| 98 | - if ($state instanceof EE_State) { |
|
| 99 | - $state_options[ $state->country()->name() ][ $state->get($this->valueFieldName()) ] = $state->name(); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - return $state_options; |
|
| 104 | - } |
|
| 72 | + /** |
|
| 73 | + * get_state_answer_options |
|
| 74 | + * |
|
| 75 | + * @param array $state_options |
|
| 76 | + * @return array |
|
| 77 | + * @throws EE_Error |
|
| 78 | + * @throws InvalidArgumentException |
|
| 79 | + * @throws ReflectionException |
|
| 80 | + * @throws InvalidDataTypeException |
|
| 81 | + * @throws InvalidInterfaceException |
|
| 82 | + */ |
|
| 83 | + public function get_state_answer_options($state_options = null) |
|
| 84 | + { |
|
| 85 | + // if passed something that is NOT an array |
|
| 86 | + if (! is_array($state_options) || empty($state_options)) { |
|
| 87 | + // get possibly cached list of states |
|
| 88 | + $states = EEM_State::instance()->get_all_active_states(); |
|
| 89 | + } |
|
| 90 | + if (is_array($state_options) && reset($state_options) instanceof EE_State) { |
|
| 91 | + $states = $state_options; |
|
| 92 | + $state_options = array(); |
|
| 93 | + } |
|
| 94 | + if (! empty($states)) { |
|
| 95 | + // set the default |
|
| 96 | + $state_options[''][''] = ''; |
|
| 97 | + foreach ($states as $state) { |
|
| 98 | + if ($state instanceof EE_State) { |
|
| 99 | + $state_options[ $state->country()->name() ][ $state->get($this->valueFieldName()) ] = $state->name(); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + return $state_options; |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -24,8 +24,8 @@ discard block |
||
| 24 | 24 | "url": "<?php echo $event_permalink; ?>", |
| 25 | 25 | "offers": [ |
| 26 | 26 | <?php |
| 27 | - $i = 0; |
|
| 28 | - foreach ($event_tickets as $ticket) {?> |
|
| 27 | + $i = 0; |
|
| 28 | + foreach ($event_tickets as $ticket) {?> |
|
| 29 | 29 | { |
| 30 | 30 | "@type": "Offer", |
| 31 | 31 | "url": "<?php echo $event_permalink; ?>", |
@@ -34,18 +34,18 @@ discard block |
||
| 34 | 34 | "price": "<?php echo $ticket['price']; ?>", |
| 35 | 35 | "priceCurrency": "<?php echo $currency; ?>" |
| 36 | 36 | <?php if (isset($ticket['availability'])) { |
| 37 | - ?>,"availability": "http://schema.org/<?php echo $ticket['availability']; ?>" |
|
| 37 | + ?>,"availability": "http://schema.org/<?php echo $ticket['availability']; ?>" |
|
| 38 | 38 | <?php } ?> |
| 39 | 39 | }<?php |
| 40 | - $i++; |
|
| 41 | - if ($i < count($event_tickets)) { |
|
| 42 | - echo ','; |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - ?> |
|
| 40 | + $i++; |
|
| 41 | + if ($i < count($event_tickets)) { |
|
| 42 | + echo ','; |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + ?> |
|
| 46 | 46 | ]<?php |
| 47 | - if ($venue_name) { |
|
| 48 | - ?>, |
|
| 47 | + if ($venue_name) { |
|
| 48 | + ?>, |
|
| 49 | 49 | "location": { |
| 50 | 50 | "@type": "Place", |
| 51 | 51 | "name": <?php echo wp_json_encode($venue_name); ?>, |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | <?php |
| 61 | - } ?> |
|
| 61 | + } ?> |
|
| 62 | 62 | <?php |
| 63 | - if ($event_image) { |
|
| 64 | - ?>, |
|
| 63 | + if ($event_image) { |
|
| 64 | + ?>, |
|
| 65 | 65 | "image": "<?php echo $event_image; ?>" |
| 66 | 66 | <?php |
| 67 | - } ?> |
|
| 67 | + } ?> |
|
| 68 | 68 | <?php do_action('AHEE__json_linked_data_for_event__template'); ?> |
| 69 | 69 | } |
| 70 | 70 | |
@@ -19,2399 +19,2399 @@ discard block |
||
| 19 | 19 | class Registrations_Admin_Page extends EE_Admin_Page_CPT |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var EE_Registration |
|
| 24 | - */ |
|
| 25 | - private $_registration; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var EE_Event |
|
| 29 | - */ |
|
| 30 | - private $_reg_event; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var EE_Session |
|
| 34 | - */ |
|
| 35 | - private $_session; |
|
| 36 | - |
|
| 37 | - private static $_reg_status; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Form for displaying the custom questions for this registration. |
|
| 41 | - * This gets used a few times throughout the request so its best to cache it |
|
| 42 | - * |
|
| 43 | - * @var EE_Registration_Custom_Questions_Form |
|
| 44 | - */ |
|
| 45 | - protected $_reg_custom_questions_form = null; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * constructor |
|
| 50 | - * |
|
| 51 | - * @Constructor |
|
| 52 | - * @access public |
|
| 53 | - * @param bool $routing |
|
| 54 | - * @return Registrations_Admin_Page |
|
| 55 | - */ |
|
| 56 | - public function __construct($routing = true) |
|
| 57 | - { |
|
| 58 | - parent::__construct($routing); |
|
| 59 | - add_action('wp_loaded', array($this, 'wp_loaded')); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - public function wp_loaded() |
|
| 64 | - { |
|
| 65 | - // when adding a new registration... |
|
| 66 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
|
| 67 | - EE_System::do_not_cache(); |
|
| 68 | - if (! isset($this->_req_data['processing_registration']) |
|
| 69 | - || absint($this->_req_data['processing_registration']) !== 1 |
|
| 70 | - ) { |
|
| 71 | - // and it's NOT the attendee information reg step |
|
| 72 | - // force cookie expiration by setting time to last week |
|
| 73 | - setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
| 74 | - // and update the global |
|
| 75 | - $_COOKIE['ee_registration_added'] = 0; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - protected function _init_page_props() |
|
| 82 | - { |
|
| 83 | - $this->page_slug = REG_PG_SLUG; |
|
| 84 | - $this->_admin_base_url = REG_ADMIN_URL; |
|
| 85 | - $this->_admin_base_path = REG_ADMIN; |
|
| 86 | - $this->page_label = esc_html__('Registrations', 'event_espresso'); |
|
| 87 | - $this->_cpt_routes = array( |
|
| 88 | - 'add_new_attendee' => 'espresso_attendees', |
|
| 89 | - 'edit_attendee' => 'espresso_attendees', |
|
| 90 | - 'insert_attendee' => 'espresso_attendees', |
|
| 91 | - 'update_attendee' => 'espresso_attendees', |
|
| 92 | - ); |
|
| 93 | - $this->_cpt_model_names = array( |
|
| 94 | - 'add_new_attendee' => 'EEM_Attendee', |
|
| 95 | - 'edit_attendee' => 'EEM_Attendee', |
|
| 96 | - ); |
|
| 97 | - $this->_cpt_edit_routes = array( |
|
| 98 | - 'espresso_attendees' => 'edit_attendee', |
|
| 99 | - ); |
|
| 100 | - $this->_pagenow_map = array( |
|
| 101 | - 'add_new_attendee' => 'post-new.php', |
|
| 102 | - 'edit_attendee' => 'post.php', |
|
| 103 | - 'trash' => 'post.php', |
|
| 104 | - ); |
|
| 105 | - add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10); |
|
| 106 | - // add filters so that the comment urls don't take users to a confusing 404 page |
|
| 107 | - add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - public function clear_comment_link($link, $comment, $args) |
|
| 112 | - { |
|
| 113 | - // gotta make sure this only happens on this route |
|
| 114 | - $post_type = get_post_type($comment->comment_post_ID); |
|
| 115 | - if ($post_type === 'espresso_attendees') { |
|
| 116 | - return '#commentsdiv'; |
|
| 117 | - } |
|
| 118 | - return $link; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - protected function _ajax_hooks() |
|
| 123 | - { |
|
| 124 | - // todo: all hooks for registrations ajax goes in here |
|
| 125 | - add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status')); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - |
|
| 129 | - protected function _define_page_props() |
|
| 130 | - { |
|
| 131 | - $this->_admin_page_title = $this->page_label; |
|
| 132 | - $this->_labels = array( |
|
| 133 | - 'buttons' => array( |
|
| 134 | - 'add-registrant' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 135 | - 'add-attendee' => esc_html__('Add Contact', 'event_espresso'), |
|
| 136 | - 'edit' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 137 | - 'report' => esc_html__("Event Registrations CSV Report", "event_espresso"), |
|
| 138 | - 'report_all' => esc_html__('All Registrations CSV Report', 'event_espresso'), |
|
| 139 | - 'report_filtered' => esc_html__('Filtered CSV Report', 'event_espresso'), |
|
| 140 | - 'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'), |
|
| 141 | - 'contact_list_export' => esc_html__("Export Data", "event_espresso"), |
|
| 142 | - ), |
|
| 143 | - 'publishbox' => array( |
|
| 144 | - 'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'), |
|
| 145 | - 'edit_attendee' => esc_html__("Update Contact Record", 'event_espresso'), |
|
| 146 | - ), |
|
| 147 | - 'hide_add_button_on_cpt_route' => array( |
|
| 148 | - 'edit_attendee' => true, |
|
| 149 | - ), |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * grab url requests and route them |
|
| 156 | - * |
|
| 157 | - * @access private |
|
| 158 | - * @return void |
|
| 159 | - */ |
|
| 160 | - public function _set_page_routes() |
|
| 161 | - { |
|
| 162 | - $this->_get_registration_status_array(); |
|
| 163 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 164 | - ? $this->_req_data['_REG_ID'] : 0; |
|
| 165 | - $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 166 | - ? $this->_req_data['reg_status_change_form']['REG_ID'] |
|
| 167 | - : $reg_id; |
|
| 168 | - $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID']) |
|
| 169 | - ? $this->_req_data['ATT_ID'] : 0; |
|
| 170 | - $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) |
|
| 171 | - ? $this->_req_data['post'] |
|
| 172 | - : $att_id; |
|
| 173 | - $this->_page_routes = array( |
|
| 174 | - 'default' => array( |
|
| 175 | - 'func' => '_registrations_overview_list_table', |
|
| 176 | - 'capability' => 'ee_read_registrations', |
|
| 177 | - ), |
|
| 178 | - 'view_registration' => array( |
|
| 179 | - 'func' => '_registration_details', |
|
| 180 | - 'capability' => 'ee_read_registration', |
|
| 181 | - 'obj_id' => $reg_id, |
|
| 182 | - ), |
|
| 183 | - 'edit_registration' => array( |
|
| 184 | - 'func' => '_update_attendee_registration_form', |
|
| 185 | - 'noheader' => true, |
|
| 186 | - 'headers_sent_route' => 'view_registration', |
|
| 187 | - 'capability' => 'ee_edit_registration', |
|
| 188 | - 'obj_id' => $reg_id, |
|
| 189 | - '_REG_ID' => $reg_id, |
|
| 190 | - ), |
|
| 191 | - 'trash_registrations' => array( |
|
| 192 | - 'func' => '_trash_or_restore_registrations', |
|
| 193 | - 'args' => array('trash' => true), |
|
| 194 | - 'noheader' => true, |
|
| 195 | - 'capability' => 'ee_delete_registrations', |
|
| 196 | - ), |
|
| 197 | - 'restore_registrations' => array( |
|
| 198 | - 'func' => '_trash_or_restore_registrations', |
|
| 199 | - 'args' => array('trash' => false), |
|
| 200 | - 'noheader' => true, |
|
| 201 | - 'capability' => 'ee_delete_registrations', |
|
| 202 | - ), |
|
| 203 | - 'delete_registrations' => array( |
|
| 204 | - 'func' => '_delete_registrations', |
|
| 205 | - 'noheader' => true, |
|
| 206 | - 'capability' => 'ee_delete_registrations', |
|
| 207 | - ), |
|
| 208 | - 'new_registration' => array( |
|
| 209 | - 'func' => 'new_registration', |
|
| 210 | - 'capability' => 'ee_edit_registrations', |
|
| 211 | - ), |
|
| 212 | - 'process_reg_step' => array( |
|
| 213 | - 'func' => 'process_reg_step', |
|
| 214 | - 'noheader' => true, |
|
| 215 | - 'capability' => 'ee_edit_registrations', |
|
| 216 | - ), |
|
| 217 | - 'redirect_to_txn' => array( |
|
| 218 | - 'func' => 'redirect_to_txn', |
|
| 219 | - 'noheader' => true, |
|
| 220 | - 'capability' => 'ee_edit_registrations', |
|
| 221 | - ), |
|
| 222 | - 'change_reg_status' => array( |
|
| 223 | - 'func' => '_change_reg_status', |
|
| 224 | - 'noheader' => true, |
|
| 225 | - 'capability' => 'ee_edit_registration', |
|
| 226 | - 'obj_id' => $reg_id, |
|
| 227 | - ), |
|
| 228 | - 'approve_registration' => array( |
|
| 229 | - 'func' => 'approve_registration', |
|
| 230 | - 'noheader' => true, |
|
| 231 | - 'capability' => 'ee_edit_registration', |
|
| 232 | - 'obj_id' => $reg_id, |
|
| 233 | - ), |
|
| 234 | - 'approve_and_notify_registration' => array( |
|
| 235 | - 'func' => 'approve_registration', |
|
| 236 | - 'noheader' => true, |
|
| 237 | - 'args' => array(true), |
|
| 238 | - 'capability' => 'ee_edit_registration', |
|
| 239 | - 'obj_id' => $reg_id, |
|
| 240 | - ), |
|
| 241 | - 'approve_registrations' => array( |
|
| 242 | - 'func' => 'bulk_action_on_registrations', |
|
| 243 | - 'noheader' => true, |
|
| 244 | - 'capability' => 'ee_edit_registrations', |
|
| 245 | - 'args' => array('approve'), |
|
| 246 | - ), |
|
| 247 | - 'approve_and_notify_registrations' => array( |
|
| 248 | - 'func' => 'bulk_action_on_registrations', |
|
| 249 | - 'noheader' => true, |
|
| 250 | - 'capability' => 'ee_edit_registrations', |
|
| 251 | - 'args' => array('approve', true), |
|
| 252 | - ), |
|
| 253 | - 'decline_registration' => array( |
|
| 254 | - 'func' => 'decline_registration', |
|
| 255 | - 'noheader' => true, |
|
| 256 | - 'capability' => 'ee_edit_registration', |
|
| 257 | - 'obj_id' => $reg_id, |
|
| 258 | - ), |
|
| 259 | - 'decline_and_notify_registration' => array( |
|
| 260 | - 'func' => 'decline_registration', |
|
| 261 | - 'noheader' => true, |
|
| 262 | - 'args' => array(true), |
|
| 263 | - 'capability' => 'ee_edit_registration', |
|
| 264 | - 'obj_id' => $reg_id, |
|
| 265 | - ), |
|
| 266 | - 'decline_registrations' => array( |
|
| 267 | - 'func' => 'bulk_action_on_registrations', |
|
| 268 | - 'noheader' => true, |
|
| 269 | - 'capability' => 'ee_edit_registrations', |
|
| 270 | - 'args' => array('decline'), |
|
| 271 | - ), |
|
| 272 | - 'decline_and_notify_registrations' => array( |
|
| 273 | - 'func' => 'bulk_action_on_registrations', |
|
| 274 | - 'noheader' => true, |
|
| 275 | - 'capability' => 'ee_edit_registrations', |
|
| 276 | - 'args' => array('decline', true), |
|
| 277 | - ), |
|
| 278 | - 'pending_registration' => array( |
|
| 279 | - 'func' => 'pending_registration', |
|
| 280 | - 'noheader' => true, |
|
| 281 | - 'capability' => 'ee_edit_registration', |
|
| 282 | - 'obj_id' => $reg_id, |
|
| 283 | - ), |
|
| 284 | - 'pending_and_notify_registration' => array( |
|
| 285 | - 'func' => 'pending_registration', |
|
| 286 | - 'noheader' => true, |
|
| 287 | - 'args' => array(true), |
|
| 288 | - 'capability' => 'ee_edit_registration', |
|
| 289 | - 'obj_id' => $reg_id, |
|
| 290 | - ), |
|
| 291 | - 'pending_registrations' => array( |
|
| 292 | - 'func' => 'bulk_action_on_registrations', |
|
| 293 | - 'noheader' => true, |
|
| 294 | - 'capability' => 'ee_edit_registrations', |
|
| 295 | - 'args' => array('pending'), |
|
| 296 | - ), |
|
| 297 | - 'pending_and_notify_registrations' => array( |
|
| 298 | - 'func' => 'bulk_action_on_registrations', |
|
| 299 | - 'noheader' => true, |
|
| 300 | - 'capability' => 'ee_edit_registrations', |
|
| 301 | - 'args' => array('pending', true), |
|
| 302 | - ), |
|
| 303 | - 'no_approve_registration' => array( |
|
| 304 | - 'func' => 'not_approve_registration', |
|
| 305 | - 'noheader' => true, |
|
| 306 | - 'capability' => 'ee_edit_registration', |
|
| 307 | - 'obj_id' => $reg_id, |
|
| 308 | - ), |
|
| 309 | - 'no_approve_and_notify_registration' => array( |
|
| 310 | - 'func' => 'not_approve_registration', |
|
| 311 | - 'noheader' => true, |
|
| 312 | - 'args' => array(true), |
|
| 313 | - 'capability' => 'ee_edit_registration', |
|
| 314 | - 'obj_id' => $reg_id, |
|
| 315 | - ), |
|
| 316 | - 'no_approve_registrations' => array( |
|
| 317 | - 'func' => 'bulk_action_on_registrations', |
|
| 318 | - 'noheader' => true, |
|
| 319 | - 'capability' => 'ee_edit_registrations', |
|
| 320 | - 'args' => array('not_approve'), |
|
| 321 | - ), |
|
| 322 | - 'no_approve_and_notify_registrations' => array( |
|
| 323 | - 'func' => 'bulk_action_on_registrations', |
|
| 324 | - 'noheader' => true, |
|
| 325 | - 'capability' => 'ee_edit_registrations', |
|
| 326 | - 'args' => array('not_approve', true), |
|
| 327 | - ), |
|
| 328 | - 'cancel_registration' => array( |
|
| 329 | - 'func' => 'cancel_registration', |
|
| 330 | - 'noheader' => true, |
|
| 331 | - 'capability' => 'ee_edit_registration', |
|
| 332 | - 'obj_id' => $reg_id, |
|
| 333 | - ), |
|
| 334 | - 'cancel_and_notify_registration' => array( |
|
| 335 | - 'func' => 'cancel_registration', |
|
| 336 | - 'noheader' => true, |
|
| 337 | - 'args' => array(true), |
|
| 338 | - 'capability' => 'ee_edit_registration', |
|
| 339 | - 'obj_id' => $reg_id, |
|
| 340 | - ), |
|
| 341 | - 'cancel_registrations' => array( |
|
| 342 | - 'func' => 'bulk_action_on_registrations', |
|
| 343 | - 'noheader' => true, |
|
| 344 | - 'capability' => 'ee_edit_registrations', |
|
| 345 | - 'args' => array('cancel'), |
|
| 346 | - ), |
|
| 347 | - 'cancel_and_notify_registrations' => array( |
|
| 348 | - 'func' => 'bulk_action_on_registrations', |
|
| 349 | - 'noheader' => true, |
|
| 350 | - 'capability' => 'ee_edit_registrations', |
|
| 351 | - 'args' => array('cancel', true), |
|
| 352 | - ), |
|
| 353 | - 'wait_list_registration' => array( |
|
| 354 | - 'func' => 'wait_list_registration', |
|
| 355 | - 'noheader' => true, |
|
| 356 | - 'capability' => 'ee_edit_registration', |
|
| 357 | - 'obj_id' => $reg_id, |
|
| 358 | - ), |
|
| 359 | - 'wait_list_and_notify_registration' => array( |
|
| 360 | - 'func' => 'wait_list_registration', |
|
| 361 | - 'noheader' => true, |
|
| 362 | - 'args' => array(true), |
|
| 363 | - 'capability' => 'ee_edit_registration', |
|
| 364 | - 'obj_id' => $reg_id, |
|
| 365 | - ), |
|
| 366 | - 'contact_list' => array( |
|
| 367 | - 'func' => '_attendee_contact_list_table', |
|
| 368 | - 'capability' => 'ee_read_contacts', |
|
| 369 | - ), |
|
| 370 | - 'add_new_attendee' => array( |
|
| 371 | - 'func' => '_create_new_cpt_item', |
|
| 372 | - 'args' => array( |
|
| 373 | - 'new_attendee' => true, |
|
| 374 | - 'capability' => 'ee_edit_contacts', |
|
| 375 | - ), |
|
| 376 | - ), |
|
| 377 | - 'edit_attendee' => array( |
|
| 378 | - 'func' => '_edit_cpt_item', |
|
| 379 | - 'capability' => 'ee_edit_contacts', |
|
| 380 | - 'obj_id' => $att_id, |
|
| 381 | - ), |
|
| 382 | - 'duplicate_attendee' => array( |
|
| 383 | - 'func' => '_duplicate_attendee', |
|
| 384 | - 'noheader' => true, |
|
| 385 | - 'capability' => 'ee_edit_contacts', |
|
| 386 | - 'obj_id' => $att_id, |
|
| 387 | - ), |
|
| 388 | - 'insert_attendee' => array( |
|
| 389 | - 'func' => '_insert_or_update_attendee', |
|
| 390 | - 'args' => array( |
|
| 391 | - 'new_attendee' => true, |
|
| 392 | - ), |
|
| 393 | - 'noheader' => true, |
|
| 394 | - 'capability' => 'ee_edit_contacts', |
|
| 395 | - ), |
|
| 396 | - 'update_attendee' => array( |
|
| 397 | - 'func' => '_insert_or_update_attendee', |
|
| 398 | - 'args' => array( |
|
| 399 | - 'new_attendee' => false, |
|
| 400 | - ), |
|
| 401 | - 'noheader' => true, |
|
| 402 | - 'capability' => 'ee_edit_contacts', |
|
| 403 | - 'obj_id' => $att_id, |
|
| 404 | - ), |
|
| 405 | - 'trash_attendees' => array( |
|
| 406 | - 'func' => '_trash_or_restore_attendees', |
|
| 407 | - 'args' => array( |
|
| 408 | - 'trash' => 'true', |
|
| 409 | - ), |
|
| 410 | - 'noheader' => true, |
|
| 411 | - 'capability' => 'ee_delete_contacts', |
|
| 412 | - ), |
|
| 413 | - 'trash_attendee' => array( |
|
| 414 | - 'func' => '_trash_or_restore_attendees', |
|
| 415 | - 'args' => array( |
|
| 416 | - 'trash' => true, |
|
| 417 | - ), |
|
| 418 | - 'noheader' => true, |
|
| 419 | - 'capability' => 'ee_delete_contacts', |
|
| 420 | - 'obj_id' => $att_id, |
|
| 421 | - ), |
|
| 422 | - 'restore_attendees' => array( |
|
| 423 | - 'func' => '_trash_or_restore_attendees', |
|
| 424 | - 'args' => array( |
|
| 425 | - 'trash' => false, |
|
| 426 | - ), |
|
| 427 | - 'noheader' => true, |
|
| 428 | - 'capability' => 'ee_delete_contacts', |
|
| 429 | - 'obj_id' => $att_id, |
|
| 430 | - ), |
|
| 431 | - 'resend_registration' => array( |
|
| 432 | - 'func' => '_resend_registration', |
|
| 433 | - 'noheader' => true, |
|
| 434 | - 'capability' => 'ee_send_message', |
|
| 435 | - ), |
|
| 436 | - 'registrations_report' => array( |
|
| 437 | - 'func' => '_registrations_report', |
|
| 438 | - 'noheader' => true, |
|
| 439 | - 'capability' => 'ee_read_registrations', |
|
| 440 | - ), |
|
| 441 | - 'contact_list_export' => array( |
|
| 442 | - 'func' => '_contact_list_export', |
|
| 443 | - 'noheader' => true, |
|
| 444 | - 'capability' => 'export', |
|
| 445 | - ), |
|
| 446 | - 'contact_list_report' => array( |
|
| 447 | - 'func' => '_contact_list_report', |
|
| 448 | - 'noheader' => true, |
|
| 449 | - 'capability' => 'ee_read_contacts', |
|
| 450 | - ), |
|
| 451 | - ); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - protected function _set_page_config() |
|
| 456 | - { |
|
| 457 | - $this->_page_config = array( |
|
| 458 | - 'default' => array( |
|
| 459 | - 'nav' => array( |
|
| 460 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 461 | - 'order' => 5, |
|
| 462 | - ), |
|
| 463 | - 'help_tabs' => array( |
|
| 464 | - 'registrations_overview_help_tab' => array( |
|
| 465 | - 'title' => esc_html__('Registrations Overview', 'event_espresso'), |
|
| 466 | - 'filename' => 'registrations_overview', |
|
| 467 | - ), |
|
| 468 | - 'registrations_overview_table_column_headings_help_tab' => array( |
|
| 469 | - 'title' => esc_html__('Registrations Table Column Headings', 'event_espresso'), |
|
| 470 | - 'filename' => 'registrations_overview_table_column_headings', |
|
| 471 | - ), |
|
| 472 | - 'registrations_overview_filters_help_tab' => array( |
|
| 473 | - 'title' => esc_html__('Registration Filters', 'event_espresso'), |
|
| 474 | - 'filename' => 'registrations_overview_filters', |
|
| 475 | - ), |
|
| 476 | - 'registrations_overview_views_help_tab' => array( |
|
| 477 | - 'title' => esc_html__('Registration Views', 'event_espresso'), |
|
| 478 | - 'filename' => 'registrations_overview_views', |
|
| 479 | - ), |
|
| 480 | - 'registrations_regoverview_other_help_tab' => array( |
|
| 481 | - 'title' => esc_html__('Registrations Other', 'event_espresso'), |
|
| 482 | - 'filename' => 'registrations_overview_other', |
|
| 483 | - ), |
|
| 484 | - ), |
|
| 485 | - 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
| 486 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
| 487 | - 'list_table' => 'EE_Registrations_List_Table', |
|
| 488 | - 'require_nonce' => false, |
|
| 489 | - ), |
|
| 490 | - 'view_registration' => array( |
|
| 491 | - 'nav' => array( |
|
| 492 | - 'label' => esc_html__('REG Details', 'event_espresso'), |
|
| 493 | - 'order' => 15, |
|
| 494 | - 'url' => isset($this->_req_data['_REG_ID']) |
|
| 495 | - ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url) |
|
| 496 | - : $this->_admin_base_url, |
|
| 497 | - 'persistent' => false, |
|
| 498 | - ), |
|
| 499 | - 'help_tabs' => array( |
|
| 500 | - 'registrations_details_help_tab' => array( |
|
| 501 | - 'title' => esc_html__('Registration Details', 'event_espresso'), |
|
| 502 | - 'filename' => 'registrations_details', |
|
| 503 | - ), |
|
| 504 | - 'registrations_details_table_help_tab' => array( |
|
| 505 | - 'title' => esc_html__('Registration Details Table', 'event_espresso'), |
|
| 506 | - 'filename' => 'registrations_details_table', |
|
| 507 | - ), |
|
| 508 | - 'registrations_details_form_answers_help_tab' => array( |
|
| 509 | - 'title' => esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 510 | - 'filename' => 'registrations_details_form_answers', |
|
| 511 | - ), |
|
| 512 | - 'registrations_details_registrant_details_help_tab' => array( |
|
| 513 | - 'title' => esc_html__('Contact Details', 'event_espresso'), |
|
| 514 | - 'filename' => 'registrations_details_registrant_details', |
|
| 515 | - ), |
|
| 516 | - ), |
|
| 517 | - 'help_tour' => array('Registration_Details_Help_Tour'), |
|
| 518 | - 'metaboxes' => array_merge( |
|
| 519 | - $this->_default_espresso_metaboxes, |
|
| 520 | - array('_registration_details_metaboxes') |
|
| 521 | - ), |
|
| 522 | - 'require_nonce' => false, |
|
| 523 | - ), |
|
| 524 | - 'new_registration' => array( |
|
| 525 | - 'nav' => array( |
|
| 526 | - 'label' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 527 | - 'url' => '#', |
|
| 528 | - 'order' => 15, |
|
| 529 | - 'persistent' => false, |
|
| 530 | - ), |
|
| 531 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 532 | - 'labels' => array( |
|
| 533 | - 'publishbox' => esc_html__('Save Registration', 'event_espresso'), |
|
| 534 | - ), |
|
| 535 | - 'require_nonce' => false, |
|
| 536 | - ), |
|
| 537 | - 'add_new_attendee' => array( |
|
| 538 | - 'nav' => array( |
|
| 539 | - 'label' => esc_html__('Add Contact', 'event_espresso'), |
|
| 540 | - 'order' => 15, |
|
| 541 | - 'persistent' => false, |
|
| 542 | - ), |
|
| 543 | - 'metaboxes' => array_merge( |
|
| 544 | - $this->_default_espresso_metaboxes, |
|
| 545 | - array('_publish_post_box', 'attendee_editor_metaboxes') |
|
| 546 | - ), |
|
| 547 | - 'require_nonce' => false, |
|
| 548 | - ), |
|
| 549 | - 'edit_attendee' => array( |
|
| 550 | - 'nav' => array( |
|
| 551 | - 'label' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 552 | - 'order' => 15, |
|
| 553 | - 'persistent' => false, |
|
| 554 | - 'url' => isset($this->_req_data['ATT_ID']) |
|
| 555 | - ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url) |
|
| 556 | - : $this->_admin_base_url, |
|
| 557 | - ), |
|
| 558 | - 'metaboxes' => array('attendee_editor_metaboxes'), |
|
| 559 | - 'require_nonce' => false, |
|
| 560 | - ), |
|
| 561 | - 'contact_list' => array( |
|
| 562 | - 'nav' => array( |
|
| 563 | - 'label' => esc_html__('Contact List', 'event_espresso'), |
|
| 564 | - 'order' => 20, |
|
| 565 | - ), |
|
| 566 | - 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
| 567 | - 'help_tabs' => array( |
|
| 568 | - 'registrations_contact_list_help_tab' => array( |
|
| 569 | - 'title' => esc_html__('Registrations Contact List', 'event_espresso'), |
|
| 570 | - 'filename' => 'registrations_contact_list', |
|
| 571 | - ), |
|
| 572 | - 'registrations_contact-list_table_column_headings_help_tab' => array( |
|
| 573 | - 'title' => esc_html__('Contact List Table Column Headings', 'event_espresso'), |
|
| 574 | - 'filename' => 'registrations_contact_list_table_column_headings', |
|
| 575 | - ), |
|
| 576 | - 'registrations_contact_list_views_help_tab' => array( |
|
| 577 | - 'title' => esc_html__('Contact List Views', 'event_espresso'), |
|
| 578 | - 'filename' => 'registrations_contact_list_views', |
|
| 579 | - ), |
|
| 580 | - 'registrations_contact_list_other_help_tab' => array( |
|
| 581 | - 'title' => esc_html__('Contact List Other', 'event_espresso'), |
|
| 582 | - 'filename' => 'registrations_contact_list_other', |
|
| 583 | - ), |
|
| 584 | - ), |
|
| 585 | - 'help_tour' => array('Contact_List_Help_Tour'), |
|
| 586 | - 'metaboxes' => array(), |
|
| 587 | - 'require_nonce' => false, |
|
| 588 | - ), |
|
| 589 | - // override default cpt routes |
|
| 590 | - 'create_new' => '', |
|
| 591 | - 'edit' => '', |
|
| 592 | - ); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * The below methods aren't used by this class currently |
|
| 598 | - */ |
|
| 599 | - protected function _add_screen_options() |
|
| 600 | - { |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - |
|
| 604 | - protected function _add_feature_pointers() |
|
| 605 | - { |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - |
|
| 609 | - public function admin_init() |
|
| 610 | - { |
|
| 611 | - EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__( |
|
| 612 | - 'click "Update Registration Questions" to save your changes', |
|
| 613 | - 'event_espresso' |
|
| 614 | - ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - public function admin_notices() |
|
| 619 | - { |
|
| 620 | - } |
|
| 621 | - |
|
| 622 | - |
|
| 623 | - public function admin_footer_scripts() |
|
| 624 | - { |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * get list of registration statuses |
|
| 630 | - * |
|
| 631 | - * @access private |
|
| 632 | - * @return void |
|
| 633 | - * @throws EE_Error |
|
| 634 | - */ |
|
| 635 | - private function _get_registration_status_array() |
|
| 636 | - { |
|
| 637 | - self::$_reg_status = EEM_Registration::reg_status_array(array(), true); |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - |
|
| 641 | - protected function _add_screen_options_default() |
|
| 642 | - { |
|
| 643 | - $this->_per_page_screen_option(); |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - protected function _add_screen_options_contact_list() |
|
| 648 | - { |
|
| 649 | - $page_title = $this->_admin_page_title; |
|
| 650 | - $this->_admin_page_title = esc_html__("Contacts", 'event_espresso'); |
|
| 651 | - $this->_per_page_screen_option(); |
|
| 652 | - $this->_admin_page_title = $page_title; |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - |
|
| 656 | - public function load_scripts_styles() |
|
| 657 | - { |
|
| 658 | - // style |
|
| 659 | - wp_register_style( |
|
| 660 | - 'espresso_reg', |
|
| 661 | - REG_ASSETS_URL . 'espresso_registrations_admin.css', |
|
| 662 | - array('ee-admin-css'), |
|
| 663 | - EVENT_ESPRESSO_VERSION |
|
| 664 | - ); |
|
| 665 | - wp_enqueue_style('espresso_reg'); |
|
| 666 | - // script |
|
| 667 | - wp_register_script( |
|
| 668 | - 'espresso_reg', |
|
| 669 | - REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 670 | - array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), |
|
| 671 | - EVENT_ESPRESSO_VERSION, |
|
| 672 | - true |
|
| 673 | - ); |
|
| 674 | - wp_enqueue_script('espresso_reg'); |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - public function load_scripts_styles_edit_attendee() |
|
| 679 | - { |
|
| 680 | - // stuff to only show up on our attendee edit details page. |
|
| 681 | - $attendee_details_translations = array( |
|
| 682 | - 'att_publish_text' => sprintf( |
|
| 683 | - /* translators: The date and time */ |
|
| 684 | - wp_strip_all_tags(__('Created on: %s', 'event_espresso')), |
|
| 685 | - '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>' |
|
| 686 | - ), |
|
| 687 | - ); |
|
| 688 | - wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
| 689 | - wp_enqueue_script('jquery-validate'); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - |
|
| 693 | - public function load_scripts_styles_view_registration() |
|
| 694 | - { |
|
| 695 | - // styles |
|
| 696 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 697 | - // scripts |
|
| 698 | - $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 699 | - $this->_reg_custom_questions_form->wp_enqueue_scripts(true); |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - |
|
| 703 | - public function load_scripts_styles_contact_list() |
|
| 704 | - { |
|
| 705 | - wp_dequeue_style('espresso_reg'); |
|
| 706 | - wp_register_style( |
|
| 707 | - 'espresso_att', |
|
| 708 | - REG_ASSETS_URL . 'espresso_attendees_admin.css', |
|
| 709 | - array('ee-admin-css'), |
|
| 710 | - EVENT_ESPRESSO_VERSION |
|
| 711 | - ); |
|
| 712 | - wp_enqueue_style('espresso_att'); |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - |
|
| 716 | - public function load_scripts_styles_new_registration() |
|
| 717 | - { |
|
| 718 | - wp_register_script( |
|
| 719 | - 'ee-spco-for-admin', |
|
| 720 | - REG_ASSETS_URL . 'spco_for_admin.js', |
|
| 721 | - array('underscore', 'jquery'), |
|
| 722 | - EVENT_ESPRESSO_VERSION, |
|
| 723 | - true |
|
| 724 | - ); |
|
| 725 | - wp_enqueue_script('ee-spco-for-admin'); |
|
| 726 | - add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 727 | - EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
| 728 | - EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
| 729 | - EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 730 | - } |
|
| 731 | - |
|
| 732 | - |
|
| 733 | - public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
| 734 | - { |
|
| 735 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - |
|
| 739 | - public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
| 740 | - { |
|
| 741 | - add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - |
|
| 745 | - protected function _set_list_table_views_default() |
|
| 746 | - { |
|
| 747 | - // for notification related bulk actions we need to make sure only active messengers have an option. |
|
| 748 | - EED_Messages::set_autoloaders(); |
|
| 749 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 750 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 751 | - $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
| 752 | - // key= bulk_action_slug, value= message type. |
|
| 753 | - $match_array = array( |
|
| 754 | - 'approve_registrations' => 'registration', |
|
| 755 | - 'decline_registrations' => 'declined_registration', |
|
| 756 | - 'pending_registrations' => 'pending_approval', |
|
| 757 | - 'no_approve_registrations' => 'not_approved_registration', |
|
| 758 | - 'cancel_registrations' => 'cancelled_registration', |
|
| 759 | - ); |
|
| 760 | - $can_send = EE_Registry::instance()->CAP->current_user_can( |
|
| 761 | - 'ee_send_message', |
|
| 762 | - 'batch_send_messages' |
|
| 763 | - ); |
|
| 764 | - /** setup reg status bulk actions **/ |
|
| 765 | - $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso'); |
|
| 766 | - if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) { |
|
| 767 | - $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__( |
|
| 768 | - 'Approve and Notify Registrations', |
|
| 769 | - 'event_espresso' |
|
| 770 | - ); |
|
| 771 | - } |
|
| 772 | - $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso'); |
|
| 773 | - if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) { |
|
| 774 | - $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__( |
|
| 775 | - 'Decline and Notify Registrations', |
|
| 776 | - 'event_espresso' |
|
| 777 | - ); |
|
| 778 | - } |
|
| 779 | - $def_reg_status_actions['pending_registrations'] = esc_html__( |
|
| 780 | - 'Set Registrations to Pending Payment', |
|
| 781 | - 'event_espresso' |
|
| 782 | - ); |
|
| 783 | - if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) { |
|
| 784 | - $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__( |
|
| 785 | - 'Set Registrations to Pending Payment and Notify', |
|
| 786 | - 'event_espresso' |
|
| 787 | - ); |
|
| 788 | - } |
|
| 789 | - $def_reg_status_actions['no_approve_registrations'] = esc_html__( |
|
| 790 | - 'Set Registrations to Not Approved', |
|
| 791 | - 'event_espresso' |
|
| 792 | - ); |
|
| 793 | - if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) { |
|
| 794 | - $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__( |
|
| 795 | - 'Set Registrations to Not Approved and Notify', |
|
| 796 | - 'event_espresso' |
|
| 797 | - ); |
|
| 798 | - } |
|
| 799 | - $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso'); |
|
| 800 | - if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) { |
|
| 801 | - $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__( |
|
| 802 | - 'Cancel Registrations and Notify', |
|
| 803 | - 'event_espresso' |
|
| 804 | - ); |
|
| 805 | - } |
|
| 806 | - $def_reg_status_actions = apply_filters( |
|
| 807 | - 'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array', |
|
| 808 | - $def_reg_status_actions, |
|
| 809 | - $active_mts, |
|
| 810 | - $can_send |
|
| 811 | - ); |
|
| 812 | - |
|
| 813 | - $this->_views = array( |
|
| 814 | - 'all' => array( |
|
| 815 | - 'slug' => 'all', |
|
| 816 | - 'label' => esc_html__('View All Registrations', 'event_espresso'), |
|
| 817 | - 'count' => 0, |
|
| 818 | - 'bulk_action' => array_merge( |
|
| 819 | - $def_reg_status_actions, |
|
| 820 | - array( |
|
| 821 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 822 | - ) |
|
| 823 | - ), |
|
| 824 | - ), |
|
| 825 | - 'month' => array( |
|
| 826 | - 'slug' => 'month', |
|
| 827 | - 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 828 | - 'count' => 0, |
|
| 829 | - 'bulk_action' => array_merge( |
|
| 830 | - $def_reg_status_actions, |
|
| 831 | - array( |
|
| 832 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 833 | - ) |
|
| 834 | - ), |
|
| 835 | - ), |
|
| 836 | - 'today' => array( |
|
| 837 | - 'slug' => 'today', |
|
| 838 | - 'label' => sprintf( |
|
| 839 | - esc_html__('Today - %s', 'event_espresso'), |
|
| 840 | - date('M d, Y', current_time('timestamp')) |
|
| 841 | - ), |
|
| 842 | - 'count' => 0, |
|
| 843 | - 'bulk_action' => array_merge( |
|
| 844 | - $def_reg_status_actions, |
|
| 845 | - array( |
|
| 846 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 847 | - ) |
|
| 848 | - ), |
|
| 849 | - ), |
|
| 850 | - ); |
|
| 851 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 852 | - 'ee_delete_registrations', |
|
| 853 | - 'espresso_registrations_delete_registration' |
|
| 854 | - )) { |
|
| 855 | - $this->_views['incomplete'] = array( |
|
| 856 | - 'slug' => 'incomplete', |
|
| 857 | - 'label' => esc_html__('Incomplete', 'event_espresso'), |
|
| 858 | - 'count' => 0, |
|
| 859 | - 'bulk_action' => array( |
|
| 860 | - 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 861 | - ), |
|
| 862 | - ); |
|
| 863 | - $this->_views['trash'] = array( |
|
| 864 | - 'slug' => 'trash', |
|
| 865 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 866 | - 'count' => 0, |
|
| 867 | - 'bulk_action' => array( |
|
| 868 | - 'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'), |
|
| 869 | - 'delete_registrations' => esc_html__('Delete Registrations Permanently', 'event_espresso'), |
|
| 870 | - ), |
|
| 871 | - ); |
|
| 872 | - } |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - |
|
| 876 | - protected function _set_list_table_views_contact_list() |
|
| 877 | - { |
|
| 878 | - $this->_views = array( |
|
| 879 | - 'in_use' => array( |
|
| 880 | - 'slug' => 'in_use', |
|
| 881 | - 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 882 | - 'count' => 0, |
|
| 883 | - 'bulk_action' => array( |
|
| 884 | - 'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 885 | - ), |
|
| 886 | - ), |
|
| 887 | - ); |
|
| 888 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 889 | - 'ee_delete_contacts', |
|
| 890 | - 'espresso_registrations_trash_attendees' |
|
| 891 | - ) |
|
| 892 | - ) { |
|
| 893 | - $this->_views['trash'] = array( |
|
| 894 | - 'slug' => 'trash', |
|
| 895 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 896 | - 'count' => 0, |
|
| 897 | - 'bulk_action' => array( |
|
| 898 | - 'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 899 | - ), |
|
| 900 | - ); |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - |
|
| 905 | - protected function _registration_legend_items() |
|
| 906 | - { |
|
| 907 | - $fc_items = array( |
|
| 908 | - 'star-icon' => array( |
|
| 909 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 910 | - 'desc' => esc_html__('This is the Primary Registrant', 'event_espresso'), |
|
| 911 | - ), |
|
| 912 | - 'view_details' => array( |
|
| 913 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 914 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 915 | - ), |
|
| 916 | - 'edit_attendee' => array( |
|
| 917 | - 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
|
| 918 | - 'desc' => esc_html__('Edit Contact Details', 'event_espresso'), |
|
| 919 | - ), |
|
| 920 | - 'view_transaction' => array( |
|
| 921 | - 'class' => 'dashicons dashicons-cart', |
|
| 922 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 923 | - ), |
|
| 924 | - 'view_invoice' => array( |
|
| 925 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 926 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 927 | - ), |
|
| 928 | - ); |
|
| 929 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 930 | - 'ee_send_message', |
|
| 931 | - 'espresso_registrations_resend_registration' |
|
| 932 | - )) { |
|
| 933 | - $fc_items['resend_registration'] = array( |
|
| 934 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 935 | - 'desc' => esc_html__('Resend Registration Details', 'event_espresso'), |
|
| 936 | - ); |
|
| 937 | - } else { |
|
| 938 | - $fc_items['blank'] = array('class' => 'blank', 'desc' => ''); |
|
| 939 | - } |
|
| 940 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 941 | - 'ee_read_global_messages', |
|
| 942 | - 'view_filtered_messages' |
|
| 943 | - )) { |
|
| 944 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 945 | - if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 946 | - $fc_items['view_related_messages'] = array( |
|
| 947 | - 'class' => $related_for_icon['css_class'], |
|
| 948 | - 'desc' => $related_for_icon['label'], |
|
| 949 | - ); |
|
| 950 | - } |
|
| 951 | - } |
|
| 952 | - $sc_items = array( |
|
| 953 | - 'approved_status' => array( |
|
| 954 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 955 | - 'desc' => EEH_Template::pretty_status( |
|
| 956 | - EEM_Registration::status_id_approved, |
|
| 957 | - false, |
|
| 958 | - 'sentence' |
|
| 959 | - ), |
|
| 960 | - ), |
|
| 961 | - 'pending_status' => array( |
|
| 962 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 963 | - 'desc' => EEH_Template::pretty_status( |
|
| 964 | - EEM_Registration::status_id_pending_payment, |
|
| 965 | - false, |
|
| 966 | - 'sentence' |
|
| 967 | - ), |
|
| 968 | - ), |
|
| 969 | - 'wait_list' => array( |
|
| 970 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 971 | - 'desc' => EEH_Template::pretty_status( |
|
| 972 | - EEM_Registration::status_id_wait_list, |
|
| 973 | - false, |
|
| 974 | - 'sentence' |
|
| 975 | - ), |
|
| 976 | - ), |
|
| 977 | - 'incomplete_status' => array( |
|
| 978 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
| 979 | - 'desc' => EEH_Template::pretty_status( |
|
| 980 | - EEM_Registration::status_id_incomplete, |
|
| 981 | - false, |
|
| 982 | - 'sentence' |
|
| 983 | - ), |
|
| 984 | - ), |
|
| 985 | - 'not_approved' => array( |
|
| 986 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 987 | - 'desc' => EEH_Template::pretty_status( |
|
| 988 | - EEM_Registration::status_id_not_approved, |
|
| 989 | - false, |
|
| 990 | - 'sentence' |
|
| 991 | - ), |
|
| 992 | - ), |
|
| 993 | - 'declined_status' => array( |
|
| 994 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 995 | - 'desc' => EEH_Template::pretty_status( |
|
| 996 | - EEM_Registration::status_id_declined, |
|
| 997 | - false, |
|
| 998 | - 'sentence' |
|
| 999 | - ), |
|
| 1000 | - ), |
|
| 1001 | - 'cancelled_status' => array( |
|
| 1002 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1003 | - 'desc' => EEH_Template::pretty_status( |
|
| 1004 | - EEM_Registration::status_id_cancelled, |
|
| 1005 | - false, |
|
| 1006 | - 'sentence' |
|
| 1007 | - ), |
|
| 1008 | - ), |
|
| 1009 | - ); |
|
| 1010 | - return array_merge($fc_items, $sc_items); |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - |
|
| 1014 | - |
|
| 1015 | - /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
| 1016 | - /** |
|
| 1017 | - * @throws \EE_Error |
|
| 1018 | - */ |
|
| 1019 | - protected function _registrations_overview_list_table() |
|
| 1020 | - { |
|
| 1021 | - $this->_template_args['admin_page_header'] = ''; |
|
| 1022 | - $EVT_ID = ! empty($this->_req_data['event_id']) |
|
| 1023 | - ? absint($this->_req_data['event_id']) |
|
| 1024 | - : 0; |
|
| 1025 | - $ATT_ID = ! empty($this->_req_data['ATT_ID']) |
|
| 1026 | - ? absint($this->_req_data['ATT_ID']) |
|
| 1027 | - : 0; |
|
| 1028 | - if ($ATT_ID) { |
|
| 1029 | - $attendee = EEM_Attendee::instance()->get_one_by_ID($ATT_ID); |
|
| 1030 | - if ($attendee instanceof EE_Attendee) { |
|
| 1031 | - $this->_template_args['admin_page_header'] = sprintf( |
|
| 1032 | - esc_html__( |
|
| 1033 | - '%1$s Viewing registrations for %2$s%3$s', |
|
| 1034 | - 'event_espresso' |
|
| 1035 | - ), |
|
| 1036 | - '<h3 style="line-height:1.5em;">', |
|
| 1037 | - '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 1038 | - array( |
|
| 1039 | - 'action' => 'edit_attendee', |
|
| 1040 | - 'post' => $ATT_ID, |
|
| 1041 | - ), |
|
| 1042 | - REG_ADMIN_URL |
|
| 1043 | - ) . '">' . $attendee->full_name() . '</a>', |
|
| 1044 | - '</h3>' |
|
| 1045 | - ); |
|
| 1046 | - } |
|
| 1047 | - } |
|
| 1048 | - if ($EVT_ID) { |
|
| 1049 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 1050 | - 'ee_edit_registrations', |
|
| 1051 | - 'espresso_registrations_new_registration', |
|
| 1052 | - $EVT_ID |
|
| 1053 | - )) { |
|
| 1054 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 1055 | - 'new_registration', |
|
| 1056 | - 'add-registrant', |
|
| 1057 | - array('event_id' => $EVT_ID), |
|
| 1058 | - 'add-new-h2' |
|
| 1059 | - ); |
|
| 1060 | - } |
|
| 1061 | - $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 1062 | - if ($event instanceof EE_Event) { |
|
| 1063 | - $this->_template_args['admin_page_header'] = sprintf( |
|
| 1064 | - esc_html__( |
|
| 1065 | - '%s Viewing registrations for the event: %s%s', |
|
| 1066 | - 'event_espresso' |
|
| 1067 | - ), |
|
| 1068 | - '<h3 style="line-height:1.5em;">', |
|
| 1069 | - '<br /><a href="' |
|
| 1070 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
| 1071 | - array( |
|
| 1072 | - 'action' => 'edit', |
|
| 1073 | - 'post' => $event->ID(), |
|
| 1074 | - ), |
|
| 1075 | - EVENTS_ADMIN_URL |
|
| 1076 | - ) |
|
| 1077 | - . '"> ' |
|
| 1078 | - . $event->get('EVT_name') |
|
| 1079 | - . ' </a> ', |
|
| 1080 | - '</h3>' |
|
| 1081 | - ); |
|
| 1082 | - } |
|
| 1083 | - $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
|
| 1084 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1085 | - if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') { |
|
| 1086 | - $this->_template_args['admin_page_header'] = substr( |
|
| 1087 | - $this->_template_args['admin_page_header'], |
|
| 1088 | - 0, |
|
| 1089 | - -5 |
|
| 1090 | - ); |
|
| 1091 | - $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
|
| 1092 | - $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1093 | - $this->_template_args['admin_page_header'] .= $datetime->name(); |
|
| 1094 | - $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
| 1095 | - $this->_template_args['admin_page_header'] .= '</span></h3>'; |
|
| 1096 | - } |
|
| 1097 | - } |
|
| 1098 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
| 1099 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - |
|
| 1103 | - /** |
|
| 1104 | - * This sets the _registration property for the registration details screen |
|
| 1105 | - * |
|
| 1106 | - * @access private |
|
| 1107 | - * @return bool |
|
| 1108 | - * @throws EE_Error |
|
| 1109 | - * @throws InvalidArgumentException |
|
| 1110 | - * @throws InvalidDataTypeException |
|
| 1111 | - * @throws InvalidInterfaceException |
|
| 1112 | - */ |
|
| 1113 | - private function _set_registration_object() |
|
| 1114 | - { |
|
| 1115 | - // get out if we've already set the object |
|
| 1116 | - if ($this->_registration instanceof EE_Registration) { |
|
| 1117 | - return true; |
|
| 1118 | - } |
|
| 1119 | - $REG = EEM_Registration::instance(); |
|
| 1120 | - $REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 1121 | - if ($this->_registration = $REG->get_one_by_ID($REG_ID)) { |
|
| 1122 | - return true; |
|
| 1123 | - } else { |
|
| 1124 | - $error_msg = sprintf( |
|
| 1125 | - esc_html__( |
|
| 1126 | - 'An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
| 1127 | - 'event_espresso' |
|
| 1128 | - ), |
|
| 1129 | - $REG_ID |
|
| 1130 | - ); |
|
| 1131 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1132 | - $this->_registration = null; |
|
| 1133 | - return false; |
|
| 1134 | - } |
|
| 1135 | - } |
|
| 1136 | - |
|
| 1137 | - |
|
| 1138 | - /** |
|
| 1139 | - * Used to retrieve registrations for the list table. |
|
| 1140 | - * |
|
| 1141 | - * @param int $per_page |
|
| 1142 | - * @param bool $count |
|
| 1143 | - * @param bool $this_month |
|
| 1144 | - * @param bool $today |
|
| 1145 | - * @return EE_Registration[]|int |
|
| 1146 | - * @throws EE_Error |
|
| 1147 | - * @throws InvalidArgumentException |
|
| 1148 | - * @throws InvalidDataTypeException |
|
| 1149 | - * @throws InvalidInterfaceException |
|
| 1150 | - */ |
|
| 1151 | - public function get_registrations( |
|
| 1152 | - $per_page = 10, |
|
| 1153 | - $count = false, |
|
| 1154 | - $this_month = false, |
|
| 1155 | - $today = false |
|
| 1156 | - ) { |
|
| 1157 | - if ($this_month) { |
|
| 1158 | - $this->_req_data['status'] = 'month'; |
|
| 1159 | - } |
|
| 1160 | - if ($today) { |
|
| 1161 | - $this->_req_data['status'] = 'today'; |
|
| 1162 | - } |
|
| 1163 | - $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
|
| 1164 | - /** |
|
| 1165 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1166 | - * |
|
| 1167 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1168 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1169 | - * or if you have the development copy of EE you can view this at the path: |
|
| 1170 | - * /docs/G--Model-System/model-query-params.md |
|
| 1171 | - */ |
|
| 1172 | - $query_params['group_by'] = ''; |
|
| 1173 | - |
|
| 1174 | - return $count |
|
| 1175 | - ? EEM_Registration::instance()->count($query_params) |
|
| 1176 | - /** @type EE_Registration[] */ |
|
| 1177 | - : EEM_Registration::instance()->get_all($query_params); |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - |
|
| 1181 | - /** |
|
| 1182 | - * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
| 1183 | - * Note: this listens to values on the request for some of the query parameters. |
|
| 1184 | - * |
|
| 1185 | - * @param array $request |
|
| 1186 | - * @param int $per_page |
|
| 1187 | - * @param bool $count |
|
| 1188 | - * @return array |
|
| 1189 | - * @throws EE_Error |
|
| 1190 | - */ |
|
| 1191 | - protected function _get_registration_query_parameters( |
|
| 1192 | - $request = array(), |
|
| 1193 | - $per_page = 10, |
|
| 1194 | - $count = false |
|
| 1195 | - ) { |
|
| 1196 | - |
|
| 1197 | - $query_params = array( |
|
| 1198 | - 0 => $this->_get_where_conditions_for_registrations_query( |
|
| 1199 | - $request |
|
| 1200 | - ), |
|
| 1201 | - 'caps' => EEM_Registration::caps_read_admin, |
|
| 1202 | - 'default_where_conditions' => 'this_model_only', |
|
| 1203 | - ); |
|
| 1204 | - if (! $count) { |
|
| 1205 | - $query_params = array_merge( |
|
| 1206 | - $query_params, |
|
| 1207 | - $this->_get_orderby_for_registrations_query(), |
|
| 1208 | - $this->_get_limit($per_page) |
|
| 1209 | - ); |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - return $query_params; |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - |
|
| 1216 | - /** |
|
| 1217 | - * This will add ATT_ID to the provided $where array for EE model query parameters. |
|
| 1218 | - * |
|
| 1219 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1220 | - * @return array |
|
| 1221 | - */ |
|
| 1222 | - protected function addAttendeeIdToWhereConditions(array $request) |
|
| 1223 | - { |
|
| 1224 | - $where = array(); |
|
| 1225 | - if (! empty($request['ATT_ID'])) { |
|
| 1226 | - $where['ATT_ID'] = absint($request['ATT_ID']); |
|
| 1227 | - } |
|
| 1228 | - return $where; |
|
| 1229 | - } |
|
| 1230 | - |
|
| 1231 | - |
|
| 1232 | - /** |
|
| 1233 | - * This will add EVT_ID to the provided $where array for EE model query parameters. |
|
| 1234 | - * |
|
| 1235 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1236 | - * @return array |
|
| 1237 | - */ |
|
| 1238 | - protected function _add_event_id_to_where_conditions(array $request) |
|
| 1239 | - { |
|
| 1240 | - $where = array(); |
|
| 1241 | - if (! empty($request['event_id'])) { |
|
| 1242 | - $where['EVT_ID'] = absint($request['event_id']); |
|
| 1243 | - } |
|
| 1244 | - return $where; |
|
| 1245 | - } |
|
| 1246 | - |
|
| 1247 | - |
|
| 1248 | - /** |
|
| 1249 | - * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
| 1250 | - * |
|
| 1251 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1252 | - * @return array |
|
| 1253 | - */ |
|
| 1254 | - protected function _add_category_id_to_where_conditions(array $request) |
|
| 1255 | - { |
|
| 1256 | - $where = array(); |
|
| 1257 | - if (! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) { |
|
| 1258 | - $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
|
| 1259 | - } |
|
| 1260 | - return $where; |
|
| 1261 | - } |
|
| 1262 | - |
|
| 1263 | - |
|
| 1264 | - /** |
|
| 1265 | - * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
| 1266 | - * |
|
| 1267 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1268 | - * @return array |
|
| 1269 | - */ |
|
| 1270 | - protected function _add_datetime_id_to_where_conditions(array $request) |
|
| 1271 | - { |
|
| 1272 | - $where = array(); |
|
| 1273 | - if (! empty($request['datetime_id'])) { |
|
| 1274 | - $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
|
| 1275 | - } |
|
| 1276 | - if (! empty($request['DTT_ID'])) { |
|
| 1277 | - $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
|
| 1278 | - } |
|
| 1279 | - return $where; |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - |
|
| 1283 | - /** |
|
| 1284 | - * Adds the correct registration status to the where conditions for the registrations query. |
|
| 1285 | - * |
|
| 1286 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1287 | - * @return array |
|
| 1288 | - */ |
|
| 1289 | - protected function _add_registration_status_to_where_conditions(array $request) |
|
| 1290 | - { |
|
| 1291 | - $where = array(); |
|
| 1292 | - $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1293 | - $registration_status = ! empty($request['_reg_status']) |
|
| 1294 | - ? sanitize_text_field($request['_reg_status']) |
|
| 1295 | - : ''; |
|
| 1296 | - |
|
| 1297 | - /* |
|
| 22 | + /** |
|
| 23 | + * @var EE_Registration |
|
| 24 | + */ |
|
| 25 | + private $_registration; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var EE_Event |
|
| 29 | + */ |
|
| 30 | + private $_reg_event; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var EE_Session |
|
| 34 | + */ |
|
| 35 | + private $_session; |
|
| 36 | + |
|
| 37 | + private static $_reg_status; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Form for displaying the custom questions for this registration. |
|
| 41 | + * This gets used a few times throughout the request so its best to cache it |
|
| 42 | + * |
|
| 43 | + * @var EE_Registration_Custom_Questions_Form |
|
| 44 | + */ |
|
| 45 | + protected $_reg_custom_questions_form = null; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * constructor |
|
| 50 | + * |
|
| 51 | + * @Constructor |
|
| 52 | + * @access public |
|
| 53 | + * @param bool $routing |
|
| 54 | + * @return Registrations_Admin_Page |
|
| 55 | + */ |
|
| 56 | + public function __construct($routing = true) |
|
| 57 | + { |
|
| 58 | + parent::__construct($routing); |
|
| 59 | + add_action('wp_loaded', array($this, 'wp_loaded')); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + public function wp_loaded() |
|
| 64 | + { |
|
| 65 | + // when adding a new registration... |
|
| 66 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'new_registration') { |
|
| 67 | + EE_System::do_not_cache(); |
|
| 68 | + if (! isset($this->_req_data['processing_registration']) |
|
| 69 | + || absint($this->_req_data['processing_registration']) !== 1 |
|
| 70 | + ) { |
|
| 71 | + // and it's NOT the attendee information reg step |
|
| 72 | + // force cookie expiration by setting time to last week |
|
| 73 | + setcookie('ee_registration_added', 0, time() - WEEK_IN_SECONDS, '/'); |
|
| 74 | + // and update the global |
|
| 75 | + $_COOKIE['ee_registration_added'] = 0; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + protected function _init_page_props() |
|
| 82 | + { |
|
| 83 | + $this->page_slug = REG_PG_SLUG; |
|
| 84 | + $this->_admin_base_url = REG_ADMIN_URL; |
|
| 85 | + $this->_admin_base_path = REG_ADMIN; |
|
| 86 | + $this->page_label = esc_html__('Registrations', 'event_espresso'); |
|
| 87 | + $this->_cpt_routes = array( |
|
| 88 | + 'add_new_attendee' => 'espresso_attendees', |
|
| 89 | + 'edit_attendee' => 'espresso_attendees', |
|
| 90 | + 'insert_attendee' => 'espresso_attendees', |
|
| 91 | + 'update_attendee' => 'espresso_attendees', |
|
| 92 | + ); |
|
| 93 | + $this->_cpt_model_names = array( |
|
| 94 | + 'add_new_attendee' => 'EEM_Attendee', |
|
| 95 | + 'edit_attendee' => 'EEM_Attendee', |
|
| 96 | + ); |
|
| 97 | + $this->_cpt_edit_routes = array( |
|
| 98 | + 'espresso_attendees' => 'edit_attendee', |
|
| 99 | + ); |
|
| 100 | + $this->_pagenow_map = array( |
|
| 101 | + 'add_new_attendee' => 'post-new.php', |
|
| 102 | + 'edit_attendee' => 'post.php', |
|
| 103 | + 'trash' => 'post.php', |
|
| 104 | + ); |
|
| 105 | + add_action('edit_form_after_title', array($this, 'after_title_form_fields'), 10); |
|
| 106 | + // add filters so that the comment urls don't take users to a confusing 404 page |
|
| 107 | + add_filter('get_comment_link', array($this, 'clear_comment_link'), 10, 3); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + public function clear_comment_link($link, $comment, $args) |
|
| 112 | + { |
|
| 113 | + // gotta make sure this only happens on this route |
|
| 114 | + $post_type = get_post_type($comment->comment_post_ID); |
|
| 115 | + if ($post_type === 'espresso_attendees') { |
|
| 116 | + return '#commentsdiv'; |
|
| 117 | + } |
|
| 118 | + return $link; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + protected function _ajax_hooks() |
|
| 123 | + { |
|
| 124 | + // todo: all hooks for registrations ajax goes in here |
|
| 125 | + add_action('wp_ajax_toggle_checkin_status', array($this, 'toggle_checkin_status')); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + |
|
| 129 | + protected function _define_page_props() |
|
| 130 | + { |
|
| 131 | + $this->_admin_page_title = $this->page_label; |
|
| 132 | + $this->_labels = array( |
|
| 133 | + 'buttons' => array( |
|
| 134 | + 'add-registrant' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 135 | + 'add-attendee' => esc_html__('Add Contact', 'event_espresso'), |
|
| 136 | + 'edit' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 137 | + 'report' => esc_html__("Event Registrations CSV Report", "event_espresso"), |
|
| 138 | + 'report_all' => esc_html__('All Registrations CSV Report', 'event_espresso'), |
|
| 139 | + 'report_filtered' => esc_html__('Filtered CSV Report', 'event_espresso'), |
|
| 140 | + 'contact_list_report' => esc_html__('Contact List Report', 'event_espresso'), |
|
| 141 | + 'contact_list_export' => esc_html__("Export Data", "event_espresso"), |
|
| 142 | + ), |
|
| 143 | + 'publishbox' => array( |
|
| 144 | + 'add_new_attendee' => esc_html__("Add Contact Record", 'event_espresso'), |
|
| 145 | + 'edit_attendee' => esc_html__("Update Contact Record", 'event_espresso'), |
|
| 146 | + ), |
|
| 147 | + 'hide_add_button_on_cpt_route' => array( |
|
| 148 | + 'edit_attendee' => true, |
|
| 149 | + ), |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * grab url requests and route them |
|
| 156 | + * |
|
| 157 | + * @access private |
|
| 158 | + * @return void |
|
| 159 | + */ |
|
| 160 | + public function _set_page_routes() |
|
| 161 | + { |
|
| 162 | + $this->_get_registration_status_array(); |
|
| 163 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 164 | + ? $this->_req_data['_REG_ID'] : 0; |
|
| 165 | + $reg_id = empty($reg_id) && ! empty($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 166 | + ? $this->_req_data['reg_status_change_form']['REG_ID'] |
|
| 167 | + : $reg_id; |
|
| 168 | + $att_id = ! empty($this->_req_data['ATT_ID']) && ! is_array($this->_req_data['ATT_ID']) |
|
| 169 | + ? $this->_req_data['ATT_ID'] : 0; |
|
| 170 | + $att_id = ! empty($this->_req_data['post']) && ! is_array($this->_req_data['post']) |
|
| 171 | + ? $this->_req_data['post'] |
|
| 172 | + : $att_id; |
|
| 173 | + $this->_page_routes = array( |
|
| 174 | + 'default' => array( |
|
| 175 | + 'func' => '_registrations_overview_list_table', |
|
| 176 | + 'capability' => 'ee_read_registrations', |
|
| 177 | + ), |
|
| 178 | + 'view_registration' => array( |
|
| 179 | + 'func' => '_registration_details', |
|
| 180 | + 'capability' => 'ee_read_registration', |
|
| 181 | + 'obj_id' => $reg_id, |
|
| 182 | + ), |
|
| 183 | + 'edit_registration' => array( |
|
| 184 | + 'func' => '_update_attendee_registration_form', |
|
| 185 | + 'noheader' => true, |
|
| 186 | + 'headers_sent_route' => 'view_registration', |
|
| 187 | + 'capability' => 'ee_edit_registration', |
|
| 188 | + 'obj_id' => $reg_id, |
|
| 189 | + '_REG_ID' => $reg_id, |
|
| 190 | + ), |
|
| 191 | + 'trash_registrations' => array( |
|
| 192 | + 'func' => '_trash_or_restore_registrations', |
|
| 193 | + 'args' => array('trash' => true), |
|
| 194 | + 'noheader' => true, |
|
| 195 | + 'capability' => 'ee_delete_registrations', |
|
| 196 | + ), |
|
| 197 | + 'restore_registrations' => array( |
|
| 198 | + 'func' => '_trash_or_restore_registrations', |
|
| 199 | + 'args' => array('trash' => false), |
|
| 200 | + 'noheader' => true, |
|
| 201 | + 'capability' => 'ee_delete_registrations', |
|
| 202 | + ), |
|
| 203 | + 'delete_registrations' => array( |
|
| 204 | + 'func' => '_delete_registrations', |
|
| 205 | + 'noheader' => true, |
|
| 206 | + 'capability' => 'ee_delete_registrations', |
|
| 207 | + ), |
|
| 208 | + 'new_registration' => array( |
|
| 209 | + 'func' => 'new_registration', |
|
| 210 | + 'capability' => 'ee_edit_registrations', |
|
| 211 | + ), |
|
| 212 | + 'process_reg_step' => array( |
|
| 213 | + 'func' => 'process_reg_step', |
|
| 214 | + 'noheader' => true, |
|
| 215 | + 'capability' => 'ee_edit_registrations', |
|
| 216 | + ), |
|
| 217 | + 'redirect_to_txn' => array( |
|
| 218 | + 'func' => 'redirect_to_txn', |
|
| 219 | + 'noheader' => true, |
|
| 220 | + 'capability' => 'ee_edit_registrations', |
|
| 221 | + ), |
|
| 222 | + 'change_reg_status' => array( |
|
| 223 | + 'func' => '_change_reg_status', |
|
| 224 | + 'noheader' => true, |
|
| 225 | + 'capability' => 'ee_edit_registration', |
|
| 226 | + 'obj_id' => $reg_id, |
|
| 227 | + ), |
|
| 228 | + 'approve_registration' => array( |
|
| 229 | + 'func' => 'approve_registration', |
|
| 230 | + 'noheader' => true, |
|
| 231 | + 'capability' => 'ee_edit_registration', |
|
| 232 | + 'obj_id' => $reg_id, |
|
| 233 | + ), |
|
| 234 | + 'approve_and_notify_registration' => array( |
|
| 235 | + 'func' => 'approve_registration', |
|
| 236 | + 'noheader' => true, |
|
| 237 | + 'args' => array(true), |
|
| 238 | + 'capability' => 'ee_edit_registration', |
|
| 239 | + 'obj_id' => $reg_id, |
|
| 240 | + ), |
|
| 241 | + 'approve_registrations' => array( |
|
| 242 | + 'func' => 'bulk_action_on_registrations', |
|
| 243 | + 'noheader' => true, |
|
| 244 | + 'capability' => 'ee_edit_registrations', |
|
| 245 | + 'args' => array('approve'), |
|
| 246 | + ), |
|
| 247 | + 'approve_and_notify_registrations' => array( |
|
| 248 | + 'func' => 'bulk_action_on_registrations', |
|
| 249 | + 'noheader' => true, |
|
| 250 | + 'capability' => 'ee_edit_registrations', |
|
| 251 | + 'args' => array('approve', true), |
|
| 252 | + ), |
|
| 253 | + 'decline_registration' => array( |
|
| 254 | + 'func' => 'decline_registration', |
|
| 255 | + 'noheader' => true, |
|
| 256 | + 'capability' => 'ee_edit_registration', |
|
| 257 | + 'obj_id' => $reg_id, |
|
| 258 | + ), |
|
| 259 | + 'decline_and_notify_registration' => array( |
|
| 260 | + 'func' => 'decline_registration', |
|
| 261 | + 'noheader' => true, |
|
| 262 | + 'args' => array(true), |
|
| 263 | + 'capability' => 'ee_edit_registration', |
|
| 264 | + 'obj_id' => $reg_id, |
|
| 265 | + ), |
|
| 266 | + 'decline_registrations' => array( |
|
| 267 | + 'func' => 'bulk_action_on_registrations', |
|
| 268 | + 'noheader' => true, |
|
| 269 | + 'capability' => 'ee_edit_registrations', |
|
| 270 | + 'args' => array('decline'), |
|
| 271 | + ), |
|
| 272 | + 'decline_and_notify_registrations' => array( |
|
| 273 | + 'func' => 'bulk_action_on_registrations', |
|
| 274 | + 'noheader' => true, |
|
| 275 | + 'capability' => 'ee_edit_registrations', |
|
| 276 | + 'args' => array('decline', true), |
|
| 277 | + ), |
|
| 278 | + 'pending_registration' => array( |
|
| 279 | + 'func' => 'pending_registration', |
|
| 280 | + 'noheader' => true, |
|
| 281 | + 'capability' => 'ee_edit_registration', |
|
| 282 | + 'obj_id' => $reg_id, |
|
| 283 | + ), |
|
| 284 | + 'pending_and_notify_registration' => array( |
|
| 285 | + 'func' => 'pending_registration', |
|
| 286 | + 'noheader' => true, |
|
| 287 | + 'args' => array(true), |
|
| 288 | + 'capability' => 'ee_edit_registration', |
|
| 289 | + 'obj_id' => $reg_id, |
|
| 290 | + ), |
|
| 291 | + 'pending_registrations' => array( |
|
| 292 | + 'func' => 'bulk_action_on_registrations', |
|
| 293 | + 'noheader' => true, |
|
| 294 | + 'capability' => 'ee_edit_registrations', |
|
| 295 | + 'args' => array('pending'), |
|
| 296 | + ), |
|
| 297 | + 'pending_and_notify_registrations' => array( |
|
| 298 | + 'func' => 'bulk_action_on_registrations', |
|
| 299 | + 'noheader' => true, |
|
| 300 | + 'capability' => 'ee_edit_registrations', |
|
| 301 | + 'args' => array('pending', true), |
|
| 302 | + ), |
|
| 303 | + 'no_approve_registration' => array( |
|
| 304 | + 'func' => 'not_approve_registration', |
|
| 305 | + 'noheader' => true, |
|
| 306 | + 'capability' => 'ee_edit_registration', |
|
| 307 | + 'obj_id' => $reg_id, |
|
| 308 | + ), |
|
| 309 | + 'no_approve_and_notify_registration' => array( |
|
| 310 | + 'func' => 'not_approve_registration', |
|
| 311 | + 'noheader' => true, |
|
| 312 | + 'args' => array(true), |
|
| 313 | + 'capability' => 'ee_edit_registration', |
|
| 314 | + 'obj_id' => $reg_id, |
|
| 315 | + ), |
|
| 316 | + 'no_approve_registrations' => array( |
|
| 317 | + 'func' => 'bulk_action_on_registrations', |
|
| 318 | + 'noheader' => true, |
|
| 319 | + 'capability' => 'ee_edit_registrations', |
|
| 320 | + 'args' => array('not_approve'), |
|
| 321 | + ), |
|
| 322 | + 'no_approve_and_notify_registrations' => array( |
|
| 323 | + 'func' => 'bulk_action_on_registrations', |
|
| 324 | + 'noheader' => true, |
|
| 325 | + 'capability' => 'ee_edit_registrations', |
|
| 326 | + 'args' => array('not_approve', true), |
|
| 327 | + ), |
|
| 328 | + 'cancel_registration' => array( |
|
| 329 | + 'func' => 'cancel_registration', |
|
| 330 | + 'noheader' => true, |
|
| 331 | + 'capability' => 'ee_edit_registration', |
|
| 332 | + 'obj_id' => $reg_id, |
|
| 333 | + ), |
|
| 334 | + 'cancel_and_notify_registration' => array( |
|
| 335 | + 'func' => 'cancel_registration', |
|
| 336 | + 'noheader' => true, |
|
| 337 | + 'args' => array(true), |
|
| 338 | + 'capability' => 'ee_edit_registration', |
|
| 339 | + 'obj_id' => $reg_id, |
|
| 340 | + ), |
|
| 341 | + 'cancel_registrations' => array( |
|
| 342 | + 'func' => 'bulk_action_on_registrations', |
|
| 343 | + 'noheader' => true, |
|
| 344 | + 'capability' => 'ee_edit_registrations', |
|
| 345 | + 'args' => array('cancel'), |
|
| 346 | + ), |
|
| 347 | + 'cancel_and_notify_registrations' => array( |
|
| 348 | + 'func' => 'bulk_action_on_registrations', |
|
| 349 | + 'noheader' => true, |
|
| 350 | + 'capability' => 'ee_edit_registrations', |
|
| 351 | + 'args' => array('cancel', true), |
|
| 352 | + ), |
|
| 353 | + 'wait_list_registration' => array( |
|
| 354 | + 'func' => 'wait_list_registration', |
|
| 355 | + 'noheader' => true, |
|
| 356 | + 'capability' => 'ee_edit_registration', |
|
| 357 | + 'obj_id' => $reg_id, |
|
| 358 | + ), |
|
| 359 | + 'wait_list_and_notify_registration' => array( |
|
| 360 | + 'func' => 'wait_list_registration', |
|
| 361 | + 'noheader' => true, |
|
| 362 | + 'args' => array(true), |
|
| 363 | + 'capability' => 'ee_edit_registration', |
|
| 364 | + 'obj_id' => $reg_id, |
|
| 365 | + ), |
|
| 366 | + 'contact_list' => array( |
|
| 367 | + 'func' => '_attendee_contact_list_table', |
|
| 368 | + 'capability' => 'ee_read_contacts', |
|
| 369 | + ), |
|
| 370 | + 'add_new_attendee' => array( |
|
| 371 | + 'func' => '_create_new_cpt_item', |
|
| 372 | + 'args' => array( |
|
| 373 | + 'new_attendee' => true, |
|
| 374 | + 'capability' => 'ee_edit_contacts', |
|
| 375 | + ), |
|
| 376 | + ), |
|
| 377 | + 'edit_attendee' => array( |
|
| 378 | + 'func' => '_edit_cpt_item', |
|
| 379 | + 'capability' => 'ee_edit_contacts', |
|
| 380 | + 'obj_id' => $att_id, |
|
| 381 | + ), |
|
| 382 | + 'duplicate_attendee' => array( |
|
| 383 | + 'func' => '_duplicate_attendee', |
|
| 384 | + 'noheader' => true, |
|
| 385 | + 'capability' => 'ee_edit_contacts', |
|
| 386 | + 'obj_id' => $att_id, |
|
| 387 | + ), |
|
| 388 | + 'insert_attendee' => array( |
|
| 389 | + 'func' => '_insert_or_update_attendee', |
|
| 390 | + 'args' => array( |
|
| 391 | + 'new_attendee' => true, |
|
| 392 | + ), |
|
| 393 | + 'noheader' => true, |
|
| 394 | + 'capability' => 'ee_edit_contacts', |
|
| 395 | + ), |
|
| 396 | + 'update_attendee' => array( |
|
| 397 | + 'func' => '_insert_or_update_attendee', |
|
| 398 | + 'args' => array( |
|
| 399 | + 'new_attendee' => false, |
|
| 400 | + ), |
|
| 401 | + 'noheader' => true, |
|
| 402 | + 'capability' => 'ee_edit_contacts', |
|
| 403 | + 'obj_id' => $att_id, |
|
| 404 | + ), |
|
| 405 | + 'trash_attendees' => array( |
|
| 406 | + 'func' => '_trash_or_restore_attendees', |
|
| 407 | + 'args' => array( |
|
| 408 | + 'trash' => 'true', |
|
| 409 | + ), |
|
| 410 | + 'noheader' => true, |
|
| 411 | + 'capability' => 'ee_delete_contacts', |
|
| 412 | + ), |
|
| 413 | + 'trash_attendee' => array( |
|
| 414 | + 'func' => '_trash_or_restore_attendees', |
|
| 415 | + 'args' => array( |
|
| 416 | + 'trash' => true, |
|
| 417 | + ), |
|
| 418 | + 'noheader' => true, |
|
| 419 | + 'capability' => 'ee_delete_contacts', |
|
| 420 | + 'obj_id' => $att_id, |
|
| 421 | + ), |
|
| 422 | + 'restore_attendees' => array( |
|
| 423 | + 'func' => '_trash_or_restore_attendees', |
|
| 424 | + 'args' => array( |
|
| 425 | + 'trash' => false, |
|
| 426 | + ), |
|
| 427 | + 'noheader' => true, |
|
| 428 | + 'capability' => 'ee_delete_contacts', |
|
| 429 | + 'obj_id' => $att_id, |
|
| 430 | + ), |
|
| 431 | + 'resend_registration' => array( |
|
| 432 | + 'func' => '_resend_registration', |
|
| 433 | + 'noheader' => true, |
|
| 434 | + 'capability' => 'ee_send_message', |
|
| 435 | + ), |
|
| 436 | + 'registrations_report' => array( |
|
| 437 | + 'func' => '_registrations_report', |
|
| 438 | + 'noheader' => true, |
|
| 439 | + 'capability' => 'ee_read_registrations', |
|
| 440 | + ), |
|
| 441 | + 'contact_list_export' => array( |
|
| 442 | + 'func' => '_contact_list_export', |
|
| 443 | + 'noheader' => true, |
|
| 444 | + 'capability' => 'export', |
|
| 445 | + ), |
|
| 446 | + 'contact_list_report' => array( |
|
| 447 | + 'func' => '_contact_list_report', |
|
| 448 | + 'noheader' => true, |
|
| 449 | + 'capability' => 'ee_read_contacts', |
|
| 450 | + ), |
|
| 451 | + ); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + protected function _set_page_config() |
|
| 456 | + { |
|
| 457 | + $this->_page_config = array( |
|
| 458 | + 'default' => array( |
|
| 459 | + 'nav' => array( |
|
| 460 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 461 | + 'order' => 5, |
|
| 462 | + ), |
|
| 463 | + 'help_tabs' => array( |
|
| 464 | + 'registrations_overview_help_tab' => array( |
|
| 465 | + 'title' => esc_html__('Registrations Overview', 'event_espresso'), |
|
| 466 | + 'filename' => 'registrations_overview', |
|
| 467 | + ), |
|
| 468 | + 'registrations_overview_table_column_headings_help_tab' => array( |
|
| 469 | + 'title' => esc_html__('Registrations Table Column Headings', 'event_espresso'), |
|
| 470 | + 'filename' => 'registrations_overview_table_column_headings', |
|
| 471 | + ), |
|
| 472 | + 'registrations_overview_filters_help_tab' => array( |
|
| 473 | + 'title' => esc_html__('Registration Filters', 'event_espresso'), |
|
| 474 | + 'filename' => 'registrations_overview_filters', |
|
| 475 | + ), |
|
| 476 | + 'registrations_overview_views_help_tab' => array( |
|
| 477 | + 'title' => esc_html__('Registration Views', 'event_espresso'), |
|
| 478 | + 'filename' => 'registrations_overview_views', |
|
| 479 | + ), |
|
| 480 | + 'registrations_regoverview_other_help_tab' => array( |
|
| 481 | + 'title' => esc_html__('Registrations Other', 'event_espresso'), |
|
| 482 | + 'filename' => 'registrations_overview_other', |
|
| 483 | + ), |
|
| 484 | + ), |
|
| 485 | + 'help_tour' => array('Registration_Overview_Help_Tour'), |
|
| 486 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
| 487 | + 'list_table' => 'EE_Registrations_List_Table', |
|
| 488 | + 'require_nonce' => false, |
|
| 489 | + ), |
|
| 490 | + 'view_registration' => array( |
|
| 491 | + 'nav' => array( |
|
| 492 | + 'label' => esc_html__('REG Details', 'event_espresso'), |
|
| 493 | + 'order' => 15, |
|
| 494 | + 'url' => isset($this->_req_data['_REG_ID']) |
|
| 495 | + ? add_query_arg(array('_REG_ID' => $this->_req_data['_REG_ID']), $this->_current_page_view_url) |
|
| 496 | + : $this->_admin_base_url, |
|
| 497 | + 'persistent' => false, |
|
| 498 | + ), |
|
| 499 | + 'help_tabs' => array( |
|
| 500 | + 'registrations_details_help_tab' => array( |
|
| 501 | + 'title' => esc_html__('Registration Details', 'event_espresso'), |
|
| 502 | + 'filename' => 'registrations_details', |
|
| 503 | + ), |
|
| 504 | + 'registrations_details_table_help_tab' => array( |
|
| 505 | + 'title' => esc_html__('Registration Details Table', 'event_espresso'), |
|
| 506 | + 'filename' => 'registrations_details_table', |
|
| 507 | + ), |
|
| 508 | + 'registrations_details_form_answers_help_tab' => array( |
|
| 509 | + 'title' => esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 510 | + 'filename' => 'registrations_details_form_answers', |
|
| 511 | + ), |
|
| 512 | + 'registrations_details_registrant_details_help_tab' => array( |
|
| 513 | + 'title' => esc_html__('Contact Details', 'event_espresso'), |
|
| 514 | + 'filename' => 'registrations_details_registrant_details', |
|
| 515 | + ), |
|
| 516 | + ), |
|
| 517 | + 'help_tour' => array('Registration_Details_Help_Tour'), |
|
| 518 | + 'metaboxes' => array_merge( |
|
| 519 | + $this->_default_espresso_metaboxes, |
|
| 520 | + array('_registration_details_metaboxes') |
|
| 521 | + ), |
|
| 522 | + 'require_nonce' => false, |
|
| 523 | + ), |
|
| 524 | + 'new_registration' => array( |
|
| 525 | + 'nav' => array( |
|
| 526 | + 'label' => esc_html__('Add New Registration', 'event_espresso'), |
|
| 527 | + 'url' => '#', |
|
| 528 | + 'order' => 15, |
|
| 529 | + 'persistent' => false, |
|
| 530 | + ), |
|
| 531 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
| 532 | + 'labels' => array( |
|
| 533 | + 'publishbox' => esc_html__('Save Registration', 'event_espresso'), |
|
| 534 | + ), |
|
| 535 | + 'require_nonce' => false, |
|
| 536 | + ), |
|
| 537 | + 'add_new_attendee' => array( |
|
| 538 | + 'nav' => array( |
|
| 539 | + 'label' => esc_html__('Add Contact', 'event_espresso'), |
|
| 540 | + 'order' => 15, |
|
| 541 | + 'persistent' => false, |
|
| 542 | + ), |
|
| 543 | + 'metaboxes' => array_merge( |
|
| 544 | + $this->_default_espresso_metaboxes, |
|
| 545 | + array('_publish_post_box', 'attendee_editor_metaboxes') |
|
| 546 | + ), |
|
| 547 | + 'require_nonce' => false, |
|
| 548 | + ), |
|
| 549 | + 'edit_attendee' => array( |
|
| 550 | + 'nav' => array( |
|
| 551 | + 'label' => esc_html__('Edit Contact', 'event_espresso'), |
|
| 552 | + 'order' => 15, |
|
| 553 | + 'persistent' => false, |
|
| 554 | + 'url' => isset($this->_req_data['ATT_ID']) |
|
| 555 | + ? add_query_arg(array('ATT_ID' => $this->_req_data['ATT_ID']), $this->_current_page_view_url) |
|
| 556 | + : $this->_admin_base_url, |
|
| 557 | + ), |
|
| 558 | + 'metaboxes' => array('attendee_editor_metaboxes'), |
|
| 559 | + 'require_nonce' => false, |
|
| 560 | + ), |
|
| 561 | + 'contact_list' => array( |
|
| 562 | + 'nav' => array( |
|
| 563 | + 'label' => esc_html__('Contact List', 'event_espresso'), |
|
| 564 | + 'order' => 20, |
|
| 565 | + ), |
|
| 566 | + 'list_table' => 'EE_Attendee_Contact_List_Table', |
|
| 567 | + 'help_tabs' => array( |
|
| 568 | + 'registrations_contact_list_help_tab' => array( |
|
| 569 | + 'title' => esc_html__('Registrations Contact List', 'event_espresso'), |
|
| 570 | + 'filename' => 'registrations_contact_list', |
|
| 571 | + ), |
|
| 572 | + 'registrations_contact-list_table_column_headings_help_tab' => array( |
|
| 573 | + 'title' => esc_html__('Contact List Table Column Headings', 'event_espresso'), |
|
| 574 | + 'filename' => 'registrations_contact_list_table_column_headings', |
|
| 575 | + ), |
|
| 576 | + 'registrations_contact_list_views_help_tab' => array( |
|
| 577 | + 'title' => esc_html__('Contact List Views', 'event_espresso'), |
|
| 578 | + 'filename' => 'registrations_contact_list_views', |
|
| 579 | + ), |
|
| 580 | + 'registrations_contact_list_other_help_tab' => array( |
|
| 581 | + 'title' => esc_html__('Contact List Other', 'event_espresso'), |
|
| 582 | + 'filename' => 'registrations_contact_list_other', |
|
| 583 | + ), |
|
| 584 | + ), |
|
| 585 | + 'help_tour' => array('Contact_List_Help_Tour'), |
|
| 586 | + 'metaboxes' => array(), |
|
| 587 | + 'require_nonce' => false, |
|
| 588 | + ), |
|
| 589 | + // override default cpt routes |
|
| 590 | + 'create_new' => '', |
|
| 591 | + 'edit' => '', |
|
| 592 | + ); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * The below methods aren't used by this class currently |
|
| 598 | + */ |
|
| 599 | + protected function _add_screen_options() |
|
| 600 | + { |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + |
|
| 604 | + protected function _add_feature_pointers() |
|
| 605 | + { |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + |
|
| 609 | + public function admin_init() |
|
| 610 | + { |
|
| 611 | + EE_Registry::$i18n_js_strings['update_att_qstns'] = esc_html__( |
|
| 612 | + 'click "Update Registration Questions" to save your changes', |
|
| 613 | + 'event_espresso' |
|
| 614 | + ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + public function admin_notices() |
|
| 619 | + { |
|
| 620 | + } |
|
| 621 | + |
|
| 622 | + |
|
| 623 | + public function admin_footer_scripts() |
|
| 624 | + { |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * get list of registration statuses |
|
| 630 | + * |
|
| 631 | + * @access private |
|
| 632 | + * @return void |
|
| 633 | + * @throws EE_Error |
|
| 634 | + */ |
|
| 635 | + private function _get_registration_status_array() |
|
| 636 | + { |
|
| 637 | + self::$_reg_status = EEM_Registration::reg_status_array(array(), true); |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + |
|
| 641 | + protected function _add_screen_options_default() |
|
| 642 | + { |
|
| 643 | + $this->_per_page_screen_option(); |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + protected function _add_screen_options_contact_list() |
|
| 648 | + { |
|
| 649 | + $page_title = $this->_admin_page_title; |
|
| 650 | + $this->_admin_page_title = esc_html__("Contacts", 'event_espresso'); |
|
| 651 | + $this->_per_page_screen_option(); |
|
| 652 | + $this->_admin_page_title = $page_title; |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + |
|
| 656 | + public function load_scripts_styles() |
|
| 657 | + { |
|
| 658 | + // style |
|
| 659 | + wp_register_style( |
|
| 660 | + 'espresso_reg', |
|
| 661 | + REG_ASSETS_URL . 'espresso_registrations_admin.css', |
|
| 662 | + array('ee-admin-css'), |
|
| 663 | + EVENT_ESPRESSO_VERSION |
|
| 664 | + ); |
|
| 665 | + wp_enqueue_style('espresso_reg'); |
|
| 666 | + // script |
|
| 667 | + wp_register_script( |
|
| 668 | + 'espresso_reg', |
|
| 669 | + REG_ASSETS_URL . 'espresso_registrations_admin.js', |
|
| 670 | + array('jquery-ui-datepicker', 'jquery-ui-draggable', 'ee_admin_js'), |
|
| 671 | + EVENT_ESPRESSO_VERSION, |
|
| 672 | + true |
|
| 673 | + ); |
|
| 674 | + wp_enqueue_script('espresso_reg'); |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + public function load_scripts_styles_edit_attendee() |
|
| 679 | + { |
|
| 680 | + // stuff to only show up on our attendee edit details page. |
|
| 681 | + $attendee_details_translations = array( |
|
| 682 | + 'att_publish_text' => sprintf( |
|
| 683 | + /* translators: The date and time */ |
|
| 684 | + wp_strip_all_tags(__('Created on: %s', 'event_espresso')), |
|
| 685 | + '<b>' . $this->_cpt_model_obj->get_datetime('ATT_created') . '</b>' |
|
| 686 | + ), |
|
| 687 | + ); |
|
| 688 | + wp_localize_script('espresso_reg', 'ATTENDEE_DETAILS', $attendee_details_translations); |
|
| 689 | + wp_enqueue_script('jquery-validate'); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + |
|
| 693 | + public function load_scripts_styles_view_registration() |
|
| 694 | + { |
|
| 695 | + // styles |
|
| 696 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 697 | + // scripts |
|
| 698 | + $this->_get_reg_custom_questions_form($this->_registration->ID()); |
|
| 699 | + $this->_reg_custom_questions_form->wp_enqueue_scripts(true); |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + |
|
| 703 | + public function load_scripts_styles_contact_list() |
|
| 704 | + { |
|
| 705 | + wp_dequeue_style('espresso_reg'); |
|
| 706 | + wp_register_style( |
|
| 707 | + 'espresso_att', |
|
| 708 | + REG_ASSETS_URL . 'espresso_attendees_admin.css', |
|
| 709 | + array('ee-admin-css'), |
|
| 710 | + EVENT_ESPRESSO_VERSION |
|
| 711 | + ); |
|
| 712 | + wp_enqueue_style('espresso_att'); |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + |
|
| 716 | + public function load_scripts_styles_new_registration() |
|
| 717 | + { |
|
| 718 | + wp_register_script( |
|
| 719 | + 'ee-spco-for-admin', |
|
| 720 | + REG_ASSETS_URL . 'spco_for_admin.js', |
|
| 721 | + array('underscore', 'jquery'), |
|
| 722 | + EVENT_ESPRESSO_VERSION, |
|
| 723 | + true |
|
| 724 | + ); |
|
| 725 | + wp_enqueue_script('ee-spco-for-admin'); |
|
| 726 | + add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true'); |
|
| 727 | + EE_Form_Section_Proper::wp_enqueue_scripts(); |
|
| 728 | + EED_Ticket_Selector::load_tckt_slctr_assets(); |
|
| 729 | + EE_Datepicker_Input::enqueue_styles_and_scripts(); |
|
| 730 | + } |
|
| 731 | + |
|
| 732 | + |
|
| 733 | + public function AHEE__EE_Admin_Page__route_admin_request_resend_registration() |
|
| 734 | + { |
|
| 735 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + |
|
| 739 | + public function AHEE__EE_Admin_Page__route_admin_request_approve_registration() |
|
| 740 | + { |
|
| 741 | + add_filter('FHEE_load_EE_messages', '__return_true'); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + |
|
| 745 | + protected function _set_list_table_views_default() |
|
| 746 | + { |
|
| 747 | + // for notification related bulk actions we need to make sure only active messengers have an option. |
|
| 748 | + EED_Messages::set_autoloaders(); |
|
| 749 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
| 750 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
| 751 | + $active_mts = $message_resource_manager->list_of_active_message_types(); |
|
| 752 | + // key= bulk_action_slug, value= message type. |
|
| 753 | + $match_array = array( |
|
| 754 | + 'approve_registrations' => 'registration', |
|
| 755 | + 'decline_registrations' => 'declined_registration', |
|
| 756 | + 'pending_registrations' => 'pending_approval', |
|
| 757 | + 'no_approve_registrations' => 'not_approved_registration', |
|
| 758 | + 'cancel_registrations' => 'cancelled_registration', |
|
| 759 | + ); |
|
| 760 | + $can_send = EE_Registry::instance()->CAP->current_user_can( |
|
| 761 | + 'ee_send_message', |
|
| 762 | + 'batch_send_messages' |
|
| 763 | + ); |
|
| 764 | + /** setup reg status bulk actions **/ |
|
| 765 | + $def_reg_status_actions['approve_registrations'] = esc_html__('Approve Registrations', 'event_espresso'); |
|
| 766 | + if ($can_send && in_array($match_array['approve_registrations'], $active_mts, true)) { |
|
| 767 | + $def_reg_status_actions['approve_and_notify_registrations'] = esc_html__( |
|
| 768 | + 'Approve and Notify Registrations', |
|
| 769 | + 'event_espresso' |
|
| 770 | + ); |
|
| 771 | + } |
|
| 772 | + $def_reg_status_actions['decline_registrations'] = esc_html__('Decline Registrations', 'event_espresso'); |
|
| 773 | + if ($can_send && in_array($match_array['decline_registrations'], $active_mts, true)) { |
|
| 774 | + $def_reg_status_actions['decline_and_notify_registrations'] = esc_html__( |
|
| 775 | + 'Decline and Notify Registrations', |
|
| 776 | + 'event_espresso' |
|
| 777 | + ); |
|
| 778 | + } |
|
| 779 | + $def_reg_status_actions['pending_registrations'] = esc_html__( |
|
| 780 | + 'Set Registrations to Pending Payment', |
|
| 781 | + 'event_espresso' |
|
| 782 | + ); |
|
| 783 | + if ($can_send && in_array($match_array['pending_registrations'], $active_mts, true)) { |
|
| 784 | + $def_reg_status_actions['pending_and_notify_registrations'] = esc_html__( |
|
| 785 | + 'Set Registrations to Pending Payment and Notify', |
|
| 786 | + 'event_espresso' |
|
| 787 | + ); |
|
| 788 | + } |
|
| 789 | + $def_reg_status_actions['no_approve_registrations'] = esc_html__( |
|
| 790 | + 'Set Registrations to Not Approved', |
|
| 791 | + 'event_espresso' |
|
| 792 | + ); |
|
| 793 | + if ($can_send && in_array($match_array['no_approve_registrations'], $active_mts, true)) { |
|
| 794 | + $def_reg_status_actions['no_approve_and_notify_registrations'] = esc_html__( |
|
| 795 | + 'Set Registrations to Not Approved and Notify', |
|
| 796 | + 'event_espresso' |
|
| 797 | + ); |
|
| 798 | + } |
|
| 799 | + $def_reg_status_actions['cancel_registrations'] = esc_html__('Cancel Registrations', 'event_espresso'); |
|
| 800 | + if ($can_send && in_array($match_array['cancel_registrations'], $active_mts, true)) { |
|
| 801 | + $def_reg_status_actions['cancel_and_notify_registrations'] = esc_html__( |
|
| 802 | + 'Cancel Registrations and Notify', |
|
| 803 | + 'event_espresso' |
|
| 804 | + ); |
|
| 805 | + } |
|
| 806 | + $def_reg_status_actions = apply_filters( |
|
| 807 | + 'FHEE__Registrations_Admin_Page___set_list_table_views_default__def_reg_status_actions_array', |
|
| 808 | + $def_reg_status_actions, |
|
| 809 | + $active_mts, |
|
| 810 | + $can_send |
|
| 811 | + ); |
|
| 812 | + |
|
| 813 | + $this->_views = array( |
|
| 814 | + 'all' => array( |
|
| 815 | + 'slug' => 'all', |
|
| 816 | + 'label' => esc_html__('View All Registrations', 'event_espresso'), |
|
| 817 | + 'count' => 0, |
|
| 818 | + 'bulk_action' => array_merge( |
|
| 819 | + $def_reg_status_actions, |
|
| 820 | + array( |
|
| 821 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 822 | + ) |
|
| 823 | + ), |
|
| 824 | + ), |
|
| 825 | + 'month' => array( |
|
| 826 | + 'slug' => 'month', |
|
| 827 | + 'label' => esc_html__('This Month', 'event_espresso'), |
|
| 828 | + 'count' => 0, |
|
| 829 | + 'bulk_action' => array_merge( |
|
| 830 | + $def_reg_status_actions, |
|
| 831 | + array( |
|
| 832 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 833 | + ) |
|
| 834 | + ), |
|
| 835 | + ), |
|
| 836 | + 'today' => array( |
|
| 837 | + 'slug' => 'today', |
|
| 838 | + 'label' => sprintf( |
|
| 839 | + esc_html__('Today - %s', 'event_espresso'), |
|
| 840 | + date('M d, Y', current_time('timestamp')) |
|
| 841 | + ), |
|
| 842 | + 'count' => 0, |
|
| 843 | + 'bulk_action' => array_merge( |
|
| 844 | + $def_reg_status_actions, |
|
| 845 | + array( |
|
| 846 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 847 | + ) |
|
| 848 | + ), |
|
| 849 | + ), |
|
| 850 | + ); |
|
| 851 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 852 | + 'ee_delete_registrations', |
|
| 853 | + 'espresso_registrations_delete_registration' |
|
| 854 | + )) { |
|
| 855 | + $this->_views['incomplete'] = array( |
|
| 856 | + 'slug' => 'incomplete', |
|
| 857 | + 'label' => esc_html__('Incomplete', 'event_espresso'), |
|
| 858 | + 'count' => 0, |
|
| 859 | + 'bulk_action' => array( |
|
| 860 | + 'trash_registrations' => esc_html__('Trash Registrations', 'event_espresso'), |
|
| 861 | + ), |
|
| 862 | + ); |
|
| 863 | + $this->_views['trash'] = array( |
|
| 864 | + 'slug' => 'trash', |
|
| 865 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 866 | + 'count' => 0, |
|
| 867 | + 'bulk_action' => array( |
|
| 868 | + 'restore_registrations' => esc_html__('Restore Registrations', 'event_espresso'), |
|
| 869 | + 'delete_registrations' => esc_html__('Delete Registrations Permanently', 'event_espresso'), |
|
| 870 | + ), |
|
| 871 | + ); |
|
| 872 | + } |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + |
|
| 876 | + protected function _set_list_table_views_contact_list() |
|
| 877 | + { |
|
| 878 | + $this->_views = array( |
|
| 879 | + 'in_use' => array( |
|
| 880 | + 'slug' => 'in_use', |
|
| 881 | + 'label' => esc_html__('In Use', 'event_espresso'), |
|
| 882 | + 'count' => 0, |
|
| 883 | + 'bulk_action' => array( |
|
| 884 | + 'trash_attendees' => esc_html__('Move to Trash', 'event_espresso'), |
|
| 885 | + ), |
|
| 886 | + ), |
|
| 887 | + ); |
|
| 888 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 889 | + 'ee_delete_contacts', |
|
| 890 | + 'espresso_registrations_trash_attendees' |
|
| 891 | + ) |
|
| 892 | + ) { |
|
| 893 | + $this->_views['trash'] = array( |
|
| 894 | + 'slug' => 'trash', |
|
| 895 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
| 896 | + 'count' => 0, |
|
| 897 | + 'bulk_action' => array( |
|
| 898 | + 'restore_attendees' => esc_html__('Restore from Trash', 'event_espresso'), |
|
| 899 | + ), |
|
| 900 | + ); |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + |
|
| 905 | + protected function _registration_legend_items() |
|
| 906 | + { |
|
| 907 | + $fc_items = array( |
|
| 908 | + 'star-icon' => array( |
|
| 909 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 910 | + 'desc' => esc_html__('This is the Primary Registrant', 'event_espresso'), |
|
| 911 | + ), |
|
| 912 | + 'view_details' => array( |
|
| 913 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 914 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 915 | + ), |
|
| 916 | + 'edit_attendee' => array( |
|
| 917 | + 'class' => 'ee-icon ee-icon-user-edit ee-icon-size-16', |
|
| 918 | + 'desc' => esc_html__('Edit Contact Details', 'event_espresso'), |
|
| 919 | + ), |
|
| 920 | + 'view_transaction' => array( |
|
| 921 | + 'class' => 'dashicons dashicons-cart', |
|
| 922 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 923 | + ), |
|
| 924 | + 'view_invoice' => array( |
|
| 925 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 926 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 927 | + ), |
|
| 928 | + ); |
|
| 929 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 930 | + 'ee_send_message', |
|
| 931 | + 'espresso_registrations_resend_registration' |
|
| 932 | + )) { |
|
| 933 | + $fc_items['resend_registration'] = array( |
|
| 934 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 935 | + 'desc' => esc_html__('Resend Registration Details', 'event_espresso'), |
|
| 936 | + ); |
|
| 937 | + } else { |
|
| 938 | + $fc_items['blank'] = array('class' => 'blank', 'desc' => ''); |
|
| 939 | + } |
|
| 940 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 941 | + 'ee_read_global_messages', |
|
| 942 | + 'view_filtered_messages' |
|
| 943 | + )) { |
|
| 944 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 945 | + if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { |
|
| 946 | + $fc_items['view_related_messages'] = array( |
|
| 947 | + 'class' => $related_for_icon['css_class'], |
|
| 948 | + 'desc' => $related_for_icon['label'], |
|
| 949 | + ); |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | + $sc_items = array( |
|
| 953 | + 'approved_status' => array( |
|
| 954 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 955 | + 'desc' => EEH_Template::pretty_status( |
|
| 956 | + EEM_Registration::status_id_approved, |
|
| 957 | + false, |
|
| 958 | + 'sentence' |
|
| 959 | + ), |
|
| 960 | + ), |
|
| 961 | + 'pending_status' => array( |
|
| 962 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 963 | + 'desc' => EEH_Template::pretty_status( |
|
| 964 | + EEM_Registration::status_id_pending_payment, |
|
| 965 | + false, |
|
| 966 | + 'sentence' |
|
| 967 | + ), |
|
| 968 | + ), |
|
| 969 | + 'wait_list' => array( |
|
| 970 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 971 | + 'desc' => EEH_Template::pretty_status( |
|
| 972 | + EEM_Registration::status_id_wait_list, |
|
| 973 | + false, |
|
| 974 | + 'sentence' |
|
| 975 | + ), |
|
| 976 | + ), |
|
| 977 | + 'incomplete_status' => array( |
|
| 978 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_incomplete, |
|
| 979 | + 'desc' => EEH_Template::pretty_status( |
|
| 980 | + EEM_Registration::status_id_incomplete, |
|
| 981 | + false, |
|
| 982 | + 'sentence' |
|
| 983 | + ), |
|
| 984 | + ), |
|
| 985 | + 'not_approved' => array( |
|
| 986 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 987 | + 'desc' => EEH_Template::pretty_status( |
|
| 988 | + EEM_Registration::status_id_not_approved, |
|
| 989 | + false, |
|
| 990 | + 'sentence' |
|
| 991 | + ), |
|
| 992 | + ), |
|
| 993 | + 'declined_status' => array( |
|
| 994 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 995 | + 'desc' => EEH_Template::pretty_status( |
|
| 996 | + EEM_Registration::status_id_declined, |
|
| 997 | + false, |
|
| 998 | + 'sentence' |
|
| 999 | + ), |
|
| 1000 | + ), |
|
| 1001 | + 'cancelled_status' => array( |
|
| 1002 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1003 | + 'desc' => EEH_Template::pretty_status( |
|
| 1004 | + EEM_Registration::status_id_cancelled, |
|
| 1005 | + false, |
|
| 1006 | + 'sentence' |
|
| 1007 | + ), |
|
| 1008 | + ), |
|
| 1009 | + ); |
|
| 1010 | + return array_merge($fc_items, $sc_items); |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + |
|
| 1014 | + |
|
| 1015 | + /*************************************** REGISTRATION OVERVIEW **************************************/ |
|
| 1016 | + /** |
|
| 1017 | + * @throws \EE_Error |
|
| 1018 | + */ |
|
| 1019 | + protected function _registrations_overview_list_table() |
|
| 1020 | + { |
|
| 1021 | + $this->_template_args['admin_page_header'] = ''; |
|
| 1022 | + $EVT_ID = ! empty($this->_req_data['event_id']) |
|
| 1023 | + ? absint($this->_req_data['event_id']) |
|
| 1024 | + : 0; |
|
| 1025 | + $ATT_ID = ! empty($this->_req_data['ATT_ID']) |
|
| 1026 | + ? absint($this->_req_data['ATT_ID']) |
|
| 1027 | + : 0; |
|
| 1028 | + if ($ATT_ID) { |
|
| 1029 | + $attendee = EEM_Attendee::instance()->get_one_by_ID($ATT_ID); |
|
| 1030 | + if ($attendee instanceof EE_Attendee) { |
|
| 1031 | + $this->_template_args['admin_page_header'] = sprintf( |
|
| 1032 | + esc_html__( |
|
| 1033 | + '%1$s Viewing registrations for %2$s%3$s', |
|
| 1034 | + 'event_espresso' |
|
| 1035 | + ), |
|
| 1036 | + '<h3 style="line-height:1.5em;">', |
|
| 1037 | + '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
| 1038 | + array( |
|
| 1039 | + 'action' => 'edit_attendee', |
|
| 1040 | + 'post' => $ATT_ID, |
|
| 1041 | + ), |
|
| 1042 | + REG_ADMIN_URL |
|
| 1043 | + ) . '">' . $attendee->full_name() . '</a>', |
|
| 1044 | + '</h3>' |
|
| 1045 | + ); |
|
| 1046 | + } |
|
| 1047 | + } |
|
| 1048 | + if ($EVT_ID) { |
|
| 1049 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 1050 | + 'ee_edit_registrations', |
|
| 1051 | + 'espresso_registrations_new_registration', |
|
| 1052 | + $EVT_ID |
|
| 1053 | + )) { |
|
| 1054 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
| 1055 | + 'new_registration', |
|
| 1056 | + 'add-registrant', |
|
| 1057 | + array('event_id' => $EVT_ID), |
|
| 1058 | + 'add-new-h2' |
|
| 1059 | + ); |
|
| 1060 | + } |
|
| 1061 | + $event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 1062 | + if ($event instanceof EE_Event) { |
|
| 1063 | + $this->_template_args['admin_page_header'] = sprintf( |
|
| 1064 | + esc_html__( |
|
| 1065 | + '%s Viewing registrations for the event: %s%s', |
|
| 1066 | + 'event_espresso' |
|
| 1067 | + ), |
|
| 1068 | + '<h3 style="line-height:1.5em;">', |
|
| 1069 | + '<br /><a href="' |
|
| 1070 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
| 1071 | + array( |
|
| 1072 | + 'action' => 'edit', |
|
| 1073 | + 'post' => $event->ID(), |
|
| 1074 | + ), |
|
| 1075 | + EVENTS_ADMIN_URL |
|
| 1076 | + ) |
|
| 1077 | + . '"> ' |
|
| 1078 | + . $event->get('EVT_name') |
|
| 1079 | + . ' </a> ', |
|
| 1080 | + '</h3>' |
|
| 1081 | + ); |
|
| 1082 | + } |
|
| 1083 | + $DTT_ID = ! empty($this->_req_data['datetime_id']) ? absint($this->_req_data['datetime_id']) : 0; |
|
| 1084 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1085 | + if ($datetime instanceof EE_Datetime && $this->_template_args['admin_page_header'] !== '') { |
|
| 1086 | + $this->_template_args['admin_page_header'] = substr( |
|
| 1087 | + $this->_template_args['admin_page_header'], |
|
| 1088 | + 0, |
|
| 1089 | + -5 |
|
| 1090 | + ); |
|
| 1091 | + $this->_template_args['admin_page_header'] .= ' <span class="drk-grey-text">'; |
|
| 1092 | + $this->_template_args['admin_page_header'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1093 | + $this->_template_args['admin_page_header'] .= $datetime->name(); |
|
| 1094 | + $this->_template_args['admin_page_header'] .= ' ( ' . $datetime->start_date() . ' )'; |
|
| 1095 | + $this->_template_args['admin_page_header'] .= '</span></h3>'; |
|
| 1096 | + } |
|
| 1097 | + } |
|
| 1098 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_registration_legend_items()); |
|
| 1099 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + |
|
| 1103 | + /** |
|
| 1104 | + * This sets the _registration property for the registration details screen |
|
| 1105 | + * |
|
| 1106 | + * @access private |
|
| 1107 | + * @return bool |
|
| 1108 | + * @throws EE_Error |
|
| 1109 | + * @throws InvalidArgumentException |
|
| 1110 | + * @throws InvalidDataTypeException |
|
| 1111 | + * @throws InvalidInterfaceException |
|
| 1112 | + */ |
|
| 1113 | + private function _set_registration_object() |
|
| 1114 | + { |
|
| 1115 | + // get out if we've already set the object |
|
| 1116 | + if ($this->_registration instanceof EE_Registration) { |
|
| 1117 | + return true; |
|
| 1118 | + } |
|
| 1119 | + $REG = EEM_Registration::instance(); |
|
| 1120 | + $REG_ID = (! empty($this->_req_data['_REG_ID'])) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 1121 | + if ($this->_registration = $REG->get_one_by_ID($REG_ID)) { |
|
| 1122 | + return true; |
|
| 1123 | + } else { |
|
| 1124 | + $error_msg = sprintf( |
|
| 1125 | + esc_html__( |
|
| 1126 | + 'An error occurred and the details for Registration ID #%s could not be retrieved.', |
|
| 1127 | + 'event_espresso' |
|
| 1128 | + ), |
|
| 1129 | + $REG_ID |
|
| 1130 | + ); |
|
| 1131 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 1132 | + $this->_registration = null; |
|
| 1133 | + return false; |
|
| 1134 | + } |
|
| 1135 | + } |
|
| 1136 | + |
|
| 1137 | + |
|
| 1138 | + /** |
|
| 1139 | + * Used to retrieve registrations for the list table. |
|
| 1140 | + * |
|
| 1141 | + * @param int $per_page |
|
| 1142 | + * @param bool $count |
|
| 1143 | + * @param bool $this_month |
|
| 1144 | + * @param bool $today |
|
| 1145 | + * @return EE_Registration[]|int |
|
| 1146 | + * @throws EE_Error |
|
| 1147 | + * @throws InvalidArgumentException |
|
| 1148 | + * @throws InvalidDataTypeException |
|
| 1149 | + * @throws InvalidInterfaceException |
|
| 1150 | + */ |
|
| 1151 | + public function get_registrations( |
|
| 1152 | + $per_page = 10, |
|
| 1153 | + $count = false, |
|
| 1154 | + $this_month = false, |
|
| 1155 | + $today = false |
|
| 1156 | + ) { |
|
| 1157 | + if ($this_month) { |
|
| 1158 | + $this->_req_data['status'] = 'month'; |
|
| 1159 | + } |
|
| 1160 | + if ($today) { |
|
| 1161 | + $this->_req_data['status'] = 'today'; |
|
| 1162 | + } |
|
| 1163 | + $query_params = $this->_get_registration_query_parameters($this->_req_data, $per_page, $count); |
|
| 1164 | + /** |
|
| 1165 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1166 | + * |
|
| 1167 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1168 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1169 | + * or if you have the development copy of EE you can view this at the path: |
|
| 1170 | + * /docs/G--Model-System/model-query-params.md |
|
| 1171 | + */ |
|
| 1172 | + $query_params['group_by'] = ''; |
|
| 1173 | + |
|
| 1174 | + return $count |
|
| 1175 | + ? EEM_Registration::instance()->count($query_params) |
|
| 1176 | + /** @type EE_Registration[] */ |
|
| 1177 | + : EEM_Registration::instance()->get_all($query_params); |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + |
|
| 1181 | + /** |
|
| 1182 | + * Retrieves the query parameters to be used by the Registration model for getting registrations. |
|
| 1183 | + * Note: this listens to values on the request for some of the query parameters. |
|
| 1184 | + * |
|
| 1185 | + * @param array $request |
|
| 1186 | + * @param int $per_page |
|
| 1187 | + * @param bool $count |
|
| 1188 | + * @return array |
|
| 1189 | + * @throws EE_Error |
|
| 1190 | + */ |
|
| 1191 | + protected function _get_registration_query_parameters( |
|
| 1192 | + $request = array(), |
|
| 1193 | + $per_page = 10, |
|
| 1194 | + $count = false |
|
| 1195 | + ) { |
|
| 1196 | + |
|
| 1197 | + $query_params = array( |
|
| 1198 | + 0 => $this->_get_where_conditions_for_registrations_query( |
|
| 1199 | + $request |
|
| 1200 | + ), |
|
| 1201 | + 'caps' => EEM_Registration::caps_read_admin, |
|
| 1202 | + 'default_where_conditions' => 'this_model_only', |
|
| 1203 | + ); |
|
| 1204 | + if (! $count) { |
|
| 1205 | + $query_params = array_merge( |
|
| 1206 | + $query_params, |
|
| 1207 | + $this->_get_orderby_for_registrations_query(), |
|
| 1208 | + $this->_get_limit($per_page) |
|
| 1209 | + ); |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + return $query_params; |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + |
|
| 1216 | + /** |
|
| 1217 | + * This will add ATT_ID to the provided $where array for EE model query parameters. |
|
| 1218 | + * |
|
| 1219 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1220 | + * @return array |
|
| 1221 | + */ |
|
| 1222 | + protected function addAttendeeIdToWhereConditions(array $request) |
|
| 1223 | + { |
|
| 1224 | + $where = array(); |
|
| 1225 | + if (! empty($request['ATT_ID'])) { |
|
| 1226 | + $where['ATT_ID'] = absint($request['ATT_ID']); |
|
| 1227 | + } |
|
| 1228 | + return $where; |
|
| 1229 | + } |
|
| 1230 | + |
|
| 1231 | + |
|
| 1232 | + /** |
|
| 1233 | + * This will add EVT_ID to the provided $where array for EE model query parameters. |
|
| 1234 | + * |
|
| 1235 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1236 | + * @return array |
|
| 1237 | + */ |
|
| 1238 | + protected function _add_event_id_to_where_conditions(array $request) |
|
| 1239 | + { |
|
| 1240 | + $where = array(); |
|
| 1241 | + if (! empty($request['event_id'])) { |
|
| 1242 | + $where['EVT_ID'] = absint($request['event_id']); |
|
| 1243 | + } |
|
| 1244 | + return $where; |
|
| 1245 | + } |
|
| 1246 | + |
|
| 1247 | + |
|
| 1248 | + /** |
|
| 1249 | + * Adds category ID if it exists in the request to the where conditions for the registrations query. |
|
| 1250 | + * |
|
| 1251 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1252 | + * @return array |
|
| 1253 | + */ |
|
| 1254 | + protected function _add_category_id_to_where_conditions(array $request) |
|
| 1255 | + { |
|
| 1256 | + $where = array(); |
|
| 1257 | + if (! empty($request['EVT_CAT']) && (int) $request['EVT_CAT'] !== -1) { |
|
| 1258 | + $where['Event.Term_Taxonomy.term_id'] = absint($request['EVT_CAT']); |
|
| 1259 | + } |
|
| 1260 | + return $where; |
|
| 1261 | + } |
|
| 1262 | + |
|
| 1263 | + |
|
| 1264 | + /** |
|
| 1265 | + * Adds the datetime ID if it exists in the request to the where conditions for the registrations query. |
|
| 1266 | + * |
|
| 1267 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1268 | + * @return array |
|
| 1269 | + */ |
|
| 1270 | + protected function _add_datetime_id_to_where_conditions(array $request) |
|
| 1271 | + { |
|
| 1272 | + $where = array(); |
|
| 1273 | + if (! empty($request['datetime_id'])) { |
|
| 1274 | + $where['Ticket.Datetime.DTT_ID'] = absint($request['datetime_id']); |
|
| 1275 | + } |
|
| 1276 | + if (! empty($request['DTT_ID'])) { |
|
| 1277 | + $where['Ticket.Datetime.DTT_ID'] = absint($request['DTT_ID']); |
|
| 1278 | + } |
|
| 1279 | + return $where; |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + |
|
| 1283 | + /** |
|
| 1284 | + * Adds the correct registration status to the where conditions for the registrations query. |
|
| 1285 | + * |
|
| 1286 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1287 | + * @return array |
|
| 1288 | + */ |
|
| 1289 | + protected function _add_registration_status_to_where_conditions(array $request) |
|
| 1290 | + { |
|
| 1291 | + $where = array(); |
|
| 1292 | + $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1293 | + $registration_status = ! empty($request['_reg_status']) |
|
| 1294 | + ? sanitize_text_field($request['_reg_status']) |
|
| 1295 | + : ''; |
|
| 1296 | + |
|
| 1297 | + /* |
|
| 1298 | 1298 | * If filtering by registration status, then we show registrations matching that status. |
| 1299 | 1299 | * If not filtering by specified status, then we show all registrations excluding incomplete registrations |
| 1300 | 1300 | * UNLESS viewing trashed registrations. |
| 1301 | 1301 | */ |
| 1302 | - if (! empty($registration_status)) { |
|
| 1303 | - $where['STS_ID'] = $registration_status; |
|
| 1304 | - } else { |
|
| 1305 | - // make sure we exclude incomplete registrations, but only if not trashed. |
|
| 1306 | - if ($view === 'trash') { |
|
| 1307 | - $where['REG_deleted'] = true; |
|
| 1308 | - } elseif ($view === 'incomplete') { |
|
| 1309 | - $where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 1310 | - } else { |
|
| 1311 | - $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 1312 | - } |
|
| 1313 | - } |
|
| 1314 | - return $where; |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - |
|
| 1318 | - /** |
|
| 1319 | - * Adds any provided date restraints to the where conditions for the registrations query. |
|
| 1320 | - * |
|
| 1321 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1322 | - * @return array |
|
| 1323 | - * @throws EE_Error |
|
| 1324 | - * @throws InvalidArgumentException |
|
| 1325 | - * @throws InvalidDataTypeException |
|
| 1326 | - * @throws InvalidInterfaceException |
|
| 1327 | - */ |
|
| 1328 | - protected function _add_date_to_where_conditions(array $request) |
|
| 1329 | - { |
|
| 1330 | - $where = array(); |
|
| 1331 | - $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1332 | - $month_range = ! empty($request['month_range']) |
|
| 1333 | - ? sanitize_text_field($request['month_range']) |
|
| 1334 | - : ''; |
|
| 1335 | - $retrieve_for_today = $view === 'today'; |
|
| 1336 | - $retrieve_for_this_month = $view === 'month'; |
|
| 1337 | - |
|
| 1338 | - if ($retrieve_for_today) { |
|
| 1339 | - $now = date('Y-m-d', current_time('timestamp')); |
|
| 1340 | - $where['REG_date'] = array( |
|
| 1341 | - 'BETWEEN', |
|
| 1342 | - array( |
|
| 1343 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1344 | - 'REG_date', |
|
| 1345 | - $now . ' 00:00:00', |
|
| 1346 | - 'Y-m-d H:i:s' |
|
| 1347 | - ), |
|
| 1348 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1349 | - 'REG_date', |
|
| 1350 | - $now . ' 23:59:59', |
|
| 1351 | - 'Y-m-d H:i:s' |
|
| 1352 | - ), |
|
| 1353 | - ), |
|
| 1354 | - ); |
|
| 1355 | - } elseif ($retrieve_for_this_month) { |
|
| 1356 | - $current_year_and_month = date('Y-m', current_time('timestamp')); |
|
| 1357 | - $days_this_month = date('t', current_time('timestamp')); |
|
| 1358 | - $where['REG_date'] = array( |
|
| 1359 | - 'BETWEEN', |
|
| 1360 | - array( |
|
| 1361 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1362 | - 'REG_date', |
|
| 1363 | - $current_year_and_month . '-01 00:00:00', |
|
| 1364 | - 'Y-m-d H:i:s' |
|
| 1365 | - ), |
|
| 1366 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1367 | - 'REG_date', |
|
| 1368 | - $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 1369 | - 'Y-m-d H:i:s' |
|
| 1370 | - ), |
|
| 1371 | - ), |
|
| 1372 | - ); |
|
| 1373 | - } elseif ($month_range) { |
|
| 1374 | - $pieces = explode(' ', $month_range, 3); |
|
| 1375 | - $month_requested = ! empty($pieces[0]) |
|
| 1376 | - ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
| 1377 | - : ''; |
|
| 1378 | - $year_requested = ! empty($pieces[1]) |
|
| 1379 | - ? $pieces[1] |
|
| 1380 | - : ''; |
|
| 1381 | - // if there is not a month or year then we can't go further |
|
| 1382 | - if ($month_requested && $year_requested) { |
|
| 1383 | - $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 1384 | - $where['REG_date'] = array( |
|
| 1385 | - 'BETWEEN', |
|
| 1386 | - array( |
|
| 1387 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1388 | - 'REG_date', |
|
| 1389 | - $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 1390 | - 'Y-m-d H:i:s' |
|
| 1391 | - ), |
|
| 1392 | - EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1393 | - 'REG_date', |
|
| 1394 | - $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 1395 | - 'Y-m-d H:i:s' |
|
| 1396 | - ), |
|
| 1397 | - ), |
|
| 1398 | - ); |
|
| 1399 | - } |
|
| 1400 | - } |
|
| 1401 | - return $where; |
|
| 1402 | - } |
|
| 1403 | - |
|
| 1404 | - |
|
| 1405 | - /** |
|
| 1406 | - * Adds any provided search restraints to the where conditions for the registrations query |
|
| 1407 | - * |
|
| 1408 | - * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1409 | - * @return array |
|
| 1410 | - */ |
|
| 1411 | - protected function _add_search_to_where_conditions(array $request) |
|
| 1412 | - { |
|
| 1413 | - $where = array(); |
|
| 1414 | - if (! empty($request['s'])) { |
|
| 1415 | - $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
| 1416 | - $where['OR*search_conditions'] = array( |
|
| 1417 | - 'Event.EVT_name' => array('LIKE', $search_string), |
|
| 1418 | - 'Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1419 | - 'Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1420 | - 'Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1421 | - 'Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1422 | - 'Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1423 | - 'Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1424 | - 'Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1425 | - 'Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1426 | - 'Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1427 | - 'Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1428 | - 'REG_final_price' => array('LIKE', $search_string), |
|
| 1429 | - 'REG_code' => array('LIKE', $search_string), |
|
| 1430 | - 'REG_count' => array('LIKE', $search_string), |
|
| 1431 | - 'REG_group_size' => array('LIKE', $search_string), |
|
| 1432 | - 'Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1433 | - 'Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1434 | - 'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 1435 | - ); |
|
| 1436 | - } |
|
| 1437 | - return $where; |
|
| 1438 | - } |
|
| 1439 | - |
|
| 1440 | - |
|
| 1441 | - /** |
|
| 1442 | - * Sets up the where conditions for the registrations query. |
|
| 1443 | - * |
|
| 1444 | - * @param array $request |
|
| 1445 | - * @return array |
|
| 1446 | - * @throws EE_Error |
|
| 1447 | - */ |
|
| 1448 | - protected function _get_where_conditions_for_registrations_query($request) |
|
| 1449 | - { |
|
| 1450 | - return apply_filters( |
|
| 1451 | - 'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', |
|
| 1452 | - array_merge( |
|
| 1453 | - $this->addAttendeeIdToWhereConditions($request), |
|
| 1454 | - $this->_add_event_id_to_where_conditions($request), |
|
| 1455 | - $this->_add_category_id_to_where_conditions($request), |
|
| 1456 | - $this->_add_datetime_id_to_where_conditions($request), |
|
| 1457 | - $this->_add_registration_status_to_where_conditions($request), |
|
| 1458 | - $this->_add_date_to_where_conditions($request), |
|
| 1459 | - $this->_add_search_to_where_conditions($request) |
|
| 1460 | - ), |
|
| 1461 | - $request |
|
| 1462 | - ); |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - |
|
| 1466 | - /** |
|
| 1467 | - * Sets up the orderby for the registrations query. |
|
| 1468 | - * |
|
| 1469 | - * @return array |
|
| 1470 | - */ |
|
| 1471 | - protected function _get_orderby_for_registrations_query() |
|
| 1472 | - { |
|
| 1473 | - $orderby_field = ! empty($this->_req_data['orderby']) |
|
| 1474 | - ? sanitize_text_field($this->_req_data['orderby']) |
|
| 1475 | - : '_REG_date'; |
|
| 1476 | - switch ($orderby_field) { |
|
| 1477 | - case '_REG_ID': |
|
| 1478 | - $orderby = array('REG_ID'); |
|
| 1479 | - break; |
|
| 1480 | - case '_Reg_status': |
|
| 1481 | - $orderby = array('STS_ID'); |
|
| 1482 | - break; |
|
| 1483 | - case 'ATT_fname': |
|
| 1484 | - $orderby = array('Attendee.ATT_fname', 'Attendee.ATT_lname'); |
|
| 1485 | - break; |
|
| 1486 | - case 'ATT_lname': |
|
| 1487 | - $orderby = array('Attendee.ATT_lname', 'Attendee.ATT_fname'); |
|
| 1488 | - break; |
|
| 1489 | - case 'event_name': |
|
| 1490 | - $orderby = array('Event.EVT_name'); |
|
| 1491 | - break; |
|
| 1492 | - case 'DTT_EVT_start': |
|
| 1493 | - $orderby = array('Event.Datetime.DTT_EVT_start'); |
|
| 1494 | - break; |
|
| 1495 | - case '_REG_date': |
|
| 1496 | - $orderby = array('REG_date'); |
|
| 1497 | - break; |
|
| 1498 | - default: |
|
| 1499 | - $orderby = array($orderby_field); |
|
| 1500 | - break; |
|
| 1501 | - } |
|
| 1502 | - |
|
| 1503 | - // order |
|
| 1504 | - $order = ! empty($this->_req_data['order']) |
|
| 1505 | - ? sanitize_text_field($this->_req_data['order']) |
|
| 1506 | - : 'DESC'; |
|
| 1507 | - $orderby = array_combine( |
|
| 1508 | - $orderby, |
|
| 1509 | - array_fill(0, count($orderby), $order) |
|
| 1510 | - ); |
|
| 1511 | - // because there are many registrations with the same date, define |
|
| 1512 | - // a secondary way to order them, otherwise MySQL seems to be a bit random |
|
| 1513 | - if (empty($orderby['REG_ID'])) { |
|
| 1514 | - $orderby['REG_ID'] = $order; |
|
| 1515 | - } |
|
| 1516 | - |
|
| 1517 | - $orderby = apply_filters( |
|
| 1518 | - 'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query', |
|
| 1519 | - $orderby, |
|
| 1520 | - $this->_req_data |
|
| 1521 | - ); |
|
| 1522 | - |
|
| 1523 | - return array('order_by' => $orderby); |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - |
|
| 1527 | - /** |
|
| 1528 | - * Sets up the limit for the registrations query. |
|
| 1529 | - * |
|
| 1530 | - * @param $per_page |
|
| 1531 | - * @return array |
|
| 1532 | - */ |
|
| 1533 | - protected function _get_limit($per_page) |
|
| 1534 | - { |
|
| 1535 | - $current_page = ! empty($this->_req_data['paged']) |
|
| 1536 | - ? absint($this->_req_data['paged']) |
|
| 1537 | - : 1; |
|
| 1538 | - $per_page = ! empty($this->_req_data['perpage']) |
|
| 1539 | - ? $this->_req_data['perpage'] |
|
| 1540 | - : $per_page; |
|
| 1541 | - |
|
| 1542 | - // -1 means return all results so get out if that's set. |
|
| 1543 | - if ((int) $per_page === -1) { |
|
| 1544 | - return array(); |
|
| 1545 | - } |
|
| 1546 | - $per_page = absint($per_page); |
|
| 1547 | - $offset = ($current_page - 1) * $per_page; |
|
| 1548 | - return array('limit' => array($offset, $per_page)); |
|
| 1549 | - } |
|
| 1550 | - |
|
| 1551 | - |
|
| 1552 | - public function get_registration_status_array() |
|
| 1553 | - { |
|
| 1554 | - return self::$_reg_status; |
|
| 1555 | - } |
|
| 1556 | - |
|
| 1557 | - |
|
| 1558 | - |
|
| 1559 | - |
|
| 1560 | - /*************************************** REGISTRATION DETAILS ***************************************/ |
|
| 1561 | - /** |
|
| 1562 | - * generates HTML for the View Registration Details Admin page |
|
| 1563 | - * |
|
| 1564 | - * @access protected |
|
| 1565 | - * @return void |
|
| 1566 | - * @throws DomainException |
|
| 1567 | - * @throws EE_Error |
|
| 1568 | - * @throws InvalidArgumentException |
|
| 1569 | - * @throws InvalidDataTypeException |
|
| 1570 | - * @throws InvalidInterfaceException |
|
| 1571 | - * @throws EntityNotFoundException |
|
| 1572 | - */ |
|
| 1573 | - protected function _registration_details() |
|
| 1574 | - { |
|
| 1575 | - $this->_template_args = array(); |
|
| 1576 | - $this->_set_registration_object(); |
|
| 1577 | - if (is_object($this->_registration)) { |
|
| 1578 | - $transaction = $this->_registration->transaction() |
|
| 1579 | - ? $this->_registration->transaction() |
|
| 1580 | - : EE_Transaction::new_instance(); |
|
| 1581 | - $this->_session = $transaction->session_data(); |
|
| 1582 | - $event_id = $this->_registration->event_ID(); |
|
| 1583 | - $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
| 1584 | - $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso'); |
|
| 1585 | - $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
| 1586 | - $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 1587 | - $this->_template_args['grand_total'] = $transaction->total(); |
|
| 1588 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1589 | - // link back to overview |
|
| 1590 | - $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
| 1591 | - $this->_template_args['registration'] = $this->_registration; |
|
| 1592 | - $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1593 | - array( |
|
| 1594 | - 'action' => 'default', |
|
| 1595 | - 'event_id' => $event_id, |
|
| 1596 | - ), |
|
| 1597 | - REG_ADMIN_URL |
|
| 1598 | - ); |
|
| 1599 | - $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1600 | - array( |
|
| 1601 | - 'action' => 'default', |
|
| 1602 | - 'EVT_ID' => $event_id, |
|
| 1603 | - 'page' => 'espresso_transactions', |
|
| 1604 | - ), |
|
| 1605 | - admin_url('admin.php') |
|
| 1606 | - ); |
|
| 1607 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1608 | - array( |
|
| 1609 | - 'page' => 'espresso_events', |
|
| 1610 | - 'action' => 'edit', |
|
| 1611 | - 'post' => $event_id, |
|
| 1612 | - ), |
|
| 1613 | - admin_url('admin.php') |
|
| 1614 | - ); |
|
| 1615 | - // next and previous links |
|
| 1616 | - $next_reg = $this->_registration->next( |
|
| 1617 | - null, |
|
| 1618 | - array(), |
|
| 1619 | - 'REG_ID' |
|
| 1620 | - ); |
|
| 1621 | - $this->_template_args['next_registration'] = $next_reg |
|
| 1622 | - ? $this->_next_link( |
|
| 1623 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 1624 | - array( |
|
| 1625 | - 'action' => 'view_registration', |
|
| 1626 | - '_REG_ID' => $next_reg['REG_ID'], |
|
| 1627 | - ), |
|
| 1628 | - REG_ADMIN_URL |
|
| 1629 | - ), |
|
| 1630 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 1631 | - ) |
|
| 1632 | - : ''; |
|
| 1633 | - $previous_reg = $this->_registration->previous( |
|
| 1634 | - null, |
|
| 1635 | - array(), |
|
| 1636 | - 'REG_ID' |
|
| 1637 | - ); |
|
| 1638 | - $this->_template_args['previous_registration'] = $previous_reg |
|
| 1639 | - ? $this->_previous_link( |
|
| 1640 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 1641 | - array( |
|
| 1642 | - 'action' => 'view_registration', |
|
| 1643 | - '_REG_ID' => $previous_reg['REG_ID'], |
|
| 1644 | - ), |
|
| 1645 | - REG_ADMIN_URL |
|
| 1646 | - ), |
|
| 1647 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 1648 | - ) |
|
| 1649 | - : ''; |
|
| 1650 | - // grab header |
|
| 1651 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1652 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1653 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 1654 | - $template_path, |
|
| 1655 | - $this->_template_args, |
|
| 1656 | - true |
|
| 1657 | - ); |
|
| 1658 | - } else { |
|
| 1659 | - $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
|
| 1660 | - } |
|
| 1661 | - // the details template wrapper |
|
| 1662 | - $this->display_admin_page_with_sidebar(); |
|
| 1663 | - } |
|
| 1664 | - |
|
| 1665 | - |
|
| 1666 | - protected function _registration_details_metaboxes() |
|
| 1667 | - { |
|
| 1668 | - do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
| 1669 | - $this->_set_registration_object(); |
|
| 1670 | - $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
| 1671 | - add_meta_box( |
|
| 1672 | - 'edit-reg-status-mbox', |
|
| 1673 | - esc_html__('Registration Status', 'event_espresso'), |
|
| 1674 | - array($this, 'set_reg_status_buttons_metabox'), |
|
| 1675 | - $this->wp_page_slug, |
|
| 1676 | - 'normal', |
|
| 1677 | - 'high' |
|
| 1678 | - ); |
|
| 1679 | - add_meta_box( |
|
| 1680 | - 'edit-reg-details-mbox', |
|
| 1681 | - esc_html__('Registration Details', 'event_espresso'), |
|
| 1682 | - array($this, '_reg_details_meta_box'), |
|
| 1683 | - $this->wp_page_slug, |
|
| 1684 | - 'normal', |
|
| 1685 | - 'high' |
|
| 1686 | - ); |
|
| 1687 | - if ($attendee instanceof EE_Attendee |
|
| 1688 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 1689 | - 'ee_read_registration', |
|
| 1690 | - 'edit-reg-questions-mbox', |
|
| 1691 | - $this->_registration->ID() |
|
| 1692 | - ) |
|
| 1693 | - ) { |
|
| 1694 | - add_meta_box( |
|
| 1695 | - 'edit-reg-questions-mbox', |
|
| 1696 | - esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 1697 | - array($this, '_reg_questions_meta_box'), |
|
| 1698 | - $this->wp_page_slug, |
|
| 1699 | - 'normal', |
|
| 1700 | - 'high' |
|
| 1701 | - ); |
|
| 1702 | - } |
|
| 1703 | - add_meta_box( |
|
| 1704 | - 'edit-reg-registrant-mbox', |
|
| 1705 | - esc_html__('Contact Details', 'event_espresso'), |
|
| 1706 | - array($this, '_reg_registrant_side_meta_box'), |
|
| 1707 | - $this->wp_page_slug, |
|
| 1708 | - 'side', |
|
| 1709 | - 'high' |
|
| 1710 | - ); |
|
| 1711 | - if ($this->_registration->group_size() > 1) { |
|
| 1712 | - add_meta_box( |
|
| 1713 | - 'edit-reg-attendees-mbox', |
|
| 1714 | - esc_html__('Other Registrations in this Transaction', 'event_espresso'), |
|
| 1715 | - array($this, '_reg_attendees_meta_box'), |
|
| 1716 | - $this->wp_page_slug, |
|
| 1717 | - 'normal', |
|
| 1718 | - 'high' |
|
| 1719 | - ); |
|
| 1720 | - } |
|
| 1721 | - } |
|
| 1722 | - |
|
| 1723 | - |
|
| 1724 | - /** |
|
| 1725 | - * set_reg_status_buttons_metabox |
|
| 1726 | - * |
|
| 1727 | - * @access protected |
|
| 1728 | - * @return string |
|
| 1729 | - * @throws \EE_Error |
|
| 1730 | - */ |
|
| 1731 | - public function set_reg_status_buttons_metabox() |
|
| 1732 | - { |
|
| 1733 | - $this->_set_registration_object(); |
|
| 1734 | - $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
| 1735 | - echo $change_reg_status_form->form_open( |
|
| 1736 | - self::add_query_args_and_nonce( |
|
| 1737 | - array( |
|
| 1738 | - 'action' => 'change_reg_status', |
|
| 1739 | - ), |
|
| 1740 | - REG_ADMIN_URL |
|
| 1741 | - ) |
|
| 1742 | - ); |
|
| 1743 | - echo $change_reg_status_form->get_html(); |
|
| 1744 | - echo $change_reg_status_form->form_close(); |
|
| 1745 | - } |
|
| 1746 | - |
|
| 1747 | - |
|
| 1748 | - /** |
|
| 1749 | - * @return EE_Form_Section_Proper |
|
| 1750 | - * @throws EE_Error |
|
| 1751 | - * @throws InvalidArgumentException |
|
| 1752 | - * @throws InvalidDataTypeException |
|
| 1753 | - * @throws InvalidInterfaceException |
|
| 1754 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1755 | - */ |
|
| 1756 | - protected function _generate_reg_status_change_form() |
|
| 1757 | - { |
|
| 1758 | - $reg_status_change_form_array = array( |
|
| 1759 | - 'name' => 'reg_status_change_form', |
|
| 1760 | - 'html_id' => 'reg-status-change-form', |
|
| 1761 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1762 | - 'subsections' => array( |
|
| 1763 | - 'return' => new EE_Hidden_Input( |
|
| 1764 | - array( |
|
| 1765 | - 'name' => 'return', |
|
| 1766 | - 'default' => 'view_registration', |
|
| 1767 | - ) |
|
| 1768 | - ), |
|
| 1769 | - 'REG_ID' => new EE_Hidden_Input( |
|
| 1770 | - array( |
|
| 1771 | - 'name' => 'REG_ID', |
|
| 1772 | - 'default' => $this->_registration->ID(), |
|
| 1773 | - ) |
|
| 1774 | - ), |
|
| 1775 | - 'current_status' => new EE_Form_Section_HTML( |
|
| 1776 | - EEH_HTML::table( |
|
| 1777 | - EEH_HTML::tr( |
|
| 1778 | - EEH_HTML::th( |
|
| 1779 | - EEH_HTML::label( |
|
| 1780 | - EEH_HTML::strong( |
|
| 1781 | - esc_html__('Current Registration Status', 'event_espresso') |
|
| 1782 | - ) |
|
| 1783 | - ) |
|
| 1784 | - ) |
|
| 1785 | - . EEH_HTML::td( |
|
| 1786 | - EEH_HTML::strong( |
|
| 1787 | - $this->_registration->pretty_status(), |
|
| 1788 | - '', |
|
| 1789 | - 'status-' . $this->_registration->status_ID(), |
|
| 1790 | - 'line-height: 1em; font-size: 1.5em; font-weight: bold;' |
|
| 1791 | - ) |
|
| 1792 | - ) |
|
| 1793 | - ) |
|
| 1794 | - ) |
|
| 1795 | - ) |
|
| 1796 | - ) |
|
| 1797 | - ); |
|
| 1798 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 1799 | - 'ee_edit_registration', |
|
| 1800 | - 'toggle_registration_status', |
|
| 1801 | - $this->_registration->ID() |
|
| 1802 | - )) { |
|
| 1803 | - $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input( |
|
| 1804 | - $this->_get_reg_statuses(), |
|
| 1805 | - array( |
|
| 1806 | - 'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'), |
|
| 1807 | - 'default' => $this->_registration->status_ID(), |
|
| 1808 | - ) |
|
| 1809 | - ); |
|
| 1810 | - $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input( |
|
| 1811 | - array( |
|
| 1812 | - 'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'), |
|
| 1813 | - 'default' => false, |
|
| 1814 | - 'html_help_text' => esc_html__( |
|
| 1815 | - 'If set to "Yes", then the related messages will be sent to the registrant.', |
|
| 1816 | - 'event_espresso' |
|
| 1817 | - ) |
|
| 1818 | - ) |
|
| 1819 | - ); |
|
| 1820 | - $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input( |
|
| 1821 | - array( |
|
| 1822 | - 'html_class' => 'button-primary', |
|
| 1823 | - 'html_label_text' => ' ', |
|
| 1824 | - 'default' => esc_html__('Update Registration Status', 'event_espresso'), |
|
| 1825 | - ) |
|
| 1826 | - ); |
|
| 1827 | - } |
|
| 1828 | - return new EE_Form_Section_Proper($reg_status_change_form_array); |
|
| 1829 | - } |
|
| 1830 | - |
|
| 1831 | - |
|
| 1832 | - /** |
|
| 1833 | - * Returns an array of all the buttons for the various statuses and switch status actions |
|
| 1834 | - * |
|
| 1835 | - * @return array |
|
| 1836 | - * @throws EE_Error |
|
| 1837 | - * @throws InvalidArgumentException |
|
| 1838 | - * @throws InvalidDataTypeException |
|
| 1839 | - * @throws InvalidInterfaceException |
|
| 1840 | - * @throws EntityNotFoundException |
|
| 1841 | - */ |
|
| 1842 | - protected function _get_reg_statuses() |
|
| 1843 | - { |
|
| 1844 | - $reg_status_array = EEM_Registration::instance()->reg_status_array(); |
|
| 1845 | - unset($reg_status_array[ EEM_Registration::status_id_incomplete ]); |
|
| 1846 | - // get current reg status |
|
| 1847 | - $current_status = $this->_registration->status_ID(); |
|
| 1848 | - // is registration for free event? This will determine whether to display the pending payment option |
|
| 1849 | - if ($current_status !== EEM_Registration::status_id_pending_payment |
|
| 1850 | - && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00) |
|
| 1851 | - ) { |
|
| 1852 | - unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]); |
|
| 1853 | - } |
|
| 1854 | - return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence'); |
|
| 1855 | - } |
|
| 1856 | - |
|
| 1857 | - |
|
| 1858 | - /** |
|
| 1859 | - * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
| 1860 | - * |
|
| 1861 | - * @param bool $status REG status given for changing registrations to. |
|
| 1862 | - * @param bool $notify Whether to send messages notifications or not. |
|
| 1863 | - * @return array (array with reg_id(s) updated and whether update was successful. |
|
| 1864 | - * @throws EE_Error |
|
| 1865 | - * @throws InvalidArgumentException |
|
| 1866 | - * @throws InvalidDataTypeException |
|
| 1867 | - * @throws InvalidInterfaceException |
|
| 1868 | - * @throws ReflectionException |
|
| 1869 | - * @throws RuntimeException |
|
| 1870 | - * @throws EntityNotFoundException |
|
| 1871 | - */ |
|
| 1872 | - protected function _set_registration_status_from_request($status = false, $notify = false) |
|
| 1873 | - { |
|
| 1874 | - if (isset($this->_req_data['reg_status_change_form'])) { |
|
| 1875 | - $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 1876 | - ? (array) $this->_req_data['reg_status_change_form']['REG_ID'] |
|
| 1877 | - : array(); |
|
| 1878 | - } else { |
|
| 1879 | - $REG_IDs = isset($this->_req_data['_REG_ID']) |
|
| 1880 | - ? (array) $this->_req_data['_REG_ID'] |
|
| 1881 | - : array(); |
|
| 1882 | - } |
|
| 1883 | - // sanitize $REG_IDs |
|
| 1884 | - $REG_IDs = array_map('absint', $REG_IDs); |
|
| 1885 | - // and remove empty entries |
|
| 1886 | - $REG_IDs = array_filter($REG_IDs); |
|
| 1887 | - |
|
| 1888 | - $result = $this->_set_registration_status($REG_IDs, $status, $notify); |
|
| 1889 | - |
|
| 1890 | - /** |
|
| 1891 | - * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications. |
|
| 1892 | - * Currently this value is used downstream by the _process_resend_registration method. |
|
| 1893 | - * |
|
| 1894 | - * @param int|array $registration_ids The registration ids that have had their status changed successfully. |
|
| 1895 | - * @param bool $status The status registrations were changed to. |
|
| 1896 | - * @param bool $success If the status was changed successfully for all registrations. |
|
| 1897 | - * @param Registrations_Admin_Page $admin_page_object |
|
| 1898 | - */ |
|
| 1899 | - $this->_req_data['_REG_ID'] = apply_filters( |
|
| 1900 | - 'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs', |
|
| 1901 | - $result['REG_ID'], |
|
| 1902 | - $status, |
|
| 1903 | - $result['success'], |
|
| 1904 | - $this |
|
| 1905 | - ); |
|
| 1906 | - |
|
| 1907 | - // notify? |
|
| 1908 | - if ($notify |
|
| 1909 | - && $result['success'] |
|
| 1910 | - && ! empty($this->_req_data['_REG_ID']) |
|
| 1911 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 1912 | - 'ee_send_message', |
|
| 1913 | - 'espresso_registrations_resend_registration' |
|
| 1914 | - ) |
|
| 1915 | - ) { |
|
| 1916 | - $this->_process_resend_registration(); |
|
| 1917 | - } |
|
| 1918 | - return $result; |
|
| 1919 | - } |
|
| 1920 | - |
|
| 1921 | - |
|
| 1922 | - /** |
|
| 1923 | - * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
| 1924 | - * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
| 1925 | - * |
|
| 1926 | - * @param array $REG_IDs |
|
| 1927 | - * @param string $status |
|
| 1928 | - * @param bool $notify Used to indicate whether notification was requested or not. This determines the context |
|
| 1929 | - * slug sent with setting the registration status. |
|
| 1930 | - * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
| 1931 | - * @throws EE_Error |
|
| 1932 | - * @throws InvalidArgumentException |
|
| 1933 | - * @throws InvalidDataTypeException |
|
| 1934 | - * @throws InvalidInterfaceException |
|
| 1935 | - * @throws ReflectionException |
|
| 1936 | - * @throws RuntimeException |
|
| 1937 | - * @throws EntityNotFoundException |
|
| 1938 | - */ |
|
| 1939 | - protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false) |
|
| 1940 | - { |
|
| 1941 | - $success = false; |
|
| 1942 | - // typecast $REG_IDs |
|
| 1943 | - $REG_IDs = (array) $REG_IDs; |
|
| 1944 | - if (! empty($REG_IDs)) { |
|
| 1945 | - $success = true; |
|
| 1946 | - // set default status if none is passed |
|
| 1947 | - $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
|
| 1948 | - $status_context = $notify |
|
| 1949 | - ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY |
|
| 1950 | - : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN; |
|
| 1951 | - // loop through REG_ID's and change status |
|
| 1952 | - foreach ($REG_IDs as $REG_ID) { |
|
| 1953 | - $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 1954 | - if ($registration instanceof EE_Registration) { |
|
| 1955 | - $registration->set_status( |
|
| 1956 | - $status, |
|
| 1957 | - false, |
|
| 1958 | - new Context( |
|
| 1959 | - $status_context, |
|
| 1960 | - esc_html__( |
|
| 1961 | - 'Manually triggered status change on a Registration Admin Page route.', |
|
| 1962 | - 'event_espresso' |
|
| 1963 | - ) |
|
| 1964 | - ) |
|
| 1965 | - ); |
|
| 1966 | - $result = $registration->save(); |
|
| 1967 | - // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
| 1968 | - $success = $result !== false ? $success : false; |
|
| 1969 | - } |
|
| 1970 | - } |
|
| 1971 | - } |
|
| 1972 | - |
|
| 1973 | - // return $success and processed registrations |
|
| 1974 | - return array('REG_ID' => $REG_IDs, 'success' => $success); |
|
| 1975 | - } |
|
| 1976 | - |
|
| 1977 | - |
|
| 1978 | - /** |
|
| 1979 | - * Common logic for setting up success message and redirecting to appropriate route |
|
| 1980 | - * |
|
| 1981 | - * @param string $STS_ID status id for the registration changed to |
|
| 1982 | - * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
| 1983 | - * @return void |
|
| 1984 | - * @throws EE_Error |
|
| 1985 | - */ |
|
| 1986 | - protected function _reg_status_change_return($STS_ID, $notify = false) |
|
| 1987 | - { |
|
| 1988 | - $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
| 1989 | - : array('success' => false); |
|
| 1990 | - $success = isset($result['success']) && $result['success']; |
|
| 1991 | - // setup success message |
|
| 1992 | - if ($success) { |
|
| 1993 | - if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
| 1994 | - $msg = sprintf( |
|
| 1995 | - esc_html__('Registration status has been set to %s', 'event_espresso'), |
|
| 1996 | - EEH_Template::pretty_status($STS_ID, false, 'lower') |
|
| 1997 | - ); |
|
| 1998 | - } else { |
|
| 1999 | - $msg = sprintf( |
|
| 2000 | - esc_html__('Registrations have been set to %s.', 'event_espresso'), |
|
| 2001 | - EEH_Template::pretty_status($STS_ID, false, 'lower') |
|
| 2002 | - ); |
|
| 2003 | - } |
|
| 2004 | - EE_Error::add_success($msg); |
|
| 2005 | - } else { |
|
| 2006 | - EE_Error::add_error( |
|
| 2007 | - esc_html__( |
|
| 2008 | - 'Something went wrong, and the status was not changed', |
|
| 2009 | - 'event_espresso' |
|
| 2010 | - ), |
|
| 2011 | - __FILE__, |
|
| 2012 | - __LINE__, |
|
| 2013 | - __FUNCTION__ |
|
| 2014 | - ); |
|
| 2015 | - } |
|
| 2016 | - if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') { |
|
| 2017 | - $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
|
| 2018 | - } else { |
|
| 2019 | - $route = array('action' => 'default'); |
|
| 2020 | - } |
|
| 2021 | - $route = $this->mergeExistingRequestParamsWithRedirectArgs($route); |
|
| 2022 | - $this->_redirect_after_action($success, '', '', $route, true); |
|
| 2023 | - } |
|
| 2024 | - |
|
| 2025 | - |
|
| 2026 | - /** |
|
| 2027 | - * incoming reg status change from reg details page. |
|
| 2028 | - * |
|
| 2029 | - * @return void |
|
| 2030 | - */ |
|
| 2031 | - protected function _change_reg_status() |
|
| 2032 | - { |
|
| 2033 | - $this->_req_data['return'] = 'view_registration'; |
|
| 2034 | - // set notify based on whether the send notifications toggle is set or not |
|
| 2035 | - $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
|
| 2036 | - // $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
|
| 2037 | - $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
|
| 2038 | - ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
|
| 2039 | - switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
|
| 2040 | - case EEM_Registration::status_id_approved: |
|
| 2041 | - case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'): |
|
| 2042 | - $this->approve_registration($notify); |
|
| 2043 | - break; |
|
| 2044 | - case EEM_Registration::status_id_pending_payment: |
|
| 2045 | - case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'): |
|
| 2046 | - $this->pending_registration($notify); |
|
| 2047 | - break; |
|
| 2048 | - case EEM_Registration::status_id_not_approved: |
|
| 2049 | - case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'): |
|
| 2050 | - $this->not_approve_registration($notify); |
|
| 2051 | - break; |
|
| 2052 | - case EEM_Registration::status_id_declined: |
|
| 2053 | - case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'): |
|
| 2054 | - $this->decline_registration($notify); |
|
| 2055 | - break; |
|
| 2056 | - case EEM_Registration::status_id_cancelled: |
|
| 2057 | - case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'): |
|
| 2058 | - $this->cancel_registration($notify); |
|
| 2059 | - break; |
|
| 2060 | - case EEM_Registration::status_id_wait_list: |
|
| 2061 | - case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'): |
|
| 2062 | - $this->wait_list_registration($notify); |
|
| 2063 | - break; |
|
| 2064 | - case EEM_Registration::status_id_incomplete: |
|
| 2065 | - default: |
|
| 2066 | - $result['success'] = false; |
|
| 2067 | - unset($this->_req_data['return']); |
|
| 2068 | - $this->_reg_status_change_return('', false); |
|
| 2069 | - break; |
|
| 2070 | - } |
|
| 2071 | - } |
|
| 2072 | - |
|
| 2073 | - |
|
| 2074 | - /** |
|
| 2075 | - * Callback for bulk action routes. |
|
| 2076 | - * Note: although we could just register the singular route callbacks for each bulk action route as well, this |
|
| 2077 | - * method was chosen so there is one central place all the registration status bulk actions are going through. |
|
| 2078 | - * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to |
|
| 2079 | - * when an action is happening on just a single registration). |
|
| 2080 | - * |
|
| 2081 | - * @param $action |
|
| 2082 | - * @param bool $notify |
|
| 2083 | - */ |
|
| 2084 | - protected function bulk_action_on_registrations($action, $notify = false) |
|
| 2085 | - { |
|
| 2086 | - do_action( |
|
| 2087 | - 'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution', |
|
| 2088 | - $this, |
|
| 2089 | - $action, |
|
| 2090 | - $notify |
|
| 2091 | - ); |
|
| 2092 | - $method = $action . '_registration'; |
|
| 2093 | - if (method_exists($this, $method)) { |
|
| 2094 | - $this->$method($notify); |
|
| 2095 | - } |
|
| 2096 | - } |
|
| 2097 | - |
|
| 2098 | - |
|
| 2099 | - /** |
|
| 2100 | - * approve_registration |
|
| 2101 | - * |
|
| 2102 | - * @access protected |
|
| 2103 | - * @param bool $notify whether or not to notify the registrant about their approval. |
|
| 2104 | - * @return void |
|
| 2105 | - */ |
|
| 2106 | - protected function approve_registration($notify = false) |
|
| 2107 | - { |
|
| 2108 | - $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
| 2109 | - } |
|
| 2110 | - |
|
| 2111 | - |
|
| 2112 | - /** |
|
| 2113 | - * decline_registration |
|
| 2114 | - * |
|
| 2115 | - * @access protected |
|
| 2116 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 2117 | - * @return void |
|
| 2118 | - */ |
|
| 2119 | - protected function decline_registration($notify = false) |
|
| 2120 | - { |
|
| 2121 | - $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
| 2122 | - } |
|
| 2123 | - |
|
| 2124 | - |
|
| 2125 | - /** |
|
| 2126 | - * cancel_registration |
|
| 2127 | - * |
|
| 2128 | - * @access protected |
|
| 2129 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 2130 | - * @return void |
|
| 2131 | - */ |
|
| 2132 | - protected function cancel_registration($notify = false) |
|
| 2133 | - { |
|
| 2134 | - $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
| 2135 | - } |
|
| 2136 | - |
|
| 2137 | - |
|
| 2138 | - /** |
|
| 2139 | - * not_approve_registration |
|
| 2140 | - * |
|
| 2141 | - * @access protected |
|
| 2142 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 2143 | - * @return void |
|
| 2144 | - */ |
|
| 2145 | - protected function not_approve_registration($notify = false) |
|
| 2146 | - { |
|
| 2147 | - $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
| 2148 | - } |
|
| 2149 | - |
|
| 2150 | - |
|
| 2151 | - /** |
|
| 2152 | - * decline_registration |
|
| 2153 | - * |
|
| 2154 | - * @access protected |
|
| 2155 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 2156 | - * @return void |
|
| 2157 | - */ |
|
| 2158 | - protected function pending_registration($notify = false) |
|
| 2159 | - { |
|
| 2160 | - $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
| 2161 | - } |
|
| 2162 | - |
|
| 2163 | - |
|
| 2164 | - /** |
|
| 2165 | - * waitlist_registration |
|
| 2166 | - * |
|
| 2167 | - * @access protected |
|
| 2168 | - * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 2169 | - * @return void |
|
| 2170 | - */ |
|
| 2171 | - protected function wait_list_registration($notify = false) |
|
| 2172 | - { |
|
| 2173 | - $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
| 2174 | - } |
|
| 2175 | - |
|
| 2176 | - |
|
| 2177 | - /** |
|
| 2178 | - * generates HTML for the Registration main meta box |
|
| 2179 | - * |
|
| 2180 | - * @access public |
|
| 2181 | - * @return void |
|
| 2182 | - * @throws DomainException |
|
| 2183 | - * @throws EE_Error |
|
| 2184 | - * @throws InvalidArgumentException |
|
| 2185 | - * @throws InvalidDataTypeException |
|
| 2186 | - * @throws InvalidInterfaceException |
|
| 2187 | - * @throws ReflectionException |
|
| 2188 | - * @throws EntityNotFoundException |
|
| 2189 | - */ |
|
| 2190 | - public function _reg_details_meta_box() |
|
| 2191 | - { |
|
| 2192 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 2193 | - EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 2194 | - EE_Registry::instance()->load_helper('Line_Item'); |
|
| 2195 | - $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 2196 | - : EE_Transaction::new_instance(); |
|
| 2197 | - $this->_session = $transaction->session_data(); |
|
| 2198 | - $filters = new EE_Line_Item_Filter_Collection(); |
|
| 2199 | - $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
| 2200 | - $filters->add(new EE_Non_Zero_Line_Item_Filter()); |
|
| 2201 | - $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
| 2202 | - $filters, |
|
| 2203 | - $transaction->total_line_item() |
|
| 2204 | - ); |
|
| 2205 | - $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 2206 | - $line_item_display = new EE_Line_Item_Display( |
|
| 2207 | - 'reg_admin_table', |
|
| 2208 | - 'EE_Admin_Table_Registration_Line_Item_Display_Strategy' |
|
| 2209 | - ); |
|
| 2210 | - $this->_template_args['line_item_table'] = $line_item_display->display_line_item( |
|
| 2211 | - $filtered_line_item_tree, |
|
| 2212 | - array('EE_Registration' => $this->_registration) |
|
| 2213 | - ); |
|
| 2214 | - $attendee = $this->_registration->attendee(); |
|
| 2215 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 2216 | - 'ee_read_transaction', |
|
| 2217 | - 'espresso_transactions_view_transaction' |
|
| 2218 | - )) { |
|
| 2219 | - $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link( |
|
| 2220 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 2221 | - array( |
|
| 2222 | - 'action' => 'view_transaction', |
|
| 2223 | - 'TXN_ID' => $transaction->ID(), |
|
| 2224 | - ), |
|
| 2225 | - TXN_ADMIN_URL |
|
| 2226 | - ), |
|
| 2227 | - esc_html__(' View Transaction', 'event_espresso'), |
|
| 2228 | - 'button secondary-button right', |
|
| 2229 | - 'dashicons dashicons-cart' |
|
| 2230 | - ); |
|
| 2231 | - } else { |
|
| 2232 | - $this->_template_args['view_transaction_button'] = ''; |
|
| 2233 | - } |
|
| 2234 | - if ($attendee instanceof EE_Attendee |
|
| 2235 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 2236 | - 'ee_send_message', |
|
| 2237 | - 'espresso_registrations_resend_registration' |
|
| 2238 | - ) |
|
| 2239 | - ) { |
|
| 2240 | - $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link( |
|
| 2241 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 2242 | - array( |
|
| 2243 | - 'action' => 'resend_registration', |
|
| 2244 | - '_REG_ID' => $this->_registration->ID(), |
|
| 2245 | - 'redirect_to' => 'view_registration', |
|
| 2246 | - ), |
|
| 2247 | - REG_ADMIN_URL |
|
| 2248 | - ), |
|
| 2249 | - esc_html__(' Resend Registration', 'event_espresso'), |
|
| 2250 | - 'button secondary-button right', |
|
| 2251 | - 'dashicons dashicons-email-alt' |
|
| 2252 | - ); |
|
| 2253 | - } else { |
|
| 2254 | - $this->_template_args['resend_registration_button'] = ''; |
|
| 2255 | - } |
|
| 2256 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2257 | - $payment = $transaction->get_first_related('Payment'); |
|
| 2258 | - $payment = ! $payment instanceof EE_Payment |
|
| 2259 | - ? EE_Payment::new_instance() |
|
| 2260 | - : $payment; |
|
| 2261 | - $payment_method = $payment->get_first_related('Payment_Method'); |
|
| 2262 | - $payment_method = ! $payment_method instanceof EE_Payment_Method |
|
| 2263 | - ? EE_Payment_Method::new_instance() |
|
| 2264 | - : $payment_method; |
|
| 2265 | - $reg_details = array( |
|
| 2266 | - 'payment_method' => $payment_method->name(), |
|
| 2267 | - 'response_msg' => $payment->gateway_response(), |
|
| 2268 | - 'registration_id' => $this->_registration->get('REG_code'), |
|
| 2269 | - 'registration_session' => $this->_registration->session_ID(), |
|
| 2270 | - 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
| 2271 | - 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
| 2272 | - ); |
|
| 2273 | - if (isset($reg_details['registration_id'])) { |
|
| 2274 | - $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
| 2275 | - $this->_template_args['reg_details']['registration_id']['label'] = esc_html__( |
|
| 2276 | - 'Registration ID', |
|
| 2277 | - 'event_espresso' |
|
| 2278 | - ); |
|
| 2279 | - $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
| 2280 | - } |
|
| 2281 | - if (isset($reg_details['payment_method'])) { |
|
| 2282 | - $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
| 2283 | - $this->_template_args['reg_details']['payment_method']['label'] = esc_html__( |
|
| 2284 | - 'Most Recent Payment Method', |
|
| 2285 | - 'event_espresso' |
|
| 2286 | - ); |
|
| 2287 | - $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
| 2288 | - $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
| 2289 | - $this->_template_args['reg_details']['response_msg']['label'] = esc_html__( |
|
| 2290 | - 'Payment method response', |
|
| 2291 | - 'event_espresso' |
|
| 2292 | - ); |
|
| 2293 | - $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 2294 | - } |
|
| 2295 | - $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
| 2296 | - $this->_template_args['reg_details']['registration_session']['label'] = esc_html__( |
|
| 2297 | - 'Registration Session', |
|
| 2298 | - 'event_espresso' |
|
| 2299 | - ); |
|
| 2300 | - $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
| 2301 | - $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
| 2302 | - $this->_template_args['reg_details']['ip_address']['label'] = esc_html__( |
|
| 2303 | - 'Registration placed from IP', |
|
| 2304 | - 'event_espresso' |
|
| 2305 | - ); |
|
| 2306 | - $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
| 2307 | - $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
| 2308 | - $this->_template_args['reg_details']['user_agent']['label'] = esc_html__( |
|
| 2309 | - 'Registrant User Agent', |
|
| 2310 | - 'event_espresso' |
|
| 2311 | - ); |
|
| 2312 | - $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
| 2313 | - $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2314 | - array( |
|
| 2315 | - 'action' => 'default', |
|
| 2316 | - 'event_id' => $this->_registration->event_ID(), |
|
| 2317 | - ), |
|
| 2318 | - REG_ADMIN_URL |
|
| 2319 | - ); |
|
| 2320 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2321 | - $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
| 2322 | - $template_path = |
|
| 2323 | - REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 2324 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2325 | - } |
|
| 2326 | - |
|
| 2327 | - |
|
| 2328 | - /** |
|
| 2329 | - * generates HTML for the Registration Questions meta box. |
|
| 2330 | - * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
| 2331 | - * otherwise uses new forms system |
|
| 2332 | - * |
|
| 2333 | - * @access public |
|
| 2334 | - * @return void |
|
| 2335 | - * @throws DomainException |
|
| 2336 | - * @throws EE_Error |
|
| 2337 | - */ |
|
| 2338 | - public function _reg_questions_meta_box() |
|
| 2339 | - { |
|
| 2340 | - // allow someone to override this method entirely |
|
| 2341 | - if (apply_filters( |
|
| 2342 | - 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', |
|
| 2343 | - true, |
|
| 2344 | - $this, |
|
| 2345 | - $this->_registration |
|
| 2346 | - )) { |
|
| 2347 | - $form = $this->_get_reg_custom_questions_form( |
|
| 2348 | - $this->_registration->ID() |
|
| 2349 | - ); |
|
| 2350 | - $this->_template_args['att_questions'] = count($form->subforms()) > 0 |
|
| 2351 | - ? $form->get_html_and_js() |
|
| 2352 | - : ''; |
|
| 2353 | - $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
| 2354 | - $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2355 | - $template_path = |
|
| 2356 | - REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 2357 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2358 | - } |
|
| 2359 | - } |
|
| 2360 | - |
|
| 2361 | - |
|
| 2362 | - /** |
|
| 2363 | - * form_before_question_group |
|
| 2364 | - * |
|
| 2365 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2366 | - * @access public |
|
| 2367 | - * @param string $output |
|
| 2368 | - * @return string |
|
| 2369 | - */ |
|
| 2370 | - public function form_before_question_group($output) |
|
| 2371 | - { |
|
| 2372 | - EE_Error::doing_it_wrong( |
|
| 2373 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2374 | - esc_html__( |
|
| 2375 | - '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.', |
|
| 2376 | - 'event_espresso' |
|
| 2377 | - ), |
|
| 2378 | - '4.8.32.rc.000' |
|
| 2379 | - ); |
|
| 2380 | - return ' |
|
| 1302 | + if (! empty($registration_status)) { |
|
| 1303 | + $where['STS_ID'] = $registration_status; |
|
| 1304 | + } else { |
|
| 1305 | + // make sure we exclude incomplete registrations, but only if not trashed. |
|
| 1306 | + if ($view === 'trash') { |
|
| 1307 | + $where['REG_deleted'] = true; |
|
| 1308 | + } elseif ($view === 'incomplete') { |
|
| 1309 | + $where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
| 1310 | + } else { |
|
| 1311 | + $where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1314 | + return $where; |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + |
|
| 1318 | + /** |
|
| 1319 | + * Adds any provided date restraints to the where conditions for the registrations query. |
|
| 1320 | + * |
|
| 1321 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1322 | + * @return array |
|
| 1323 | + * @throws EE_Error |
|
| 1324 | + * @throws InvalidArgumentException |
|
| 1325 | + * @throws InvalidDataTypeException |
|
| 1326 | + * @throws InvalidInterfaceException |
|
| 1327 | + */ |
|
| 1328 | + protected function _add_date_to_where_conditions(array $request) |
|
| 1329 | + { |
|
| 1330 | + $where = array(); |
|
| 1331 | + $view = EEH_Array::is_set($request, 'status', ''); |
|
| 1332 | + $month_range = ! empty($request['month_range']) |
|
| 1333 | + ? sanitize_text_field($request['month_range']) |
|
| 1334 | + : ''; |
|
| 1335 | + $retrieve_for_today = $view === 'today'; |
|
| 1336 | + $retrieve_for_this_month = $view === 'month'; |
|
| 1337 | + |
|
| 1338 | + if ($retrieve_for_today) { |
|
| 1339 | + $now = date('Y-m-d', current_time('timestamp')); |
|
| 1340 | + $where['REG_date'] = array( |
|
| 1341 | + 'BETWEEN', |
|
| 1342 | + array( |
|
| 1343 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1344 | + 'REG_date', |
|
| 1345 | + $now . ' 00:00:00', |
|
| 1346 | + 'Y-m-d H:i:s' |
|
| 1347 | + ), |
|
| 1348 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1349 | + 'REG_date', |
|
| 1350 | + $now . ' 23:59:59', |
|
| 1351 | + 'Y-m-d H:i:s' |
|
| 1352 | + ), |
|
| 1353 | + ), |
|
| 1354 | + ); |
|
| 1355 | + } elseif ($retrieve_for_this_month) { |
|
| 1356 | + $current_year_and_month = date('Y-m', current_time('timestamp')); |
|
| 1357 | + $days_this_month = date('t', current_time('timestamp')); |
|
| 1358 | + $where['REG_date'] = array( |
|
| 1359 | + 'BETWEEN', |
|
| 1360 | + array( |
|
| 1361 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1362 | + 'REG_date', |
|
| 1363 | + $current_year_and_month . '-01 00:00:00', |
|
| 1364 | + 'Y-m-d H:i:s' |
|
| 1365 | + ), |
|
| 1366 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1367 | + 'REG_date', |
|
| 1368 | + $current_year_and_month . '-' . $days_this_month . ' 23:59:59', |
|
| 1369 | + 'Y-m-d H:i:s' |
|
| 1370 | + ), |
|
| 1371 | + ), |
|
| 1372 | + ); |
|
| 1373 | + } elseif ($month_range) { |
|
| 1374 | + $pieces = explode(' ', $month_range, 3); |
|
| 1375 | + $month_requested = ! empty($pieces[0]) |
|
| 1376 | + ? date('m', \EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) |
|
| 1377 | + : ''; |
|
| 1378 | + $year_requested = ! empty($pieces[1]) |
|
| 1379 | + ? $pieces[1] |
|
| 1380 | + : ''; |
|
| 1381 | + // if there is not a month or year then we can't go further |
|
| 1382 | + if ($month_requested && $year_requested) { |
|
| 1383 | + $days_in_month = date('t', strtotime($year_requested . '-' . $month_requested . '-' . '01')); |
|
| 1384 | + $where['REG_date'] = array( |
|
| 1385 | + 'BETWEEN', |
|
| 1386 | + array( |
|
| 1387 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1388 | + 'REG_date', |
|
| 1389 | + $year_requested . '-' . $month_requested . '-01 00:00:00', |
|
| 1390 | + 'Y-m-d H:i:s' |
|
| 1391 | + ), |
|
| 1392 | + EEM_Registration::instance()->convert_datetime_for_query( |
|
| 1393 | + 'REG_date', |
|
| 1394 | + $year_requested . '-' . $month_requested . '-' . $days_in_month . ' 23:59:59', |
|
| 1395 | + 'Y-m-d H:i:s' |
|
| 1396 | + ), |
|
| 1397 | + ), |
|
| 1398 | + ); |
|
| 1399 | + } |
|
| 1400 | + } |
|
| 1401 | + return $where; |
|
| 1402 | + } |
|
| 1403 | + |
|
| 1404 | + |
|
| 1405 | + /** |
|
| 1406 | + * Adds any provided search restraints to the where conditions for the registrations query |
|
| 1407 | + * |
|
| 1408 | + * @param array $request usually the same as $this->_req_data but not necessarily |
|
| 1409 | + * @return array |
|
| 1410 | + */ |
|
| 1411 | + protected function _add_search_to_where_conditions(array $request) |
|
| 1412 | + { |
|
| 1413 | + $where = array(); |
|
| 1414 | + if (! empty($request['s'])) { |
|
| 1415 | + $search_string = '%' . sanitize_text_field($request['s']) . '%'; |
|
| 1416 | + $where['OR*search_conditions'] = array( |
|
| 1417 | + 'Event.EVT_name' => array('LIKE', $search_string), |
|
| 1418 | + 'Event.EVT_desc' => array('LIKE', $search_string), |
|
| 1419 | + 'Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 1420 | + 'Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 1421 | + 'Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 1422 | + 'Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 1423 | + 'Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 1424 | + 'Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 1425 | + 'Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 1426 | + 'Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 1427 | + 'Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 1428 | + 'REG_final_price' => array('LIKE', $search_string), |
|
| 1429 | + 'REG_code' => array('LIKE', $search_string), |
|
| 1430 | + 'REG_count' => array('LIKE', $search_string), |
|
| 1431 | + 'REG_group_size' => array('LIKE', $search_string), |
|
| 1432 | + 'Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 1433 | + 'Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 1434 | + 'Transaction.Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 1435 | + ); |
|
| 1436 | + } |
|
| 1437 | + return $where; |
|
| 1438 | + } |
|
| 1439 | + |
|
| 1440 | + |
|
| 1441 | + /** |
|
| 1442 | + * Sets up the where conditions for the registrations query. |
|
| 1443 | + * |
|
| 1444 | + * @param array $request |
|
| 1445 | + * @return array |
|
| 1446 | + * @throws EE_Error |
|
| 1447 | + */ |
|
| 1448 | + protected function _get_where_conditions_for_registrations_query($request) |
|
| 1449 | + { |
|
| 1450 | + return apply_filters( |
|
| 1451 | + 'FHEE__Registrations_Admin_Page___get_where_conditions_for_registrations_query', |
|
| 1452 | + array_merge( |
|
| 1453 | + $this->addAttendeeIdToWhereConditions($request), |
|
| 1454 | + $this->_add_event_id_to_where_conditions($request), |
|
| 1455 | + $this->_add_category_id_to_where_conditions($request), |
|
| 1456 | + $this->_add_datetime_id_to_where_conditions($request), |
|
| 1457 | + $this->_add_registration_status_to_where_conditions($request), |
|
| 1458 | + $this->_add_date_to_where_conditions($request), |
|
| 1459 | + $this->_add_search_to_where_conditions($request) |
|
| 1460 | + ), |
|
| 1461 | + $request |
|
| 1462 | + ); |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + |
|
| 1466 | + /** |
|
| 1467 | + * Sets up the orderby for the registrations query. |
|
| 1468 | + * |
|
| 1469 | + * @return array |
|
| 1470 | + */ |
|
| 1471 | + protected function _get_orderby_for_registrations_query() |
|
| 1472 | + { |
|
| 1473 | + $orderby_field = ! empty($this->_req_data['orderby']) |
|
| 1474 | + ? sanitize_text_field($this->_req_data['orderby']) |
|
| 1475 | + : '_REG_date'; |
|
| 1476 | + switch ($orderby_field) { |
|
| 1477 | + case '_REG_ID': |
|
| 1478 | + $orderby = array('REG_ID'); |
|
| 1479 | + break; |
|
| 1480 | + case '_Reg_status': |
|
| 1481 | + $orderby = array('STS_ID'); |
|
| 1482 | + break; |
|
| 1483 | + case 'ATT_fname': |
|
| 1484 | + $orderby = array('Attendee.ATT_fname', 'Attendee.ATT_lname'); |
|
| 1485 | + break; |
|
| 1486 | + case 'ATT_lname': |
|
| 1487 | + $orderby = array('Attendee.ATT_lname', 'Attendee.ATT_fname'); |
|
| 1488 | + break; |
|
| 1489 | + case 'event_name': |
|
| 1490 | + $orderby = array('Event.EVT_name'); |
|
| 1491 | + break; |
|
| 1492 | + case 'DTT_EVT_start': |
|
| 1493 | + $orderby = array('Event.Datetime.DTT_EVT_start'); |
|
| 1494 | + break; |
|
| 1495 | + case '_REG_date': |
|
| 1496 | + $orderby = array('REG_date'); |
|
| 1497 | + break; |
|
| 1498 | + default: |
|
| 1499 | + $orderby = array($orderby_field); |
|
| 1500 | + break; |
|
| 1501 | + } |
|
| 1502 | + |
|
| 1503 | + // order |
|
| 1504 | + $order = ! empty($this->_req_data['order']) |
|
| 1505 | + ? sanitize_text_field($this->_req_data['order']) |
|
| 1506 | + : 'DESC'; |
|
| 1507 | + $orderby = array_combine( |
|
| 1508 | + $orderby, |
|
| 1509 | + array_fill(0, count($orderby), $order) |
|
| 1510 | + ); |
|
| 1511 | + // because there are many registrations with the same date, define |
|
| 1512 | + // a secondary way to order them, otherwise MySQL seems to be a bit random |
|
| 1513 | + if (empty($orderby['REG_ID'])) { |
|
| 1514 | + $orderby['REG_ID'] = $order; |
|
| 1515 | + } |
|
| 1516 | + |
|
| 1517 | + $orderby = apply_filters( |
|
| 1518 | + 'FHEE__Registrations_Admin_Page___get_orderby_for_registrations_query', |
|
| 1519 | + $orderby, |
|
| 1520 | + $this->_req_data |
|
| 1521 | + ); |
|
| 1522 | + |
|
| 1523 | + return array('order_by' => $orderby); |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + |
|
| 1527 | + /** |
|
| 1528 | + * Sets up the limit for the registrations query. |
|
| 1529 | + * |
|
| 1530 | + * @param $per_page |
|
| 1531 | + * @return array |
|
| 1532 | + */ |
|
| 1533 | + protected function _get_limit($per_page) |
|
| 1534 | + { |
|
| 1535 | + $current_page = ! empty($this->_req_data['paged']) |
|
| 1536 | + ? absint($this->_req_data['paged']) |
|
| 1537 | + : 1; |
|
| 1538 | + $per_page = ! empty($this->_req_data['perpage']) |
|
| 1539 | + ? $this->_req_data['perpage'] |
|
| 1540 | + : $per_page; |
|
| 1541 | + |
|
| 1542 | + // -1 means return all results so get out if that's set. |
|
| 1543 | + if ((int) $per_page === -1) { |
|
| 1544 | + return array(); |
|
| 1545 | + } |
|
| 1546 | + $per_page = absint($per_page); |
|
| 1547 | + $offset = ($current_page - 1) * $per_page; |
|
| 1548 | + return array('limit' => array($offset, $per_page)); |
|
| 1549 | + } |
|
| 1550 | + |
|
| 1551 | + |
|
| 1552 | + public function get_registration_status_array() |
|
| 1553 | + { |
|
| 1554 | + return self::$_reg_status; |
|
| 1555 | + } |
|
| 1556 | + |
|
| 1557 | + |
|
| 1558 | + |
|
| 1559 | + |
|
| 1560 | + /*************************************** REGISTRATION DETAILS ***************************************/ |
|
| 1561 | + /** |
|
| 1562 | + * generates HTML for the View Registration Details Admin page |
|
| 1563 | + * |
|
| 1564 | + * @access protected |
|
| 1565 | + * @return void |
|
| 1566 | + * @throws DomainException |
|
| 1567 | + * @throws EE_Error |
|
| 1568 | + * @throws InvalidArgumentException |
|
| 1569 | + * @throws InvalidDataTypeException |
|
| 1570 | + * @throws InvalidInterfaceException |
|
| 1571 | + * @throws EntityNotFoundException |
|
| 1572 | + */ |
|
| 1573 | + protected function _registration_details() |
|
| 1574 | + { |
|
| 1575 | + $this->_template_args = array(); |
|
| 1576 | + $this->_set_registration_object(); |
|
| 1577 | + if (is_object($this->_registration)) { |
|
| 1578 | + $transaction = $this->_registration->transaction() |
|
| 1579 | + ? $this->_registration->transaction() |
|
| 1580 | + : EE_Transaction::new_instance(); |
|
| 1581 | + $this->_session = $transaction->session_data(); |
|
| 1582 | + $event_id = $this->_registration->event_ID(); |
|
| 1583 | + $this->_template_args['reg_nmbr']['value'] = $this->_registration->ID(); |
|
| 1584 | + $this->_template_args['reg_nmbr']['label'] = esc_html__('Registration Number', 'event_espresso'); |
|
| 1585 | + $this->_template_args['reg_datetime']['value'] = $this->_registration->get_i18n_datetime('REG_date'); |
|
| 1586 | + $this->_template_args['reg_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 1587 | + $this->_template_args['grand_total'] = $transaction->total(); |
|
| 1588 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 1589 | + // link back to overview |
|
| 1590 | + $this->_template_args['reg_overview_url'] = REG_ADMIN_URL; |
|
| 1591 | + $this->_template_args['registration'] = $this->_registration; |
|
| 1592 | + $this->_template_args['filtered_registrations_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1593 | + array( |
|
| 1594 | + 'action' => 'default', |
|
| 1595 | + 'event_id' => $event_id, |
|
| 1596 | + ), |
|
| 1597 | + REG_ADMIN_URL |
|
| 1598 | + ); |
|
| 1599 | + $this->_template_args['filtered_transactions_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1600 | + array( |
|
| 1601 | + 'action' => 'default', |
|
| 1602 | + 'EVT_ID' => $event_id, |
|
| 1603 | + 'page' => 'espresso_transactions', |
|
| 1604 | + ), |
|
| 1605 | + admin_url('admin.php') |
|
| 1606 | + ); |
|
| 1607 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1608 | + array( |
|
| 1609 | + 'page' => 'espresso_events', |
|
| 1610 | + 'action' => 'edit', |
|
| 1611 | + 'post' => $event_id, |
|
| 1612 | + ), |
|
| 1613 | + admin_url('admin.php') |
|
| 1614 | + ); |
|
| 1615 | + // next and previous links |
|
| 1616 | + $next_reg = $this->_registration->next( |
|
| 1617 | + null, |
|
| 1618 | + array(), |
|
| 1619 | + 'REG_ID' |
|
| 1620 | + ); |
|
| 1621 | + $this->_template_args['next_registration'] = $next_reg |
|
| 1622 | + ? $this->_next_link( |
|
| 1623 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 1624 | + array( |
|
| 1625 | + 'action' => 'view_registration', |
|
| 1626 | + '_REG_ID' => $next_reg['REG_ID'], |
|
| 1627 | + ), |
|
| 1628 | + REG_ADMIN_URL |
|
| 1629 | + ), |
|
| 1630 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 1631 | + ) |
|
| 1632 | + : ''; |
|
| 1633 | + $previous_reg = $this->_registration->previous( |
|
| 1634 | + null, |
|
| 1635 | + array(), |
|
| 1636 | + 'REG_ID' |
|
| 1637 | + ); |
|
| 1638 | + $this->_template_args['previous_registration'] = $previous_reg |
|
| 1639 | + ? $this->_previous_link( |
|
| 1640 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 1641 | + array( |
|
| 1642 | + 'action' => 'view_registration', |
|
| 1643 | + '_REG_ID' => $previous_reg['REG_ID'], |
|
| 1644 | + ), |
|
| 1645 | + REG_ADMIN_URL |
|
| 1646 | + ), |
|
| 1647 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 1648 | + ) |
|
| 1649 | + : ''; |
|
| 1650 | + // grab header |
|
| 1651 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_header.template.php'; |
|
| 1652 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 1653 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 1654 | + $template_path, |
|
| 1655 | + $this->_template_args, |
|
| 1656 | + true |
|
| 1657 | + ); |
|
| 1658 | + } else { |
|
| 1659 | + $this->_template_args['admin_page_header'] = $this->display_espresso_notices(); |
|
| 1660 | + } |
|
| 1661 | + // the details template wrapper |
|
| 1662 | + $this->display_admin_page_with_sidebar(); |
|
| 1663 | + } |
|
| 1664 | + |
|
| 1665 | + |
|
| 1666 | + protected function _registration_details_metaboxes() |
|
| 1667 | + { |
|
| 1668 | + do_action('AHEE__Registrations_Admin_Page___registration_details_metabox__start', $this); |
|
| 1669 | + $this->_set_registration_object(); |
|
| 1670 | + $attendee = $this->_registration instanceof EE_Registration ? $this->_registration->attendee() : null; |
|
| 1671 | + add_meta_box( |
|
| 1672 | + 'edit-reg-status-mbox', |
|
| 1673 | + esc_html__('Registration Status', 'event_espresso'), |
|
| 1674 | + array($this, 'set_reg_status_buttons_metabox'), |
|
| 1675 | + $this->wp_page_slug, |
|
| 1676 | + 'normal', |
|
| 1677 | + 'high' |
|
| 1678 | + ); |
|
| 1679 | + add_meta_box( |
|
| 1680 | + 'edit-reg-details-mbox', |
|
| 1681 | + esc_html__('Registration Details', 'event_espresso'), |
|
| 1682 | + array($this, '_reg_details_meta_box'), |
|
| 1683 | + $this->wp_page_slug, |
|
| 1684 | + 'normal', |
|
| 1685 | + 'high' |
|
| 1686 | + ); |
|
| 1687 | + if ($attendee instanceof EE_Attendee |
|
| 1688 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 1689 | + 'ee_read_registration', |
|
| 1690 | + 'edit-reg-questions-mbox', |
|
| 1691 | + $this->_registration->ID() |
|
| 1692 | + ) |
|
| 1693 | + ) { |
|
| 1694 | + add_meta_box( |
|
| 1695 | + 'edit-reg-questions-mbox', |
|
| 1696 | + esc_html__('Registration Form Answers', 'event_espresso'), |
|
| 1697 | + array($this, '_reg_questions_meta_box'), |
|
| 1698 | + $this->wp_page_slug, |
|
| 1699 | + 'normal', |
|
| 1700 | + 'high' |
|
| 1701 | + ); |
|
| 1702 | + } |
|
| 1703 | + add_meta_box( |
|
| 1704 | + 'edit-reg-registrant-mbox', |
|
| 1705 | + esc_html__('Contact Details', 'event_espresso'), |
|
| 1706 | + array($this, '_reg_registrant_side_meta_box'), |
|
| 1707 | + $this->wp_page_slug, |
|
| 1708 | + 'side', |
|
| 1709 | + 'high' |
|
| 1710 | + ); |
|
| 1711 | + if ($this->_registration->group_size() > 1) { |
|
| 1712 | + add_meta_box( |
|
| 1713 | + 'edit-reg-attendees-mbox', |
|
| 1714 | + esc_html__('Other Registrations in this Transaction', 'event_espresso'), |
|
| 1715 | + array($this, '_reg_attendees_meta_box'), |
|
| 1716 | + $this->wp_page_slug, |
|
| 1717 | + 'normal', |
|
| 1718 | + 'high' |
|
| 1719 | + ); |
|
| 1720 | + } |
|
| 1721 | + } |
|
| 1722 | + |
|
| 1723 | + |
|
| 1724 | + /** |
|
| 1725 | + * set_reg_status_buttons_metabox |
|
| 1726 | + * |
|
| 1727 | + * @access protected |
|
| 1728 | + * @return string |
|
| 1729 | + * @throws \EE_Error |
|
| 1730 | + */ |
|
| 1731 | + public function set_reg_status_buttons_metabox() |
|
| 1732 | + { |
|
| 1733 | + $this->_set_registration_object(); |
|
| 1734 | + $change_reg_status_form = $this->_generate_reg_status_change_form(); |
|
| 1735 | + echo $change_reg_status_form->form_open( |
|
| 1736 | + self::add_query_args_and_nonce( |
|
| 1737 | + array( |
|
| 1738 | + 'action' => 'change_reg_status', |
|
| 1739 | + ), |
|
| 1740 | + REG_ADMIN_URL |
|
| 1741 | + ) |
|
| 1742 | + ); |
|
| 1743 | + echo $change_reg_status_form->get_html(); |
|
| 1744 | + echo $change_reg_status_form->form_close(); |
|
| 1745 | + } |
|
| 1746 | + |
|
| 1747 | + |
|
| 1748 | + /** |
|
| 1749 | + * @return EE_Form_Section_Proper |
|
| 1750 | + * @throws EE_Error |
|
| 1751 | + * @throws InvalidArgumentException |
|
| 1752 | + * @throws InvalidDataTypeException |
|
| 1753 | + * @throws InvalidInterfaceException |
|
| 1754 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 1755 | + */ |
|
| 1756 | + protected function _generate_reg_status_change_form() |
|
| 1757 | + { |
|
| 1758 | + $reg_status_change_form_array = array( |
|
| 1759 | + 'name' => 'reg_status_change_form', |
|
| 1760 | + 'html_id' => 'reg-status-change-form', |
|
| 1761 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
| 1762 | + 'subsections' => array( |
|
| 1763 | + 'return' => new EE_Hidden_Input( |
|
| 1764 | + array( |
|
| 1765 | + 'name' => 'return', |
|
| 1766 | + 'default' => 'view_registration', |
|
| 1767 | + ) |
|
| 1768 | + ), |
|
| 1769 | + 'REG_ID' => new EE_Hidden_Input( |
|
| 1770 | + array( |
|
| 1771 | + 'name' => 'REG_ID', |
|
| 1772 | + 'default' => $this->_registration->ID(), |
|
| 1773 | + ) |
|
| 1774 | + ), |
|
| 1775 | + 'current_status' => new EE_Form_Section_HTML( |
|
| 1776 | + EEH_HTML::table( |
|
| 1777 | + EEH_HTML::tr( |
|
| 1778 | + EEH_HTML::th( |
|
| 1779 | + EEH_HTML::label( |
|
| 1780 | + EEH_HTML::strong( |
|
| 1781 | + esc_html__('Current Registration Status', 'event_espresso') |
|
| 1782 | + ) |
|
| 1783 | + ) |
|
| 1784 | + ) |
|
| 1785 | + . EEH_HTML::td( |
|
| 1786 | + EEH_HTML::strong( |
|
| 1787 | + $this->_registration->pretty_status(), |
|
| 1788 | + '', |
|
| 1789 | + 'status-' . $this->_registration->status_ID(), |
|
| 1790 | + 'line-height: 1em; font-size: 1.5em; font-weight: bold;' |
|
| 1791 | + ) |
|
| 1792 | + ) |
|
| 1793 | + ) |
|
| 1794 | + ) |
|
| 1795 | + ) |
|
| 1796 | + ) |
|
| 1797 | + ); |
|
| 1798 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 1799 | + 'ee_edit_registration', |
|
| 1800 | + 'toggle_registration_status', |
|
| 1801 | + $this->_registration->ID() |
|
| 1802 | + )) { |
|
| 1803 | + $reg_status_change_form_array['subsections']['reg_status'] = new EE_Select_Input( |
|
| 1804 | + $this->_get_reg_statuses(), |
|
| 1805 | + array( |
|
| 1806 | + 'html_label_text' => esc_html__('Change Registration Status to', 'event_espresso'), |
|
| 1807 | + 'default' => $this->_registration->status_ID(), |
|
| 1808 | + ) |
|
| 1809 | + ); |
|
| 1810 | + $reg_status_change_form_array['subsections']['send_notifications'] = new EE_Yes_No_Input( |
|
| 1811 | + array( |
|
| 1812 | + 'html_label_text' => esc_html__('Send Related Messages', 'event_espresso'), |
|
| 1813 | + 'default' => false, |
|
| 1814 | + 'html_help_text' => esc_html__( |
|
| 1815 | + 'If set to "Yes", then the related messages will be sent to the registrant.', |
|
| 1816 | + 'event_espresso' |
|
| 1817 | + ) |
|
| 1818 | + ) |
|
| 1819 | + ); |
|
| 1820 | + $reg_status_change_form_array['subsections']['submit'] = new EE_Submit_Input( |
|
| 1821 | + array( |
|
| 1822 | + 'html_class' => 'button-primary', |
|
| 1823 | + 'html_label_text' => ' ', |
|
| 1824 | + 'default' => esc_html__('Update Registration Status', 'event_espresso'), |
|
| 1825 | + ) |
|
| 1826 | + ); |
|
| 1827 | + } |
|
| 1828 | + return new EE_Form_Section_Proper($reg_status_change_form_array); |
|
| 1829 | + } |
|
| 1830 | + |
|
| 1831 | + |
|
| 1832 | + /** |
|
| 1833 | + * Returns an array of all the buttons for the various statuses and switch status actions |
|
| 1834 | + * |
|
| 1835 | + * @return array |
|
| 1836 | + * @throws EE_Error |
|
| 1837 | + * @throws InvalidArgumentException |
|
| 1838 | + * @throws InvalidDataTypeException |
|
| 1839 | + * @throws InvalidInterfaceException |
|
| 1840 | + * @throws EntityNotFoundException |
|
| 1841 | + */ |
|
| 1842 | + protected function _get_reg_statuses() |
|
| 1843 | + { |
|
| 1844 | + $reg_status_array = EEM_Registration::instance()->reg_status_array(); |
|
| 1845 | + unset($reg_status_array[ EEM_Registration::status_id_incomplete ]); |
|
| 1846 | + // get current reg status |
|
| 1847 | + $current_status = $this->_registration->status_ID(); |
|
| 1848 | + // is registration for free event? This will determine whether to display the pending payment option |
|
| 1849 | + if ($current_status !== EEM_Registration::status_id_pending_payment |
|
| 1850 | + && EEH_Money::compare_floats($this->_registration->ticket()->price(), 0.00) |
|
| 1851 | + ) { |
|
| 1852 | + unset($reg_status_array[ EEM_Registration::status_id_pending_payment ]); |
|
| 1853 | + } |
|
| 1854 | + return EEM_Status::instance()->localized_status($reg_status_array, false, 'sentence'); |
|
| 1855 | + } |
|
| 1856 | + |
|
| 1857 | + |
|
| 1858 | + /** |
|
| 1859 | + * This method is used when using _REG_ID from request which may or may not be an array of reg_ids. |
|
| 1860 | + * |
|
| 1861 | + * @param bool $status REG status given for changing registrations to. |
|
| 1862 | + * @param bool $notify Whether to send messages notifications or not. |
|
| 1863 | + * @return array (array with reg_id(s) updated and whether update was successful. |
|
| 1864 | + * @throws EE_Error |
|
| 1865 | + * @throws InvalidArgumentException |
|
| 1866 | + * @throws InvalidDataTypeException |
|
| 1867 | + * @throws InvalidInterfaceException |
|
| 1868 | + * @throws ReflectionException |
|
| 1869 | + * @throws RuntimeException |
|
| 1870 | + * @throws EntityNotFoundException |
|
| 1871 | + */ |
|
| 1872 | + protected function _set_registration_status_from_request($status = false, $notify = false) |
|
| 1873 | + { |
|
| 1874 | + if (isset($this->_req_data['reg_status_change_form'])) { |
|
| 1875 | + $REG_IDs = isset($this->_req_data['reg_status_change_form']['REG_ID']) |
|
| 1876 | + ? (array) $this->_req_data['reg_status_change_form']['REG_ID'] |
|
| 1877 | + : array(); |
|
| 1878 | + } else { |
|
| 1879 | + $REG_IDs = isset($this->_req_data['_REG_ID']) |
|
| 1880 | + ? (array) $this->_req_data['_REG_ID'] |
|
| 1881 | + : array(); |
|
| 1882 | + } |
|
| 1883 | + // sanitize $REG_IDs |
|
| 1884 | + $REG_IDs = array_map('absint', $REG_IDs); |
|
| 1885 | + // and remove empty entries |
|
| 1886 | + $REG_IDs = array_filter($REG_IDs); |
|
| 1887 | + |
|
| 1888 | + $result = $this->_set_registration_status($REG_IDs, $status, $notify); |
|
| 1889 | + |
|
| 1890 | + /** |
|
| 1891 | + * Set and filter $_req_data['_REG_ID'] for any potential future messages notifications. |
|
| 1892 | + * Currently this value is used downstream by the _process_resend_registration method. |
|
| 1893 | + * |
|
| 1894 | + * @param int|array $registration_ids The registration ids that have had their status changed successfully. |
|
| 1895 | + * @param bool $status The status registrations were changed to. |
|
| 1896 | + * @param bool $success If the status was changed successfully for all registrations. |
|
| 1897 | + * @param Registrations_Admin_Page $admin_page_object |
|
| 1898 | + */ |
|
| 1899 | + $this->_req_data['_REG_ID'] = apply_filters( |
|
| 1900 | + 'FHEE__Registrations_Admin_Page___set_registration_status_from_request__REG_IDs', |
|
| 1901 | + $result['REG_ID'], |
|
| 1902 | + $status, |
|
| 1903 | + $result['success'], |
|
| 1904 | + $this |
|
| 1905 | + ); |
|
| 1906 | + |
|
| 1907 | + // notify? |
|
| 1908 | + if ($notify |
|
| 1909 | + && $result['success'] |
|
| 1910 | + && ! empty($this->_req_data['_REG_ID']) |
|
| 1911 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 1912 | + 'ee_send_message', |
|
| 1913 | + 'espresso_registrations_resend_registration' |
|
| 1914 | + ) |
|
| 1915 | + ) { |
|
| 1916 | + $this->_process_resend_registration(); |
|
| 1917 | + } |
|
| 1918 | + return $result; |
|
| 1919 | + } |
|
| 1920 | + |
|
| 1921 | + |
|
| 1922 | + /** |
|
| 1923 | + * Set the registration status for the given reg_id (which may or may not be an array, it gets typecast to an |
|
| 1924 | + * array). Note, this method does NOT take care of possible notifications. That is required by calling code. |
|
| 1925 | + * |
|
| 1926 | + * @param array $REG_IDs |
|
| 1927 | + * @param string $status |
|
| 1928 | + * @param bool $notify Used to indicate whether notification was requested or not. This determines the context |
|
| 1929 | + * slug sent with setting the registration status. |
|
| 1930 | + * @return array (an array with 'success' key representing whether status change was successful, and 'REG_ID' as |
|
| 1931 | + * @throws EE_Error |
|
| 1932 | + * @throws InvalidArgumentException |
|
| 1933 | + * @throws InvalidDataTypeException |
|
| 1934 | + * @throws InvalidInterfaceException |
|
| 1935 | + * @throws ReflectionException |
|
| 1936 | + * @throws RuntimeException |
|
| 1937 | + * @throws EntityNotFoundException |
|
| 1938 | + */ |
|
| 1939 | + protected function _set_registration_status($REG_IDs = array(), $status = '', $notify = false) |
|
| 1940 | + { |
|
| 1941 | + $success = false; |
|
| 1942 | + // typecast $REG_IDs |
|
| 1943 | + $REG_IDs = (array) $REG_IDs; |
|
| 1944 | + if (! empty($REG_IDs)) { |
|
| 1945 | + $success = true; |
|
| 1946 | + // set default status if none is passed |
|
| 1947 | + $status = $status ? $status : EEM_Registration::status_id_pending_payment; |
|
| 1948 | + $status_context = $notify |
|
| 1949 | + ? Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN_NOTIFY |
|
| 1950 | + : Domain::CONTEXT_REGISTRATION_STATUS_CHANGE_REGISTRATION_ADMIN; |
|
| 1951 | + // loop through REG_ID's and change status |
|
| 1952 | + foreach ($REG_IDs as $REG_ID) { |
|
| 1953 | + $registration = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 1954 | + if ($registration instanceof EE_Registration) { |
|
| 1955 | + $registration->set_status( |
|
| 1956 | + $status, |
|
| 1957 | + false, |
|
| 1958 | + new Context( |
|
| 1959 | + $status_context, |
|
| 1960 | + esc_html__( |
|
| 1961 | + 'Manually triggered status change on a Registration Admin Page route.', |
|
| 1962 | + 'event_espresso' |
|
| 1963 | + ) |
|
| 1964 | + ) |
|
| 1965 | + ); |
|
| 1966 | + $result = $registration->save(); |
|
| 1967 | + // verifying explicit fails because update *may* just return 0 for 0 rows affected |
|
| 1968 | + $success = $result !== false ? $success : false; |
|
| 1969 | + } |
|
| 1970 | + } |
|
| 1971 | + } |
|
| 1972 | + |
|
| 1973 | + // return $success and processed registrations |
|
| 1974 | + return array('REG_ID' => $REG_IDs, 'success' => $success); |
|
| 1975 | + } |
|
| 1976 | + |
|
| 1977 | + |
|
| 1978 | + /** |
|
| 1979 | + * Common logic for setting up success message and redirecting to appropriate route |
|
| 1980 | + * |
|
| 1981 | + * @param string $STS_ID status id for the registration changed to |
|
| 1982 | + * @param bool $notify indicates whether the _set_registration_status_from_request does notifications or not. |
|
| 1983 | + * @return void |
|
| 1984 | + * @throws EE_Error |
|
| 1985 | + */ |
|
| 1986 | + protected function _reg_status_change_return($STS_ID, $notify = false) |
|
| 1987 | + { |
|
| 1988 | + $result = ! empty($STS_ID) ? $this->_set_registration_status_from_request($STS_ID, $notify) |
|
| 1989 | + : array('success' => false); |
|
| 1990 | + $success = isset($result['success']) && $result['success']; |
|
| 1991 | + // setup success message |
|
| 1992 | + if ($success) { |
|
| 1993 | + if (is_array($result['REG_ID']) && count($result['REG_ID']) === 1) { |
|
| 1994 | + $msg = sprintf( |
|
| 1995 | + esc_html__('Registration status has been set to %s', 'event_espresso'), |
|
| 1996 | + EEH_Template::pretty_status($STS_ID, false, 'lower') |
|
| 1997 | + ); |
|
| 1998 | + } else { |
|
| 1999 | + $msg = sprintf( |
|
| 2000 | + esc_html__('Registrations have been set to %s.', 'event_espresso'), |
|
| 2001 | + EEH_Template::pretty_status($STS_ID, false, 'lower') |
|
| 2002 | + ); |
|
| 2003 | + } |
|
| 2004 | + EE_Error::add_success($msg); |
|
| 2005 | + } else { |
|
| 2006 | + EE_Error::add_error( |
|
| 2007 | + esc_html__( |
|
| 2008 | + 'Something went wrong, and the status was not changed', |
|
| 2009 | + 'event_espresso' |
|
| 2010 | + ), |
|
| 2011 | + __FILE__, |
|
| 2012 | + __LINE__, |
|
| 2013 | + __FUNCTION__ |
|
| 2014 | + ); |
|
| 2015 | + } |
|
| 2016 | + if (isset($this->_req_data['return']) && $this->_req_data['return'] == 'view_registration') { |
|
| 2017 | + $route = array('action' => 'view_registration', '_REG_ID' => reset($result['REG_ID'])); |
|
| 2018 | + } else { |
|
| 2019 | + $route = array('action' => 'default'); |
|
| 2020 | + } |
|
| 2021 | + $route = $this->mergeExistingRequestParamsWithRedirectArgs($route); |
|
| 2022 | + $this->_redirect_after_action($success, '', '', $route, true); |
|
| 2023 | + } |
|
| 2024 | + |
|
| 2025 | + |
|
| 2026 | + /** |
|
| 2027 | + * incoming reg status change from reg details page. |
|
| 2028 | + * |
|
| 2029 | + * @return void |
|
| 2030 | + */ |
|
| 2031 | + protected function _change_reg_status() |
|
| 2032 | + { |
|
| 2033 | + $this->_req_data['return'] = 'view_registration'; |
|
| 2034 | + // set notify based on whether the send notifications toggle is set or not |
|
| 2035 | + $notify = ! empty($this->_req_data['reg_status_change_form']['send_notifications']); |
|
| 2036 | + // $notify = ! empty( $this->_req_data['txn_reg_status_change']['send_notifications'] ); |
|
| 2037 | + $this->_req_data['reg_status_change_form']['reg_status'] = isset($this->_req_data['reg_status_change_form']['reg_status']) |
|
| 2038 | + ? $this->_req_data['reg_status_change_form']['reg_status'] : ''; |
|
| 2039 | + switch ($this->_req_data['reg_status_change_form']['reg_status']) { |
|
| 2040 | + case EEM_Registration::status_id_approved: |
|
| 2041 | + case EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'): |
|
| 2042 | + $this->approve_registration($notify); |
|
| 2043 | + break; |
|
| 2044 | + case EEM_Registration::status_id_pending_payment: |
|
| 2045 | + case EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'): |
|
| 2046 | + $this->pending_registration($notify); |
|
| 2047 | + break; |
|
| 2048 | + case EEM_Registration::status_id_not_approved: |
|
| 2049 | + case EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'): |
|
| 2050 | + $this->not_approve_registration($notify); |
|
| 2051 | + break; |
|
| 2052 | + case EEM_Registration::status_id_declined: |
|
| 2053 | + case EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'): |
|
| 2054 | + $this->decline_registration($notify); |
|
| 2055 | + break; |
|
| 2056 | + case EEM_Registration::status_id_cancelled: |
|
| 2057 | + case EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'): |
|
| 2058 | + $this->cancel_registration($notify); |
|
| 2059 | + break; |
|
| 2060 | + case EEM_Registration::status_id_wait_list: |
|
| 2061 | + case EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'): |
|
| 2062 | + $this->wait_list_registration($notify); |
|
| 2063 | + break; |
|
| 2064 | + case EEM_Registration::status_id_incomplete: |
|
| 2065 | + default: |
|
| 2066 | + $result['success'] = false; |
|
| 2067 | + unset($this->_req_data['return']); |
|
| 2068 | + $this->_reg_status_change_return('', false); |
|
| 2069 | + break; |
|
| 2070 | + } |
|
| 2071 | + } |
|
| 2072 | + |
|
| 2073 | + |
|
| 2074 | + /** |
|
| 2075 | + * Callback for bulk action routes. |
|
| 2076 | + * Note: although we could just register the singular route callbacks for each bulk action route as well, this |
|
| 2077 | + * method was chosen so there is one central place all the registration status bulk actions are going through. |
|
| 2078 | + * Potentially, this provides an easier place to locate logic that is specific to these bulk actions (as opposed to |
|
| 2079 | + * when an action is happening on just a single registration). |
|
| 2080 | + * |
|
| 2081 | + * @param $action |
|
| 2082 | + * @param bool $notify |
|
| 2083 | + */ |
|
| 2084 | + protected function bulk_action_on_registrations($action, $notify = false) |
|
| 2085 | + { |
|
| 2086 | + do_action( |
|
| 2087 | + 'AHEE__Registrations_Admin_Page__bulk_action_on_registrations__before_execution', |
|
| 2088 | + $this, |
|
| 2089 | + $action, |
|
| 2090 | + $notify |
|
| 2091 | + ); |
|
| 2092 | + $method = $action . '_registration'; |
|
| 2093 | + if (method_exists($this, $method)) { |
|
| 2094 | + $this->$method($notify); |
|
| 2095 | + } |
|
| 2096 | + } |
|
| 2097 | + |
|
| 2098 | + |
|
| 2099 | + /** |
|
| 2100 | + * approve_registration |
|
| 2101 | + * |
|
| 2102 | + * @access protected |
|
| 2103 | + * @param bool $notify whether or not to notify the registrant about their approval. |
|
| 2104 | + * @return void |
|
| 2105 | + */ |
|
| 2106 | + protected function approve_registration($notify = false) |
|
| 2107 | + { |
|
| 2108 | + $this->_reg_status_change_return(EEM_Registration::status_id_approved, $notify); |
|
| 2109 | + } |
|
| 2110 | + |
|
| 2111 | + |
|
| 2112 | + /** |
|
| 2113 | + * decline_registration |
|
| 2114 | + * |
|
| 2115 | + * @access protected |
|
| 2116 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 2117 | + * @return void |
|
| 2118 | + */ |
|
| 2119 | + protected function decline_registration($notify = false) |
|
| 2120 | + { |
|
| 2121 | + $this->_reg_status_change_return(EEM_Registration::status_id_declined, $notify); |
|
| 2122 | + } |
|
| 2123 | + |
|
| 2124 | + |
|
| 2125 | + /** |
|
| 2126 | + * cancel_registration |
|
| 2127 | + * |
|
| 2128 | + * @access protected |
|
| 2129 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 2130 | + * @return void |
|
| 2131 | + */ |
|
| 2132 | + protected function cancel_registration($notify = false) |
|
| 2133 | + { |
|
| 2134 | + $this->_reg_status_change_return(EEM_Registration::status_id_cancelled, $notify); |
|
| 2135 | + } |
|
| 2136 | + |
|
| 2137 | + |
|
| 2138 | + /** |
|
| 2139 | + * not_approve_registration |
|
| 2140 | + * |
|
| 2141 | + * @access protected |
|
| 2142 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 2143 | + * @return void |
|
| 2144 | + */ |
|
| 2145 | + protected function not_approve_registration($notify = false) |
|
| 2146 | + { |
|
| 2147 | + $this->_reg_status_change_return(EEM_Registration::status_id_not_approved, $notify); |
|
| 2148 | + } |
|
| 2149 | + |
|
| 2150 | + |
|
| 2151 | + /** |
|
| 2152 | + * decline_registration |
|
| 2153 | + * |
|
| 2154 | + * @access protected |
|
| 2155 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 2156 | + * @return void |
|
| 2157 | + */ |
|
| 2158 | + protected function pending_registration($notify = false) |
|
| 2159 | + { |
|
| 2160 | + $this->_reg_status_change_return(EEM_Registration::status_id_pending_payment, $notify); |
|
| 2161 | + } |
|
| 2162 | + |
|
| 2163 | + |
|
| 2164 | + /** |
|
| 2165 | + * waitlist_registration |
|
| 2166 | + * |
|
| 2167 | + * @access protected |
|
| 2168 | + * @param bool $notify whether or not to notify the registrant about their status change. |
|
| 2169 | + * @return void |
|
| 2170 | + */ |
|
| 2171 | + protected function wait_list_registration($notify = false) |
|
| 2172 | + { |
|
| 2173 | + $this->_reg_status_change_return(EEM_Registration::status_id_wait_list, $notify); |
|
| 2174 | + } |
|
| 2175 | + |
|
| 2176 | + |
|
| 2177 | + /** |
|
| 2178 | + * generates HTML for the Registration main meta box |
|
| 2179 | + * |
|
| 2180 | + * @access public |
|
| 2181 | + * @return void |
|
| 2182 | + * @throws DomainException |
|
| 2183 | + * @throws EE_Error |
|
| 2184 | + * @throws InvalidArgumentException |
|
| 2185 | + * @throws InvalidDataTypeException |
|
| 2186 | + * @throws InvalidInterfaceException |
|
| 2187 | + * @throws ReflectionException |
|
| 2188 | + * @throws EntityNotFoundException |
|
| 2189 | + */ |
|
| 2190 | + public function _reg_details_meta_box() |
|
| 2191 | + { |
|
| 2192 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 2193 | + EEH_Autoloader::register_line_item_filter_autoloaders(); |
|
| 2194 | + EE_Registry::instance()->load_helper('Line_Item'); |
|
| 2195 | + $transaction = $this->_registration->transaction() ? $this->_registration->transaction() |
|
| 2196 | + : EE_Transaction::new_instance(); |
|
| 2197 | + $this->_session = $transaction->session_data(); |
|
| 2198 | + $filters = new EE_Line_Item_Filter_Collection(); |
|
| 2199 | + $filters->add(new EE_Single_Registration_Line_Item_Filter($this->_registration)); |
|
| 2200 | + $filters->add(new EE_Non_Zero_Line_Item_Filter()); |
|
| 2201 | + $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
|
| 2202 | + $filters, |
|
| 2203 | + $transaction->total_line_item() |
|
| 2204 | + ); |
|
| 2205 | + $filtered_line_item_tree = $line_item_filter_processor->process(); |
|
| 2206 | + $line_item_display = new EE_Line_Item_Display( |
|
| 2207 | + 'reg_admin_table', |
|
| 2208 | + 'EE_Admin_Table_Registration_Line_Item_Display_Strategy' |
|
| 2209 | + ); |
|
| 2210 | + $this->_template_args['line_item_table'] = $line_item_display->display_line_item( |
|
| 2211 | + $filtered_line_item_tree, |
|
| 2212 | + array('EE_Registration' => $this->_registration) |
|
| 2213 | + ); |
|
| 2214 | + $attendee = $this->_registration->attendee(); |
|
| 2215 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 2216 | + 'ee_read_transaction', |
|
| 2217 | + 'espresso_transactions_view_transaction' |
|
| 2218 | + )) { |
|
| 2219 | + $this->_template_args['view_transaction_button'] = EEH_Template::get_button_or_link( |
|
| 2220 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 2221 | + array( |
|
| 2222 | + 'action' => 'view_transaction', |
|
| 2223 | + 'TXN_ID' => $transaction->ID(), |
|
| 2224 | + ), |
|
| 2225 | + TXN_ADMIN_URL |
|
| 2226 | + ), |
|
| 2227 | + esc_html__(' View Transaction', 'event_espresso'), |
|
| 2228 | + 'button secondary-button right', |
|
| 2229 | + 'dashicons dashicons-cart' |
|
| 2230 | + ); |
|
| 2231 | + } else { |
|
| 2232 | + $this->_template_args['view_transaction_button'] = ''; |
|
| 2233 | + } |
|
| 2234 | + if ($attendee instanceof EE_Attendee |
|
| 2235 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 2236 | + 'ee_send_message', |
|
| 2237 | + 'espresso_registrations_resend_registration' |
|
| 2238 | + ) |
|
| 2239 | + ) { |
|
| 2240 | + $this->_template_args['resend_registration_button'] = EEH_Template::get_button_or_link( |
|
| 2241 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 2242 | + array( |
|
| 2243 | + 'action' => 'resend_registration', |
|
| 2244 | + '_REG_ID' => $this->_registration->ID(), |
|
| 2245 | + 'redirect_to' => 'view_registration', |
|
| 2246 | + ), |
|
| 2247 | + REG_ADMIN_URL |
|
| 2248 | + ), |
|
| 2249 | + esc_html__(' Resend Registration', 'event_espresso'), |
|
| 2250 | + 'button secondary-button right', |
|
| 2251 | + 'dashicons dashicons-email-alt' |
|
| 2252 | + ); |
|
| 2253 | + } else { |
|
| 2254 | + $this->_template_args['resend_registration_button'] = ''; |
|
| 2255 | + } |
|
| 2256 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2257 | + $payment = $transaction->get_first_related('Payment'); |
|
| 2258 | + $payment = ! $payment instanceof EE_Payment |
|
| 2259 | + ? EE_Payment::new_instance() |
|
| 2260 | + : $payment; |
|
| 2261 | + $payment_method = $payment->get_first_related('Payment_Method'); |
|
| 2262 | + $payment_method = ! $payment_method instanceof EE_Payment_Method |
|
| 2263 | + ? EE_Payment_Method::new_instance() |
|
| 2264 | + : $payment_method; |
|
| 2265 | + $reg_details = array( |
|
| 2266 | + 'payment_method' => $payment_method->name(), |
|
| 2267 | + 'response_msg' => $payment->gateway_response(), |
|
| 2268 | + 'registration_id' => $this->_registration->get('REG_code'), |
|
| 2269 | + 'registration_session' => $this->_registration->session_ID(), |
|
| 2270 | + 'ip_address' => isset($this->_session['ip_address']) ? $this->_session['ip_address'] : '', |
|
| 2271 | + 'user_agent' => isset($this->_session['user_agent']) ? $this->_session['user_agent'] : '', |
|
| 2272 | + ); |
|
| 2273 | + if (isset($reg_details['registration_id'])) { |
|
| 2274 | + $this->_template_args['reg_details']['registration_id']['value'] = $reg_details['registration_id']; |
|
| 2275 | + $this->_template_args['reg_details']['registration_id']['label'] = esc_html__( |
|
| 2276 | + 'Registration ID', |
|
| 2277 | + 'event_espresso' |
|
| 2278 | + ); |
|
| 2279 | + $this->_template_args['reg_details']['registration_id']['class'] = 'regular-text'; |
|
| 2280 | + } |
|
| 2281 | + if (isset($reg_details['payment_method'])) { |
|
| 2282 | + $this->_template_args['reg_details']['payment_method']['value'] = $reg_details['payment_method']; |
|
| 2283 | + $this->_template_args['reg_details']['payment_method']['label'] = esc_html__( |
|
| 2284 | + 'Most Recent Payment Method', |
|
| 2285 | + 'event_espresso' |
|
| 2286 | + ); |
|
| 2287 | + $this->_template_args['reg_details']['payment_method']['class'] = 'regular-text'; |
|
| 2288 | + $this->_template_args['reg_details']['response_msg']['value'] = $reg_details['response_msg']; |
|
| 2289 | + $this->_template_args['reg_details']['response_msg']['label'] = esc_html__( |
|
| 2290 | + 'Payment method response', |
|
| 2291 | + 'event_espresso' |
|
| 2292 | + ); |
|
| 2293 | + $this->_template_args['reg_details']['response_msg']['class'] = 'regular-text'; |
|
| 2294 | + } |
|
| 2295 | + $this->_template_args['reg_details']['registration_session']['value'] = $reg_details['registration_session']; |
|
| 2296 | + $this->_template_args['reg_details']['registration_session']['label'] = esc_html__( |
|
| 2297 | + 'Registration Session', |
|
| 2298 | + 'event_espresso' |
|
| 2299 | + ); |
|
| 2300 | + $this->_template_args['reg_details']['registration_session']['class'] = 'regular-text'; |
|
| 2301 | + $this->_template_args['reg_details']['ip_address']['value'] = $reg_details['ip_address']; |
|
| 2302 | + $this->_template_args['reg_details']['ip_address']['label'] = esc_html__( |
|
| 2303 | + 'Registration placed from IP', |
|
| 2304 | + 'event_espresso' |
|
| 2305 | + ); |
|
| 2306 | + $this->_template_args['reg_details']['ip_address']['class'] = 'regular-text'; |
|
| 2307 | + $this->_template_args['reg_details']['user_agent']['value'] = $reg_details['user_agent']; |
|
| 2308 | + $this->_template_args['reg_details']['user_agent']['label'] = esc_html__( |
|
| 2309 | + 'Registrant User Agent', |
|
| 2310 | + 'event_espresso' |
|
| 2311 | + ); |
|
| 2312 | + $this->_template_args['reg_details']['user_agent']['class'] = 'large-text'; |
|
| 2313 | + $this->_template_args['event_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2314 | + array( |
|
| 2315 | + 'action' => 'default', |
|
| 2316 | + 'event_id' => $this->_registration->event_ID(), |
|
| 2317 | + ), |
|
| 2318 | + REG_ADMIN_URL |
|
| 2319 | + ); |
|
| 2320 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2321 | + $this->_template_args['event_id'] = $this->_registration->event_ID(); |
|
| 2322 | + $template_path = |
|
| 2323 | + REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_details.template.php'; |
|
| 2324 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2325 | + } |
|
| 2326 | + |
|
| 2327 | + |
|
| 2328 | + /** |
|
| 2329 | + * generates HTML for the Registration Questions meta box. |
|
| 2330 | + * If pre-4.8.32.rc.000 hooks are used, uses old methods (with its filters), |
|
| 2331 | + * otherwise uses new forms system |
|
| 2332 | + * |
|
| 2333 | + * @access public |
|
| 2334 | + * @return void |
|
| 2335 | + * @throws DomainException |
|
| 2336 | + * @throws EE_Error |
|
| 2337 | + */ |
|
| 2338 | + public function _reg_questions_meta_box() |
|
| 2339 | + { |
|
| 2340 | + // allow someone to override this method entirely |
|
| 2341 | + if (apply_filters( |
|
| 2342 | + 'FHEE__Registrations_Admin_Page___reg_questions_meta_box__do_default', |
|
| 2343 | + true, |
|
| 2344 | + $this, |
|
| 2345 | + $this->_registration |
|
| 2346 | + )) { |
|
| 2347 | + $form = $this->_get_reg_custom_questions_form( |
|
| 2348 | + $this->_registration->ID() |
|
| 2349 | + ); |
|
| 2350 | + $this->_template_args['att_questions'] = count($form->subforms()) > 0 |
|
| 2351 | + ? $form->get_html_and_js() |
|
| 2352 | + : ''; |
|
| 2353 | + $this->_template_args['reg_questions_form_action'] = 'edit_registration'; |
|
| 2354 | + $this->_template_args['REG_ID'] = $this->_registration->ID(); |
|
| 2355 | + $template_path = |
|
| 2356 | + REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_reg_questions.template.php'; |
|
| 2357 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2358 | + } |
|
| 2359 | + } |
|
| 2360 | + |
|
| 2361 | + |
|
| 2362 | + /** |
|
| 2363 | + * form_before_question_group |
|
| 2364 | + * |
|
| 2365 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2366 | + * @access public |
|
| 2367 | + * @param string $output |
|
| 2368 | + * @return string |
|
| 2369 | + */ |
|
| 2370 | + public function form_before_question_group($output) |
|
| 2371 | + { |
|
| 2372 | + EE_Error::doing_it_wrong( |
|
| 2373 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2374 | + esc_html__( |
|
| 2375 | + '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.', |
|
| 2376 | + 'event_espresso' |
|
| 2377 | + ), |
|
| 2378 | + '4.8.32.rc.000' |
|
| 2379 | + ); |
|
| 2380 | + return ' |
|
| 2381 | 2381 | <table class="form-table ee-width-100"> |
| 2382 | 2382 | <tbody> |
| 2383 | 2383 | '; |
| 2384 | - } |
|
| 2385 | - |
|
| 2386 | - |
|
| 2387 | - /** |
|
| 2388 | - * form_after_question_group |
|
| 2389 | - * |
|
| 2390 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2391 | - * @access public |
|
| 2392 | - * @param string $output |
|
| 2393 | - * @return string |
|
| 2394 | - */ |
|
| 2395 | - public function form_after_question_group($output) |
|
| 2396 | - { |
|
| 2397 | - EE_Error::doing_it_wrong( |
|
| 2398 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2399 | - esc_html__( |
|
| 2400 | - '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.', |
|
| 2401 | - 'event_espresso' |
|
| 2402 | - ), |
|
| 2403 | - '4.8.32.rc.000' |
|
| 2404 | - ); |
|
| 2405 | - return ' |
|
| 2384 | + } |
|
| 2385 | + |
|
| 2386 | + |
|
| 2387 | + /** |
|
| 2388 | + * form_after_question_group |
|
| 2389 | + * |
|
| 2390 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2391 | + * @access public |
|
| 2392 | + * @param string $output |
|
| 2393 | + * @return string |
|
| 2394 | + */ |
|
| 2395 | + public function form_after_question_group($output) |
|
| 2396 | + { |
|
| 2397 | + EE_Error::doing_it_wrong( |
|
| 2398 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2399 | + esc_html__( |
|
| 2400 | + '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.', |
|
| 2401 | + 'event_espresso' |
|
| 2402 | + ), |
|
| 2403 | + '4.8.32.rc.000' |
|
| 2404 | + ); |
|
| 2405 | + return ' |
|
| 2406 | 2406 | <tr class="hide-if-no-js"> |
| 2407 | 2407 | <th> </th> |
| 2408 | 2408 | <td class="reg-admin-edit-attendee-question-td"> |
| 2409 | 2409 | <a class="reg-admin-edit-attendee-question-lnk" href="#" title="' |
| 2410 | - . esc_attr__('click to edit question', 'event_espresso') |
|
| 2411 | - . '"> |
|
| 2410 | + . esc_attr__('click to edit question', 'event_espresso') |
|
| 2411 | + . '"> |
|
| 2412 | 2412 | <span class="reg-admin-edit-question-group-spn lt-grey-txt">' |
| 2413 | - . esc_html__('edit the above question group', 'event_espresso') |
|
| 2414 | - . '</span> |
|
| 2413 | + . esc_html__('edit the above question group', 'event_espresso') |
|
| 2414 | + . '</span> |
|
| 2415 | 2415 | <div class="dashicons dashicons-edit"></div> |
| 2416 | 2416 | </a> |
| 2417 | 2417 | </td> |
@@ -2419,609 +2419,609 @@ discard block |
||
| 2419 | 2419 | </tbody> |
| 2420 | 2420 | </table> |
| 2421 | 2421 | '; |
| 2422 | - } |
|
| 2423 | - |
|
| 2424 | - |
|
| 2425 | - /** |
|
| 2426 | - * form_form_field_label_wrap |
|
| 2427 | - * |
|
| 2428 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2429 | - * @access public |
|
| 2430 | - * @param string $label |
|
| 2431 | - * @return string |
|
| 2432 | - */ |
|
| 2433 | - public function form_form_field_label_wrap($label) |
|
| 2434 | - { |
|
| 2435 | - EE_Error::doing_it_wrong( |
|
| 2436 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2437 | - esc_html__( |
|
| 2438 | - '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.', |
|
| 2439 | - 'event_espresso' |
|
| 2440 | - ), |
|
| 2441 | - '4.8.32.rc.000' |
|
| 2442 | - ); |
|
| 2443 | - return ' |
|
| 2422 | + } |
|
| 2423 | + |
|
| 2424 | + |
|
| 2425 | + /** |
|
| 2426 | + * form_form_field_label_wrap |
|
| 2427 | + * |
|
| 2428 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2429 | + * @access public |
|
| 2430 | + * @param string $label |
|
| 2431 | + * @return string |
|
| 2432 | + */ |
|
| 2433 | + public function form_form_field_label_wrap($label) |
|
| 2434 | + { |
|
| 2435 | + EE_Error::doing_it_wrong( |
|
| 2436 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2437 | + esc_html__( |
|
| 2438 | + '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.', |
|
| 2439 | + 'event_espresso' |
|
| 2440 | + ), |
|
| 2441 | + '4.8.32.rc.000' |
|
| 2442 | + ); |
|
| 2443 | + return ' |
|
| 2444 | 2444 | <tr> |
| 2445 | 2445 | <th> |
| 2446 | 2446 | ' . $label . ' |
| 2447 | 2447 | </th>'; |
| 2448 | - } |
|
| 2449 | - |
|
| 2450 | - |
|
| 2451 | - /** |
|
| 2452 | - * form_form_field_input__wrap |
|
| 2453 | - * |
|
| 2454 | - * @deprecated as of 4.8.32.rc.000 |
|
| 2455 | - * @access public |
|
| 2456 | - * @param string $input |
|
| 2457 | - * @return string |
|
| 2458 | - */ |
|
| 2459 | - public function form_form_field_input__wrap($input) |
|
| 2460 | - { |
|
| 2461 | - EE_Error::doing_it_wrong( |
|
| 2462 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 2463 | - esc_html__( |
|
| 2464 | - '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.', |
|
| 2465 | - 'event_espresso' |
|
| 2466 | - ), |
|
| 2467 | - '4.8.32.rc.000' |
|
| 2468 | - ); |
|
| 2469 | - return ' |
|
| 2448 | + } |
|
| 2449 | + |
|
| 2450 | + |
|
| 2451 | + /** |
|
| 2452 | + * form_form_field_input__wrap |
|
| 2453 | + * |
|
| 2454 | + * @deprecated as of 4.8.32.rc.000 |
|
| 2455 | + * @access public |
|
| 2456 | + * @param string $input |
|
| 2457 | + * @return string |
|
| 2458 | + */ |
|
| 2459 | + public function form_form_field_input__wrap($input) |
|
| 2460 | + { |
|
| 2461 | + EE_Error::doing_it_wrong( |
|
| 2462 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 2463 | + esc_html__( |
|
| 2464 | + '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.', |
|
| 2465 | + 'event_espresso' |
|
| 2466 | + ), |
|
| 2467 | + '4.8.32.rc.000' |
|
| 2468 | + ); |
|
| 2469 | + return ' |
|
| 2470 | 2470 | <td class="reg-admin-attendee-questions-input-td disabled-input"> |
| 2471 | 2471 | ' . $input . ' |
| 2472 | 2472 | </td> |
| 2473 | 2473 | </tr>'; |
| 2474 | - } |
|
| 2475 | - |
|
| 2476 | - |
|
| 2477 | - /** |
|
| 2478 | - * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
| 2479 | - * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
| 2480 | - * to display the page |
|
| 2481 | - * |
|
| 2482 | - * @access protected |
|
| 2483 | - * @return void |
|
| 2484 | - * @throws EE_Error |
|
| 2485 | - */ |
|
| 2486 | - protected function _update_attendee_registration_form() |
|
| 2487 | - { |
|
| 2488 | - do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
| 2489 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 2490 | - $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 2491 | - $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
| 2492 | - if ($success) { |
|
| 2493 | - $what = esc_html__('Registration Form', 'event_espresso'); |
|
| 2494 | - $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
|
| 2495 | - : array('action' => 'default'); |
|
| 2496 | - $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route); |
|
| 2497 | - } |
|
| 2498 | - } |
|
| 2499 | - } |
|
| 2500 | - |
|
| 2501 | - |
|
| 2502 | - /** |
|
| 2503 | - * Gets the form for saving registrations custom questions (if done |
|
| 2504 | - * previously retrieves the cached form object, which may have validation errors in it) |
|
| 2505 | - * |
|
| 2506 | - * @param int $REG_ID |
|
| 2507 | - * @return EE_Registration_Custom_Questions_Form |
|
| 2508 | - * @throws EE_Error |
|
| 2509 | - * @throws InvalidArgumentException |
|
| 2510 | - * @throws InvalidDataTypeException |
|
| 2511 | - * @throws InvalidInterfaceException |
|
| 2512 | - */ |
|
| 2513 | - protected function _get_reg_custom_questions_form($REG_ID) |
|
| 2514 | - { |
|
| 2515 | - if (! $this->_reg_custom_questions_form) { |
|
| 2516 | - require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 2517 | - $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
| 2518 | - EEM_Registration::instance()->get_one_by_ID($REG_ID) |
|
| 2519 | - ); |
|
| 2520 | - $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
| 2521 | - } |
|
| 2522 | - return $this->_reg_custom_questions_form; |
|
| 2523 | - } |
|
| 2524 | - |
|
| 2525 | - |
|
| 2526 | - /** |
|
| 2527 | - * Saves |
|
| 2528 | - * |
|
| 2529 | - * @access private |
|
| 2530 | - * @param bool $REG_ID |
|
| 2531 | - * @return bool |
|
| 2532 | - * @throws EE_Error |
|
| 2533 | - * @throws InvalidArgumentException |
|
| 2534 | - * @throws InvalidDataTypeException |
|
| 2535 | - * @throws InvalidInterfaceException |
|
| 2536 | - */ |
|
| 2537 | - private function _save_reg_custom_questions_form($REG_ID = false) |
|
| 2538 | - { |
|
| 2539 | - if (! $REG_ID) { |
|
| 2540 | - EE_Error::add_error( |
|
| 2541 | - esc_html__( |
|
| 2542 | - 'An error occurred. No registration ID was received.', |
|
| 2543 | - 'event_espresso' |
|
| 2544 | - ), |
|
| 2545 | - __FILE__, |
|
| 2546 | - __FUNCTION__, |
|
| 2547 | - __LINE__ |
|
| 2548 | - ); |
|
| 2549 | - } |
|
| 2550 | - $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
| 2551 | - $form->receive_form_submission($this->_req_data); |
|
| 2552 | - $success = false; |
|
| 2553 | - if ($form->is_valid()) { |
|
| 2554 | - foreach ($form->subforms() as $question_group_id => $question_group_form) { |
|
| 2555 | - foreach ($question_group_form->inputs() as $question_id => $input) { |
|
| 2556 | - $where_conditions = array( |
|
| 2557 | - 'QST_ID' => $question_id, |
|
| 2558 | - 'REG_ID' => $REG_ID, |
|
| 2559 | - ); |
|
| 2560 | - $possibly_new_values = array( |
|
| 2561 | - 'ANS_value' => $input->normalized_value(), |
|
| 2562 | - ); |
|
| 2563 | - $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
|
| 2564 | - if ($answer instanceof EE_Answer) { |
|
| 2565 | - $success = $answer->save($possibly_new_values); |
|
| 2566 | - } else { |
|
| 2567 | - // insert it then |
|
| 2568 | - $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
| 2569 | - $answer = EE_Answer::new_instance($cols_n_vals); |
|
| 2570 | - $success = $answer->save(); |
|
| 2571 | - } |
|
| 2572 | - } |
|
| 2573 | - } |
|
| 2574 | - } else { |
|
| 2575 | - EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2576 | - } |
|
| 2577 | - return $success; |
|
| 2578 | - } |
|
| 2579 | - |
|
| 2580 | - |
|
| 2581 | - /** |
|
| 2582 | - * generates HTML for the Registration main meta box |
|
| 2583 | - * |
|
| 2584 | - * @access public |
|
| 2585 | - * @return void |
|
| 2586 | - * @throws DomainException |
|
| 2587 | - * @throws EE_Error |
|
| 2588 | - * @throws InvalidArgumentException |
|
| 2589 | - * @throws InvalidDataTypeException |
|
| 2590 | - * @throws InvalidInterfaceException |
|
| 2591 | - */ |
|
| 2592 | - public function _reg_attendees_meta_box() |
|
| 2593 | - { |
|
| 2594 | - $REG = EEM_Registration::instance(); |
|
| 2595 | - // get all other registrations on this transaction, and cache |
|
| 2596 | - // the attendees for them so we don't have to run another query using force_join |
|
| 2597 | - $registrations = $REG->get_all( |
|
| 2598 | - array( |
|
| 2599 | - array( |
|
| 2600 | - 'TXN_ID' => $this->_registration->transaction_ID(), |
|
| 2601 | - 'REG_ID' => array('!=', $this->_registration->ID()), |
|
| 2602 | - ), |
|
| 2603 | - 'force_join' => array('Attendee'), |
|
| 2604 | - 'default_where_conditions' => 'other_models_only', |
|
| 2605 | - ) |
|
| 2606 | - ); |
|
| 2607 | - $this->_template_args['attendees'] = array(); |
|
| 2608 | - $this->_template_args['attendee_notice'] = ''; |
|
| 2609 | - if (empty($registrations) |
|
| 2610 | - || (is_array($registrations) |
|
| 2611 | - && ! EEH_Array::get_one_item_from_array($registrations)) |
|
| 2612 | - ) { |
|
| 2613 | - EE_Error::add_error( |
|
| 2614 | - esc_html__( |
|
| 2615 | - 'There are no records attached to this registration. Something may have gone wrong with the registration', |
|
| 2616 | - 'event_espresso' |
|
| 2617 | - ), |
|
| 2618 | - __FILE__, |
|
| 2619 | - __FUNCTION__, |
|
| 2620 | - __LINE__ |
|
| 2621 | - ); |
|
| 2622 | - $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
| 2623 | - } else { |
|
| 2624 | - $att_nmbr = 1; |
|
| 2625 | - foreach ($registrations as $registration) { |
|
| 2626 | - /* @var $registration EE_Registration */ |
|
| 2627 | - $attendee = $registration->attendee() |
|
| 2628 | - ? $registration->attendee() |
|
| 2629 | - : EEM_Attendee::instance() |
|
| 2630 | - ->create_default_object(); |
|
| 2631 | - $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID(); |
|
| 2632 | - $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname(); |
|
| 2633 | - $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname(); |
|
| 2634 | - $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email(); |
|
| 2635 | - $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price(); |
|
| 2636 | - $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode( |
|
| 2637 | - ', ', |
|
| 2638 | - $attendee->full_address_as_array() |
|
| 2639 | - ); |
|
| 2640 | - $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce( |
|
| 2641 | - array( |
|
| 2642 | - 'action' => 'edit_attendee', |
|
| 2643 | - 'post' => $attendee->ID(), |
|
| 2644 | - ), |
|
| 2645 | - REG_ADMIN_URL |
|
| 2646 | - ); |
|
| 2647 | - $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event |
|
| 2648 | - ? $registration->event_obj()->name() |
|
| 2649 | - : ''; |
|
| 2650 | - $att_nmbr++; |
|
| 2651 | - } |
|
| 2652 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2653 | - } |
|
| 2654 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2655 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2656 | - } |
|
| 2657 | - |
|
| 2658 | - |
|
| 2659 | - /** |
|
| 2660 | - * generates HTML for the Edit Registration side meta box |
|
| 2661 | - * |
|
| 2662 | - * @access public |
|
| 2663 | - * @return void |
|
| 2664 | - * @throws DomainException |
|
| 2665 | - * @throws EE_Error |
|
| 2666 | - * @throws InvalidArgumentException |
|
| 2667 | - * @throws InvalidDataTypeException |
|
| 2668 | - * @throws InvalidInterfaceException |
|
| 2669 | - */ |
|
| 2670 | - public function _reg_registrant_side_meta_box() |
|
| 2671 | - { |
|
| 2672 | - /*@var $attendee EE_Attendee */ |
|
| 2673 | - $att_check = $this->_registration->attendee(); |
|
| 2674 | - $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object(); |
|
| 2675 | - // now let's determine if this is not the primary registration. If it isn't then we set the |
|
| 2676 | - // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the |
|
| 2677 | - // primary registration object (that way we know if we need to show create button or not) |
|
| 2678 | - if (! $this->_registration->is_primary_registrant()) { |
|
| 2679 | - $primary_registration = $this->_registration->get_primary_registration(); |
|
| 2680 | - $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
| 2681 | - : null; |
|
| 2682 | - if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
| 2683 | - // in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own |
|
| 2684 | - // custom attendee object so let's not worry about the primary reg. |
|
| 2685 | - $primary_registration = null; |
|
| 2686 | - } |
|
| 2687 | - } else { |
|
| 2688 | - $primary_registration = null; |
|
| 2689 | - } |
|
| 2690 | - $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
| 2691 | - $this->_template_args['fname'] = $attendee->fname(); |
|
| 2692 | - $this->_template_args['lname'] = $attendee->lname(); |
|
| 2693 | - $this->_template_args['email'] = $attendee->email(); |
|
| 2694 | - $this->_template_args['phone'] = $attendee->phone(); |
|
| 2695 | - $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
| 2696 | - // edit link |
|
| 2697 | - $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2698 | - array( |
|
| 2699 | - 'action' => 'edit_attendee', |
|
| 2700 | - 'post' => $attendee->ID(), |
|
| 2701 | - ), |
|
| 2702 | - REG_ADMIN_URL |
|
| 2703 | - ); |
|
| 2704 | - $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso'); |
|
| 2705 | - // create link |
|
| 2706 | - $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2707 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 2708 | - array( |
|
| 2709 | - 'action' => 'duplicate_attendee', |
|
| 2710 | - '_REG_ID' => $this->_registration->ID(), |
|
| 2711 | - ), |
|
| 2712 | - REG_ADMIN_URL |
|
| 2713 | - ) : ''; |
|
| 2714 | - $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso'); |
|
| 2715 | - $this->_template_args['att_check'] = $att_check; |
|
| 2716 | - $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2717 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2718 | - } |
|
| 2719 | - |
|
| 2720 | - |
|
| 2721 | - /** |
|
| 2722 | - * trash or restore registrations |
|
| 2723 | - * |
|
| 2724 | - * @param boolean $trash whether to archive or restore |
|
| 2725 | - * @return void |
|
| 2726 | - * @throws EE_Error |
|
| 2727 | - * @throws InvalidArgumentException |
|
| 2728 | - * @throws InvalidDataTypeException |
|
| 2729 | - * @throws InvalidInterfaceException |
|
| 2730 | - * @throws RuntimeException |
|
| 2731 | - * @access protected |
|
| 2732 | - */ |
|
| 2733 | - protected function _trash_or_restore_registrations($trash = true) |
|
| 2734 | - { |
|
| 2735 | - // if empty _REG_ID then get out because there's nothing to do |
|
| 2736 | - if (empty($this->_req_data['_REG_ID'])) { |
|
| 2737 | - EE_Error::add_error( |
|
| 2738 | - sprintf( |
|
| 2739 | - esc_html__( |
|
| 2740 | - 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
|
| 2741 | - 'event_espresso' |
|
| 2742 | - ), |
|
| 2743 | - $trash ? 'trash' : 'restore' |
|
| 2744 | - ), |
|
| 2745 | - __FILE__, |
|
| 2746 | - __LINE__, |
|
| 2747 | - __FUNCTION__ |
|
| 2748 | - ); |
|
| 2749 | - $this->_redirect_after_action(false, '', '', array(), true); |
|
| 2750 | - } |
|
| 2751 | - $success = 0; |
|
| 2752 | - $overwrite_msgs = false; |
|
| 2753 | - // Checkboxes |
|
| 2754 | - if (! is_array($this->_req_data['_REG_ID'])) { |
|
| 2755 | - $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']); |
|
| 2756 | - } |
|
| 2757 | - $reg_count = count($this->_req_data['_REG_ID']); |
|
| 2758 | - // cycle thru checkboxes |
|
| 2759 | - foreach ($this->_req_data['_REG_ID'] as $REG_ID) { |
|
| 2760 | - /** @var EE_Registration $REG */ |
|
| 2761 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 2762 | - $payments = $REG->registration_payments(); |
|
| 2763 | - if (! empty($payments)) { |
|
| 2764 | - $name = $REG->attendee() instanceof EE_Attendee |
|
| 2765 | - ? $REG->attendee()->full_name() |
|
| 2766 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 2767 | - $overwrite_msgs = true; |
|
| 2768 | - EE_Error::add_error( |
|
| 2769 | - sprintf( |
|
| 2770 | - esc_html__( |
|
| 2771 | - '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.', |
|
| 2772 | - 'event_espresso' |
|
| 2773 | - ), |
|
| 2774 | - $name |
|
| 2775 | - ), |
|
| 2776 | - __FILE__, |
|
| 2777 | - __FUNCTION__, |
|
| 2778 | - __LINE__ |
|
| 2779 | - ); |
|
| 2780 | - // can't trash this registration because it has payments. |
|
| 2781 | - continue; |
|
| 2782 | - } |
|
| 2783 | - $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2784 | - if ($updated) { |
|
| 2785 | - $success++; |
|
| 2786 | - } |
|
| 2787 | - } |
|
| 2788 | - $this->_redirect_after_action( |
|
| 2789 | - $success === $reg_count, // were ALL registrations affected? |
|
| 2790 | - $success > 1 |
|
| 2791 | - ? esc_html__('Registrations', 'event_espresso') |
|
| 2792 | - : esc_html__('Registration', 'event_espresso'), |
|
| 2793 | - $trash |
|
| 2794 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 2795 | - : esc_html__('restored', 'event_espresso'), |
|
| 2796 | - $this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')), |
|
| 2797 | - $overwrite_msgs |
|
| 2798 | - ); |
|
| 2799 | - } |
|
| 2800 | - |
|
| 2801 | - |
|
| 2802 | - /** |
|
| 2803 | - * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
| 2804 | - * registration but also. |
|
| 2805 | - * 1. Removing relations to EE_Attendee |
|
| 2806 | - * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
| 2807 | - * ALSO trashed. |
|
| 2808 | - * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
| 2809 | - * 4. Removing relationships between all tickets and the related registrations |
|
| 2810 | - * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
| 2811 | - * 6. Deleting permanently any related Checkins. |
|
| 2812 | - * |
|
| 2813 | - * @return void |
|
| 2814 | - * @throws EE_Error |
|
| 2815 | - * @throws InvalidArgumentException |
|
| 2816 | - * @throws InvalidDataTypeException |
|
| 2817 | - * @throws InvalidInterfaceException |
|
| 2818 | - */ |
|
| 2819 | - protected function _delete_registrations() |
|
| 2820 | - { |
|
| 2821 | - $REG_MDL = EEM_Registration::instance(); |
|
| 2822 | - $success = 1; |
|
| 2823 | - // Checkboxes |
|
| 2824 | - if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
| 2825 | - // if array has more than one element than success message should be plural |
|
| 2826 | - $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
| 2827 | - // cycle thru checkboxes |
|
| 2828 | - while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
| 2829 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2830 | - if (! $REG instanceof EE_Registration) { |
|
| 2831 | - continue; |
|
| 2832 | - } |
|
| 2833 | - $deleted = $this->_delete_registration($REG); |
|
| 2834 | - if (! $deleted) { |
|
| 2835 | - $success = 0; |
|
| 2836 | - } |
|
| 2837 | - } |
|
| 2838 | - } else { |
|
| 2839 | - // grab single id and delete |
|
| 2840 | - $REG_ID = $this->_req_data['_REG_ID']; |
|
| 2841 | - $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2842 | - $deleted = $this->_delete_registration($REG); |
|
| 2843 | - if (! $deleted) { |
|
| 2844 | - $success = 0; |
|
| 2845 | - } |
|
| 2846 | - } |
|
| 2847 | - $what = $success > 1 |
|
| 2848 | - ? esc_html__('Registrations', 'event_espresso') |
|
| 2849 | - : esc_html__('Registration', 'event_espresso'); |
|
| 2850 | - $action_desc = esc_html__('permanently deleted.', 'event_espresso'); |
|
| 2851 | - $this->_redirect_after_action( |
|
| 2852 | - $success, |
|
| 2853 | - $what, |
|
| 2854 | - $action_desc, |
|
| 2855 | - $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']), |
|
| 2856 | - true |
|
| 2857 | - ); |
|
| 2858 | - } |
|
| 2859 | - |
|
| 2860 | - |
|
| 2861 | - /** |
|
| 2862 | - * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
| 2863 | - * models get affected. |
|
| 2864 | - * |
|
| 2865 | - * @param EE_Registration $REG registration to be deleted permenantly |
|
| 2866 | - * @return bool true = successful deletion, false = fail. |
|
| 2867 | - * @throws EE_Error |
|
| 2868 | - */ |
|
| 2869 | - protected function _delete_registration(EE_Registration $REG) |
|
| 2870 | - { |
|
| 2871 | - // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related |
|
| 2872 | - // registrations on the transaction that are NOT trashed. |
|
| 2873 | - $TXN = $REG->get_first_related('Transaction'); |
|
| 2874 | - $REGS = $TXN->get_many_related('Registration'); |
|
| 2875 | - $all_trashed = true; |
|
| 2876 | - foreach ($REGS as $registration) { |
|
| 2877 | - if (! $registration->get('REG_deleted')) { |
|
| 2878 | - $all_trashed = false; |
|
| 2879 | - } |
|
| 2880 | - } |
|
| 2881 | - if (! $all_trashed) { |
|
| 2882 | - EE_Error::add_error( |
|
| 2883 | - esc_html__( |
|
| 2884 | - '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.', |
|
| 2885 | - 'event_espresso' |
|
| 2886 | - ), |
|
| 2887 | - __FILE__, |
|
| 2888 | - __FUNCTION__, |
|
| 2889 | - __LINE__ |
|
| 2890 | - ); |
|
| 2891 | - return false; |
|
| 2892 | - } |
|
| 2893 | - // k made it here so that means we can delete all the related transactions and their answers (but let's do them |
|
| 2894 | - // separately from THIS one). |
|
| 2895 | - foreach ($REGS as $registration) { |
|
| 2896 | - // delete related answers |
|
| 2897 | - $registration->delete_related_permanently('Answer'); |
|
| 2898 | - // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
| 2899 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 2900 | - if ($attendee instanceof EE_Attendee) { |
|
| 2901 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2902 | - } |
|
| 2903 | - // now remove relationships to tickets on this registration. |
|
| 2904 | - $registration->_remove_relations('Ticket'); |
|
| 2905 | - // now delete permanently the checkins related to this registration. |
|
| 2906 | - $registration->delete_related_permanently('Checkin'); |
|
| 2907 | - if ($registration->ID() === $REG->ID()) { |
|
| 2908 | - continue; |
|
| 2909 | - } //we don't want to delete permanently the existing registration just yet. |
|
| 2910 | - // remove relation to transaction for these registrations if NOT the existing registrations |
|
| 2911 | - $registration->_remove_relations('Transaction'); |
|
| 2912 | - // delete permanently any related messages. |
|
| 2913 | - $registration->delete_related_permanently('Message'); |
|
| 2914 | - // now delete this registration permanently |
|
| 2915 | - $registration->delete_permanently(); |
|
| 2916 | - } |
|
| 2917 | - // now all related registrations on the transaction are handled. So let's just handle this registration itself |
|
| 2918 | - // (the transaction and line items should be all that's left). |
|
| 2919 | - // delete the line items related to the transaction for this registration. |
|
| 2920 | - $TXN->delete_related_permanently('Line_Item'); |
|
| 2921 | - // we need to remove all the relationships on the transaction |
|
| 2922 | - $TXN->delete_related_permanently('Payment'); |
|
| 2923 | - $TXN->delete_related_permanently('Extra_Meta'); |
|
| 2924 | - $TXN->delete_related_permanently('Message'); |
|
| 2925 | - // now we can delete this REG permanently (and the transaction of course) |
|
| 2926 | - $REG->delete_related_permanently('Transaction'); |
|
| 2927 | - return $REG->delete_permanently(); |
|
| 2928 | - } |
|
| 2929 | - |
|
| 2930 | - |
|
| 2931 | - /** |
|
| 2932 | - * generates HTML for the Register New Attendee Admin page |
|
| 2933 | - * |
|
| 2934 | - * @access private |
|
| 2935 | - * @throws DomainException |
|
| 2936 | - * @throws EE_Error |
|
| 2937 | - */ |
|
| 2938 | - public function new_registration() |
|
| 2939 | - { |
|
| 2940 | - if (! $this->_set_reg_event()) { |
|
| 2941 | - throw new EE_Error( |
|
| 2942 | - esc_html__( |
|
| 2943 | - 'Unable to continue with registering because there is no Event ID in the request', |
|
| 2944 | - 'event_espresso' |
|
| 2945 | - ) |
|
| 2946 | - ); |
|
| 2947 | - } |
|
| 2948 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2949 | - // gotta start with a clean slate if we're not coming here via ajax |
|
| 2950 | - if (! defined('DOING_AJAX') |
|
| 2951 | - && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error'])) |
|
| 2952 | - ) { |
|
| 2953 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2954 | - } |
|
| 2955 | - $this->_template_args['event_name'] = ''; |
|
| 2956 | - // event name |
|
| 2957 | - if ($this->_reg_event) { |
|
| 2958 | - $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
| 2959 | - $edit_event_url = self::add_query_args_and_nonce( |
|
| 2960 | - array( |
|
| 2961 | - 'action' => 'edit', |
|
| 2962 | - 'post' => $this->_reg_event->ID(), |
|
| 2963 | - ), |
|
| 2964 | - EVENTS_ADMIN_URL |
|
| 2965 | - ); |
|
| 2966 | - $edit_event_lnk = '<a href="' |
|
| 2967 | - . $edit_event_url |
|
| 2968 | - . '" title="' |
|
| 2969 | - . esc_attr__('Edit ', 'event_espresso') |
|
| 2970 | - . $this->_reg_event->name() |
|
| 2971 | - . '">' |
|
| 2972 | - . esc_html__('Edit Event', 'event_espresso') |
|
| 2973 | - . '</a>'; |
|
| 2974 | - $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 2975 | - . $edit_event_lnk |
|
| 2976 | - . '</span>'; |
|
| 2977 | - } |
|
| 2978 | - $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
| 2979 | - if (defined('DOING_AJAX')) { |
|
| 2980 | - $this->_return_json(); |
|
| 2981 | - } |
|
| 2982 | - // grab header |
|
| 2983 | - $template_path = |
|
| 2984 | - REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2985 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2986 | - $template_path, |
|
| 2987 | - $this->_template_args, |
|
| 2988 | - true |
|
| 2989 | - ); |
|
| 2990 | - // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 2991 | - // the details template wrapper |
|
| 2992 | - $this->display_admin_page_with_sidebar(); |
|
| 2993 | - } |
|
| 2994 | - |
|
| 2995 | - |
|
| 2996 | - /** |
|
| 2997 | - * This returns the content for a registration step |
|
| 2998 | - * |
|
| 2999 | - * @access protected |
|
| 3000 | - * @return string html |
|
| 3001 | - * @throws DomainException |
|
| 3002 | - * @throws EE_Error |
|
| 3003 | - * @throws InvalidArgumentException |
|
| 3004 | - * @throws InvalidDataTypeException |
|
| 3005 | - * @throws InvalidInterfaceException |
|
| 3006 | - */ |
|
| 3007 | - protected function _get_registration_step_content() |
|
| 3008 | - { |
|
| 3009 | - if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
| 3010 | - $warning_msg = sprintf( |
|
| 3011 | - esc_html__( |
|
| 3012 | - '%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', |
|
| 3013 | - 'event_espresso' |
|
| 3014 | - ), |
|
| 3015 | - '<br />', |
|
| 3016 | - '<h3 class="important-notice">', |
|
| 3017 | - '</h3>', |
|
| 3018 | - '<div class="float-right">', |
|
| 3019 | - '<span id="redirect_timer" class="important-notice">30</span>', |
|
| 3020 | - '</div>', |
|
| 3021 | - '<b>', |
|
| 3022 | - '</b>' |
|
| 3023 | - ); |
|
| 3024 | - return ' |
|
| 2474 | + } |
|
| 2475 | + |
|
| 2476 | + |
|
| 2477 | + /** |
|
| 2478 | + * Updates the registration's custom questions according to the form info, if the form is submitted. |
|
| 2479 | + * If it's not a post, the "view_registrations" route will be called next on the SAME request |
|
| 2480 | + * to display the page |
|
| 2481 | + * |
|
| 2482 | + * @access protected |
|
| 2483 | + * @return void |
|
| 2484 | + * @throws EE_Error |
|
| 2485 | + */ |
|
| 2486 | + protected function _update_attendee_registration_form() |
|
| 2487 | + { |
|
| 2488 | + do_action('AHEE__Registrations_Admin_Page___update_attendee_registration_form__start', $this); |
|
| 2489 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 2490 | + $REG_ID = isset($this->_req_data['_REG_ID']) ? absint($this->_req_data['_REG_ID']) : false; |
|
| 2491 | + $success = $this->_save_reg_custom_questions_form($REG_ID); |
|
| 2492 | + if ($success) { |
|
| 2493 | + $what = esc_html__('Registration Form', 'event_espresso'); |
|
| 2494 | + $route = $REG_ID ? array('action' => 'view_registration', '_REG_ID' => $REG_ID) |
|
| 2495 | + : array('action' => 'default'); |
|
| 2496 | + $this->_redirect_after_action($success, $what, esc_html__('updated', 'event_espresso'), $route); |
|
| 2497 | + } |
|
| 2498 | + } |
|
| 2499 | + } |
|
| 2500 | + |
|
| 2501 | + |
|
| 2502 | + /** |
|
| 2503 | + * Gets the form for saving registrations custom questions (if done |
|
| 2504 | + * previously retrieves the cached form object, which may have validation errors in it) |
|
| 2505 | + * |
|
| 2506 | + * @param int $REG_ID |
|
| 2507 | + * @return EE_Registration_Custom_Questions_Form |
|
| 2508 | + * @throws EE_Error |
|
| 2509 | + * @throws InvalidArgumentException |
|
| 2510 | + * @throws InvalidDataTypeException |
|
| 2511 | + * @throws InvalidInterfaceException |
|
| 2512 | + */ |
|
| 2513 | + protected function _get_reg_custom_questions_form($REG_ID) |
|
| 2514 | + { |
|
| 2515 | + if (! $this->_reg_custom_questions_form) { |
|
| 2516 | + require_once(REG_ADMIN . 'form_sections' . DS . 'EE_Registration_Custom_Questions_Form.form.php'); |
|
| 2517 | + $this->_reg_custom_questions_form = new EE_Registration_Custom_Questions_Form( |
|
| 2518 | + EEM_Registration::instance()->get_one_by_ID($REG_ID) |
|
| 2519 | + ); |
|
| 2520 | + $this->_reg_custom_questions_form->_construct_finalize(null, null); |
|
| 2521 | + } |
|
| 2522 | + return $this->_reg_custom_questions_form; |
|
| 2523 | + } |
|
| 2524 | + |
|
| 2525 | + |
|
| 2526 | + /** |
|
| 2527 | + * Saves |
|
| 2528 | + * |
|
| 2529 | + * @access private |
|
| 2530 | + * @param bool $REG_ID |
|
| 2531 | + * @return bool |
|
| 2532 | + * @throws EE_Error |
|
| 2533 | + * @throws InvalidArgumentException |
|
| 2534 | + * @throws InvalidDataTypeException |
|
| 2535 | + * @throws InvalidInterfaceException |
|
| 2536 | + */ |
|
| 2537 | + private function _save_reg_custom_questions_form($REG_ID = false) |
|
| 2538 | + { |
|
| 2539 | + if (! $REG_ID) { |
|
| 2540 | + EE_Error::add_error( |
|
| 2541 | + esc_html__( |
|
| 2542 | + 'An error occurred. No registration ID was received.', |
|
| 2543 | + 'event_espresso' |
|
| 2544 | + ), |
|
| 2545 | + __FILE__, |
|
| 2546 | + __FUNCTION__, |
|
| 2547 | + __LINE__ |
|
| 2548 | + ); |
|
| 2549 | + } |
|
| 2550 | + $form = $this->_get_reg_custom_questions_form($REG_ID); |
|
| 2551 | + $form->receive_form_submission($this->_req_data); |
|
| 2552 | + $success = false; |
|
| 2553 | + if ($form->is_valid()) { |
|
| 2554 | + foreach ($form->subforms() as $question_group_id => $question_group_form) { |
|
| 2555 | + foreach ($question_group_form->inputs() as $question_id => $input) { |
|
| 2556 | + $where_conditions = array( |
|
| 2557 | + 'QST_ID' => $question_id, |
|
| 2558 | + 'REG_ID' => $REG_ID, |
|
| 2559 | + ); |
|
| 2560 | + $possibly_new_values = array( |
|
| 2561 | + 'ANS_value' => $input->normalized_value(), |
|
| 2562 | + ); |
|
| 2563 | + $answer = EEM_Answer::instance()->get_one(array($where_conditions)); |
|
| 2564 | + if ($answer instanceof EE_Answer) { |
|
| 2565 | + $success = $answer->save($possibly_new_values); |
|
| 2566 | + } else { |
|
| 2567 | + // insert it then |
|
| 2568 | + $cols_n_vals = array_merge($where_conditions, $possibly_new_values); |
|
| 2569 | + $answer = EE_Answer::new_instance($cols_n_vals); |
|
| 2570 | + $success = $answer->save(); |
|
| 2571 | + } |
|
| 2572 | + } |
|
| 2573 | + } |
|
| 2574 | + } else { |
|
| 2575 | + EE_Error::add_error($form->get_validation_error_string(), __FILE__, __FUNCTION__, __LINE__); |
|
| 2576 | + } |
|
| 2577 | + return $success; |
|
| 2578 | + } |
|
| 2579 | + |
|
| 2580 | + |
|
| 2581 | + /** |
|
| 2582 | + * generates HTML for the Registration main meta box |
|
| 2583 | + * |
|
| 2584 | + * @access public |
|
| 2585 | + * @return void |
|
| 2586 | + * @throws DomainException |
|
| 2587 | + * @throws EE_Error |
|
| 2588 | + * @throws InvalidArgumentException |
|
| 2589 | + * @throws InvalidDataTypeException |
|
| 2590 | + * @throws InvalidInterfaceException |
|
| 2591 | + */ |
|
| 2592 | + public function _reg_attendees_meta_box() |
|
| 2593 | + { |
|
| 2594 | + $REG = EEM_Registration::instance(); |
|
| 2595 | + // get all other registrations on this transaction, and cache |
|
| 2596 | + // the attendees for them so we don't have to run another query using force_join |
|
| 2597 | + $registrations = $REG->get_all( |
|
| 2598 | + array( |
|
| 2599 | + array( |
|
| 2600 | + 'TXN_ID' => $this->_registration->transaction_ID(), |
|
| 2601 | + 'REG_ID' => array('!=', $this->_registration->ID()), |
|
| 2602 | + ), |
|
| 2603 | + 'force_join' => array('Attendee'), |
|
| 2604 | + 'default_where_conditions' => 'other_models_only', |
|
| 2605 | + ) |
|
| 2606 | + ); |
|
| 2607 | + $this->_template_args['attendees'] = array(); |
|
| 2608 | + $this->_template_args['attendee_notice'] = ''; |
|
| 2609 | + if (empty($registrations) |
|
| 2610 | + || (is_array($registrations) |
|
| 2611 | + && ! EEH_Array::get_one_item_from_array($registrations)) |
|
| 2612 | + ) { |
|
| 2613 | + EE_Error::add_error( |
|
| 2614 | + esc_html__( |
|
| 2615 | + 'There are no records attached to this registration. Something may have gone wrong with the registration', |
|
| 2616 | + 'event_espresso' |
|
| 2617 | + ), |
|
| 2618 | + __FILE__, |
|
| 2619 | + __FUNCTION__, |
|
| 2620 | + __LINE__ |
|
| 2621 | + ); |
|
| 2622 | + $this->_template_args['attendee_notice'] = EE_Error::get_notices(); |
|
| 2623 | + } else { |
|
| 2624 | + $att_nmbr = 1; |
|
| 2625 | + foreach ($registrations as $registration) { |
|
| 2626 | + /* @var $registration EE_Registration */ |
|
| 2627 | + $attendee = $registration->attendee() |
|
| 2628 | + ? $registration->attendee() |
|
| 2629 | + : EEM_Attendee::instance() |
|
| 2630 | + ->create_default_object(); |
|
| 2631 | + $this->_template_args['attendees'][ $att_nmbr ]['STS_ID'] = $registration->status_ID(); |
|
| 2632 | + $this->_template_args['attendees'][ $att_nmbr ]['fname'] = $attendee->fname(); |
|
| 2633 | + $this->_template_args['attendees'][ $att_nmbr ]['lname'] = $attendee->lname(); |
|
| 2634 | + $this->_template_args['attendees'][ $att_nmbr ]['email'] = $attendee->email(); |
|
| 2635 | + $this->_template_args['attendees'][ $att_nmbr ]['final_price'] = $registration->final_price(); |
|
| 2636 | + $this->_template_args['attendees'][ $att_nmbr ]['address'] = implode( |
|
| 2637 | + ', ', |
|
| 2638 | + $attendee->full_address_as_array() |
|
| 2639 | + ); |
|
| 2640 | + $this->_template_args['attendees'][ $att_nmbr ]['att_link'] = self::add_query_args_and_nonce( |
|
| 2641 | + array( |
|
| 2642 | + 'action' => 'edit_attendee', |
|
| 2643 | + 'post' => $attendee->ID(), |
|
| 2644 | + ), |
|
| 2645 | + REG_ADMIN_URL |
|
| 2646 | + ); |
|
| 2647 | + $this->_template_args['attendees'][ $att_nmbr ]['event_name'] = $registration->event_obj() instanceof EE_Event |
|
| 2648 | + ? $registration->event_obj()->name() |
|
| 2649 | + : ''; |
|
| 2650 | + $att_nmbr++; |
|
| 2651 | + } |
|
| 2652 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 2653 | + } |
|
| 2654 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_main_meta_box_attendees.template.php'; |
|
| 2655 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2656 | + } |
|
| 2657 | + |
|
| 2658 | + |
|
| 2659 | + /** |
|
| 2660 | + * generates HTML for the Edit Registration side meta box |
|
| 2661 | + * |
|
| 2662 | + * @access public |
|
| 2663 | + * @return void |
|
| 2664 | + * @throws DomainException |
|
| 2665 | + * @throws EE_Error |
|
| 2666 | + * @throws InvalidArgumentException |
|
| 2667 | + * @throws InvalidDataTypeException |
|
| 2668 | + * @throws InvalidInterfaceException |
|
| 2669 | + */ |
|
| 2670 | + public function _reg_registrant_side_meta_box() |
|
| 2671 | + { |
|
| 2672 | + /*@var $attendee EE_Attendee */ |
|
| 2673 | + $att_check = $this->_registration->attendee(); |
|
| 2674 | + $attendee = $att_check instanceof EE_Attendee ? $att_check : EEM_Attendee::instance()->create_default_object(); |
|
| 2675 | + // now let's determine if this is not the primary registration. If it isn't then we set the |
|
| 2676 | + // primary_registration object for reference BUT ONLY if the Attendee object loaded is not the same as the |
|
| 2677 | + // primary registration object (that way we know if we need to show create button or not) |
|
| 2678 | + if (! $this->_registration->is_primary_registrant()) { |
|
| 2679 | + $primary_registration = $this->_registration->get_primary_registration(); |
|
| 2680 | + $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() |
|
| 2681 | + : null; |
|
| 2682 | + if (! $primary_attendee instanceof EE_Attendee || $attendee->ID() !== $primary_attendee->ID()) { |
|
| 2683 | + // in here? This means the displayed registration is not the primary registrant but ALREADY HAS its own |
|
| 2684 | + // custom attendee object so let's not worry about the primary reg. |
|
| 2685 | + $primary_registration = null; |
|
| 2686 | + } |
|
| 2687 | + } else { |
|
| 2688 | + $primary_registration = null; |
|
| 2689 | + } |
|
| 2690 | + $this->_template_args['ATT_ID'] = $attendee->ID(); |
|
| 2691 | + $this->_template_args['fname'] = $attendee->fname(); |
|
| 2692 | + $this->_template_args['lname'] = $attendee->lname(); |
|
| 2693 | + $this->_template_args['email'] = $attendee->email(); |
|
| 2694 | + $this->_template_args['phone'] = $attendee->phone(); |
|
| 2695 | + $this->_template_args['formatted_address'] = EEH_Address::format($attendee); |
|
| 2696 | + // edit link |
|
| 2697 | + $this->_template_args['att_edit_link'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 2698 | + array( |
|
| 2699 | + 'action' => 'edit_attendee', |
|
| 2700 | + 'post' => $attendee->ID(), |
|
| 2701 | + ), |
|
| 2702 | + REG_ADMIN_URL |
|
| 2703 | + ); |
|
| 2704 | + $this->_template_args['att_edit_label'] = esc_html__('View/Edit Contact', 'event_espresso'); |
|
| 2705 | + // create link |
|
| 2706 | + $this->_template_args['create_link'] = $primary_registration instanceof EE_Registration |
|
| 2707 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 2708 | + array( |
|
| 2709 | + 'action' => 'duplicate_attendee', |
|
| 2710 | + '_REG_ID' => $this->_registration->ID(), |
|
| 2711 | + ), |
|
| 2712 | + REG_ADMIN_URL |
|
| 2713 | + ) : ''; |
|
| 2714 | + $this->_template_args['create_label'] = esc_html__('Create Contact', 'event_espresso'); |
|
| 2715 | + $this->_template_args['att_check'] = $att_check; |
|
| 2716 | + $template_path = REG_TEMPLATE_PATH . 'reg_admin_details_side_meta_box_registrant.template.php'; |
|
| 2717 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 2718 | + } |
|
| 2719 | + |
|
| 2720 | + |
|
| 2721 | + /** |
|
| 2722 | + * trash or restore registrations |
|
| 2723 | + * |
|
| 2724 | + * @param boolean $trash whether to archive or restore |
|
| 2725 | + * @return void |
|
| 2726 | + * @throws EE_Error |
|
| 2727 | + * @throws InvalidArgumentException |
|
| 2728 | + * @throws InvalidDataTypeException |
|
| 2729 | + * @throws InvalidInterfaceException |
|
| 2730 | + * @throws RuntimeException |
|
| 2731 | + * @access protected |
|
| 2732 | + */ |
|
| 2733 | + protected function _trash_or_restore_registrations($trash = true) |
|
| 2734 | + { |
|
| 2735 | + // if empty _REG_ID then get out because there's nothing to do |
|
| 2736 | + if (empty($this->_req_data['_REG_ID'])) { |
|
| 2737 | + EE_Error::add_error( |
|
| 2738 | + sprintf( |
|
| 2739 | + esc_html__( |
|
| 2740 | + 'In order to %1$s registrations you must select which ones you wish to %1$s by clicking the checkboxes.', |
|
| 2741 | + 'event_espresso' |
|
| 2742 | + ), |
|
| 2743 | + $trash ? 'trash' : 'restore' |
|
| 2744 | + ), |
|
| 2745 | + __FILE__, |
|
| 2746 | + __LINE__, |
|
| 2747 | + __FUNCTION__ |
|
| 2748 | + ); |
|
| 2749 | + $this->_redirect_after_action(false, '', '', array(), true); |
|
| 2750 | + } |
|
| 2751 | + $success = 0; |
|
| 2752 | + $overwrite_msgs = false; |
|
| 2753 | + // Checkboxes |
|
| 2754 | + if (! is_array($this->_req_data['_REG_ID'])) { |
|
| 2755 | + $this->_req_data['_REG_ID'] = array($this->_req_data['_REG_ID']); |
|
| 2756 | + } |
|
| 2757 | + $reg_count = count($this->_req_data['_REG_ID']); |
|
| 2758 | + // cycle thru checkboxes |
|
| 2759 | + foreach ($this->_req_data['_REG_ID'] as $REG_ID) { |
|
| 2760 | + /** @var EE_Registration $REG */ |
|
| 2761 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 2762 | + $payments = $REG->registration_payments(); |
|
| 2763 | + if (! empty($payments)) { |
|
| 2764 | + $name = $REG->attendee() instanceof EE_Attendee |
|
| 2765 | + ? $REG->attendee()->full_name() |
|
| 2766 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 2767 | + $overwrite_msgs = true; |
|
| 2768 | + EE_Error::add_error( |
|
| 2769 | + sprintf( |
|
| 2770 | + esc_html__( |
|
| 2771 | + '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.', |
|
| 2772 | + 'event_espresso' |
|
| 2773 | + ), |
|
| 2774 | + $name |
|
| 2775 | + ), |
|
| 2776 | + __FILE__, |
|
| 2777 | + __FUNCTION__, |
|
| 2778 | + __LINE__ |
|
| 2779 | + ); |
|
| 2780 | + // can't trash this registration because it has payments. |
|
| 2781 | + continue; |
|
| 2782 | + } |
|
| 2783 | + $updated = $trash ? $REG->delete() : $REG->restore(); |
|
| 2784 | + if ($updated) { |
|
| 2785 | + $success++; |
|
| 2786 | + } |
|
| 2787 | + } |
|
| 2788 | + $this->_redirect_after_action( |
|
| 2789 | + $success === $reg_count, // were ALL registrations affected? |
|
| 2790 | + $success > 1 |
|
| 2791 | + ? esc_html__('Registrations', 'event_espresso') |
|
| 2792 | + : esc_html__('Registration', 'event_espresso'), |
|
| 2793 | + $trash |
|
| 2794 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 2795 | + : esc_html__('restored', 'event_espresso'), |
|
| 2796 | + $this->mergeExistingRequestParamsWithRedirectArgs(array('action' => 'default')), |
|
| 2797 | + $overwrite_msgs |
|
| 2798 | + ); |
|
| 2799 | + } |
|
| 2800 | + |
|
| 2801 | + |
|
| 2802 | + /** |
|
| 2803 | + * This is used to permanently delete registrations. Note, this will handle not only deleting permanently the |
|
| 2804 | + * registration but also. |
|
| 2805 | + * 1. Removing relations to EE_Attendee |
|
| 2806 | + * 2. Deleting permanently the related transaction, but ONLY if all related registrations to the transaction are |
|
| 2807 | + * ALSO trashed. |
|
| 2808 | + * 3. Deleting permanently any related Line items but only if the above conditions are met. |
|
| 2809 | + * 4. Removing relationships between all tickets and the related registrations |
|
| 2810 | + * 5. Deleting permanently any related Answers (and the answers for other related registrations that were deleted.) |
|
| 2811 | + * 6. Deleting permanently any related Checkins. |
|
| 2812 | + * |
|
| 2813 | + * @return void |
|
| 2814 | + * @throws EE_Error |
|
| 2815 | + * @throws InvalidArgumentException |
|
| 2816 | + * @throws InvalidDataTypeException |
|
| 2817 | + * @throws InvalidInterfaceException |
|
| 2818 | + */ |
|
| 2819 | + protected function _delete_registrations() |
|
| 2820 | + { |
|
| 2821 | + $REG_MDL = EEM_Registration::instance(); |
|
| 2822 | + $success = 1; |
|
| 2823 | + // Checkboxes |
|
| 2824 | + if (! empty($this->_req_data['_REG_ID']) && is_array($this->_req_data['_REG_ID'])) { |
|
| 2825 | + // if array has more than one element than success message should be plural |
|
| 2826 | + $success = count($this->_req_data['_REG_ID']) > 1 ? 2 : 1; |
|
| 2827 | + // cycle thru checkboxes |
|
| 2828 | + while (list($ind, $REG_ID) = each($this->_req_data['_REG_ID'])) { |
|
| 2829 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2830 | + if (! $REG instanceof EE_Registration) { |
|
| 2831 | + continue; |
|
| 2832 | + } |
|
| 2833 | + $deleted = $this->_delete_registration($REG); |
|
| 2834 | + if (! $deleted) { |
|
| 2835 | + $success = 0; |
|
| 2836 | + } |
|
| 2837 | + } |
|
| 2838 | + } else { |
|
| 2839 | + // grab single id and delete |
|
| 2840 | + $REG_ID = $this->_req_data['_REG_ID']; |
|
| 2841 | + $REG = $REG_MDL->get_one_by_ID($REG_ID); |
|
| 2842 | + $deleted = $this->_delete_registration($REG); |
|
| 2843 | + if (! $deleted) { |
|
| 2844 | + $success = 0; |
|
| 2845 | + } |
|
| 2846 | + } |
|
| 2847 | + $what = $success > 1 |
|
| 2848 | + ? esc_html__('Registrations', 'event_espresso') |
|
| 2849 | + : esc_html__('Registration', 'event_espresso'); |
|
| 2850 | + $action_desc = esc_html__('permanently deleted.', 'event_espresso'); |
|
| 2851 | + $this->_redirect_after_action( |
|
| 2852 | + $success, |
|
| 2853 | + $what, |
|
| 2854 | + $action_desc, |
|
| 2855 | + $this->mergeExistingRequestParamsWithRedirectArgs(['action' => 'default']), |
|
| 2856 | + true |
|
| 2857 | + ); |
|
| 2858 | + } |
|
| 2859 | + |
|
| 2860 | + |
|
| 2861 | + /** |
|
| 2862 | + * handles the permanent deletion of a registration. See comments with _delete_registrations() for details on what |
|
| 2863 | + * models get affected. |
|
| 2864 | + * |
|
| 2865 | + * @param EE_Registration $REG registration to be deleted permenantly |
|
| 2866 | + * @return bool true = successful deletion, false = fail. |
|
| 2867 | + * @throws EE_Error |
|
| 2868 | + */ |
|
| 2869 | + protected function _delete_registration(EE_Registration $REG) |
|
| 2870 | + { |
|
| 2871 | + // first we start with the transaction... ultimately, we WILL not delete permanently if there are any related |
|
| 2872 | + // registrations on the transaction that are NOT trashed. |
|
| 2873 | + $TXN = $REG->get_first_related('Transaction'); |
|
| 2874 | + $REGS = $TXN->get_many_related('Registration'); |
|
| 2875 | + $all_trashed = true; |
|
| 2876 | + foreach ($REGS as $registration) { |
|
| 2877 | + if (! $registration->get('REG_deleted')) { |
|
| 2878 | + $all_trashed = false; |
|
| 2879 | + } |
|
| 2880 | + } |
|
| 2881 | + if (! $all_trashed) { |
|
| 2882 | + EE_Error::add_error( |
|
| 2883 | + esc_html__( |
|
| 2884 | + '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.', |
|
| 2885 | + 'event_espresso' |
|
| 2886 | + ), |
|
| 2887 | + __FILE__, |
|
| 2888 | + __FUNCTION__, |
|
| 2889 | + __LINE__ |
|
| 2890 | + ); |
|
| 2891 | + return false; |
|
| 2892 | + } |
|
| 2893 | + // k made it here so that means we can delete all the related transactions and their answers (but let's do them |
|
| 2894 | + // separately from THIS one). |
|
| 2895 | + foreach ($REGS as $registration) { |
|
| 2896 | + // delete related answers |
|
| 2897 | + $registration->delete_related_permanently('Answer'); |
|
| 2898 | + // remove relationship to EE_Attendee (but we ALWAYS leave the contact record intact) |
|
| 2899 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 2900 | + if ($attendee instanceof EE_Attendee) { |
|
| 2901 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 2902 | + } |
|
| 2903 | + // now remove relationships to tickets on this registration. |
|
| 2904 | + $registration->_remove_relations('Ticket'); |
|
| 2905 | + // now delete permanently the checkins related to this registration. |
|
| 2906 | + $registration->delete_related_permanently('Checkin'); |
|
| 2907 | + if ($registration->ID() === $REG->ID()) { |
|
| 2908 | + continue; |
|
| 2909 | + } //we don't want to delete permanently the existing registration just yet. |
|
| 2910 | + // remove relation to transaction for these registrations if NOT the existing registrations |
|
| 2911 | + $registration->_remove_relations('Transaction'); |
|
| 2912 | + // delete permanently any related messages. |
|
| 2913 | + $registration->delete_related_permanently('Message'); |
|
| 2914 | + // now delete this registration permanently |
|
| 2915 | + $registration->delete_permanently(); |
|
| 2916 | + } |
|
| 2917 | + // now all related registrations on the transaction are handled. So let's just handle this registration itself |
|
| 2918 | + // (the transaction and line items should be all that's left). |
|
| 2919 | + // delete the line items related to the transaction for this registration. |
|
| 2920 | + $TXN->delete_related_permanently('Line_Item'); |
|
| 2921 | + // we need to remove all the relationships on the transaction |
|
| 2922 | + $TXN->delete_related_permanently('Payment'); |
|
| 2923 | + $TXN->delete_related_permanently('Extra_Meta'); |
|
| 2924 | + $TXN->delete_related_permanently('Message'); |
|
| 2925 | + // now we can delete this REG permanently (and the transaction of course) |
|
| 2926 | + $REG->delete_related_permanently('Transaction'); |
|
| 2927 | + return $REG->delete_permanently(); |
|
| 2928 | + } |
|
| 2929 | + |
|
| 2930 | + |
|
| 2931 | + /** |
|
| 2932 | + * generates HTML for the Register New Attendee Admin page |
|
| 2933 | + * |
|
| 2934 | + * @access private |
|
| 2935 | + * @throws DomainException |
|
| 2936 | + * @throws EE_Error |
|
| 2937 | + */ |
|
| 2938 | + public function new_registration() |
|
| 2939 | + { |
|
| 2940 | + if (! $this->_set_reg_event()) { |
|
| 2941 | + throw new EE_Error( |
|
| 2942 | + esc_html__( |
|
| 2943 | + 'Unable to continue with registering because there is no Event ID in the request', |
|
| 2944 | + 'event_espresso' |
|
| 2945 | + ) |
|
| 2946 | + ); |
|
| 2947 | + } |
|
| 2948 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 2949 | + // gotta start with a clean slate if we're not coming here via ajax |
|
| 2950 | + if (! defined('DOING_AJAX') |
|
| 2951 | + && (! isset($this->_req_data['processing_registration']) || isset($this->_req_data['step_error'])) |
|
| 2952 | + ) { |
|
| 2953 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 2954 | + } |
|
| 2955 | + $this->_template_args['event_name'] = ''; |
|
| 2956 | + // event name |
|
| 2957 | + if ($this->_reg_event) { |
|
| 2958 | + $this->_template_args['event_name'] = $this->_reg_event->name(); |
|
| 2959 | + $edit_event_url = self::add_query_args_and_nonce( |
|
| 2960 | + array( |
|
| 2961 | + 'action' => 'edit', |
|
| 2962 | + 'post' => $this->_reg_event->ID(), |
|
| 2963 | + ), |
|
| 2964 | + EVENTS_ADMIN_URL |
|
| 2965 | + ); |
|
| 2966 | + $edit_event_lnk = '<a href="' |
|
| 2967 | + . $edit_event_url |
|
| 2968 | + . '" title="' |
|
| 2969 | + . esc_attr__('Edit ', 'event_espresso') |
|
| 2970 | + . $this->_reg_event->name() |
|
| 2971 | + . '">' |
|
| 2972 | + . esc_html__('Edit Event', 'event_espresso') |
|
| 2973 | + . '</a>'; |
|
| 2974 | + $this->_template_args['event_name'] .= ' <span class="admin-page-header-edit-lnk not-bold">' |
|
| 2975 | + . $edit_event_lnk |
|
| 2976 | + . '</span>'; |
|
| 2977 | + } |
|
| 2978 | + $this->_template_args['step_content'] = $this->_get_registration_step_content(); |
|
| 2979 | + if (defined('DOING_AJAX')) { |
|
| 2980 | + $this->_return_json(); |
|
| 2981 | + } |
|
| 2982 | + // grab header |
|
| 2983 | + $template_path = |
|
| 2984 | + REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee.template.php'; |
|
| 2985 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 2986 | + $template_path, |
|
| 2987 | + $this->_template_args, |
|
| 2988 | + true |
|
| 2989 | + ); |
|
| 2990 | + // $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
| 2991 | + // the details template wrapper |
|
| 2992 | + $this->display_admin_page_with_sidebar(); |
|
| 2993 | + } |
|
| 2994 | + |
|
| 2995 | + |
|
| 2996 | + /** |
|
| 2997 | + * This returns the content for a registration step |
|
| 2998 | + * |
|
| 2999 | + * @access protected |
|
| 3000 | + * @return string html |
|
| 3001 | + * @throws DomainException |
|
| 3002 | + * @throws EE_Error |
|
| 3003 | + * @throws InvalidArgumentException |
|
| 3004 | + * @throws InvalidDataTypeException |
|
| 3005 | + * @throws InvalidInterfaceException |
|
| 3006 | + */ |
|
| 3007 | + protected function _get_registration_step_content() |
|
| 3008 | + { |
|
| 3009 | + if (isset($_COOKIE['ee_registration_added']) && $_COOKIE['ee_registration_added']) { |
|
| 3010 | + $warning_msg = sprintf( |
|
| 3011 | + esc_html__( |
|
| 3012 | + '%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', |
|
| 3013 | + 'event_espresso' |
|
| 3014 | + ), |
|
| 3015 | + '<br />', |
|
| 3016 | + '<h3 class="important-notice">', |
|
| 3017 | + '</h3>', |
|
| 3018 | + '<div class="float-right">', |
|
| 3019 | + '<span id="redirect_timer" class="important-notice">30</span>', |
|
| 3020 | + '</div>', |
|
| 3021 | + '<b>', |
|
| 3022 | + '</b>' |
|
| 3023 | + ); |
|
| 3024 | + return ' |
|
| 3025 | 3025 | <div id="ee-add-reg-back-button-dv"><p>' . $warning_msg . '</p></div> |
| 3026 | 3026 | <script > |
| 3027 | 3027 | // WHOAH !!! it appears that someone is using the back button from the Transaction admin page |
@@ -3034,856 +3034,856 @@ discard block |
||
| 3034 | 3034 | } |
| 3035 | 3035 | }, 800 ); |
| 3036 | 3036 | </script >'; |
| 3037 | - } |
|
| 3038 | - $template_args = array( |
|
| 3039 | - 'title' => '', |
|
| 3040 | - 'content' => '', |
|
| 3041 | - 'step_button_text' => '', |
|
| 3042 | - 'show_notification_toggle' => false, |
|
| 3043 | - ); |
|
| 3044 | - // to indicate we're processing a new registration |
|
| 3045 | - $hidden_fields = array( |
|
| 3046 | - 'processing_registration' => array( |
|
| 3047 | - 'type' => 'hidden', |
|
| 3048 | - 'value' => 0, |
|
| 3049 | - ), |
|
| 3050 | - 'event_id' => array( |
|
| 3051 | - 'type' => 'hidden', |
|
| 3052 | - 'value' => $this->_reg_event->ID(), |
|
| 3053 | - ), |
|
| 3054 | - ); |
|
| 3055 | - // if the cart is empty then we know we're at step one so we'll display ticket selector |
|
| 3056 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
| 3057 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 3058 | - switch ($step) { |
|
| 3059 | - case 'ticket': |
|
| 3060 | - $hidden_fields['processing_registration']['value'] = 1; |
|
| 3061 | - $template_args['title'] = esc_html__( |
|
| 3062 | - 'Step One: Select the Ticket for this registration', |
|
| 3063 | - 'event_espresso' |
|
| 3064 | - ); |
|
| 3065 | - $template_args['content'] = |
|
| 3066 | - EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
| 3067 | - $template_args['content'] .= '</div>'; |
|
| 3068 | - $template_args['step_button_text'] = esc_html__( |
|
| 3069 | - 'Add Tickets and Continue to Registrant Details', |
|
| 3070 | - 'event_espresso' |
|
| 3071 | - ); |
|
| 3072 | - $template_args['show_notification_toggle'] = false; |
|
| 3073 | - break; |
|
| 3074 | - case 'questions': |
|
| 3075 | - $hidden_fields['processing_registration']['value'] = 2; |
|
| 3076 | - $template_args['title'] = esc_html__( |
|
| 3077 | - 'Step Two: Add Registrant Details for this Registration', |
|
| 3078 | - 'event_espresso' |
|
| 3079 | - ); |
|
| 3080 | - // in theory we should be able to run EED_SPCO at this point because the cart should have been setup |
|
| 3081 | - // properly by the first process_reg_step run. |
|
| 3082 | - $template_args['content'] = |
|
| 3083 | - EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
| 3084 | - $template_args['step_button_text'] = esc_html__( |
|
| 3085 | - 'Save Registration and Continue to Details', |
|
| 3086 | - 'event_espresso' |
|
| 3087 | - ); |
|
| 3088 | - $template_args['show_notification_toggle'] = true; |
|
| 3089 | - break; |
|
| 3090 | - } |
|
| 3091 | - // we come back to the process_registration_step route. |
|
| 3092 | - $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields); |
|
| 3093 | - return EEH_Template::display_template( |
|
| 3094 | - REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 3095 | - $template_args, |
|
| 3096 | - true |
|
| 3097 | - ); |
|
| 3098 | - } |
|
| 3099 | - |
|
| 3100 | - |
|
| 3101 | - /** |
|
| 3102 | - * set_reg_event |
|
| 3103 | - * |
|
| 3104 | - * @access private |
|
| 3105 | - * @return bool |
|
| 3106 | - * @throws EE_Error |
|
| 3107 | - * @throws InvalidArgumentException |
|
| 3108 | - * @throws InvalidDataTypeException |
|
| 3109 | - * @throws InvalidInterfaceException |
|
| 3110 | - */ |
|
| 3111 | - private function _set_reg_event() |
|
| 3112 | - { |
|
| 3113 | - if (is_object($this->_reg_event)) { |
|
| 3114 | - return true; |
|
| 3115 | - } |
|
| 3116 | - $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
| 3117 | - if (! $EVT_ID) { |
|
| 3118 | - return false; |
|
| 3119 | - } |
|
| 3120 | - $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 3121 | - return true; |
|
| 3122 | - } |
|
| 3123 | - |
|
| 3124 | - |
|
| 3125 | - /** |
|
| 3126 | - * process_reg_step |
|
| 3127 | - * |
|
| 3128 | - * @access public |
|
| 3129 | - * @return string |
|
| 3130 | - * @throws DomainException |
|
| 3131 | - * @throws EE_Error |
|
| 3132 | - * @throws InvalidArgumentException |
|
| 3133 | - * @throws InvalidDataTypeException |
|
| 3134 | - * @throws InvalidInterfaceException |
|
| 3135 | - * @throws ReflectionException |
|
| 3136 | - * @throws RuntimeException |
|
| 3137 | - */ |
|
| 3138 | - public function process_reg_step() |
|
| 3139 | - { |
|
| 3140 | - EE_System::do_not_cache(); |
|
| 3141 | - $this->_set_reg_event(); |
|
| 3142 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 3143 | - EE_Registry::instance()->REQ->set('uts', time()); |
|
| 3144 | - // what step are we on? |
|
| 3145 | - $cart = EE_Registry::instance()->SSN->cart(); |
|
| 3146 | - $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 3147 | - // if doing ajax then we need to verify the nonce |
|
| 3148 | - if (defined('DOING_AJAX')) { |
|
| 3149 | - $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
| 3150 | - ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : ''; |
|
| 3151 | - $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 3152 | - } |
|
| 3153 | - switch ($step) { |
|
| 3154 | - case 'ticket': |
|
| 3155 | - // process ticket selection |
|
| 3156 | - $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
| 3157 | - if ($success) { |
|
| 3158 | - EE_Error::add_success( |
|
| 3159 | - esc_html__( |
|
| 3160 | - 'Tickets Selected. Now complete the registration.', |
|
| 3161 | - 'event_espresso' |
|
| 3162 | - ) |
|
| 3163 | - ); |
|
| 3164 | - } else { |
|
| 3165 | - $query_args['step_error'] = $this->_req_data['step_error'] = true; |
|
| 3166 | - } |
|
| 3167 | - if (defined('DOING_AJAX')) { |
|
| 3168 | - $this->new_registration(); // display next step |
|
| 3169 | - } else { |
|
| 3170 | - $query_args = array( |
|
| 3171 | - 'action' => 'new_registration', |
|
| 3172 | - 'processing_registration' => 1, |
|
| 3173 | - 'event_id' => $this->_reg_event->ID(), |
|
| 3174 | - 'uts' => time(), |
|
| 3175 | - ); |
|
| 3176 | - $this->_redirect_after_action( |
|
| 3177 | - false, |
|
| 3178 | - '', |
|
| 3179 | - '', |
|
| 3180 | - $query_args, |
|
| 3181 | - true |
|
| 3182 | - ); |
|
| 3183 | - } |
|
| 3184 | - break; |
|
| 3185 | - case 'questions': |
|
| 3186 | - if (! isset( |
|
| 3187 | - $this->_req_data['txn_reg_status_change'], |
|
| 3188 | - $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 3189 | - ) |
|
| 3190 | - ) { |
|
| 3191 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
| 3192 | - } |
|
| 3193 | - // process registration |
|
| 3194 | - $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
| 3195 | - if ($cart instanceof EE_Cart) { |
|
| 3196 | - $grand_total = $cart->get_cart_grand_total(); |
|
| 3197 | - if ($grand_total instanceof EE_Line_Item) { |
|
| 3198 | - $grand_total->save_this_and_descendants_to_txn(); |
|
| 3199 | - } |
|
| 3200 | - } |
|
| 3201 | - if (! $transaction instanceof EE_Transaction) { |
|
| 3202 | - $query_args = array( |
|
| 3203 | - 'action' => 'new_registration', |
|
| 3204 | - 'processing_registration' => 2, |
|
| 3205 | - 'event_id' => $this->_reg_event->ID(), |
|
| 3206 | - 'uts' => time(), |
|
| 3207 | - ); |
|
| 3208 | - if (defined('DOING_AJAX')) { |
|
| 3209 | - // display registration form again because there are errors (maybe validation?) |
|
| 3210 | - $this->new_registration(); |
|
| 3211 | - return; |
|
| 3212 | - } else { |
|
| 3213 | - $this->_redirect_after_action( |
|
| 3214 | - false, |
|
| 3215 | - '', |
|
| 3216 | - '', |
|
| 3217 | - $query_args, |
|
| 3218 | - true |
|
| 3219 | - ); |
|
| 3220 | - return; |
|
| 3221 | - } |
|
| 3222 | - } |
|
| 3223 | - // maybe update status, and make sure to save transaction if not done already |
|
| 3224 | - if (! $transaction->update_status_based_on_total_paid()) { |
|
| 3225 | - $transaction->save(); |
|
| 3226 | - } |
|
| 3227 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 3228 | - $this->_req_data = array(); |
|
| 3229 | - $query_args = array( |
|
| 3230 | - 'action' => 'redirect_to_txn', |
|
| 3231 | - 'TXN_ID' => $transaction->ID(), |
|
| 3232 | - 'EVT_ID' => $this->_reg_event->ID(), |
|
| 3233 | - 'event_name' => urlencode($this->_reg_event->name()), |
|
| 3234 | - 'redirect_from' => 'new_registration', |
|
| 3235 | - ); |
|
| 3236 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3237 | - break; |
|
| 3238 | - } |
|
| 3239 | - // what are you looking here for? Should be nothing to do at this point. |
|
| 3240 | - } |
|
| 3241 | - |
|
| 3242 | - |
|
| 3243 | - /** |
|
| 3244 | - * redirect_to_txn |
|
| 3245 | - * |
|
| 3246 | - * @access public |
|
| 3247 | - * @return void |
|
| 3248 | - * @throws EE_Error |
|
| 3249 | - * @throws InvalidArgumentException |
|
| 3250 | - * @throws InvalidDataTypeException |
|
| 3251 | - * @throws InvalidInterfaceException |
|
| 3252 | - */ |
|
| 3253 | - public function redirect_to_txn() |
|
| 3254 | - { |
|
| 3255 | - EE_System::do_not_cache(); |
|
| 3256 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 3257 | - $query_args = array( |
|
| 3258 | - 'action' => 'view_transaction', |
|
| 3259 | - 'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0, |
|
| 3260 | - 'page' => 'espresso_transactions', |
|
| 3261 | - ); |
|
| 3262 | - if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) { |
|
| 3263 | - $query_args['EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 3264 | - $query_args['event_name'] = urlencode($this->_req_data['event_name']); |
|
| 3265 | - $query_args['redirect_from'] = $this->_req_data['redirect_from']; |
|
| 3266 | - } |
|
| 3267 | - EE_Error::add_success( |
|
| 3268 | - esc_html__( |
|
| 3269 | - 'Registration Created. Please review the transaction and add any payments as necessary', |
|
| 3270 | - 'event_espresso' |
|
| 3271 | - ) |
|
| 3272 | - ); |
|
| 3273 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3274 | - } |
|
| 3275 | - |
|
| 3276 | - |
|
| 3277 | - /** |
|
| 3278 | - * generates HTML for the Attendee Contact List |
|
| 3279 | - * |
|
| 3280 | - * @access protected |
|
| 3281 | - * @return void |
|
| 3282 | - */ |
|
| 3283 | - protected function _attendee_contact_list_table() |
|
| 3284 | - { |
|
| 3285 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3286 | - $this->_search_btn_label = esc_html__('Contacts', 'event_espresso'); |
|
| 3287 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 3288 | - } |
|
| 3289 | - |
|
| 3290 | - |
|
| 3291 | - /** |
|
| 3292 | - * get_attendees |
|
| 3293 | - * |
|
| 3294 | - * @param $per_page |
|
| 3295 | - * @param bool $count whether to return count or data. |
|
| 3296 | - * @param bool $trash |
|
| 3297 | - * @return array |
|
| 3298 | - * @throws EE_Error |
|
| 3299 | - * @throws InvalidArgumentException |
|
| 3300 | - * @throws InvalidDataTypeException |
|
| 3301 | - * @throws InvalidInterfaceException |
|
| 3302 | - * @access public |
|
| 3303 | - */ |
|
| 3304 | - public function get_attendees($per_page, $count = false, $trash = false) |
|
| 3305 | - { |
|
| 3306 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3307 | - require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 3308 | - $ATT_MDL = EEM_Attendee::instance(); |
|
| 3309 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 3310 | - switch ($this->_req_data['orderby']) { |
|
| 3311 | - case 'ATT_ID': |
|
| 3312 | - $orderby = 'ATT_ID'; |
|
| 3313 | - break; |
|
| 3314 | - case 'ATT_fname': |
|
| 3315 | - $orderby = 'ATT_fname'; |
|
| 3316 | - break; |
|
| 3317 | - case 'ATT_email': |
|
| 3318 | - $orderby = 'ATT_email'; |
|
| 3319 | - break; |
|
| 3320 | - case 'ATT_city': |
|
| 3321 | - $orderby = 'ATT_city'; |
|
| 3322 | - break; |
|
| 3323 | - case 'STA_ID': |
|
| 3324 | - $orderby = 'STA_ID'; |
|
| 3325 | - break; |
|
| 3326 | - case 'CNT_ID': |
|
| 3327 | - $orderby = 'CNT_ID'; |
|
| 3328 | - break; |
|
| 3329 | - case 'Registration_Count': |
|
| 3330 | - $orderby = 'Registration_Count'; |
|
| 3331 | - break; |
|
| 3332 | - default: |
|
| 3333 | - $orderby = 'ATT_lname'; |
|
| 3334 | - } |
|
| 3335 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 3336 | - ? $this->_req_data['order'] |
|
| 3337 | - : 'ASC'; |
|
| 3338 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 3339 | - ? $this->_req_data['paged'] |
|
| 3340 | - : 1; |
|
| 3341 | - $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
| 3342 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 3343 | - ? $this->_req_data['perpage'] |
|
| 3344 | - : $per_page; |
|
| 3345 | - $_where = array(); |
|
| 3346 | - if (! empty($this->_req_data['s'])) { |
|
| 3347 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 3348 | - $_where['OR'] = array( |
|
| 3349 | - 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
|
| 3350 | - 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
|
| 3351 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $sstr), |
|
| 3352 | - 'ATT_fname' => array('LIKE', $sstr), |
|
| 3353 | - 'ATT_lname' => array('LIKE', $sstr), |
|
| 3354 | - 'ATT_short_bio' => array('LIKE', $sstr), |
|
| 3355 | - 'ATT_email' => array('LIKE', $sstr), |
|
| 3356 | - 'ATT_address' => array('LIKE', $sstr), |
|
| 3357 | - 'ATT_address2' => array('LIKE', $sstr), |
|
| 3358 | - 'ATT_city' => array('LIKE', $sstr), |
|
| 3359 | - 'Country.CNT_name' => array('LIKE', $sstr), |
|
| 3360 | - 'State.STA_name' => array('LIKE', $sstr), |
|
| 3361 | - 'ATT_phone' => array('LIKE', $sstr), |
|
| 3362 | - 'Registration.REG_final_price' => array('LIKE', $sstr), |
|
| 3363 | - 'Registration.REG_code' => array('LIKE', $sstr), |
|
| 3364 | - 'Registration.REG_group_size' => array('LIKE', $sstr), |
|
| 3365 | - ); |
|
| 3366 | - } |
|
| 3367 | - $offset = ($current_page - 1) * $per_page; |
|
| 3368 | - $limit = $count ? null : array($offset, $per_page); |
|
| 3369 | - $query_args = array( |
|
| 3370 | - $_where, |
|
| 3371 | - 'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')), |
|
| 3372 | - 'limit' => $limit, |
|
| 3373 | - ); |
|
| 3374 | - if (! $count) { |
|
| 3375 | - $query_args['order_by'] = array($orderby => $sort); |
|
| 3376 | - } |
|
| 3377 | - if ($trash) { |
|
| 3378 | - $query_args[0]['status'] = array('!=', 'publish'); |
|
| 3379 | - $all_attendees = $count |
|
| 3380 | - ? $ATT_MDL->count($query_args, 'ATT_ID', true) |
|
| 3381 | - : $ATT_MDL->get_all($query_args); |
|
| 3382 | - } else { |
|
| 3383 | - $query_args[0]['status'] = array('IN', array('publish')); |
|
| 3384 | - $all_attendees = $count |
|
| 3385 | - ? $ATT_MDL->count($query_args, 'ATT_ID', true) |
|
| 3386 | - : $ATT_MDL->get_all($query_args); |
|
| 3387 | - } |
|
| 3388 | - return $all_attendees; |
|
| 3389 | - } |
|
| 3390 | - |
|
| 3391 | - |
|
| 3392 | - /** |
|
| 3393 | - * This is just taking care of resending the registration confirmation |
|
| 3394 | - * |
|
| 3395 | - * @access protected |
|
| 3396 | - * @return void |
|
| 3397 | - */ |
|
| 3398 | - protected function _resend_registration() |
|
| 3399 | - { |
|
| 3400 | - $this->_process_resend_registration(); |
|
| 3401 | - $query_args = isset($this->_req_data['redirect_to']) |
|
| 3402 | - ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID']) |
|
| 3403 | - : array('action' => 'default'); |
|
| 3404 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3405 | - } |
|
| 3406 | - |
|
| 3407 | - /** |
|
| 3408 | - * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
| 3409 | - * to use when selecting registrations |
|
| 3410 | - * |
|
| 3411 | - * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
| 3412 | - * the query parameters from the request |
|
| 3413 | - * @return void ends the request with a redirect or download |
|
| 3414 | - */ |
|
| 3415 | - public function _registrations_report_base($method_name_for_getting_query_params) |
|
| 3416 | - { |
|
| 3417 | - if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3418 | - wp_redirect( |
|
| 3419 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 3420 | - array( |
|
| 3421 | - 'page' => 'espresso_batch', |
|
| 3422 | - 'batch' => 'file', |
|
| 3423 | - 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 3424 | - 'filters' => urlencode( |
|
| 3425 | - serialize( |
|
| 3426 | - call_user_func( |
|
| 3427 | - array($this, $method_name_for_getting_query_params), |
|
| 3428 | - EEH_Array::is_set( |
|
| 3429 | - $this->_req_data, |
|
| 3430 | - 'filters', |
|
| 3431 | - array() |
|
| 3432 | - ) |
|
| 3433 | - ) |
|
| 3434 | - ) |
|
| 3435 | - ), |
|
| 3436 | - 'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false), |
|
| 3437 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
| 3438 | - 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 3439 | - ) |
|
| 3440 | - ) |
|
| 3441 | - ); |
|
| 3442 | - } else { |
|
| 3443 | - $new_request_args = array( |
|
| 3444 | - 'export' => 'report', |
|
| 3445 | - 'action' => 'registrations_report_for_event', |
|
| 3446 | - 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 3447 | - ); |
|
| 3448 | - $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 3449 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3450 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3451 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3452 | - $EE_Export->export(); |
|
| 3453 | - } |
|
| 3454 | - } |
|
| 3455 | - } |
|
| 3456 | - |
|
| 3457 | - |
|
| 3458 | - /** |
|
| 3459 | - * Creates a registration report using only query parameters in the request |
|
| 3460 | - * |
|
| 3461 | - * @return void |
|
| 3462 | - */ |
|
| 3463 | - public function _registrations_report() |
|
| 3464 | - { |
|
| 3465 | - $this->_registrations_report_base('_get_registration_query_parameters'); |
|
| 3466 | - } |
|
| 3467 | - |
|
| 3468 | - |
|
| 3469 | - public function _contact_list_export() |
|
| 3470 | - { |
|
| 3471 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3472 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3473 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3474 | - $EE_Export->export_attendees(); |
|
| 3475 | - } |
|
| 3476 | - } |
|
| 3477 | - |
|
| 3478 | - |
|
| 3479 | - public function _contact_list_report() |
|
| 3480 | - { |
|
| 3481 | - if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3482 | - wp_redirect( |
|
| 3483 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 3484 | - array( |
|
| 3485 | - 'page' => 'espresso_batch', |
|
| 3486 | - 'batch' => 'file', |
|
| 3487 | - 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
| 3488 | - 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 3489 | - ) |
|
| 3490 | - ) |
|
| 3491 | - ); |
|
| 3492 | - } else { |
|
| 3493 | - if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3494 | - require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3495 | - $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3496 | - $EE_Export->report_attendees(); |
|
| 3497 | - } |
|
| 3498 | - } |
|
| 3499 | - } |
|
| 3500 | - |
|
| 3501 | - |
|
| 3502 | - |
|
| 3503 | - |
|
| 3504 | - |
|
| 3505 | - /*************************************** ATTENDEE DETAILS ***************************************/ |
|
| 3506 | - /** |
|
| 3507 | - * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
| 3508 | - * |
|
| 3509 | - * @return void |
|
| 3510 | - * @throws EE_Error |
|
| 3511 | - * @throws InvalidArgumentException |
|
| 3512 | - * @throws InvalidDataTypeException |
|
| 3513 | - * @throws InvalidInterfaceException |
|
| 3514 | - */ |
|
| 3515 | - protected function _duplicate_attendee() |
|
| 3516 | - { |
|
| 3517 | - $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default'; |
|
| 3518 | - // verify we have necessary info |
|
| 3519 | - if (empty($this->_req_data['_REG_ID'])) { |
|
| 3520 | - EE_Error::add_error( |
|
| 3521 | - esc_html__( |
|
| 3522 | - 'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
| 3523 | - 'event_espresso' |
|
| 3524 | - ), |
|
| 3525 | - __FILE__, |
|
| 3526 | - __LINE__, |
|
| 3527 | - __FUNCTION__ |
|
| 3528 | - ); |
|
| 3529 | - $query_args = array('action' => $action); |
|
| 3530 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3531 | - } |
|
| 3532 | - // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
| 3533 | - $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']); |
|
| 3534 | - $attendee = $registration->attendee(); |
|
| 3535 | - // remove relation of existing attendee on registration |
|
| 3536 | - $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 3537 | - // new attendee |
|
| 3538 | - $new_attendee = clone $attendee; |
|
| 3539 | - $new_attendee->set('ATT_ID', 0); |
|
| 3540 | - $new_attendee->save(); |
|
| 3541 | - // add new attendee to reg |
|
| 3542 | - $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
| 3543 | - EE_Error::add_success( |
|
| 3544 | - esc_html__( |
|
| 3545 | - 'New Contact record created. Now make any edits you wish to make for this contact.', |
|
| 3546 | - 'event_espresso' |
|
| 3547 | - ) |
|
| 3548 | - ); |
|
| 3549 | - // redirect to edit page for attendee |
|
| 3550 | - $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee'); |
|
| 3551 | - $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3552 | - } |
|
| 3553 | - |
|
| 3554 | - |
|
| 3555 | - /** |
|
| 3556 | - * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook. |
|
| 3557 | - * |
|
| 3558 | - * @param int $post_id |
|
| 3559 | - * @param WP_POST $post |
|
| 3560 | - * @throws DomainException |
|
| 3561 | - * @throws EE_Error |
|
| 3562 | - * @throws InvalidArgumentException |
|
| 3563 | - * @throws InvalidDataTypeException |
|
| 3564 | - * @throws InvalidInterfaceException |
|
| 3565 | - * @throws LogicException |
|
| 3566 | - * @throws InvalidFormSubmissionException |
|
| 3567 | - */ |
|
| 3568 | - protected function _insert_update_cpt_item($post_id, $post) |
|
| 3569 | - { |
|
| 3570 | - $success = true; |
|
| 3571 | - $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees' |
|
| 3572 | - ? EEM_Attendee::instance()->get_one_by_ID($post_id) |
|
| 3573 | - : null; |
|
| 3574 | - // for attendee updates |
|
| 3575 | - if ($attendee instanceof EE_Attendee) { |
|
| 3576 | - // note we should only be UPDATING attendees at this point. |
|
| 3577 | - $updated_fields = array( |
|
| 3578 | - 'ATT_fname' => $this->_req_data['ATT_fname'], |
|
| 3579 | - 'ATT_lname' => $this->_req_data['ATT_lname'], |
|
| 3580 | - 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
| 3581 | - 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
|
| 3582 | - 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
|
| 3583 | - 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
|
| 3584 | - 'STA_ID' => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '', |
|
| 3585 | - 'CNT_ISO' => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '', |
|
| 3586 | - 'ATT_zip' => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '', |
|
| 3587 | - ); |
|
| 3588 | - foreach ($updated_fields as $field => $value) { |
|
| 3589 | - $attendee->set($field, $value); |
|
| 3590 | - } |
|
| 3591 | - |
|
| 3592 | - // process contact details metabox form handler (which will also save the attendee) |
|
| 3593 | - $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee); |
|
| 3594 | - $success = $contact_details_form->process($this->_req_data); |
|
| 3595 | - |
|
| 3596 | - $attendee_update_callbacks = apply_filters( |
|
| 3597 | - 'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
| 3598 | - array() |
|
| 3599 | - ); |
|
| 3600 | - foreach ($attendee_update_callbacks as $a_callback) { |
|
| 3601 | - if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) { |
|
| 3602 | - throw new EE_Error( |
|
| 3603 | - sprintf( |
|
| 3604 | - esc_html__( |
|
| 3605 | - '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.', |
|
| 3606 | - 'event_espresso' |
|
| 3607 | - ), |
|
| 3608 | - $a_callback |
|
| 3609 | - ) |
|
| 3610 | - ); |
|
| 3611 | - } |
|
| 3612 | - } |
|
| 3613 | - } |
|
| 3614 | - |
|
| 3615 | - if ($success === false) { |
|
| 3616 | - EE_Error::add_error( |
|
| 3617 | - esc_html__( |
|
| 3618 | - 'Something went wrong with updating the meta table data for the registration.', |
|
| 3619 | - 'event_espresso' |
|
| 3620 | - ), |
|
| 3621 | - __FILE__, |
|
| 3622 | - __FUNCTION__, |
|
| 3623 | - __LINE__ |
|
| 3624 | - ); |
|
| 3625 | - } |
|
| 3626 | - } |
|
| 3627 | - |
|
| 3628 | - |
|
| 3629 | - public function trash_cpt_item($post_id) |
|
| 3630 | - { |
|
| 3631 | - } |
|
| 3632 | - |
|
| 3633 | - |
|
| 3634 | - public function delete_cpt_item($post_id) |
|
| 3635 | - { |
|
| 3636 | - } |
|
| 3637 | - |
|
| 3638 | - |
|
| 3639 | - public function restore_cpt_item($post_id) |
|
| 3640 | - { |
|
| 3641 | - } |
|
| 3642 | - |
|
| 3643 | - |
|
| 3644 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
| 3645 | - { |
|
| 3646 | - } |
|
| 3647 | - |
|
| 3648 | - |
|
| 3649 | - public function attendee_editor_metaboxes() |
|
| 3650 | - { |
|
| 3651 | - $this->verify_cpt_object(); |
|
| 3652 | - remove_meta_box( |
|
| 3653 | - 'postexcerpt', |
|
| 3654 | - esc_html__('Excerpt', 'event_espresso'), |
|
| 3655 | - 'post_excerpt_meta_box', |
|
| 3656 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 3657 | - 'normal', |
|
| 3658 | - 'core' |
|
| 3659 | - ); |
|
| 3660 | - remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core'); |
|
| 3661 | - if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
| 3662 | - add_meta_box( |
|
| 3663 | - 'postexcerpt', |
|
| 3664 | - esc_html__('Short Biography', 'event_espresso'), |
|
| 3665 | - 'post_excerpt_meta_box', |
|
| 3666 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 3667 | - 'normal' |
|
| 3668 | - ); |
|
| 3669 | - } |
|
| 3670 | - if (post_type_supports('espresso_attendees', 'comments')) { |
|
| 3671 | - add_meta_box( |
|
| 3672 | - 'commentsdiv', |
|
| 3673 | - esc_html__('Notes on the Contact', 'event_espresso'), |
|
| 3674 | - 'post_comment_meta_box', |
|
| 3675 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 3676 | - 'normal', |
|
| 3677 | - 'core' |
|
| 3678 | - ); |
|
| 3679 | - } |
|
| 3680 | - add_meta_box( |
|
| 3681 | - 'attendee_contact_info', |
|
| 3682 | - esc_html__('Contact Info', 'event_espresso'), |
|
| 3683 | - array($this, 'attendee_contact_info'), |
|
| 3684 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 3685 | - 'side', |
|
| 3686 | - 'core' |
|
| 3687 | - ); |
|
| 3688 | - add_meta_box( |
|
| 3689 | - 'attendee_details_address', |
|
| 3690 | - esc_html__('Address Details', 'event_espresso'), |
|
| 3691 | - array($this, 'attendee_address_details'), |
|
| 3692 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 3693 | - 'normal', |
|
| 3694 | - 'core' |
|
| 3695 | - ); |
|
| 3696 | - add_meta_box( |
|
| 3697 | - 'attendee_registrations', |
|
| 3698 | - esc_html__('Registrations for this Contact', 'event_espresso'), |
|
| 3699 | - array($this, 'attendee_registrations_meta_box'), |
|
| 3700 | - $this->_cpt_routes[ $this->_req_action ], |
|
| 3701 | - 'normal', |
|
| 3702 | - 'high' |
|
| 3703 | - ); |
|
| 3704 | - } |
|
| 3705 | - |
|
| 3706 | - |
|
| 3707 | - /** |
|
| 3708 | - * Metabox for attendee contact info |
|
| 3709 | - * |
|
| 3710 | - * @param WP_Post $post wp post object |
|
| 3711 | - * @return string attendee contact info ( and form ) |
|
| 3712 | - * @throws EE_Error |
|
| 3713 | - * @throws InvalidArgumentException |
|
| 3714 | - * @throws InvalidDataTypeException |
|
| 3715 | - * @throws InvalidInterfaceException |
|
| 3716 | - * @throws LogicException |
|
| 3717 | - * @throws DomainException |
|
| 3718 | - */ |
|
| 3719 | - public function attendee_contact_info($post) |
|
| 3720 | - { |
|
| 3721 | - // get attendee object ( should already have it ) |
|
| 3722 | - $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj); |
|
| 3723 | - $form->enqueueStylesAndScripts(); |
|
| 3724 | - echo $form->display(); |
|
| 3725 | - } |
|
| 3726 | - |
|
| 3727 | - |
|
| 3728 | - /** |
|
| 3729 | - * Return form handler for the contact details metabox |
|
| 3730 | - * |
|
| 3731 | - * @param EE_Attendee $attendee |
|
| 3732 | - * @return AttendeeContactDetailsMetaboxFormHandler |
|
| 3733 | - * @throws DomainException |
|
| 3734 | - * @throws InvalidArgumentException |
|
| 3735 | - * @throws InvalidDataTypeException |
|
| 3736 | - * @throws InvalidInterfaceException |
|
| 3737 | - */ |
|
| 3738 | - protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee) |
|
| 3739 | - { |
|
| 3740 | - return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance()); |
|
| 3741 | - } |
|
| 3742 | - |
|
| 3743 | - |
|
| 3744 | - /** |
|
| 3745 | - * Metabox for attendee details |
|
| 3746 | - * |
|
| 3747 | - * @param WP_Post $post wp post object |
|
| 3748 | - * @throws DomainException |
|
| 3749 | - */ |
|
| 3750 | - public function attendee_address_details($post) |
|
| 3751 | - { |
|
| 3752 | - // get attendee object (should already have it) |
|
| 3753 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3754 | - $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3755 | - new EE_Question_Form_Input( |
|
| 3756 | - EE_Question::new_instance( |
|
| 3757 | - array( |
|
| 3758 | - 'QST_ID' => 0, |
|
| 3759 | - 'QST_display_text' => esc_html__('State/Province', 'event_espresso'), |
|
| 3760 | - 'QST_system' => 'admin-state', |
|
| 3761 | - ) |
|
| 3762 | - ), |
|
| 3763 | - EE_Answer::new_instance( |
|
| 3764 | - array( |
|
| 3765 | - 'ANS_ID' => 0, |
|
| 3766 | - 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
| 3767 | - ) |
|
| 3768 | - ), |
|
| 3769 | - array( |
|
| 3770 | - 'input_id' => 'STA_ID', |
|
| 3771 | - 'input_name' => 'STA_ID', |
|
| 3772 | - 'input_prefix' => '', |
|
| 3773 | - 'append_qstn_id' => false, |
|
| 3774 | - ) |
|
| 3775 | - ) |
|
| 3776 | - ); |
|
| 3777 | - $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3778 | - new EE_Question_Form_Input( |
|
| 3779 | - EE_Question::new_instance( |
|
| 3780 | - array( |
|
| 3781 | - 'QST_ID' => 0, |
|
| 3782 | - 'QST_display_text' => esc_html__('Country', 'event_espresso'), |
|
| 3783 | - 'QST_system' => 'admin-country', |
|
| 3784 | - ) |
|
| 3785 | - ), |
|
| 3786 | - EE_Answer::new_instance( |
|
| 3787 | - array( |
|
| 3788 | - 'ANS_ID' => 0, |
|
| 3789 | - 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
| 3790 | - ) |
|
| 3791 | - ), |
|
| 3792 | - array( |
|
| 3793 | - 'input_id' => 'CNT_ISO', |
|
| 3794 | - 'input_name' => 'CNT_ISO', |
|
| 3795 | - 'input_prefix' => '', |
|
| 3796 | - 'append_qstn_id' => false, |
|
| 3797 | - ) |
|
| 3798 | - ) |
|
| 3799 | - ); |
|
| 3800 | - $template = |
|
| 3801 | - REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 3802 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 3803 | - } |
|
| 3804 | - |
|
| 3805 | - |
|
| 3806 | - /** |
|
| 3807 | - * _attendee_details |
|
| 3808 | - * |
|
| 3809 | - * @access protected |
|
| 3810 | - * @param $post |
|
| 3811 | - * @return void |
|
| 3812 | - * @throws DomainException |
|
| 3813 | - * @throws EE_Error |
|
| 3814 | - */ |
|
| 3815 | - public function attendee_registrations_meta_box($post) |
|
| 3816 | - { |
|
| 3817 | - $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3818 | - $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
| 3819 | - $template = |
|
| 3820 | - REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 3821 | - EEH_Template::display_template($template, $this->_template_args); |
|
| 3822 | - } |
|
| 3823 | - |
|
| 3824 | - |
|
| 3825 | - /** |
|
| 3826 | - * add in the form fields for the attendee edit |
|
| 3827 | - * |
|
| 3828 | - * @param WP_Post $post wp post object |
|
| 3829 | - * @return string html for new form. |
|
| 3830 | - * @throws DomainException |
|
| 3831 | - */ |
|
| 3832 | - public function after_title_form_fields($post) |
|
| 3833 | - { |
|
| 3834 | - if ($post->post_type == 'espresso_attendees') { |
|
| 3835 | - $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 3836 | - $template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3837 | - EEH_Template::display_template($template, $template_args); |
|
| 3838 | - } |
|
| 3839 | - } |
|
| 3840 | - |
|
| 3841 | - |
|
| 3842 | - /** |
|
| 3843 | - * _trash_or_restore_attendee |
|
| 3844 | - * |
|
| 3845 | - * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 3846 | - * @return void |
|
| 3847 | - * @throws EE_Error |
|
| 3848 | - * @throws InvalidArgumentException |
|
| 3849 | - * @throws InvalidDataTypeException |
|
| 3850 | - * @throws InvalidInterfaceException |
|
| 3851 | - * @access protected |
|
| 3852 | - */ |
|
| 3853 | - protected function _trash_or_restore_attendees($trash = true) |
|
| 3854 | - { |
|
| 3855 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3856 | - $ATT_MDL = EEM_Attendee::instance(); |
|
| 3857 | - $success = 1; |
|
| 3858 | - // Checkboxes |
|
| 3859 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3860 | - // if array has more than one element than success message should be plural |
|
| 3861 | - $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3862 | - // cycle thru checkboxes |
|
| 3863 | - while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3864 | - $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID) |
|
| 3865 | - : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID); |
|
| 3866 | - if (! $updated) { |
|
| 3867 | - $success = 0; |
|
| 3868 | - } |
|
| 3869 | - } |
|
| 3870 | - } else { |
|
| 3871 | - // grab single id and delete |
|
| 3872 | - $ATT_ID = absint($this->_req_data['ATT_ID']); |
|
| 3873 | - // get attendee |
|
| 3874 | - $att = $ATT_MDL->get_one_by_ID($ATT_ID); |
|
| 3875 | - $updated = $trash ? $att->set_status('trash') : $att->set_status('publish'); |
|
| 3876 | - $updated = $att->save(); |
|
| 3877 | - if (! $updated) { |
|
| 3878 | - $success = 0; |
|
| 3879 | - } |
|
| 3880 | - } |
|
| 3881 | - $what = $success > 1 |
|
| 3882 | - ? esc_html__('Contacts', 'event_espresso') |
|
| 3883 | - : esc_html__('Contact', 'event_espresso'); |
|
| 3884 | - $action_desc = $trash |
|
| 3885 | - ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3886 | - : esc_html__('restored', 'event_espresso'); |
|
| 3887 | - $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list')); |
|
| 3888 | - } |
|
| 3037 | + } |
|
| 3038 | + $template_args = array( |
|
| 3039 | + 'title' => '', |
|
| 3040 | + 'content' => '', |
|
| 3041 | + 'step_button_text' => '', |
|
| 3042 | + 'show_notification_toggle' => false, |
|
| 3043 | + ); |
|
| 3044 | + // to indicate we're processing a new registration |
|
| 3045 | + $hidden_fields = array( |
|
| 3046 | + 'processing_registration' => array( |
|
| 3047 | + 'type' => 'hidden', |
|
| 3048 | + 'value' => 0, |
|
| 3049 | + ), |
|
| 3050 | + 'event_id' => array( |
|
| 3051 | + 'type' => 'hidden', |
|
| 3052 | + 'value' => $this->_reg_event->ID(), |
|
| 3053 | + ), |
|
| 3054 | + ); |
|
| 3055 | + // if the cart is empty then we know we're at step one so we'll display ticket selector |
|
| 3056 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
| 3057 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 3058 | + switch ($step) { |
|
| 3059 | + case 'ticket': |
|
| 3060 | + $hidden_fields['processing_registration']['value'] = 1; |
|
| 3061 | + $template_args['title'] = esc_html__( |
|
| 3062 | + 'Step One: Select the Ticket for this registration', |
|
| 3063 | + 'event_espresso' |
|
| 3064 | + ); |
|
| 3065 | + $template_args['content'] = |
|
| 3066 | + EED_Ticket_Selector::instance()->display_ticket_selector($this->_reg_event); |
|
| 3067 | + $template_args['content'] .= '</div>'; |
|
| 3068 | + $template_args['step_button_text'] = esc_html__( |
|
| 3069 | + 'Add Tickets and Continue to Registrant Details', |
|
| 3070 | + 'event_espresso' |
|
| 3071 | + ); |
|
| 3072 | + $template_args['show_notification_toggle'] = false; |
|
| 3073 | + break; |
|
| 3074 | + case 'questions': |
|
| 3075 | + $hidden_fields['processing_registration']['value'] = 2; |
|
| 3076 | + $template_args['title'] = esc_html__( |
|
| 3077 | + 'Step Two: Add Registrant Details for this Registration', |
|
| 3078 | + 'event_espresso' |
|
| 3079 | + ); |
|
| 3080 | + // in theory we should be able to run EED_SPCO at this point because the cart should have been setup |
|
| 3081 | + // properly by the first process_reg_step run. |
|
| 3082 | + $template_args['content'] = |
|
| 3083 | + EED_Single_Page_Checkout::registration_checkout_for_admin(); |
|
| 3084 | + $template_args['step_button_text'] = esc_html__( |
|
| 3085 | + 'Save Registration and Continue to Details', |
|
| 3086 | + 'event_espresso' |
|
| 3087 | + ); |
|
| 3088 | + $template_args['show_notification_toggle'] = true; |
|
| 3089 | + break; |
|
| 3090 | + } |
|
| 3091 | + // we come back to the process_registration_step route. |
|
| 3092 | + $this->_set_add_edit_form_tags('process_reg_step', $hidden_fields); |
|
| 3093 | + return EEH_Template::display_template( |
|
| 3094 | + REG_TEMPLATE_PATH . 'reg_admin_register_new_attendee_step_content.template.php', |
|
| 3095 | + $template_args, |
|
| 3096 | + true |
|
| 3097 | + ); |
|
| 3098 | + } |
|
| 3099 | + |
|
| 3100 | + |
|
| 3101 | + /** |
|
| 3102 | + * set_reg_event |
|
| 3103 | + * |
|
| 3104 | + * @access private |
|
| 3105 | + * @return bool |
|
| 3106 | + * @throws EE_Error |
|
| 3107 | + * @throws InvalidArgumentException |
|
| 3108 | + * @throws InvalidDataTypeException |
|
| 3109 | + * @throws InvalidInterfaceException |
|
| 3110 | + */ |
|
| 3111 | + private function _set_reg_event() |
|
| 3112 | + { |
|
| 3113 | + if (is_object($this->_reg_event)) { |
|
| 3114 | + return true; |
|
| 3115 | + } |
|
| 3116 | + $EVT_ID = (! empty($this->_req_data['event_id'])) ? absint($this->_req_data['event_id']) : false; |
|
| 3117 | + if (! $EVT_ID) { |
|
| 3118 | + return false; |
|
| 3119 | + } |
|
| 3120 | + $this->_reg_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 3121 | + return true; |
|
| 3122 | + } |
|
| 3123 | + |
|
| 3124 | + |
|
| 3125 | + /** |
|
| 3126 | + * process_reg_step |
|
| 3127 | + * |
|
| 3128 | + * @access public |
|
| 3129 | + * @return string |
|
| 3130 | + * @throws DomainException |
|
| 3131 | + * @throws EE_Error |
|
| 3132 | + * @throws InvalidArgumentException |
|
| 3133 | + * @throws InvalidDataTypeException |
|
| 3134 | + * @throws InvalidInterfaceException |
|
| 3135 | + * @throws ReflectionException |
|
| 3136 | + * @throws RuntimeException |
|
| 3137 | + */ |
|
| 3138 | + public function process_reg_step() |
|
| 3139 | + { |
|
| 3140 | + EE_System::do_not_cache(); |
|
| 3141 | + $this->_set_reg_event(); |
|
| 3142 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
| 3143 | + EE_Registry::instance()->REQ->set('uts', time()); |
|
| 3144 | + // what step are we on? |
|
| 3145 | + $cart = EE_Registry::instance()->SSN->cart(); |
|
| 3146 | + $step = ! $cart instanceof EE_Cart ? 'ticket' : 'questions'; |
|
| 3147 | + // if doing ajax then we need to verify the nonce |
|
| 3148 | + if (defined('DOING_AJAX')) { |
|
| 3149 | + $nonce = isset($this->_req_data[ $this->_req_nonce ]) |
|
| 3150 | + ? sanitize_text_field($this->_req_data[ $this->_req_nonce ]) : ''; |
|
| 3151 | + $this->_verify_nonce($nonce, $this->_req_nonce); |
|
| 3152 | + } |
|
| 3153 | + switch ($step) { |
|
| 3154 | + case 'ticket': |
|
| 3155 | + // process ticket selection |
|
| 3156 | + $success = EED_Ticket_Selector::instance()->process_ticket_selections(); |
|
| 3157 | + if ($success) { |
|
| 3158 | + EE_Error::add_success( |
|
| 3159 | + esc_html__( |
|
| 3160 | + 'Tickets Selected. Now complete the registration.', |
|
| 3161 | + 'event_espresso' |
|
| 3162 | + ) |
|
| 3163 | + ); |
|
| 3164 | + } else { |
|
| 3165 | + $query_args['step_error'] = $this->_req_data['step_error'] = true; |
|
| 3166 | + } |
|
| 3167 | + if (defined('DOING_AJAX')) { |
|
| 3168 | + $this->new_registration(); // display next step |
|
| 3169 | + } else { |
|
| 3170 | + $query_args = array( |
|
| 3171 | + 'action' => 'new_registration', |
|
| 3172 | + 'processing_registration' => 1, |
|
| 3173 | + 'event_id' => $this->_reg_event->ID(), |
|
| 3174 | + 'uts' => time(), |
|
| 3175 | + ); |
|
| 3176 | + $this->_redirect_after_action( |
|
| 3177 | + false, |
|
| 3178 | + '', |
|
| 3179 | + '', |
|
| 3180 | + $query_args, |
|
| 3181 | + true |
|
| 3182 | + ); |
|
| 3183 | + } |
|
| 3184 | + break; |
|
| 3185 | + case 'questions': |
|
| 3186 | + if (! isset( |
|
| 3187 | + $this->_req_data['txn_reg_status_change'], |
|
| 3188 | + $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 3189 | + ) |
|
| 3190 | + ) { |
|
| 3191 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_false', 15); |
|
| 3192 | + } |
|
| 3193 | + // process registration |
|
| 3194 | + $transaction = EED_Single_Page_Checkout::instance()->process_registration_from_admin(); |
|
| 3195 | + if ($cart instanceof EE_Cart) { |
|
| 3196 | + $grand_total = $cart->get_cart_grand_total(); |
|
| 3197 | + if ($grand_total instanceof EE_Line_Item) { |
|
| 3198 | + $grand_total->save_this_and_descendants_to_txn(); |
|
| 3199 | + } |
|
| 3200 | + } |
|
| 3201 | + if (! $transaction instanceof EE_Transaction) { |
|
| 3202 | + $query_args = array( |
|
| 3203 | + 'action' => 'new_registration', |
|
| 3204 | + 'processing_registration' => 2, |
|
| 3205 | + 'event_id' => $this->_reg_event->ID(), |
|
| 3206 | + 'uts' => time(), |
|
| 3207 | + ); |
|
| 3208 | + if (defined('DOING_AJAX')) { |
|
| 3209 | + // display registration form again because there are errors (maybe validation?) |
|
| 3210 | + $this->new_registration(); |
|
| 3211 | + return; |
|
| 3212 | + } else { |
|
| 3213 | + $this->_redirect_after_action( |
|
| 3214 | + false, |
|
| 3215 | + '', |
|
| 3216 | + '', |
|
| 3217 | + $query_args, |
|
| 3218 | + true |
|
| 3219 | + ); |
|
| 3220 | + return; |
|
| 3221 | + } |
|
| 3222 | + } |
|
| 3223 | + // maybe update status, and make sure to save transaction if not done already |
|
| 3224 | + if (! $transaction->update_status_based_on_total_paid()) { |
|
| 3225 | + $transaction->save(); |
|
| 3226 | + } |
|
| 3227 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 3228 | + $this->_req_data = array(); |
|
| 3229 | + $query_args = array( |
|
| 3230 | + 'action' => 'redirect_to_txn', |
|
| 3231 | + 'TXN_ID' => $transaction->ID(), |
|
| 3232 | + 'EVT_ID' => $this->_reg_event->ID(), |
|
| 3233 | + 'event_name' => urlencode($this->_reg_event->name()), |
|
| 3234 | + 'redirect_from' => 'new_registration', |
|
| 3235 | + ); |
|
| 3236 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3237 | + break; |
|
| 3238 | + } |
|
| 3239 | + // what are you looking here for? Should be nothing to do at this point. |
|
| 3240 | + } |
|
| 3241 | + |
|
| 3242 | + |
|
| 3243 | + /** |
|
| 3244 | + * redirect_to_txn |
|
| 3245 | + * |
|
| 3246 | + * @access public |
|
| 3247 | + * @return void |
|
| 3248 | + * @throws EE_Error |
|
| 3249 | + * @throws InvalidArgumentException |
|
| 3250 | + * @throws InvalidDataTypeException |
|
| 3251 | + * @throws InvalidInterfaceException |
|
| 3252 | + */ |
|
| 3253 | + public function redirect_to_txn() |
|
| 3254 | + { |
|
| 3255 | + EE_System::do_not_cache(); |
|
| 3256 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 3257 | + $query_args = array( |
|
| 3258 | + 'action' => 'view_transaction', |
|
| 3259 | + 'TXN_ID' => isset($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : 0, |
|
| 3260 | + 'page' => 'espresso_transactions', |
|
| 3261 | + ); |
|
| 3262 | + if (isset($this->_req_data['EVT_ID'], $this->_req_data['redirect_from'])) { |
|
| 3263 | + $query_args['EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 3264 | + $query_args['event_name'] = urlencode($this->_req_data['event_name']); |
|
| 3265 | + $query_args['redirect_from'] = $this->_req_data['redirect_from']; |
|
| 3266 | + } |
|
| 3267 | + EE_Error::add_success( |
|
| 3268 | + esc_html__( |
|
| 3269 | + 'Registration Created. Please review the transaction and add any payments as necessary', |
|
| 3270 | + 'event_espresso' |
|
| 3271 | + ) |
|
| 3272 | + ); |
|
| 3273 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3274 | + } |
|
| 3275 | + |
|
| 3276 | + |
|
| 3277 | + /** |
|
| 3278 | + * generates HTML for the Attendee Contact List |
|
| 3279 | + * |
|
| 3280 | + * @access protected |
|
| 3281 | + * @return void |
|
| 3282 | + */ |
|
| 3283 | + protected function _attendee_contact_list_table() |
|
| 3284 | + { |
|
| 3285 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3286 | + $this->_search_btn_label = esc_html__('Contacts', 'event_espresso'); |
|
| 3287 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 3288 | + } |
|
| 3289 | + |
|
| 3290 | + |
|
| 3291 | + /** |
|
| 3292 | + * get_attendees |
|
| 3293 | + * |
|
| 3294 | + * @param $per_page |
|
| 3295 | + * @param bool $count whether to return count or data. |
|
| 3296 | + * @param bool $trash |
|
| 3297 | + * @return array |
|
| 3298 | + * @throws EE_Error |
|
| 3299 | + * @throws InvalidArgumentException |
|
| 3300 | + * @throws InvalidDataTypeException |
|
| 3301 | + * @throws InvalidInterfaceException |
|
| 3302 | + * @access public |
|
| 3303 | + */ |
|
| 3304 | + public function get_attendees($per_page, $count = false, $trash = false) |
|
| 3305 | + { |
|
| 3306 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3307 | + require_once(REG_ADMIN . 'EE_Attendee_Contact_List_Table.class.php'); |
|
| 3308 | + $ATT_MDL = EEM_Attendee::instance(); |
|
| 3309 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 3310 | + switch ($this->_req_data['orderby']) { |
|
| 3311 | + case 'ATT_ID': |
|
| 3312 | + $orderby = 'ATT_ID'; |
|
| 3313 | + break; |
|
| 3314 | + case 'ATT_fname': |
|
| 3315 | + $orderby = 'ATT_fname'; |
|
| 3316 | + break; |
|
| 3317 | + case 'ATT_email': |
|
| 3318 | + $orderby = 'ATT_email'; |
|
| 3319 | + break; |
|
| 3320 | + case 'ATT_city': |
|
| 3321 | + $orderby = 'ATT_city'; |
|
| 3322 | + break; |
|
| 3323 | + case 'STA_ID': |
|
| 3324 | + $orderby = 'STA_ID'; |
|
| 3325 | + break; |
|
| 3326 | + case 'CNT_ID': |
|
| 3327 | + $orderby = 'CNT_ID'; |
|
| 3328 | + break; |
|
| 3329 | + case 'Registration_Count': |
|
| 3330 | + $orderby = 'Registration_Count'; |
|
| 3331 | + break; |
|
| 3332 | + default: |
|
| 3333 | + $orderby = 'ATT_lname'; |
|
| 3334 | + } |
|
| 3335 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) |
|
| 3336 | + ? $this->_req_data['order'] |
|
| 3337 | + : 'ASC'; |
|
| 3338 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) |
|
| 3339 | + ? $this->_req_data['paged'] |
|
| 3340 | + : 1; |
|
| 3341 | + $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
| 3342 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) |
|
| 3343 | + ? $this->_req_data['perpage'] |
|
| 3344 | + : $per_page; |
|
| 3345 | + $_where = array(); |
|
| 3346 | + if (! empty($this->_req_data['s'])) { |
|
| 3347 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
| 3348 | + $_where['OR'] = array( |
|
| 3349 | + 'Registration.Event.EVT_name' => array('LIKE', $sstr), |
|
| 3350 | + 'Registration.Event.EVT_desc' => array('LIKE', $sstr), |
|
| 3351 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $sstr), |
|
| 3352 | + 'ATT_fname' => array('LIKE', $sstr), |
|
| 3353 | + 'ATT_lname' => array('LIKE', $sstr), |
|
| 3354 | + 'ATT_short_bio' => array('LIKE', $sstr), |
|
| 3355 | + 'ATT_email' => array('LIKE', $sstr), |
|
| 3356 | + 'ATT_address' => array('LIKE', $sstr), |
|
| 3357 | + 'ATT_address2' => array('LIKE', $sstr), |
|
| 3358 | + 'ATT_city' => array('LIKE', $sstr), |
|
| 3359 | + 'Country.CNT_name' => array('LIKE', $sstr), |
|
| 3360 | + 'State.STA_name' => array('LIKE', $sstr), |
|
| 3361 | + 'ATT_phone' => array('LIKE', $sstr), |
|
| 3362 | + 'Registration.REG_final_price' => array('LIKE', $sstr), |
|
| 3363 | + 'Registration.REG_code' => array('LIKE', $sstr), |
|
| 3364 | + 'Registration.REG_group_size' => array('LIKE', $sstr), |
|
| 3365 | + ); |
|
| 3366 | + } |
|
| 3367 | + $offset = ($current_page - 1) * $per_page; |
|
| 3368 | + $limit = $count ? null : array($offset, $per_page); |
|
| 3369 | + $query_args = array( |
|
| 3370 | + $_where, |
|
| 3371 | + 'extra_selects' => array('Registration_Count' => array('Registration.REG_ID', 'count', '%d')), |
|
| 3372 | + 'limit' => $limit, |
|
| 3373 | + ); |
|
| 3374 | + if (! $count) { |
|
| 3375 | + $query_args['order_by'] = array($orderby => $sort); |
|
| 3376 | + } |
|
| 3377 | + if ($trash) { |
|
| 3378 | + $query_args[0]['status'] = array('!=', 'publish'); |
|
| 3379 | + $all_attendees = $count |
|
| 3380 | + ? $ATT_MDL->count($query_args, 'ATT_ID', true) |
|
| 3381 | + : $ATT_MDL->get_all($query_args); |
|
| 3382 | + } else { |
|
| 3383 | + $query_args[0]['status'] = array('IN', array('publish')); |
|
| 3384 | + $all_attendees = $count |
|
| 3385 | + ? $ATT_MDL->count($query_args, 'ATT_ID', true) |
|
| 3386 | + : $ATT_MDL->get_all($query_args); |
|
| 3387 | + } |
|
| 3388 | + return $all_attendees; |
|
| 3389 | + } |
|
| 3390 | + |
|
| 3391 | + |
|
| 3392 | + /** |
|
| 3393 | + * This is just taking care of resending the registration confirmation |
|
| 3394 | + * |
|
| 3395 | + * @access protected |
|
| 3396 | + * @return void |
|
| 3397 | + */ |
|
| 3398 | + protected function _resend_registration() |
|
| 3399 | + { |
|
| 3400 | + $this->_process_resend_registration(); |
|
| 3401 | + $query_args = isset($this->_req_data['redirect_to']) |
|
| 3402 | + ? array('action' => $this->_req_data['redirect_to'], '_REG_ID' => $this->_req_data['_REG_ID']) |
|
| 3403 | + : array('action' => 'default'); |
|
| 3404 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 3405 | + } |
|
| 3406 | + |
|
| 3407 | + /** |
|
| 3408 | + * Creates a registration report, but accepts the name of a method to use for preparing the query parameters |
|
| 3409 | + * to use when selecting registrations |
|
| 3410 | + * |
|
| 3411 | + * @param string $method_name_for_getting_query_params the name of the method (on this class) to use for preparing |
|
| 3412 | + * the query parameters from the request |
|
| 3413 | + * @return void ends the request with a redirect or download |
|
| 3414 | + */ |
|
| 3415 | + public function _registrations_report_base($method_name_for_getting_query_params) |
|
| 3416 | + { |
|
| 3417 | + if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3418 | + wp_redirect( |
|
| 3419 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 3420 | + array( |
|
| 3421 | + 'page' => 'espresso_batch', |
|
| 3422 | + 'batch' => 'file', |
|
| 3423 | + 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 3424 | + 'filters' => urlencode( |
|
| 3425 | + serialize( |
|
| 3426 | + call_user_func( |
|
| 3427 | + array($this, $method_name_for_getting_query_params), |
|
| 3428 | + EEH_Array::is_set( |
|
| 3429 | + $this->_req_data, |
|
| 3430 | + 'filters', |
|
| 3431 | + array() |
|
| 3432 | + ) |
|
| 3433 | + ) |
|
| 3434 | + ) |
|
| 3435 | + ), |
|
| 3436 | + 'use_filters' => EEH_Array::is_set($this->_req_data, 'use_filters', false), |
|
| 3437 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\RegistrationsReport'), |
|
| 3438 | + 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 3439 | + ) |
|
| 3440 | + ) |
|
| 3441 | + ); |
|
| 3442 | + } else { |
|
| 3443 | + $new_request_args = array( |
|
| 3444 | + 'export' => 'report', |
|
| 3445 | + 'action' => 'registrations_report_for_event', |
|
| 3446 | + 'EVT_ID' => isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null, |
|
| 3447 | + ); |
|
| 3448 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
| 3449 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3450 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3451 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3452 | + $EE_Export->export(); |
|
| 3453 | + } |
|
| 3454 | + } |
|
| 3455 | + } |
|
| 3456 | + |
|
| 3457 | + |
|
| 3458 | + /** |
|
| 3459 | + * Creates a registration report using only query parameters in the request |
|
| 3460 | + * |
|
| 3461 | + * @return void |
|
| 3462 | + */ |
|
| 3463 | + public function _registrations_report() |
|
| 3464 | + { |
|
| 3465 | + $this->_registrations_report_base('_get_registration_query_parameters'); |
|
| 3466 | + } |
|
| 3467 | + |
|
| 3468 | + |
|
| 3469 | + public function _contact_list_export() |
|
| 3470 | + { |
|
| 3471 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3472 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3473 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3474 | + $EE_Export->export_attendees(); |
|
| 3475 | + } |
|
| 3476 | + } |
|
| 3477 | + |
|
| 3478 | + |
|
| 3479 | + public function _contact_list_report() |
|
| 3480 | + { |
|
| 3481 | + if (! defined('EE_USE_OLD_CSV_REPORT_CLASS')) { |
|
| 3482 | + wp_redirect( |
|
| 3483 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 3484 | + array( |
|
| 3485 | + 'page' => 'espresso_batch', |
|
| 3486 | + 'batch' => 'file', |
|
| 3487 | + 'job_handler' => urlencode('EventEspressoBatchRequest\JobHandlers\AttendeesReport'), |
|
| 3488 | + 'return_url' => urlencode($this->_req_data['return_url']), |
|
| 3489 | + ) |
|
| 3490 | + ) |
|
| 3491 | + ); |
|
| 3492 | + } else { |
|
| 3493 | + if (is_readable(EE_CLASSES . 'EE_Export.class.php')) { |
|
| 3494 | + require_once(EE_CLASSES . 'EE_Export.class.php'); |
|
| 3495 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
| 3496 | + $EE_Export->report_attendees(); |
|
| 3497 | + } |
|
| 3498 | + } |
|
| 3499 | + } |
|
| 3500 | + |
|
| 3501 | + |
|
| 3502 | + |
|
| 3503 | + |
|
| 3504 | + |
|
| 3505 | + /*************************************** ATTENDEE DETAILS ***************************************/ |
|
| 3506 | + /** |
|
| 3507 | + * This duplicates the attendee object for the given incoming registration id and attendee_id. |
|
| 3508 | + * |
|
| 3509 | + * @return void |
|
| 3510 | + * @throws EE_Error |
|
| 3511 | + * @throws InvalidArgumentException |
|
| 3512 | + * @throws InvalidDataTypeException |
|
| 3513 | + * @throws InvalidInterfaceException |
|
| 3514 | + */ |
|
| 3515 | + protected function _duplicate_attendee() |
|
| 3516 | + { |
|
| 3517 | + $action = ! empty($this->_req_data['return']) ? $this->_req_data['return'] : 'default'; |
|
| 3518 | + // verify we have necessary info |
|
| 3519 | + if (empty($this->_req_data['_REG_ID'])) { |
|
| 3520 | + EE_Error::add_error( |
|
| 3521 | + esc_html__( |
|
| 3522 | + 'Unable to create the contact for the registration because the required parameters are not present (_REG_ID )', |
|
| 3523 | + 'event_espresso' |
|
| 3524 | + ), |
|
| 3525 | + __FILE__, |
|
| 3526 | + __LINE__, |
|
| 3527 | + __FUNCTION__ |
|
| 3528 | + ); |
|
| 3529 | + $query_args = array('action' => $action); |
|
| 3530 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3531 | + } |
|
| 3532 | + // okay necessary deets present... let's dupe the incoming attendee and attach to incoming registration. |
|
| 3533 | + $registration = EEM_Registration::instance()->get_one_by_ID($this->_req_data['_REG_ID']); |
|
| 3534 | + $attendee = $registration->attendee(); |
|
| 3535 | + // remove relation of existing attendee on registration |
|
| 3536 | + $registration->_remove_relation_to($attendee, 'Attendee'); |
|
| 3537 | + // new attendee |
|
| 3538 | + $new_attendee = clone $attendee; |
|
| 3539 | + $new_attendee->set('ATT_ID', 0); |
|
| 3540 | + $new_attendee->save(); |
|
| 3541 | + // add new attendee to reg |
|
| 3542 | + $registration->_add_relation_to($new_attendee, 'Attendee'); |
|
| 3543 | + EE_Error::add_success( |
|
| 3544 | + esc_html__( |
|
| 3545 | + 'New Contact record created. Now make any edits you wish to make for this contact.', |
|
| 3546 | + 'event_espresso' |
|
| 3547 | + ) |
|
| 3548 | + ); |
|
| 3549 | + // redirect to edit page for attendee |
|
| 3550 | + $query_args = array('post' => $new_attendee->ID(), 'action' => 'edit_attendee'); |
|
| 3551 | + $this->_redirect_after_action('', '', '', $query_args, true); |
|
| 3552 | + } |
|
| 3553 | + |
|
| 3554 | + |
|
| 3555 | + /** |
|
| 3556 | + * Callback invoked by parent EE_Admin_CPT class hooked in on `save_post` wp hook. |
|
| 3557 | + * |
|
| 3558 | + * @param int $post_id |
|
| 3559 | + * @param WP_POST $post |
|
| 3560 | + * @throws DomainException |
|
| 3561 | + * @throws EE_Error |
|
| 3562 | + * @throws InvalidArgumentException |
|
| 3563 | + * @throws InvalidDataTypeException |
|
| 3564 | + * @throws InvalidInterfaceException |
|
| 3565 | + * @throws LogicException |
|
| 3566 | + * @throws InvalidFormSubmissionException |
|
| 3567 | + */ |
|
| 3568 | + protected function _insert_update_cpt_item($post_id, $post) |
|
| 3569 | + { |
|
| 3570 | + $success = true; |
|
| 3571 | + $attendee = $post instanceof WP_Post && $post->post_type === 'espresso_attendees' |
|
| 3572 | + ? EEM_Attendee::instance()->get_one_by_ID($post_id) |
|
| 3573 | + : null; |
|
| 3574 | + // for attendee updates |
|
| 3575 | + if ($attendee instanceof EE_Attendee) { |
|
| 3576 | + // note we should only be UPDATING attendees at this point. |
|
| 3577 | + $updated_fields = array( |
|
| 3578 | + 'ATT_fname' => $this->_req_data['ATT_fname'], |
|
| 3579 | + 'ATT_lname' => $this->_req_data['ATT_lname'], |
|
| 3580 | + 'ATT_full_name' => $this->_req_data['ATT_fname'] . ' ' . $this->_req_data['ATT_lname'], |
|
| 3581 | + 'ATT_address' => isset($this->_req_data['ATT_address']) ? $this->_req_data['ATT_address'] : '', |
|
| 3582 | + 'ATT_address2' => isset($this->_req_data['ATT_address2']) ? $this->_req_data['ATT_address2'] : '', |
|
| 3583 | + 'ATT_city' => isset($this->_req_data['ATT_city']) ? $this->_req_data['ATT_city'] : '', |
|
| 3584 | + 'STA_ID' => isset($this->_req_data['STA_ID']) ? $this->_req_data['STA_ID'] : '', |
|
| 3585 | + 'CNT_ISO' => isset($this->_req_data['CNT_ISO']) ? $this->_req_data['CNT_ISO'] : '', |
|
| 3586 | + 'ATT_zip' => isset($this->_req_data['ATT_zip']) ? $this->_req_data['ATT_zip'] : '', |
|
| 3587 | + ); |
|
| 3588 | + foreach ($updated_fields as $field => $value) { |
|
| 3589 | + $attendee->set($field, $value); |
|
| 3590 | + } |
|
| 3591 | + |
|
| 3592 | + // process contact details metabox form handler (which will also save the attendee) |
|
| 3593 | + $contact_details_form = $this->getAttendeeContactDetailsMetaboxFormHandler($attendee); |
|
| 3594 | + $success = $contact_details_form->process($this->_req_data); |
|
| 3595 | + |
|
| 3596 | + $attendee_update_callbacks = apply_filters( |
|
| 3597 | + 'FHEE__Registrations_Admin_Page__insert_update_cpt_item__attendee_update', |
|
| 3598 | + array() |
|
| 3599 | + ); |
|
| 3600 | + foreach ($attendee_update_callbacks as $a_callback) { |
|
| 3601 | + if (false === call_user_func_array($a_callback, array($attendee, $this->_req_data))) { |
|
| 3602 | + throw new EE_Error( |
|
| 3603 | + sprintf( |
|
| 3604 | + esc_html__( |
|
| 3605 | + '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.', |
|
| 3606 | + 'event_espresso' |
|
| 3607 | + ), |
|
| 3608 | + $a_callback |
|
| 3609 | + ) |
|
| 3610 | + ); |
|
| 3611 | + } |
|
| 3612 | + } |
|
| 3613 | + } |
|
| 3614 | + |
|
| 3615 | + if ($success === false) { |
|
| 3616 | + EE_Error::add_error( |
|
| 3617 | + esc_html__( |
|
| 3618 | + 'Something went wrong with updating the meta table data for the registration.', |
|
| 3619 | + 'event_espresso' |
|
| 3620 | + ), |
|
| 3621 | + __FILE__, |
|
| 3622 | + __FUNCTION__, |
|
| 3623 | + __LINE__ |
|
| 3624 | + ); |
|
| 3625 | + } |
|
| 3626 | + } |
|
| 3627 | + |
|
| 3628 | + |
|
| 3629 | + public function trash_cpt_item($post_id) |
|
| 3630 | + { |
|
| 3631 | + } |
|
| 3632 | + |
|
| 3633 | + |
|
| 3634 | + public function delete_cpt_item($post_id) |
|
| 3635 | + { |
|
| 3636 | + } |
|
| 3637 | + |
|
| 3638 | + |
|
| 3639 | + public function restore_cpt_item($post_id) |
|
| 3640 | + { |
|
| 3641 | + } |
|
| 3642 | + |
|
| 3643 | + |
|
| 3644 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
| 3645 | + { |
|
| 3646 | + } |
|
| 3647 | + |
|
| 3648 | + |
|
| 3649 | + public function attendee_editor_metaboxes() |
|
| 3650 | + { |
|
| 3651 | + $this->verify_cpt_object(); |
|
| 3652 | + remove_meta_box( |
|
| 3653 | + 'postexcerpt', |
|
| 3654 | + esc_html__('Excerpt', 'event_espresso'), |
|
| 3655 | + 'post_excerpt_meta_box', |
|
| 3656 | + $this->_cpt_routes[ $this->_req_action ], |
|
| 3657 | + 'normal', |
|
| 3658 | + 'core' |
|
| 3659 | + ); |
|
| 3660 | + remove_meta_box('commentstatusdiv', $this->_cpt_routes[ $this->_req_action ], 'normal', 'core'); |
|
| 3661 | + if (post_type_supports('espresso_attendees', 'excerpt')) { |
|
| 3662 | + add_meta_box( |
|
| 3663 | + 'postexcerpt', |
|
| 3664 | + esc_html__('Short Biography', 'event_espresso'), |
|
| 3665 | + 'post_excerpt_meta_box', |
|
| 3666 | + $this->_cpt_routes[ $this->_req_action ], |
|
| 3667 | + 'normal' |
|
| 3668 | + ); |
|
| 3669 | + } |
|
| 3670 | + if (post_type_supports('espresso_attendees', 'comments')) { |
|
| 3671 | + add_meta_box( |
|
| 3672 | + 'commentsdiv', |
|
| 3673 | + esc_html__('Notes on the Contact', 'event_espresso'), |
|
| 3674 | + 'post_comment_meta_box', |
|
| 3675 | + $this->_cpt_routes[ $this->_req_action ], |
|
| 3676 | + 'normal', |
|
| 3677 | + 'core' |
|
| 3678 | + ); |
|
| 3679 | + } |
|
| 3680 | + add_meta_box( |
|
| 3681 | + 'attendee_contact_info', |
|
| 3682 | + esc_html__('Contact Info', 'event_espresso'), |
|
| 3683 | + array($this, 'attendee_contact_info'), |
|
| 3684 | + $this->_cpt_routes[ $this->_req_action ], |
|
| 3685 | + 'side', |
|
| 3686 | + 'core' |
|
| 3687 | + ); |
|
| 3688 | + add_meta_box( |
|
| 3689 | + 'attendee_details_address', |
|
| 3690 | + esc_html__('Address Details', 'event_espresso'), |
|
| 3691 | + array($this, 'attendee_address_details'), |
|
| 3692 | + $this->_cpt_routes[ $this->_req_action ], |
|
| 3693 | + 'normal', |
|
| 3694 | + 'core' |
|
| 3695 | + ); |
|
| 3696 | + add_meta_box( |
|
| 3697 | + 'attendee_registrations', |
|
| 3698 | + esc_html__('Registrations for this Contact', 'event_espresso'), |
|
| 3699 | + array($this, 'attendee_registrations_meta_box'), |
|
| 3700 | + $this->_cpt_routes[ $this->_req_action ], |
|
| 3701 | + 'normal', |
|
| 3702 | + 'high' |
|
| 3703 | + ); |
|
| 3704 | + } |
|
| 3705 | + |
|
| 3706 | + |
|
| 3707 | + /** |
|
| 3708 | + * Metabox for attendee contact info |
|
| 3709 | + * |
|
| 3710 | + * @param WP_Post $post wp post object |
|
| 3711 | + * @return string attendee contact info ( and form ) |
|
| 3712 | + * @throws EE_Error |
|
| 3713 | + * @throws InvalidArgumentException |
|
| 3714 | + * @throws InvalidDataTypeException |
|
| 3715 | + * @throws InvalidInterfaceException |
|
| 3716 | + * @throws LogicException |
|
| 3717 | + * @throws DomainException |
|
| 3718 | + */ |
|
| 3719 | + public function attendee_contact_info($post) |
|
| 3720 | + { |
|
| 3721 | + // get attendee object ( should already have it ) |
|
| 3722 | + $form = $this->getAttendeeContactDetailsMetaboxFormHandler($this->_cpt_model_obj); |
|
| 3723 | + $form->enqueueStylesAndScripts(); |
|
| 3724 | + echo $form->display(); |
|
| 3725 | + } |
|
| 3726 | + |
|
| 3727 | + |
|
| 3728 | + /** |
|
| 3729 | + * Return form handler for the contact details metabox |
|
| 3730 | + * |
|
| 3731 | + * @param EE_Attendee $attendee |
|
| 3732 | + * @return AttendeeContactDetailsMetaboxFormHandler |
|
| 3733 | + * @throws DomainException |
|
| 3734 | + * @throws InvalidArgumentException |
|
| 3735 | + * @throws InvalidDataTypeException |
|
| 3736 | + * @throws InvalidInterfaceException |
|
| 3737 | + */ |
|
| 3738 | + protected function getAttendeeContactDetailsMetaboxFormHandler(EE_Attendee $attendee) |
|
| 3739 | + { |
|
| 3740 | + return new AttendeeContactDetailsMetaboxFormHandler($attendee, EE_Registry::instance()); |
|
| 3741 | + } |
|
| 3742 | + |
|
| 3743 | + |
|
| 3744 | + /** |
|
| 3745 | + * Metabox for attendee details |
|
| 3746 | + * |
|
| 3747 | + * @param WP_Post $post wp post object |
|
| 3748 | + * @throws DomainException |
|
| 3749 | + */ |
|
| 3750 | + public function attendee_address_details($post) |
|
| 3751 | + { |
|
| 3752 | + // get attendee object (should already have it) |
|
| 3753 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3754 | + $this->_template_args['state_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3755 | + new EE_Question_Form_Input( |
|
| 3756 | + EE_Question::new_instance( |
|
| 3757 | + array( |
|
| 3758 | + 'QST_ID' => 0, |
|
| 3759 | + 'QST_display_text' => esc_html__('State/Province', 'event_espresso'), |
|
| 3760 | + 'QST_system' => 'admin-state', |
|
| 3761 | + ) |
|
| 3762 | + ), |
|
| 3763 | + EE_Answer::new_instance( |
|
| 3764 | + array( |
|
| 3765 | + 'ANS_ID' => 0, |
|
| 3766 | + 'ANS_value' => $this->_cpt_model_obj->state_ID(), |
|
| 3767 | + ) |
|
| 3768 | + ), |
|
| 3769 | + array( |
|
| 3770 | + 'input_id' => 'STA_ID', |
|
| 3771 | + 'input_name' => 'STA_ID', |
|
| 3772 | + 'input_prefix' => '', |
|
| 3773 | + 'append_qstn_id' => false, |
|
| 3774 | + ) |
|
| 3775 | + ) |
|
| 3776 | + ); |
|
| 3777 | + $this->_template_args['country_html'] = EEH_Form_Fields::generate_form_input( |
|
| 3778 | + new EE_Question_Form_Input( |
|
| 3779 | + EE_Question::new_instance( |
|
| 3780 | + array( |
|
| 3781 | + 'QST_ID' => 0, |
|
| 3782 | + 'QST_display_text' => esc_html__('Country', 'event_espresso'), |
|
| 3783 | + 'QST_system' => 'admin-country', |
|
| 3784 | + ) |
|
| 3785 | + ), |
|
| 3786 | + EE_Answer::new_instance( |
|
| 3787 | + array( |
|
| 3788 | + 'ANS_ID' => 0, |
|
| 3789 | + 'ANS_value' => $this->_cpt_model_obj->country_ID(), |
|
| 3790 | + ) |
|
| 3791 | + ), |
|
| 3792 | + array( |
|
| 3793 | + 'input_id' => 'CNT_ISO', |
|
| 3794 | + 'input_name' => 'CNT_ISO', |
|
| 3795 | + 'input_prefix' => '', |
|
| 3796 | + 'append_qstn_id' => false, |
|
| 3797 | + ) |
|
| 3798 | + ) |
|
| 3799 | + ); |
|
| 3800 | + $template = |
|
| 3801 | + REG_TEMPLATE_PATH . 'attendee_address_details_metabox_content.template.php'; |
|
| 3802 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 3803 | + } |
|
| 3804 | + |
|
| 3805 | + |
|
| 3806 | + /** |
|
| 3807 | + * _attendee_details |
|
| 3808 | + * |
|
| 3809 | + * @access protected |
|
| 3810 | + * @param $post |
|
| 3811 | + * @return void |
|
| 3812 | + * @throws DomainException |
|
| 3813 | + * @throws EE_Error |
|
| 3814 | + */ |
|
| 3815 | + public function attendee_registrations_meta_box($post) |
|
| 3816 | + { |
|
| 3817 | + $this->_template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3818 | + $this->_template_args['registrations'] = $this->_cpt_model_obj->get_many_related('Registration'); |
|
| 3819 | + $template = |
|
| 3820 | + REG_TEMPLATE_PATH . 'attendee_registrations_main_meta_box.template.php'; |
|
| 3821 | + EEH_Template::display_template($template, $this->_template_args); |
|
| 3822 | + } |
|
| 3823 | + |
|
| 3824 | + |
|
| 3825 | + /** |
|
| 3826 | + * add in the form fields for the attendee edit |
|
| 3827 | + * |
|
| 3828 | + * @param WP_Post $post wp post object |
|
| 3829 | + * @return string html for new form. |
|
| 3830 | + * @throws DomainException |
|
| 3831 | + */ |
|
| 3832 | + public function after_title_form_fields($post) |
|
| 3833 | + { |
|
| 3834 | + if ($post->post_type == 'espresso_attendees') { |
|
| 3835 | + $template = REG_TEMPLATE_PATH . 'attendee_details_after_title_form_fields.template.php'; |
|
| 3836 | + $template_args['attendee'] = $this->_cpt_model_obj; |
|
| 3837 | + EEH_Template::display_template($template, $template_args); |
|
| 3838 | + } |
|
| 3839 | + } |
|
| 3840 | + |
|
| 3841 | + |
|
| 3842 | + /** |
|
| 3843 | + * _trash_or_restore_attendee |
|
| 3844 | + * |
|
| 3845 | + * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE) |
|
| 3846 | + * @return void |
|
| 3847 | + * @throws EE_Error |
|
| 3848 | + * @throws InvalidArgumentException |
|
| 3849 | + * @throws InvalidDataTypeException |
|
| 3850 | + * @throws InvalidInterfaceException |
|
| 3851 | + * @access protected |
|
| 3852 | + */ |
|
| 3853 | + protected function _trash_or_restore_attendees($trash = true) |
|
| 3854 | + { |
|
| 3855 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 3856 | + $ATT_MDL = EEM_Attendee::instance(); |
|
| 3857 | + $success = 1; |
|
| 3858 | + // Checkboxes |
|
| 3859 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 3860 | + // if array has more than one element than success message should be plural |
|
| 3861 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
| 3862 | + // cycle thru checkboxes |
|
| 3863 | + while (list($ATT_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 3864 | + $updated = $trash ? $ATT_MDL->update_by_ID(array('status' => 'trash'), $ATT_ID) |
|
| 3865 | + : $ATT_MDL->update_by_ID(array('status' => 'publish'), $ATT_ID); |
|
| 3866 | + if (! $updated) { |
|
| 3867 | + $success = 0; |
|
| 3868 | + } |
|
| 3869 | + } |
|
| 3870 | + } else { |
|
| 3871 | + // grab single id and delete |
|
| 3872 | + $ATT_ID = absint($this->_req_data['ATT_ID']); |
|
| 3873 | + // get attendee |
|
| 3874 | + $att = $ATT_MDL->get_one_by_ID($ATT_ID); |
|
| 3875 | + $updated = $trash ? $att->set_status('trash') : $att->set_status('publish'); |
|
| 3876 | + $updated = $att->save(); |
|
| 3877 | + if (! $updated) { |
|
| 3878 | + $success = 0; |
|
| 3879 | + } |
|
| 3880 | + } |
|
| 3881 | + $what = $success > 1 |
|
| 3882 | + ? esc_html__('Contacts', 'event_espresso') |
|
| 3883 | + : esc_html__('Contact', 'event_espresso'); |
|
| 3884 | + $action_desc = $trash |
|
| 3885 | + ? esc_html__('moved to the trash', 'event_espresso') |
|
| 3886 | + : esc_html__('restored', 'event_espresso'); |
|
| 3887 | + $this->_redirect_after_action($success, $what, $action_desc, array('action' => 'contact_list')); |
|
| 3888 | + } |
|
| 3889 | 3889 | } |
@@ -1,6 +1,5 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -use EventEspresso\core\services\formatters\AsciiOnly; |
|
| 4 | 3 | use EventEspresso\core\services\loaders\LoaderFactory; |
| 5 | 4 | |
| 6 | 5 | /** |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | $line_item->unit_price(), |
| 217 | 217 | 'N' |
| 218 | 218 | ); |
| 219 | - $order_description .= $this->prepareStringForAuthnet($line_item->desc()) . ', '; |
|
| 219 | + $order_description .= $this->prepareStringForAuthnet($line_item->desc()).', '; |
|
| 220 | 220 | } |
| 221 | 221 | foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
| 222 | 222 | $this->addLineItem( |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | // invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
| 255 | 255 | // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
| 256 | 256 | // in which case, we need to generate teh invoice num per request right here... |
| 257 | - $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
| 257 | + $this->setField('invoice_num', wp_generate_password(12, false)); // $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
| 258 | 258 | // tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
| 259 | 259 | $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
| 260 | 260 | |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | // Capture response |
| 266 | 266 | $this->type = "AUTH_CAPTURE"; |
| 267 | 267 | $response = $this->_sendRequest($payment); |
| 268 | - if (! empty($response)) { |
|
| 268 | + if ( ! empty($response)) { |
|
| 269 | 269 | if ($response->error_message) { |
| 270 | 270 | $payment->set_status($this->_pay_model->failed_status()); |
| 271 | 271 | $payment->set_gateway_response($response->error_message); |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | protected function _set_sensitive_billing_data($billing_info) |
| 312 | 312 | { |
| 313 | 313 | $this->setField('card_num', $billing_info['credit_card']); |
| 314 | - $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
| 314 | + $this->setField('exp_date', $billing_info['exp_month'].$billing_info['exp_year']); |
|
| 315 | 315 | $this->setField('card_code', $billing_info['cvv']); |
| 316 | 316 | } |
| 317 | 317 | |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | protected function setField($name, $value) |
| 352 | 352 | { |
| 353 | 353 | if (in_array($name, $this->_all_aim_fields)) { |
| 354 | - $this->_x_post_fields[ $name ] = $value; |
|
| 354 | + $this->_x_post_fields[$name] = $value; |
|
| 355 | 355 | } else { |
| 356 | 356 | throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
| 357 | 357 | To set a custom field use setCustomField('field','value') instead."); |
@@ -371,11 +371,11 @@ discard block |
||
| 371 | 371 | $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
| 372 | 372 | $x_keys = array(); |
| 373 | 373 | foreach ($this->_x_post_fields as $key => $value) { |
| 374 | - $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
| 374 | + $x_keys[] = "x_$key=".urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
| 375 | 375 | } |
| 376 | 376 | // Add line items |
| 377 | 377 | foreach ($this->_additional_line_items as $key => $value) { |
| 378 | - $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
| 378 | + $x_keys[] = "x_line_item=".urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
| 379 | 379 | } |
| 380 | 380 | $this->_log_clean_request($x_keys, $payment); |
| 381 | 381 | $post_url = $this->_get_server_url(); |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
| 388 | 388 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
| 389 | 389 | if ($this->VERIFY_PEER) { |
| 390 | - curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
| 390 | + curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__).'/ssl/cert.pem'); |
|
| 391 | 391 | } else { |
| 392 | 392 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
| 393 | 393 | } |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | $response = curl_exec($curl_request); |
| 400 | 400 | |
| 401 | 401 | curl_close($curl_request); |
| 402 | - $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
| 402 | + $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
| 403 | 403 | |
| 404 | 404 | return $this->_log_and_clean_response($response_obj, $payment); |
| 405 | 405 | } |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | if (strpos($keyvaltogether, $key) === 0) { |
| 420 | 420 | // found it at the first character |
| 421 | 421 | // so its one of them |
| 422 | - unset($request_array[ $index ]); |
|
| 422 | + unset($request_array[$index]); |
|
| 423 | 423 | } |
| 424 | 424 | } |
| 425 | 425 | } |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | // Split Array |
| 561 | 561 | $this->response = $response; |
| 562 | 562 | if ($encap_char) { |
| 563 | - $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
| 563 | + $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
| 564 | 564 | } else { |
| 565 | 565 | $this->_response_array = explode($delimiter, $response); |
| 566 | 566 | } |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | } |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | -if (! class_exists('AuthorizeNetException')) { |
|
| 645 | +if ( ! class_exists('AuthorizeNetException')) { |
|
| 646 | 646 | /** |
| 647 | 647 | * Class AuthorizeNetException |
| 648 | 648 | * |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | /** |
| 363 | 363 | * Posts the request to AuthorizeNet & returns response. |
| 364 | 364 | * |
| 365 | - * @param $payment |
|
| 365 | + * @param EEI_Payment $payment |
|
| 366 | 366 | * @return \EE_AuthorizeNetAIM_Response |
| 367 | 367 | */ |
| 368 | 368 | private function _sendRequest($payment) |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | /** |
| 452 | 452 | * Removes characters Authorize.net doesn't handle well. |
| 453 | 453 | * @since 4.9.82.p |
| 454 | - * @param $text |
|
| 454 | + * @param string $text |
|
| 455 | 455 | * @return string |
| 456 | 456 | */ |
| 457 | 457 | private function prepareStringForAuthnet($text) |
@@ -26,442 +26,442 @@ discard block |
||
| 26 | 26 | class EEG_Aim extends EE_Onsite_Gateway |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL |
|
| 30 | - |
|
| 31 | - const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
| 32 | - |
|
| 33 | - protected $_login_id; |
|
| 34 | - |
|
| 35 | - protected $_transaction_key; |
|
| 36 | - |
|
| 37 | - protected $_server; |
|
| 38 | - |
|
| 39 | - protected $_currencies_supported = array( |
|
| 40 | - 'AUD', |
|
| 41 | - 'USD', |
|
| 42 | - 'CAD', |
|
| 43 | - 'EUR', |
|
| 44 | - 'GBP', |
|
| 45 | - 'NZD', |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Whether to send test transactions (even to live site) |
|
| 50 | - * |
|
| 51 | - * @var boolean |
|
| 52 | - */ |
|
| 53 | - protected $_test_transactions; |
|
| 54 | - |
|
| 55 | - private $VERIFY_PEER = false; |
|
| 56 | - |
|
| 57 | - private $_x_post_fields = array( |
|
| 58 | - "version" => "3.1", |
|
| 59 | - "delim_char" => ",", |
|
| 60 | - "delim_data" => "TRUE", |
|
| 61 | - "relay_response" => "FALSE", |
|
| 62 | - "encap_char" => "|", |
|
| 63 | - ); |
|
| 64 | - |
|
| 65 | - private $_additional_line_items = array(); |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * A list of all fields in the AIM API. |
|
| 69 | - * Used to warn user if they try to set a field not offered in the API. |
|
| 70 | - */ |
|
| 71 | - private $_all_aim_fields = array( |
|
| 72 | - "address", |
|
| 73 | - "allow_partial_auth", |
|
| 74 | - "amount", |
|
| 75 | - "auth_code", |
|
| 76 | - "authentication_indicator", |
|
| 77 | - "bank_aba_code", |
|
| 78 | - "bank_acct_name", |
|
| 79 | - "bank_acct_num", |
|
| 80 | - "bank_acct_type", |
|
| 81 | - "bank_check_number", |
|
| 82 | - "bank_name", |
|
| 83 | - "card_code", |
|
| 84 | - "card_num", |
|
| 85 | - "cardholder_authentication_value", |
|
| 86 | - "city", |
|
| 87 | - "company", |
|
| 88 | - "country", |
|
| 89 | - "cust_id", |
|
| 90 | - "customer_ip", |
|
| 91 | - "delim_char", |
|
| 92 | - "delim_data", |
|
| 93 | - "description", |
|
| 94 | - "duplicate_window", |
|
| 95 | - "duty", |
|
| 96 | - "echeck_type", |
|
| 97 | - "email", |
|
| 98 | - "email_customer", |
|
| 99 | - "encap_char", |
|
| 100 | - "exp_date", |
|
| 101 | - "fax", |
|
| 102 | - "first_name", |
|
| 103 | - "footer_email_receipt", |
|
| 104 | - "freight", |
|
| 105 | - "header_email_receipt", |
|
| 106 | - "invoice_num", |
|
| 107 | - "last_name", |
|
| 108 | - "line_item", |
|
| 109 | - "login", |
|
| 110 | - "method", |
|
| 111 | - "phone", |
|
| 112 | - "po_num", |
|
| 113 | - "recurring_billing", |
|
| 114 | - "relay_response", |
|
| 115 | - "ship_to_address", |
|
| 116 | - "ship_to_city", |
|
| 117 | - "ship_to_company", |
|
| 118 | - "ship_to_country", |
|
| 119 | - "ship_to_first_name", |
|
| 120 | - "ship_to_last_name", |
|
| 121 | - "ship_to_state", |
|
| 122 | - "ship_to_zip", |
|
| 123 | - "split_tender_id", |
|
| 124 | - "state", |
|
| 125 | - "tax", |
|
| 126 | - "tax_exempt", |
|
| 127 | - "test_request", |
|
| 128 | - "tran_key", |
|
| 129 | - "trans_id", |
|
| 130 | - "type", |
|
| 131 | - "version", |
|
| 132 | - "zip", |
|
| 133 | - "solution_id", |
|
| 134 | - "currency_code" |
|
| 135 | - ); |
|
| 136 | - |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Gets the URL where the request should go. This is filterable |
|
| 140 | - * |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - protected function _get_server_url() |
|
| 144 | - { |
|
| 145 | - return apply_filters( |
|
| 146 | - 'FHEE__EEG_Aim___get_server_url', |
|
| 147 | - $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL, |
|
| 148 | - $this |
|
| 149 | - ); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * TEMPORARY CALLBACK! Do not use |
|
| 155 | - * Callback which filters the server url. This is added so site admins can revert to using |
|
| 156 | - * the old AIM server in case Akamai service breaks their integration. |
|
| 157 | - * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net |
|
| 158 | - * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343) |
|
| 159 | - * Once that happens, this will be obsolete and WILL BE REMOVED. |
|
| 160 | - * |
|
| 161 | - * @param string $url |
|
| 162 | - * @param EEG_Aim $gateway_object |
|
| 163 | - * @return string |
|
| 164 | - */ |
|
| 165 | - public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) |
|
| 166 | - { |
|
| 167 | - if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) { |
|
| 168 | - return 'https://secure.authorize.net/gateway/transact.dll'; |
|
| 169 | - } else { |
|
| 170 | - return $url; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Asks the gateway to do whatever it does to process the payment. Onsite gateways will |
|
| 177 | - * usually send a request directly to the payment provider and update the payment's status based on that; |
|
| 178 | - * whereas offsite gateways will usually just update the payment with the URL and query parameters to use |
|
| 179 | - * for sending the request via http_remote_request() |
|
| 180 | - * |
|
| 181 | - * @param EEI_Payment $payment |
|
| 182 | - * @param array $billing_info { |
|
| 183 | - * @type $credit_card string |
|
| 184 | - * @type $cvv string |
|
| 185 | - * @type $exp_month string |
|
| 186 | - * @type $exp_year string |
|
| 187 | - * @see parent::do_direct_payment |
|
| 188 | - * } |
|
| 189 | - * @return EEI_Payment updated |
|
| 190 | - */ |
|
| 191 | - public function do_direct_payment($payment, $billing_info = null) |
|
| 192 | - { |
|
| 193 | - add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
| 194 | - // Enable test mode if needed |
|
| 195 | - // 4007000000027 <-- test successful visa |
|
| 196 | - // 4222222222222 <-- test failure card number |
|
| 197 | - |
|
| 198 | - $item_num = 1; |
|
| 199 | - $transaction = $payment->transaction(); |
|
| 200 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 201 | - $order_description = $this->prepareStringForAuthnet($gateway_formatter->formatOrderDescription($payment)); |
|
| 202 | - $primary_registrant = $transaction->primary_registration(); |
|
| 203 | - // if we're are charging for the full amount, show the normal line items |
|
| 204 | - // and the itemized total adds up properly |
|
| 205 | - if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
| 206 | - $total_line_item = $transaction->total_line_item(); |
|
| 207 | - foreach ($total_line_item->get_items() as $line_item) { |
|
| 208 | - if ($line_item->quantity() == 0) { |
|
| 209 | - continue; |
|
| 210 | - } |
|
| 211 | - $this->addLineItem( |
|
| 212 | - $item_num++, |
|
| 213 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 214 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 215 | - $line_item->quantity(), |
|
| 216 | - $line_item->unit_price(), |
|
| 217 | - 'N' |
|
| 218 | - ); |
|
| 219 | - $order_description .= $this->prepareStringForAuthnet($line_item->desc()) . ', '; |
|
| 220 | - } |
|
| 221 | - foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
| 222 | - $this->addLineItem( |
|
| 223 | - $item_num++, |
|
| 224 | - $tax_line_item->name(), |
|
| 225 | - $tax_line_item->desc(), |
|
| 226 | - 1, |
|
| 227 | - $tax_line_item->total(), |
|
| 228 | - 'N' |
|
| 229 | - ); |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // start transaction |
|
| 234 | - // if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
|
| 235 | - $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
|
| 236 | - $this->setField('solution_id', $partner_id); |
|
| 237 | - $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount())); |
|
| 238 | - $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
| 239 | - $this->_set_sensitive_billing_data($billing_info); |
|
| 240 | - $this->setField('first_name', $billing_info['first_name']); |
|
| 241 | - $this->setField('last_name', $billing_info['last_name']); |
|
| 242 | - $this->setField('email', $billing_info['email']); |
|
| 243 | - $this->setField('company', $billing_info['company']); |
|
| 244 | - $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
|
| 245 | - $this->setField('city', $billing_info['city']); |
|
| 246 | - $this->setField('state', $billing_info['state']); |
|
| 247 | - $this->setField('country', $billing_info['country']); |
|
| 248 | - $this->setField('zip', $billing_info['zip']); |
|
| 249 | - $this->setField('fax', $billing_info['fax']); |
|
| 250 | - $this->setField('cust_id', $primary_registrant->ID()); |
|
| 251 | - $this->setField('phone', $billing_info['phone']); |
|
| 252 | - $currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config'); |
|
| 253 | - $this->setField('currency_code', $currency_config->code); |
|
| 254 | - // invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
|
| 255 | - // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
|
| 256 | - // in which case, we need to generate teh invoice num per request right here... |
|
| 257 | - $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
| 258 | - // tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
|
| 259 | - $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
| 260 | - |
|
| 261 | - if ($this->_test_transactions) { |
|
| 262 | - $this->test_request = "true"; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - // Capture response |
|
| 266 | - $this->type = "AUTH_CAPTURE"; |
|
| 267 | - $response = $this->_sendRequest($payment); |
|
| 268 | - if (! empty($response)) { |
|
| 269 | - if ($response->error_message) { |
|
| 270 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 271 | - $payment->set_gateway_response($response->error_message); |
|
| 272 | - } else { |
|
| 273 | - $payment_status = $response->approved |
|
| 274 | - ? $this->_pay_model->approved_status() |
|
| 275 | - : $this->_pay_model->declined_status(); |
|
| 276 | - $payment->set_status($payment_status); |
|
| 277 | - // make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
| 278 | - $payment->set_amount((float) $response->amount); |
|
| 279 | - $payment->set_gateway_response( |
|
| 280 | - sprintf( |
|
| 281 | - esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
| 282 | - $response->response_reason_text, |
|
| 283 | - $response->response_reason_code |
|
| 284 | - ) |
|
| 285 | - ); |
|
| 286 | - if ($this->_debug_mode) { |
|
| 287 | - $txn_id = $response->invoice_number; |
|
| 288 | - } else { |
|
| 289 | - $txn_id = $response->transaction_id; |
|
| 290 | - } |
|
| 291 | - $payment->set_txn_id_chq_nmbr($txn_id); |
|
| 292 | - } |
|
| 293 | - $payment->set_extra_accntng($primary_registrant->reg_code()); |
|
| 294 | - $payment->set_details(print_r($response, true)); |
|
| 295 | - } else { |
|
| 296 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 297 | - $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
|
| 298 | - $payment->set_details(print_r($response, true)); |
|
| 299 | - } |
|
| 300 | - return $payment; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Sets billing data for the upcoming request to AIM that is considered sensitive; |
|
| 306 | - * also this method can be overridden by children classes to easily change |
|
| 307 | - * what billing data gets sent |
|
| 308 | - * |
|
| 309 | - * @param array $billing_info |
|
| 310 | - */ |
|
| 311 | - protected function _set_sensitive_billing_data($billing_info) |
|
| 312 | - { |
|
| 313 | - $this->setField('card_num', $billing_info['credit_card']); |
|
| 314 | - $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
| 315 | - $this->setField('card_code', $billing_info['cvv']); |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Add a line item. |
|
| 321 | - * |
|
| 322 | - * @param string $item_id |
|
| 323 | - * @param string $item_name |
|
| 324 | - * @param string $item_description |
|
| 325 | - * @param string $item_quantity |
|
| 326 | - * @param string $item_unit_price |
|
| 327 | - * @param string $item_taxable |
|
| 328 | - */ |
|
| 329 | - public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
| 330 | - { |
|
| 331 | - $args = array( |
|
| 332 | - substr($item_id, 0, 31), |
|
| 333 | - substr($this->prepareStringForAuthnet($item_name), 0, 31), |
|
| 334 | - substr($this->prepareStringForAuthnet($item_description), 0, 255), |
|
| 335 | - number_format(abs($item_quantity), 2, '.', ''), |
|
| 336 | - number_format(abs($item_unit_price), 2, '.', ''), |
|
| 337 | - $item_taxable === 'N' ? 'N' : 'Y' |
|
| 338 | - ); |
|
| 339 | - $this->_additional_line_items[] = implode('<|>', $args); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Set an individual name/value pair. This will append x_ to the name |
|
| 345 | - * before posting. |
|
| 346 | - * |
|
| 347 | - * @param string $name |
|
| 348 | - * @param string $value |
|
| 349 | - * @throws AuthorizeNetException |
|
| 350 | - */ |
|
| 351 | - protected function setField($name, $value) |
|
| 352 | - { |
|
| 353 | - if (in_array($name, $this->_all_aim_fields)) { |
|
| 354 | - $this->_x_post_fields[ $name ] = $value; |
|
| 355 | - } else { |
|
| 356 | - throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
| 29 | + const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL |
|
| 30 | + |
|
| 31 | + const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll'; |
|
| 32 | + |
|
| 33 | + protected $_login_id; |
|
| 34 | + |
|
| 35 | + protected $_transaction_key; |
|
| 36 | + |
|
| 37 | + protected $_server; |
|
| 38 | + |
|
| 39 | + protected $_currencies_supported = array( |
|
| 40 | + 'AUD', |
|
| 41 | + 'USD', |
|
| 42 | + 'CAD', |
|
| 43 | + 'EUR', |
|
| 44 | + 'GBP', |
|
| 45 | + 'NZD', |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Whether to send test transactions (even to live site) |
|
| 50 | + * |
|
| 51 | + * @var boolean |
|
| 52 | + */ |
|
| 53 | + protected $_test_transactions; |
|
| 54 | + |
|
| 55 | + private $VERIFY_PEER = false; |
|
| 56 | + |
|
| 57 | + private $_x_post_fields = array( |
|
| 58 | + "version" => "3.1", |
|
| 59 | + "delim_char" => ",", |
|
| 60 | + "delim_data" => "TRUE", |
|
| 61 | + "relay_response" => "FALSE", |
|
| 62 | + "encap_char" => "|", |
|
| 63 | + ); |
|
| 64 | + |
|
| 65 | + private $_additional_line_items = array(); |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * A list of all fields in the AIM API. |
|
| 69 | + * Used to warn user if they try to set a field not offered in the API. |
|
| 70 | + */ |
|
| 71 | + private $_all_aim_fields = array( |
|
| 72 | + "address", |
|
| 73 | + "allow_partial_auth", |
|
| 74 | + "amount", |
|
| 75 | + "auth_code", |
|
| 76 | + "authentication_indicator", |
|
| 77 | + "bank_aba_code", |
|
| 78 | + "bank_acct_name", |
|
| 79 | + "bank_acct_num", |
|
| 80 | + "bank_acct_type", |
|
| 81 | + "bank_check_number", |
|
| 82 | + "bank_name", |
|
| 83 | + "card_code", |
|
| 84 | + "card_num", |
|
| 85 | + "cardholder_authentication_value", |
|
| 86 | + "city", |
|
| 87 | + "company", |
|
| 88 | + "country", |
|
| 89 | + "cust_id", |
|
| 90 | + "customer_ip", |
|
| 91 | + "delim_char", |
|
| 92 | + "delim_data", |
|
| 93 | + "description", |
|
| 94 | + "duplicate_window", |
|
| 95 | + "duty", |
|
| 96 | + "echeck_type", |
|
| 97 | + "email", |
|
| 98 | + "email_customer", |
|
| 99 | + "encap_char", |
|
| 100 | + "exp_date", |
|
| 101 | + "fax", |
|
| 102 | + "first_name", |
|
| 103 | + "footer_email_receipt", |
|
| 104 | + "freight", |
|
| 105 | + "header_email_receipt", |
|
| 106 | + "invoice_num", |
|
| 107 | + "last_name", |
|
| 108 | + "line_item", |
|
| 109 | + "login", |
|
| 110 | + "method", |
|
| 111 | + "phone", |
|
| 112 | + "po_num", |
|
| 113 | + "recurring_billing", |
|
| 114 | + "relay_response", |
|
| 115 | + "ship_to_address", |
|
| 116 | + "ship_to_city", |
|
| 117 | + "ship_to_company", |
|
| 118 | + "ship_to_country", |
|
| 119 | + "ship_to_first_name", |
|
| 120 | + "ship_to_last_name", |
|
| 121 | + "ship_to_state", |
|
| 122 | + "ship_to_zip", |
|
| 123 | + "split_tender_id", |
|
| 124 | + "state", |
|
| 125 | + "tax", |
|
| 126 | + "tax_exempt", |
|
| 127 | + "test_request", |
|
| 128 | + "tran_key", |
|
| 129 | + "trans_id", |
|
| 130 | + "type", |
|
| 131 | + "version", |
|
| 132 | + "zip", |
|
| 133 | + "solution_id", |
|
| 134 | + "currency_code" |
|
| 135 | + ); |
|
| 136 | + |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Gets the URL where the request should go. This is filterable |
|
| 140 | + * |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + protected function _get_server_url() |
|
| 144 | + { |
|
| 145 | + return apply_filters( |
|
| 146 | + 'FHEE__EEG_Aim___get_server_url', |
|
| 147 | + $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL, |
|
| 148 | + $this |
|
| 149 | + ); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * TEMPORARY CALLBACK! Do not use |
|
| 155 | + * Callback which filters the server url. This is added so site admins can revert to using |
|
| 156 | + * the old AIM server in case Akamai service breaks their integration. |
|
| 157 | + * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net |
|
| 158 | + * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343) |
|
| 159 | + * Once that happens, this will be obsolete and WILL BE REMOVED. |
|
| 160 | + * |
|
| 161 | + * @param string $url |
|
| 162 | + * @param EEG_Aim $gateway_object |
|
| 163 | + * @return string |
|
| 164 | + */ |
|
| 165 | + public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) |
|
| 166 | + { |
|
| 167 | + if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) { |
|
| 168 | + return 'https://secure.authorize.net/gateway/transact.dll'; |
|
| 169 | + } else { |
|
| 170 | + return $url; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Asks the gateway to do whatever it does to process the payment. Onsite gateways will |
|
| 177 | + * usually send a request directly to the payment provider and update the payment's status based on that; |
|
| 178 | + * whereas offsite gateways will usually just update the payment with the URL and query parameters to use |
|
| 179 | + * for sending the request via http_remote_request() |
|
| 180 | + * |
|
| 181 | + * @param EEI_Payment $payment |
|
| 182 | + * @param array $billing_info { |
|
| 183 | + * @type $credit_card string |
|
| 184 | + * @type $cvv string |
|
| 185 | + * @type $exp_month string |
|
| 186 | + * @type $exp_year string |
|
| 187 | + * @see parent::do_direct_payment |
|
| 188 | + * } |
|
| 189 | + * @return EEI_Payment updated |
|
| 190 | + */ |
|
| 191 | + public function do_direct_payment($payment, $billing_info = null) |
|
| 192 | + { |
|
| 193 | + add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
| 194 | + // Enable test mode if needed |
|
| 195 | + // 4007000000027 <-- test successful visa |
|
| 196 | + // 4222222222222 <-- test failure card number |
|
| 197 | + |
|
| 198 | + $item_num = 1; |
|
| 199 | + $transaction = $payment->transaction(); |
|
| 200 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 201 | + $order_description = $this->prepareStringForAuthnet($gateway_formatter->formatOrderDescription($payment)); |
|
| 202 | + $primary_registrant = $transaction->primary_registration(); |
|
| 203 | + // if we're are charging for the full amount, show the normal line items |
|
| 204 | + // and the itemized total adds up properly |
|
| 205 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
| 206 | + $total_line_item = $transaction->total_line_item(); |
|
| 207 | + foreach ($total_line_item->get_items() as $line_item) { |
|
| 208 | + if ($line_item->quantity() == 0) { |
|
| 209 | + continue; |
|
| 210 | + } |
|
| 211 | + $this->addLineItem( |
|
| 212 | + $item_num++, |
|
| 213 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 214 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 215 | + $line_item->quantity(), |
|
| 216 | + $line_item->unit_price(), |
|
| 217 | + 'N' |
|
| 218 | + ); |
|
| 219 | + $order_description .= $this->prepareStringForAuthnet($line_item->desc()) . ', '; |
|
| 220 | + } |
|
| 221 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
| 222 | + $this->addLineItem( |
|
| 223 | + $item_num++, |
|
| 224 | + $tax_line_item->name(), |
|
| 225 | + $tax_line_item->desc(), |
|
| 226 | + 1, |
|
| 227 | + $tax_line_item->total(), |
|
| 228 | + 'N' |
|
| 229 | + ); |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // start transaction |
|
| 234 | + // if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
|
| 235 | + $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
|
| 236 | + $this->setField('solution_id', $partner_id); |
|
| 237 | + $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount())); |
|
| 238 | + $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
| 239 | + $this->_set_sensitive_billing_data($billing_info); |
|
| 240 | + $this->setField('first_name', $billing_info['first_name']); |
|
| 241 | + $this->setField('last_name', $billing_info['last_name']); |
|
| 242 | + $this->setField('email', $billing_info['email']); |
|
| 243 | + $this->setField('company', $billing_info['company']); |
|
| 244 | + $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
|
| 245 | + $this->setField('city', $billing_info['city']); |
|
| 246 | + $this->setField('state', $billing_info['state']); |
|
| 247 | + $this->setField('country', $billing_info['country']); |
|
| 248 | + $this->setField('zip', $billing_info['zip']); |
|
| 249 | + $this->setField('fax', $billing_info['fax']); |
|
| 250 | + $this->setField('cust_id', $primary_registrant->ID()); |
|
| 251 | + $this->setField('phone', $billing_info['phone']); |
|
| 252 | + $currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config'); |
|
| 253 | + $this->setField('currency_code', $currency_config->code); |
|
| 254 | + // invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
|
| 255 | + // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
|
| 256 | + // in which case, we need to generate teh invoice num per request right here... |
|
| 257 | + $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
| 258 | + // tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
|
| 259 | + $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
| 260 | + |
|
| 261 | + if ($this->_test_transactions) { |
|
| 262 | + $this->test_request = "true"; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + // Capture response |
|
| 266 | + $this->type = "AUTH_CAPTURE"; |
|
| 267 | + $response = $this->_sendRequest($payment); |
|
| 268 | + if (! empty($response)) { |
|
| 269 | + if ($response->error_message) { |
|
| 270 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 271 | + $payment->set_gateway_response($response->error_message); |
|
| 272 | + } else { |
|
| 273 | + $payment_status = $response->approved |
|
| 274 | + ? $this->_pay_model->approved_status() |
|
| 275 | + : $this->_pay_model->declined_status(); |
|
| 276 | + $payment->set_status($payment_status); |
|
| 277 | + // make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
| 278 | + $payment->set_amount((float) $response->amount); |
|
| 279 | + $payment->set_gateway_response( |
|
| 280 | + sprintf( |
|
| 281 | + esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
| 282 | + $response->response_reason_text, |
|
| 283 | + $response->response_reason_code |
|
| 284 | + ) |
|
| 285 | + ); |
|
| 286 | + if ($this->_debug_mode) { |
|
| 287 | + $txn_id = $response->invoice_number; |
|
| 288 | + } else { |
|
| 289 | + $txn_id = $response->transaction_id; |
|
| 290 | + } |
|
| 291 | + $payment->set_txn_id_chq_nmbr($txn_id); |
|
| 292 | + } |
|
| 293 | + $payment->set_extra_accntng($primary_registrant->reg_code()); |
|
| 294 | + $payment->set_details(print_r($response, true)); |
|
| 295 | + } else { |
|
| 296 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 297 | + $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
|
| 298 | + $payment->set_details(print_r($response, true)); |
|
| 299 | + } |
|
| 300 | + return $payment; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Sets billing data for the upcoming request to AIM that is considered sensitive; |
|
| 306 | + * also this method can be overridden by children classes to easily change |
|
| 307 | + * what billing data gets sent |
|
| 308 | + * |
|
| 309 | + * @param array $billing_info |
|
| 310 | + */ |
|
| 311 | + protected function _set_sensitive_billing_data($billing_info) |
|
| 312 | + { |
|
| 313 | + $this->setField('card_num', $billing_info['credit_card']); |
|
| 314 | + $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']); |
|
| 315 | + $this->setField('card_code', $billing_info['cvv']); |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Add a line item. |
|
| 321 | + * |
|
| 322 | + * @param string $item_id |
|
| 323 | + * @param string $item_name |
|
| 324 | + * @param string $item_description |
|
| 325 | + * @param string $item_quantity |
|
| 326 | + * @param string $item_unit_price |
|
| 327 | + * @param string $item_taxable |
|
| 328 | + */ |
|
| 329 | + public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable) |
|
| 330 | + { |
|
| 331 | + $args = array( |
|
| 332 | + substr($item_id, 0, 31), |
|
| 333 | + substr($this->prepareStringForAuthnet($item_name), 0, 31), |
|
| 334 | + substr($this->prepareStringForAuthnet($item_description), 0, 255), |
|
| 335 | + number_format(abs($item_quantity), 2, '.', ''), |
|
| 336 | + number_format(abs($item_unit_price), 2, '.', ''), |
|
| 337 | + $item_taxable === 'N' ? 'N' : 'Y' |
|
| 338 | + ); |
|
| 339 | + $this->_additional_line_items[] = implode('<|>', $args); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Set an individual name/value pair. This will append x_ to the name |
|
| 345 | + * before posting. |
|
| 346 | + * |
|
| 347 | + * @param string $name |
|
| 348 | + * @param string $value |
|
| 349 | + * @throws AuthorizeNetException |
|
| 350 | + */ |
|
| 351 | + protected function setField($name, $value) |
|
| 352 | + { |
|
| 353 | + if (in_array($name, $this->_all_aim_fields)) { |
|
| 354 | + $this->_x_post_fields[ $name ] = $value; |
|
| 355 | + } else { |
|
| 356 | + throw new AuthorizeNetException("Error: no field $name exists in the AIM API. |
|
| 357 | 357 | To set a custom field use setCustomField('field','value') instead."); |
| 358 | - } |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * Posts the request to AuthorizeNet & returns response. |
|
| 364 | - * |
|
| 365 | - * @param $payment |
|
| 366 | - * @return \EE_AuthorizeNetAIM_Response |
|
| 367 | - */ |
|
| 368 | - private function _sendRequest($payment) |
|
| 369 | - { |
|
| 370 | - $this->_x_post_fields['login'] = $this->_login_id; |
|
| 371 | - $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
| 372 | - $x_keys = array(); |
|
| 373 | - foreach ($this->_x_post_fields as $key => $value) { |
|
| 374 | - $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
| 375 | - } |
|
| 376 | - // Add line items |
|
| 377 | - foreach ($this->_additional_line_items as $key => $value) { |
|
| 378 | - $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
| 379 | - } |
|
| 380 | - $this->_log_clean_request($x_keys, $payment); |
|
| 381 | - $post_url = $this->_get_server_url(); |
|
| 382 | - $curl_request = curl_init($post_url); |
|
| 383 | - $post_body = implode("&", $x_keys); |
|
| 384 | - curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
|
| 385 | - curl_setopt($curl_request, CURLOPT_HEADER, 0); |
|
| 386 | - curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
|
| 387 | - curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
|
| 388 | - curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
|
| 389 | - if ($this->VERIFY_PEER) { |
|
| 390 | - curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
| 391 | - } else { |
|
| 392 | - curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - if (preg_match('/xml/', $post_url)) { |
|
| 396 | - curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - $response = curl_exec($curl_request); |
|
| 400 | - |
|
| 401 | - curl_close($curl_request); |
|
| 402 | - $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
| 403 | - |
|
| 404 | - return $this->_log_and_clean_response($response_obj, $payment); |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Logs the clean data only |
|
| 410 | - * |
|
| 411 | - * @param array $request_array |
|
| 412 | - * @param EEI_Payment $payment |
|
| 413 | - */ |
|
| 414 | - protected function _log_clean_request($request_array, $payment) |
|
| 415 | - { |
|
| 416 | - $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
| 417 | - foreach ($request_array as $index => $keyvaltogether) { |
|
| 418 | - foreach ($keys_to_filter_out as $key) { |
|
| 419 | - if (strpos($keyvaltogether, $key) === 0) { |
|
| 420 | - // found it at the first character |
|
| 421 | - // so its one of them |
|
| 422 | - unset($request_array[ $index ]); |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - $this->log( |
|
| 427 | - array( |
|
| 428 | - 'AIM Request sent:' => $request_array, |
|
| 429 | - 'Server URL' => $this->_get_server_url() |
|
| 430 | - ), |
|
| 431 | - $payment |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Logs the response and cleans it |
|
| 439 | - * |
|
| 440 | - * @param EE_AuthorizeNetAIM_Response $response_obj |
|
| 441 | - * @param EE_Payment $payment |
|
| 442 | - * @return \EE_AuthorizeNetAIM_Response |
|
| 443 | - */ |
|
| 444 | - private function _log_and_clean_response($response_obj, $payment) |
|
| 445 | - { |
|
| 446 | - $response_obj->account_number = ''; |
|
| 447 | - $this->log(array('AIM Response received:' => (array) $response_obj), $payment); |
|
| 448 | - return $response_obj; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Removes characters Authorize.net doesn't handle well. |
|
| 453 | - * @since 4.9.82.p |
|
| 454 | - * @param $text |
|
| 455 | - * @return string |
|
| 456 | - */ |
|
| 457 | - private function prepareStringForAuthnet($text) |
|
| 458 | - { |
|
| 459 | - return str_replace( |
|
| 460 | - '\'', |
|
| 461 | - '', |
|
| 462 | - $text |
|
| 463 | - ); |
|
| 464 | - } |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * Posts the request to AuthorizeNet & returns response. |
|
| 364 | + * |
|
| 365 | + * @param $payment |
|
| 366 | + * @return \EE_AuthorizeNetAIM_Response |
|
| 367 | + */ |
|
| 368 | + private function _sendRequest($payment) |
|
| 369 | + { |
|
| 370 | + $this->_x_post_fields['login'] = $this->_login_id; |
|
| 371 | + $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
|
| 372 | + $x_keys = array(); |
|
| 373 | + foreach ($this->_x_post_fields as $key => $value) { |
|
| 374 | + $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
| 375 | + } |
|
| 376 | + // Add line items |
|
| 377 | + foreach ($this->_additional_line_items as $key => $value) { |
|
| 378 | + $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
| 379 | + } |
|
| 380 | + $this->_log_clean_request($x_keys, $payment); |
|
| 381 | + $post_url = $this->_get_server_url(); |
|
| 382 | + $curl_request = curl_init($post_url); |
|
| 383 | + $post_body = implode("&", $x_keys); |
|
| 384 | + curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
|
| 385 | + curl_setopt($curl_request, CURLOPT_HEADER, 0); |
|
| 386 | + curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
|
| 387 | + curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
|
| 388 | + curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
|
| 389 | + if ($this->VERIFY_PEER) { |
|
| 390 | + curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem'); |
|
| 391 | + } else { |
|
| 392 | + curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + if (preg_match('/xml/', $post_url)) { |
|
| 396 | + curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml")); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + $response = curl_exec($curl_request); |
|
| 400 | + |
|
| 401 | + curl_close($curl_request); |
|
| 402 | + $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
| 403 | + |
|
| 404 | + return $this->_log_and_clean_response($response_obj, $payment); |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Logs the clean data only |
|
| 410 | + * |
|
| 411 | + * @param array $request_array |
|
| 412 | + * @param EEI_Payment $payment |
|
| 413 | + */ |
|
| 414 | + protected function _log_clean_request($request_array, $payment) |
|
| 415 | + { |
|
| 416 | + $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
| 417 | + foreach ($request_array as $index => $keyvaltogether) { |
|
| 418 | + foreach ($keys_to_filter_out as $key) { |
|
| 419 | + if (strpos($keyvaltogether, $key) === 0) { |
|
| 420 | + // found it at the first character |
|
| 421 | + // so its one of them |
|
| 422 | + unset($request_array[ $index ]); |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + $this->log( |
|
| 427 | + array( |
|
| 428 | + 'AIM Request sent:' => $request_array, |
|
| 429 | + 'Server URL' => $this->_get_server_url() |
|
| 430 | + ), |
|
| 431 | + $payment |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Logs the response and cleans it |
|
| 439 | + * |
|
| 440 | + * @param EE_AuthorizeNetAIM_Response $response_obj |
|
| 441 | + * @param EE_Payment $payment |
|
| 442 | + * @return \EE_AuthorizeNetAIM_Response |
|
| 443 | + */ |
|
| 444 | + private function _log_and_clean_response($response_obj, $payment) |
|
| 445 | + { |
|
| 446 | + $response_obj->account_number = ''; |
|
| 447 | + $this->log(array('AIM Response received:' => (array) $response_obj), $payment); |
|
| 448 | + return $response_obj; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Removes characters Authorize.net doesn't handle well. |
|
| 453 | + * @since 4.9.82.p |
|
| 454 | + * @param $text |
|
| 455 | + * @return string |
|
| 456 | + */ |
|
| 457 | + private function prepareStringForAuthnet($text) |
|
| 458 | + { |
|
| 459 | + return str_replace( |
|
| 460 | + '\'', |
|
| 461 | + '', |
|
| 462 | + $text |
|
| 463 | + ); |
|
| 464 | + } |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | |
@@ -477,192 +477,192 @@ discard block |
||
| 477 | 477 | class EE_AuthorizeNetAIM_Response |
| 478 | 478 | { |
| 479 | 479 | |
| 480 | - const APPROVED = '1'; |
|
| 481 | - const DECLINED = '2'; |
|
| 482 | - const ERROR = '3'; |
|
| 483 | - const HELD = '4'; |
|
| 484 | - |
|
| 485 | - protected $_x_post_fields = array( |
|
| 486 | - "version" => "3.1", |
|
| 487 | - "delim_char" => ",", |
|
| 488 | - "delim_data" => "TRUE", |
|
| 489 | - "relay_response" => "FALSE", |
|
| 490 | - "encap_char" => "|", |
|
| 491 | - ); |
|
| 492 | - public $approved; |
|
| 493 | - public $declined; |
|
| 494 | - public $error; |
|
| 495 | - public $held; |
|
| 496 | - public $response_code; |
|
| 497 | - public $response_subcode; |
|
| 498 | - public $response_reason_code; |
|
| 499 | - public $response_reason_text; |
|
| 500 | - public $authorization_code; |
|
| 501 | - public $avs_response; |
|
| 502 | - public $transaction_id; |
|
| 503 | - public $invoice_number; |
|
| 504 | - public $description; |
|
| 505 | - public $amount; |
|
| 506 | - public $method; |
|
| 507 | - public $transaction_type; |
|
| 508 | - public $customer_id; |
|
| 509 | - public $first_name; |
|
| 510 | - public $last_name; |
|
| 511 | - public $company; |
|
| 512 | - public $address; |
|
| 513 | - public $city; |
|
| 514 | - public $state; |
|
| 515 | - public $zip_code; |
|
| 516 | - public $country; |
|
| 517 | - public $phone; |
|
| 518 | - public $fax; |
|
| 519 | - public $email_address; |
|
| 520 | - public $ship_to_first_name; |
|
| 521 | - public $ship_to_last_name; |
|
| 522 | - public $ship_to_company; |
|
| 523 | - public $ship_to_address; |
|
| 524 | - public $ship_to_city; |
|
| 525 | - public $ship_to_state; |
|
| 526 | - public $ship_to_zip_code; |
|
| 527 | - public $ship_to_country; |
|
| 528 | - public $tax; |
|
| 529 | - public $duty; |
|
| 530 | - public $freight; |
|
| 531 | - public $tax_exempt; |
|
| 532 | - public $purchase_order_number; |
|
| 533 | - public $md5_hash; |
|
| 534 | - public $card_code_response; |
|
| 535 | - public $cavv_response; // cardholder_authentication_verification_response |
|
| 536 | - public $account_number; |
|
| 537 | - public $card_type; |
|
| 538 | - public $split_tender_id; |
|
| 539 | - public $requested_amount; |
|
| 540 | - public $balance_on_card; |
|
| 541 | - public $response; // The response string from AuthorizeNet. |
|
| 542 | - public $error_message; |
|
| 543 | - private $_response_array = array(); // An array with the split response. |
|
| 544 | - |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Constructor. Parses the AuthorizeNet response string |
|
| 548 | - * |
|
| 549 | - * @param string $response The response from the AuthNet server. |
|
| 550 | - * @var string $delimiter The delimiter used (default is ",") |
|
| 551 | - * @var string $encap_char The encap_char used (default is "|") |
|
| 552 | - * @var array $custom_fields Any custom fields set in the request. |
|
| 553 | - */ |
|
| 554 | - |
|
| 555 | - public function __construct($response) |
|
| 556 | - { |
|
| 557 | - $encap_char = $this->_x_post_fields['encap_char']; |
|
| 558 | - $delimiter = $this->_x_post_fields['delim_char']; |
|
| 559 | - if ($response) { |
|
| 560 | - // Split Array |
|
| 561 | - $this->response = $response; |
|
| 562 | - if ($encap_char) { |
|
| 563 | - $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
| 564 | - } else { |
|
| 565 | - $this->_response_array = explode($delimiter, $response); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * If AuthorizeNet doesn't return a delimited response. |
|
| 570 | - */ |
|
| 571 | - if (count($this->_response_array) < 10) { |
|
| 572 | - $this->approved = false; |
|
| 573 | - $this->error = true; |
|
| 574 | - $this->error_message = sprintf( |
|
| 575 | - esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
| 576 | - esc_html($response) |
|
| 577 | - ); |
|
| 578 | - return; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - |
|
| 582 | - |
|
| 583 | - // Set all fields |
|
| 584 | - $this->response_code = $this->_response_array[0]; |
|
| 585 | - $this->response_subcode = $this->_response_array[1]; |
|
| 586 | - $this->response_reason_code = $this->_response_array[2]; |
|
| 587 | - $this->response_reason_text = $this->_response_array[3]; |
|
| 588 | - $this->authorization_code = $this->_response_array[4]; |
|
| 589 | - $this->avs_response = $this->_response_array[5]; |
|
| 590 | - $this->transaction_id = $this->_response_array[6]; |
|
| 591 | - $this->invoice_number = $this->_response_array[7]; |
|
| 592 | - $this->description = $this->_response_array[8]; |
|
| 593 | - $this->amount = $this->_response_array[9]; |
|
| 594 | - $this->method = $this->_response_array[10]; |
|
| 595 | - $this->transaction_type = $this->_response_array[11]; |
|
| 596 | - $this->customer_id = $this->_response_array[12]; |
|
| 597 | - $this->first_name = $this->_response_array[13]; |
|
| 598 | - $this->last_name = $this->_response_array[14]; |
|
| 599 | - $this->company = $this->_response_array[15]; |
|
| 600 | - $this->address = $this->_response_array[16]; |
|
| 601 | - $this->city = $this->_response_array[17]; |
|
| 602 | - $this->state = $this->_response_array[18]; |
|
| 603 | - $this->zip_code = $this->_response_array[19]; |
|
| 604 | - $this->country = $this->_response_array[20]; |
|
| 605 | - $this->phone = $this->_response_array[21]; |
|
| 606 | - $this->fax = $this->_response_array[22]; |
|
| 607 | - $this->email_address = $this->_response_array[23]; |
|
| 608 | - $this->ship_to_first_name = $this->_response_array[24]; |
|
| 609 | - $this->ship_to_last_name = $this->_response_array[25]; |
|
| 610 | - $this->ship_to_company = $this->_response_array[26]; |
|
| 611 | - $this->ship_to_address = $this->_response_array[27]; |
|
| 612 | - $this->ship_to_city = $this->_response_array[28]; |
|
| 613 | - $this->ship_to_state = $this->_response_array[29]; |
|
| 614 | - $this->ship_to_zip_code = $this->_response_array[30]; |
|
| 615 | - $this->ship_to_country = $this->_response_array[31]; |
|
| 616 | - $this->tax = $this->_response_array[32]; |
|
| 617 | - $this->duty = $this->_response_array[33]; |
|
| 618 | - $this->freight = $this->_response_array[34]; |
|
| 619 | - $this->tax_exempt = $this->_response_array[35]; |
|
| 620 | - $this->purchase_order_number = $this->_response_array[36]; |
|
| 621 | - $this->md5_hash = $this->_response_array[37]; |
|
| 622 | - $this->card_code_response = $this->_response_array[38]; |
|
| 623 | - $this->cavv_response = $this->_response_array[39]; |
|
| 624 | - $this->account_number = $this->_response_array[50]; |
|
| 625 | - $this->card_type = $this->_response_array[51]; |
|
| 626 | - $this->split_tender_id = $this->_response_array[52]; |
|
| 627 | - $this->requested_amount = $this->_response_array[53]; |
|
| 628 | - $this->balance_on_card = $this->_response_array[54]; |
|
| 629 | - |
|
| 630 | - $this->approved = ($this->response_code === self::APPROVED); |
|
| 631 | - $this->declined = ($this->response_code === self::DECLINED); |
|
| 632 | - $this->error = ($this->response_code === self::ERROR); |
|
| 633 | - $this->held = ($this->response_code === self::HELD); |
|
| 634 | - } else { |
|
| 635 | - $this->approved = false; |
|
| 636 | - $this->error = true; |
|
| 637 | - $this->error_message = esc_html__( |
|
| 638 | - 'Error connecting to Authorize.net', |
|
| 639 | - 'event_espresso' |
|
| 640 | - ); |
|
| 641 | - } |
|
| 642 | - } |
|
| 480 | + const APPROVED = '1'; |
|
| 481 | + const DECLINED = '2'; |
|
| 482 | + const ERROR = '3'; |
|
| 483 | + const HELD = '4'; |
|
| 484 | + |
|
| 485 | + protected $_x_post_fields = array( |
|
| 486 | + "version" => "3.1", |
|
| 487 | + "delim_char" => ",", |
|
| 488 | + "delim_data" => "TRUE", |
|
| 489 | + "relay_response" => "FALSE", |
|
| 490 | + "encap_char" => "|", |
|
| 491 | + ); |
|
| 492 | + public $approved; |
|
| 493 | + public $declined; |
|
| 494 | + public $error; |
|
| 495 | + public $held; |
|
| 496 | + public $response_code; |
|
| 497 | + public $response_subcode; |
|
| 498 | + public $response_reason_code; |
|
| 499 | + public $response_reason_text; |
|
| 500 | + public $authorization_code; |
|
| 501 | + public $avs_response; |
|
| 502 | + public $transaction_id; |
|
| 503 | + public $invoice_number; |
|
| 504 | + public $description; |
|
| 505 | + public $amount; |
|
| 506 | + public $method; |
|
| 507 | + public $transaction_type; |
|
| 508 | + public $customer_id; |
|
| 509 | + public $first_name; |
|
| 510 | + public $last_name; |
|
| 511 | + public $company; |
|
| 512 | + public $address; |
|
| 513 | + public $city; |
|
| 514 | + public $state; |
|
| 515 | + public $zip_code; |
|
| 516 | + public $country; |
|
| 517 | + public $phone; |
|
| 518 | + public $fax; |
|
| 519 | + public $email_address; |
|
| 520 | + public $ship_to_first_name; |
|
| 521 | + public $ship_to_last_name; |
|
| 522 | + public $ship_to_company; |
|
| 523 | + public $ship_to_address; |
|
| 524 | + public $ship_to_city; |
|
| 525 | + public $ship_to_state; |
|
| 526 | + public $ship_to_zip_code; |
|
| 527 | + public $ship_to_country; |
|
| 528 | + public $tax; |
|
| 529 | + public $duty; |
|
| 530 | + public $freight; |
|
| 531 | + public $tax_exempt; |
|
| 532 | + public $purchase_order_number; |
|
| 533 | + public $md5_hash; |
|
| 534 | + public $card_code_response; |
|
| 535 | + public $cavv_response; // cardholder_authentication_verification_response |
|
| 536 | + public $account_number; |
|
| 537 | + public $card_type; |
|
| 538 | + public $split_tender_id; |
|
| 539 | + public $requested_amount; |
|
| 540 | + public $balance_on_card; |
|
| 541 | + public $response; // The response string from AuthorizeNet. |
|
| 542 | + public $error_message; |
|
| 543 | + private $_response_array = array(); // An array with the split response. |
|
| 544 | + |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Constructor. Parses the AuthorizeNet response string |
|
| 548 | + * |
|
| 549 | + * @param string $response The response from the AuthNet server. |
|
| 550 | + * @var string $delimiter The delimiter used (default is ",") |
|
| 551 | + * @var string $encap_char The encap_char used (default is "|") |
|
| 552 | + * @var array $custom_fields Any custom fields set in the request. |
|
| 553 | + */ |
|
| 554 | + |
|
| 555 | + public function __construct($response) |
|
| 556 | + { |
|
| 557 | + $encap_char = $this->_x_post_fields['encap_char']; |
|
| 558 | + $delimiter = $this->_x_post_fields['delim_char']; |
|
| 559 | + if ($response) { |
|
| 560 | + // Split Array |
|
| 561 | + $this->response = $response; |
|
| 562 | + if ($encap_char) { |
|
| 563 | + $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
| 564 | + } else { |
|
| 565 | + $this->_response_array = explode($delimiter, $response); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * If AuthorizeNet doesn't return a delimited response. |
|
| 570 | + */ |
|
| 571 | + if (count($this->_response_array) < 10) { |
|
| 572 | + $this->approved = false; |
|
| 573 | + $this->error = true; |
|
| 574 | + $this->error_message = sprintf( |
|
| 575 | + esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
| 576 | + esc_html($response) |
|
| 577 | + ); |
|
| 578 | + return; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + |
|
| 582 | + |
|
| 583 | + // Set all fields |
|
| 584 | + $this->response_code = $this->_response_array[0]; |
|
| 585 | + $this->response_subcode = $this->_response_array[1]; |
|
| 586 | + $this->response_reason_code = $this->_response_array[2]; |
|
| 587 | + $this->response_reason_text = $this->_response_array[3]; |
|
| 588 | + $this->authorization_code = $this->_response_array[4]; |
|
| 589 | + $this->avs_response = $this->_response_array[5]; |
|
| 590 | + $this->transaction_id = $this->_response_array[6]; |
|
| 591 | + $this->invoice_number = $this->_response_array[7]; |
|
| 592 | + $this->description = $this->_response_array[8]; |
|
| 593 | + $this->amount = $this->_response_array[9]; |
|
| 594 | + $this->method = $this->_response_array[10]; |
|
| 595 | + $this->transaction_type = $this->_response_array[11]; |
|
| 596 | + $this->customer_id = $this->_response_array[12]; |
|
| 597 | + $this->first_name = $this->_response_array[13]; |
|
| 598 | + $this->last_name = $this->_response_array[14]; |
|
| 599 | + $this->company = $this->_response_array[15]; |
|
| 600 | + $this->address = $this->_response_array[16]; |
|
| 601 | + $this->city = $this->_response_array[17]; |
|
| 602 | + $this->state = $this->_response_array[18]; |
|
| 603 | + $this->zip_code = $this->_response_array[19]; |
|
| 604 | + $this->country = $this->_response_array[20]; |
|
| 605 | + $this->phone = $this->_response_array[21]; |
|
| 606 | + $this->fax = $this->_response_array[22]; |
|
| 607 | + $this->email_address = $this->_response_array[23]; |
|
| 608 | + $this->ship_to_first_name = $this->_response_array[24]; |
|
| 609 | + $this->ship_to_last_name = $this->_response_array[25]; |
|
| 610 | + $this->ship_to_company = $this->_response_array[26]; |
|
| 611 | + $this->ship_to_address = $this->_response_array[27]; |
|
| 612 | + $this->ship_to_city = $this->_response_array[28]; |
|
| 613 | + $this->ship_to_state = $this->_response_array[29]; |
|
| 614 | + $this->ship_to_zip_code = $this->_response_array[30]; |
|
| 615 | + $this->ship_to_country = $this->_response_array[31]; |
|
| 616 | + $this->tax = $this->_response_array[32]; |
|
| 617 | + $this->duty = $this->_response_array[33]; |
|
| 618 | + $this->freight = $this->_response_array[34]; |
|
| 619 | + $this->tax_exempt = $this->_response_array[35]; |
|
| 620 | + $this->purchase_order_number = $this->_response_array[36]; |
|
| 621 | + $this->md5_hash = $this->_response_array[37]; |
|
| 622 | + $this->card_code_response = $this->_response_array[38]; |
|
| 623 | + $this->cavv_response = $this->_response_array[39]; |
|
| 624 | + $this->account_number = $this->_response_array[50]; |
|
| 625 | + $this->card_type = $this->_response_array[51]; |
|
| 626 | + $this->split_tender_id = $this->_response_array[52]; |
|
| 627 | + $this->requested_amount = $this->_response_array[53]; |
|
| 628 | + $this->balance_on_card = $this->_response_array[54]; |
|
| 629 | + |
|
| 630 | + $this->approved = ($this->response_code === self::APPROVED); |
|
| 631 | + $this->declined = ($this->response_code === self::DECLINED); |
|
| 632 | + $this->error = ($this->response_code === self::ERROR); |
|
| 633 | + $this->held = ($this->response_code === self::HELD); |
|
| 634 | + } else { |
|
| 635 | + $this->approved = false; |
|
| 636 | + $this->error = true; |
|
| 637 | + $this->error_message = esc_html__( |
|
| 638 | + 'Error connecting to Authorize.net', |
|
| 639 | + 'event_espresso' |
|
| 640 | + ); |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | if (! class_exists('AuthorizeNetException')) { |
| 646 | - /** |
|
| 647 | - * Class AuthorizeNetException |
|
| 648 | - * |
|
| 649 | - * @package AuthorizeNet |
|
| 650 | - */ |
|
| 651 | - class AuthorizeNetException extends Exception |
|
| 652 | - { |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Construct the exception. Note: The message is NOT binary safe. |
|
| 656 | - * |
|
| 657 | - * @link http://php.net/manual/en/exception.construct.php |
|
| 658 | - * @param string $message [optional] The Exception message to throw. |
|
| 659 | - * @param int $code [optional] The Exception code. |
|
| 660 | - * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
|
| 661 | - * @since 5.1.0 |
|
| 662 | - */ |
|
| 663 | - public function __construct($message = "", $code = 0, Exception $previous = null) |
|
| 664 | - { |
|
| 665 | - parent::__construct($message, $code, $previous); |
|
| 666 | - } |
|
| 667 | - } |
|
| 646 | + /** |
|
| 647 | + * Class AuthorizeNetException |
|
| 648 | + * |
|
| 649 | + * @package AuthorizeNet |
|
| 650 | + */ |
|
| 651 | + class AuthorizeNetException extends Exception |
|
| 652 | + { |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Construct the exception. Note: The message is NOT binary safe. |
|
| 656 | + * |
|
| 657 | + * @link http://php.net/manual/en/exception.construct.php |
|
| 658 | + * @param string $message [optional] The Exception message to throw. |
|
| 659 | + * @param int $code [optional] The Exception code. |
|
| 660 | + * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
|
| 661 | + * @since 5.1.0 |
|
| 662 | + */ |
|
| 663 | + public function __construct($message = "", $code = 0, Exception $previous = null) |
|
| 664 | + { |
|
| 665 | + parent::__construct($message, $code, $previous); |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | 668 | } |
@@ -21,139 +21,139 @@ |
||
| 21 | 21 | class EE_Event_List_Shortcodes extends EE_Shortcodes |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - public function __construct() |
|
| 25 | - { |
|
| 26 | - parent::__construct(); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - protected function _init_props() |
|
| 31 | - { |
|
| 32 | - $this->label = __('Event List Shortcodes', 'event_espresso'); |
|
| 33 | - $this->description = __('All shortcodes specific to event lists', 'event_espresso'); |
|
| 34 | - $this->_shortcodes = array( |
|
| 35 | - '[EVENT_LIST]' => __('Will output a list of events', 'event_espresso'), |
|
| 36 | - ); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - |
|
| 40 | - protected function _parser($shortcode) |
|
| 41 | - { |
|
| 42 | - switch ($shortcode) { |
|
| 43 | - case '[EVENT_LIST]': |
|
| 44 | - return $this->_get_event_list(); |
|
| 45 | - break; |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * figure out what the incoming data is and then return the appropriate parsed value. |
|
| 52 | - * |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 55 | - private function _get_event_list() |
|
| 56 | - { |
|
| 57 | - $this->_validate_list_requirements(); |
|
| 58 | - |
|
| 59 | - if ($this->_data['data'] instanceof EE_Messages_Addressee) { |
|
| 60 | - return $this->_get_event_list_for_main(); |
|
| 61 | - } elseif ($this->_data['data'] instanceof EE_Registration) { |
|
| 62 | - return $this->_get_event_list_for_registration(); |
|
| 63 | - } // prevent recursive loop |
|
| 64 | - else { |
|
| 65 | - return ''; |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * This returns the parsed event list for main template |
|
| 72 | - * |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 75 | - private function _get_event_list_for_main() |
|
| 76 | - { |
|
| 77 | - |
|
| 78 | - $valid_shortcodes = array( |
|
| 79 | - 'event', |
|
| 80 | - 'attendee_list', |
|
| 81 | - 'ticket_list', |
|
| 82 | - 'datetime_list', |
|
| 83 | - 'venue', |
|
| 84 | - 'attendee', |
|
| 85 | - 'recipient_list', |
|
| 86 | - 'recipient_details', |
|
| 87 | - 'primary_registration_list', |
|
| 88 | - 'primary_registration_details', |
|
| 89 | - 'event_author', |
|
| 90 | - 'organization', |
|
| 91 | - ); |
|
| 92 | - $template = $this->_data['template']; |
|
| 93 | - $data = $this->_data['data']; |
|
| 94 | - $events = ''; |
|
| 95 | - |
|
| 96 | - // now we need to loop through the events array in EE_Messages_Addressee and send data to the EE_Parser helper. |
|
| 97 | - foreach ($data->events as $event) { |
|
| 98 | - $events .= $this->_shortcode_helper->parse_event_list_template( |
|
| 99 | - $template, |
|
| 100 | - $event['event'], |
|
| 101 | - $valid_shortcodes, |
|
| 102 | - $this->_extra_data |
|
| 103 | - ); |
|
| 104 | - } |
|
| 105 | - return $events; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * This returns the parsed event list for an attendee |
|
| 111 | - * |
|
| 112 | - * @return string |
|
| 113 | - */ |
|
| 114 | - private function _get_event_list_for_registration() |
|
| 115 | - { |
|
| 116 | - $valid_shortcodes = array( |
|
| 117 | - 'event', |
|
| 118 | - 'ticket_list', |
|
| 119 | - 'datetime_list', |
|
| 120 | - 'attendee', |
|
| 121 | - 'event_author', |
|
| 122 | - 'recipient_details', |
|
| 123 | - 'recipient_list', |
|
| 124 | - 'venue', |
|
| 125 | - 'organization', |
|
| 126 | - ); |
|
| 127 | - $template = is_array($this->_data['template']) && isset($this->_data['template']['event_list']) |
|
| 128 | - ? $this->_data['template']['event_list'] : $this->_extra_data['template']['event_list']; |
|
| 129 | - $registration = $this->_data['data']; |
|
| 130 | - |
|
| 131 | - // let's remove any existing [ATTENDEE_LIST] shortcode from the event list template so that we don't get recursion. |
|
| 132 | - $template = str_replace('[ATTENDEE_LIST]', '', $template); |
|
| 133 | - |
|
| 134 | - // here we're setting up the events for the event_list template for THIS registration. |
|
| 135 | - $evt_result = ''; |
|
| 136 | - $all_events = $this->_get_events_from_registration($registration); |
|
| 137 | - |
|
| 138 | - // we're NOT going to prepare a list of attendees this time around |
|
| 139 | - $events = ''; |
|
| 140 | - |
|
| 141 | - foreach ((array) $all_events as $event) { |
|
| 142 | - $events .= $this->_shortcode_helper->parse_event_list_template( |
|
| 143 | - $template, |
|
| 144 | - $event, |
|
| 145 | - $valid_shortcodes, |
|
| 146 | - $this->_extra_data |
|
| 147 | - ); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $events; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - private function _get_events_from_registration(EE_Registration $registration) |
|
| 155 | - { |
|
| 156 | - return isset($this->_extra_data['data']->registrations) |
|
| 157 | - ? array($this->_extra_data['data']->registrations[ $registration->ID() ]['evt_obj']) : array(); |
|
| 158 | - } |
|
| 24 | + public function __construct() |
|
| 25 | + { |
|
| 26 | + parent::__construct(); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + protected function _init_props() |
|
| 31 | + { |
|
| 32 | + $this->label = __('Event List Shortcodes', 'event_espresso'); |
|
| 33 | + $this->description = __('All shortcodes specific to event lists', 'event_espresso'); |
|
| 34 | + $this->_shortcodes = array( |
|
| 35 | + '[EVENT_LIST]' => __('Will output a list of events', 'event_espresso'), |
|
| 36 | + ); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + |
|
| 40 | + protected function _parser($shortcode) |
|
| 41 | + { |
|
| 42 | + switch ($shortcode) { |
|
| 43 | + case '[EVENT_LIST]': |
|
| 44 | + return $this->_get_event_list(); |
|
| 45 | + break; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * figure out what the incoming data is and then return the appropriate parsed value. |
|
| 52 | + * |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | + private function _get_event_list() |
|
| 56 | + { |
|
| 57 | + $this->_validate_list_requirements(); |
|
| 58 | + |
|
| 59 | + if ($this->_data['data'] instanceof EE_Messages_Addressee) { |
|
| 60 | + return $this->_get_event_list_for_main(); |
|
| 61 | + } elseif ($this->_data['data'] instanceof EE_Registration) { |
|
| 62 | + return $this->_get_event_list_for_registration(); |
|
| 63 | + } // prevent recursive loop |
|
| 64 | + else { |
|
| 65 | + return ''; |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * This returns the parsed event list for main template |
|
| 72 | + * |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | + private function _get_event_list_for_main() |
|
| 76 | + { |
|
| 77 | + |
|
| 78 | + $valid_shortcodes = array( |
|
| 79 | + 'event', |
|
| 80 | + 'attendee_list', |
|
| 81 | + 'ticket_list', |
|
| 82 | + 'datetime_list', |
|
| 83 | + 'venue', |
|
| 84 | + 'attendee', |
|
| 85 | + 'recipient_list', |
|
| 86 | + 'recipient_details', |
|
| 87 | + 'primary_registration_list', |
|
| 88 | + 'primary_registration_details', |
|
| 89 | + 'event_author', |
|
| 90 | + 'organization', |
|
| 91 | + ); |
|
| 92 | + $template = $this->_data['template']; |
|
| 93 | + $data = $this->_data['data']; |
|
| 94 | + $events = ''; |
|
| 95 | + |
|
| 96 | + // now we need to loop through the events array in EE_Messages_Addressee and send data to the EE_Parser helper. |
|
| 97 | + foreach ($data->events as $event) { |
|
| 98 | + $events .= $this->_shortcode_helper->parse_event_list_template( |
|
| 99 | + $template, |
|
| 100 | + $event['event'], |
|
| 101 | + $valid_shortcodes, |
|
| 102 | + $this->_extra_data |
|
| 103 | + ); |
|
| 104 | + } |
|
| 105 | + return $events; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * This returns the parsed event list for an attendee |
|
| 111 | + * |
|
| 112 | + * @return string |
|
| 113 | + */ |
|
| 114 | + private function _get_event_list_for_registration() |
|
| 115 | + { |
|
| 116 | + $valid_shortcodes = array( |
|
| 117 | + 'event', |
|
| 118 | + 'ticket_list', |
|
| 119 | + 'datetime_list', |
|
| 120 | + 'attendee', |
|
| 121 | + 'event_author', |
|
| 122 | + 'recipient_details', |
|
| 123 | + 'recipient_list', |
|
| 124 | + 'venue', |
|
| 125 | + 'organization', |
|
| 126 | + ); |
|
| 127 | + $template = is_array($this->_data['template']) && isset($this->_data['template']['event_list']) |
|
| 128 | + ? $this->_data['template']['event_list'] : $this->_extra_data['template']['event_list']; |
|
| 129 | + $registration = $this->_data['data']; |
|
| 130 | + |
|
| 131 | + // let's remove any existing [ATTENDEE_LIST] shortcode from the event list template so that we don't get recursion. |
|
| 132 | + $template = str_replace('[ATTENDEE_LIST]', '', $template); |
|
| 133 | + |
|
| 134 | + // here we're setting up the events for the event_list template for THIS registration. |
|
| 135 | + $evt_result = ''; |
|
| 136 | + $all_events = $this->_get_events_from_registration($registration); |
|
| 137 | + |
|
| 138 | + // we're NOT going to prepare a list of attendees this time around |
|
| 139 | + $events = ''; |
|
| 140 | + |
|
| 141 | + foreach ((array) $all_events as $event) { |
|
| 142 | + $events .= $this->_shortcode_helper->parse_event_list_template( |
|
| 143 | + $template, |
|
| 144 | + $event, |
|
| 145 | + $valid_shortcodes, |
|
| 146 | + $this->_extra_data |
|
| 147 | + ); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $events; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + private function _get_events_from_registration(EE_Registration $registration) |
|
| 155 | + { |
|
| 156 | + return isset($this->_extra_data['data']->registrations) |
|
| 157 | + ? array($this->_extra_data['data']->registrations[ $registration->ID() ]['evt_obj']) : array(); |
|
| 158 | + } |
|
| 159 | 159 | } |
@@ -18,181 +18,181 @@ |
||
| 18 | 18 | class RequestTypeContextDetector |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var RequestTypeContextFactoryInterface $factory |
|
| 23 | - */ |
|
| 24 | - private $factory; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var RequestInterface $request |
|
| 28 | - */ |
|
| 29 | - private $request; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var array $globalRouteConditions |
|
| 33 | - */ |
|
| 34 | - private $globalRouteConditions; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * RequestTypeContextDetector constructor. |
|
| 39 | - * |
|
| 40 | - * @param RequestInterface $request |
|
| 41 | - * @param RequestTypeContextFactoryInterface $factory |
|
| 42 | - * @param array $globalRouteConditions an array for injecting values that would |
|
| 43 | - * otherwise be defined as global constants |
|
| 44 | - * or other global variables for the current |
|
| 45 | - * request route such as DOING_AJAX |
|
| 46 | - */ |
|
| 47 | - public function __construct( |
|
| 48 | - RequestInterface $request, |
|
| 49 | - RequestTypeContextFactoryInterface $factory, |
|
| 50 | - array $globalRouteConditions = array() |
|
| 51 | - ) { |
|
| 52 | - $this->request = $request; |
|
| 53 | - $this->factory = $factory; |
|
| 54 | - $this->globalRouteConditions = $globalRouteConditions; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @return mixed |
|
| 60 | - */ |
|
| 61 | - private function getGlobalRouteCondition($globalRouteCondition, $default) |
|
| 62 | - { |
|
| 63 | - return isset($this->globalRouteConditions[ $globalRouteCondition ]) |
|
| 64 | - ? $this->globalRouteConditions[ $globalRouteCondition ] |
|
| 65 | - : $default; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @return RequestTypeContext |
|
| 71 | - * @throws InvalidArgumentException |
|
| 72 | - */ |
|
| 73 | - public function detectRequestTypeContext() |
|
| 74 | - { |
|
| 75 | - // Detect error scrapes |
|
| 76 | - if ($this->request->getRequestParam('wp_scrape_key') !== null |
|
| 77 | - && $this->request->getRequestParam('wp_scrape_nonce') !== null |
|
| 78 | - ) { |
|
| 79 | - return $this->factory->create(RequestTypeContext::WP_SCRAPE); |
|
| 80 | - } |
|
| 81 | - // Detect EE REST API |
|
| 82 | - if ($this->isEspressoRestApiRequest()) { |
|
| 83 | - return $this->factory->create(RequestTypeContext::API); |
|
| 84 | - } |
|
| 85 | - // Detect WP REST API |
|
| 86 | - if ($this->isWordPressRestApiRequest()) { |
|
| 87 | - return $this->factory->create(RequestTypeContext::WP_API); |
|
| 88 | - } |
|
| 89 | - // Detect AJAX |
|
| 90 | - if ($this->getGlobalRouteCondition('DOING_AJAX', false)) { |
|
| 91 | - if (filter_var($this->request->getRequestParam('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
| 92 | - return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
|
| 93 | - } |
|
| 94 | - if (filter_var($this->request->getRequestParam('ee_admin_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
| 95 | - return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
|
| 96 | - } |
|
| 97 | - if ($this->request->getRequestParam('action') === 'heartbeat') { |
|
| 98 | - return $this->factory->create(RequestTypeContext::AJAX_HEARTBEAT); |
|
| 99 | - } |
|
| 100 | - return $this->factory->create(RequestTypeContext::AJAX_OTHER); |
|
| 101 | - } |
|
| 102 | - // Detect WP_Cron |
|
| 103 | - if ($this->isCronRequest()) { |
|
| 104 | - return $this->factory->create(RequestTypeContext::CRON); |
|
| 105 | - } |
|
| 106 | - // Detect command line requests |
|
| 107 | - if ($this->getGlobalRouteCondition('WP_CLI', false)) { |
|
| 108 | - return $this->factory->create(RequestTypeContext::CLI); |
|
| 109 | - } |
|
| 110 | - // detect WordPress admin (ie: "Dashboard") |
|
| 111 | - if ($this->getGlobalRouteCondition('is_admin', false)) { |
|
| 112 | - return $this->factory->create(RequestTypeContext::ADMIN); |
|
| 113 | - } |
|
| 114 | - // Detect iFrames |
|
| 115 | - if ($this->isIframeRoute()) { |
|
| 116 | - return $this->factory->create(RequestTypeContext::IFRAME); |
|
| 117 | - } |
|
| 118 | - // Detect Feeds |
|
| 119 | - if ($this->isFeedRequest()) { |
|
| 120 | - return $this->factory->create(RequestTypeContext::FEED); |
|
| 121 | - } |
|
| 122 | - // and by process of elimination... |
|
| 123 | - return $this->factory->create(RequestTypeContext::FRONTEND); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @return bool |
|
| 129 | - */ |
|
| 130 | - private function isEspressoRestApiRequest() |
|
| 131 | - { |
|
| 132 | - // Check for URLs like http://mysite.com/?rest_route=/ee... and http://mysite.com/wp-json/ee/... |
|
| 133 | - return strpos( |
|
| 134 | - $this->request->getRequestParam('rest_route', false), |
|
| 135 | - '/' . Domain::API_NAMESPACE |
|
| 136 | - ) === 0 |
|
| 137 | - || $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . '/' . Domain::API_NAMESPACE); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @return bool |
|
| 144 | - */ |
|
| 145 | - private function isWordPressRestApiRequest() |
|
| 146 | - { |
|
| 147 | - // Check for URLs like http://mysite.com/?rest_route=/.. and http://mysite.com/wp-json/... |
|
| 148 | - return $this->request->getRequestParam('rest_route', false) |
|
| 149 | - || $this->uriPathMatches(trim(rest_get_url_prefix(), '/')); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @return bool |
|
| 155 | - */ |
|
| 156 | - private function isCronRequest() |
|
| 157 | - { |
|
| 158 | - return $this->uriPathMatches('wp-cron.php'); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @return bool |
|
| 164 | - */ |
|
| 165 | - private function isFeedRequest() |
|
| 166 | - { |
|
| 167 | - return $this->uriPathMatches('feed'); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * @param string $component |
|
| 173 | - * @return bool |
|
| 174 | - */ |
|
| 175 | - private function uriPathMatches($component) |
|
| 176 | - { |
|
| 177 | - $request_uri = $this->request->requestUri(true); |
|
| 178 | - $parts = explode('?', $request_uri); |
|
| 179 | - $path = trim(reset($parts), '/'); |
|
| 180 | - return strpos($path, $component) === 0; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @return bool |
|
| 186 | - */ |
|
| 187 | - private function isIframeRoute() |
|
| 188 | - { |
|
| 189 | - $is_iframe_route = apply_filters( |
|
| 190 | - 'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute', |
|
| 191 | - $this->request->getRequestParam('event_list', '') === 'iframe' |
|
| 192 | - || $this->request->getRequestParam('ticket_selector', '') === 'iframe' |
|
| 193 | - || $this->request->getRequestParam('calendar', '') === 'iframe', |
|
| 194 | - $this |
|
| 195 | - ); |
|
| 196 | - return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN); |
|
| 197 | - } |
|
| 21 | + /** |
|
| 22 | + * @var RequestTypeContextFactoryInterface $factory |
|
| 23 | + */ |
|
| 24 | + private $factory; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var RequestInterface $request |
|
| 28 | + */ |
|
| 29 | + private $request; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var array $globalRouteConditions |
|
| 33 | + */ |
|
| 34 | + private $globalRouteConditions; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * RequestTypeContextDetector constructor. |
|
| 39 | + * |
|
| 40 | + * @param RequestInterface $request |
|
| 41 | + * @param RequestTypeContextFactoryInterface $factory |
|
| 42 | + * @param array $globalRouteConditions an array for injecting values that would |
|
| 43 | + * otherwise be defined as global constants |
|
| 44 | + * or other global variables for the current |
|
| 45 | + * request route such as DOING_AJAX |
|
| 46 | + */ |
|
| 47 | + public function __construct( |
|
| 48 | + RequestInterface $request, |
|
| 49 | + RequestTypeContextFactoryInterface $factory, |
|
| 50 | + array $globalRouteConditions = array() |
|
| 51 | + ) { |
|
| 52 | + $this->request = $request; |
|
| 53 | + $this->factory = $factory; |
|
| 54 | + $this->globalRouteConditions = $globalRouteConditions; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @return mixed |
|
| 60 | + */ |
|
| 61 | + private function getGlobalRouteCondition($globalRouteCondition, $default) |
|
| 62 | + { |
|
| 63 | + return isset($this->globalRouteConditions[ $globalRouteCondition ]) |
|
| 64 | + ? $this->globalRouteConditions[ $globalRouteCondition ] |
|
| 65 | + : $default; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @return RequestTypeContext |
|
| 71 | + * @throws InvalidArgumentException |
|
| 72 | + */ |
|
| 73 | + public function detectRequestTypeContext() |
|
| 74 | + { |
|
| 75 | + // Detect error scrapes |
|
| 76 | + if ($this->request->getRequestParam('wp_scrape_key') !== null |
|
| 77 | + && $this->request->getRequestParam('wp_scrape_nonce') !== null |
|
| 78 | + ) { |
|
| 79 | + return $this->factory->create(RequestTypeContext::WP_SCRAPE); |
|
| 80 | + } |
|
| 81 | + // Detect EE REST API |
|
| 82 | + if ($this->isEspressoRestApiRequest()) { |
|
| 83 | + return $this->factory->create(RequestTypeContext::API); |
|
| 84 | + } |
|
| 85 | + // Detect WP REST API |
|
| 86 | + if ($this->isWordPressRestApiRequest()) { |
|
| 87 | + return $this->factory->create(RequestTypeContext::WP_API); |
|
| 88 | + } |
|
| 89 | + // Detect AJAX |
|
| 90 | + if ($this->getGlobalRouteCondition('DOING_AJAX', false)) { |
|
| 91 | + if (filter_var($this->request->getRequestParam('ee_front_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
| 92 | + return $this->factory->create(RequestTypeContext::AJAX_FRONT); |
|
| 93 | + } |
|
| 94 | + if (filter_var($this->request->getRequestParam('ee_admin_ajax'), FILTER_VALIDATE_BOOLEAN)) { |
|
| 95 | + return $this->factory->create(RequestTypeContext::AJAX_ADMIN); |
|
| 96 | + } |
|
| 97 | + if ($this->request->getRequestParam('action') === 'heartbeat') { |
|
| 98 | + return $this->factory->create(RequestTypeContext::AJAX_HEARTBEAT); |
|
| 99 | + } |
|
| 100 | + return $this->factory->create(RequestTypeContext::AJAX_OTHER); |
|
| 101 | + } |
|
| 102 | + // Detect WP_Cron |
|
| 103 | + if ($this->isCronRequest()) { |
|
| 104 | + return $this->factory->create(RequestTypeContext::CRON); |
|
| 105 | + } |
|
| 106 | + // Detect command line requests |
|
| 107 | + if ($this->getGlobalRouteCondition('WP_CLI', false)) { |
|
| 108 | + return $this->factory->create(RequestTypeContext::CLI); |
|
| 109 | + } |
|
| 110 | + // detect WordPress admin (ie: "Dashboard") |
|
| 111 | + if ($this->getGlobalRouteCondition('is_admin', false)) { |
|
| 112 | + return $this->factory->create(RequestTypeContext::ADMIN); |
|
| 113 | + } |
|
| 114 | + // Detect iFrames |
|
| 115 | + if ($this->isIframeRoute()) { |
|
| 116 | + return $this->factory->create(RequestTypeContext::IFRAME); |
|
| 117 | + } |
|
| 118 | + // Detect Feeds |
|
| 119 | + if ($this->isFeedRequest()) { |
|
| 120 | + return $this->factory->create(RequestTypeContext::FEED); |
|
| 121 | + } |
|
| 122 | + // and by process of elimination... |
|
| 123 | + return $this->factory->create(RequestTypeContext::FRONTEND); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @return bool |
|
| 129 | + */ |
|
| 130 | + private function isEspressoRestApiRequest() |
|
| 131 | + { |
|
| 132 | + // Check for URLs like http://mysite.com/?rest_route=/ee... and http://mysite.com/wp-json/ee/... |
|
| 133 | + return strpos( |
|
| 134 | + $this->request->getRequestParam('rest_route', false), |
|
| 135 | + '/' . Domain::API_NAMESPACE |
|
| 136 | + ) === 0 |
|
| 137 | + || $this->uriPathMatches(trim(rest_get_url_prefix(), '/') . '/' . Domain::API_NAMESPACE); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @return bool |
|
| 144 | + */ |
|
| 145 | + private function isWordPressRestApiRequest() |
|
| 146 | + { |
|
| 147 | + // Check for URLs like http://mysite.com/?rest_route=/.. and http://mysite.com/wp-json/... |
|
| 148 | + return $this->request->getRequestParam('rest_route', false) |
|
| 149 | + || $this->uriPathMatches(trim(rest_get_url_prefix(), '/')); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @return bool |
|
| 155 | + */ |
|
| 156 | + private function isCronRequest() |
|
| 157 | + { |
|
| 158 | + return $this->uriPathMatches('wp-cron.php'); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * @return bool |
|
| 164 | + */ |
|
| 165 | + private function isFeedRequest() |
|
| 166 | + { |
|
| 167 | + return $this->uriPathMatches('feed'); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * @param string $component |
|
| 173 | + * @return bool |
|
| 174 | + */ |
|
| 175 | + private function uriPathMatches($component) |
|
| 176 | + { |
|
| 177 | + $request_uri = $this->request->requestUri(true); |
|
| 178 | + $parts = explode('?', $request_uri); |
|
| 179 | + $path = trim(reset($parts), '/'); |
|
| 180 | + return strpos($path, $component) === 0; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @return bool |
|
| 186 | + */ |
|
| 187 | + private function isIframeRoute() |
|
| 188 | + { |
|
| 189 | + $is_iframe_route = apply_filters( |
|
| 190 | + 'FHEE__EventEspresso_core_domain_services_contexts_RequestTypeContextDetector__isIframeRoute', |
|
| 191 | + $this->request->getRequestParam('event_list', '') === 'iframe' |
|
| 192 | + || $this->request->getRequestParam('ticket_selector', '') === 'iframe' |
|
| 193 | + || $this->request->getRequestParam('calendar', '') === 'iframe', |
|
| 194 | + $this |
|
| 195 | + ); |
|
| 196 | + return filter_var($is_iframe_route, FILTER_VALIDATE_BOOLEAN); |
|
| 197 | + } |
|
| 198 | 198 | } |
@@ -17,640 +17,640 @@ |
||
| 17 | 17 | class Request implements InterminableInterface, RequestInterface, ReservedInstanceInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * $_GET parameters |
|
| 22 | - * |
|
| 23 | - * @var array $get |
|
| 24 | - */ |
|
| 25 | - private $get; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * $_POST parameters |
|
| 29 | - * |
|
| 30 | - * @var array $post |
|
| 31 | - */ |
|
| 32 | - private $post; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * $_COOKIE parameters |
|
| 36 | - * |
|
| 37 | - * @var array $cookie |
|
| 38 | - */ |
|
| 39 | - private $cookie; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * $_SERVER parameters |
|
| 43 | - * |
|
| 44 | - * @var array $server |
|
| 45 | - */ |
|
| 46 | - private $server; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * $_FILES parameters |
|
| 50 | - * |
|
| 51 | - * @var array $files |
|
| 52 | - */ |
|
| 53 | - private $files; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * $_REQUEST parameters |
|
| 57 | - * |
|
| 58 | - * @var array $request |
|
| 59 | - */ |
|
| 60 | - private $request; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var RequestTypeContextCheckerInterface |
|
| 64 | - */ |
|
| 65 | - private $request_type; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * IP address for request |
|
| 69 | - * |
|
| 70 | - * @var string $ip_address |
|
| 71 | - */ |
|
| 72 | - private $ip_address; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @var string $user_agent |
|
| 76 | - */ |
|
| 77 | - private $user_agent; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * true if current user appears to be some kind of bot |
|
| 81 | - * |
|
| 82 | - * @var bool $is_bot |
|
| 83 | - */ |
|
| 84 | - private $is_bot; |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @param array $get |
|
| 89 | - * @param array $post |
|
| 90 | - * @param array $cookie |
|
| 91 | - * @param array $server |
|
| 92 | - * @param array $files |
|
| 93 | - */ |
|
| 94 | - public function __construct(array $get, array $post, array $cookie, array $server, array $files = array()) |
|
| 95 | - { |
|
| 96 | - // grab request vars |
|
| 97 | - $this->get = $get; |
|
| 98 | - $this->post = $post; |
|
| 99 | - $this->cookie = $cookie; |
|
| 100 | - $this->server = $server; |
|
| 101 | - $this->files = $files; |
|
| 102 | - $this->request = array_merge($this->get, $this->post); |
|
| 103 | - $this->ip_address = $this->visitorIp(); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param RequestTypeContextCheckerInterface $type |
|
| 109 | - */ |
|
| 110 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
| 111 | - { |
|
| 112 | - $this->request_type = $type; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @return array |
|
| 118 | - */ |
|
| 119 | - public function getParams() |
|
| 120 | - { |
|
| 121 | - return $this->get; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return array |
|
| 127 | - */ |
|
| 128 | - public function postParams() |
|
| 129 | - { |
|
| 130 | - return $this->post; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @return array |
|
| 136 | - */ |
|
| 137 | - public function cookieParams() |
|
| 138 | - { |
|
| 139 | - return $this->cookie; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @return array |
|
| 145 | - */ |
|
| 146 | - public function serverParams() |
|
| 147 | - { |
|
| 148 | - return $this->server; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - public function filesParams() |
|
| 156 | - { |
|
| 157 | - return $this->files; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * returns contents of $_REQUEST |
|
| 163 | - * |
|
| 164 | - * @return array |
|
| 165 | - */ |
|
| 166 | - public function requestParams() |
|
| 167 | - { |
|
| 168 | - return $this->request; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @param $key |
|
| 174 | - * @param $value |
|
| 175 | - * @param bool $override_ee |
|
| 176 | - * @return void |
|
| 177 | - */ |
|
| 178 | - public function setRequestParam($key, $value, $override_ee = false) |
|
| 179 | - { |
|
| 180 | - // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
| 181 | - if ($key !== 'ee' |
|
| 182 | - || ($key === 'ee' && empty($this->request['ee'])) |
|
| 183 | - || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
| 184 | - ) { |
|
| 185 | - $this->request[ $key ] = $value; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * returns the value for a request param if the given key exists |
|
| 192 | - * |
|
| 193 | - * @param $key |
|
| 194 | - * @param null $default |
|
| 195 | - * @return mixed |
|
| 196 | - */ |
|
| 197 | - public function getRequestParam($key, $default = null) |
|
| 198 | - { |
|
| 199 | - return $this->requestParameterDrillDown($key, $default, 'get'); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * check if param exists |
|
| 205 | - * |
|
| 206 | - * @param $key |
|
| 207 | - * @return bool |
|
| 208 | - */ |
|
| 209 | - public function requestParamIsSet($key) |
|
| 210 | - { |
|
| 211 | - return $this->requestParameterDrillDown($key); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 217 | - * and return the value for the first match found |
|
| 218 | - * wildcards can be either of the following: |
|
| 219 | - * ? to represent a single character of any type |
|
| 220 | - * * to represent one or more characters of any type |
|
| 221 | - * |
|
| 222 | - * @param string $pattern |
|
| 223 | - * @param null|mixed $default |
|
| 224 | - * @return mixed |
|
| 225 | - */ |
|
| 226 | - public function getMatch($pattern, $default = null) |
|
| 227 | - { |
|
| 228 | - return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 234 | - * wildcards can be either of the following: |
|
| 235 | - * ? to represent a single character of any type |
|
| 236 | - * * to represent one or more characters of any type |
|
| 237 | - * returns true if a match is found or false if not |
|
| 238 | - * |
|
| 239 | - * @param string $pattern |
|
| 240 | - * @return bool |
|
| 241 | - */ |
|
| 242 | - public function matches($pattern) |
|
| 243 | - { |
|
| 244 | - return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
| 250 | - * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
| 251 | - * and used to search through the current request's parameter keys |
|
| 252 | - * @param array $request_params The array of request parameters to search through |
|
| 253 | - * @param mixed $default [optional] The value to be returned if no match is found. |
|
| 254 | - * Default is null |
|
| 255 | - * @param string $return [optional] Controls what kind of value is returned. |
|
| 256 | - * Options are: |
|
| 257 | - * 'bool' will return true or false if match is found or not |
|
| 258 | - * 'key' will return the first key found that matches the supplied pattern |
|
| 259 | - * 'value' will return the value for the first request parameter |
|
| 260 | - * whose key matches the supplied pattern |
|
| 261 | - * Default is 'value' |
|
| 262 | - * @return boolean|string |
|
| 263 | - */ |
|
| 264 | - private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
| 265 | - { |
|
| 266 | - $return = in_array($return, array('bool', 'key', 'value'), true) |
|
| 267 | - ? $return |
|
| 268 | - : 'is_set'; |
|
| 269 | - // replace wildcard chars with regex chars |
|
| 270 | - $pattern = str_replace( |
|
| 271 | - array("\*", "\?"), |
|
| 272 | - array('.*', '.'), |
|
| 273 | - preg_quote($pattern, '/') |
|
| 274 | - ); |
|
| 275 | - foreach ($request_params as $key => $request_param) { |
|
| 276 | - if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
| 277 | - // return value for request param |
|
| 278 | - if ($return === 'value') { |
|
| 279 | - return $request_params[ $key ]; |
|
| 280 | - } |
|
| 281 | - // or actual key or true just to indicate it was found |
|
| 282 | - return $return === 'key' ? $key : true; |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - // match not found so return default value or false |
|
| 286 | - return $return === 'value' ? $default : false; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * the supplied key can be a simple string to represent a "top-level" request parameter |
|
| 292 | - * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
| 293 | - * by using square brackets to surround keys for deeper array elements. |
|
| 294 | - * For example : |
|
| 295 | - * if the supplied $key was: "first[second][third]" |
|
| 296 | - * then this will attempt to drill down into the request parameter array to find a value. |
|
| 297 | - * Given the following request parameters: |
|
| 298 | - * array( |
|
| 299 | - * 'first' => array( |
|
| 300 | - * 'second' => array( |
|
| 301 | - * 'third' => 'has a value' |
|
| 302 | - * ) |
|
| 303 | - * ) |
|
| 304 | - * ) |
|
| 305 | - * would return true if default parameters were set |
|
| 306 | - * |
|
| 307 | - * @param string $callback |
|
| 308 | - * @param $key |
|
| 309 | - * @param null $default |
|
| 310 | - * @param array $request_params |
|
| 311 | - * @return bool|mixed|null |
|
| 312 | - */ |
|
| 313 | - private function requestParameterDrillDown( |
|
| 314 | - $key, |
|
| 315 | - $default = null, |
|
| 316 | - $callback = 'is_set', |
|
| 317 | - array $request_params = array() |
|
| 318 | - ) { |
|
| 319 | - $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
| 320 | - ? $callback |
|
| 321 | - : 'is_set'; |
|
| 322 | - $request_params = ! empty($request_params) |
|
| 323 | - ? $request_params |
|
| 324 | - : $this->request; |
|
| 325 | - // does incoming key represent an array like 'first[second][third]' ? |
|
| 326 | - if (strpos($key, '[') !== false) { |
|
| 327 | - // turn it into an actual array |
|
| 328 | - $key = str_replace(']', '', $key); |
|
| 329 | - $keys = explode('[', $key); |
|
| 330 | - $key = array_shift($keys); |
|
| 331 | - if ($callback === 'match') { |
|
| 332 | - $real_key = $this->match($key, $request_params, $default, 'key'); |
|
| 333 | - $key = $real_key ? $real_key : $key; |
|
| 334 | - } |
|
| 335 | - // check if top level key exists |
|
| 336 | - if (isset($request_params[ $key ])) { |
|
| 337 | - // build a new key to pass along like: 'second[third]' |
|
| 338 | - // or just 'second' depending on depth of keys |
|
| 339 | - $key_string = array_shift($keys); |
|
| 340 | - if (! empty($keys)) { |
|
| 341 | - $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 342 | - } |
|
| 343 | - return $this->requestParameterDrillDown( |
|
| 344 | - $key_string, |
|
| 345 | - $default, |
|
| 346 | - $callback, |
|
| 347 | - $request_params[ $key ] |
|
| 348 | - ); |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - if ($callback === 'is_set') { |
|
| 352 | - return isset($request_params[ $key ]); |
|
| 353 | - } |
|
| 354 | - if ($callback === 'match') { |
|
| 355 | - return $this->match($key, $request_params, $default); |
|
| 356 | - } |
|
| 357 | - return isset($request_params[ $key ]) |
|
| 358 | - ? $request_params[ $key ] |
|
| 359 | - : $default; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * remove param |
|
| 365 | - * |
|
| 366 | - * @param $key |
|
| 367 | - * @param bool $unset_from_global_too |
|
| 368 | - */ |
|
| 369 | - public function unSetRequestParam($key, $unset_from_global_too = false) |
|
| 370 | - { |
|
| 371 | - unset($this->request[ $key ]); |
|
| 372 | - if ($unset_from_global_too) { |
|
| 373 | - unset($_REQUEST[ $key ]); |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - /** |
|
| 379 | - * @return string |
|
| 380 | - */ |
|
| 381 | - public function ipAddress() |
|
| 382 | - { |
|
| 383 | - return $this->ip_address; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * attempt to get IP address of current visitor from server |
|
| 389 | - * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
| 390 | - * |
|
| 391 | - * @access public |
|
| 392 | - * @return string |
|
| 393 | - */ |
|
| 394 | - private function visitorIp() |
|
| 395 | - { |
|
| 396 | - $visitor_ip = '0.0.0.0'; |
|
| 397 | - $server_keys = array( |
|
| 398 | - 'HTTP_CLIENT_IP', |
|
| 399 | - 'HTTP_X_FORWARDED_FOR', |
|
| 400 | - 'HTTP_X_FORWARDED', |
|
| 401 | - 'HTTP_X_CLUSTER_CLIENT_IP', |
|
| 402 | - 'HTTP_FORWARDED_FOR', |
|
| 403 | - 'HTTP_FORWARDED', |
|
| 404 | - 'REMOTE_ADDR', |
|
| 405 | - ); |
|
| 406 | - foreach ($server_keys as $key) { |
|
| 407 | - if (isset($this->server[ $key ])) { |
|
| 408 | - foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
| 409 | - if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
| 410 | - $visitor_ip = $ip; |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - return $visitor_ip; |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - |
|
| 419 | - /** |
|
| 420 | - * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
| 421 | - * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
| 422 | - * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
| 423 | - * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
| 424 | - * @return string |
|
| 425 | - */ |
|
| 426 | - public function requestUri($relativeToWpRoot = false) |
|
| 427 | - { |
|
| 428 | - $request_uri = filter_input( |
|
| 429 | - INPUT_SERVER, |
|
| 430 | - 'REQUEST_URI', |
|
| 431 | - FILTER_SANITIZE_URL, |
|
| 432 | - FILTER_NULL_ON_FAILURE |
|
| 433 | - ); |
|
| 434 | - if (empty($request_uri)) { |
|
| 435 | - // fallback sanitization if the above fails |
|
| 436 | - $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
| 437 | - } |
|
| 438 | - if ($relativeToWpRoot) { |
|
| 439 | - $home_path = untrailingslashit( |
|
| 440 | - parse_url( |
|
| 441 | - home_url(), |
|
| 442 | - PHP_URL_PATH |
|
| 443 | - ) |
|
| 444 | - ); |
|
| 445 | - $request_uri = str_replace( |
|
| 446 | - $home_path, |
|
| 447 | - '', |
|
| 448 | - $request_uri |
|
| 449 | - ); |
|
| 450 | - } |
|
| 451 | - return $request_uri; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - /** |
|
| 455 | - * @return string |
|
| 456 | - */ |
|
| 457 | - public function userAgent() |
|
| 458 | - { |
|
| 459 | - return $this->user_agent; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * @param string $user_agent |
|
| 465 | - */ |
|
| 466 | - public function setUserAgent($user_agent = '') |
|
| 467 | - { |
|
| 468 | - if ($user_agent === '' || ! is_string($user_agent)) { |
|
| 469 | - $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
| 470 | - } |
|
| 471 | - $this->user_agent = $user_agent; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - |
|
| 475 | - /** |
|
| 476 | - * @return bool |
|
| 477 | - */ |
|
| 478 | - public function isBot() |
|
| 479 | - { |
|
| 480 | - return $this->is_bot; |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * @param bool $is_bot |
|
| 486 | - */ |
|
| 487 | - public function setIsBot($is_bot) |
|
| 488 | - { |
|
| 489 | - $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - |
|
| 493 | - /** |
|
| 494 | - * @return bool |
|
| 495 | - */ |
|
| 496 | - public function isActivation() |
|
| 497 | - { |
|
| 498 | - return $this->request_type->isActivation(); |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * @param $is_activation |
|
| 504 | - * @return bool |
|
| 505 | - */ |
|
| 506 | - public function setIsActivation($is_activation) |
|
| 507 | - { |
|
| 508 | - return $this->request_type->setIsActivation($is_activation); |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * @return bool |
|
| 514 | - */ |
|
| 515 | - public function isAdmin() |
|
| 516 | - { |
|
| 517 | - return $this->request_type->isAdmin(); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - |
|
| 521 | - /** |
|
| 522 | - * @return bool |
|
| 523 | - */ |
|
| 524 | - public function isAdminAjax() |
|
| 525 | - { |
|
| 526 | - return $this->request_type->isAdminAjax(); |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * @return bool |
|
| 532 | - */ |
|
| 533 | - public function isAjax() |
|
| 534 | - { |
|
| 535 | - return $this->request_type->isAjax(); |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - |
|
| 539 | - /** |
|
| 540 | - * @return bool |
|
| 541 | - */ |
|
| 542 | - public function isEeAjax() |
|
| 543 | - { |
|
| 544 | - return $this->request_type->isEeAjax(); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * @return bool |
|
| 550 | - */ |
|
| 551 | - public function isOtherAjax() |
|
| 552 | - { |
|
| 553 | - return $this->request_type->isOtherAjax(); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * @return bool |
|
| 559 | - */ |
|
| 560 | - public function isApi() |
|
| 561 | - { |
|
| 562 | - return $this->request_type->isApi(); |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * @return bool |
|
| 568 | - */ |
|
| 569 | - public function isCli() |
|
| 570 | - { |
|
| 571 | - return $this->request_type->isCli(); |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * @return bool |
|
| 577 | - */ |
|
| 578 | - public function isCron() |
|
| 579 | - { |
|
| 580 | - return $this->request_type->isCron(); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - |
|
| 584 | - /** |
|
| 585 | - * @return bool |
|
| 586 | - */ |
|
| 587 | - public function isFeed() |
|
| 588 | - { |
|
| 589 | - return $this->request_type->isFeed(); |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * @return bool |
|
| 595 | - */ |
|
| 596 | - public function isFrontend() |
|
| 597 | - { |
|
| 598 | - return $this->request_type->isFrontend(); |
|
| 599 | - } |
|
| 600 | - |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * @return bool |
|
| 604 | - */ |
|
| 605 | - public function isFrontAjax() |
|
| 606 | - { |
|
| 607 | - return $this->request_type->isFrontAjax(); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * @return bool |
|
| 613 | - */ |
|
| 614 | - public function isIframe() |
|
| 615 | - { |
|
| 616 | - return $this->request_type->isIframe(); |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * @return bool |
|
| 622 | - */ |
|
| 623 | - public function isWordPressApi() |
|
| 624 | - { |
|
| 625 | - return $this->request_type->isWordPressApi(); |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - |
|
| 629 | - |
|
| 630 | - /** |
|
| 631 | - * @return bool |
|
| 632 | - */ |
|
| 633 | - public function isWordPressHeartbeat() |
|
| 634 | - { |
|
| 635 | - return $this->request_type->isWordPressHeartbeat(); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * @return bool |
|
| 642 | - */ |
|
| 643 | - public function isWordPressScrape() |
|
| 644 | - { |
|
| 645 | - return $this->request_type->isWordPressScrape(); |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * @return string |
|
| 651 | - */ |
|
| 652 | - public function slug() |
|
| 653 | - { |
|
| 654 | - return $this->request_type->slug(); |
|
| 655 | - } |
|
| 20 | + /** |
|
| 21 | + * $_GET parameters |
|
| 22 | + * |
|
| 23 | + * @var array $get |
|
| 24 | + */ |
|
| 25 | + private $get; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * $_POST parameters |
|
| 29 | + * |
|
| 30 | + * @var array $post |
|
| 31 | + */ |
|
| 32 | + private $post; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * $_COOKIE parameters |
|
| 36 | + * |
|
| 37 | + * @var array $cookie |
|
| 38 | + */ |
|
| 39 | + private $cookie; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * $_SERVER parameters |
|
| 43 | + * |
|
| 44 | + * @var array $server |
|
| 45 | + */ |
|
| 46 | + private $server; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * $_FILES parameters |
|
| 50 | + * |
|
| 51 | + * @var array $files |
|
| 52 | + */ |
|
| 53 | + private $files; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * $_REQUEST parameters |
|
| 57 | + * |
|
| 58 | + * @var array $request |
|
| 59 | + */ |
|
| 60 | + private $request; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var RequestTypeContextCheckerInterface |
|
| 64 | + */ |
|
| 65 | + private $request_type; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * IP address for request |
|
| 69 | + * |
|
| 70 | + * @var string $ip_address |
|
| 71 | + */ |
|
| 72 | + private $ip_address; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @var string $user_agent |
|
| 76 | + */ |
|
| 77 | + private $user_agent; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * true if current user appears to be some kind of bot |
|
| 81 | + * |
|
| 82 | + * @var bool $is_bot |
|
| 83 | + */ |
|
| 84 | + private $is_bot; |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @param array $get |
|
| 89 | + * @param array $post |
|
| 90 | + * @param array $cookie |
|
| 91 | + * @param array $server |
|
| 92 | + * @param array $files |
|
| 93 | + */ |
|
| 94 | + public function __construct(array $get, array $post, array $cookie, array $server, array $files = array()) |
|
| 95 | + { |
|
| 96 | + // grab request vars |
|
| 97 | + $this->get = $get; |
|
| 98 | + $this->post = $post; |
|
| 99 | + $this->cookie = $cookie; |
|
| 100 | + $this->server = $server; |
|
| 101 | + $this->files = $files; |
|
| 102 | + $this->request = array_merge($this->get, $this->post); |
|
| 103 | + $this->ip_address = $this->visitorIp(); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param RequestTypeContextCheckerInterface $type |
|
| 109 | + */ |
|
| 110 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type) |
|
| 111 | + { |
|
| 112 | + $this->request_type = $type; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @return array |
|
| 118 | + */ |
|
| 119 | + public function getParams() |
|
| 120 | + { |
|
| 121 | + return $this->get; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return array |
|
| 127 | + */ |
|
| 128 | + public function postParams() |
|
| 129 | + { |
|
| 130 | + return $this->post; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @return array |
|
| 136 | + */ |
|
| 137 | + public function cookieParams() |
|
| 138 | + { |
|
| 139 | + return $this->cookie; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @return array |
|
| 145 | + */ |
|
| 146 | + public function serverParams() |
|
| 147 | + { |
|
| 148 | + return $this->server; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + public function filesParams() |
|
| 156 | + { |
|
| 157 | + return $this->files; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * returns contents of $_REQUEST |
|
| 163 | + * |
|
| 164 | + * @return array |
|
| 165 | + */ |
|
| 166 | + public function requestParams() |
|
| 167 | + { |
|
| 168 | + return $this->request; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @param $key |
|
| 174 | + * @param $value |
|
| 175 | + * @param bool $override_ee |
|
| 176 | + * @return void |
|
| 177 | + */ |
|
| 178 | + public function setRequestParam($key, $value, $override_ee = false) |
|
| 179 | + { |
|
| 180 | + // don't allow "ee" to be overwritten unless explicitly instructed to do so |
|
| 181 | + if ($key !== 'ee' |
|
| 182 | + || ($key === 'ee' && empty($this->request['ee'])) |
|
| 183 | + || ($key === 'ee' && ! empty($this->request['ee']) && $override_ee) |
|
| 184 | + ) { |
|
| 185 | + $this->request[ $key ] = $value; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * returns the value for a request param if the given key exists |
|
| 192 | + * |
|
| 193 | + * @param $key |
|
| 194 | + * @param null $default |
|
| 195 | + * @return mixed |
|
| 196 | + */ |
|
| 197 | + public function getRequestParam($key, $default = null) |
|
| 198 | + { |
|
| 199 | + return $this->requestParameterDrillDown($key, $default, 'get'); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * check if param exists |
|
| 205 | + * |
|
| 206 | + * @param $key |
|
| 207 | + * @return bool |
|
| 208 | + */ |
|
| 209 | + public function requestParamIsSet($key) |
|
| 210 | + { |
|
| 211 | + return $this->requestParameterDrillDown($key); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 217 | + * and return the value for the first match found |
|
| 218 | + * wildcards can be either of the following: |
|
| 219 | + * ? to represent a single character of any type |
|
| 220 | + * * to represent one or more characters of any type |
|
| 221 | + * |
|
| 222 | + * @param string $pattern |
|
| 223 | + * @param null|mixed $default |
|
| 224 | + * @return mixed |
|
| 225 | + */ |
|
| 226 | + public function getMatch($pattern, $default = null) |
|
| 227 | + { |
|
| 228 | + return $this->requestParameterDrillDown($pattern, $default, 'match'); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 234 | + * wildcards can be either of the following: |
|
| 235 | + * ? to represent a single character of any type |
|
| 236 | + * * to represent one or more characters of any type |
|
| 237 | + * returns true if a match is found or false if not |
|
| 238 | + * |
|
| 239 | + * @param string $pattern |
|
| 240 | + * @return bool |
|
| 241 | + */ |
|
| 242 | + public function matches($pattern) |
|
| 243 | + { |
|
| 244 | + return $this->requestParameterDrillDown($pattern, null, 'match') !== null; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * @see https://stackoverflow.com/questions/6163055/php-string-matching-with-wildcard |
|
| 250 | + * @param string $pattern A string including wildcards to be converted to a regex pattern |
|
| 251 | + * and used to search through the current request's parameter keys |
|
| 252 | + * @param array $request_params The array of request parameters to search through |
|
| 253 | + * @param mixed $default [optional] The value to be returned if no match is found. |
|
| 254 | + * Default is null |
|
| 255 | + * @param string $return [optional] Controls what kind of value is returned. |
|
| 256 | + * Options are: |
|
| 257 | + * 'bool' will return true or false if match is found or not |
|
| 258 | + * 'key' will return the first key found that matches the supplied pattern |
|
| 259 | + * 'value' will return the value for the first request parameter |
|
| 260 | + * whose key matches the supplied pattern |
|
| 261 | + * Default is 'value' |
|
| 262 | + * @return boolean|string |
|
| 263 | + */ |
|
| 264 | + private function match($pattern, array $request_params, $default = null, $return = 'value') |
|
| 265 | + { |
|
| 266 | + $return = in_array($return, array('bool', 'key', 'value'), true) |
|
| 267 | + ? $return |
|
| 268 | + : 'is_set'; |
|
| 269 | + // replace wildcard chars with regex chars |
|
| 270 | + $pattern = str_replace( |
|
| 271 | + array("\*", "\?"), |
|
| 272 | + array('.*', '.'), |
|
| 273 | + preg_quote($pattern, '/') |
|
| 274 | + ); |
|
| 275 | + foreach ($request_params as $key => $request_param) { |
|
| 276 | + if (preg_match('/^' . $pattern . '$/is', $key)) { |
|
| 277 | + // return value for request param |
|
| 278 | + if ($return === 'value') { |
|
| 279 | + return $request_params[ $key ]; |
|
| 280 | + } |
|
| 281 | + // or actual key or true just to indicate it was found |
|
| 282 | + return $return === 'key' ? $key : true; |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + // match not found so return default value or false |
|
| 286 | + return $return === 'value' ? $default : false; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * the supplied key can be a simple string to represent a "top-level" request parameter |
|
| 292 | + * or represent a key for a request parameter that is nested deeper within the request parameter array, |
|
| 293 | + * by using square brackets to surround keys for deeper array elements. |
|
| 294 | + * For example : |
|
| 295 | + * if the supplied $key was: "first[second][third]" |
|
| 296 | + * then this will attempt to drill down into the request parameter array to find a value. |
|
| 297 | + * Given the following request parameters: |
|
| 298 | + * array( |
|
| 299 | + * 'first' => array( |
|
| 300 | + * 'second' => array( |
|
| 301 | + * 'third' => 'has a value' |
|
| 302 | + * ) |
|
| 303 | + * ) |
|
| 304 | + * ) |
|
| 305 | + * would return true if default parameters were set |
|
| 306 | + * |
|
| 307 | + * @param string $callback |
|
| 308 | + * @param $key |
|
| 309 | + * @param null $default |
|
| 310 | + * @param array $request_params |
|
| 311 | + * @return bool|mixed|null |
|
| 312 | + */ |
|
| 313 | + private function requestParameterDrillDown( |
|
| 314 | + $key, |
|
| 315 | + $default = null, |
|
| 316 | + $callback = 'is_set', |
|
| 317 | + array $request_params = array() |
|
| 318 | + ) { |
|
| 319 | + $callback = in_array($callback, array('is_set', 'get', 'match'), true) |
|
| 320 | + ? $callback |
|
| 321 | + : 'is_set'; |
|
| 322 | + $request_params = ! empty($request_params) |
|
| 323 | + ? $request_params |
|
| 324 | + : $this->request; |
|
| 325 | + // does incoming key represent an array like 'first[second][third]' ? |
|
| 326 | + if (strpos($key, '[') !== false) { |
|
| 327 | + // turn it into an actual array |
|
| 328 | + $key = str_replace(']', '', $key); |
|
| 329 | + $keys = explode('[', $key); |
|
| 330 | + $key = array_shift($keys); |
|
| 331 | + if ($callback === 'match') { |
|
| 332 | + $real_key = $this->match($key, $request_params, $default, 'key'); |
|
| 333 | + $key = $real_key ? $real_key : $key; |
|
| 334 | + } |
|
| 335 | + // check if top level key exists |
|
| 336 | + if (isset($request_params[ $key ])) { |
|
| 337 | + // build a new key to pass along like: 'second[third]' |
|
| 338 | + // or just 'second' depending on depth of keys |
|
| 339 | + $key_string = array_shift($keys); |
|
| 340 | + if (! empty($keys)) { |
|
| 341 | + $key_string .= '[' . implode('][', $keys) . ']'; |
|
| 342 | + } |
|
| 343 | + return $this->requestParameterDrillDown( |
|
| 344 | + $key_string, |
|
| 345 | + $default, |
|
| 346 | + $callback, |
|
| 347 | + $request_params[ $key ] |
|
| 348 | + ); |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + if ($callback === 'is_set') { |
|
| 352 | + return isset($request_params[ $key ]); |
|
| 353 | + } |
|
| 354 | + if ($callback === 'match') { |
|
| 355 | + return $this->match($key, $request_params, $default); |
|
| 356 | + } |
|
| 357 | + return isset($request_params[ $key ]) |
|
| 358 | + ? $request_params[ $key ] |
|
| 359 | + : $default; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * remove param |
|
| 365 | + * |
|
| 366 | + * @param $key |
|
| 367 | + * @param bool $unset_from_global_too |
|
| 368 | + */ |
|
| 369 | + public function unSetRequestParam($key, $unset_from_global_too = false) |
|
| 370 | + { |
|
| 371 | + unset($this->request[ $key ]); |
|
| 372 | + if ($unset_from_global_too) { |
|
| 373 | + unset($_REQUEST[ $key ]); |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + /** |
|
| 379 | + * @return string |
|
| 380 | + */ |
|
| 381 | + public function ipAddress() |
|
| 382 | + { |
|
| 383 | + return $this->ip_address; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * attempt to get IP address of current visitor from server |
|
| 389 | + * plz see: http://stackoverflow.com/a/2031935/1475279 |
|
| 390 | + * |
|
| 391 | + * @access public |
|
| 392 | + * @return string |
|
| 393 | + */ |
|
| 394 | + private function visitorIp() |
|
| 395 | + { |
|
| 396 | + $visitor_ip = '0.0.0.0'; |
|
| 397 | + $server_keys = array( |
|
| 398 | + 'HTTP_CLIENT_IP', |
|
| 399 | + 'HTTP_X_FORWARDED_FOR', |
|
| 400 | + 'HTTP_X_FORWARDED', |
|
| 401 | + 'HTTP_X_CLUSTER_CLIENT_IP', |
|
| 402 | + 'HTTP_FORWARDED_FOR', |
|
| 403 | + 'HTTP_FORWARDED', |
|
| 404 | + 'REMOTE_ADDR', |
|
| 405 | + ); |
|
| 406 | + foreach ($server_keys as $key) { |
|
| 407 | + if (isset($this->server[ $key ])) { |
|
| 408 | + foreach (array_map('trim', explode(',', $this->server[ $key ])) as $ip) { |
|
| 409 | + if ($ip === '127.0.0.1' || filter_var($ip, FILTER_VALIDATE_IP) !== false) { |
|
| 410 | + $visitor_ip = $ip; |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + return $visitor_ip; |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + |
|
| 419 | + /** |
|
| 420 | + * Gets the request's literal URI. Related to `requestUriAfterSiteHomeUri`, see its description for a comparison. |
|
| 421 | + * @param boolean $relativeToWpRoot If home_url() is "http://mysite.com/wp/", and a request comes to |
|
| 422 | + * "http://mysite.com/wp/wp-json", setting $relativeToWpRoot=true will return |
|
| 423 | + * "/wp-json", whereas $relativeToWpRoot=false will return "/wp/wp-json/". |
|
| 424 | + * @return string |
|
| 425 | + */ |
|
| 426 | + public function requestUri($relativeToWpRoot = false) |
|
| 427 | + { |
|
| 428 | + $request_uri = filter_input( |
|
| 429 | + INPUT_SERVER, |
|
| 430 | + 'REQUEST_URI', |
|
| 431 | + FILTER_SANITIZE_URL, |
|
| 432 | + FILTER_NULL_ON_FAILURE |
|
| 433 | + ); |
|
| 434 | + if (empty($request_uri)) { |
|
| 435 | + // fallback sanitization if the above fails |
|
| 436 | + $request_uri = wp_sanitize_redirect($this->server['REQUEST_URI']); |
|
| 437 | + } |
|
| 438 | + if ($relativeToWpRoot) { |
|
| 439 | + $home_path = untrailingslashit( |
|
| 440 | + parse_url( |
|
| 441 | + home_url(), |
|
| 442 | + PHP_URL_PATH |
|
| 443 | + ) |
|
| 444 | + ); |
|
| 445 | + $request_uri = str_replace( |
|
| 446 | + $home_path, |
|
| 447 | + '', |
|
| 448 | + $request_uri |
|
| 449 | + ); |
|
| 450 | + } |
|
| 451 | + return $request_uri; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + /** |
|
| 455 | + * @return string |
|
| 456 | + */ |
|
| 457 | + public function userAgent() |
|
| 458 | + { |
|
| 459 | + return $this->user_agent; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * @param string $user_agent |
|
| 465 | + */ |
|
| 466 | + public function setUserAgent($user_agent = '') |
|
| 467 | + { |
|
| 468 | + if ($user_agent === '' || ! is_string($user_agent)) { |
|
| 469 | + $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? (string) esc_attr($_SERVER['HTTP_USER_AGENT']) : ''; |
|
| 470 | + } |
|
| 471 | + $this->user_agent = $user_agent; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + |
|
| 475 | + /** |
|
| 476 | + * @return bool |
|
| 477 | + */ |
|
| 478 | + public function isBot() |
|
| 479 | + { |
|
| 480 | + return $this->is_bot; |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * @param bool $is_bot |
|
| 486 | + */ |
|
| 487 | + public function setIsBot($is_bot) |
|
| 488 | + { |
|
| 489 | + $this->is_bot = filter_var($is_bot, FILTER_VALIDATE_BOOLEAN); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + |
|
| 493 | + /** |
|
| 494 | + * @return bool |
|
| 495 | + */ |
|
| 496 | + public function isActivation() |
|
| 497 | + { |
|
| 498 | + return $this->request_type->isActivation(); |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * @param $is_activation |
|
| 504 | + * @return bool |
|
| 505 | + */ |
|
| 506 | + public function setIsActivation($is_activation) |
|
| 507 | + { |
|
| 508 | + return $this->request_type->setIsActivation($is_activation); |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * @return bool |
|
| 514 | + */ |
|
| 515 | + public function isAdmin() |
|
| 516 | + { |
|
| 517 | + return $this->request_type->isAdmin(); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + |
|
| 521 | + /** |
|
| 522 | + * @return bool |
|
| 523 | + */ |
|
| 524 | + public function isAdminAjax() |
|
| 525 | + { |
|
| 526 | + return $this->request_type->isAdminAjax(); |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * @return bool |
|
| 532 | + */ |
|
| 533 | + public function isAjax() |
|
| 534 | + { |
|
| 535 | + return $this->request_type->isAjax(); |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + |
|
| 539 | + /** |
|
| 540 | + * @return bool |
|
| 541 | + */ |
|
| 542 | + public function isEeAjax() |
|
| 543 | + { |
|
| 544 | + return $this->request_type->isEeAjax(); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * @return bool |
|
| 550 | + */ |
|
| 551 | + public function isOtherAjax() |
|
| 552 | + { |
|
| 553 | + return $this->request_type->isOtherAjax(); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * @return bool |
|
| 559 | + */ |
|
| 560 | + public function isApi() |
|
| 561 | + { |
|
| 562 | + return $this->request_type->isApi(); |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * @return bool |
|
| 568 | + */ |
|
| 569 | + public function isCli() |
|
| 570 | + { |
|
| 571 | + return $this->request_type->isCli(); |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * @return bool |
|
| 577 | + */ |
|
| 578 | + public function isCron() |
|
| 579 | + { |
|
| 580 | + return $this->request_type->isCron(); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + |
|
| 584 | + /** |
|
| 585 | + * @return bool |
|
| 586 | + */ |
|
| 587 | + public function isFeed() |
|
| 588 | + { |
|
| 589 | + return $this->request_type->isFeed(); |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * @return bool |
|
| 595 | + */ |
|
| 596 | + public function isFrontend() |
|
| 597 | + { |
|
| 598 | + return $this->request_type->isFrontend(); |
|
| 599 | + } |
|
| 600 | + |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * @return bool |
|
| 604 | + */ |
|
| 605 | + public function isFrontAjax() |
|
| 606 | + { |
|
| 607 | + return $this->request_type->isFrontAjax(); |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * @return bool |
|
| 613 | + */ |
|
| 614 | + public function isIframe() |
|
| 615 | + { |
|
| 616 | + return $this->request_type->isIframe(); |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * @return bool |
|
| 622 | + */ |
|
| 623 | + public function isWordPressApi() |
|
| 624 | + { |
|
| 625 | + return $this->request_type->isWordPressApi(); |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + |
|
| 629 | + |
|
| 630 | + /** |
|
| 631 | + * @return bool |
|
| 632 | + */ |
|
| 633 | + public function isWordPressHeartbeat() |
|
| 634 | + { |
|
| 635 | + return $this->request_type->isWordPressHeartbeat(); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * @return bool |
|
| 642 | + */ |
|
| 643 | + public function isWordPressScrape() |
|
| 644 | + { |
|
| 645 | + return $this->request_type->isWordPressScrape(); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * @return string |
|
| 651 | + */ |
|
| 652 | + public function slug() |
|
| 653 | + { |
|
| 654 | + return $this->request_type->slug(); |
|
| 655 | + } |
|
| 656 | 656 | } |
@@ -16,146 +16,146 @@ |
||
| 16 | 16 | interface RequestInterface extends RequestTypeContextCheckerInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @param RequestTypeContextCheckerInterface $type |
|
| 21 | - */ |
|
| 22 | - public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @return array |
|
| 26 | - */ |
|
| 27 | - public function getParams(); |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @return array |
|
| 32 | - */ |
|
| 33 | - public function postParams(); |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @return array |
|
| 38 | - */ |
|
| 39 | - public function cookieParams(); |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @return array |
|
| 44 | - */ |
|
| 45 | - public function serverParams(); |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @return array |
|
| 50 | - */ |
|
| 51 | - public function filesParams(); |
|
| 19 | + /** |
|
| 20 | + * @param RequestTypeContextCheckerInterface $type |
|
| 21 | + */ |
|
| 22 | + public function setRequestTypeContextChecker(RequestTypeContextCheckerInterface $type); |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @return array |
|
| 26 | + */ |
|
| 27 | + public function getParams(); |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @return array |
|
| 32 | + */ |
|
| 33 | + public function postParams(); |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @return array |
|
| 38 | + */ |
|
| 39 | + public function cookieParams(); |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @return array |
|
| 44 | + */ |
|
| 45 | + public function serverParams(); |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @return array |
|
| 50 | + */ |
|
| 51 | + public function filesParams(); |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * returns contents of $_REQUEST |
|
| 56 | - * |
|
| 57 | - * @return array |
|
| 58 | - */ |
|
| 59 | - public function requestParams(); |
|
| 54 | + /** |
|
| 55 | + * returns contents of $_REQUEST |
|
| 56 | + * |
|
| 57 | + * @return array |
|
| 58 | + */ |
|
| 59 | + public function requestParams(); |
|
| 60 | 60 | |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @param string $key |
|
| 64 | - * @param string $value |
|
| 65 | - * @param bool $override_ee |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public function setRequestParam($key, $value, $override_ee = false); |
|
| 62 | + /** |
|
| 63 | + * @param string $key |
|
| 64 | + * @param string $value |
|
| 65 | + * @param bool $override_ee |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public function setRequestParam($key, $value, $override_ee = false); |
|
| 69 | 69 | |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * returns the value for a request param if the given key exists |
|
| 73 | - * |
|
| 74 | - * @param string $key |
|
| 75 | - * @param null $default |
|
| 76 | - * @return mixed |
|
| 77 | - */ |
|
| 78 | - public function getRequestParam($key, $default = null); |
|
| 71 | + /** |
|
| 72 | + * returns the value for a request param if the given key exists |
|
| 73 | + * |
|
| 74 | + * @param string $key |
|
| 75 | + * @param null $default |
|
| 76 | + * @return mixed |
|
| 77 | + */ |
|
| 78 | + public function getRequestParam($key, $default = null); |
|
| 79 | 79 | |
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * check if param exists |
|
| 83 | - * |
|
| 84 | - * @param string $key |
|
| 85 | - * @return bool |
|
| 86 | - */ |
|
| 87 | - public function requestParamIsSet($key); |
|
| 81 | + /** |
|
| 82 | + * check if param exists |
|
| 83 | + * |
|
| 84 | + * @param string $key |
|
| 85 | + * @return bool |
|
| 86 | + */ |
|
| 87 | + public function requestParamIsSet($key); |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 92 | - * and return the value for the first match found |
|
| 93 | - * wildcards can be either of the following: |
|
| 94 | - * ? to represent a single character of any type |
|
| 95 | - * * to represent one or more characters of any type |
|
| 96 | - * |
|
| 97 | - * @param string $pattern |
|
| 98 | - * @param null|mixed $default |
|
| 99 | - * @return false|int |
|
| 100 | - */ |
|
| 101 | - public function getMatch($pattern, $default = null); |
|
| 90 | + /** |
|
| 91 | + * check if a request parameter exists whose key that matches the supplied wildcard pattern |
|
| 92 | + * and return the value for the first match found |
|
| 93 | + * wildcards can be either of the following: |
|
| 94 | + * ? to represent a single character of any type |
|
| 95 | + * * to represent one or more characters of any type |
|
| 96 | + * |
|
| 97 | + * @param string $pattern |
|
| 98 | + * @param null|mixed $default |
|
| 99 | + * @return false|int |
|
| 100 | + */ |
|
| 101 | + public function getMatch($pattern, $default = null); |
|
| 102 | 102 | |
| 103 | 103 | |
| 104 | - /** |
|
| 105 | - * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 106 | - * wildcards can be either of the following: |
|
| 107 | - * ? to represent a single character of any type |
|
| 108 | - * * to represent one or more characters of any type |
|
| 109 | - * returns true if a match is found or false if not |
|
| 110 | - * |
|
| 111 | - * @param string $pattern |
|
| 112 | - * @return false|int |
|
| 113 | - */ |
|
| 114 | - public function matches($pattern); |
|
| 104 | + /** |
|
| 105 | + * check if a request parameter exists whose key matches the supplied wildcard pattern |
|
| 106 | + * wildcards can be either of the following: |
|
| 107 | + * ? to represent a single character of any type |
|
| 108 | + * * to represent one or more characters of any type |
|
| 109 | + * returns true if a match is found or false if not |
|
| 110 | + * |
|
| 111 | + * @param string $pattern |
|
| 112 | + * @return false|int |
|
| 113 | + */ |
|
| 114 | + public function matches($pattern); |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * remove param |
|
| 119 | - * |
|
| 120 | - * @param string $key |
|
| 121 | - * @param bool $unset_from_global_too |
|
| 122 | - */ |
|
| 123 | - public function unSetRequestParam($key, $unset_from_global_too = false); |
|
| 117 | + /** |
|
| 118 | + * remove param |
|
| 119 | + * |
|
| 120 | + * @param string $key |
|
| 121 | + * @param bool $unset_from_global_too |
|
| 122 | + */ |
|
| 123 | + public function unSetRequestParam($key, $unset_from_global_too = false); |
|
| 124 | 124 | |
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - public function ipAddress(); |
|
| 126 | + /** |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + public function ipAddress(); |
|
| 130 | 130 | |
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not. |
|
| 134 | - * @return string |
|
| 135 | - */ |
|
| 136 | - public function requestUri($relativeToWpRoot = false); |
|
| 137 | - |
|
| 132 | + /** |
|
| 133 | + * @param boolean $relativeToWpRoot whether to return the uri relative to WordPress' home URL, or not. |
|
| 134 | + * @return string |
|
| 135 | + */ |
|
| 136 | + public function requestUri($relativeToWpRoot = false); |
|
| 137 | + |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * @return string |
|
| 141 | - */ |
|
| 142 | - public function userAgent(); |
|
| 143 | - |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @param string $user_agent |
|
| 147 | - */ |
|
| 148 | - public function setUserAgent($user_agent = ''); |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @return bool |
|
| 153 | - */ |
|
| 154 | - public function isBot(); |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @param bool $is_bot |
|
| 159 | - */ |
|
| 160 | - public function setIsBot($is_bot); |
|
| 139 | + /** |
|
| 140 | + * @return string |
|
| 141 | + */ |
|
| 142 | + public function userAgent(); |
|
| 143 | + |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @param string $user_agent |
|
| 147 | + */ |
|
| 148 | + public function setUserAgent($user_agent = ''); |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @return bool |
|
| 153 | + */ |
|
| 154 | + public function isBot(); |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @param bool $is_bot |
|
| 159 | + */ |
|
| 160 | + public function setIsBot($is_bot); |
|
| 161 | 161 | } |
@@ -13,1357 +13,1357 @@ |
||
| 13 | 13 | class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * cached value for the the logical active status for the event |
|
| 18 | - * |
|
| 19 | - * @see get_active_status() |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $_active_status = ''; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
| 26 | - * |
|
| 27 | - * @var EE_Datetime |
|
| 28 | - */ |
|
| 29 | - protected $_Primary_Datetime; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var EventSpacesCalculator $available_spaces_calculator |
|
| 33 | - */ |
|
| 34 | - protected $available_spaces_calculator; |
|
| 35 | - |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @param array $props_n_values incoming values |
|
| 39 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 40 | - * used.) |
|
| 41 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 42 | - * date_format and the second value is the time format |
|
| 43 | - * @return EE_Event |
|
| 44 | - * @throws EE_Error |
|
| 45 | - */ |
|
| 46 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 47 | - { |
|
| 48 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 49 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param array $props_n_values incoming values from the database |
|
| 55 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 56 | - * the website will be used. |
|
| 57 | - * @return EE_Event |
|
| 58 | - * @throws EE_Error |
|
| 59 | - */ |
|
| 60 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 61 | - { |
|
| 62 | - return new self($props_n_values, true, $timezone); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @return EventSpacesCalculator |
|
| 68 | - * @throws \EE_Error |
|
| 69 | - */ |
|
| 70 | - public function getAvailableSpacesCalculator() |
|
| 71 | - { |
|
| 72 | - if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
| 73 | - $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
| 74 | - } |
|
| 75 | - return $this->available_spaces_calculator; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
| 81 | - * |
|
| 82 | - * @param string $field_name |
|
| 83 | - * @param mixed $field_value |
|
| 84 | - * @param bool $use_default |
|
| 85 | - * @throws EE_Error |
|
| 86 | - */ |
|
| 87 | - public function set($field_name, $field_value, $use_default = false) |
|
| 88 | - { |
|
| 89 | - switch ($field_name) { |
|
| 90 | - case 'status': |
|
| 91 | - $this->set_status($field_value, $use_default); |
|
| 92 | - break; |
|
| 93 | - default: |
|
| 94 | - parent::set($field_name, $field_value, $use_default); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * set_status |
|
| 101 | - * Checks if event status is being changed to SOLD OUT |
|
| 102 | - * and updates event meta data with previous event status |
|
| 103 | - * so that we can revert things if/when the event is no longer sold out |
|
| 104 | - * |
|
| 105 | - * @access public |
|
| 106 | - * @param string $new_status |
|
| 107 | - * @param bool $use_default |
|
| 108 | - * @return void |
|
| 109 | - * @throws EE_Error |
|
| 110 | - */ |
|
| 111 | - public function set_status($new_status = null, $use_default = false) |
|
| 112 | - { |
|
| 113 | - // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
| 114 | - if (empty($new_status) && ! $use_default) { |
|
| 115 | - return; |
|
| 116 | - } |
|
| 117 | - // get current Event status |
|
| 118 | - $old_status = $this->status(); |
|
| 119 | - // if status has changed |
|
| 120 | - if ($old_status !== $new_status) { |
|
| 121 | - // TO sold_out |
|
| 122 | - if ($new_status === EEM_Event::sold_out) { |
|
| 123 | - // save the previous event status so that we can revert if the event is no longer sold out |
|
| 124 | - $this->add_post_meta('_previous_event_status', $old_status); |
|
| 125 | - do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
| 126 | - // OR FROM sold_out |
|
| 127 | - } elseif ($old_status === EEM_Event::sold_out) { |
|
| 128 | - $this->delete_post_meta('_previous_event_status'); |
|
| 129 | - do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
| 130 | - } |
|
| 131 | - // clear out the active status so that it gets reset the next time it is requested |
|
| 132 | - $this->_active_status = null; |
|
| 133 | - // update status |
|
| 134 | - parent::set('status', $new_status, $use_default); |
|
| 135 | - do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
| 136 | - return; |
|
| 137 | - } |
|
| 138 | - // even though the old value matches the new value, it's still good to |
|
| 139 | - // allow the parent set method to have a say |
|
| 140 | - parent::set('status', $new_status, $use_default); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Gets all the datetimes for this event |
|
| 146 | - * |
|
| 147 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 148 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
| 149 | - * @throws EE_Error |
|
| 150 | - */ |
|
| 151 | - public function datetimes($query_params = array()) |
|
| 152 | - { |
|
| 153 | - return $this->get_many_related('Datetime', $query_params); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
| 159 | - * |
|
| 160 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
| 161 | - * @throws EE_Error |
|
| 162 | - */ |
|
| 163 | - public function datetimes_in_chronological_order() |
|
| 164 | - { |
|
| 165 | - return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
| 171 | - * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
| 172 | - * after running our query, so that this timezone isn't set for EVERY query |
|
| 173 | - * on EEM_Datetime for the rest of the request, no? |
|
| 174 | - * |
|
| 175 | - * @param boolean $show_expired whether or not to include expired events |
|
| 176 | - * @param boolean $show_deleted whether or not to include deleted events |
|
| 177 | - * @param null $limit |
|
| 178 | - * @return EE_Datetime[] |
|
| 179 | - * @throws EE_Error |
|
| 180 | - */ |
|
| 181 | - public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
| 182 | - { |
|
| 183 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
| 184 | - $this->ID(), |
|
| 185 | - $show_expired, |
|
| 186 | - $show_deleted, |
|
| 187 | - $limit |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Returns one related datetime. Mostly only used by some legacy code. |
|
| 194 | - * |
|
| 195 | - * @return EE_Base_Class|EE_Datetime |
|
| 196 | - * @throws EE_Error |
|
| 197 | - */ |
|
| 198 | - public function first_datetime() |
|
| 199 | - { |
|
| 200 | - return $this->get_first_related('Datetime'); |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Returns the 'primary' datetime for the event |
|
| 206 | - * |
|
| 207 | - * @param bool $try_to_exclude_expired |
|
| 208 | - * @param bool $try_to_exclude_deleted |
|
| 209 | - * @return EE_Datetime |
|
| 210 | - * @throws EE_Error |
|
| 211 | - */ |
|
| 212 | - public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
| 213 | - { |
|
| 214 | - if (! empty($this->_Primary_Datetime)) { |
|
| 215 | - return $this->_Primary_Datetime; |
|
| 216 | - } |
|
| 217 | - $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
| 218 | - $this->ID(), |
|
| 219 | - $try_to_exclude_expired, |
|
| 220 | - $try_to_exclude_deleted |
|
| 221 | - ); |
|
| 222 | - return $this->_Primary_Datetime; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Gets all the tickets available for purchase of this event |
|
| 228 | - * |
|
| 229 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 230 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
| 231 | - * @throws EE_Error |
|
| 232 | - */ |
|
| 233 | - public function tickets($query_params = array()) |
|
| 234 | - { |
|
| 235 | - // first get all datetimes |
|
| 236 | - $datetimes = $this->datetimes_ordered(); |
|
| 237 | - if (! $datetimes) { |
|
| 238 | - return array(); |
|
| 239 | - } |
|
| 240 | - $datetime_ids = array(); |
|
| 241 | - foreach ($datetimes as $datetime) { |
|
| 242 | - $datetime_ids[] = $datetime->ID(); |
|
| 243 | - } |
|
| 244 | - $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
| 245 | - // if incoming $query_params has where conditions let's merge but not override existing. |
|
| 246 | - if (is_array($query_params) && isset($query_params[0])) { |
|
| 247 | - $where_params = array_merge($query_params[0], $where_params); |
|
| 248 | - unset($query_params[0]); |
|
| 249 | - } |
|
| 250 | - // now add $where_params to $query_params |
|
| 251 | - $query_params[0] = $where_params; |
|
| 252 | - return EEM_Ticket::instance()->get_all($query_params); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * get all unexpired untrashed tickets |
|
| 258 | - * |
|
| 259 | - * @return EE_Ticket[] |
|
| 260 | - * @throws EE_Error |
|
| 261 | - */ |
|
| 262 | - public function active_tickets() |
|
| 263 | - { |
|
| 264 | - return $this->tickets( |
|
| 265 | - array( |
|
| 266 | - array( |
|
| 267 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 268 | - 'TKT_deleted' => false, |
|
| 269 | - ), |
|
| 270 | - ) |
|
| 271 | - ); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @return bool |
|
| 277 | - * @throws EE_Error |
|
| 278 | - */ |
|
| 279 | - public function additional_limit() |
|
| 280 | - { |
|
| 281 | - return $this->get('EVT_additional_limit'); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * @return bool |
|
| 287 | - * @throws EE_Error |
|
| 288 | - */ |
|
| 289 | - public function allow_overflow() |
|
| 290 | - { |
|
| 291 | - return $this->get('EVT_allow_overflow'); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * @return bool |
|
| 297 | - * @throws EE_Error |
|
| 298 | - */ |
|
| 299 | - public function created() |
|
| 300 | - { |
|
| 301 | - return $this->get('EVT_created'); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * @return bool |
|
| 307 | - * @throws EE_Error |
|
| 308 | - */ |
|
| 309 | - public function description() |
|
| 310 | - { |
|
| 311 | - return $this->get('EVT_desc'); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Runs do_shortcode and wpautop on the description |
|
| 317 | - * |
|
| 318 | - * @return string of html |
|
| 319 | - * @throws EE_Error |
|
| 320 | - */ |
|
| 321 | - public function description_filtered() |
|
| 322 | - { |
|
| 323 | - return $this->get_pretty('EVT_desc'); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - /** |
|
| 328 | - * @return bool |
|
| 329 | - * @throws EE_Error |
|
| 330 | - */ |
|
| 331 | - public function display_description() |
|
| 332 | - { |
|
| 333 | - return $this->get('EVT_display_desc'); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * @return bool |
|
| 339 | - * @throws EE_Error |
|
| 340 | - */ |
|
| 341 | - public function display_ticket_selector() |
|
| 342 | - { |
|
| 343 | - return (bool) $this->get('EVT_display_ticket_selector'); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * @return bool |
|
| 349 | - * @throws EE_Error |
|
| 350 | - */ |
|
| 351 | - public function external_url() |
|
| 352 | - { |
|
| 353 | - return $this->get('EVT_external_URL'); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * @return bool |
|
| 359 | - * @throws EE_Error |
|
| 360 | - */ |
|
| 361 | - public function member_only() |
|
| 362 | - { |
|
| 363 | - return $this->get('EVT_member_only'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * @return bool |
|
| 369 | - * @throws EE_Error |
|
| 370 | - */ |
|
| 371 | - public function phone() |
|
| 372 | - { |
|
| 373 | - return $this->get('EVT_phone'); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * @return bool |
|
| 379 | - * @throws EE_Error |
|
| 380 | - */ |
|
| 381 | - public function modified() |
|
| 382 | - { |
|
| 383 | - return $this->get('EVT_modified'); |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * @return bool |
|
| 389 | - * @throws EE_Error |
|
| 390 | - */ |
|
| 391 | - public function name() |
|
| 392 | - { |
|
| 393 | - return $this->get('EVT_name'); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * @return bool |
|
| 399 | - * @throws EE_Error |
|
| 400 | - */ |
|
| 401 | - public function order() |
|
| 402 | - { |
|
| 403 | - return $this->get('EVT_order'); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * @return bool|string |
|
| 409 | - * @throws EE_Error |
|
| 410 | - */ |
|
| 411 | - public function default_registration_status() |
|
| 412 | - { |
|
| 413 | - $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
| 414 | - return ! empty($event_default_registration_status) |
|
| 415 | - ? $event_default_registration_status |
|
| 416 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * @param int $num_words |
|
| 422 | - * @param null $more |
|
| 423 | - * @param bool $not_full_desc |
|
| 424 | - * @return bool|string |
|
| 425 | - * @throws EE_Error |
|
| 426 | - */ |
|
| 427 | - public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
| 428 | - { |
|
| 429 | - $short_desc = $this->get('EVT_short_desc'); |
|
| 430 | - if (! empty($short_desc) || $not_full_desc) { |
|
| 431 | - return $short_desc; |
|
| 432 | - } |
|
| 433 | - $full_desc = $this->get('EVT_desc'); |
|
| 434 | - return wp_trim_words($full_desc, $num_words, $more); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * @return bool |
|
| 440 | - * @throws EE_Error |
|
| 441 | - */ |
|
| 442 | - public function slug() |
|
| 443 | - { |
|
| 444 | - return $this->get('EVT_slug'); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * @return bool |
|
| 450 | - * @throws EE_Error |
|
| 451 | - */ |
|
| 452 | - public function timezone_string() |
|
| 453 | - { |
|
| 454 | - return $this->get('EVT_timezone_string'); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * @return bool |
|
| 460 | - * @throws EE_Error |
|
| 461 | - */ |
|
| 462 | - public function visible_on() |
|
| 463 | - { |
|
| 464 | - return $this->get('EVT_visible_on'); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * @return int |
|
| 470 | - * @throws EE_Error |
|
| 471 | - */ |
|
| 472 | - public function wp_user() |
|
| 473 | - { |
|
| 474 | - return $this->get('EVT_wp_user'); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * @return bool |
|
| 480 | - * @throws EE_Error |
|
| 481 | - */ |
|
| 482 | - public function donations() |
|
| 483 | - { |
|
| 484 | - return $this->get('EVT_donations'); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * @param $limit |
|
| 490 | - * @throws EE_Error |
|
| 491 | - */ |
|
| 492 | - public function set_additional_limit($limit) |
|
| 493 | - { |
|
| 494 | - $this->set('EVT_additional_limit', $limit); |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * @param $created |
|
| 500 | - * @throws EE_Error |
|
| 501 | - */ |
|
| 502 | - public function set_created($created) |
|
| 503 | - { |
|
| 504 | - $this->set('EVT_created', $created); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * @param $desc |
|
| 510 | - * @throws EE_Error |
|
| 511 | - */ |
|
| 512 | - public function set_description($desc) |
|
| 513 | - { |
|
| 514 | - $this->set('EVT_desc', $desc); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * @param $display_desc |
|
| 520 | - * @throws EE_Error |
|
| 521 | - */ |
|
| 522 | - public function set_display_description($display_desc) |
|
| 523 | - { |
|
| 524 | - $this->set('EVT_display_desc', $display_desc); |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * @param $display_ticket_selector |
|
| 530 | - * @throws EE_Error |
|
| 531 | - */ |
|
| 532 | - public function set_display_ticket_selector($display_ticket_selector) |
|
| 533 | - { |
|
| 534 | - $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * @param $external_url |
|
| 540 | - * @throws EE_Error |
|
| 541 | - */ |
|
| 542 | - public function set_external_url($external_url) |
|
| 543 | - { |
|
| 544 | - $this->set('EVT_external_URL', $external_url); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * @param $member_only |
|
| 550 | - * @throws EE_Error |
|
| 551 | - */ |
|
| 552 | - public function set_member_only($member_only) |
|
| 553 | - { |
|
| 554 | - $this->set('EVT_member_only', $member_only); |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - |
|
| 558 | - /** |
|
| 559 | - * @param $event_phone |
|
| 560 | - * @throws EE_Error |
|
| 561 | - */ |
|
| 562 | - public function set_event_phone($event_phone) |
|
| 563 | - { |
|
| 564 | - $this->set('EVT_phone', $event_phone); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - /** |
|
| 569 | - * @param $modified |
|
| 570 | - * @throws EE_Error |
|
| 571 | - */ |
|
| 572 | - public function set_modified($modified) |
|
| 573 | - { |
|
| 574 | - $this->set('EVT_modified', $modified); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * @param $name |
|
| 580 | - * @throws EE_Error |
|
| 581 | - */ |
|
| 582 | - public function set_name($name) |
|
| 583 | - { |
|
| 584 | - $this->set('EVT_name', $name); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - |
|
| 588 | - /** |
|
| 589 | - * @param $order |
|
| 590 | - * @throws EE_Error |
|
| 591 | - */ |
|
| 592 | - public function set_order($order) |
|
| 593 | - { |
|
| 594 | - $this->set('EVT_order', $order); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - |
|
| 598 | - /** |
|
| 599 | - * @param $short_desc |
|
| 600 | - * @throws EE_Error |
|
| 601 | - */ |
|
| 602 | - public function set_short_description($short_desc) |
|
| 603 | - { |
|
| 604 | - $this->set('EVT_short_desc', $short_desc); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * @param $slug |
|
| 610 | - * @throws EE_Error |
|
| 611 | - */ |
|
| 612 | - public function set_slug($slug) |
|
| 613 | - { |
|
| 614 | - $this->set('EVT_slug', $slug); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * @param $timezone_string |
|
| 620 | - * @throws EE_Error |
|
| 621 | - */ |
|
| 622 | - public function set_timezone_string($timezone_string) |
|
| 623 | - { |
|
| 624 | - $this->set('EVT_timezone_string', $timezone_string); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - |
|
| 628 | - /** |
|
| 629 | - * @param $visible_on |
|
| 630 | - * @throws EE_Error |
|
| 631 | - */ |
|
| 632 | - public function set_visible_on($visible_on) |
|
| 633 | - { |
|
| 634 | - $this->set('EVT_visible_on', $visible_on); |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - |
|
| 638 | - /** |
|
| 639 | - * @param $wp_user |
|
| 640 | - * @throws EE_Error |
|
| 641 | - */ |
|
| 642 | - public function set_wp_user($wp_user) |
|
| 643 | - { |
|
| 644 | - $this->set('EVT_wp_user', $wp_user); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * @param $default_registration_status |
|
| 650 | - * @throws EE_Error |
|
| 651 | - */ |
|
| 652 | - public function set_default_registration_status($default_registration_status) |
|
| 653 | - { |
|
| 654 | - $this->set('EVT_default_registration_status', $default_registration_status); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - |
|
| 658 | - /** |
|
| 659 | - * @param $donations |
|
| 660 | - * @throws EE_Error |
|
| 661 | - */ |
|
| 662 | - public function set_donations($donations) |
|
| 663 | - { |
|
| 664 | - $this->set('EVT_donations', $donations); |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - |
|
| 668 | - /** |
|
| 669 | - * Adds a venue to this event |
|
| 670 | - * |
|
| 671 | - * @param EE_Venue /int $venue_id_or_obj |
|
| 672 | - * @return EE_Base_Class|EE_Venue |
|
| 673 | - * @throws EE_Error |
|
| 674 | - */ |
|
| 675 | - public function add_venue($venue_id_or_obj) |
|
| 676 | - { |
|
| 677 | - return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * Removes a venue from the event |
|
| 683 | - * |
|
| 684 | - * @param EE_Venue /int $venue_id_or_obj |
|
| 685 | - * @return EE_Base_Class|EE_Venue |
|
| 686 | - * @throws EE_Error |
|
| 687 | - */ |
|
| 688 | - public function remove_venue($venue_id_or_obj) |
|
| 689 | - { |
|
| 690 | - return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
| 696 | - * |
|
| 697 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 698 | - * @return EE_Base_Class[]|EE_Venue[] |
|
| 699 | - * @throws EE_Error |
|
| 700 | - */ |
|
| 701 | - public function venues($query_params = array()) |
|
| 702 | - { |
|
| 703 | - return $this->get_many_related('Venue', $query_params); |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * check if event id is present and if event is published |
|
| 709 | - * |
|
| 710 | - * @access public |
|
| 711 | - * @return boolean true yes, false no |
|
| 712 | - * @throws EE_Error |
|
| 713 | - */ |
|
| 714 | - private function _has_ID_and_is_published() |
|
| 715 | - { |
|
| 716 | - // first check if event id is present and not NULL, |
|
| 717 | - // then check if this event is published (or any of the equivalent "published" statuses) |
|
| 718 | - return |
|
| 719 | - $this->ID() && $this->ID() !== null |
|
| 720 | - && ( |
|
| 721 | - $this->status() === 'publish' |
|
| 722 | - || $this->status() === EEM_Event::sold_out |
|
| 723 | - || $this->status() === EEM_Event::postponed |
|
| 724 | - || $this->status() === EEM_Event::cancelled |
|
| 725 | - ); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
| 731 | - * |
|
| 732 | - * @access public |
|
| 733 | - * @return boolean true yes, false no |
|
| 734 | - * @throws EE_Error |
|
| 735 | - */ |
|
| 736 | - public function is_upcoming() |
|
| 737 | - { |
|
| 738 | - // check if event id is present and if this event is published |
|
| 739 | - if ($this->is_inactive()) { |
|
| 740 | - return false; |
|
| 741 | - } |
|
| 742 | - // set initial value |
|
| 743 | - $upcoming = false; |
|
| 744 | - // next let's get all datetimes and loop through them |
|
| 745 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 746 | - foreach ($datetimes as $datetime) { |
|
| 747 | - if ($datetime instanceof EE_Datetime) { |
|
| 748 | - // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
| 749 | - if ($datetime->is_expired()) { |
|
| 750 | - continue; |
|
| 751 | - } |
|
| 752 | - // if this dtt is active then we return false. |
|
| 753 | - if ($datetime->is_active()) { |
|
| 754 | - return false; |
|
| 755 | - } |
|
| 756 | - // otherwise let's check upcoming status |
|
| 757 | - $upcoming = $datetime->is_upcoming(); |
|
| 758 | - } |
|
| 759 | - } |
|
| 760 | - return $upcoming; |
|
| 761 | - } |
|
| 762 | - |
|
| 763 | - |
|
| 764 | - /** |
|
| 765 | - * @return bool |
|
| 766 | - * @throws EE_Error |
|
| 767 | - */ |
|
| 768 | - public function is_active() |
|
| 769 | - { |
|
| 770 | - // check if event id is present and if this event is published |
|
| 771 | - if ($this->is_inactive()) { |
|
| 772 | - return false; |
|
| 773 | - } |
|
| 774 | - // set initial value |
|
| 775 | - $active = false; |
|
| 776 | - // next let's get all datetimes and loop through them |
|
| 777 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 778 | - foreach ($datetimes as $datetime) { |
|
| 779 | - if ($datetime instanceof EE_Datetime) { |
|
| 780 | - // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
| 781 | - if ($datetime->is_expired()) { |
|
| 782 | - continue; |
|
| 783 | - } |
|
| 784 | - // if this dtt is upcoming then we return false. |
|
| 785 | - if ($datetime->is_upcoming()) { |
|
| 786 | - return false; |
|
| 787 | - } |
|
| 788 | - // otherwise let's check active status |
|
| 789 | - $active = $datetime->is_active(); |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - return $active; |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * @return bool |
|
| 798 | - * @throws EE_Error |
|
| 799 | - */ |
|
| 800 | - public function is_expired() |
|
| 801 | - { |
|
| 802 | - // check if event id is present and if this event is published |
|
| 803 | - if ($this->is_inactive()) { |
|
| 804 | - return false; |
|
| 805 | - } |
|
| 806 | - // set initial value |
|
| 807 | - $expired = false; |
|
| 808 | - // first let's get all datetimes and loop through them |
|
| 809 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
| 810 | - foreach ($datetimes as $datetime) { |
|
| 811 | - if ($datetime instanceof EE_Datetime) { |
|
| 812 | - // if this dtt is upcoming or active then we return false. |
|
| 813 | - if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
| 814 | - return false; |
|
| 815 | - } |
|
| 816 | - // otherwise let's check active status |
|
| 817 | - $expired = $datetime->is_expired(); |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - return $expired; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - |
|
| 824 | - /** |
|
| 825 | - * @return bool |
|
| 826 | - * @throws EE_Error |
|
| 827 | - */ |
|
| 828 | - public function is_inactive() |
|
| 829 | - { |
|
| 830 | - // check if event id is present and if this event is published |
|
| 831 | - if ($this->_has_ID_and_is_published()) { |
|
| 832 | - return false; |
|
| 833 | - } |
|
| 834 | - return true; |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * calculate spaces remaining based on "saleable" tickets |
|
| 840 | - * |
|
| 841 | - * @param array $tickets |
|
| 842 | - * @param bool $filtered |
|
| 843 | - * @return int|float |
|
| 844 | - * @throws EE_Error |
|
| 845 | - * @throws DomainException |
|
| 846 | - * @throws UnexpectedEntityException |
|
| 847 | - */ |
|
| 848 | - public function spaces_remaining($tickets = array(), $filtered = true) |
|
| 849 | - { |
|
| 850 | - $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
| 851 | - $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
| 852 | - return $filtered |
|
| 853 | - ? apply_filters( |
|
| 854 | - 'FHEE_EE_Event__spaces_remaining', |
|
| 855 | - $spaces_remaining, |
|
| 856 | - $this, |
|
| 857 | - $tickets |
|
| 858 | - ) |
|
| 859 | - : $spaces_remaining; |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * perform_sold_out_status_check |
|
| 865 | - * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
| 866 | - * available... if NOT, then the event status will get toggled to 'sold_out' |
|
| 867 | - * |
|
| 868 | - * @return bool return the ACTUAL sold out state. |
|
| 869 | - * @throws EE_Error |
|
| 870 | - * @throws DomainException |
|
| 871 | - * @throws UnexpectedEntityException |
|
| 872 | - */ |
|
| 873 | - public function perform_sold_out_status_check() |
|
| 874 | - { |
|
| 875 | - // get all tickets |
|
| 876 | - $tickets = $this->tickets( |
|
| 877 | - array( |
|
| 878 | - 'default_where_conditions' => 'none', |
|
| 879 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 880 | - ) |
|
| 881 | - ); |
|
| 882 | - $all_expired = true; |
|
| 883 | - foreach ($tickets as $ticket) { |
|
| 884 | - if (! $ticket->is_expired()) { |
|
| 885 | - $all_expired = false; |
|
| 886 | - break; |
|
| 887 | - } |
|
| 888 | - } |
|
| 889 | - // if all the tickets are just expired, then don't update the event status to sold out |
|
| 890 | - if ($all_expired) { |
|
| 891 | - return true; |
|
| 892 | - } |
|
| 893 | - $spaces_remaining = $this->spaces_remaining($tickets); |
|
| 894 | - if ($spaces_remaining < 1) { |
|
| 895 | - if ($this->status() !== EEM_Event::post_status_private) { |
|
| 896 | - $this->set_status(EEM_Event::sold_out); |
|
| 897 | - $this->save(); |
|
| 898 | - } |
|
| 899 | - $sold_out = true; |
|
| 900 | - } else { |
|
| 901 | - $sold_out = false; |
|
| 902 | - // was event previously marked as sold out ? |
|
| 903 | - if ($this->status() === EEM_Event::sold_out) { |
|
| 904 | - // revert status to previous value, if it was set |
|
| 905 | - $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
| 906 | - if ($previous_event_status) { |
|
| 907 | - $this->set_status($previous_event_status); |
|
| 908 | - $this->save(); |
|
| 909 | - } |
|
| 910 | - } |
|
| 911 | - } |
|
| 912 | - do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
| 913 | - return $sold_out; |
|
| 914 | - } |
|
| 915 | - |
|
| 916 | - |
|
| 917 | - /** |
|
| 918 | - * This returns the total remaining spaces for sale on this event. |
|
| 919 | - * |
|
| 920 | - * @uses EE_Event::total_available_spaces() |
|
| 921 | - * @return float|int |
|
| 922 | - * @throws EE_Error |
|
| 923 | - * @throws DomainException |
|
| 924 | - * @throws UnexpectedEntityException |
|
| 925 | - */ |
|
| 926 | - public function spaces_remaining_for_sale() |
|
| 927 | - { |
|
| 928 | - return $this->total_available_spaces(true); |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - |
|
| 932 | - /** |
|
| 933 | - * This returns the total spaces available for an event |
|
| 934 | - * while considering all the qtys on the tickets and the reg limits |
|
| 935 | - * on the datetimes attached to this event. |
|
| 936 | - * |
|
| 937 | - * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
| 938 | - * If this is false, then we return the most tickets that could ever be sold |
|
| 939 | - * for this event with the datetime and tickets setup on the event under optimal |
|
| 940 | - * selling conditions. Otherwise we return a live calculation of spaces available |
|
| 941 | - * based on tickets sold. Depending on setup and stage of sales, this |
|
| 942 | - * may appear to equal remaining tickets. However, the more tickets are |
|
| 943 | - * sold out, the more accurate the "live" total is. |
|
| 944 | - * @return float|int |
|
| 945 | - * @throws EE_Error |
|
| 946 | - * @throws DomainException |
|
| 947 | - * @throws UnexpectedEntityException |
|
| 948 | - */ |
|
| 949 | - public function total_available_spaces($consider_sold = false) |
|
| 950 | - { |
|
| 951 | - $spaces_available = $consider_sold |
|
| 952 | - ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
| 953 | - : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
| 954 | - return apply_filters( |
|
| 955 | - 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
| 956 | - $spaces_available, |
|
| 957 | - $this, |
|
| 958 | - $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
| 959 | - $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
| 960 | - ); |
|
| 961 | - } |
|
| 962 | - |
|
| 963 | - |
|
| 964 | - /** |
|
| 965 | - * Checks if the event is set to sold out |
|
| 966 | - * |
|
| 967 | - * @param bool $actual whether or not to perform calculations to not only figure the |
|
| 968 | - * actual status but also to flip the status if necessary to sold |
|
| 969 | - * out If false, we just check the existing status of the event |
|
| 970 | - * @return boolean |
|
| 971 | - * @throws EE_Error |
|
| 972 | - */ |
|
| 973 | - public function is_sold_out($actual = false) |
|
| 974 | - { |
|
| 975 | - if (! $actual) { |
|
| 976 | - return $this->status() === EEM_Event::sold_out; |
|
| 977 | - } |
|
| 978 | - return $this->perform_sold_out_status_check(); |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * Checks if the event is marked as postponed |
|
| 984 | - * |
|
| 985 | - * @return boolean |
|
| 986 | - */ |
|
| 987 | - public function is_postponed() |
|
| 988 | - { |
|
| 989 | - return $this->status() === EEM_Event::postponed; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - |
|
| 993 | - /** |
|
| 994 | - * Checks if the event is marked as cancelled |
|
| 995 | - * |
|
| 996 | - * @return boolean |
|
| 997 | - */ |
|
| 998 | - public function is_cancelled() |
|
| 999 | - { |
|
| 1000 | - return $this->status() === EEM_Event::cancelled; |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
| 1006 | - * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
| 1007 | - * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
| 1008 | - * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
| 1009 | - * the event is considered expired. |
|
| 1010 | - * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
| 1011 | - * status set on the EVENT when it is not published and thus is done |
|
| 1012 | - * |
|
| 1013 | - * @param bool $reset |
|
| 1014 | - * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
| 1015 | - * @throws EE_Error |
|
| 1016 | - */ |
|
| 1017 | - public function get_active_status($reset = false) |
|
| 1018 | - { |
|
| 1019 | - // if the active status has already been set, then just use that value (unless we are resetting it) |
|
| 1020 | - if (! empty($this->_active_status) && ! $reset) { |
|
| 1021 | - return $this->_active_status; |
|
| 1022 | - } |
|
| 1023 | - // first check if event id is present on this object |
|
| 1024 | - if (! $this->ID()) { |
|
| 1025 | - return false; |
|
| 1026 | - } |
|
| 1027 | - $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
| 1028 | - // if event is published: |
|
| 1029 | - if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
| 1030 | - // active? |
|
| 1031 | - if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1032 | - EE_Datetime::active, |
|
| 1033 | - $where_params_for_event |
|
| 1034 | - ) > 0) { |
|
| 1035 | - $this->_active_status = EE_Datetime::active; |
|
| 1036 | - } else { |
|
| 1037 | - // upcoming? |
|
| 1038 | - if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1039 | - EE_Datetime::upcoming, |
|
| 1040 | - $where_params_for_event |
|
| 1041 | - ) > 0) { |
|
| 1042 | - $this->_active_status = EE_Datetime::upcoming; |
|
| 1043 | - } else { |
|
| 1044 | - // expired? |
|
| 1045 | - if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1046 | - EE_Datetime::expired, |
|
| 1047 | - $where_params_for_event |
|
| 1048 | - ) > 0 |
|
| 1049 | - ) { |
|
| 1050 | - $this->_active_status = EE_Datetime::expired; |
|
| 1051 | - } else { |
|
| 1052 | - // it would be odd if things make it this far because it basically means there are no datetime's |
|
| 1053 | - // attached to the event. So in this case it will just be considered inactive. |
|
| 1054 | - $this->_active_status = EE_Datetime::inactive; |
|
| 1055 | - } |
|
| 1056 | - } |
|
| 1057 | - } |
|
| 1058 | - } else { |
|
| 1059 | - // the event is not published, so let's just set it's active status according to its' post status |
|
| 1060 | - switch ($this->status()) { |
|
| 1061 | - case EEM_Event::sold_out: |
|
| 1062 | - $this->_active_status = EE_Datetime::sold_out; |
|
| 1063 | - break; |
|
| 1064 | - case EEM_Event::cancelled: |
|
| 1065 | - $this->_active_status = EE_Datetime::cancelled; |
|
| 1066 | - break; |
|
| 1067 | - case EEM_Event::postponed: |
|
| 1068 | - $this->_active_status = EE_Datetime::postponed; |
|
| 1069 | - break; |
|
| 1070 | - default: |
|
| 1071 | - $this->_active_status = EE_Datetime::inactive; |
|
| 1072 | - } |
|
| 1073 | - } |
|
| 1074 | - return $this->_active_status; |
|
| 1075 | - } |
|
| 1076 | - |
|
| 1077 | - |
|
| 1078 | - /** |
|
| 1079 | - * pretty_active_status |
|
| 1080 | - * |
|
| 1081 | - * @access public |
|
| 1082 | - * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
| 1083 | - * @return mixed void|string |
|
| 1084 | - * @throws EE_Error |
|
| 1085 | - */ |
|
| 1086 | - public function pretty_active_status($echo = true) |
|
| 1087 | - { |
|
| 1088 | - $active_status = $this->get_active_status(); |
|
| 1089 | - $status = '<span class="ee-status event-active-status-' |
|
| 1090 | - . $active_status |
|
| 1091 | - . '">' |
|
| 1092 | - . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
| 1093 | - . '</span>'; |
|
| 1094 | - if ($echo) { |
|
| 1095 | - echo $status; |
|
| 1096 | - return ''; |
|
| 1097 | - } |
|
| 1098 | - return $status; |
|
| 1099 | - } |
|
| 1100 | - |
|
| 1101 | - |
|
| 1102 | - /** |
|
| 1103 | - * @return bool|int |
|
| 1104 | - * @throws EE_Error |
|
| 1105 | - */ |
|
| 1106 | - public function get_number_of_tickets_sold() |
|
| 1107 | - { |
|
| 1108 | - $tkt_sold = 0; |
|
| 1109 | - if (! $this->ID()) { |
|
| 1110 | - return 0; |
|
| 1111 | - } |
|
| 1112 | - $datetimes = $this->datetimes(); |
|
| 1113 | - foreach ($datetimes as $datetime) { |
|
| 1114 | - if ($datetime instanceof EE_Datetime) { |
|
| 1115 | - $tkt_sold += $datetime->sold(); |
|
| 1116 | - } |
|
| 1117 | - } |
|
| 1118 | - return $tkt_sold; |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - |
|
| 1122 | - /** |
|
| 1123 | - * This just returns a count of all the registrations for this event |
|
| 1124 | - * |
|
| 1125 | - * @access public |
|
| 1126 | - * @return int |
|
| 1127 | - * @throws EE_Error |
|
| 1128 | - */ |
|
| 1129 | - public function get_count_of_all_registrations() |
|
| 1130 | - { |
|
| 1131 | - return EEM_Event::instance()->count_related($this, 'Registration'); |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - |
|
| 1135 | - /** |
|
| 1136 | - * This returns the ticket with the earliest start time that is |
|
| 1137 | - * available for this event (across all datetimes attached to the event) |
|
| 1138 | - * |
|
| 1139 | - * @return EE_Base_Class|EE_Ticket|null |
|
| 1140 | - * @throws EE_Error |
|
| 1141 | - */ |
|
| 1142 | - public function get_ticket_with_earliest_start_time() |
|
| 1143 | - { |
|
| 1144 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1145 | - $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
| 1146 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * This returns the ticket with the latest end time that is available |
|
| 1152 | - * for this event (across all datetimes attached to the event) |
|
| 1153 | - * |
|
| 1154 | - * @return EE_Base_Class|EE_Ticket|null |
|
| 1155 | - * @throws EE_Error |
|
| 1156 | - */ |
|
| 1157 | - public function get_ticket_with_latest_end_time() |
|
| 1158 | - { |
|
| 1159 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1160 | - $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
| 1161 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - |
|
| 1165 | - /** |
|
| 1166 | - * This returns the number of different ticket types currently on sale for this event. |
|
| 1167 | - * |
|
| 1168 | - * @return int |
|
| 1169 | - * @throws EE_Error |
|
| 1170 | - */ |
|
| 1171 | - public function countTicketsOnSale() |
|
| 1172 | - { |
|
| 1173 | - $where = array( |
|
| 1174 | - 'Datetime.EVT_ID' => $this->ID(), |
|
| 1175 | - 'TKT_start_date' => array('<', time()), |
|
| 1176 | - 'TKT_end_date' => array('>', time()), |
|
| 1177 | - ); |
|
| 1178 | - return EEM_Ticket::instance()->count(array($where)); |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - |
|
| 1182 | - /** |
|
| 1183 | - * This returns whether there are any tickets on sale for this event. |
|
| 1184 | - * |
|
| 1185 | - * @return bool true = YES tickets on sale. |
|
| 1186 | - * @throws EE_Error |
|
| 1187 | - */ |
|
| 1188 | - public function tickets_on_sale() |
|
| 1189 | - { |
|
| 1190 | - return $this->countTicketsOnSale() > 0; |
|
| 1191 | - } |
|
| 1192 | - |
|
| 1193 | - |
|
| 1194 | - /** |
|
| 1195 | - * Gets the URL for viewing this event on the front-end. Overrides parent |
|
| 1196 | - * to check for an external URL first |
|
| 1197 | - * |
|
| 1198 | - * @return string |
|
| 1199 | - * @throws EE_Error |
|
| 1200 | - */ |
|
| 1201 | - public function get_permalink() |
|
| 1202 | - { |
|
| 1203 | - if ($this->external_url()) { |
|
| 1204 | - return $this->external_url(); |
|
| 1205 | - } |
|
| 1206 | - return parent::get_permalink(); |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - |
|
| 1210 | - /** |
|
| 1211 | - * Gets the first term for 'espresso_event_categories' we can find |
|
| 1212 | - * |
|
| 1213 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1214 | - * @return EE_Base_Class|EE_Term|null |
|
| 1215 | - * @throws EE_Error |
|
| 1216 | - */ |
|
| 1217 | - public function first_event_category($query_params = array()) |
|
| 1218 | - { |
|
| 1219 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1220 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1221 | - return EEM_Term::instance()->get_one($query_params); |
|
| 1222 | - } |
|
| 1223 | - |
|
| 1224 | - |
|
| 1225 | - /** |
|
| 1226 | - * Gets all terms for 'espresso_event_categories' we can find |
|
| 1227 | - * |
|
| 1228 | - * @param array $query_params |
|
| 1229 | - * @return EE_Base_Class[]|EE_Term[] |
|
| 1230 | - * @throws EE_Error |
|
| 1231 | - */ |
|
| 1232 | - public function get_all_event_categories($query_params = array()) |
|
| 1233 | - { |
|
| 1234 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1235 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1236 | - return EEM_Term::instance()->get_all($query_params); |
|
| 1237 | - } |
|
| 1238 | - |
|
| 1239 | - |
|
| 1240 | - /** |
|
| 1241 | - * Adds a question group to this event |
|
| 1242 | - * |
|
| 1243 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1244 | - * @param bool $for_primary if true, the question group will be added for the primary |
|
| 1245 | - * registrant, if false will be added for others. default: false |
|
| 1246 | - * @return EE_Base_Class|EE_Question_Group |
|
| 1247 | - * @throws EE_Error |
|
| 1248 | - */ |
|
| 1249 | - public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1250 | - { |
|
| 1251 | - $extra = $for_primary |
|
| 1252 | - ? array('EQG_primary' => 1) |
|
| 1253 | - : array(); |
|
| 1254 | - return $this->_add_relation_to($question_group_id_or_obj, 'Question_Group', $extra); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - |
|
| 1258 | - /** |
|
| 1259 | - * Removes a question group from the event |
|
| 1260 | - * |
|
| 1261 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1262 | - * @param bool $for_primary if true, the question group will be removed from the primary |
|
| 1263 | - * registrant, if false will be removed from others. default: false |
|
| 1264 | - * @return EE_Base_Class|EE_Question_Group |
|
| 1265 | - * @throws EE_Error |
|
| 1266 | - */ |
|
| 1267 | - public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1268 | - { |
|
| 1269 | - $where = $for_primary |
|
| 1270 | - ? array('EQG_primary' => 1) |
|
| 1271 | - : array(); |
|
| 1272 | - return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group', $where); |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - |
|
| 1276 | - /** |
|
| 1277 | - * Gets all the question groups, ordering them by QSG_order ascending |
|
| 1278 | - * |
|
| 1279 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1280 | - * @return EE_Base_Class[]|EE_Question_Group[] |
|
| 1281 | - * @throws EE_Error |
|
| 1282 | - */ |
|
| 1283 | - public function question_groups($query_params = array()) |
|
| 1284 | - { |
|
| 1285 | - $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1286 | - return $this->get_many_related('Question_Group', $query_params); |
|
| 1287 | - } |
|
| 1288 | - |
|
| 1289 | - |
|
| 1290 | - /** |
|
| 1291 | - * Implementation for EEI_Has_Icon interface method. |
|
| 1292 | - * |
|
| 1293 | - * @see EEI_Visual_Representation for comments |
|
| 1294 | - * @return string |
|
| 1295 | - */ |
|
| 1296 | - public function get_icon() |
|
| 1297 | - { |
|
| 1298 | - return '<span class="dashicons dashicons-flag"></span>'; |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - |
|
| 1302 | - /** |
|
| 1303 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1304 | - * |
|
| 1305 | - * @see EEI_Admin_Links for comments |
|
| 1306 | - * @return string |
|
| 1307 | - * @throws EE_Error |
|
| 1308 | - */ |
|
| 1309 | - public function get_admin_details_link() |
|
| 1310 | - { |
|
| 1311 | - return $this->get_admin_edit_link(); |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - |
|
| 1315 | - /** |
|
| 1316 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1317 | - * |
|
| 1318 | - * @see EEI_Admin_Links for comments |
|
| 1319 | - * @return string |
|
| 1320 | - * @throws EE_Error |
|
| 1321 | - */ |
|
| 1322 | - public function get_admin_edit_link() |
|
| 1323 | - { |
|
| 1324 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1325 | - array( |
|
| 1326 | - 'page' => 'espresso_events', |
|
| 1327 | - 'action' => 'edit', |
|
| 1328 | - 'post' => $this->ID(), |
|
| 1329 | - ), |
|
| 1330 | - admin_url('admin.php') |
|
| 1331 | - ); |
|
| 1332 | - } |
|
| 1333 | - |
|
| 1334 | - |
|
| 1335 | - /** |
|
| 1336 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1337 | - * |
|
| 1338 | - * @see EEI_Admin_Links for comments |
|
| 1339 | - * @return string |
|
| 1340 | - */ |
|
| 1341 | - public function get_admin_settings_link() |
|
| 1342 | - { |
|
| 1343 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1344 | - array( |
|
| 1345 | - 'page' => 'espresso_events', |
|
| 1346 | - 'action' => 'default_event_settings', |
|
| 1347 | - ), |
|
| 1348 | - admin_url('admin.php') |
|
| 1349 | - ); |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - |
|
| 1353 | - /** |
|
| 1354 | - * Implementation for EEI_Admin_Links interface method. |
|
| 1355 | - * |
|
| 1356 | - * @see EEI_Admin_Links for comments |
|
| 1357 | - * @return string |
|
| 1358 | - */ |
|
| 1359 | - public function get_admin_overview_link() |
|
| 1360 | - { |
|
| 1361 | - return EEH_URL::add_query_args_and_nonce( |
|
| 1362 | - array( |
|
| 1363 | - 'page' => 'espresso_events', |
|
| 1364 | - 'action' => 'default', |
|
| 1365 | - ), |
|
| 1366 | - admin_url('admin.php') |
|
| 1367 | - ); |
|
| 1368 | - } |
|
| 16 | + /** |
|
| 17 | + * cached value for the the logical active status for the event |
|
| 18 | + * |
|
| 19 | + * @see get_active_status() |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $_active_status = ''; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
| 26 | + * |
|
| 27 | + * @var EE_Datetime |
|
| 28 | + */ |
|
| 29 | + protected $_Primary_Datetime; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var EventSpacesCalculator $available_spaces_calculator |
|
| 33 | + */ |
|
| 34 | + protected $available_spaces_calculator; |
|
| 35 | + |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @param array $props_n_values incoming values |
|
| 39 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 40 | + * used.) |
|
| 41 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 42 | + * date_format and the second value is the time format |
|
| 43 | + * @return EE_Event |
|
| 44 | + * @throws EE_Error |
|
| 45 | + */ |
|
| 46 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 47 | + { |
|
| 48 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 49 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param array $props_n_values incoming values from the database |
|
| 55 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 56 | + * the website will be used. |
|
| 57 | + * @return EE_Event |
|
| 58 | + * @throws EE_Error |
|
| 59 | + */ |
|
| 60 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 61 | + { |
|
| 62 | + return new self($props_n_values, true, $timezone); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @return EventSpacesCalculator |
|
| 68 | + * @throws \EE_Error |
|
| 69 | + */ |
|
| 70 | + public function getAvailableSpacesCalculator() |
|
| 71 | + { |
|
| 72 | + if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
| 73 | + $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
| 74 | + } |
|
| 75 | + return $this->available_spaces_calculator; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
| 81 | + * |
|
| 82 | + * @param string $field_name |
|
| 83 | + * @param mixed $field_value |
|
| 84 | + * @param bool $use_default |
|
| 85 | + * @throws EE_Error |
|
| 86 | + */ |
|
| 87 | + public function set($field_name, $field_value, $use_default = false) |
|
| 88 | + { |
|
| 89 | + switch ($field_name) { |
|
| 90 | + case 'status': |
|
| 91 | + $this->set_status($field_value, $use_default); |
|
| 92 | + break; |
|
| 93 | + default: |
|
| 94 | + parent::set($field_name, $field_value, $use_default); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * set_status |
|
| 101 | + * Checks if event status is being changed to SOLD OUT |
|
| 102 | + * and updates event meta data with previous event status |
|
| 103 | + * so that we can revert things if/when the event is no longer sold out |
|
| 104 | + * |
|
| 105 | + * @access public |
|
| 106 | + * @param string $new_status |
|
| 107 | + * @param bool $use_default |
|
| 108 | + * @return void |
|
| 109 | + * @throws EE_Error |
|
| 110 | + */ |
|
| 111 | + public function set_status($new_status = null, $use_default = false) |
|
| 112 | + { |
|
| 113 | + // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
| 114 | + if (empty($new_status) && ! $use_default) { |
|
| 115 | + return; |
|
| 116 | + } |
|
| 117 | + // get current Event status |
|
| 118 | + $old_status = $this->status(); |
|
| 119 | + // if status has changed |
|
| 120 | + if ($old_status !== $new_status) { |
|
| 121 | + // TO sold_out |
|
| 122 | + if ($new_status === EEM_Event::sold_out) { |
|
| 123 | + // save the previous event status so that we can revert if the event is no longer sold out |
|
| 124 | + $this->add_post_meta('_previous_event_status', $old_status); |
|
| 125 | + do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
| 126 | + // OR FROM sold_out |
|
| 127 | + } elseif ($old_status === EEM_Event::sold_out) { |
|
| 128 | + $this->delete_post_meta('_previous_event_status'); |
|
| 129 | + do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
| 130 | + } |
|
| 131 | + // clear out the active status so that it gets reset the next time it is requested |
|
| 132 | + $this->_active_status = null; |
|
| 133 | + // update status |
|
| 134 | + parent::set('status', $new_status, $use_default); |
|
| 135 | + do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
| 136 | + return; |
|
| 137 | + } |
|
| 138 | + // even though the old value matches the new value, it's still good to |
|
| 139 | + // allow the parent set method to have a say |
|
| 140 | + parent::set('status', $new_status, $use_default); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Gets all the datetimes for this event |
|
| 146 | + * |
|
| 147 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 148 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
| 149 | + * @throws EE_Error |
|
| 150 | + */ |
|
| 151 | + public function datetimes($query_params = array()) |
|
| 152 | + { |
|
| 153 | + return $this->get_many_related('Datetime', $query_params); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
| 159 | + * |
|
| 160 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
| 161 | + * @throws EE_Error |
|
| 162 | + */ |
|
| 163 | + public function datetimes_in_chronological_order() |
|
| 164 | + { |
|
| 165 | + return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
| 171 | + * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
| 172 | + * after running our query, so that this timezone isn't set for EVERY query |
|
| 173 | + * on EEM_Datetime for the rest of the request, no? |
|
| 174 | + * |
|
| 175 | + * @param boolean $show_expired whether or not to include expired events |
|
| 176 | + * @param boolean $show_deleted whether or not to include deleted events |
|
| 177 | + * @param null $limit |
|
| 178 | + * @return EE_Datetime[] |
|
| 179 | + * @throws EE_Error |
|
| 180 | + */ |
|
| 181 | + public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
| 182 | + { |
|
| 183 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
| 184 | + $this->ID(), |
|
| 185 | + $show_expired, |
|
| 186 | + $show_deleted, |
|
| 187 | + $limit |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Returns one related datetime. Mostly only used by some legacy code. |
|
| 194 | + * |
|
| 195 | + * @return EE_Base_Class|EE_Datetime |
|
| 196 | + * @throws EE_Error |
|
| 197 | + */ |
|
| 198 | + public function first_datetime() |
|
| 199 | + { |
|
| 200 | + return $this->get_first_related('Datetime'); |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Returns the 'primary' datetime for the event |
|
| 206 | + * |
|
| 207 | + * @param bool $try_to_exclude_expired |
|
| 208 | + * @param bool $try_to_exclude_deleted |
|
| 209 | + * @return EE_Datetime |
|
| 210 | + * @throws EE_Error |
|
| 211 | + */ |
|
| 212 | + public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
| 213 | + { |
|
| 214 | + if (! empty($this->_Primary_Datetime)) { |
|
| 215 | + return $this->_Primary_Datetime; |
|
| 216 | + } |
|
| 217 | + $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
| 218 | + $this->ID(), |
|
| 219 | + $try_to_exclude_expired, |
|
| 220 | + $try_to_exclude_deleted |
|
| 221 | + ); |
|
| 222 | + return $this->_Primary_Datetime; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Gets all the tickets available for purchase of this event |
|
| 228 | + * |
|
| 229 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 230 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
| 231 | + * @throws EE_Error |
|
| 232 | + */ |
|
| 233 | + public function tickets($query_params = array()) |
|
| 234 | + { |
|
| 235 | + // first get all datetimes |
|
| 236 | + $datetimes = $this->datetimes_ordered(); |
|
| 237 | + if (! $datetimes) { |
|
| 238 | + return array(); |
|
| 239 | + } |
|
| 240 | + $datetime_ids = array(); |
|
| 241 | + foreach ($datetimes as $datetime) { |
|
| 242 | + $datetime_ids[] = $datetime->ID(); |
|
| 243 | + } |
|
| 244 | + $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
| 245 | + // if incoming $query_params has where conditions let's merge but not override existing. |
|
| 246 | + if (is_array($query_params) && isset($query_params[0])) { |
|
| 247 | + $where_params = array_merge($query_params[0], $where_params); |
|
| 248 | + unset($query_params[0]); |
|
| 249 | + } |
|
| 250 | + // now add $where_params to $query_params |
|
| 251 | + $query_params[0] = $where_params; |
|
| 252 | + return EEM_Ticket::instance()->get_all($query_params); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * get all unexpired untrashed tickets |
|
| 258 | + * |
|
| 259 | + * @return EE_Ticket[] |
|
| 260 | + * @throws EE_Error |
|
| 261 | + */ |
|
| 262 | + public function active_tickets() |
|
| 263 | + { |
|
| 264 | + return $this->tickets( |
|
| 265 | + array( |
|
| 266 | + array( |
|
| 267 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 268 | + 'TKT_deleted' => false, |
|
| 269 | + ), |
|
| 270 | + ) |
|
| 271 | + ); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @return bool |
|
| 277 | + * @throws EE_Error |
|
| 278 | + */ |
|
| 279 | + public function additional_limit() |
|
| 280 | + { |
|
| 281 | + return $this->get('EVT_additional_limit'); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * @return bool |
|
| 287 | + * @throws EE_Error |
|
| 288 | + */ |
|
| 289 | + public function allow_overflow() |
|
| 290 | + { |
|
| 291 | + return $this->get('EVT_allow_overflow'); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * @return bool |
|
| 297 | + * @throws EE_Error |
|
| 298 | + */ |
|
| 299 | + public function created() |
|
| 300 | + { |
|
| 301 | + return $this->get('EVT_created'); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * @return bool |
|
| 307 | + * @throws EE_Error |
|
| 308 | + */ |
|
| 309 | + public function description() |
|
| 310 | + { |
|
| 311 | + return $this->get('EVT_desc'); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Runs do_shortcode and wpautop on the description |
|
| 317 | + * |
|
| 318 | + * @return string of html |
|
| 319 | + * @throws EE_Error |
|
| 320 | + */ |
|
| 321 | + public function description_filtered() |
|
| 322 | + { |
|
| 323 | + return $this->get_pretty('EVT_desc'); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + /** |
|
| 328 | + * @return bool |
|
| 329 | + * @throws EE_Error |
|
| 330 | + */ |
|
| 331 | + public function display_description() |
|
| 332 | + { |
|
| 333 | + return $this->get('EVT_display_desc'); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + |
|
| 337 | + /** |
|
| 338 | + * @return bool |
|
| 339 | + * @throws EE_Error |
|
| 340 | + */ |
|
| 341 | + public function display_ticket_selector() |
|
| 342 | + { |
|
| 343 | + return (bool) $this->get('EVT_display_ticket_selector'); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * @return bool |
|
| 349 | + * @throws EE_Error |
|
| 350 | + */ |
|
| 351 | + public function external_url() |
|
| 352 | + { |
|
| 353 | + return $this->get('EVT_external_URL'); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * @return bool |
|
| 359 | + * @throws EE_Error |
|
| 360 | + */ |
|
| 361 | + public function member_only() |
|
| 362 | + { |
|
| 363 | + return $this->get('EVT_member_only'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * @return bool |
|
| 369 | + * @throws EE_Error |
|
| 370 | + */ |
|
| 371 | + public function phone() |
|
| 372 | + { |
|
| 373 | + return $this->get('EVT_phone'); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * @return bool |
|
| 379 | + * @throws EE_Error |
|
| 380 | + */ |
|
| 381 | + public function modified() |
|
| 382 | + { |
|
| 383 | + return $this->get('EVT_modified'); |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * @return bool |
|
| 389 | + * @throws EE_Error |
|
| 390 | + */ |
|
| 391 | + public function name() |
|
| 392 | + { |
|
| 393 | + return $this->get('EVT_name'); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * @return bool |
|
| 399 | + * @throws EE_Error |
|
| 400 | + */ |
|
| 401 | + public function order() |
|
| 402 | + { |
|
| 403 | + return $this->get('EVT_order'); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * @return bool|string |
|
| 409 | + * @throws EE_Error |
|
| 410 | + */ |
|
| 411 | + public function default_registration_status() |
|
| 412 | + { |
|
| 413 | + $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
| 414 | + return ! empty($event_default_registration_status) |
|
| 415 | + ? $event_default_registration_status |
|
| 416 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * @param int $num_words |
|
| 422 | + * @param null $more |
|
| 423 | + * @param bool $not_full_desc |
|
| 424 | + * @return bool|string |
|
| 425 | + * @throws EE_Error |
|
| 426 | + */ |
|
| 427 | + public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
| 428 | + { |
|
| 429 | + $short_desc = $this->get('EVT_short_desc'); |
|
| 430 | + if (! empty($short_desc) || $not_full_desc) { |
|
| 431 | + return $short_desc; |
|
| 432 | + } |
|
| 433 | + $full_desc = $this->get('EVT_desc'); |
|
| 434 | + return wp_trim_words($full_desc, $num_words, $more); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * @return bool |
|
| 440 | + * @throws EE_Error |
|
| 441 | + */ |
|
| 442 | + public function slug() |
|
| 443 | + { |
|
| 444 | + return $this->get('EVT_slug'); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * @return bool |
|
| 450 | + * @throws EE_Error |
|
| 451 | + */ |
|
| 452 | + public function timezone_string() |
|
| 453 | + { |
|
| 454 | + return $this->get('EVT_timezone_string'); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * @return bool |
|
| 460 | + * @throws EE_Error |
|
| 461 | + */ |
|
| 462 | + public function visible_on() |
|
| 463 | + { |
|
| 464 | + return $this->get('EVT_visible_on'); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * @return int |
|
| 470 | + * @throws EE_Error |
|
| 471 | + */ |
|
| 472 | + public function wp_user() |
|
| 473 | + { |
|
| 474 | + return $this->get('EVT_wp_user'); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * @return bool |
|
| 480 | + * @throws EE_Error |
|
| 481 | + */ |
|
| 482 | + public function donations() |
|
| 483 | + { |
|
| 484 | + return $this->get('EVT_donations'); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * @param $limit |
|
| 490 | + * @throws EE_Error |
|
| 491 | + */ |
|
| 492 | + public function set_additional_limit($limit) |
|
| 493 | + { |
|
| 494 | + $this->set('EVT_additional_limit', $limit); |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * @param $created |
|
| 500 | + * @throws EE_Error |
|
| 501 | + */ |
|
| 502 | + public function set_created($created) |
|
| 503 | + { |
|
| 504 | + $this->set('EVT_created', $created); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * @param $desc |
|
| 510 | + * @throws EE_Error |
|
| 511 | + */ |
|
| 512 | + public function set_description($desc) |
|
| 513 | + { |
|
| 514 | + $this->set('EVT_desc', $desc); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * @param $display_desc |
|
| 520 | + * @throws EE_Error |
|
| 521 | + */ |
|
| 522 | + public function set_display_description($display_desc) |
|
| 523 | + { |
|
| 524 | + $this->set('EVT_display_desc', $display_desc); |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * @param $display_ticket_selector |
|
| 530 | + * @throws EE_Error |
|
| 531 | + */ |
|
| 532 | + public function set_display_ticket_selector($display_ticket_selector) |
|
| 533 | + { |
|
| 534 | + $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * @param $external_url |
|
| 540 | + * @throws EE_Error |
|
| 541 | + */ |
|
| 542 | + public function set_external_url($external_url) |
|
| 543 | + { |
|
| 544 | + $this->set('EVT_external_URL', $external_url); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * @param $member_only |
|
| 550 | + * @throws EE_Error |
|
| 551 | + */ |
|
| 552 | + public function set_member_only($member_only) |
|
| 553 | + { |
|
| 554 | + $this->set('EVT_member_only', $member_only); |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + |
|
| 558 | + /** |
|
| 559 | + * @param $event_phone |
|
| 560 | + * @throws EE_Error |
|
| 561 | + */ |
|
| 562 | + public function set_event_phone($event_phone) |
|
| 563 | + { |
|
| 564 | + $this->set('EVT_phone', $event_phone); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + /** |
|
| 569 | + * @param $modified |
|
| 570 | + * @throws EE_Error |
|
| 571 | + */ |
|
| 572 | + public function set_modified($modified) |
|
| 573 | + { |
|
| 574 | + $this->set('EVT_modified', $modified); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * @param $name |
|
| 580 | + * @throws EE_Error |
|
| 581 | + */ |
|
| 582 | + public function set_name($name) |
|
| 583 | + { |
|
| 584 | + $this->set('EVT_name', $name); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + |
|
| 588 | + /** |
|
| 589 | + * @param $order |
|
| 590 | + * @throws EE_Error |
|
| 591 | + */ |
|
| 592 | + public function set_order($order) |
|
| 593 | + { |
|
| 594 | + $this->set('EVT_order', $order); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + |
|
| 598 | + /** |
|
| 599 | + * @param $short_desc |
|
| 600 | + * @throws EE_Error |
|
| 601 | + */ |
|
| 602 | + public function set_short_description($short_desc) |
|
| 603 | + { |
|
| 604 | + $this->set('EVT_short_desc', $short_desc); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * @param $slug |
|
| 610 | + * @throws EE_Error |
|
| 611 | + */ |
|
| 612 | + public function set_slug($slug) |
|
| 613 | + { |
|
| 614 | + $this->set('EVT_slug', $slug); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * @param $timezone_string |
|
| 620 | + * @throws EE_Error |
|
| 621 | + */ |
|
| 622 | + public function set_timezone_string($timezone_string) |
|
| 623 | + { |
|
| 624 | + $this->set('EVT_timezone_string', $timezone_string); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + |
|
| 628 | + /** |
|
| 629 | + * @param $visible_on |
|
| 630 | + * @throws EE_Error |
|
| 631 | + */ |
|
| 632 | + public function set_visible_on($visible_on) |
|
| 633 | + { |
|
| 634 | + $this->set('EVT_visible_on', $visible_on); |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + |
|
| 638 | + /** |
|
| 639 | + * @param $wp_user |
|
| 640 | + * @throws EE_Error |
|
| 641 | + */ |
|
| 642 | + public function set_wp_user($wp_user) |
|
| 643 | + { |
|
| 644 | + $this->set('EVT_wp_user', $wp_user); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * @param $default_registration_status |
|
| 650 | + * @throws EE_Error |
|
| 651 | + */ |
|
| 652 | + public function set_default_registration_status($default_registration_status) |
|
| 653 | + { |
|
| 654 | + $this->set('EVT_default_registration_status', $default_registration_status); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + |
|
| 658 | + /** |
|
| 659 | + * @param $donations |
|
| 660 | + * @throws EE_Error |
|
| 661 | + */ |
|
| 662 | + public function set_donations($donations) |
|
| 663 | + { |
|
| 664 | + $this->set('EVT_donations', $donations); |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + |
|
| 668 | + /** |
|
| 669 | + * Adds a venue to this event |
|
| 670 | + * |
|
| 671 | + * @param EE_Venue /int $venue_id_or_obj |
|
| 672 | + * @return EE_Base_Class|EE_Venue |
|
| 673 | + * @throws EE_Error |
|
| 674 | + */ |
|
| 675 | + public function add_venue($venue_id_or_obj) |
|
| 676 | + { |
|
| 677 | + return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * Removes a venue from the event |
|
| 683 | + * |
|
| 684 | + * @param EE_Venue /int $venue_id_or_obj |
|
| 685 | + * @return EE_Base_Class|EE_Venue |
|
| 686 | + * @throws EE_Error |
|
| 687 | + */ |
|
| 688 | + public function remove_venue($venue_id_or_obj) |
|
| 689 | + { |
|
| 690 | + return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
| 696 | + * |
|
| 697 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 698 | + * @return EE_Base_Class[]|EE_Venue[] |
|
| 699 | + * @throws EE_Error |
|
| 700 | + */ |
|
| 701 | + public function venues($query_params = array()) |
|
| 702 | + { |
|
| 703 | + return $this->get_many_related('Venue', $query_params); |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * check if event id is present and if event is published |
|
| 709 | + * |
|
| 710 | + * @access public |
|
| 711 | + * @return boolean true yes, false no |
|
| 712 | + * @throws EE_Error |
|
| 713 | + */ |
|
| 714 | + private function _has_ID_and_is_published() |
|
| 715 | + { |
|
| 716 | + // first check if event id is present and not NULL, |
|
| 717 | + // then check if this event is published (or any of the equivalent "published" statuses) |
|
| 718 | + return |
|
| 719 | + $this->ID() && $this->ID() !== null |
|
| 720 | + && ( |
|
| 721 | + $this->status() === 'publish' |
|
| 722 | + || $this->status() === EEM_Event::sold_out |
|
| 723 | + || $this->status() === EEM_Event::postponed |
|
| 724 | + || $this->status() === EEM_Event::cancelled |
|
| 725 | + ); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
| 731 | + * |
|
| 732 | + * @access public |
|
| 733 | + * @return boolean true yes, false no |
|
| 734 | + * @throws EE_Error |
|
| 735 | + */ |
|
| 736 | + public function is_upcoming() |
|
| 737 | + { |
|
| 738 | + // check if event id is present and if this event is published |
|
| 739 | + if ($this->is_inactive()) { |
|
| 740 | + return false; |
|
| 741 | + } |
|
| 742 | + // set initial value |
|
| 743 | + $upcoming = false; |
|
| 744 | + // next let's get all datetimes and loop through them |
|
| 745 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 746 | + foreach ($datetimes as $datetime) { |
|
| 747 | + if ($datetime instanceof EE_Datetime) { |
|
| 748 | + // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
| 749 | + if ($datetime->is_expired()) { |
|
| 750 | + continue; |
|
| 751 | + } |
|
| 752 | + // if this dtt is active then we return false. |
|
| 753 | + if ($datetime->is_active()) { |
|
| 754 | + return false; |
|
| 755 | + } |
|
| 756 | + // otherwise let's check upcoming status |
|
| 757 | + $upcoming = $datetime->is_upcoming(); |
|
| 758 | + } |
|
| 759 | + } |
|
| 760 | + return $upcoming; |
|
| 761 | + } |
|
| 762 | + |
|
| 763 | + |
|
| 764 | + /** |
|
| 765 | + * @return bool |
|
| 766 | + * @throws EE_Error |
|
| 767 | + */ |
|
| 768 | + public function is_active() |
|
| 769 | + { |
|
| 770 | + // check if event id is present and if this event is published |
|
| 771 | + if ($this->is_inactive()) { |
|
| 772 | + return false; |
|
| 773 | + } |
|
| 774 | + // set initial value |
|
| 775 | + $active = false; |
|
| 776 | + // next let's get all datetimes and loop through them |
|
| 777 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 778 | + foreach ($datetimes as $datetime) { |
|
| 779 | + if ($datetime instanceof EE_Datetime) { |
|
| 780 | + // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
| 781 | + if ($datetime->is_expired()) { |
|
| 782 | + continue; |
|
| 783 | + } |
|
| 784 | + // if this dtt is upcoming then we return false. |
|
| 785 | + if ($datetime->is_upcoming()) { |
|
| 786 | + return false; |
|
| 787 | + } |
|
| 788 | + // otherwise let's check active status |
|
| 789 | + $active = $datetime->is_active(); |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + return $active; |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * @return bool |
|
| 798 | + * @throws EE_Error |
|
| 799 | + */ |
|
| 800 | + public function is_expired() |
|
| 801 | + { |
|
| 802 | + // check if event id is present and if this event is published |
|
| 803 | + if ($this->is_inactive()) { |
|
| 804 | + return false; |
|
| 805 | + } |
|
| 806 | + // set initial value |
|
| 807 | + $expired = false; |
|
| 808 | + // first let's get all datetimes and loop through them |
|
| 809 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
| 810 | + foreach ($datetimes as $datetime) { |
|
| 811 | + if ($datetime instanceof EE_Datetime) { |
|
| 812 | + // if this dtt is upcoming or active then we return false. |
|
| 813 | + if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
| 814 | + return false; |
|
| 815 | + } |
|
| 816 | + // otherwise let's check active status |
|
| 817 | + $expired = $datetime->is_expired(); |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + return $expired; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + |
|
| 824 | + /** |
|
| 825 | + * @return bool |
|
| 826 | + * @throws EE_Error |
|
| 827 | + */ |
|
| 828 | + public function is_inactive() |
|
| 829 | + { |
|
| 830 | + // check if event id is present and if this event is published |
|
| 831 | + if ($this->_has_ID_and_is_published()) { |
|
| 832 | + return false; |
|
| 833 | + } |
|
| 834 | + return true; |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * calculate spaces remaining based on "saleable" tickets |
|
| 840 | + * |
|
| 841 | + * @param array $tickets |
|
| 842 | + * @param bool $filtered |
|
| 843 | + * @return int|float |
|
| 844 | + * @throws EE_Error |
|
| 845 | + * @throws DomainException |
|
| 846 | + * @throws UnexpectedEntityException |
|
| 847 | + */ |
|
| 848 | + public function spaces_remaining($tickets = array(), $filtered = true) |
|
| 849 | + { |
|
| 850 | + $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
| 851 | + $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
| 852 | + return $filtered |
|
| 853 | + ? apply_filters( |
|
| 854 | + 'FHEE_EE_Event__spaces_remaining', |
|
| 855 | + $spaces_remaining, |
|
| 856 | + $this, |
|
| 857 | + $tickets |
|
| 858 | + ) |
|
| 859 | + : $spaces_remaining; |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * perform_sold_out_status_check |
|
| 865 | + * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
| 866 | + * available... if NOT, then the event status will get toggled to 'sold_out' |
|
| 867 | + * |
|
| 868 | + * @return bool return the ACTUAL sold out state. |
|
| 869 | + * @throws EE_Error |
|
| 870 | + * @throws DomainException |
|
| 871 | + * @throws UnexpectedEntityException |
|
| 872 | + */ |
|
| 873 | + public function perform_sold_out_status_check() |
|
| 874 | + { |
|
| 875 | + // get all tickets |
|
| 876 | + $tickets = $this->tickets( |
|
| 877 | + array( |
|
| 878 | + 'default_where_conditions' => 'none', |
|
| 879 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
| 880 | + ) |
|
| 881 | + ); |
|
| 882 | + $all_expired = true; |
|
| 883 | + foreach ($tickets as $ticket) { |
|
| 884 | + if (! $ticket->is_expired()) { |
|
| 885 | + $all_expired = false; |
|
| 886 | + break; |
|
| 887 | + } |
|
| 888 | + } |
|
| 889 | + // if all the tickets are just expired, then don't update the event status to sold out |
|
| 890 | + if ($all_expired) { |
|
| 891 | + return true; |
|
| 892 | + } |
|
| 893 | + $spaces_remaining = $this->spaces_remaining($tickets); |
|
| 894 | + if ($spaces_remaining < 1) { |
|
| 895 | + if ($this->status() !== EEM_Event::post_status_private) { |
|
| 896 | + $this->set_status(EEM_Event::sold_out); |
|
| 897 | + $this->save(); |
|
| 898 | + } |
|
| 899 | + $sold_out = true; |
|
| 900 | + } else { |
|
| 901 | + $sold_out = false; |
|
| 902 | + // was event previously marked as sold out ? |
|
| 903 | + if ($this->status() === EEM_Event::sold_out) { |
|
| 904 | + // revert status to previous value, if it was set |
|
| 905 | + $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
| 906 | + if ($previous_event_status) { |
|
| 907 | + $this->set_status($previous_event_status); |
|
| 908 | + $this->save(); |
|
| 909 | + } |
|
| 910 | + } |
|
| 911 | + } |
|
| 912 | + do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
| 913 | + return $sold_out; |
|
| 914 | + } |
|
| 915 | + |
|
| 916 | + |
|
| 917 | + /** |
|
| 918 | + * This returns the total remaining spaces for sale on this event. |
|
| 919 | + * |
|
| 920 | + * @uses EE_Event::total_available_spaces() |
|
| 921 | + * @return float|int |
|
| 922 | + * @throws EE_Error |
|
| 923 | + * @throws DomainException |
|
| 924 | + * @throws UnexpectedEntityException |
|
| 925 | + */ |
|
| 926 | + public function spaces_remaining_for_sale() |
|
| 927 | + { |
|
| 928 | + return $this->total_available_spaces(true); |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + |
|
| 932 | + /** |
|
| 933 | + * This returns the total spaces available for an event |
|
| 934 | + * while considering all the qtys on the tickets and the reg limits |
|
| 935 | + * on the datetimes attached to this event. |
|
| 936 | + * |
|
| 937 | + * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
| 938 | + * If this is false, then we return the most tickets that could ever be sold |
|
| 939 | + * for this event with the datetime and tickets setup on the event under optimal |
|
| 940 | + * selling conditions. Otherwise we return a live calculation of spaces available |
|
| 941 | + * based on tickets sold. Depending on setup and stage of sales, this |
|
| 942 | + * may appear to equal remaining tickets. However, the more tickets are |
|
| 943 | + * sold out, the more accurate the "live" total is. |
|
| 944 | + * @return float|int |
|
| 945 | + * @throws EE_Error |
|
| 946 | + * @throws DomainException |
|
| 947 | + * @throws UnexpectedEntityException |
|
| 948 | + */ |
|
| 949 | + public function total_available_spaces($consider_sold = false) |
|
| 950 | + { |
|
| 951 | + $spaces_available = $consider_sold |
|
| 952 | + ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
| 953 | + : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
| 954 | + return apply_filters( |
|
| 955 | + 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
| 956 | + $spaces_available, |
|
| 957 | + $this, |
|
| 958 | + $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
| 959 | + $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
| 960 | + ); |
|
| 961 | + } |
|
| 962 | + |
|
| 963 | + |
|
| 964 | + /** |
|
| 965 | + * Checks if the event is set to sold out |
|
| 966 | + * |
|
| 967 | + * @param bool $actual whether or not to perform calculations to not only figure the |
|
| 968 | + * actual status but also to flip the status if necessary to sold |
|
| 969 | + * out If false, we just check the existing status of the event |
|
| 970 | + * @return boolean |
|
| 971 | + * @throws EE_Error |
|
| 972 | + */ |
|
| 973 | + public function is_sold_out($actual = false) |
|
| 974 | + { |
|
| 975 | + if (! $actual) { |
|
| 976 | + return $this->status() === EEM_Event::sold_out; |
|
| 977 | + } |
|
| 978 | + return $this->perform_sold_out_status_check(); |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * Checks if the event is marked as postponed |
|
| 984 | + * |
|
| 985 | + * @return boolean |
|
| 986 | + */ |
|
| 987 | + public function is_postponed() |
|
| 988 | + { |
|
| 989 | + return $this->status() === EEM_Event::postponed; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + |
|
| 993 | + /** |
|
| 994 | + * Checks if the event is marked as cancelled |
|
| 995 | + * |
|
| 996 | + * @return boolean |
|
| 997 | + */ |
|
| 998 | + public function is_cancelled() |
|
| 999 | + { |
|
| 1000 | + return $this->status() === EEM_Event::cancelled; |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
| 1006 | + * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
| 1007 | + * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
| 1008 | + * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
| 1009 | + * the event is considered expired. |
|
| 1010 | + * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
| 1011 | + * status set on the EVENT when it is not published and thus is done |
|
| 1012 | + * |
|
| 1013 | + * @param bool $reset |
|
| 1014 | + * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
| 1015 | + * @throws EE_Error |
|
| 1016 | + */ |
|
| 1017 | + public function get_active_status($reset = false) |
|
| 1018 | + { |
|
| 1019 | + // if the active status has already been set, then just use that value (unless we are resetting it) |
|
| 1020 | + if (! empty($this->_active_status) && ! $reset) { |
|
| 1021 | + return $this->_active_status; |
|
| 1022 | + } |
|
| 1023 | + // first check if event id is present on this object |
|
| 1024 | + if (! $this->ID()) { |
|
| 1025 | + return false; |
|
| 1026 | + } |
|
| 1027 | + $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
| 1028 | + // if event is published: |
|
| 1029 | + if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
| 1030 | + // active? |
|
| 1031 | + if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1032 | + EE_Datetime::active, |
|
| 1033 | + $where_params_for_event |
|
| 1034 | + ) > 0) { |
|
| 1035 | + $this->_active_status = EE_Datetime::active; |
|
| 1036 | + } else { |
|
| 1037 | + // upcoming? |
|
| 1038 | + if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1039 | + EE_Datetime::upcoming, |
|
| 1040 | + $where_params_for_event |
|
| 1041 | + ) > 0) { |
|
| 1042 | + $this->_active_status = EE_Datetime::upcoming; |
|
| 1043 | + } else { |
|
| 1044 | + // expired? |
|
| 1045 | + if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
| 1046 | + EE_Datetime::expired, |
|
| 1047 | + $where_params_for_event |
|
| 1048 | + ) > 0 |
|
| 1049 | + ) { |
|
| 1050 | + $this->_active_status = EE_Datetime::expired; |
|
| 1051 | + } else { |
|
| 1052 | + // it would be odd if things make it this far because it basically means there are no datetime's |
|
| 1053 | + // attached to the event. So in this case it will just be considered inactive. |
|
| 1054 | + $this->_active_status = EE_Datetime::inactive; |
|
| 1055 | + } |
|
| 1056 | + } |
|
| 1057 | + } |
|
| 1058 | + } else { |
|
| 1059 | + // the event is not published, so let's just set it's active status according to its' post status |
|
| 1060 | + switch ($this->status()) { |
|
| 1061 | + case EEM_Event::sold_out: |
|
| 1062 | + $this->_active_status = EE_Datetime::sold_out; |
|
| 1063 | + break; |
|
| 1064 | + case EEM_Event::cancelled: |
|
| 1065 | + $this->_active_status = EE_Datetime::cancelled; |
|
| 1066 | + break; |
|
| 1067 | + case EEM_Event::postponed: |
|
| 1068 | + $this->_active_status = EE_Datetime::postponed; |
|
| 1069 | + break; |
|
| 1070 | + default: |
|
| 1071 | + $this->_active_status = EE_Datetime::inactive; |
|
| 1072 | + } |
|
| 1073 | + } |
|
| 1074 | + return $this->_active_status; |
|
| 1075 | + } |
|
| 1076 | + |
|
| 1077 | + |
|
| 1078 | + /** |
|
| 1079 | + * pretty_active_status |
|
| 1080 | + * |
|
| 1081 | + * @access public |
|
| 1082 | + * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
| 1083 | + * @return mixed void|string |
|
| 1084 | + * @throws EE_Error |
|
| 1085 | + */ |
|
| 1086 | + public function pretty_active_status($echo = true) |
|
| 1087 | + { |
|
| 1088 | + $active_status = $this->get_active_status(); |
|
| 1089 | + $status = '<span class="ee-status event-active-status-' |
|
| 1090 | + . $active_status |
|
| 1091 | + . '">' |
|
| 1092 | + . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
| 1093 | + . '</span>'; |
|
| 1094 | + if ($echo) { |
|
| 1095 | + echo $status; |
|
| 1096 | + return ''; |
|
| 1097 | + } |
|
| 1098 | + return $status; |
|
| 1099 | + } |
|
| 1100 | + |
|
| 1101 | + |
|
| 1102 | + /** |
|
| 1103 | + * @return bool|int |
|
| 1104 | + * @throws EE_Error |
|
| 1105 | + */ |
|
| 1106 | + public function get_number_of_tickets_sold() |
|
| 1107 | + { |
|
| 1108 | + $tkt_sold = 0; |
|
| 1109 | + if (! $this->ID()) { |
|
| 1110 | + return 0; |
|
| 1111 | + } |
|
| 1112 | + $datetimes = $this->datetimes(); |
|
| 1113 | + foreach ($datetimes as $datetime) { |
|
| 1114 | + if ($datetime instanceof EE_Datetime) { |
|
| 1115 | + $tkt_sold += $datetime->sold(); |
|
| 1116 | + } |
|
| 1117 | + } |
|
| 1118 | + return $tkt_sold; |
|
| 1119 | + } |
|
| 1120 | + |
|
| 1121 | + |
|
| 1122 | + /** |
|
| 1123 | + * This just returns a count of all the registrations for this event |
|
| 1124 | + * |
|
| 1125 | + * @access public |
|
| 1126 | + * @return int |
|
| 1127 | + * @throws EE_Error |
|
| 1128 | + */ |
|
| 1129 | + public function get_count_of_all_registrations() |
|
| 1130 | + { |
|
| 1131 | + return EEM_Event::instance()->count_related($this, 'Registration'); |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + |
|
| 1135 | + /** |
|
| 1136 | + * This returns the ticket with the earliest start time that is |
|
| 1137 | + * available for this event (across all datetimes attached to the event) |
|
| 1138 | + * |
|
| 1139 | + * @return EE_Base_Class|EE_Ticket|null |
|
| 1140 | + * @throws EE_Error |
|
| 1141 | + */ |
|
| 1142 | + public function get_ticket_with_earliest_start_time() |
|
| 1143 | + { |
|
| 1144 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1145 | + $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
| 1146 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * This returns the ticket with the latest end time that is available |
|
| 1152 | + * for this event (across all datetimes attached to the event) |
|
| 1153 | + * |
|
| 1154 | + * @return EE_Base_Class|EE_Ticket|null |
|
| 1155 | + * @throws EE_Error |
|
| 1156 | + */ |
|
| 1157 | + public function get_ticket_with_latest_end_time() |
|
| 1158 | + { |
|
| 1159 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
| 1160 | + $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
| 1161 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + |
|
| 1165 | + /** |
|
| 1166 | + * This returns the number of different ticket types currently on sale for this event. |
|
| 1167 | + * |
|
| 1168 | + * @return int |
|
| 1169 | + * @throws EE_Error |
|
| 1170 | + */ |
|
| 1171 | + public function countTicketsOnSale() |
|
| 1172 | + { |
|
| 1173 | + $where = array( |
|
| 1174 | + 'Datetime.EVT_ID' => $this->ID(), |
|
| 1175 | + 'TKT_start_date' => array('<', time()), |
|
| 1176 | + 'TKT_end_date' => array('>', time()), |
|
| 1177 | + ); |
|
| 1178 | + return EEM_Ticket::instance()->count(array($where)); |
|
| 1179 | + } |
|
| 1180 | + |
|
| 1181 | + |
|
| 1182 | + /** |
|
| 1183 | + * This returns whether there are any tickets on sale for this event. |
|
| 1184 | + * |
|
| 1185 | + * @return bool true = YES tickets on sale. |
|
| 1186 | + * @throws EE_Error |
|
| 1187 | + */ |
|
| 1188 | + public function tickets_on_sale() |
|
| 1189 | + { |
|
| 1190 | + return $this->countTicketsOnSale() > 0; |
|
| 1191 | + } |
|
| 1192 | + |
|
| 1193 | + |
|
| 1194 | + /** |
|
| 1195 | + * Gets the URL for viewing this event on the front-end. Overrides parent |
|
| 1196 | + * to check for an external URL first |
|
| 1197 | + * |
|
| 1198 | + * @return string |
|
| 1199 | + * @throws EE_Error |
|
| 1200 | + */ |
|
| 1201 | + public function get_permalink() |
|
| 1202 | + { |
|
| 1203 | + if ($this->external_url()) { |
|
| 1204 | + return $this->external_url(); |
|
| 1205 | + } |
|
| 1206 | + return parent::get_permalink(); |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + |
|
| 1210 | + /** |
|
| 1211 | + * Gets the first term for 'espresso_event_categories' we can find |
|
| 1212 | + * |
|
| 1213 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1214 | + * @return EE_Base_Class|EE_Term|null |
|
| 1215 | + * @throws EE_Error |
|
| 1216 | + */ |
|
| 1217 | + public function first_event_category($query_params = array()) |
|
| 1218 | + { |
|
| 1219 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1220 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1221 | + return EEM_Term::instance()->get_one($query_params); |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + |
|
| 1225 | + /** |
|
| 1226 | + * Gets all terms for 'espresso_event_categories' we can find |
|
| 1227 | + * |
|
| 1228 | + * @param array $query_params |
|
| 1229 | + * @return EE_Base_Class[]|EE_Term[] |
|
| 1230 | + * @throws EE_Error |
|
| 1231 | + */ |
|
| 1232 | + public function get_all_event_categories($query_params = array()) |
|
| 1233 | + { |
|
| 1234 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
| 1235 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
| 1236 | + return EEM_Term::instance()->get_all($query_params); |
|
| 1237 | + } |
|
| 1238 | + |
|
| 1239 | + |
|
| 1240 | + /** |
|
| 1241 | + * Adds a question group to this event |
|
| 1242 | + * |
|
| 1243 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1244 | + * @param bool $for_primary if true, the question group will be added for the primary |
|
| 1245 | + * registrant, if false will be added for others. default: false |
|
| 1246 | + * @return EE_Base_Class|EE_Question_Group |
|
| 1247 | + * @throws EE_Error |
|
| 1248 | + */ |
|
| 1249 | + public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1250 | + { |
|
| 1251 | + $extra = $for_primary |
|
| 1252 | + ? array('EQG_primary' => 1) |
|
| 1253 | + : array(); |
|
| 1254 | + return $this->_add_relation_to($question_group_id_or_obj, 'Question_Group', $extra); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + |
|
| 1258 | + /** |
|
| 1259 | + * Removes a question group from the event |
|
| 1260 | + * |
|
| 1261 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
| 1262 | + * @param bool $for_primary if true, the question group will be removed from the primary |
|
| 1263 | + * registrant, if false will be removed from others. default: false |
|
| 1264 | + * @return EE_Base_Class|EE_Question_Group |
|
| 1265 | + * @throws EE_Error |
|
| 1266 | + */ |
|
| 1267 | + public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
| 1268 | + { |
|
| 1269 | + $where = $for_primary |
|
| 1270 | + ? array('EQG_primary' => 1) |
|
| 1271 | + : array(); |
|
| 1272 | + return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group', $where); |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + |
|
| 1276 | + /** |
|
| 1277 | + * Gets all the question groups, ordering them by QSG_order ascending |
|
| 1278 | + * |
|
| 1279 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1280 | + * @return EE_Base_Class[]|EE_Question_Group[] |
|
| 1281 | + * @throws EE_Error |
|
| 1282 | + */ |
|
| 1283 | + public function question_groups($query_params = array()) |
|
| 1284 | + { |
|
| 1285 | + $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
| 1286 | + return $this->get_many_related('Question_Group', $query_params); |
|
| 1287 | + } |
|
| 1288 | + |
|
| 1289 | + |
|
| 1290 | + /** |
|
| 1291 | + * Implementation for EEI_Has_Icon interface method. |
|
| 1292 | + * |
|
| 1293 | + * @see EEI_Visual_Representation for comments |
|
| 1294 | + * @return string |
|
| 1295 | + */ |
|
| 1296 | + public function get_icon() |
|
| 1297 | + { |
|
| 1298 | + return '<span class="dashicons dashicons-flag"></span>'; |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + |
|
| 1302 | + /** |
|
| 1303 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1304 | + * |
|
| 1305 | + * @see EEI_Admin_Links for comments |
|
| 1306 | + * @return string |
|
| 1307 | + * @throws EE_Error |
|
| 1308 | + */ |
|
| 1309 | + public function get_admin_details_link() |
|
| 1310 | + { |
|
| 1311 | + return $this->get_admin_edit_link(); |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + |
|
| 1315 | + /** |
|
| 1316 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1317 | + * |
|
| 1318 | + * @see EEI_Admin_Links for comments |
|
| 1319 | + * @return string |
|
| 1320 | + * @throws EE_Error |
|
| 1321 | + */ |
|
| 1322 | + public function get_admin_edit_link() |
|
| 1323 | + { |
|
| 1324 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1325 | + array( |
|
| 1326 | + 'page' => 'espresso_events', |
|
| 1327 | + 'action' => 'edit', |
|
| 1328 | + 'post' => $this->ID(), |
|
| 1329 | + ), |
|
| 1330 | + admin_url('admin.php') |
|
| 1331 | + ); |
|
| 1332 | + } |
|
| 1333 | + |
|
| 1334 | + |
|
| 1335 | + /** |
|
| 1336 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1337 | + * |
|
| 1338 | + * @see EEI_Admin_Links for comments |
|
| 1339 | + * @return string |
|
| 1340 | + */ |
|
| 1341 | + public function get_admin_settings_link() |
|
| 1342 | + { |
|
| 1343 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1344 | + array( |
|
| 1345 | + 'page' => 'espresso_events', |
|
| 1346 | + 'action' => 'default_event_settings', |
|
| 1347 | + ), |
|
| 1348 | + admin_url('admin.php') |
|
| 1349 | + ); |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + |
|
| 1353 | + /** |
|
| 1354 | + * Implementation for EEI_Admin_Links interface method. |
|
| 1355 | + * |
|
| 1356 | + * @see EEI_Admin_Links for comments |
|
| 1357 | + * @return string |
|
| 1358 | + */ |
|
| 1359 | + public function get_admin_overview_link() |
|
| 1360 | + { |
|
| 1361 | + return EEH_URL::add_query_args_and_nonce( |
|
| 1362 | + array( |
|
| 1363 | + 'page' => 'espresso_events', |
|
| 1364 | + 'action' => 'default', |
|
| 1365 | + ), |
|
| 1366 | + admin_url('admin.php') |
|
| 1367 | + ); |
|
| 1368 | + } |
|
| 1369 | 1369 | } |