| @@ -102,7 +102,7 @@ discard block | ||
| 102 | 102 | * | 
| 103 | 103 | * @abstract | 
| 104 | 104 | * @access protected | 
| 105 | - * @return array | |
| 105 | + * @return string[] | |
| 106 | 106 | */ | 
| 107 | 107 | protected function _get_table_filters() | 
| 108 | 108 |      { | 
| @@ -265,7 +265,7 @@ discard block | ||
| 265 | 265 | * column_TXN_paid | 
| 266 | 266 | * | 
| 267 | 267 | * @param \EE_Transaction $transaction | 
| 268 | - * @return mixed|string | |
| 268 | + * @return string | |
| 269 | 269 | * @throws \EE_Error | 
| 270 | 270 | */ | 
| 271 | 271 | public function column_TXN_paid(EE_Transaction $transaction) | 
| @@ -13,114 +13,114 @@ discard block | ||
| 13 | 13 | class EE_Admin_Transactions_List_Table extends EE_Admin_List_Table | 
| 14 | 14 |  { | 
| 15 | 15 | |
| 16 | - private $_status; | |
| 17 | - | |
| 18 | - | |
| 19 | - /** | |
| 20 | - * @param \Transactions_Admin_Page $admin_page | |
| 21 | - */ | |
| 22 | - public function __construct(\Transactions_Admin_Page $admin_page) | |
| 23 | -    { | |
| 24 | - parent::__construct($admin_page); | |
| 25 | - $this->_status = $this->_admin_page->get_transaction_status_array(); | |
| 26 | - } | |
| 27 | - | |
| 28 | - | |
| 29 | - /** | |
| 30 | - *_setup_data | |
| 31 | - */ | |
| 32 | - protected function _setup_data() | |
| 33 | -    { | |
| 34 | - $this->_data = $this->_admin_page->get_transactions($this->_per_page); | |
| 35 | - $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; | |
| 36 | - $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); | |
| 37 | - } | |
| 38 | - | |
| 39 | - | |
| 40 | - /** | |
| 41 | - *_set_properties | |
| 42 | - */ | |
| 43 | - protected function _set_properties() | |
| 44 | -    { | |
| 45 | - $this->_wp_list_args = array( | |
| 46 | -            'singular' => __('transaction', 'event_espresso'), | |
| 47 | -            'plural'   => __('transactions', 'event_espresso'), | |
| 48 | - 'ajax' => true, | |
| 49 | - 'screen' => $this->_admin_page->get_current_screen()->id, | |
| 50 | - ); | |
| 51 | -        $ID_column_name      = __('ID', 'event_espresso'); | |
| 52 | - $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; | |
| 53 | -        $ID_column_name      .= __('Transaction Date', 'event_espresso'); | |
| 54 | - $ID_column_name .= '</span> '; | |
| 55 | - $this->_columns = array( | |
| 56 | - 'TXN_ID' => $ID_column_name, | |
| 57 | -            'TXN_timestamp' => __('Transaction Date', 'event_espresso'), | |
| 58 | -            'TXN_total'     => __('Total', 'event_espresso'), | |
| 59 | -            'TXN_paid'      => __('Paid', 'event_espresso'), | |
| 60 | -            'ATT_fname'     => __('Primary Registrant', 'event_espresso'), | |
| 61 | -            'event_name'    => __('Event', 'event_espresso'), | |
| 62 | -            'actions'       => __('Actions', 'event_espresso'), | |
| 63 | - ); | |
| 64 | - | |
| 65 | - $this->_sortable_columns = array( | |
| 66 | -            'TXN_ID'        => array('TXN_ID' => false), | |
| 67 | -            'event_name'    => array('event_name' => false), | |
| 68 | -            'ATT_fname'     => array('ATT_fname' => false), | |
| 69 | -            'TXN_timestamp' => array('TXN_timestamp' => true) //true means its already sorted | |
| 70 | - ); | |
| 71 | - | |
| 72 | - $this->_primary_column = 'TXN_ID'; | |
| 73 | - | |
| 74 | - $this->_hidden_columns = array(); | |
| 75 | - } | |
| 76 | - | |
| 77 | - | |
| 78 | - /** | |
| 79 | - * This simply sets up the row class for the table rows. | |
| 80 | - * Allows for easier overriding of child methods for setting up sorting. | |
| 81 | - * | |
| 82 | - * @param EE_Transaction $transaction the current item | |
| 83 | - * @return string | |
| 84 | - * @throws \EE_Error | |
| 85 | - */ | |
| 86 | - protected function _get_row_class($transaction) | |
| 87 | -    { | |
| 88 | - $class = parent::_get_row_class($transaction); | |
| 89 | - //add status class | |
| 90 | - $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); | |
| 91 | -        if ($this->_has_checkbox_column) { | |
| 92 | - $class .= ' has-checkbox-column'; | |
| 93 | - } | |
| 94 | - return $class; | |
| 95 | - } | |
| 96 | - | |
| 97 | - | |
| 98 | - /** | |
| 99 | - * _get_table_filters | |
| 100 | - * We use this to assemble and return any filters that are associated with this table that help further refine what | |
| 101 | - * get's shown in the table. | |
| 102 | - * | |
| 103 | - * @abstract | |
| 104 | - * @access protected | |
| 105 | - * @return array | |
| 106 | - */ | |
| 107 | - protected function _get_table_filters() | |
| 108 | -    { | |
| 109 | - $filters = array(); | |
| 110 | - $start_date = isset($this->_req_data['txn-filter-start-date']) | |
| 111 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) | |
| 112 | - : date( | |
| 113 | - 'm/d/Y', | |
| 114 | -                strtotime('-10 year') | |
| 115 | - ); | |
| 116 | - $end_date = isset($this->_req_data['txn-filter-end-date']) | |
| 117 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) | |
| 118 | - : date( | |
| 119 | - 'm/d/Y', | |
| 120 | -                current_time('timestamp') | |
| 121 | - ); | |
| 122 | - ob_start(); | |
| 123 | - ?> | |
| 16 | + private $_status; | |
| 17 | + | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * @param \Transactions_Admin_Page $admin_page | |
| 21 | + */ | |
| 22 | + public function __construct(\Transactions_Admin_Page $admin_page) | |
| 23 | +	{ | |
| 24 | + parent::__construct($admin_page); | |
| 25 | + $this->_status = $this->_admin_page->get_transaction_status_array(); | |
| 26 | + } | |
| 27 | + | |
| 28 | + | |
| 29 | + /** | |
| 30 | + *_setup_data | |
| 31 | + */ | |
| 32 | + protected function _setup_data() | |
| 33 | +	{ | |
| 34 | + $this->_data = $this->_admin_page->get_transactions($this->_per_page); | |
| 35 | + $status = ! empty($this->_req_data['status']) ? $this->_req_data['status'] : 'all'; | |
| 36 | + $this->_all_data_count = $this->_admin_page->get_transactions($this->_per_page, true, $status); | |
| 37 | + } | |
| 38 | + | |
| 39 | + | |
| 40 | + /** | |
| 41 | + *_set_properties | |
| 42 | + */ | |
| 43 | + protected function _set_properties() | |
| 44 | +	{ | |
| 45 | + $this->_wp_list_args = array( | |
| 46 | +			'singular' => __('transaction', 'event_espresso'), | |
| 47 | +			'plural'   => __('transactions', 'event_espresso'), | |
| 48 | + 'ajax' => true, | |
| 49 | + 'screen' => $this->_admin_page->get_current_screen()->id, | |
| 50 | + ); | |
| 51 | +		$ID_column_name      = __('ID', 'event_espresso'); | |
| 52 | + $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; | |
| 53 | +		$ID_column_name      .= __('Transaction Date', 'event_espresso'); | |
| 54 | + $ID_column_name .= '</span> '; | |
| 55 | + $this->_columns = array( | |
| 56 | + 'TXN_ID' => $ID_column_name, | |
| 57 | +			'TXN_timestamp' => __('Transaction Date', 'event_espresso'), | |
| 58 | +			'TXN_total'     => __('Total', 'event_espresso'), | |
| 59 | +			'TXN_paid'      => __('Paid', 'event_espresso'), | |
| 60 | +			'ATT_fname'     => __('Primary Registrant', 'event_espresso'), | |
| 61 | +			'event_name'    => __('Event', 'event_espresso'), | |
| 62 | +			'actions'       => __('Actions', 'event_espresso'), | |
| 63 | + ); | |
| 64 | + | |
| 65 | + $this->_sortable_columns = array( | |
| 66 | +			'TXN_ID'        => array('TXN_ID' => false), | |
| 67 | +			'event_name'    => array('event_name' => false), | |
| 68 | +			'ATT_fname'     => array('ATT_fname' => false), | |
| 69 | +			'TXN_timestamp' => array('TXN_timestamp' => true) //true means its already sorted | |
| 70 | + ); | |
| 71 | + | |
| 72 | + $this->_primary_column = 'TXN_ID'; | |
| 73 | + | |
| 74 | + $this->_hidden_columns = array(); | |
| 75 | + } | |
| 76 | + | |
| 77 | + | |
| 78 | + /** | |
| 79 | + * This simply sets up the row class for the table rows. | |
| 80 | + * Allows for easier overriding of child methods for setting up sorting. | |
| 81 | + * | |
| 82 | + * @param EE_Transaction $transaction the current item | |
| 83 | + * @return string | |
| 84 | + * @throws \EE_Error | |
| 85 | + */ | |
| 86 | + protected function _get_row_class($transaction) | |
| 87 | +	{ | |
| 88 | + $class = parent::_get_row_class($transaction); | |
| 89 | + //add status class | |
| 90 | + $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); | |
| 91 | +		if ($this->_has_checkbox_column) { | |
| 92 | + $class .= ' has-checkbox-column'; | |
| 93 | + } | |
| 94 | + return $class; | |
| 95 | + } | |
| 96 | + | |
| 97 | + | |
| 98 | + /** | |
| 99 | + * _get_table_filters | |
| 100 | + * We use this to assemble and return any filters that are associated with this table that help further refine what | |
| 101 | + * get's shown in the table. | |
| 102 | + * | |
| 103 | + * @abstract | |
| 104 | + * @access protected | |
| 105 | + * @return array | |
| 106 | + */ | |
| 107 | + protected function _get_table_filters() | |
| 108 | +	{ | |
| 109 | + $filters = array(); | |
| 110 | + $start_date = isset($this->_req_data['txn-filter-start-date']) | |
| 111 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) | |
| 112 | + : date( | |
| 113 | + 'm/d/Y', | |
| 114 | +				strtotime('-10 year') | |
| 115 | + ); | |
| 116 | + $end_date = isset($this->_req_data['txn-filter-end-date']) | |
| 117 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) | |
| 118 | + : date( | |
| 119 | + 'm/d/Y', | |
| 120 | +				current_time('timestamp') | |
| 121 | + ); | |
| 122 | + ob_start(); | |
| 123 | + ?> | |
| 124 | 124 | <label for="txn-filter-start-date">Display Transactions from </label> | 
| 125 | 125 | <input id="txn-filter-start-date" class="datepicker" type="text" value="<?php echo $start_date; ?>" | 
| 126 | 126 | name="txn-filter-start-date" size="15"/> | 
| @@ -128,534 +128,534 @@ discard block | ||
| 128 | 128 | <input id="txn-filter-end-date" class="datepicker" type="text" value="<?php echo $end_date; ?>" | 
| 129 | 129 | name="txn-filter-end-date" size="15"/> | 
| 130 | 130 | <?php | 
| 131 | - $filters[] = ob_get_contents(); | |
| 132 | - ob_end_clean(); | |
| 133 | - return $filters; | |
| 134 | - } | |
| 135 | - | |
| 136 | - | |
| 137 | - /** | |
| 138 | - *_add_view_counts | |
| 139 | - */ | |
| 140 | - protected function _add_view_counts() | |
| 141 | -    { | |
| 142 | - $this->_views['all']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'all'); | |
| 143 | - $this->_views['abandoned']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'abandoned'); | |
| 144 | - $this->_views['failed']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'failed'); | |
| 145 | - } | |
| 146 | - | |
| 147 | - | |
| 148 | - /** | |
| 149 | - * column TXN_ID | |
| 150 | - * | |
| 151 | - * @param \EE_Transaction $transaction | |
| 152 | - * @return string | |
| 153 | - * @throws \EE_Error | |
| 154 | - */ | |
| 155 | - public function column_TXN_ID(EE_Transaction $transaction) | |
| 156 | -    { | |
| 157 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 158 | - 'action' => 'view_transaction', | |
| 159 | - 'TXN_ID' => $transaction->ID(), | |
| 160 | - ), TXN_ADMIN_URL); | |
| 161 | - $content = '<a href="' . $view_lnk_url . '"' | |
| 162 | -                        . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' | |
| 163 | - . $transaction->ID() | |
| 164 | - . '</a>'; | |
| 165 | - | |
| 166 | - //txn timestamp | |
| 167 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; | |
| 168 | - return $content; | |
| 169 | - } | |
| 170 | - | |
| 171 | - | |
| 172 | - /** | |
| 173 | - * @param \EE_Transaction $transaction | |
| 174 | - * @return string | |
| 175 | - * @throws \EE_Error | |
| 176 | - */ | |
| 177 | - protected function _get_txn_timestamp(EE_Transaction $transaction) | |
| 178 | -    { | |
| 179 | - //txn timestamp | |
| 180 | - // is TXN less than 2 hours old ? | |
| 181 | - if (($transaction->failed() || $transaction->is_abandoned()) | |
| 182 | - && ( | |
| 183 | - (time() - EE_Registry::instance()->SSN->lifespan()) < $transaction->datetime(false, true) | |
| 184 | - ) | |
| 185 | -        ) { | |
| 186 | -            $timestamp = esc_html__('TXN in progress...', 'event_espresso'); | |
| 187 | -        } else { | |
| 188 | -            $timestamp = $transaction->get_i18n_datetime('TXN_timestamp'); | |
| 189 | - } | |
| 190 | - return $timestamp; | |
| 191 | - } | |
| 192 | - | |
| 193 | - | |
| 194 | - /** | |
| 195 | - * column_cb | |
| 196 | - * | |
| 197 | - * @param \EE_Transaction $transaction | |
| 198 | - * @return string | |
| 199 | - * @throws \EE_Error | |
| 200 | - */ | |
| 201 | - public function column_cb($transaction) | |
| 202 | -    { | |
| 203 | - return sprintf( | |
| 204 | - '<input type="checkbox" name="%1$s[]" value="%2$s" />', | |
| 205 | - $this->_wp_list_args['singular'], | |
| 206 | - $transaction->ID() | |
| 207 | - ); | |
| 208 | - } | |
| 209 | - | |
| 210 | - | |
| 211 | - /** | |
| 212 | - * column_TXN_timestamp | |
| 213 | - * | |
| 214 | - * @param \EE_Transaction $transaction | |
| 215 | - * @return string | |
| 216 | - * @throws \EE_Error | |
| 217 | - */ | |
| 218 | - public function column_TXN_timestamp(EE_Transaction $transaction) | |
| 219 | -    { | |
| 220 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 221 | - 'action' => 'view_transaction', | |
| 222 | - 'TXN_ID' => $transaction->ID(), | |
| 223 | - ), TXN_ADMIN_URL); | |
| 224 | - $txn_date = '<a href="' . $view_lnk_url . '"' | |
| 225 | - . ' title="' | |
| 226 | -                        . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' | |
| 227 | - . $this->_get_txn_timestamp($transaction) | |
| 228 | - . '</a>'; | |
| 229 | - //status | |
| 230 | - $txn_date .= '<br><span class="ee-status-text-small">' | |
| 231 | - . EEH_Template::pretty_status( | |
| 232 | - $transaction->status_ID(), | |
| 233 | - false, | |
| 234 | - 'sentence' | |
| 235 | - ) | |
| 236 | - . '</span>'; | |
| 237 | - return $txn_date; | |
| 238 | - } | |
| 239 | - | |
| 240 | - | |
| 241 | - /** | |
| 242 | - * column_TXN_total | |
| 243 | - * | |
| 244 | - * @param \EE_Transaction $transaction | |
| 245 | - * @return string | |
| 246 | - * @throws \EE_Error | |
| 247 | - */ | |
| 248 | - public function column_TXN_total(EE_Transaction $transaction) | |
| 249 | -    { | |
| 250 | -        if ($transaction->get('TXN_total') > 0) { | |
| 251 | - return '<span class="txn-pad-rght">' | |
| 252 | - . apply_filters( | |
| 253 | - 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', | |
| 254 | -                       $transaction->get_pretty('TXN_total'), | |
| 255 | - $transaction | |
| 256 | - ) | |
| 257 | - . '</span>'; | |
| 258 | -        } else { | |
| 259 | -            return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; | |
| 260 | - } | |
| 261 | - } | |
| 262 | - | |
| 263 | - | |
| 264 | - /** | |
| 265 | - * column_TXN_paid | |
| 266 | - * | |
| 267 | - * @param \EE_Transaction $transaction | |
| 268 | - * @return mixed|string | |
| 269 | - * @throws \EE_Error | |
| 270 | - */ | |
| 271 | - public function column_TXN_paid(EE_Transaction $transaction) | |
| 272 | -    { | |
| 273 | -        $transaction_total = $transaction->get('TXN_total'); | |
| 274 | -        $transaction_paid  = $transaction->get('TXN_paid'); | |
| 275 | - | |
| 276 | -        if (\EEH_Money::compare_floats($transaction_total, 0, '>')) { | |
| 277 | - // monies owing | |
| 278 | - $span_class = 'txn-overview-part-payment-spn'; | |
| 279 | -            if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { | |
| 280 | - // paid in full | |
| 281 | - $span_class = 'txn-overview-full-payment-spn'; | |
| 282 | -            } elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) { | |
| 283 | - // no payments made | |
| 284 | - $span_class = 'txn-overview-no-payment-spn'; | |
| 285 | - } | |
| 286 | -        } else { | |
| 287 | - $span_class = 'txn-overview-free-event-spn'; | |
| 288 | - $transaction_paid = 0; | |
| 289 | - } | |
| 290 | - | |
| 291 | - $payment_method = $transaction->payment_method(); | |
| 292 | - $payment_method_name = $payment_method instanceof EE_Payment_Method | |
| 293 | - ? $payment_method->admin_name() | |
| 294 | -            : esc_html__('Unknown', 'event_espresso'); | |
| 295 | -        $transaction_paid_content = $transaction_paid !== 0 ? $transaction->get_pretty('TXN_paid') : $transaction_paid; | |
| 296 | - | |
| 297 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' | |
| 298 | - . $transaction_paid_content | |
| 299 | - . '</span>'; | |
| 300 | -        if ($transaction_paid > 0) { | |
| 301 | - $content .= '<br><span class="ee-status-text-small">' | |
| 302 | - . sprintf( | |
| 303 | -                            esc_html__('...via %s', 'event_espresso'), | |
| 304 | - $payment_method_name | |
| 305 | - ) | |
| 306 | - . '</span>'; | |
| 307 | - } | |
| 308 | - return $content; | |
| 309 | - } | |
| 310 | - | |
| 311 | - | |
| 312 | - /** | |
| 313 | - * column_ATT_fname | |
| 314 | - * | |
| 315 | - * @param \EE_Transaction $transaction | |
| 316 | - * @return string | |
| 317 | - * @throws \EE_Error | |
| 318 | - */ | |
| 319 | - public function column_ATT_fname(EE_Transaction $transaction) | |
| 320 | -    { | |
| 321 | - $primary_reg = $transaction->primary_registration(); | |
| 322 | -        $attendee    = $primary_reg->get_first_related('Attendee'); | |
| 323 | -        if ($attendee instanceof EE_Attendee) { | |
| 324 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 325 | - 'action' => 'view_registration', | |
| 326 | - '_REG_ID' => $primary_reg->ID(), | |
| 327 | - ), REG_ADMIN_URL); | |
| 328 | - $content = EE_Registry::instance()->CAP->current_user_can( | |
| 329 | - 'ee_read_registration', | |
| 330 | - 'espresso_registrations_view_registration', | |
| 331 | - $primary_reg->ID() | |
| 332 | - ) | |
| 333 | - ? '<a href="' . $edit_lnk_url . '"' | |
| 334 | -                    . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' | |
| 335 | - . $attendee->full_name() | |
| 336 | - . '</a>' | |
| 337 | - : $attendee->full_name(); | |
| 338 | - $content .= '<br>' . $attendee->email(); | |
| 339 | - return $content; | |
| 340 | - } | |
| 341 | - return $transaction->failed() || $transaction->is_abandoned() | |
| 342 | -            ? esc_html__('no contact record.', 'event_espresso') | |
| 343 | - : esc_html__( | |
| 344 | - 'No contact record, because the transaction was abandoned or the registration process failed.', | |
| 345 | - 'event_espresso' | |
| 346 | - ); | |
| 347 | - } | |
| 348 | - | |
| 349 | - | |
| 350 | - /** | |
| 351 | - * column_ATT_email | |
| 352 | - * | |
| 353 | - * @param \EE_Transaction $transaction | |
| 354 | - * @return string | |
| 355 | - * @throws \EE_Error | |
| 356 | - */ | |
| 357 | - public function column_ATT_email(EE_Transaction $transaction) | |
| 358 | -    { | |
| 359 | -        $attendee = $transaction->primary_registration()->get_first_related('Attendee'); | |
| 360 | -        if (! empty($attendee)) { | |
| 361 | -            return '<a href="mailto:' . $attendee->get('ATT_email') . '">' | |
| 362 | -                   . $attendee->get('ATT_email') | |
| 363 | - . '</a>'; | |
| 364 | -        } else { | |
| 365 | - return $transaction->failed() || $transaction->is_abandoned() | |
| 366 | -                ? esc_html__('no contact record.', 'event_espresso') | |
| 367 | - : esc_html__( | |
| 368 | - 'No contact record, because the transaction was abandoned or the registration process failed.', | |
| 369 | - 'event_espresso' | |
| 370 | - ); | |
| 371 | - } | |
| 372 | - } | |
| 373 | - | |
| 374 | - | |
| 375 | - /** | |
| 376 | - * column_event_name | |
| 377 | - * | |
| 378 | - * @param \EE_Transaction $transaction | |
| 379 | - * @return string | |
| 380 | - * @throws \EE_Error | |
| 381 | - */ | |
| 382 | - public function column_event_name(EE_Transaction $transaction) | |
| 383 | -    { | |
| 384 | - $actions = array(); | |
| 385 | -        $event   = $transaction->primary_registration()->get_first_related('Event'); | |
| 386 | -        if (! empty($event)) { | |
| 387 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( | |
| 388 | -                array('action' => 'edit', 'post' => $event->ID()), | |
| 389 | - EVENTS_ADMIN_URL | |
| 390 | - ); | |
| 391 | -            $event_name     = $event->get('EVT_name'); | |
| 392 | - | |
| 393 | - //filter this view by transactions for this event | |
| 394 | - $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 395 | - 'action' => 'default', | |
| 396 | - 'EVT_ID' => $event->ID(), | |
| 397 | - )); | |
| 398 | - if (EE_Registry::instance()->CAP->current_user_can( | |
| 399 | - 'ee_edit_event', | |
| 400 | - 'espresso_events_edit', | |
| 401 | - $event->ID() | |
| 402 | -            )) { | |
| 403 | - $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' | |
| 404 | -                        . ' title="' . esc_attr__('Filter transactions by this event', 'event_espresso') . '">' | |
| 405 | -                        . esc_html__('View Transactions for this event', 'event_espresso') | |
| 406 | - . '</a>'; | |
| 407 | - } | |
| 408 | - | |
| 409 | - return sprintf( | |
| 410 | - '%1$s %2$s', | |
| 411 | - EE_Registry::instance()->CAP->current_user_can( | |
| 412 | - 'ee_edit_event', | |
| 413 | - 'espresso_events_edit', | |
| 414 | - $event->ID() | |
| 415 | - ) | |
| 416 | - ? '<a href="' . $edit_event_url . '"' | |
| 417 | - . ' title="' | |
| 418 | - . sprintf( | |
| 419 | -                            esc_attr__('Edit Event: %s', 'event_espresso'), | |
| 420 | -                            $event->get('EVT_name') | |
| 421 | - ) | |
| 422 | - . '">' | |
| 423 | - . wp_trim_words( | |
| 424 | - $event_name, | |
| 425 | - 30, | |
| 426 | - '...' | |
| 427 | - ) | |
| 428 | - . '</a>' | |
| 429 | - : wp_trim_words($event_name, 30, '...'), | |
| 430 | - $this->row_actions($actions) | |
| 431 | - ); | |
| 432 | -        } else { | |
| 433 | - return esc_html__( | |
| 434 | - 'The event associated with this transaction via the primary registration cannot be retrieved.', | |
| 435 | - 'event_espresso' | |
| 436 | - ); | |
| 437 | - } | |
| 438 | - } | |
| 439 | - | |
| 440 | - | |
| 441 | - /** | |
| 442 | - * column_actions | |
| 443 | - * | |
| 444 | - * @param \EE_Transaction $transaction | |
| 445 | - * @return string | |
| 446 | - * @throws \EE_Error | |
| 447 | - */ | |
| 448 | - public function column_actions(EE_Transaction $transaction) | |
| 449 | -    { | |
| 450 | - return $this->_action_string( | |
| 451 | - $this->get_transaction_details_link($transaction) | |
| 452 | - . $this->get_invoice_link($transaction) | |
| 453 | - . $this->get_receipt_link($transaction) | |
| 454 | - . $this->get_primary_registration_details_link($transaction) | |
| 455 | - . $this->get_send_payment_reminder_trigger_link($transaction) | |
| 456 | - . $this->get_payment_overview_link($transaction) | |
| 457 | - . $this->get_related_messages_link($transaction), | |
| 458 | - $transaction, | |
| 459 | - 'ul', | |
| 460 | - 'txn-overview-actions-ul' | |
| 461 | - ); | |
| 462 | - } | |
| 463 | - | |
| 464 | - | |
| 465 | - /** | |
| 466 | - * Get the transaction details link. | |
| 467 | - * @param EE_Transaction $transaction | |
| 468 | - * @return string | |
| 469 | - * @throws EE_Error | |
| 470 | - */ | |
| 471 | - protected function get_transaction_details_link(EE_Transaction $transaction) | |
| 472 | -    { | |
| 473 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 474 | - 'action' => 'view_transaction', | |
| 475 | - 'TXN_ID' => $transaction->ID(), | |
| 476 | - ), TXN_ADMIN_URL); | |
| 477 | - return ' | |
| 131 | + $filters[] = ob_get_contents(); | |
| 132 | + ob_end_clean(); | |
| 133 | + return $filters; | |
| 134 | + } | |
| 135 | + | |
| 136 | + | |
| 137 | + /** | |
| 138 | + *_add_view_counts | |
| 139 | + */ | |
| 140 | + protected function _add_view_counts() | |
| 141 | +	{ | |
| 142 | + $this->_views['all']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'all'); | |
| 143 | + $this->_views['abandoned']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'abandoned'); | |
| 144 | + $this->_views['failed']['count'] = $this->_admin_page->get_transactions($this->_per_page, true, 'failed'); | |
| 145 | + } | |
| 146 | + | |
| 147 | + | |
| 148 | + /** | |
| 149 | + * column TXN_ID | |
| 150 | + * | |
| 151 | + * @param \EE_Transaction $transaction | |
| 152 | + * @return string | |
| 153 | + * @throws \EE_Error | |
| 154 | + */ | |
| 155 | + public function column_TXN_ID(EE_Transaction $transaction) | |
| 156 | +	{ | |
| 157 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 158 | + 'action' => 'view_transaction', | |
| 159 | + 'TXN_ID' => $transaction->ID(), | |
| 160 | + ), TXN_ADMIN_URL); | |
| 161 | + $content = '<a href="' . $view_lnk_url . '"' | |
| 162 | +						. ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' | |
| 163 | + . $transaction->ID() | |
| 164 | + . '</a>'; | |
| 165 | + | |
| 166 | + //txn timestamp | |
| 167 | + $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; | |
| 168 | + return $content; | |
| 169 | + } | |
| 170 | + | |
| 171 | + | |
| 172 | + /** | |
| 173 | + * @param \EE_Transaction $transaction | |
| 174 | + * @return string | |
| 175 | + * @throws \EE_Error | |
| 176 | + */ | |
| 177 | + protected function _get_txn_timestamp(EE_Transaction $transaction) | |
| 178 | +	{ | |
| 179 | + //txn timestamp | |
| 180 | + // is TXN less than 2 hours old ? | |
| 181 | + if (($transaction->failed() || $transaction->is_abandoned()) | |
| 182 | + && ( | |
| 183 | + (time() - EE_Registry::instance()->SSN->lifespan()) < $transaction->datetime(false, true) | |
| 184 | + ) | |
| 185 | +		) { | |
| 186 | +			$timestamp = esc_html__('TXN in progress...', 'event_espresso'); | |
| 187 | +		} else { | |
| 188 | +			$timestamp = $transaction->get_i18n_datetime('TXN_timestamp'); | |
| 189 | + } | |
| 190 | + return $timestamp; | |
| 191 | + } | |
| 192 | + | |
| 193 | + | |
| 194 | + /** | |
| 195 | + * column_cb | |
| 196 | + * | |
| 197 | + * @param \EE_Transaction $transaction | |
| 198 | + * @return string | |
| 199 | + * @throws \EE_Error | |
| 200 | + */ | |
| 201 | + public function column_cb($transaction) | |
| 202 | +	{ | |
| 203 | + return sprintf( | |
| 204 | + '<input type="checkbox" name="%1$s[]" value="%2$s" />', | |
| 205 | + $this->_wp_list_args['singular'], | |
| 206 | + $transaction->ID() | |
| 207 | + ); | |
| 208 | + } | |
| 209 | + | |
| 210 | + | |
| 211 | + /** | |
| 212 | + * column_TXN_timestamp | |
| 213 | + * | |
| 214 | + * @param \EE_Transaction $transaction | |
| 215 | + * @return string | |
| 216 | + * @throws \EE_Error | |
| 217 | + */ | |
| 218 | + public function column_TXN_timestamp(EE_Transaction $transaction) | |
| 219 | +	{ | |
| 220 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 221 | + 'action' => 'view_transaction', | |
| 222 | + 'TXN_ID' => $transaction->ID(), | |
| 223 | + ), TXN_ADMIN_URL); | |
| 224 | + $txn_date = '<a href="' . $view_lnk_url . '"' | |
| 225 | + . ' title="' | |
| 226 | +						. esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' | |
| 227 | + . $this->_get_txn_timestamp($transaction) | |
| 228 | + . '</a>'; | |
| 229 | + //status | |
| 230 | + $txn_date .= '<br><span class="ee-status-text-small">' | |
| 231 | + . EEH_Template::pretty_status( | |
| 232 | + $transaction->status_ID(), | |
| 233 | + false, | |
| 234 | + 'sentence' | |
| 235 | + ) | |
| 236 | + . '</span>'; | |
| 237 | + return $txn_date; | |
| 238 | + } | |
| 239 | + | |
| 240 | + | |
| 241 | + /** | |
| 242 | + * column_TXN_total | |
| 243 | + * | |
| 244 | + * @param \EE_Transaction $transaction | |
| 245 | + * @return string | |
| 246 | + * @throws \EE_Error | |
| 247 | + */ | |
| 248 | + public function column_TXN_total(EE_Transaction $transaction) | |
| 249 | +	{ | |
| 250 | +		if ($transaction->get('TXN_total') > 0) { | |
| 251 | + return '<span class="txn-pad-rght">' | |
| 252 | + . apply_filters( | |
| 253 | + 'FHEE__EE_Admin_Transactions_List_Table__column_TXN_total__TXN_total', | |
| 254 | +					   $transaction->get_pretty('TXN_total'), | |
| 255 | + $transaction | |
| 256 | + ) | |
| 257 | + . '</span>'; | |
| 258 | +		} else { | |
| 259 | +			return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; | |
| 260 | + } | |
| 261 | + } | |
| 262 | + | |
| 263 | + | |
| 264 | + /** | |
| 265 | + * column_TXN_paid | |
| 266 | + * | |
| 267 | + * @param \EE_Transaction $transaction | |
| 268 | + * @return mixed|string | |
| 269 | + * @throws \EE_Error | |
| 270 | + */ | |
| 271 | + public function column_TXN_paid(EE_Transaction $transaction) | |
| 272 | +	{ | |
| 273 | +		$transaction_total = $transaction->get('TXN_total'); | |
| 274 | +		$transaction_paid  = $transaction->get('TXN_paid'); | |
| 275 | + | |
| 276 | +		if (\EEH_Money::compare_floats($transaction_total, 0, '>')) { | |
| 277 | + // monies owing | |
| 278 | + $span_class = 'txn-overview-part-payment-spn'; | |
| 279 | +			if (\EEH_Money::compare_floats($transaction_paid, $transaction_total, '>=')) { | |
| 280 | + // paid in full | |
| 281 | + $span_class = 'txn-overview-full-payment-spn'; | |
| 282 | +			} elseif (\EEH_Money::compare_floats($transaction_paid, 0, '==')) { | |
| 283 | + // no payments made | |
| 284 | + $span_class = 'txn-overview-no-payment-spn'; | |
| 285 | + } | |
| 286 | +		} else { | |
| 287 | + $span_class = 'txn-overview-free-event-spn'; | |
| 288 | + $transaction_paid = 0; | |
| 289 | + } | |
| 290 | + | |
| 291 | + $payment_method = $transaction->payment_method(); | |
| 292 | + $payment_method_name = $payment_method instanceof EE_Payment_Method | |
| 293 | + ? $payment_method->admin_name() | |
| 294 | +			: esc_html__('Unknown', 'event_espresso'); | |
| 295 | +		$transaction_paid_content = $transaction_paid !== 0 ? $transaction->get_pretty('TXN_paid') : $transaction_paid; | |
| 296 | + | |
| 297 | + $content = '<span class="' . $span_class . ' txn-pad-rght">' | |
| 298 | + . $transaction_paid_content | |
| 299 | + . '</span>'; | |
| 300 | +		if ($transaction_paid > 0) { | |
| 301 | + $content .= '<br><span class="ee-status-text-small">' | |
| 302 | + . sprintf( | |
| 303 | +							esc_html__('...via %s', 'event_espresso'), | |
| 304 | + $payment_method_name | |
| 305 | + ) | |
| 306 | + . '</span>'; | |
| 307 | + } | |
| 308 | + return $content; | |
| 309 | + } | |
| 310 | + | |
| 311 | + | |
| 312 | + /** | |
| 313 | + * column_ATT_fname | |
| 314 | + * | |
| 315 | + * @param \EE_Transaction $transaction | |
| 316 | + * @return string | |
| 317 | + * @throws \EE_Error | |
| 318 | + */ | |
| 319 | + public function column_ATT_fname(EE_Transaction $transaction) | |
| 320 | +	{ | |
| 321 | + $primary_reg = $transaction->primary_registration(); | |
| 322 | +		$attendee    = $primary_reg->get_first_related('Attendee'); | |
| 323 | +		if ($attendee instanceof EE_Attendee) { | |
| 324 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 325 | + 'action' => 'view_registration', | |
| 326 | + '_REG_ID' => $primary_reg->ID(), | |
| 327 | + ), REG_ADMIN_URL); | |
| 328 | + $content = EE_Registry::instance()->CAP->current_user_can( | |
| 329 | + 'ee_read_registration', | |
| 330 | + 'espresso_registrations_view_registration', | |
| 331 | + $primary_reg->ID() | |
| 332 | + ) | |
| 333 | + ? '<a href="' . $edit_lnk_url . '"' | |
| 334 | +					. ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' | |
| 335 | + . $attendee->full_name() | |
| 336 | + . '</a>' | |
| 337 | + : $attendee->full_name(); | |
| 338 | + $content .= '<br>' . $attendee->email(); | |
| 339 | + return $content; | |
| 340 | + } | |
| 341 | + return $transaction->failed() || $transaction->is_abandoned() | |
| 342 | +			? esc_html__('no contact record.', 'event_espresso') | |
| 343 | + : esc_html__( | |
| 344 | + 'No contact record, because the transaction was abandoned or the registration process failed.', | |
| 345 | + 'event_espresso' | |
| 346 | + ); | |
| 347 | + } | |
| 348 | + | |
| 349 | + | |
| 350 | + /** | |
| 351 | + * column_ATT_email | |
| 352 | + * | |
| 353 | + * @param \EE_Transaction $transaction | |
| 354 | + * @return string | |
| 355 | + * @throws \EE_Error | |
| 356 | + */ | |
| 357 | + public function column_ATT_email(EE_Transaction $transaction) | |
| 358 | +	{ | |
| 359 | +		$attendee = $transaction->primary_registration()->get_first_related('Attendee'); | |
| 360 | +		if (! empty($attendee)) { | |
| 361 | +			return '<a href="mailto:' . $attendee->get('ATT_email') . '">' | |
| 362 | +				   . $attendee->get('ATT_email') | |
| 363 | + . '</a>'; | |
| 364 | +		} else { | |
| 365 | + return $transaction->failed() || $transaction->is_abandoned() | |
| 366 | +				? esc_html__('no contact record.', 'event_espresso') | |
| 367 | + : esc_html__( | |
| 368 | + 'No contact record, because the transaction was abandoned or the registration process failed.', | |
| 369 | + 'event_espresso' | |
| 370 | + ); | |
| 371 | + } | |
| 372 | + } | |
| 373 | + | |
| 374 | + | |
| 375 | + /** | |
| 376 | + * column_event_name | |
| 377 | + * | |
| 378 | + * @param \EE_Transaction $transaction | |
| 379 | + * @return string | |
| 380 | + * @throws \EE_Error | |
| 381 | + */ | |
| 382 | + public function column_event_name(EE_Transaction $transaction) | |
| 383 | +	{ | |
| 384 | + $actions = array(); | |
| 385 | +		$event   = $transaction->primary_registration()->get_first_related('Event'); | |
| 386 | +		if (! empty($event)) { | |
| 387 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( | |
| 388 | +				array('action' => 'edit', 'post' => $event->ID()), | |
| 389 | + EVENTS_ADMIN_URL | |
| 390 | + ); | |
| 391 | +			$event_name     = $event->get('EVT_name'); | |
| 392 | + | |
| 393 | + //filter this view by transactions for this event | |
| 394 | + $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 395 | + 'action' => 'default', | |
| 396 | + 'EVT_ID' => $event->ID(), | |
| 397 | + )); | |
| 398 | + if (EE_Registry::instance()->CAP->current_user_can( | |
| 399 | + 'ee_edit_event', | |
| 400 | + 'espresso_events_edit', | |
| 401 | + $event->ID() | |
| 402 | +			)) { | |
| 403 | + $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' | |
| 404 | +						. ' title="' . esc_attr__('Filter transactions by this event', 'event_espresso') . '">' | |
| 405 | +						. esc_html__('View Transactions for this event', 'event_espresso') | |
| 406 | + . '</a>'; | |
| 407 | + } | |
| 408 | + | |
| 409 | + return sprintf( | |
| 410 | + '%1$s %2$s', | |
| 411 | + EE_Registry::instance()->CAP->current_user_can( | |
| 412 | + 'ee_edit_event', | |
| 413 | + 'espresso_events_edit', | |
| 414 | + $event->ID() | |
| 415 | + ) | |
| 416 | + ? '<a href="' . $edit_event_url . '"' | |
| 417 | + . ' title="' | |
| 418 | + . sprintf( | |
| 419 | +							esc_attr__('Edit Event: %s', 'event_espresso'), | |
| 420 | +							$event->get('EVT_name') | |
| 421 | + ) | |
| 422 | + . '">' | |
| 423 | + . wp_trim_words( | |
| 424 | + $event_name, | |
| 425 | + 30, | |
| 426 | + '...' | |
| 427 | + ) | |
| 428 | + . '</a>' | |
| 429 | + : wp_trim_words($event_name, 30, '...'), | |
| 430 | + $this->row_actions($actions) | |
| 431 | + ); | |
| 432 | +		} else { | |
| 433 | + return esc_html__( | |
| 434 | + 'The event associated with this transaction via the primary registration cannot be retrieved.', | |
| 435 | + 'event_espresso' | |
| 436 | + ); | |
| 437 | + } | |
| 438 | + } | |
| 439 | + | |
| 440 | + | |
| 441 | + /** | |
| 442 | + * column_actions | |
| 443 | + * | |
| 444 | + * @param \EE_Transaction $transaction | |
| 445 | + * @return string | |
| 446 | + * @throws \EE_Error | |
| 447 | + */ | |
| 448 | + public function column_actions(EE_Transaction $transaction) | |
| 449 | +	{ | |
| 450 | + return $this->_action_string( | |
| 451 | + $this->get_transaction_details_link($transaction) | |
| 452 | + . $this->get_invoice_link($transaction) | |
| 453 | + . $this->get_receipt_link($transaction) | |
| 454 | + . $this->get_primary_registration_details_link($transaction) | |
| 455 | + . $this->get_send_payment_reminder_trigger_link($transaction) | |
| 456 | + . $this->get_payment_overview_link($transaction) | |
| 457 | + . $this->get_related_messages_link($transaction), | |
| 458 | + $transaction, | |
| 459 | + 'ul', | |
| 460 | + 'txn-overview-actions-ul' | |
| 461 | + ); | |
| 462 | + } | |
| 463 | + | |
| 464 | + | |
| 465 | + /** | |
| 466 | + * Get the transaction details link. | |
| 467 | + * @param EE_Transaction $transaction | |
| 468 | + * @return string | |
| 469 | + * @throws EE_Error | |
| 470 | + */ | |
| 471 | + protected function get_transaction_details_link(EE_Transaction $transaction) | |
| 472 | +	{ | |
| 473 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 474 | + 'action' => 'view_transaction', | |
| 475 | + 'TXN_ID' => $transaction->ID(), | |
| 476 | + ), TXN_ADMIN_URL); | |
| 477 | + return ' | |
| 478 | 478 | <li> | 
| 479 | 479 | <a href="' . $url . '"' | 
| 480 | -                    . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> | |
| 480 | +					. ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> | |
| 481 | 481 | <span class="dashicons dashicons-cart"></span> | 
| 482 | 482 | </a> | 
| 483 | 483 | </li>'; | 
| 484 | - } | |
| 485 | - | |
| 486 | - | |
| 487 | - /** | |
| 488 | - * Get the invoice link for the given registration. | |
| 489 | - * @param EE_Transaction $transaction | |
| 490 | - * @return string | |
| 491 | - * @throws EE_Error | |
| 492 | - */ | |
| 493 | - protected function get_invoice_link(EE_Transaction $transaction) | |
| 494 | -    { | |
| 495 | - $registration = $transaction->primary_registration(); | |
| 496 | -        if ($registration instanceof EE_Registration) { | |
| 497 | - $url = $registration->invoice_url(); | |
| 498 | - //only show invoice link if message type is active. | |
| 499 | - if ($registration->attendee() instanceof EE_Attendee | |
| 500 | -                && EEH_MSG_Template::is_mt_active('invoice') | |
| 501 | -            ) { | |
| 502 | - return ' | |
| 484 | + } | |
| 485 | + | |
| 486 | + | |
| 487 | + /** | |
| 488 | + * Get the invoice link for the given registration. | |
| 489 | + * @param EE_Transaction $transaction | |
| 490 | + * @return string | |
| 491 | + * @throws EE_Error | |
| 492 | + */ | |
| 493 | + protected function get_invoice_link(EE_Transaction $transaction) | |
| 494 | +	{ | |
| 495 | + $registration = $transaction->primary_registration(); | |
| 496 | +		if ($registration instanceof EE_Registration) { | |
| 497 | + $url = $registration->invoice_url(); | |
| 498 | + //only show invoice link if message type is active. | |
| 499 | + if ($registration->attendee() instanceof EE_Attendee | |
| 500 | +				&& EEH_MSG_Template::is_mt_active('invoice') | |
| 501 | +			) { | |
| 502 | + return ' | |
| 503 | 503 | <li> | 
| 504 | 504 |                      <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' | 
| 505 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> | |
| 505 | + . ' target="_blank" href="' . $url . '" class="tiny-text"> | |
| 506 | 506 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> | 
| 507 | 507 | </a> | 
| 508 | 508 | </li>'; | 
| 509 | - } | |
| 510 | - } | |
| 511 | - return ''; | |
| 512 | - } | |
| 513 | - | |
| 514 | - | |
| 515 | - /** | |
| 516 | - * Get the receipt link for the transaction. | |
| 517 | - * @param EE_Transaction $transaction | |
| 518 | - * @return string | |
| 519 | - * @throws EE_Error | |
| 520 | - */ | |
| 521 | - protected function get_receipt_link(EE_Transaction $transaction) | |
| 522 | -    { | |
| 523 | - $registration = $transaction->primary_registration(); | |
| 524 | -        if ($registration instanceof EE_Registration) { | |
| 525 | - $url = $registration->receipt_url(); | |
| 526 | - //only show receipt link if message type is active. | |
| 527 | - if ($registration->attendee() instanceof EE_Attendee | |
| 528 | -                && EEH_MSG_Template::is_mt_active('receipt')) { | |
| 529 | - return ' | |
| 509 | + } | |
| 510 | + } | |
| 511 | + return ''; | |
| 512 | + } | |
| 513 | + | |
| 514 | + | |
| 515 | + /** | |
| 516 | + * Get the receipt link for the transaction. | |
| 517 | + * @param EE_Transaction $transaction | |
| 518 | + * @return string | |
| 519 | + * @throws EE_Error | |
| 520 | + */ | |
| 521 | + protected function get_receipt_link(EE_Transaction $transaction) | |
| 522 | +	{ | |
| 523 | + $registration = $transaction->primary_registration(); | |
| 524 | +		if ($registration instanceof EE_Registration) { | |
| 525 | + $url = $registration->receipt_url(); | |
| 526 | + //only show receipt link if message type is active. | |
| 527 | + if ($registration->attendee() instanceof EE_Attendee | |
| 528 | +				&& EEH_MSG_Template::is_mt_active('receipt')) { | |
| 529 | + return ' | |
| 530 | 530 | <li> | 
| 531 | 531 |  				<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' | 
| 532 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> | |
| 532 | + . ' target="_blank" href="' . $url . '" class="tiny-text"> | |
| 533 | 533 | <span class="dashicons dashicons-media-default ee-icon-size-18"></span> | 
| 534 | 534 | </a> | 
| 535 | 535 | </li>'; | 
| 536 | - } | |
| 537 | - } | |
| 538 | - return ''; | |
| 539 | - } | |
| 540 | - | |
| 541 | - | |
| 542 | - /** | |
| 543 | - * Get the link to view the details for the primary registration. | |
| 544 | - * @param EE_Transaction $transaction | |
| 545 | - * @return string | |
| 546 | - * @throws EE_Error | |
| 547 | - */ | |
| 548 | - protected function get_primary_registration_details_link(EE_Transaction $transaction) | |
| 549 | -    { | |
| 550 | - $registration = $transaction->primary_registration(); | |
| 551 | -        if ($registration instanceof EE_Registration) { | |
| 552 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 553 | - 'action' => 'view_registration', | |
| 554 | - '_REG_ID' => $registration->ID(), | |
| 555 | - ), REG_ADMIN_URL); | |
| 556 | - return EE_Registry::instance()->CAP->current_user_can( | |
| 557 | - 'ee_read_registration', | |
| 558 | - 'espresso_registrations_view_registration', | |
| 559 | - $registration->ID() | |
| 560 | - ) | |
| 561 | - ? ' | |
| 536 | + } | |
| 537 | + } | |
| 538 | + return ''; | |
| 539 | + } | |
| 540 | + | |
| 541 | + | |
| 542 | + /** | |
| 543 | + * Get the link to view the details for the primary registration. | |
| 544 | + * @param EE_Transaction $transaction | |
| 545 | + * @return string | |
| 546 | + * @throws EE_Error | |
| 547 | + */ | |
| 548 | + protected function get_primary_registration_details_link(EE_Transaction $transaction) | |
| 549 | +	{ | |
| 550 | + $registration = $transaction->primary_registration(); | |
| 551 | +		if ($registration instanceof EE_Registration) { | |
| 552 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 553 | + 'action' => 'view_registration', | |
| 554 | + '_REG_ID' => $registration->ID(), | |
| 555 | + ), REG_ADMIN_URL); | |
| 556 | + return EE_Registry::instance()->CAP->current_user_can( | |
| 557 | + 'ee_read_registration', | |
| 558 | + 'espresso_registrations_view_registration', | |
| 559 | + $registration->ID() | |
| 560 | + ) | |
| 561 | + ? ' | |
| 562 | 562 | <li> | 
| 563 | 563 | <a href="' . $url . '"' | 
| 564 | -                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> | |
| 564 | +				  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> | |
| 565 | 565 | <span class="dashicons dashicons-clipboard"></span> | 
| 566 | 566 | </a> | 
| 567 | 567 | </li>' | 
| 568 | - : ''; | |
| 569 | - } | |
| 570 | - return ''; | |
| 571 | - } | |
| 572 | - | |
| 573 | - | |
| 574 | - /** | |
| 575 | - * Get send payment reminder trigger link | |
| 576 | - * @param EE_Transaction $transaction | |
| 577 | - * @return string | |
| 578 | - * @throws EE_Error | |
| 579 | - */ | |
| 580 | - protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) | |
| 581 | -    { | |
| 582 | - $registration = $transaction->primary_registration(); | |
| 583 | - if ($registration instanceof EE_Registration | |
| 584 | - && $registration->attendee() instanceof EE_Attendee | |
| 585 | -            && EEH_MSG_Template::is_mt_active('payment_reminder') | |
| 586 | - && ! in_array( | |
| 587 | - $transaction->status_ID(), | |
| 588 | - array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), | |
| 589 | - true | |
| 590 | - ) | |
| 591 | - && EE_Registry::instance()->CAP->current_user_can( | |
| 592 | - 'ee_send_message', | |
| 593 | - 'espresso_transactions_send_payment_reminder' | |
| 594 | - ) | |
| 595 | -        ) { | |
| 596 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 597 | - 'action' => 'send_payment_reminder', | |
| 598 | - 'TXN_ID' => $transaction->ID(), | |
| 599 | - ), TXN_ADMIN_URL); | |
| 600 | - return ' | |
| 568 | + : ''; | |
| 569 | + } | |
| 570 | + return ''; | |
| 571 | + } | |
| 572 | + | |
| 573 | + | |
| 574 | + /** | |
| 575 | + * Get send payment reminder trigger link | |
| 576 | + * @param EE_Transaction $transaction | |
| 577 | + * @return string | |
| 578 | + * @throws EE_Error | |
| 579 | + */ | |
| 580 | + protected function get_send_payment_reminder_trigger_link(EE_Transaction $transaction) | |
| 581 | +	{ | |
| 582 | + $registration = $transaction->primary_registration(); | |
| 583 | + if ($registration instanceof EE_Registration | |
| 584 | + && $registration->attendee() instanceof EE_Attendee | |
| 585 | +			&& EEH_MSG_Template::is_mt_active('payment_reminder') | |
| 586 | + && ! in_array( | |
| 587 | + $transaction->status_ID(), | |
| 588 | + array(EEM_Transaction::complete_status_code, EEM_Transaction::overpaid_status_code), | |
| 589 | + true | |
| 590 | + ) | |
| 591 | + && EE_Registry::instance()->CAP->current_user_can( | |
| 592 | + 'ee_send_message', | |
| 593 | + 'espresso_transactions_send_payment_reminder' | |
| 594 | + ) | |
| 595 | +		) { | |
| 596 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 597 | + 'action' => 'send_payment_reminder', | |
| 598 | + 'TXN_ID' => $transaction->ID(), | |
| 599 | + ), TXN_ADMIN_URL); | |
| 600 | + return ' | |
| 601 | 601 | <li> | 
| 602 | 602 | <a href="' . $url . '"' | 
| 603 | -                  . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> | |
| 603 | +				  . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> | |
| 604 | 604 | <span class="dashicons dashicons-email-alt"></span> | 
| 605 | 605 | </a> | 
| 606 | 606 | </li>'; | 
| 607 | - } | |
| 608 | - return ''; | |
| 609 | - } | |
| 610 | - | |
| 611 | - | |
| 612 | - | |
| 613 | - /** | |
| 614 | - * Get link to filtered view in the message activity list table of messages for this transaction. | |
| 615 | - * @param EE_Transaction $transaction | |
| 616 | - * @return string | |
| 617 | - * @throws EE_Error | |
| 618 | - */ | |
| 619 | - protected function get_related_messages_link(EE_Transaction $transaction) | |
| 620 | -    { | |
| 621 | - $url = EEH_MSG_Template::get_message_action_link( | |
| 622 | - 'see_notifications_for', | |
| 623 | - null, | |
| 624 | -            array('TXN_ID' => $transaction->ID()) | |
| 625 | - ); | |
| 626 | - return EE_Registry::instance()->CAP->current_user_can( | |
| 627 | - 'ee_read_global_messages', | |
| 628 | - 'view_filtered_messages' | |
| 629 | - ) | |
| 630 | - ? '<li>' . $url . '</li>' | |
| 631 | - : ''; | |
| 632 | - } | |
| 633 | - | |
| 634 | - | |
| 635 | - /** | |
| 636 | - * Return the link to make a payment on the frontend | |
| 637 | - * @param EE_Transaction $transaction | |
| 638 | - * @return string | |
| 639 | - * @throws EE_Error | |
| 640 | - */ | |
| 641 | - protected function get_payment_overview_link(EE_Transaction $transaction) | |
| 642 | -    { | |
| 643 | - $registration = $transaction->primary_registration(); | |
| 644 | - if ($registration instanceof EE_Registration | |
| 645 | - && $transaction->status_ID() !== EEM_Transaction::complete_status_code | |
| 646 | - && $registration->owes_monies_and_can_pay() | |
| 647 | -        ) { | |
| 648 | - return ' | |
| 607 | + } | |
| 608 | + return ''; | |
| 609 | + } | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + /** | |
| 614 | + * Get link to filtered view in the message activity list table of messages for this transaction. | |
| 615 | + * @param EE_Transaction $transaction | |
| 616 | + * @return string | |
| 617 | + * @throws EE_Error | |
| 618 | + */ | |
| 619 | + protected function get_related_messages_link(EE_Transaction $transaction) | |
| 620 | +	{ | |
| 621 | + $url = EEH_MSG_Template::get_message_action_link( | |
| 622 | + 'see_notifications_for', | |
| 623 | + null, | |
| 624 | +			array('TXN_ID' => $transaction->ID()) | |
| 625 | + ); | |
| 626 | + return EE_Registry::instance()->CAP->current_user_can( | |
| 627 | + 'ee_read_global_messages', | |
| 628 | + 'view_filtered_messages' | |
| 629 | + ) | |
| 630 | + ? '<li>' . $url . '</li>' | |
| 631 | + : ''; | |
| 632 | + } | |
| 633 | + | |
| 634 | + | |
| 635 | + /** | |
| 636 | + * Return the link to make a payment on the frontend | |
| 637 | + * @param EE_Transaction $transaction | |
| 638 | + * @return string | |
| 639 | + * @throws EE_Error | |
| 640 | + */ | |
| 641 | + protected function get_payment_overview_link(EE_Transaction $transaction) | |
| 642 | +	{ | |
| 643 | + $registration = $transaction->primary_registration(); | |
| 644 | + if ($registration instanceof EE_Registration | |
| 645 | + && $transaction->status_ID() !== EEM_Transaction::complete_status_code | |
| 646 | + && $registration->owes_monies_and_can_pay() | |
| 647 | +		) { | |
| 648 | + return ' | |
| 649 | 649 | <li> | 
| 650 | 650 |                  <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' | 
| 651 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' | |
| 652 | - . ' class="tiny-text"> | |
| 651 | + . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' | |
| 652 | + . ' class="tiny-text"> | |
| 653 | 653 | <span class="dashicons dashicons-money ee-icon-size-18"></span> | 
| 654 | 654 | </a> | 
| 655 | 655 | </li> | 
| 656 | 656 | '; | 
| 657 | 657 | |
| 658 | - } | |
| 659 | - return ''; | |
| 660 | - } | |
| 658 | + } | |
| 659 | + return ''; | |
| 660 | + } | |
| 661 | 661 | } | 
| @@ -48,11 +48,11 @@ discard block | ||
| 48 | 48 | 'ajax' => true, | 
| 49 | 49 | 'screen' => $this->_admin_page->get_current_screen()->id, | 
| 50 | 50 | ); | 
| 51 | -        $ID_column_name      = __('ID', 'event_espresso'); | |
| 51 | +        $ID_column_name = __('ID', 'event_espresso'); | |
| 52 | 52 | $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; | 
| 53 | 53 |          $ID_column_name      .= __('Transaction Date', 'event_espresso'); | 
| 54 | 54 | $ID_column_name .= '</span> '; | 
| 55 | - $this->_columns = array( | |
| 55 | + $this->_columns = array( | |
| 56 | 56 | 'TXN_ID' => $ID_column_name, | 
| 57 | 57 |              'TXN_timestamp' => __('Transaction Date', 'event_espresso'), | 
| 58 | 58 |              'TXN_total'     => __('Total', 'event_espresso'), | 
| @@ -87,7 +87,7 @@ discard block | ||
| 87 | 87 |      { | 
| 88 | 88 | $class = parent::_get_row_class($transaction); | 
| 89 | 89 | //add status class | 
| 90 | - $class .= ' ee-status-strip txn-status-' . $transaction->status_ID(); | |
| 90 | + $class .= ' ee-status-strip txn-status-'.$transaction->status_ID(); | |
| 91 | 91 |          if ($this->_has_checkbox_column) { | 
| 92 | 92 | $class .= ' has-checkbox-column'; | 
| 93 | 93 | } | 
| @@ -113,7 +113,7 @@ discard block | ||
| 113 | 113 | 'm/d/Y', | 
| 114 | 114 |                  strtotime('-10 year') | 
| 115 | 115 | ); | 
| 116 | - $end_date = isset($this->_req_data['txn-filter-end-date']) | |
| 116 | + $end_date = isset($this->_req_data['txn-filter-end-date']) | |
| 117 | 117 | ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) | 
| 118 | 118 | : date( | 
| 119 | 119 | 'm/d/Y', | 
| @@ -158,13 +158,13 @@ discard block | ||
| 158 | 158 | 'action' => 'view_transaction', | 
| 159 | 159 | 'TXN_ID' => $transaction->ID(), | 
| 160 | 160 | ), TXN_ADMIN_URL); | 
| 161 | - $content = '<a href="' . $view_lnk_url . '"' | |
| 162 | -                        . ' title="' . esc_attr__('Go to Transaction Details', 'event_espresso') . '">' | |
| 161 | + $content = '<a href="'.$view_lnk_url.'"' | |
| 162 | +                        . ' title="'.esc_attr__('Go to Transaction Details', 'event_espresso').'">' | |
| 163 | 163 | . $transaction->ID() | 
| 164 | 164 | . '</a>'; | 
| 165 | 165 | |
| 166 | 166 | //txn timestamp | 
| 167 | - $content .= ' <span class="show-on-mobile-view-only">' . $this->_get_txn_timestamp($transaction) . '</span>'; | |
| 167 | + $content .= ' <span class="show-on-mobile-view-only">'.$this->_get_txn_timestamp($transaction).'</span>'; | |
| 168 | 168 | return $content; | 
| 169 | 169 | } | 
| 170 | 170 | |
| @@ -221,9 +221,9 @@ discard block | ||
| 221 | 221 | 'action' => 'view_transaction', | 
| 222 | 222 | 'TXN_ID' => $transaction->ID(), | 
| 223 | 223 | ), TXN_ADMIN_URL); | 
| 224 | - $txn_date = '<a href="' . $view_lnk_url . '"' | |
| 224 | + $txn_date = '<a href="'.$view_lnk_url.'"' | |
| 225 | 225 | . ' title="' | 
| 226 | -                        . esc_attr__('View Transaction Details for TXN #', 'event_espresso') . $transaction->ID() . '">' | |
| 226 | +                        . esc_attr__('View Transaction Details for TXN #', 'event_espresso').$transaction->ID().'">' | |
| 227 | 227 | . $this->_get_txn_timestamp($transaction) | 
| 228 | 228 | . '</a>'; | 
| 229 | 229 | //status | 
| @@ -256,7 +256,7 @@ discard block | ||
| 256 | 256 | ) | 
| 257 | 257 | . '</span>'; | 
| 258 | 258 |          } else { | 
| 259 | -            return '<span class="txn-overview-free-event-spn">' . esc_html__('free', 'event_espresso') . '</span>'; | |
| 259 | +            return '<span class="txn-overview-free-event-spn">'.esc_html__('free', 'event_espresso').'</span>'; | |
| 260 | 260 | } | 
| 261 | 261 | } | 
| 262 | 262 | |
| @@ -294,7 +294,7 @@ discard block | ||
| 294 | 294 |              : esc_html__('Unknown', 'event_espresso'); | 
| 295 | 295 |          $transaction_paid_content = $transaction_paid !== 0 ? $transaction->get_pretty('TXN_paid') : $transaction_paid; | 
| 296 | 296 | |
| 297 | - $content = '<span class="' . $span_class . ' txn-pad-rght">' | |
| 297 | + $content = '<span class="'.$span_class.' txn-pad-rght">' | |
| 298 | 298 | . $transaction_paid_content | 
| 299 | 299 | . '</span>'; | 
| 300 | 300 |          if ($transaction_paid > 0) { | 
| @@ -325,17 +325,17 @@ discard block | ||
| 325 | 325 | 'action' => 'view_registration', | 
| 326 | 326 | '_REG_ID' => $primary_reg->ID(), | 
| 327 | 327 | ), REG_ADMIN_URL); | 
| 328 | - $content = EE_Registry::instance()->CAP->current_user_can( | |
| 328 | + $content = EE_Registry::instance()->CAP->current_user_can( | |
| 329 | 329 | 'ee_read_registration', | 
| 330 | 330 | 'espresso_registrations_view_registration', | 
| 331 | 331 | $primary_reg->ID() | 
| 332 | 332 | ) | 
| 333 | - ? '<a href="' . $edit_lnk_url . '"' | |
| 334 | -                    . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '">' | |
| 333 | + ? '<a href="'.$edit_lnk_url.'"' | |
| 334 | +                    . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'">' | |
| 335 | 335 | . $attendee->full_name() | 
| 336 | 336 | . '</a>' | 
| 337 | 337 | : $attendee->full_name(); | 
| 338 | - $content .= '<br>' . $attendee->email(); | |
| 338 | + $content .= '<br>'.$attendee->email(); | |
| 339 | 339 | return $content; | 
| 340 | 340 | } | 
| 341 | 341 | return $transaction->failed() || $transaction->is_abandoned() | 
| @@ -357,8 +357,8 @@ discard block | ||
| 357 | 357 | public function column_ATT_email(EE_Transaction $transaction) | 
| 358 | 358 |      { | 
| 359 | 359 |          $attendee = $transaction->primary_registration()->get_first_related('Attendee'); | 
| 360 | -        if (! empty($attendee)) { | |
| 361 | -            return '<a href="mailto:' . $attendee->get('ATT_email') . '">' | |
| 360 | +        if ( ! empty($attendee)) { | |
| 361 | +            return '<a href="mailto:'.$attendee->get('ATT_email').'">' | |
| 362 | 362 |                     . $attendee->get('ATT_email') | 
| 363 | 363 | . '</a>'; | 
| 364 | 364 |          } else { | 
| @@ -383,12 +383,12 @@ discard block | ||
| 383 | 383 |      { | 
| 384 | 384 | $actions = array(); | 
| 385 | 385 |          $event   = $transaction->primary_registration()->get_first_related('Event'); | 
| 386 | -        if (! empty($event)) { | |
| 386 | +        if ( ! empty($event)) { | |
| 387 | 387 | $edit_event_url = EE_Admin_Page::add_query_args_and_nonce( | 
| 388 | 388 |                  array('action' => 'edit', 'post' => $event->ID()), | 
| 389 | 389 | EVENTS_ADMIN_URL | 
| 390 | 390 | ); | 
| 391 | -            $event_name     = $event->get('EVT_name'); | |
| 391 | +            $event_name = $event->get('EVT_name'); | |
| 392 | 392 | |
| 393 | 393 | //filter this view by transactions for this event | 
| 394 | 394 | $txn_by_event_lnk = EE_Admin_Page::add_query_args_and_nonce(array( | 
| @@ -400,8 +400,8 @@ discard block | ||
| 400 | 400 | 'espresso_events_edit', | 
| 401 | 401 | $event->ID() | 
| 402 | 402 |              )) { | 
| 403 | - $actions['filter_by_event'] = '<a href="' . $txn_by_event_lnk . '"' | |
| 404 | -                        . ' title="' . esc_attr__('Filter transactions by this event', 'event_espresso') . '">' | |
| 403 | + $actions['filter_by_event'] = '<a href="'.$txn_by_event_lnk.'"' | |
| 404 | +                        . ' title="'.esc_attr__('Filter transactions by this event', 'event_espresso').'">' | |
| 405 | 405 |                          . esc_html__('View Transactions for this event', 'event_espresso') | 
| 406 | 406 | . '</a>'; | 
| 407 | 407 | } | 
| @@ -413,7 +413,7 @@ discard block | ||
| 413 | 413 | 'espresso_events_edit', | 
| 414 | 414 | $event->ID() | 
| 415 | 415 | ) | 
| 416 | - ? '<a href="' . $edit_event_url . '"' | |
| 416 | + ? '<a href="'.$edit_event_url.'"' | |
| 417 | 417 | . ' title="' | 
| 418 | 418 | . sprintf( | 
| 419 | 419 |                              esc_attr__('Edit Event: %s', 'event_espresso'), | 
| @@ -470,14 +470,14 @@ discard block | ||
| 470 | 470 | */ | 
| 471 | 471 | protected function get_transaction_details_link(EE_Transaction $transaction) | 
| 472 | 472 |      { | 
| 473 | - $url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 473 | + $url = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 474 | 474 | 'action' => 'view_transaction', | 
| 475 | 475 | 'TXN_ID' => $transaction->ID(), | 
| 476 | 476 | ), TXN_ADMIN_URL); | 
| 477 | 477 | return ' | 
| 478 | 478 | <li> | 
| 479 | - <a href="' . $url . '"' | |
| 480 | -                    . ' title="' . esc_attr__('View Transaction Details', 'event_espresso') . '" class="tiny-text"> | |
| 479 | + <a href="' . $url.'"' | |
| 480 | +                    . ' title="'.esc_attr__('View Transaction Details', 'event_espresso').'" class="tiny-text"> | |
| 481 | 481 | <span class="dashicons dashicons-cart"></span> | 
| 482 | 482 | </a> | 
| 483 | 483 | </li>'; | 
| @@ -501,8 +501,8 @@ discard block | ||
| 501 | 501 |              ) { | 
| 502 | 502 | return ' | 
| 503 | 503 | <li> | 
| 504 | -                    <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso') . '"' | |
| 505 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> | |
| 504 | +                    <a title="' . esc_attr__('View Transaction Invoice', 'event_espresso').'"' | |
| 505 | + . ' target="_blank" href="'.$url.'" class="tiny-text"> | |
| 506 | 506 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> | 
| 507 | 507 | </a> | 
| 508 | 508 | </li>'; | 
| @@ -528,8 +528,8 @@ discard block | ||
| 528 | 528 |                  && EEH_MSG_Template::is_mt_active('receipt')) { | 
| 529 | 529 | return ' | 
| 530 | 530 | <li> | 
| 531 | -				<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso') . '"' | |
| 532 | - . ' target="_blank" href="' . $url . '" class="tiny-text"> | |
| 531 | +				<a title="' . esc_attr__('View Transaction Receipt', 'event_espresso').'"' | |
| 532 | + . ' target="_blank" href="'.$url.'" class="tiny-text"> | |
| 533 | 533 | <span class="dashicons dashicons-media-default ee-icon-size-18"></span> | 
| 534 | 534 | </a> | 
| 535 | 535 | </li>'; | 
| @@ -560,8 +560,8 @@ discard block | ||
| 560 | 560 | ) | 
| 561 | 561 | ? ' | 
| 562 | 562 | <li> | 
| 563 | - <a href="' . $url . '"' | |
| 564 | -                  . ' title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> | |
| 563 | + <a href="' . $url.'"' | |
| 564 | +                  . ' title="'.esc_attr__('View Registration Details', 'event_espresso').'" class="tiny-text"> | |
| 565 | 565 | <span class="dashicons dashicons-clipboard"></span> | 
| 566 | 566 | </a> | 
| 567 | 567 | </li>' | 
| @@ -599,8 +599,8 @@ discard block | ||
| 599 | 599 | ), TXN_ADMIN_URL); | 
| 600 | 600 | return ' | 
| 601 | 601 | <li> | 
| 602 | - <a href="' . $url . '"' | |
| 603 | -                  . ' title="' . esc_attr__('Send Payment Reminder', 'event_espresso') . '" class="tiny-text"> | |
| 602 | + <a href="' . $url.'"' | |
| 603 | +                  . ' title="'.esc_attr__('Send Payment Reminder', 'event_espresso').'" class="tiny-text"> | |
| 604 | 604 | <span class="dashicons dashicons-email-alt"></span> | 
| 605 | 605 | </a> | 
| 606 | 606 | </li>'; | 
| @@ -627,7 +627,7 @@ discard block | ||
| 627 | 627 | 'ee_read_global_messages', | 
| 628 | 628 | 'view_filtered_messages' | 
| 629 | 629 | ) | 
| 630 | - ? '<li>' . $url . '</li>' | |
| 630 | + ? '<li>'.$url.'</li>' | |
| 631 | 631 | : ''; | 
| 632 | 632 | } | 
| 633 | 633 | |
| @@ -647,8 +647,8 @@ discard block | ||
| 647 | 647 |          ) { | 
| 648 | 648 | return ' | 
| 649 | 649 | <li> | 
| 650 | -                <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso') . '"' | |
| 651 | - . ' target="_blank" href="' . $registration->payment_overview_url(true) . '"' | |
| 650 | +                <a title="' . esc_attr__('Make Payment from the Frontend.', 'event_espresso').'"' | |
| 651 | + . ' target="_blank" href="'.$registration->payment_overview_url(true).'"' | |
| 652 | 652 | . ' class="tiny-text"> | 
| 653 | 653 | <span class="dashicons dashicons-money ee-icon-size-18"></span> | 
| 654 | 654 | </a> | 
| @@ -1159,7 +1159,7 @@ discard block | ||
| 1159 | 1159 | * Sets deleted | 
| 1160 | 1160 | * | 
| 1161 | 1161 | * @param boolean $deleted | 
| 1162 | - * @return bool | |
| 1162 | + * @return boolean|null | |
| 1163 | 1163 | * @throws EE_Error | 
| 1164 | 1164 | * @throws RuntimeException | 
| 1165 | 1165 | */ | 
| @@ -1217,6 +1217,7 @@ discard block | ||
| 1217 | 1217 | * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against | 
| 1218 | 1218 | * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also | 
| 1219 | 1219 | * consider registration status as well as datetime access. | 
| 1220 | + * @param integer $DTT_OR_ID | |
| 1220 | 1221 | * @return bool | 
| 1221 | 1222 | * @throws EE_Error | 
| 1222 | 1223 | */ | 
| @@ -1387,7 +1388,7 @@ discard block | ||
| 1387 | 1388 | * Returns the latest datetime related to this registration (via the ticket attached to the registration). | 
| 1388 | 1389 | * "Latest" is defined by the `DTT_EVT_start` column. | 
| 1389 | 1390 | * | 
| 1390 | - * @return EE_Datetime|null | |
| 1391 | + * @return null|EE_Base_Class | |
| 1391 | 1392 | * @throws \EE_Error | 
| 1392 | 1393 | */ | 
| 1393 | 1394 | public function get_latest_related_datetime() | 
| @@ -1680,7 +1681,7 @@ discard block | ||
| 1680 | 1681 | * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. | 
| 1681 | 1682 | * Note: if there are no payments on the registration there will be no payment method returned. | 
| 1682 | 1683 | * | 
| 1683 | - * @return EE_Payment_Method|null | |
| 1684 | + * @return null|EE_Base_Class | |
| 1684 | 1685 | */ | 
| 1685 | 1686 | public function payment_method() | 
| 1686 | 1687 |      { | 
| @@ -109,7 +109,7 @@ discard block | ||
| 109 | 109 |      { | 
| 110 | 110 |          switch ($field_name) { | 
| 111 | 111 | case 'REG_code': | 
| 112 | -                if (! empty($field_value) && $this->reg_code() === null) { | |
| 112 | +                if ( ! empty($field_value) && $this->reg_code() === null) { | |
| 113 | 113 | $this->set_reg_code($field_value, $use_default); | 
| 114 | 114 | } | 
| 115 | 115 | break; | 
| @@ -284,7 +284,7 @@ discard block | ||
| 284 | 284 | public function event() | 
| 285 | 285 |      { | 
| 286 | 286 |          $event = $this->get_first_related('Event'); | 
| 287 | -        if (! $event instanceof \EE_Event) { | |
| 287 | +        if ( ! $event instanceof \EE_Event) { | |
| 288 | 288 |              throw new EntityNotFoundException('Event ID', $this->event_ID()); | 
| 289 | 289 | } | 
| 290 | 290 | return $event; | 
| @@ -973,7 +973,7 @@ discard block | ||
| 973 | 973 | false, | 
| 974 | 974 | 'sentence' | 
| 975 | 975 | ); | 
| 976 | - $icon = ''; | |
| 976 | + $icon = ''; | |
| 977 | 977 |          switch ($this->status_ID()) { | 
| 978 | 978 | case EEM_Registration::status_id_approved: | 
| 979 | 979 | $icon = $show_icons | 
| @@ -1011,7 +1011,7 @@ discard block | ||
| 1011 | 1011 | : ''; | 
| 1012 | 1012 | break; | 
| 1013 | 1013 | } | 
| 1014 | - return $icon . $status[$this->status_ID()]; | |
| 1014 | + return $icon.$status[$this->status_ID()]; | |
| 1015 | 1015 | } | 
| 1016 | 1016 | |
| 1017 | 1017 | |
| @@ -1229,7 +1229,7 @@ discard block | ||
| 1229 | 1229 | return false; | 
| 1230 | 1230 | } | 
| 1231 | 1231 | //is there a datetime ticket that matches this dtt_ID? | 
| 1232 | - if (! (EEM_Datetime_Ticket::instance()->exists(array( | |
| 1232 | + if ( ! (EEM_Datetime_Ticket::instance()->exists(array( | |
| 1233 | 1233 | array( | 
| 1234 | 1234 |                  'TKT_ID' => $this->get('TKT_ID'), | 
| 1235 | 1235 | 'DTT_ID' => $DTT_ID, | 
| @@ -1258,7 +1258,7 @@ discard block | ||
| 1258 | 1258 |      { | 
| 1259 | 1259 | $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); | 
| 1260 | 1260 | |
| 1261 | -        if (! $DTT_ID) { | |
| 1261 | +        if ( ! $DTT_ID) { | |
| 1262 | 1262 | return false; | 
| 1263 | 1263 | } | 
| 1264 | 1264 | |
| @@ -1266,7 +1266,7 @@ discard block | ||
| 1266 | 1266 | |
| 1267 | 1267 | // if max uses is not set or equals infinity then return true cause its not a factor for whether user can | 
| 1268 | 1268 | // check-in or not. | 
| 1269 | -        if (! $max_uses || $max_uses === EE_INF) { | |
| 1269 | +        if ( ! $max_uses || $max_uses === EE_INF) { | |
| 1270 | 1270 | return true; | 
| 1271 | 1271 | } | 
| 1272 | 1272 | |
| @@ -1322,7 +1322,7 @@ discard block | ||
| 1322 | 1322 | $datetime = $this->get_latest_related_datetime(); | 
| 1323 | 1323 | $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; | 
| 1324 | 1324 | // verify the registration can checkin for the given DTT_ID | 
| 1325 | -        } elseif (! $this->can_checkin($DTT_ID, $verify)) { | |
| 1325 | +        } elseif ( ! $this->can_checkin($DTT_ID, $verify)) { | |
| 1326 | 1326 | EE_Error::add_error( | 
| 1327 | 1327 | sprintf( | 
| 1328 | 1328 | esc_html__( | 
| @@ -1505,7 +1505,7 @@ discard block | ||
| 1505 | 1505 | public function transaction() | 
| 1506 | 1506 |      { | 
| 1507 | 1507 |          $transaction = $this->get_first_related('Transaction'); | 
| 1508 | -        if (! $transaction instanceof \EE_Transaction) { | |
| 1508 | +        if ( ! $transaction instanceof \EE_Transaction) { | |
| 1509 | 1509 |              throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); | 
| 1510 | 1510 | } | 
| 1511 | 1511 | return $transaction; | 
| @@ -1559,11 +1559,11 @@ discard block | ||
| 1559 | 1559 | ); | 
| 1560 | 1560 | return; | 
| 1561 | 1561 | } | 
| 1562 | -        if (! $this->reg_code()) { | |
| 1562 | +        if ( ! $this->reg_code()) { | |
| 1563 | 1563 |              parent::set('REG_code', $REG_code, $use_default); | 
| 1564 | 1564 |          } else { | 
| 1565 | 1565 | EE_Error::doing_it_wrong( | 
| 1566 | - __CLASS__ . '::' . __FUNCTION__, | |
| 1566 | + __CLASS__.'::'.__FUNCTION__, | |
| 1567 | 1567 |                  esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), | 
| 1568 | 1568 | '4.6.0' | 
| 1569 | 1569 | ); | 
| @@ -1713,7 +1713,7 @@ discard block | ||
| 1713 | 1713 | break; | 
| 1714 | 1714 | } | 
| 1715 | 1715 | } | 
| 1716 | -        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { | |
| 1716 | +        if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { | |
| 1717 | 1717 |              throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); | 
| 1718 | 1718 | } | 
| 1719 | 1719 | return $line_item; | 
| @@ -15,1792 +15,1792 @@ | ||
| 15 | 15 |  { | 
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** | |
| 19 | - * Used to reference when a registration has never been checked in. | |
| 20 | - * | |
| 21 | - * @type int | |
| 22 | - */ | |
| 23 | - const checkin_status_never = 2; | |
| 24 | - | |
| 25 | - /** | |
| 26 | - * Used to reference when a registration has been checked in. | |
| 27 | - * | |
| 28 | - * @type int | |
| 29 | - */ | |
| 30 | - const checkin_status_in = 1; | |
| 31 | - | |
| 32 | - | |
| 33 | - /** | |
| 34 | - * Used to reference when a registration has been checked out. | |
| 35 | - * | |
| 36 | - * @type int | |
| 37 | - */ | |
| 38 | - const checkin_status_out = 0; | |
| 39 | - | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * extra meta key for tracking reg status os trashed registrations | |
| 43 | - * | |
| 44 | - * @type string | |
| 45 | - */ | |
| 46 | - const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; | |
| 47 | - | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * extra meta key for tracking if registration has reserved ticket | |
| 51 | - * | |
| 52 | - * @type string | |
| 53 | - */ | |
| 54 | - const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; | |
| 55 | - | |
| 56 | - | |
| 57 | - | |
| 58 | - /** | |
| 59 | - * Set Event ID | |
| 60 | - * | |
| 61 | - * @param int $EVT_ID Event ID | |
| 62 | - * @throws EE_Error | |
| 63 | - * @throws RuntimeException | |
| 64 | - */ | |
| 65 | - public function set_event($EVT_ID = 0) | |
| 66 | -    { | |
| 67 | -        $this->set('EVT_ID', $EVT_ID); | |
| 68 | - } | |
| 69 | - | |
| 70 | - | |
| 71 | - | |
| 72 | - /** | |
| 73 | - * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can | |
| 74 | - * be routed to internal methods | |
| 75 | - * | |
| 76 | - * @param string $field_name | |
| 77 | - * @param mixed $field_value | |
| 78 | - * @param bool $use_default | |
| 79 | - * @throws \EE_Error | |
| 80 | - * @throws \RuntimeException | |
| 81 | - */ | |
| 82 | - public function set($field_name, $field_value, $use_default = false) | |
| 83 | -    { | |
| 84 | -        switch ($field_name) { | |
| 85 | - case 'REG_code': | |
| 86 | -                if (! empty($field_value) && $this->reg_code() === null) { | |
| 87 | - $this->set_reg_code($field_value, $use_default); | |
| 88 | - } | |
| 89 | - break; | |
| 90 | - case 'STS_ID': | |
| 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 ID | |
| 101 | - * updates the registration status and ALSO... | |
| 102 | - * calls reserve_registration_space() if the reg status changes TO approved from any other reg status | |
| 103 | - * calls release_registration_space() if the reg status changes FROM approved to any other reg status | |
| 104 | - * | |
| 105 | - * @param string $new_STS_ID | |
| 106 | - * @param boolean $use_default | |
| 107 | - * @return bool | |
| 108 | - * @throws \RuntimeException | |
| 109 | - * @throws \EE_Error | |
| 110 | - */ | |
| 111 | - public function set_status($new_STS_ID = null, $use_default = false) | |
| 112 | -    { | |
| 113 | - // get current REG_Status | |
| 114 | - $old_STS_ID = $this->status_ID(); | |
| 115 | - // if status has changed | |
| 116 | - if ($old_STS_ID !== $new_STS_ID // and that status has actually changed | |
| 117 | - && ! empty($old_STS_ID) // and that old status is actually set | |
| 118 | - && ! empty($new_STS_ID) // as well as the new status | |
| 119 | - && $this->ID() // ensure registration is in the db | |
| 120 | -        ) { | |
| 121 | - // TO approved | |
| 122 | -            if ($new_STS_ID === EEM_Registration::status_id_approved) { | |
| 123 | - // reserve a space by incrementing ticket and datetime sold values | |
| 124 | - $this->_reserve_registration_space(); | |
| 125 | -                do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID); | |
| 126 | - // OR FROM approved | |
| 127 | -            } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { | |
| 128 | - // release a space by decrementing ticket and datetime sold values | |
| 129 | - $this->_release_registration_space(); | |
| 130 | -                do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID); | |
| 131 | - } | |
| 132 | - // update status | |
| 133 | -            parent::set('STS_ID', $new_STS_ID, $use_default); | |
| 134 | - $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID); | |
| 135 | - /** @type EE_Transaction_Payments $transaction_payments */ | |
| 136 | -            $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); | |
| 137 | - $transaction_payments->recalculate_transaction_total($this->transaction(), false); | |
| 138 | - $this->transaction()->update_status_based_on_total_paid(true); | |
| 139 | -            do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID); | |
| 140 | - return true; | |
| 141 | - } | |
| 142 | - //even though the old value matches the new value, it's still good to | |
| 143 | - //allow the parent set method to have a say | |
| 144 | -        parent::set('STS_ID', $new_STS_ID, $use_default); | |
| 145 | - return true; | |
| 146 | - } | |
| 147 | - | |
| 148 | - | |
| 149 | - /** | |
| 150 | - * update REGs and TXN when cancelled or declined registrations involved | |
| 151 | - * | |
| 152 | - * @param string $new_STS_ID | |
| 153 | - * @param string $old_STS_ID | |
| 154 | - * @throws \EE_Error | |
| 155 | - */ | |
| 156 | - private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID) | |
| 157 | -    { | |
| 158 | - // these reg statuses should not be considered in any calculations involving monies owing | |
| 159 | - $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); | |
| 160 | - // true if registration has been cancelled or declined | |
| 161 | - if (in_array($new_STS_ID, $closed_reg_statuses, true) | |
| 162 | - && ! in_array($old_STS_ID, $closed_reg_statuses, true) | |
| 163 | -        ) { | |
| 164 | - /** @type EE_Registration_Processor $registration_processor */ | |
| 165 | -            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); | |
| 166 | - /** @type EE_Transaction_Processor $transaction_processor */ | |
| 167 | -            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); | |
| 168 | - // cancelled or declined registration | |
| 169 | - $registration_processor->update_registration_after_being_canceled_or_declined( | |
| 170 | - $this, | |
| 171 | - $closed_reg_statuses | |
| 172 | - ); | |
| 173 | - $transaction_processor->update_transaction_after_canceled_or_declined_registration( | |
| 174 | - $this, | |
| 175 | - $closed_reg_statuses, | |
| 176 | - false | |
| 177 | - ); | |
| 178 | -            do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID); | |
| 179 | - return; | |
| 180 | - } | |
| 181 | - // true if reinstating cancelled or declined registration | |
| 182 | - if (in_array($old_STS_ID, $closed_reg_statuses, true) | |
| 183 | - && ! in_array($new_STS_ID, $closed_reg_statuses, true) | |
| 184 | -        ) { | |
| 185 | - /** @type EE_Registration_Processor $registration_processor */ | |
| 186 | -            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); | |
| 187 | - /** @type EE_Transaction_Processor $transaction_processor */ | |
| 188 | -            $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); | |
| 189 | - // reinstating cancelled or declined registration | |
| 190 | - $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( | |
| 191 | - $this, | |
| 192 | - $closed_reg_statuses | |
| 193 | - ); | |
| 194 | - $transaction_processor->update_transaction_after_reinstating_canceled_registration( | |
| 195 | - $this, | |
| 196 | - $closed_reg_statuses, | |
| 197 | - false | |
| 198 | - ); | |
| 199 | -            do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID); | |
| 200 | - } | |
| 201 | - } | |
| 202 | - | |
| 203 | - | |
| 204 | - /** | |
| 205 | - * get Status ID | |
| 206 | - */ | |
| 207 | - public function status_ID() | |
| 208 | -    { | |
| 209 | -        return $this->get('STS_ID'); | |
| 210 | - } | |
| 211 | - | |
| 212 | - | |
| 213 | - /** | |
| 214 | - * increments this registration's related ticket sold and corresponding datetime sold values | |
| 215 | - * | |
| 216 | - * @return void | |
| 217 | - * @throws EE_Error | |
| 218 | - * @throws EntityNotFoundException | |
| 219 | - */ | |
| 220 | - private function _reserve_registration_space() | |
| 221 | -    { | |
| 222 | - // reserved ticket and datetime counts will be decremented as sold counts are incremented | |
| 223 | - // so stop tracking that this reg has a ticket reserved | |
| 224 | - $this->release_reserved_ticket(); | |
| 225 | - $ticket = $this->ticket(); | |
| 226 | - $ticket->increase_sold(); | |
| 227 | - $ticket->save(); | |
| 228 | - // possibly set event status to sold out | |
| 229 | - $this->event()->perform_sold_out_status_check(); | |
| 230 | - } | |
| 231 | - | |
| 232 | - | |
| 233 | - /** | |
| 234 | - * Gets the ticket this registration is for | |
| 235 | - * | |
| 236 | - * @param boolean $include_archived whether to include archived tickets or not. | |
| 237 | - * @return EE_Ticket|EE_Base_Class | |
| 238 | - * @throws \EE_Error | |
| 239 | - */ | |
| 240 | - public function ticket($include_archived = true) | |
| 241 | -    { | |
| 242 | - $query_params = array(); | |
| 243 | -        if ($include_archived) { | |
| 244 | - $query_params['default_where_conditions'] = 'none'; | |
| 245 | - } | |
| 246 | -        return $this->get_first_related('Ticket', $query_params); | |
| 247 | - } | |
| 248 | - | |
| 249 | - | |
| 250 | - /** | |
| 251 | - * Gets the event this registration is for | |
| 252 | - * | |
| 253 | - * @return EE_Event | |
| 254 | - * @throws EE_Error | |
| 255 | - * @throws EntityNotFoundException | |
| 256 | - */ | |
| 257 | - public function event() | |
| 258 | -    { | |
| 259 | -        $event = $this->get_first_related('Event'); | |
| 260 | -        if (! $event instanceof \EE_Event) { | |
| 261 | -            throw new EntityNotFoundException('Event ID', $this->event_ID()); | |
| 262 | - } | |
| 263 | - return $event; | |
| 264 | - } | |
| 265 | - | |
| 266 | - | |
| 267 | - /** | |
| 268 | - * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond | |
| 269 | - * with the author of the event this registration is for. | |
| 270 | - * | |
| 271 | - * @since 4.5.0 | |
| 272 | - * @return int | |
| 273 | - * @throws EE_Error | |
| 274 | - * @throws EntityNotFoundException | |
| 275 | - */ | |
| 276 | - public function wp_user() | |
| 277 | -    { | |
| 278 | - $event = $this->event(); | |
| 279 | -        if ($event instanceof EE_Event) { | |
| 280 | - return $event->wp_user(); | |
| 281 | - } | |
| 282 | - return 0; | |
| 283 | - } | |
| 284 | - | |
| 285 | - | |
| 286 | - /** | |
| 287 | - * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values | |
| 288 | - * | |
| 289 | - * @return void | |
| 290 | - * @throws \EE_Error | |
| 291 | - */ | |
| 292 | - private function _release_registration_space() | |
| 293 | -    { | |
| 294 | - $ticket = $this->ticket(); | |
| 295 | - $ticket->decrease_sold(); | |
| 296 | - $ticket->save(); | |
| 297 | - } | |
| 298 | - | |
| 299 | - | |
| 300 | - /** | |
| 301 | - * tracks this registration's ticket reservation in extra meta | |
| 302 | - * and can increment related ticket reserved and corresponding datetime reserved values | |
| 303 | - * | |
| 304 | - * @param bool $update_ticket if true, will increment ticket and datetime reserved count | |
| 305 | - * @return void | |
| 306 | - * @throws \EE_Error | |
| 307 | - */ | |
| 308 | - public function reserve_ticket($update_ticket = false) | |
| 309 | -    { | |
| 310 | -        if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) { | |
| 311 | - // PLZ NOTE: although checking $update_ticket first would be more efficient, | |
| 312 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first | |
| 313 | -            if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) { | |
| 314 | - $ticket = $this->ticket(); | |
| 315 | - $ticket->increase_reserved(); | |
| 316 | - $ticket->save(); | |
| 317 | - } | |
| 318 | - } | |
| 319 | - } | |
| 320 | - | |
| 321 | - | |
| 322 | - /** | |
| 323 | - * stops tracking this registration's ticket reservation in extra meta | |
| 324 | - * decrements (subtracts) related ticket reserved and corresponding datetime reserved values | |
| 325 | - * | |
| 326 | - * @param bool $update_ticket if true, will decrement ticket and datetime reserved count | |
| 327 | - * @return void | |
| 328 | - * @throws \EE_Error | |
| 329 | - */ | |
| 330 | - public function release_reserved_ticket($update_ticket = false) | |
| 331 | -    { | |
| 332 | -        if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) { | |
| 333 | - // PLZ NOTE: although checking $update_ticket first would be more efficient, | |
| 334 | - // we NEED to ALWAYS call delete_extra_meta(), which is why that is done first | |
| 335 | -            if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) { | |
| 336 | - $ticket = $this->ticket(); | |
| 337 | - $ticket->decrease_reserved(); | |
| 338 | - $ticket->save(); | |
| 339 | - } | |
| 340 | - } | |
| 341 | - } | |
| 342 | - | |
| 343 | - | |
| 344 | - /** | |
| 345 | - * Set Attendee ID | |
| 346 | - * | |
| 347 | - * @param int $ATT_ID Attendee ID | |
| 348 | - * @throws EE_Error | |
| 349 | - * @throws RuntimeException | |
| 350 | - */ | |
| 351 | - public function set_attendee_id($ATT_ID = 0) | |
| 352 | -    { | |
| 353 | -        $this->set('ATT_ID', $ATT_ID); | |
| 354 | - } | |
| 355 | - | |
| 356 | - | |
| 357 | - /** | |
| 358 | - * Set Transaction ID | |
| 359 | - * | |
| 360 | - * @param int $TXN_ID Transaction ID | |
| 361 | - * @throws EE_Error | |
| 362 | - * @throws RuntimeException | |
| 363 | - */ | |
| 364 | - public function set_transaction_id($TXN_ID = 0) | |
| 365 | -    { | |
| 366 | -        $this->set('TXN_ID', $TXN_ID); | |
| 367 | - } | |
| 368 | - | |
| 369 | - | |
| 370 | - /** | |
| 371 | - * Set Session | |
| 372 | - * | |
| 373 | - * @param string $REG_session PHP Session ID | |
| 374 | - * @throws EE_Error | |
| 375 | - * @throws RuntimeException | |
| 376 | - */ | |
| 377 | - public function set_session($REG_session = '') | |
| 378 | -    { | |
| 379 | -        $this->set('REG_session', $REG_session); | |
| 380 | - } | |
| 381 | - | |
| 382 | - | |
| 383 | - /** | |
| 384 | - * Set Registration URL Link | |
| 385 | - * | |
| 386 | - * @param string $REG_url_link Registration URL Link | |
| 387 | - * @throws EE_Error | |
| 388 | - * @throws RuntimeException | |
| 389 | - */ | |
| 390 | - public function set_reg_url_link($REG_url_link = '') | |
| 391 | -    { | |
| 392 | -        $this->set('REG_url_link', $REG_url_link); | |
| 393 | - } | |
| 394 | - | |
| 395 | - | |
| 396 | - /** | |
| 397 | - * Set Attendee Counter | |
| 398 | - * | |
| 399 | - * @param int $REG_count Primary Attendee | |
| 400 | - * @throws EE_Error | |
| 401 | - * @throws RuntimeException | |
| 402 | - */ | |
| 403 | - public function set_count($REG_count = 1) | |
| 404 | -    { | |
| 405 | -        $this->set('REG_count', $REG_count); | |
| 406 | - } | |
| 407 | - | |
| 408 | - | |
| 409 | - /** | |
| 410 | - * Set Group Size | |
| 411 | - * | |
| 412 | - * @param boolean $REG_group_size Group Registration | |
| 413 | - * @throws EE_Error | |
| 414 | - * @throws RuntimeException | |
| 415 | - */ | |
| 416 | - public function set_group_size($REG_group_size = false) | |
| 417 | -    { | |
| 418 | -        $this->set('REG_group_size', $REG_group_size); | |
| 419 | - } | |
| 420 | - | |
| 421 | - | |
| 422 | - /** | |
| 423 | - * is_not_approved - convenience method that returns TRUE if REG status ID == | |
| 424 | - * EEM_Registration::status_id_not_approved | |
| 425 | - * | |
| 426 | - * @return boolean | |
| 427 | - */ | |
| 428 | - public function is_not_approved() | |
| 429 | -    { | |
| 430 | - return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; | |
| 431 | - } | |
| 432 | - | |
| 433 | - | |
| 434 | - /** | |
| 435 | - * is_pending_payment - convenience method that returns TRUE if REG status ID == | |
| 436 | - * EEM_Registration::status_id_pending_payment | |
| 437 | - * | |
| 438 | - * @return boolean | |
| 439 | - */ | |
| 440 | - public function is_pending_payment() | |
| 441 | -    { | |
| 442 | - return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; | |
| 443 | - } | |
| 444 | - | |
| 445 | - | |
| 446 | - /** | |
| 447 | - * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved | |
| 448 | - * | |
| 449 | - * @return boolean | |
| 450 | - */ | |
| 451 | - public function is_approved() | |
| 452 | -    { | |
| 453 | - return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; | |
| 454 | - } | |
| 455 | - | |
| 456 | - | |
| 457 | - /** | |
| 458 | - * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled | |
| 459 | - * | |
| 460 | - * @return boolean | |
| 461 | - */ | |
| 462 | - public function is_cancelled() | |
| 463 | -    { | |
| 464 | - return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; | |
| 465 | - } | |
| 466 | - | |
| 467 | - | |
| 468 | - /** | |
| 469 | - * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined | |
| 470 | - * | |
| 471 | - * @return boolean | |
| 472 | - */ | |
| 473 | - public function is_declined() | |
| 474 | -    { | |
| 475 | - return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; | |
| 476 | - } | |
| 477 | - | |
| 478 | - | |
| 479 | - /** | |
| 480 | - * is_incomplete - convenience method that returns TRUE if REG status ID == | |
| 481 | - * EEM_Registration::status_id_incomplete | |
| 482 | - * | |
| 483 | - * @return boolean | |
| 484 | - */ | |
| 485 | - public function is_incomplete() | |
| 486 | -    { | |
| 487 | - return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; | |
| 488 | - } | |
| 489 | - | |
| 490 | - | |
| 491 | - /** | |
| 492 | - * Set Registration Date | |
| 493 | - * | |
| 494 | - * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of | |
| 495 | - * Date | |
| 496 | - * @throws EE_Error | |
| 497 | - * @throws RuntimeException | |
| 498 | - */ | |
| 499 | - public function set_reg_date($REG_date = false) | |
| 500 | -    { | |
| 501 | -        $this->set('REG_date', $REG_date); | |
| 502 | - } | |
| 503 | - | |
| 504 | - | |
| 505 | - /** | |
| 506 | - * Set final price owing for this registration after all ticket/price modifications | |
| 507 | - * | |
| 508 | - * @access public | |
| 509 | - * @param float $REG_final_price | |
| 510 | - * @throws EE_Error | |
| 511 | - * @throws RuntimeException | |
| 512 | - */ | |
| 513 | - public function set_final_price($REG_final_price = 0.00) | |
| 514 | -    { | |
| 515 | -        $this->set('REG_final_price', $REG_final_price); | |
| 516 | - } | |
| 517 | - | |
| 518 | - | |
| 519 | - /** | |
| 520 | - * Set amount paid towards this registration's final price | |
| 521 | - * | |
| 522 | - * @access public | |
| 523 | - * @param float $REG_paid | |
| 524 | - * @throws EE_Error | |
| 525 | - * @throws RuntimeException | |
| 526 | - */ | |
| 527 | - public function set_paid($REG_paid = 0.00) | |
| 528 | -    { | |
| 529 | -        $this->set('REG_paid', $REG_paid); | |
| 530 | - } | |
| 531 | - | |
| 532 | - | |
| 533 | - /** | |
| 534 | - * Attendee Is Going | |
| 535 | - * | |
| 536 | - * @param boolean $REG_att_is_going Attendee Is Going | |
| 537 | - * @throws EE_Error | |
| 538 | - * @throws RuntimeException | |
| 539 | - */ | |
| 540 | - public function set_att_is_going($REG_att_is_going = false) | |
| 541 | -    { | |
| 542 | -        $this->set('REG_att_is_going', $REG_att_is_going); | |
| 543 | - } | |
| 544 | - | |
| 545 | - | |
| 546 | - /** | |
| 547 | - * Gets the related attendee | |
| 548 | - * | |
| 549 | - * @return EE_Attendee | |
| 550 | - * @throws EE_Error | |
| 551 | - */ | |
| 552 | - public function attendee() | |
| 553 | -    { | |
| 554 | -        return $this->get_first_related('Attendee'); | |
| 555 | - } | |
| 556 | - | |
| 557 | - | |
| 558 | - /** | |
| 559 | - * get Event ID | |
| 560 | - */ | |
| 561 | - public function event_ID() | |
| 562 | -    { | |
| 563 | -        return $this->get('EVT_ID'); | |
| 564 | - } | |
| 565 | - | |
| 566 | - | |
| 567 | - /** | |
| 568 | - * get Event ID | |
| 569 | - */ | |
| 570 | - public function event_name() | |
| 571 | -    { | |
| 572 | - $event = $this->event_obj(); | |
| 573 | -        if ($event) { | |
| 574 | - return $event->name(); | |
| 575 | -        } else { | |
| 576 | - return null; | |
| 577 | - } | |
| 578 | - } | |
| 579 | - | |
| 580 | - | |
| 581 | - /** | |
| 582 | - * Fetches the event this registration is for | |
| 583 | - * | |
| 584 | - * @return EE_Event | |
| 585 | - * @throws EE_Error | |
| 586 | - */ | |
| 587 | - public function event_obj() | |
| 588 | -    { | |
| 589 | -        return $this->get_first_related('Event'); | |
| 590 | - } | |
| 591 | - | |
| 592 | - | |
| 593 | - /** | |
| 594 | - * get Attendee ID | |
| 595 | - */ | |
| 596 | - public function attendee_ID() | |
| 597 | -    { | |
| 598 | -        return $this->get('ATT_ID'); | |
| 599 | - } | |
| 600 | - | |
| 601 | - | |
| 602 | - /** | |
| 603 | - * get PHP Session ID | |
| 604 | - */ | |
| 605 | - public function session_ID() | |
| 606 | -    { | |
| 607 | -        return $this->get('REG_session'); | |
| 608 | - } | |
| 609 | - | |
| 610 | - | |
| 611 | - /** | |
| 612 | - * Gets the string which represents the URL trigger for the receipt template in the message template system. | |
| 613 | - * | |
| 614 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. | |
| 615 | - * @return string | |
| 616 | - */ | |
| 617 | - public function receipt_url($messenger = 'html') | |
| 618 | -    { | |
| 619 | - | |
| 620 | - /** | |
| 621 | - * The below will be deprecated one version after this. We check first if there is a custom receipt template | |
| 622 | - * already in use on old system. If there is then we just return the standard url for it. | |
| 623 | - * | |
| 624 | - * @since 4.5.0 | |
| 625 | - */ | |
| 626 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; | |
| 627 | - $has_custom = EEH_Template::locate_template( | |
| 628 | - $template_relative_path, | |
| 629 | - array(), | |
| 630 | - true, | |
| 631 | - true, | |
| 632 | - true | |
| 633 | - ); | |
| 634 | - | |
| 635 | -        if ($has_custom) { | |
| 636 | -            return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); | |
| 637 | - } | |
| 638 | -        return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); | |
| 639 | - } | |
| 640 | - | |
| 641 | - | |
| 642 | - /** | |
| 643 | - * Gets the string which represents the URL trigger for the invoice template in the message template system. | |
| 644 | - * | |
| 645 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. | |
| 646 | - * @return string | |
| 647 | - * @throws EE_Error | |
| 648 | - */ | |
| 649 | - public function invoice_url($messenger = 'html') | |
| 650 | -    { | |
| 651 | - /** | |
| 652 | - * The below will be deprecated one version after this. We check first if there is a custom invoice template | |
| 653 | - * already in use on old system. If there is then we just return the standard url for it. | |
| 654 | - * | |
| 655 | - * @since 4.5.0 | |
| 656 | - */ | |
| 657 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; | |
| 658 | - $has_custom = EEH_Template::locate_template( | |
| 659 | - $template_relative_path, | |
| 660 | - array(), | |
| 661 | - true, | |
| 662 | - true, | |
| 663 | - true | |
| 664 | - ); | |
| 665 | - | |
| 666 | -        if ($has_custom) { | |
| 667 | -            if ($messenger == 'html') { | |
| 668 | -                return $this->invoice_url('launch'); | |
| 669 | - } | |
| 670 | - $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; | |
| 671 | - | |
| 672 | -            $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); | |
| 673 | -            if ($messenger == 'html') { | |
| 674 | - $query_args['html'] = true; | |
| 675 | - } | |
| 676 | - return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); | |
| 677 | - } | |
| 678 | -        return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); | |
| 679 | - } | |
| 680 | - | |
| 681 | - | |
| 682 | - /** | |
| 683 | - * get Registration URL Link | |
| 684 | - * | |
| 685 | - * @access public | |
| 686 | - * @return string | |
| 687 | - * @throws \EE_Error | |
| 688 | - */ | |
| 689 | - public function reg_url_link() | |
| 690 | -    { | |
| 691 | -        return (string) $this->get('REG_url_link'); | |
| 692 | - } | |
| 693 | - | |
| 694 | - | |
| 695 | - /** | |
| 696 | - * Echoes out invoice_url() | |
| 697 | - * | |
| 698 | - * @param string $type 'download','launch', or 'html' (default is 'launch') | |
| 699 | - * @return void | |
| 700 | - * @throws EE_Error | |
| 701 | - */ | |
| 702 | - public function e_invoice_url($type = 'launch') | |
| 703 | -    { | |
| 704 | - echo $this->invoice_url($type); | |
| 705 | - } | |
| 706 | - | |
| 707 | - | |
| 708 | - /** | |
| 709 | - * Echoes out payment_overview_url | |
| 710 | - */ | |
| 711 | - public function e_payment_overview_url() | |
| 712 | -    { | |
| 713 | - echo $this->payment_overview_url(); | |
| 714 | - } | |
| 715 | - | |
| 716 | - | |
| 717 | - /** | |
| 718 | - * Gets the URL of the thank you page with this registration REG_url_link added as | |
| 719 | - * a query parameter | |
| 720 | - * | |
| 721 | - * @param bool $clear_session Set to true when you want to clear the session on revisiting the | |
| 722 | - * payment overview url. | |
| 723 | - * @return string | |
| 724 | - * @throws EE_Error | |
| 725 | - */ | |
| 726 | - public function payment_overview_url($clear_session = false) | |
| 727 | -    { | |
| 728 | - return add_query_arg(array( | |
| 729 | - 'e_reg_url_link' => $this->reg_url_link(), | |
| 730 | - 'step' => 'payment_options', | |
| 731 | - 'revisit' => true, | |
| 732 | - 'clear_session' => (bool) $clear_session | |
| 733 | - ), EE_Registry::instance()->CFG->core->reg_page_url()); | |
| 734 | - } | |
| 735 | - | |
| 736 | - | |
| 737 | - /** | |
| 738 | - * Gets the URL of the thank you page with this registration REG_url_link added as | |
| 739 | - * a query parameter | |
| 740 | - * | |
| 741 | - * @return string | |
| 742 | - * @throws EE_Error | |
| 743 | - */ | |
| 744 | - public function edit_attendee_information_url() | |
| 745 | -    { | |
| 746 | - return add_query_arg(array( | |
| 747 | - 'e_reg_url_link' => $this->reg_url_link(), | |
| 748 | - 'step' => 'attendee_information', | |
| 749 | - 'revisit' => true, | |
| 750 | - ), EE_Registry::instance()->CFG->core->reg_page_url()); | |
| 751 | - } | |
| 752 | - | |
| 753 | - | |
| 754 | - /** | |
| 755 | - * Simply generates and returns the appropriate admin_url link to edit this registration | |
| 756 | - * | |
| 757 | - * @return string | |
| 758 | - * @throws EE_Error | |
| 759 | - */ | |
| 760 | - public function get_admin_edit_url() | |
| 761 | -    { | |
| 762 | - return EEH_URL::add_query_args_and_nonce(array( | |
| 763 | - 'page' => 'espresso_registrations', | |
| 764 | - 'action' => 'view_registration', | |
| 765 | - '_REG_ID' => $this->ID(), | |
| 766 | -        ), admin_url('admin.php')); | |
| 767 | - } | |
| 768 | - | |
| 769 | - | |
| 770 | - /** | |
| 771 | - * is_primary_registrant? | |
| 772 | - */ | |
| 773 | - public function is_primary_registrant() | |
| 774 | -    { | |
| 775 | -        return $this->get('REG_count') == 1 ? true : false; | |
| 776 | - } | |
| 777 | - | |
| 778 | - | |
| 779 | - /** | |
| 780 | - * This returns the primary registration object for this registration group (which may be this object). | |
| 781 | - * | |
| 782 | - * @return EE_Registration | |
| 783 | - * @throws EE_Error | |
| 784 | - */ | |
| 785 | - public function get_primary_registration() | |
| 786 | -    { | |
| 787 | -        if ($this->is_primary_registrant()) { | |
| 788 | - return $this; | |
| 789 | - } | |
| 790 | - | |
| 791 | - //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 | |
| 792 | - /** @var EE_Registration $primary_registrant */ | |
| 793 | - $primary_registrant = EEM_Registration::instance()->get_one(array( | |
| 794 | - array( | |
| 795 | - 'TXN_ID' => $this->transaction_ID(), | |
| 796 | - 'REG_count' => 1, | |
| 797 | - ), | |
| 798 | - )); | |
| 799 | - return $primary_registrant; | |
| 800 | - } | |
| 801 | - | |
| 802 | - | |
| 803 | - /** | |
| 804 | - * get Attendee Number | |
| 805 | - * | |
| 806 | - * @access public | |
| 807 | - */ | |
| 808 | - public function count() | |
| 809 | -    { | |
| 810 | -        return $this->get('REG_count'); | |
| 811 | - } | |
| 812 | - | |
| 813 | - | |
| 814 | - /** | |
| 815 | - * get Group Size | |
| 816 | - */ | |
| 817 | - public function group_size() | |
| 818 | -    { | |
| 819 | -        return $this->get('REG_group_size'); | |
| 820 | - } | |
| 821 | - | |
| 822 | - | |
| 823 | - /** | |
| 824 | - * get Registration Date | |
| 825 | - */ | |
| 826 | - public function date() | |
| 827 | -    { | |
| 828 | -        return $this->get('REG_date'); | |
| 829 | - } | |
| 830 | - | |
| 831 | - | |
| 832 | - /** | |
| 833 | - * gets a pretty date | |
| 834 | - * | |
| 835 | - * @param string $date_format | |
| 836 | - * @param string $time_format | |
| 837 | - * @return string | |
| 838 | - * @throws EE_Error | |
| 839 | - */ | |
| 840 | - public function pretty_date($date_format = null, $time_format = null) | |
| 841 | -    { | |
| 842 | -        return $this->get_datetime('REG_date', $date_format, $time_format); | |
| 843 | - } | |
| 844 | - | |
| 845 | - | |
| 846 | - /** | |
| 847 | - * final_price | |
| 848 | - * the registration's share of the transaction total, so that the | |
| 849 | - * sum of all the transaction's REG_final_prices equal the transaction's total | |
| 850 | - * | |
| 851 | - * @return float | |
| 852 | - * @throws EE_Error | |
| 853 | - */ | |
| 854 | - public function final_price() | |
| 855 | -    { | |
| 856 | -        return $this->get('REG_final_price'); | |
| 857 | - } | |
| 858 | - | |
| 859 | - | |
| 860 | - /** | |
| 861 | - * pretty_final_price | |
| 862 | - * final price as formatted string, with correct decimal places and currency symbol | |
| 863 | - * | |
| 864 | - * @return string | |
| 865 | - * @throws EE_Error | |
| 866 | - */ | |
| 867 | - public function pretty_final_price() | |
| 868 | -    { | |
| 869 | -        return $this->get_pretty('REG_final_price'); | |
| 870 | - } | |
| 871 | - | |
| 872 | - | |
| 873 | - /** | |
| 874 | - * get paid (yeah) | |
| 875 | - * | |
| 876 | - * @return float | |
| 877 | - * @throws EE_Error | |
| 878 | - */ | |
| 879 | - public function paid() | |
| 880 | -    { | |
| 881 | -        return $this->get('REG_paid'); | |
| 882 | - } | |
| 883 | - | |
| 884 | - | |
| 885 | - /** | |
| 886 | - * pretty_paid | |
| 887 | - * | |
| 888 | - * @return float | |
| 889 | - * @throws EE_Error | |
| 890 | - */ | |
| 891 | - public function pretty_paid() | |
| 892 | -    { | |
| 893 | -        return $this->get_pretty('REG_paid'); | |
| 894 | - } | |
| 895 | - | |
| 896 | - | |
| 897 | - /** | |
| 898 | - * owes_monies_and_can_pay | |
| 899 | - * whether or not this registration has monies owing and it's' status allows payment | |
| 900 | - * | |
| 901 | - * @param array $requires_payment | |
| 902 | - * @return bool | |
| 903 | - * @throws EE_Error | |
| 904 | - */ | |
| 905 | - public function owes_monies_and_can_pay($requires_payment = array()) | |
| 906 | -    { | |
| 907 | - // these reg statuses require payment (if event is not free) | |
| 908 | - $requires_payment = ! empty($requires_payment) | |
| 909 | - ? $requires_payment | |
| 910 | - : EEM_Registration::reg_statuses_that_allow_payment(); | |
| 911 | - if (in_array($this->status_ID(), $requires_payment) && | |
| 912 | - $this->final_price() != 0 && | |
| 913 | - $this->final_price() != $this->paid() | |
| 914 | -        ) { | |
| 915 | - return true; | |
| 916 | -        } else { | |
| 917 | - return false; | |
| 918 | - } | |
| 919 | - } | |
| 920 | - | |
| 921 | - | |
| 922 | - /** | |
| 923 | - * Prints out the return value of $this->pretty_status() | |
| 924 | - * | |
| 925 | - * @param bool $show_icons | |
| 926 | - * @return void | |
| 927 | - * @throws EE_Error | |
| 928 | - */ | |
| 929 | - public function e_pretty_status($show_icons = false) | |
| 930 | -    { | |
| 931 | - echo $this->pretty_status($show_icons); | |
| 932 | - } | |
| 933 | - | |
| 934 | - | |
| 935 | - /** | |
| 936 | - * Returns a nice version of the status for displaying to customers | |
| 937 | - * | |
| 938 | - * @param bool $show_icons | |
| 939 | - * @return string | |
| 940 | - * @throws EE_Error | |
| 941 | - */ | |
| 942 | - public function pretty_status($show_icons = false) | |
| 943 | -    { | |
| 944 | - $status = EEM_Status::instance()->localized_status( | |
| 945 | -            array($this->status_ID() => esc_html__('unknown', 'event_espresso')), | |
| 946 | - false, | |
| 947 | - 'sentence' | |
| 948 | - ); | |
| 949 | - $icon = ''; | |
| 950 | -        switch ($this->status_ID()) { | |
| 951 | - case EEM_Registration::status_id_approved: | |
| 952 | - $icon = $show_icons | |
| 953 | - ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' | |
| 954 | - : ''; | |
| 955 | - break; | |
| 956 | - case EEM_Registration::status_id_pending_payment: | |
| 957 | - $icon = $show_icons | |
| 958 | - ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' | |
| 959 | - : ''; | |
| 960 | - break; | |
| 961 | - case EEM_Registration::status_id_not_approved: | |
| 962 | - $icon = $show_icons | |
| 963 | - ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' | |
| 964 | - : ''; | |
| 965 | - break; | |
| 966 | - case EEM_Registration::status_id_cancelled: | |
| 967 | - $icon = $show_icons | |
| 968 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' | |
| 969 | - : ''; | |
| 970 | - break; | |
| 971 | - case EEM_Registration::status_id_incomplete: | |
| 972 | - $icon = $show_icons | |
| 973 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' | |
| 974 | - : ''; | |
| 975 | - break; | |
| 976 | - case EEM_Registration::status_id_declined: | |
| 977 | - $icon = $show_icons | |
| 978 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' | |
| 979 | - : ''; | |
| 980 | - break; | |
| 981 | - case EEM_Registration::status_id_wait_list: | |
| 982 | - $icon = $show_icons | |
| 983 | - ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' | |
| 984 | - : ''; | |
| 985 | - break; | |
| 986 | - } | |
| 987 | - return $icon . $status[$this->status_ID()]; | |
| 988 | - } | |
| 989 | - | |
| 990 | - | |
| 991 | - /** | |
| 992 | - * get Attendee Is Going | |
| 993 | - */ | |
| 994 | - public function att_is_going() | |
| 995 | -    { | |
| 996 | -        return $this->get('REG_att_is_going'); | |
| 997 | - } | |
| 998 | - | |
| 999 | - | |
| 1000 | - /** | |
| 1001 | - * Gets related answers | |
| 1002 | - * | |
| 1003 | - * @param array $query_params like EEM_Base::get_all | |
| 1004 | - * @return EE_Answer[] | |
| 1005 | - * @throws EE_Error | |
| 1006 | - */ | |
| 1007 | - public function answers($query_params = null) | |
| 1008 | -    { | |
| 1009 | -        return $this->get_many_related('Answer', $query_params); | |
| 1010 | - } | |
| 1011 | - | |
| 1012 | - | |
| 1013 | - /** | |
| 1014 | - * Gets the registration's answer value to the specified question | |
| 1015 | - * (either the question's ID or a question object) | |
| 1016 | - * | |
| 1017 | - * @param EE_Question|int $question | |
| 1018 | - * @param bool $pretty_value | |
| 1019 | - * @return array|string if pretty_value= true, the result will always be a string | |
| 1020 | - * (because the answer might be an array of answer values, so passing pretty_value=true | |
| 1021 | - * will convert it into some kind of string) | |
| 1022 | - * @throws EE_Error | |
| 1023 | - */ | |
| 1024 | - public function answer_value_to_question($question, $pretty_value = true) | |
| 1025 | -    { | |
| 1026 | - $question_id = EEM_Question::instance()->ensure_is_ID($question); | |
| 1027 | - return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); | |
| 1028 | - } | |
| 1029 | - | |
| 1030 | - | |
| 1031 | - /** | |
| 1032 | - * question_groups | |
| 1033 | - * returns an array of EE_Question_Group objects for this registration | |
| 1034 | - * | |
| 1035 | - * @return EE_Question_Group[] | |
| 1036 | - * @throws EE_Error | |
| 1037 | - * @throws EntityNotFoundException | |
| 1038 | - */ | |
| 1039 | - public function question_groups() | |
| 1040 | -    { | |
| 1041 | - $question_groups = array(); | |
| 1042 | -        if ($this->event() instanceof EE_Event) { | |
| 1043 | - $question_groups = $this->event()->question_groups( | |
| 1044 | - array( | |
| 1045 | - array( | |
| 1046 | - 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, | |
| 1047 | - ), | |
| 1048 | -                    'order_by' => array('QSG_order' => 'ASC'), | |
| 1049 | - ) | |
| 1050 | - ); | |
| 1051 | - } | |
| 1052 | - return $question_groups; | |
| 1053 | - } | |
| 1054 | - | |
| 1055 | - | |
| 1056 | - /** | |
| 1057 | - * count_question_groups | |
| 1058 | - * returns a count of the number of EE_Question_Group objects for this registration | |
| 1059 | - * | |
| 1060 | - * @return int | |
| 1061 | - * @throws EE_Error | |
| 1062 | - * @throws EntityNotFoundException | |
| 1063 | - */ | |
| 1064 | - public function count_question_groups() | |
| 1065 | -    { | |
| 1066 | - $qg_count = 0; | |
| 1067 | -        if ($this->event() instanceof EE_Event) { | |
| 1068 | - $qg_count = $this->event()->count_related( | |
| 1069 | - 'Question_Group', | |
| 1070 | - array( | |
| 1071 | - array( | |
| 1072 | - 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, | |
| 1073 | - ), | |
| 1074 | - ) | |
| 1075 | - ); | |
| 1076 | - } | |
| 1077 | - return $qg_count; | |
| 1078 | - } | |
| 1079 | - | |
| 1080 | - | |
| 1081 | - /** | |
| 1082 | - * Returns the registration date in the 'standard' string format | |
| 1083 | - * (function may be improved in the future to allow for different formats and timezones) | |
| 1084 | - * | |
| 1085 | - * @return string | |
| 1086 | - * @throws EE_Error | |
| 1087 | - */ | |
| 1088 | - public function reg_date() | |
| 1089 | -    { | |
| 1090 | -        return $this->get_datetime('REG_date'); | |
| 1091 | - } | |
| 1092 | - | |
| 1093 | - | |
| 1094 | - /** | |
| 1095 | - * Gets the datetime-ticket for this registration (ie, it can be used to isolate | |
| 1096 | - * the ticket this registration purchased, or the datetime they have registered | |
| 1097 | - * to attend) | |
| 1098 | - * | |
| 1099 | - * @return EE_Datetime_Ticket | |
| 1100 | - * @throws EE_Error | |
| 1101 | - */ | |
| 1102 | - public function datetime_ticket() | |
| 1103 | -    { | |
| 1104 | -        return $this->get_first_related('Datetime_Ticket'); | |
| 1105 | - } | |
| 1106 | - | |
| 1107 | - | |
| 1108 | - /** | |
| 1109 | - * Sets the registration's datetime_ticket. | |
| 1110 | - * | |
| 1111 | - * @param EE_Datetime_Ticket $datetime_ticket | |
| 1112 | - * @return EE_Datetime_Ticket | |
| 1113 | - * @throws EE_Error | |
| 1114 | - */ | |
| 1115 | - public function set_datetime_ticket($datetime_ticket) | |
| 1116 | -    { | |
| 1117 | - return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); | |
| 1118 | - } | |
| 1119 | - | |
| 1120 | - /** | |
| 1121 | - * Gets deleted | |
| 1122 | - * | |
| 1123 | - * @return bool | |
| 1124 | - * @throws EE_Error | |
| 1125 | - */ | |
| 1126 | - public function deleted() | |
| 1127 | -    { | |
| 1128 | -        return $this->get('REG_deleted'); | |
| 1129 | - } | |
| 1130 | - | |
| 1131 | - /** | |
| 1132 | - * Sets deleted | |
| 1133 | - * | |
| 1134 | - * @param boolean $deleted | |
| 1135 | - * @return bool | |
| 1136 | - * @throws EE_Error | |
| 1137 | - * @throws RuntimeException | |
| 1138 | - */ | |
| 1139 | - public function set_deleted($deleted) | |
| 1140 | -    { | |
| 1141 | -        if ($deleted) { | |
| 1142 | - $this->delete(); | |
| 1143 | -        } else { | |
| 1144 | - $this->restore(); | |
| 1145 | - } | |
| 1146 | - } | |
| 1147 | - | |
| 1148 | - | |
| 1149 | - /** | |
| 1150 | - * Get the status object of this object | |
| 1151 | - * | |
| 1152 | - * @return EE_Status | |
| 1153 | - * @throws EE_Error | |
| 1154 | - */ | |
| 1155 | - public function status_obj() | |
| 1156 | -    { | |
| 1157 | -        return $this->get_first_related('Status'); | |
| 1158 | - } | |
| 1159 | - | |
| 1160 | - | |
| 1161 | - /** | |
| 1162 | - * Returns the number of times this registration has checked into any of the datetimes | |
| 1163 | - * its available for | |
| 1164 | - * | |
| 1165 | - * @return int | |
| 1166 | - * @throws EE_Error | |
| 1167 | - */ | |
| 1168 | - public function count_checkins() | |
| 1169 | -    { | |
| 1170 | - return $this->get_model()->count_related($this, 'Checkin'); | |
| 1171 | - } | |
| 1172 | - | |
| 1173 | - | |
| 1174 | - /** | |
| 1175 | - * Returns the number of current Check-ins this registration is checked into for any of the datetimes the | |
| 1176 | - * registration is for. Note, this is ONLY checked in (does not include checkedout) | |
| 1177 | - * | |
| 1178 | - * @return int | |
| 1179 | - * @throws EE_Error | |
| 1180 | - */ | |
| 1181 | - public function count_checkins_not_checkedout() | |
| 1182 | -    { | |
| 1183 | -        return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); | |
| 1184 | - } | |
| 1185 | - | |
| 1186 | - | |
| 1187 | - /** | |
| 1188 | - * The purpose of this method is simply to check whether this registration can checkin to the given datetime. | |
| 1189 | - * | |
| 1190 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against | |
| 1191 | - * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also | |
| 1192 | - * consider registration status as well as datetime access. | |
| 1193 | - * @return bool | |
| 1194 | - * @throws EE_Error | |
| 1195 | - */ | |
| 1196 | - public function can_checkin($DTT_OR_ID, $check_approved = true) | |
| 1197 | -    { | |
| 1198 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); | |
| 1199 | - | |
| 1200 | - //first check registration status | |
| 1201 | -        if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { | |
| 1202 | - return false; | |
| 1203 | - } | |
| 1204 | - //is there a datetime ticket that matches this dtt_ID? | |
| 1205 | - if (! (EEM_Datetime_Ticket::instance()->exists(array( | |
| 1206 | - array( | |
| 1207 | -                'TKT_ID' => $this->get('TKT_ID'), | |
| 1208 | - 'DTT_ID' => $DTT_ID, | |
| 1209 | - ), | |
| 1210 | - ))) | |
| 1211 | -        ) { | |
| 1212 | - return false; | |
| 1213 | - } | |
| 1214 | - | |
| 1215 | - //final check is against TKT_uses | |
| 1216 | - return $this->verify_can_checkin_against_TKT_uses($DTT_ID); | |
| 1217 | - } | |
| 1218 | - | |
| 1219 | - | |
| 1220 | - /** | |
| 1221 | - * This method verifies whether the user can checkin for the given datetime considering the max uses value set on | |
| 1222 | - * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the | |
| 1223 | - * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, | |
| 1224 | - * then return false. Otherwise return true. | |
| 1225 | - * | |
| 1226 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against | |
| 1227 | - * @return bool true means can checkin. false means cannot checkin. | |
| 1228 | - * @throws EE_Error | |
| 1229 | - */ | |
| 1230 | - public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) | |
| 1231 | -    { | |
| 1232 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); | |
| 1233 | - | |
| 1234 | -        if (! $DTT_ID) { | |
| 1235 | - return false; | |
| 1236 | - } | |
| 1237 | - | |
| 1238 | - $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; | |
| 1239 | - | |
| 1240 | - // if max uses is not set or equals infinity then return true cause its not a factor for whether user can | |
| 1241 | - // check-in or not. | |
| 1242 | -        if (! $max_uses || $max_uses === EE_INF) { | |
| 1243 | - return true; | |
| 1244 | - } | |
| 1245 | - | |
| 1246 | - //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just | |
| 1247 | - //go ahead and toggle. | |
| 1248 | -        if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { | |
| 1249 | - return true; | |
| 1250 | - } | |
| 1251 | - | |
| 1252 | - //made it here so the last check is whether the number of checkins per unique datetime on this registration | |
| 1253 | - //disallows further check-ins. | |
| 1254 | - $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array( | |
| 1255 | - array( | |
| 1256 | - 'REG_ID' => $this->ID(), | |
| 1257 | - 'CHK_in' => true, | |
| 1258 | - ), | |
| 1259 | - ), 'DTT_ID', true); | |
| 1260 | - // checkins have already reached their max number of uses | |
| 1261 | - // so registrant can NOT checkin | |
| 1262 | -        if ($count_unique_dtt_checkins >= $max_uses) { | |
| 1263 | - EE_Error::add_error( | |
| 1264 | - esc_html__( | |
| 1265 | - 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', | |
| 1266 | - 'event_espresso' | |
| 1267 | - ), | |
| 1268 | - __FILE__, | |
| 1269 | - __FUNCTION__, | |
| 1270 | - __LINE__ | |
| 1271 | - ); | |
| 1272 | - return false; | |
| 1273 | - } | |
| 1274 | - return true; | |
| 1275 | - } | |
| 1276 | - | |
| 1277 | - | |
| 1278 | - /** | |
| 1279 | - * toggle Check-in status for this registration | |
| 1280 | - * Check-ins are toggled in the following order: | |
| 1281 | - * never checked in -> checked in | |
| 1282 | - * checked in -> checked out | |
| 1283 | - * checked out -> checked in | |
| 1284 | - * | |
| 1285 | - * @param int $DTT_ID include specific datetime to toggle Check-in for. | |
| 1286 | - * If not included or null, then it is assumed latest datetime is being toggled. | |
| 1287 | - * @param bool $verify If true then can_checkin() is used to verify whether the person | |
| 1288 | - * can be checked in or not. Otherwise this forces change in checkin status. | |
| 1289 | - * @return bool|int the chk_in status toggled to OR false if nothing got changed. | |
| 1290 | - * @throws EE_Error | |
| 1291 | - */ | |
| 1292 | - public function toggle_checkin_status($DTT_ID = null, $verify = false) | |
| 1293 | -    { | |
| 1294 | -        if (empty($DTT_ID)) { | |
| 1295 | - $datetime = $this->get_latest_related_datetime(); | |
| 1296 | - $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; | |
| 1297 | - // verify the registration can checkin for the given DTT_ID | |
| 1298 | -        } elseif (! $this->can_checkin($DTT_ID, $verify)) { | |
| 1299 | - EE_Error::add_error( | |
| 1300 | - sprintf( | |
| 1301 | - esc_html__( | |
| 1302 | - 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', | |
| 1303 | - 'event_espresso' | |
| 1304 | - ), | |
| 1305 | - $this->ID(), | |
| 1306 | - $DTT_ID | |
| 1307 | - ), | |
| 1308 | - __FILE__, | |
| 1309 | - __FUNCTION__, | |
| 1310 | - __LINE__ | |
| 1311 | - ); | |
| 1312 | - return false; | |
| 1313 | - } | |
| 1314 | - $status_paths = array( | |
| 1315 | - EE_Registration::checkin_status_never => EE_Registration::checkin_status_in, | |
| 1316 | - EE_Registration::checkin_status_in => EE_Registration::checkin_status_out, | |
| 1317 | - EE_Registration::checkin_status_out => EE_Registration::checkin_status_in, | |
| 1318 | - ); | |
| 1319 | - //start by getting the current status so we know what status we'll be changing to. | |
| 1320 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); | |
| 1321 | - $status_to = $status_paths[$cur_status]; | |
| 1322 | - // database only records true for checked IN or false for checked OUT | |
| 1323 | - // no record ( null ) means checked in NEVER, but we obviously don't save that | |
| 1324 | - $new_status = $status_to === EE_Registration::checkin_status_in ? true : false; | |
| 1325 | - // add relation - note Check-ins are always creating new rows | |
| 1326 | - // because we are keeping track of Check-ins over time. | |
| 1327 | - // Eventually we'll probably want to show a list table | |
| 1328 | - // for the individual Check-ins so that they can be managed. | |
| 1329 | - $checkin = EE_Checkin::new_instance(array( | |
| 1330 | - 'REG_ID' => $this->ID(), | |
| 1331 | - 'DTT_ID' => $DTT_ID, | |
| 1332 | - 'CHK_in' => $new_status, | |
| 1333 | - )); | |
| 1334 | - // if the record could not be saved then return false | |
| 1335 | -        if ($checkin->save() === 0) { | |
| 1336 | -            if (WP_DEBUG) { | |
| 1337 | - global $wpdb; | |
| 1338 | - $error = sprintf( | |
| 1339 | - esc_html__( | |
| 1340 | - 'Registration check in update failed because of the following database error: %1$s%2$s', | |
| 1341 | - 'event_espresso' | |
| 1342 | - ), | |
| 1343 | - '<br />', | |
| 1344 | - $wpdb->last_error | |
| 1345 | - ); | |
| 1346 | -            } else { | |
| 1347 | - $error = esc_html__( | |
| 1348 | - 'Registration check in update failed because of an unknown database error', | |
| 1349 | - 'event_espresso' | |
| 1350 | - ); | |
| 1351 | - } | |
| 1352 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); | |
| 1353 | - return false; | |
| 1354 | - } | |
| 1355 | - return $status_to; | |
| 1356 | - } | |
| 1357 | - | |
| 1358 | - | |
| 1359 | - /** | |
| 1360 | - * Returns the latest datetime related to this registration (via the ticket attached to the registration). | |
| 1361 | - * "Latest" is defined by the `DTT_EVT_start` column. | |
| 1362 | - * | |
| 1363 | - * @return EE_Datetime|null | |
| 1364 | - * @throws \EE_Error | |
| 1365 | - */ | |
| 1366 | - public function get_latest_related_datetime() | |
| 1367 | -    { | |
| 1368 | - return EEM_Datetime::instance()->get_one( | |
| 1369 | - array( | |
| 1370 | - array( | |
| 1371 | - 'Ticket.Registration.REG_ID' => $this->ID(), | |
| 1372 | - ), | |
| 1373 | -                'order_by' => array('DTT_EVT_start' => 'DESC'), | |
| 1374 | - ) | |
| 1375 | - ); | |
| 1376 | - } | |
| 1377 | - | |
| 1378 | - | |
| 1379 | - /** | |
| 1380 | - * Returns the earliest datetime related to this registration (via the ticket attached to the registration). | |
| 1381 | - * "Earliest" is defined by the `DTT_EVT_start` column. | |
| 1382 | - * | |
| 1383 | - * @throws \EE_Error | |
| 1384 | - */ | |
| 1385 | - public function get_earliest_related_datetime() | |
| 1386 | -    { | |
| 1387 | - return EEM_Datetime::instance()->get_one( | |
| 1388 | - array( | |
| 1389 | - array( | |
| 1390 | - 'Ticket.Registration.REG_ID' => $this->ID(), | |
| 1391 | - ), | |
| 1392 | -                'order_by' => array('DTT_EVT_start' => 'ASC'), | |
| 1393 | - ) | |
| 1394 | - ); | |
| 1395 | - } | |
| 1396 | - | |
| 1397 | - | |
| 1398 | - /** | |
| 1399 | - * This method simply returns the check-in status for this registration and the given datetime. | |
| 1400 | - * If neither the datetime nor the checkin values are provided as arguments, | |
| 1401 | - * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. | |
| 1402 | - * | |
| 1403 | - * @param int $DTT_ID The ID of the datetime we're checking against | |
| 1404 | - * (if empty we'll get the primary datetime for | |
| 1405 | - * this registration (via event) and use it's ID); | |
| 1406 | - * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. | |
| 1407 | - * @return int Integer representing Check-in status. | |
| 1408 | - * @throws \EE_Error | |
| 1409 | - */ | |
| 1410 | - public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) | |
| 1411 | -    { | |
| 1412 | - $checkin_query_params = array( | |
| 1413 | -            'order_by' => array('CHK_timestamp' => 'DESC'), | |
| 1414 | - ); | |
| 1415 | - | |
| 1416 | -        if ($DTT_ID > 0) { | |
| 1417 | -            $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); | |
| 1418 | - } | |
| 1419 | - | |
| 1420 | - //get checkin object (if exists) | |
| 1421 | - $checkin = $checkin instanceof EE_Checkin | |
| 1422 | - ? $checkin | |
| 1423 | -            : $this->get_first_related('Checkin', $checkin_query_params); | |
| 1424 | -        if ($checkin instanceof EE_Checkin) { | |
| 1425 | -            if ($checkin->get('CHK_in')) { | |
| 1426 | - return EE_Registration::checkin_status_in; //checked in | |
| 1427 | - } | |
| 1428 | - return EE_Registration::checkin_status_out; //had checked in but is now checked out. | |
| 1429 | - } | |
| 1430 | - return EE_Registration::checkin_status_never; //never been checked in | |
| 1431 | - } | |
| 1432 | - | |
| 1433 | - | |
| 1434 | - /** | |
| 1435 | - * This method returns a localized message for the toggled Check-in message. | |
| 1436 | - * | |
| 1437 | - * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, | |
| 1438 | - * then it is assumed Check-in for primary datetime was toggled. | |
| 1439 | - * @param bool $error This just flags that you want an error message returned. This is put in so that the error | |
| 1440 | - * message can be customized with the attendee name. | |
| 1441 | - * @return string internationalized message | |
| 1442 | - * @throws EE_Error | |
| 1443 | - */ | |
| 1444 | - public function get_checkin_msg($DTT_ID, $error = false) | |
| 1445 | -    { | |
| 1446 | - //let's get the attendee first so we can include the name of the attendee | |
| 1447 | -        $attendee = $this->get_first_related('Attendee'); | |
| 1448 | -        if ($attendee instanceof EE_Attendee) { | |
| 1449 | -            if ($error) { | |
| 1450 | -                return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); | |
| 1451 | - } | |
| 1452 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID); | |
| 1453 | - //what is the status message going to be? | |
| 1454 | -            switch ($cur_status) { | |
| 1455 | - case EE_Registration::checkin_status_never: | |
| 1456 | -                    return sprintf(__("%s has been removed from Check-in records", "event_espresso"), | |
| 1457 | - $attendee->full_name()); | |
| 1458 | - break; | |
| 1459 | - case EE_Registration::checkin_status_in: | |
| 1460 | -                    return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); | |
| 1461 | - break; | |
| 1462 | - case EE_Registration::checkin_status_out: | |
| 1463 | -                    return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); | |
| 1464 | - break; | |
| 1465 | - } | |
| 1466 | - } | |
| 1467 | -        return esc_html__("The check-in status could not be determined.", "event_espresso"); | |
| 1468 | - } | |
| 1469 | - | |
| 1470 | - | |
| 1471 | - /** | |
| 1472 | - * Returns the related EE_Transaction to this registration | |
| 1473 | - * | |
| 1474 | - * @return EE_Transaction | |
| 1475 | - * @throws EE_Error | |
| 1476 | - * @throws EntityNotFoundException | |
| 1477 | - */ | |
| 1478 | - public function transaction() | |
| 1479 | -    { | |
| 1480 | -        $transaction = $this->get_first_related('Transaction'); | |
| 1481 | -        if (! $transaction instanceof \EE_Transaction) { | |
| 1482 | -            throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); | |
| 1483 | - } | |
| 1484 | - return $transaction; | |
| 1485 | - } | |
| 1486 | - | |
| 1487 | - | |
| 1488 | - /** | |
| 1489 | - * get Registration Code | |
| 1490 | - */ | |
| 1491 | - public function reg_code() | |
| 1492 | -    { | |
| 1493 | -        return $this->get('REG_code'); | |
| 1494 | - } | |
| 1495 | - | |
| 1496 | - | |
| 1497 | - /** | |
| 1498 | - * get Transaction ID | |
| 1499 | - */ | |
| 1500 | - public function transaction_ID() | |
| 1501 | -    { | |
| 1502 | -        return $this->get('TXN_ID'); | |
| 1503 | - } | |
| 1504 | - | |
| 1505 | - | |
| 1506 | - /** | |
| 1507 | - * @return int | |
| 1508 | - * @throws EE_Error | |
| 1509 | - */ | |
| 1510 | - public function ticket_ID() | |
| 1511 | -    { | |
| 1512 | -        return $this->get('TKT_ID'); | |
| 1513 | - } | |
| 1514 | - | |
| 1515 | - | |
| 1516 | - /** | |
| 1517 | - * Set Registration Code | |
| 1518 | - * | |
| 1519 | - * @access public | |
| 1520 | - * @param string $REG_code Registration Code | |
| 1521 | - * @param boolean $use_default | |
| 1522 | - * @throws EE_Error | |
| 1523 | - */ | |
| 1524 | - public function set_reg_code($REG_code, $use_default = false) | |
| 1525 | -    { | |
| 1526 | -        if (empty($REG_code)) { | |
| 1527 | - EE_Error::add_error( | |
| 1528 | -                esc_html__('REG_code can not be empty.', 'event_espresso'), | |
| 1529 | - __FILE__, | |
| 1530 | - __FUNCTION__, | |
| 1531 | - __LINE__ | |
| 1532 | - ); | |
| 1533 | - return; | |
| 1534 | - } | |
| 1535 | -        if (! $this->reg_code()) { | |
| 1536 | -            parent::set('REG_code', $REG_code, $use_default); | |
| 1537 | -        } else { | |
| 1538 | - EE_Error::doing_it_wrong( | |
| 1539 | - __CLASS__ . '::' . __FUNCTION__, | |
| 1540 | -                esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), | |
| 1541 | - '4.6.0' | |
| 1542 | - ); | |
| 1543 | - } | |
| 1544 | - } | |
| 1545 | - | |
| 1546 | - | |
| 1547 | - /** | |
| 1548 | - * Returns all other registrations in the same group as this registrant who have the same ticket option. | |
| 1549 | - * Note, if you want to just get all registrations in the same transaction (group), use: | |
| 1550 | - * $registration->transaction()->registrations(); | |
| 1551 | - * | |
| 1552 | - * @since 4.5.0 | |
| 1553 | - * @return EE_Registration[] or empty array if this isn't a group registration. | |
| 1554 | - * @throws EE_Error | |
| 1555 | - */ | |
| 1556 | - public function get_all_other_registrations_in_group() | |
| 1557 | -    { | |
| 1558 | -        if ($this->group_size() < 2) { | |
| 1559 | - return array(); | |
| 1560 | - } | |
| 1561 | - | |
| 1562 | - $query[0] = array( | |
| 1563 | - 'TXN_ID' => $this->transaction_ID(), | |
| 1564 | -            'REG_ID' => array('!=', $this->ID()), | |
| 1565 | - 'TKT_ID' => $this->ticket_ID(), | |
| 1566 | - ); | |
| 1567 | - /** @var EE_Registration[] $registrations */ | |
| 1568 | - $registrations = $this->get_model()->get_all($query); | |
| 1569 | - return $registrations; | |
| 1570 | - } | |
| 1571 | - | |
| 1572 | - /** | |
| 1573 | - * Return the link to the admin details for the object. | |
| 1574 | - * | |
| 1575 | - * @return string | |
| 1576 | - * @throws EE_Error | |
| 1577 | - */ | |
| 1578 | - public function get_admin_details_link() | |
| 1579 | -    { | |
| 1580 | -        EE_Registry::instance()->load_helper('URL'); | |
| 1581 | - return EEH_URL::add_query_args_and_nonce( | |
| 1582 | - array( | |
| 1583 | - 'page' => 'espresso_registrations', | |
| 1584 | - 'action' => 'view_registration', | |
| 1585 | - '_REG_ID' => $this->ID(), | |
| 1586 | - ), | |
| 1587 | -            admin_url('admin.php') | |
| 1588 | - ); | |
| 1589 | - } | |
| 1590 | - | |
| 1591 | - /** | |
| 1592 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. | |
| 1593 | - * | |
| 1594 | - * @return string | |
| 1595 | - * @throws EE_Error | |
| 1596 | - */ | |
| 1597 | - public function get_admin_edit_link() | |
| 1598 | -    { | |
| 1599 | - return $this->get_admin_details_link(); | |
| 1600 | - } | |
| 1601 | - | |
| 1602 | - /** | |
| 1603 | - * Returns the link to a settings page for the object. | |
| 1604 | - * | |
| 1605 | - * @return string | |
| 1606 | - * @throws EE_Error | |
| 1607 | - */ | |
| 1608 | - public function get_admin_settings_link() | |
| 1609 | -    { | |
| 1610 | - return $this->get_admin_details_link(); | |
| 1611 | - } | |
| 1612 | - | |
| 1613 | - /** | |
| 1614 | - * Returns the link to the "overview" for the object (typically the "list table" view). | |
| 1615 | - * | |
| 1616 | - * @return string | |
| 1617 | - */ | |
| 1618 | - public function get_admin_overview_link() | |
| 1619 | -    { | |
| 1620 | -        EE_Registry::instance()->load_helper('URL'); | |
| 1621 | - return EEH_URL::add_query_args_and_nonce( | |
| 1622 | - array( | |
| 1623 | - 'page' => 'espresso_registrations', | |
| 1624 | - ), | |
| 1625 | -            admin_url('admin.php') | |
| 1626 | - ); | |
| 1627 | - } | |
| 1628 | - | |
| 1629 | - | |
| 1630 | - /** | |
| 1631 | - * @param array $query_params | |
| 1632 | - * @return \EE_Registration[] | |
| 1633 | - * @throws \EE_Error | |
| 1634 | - */ | |
| 1635 | - public function payments($query_params = array()) | |
| 1636 | -    { | |
| 1637 | -        return $this->get_many_related('Payment', $query_params); | |
| 1638 | - } | |
| 1639 | - | |
| 1640 | - | |
| 1641 | - /** | |
| 1642 | - * @param array $query_params | |
| 1643 | - * @return \EE_Registration_Payment[] | |
| 1644 | - * @throws \EE_Error | |
| 1645 | - */ | |
| 1646 | - public function registration_payments($query_params = array()) | |
| 1647 | -    { | |
| 1648 | -        return $this->get_many_related('Registration_Payment', $query_params); | |
| 1649 | - } | |
| 1650 | - | |
| 1651 | - | |
| 1652 | - /** | |
| 1653 | - * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. | |
| 1654 | - * Note: if there are no payments on the registration there will be no payment method returned. | |
| 1655 | - * | |
| 1656 | - * @return EE_Payment_Method|null | |
| 1657 | - */ | |
| 1658 | - public function payment_method() | |
| 1659 | -    { | |
| 1660 | - return EEM_Payment_Method::instance()->get_last_used_for_registration($this); | |
| 1661 | - } | |
| 1662 | - | |
| 1663 | - | |
| 1664 | - /** | |
| 1665 | - * @return \EE_Line_Item | |
| 1666 | - * @throws EntityNotFoundException | |
| 1667 | - * @throws \EE_Error | |
| 1668 | - */ | |
| 1669 | - public function ticket_line_item() | |
| 1670 | -    { | |
| 1671 | - $ticket = $this->ticket(); | |
| 1672 | - $transaction = $this->transaction(); | |
| 1673 | - $line_item = null; | |
| 1674 | - $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( | |
| 1675 | - $transaction->total_line_item(), | |
| 1676 | - 'Ticket', | |
| 1677 | - array($ticket->ID()) | |
| 1678 | - ); | |
| 1679 | -        foreach ($ticket_line_items as $ticket_line_item) { | |
| 1680 | - if ( | |
| 1681 | - $ticket_line_item instanceof \EE_Line_Item | |
| 1682 | - && $ticket_line_item->OBJ_type() === 'Ticket' | |
| 1683 | - && $ticket_line_item->OBJ_ID() === $ticket->ID() | |
| 1684 | -            ) { | |
| 1685 | - $line_item = $ticket_line_item; | |
| 1686 | - break; | |
| 1687 | - } | |
| 1688 | - } | |
| 1689 | -        if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { | |
| 1690 | -            throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); | |
| 1691 | - } | |
| 1692 | - return $line_item; | |
| 1693 | - } | |
| 1694 | - | |
| 1695 | - | |
| 1696 | - /** | |
| 1697 | - * Soft Deletes this model object. | |
| 1698 | - * | |
| 1699 | - * @return boolean | int | |
| 1700 | - * @throws \RuntimeException | |
| 1701 | - * @throws \EE_Error | |
| 1702 | - */ | |
| 1703 | - public function delete() | |
| 1704 | -    { | |
| 1705 | -        if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { | |
| 1706 | - $this->set_status(EEM_Registration::status_id_cancelled); | |
| 1707 | - } | |
| 1708 | - return parent::delete(); | |
| 1709 | - } | |
| 1710 | - | |
| 1711 | - | |
| 1712 | - /** | |
| 1713 | - * Restores whatever the previous status was on a registration before it was trashed (if possible) | |
| 1714 | - * | |
| 1715 | - * @throws \EE_Error | |
| 1716 | - * @throws \RuntimeException | |
| 1717 | - */ | |
| 1718 | - public function restore() | |
| 1719 | -    { | |
| 1720 | - $previous_status = $this->get_extra_meta( | |
| 1721 | - EE_Registration::PRE_TRASH_REG_STATUS_KEY, | |
| 1722 | - true, | |
| 1723 | - EEM_Registration::status_id_cancelled | |
| 1724 | - ); | |
| 1725 | -        if ($previous_status) { | |
| 1726 | - $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); | |
| 1727 | - $this->set_status($previous_status); | |
| 1728 | - } | |
| 1729 | - return parent::restore(); | |
| 1730 | - } | |
| 1731 | - | |
| 1732 | - | |
| 1733 | - | |
| 1734 | - /*************************** DEPRECATED ***************************/ | |
| 1735 | - | |
| 1736 | - | |
| 1737 | - /** | |
| 1738 | - * @deprecated | |
| 1739 | - * @since 4.7.0 | |
| 1740 | - * @access public | |
| 1741 | - */ | |
| 1742 | - public function price_paid() | |
| 1743 | -    { | |
| 1744 | -        EE_Error::doing_it_wrong('EE_Registration::price_paid()', | |
| 1745 | -            esc_html__('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'), | |
| 1746 | - '4.7.0'); | |
| 1747 | - return $this->final_price(); | |
| 1748 | - } | |
| 1749 | - | |
| 1750 | - | |
| 1751 | - /** | |
| 1752 | - * @deprecated | |
| 1753 | - * @since 4.7.0 | |
| 1754 | - * @access public | |
| 1755 | - * @param float $REG_final_price | |
| 1756 | - * @throws EE_Error | |
| 1757 | - * @throws RuntimeException | |
| 1758 | - */ | |
| 1759 | - public function set_price_paid($REG_final_price = 0.00) | |
| 1760 | -    { | |
| 1761 | -        EE_Error::doing_it_wrong('EE_Registration::set_price_paid()', | |
| 1762 | -            esc_html__('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'), | |
| 1763 | - '4.7.0'); | |
| 1764 | - $this->set_final_price($REG_final_price); | |
| 1765 | - } | |
| 1766 | - | |
| 1767 | - | |
| 1768 | - /** | |
| 1769 | - * @deprecated | |
| 1770 | - * @since 4.7.0 | |
| 1771 | - * @return string | |
| 1772 | - * @throws EE_Error | |
| 1773 | - */ | |
| 1774 | - public function pretty_price_paid() | |
| 1775 | -    { | |
| 1776 | -        EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()', | |
| 1777 | -            esc_html__('This method is deprecated, please use EE_Registration::pretty_final_price() instead.', | |
| 1778 | - 'event_espresso'), '4.7.0'); | |
| 1779 | - return $this->pretty_final_price(); | |
| 1780 | - } | |
| 1781 | - | |
| 1782 | - | |
| 1783 | - /** | |
| 1784 | - * Gets the primary datetime related to this registration via the related Event to this registration | |
| 1785 | - * | |
| 1786 | - * @deprecated 4.9.17 | |
| 1787 | - * @return EE_Datetime | |
| 1788 | - * @throws EE_Error | |
| 1789 | - * @throws EntityNotFoundException | |
| 1790 | - */ | |
| 1791 | - public function get_related_primary_datetime() | |
| 1792 | -    { | |
| 1793 | - EE_Error::doing_it_wrong( | |
| 1794 | - __METHOD__, | |
| 1795 | - esc_html__( | |
| 1796 | - 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', | |
| 1797 | - 'event_espresso' | |
| 1798 | - ), | |
| 1799 | - '4.9.17', | |
| 1800 | - '5.0.0' | |
| 1801 | - ); | |
| 1802 | - return $this->event()->primary_datetime(); | |
| 1803 | - } | |
| 18 | + /** | |
| 19 | + * Used to reference when a registration has never been checked in. | |
| 20 | + * | |
| 21 | + * @type int | |
| 22 | + */ | |
| 23 | + const checkin_status_never = 2; | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * Used to reference when a registration has been checked in. | |
| 27 | + * | |
| 28 | + * @type int | |
| 29 | + */ | |
| 30 | + const checkin_status_in = 1; | |
| 31 | + | |
| 32 | + | |
| 33 | + /** | |
| 34 | + * Used to reference when a registration has been checked out. | |
| 35 | + * | |
| 36 | + * @type int | |
| 37 | + */ | |
| 38 | + const checkin_status_out = 0; | |
| 39 | + | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * extra meta key for tracking reg status os trashed registrations | |
| 43 | + * | |
| 44 | + * @type string | |
| 45 | + */ | |
| 46 | + const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; | |
| 47 | + | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * extra meta key for tracking if registration has reserved ticket | |
| 51 | + * | |
| 52 | + * @type string | |
| 53 | + */ | |
| 54 | + const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * Set Event ID | |
| 60 | + * | |
| 61 | + * @param int $EVT_ID Event ID | |
| 62 | + * @throws EE_Error | |
| 63 | + * @throws RuntimeException | |
| 64 | + */ | |
| 65 | + public function set_event($EVT_ID = 0) | |
| 66 | +	{ | |
| 67 | +		$this->set('EVT_ID', $EVT_ID); | |
| 68 | + } | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + /** | |
| 73 | + * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can | |
| 74 | + * be routed to internal methods | |
| 75 | + * | |
| 76 | + * @param string $field_name | |
| 77 | + * @param mixed $field_value | |
| 78 | + * @param bool $use_default | |
| 79 | + * @throws \EE_Error | |
| 80 | + * @throws \RuntimeException | |
| 81 | + */ | |
| 82 | + public function set($field_name, $field_value, $use_default = false) | |
| 83 | +	{ | |
| 84 | +		switch ($field_name) { | |
| 85 | + case 'REG_code': | |
| 86 | +				if (! empty($field_value) && $this->reg_code() === null) { | |
| 87 | + $this->set_reg_code($field_value, $use_default); | |
| 88 | + } | |
| 89 | + break; | |
| 90 | + case 'STS_ID': | |
| 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 ID | |
| 101 | + * updates the registration status and ALSO... | |
| 102 | + * calls reserve_registration_space() if the reg status changes TO approved from any other reg status | |
| 103 | + * calls release_registration_space() if the reg status changes FROM approved to any other reg status | |
| 104 | + * | |
| 105 | + * @param string $new_STS_ID | |
| 106 | + * @param boolean $use_default | |
| 107 | + * @return bool | |
| 108 | + * @throws \RuntimeException | |
| 109 | + * @throws \EE_Error | |
| 110 | + */ | |
| 111 | + public function set_status($new_STS_ID = null, $use_default = false) | |
| 112 | +	{ | |
| 113 | + // get current REG_Status | |
| 114 | + $old_STS_ID = $this->status_ID(); | |
| 115 | + // if status has changed | |
| 116 | + if ($old_STS_ID !== $new_STS_ID // and that status has actually changed | |
| 117 | + && ! empty($old_STS_ID) // and that old status is actually set | |
| 118 | + && ! empty($new_STS_ID) // as well as the new status | |
| 119 | + && $this->ID() // ensure registration is in the db | |
| 120 | +		) { | |
| 121 | + // TO approved | |
| 122 | +			if ($new_STS_ID === EEM_Registration::status_id_approved) { | |
| 123 | + // reserve a space by incrementing ticket and datetime sold values | |
| 124 | + $this->_reserve_registration_space(); | |
| 125 | +				do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID); | |
| 126 | + // OR FROM approved | |
| 127 | +			} elseif ($old_STS_ID === EEM_Registration::status_id_approved) { | |
| 128 | + // release a space by decrementing ticket and datetime sold values | |
| 129 | + $this->_release_registration_space(); | |
| 130 | +				do_action('AHEE__EE_Registration__set_status__from_approved', $this, $old_STS_ID, $new_STS_ID); | |
| 131 | + } | |
| 132 | + // update status | |
| 133 | +			parent::set('STS_ID', $new_STS_ID, $use_default); | |
| 134 | + $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID); | |
| 135 | + /** @type EE_Transaction_Payments $transaction_payments */ | |
| 136 | +			$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); | |
| 137 | + $transaction_payments->recalculate_transaction_total($this->transaction(), false); | |
| 138 | + $this->transaction()->update_status_based_on_total_paid(true); | |
| 139 | +			do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID); | |
| 140 | + return true; | |
| 141 | + } | |
| 142 | + //even though the old value matches the new value, it's still good to | |
| 143 | + //allow the parent set method to have a say | |
| 144 | +		parent::set('STS_ID', $new_STS_ID, $use_default); | |
| 145 | + return true; | |
| 146 | + } | |
| 147 | + | |
| 148 | + | |
| 149 | + /** | |
| 150 | + * update REGs and TXN when cancelled or declined registrations involved | |
| 151 | + * | |
| 152 | + * @param string $new_STS_ID | |
| 153 | + * @param string $old_STS_ID | |
| 154 | + * @throws \EE_Error | |
| 155 | + */ | |
| 156 | + private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID) | |
| 157 | +	{ | |
| 158 | + // these reg statuses should not be considered in any calculations involving monies owing | |
| 159 | + $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); | |
| 160 | + // true if registration has been cancelled or declined | |
| 161 | + if (in_array($new_STS_ID, $closed_reg_statuses, true) | |
| 162 | + && ! in_array($old_STS_ID, $closed_reg_statuses, true) | |
| 163 | +		) { | |
| 164 | + /** @type EE_Registration_Processor $registration_processor */ | |
| 165 | +			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); | |
| 166 | + /** @type EE_Transaction_Processor $transaction_processor */ | |
| 167 | +			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); | |
| 168 | + // cancelled or declined registration | |
| 169 | + $registration_processor->update_registration_after_being_canceled_or_declined( | |
| 170 | + $this, | |
| 171 | + $closed_reg_statuses | |
| 172 | + ); | |
| 173 | + $transaction_processor->update_transaction_after_canceled_or_declined_registration( | |
| 174 | + $this, | |
| 175 | + $closed_reg_statuses, | |
| 176 | + false | |
| 177 | + ); | |
| 178 | +			do_action('AHEE__EE_Registration__set_status__canceled_or_declined', $this, $old_STS_ID, $new_STS_ID); | |
| 179 | + return; | |
| 180 | + } | |
| 181 | + // true if reinstating cancelled or declined registration | |
| 182 | + if (in_array($old_STS_ID, $closed_reg_statuses, true) | |
| 183 | + && ! in_array($new_STS_ID, $closed_reg_statuses, true) | |
| 184 | +		) { | |
| 185 | + /** @type EE_Registration_Processor $registration_processor */ | |
| 186 | +			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); | |
| 187 | + /** @type EE_Transaction_Processor $transaction_processor */ | |
| 188 | +			$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); | |
| 189 | + // reinstating cancelled or declined registration | |
| 190 | + $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( | |
| 191 | + $this, | |
| 192 | + $closed_reg_statuses | |
| 193 | + ); | |
| 194 | + $transaction_processor->update_transaction_after_reinstating_canceled_registration( | |
| 195 | + $this, | |
| 196 | + $closed_reg_statuses, | |
| 197 | + false | |
| 198 | + ); | |
| 199 | +			do_action('AHEE__EE_Registration__set_status__after_reinstated', $this, $old_STS_ID, $new_STS_ID); | |
| 200 | + } | |
| 201 | + } | |
| 202 | + | |
| 203 | + | |
| 204 | + /** | |
| 205 | + * get Status ID | |
| 206 | + */ | |
| 207 | + public function status_ID() | |
| 208 | +	{ | |
| 209 | +		return $this->get('STS_ID'); | |
| 210 | + } | |
| 211 | + | |
| 212 | + | |
| 213 | + /** | |
| 214 | + * increments this registration's related ticket sold and corresponding datetime sold values | |
| 215 | + * | |
| 216 | + * @return void | |
| 217 | + * @throws EE_Error | |
| 218 | + * @throws EntityNotFoundException | |
| 219 | + */ | |
| 220 | + private function _reserve_registration_space() | |
| 221 | +	{ | |
| 222 | + // reserved ticket and datetime counts will be decremented as sold counts are incremented | |
| 223 | + // so stop tracking that this reg has a ticket reserved | |
| 224 | + $this->release_reserved_ticket(); | |
| 225 | + $ticket = $this->ticket(); | |
| 226 | + $ticket->increase_sold(); | |
| 227 | + $ticket->save(); | |
| 228 | + // possibly set event status to sold out | |
| 229 | + $this->event()->perform_sold_out_status_check(); | |
| 230 | + } | |
| 231 | + | |
| 232 | + | |
| 233 | + /** | |
| 234 | + * Gets the ticket this registration is for | |
| 235 | + * | |
| 236 | + * @param boolean $include_archived whether to include archived tickets or not. | |
| 237 | + * @return EE_Ticket|EE_Base_Class | |
| 238 | + * @throws \EE_Error | |
| 239 | + */ | |
| 240 | + public function ticket($include_archived = true) | |
| 241 | +	{ | |
| 242 | + $query_params = array(); | |
| 243 | +		if ($include_archived) { | |
| 244 | + $query_params['default_where_conditions'] = 'none'; | |
| 245 | + } | |
| 246 | +		return $this->get_first_related('Ticket', $query_params); | |
| 247 | + } | |
| 248 | + | |
| 249 | + | |
| 250 | + /** | |
| 251 | + * Gets the event this registration is for | |
| 252 | + * | |
| 253 | + * @return EE_Event | |
| 254 | + * @throws EE_Error | |
| 255 | + * @throws EntityNotFoundException | |
| 256 | + */ | |
| 257 | + public function event() | |
| 258 | +	{ | |
| 259 | +		$event = $this->get_first_related('Event'); | |
| 260 | +		if (! $event instanceof \EE_Event) { | |
| 261 | +			throw new EntityNotFoundException('Event ID', $this->event_ID()); | |
| 262 | + } | |
| 263 | + return $event; | |
| 264 | + } | |
| 265 | + | |
| 266 | + | |
| 267 | + /** | |
| 268 | + * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond | |
| 269 | + * with the author of the event this registration is for. | |
| 270 | + * | |
| 271 | + * @since 4.5.0 | |
| 272 | + * @return int | |
| 273 | + * @throws EE_Error | |
| 274 | + * @throws EntityNotFoundException | |
| 275 | + */ | |
| 276 | + public function wp_user() | |
| 277 | +	{ | |
| 278 | + $event = $this->event(); | |
| 279 | +		if ($event instanceof EE_Event) { | |
| 280 | + return $event->wp_user(); | |
| 281 | + } | |
| 282 | + return 0; | |
| 283 | + } | |
| 284 | + | |
| 285 | + | |
| 286 | + /** | |
| 287 | + * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values | |
| 288 | + * | |
| 289 | + * @return void | |
| 290 | + * @throws \EE_Error | |
| 291 | + */ | |
| 292 | + private function _release_registration_space() | |
| 293 | +	{ | |
| 294 | + $ticket = $this->ticket(); | |
| 295 | + $ticket->decrease_sold(); | |
| 296 | + $ticket->save(); | |
| 297 | + } | |
| 298 | + | |
| 299 | + | |
| 300 | + /** | |
| 301 | + * tracks this registration's ticket reservation in extra meta | |
| 302 | + * and can increment related ticket reserved and corresponding datetime reserved values | |
| 303 | + * | |
| 304 | + * @param bool $update_ticket if true, will increment ticket and datetime reserved count | |
| 305 | + * @return void | |
| 306 | + * @throws \EE_Error | |
| 307 | + */ | |
| 308 | + public function reserve_ticket($update_ticket = false) | |
| 309 | +	{ | |
| 310 | +		if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) { | |
| 311 | + // PLZ NOTE: although checking $update_ticket first would be more efficient, | |
| 312 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first | |
| 313 | +			if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) { | |
| 314 | + $ticket = $this->ticket(); | |
| 315 | + $ticket->increase_reserved(); | |
| 316 | + $ticket->save(); | |
| 317 | + } | |
| 318 | + } | |
| 319 | + } | |
| 320 | + | |
| 321 | + | |
| 322 | + /** | |
| 323 | + * stops tracking this registration's ticket reservation in extra meta | |
| 324 | + * decrements (subtracts) related ticket reserved and corresponding datetime reserved values | |
| 325 | + * | |
| 326 | + * @param bool $update_ticket if true, will decrement ticket and datetime reserved count | |
| 327 | + * @return void | |
| 328 | + * @throws \EE_Error | |
| 329 | + */ | |
| 330 | + public function release_reserved_ticket($update_ticket = false) | |
| 331 | +	{ | |
| 332 | +		if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) { | |
| 333 | + // PLZ NOTE: although checking $update_ticket first would be more efficient, | |
| 334 | + // we NEED to ALWAYS call delete_extra_meta(), which is why that is done first | |
| 335 | +			if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) { | |
| 336 | + $ticket = $this->ticket(); | |
| 337 | + $ticket->decrease_reserved(); | |
| 338 | + $ticket->save(); | |
| 339 | + } | |
| 340 | + } | |
| 341 | + } | |
| 342 | + | |
| 343 | + | |
| 344 | + /** | |
| 345 | + * Set Attendee ID | |
| 346 | + * | |
| 347 | + * @param int $ATT_ID Attendee ID | |
| 348 | + * @throws EE_Error | |
| 349 | + * @throws RuntimeException | |
| 350 | + */ | |
| 351 | + public function set_attendee_id($ATT_ID = 0) | |
| 352 | +	{ | |
| 353 | +		$this->set('ATT_ID', $ATT_ID); | |
| 354 | + } | |
| 355 | + | |
| 356 | + | |
| 357 | + /** | |
| 358 | + * Set Transaction ID | |
| 359 | + * | |
| 360 | + * @param int $TXN_ID Transaction ID | |
| 361 | + * @throws EE_Error | |
| 362 | + * @throws RuntimeException | |
| 363 | + */ | |
| 364 | + public function set_transaction_id($TXN_ID = 0) | |
| 365 | +	{ | |
| 366 | +		$this->set('TXN_ID', $TXN_ID); | |
| 367 | + } | |
| 368 | + | |
| 369 | + | |
| 370 | + /** | |
| 371 | + * Set Session | |
| 372 | + * | |
| 373 | + * @param string $REG_session PHP Session ID | |
| 374 | + * @throws EE_Error | |
| 375 | + * @throws RuntimeException | |
| 376 | + */ | |
| 377 | + public function set_session($REG_session = '') | |
| 378 | +	{ | |
| 379 | +		$this->set('REG_session', $REG_session); | |
| 380 | + } | |
| 381 | + | |
| 382 | + | |
| 383 | + /** | |
| 384 | + * Set Registration URL Link | |
| 385 | + * | |
| 386 | + * @param string $REG_url_link Registration URL Link | |
| 387 | + * @throws EE_Error | |
| 388 | + * @throws RuntimeException | |
| 389 | + */ | |
| 390 | + public function set_reg_url_link($REG_url_link = '') | |
| 391 | +	{ | |
| 392 | +		$this->set('REG_url_link', $REG_url_link); | |
| 393 | + } | |
| 394 | + | |
| 395 | + | |
| 396 | + /** | |
| 397 | + * Set Attendee Counter | |
| 398 | + * | |
| 399 | + * @param int $REG_count Primary Attendee | |
| 400 | + * @throws EE_Error | |
| 401 | + * @throws RuntimeException | |
| 402 | + */ | |
| 403 | + public function set_count($REG_count = 1) | |
| 404 | +	{ | |
| 405 | +		$this->set('REG_count', $REG_count); | |
| 406 | + } | |
| 407 | + | |
| 408 | + | |
| 409 | + /** | |
| 410 | + * Set Group Size | |
| 411 | + * | |
| 412 | + * @param boolean $REG_group_size Group Registration | |
| 413 | + * @throws EE_Error | |
| 414 | + * @throws RuntimeException | |
| 415 | + */ | |
| 416 | + public function set_group_size($REG_group_size = false) | |
| 417 | +	{ | |
| 418 | +		$this->set('REG_group_size', $REG_group_size); | |
| 419 | + } | |
| 420 | + | |
| 421 | + | |
| 422 | + /** | |
| 423 | + * is_not_approved - convenience method that returns TRUE if REG status ID == | |
| 424 | + * EEM_Registration::status_id_not_approved | |
| 425 | + * | |
| 426 | + * @return boolean | |
| 427 | + */ | |
| 428 | + public function is_not_approved() | |
| 429 | +	{ | |
| 430 | + return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; | |
| 431 | + } | |
| 432 | + | |
| 433 | + | |
| 434 | + /** | |
| 435 | + * is_pending_payment - convenience method that returns TRUE if REG status ID == | |
| 436 | + * EEM_Registration::status_id_pending_payment | |
| 437 | + * | |
| 438 | + * @return boolean | |
| 439 | + */ | |
| 440 | + public function is_pending_payment() | |
| 441 | +	{ | |
| 442 | + return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; | |
| 443 | + } | |
| 444 | + | |
| 445 | + | |
| 446 | + /** | |
| 447 | + * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved | |
| 448 | + * | |
| 449 | + * @return boolean | |
| 450 | + */ | |
| 451 | + public function is_approved() | |
| 452 | +	{ | |
| 453 | + return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; | |
| 454 | + } | |
| 455 | + | |
| 456 | + | |
| 457 | + /** | |
| 458 | + * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled | |
| 459 | + * | |
| 460 | + * @return boolean | |
| 461 | + */ | |
| 462 | + public function is_cancelled() | |
| 463 | +	{ | |
| 464 | + return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; | |
| 465 | + } | |
| 466 | + | |
| 467 | + | |
| 468 | + /** | |
| 469 | + * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined | |
| 470 | + * | |
| 471 | + * @return boolean | |
| 472 | + */ | |
| 473 | + public function is_declined() | |
| 474 | +	{ | |
| 475 | + return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; | |
| 476 | + } | |
| 477 | + | |
| 478 | + | |
| 479 | + /** | |
| 480 | + * is_incomplete - convenience method that returns TRUE if REG status ID == | |
| 481 | + * EEM_Registration::status_id_incomplete | |
| 482 | + * | |
| 483 | + * @return boolean | |
| 484 | + */ | |
| 485 | + public function is_incomplete() | |
| 486 | +	{ | |
| 487 | + return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; | |
| 488 | + } | |
| 489 | + | |
| 490 | + | |
| 491 | + /** | |
| 492 | + * Set Registration Date | |
| 493 | + * | |
| 494 | + * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of | |
| 495 | + * Date | |
| 496 | + * @throws EE_Error | |
| 497 | + * @throws RuntimeException | |
| 498 | + */ | |
| 499 | + public function set_reg_date($REG_date = false) | |
| 500 | +	{ | |
| 501 | +		$this->set('REG_date', $REG_date); | |
| 502 | + } | |
| 503 | + | |
| 504 | + | |
| 505 | + /** | |
| 506 | + * Set final price owing for this registration after all ticket/price modifications | |
| 507 | + * | |
| 508 | + * @access public | |
| 509 | + * @param float $REG_final_price | |
| 510 | + * @throws EE_Error | |
| 511 | + * @throws RuntimeException | |
| 512 | + */ | |
| 513 | + public function set_final_price($REG_final_price = 0.00) | |
| 514 | +	{ | |
| 515 | +		$this->set('REG_final_price', $REG_final_price); | |
| 516 | + } | |
| 517 | + | |
| 518 | + | |
| 519 | + /** | |
| 520 | + * Set amount paid towards this registration's final price | |
| 521 | + * | |
| 522 | + * @access public | |
| 523 | + * @param float $REG_paid | |
| 524 | + * @throws EE_Error | |
| 525 | + * @throws RuntimeException | |
| 526 | + */ | |
| 527 | + public function set_paid($REG_paid = 0.00) | |
| 528 | +	{ | |
| 529 | +		$this->set('REG_paid', $REG_paid); | |
| 530 | + } | |
| 531 | + | |
| 532 | + | |
| 533 | + /** | |
| 534 | + * Attendee Is Going | |
| 535 | + * | |
| 536 | + * @param boolean $REG_att_is_going Attendee Is Going | |
| 537 | + * @throws EE_Error | |
| 538 | + * @throws RuntimeException | |
| 539 | + */ | |
| 540 | + public function set_att_is_going($REG_att_is_going = false) | |
| 541 | +	{ | |
| 542 | +		$this->set('REG_att_is_going', $REG_att_is_going); | |
| 543 | + } | |
| 544 | + | |
| 545 | + | |
| 546 | + /** | |
| 547 | + * Gets the related attendee | |
| 548 | + * | |
| 549 | + * @return EE_Attendee | |
| 550 | + * @throws EE_Error | |
| 551 | + */ | |
| 552 | + public function attendee() | |
| 553 | +	{ | |
| 554 | +		return $this->get_first_related('Attendee'); | |
| 555 | + } | |
| 556 | + | |
| 557 | + | |
| 558 | + /** | |
| 559 | + * get Event ID | |
| 560 | + */ | |
| 561 | + public function event_ID() | |
| 562 | +	{ | |
| 563 | +		return $this->get('EVT_ID'); | |
| 564 | + } | |
| 565 | + | |
| 566 | + | |
| 567 | + /** | |
| 568 | + * get Event ID | |
| 569 | + */ | |
| 570 | + public function event_name() | |
| 571 | +	{ | |
| 572 | + $event = $this->event_obj(); | |
| 573 | +		if ($event) { | |
| 574 | + return $event->name(); | |
| 575 | +		} else { | |
| 576 | + return null; | |
| 577 | + } | |
| 578 | + } | |
| 579 | + | |
| 580 | + | |
| 581 | + /** | |
| 582 | + * Fetches the event this registration is for | |
| 583 | + * | |
| 584 | + * @return EE_Event | |
| 585 | + * @throws EE_Error | |
| 586 | + */ | |
| 587 | + public function event_obj() | |
| 588 | +	{ | |
| 589 | +		return $this->get_first_related('Event'); | |
| 590 | + } | |
| 591 | + | |
| 592 | + | |
| 593 | + /** | |
| 594 | + * get Attendee ID | |
| 595 | + */ | |
| 596 | + public function attendee_ID() | |
| 597 | +	{ | |
| 598 | +		return $this->get('ATT_ID'); | |
| 599 | + } | |
| 600 | + | |
| 601 | + | |
| 602 | + /** | |
| 603 | + * get PHP Session ID | |
| 604 | + */ | |
| 605 | + public function session_ID() | |
| 606 | +	{ | |
| 607 | +		return $this->get('REG_session'); | |
| 608 | + } | |
| 609 | + | |
| 610 | + | |
| 611 | + /** | |
| 612 | + * Gets the string which represents the URL trigger for the receipt template in the message template system. | |
| 613 | + * | |
| 614 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. | |
| 615 | + * @return string | |
| 616 | + */ | |
| 617 | + public function receipt_url($messenger = 'html') | |
| 618 | +	{ | |
| 619 | + | |
| 620 | + /** | |
| 621 | + * The below will be deprecated one version after this. We check first if there is a custom receipt template | |
| 622 | + * already in use on old system. If there is then we just return the standard url for it. | |
| 623 | + * | |
| 624 | + * @since 4.5.0 | |
| 625 | + */ | |
| 626 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; | |
| 627 | + $has_custom = EEH_Template::locate_template( | |
| 628 | + $template_relative_path, | |
| 629 | + array(), | |
| 630 | + true, | |
| 631 | + true, | |
| 632 | + true | |
| 633 | + ); | |
| 634 | + | |
| 635 | +		if ($has_custom) { | |
| 636 | +			return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); | |
| 637 | + } | |
| 638 | +		return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); | |
| 639 | + } | |
| 640 | + | |
| 641 | + | |
| 642 | + /** | |
| 643 | + * Gets the string which represents the URL trigger for the invoice template in the message template system. | |
| 644 | + * | |
| 645 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. | |
| 646 | + * @return string | |
| 647 | + * @throws EE_Error | |
| 648 | + */ | |
| 649 | + public function invoice_url($messenger = 'html') | |
| 650 | +	{ | |
| 651 | + /** | |
| 652 | + * The below will be deprecated one version after this. We check first if there is a custom invoice template | |
| 653 | + * already in use on old system. If there is then we just return the standard url for it. | |
| 654 | + * | |
| 655 | + * @since 4.5.0 | |
| 656 | + */ | |
| 657 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; | |
| 658 | + $has_custom = EEH_Template::locate_template( | |
| 659 | + $template_relative_path, | |
| 660 | + array(), | |
| 661 | + true, | |
| 662 | + true, | |
| 663 | + true | |
| 664 | + ); | |
| 665 | + | |
| 666 | +		if ($has_custom) { | |
| 667 | +			if ($messenger == 'html') { | |
| 668 | +				return $this->invoice_url('launch'); | |
| 669 | + } | |
| 670 | + $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; | |
| 671 | + | |
| 672 | +			$query_args = array('ee' => $route, 'id' => $this->reg_url_link()); | |
| 673 | +			if ($messenger == 'html') { | |
| 674 | + $query_args['html'] = true; | |
| 675 | + } | |
| 676 | + return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); | |
| 677 | + } | |
| 678 | +		return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); | |
| 679 | + } | |
| 680 | + | |
| 681 | + | |
| 682 | + /** | |
| 683 | + * get Registration URL Link | |
| 684 | + * | |
| 685 | + * @access public | |
| 686 | + * @return string | |
| 687 | + * @throws \EE_Error | |
| 688 | + */ | |
| 689 | + public function reg_url_link() | |
| 690 | +	{ | |
| 691 | +		return (string) $this->get('REG_url_link'); | |
| 692 | + } | |
| 693 | + | |
| 694 | + | |
| 695 | + /** | |
| 696 | + * Echoes out invoice_url() | |
| 697 | + * | |
| 698 | + * @param string $type 'download','launch', or 'html' (default is 'launch') | |
| 699 | + * @return void | |
| 700 | + * @throws EE_Error | |
| 701 | + */ | |
| 702 | + public function e_invoice_url($type = 'launch') | |
| 703 | +	{ | |
| 704 | + echo $this->invoice_url($type); | |
| 705 | + } | |
| 706 | + | |
| 707 | + | |
| 708 | + /** | |
| 709 | + * Echoes out payment_overview_url | |
| 710 | + */ | |
| 711 | + public function e_payment_overview_url() | |
| 712 | +	{ | |
| 713 | + echo $this->payment_overview_url(); | |
| 714 | + } | |
| 715 | + | |
| 716 | + | |
| 717 | + /** | |
| 718 | + * Gets the URL of the thank you page with this registration REG_url_link added as | |
| 719 | + * a query parameter | |
| 720 | + * | |
| 721 | + * @param bool $clear_session Set to true when you want to clear the session on revisiting the | |
| 722 | + * payment overview url. | |
| 723 | + * @return string | |
| 724 | + * @throws EE_Error | |
| 725 | + */ | |
| 726 | + public function payment_overview_url($clear_session = false) | |
| 727 | +	{ | |
| 728 | + return add_query_arg(array( | |
| 729 | + 'e_reg_url_link' => $this->reg_url_link(), | |
| 730 | + 'step' => 'payment_options', | |
| 731 | + 'revisit' => true, | |
| 732 | + 'clear_session' => (bool) $clear_session | |
| 733 | + ), EE_Registry::instance()->CFG->core->reg_page_url()); | |
| 734 | + } | |
| 735 | + | |
| 736 | + | |
| 737 | + /** | |
| 738 | + * Gets the URL of the thank you page with this registration REG_url_link added as | |
| 739 | + * a query parameter | |
| 740 | + * | |
| 741 | + * @return string | |
| 742 | + * @throws EE_Error | |
| 743 | + */ | |
| 744 | + public function edit_attendee_information_url() | |
| 745 | +	{ | |
| 746 | + return add_query_arg(array( | |
| 747 | + 'e_reg_url_link' => $this->reg_url_link(), | |
| 748 | + 'step' => 'attendee_information', | |
| 749 | + 'revisit' => true, | |
| 750 | + ), EE_Registry::instance()->CFG->core->reg_page_url()); | |
| 751 | + } | |
| 752 | + | |
| 753 | + | |
| 754 | + /** | |
| 755 | + * Simply generates and returns the appropriate admin_url link to edit this registration | |
| 756 | + * | |
| 757 | + * @return string | |
| 758 | + * @throws EE_Error | |
| 759 | + */ | |
| 760 | + public function get_admin_edit_url() | |
| 761 | +	{ | |
| 762 | + return EEH_URL::add_query_args_and_nonce(array( | |
| 763 | + 'page' => 'espresso_registrations', | |
| 764 | + 'action' => 'view_registration', | |
| 765 | + '_REG_ID' => $this->ID(), | |
| 766 | +		), admin_url('admin.php')); | |
| 767 | + } | |
| 768 | + | |
| 769 | + | |
| 770 | + /** | |
| 771 | + * is_primary_registrant? | |
| 772 | + */ | |
| 773 | + public function is_primary_registrant() | |
| 774 | +	{ | |
| 775 | +		return $this->get('REG_count') == 1 ? true : false; | |
| 776 | + } | |
| 777 | + | |
| 778 | + | |
| 779 | + /** | |
| 780 | + * This returns the primary registration object for this registration group (which may be this object). | |
| 781 | + * | |
| 782 | + * @return EE_Registration | |
| 783 | + * @throws EE_Error | |
| 784 | + */ | |
| 785 | + public function get_primary_registration() | |
| 786 | +	{ | |
| 787 | +		if ($this->is_primary_registrant()) { | |
| 788 | + return $this; | |
| 789 | + } | |
| 790 | + | |
| 791 | + //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 | |
| 792 | + /** @var EE_Registration $primary_registrant */ | |
| 793 | + $primary_registrant = EEM_Registration::instance()->get_one(array( | |
| 794 | + array( | |
| 795 | + 'TXN_ID' => $this->transaction_ID(), | |
| 796 | + 'REG_count' => 1, | |
| 797 | + ), | |
| 798 | + )); | |
| 799 | + return $primary_registrant; | |
| 800 | + } | |
| 801 | + | |
| 802 | + | |
| 803 | + /** | |
| 804 | + * get Attendee Number | |
| 805 | + * | |
| 806 | + * @access public | |
| 807 | + */ | |
| 808 | + public function count() | |
| 809 | +	{ | |
| 810 | +		return $this->get('REG_count'); | |
| 811 | + } | |
| 812 | + | |
| 813 | + | |
| 814 | + /** | |
| 815 | + * get Group Size | |
| 816 | + */ | |
| 817 | + public function group_size() | |
| 818 | +	{ | |
| 819 | +		return $this->get('REG_group_size'); | |
| 820 | + } | |
| 821 | + | |
| 822 | + | |
| 823 | + /** | |
| 824 | + * get Registration Date | |
| 825 | + */ | |
| 826 | + public function date() | |
| 827 | +	{ | |
| 828 | +		return $this->get('REG_date'); | |
| 829 | + } | |
| 830 | + | |
| 831 | + | |
| 832 | + /** | |
| 833 | + * gets a pretty date | |
| 834 | + * | |
| 835 | + * @param string $date_format | |
| 836 | + * @param string $time_format | |
| 837 | + * @return string | |
| 838 | + * @throws EE_Error | |
| 839 | + */ | |
| 840 | + public function pretty_date($date_format = null, $time_format = null) | |
| 841 | +	{ | |
| 842 | +		return $this->get_datetime('REG_date', $date_format, $time_format); | |
| 843 | + } | |
| 844 | + | |
| 845 | + | |
| 846 | + /** | |
| 847 | + * final_price | |
| 848 | + * the registration's share of the transaction total, so that the | |
| 849 | + * sum of all the transaction's REG_final_prices equal the transaction's total | |
| 850 | + * | |
| 851 | + * @return float | |
| 852 | + * @throws EE_Error | |
| 853 | + */ | |
| 854 | + public function final_price() | |
| 855 | +	{ | |
| 856 | +		return $this->get('REG_final_price'); | |
| 857 | + } | |
| 858 | + | |
| 859 | + | |
| 860 | + /** | |
| 861 | + * pretty_final_price | |
| 862 | + * final price as formatted string, with correct decimal places and currency symbol | |
| 863 | + * | |
| 864 | + * @return string | |
| 865 | + * @throws EE_Error | |
| 866 | + */ | |
| 867 | + public function pretty_final_price() | |
| 868 | +	{ | |
| 869 | +		return $this->get_pretty('REG_final_price'); | |
| 870 | + } | |
| 871 | + | |
| 872 | + | |
| 873 | + /** | |
| 874 | + * get paid (yeah) | |
| 875 | + * | |
| 876 | + * @return float | |
| 877 | + * @throws EE_Error | |
| 878 | + */ | |
| 879 | + public function paid() | |
| 880 | +	{ | |
| 881 | +		return $this->get('REG_paid'); | |
| 882 | + } | |
| 883 | + | |
| 884 | + | |
| 885 | + /** | |
| 886 | + * pretty_paid | |
| 887 | + * | |
| 888 | + * @return float | |
| 889 | + * @throws EE_Error | |
| 890 | + */ | |
| 891 | + public function pretty_paid() | |
| 892 | +	{ | |
| 893 | +		return $this->get_pretty('REG_paid'); | |
| 894 | + } | |
| 895 | + | |
| 896 | + | |
| 897 | + /** | |
| 898 | + * owes_monies_and_can_pay | |
| 899 | + * whether or not this registration has monies owing and it's' status allows payment | |
| 900 | + * | |
| 901 | + * @param array $requires_payment | |
| 902 | + * @return bool | |
| 903 | + * @throws EE_Error | |
| 904 | + */ | |
| 905 | + public function owes_monies_and_can_pay($requires_payment = array()) | |
| 906 | +	{ | |
| 907 | + // these reg statuses require payment (if event is not free) | |
| 908 | + $requires_payment = ! empty($requires_payment) | |
| 909 | + ? $requires_payment | |
| 910 | + : EEM_Registration::reg_statuses_that_allow_payment(); | |
| 911 | + if (in_array($this->status_ID(), $requires_payment) && | |
| 912 | + $this->final_price() != 0 && | |
| 913 | + $this->final_price() != $this->paid() | |
| 914 | +		) { | |
| 915 | + return true; | |
| 916 | +		} else { | |
| 917 | + return false; | |
| 918 | + } | |
| 919 | + } | |
| 920 | + | |
| 921 | + | |
| 922 | + /** | |
| 923 | + * Prints out the return value of $this->pretty_status() | |
| 924 | + * | |
| 925 | + * @param bool $show_icons | |
| 926 | + * @return void | |
| 927 | + * @throws EE_Error | |
| 928 | + */ | |
| 929 | + public function e_pretty_status($show_icons = false) | |
| 930 | +	{ | |
| 931 | + echo $this->pretty_status($show_icons); | |
| 932 | + } | |
| 933 | + | |
| 934 | + | |
| 935 | + /** | |
| 936 | + * Returns a nice version of the status for displaying to customers | |
| 937 | + * | |
| 938 | + * @param bool $show_icons | |
| 939 | + * @return string | |
| 940 | + * @throws EE_Error | |
| 941 | + */ | |
| 942 | + public function pretty_status($show_icons = false) | |
| 943 | +	{ | |
| 944 | + $status = EEM_Status::instance()->localized_status( | |
| 945 | +			array($this->status_ID() => esc_html__('unknown', 'event_espresso')), | |
| 946 | + false, | |
| 947 | + 'sentence' | |
| 948 | + ); | |
| 949 | + $icon = ''; | |
| 950 | +		switch ($this->status_ID()) { | |
| 951 | + case EEM_Registration::status_id_approved: | |
| 952 | + $icon = $show_icons | |
| 953 | + ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' | |
| 954 | + : ''; | |
| 955 | + break; | |
| 956 | + case EEM_Registration::status_id_pending_payment: | |
| 957 | + $icon = $show_icons | |
| 958 | + ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' | |
| 959 | + : ''; | |
| 960 | + break; | |
| 961 | + case EEM_Registration::status_id_not_approved: | |
| 962 | + $icon = $show_icons | |
| 963 | + ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' | |
| 964 | + : ''; | |
| 965 | + break; | |
| 966 | + case EEM_Registration::status_id_cancelled: | |
| 967 | + $icon = $show_icons | |
| 968 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' | |
| 969 | + : ''; | |
| 970 | + break; | |
| 971 | + case EEM_Registration::status_id_incomplete: | |
| 972 | + $icon = $show_icons | |
| 973 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' | |
| 974 | + : ''; | |
| 975 | + break; | |
| 976 | + case EEM_Registration::status_id_declined: | |
| 977 | + $icon = $show_icons | |
| 978 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' | |
| 979 | + : ''; | |
| 980 | + break; | |
| 981 | + case EEM_Registration::status_id_wait_list: | |
| 982 | + $icon = $show_icons | |
| 983 | + ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' | |
| 984 | + : ''; | |
| 985 | + break; | |
| 986 | + } | |
| 987 | + return $icon . $status[$this->status_ID()]; | |
| 988 | + } | |
| 989 | + | |
| 990 | + | |
| 991 | + /** | |
| 992 | + * get Attendee Is Going | |
| 993 | + */ | |
| 994 | + public function att_is_going() | |
| 995 | +	{ | |
| 996 | +		return $this->get('REG_att_is_going'); | |
| 997 | + } | |
| 998 | + | |
| 999 | + | |
| 1000 | + /** | |
| 1001 | + * Gets related answers | |
| 1002 | + * | |
| 1003 | + * @param array $query_params like EEM_Base::get_all | |
| 1004 | + * @return EE_Answer[] | |
| 1005 | + * @throws EE_Error | |
| 1006 | + */ | |
| 1007 | + public function answers($query_params = null) | |
| 1008 | +	{ | |
| 1009 | +		return $this->get_many_related('Answer', $query_params); | |
| 1010 | + } | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + /** | |
| 1014 | + * Gets the registration's answer value to the specified question | |
| 1015 | + * (either the question's ID or a question object) | |
| 1016 | + * | |
| 1017 | + * @param EE_Question|int $question | |
| 1018 | + * @param bool $pretty_value | |
| 1019 | + * @return array|string if pretty_value= true, the result will always be a string | |
| 1020 | + * (because the answer might be an array of answer values, so passing pretty_value=true | |
| 1021 | + * will convert it into some kind of string) | |
| 1022 | + * @throws EE_Error | |
| 1023 | + */ | |
| 1024 | + public function answer_value_to_question($question, $pretty_value = true) | |
| 1025 | +	{ | |
| 1026 | + $question_id = EEM_Question::instance()->ensure_is_ID($question); | |
| 1027 | + return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); | |
| 1028 | + } | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + /** | |
| 1032 | + * question_groups | |
| 1033 | + * returns an array of EE_Question_Group objects for this registration | |
| 1034 | + * | |
| 1035 | + * @return EE_Question_Group[] | |
| 1036 | + * @throws EE_Error | |
| 1037 | + * @throws EntityNotFoundException | |
| 1038 | + */ | |
| 1039 | + public function question_groups() | |
| 1040 | +	{ | |
| 1041 | + $question_groups = array(); | |
| 1042 | +		if ($this->event() instanceof EE_Event) { | |
| 1043 | + $question_groups = $this->event()->question_groups( | |
| 1044 | + array( | |
| 1045 | + array( | |
| 1046 | + 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, | |
| 1047 | + ), | |
| 1048 | +					'order_by' => array('QSG_order' => 'ASC'), | |
| 1049 | + ) | |
| 1050 | + ); | |
| 1051 | + } | |
| 1052 | + return $question_groups; | |
| 1053 | + } | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + /** | |
| 1057 | + * count_question_groups | |
| 1058 | + * returns a count of the number of EE_Question_Group objects for this registration | |
| 1059 | + * | |
| 1060 | + * @return int | |
| 1061 | + * @throws EE_Error | |
| 1062 | + * @throws EntityNotFoundException | |
| 1063 | + */ | |
| 1064 | + public function count_question_groups() | |
| 1065 | +	{ | |
| 1066 | + $qg_count = 0; | |
| 1067 | +		if ($this->event() instanceof EE_Event) { | |
| 1068 | + $qg_count = $this->event()->count_related( | |
| 1069 | + 'Question_Group', | |
| 1070 | + array( | |
| 1071 | + array( | |
| 1072 | + 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, | |
| 1073 | + ), | |
| 1074 | + ) | |
| 1075 | + ); | |
| 1076 | + } | |
| 1077 | + return $qg_count; | |
| 1078 | + } | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + /** | |
| 1082 | + * Returns the registration date in the 'standard' string format | |
| 1083 | + * (function may be improved in the future to allow for different formats and timezones) | |
| 1084 | + * | |
| 1085 | + * @return string | |
| 1086 | + * @throws EE_Error | |
| 1087 | + */ | |
| 1088 | + public function reg_date() | |
| 1089 | +	{ | |
| 1090 | +		return $this->get_datetime('REG_date'); | |
| 1091 | + } | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + /** | |
| 1095 | + * Gets the datetime-ticket for this registration (ie, it can be used to isolate | |
| 1096 | + * the ticket this registration purchased, or the datetime they have registered | |
| 1097 | + * to attend) | |
| 1098 | + * | |
| 1099 | + * @return EE_Datetime_Ticket | |
| 1100 | + * @throws EE_Error | |
| 1101 | + */ | |
| 1102 | + public function datetime_ticket() | |
| 1103 | +	{ | |
| 1104 | +		return $this->get_first_related('Datetime_Ticket'); | |
| 1105 | + } | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + /** | |
| 1109 | + * Sets the registration's datetime_ticket. | |
| 1110 | + * | |
| 1111 | + * @param EE_Datetime_Ticket $datetime_ticket | |
| 1112 | + * @return EE_Datetime_Ticket | |
| 1113 | + * @throws EE_Error | |
| 1114 | + */ | |
| 1115 | + public function set_datetime_ticket($datetime_ticket) | |
| 1116 | +	{ | |
| 1117 | + return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); | |
| 1118 | + } | |
| 1119 | + | |
| 1120 | + /** | |
| 1121 | + * Gets deleted | |
| 1122 | + * | |
| 1123 | + * @return bool | |
| 1124 | + * @throws EE_Error | |
| 1125 | + */ | |
| 1126 | + public function deleted() | |
| 1127 | +	{ | |
| 1128 | +		return $this->get('REG_deleted'); | |
| 1129 | + } | |
| 1130 | + | |
| 1131 | + /** | |
| 1132 | + * Sets deleted | |
| 1133 | + * | |
| 1134 | + * @param boolean $deleted | |
| 1135 | + * @return bool | |
| 1136 | + * @throws EE_Error | |
| 1137 | + * @throws RuntimeException | |
| 1138 | + */ | |
| 1139 | + public function set_deleted($deleted) | |
| 1140 | +	{ | |
| 1141 | +		if ($deleted) { | |
| 1142 | + $this->delete(); | |
| 1143 | +		} else { | |
| 1144 | + $this->restore(); | |
| 1145 | + } | |
| 1146 | + } | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + /** | |
| 1150 | + * Get the status object of this object | |
| 1151 | + * | |
| 1152 | + * @return EE_Status | |
| 1153 | + * @throws EE_Error | |
| 1154 | + */ | |
| 1155 | + public function status_obj() | |
| 1156 | +	{ | |
| 1157 | +		return $this->get_first_related('Status'); | |
| 1158 | + } | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + /** | |
| 1162 | + * Returns the number of times this registration has checked into any of the datetimes | |
| 1163 | + * its available for | |
| 1164 | + * | |
| 1165 | + * @return int | |
| 1166 | + * @throws EE_Error | |
| 1167 | + */ | |
| 1168 | + public function count_checkins() | |
| 1169 | +	{ | |
| 1170 | + return $this->get_model()->count_related($this, 'Checkin'); | |
| 1171 | + } | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + /** | |
| 1175 | + * Returns the number of current Check-ins this registration is checked into for any of the datetimes the | |
| 1176 | + * registration is for. Note, this is ONLY checked in (does not include checkedout) | |
| 1177 | + * | |
| 1178 | + * @return int | |
| 1179 | + * @throws EE_Error | |
| 1180 | + */ | |
| 1181 | + public function count_checkins_not_checkedout() | |
| 1182 | +	{ | |
| 1183 | +		return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); | |
| 1184 | + } | |
| 1185 | + | |
| 1186 | + | |
| 1187 | + /** | |
| 1188 | + * The purpose of this method is simply to check whether this registration can checkin to the given datetime. | |
| 1189 | + * | |
| 1190 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against | |
| 1191 | + * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also | |
| 1192 | + * consider registration status as well as datetime access. | |
| 1193 | + * @return bool | |
| 1194 | + * @throws EE_Error | |
| 1195 | + */ | |
| 1196 | + public function can_checkin($DTT_OR_ID, $check_approved = true) | |
| 1197 | +	{ | |
| 1198 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); | |
| 1199 | + | |
| 1200 | + //first check registration status | |
| 1201 | +		if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { | |
| 1202 | + return false; | |
| 1203 | + } | |
| 1204 | + //is there a datetime ticket that matches this dtt_ID? | |
| 1205 | + if (! (EEM_Datetime_Ticket::instance()->exists(array( | |
| 1206 | + array( | |
| 1207 | +				'TKT_ID' => $this->get('TKT_ID'), | |
| 1208 | + 'DTT_ID' => $DTT_ID, | |
| 1209 | + ), | |
| 1210 | + ))) | |
| 1211 | +		) { | |
| 1212 | + return false; | |
| 1213 | + } | |
| 1214 | + | |
| 1215 | + //final check is against TKT_uses | |
| 1216 | + return $this->verify_can_checkin_against_TKT_uses($DTT_ID); | |
| 1217 | + } | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + /** | |
| 1221 | + * This method verifies whether the user can checkin for the given datetime considering the max uses value set on | |
| 1222 | + * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the | |
| 1223 | + * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, | |
| 1224 | + * then return false. Otherwise return true. | |
| 1225 | + * | |
| 1226 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against | |
| 1227 | + * @return bool true means can checkin. false means cannot checkin. | |
| 1228 | + * @throws EE_Error | |
| 1229 | + */ | |
| 1230 | + public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) | |
| 1231 | +	{ | |
| 1232 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); | |
| 1233 | + | |
| 1234 | +		if (! $DTT_ID) { | |
| 1235 | + return false; | |
| 1236 | + } | |
| 1237 | + | |
| 1238 | + $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; | |
| 1239 | + | |
| 1240 | + // if max uses is not set or equals infinity then return true cause its not a factor for whether user can | |
| 1241 | + // check-in or not. | |
| 1242 | +		if (! $max_uses || $max_uses === EE_INF) { | |
| 1243 | + return true; | |
| 1244 | + } | |
| 1245 | + | |
| 1246 | + //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just | |
| 1247 | + //go ahead and toggle. | |
| 1248 | +		if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { | |
| 1249 | + return true; | |
| 1250 | + } | |
| 1251 | + | |
| 1252 | + //made it here so the last check is whether the number of checkins per unique datetime on this registration | |
| 1253 | + //disallows further check-ins. | |
| 1254 | + $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array( | |
| 1255 | + array( | |
| 1256 | + 'REG_ID' => $this->ID(), | |
| 1257 | + 'CHK_in' => true, | |
| 1258 | + ), | |
| 1259 | + ), 'DTT_ID', true); | |
| 1260 | + // checkins have already reached their max number of uses | |
| 1261 | + // so registrant can NOT checkin | |
| 1262 | +		if ($count_unique_dtt_checkins >= $max_uses) { | |
| 1263 | + EE_Error::add_error( | |
| 1264 | + esc_html__( | |
| 1265 | + 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', | |
| 1266 | + 'event_espresso' | |
| 1267 | + ), | |
| 1268 | + __FILE__, | |
| 1269 | + __FUNCTION__, | |
| 1270 | + __LINE__ | |
| 1271 | + ); | |
| 1272 | + return false; | |
| 1273 | + } | |
| 1274 | + return true; | |
| 1275 | + } | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + /** | |
| 1279 | + * toggle Check-in status for this registration | |
| 1280 | + * Check-ins are toggled in the following order: | |
| 1281 | + * never checked in -> checked in | |
| 1282 | + * checked in -> checked out | |
| 1283 | + * checked out -> checked in | |
| 1284 | + * | |
| 1285 | + * @param int $DTT_ID include specific datetime to toggle Check-in for. | |
| 1286 | + * If not included or null, then it is assumed latest datetime is being toggled. | |
| 1287 | + * @param bool $verify If true then can_checkin() is used to verify whether the person | |
| 1288 | + * can be checked in or not. Otherwise this forces change in checkin status. | |
| 1289 | + * @return bool|int the chk_in status toggled to OR false if nothing got changed. | |
| 1290 | + * @throws EE_Error | |
| 1291 | + */ | |
| 1292 | + public function toggle_checkin_status($DTT_ID = null, $verify = false) | |
| 1293 | +	{ | |
| 1294 | +		if (empty($DTT_ID)) { | |
| 1295 | + $datetime = $this->get_latest_related_datetime(); | |
| 1296 | + $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; | |
| 1297 | + // verify the registration can checkin for the given DTT_ID | |
| 1298 | +		} elseif (! $this->can_checkin($DTT_ID, $verify)) { | |
| 1299 | + EE_Error::add_error( | |
| 1300 | + sprintf( | |
| 1301 | + esc_html__( | |
| 1302 | + 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', | |
| 1303 | + 'event_espresso' | |
| 1304 | + ), | |
| 1305 | + $this->ID(), | |
| 1306 | + $DTT_ID | |
| 1307 | + ), | |
| 1308 | + __FILE__, | |
| 1309 | + __FUNCTION__, | |
| 1310 | + __LINE__ | |
| 1311 | + ); | |
| 1312 | + return false; | |
| 1313 | + } | |
| 1314 | + $status_paths = array( | |
| 1315 | + EE_Registration::checkin_status_never => EE_Registration::checkin_status_in, | |
| 1316 | + EE_Registration::checkin_status_in => EE_Registration::checkin_status_out, | |
| 1317 | + EE_Registration::checkin_status_out => EE_Registration::checkin_status_in, | |
| 1318 | + ); | |
| 1319 | + //start by getting the current status so we know what status we'll be changing to. | |
| 1320 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); | |
| 1321 | + $status_to = $status_paths[$cur_status]; | |
| 1322 | + // database only records true for checked IN or false for checked OUT | |
| 1323 | + // no record ( null ) means checked in NEVER, but we obviously don't save that | |
| 1324 | + $new_status = $status_to === EE_Registration::checkin_status_in ? true : false; | |
| 1325 | + // add relation - note Check-ins are always creating new rows | |
| 1326 | + // because we are keeping track of Check-ins over time. | |
| 1327 | + // Eventually we'll probably want to show a list table | |
| 1328 | + // for the individual Check-ins so that they can be managed. | |
| 1329 | + $checkin = EE_Checkin::new_instance(array( | |
| 1330 | + 'REG_ID' => $this->ID(), | |
| 1331 | + 'DTT_ID' => $DTT_ID, | |
| 1332 | + 'CHK_in' => $new_status, | |
| 1333 | + )); | |
| 1334 | + // if the record could not be saved then return false | |
| 1335 | +		if ($checkin->save() === 0) { | |
| 1336 | +			if (WP_DEBUG) { | |
| 1337 | + global $wpdb; | |
| 1338 | + $error = sprintf( | |
| 1339 | + esc_html__( | |
| 1340 | + 'Registration check in update failed because of the following database error: %1$s%2$s', | |
| 1341 | + 'event_espresso' | |
| 1342 | + ), | |
| 1343 | + '<br />', | |
| 1344 | + $wpdb->last_error | |
| 1345 | + ); | |
| 1346 | +			} else { | |
| 1347 | + $error = esc_html__( | |
| 1348 | + 'Registration check in update failed because of an unknown database error', | |
| 1349 | + 'event_espresso' | |
| 1350 | + ); | |
| 1351 | + } | |
| 1352 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); | |
| 1353 | + return false; | |
| 1354 | + } | |
| 1355 | + return $status_to; | |
| 1356 | + } | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + /** | |
| 1360 | + * Returns the latest datetime related to this registration (via the ticket attached to the registration). | |
| 1361 | + * "Latest" is defined by the `DTT_EVT_start` column. | |
| 1362 | + * | |
| 1363 | + * @return EE_Datetime|null | |
| 1364 | + * @throws \EE_Error | |
| 1365 | + */ | |
| 1366 | + public function get_latest_related_datetime() | |
| 1367 | +	{ | |
| 1368 | + return EEM_Datetime::instance()->get_one( | |
| 1369 | + array( | |
| 1370 | + array( | |
| 1371 | + 'Ticket.Registration.REG_ID' => $this->ID(), | |
| 1372 | + ), | |
| 1373 | +				'order_by' => array('DTT_EVT_start' => 'DESC'), | |
| 1374 | + ) | |
| 1375 | + ); | |
| 1376 | + } | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + /** | |
| 1380 | + * Returns the earliest datetime related to this registration (via the ticket attached to the registration). | |
| 1381 | + * "Earliest" is defined by the `DTT_EVT_start` column. | |
| 1382 | + * | |
| 1383 | + * @throws \EE_Error | |
| 1384 | + */ | |
| 1385 | + public function get_earliest_related_datetime() | |
| 1386 | +	{ | |
| 1387 | + return EEM_Datetime::instance()->get_one( | |
| 1388 | + array( | |
| 1389 | + array( | |
| 1390 | + 'Ticket.Registration.REG_ID' => $this->ID(), | |
| 1391 | + ), | |
| 1392 | +				'order_by' => array('DTT_EVT_start' => 'ASC'), | |
| 1393 | + ) | |
| 1394 | + ); | |
| 1395 | + } | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + /** | |
| 1399 | + * This method simply returns the check-in status for this registration and the given datetime. | |
| 1400 | + * If neither the datetime nor the checkin values are provided as arguments, | |
| 1401 | + * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. | |
| 1402 | + * | |
| 1403 | + * @param int $DTT_ID The ID of the datetime we're checking against | |
| 1404 | + * (if empty we'll get the primary datetime for | |
| 1405 | + * this registration (via event) and use it's ID); | |
| 1406 | + * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. | |
| 1407 | + * @return int Integer representing Check-in status. | |
| 1408 | + * @throws \EE_Error | |
| 1409 | + */ | |
| 1410 | + public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) | |
| 1411 | +	{ | |
| 1412 | + $checkin_query_params = array( | |
| 1413 | +			'order_by' => array('CHK_timestamp' => 'DESC'), | |
| 1414 | + ); | |
| 1415 | + | |
| 1416 | +		if ($DTT_ID > 0) { | |
| 1417 | +			$checkin_query_params[0] = array('DTT_ID' => $DTT_ID); | |
| 1418 | + } | |
| 1419 | + | |
| 1420 | + //get checkin object (if exists) | |
| 1421 | + $checkin = $checkin instanceof EE_Checkin | |
| 1422 | + ? $checkin | |
| 1423 | +			: $this->get_first_related('Checkin', $checkin_query_params); | |
| 1424 | +		if ($checkin instanceof EE_Checkin) { | |
| 1425 | +			if ($checkin->get('CHK_in')) { | |
| 1426 | + return EE_Registration::checkin_status_in; //checked in | |
| 1427 | + } | |
| 1428 | + return EE_Registration::checkin_status_out; //had checked in but is now checked out. | |
| 1429 | + } | |
| 1430 | + return EE_Registration::checkin_status_never; //never been checked in | |
| 1431 | + } | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + /** | |
| 1435 | + * This method returns a localized message for the toggled Check-in message. | |
| 1436 | + * | |
| 1437 | + * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, | |
| 1438 | + * then it is assumed Check-in for primary datetime was toggled. | |
| 1439 | + * @param bool $error This just flags that you want an error message returned. This is put in so that the error | |
| 1440 | + * message can be customized with the attendee name. | |
| 1441 | + * @return string internationalized message | |
| 1442 | + * @throws EE_Error | |
| 1443 | + */ | |
| 1444 | + public function get_checkin_msg($DTT_ID, $error = false) | |
| 1445 | +	{ | |
| 1446 | + //let's get the attendee first so we can include the name of the attendee | |
| 1447 | +		$attendee = $this->get_first_related('Attendee'); | |
| 1448 | +		if ($attendee instanceof EE_Attendee) { | |
| 1449 | +			if ($error) { | |
| 1450 | +				return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); | |
| 1451 | + } | |
| 1452 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID); | |
| 1453 | + //what is the status message going to be? | |
| 1454 | +			switch ($cur_status) { | |
| 1455 | + case EE_Registration::checkin_status_never: | |
| 1456 | +					return sprintf(__("%s has been removed from Check-in records", "event_espresso"), | |
| 1457 | + $attendee->full_name()); | |
| 1458 | + break; | |
| 1459 | + case EE_Registration::checkin_status_in: | |
| 1460 | +					return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); | |
| 1461 | + break; | |
| 1462 | + case EE_Registration::checkin_status_out: | |
| 1463 | +					return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); | |
| 1464 | + break; | |
| 1465 | + } | |
| 1466 | + } | |
| 1467 | +		return esc_html__("The check-in status could not be determined.", "event_espresso"); | |
| 1468 | + } | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + /** | |
| 1472 | + * Returns the related EE_Transaction to this registration | |
| 1473 | + * | |
| 1474 | + * @return EE_Transaction | |
| 1475 | + * @throws EE_Error | |
| 1476 | + * @throws EntityNotFoundException | |
| 1477 | + */ | |
| 1478 | + public function transaction() | |
| 1479 | +	{ | |
| 1480 | +		$transaction = $this->get_first_related('Transaction'); | |
| 1481 | +		if (! $transaction instanceof \EE_Transaction) { | |
| 1482 | +			throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); | |
| 1483 | + } | |
| 1484 | + return $transaction; | |
| 1485 | + } | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + /** | |
| 1489 | + * get Registration Code | |
| 1490 | + */ | |
| 1491 | + public function reg_code() | |
| 1492 | +	{ | |
| 1493 | +		return $this->get('REG_code'); | |
| 1494 | + } | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + /** | |
| 1498 | + * get Transaction ID | |
| 1499 | + */ | |
| 1500 | + public function transaction_ID() | |
| 1501 | +	{ | |
| 1502 | +		return $this->get('TXN_ID'); | |
| 1503 | + } | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + /** | |
| 1507 | + * @return int | |
| 1508 | + * @throws EE_Error | |
| 1509 | + */ | |
| 1510 | + public function ticket_ID() | |
| 1511 | +	{ | |
| 1512 | +		return $this->get('TKT_ID'); | |
| 1513 | + } | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + /** | |
| 1517 | + * Set Registration Code | |
| 1518 | + * | |
| 1519 | + * @access public | |
| 1520 | + * @param string $REG_code Registration Code | |
| 1521 | + * @param boolean $use_default | |
| 1522 | + * @throws EE_Error | |
| 1523 | + */ | |
| 1524 | + public function set_reg_code($REG_code, $use_default = false) | |
| 1525 | +	{ | |
| 1526 | +		if (empty($REG_code)) { | |
| 1527 | + EE_Error::add_error( | |
| 1528 | +				esc_html__('REG_code can not be empty.', 'event_espresso'), | |
| 1529 | + __FILE__, | |
| 1530 | + __FUNCTION__, | |
| 1531 | + __LINE__ | |
| 1532 | + ); | |
| 1533 | + return; | |
| 1534 | + } | |
| 1535 | +		if (! $this->reg_code()) { | |
| 1536 | +			parent::set('REG_code', $REG_code, $use_default); | |
| 1537 | +		} else { | |
| 1538 | + EE_Error::doing_it_wrong( | |
| 1539 | + __CLASS__ . '::' . __FUNCTION__, | |
| 1540 | +				esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), | |
| 1541 | + '4.6.0' | |
| 1542 | + ); | |
| 1543 | + } | |
| 1544 | + } | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + /** | |
| 1548 | + * Returns all other registrations in the same group as this registrant who have the same ticket option. | |
| 1549 | + * Note, if you want to just get all registrations in the same transaction (group), use: | |
| 1550 | + * $registration->transaction()->registrations(); | |
| 1551 | + * | |
| 1552 | + * @since 4.5.0 | |
| 1553 | + * @return EE_Registration[] or empty array if this isn't a group registration. | |
| 1554 | + * @throws EE_Error | |
| 1555 | + */ | |
| 1556 | + public function get_all_other_registrations_in_group() | |
| 1557 | +	{ | |
| 1558 | +		if ($this->group_size() < 2) { | |
| 1559 | + return array(); | |
| 1560 | + } | |
| 1561 | + | |
| 1562 | + $query[0] = array( | |
| 1563 | + 'TXN_ID' => $this->transaction_ID(), | |
| 1564 | +			'REG_ID' => array('!=', $this->ID()), | |
| 1565 | + 'TKT_ID' => $this->ticket_ID(), | |
| 1566 | + ); | |
| 1567 | + /** @var EE_Registration[] $registrations */ | |
| 1568 | + $registrations = $this->get_model()->get_all($query); | |
| 1569 | + return $registrations; | |
| 1570 | + } | |
| 1571 | + | |
| 1572 | + /** | |
| 1573 | + * Return the link to the admin details for the object. | |
| 1574 | + * | |
| 1575 | + * @return string | |
| 1576 | + * @throws EE_Error | |
| 1577 | + */ | |
| 1578 | + public function get_admin_details_link() | |
| 1579 | +	{ | |
| 1580 | +		EE_Registry::instance()->load_helper('URL'); | |
| 1581 | + return EEH_URL::add_query_args_and_nonce( | |
| 1582 | + array( | |
| 1583 | + 'page' => 'espresso_registrations', | |
| 1584 | + 'action' => 'view_registration', | |
| 1585 | + '_REG_ID' => $this->ID(), | |
| 1586 | + ), | |
| 1587 | +			admin_url('admin.php') | |
| 1588 | + ); | |
| 1589 | + } | |
| 1590 | + | |
| 1591 | + /** | |
| 1592 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. | |
| 1593 | + * | |
| 1594 | + * @return string | |
| 1595 | + * @throws EE_Error | |
| 1596 | + */ | |
| 1597 | + public function get_admin_edit_link() | |
| 1598 | +	{ | |
| 1599 | + return $this->get_admin_details_link(); | |
| 1600 | + } | |
| 1601 | + | |
| 1602 | + /** | |
| 1603 | + * Returns the link to a settings page for the object. | |
| 1604 | + * | |
| 1605 | + * @return string | |
| 1606 | + * @throws EE_Error | |
| 1607 | + */ | |
| 1608 | + public function get_admin_settings_link() | |
| 1609 | +	{ | |
| 1610 | + return $this->get_admin_details_link(); | |
| 1611 | + } | |
| 1612 | + | |
| 1613 | + /** | |
| 1614 | + * Returns the link to the "overview" for the object (typically the "list table" view). | |
| 1615 | + * | |
| 1616 | + * @return string | |
| 1617 | + */ | |
| 1618 | + public function get_admin_overview_link() | |
| 1619 | +	{ | |
| 1620 | +		EE_Registry::instance()->load_helper('URL'); | |
| 1621 | + return EEH_URL::add_query_args_and_nonce( | |
| 1622 | + array( | |
| 1623 | + 'page' => 'espresso_registrations', | |
| 1624 | + ), | |
| 1625 | +			admin_url('admin.php') | |
| 1626 | + ); | |
| 1627 | + } | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + /** | |
| 1631 | + * @param array $query_params | |
| 1632 | + * @return \EE_Registration[] | |
| 1633 | + * @throws \EE_Error | |
| 1634 | + */ | |
| 1635 | + public function payments($query_params = array()) | |
| 1636 | +	{ | |
| 1637 | +		return $this->get_many_related('Payment', $query_params); | |
| 1638 | + } | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + /** | |
| 1642 | + * @param array $query_params | |
| 1643 | + * @return \EE_Registration_Payment[] | |
| 1644 | + * @throws \EE_Error | |
| 1645 | + */ | |
| 1646 | + public function registration_payments($query_params = array()) | |
| 1647 | +	{ | |
| 1648 | +		return $this->get_many_related('Registration_Payment', $query_params); | |
| 1649 | + } | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + /** | |
| 1653 | + * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. | |
| 1654 | + * Note: if there are no payments on the registration there will be no payment method returned. | |
| 1655 | + * | |
| 1656 | + * @return EE_Payment_Method|null | |
| 1657 | + */ | |
| 1658 | + public function payment_method() | |
| 1659 | +	{ | |
| 1660 | + return EEM_Payment_Method::instance()->get_last_used_for_registration($this); | |
| 1661 | + } | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + /** | |
| 1665 | + * @return \EE_Line_Item | |
| 1666 | + * @throws EntityNotFoundException | |
| 1667 | + * @throws \EE_Error | |
| 1668 | + */ | |
| 1669 | + public function ticket_line_item() | |
| 1670 | +	{ | |
| 1671 | + $ticket = $this->ticket(); | |
| 1672 | + $transaction = $this->transaction(); | |
| 1673 | + $line_item = null; | |
| 1674 | + $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( | |
| 1675 | + $transaction->total_line_item(), | |
| 1676 | + 'Ticket', | |
| 1677 | + array($ticket->ID()) | |
| 1678 | + ); | |
| 1679 | +		foreach ($ticket_line_items as $ticket_line_item) { | |
| 1680 | + if ( | |
| 1681 | + $ticket_line_item instanceof \EE_Line_Item | |
| 1682 | + && $ticket_line_item->OBJ_type() === 'Ticket' | |
| 1683 | + && $ticket_line_item->OBJ_ID() === $ticket->ID() | |
| 1684 | +			) { | |
| 1685 | + $line_item = $ticket_line_item; | |
| 1686 | + break; | |
| 1687 | + } | |
| 1688 | + } | |
| 1689 | +		if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { | |
| 1690 | +			throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); | |
| 1691 | + } | |
| 1692 | + return $line_item; | |
| 1693 | + } | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + /** | |
| 1697 | + * Soft Deletes this model object. | |
| 1698 | + * | |
| 1699 | + * @return boolean | int | |
| 1700 | + * @throws \RuntimeException | |
| 1701 | + * @throws \EE_Error | |
| 1702 | + */ | |
| 1703 | + public function delete() | |
| 1704 | +	{ | |
| 1705 | +		if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { | |
| 1706 | + $this->set_status(EEM_Registration::status_id_cancelled); | |
| 1707 | + } | |
| 1708 | + return parent::delete(); | |
| 1709 | + } | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + /** | |
| 1713 | + * Restores whatever the previous status was on a registration before it was trashed (if possible) | |
| 1714 | + * | |
| 1715 | + * @throws \EE_Error | |
| 1716 | + * @throws \RuntimeException | |
| 1717 | + */ | |
| 1718 | + public function restore() | |
| 1719 | +	{ | |
| 1720 | + $previous_status = $this->get_extra_meta( | |
| 1721 | + EE_Registration::PRE_TRASH_REG_STATUS_KEY, | |
| 1722 | + true, | |
| 1723 | + EEM_Registration::status_id_cancelled | |
| 1724 | + ); | |
| 1725 | +		if ($previous_status) { | |
| 1726 | + $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); | |
| 1727 | + $this->set_status($previous_status); | |
| 1728 | + } | |
| 1729 | + return parent::restore(); | |
| 1730 | + } | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + /*************************** DEPRECATED ***************************/ | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + /** | |
| 1738 | + * @deprecated | |
| 1739 | + * @since 4.7.0 | |
| 1740 | + * @access public | |
| 1741 | + */ | |
| 1742 | + public function price_paid() | |
| 1743 | +	{ | |
| 1744 | +		EE_Error::doing_it_wrong('EE_Registration::price_paid()', | |
| 1745 | +			esc_html__('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'), | |
| 1746 | + '4.7.0'); | |
| 1747 | + return $this->final_price(); | |
| 1748 | + } | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + /** | |
| 1752 | + * @deprecated | |
| 1753 | + * @since 4.7.0 | |
| 1754 | + * @access public | |
| 1755 | + * @param float $REG_final_price | |
| 1756 | + * @throws EE_Error | |
| 1757 | + * @throws RuntimeException | |
| 1758 | + */ | |
| 1759 | + public function set_price_paid($REG_final_price = 0.00) | |
| 1760 | +	{ | |
| 1761 | +		EE_Error::doing_it_wrong('EE_Registration::set_price_paid()', | |
| 1762 | +			esc_html__('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'), | |
| 1763 | + '4.7.0'); | |
| 1764 | + $this->set_final_price($REG_final_price); | |
| 1765 | + } | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + /** | |
| 1769 | + * @deprecated | |
| 1770 | + * @since 4.7.0 | |
| 1771 | + * @return string | |
| 1772 | + * @throws EE_Error | |
| 1773 | + */ | |
| 1774 | + public function pretty_price_paid() | |
| 1775 | +	{ | |
| 1776 | +		EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()', | |
| 1777 | +			esc_html__('This method is deprecated, please use EE_Registration::pretty_final_price() instead.', | |
| 1778 | + 'event_espresso'), '4.7.0'); | |
| 1779 | + return $this->pretty_final_price(); | |
| 1780 | + } | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + /** | |
| 1784 | + * Gets the primary datetime related to this registration via the related Event to this registration | |
| 1785 | + * | |
| 1786 | + * @deprecated 4.9.17 | |
| 1787 | + * @return EE_Datetime | |
| 1788 | + * @throws EE_Error | |
| 1789 | + * @throws EntityNotFoundException | |
| 1790 | + */ | |
| 1791 | + public function get_related_primary_datetime() | |
| 1792 | +	{ | |
| 1793 | + EE_Error::doing_it_wrong( | |
| 1794 | + __METHOD__, | |
| 1795 | + esc_html__( | |
| 1796 | + 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', | |
| 1797 | + 'event_espresso' | |
| 1798 | + ), | |
| 1799 | + '4.9.17', | |
| 1800 | + '5.0.0' | |
| 1801 | + ); | |
| 1802 | + return $this->event()->primary_datetime(); | |
| 1803 | + } | |
| 1804 | 1804 | |
| 1805 | 1805 | |
| 1806 | 1806 | } | 
| @@ -5,7 +5,7 @@ discard block | ||
| 5 | 5 | use EventEspresso\core\exceptions\InvalidEntityException; | 
| 6 | 6 | |
| 7 | 7 |  if ( ! defined('EVENT_ESPRESSO_VERSION')) { | 
| 8 | -    exit('No direct script access allowed'); | |
| 8 | +	exit('No direct script access allowed'); | |
| 9 | 9 | } | 
| 10 | 10 | |
| 11 | 11 | |
| @@ -20,1861 +20,1861 @@ discard block | ||
| 20 | 20 | class EED_Single_Page_Checkout extends EED_Module | 
| 21 | 21 |  { | 
| 22 | 22 | |
| 23 | - /** | |
| 24 | - * $_initialized - has the SPCO controller already been initialized ? | |
| 25 | - * | |
| 26 | - * @access private | |
| 27 | - * @var bool $_initialized | |
| 28 | - */ | |
| 29 | - private static $_initialized = false; | |
| 30 | - | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * $_checkout_verified - is the EE_Checkout verified as correct for this request ? | |
| 34 | - * | |
| 35 | - * @access private | |
| 36 | - * @var bool $_valid_checkout | |
| 37 | - */ | |
| 38 | - private static $_checkout_verified = true; | |
| 39 | - | |
| 40 | - /** | |
| 41 | - * $_reg_steps_array - holds initial array of reg steps | |
| 42 | - * | |
| 43 | - * @access private | |
| 44 | - * @var array $_reg_steps_array | |
| 45 | - */ | |
| 46 | - private static $_reg_steps_array = array(); | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process | |
| 50 | - * | |
| 51 | - * @access public | |
| 52 | - * @var EE_Checkout $checkout | |
| 53 | - */ | |
| 54 | - public $checkout; | |
| 55 | - | |
| 56 | - | |
| 57 | - | |
| 58 | - /** | |
| 59 | - * @return EED_Module|EED_Single_Page_Checkout | |
| 60 | - */ | |
| 61 | - public static function instance() | |
| 62 | -    { | |
| 63 | -        add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); | |
| 64 | - return parent::get_instance(__CLASS__); | |
| 65 | - } | |
| 66 | - | |
| 67 | - | |
| 68 | - | |
| 69 | - /** | |
| 70 | - * @return EE_CART | |
| 71 | - */ | |
| 72 | - public function cart() | |
| 73 | -    { | |
| 74 | - return $this->checkout->cart; | |
| 75 | - } | |
| 76 | - | |
| 77 | - | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * @return EE_Transaction | |
| 81 | - */ | |
| 82 | - public function transaction() | |
| 83 | -    { | |
| 84 | - return $this->checkout->transaction; | |
| 85 | - } | |
| 86 | - | |
| 87 | - | |
| 88 | - | |
| 89 | - /** | |
| 90 | - * set_hooks - for hooking into EE Core, other modules, etc | |
| 91 | - * | |
| 92 | - * @access public | |
| 93 | - * @return void | |
| 94 | - * @throws EE_Error | |
| 95 | - */ | |
| 96 | - public static function set_hooks() | |
| 97 | -    { | |
| 98 | - EED_Single_Page_Checkout::set_definitions(); | |
| 99 | - } | |
| 100 | - | |
| 101 | - | |
| 102 | - | |
| 103 | - /** | |
| 104 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc | |
| 105 | - * | |
| 106 | - * @access public | |
| 107 | - * @return void | |
| 108 | - * @throws EE_Error | |
| 109 | - */ | |
| 110 | - public static function set_hooks_admin() | |
| 111 | -    { | |
| 112 | - EED_Single_Page_Checkout::set_definitions(); | |
| 113 | -        if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { | |
| 114 | - return; | |
| 115 | - } | |
| 116 | - // going to start an output buffer in case anything gets accidentally output | |
| 117 | - // that might disrupt our JSON response | |
| 118 | - ob_start(); | |
| 119 | - EED_Single_Page_Checkout::load_request_handler(); | |
| 120 | - EED_Single_Page_Checkout::load_reg_steps(); | |
| 121 | - // set ajax hooks | |
| 122 | -        add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); | |
| 123 | -        add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); | |
| 124 | -        add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); | |
| 125 | -        add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); | |
| 126 | -        add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); | |
| 127 | -        add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); | |
| 128 | - } | |
| 129 | - | |
| 130 | - | |
| 131 | - | |
| 132 | - /** | |
| 133 | - * process ajax request | |
| 134 | - * | |
| 135 | - * @param string $ajax_action | |
| 136 | - * @throws EE_Error | |
| 137 | - */ | |
| 138 | - public static function process_ajax_request($ajax_action) | |
| 139 | -    { | |
| 140 | -        EE_Registry::instance()->REQ->set('action', $ajax_action); | |
| 141 | - EED_Single_Page_Checkout::instance()->_initialize(); | |
| 142 | - } | |
| 143 | - | |
| 144 | - | |
| 145 | - | |
| 146 | - /** | |
| 147 | - * ajax display registration step | |
| 148 | - * | |
| 149 | - * @throws EE_Error | |
| 150 | - */ | |
| 151 | - public static function display_reg_step() | |
| 152 | -    { | |
| 153 | -        EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); | |
| 154 | - } | |
| 155 | - | |
| 156 | - | |
| 157 | - | |
| 158 | - /** | |
| 159 | - * ajax process registration step | |
| 160 | - * | |
| 161 | - * @throws EE_Error | |
| 162 | - */ | |
| 163 | - public static function process_reg_step() | |
| 164 | -    { | |
| 165 | -        EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); | |
| 166 | - } | |
| 167 | - | |
| 168 | - | |
| 169 | - | |
| 170 | - /** | |
| 171 | - * ajax process registration step | |
| 172 | - * | |
| 173 | - * @throws EE_Error | |
| 174 | - */ | |
| 175 | - public static function update_reg_step() | |
| 176 | -    { | |
| 177 | -        EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); | |
| 178 | - } | |
| 179 | - | |
| 180 | - | |
| 181 | - | |
| 182 | - /** | |
| 183 | - * update_checkout | |
| 184 | - * | |
| 185 | - * @access public | |
| 186 | - * @return void | |
| 187 | - * @throws EE_Error | |
| 188 | - */ | |
| 189 | - public static function update_checkout() | |
| 190 | -    { | |
| 191 | -        EED_Single_Page_Checkout::process_ajax_request('update_checkout'); | |
| 192 | - } | |
| 193 | - | |
| 194 | - | |
| 195 | - | |
| 196 | - /** | |
| 197 | - * load_request_handler | |
| 198 | - * | |
| 199 | - * @access public | |
| 200 | - * @return void | |
| 201 | - */ | |
| 202 | - public static function load_request_handler() | |
| 203 | -    { | |
| 204 | - // load core Request_Handler class | |
| 205 | -        if (EE_Registry::instance()->REQ !== null) { | |
| 206 | -            EE_Registry::instance()->load_core('Request_Handler'); | |
| 207 | - } | |
| 208 | - } | |
| 209 | - | |
| 210 | - | |
| 211 | - | |
| 212 | - /** | |
| 213 | - * set_definitions | |
| 214 | - * | |
| 215 | - * @access public | |
| 216 | - * @return void | |
| 217 | - * @throws EE_Error | |
| 218 | - */ | |
| 219 | - public static function set_definitions() | |
| 220 | -    { | |
| 221 | -        if(defined('SPCO_BASE_PATH')) { | |
| 222 | - return; | |
| 223 | - } | |
| 224 | - define( | |
| 225 | - 'SPCO_BASE_PATH', | |
| 226 | -            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS | |
| 227 | - ); | |
| 228 | -        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); | |
| 229 | -        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); | |
| 230 | -        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); | |
| 231 | -        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); | |
| 232 | -        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); | |
| 233 | -        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); | |
| 234 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); | |
| 235 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( | |
| 236 | -            __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', | |
| 237 | - 'event_espresso'), | |
| 238 | - '<h4 class="important-notice">', | |
| 239 | - '</h4>', | |
| 240 | - '<br />', | |
| 241 | - '<p>', | |
| 242 | -            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', | |
| 243 | - '">', | |
| 244 | - '</a>', | |
| 245 | - '</p>' | |
| 246 | - ); | |
| 247 | - } | |
| 248 | - | |
| 249 | - | |
| 250 | - | |
| 251 | - /** | |
| 252 | - * load_reg_steps | |
| 253 | - * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array | |
| 254 | - * | |
| 255 | - * @access private | |
| 256 | - * @throws EE_Error | |
| 257 | - */ | |
| 258 | - public static function load_reg_steps() | |
| 259 | -    { | |
| 260 | - static $reg_steps_loaded = false; | |
| 261 | -        if ($reg_steps_loaded) { | |
| 262 | - return; | |
| 263 | - } | |
| 264 | - // filter list of reg_steps | |
| 265 | - $reg_steps_to_load = (array)apply_filters( | |
| 266 | - 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', | |
| 267 | - EED_Single_Page_Checkout::get_reg_steps() | |
| 268 | - ); | |
| 269 | - // sort by key (order) | |
| 270 | - ksort($reg_steps_to_load); | |
| 271 | - // loop through folders | |
| 272 | -        foreach ($reg_steps_to_load as $order => $reg_step) { | |
| 273 | - // we need a | |
| 274 | -            if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { | |
| 275 | - // copy over to the reg_steps_array | |
| 276 | - EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; | |
| 277 | - // register custom key route for each reg step | |
| 278 | - // ie: step=>"slug" - this is the entire reason we load the reg steps array now | |
| 279 | - EE_Config::register_route( | |
| 280 | - $reg_step['slug'], | |
| 281 | - 'EED_Single_Page_Checkout', | |
| 282 | - 'run', | |
| 283 | - 'step' | |
| 284 | - ); | |
| 285 | - // add AJAX or other hooks | |
| 286 | -                if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { | |
| 287 | - // setup autoloaders if necessary | |
| 288 | -                    if ( ! class_exists($reg_step['class_name'])) { | |
| 289 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( | |
| 290 | - $reg_step['file_path'], | |
| 291 | - true | |
| 292 | - ); | |
| 293 | - } | |
| 294 | -                    if (is_callable($reg_step['class_name'], 'set_hooks')) { | |
| 295 | - call_user_func(array($reg_step['class_name'], 'set_hooks')); | |
| 296 | - } | |
| 297 | - } | |
| 298 | - } | |
| 299 | - } | |
| 300 | - $reg_steps_loaded = true; | |
| 301 | - } | |
| 302 | - | |
| 303 | - | |
| 304 | - | |
| 305 | - /** | |
| 306 | - * get_reg_steps | |
| 307 | - * | |
| 308 | - * @access public | |
| 309 | - * @return array | |
| 310 | - */ | |
| 311 | - public static function get_reg_steps() | |
| 312 | -    { | |
| 313 | - $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; | |
| 314 | -        if (empty($reg_steps)) { | |
| 315 | - $reg_steps = array( | |
| 316 | - 10 => array( | |
| 317 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', | |
| 318 | - 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', | |
| 319 | - 'slug' => 'attendee_information', | |
| 320 | - 'has_hooks' => false, | |
| 321 | - ), | |
| 322 | - 20 => array( | |
| 323 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', | |
| 324 | - 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', | |
| 325 | - 'slug' => 'registration_confirmation', | |
| 326 | - 'has_hooks' => false, | |
| 327 | - ), | |
| 328 | - 30 => array( | |
| 329 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', | |
| 330 | - 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', | |
| 331 | - 'slug' => 'payment_options', | |
| 332 | - 'has_hooks' => true, | |
| 333 | - ), | |
| 334 | - 999 => array( | |
| 335 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', | |
| 336 | - 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', | |
| 337 | - 'slug' => 'finalize_registration', | |
| 338 | - 'has_hooks' => false, | |
| 339 | - ), | |
| 340 | - ); | |
| 341 | - } | |
| 342 | - return $reg_steps; | |
| 343 | - } | |
| 344 | - | |
| 345 | - | |
| 346 | - | |
| 347 | - /** | |
| 348 | - * registration_checkout_for_admin | |
| 349 | - * | |
| 350 | - * @access public | |
| 351 | - * @return string | |
| 352 | - * @throws EE_Error | |
| 353 | - */ | |
| 354 | - public static function registration_checkout_for_admin() | |
| 355 | -    { | |
| 356 | - EED_Single_Page_Checkout::load_request_handler(); | |
| 357 | -        EE_Registry::instance()->REQ->set('step', 'attendee_information'); | |
| 358 | -        EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); | |
| 359 | -        EE_Registry::instance()->REQ->set('process_form_submission', false); | |
| 360 | - EED_Single_Page_Checkout::instance()->_initialize(); | |
| 361 | - EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); | |
| 362 | - return EE_Registry::instance()->REQ->get_output(); | |
| 363 | - } | |
| 364 | - | |
| 365 | - | |
| 366 | - | |
| 367 | - /** | |
| 368 | - * process_registration_from_admin | |
| 369 | - * | |
| 370 | - * @access public | |
| 371 | - * @return \EE_Transaction | |
| 372 | - * @throws EE_Error | |
| 373 | - */ | |
| 374 | - public static function process_registration_from_admin() | |
| 375 | -    { | |
| 376 | - EED_Single_Page_Checkout::load_request_handler(); | |
| 377 | -        EE_Registry::instance()->REQ->set('step', 'attendee_information'); | |
| 378 | -        EE_Registry::instance()->REQ->set('action', 'process_reg_step'); | |
| 379 | -        EE_Registry::instance()->REQ->set('process_form_submission', true); | |
| 380 | - EED_Single_Page_Checkout::instance()->_initialize(); | |
| 381 | -        if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { | |
| 382 | - $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); | |
| 383 | -            if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { | |
| 384 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); | |
| 385 | -                if ($final_reg_step->process_reg_step()) { | |
| 386 | - $final_reg_step->set_completed(); | |
| 387 | - EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); | |
| 388 | - return EED_Single_Page_Checkout::instance()->checkout->transaction; | |
| 389 | - } | |
| 390 | - } | |
| 391 | - } | |
| 392 | - return null; | |
| 393 | - } | |
| 394 | - | |
| 395 | - | |
| 396 | - | |
| 397 | - /** | |
| 398 | - * run | |
| 399 | - * | |
| 400 | - * @access public | |
| 401 | - * @param WP_Query $WP_Query | |
| 402 | - * @return void | |
| 403 | - * @throws EE_Error | |
| 404 | - */ | |
| 405 | - public function run($WP_Query) | |
| 406 | -    { | |
| 407 | - if ( | |
| 408 | - $WP_Query instanceof WP_Query | |
| 409 | - && $WP_Query->is_main_query() | |
| 410 | -            && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) | |
| 411 | - && $this->_is_reg_checkout() | |
| 412 | -        ) { | |
| 413 | - $this->_initialize(); | |
| 414 | - } | |
| 415 | - } | |
| 416 | - | |
| 417 | - | |
| 418 | - | |
| 419 | - /** | |
| 420 | - * determines whether current url matches reg page url | |
| 421 | - * | |
| 422 | - * @return bool | |
| 423 | - */ | |
| 424 | - protected function _is_reg_checkout() | |
| 425 | -    { | |
| 426 | - // get current permalink for reg page without any extra query args | |
| 427 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); | |
| 428 | - // get request URI for current request, but without the scheme or host | |
| 429 | -        $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); | |
| 430 | - $current_request_uri = html_entity_decode($current_request_uri); | |
| 431 | - // get array of query args from the current request URI | |
| 432 | - $query_args = \EEH_URL::get_query_string($current_request_uri); | |
| 433 | - // grab page id if it is set | |
| 434 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; | |
| 435 | - // and remove the page id from the query args (we will re-add it later) | |
| 436 | - unset($query_args['page_id']); | |
| 437 | - // now strip all query args from current request URI | |
| 438 | - $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); | |
| 439 | - // and re-add the page id if it was set | |
| 440 | -        if ($page_id) { | |
| 441 | -            $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); | |
| 442 | - } | |
| 443 | - // remove slashes and ? | |
| 444 | - $current_request_uri = trim($current_request_uri, '?/'); | |
| 445 | - // is current request URI part of the known full reg page URL ? | |
| 446 | - return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; | |
| 447 | - } | |
| 448 | - | |
| 449 | - | |
| 450 | - | |
| 451 | - /** | |
| 452 | - * @param WP_Query $wp_query | |
| 453 | - * @return void | |
| 454 | - * @throws EE_Error | |
| 455 | - */ | |
| 456 | - public static function init($wp_query) | |
| 457 | -    { | |
| 458 | - EED_Single_Page_Checkout::instance()->run($wp_query); | |
| 459 | - } | |
| 460 | - | |
| 461 | - | |
| 462 | - | |
| 463 | - /** | |
| 464 | - * _initialize - initial module setup | |
| 465 | - * | |
| 466 | - * @access private | |
| 467 | - * @throws EE_Error | |
| 468 | - * @return void | |
| 469 | - */ | |
| 470 | - private function _initialize() | |
| 471 | -    { | |
| 472 | - // ensure SPCO doesn't run twice | |
| 473 | -        if (EED_Single_Page_Checkout::$_initialized) { | |
| 474 | - return; | |
| 475 | - } | |
| 476 | -        try { | |
| 477 | - EED_Single_Page_Checkout::load_reg_steps(); | |
| 478 | - $this->_verify_session(); | |
| 479 | - // setup the EE_Checkout object | |
| 480 | - $this->checkout = $this->_initialize_checkout(); | |
| 481 | - // filter checkout | |
| 482 | -            $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); | |
| 483 | - // get the $_GET | |
| 484 | - $this->_get_request_vars(); | |
| 485 | -            if ($this->_block_bots()) { | |
| 486 | - return; | |
| 487 | - } | |
| 488 | - // filter continue_reg | |
| 489 | - $this->checkout->continue_reg = apply_filters( | |
| 490 | - 'FHEE__EED_Single_Page_Checkout__init___continue_reg', | |
| 491 | - true, | |
| 492 | - $this->checkout | |
| 493 | - ); | |
| 494 | - // load the reg steps array | |
| 495 | -            if ( ! $this->_load_and_instantiate_reg_steps()) { | |
| 496 | - EED_Single_Page_Checkout::$_initialized = true; | |
| 497 | - return; | |
| 498 | - } | |
| 499 | - // set the current step | |
| 500 | - $this->checkout->set_current_step($this->checkout->step); | |
| 501 | - // and the next step | |
| 502 | - $this->checkout->set_next_step(); | |
| 503 | - // verify that everything has been setup correctly | |
| 504 | -            if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { | |
| 505 | - EED_Single_Page_Checkout::$_initialized = true; | |
| 506 | - return; | |
| 507 | - } | |
| 508 | - // lock the transaction | |
| 509 | - $this->checkout->transaction->lock(); | |
| 510 | - // make sure all of our cached objects are added to their respective model entity mappers | |
| 511 | - $this->checkout->refresh_all_entities(); | |
| 512 | - // set amount owing | |
| 513 | - $this->checkout->amount_owing = $this->checkout->transaction->remaining(); | |
| 514 | - // initialize each reg step, which gives them the chance to potentially alter the process | |
| 515 | - $this->_initialize_reg_steps(); | |
| 516 | - // DEBUG LOG | |
| 517 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); | |
| 518 | - // get reg form | |
| 519 | -            if( ! $this->_check_form_submission()) { | |
| 520 | - EED_Single_Page_Checkout::$_initialized = true; | |
| 521 | - return; | |
| 522 | - } | |
| 523 | - // checkout the action!!! | |
| 524 | - $this->_process_form_action(); | |
| 525 | - // add some style and make it dance | |
| 526 | - $this->add_styles_and_scripts(); | |
| 527 | - // kk... SPCO has successfully run | |
| 528 | - EED_Single_Page_Checkout::$_initialized = true; | |
| 529 | - // set no cache headers and constants | |
| 530 | - EE_System::do_not_cache(); | |
| 531 | - // add anchor | |
| 532 | -            add_action('loop_start', array($this, 'set_checkout_anchor'), 1); | |
| 533 | - // remove transaction lock | |
| 534 | -            add_action('shutdown', array($this, 'unlock_transaction'), 1); | |
| 535 | -        } catch (Exception $e) { | |
| 536 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); | |
| 537 | - } | |
| 538 | - } | |
| 539 | - | |
| 540 | - | |
| 541 | - | |
| 542 | - /** | |
| 543 | - * _verify_session | |
| 544 | - * checks that the session is valid and not expired | |
| 545 | - * | |
| 546 | - * @access private | |
| 547 | - * @throws EE_Error | |
| 548 | - */ | |
| 549 | - private function _verify_session() | |
| 550 | -    { | |
| 551 | -        if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { | |
| 552 | -            throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); | |
| 553 | - } | |
| 554 | - $clear_session_requested = filter_var( | |
| 555 | -            EE_Registry::instance()->REQ->get('clear_session', false), | |
| 556 | - FILTER_VALIDATE_BOOLEAN | |
| 557 | - ); | |
| 558 | - // is session still valid ? | |
| 559 | - if ($clear_session_requested | |
| 560 | - || ( EE_Registry::instance()->SSN->expired() | |
| 561 | -              && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' | |
| 562 | - ) | |
| 563 | -        ) { | |
| 564 | - $this->checkout = new EE_Checkout(); | |
| 565 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); | |
| 566 | - // EE_Registry::instance()->SSN->reset_cart(); | |
| 567 | - // EE_Registry::instance()->SSN->reset_checkout(); | |
| 568 | - // EE_Registry::instance()->SSN->reset_transaction(); | |
| 569 | -            if (! $clear_session_requested) { | |
| 570 | - EE_Error::add_attention( | |
| 571 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'], | |
| 572 | - __FILE__, __FUNCTION__, __LINE__ | |
| 573 | - ); | |
| 574 | - } | |
| 575 | - // EE_Registry::instance()->SSN->reset_expired(); | |
| 576 | - } | |
| 577 | - } | |
| 578 | - | |
| 579 | - | |
| 580 | - | |
| 581 | - /** | |
| 582 | - * _initialize_checkout | |
| 583 | - * loads and instantiates EE_Checkout | |
| 584 | - * | |
| 585 | - * @access private | |
| 586 | - * @throws EE_Error | |
| 587 | - * @return EE_Checkout | |
| 588 | - */ | |
| 589 | - private function _initialize_checkout() | |
| 590 | -    { | |
| 591 | - // look in session for existing checkout | |
| 592 | - /** @type EE_Checkout $checkout */ | |
| 593 | - $checkout = EE_Registry::instance()->SSN->checkout(); | |
| 594 | - // verify | |
| 595 | -        if ( ! $checkout instanceof EE_Checkout) { | |
| 596 | - // instantiate EE_Checkout object for handling the properties of the current checkout process | |
| 597 | - $checkout = EE_Registry::instance()->load_file( | |
| 598 | - SPCO_INC_PATH, | |
| 599 | - 'EE_Checkout', | |
| 600 | - 'class', array(), | |
| 601 | - false | |
| 602 | - ); | |
| 603 | -        } else { | |
| 604 | -            if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { | |
| 605 | - $this->unlock_transaction(); | |
| 606 | - wp_safe_redirect($checkout->redirect_url); | |
| 607 | - exit(); | |
| 608 | - } | |
| 609 | - } | |
| 610 | -        $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); | |
| 611 | - // verify again | |
| 612 | -        if ( ! $checkout instanceof EE_Checkout) { | |
| 613 | -            throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); | |
| 614 | - } | |
| 615 | - // reset anything that needs a clean slate for each request | |
| 616 | - $checkout->reset_for_current_request(); | |
| 617 | - return $checkout; | |
| 618 | - } | |
| 619 | - | |
| 620 | - | |
| 621 | - | |
| 622 | - /** | |
| 623 | - * _get_request_vars | |
| 624 | - * | |
| 625 | - * @access private | |
| 626 | - * @return void | |
| 627 | - * @throws EE_Error | |
| 628 | - */ | |
| 629 | - private function _get_request_vars() | |
| 630 | -    { | |
| 631 | - // load classes | |
| 632 | - EED_Single_Page_Checkout::load_request_handler(); | |
| 633 | - //make sure this request is marked as belonging to EE | |
| 634 | - EE_Registry::instance()->REQ->set_espresso_page(true); | |
| 635 | - // which step is being requested ? | |
| 636 | -        $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); | |
| 637 | - // which step is being edited ? | |
| 638 | -        $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); | |
| 639 | - // and what we're doing on the current step | |
| 640 | -        $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); | |
| 641 | - // timestamp | |
| 642 | -        $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); | |
| 643 | - // returning to edit ? | |
| 644 | -        $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); | |
| 645 | - // or some other kind of revisit ? | |
| 646 | - $this->checkout->revisit = filter_var( | |
| 647 | -            EE_Registry::instance()->REQ->get('revisit', false), | |
| 648 | - FILTER_VALIDATE_BOOLEAN | |
| 649 | - ); | |
| 650 | - // and whether or not to generate a reg form for this request | |
| 651 | - $this->checkout->generate_reg_form = filter_var( | |
| 652 | -            EE_Registry::instance()->REQ->get('generate_reg_form', true), | |
| 653 | - FILTER_VALIDATE_BOOLEAN | |
| 654 | - ); | |
| 655 | - // and whether or not to process a reg form submission for this request | |
| 656 | - $this->checkout->process_form_submission = filter_var( | |
| 657 | - EE_Registry::instance()->REQ->get( | |
| 658 | - 'process_form_submission', | |
| 659 | - $this->checkout->action === 'process_reg_step' | |
| 660 | - ), | |
| 661 | - FILTER_VALIDATE_BOOLEAN | |
| 662 | - ); | |
| 663 | - $this->checkout->process_form_submission = filter_var( | |
| 664 | - $this->checkout->action !== 'display_spco_reg_step' | |
| 665 | - ? $this->checkout->process_form_submission | |
| 666 | - : false, | |
| 667 | - FILTER_VALIDATE_BOOLEAN | |
| 668 | - ); | |
| 669 | - // $this->_display_request_vars(); | |
| 670 | - } | |
| 671 | - | |
| 672 | - | |
| 673 | - | |
| 674 | - /** | |
| 675 | - * _display_request_vars | |
| 676 | - * | |
| 677 | - * @access protected | |
| 678 | - * @return void | |
| 679 | - */ | |
| 680 | - protected function _display_request_vars() | |
| 681 | -    { | |
| 682 | -        if ( ! WP_DEBUG) { | |
| 683 | - return; | |
| 684 | - } | |
| 685 | - EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); | |
| 686 | - EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); | |
| 687 | - EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); | |
| 688 | - EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); | |
| 689 | - EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); | |
| 690 | - EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); | |
| 691 | - EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); | |
| 692 | - EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); | |
| 693 | - } | |
| 694 | - | |
| 695 | - | |
| 696 | - | |
| 697 | - /** | |
| 698 | - * _block_bots | |
| 699 | - * checks that the incoming request has either of the following set: | |
| 700 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector | |
| 701 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN | |
| 702 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... | |
| 703 | - * then where you coming from man? | |
| 704 | - * | |
| 705 | - * @return boolean | |
| 706 | - */ | |
| 707 | - private function _block_bots() | |
| 708 | -    { | |
| 709 | - $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); | |
| 710 | -        if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { | |
| 711 | - return true; | |
| 712 | - } | |
| 713 | - return false; | |
| 714 | - } | |
| 715 | - | |
| 716 | - | |
| 717 | - | |
| 718 | - /** | |
| 719 | - * _get_first_step | |
| 720 | - * gets slug for first step in $_reg_steps_array | |
| 721 | - * | |
| 722 | - * @access private | |
| 723 | - * @throws EE_Error | |
| 724 | - * @return string | |
| 725 | - */ | |
| 726 | - private function _get_first_step() | |
| 727 | -    { | |
| 728 | - $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); | |
| 729 | - return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; | |
| 730 | - } | |
| 731 | - | |
| 732 | - | |
| 733 | - | |
| 734 | - /** | |
| 735 | - * _load_and_instantiate_reg_steps | |
| 736 | - * instantiates each reg step based on the loaded reg_steps array | |
| 737 | - * | |
| 738 | - * @access private | |
| 739 | - * @throws EE_Error | |
| 740 | - * @return bool | |
| 741 | - */ | |
| 742 | - private function _load_and_instantiate_reg_steps() | |
| 743 | -    { | |
| 744 | -        do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); | |
| 745 | - // have reg_steps already been instantiated ? | |
| 746 | - if ( | |
| 747 | - empty($this->checkout->reg_steps) | |
| 748 | -            || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) | |
| 749 | -        ) { | |
| 750 | - // if not, then loop through raw reg steps array | |
| 751 | -            foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { | |
| 752 | -                if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { | |
| 753 | - return false; | |
| 754 | - } | |
| 755 | - } | |
| 756 | - EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; | |
| 757 | - EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; | |
| 758 | - // skip the registration_confirmation page ? | |
| 759 | -            if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { | |
| 760 | - // just remove it from the reg steps array | |
| 761 | -                $this->checkout->remove_reg_step('registration_confirmation', false); | |
| 762 | - } else if ( | |
| 763 | - isset($this->checkout->reg_steps['registration_confirmation']) | |
| 764 | - && EE_Registry::instance()->CFG->registration->reg_confirmation_last | |
| 765 | -            ) { | |
| 766 | - // set the order to something big like 100 | |
| 767 | -                $this->checkout->set_reg_step_order('registration_confirmation', 100); | |
| 768 | - } | |
| 769 | - // filter the array for good luck | |
| 770 | - $this->checkout->reg_steps = apply_filters( | |
| 771 | - 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', | |
| 772 | - $this->checkout->reg_steps | |
| 773 | - ); | |
| 774 | - // finally re-sort based on the reg step class order properties | |
| 775 | - $this->checkout->sort_reg_steps(); | |
| 776 | -        } else { | |
| 777 | -            foreach ($this->checkout->reg_steps as $reg_step) { | |
| 778 | - // set all current step stati to FALSE | |
| 779 | - $reg_step->set_is_current_step(false); | |
| 780 | - } | |
| 781 | - } | |
| 782 | -        if (empty($this->checkout->reg_steps)) { | |
| 783 | - EE_Error::add_error( | |
| 784 | -                __('No Reg Steps were loaded..', 'event_espresso'), | |
| 785 | - __FILE__, __FUNCTION__, __LINE__ | |
| 786 | - ); | |
| 787 | - return false; | |
| 788 | - } | |
| 789 | - // make reg step details available to JS | |
| 790 | - $this->checkout->set_reg_step_JSON_info(); | |
| 791 | - return true; | |
| 792 | - } | |
| 793 | - | |
| 794 | - | |
| 795 | - | |
| 796 | - /** | |
| 797 | - * _load_and_instantiate_reg_step | |
| 798 | - * | |
| 799 | - * @access private | |
| 800 | - * @param array $reg_step | |
| 801 | - * @param int $order | |
| 802 | - * @return bool | |
| 803 | - */ | |
| 804 | - private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) | |
| 805 | -    { | |
| 806 | - // we need a file_path, class_name, and slug to add a reg step | |
| 807 | -        if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { | |
| 808 | - // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) | |
| 809 | - if ( | |
| 810 | - $this->checkout->reg_url_link | |
| 811 | - && $this->checkout->step !== $reg_step['slug'] | |
| 812 | - && $reg_step['slug'] !== 'finalize_registration' | |
| 813 | - // normally at this point we would NOT load the reg step, but this filter can change that | |
| 814 | - && apply_filters( | |
| 815 | - 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', | |
| 816 | - true, | |
| 817 | - $reg_step, | |
| 818 | - $this->checkout | |
| 819 | - ) | |
| 820 | -            ) { | |
| 821 | - return true; | |
| 822 | - } | |
| 823 | - // instantiate step class using file path and class name | |
| 824 | - $reg_step_obj = EE_Registry::instance()->load_file( | |
| 825 | - $reg_step['file_path'], | |
| 826 | - $reg_step['class_name'], | |
| 827 | - 'class', | |
| 828 | - $this->checkout, | |
| 829 | - false | |
| 830 | - ); | |
| 831 | - // did we gets the goods ? | |
| 832 | -            if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { | |
| 833 | - // set reg step order based on config | |
| 834 | - $reg_step_obj->set_order($order); | |
| 835 | - // add instantiated reg step object to the master reg steps array | |
| 836 | - $this->checkout->add_reg_step($reg_step_obj); | |
| 837 | -            } else { | |
| 838 | - EE_Error::add_error( | |
| 839 | -                    __('The current step could not be set.', 'event_espresso'), | |
| 840 | - __FILE__, __FUNCTION__, __LINE__ | |
| 841 | - ); | |
| 842 | - return false; | |
| 843 | - } | |
| 844 | -        } else { | |
| 845 | -            if (WP_DEBUG) { | |
| 846 | - EE_Error::add_error( | |
| 847 | - sprintf( | |
| 848 | - __( | |
| 849 | - 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', | |
| 850 | - 'event_espresso' | |
| 851 | - ), | |
| 852 | - isset($reg_step['file_path']) ? $reg_step['file_path'] : '', | |
| 853 | - isset($reg_step['class_name']) ? $reg_step['class_name'] : '', | |
| 854 | - isset($reg_step['slug']) ? $reg_step['slug'] : '', | |
| 855 | - '<ul>', | |
| 856 | - '<li>', | |
| 857 | - '</li>', | |
| 858 | - '</ul>' | |
| 859 | - ), | |
| 860 | - __FILE__, __FUNCTION__, __LINE__ | |
| 861 | - ); | |
| 862 | - } | |
| 863 | - return false; | |
| 864 | - } | |
| 865 | - return true; | |
| 866 | - } | |
| 867 | - | |
| 868 | - | |
| 869 | - /** | |
| 870 | - * _verify_transaction_and_get_registrations | |
| 871 | - * | |
| 872 | - * @access private | |
| 873 | - * @return bool | |
| 874 | - * @throws InvalidDataTypeException | |
| 875 | - * @throws InvalidEntityException | |
| 876 | - * @throws EE_Error | |
| 877 | - */ | |
| 878 | - private function _verify_transaction_and_get_registrations() | |
| 879 | -    { | |
| 880 | - // was there already a valid transaction in the checkout from the session ? | |
| 881 | -        if ( ! $this->checkout->transaction instanceof EE_Transaction) { | |
| 882 | - // get transaction from db or session | |
| 883 | - $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() | |
| 884 | - ? $this->_get_transaction_and_cart_for_previous_visit() | |
| 885 | - : $this->_get_cart_for_current_session_and_setup_new_transaction(); | |
| 886 | -            if ( ! $this->checkout->transaction instanceof EE_Transaction) { | |
| 887 | - EE_Error::add_error( | |
| 888 | -                    __('Your Registration and Transaction information could not be retrieved from the db.', | |
| 889 | - 'event_espresso'), | |
| 890 | - __FILE__, __FUNCTION__, __LINE__ | |
| 891 | - ); | |
| 892 | - $this->checkout->transaction = EE_Transaction::new_instance(); | |
| 893 | - // add some style and make it dance | |
| 894 | - $this->add_styles_and_scripts(); | |
| 895 | - EED_Single_Page_Checkout::$_initialized = true; | |
| 896 | - return false; | |
| 897 | - } | |
| 898 | - // and the registrations for the transaction | |
| 899 | - $this->_get_registrations($this->checkout->transaction); | |
| 900 | - } | |
| 901 | - return true; | |
| 902 | - } | |
| 903 | - | |
| 904 | - | |
| 905 | - | |
| 906 | - /** | |
| 907 | - * _get_transaction_and_cart_for_previous_visit | |
| 908 | - * | |
| 909 | - * @access private | |
| 910 | - * @return mixed EE_Transaction|NULL | |
| 911 | - */ | |
| 912 | - private function _get_transaction_and_cart_for_previous_visit() | |
| 913 | -    { | |
| 914 | - /** @var $TXN_model EEM_Transaction */ | |
| 915 | -        $TXN_model = EE_Registry::instance()->load_model('Transaction'); | |
| 916 | - // because the reg_url_link is present in the request, | |
| 917 | - // this is a return visit to SPCO, so we'll get the transaction data from the db | |
| 918 | - $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); | |
| 919 | - // verify transaction | |
| 920 | -        if ($transaction instanceof EE_Transaction) { | |
| 921 | - // and get the cart that was used for that transaction | |
| 922 | - $this->checkout->cart = $this->_get_cart_for_transaction($transaction); | |
| 923 | - return $transaction; | |
| 924 | - } | |
| 925 | - EE_Error::add_error( | |
| 926 | -            __('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), | |
| 927 | - __FILE__, __FUNCTION__, __LINE__ | |
| 928 | - ); | |
| 929 | - return null; | |
| 930 | - | |
| 931 | - } | |
| 932 | - | |
| 933 | - | |
| 934 | - | |
| 935 | - /** | |
| 936 | - * _get_cart_for_transaction | |
| 937 | - * | |
| 938 | - * @access private | |
| 939 | - * @param EE_Transaction $transaction | |
| 940 | - * @return EE_Cart | |
| 941 | - */ | |
| 942 | - private function _get_cart_for_transaction($transaction) | |
| 943 | -    { | |
| 944 | - return $this->checkout->get_cart_for_transaction($transaction); | |
| 945 | - } | |
| 946 | - | |
| 947 | - | |
| 948 | - | |
| 949 | - /** | |
| 950 | - * get_cart_for_transaction | |
| 951 | - * | |
| 952 | - * @access public | |
| 953 | - * @param EE_Transaction $transaction | |
| 954 | - * @return EE_Cart | |
| 955 | - */ | |
| 956 | - public function get_cart_for_transaction(EE_Transaction $transaction) | |
| 957 | -    { | |
| 958 | - return $this->checkout->get_cart_for_transaction($transaction); | |
| 959 | - } | |
| 960 | - | |
| 961 | - | |
| 962 | - | |
| 963 | - /** | |
| 964 | - * _get_transaction_and_cart_for_current_session | |
| 965 | - * generates a new EE_Transaction object and adds it to the $_transaction property. | |
| 966 | - * | |
| 967 | - * @access private | |
| 968 | - * @return EE_Transaction | |
| 969 | - * @throws EE_Error | |
| 970 | - */ | |
| 971 | - private function _get_cart_for_current_session_and_setup_new_transaction() | |
| 972 | -    { | |
| 973 | - // if there's no transaction, then this is the FIRST visit to SPCO | |
| 974 | - // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) | |
| 975 | - $this->checkout->cart = $this->_get_cart_for_transaction(null); | |
| 976 | - // and then create a new transaction | |
| 977 | - $transaction = $this->_initialize_transaction(); | |
| 978 | - // verify transaction | |
| 979 | -        if ($transaction instanceof EE_Transaction) { | |
| 980 | - // save it so that we have an ID for other objects to use | |
| 981 | - $transaction->save(); | |
| 982 | - // and save TXN data to the cart | |
| 983 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); | |
| 984 | -        } else { | |
| 985 | - EE_Error::add_error( | |
| 986 | -                __('A Valid Transaction could not be initialized.', 'event_espresso'), | |
| 987 | - __FILE__, __FUNCTION__, __LINE__ | |
| 988 | - ); | |
| 989 | - } | |
| 990 | - return $transaction; | |
| 991 | - } | |
| 992 | - | |
| 993 | - | |
| 994 | - | |
| 995 | - /** | |
| 996 | - * generates a new EE_Transaction object and adds it to the $_transaction property. | |
| 997 | - * | |
| 998 | - * @access private | |
| 999 | - * @return mixed EE_Transaction|NULL | |
| 1000 | - */ | |
| 1001 | - private function _initialize_transaction() | |
| 1002 | -    { | |
| 1003 | -        try { | |
| 1004 | - // ensure cart totals have been calculated | |
| 1005 | - $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); | |
| 1006 | - // grab the cart grand total | |
| 1007 | - $cart_total = $this->checkout->cart->get_cart_grand_total(); | |
| 1008 | - // create new TXN | |
| 1009 | - $transaction = EE_Transaction::new_instance( | |
| 1010 | - array( | |
| 1011 | - 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), | |
| 1012 | - 'TXN_total' => $cart_total > 0 ? $cart_total : 0, | |
| 1013 | - 'TXN_paid' => 0, | |
| 1014 | - 'STS_ID' => EEM_Transaction::failed_status_code, | |
| 1015 | - ) | |
| 1016 | - ); | |
| 1017 | - // save it so that we have an ID for other objects to use | |
| 1018 | - $transaction->save(); | |
| 1019 | - // set cron job for following up on TXNs after their session has expired | |
| 1020 | - EE_Cron_Tasks::schedule_expired_transaction_check( | |
| 1021 | - EE_Registry::instance()->SSN->expiration() + 1, | |
| 1022 | - $transaction->ID() | |
| 1023 | - ); | |
| 1024 | - return $transaction; | |
| 1025 | -        } catch (Exception $e) { | |
| 1026 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); | |
| 1027 | - } | |
| 1028 | - return null; | |
| 1029 | - } | |
| 1030 | - | |
| 1031 | - | |
| 1032 | - /** | |
| 1033 | - * _get_registrations | |
| 1034 | - * | |
| 1035 | - * @access private | |
| 1036 | - * @param EE_Transaction $transaction | |
| 1037 | - * @return void | |
| 1038 | - * @throws InvalidDataTypeException | |
| 1039 | - * @throws InvalidEntityException | |
| 1040 | - * @throws EE_Error | |
| 1041 | - */ | |
| 1042 | - private function _get_registrations(EE_Transaction $transaction) | |
| 1043 | -    { | |
| 1044 | -        // first step: grab the registrants  { : o | |
| 1045 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); | |
| 1046 | - // verify registrations have been set | |
| 1047 | -        if (empty($registrations)) { | |
| 1048 | - // if no cached registrations, then check the db | |
| 1049 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); | |
| 1050 | - // still nothing ? well as long as this isn't a revisit | |
| 1051 | -            if (empty($registrations) && ! $this->checkout->revisit) { | |
| 1052 | - // generate new registrations from scratch | |
| 1053 | - $registrations = $this->_initialize_registrations($transaction); | |
| 1054 | - } | |
| 1055 | - } | |
| 1056 | - // sort by their original registration order | |
| 1057 | -        usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); | |
| 1058 | - // then loop thru the array | |
| 1059 | -        foreach ($registrations as $registration) { | |
| 1060 | - // verify each registration | |
| 1061 | -            if ($registration instanceof EE_Registration) { | |
| 1062 | - // we display all attendee info for the primary registrant | |
| 1063 | - if ($this->checkout->reg_url_link === $registration->reg_url_link() | |
| 1064 | - && $registration->is_primary_registrant() | |
| 1065 | -                ) { | |
| 1066 | - $this->checkout->primary_revisit = true; | |
| 1067 | - break; | |
| 1068 | - } | |
| 1069 | - if ($this->checkout->revisit | |
| 1070 | - && $this->checkout->reg_url_link !== $registration->reg_url_link() | |
| 1071 | -                ) { | |
| 1072 | - // but hide info if it doesn't belong to you | |
| 1073 | -                    $transaction->clear_cache('Registration', $registration->ID()); | |
| 1074 | - } | |
| 1075 | - $this->checkout->set_reg_status_updated($registration->ID(), false); | |
| 1076 | - } | |
| 1077 | - } | |
| 1078 | - } | |
| 1079 | - | |
| 1080 | - | |
| 1081 | - /** | |
| 1082 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object | |
| 1083 | - * | |
| 1084 | - * @access private | |
| 1085 | - * @param EE_Transaction $transaction | |
| 1086 | - * @return array | |
| 1087 | - * @throws InvalidDataTypeException | |
| 1088 | - * @throws InvalidEntityException | |
| 1089 | - * @throws EE_Error | |
| 1090 | - */ | |
| 1091 | - private function _initialize_registrations(EE_Transaction $transaction) | |
| 1092 | -    { | |
| 1093 | - $att_nmbr = 0; | |
| 1094 | - $registrations = array(); | |
| 1095 | -        if ($transaction instanceof EE_Transaction) { | |
| 1096 | - /** @type EE_Registration_Processor $registration_processor */ | |
| 1097 | -            $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); | |
| 1098 | - $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); | |
| 1099 | - // now let's add the cart items to the $transaction | |
| 1100 | -            foreach ($this->checkout->cart->get_tickets() as $line_item) { | |
| 1101 | - //do the following for each ticket of this type they selected | |
| 1102 | -                for ($x = 1; $x <= $line_item->quantity(); $x++) { | |
| 1103 | - $att_nmbr++; | |
| 1104 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ | |
| 1105 | - $CreateRegistrationCommand = EE_Registry::instance()->create( | |
| 1106 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', | |
| 1107 | - array( | |
| 1108 | - $transaction, | |
| 1109 | - $line_item, | |
| 1110 | - $att_nmbr, | |
| 1111 | - $this->checkout->total_ticket_count, | |
| 1112 | - ) | |
| 1113 | - ); | |
| 1114 | - // override capabilities for frontend registrations | |
| 1115 | -                    if ( ! is_admin()) { | |
| 1116 | - $CreateRegistrationCommand->setCapCheck( | |
| 1117 | -                            new PublicCapabilities('', 'create_new_registration') | |
| 1118 | - ); | |
| 1119 | - } | |
| 1120 | - $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); | |
| 1121 | -                    if ( ! $registration instanceof EE_Registration) { | |
| 1122 | - throw new InvalidEntityException($registration, 'EE_Registration'); | |
| 1123 | - } | |
| 1124 | - $registrations[ $registration->ID() ] = $registration; | |
| 1125 | - } | |
| 1126 | - } | |
| 1127 | - $registration_processor->fix_reg_final_price_rounding_issue($transaction); | |
| 1128 | - } | |
| 1129 | - return $registrations; | |
| 1130 | - } | |
| 1131 | - | |
| 1132 | - | |
| 1133 | - | |
| 1134 | - /** | |
| 1135 | - * sorts registrations by REG_count | |
| 1136 | - * | |
| 1137 | - * @access public | |
| 1138 | - * @param EE_Registration $reg_A | |
| 1139 | - * @param EE_Registration $reg_B | |
| 1140 | - * @return int | |
| 1141 | - */ | |
| 1142 | - public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) | |
| 1143 | -    { | |
| 1144 | - // this shouldn't ever happen within the same TXN, but oh well | |
| 1145 | -        if ($reg_A->count() === $reg_B->count()) { | |
| 1146 | - return 0; | |
| 1147 | - } | |
| 1148 | - return ($reg_A->count() > $reg_B->count()) ? 1 : -1; | |
| 1149 | - } | |
| 1150 | - | |
| 1151 | - | |
| 1152 | - | |
| 1153 | - /** | |
| 1154 | - * _final_verifications | |
| 1155 | - * just makes sure that everything is set up correctly before proceeding | |
| 1156 | - * | |
| 1157 | - * @access private | |
| 1158 | - * @return bool | |
| 1159 | - * @throws EE_Error | |
| 1160 | - */ | |
| 1161 | - private function _final_verifications() | |
| 1162 | -    { | |
| 1163 | - // filter checkout | |
| 1164 | - $this->checkout = apply_filters( | |
| 1165 | - 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', | |
| 1166 | - $this->checkout | |
| 1167 | - ); | |
| 1168 | - //verify that current step is still set correctly | |
| 1169 | -        if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { | |
| 1170 | - EE_Error::add_error( | |
| 1171 | -                __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), | |
| 1172 | - __FILE__, | |
| 1173 | - __FUNCTION__, | |
| 1174 | - __LINE__ | |
| 1175 | - ); | |
| 1176 | - return false; | |
| 1177 | - } | |
| 1178 | - // if returning to SPCO, then verify that primary registrant is set | |
| 1179 | -        if ( ! empty($this->checkout->reg_url_link)) { | |
| 1180 | - $valid_registrant = $this->checkout->transaction->primary_registration(); | |
| 1181 | -            if ( ! $valid_registrant instanceof EE_Registration) { | |
| 1182 | - EE_Error::add_error( | |
| 1183 | -                    __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), | |
| 1184 | - __FILE__, | |
| 1185 | - __FUNCTION__, | |
| 1186 | - __LINE__ | |
| 1187 | - ); | |
| 1188 | - return false; | |
| 1189 | - } | |
| 1190 | - $valid_registrant = null; | |
| 1191 | - foreach ( | |
| 1192 | - $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration | |
| 1193 | -            ) { | |
| 1194 | - if ( | |
| 1195 | - $registration instanceof EE_Registration | |
| 1196 | - && $registration->reg_url_link() === $this->checkout->reg_url_link | |
| 1197 | -                ) { | |
| 1198 | - $valid_registrant = $registration; | |
| 1199 | - } | |
| 1200 | - } | |
| 1201 | -            if ( ! $valid_registrant instanceof EE_Registration) { | |
| 1202 | - // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? | |
| 1203 | -                if (EED_Single_Page_Checkout::$_checkout_verified) { | |
| 1204 | - // clear the session, mark the checkout as unverified, and try again | |
| 1205 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); | |
| 1206 | - EED_Single_Page_Checkout::$_initialized = false; | |
| 1207 | - EED_Single_Page_Checkout::$_checkout_verified = false; | |
| 1208 | - $this->_initialize(); | |
| 1209 | - EE_Error::reset_notices(); | |
| 1210 | - return false; | |
| 1211 | - } | |
| 1212 | - EE_Error::add_error( | |
| 1213 | - __( | |
| 1214 | - 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', | |
| 1215 | - 'event_espresso' | |
| 1216 | - ), | |
| 1217 | - __FILE__, | |
| 1218 | - __FUNCTION__, | |
| 1219 | - __LINE__ | |
| 1220 | - ); | |
| 1221 | - return false; | |
| 1222 | - } | |
| 1223 | - } | |
| 1224 | - // now that things have been kinda sufficiently verified, | |
| 1225 | - // let's add the checkout to the session so that it's available to other systems | |
| 1226 | - EE_Registry::instance()->SSN->set_checkout($this->checkout); | |
| 1227 | - return true; | |
| 1228 | - } | |
| 1229 | - | |
| 1230 | - | |
| 1231 | - | |
| 1232 | - /** | |
| 1233 | - * _initialize_reg_steps | |
| 1234 | - * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required | |
| 1235 | - * then loops thru all of the active reg steps and calls the initialize_reg_step() method | |
| 1236 | - * | |
| 1237 | - * @access private | |
| 1238 | - * @param bool $reinitializing | |
| 1239 | - * @throws EE_Error | |
| 1240 | - */ | |
| 1241 | - private function _initialize_reg_steps($reinitializing = false) | |
| 1242 | -    { | |
| 1243 | - $this->checkout->set_reg_step_initiated($this->checkout->current_step); | |
| 1244 | - // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS | |
| 1245 | -        foreach ($this->checkout->reg_steps as $reg_step) { | |
| 1246 | -            if ( ! $reg_step->initialize_reg_step()) { | |
| 1247 | - // if not initialized then maybe this step is being removed... | |
| 1248 | -                if ( ! $reinitializing && $reg_step->is_current_step()) { | |
| 1249 | - // if it was the current step, then we need to start over here | |
| 1250 | - $this->_initialize_reg_steps(true); | |
| 1251 | - return; | |
| 1252 | - } | |
| 1253 | - continue; | |
| 1254 | - } | |
| 1255 | - // add css and JS for current step | |
| 1256 | - $reg_step->enqueue_styles_and_scripts(); | |
| 1257 | - // i18n | |
| 1258 | - $reg_step->translate_js_strings(); | |
| 1259 | -            if ($reg_step->is_current_step()) { | |
| 1260 | - // the text that appears on the reg step form submit button | |
| 1261 | - $reg_step->set_submit_button_text(); | |
| 1262 | - } | |
| 1263 | - } | |
| 1264 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information | |
| 1265 | - do_action( | |
| 1266 | -            "AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", | |
| 1267 | - $this->checkout->current_step | |
| 1268 | - ); | |
| 1269 | - } | |
| 1270 | - | |
| 1271 | - | |
| 1272 | - | |
| 1273 | - /** | |
| 1274 | - * _check_form_submission | |
| 1275 | - * | |
| 1276 | - * @access private | |
| 1277 | - * @return boolean | |
| 1278 | - */ | |
| 1279 | - private function _check_form_submission() | |
| 1280 | -    { | |
| 1281 | - //does this request require the reg form to be generated ? | |
| 1282 | -        if ($this->checkout->generate_reg_form) { | |
| 1283 | - // ever heard that song by Blue Rodeo ? | |
| 1284 | -            try { | |
| 1285 | - $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); | |
| 1286 | - // if not displaying a form, then check for form submission | |
| 1287 | - if ( | |
| 1288 | - $this->checkout->process_form_submission | |
| 1289 | - && $this->checkout->current_step->reg_form->was_submitted() | |
| 1290 | -                ) { | |
| 1291 | - // clear out any old data in case this step is being run again | |
| 1292 | - $this->checkout->current_step->set_valid_data(array()); | |
| 1293 | - // capture submitted form data | |
| 1294 | - $this->checkout->current_step->reg_form->receive_form_submission( | |
| 1295 | - apply_filters( | |
| 1296 | - 'FHEE__Single_Page_Checkout___check_form_submission__request_params', | |
| 1297 | - EE_Registry::instance()->REQ->params(), | |
| 1298 | - $this->checkout | |
| 1299 | - ) | |
| 1300 | - ); | |
| 1301 | - // validate submitted form data | |
| 1302 | -                    if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { | |
| 1303 | - // thou shall not pass !!! | |
| 1304 | - $this->checkout->continue_reg = false; | |
| 1305 | - // any form validation errors? | |
| 1306 | -                        if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { | |
| 1307 | - $submission_error_messages = array(); | |
| 1308 | - // bad, bad, bad registrant | |
| 1309 | - foreach ( | |
| 1310 | - $this->checkout->current_step->reg_form->get_validation_errors_accumulated() | |
| 1311 | - as $validation_error | |
| 1312 | -                            ) { | |
| 1313 | -                                if ($validation_error instanceof EE_Validation_Error) { | |
| 1314 | - $submission_error_messages[] = sprintf( | |
| 1315 | -                                        __('%s : %s', 'event_espresso'), | |
| 1316 | - $validation_error->get_form_section()->html_label_text(), | |
| 1317 | - $validation_error->getMessage() | |
| 1318 | - ); | |
| 1319 | - } | |
| 1320 | - } | |
| 1321 | - EE_Error::add_error( | |
| 1322 | -                                implode('<br />', $submission_error_messages), | |
| 1323 | - __FILE__, __FUNCTION__, __LINE__ | |
| 1324 | - ); | |
| 1325 | - } | |
| 1326 | - // well not really... what will happen is | |
| 1327 | - // we'll just get redirected back to redo the current step | |
| 1328 | - $this->go_to_next_step(); | |
| 1329 | - return false; | |
| 1330 | - } | |
| 1331 | - } | |
| 1332 | -            } catch (EE_Error $e) { | |
| 1333 | - $e->get_error(); | |
| 1334 | - } | |
| 1335 | - } | |
| 1336 | - return true; | |
| 1337 | - } | |
| 1338 | - | |
| 1339 | - | |
| 1340 | - | |
| 1341 | - /** | |
| 1342 | - * _process_action | |
| 1343 | - * | |
| 1344 | - * @access private | |
| 1345 | - * @return void | |
| 1346 | - * @throws EE_Error | |
| 1347 | - */ | |
| 1348 | - private function _process_form_action() | |
| 1349 | -    { | |
| 1350 | - // what cha wanna do? | |
| 1351 | -        switch ($this->checkout->action) { | |
| 1352 | - // AJAX next step reg form | |
| 1353 | - case 'display_spco_reg_step' : | |
| 1354 | - $this->checkout->redirect = false; | |
| 1355 | -                if (EE_Registry::instance()->REQ->ajax) { | |
| 1356 | - $this->checkout->json_response->set_reg_step_html( | |
| 1357 | - $this->checkout->current_step->display_reg_form() | |
| 1358 | - ); | |
| 1359 | - } | |
| 1360 | - break; | |
| 1361 | - default : | |
| 1362 | - // meh... do one of those other steps first | |
| 1363 | - if ( | |
| 1364 | - ! empty($this->checkout->action) | |
| 1365 | - && is_callable(array($this->checkout->current_step, $this->checkout->action)) | |
| 1366 | -                ) { | |
| 1367 | - // dynamically creates hook point like: | |
| 1368 | - // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step | |
| 1369 | - do_action( | |
| 1370 | -                        "AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", | |
| 1371 | - $this->checkout->current_step | |
| 1372 | - ); | |
| 1373 | - // call action on current step | |
| 1374 | -                    if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { | |
| 1375 | - // good registrant, you get to proceed | |
| 1376 | - if ( | |
| 1377 | - $this->checkout->current_step->success_message() !== '' | |
| 1378 | - && apply_filters( | |
| 1379 | - 'FHEE__Single_Page_Checkout___process_form_action__display_success', | |
| 1380 | - false | |
| 1381 | - ) | |
| 1382 | -                        ) { | |
| 1383 | - EE_Error::add_success( | |
| 1384 | - $this->checkout->current_step->success_message() | |
| 1385 | - . '<br />' . $this->checkout->next_step->_instructions() | |
| 1386 | - ); | |
| 1387 | - } | |
| 1388 | - // pack it up, pack it in... | |
| 1389 | - $this->_setup_redirect(); | |
| 1390 | - } | |
| 1391 | - // dynamically creates hook point like: | |
| 1392 | - // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step | |
| 1393 | - do_action( | |
| 1394 | -                        "AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", | |
| 1395 | - $this->checkout->current_step | |
| 1396 | - ); | |
| 1397 | -                } else { | |
| 1398 | - EE_Error::add_error( | |
| 1399 | - sprintf( | |
| 1400 | - __( | |
| 1401 | - 'The requested form action "%s" does not exist for the current "%s" registration step.', | |
| 1402 | - 'event_espresso' | |
| 1403 | - ), | |
| 1404 | - $this->checkout->action, | |
| 1405 | - $this->checkout->current_step->name() | |
| 1406 | - ), | |
| 1407 | - __FILE__, | |
| 1408 | - __FUNCTION__, | |
| 1409 | - __LINE__ | |
| 1410 | - ); | |
| 1411 | - } | |
| 1412 | - // end default | |
| 1413 | - } | |
| 1414 | - // store our progress so far | |
| 1415 | - $this->checkout->stash_transaction_and_checkout(); | |
| 1416 | - // advance to the next step! If you pass GO, collect $200 | |
| 1417 | - $this->go_to_next_step(); | |
| 1418 | - } | |
| 1419 | - | |
| 1420 | - | |
| 1421 | - | |
| 1422 | - /** | |
| 1423 | - * add_styles_and_scripts | |
| 1424 | - * | |
| 1425 | - * @access public | |
| 1426 | - * @return void | |
| 1427 | - */ | |
| 1428 | - public function add_styles_and_scripts() | |
| 1429 | -    { | |
| 1430 | - // i18n | |
| 1431 | - $this->translate_js_strings(); | |
| 1432 | -        if ($this->checkout->admin_request) { | |
| 1433 | -            add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); | |
| 1434 | -        } else { | |
| 1435 | -            add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); | |
| 1436 | - } | |
| 1437 | - } | |
| 1438 | - | |
| 1439 | - | |
| 1440 | - | |
| 1441 | - /** | |
| 1442 | - * translate_js_strings | |
| 1443 | - * | |
| 1444 | - * @access public | |
| 1445 | - * @return void | |
| 1446 | - */ | |
| 1447 | - public function translate_js_strings() | |
| 1448 | -    { | |
| 1449 | - EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; | |
| 1450 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; | |
| 1451 | - EE_Registry::$i18n_js_strings['server_error'] = __( | |
| 1452 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', | |
| 1453 | - 'event_espresso' | |
| 1454 | - ); | |
| 1455 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __( | |
| 1456 | - 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', | |
| 1457 | - 'event_espresso' | |
| 1458 | - ); | |
| 1459 | - EE_Registry::$i18n_js_strings['validation_error'] = __( | |
| 1460 | - 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', | |
| 1461 | - 'event_espresso' | |
| 1462 | - ); | |
| 1463 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( | |
| 1464 | - 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', | |
| 1465 | - 'event_espresso' | |
| 1466 | - ); | |
| 1467 | - EE_Registry::$i18n_js_strings['reg_step_error'] = __( | |
| 1468 | - 'This registration step could not be completed. Please refresh the page and try again.', | |
| 1469 | - 'event_espresso' | |
| 1470 | - ); | |
| 1471 | - EE_Registry::$i18n_js_strings['invalid_coupon'] = __( | |
| 1472 | - 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', | |
| 1473 | - 'event_espresso' | |
| 1474 | - ); | |
| 1475 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( | |
| 1476 | - __( | |
| 1477 | - 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', | |
| 1478 | - 'event_espresso' | |
| 1479 | - ), | |
| 1480 | - '<br/>', | |
| 1481 | - '<br/>' | |
| 1482 | - ); | |
| 1483 | -        EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); | |
| 1484 | - EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); | |
| 1485 | - EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; | |
| 1486 | - EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; | |
| 1487 | -        EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); | |
| 1488 | -        EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); | |
| 1489 | -        EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); | |
| 1490 | -        EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); | |
| 1491 | -        EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); | |
| 1492 | -        EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); | |
| 1493 | -        EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); | |
| 1494 | -        EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); | |
| 1495 | -        EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); | |
| 1496 | -        EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); | |
| 1497 | -        EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); | |
| 1498 | -        EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); | |
| 1499 | -        EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); | |
| 1500 | -        EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); | |
| 1501 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( | |
| 1502 | - __( | |
| 1503 | - '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', | |
| 1504 | - 'event_espresso' | |
| 1505 | - ), | |
| 1506 | - '<h4 class="important-notice">', | |
| 1507 | - '</h4>', | |
| 1508 | - '<br />', | |
| 1509 | - '<p>', | |
| 1510 | -            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', | |
| 1511 | - '">', | |
| 1512 | - '</a>', | |
| 1513 | - '</p>' | |
| 1514 | - ); | |
| 1515 | - EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( | |
| 1516 | - 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', | |
| 1517 | - true | |
| 1518 | - ); | |
| 1519 | - EE_Registry::$i18n_js_strings['session_extension'] = absint( | |
| 1520 | -            apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) | |
| 1521 | - ); | |
| 1522 | - EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( | |
| 1523 | - 'M d, Y H:i:s', | |
| 1524 | -            EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) | |
| 1525 | - ); | |
| 1526 | - } | |
| 1527 | - | |
| 1528 | - | |
| 1529 | - | |
| 1530 | - /** | |
| 1531 | - * enqueue_styles_and_scripts | |
| 1532 | - * | |
| 1533 | - * @access public | |
| 1534 | - * @return void | |
| 1535 | - * @throws EE_Error | |
| 1536 | - */ | |
| 1537 | - public function enqueue_styles_and_scripts() | |
| 1538 | -    { | |
| 1539 | - // load css | |
| 1540 | - wp_register_style( | |
| 1541 | - 'single_page_checkout', | |
| 1542 | - SPCO_CSS_URL . 'single_page_checkout.css', | |
| 1543 | -            array('espresso_default'), | |
| 1544 | - EVENT_ESPRESSO_VERSION | |
| 1545 | - ); | |
| 1546 | -        wp_enqueue_style('single_page_checkout'); | |
| 1547 | - // load JS | |
| 1548 | - wp_register_script( | |
| 1549 | - 'jquery_plugin', | |
| 1550 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', | |
| 1551 | -            array('jquery'), | |
| 1552 | - '1.0.1', | |
| 1553 | - true | |
| 1554 | - ); | |
| 1555 | - wp_register_script( | |
| 1556 | - 'jquery_countdown', | |
| 1557 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', | |
| 1558 | -            array('jquery_plugin'), | |
| 1559 | - '2.0.2', | |
| 1560 | - true | |
| 1561 | - ); | |
| 1562 | - wp_register_script( | |
| 1563 | - 'single_page_checkout', | |
| 1564 | - SPCO_JS_URL . 'single_page_checkout.js', | |
| 1565 | -            array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), | |
| 1566 | - EVENT_ESPRESSO_VERSION, | |
| 1567 | - true | |
| 1568 | - ); | |
| 1569 | -        if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { | |
| 1570 | - $this->checkout->registration_form->enqueue_js(); | |
| 1571 | - } | |
| 1572 | -        if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { | |
| 1573 | - $this->checkout->current_step->reg_form->enqueue_js(); | |
| 1574 | - } | |
| 1575 | -        wp_enqueue_script('single_page_checkout'); | |
| 1576 | - /** | |
| 1577 | - * global action hook for enqueueing styles and scripts with | |
| 1578 | - * spco calls. | |
| 1579 | - */ | |
| 1580 | -        do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); | |
| 1581 | - /** | |
| 1582 | - * dynamic action hook for enqueueing styles and scripts with spco calls. | |
| 1583 | - * The hook will end up being something like: | |
| 1584 | - * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information | |
| 1585 | - */ | |
| 1586 | - do_action( | |
| 1587 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), | |
| 1588 | - $this | |
| 1589 | - ); | |
| 1590 | - } | |
| 1591 | - | |
| 1592 | - | |
| 1593 | - | |
| 1594 | - /** | |
| 1595 | - * display the Registration Single Page Checkout Form | |
| 1596 | - * | |
| 1597 | - * @access private | |
| 1598 | - * @return void | |
| 1599 | - * @throws EE_Error | |
| 1600 | - */ | |
| 1601 | - private function _display_spco_reg_form() | |
| 1602 | -    { | |
| 1603 | - // if registering via the admin, just display the reg form for the current step | |
| 1604 | -        if ($this->checkout->admin_request) { | |
| 1605 | - EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); | |
| 1606 | -        } else { | |
| 1607 | - // add powered by EE msg | |
| 1608 | -            add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); | |
| 1609 | - $empty_cart = count( | |
| 1610 | - $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) | |
| 1611 | - ) < 1; | |
| 1612 | - EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; | |
| 1613 | - $cookies_not_set_msg = ''; | |
| 1614 | -            if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { | |
| 1615 | - $cookies_not_set_msg = apply_filters( | |
| 1616 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', | |
| 1617 | - sprintf( | |
| 1618 | - __( | |
| 1619 | - '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', | |
| 1620 | - 'event_espresso' | |
| 1621 | - ), | |
| 1622 | - '<div class="ee-attention">', | |
| 1623 | - '</div>', | |
| 1624 | - '<h6 class="important-notice">', | |
| 1625 | - '</h6>', | |
| 1626 | - '<p>', | |
| 1627 | - '</p>', | |
| 1628 | - '<br />', | |
| 1629 | - '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', | |
| 1630 | - '</a>' | |
| 1631 | - ) | |
| 1632 | - ); | |
| 1633 | - } | |
| 1634 | - $this->checkout->registration_form = new EE_Form_Section_Proper( | |
| 1635 | - array( | |
| 1636 | - 'name' => 'single-page-checkout', | |
| 1637 | - 'html_id' => 'ee-single-page-checkout-dv', | |
| 1638 | - 'layout_strategy' => | |
| 1639 | - new EE_Template_Layout( | |
| 1640 | - array( | |
| 1641 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', | |
| 1642 | - 'template_args' => array( | |
| 1643 | - 'empty_cart' => $empty_cart, | |
| 1644 | - 'revisit' => $this->checkout->revisit, | |
| 1645 | - 'reg_steps' => $this->checkout->reg_steps, | |
| 1646 | - 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step | |
| 1647 | - ? $this->checkout->next_step->slug() | |
| 1648 | - : '', | |
| 1649 | - 'cancel_page_url' => $this->checkout->cancel_page_url, | |
| 1650 | - 'empty_msg' => apply_filters( | |
| 1651 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', | |
| 1652 | - sprintf( | |
| 1653 | - __( | |
| 1654 | - 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', | |
| 1655 | - 'event_espresso' | |
| 1656 | - ), | |
| 1657 | - '<a href="' | |
| 1658 | -                                            . get_post_type_archive_link('espresso_events') | |
| 1659 | - . '" title="', | |
| 1660 | - '">', | |
| 1661 | - '</a>' | |
| 1662 | - ) | |
| 1663 | - ), | |
| 1664 | - 'cookies_not_set_msg' => $cookies_not_set_msg, | |
| 1665 | - 'registration_time_limit' => $this->checkout->get_registration_time_limit(), | |
| 1666 | - 'session_expiration' => gmdate( | |
| 1667 | - 'M d, Y H:i:s', | |
| 1668 | - EE_Registry::instance()->SSN->expiration() | |
| 1669 | -                                        + (get_option('gmt_offset') * HOUR_IN_SECONDS) | |
| 1670 | - ), | |
| 1671 | - ), | |
| 1672 | - ) | |
| 1673 | - ), | |
| 1674 | - ) | |
| 1675 | - ); | |
| 1676 | - // load template and add to output sent that gets filtered into the_content() | |
| 1677 | - EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); | |
| 1678 | - } | |
| 1679 | - } | |
| 1680 | - | |
| 1681 | - | |
| 1682 | - | |
| 1683 | - /** | |
| 1684 | - * add_extra_finalize_registration_inputs | |
| 1685 | - * | |
| 1686 | - * @access public | |
| 1687 | - * @param $next_step | |
| 1688 | - * @internal param string $label | |
| 1689 | - * @return void | |
| 1690 | - */ | |
| 1691 | - public function add_extra_finalize_registration_inputs($next_step) | |
| 1692 | -    { | |
| 1693 | -        if ($next_step === 'finalize_registration') { | |
| 1694 | - echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; | |
| 1695 | - } | |
| 1696 | - } | |
| 1697 | - | |
| 1698 | - | |
| 1699 | - | |
| 1700 | - /** | |
| 1701 | - * display_registration_footer | |
| 1702 | - * | |
| 1703 | - * @access public | |
| 1704 | - * @return string | |
| 1705 | - */ | |
| 1706 | - public static function display_registration_footer() | |
| 1707 | -    { | |
| 1708 | - if ( | |
| 1709 | - apply_filters( | |
| 1710 | - 'FHEE__EE_Front__Controller__show_reg_footer', | |
| 1711 | - EE_Registry::instance()->CFG->admin->show_reg_footer | |
| 1712 | - ) | |
| 1713 | -        ) { | |
| 1714 | - add_filter( | |
| 1715 | - 'FHEE__EEH_Template__powered_by_event_espresso__url', | |
| 1716 | -                function ($url) { | |
| 1717 | -                    return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); | |
| 1718 | - } | |
| 1719 | - ); | |
| 1720 | - echo apply_filters( | |
| 1721 | - 'FHEE__EE_Front_Controller__display_registration_footer', | |
| 1722 | - \EEH_Template::powered_by_event_espresso( | |
| 1723 | - '', | |
| 1724 | - 'espresso-registration-footer-dv', | |
| 1725 | -                    array('utm_content' => 'registration_checkout') | |
| 1726 | - ) | |
| 1727 | - ); | |
| 1728 | - } | |
| 1729 | - return ''; | |
| 1730 | - } | |
| 1731 | - | |
| 1732 | - | |
| 1733 | - | |
| 1734 | - /** | |
| 1735 | - * unlock_transaction | |
| 1736 | - * | |
| 1737 | - * @access public | |
| 1738 | - * @return void | |
| 1739 | - * @throws EE_Error | |
| 1740 | - */ | |
| 1741 | - public function unlock_transaction() | |
| 1742 | -    { | |
| 1743 | -        if ($this->checkout->transaction instanceof EE_Transaction) { | |
| 1744 | - $this->checkout->transaction->unlock(); | |
| 1745 | - } | |
| 1746 | - } | |
| 1747 | - | |
| 1748 | - | |
| 1749 | - | |
| 1750 | - /** | |
| 1751 | - * _setup_redirect | |
| 1752 | - * | |
| 1753 | - * @access private | |
| 1754 | - * @return void | |
| 1755 | - */ | |
| 1756 | - private function _setup_redirect() | |
| 1757 | -    { | |
| 1758 | -        if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { | |
| 1759 | - $this->checkout->redirect = true; | |
| 1760 | -            if (empty($this->checkout->redirect_url)) { | |
| 1761 | - $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); | |
| 1762 | - } | |
| 1763 | - $this->checkout->redirect_url = apply_filters( | |
| 1764 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', | |
| 1765 | - $this->checkout->redirect_url, | |
| 1766 | - $this->checkout | |
| 1767 | - ); | |
| 1768 | - } | |
| 1769 | - } | |
| 1770 | - | |
| 1771 | - | |
| 1772 | - | |
| 1773 | - /** | |
| 1774 | - * handle ajax message responses and redirects | |
| 1775 | - * | |
| 1776 | - * @access public | |
| 1777 | - * @return void | |
| 1778 | - * @throws EE_Error | |
| 1779 | - */ | |
| 1780 | - public function go_to_next_step() | |
| 1781 | -    { | |
| 1782 | -        if (EE_Registry::instance()->REQ->ajax) { | |
| 1783 | - // capture contents of output buffer we started earlier in the request, and insert into JSON response | |
| 1784 | - $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); | |
| 1785 | - } | |
| 1786 | - $this->unlock_transaction(); | |
| 1787 | - // just return for these conditions | |
| 1788 | - if ( | |
| 1789 | - $this->checkout->admin_request | |
| 1790 | - || $this->checkout->action === 'redirect_form' | |
| 1791 | - || $this->checkout->action === 'update_checkout' | |
| 1792 | -        ) { | |
| 1793 | - return; | |
| 1794 | - } | |
| 1795 | - // AJAX response | |
| 1796 | - $this->_handle_json_response(); | |
| 1797 | - // redirect to next step or the Thank You page | |
| 1798 | - $this->_handle_html_redirects(); | |
| 1799 | - // hmmm... must be something wrong, so let's just display the form again ! | |
| 1800 | - $this->_display_spco_reg_form(); | |
| 1801 | - } | |
| 1802 | - | |
| 1803 | - | |
| 1804 | - | |
| 1805 | - /** | |
| 1806 | - * _handle_json_response | |
| 1807 | - * | |
| 1808 | - * @access protected | |
| 1809 | - * @return void | |
| 1810 | - */ | |
| 1811 | - protected function _handle_json_response() | |
| 1812 | -    { | |
| 1813 | - // if this is an ajax request | |
| 1814 | -        if (EE_Registry::instance()->REQ->ajax) { | |
| 1815 | - // DEBUG LOG | |
| 1816 | - //$this->checkout->log( | |
| 1817 | - // __CLASS__, __FUNCTION__, __LINE__, | |
| 1818 | - // array( | |
| 1819 | - // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), | |
| 1820 | - // 'redirect' => $this->checkout->redirect, | |
| 1821 | - // 'continue_reg' => $this->checkout->continue_reg, | |
| 1822 | - // ) | |
| 1823 | - //); | |
| 1824 | - $this->checkout->json_response->set_registration_time_limit( | |
| 1825 | - $this->checkout->get_registration_time_limit() | |
| 1826 | - ); | |
| 1827 | - $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); | |
| 1828 | - // just send the ajax ( | |
| 1829 | - $json_response = apply_filters( | |
| 1830 | - 'FHEE__EE_Single_Page_Checkout__JSON_response', | |
| 1831 | - $this->checkout->json_response | |
| 1832 | - ); | |
| 1833 | - echo $json_response; | |
| 1834 | - exit(); | |
| 1835 | - } | |
| 1836 | - } | |
| 1837 | - | |
| 1838 | - | |
| 1839 | - | |
| 1840 | - /** | |
| 1841 | - * _handle_redirects | |
| 1842 | - * | |
| 1843 | - * @access protected | |
| 1844 | - * @return void | |
| 1845 | - */ | |
| 1846 | - protected function _handle_html_redirects() | |
| 1847 | -    { | |
| 1848 | - // going somewhere ? | |
| 1849 | -        if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { | |
| 1850 | - // store notices in a transient | |
| 1851 | - EE_Error::get_notices(false, true, true); | |
| 1852 | - // DEBUG LOG | |
| 1853 | - //$this->checkout->log( | |
| 1854 | - // __CLASS__, __FUNCTION__, __LINE__, | |
| 1855 | - // array( | |
| 1856 | - // 'headers_sent' => headers_sent(), | |
| 1857 | - // 'redirect_url' => $this->checkout->redirect_url, | |
| 1858 | - // 'headers_list' => headers_list(), | |
| 1859 | - // ) | |
| 1860 | - //); | |
| 1861 | - wp_safe_redirect($this->checkout->redirect_url); | |
| 1862 | - exit(); | |
| 1863 | - } | |
| 1864 | - } | |
| 1865 | - | |
| 1866 | - | |
| 1867 | - | |
| 1868 | - /** | |
| 1869 | - * set_checkout_anchor | |
| 1870 | - * | |
| 1871 | - * @access public | |
| 1872 | - * @return void | |
| 1873 | - */ | |
| 1874 | - public function set_checkout_anchor() | |
| 1875 | -    { | |
| 1876 | - echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; | |
| 1877 | - } | |
| 23 | + /** | |
| 24 | + * $_initialized - has the SPCO controller already been initialized ? | |
| 25 | + * | |
| 26 | + * @access private | |
| 27 | + * @var bool $_initialized | |
| 28 | + */ | |
| 29 | + private static $_initialized = false; | |
| 30 | + | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * $_checkout_verified - is the EE_Checkout verified as correct for this request ? | |
| 34 | + * | |
| 35 | + * @access private | |
| 36 | + * @var bool $_valid_checkout | |
| 37 | + */ | |
| 38 | + private static $_checkout_verified = true; | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * $_reg_steps_array - holds initial array of reg steps | |
| 42 | + * | |
| 43 | + * @access private | |
| 44 | + * @var array $_reg_steps_array | |
| 45 | + */ | |
| 46 | + private static $_reg_steps_array = array(); | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process | |
| 50 | + * | |
| 51 | + * @access public | |
| 52 | + * @var EE_Checkout $checkout | |
| 53 | + */ | |
| 54 | + public $checkout; | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * @return EED_Module|EED_Single_Page_Checkout | |
| 60 | + */ | |
| 61 | + public static function instance() | |
| 62 | +	{ | |
| 63 | +		add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); | |
| 64 | + return parent::get_instance(__CLASS__); | |
| 65 | + } | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * @return EE_CART | |
| 71 | + */ | |
| 72 | + public function cart() | |
| 73 | +	{ | |
| 74 | + return $this->checkout->cart; | |
| 75 | + } | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * @return EE_Transaction | |
| 81 | + */ | |
| 82 | + public function transaction() | |
| 83 | +	{ | |
| 84 | + return $this->checkout->transaction; | |
| 85 | + } | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * set_hooks - for hooking into EE Core, other modules, etc | |
| 91 | + * | |
| 92 | + * @access public | |
| 93 | + * @return void | |
| 94 | + * @throws EE_Error | |
| 95 | + */ | |
| 96 | + public static function set_hooks() | |
| 97 | +	{ | |
| 98 | + EED_Single_Page_Checkout::set_definitions(); | |
| 99 | + } | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + /** | |
| 104 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc | |
| 105 | + * | |
| 106 | + * @access public | |
| 107 | + * @return void | |
| 108 | + * @throws EE_Error | |
| 109 | + */ | |
| 110 | + public static function set_hooks_admin() | |
| 111 | +	{ | |
| 112 | + EED_Single_Page_Checkout::set_definitions(); | |
| 113 | +		if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { | |
| 114 | + return; | |
| 115 | + } | |
| 116 | + // going to start an output buffer in case anything gets accidentally output | |
| 117 | + // that might disrupt our JSON response | |
| 118 | + ob_start(); | |
| 119 | + EED_Single_Page_Checkout::load_request_handler(); | |
| 120 | + EED_Single_Page_Checkout::load_reg_steps(); | |
| 121 | + // set ajax hooks | |
| 122 | +		add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); | |
| 123 | +		add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); | |
| 124 | +		add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); | |
| 125 | +		add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); | |
| 126 | +		add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); | |
| 127 | +		add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); | |
| 128 | + } | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * process ajax request | |
| 134 | + * | |
| 135 | + * @param string $ajax_action | |
| 136 | + * @throws EE_Error | |
| 137 | + */ | |
| 138 | + public static function process_ajax_request($ajax_action) | |
| 139 | +	{ | |
| 140 | +		EE_Registry::instance()->REQ->set('action', $ajax_action); | |
| 141 | + EED_Single_Page_Checkout::instance()->_initialize(); | |
| 142 | + } | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * ajax display registration step | |
| 148 | + * | |
| 149 | + * @throws EE_Error | |
| 150 | + */ | |
| 151 | + public static function display_reg_step() | |
| 152 | +	{ | |
| 153 | +		EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); | |
| 154 | + } | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + /** | |
| 159 | + * ajax process registration step | |
| 160 | + * | |
| 161 | + * @throws EE_Error | |
| 162 | + */ | |
| 163 | + public static function process_reg_step() | |
| 164 | +	{ | |
| 165 | +		EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); | |
| 166 | + } | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + /** | |
| 171 | + * ajax process registration step | |
| 172 | + * | |
| 173 | + * @throws EE_Error | |
| 174 | + */ | |
| 175 | + public static function update_reg_step() | |
| 176 | +	{ | |
| 177 | +		EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); | |
| 178 | + } | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + /** | |
| 183 | + * update_checkout | |
| 184 | + * | |
| 185 | + * @access public | |
| 186 | + * @return void | |
| 187 | + * @throws EE_Error | |
| 188 | + */ | |
| 189 | + public static function update_checkout() | |
| 190 | +	{ | |
| 191 | +		EED_Single_Page_Checkout::process_ajax_request('update_checkout'); | |
| 192 | + } | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + /** | |
| 197 | + * load_request_handler | |
| 198 | + * | |
| 199 | + * @access public | |
| 200 | + * @return void | |
| 201 | + */ | |
| 202 | + public static function load_request_handler() | |
| 203 | +	{ | |
| 204 | + // load core Request_Handler class | |
| 205 | +		if (EE_Registry::instance()->REQ !== null) { | |
| 206 | +			EE_Registry::instance()->load_core('Request_Handler'); | |
| 207 | + } | |
| 208 | + } | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + /** | |
| 213 | + * set_definitions | |
| 214 | + * | |
| 215 | + * @access public | |
| 216 | + * @return void | |
| 217 | + * @throws EE_Error | |
| 218 | + */ | |
| 219 | + public static function set_definitions() | |
| 220 | +	{ | |
| 221 | +		if(defined('SPCO_BASE_PATH')) { | |
| 222 | + return; | |
| 223 | + } | |
| 224 | + define( | |
| 225 | + 'SPCO_BASE_PATH', | |
| 226 | +			rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS | |
| 227 | + ); | |
| 228 | +		define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); | |
| 229 | +		define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); | |
| 230 | +		define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); | |
| 231 | +		define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); | |
| 232 | +		define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); | |
| 233 | +		define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); | |
| 234 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); | |
| 235 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( | |
| 236 | +			__('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', | |
| 237 | + 'event_espresso'), | |
| 238 | + '<h4 class="important-notice">', | |
| 239 | + '</h4>', | |
| 240 | + '<br />', | |
| 241 | + '<p>', | |
| 242 | +			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="', | |
| 243 | + '">', | |
| 244 | + '</a>', | |
| 245 | + '</p>' | |
| 246 | + ); | |
| 247 | + } | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + /** | |
| 252 | + * load_reg_steps | |
| 253 | + * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array | |
| 254 | + * | |
| 255 | + * @access private | |
| 256 | + * @throws EE_Error | |
| 257 | + */ | |
| 258 | + public static function load_reg_steps() | |
| 259 | +	{ | |
| 260 | + static $reg_steps_loaded = false; | |
| 261 | +		if ($reg_steps_loaded) { | |
| 262 | + return; | |
| 263 | + } | |
| 264 | + // filter list of reg_steps | |
| 265 | + $reg_steps_to_load = (array)apply_filters( | |
| 266 | + 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', | |
| 267 | + EED_Single_Page_Checkout::get_reg_steps() | |
| 268 | + ); | |
| 269 | + // sort by key (order) | |
| 270 | + ksort($reg_steps_to_load); | |
| 271 | + // loop through folders | |
| 272 | +		foreach ($reg_steps_to_load as $order => $reg_step) { | |
| 273 | + // we need a | |
| 274 | +			if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { | |
| 275 | + // copy over to the reg_steps_array | |
| 276 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; | |
| 277 | + // register custom key route for each reg step | |
| 278 | + // ie: step=>"slug" - this is the entire reason we load the reg steps array now | |
| 279 | + EE_Config::register_route( | |
| 280 | + $reg_step['slug'], | |
| 281 | + 'EED_Single_Page_Checkout', | |
| 282 | + 'run', | |
| 283 | + 'step' | |
| 284 | + ); | |
| 285 | + // add AJAX or other hooks | |
| 286 | +				if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { | |
| 287 | + // setup autoloaders if necessary | |
| 288 | +					if ( ! class_exists($reg_step['class_name'])) { | |
| 289 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder( | |
| 290 | + $reg_step['file_path'], | |
| 291 | + true | |
| 292 | + ); | |
| 293 | + } | |
| 294 | +					if (is_callable($reg_step['class_name'], 'set_hooks')) { | |
| 295 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); | |
| 296 | + } | |
| 297 | + } | |
| 298 | + } | |
| 299 | + } | |
| 300 | + $reg_steps_loaded = true; | |
| 301 | + } | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + /** | |
| 306 | + * get_reg_steps | |
| 307 | + * | |
| 308 | + * @access public | |
| 309 | + * @return array | |
| 310 | + */ | |
| 311 | + public static function get_reg_steps() | |
| 312 | +	{ | |
| 313 | + $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; | |
| 314 | +		if (empty($reg_steps)) { | |
| 315 | + $reg_steps = array( | |
| 316 | + 10 => array( | |
| 317 | + 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', | |
| 318 | + 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', | |
| 319 | + 'slug' => 'attendee_information', | |
| 320 | + 'has_hooks' => false, | |
| 321 | + ), | |
| 322 | + 20 => array( | |
| 323 | + 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', | |
| 324 | + 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', | |
| 325 | + 'slug' => 'registration_confirmation', | |
| 326 | + 'has_hooks' => false, | |
| 327 | + ), | |
| 328 | + 30 => array( | |
| 329 | + 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', | |
| 330 | + 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', | |
| 331 | + 'slug' => 'payment_options', | |
| 332 | + 'has_hooks' => true, | |
| 333 | + ), | |
| 334 | + 999 => array( | |
| 335 | + 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', | |
| 336 | + 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', | |
| 337 | + 'slug' => 'finalize_registration', | |
| 338 | + 'has_hooks' => false, | |
| 339 | + ), | |
| 340 | + ); | |
| 341 | + } | |
| 342 | + return $reg_steps; | |
| 343 | + } | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + /** | |
| 348 | + * registration_checkout_for_admin | |
| 349 | + * | |
| 350 | + * @access public | |
| 351 | + * @return string | |
| 352 | + * @throws EE_Error | |
| 353 | + */ | |
| 354 | + public static function registration_checkout_for_admin() | |
| 355 | +	{ | |
| 356 | + EED_Single_Page_Checkout::load_request_handler(); | |
| 357 | +		EE_Registry::instance()->REQ->set('step', 'attendee_information'); | |
| 358 | +		EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); | |
| 359 | +		EE_Registry::instance()->REQ->set('process_form_submission', false); | |
| 360 | + EED_Single_Page_Checkout::instance()->_initialize(); | |
| 361 | + EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); | |
| 362 | + return EE_Registry::instance()->REQ->get_output(); | |
| 363 | + } | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + /** | |
| 368 | + * process_registration_from_admin | |
| 369 | + * | |
| 370 | + * @access public | |
| 371 | + * @return \EE_Transaction | |
| 372 | + * @throws EE_Error | |
| 373 | + */ | |
| 374 | + public static function process_registration_from_admin() | |
| 375 | +	{ | |
| 376 | + EED_Single_Page_Checkout::load_request_handler(); | |
| 377 | +		EE_Registry::instance()->REQ->set('step', 'attendee_information'); | |
| 378 | +		EE_Registry::instance()->REQ->set('action', 'process_reg_step'); | |
| 379 | +		EE_Registry::instance()->REQ->set('process_form_submission', true); | |
| 380 | + EED_Single_Page_Checkout::instance()->_initialize(); | |
| 381 | +		if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { | |
| 382 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); | |
| 383 | +			if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { | |
| 384 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); | |
| 385 | +				if ($final_reg_step->process_reg_step()) { | |
| 386 | + $final_reg_step->set_completed(); | |
| 387 | + EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); | |
| 388 | + return EED_Single_Page_Checkout::instance()->checkout->transaction; | |
| 389 | + } | |
| 390 | + } | |
| 391 | + } | |
| 392 | + return null; | |
| 393 | + } | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + /** | |
| 398 | + * run | |
| 399 | + * | |
| 400 | + * @access public | |
| 401 | + * @param WP_Query $WP_Query | |
| 402 | + * @return void | |
| 403 | + * @throws EE_Error | |
| 404 | + */ | |
| 405 | + public function run($WP_Query) | |
| 406 | +	{ | |
| 407 | + if ( | |
| 408 | + $WP_Query instanceof WP_Query | |
| 409 | + && $WP_Query->is_main_query() | |
| 410 | +			&& apply_filters('FHEE__EED_Single_Page_Checkout__run', true) | |
| 411 | + && $this->_is_reg_checkout() | |
| 412 | +		) { | |
| 413 | + $this->_initialize(); | |
| 414 | + } | |
| 415 | + } | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + /** | |
| 420 | + * determines whether current url matches reg page url | |
| 421 | + * | |
| 422 | + * @return bool | |
| 423 | + */ | |
| 424 | + protected function _is_reg_checkout() | |
| 425 | +	{ | |
| 426 | + // get current permalink for reg page without any extra query args | |
| 427 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); | |
| 428 | + // get request URI for current request, but without the scheme or host | |
| 429 | +		$current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); | |
| 430 | + $current_request_uri = html_entity_decode($current_request_uri); | |
| 431 | + // get array of query args from the current request URI | |
| 432 | + $query_args = \EEH_URL::get_query_string($current_request_uri); | |
| 433 | + // grab page id if it is set | |
| 434 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; | |
| 435 | + // and remove the page id from the query args (we will re-add it later) | |
| 436 | + unset($query_args['page_id']); | |
| 437 | + // now strip all query args from current request URI | |
| 438 | + $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); | |
| 439 | + // and re-add the page id if it was set | |
| 440 | +		if ($page_id) { | |
| 441 | +			$current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); | |
| 442 | + } | |
| 443 | + // remove slashes and ? | |
| 444 | + $current_request_uri = trim($current_request_uri, '?/'); | |
| 445 | + // is current request URI part of the known full reg page URL ? | |
| 446 | + return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; | |
| 447 | + } | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + /** | |
| 452 | + * @param WP_Query $wp_query | |
| 453 | + * @return void | |
| 454 | + * @throws EE_Error | |
| 455 | + */ | |
| 456 | + public static function init($wp_query) | |
| 457 | +	{ | |
| 458 | + EED_Single_Page_Checkout::instance()->run($wp_query); | |
| 459 | + } | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + /** | |
| 464 | + * _initialize - initial module setup | |
| 465 | + * | |
| 466 | + * @access private | |
| 467 | + * @throws EE_Error | |
| 468 | + * @return void | |
| 469 | + */ | |
| 470 | + private function _initialize() | |
| 471 | +	{ | |
| 472 | + // ensure SPCO doesn't run twice | |
| 473 | +		if (EED_Single_Page_Checkout::$_initialized) { | |
| 474 | + return; | |
| 475 | + } | |
| 476 | +		try { | |
| 477 | + EED_Single_Page_Checkout::load_reg_steps(); | |
| 478 | + $this->_verify_session(); | |
| 479 | + // setup the EE_Checkout object | |
| 480 | + $this->checkout = $this->_initialize_checkout(); | |
| 481 | + // filter checkout | |
| 482 | +			$this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); | |
| 483 | + // get the $_GET | |
| 484 | + $this->_get_request_vars(); | |
| 485 | +			if ($this->_block_bots()) { | |
| 486 | + return; | |
| 487 | + } | |
| 488 | + // filter continue_reg | |
| 489 | + $this->checkout->continue_reg = apply_filters( | |
| 490 | + 'FHEE__EED_Single_Page_Checkout__init___continue_reg', | |
| 491 | + true, | |
| 492 | + $this->checkout | |
| 493 | + ); | |
| 494 | + // load the reg steps array | |
| 495 | +			if ( ! $this->_load_and_instantiate_reg_steps()) { | |
| 496 | + EED_Single_Page_Checkout::$_initialized = true; | |
| 497 | + return; | |
| 498 | + } | |
| 499 | + // set the current step | |
| 500 | + $this->checkout->set_current_step($this->checkout->step); | |
| 501 | + // and the next step | |
| 502 | + $this->checkout->set_next_step(); | |
| 503 | + // verify that everything has been setup correctly | |
| 504 | +			if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { | |
| 505 | + EED_Single_Page_Checkout::$_initialized = true; | |
| 506 | + return; | |
| 507 | + } | |
| 508 | + // lock the transaction | |
| 509 | + $this->checkout->transaction->lock(); | |
| 510 | + // make sure all of our cached objects are added to their respective model entity mappers | |
| 511 | + $this->checkout->refresh_all_entities(); | |
| 512 | + // set amount owing | |
| 513 | + $this->checkout->amount_owing = $this->checkout->transaction->remaining(); | |
| 514 | + // initialize each reg step, which gives them the chance to potentially alter the process | |
| 515 | + $this->_initialize_reg_steps(); | |
| 516 | + // DEBUG LOG | |
| 517 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); | |
| 518 | + // get reg form | |
| 519 | +			if( ! $this->_check_form_submission()) { | |
| 520 | + EED_Single_Page_Checkout::$_initialized = true; | |
| 521 | + return; | |
| 522 | + } | |
| 523 | + // checkout the action!!! | |
| 524 | + $this->_process_form_action(); | |
| 525 | + // add some style and make it dance | |
| 526 | + $this->add_styles_and_scripts(); | |
| 527 | + // kk... SPCO has successfully run | |
| 528 | + EED_Single_Page_Checkout::$_initialized = true; | |
| 529 | + // set no cache headers and constants | |
| 530 | + EE_System::do_not_cache(); | |
| 531 | + // add anchor | |
| 532 | +			add_action('loop_start', array($this, 'set_checkout_anchor'), 1); | |
| 533 | + // remove transaction lock | |
| 534 | +			add_action('shutdown', array($this, 'unlock_transaction'), 1); | |
| 535 | +		} catch (Exception $e) { | |
| 536 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); | |
| 537 | + } | |
| 538 | + } | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + /** | |
| 543 | + * _verify_session | |
| 544 | + * checks that the session is valid and not expired | |
| 545 | + * | |
| 546 | + * @access private | |
| 547 | + * @throws EE_Error | |
| 548 | + */ | |
| 549 | + private function _verify_session() | |
| 550 | +	{ | |
| 551 | +		if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { | |
| 552 | +			throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); | |
| 553 | + } | |
| 554 | + $clear_session_requested = filter_var( | |
| 555 | +			EE_Registry::instance()->REQ->get('clear_session', false), | |
| 556 | + FILTER_VALIDATE_BOOLEAN | |
| 557 | + ); | |
| 558 | + // is session still valid ? | |
| 559 | + if ($clear_session_requested | |
| 560 | + || ( EE_Registry::instance()->SSN->expired() | |
| 561 | +			  && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' | |
| 562 | + ) | |
| 563 | +		) { | |
| 564 | + $this->checkout = new EE_Checkout(); | |
| 565 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); | |
| 566 | + // EE_Registry::instance()->SSN->reset_cart(); | |
| 567 | + // EE_Registry::instance()->SSN->reset_checkout(); | |
| 568 | + // EE_Registry::instance()->SSN->reset_transaction(); | |
| 569 | +			if (! $clear_session_requested) { | |
| 570 | + EE_Error::add_attention( | |
| 571 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'], | |
| 572 | + __FILE__, __FUNCTION__, __LINE__ | |
| 573 | + ); | |
| 574 | + } | |
| 575 | + // EE_Registry::instance()->SSN->reset_expired(); | |
| 576 | + } | |
| 577 | + } | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + /** | |
| 582 | + * _initialize_checkout | |
| 583 | + * loads and instantiates EE_Checkout | |
| 584 | + * | |
| 585 | + * @access private | |
| 586 | + * @throws EE_Error | |
| 587 | + * @return EE_Checkout | |
| 588 | + */ | |
| 589 | + private function _initialize_checkout() | |
| 590 | +	{ | |
| 591 | + // look in session for existing checkout | |
| 592 | + /** @type EE_Checkout $checkout */ | |
| 593 | + $checkout = EE_Registry::instance()->SSN->checkout(); | |
| 594 | + // verify | |
| 595 | +		if ( ! $checkout instanceof EE_Checkout) { | |
| 596 | + // instantiate EE_Checkout object for handling the properties of the current checkout process | |
| 597 | + $checkout = EE_Registry::instance()->load_file( | |
| 598 | + SPCO_INC_PATH, | |
| 599 | + 'EE_Checkout', | |
| 600 | + 'class', array(), | |
| 601 | + false | |
| 602 | + ); | |
| 603 | +		} else { | |
| 604 | +			if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { | |
| 605 | + $this->unlock_transaction(); | |
| 606 | + wp_safe_redirect($checkout->redirect_url); | |
| 607 | + exit(); | |
| 608 | + } | |
| 609 | + } | |
| 610 | +		$checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); | |
| 611 | + // verify again | |
| 612 | +		if ( ! $checkout instanceof EE_Checkout) { | |
| 613 | +			throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); | |
| 614 | + } | |
| 615 | + // reset anything that needs a clean slate for each request | |
| 616 | + $checkout->reset_for_current_request(); | |
| 617 | + return $checkout; | |
| 618 | + } | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + /** | |
| 623 | + * _get_request_vars | |
| 624 | + * | |
| 625 | + * @access private | |
| 626 | + * @return void | |
| 627 | + * @throws EE_Error | |
| 628 | + */ | |
| 629 | + private function _get_request_vars() | |
| 630 | +	{ | |
| 631 | + // load classes | |
| 632 | + EED_Single_Page_Checkout::load_request_handler(); | |
| 633 | + //make sure this request is marked as belonging to EE | |
| 634 | + EE_Registry::instance()->REQ->set_espresso_page(true); | |
| 635 | + // which step is being requested ? | |
| 636 | +		$this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); | |
| 637 | + // which step is being edited ? | |
| 638 | +		$this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); | |
| 639 | + // and what we're doing on the current step | |
| 640 | +		$this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); | |
| 641 | + // timestamp | |
| 642 | +		$this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); | |
| 643 | + // returning to edit ? | |
| 644 | +		$this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); | |
| 645 | + // or some other kind of revisit ? | |
| 646 | + $this->checkout->revisit = filter_var( | |
| 647 | +			EE_Registry::instance()->REQ->get('revisit', false), | |
| 648 | + FILTER_VALIDATE_BOOLEAN | |
| 649 | + ); | |
| 650 | + // and whether or not to generate a reg form for this request | |
| 651 | + $this->checkout->generate_reg_form = filter_var( | |
| 652 | +			EE_Registry::instance()->REQ->get('generate_reg_form', true), | |
| 653 | + FILTER_VALIDATE_BOOLEAN | |
| 654 | + ); | |
| 655 | + // and whether or not to process a reg form submission for this request | |
| 656 | + $this->checkout->process_form_submission = filter_var( | |
| 657 | + EE_Registry::instance()->REQ->get( | |
| 658 | + 'process_form_submission', | |
| 659 | + $this->checkout->action === 'process_reg_step' | |
| 660 | + ), | |
| 661 | + FILTER_VALIDATE_BOOLEAN | |
| 662 | + ); | |
| 663 | + $this->checkout->process_form_submission = filter_var( | |
| 664 | + $this->checkout->action !== 'display_spco_reg_step' | |
| 665 | + ? $this->checkout->process_form_submission | |
| 666 | + : false, | |
| 667 | + FILTER_VALIDATE_BOOLEAN | |
| 668 | + ); | |
| 669 | + // $this->_display_request_vars(); | |
| 670 | + } | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + /** | |
| 675 | + * _display_request_vars | |
| 676 | + * | |
| 677 | + * @access protected | |
| 678 | + * @return void | |
| 679 | + */ | |
| 680 | + protected function _display_request_vars() | |
| 681 | +	{ | |
| 682 | +		if ( ! WP_DEBUG) { | |
| 683 | + return; | |
| 684 | + } | |
| 685 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); | |
| 686 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); | |
| 687 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); | |
| 688 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); | |
| 689 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); | |
| 690 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); | |
| 691 | + EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); | |
| 692 | + EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); | |
| 693 | + } | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + /** | |
| 698 | + * _block_bots | |
| 699 | + * checks that the incoming request has either of the following set: | |
| 700 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector | |
| 701 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN | |
| 702 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... | |
| 703 | + * then where you coming from man? | |
| 704 | + * | |
| 705 | + * @return boolean | |
| 706 | + */ | |
| 707 | + private function _block_bots() | |
| 708 | +	{ | |
| 709 | + $invalid_checkout_access = EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); | |
| 710 | +		if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { | |
| 711 | + return true; | |
| 712 | + } | |
| 713 | + return false; | |
| 714 | + } | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + /** | |
| 719 | + * _get_first_step | |
| 720 | + * gets slug for first step in $_reg_steps_array | |
| 721 | + * | |
| 722 | + * @access private | |
| 723 | + * @throws EE_Error | |
| 724 | + * @return string | |
| 725 | + */ | |
| 726 | + private function _get_first_step() | |
| 727 | +	{ | |
| 728 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); | |
| 729 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; | |
| 730 | + } | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + /** | |
| 735 | + * _load_and_instantiate_reg_steps | |
| 736 | + * instantiates each reg step based on the loaded reg_steps array | |
| 737 | + * | |
| 738 | + * @access private | |
| 739 | + * @throws EE_Error | |
| 740 | + * @return bool | |
| 741 | + */ | |
| 742 | + private function _load_and_instantiate_reg_steps() | |
| 743 | +	{ | |
| 744 | +		do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); | |
| 745 | + // have reg_steps already been instantiated ? | |
| 746 | + if ( | |
| 747 | + empty($this->checkout->reg_steps) | |
| 748 | +			|| apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) | |
| 749 | +		) { | |
| 750 | + // if not, then loop through raw reg steps array | |
| 751 | +			foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { | |
| 752 | +				if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { | |
| 753 | + return false; | |
| 754 | + } | |
| 755 | + } | |
| 756 | + EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; | |
| 757 | + EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; | |
| 758 | + // skip the registration_confirmation page ? | |
| 759 | +			if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { | |
| 760 | + // just remove it from the reg steps array | |
| 761 | +				$this->checkout->remove_reg_step('registration_confirmation', false); | |
| 762 | + } else if ( | |
| 763 | + isset($this->checkout->reg_steps['registration_confirmation']) | |
| 764 | + && EE_Registry::instance()->CFG->registration->reg_confirmation_last | |
| 765 | +			) { | |
| 766 | + // set the order to something big like 100 | |
| 767 | +				$this->checkout->set_reg_step_order('registration_confirmation', 100); | |
| 768 | + } | |
| 769 | + // filter the array for good luck | |
| 770 | + $this->checkout->reg_steps = apply_filters( | |
| 771 | + 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', | |
| 772 | + $this->checkout->reg_steps | |
| 773 | + ); | |
| 774 | + // finally re-sort based on the reg step class order properties | |
| 775 | + $this->checkout->sort_reg_steps(); | |
| 776 | +		} else { | |
| 777 | +			foreach ($this->checkout->reg_steps as $reg_step) { | |
| 778 | + // set all current step stati to FALSE | |
| 779 | + $reg_step->set_is_current_step(false); | |
| 780 | + } | |
| 781 | + } | |
| 782 | +		if (empty($this->checkout->reg_steps)) { | |
| 783 | + EE_Error::add_error( | |
| 784 | +				__('No Reg Steps were loaded..', 'event_espresso'), | |
| 785 | + __FILE__, __FUNCTION__, __LINE__ | |
| 786 | + ); | |
| 787 | + return false; | |
| 788 | + } | |
| 789 | + // make reg step details available to JS | |
| 790 | + $this->checkout->set_reg_step_JSON_info(); | |
| 791 | + return true; | |
| 792 | + } | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + /** | |
| 797 | + * _load_and_instantiate_reg_step | |
| 798 | + * | |
| 799 | + * @access private | |
| 800 | + * @param array $reg_step | |
| 801 | + * @param int $order | |
| 802 | + * @return bool | |
| 803 | + */ | |
| 804 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) | |
| 805 | +	{ | |
| 806 | + // we need a file_path, class_name, and slug to add a reg step | |
| 807 | +		if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { | |
| 808 | + // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) | |
| 809 | + if ( | |
| 810 | + $this->checkout->reg_url_link | |
| 811 | + && $this->checkout->step !== $reg_step['slug'] | |
| 812 | + && $reg_step['slug'] !== 'finalize_registration' | |
| 813 | + // normally at this point we would NOT load the reg step, but this filter can change that | |
| 814 | + && apply_filters( | |
| 815 | + 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', | |
| 816 | + true, | |
| 817 | + $reg_step, | |
| 818 | + $this->checkout | |
| 819 | + ) | |
| 820 | +			) { | |
| 821 | + return true; | |
| 822 | + } | |
| 823 | + // instantiate step class using file path and class name | |
| 824 | + $reg_step_obj = EE_Registry::instance()->load_file( | |
| 825 | + $reg_step['file_path'], | |
| 826 | + $reg_step['class_name'], | |
| 827 | + 'class', | |
| 828 | + $this->checkout, | |
| 829 | + false | |
| 830 | + ); | |
| 831 | + // did we gets the goods ? | |
| 832 | +			if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { | |
| 833 | + // set reg step order based on config | |
| 834 | + $reg_step_obj->set_order($order); | |
| 835 | + // add instantiated reg step object to the master reg steps array | |
| 836 | + $this->checkout->add_reg_step($reg_step_obj); | |
| 837 | +			} else { | |
| 838 | + EE_Error::add_error( | |
| 839 | +					__('The current step could not be set.', 'event_espresso'), | |
| 840 | + __FILE__, __FUNCTION__, __LINE__ | |
| 841 | + ); | |
| 842 | + return false; | |
| 843 | + } | |
| 844 | +		} else { | |
| 845 | +			if (WP_DEBUG) { | |
| 846 | + EE_Error::add_error( | |
| 847 | + sprintf( | |
| 848 | + __( | |
| 849 | + 'A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', | |
| 850 | + 'event_espresso' | |
| 851 | + ), | |
| 852 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', | |
| 853 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', | |
| 854 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', | |
| 855 | + '<ul>', | |
| 856 | + '<li>', | |
| 857 | + '</li>', | |
| 858 | + '</ul>' | |
| 859 | + ), | |
| 860 | + __FILE__, __FUNCTION__, __LINE__ | |
| 861 | + ); | |
| 862 | + } | |
| 863 | + return false; | |
| 864 | + } | |
| 865 | + return true; | |
| 866 | + } | |
| 867 | + | |
| 868 | + | |
| 869 | + /** | |
| 870 | + * _verify_transaction_and_get_registrations | |
| 871 | + * | |
| 872 | + * @access private | |
| 873 | + * @return bool | |
| 874 | + * @throws InvalidDataTypeException | |
| 875 | + * @throws InvalidEntityException | |
| 876 | + * @throws EE_Error | |
| 877 | + */ | |
| 878 | + private function _verify_transaction_and_get_registrations() | |
| 879 | +	{ | |
| 880 | + // was there already a valid transaction in the checkout from the session ? | |
| 881 | +		if ( ! $this->checkout->transaction instanceof EE_Transaction) { | |
| 882 | + // get transaction from db or session | |
| 883 | + $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() | |
| 884 | + ? $this->_get_transaction_and_cart_for_previous_visit() | |
| 885 | + : $this->_get_cart_for_current_session_and_setup_new_transaction(); | |
| 886 | +			if ( ! $this->checkout->transaction instanceof EE_Transaction) { | |
| 887 | + EE_Error::add_error( | |
| 888 | +					__('Your Registration and Transaction information could not be retrieved from the db.', | |
| 889 | + 'event_espresso'), | |
| 890 | + __FILE__, __FUNCTION__, __LINE__ | |
| 891 | + ); | |
| 892 | + $this->checkout->transaction = EE_Transaction::new_instance(); | |
| 893 | + // add some style and make it dance | |
| 894 | + $this->add_styles_and_scripts(); | |
| 895 | + EED_Single_Page_Checkout::$_initialized = true; | |
| 896 | + return false; | |
| 897 | + } | |
| 898 | + // and the registrations for the transaction | |
| 899 | + $this->_get_registrations($this->checkout->transaction); | |
| 900 | + } | |
| 901 | + return true; | |
| 902 | + } | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + /** | |
| 907 | + * _get_transaction_and_cart_for_previous_visit | |
| 908 | + * | |
| 909 | + * @access private | |
| 910 | + * @return mixed EE_Transaction|NULL | |
| 911 | + */ | |
| 912 | + private function _get_transaction_and_cart_for_previous_visit() | |
| 913 | +	{ | |
| 914 | + /** @var $TXN_model EEM_Transaction */ | |
| 915 | +		$TXN_model = EE_Registry::instance()->load_model('Transaction'); | |
| 916 | + // because the reg_url_link is present in the request, | |
| 917 | + // this is a return visit to SPCO, so we'll get the transaction data from the db | |
| 918 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); | |
| 919 | + // verify transaction | |
| 920 | +		if ($transaction instanceof EE_Transaction) { | |
| 921 | + // and get the cart that was used for that transaction | |
| 922 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); | |
| 923 | + return $transaction; | |
| 924 | + } | |
| 925 | + EE_Error::add_error( | |
| 926 | +			__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), | |
| 927 | + __FILE__, __FUNCTION__, __LINE__ | |
| 928 | + ); | |
| 929 | + return null; | |
| 930 | + | |
| 931 | + } | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + /** | |
| 936 | + * _get_cart_for_transaction | |
| 937 | + * | |
| 938 | + * @access private | |
| 939 | + * @param EE_Transaction $transaction | |
| 940 | + * @return EE_Cart | |
| 941 | + */ | |
| 942 | + private function _get_cart_for_transaction($transaction) | |
| 943 | +	{ | |
| 944 | + return $this->checkout->get_cart_for_transaction($transaction); | |
| 945 | + } | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + /** | |
| 950 | + * get_cart_for_transaction | |
| 951 | + * | |
| 952 | + * @access public | |
| 953 | + * @param EE_Transaction $transaction | |
| 954 | + * @return EE_Cart | |
| 955 | + */ | |
| 956 | + public function get_cart_for_transaction(EE_Transaction $transaction) | |
| 957 | +	{ | |
| 958 | + return $this->checkout->get_cart_for_transaction($transaction); | |
| 959 | + } | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + /** | |
| 964 | + * _get_transaction_and_cart_for_current_session | |
| 965 | + * generates a new EE_Transaction object and adds it to the $_transaction property. | |
| 966 | + * | |
| 967 | + * @access private | |
| 968 | + * @return EE_Transaction | |
| 969 | + * @throws EE_Error | |
| 970 | + */ | |
| 971 | + private function _get_cart_for_current_session_and_setup_new_transaction() | |
| 972 | +	{ | |
| 973 | + // if there's no transaction, then this is the FIRST visit to SPCO | |
| 974 | + // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) | |
| 975 | + $this->checkout->cart = $this->_get_cart_for_transaction(null); | |
| 976 | + // and then create a new transaction | |
| 977 | + $transaction = $this->_initialize_transaction(); | |
| 978 | + // verify transaction | |
| 979 | +		if ($transaction instanceof EE_Transaction) { | |
| 980 | + // save it so that we have an ID for other objects to use | |
| 981 | + $transaction->save(); | |
| 982 | + // and save TXN data to the cart | |
| 983 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); | |
| 984 | +		} else { | |
| 985 | + EE_Error::add_error( | |
| 986 | +				__('A Valid Transaction could not be initialized.', 'event_espresso'), | |
| 987 | + __FILE__, __FUNCTION__, __LINE__ | |
| 988 | + ); | |
| 989 | + } | |
| 990 | + return $transaction; | |
| 991 | + } | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + /** | |
| 996 | + * generates a new EE_Transaction object and adds it to the $_transaction property. | |
| 997 | + * | |
| 998 | + * @access private | |
| 999 | + * @return mixed EE_Transaction|NULL | |
| 1000 | + */ | |
| 1001 | + private function _initialize_transaction() | |
| 1002 | +	{ | |
| 1003 | +		try { | |
| 1004 | + // ensure cart totals have been calculated | |
| 1005 | + $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); | |
| 1006 | + // grab the cart grand total | |
| 1007 | + $cart_total = $this->checkout->cart->get_cart_grand_total(); | |
| 1008 | + // create new TXN | |
| 1009 | + $transaction = EE_Transaction::new_instance( | |
| 1010 | + array( | |
| 1011 | + 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), | |
| 1012 | + 'TXN_total' => $cart_total > 0 ? $cart_total : 0, | |
| 1013 | + 'TXN_paid' => 0, | |
| 1014 | + 'STS_ID' => EEM_Transaction::failed_status_code, | |
| 1015 | + ) | |
| 1016 | + ); | |
| 1017 | + // save it so that we have an ID for other objects to use | |
| 1018 | + $transaction->save(); | |
| 1019 | + // set cron job for following up on TXNs after their session has expired | |
| 1020 | + EE_Cron_Tasks::schedule_expired_transaction_check( | |
| 1021 | + EE_Registry::instance()->SSN->expiration() + 1, | |
| 1022 | + $transaction->ID() | |
| 1023 | + ); | |
| 1024 | + return $transaction; | |
| 1025 | +		} catch (Exception $e) { | |
| 1026 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); | |
| 1027 | + } | |
| 1028 | + return null; | |
| 1029 | + } | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + /** | |
| 1033 | + * _get_registrations | |
| 1034 | + * | |
| 1035 | + * @access private | |
| 1036 | + * @param EE_Transaction $transaction | |
| 1037 | + * @return void | |
| 1038 | + * @throws InvalidDataTypeException | |
| 1039 | + * @throws InvalidEntityException | |
| 1040 | + * @throws EE_Error | |
| 1041 | + */ | |
| 1042 | + private function _get_registrations(EE_Transaction $transaction) | |
| 1043 | +	{ | |
| 1044 | +		// first step: grab the registrants  { : o | |
| 1045 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); | |
| 1046 | + // verify registrations have been set | |
| 1047 | +		if (empty($registrations)) { | |
| 1048 | + // if no cached registrations, then check the db | |
| 1049 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); | |
| 1050 | + // still nothing ? well as long as this isn't a revisit | |
| 1051 | +			if (empty($registrations) && ! $this->checkout->revisit) { | |
| 1052 | + // generate new registrations from scratch | |
| 1053 | + $registrations = $this->_initialize_registrations($transaction); | |
| 1054 | + } | |
| 1055 | + } | |
| 1056 | + // sort by their original registration order | |
| 1057 | +		usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); | |
| 1058 | + // then loop thru the array | |
| 1059 | +		foreach ($registrations as $registration) { | |
| 1060 | + // verify each registration | |
| 1061 | +			if ($registration instanceof EE_Registration) { | |
| 1062 | + // we display all attendee info for the primary registrant | |
| 1063 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() | |
| 1064 | + && $registration->is_primary_registrant() | |
| 1065 | +				) { | |
| 1066 | + $this->checkout->primary_revisit = true; | |
| 1067 | + break; | |
| 1068 | + } | |
| 1069 | + if ($this->checkout->revisit | |
| 1070 | + && $this->checkout->reg_url_link !== $registration->reg_url_link() | |
| 1071 | +				) { | |
| 1072 | + // but hide info if it doesn't belong to you | |
| 1073 | +					$transaction->clear_cache('Registration', $registration->ID()); | |
| 1074 | + } | |
| 1075 | + $this->checkout->set_reg_status_updated($registration->ID(), false); | |
| 1076 | + } | |
| 1077 | + } | |
| 1078 | + } | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + /** | |
| 1082 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object | |
| 1083 | + * | |
| 1084 | + * @access private | |
| 1085 | + * @param EE_Transaction $transaction | |
| 1086 | + * @return array | |
| 1087 | + * @throws InvalidDataTypeException | |
| 1088 | + * @throws InvalidEntityException | |
| 1089 | + * @throws EE_Error | |
| 1090 | + */ | |
| 1091 | + private function _initialize_registrations(EE_Transaction $transaction) | |
| 1092 | +	{ | |
| 1093 | + $att_nmbr = 0; | |
| 1094 | + $registrations = array(); | |
| 1095 | +		if ($transaction instanceof EE_Transaction) { | |
| 1096 | + /** @type EE_Registration_Processor $registration_processor */ | |
| 1097 | +			$registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); | |
| 1098 | + $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); | |
| 1099 | + // now let's add the cart items to the $transaction | |
| 1100 | +			foreach ($this->checkout->cart->get_tickets() as $line_item) { | |
| 1101 | + //do the following for each ticket of this type they selected | |
| 1102 | +				for ($x = 1; $x <= $line_item->quantity(); $x++) { | |
| 1103 | + $att_nmbr++; | |
| 1104 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ | |
| 1105 | + $CreateRegistrationCommand = EE_Registry::instance()->create( | |
| 1106 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', | |
| 1107 | + array( | |
| 1108 | + $transaction, | |
| 1109 | + $line_item, | |
| 1110 | + $att_nmbr, | |
| 1111 | + $this->checkout->total_ticket_count, | |
| 1112 | + ) | |
| 1113 | + ); | |
| 1114 | + // override capabilities for frontend registrations | |
| 1115 | +					if ( ! is_admin()) { | |
| 1116 | + $CreateRegistrationCommand->setCapCheck( | |
| 1117 | +							new PublicCapabilities('', 'create_new_registration') | |
| 1118 | + ); | |
| 1119 | + } | |
| 1120 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); | |
| 1121 | +					if ( ! $registration instanceof EE_Registration) { | |
| 1122 | + throw new InvalidEntityException($registration, 'EE_Registration'); | |
| 1123 | + } | |
| 1124 | + $registrations[ $registration->ID() ] = $registration; | |
| 1125 | + } | |
| 1126 | + } | |
| 1127 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); | |
| 1128 | + } | |
| 1129 | + return $registrations; | |
| 1130 | + } | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + /** | |
| 1135 | + * sorts registrations by REG_count | |
| 1136 | + * | |
| 1137 | + * @access public | |
| 1138 | + * @param EE_Registration $reg_A | |
| 1139 | + * @param EE_Registration $reg_B | |
| 1140 | + * @return int | |
| 1141 | + */ | |
| 1142 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) | |
| 1143 | +	{ | |
| 1144 | + // this shouldn't ever happen within the same TXN, but oh well | |
| 1145 | +		if ($reg_A->count() === $reg_B->count()) { | |
| 1146 | + return 0; | |
| 1147 | + } | |
| 1148 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; | |
| 1149 | + } | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + /** | |
| 1154 | + * _final_verifications | |
| 1155 | + * just makes sure that everything is set up correctly before proceeding | |
| 1156 | + * | |
| 1157 | + * @access private | |
| 1158 | + * @return bool | |
| 1159 | + * @throws EE_Error | |
| 1160 | + */ | |
| 1161 | + private function _final_verifications() | |
| 1162 | +	{ | |
| 1163 | + // filter checkout | |
| 1164 | + $this->checkout = apply_filters( | |
| 1165 | + 'FHEE__EED_Single_Page_Checkout___final_verifications__checkout', | |
| 1166 | + $this->checkout | |
| 1167 | + ); | |
| 1168 | + //verify that current step is still set correctly | |
| 1169 | +		if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { | |
| 1170 | + EE_Error::add_error( | |
| 1171 | +				__('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), | |
| 1172 | + __FILE__, | |
| 1173 | + __FUNCTION__, | |
| 1174 | + __LINE__ | |
| 1175 | + ); | |
| 1176 | + return false; | |
| 1177 | + } | |
| 1178 | + // if returning to SPCO, then verify that primary registrant is set | |
| 1179 | +		if ( ! empty($this->checkout->reg_url_link)) { | |
| 1180 | + $valid_registrant = $this->checkout->transaction->primary_registration(); | |
| 1181 | +			if ( ! $valid_registrant instanceof EE_Registration) { | |
| 1182 | + EE_Error::add_error( | |
| 1183 | +					__('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), | |
| 1184 | + __FILE__, | |
| 1185 | + __FUNCTION__, | |
| 1186 | + __LINE__ | |
| 1187 | + ); | |
| 1188 | + return false; | |
| 1189 | + } | |
| 1190 | + $valid_registrant = null; | |
| 1191 | + foreach ( | |
| 1192 | + $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration | |
| 1193 | +			) { | |
| 1194 | + if ( | |
| 1195 | + $registration instanceof EE_Registration | |
| 1196 | + && $registration->reg_url_link() === $this->checkout->reg_url_link | |
| 1197 | +				) { | |
| 1198 | + $valid_registrant = $registration; | |
| 1199 | + } | |
| 1200 | + } | |
| 1201 | +			if ( ! $valid_registrant instanceof EE_Registration) { | |
| 1202 | + // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? | |
| 1203 | +				if (EED_Single_Page_Checkout::$_checkout_verified) { | |
| 1204 | + // clear the session, mark the checkout as unverified, and try again | |
| 1205 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); | |
| 1206 | + EED_Single_Page_Checkout::$_initialized = false; | |
| 1207 | + EED_Single_Page_Checkout::$_checkout_verified = false; | |
| 1208 | + $this->_initialize(); | |
| 1209 | + EE_Error::reset_notices(); | |
| 1210 | + return false; | |
| 1211 | + } | |
| 1212 | + EE_Error::add_error( | |
| 1213 | + __( | |
| 1214 | + 'We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', | |
| 1215 | + 'event_espresso' | |
| 1216 | + ), | |
| 1217 | + __FILE__, | |
| 1218 | + __FUNCTION__, | |
| 1219 | + __LINE__ | |
| 1220 | + ); | |
| 1221 | + return false; | |
| 1222 | + } | |
| 1223 | + } | |
| 1224 | + // now that things have been kinda sufficiently verified, | |
| 1225 | + // let's add the checkout to the session so that it's available to other systems | |
| 1226 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); | |
| 1227 | + return true; | |
| 1228 | + } | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + /** | |
| 1233 | + * _initialize_reg_steps | |
| 1234 | + * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required | |
| 1235 | + * then loops thru all of the active reg steps and calls the initialize_reg_step() method | |
| 1236 | + * | |
| 1237 | + * @access private | |
| 1238 | + * @param bool $reinitializing | |
| 1239 | + * @throws EE_Error | |
| 1240 | + */ | |
| 1241 | + private function _initialize_reg_steps($reinitializing = false) | |
| 1242 | +	{ | |
| 1243 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); | |
| 1244 | + // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS | |
| 1245 | +		foreach ($this->checkout->reg_steps as $reg_step) { | |
| 1246 | +			if ( ! $reg_step->initialize_reg_step()) { | |
| 1247 | + // if not initialized then maybe this step is being removed... | |
| 1248 | +				if ( ! $reinitializing && $reg_step->is_current_step()) { | |
| 1249 | + // if it was the current step, then we need to start over here | |
| 1250 | + $this->_initialize_reg_steps(true); | |
| 1251 | + return; | |
| 1252 | + } | |
| 1253 | + continue; | |
| 1254 | + } | |
| 1255 | + // add css and JS for current step | |
| 1256 | + $reg_step->enqueue_styles_and_scripts(); | |
| 1257 | + // i18n | |
| 1258 | + $reg_step->translate_js_strings(); | |
| 1259 | +			if ($reg_step->is_current_step()) { | |
| 1260 | + // the text that appears on the reg step form submit button | |
| 1261 | + $reg_step->set_submit_button_text(); | |
| 1262 | + } | |
| 1263 | + } | |
| 1264 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information | |
| 1265 | + do_action( | |
| 1266 | +			"AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", | |
| 1267 | + $this->checkout->current_step | |
| 1268 | + ); | |
| 1269 | + } | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + /** | |
| 1274 | + * _check_form_submission | |
| 1275 | + * | |
| 1276 | + * @access private | |
| 1277 | + * @return boolean | |
| 1278 | + */ | |
| 1279 | + private function _check_form_submission() | |
| 1280 | +	{ | |
| 1281 | + //does this request require the reg form to be generated ? | |
| 1282 | +		if ($this->checkout->generate_reg_form) { | |
| 1283 | + // ever heard that song by Blue Rodeo ? | |
| 1284 | +			try { | |
| 1285 | + $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); | |
| 1286 | + // if not displaying a form, then check for form submission | |
| 1287 | + if ( | |
| 1288 | + $this->checkout->process_form_submission | |
| 1289 | + && $this->checkout->current_step->reg_form->was_submitted() | |
| 1290 | +				) { | |
| 1291 | + // clear out any old data in case this step is being run again | |
| 1292 | + $this->checkout->current_step->set_valid_data(array()); | |
| 1293 | + // capture submitted form data | |
| 1294 | + $this->checkout->current_step->reg_form->receive_form_submission( | |
| 1295 | + apply_filters( | |
| 1296 | + 'FHEE__Single_Page_Checkout___check_form_submission__request_params', | |
| 1297 | + EE_Registry::instance()->REQ->params(), | |
| 1298 | + $this->checkout | |
| 1299 | + ) | |
| 1300 | + ); | |
| 1301 | + // validate submitted form data | |
| 1302 | +					if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { | |
| 1303 | + // thou shall not pass !!! | |
| 1304 | + $this->checkout->continue_reg = false; | |
| 1305 | + // any form validation errors? | |
| 1306 | +						if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { | |
| 1307 | + $submission_error_messages = array(); | |
| 1308 | + // bad, bad, bad registrant | |
| 1309 | + foreach ( | |
| 1310 | + $this->checkout->current_step->reg_form->get_validation_errors_accumulated() | |
| 1311 | + as $validation_error | |
| 1312 | +							) { | |
| 1313 | +								if ($validation_error instanceof EE_Validation_Error) { | |
| 1314 | + $submission_error_messages[] = sprintf( | |
| 1315 | +										__('%s : %s', 'event_espresso'), | |
| 1316 | + $validation_error->get_form_section()->html_label_text(), | |
| 1317 | + $validation_error->getMessage() | |
| 1318 | + ); | |
| 1319 | + } | |
| 1320 | + } | |
| 1321 | + EE_Error::add_error( | |
| 1322 | +								implode('<br />', $submission_error_messages), | |
| 1323 | + __FILE__, __FUNCTION__, __LINE__ | |
| 1324 | + ); | |
| 1325 | + } | |
| 1326 | + // well not really... what will happen is | |
| 1327 | + // we'll just get redirected back to redo the current step | |
| 1328 | + $this->go_to_next_step(); | |
| 1329 | + return false; | |
| 1330 | + } | |
| 1331 | + } | |
| 1332 | +			} catch (EE_Error $e) { | |
| 1333 | + $e->get_error(); | |
| 1334 | + } | |
| 1335 | + } | |
| 1336 | + return true; | |
| 1337 | + } | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + /** | |
| 1342 | + * _process_action | |
| 1343 | + * | |
| 1344 | + * @access private | |
| 1345 | + * @return void | |
| 1346 | + * @throws EE_Error | |
| 1347 | + */ | |
| 1348 | + private function _process_form_action() | |
| 1349 | +	{ | |
| 1350 | + // what cha wanna do? | |
| 1351 | +		switch ($this->checkout->action) { | |
| 1352 | + // AJAX next step reg form | |
| 1353 | + case 'display_spco_reg_step' : | |
| 1354 | + $this->checkout->redirect = false; | |
| 1355 | +				if (EE_Registry::instance()->REQ->ajax) { | |
| 1356 | + $this->checkout->json_response->set_reg_step_html( | |
| 1357 | + $this->checkout->current_step->display_reg_form() | |
| 1358 | + ); | |
| 1359 | + } | |
| 1360 | + break; | |
| 1361 | + default : | |
| 1362 | + // meh... do one of those other steps first | |
| 1363 | + if ( | |
| 1364 | + ! empty($this->checkout->action) | |
| 1365 | + && is_callable(array($this->checkout->current_step, $this->checkout->action)) | |
| 1366 | +				) { | |
| 1367 | + // dynamically creates hook point like: | |
| 1368 | + // AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step | |
| 1369 | + do_action( | |
| 1370 | +						"AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", | |
| 1371 | + $this->checkout->current_step | |
| 1372 | + ); | |
| 1373 | + // call action on current step | |
| 1374 | +					if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { | |
| 1375 | + // good registrant, you get to proceed | |
| 1376 | + if ( | |
| 1377 | + $this->checkout->current_step->success_message() !== '' | |
| 1378 | + && apply_filters( | |
| 1379 | + 'FHEE__Single_Page_Checkout___process_form_action__display_success', | |
| 1380 | + false | |
| 1381 | + ) | |
| 1382 | +						) { | |
| 1383 | + EE_Error::add_success( | |
| 1384 | + $this->checkout->current_step->success_message() | |
| 1385 | + . '<br />' . $this->checkout->next_step->_instructions() | |
| 1386 | + ); | |
| 1387 | + } | |
| 1388 | + // pack it up, pack it in... | |
| 1389 | + $this->_setup_redirect(); | |
| 1390 | + } | |
| 1391 | + // dynamically creates hook point like: | |
| 1392 | + // AHEE__Single_Page_Checkout__after_payment_options__process_reg_step | |
| 1393 | + do_action( | |
| 1394 | +						"AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", | |
| 1395 | + $this->checkout->current_step | |
| 1396 | + ); | |
| 1397 | +				} else { | |
| 1398 | + EE_Error::add_error( | |
| 1399 | + sprintf( | |
| 1400 | + __( | |
| 1401 | + 'The requested form action "%s" does not exist for the current "%s" registration step.', | |
| 1402 | + 'event_espresso' | |
| 1403 | + ), | |
| 1404 | + $this->checkout->action, | |
| 1405 | + $this->checkout->current_step->name() | |
| 1406 | + ), | |
| 1407 | + __FILE__, | |
| 1408 | + __FUNCTION__, | |
| 1409 | + __LINE__ | |
| 1410 | + ); | |
| 1411 | + } | |
| 1412 | + // end default | |
| 1413 | + } | |
| 1414 | + // store our progress so far | |
| 1415 | + $this->checkout->stash_transaction_and_checkout(); | |
| 1416 | + // advance to the next step! If you pass GO, collect $200 | |
| 1417 | + $this->go_to_next_step(); | |
| 1418 | + } | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + /** | |
| 1423 | + * add_styles_and_scripts | |
| 1424 | + * | |
| 1425 | + * @access public | |
| 1426 | + * @return void | |
| 1427 | + */ | |
| 1428 | + public function add_styles_and_scripts() | |
| 1429 | +	{ | |
| 1430 | + // i18n | |
| 1431 | + $this->translate_js_strings(); | |
| 1432 | +		if ($this->checkout->admin_request) { | |
| 1433 | +			add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); | |
| 1434 | +		} else { | |
| 1435 | +			add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); | |
| 1436 | + } | |
| 1437 | + } | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + /** | |
| 1442 | + * translate_js_strings | |
| 1443 | + * | |
| 1444 | + * @access public | |
| 1445 | + * @return void | |
| 1446 | + */ | |
| 1447 | + public function translate_js_strings() | |
| 1448 | +	{ | |
| 1449 | + EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; | |
| 1450 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; | |
| 1451 | + EE_Registry::$i18n_js_strings['server_error'] = __( | |
| 1452 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', | |
| 1453 | + 'event_espresso' | |
| 1454 | + ); | |
| 1455 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __( | |
| 1456 | + 'An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', | |
| 1457 | + 'event_espresso' | |
| 1458 | + ); | |
| 1459 | + EE_Registry::$i18n_js_strings['validation_error'] = __( | |
| 1460 | + 'There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', | |
| 1461 | + 'event_espresso' | |
| 1462 | + ); | |
| 1463 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __( | |
| 1464 | + 'There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', | |
| 1465 | + 'event_espresso' | |
| 1466 | + ); | |
| 1467 | + EE_Registry::$i18n_js_strings['reg_step_error'] = __( | |
| 1468 | + 'This registration step could not be completed. Please refresh the page and try again.', | |
| 1469 | + 'event_espresso' | |
| 1470 | + ); | |
| 1471 | + EE_Registry::$i18n_js_strings['invalid_coupon'] = __( | |
| 1472 | + 'We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', | |
| 1473 | + 'event_espresso' | |
| 1474 | + ); | |
| 1475 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf( | |
| 1476 | + __( | |
| 1477 | + 'Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', | |
| 1478 | + 'event_espresso' | |
| 1479 | + ), | |
| 1480 | + '<br/>', | |
| 1481 | + '<br/>' | |
| 1482 | + ); | |
| 1483 | +		EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); | |
| 1484 | + EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); | |
| 1485 | + EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; | |
| 1486 | + EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; | |
| 1487 | +		EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); | |
| 1488 | +		EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); | |
| 1489 | +		EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); | |
| 1490 | +		EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); | |
| 1491 | +		EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); | |
| 1492 | +		EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); | |
| 1493 | +		EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); | |
| 1494 | +		EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); | |
| 1495 | +		EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); | |
| 1496 | +		EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); | |
| 1497 | +		EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); | |
| 1498 | +		EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); | |
| 1499 | +		EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); | |
| 1500 | +		EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); | |
| 1501 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( | |
| 1502 | + __( | |
| 1503 | + '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', | |
| 1504 | + 'event_espresso' | |
| 1505 | + ), | |
| 1506 | + '<h4 class="important-notice">', | |
| 1507 | + '</h4>', | |
| 1508 | + '<br />', | |
| 1509 | + '<p>', | |
| 1510 | +			'<a href="' . get_post_type_archive_link('espresso_events') . '" title="', | |
| 1511 | + '">', | |
| 1512 | + '</a>', | |
| 1513 | + '</p>' | |
| 1514 | + ); | |
| 1515 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters( | |
| 1516 | + 'FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', | |
| 1517 | + true | |
| 1518 | + ); | |
| 1519 | + EE_Registry::$i18n_js_strings['session_extension'] = absint( | |
| 1520 | +			apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) | |
| 1521 | + ); | |
| 1522 | + EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( | |
| 1523 | + 'M d, Y H:i:s', | |
| 1524 | +			EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) | |
| 1525 | + ); | |
| 1526 | + } | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + /** | |
| 1531 | + * enqueue_styles_and_scripts | |
| 1532 | + * | |
| 1533 | + * @access public | |
| 1534 | + * @return void | |
| 1535 | + * @throws EE_Error | |
| 1536 | + */ | |
| 1537 | + public function enqueue_styles_and_scripts() | |
| 1538 | +	{ | |
| 1539 | + // load css | |
| 1540 | + wp_register_style( | |
| 1541 | + 'single_page_checkout', | |
| 1542 | + SPCO_CSS_URL . 'single_page_checkout.css', | |
| 1543 | +			array('espresso_default'), | |
| 1544 | + EVENT_ESPRESSO_VERSION | |
| 1545 | + ); | |
| 1546 | +		wp_enqueue_style('single_page_checkout'); | |
| 1547 | + // load JS | |
| 1548 | + wp_register_script( | |
| 1549 | + 'jquery_plugin', | |
| 1550 | + EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', | |
| 1551 | +			array('jquery'), | |
| 1552 | + '1.0.1', | |
| 1553 | + true | |
| 1554 | + ); | |
| 1555 | + wp_register_script( | |
| 1556 | + 'jquery_countdown', | |
| 1557 | + EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', | |
| 1558 | +			array('jquery_plugin'), | |
| 1559 | + '2.0.2', | |
| 1560 | + true | |
| 1561 | + ); | |
| 1562 | + wp_register_script( | |
| 1563 | + 'single_page_checkout', | |
| 1564 | + SPCO_JS_URL . 'single_page_checkout.js', | |
| 1565 | +			array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), | |
| 1566 | + EVENT_ESPRESSO_VERSION, | |
| 1567 | + true | |
| 1568 | + ); | |
| 1569 | +		if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { | |
| 1570 | + $this->checkout->registration_form->enqueue_js(); | |
| 1571 | + } | |
| 1572 | +		if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { | |
| 1573 | + $this->checkout->current_step->reg_form->enqueue_js(); | |
| 1574 | + } | |
| 1575 | +		wp_enqueue_script('single_page_checkout'); | |
| 1576 | + /** | |
| 1577 | + * global action hook for enqueueing styles and scripts with | |
| 1578 | + * spco calls. | |
| 1579 | + */ | |
| 1580 | +		do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); | |
| 1581 | + /** | |
| 1582 | + * dynamic action hook for enqueueing styles and scripts with spco calls. | |
| 1583 | + * The hook will end up being something like: | |
| 1584 | + * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information | |
| 1585 | + */ | |
| 1586 | + do_action( | |
| 1587 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), | |
| 1588 | + $this | |
| 1589 | + ); | |
| 1590 | + } | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + /** | |
| 1595 | + * display the Registration Single Page Checkout Form | |
| 1596 | + * | |
| 1597 | + * @access private | |
| 1598 | + * @return void | |
| 1599 | + * @throws EE_Error | |
| 1600 | + */ | |
| 1601 | + private function _display_spco_reg_form() | |
| 1602 | +	{ | |
| 1603 | + // if registering via the admin, just display the reg form for the current step | |
| 1604 | +		if ($this->checkout->admin_request) { | |
| 1605 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); | |
| 1606 | +		} else { | |
| 1607 | + // add powered by EE msg | |
| 1608 | +			add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); | |
| 1609 | + $empty_cart = count( | |
| 1610 | + $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) | |
| 1611 | + ) < 1; | |
| 1612 | + EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; | |
| 1613 | + $cookies_not_set_msg = ''; | |
| 1614 | +			if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { | |
| 1615 | + $cookies_not_set_msg = apply_filters( | |
| 1616 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', | |
| 1617 | + sprintf( | |
| 1618 | + __( | |
| 1619 | + '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', | |
| 1620 | + 'event_espresso' | |
| 1621 | + ), | |
| 1622 | + '<div class="ee-attention">', | |
| 1623 | + '</div>', | |
| 1624 | + '<h6 class="important-notice">', | |
| 1625 | + '</h6>', | |
| 1626 | + '<p>', | |
| 1627 | + '</p>', | |
| 1628 | + '<br />', | |
| 1629 | + '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', | |
| 1630 | + '</a>' | |
| 1631 | + ) | |
| 1632 | + ); | |
| 1633 | + } | |
| 1634 | + $this->checkout->registration_form = new EE_Form_Section_Proper( | |
| 1635 | + array( | |
| 1636 | + 'name' => 'single-page-checkout', | |
| 1637 | + 'html_id' => 'ee-single-page-checkout-dv', | |
| 1638 | + 'layout_strategy' => | |
| 1639 | + new EE_Template_Layout( | |
| 1640 | + array( | |
| 1641 | + 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', | |
| 1642 | + 'template_args' => array( | |
| 1643 | + 'empty_cart' => $empty_cart, | |
| 1644 | + 'revisit' => $this->checkout->revisit, | |
| 1645 | + 'reg_steps' => $this->checkout->reg_steps, | |
| 1646 | + 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step | |
| 1647 | + ? $this->checkout->next_step->slug() | |
| 1648 | + : '', | |
| 1649 | + 'cancel_page_url' => $this->checkout->cancel_page_url, | |
| 1650 | + 'empty_msg' => apply_filters( | |
| 1651 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', | |
| 1652 | + sprintf( | |
| 1653 | + __( | |
| 1654 | + 'You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', | |
| 1655 | + 'event_espresso' | |
| 1656 | + ), | |
| 1657 | + '<a href="' | |
| 1658 | +											. get_post_type_archive_link('espresso_events') | |
| 1659 | + . '" title="', | |
| 1660 | + '">', | |
| 1661 | + '</a>' | |
| 1662 | + ) | |
| 1663 | + ), | |
| 1664 | + 'cookies_not_set_msg' => $cookies_not_set_msg, | |
| 1665 | + 'registration_time_limit' => $this->checkout->get_registration_time_limit(), | |
| 1666 | + 'session_expiration' => gmdate( | |
| 1667 | + 'M d, Y H:i:s', | |
| 1668 | + EE_Registry::instance()->SSN->expiration() | |
| 1669 | +										+ (get_option('gmt_offset') * HOUR_IN_SECONDS) | |
| 1670 | + ), | |
| 1671 | + ), | |
| 1672 | + ) | |
| 1673 | + ), | |
| 1674 | + ) | |
| 1675 | + ); | |
| 1676 | + // load template and add to output sent that gets filtered into the_content() | |
| 1677 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); | |
| 1678 | + } | |
| 1679 | + } | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + /** | |
| 1684 | + * add_extra_finalize_registration_inputs | |
| 1685 | + * | |
| 1686 | + * @access public | |
| 1687 | + * @param $next_step | |
| 1688 | + * @internal param string $label | |
| 1689 | + * @return void | |
| 1690 | + */ | |
| 1691 | + public function add_extra_finalize_registration_inputs($next_step) | |
| 1692 | +	{ | |
| 1693 | +		if ($next_step === 'finalize_registration') { | |
| 1694 | + echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; | |
| 1695 | + } | |
| 1696 | + } | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + /** | |
| 1701 | + * display_registration_footer | |
| 1702 | + * | |
| 1703 | + * @access public | |
| 1704 | + * @return string | |
| 1705 | + */ | |
| 1706 | + public static function display_registration_footer() | |
| 1707 | +	{ | |
| 1708 | + if ( | |
| 1709 | + apply_filters( | |
| 1710 | + 'FHEE__EE_Front__Controller__show_reg_footer', | |
| 1711 | + EE_Registry::instance()->CFG->admin->show_reg_footer | |
| 1712 | + ) | |
| 1713 | +		) { | |
| 1714 | + add_filter( | |
| 1715 | + 'FHEE__EEH_Template__powered_by_event_espresso__url', | |
| 1716 | +				function ($url) { | |
| 1717 | +					return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); | |
| 1718 | + } | |
| 1719 | + ); | |
| 1720 | + echo apply_filters( | |
| 1721 | + 'FHEE__EE_Front_Controller__display_registration_footer', | |
| 1722 | + \EEH_Template::powered_by_event_espresso( | |
| 1723 | + '', | |
| 1724 | + 'espresso-registration-footer-dv', | |
| 1725 | +					array('utm_content' => 'registration_checkout') | |
| 1726 | + ) | |
| 1727 | + ); | |
| 1728 | + } | |
| 1729 | + return ''; | |
| 1730 | + } | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + /** | |
| 1735 | + * unlock_transaction | |
| 1736 | + * | |
| 1737 | + * @access public | |
| 1738 | + * @return void | |
| 1739 | + * @throws EE_Error | |
| 1740 | + */ | |
| 1741 | + public function unlock_transaction() | |
| 1742 | +	{ | |
| 1743 | +		if ($this->checkout->transaction instanceof EE_Transaction) { | |
| 1744 | + $this->checkout->transaction->unlock(); | |
| 1745 | + } | |
| 1746 | + } | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + /** | |
| 1751 | + * _setup_redirect | |
| 1752 | + * | |
| 1753 | + * @access private | |
| 1754 | + * @return void | |
| 1755 | + */ | |
| 1756 | + private function _setup_redirect() | |
| 1757 | +	{ | |
| 1758 | +		if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { | |
| 1759 | + $this->checkout->redirect = true; | |
| 1760 | +			if (empty($this->checkout->redirect_url)) { | |
| 1761 | + $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); | |
| 1762 | + } | |
| 1763 | + $this->checkout->redirect_url = apply_filters( | |
| 1764 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', | |
| 1765 | + $this->checkout->redirect_url, | |
| 1766 | + $this->checkout | |
| 1767 | + ); | |
| 1768 | + } | |
| 1769 | + } | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + /** | |
| 1774 | + * handle ajax message responses and redirects | |
| 1775 | + * | |
| 1776 | + * @access public | |
| 1777 | + * @return void | |
| 1778 | + * @throws EE_Error | |
| 1779 | + */ | |
| 1780 | + public function go_to_next_step() | |
| 1781 | +	{ | |
| 1782 | +		if (EE_Registry::instance()->REQ->ajax) { | |
| 1783 | + // capture contents of output buffer we started earlier in the request, and insert into JSON response | |
| 1784 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); | |
| 1785 | + } | |
| 1786 | + $this->unlock_transaction(); | |
| 1787 | + // just return for these conditions | |
| 1788 | + if ( | |
| 1789 | + $this->checkout->admin_request | |
| 1790 | + || $this->checkout->action === 'redirect_form' | |
| 1791 | + || $this->checkout->action === 'update_checkout' | |
| 1792 | +		) { | |
| 1793 | + return; | |
| 1794 | + } | |
| 1795 | + // AJAX response | |
| 1796 | + $this->_handle_json_response(); | |
| 1797 | + // redirect to next step or the Thank You page | |
| 1798 | + $this->_handle_html_redirects(); | |
| 1799 | + // hmmm... must be something wrong, so let's just display the form again ! | |
| 1800 | + $this->_display_spco_reg_form(); | |
| 1801 | + } | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + /** | |
| 1806 | + * _handle_json_response | |
| 1807 | + * | |
| 1808 | + * @access protected | |
| 1809 | + * @return void | |
| 1810 | + */ | |
| 1811 | + protected function _handle_json_response() | |
| 1812 | +	{ | |
| 1813 | + // if this is an ajax request | |
| 1814 | +		if (EE_Registry::instance()->REQ->ajax) { | |
| 1815 | + // DEBUG LOG | |
| 1816 | + //$this->checkout->log( | |
| 1817 | + // __CLASS__, __FUNCTION__, __LINE__, | |
| 1818 | + // array( | |
| 1819 | + // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), | |
| 1820 | + // 'redirect' => $this->checkout->redirect, | |
| 1821 | + // 'continue_reg' => $this->checkout->continue_reg, | |
| 1822 | + // ) | |
| 1823 | + //); | |
| 1824 | + $this->checkout->json_response->set_registration_time_limit( | |
| 1825 | + $this->checkout->get_registration_time_limit() | |
| 1826 | + ); | |
| 1827 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); | |
| 1828 | + // just send the ajax ( | |
| 1829 | + $json_response = apply_filters( | |
| 1830 | + 'FHEE__EE_Single_Page_Checkout__JSON_response', | |
| 1831 | + $this->checkout->json_response | |
| 1832 | + ); | |
| 1833 | + echo $json_response; | |
| 1834 | + exit(); | |
| 1835 | + } | |
| 1836 | + } | |
| 1837 | + | |
| 1838 | + | |
| 1839 | + | |
| 1840 | + /** | |
| 1841 | + * _handle_redirects | |
| 1842 | + * | |
| 1843 | + * @access protected | |
| 1844 | + * @return void | |
| 1845 | + */ | |
| 1846 | + protected function _handle_html_redirects() | |
| 1847 | +	{ | |
| 1848 | + // going somewhere ? | |
| 1849 | +		if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { | |
| 1850 | + // store notices in a transient | |
| 1851 | + EE_Error::get_notices(false, true, true); | |
| 1852 | + // DEBUG LOG | |
| 1853 | + //$this->checkout->log( | |
| 1854 | + // __CLASS__, __FUNCTION__, __LINE__, | |
| 1855 | + // array( | |
| 1856 | + // 'headers_sent' => headers_sent(), | |
| 1857 | + // 'redirect_url' => $this->checkout->redirect_url, | |
| 1858 | + // 'headers_list' => headers_list(), | |
| 1859 | + // ) | |
| 1860 | + //); | |
| 1861 | + wp_safe_redirect($this->checkout->redirect_url); | |
| 1862 | + exit(); | |
| 1863 | + } | |
| 1864 | + } | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + /** | |
| 1869 | + * set_checkout_anchor | |
| 1870 | + * | |
| 1871 | + * @access public | |
| 1872 | + * @return void | |
| 1873 | + */ | |
| 1874 | + public function set_checkout_anchor() | |
| 1875 | +	{ | |
| 1876 | + echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; | |
| 1877 | + } | |
| 1878 | 1878 | |
| 1879 | 1879 | |
| 1880 | 1880 | |
| @@ -218,19 +218,19 @@ discard block | ||
| 218 | 218 | */ | 
| 219 | 219 | public static function set_definitions() | 
| 220 | 220 |      { | 
| 221 | -        if(defined('SPCO_BASE_PATH')) { | |
| 221 | +        if (defined('SPCO_BASE_PATH')) { | |
| 222 | 222 | return; | 
| 223 | 223 | } | 
| 224 | 224 | define( | 
| 225 | 225 | 'SPCO_BASE_PATH', | 
| 226 | -            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS | |
| 226 | +            rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS).DS | |
| 227 | 227 | ); | 
| 228 | -        define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); | |
| 229 | -        define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); | |
| 230 | -        define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); | |
| 231 | -        define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); | |
| 232 | -        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); | |
| 233 | -        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); | |
| 228 | +        define('SPCO_CSS_URL', plugin_dir_url(__FILE__).'css'.DS); | |
| 229 | +        define('SPCO_IMG_URL', plugin_dir_url(__FILE__).'img'.DS); | |
| 230 | +        define('SPCO_JS_URL', plugin_dir_url(__FILE__).'js'.DS); | |
| 231 | +        define('SPCO_INC_PATH', SPCO_BASE_PATH.'inc'.DS); | |
| 232 | +        define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH.'reg_steps'.DS); | |
| 233 | +        define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH.'templates'.DS); | |
| 234 | 234 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); | 
| 235 | 235 | EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( | 
| 236 | 236 |              __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', | 
| @@ -239,7 +239,7 @@ discard block | ||
| 239 | 239 | '</h4>', | 
| 240 | 240 | '<br />', | 
| 241 | 241 | '<p>', | 
| 242 | -            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', | |
| 242 | +            '<a href="'.get_post_type_archive_link('espresso_events').'" title="', | |
| 243 | 243 | '">', | 
| 244 | 244 | '</a>', | 
| 245 | 245 | '</p>' | 
| @@ -262,7 +262,7 @@ discard block | ||
| 262 | 262 | return; | 
| 263 | 263 | } | 
| 264 | 264 | // filter list of reg_steps | 
| 265 | - $reg_steps_to_load = (array)apply_filters( | |
| 265 | + $reg_steps_to_load = (array) apply_filters( | |
| 266 | 266 | 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', | 
| 267 | 267 | EED_Single_Page_Checkout::get_reg_steps() | 
| 268 | 268 | ); | 
| @@ -314,25 +314,25 @@ discard block | ||
| 314 | 314 |          if (empty($reg_steps)) { | 
| 315 | 315 | $reg_steps = array( | 
| 316 | 316 | 10 => array( | 
| 317 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', | |
| 317 | + 'file_path' => SPCO_REG_STEPS_PATH.'attendee_information', | |
| 318 | 318 | 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', | 
| 319 | 319 | 'slug' => 'attendee_information', | 
| 320 | 320 | 'has_hooks' => false, | 
| 321 | 321 | ), | 
| 322 | 322 | 20 => array( | 
| 323 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', | |
| 323 | + 'file_path' => SPCO_REG_STEPS_PATH.'registration_confirmation', | |
| 324 | 324 | 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', | 
| 325 | 325 | 'slug' => 'registration_confirmation', | 
| 326 | 326 | 'has_hooks' => false, | 
| 327 | 327 | ), | 
| 328 | 328 | 30 => array( | 
| 329 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', | |
| 329 | + 'file_path' => SPCO_REG_STEPS_PATH.'payment_options', | |
| 330 | 330 | 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', | 
| 331 | 331 | 'slug' => 'payment_options', | 
| 332 | 332 | 'has_hooks' => true, | 
| 333 | 333 | ), | 
| 334 | 334 | 999 => array( | 
| 335 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', | |
| 335 | + 'file_path' => SPCO_REG_STEPS_PATH.'finalize_registration', | |
| 336 | 336 | 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', | 
| 337 | 337 | 'slug' => 'finalize_registration', | 
| 338 | 338 | 'has_hooks' => false, | 
| @@ -516,7 +516,7 @@ discard block | ||
| 516 | 516 | // DEBUG LOG | 
| 517 | 517 | //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); | 
| 518 | 518 | // get reg form | 
| 519 | -            if( ! $this->_check_form_submission()) { | |
| 519 | +            if ( ! $this->_check_form_submission()) { | |
| 520 | 520 | EED_Single_Page_Checkout::$_initialized = true; | 
| 521 | 521 | return; | 
| 522 | 522 | } | 
| @@ -557,7 +557,7 @@ discard block | ||
| 557 | 557 | ); | 
| 558 | 558 | // is session still valid ? | 
| 559 | 559 | if ($clear_session_requested | 
| 560 | - || ( EE_Registry::instance()->SSN->expired() | |
| 560 | + || (EE_Registry::instance()->SSN->expired() | |
| 561 | 561 |                && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '' | 
| 562 | 562 | ) | 
| 563 | 563 |          ) { | 
| @@ -566,7 +566,7 @@ discard block | ||
| 566 | 566 | // EE_Registry::instance()->SSN->reset_cart(); | 
| 567 | 567 | // EE_Registry::instance()->SSN->reset_checkout(); | 
| 568 | 568 | // EE_Registry::instance()->SSN->reset_transaction(); | 
| 569 | -            if (! $clear_session_requested) { | |
| 569 | +            if ( ! $clear_session_requested) { | |
| 570 | 570 | EE_Error::add_attention( | 
| 571 | 571 | EE_Registry::$i18n_js_strings['registration_expiration_notice'], | 
| 572 | 572 | __FILE__, __FUNCTION__, __LINE__ | 
| @@ -1121,7 +1121,7 @@ discard block | ||
| 1121 | 1121 |                      if ( ! $registration instanceof EE_Registration) { | 
| 1122 | 1122 | throw new InvalidEntityException($registration, 'EE_Registration'); | 
| 1123 | 1123 | } | 
| 1124 | - $registrations[ $registration->ID() ] = $registration; | |
| 1124 | + $registrations[$registration->ID()] = $registration; | |
| 1125 | 1125 | } | 
| 1126 | 1126 | } | 
| 1127 | 1127 | $registration_processor->fix_reg_final_price_rounding_issue($transaction); | 
| @@ -1382,7 +1382,7 @@ discard block | ||
| 1382 | 1382 |                          ) { | 
| 1383 | 1383 | EE_Error::add_success( | 
| 1384 | 1384 | $this->checkout->current_step->success_message() | 
| 1385 | - . '<br />' . $this->checkout->next_step->_instructions() | |
| 1385 | + . '<br />'.$this->checkout->next_step->_instructions() | |
| 1386 | 1386 | ); | 
| 1387 | 1387 | } | 
| 1388 | 1388 | // pack it up, pack it in... | 
| @@ -1507,7 +1507,7 @@ discard block | ||
| 1507 | 1507 | '</h4>', | 
| 1508 | 1508 | '<br />', | 
| 1509 | 1509 | '<p>', | 
| 1510 | -            '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', | |
| 1510 | +            '<a href="'.get_post_type_archive_link('espresso_events').'" title="', | |
| 1511 | 1511 | '">', | 
| 1512 | 1512 | '</a>', | 
| 1513 | 1513 | '</p>' | 
| @@ -1539,7 +1539,7 @@ discard block | ||
| 1539 | 1539 | // load css | 
| 1540 | 1540 | wp_register_style( | 
| 1541 | 1541 | 'single_page_checkout', | 
| 1542 | - SPCO_CSS_URL . 'single_page_checkout.css', | |
| 1542 | + SPCO_CSS_URL.'single_page_checkout.css', | |
| 1543 | 1543 |              array('espresso_default'), | 
| 1544 | 1544 | EVENT_ESPRESSO_VERSION | 
| 1545 | 1545 | ); | 
| @@ -1547,21 +1547,21 @@ discard block | ||
| 1547 | 1547 | // load JS | 
| 1548 | 1548 | wp_register_script( | 
| 1549 | 1549 | 'jquery_plugin', | 
| 1550 | - EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', | |
| 1550 | + EE_THIRD_PARTY_URL.'jquery .plugin.min.js', | |
| 1551 | 1551 |              array('jquery'), | 
| 1552 | 1552 | '1.0.1', | 
| 1553 | 1553 | true | 
| 1554 | 1554 | ); | 
| 1555 | 1555 | wp_register_script( | 
| 1556 | 1556 | 'jquery_countdown', | 
| 1557 | - EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', | |
| 1557 | + EE_THIRD_PARTY_URL.'jquery .countdown.min.js', | |
| 1558 | 1558 |              array('jquery_plugin'), | 
| 1559 | 1559 | '2.0.2', | 
| 1560 | 1560 | true | 
| 1561 | 1561 | ); | 
| 1562 | 1562 | wp_register_script( | 
| 1563 | 1563 | 'single_page_checkout', | 
| 1564 | - SPCO_JS_URL . 'single_page_checkout.js', | |
| 1564 | + SPCO_JS_URL.'single_page_checkout.js', | |
| 1565 | 1565 |              array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), | 
| 1566 | 1566 | EVENT_ESPRESSO_VERSION, | 
| 1567 | 1567 | true | 
| @@ -1584,7 +1584,7 @@ discard block | ||
| 1584 | 1584 | * AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information | 
| 1585 | 1585 | */ | 
| 1586 | 1586 | do_action( | 
| 1587 | - 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), | |
| 1587 | + 'AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__'.$this->checkout->current_step->slug(), | |
| 1588 | 1588 | $this | 
| 1589 | 1589 | ); | 
| 1590 | 1590 | } | 
| @@ -1638,7 +1638,7 @@ discard block | ||
| 1638 | 1638 | 'layout_strategy' => | 
| 1639 | 1639 | new EE_Template_Layout( | 
| 1640 | 1640 | array( | 
| 1641 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', | |
| 1641 | + 'layout_template_file' => SPCO_TEMPLATES_PATH.'registration_page_wrapper.template.php', | |
| 1642 | 1642 | 'template_args' => array( | 
| 1643 | 1643 | 'empty_cart' => $empty_cart, | 
| 1644 | 1644 | 'revisit' => $this->checkout->revisit, | 
| @@ -1713,7 +1713,7 @@ discard block | ||
| 1713 | 1713 |          ) { | 
| 1714 | 1714 | add_filter( | 
| 1715 | 1715 | 'FHEE__EEH_Template__powered_by_event_espresso__url', | 
| 1716 | -                function ($url) { | |
| 1716 | +                function($url) { | |
| 1717 | 1717 |                      return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); | 
| 1718 | 1718 | } | 
| 1719 | 1719 | ); | 
| @@ -1,5 +1,5 @@ discard block | ||
| 1 | 1 |  <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { | 
| 2 | -    exit('No direct script access allowed'); | |
| 2 | +	exit('No direct script access allowed'); | |
| 3 | 3 | } | 
| 4 | 4 | |
| 5 | 5 | /** | 
| @@ -27,1975 +27,1975 @@ discard block | ||
| 27 | 27 | class Transactions_Admin_Page extends EE_Admin_Page | 
| 28 | 28 |  { | 
| 29 | 29 | |
| 30 | - /** | |
| 31 | - * @var EE_Transaction | |
| 32 | - */ | |
| 33 | - private $_transaction; | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * @var EE_Session | |
| 37 | - */ | |
| 38 | - private $_session; | |
| 39 | - | |
| 40 | - /** | |
| 41 | - * @var array $_txn_status | |
| 42 | - */ | |
| 43 | - private static $_txn_status; | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * @var array $_pay_status | |
| 47 | - */ | |
| 48 | - private static $_pay_status; | |
| 49 | - | |
| 50 | - /** | |
| 51 | - * @var array $_existing_reg_payment_REG_IDs | |
| 52 | - */ | |
| 53 | - protected $_existing_reg_payment_REG_IDs = null; | |
| 54 | - | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * @Constructor | |
| 58 | - * @access public | |
| 59 | - * | |
| 60 | - * @param bool $routing | |
| 61 | - * | |
| 62 | - * @return Transactions_Admin_Page | |
| 63 | - */ | |
| 64 | - public function __construct($routing = true) | |
| 65 | -    { | |
| 66 | - parent::__construct($routing); | |
| 67 | - } | |
| 68 | - | |
| 69 | - | |
| 70 | - /** | |
| 71 | - * _init_page_props | |
| 72 | - * @return void | |
| 73 | - */ | |
| 74 | - protected function _init_page_props() | |
| 75 | -    { | |
| 76 | - $this->page_slug = TXN_PG_SLUG; | |
| 77 | -        $this->page_label       = esc_html__('Transactions', 'event_espresso'); | |
| 78 | - $this->_admin_base_url = TXN_ADMIN_URL; | |
| 79 | - $this->_admin_base_path = TXN_ADMIN; | |
| 80 | - } | |
| 81 | - | |
| 82 | - | |
| 83 | - /** | |
| 84 | - * _ajax_hooks | |
| 85 | - * @return void | |
| 86 | - */ | |
| 87 | - protected function _ajax_hooks() | |
| 88 | -    { | |
| 89 | -        add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); | |
| 90 | -        add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); | |
| 91 | -        add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); | |
| 92 | - } | |
| 93 | - | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * _define_page_props | |
| 97 | - * @return void | |
| 98 | - */ | |
| 99 | - protected function _define_page_props() | |
| 100 | -    { | |
| 101 | - $this->_admin_page_title = $this->page_label; | |
| 102 | - $this->_labels = array( | |
| 103 | - 'buttons' => array( | |
| 104 | -                'add'    => esc_html__('Add New Transaction', 'event_espresso'), | |
| 105 | -                'edit'   => esc_html__('Edit Transaction', 'event_espresso'), | |
| 106 | -                'delete' => esc_html__('Delete Transaction', 'event_espresso'), | |
| 107 | - ) | |
| 108 | - ); | |
| 109 | - } | |
| 110 | - | |
| 111 | - | |
| 112 | - /** | |
| 113 | - * grab url requests and route them | |
| 114 | - * @access private | |
| 115 | - * @return void | |
| 116 | - */ | |
| 117 | - public function _set_page_routes() | |
| 118 | -    { | |
| 119 | - | |
| 120 | - $this->_set_transaction_status_array(); | |
| 121 | - | |
| 122 | - $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0; | |
| 123 | - | |
| 124 | - $this->_page_routes = array( | |
| 125 | - | |
| 126 | - 'default' => array( | |
| 127 | - 'func' => '_transactions_overview_list_table', | |
| 128 | - 'capability' => 'ee_read_transactions' | |
| 129 | - ), | |
| 130 | - | |
| 131 | - 'view_transaction' => array( | |
| 132 | - 'func' => '_transaction_details', | |
| 133 | - 'capability' => 'ee_read_transaction', | |
| 134 | - 'obj_id' => $txn_id | |
| 135 | - ), | |
| 136 | - | |
| 137 | - 'send_payment_reminder' => array( | |
| 138 | - 'func' => '_send_payment_reminder', | |
| 139 | - 'noheader' => true, | |
| 140 | - 'capability' => 'ee_send_message' | |
| 141 | - ), | |
| 142 | - | |
| 143 | - 'espresso_apply_payment' => array( | |
| 144 | - 'func' => 'apply_payments_or_refunds', | |
| 145 | - 'noheader' => true, | |
| 146 | - 'capability' => 'ee_edit_payments' | |
| 147 | - ), | |
| 148 | - | |
| 149 | - 'espresso_apply_refund' => array( | |
| 150 | - 'func' => 'apply_payments_or_refunds', | |
| 151 | - 'noheader' => true, | |
| 152 | - 'capability' => 'ee_edit_payments' | |
| 153 | - ), | |
| 154 | - | |
| 155 | - 'espresso_delete_payment' => array( | |
| 156 | - 'func' => 'delete_payment', | |
| 157 | - 'noheader' => true, | |
| 158 | - 'capability' => 'ee_delete_payments' | |
| 159 | - ), | |
| 160 | - | |
| 161 | - ); | |
| 162 | - | |
| 163 | - } | |
| 164 | - | |
| 165 | - | |
| 166 | - protected function _set_page_config() | |
| 167 | -    { | |
| 168 | - $this->_page_config = array( | |
| 169 | - 'default' => array( | |
| 170 | - 'nav' => array( | |
| 171 | -                    'label' => esc_html__('Overview', 'event_espresso'), | |
| 172 | - 'order' => 10 | |
| 173 | - ), | |
| 174 | - 'list_table' => 'EE_Admin_Transactions_List_Table', | |
| 175 | - 'help_tabs' => array( | |
| 176 | - 'transactions_overview_help_tab' => array( | |
| 177 | -                        'title'    => esc_html__('Transactions Overview', 'event_espresso'), | |
| 178 | - 'filename' => 'transactions_overview' | |
| 179 | - ), | |
| 180 | - 'transactions_overview_table_column_headings_help_tab' => array( | |
| 181 | -                        'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'), | |
| 182 | - 'filename' => 'transactions_overview_table_column_headings' | |
| 183 | - ), | |
| 184 | - 'transactions_overview_views_filters_help_tab' => array( | |
| 185 | -                        'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), | |
| 186 | - 'filename' => 'transactions_overview_views_filters_search' | |
| 187 | - ), | |
| 188 | - ), | |
| 189 | -                'help_tour'     => array('Transactions_Overview_Help_Tour'), | |
| 190 | - /** | |
| 191 | - * commented out because currently we are not displaying tips for transaction list table status but this | |
| 192 | - * may change in a later iteration so want to keep the code for then. | |
| 193 | - */ | |
| 194 | - //'qtips' => array( 'Transactions_List_Table_Tips' ), | |
| 195 | - 'require_nonce' => false | |
| 196 | - ), | |
| 197 | - 'view_transaction' => array( | |
| 198 | - 'nav' => array( | |
| 199 | -                    'label'      => esc_html__('View Transaction', 'event_espresso'), | |
| 200 | - 'order' => 5, | |
| 201 | -                    'url'        => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), | |
| 202 | - $this->_current_page_view_url) : $this->_admin_base_url, | |
| 203 | - 'persistent' => false | |
| 204 | - ), | |
| 205 | - 'help_tabs' => array( | |
| 206 | - 'transactions_view_transaction_help_tab' => array( | |
| 207 | -                        'title'    => esc_html__('View Transaction', 'event_espresso'), | |
| 208 | - 'filename' => 'transactions_view_transaction' | |
| 209 | - ), | |
| 210 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( | |
| 211 | -                        'title'    => esc_html__('Transaction Details Table', 'event_espresso'), | |
| 212 | - 'filename' => 'transactions_view_transaction_transaction_details_table' | |
| 213 | - ), | |
| 214 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( | |
| 215 | -                        'title'    => esc_html__('Attendees Registered', 'event_espresso'), | |
| 216 | - 'filename' => 'transactions_view_transaction_attendees_registered' | |
| 217 | - ), | |
| 218 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( | |
| 219 | -                        'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), | |
| 220 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information' | |
| 221 | - ), | |
| 222 | - ), | |
| 223 | -                'qtips'     => array('Transaction_Details_Tips'), | |
| 224 | -                'help_tour' => array('Transaction_Details_Help_Tour'), | |
| 225 | -                'metaboxes' => array('_transaction_details_metaboxes'), | |
| 226 | - | |
| 227 | - 'require_nonce' => false | |
| 228 | - ) | |
| 229 | - ); | |
| 230 | - } | |
| 231 | - | |
| 232 | - | |
| 233 | - /** | |
| 234 | - * The below methods aren't used by this class currently | |
| 235 | - */ | |
| 236 | - protected function _add_screen_options() | |
| 237 | -    { | |
| 238 | - } | |
| 239 | - | |
| 240 | - protected function _add_feature_pointers() | |
| 241 | -    { | |
| 242 | - } | |
| 243 | - | |
| 244 | - public function admin_init() | |
| 245 | -    { | |
| 246 | - // IF a registration was JUST added via the admin... | |
| 247 | - if ( | |
| 248 | - isset( | |
| 249 | - $this->_req_data['redirect_from'], | |
| 250 | - $this->_req_data['EVT_ID'], | |
| 251 | - $this->_req_data['event_name'] | |
| 252 | - ) | |
| 253 | -        ) { | |
| 254 | - // then set a cookie so that we can block any attempts to use | |
| 255 | - // the back button as a way to enter another registration. | |
| 256 | -            setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'); | |
| 257 | - // and update the global | |
| 258 | - $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; | |
| 259 | - } | |
| 260 | -        EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', | |
| 261 | - 'event_espresso'); | |
| 262 | -        EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__('An error occurred! Please refresh the page and try again.', | |
| 263 | - 'event_espresso'); | |
| 264 | - EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; | |
| 265 | - EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; | |
| 266 | -        EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso'); | |
| 267 | -        EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__('This transaction has been overpaid ! Payments Total', | |
| 268 | - 'event_espresso'); | |
| 269 | - } | |
| 270 | - | |
| 271 | - public function admin_notices() | |
| 272 | -    { | |
| 273 | - } | |
| 274 | - | |
| 275 | - public function admin_footer_scripts() | |
| 276 | -    { | |
| 277 | - } | |
| 278 | - | |
| 279 | - | |
| 280 | - /** | |
| 281 | - * _set_transaction_status_array | |
| 282 | - * sets list of transaction statuses | |
| 283 | - * | |
| 284 | - * @access private | |
| 285 | - * @return void | |
| 286 | - */ | |
| 287 | - private function _set_transaction_status_array() | |
| 288 | -    { | |
| 289 | - self::$_txn_status = EEM_Transaction::instance()->status_array(true); | |
| 290 | - } | |
| 291 | - | |
| 292 | - | |
| 293 | - /** | |
| 294 | - * get_transaction_status_array | |
| 295 | - * return the transaction status array for wp_list_table | |
| 296 | - * | |
| 297 | - * @access public | |
| 298 | - * @return array | |
| 299 | - */ | |
| 300 | - public function get_transaction_status_array() | |
| 301 | -    { | |
| 302 | - return self::$_txn_status; | |
| 303 | - } | |
| 304 | - | |
| 305 | - | |
| 306 | - /** | |
| 307 | - * get list of payment statuses | |
| 308 | - * | |
| 309 | - * @access private | |
| 310 | - * @return void | |
| 311 | - */ | |
| 312 | - private function _get_payment_status_array() | |
| 313 | -    { | |
| 314 | - self::$_pay_status = EEM_Payment::instance()->status_array(true); | |
| 315 | - $this->_template_args['payment_status'] = self::$_pay_status; | |
| 316 | - | |
| 317 | - } | |
| 318 | - | |
| 319 | - | |
| 320 | - /** | |
| 321 | - * _add_screen_options_default | |
| 322 | - * | |
| 323 | - * @access protected | |
| 324 | - * @return void | |
| 325 | - */ | |
| 326 | - protected function _add_screen_options_default() | |
| 327 | -    { | |
| 328 | - $this->_per_page_screen_option(); | |
| 329 | - } | |
| 330 | - | |
| 331 | - | |
| 332 | - /** | |
| 333 | - * load_scripts_styles | |
| 334 | - * | |
| 335 | - * @access public | |
| 336 | - * @return void | |
| 337 | - */ | |
| 338 | - public function load_scripts_styles() | |
| 339 | -    { | |
| 340 | - //enqueue style | |
| 341 | -        wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), | |
| 342 | - EVENT_ESPRESSO_VERSION); | |
| 343 | -        wp_enqueue_style('espresso_txn'); | |
| 344 | - //scripts | |
| 345 | -        wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( | |
| 346 | - 'ee_admin_js', | |
| 347 | - 'ee-datepicker', | |
| 348 | - 'jquery-ui-datepicker', | |
| 349 | - 'jquery-ui-draggable', | |
| 350 | - 'ee-dialog', | |
| 351 | - 'ee-accounting', | |
| 352 | - 'ee-serialize-full-array' | |
| 353 | - ), EVENT_ESPRESSO_VERSION, true); | |
| 354 | -        wp_enqueue_script('espresso_txn'); | |
| 355 | - | |
| 356 | - } | |
| 357 | - | |
| 358 | - | |
| 359 | - /** | |
| 360 | - * load_scripts_styles_view_transaction | |
| 361 | - * | |
| 362 | - * @access public | |
| 363 | - * @return void | |
| 364 | - */ | |
| 365 | - public function load_scripts_styles_view_transaction() | |
| 366 | -    { | |
| 367 | - //styles | |
| 368 | -        wp_enqueue_style('espresso-ui-theme'); | |
| 369 | - } | |
| 370 | - | |
| 371 | - | |
| 372 | - /** | |
| 373 | - * load_scripts_styles_default | |
| 374 | - * | |
| 375 | - * @access public | |
| 376 | - * @return void | |
| 377 | - */ | |
| 378 | - public function load_scripts_styles_default() | |
| 379 | -    { | |
| 380 | - //styles | |
| 381 | -        wp_enqueue_style('espresso-ui-theme'); | |
| 382 | - } | |
| 383 | - | |
| 384 | - | |
| 385 | - /** | |
| 386 | - * _set_list_table_views_default | |
| 387 | - * | |
| 388 | - * @access protected | |
| 389 | - * @return void | |
| 390 | - */ | |
| 391 | - protected function _set_list_table_views_default() | |
| 392 | -    { | |
| 393 | - $this->_views = array( | |
| 394 | - 'all' => array( | |
| 395 | - 'slug' => 'all', | |
| 396 | -                'label' => esc_html__('View All Transactions', 'event_espresso'), | |
| 397 | - 'count' => 0 | |
| 398 | - ), | |
| 399 | - 'abandoned' => array( | |
| 400 | - 'slug' => 'abandoned', | |
| 401 | -                'label' => esc_html__('Abandoned Transactions', 'event_espresso'), | |
| 402 | - 'count' => 0 | |
| 403 | - ), | |
| 404 | - 'failed' => array( | |
| 405 | - 'slug' => 'failed', | |
| 406 | -                'label' => esc_html__('Failed Transactions', 'event_espresso'), | |
| 407 | - 'count' => 0 | |
| 408 | - ) | |
| 409 | - ); | |
| 410 | - } | |
| 411 | - | |
| 412 | - | |
| 413 | - /** | |
| 414 | - * _set_transaction_object | |
| 415 | - * This sets the _transaction property for the transaction details screen | |
| 416 | - * | |
| 417 | - * @access private | |
| 418 | - * @return void | |
| 419 | - */ | |
| 420 | - private function _set_transaction_object() | |
| 421 | -    { | |
| 422 | -        if (is_object($this->_transaction)) { | |
| 423 | - return; | |
| 424 | - } //get out we've already set the object | |
| 425 | - | |
| 426 | - $TXN = EEM_Transaction::instance(); | |
| 427 | - | |
| 428 | - $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; | |
| 429 | - | |
| 430 | - //get transaction object | |
| 431 | - $this->_transaction = $TXN->get_one_by_ID($TXN_ID); | |
| 432 | -        $this->_session     = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null; | |
| 433 | - $this->_transaction->verify_abandoned_transaction_status(); | |
| 434 | - | |
| 435 | -        if (empty($this->_transaction)) { | |
| 436 | -            $error_msg = esc_html__('An error occurred and the details for Transaction ID #', | |
| 437 | -                    'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); | |
| 438 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); | |
| 439 | - } | |
| 440 | - } | |
| 441 | - | |
| 442 | - | |
| 443 | - /** | |
| 444 | - * _transaction_legend_items | |
| 445 | - * | |
| 446 | - * @access protected | |
| 447 | - * @return array | |
| 448 | - */ | |
| 449 | - protected function _transaction_legend_items() | |
| 450 | -    { | |
| 451 | -        EE_Registry::instance()->load_helper('MSG_Template'); | |
| 452 | - $items = array(); | |
| 453 | - | |
| 454 | -        if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { | |
| 455 | -            $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); | |
| 456 | -            if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { | |
| 457 | - $items['view_related_messages'] = array( | |
| 458 | - 'class' => $related_for_icon['css_class'], | |
| 459 | - 'desc' => $related_for_icon['label'], | |
| 460 | - ); | |
| 461 | - } | |
| 462 | - } | |
| 463 | - | |
| 464 | - $items = apply_filters( | |
| 465 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', | |
| 466 | - array_merge($items, | |
| 467 | - array( | |
| 468 | - 'view_details' => array( | |
| 469 | - 'class' => 'dashicons dashicons-cart', | |
| 470 | -                        'desc'  => esc_html__('View Transaction Details', 'event_espresso') | |
| 471 | - ), | |
| 472 | - 'view_invoice' => array( | |
| 473 | - 'class' => 'dashicons dashicons-media-spreadsheet', | |
| 474 | -                        'desc'  => esc_html__('View Transaction Invoice', 'event_espresso') | |
| 475 | - ), | |
| 476 | - 'view_receipt' => array( | |
| 477 | - 'class' => 'dashicons dashicons-media-default', | |
| 478 | -                        'desc'  => esc_html__('View Transaction Receipt', 'event_espresso') | |
| 479 | - ), | |
| 480 | - 'view_registration' => array( | |
| 481 | - 'class' => 'dashicons dashicons-clipboard', | |
| 482 | -                        'desc'  => esc_html__('View Registration Details', 'event_espresso') | |
| 483 | - ), | |
| 484 | - 'payment_overview_link' => array( | |
| 485 | - 'class' => 'dashicons dashicons-money', | |
| 486 | -                        'desc' => esc_html__('Make Payment on Frontend', 'event_espresso') | |
| 487 | - ) | |
| 488 | - ) | |
| 489 | - ) | |
| 490 | - ); | |
| 491 | - | |
| 492 | -        if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', | |
| 493 | - 'espresso_transactions_send_payment_reminder') | |
| 494 | -        ) { | |
| 495 | -            if (EEH_MSG_Template::is_mt_active('payment_reminder')) { | |
| 496 | - $items['send_payment_reminder'] = array( | |
| 497 | - 'class' => 'dashicons dashicons-email-alt', | |
| 498 | -                    'desc'  => esc_html__('Send Payment Reminder', 'event_espresso') | |
| 499 | - ); | |
| 500 | -            } else { | |
| 501 | - $items['blank*'] = array( | |
| 502 | - 'class' => '', | |
| 503 | - 'desc' => '' | |
| 504 | - ); | |
| 505 | - } | |
| 506 | -        } else { | |
| 507 | - $items['blank*'] = array( | |
| 508 | - 'class' => '', | |
| 509 | - 'desc' => '' | |
| 510 | - ); | |
| 511 | - } | |
| 512 | - $more_items = apply_filters( | |
| 513 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', | |
| 514 | - array( | |
| 515 | - 'overpaid' => array( | |
| 516 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, | |
| 517 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence') | |
| 518 | - ), | |
| 519 | - 'complete' => array( | |
| 520 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, | |
| 521 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence') | |
| 522 | - ), | |
| 523 | - 'incomplete' => array( | |
| 524 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, | |
| 525 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence') | |
| 526 | - ), | |
| 527 | - 'abandoned' => array( | |
| 528 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, | |
| 529 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence') | |
| 530 | - ), | |
| 531 | - 'failed' => array( | |
| 532 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, | |
| 533 | - 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence') | |
| 534 | - ) | |
| 535 | - ) | |
| 536 | - ); | |
| 537 | - | |
| 538 | - return array_merge($items, $more_items); | |
| 539 | - } | |
| 540 | - | |
| 541 | - | |
| 542 | - /** | |
| 543 | - * _transactions_overview_list_table | |
| 544 | - * | |
| 545 | - * @access protected | |
| 546 | - * @return void | |
| 547 | - */ | |
| 548 | - protected function _transactions_overview_list_table() | |
| 549 | -    { | |
| 550 | -        $this->_admin_page_title                   = esc_html__('Transactions', 'event_espresso'); | |
| 551 | - $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; | |
| 552 | -        $this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', | |
| 553 | - 'event_espresso'), '<h3>', | |
| 554 | -            '<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), | |
| 555 | -                EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', | |
| 556 | -                'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; | |
| 557 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); | |
| 558 | - $this->display_admin_list_table_page_with_no_sidebar(); | |
| 559 | - } | |
| 560 | - | |
| 561 | - | |
| 562 | - /** | |
| 563 | - * _transaction_details | |
| 564 | - * generates HTML for the View Transaction Details Admin page | |
| 565 | - * | |
| 566 | - * @access protected | |
| 567 | - * @return void | |
| 568 | - */ | |
| 569 | - protected function _transaction_details() | |
| 570 | -    { | |
| 571 | -        do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); | |
| 572 | - | |
| 573 | - $this->_set_transaction_status_array(); | |
| 574 | - | |
| 575 | - $this->_template_args = array(); | |
| 576 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; | |
| 577 | - | |
| 578 | - $this->_set_transaction_object(); | |
| 579 | - | |
| 580 | - $primary_registration = $this->_transaction->primary_registration(); | |
| 581 | - $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null; | |
| 582 | - | |
| 583 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); | |
| 584 | -        $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); | |
| 585 | - | |
| 586 | -        $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); | |
| 587 | -        $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); | |
| 588 | - | |
| 589 | -        $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; | |
| 590 | -        $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); | |
| 591 | -        $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); | |
| 592 | - | |
| 593 | -        $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); | |
| 594 | -        $this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid'); | |
| 595 | - | |
| 596 | - if ( | |
| 597 | - $attendee instanceof EE_Attendee | |
| 598 | - && EE_Registry::instance()->CAP->current_user_can( | |
| 599 | - 'ee_send_message', | |
| 600 | - 'espresso_transactions_send_payment_reminder' | |
| 601 | - ) | |
| 602 | -        ) { | |
| 603 | - $this->_template_args['send_payment_reminder_button'] = | |
| 604 | -                EEH_MSG_Template::is_mt_active('payment_reminder') | |
| 605 | -                && $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code | |
| 606 | -                && $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code | |
| 607 | - ? EEH_Template::get_button_or_link( | |
| 608 | - EE_Admin_Page::add_query_args_and_nonce( | |
| 609 | - array( | |
| 610 | - 'action' => 'send_payment_reminder', | |
| 611 | - 'TXN_ID' => $this->_transaction->ID(), | |
| 612 | - 'redirect_to' => 'view_transaction' | |
| 613 | - ), | |
| 614 | - TXN_ADMIN_URL | |
| 615 | - ), | |
| 616 | -                    __(' Send Payment Reminder', 'event_espresso'), | |
| 617 | - 'button secondary-button right', | |
| 618 | - 'dashicons dashicons-email-alt' | |
| 619 | - ) | |
| 620 | - : ''; | |
| 621 | -        } else { | |
| 622 | - $this->_template_args['send_payment_reminder_button'] = ''; | |
| 623 | - } | |
| 624 | - | |
| 625 | -        $amount_due                         = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); | |
| 626 | - $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); | |
| 627 | -        if (EE_Registry::instance()->CFG->currency->sign_b4) { | |
| 628 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; | |
| 629 | -        } else { | |
| 630 | - $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; | |
| 631 | - } | |
| 632 | - $this->_template_args['amount_due_class'] = ''; | |
| 633 | - | |
| 634 | -        if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { | |
| 635 | - // paid in full | |
| 636 | - $this->_template_args['amount_due'] = false; | |
| 637 | -        } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { | |
| 638 | - // overpaid | |
| 639 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; | |
| 640 | -        } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) { | |
| 641 | - // monies owing | |
| 642 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; | |
| 643 | -        } elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) { | |
| 644 | - // no payments made yet | |
| 645 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; | |
| 646 | -        } elseif ($this->_transaction->get('TXN_total') == 0) { | |
| 647 | - // free event | |
| 648 | - $this->_template_args['amount_due'] = false; | |
| 649 | - } | |
| 650 | - | |
| 651 | - $payment_method = $this->_transaction->payment_method(); | |
| 652 | - | |
| 653 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method | |
| 654 | - ? $payment_method->admin_name() | |
| 655 | -            : esc_html__('Unknown', 'event_espresso'); | |
| 656 | - | |
| 657 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; | |
| 658 | - // link back to overview | |
| 659 | - $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER']) | |
| 660 | - ? $_SERVER['HTTP_REFERER'] | |
| 661 | - : TXN_ADMIN_URL; | |
| 662 | - | |
| 663 | - | |
| 664 | - // next link | |
| 665 | - $next_txn = $this->_transaction->next( | |
| 666 | - null, | |
| 667 | -            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), | |
| 668 | - 'TXN_ID' | |
| 669 | - ); | |
| 670 | - $this->_template_args['next_transaction'] = $next_txn | |
| 671 | - ? $this->_next_link( | |
| 672 | - EE_Admin_Page::add_query_args_and_nonce( | |
| 673 | -                    array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), | |
| 674 | - TXN_ADMIN_URL | |
| 675 | - ), | |
| 676 | - 'dashicons dashicons-arrow-right ee-icon-size-22' | |
| 677 | - ) | |
| 678 | - : ''; | |
| 679 | - // previous link | |
| 680 | - $previous_txn = $this->_transaction->previous( | |
| 681 | - null, | |
| 682 | -            array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), | |
| 683 | - 'TXN_ID' | |
| 684 | - ); | |
| 685 | - $this->_template_args['previous_transaction'] = $previous_txn | |
| 686 | - ? $this->_previous_link( | |
| 687 | - EE_Admin_Page::add_query_args_and_nonce( | |
| 688 | -                    array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), | |
| 689 | - TXN_ADMIN_URL | |
| 690 | - ), | |
| 691 | - 'dashicons dashicons-arrow-left ee-icon-size-22' | |
| 692 | - ) | |
| 693 | - : ''; | |
| 694 | - | |
| 695 | - // were we just redirected here after adding a new registration ??? | |
| 696 | - if ( | |
| 697 | - isset( | |
| 698 | - $this->_req_data['redirect_from'], | |
| 699 | - $this->_req_data['EVT_ID'], | |
| 700 | - $this->_req_data['event_name'] | |
| 701 | - ) | |
| 702 | -        ) { | |
| 703 | - if ( | |
| 704 | - EE_Registry::instance()->CAP->current_user_can( | |
| 705 | - 'ee_edit_registrations', | |
| 706 | - 'espresso_registrations_new_registration', | |
| 707 | - $this->_req_data['EVT_ID'] | |
| 708 | - ) | |
| 709 | -            ) { | |
| 710 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; | |
| 711 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( | |
| 712 | - array( | |
| 713 | - 'page' => 'espresso_registrations', | |
| 714 | - 'action' => 'new_registration', | |
| 715 | - 'return' => 'default', | |
| 716 | - 'TXN_ID' => $this->_transaction->ID(), | |
| 717 | - 'event_id' => $this->_req_data['EVT_ID'], | |
| 718 | - ), | |
| 719 | - REG_ADMIN_URL | |
| 720 | - ); | |
| 721 | - $this->_admin_page_title .= '">'; | |
| 722 | - | |
| 723 | - $this->_admin_page_title .= sprintf( | |
| 724 | -                    esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), | |
| 725 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') | |
| 726 | - ); | |
| 727 | - $this->_admin_page_title .= '</a>'; | |
| 728 | - } | |
| 729 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); | |
| 730 | - } | |
| 731 | - // grab messages at the last second | |
| 732 | - $this->_template_args['notices'] = EE_Error::get_notices(); | |
| 733 | - // path to template | |
| 734 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; | |
| 735 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, | |
| 736 | - $this->_template_args, true); | |
| 737 | - | |
| 738 | - // the details template wrapper | |
| 739 | - $this->display_admin_page_with_sidebar(); | |
| 740 | - | |
| 741 | - } | |
| 742 | - | |
| 743 | - | |
| 744 | - /** | |
| 745 | - * _transaction_details_metaboxes | |
| 746 | - * | |
| 747 | - * @access protected | |
| 748 | - * @return void | |
| 749 | - */ | |
| 750 | - protected function _transaction_details_metaboxes() | |
| 751 | -    { | |
| 752 | - | |
| 753 | - $this->_set_transaction_object(); | |
| 754 | - | |
| 755 | -        add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'), | |
| 756 | - array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high'); | |
| 757 | - add_meta_box( | |
| 758 | - 'edit-txn-attendees-mbox', | |
| 759 | -            esc_html__('Attendees Registered in this Transaction', 'event_espresso'), | |
| 760 | - array($this, 'txn_attendees_meta_box'), | |
| 761 | - $this->_wp_page_slug, | |
| 762 | - 'normal', | |
| 763 | - 'high', | |
| 764 | -            array('TXN_ID' => $this->_transaction->ID()) | |
| 765 | - ); | |
| 766 | -        add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'), | |
| 767 | - array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); | |
| 768 | -        add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'), | |
| 769 | - array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); | |
| 770 | - | |
| 771 | - } | |
| 772 | - | |
| 773 | - | |
| 774 | - /** | |
| 775 | - * txn_details_meta_box | |
| 776 | - * generates HTML for the Transaction main meta box | |
| 777 | - * | |
| 778 | - * @access public | |
| 779 | - * @return void | |
| 780 | - */ | |
| 781 | - public function txn_details_meta_box() | |
| 782 | -    { | |
| 783 | - | |
| 784 | - $this->_set_transaction_object(); | |
| 785 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); | |
| 786 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null; | |
| 787 | - | |
| 788 | - //get line table | |
| 789 | - EEH_Autoloader::register_line_item_display_autoloaders(); | |
| 790 | -        $Line_Item_Display                       = new EE_Line_Item_Display('admin_table', | |
| 791 | - 'EE_Admin_Table_Line_Item_Display_Strategy'); | |
| 792 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item()); | |
| 793 | -        $this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')->get('REG_code'); | |
| 794 | - | |
| 795 | - // process taxes | |
| 796 | -        $taxes                         = $this->_transaction->get_many_related('Line_Item', | |
| 797 | -            array(array('LIN_type' => EEM_Line_Item::type_tax))); | |
| 798 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; | |
| 799 | - | |
| 800 | -        $this->_template_args['grand_total']     = EEH_Template::format_currency($this->_transaction->get('TXN_total'), | |
| 801 | - false, false); | |
| 802 | -        $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); | |
| 803 | -        $this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID'); | |
| 30 | + /** | |
| 31 | + * @var EE_Transaction | |
| 32 | + */ | |
| 33 | + private $_transaction; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * @var EE_Session | |
| 37 | + */ | |
| 38 | + private $_session; | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * @var array $_txn_status | |
| 42 | + */ | |
| 43 | + private static $_txn_status; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * @var array $_pay_status | |
| 47 | + */ | |
| 48 | + private static $_pay_status; | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * @var array $_existing_reg_payment_REG_IDs | |
| 52 | + */ | |
| 53 | + protected $_existing_reg_payment_REG_IDs = null; | |
| 54 | + | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * @Constructor | |
| 58 | + * @access public | |
| 59 | + * | |
| 60 | + * @param bool $routing | |
| 61 | + * | |
| 62 | + * @return Transactions_Admin_Page | |
| 63 | + */ | |
| 64 | + public function __construct($routing = true) | |
| 65 | +	{ | |
| 66 | + parent::__construct($routing); | |
| 67 | + } | |
| 68 | + | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * _init_page_props | |
| 72 | + * @return void | |
| 73 | + */ | |
| 74 | + protected function _init_page_props() | |
| 75 | +	{ | |
| 76 | + $this->page_slug = TXN_PG_SLUG; | |
| 77 | +		$this->page_label       = esc_html__('Transactions', 'event_espresso'); | |
| 78 | + $this->_admin_base_url = TXN_ADMIN_URL; | |
| 79 | + $this->_admin_base_path = TXN_ADMIN; | |
| 80 | + } | |
| 81 | + | |
| 82 | + | |
| 83 | + /** | |
| 84 | + * _ajax_hooks | |
| 85 | + * @return void | |
| 86 | + */ | |
| 87 | + protected function _ajax_hooks() | |
| 88 | +	{ | |
| 89 | +		add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); | |
| 90 | +		add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); | |
| 91 | +		add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); | |
| 92 | + } | |
| 93 | + | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * _define_page_props | |
| 97 | + * @return void | |
| 98 | + */ | |
| 99 | + protected function _define_page_props() | |
| 100 | +	{ | |
| 101 | + $this->_admin_page_title = $this->page_label; | |
| 102 | + $this->_labels = array( | |
| 103 | + 'buttons' => array( | |
| 104 | +				'add'    => esc_html__('Add New Transaction', 'event_espresso'), | |
| 105 | +				'edit'   => esc_html__('Edit Transaction', 'event_espresso'), | |
| 106 | +				'delete' => esc_html__('Delete Transaction', 'event_espresso'), | |
| 107 | + ) | |
| 108 | + ); | |
| 109 | + } | |
| 110 | + | |
| 111 | + | |
| 112 | + /** | |
| 113 | + * grab url requests and route them | |
| 114 | + * @access private | |
| 115 | + * @return void | |
| 116 | + */ | |
| 117 | + public function _set_page_routes() | |
| 118 | +	{ | |
| 119 | + | |
| 120 | + $this->_set_transaction_status_array(); | |
| 121 | + | |
| 122 | + $txn_id = ! empty($this->_req_data['TXN_ID']) && ! is_array($this->_req_data['TXN_ID']) ? $this->_req_data['TXN_ID'] : 0; | |
| 123 | + | |
| 124 | + $this->_page_routes = array( | |
| 125 | + | |
| 126 | + 'default' => array( | |
| 127 | + 'func' => '_transactions_overview_list_table', | |
| 128 | + 'capability' => 'ee_read_transactions' | |
| 129 | + ), | |
| 130 | + | |
| 131 | + 'view_transaction' => array( | |
| 132 | + 'func' => '_transaction_details', | |
| 133 | + 'capability' => 'ee_read_transaction', | |
| 134 | + 'obj_id' => $txn_id | |
| 135 | + ), | |
| 136 | + | |
| 137 | + 'send_payment_reminder' => array( | |
| 138 | + 'func' => '_send_payment_reminder', | |
| 139 | + 'noheader' => true, | |
| 140 | + 'capability' => 'ee_send_message' | |
| 141 | + ), | |
| 142 | + | |
| 143 | + 'espresso_apply_payment' => array( | |
| 144 | + 'func' => 'apply_payments_or_refunds', | |
| 145 | + 'noheader' => true, | |
| 146 | + 'capability' => 'ee_edit_payments' | |
| 147 | + ), | |
| 148 | + | |
| 149 | + 'espresso_apply_refund' => array( | |
| 150 | + 'func' => 'apply_payments_or_refunds', | |
| 151 | + 'noheader' => true, | |
| 152 | + 'capability' => 'ee_edit_payments' | |
| 153 | + ), | |
| 154 | + | |
| 155 | + 'espresso_delete_payment' => array( | |
| 156 | + 'func' => 'delete_payment', | |
| 157 | + 'noheader' => true, | |
| 158 | + 'capability' => 'ee_delete_payments' | |
| 159 | + ), | |
| 160 | + | |
| 161 | + ); | |
| 162 | + | |
| 163 | + } | |
| 164 | + | |
| 165 | + | |
| 166 | + protected function _set_page_config() | |
| 167 | +	{ | |
| 168 | + $this->_page_config = array( | |
| 169 | + 'default' => array( | |
| 170 | + 'nav' => array( | |
| 171 | +					'label' => esc_html__('Overview', 'event_espresso'), | |
| 172 | + 'order' => 10 | |
| 173 | + ), | |
| 174 | + 'list_table' => 'EE_Admin_Transactions_List_Table', | |
| 175 | + 'help_tabs' => array( | |
| 176 | + 'transactions_overview_help_tab' => array( | |
| 177 | +						'title'    => esc_html__('Transactions Overview', 'event_espresso'), | |
| 178 | + 'filename' => 'transactions_overview' | |
| 179 | + ), | |
| 180 | + 'transactions_overview_table_column_headings_help_tab' => array( | |
| 181 | +						'title'    => esc_html__('Transactions Table Column Headings', 'event_espresso'), | |
| 182 | + 'filename' => 'transactions_overview_table_column_headings' | |
| 183 | + ), | |
| 184 | + 'transactions_overview_views_filters_help_tab' => array( | |
| 185 | +						'title'    => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), | |
| 186 | + 'filename' => 'transactions_overview_views_filters_search' | |
| 187 | + ), | |
| 188 | + ), | |
| 189 | +				'help_tour'     => array('Transactions_Overview_Help_Tour'), | |
| 190 | + /** | |
| 191 | + * commented out because currently we are not displaying tips for transaction list table status but this | |
| 192 | + * may change in a later iteration so want to keep the code for then. | |
| 193 | + */ | |
| 194 | + //'qtips' => array( 'Transactions_List_Table_Tips' ), | |
| 195 | + 'require_nonce' => false | |
| 196 | + ), | |
| 197 | + 'view_transaction' => array( | |
| 198 | + 'nav' => array( | |
| 199 | +					'label'      => esc_html__('View Transaction', 'event_espresso'), | |
| 200 | + 'order' => 5, | |
| 201 | +					'url'        => isset($this->_req_data['TXN_ID']) ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), | |
| 202 | + $this->_current_page_view_url) : $this->_admin_base_url, | |
| 203 | + 'persistent' => false | |
| 204 | + ), | |
| 205 | + 'help_tabs' => array( | |
| 206 | + 'transactions_view_transaction_help_tab' => array( | |
| 207 | +						'title'    => esc_html__('View Transaction', 'event_espresso'), | |
| 208 | + 'filename' => 'transactions_view_transaction' | |
| 209 | + ), | |
| 210 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( | |
| 211 | +						'title'    => esc_html__('Transaction Details Table', 'event_espresso'), | |
| 212 | + 'filename' => 'transactions_view_transaction_transaction_details_table' | |
| 213 | + ), | |
| 214 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( | |
| 215 | +						'title'    => esc_html__('Attendees Registered', 'event_espresso'), | |
| 216 | + 'filename' => 'transactions_view_transaction_attendees_registered' | |
| 217 | + ), | |
| 218 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( | |
| 219 | +						'title'    => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), | |
| 220 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information' | |
| 221 | + ), | |
| 222 | + ), | |
| 223 | +				'qtips'     => array('Transaction_Details_Tips'), | |
| 224 | +				'help_tour' => array('Transaction_Details_Help_Tour'), | |
| 225 | +				'metaboxes' => array('_transaction_details_metaboxes'), | |
| 226 | + | |
| 227 | + 'require_nonce' => false | |
| 228 | + ) | |
| 229 | + ); | |
| 230 | + } | |
| 231 | + | |
| 232 | + | |
| 233 | + /** | |
| 234 | + * The below methods aren't used by this class currently | |
| 235 | + */ | |
| 236 | + protected function _add_screen_options() | |
| 237 | +	{ | |
| 238 | + } | |
| 239 | + | |
| 240 | + protected function _add_feature_pointers() | |
| 241 | +	{ | |
| 242 | + } | |
| 243 | + | |
| 244 | + public function admin_init() | |
| 245 | +	{ | |
| 246 | + // IF a registration was JUST added via the admin... | |
| 247 | + if ( | |
| 248 | + isset( | |
| 249 | + $this->_req_data['redirect_from'], | |
| 250 | + $this->_req_data['EVT_ID'], | |
| 251 | + $this->_req_data['event_name'] | |
| 252 | + ) | |
| 253 | +		) { | |
| 254 | + // then set a cookie so that we can block any attempts to use | |
| 255 | + // the back button as a way to enter another registration. | |
| 256 | +			setcookie('ee_registration_added', $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/'); | |
| 257 | + // and update the global | |
| 258 | + $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; | |
| 259 | + } | |
| 260 | +		EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__('An error occurred! Your request may have been processed, but a valid response from the server was not received. Please refresh the page and try again.', | |
| 261 | + 'event_espresso'); | |
| 262 | +		EE_Registry::$i18n_js_strings['error_occurred']          = esc_html__('An error occurred! Please refresh the page and try again.', | |
| 263 | + 'event_espresso'); | |
| 264 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; | |
| 265 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; | |
| 266 | +		EE_Registry::$i18n_js_strings['payments_total']          = esc_html__('Payments Total', 'event_espresso'); | |
| 267 | +		EE_Registry::$i18n_js_strings['transaction_overpaid']    = esc_html__('This transaction has been overpaid ! Payments Total', | |
| 268 | + 'event_espresso'); | |
| 269 | + } | |
| 270 | + | |
| 271 | + public function admin_notices() | |
| 272 | +	{ | |
| 273 | + } | |
| 274 | + | |
| 275 | + public function admin_footer_scripts() | |
| 276 | +	{ | |
| 277 | + } | |
| 278 | + | |
| 279 | + | |
| 280 | + /** | |
| 281 | + * _set_transaction_status_array | |
| 282 | + * sets list of transaction statuses | |
| 283 | + * | |
| 284 | + * @access private | |
| 285 | + * @return void | |
| 286 | + */ | |
| 287 | + private function _set_transaction_status_array() | |
| 288 | +	{ | |
| 289 | + self::$_txn_status = EEM_Transaction::instance()->status_array(true); | |
| 290 | + } | |
| 291 | + | |
| 292 | + | |
| 293 | + /** | |
| 294 | + * get_transaction_status_array | |
| 295 | + * return the transaction status array for wp_list_table | |
| 296 | + * | |
| 297 | + * @access public | |
| 298 | + * @return array | |
| 299 | + */ | |
| 300 | + public function get_transaction_status_array() | |
| 301 | +	{ | |
| 302 | + return self::$_txn_status; | |
| 303 | + } | |
| 304 | + | |
| 305 | + | |
| 306 | + /** | |
| 307 | + * get list of payment statuses | |
| 308 | + * | |
| 309 | + * @access private | |
| 310 | + * @return void | |
| 311 | + */ | |
| 312 | + private function _get_payment_status_array() | |
| 313 | +	{ | |
| 314 | + self::$_pay_status = EEM_Payment::instance()->status_array(true); | |
| 315 | + $this->_template_args['payment_status'] = self::$_pay_status; | |
| 316 | + | |
| 317 | + } | |
| 318 | + | |
| 319 | + | |
| 320 | + /** | |
| 321 | + * _add_screen_options_default | |
| 322 | + * | |
| 323 | + * @access protected | |
| 324 | + * @return void | |
| 325 | + */ | |
| 326 | + protected function _add_screen_options_default() | |
| 327 | +	{ | |
| 328 | + $this->_per_page_screen_option(); | |
| 329 | + } | |
| 330 | + | |
| 331 | + | |
| 332 | + /** | |
| 333 | + * load_scripts_styles | |
| 334 | + * | |
| 335 | + * @access public | |
| 336 | + * @return void | |
| 337 | + */ | |
| 338 | + public function load_scripts_styles() | |
| 339 | +	{ | |
| 340 | + //enqueue style | |
| 341 | +		wp_register_style('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.css', array(), | |
| 342 | + EVENT_ESPRESSO_VERSION); | |
| 343 | +		wp_enqueue_style('espresso_txn'); | |
| 344 | + //scripts | |
| 345 | +		wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( | |
| 346 | + 'ee_admin_js', | |
| 347 | + 'ee-datepicker', | |
| 348 | + 'jquery-ui-datepicker', | |
| 349 | + 'jquery-ui-draggable', | |
| 350 | + 'ee-dialog', | |
| 351 | + 'ee-accounting', | |
| 352 | + 'ee-serialize-full-array' | |
| 353 | + ), EVENT_ESPRESSO_VERSION, true); | |
| 354 | +		wp_enqueue_script('espresso_txn'); | |
| 355 | + | |
| 356 | + } | |
| 357 | + | |
| 358 | + | |
| 359 | + /** | |
| 360 | + * load_scripts_styles_view_transaction | |
| 361 | + * | |
| 362 | + * @access public | |
| 363 | + * @return void | |
| 364 | + */ | |
| 365 | + public function load_scripts_styles_view_transaction() | |
| 366 | +	{ | |
| 367 | + //styles | |
| 368 | +		wp_enqueue_style('espresso-ui-theme'); | |
| 369 | + } | |
| 370 | + | |
| 371 | + | |
| 372 | + /** | |
| 373 | + * load_scripts_styles_default | |
| 374 | + * | |
| 375 | + * @access public | |
| 376 | + * @return void | |
| 377 | + */ | |
| 378 | + public function load_scripts_styles_default() | |
| 379 | +	{ | |
| 380 | + //styles | |
| 381 | +		wp_enqueue_style('espresso-ui-theme'); | |
| 382 | + } | |
| 383 | + | |
| 384 | + | |
| 385 | + /** | |
| 386 | + * _set_list_table_views_default | |
| 387 | + * | |
| 388 | + * @access protected | |
| 389 | + * @return void | |
| 390 | + */ | |
| 391 | + protected function _set_list_table_views_default() | |
| 392 | +	{ | |
| 393 | + $this->_views = array( | |
| 394 | + 'all' => array( | |
| 395 | + 'slug' => 'all', | |
| 396 | +				'label' => esc_html__('View All Transactions', 'event_espresso'), | |
| 397 | + 'count' => 0 | |
| 398 | + ), | |
| 399 | + 'abandoned' => array( | |
| 400 | + 'slug' => 'abandoned', | |
| 401 | +				'label' => esc_html__('Abandoned Transactions', 'event_espresso'), | |
| 402 | + 'count' => 0 | |
| 403 | + ), | |
| 404 | + 'failed' => array( | |
| 405 | + 'slug' => 'failed', | |
| 406 | +				'label' => esc_html__('Failed Transactions', 'event_espresso'), | |
| 407 | + 'count' => 0 | |
| 408 | + ) | |
| 409 | + ); | |
| 410 | + } | |
| 411 | + | |
| 412 | + | |
| 413 | + /** | |
| 414 | + * _set_transaction_object | |
| 415 | + * This sets the _transaction property for the transaction details screen | |
| 416 | + * | |
| 417 | + * @access private | |
| 418 | + * @return void | |
| 419 | + */ | |
| 420 | + private function _set_transaction_object() | |
| 421 | +	{ | |
| 422 | +		if (is_object($this->_transaction)) { | |
| 423 | + return; | |
| 424 | + } //get out we've already set the object | |
| 425 | + | |
| 426 | + $TXN = EEM_Transaction::instance(); | |
| 427 | + | |
| 428 | + $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; | |
| 429 | + | |
| 430 | + //get transaction object | |
| 431 | + $this->_transaction = $TXN->get_one_by_ID($TXN_ID); | |
| 432 | +		$this->_session     = ! empty($this->_transaction) ? $this->_transaction->get('TXN_session_data') : null; | |
| 433 | + $this->_transaction->verify_abandoned_transaction_status(); | |
| 434 | + | |
| 435 | +		if (empty($this->_transaction)) { | |
| 436 | +			$error_msg = esc_html__('An error occurred and the details for Transaction ID #', | |
| 437 | +					'event_espresso') . $TXN_ID . esc_html__(' could not be retrieved.', 'event_espresso'); | |
| 438 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); | |
| 439 | + } | |
| 440 | + } | |
| 441 | + | |
| 442 | + | |
| 443 | + /** | |
| 444 | + * _transaction_legend_items | |
| 445 | + * | |
| 446 | + * @access protected | |
| 447 | + * @return array | |
| 448 | + */ | |
| 449 | + protected function _transaction_legend_items() | |
| 450 | +	{ | |
| 451 | +		EE_Registry::instance()->load_helper('MSG_Template'); | |
| 452 | + $items = array(); | |
| 453 | + | |
| 454 | +		if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { | |
| 455 | +			$related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); | |
| 456 | +			if (isset($related_for_icon['css_class']) && isset($related_for_icon['label'])) { | |
| 457 | + $items['view_related_messages'] = array( | |
| 458 | + 'class' => $related_for_icon['css_class'], | |
| 459 | + 'desc' => $related_for_icon['label'], | |
| 460 | + ); | |
| 461 | + } | |
| 462 | + } | |
| 463 | + | |
| 464 | + $items = apply_filters( | |
| 465 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', | |
| 466 | + array_merge($items, | |
| 467 | + array( | |
| 468 | + 'view_details' => array( | |
| 469 | + 'class' => 'dashicons dashicons-cart', | |
| 470 | +						'desc'  => esc_html__('View Transaction Details', 'event_espresso') | |
| 471 | + ), | |
| 472 | + 'view_invoice' => array( | |
| 473 | + 'class' => 'dashicons dashicons-media-spreadsheet', | |
| 474 | +						'desc'  => esc_html__('View Transaction Invoice', 'event_espresso') | |
| 475 | + ), | |
| 476 | + 'view_receipt' => array( | |
| 477 | + 'class' => 'dashicons dashicons-media-default', | |
| 478 | +						'desc'  => esc_html__('View Transaction Receipt', 'event_espresso') | |
| 479 | + ), | |
| 480 | + 'view_registration' => array( | |
| 481 | + 'class' => 'dashicons dashicons-clipboard', | |
| 482 | +						'desc'  => esc_html__('View Registration Details', 'event_espresso') | |
| 483 | + ), | |
| 484 | + 'payment_overview_link' => array( | |
| 485 | + 'class' => 'dashicons dashicons-money', | |
| 486 | +						'desc' => esc_html__('Make Payment on Frontend', 'event_espresso') | |
| 487 | + ) | |
| 488 | + ) | |
| 489 | + ) | |
| 490 | + ); | |
| 491 | + | |
| 492 | +		if (EE_Registry::instance()->CAP->current_user_can('ee_send_message', | |
| 493 | + 'espresso_transactions_send_payment_reminder') | |
| 494 | +		) { | |
| 495 | +			if (EEH_MSG_Template::is_mt_active('payment_reminder')) { | |
| 496 | + $items['send_payment_reminder'] = array( | |
| 497 | + 'class' => 'dashicons dashicons-email-alt', | |
| 498 | +					'desc'  => esc_html__('Send Payment Reminder', 'event_espresso') | |
| 499 | + ); | |
| 500 | +			} else { | |
| 501 | + $items['blank*'] = array( | |
| 502 | + 'class' => '', | |
| 503 | + 'desc' => '' | |
| 504 | + ); | |
| 505 | + } | |
| 506 | +		} else { | |
| 507 | + $items['blank*'] = array( | |
| 508 | + 'class' => '', | |
| 509 | + 'desc' => '' | |
| 510 | + ); | |
| 511 | + } | |
| 512 | + $more_items = apply_filters( | |
| 513 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', | |
| 514 | + array( | |
| 515 | + 'overpaid' => array( | |
| 516 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, | |
| 517 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::overpaid_status_code, false, 'sentence') | |
| 518 | + ), | |
| 519 | + 'complete' => array( | |
| 520 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, | |
| 521 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::complete_status_code, false, 'sentence') | |
| 522 | + ), | |
| 523 | + 'incomplete' => array( | |
| 524 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, | |
| 525 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::incomplete_status_code, false, 'sentence') | |
| 526 | + ), | |
| 527 | + 'abandoned' => array( | |
| 528 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, | |
| 529 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::abandoned_status_code, false, 'sentence') | |
| 530 | + ), | |
| 531 | + 'failed' => array( | |
| 532 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, | |
| 533 | + 'desc' => EEH_Template::pretty_status(EEM_Transaction::failed_status_code, false, 'sentence') | |
| 534 | + ) | |
| 535 | + ) | |
| 536 | + ); | |
| 537 | + | |
| 538 | + return array_merge($items, $more_items); | |
| 539 | + } | |
| 540 | + | |
| 541 | + | |
| 542 | + /** | |
| 543 | + * _transactions_overview_list_table | |
| 544 | + * | |
| 545 | + * @access protected | |
| 546 | + * @return void | |
| 547 | + */ | |
| 548 | + protected function _transactions_overview_list_table() | |
| 549 | +	{ | |
| 550 | +		$this->_admin_page_title                   = esc_html__('Transactions', 'event_espresso'); | |
| 551 | + $event = isset($this->_req_data['EVT_ID']) ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) : null; | |
| 552 | +		$this->_template_args['admin_page_header'] = $event instanceof EE_Event ? sprintf(esc_html__('%sViewing Transactions for the Event: %s%s', | |
| 553 | + 'event_espresso'), '<h3>', | |
| 554 | +			'<a href="' . EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $event->ID()), | |
| 555 | +				EVENTS_ADMIN_URL) . '" title="' . esc_attr__('Click to Edit event', | |
| 556 | +				'event_espresso') . '">' . $event->get('EVT_name') . '</a>', '</h3>') : ''; | |
| 557 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); | |
| 558 | + $this->display_admin_list_table_page_with_no_sidebar(); | |
| 559 | + } | |
| 560 | + | |
| 561 | + | |
| 562 | + /** | |
| 563 | + * _transaction_details | |
| 564 | + * generates HTML for the View Transaction Details Admin page | |
| 565 | + * | |
| 566 | + * @access protected | |
| 567 | + * @return void | |
| 568 | + */ | |
| 569 | + protected function _transaction_details() | |
| 570 | +	{ | |
| 571 | +		do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); | |
| 572 | + | |
| 573 | + $this->_set_transaction_status_array(); | |
| 574 | + | |
| 575 | + $this->_template_args = array(); | |
| 576 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; | |
| 577 | + | |
| 578 | + $this->_set_transaction_object(); | |
| 579 | + | |
| 580 | + $primary_registration = $this->_transaction->primary_registration(); | |
| 581 | + $attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : null; | |
| 582 | + | |
| 583 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); | |
| 584 | +		$this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); | |
| 585 | + | |
| 586 | +		$this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); | |
| 587 | +		$this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); | |
| 588 | + | |
| 589 | +		$this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; | |
| 590 | +		$this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); | |
| 591 | +		$this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); | |
| 592 | + | |
| 593 | +		$this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); | |
| 594 | +		$this->_template_args['total_paid']  = $this->_transaction->get('TXN_paid'); | |
| 595 | + | |
| 596 | + if ( | |
| 597 | + $attendee instanceof EE_Attendee | |
| 598 | + && EE_Registry::instance()->CAP->current_user_can( | |
| 599 | + 'ee_send_message', | |
| 600 | + 'espresso_transactions_send_payment_reminder' | |
| 601 | + ) | |
| 602 | +		) { | |
| 603 | + $this->_template_args['send_payment_reminder_button'] = | |
| 604 | +				EEH_MSG_Template::is_mt_active('payment_reminder') | |
| 605 | +				&& $this->_transaction->get('STS_ID') != EEM_Transaction::complete_status_code | |
| 606 | +				&& $this->_transaction->get('STS_ID') != EEM_Transaction::overpaid_status_code | |
| 607 | + ? EEH_Template::get_button_or_link( | |
| 608 | + EE_Admin_Page::add_query_args_and_nonce( | |
| 609 | + array( | |
| 610 | + 'action' => 'send_payment_reminder', | |
| 611 | + 'TXN_ID' => $this->_transaction->ID(), | |
| 612 | + 'redirect_to' => 'view_transaction' | |
| 613 | + ), | |
| 614 | + TXN_ADMIN_URL | |
| 615 | + ), | |
| 616 | +					__(' Send Payment Reminder', 'event_espresso'), | |
| 617 | + 'button secondary-button right', | |
| 618 | + 'dashicons dashicons-email-alt' | |
| 619 | + ) | |
| 620 | + : ''; | |
| 621 | +		} else { | |
| 622 | + $this->_template_args['send_payment_reminder_button'] = ''; | |
| 623 | + } | |
| 624 | + | |
| 625 | +		$amount_due                         = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); | |
| 626 | + $this->_template_args['amount_due'] = EEH_Template::format_currency($amount_due, true); | |
| 627 | +		if (EE_Registry::instance()->CFG->currency->sign_b4) { | |
| 628 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign . $this->_template_args['amount_due']; | |
| 629 | +		} else { | |
| 630 | + $this->_template_args['amount_due'] = $this->_template_args['amount_due'] . EE_Registry::instance()->CFG->currency->sign; | |
| 631 | + } | |
| 632 | + $this->_template_args['amount_due_class'] = ''; | |
| 633 | + | |
| 634 | +		if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { | |
| 635 | + // paid in full | |
| 636 | + $this->_template_args['amount_due'] = false; | |
| 637 | +		} elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { | |
| 638 | + // overpaid | |
| 639 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; | |
| 640 | +		} elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') > 0)) { | |
| 641 | + // monies owing | |
| 642 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; | |
| 643 | +		} elseif (($this->_transaction->get('TXN_total') > 0) && ($this->_transaction->get('TXN_paid') == 0)) { | |
| 644 | + // no payments made yet | |
| 645 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; | |
| 646 | +		} elseif ($this->_transaction->get('TXN_total') == 0) { | |
| 647 | + // free event | |
| 648 | + $this->_template_args['amount_due'] = false; | |
| 649 | + } | |
| 650 | + | |
| 651 | + $payment_method = $this->_transaction->payment_method(); | |
| 652 | + | |
| 653 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method | |
| 654 | + ? $payment_method->admin_name() | |
| 655 | +			: esc_html__('Unknown', 'event_espresso'); | |
| 656 | + | |
| 657 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; | |
| 658 | + // link back to overview | |
| 659 | + $this->_template_args['txn_overview_url'] = ! empty ($_SERVER['HTTP_REFERER']) | |
| 660 | + ? $_SERVER['HTTP_REFERER'] | |
| 661 | + : TXN_ADMIN_URL; | |
| 662 | + | |
| 663 | + | |
| 664 | + // next link | |
| 665 | + $next_txn = $this->_transaction->next( | |
| 666 | + null, | |
| 667 | +			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), | |
| 668 | + 'TXN_ID' | |
| 669 | + ); | |
| 670 | + $this->_template_args['next_transaction'] = $next_txn | |
| 671 | + ? $this->_next_link( | |
| 672 | + EE_Admin_Page::add_query_args_and_nonce( | |
| 673 | +					array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), | |
| 674 | + TXN_ADMIN_URL | |
| 675 | + ), | |
| 676 | + 'dashicons dashicons-arrow-right ee-icon-size-22' | |
| 677 | + ) | |
| 678 | + : ''; | |
| 679 | + // previous link | |
| 680 | + $previous_txn = $this->_transaction->previous( | |
| 681 | + null, | |
| 682 | +			array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), | |
| 683 | + 'TXN_ID' | |
| 684 | + ); | |
| 685 | + $this->_template_args['previous_transaction'] = $previous_txn | |
| 686 | + ? $this->_previous_link( | |
| 687 | + EE_Admin_Page::add_query_args_and_nonce( | |
| 688 | +					array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), | |
| 689 | + TXN_ADMIN_URL | |
| 690 | + ), | |
| 691 | + 'dashicons dashicons-arrow-left ee-icon-size-22' | |
| 692 | + ) | |
| 693 | + : ''; | |
| 694 | + | |
| 695 | + // were we just redirected here after adding a new registration ??? | |
| 696 | + if ( | |
| 697 | + isset( | |
| 698 | + $this->_req_data['redirect_from'], | |
| 699 | + $this->_req_data['EVT_ID'], | |
| 700 | + $this->_req_data['event_name'] | |
| 701 | + ) | |
| 702 | +		) { | |
| 703 | + if ( | |
| 704 | + EE_Registry::instance()->CAP->current_user_can( | |
| 705 | + 'ee_edit_registrations', | |
| 706 | + 'espresso_registrations_new_registration', | |
| 707 | + $this->_req_data['EVT_ID'] | |
| 708 | + ) | |
| 709 | +			) { | |
| 710 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; | |
| 711 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( | |
| 712 | + array( | |
| 713 | + 'page' => 'espresso_registrations', | |
| 714 | + 'action' => 'new_registration', | |
| 715 | + 'return' => 'default', | |
| 716 | + 'TXN_ID' => $this->_transaction->ID(), | |
| 717 | + 'event_id' => $this->_req_data['EVT_ID'], | |
| 718 | + ), | |
| 719 | + REG_ADMIN_URL | |
| 720 | + ); | |
| 721 | + $this->_admin_page_title .= '">'; | |
| 722 | + | |
| 723 | + $this->_admin_page_title .= sprintf( | |
| 724 | +					esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), | |
| 725 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') | |
| 726 | + ); | |
| 727 | + $this->_admin_page_title .= '</a>'; | |
| 728 | + } | |
| 729 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); | |
| 730 | + } | |
| 731 | + // grab messages at the last second | |
| 732 | + $this->_template_args['notices'] = EE_Error::get_notices(); | |
| 733 | + // path to template | |
| 734 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; | |
| 735 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template($template_path, | |
| 736 | + $this->_template_args, true); | |
| 737 | + | |
| 738 | + // the details template wrapper | |
| 739 | + $this->display_admin_page_with_sidebar(); | |
| 740 | + | |
| 741 | + } | |
| 742 | + | |
| 743 | + | |
| 744 | + /** | |
| 745 | + * _transaction_details_metaboxes | |
| 746 | + * | |
| 747 | + * @access protected | |
| 748 | + * @return void | |
| 749 | + */ | |
| 750 | + protected function _transaction_details_metaboxes() | |
| 751 | +	{ | |
| 752 | + | |
| 753 | + $this->_set_transaction_object(); | |
| 754 | + | |
| 755 | +		add_meta_box('edit-txn-details-mbox', esc_html__('Transaction Details', 'event_espresso'), | |
| 756 | + array($this, 'txn_details_meta_box'), $this->_wp_page_slug, 'normal', 'high'); | |
| 757 | + add_meta_box( | |
| 758 | + 'edit-txn-attendees-mbox', | |
| 759 | +			esc_html__('Attendees Registered in this Transaction', 'event_espresso'), | |
| 760 | + array($this, 'txn_attendees_meta_box'), | |
| 761 | + $this->_wp_page_slug, | |
| 762 | + 'normal', | |
| 763 | + 'high', | |
| 764 | +			array('TXN_ID' => $this->_transaction->ID()) | |
| 765 | + ); | |
| 766 | +		add_meta_box('edit-txn-registrant-mbox', esc_html__('Primary Contact', 'event_espresso'), | |
| 767 | + array($this, 'txn_registrant_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); | |
| 768 | +		add_meta_box('edit-txn-billing-info-mbox', esc_html__('Billing Information', 'event_espresso'), | |
| 769 | + array($this, 'txn_billing_info_side_meta_box'), $this->_wp_page_slug, 'side', 'high'); | |
| 770 | + | |
| 771 | + } | |
| 772 | + | |
| 773 | + | |
| 774 | + /** | |
| 775 | + * txn_details_meta_box | |
| 776 | + * generates HTML for the Transaction main meta box | |
| 777 | + * | |
| 778 | + * @access public | |
| 779 | + * @return void | |
| 780 | + */ | |
| 781 | + public function txn_details_meta_box() | |
| 782 | +	{ | |
| 783 | + | |
| 784 | + $this->_set_transaction_object(); | |
| 785 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); | |
| 786 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->attendee() : null; | |
| 787 | + | |
| 788 | + //get line table | |
| 789 | + EEH_Autoloader::register_line_item_display_autoloaders(); | |
| 790 | +		$Line_Item_Display                       = new EE_Line_Item_Display('admin_table', | |
| 791 | + 'EE_Admin_Table_Line_Item_Display_Strategy'); | |
| 792 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item($this->_transaction->total_line_item()); | |
| 793 | +		$this->_template_args['REG_code']        = $this->_transaction->get_first_related('Registration')->get('REG_code'); | |
| 794 | + | |
| 795 | + // process taxes | |
| 796 | +		$taxes                         = $this->_transaction->get_many_related('Line_Item', | |
| 797 | +			array(array('LIN_type' => EEM_Line_Item::type_tax))); | |
| 798 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; | |
| 799 | + | |
| 800 | +		$this->_template_args['grand_total']     = EEH_Template::format_currency($this->_transaction->get('TXN_total'), | |
| 801 | + false, false); | |
| 802 | +		$this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); | |
| 803 | +		$this->_template_args['TXN_status']      = $this->_transaction->get('STS_ID'); | |
| 804 | 804 | |
| 805 | 805 |  //		$txn_status_class = 'status-' . $this->_transaction->get('STS_ID'); | 
| 806 | 806 | |
| 807 | - // process payment details | |
| 808 | -        $payments = $this->_transaction->get_many_related('Payment'); | |
| 809 | -        if ( ! empty($payments)) { | |
| 810 | - $this->_template_args['payments'] = $payments; | |
| 811 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); | |
| 812 | -        } else { | |
| 813 | - $this->_template_args['payments'] = false; | |
| 814 | - $this->_template_args['existing_reg_payments'] = array(); | |
| 815 | - } | |
| 816 | - | |
| 817 | -        $this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); | |
| 818 | -        $this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'), | |
| 819 | - TXN_ADMIN_URL); | |
| 820 | - | |
| 821 | -        if (isset($txn_details['invoice_number'])) { | |
| 822 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; | |
| 823 | -            $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number', | |
| 824 | - 'event_espresso'); | |
| 825 | - } | |
| 826 | - | |
| 827 | -        $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session'); | |
| 828 | -        $this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session', | |
| 829 | - 'event_espresso'); | |
| 830 | - | |
| 831 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : ''; | |
| 832 | -        $this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP', | |
| 833 | - 'event_espresso'); | |
| 834 | - | |
| 835 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : ''; | |
| 836 | -        $this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent', | |
| 837 | - 'event_espresso'); | |
| 838 | - | |
| 839 | - $reg_steps = '<ul>'; | |
| 840 | -        foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { | |
| 841 | -            if ($reg_step_status === true) { | |
| 842 | -                $reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), | |
| 843 | -                        ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; | |
| 844 | -            } else if (is_numeric($reg_step_status) && $reg_step_status !== false) { | |
| 845 | - $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( | |
| 846 | -                        esc_html__('%1$s : Initiated %2$s', 'event_espresso'), | |
| 847 | -                        ucwords(str_replace('_', ' ', $reg_step)), | |
| 848 | -                        date(get_option('date_format') . ' ' . get_option('time_format'), | |
| 849 | -                            ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) | |
| 850 | - ) . '</li>'; | |
| 851 | -            } else { | |
| 852 | -                $reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', | |
| 853 | -                        'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; | |
| 854 | - } | |
| 855 | - } | |
| 856 | - $reg_steps .= '</ul>'; | |
| 857 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; | |
| 858 | -        $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress', | |
| 859 | - 'event_espresso'); | |
| 860 | - | |
| 861 | - | |
| 862 | - $this->_get_registrations_to_apply_payment_to(); | |
| 863 | - $this->_get_payment_methods($payments); | |
| 864 | - $this->_get_payment_status_array(); | |
| 865 | - $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. | |
| 866 | - | |
| 867 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( | |
| 868 | - 'action' => 'edit_transaction', | |
| 869 | - 'process' => 'transaction' | |
| 870 | - ), TXN_ADMIN_URL); | |
| 871 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( | |
| 872 | - 'page' => 'espresso_transactions', | |
| 873 | - 'action' => 'espresso_apply_payment' | |
| 874 | - ), WP_AJAX_URL); | |
| 875 | - $this->_template_args['delete_payment_form_url'] = add_query_arg(array( | |
| 876 | - 'page' => 'espresso_transactions', | |
| 877 | - 'action' => 'espresso_delete_payment' | |
| 878 | - ), WP_AJAX_URL); | |
| 879 | - | |
| 880 | - // 'espresso_delete_payment_nonce' | |
| 881 | - | |
| 882 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; | |
| 883 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); | |
| 884 | - | |
| 885 | - } | |
| 886 | - | |
| 887 | - | |
| 888 | - /** | |
| 889 | - * _get_registration_payment_IDs | |
| 890 | - * | |
| 891 | - * generates an array of Payment IDs and their corresponding Registration IDs | |
| 892 | - * | |
| 893 | - * @access protected | |
| 894 | - * | |
| 895 | - * @param EE_Payment[] $payments | |
| 896 | - * | |
| 897 | - * @return array | |
| 898 | - */ | |
| 899 | - protected function _get_registration_payment_IDs($payments = array()) | |
| 900 | -    { | |
| 901 | - $existing_reg_payments = array(); | |
| 902 | - // get all reg payments for these payments | |
| 903 | - $reg_payments = EEM_Registration_Payment::instance()->get_all(array( | |
| 904 | - array( | |
| 905 | - 'PAY_ID' => array( | |
| 906 | - 'IN', | |
| 907 | - array_keys($payments) | |
| 908 | - ) | |
| 909 | - ) | |
| 910 | - )); | |
| 911 | -        if ( ! empty($reg_payments)) { | |
| 912 | -            foreach ($payments as $payment) { | |
| 913 | -                if ( ! $payment instanceof EE_Payment) { | |
| 914 | - continue; | |
| 915 | -                } else if ( ! isset($existing_reg_payments[$payment->ID()])) { | |
| 916 | - $existing_reg_payments[$payment->ID()] = array(); | |
| 917 | - } | |
| 918 | -                foreach ($reg_payments as $reg_payment) { | |
| 919 | -                    if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) { | |
| 920 | - $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); | |
| 921 | - } | |
| 922 | - } | |
| 923 | - } | |
| 924 | - } | |
| 925 | - | |
| 926 | - return $existing_reg_payments; | |
| 927 | - } | |
| 928 | - | |
| 929 | - | |
| 930 | - /** | |
| 931 | - * _get_registrations_to_apply_payment_to | |
| 932 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window | |
| 933 | - * which allows the admin to only apply the payment to the specific registrations | |
| 934 | - * | |
| 935 | - * @access protected | |
| 936 | - * @return void | |
| 937 | - * @throws \EE_Error | |
| 938 | - */ | |
| 939 | - protected function _get_registrations_to_apply_payment_to() | |
| 940 | -    { | |
| 941 | - // we want any registration with an active status (ie: not deleted or cancelled) | |
| 942 | - $query_params = array( | |
| 943 | - array( | |
| 944 | - 'STS_ID' => array( | |
| 945 | - 'IN', | |
| 946 | - array( | |
| 947 | - EEM_Registration::status_id_approved, | |
| 948 | - EEM_Registration::status_id_pending_payment, | |
| 949 | - EEM_Registration::status_id_not_approved, | |
| 950 | - ) | |
| 951 | - ) | |
| 952 | - ) | |
| 953 | - ); | |
| 954 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( | |
| 955 | - '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' | |
| 956 | - ); | |
| 957 | -        $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); | |
| 958 | -        $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); | |
| 959 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( | |
| 960 | - EEH_HTML::tr( | |
| 961 | -                EEH_HTML::th(esc_html__('ID', 'event_espresso')) . | |
| 962 | -                EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . | |
| 963 | -                EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . | |
| 964 | -                EEH_HTML::th(esc_html__('Event', 'event_espresso')) . | |
| 965 | -                EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . | |
| 966 | -                EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . | |
| 967 | -                EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') | |
| 968 | - ) | |
| 969 | - ); | |
| 970 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); | |
| 971 | - // get registrations for TXN | |
| 972 | - $registrations = $this->_transaction->registrations($query_params); | |
| 973 | -        foreach ($registrations as $registration) { | |
| 974 | -            if ($registration instanceof EE_Registration) { | |
| 975 | - $attendee_name = $registration->attendee() instanceof EE_Attendee | |
| 976 | - ? $registration->attendee()->full_name() | |
| 977 | -                    : esc_html__('Unknown Attendee', 'event_espresso'); | |
| 978 | - $owing = $registration->final_price() - $registration->paid(); | |
| 979 | - $taxable = $registration->ticket()->taxable() | |
| 980 | -                    ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' | |
| 981 | - : ''; | |
| 982 | - $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) | |
| 983 | - ? ' checked="checked"' | |
| 984 | - : ''; | |
| 985 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; | |
| 986 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( | |
| 987 | - EEH_HTML::td($registration->ID()) . | |
| 988 | - EEH_HTML::td($attendee_name) . | |
| 989 | - EEH_HTML::td( | |
| 990 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable | |
| 991 | - ) . | |
| 992 | - EEH_HTML::td($registration->event_name()) . | |
| 993 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . | |
| 994 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . | |
| 995 | - EEH_HTML::td( | |
| 996 | - '<input type="checkbox" value="' . $registration->ID() | |
| 997 | - . '" name="txn_admin_payment[registrations]"' | |
| 998 | - . $checked . $disabled . '>', | |
| 999 | - '', 'jst-cntr' | |
| 1000 | - ), | |
| 1001 | - 'apply-payment-registration-row-' . $registration->ID() | |
| 1002 | - ); | |
| 1003 | - } | |
| 1004 | - } | |
| 1005 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); | |
| 1006 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); | |
| 1007 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); | |
| 1008 | - $registrations_to_apply_payment_to .= EEH_HTML::p( | |
| 1009 | - esc_html__( | |
| 1010 | - 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', | |
| 1011 | - 'event_espresso' | |
| 1012 | - ), | |
| 1013 | - '', 'clear description' | |
| 1014 | - ); | |
| 1015 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); | |
| 1016 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; | |
| 1017 | - } | |
| 1018 | - | |
| 1019 | - | |
| 1020 | - /** | |
| 1021 | - * _get_reg_status_selection | |
| 1022 | - * | |
| 1023 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets | |
| 1024 | - * instead of events. | |
| 1025 | - * @access protected | |
| 1026 | - * @return void | |
| 1027 | - */ | |
| 1028 | - protected function _get_reg_status_selection() | |
| 1029 | -    { | |
| 1030 | - //first get all possible statuses | |
| 1031 | - $statuses = EEM_Registration::reg_status_array(array(), true); | |
| 1032 | - //let's add a "don't change" option. | |
| 1033 | -        $status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso'); | |
| 1034 | - $status_array = array_merge($status_array, $statuses); | |
| 1035 | -        $this->_template_args['status_change_select']        = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]', | |
| 1036 | - $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status'); | |
| 1037 | -        $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]', | |
| 1038 | - $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status'); | |
| 1039 | - | |
| 1040 | - } | |
| 1041 | - | |
| 1042 | - | |
| 1043 | - /** | |
| 1044 | - * _get_payment_methods | |
| 1045 | - * Gets all the payment methods available generally, or the ones that are already | |
| 1046 | - * selected on these payments (in case their payment methods are no longer active). | |
| 1047 | - * Has the side-effect of updating the template args' payment_methods item | |
| 1048 | - * @access private | |
| 1049 | - * | |
| 1050 | - * @param EE_Payment[] to show on this page | |
| 1051 | - * | |
| 1052 | - * @return void | |
| 1053 | - */ | |
| 1054 | - private function _get_payment_methods($payments = array()) | |
| 1055 | -    { | |
| 1056 | - $payment_methods_of_payments = array(); | |
| 1057 | -        foreach ($payments as $payment) { | |
| 1058 | -            if ($payment instanceof EE_Payment) { | |
| 1059 | -                $payment_methods_of_payments[] = $payment->get('PMD_ID'); | |
| 1060 | - } | |
| 1061 | - } | |
| 1062 | -        if ($payment_methods_of_payments) { | |
| 1063 | - $query_args = array( | |
| 1064 | - array( | |
| 1065 | - 'OR*payment_method_for_payment' => array( | |
| 1066 | -                        'PMD_ID'    => array('IN', $payment_methods_of_payments), | |
| 1067 | -                        'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%') | |
| 1068 | - ) | |
| 1069 | - ) | |
| 1070 | - ); | |
| 1071 | -        } else { | |
| 1072 | -            $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); | |
| 1073 | - } | |
| 1074 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); | |
| 1075 | - } | |
| 1076 | - | |
| 1077 | - | |
| 1078 | - /** | |
| 1079 | - * txn_attendees_meta_box | |
| 1080 | - * generates HTML for the Attendees Transaction main meta box | |
| 1081 | - * | |
| 1082 | - * @access public | |
| 1083 | - * | |
| 1084 | - * @param WP_Post $post | |
| 1085 | - * @param array $metabox | |
| 1086 | - * | |
| 1087 | - * @return void | |
| 1088 | - */ | |
| 1089 | -    public function txn_attendees_meta_box($post, $metabox = array('args' => array())) | |
| 1090 | -    { | |
| 1091 | - | |
| 1092 | - extract($metabox['args']); | |
| 1093 | - $this->_template_args['post'] = $post; | |
| 1094 | - $this->_template_args['event_attendees'] = array(); | |
| 1095 | - // process items in cart | |
| 1096 | -        $line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item'))); | |
| 1097 | -        if ( ! empty($line_items)) { | |
| 1098 | -            foreach ($line_items as $item) { | |
| 1099 | -                if ($item instanceof EE_Line_Item) { | |
| 1100 | -                    switch ($item->OBJ_type()) { | |
| 1101 | - | |
| 1102 | - case 'Event' : | |
| 1103 | - break; | |
| 1104 | - | |
| 1105 | - case 'Ticket' : | |
| 1106 | - $ticket = $item->ticket(); | |
| 1107 | - //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? | |
| 1108 | -                            if ( ! $ticket instanceof EE_Ticket) { | |
| 1109 | - continue; | |
| 1110 | - } | |
| 1111 | -                            try { | |
| 1112 | - $event_name = $ticket->get_event_name(); | |
| 1113 | -                            } catch (Exception $e) { | |
| 1114 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); | |
| 1115 | -                                $event_name = esc_html__('Unknown Event', 'event_espresso'); | |
| 1116 | - } | |
| 1117 | -                            $event_name .= ' - ' . $item->get('LIN_name'); | |
| 1118 | -                            $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); | |
| 1119 | - // now get all of the registrations for this transaction that use this ticket | |
| 1120 | -                            $registrations = $ticket->get_many_related('Registration', | |
| 1121 | -                                array(array('TXN_ID' => $this->_transaction->ID()))); | |
| 1122 | -                            foreach ($registrations as $registration) { | |
| 1123 | -                                if ( ! $registration instanceof EE_Registration) { | |
| 1124 | - continue; | |
| 1125 | - } | |
| 1126 | - $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] = $registration->status_ID(); | |
| 1127 | - $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->count(); | |
| 1128 | - $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; | |
| 1129 | - $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; | |
| 1130 | - // attendee info | |
| 1131 | -                                $attendee = $registration->get_first_related('Attendee'); | |
| 1132 | -                                if ($attendee instanceof EE_Attendee) { | |
| 1133 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); | |
| 1134 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); | |
| 1135 | -                                    $this->_template_args['event_attendees'][$registration->ID()]['email']    = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', | |
| 1136 | - 'event_espresso') . '">' . $attendee->email() . '</a>'; | |
| 1137 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, | |
| 1138 | - 'inline', false, false); | |
| 1139 | -                                } else { | |
| 1140 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; | |
| 1141 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; | |
| 1142 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; | |
| 1143 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; | |
| 1144 | - } | |
| 1145 | - } | |
| 1146 | - break; | |
| 1147 | - | |
| 1148 | - } | |
| 1149 | - } | |
| 1150 | - } | |
| 1151 | - | |
| 1152 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( | |
| 1153 | - 'action' => 'edit_transaction', | |
| 1154 | - 'process' => 'attendees' | |
| 1155 | - ), TXN_ADMIN_URL); | |
| 1156 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', | |
| 1157 | - $this->_template_args, true); | |
| 1158 | - | |
| 1159 | -        } else { | |
| 1160 | - echo sprintf( | |
| 1161 | -                esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', | |
| 1162 | - 'event_espresso'), | |
| 1163 | - '<p class="important-notice">', | |
| 1164 | - '</p>' | |
| 1165 | - ); | |
| 1166 | - } | |
| 1167 | - } | |
| 1168 | - | |
| 1169 | - | |
| 1170 | - /** | |
| 1171 | - * txn_registrant_side_meta_box | |
| 1172 | - * generates HTML for the Edit Transaction side meta box | |
| 1173 | - * | |
| 1174 | - * @access public | |
| 1175 | - * @throws \EE_Error | |
| 1176 | - * @return void | |
| 1177 | - */ | |
| 1178 | - public function txn_registrant_side_meta_box() | |
| 1179 | -    { | |
| 1180 | -        $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; | |
| 1181 | -        if ( ! $primary_att instanceof EE_Attendee) { | |
| 1182 | -            $this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.', | |
| 1183 | - 'event_espresso'); | |
| 1184 | - $primary_att = EEM_Attendee::instance()->create_default_object(); | |
| 1185 | - } | |
| 1186 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); | |
| 1187 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); | |
| 1188 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); | |
| 1189 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); | |
| 1190 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); | |
| 1191 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 1192 | - 'action' => 'edit_attendee', | |
| 1193 | - 'post' => $primary_att->ID() | |
| 1194 | - ), REG_ADMIN_URL); | |
| 1195 | - // get formatted address for registrant | |
| 1196 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); | |
| 1197 | - echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', | |
| 1198 | - $this->_template_args, true); | |
| 1199 | - } | |
| 1200 | - | |
| 1201 | - | |
| 1202 | - /** | |
| 1203 | - * txn_billing_info_side_meta_box | |
| 1204 | - * generates HTML for the Edit Transaction side meta box | |
| 1205 | - * | |
| 1206 | - * @access public | |
| 1207 | - * @return void | |
| 1208 | - */ | |
| 1209 | - public function txn_billing_info_side_meta_box() | |
| 1210 | -    { | |
| 1211 | - | |
| 1212 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); | |
| 1213 | - $this->_template_args['billing_form_url'] = add_query_arg( | |
| 1214 | -            array('action' => 'edit_transaction', 'process' => 'billing'), | |
| 1215 | - TXN_ADMIN_URL | |
| 1216 | - ); | |
| 1217 | - | |
| 1218 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; | |
| 1219 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ | |
| 1220 | - } | |
| 1221 | - | |
| 1222 | - | |
| 1223 | - /** | |
| 1224 | - * apply_payments_or_refunds | |
| 1225 | - * registers a payment or refund made towards a transaction | |
| 1226 | - * | |
| 1227 | - * @access public | |
| 1228 | - * @return void | |
| 1229 | - */ | |
| 1230 | - public function apply_payments_or_refunds() | |
| 1231 | -    { | |
| 1232 | -        $json_response_data = array('return_data' => false); | |
| 1233 | - $valid_data = $this->_validate_payment_request_data(); | |
| 1234 | -        if ( ! empty($valid_data)) { | |
| 1235 | - $PAY_ID = $valid_data['PAY_ID']; | |
| 1236 | - //save the new payment | |
| 1237 | - $payment = $this->_create_payment_from_request_data($valid_data); | |
| 1238 | - // get the TXN for this payment | |
| 1239 | - $transaction = $payment->transaction(); | |
| 1240 | - // verify transaction | |
| 1241 | -            if ($transaction instanceof EE_Transaction) { | |
| 1242 | - // calculate_total_payments_and_update_status | |
| 1243 | - $this->_process_transaction_payments($transaction); | |
| 1244 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); | |
| 1245 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); | |
| 1246 | - // apply payment to registrations (if applicable) | |
| 1247 | -                if ( ! empty($REG_IDs)) { | |
| 1248 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); | |
| 1249 | - $this->_maybe_send_notifications(); | |
| 1250 | - // now process status changes for the same registrations | |
| 1251 | - $this->_process_registration_status_change($transaction, $REG_IDs); | |
| 1252 | - } | |
| 1253 | - $this->_maybe_send_notifications($payment); | |
| 1254 | - //prepare to render page | |
| 1255 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); | |
| 1256 | -                do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, | |
| 1257 | - $payment); | |
| 1258 | -            } else { | |
| 1259 | - EE_Error::add_error( | |
| 1260 | -                    esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'), | |
| 1261 | - __FILE__, __FUNCTION__, __LINE__ | |
| 1262 | - ); | |
| 1263 | - } | |
| 1264 | -        } else { | |
| 1265 | -            EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.', | |
| 1266 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); | |
| 1267 | - } | |
| 1268 | - | |
| 1269 | - $notices = EE_Error::get_notices(false, false, false); | |
| 1270 | - $this->_template_args = array( | |
| 1271 | - 'data' => $json_response_data, | |
| 1272 | - 'error' => $notices['errors'], | |
| 1273 | - 'success' => $notices['success'] | |
| 1274 | - ); | |
| 1275 | - $this->_return_json(); | |
| 1276 | - } | |
| 1277 | - | |
| 1278 | - | |
| 1279 | - /** | |
| 1280 | - * _validate_payment_request_data | |
| 1281 | - * | |
| 1282 | - * @return array | |
| 1283 | - */ | |
| 1284 | - protected function _validate_payment_request_data() | |
| 1285 | -    { | |
| 1286 | -        if ( ! isset($this->_req_data['txn_admin_payment'])) { | |
| 1287 | - return false; | |
| 1288 | - } | |
| 1289 | - $payment_form = $this->_generate_payment_form_section(); | |
| 1290 | -        try { | |
| 1291 | -            if ($payment_form->was_submitted()) { | |
| 1292 | - $payment_form->receive_form_submission(); | |
| 1293 | -                if ( ! $payment_form->is_valid()) { | |
| 1294 | - $submission_error_messages = array(); | |
| 1295 | -                    foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { | |
| 1296 | -                        if ($validation_error instanceof EE_Validation_Error) { | |
| 1297 | - $submission_error_messages[] = sprintf( | |
| 1298 | -                                _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), | |
| 1299 | - $validation_error->get_form_section()->html_label_text(), | |
| 1300 | - $validation_error->getMessage() | |
| 1301 | - ); | |
| 1302 | - } | |
| 1303 | - } | |
| 1304 | -                    EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); | |
| 1305 | - | |
| 1306 | - return array(); | |
| 1307 | - } | |
| 1308 | - } | |
| 1309 | -        } catch (EE_Error $e) { | |
| 1310 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); | |
| 1311 | - | |
| 1312 | - return array(); | |
| 1313 | - } | |
| 1314 | - | |
| 1315 | - return $payment_form->valid_data(); | |
| 1316 | - } | |
| 1317 | - | |
| 1318 | - | |
| 1319 | - /** | |
| 1320 | - * _generate_payment_form_section | |
| 1321 | - * | |
| 1322 | - * @return EE_Form_Section_Proper | |
| 1323 | - */ | |
| 1324 | - protected function _generate_payment_form_section() | |
| 1325 | -    { | |
| 1326 | - return new EE_Form_Section_Proper( | |
| 1327 | - array( | |
| 1328 | - 'name' => 'txn_admin_payment', | |
| 1329 | - 'subsections' => array( | |
| 1330 | - 'PAY_ID' => new EE_Text_Input( | |
| 1331 | - array( | |
| 1332 | - 'default' => 0, | |
| 1333 | - 'required' => false, | |
| 1334 | -                            'html_label_text'       => esc_html__('Payment ID', 'event_espresso'), | |
| 1335 | - 'validation_strategies' => array(new EE_Int_Normalization()) | |
| 1336 | - ) | |
| 1337 | - ), | |
| 1338 | - 'TXN_ID' => new EE_Text_Input( | |
| 1339 | - array( | |
| 1340 | - 'default' => 0, | |
| 1341 | - 'required' => true, | |
| 1342 | -                            'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'), | |
| 1343 | - 'validation_strategies' => array(new EE_Int_Normalization()) | |
| 1344 | - ) | |
| 1345 | - ), | |
| 1346 | - 'type' => new EE_Text_Input( | |
| 1347 | - array( | |
| 1348 | - 'default' => 1, | |
| 1349 | - 'required' => true, | |
| 1350 | -                            'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'), | |
| 1351 | - 'validation_strategies' => array(new EE_Int_Normalization()) | |
| 1352 | - ) | |
| 1353 | - ), | |
| 1354 | - 'amount' => new EE_Text_Input( | |
| 1355 | - array( | |
| 1356 | - 'default' => 0, | |
| 1357 | - 'required' => true, | |
| 1358 | -                            'html_label_text'       => esc_html__('Payment amount', 'event_espresso'), | |
| 1359 | - 'validation_strategies' => array(new EE_Float_Normalization()) | |
| 1360 | - ) | |
| 1361 | - ), | |
| 1362 | - 'status' => new EE_Text_Input( | |
| 1363 | - array( | |
| 1364 | - 'default' => EEM_Payment::status_id_approved, | |
| 1365 | - 'required' => true, | |
| 1366 | -                            'html_label_text' => esc_html__('Payment status', 'event_espresso'), | |
| 1367 | - ) | |
| 1368 | - ), | |
| 1369 | - 'PMD_ID' => new EE_Text_Input( | |
| 1370 | - array( | |
| 1371 | - 'default' => 2, | |
| 1372 | - 'required' => true, | |
| 1373 | -                            'html_label_text'       => esc_html__('Payment Method', 'event_espresso'), | |
| 1374 | - 'validation_strategies' => array(new EE_Int_Normalization()) | |
| 1375 | - ) | |
| 1376 | - ), | |
| 1377 | - 'date' => new EE_Text_Input( | |
| 1378 | - array( | |
| 1379 | - 'default' => time(), | |
| 1380 | - 'required' => true, | |
| 1381 | -                            'html_label_text' => esc_html__('Payment date', 'event_espresso'), | |
| 1382 | - ) | |
| 1383 | - ), | |
| 1384 | - 'txn_id_chq_nmbr' => new EE_Text_Input( | |
| 1385 | - array( | |
| 1386 | - 'default' => '', | |
| 1387 | - 'required' => false, | |
| 1388 | -                            'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'), | |
| 1389 | - 'validation_strategies' => array( | |
| 1390 | -                                new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), | |
| 1391 | - 100), | |
| 1392 | - ) | |
| 1393 | - ) | |
| 1394 | - ), | |
| 1395 | - 'po_number' => new EE_Text_Input( | |
| 1396 | - array( | |
| 1397 | - 'default' => '', | |
| 1398 | - 'required' => false, | |
| 1399 | -                            'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'), | |
| 1400 | - 'validation_strategies' => array( | |
| 1401 | -                                new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), | |
| 1402 | - 100), | |
| 1403 | - ) | |
| 1404 | - ) | |
| 1405 | - ), | |
| 1406 | - 'accounting' => new EE_Text_Input( | |
| 1407 | - array( | |
| 1408 | - 'default' => '', | |
| 1409 | - 'required' => false, | |
| 1410 | -                            'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'), | |
| 1411 | - 'validation_strategies' => array( | |
| 1412 | -                                new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), | |
| 1413 | - 100), | |
| 1414 | - ) | |
| 1415 | - ) | |
| 1416 | - ), | |
| 1417 | - ) | |
| 1418 | - ) | |
| 1419 | - ); | |
| 1420 | - } | |
| 1421 | - | |
| 1422 | - | |
| 1423 | - /** | |
| 1424 | - * _create_payment_from_request_data | |
| 1425 | - * | |
| 1426 | - * @param array $valid_data | |
| 1427 | - * | |
| 1428 | - * @return EE_Payment | |
| 1429 | - */ | |
| 1430 | - protected function _create_payment_from_request_data($valid_data) | |
| 1431 | -    { | |
| 1432 | - $PAY_ID = $valid_data['PAY_ID']; | |
| 1433 | - // get payment amount | |
| 1434 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; | |
| 1435 | - // payments have a type value of 1 and refunds have a type value of -1 | |
| 1436 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds | |
| 1437 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; | |
| 1438 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. | |
| 1439 | -        $date    = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a', | |
| 1440 | -            current_time('timestamp')); | |
| 1441 | - $payment = EE_Payment::new_instance( | |
| 1442 | - array( | |
| 1443 | - 'TXN_ID' => $valid_data['TXN_ID'], | |
| 1444 | - 'STS_ID' => $valid_data['status'], | |
| 1445 | - 'PAY_timestamp' => $date, | |
| 1446 | - 'PAY_source' => EEM_Payment_Method::scope_admin, | |
| 1447 | - 'PMD_ID' => $valid_data['PMD_ID'], | |
| 1448 | - 'PAY_amount' => $amount, | |
| 1449 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], | |
| 1450 | - 'PAY_po_number' => $valid_data['po_number'], | |
| 1451 | - 'PAY_extra_accntng' => $valid_data['accounting'], | |
| 1452 | - 'PAY_details' => $valid_data, | |
| 1453 | - 'PAY_ID' => $PAY_ID | |
| 1454 | - ), | |
| 1455 | - '', | |
| 1456 | -            array('Y-m-d', 'g:i a') | |
| 1457 | - ); | |
| 1458 | - | |
| 1459 | -        if ( ! $payment->save()) { | |
| 1460 | - EE_Error::add_error( | |
| 1461 | - sprintf( | |
| 1462 | -                    esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), | |
| 1463 | - $payment->ID() | |
| 1464 | - ), | |
| 1465 | - __FILE__, __FUNCTION__, __LINE__ | |
| 1466 | - ); | |
| 1467 | - } | |
| 1468 | - | |
| 1469 | - return $payment; | |
| 1470 | - } | |
| 1471 | - | |
| 1472 | - | |
| 1473 | - /** | |
| 1474 | - * _process_transaction_payments | |
| 1475 | - * | |
| 1476 | - * @param \EE_Transaction $transaction | |
| 1477 | - * | |
| 1478 | - * @return array | |
| 1479 | - */ | |
| 1480 | - protected function _process_transaction_payments(EE_Transaction $transaction) | |
| 1481 | -    { | |
| 1482 | - /** @type EE_Transaction_Payments $transaction_payments */ | |
| 1483 | -        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); | |
| 1484 | - //update the transaction with this payment | |
| 1485 | -        if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { | |
| 1486 | -            EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'), | |
| 1487 | - __FILE__, __FUNCTION__, __LINE__); | |
| 1488 | -        } else { | |
| 1489 | - EE_Error::add_error( | |
| 1490 | -                esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.', | |
| 1491 | - 'event_espresso') | |
| 1492 | - , __FILE__, __FUNCTION__, __LINE__ | |
| 1493 | - ); | |
| 1494 | - } | |
| 1495 | - } | |
| 1496 | - | |
| 1497 | - | |
| 1498 | - /** | |
| 1499 | - * _get_REG_IDs_to_apply_payment_to | |
| 1500 | - * | |
| 1501 | - * returns a list of registration IDs that the payment will apply to | |
| 1502 | - * | |
| 1503 | - * @param \EE_Payment $payment | |
| 1504 | - * | |
| 1505 | - * @return array | |
| 1506 | - */ | |
| 1507 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) | |
| 1508 | -    { | |
| 1509 | - $REG_IDs = array(); | |
| 1510 | - // grab array of IDs for specific registrations to apply changes to | |
| 1511 | -        if (isset($this->_req_data['txn_admin_payment']['registrations'])) { | |
| 1512 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; | |
| 1513 | - } | |
| 1514 | - //nothing specified ? then get all reg IDs | |
| 1515 | -        if (empty($REG_IDs)) { | |
| 1516 | - $registrations = $payment->transaction()->registrations(); | |
| 1517 | - $REG_IDs = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment); | |
| 1518 | - } | |
| 1519 | - | |
| 1520 | - // ensure that REG_IDs are integers and NOT strings | |
| 1521 | -        return array_map('intval', $REG_IDs); | |
| 1522 | - } | |
| 1523 | - | |
| 1524 | - | |
| 1525 | - /** | |
| 1526 | - * @return array | |
| 1527 | - */ | |
| 1528 | - public function existing_reg_payment_REG_IDs() | |
| 1529 | -    { | |
| 1530 | - return $this->_existing_reg_payment_REG_IDs; | |
| 1531 | - } | |
| 1532 | - | |
| 1533 | - | |
| 1534 | - /** | |
| 1535 | - * @param array $existing_reg_payment_REG_IDs | |
| 1536 | - */ | |
| 1537 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) | |
| 1538 | -    { | |
| 1539 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; | |
| 1540 | - } | |
| 1541 | - | |
| 1542 | - | |
| 1543 | - /** | |
| 1544 | - * _get_existing_reg_payment_REG_IDs | |
| 1545 | - * | |
| 1546 | - * returns a list of registration IDs that the payment is currently related to | |
| 1547 | - * as recorded in the database | |
| 1548 | - * | |
| 1549 | - * @param \EE_Payment $payment | |
| 1550 | - * | |
| 1551 | - * @return array | |
| 1552 | - */ | |
| 1553 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) | |
| 1554 | -    { | |
| 1555 | -        if ($this->existing_reg_payment_REG_IDs() === null) { | |
| 1556 | - // let's get any existing reg payment records for this payment | |
| 1557 | -            $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); | |
| 1558 | - // but we only want the REG IDs, so grab the array keys | |
| 1559 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array(); | |
| 1560 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); | |
| 1561 | - } | |
| 1562 | - | |
| 1563 | - return $this->existing_reg_payment_REG_IDs(); | |
| 1564 | - } | |
| 1565 | - | |
| 1566 | - | |
| 1567 | - /** | |
| 1568 | - * _remove_existing_registration_payments | |
| 1569 | - * | |
| 1570 | - * this calculates the difference between existing relations | |
| 1571 | - * to the supplied payment and the new list registration IDs, | |
| 1572 | - * removes any related registrations that no longer apply, | |
| 1573 | - * and then updates the registration paid fields | |
| 1574 | - * | |
| 1575 | - * @param \EE_Payment $payment | |
| 1576 | - * @param int $PAY_ID | |
| 1577 | - * | |
| 1578 | - * @return bool; | |
| 1579 | - */ | |
| 1580 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) | |
| 1581 | -    { | |
| 1582 | - // newly created payments will have nothing recorded for $PAY_ID | |
| 1583 | -        if ($PAY_ID == 0) { | |
| 1584 | - return false; | |
| 1585 | - } | |
| 1586 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); | |
| 1587 | -        if (empty($existing_reg_payment_REG_IDs)) { | |
| 1588 | - return false; | |
| 1589 | - } | |
| 1590 | - /** @type EE_Transaction_Payments $transaction_payments */ | |
| 1591 | -        $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); | |
| 1592 | - | |
| 1593 | - return $transaction_payments->delete_registration_payments_and_update_registrations( | |
| 1594 | - $payment, | |
| 1595 | - array( | |
| 1596 | - array( | |
| 1597 | - 'PAY_ID' => $payment->ID(), | |
| 1598 | -                    'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), | |
| 1599 | - ) | |
| 1600 | - ) | |
| 1601 | - ); | |
| 1602 | - } | |
| 1603 | - | |
| 1604 | - | |
| 1605 | - /** | |
| 1606 | - * _update_registration_payments | |
| 1607 | - * | |
| 1608 | - * this applies the payments to the selected registrations | |
| 1609 | - * but only if they have not already been paid for | |
| 1610 | - * | |
| 1611 | - * @param EE_Transaction $transaction | |
| 1612 | - * @param \EE_Payment $payment | |
| 1613 | - * @param array $REG_IDs | |
| 1614 | - * | |
| 1615 | - * @return bool | |
| 1616 | - */ | |
| 1617 | - protected function _update_registration_payments( | |
| 1618 | - EE_Transaction $transaction, | |
| 1619 | - EE_Payment $payment, | |
| 1620 | - $REG_IDs = array() | |
| 1621 | -    ) { | |
| 1622 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() | |
| 1623 | - // so let's do that using our set of REG_IDs from the form | |
| 1624 | - $registration_query_where_params = array( | |
| 1625 | -            'REG_ID' => array('IN', $REG_IDs) | |
| 1626 | - ); | |
| 1627 | - // but add in some conditions regarding payment, | |
| 1628 | - // so that we don't apply payments to registrations that are free or have already been paid for | |
| 1629 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) | |
| 1630 | -        if ( ! $payment->is_a_refund()) { | |
| 1631 | -            $registration_query_where_params['REG_final_price']  = array('!=', 0); | |
| 1632 | -            $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); | |
| 1633 | - } | |
| 1634 | - //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); | |
| 1635 | - $registrations = $transaction->registrations(array($registration_query_where_params)); | |
| 1636 | -        if ( ! empty($registrations)) { | |
| 1637 | - /** @type EE_Payment_Processor $payment_processor */ | |
| 1638 | -            $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); | |
| 1639 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); | |
| 1640 | - } | |
| 1641 | - } | |
| 1642 | - | |
| 1643 | - | |
| 1644 | - /** | |
| 1645 | - * _process_registration_status_change | |
| 1646 | - * | |
| 1647 | - * This processes requested registration status changes for all the registrations | |
| 1648 | - * on a given transaction and (optionally) sends out notifications for the changes. | |
| 1649 | - * | |
| 1650 | - * @param EE_Transaction $transaction | |
| 1651 | - * @param array $REG_IDs | |
| 1652 | - * | |
| 1653 | - * @return bool | |
| 1654 | - */ | |
| 1655 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) | |
| 1656 | -    { | |
| 1657 | - // first if there is no change in status then we get out. | |
| 1658 | - if ( | |
| 1659 | - ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status']) | |
| 1660 | - || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN' | |
| 1661 | -        ) { | |
| 1662 | - //no error message, no change requested, just nothing to do man. | |
| 1663 | - return false; | |
| 1664 | - } | |
| 1665 | - /** @type EE_Transaction_Processor $transaction_processor */ | |
| 1666 | -        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); | |
| 1667 | - | |
| 1668 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses | |
| 1669 | - return $transaction_processor->manually_update_registration_statuses( | |
| 1670 | - $transaction, | |
| 1671 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), | |
| 1672 | -            array(array('REG_ID' => array('IN', $REG_IDs))) | |
| 1673 | - ); | |
| 1674 | - } | |
| 1675 | - | |
| 1676 | - | |
| 1677 | - /** | |
| 1678 | - * _build_payment_json_response | |
| 1679 | - * | |
| 1680 | - * @access public | |
| 1681 | - * | |
| 1682 | - * @param \EE_Payment $payment | |
| 1683 | - * @param array $REG_IDs | |
| 1684 | - * @param bool | null $delete_txn_reg_status_change | |
| 1685 | - * | |
| 1686 | - * @return array | |
| 1687 | - */ | |
| 1688 | - protected function _build_payment_json_response( | |
| 1689 | - EE_Payment $payment, | |
| 1690 | - $REG_IDs = array(), | |
| 1691 | - $delete_txn_reg_status_change = null | |
| 1692 | -    ) { | |
| 1693 | - // was the payment deleted ? | |
| 1694 | -        if (is_bool($delete_txn_reg_status_change)) { | |
| 1695 | - return array( | |
| 1696 | - 'PAY_ID' => $payment->ID(), | |
| 1697 | - 'amount' => $payment->amount(), | |
| 1698 | - 'total_paid' => $payment->transaction()->paid(), | |
| 1699 | - 'txn_status' => $payment->transaction()->status_ID(), | |
| 1700 | - 'pay_status' => $payment->STS_ID(), | |
| 1701 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), | |
| 1702 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, | |
| 1703 | - ); | |
| 1704 | -        } else { | |
| 1705 | - $this->_get_payment_status_array(); | |
| 1706 | - | |
| 1707 | - return array( | |
| 1708 | - 'amount' => $payment->amount(), | |
| 1709 | - 'total_paid' => $payment->transaction()->paid(), | |
| 1710 | - 'txn_status' => $payment->transaction()->status_ID(), | |
| 1711 | - 'pay_status' => $payment->STS_ID(), | |
| 1712 | - 'PAY_ID' => $payment->ID(), | |
| 1713 | - 'STS_ID' => $payment->STS_ID(), | |
| 1714 | - 'status' => self::$_pay_status[$payment->STS_ID()], | |
| 1715 | -                'date'             => $payment->timestamp('Y-m-d', 'h:i a'), | |
| 1716 | - 'method' => strtoupper($payment->source()), | |
| 1717 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, | |
| 1718 | -                'gateway'          => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", | |
| 1719 | - 'event_espresso'), | |
| 1720 | - 'gateway_response' => $payment->gateway_response(), | |
| 1721 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), | |
| 1722 | - 'po_number' => $payment->po_number(), | |
| 1723 | - 'extra_accntng' => $payment->extra_accntng(), | |
| 1724 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), | |
| 1725 | - ); | |
| 1726 | - } | |
| 1727 | - } | |
| 1728 | - | |
| 1729 | - | |
| 1730 | - /** | |
| 1731 | - * delete_payment | |
| 1732 | - * delete a payment or refund made towards a transaction | |
| 1733 | - * | |
| 1734 | - * @access public | |
| 1735 | - * @return void | |
| 1736 | - */ | |
| 1737 | - public function delete_payment() | |
| 1738 | -    { | |
| 1739 | -        $json_response_data = array('return_data' => false); | |
| 1740 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0; | |
| 1741 | -        if ($PAY_ID) { | |
| 1742 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false; | |
| 1743 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); | |
| 1744 | -            if ($payment instanceof EE_Payment) { | |
| 1745 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); | |
| 1746 | - /** @type EE_Transaction_Payments $transaction_payments */ | |
| 1747 | -                $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); | |
| 1748 | -                if ($transaction_payments->delete_payment_and_update_transaction($payment)) { | |
| 1749 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs, | |
| 1750 | - $delete_txn_reg_status_change); | |
| 1751 | -                    if ($delete_txn_reg_status_change) { | |
| 1752 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; | |
| 1753 | - //MAKE sure we also add the delete_txn_req_status_change to the | |
| 1754 | - //$_REQUEST global because that's how messages will be looking for it. | |
| 1755 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; | |
| 1756 | - $this->_maybe_send_notifications(); | |
| 1757 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); | |
| 1758 | - } | |
| 1759 | - } | |
| 1760 | -            } else { | |
| 1761 | - EE_Error::add_error( | |
| 1762 | -                    esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), | |
| 1763 | - __FILE__, __FUNCTION__, __LINE__ | |
| 1764 | - ); | |
| 1765 | - } | |
| 1766 | -        } else { | |
| 1767 | - EE_Error::add_error( | |
| 1768 | -                esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.', | |
| 1769 | - 'event_espresso'), | |
| 1770 | - __FILE__, __FUNCTION__, __LINE__ | |
| 1771 | - ); | |
| 1772 | - } | |
| 1773 | - $notices = EE_Error::get_notices(false, false, false); | |
| 1774 | - $this->_template_args = array( | |
| 1775 | - 'data' => $json_response_data, | |
| 1776 | - 'success' => $notices['success'], | |
| 1777 | - 'error' => $notices['errors'], | |
| 1778 | - 'attention' => $notices['attention'] | |
| 1779 | - ); | |
| 1780 | - $this->_return_json(); | |
| 1781 | - } | |
| 1782 | - | |
| 1783 | - | |
| 1784 | - /** | |
| 1785 | - * _registration_payment_data_array | |
| 1786 | - * adds info for 'owing' and 'paid' for each registration to the json response | |
| 1787 | - * | |
| 1788 | - * @access protected | |
| 1789 | - * | |
| 1790 | - * @param array $REG_IDs | |
| 1791 | - * | |
| 1792 | - * @return array | |
| 1793 | - */ | |
| 1794 | - protected function _registration_payment_data_array($REG_IDs) | |
| 1795 | -    { | |
| 1796 | - $registration_payment_data = array(); | |
| 1797 | - //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. | |
| 1798 | -        if ( ! empty($REG_IDs)) { | |
| 1799 | -            $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); | |
| 1800 | -            foreach ($registrations as $registration) { | |
| 1801 | -                if ($registration instanceof EE_Registration) { | |
| 1802 | - $registration_payment_data[$registration->ID()] = array( | |
| 1803 | - 'paid' => $registration->pretty_paid(), | |
| 1804 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), | |
| 1805 | - ); | |
| 1806 | - } | |
| 1807 | - } | |
| 1808 | - } | |
| 1809 | - | |
| 1810 | - return $registration_payment_data; | |
| 1811 | - } | |
| 1812 | - | |
| 1813 | - | |
| 1814 | - /** | |
| 1815 | - * _maybe_send_notifications | |
| 1816 | - * | |
| 1817 | - * determines whether or not the admin has indicated that notifications should be sent. | |
| 1818 | - * If so, will toggle a filter switch for delivering registration notices. | |
| 1819 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. | |
| 1820 | - * | |
| 1821 | - * @access protected | |
| 1822 | - * | |
| 1823 | - * @param \EE_Payment | null $payment | |
| 1824 | - */ | |
| 1825 | - protected function _maybe_send_notifications($payment = null) | |
| 1826 | -    { | |
| 1827 | -        switch ($payment instanceof EE_Payment) { | |
| 1828 | - // payment notifications | |
| 1829 | - case true : | |
| 1830 | - if ( | |
| 1831 | - isset( | |
| 1832 | - $this->_req_data['txn_payments'], | |
| 1833 | - $this->_req_data['txn_payments']['send_notifications'] | |
| 1834 | - ) && | |
| 1835 | - filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) | |
| 1836 | -                ) { | |
| 1837 | - $this->_process_payment_notification($payment); | |
| 1838 | - } | |
| 1839 | - break; | |
| 1840 | - // registration notifications | |
| 1841 | - case false : | |
| 1842 | - if ( | |
| 1843 | - isset( | |
| 1844 | - $this->_req_data['txn_reg_status_change'], | |
| 1845 | - $this->_req_data['txn_reg_status_change']['send_notifications'] | |
| 1846 | - ) && | |
| 1847 | - filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) | |
| 1848 | -                ) { | |
| 1849 | -                    add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); | |
| 1850 | - } | |
| 1851 | - break; | |
| 1852 | - } | |
| 1853 | - } | |
| 1854 | - | |
| 1855 | - | |
| 1856 | - /** | |
| 1857 | - * _send_payment_reminder | |
| 1858 | - * generates HTML for the View Transaction Details Admin page | |
| 1859 | - * | |
| 1860 | - * @access protected | |
| 1861 | - * @return void | |
| 1862 | - */ | |
| 1863 | - protected function _send_payment_reminder() | |
| 1864 | -    { | |
| 1865 | - $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; | |
| 1866 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); | |
| 1867 | - $query_args = isset($this->_req_data['redirect_to']) ? array( | |
| 1868 | - 'action' => $this->_req_data['redirect_to'], | |
| 1869 | - 'TXN_ID' => $this->_req_data['TXN_ID'] | |
| 1870 | - ) : array(); | |
| 1871 | -        do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', | |
| 1872 | - $transaction); | |
| 1873 | -        $this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'), | |
| 1874 | -            esc_html__('sent', 'event_espresso'), $query_args, true); | |
| 1875 | - } | |
| 1876 | - | |
| 1877 | - | |
| 1878 | - /** | |
| 1879 | - * get_transactions | |
| 1880 | - * get transactions for given parameters (used by list table) | |
| 1881 | - * | |
| 1882 | - * @param int $perpage how many transactions displayed per page | |
| 1883 | - * @param boolean $count return the count or objects | |
| 1884 | - * @param string $view | |
| 1885 | - * | |
| 1886 | - * @return mixed int = count || array of transaction objects | |
| 1887 | - */ | |
| 1888 | - public function get_transactions($perpage, $count = false, $view = '') | |
| 1889 | -    { | |
| 1890 | - | |
| 1891 | - $TXN = EEM_Transaction::instance(); | |
| 1892 | - | |
| 1893 | -        $start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', | |
| 1894 | -            strtotime('-10 year')); | |
| 1895 | -        $end_date   = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); | |
| 1896 | - | |
| 1897 | - //make sure our timestamps start and end right at the boundaries for each day | |
| 1898 | -        $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; | |
| 1899 | -        $end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; | |
| 1900 | - | |
| 1901 | - | |
| 1902 | - //convert to timestamps | |
| 1903 | - $start_date = strtotime($start_date); | |
| 1904 | - $end_date = strtotime($end_date); | |
| 1905 | - | |
| 1906 | - //makes sure start date is the lowest value and vice versa | |
| 1907 | - $start_date = min($start_date, $end_date); | |
| 1908 | - $end_date = max($start_date, $end_date); | |
| 1909 | - | |
| 1910 | - //convert to correct format for query | |
| 1911 | -        $start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', | |
| 1912 | -            date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s'); | |
| 1913 | -        $end_date   = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', | |
| 1914 | -            date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s'); | |
| 1915 | - | |
| 1916 | - | |
| 1917 | - //set orderby | |
| 1918 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; | |
| 1919 | - | |
| 1920 | -        switch ($this->_req_data['orderby']) { | |
| 1921 | - case 'TXN_ID': | |
| 1922 | - $orderby = 'TXN_ID'; | |
| 1923 | - break; | |
| 1924 | - case 'ATT_fname': | |
| 1925 | - $orderby = 'Registration.Attendee.ATT_fname'; | |
| 1926 | - break; | |
| 1927 | - case 'event_name': | |
| 1928 | - $orderby = 'Registration.Event.EVT_name'; | |
| 1929 | - break; | |
| 1930 | - default: //'TXN_timestamp' | |
| 1931 | - $orderby = 'TXN_timestamp'; | |
| 1932 | - } | |
| 1933 | - | |
| 1934 | - $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC'; | |
| 1935 | - $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; | |
| 1936 | - $per_page = isset($perpage) && ! empty($perpage) ? $perpage : 10; | |
| 1937 | - $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; | |
| 1938 | - | |
| 1939 | - $offset = ($current_page - 1) * $per_page; | |
| 1940 | - $limit = array($offset, $per_page); | |
| 1941 | - | |
| 1942 | - $_where = array( | |
| 1943 | -            'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)), | |
| 1944 | - 'Registration.REG_count' => 1 | |
| 1945 | - ); | |
| 1946 | - | |
| 1947 | -        if (isset($this->_req_data['EVT_ID'])) { | |
| 1948 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; | |
| 1949 | - } | |
| 1950 | - | |
| 1951 | -        if (isset($this->_req_data['s'])) { | |
| 1952 | - $search_string = '%' . $this->_req_data['s'] . '%'; | |
| 1953 | - $_where['OR'] = array( | |
| 1954 | -                'Registration.Event.EVT_name'         => array('LIKE', $search_string), | |
| 1955 | -                'Registration.Event.EVT_desc'         => array('LIKE', $search_string), | |
| 1956 | -                'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string), | |
| 1957 | -                'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), | |
| 1958 | -                'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string), | |
| 1959 | -                'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string), | |
| 1960 | -                'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), | |
| 1961 | -                'Registration.Attendee.ATT_email'     => array('LIKE', $search_string), | |
| 1962 | -                'Registration.Attendee.ATT_address'   => array('LIKE', $search_string), | |
| 1963 | -                'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string), | |
| 1964 | -                'Registration.Attendee.ATT_city'      => array('LIKE', $search_string), | |
| 1965 | -                'Registration.REG_final_price'        => array('LIKE', $search_string), | |
| 1966 | -                'Registration.REG_code'               => array('LIKE', $search_string), | |
| 1967 | -                'Registration.REG_count'              => array('LIKE', $search_string), | |
| 1968 | -                'Registration.REG_group_size'         => array('LIKE', $search_string), | |
| 1969 | -                'Registration.Ticket.TKT_name'        => array('LIKE', $search_string), | |
| 1970 | -                'Registration.Ticket.TKT_description' => array('LIKE', $search_string), | |
| 1971 | -                'Payment.PAY_source'                  => array('LIKE', $search_string), | |
| 1972 | -                'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string), | |
| 1973 | -                'TXN_session_data'                    => array('LIKE', $search_string), | |
| 1974 | -                'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string) | |
| 1975 | - ); | |
| 1976 | - } | |
| 1977 | - | |
| 1978 | - //failed transactions | |
| 1979 | - $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false; | |
| 1980 | - $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false; | |
| 1981 | - | |
| 1982 | -        if ($failed) { | |
| 1983 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; | |
| 1984 | -        } else if ($abandoned) { | |
| 1985 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; | |
| 1986 | -        } else { | |
| 1987 | -            $_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code); | |
| 1988 | -            $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); | |
| 1989 | - } | |
| 1990 | - | |
| 1991 | - $query_params = array($_where, 'order_by' => array($orderby => $sort), 'limit' => $limit); | |
| 1992 | - | |
| 1993 | - $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params); | |
| 1994 | - | |
| 1995 | - | |
| 1996 | - return $transactions; | |
| 1997 | - | |
| 1998 | - } | |
| 807 | + // process payment details | |
| 808 | +		$payments = $this->_transaction->get_many_related('Payment'); | |
| 809 | +		if ( ! empty($payments)) { | |
| 810 | + $this->_template_args['payments'] = $payments; | |
| 811 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); | |
| 812 | +		} else { | |
| 813 | + $this->_template_args['payments'] = false; | |
| 814 | + $this->_template_args['existing_reg_payments'] = array(); | |
| 815 | + } | |
| 816 | + | |
| 817 | +		$this->_template_args['edit_payment_url']   = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); | |
| 818 | +		$this->_template_args['delete_payment_url'] = add_query_arg(array('action' => 'espresso_delete_payment'), | |
| 819 | + TXN_ADMIN_URL); | |
| 820 | + | |
| 821 | +		if (isset($txn_details['invoice_number'])) { | |
| 822 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; | |
| 823 | +			$this->_template_args['txn_details']['invoice_number']['label'] = esc_html__('Invoice Number', | |
| 824 | + 'event_espresso'); | |
| 825 | + } | |
| 826 | + | |
| 827 | +		$this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction->get_first_related('Registration')->get('REG_session'); | |
| 828 | +		$this->_template_args['txn_details']['registration_session']['label'] = esc_html__('Registration Session', | |
| 829 | + 'event_espresso'); | |
| 830 | + | |
| 831 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) ? $this->_session['ip_address'] : ''; | |
| 832 | +		$this->_template_args['txn_details']['ip_address']['label'] = esc_html__('Transaction placed from IP', | |
| 833 | + 'event_espresso'); | |
| 834 | + | |
| 835 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) ? $this->_session['user_agent'] : ''; | |
| 836 | +		$this->_template_args['txn_details']['user_agent']['label'] = esc_html__('Registrant User Agent', | |
| 837 | + 'event_espresso'); | |
| 838 | + | |
| 839 | + $reg_steps = '<ul>'; | |
| 840 | +		foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { | |
| 841 | +			if ($reg_step_status === true) { | |
| 842 | +				$reg_steps .= '<li style="color:#70cc50">' . sprintf(esc_html__('%1$s : Completed', 'event_espresso'), | |
| 843 | +						ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; | |
| 844 | +			} else if (is_numeric($reg_step_status) && $reg_step_status !== false) { | |
| 845 | + $reg_steps .= '<li style="color:#2EA2CC">' . sprintf( | |
| 846 | +						esc_html__('%1$s : Initiated %2$s', 'event_espresso'), | |
| 847 | +						ucwords(str_replace('_', ' ', $reg_step)), | |
| 848 | +						date(get_option('date_format') . ' ' . get_option('time_format'), | |
| 849 | +							($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS))) | |
| 850 | + ) . '</li>'; | |
| 851 | +			} else { | |
| 852 | +				$reg_steps .= '<li style="color:#E76700">' . sprintf(esc_html__('%1$s : Never Initiated', | |
| 853 | +						'event_espresso'), ucwords(str_replace('_', ' ', $reg_step))) . '</li>'; | |
| 854 | + } | |
| 855 | + } | |
| 856 | + $reg_steps .= '</ul>'; | |
| 857 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; | |
| 858 | +		$this->_template_args['txn_details']['reg_steps']['label'] = esc_html__('Registration Step Progress', | |
| 859 | + 'event_espresso'); | |
| 860 | + | |
| 861 | + | |
| 862 | + $this->_get_registrations_to_apply_payment_to(); | |
| 863 | + $this->_get_payment_methods($payments); | |
| 864 | + $this->_get_payment_status_array(); | |
| 865 | + $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. | |
| 866 | + | |
| 867 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( | |
| 868 | + 'action' => 'edit_transaction', | |
| 869 | + 'process' => 'transaction' | |
| 870 | + ), TXN_ADMIN_URL); | |
| 871 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( | |
| 872 | + 'page' => 'espresso_transactions', | |
| 873 | + 'action' => 'espresso_apply_payment' | |
| 874 | + ), WP_AJAX_URL); | |
| 875 | + $this->_template_args['delete_payment_form_url'] = add_query_arg(array( | |
| 876 | + 'page' => 'espresso_transactions', | |
| 877 | + 'action' => 'espresso_delete_payment' | |
| 878 | + ), WP_AJAX_URL); | |
| 879 | + | |
| 880 | + // 'espresso_delete_payment_nonce' | |
| 881 | + | |
| 882 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; | |
| 883 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); | |
| 884 | + | |
| 885 | + } | |
| 886 | + | |
| 887 | + | |
| 888 | + /** | |
| 889 | + * _get_registration_payment_IDs | |
| 890 | + * | |
| 891 | + * generates an array of Payment IDs and their corresponding Registration IDs | |
| 892 | + * | |
| 893 | + * @access protected | |
| 894 | + * | |
| 895 | + * @param EE_Payment[] $payments | |
| 896 | + * | |
| 897 | + * @return array | |
| 898 | + */ | |
| 899 | + protected function _get_registration_payment_IDs($payments = array()) | |
| 900 | +	{ | |
| 901 | + $existing_reg_payments = array(); | |
| 902 | + // get all reg payments for these payments | |
| 903 | + $reg_payments = EEM_Registration_Payment::instance()->get_all(array( | |
| 904 | + array( | |
| 905 | + 'PAY_ID' => array( | |
| 906 | + 'IN', | |
| 907 | + array_keys($payments) | |
| 908 | + ) | |
| 909 | + ) | |
| 910 | + )); | |
| 911 | +		if ( ! empty($reg_payments)) { | |
| 912 | +			foreach ($payments as $payment) { | |
| 913 | +				if ( ! $payment instanceof EE_Payment) { | |
| 914 | + continue; | |
| 915 | +				} else if ( ! isset($existing_reg_payments[$payment->ID()])) { | |
| 916 | + $existing_reg_payments[$payment->ID()] = array(); | |
| 917 | + } | |
| 918 | +				foreach ($reg_payments as $reg_payment) { | |
| 919 | +					if ($reg_payment instanceof EE_Registration_Payment && $reg_payment->payment_ID() === $payment->ID()) { | |
| 920 | + $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); | |
| 921 | + } | |
| 922 | + } | |
| 923 | + } | |
| 924 | + } | |
| 925 | + | |
| 926 | + return $existing_reg_payments; | |
| 927 | + } | |
| 928 | + | |
| 929 | + | |
| 930 | + /** | |
| 931 | + * _get_registrations_to_apply_payment_to | |
| 932 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window | |
| 933 | + * which allows the admin to only apply the payment to the specific registrations | |
| 934 | + * | |
| 935 | + * @access protected | |
| 936 | + * @return void | |
| 937 | + * @throws \EE_Error | |
| 938 | + */ | |
| 939 | + protected function _get_registrations_to_apply_payment_to() | |
| 940 | +	{ | |
| 941 | + // we want any registration with an active status (ie: not deleted or cancelled) | |
| 942 | + $query_params = array( | |
| 943 | + array( | |
| 944 | + 'STS_ID' => array( | |
| 945 | + 'IN', | |
| 946 | + array( | |
| 947 | + EEM_Registration::status_id_approved, | |
| 948 | + EEM_Registration::status_id_pending_payment, | |
| 949 | + EEM_Registration::status_id_not_approved, | |
| 950 | + ) | |
| 951 | + ) | |
| 952 | + ) | |
| 953 | + ); | |
| 954 | + $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( | |
| 955 | + '', 'txn-admin-apply-payment-to-registrations-dv', '', 'clear: both; margin: 1.5em 0 0; display: none;' | |
| 956 | + ); | |
| 957 | +		$registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); | |
| 958 | +		$registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); | |
| 959 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( | |
| 960 | + EEH_HTML::tr( | |
| 961 | +				EEH_HTML::th(esc_html__('ID', 'event_espresso')) . | |
| 962 | +				EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . | |
| 963 | +				EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . | |
| 964 | +				EEH_HTML::th(esc_html__('Event', 'event_espresso')) . | |
| 965 | +				EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . | |
| 966 | +				EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . | |
| 967 | +				EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') | |
| 968 | + ) | |
| 969 | + ); | |
| 970 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); | |
| 971 | + // get registrations for TXN | |
| 972 | + $registrations = $this->_transaction->registrations($query_params); | |
| 973 | +		foreach ($registrations as $registration) { | |
| 974 | +			if ($registration instanceof EE_Registration) { | |
| 975 | + $attendee_name = $registration->attendee() instanceof EE_Attendee | |
| 976 | + ? $registration->attendee()->full_name() | |
| 977 | +					: esc_html__('Unknown Attendee', 'event_espresso'); | |
| 978 | + $owing = $registration->final_price() - $registration->paid(); | |
| 979 | + $taxable = $registration->ticket()->taxable() | |
| 980 | +					? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' | |
| 981 | + : ''; | |
| 982 | + $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) | |
| 983 | + ? ' checked="checked"' | |
| 984 | + : ''; | |
| 985 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; | |
| 986 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( | |
| 987 | + EEH_HTML::td($registration->ID()) . | |
| 988 | + EEH_HTML::td($attendee_name) . | |
| 989 | + EEH_HTML::td( | |
| 990 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable | |
| 991 | + ) . | |
| 992 | + EEH_HTML::td($registration->event_name()) . | |
| 993 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . | |
| 994 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . | |
| 995 | + EEH_HTML::td( | |
| 996 | + '<input type="checkbox" value="' . $registration->ID() | |
| 997 | + . '" name="txn_admin_payment[registrations]"' | |
| 998 | + . $checked . $disabled . '>', | |
| 999 | + '', 'jst-cntr' | |
| 1000 | + ), | |
| 1001 | + 'apply-payment-registration-row-' . $registration->ID() | |
| 1002 | + ); | |
| 1003 | + } | |
| 1004 | + } | |
| 1005 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); | |
| 1006 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); | |
| 1007 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); | |
| 1008 | + $registrations_to_apply_payment_to .= EEH_HTML::p( | |
| 1009 | + esc_html__( | |
| 1010 | + 'The payment will only be applied to the registrations that have a check mark in their corresponding check box. Checkboxes for free registrations have been disabled.', | |
| 1011 | + 'event_espresso' | |
| 1012 | + ), | |
| 1013 | + '', 'clear description' | |
| 1014 | + ); | |
| 1015 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); | |
| 1016 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; | |
| 1017 | + } | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + /** | |
| 1021 | + * _get_reg_status_selection | |
| 1022 | + * | |
| 1023 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets | |
| 1024 | + * instead of events. | |
| 1025 | + * @access protected | |
| 1026 | + * @return void | |
| 1027 | + */ | |
| 1028 | + protected function _get_reg_status_selection() | |
| 1029 | +	{ | |
| 1030 | + //first get all possible statuses | |
| 1031 | + $statuses = EEM_Registration::reg_status_array(array(), true); | |
| 1032 | + //let's add a "don't change" option. | |
| 1033 | +		$status_array['NAN']                                 = esc_html__('Leave the Same', 'event_espresso'); | |
| 1034 | + $status_array = array_merge($status_array, $statuses); | |
| 1035 | +		$this->_template_args['status_change_select']        = EEH_Form_Fields::select_input('txn_reg_status_change[reg_status]', | |
| 1036 | + $status_array, 'NAN', 'id="txn-admin-payment-reg-status-inp"', 'txn-reg-status-change-reg-status'); | |
| 1037 | +		$this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input('delete_txn_reg_status_change[reg_status]', | |
| 1038 | + $status_array, 'NAN', 'delete-txn-admin-payment-reg-status-inp', 'delete-txn-reg-status-change-reg-status'); | |
| 1039 | + | |
| 1040 | + } | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + /** | |
| 1044 | + * _get_payment_methods | |
| 1045 | + * Gets all the payment methods available generally, or the ones that are already | |
| 1046 | + * selected on these payments (in case their payment methods are no longer active). | |
| 1047 | + * Has the side-effect of updating the template args' payment_methods item | |
| 1048 | + * @access private | |
| 1049 | + * | |
| 1050 | + * @param EE_Payment[] to show on this page | |
| 1051 | + * | |
| 1052 | + * @return void | |
| 1053 | + */ | |
| 1054 | + private function _get_payment_methods($payments = array()) | |
| 1055 | +	{ | |
| 1056 | + $payment_methods_of_payments = array(); | |
| 1057 | +		foreach ($payments as $payment) { | |
| 1058 | +			if ($payment instanceof EE_Payment) { | |
| 1059 | +				$payment_methods_of_payments[] = $payment->get('PMD_ID'); | |
| 1060 | + } | |
| 1061 | + } | |
| 1062 | +		if ($payment_methods_of_payments) { | |
| 1063 | + $query_args = array( | |
| 1064 | + array( | |
| 1065 | + 'OR*payment_method_for_payment' => array( | |
| 1066 | +						'PMD_ID'    => array('IN', $payment_methods_of_payments), | |
| 1067 | +						'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%') | |
| 1068 | + ) | |
| 1069 | + ) | |
| 1070 | + ); | |
| 1071 | +		} else { | |
| 1072 | +			$query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); | |
| 1073 | + } | |
| 1074 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); | |
| 1075 | + } | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + /** | |
| 1079 | + * txn_attendees_meta_box | |
| 1080 | + * generates HTML for the Attendees Transaction main meta box | |
| 1081 | + * | |
| 1082 | + * @access public | |
| 1083 | + * | |
| 1084 | + * @param WP_Post $post | |
| 1085 | + * @param array $metabox | |
| 1086 | + * | |
| 1087 | + * @return void | |
| 1088 | + */ | |
| 1089 | +	public function txn_attendees_meta_box($post, $metabox = array('args' => array())) | |
| 1090 | +	{ | |
| 1091 | + | |
| 1092 | + extract($metabox['args']); | |
| 1093 | + $this->_template_args['post'] = $post; | |
| 1094 | + $this->_template_args['event_attendees'] = array(); | |
| 1095 | + // process items in cart | |
| 1096 | +		$line_items = $this->_transaction->get_many_related('Line_Item', array(array('LIN_type' => 'line-item'))); | |
| 1097 | +		if ( ! empty($line_items)) { | |
| 1098 | +			foreach ($line_items as $item) { | |
| 1099 | +				if ($item instanceof EE_Line_Item) { | |
| 1100 | +					switch ($item->OBJ_type()) { | |
| 1101 | + | |
| 1102 | + case 'Event' : | |
| 1103 | + break; | |
| 1104 | + | |
| 1105 | + case 'Ticket' : | |
| 1106 | + $ticket = $item->ticket(); | |
| 1107 | + //right now we're only handling tickets here. Cause its expected that only tickets will have attendees right? | |
| 1108 | +							if ( ! $ticket instanceof EE_Ticket) { | |
| 1109 | + continue; | |
| 1110 | + } | |
| 1111 | +							try { | |
| 1112 | + $event_name = $ticket->get_event_name(); | |
| 1113 | +							} catch (Exception $e) { | |
| 1114 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); | |
| 1115 | +								$event_name = esc_html__('Unknown Event', 'event_espresso'); | |
| 1116 | + } | |
| 1117 | +							$event_name .= ' - ' . $item->get('LIN_name'); | |
| 1118 | +							$ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); | |
| 1119 | + // now get all of the registrations for this transaction that use this ticket | |
| 1120 | +							$registrations = $ticket->get_many_related('Registration', | |
| 1121 | +								array(array('TXN_ID' => $this->_transaction->ID()))); | |
| 1122 | +							foreach ($registrations as $registration) { | |
| 1123 | +								if ( ! $registration instanceof EE_Registration) { | |
| 1124 | + continue; | |
| 1125 | + } | |
| 1126 | + $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] = $registration->status_ID(); | |
| 1127 | + $this->_template_args['event_attendees'][$registration->ID()]['att_num'] = $registration->count(); | |
| 1128 | + $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] = $event_name; | |
| 1129 | + $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] = $ticket_price; | |
| 1130 | + // attendee info | |
| 1131 | +								$attendee = $registration->get_first_related('Attendee'); | |
| 1132 | +								if ($attendee instanceof EE_Attendee) { | |
| 1133 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = $attendee->ID(); | |
| 1134 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = $attendee->full_name(); | |
| 1135 | +									$this->_template_args['event_attendees'][$registration->ID()]['email']    = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name . esc_html__(' Event', | |
| 1136 | + 'event_espresso') . '">' . $attendee->email() . '</a>'; | |
| 1137 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = EEH_Address::format($attendee, | |
| 1138 | + 'inline', false, false); | |
| 1139 | +								} else { | |
| 1140 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; | |
| 1141 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; | |
| 1142 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; | |
| 1143 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; | |
| 1144 | + } | |
| 1145 | + } | |
| 1146 | + break; | |
| 1147 | + | |
| 1148 | + } | |
| 1149 | + } | |
| 1150 | + } | |
| 1151 | + | |
| 1152 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( | |
| 1153 | + 'action' => 'edit_transaction', | |
| 1154 | + 'process' => 'attendees' | |
| 1155 | + ), TXN_ADMIN_URL); | |
| 1156 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', | |
| 1157 | + $this->_template_args, true); | |
| 1158 | + | |
| 1159 | +		} else { | |
| 1160 | + echo sprintf( | |
| 1161 | +				esc_html__('%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', | |
| 1162 | + 'event_espresso'), | |
| 1163 | + '<p class="important-notice">', | |
| 1164 | + '</p>' | |
| 1165 | + ); | |
| 1166 | + } | |
| 1167 | + } | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + /** | |
| 1171 | + * txn_registrant_side_meta_box | |
| 1172 | + * generates HTML for the Edit Transaction side meta box | |
| 1173 | + * | |
| 1174 | + * @access public | |
| 1175 | + * @throws \EE_Error | |
| 1176 | + * @return void | |
| 1177 | + */ | |
| 1178 | + public function txn_registrant_side_meta_box() | |
| 1179 | +	{ | |
| 1180 | +		$primary_att = $this->_transaction->primary_registration() instanceof EE_Registration ? $this->_transaction->primary_registration()->get_first_related('Attendee') : null; | |
| 1181 | +		if ( ! $primary_att instanceof EE_Attendee) { | |
| 1182 | +			$this->_template_args['no_attendee_message'] = esc_html__('There is no attached contact for this transaction.  The transaction either failed due to an error or was abandoned.', | |
| 1183 | + 'event_espresso'); | |
| 1184 | + $primary_att = EEM_Attendee::instance()->create_default_object(); | |
| 1185 | + } | |
| 1186 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); | |
| 1187 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); | |
| 1188 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); | |
| 1189 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); | |
| 1190 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); | |
| 1191 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( | |
| 1192 | + 'action' => 'edit_attendee', | |
| 1193 | + 'post' => $primary_att->ID() | |
| 1194 | + ), REG_ADMIN_URL); | |
| 1195 | + // get formatted address for registrant | |
| 1196 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); | |
| 1197 | + echo EEH_Template::display_template(TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', | |
| 1198 | + $this->_template_args, true); | |
| 1199 | + } | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + /** | |
| 1203 | + * txn_billing_info_side_meta_box | |
| 1204 | + * generates HTML for the Edit Transaction side meta box | |
| 1205 | + * | |
| 1206 | + * @access public | |
| 1207 | + * @return void | |
| 1208 | + */ | |
| 1209 | + public function txn_billing_info_side_meta_box() | |
| 1210 | +	{ | |
| 1211 | + | |
| 1212 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); | |
| 1213 | + $this->_template_args['billing_form_url'] = add_query_arg( | |
| 1214 | +			array('action' => 'edit_transaction', 'process' => 'billing'), | |
| 1215 | + TXN_ADMIN_URL | |
| 1216 | + ); | |
| 1217 | + | |
| 1218 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; | |
| 1219 | + echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ | |
| 1220 | + } | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + /** | |
| 1224 | + * apply_payments_or_refunds | |
| 1225 | + * registers a payment or refund made towards a transaction | |
| 1226 | + * | |
| 1227 | + * @access public | |
| 1228 | + * @return void | |
| 1229 | + */ | |
| 1230 | + public function apply_payments_or_refunds() | |
| 1231 | +	{ | |
| 1232 | +		$json_response_data = array('return_data' => false); | |
| 1233 | + $valid_data = $this->_validate_payment_request_data(); | |
| 1234 | +		if ( ! empty($valid_data)) { | |
| 1235 | + $PAY_ID = $valid_data['PAY_ID']; | |
| 1236 | + //save the new payment | |
| 1237 | + $payment = $this->_create_payment_from_request_data($valid_data); | |
| 1238 | + // get the TXN for this payment | |
| 1239 | + $transaction = $payment->transaction(); | |
| 1240 | + // verify transaction | |
| 1241 | +			if ($transaction instanceof EE_Transaction) { | |
| 1242 | + // calculate_total_payments_and_update_status | |
| 1243 | + $this->_process_transaction_payments($transaction); | |
| 1244 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); | |
| 1245 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); | |
| 1246 | + // apply payment to registrations (if applicable) | |
| 1247 | +				if ( ! empty($REG_IDs)) { | |
| 1248 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); | |
| 1249 | + $this->_maybe_send_notifications(); | |
| 1250 | + // now process status changes for the same registrations | |
| 1251 | + $this->_process_registration_status_change($transaction, $REG_IDs); | |
| 1252 | + } | |
| 1253 | + $this->_maybe_send_notifications($payment); | |
| 1254 | + //prepare to render page | |
| 1255 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); | |
| 1256 | +				do_action('AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', $transaction, | |
| 1257 | + $payment); | |
| 1258 | +			} else { | |
| 1259 | + EE_Error::add_error( | |
| 1260 | +					esc_html__('A valid Transaction for this payment could not be retrieved.', 'event_espresso'), | |
| 1261 | + __FILE__, __FUNCTION__, __LINE__ | |
| 1262 | + ); | |
| 1263 | + } | |
| 1264 | +		} else { | |
| 1265 | +			EE_Error::add_error(esc_html__('The payment form data could not be processed. Please try again.', | |
| 1266 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); | |
| 1267 | + } | |
| 1268 | + | |
| 1269 | + $notices = EE_Error::get_notices(false, false, false); | |
| 1270 | + $this->_template_args = array( | |
| 1271 | + 'data' => $json_response_data, | |
| 1272 | + 'error' => $notices['errors'], | |
| 1273 | + 'success' => $notices['success'] | |
| 1274 | + ); | |
| 1275 | + $this->_return_json(); | |
| 1276 | + } | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + /** | |
| 1280 | + * _validate_payment_request_data | |
| 1281 | + * | |
| 1282 | + * @return array | |
| 1283 | + */ | |
| 1284 | + protected function _validate_payment_request_data() | |
| 1285 | +	{ | |
| 1286 | +		if ( ! isset($this->_req_data['txn_admin_payment'])) { | |
| 1287 | + return false; | |
| 1288 | + } | |
| 1289 | + $payment_form = $this->_generate_payment_form_section(); | |
| 1290 | +		try { | |
| 1291 | +			if ($payment_form->was_submitted()) { | |
| 1292 | + $payment_form->receive_form_submission(); | |
| 1293 | +				if ( ! $payment_form->is_valid()) { | |
| 1294 | + $submission_error_messages = array(); | |
| 1295 | +					foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { | |
| 1296 | +						if ($validation_error instanceof EE_Validation_Error) { | |
| 1297 | + $submission_error_messages[] = sprintf( | |
| 1298 | +								_x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), | |
| 1299 | + $validation_error->get_form_section()->html_label_text(), | |
| 1300 | + $validation_error->getMessage() | |
| 1301 | + ); | |
| 1302 | + } | |
| 1303 | + } | |
| 1304 | +					EE_Error::add_error(join('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); | |
| 1305 | + | |
| 1306 | + return array(); | |
| 1307 | + } | |
| 1308 | + } | |
| 1309 | +		} catch (EE_Error $e) { | |
| 1310 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); | |
| 1311 | + | |
| 1312 | + return array(); | |
| 1313 | + } | |
| 1314 | + | |
| 1315 | + return $payment_form->valid_data(); | |
| 1316 | + } | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + /** | |
| 1320 | + * _generate_payment_form_section | |
| 1321 | + * | |
| 1322 | + * @return EE_Form_Section_Proper | |
| 1323 | + */ | |
| 1324 | + protected function _generate_payment_form_section() | |
| 1325 | +	{ | |
| 1326 | + return new EE_Form_Section_Proper( | |
| 1327 | + array( | |
| 1328 | + 'name' => 'txn_admin_payment', | |
| 1329 | + 'subsections' => array( | |
| 1330 | + 'PAY_ID' => new EE_Text_Input( | |
| 1331 | + array( | |
| 1332 | + 'default' => 0, | |
| 1333 | + 'required' => false, | |
| 1334 | +							'html_label_text'       => esc_html__('Payment ID', 'event_espresso'), | |
| 1335 | + 'validation_strategies' => array(new EE_Int_Normalization()) | |
| 1336 | + ) | |
| 1337 | + ), | |
| 1338 | + 'TXN_ID' => new EE_Text_Input( | |
| 1339 | + array( | |
| 1340 | + 'default' => 0, | |
| 1341 | + 'required' => true, | |
| 1342 | +							'html_label_text'       => esc_html__('Transaction ID', 'event_espresso'), | |
| 1343 | + 'validation_strategies' => array(new EE_Int_Normalization()) | |
| 1344 | + ) | |
| 1345 | + ), | |
| 1346 | + 'type' => new EE_Text_Input( | |
| 1347 | + array( | |
| 1348 | + 'default' => 1, | |
| 1349 | + 'required' => true, | |
| 1350 | +							'html_label_text'       => esc_html__('Payment or Refund', 'event_espresso'), | |
| 1351 | + 'validation_strategies' => array(new EE_Int_Normalization()) | |
| 1352 | + ) | |
| 1353 | + ), | |
| 1354 | + 'amount' => new EE_Text_Input( | |
| 1355 | + array( | |
| 1356 | + 'default' => 0, | |
| 1357 | + 'required' => true, | |
| 1358 | +							'html_label_text'       => esc_html__('Payment amount', 'event_espresso'), | |
| 1359 | + 'validation_strategies' => array(new EE_Float_Normalization()) | |
| 1360 | + ) | |
| 1361 | + ), | |
| 1362 | + 'status' => new EE_Text_Input( | |
| 1363 | + array( | |
| 1364 | + 'default' => EEM_Payment::status_id_approved, | |
| 1365 | + 'required' => true, | |
| 1366 | +							'html_label_text' => esc_html__('Payment status', 'event_espresso'), | |
| 1367 | + ) | |
| 1368 | + ), | |
| 1369 | + 'PMD_ID' => new EE_Text_Input( | |
| 1370 | + array( | |
| 1371 | + 'default' => 2, | |
| 1372 | + 'required' => true, | |
| 1373 | +							'html_label_text'       => esc_html__('Payment Method', 'event_espresso'), | |
| 1374 | + 'validation_strategies' => array(new EE_Int_Normalization()) | |
| 1375 | + ) | |
| 1376 | + ), | |
| 1377 | + 'date' => new EE_Text_Input( | |
| 1378 | + array( | |
| 1379 | + 'default' => time(), | |
| 1380 | + 'required' => true, | |
| 1381 | +							'html_label_text' => esc_html__('Payment date', 'event_espresso'), | |
| 1382 | + ) | |
| 1383 | + ), | |
| 1384 | + 'txn_id_chq_nmbr' => new EE_Text_Input( | |
| 1385 | + array( | |
| 1386 | + 'default' => '', | |
| 1387 | + 'required' => false, | |
| 1388 | +							'html_label_text'       => esc_html__('Transaction or Cheque Number', 'event_espresso'), | |
| 1389 | + 'validation_strategies' => array( | |
| 1390 | +								new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), | |
| 1391 | + 100), | |
| 1392 | + ) | |
| 1393 | + ) | |
| 1394 | + ), | |
| 1395 | + 'po_number' => new EE_Text_Input( | |
| 1396 | + array( | |
| 1397 | + 'default' => '', | |
| 1398 | + 'required' => false, | |
| 1399 | +							'html_label_text'       => esc_html__('Purchase Order Number', 'event_espresso'), | |
| 1400 | + 'validation_strategies' => array( | |
| 1401 | +								new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), | |
| 1402 | + 100), | |
| 1403 | + ) | |
| 1404 | + ) | |
| 1405 | + ), | |
| 1406 | + 'accounting' => new EE_Text_Input( | |
| 1407 | + array( | |
| 1408 | + 'default' => '', | |
| 1409 | + 'required' => false, | |
| 1410 | +							'html_label_text'       => esc_html__('Extra Field for Accounting', 'event_espresso'), | |
| 1411 | + 'validation_strategies' => array( | |
| 1412 | +								new EE_Max_Length_Validation_Strategy(esc_html__('Input too long', 'event_espresso'), | |
| 1413 | + 100), | |
| 1414 | + ) | |
| 1415 | + ) | |
| 1416 | + ), | |
| 1417 | + ) | |
| 1418 | + ) | |
| 1419 | + ); | |
| 1420 | + } | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + /** | |
| 1424 | + * _create_payment_from_request_data | |
| 1425 | + * | |
| 1426 | + * @param array $valid_data | |
| 1427 | + * | |
| 1428 | + * @return EE_Payment | |
| 1429 | + */ | |
| 1430 | + protected function _create_payment_from_request_data($valid_data) | |
| 1431 | +	{ | |
| 1432 | + $PAY_ID = $valid_data['PAY_ID']; | |
| 1433 | + // get payment amount | |
| 1434 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; | |
| 1435 | + // payments have a type value of 1 and refunds have a type value of -1 | |
| 1436 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds | |
| 1437 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; | |
| 1438 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. | |
| 1439 | +		$date    = $valid_data['date'] ? preg_replace('/\s+/', ' ', $valid_data['date']) : date('Y-m-d g:i a', | |
| 1440 | +			current_time('timestamp')); | |
| 1441 | + $payment = EE_Payment::new_instance( | |
| 1442 | + array( | |
| 1443 | + 'TXN_ID' => $valid_data['TXN_ID'], | |
| 1444 | + 'STS_ID' => $valid_data['status'], | |
| 1445 | + 'PAY_timestamp' => $date, | |
| 1446 | + 'PAY_source' => EEM_Payment_Method::scope_admin, | |
| 1447 | + 'PMD_ID' => $valid_data['PMD_ID'], | |
| 1448 | + 'PAY_amount' => $amount, | |
| 1449 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], | |
| 1450 | + 'PAY_po_number' => $valid_data['po_number'], | |
| 1451 | + 'PAY_extra_accntng' => $valid_data['accounting'], | |
| 1452 | + 'PAY_details' => $valid_data, | |
| 1453 | + 'PAY_ID' => $PAY_ID | |
| 1454 | + ), | |
| 1455 | + '', | |
| 1456 | +			array('Y-m-d', 'g:i a') | |
| 1457 | + ); | |
| 1458 | + | |
| 1459 | +		if ( ! $payment->save()) { | |
| 1460 | + EE_Error::add_error( | |
| 1461 | + sprintf( | |
| 1462 | +					esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), | |
| 1463 | + $payment->ID() | |
| 1464 | + ), | |
| 1465 | + __FILE__, __FUNCTION__, __LINE__ | |
| 1466 | + ); | |
| 1467 | + } | |
| 1468 | + | |
| 1469 | + return $payment; | |
| 1470 | + } | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + /** | |
| 1474 | + * _process_transaction_payments | |
| 1475 | + * | |
| 1476 | + * @param \EE_Transaction $transaction | |
| 1477 | + * | |
| 1478 | + * @return array | |
| 1479 | + */ | |
| 1480 | + protected function _process_transaction_payments(EE_Transaction $transaction) | |
| 1481 | +	{ | |
| 1482 | + /** @type EE_Transaction_Payments $transaction_payments */ | |
| 1483 | +		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); | |
| 1484 | + //update the transaction with this payment | |
| 1485 | +		if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { | |
| 1486 | +			EE_Error::add_success(esc_html__('The payment has been processed successfully.', 'event_espresso'), | |
| 1487 | + __FILE__, __FUNCTION__, __LINE__); | |
| 1488 | +		} else { | |
| 1489 | + EE_Error::add_error( | |
| 1490 | +				esc_html__('The payment was processed successfully but the amount paid for the transaction was not updated.', | |
| 1491 | + 'event_espresso') | |
| 1492 | + , __FILE__, __FUNCTION__, __LINE__ | |
| 1493 | + ); | |
| 1494 | + } | |
| 1495 | + } | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + /** | |
| 1499 | + * _get_REG_IDs_to_apply_payment_to | |
| 1500 | + * | |
| 1501 | + * returns a list of registration IDs that the payment will apply to | |
| 1502 | + * | |
| 1503 | + * @param \EE_Payment $payment | |
| 1504 | + * | |
| 1505 | + * @return array | |
| 1506 | + */ | |
| 1507 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) | |
| 1508 | +	{ | |
| 1509 | + $REG_IDs = array(); | |
| 1510 | + // grab array of IDs for specific registrations to apply changes to | |
| 1511 | +		if (isset($this->_req_data['txn_admin_payment']['registrations'])) { | |
| 1512 | + $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; | |
| 1513 | + } | |
| 1514 | + //nothing specified ? then get all reg IDs | |
| 1515 | +		if (empty($REG_IDs)) { | |
| 1516 | + $registrations = $payment->transaction()->registrations(); | |
| 1517 | + $REG_IDs = ! empty($registrations) ? array_keys($registrations) : $this->_get_existing_reg_payment_REG_IDs($payment); | |
| 1518 | + } | |
| 1519 | + | |
| 1520 | + // ensure that REG_IDs are integers and NOT strings | |
| 1521 | +		return array_map('intval', $REG_IDs); | |
| 1522 | + } | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + /** | |
| 1526 | + * @return array | |
| 1527 | + */ | |
| 1528 | + public function existing_reg_payment_REG_IDs() | |
| 1529 | +	{ | |
| 1530 | + return $this->_existing_reg_payment_REG_IDs; | |
| 1531 | + } | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + /** | |
| 1535 | + * @param array $existing_reg_payment_REG_IDs | |
| 1536 | + */ | |
| 1537 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) | |
| 1538 | +	{ | |
| 1539 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; | |
| 1540 | + } | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + /** | |
| 1544 | + * _get_existing_reg_payment_REG_IDs | |
| 1545 | + * | |
| 1546 | + * returns a list of registration IDs that the payment is currently related to | |
| 1547 | + * as recorded in the database | |
| 1548 | + * | |
| 1549 | + * @param \EE_Payment $payment | |
| 1550 | + * | |
| 1551 | + * @return array | |
| 1552 | + */ | |
| 1553 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) | |
| 1554 | +	{ | |
| 1555 | +		if ($this->existing_reg_payment_REG_IDs() === null) { | |
| 1556 | + // let's get any existing reg payment records for this payment | |
| 1557 | +			$existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); | |
| 1558 | + // but we only want the REG IDs, so grab the array keys | |
| 1559 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) ? array_keys($existing_reg_payment_REG_IDs) : array(); | |
| 1560 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); | |
| 1561 | + } | |
| 1562 | + | |
| 1563 | + return $this->existing_reg_payment_REG_IDs(); | |
| 1564 | + } | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + /** | |
| 1568 | + * _remove_existing_registration_payments | |
| 1569 | + * | |
| 1570 | + * this calculates the difference between existing relations | |
| 1571 | + * to the supplied payment and the new list registration IDs, | |
| 1572 | + * removes any related registrations that no longer apply, | |
| 1573 | + * and then updates the registration paid fields | |
| 1574 | + * | |
| 1575 | + * @param \EE_Payment $payment | |
| 1576 | + * @param int $PAY_ID | |
| 1577 | + * | |
| 1578 | + * @return bool; | |
| 1579 | + */ | |
| 1580 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) | |
| 1581 | +	{ | |
| 1582 | + // newly created payments will have nothing recorded for $PAY_ID | |
| 1583 | +		if ($PAY_ID == 0) { | |
| 1584 | + return false; | |
| 1585 | + } | |
| 1586 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); | |
| 1587 | +		if (empty($existing_reg_payment_REG_IDs)) { | |
| 1588 | + return false; | |
| 1589 | + } | |
| 1590 | + /** @type EE_Transaction_Payments $transaction_payments */ | |
| 1591 | +		$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); | |
| 1592 | + | |
| 1593 | + return $transaction_payments->delete_registration_payments_and_update_registrations( | |
| 1594 | + $payment, | |
| 1595 | + array( | |
| 1596 | + array( | |
| 1597 | + 'PAY_ID' => $payment->ID(), | |
| 1598 | +					'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), | |
| 1599 | + ) | |
| 1600 | + ) | |
| 1601 | + ); | |
| 1602 | + } | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + /** | |
| 1606 | + * _update_registration_payments | |
| 1607 | + * | |
| 1608 | + * this applies the payments to the selected registrations | |
| 1609 | + * but only if they have not already been paid for | |
| 1610 | + * | |
| 1611 | + * @param EE_Transaction $transaction | |
| 1612 | + * @param \EE_Payment $payment | |
| 1613 | + * @param array $REG_IDs | |
| 1614 | + * | |
| 1615 | + * @return bool | |
| 1616 | + */ | |
| 1617 | + protected function _update_registration_payments( | |
| 1618 | + EE_Transaction $transaction, | |
| 1619 | + EE_Payment $payment, | |
| 1620 | + $REG_IDs = array() | |
| 1621 | +	) { | |
| 1622 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() | |
| 1623 | + // so let's do that using our set of REG_IDs from the form | |
| 1624 | + $registration_query_where_params = array( | |
| 1625 | +			'REG_ID' => array('IN', $REG_IDs) | |
| 1626 | + ); | |
| 1627 | + // but add in some conditions regarding payment, | |
| 1628 | + // so that we don't apply payments to registrations that are free or have already been paid for | |
| 1629 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) | |
| 1630 | +		if ( ! $payment->is_a_refund()) { | |
| 1631 | +			$registration_query_where_params['REG_final_price']  = array('!=', 0); | |
| 1632 | +			$registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); | |
| 1633 | + } | |
| 1634 | + //EEH_Debug_Tools::printr( $registration_query_where_params, '$registration_query_where_params', __FILE__, __LINE__ ); | |
| 1635 | + $registrations = $transaction->registrations(array($registration_query_where_params)); | |
| 1636 | +		if ( ! empty($registrations)) { | |
| 1637 | + /** @type EE_Payment_Processor $payment_processor */ | |
| 1638 | +			$payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); | |
| 1639 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); | |
| 1640 | + } | |
| 1641 | + } | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + /** | |
| 1645 | + * _process_registration_status_change | |
| 1646 | + * | |
| 1647 | + * This processes requested registration status changes for all the registrations | |
| 1648 | + * on a given transaction and (optionally) sends out notifications for the changes. | |
| 1649 | + * | |
| 1650 | + * @param EE_Transaction $transaction | |
| 1651 | + * @param array $REG_IDs | |
| 1652 | + * | |
| 1653 | + * @return bool | |
| 1654 | + */ | |
| 1655 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) | |
| 1656 | +	{ | |
| 1657 | + // first if there is no change in status then we get out. | |
| 1658 | + if ( | |
| 1659 | + ! isset($this->_req_data['txn_reg_status_change'], $this->_req_data['txn_reg_status_change']['reg_status']) | |
| 1660 | + || $this->_req_data['txn_reg_status_change']['reg_status'] == 'NAN' | |
| 1661 | +		) { | |
| 1662 | + //no error message, no change requested, just nothing to do man. | |
| 1663 | + return false; | |
| 1664 | + } | |
| 1665 | + /** @type EE_Transaction_Processor $transaction_processor */ | |
| 1666 | +		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); | |
| 1667 | + | |
| 1668 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses | |
| 1669 | + return $transaction_processor->manually_update_registration_statuses( | |
| 1670 | + $transaction, | |
| 1671 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), | |
| 1672 | +			array(array('REG_ID' => array('IN', $REG_IDs))) | |
| 1673 | + ); | |
| 1674 | + } | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + /** | |
| 1678 | + * _build_payment_json_response | |
| 1679 | + * | |
| 1680 | + * @access public | |
| 1681 | + * | |
| 1682 | + * @param \EE_Payment $payment | |
| 1683 | + * @param array $REG_IDs | |
| 1684 | + * @param bool | null $delete_txn_reg_status_change | |
| 1685 | + * | |
| 1686 | + * @return array | |
| 1687 | + */ | |
| 1688 | + protected function _build_payment_json_response( | |
| 1689 | + EE_Payment $payment, | |
| 1690 | + $REG_IDs = array(), | |
| 1691 | + $delete_txn_reg_status_change = null | |
| 1692 | +	) { | |
| 1693 | + // was the payment deleted ? | |
| 1694 | +		if (is_bool($delete_txn_reg_status_change)) { | |
| 1695 | + return array( | |
| 1696 | + 'PAY_ID' => $payment->ID(), | |
| 1697 | + 'amount' => $payment->amount(), | |
| 1698 | + 'total_paid' => $payment->transaction()->paid(), | |
| 1699 | + 'txn_status' => $payment->transaction()->status_ID(), | |
| 1700 | + 'pay_status' => $payment->STS_ID(), | |
| 1701 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), | |
| 1702 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, | |
| 1703 | + ); | |
| 1704 | +		} else { | |
| 1705 | + $this->_get_payment_status_array(); | |
| 1706 | + | |
| 1707 | + return array( | |
| 1708 | + 'amount' => $payment->amount(), | |
| 1709 | + 'total_paid' => $payment->transaction()->paid(), | |
| 1710 | + 'txn_status' => $payment->transaction()->status_ID(), | |
| 1711 | + 'pay_status' => $payment->STS_ID(), | |
| 1712 | + 'PAY_ID' => $payment->ID(), | |
| 1713 | + 'STS_ID' => $payment->STS_ID(), | |
| 1714 | + 'status' => self::$_pay_status[$payment->STS_ID()], | |
| 1715 | +				'date'             => $payment->timestamp('Y-m-d', 'h:i a'), | |
| 1716 | + 'method' => strtoupper($payment->source()), | |
| 1717 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, | |
| 1718 | +				'gateway'          => $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", | |
| 1719 | + 'event_espresso'), | |
| 1720 | + 'gateway_response' => $payment->gateway_response(), | |
| 1721 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), | |
| 1722 | + 'po_number' => $payment->po_number(), | |
| 1723 | + 'extra_accntng' => $payment->extra_accntng(), | |
| 1724 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), | |
| 1725 | + ); | |
| 1726 | + } | |
| 1727 | + } | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + /** | |
| 1731 | + * delete_payment | |
| 1732 | + * delete a payment or refund made towards a transaction | |
| 1733 | + * | |
| 1734 | + * @access public | |
| 1735 | + * @return void | |
| 1736 | + */ | |
| 1737 | + public function delete_payment() | |
| 1738 | +	{ | |
| 1739 | +		$json_response_data = array('return_data' => false); | |
| 1740 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment'], $this->_req_data['delete_txn_admin_payment']['PAY_ID']) ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) : 0; | |
| 1741 | +		if ($PAY_ID) { | |
| 1742 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) ? $this->_req_data['delete_txn_reg_status_change'] : false; | |
| 1743 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); | |
| 1744 | +			if ($payment instanceof EE_Payment) { | |
| 1745 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); | |
| 1746 | + /** @type EE_Transaction_Payments $transaction_payments */ | |
| 1747 | +				$transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); | |
| 1748 | +				if ($transaction_payments->delete_payment_and_update_transaction($payment)) { | |
| 1749 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs, | |
| 1750 | + $delete_txn_reg_status_change); | |
| 1751 | +					if ($delete_txn_reg_status_change) { | |
| 1752 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; | |
| 1753 | + //MAKE sure we also add the delete_txn_req_status_change to the | |
| 1754 | + //$_REQUEST global because that's how messages will be looking for it. | |
| 1755 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; | |
| 1756 | + $this->_maybe_send_notifications(); | |
| 1757 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); | |
| 1758 | + } | |
| 1759 | + } | |
| 1760 | +			} else { | |
| 1761 | + EE_Error::add_error( | |
| 1762 | +					esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), | |
| 1763 | + __FILE__, __FUNCTION__, __LINE__ | |
| 1764 | + ); | |
| 1765 | + } | |
| 1766 | +		} else { | |
| 1767 | + EE_Error::add_error( | |
| 1768 | +				esc_html__('A valid Payment ID was not received, therefore payment form data could not be loaded.', | |
| 1769 | + 'event_espresso'), | |
| 1770 | + __FILE__, __FUNCTION__, __LINE__ | |
| 1771 | + ); | |
| 1772 | + } | |
| 1773 | + $notices = EE_Error::get_notices(false, false, false); | |
| 1774 | + $this->_template_args = array( | |
| 1775 | + 'data' => $json_response_data, | |
| 1776 | + 'success' => $notices['success'], | |
| 1777 | + 'error' => $notices['errors'], | |
| 1778 | + 'attention' => $notices['attention'] | |
| 1779 | + ); | |
| 1780 | + $this->_return_json(); | |
| 1781 | + } | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + /** | |
| 1785 | + * _registration_payment_data_array | |
| 1786 | + * adds info for 'owing' and 'paid' for each registration to the json response | |
| 1787 | + * | |
| 1788 | + * @access protected | |
| 1789 | + * | |
| 1790 | + * @param array $REG_IDs | |
| 1791 | + * | |
| 1792 | + * @return array | |
| 1793 | + */ | |
| 1794 | + protected function _registration_payment_data_array($REG_IDs) | |
| 1795 | +	{ | |
| 1796 | + $registration_payment_data = array(); | |
| 1797 | + //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. | |
| 1798 | +		if ( ! empty($REG_IDs)) { | |
| 1799 | +			$registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); | |
| 1800 | +			foreach ($registrations as $registration) { | |
| 1801 | +				if ($registration instanceof EE_Registration) { | |
| 1802 | + $registration_payment_data[$registration->ID()] = array( | |
| 1803 | + 'paid' => $registration->pretty_paid(), | |
| 1804 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), | |
| 1805 | + ); | |
| 1806 | + } | |
| 1807 | + } | |
| 1808 | + } | |
| 1809 | + | |
| 1810 | + return $registration_payment_data; | |
| 1811 | + } | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + /** | |
| 1815 | + * _maybe_send_notifications | |
| 1816 | + * | |
| 1817 | + * determines whether or not the admin has indicated that notifications should be sent. | |
| 1818 | + * If so, will toggle a filter switch for delivering registration notices. | |
| 1819 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. | |
| 1820 | + * | |
| 1821 | + * @access protected | |
| 1822 | + * | |
| 1823 | + * @param \EE_Payment | null $payment | |
| 1824 | + */ | |
| 1825 | + protected function _maybe_send_notifications($payment = null) | |
| 1826 | +	{ | |
| 1827 | +		switch ($payment instanceof EE_Payment) { | |
| 1828 | + // payment notifications | |
| 1829 | + case true : | |
| 1830 | + if ( | |
| 1831 | + isset( | |
| 1832 | + $this->_req_data['txn_payments'], | |
| 1833 | + $this->_req_data['txn_payments']['send_notifications'] | |
| 1834 | + ) && | |
| 1835 | + filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) | |
| 1836 | +				) { | |
| 1837 | + $this->_process_payment_notification($payment); | |
| 1838 | + } | |
| 1839 | + break; | |
| 1840 | + // registration notifications | |
| 1841 | + case false : | |
| 1842 | + if ( | |
| 1843 | + isset( | |
| 1844 | + $this->_req_data['txn_reg_status_change'], | |
| 1845 | + $this->_req_data['txn_reg_status_change']['send_notifications'] | |
| 1846 | + ) && | |
| 1847 | + filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) | |
| 1848 | +				) { | |
| 1849 | +					add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); | |
| 1850 | + } | |
| 1851 | + break; | |
| 1852 | + } | |
| 1853 | + } | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + /** | |
| 1857 | + * _send_payment_reminder | |
| 1858 | + * generates HTML for the View Transaction Details Admin page | |
| 1859 | + * | |
| 1860 | + * @access protected | |
| 1861 | + * @return void | |
| 1862 | + */ | |
| 1863 | + protected function _send_payment_reminder() | |
| 1864 | +	{ | |
| 1865 | + $TXN_ID = ( ! empty($this->_req_data['TXN_ID'])) ? absint($this->_req_data['TXN_ID']) : false; | |
| 1866 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); | |
| 1867 | + $query_args = isset($this->_req_data['redirect_to']) ? array( | |
| 1868 | + 'action' => $this->_req_data['redirect_to'], | |
| 1869 | + 'TXN_ID' => $this->_req_data['TXN_ID'] | |
| 1870 | + ) : array(); | |
| 1871 | +		do_action('AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', | |
| 1872 | + $transaction); | |
| 1873 | +		$this->_redirect_after_action(false, esc_html__('payment reminder', 'event_espresso'), | |
| 1874 | +			esc_html__('sent', 'event_espresso'), $query_args, true); | |
| 1875 | + } | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + /** | |
| 1879 | + * get_transactions | |
| 1880 | + * get transactions for given parameters (used by list table) | |
| 1881 | + * | |
| 1882 | + * @param int $perpage how many transactions displayed per page | |
| 1883 | + * @param boolean $count return the count or objects | |
| 1884 | + * @param string $view | |
| 1885 | + * | |
| 1886 | + * @return mixed int = count || array of transaction objects | |
| 1887 | + */ | |
| 1888 | + public function get_transactions($perpage, $count = false, $view = '') | |
| 1889 | +	{ | |
| 1890 | + | |
| 1891 | + $TXN = EEM_Transaction::instance(); | |
| 1892 | + | |
| 1893 | +		$start_date = isset($this->_req_data['txn-filter-start-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) : date('m/d/Y', | |
| 1894 | +			strtotime('-10 year')); | |
| 1895 | +		$end_date   = isset($this->_req_data['txn-filter-end-date']) ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) : date('m/d/Y'); | |
| 1896 | + | |
| 1897 | + //make sure our timestamps start and end right at the boundaries for each day | |
| 1898 | +		$start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; | |
| 1899 | +		$end_date   = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + //convert to timestamps | |
| 1903 | + $start_date = strtotime($start_date); | |
| 1904 | + $end_date = strtotime($end_date); | |
| 1905 | + | |
| 1906 | + //makes sure start date is the lowest value and vice versa | |
| 1907 | + $start_date = min($start_date, $end_date); | |
| 1908 | + $end_date = max($start_date, $end_date); | |
| 1909 | + | |
| 1910 | + //convert to correct format for query | |
| 1911 | +		$start_date = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', | |
| 1912 | +			date('Y-m-d H:i:s', $start_date), 'Y-m-d H:i:s'); | |
| 1913 | +		$end_date   = EEM_Transaction::instance()->convert_datetime_for_query('TXN_timestamp', | |
| 1914 | +			date('Y-m-d H:i:s', $end_date), 'Y-m-d H:i:s'); | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + //set orderby | |
| 1918 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; | |
| 1919 | + | |
| 1920 | +		switch ($this->_req_data['orderby']) { | |
| 1921 | + case 'TXN_ID': | |
| 1922 | + $orderby = 'TXN_ID'; | |
| 1923 | + break; | |
| 1924 | + case 'ATT_fname': | |
| 1925 | + $orderby = 'Registration.Attendee.ATT_fname'; | |
| 1926 | + break; | |
| 1927 | + case 'event_name': | |
| 1928 | + $orderby = 'Registration.Event.EVT_name'; | |
| 1929 | + break; | |
| 1930 | + default: //'TXN_timestamp' | |
| 1931 | + $orderby = 'TXN_timestamp'; | |
| 1932 | + } | |
| 1933 | + | |
| 1934 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'DESC'; | |
| 1935 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; | |
| 1936 | + $per_page = isset($perpage) && ! empty($perpage) ? $perpage : 10; | |
| 1937 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; | |
| 1938 | + | |
| 1939 | + $offset = ($current_page - 1) * $per_page; | |
| 1940 | + $limit = array($offset, $per_page); | |
| 1941 | + | |
| 1942 | + $_where = array( | |
| 1943 | +			'TXN_timestamp'          => array('BETWEEN', array($start_date, $end_date)), | |
| 1944 | + 'Registration.REG_count' => 1 | |
| 1945 | + ); | |
| 1946 | + | |
| 1947 | +		if (isset($this->_req_data['EVT_ID'])) { | |
| 1948 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; | |
| 1949 | + } | |
| 1950 | + | |
| 1951 | +		if (isset($this->_req_data['s'])) { | |
| 1952 | + $search_string = '%' . $this->_req_data['s'] . '%'; | |
| 1953 | + $_where['OR'] = array( | |
| 1954 | +				'Registration.Event.EVT_name'         => array('LIKE', $search_string), | |
| 1955 | +				'Registration.Event.EVT_desc'         => array('LIKE', $search_string), | |
| 1956 | +				'Registration.Event.EVT_short_desc'   => array('LIKE', $search_string), | |
| 1957 | +				'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), | |
| 1958 | +				'Registration.Attendee.ATT_fname'     => array('LIKE', $search_string), | |
| 1959 | +				'Registration.Attendee.ATT_lname'     => array('LIKE', $search_string), | |
| 1960 | +				'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), | |
| 1961 | +				'Registration.Attendee.ATT_email'     => array('LIKE', $search_string), | |
| 1962 | +				'Registration.Attendee.ATT_address'   => array('LIKE', $search_string), | |
| 1963 | +				'Registration.Attendee.ATT_address2'  => array('LIKE', $search_string), | |
| 1964 | +				'Registration.Attendee.ATT_city'      => array('LIKE', $search_string), | |
| 1965 | +				'Registration.REG_final_price'        => array('LIKE', $search_string), | |
| 1966 | +				'Registration.REG_code'               => array('LIKE', $search_string), | |
| 1967 | +				'Registration.REG_count'              => array('LIKE', $search_string), | |
| 1968 | +				'Registration.REG_group_size'         => array('LIKE', $search_string), | |
| 1969 | +				'Registration.Ticket.TKT_name'        => array('LIKE', $search_string), | |
| 1970 | +				'Registration.Ticket.TKT_description' => array('LIKE', $search_string), | |
| 1971 | +				'Payment.PAY_source'                  => array('LIKE', $search_string), | |
| 1972 | +				'Payment.Payment_Method.PMD_name'     => array('LIKE', $search_string), | |
| 1973 | +				'TXN_session_data'                    => array('LIKE', $search_string), | |
| 1974 | +				'Payment.PAY_txn_id_chq_nmbr'         => array('LIKE', $search_string) | |
| 1975 | + ); | |
| 1976 | + } | |
| 1977 | + | |
| 1978 | + //failed transactions | |
| 1979 | + $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'failed' && ! $count) || ($count && $view == 'failed') ? true : false; | |
| 1980 | + $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] == 'abandoned' && ! $count) || ($count && $view == 'abandoned') ? true : false; | |
| 1981 | + | |
| 1982 | +		if ($failed) { | |
| 1983 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; | |
| 1984 | +		} else if ($abandoned) { | |
| 1985 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; | |
| 1986 | +		} else { | |
| 1987 | +			$_where['STS_ID']  = array('!=', EEM_Transaction::failed_status_code); | |
| 1988 | +			$_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); | |
| 1989 | + } | |
| 1990 | + | |
| 1991 | + $query_params = array($_where, 'order_by' => array($orderby => $sort), 'limit' => $limit); | |
| 1992 | + | |
| 1993 | + $transactions = $count ? $TXN->count(array($_where), 'TXN_ID', true) : $TXN->get_all($query_params); | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + return $transactions; | |
| 1997 | + | |
| 1998 | + } | |
| 1999 | 1999 | |
| 2000 | 2000 | |
| 2001 | 2001 | } | 
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 | use EventEspresso\core\exceptions\InvalidDataTypeException; | 
| 3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; | 
| 4 | -use EventEspresso\core\services\loaders\LoaderFactory; | |
| 5 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; | 
| 6 | 5 | |
| 7 | 6 |  if (! defined('EVENT_ESPRESSO_VERSION')) { | 
| @@ -4,7 +4,7 @@ discard block | ||
| 4 | 4 | use EventEspresso\core\services\loaders\LoaderFactory; | 
| 5 | 5 | use EventEspresso\core\services\loaders\LoaderInterface; | 
| 6 | 6 | |
| 7 | -if (! defined('EVENT_ESPRESSO_VERSION')) { | |
| 7 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { | |
| 8 | 8 |      exit('No direct script access allowed'); | 
| 9 | 9 | } | 
| 10 | 10 | |
| @@ -130,7 +130,7 @@ discard block | ||
| 130 | 130 | public static function instance(EE_Request $request = null, EE_Response $response = null) | 
| 131 | 131 |      { | 
| 132 | 132 | // check if class object is instantiated, and instantiated properly | 
| 133 | -        if (! self::$_instance instanceof EE_Dependency_Map) { | |
| 133 | +        if ( ! self::$_instance instanceof EE_Dependency_Map) { | |
| 134 | 134 | self::$_instance = new EE_Dependency_Map($request, $response); | 
| 135 | 135 | } | 
| 136 | 136 | return self::$_instance; | 
| @@ -185,16 +185,16 @@ discard block | ||
| 185 | 185 |      ) { | 
| 186 | 186 | $class = trim($class, '\\'); | 
| 187 | 187 | $registered = false; | 
| 188 | -        if (empty(self::$_instance->_dependency_map[ $class ])) { | |
| 189 | - self::$_instance->_dependency_map[ $class ] = array(); | |
| 188 | +        if (empty(self::$_instance->_dependency_map[$class])) { | |
| 189 | + self::$_instance->_dependency_map[$class] = array(); | |
| 190 | 190 | } | 
| 191 | 191 | // we need to make sure that any aliases used when registering a dependency | 
| 192 | 192 | // get resolved to the correct class name | 
| 193 | -        foreach ((array)$dependencies as $dependency => $load_source) { | |
| 193 | +        foreach ((array) $dependencies as $dependency => $load_source) { | |
| 194 | 194 | $alias = self::$_instance->get_alias($dependency); | 
| 195 | 195 | if ( | 
| 196 | 196 | $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES | 
| 197 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) | |
| 197 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) | |
| 198 | 198 |              ) { | 
| 199 | 199 | unset($dependencies[$dependency]); | 
| 200 | 200 | $dependencies[$alias] = $load_source; | 
| @@ -207,13 +207,13 @@ discard block | ||
| 207 | 207 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C | 
| 208 | 208 | // Union is way faster than array_merge() but should be used with caution... | 
| 209 | 209 | // especially with numerically indexed arrays | 
| 210 | - $dependencies += self::$_instance->_dependency_map[ $class ]; | |
| 210 | + $dependencies += self::$_instance->_dependency_map[$class]; | |
| 211 | 211 | // now we need to ensure that the resulting dependencies | 
| 212 | 212 | // array only has the entries that are required for the class | 
| 213 | 213 | // so first count how many dependencies were originally registered for the class | 
| 214 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); | |
| 214 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); | |
| 215 | 215 | // if that count is non-zero (meaning dependencies were already registered) | 
| 216 | - self::$_instance->_dependency_map[ $class ] = $dependency_count | |
| 216 | + self::$_instance->_dependency_map[$class] = $dependency_count | |
| 217 | 217 | // then truncate the final array to match that count | 
| 218 | 218 | ? array_slice($dependencies, 0, $dependency_count) | 
| 219 | 219 | // otherwise just take the incoming array because nothing previously existed | 
| @@ -231,7 +231,7 @@ discard block | ||
| 231 | 231 | */ | 
| 232 | 232 | public static function register_class_loader($class_name, $loader = 'load_core') | 
| 233 | 233 |      { | 
| 234 | -        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { | |
| 234 | +        if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { | |
| 235 | 235 | throw new DomainException( | 
| 236 | 236 |                  esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') | 
| 237 | 237 | ); | 
| @@ -255,7 +255,7 @@ discard block | ||
| 255 | 255 | ); | 
| 256 | 256 | } | 
| 257 | 257 | $class_name = self::$_instance->get_alias($class_name); | 
| 258 | -        if (! isset(self::$_instance->_class_loaders[$class_name])) { | |
| 258 | +        if ( ! isset(self::$_instance->_class_loaders[$class_name])) { | |
| 259 | 259 | self::$_instance->_class_loaders[$class_name] = $loader; | 
| 260 | 260 | return true; | 
| 261 | 261 | } | 
| @@ -340,7 +340,7 @@ discard block | ||
| 340 | 340 | public function class_loader($class_name) | 
| 341 | 341 |      { | 
| 342 | 342 | // all legacy models use load_model() | 
| 343 | -        if(strpos($class_name, 'EEM_') === 0){ | |
| 343 | +        if (strpos($class_name, 'EEM_') === 0) { | |
| 344 | 344 | return 'load_model'; | 
| 345 | 345 | } | 
| 346 | 346 | $class_name = $this->get_alias($class_name); | 
| @@ -369,7 +369,7 @@ discard block | ||
| 369 | 369 | public function add_alias($class_name, $alias, $for_class = '') | 
| 370 | 370 |      { | 
| 371 | 371 |          if ($for_class !== '') { | 
| 372 | -            if (! isset($this->_aliases[$for_class])) { | |
| 372 | +            if ( ! isset($this->_aliases[$for_class])) { | |
| 373 | 373 | $this->_aliases[$for_class] = array(); | 
| 374 | 374 | } | 
| 375 | 375 | $this->_aliases[$for_class][$class_name] = $alias; | 
| @@ -415,10 +415,10 @@ discard block | ||
| 415 | 415 | */ | 
| 416 | 416 | public function get_alias($class_name = '', $for_class = '') | 
| 417 | 417 |      { | 
| 418 | -        if (! $this->has_alias($class_name, $for_class)) { | |
| 418 | +        if ( ! $this->has_alias($class_name, $for_class)) { | |
| 419 | 419 | return $class_name; | 
| 420 | 420 | } | 
| 421 | -        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { | |
| 421 | +        if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) { | |
| 422 | 422 | return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); | 
| 423 | 423 | } | 
| 424 | 424 | return $this->get_alias($this->_aliases[$class_name]); | 
| @@ -664,10 +664,10 @@ discard block | ||
| 664 | 664 | 'EE_Front_Controller' => 'load_core', | 
| 665 | 665 | 'EE_Module_Request_Router' => 'load_core', | 
| 666 | 666 | 'EE_Registry' => 'load_core', | 
| 667 | -            'EE_Request'                           => function () use (&$request) { | |
| 667 | +            'EE_Request'                           => function() use (&$request) { | |
| 668 | 668 | return $request; | 
| 669 | 669 | }, | 
| 670 | -            'EE_Response'                          => function () use (&$response) { | |
| 670 | +            'EE_Response'                          => function() use (&$response) { | |
| 671 | 671 | return $response; | 
| 672 | 672 | }, | 
| 673 | 673 | 'EE_Request_Handler' => 'load_core', | 
| @@ -684,7 +684,7 @@ discard block | ||
| 684 | 684 | 'EE_Messages_Queue' => 'load_lib', | 
| 685 | 685 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', | 
| 686 | 686 | 'EE_Message_Template_Group_Collection' => 'load_lib', | 
| 687 | -            'EE_Messages_Generator'                => function () { | |
| 687 | +            'EE_Messages_Generator'                => function() { | |
| 688 | 688 | return EE_Registry::instance()->load_lib( | 
| 689 | 689 | 'Messages_Generator', | 
| 690 | 690 | array(), | 
| @@ -692,7 +692,7 @@ discard block | ||
| 692 | 692 | false | 
| 693 | 693 | ); | 
| 694 | 694 | }, | 
| 695 | -            'EE_Messages_Template_Defaults'        => function ($arguments = array()) { | |
| 695 | +            'EE_Messages_Template_Defaults'        => function($arguments = array()) { | |
| 696 | 696 | return EE_Registry::instance()->load_lib( | 
| 697 | 697 | 'Messages_Template_Defaults', | 
| 698 | 698 | $arguments, | 
| @@ -705,19 +705,19 @@ discard block | ||
| 705 | 705 | // 'EEM_Message_Template_Group' => 'load_model', | 
| 706 | 706 | // 'EEM_Message_Template' => 'load_model', | 
| 707 | 707 | //load_helper | 
| 708 | -            'EEH_Parse_Shortcodes'                 => function () { | |
| 708 | +            'EEH_Parse_Shortcodes'                 => function() { | |
| 709 | 709 |                  if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { | 
| 710 | 710 | return new EEH_Parse_Shortcodes(); | 
| 711 | 711 | } | 
| 712 | 712 | return null; | 
| 713 | 713 | }, | 
| 714 | -            'EE_Template_Config'                   => function () { | |
| 714 | +            'EE_Template_Config'                   => function() { | |
| 715 | 715 | return EE_Config::instance()->template_settings; | 
| 716 | 716 | }, | 
| 717 | -            'EE_Currency_Config'                   => function () { | |
| 717 | +            'EE_Currency_Config'                   => function() { | |
| 718 | 718 | return EE_Config::instance()->currency; | 
| 719 | 719 | }, | 
| 720 | -            'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { | |
| 720 | +            'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) { | |
| 721 | 721 | return $loader; | 
| 722 | 722 | }, | 
| 723 | 723 | ); | 
| @@ -5,7 +5,7 @@ discard block | ||
| 5 | 5 | use EventEspresso\core\services\loaders\LoaderInterface; | 
| 6 | 6 | |
| 7 | 7 |  if (! defined('EVENT_ESPRESSO_VERSION')) { | 
| 8 | -    exit('No direct script access allowed'); | |
| 8 | +	exit('No direct script access allowed'); | |
| 9 | 9 | } | 
| 10 | 10 | |
| 11 | 11 | |
| @@ -22,772 +22,772 @@ discard block | ||
| 22 | 22 | class EE_Dependency_Map | 
| 23 | 23 |  { | 
| 24 | 24 | |
| 25 | - /** | |
| 26 | - * This means that the requested class dependency is not present in the dependency map | |
| 27 | - */ | |
| 28 | - const not_registered = 0; | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. | |
| 32 | - */ | |
| 33 | - const load_new_object = 1; | |
| 34 | - | |
| 35 | - /** | |
| 36 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. | |
| 37 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. | |
| 38 | - */ | |
| 39 | - const load_from_cache = 2; | |
| 40 | - | |
| 41 | - /** | |
| 42 | - * When registering a dependency, | |
| 43 | - * this indicates to keep any existing dependencies that already exist, | |
| 44 | - * and simply discard any new dependencies declared in the incoming data | |
| 45 | - */ | |
| 46 | - const KEEP_EXISTING_DEPENDENCIES = 0; | |
| 47 | - | |
| 48 | - /** | |
| 49 | - * When registering a dependency, | |
| 50 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data | |
| 51 | - */ | |
| 52 | - const OVERWRITE_DEPENDENCIES = 1; | |
| 53 | - | |
| 54 | - | |
| 55 | - | |
| 56 | - /** | |
| 57 | - * @type EE_Dependency_Map $_instance | |
| 58 | - */ | |
| 59 | - protected static $_instance; | |
| 60 | - | |
| 61 | - /** | |
| 62 | - * @type EE_Request $request | |
| 63 | - */ | |
| 64 | - protected $_request; | |
| 65 | - | |
| 66 | - /** | |
| 67 | - * @type EE_Response $response | |
| 68 | - */ | |
| 69 | - protected $_response; | |
| 70 | - | |
| 71 | - /** | |
| 72 | - * @type LoaderInterface $loader | |
| 73 | - */ | |
| 74 | - protected $loader; | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * @type array $_dependency_map | |
| 78 | - */ | |
| 79 | - protected $_dependency_map = array(); | |
| 80 | - | |
| 81 | - /** | |
| 82 | - * @type array $_class_loaders | |
| 83 | - */ | |
| 84 | - protected $_class_loaders = array(); | |
| 85 | - | |
| 86 | - /** | |
| 87 | - * @type array $_aliases | |
| 88 | - */ | |
| 89 | - protected $_aliases = array(); | |
| 90 | - | |
| 91 | - | |
| 92 | - | |
| 93 | - /** | |
| 94 | - * EE_Dependency_Map constructor. | |
| 95 | - * | |
| 96 | - * @param EE_Request $request | |
| 97 | - * @param EE_Response $response | |
| 98 | - */ | |
| 99 | - protected function __construct(EE_Request $request, EE_Response $response) | |
| 100 | -    { | |
| 101 | - $this->_request = $request; | |
| 102 | - $this->_response = $response; | |
| 103 | -        add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); | |
| 104 | -        do_action('EE_Dependency_Map____construct'); | |
| 105 | - } | |
| 106 | - | |
| 107 | - | |
| 108 | - | |
| 109 | - /** | |
| 110 | - * @throws InvalidDataTypeException | |
| 111 | - * @throws InvalidInterfaceException | |
| 112 | - * @throws InvalidArgumentException | |
| 113 | - */ | |
| 114 | - public function initialize() | |
| 115 | -    { | |
| 116 | - $this->_register_core_dependencies(); | |
| 117 | - $this->_register_core_class_loaders(); | |
| 118 | - $this->_register_core_aliases(); | |
| 119 | - } | |
| 120 | - | |
| 121 | - | |
| 122 | - | |
| 123 | - /** | |
| 124 | - * @singleton method used to instantiate class object | |
| 125 | - * @access public | |
| 126 | - * @param EE_Request $request | |
| 127 | - * @param EE_Response $response | |
| 128 | - * @return EE_Dependency_Map | |
| 129 | - */ | |
| 130 | - public static function instance(EE_Request $request = null, EE_Response $response = null) | |
| 131 | -    { | |
| 132 | - // check if class object is instantiated, and instantiated properly | |
| 133 | -        if (! self::$_instance instanceof EE_Dependency_Map) { | |
| 134 | - self::$_instance = new EE_Dependency_Map($request, $response); | |
| 135 | - } | |
| 136 | - return self::$_instance; | |
| 137 | - } | |
| 138 | - | |
| 139 | - | |
| 140 | - | |
| 141 | - /** | |
| 142 | - * @param LoaderInterface $loader | |
| 143 | - */ | |
| 144 | - public function setLoader(LoaderInterface $loader) | |
| 145 | -    { | |
| 146 | - $this->loader = $loader; | |
| 147 | - } | |
| 148 | - | |
| 149 | - | |
| 150 | - | |
| 151 | - /** | |
| 152 | - * @param string $class | |
| 153 | - * @param array $dependencies | |
| 154 | - * @param int $overwrite | |
| 155 | - * @return bool | |
| 156 | - */ | |
| 157 | - public static function register_dependencies( | |
| 158 | - $class, | |
| 159 | - array $dependencies, | |
| 160 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES | |
| 161 | -    ) { | |
| 162 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); | |
| 163 | - } | |
| 164 | - | |
| 165 | - | |
| 166 | - | |
| 167 | - /** | |
| 168 | - * Assigns an array of class names and corresponding load sources (new or cached) | |
| 169 | - * to the class specified by the first parameter. | |
| 170 | - * IMPORTANT !!! | |
| 171 | - * The order of elements in the incoming $dependencies array MUST match | |
| 172 | - * the order of the constructor parameters for the class in question. | |
| 173 | - * This is especially important when overriding any existing dependencies that are registered. | |
| 174 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. | |
| 175 | - * | |
| 176 | - * @param string $class | |
| 177 | - * @param array $dependencies | |
| 178 | - * @param int $overwrite | |
| 179 | - * @return bool | |
| 180 | - */ | |
| 181 | - public function registerDependencies( | |
| 182 | - $class, | |
| 183 | - array $dependencies, | |
| 184 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES | |
| 185 | -    ) { | |
| 186 | - $class = trim($class, '\\'); | |
| 187 | - $registered = false; | |
| 188 | -        if (empty(self::$_instance->_dependency_map[ $class ])) { | |
| 189 | - self::$_instance->_dependency_map[ $class ] = array(); | |
| 190 | - } | |
| 191 | - // we need to make sure that any aliases used when registering a dependency | |
| 192 | - // get resolved to the correct class name | |
| 193 | -        foreach ((array)$dependencies as $dependency => $load_source) { | |
| 194 | - $alias = self::$_instance->get_alias($dependency); | |
| 195 | - if ( | |
| 196 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES | |
| 197 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) | |
| 198 | -            ) { | |
| 199 | - unset($dependencies[$dependency]); | |
| 200 | - $dependencies[$alias] = $load_source; | |
| 201 | - $registered = true; | |
| 202 | - } | |
| 203 | - } | |
| 204 | - // now add our two lists of dependencies together. | |
| 205 | - // using Union (+=) favours the arrays in precedence from left to right, | |
| 206 | - // so $dependencies is NOT overwritten because it is listed first | |
| 207 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C | |
| 208 | - // Union is way faster than array_merge() but should be used with caution... | |
| 209 | - // especially with numerically indexed arrays | |
| 210 | - $dependencies += self::$_instance->_dependency_map[ $class ]; | |
| 211 | - // now we need to ensure that the resulting dependencies | |
| 212 | - // array only has the entries that are required for the class | |
| 213 | - // so first count how many dependencies were originally registered for the class | |
| 214 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); | |
| 215 | - // if that count is non-zero (meaning dependencies were already registered) | |
| 216 | - self::$_instance->_dependency_map[ $class ] = $dependency_count | |
| 217 | - // then truncate the final array to match that count | |
| 218 | - ? array_slice($dependencies, 0, $dependency_count) | |
| 219 | - // otherwise just take the incoming array because nothing previously existed | |
| 220 | - : $dependencies; | |
| 221 | - return $registered; | |
| 222 | - } | |
| 223 | - | |
| 224 | - | |
| 225 | - | |
| 226 | - /** | |
| 227 | - * @param string $class_name | |
| 228 | - * @param string $loader | |
| 229 | - * @return bool | |
| 230 | - * @throws DomainException | |
| 231 | - */ | |
| 232 | - public static function register_class_loader($class_name, $loader = 'load_core') | |
| 233 | -    { | |
| 234 | -        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { | |
| 235 | - throw new DomainException( | |
| 236 | -                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') | |
| 237 | - ); | |
| 238 | - } | |
| 239 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry | |
| 240 | - if ( | |
| 241 | - ! is_callable($loader) | |
| 242 | - && ( | |
| 243 | - strpos($loader, 'load_') !== 0 | |
| 244 | -                || ! method_exists('EE_Registry', $loader) | |
| 245 | - ) | |
| 246 | -        ) { | |
| 247 | - throw new DomainException( | |
| 248 | - sprintf( | |
| 249 | - esc_html__( | |
| 250 | - '"%1$s" is not a valid loader method on EE_Registry.', | |
| 251 | - 'event_espresso' | |
| 252 | - ), | |
| 253 | - $loader | |
| 254 | - ) | |
| 255 | - ); | |
| 256 | - } | |
| 257 | - $class_name = self::$_instance->get_alias($class_name); | |
| 258 | -        if (! isset(self::$_instance->_class_loaders[$class_name])) { | |
| 259 | - self::$_instance->_class_loaders[$class_name] = $loader; | |
| 260 | - return true; | |
| 261 | - } | |
| 262 | - return false; | |
| 263 | - } | |
| 264 | - | |
| 265 | - | |
| 266 | - | |
| 267 | - /** | |
| 268 | - * @return array | |
| 269 | - */ | |
| 270 | - public function dependency_map() | |
| 271 | -    { | |
| 272 | - return $this->_dependency_map; | |
| 273 | - } | |
| 274 | - | |
| 275 | - | |
| 276 | - | |
| 277 | - /** | |
| 278 | - * returns TRUE if dependency map contains a listing for the provided class name | |
| 279 | - * | |
| 280 | - * @param string $class_name | |
| 281 | - * @return boolean | |
| 282 | - */ | |
| 283 | - public function has($class_name = '') | |
| 284 | -    { | |
| 285 | - // all legacy models have the same dependencies | |
| 286 | -        if (strpos($class_name, 'EEM_') === 0) { | |
| 287 | - $class_name = 'LEGACY_MODELS'; | |
| 288 | - } | |
| 289 | - return isset($this->_dependency_map[$class_name]) ? true : false; | |
| 290 | - } | |
| 291 | - | |
| 292 | - | |
| 293 | - | |
| 294 | - /** | |
| 295 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency | |
| 296 | - * | |
| 297 | - * @param string $class_name | |
| 298 | - * @param string $dependency | |
| 299 | - * @return bool | |
| 300 | - */ | |
| 301 | - public function has_dependency_for_class($class_name = '', $dependency = '') | |
| 302 | -    { | |
| 303 | - // all legacy models have the same dependencies | |
| 304 | -        if (strpos($class_name, 'EEM_') === 0) { | |
| 305 | - $class_name = 'LEGACY_MODELS'; | |
| 306 | - } | |
| 307 | - $dependency = $this->get_alias($dependency); | |
| 308 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) | |
| 309 | - ? true | |
| 310 | - : false; | |
| 311 | - } | |
| 312 | - | |
| 313 | - | |
| 314 | - | |
| 315 | - /** | |
| 316 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned | |
| 317 | - * | |
| 318 | - * @param string $class_name | |
| 319 | - * @param string $dependency | |
| 320 | - * @return int | |
| 321 | - */ | |
| 322 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') | |
| 323 | -    { | |
| 324 | - // all legacy models have the same dependencies | |
| 325 | -        if (strpos($class_name, 'EEM_') === 0) { | |
| 326 | - $class_name = 'LEGACY_MODELS'; | |
| 327 | - } | |
| 328 | - $dependency = $this->get_alias($dependency); | |
| 329 | - return $this->has_dependency_for_class($class_name, $dependency) | |
| 330 | - ? $this->_dependency_map[$class_name][$dependency] | |
| 331 | - : EE_Dependency_Map::not_registered; | |
| 332 | - } | |
| 333 | - | |
| 334 | - | |
| 335 | - | |
| 336 | - /** | |
| 337 | - * @param string $class_name | |
| 338 | - * @return string | Closure | |
| 339 | - */ | |
| 340 | - public function class_loader($class_name) | |
| 341 | -    { | |
| 342 | - // all legacy models use load_model() | |
| 343 | -        if(strpos($class_name, 'EEM_') === 0){ | |
| 344 | - return 'load_model'; | |
| 345 | - } | |
| 346 | - $class_name = $this->get_alias($class_name); | |
| 347 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; | |
| 348 | - } | |
| 349 | - | |
| 350 | - | |
| 351 | - | |
| 352 | - /** | |
| 353 | - * @return array | |
| 354 | - */ | |
| 355 | - public function class_loaders() | |
| 356 | -    { | |
| 357 | - return $this->_class_loaders; | |
| 358 | - } | |
| 359 | - | |
| 360 | - | |
| 361 | - | |
| 362 | - /** | |
| 363 | - * adds an alias for a classname | |
| 364 | - * | |
| 365 | - * @param string $class_name the class name that should be used (concrete class to replace interface) | |
| 366 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) | |
| 367 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) | |
| 368 | - */ | |
| 369 | - public function add_alias($class_name, $alias, $for_class = '') | |
| 370 | -    { | |
| 371 | -        if ($for_class !== '') { | |
| 372 | -            if (! isset($this->_aliases[$for_class])) { | |
| 373 | - $this->_aliases[$for_class] = array(); | |
| 374 | - } | |
| 375 | - $this->_aliases[$for_class][$class_name] = $alias; | |
| 376 | - } | |
| 377 | - $this->_aliases[$class_name] = $alias; | |
| 378 | - } | |
| 379 | - | |
| 380 | - | |
| 381 | - | |
| 382 | - /** | |
| 383 | - * returns TRUE if the provided class name has an alias | |
| 384 | - * | |
| 385 | - * @param string $class_name | |
| 386 | - * @param string $for_class | |
| 387 | - * @return bool | |
| 388 | - */ | |
| 389 | - public function has_alias($class_name = '', $for_class = '') | |
| 390 | -    { | |
| 391 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) | |
| 392 | - || ( | |
| 393 | - isset($this->_aliases[$class_name]) | |
| 394 | - && ! is_array($this->_aliases[$class_name]) | |
| 395 | - ); | |
| 396 | - } | |
| 397 | - | |
| 398 | - | |
| 399 | - | |
| 400 | - /** | |
| 401 | - * returns alias for class name if one exists, otherwise returns the original classname | |
| 402 | - * functions recursively, so that multiple aliases can be used to drill down to a classname | |
| 403 | - * for example: | |
| 404 | - * if the following two entries were added to the _aliases array: | |
| 405 | - * array( | |
| 406 | - * 'interface_alias' => 'some\namespace\interface' | |
| 407 | - * 'some\namespace\interface' => 'some\namespace\classname' | |
| 408 | - * ) | |
| 409 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) | |
| 410 | - * to load an instance of 'some\namespace\classname' | |
| 411 | - * | |
| 412 | - * @param string $class_name | |
| 413 | - * @param string $for_class | |
| 414 | - * @return string | |
| 415 | - */ | |
| 416 | - public function get_alias($class_name = '', $for_class = '') | |
| 417 | -    { | |
| 418 | -        if (! $this->has_alias($class_name, $for_class)) { | |
| 419 | - return $class_name; | |
| 420 | - } | |
| 421 | -        if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { | |
| 422 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); | |
| 423 | - } | |
| 424 | - return $this->get_alias($this->_aliases[$class_name]); | |
| 425 | - } | |
| 426 | - | |
| 427 | - | |
| 428 | - | |
| 429 | - /** | |
| 430 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, | |
| 431 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. | |
| 432 | - * This is done by using the following class constants: | |
| 433 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object | |
| 434 | - * EE_Dependency_Map::load_new_object - generates a new object every time | |
| 435 | - */ | |
| 436 | - protected function _register_core_dependencies() | |
| 437 | -    { | |
| 438 | - $this->_dependency_map = array( | |
| 439 | - 'EE_Request_Handler' => array( | |
| 440 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, | |
| 441 | - ), | |
| 442 | - 'EE_System' => array( | |
| 443 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, | |
| 444 | - ), | |
| 445 | - 'EE_Session' => array( | |
| 446 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, | |
| 447 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, | |
| 448 | - ), | |
| 449 | - 'EE_Cart' => array( | |
| 450 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, | |
| 451 | - ), | |
| 452 | - 'EE_Front_Controller' => array( | |
| 453 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, | |
| 454 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, | |
| 455 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, | |
| 456 | - ), | |
| 457 | - 'EE_Messenger_Collection_Loader' => array( | |
| 458 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, | |
| 459 | - ), | |
| 460 | - 'EE_Message_Type_Collection_Loader' => array( | |
| 461 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, | |
| 462 | - ), | |
| 463 | - 'EE_Message_Resource_Manager' => array( | |
| 464 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, | |
| 465 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, | |
| 466 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, | |
| 467 | - ), | |
| 468 | - 'EE_Message_Factory' => array( | |
| 469 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, | |
| 470 | - ), | |
| 471 | - 'EE_messages' => array( | |
| 472 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, | |
| 473 | - ), | |
| 474 | - 'EE_Messages_Generator' => array( | |
| 475 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, | |
| 476 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, | |
| 477 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, | |
| 478 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, | |
| 479 | - ), | |
| 480 | - 'EE_Messages_Processor' => array( | |
| 481 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, | |
| 482 | - ), | |
| 483 | - 'EE_Messages_Queue' => array( | |
| 484 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, | |
| 485 | - ), | |
| 486 | - 'EE_Messages_Template_Defaults' => array( | |
| 487 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, | |
| 488 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, | |
| 489 | - ), | |
| 490 | - 'EE_Message_To_Generate_From_Request' => array( | |
| 491 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, | |
| 492 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, | |
| 493 | - ), | |
| 494 | - 'EventEspresso\core\services\commands\CommandBus' => array( | |
| 495 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, | |
| 496 | - ), | |
| 497 | - 'EventEspresso\services\commands\CommandHandler' => array( | |
| 498 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, | |
| 499 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, | |
| 500 | - ), | |
| 501 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( | |
| 502 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, | |
| 503 | - ), | |
| 504 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( | |
| 505 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, | |
| 506 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, | |
| 507 | - ), | |
| 508 | - 'EventEspresso\core\services\commands\CommandFactory' => array( | |
| 509 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, | |
| 510 | - ), | |
| 511 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( | |
| 512 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, | |
| 513 | - ), | |
| 514 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( | |
| 515 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, | |
| 516 | - ), | |
| 517 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( | |
| 518 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, | |
| 519 | - ), | |
| 520 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( | |
| 521 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, | |
| 522 | - ), | |
| 523 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( | |
| 524 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, | |
| 525 | - ), | |
| 526 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( | |
| 527 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, | |
| 528 | - ), | |
| 529 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( | |
| 530 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, | |
| 531 | - ), | |
| 532 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( | |
| 533 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, | |
| 534 | - ), | |
| 535 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( | |
| 536 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, | |
| 537 | - ), | |
| 538 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( | |
| 539 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, | |
| 540 | - ), | |
| 541 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( | |
| 542 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, | |
| 543 | - ), | |
| 544 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( | |
| 545 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, | |
| 546 | - ), | |
| 547 | - 'EventEspresso\core\services\database\TableManager' => array( | |
| 548 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 549 | - ), | |
| 550 | - 'EE_Data_Migration_Class_Base' => array( | |
| 551 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 552 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 553 | - ), | |
| 554 | - 'EE_DMS_Core_4_1_0' => array( | |
| 555 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 556 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 557 | - ), | |
| 558 | - 'EE_DMS_Core_4_2_0' => array( | |
| 559 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 560 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 561 | - ), | |
| 562 | - 'EE_DMS_Core_4_3_0' => array( | |
| 563 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 564 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 565 | - ), | |
| 566 | - 'EE_DMS_Core_4_4_0' => array( | |
| 567 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 568 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 569 | - ), | |
| 570 | - 'EE_DMS_Core_4_5_0' => array( | |
| 571 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 572 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 573 | - ), | |
| 574 | - 'EE_DMS_Core_4_6_0' => array( | |
| 575 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 576 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 577 | - ), | |
| 578 | - 'EE_DMS_Core_4_7_0' => array( | |
| 579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 580 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 581 | - ), | |
| 582 | - 'EE_DMS_Core_4_8_0' => array( | |
| 583 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 584 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 585 | - ), | |
| 586 | - 'EE_DMS_Core_4_9_0' => array( | |
| 587 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 588 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 589 | - ), | |
| 590 | - 'EventEspresso\core\services\assets\Registry' => array( | |
| 591 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, | |
| 592 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, | |
| 593 | - ), | |
| 594 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( | |
| 595 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 596 | - ), | |
| 597 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( | |
| 598 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 599 | - ), | |
| 600 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( | |
| 601 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 602 | - ), | |
| 603 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( | |
| 604 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 605 | - ), | |
| 606 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( | |
| 607 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 608 | - ), | |
| 609 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( | |
| 610 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 611 | - ), | |
| 612 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( | |
| 613 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 614 | - ), | |
| 615 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( | |
| 616 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, | |
| 617 | - ), | |
| 618 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( | |
| 619 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, | |
| 620 | - ), | |
| 621 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( | |
| 622 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, | |
| 623 | - ), | |
| 624 | - 'LEGACY_MODELS' => array( | |
| 625 | - null, | |
| 626 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, | |
| 627 | - ), | |
| 628 | - 'EE_Module_Request_Router' => array( | |
| 629 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, | |
| 630 | - ), | |
| 631 | - ); | |
| 632 | - } | |
| 633 | - | |
| 634 | - | |
| 635 | - | |
| 636 | - /** | |
| 637 | - * Registers how core classes are loaded. | |
| 638 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: | |
| 639 | - * 'EE_Request_Handler' => 'load_core' | |
| 640 | - * 'EE_Messages_Queue' => 'load_lib' | |
| 641 | - * 'EEH_Debug_Tools' => 'load_helper' | |
| 642 | - * or, if greater control is required, by providing a custom closure. For example: | |
| 643 | -     *        'Some_Class' => function () { | |
| 644 | - * return new Some_Class(); | |
| 645 | - * }, | |
| 646 | - * This is required for instantiating dependencies | |
| 647 | - * where an interface has been type hinted in a class constructor. For example: | |
| 648 | -     *        'Required_Interface' => function () { | |
| 649 | - * return new A_Class_That_Implements_Required_Interface(); | |
| 650 | - * }, | |
| 651 | - * | |
| 652 | - * @throws InvalidInterfaceException | |
| 653 | - * @throws InvalidDataTypeException | |
| 654 | - * @throws InvalidArgumentException | |
| 655 | - */ | |
| 656 | - protected function _register_core_class_loaders() | |
| 657 | -    { | |
| 658 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot | |
| 659 | - //be used in a closure. | |
| 660 | - $request = &$this->_request; | |
| 661 | - $response = &$this->_response; | |
| 662 | - $loader = &$this->loader; | |
| 663 | - $this->_class_loaders = array( | |
| 664 | - //load_core | |
| 665 | - 'EE_Capabilities' => 'load_core', | |
| 666 | - 'EE_Encryption' => 'load_core', | |
| 667 | - 'EE_Front_Controller' => 'load_core', | |
| 668 | - 'EE_Module_Request_Router' => 'load_core', | |
| 669 | - 'EE_Registry' => 'load_core', | |
| 670 | -            'EE_Request'                           => function () use (&$request) { | |
| 671 | - return $request; | |
| 672 | - }, | |
| 673 | -            'EE_Response'                          => function () use (&$response) { | |
| 674 | - return $response; | |
| 675 | - }, | |
| 676 | - 'EE_Request_Handler' => 'load_core', | |
| 677 | - 'EE_Session' => 'load_core', | |
| 678 | - 'EE_Cron_Tasks' => 'load_core', | |
| 679 | - //load_lib | |
| 680 | - 'EE_Message_Resource_Manager' => 'load_lib', | |
| 681 | - 'EE_Message_Type_Collection' => 'load_lib', | |
| 682 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', | |
| 683 | - 'EE_Messenger_Collection' => 'load_lib', | |
| 684 | - 'EE_Messenger_Collection_Loader' => 'load_lib', | |
| 685 | - 'EE_Messages_Processor' => 'load_lib', | |
| 686 | - 'EE_Message_Repository' => 'load_lib', | |
| 687 | - 'EE_Messages_Queue' => 'load_lib', | |
| 688 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', | |
| 689 | - 'EE_Message_Template_Group_Collection' => 'load_lib', | |
| 690 | -            'EE_Messages_Generator'                => function () { | |
| 691 | - return EE_Registry::instance()->load_lib( | |
| 692 | - 'Messages_Generator', | |
| 693 | - array(), | |
| 694 | - false, | |
| 695 | - false | |
| 696 | - ); | |
| 697 | - }, | |
| 698 | -            'EE_Messages_Template_Defaults'        => function ($arguments = array()) { | |
| 699 | - return EE_Registry::instance()->load_lib( | |
| 700 | - 'Messages_Template_Defaults', | |
| 701 | - $arguments, | |
| 702 | - false, | |
| 703 | - false | |
| 704 | - ); | |
| 705 | - }, | |
| 706 | - //load_model | |
| 707 | - // 'EEM_Attendee' => 'load_model', | |
| 708 | - // 'EEM_Message_Template_Group' => 'load_model', | |
| 709 | - // 'EEM_Message_Template' => 'load_model', | |
| 710 | - //load_helper | |
| 711 | -            'EEH_Parse_Shortcodes'                 => function () { | |
| 712 | -                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { | |
| 713 | - return new EEH_Parse_Shortcodes(); | |
| 714 | - } | |
| 715 | - return null; | |
| 716 | - }, | |
| 717 | -            'EE_Template_Config'                   => function () { | |
| 718 | - return EE_Config::instance()->template_settings; | |
| 719 | - }, | |
| 720 | -            'EE_Currency_Config'                   => function () { | |
| 721 | - return EE_Config::instance()->currency; | |
| 722 | - }, | |
| 723 | -            'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { | |
| 724 | - return $loader; | |
| 725 | - }, | |
| 726 | - ); | |
| 727 | - } | |
| 728 | - | |
| 729 | - | |
| 730 | - | |
| 731 | - /** | |
| 732 | - * can be used for supplying alternate names for classes, | |
| 733 | - * or for connecting interface names to instantiable classes | |
| 734 | - */ | |
| 735 | - protected function _register_core_aliases() | |
| 736 | -    { | |
| 737 | - $this->_aliases = array( | |
| 738 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', | |
| 739 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', | |
| 740 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', | |
| 741 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', | |
| 742 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', | |
| 743 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', | |
| 744 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', | |
| 745 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', | |
| 746 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', | |
| 747 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', | |
| 748 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', | |
| 749 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', | |
| 750 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', | |
| 751 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', | |
| 752 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', | |
| 753 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', | |
| 754 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', | |
| 755 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', | |
| 756 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', | |
| 757 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', | |
| 758 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', | |
| 759 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', | |
| 760 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', | |
| 761 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', | |
| 762 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', | |
| 763 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', | |
| 764 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', | |
| 765 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', | |
| 766 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', | |
| 767 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', | |
| 768 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', | |
| 769 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', | |
| 770 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', | |
| 771 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', | |
| 772 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', | |
| 773 | - ); | |
| 774 | - } | |
| 775 | - | |
| 776 | - | |
| 777 | - | |
| 778 | - /** | |
| 779 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the | |
| 780 | - * request Primarily used by unit tests. | |
| 781 | - * | |
| 782 | - * @throws InvalidDataTypeException | |
| 783 | - * @throws InvalidInterfaceException | |
| 784 | - * @throws InvalidArgumentException | |
| 785 | - */ | |
| 786 | - public function reset() | |
| 787 | -    { | |
| 788 | - $this->_register_core_class_loaders(); | |
| 789 | - $this->_register_core_dependencies(); | |
| 790 | - } | |
| 25 | + /** | |
| 26 | + * This means that the requested class dependency is not present in the dependency map | |
| 27 | + */ | |
| 28 | + const not_registered = 0; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. | |
| 32 | + */ | |
| 33 | + const load_new_object = 1; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. | |
| 37 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. | |
| 38 | + */ | |
| 39 | + const load_from_cache = 2; | |
| 40 | + | |
| 41 | + /** | |
| 42 | + * When registering a dependency, | |
| 43 | + * this indicates to keep any existing dependencies that already exist, | |
| 44 | + * and simply discard any new dependencies declared in the incoming data | |
| 45 | + */ | |
| 46 | + const KEEP_EXISTING_DEPENDENCIES = 0; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * When registering a dependency, | |
| 50 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data | |
| 51 | + */ | |
| 52 | + const OVERWRITE_DEPENDENCIES = 1; | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * @type EE_Dependency_Map $_instance | |
| 58 | + */ | |
| 59 | + protected static $_instance; | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * @type EE_Request $request | |
| 63 | + */ | |
| 64 | + protected $_request; | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * @type EE_Response $response | |
| 68 | + */ | |
| 69 | + protected $_response; | |
| 70 | + | |
| 71 | + /** | |
| 72 | + * @type LoaderInterface $loader | |
| 73 | + */ | |
| 74 | + protected $loader; | |
| 75 | + | |
| 76 | + /** | |
| 77 | + * @type array $_dependency_map | |
| 78 | + */ | |
| 79 | + protected $_dependency_map = array(); | |
| 80 | + | |
| 81 | + /** | |
| 82 | + * @type array $_class_loaders | |
| 83 | + */ | |
| 84 | + protected $_class_loaders = array(); | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * @type array $_aliases | |
| 88 | + */ | |
| 89 | + protected $_aliases = array(); | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + /** | |
| 94 | + * EE_Dependency_Map constructor. | |
| 95 | + * | |
| 96 | + * @param EE_Request $request | |
| 97 | + * @param EE_Response $response | |
| 98 | + */ | |
| 99 | + protected function __construct(EE_Request $request, EE_Response $response) | |
| 100 | +	{ | |
| 101 | + $this->_request = $request; | |
| 102 | + $this->_response = $response; | |
| 103 | +		add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); | |
| 104 | +		do_action('EE_Dependency_Map____construct'); | |
| 105 | + } | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + /** | |
| 110 | + * @throws InvalidDataTypeException | |
| 111 | + * @throws InvalidInterfaceException | |
| 112 | + * @throws InvalidArgumentException | |
| 113 | + */ | |
| 114 | + public function initialize() | |
| 115 | +	{ | |
| 116 | + $this->_register_core_dependencies(); | |
| 117 | + $this->_register_core_class_loaders(); | |
| 118 | + $this->_register_core_aliases(); | |
| 119 | + } | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + /** | |
| 124 | + * @singleton method used to instantiate class object | |
| 125 | + * @access public | |
| 126 | + * @param EE_Request $request | |
| 127 | + * @param EE_Response $response | |
| 128 | + * @return EE_Dependency_Map | |
| 129 | + */ | |
| 130 | + public static function instance(EE_Request $request = null, EE_Response $response = null) | |
| 131 | +	{ | |
| 132 | + // check if class object is instantiated, and instantiated properly | |
| 133 | +		if (! self::$_instance instanceof EE_Dependency_Map) { | |
| 134 | + self::$_instance = new EE_Dependency_Map($request, $response); | |
| 135 | + } | |
| 136 | + return self::$_instance; | |
| 137 | + } | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + /** | |
| 142 | + * @param LoaderInterface $loader | |
| 143 | + */ | |
| 144 | + public function setLoader(LoaderInterface $loader) | |
| 145 | +	{ | |
| 146 | + $this->loader = $loader; | |
| 147 | + } | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + /** | |
| 152 | + * @param string $class | |
| 153 | + * @param array $dependencies | |
| 154 | + * @param int $overwrite | |
| 155 | + * @return bool | |
| 156 | + */ | |
| 157 | + public static function register_dependencies( | |
| 158 | + $class, | |
| 159 | + array $dependencies, | |
| 160 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES | |
| 161 | +	) { | |
| 162 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); | |
| 163 | + } | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + /** | |
| 168 | + * Assigns an array of class names and corresponding load sources (new or cached) | |
| 169 | + * to the class specified by the first parameter. | |
| 170 | + * IMPORTANT !!! | |
| 171 | + * The order of elements in the incoming $dependencies array MUST match | |
| 172 | + * the order of the constructor parameters for the class in question. | |
| 173 | + * This is especially important when overriding any existing dependencies that are registered. | |
| 174 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. | |
| 175 | + * | |
| 176 | + * @param string $class | |
| 177 | + * @param array $dependencies | |
| 178 | + * @param int $overwrite | |
| 179 | + * @return bool | |
| 180 | + */ | |
| 181 | + public function registerDependencies( | |
| 182 | + $class, | |
| 183 | + array $dependencies, | |
| 184 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES | |
| 185 | +	) { | |
| 186 | + $class = trim($class, '\\'); | |
| 187 | + $registered = false; | |
| 188 | +		if (empty(self::$_instance->_dependency_map[ $class ])) { | |
| 189 | + self::$_instance->_dependency_map[ $class ] = array(); | |
| 190 | + } | |
| 191 | + // we need to make sure that any aliases used when registering a dependency | |
| 192 | + // get resolved to the correct class name | |
| 193 | +		foreach ((array)$dependencies as $dependency => $load_source) { | |
| 194 | + $alias = self::$_instance->get_alias($dependency); | |
| 195 | + if ( | |
| 196 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES | |
| 197 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) | |
| 198 | +			) { | |
| 199 | + unset($dependencies[$dependency]); | |
| 200 | + $dependencies[$alias] = $load_source; | |
| 201 | + $registered = true; | |
| 202 | + } | |
| 203 | + } | |
| 204 | + // now add our two lists of dependencies together. | |
| 205 | + // using Union (+=) favours the arrays in precedence from left to right, | |
| 206 | + // so $dependencies is NOT overwritten because it is listed first | |
| 207 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C | |
| 208 | + // Union is way faster than array_merge() but should be used with caution... | |
| 209 | + // especially with numerically indexed arrays | |
| 210 | + $dependencies += self::$_instance->_dependency_map[ $class ]; | |
| 211 | + // now we need to ensure that the resulting dependencies | |
| 212 | + // array only has the entries that are required for the class | |
| 213 | + // so first count how many dependencies were originally registered for the class | |
| 214 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); | |
| 215 | + // if that count is non-zero (meaning dependencies were already registered) | |
| 216 | + self::$_instance->_dependency_map[ $class ] = $dependency_count | |
| 217 | + // then truncate the final array to match that count | |
| 218 | + ? array_slice($dependencies, 0, $dependency_count) | |
| 219 | + // otherwise just take the incoming array because nothing previously existed | |
| 220 | + : $dependencies; | |
| 221 | + return $registered; | |
| 222 | + } | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + /** | |
| 227 | + * @param string $class_name | |
| 228 | + * @param string $loader | |
| 229 | + * @return bool | |
| 230 | + * @throws DomainException | |
| 231 | + */ | |
| 232 | + public static function register_class_loader($class_name, $loader = 'load_core') | |
| 233 | +	{ | |
| 234 | +		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { | |
| 235 | + throw new DomainException( | |
| 236 | +				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') | |
| 237 | + ); | |
| 238 | + } | |
| 239 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry | |
| 240 | + if ( | |
| 241 | + ! is_callable($loader) | |
| 242 | + && ( | |
| 243 | + strpos($loader, 'load_') !== 0 | |
| 244 | +				|| ! method_exists('EE_Registry', $loader) | |
| 245 | + ) | |
| 246 | +		) { | |
| 247 | + throw new DomainException( | |
| 248 | + sprintf( | |
| 249 | + esc_html__( | |
| 250 | + '"%1$s" is not a valid loader method on EE_Registry.', | |
| 251 | + 'event_espresso' | |
| 252 | + ), | |
| 253 | + $loader | |
| 254 | + ) | |
| 255 | + ); | |
| 256 | + } | |
| 257 | + $class_name = self::$_instance->get_alias($class_name); | |
| 258 | +		if (! isset(self::$_instance->_class_loaders[$class_name])) { | |
| 259 | + self::$_instance->_class_loaders[$class_name] = $loader; | |
| 260 | + return true; | |
| 261 | + } | |
| 262 | + return false; | |
| 263 | + } | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + /** | |
| 268 | + * @return array | |
| 269 | + */ | |
| 270 | + public function dependency_map() | |
| 271 | +	{ | |
| 272 | + return $this->_dependency_map; | |
| 273 | + } | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + /** | |
| 278 | + * returns TRUE if dependency map contains a listing for the provided class name | |
| 279 | + * | |
| 280 | + * @param string $class_name | |
| 281 | + * @return boolean | |
| 282 | + */ | |
| 283 | + public function has($class_name = '') | |
| 284 | +	{ | |
| 285 | + // all legacy models have the same dependencies | |
| 286 | +		if (strpos($class_name, 'EEM_') === 0) { | |
| 287 | + $class_name = 'LEGACY_MODELS'; | |
| 288 | + } | |
| 289 | + return isset($this->_dependency_map[$class_name]) ? true : false; | |
| 290 | + } | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + /** | |
| 295 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency | |
| 296 | + * | |
| 297 | + * @param string $class_name | |
| 298 | + * @param string $dependency | |
| 299 | + * @return bool | |
| 300 | + */ | |
| 301 | + public function has_dependency_for_class($class_name = '', $dependency = '') | |
| 302 | +	{ | |
| 303 | + // all legacy models have the same dependencies | |
| 304 | +		if (strpos($class_name, 'EEM_') === 0) { | |
| 305 | + $class_name = 'LEGACY_MODELS'; | |
| 306 | + } | |
| 307 | + $dependency = $this->get_alias($dependency); | |
| 308 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) | |
| 309 | + ? true | |
| 310 | + : false; | |
| 311 | + } | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + /** | |
| 316 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned | |
| 317 | + * | |
| 318 | + * @param string $class_name | |
| 319 | + * @param string $dependency | |
| 320 | + * @return int | |
| 321 | + */ | |
| 322 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') | |
| 323 | +	{ | |
| 324 | + // all legacy models have the same dependencies | |
| 325 | +		if (strpos($class_name, 'EEM_') === 0) { | |
| 326 | + $class_name = 'LEGACY_MODELS'; | |
| 327 | + } | |
| 328 | + $dependency = $this->get_alias($dependency); | |
| 329 | + return $this->has_dependency_for_class($class_name, $dependency) | |
| 330 | + ? $this->_dependency_map[$class_name][$dependency] | |
| 331 | + : EE_Dependency_Map::not_registered; | |
| 332 | + } | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + /** | |
| 337 | + * @param string $class_name | |
| 338 | + * @return string | Closure | |
| 339 | + */ | |
| 340 | + public function class_loader($class_name) | |
| 341 | +	{ | |
| 342 | + // all legacy models use load_model() | |
| 343 | +		if(strpos($class_name, 'EEM_') === 0){ | |
| 344 | + return 'load_model'; | |
| 345 | + } | |
| 346 | + $class_name = $this->get_alias($class_name); | |
| 347 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; | |
| 348 | + } | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + /** | |
| 353 | + * @return array | |
| 354 | + */ | |
| 355 | + public function class_loaders() | |
| 356 | +	{ | |
| 357 | + return $this->_class_loaders; | |
| 358 | + } | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + /** | |
| 363 | + * adds an alias for a classname | |
| 364 | + * | |
| 365 | + * @param string $class_name the class name that should be used (concrete class to replace interface) | |
| 366 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) | |
| 367 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) | |
| 368 | + */ | |
| 369 | + public function add_alias($class_name, $alias, $for_class = '') | |
| 370 | +	{ | |
| 371 | +		if ($for_class !== '') { | |
| 372 | +			if (! isset($this->_aliases[$for_class])) { | |
| 373 | + $this->_aliases[$for_class] = array(); | |
| 374 | + } | |
| 375 | + $this->_aliases[$for_class][$class_name] = $alias; | |
| 376 | + } | |
| 377 | + $this->_aliases[$class_name] = $alias; | |
| 378 | + } | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + /** | |
| 383 | + * returns TRUE if the provided class name has an alias | |
| 384 | + * | |
| 385 | + * @param string $class_name | |
| 386 | + * @param string $for_class | |
| 387 | + * @return bool | |
| 388 | + */ | |
| 389 | + public function has_alias($class_name = '', $for_class = '') | |
| 390 | +	{ | |
| 391 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) | |
| 392 | + || ( | |
| 393 | + isset($this->_aliases[$class_name]) | |
| 394 | + && ! is_array($this->_aliases[$class_name]) | |
| 395 | + ); | |
| 396 | + } | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + /** | |
| 401 | + * returns alias for class name if one exists, otherwise returns the original classname | |
| 402 | + * functions recursively, so that multiple aliases can be used to drill down to a classname | |
| 403 | + * for example: | |
| 404 | + * if the following two entries were added to the _aliases array: | |
| 405 | + * array( | |
| 406 | + * 'interface_alias' => 'some\namespace\interface' | |
| 407 | + * 'some\namespace\interface' => 'some\namespace\classname' | |
| 408 | + * ) | |
| 409 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) | |
| 410 | + * to load an instance of 'some\namespace\classname' | |
| 411 | + * | |
| 412 | + * @param string $class_name | |
| 413 | + * @param string $for_class | |
| 414 | + * @return string | |
| 415 | + */ | |
| 416 | + public function get_alias($class_name = '', $for_class = '') | |
| 417 | +	{ | |
| 418 | +		if (! $this->has_alias($class_name, $for_class)) { | |
| 419 | + return $class_name; | |
| 420 | + } | |
| 421 | +		if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { | |
| 422 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); | |
| 423 | + } | |
| 424 | + return $this->get_alias($this->_aliases[$class_name]); | |
| 425 | + } | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + /** | |
| 430 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, | |
| 431 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. | |
| 432 | + * This is done by using the following class constants: | |
| 433 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object | |
| 434 | + * EE_Dependency_Map::load_new_object - generates a new object every time | |
| 435 | + */ | |
| 436 | + protected function _register_core_dependencies() | |
| 437 | +	{ | |
| 438 | + $this->_dependency_map = array( | |
| 439 | + 'EE_Request_Handler' => array( | |
| 440 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, | |
| 441 | + ), | |
| 442 | + 'EE_System' => array( | |
| 443 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, | |
| 444 | + ), | |
| 445 | + 'EE_Session' => array( | |
| 446 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, | |
| 447 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, | |
| 448 | + ), | |
| 449 | + 'EE_Cart' => array( | |
| 450 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, | |
| 451 | + ), | |
| 452 | + 'EE_Front_Controller' => array( | |
| 453 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, | |
| 454 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, | |
| 455 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, | |
| 456 | + ), | |
| 457 | + 'EE_Messenger_Collection_Loader' => array( | |
| 458 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, | |
| 459 | + ), | |
| 460 | + 'EE_Message_Type_Collection_Loader' => array( | |
| 461 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, | |
| 462 | + ), | |
| 463 | + 'EE_Message_Resource_Manager' => array( | |
| 464 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, | |
| 465 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, | |
| 466 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, | |
| 467 | + ), | |
| 468 | + 'EE_Message_Factory' => array( | |
| 469 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, | |
| 470 | + ), | |
| 471 | + 'EE_messages' => array( | |
| 472 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, | |
| 473 | + ), | |
| 474 | + 'EE_Messages_Generator' => array( | |
| 475 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, | |
| 476 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, | |
| 477 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, | |
| 478 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, | |
| 479 | + ), | |
| 480 | + 'EE_Messages_Processor' => array( | |
| 481 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, | |
| 482 | + ), | |
| 483 | + 'EE_Messages_Queue' => array( | |
| 484 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, | |
| 485 | + ), | |
| 486 | + 'EE_Messages_Template_Defaults' => array( | |
| 487 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, | |
| 488 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, | |
| 489 | + ), | |
| 490 | + 'EE_Message_To_Generate_From_Request' => array( | |
| 491 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, | |
| 492 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, | |
| 493 | + ), | |
| 494 | + 'EventEspresso\core\services\commands\CommandBus' => array( | |
| 495 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, | |
| 496 | + ), | |
| 497 | + 'EventEspresso\services\commands\CommandHandler' => array( | |
| 498 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, | |
| 499 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, | |
| 500 | + ), | |
| 501 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( | |
| 502 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, | |
| 503 | + ), | |
| 504 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( | |
| 505 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, | |
| 506 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, | |
| 507 | + ), | |
| 508 | + 'EventEspresso\core\services\commands\CommandFactory' => array( | |
| 509 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, | |
| 510 | + ), | |
| 511 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( | |
| 512 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, | |
| 513 | + ), | |
| 514 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( | |
| 515 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, | |
| 516 | + ), | |
| 517 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( | |
| 518 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, | |
| 519 | + ), | |
| 520 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( | |
| 521 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, | |
| 522 | + ), | |
| 523 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( | |
| 524 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, | |
| 525 | + ), | |
| 526 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( | |
| 527 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, | |
| 528 | + ), | |
| 529 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( | |
| 530 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, | |
| 531 | + ), | |
| 532 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( | |
| 533 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, | |
| 534 | + ), | |
| 535 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( | |
| 536 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, | |
| 537 | + ), | |
| 538 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( | |
| 539 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, | |
| 540 | + ), | |
| 541 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( | |
| 542 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, | |
| 543 | + ), | |
| 544 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( | |
| 545 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, | |
| 546 | + ), | |
| 547 | + 'EventEspresso\core\services\database\TableManager' => array( | |
| 548 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 549 | + ), | |
| 550 | + 'EE_Data_Migration_Class_Base' => array( | |
| 551 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 552 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 553 | + ), | |
| 554 | + 'EE_DMS_Core_4_1_0' => array( | |
| 555 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 556 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 557 | + ), | |
| 558 | + 'EE_DMS_Core_4_2_0' => array( | |
| 559 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 560 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 561 | + ), | |
| 562 | + 'EE_DMS_Core_4_3_0' => array( | |
| 563 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 564 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 565 | + ), | |
| 566 | + 'EE_DMS_Core_4_4_0' => array( | |
| 567 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 568 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 569 | + ), | |
| 570 | + 'EE_DMS_Core_4_5_0' => array( | |
| 571 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 572 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 573 | + ), | |
| 574 | + 'EE_DMS_Core_4_6_0' => array( | |
| 575 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 576 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 577 | + ), | |
| 578 | + 'EE_DMS_Core_4_7_0' => array( | |
| 579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 580 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 581 | + ), | |
| 582 | + 'EE_DMS_Core_4_8_0' => array( | |
| 583 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 584 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 585 | + ), | |
| 586 | + 'EE_DMS_Core_4_9_0' => array( | |
| 587 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, | |
| 588 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, | |
| 589 | + ), | |
| 590 | + 'EventEspresso\core\services\assets\Registry' => array( | |
| 591 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, | |
| 592 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, | |
| 593 | + ), | |
| 594 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( | |
| 595 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 596 | + ), | |
| 597 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( | |
| 598 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 599 | + ), | |
| 600 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( | |
| 601 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 602 | + ), | |
| 603 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( | |
| 604 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 605 | + ), | |
| 606 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( | |
| 607 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 608 | + ), | |
| 609 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( | |
| 610 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 611 | + ), | |
| 612 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( | |
| 613 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, | |
| 614 | + ), | |
| 615 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( | |
| 616 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, | |
| 617 | + ), | |
| 618 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( | |
| 619 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, | |
| 620 | + ), | |
| 621 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( | |
| 622 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, | |
| 623 | + ), | |
| 624 | + 'LEGACY_MODELS' => array( | |
| 625 | + null, | |
| 626 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, | |
| 627 | + ), | |
| 628 | + 'EE_Module_Request_Router' => array( | |
| 629 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, | |
| 630 | + ), | |
| 631 | + ); | |
| 632 | + } | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + /** | |
| 637 | + * Registers how core classes are loaded. | |
| 638 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: | |
| 639 | + * 'EE_Request_Handler' => 'load_core' | |
| 640 | + * 'EE_Messages_Queue' => 'load_lib' | |
| 641 | + * 'EEH_Debug_Tools' => 'load_helper' | |
| 642 | + * or, if greater control is required, by providing a custom closure. For example: | |
| 643 | +	 *        'Some_Class' => function () { | |
| 644 | + * return new Some_Class(); | |
| 645 | + * }, | |
| 646 | + * This is required for instantiating dependencies | |
| 647 | + * where an interface has been type hinted in a class constructor. For example: | |
| 648 | +	 *        'Required_Interface' => function () { | |
| 649 | + * return new A_Class_That_Implements_Required_Interface(); | |
| 650 | + * }, | |
| 651 | + * | |
| 652 | + * @throws InvalidInterfaceException | |
| 653 | + * @throws InvalidDataTypeException | |
| 654 | + * @throws InvalidArgumentException | |
| 655 | + */ | |
| 656 | + protected function _register_core_class_loaders() | |
| 657 | +	{ | |
| 658 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot | |
| 659 | + //be used in a closure. | |
| 660 | + $request = &$this->_request; | |
| 661 | + $response = &$this->_response; | |
| 662 | + $loader = &$this->loader; | |
| 663 | + $this->_class_loaders = array( | |
| 664 | + //load_core | |
| 665 | + 'EE_Capabilities' => 'load_core', | |
| 666 | + 'EE_Encryption' => 'load_core', | |
| 667 | + 'EE_Front_Controller' => 'load_core', | |
| 668 | + 'EE_Module_Request_Router' => 'load_core', | |
| 669 | + 'EE_Registry' => 'load_core', | |
| 670 | +			'EE_Request'                           => function () use (&$request) { | |
| 671 | + return $request; | |
| 672 | + }, | |
| 673 | +			'EE_Response'                          => function () use (&$response) { | |
| 674 | + return $response; | |
| 675 | + }, | |
| 676 | + 'EE_Request_Handler' => 'load_core', | |
| 677 | + 'EE_Session' => 'load_core', | |
| 678 | + 'EE_Cron_Tasks' => 'load_core', | |
| 679 | + //load_lib | |
| 680 | + 'EE_Message_Resource_Manager' => 'load_lib', | |
| 681 | + 'EE_Message_Type_Collection' => 'load_lib', | |
| 682 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', | |
| 683 | + 'EE_Messenger_Collection' => 'load_lib', | |
| 684 | + 'EE_Messenger_Collection_Loader' => 'load_lib', | |
| 685 | + 'EE_Messages_Processor' => 'load_lib', | |
| 686 | + 'EE_Message_Repository' => 'load_lib', | |
| 687 | + 'EE_Messages_Queue' => 'load_lib', | |
| 688 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', | |
| 689 | + 'EE_Message_Template_Group_Collection' => 'load_lib', | |
| 690 | +			'EE_Messages_Generator'                => function () { | |
| 691 | + return EE_Registry::instance()->load_lib( | |
| 692 | + 'Messages_Generator', | |
| 693 | + array(), | |
| 694 | + false, | |
| 695 | + false | |
| 696 | + ); | |
| 697 | + }, | |
| 698 | +			'EE_Messages_Template_Defaults'        => function ($arguments = array()) { | |
| 699 | + return EE_Registry::instance()->load_lib( | |
| 700 | + 'Messages_Template_Defaults', | |
| 701 | + $arguments, | |
| 702 | + false, | |
| 703 | + false | |
| 704 | + ); | |
| 705 | + }, | |
| 706 | + //load_model | |
| 707 | + // 'EEM_Attendee' => 'load_model', | |
| 708 | + // 'EEM_Message_Template_Group' => 'load_model', | |
| 709 | + // 'EEM_Message_Template' => 'load_model', | |
| 710 | + //load_helper | |
| 711 | +			'EEH_Parse_Shortcodes'                 => function () { | |
| 712 | +				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { | |
| 713 | + return new EEH_Parse_Shortcodes(); | |
| 714 | + } | |
| 715 | + return null; | |
| 716 | + }, | |
| 717 | +			'EE_Template_Config'                   => function () { | |
| 718 | + return EE_Config::instance()->template_settings; | |
| 719 | + }, | |
| 720 | +			'EE_Currency_Config'                   => function () { | |
| 721 | + return EE_Config::instance()->currency; | |
| 722 | + }, | |
| 723 | +			'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { | |
| 724 | + return $loader; | |
| 725 | + }, | |
| 726 | + ); | |
| 727 | + } | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + /** | |
| 732 | + * can be used for supplying alternate names for classes, | |
| 733 | + * or for connecting interface names to instantiable classes | |
| 734 | + */ | |
| 735 | + protected function _register_core_aliases() | |
| 736 | +	{ | |
| 737 | + $this->_aliases = array( | |
| 738 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', | |
| 739 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', | |
| 740 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', | |
| 741 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', | |
| 742 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', | |
| 743 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', | |
| 744 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', | |
| 745 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', | |
| 746 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', | |
| 747 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', | |
| 748 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', | |
| 749 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', | |
| 750 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', | |
| 751 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', | |
| 752 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', | |
| 753 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', | |
| 754 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', | |
| 755 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', | |
| 756 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', | |
| 757 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', | |
| 758 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', | |
| 759 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', | |
| 760 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', | |
| 761 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', | |
| 762 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', | |
| 763 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', | |
| 764 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', | |
| 765 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', | |
| 766 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', | |
| 767 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', | |
| 768 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', | |
| 769 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', | |
| 770 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', | |
| 771 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', | |
| 772 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', | |
| 773 | + ); | |
| 774 | + } | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + /** | |
| 779 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the | |
| 780 | + * request Primarily used by unit tests. | |
| 781 | + * | |
| 782 | + * @throws InvalidDataTypeException | |
| 783 | + * @throws InvalidInterfaceException | |
| 784 | + * @throws InvalidArgumentException | |
| 785 | + */ | |
| 786 | + public function reset() | |
| 787 | +	{ | |
| 788 | + $this->_register_core_class_loaders(); | |
| 789 | + $this->_register_core_dependencies(); | |
| 790 | + } | |
| 791 | 791 | |
| 792 | 792 | |
| 793 | 793 | } | 
| @@ -3,7 +3,7 @@ discard block | ||
| 3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; | 
| 4 | 4 | use EventEspresso\core\services\loaders\LoaderFactory; | 
| 5 | 5 | |
| 6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { | |
| 6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { | |
| 7 | 7 |      exit('No direct script access allowed'); | 
| 8 | 8 | } | 
| 9 | 9 | |
| @@ -51,7 +51,7 @@ discard block | ||
| 51 | 51 | */ | 
| 52 | 52 | public function __construct() | 
| 53 | 53 |      { | 
| 54 | -        espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); | |
| 54 | +        espresso_load_required('EventEspresso\core\Factory', EE_CORE.'Factory.php'); | |
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | 57 | |
| @@ -105,9 +105,9 @@ discard block | ||
| 105 | 105 | $this->_load_class_tools(); | 
| 106 | 106 | // load interfaces | 
| 107 | 107 |          espresso_load_required('EEI_Payment_Method_Interfaces', | 
| 108 | - EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); | |
| 108 | + EE_LIBRARIES.'payment_methods'.DS.'EEI_Payment_Method_Interfaces.php'); | |
| 109 | 109 | // deprecated functions | 
| 110 | -        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); | |
| 110 | +        espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php'); | |
| 111 | 111 | // WP cron jobs | 
| 112 | 112 |          $loader->getShared('EE_Cron_Tasks'); | 
| 113 | 113 |          $loader->getShared('EE_Request_Handler'); | 
| @@ -143,7 +143,7 @@ discard block | ||
| 143 | 143 | */ | 
| 144 | 144 | public function dependency_map() | 
| 145 | 145 |      { | 
| 146 | -        if (! $this->dependency_map instanceof EE_Dependency_Map) { | |
| 146 | +        if ( ! $this->dependency_map instanceof EE_Dependency_Map) { | |
| 147 | 147 | throw new EE_Error( | 
| 148 | 148 | sprintf( | 
| 149 | 149 |                      __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), | 
| @@ -162,7 +162,7 @@ discard block | ||
| 162 | 162 | */ | 
| 163 | 163 | public function registry() | 
| 164 | 164 |      { | 
| 165 | -        if (! $this->registry instanceof EE_Registry) { | |
| 165 | +        if ( ! $this->registry instanceof EE_Registry) { | |
| 166 | 166 | throw new EE_Error( | 
| 167 | 167 | sprintf( | 
| 168 | 168 |                      __('Invalid EE_Registry: "%1$s"', 'event_espresso'), | 
| @@ -180,14 +180,14 @@ discard block | ||
| 180 | 180 | */ | 
| 181 | 181 | private function _load_dependency_map() | 
| 182 | 182 |      { | 
| 183 | -        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { | |
| 183 | +        if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) { | |
| 184 | 184 | EE_Error::add_error( | 
| 185 | 185 |                  __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), | 
| 186 | 186 | __FILE__, __FUNCTION__, __LINE__ | 
| 187 | 187 | ); | 
| 188 | 188 | wp_die(EE_Error::get_notices()); | 
| 189 | 189 | } | 
| 190 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); | |
| 190 | + require_once(EE_CORE.'EE_Dependency_Map.core.php'); | |
| 191 | 191 | return EE_Dependency_Map::instance($this->request, $this->response); | 
| 192 | 192 | } | 
| 193 | 193 | |
| @@ -198,14 +198,14 @@ discard block | ||
| 198 | 198 | */ | 
| 199 | 199 | private function _load_registry() | 
| 200 | 200 |      { | 
| 201 | -        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { | |
| 201 | +        if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) { | |
| 202 | 202 | EE_Error::add_error( | 
| 203 | 203 |                  __('The EE_Registry core class could not be loaded.', 'event_espresso'), | 
| 204 | 204 | __FILE__, __FUNCTION__, __LINE__ | 
| 205 | 205 | ); | 
| 206 | 206 | wp_die(EE_Error::get_notices()); | 
| 207 | 207 | } | 
| 208 | - require_once(EE_CORE . 'EE_Registry.core.php'); | |
| 208 | + require_once(EE_CORE.'EE_Registry.core.php'); | |
| 209 | 209 | return EE_Registry::instance($this->dependency_map); | 
| 210 | 210 | } | 
| 211 | 211 | |
| @@ -216,13 +216,13 @@ discard block | ||
| 216 | 216 | */ | 
| 217 | 217 | private function _load_class_tools() | 
| 218 | 218 |      { | 
| 219 | -        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { | |
| 219 | +        if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) { | |
| 220 | 220 | EE_Error::add_error( | 
| 221 | 221 |                  __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), | 
| 222 | 222 | __FILE__, __FUNCTION__, __LINE__ | 
| 223 | 223 | ); | 
| 224 | 224 | } | 
| 225 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); | |
| 225 | + require_once(EE_HELPERS.'EEH_Class_Tools.helper.php'); | |
| 226 | 226 | } | 
| 227 | 227 | |
| 228 | 228 | |
| @@ -4,7 +4,7 @@ discard block | ||
| 4 | 4 | use EventEspresso\core\services\loaders\LoaderFactory; | 
| 5 | 5 | |
| 6 | 6 |  if (! defined('EVENT_ESPRESSO_VERSION')) { | 
| 7 | -    exit('No direct script access allowed'); | |
| 7 | +	exit('No direct script access allowed'); | |
| 8 | 8 | } | 
| 9 | 9 | |
| 10 | 10 | |
| @@ -24,208 +24,208 @@ discard block | ||
| 24 | 24 | class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App | 
| 25 | 25 |  { | 
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * @var EE_Request $request | |
| 29 | - */ | |
| 30 | - protected $request; | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * @var EE_Response $response | |
| 34 | - */ | |
| 35 | - protected $response; | |
| 36 | - | |
| 37 | - /** | |
| 38 | - * @var EE_Dependency_Map $dependency_map | |
| 39 | - */ | |
| 40 | - protected $dependency_map; | |
| 41 | - | |
| 42 | - /** | |
| 43 | - * @var EE_Registry $registry | |
| 44 | - */ | |
| 45 | - protected $registry; | |
| 46 | - | |
| 47 | - | |
| 48 | - | |
| 49 | - /** | |
| 50 | - * EE_Load_Espresso_Core constructor | |
| 51 | - */ | |
| 52 | - public function __construct() | |
| 53 | -    { | |
| 54 | -        espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); | |
| 55 | - } | |
| 56 | - | |
| 57 | - | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * handle | |
| 61 | - * sets hooks for running rest of system | |
| 62 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point | |
| 63 | - * starting EE Addons from any other point may lead to problems | |
| 64 | - * | |
| 65 | - * @param EE_Request $request | |
| 66 | - * @param EE_Response $response | |
| 67 | - * @return EE_Response | |
| 68 | - * @throws EE_Error | |
| 69 | - * @throws InvalidDataTypeException | |
| 70 | - * @throws InvalidInterfaceException | |
| 71 | - * @throws InvalidArgumentException | |
| 72 | - */ | |
| 73 | - public function handle_request(EE_Request $request, EE_Response $response) | |
| 74 | -    { | |
| 75 | - $this->request = $request; | |
| 76 | - $this->response = $response; | |
| 77 | - // info about how to load classes required by other classes | |
| 78 | - $this->dependency_map = $this->_load_dependency_map(); | |
| 79 | - // central repository for classes | |
| 80 | - $this->registry = $this->_load_registry(); | |
| 81 | - // PSR4 Autoloaders | |
| 82 | -        $this->registry->load_core('EE_Psr4AutoloaderInit'); | |
| 83 | -        do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); | |
| 84 | - $loader = LoaderFactory::getLoader($this->registry); | |
| 85 | - $this->dependency_map->setLoader($loader); | |
| 86 | - // build DI container | |
| 87 | - // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); | |
| 88 | - // $OpenCoffeeShop->addRecipes(); | |
| 89 | - // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); | |
| 90 | - // workarounds for PHP < 5.3 | |
| 91 | - $this->_load_class_tools(); | |
| 92 | - // load interfaces | |
| 93 | -        espresso_load_required('EEI_Payment_Method_Interfaces', | |
| 94 | - EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); | |
| 95 | - // deprecated functions | |
| 96 | -        espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); | |
| 97 | - // WP cron jobs | |
| 98 | -        $loader->getShared('EE_Cron_Tasks'); | |
| 99 | -        $loader->getShared('EE_Request_Handler'); | |
| 100 | -        $loader->getShared('EE_System'); | |
| 101 | - return $this->response; | |
| 102 | - } | |
| 103 | - | |
| 104 | - | |
| 105 | - | |
| 106 | - /** | |
| 107 | - * @return EE_Request | |
| 108 | - */ | |
| 109 | - public function request() | |
| 110 | -    { | |
| 111 | - return $this->request; | |
| 112 | - } | |
| 113 | - | |
| 114 | - | |
| 115 | - | |
| 116 | - /** | |
| 117 | - * @return EE_Response | |
| 118 | - */ | |
| 119 | - public function response() | |
| 120 | -    { | |
| 121 | - return $this->response; | |
| 122 | - } | |
| 123 | - | |
| 124 | - | |
| 125 | - | |
| 126 | - /** | |
| 127 | - * @return EE_Dependency_Map | |
| 128 | - * @throws EE_Error | |
| 129 | - */ | |
| 130 | - public function dependency_map() | |
| 131 | -    { | |
| 132 | -        if (! $this->dependency_map instanceof EE_Dependency_Map) { | |
| 133 | - throw new EE_Error( | |
| 134 | - sprintf( | |
| 135 | -                    __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), | |
| 136 | - print_r($this->dependency_map, true) | |
| 137 | - ) | |
| 138 | - ); | |
| 139 | - } | |
| 140 | - return $this->dependency_map; | |
| 141 | - } | |
| 142 | - | |
| 143 | - | |
| 144 | - | |
| 145 | - /** | |
| 146 | - * @return EE_Registry | |
| 147 | - * @throws EE_Error | |
| 148 | - */ | |
| 149 | - public function registry() | |
| 150 | -    { | |
| 151 | -        if (! $this->registry instanceof EE_Registry) { | |
| 152 | - throw new EE_Error( | |
| 153 | - sprintf( | |
| 154 | -                    __('Invalid EE_Registry: "%1$s"', 'event_espresso'), | |
| 155 | - print_r($this->registry, true) | |
| 156 | - ) | |
| 157 | - ); | |
| 158 | - } | |
| 159 | - return $this->registry; | |
| 160 | - } | |
| 161 | - | |
| 162 | - | |
| 163 | - | |
| 164 | - /** | |
| 165 | - * @return EE_Dependency_Map | |
| 166 | - */ | |
| 167 | - private function _load_dependency_map() | |
| 168 | -    { | |
| 169 | -        if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { | |
| 170 | - EE_Error::add_error( | |
| 171 | -                __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), | |
| 172 | - __FILE__, __FUNCTION__, __LINE__ | |
| 173 | - ); | |
| 174 | - wp_die(EE_Error::get_notices()); | |
| 175 | - } | |
| 176 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); | |
| 177 | - return EE_Dependency_Map::instance($this->request, $this->response); | |
| 178 | - } | |
| 179 | - | |
| 180 | - | |
| 181 | - | |
| 182 | - /** | |
| 183 | - * @return EE_Registry | |
| 184 | - */ | |
| 185 | - private function _load_registry() | |
| 186 | -    { | |
| 187 | -        if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { | |
| 188 | - EE_Error::add_error( | |
| 189 | -                __('The EE_Registry core class could not be loaded.', 'event_espresso'), | |
| 190 | - __FILE__, __FUNCTION__, __LINE__ | |
| 191 | - ); | |
| 192 | - wp_die(EE_Error::get_notices()); | |
| 193 | - } | |
| 194 | - require_once(EE_CORE . 'EE_Registry.core.php'); | |
| 195 | - return EE_Registry::instance($this->dependency_map); | |
| 196 | - } | |
| 197 | - | |
| 198 | - | |
| 199 | - | |
| 200 | - /** | |
| 201 | - * @return void | |
| 202 | - */ | |
| 203 | - private function _load_class_tools() | |
| 204 | -    { | |
| 205 | -        if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { | |
| 206 | - EE_Error::add_error( | |
| 207 | -                __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), | |
| 208 | - __FILE__, __FUNCTION__, __LINE__ | |
| 209 | - ); | |
| 210 | - } | |
| 211 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); | |
| 212 | - } | |
| 213 | - | |
| 214 | - | |
| 215 | - | |
| 216 | - /** | |
| 217 | - * called after the request stack has been fully processed | |
| 218 | - * if any of the middleware apps has requested the plugin be deactivated, then we do that now | |
| 219 | - * | |
| 220 | - * @param EE_Request $request | |
| 221 | - * @param EE_Response $response | |
| 222 | - */ | |
| 223 | - public function handle_response(EE_Request $request, EE_Response $response) | |
| 224 | -    { | |
| 225 | -        if ($response->plugin_deactivated()) { | |
| 226 | - espresso_deactivate_plugin(EE_PLUGIN_BASENAME); | |
| 227 | - } | |
| 228 | - } | |
| 27 | + /** | |
| 28 | + * @var EE_Request $request | |
| 29 | + */ | |
| 30 | + protected $request; | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * @var EE_Response $response | |
| 34 | + */ | |
| 35 | + protected $response; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * @var EE_Dependency_Map $dependency_map | |
| 39 | + */ | |
| 40 | + protected $dependency_map; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * @var EE_Registry $registry | |
| 44 | + */ | |
| 45 | + protected $registry; | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * EE_Load_Espresso_Core constructor | |
| 51 | + */ | |
| 52 | + public function __construct() | |
| 53 | +	{ | |
| 54 | +		espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); | |
| 55 | + } | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * handle | |
| 61 | + * sets hooks for running rest of system | |
| 62 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point | |
| 63 | + * starting EE Addons from any other point may lead to problems | |
| 64 | + * | |
| 65 | + * @param EE_Request $request | |
| 66 | + * @param EE_Response $response | |
| 67 | + * @return EE_Response | |
| 68 | + * @throws EE_Error | |
| 69 | + * @throws InvalidDataTypeException | |
| 70 | + * @throws InvalidInterfaceException | |
| 71 | + * @throws InvalidArgumentException | |
| 72 | + */ | |
| 73 | + public function handle_request(EE_Request $request, EE_Response $response) | |
| 74 | +	{ | |
| 75 | + $this->request = $request; | |
| 76 | + $this->response = $response; | |
| 77 | + // info about how to load classes required by other classes | |
| 78 | + $this->dependency_map = $this->_load_dependency_map(); | |
| 79 | + // central repository for classes | |
| 80 | + $this->registry = $this->_load_registry(); | |
| 81 | + // PSR4 Autoloaders | |
| 82 | +		$this->registry->load_core('EE_Psr4AutoloaderInit'); | |
| 83 | +		do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); | |
| 84 | + $loader = LoaderFactory::getLoader($this->registry); | |
| 85 | + $this->dependency_map->setLoader($loader); | |
| 86 | + // build DI container | |
| 87 | + // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); | |
| 88 | + // $OpenCoffeeShop->addRecipes(); | |
| 89 | + // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); | |
| 90 | + // workarounds for PHP < 5.3 | |
| 91 | + $this->_load_class_tools(); | |
| 92 | + // load interfaces | |
| 93 | +		espresso_load_required('EEI_Payment_Method_Interfaces', | |
| 94 | + EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); | |
| 95 | + // deprecated functions | |
| 96 | +		espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); | |
| 97 | + // WP cron jobs | |
| 98 | +		$loader->getShared('EE_Cron_Tasks'); | |
| 99 | +		$loader->getShared('EE_Request_Handler'); | |
| 100 | +		$loader->getShared('EE_System'); | |
| 101 | + return $this->response; | |
| 102 | + } | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + /** | |
| 107 | + * @return EE_Request | |
| 108 | + */ | |
| 109 | + public function request() | |
| 110 | +	{ | |
| 111 | + return $this->request; | |
| 112 | + } | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + /** | |
| 117 | + * @return EE_Response | |
| 118 | + */ | |
| 119 | + public function response() | |
| 120 | +	{ | |
| 121 | + return $this->response; | |
| 122 | + } | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * @return EE_Dependency_Map | |
| 128 | + * @throws EE_Error | |
| 129 | + */ | |
| 130 | + public function dependency_map() | |
| 131 | +	{ | |
| 132 | +		if (! $this->dependency_map instanceof EE_Dependency_Map) { | |
| 133 | + throw new EE_Error( | |
| 134 | + sprintf( | |
| 135 | +					__('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), | |
| 136 | + print_r($this->dependency_map, true) | |
| 137 | + ) | |
| 138 | + ); | |
| 139 | + } | |
| 140 | + return $this->dependency_map; | |
| 141 | + } | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + /** | |
| 146 | + * @return EE_Registry | |
| 147 | + * @throws EE_Error | |
| 148 | + */ | |
| 149 | + public function registry() | |
| 150 | +	{ | |
| 151 | +		if (! $this->registry instanceof EE_Registry) { | |
| 152 | + throw new EE_Error( | |
| 153 | + sprintf( | |
| 154 | +					__('Invalid EE_Registry: "%1$s"', 'event_espresso'), | |
| 155 | + print_r($this->registry, true) | |
| 156 | + ) | |
| 157 | + ); | |
| 158 | + } | |
| 159 | + return $this->registry; | |
| 160 | + } | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + /** | |
| 165 | + * @return EE_Dependency_Map | |
| 166 | + */ | |
| 167 | + private function _load_dependency_map() | |
| 168 | +	{ | |
| 169 | +		if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { | |
| 170 | + EE_Error::add_error( | |
| 171 | +				__('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), | |
| 172 | + __FILE__, __FUNCTION__, __LINE__ | |
| 173 | + ); | |
| 174 | + wp_die(EE_Error::get_notices()); | |
| 175 | + } | |
| 176 | + require_once(EE_CORE . 'EE_Dependency_Map.core.php'); | |
| 177 | + return EE_Dependency_Map::instance($this->request, $this->response); | |
| 178 | + } | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + /** | |
| 183 | + * @return EE_Registry | |
| 184 | + */ | |
| 185 | + private function _load_registry() | |
| 186 | +	{ | |
| 187 | +		if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { | |
| 188 | + EE_Error::add_error( | |
| 189 | +				__('The EE_Registry core class could not be loaded.', 'event_espresso'), | |
| 190 | + __FILE__, __FUNCTION__, __LINE__ | |
| 191 | + ); | |
| 192 | + wp_die(EE_Error::get_notices()); | |
| 193 | + } | |
| 194 | + require_once(EE_CORE . 'EE_Registry.core.php'); | |
| 195 | + return EE_Registry::instance($this->dependency_map); | |
| 196 | + } | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + /** | |
| 201 | + * @return void | |
| 202 | + */ | |
| 203 | + private function _load_class_tools() | |
| 204 | +	{ | |
| 205 | +		if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { | |
| 206 | + EE_Error::add_error( | |
| 207 | +				__('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), | |
| 208 | + __FILE__, __FUNCTION__, __LINE__ | |
| 209 | + ); | |
| 210 | + } | |
| 211 | + require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); | |
| 212 | + } | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + /** | |
| 217 | + * called after the request stack has been fully processed | |
| 218 | + * if any of the middleware apps has requested the plugin be deactivated, then we do that now | |
| 219 | + * | |
| 220 | + * @param EE_Request $request | |
| 221 | + * @param EE_Response $response | |
| 222 | + */ | |
| 223 | + public function handle_response(EE_Request $request, EE_Response $response) | |
| 224 | +	{ | |
| 225 | +		if ($response->plugin_deactivated()) { | |
| 226 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); | |
| 227 | + } | |
| 228 | + } | |
| 229 | 229 | |
| 230 | 230 | |
| 231 | 231 | |
| @@ -1,7 +1,7 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | 2 | |
| 3 | 3 |  if ( ! defined('EVENT_ESPRESSO_VERSION')) { | 
| 4 | -    exit('No direct script access allowed'); | |
| 4 | +	exit('No direct script access allowed'); | |
| 5 | 5 | } | 
| 6 | 6 | require_once(EE_MODELS . 'EEM_Base.model.php'); | 
| 7 | 7 | |
| @@ -17,193 +17,193 @@ discard block | ||
| 17 | 17 | class EEM_Transaction extends EEM_Base | 
| 18 | 18 |  { | 
| 19 | 19 | |
| 20 | - // private instance of the Transaction object | |
| 21 | - protected static $_instance; | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, | |
| 25 | - * but payment is pending. This is the state for transactions where payment is promised | |
| 26 | - * from an offline gateway. | |
| 27 | - */ | |
| 28 | - // const open_status_code = 'TPN'; | |
| 29 | - | |
| 30 | - /** | |
| 31 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, | |
| 32 | - * either due to a technical reason (server or computer crash during registration), | |
| 33 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants | |
| 34 | - */ | |
| 35 | - const failed_status_code = 'TFL'; | |
| 36 | - | |
| 37 | - /** | |
| 38 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, | |
| 39 | - * either due to a technical reason (server or computer crash during registration), | |
| 40 | - * or due to an abandoned cart after registrant chose not to complete the registration process | |
| 41 | - * HOWEVER... | |
| 42 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one | |
| 43 | - * registrant | |
| 44 | - */ | |
| 45 | - const abandoned_status_code = 'TAB'; | |
| 46 | - | |
| 47 | - /** | |
| 48 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, | |
| 49 | - * meaning that monies are still owing: TXN_paid < TXN_total | |
| 50 | - */ | |
| 51 | - const incomplete_status_code = 'TIN'; | |
| 52 | - | |
| 53 | - /** | |
| 54 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. | |
| 55 | - * meaning that NO monies are owing: TXN_paid == TXN_total | |
| 56 | - */ | |
| 57 | - const complete_status_code = 'TCM'; | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. | |
| 61 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total | |
| 62 | - */ | |
| 63 | - const overpaid_status_code = 'TOP'; | |
| 64 | - | |
| 65 | - | |
| 66 | - /** | |
| 67 | - * private constructor to prevent direct creation | |
| 68 | - * | |
| 69 | - * @Constructor | |
| 70 | - * @access protected | |
| 71 | - * | |
| 72 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any | |
| 73 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the | |
| 74 | - * date time model field objects. Default is NULL (and will be assumed using the set | |
| 75 | - * timezone in the 'timezone_string' wp option) | |
| 76 | - * | |
| 77 | - * @return EEM_Transaction | |
| 78 | - * @throws \EE_Error | |
| 79 | - */ | |
| 80 | - protected function __construct($timezone) | |
| 81 | -    { | |
| 82 | -        $this->singular_item = __('Transaction', 'event_espresso'); | |
| 83 | -        $this->plural_item   = __('Transactions', 'event_espresso'); | |
| 84 | - | |
| 85 | - $this->_tables = array( | |
| 86 | -            'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') | |
| 87 | - ); | |
| 88 | - $this->_fields = array( | |
| 89 | - 'TransactionTable' => array( | |
| 90 | -                'TXN_ID'           => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), | |
| 91 | -                'TXN_timestamp'    => new EE_Datetime_Field('TXN_timestamp', | |
| 92 | -                    __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, | |
| 93 | - $timezone), | |
| 94 | -                'TXN_total'        => new EE_Money_Field('TXN_total', | |
| 95 | -                    __('Total value of Transaction', 'event_espresso'), false, 0), | |
| 96 | -                'TXN_paid'         => new EE_Money_Field('TXN_paid', | |
| 97 | -                    __('Amount paid towards transaction to date', 'event_espresso'), false, 0), | |
| 98 | -                'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), | |
| 99 | - false, EEM_Transaction::failed_status_code, 'Status'), | |
| 100 | -                'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data', | |
| 101 | -                    __('Serialized session data', 'event_espresso'), true, ''), | |
| 102 | -                'TXN_hash_salt'    => new EE_Plain_Text_Field('TXN_hash_salt', | |
| 103 | -                    __('Transaction Hash Salt', 'event_espresso'), true, ''), | |
| 104 | -                'PMD_ID'           => new EE_Foreign_Key_Int_Field('PMD_ID', | |
| 105 | -                    __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'), | |
| 106 | -                'TXN_reg_steps'    => new EE_Serialized_Text_Field('TXN_reg_steps', | |
| 107 | -                    __('Registration Steps', 'event_espresso'), false, array()), | |
| 108 | - ) | |
| 109 | - ); | |
| 110 | - $this->_model_relations = array( | |
| 111 | - 'Registration' => new EE_Has_Many_Relation(), | |
| 112 | - 'Payment' => new EE_Has_Many_Relation(), | |
| 113 | - 'Status' => new EE_Belongs_To_Relation(), | |
| 114 | - 'Line_Item' => new EE_Has_Many_Relation(false), | |
| 115 | - //you can delete a transaction without needing to delete its line items | |
| 116 | - 'Payment_Method' => new EE_Belongs_To_Relation(), | |
| 117 | - 'Message' => new EE_Has_Many_Relation() | |
| 118 | - ); | |
| 119 | - $this->_model_chain_to_wp_user = 'Registration.Event'; | |
| 120 | - parent::__construct($timezone); | |
| 121 | - | |
| 122 | - } | |
| 123 | - | |
| 124 | - | |
| 125 | - /** | |
| 126 | - * txn_status_array | |
| 127 | - * get list of transaction statuses | |
| 128 | - * | |
| 129 | - * @access public | |
| 130 | - * @return array | |
| 131 | - */ | |
| 132 | - public static function txn_status_array() | |
| 133 | -    { | |
| 134 | - return apply_filters( | |
| 135 | - 'FHEE__EEM_Transaction__txn_status_array', | |
| 136 | - array( | |
| 137 | - EEM_Transaction::overpaid_status_code, | |
| 138 | - EEM_Transaction::complete_status_code, | |
| 139 | - EEM_Transaction::incomplete_status_code, | |
| 140 | - EEM_Transaction::abandoned_status_code, | |
| 141 | - EEM_Transaction::failed_status_code, | |
| 142 | - ) | |
| 143 | - ); | |
| 144 | - } | |
| 145 | - | |
| 146 | - /** | |
| 147 | - * get the revenue per day for the Transaction Admin page Reports Tab | |
| 148 | - * | |
| 149 | - * @access public | |
| 150 | - * | |
| 151 | - * @param string $period | |
| 152 | - * | |
| 153 | - * @return \stdClass[] | |
| 154 | - */ | |
| 155 | - public function get_revenue_per_day_report($period = '-1 month') | |
| 156 | -    { | |
| 157 | -        $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), | |
| 158 | - 'Y-m-d H:i:s', 'UTC'); | |
| 159 | - | |
| 160 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); | |
| 161 | - | |
| 162 | - return $this->_get_all_wpdb_results( | |
| 163 | - array( | |
| 164 | - array( | |
| 165 | -                    'TXN_timestamp' => array('>=', $sql_date) | |
| 166 | - ), | |
| 167 | - 'group_by' => 'txnDate', | |
| 168 | -                'order_by' => array('TXN_timestamp' => 'ASC') | |
| 169 | - ), | |
| 170 | - OBJECT, | |
| 171 | - array( | |
| 172 | -                'txnDate' => array('DATE(' . $query_interval . ')', '%s'), | |
| 173 | -                'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') | |
| 174 | - ) | |
| 175 | - ); | |
| 176 | - } | |
| 177 | - | |
| 178 | - | |
| 179 | - /** | |
| 180 | - * get the revenue per event for the Transaction Admin page Reports Tab | |
| 181 | - * | |
| 182 | - * @access public | |
| 183 | - * | |
| 184 | - * @param string $period | |
| 185 | - * | |
| 186 | - * @throws \EE_Error | |
| 187 | - * @return mixed | |
| 188 | - */ | |
| 189 | - public function get_revenue_per_event_report($period = '-1 month') | |
| 190 | -    { | |
| 191 | - global $wpdb; | |
| 192 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; | |
| 193 | - $registration_table = $wpdb->prefix . 'esp_registration'; | |
| 194 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; | |
| 195 | - $event_table = $wpdb->posts; | |
| 196 | - $payment_table = $wpdb->prefix . 'esp_payment'; | |
| 197 | -        $sql_date                   = date('Y-m-d H:i:s', strtotime($period)); | |
| 198 | - $approved_payment_status = EEM_Payment::status_id_approved; | |
| 199 | - $extra_event_on_join = ''; | |
| 200 | - //exclude events not authored by user if permissions in effect | |
| 201 | -        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { | |
| 202 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); | |
| 203 | - } | |
| 204 | - | |
| 205 | - return $wpdb->get_results( | |
| 206 | - "SELECT | |
| 20 | + // private instance of the Transaction object | |
| 21 | + protected static $_instance; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, | |
| 25 | + * but payment is pending. This is the state for transactions where payment is promised | |
| 26 | + * from an offline gateway. | |
| 27 | + */ | |
| 28 | + // const open_status_code = 'TPN'; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, | |
| 32 | + * either due to a technical reason (server or computer crash during registration), | |
| 33 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants | |
| 34 | + */ | |
| 35 | + const failed_status_code = 'TFL'; | |
| 36 | + | |
| 37 | + /** | |
| 38 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, | |
| 39 | + * either due to a technical reason (server or computer crash during registration), | |
| 40 | + * or due to an abandoned cart after registrant chose not to complete the registration process | |
| 41 | + * HOWEVER... | |
| 42 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one | |
| 43 | + * registrant | |
| 44 | + */ | |
| 45 | + const abandoned_status_code = 'TAB'; | |
| 46 | + | |
| 47 | + /** | |
| 48 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, | |
| 49 | + * meaning that monies are still owing: TXN_paid < TXN_total | |
| 50 | + */ | |
| 51 | + const incomplete_status_code = 'TIN'; | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. | |
| 55 | + * meaning that NO monies are owing: TXN_paid == TXN_total | |
| 56 | + */ | |
| 57 | + const complete_status_code = 'TCM'; | |
| 58 | + | |
| 59 | + /** | |
| 60 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. | |
| 61 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total | |
| 62 | + */ | |
| 63 | + const overpaid_status_code = 'TOP'; | |
| 64 | + | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * private constructor to prevent direct creation | |
| 68 | + * | |
| 69 | + * @Constructor | |
| 70 | + * @access protected | |
| 71 | + * | |
| 72 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any | |
| 73 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the | |
| 74 | + * date time model field objects. Default is NULL (and will be assumed using the set | |
| 75 | + * timezone in the 'timezone_string' wp option) | |
| 76 | + * | |
| 77 | + * @return EEM_Transaction | |
| 78 | + * @throws \EE_Error | |
| 79 | + */ | |
| 80 | + protected function __construct($timezone) | |
| 81 | +	{ | |
| 82 | +		$this->singular_item = __('Transaction', 'event_espresso'); | |
| 83 | +		$this->plural_item   = __('Transactions', 'event_espresso'); | |
| 84 | + | |
| 85 | + $this->_tables = array( | |
| 86 | +			'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') | |
| 87 | + ); | |
| 88 | + $this->_fields = array( | |
| 89 | + 'TransactionTable' => array( | |
| 90 | +				'TXN_ID'           => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), | |
| 91 | +				'TXN_timestamp'    => new EE_Datetime_Field('TXN_timestamp', | |
| 92 | +					__('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, | |
| 93 | + $timezone), | |
| 94 | +				'TXN_total'        => new EE_Money_Field('TXN_total', | |
| 95 | +					__('Total value of Transaction', 'event_espresso'), false, 0), | |
| 96 | +				'TXN_paid'         => new EE_Money_Field('TXN_paid', | |
| 97 | +					__('Amount paid towards transaction to date', 'event_espresso'), false, 0), | |
| 98 | +				'STS_ID'           => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), | |
| 99 | + false, EEM_Transaction::failed_status_code, 'Status'), | |
| 100 | +				'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data', | |
| 101 | +					__('Serialized session data', 'event_espresso'), true, ''), | |
| 102 | +				'TXN_hash_salt'    => new EE_Plain_Text_Field('TXN_hash_salt', | |
| 103 | +					__('Transaction Hash Salt', 'event_espresso'), true, ''), | |
| 104 | +				'PMD_ID'           => new EE_Foreign_Key_Int_Field('PMD_ID', | |
| 105 | +					__("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'), | |
| 106 | +				'TXN_reg_steps'    => new EE_Serialized_Text_Field('TXN_reg_steps', | |
| 107 | +					__('Registration Steps', 'event_espresso'), false, array()), | |
| 108 | + ) | |
| 109 | + ); | |
| 110 | + $this->_model_relations = array( | |
| 111 | + 'Registration' => new EE_Has_Many_Relation(), | |
| 112 | + 'Payment' => new EE_Has_Many_Relation(), | |
| 113 | + 'Status' => new EE_Belongs_To_Relation(), | |
| 114 | + 'Line_Item' => new EE_Has_Many_Relation(false), | |
| 115 | + //you can delete a transaction without needing to delete its line items | |
| 116 | + 'Payment_Method' => new EE_Belongs_To_Relation(), | |
| 117 | + 'Message' => new EE_Has_Many_Relation() | |
| 118 | + ); | |
| 119 | + $this->_model_chain_to_wp_user = 'Registration.Event'; | |
| 120 | + parent::__construct($timezone); | |
| 121 | + | |
| 122 | + } | |
| 123 | + | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * txn_status_array | |
| 127 | + * get list of transaction statuses | |
| 128 | + * | |
| 129 | + * @access public | |
| 130 | + * @return array | |
| 131 | + */ | |
| 132 | + public static function txn_status_array() | |
| 133 | +	{ | |
| 134 | + return apply_filters( | |
| 135 | + 'FHEE__EEM_Transaction__txn_status_array', | |
| 136 | + array( | |
| 137 | + EEM_Transaction::overpaid_status_code, | |
| 138 | + EEM_Transaction::complete_status_code, | |
| 139 | + EEM_Transaction::incomplete_status_code, | |
| 140 | + EEM_Transaction::abandoned_status_code, | |
| 141 | + EEM_Transaction::failed_status_code, | |
| 142 | + ) | |
| 143 | + ); | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * get the revenue per day for the Transaction Admin page Reports Tab | |
| 148 | + * | |
| 149 | + * @access public | |
| 150 | + * | |
| 151 | + * @param string $period | |
| 152 | + * | |
| 153 | + * @return \stdClass[] | |
| 154 | + */ | |
| 155 | + public function get_revenue_per_day_report($period = '-1 month') | |
| 156 | +	{ | |
| 157 | +		$sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), | |
| 158 | + 'Y-m-d H:i:s', 'UTC'); | |
| 159 | + | |
| 160 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); | |
| 161 | + | |
| 162 | + return $this->_get_all_wpdb_results( | |
| 163 | + array( | |
| 164 | + array( | |
| 165 | +					'TXN_timestamp' => array('>=', $sql_date) | |
| 166 | + ), | |
| 167 | + 'group_by' => 'txnDate', | |
| 168 | +				'order_by' => array('TXN_timestamp' => 'ASC') | |
| 169 | + ), | |
| 170 | + OBJECT, | |
| 171 | + array( | |
| 172 | +				'txnDate' => array('DATE(' . $query_interval . ')', '%s'), | |
| 173 | +				'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') | |
| 174 | + ) | |
| 175 | + ); | |
| 176 | + } | |
| 177 | + | |
| 178 | + | |
| 179 | + /** | |
| 180 | + * get the revenue per event for the Transaction Admin page Reports Tab | |
| 181 | + * | |
| 182 | + * @access public | |
| 183 | + * | |
| 184 | + * @param string $period | |
| 185 | + * | |
| 186 | + * @throws \EE_Error | |
| 187 | + * @return mixed | |
| 188 | + */ | |
| 189 | + public function get_revenue_per_event_report($period = '-1 month') | |
| 190 | +	{ | |
| 191 | + global $wpdb; | |
| 192 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; | |
| 193 | + $registration_table = $wpdb->prefix . 'esp_registration'; | |
| 194 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; | |
| 195 | + $event_table = $wpdb->posts; | |
| 196 | + $payment_table = $wpdb->prefix . 'esp_payment'; | |
| 197 | +		$sql_date                   = date('Y-m-d H:i:s', strtotime($period)); | |
| 198 | + $approved_payment_status = EEM_Payment::status_id_approved; | |
| 199 | + $extra_event_on_join = ''; | |
| 200 | + //exclude events not authored by user if permissions in effect | |
| 201 | +		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { | |
| 202 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); | |
| 203 | + } | |
| 204 | + | |
| 205 | + return $wpdb->get_results( | |
| 206 | + "SELECT | |
| 207 | 207 | Transaction_Event.event_name AS event_name, | 
| 208 | 208 | SUM(Transaction_Event.paid) AS revenue | 
| 209 | 209 | FROM | 
| @@ -230,185 +230,185 @@ discard block | ||
| 230 | 230 | $extra_event_on_join | 
| 231 | 231 | ) AS Transaction_Event | 
| 232 | 232 | GROUP BY event_name", | 
| 233 | - OBJECT | |
| 234 | - ); | |
| 235 | - } | |
| 236 | - | |
| 237 | - | |
| 238 | - /** | |
| 239 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the | |
| 240 | - * $_REQUEST global variable. Either way, tries to find the current transaction (through | |
| 241 | - * the registration pointed to by reg_url_link), if not returns null | |
| 242 | - * | |
| 243 | - * @param string $reg_url_link | |
| 244 | - * | |
| 245 | - * @return EE_Transaction | |
| 246 | - */ | |
| 247 | - public function get_transaction_from_reg_url_link($reg_url_link = '') | |
| 248 | -    { | |
| 249 | - return $this->get_one(array( | |
| 250 | - array( | |
| 251 | -                'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', | |
| 252 | - '') | |
| 253 | - ) | |
| 254 | - )); | |
| 255 | - } | |
| 256 | - | |
| 257 | - | |
| 258 | - /** | |
| 259 | - * Updates the provided EE_Transaction with all the applicable payments | |
| 260 | - * (or fetch the EE_Transaction from its ID) | |
| 261 | - * | |
| 262 | - * @deprecated | |
| 263 | - * | |
| 264 | - * @param EE_Transaction|int $transaction_obj_or_id | |
| 265 | - * @param boolean $save_txn whether or not to save the transaction during this function call | |
| 266 | - * | |
| 267 | - * @return boolean | |
| 268 | - * @throws \EE_Error | |
| 269 | - */ | |
| 270 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) | |
| 271 | -    { | |
| 272 | - EE_Error::doing_it_wrong( | |
| 273 | - __CLASS__ . '::' . __FUNCTION__, | |
| 274 | -            sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), | |
| 275 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), | |
| 276 | - '4.6.0' | |
| 277 | - ); | |
| 278 | - /** @type EE_Transaction_Processor $transaction_processor */ | |
| 279 | -        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); | |
| 280 | - | |
| 281 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( | |
| 282 | - $this->ensure_is_obj($transaction_obj_or_id) | |
| 283 | - ); | |
| 284 | - } | |
| 285 | - | |
| 286 | - /** | |
| 287 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS | |
| 288 | - * of these, so we are very careful to NOT select (which the models do even when deleting), | |
| 289 | - * and so we only use wpdb directly and only do minimal joins. | |
| 290 | - * Transactions are considered "junk" if they're failed for longer than a week. | |
| 291 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on | |
| 292 | - * it, it's probably not junk (regardless of what status it has). | |
| 293 | - * The downside to this approach is that is addons are listening for object deletions | |
| 294 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into | |
| 295 | - * to catch these types of deletions. | |
| 296 | - * | |
| 297 | - * @global WPDB $wpdb | |
| 298 | - * @return mixed | |
| 299 | - */ | |
| 300 | - public function delete_junk_transactions() | |
| 301 | -    { | |
| 302 | - /** @type WPDB $wpdb */ | |
| 303 | - global $wpdb; | |
| 304 | - $deleted = false; | |
| 305 | - $time_to_leave_alone = apply_filters( | |
| 306 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone' | |
| 307 | - , WEEK_IN_SECONDS | |
| 308 | - ); | |
| 309 | - | |
| 310 | - | |
| 311 | - /** | |
| 312 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. | |
| 313 | - * Useful for plugins that want to exclude transactions matching certain query parameters. | |
| 314 | - * The query parameters should be in the format accepted by the EEM_Base model queries. | |
| 315 | - */ | |
| 316 | - $ids_query = apply_filters( | |
| 317 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', | |
| 318 | - array( | |
| 319 | - 0 => array( | |
| 320 | - 'STS_ID' => EEM_Transaction::failed_status_code, | |
| 321 | - 'Payment.PAY_ID' => array( 'IS NULL' ), | |
| 322 | -                    'TXN_timestamp' => array('<', time() - $time_to_leave_alone) | |
| 323 | - ) | |
| 324 | - ), | |
| 325 | - $time_to_leave_alone | |
| 326 | - ); | |
| 327 | - | |
| 328 | - | |
| 329 | - /** | |
| 330 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions | |
| 331 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. | |
| 332 | - */ | |
| 333 | - $txn_ids = apply_filters( | |
| 334 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', | |
| 335 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), | |
| 336 | - $time_to_leave_alone | |
| 337 | - ); | |
| 338 | - //now that we have the ids to delete | |
| 339 | -        if (! empty($txn_ids) && is_array($txn_ids)) { | |
| 340 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array | |
| 341 | - EEM_Transaction::unset_locked_transactions($txn_ids); | |
| 342 | - // let's get deletin'... | |
| 343 | - // Why no wpdb->prepare? Because the data is trusted. | |
| 344 | - // We got the ids from the original query to get them FROM | |
| 345 | - // the db (which is sanitized) so no need to prepare them again. | |
| 346 | - $query = ' | |
| 233 | + OBJECT | |
| 234 | + ); | |
| 235 | + } | |
| 236 | + | |
| 237 | + | |
| 238 | + /** | |
| 239 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the | |
| 240 | + * $_REQUEST global variable. Either way, tries to find the current transaction (through | |
| 241 | + * the registration pointed to by reg_url_link), if not returns null | |
| 242 | + * | |
| 243 | + * @param string $reg_url_link | |
| 244 | + * | |
| 245 | + * @return EE_Transaction | |
| 246 | + */ | |
| 247 | + public function get_transaction_from_reg_url_link($reg_url_link = '') | |
| 248 | +	{ | |
| 249 | + return $this->get_one(array( | |
| 250 | + array( | |
| 251 | +				'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', | |
| 252 | + '') | |
| 253 | + ) | |
| 254 | + )); | |
| 255 | + } | |
| 256 | + | |
| 257 | + | |
| 258 | + /** | |
| 259 | + * Updates the provided EE_Transaction with all the applicable payments | |
| 260 | + * (or fetch the EE_Transaction from its ID) | |
| 261 | + * | |
| 262 | + * @deprecated | |
| 263 | + * | |
| 264 | + * @param EE_Transaction|int $transaction_obj_or_id | |
| 265 | + * @param boolean $save_txn whether or not to save the transaction during this function call | |
| 266 | + * | |
| 267 | + * @return boolean | |
| 268 | + * @throws \EE_Error | |
| 269 | + */ | |
| 270 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) | |
| 271 | +	{ | |
| 272 | + EE_Error::doing_it_wrong( | |
| 273 | + __CLASS__ . '::' . __FUNCTION__, | |
| 274 | +			sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), | |
| 275 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), | |
| 276 | + '4.6.0' | |
| 277 | + ); | |
| 278 | + /** @type EE_Transaction_Processor $transaction_processor */ | |
| 279 | +		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); | |
| 280 | + | |
| 281 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( | |
| 282 | + $this->ensure_is_obj($transaction_obj_or_id) | |
| 283 | + ); | |
| 284 | + } | |
| 285 | + | |
| 286 | + /** | |
| 287 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS | |
| 288 | + * of these, so we are very careful to NOT select (which the models do even when deleting), | |
| 289 | + * and so we only use wpdb directly and only do minimal joins. | |
| 290 | + * Transactions are considered "junk" if they're failed for longer than a week. | |
| 291 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on | |
| 292 | + * it, it's probably not junk (regardless of what status it has). | |
| 293 | + * The downside to this approach is that is addons are listening for object deletions | |
| 294 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into | |
| 295 | + * to catch these types of deletions. | |
| 296 | + * | |
| 297 | + * @global WPDB $wpdb | |
| 298 | + * @return mixed | |
| 299 | + */ | |
| 300 | + public function delete_junk_transactions() | |
| 301 | +	{ | |
| 302 | + /** @type WPDB $wpdb */ | |
| 303 | + global $wpdb; | |
| 304 | + $deleted = false; | |
| 305 | + $time_to_leave_alone = apply_filters( | |
| 306 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone' | |
| 307 | + , WEEK_IN_SECONDS | |
| 308 | + ); | |
| 309 | + | |
| 310 | + | |
| 311 | + /** | |
| 312 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. | |
| 313 | + * Useful for plugins that want to exclude transactions matching certain query parameters. | |
| 314 | + * The query parameters should be in the format accepted by the EEM_Base model queries. | |
| 315 | + */ | |
| 316 | + $ids_query = apply_filters( | |
| 317 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', | |
| 318 | + array( | |
| 319 | + 0 => array( | |
| 320 | + 'STS_ID' => EEM_Transaction::failed_status_code, | |
| 321 | + 'Payment.PAY_ID' => array( 'IS NULL' ), | |
| 322 | +					'TXN_timestamp' => array('<', time() - $time_to_leave_alone) | |
| 323 | + ) | |
| 324 | + ), | |
| 325 | + $time_to_leave_alone | |
| 326 | + ); | |
| 327 | + | |
| 328 | + | |
| 329 | + /** | |
| 330 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions | |
| 331 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. | |
| 332 | + */ | |
| 333 | + $txn_ids = apply_filters( | |
| 334 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', | |
| 335 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), | |
| 336 | + $time_to_leave_alone | |
| 337 | + ); | |
| 338 | + //now that we have the ids to delete | |
| 339 | +		if (! empty($txn_ids) && is_array($txn_ids)) { | |
| 340 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array | |
| 341 | + EEM_Transaction::unset_locked_transactions($txn_ids); | |
| 342 | + // let's get deletin'... | |
| 343 | + // Why no wpdb->prepare? Because the data is trusted. | |
| 344 | + // We got the ids from the original query to get them FROM | |
| 345 | + // the db (which is sanitized) so no need to prepare them again. | |
| 346 | + $query = ' | |
| 347 | 347 | DELETE | 
| 348 | 348 | FROM ' . $this->table() . ' | 
| 349 | 349 | WHERE | 
| 350 | 350 |  					TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; | 
| 351 | - $deleted = $wpdb->query($query); | |
| 352 | - } | |
| 353 | -        if ($deleted) { | |
| 354 | - /** | |
| 355 | - * Allows code to do something after the transactions have been deleted. | |
| 356 | - */ | |
| 357 | -            do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); | |
| 358 | - } | |
| 359 | - | |
| 360 | - return $deleted; | |
| 361 | - } | |
| 362 | - | |
| 363 | - | |
| 364 | - /** | |
| 365 | - * @param array $transaction_IDs | |
| 366 | - * | |
| 367 | - * @return bool | |
| 368 | - */ | |
| 369 | - public static function unset_locked_transactions(array $transaction_IDs) | |
| 370 | -    { | |
| 371 | -        $locked_transactions = get_option('ee_locked_transactions', array()); | |
| 372 | - $update = false; | |
| 373 | -        foreach ($transaction_IDs as $TXN_ID) { | |
| 374 | -            if (isset($locked_transactions[$TXN_ID])) { | |
| 375 | - unset($locked_transactions[$TXN_ID]); | |
| 376 | - $update = true; | |
| 377 | - } | |
| 378 | - } | |
| 379 | -        if ($update) { | |
| 380 | -            update_option('ee_locked_transactions', $locked_transactions); | |
| 381 | - } | |
| 382 | - | |
| 383 | - return $update; | |
| 384 | - } | |
| 385 | - | |
| 386 | - | |
| 387 | - | |
| 388 | - /** | |
| 389 | - * returns an array of EE_Transaction objects whose timestamp is less than | |
| 390 | - * the current time minus the session lifespan, which defaults to 60 minutes | |
| 391 | - * | |
| 392 | - * @return EE_Base_Class[]|EE_Transaction[] | |
| 393 | - * @throws \EE_Error | |
| 394 | - */ | |
| 395 | - public function get_transactions_in_progress() | |
| 396 | -    { | |
| 397 | - return $this->get_all( | |
| 398 | - array( | |
| 399 | - array( | |
| 400 | - 'TXN_timestamp' => array( | |
| 401 | - '>', | |
| 402 | - time() - EE_Registry::instance()->SSN->lifespan() | |
| 403 | - ), | |
| 404 | - 'STS_ID' => array( | |
| 405 | - '!=', | |
| 406 | - EEM_Transaction::complete_status_code | |
| 407 | - ), | |
| 408 | - ) | |
| 409 | - ) | |
| 410 | - ); | |
| 411 | - } | |
| 351 | + $deleted = $wpdb->query($query); | |
| 352 | + } | |
| 353 | +		if ($deleted) { | |
| 354 | + /** | |
| 355 | + * Allows code to do something after the transactions have been deleted. | |
| 356 | + */ | |
| 357 | +			do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); | |
| 358 | + } | |
| 359 | + | |
| 360 | + return $deleted; | |
| 361 | + } | |
| 362 | + | |
| 363 | + | |
| 364 | + /** | |
| 365 | + * @param array $transaction_IDs | |
| 366 | + * | |
| 367 | + * @return bool | |
| 368 | + */ | |
| 369 | + public static function unset_locked_transactions(array $transaction_IDs) | |
| 370 | +	{ | |
| 371 | +		$locked_transactions = get_option('ee_locked_transactions', array()); | |
| 372 | + $update = false; | |
| 373 | +		foreach ($transaction_IDs as $TXN_ID) { | |
| 374 | +			if (isset($locked_transactions[$TXN_ID])) { | |
| 375 | + unset($locked_transactions[$TXN_ID]); | |
| 376 | + $update = true; | |
| 377 | + } | |
| 378 | + } | |
| 379 | +		if ($update) { | |
| 380 | +			update_option('ee_locked_transactions', $locked_transactions); | |
| 381 | + } | |
| 382 | + | |
| 383 | + return $update; | |
| 384 | + } | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + /** | |
| 389 | + * returns an array of EE_Transaction objects whose timestamp is less than | |
| 390 | + * the current time minus the session lifespan, which defaults to 60 minutes | |
| 391 | + * | |
| 392 | + * @return EE_Base_Class[]|EE_Transaction[] | |
| 393 | + * @throws \EE_Error | |
| 394 | + */ | |
| 395 | + public function get_transactions_in_progress() | |
| 396 | +	{ | |
| 397 | + return $this->get_all( | |
| 398 | + array( | |
| 399 | + array( | |
| 400 | + 'TXN_timestamp' => array( | |
| 401 | + '>', | |
| 402 | + time() - EE_Registry::instance()->SSN->lifespan() | |
| 403 | + ), | |
| 404 | + 'STS_ID' => array( | |
| 405 | + '!=', | |
| 406 | + EEM_Transaction::complete_status_code | |
| 407 | + ), | |
| 408 | + ) | |
| 409 | + ) | |
| 410 | + ); | |
| 411 | + } | |
| 412 | 412 | |
| 413 | 413 | |
| 414 | 414 | } | 
| @@ -3,7 +3,7 @@ discard block | ||
| 3 | 3 |  if ( ! defined('EVENT_ESPRESSO_VERSION')) { | 
| 4 | 4 |      exit('No direct script access allowed'); | 
| 5 | 5 | } | 
| 6 | -require_once(EE_MODELS . 'EEM_Base.model.php'); | |
| 6 | +require_once(EE_MODELS.'EEM_Base.model.php'); | |
| 7 | 7 | |
| 8 | 8 | /** | 
| 9 | 9 | * | 
| @@ -107,7 +107,7 @@ discard block | ||
| 107 | 107 |                      __('Registration Steps', 'event_espresso'), false, array()), | 
| 108 | 108 | ) | 
| 109 | 109 | ); | 
| 110 | - $this->_model_relations = array( | |
| 110 | + $this->_model_relations = array( | |
| 111 | 111 | 'Registration' => new EE_Has_Many_Relation(), | 
| 112 | 112 | 'Payment' => new EE_Has_Many_Relation(), | 
| 113 | 113 | 'Status' => new EE_Belongs_To_Relation(), | 
| @@ -169,7 +169,7 @@ discard block | ||
| 169 | 169 | ), | 
| 170 | 170 | OBJECT, | 
| 171 | 171 | array( | 
| 172 | -                'txnDate' => array('DATE(' . $query_interval . ')', '%s'), | |
| 172 | +                'txnDate' => array('DATE('.$query_interval.')', '%s'), | |
| 173 | 173 |                  'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') | 
| 174 | 174 | ) | 
| 175 | 175 | ); | 
| @@ -189,17 +189,17 @@ discard block | ||
| 189 | 189 | public function get_revenue_per_event_report($period = '-1 month') | 
| 190 | 190 |      { | 
| 191 | 191 | global $wpdb; | 
| 192 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; | |
| 193 | - $registration_table = $wpdb->prefix . 'esp_registration'; | |
| 194 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; | |
| 192 | + $transaction_table = $wpdb->prefix.'esp_transaction'; | |
| 193 | + $registration_table = $wpdb->prefix.'esp_registration'; | |
| 194 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; | |
| 195 | 195 | $event_table = $wpdb->posts; | 
| 196 | - $payment_table = $wpdb->prefix . 'esp_payment'; | |
| 196 | + $payment_table = $wpdb->prefix.'esp_payment'; | |
| 197 | 197 |          $sql_date                   = date('Y-m-d H:i:s', strtotime($period)); | 
| 198 | 198 | $approved_payment_status = EEM_Payment::status_id_approved; | 
| 199 | 199 | $extra_event_on_join = ''; | 
| 200 | 200 | //exclude events not authored by user if permissions in effect | 
| 201 | 201 |          if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { | 
| 202 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); | |
| 202 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); | |
| 203 | 203 | } | 
| 204 | 204 | |
| 205 | 205 | return $wpdb->get_results( | 
| @@ -270,7 +270,7 @@ discard block | ||
| 270 | 270 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) | 
| 271 | 271 |      { | 
| 272 | 272 | EE_Error::doing_it_wrong( | 
| 273 | - __CLASS__ . '::' . __FUNCTION__, | |
| 273 | + __CLASS__.'::'.__FUNCTION__, | |
| 274 | 274 |              sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), | 
| 275 | 275 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), | 
| 276 | 276 | '4.6.0' | 
| @@ -318,7 +318,7 @@ discard block | ||
| 318 | 318 | array( | 
| 319 | 319 | 0 => array( | 
| 320 | 320 | 'STS_ID' => EEM_Transaction::failed_status_code, | 
| 321 | - 'Payment.PAY_ID' => array( 'IS NULL' ), | |
| 321 | +                    'Payment.PAY_ID' => array('IS NULL'), | |
| 322 | 322 |                      'TXN_timestamp' => array('<', time() - $time_to_leave_alone) | 
| 323 | 323 | ) | 
| 324 | 324 | ), | 
| @@ -336,18 +336,18 @@ discard block | ||
| 336 | 336 | $time_to_leave_alone | 
| 337 | 337 | ); | 
| 338 | 338 | //now that we have the ids to delete | 
| 339 | -        if (! empty($txn_ids) && is_array($txn_ids)) { | |
| 339 | +        if ( ! empty($txn_ids) && is_array($txn_ids)) { | |
| 340 | 340 | // first, make sure these TXN's are removed the "ee_locked_transactions" array | 
| 341 | 341 | EEM_Transaction::unset_locked_transactions($txn_ids); | 
| 342 | 342 | // let's get deletin'... | 
| 343 | 343 | // Why no wpdb->prepare? Because the data is trusted. | 
| 344 | 344 | // We got the ids from the original query to get them FROM | 
| 345 | 345 | // the db (which is sanitized) so no need to prepare them again. | 
| 346 | - $query = ' | |
| 346 | + $query = ' | |
| 347 | 347 | DELETE | 
| 348 | - FROM ' . $this->table() . ' | |
| 348 | + FROM ' . $this->table().' | |
| 349 | 349 | WHERE | 
| 350 | -					TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; | |
| 350 | +					TXN_ID IN ( ' . implode(",", $txn_ids).')'; | |
| 351 | 351 | $deleted = $wpdb->query($query); | 
| 352 | 352 | } | 
| 353 | 353 |          if ($deleted) { | 
| @@ -125,14 +125,14 @@ | ||
| 125 | 125 |  	public function get_attendee_property_answer_value( EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE ){ | 
| 126 | 126 | $field_name = NULL; | 
| 127 | 127 | $value = NULL; | 
| 128 | - //backward compat: we still want to find the question's ID | |
| 129 | -                if( is_numeric( $question_system_id ) ) { | |
| 130 | - //find this question's QST_system value | |
| 131 | - $question_id = $question_system_id; | |
| 132 | - $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' ); | |
| 133 | -                } else { | |
| 134 | - $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' ); | |
| 135 | - } | |
| 128 | + //backward compat: we still want to find the question's ID | |
| 129 | +				if( is_numeric( $question_system_id ) ) { | |
| 130 | + //find this question's QST_system value | |
| 131 | + $question_id = $question_system_id; | |
| 132 | + $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' ); | |
| 133 | +				} else { | |
| 134 | + $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' ); | |
| 135 | + } | |
| 136 | 136 | //only bother checking if the registration has an attendee | 
| 137 | 137 |  		if( $registration->attendee() instanceof EE_Attendee ) { | 
| 138 | 138 | $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question( $question_system_id ); | 
| @@ -51,18 +51,18 @@ discard block | ||
| 51 | 51 | /** | 
| 52 | 52 | * constructor | 
| 53 | 53 | */ | 
| 54 | -	protected function __construct( $timezone = NULL ){ | |
| 55 | -		$this->singular_item = __('Answer','event_espresso'); | |
| 56 | -		$this->plural_item = __('Answers','event_espresso'); | |
| 54 | +	protected function __construct($timezone = NULL) { | |
| 55 | +		$this->singular_item = __('Answer', 'event_espresso'); | |
| 56 | +		$this->plural_item = __('Answers', 'event_espresso'); | |
| 57 | 57 | $this->_tables = array( | 
| 58 | 58 |  			'Answer'=> new EE_Primary_Table('esp_answer', 'ANS_ID') | 
| 59 | 59 | ); | 
| 60 | 60 | $this->_fields = array( | 
| 61 | 61 | 'Answer'=>array( | 
| 62 | -				'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID','event_espresso')), | |
| 63 | -				'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID','event_espresso'), false, 0, 'Registration'), | |
| 64 | -				'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID','event_espresso'), false, 0, 'Question'), | |
| 65 | -				'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value','event_espresso'), false, '') | |
| 62 | +				'ANS_ID'=> new EE_Primary_Key_Int_Field('ANS_ID', __('Answer ID', 'event_espresso')), | |
| 63 | +				'REG_ID'=>new EE_Foreign_Key_Int_Field('REG_ID', __('Registration ID', 'event_espresso'), false, 0, 'Registration'), | |
| 64 | +				'QST_ID'=>new EE_Foreign_Key_Int_Field('QST_ID', __('Question ID', 'event_espresso'), false, 0, 'Question'), | |
| 65 | +				'ANS_value'=>new EE_Maybe_Serialized_Simple_HTML_Field('ANS_value', __('Answer Value', 'event_espresso'), false, '') | |
| 66 | 66 | )); | 
| 67 | 67 | $this->_model_relations = array( | 
| 68 | 68 | 'Registration'=>new EE_Belongs_To_Relation(), | 
| @@ -70,7 +70,7 @@ discard block | ||
| 70 | 70 | ); | 
| 71 | 71 | $this->_model_chain_to_wp_user = 'Registration.Event'; | 
| 72 | 72 | $this->_caps_slug = 'registrations'; | 
| 73 | - parent::__construct( $timezone ); | |
| 73 | + parent::__construct($timezone); | |
| 74 | 74 | } | 
| 75 | 75 | |
| 76 | 76 | |
| @@ -83,19 +83,19 @@ discard block | ||
| 83 | 83 | * @param boolean $pretty_answer whether to call 'pretty_value' or just 'value' | 
| 84 | 84 | * @return string | 
| 85 | 85 | */ | 
| 86 | -	public function get_answer_value_to_question( EE_Registration $registration, $question_id = NULL,$pretty_answer = FALSE ){ | |
| 87 | - $value = $this->get_attendee_property_answer_value( $registration, $question_id, $pretty_answer ); | |
| 88 | -		if (  $value === NULL ){ | |
| 89 | - $answer_obj = $this->get_registration_question_answer_object( $registration, $question_id); | |
| 90 | -			if( $answer_obj instanceof EE_Answer ){ | |
| 91 | -				if($pretty_answer){ | |
| 86 | +	public function get_answer_value_to_question(EE_Registration $registration, $question_id = NULL, $pretty_answer = FALSE) { | |
| 87 | + $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer); | |
| 88 | +		if ($value === NULL) { | |
| 89 | + $answer_obj = $this->get_registration_question_answer_object($registration, $question_id); | |
| 90 | +			if ($answer_obj instanceof EE_Answer) { | |
| 91 | +				if ($pretty_answer) { | |
| 92 | 92 | $value = $answer_obj->pretty_value(); | 
| 93 | -				}else{ | |
| 93 | +				} else { | |
| 94 | 94 | $value = $answer_obj->value(); | 
| 95 | 95 | } | 
| 96 | 96 | } | 
| 97 | 97 | } | 
| 98 | - return apply_filters( 'FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id ); | |
| 98 | +		return apply_filters('FHEE__EEM_Answer__get_answer_value_to_question__answer_value', $value, $registration, $question_id); | |
| 99 | 99 | } | 
| 100 | 100 | |
| 101 | 101 | |
| @@ -106,9 +106,9 @@ discard block | ||
| 106 | 106 | * @param int $question_id | 
| 107 | 107 | * @return EE_Answer | 
| 108 | 108 | */ | 
| 109 | -	public function get_registration_question_answer_object( EE_Registration $registration, $question_id = NULL){ | |
| 110 | - $answer_obj = $this->get_one( array( array( 'QST_ID'=>$question_id, 'REG_ID'=>$registration->ID() ))); | |
| 111 | - return apply_filters( 'FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id ); | |
| 109 | +	public function get_registration_question_answer_object(EE_Registration $registration, $question_id = NULL) { | |
| 110 | +		$answer_obj = $this->get_one(array(array('QST_ID'=>$question_id, 'REG_ID'=>$registration->ID()))); | |
| 111 | +		return apply_filters('FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj', $answer_obj, $registration, $question_id); | |
| 112 | 112 | } | 
| 113 | 113 | |
| 114 | 114 | |
| @@ -122,39 +122,39 @@ discard block | ||
| 122 | 122 | * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or QST_system for | 
| 123 | 123 | * a question corresponding to an attendee field, returns null) | 
| 124 | 124 | */ | 
| 125 | -	public function get_attendee_property_answer_value( EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE ){ | |
| 125 | +	public function get_attendee_property_answer_value(EE_Registration $registration, $question_system_id = NULL, $pretty_answer = FALSE) { | |
| 126 | 126 | $field_name = NULL; | 
| 127 | 127 | $value = NULL; | 
| 128 | 128 | //backward compat: we still want to find the question's ID | 
| 129 | -                if( is_numeric( $question_system_id ) ) { | |
| 129 | +                if (is_numeric($question_system_id)) { | |
| 130 | 130 | //find this question's QST_system value | 
| 131 | 131 | $question_id = $question_system_id; | 
| 132 | - $question_system_id = EEM_Question::instance()->get_var( array( array( 'QST_ID' => $question_system_id ) ), 'QST_system' ); | |
| 132 | +                    $question_system_id = EEM_Question::instance()->get_var(array(array('QST_ID' => $question_system_id)), 'QST_system'); | |
| 133 | 133 |                  } else { | 
| 134 | - $question_id = (int) EEM_Question::instance()->get_var( array( array( 'QST_system' => $question_system_id ) ), 'QST_ID' ); | |
| 134 | +                    $question_id = (int) EEM_Question::instance()->get_var(array(array('QST_system' => $question_system_id)), 'QST_ID'); | |
| 135 | 135 | } | 
| 136 | 136 | //only bother checking if the registration has an attendee | 
| 137 | -		if( $registration->attendee() instanceof EE_Attendee ) { | |
| 138 | - $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question( $question_system_id ); | |
| 139 | -			if( $field_name ) { | |
| 140 | -				if( $pretty_answer ) { | |
| 141 | -					if( $field_name === 'STA_ID' ) { | |
| 137 | +		if ($registration->attendee() instanceof EE_Attendee) { | |
| 138 | + $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id); | |
| 139 | +			if ($field_name) { | |
| 140 | +				if ($pretty_answer) { | |
| 141 | +					if ($field_name === 'STA_ID') { | |
| 142 | 142 | $state = $registration->attendee()->state_obj(); | 
| 143 | -						$value = $state instanceof EE_State ? $state->name() : sprintf( __('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID() ); | |
| 144 | -					} else if($field_name === 'CNT_ISO') { | |
| 143 | +						$value = $state instanceof EE_State ? $state->name() : sprintf(__('Unknown State (%s)', 'event_espresso'), $registration->attendee()->state_ID()); | |
| 144 | +					} else if ($field_name === 'CNT_ISO') { | |
| 145 | 145 | $country = $registration->attendee()->country_obj(); | 
| 146 | -						$value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"),$registration->attendee()->country_ID()); | |
| 146 | +						$value = $country instanceof EE_Country ? $country->name() : sprintf(__('Unknown Country (%s)', "event_espresso"), $registration->attendee()->country_ID()); | |
| 147 | 147 |  					} else { | 
| 148 | - $value = $registration->attendee()->get_pretty( $field_name ); | |
| 148 | + $value = $registration->attendee()->get_pretty($field_name); | |
| 149 | 149 | } | 
| 150 | 150 | //if field name is blank, leave the value as null too | 
| 151 | -				}else{ | |
| 152 | - $value = $registration->attendee()->get( $field_name ); | |
| 151 | +				} else { | |
| 152 | + $value = $registration->attendee()->get($field_name); | |
| 153 | 153 | } | 
| 154 | 154 | } | 
| 155 | 155 | //if no field was found, leave value blank | 
| 156 | 156 | } | 
| 157 | - return apply_filters( 'FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id ); | |
| 157 | +		return apply_filters('FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value', $value, $registration, $question_id, $question_system_id); | |
| 158 | 158 | } | 
| 159 | 159 | |
| 160 | 160 | |
| @@ -113,12 +113,12 @@ discard block | ||
| 113 | 113 | public function previous(); | 
| 114 | 114 | |
| 115 | 115 | /** | 
| 116 | - * Returns the index of a given object, or false if not found | |
| 117 | - * | |
| 118 | - * @see http://stackoverflow.com/a/8736013 | |
| 119 | - * @param $object | |
| 120 | - * @return boolean|int|string | |
| 121 | - */ | |
| 116 | + * Returns the index of a given object, or false if not found | |
| 117 | + * | |
| 118 | + * @see http://stackoverflow.com/a/8736013 | |
| 119 | + * @param $object | |
| 120 | + * @return boolean|int|string | |
| 121 | + */ | |
| 122 | 122 | public function indexOf( $object ); | 
| 123 | 123 | |
| 124 | 124 | |
| @@ -160,17 +160,17 @@ discard block | ||
| 160 | 160 | |
| 161 | 161 | |
| 162 | 162 | |
| 163 | - /** | |
| 164 | - * detaches ALL objects from the Collection | |
| 165 | - */ | |
| 166 | - public function detachAll(); | |
| 163 | + /** | |
| 164 | + * detaches ALL objects from the Collection | |
| 165 | + */ | |
| 166 | + public function detachAll(); | |
| 167 | 167 | |
| 168 | 168 | |
| 169 | 169 | |
| 170 | - /** | |
| 171 | - * unsets and detaches ALL objects from the Collection | |
| 172 | - */ | |
| 173 | - public function trashAndDetachAll(); | |
| 170 | + /** | |
| 171 | + * unsets and detaches ALL objects from the Collection | |
| 172 | + */ | |
| 173 | + public function trashAndDetachAll(); | |
| 174 | 174 | |
| 175 | 175 | } | 
| 176 | 176 | // End of file CollectionInterface.php |