@@ -2166,6 +2166,7 @@ |
||
| 2166 | 2166 | * |
| 2167 | 2167 | * @access protected |
| 2168 | 2168 | * @param \EE_Payment | null $payment |
| 2169 | + * @param EE_Payment $payment |
|
| 2169 | 2170 | */ |
| 2170 | 2171 | protected function _maybe_send_notifications($payment = null) |
| 2171 | 2172 | { |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | '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.', |
| 267 | 267 | 'event_espresso' |
| 268 | 268 | ); |
| 269 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 269 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 270 | 270 | 'An error occurred! Please refresh the page and try again.', |
| 271 | 271 | 'event_espresso' |
| 272 | 272 | ); |
@@ -364,13 +364,13 @@ discard block |
||
| 364 | 364 | //enqueue style |
| 365 | 365 | wp_register_style( |
| 366 | 366 | 'espresso_txn', |
| 367 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 367 | + TXN_ASSETS_URL.'espresso_transactions_admin.css', |
|
| 368 | 368 | array(), |
| 369 | 369 | EVENT_ESPRESSO_VERSION |
| 370 | 370 | ); |
| 371 | 371 | wp_enqueue_style('espresso_txn'); |
| 372 | 372 | //scripts |
| 373 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 373 | + wp_register_script('espresso_txn', TXN_ASSETS_URL.'espresso_transactions_admin.js', array( |
|
| 374 | 374 | 'ee_admin_js', |
| 375 | 375 | 'ee-datepicker', |
| 376 | 376 | 'jquery-ui-datepicker', |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | : null; |
| 467 | 467 | $this->_transaction->verify_abandoned_transaction_status(); |
| 468 | 468 | |
| 469 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 469 | + if ( ! $this->_transaction instanceof EE_Transaction) { |
|
| 470 | 470 | $error_msg = sprintf( |
| 471 | 471 | esc_html__( |
| 472 | 472 | 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
| 565 | 565 | array( |
| 566 | 566 | 'overpaid' => array( |
| 567 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 567 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code, |
|
| 568 | 568 | 'desc' => EEH_Template::pretty_status( |
| 569 | 569 | EEM_Transaction::overpaid_status_code, |
| 570 | 570 | false, |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | ), |
| 573 | 573 | ), |
| 574 | 574 | 'complete' => array( |
| 575 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 575 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code, |
|
| 576 | 576 | 'desc' => EEH_Template::pretty_status( |
| 577 | 577 | EEM_Transaction::complete_status_code, |
| 578 | 578 | false, |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | ), |
| 581 | 581 | ), |
| 582 | 582 | 'incomplete' => array( |
| 583 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 583 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code, |
|
| 584 | 584 | 'desc' => EEH_Template::pretty_status( |
| 585 | 585 | EEM_Transaction::incomplete_status_code, |
| 586 | 586 | false, |
@@ -588,7 +588,7 @@ discard block |
||
| 588 | 588 | ), |
| 589 | 589 | ), |
| 590 | 590 | 'abandoned' => array( |
| 591 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 591 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code, |
|
| 592 | 592 | 'desc' => EEH_Template::pretty_status( |
| 593 | 593 | EEM_Transaction::abandoned_status_code, |
| 594 | 594 | false, |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | ), |
| 597 | 597 | ), |
| 598 | 598 | 'failed' => array( |
| 599 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 599 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code, |
|
| 600 | 600 | 'desc' => EEH_Template::pretty_status( |
| 601 | 601 | EEM_Transaction::failed_status_code, |
| 602 | 602 | false, |
@@ -645,11 +645,11 @@ discard block |
||
| 645 | 645 | 'Click to Edit event', |
| 646 | 646 | 'event_espresso' |
| 647 | 647 | ) |
| 648 | - . '">' . $event->get('EVT_name') . '</a>', |
|
| 648 | + . '">'.$event->get('EVT_name').'</a>', |
|
| 649 | 649 | '</h3>' |
| 650 | 650 | ) |
| 651 | 651 | : ''; |
| 652 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 652 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 653 | 653 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 654 | 654 | } |
| 655 | 655 | |
@@ -691,7 +691,7 @@ discard block |
||
| 691 | 691 | |
| 692 | 692 | $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
| 693 | 693 | $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
| 694 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 694 | + $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->get('STS_ID'); |
|
| 695 | 695 | |
| 696 | 696 | $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
| 697 | 697 | $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | |
| 773 | 773 | |
| 774 | 774 | // next link |
| 775 | - $next_txn = $this->_transaction->next( |
|
| 775 | + $next_txn = $this->_transaction->next( |
|
| 776 | 776 | null, |
| 777 | 777 | array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
| 778 | 778 | 'TXN_ID' |
@@ -787,7 +787,7 @@ discard block |
||
| 787 | 787 | ) |
| 788 | 788 | : ''; |
| 789 | 789 | // previous link |
| 790 | - $previous_txn = $this->_transaction->previous( |
|
| 790 | + $previous_txn = $this->_transaction->previous( |
|
| 791 | 791 | null, |
| 792 | 792 | array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
| 793 | 793 | 'TXN_ID' |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | // grab messages at the last second |
| 838 | 838 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 839 | 839 | // path to template |
| 840 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 840 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php'; |
|
| 841 | 841 | $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
| 842 | 842 | $template_path, |
| 843 | 843 | $this->_template_args, |
@@ -926,7 +926,7 @@ discard block |
||
| 926 | 926 | |
| 927 | 927 | //get line table |
| 928 | 928 | EEH_Autoloader::register_line_item_display_autoloaders(); |
| 929 | - $Line_Item_Display = new EE_Line_Item_Display( |
|
| 929 | + $Line_Item_Display = new EE_Line_Item_Display( |
|
| 930 | 930 | 'admin_table', |
| 931 | 931 | 'EE_Admin_Table_Line_Item_Display_Strategy' |
| 932 | 932 | ); |
@@ -937,13 +937,13 @@ discard block |
||
| 937 | 937 | ->get('REG_code'); |
| 938 | 938 | |
| 939 | 939 | // process taxes |
| 940 | - $taxes = $this->_transaction->get_many_related( |
|
| 940 | + $taxes = $this->_transaction->get_many_related( |
|
| 941 | 941 | 'Line_Item', |
| 942 | 942 | array(array('LIN_type' => EEM_Line_Item::type_tax)) |
| 943 | 943 | ); |
| 944 | 944 | $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
| 945 | 945 | |
| 946 | - $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 946 | + $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 947 | 947 | $this->_transaction->get('TXN_total'), |
| 948 | 948 | false, |
| 949 | 949 | false |
@@ -953,7 +953,7 @@ discard block |
||
| 953 | 953 | |
| 954 | 954 | // process payment details |
| 955 | 955 | $payments = $this->_transaction->get_many_related('Payment'); |
| 956 | - if (! empty($payments)) { |
|
| 956 | + if ( ! empty($payments)) { |
|
| 957 | 957 | $this->_template_args['payments'] = $payments; |
| 958 | 958 | $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
| 959 | 959 | } else { |
@@ -1014,7 +1014,7 @@ discard block |
||
| 1014 | 1014 | esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
| 1015 | 1015 | ucwords(str_replace('_', ' ', $reg_step)), |
| 1016 | 1016 | date( |
| 1017 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1017 | + get_option('date_format').' '.get_option('time_format'), |
|
| 1018 | 1018 | ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
| 1019 | 1019 | ) |
| 1020 | 1020 | ) |
@@ -1028,7 +1028,7 @@ discard block |
||
| 1028 | 1028 | . '</li>'; |
| 1029 | 1029 | } |
| 1030 | 1030 | } |
| 1031 | - $reg_steps .= '</ul>'; |
|
| 1031 | + $reg_steps .= '</ul>'; |
|
| 1032 | 1032 | $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
| 1033 | 1033 | $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
| 1034 | 1034 | 'Registration Step Progress', |
@@ -1041,11 +1041,11 @@ discard block |
||
| 1041 | 1041 | $this->_get_payment_status_array(); |
| 1042 | 1042 | $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
| 1043 | 1043 | |
| 1044 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1044 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1045 | 1045 | 'action' => 'edit_transaction', |
| 1046 | 1046 | 'process' => 'transaction', |
| 1047 | 1047 | ), TXN_ADMIN_URL); |
| 1048 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 1048 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 1049 | 1049 | 'page' => 'espresso_transactions', |
| 1050 | 1050 | 'action' => 'espresso_apply_payment', |
| 1051 | 1051 | ), WP_AJAX_URL); |
@@ -1056,7 +1056,7 @@ discard block |
||
| 1056 | 1056 | |
| 1057 | 1057 | // 'espresso_delete_payment_nonce' |
| 1058 | 1058 | |
| 1059 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1059 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1060 | 1060 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 1061 | 1061 | } |
| 1062 | 1062 | |
@@ -1085,11 +1085,11 @@ discard block |
||
| 1085 | 1085 | ), |
| 1086 | 1086 | ), |
| 1087 | 1087 | )); |
| 1088 | - if (! empty($reg_payments)) { |
|
| 1088 | + if ( ! empty($reg_payments)) { |
|
| 1089 | 1089 | foreach ($payments as $payment) { |
| 1090 | - if (! $payment instanceof EE_Payment) { |
|
| 1090 | + if ( ! $payment instanceof EE_Payment) { |
|
| 1091 | 1091 | continue; |
| 1092 | - } elseif (! isset($existing_reg_payments[$payment->ID()])) { |
|
| 1092 | + } elseif ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
| 1093 | 1093 | $existing_reg_payments[$payment->ID()] = array(); |
| 1094 | 1094 | } |
| 1095 | 1095 | foreach ($reg_payments as $reg_payment) { |
@@ -1118,7 +1118,7 @@ discard block |
||
| 1118 | 1118 | protected function _get_registrations_to_apply_payment_to() |
| 1119 | 1119 | { |
| 1120 | 1120 | // we want any registration with an active status (ie: not deleted or cancelled) |
| 1121 | - $query_params = array( |
|
| 1121 | + $query_params = array( |
|
| 1122 | 1122 | array( |
| 1123 | 1123 | 'STS_ID' => array( |
| 1124 | 1124 | 'IN', |
@@ -1137,16 +1137,16 @@ discard block |
||
| 1137 | 1137 | '', |
| 1138 | 1138 | 'clear: both; margin: 1.5em 0 0; display: none;' |
| 1139 | 1139 | ); |
| 1140 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1140 | + $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1141 | 1141 | $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
| 1142 | 1142 | $registrations_to_apply_payment_to .= EEH_HTML::thead( |
| 1143 | 1143 | EEH_HTML::tr( |
| 1144 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1145 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1146 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1147 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1148 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1149 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1144 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')). |
|
| 1145 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')). |
|
| 1146 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')). |
|
| 1147 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')). |
|
| 1148 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
| 1149 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
| 1150 | 1150 | EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
| 1151 | 1151 | ) |
| 1152 | 1152 | ); |
@@ -1161,29 +1161,29 @@ discard block |
||
| 1161 | 1161 | : esc_html__('Unknown Attendee', 'event_espresso'); |
| 1162 | 1162 | $owing = $registration->final_price() - $registration->paid(); |
| 1163 | 1163 | $taxable = $registration->ticket()->taxable() |
| 1164 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1164 | + ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>' |
|
| 1165 | 1165 | : ''; |
| 1166 | 1166 | $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
| 1167 | 1167 | ? ' checked="checked"' |
| 1168 | 1168 | : ''; |
| 1169 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1169 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1170 | 1170 | $registrations_to_apply_payment_to .= EEH_HTML::tr( |
| 1171 | - EEH_HTML::td($registration->ID()) . |
|
| 1172 | - EEH_HTML::td($attendee_name) . |
|
| 1171 | + EEH_HTML::td($registration->ID()). |
|
| 1172 | + EEH_HTML::td($attendee_name). |
|
| 1173 | 1173 | EEH_HTML::td( |
| 1174 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1175 | - ) . |
|
| 1176 | - EEH_HTML::td($registration->event_name()) . |
|
| 1177 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1178 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1174 | + $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable |
|
| 1175 | + ). |
|
| 1176 | + EEH_HTML::td($registration->event_name()). |
|
| 1177 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
| 1178 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
| 1179 | 1179 | EEH_HTML::td( |
| 1180 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 1180 | + '<input type="checkbox" value="'.$registration->ID() |
|
| 1181 | 1181 | . '" name="txn_admin_payment[registrations]"' |
| 1182 | - . $checked . $disabled . '>', |
|
| 1182 | + . $checked.$disabled.'>', |
|
| 1183 | 1183 | '', |
| 1184 | 1184 | 'jst-cntr' |
| 1185 | 1185 | ), |
| 1186 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1186 | + 'apply-payment-registration-row-'.$registration->ID() |
|
| 1187 | 1187 | ); |
| 1188 | 1188 | } |
| 1189 | 1189 | } |
@@ -1198,7 +1198,7 @@ discard block |
||
| 1198 | 1198 | '', |
| 1199 | 1199 | 'clear description' |
| 1200 | 1200 | ); |
| 1201 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1201 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1202 | 1202 | $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
| 1203 | 1203 | } |
| 1204 | 1204 | |
@@ -1263,12 +1263,12 @@ discard block |
||
| 1263 | 1263 | array( |
| 1264 | 1264 | 'OR*payment_method_for_payment' => array( |
| 1265 | 1265 | 'PMD_ID' => array('IN', $payment_methods_of_payments), |
| 1266 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1266 | + 'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'), |
|
| 1267 | 1267 | ), |
| 1268 | 1268 | ), |
| 1269 | 1269 | ); |
| 1270 | 1270 | } else { |
| 1271 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1271 | + $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'))); |
|
| 1272 | 1272 | } |
| 1273 | 1273 | $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
| 1274 | 1274 | } |
@@ -1297,7 +1297,7 @@ discard block |
||
| 1297 | 1297 | 'Line_Item', |
| 1298 | 1298 | array(array('LIN_type' => 'line-item')) |
| 1299 | 1299 | ); |
| 1300 | - if (! empty($line_items)) { |
|
| 1300 | + if ( ! empty($line_items)) { |
|
| 1301 | 1301 | foreach ($line_items as $item) { |
| 1302 | 1302 | if ($item instanceof EE_Line_Item) { |
| 1303 | 1303 | switch ($item->OBJ_type()) { |
@@ -1307,7 +1307,7 @@ discard block |
||
| 1307 | 1307 | $ticket = $item->ticket(); |
| 1308 | 1308 | //right now we're only handling tickets here. |
| 1309 | 1309 | //Cause its expected that only tickets will have attendees right? |
| 1310 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1310 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 1311 | 1311 | continue; |
| 1312 | 1312 | } |
| 1313 | 1313 | try { |
@@ -1316,7 +1316,7 @@ discard block |
||
| 1316 | 1316 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 1317 | 1317 | $event_name = esc_html__('Unknown Event', 'event_espresso'); |
| 1318 | 1318 | } |
| 1319 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1319 | + $event_name .= ' - '.$item->get('LIN_name'); |
|
| 1320 | 1320 | $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
| 1321 | 1321 | // now get all of the registrations for this transaction that use this ticket |
| 1322 | 1322 | $registrations = $ticket->get_many_related( |
@@ -1324,7 +1324,7 @@ discard block |
||
| 1324 | 1324 | array(array('TXN_ID' => $this->_transaction->ID())) |
| 1325 | 1325 | ); |
| 1326 | 1326 | foreach ($registrations as $registration) { |
| 1327 | - if (! $registration instanceof EE_Registration) { |
|
| 1327 | + if ( ! $registration instanceof EE_Registration) { |
|
| 1328 | 1328 | continue; |
| 1329 | 1329 | } |
| 1330 | 1330 | $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] |
@@ -1343,12 +1343,12 @@ discard block |
||
| 1343 | 1343 | $this->_template_args['event_attendees'][$registration->ID()]['attendee'] |
| 1344 | 1344 | = $attendee->full_name(); |
| 1345 | 1345 | $this->_template_args['event_attendees'][$registration->ID()]['email'] |
| 1346 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1346 | + = '<a href="mailto:'.$attendee->email().'?subject='.$event_name |
|
| 1347 | 1347 | . esc_html__( |
| 1348 | 1348 | ' Event', |
| 1349 | 1349 | 'event_espresso' |
| 1350 | 1350 | ) |
| 1351 | - . '">' . $attendee->email() . '</a>'; |
|
| 1351 | + . '">'.$attendee->email().'</a>'; |
|
| 1352 | 1352 | $this->_template_args['event_attendees'][$registration->ID()]['address'] |
| 1353 | 1353 | = EEH_Address::format($attendee, 'inline', false, false); |
| 1354 | 1354 | } else { |
@@ -1372,7 +1372,7 @@ discard block |
||
| 1372 | 1372 | TXN_ADMIN_URL |
| 1373 | 1373 | ); |
| 1374 | 1374 | echo EEH_Template::display_template( |
| 1375 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1375 | + TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1376 | 1376 | $this->_template_args, |
| 1377 | 1377 | true |
| 1378 | 1378 | ); |
@@ -1407,12 +1407,12 @@ discard block |
||
| 1407 | 1407 | $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
| 1408 | 1408 | ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
| 1409 | 1409 | : null; |
| 1410 | - if (! $primary_att instanceof EE_Attendee) { |
|
| 1410 | + if ( ! $primary_att instanceof EE_Attendee) { |
|
| 1411 | 1411 | $this->_template_args['no_attendee_message'] = esc_html__( |
| 1412 | 1412 | 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
| 1413 | 1413 | 'event_espresso' |
| 1414 | 1414 | ); |
| 1415 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1415 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1416 | 1416 | } |
| 1417 | 1417 | $this->_template_args['ATT_ID'] = $primary_att->ID(); |
| 1418 | 1418 | $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
@@ -1426,7 +1426,7 @@ discard block |
||
| 1426 | 1426 | // get formatted address for registrant |
| 1427 | 1427 | $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
| 1428 | 1428 | echo EEH_Template::display_template( |
| 1429 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1429 | + TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1430 | 1430 | $this->_template_args, |
| 1431 | 1431 | true |
| 1432 | 1432 | ); |
@@ -1451,8 +1451,8 @@ discard block |
||
| 1451 | 1451 | TXN_ADMIN_URL |
| 1452 | 1452 | ); |
| 1453 | 1453 | |
| 1454 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1455 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1454 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1455 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); /**/ |
|
| 1456 | 1456 | } |
| 1457 | 1457 | |
| 1458 | 1458 | |
@@ -1477,7 +1477,7 @@ discard block |
||
| 1477 | 1477 | 'ee_edit_payments', |
| 1478 | 1478 | 'apply_payment_or_refund_from_registration_details' |
| 1479 | 1479 | ); |
| 1480 | - if (! empty($valid_data) && $has_access) { |
|
| 1480 | + if ( ! empty($valid_data) && $has_access) { |
|
| 1481 | 1481 | $PAY_ID = $valid_data['PAY_ID']; |
| 1482 | 1482 | //save the new payment |
| 1483 | 1483 | $payment = $this->_create_payment_from_request_data($valid_data); |
@@ -1490,7 +1490,7 @@ discard block |
||
| 1490 | 1490 | $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
| 1491 | 1491 | $this->_remove_existing_registration_payments($payment, $PAY_ID); |
| 1492 | 1492 | // apply payment to registrations (if applicable) |
| 1493 | - if (! empty($REG_IDs)) { |
|
| 1493 | + if ( ! empty($REG_IDs)) { |
|
| 1494 | 1494 | $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
| 1495 | 1495 | $this->_maybe_send_notifications(); |
| 1496 | 1496 | // now process status changes for the same registrations |
@@ -1538,7 +1538,7 @@ discard block |
||
| 1538 | 1538 | ); |
| 1539 | 1539 | } |
| 1540 | 1540 | } |
| 1541 | - $notices = EE_Error::get_notices( |
|
| 1541 | + $notices = EE_Error::get_notices( |
|
| 1542 | 1542 | false, |
| 1543 | 1543 | false, |
| 1544 | 1544 | false |
@@ -1559,14 +1559,14 @@ discard block |
||
| 1559 | 1559 | */ |
| 1560 | 1560 | protected function _validate_payment_request_data() |
| 1561 | 1561 | { |
| 1562 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1562 | + if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1563 | 1563 | return false; |
| 1564 | 1564 | } |
| 1565 | 1565 | $payment_form = $this->_generate_payment_form_section(); |
| 1566 | 1566 | try { |
| 1567 | 1567 | if ($payment_form->was_submitted()) { |
| 1568 | 1568 | $payment_form->receive_form_submission(); |
| 1569 | - if (! $payment_form->is_valid()) { |
|
| 1569 | + if ( ! $payment_form->is_valid()) { |
|
| 1570 | 1570 | $submission_error_messages = array(); |
| 1571 | 1571 | foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
| 1572 | 1572 | if ($validation_error instanceof EE_Validation_Error) { |
@@ -1744,7 +1744,7 @@ discard block |
||
| 1744 | 1744 | array('Y-m-d', 'g:i a') |
| 1745 | 1745 | ); |
| 1746 | 1746 | |
| 1747 | - if (! $payment->save()) { |
|
| 1747 | + if ( ! $payment->save()) { |
|
| 1748 | 1748 | EE_Error::add_error( |
| 1749 | 1749 | sprintf( |
| 1750 | 1750 | esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
@@ -1809,7 +1809,7 @@ discard block |
||
| 1809 | 1809 | $REG_IDs = array(); |
| 1810 | 1810 | // grab array of IDs for specific registrations to apply changes to |
| 1811 | 1811 | if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
| 1812 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1812 | + $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1813 | 1813 | } |
| 1814 | 1814 | //nothing specified ? then get all reg IDs |
| 1815 | 1815 | if (empty($REG_IDs)) { |
@@ -1937,12 +1937,12 @@ discard block |
||
| 1937 | 1937 | // but add in some conditions regarding payment, |
| 1938 | 1938 | // so that we don't apply payments to registrations that are free or have already been paid for |
| 1939 | 1939 | // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
| 1940 | - if (! $payment->is_a_refund()) { |
|
| 1940 | + if ( ! $payment->is_a_refund()) { |
|
| 1941 | 1941 | $registration_query_where_params['REG_final_price'] = array('!=', 0); |
| 1942 | 1942 | $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
| 1943 | 1943 | } |
| 1944 | 1944 | $registrations = $transaction->registrations(array($registration_query_where_params)); |
| 1945 | - if (! empty($registrations)) { |
|
| 1945 | + if ( ! empty($registrations)) { |
|
| 1946 | 1946 | /** @type EE_Payment_Processor $payment_processor */ |
| 1947 | 1947 | $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
| 1948 | 1948 | $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
@@ -2142,7 +2142,7 @@ discard block |
||
| 2142 | 2142 | { |
| 2143 | 2143 | $registration_payment_data = array(); |
| 2144 | 2144 | //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
| 2145 | - if (! empty($REG_IDs)) { |
|
| 2145 | + if ( ! empty($REG_IDs)) { |
|
| 2146 | 2146 | $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
| 2147 | 2147 | foreach ($registrations as $registration) { |
| 2148 | 2148 | if ($registration instanceof EE_Registration) { |
@@ -2255,13 +2255,13 @@ discard block |
||
| 2255 | 2255 | 'm/d/Y', |
| 2256 | 2256 | strtotime('-10 year') |
| 2257 | 2257 | ); |
| 2258 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2258 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2259 | 2259 | ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
| 2260 | 2260 | : date('m/d/Y'); |
| 2261 | 2261 | |
| 2262 | 2262 | //make sure our timestamps start and end right at the boundaries for each day |
| 2263 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2264 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2263 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
| 2264 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
| 2265 | 2265 | |
| 2266 | 2266 | |
| 2267 | 2267 | //convert to timestamps |
@@ -2278,7 +2278,7 @@ discard block |
||
| 2278 | 2278 | date('Y-m-d H:i:s', $start_date), |
| 2279 | 2279 | 'Y-m-d H:i:s' |
| 2280 | 2280 | ); |
| 2281 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2281 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2282 | 2282 | 'TXN_timestamp', |
| 2283 | 2283 | date('Y-m-d H:i:s', $end_date), |
| 2284 | 2284 | 'Y-m-d H:i:s' |
@@ -2320,7 +2320,7 @@ discard block |
||
| 2320 | 2320 | } |
| 2321 | 2321 | |
| 2322 | 2322 | if (isset($this->_req_data['s'])) { |
| 2323 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2323 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 2324 | 2324 | $_where['OR'] = array( |
| 2325 | 2325 | 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
| 2326 | 2326 | 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
@@ -2347,9 +2347,9 @@ discard block |
||
| 2347 | 2347 | } |
| 2348 | 2348 | |
| 2349 | 2349 | //failed transactions |
| 2350 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2350 | + $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2351 | 2351 | || ($count && $view === 'failed'); |
| 2352 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2352 | + $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2353 | 2353 | || ($count && $view === 'abandoned'); |
| 2354 | 2354 | |
| 2355 | 2355 | if ($failed) { |
@@ -16,2370 +16,2370 @@ |
||
| 16 | 16 | class Transactions_Admin_Page extends EE_Admin_Page |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var EE_Transaction |
|
| 21 | - */ |
|
| 22 | - private $_transaction; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @var EE_Session |
|
| 26 | - */ |
|
| 27 | - private $_session; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var array $_txn_status |
|
| 31 | - */ |
|
| 32 | - private static $_txn_status; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var array $_pay_status |
|
| 36 | - */ |
|
| 37 | - private static $_pay_status; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var array $_existing_reg_payment_REG_IDs |
|
| 41 | - */ |
|
| 42 | - protected $_existing_reg_payment_REG_IDs = null; |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @Constructor |
|
| 47 | - * @access public |
|
| 48 | - * @param bool $routing |
|
| 49 | - * @throws EE_Error |
|
| 50 | - * @throws InvalidArgumentException |
|
| 51 | - * @throws ReflectionException |
|
| 52 | - * @throws InvalidDataTypeException |
|
| 53 | - * @throws InvalidInterfaceException |
|
| 54 | - */ |
|
| 55 | - public function __construct($routing = true) |
|
| 56 | - { |
|
| 57 | - parent::__construct($routing); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * _init_page_props |
|
| 63 | - * |
|
| 64 | - * @return void |
|
| 65 | - */ |
|
| 66 | - protected function _init_page_props() |
|
| 67 | - { |
|
| 68 | - $this->page_slug = TXN_PG_SLUG; |
|
| 69 | - $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 70 | - $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 71 | - $this->_admin_base_path = TXN_ADMIN; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * _ajax_hooks |
|
| 77 | - * |
|
| 78 | - * @return void |
|
| 79 | - */ |
|
| 80 | - protected function _ajax_hooks() |
|
| 81 | - { |
|
| 82 | - add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 83 | - add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 84 | - add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * _define_page_props |
|
| 90 | - * |
|
| 91 | - * @return void |
|
| 92 | - */ |
|
| 93 | - protected function _define_page_props() |
|
| 94 | - { |
|
| 95 | - $this->_admin_page_title = $this->page_label; |
|
| 96 | - $this->_labels = array( |
|
| 97 | - 'buttons' => array( |
|
| 98 | - 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 99 | - 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 100 | - 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 101 | - ), |
|
| 102 | - ); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * grab url requests and route them |
|
| 108 | - * |
|
| 109 | - * @access private |
|
| 110 | - * @return void |
|
| 111 | - * @throws EE_Error |
|
| 112 | - * @throws InvalidArgumentException |
|
| 113 | - * @throws InvalidDataTypeException |
|
| 114 | - * @throws InvalidInterfaceException |
|
| 115 | - */ |
|
| 116 | - public function _set_page_routes() |
|
| 117 | - { |
|
| 118 | - |
|
| 119 | - $this->_set_transaction_status_array(); |
|
| 120 | - |
|
| 121 | - $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
| 122 | - && ! is_array($this->_req_data['TXN_ID']) |
|
| 123 | - ? $this->_req_data['TXN_ID'] |
|
| 124 | - : 0; |
|
| 125 | - |
|
| 126 | - $this->_page_routes = array( |
|
| 127 | - |
|
| 128 | - 'default' => array( |
|
| 129 | - 'func' => '_transactions_overview_list_table', |
|
| 130 | - 'capability' => 'ee_read_transactions', |
|
| 131 | - ), |
|
| 132 | - |
|
| 133 | - 'view_transaction' => array( |
|
| 134 | - 'func' => '_transaction_details', |
|
| 135 | - 'capability' => 'ee_read_transaction', |
|
| 136 | - 'obj_id' => $txn_id, |
|
| 137 | - ), |
|
| 138 | - |
|
| 139 | - 'send_payment_reminder' => array( |
|
| 140 | - 'func' => '_send_payment_reminder', |
|
| 141 | - 'noheader' => true, |
|
| 142 | - 'capability' => 'ee_send_message', |
|
| 143 | - ), |
|
| 144 | - |
|
| 145 | - 'espresso_apply_payment' => array( |
|
| 146 | - 'func' => 'apply_payments_or_refunds', |
|
| 147 | - 'noheader' => true, |
|
| 148 | - 'capability' => 'ee_edit_payments', |
|
| 149 | - ), |
|
| 150 | - |
|
| 151 | - 'espresso_apply_refund' => array( |
|
| 152 | - 'func' => 'apply_payments_or_refunds', |
|
| 153 | - 'noheader' => true, |
|
| 154 | - 'capability' => 'ee_edit_payments', |
|
| 155 | - ), |
|
| 156 | - |
|
| 157 | - 'espresso_delete_payment' => array( |
|
| 158 | - 'func' => 'delete_payment', |
|
| 159 | - 'noheader' => true, |
|
| 160 | - 'capability' => 'ee_delete_payments', |
|
| 161 | - ), |
|
| 162 | - |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - protected function _set_page_config() |
|
| 168 | - { |
|
| 169 | - $this->_page_config = array( |
|
| 170 | - 'default' => array( |
|
| 171 | - 'nav' => array( |
|
| 172 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 173 | - 'order' => 10, |
|
| 174 | - ), |
|
| 175 | - 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 176 | - 'help_tabs' => array( |
|
| 177 | - 'transactions_overview_help_tab' => array( |
|
| 178 | - 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 179 | - 'filename' => 'transactions_overview', |
|
| 180 | - ), |
|
| 181 | - 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 182 | - 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 183 | - 'filename' => 'transactions_overview_table_column_headings', |
|
| 184 | - ), |
|
| 185 | - 'transactions_overview_views_filters_help_tab' => array( |
|
| 186 | - 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 187 | - 'filename' => 'transactions_overview_views_filters_search', |
|
| 188 | - ), |
|
| 189 | - ), |
|
| 190 | - 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 191 | - /** |
|
| 192 | - * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 193 | - * may change in a later iteration so want to keep the code for then. |
|
| 194 | - */ |
|
| 195 | - //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 196 | - 'require_nonce' => false, |
|
| 197 | - ), |
|
| 198 | - 'view_transaction' => array( |
|
| 199 | - 'nav' => array( |
|
| 200 | - 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 201 | - 'order' => 5, |
|
| 202 | - 'url' => isset($this->_req_data['TXN_ID']) |
|
| 203 | - ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
| 204 | - : $this->_admin_base_url, |
|
| 205 | - 'persistent' => false, |
|
| 206 | - ), |
|
| 207 | - 'help_tabs' => array( |
|
| 208 | - 'transactions_view_transaction_help_tab' => array( |
|
| 209 | - 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 210 | - 'filename' => 'transactions_view_transaction', |
|
| 211 | - ), |
|
| 212 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 213 | - 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 214 | - 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
| 215 | - ), |
|
| 216 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 217 | - 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 218 | - 'filename' => 'transactions_view_transaction_attendees_registered', |
|
| 219 | - ), |
|
| 220 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 221 | - 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 222 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
| 223 | - ), |
|
| 224 | - ), |
|
| 225 | - 'qtips' => array('Transaction_Details_Tips'), |
|
| 226 | - 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 227 | - 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 228 | - |
|
| 229 | - 'require_nonce' => false, |
|
| 230 | - ), |
|
| 231 | - ); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * The below methods aren't used by this class currently |
|
| 237 | - */ |
|
| 238 | - protected function _add_screen_options() |
|
| 239 | - { |
|
| 240 | - //noop |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - protected function _add_feature_pointers() |
|
| 244 | - { |
|
| 245 | - //noop |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - public function admin_init() |
|
| 249 | - { |
|
| 250 | - // IF a registration was JUST added via the admin... |
|
| 251 | - if (isset( |
|
| 252 | - $this->_req_data['redirect_from'], |
|
| 253 | - $this->_req_data['EVT_ID'], |
|
| 254 | - $this->_req_data['event_name'] |
|
| 255 | - )) { |
|
| 256 | - // then set a cookie so that we can block any attempts to use |
|
| 257 | - // the back button as a way to enter another registration. |
|
| 258 | - setcookie( |
|
| 259 | - 'ee_registration_added', |
|
| 260 | - $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/' |
|
| 261 | - ); |
|
| 262 | - // and update the global |
|
| 263 | - $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 264 | - } |
|
| 265 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
| 266 | - '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.', |
|
| 267 | - 'event_espresso' |
|
| 268 | - ); |
|
| 269 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 270 | - 'An error occurred! Please refresh the page and try again.', |
|
| 271 | - 'event_espresso' |
|
| 272 | - ); |
|
| 273 | - EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 274 | - EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 275 | - EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 276 | - EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
| 277 | - 'This transaction has been overpaid ! Payments Total', |
|
| 278 | - 'event_espresso' |
|
| 279 | - ); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - public function admin_notices() |
|
| 283 | - { |
|
| 284 | - //noop |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - public function admin_footer_scripts() |
|
| 288 | - { |
|
| 289 | - //noop |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * _set_transaction_status_array |
|
| 295 | - * sets list of transaction statuses |
|
| 296 | - * |
|
| 297 | - * @access private |
|
| 298 | - * @return void |
|
| 299 | - * @throws EE_Error |
|
| 300 | - * @throws InvalidArgumentException |
|
| 301 | - * @throws InvalidDataTypeException |
|
| 302 | - * @throws InvalidInterfaceException |
|
| 303 | - */ |
|
| 304 | - private function _set_transaction_status_array() |
|
| 305 | - { |
|
| 306 | - self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * get_transaction_status_array |
|
| 312 | - * return the transaction status array for wp_list_table |
|
| 313 | - * |
|
| 314 | - * @access public |
|
| 315 | - * @return array |
|
| 316 | - */ |
|
| 317 | - public function get_transaction_status_array() |
|
| 318 | - { |
|
| 319 | - return self::$_txn_status; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - /** |
|
| 324 | - * get list of payment statuses |
|
| 325 | - * |
|
| 326 | - * @access private |
|
| 327 | - * @return void |
|
| 328 | - * @throws EE_Error |
|
| 329 | - * @throws InvalidArgumentException |
|
| 330 | - * @throws InvalidDataTypeException |
|
| 331 | - * @throws InvalidInterfaceException |
|
| 332 | - */ |
|
| 333 | - private function _get_payment_status_array() |
|
| 334 | - { |
|
| 335 | - self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 336 | - $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 337 | - |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * _add_screen_options_default |
|
| 343 | - * |
|
| 344 | - * @access protected |
|
| 345 | - * @return void |
|
| 346 | - * @throws InvalidArgumentException |
|
| 347 | - * @throws InvalidDataTypeException |
|
| 348 | - * @throws InvalidInterfaceException |
|
| 349 | - */ |
|
| 350 | - protected function _add_screen_options_default() |
|
| 351 | - { |
|
| 352 | - $this->_per_page_screen_option(); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * load_scripts_styles |
|
| 358 | - * |
|
| 359 | - * @access public |
|
| 360 | - * @return void |
|
| 361 | - */ |
|
| 362 | - public function load_scripts_styles() |
|
| 363 | - { |
|
| 364 | - //enqueue style |
|
| 365 | - wp_register_style( |
|
| 366 | - 'espresso_txn', |
|
| 367 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 368 | - array(), |
|
| 369 | - EVENT_ESPRESSO_VERSION |
|
| 370 | - ); |
|
| 371 | - wp_enqueue_style('espresso_txn'); |
|
| 372 | - //scripts |
|
| 373 | - wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 374 | - 'ee_admin_js', |
|
| 375 | - 'ee-datepicker', |
|
| 376 | - 'jquery-ui-datepicker', |
|
| 377 | - 'jquery-ui-draggable', |
|
| 378 | - 'ee-dialog', |
|
| 379 | - 'ee-accounting', |
|
| 380 | - 'ee-serialize-full-array', |
|
| 381 | - ), EVENT_ESPRESSO_VERSION, true); |
|
| 382 | - wp_enqueue_script('espresso_txn'); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * load_scripts_styles_view_transaction |
|
| 388 | - * |
|
| 389 | - * @access public |
|
| 390 | - * @return void |
|
| 391 | - */ |
|
| 392 | - public function load_scripts_styles_view_transaction() |
|
| 393 | - { |
|
| 394 | - //styles |
|
| 395 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - |
|
| 399 | - /** |
|
| 400 | - * load_scripts_styles_default |
|
| 401 | - * |
|
| 402 | - * @access public |
|
| 403 | - * @return void |
|
| 404 | - */ |
|
| 405 | - public function load_scripts_styles_default() |
|
| 406 | - { |
|
| 407 | - //styles |
|
| 408 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * _set_list_table_views_default |
|
| 414 | - * |
|
| 415 | - * @access protected |
|
| 416 | - * @return void |
|
| 417 | - */ |
|
| 418 | - protected function _set_list_table_views_default() |
|
| 419 | - { |
|
| 420 | - $this->_views = array( |
|
| 421 | - 'all' => array( |
|
| 422 | - 'slug' => 'all', |
|
| 423 | - 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 424 | - 'count' => 0, |
|
| 425 | - ), |
|
| 426 | - 'abandoned' => array( |
|
| 427 | - 'slug' => 'abandoned', |
|
| 428 | - 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 429 | - 'count' => 0, |
|
| 430 | - ), |
|
| 431 | - 'failed' => array( |
|
| 432 | - 'slug' => 'failed', |
|
| 433 | - 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 434 | - 'count' => 0, |
|
| 435 | - ), |
|
| 436 | - ); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * _set_transaction_object |
|
| 442 | - * This sets the _transaction property for the transaction details screen |
|
| 443 | - * |
|
| 444 | - * @access private |
|
| 445 | - * @return void |
|
| 446 | - * @throws EE_Error |
|
| 447 | - * @throws InvalidArgumentException |
|
| 448 | - * @throws RuntimeException |
|
| 449 | - * @throws InvalidDataTypeException |
|
| 450 | - * @throws InvalidInterfaceException |
|
| 451 | - */ |
|
| 452 | - private function _set_transaction_object() |
|
| 453 | - { |
|
| 454 | - if ($this->_transaction instanceof EE_Transaction) { |
|
| 455 | - return; |
|
| 456 | - } //get out we've already set the object |
|
| 457 | - |
|
| 458 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
| 459 | - ? absint($this->_req_data['TXN_ID']) |
|
| 460 | - : false; |
|
| 461 | - |
|
| 462 | - //get transaction object |
|
| 463 | - $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 464 | - $this->_session = $this->_transaction instanceof EE_Transaction |
|
| 465 | - ? $this->_transaction->get('TXN_session_data') |
|
| 466 | - : null; |
|
| 467 | - $this->_transaction->verify_abandoned_transaction_status(); |
|
| 468 | - |
|
| 469 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 470 | - $error_msg = sprintf( |
|
| 471 | - esc_html__( |
|
| 472 | - 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
| 473 | - 'event_espresso' |
|
| 474 | - ), |
|
| 475 | - $TXN_ID |
|
| 476 | - ); |
|
| 477 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * _transaction_legend_items |
|
| 484 | - * |
|
| 485 | - * @access protected |
|
| 486 | - * @return array |
|
| 487 | - * @throws EE_Error |
|
| 488 | - * @throws InvalidArgumentException |
|
| 489 | - * @throws ReflectionException |
|
| 490 | - * @throws InvalidDataTypeException |
|
| 491 | - * @throws InvalidInterfaceException |
|
| 492 | - */ |
|
| 493 | - protected function _transaction_legend_items() |
|
| 494 | - { |
|
| 495 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 496 | - $items = array(); |
|
| 497 | - |
|
| 498 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 499 | - 'ee_read_global_messages', |
|
| 500 | - 'view_filtered_messages' |
|
| 501 | - )) { |
|
| 502 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 503 | - if (is_array($related_for_icon) |
|
| 504 | - && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
| 505 | - ) { |
|
| 506 | - $items['view_related_messages'] = array( |
|
| 507 | - 'class' => $related_for_icon['css_class'], |
|
| 508 | - 'desc' => $related_for_icon['label'], |
|
| 509 | - ); |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - $items = apply_filters( |
|
| 514 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 515 | - array_merge( |
|
| 516 | - $items, |
|
| 517 | - array( |
|
| 518 | - 'view_details' => array( |
|
| 519 | - 'class' => 'dashicons dashicons-cart', |
|
| 520 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 521 | - ), |
|
| 522 | - 'view_invoice' => array( |
|
| 523 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 524 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 525 | - ), |
|
| 526 | - 'view_receipt' => array( |
|
| 527 | - 'class' => 'dashicons dashicons-media-default', |
|
| 528 | - 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
| 529 | - ), |
|
| 530 | - 'view_registration' => array( |
|
| 531 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 532 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 533 | - ), |
|
| 534 | - 'payment_overview_link' => array( |
|
| 535 | - 'class' => 'dashicons dashicons-money', |
|
| 536 | - 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
| 537 | - ), |
|
| 538 | - ) |
|
| 539 | - ) |
|
| 540 | - ); |
|
| 541 | - |
|
| 542 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 543 | - 'ee_send_message', |
|
| 544 | - 'espresso_transactions_send_payment_reminder' |
|
| 545 | - )) { |
|
| 546 | - if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
| 547 | - $items['send_payment_reminder'] = array( |
|
| 548 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 549 | - 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
| 550 | - ); |
|
| 551 | - } else { |
|
| 552 | - $items['blank*'] = array( |
|
| 553 | - 'class' => '', |
|
| 554 | - 'desc' => '', |
|
| 555 | - ); |
|
| 556 | - } |
|
| 557 | - } else { |
|
| 558 | - $items['blank*'] = array( |
|
| 559 | - 'class' => '', |
|
| 560 | - 'desc' => '', |
|
| 561 | - ); |
|
| 562 | - } |
|
| 563 | - $more_items = apply_filters( |
|
| 564 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 565 | - array( |
|
| 566 | - 'overpaid' => array( |
|
| 567 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 568 | - 'desc' => EEH_Template::pretty_status( |
|
| 569 | - EEM_Transaction::overpaid_status_code, |
|
| 570 | - false, |
|
| 571 | - 'sentence' |
|
| 572 | - ), |
|
| 573 | - ), |
|
| 574 | - 'complete' => array( |
|
| 575 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 576 | - 'desc' => EEH_Template::pretty_status( |
|
| 577 | - EEM_Transaction::complete_status_code, |
|
| 578 | - false, |
|
| 579 | - 'sentence' |
|
| 580 | - ), |
|
| 581 | - ), |
|
| 582 | - 'incomplete' => array( |
|
| 583 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 584 | - 'desc' => EEH_Template::pretty_status( |
|
| 585 | - EEM_Transaction::incomplete_status_code, |
|
| 586 | - false, |
|
| 587 | - 'sentence' |
|
| 588 | - ), |
|
| 589 | - ), |
|
| 590 | - 'abandoned' => array( |
|
| 591 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 592 | - 'desc' => EEH_Template::pretty_status( |
|
| 593 | - EEM_Transaction::abandoned_status_code, |
|
| 594 | - false, |
|
| 595 | - 'sentence' |
|
| 596 | - ), |
|
| 597 | - ), |
|
| 598 | - 'failed' => array( |
|
| 599 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 600 | - 'desc' => EEH_Template::pretty_status( |
|
| 601 | - EEM_Transaction::failed_status_code, |
|
| 602 | - false, |
|
| 603 | - 'sentence' |
|
| 604 | - ), |
|
| 605 | - ), |
|
| 606 | - ) |
|
| 607 | - ); |
|
| 608 | - |
|
| 609 | - return array_merge($items, $more_items); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - |
|
| 613 | - /** |
|
| 614 | - * _transactions_overview_list_table |
|
| 615 | - * |
|
| 616 | - * @access protected |
|
| 617 | - * @return void |
|
| 618 | - * @throws DomainException |
|
| 619 | - * @throws EE_Error |
|
| 620 | - * @throws InvalidArgumentException |
|
| 621 | - * @throws InvalidDataTypeException |
|
| 622 | - * @throws InvalidInterfaceException |
|
| 623 | - * @throws ReflectionException |
|
| 624 | - */ |
|
| 625 | - protected function _transactions_overview_list_table() |
|
| 626 | - { |
|
| 627 | - $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 628 | - $event = isset($this->_req_data['EVT_ID']) |
|
| 629 | - ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
| 630 | - : null; |
|
| 631 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
| 632 | - ? sprintf( |
|
| 633 | - esc_html__( |
|
| 634 | - '%sViewing Transactions for the Event: %s%s', |
|
| 635 | - 'event_espresso' |
|
| 636 | - ), |
|
| 637 | - '<h3>', |
|
| 638 | - '<a href="' |
|
| 639 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
| 640 | - array('action' => 'edit', 'post' => $event->ID()), |
|
| 641 | - EVENTS_ADMIN_URL |
|
| 642 | - ) |
|
| 643 | - . '" title="' |
|
| 644 | - . esc_attr__( |
|
| 645 | - 'Click to Edit event', |
|
| 646 | - 'event_espresso' |
|
| 647 | - ) |
|
| 648 | - . '">' . $event->get('EVT_name') . '</a>', |
|
| 649 | - '</h3>' |
|
| 650 | - ) |
|
| 651 | - : ''; |
|
| 652 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 653 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * _transaction_details |
|
| 659 | - * generates HTML for the View Transaction Details Admin page |
|
| 660 | - * |
|
| 661 | - * @access protected |
|
| 662 | - * @return void |
|
| 663 | - * @throws DomainException |
|
| 664 | - * @throws EE_Error |
|
| 665 | - * @throws InvalidArgumentException |
|
| 666 | - * @throws InvalidDataTypeException |
|
| 667 | - * @throws InvalidInterfaceException |
|
| 668 | - * @throws RuntimeException |
|
| 669 | - */ |
|
| 670 | - protected function _transaction_details() |
|
| 671 | - { |
|
| 672 | - do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 673 | - |
|
| 674 | - $this->_set_transaction_status_array(); |
|
| 675 | - |
|
| 676 | - $this->_template_args = array(); |
|
| 677 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 678 | - |
|
| 679 | - $this->_set_transaction_object(); |
|
| 680 | - |
|
| 681 | - $primary_registration = $this->_transaction->primary_registration(); |
|
| 682 | - $attendee = $primary_registration instanceof EE_Registration |
|
| 683 | - ? $primary_registration->attendee() |
|
| 684 | - : null; |
|
| 685 | - |
|
| 686 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 687 | - $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 688 | - |
|
| 689 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 690 | - $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 691 | - |
|
| 692 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
| 693 | - $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 694 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 695 | - |
|
| 696 | - $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
| 697 | - $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
| 698 | - |
|
| 699 | - if ($attendee instanceof EE_Attendee |
|
| 700 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 701 | - 'ee_send_message', |
|
| 702 | - 'espresso_transactions_send_payment_reminder' |
|
| 703 | - ) |
|
| 704 | - ) { |
|
| 705 | - $this->_template_args['send_payment_reminder_button'] = |
|
| 706 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 707 | - && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code |
|
| 708 | - && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code |
|
| 709 | - ? EEH_Template::get_button_or_link( |
|
| 710 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 711 | - array( |
|
| 712 | - 'action' => 'send_payment_reminder', |
|
| 713 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 714 | - 'redirect_to' => 'view_transaction', |
|
| 715 | - ), |
|
| 716 | - TXN_ADMIN_URL |
|
| 717 | - ), |
|
| 718 | - __(' Send Payment Reminder', 'event_espresso'), |
|
| 719 | - 'button secondary-button right', |
|
| 720 | - 'dashicons dashicons-email-alt' |
|
| 721 | - ) |
|
| 722 | - : ''; |
|
| 723 | - } else { |
|
| 724 | - $this->_template_args['send_payment_reminder_button'] = ''; |
|
| 725 | - } |
|
| 726 | - |
|
| 727 | - $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
| 728 | - $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
| 729 | - $amount_due, |
|
| 730 | - true |
|
| 731 | - ); |
|
| 732 | - if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 733 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
| 734 | - . $this->_template_args['amount_due']; |
|
| 735 | - } else { |
|
| 736 | - $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
| 737 | - } |
|
| 738 | - $this->_template_args['amount_due_class'] = ''; |
|
| 739 | - |
|
| 740 | - if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
| 741 | - // paid in full |
|
| 742 | - $this->_template_args['amount_due'] = false; |
|
| 743 | - } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
| 744 | - // overpaid |
|
| 745 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 746 | - } elseif ($this->_transaction->get('TXN_total') > 0 |
|
| 747 | - && $this->_transaction->get('TXN_paid') > 0 |
|
| 748 | - ) { |
|
| 749 | - // monies owing |
|
| 750 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 751 | - } elseif ($this->_transaction->get('TXN_total') > 0 |
|
| 752 | - && $this->_transaction->get('TXN_paid') == 0 |
|
| 753 | - ) { |
|
| 754 | - // no payments made yet |
|
| 755 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 756 | - } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
| 757 | - // free event |
|
| 758 | - $this->_template_args['amount_due'] = false; |
|
| 759 | - } |
|
| 760 | - |
|
| 761 | - $payment_method = $this->_transaction->payment_method(); |
|
| 762 | - |
|
| 763 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 764 | - ? $payment_method->admin_name() |
|
| 765 | - : esc_html__('Unknown', 'event_espresso'); |
|
| 766 | - |
|
| 767 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 768 | - // link back to overview |
|
| 769 | - $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
| 770 | - ? $_SERVER['HTTP_REFERER'] |
|
| 771 | - : TXN_ADMIN_URL; |
|
| 772 | - |
|
| 773 | - |
|
| 774 | - // next link |
|
| 775 | - $next_txn = $this->_transaction->next( |
|
| 776 | - null, |
|
| 777 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 778 | - 'TXN_ID' |
|
| 779 | - ); |
|
| 780 | - $this->_template_args['next_transaction'] = $next_txn |
|
| 781 | - ? $this->_next_link( |
|
| 782 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 783 | - array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 784 | - TXN_ADMIN_URL |
|
| 785 | - ), |
|
| 786 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 787 | - ) |
|
| 788 | - : ''; |
|
| 789 | - // previous link |
|
| 790 | - $previous_txn = $this->_transaction->previous( |
|
| 791 | - null, |
|
| 792 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 793 | - 'TXN_ID' |
|
| 794 | - ); |
|
| 795 | - $this->_template_args['previous_transaction'] = $previous_txn |
|
| 796 | - ? $this->_previous_link( |
|
| 797 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 798 | - array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 799 | - TXN_ADMIN_URL |
|
| 800 | - ), |
|
| 801 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 802 | - ) |
|
| 803 | - : ''; |
|
| 804 | - |
|
| 805 | - // were we just redirected here after adding a new registration ??? |
|
| 806 | - if (isset( |
|
| 807 | - $this->_req_data['redirect_from'], |
|
| 808 | - $this->_req_data['EVT_ID'], |
|
| 809 | - $this->_req_data['event_name'] |
|
| 810 | - )) { |
|
| 811 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 812 | - 'ee_edit_registrations', |
|
| 813 | - 'espresso_registrations_new_registration', |
|
| 814 | - $this->_req_data['EVT_ID'] |
|
| 815 | - )) { |
|
| 816 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 817 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 818 | - array( |
|
| 819 | - 'page' => 'espresso_registrations', |
|
| 820 | - 'action' => 'new_registration', |
|
| 821 | - 'return' => 'default', |
|
| 822 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 823 | - 'event_id' => $this->_req_data['EVT_ID'], |
|
| 824 | - ), |
|
| 825 | - REG_ADMIN_URL |
|
| 826 | - ); |
|
| 827 | - $this->_admin_page_title .= '">'; |
|
| 828 | - |
|
| 829 | - $this->_admin_page_title .= sprintf( |
|
| 830 | - esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 831 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 832 | - ); |
|
| 833 | - $this->_admin_page_title .= '</a>'; |
|
| 834 | - } |
|
| 835 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 836 | - } |
|
| 837 | - // grab messages at the last second |
|
| 838 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 839 | - // path to template |
|
| 840 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 841 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 842 | - $template_path, |
|
| 843 | - $this->_template_args, |
|
| 844 | - true |
|
| 845 | - ); |
|
| 846 | - |
|
| 847 | - // the details template wrapper |
|
| 848 | - $this->display_admin_page_with_sidebar(); |
|
| 849 | - |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * _transaction_details_metaboxes |
|
| 855 | - * |
|
| 856 | - * @access protected |
|
| 857 | - * @return void |
|
| 858 | - * @throws EE_Error |
|
| 859 | - * @throws InvalidArgumentException |
|
| 860 | - * @throws InvalidDataTypeException |
|
| 861 | - * @throws InvalidInterfaceException |
|
| 862 | - * @throws RuntimeException |
|
| 863 | - */ |
|
| 864 | - protected function _transaction_details_metaboxes() |
|
| 865 | - { |
|
| 866 | - |
|
| 867 | - $this->_set_transaction_object(); |
|
| 868 | - |
|
| 869 | - add_meta_box( |
|
| 870 | - 'edit-txn-details-mbox', |
|
| 871 | - esc_html__('Transaction Details', 'event_espresso'), |
|
| 872 | - array($this, 'txn_details_meta_box'), |
|
| 873 | - $this->_wp_page_slug, |
|
| 874 | - 'normal', |
|
| 875 | - 'high' |
|
| 876 | - ); |
|
| 877 | - add_meta_box( |
|
| 878 | - 'edit-txn-attendees-mbox', |
|
| 879 | - esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 880 | - array($this, 'txn_attendees_meta_box'), |
|
| 881 | - $this->_wp_page_slug, |
|
| 882 | - 'normal', |
|
| 883 | - 'high', |
|
| 884 | - array('TXN_ID' => $this->_transaction->ID()) |
|
| 885 | - ); |
|
| 886 | - add_meta_box( |
|
| 887 | - 'edit-txn-registrant-mbox', |
|
| 888 | - esc_html__('Primary Contact', 'event_espresso'), |
|
| 889 | - array($this, 'txn_registrant_side_meta_box'), |
|
| 890 | - $this->_wp_page_slug, |
|
| 891 | - 'side', |
|
| 892 | - 'high' |
|
| 893 | - ); |
|
| 894 | - add_meta_box( |
|
| 895 | - 'edit-txn-billing-info-mbox', |
|
| 896 | - esc_html__('Billing Information', 'event_espresso'), |
|
| 897 | - array($this, 'txn_billing_info_side_meta_box'), |
|
| 898 | - $this->_wp_page_slug, |
|
| 899 | - 'side', |
|
| 900 | - 'high' |
|
| 901 | - ); |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - |
|
| 905 | - /** |
|
| 906 | - * txn_details_meta_box |
|
| 907 | - * generates HTML for the Transaction main meta box |
|
| 908 | - * |
|
| 909 | - * @access public |
|
| 910 | - * @return void |
|
| 911 | - * @throws DomainException |
|
| 912 | - * @throws EE_Error |
|
| 913 | - * @throws InvalidArgumentException |
|
| 914 | - * @throws InvalidDataTypeException |
|
| 915 | - * @throws InvalidInterfaceException |
|
| 916 | - * @throws RuntimeException |
|
| 917 | - */ |
|
| 918 | - public function txn_details_meta_box() |
|
| 919 | - { |
|
| 920 | - |
|
| 921 | - $this->_set_transaction_object(); |
|
| 922 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 923 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 924 | - ? $this->_transaction->primary_registration()->attendee() |
|
| 925 | - : null; |
|
| 926 | - $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 927 | - 'ee_edit_payments', |
|
| 928 | - 'apply_payment_or_refund_from_registration_details' |
|
| 929 | - ); |
|
| 930 | - $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 931 | - 'ee_delete_payments', |
|
| 932 | - 'delete_payment_from_registration_details' |
|
| 933 | - ); |
|
| 934 | - |
|
| 935 | - //get line table |
|
| 936 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 937 | - $Line_Item_Display = new EE_Line_Item_Display( |
|
| 938 | - 'admin_table', |
|
| 939 | - 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
| 940 | - ); |
|
| 941 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
| 942 | - $this->_transaction->total_line_item() |
|
| 943 | - ); |
|
| 944 | - $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration') |
|
| 945 | - ->get('REG_code'); |
|
| 946 | - |
|
| 947 | - // process taxes |
|
| 948 | - $taxes = $this->_transaction->get_many_related( |
|
| 949 | - 'Line_Item', |
|
| 950 | - array(array('LIN_type' => EEM_Line_Item::type_tax)) |
|
| 951 | - ); |
|
| 952 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 953 | - |
|
| 954 | - $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 955 | - $this->_transaction->get('TXN_total'), |
|
| 956 | - false, |
|
| 957 | - false |
|
| 958 | - ); |
|
| 959 | - $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
| 960 | - $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
| 961 | - |
|
| 962 | - // process payment details |
|
| 963 | - $payments = $this->_transaction->get_many_related('Payment'); |
|
| 964 | - if (! empty($payments)) { |
|
| 965 | - $this->_template_args['payments'] = $payments; |
|
| 966 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 967 | - } else { |
|
| 968 | - $this->_template_args['payments'] = false; |
|
| 969 | - $this->_template_args['existing_reg_payments'] = array(); |
|
| 970 | - } |
|
| 971 | - |
|
| 972 | - $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 973 | - $this->_template_args['delete_payment_url'] = add_query_arg( |
|
| 974 | - array('action' => 'espresso_delete_payment'), |
|
| 975 | - TXN_ADMIN_URL |
|
| 976 | - ); |
|
| 977 | - |
|
| 978 | - if (isset($txn_details['invoice_number'])) { |
|
| 979 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 980 | - $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
| 981 | - 'Invoice Number', |
|
| 982 | - 'event_espresso' |
|
| 983 | - ); |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
| 987 | - ->get_first_related('Registration') |
|
| 988 | - ->get('REG_session'); |
|
| 989 | - $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
| 990 | - 'Registration Session', |
|
| 991 | - 'event_espresso' |
|
| 992 | - ); |
|
| 993 | - |
|
| 994 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
| 995 | - ? $this->_session['ip_address'] |
|
| 996 | - : ''; |
|
| 997 | - $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
| 998 | - 'Transaction placed from IP', |
|
| 999 | - 'event_espresso' |
|
| 1000 | - ); |
|
| 1001 | - |
|
| 1002 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
| 1003 | - ? $this->_session['user_agent'] |
|
| 1004 | - : ''; |
|
| 1005 | - $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
| 1006 | - 'Registrant User Agent', |
|
| 1007 | - 'event_espresso' |
|
| 1008 | - ); |
|
| 1009 | - |
|
| 1010 | - $reg_steps = '<ul>'; |
|
| 1011 | - foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 1012 | - if ($reg_step_status === true) { |
|
| 1013 | - $reg_steps .= '<li style="color:#70cc50">' |
|
| 1014 | - . sprintf( |
|
| 1015 | - esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 1016 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1017 | - ) |
|
| 1018 | - . '</li>'; |
|
| 1019 | - } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 1020 | - $reg_steps .= '<li style="color:#2EA2CC">' |
|
| 1021 | - . sprintf( |
|
| 1022 | - esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 1023 | - ucwords(str_replace('_', ' ', $reg_step)), |
|
| 1024 | - date( |
|
| 1025 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1026 | - ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
| 1027 | - ) |
|
| 1028 | - ) |
|
| 1029 | - . '</li>'; |
|
| 1030 | - } else { |
|
| 1031 | - $reg_steps .= '<li style="color:#E76700">' |
|
| 1032 | - . sprintf( |
|
| 1033 | - esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
| 1034 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1035 | - ) |
|
| 1036 | - . '</li>'; |
|
| 1037 | - } |
|
| 1038 | - } |
|
| 1039 | - $reg_steps .= '</ul>'; |
|
| 1040 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 1041 | - $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
| 1042 | - 'Registration Step Progress', |
|
| 1043 | - 'event_espresso' |
|
| 1044 | - ); |
|
| 1045 | - |
|
| 1046 | - |
|
| 1047 | - $this->_get_registrations_to_apply_payment_to(); |
|
| 1048 | - $this->_get_payment_methods($payments); |
|
| 1049 | - $this->_get_payment_status_array(); |
|
| 1050 | - $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
| 1051 | - |
|
| 1052 | - $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1053 | - 'action' => 'edit_transaction', |
|
| 1054 | - 'process' => 'transaction', |
|
| 1055 | - ), TXN_ADMIN_URL); |
|
| 1056 | - $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 1057 | - 'page' => 'espresso_transactions', |
|
| 1058 | - 'action' => 'espresso_apply_payment', |
|
| 1059 | - ), WP_AJAX_URL); |
|
| 1060 | - $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
| 1061 | - 'page' => 'espresso_transactions', |
|
| 1062 | - 'action' => 'espresso_delete_payment', |
|
| 1063 | - ), WP_AJAX_URL); |
|
| 1064 | - |
|
| 1065 | - // 'espresso_delete_payment_nonce' |
|
| 1066 | - |
|
| 1067 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1068 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - |
|
| 1072 | - /** |
|
| 1073 | - * _get_registration_payment_IDs |
|
| 1074 | - * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 1075 | - * |
|
| 1076 | - * @access protected |
|
| 1077 | - * @param EE_Payment[] $payments |
|
| 1078 | - * @return array |
|
| 1079 | - * @throws EE_Error |
|
| 1080 | - * @throws InvalidArgumentException |
|
| 1081 | - * @throws InvalidDataTypeException |
|
| 1082 | - * @throws InvalidInterfaceException |
|
| 1083 | - */ |
|
| 1084 | - protected function _get_registration_payment_IDs($payments = array()) |
|
| 1085 | - { |
|
| 1086 | - $existing_reg_payments = array(); |
|
| 1087 | - // get all reg payments for these payments |
|
| 1088 | - $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
| 1089 | - array( |
|
| 1090 | - 'PAY_ID' => array( |
|
| 1091 | - 'IN', |
|
| 1092 | - array_keys($payments), |
|
| 1093 | - ), |
|
| 1094 | - ), |
|
| 1095 | - )); |
|
| 1096 | - if (! empty($reg_payments)) { |
|
| 1097 | - foreach ($payments as $payment) { |
|
| 1098 | - if (! $payment instanceof EE_Payment) { |
|
| 1099 | - continue; |
|
| 1100 | - } elseif (! isset($existing_reg_payments[$payment->ID()])) { |
|
| 1101 | - $existing_reg_payments[$payment->ID()] = array(); |
|
| 1102 | - } |
|
| 1103 | - foreach ($reg_payments as $reg_payment) { |
|
| 1104 | - if ($reg_payment instanceof EE_Registration_Payment |
|
| 1105 | - && $reg_payment->payment_ID() === $payment->ID() |
|
| 1106 | - ) { |
|
| 1107 | - $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 1108 | - } |
|
| 1109 | - } |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - return $existing_reg_payments; |
|
| 1114 | - } |
|
| 1115 | - |
|
| 1116 | - |
|
| 1117 | - /** |
|
| 1118 | - * _get_registrations_to_apply_payment_to |
|
| 1119 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 1120 | - * which allows the admin to only apply the payment to the specific registrations |
|
| 1121 | - * |
|
| 1122 | - * @access protected |
|
| 1123 | - * @return void |
|
| 1124 | - * @throws \EE_Error |
|
| 1125 | - */ |
|
| 1126 | - protected function _get_registrations_to_apply_payment_to() |
|
| 1127 | - { |
|
| 1128 | - // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 1129 | - $query_params = array( |
|
| 1130 | - array( |
|
| 1131 | - 'STS_ID' => array( |
|
| 1132 | - 'IN', |
|
| 1133 | - array( |
|
| 1134 | - EEM_Registration::status_id_approved, |
|
| 1135 | - EEM_Registration::status_id_pending_payment, |
|
| 1136 | - EEM_Registration::status_id_not_approved, |
|
| 1137 | - ), |
|
| 1138 | - ), |
|
| 1139 | - ), |
|
| 1140 | - ); |
|
| 1141 | - $registrations_to_apply_payment_to = EEH_HTML::br() |
|
| 1142 | - . EEH_HTML::div( |
|
| 1143 | - '', |
|
| 1144 | - 'txn-admin-apply-payment-to-registrations-dv', |
|
| 1145 | - '', |
|
| 1146 | - 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 1147 | - ); |
|
| 1148 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1149 | - $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 1150 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 1151 | - EEH_HTML::tr( |
|
| 1152 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1153 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1154 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1155 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1156 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1157 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1158 | - EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 1159 | - ) |
|
| 1160 | - ); |
|
| 1161 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 1162 | - // get registrations for TXN |
|
| 1163 | - $registrations = $this->_transaction->registrations($query_params); |
|
| 1164 | - $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
| 1165 | - foreach ($registrations as $registration) { |
|
| 1166 | - if ($registration instanceof EE_Registration) { |
|
| 1167 | - $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 1168 | - ? $registration->attendee()->full_name() |
|
| 1169 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 1170 | - $owing = $registration->final_price() - $registration->paid(); |
|
| 1171 | - $taxable = $registration->ticket()->taxable() |
|
| 1172 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1173 | - : ''; |
|
| 1174 | - $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
| 1175 | - ? ' checked="checked"' |
|
| 1176 | - : ''; |
|
| 1177 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1178 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 1179 | - EEH_HTML::td($registration->ID()) . |
|
| 1180 | - EEH_HTML::td($attendee_name) . |
|
| 1181 | - EEH_HTML::td( |
|
| 1182 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1183 | - ) . |
|
| 1184 | - EEH_HTML::td($registration->event_name()) . |
|
| 1185 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1186 | - EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1187 | - EEH_HTML::td( |
|
| 1188 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 1189 | - . '" name="txn_admin_payment[registrations]"' |
|
| 1190 | - . $checked . $disabled . '>', |
|
| 1191 | - '', |
|
| 1192 | - 'jst-cntr' |
|
| 1193 | - ), |
|
| 1194 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1195 | - ); |
|
| 1196 | - } |
|
| 1197 | - } |
|
| 1198 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1199 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1200 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1201 | - $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1202 | - esc_html__( |
|
| 1203 | - '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.', |
|
| 1204 | - 'event_espresso' |
|
| 1205 | - ), |
|
| 1206 | - '', |
|
| 1207 | - 'clear description' |
|
| 1208 | - ); |
|
| 1209 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1210 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - |
|
| 1214 | - /** |
|
| 1215 | - * _get_reg_status_selection |
|
| 1216 | - * |
|
| 1217 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1218 | - * instead of events. |
|
| 1219 | - * @access protected |
|
| 1220 | - * @return void |
|
| 1221 | - * @throws EE_Error |
|
| 1222 | - */ |
|
| 1223 | - protected function _get_reg_status_selection() |
|
| 1224 | - { |
|
| 1225 | - //first get all possible statuses |
|
| 1226 | - $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1227 | - //let's add a "don't change" option. |
|
| 1228 | - $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1229 | - $status_array = array_merge($status_array, $statuses); |
|
| 1230 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1231 | - 'txn_reg_status_change[reg_status]', |
|
| 1232 | - $status_array, |
|
| 1233 | - 'NAN', |
|
| 1234 | - 'id="txn-admin-payment-reg-status-inp"', |
|
| 1235 | - 'txn-reg-status-change-reg-status' |
|
| 1236 | - ); |
|
| 1237 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1238 | - 'delete_txn_reg_status_change[reg_status]', |
|
| 1239 | - $status_array, |
|
| 1240 | - 'NAN', |
|
| 1241 | - 'delete-txn-admin-payment-reg-status-inp', |
|
| 1242 | - 'delete-txn-reg-status-change-reg-status' |
|
| 1243 | - ); |
|
| 1244 | - } |
|
| 1245 | - |
|
| 1246 | - |
|
| 1247 | - /** |
|
| 1248 | - * _get_payment_methods |
|
| 1249 | - * Gets all the payment methods available generally, or the ones that are already |
|
| 1250 | - * selected on these payments (in case their payment methods are no longer active). |
|
| 1251 | - * Has the side-effect of updating the template args' payment_methods item |
|
| 1252 | - * |
|
| 1253 | - * @access private |
|
| 1254 | - * @param EE_Payment[] to show on this page |
|
| 1255 | - * @return void |
|
| 1256 | - * @throws EE_Error |
|
| 1257 | - * @throws InvalidArgumentException |
|
| 1258 | - * @throws InvalidDataTypeException |
|
| 1259 | - * @throws InvalidInterfaceException |
|
| 1260 | - */ |
|
| 1261 | - private function _get_payment_methods($payments = array()) |
|
| 1262 | - { |
|
| 1263 | - $payment_methods_of_payments = array(); |
|
| 1264 | - foreach ($payments as $payment) { |
|
| 1265 | - if ($payment instanceof EE_Payment) { |
|
| 1266 | - $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - if ($payment_methods_of_payments) { |
|
| 1270 | - $query_args = array( |
|
| 1271 | - array( |
|
| 1272 | - 'OR*payment_method_for_payment' => array( |
|
| 1273 | - 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1274 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1275 | - ), |
|
| 1276 | - ), |
|
| 1277 | - ); |
|
| 1278 | - } else { |
|
| 1279 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1280 | - } |
|
| 1281 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - |
|
| 1285 | - /** |
|
| 1286 | - * txn_attendees_meta_box |
|
| 1287 | - * generates HTML for the Attendees Transaction main meta box |
|
| 1288 | - * |
|
| 1289 | - * @access public |
|
| 1290 | - * @param WP_Post $post |
|
| 1291 | - * @param array $metabox |
|
| 1292 | - * @return void |
|
| 1293 | - * @throws DomainException |
|
| 1294 | - * @throws EE_Error |
|
| 1295 | - */ |
|
| 1296 | - public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1297 | - { |
|
| 1298 | - |
|
| 1299 | - /** @noinspection NonSecureExtractUsageInspection */ |
|
| 1300 | - extract($metabox['args']); |
|
| 1301 | - $this->_template_args['post'] = $post; |
|
| 1302 | - $this->_template_args['event_attendees'] = array(); |
|
| 1303 | - // process items in cart |
|
| 1304 | - $line_items = $this->_transaction->get_many_related( |
|
| 1305 | - 'Line_Item', |
|
| 1306 | - array(array('LIN_type' => 'line-item')) |
|
| 1307 | - ); |
|
| 1308 | - if (! empty($line_items)) { |
|
| 1309 | - foreach ($line_items as $item) { |
|
| 1310 | - if ($item instanceof EE_Line_Item) { |
|
| 1311 | - switch ($item->OBJ_type()) { |
|
| 1312 | - case 'Event': |
|
| 1313 | - break; |
|
| 1314 | - case 'Ticket': |
|
| 1315 | - $ticket = $item->ticket(); |
|
| 1316 | - //right now we're only handling tickets here. |
|
| 1317 | - //Cause its expected that only tickets will have attendees right? |
|
| 1318 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1319 | - continue; |
|
| 1320 | - } |
|
| 1321 | - try { |
|
| 1322 | - $event_name = $ticket->get_event_name(); |
|
| 1323 | - } catch (Exception $e) { |
|
| 1324 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1325 | - $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1326 | - } |
|
| 1327 | - $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1328 | - $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
| 1329 | - // now get all of the registrations for this transaction that use this ticket |
|
| 1330 | - $registrations = $ticket->get_many_related( |
|
| 1331 | - 'Registration', |
|
| 1332 | - array(array('TXN_ID' => $this->_transaction->ID())) |
|
| 1333 | - ); |
|
| 1334 | - foreach ($registrations as $registration) { |
|
| 1335 | - if (! $registration instanceof EE_Registration) { |
|
| 1336 | - continue; |
|
| 1337 | - } |
|
| 1338 | - $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] |
|
| 1339 | - = $registration->status_ID(); |
|
| 1340 | - $this->_template_args['event_attendees'][$registration->ID()]['att_num'] |
|
| 1341 | - = $registration->count(); |
|
| 1342 | - $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] |
|
| 1343 | - = $event_name; |
|
| 1344 | - $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] |
|
| 1345 | - = $ticket_price; |
|
| 1346 | - // attendee info |
|
| 1347 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 1348 | - if ($attendee instanceof EE_Attendee) { |
|
| 1349 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] |
|
| 1350 | - = $attendee->ID(); |
|
| 1351 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] |
|
| 1352 | - = $attendee->full_name(); |
|
| 1353 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] |
|
| 1354 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1355 | - . esc_html__( |
|
| 1356 | - ' Event', |
|
| 1357 | - 'event_espresso' |
|
| 1358 | - ) |
|
| 1359 | - . '">' . $attendee->email() . '</a>'; |
|
| 1360 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] |
|
| 1361 | - = EEH_Address::format($attendee, 'inline', false, false); |
|
| 1362 | - } else { |
|
| 1363 | - $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
| 1364 | - $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
| 1365 | - $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 1366 | - $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
| 1367 | - } |
|
| 1368 | - } |
|
| 1369 | - break; |
|
| 1370 | - |
|
| 1371 | - } |
|
| 1372 | - } |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1376 | - array( |
|
| 1377 | - 'action' => 'edit_transaction', |
|
| 1378 | - 'process' => 'attendees', |
|
| 1379 | - ), |
|
| 1380 | - TXN_ADMIN_URL |
|
| 1381 | - ); |
|
| 1382 | - echo EEH_Template::display_template( |
|
| 1383 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1384 | - $this->_template_args, |
|
| 1385 | - true |
|
| 1386 | - ); |
|
| 1387 | - |
|
| 1388 | - } else { |
|
| 1389 | - echo sprintf( |
|
| 1390 | - esc_html__( |
|
| 1391 | - '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1392 | - 'event_espresso' |
|
| 1393 | - ), |
|
| 1394 | - '<p class="important-notice">', |
|
| 1395 | - '</p>' |
|
| 1396 | - ); |
|
| 1397 | - } |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - |
|
| 1401 | - /** |
|
| 1402 | - * txn_registrant_side_meta_box |
|
| 1403 | - * generates HTML for the Edit Transaction side meta box |
|
| 1404 | - * |
|
| 1405 | - * @access public |
|
| 1406 | - * @return void |
|
| 1407 | - * @throws DomainException |
|
| 1408 | - * @throws EE_Error |
|
| 1409 | - * @throws InvalidArgumentException |
|
| 1410 | - * @throws InvalidDataTypeException |
|
| 1411 | - * @throws InvalidInterfaceException |
|
| 1412 | - */ |
|
| 1413 | - public function txn_registrant_side_meta_box() |
|
| 1414 | - { |
|
| 1415 | - $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1416 | - ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
| 1417 | - : null; |
|
| 1418 | - if (! $primary_att instanceof EE_Attendee) { |
|
| 1419 | - $this->_template_args['no_attendee_message'] = esc_html__( |
|
| 1420 | - 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1421 | - 'event_espresso' |
|
| 1422 | - ); |
|
| 1423 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1424 | - } |
|
| 1425 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1426 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1427 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1428 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1429 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1430 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1431 | - 'action' => 'edit_attendee', |
|
| 1432 | - 'post' => $primary_att->ID(), |
|
| 1433 | - ), REG_ADMIN_URL); |
|
| 1434 | - // get formatted address for registrant |
|
| 1435 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1436 | - echo EEH_Template::display_template( |
|
| 1437 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1438 | - $this->_template_args, |
|
| 1439 | - true |
|
| 1440 | - ); |
|
| 1441 | - } |
|
| 1442 | - |
|
| 1443 | - |
|
| 1444 | - /** |
|
| 1445 | - * txn_billing_info_side_meta_box |
|
| 1446 | - * generates HTML for the Edit Transaction side meta box |
|
| 1447 | - * |
|
| 1448 | - * @access public |
|
| 1449 | - * @return void |
|
| 1450 | - * @throws DomainException |
|
| 1451 | - * @throws EE_Error |
|
| 1452 | - */ |
|
| 1453 | - public function txn_billing_info_side_meta_box() |
|
| 1454 | - { |
|
| 1455 | - |
|
| 1456 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1457 | - $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1458 | - array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1459 | - TXN_ADMIN_URL |
|
| 1460 | - ); |
|
| 1461 | - |
|
| 1462 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1463 | - echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - |
|
| 1467 | - /** |
|
| 1468 | - * apply_payments_or_refunds |
|
| 1469 | - * registers a payment or refund made towards a transaction |
|
| 1470 | - * |
|
| 1471 | - * @access public |
|
| 1472 | - * @return void |
|
| 1473 | - * @throws EE_Error |
|
| 1474 | - * @throws InvalidArgumentException |
|
| 1475 | - * @throws ReflectionException |
|
| 1476 | - * @throws RuntimeException |
|
| 1477 | - * @throws InvalidDataTypeException |
|
| 1478 | - * @throws InvalidInterfaceException |
|
| 1479 | - */ |
|
| 1480 | - public function apply_payments_or_refunds() |
|
| 1481 | - { |
|
| 1482 | - $json_response_data = array('return_data' => false); |
|
| 1483 | - $valid_data = $this->_validate_payment_request_data(); |
|
| 1484 | - $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
| 1485 | - 'ee_edit_payments', |
|
| 1486 | - 'apply_payment_or_refund_from_registration_details' |
|
| 1487 | - ); |
|
| 1488 | - if (! empty($valid_data) && $has_access) { |
|
| 1489 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1490 | - //save the new payment |
|
| 1491 | - $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1492 | - // get the TXN for this payment |
|
| 1493 | - $transaction = $payment->transaction(); |
|
| 1494 | - // verify transaction |
|
| 1495 | - if ($transaction instanceof EE_Transaction) { |
|
| 1496 | - // calculate_total_payments_and_update_status |
|
| 1497 | - $this->_process_transaction_payments($transaction); |
|
| 1498 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1499 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1500 | - // apply payment to registrations (if applicable) |
|
| 1501 | - if (! empty($REG_IDs)) { |
|
| 1502 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1503 | - $this->_maybe_send_notifications(); |
|
| 1504 | - // now process status changes for the same registrations |
|
| 1505 | - $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1506 | - } |
|
| 1507 | - $this->_maybe_send_notifications($payment); |
|
| 1508 | - //prepare to render page |
|
| 1509 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1510 | - do_action( |
|
| 1511 | - 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
| 1512 | - $transaction, |
|
| 1513 | - $payment |
|
| 1514 | - ); |
|
| 1515 | - } else { |
|
| 1516 | - EE_Error::add_error( |
|
| 1517 | - esc_html__( |
|
| 1518 | - 'A valid Transaction for this payment could not be retrieved.', |
|
| 1519 | - 'event_espresso' |
|
| 1520 | - ), |
|
| 1521 | - __FILE__, |
|
| 1522 | - __FUNCTION__, |
|
| 1523 | - __LINE__ |
|
| 1524 | - ); |
|
| 1525 | - } |
|
| 1526 | - } else { |
|
| 1527 | - if ($has_access) { |
|
| 1528 | - EE_Error::add_error( |
|
| 1529 | - esc_html__( |
|
| 1530 | - 'The payment form data could not be processed. Please try again.', |
|
| 1531 | - 'event_espresso' |
|
| 1532 | - ), |
|
| 1533 | - __FILE__, |
|
| 1534 | - __FUNCTION__, |
|
| 1535 | - __LINE__ |
|
| 1536 | - ); |
|
| 1537 | - } else { |
|
| 1538 | - EE_Error::add_error( |
|
| 1539 | - esc_html__( |
|
| 1540 | - 'You do not have access to apply payments or refunds to a registration.', |
|
| 1541 | - 'event_espresso' |
|
| 1542 | - ), |
|
| 1543 | - __FILE__, |
|
| 1544 | - __FUNCTION__, |
|
| 1545 | - __LINE__ |
|
| 1546 | - ); |
|
| 1547 | - } |
|
| 1548 | - } |
|
| 1549 | - $notices = EE_Error::get_notices( |
|
| 1550 | - false, |
|
| 1551 | - false, |
|
| 1552 | - false |
|
| 1553 | - ); |
|
| 1554 | - $this->_template_args = array( |
|
| 1555 | - 'data' => $json_response_data, |
|
| 1556 | - 'error' => $notices['errors'], |
|
| 1557 | - 'success' => $notices['success'], |
|
| 1558 | - ); |
|
| 1559 | - $this->_return_json(); |
|
| 1560 | - } |
|
| 1561 | - |
|
| 1562 | - |
|
| 1563 | - /** |
|
| 1564 | - * _validate_payment_request_data |
|
| 1565 | - * |
|
| 1566 | - * @return array |
|
| 1567 | - */ |
|
| 1568 | - protected function _validate_payment_request_data() |
|
| 1569 | - { |
|
| 1570 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1571 | - return false; |
|
| 1572 | - } |
|
| 1573 | - $payment_form = $this->_generate_payment_form_section(); |
|
| 1574 | - try { |
|
| 1575 | - if ($payment_form->was_submitted()) { |
|
| 1576 | - $payment_form->receive_form_submission(); |
|
| 1577 | - if (! $payment_form->is_valid()) { |
|
| 1578 | - $submission_error_messages = array(); |
|
| 1579 | - foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1580 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1581 | - $submission_error_messages[] = sprintf( |
|
| 1582 | - _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1583 | - $validation_error->get_form_section()->html_label_text(), |
|
| 1584 | - $validation_error->getMessage() |
|
| 1585 | - ); |
|
| 1586 | - } |
|
| 1587 | - } |
|
| 1588 | - EE_Error::add_error( |
|
| 1589 | - implode('<br />', $submission_error_messages), |
|
| 1590 | - __FILE__, |
|
| 1591 | - __FUNCTION__, |
|
| 1592 | - __LINE__ |
|
| 1593 | - ); |
|
| 1594 | - |
|
| 1595 | - return array(); |
|
| 1596 | - } |
|
| 1597 | - } |
|
| 1598 | - } catch (EE_Error $e) { |
|
| 1599 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1600 | - |
|
| 1601 | - return array(); |
|
| 1602 | - } |
|
| 1603 | - |
|
| 1604 | - return $payment_form->valid_data(); |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - |
|
| 1608 | - /** |
|
| 1609 | - * _generate_payment_form_section |
|
| 1610 | - * |
|
| 1611 | - * @return EE_Form_Section_Proper |
|
| 1612 | - */ |
|
| 1613 | - protected function _generate_payment_form_section() |
|
| 1614 | - { |
|
| 1615 | - return new EE_Form_Section_Proper( |
|
| 1616 | - array( |
|
| 1617 | - 'name' => 'txn_admin_payment', |
|
| 1618 | - 'subsections' => array( |
|
| 1619 | - 'PAY_ID' => new EE_Text_Input( |
|
| 1620 | - array( |
|
| 1621 | - 'default' => 0, |
|
| 1622 | - 'required' => false, |
|
| 1623 | - 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1624 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1625 | - ) |
|
| 1626 | - ), |
|
| 1627 | - 'TXN_ID' => new EE_Text_Input( |
|
| 1628 | - array( |
|
| 1629 | - 'default' => 0, |
|
| 1630 | - 'required' => true, |
|
| 1631 | - 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1632 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1633 | - ) |
|
| 1634 | - ), |
|
| 1635 | - 'type' => new EE_Text_Input( |
|
| 1636 | - array( |
|
| 1637 | - 'default' => 1, |
|
| 1638 | - 'required' => true, |
|
| 1639 | - 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1640 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1641 | - ) |
|
| 1642 | - ), |
|
| 1643 | - 'amount' => new EE_Text_Input( |
|
| 1644 | - array( |
|
| 1645 | - 'default' => 0, |
|
| 1646 | - 'required' => true, |
|
| 1647 | - 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1648 | - 'validation_strategies' => array(new EE_Float_Normalization()), |
|
| 1649 | - ) |
|
| 1650 | - ), |
|
| 1651 | - 'status' => new EE_Text_Input( |
|
| 1652 | - array( |
|
| 1653 | - 'default' => EEM_Payment::status_id_approved, |
|
| 1654 | - 'required' => true, |
|
| 1655 | - 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1656 | - ) |
|
| 1657 | - ), |
|
| 1658 | - 'PMD_ID' => new EE_Text_Input( |
|
| 1659 | - array( |
|
| 1660 | - 'default' => 2, |
|
| 1661 | - 'required' => true, |
|
| 1662 | - 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1663 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1664 | - ) |
|
| 1665 | - ), |
|
| 1666 | - 'date' => new EE_Text_Input( |
|
| 1667 | - array( |
|
| 1668 | - 'default' => time(), |
|
| 1669 | - 'required' => true, |
|
| 1670 | - 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1671 | - ) |
|
| 1672 | - ), |
|
| 1673 | - 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1674 | - array( |
|
| 1675 | - 'default' => '', |
|
| 1676 | - 'required' => false, |
|
| 1677 | - 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1678 | - 'validation_strategies' => array( |
|
| 1679 | - new EE_Max_Length_Validation_Strategy( |
|
| 1680 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1681 | - 100 |
|
| 1682 | - ), |
|
| 1683 | - ), |
|
| 1684 | - ) |
|
| 1685 | - ), |
|
| 1686 | - 'po_number' => new EE_Text_Input( |
|
| 1687 | - array( |
|
| 1688 | - 'default' => '', |
|
| 1689 | - 'required' => false, |
|
| 1690 | - 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1691 | - 'validation_strategies' => array( |
|
| 1692 | - new EE_Max_Length_Validation_Strategy( |
|
| 1693 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1694 | - 100 |
|
| 1695 | - ), |
|
| 1696 | - ), |
|
| 1697 | - ) |
|
| 1698 | - ), |
|
| 1699 | - 'accounting' => new EE_Text_Input( |
|
| 1700 | - array( |
|
| 1701 | - 'default' => '', |
|
| 1702 | - 'required' => false, |
|
| 1703 | - 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1704 | - 'validation_strategies' => array( |
|
| 1705 | - new EE_Max_Length_Validation_Strategy( |
|
| 1706 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1707 | - 100 |
|
| 1708 | - ), |
|
| 1709 | - ), |
|
| 1710 | - ) |
|
| 1711 | - ), |
|
| 1712 | - ), |
|
| 1713 | - ) |
|
| 1714 | - ); |
|
| 1715 | - } |
|
| 1716 | - |
|
| 1717 | - |
|
| 1718 | - /** |
|
| 1719 | - * _create_payment_from_request_data |
|
| 1720 | - * |
|
| 1721 | - * @param array $valid_data |
|
| 1722 | - * @return EE_Payment |
|
| 1723 | - * @throws EE_Error |
|
| 1724 | - */ |
|
| 1725 | - protected function _create_payment_from_request_data($valid_data) |
|
| 1726 | - { |
|
| 1727 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1728 | - // get payment amount |
|
| 1729 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1730 | - // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1731 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1732 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1733 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1734 | - $date = $valid_data['date'] |
|
| 1735 | - ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
| 1736 | - : date('Y-m-d g:i a', current_time('timestamp')); |
|
| 1737 | - $payment = EE_Payment::new_instance( |
|
| 1738 | - array( |
|
| 1739 | - 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1740 | - 'STS_ID' => $valid_data['status'], |
|
| 1741 | - 'PAY_timestamp' => $date, |
|
| 1742 | - 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1743 | - 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1744 | - 'PAY_amount' => $amount, |
|
| 1745 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1746 | - 'PAY_po_number' => $valid_data['po_number'], |
|
| 1747 | - 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1748 | - 'PAY_details' => $valid_data, |
|
| 1749 | - 'PAY_ID' => $PAY_ID, |
|
| 1750 | - ), |
|
| 1751 | - '', |
|
| 1752 | - array('Y-m-d', 'g:i a') |
|
| 1753 | - ); |
|
| 1754 | - |
|
| 1755 | - if (! $payment->save()) { |
|
| 1756 | - EE_Error::add_error( |
|
| 1757 | - sprintf( |
|
| 1758 | - esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1759 | - $payment->ID() |
|
| 1760 | - ), |
|
| 1761 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 1762 | - ); |
|
| 1763 | - } |
|
| 1764 | - |
|
| 1765 | - return $payment; |
|
| 1766 | - } |
|
| 1767 | - |
|
| 1768 | - |
|
| 1769 | - /** |
|
| 1770 | - * _process_transaction_payments |
|
| 1771 | - * |
|
| 1772 | - * @param \EE_Transaction $transaction |
|
| 1773 | - * @return void |
|
| 1774 | - * @throws EE_Error |
|
| 1775 | - * @throws InvalidArgumentException |
|
| 1776 | - * @throws ReflectionException |
|
| 1777 | - * @throws InvalidDataTypeException |
|
| 1778 | - * @throws InvalidInterfaceException |
|
| 1779 | - */ |
|
| 1780 | - protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1781 | - { |
|
| 1782 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1783 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1784 | - //update the transaction with this payment |
|
| 1785 | - if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1786 | - EE_Error::add_success(esc_html__( |
|
| 1787 | - 'The payment has been processed successfully.', 'event_espresso'), |
|
| 1788 | - __FILE__, |
|
| 1789 | - __FUNCTION__, |
|
| 1790 | - __LINE__ |
|
| 1791 | - ); |
|
| 1792 | - } else { |
|
| 1793 | - EE_Error::add_error( |
|
| 1794 | - esc_html__( |
|
| 1795 | - 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1796 | - 'event_espresso' |
|
| 1797 | - ) |
|
| 1798 | - , |
|
| 1799 | - __FILE__, |
|
| 1800 | - __FUNCTION__, |
|
| 1801 | - __LINE__ |
|
| 1802 | - ); |
|
| 1803 | - } |
|
| 1804 | - } |
|
| 1805 | - |
|
| 1806 | - |
|
| 1807 | - /** |
|
| 1808 | - * _get_REG_IDs_to_apply_payment_to |
|
| 1809 | - * returns a list of registration IDs that the payment will apply to |
|
| 1810 | - * |
|
| 1811 | - * @param \EE_Payment $payment |
|
| 1812 | - * @return array |
|
| 1813 | - * @throws EE_Error |
|
| 1814 | - */ |
|
| 1815 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1816 | - { |
|
| 1817 | - $REG_IDs = array(); |
|
| 1818 | - // grab array of IDs for specific registrations to apply changes to |
|
| 1819 | - if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1820 | - $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1821 | - } |
|
| 1822 | - //nothing specified ? then get all reg IDs |
|
| 1823 | - if (empty($REG_IDs)) { |
|
| 1824 | - $registrations = $payment->transaction()->registrations(); |
|
| 1825 | - $REG_IDs = ! empty($registrations) |
|
| 1826 | - ? array_keys($registrations) |
|
| 1827 | - : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1828 | - } |
|
| 1829 | - |
|
| 1830 | - // ensure that REG_IDs are integers and NOT strings |
|
| 1831 | - return array_map('intval', $REG_IDs); |
|
| 1832 | - } |
|
| 1833 | - |
|
| 1834 | - |
|
| 1835 | - /** |
|
| 1836 | - * @return array |
|
| 1837 | - */ |
|
| 1838 | - public function existing_reg_payment_REG_IDs() |
|
| 1839 | - { |
|
| 1840 | - return $this->_existing_reg_payment_REG_IDs; |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - |
|
| 1844 | - /** |
|
| 1845 | - * @param array $existing_reg_payment_REG_IDs |
|
| 1846 | - */ |
|
| 1847 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1848 | - { |
|
| 1849 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1850 | - } |
|
| 1851 | - |
|
| 1852 | - |
|
| 1853 | - /** |
|
| 1854 | - * _get_existing_reg_payment_REG_IDs |
|
| 1855 | - * returns a list of registration IDs that the payment is currently related to |
|
| 1856 | - * as recorded in the database |
|
| 1857 | - * |
|
| 1858 | - * @param \EE_Payment $payment |
|
| 1859 | - * @return array |
|
| 1860 | - * @throws EE_Error |
|
| 1861 | - */ |
|
| 1862 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 1863 | - { |
|
| 1864 | - if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 1865 | - // let's get any existing reg payment records for this payment |
|
| 1866 | - $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 1867 | - // but we only want the REG IDs, so grab the array keys |
|
| 1868 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
| 1869 | - ? array_keys($existing_reg_payment_REG_IDs) |
|
| 1870 | - : array(); |
|
| 1871 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - return $this->existing_reg_payment_REG_IDs(); |
|
| 1875 | - } |
|
| 1876 | - |
|
| 1877 | - |
|
| 1878 | - /** |
|
| 1879 | - * _remove_existing_registration_payments |
|
| 1880 | - * this calculates the difference between existing relations |
|
| 1881 | - * to the supplied payment and the new list registration IDs, |
|
| 1882 | - * removes any related registrations that no longer apply, |
|
| 1883 | - * and then updates the registration paid fields |
|
| 1884 | - * |
|
| 1885 | - * @param \EE_Payment $payment |
|
| 1886 | - * @param int $PAY_ID |
|
| 1887 | - * @return bool; |
|
| 1888 | - * @throws EE_Error |
|
| 1889 | - * @throws InvalidArgumentException |
|
| 1890 | - * @throws ReflectionException |
|
| 1891 | - * @throws InvalidDataTypeException |
|
| 1892 | - * @throws InvalidInterfaceException |
|
| 1893 | - */ |
|
| 1894 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 1895 | - { |
|
| 1896 | - // newly created payments will have nothing recorded for $PAY_ID |
|
| 1897 | - if ($PAY_ID == 0) { |
|
| 1898 | - return false; |
|
| 1899 | - } |
|
| 1900 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1901 | - if (empty($existing_reg_payment_REG_IDs)) { |
|
| 1902 | - return false; |
|
| 1903 | - } |
|
| 1904 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1905 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1906 | - |
|
| 1907 | - return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 1908 | - $payment, |
|
| 1909 | - array( |
|
| 1910 | - array( |
|
| 1911 | - 'PAY_ID' => $payment->ID(), |
|
| 1912 | - 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 1913 | - ), |
|
| 1914 | - ) |
|
| 1915 | - ); |
|
| 1916 | - } |
|
| 1917 | - |
|
| 1918 | - |
|
| 1919 | - /** |
|
| 1920 | - * _update_registration_payments |
|
| 1921 | - * this applies the payments to the selected registrations |
|
| 1922 | - * but only if they have not already been paid for |
|
| 1923 | - * |
|
| 1924 | - * @param EE_Transaction $transaction |
|
| 1925 | - * @param \EE_Payment $payment |
|
| 1926 | - * @param array $REG_IDs |
|
| 1927 | - * @return void |
|
| 1928 | - * @throws EE_Error |
|
| 1929 | - * @throws InvalidArgumentException |
|
| 1930 | - * @throws ReflectionException |
|
| 1931 | - * @throws RuntimeException |
|
| 1932 | - * @throws InvalidDataTypeException |
|
| 1933 | - * @throws InvalidInterfaceException |
|
| 1934 | - */ |
|
| 1935 | - protected function _update_registration_payments( |
|
| 1936 | - EE_Transaction $transaction, |
|
| 1937 | - EE_Payment $payment, |
|
| 1938 | - $REG_IDs = array() |
|
| 1939 | - ) { |
|
| 1940 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 1941 | - // so let's do that using our set of REG_IDs from the form |
|
| 1942 | - $registration_query_where_params = array( |
|
| 1943 | - 'REG_ID' => array('IN', $REG_IDs), |
|
| 1944 | - ); |
|
| 1945 | - // but add in some conditions regarding payment, |
|
| 1946 | - // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 1947 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 1948 | - if (! $payment->is_a_refund()) { |
|
| 1949 | - $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 1950 | - $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 1951 | - } |
|
| 1952 | - $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 1953 | - if (! empty($registrations)) { |
|
| 1954 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 1955 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 1956 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 1957 | - } |
|
| 1958 | - } |
|
| 1959 | - |
|
| 1960 | - |
|
| 1961 | - /** |
|
| 1962 | - * _process_registration_status_change |
|
| 1963 | - * This processes requested registration status changes for all the registrations |
|
| 1964 | - * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 1965 | - * |
|
| 1966 | - * @param EE_Transaction $transaction |
|
| 1967 | - * @param array $REG_IDs |
|
| 1968 | - * @return bool |
|
| 1969 | - * @throws EE_Error |
|
| 1970 | - * @throws InvalidArgumentException |
|
| 1971 | - * @throws ReflectionException |
|
| 1972 | - * @throws InvalidDataTypeException |
|
| 1973 | - * @throws InvalidInterfaceException |
|
| 1974 | - */ |
|
| 1975 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 1976 | - { |
|
| 1977 | - // first if there is no change in status then we get out. |
|
| 1978 | - if ( |
|
| 1979 | - ! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 1980 | - || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
| 1981 | - ) { |
|
| 1982 | - //no error message, no change requested, just nothing to do man. |
|
| 1983 | - return false; |
|
| 1984 | - } |
|
| 1985 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1986 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1987 | - |
|
| 1988 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 1989 | - return $transaction_processor->manually_update_registration_statuses( |
|
| 1990 | - $transaction, |
|
| 1991 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 1992 | - array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 1993 | - ); |
|
| 1994 | - } |
|
| 1995 | - |
|
| 1996 | - |
|
| 1997 | - /** |
|
| 1998 | - * _build_payment_json_response |
|
| 1999 | - * |
|
| 2000 | - * @access public |
|
| 2001 | - * @param \EE_Payment $payment |
|
| 2002 | - * @param array $REG_IDs |
|
| 2003 | - * @param bool | null $delete_txn_reg_status_change |
|
| 2004 | - * @return array |
|
| 2005 | - * @throws EE_Error |
|
| 2006 | - * @throws InvalidArgumentException |
|
| 2007 | - * @throws InvalidDataTypeException |
|
| 2008 | - * @throws InvalidInterfaceException |
|
| 2009 | - */ |
|
| 2010 | - protected function _build_payment_json_response( |
|
| 2011 | - EE_Payment $payment, |
|
| 2012 | - $REG_IDs = array(), |
|
| 2013 | - $delete_txn_reg_status_change = null |
|
| 2014 | - ) { |
|
| 2015 | - // was the payment deleted ? |
|
| 2016 | - if (is_bool($delete_txn_reg_status_change)) { |
|
| 2017 | - return array( |
|
| 2018 | - 'PAY_ID' => $payment->ID(), |
|
| 2019 | - 'amount' => $payment->amount(), |
|
| 2020 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 2021 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2022 | - 'pay_status' => $payment->STS_ID(), |
|
| 2023 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2024 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 2025 | - ); |
|
| 2026 | - } else { |
|
| 2027 | - $this->_get_payment_status_array(); |
|
| 2028 | - |
|
| 2029 | - return array( |
|
| 2030 | - 'amount' => $payment->amount(), |
|
| 2031 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 2032 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2033 | - 'pay_status' => $payment->STS_ID(), |
|
| 2034 | - 'PAY_ID' => $payment->ID(), |
|
| 2035 | - 'STS_ID' => $payment->STS_ID(), |
|
| 2036 | - 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 2037 | - 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 2038 | - 'method' => strtoupper($payment->source()), |
|
| 2039 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 2040 | - 'gateway' => $payment->payment_method() |
|
| 2041 | - ? $payment->payment_method()->admin_name() |
|
| 2042 | - : esc_html__("Unknown", 'event_espresso'), |
|
| 2043 | - 'gateway_response' => $payment->gateway_response(), |
|
| 2044 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 2045 | - 'po_number' => $payment->po_number(), |
|
| 2046 | - 'extra_accntng' => $payment->extra_accntng(), |
|
| 2047 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2048 | - ); |
|
| 2049 | - } |
|
| 2050 | - } |
|
| 2051 | - |
|
| 2052 | - |
|
| 2053 | - /** |
|
| 2054 | - * delete_payment |
|
| 2055 | - * delete a payment or refund made towards a transaction |
|
| 2056 | - * |
|
| 2057 | - * @access public |
|
| 2058 | - * @return void |
|
| 2059 | - * @throws EE_Error |
|
| 2060 | - * @throws InvalidArgumentException |
|
| 2061 | - * @throws ReflectionException |
|
| 2062 | - * @throws InvalidDataTypeException |
|
| 2063 | - * @throws InvalidInterfaceException |
|
| 2064 | - */ |
|
| 2065 | - public function delete_payment() |
|
| 2066 | - { |
|
| 2067 | - $json_response_data = array('return_data' => false); |
|
| 2068 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2069 | - ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2070 | - : 0; |
|
| 2071 | - $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
| 2072 | - 'ee_delete_payments', |
|
| 2073 | - 'delete_payment_from_registration_details' |
|
| 2074 | - ); |
|
| 2075 | - if ($PAY_ID && $can_delete) { |
|
| 2076 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
| 2077 | - ? $this->_req_data['delete_txn_reg_status_change'] |
|
| 2078 | - : false; |
|
| 2079 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 2080 | - if ($payment instanceof EE_Payment) { |
|
| 2081 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2082 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2083 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2084 | - if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 2085 | - $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
| 2086 | - $payment, |
|
| 2087 | - $REG_IDs, |
|
| 2088 | - $delete_txn_reg_status_change |
|
| 2089 | - ); |
|
| 2090 | - if ($delete_txn_reg_status_change) { |
|
| 2091 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2092 | - //MAKE sure we also add the delete_txn_req_status_change to the |
|
| 2093 | - //$_REQUEST global because that's how messages will be looking for it. |
|
| 2094 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2095 | - $this->_maybe_send_notifications(); |
|
| 2096 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 2097 | - } |
|
| 2098 | - } |
|
| 2099 | - } else { |
|
| 2100 | - EE_Error::add_error( |
|
| 2101 | - esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 2102 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2103 | - ); |
|
| 2104 | - } |
|
| 2105 | - } else { |
|
| 2106 | - if ($can_delete) { |
|
| 2107 | - EE_Error::add_error( |
|
| 2108 | - esc_html__( |
|
| 2109 | - 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 2110 | - 'event_espresso' |
|
| 2111 | - ), |
|
| 2112 | - __FILE__, __FUNCTION__, __LINE__ |
|
| 2113 | - ); |
|
| 2114 | - } else { |
|
| 2115 | - EE_Error::add_error( |
|
| 2116 | - esc_html__( |
|
| 2117 | - 'You do not have access to delete a payment.', |
|
| 2118 | - 'event_espresso' |
|
| 2119 | - ), |
|
| 2120 | - __FILE__, |
|
| 2121 | - __FUNCTION__, |
|
| 2122 | - __LINE__ |
|
| 2123 | - ); |
|
| 2124 | - } |
|
| 2125 | - } |
|
| 2126 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 2127 | - $this->_template_args = array( |
|
| 2128 | - 'data' => $json_response_data, |
|
| 2129 | - 'success' => $notices['success'], |
|
| 2130 | - 'error' => $notices['errors'], |
|
| 2131 | - 'attention' => $notices['attention'], |
|
| 2132 | - ); |
|
| 2133 | - $this->_return_json(); |
|
| 2134 | - } |
|
| 2135 | - |
|
| 2136 | - |
|
| 2137 | - /** |
|
| 2138 | - * _registration_payment_data_array |
|
| 2139 | - * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 2140 | - * |
|
| 2141 | - * @access protected |
|
| 2142 | - * @param array $REG_IDs |
|
| 2143 | - * @return array |
|
| 2144 | - * @throws EE_Error |
|
| 2145 | - * @throws InvalidArgumentException |
|
| 2146 | - * @throws InvalidDataTypeException |
|
| 2147 | - * @throws InvalidInterfaceException |
|
| 2148 | - */ |
|
| 2149 | - protected function _registration_payment_data_array($REG_IDs) |
|
| 2150 | - { |
|
| 2151 | - $registration_payment_data = array(); |
|
| 2152 | - //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 2153 | - if (! empty($REG_IDs)) { |
|
| 2154 | - $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 2155 | - foreach ($registrations as $registration) { |
|
| 2156 | - if ($registration instanceof EE_Registration) { |
|
| 2157 | - $registration_payment_data[$registration->ID()] = array( |
|
| 2158 | - 'paid' => $registration->pretty_paid(), |
|
| 2159 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 2160 | - ); |
|
| 2161 | - } |
|
| 2162 | - } |
|
| 2163 | - } |
|
| 2164 | - |
|
| 2165 | - return $registration_payment_data; |
|
| 2166 | - } |
|
| 2167 | - |
|
| 2168 | - |
|
| 2169 | - /** |
|
| 2170 | - * _maybe_send_notifications |
|
| 2171 | - * determines whether or not the admin has indicated that notifications should be sent. |
|
| 2172 | - * If so, will toggle a filter switch for delivering registration notices. |
|
| 2173 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 2174 | - * |
|
| 2175 | - * @access protected |
|
| 2176 | - * @param \EE_Payment | null $payment |
|
| 2177 | - */ |
|
| 2178 | - protected function _maybe_send_notifications($payment = null) |
|
| 2179 | - { |
|
| 2180 | - switch ($payment instanceof EE_Payment) { |
|
| 2181 | - // payment notifications |
|
| 2182 | - case true : |
|
| 2183 | - if ( |
|
| 2184 | - isset( |
|
| 2185 | - $this->_req_data['txn_payments'], |
|
| 2186 | - $this->_req_data['txn_payments']['send_notifications'] |
|
| 2187 | - ) && |
|
| 2188 | - filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 2189 | - ) { |
|
| 2190 | - $this->_process_payment_notification($payment); |
|
| 2191 | - } |
|
| 2192 | - break; |
|
| 2193 | - // registration notifications |
|
| 2194 | - case false : |
|
| 2195 | - if ( |
|
| 2196 | - isset( |
|
| 2197 | - $this->_req_data['txn_reg_status_change'], |
|
| 2198 | - $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 2199 | - ) && |
|
| 2200 | - filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 2201 | - ) { |
|
| 2202 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 2203 | - } |
|
| 2204 | - break; |
|
| 2205 | - } |
|
| 2206 | - } |
|
| 2207 | - |
|
| 2208 | - |
|
| 2209 | - /** |
|
| 2210 | - * _send_payment_reminder |
|
| 2211 | - * generates HTML for the View Transaction Details Admin page |
|
| 2212 | - * |
|
| 2213 | - * @access protected |
|
| 2214 | - * @return void |
|
| 2215 | - * @throws EE_Error |
|
| 2216 | - * @throws InvalidArgumentException |
|
| 2217 | - * @throws InvalidDataTypeException |
|
| 2218 | - * @throws InvalidInterfaceException |
|
| 2219 | - */ |
|
| 2220 | - protected function _send_payment_reminder() |
|
| 2221 | - { |
|
| 2222 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2223 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2224 | - $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 2225 | - 'action' => $this->_req_data['redirect_to'], |
|
| 2226 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2227 | - ) : array(); |
|
| 2228 | - do_action( |
|
| 2229 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 2230 | - $transaction |
|
| 2231 | - ); |
|
| 2232 | - $this->_redirect_after_action( |
|
| 2233 | - false, |
|
| 2234 | - esc_html__('payment reminder', 'event_espresso'), |
|
| 2235 | - esc_html__('sent', 'event_espresso'), |
|
| 2236 | - $query_args, |
|
| 2237 | - true |
|
| 2238 | - ); |
|
| 2239 | - } |
|
| 2240 | - |
|
| 2241 | - |
|
| 2242 | - /** |
|
| 2243 | - * get_transactions |
|
| 2244 | - * get transactions for given parameters (used by list table) |
|
| 2245 | - * |
|
| 2246 | - * @param int $perpage how many transactions displayed per page |
|
| 2247 | - * @param boolean $count return the count or objects |
|
| 2248 | - * @param string $view |
|
| 2249 | - * @return mixed int = count || array of transaction objects |
|
| 2250 | - * @throws EE_Error |
|
| 2251 | - * @throws InvalidArgumentException |
|
| 2252 | - * @throws InvalidDataTypeException |
|
| 2253 | - * @throws InvalidInterfaceException |
|
| 2254 | - */ |
|
| 2255 | - public function get_transactions($perpage, $count = false, $view = '') |
|
| 2256 | - { |
|
| 2257 | - |
|
| 2258 | - $TXN = EEM_Transaction::instance(); |
|
| 2259 | - |
|
| 2260 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 2261 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 2262 | - : date( |
|
| 2263 | - 'm/d/Y', |
|
| 2264 | - strtotime('-10 year') |
|
| 2265 | - ); |
|
| 2266 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2267 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 2268 | - : date('m/d/Y'); |
|
| 2269 | - |
|
| 2270 | - //make sure our timestamps start and end right at the boundaries for each day |
|
| 2271 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2272 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2273 | - |
|
| 2274 | - |
|
| 2275 | - //convert to timestamps |
|
| 2276 | - $start_date = strtotime($start_date); |
|
| 2277 | - $end_date = strtotime($end_date); |
|
| 2278 | - |
|
| 2279 | - //makes sure start date is the lowest value and vice versa |
|
| 2280 | - $start_date = min($start_date, $end_date); |
|
| 2281 | - $end_date = max($start_date, $end_date); |
|
| 2282 | - |
|
| 2283 | - //convert to correct format for query |
|
| 2284 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2285 | - 'TXN_timestamp', |
|
| 2286 | - date('Y-m-d H:i:s', $start_date), |
|
| 2287 | - 'Y-m-d H:i:s' |
|
| 2288 | - ); |
|
| 2289 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2290 | - 'TXN_timestamp', |
|
| 2291 | - date('Y-m-d H:i:s', $end_date), |
|
| 2292 | - 'Y-m-d H:i:s' |
|
| 2293 | - ); |
|
| 2294 | - |
|
| 2295 | - |
|
| 2296 | - //set orderby |
|
| 2297 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2298 | - |
|
| 2299 | - switch ($this->_req_data['orderby']) { |
|
| 2300 | - case 'TXN_ID': |
|
| 2301 | - $orderby = 'TXN_ID'; |
|
| 2302 | - break; |
|
| 2303 | - case 'ATT_fname': |
|
| 2304 | - $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 2305 | - break; |
|
| 2306 | - case 'event_name': |
|
| 2307 | - $orderby = 'Registration.Event.EVT_name'; |
|
| 2308 | - break; |
|
| 2309 | - default: //'TXN_timestamp' |
|
| 2310 | - $orderby = 'TXN_timestamp'; |
|
| 2311 | - } |
|
| 2312 | - |
|
| 2313 | - $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2314 | - $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 2315 | - $per_page = ! empty($perpage) ? $perpage : 10; |
|
| 2316 | - $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 2317 | - |
|
| 2318 | - $offset = ($current_page - 1) * $per_page; |
|
| 2319 | - $limit = array($offset, $per_page); |
|
| 2320 | - |
|
| 2321 | - $_where = array( |
|
| 2322 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 2323 | - 'Registration.REG_count' => 1, |
|
| 2324 | - ); |
|
| 2325 | - |
|
| 2326 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 2327 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2328 | - } |
|
| 2329 | - |
|
| 2330 | - if (isset($this->_req_data['s'])) { |
|
| 2331 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2332 | - $_where['OR'] = array( |
|
| 2333 | - 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 2334 | - 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 2335 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 2336 | - 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 2337 | - 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 2338 | - 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 2339 | - 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 2340 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 2341 | - 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 2342 | - 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 2343 | - 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 2344 | - 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 2345 | - 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 2346 | - 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 2347 | - 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 2348 | - 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 2349 | - 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 2350 | - 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 2351 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 2352 | - 'TXN_session_data' => array('LIKE', $search_string), |
|
| 2353 | - 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 2354 | - ); |
|
| 2355 | - } |
|
| 2356 | - |
|
| 2357 | - //failed transactions |
|
| 2358 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2359 | - || ($count && $view === 'failed'); |
|
| 2360 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2361 | - || ($count && $view === 'abandoned'); |
|
| 2362 | - |
|
| 2363 | - if ($failed) { |
|
| 2364 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 2365 | - } else if ($abandoned) { |
|
| 2366 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 2367 | - } else { |
|
| 2368 | - $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 2369 | - $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 2370 | - } |
|
| 2371 | - |
|
| 2372 | - $query_params = array( |
|
| 2373 | - $_where, |
|
| 2374 | - 'order_by' => array($orderby => $sort), |
|
| 2375 | - 'limit' => $limit, |
|
| 2376 | - 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
| 2377 | - ); |
|
| 2378 | - |
|
| 2379 | - $transactions = $count |
|
| 2380 | - ? $TXN->count(array($_where), 'TXN_ID', true) |
|
| 2381 | - : $TXN->get_all($query_params); |
|
| 2382 | - |
|
| 2383 | - return $transactions; |
|
| 2384 | - } |
|
| 19 | + /** |
|
| 20 | + * @var EE_Transaction |
|
| 21 | + */ |
|
| 22 | + private $_transaction; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @var EE_Session |
|
| 26 | + */ |
|
| 27 | + private $_session; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var array $_txn_status |
|
| 31 | + */ |
|
| 32 | + private static $_txn_status; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var array $_pay_status |
|
| 36 | + */ |
|
| 37 | + private static $_pay_status; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var array $_existing_reg_payment_REG_IDs |
|
| 41 | + */ |
|
| 42 | + protected $_existing_reg_payment_REG_IDs = null; |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @Constructor |
|
| 47 | + * @access public |
|
| 48 | + * @param bool $routing |
|
| 49 | + * @throws EE_Error |
|
| 50 | + * @throws InvalidArgumentException |
|
| 51 | + * @throws ReflectionException |
|
| 52 | + * @throws InvalidDataTypeException |
|
| 53 | + * @throws InvalidInterfaceException |
|
| 54 | + */ |
|
| 55 | + public function __construct($routing = true) |
|
| 56 | + { |
|
| 57 | + parent::__construct($routing); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * _init_page_props |
|
| 63 | + * |
|
| 64 | + * @return void |
|
| 65 | + */ |
|
| 66 | + protected function _init_page_props() |
|
| 67 | + { |
|
| 68 | + $this->page_slug = TXN_PG_SLUG; |
|
| 69 | + $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 70 | + $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 71 | + $this->_admin_base_path = TXN_ADMIN; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * _ajax_hooks |
|
| 77 | + * |
|
| 78 | + * @return void |
|
| 79 | + */ |
|
| 80 | + protected function _ajax_hooks() |
|
| 81 | + { |
|
| 82 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 83 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 84 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * _define_page_props |
|
| 90 | + * |
|
| 91 | + * @return void |
|
| 92 | + */ |
|
| 93 | + protected function _define_page_props() |
|
| 94 | + { |
|
| 95 | + $this->_admin_page_title = $this->page_label; |
|
| 96 | + $this->_labels = array( |
|
| 97 | + 'buttons' => array( |
|
| 98 | + 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 99 | + 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 100 | + 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 101 | + ), |
|
| 102 | + ); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * grab url requests and route them |
|
| 108 | + * |
|
| 109 | + * @access private |
|
| 110 | + * @return void |
|
| 111 | + * @throws EE_Error |
|
| 112 | + * @throws InvalidArgumentException |
|
| 113 | + * @throws InvalidDataTypeException |
|
| 114 | + * @throws InvalidInterfaceException |
|
| 115 | + */ |
|
| 116 | + public function _set_page_routes() |
|
| 117 | + { |
|
| 118 | + |
|
| 119 | + $this->_set_transaction_status_array(); |
|
| 120 | + |
|
| 121 | + $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
| 122 | + && ! is_array($this->_req_data['TXN_ID']) |
|
| 123 | + ? $this->_req_data['TXN_ID'] |
|
| 124 | + : 0; |
|
| 125 | + |
|
| 126 | + $this->_page_routes = array( |
|
| 127 | + |
|
| 128 | + 'default' => array( |
|
| 129 | + 'func' => '_transactions_overview_list_table', |
|
| 130 | + 'capability' => 'ee_read_transactions', |
|
| 131 | + ), |
|
| 132 | + |
|
| 133 | + 'view_transaction' => array( |
|
| 134 | + 'func' => '_transaction_details', |
|
| 135 | + 'capability' => 'ee_read_transaction', |
|
| 136 | + 'obj_id' => $txn_id, |
|
| 137 | + ), |
|
| 138 | + |
|
| 139 | + 'send_payment_reminder' => array( |
|
| 140 | + 'func' => '_send_payment_reminder', |
|
| 141 | + 'noheader' => true, |
|
| 142 | + 'capability' => 'ee_send_message', |
|
| 143 | + ), |
|
| 144 | + |
|
| 145 | + 'espresso_apply_payment' => array( |
|
| 146 | + 'func' => 'apply_payments_or_refunds', |
|
| 147 | + 'noheader' => true, |
|
| 148 | + 'capability' => 'ee_edit_payments', |
|
| 149 | + ), |
|
| 150 | + |
|
| 151 | + 'espresso_apply_refund' => array( |
|
| 152 | + 'func' => 'apply_payments_or_refunds', |
|
| 153 | + 'noheader' => true, |
|
| 154 | + 'capability' => 'ee_edit_payments', |
|
| 155 | + ), |
|
| 156 | + |
|
| 157 | + 'espresso_delete_payment' => array( |
|
| 158 | + 'func' => 'delete_payment', |
|
| 159 | + 'noheader' => true, |
|
| 160 | + 'capability' => 'ee_delete_payments', |
|
| 161 | + ), |
|
| 162 | + |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + protected function _set_page_config() |
|
| 168 | + { |
|
| 169 | + $this->_page_config = array( |
|
| 170 | + 'default' => array( |
|
| 171 | + 'nav' => array( |
|
| 172 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 173 | + 'order' => 10, |
|
| 174 | + ), |
|
| 175 | + 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 176 | + 'help_tabs' => array( |
|
| 177 | + 'transactions_overview_help_tab' => array( |
|
| 178 | + 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 179 | + 'filename' => 'transactions_overview', |
|
| 180 | + ), |
|
| 181 | + 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 182 | + 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 183 | + 'filename' => 'transactions_overview_table_column_headings', |
|
| 184 | + ), |
|
| 185 | + 'transactions_overview_views_filters_help_tab' => array( |
|
| 186 | + 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 187 | + 'filename' => 'transactions_overview_views_filters_search', |
|
| 188 | + ), |
|
| 189 | + ), |
|
| 190 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 191 | + /** |
|
| 192 | + * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 193 | + * may change in a later iteration so want to keep the code for then. |
|
| 194 | + */ |
|
| 195 | + //'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 196 | + 'require_nonce' => false, |
|
| 197 | + ), |
|
| 198 | + 'view_transaction' => array( |
|
| 199 | + 'nav' => array( |
|
| 200 | + 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 201 | + 'order' => 5, |
|
| 202 | + 'url' => isset($this->_req_data['TXN_ID']) |
|
| 203 | + ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
| 204 | + : $this->_admin_base_url, |
|
| 205 | + 'persistent' => false, |
|
| 206 | + ), |
|
| 207 | + 'help_tabs' => array( |
|
| 208 | + 'transactions_view_transaction_help_tab' => array( |
|
| 209 | + 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 210 | + 'filename' => 'transactions_view_transaction', |
|
| 211 | + ), |
|
| 212 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 213 | + 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 214 | + 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
| 215 | + ), |
|
| 216 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 217 | + 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 218 | + 'filename' => 'transactions_view_transaction_attendees_registered', |
|
| 219 | + ), |
|
| 220 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 221 | + 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 222 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
| 223 | + ), |
|
| 224 | + ), |
|
| 225 | + 'qtips' => array('Transaction_Details_Tips'), |
|
| 226 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 227 | + 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 228 | + |
|
| 229 | + 'require_nonce' => false, |
|
| 230 | + ), |
|
| 231 | + ); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * The below methods aren't used by this class currently |
|
| 237 | + */ |
|
| 238 | + protected function _add_screen_options() |
|
| 239 | + { |
|
| 240 | + //noop |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + protected function _add_feature_pointers() |
|
| 244 | + { |
|
| 245 | + //noop |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + public function admin_init() |
|
| 249 | + { |
|
| 250 | + // IF a registration was JUST added via the admin... |
|
| 251 | + if (isset( |
|
| 252 | + $this->_req_data['redirect_from'], |
|
| 253 | + $this->_req_data['EVT_ID'], |
|
| 254 | + $this->_req_data['event_name'] |
|
| 255 | + )) { |
|
| 256 | + // then set a cookie so that we can block any attempts to use |
|
| 257 | + // the back button as a way to enter another registration. |
|
| 258 | + setcookie( |
|
| 259 | + 'ee_registration_added', |
|
| 260 | + $this->_req_data['EVT_ID'], time() + WEEK_IN_SECONDS, '/' |
|
| 261 | + ); |
|
| 262 | + // and update the global |
|
| 263 | + $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 264 | + } |
|
| 265 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
| 266 | + '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.', |
|
| 267 | + 'event_espresso' |
|
| 268 | + ); |
|
| 269 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 270 | + 'An error occurred! Please refresh the page and try again.', |
|
| 271 | + 'event_espresso' |
|
| 272 | + ); |
|
| 273 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 274 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 275 | + EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 276 | + EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
| 277 | + 'This transaction has been overpaid ! Payments Total', |
|
| 278 | + 'event_espresso' |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + public function admin_notices() |
|
| 283 | + { |
|
| 284 | + //noop |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + public function admin_footer_scripts() |
|
| 288 | + { |
|
| 289 | + //noop |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * _set_transaction_status_array |
|
| 295 | + * sets list of transaction statuses |
|
| 296 | + * |
|
| 297 | + * @access private |
|
| 298 | + * @return void |
|
| 299 | + * @throws EE_Error |
|
| 300 | + * @throws InvalidArgumentException |
|
| 301 | + * @throws InvalidDataTypeException |
|
| 302 | + * @throws InvalidInterfaceException |
|
| 303 | + */ |
|
| 304 | + private function _set_transaction_status_array() |
|
| 305 | + { |
|
| 306 | + self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * get_transaction_status_array |
|
| 312 | + * return the transaction status array for wp_list_table |
|
| 313 | + * |
|
| 314 | + * @access public |
|
| 315 | + * @return array |
|
| 316 | + */ |
|
| 317 | + public function get_transaction_status_array() |
|
| 318 | + { |
|
| 319 | + return self::$_txn_status; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + /** |
|
| 324 | + * get list of payment statuses |
|
| 325 | + * |
|
| 326 | + * @access private |
|
| 327 | + * @return void |
|
| 328 | + * @throws EE_Error |
|
| 329 | + * @throws InvalidArgumentException |
|
| 330 | + * @throws InvalidDataTypeException |
|
| 331 | + * @throws InvalidInterfaceException |
|
| 332 | + */ |
|
| 333 | + private function _get_payment_status_array() |
|
| 334 | + { |
|
| 335 | + self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 336 | + $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 337 | + |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * _add_screen_options_default |
|
| 343 | + * |
|
| 344 | + * @access protected |
|
| 345 | + * @return void |
|
| 346 | + * @throws InvalidArgumentException |
|
| 347 | + * @throws InvalidDataTypeException |
|
| 348 | + * @throws InvalidInterfaceException |
|
| 349 | + */ |
|
| 350 | + protected function _add_screen_options_default() |
|
| 351 | + { |
|
| 352 | + $this->_per_page_screen_option(); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * load_scripts_styles |
|
| 358 | + * |
|
| 359 | + * @access public |
|
| 360 | + * @return void |
|
| 361 | + */ |
|
| 362 | + public function load_scripts_styles() |
|
| 363 | + { |
|
| 364 | + //enqueue style |
|
| 365 | + wp_register_style( |
|
| 366 | + 'espresso_txn', |
|
| 367 | + TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 368 | + array(), |
|
| 369 | + EVENT_ESPRESSO_VERSION |
|
| 370 | + ); |
|
| 371 | + wp_enqueue_style('espresso_txn'); |
|
| 372 | + //scripts |
|
| 373 | + wp_register_script('espresso_txn', TXN_ASSETS_URL . 'espresso_transactions_admin.js', array( |
|
| 374 | + 'ee_admin_js', |
|
| 375 | + 'ee-datepicker', |
|
| 376 | + 'jquery-ui-datepicker', |
|
| 377 | + 'jquery-ui-draggable', |
|
| 378 | + 'ee-dialog', |
|
| 379 | + 'ee-accounting', |
|
| 380 | + 'ee-serialize-full-array', |
|
| 381 | + ), EVENT_ESPRESSO_VERSION, true); |
|
| 382 | + wp_enqueue_script('espresso_txn'); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * load_scripts_styles_view_transaction |
|
| 388 | + * |
|
| 389 | + * @access public |
|
| 390 | + * @return void |
|
| 391 | + */ |
|
| 392 | + public function load_scripts_styles_view_transaction() |
|
| 393 | + { |
|
| 394 | + //styles |
|
| 395 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + |
|
| 399 | + /** |
|
| 400 | + * load_scripts_styles_default |
|
| 401 | + * |
|
| 402 | + * @access public |
|
| 403 | + * @return void |
|
| 404 | + */ |
|
| 405 | + public function load_scripts_styles_default() |
|
| 406 | + { |
|
| 407 | + //styles |
|
| 408 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * _set_list_table_views_default |
|
| 414 | + * |
|
| 415 | + * @access protected |
|
| 416 | + * @return void |
|
| 417 | + */ |
|
| 418 | + protected function _set_list_table_views_default() |
|
| 419 | + { |
|
| 420 | + $this->_views = array( |
|
| 421 | + 'all' => array( |
|
| 422 | + 'slug' => 'all', |
|
| 423 | + 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 424 | + 'count' => 0, |
|
| 425 | + ), |
|
| 426 | + 'abandoned' => array( |
|
| 427 | + 'slug' => 'abandoned', |
|
| 428 | + 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 429 | + 'count' => 0, |
|
| 430 | + ), |
|
| 431 | + 'failed' => array( |
|
| 432 | + 'slug' => 'failed', |
|
| 433 | + 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 434 | + 'count' => 0, |
|
| 435 | + ), |
|
| 436 | + ); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * _set_transaction_object |
|
| 442 | + * This sets the _transaction property for the transaction details screen |
|
| 443 | + * |
|
| 444 | + * @access private |
|
| 445 | + * @return void |
|
| 446 | + * @throws EE_Error |
|
| 447 | + * @throws InvalidArgumentException |
|
| 448 | + * @throws RuntimeException |
|
| 449 | + * @throws InvalidDataTypeException |
|
| 450 | + * @throws InvalidInterfaceException |
|
| 451 | + */ |
|
| 452 | + private function _set_transaction_object() |
|
| 453 | + { |
|
| 454 | + if ($this->_transaction instanceof EE_Transaction) { |
|
| 455 | + return; |
|
| 456 | + } //get out we've already set the object |
|
| 457 | + |
|
| 458 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
| 459 | + ? absint($this->_req_data['TXN_ID']) |
|
| 460 | + : false; |
|
| 461 | + |
|
| 462 | + //get transaction object |
|
| 463 | + $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 464 | + $this->_session = $this->_transaction instanceof EE_Transaction |
|
| 465 | + ? $this->_transaction->get('TXN_session_data') |
|
| 466 | + : null; |
|
| 467 | + $this->_transaction->verify_abandoned_transaction_status(); |
|
| 468 | + |
|
| 469 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 470 | + $error_msg = sprintf( |
|
| 471 | + esc_html__( |
|
| 472 | + 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
| 473 | + 'event_espresso' |
|
| 474 | + ), |
|
| 475 | + $TXN_ID |
|
| 476 | + ); |
|
| 477 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * _transaction_legend_items |
|
| 484 | + * |
|
| 485 | + * @access protected |
|
| 486 | + * @return array |
|
| 487 | + * @throws EE_Error |
|
| 488 | + * @throws InvalidArgumentException |
|
| 489 | + * @throws ReflectionException |
|
| 490 | + * @throws InvalidDataTypeException |
|
| 491 | + * @throws InvalidInterfaceException |
|
| 492 | + */ |
|
| 493 | + protected function _transaction_legend_items() |
|
| 494 | + { |
|
| 495 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 496 | + $items = array(); |
|
| 497 | + |
|
| 498 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 499 | + 'ee_read_global_messages', |
|
| 500 | + 'view_filtered_messages' |
|
| 501 | + )) { |
|
| 502 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 503 | + if (is_array($related_for_icon) |
|
| 504 | + && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
| 505 | + ) { |
|
| 506 | + $items['view_related_messages'] = array( |
|
| 507 | + 'class' => $related_for_icon['css_class'], |
|
| 508 | + 'desc' => $related_for_icon['label'], |
|
| 509 | + ); |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + $items = apply_filters( |
|
| 514 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 515 | + array_merge( |
|
| 516 | + $items, |
|
| 517 | + array( |
|
| 518 | + 'view_details' => array( |
|
| 519 | + 'class' => 'dashicons dashicons-cart', |
|
| 520 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 521 | + ), |
|
| 522 | + 'view_invoice' => array( |
|
| 523 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 524 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 525 | + ), |
|
| 526 | + 'view_receipt' => array( |
|
| 527 | + 'class' => 'dashicons dashicons-media-default', |
|
| 528 | + 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
| 529 | + ), |
|
| 530 | + 'view_registration' => array( |
|
| 531 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 532 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 533 | + ), |
|
| 534 | + 'payment_overview_link' => array( |
|
| 535 | + 'class' => 'dashicons dashicons-money', |
|
| 536 | + 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
| 537 | + ), |
|
| 538 | + ) |
|
| 539 | + ) |
|
| 540 | + ); |
|
| 541 | + |
|
| 542 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 543 | + 'ee_send_message', |
|
| 544 | + 'espresso_transactions_send_payment_reminder' |
|
| 545 | + )) { |
|
| 546 | + if (EEH_MSG_Template::is_mt_active('payment_reminder')) { |
|
| 547 | + $items['send_payment_reminder'] = array( |
|
| 548 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 549 | + 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
| 550 | + ); |
|
| 551 | + } else { |
|
| 552 | + $items['blank*'] = array( |
|
| 553 | + 'class' => '', |
|
| 554 | + 'desc' => '', |
|
| 555 | + ); |
|
| 556 | + } |
|
| 557 | + } else { |
|
| 558 | + $items['blank*'] = array( |
|
| 559 | + 'class' => '', |
|
| 560 | + 'desc' => '', |
|
| 561 | + ); |
|
| 562 | + } |
|
| 563 | + $more_items = apply_filters( |
|
| 564 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 565 | + array( |
|
| 566 | + 'overpaid' => array( |
|
| 567 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 568 | + 'desc' => EEH_Template::pretty_status( |
|
| 569 | + EEM_Transaction::overpaid_status_code, |
|
| 570 | + false, |
|
| 571 | + 'sentence' |
|
| 572 | + ), |
|
| 573 | + ), |
|
| 574 | + 'complete' => array( |
|
| 575 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 576 | + 'desc' => EEH_Template::pretty_status( |
|
| 577 | + EEM_Transaction::complete_status_code, |
|
| 578 | + false, |
|
| 579 | + 'sentence' |
|
| 580 | + ), |
|
| 581 | + ), |
|
| 582 | + 'incomplete' => array( |
|
| 583 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 584 | + 'desc' => EEH_Template::pretty_status( |
|
| 585 | + EEM_Transaction::incomplete_status_code, |
|
| 586 | + false, |
|
| 587 | + 'sentence' |
|
| 588 | + ), |
|
| 589 | + ), |
|
| 590 | + 'abandoned' => array( |
|
| 591 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 592 | + 'desc' => EEH_Template::pretty_status( |
|
| 593 | + EEM_Transaction::abandoned_status_code, |
|
| 594 | + false, |
|
| 595 | + 'sentence' |
|
| 596 | + ), |
|
| 597 | + ), |
|
| 598 | + 'failed' => array( |
|
| 599 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 600 | + 'desc' => EEH_Template::pretty_status( |
|
| 601 | + EEM_Transaction::failed_status_code, |
|
| 602 | + false, |
|
| 603 | + 'sentence' |
|
| 604 | + ), |
|
| 605 | + ), |
|
| 606 | + ) |
|
| 607 | + ); |
|
| 608 | + |
|
| 609 | + return array_merge($items, $more_items); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + |
|
| 613 | + /** |
|
| 614 | + * _transactions_overview_list_table |
|
| 615 | + * |
|
| 616 | + * @access protected |
|
| 617 | + * @return void |
|
| 618 | + * @throws DomainException |
|
| 619 | + * @throws EE_Error |
|
| 620 | + * @throws InvalidArgumentException |
|
| 621 | + * @throws InvalidDataTypeException |
|
| 622 | + * @throws InvalidInterfaceException |
|
| 623 | + * @throws ReflectionException |
|
| 624 | + */ |
|
| 625 | + protected function _transactions_overview_list_table() |
|
| 626 | + { |
|
| 627 | + $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 628 | + $event = isset($this->_req_data['EVT_ID']) |
|
| 629 | + ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
| 630 | + : null; |
|
| 631 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
| 632 | + ? sprintf( |
|
| 633 | + esc_html__( |
|
| 634 | + '%sViewing Transactions for the Event: %s%s', |
|
| 635 | + 'event_espresso' |
|
| 636 | + ), |
|
| 637 | + '<h3>', |
|
| 638 | + '<a href="' |
|
| 639 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
| 640 | + array('action' => 'edit', 'post' => $event->ID()), |
|
| 641 | + EVENTS_ADMIN_URL |
|
| 642 | + ) |
|
| 643 | + . '" title="' |
|
| 644 | + . esc_attr__( |
|
| 645 | + 'Click to Edit event', |
|
| 646 | + 'event_espresso' |
|
| 647 | + ) |
|
| 648 | + . '">' . $event->get('EVT_name') . '</a>', |
|
| 649 | + '</h3>' |
|
| 650 | + ) |
|
| 651 | + : ''; |
|
| 652 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 653 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * _transaction_details |
|
| 659 | + * generates HTML for the View Transaction Details Admin page |
|
| 660 | + * |
|
| 661 | + * @access protected |
|
| 662 | + * @return void |
|
| 663 | + * @throws DomainException |
|
| 664 | + * @throws EE_Error |
|
| 665 | + * @throws InvalidArgumentException |
|
| 666 | + * @throws InvalidDataTypeException |
|
| 667 | + * @throws InvalidInterfaceException |
|
| 668 | + * @throws RuntimeException |
|
| 669 | + */ |
|
| 670 | + protected function _transaction_details() |
|
| 671 | + { |
|
| 672 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 673 | + |
|
| 674 | + $this->_set_transaction_status_array(); |
|
| 675 | + |
|
| 676 | + $this->_template_args = array(); |
|
| 677 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 678 | + |
|
| 679 | + $this->_set_transaction_object(); |
|
| 680 | + |
|
| 681 | + $primary_registration = $this->_transaction->primary_registration(); |
|
| 682 | + $attendee = $primary_registration instanceof EE_Registration |
|
| 683 | + ? $primary_registration->attendee() |
|
| 684 | + : null; |
|
| 685 | + |
|
| 686 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 687 | + $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 688 | + |
|
| 689 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 690 | + $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 691 | + |
|
| 692 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->get('STS_ID')]; |
|
| 693 | + $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 694 | + $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->get('STS_ID'); |
|
| 695 | + |
|
| 696 | + $this->_template_args['grand_total'] = $this->_transaction->get('TXN_total'); |
|
| 697 | + $this->_template_args['total_paid'] = $this->_transaction->get('TXN_paid'); |
|
| 698 | + |
|
| 699 | + if ($attendee instanceof EE_Attendee |
|
| 700 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 701 | + 'ee_send_message', |
|
| 702 | + 'espresso_transactions_send_payment_reminder' |
|
| 703 | + ) |
|
| 704 | + ) { |
|
| 705 | + $this->_template_args['send_payment_reminder_button'] = |
|
| 706 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 707 | + && $this->_transaction->get('STS_ID') !== EEM_Transaction::complete_status_code |
|
| 708 | + && $this->_transaction->get('STS_ID') !== EEM_Transaction::overpaid_status_code |
|
| 709 | + ? EEH_Template::get_button_or_link( |
|
| 710 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 711 | + array( |
|
| 712 | + 'action' => 'send_payment_reminder', |
|
| 713 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 714 | + 'redirect_to' => 'view_transaction', |
|
| 715 | + ), |
|
| 716 | + TXN_ADMIN_URL |
|
| 717 | + ), |
|
| 718 | + __(' Send Payment Reminder', 'event_espresso'), |
|
| 719 | + 'button secondary-button right', |
|
| 720 | + 'dashicons dashicons-email-alt' |
|
| 721 | + ) |
|
| 722 | + : ''; |
|
| 723 | + } else { |
|
| 724 | + $this->_template_args['send_payment_reminder_button'] = ''; |
|
| 725 | + } |
|
| 726 | + |
|
| 727 | + $amount_due = $this->_transaction->get('TXN_total') - $this->_transaction->get('TXN_paid'); |
|
| 728 | + $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
| 729 | + $amount_due, |
|
| 730 | + true |
|
| 731 | + ); |
|
| 732 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 733 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
| 734 | + . $this->_template_args['amount_due']; |
|
| 735 | + } else { |
|
| 736 | + $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
| 737 | + } |
|
| 738 | + $this->_template_args['amount_due_class'] = ''; |
|
| 739 | + |
|
| 740 | + if ($this->_transaction->get('TXN_paid') == $this->_transaction->get('TXN_total')) { |
|
| 741 | + // paid in full |
|
| 742 | + $this->_template_args['amount_due'] = false; |
|
| 743 | + } elseif ($this->_transaction->get('TXN_paid') > $this->_transaction->get('TXN_total')) { |
|
| 744 | + // overpaid |
|
| 745 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 746 | + } elseif ($this->_transaction->get('TXN_total') > 0 |
|
| 747 | + && $this->_transaction->get('TXN_paid') > 0 |
|
| 748 | + ) { |
|
| 749 | + // monies owing |
|
| 750 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 751 | + } elseif ($this->_transaction->get('TXN_total') > 0 |
|
| 752 | + && $this->_transaction->get('TXN_paid') == 0 |
|
| 753 | + ) { |
|
| 754 | + // no payments made yet |
|
| 755 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 756 | + } elseif ($this->_transaction->get('TXN_total') == 0) { |
|
| 757 | + // free event |
|
| 758 | + $this->_template_args['amount_due'] = false; |
|
| 759 | + } |
|
| 760 | + |
|
| 761 | + $payment_method = $this->_transaction->payment_method(); |
|
| 762 | + |
|
| 763 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 764 | + ? $payment_method->admin_name() |
|
| 765 | + : esc_html__('Unknown', 'event_espresso'); |
|
| 766 | + |
|
| 767 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 768 | + // link back to overview |
|
| 769 | + $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
| 770 | + ? $_SERVER['HTTP_REFERER'] |
|
| 771 | + : TXN_ADMIN_URL; |
|
| 772 | + |
|
| 773 | + |
|
| 774 | + // next link |
|
| 775 | + $next_txn = $this->_transaction->next( |
|
| 776 | + null, |
|
| 777 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 778 | + 'TXN_ID' |
|
| 779 | + ); |
|
| 780 | + $this->_template_args['next_transaction'] = $next_txn |
|
| 781 | + ? $this->_next_link( |
|
| 782 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 783 | + array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 784 | + TXN_ADMIN_URL |
|
| 785 | + ), |
|
| 786 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 787 | + ) |
|
| 788 | + : ''; |
|
| 789 | + // previous link |
|
| 790 | + $previous_txn = $this->_transaction->previous( |
|
| 791 | + null, |
|
| 792 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 793 | + 'TXN_ID' |
|
| 794 | + ); |
|
| 795 | + $this->_template_args['previous_transaction'] = $previous_txn |
|
| 796 | + ? $this->_previous_link( |
|
| 797 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 798 | + array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 799 | + TXN_ADMIN_URL |
|
| 800 | + ), |
|
| 801 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 802 | + ) |
|
| 803 | + : ''; |
|
| 804 | + |
|
| 805 | + // were we just redirected here after adding a new registration ??? |
|
| 806 | + if (isset( |
|
| 807 | + $this->_req_data['redirect_from'], |
|
| 808 | + $this->_req_data['EVT_ID'], |
|
| 809 | + $this->_req_data['event_name'] |
|
| 810 | + )) { |
|
| 811 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 812 | + 'ee_edit_registrations', |
|
| 813 | + 'espresso_registrations_new_registration', |
|
| 814 | + $this->_req_data['EVT_ID'] |
|
| 815 | + )) { |
|
| 816 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 817 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 818 | + array( |
|
| 819 | + 'page' => 'espresso_registrations', |
|
| 820 | + 'action' => 'new_registration', |
|
| 821 | + 'return' => 'default', |
|
| 822 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 823 | + 'event_id' => $this->_req_data['EVT_ID'], |
|
| 824 | + ), |
|
| 825 | + REG_ADMIN_URL |
|
| 826 | + ); |
|
| 827 | + $this->_admin_page_title .= '">'; |
|
| 828 | + |
|
| 829 | + $this->_admin_page_title .= sprintf( |
|
| 830 | + esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 831 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 832 | + ); |
|
| 833 | + $this->_admin_page_title .= '</a>'; |
|
| 834 | + } |
|
| 835 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 836 | + } |
|
| 837 | + // grab messages at the last second |
|
| 838 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 839 | + // path to template |
|
| 840 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 841 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 842 | + $template_path, |
|
| 843 | + $this->_template_args, |
|
| 844 | + true |
|
| 845 | + ); |
|
| 846 | + |
|
| 847 | + // the details template wrapper |
|
| 848 | + $this->display_admin_page_with_sidebar(); |
|
| 849 | + |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * _transaction_details_metaboxes |
|
| 855 | + * |
|
| 856 | + * @access protected |
|
| 857 | + * @return void |
|
| 858 | + * @throws EE_Error |
|
| 859 | + * @throws InvalidArgumentException |
|
| 860 | + * @throws InvalidDataTypeException |
|
| 861 | + * @throws InvalidInterfaceException |
|
| 862 | + * @throws RuntimeException |
|
| 863 | + */ |
|
| 864 | + protected function _transaction_details_metaboxes() |
|
| 865 | + { |
|
| 866 | + |
|
| 867 | + $this->_set_transaction_object(); |
|
| 868 | + |
|
| 869 | + add_meta_box( |
|
| 870 | + 'edit-txn-details-mbox', |
|
| 871 | + esc_html__('Transaction Details', 'event_espresso'), |
|
| 872 | + array($this, 'txn_details_meta_box'), |
|
| 873 | + $this->_wp_page_slug, |
|
| 874 | + 'normal', |
|
| 875 | + 'high' |
|
| 876 | + ); |
|
| 877 | + add_meta_box( |
|
| 878 | + 'edit-txn-attendees-mbox', |
|
| 879 | + esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 880 | + array($this, 'txn_attendees_meta_box'), |
|
| 881 | + $this->_wp_page_slug, |
|
| 882 | + 'normal', |
|
| 883 | + 'high', |
|
| 884 | + array('TXN_ID' => $this->_transaction->ID()) |
|
| 885 | + ); |
|
| 886 | + add_meta_box( |
|
| 887 | + 'edit-txn-registrant-mbox', |
|
| 888 | + esc_html__('Primary Contact', 'event_espresso'), |
|
| 889 | + array($this, 'txn_registrant_side_meta_box'), |
|
| 890 | + $this->_wp_page_slug, |
|
| 891 | + 'side', |
|
| 892 | + 'high' |
|
| 893 | + ); |
|
| 894 | + add_meta_box( |
|
| 895 | + 'edit-txn-billing-info-mbox', |
|
| 896 | + esc_html__('Billing Information', 'event_espresso'), |
|
| 897 | + array($this, 'txn_billing_info_side_meta_box'), |
|
| 898 | + $this->_wp_page_slug, |
|
| 899 | + 'side', |
|
| 900 | + 'high' |
|
| 901 | + ); |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + |
|
| 905 | + /** |
|
| 906 | + * txn_details_meta_box |
|
| 907 | + * generates HTML for the Transaction main meta box |
|
| 908 | + * |
|
| 909 | + * @access public |
|
| 910 | + * @return void |
|
| 911 | + * @throws DomainException |
|
| 912 | + * @throws EE_Error |
|
| 913 | + * @throws InvalidArgumentException |
|
| 914 | + * @throws InvalidDataTypeException |
|
| 915 | + * @throws InvalidInterfaceException |
|
| 916 | + * @throws RuntimeException |
|
| 917 | + */ |
|
| 918 | + public function txn_details_meta_box() |
|
| 919 | + { |
|
| 920 | + |
|
| 921 | + $this->_set_transaction_object(); |
|
| 922 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 923 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 924 | + ? $this->_transaction->primary_registration()->attendee() |
|
| 925 | + : null; |
|
| 926 | + $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 927 | + 'ee_edit_payments', |
|
| 928 | + 'apply_payment_or_refund_from_registration_details' |
|
| 929 | + ); |
|
| 930 | + $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 931 | + 'ee_delete_payments', |
|
| 932 | + 'delete_payment_from_registration_details' |
|
| 933 | + ); |
|
| 934 | + |
|
| 935 | + //get line table |
|
| 936 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 937 | + $Line_Item_Display = new EE_Line_Item_Display( |
|
| 938 | + 'admin_table', |
|
| 939 | + 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
| 940 | + ); |
|
| 941 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
| 942 | + $this->_transaction->total_line_item() |
|
| 943 | + ); |
|
| 944 | + $this->_template_args['REG_code'] = $this->_transaction->get_first_related('Registration') |
|
| 945 | + ->get('REG_code'); |
|
| 946 | + |
|
| 947 | + // process taxes |
|
| 948 | + $taxes = $this->_transaction->get_many_related( |
|
| 949 | + 'Line_Item', |
|
| 950 | + array(array('LIN_type' => EEM_Line_Item::type_tax)) |
|
| 951 | + ); |
|
| 952 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 953 | + |
|
| 954 | + $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 955 | + $this->_transaction->get('TXN_total'), |
|
| 956 | + false, |
|
| 957 | + false |
|
| 958 | + ); |
|
| 959 | + $this->_template_args['grand_raw_total'] = $this->_transaction->get('TXN_total'); |
|
| 960 | + $this->_template_args['TXN_status'] = $this->_transaction->get('STS_ID'); |
|
| 961 | + |
|
| 962 | + // process payment details |
|
| 963 | + $payments = $this->_transaction->get_many_related('Payment'); |
|
| 964 | + if (! empty($payments)) { |
|
| 965 | + $this->_template_args['payments'] = $payments; |
|
| 966 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 967 | + } else { |
|
| 968 | + $this->_template_args['payments'] = false; |
|
| 969 | + $this->_template_args['existing_reg_payments'] = array(); |
|
| 970 | + } |
|
| 971 | + |
|
| 972 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 973 | + $this->_template_args['delete_payment_url'] = add_query_arg( |
|
| 974 | + array('action' => 'espresso_delete_payment'), |
|
| 975 | + TXN_ADMIN_URL |
|
| 976 | + ); |
|
| 977 | + |
|
| 978 | + if (isset($txn_details['invoice_number'])) { |
|
| 979 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 980 | + $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
| 981 | + 'Invoice Number', |
|
| 982 | + 'event_espresso' |
|
| 983 | + ); |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
| 987 | + ->get_first_related('Registration') |
|
| 988 | + ->get('REG_session'); |
|
| 989 | + $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
| 990 | + 'Registration Session', |
|
| 991 | + 'event_espresso' |
|
| 992 | + ); |
|
| 993 | + |
|
| 994 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
| 995 | + ? $this->_session['ip_address'] |
|
| 996 | + : ''; |
|
| 997 | + $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
| 998 | + 'Transaction placed from IP', |
|
| 999 | + 'event_espresso' |
|
| 1000 | + ); |
|
| 1001 | + |
|
| 1002 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
| 1003 | + ? $this->_session['user_agent'] |
|
| 1004 | + : ''; |
|
| 1005 | + $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
| 1006 | + 'Registrant User Agent', |
|
| 1007 | + 'event_espresso' |
|
| 1008 | + ); |
|
| 1009 | + |
|
| 1010 | + $reg_steps = '<ul>'; |
|
| 1011 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 1012 | + if ($reg_step_status === true) { |
|
| 1013 | + $reg_steps .= '<li style="color:#70cc50">' |
|
| 1014 | + . sprintf( |
|
| 1015 | + esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 1016 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1017 | + ) |
|
| 1018 | + . '</li>'; |
|
| 1019 | + } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 1020 | + $reg_steps .= '<li style="color:#2EA2CC">' |
|
| 1021 | + . sprintf( |
|
| 1022 | + esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 1023 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
| 1024 | + date( |
|
| 1025 | + get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1026 | + ($reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS)) |
|
| 1027 | + ) |
|
| 1028 | + ) |
|
| 1029 | + . '</li>'; |
|
| 1030 | + } else { |
|
| 1031 | + $reg_steps .= '<li style="color:#E76700">' |
|
| 1032 | + . sprintf( |
|
| 1033 | + esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
| 1034 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1035 | + ) |
|
| 1036 | + . '</li>'; |
|
| 1037 | + } |
|
| 1038 | + } |
|
| 1039 | + $reg_steps .= '</ul>'; |
|
| 1040 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 1041 | + $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
| 1042 | + 'Registration Step Progress', |
|
| 1043 | + 'event_espresso' |
|
| 1044 | + ); |
|
| 1045 | + |
|
| 1046 | + |
|
| 1047 | + $this->_get_registrations_to_apply_payment_to(); |
|
| 1048 | + $this->_get_payment_methods($payments); |
|
| 1049 | + $this->_get_payment_status_array(); |
|
| 1050 | + $this->_get_reg_status_selection(); //sets up the template args for the reg status array for the transaction. |
|
| 1051 | + |
|
| 1052 | + $this->_template_args['transaction_form_url'] = add_query_arg(array( |
|
| 1053 | + 'action' => 'edit_transaction', |
|
| 1054 | + 'process' => 'transaction', |
|
| 1055 | + ), TXN_ADMIN_URL); |
|
| 1056 | + $this->_template_args['apply_payment_form_url'] = add_query_arg(array( |
|
| 1057 | + 'page' => 'espresso_transactions', |
|
| 1058 | + 'action' => 'espresso_apply_payment', |
|
| 1059 | + ), WP_AJAX_URL); |
|
| 1060 | + $this->_template_args['delete_payment_form_url'] = add_query_arg(array( |
|
| 1061 | + 'page' => 'espresso_transactions', |
|
| 1062 | + 'action' => 'espresso_delete_payment', |
|
| 1063 | + ), WP_AJAX_URL); |
|
| 1064 | + |
|
| 1065 | + // 'espresso_delete_payment_nonce' |
|
| 1066 | + |
|
| 1067 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1068 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + |
|
| 1072 | + /** |
|
| 1073 | + * _get_registration_payment_IDs |
|
| 1074 | + * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 1075 | + * |
|
| 1076 | + * @access protected |
|
| 1077 | + * @param EE_Payment[] $payments |
|
| 1078 | + * @return array |
|
| 1079 | + * @throws EE_Error |
|
| 1080 | + * @throws InvalidArgumentException |
|
| 1081 | + * @throws InvalidDataTypeException |
|
| 1082 | + * @throws InvalidInterfaceException |
|
| 1083 | + */ |
|
| 1084 | + protected function _get_registration_payment_IDs($payments = array()) |
|
| 1085 | + { |
|
| 1086 | + $existing_reg_payments = array(); |
|
| 1087 | + // get all reg payments for these payments |
|
| 1088 | + $reg_payments = EEM_Registration_Payment::instance()->get_all(array( |
|
| 1089 | + array( |
|
| 1090 | + 'PAY_ID' => array( |
|
| 1091 | + 'IN', |
|
| 1092 | + array_keys($payments), |
|
| 1093 | + ), |
|
| 1094 | + ), |
|
| 1095 | + )); |
|
| 1096 | + if (! empty($reg_payments)) { |
|
| 1097 | + foreach ($payments as $payment) { |
|
| 1098 | + if (! $payment instanceof EE_Payment) { |
|
| 1099 | + continue; |
|
| 1100 | + } elseif (! isset($existing_reg_payments[$payment->ID()])) { |
|
| 1101 | + $existing_reg_payments[$payment->ID()] = array(); |
|
| 1102 | + } |
|
| 1103 | + foreach ($reg_payments as $reg_payment) { |
|
| 1104 | + if ($reg_payment instanceof EE_Registration_Payment |
|
| 1105 | + && $reg_payment->payment_ID() === $payment->ID() |
|
| 1106 | + ) { |
|
| 1107 | + $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 1108 | + } |
|
| 1109 | + } |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + return $existing_reg_payments; |
|
| 1114 | + } |
|
| 1115 | + |
|
| 1116 | + |
|
| 1117 | + /** |
|
| 1118 | + * _get_registrations_to_apply_payment_to |
|
| 1119 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 1120 | + * which allows the admin to only apply the payment to the specific registrations |
|
| 1121 | + * |
|
| 1122 | + * @access protected |
|
| 1123 | + * @return void |
|
| 1124 | + * @throws \EE_Error |
|
| 1125 | + */ |
|
| 1126 | + protected function _get_registrations_to_apply_payment_to() |
|
| 1127 | + { |
|
| 1128 | + // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 1129 | + $query_params = array( |
|
| 1130 | + array( |
|
| 1131 | + 'STS_ID' => array( |
|
| 1132 | + 'IN', |
|
| 1133 | + array( |
|
| 1134 | + EEM_Registration::status_id_approved, |
|
| 1135 | + EEM_Registration::status_id_pending_payment, |
|
| 1136 | + EEM_Registration::status_id_not_approved, |
|
| 1137 | + ), |
|
| 1138 | + ), |
|
| 1139 | + ), |
|
| 1140 | + ); |
|
| 1141 | + $registrations_to_apply_payment_to = EEH_HTML::br() |
|
| 1142 | + . EEH_HTML::div( |
|
| 1143 | + '', |
|
| 1144 | + 'txn-admin-apply-payment-to-registrations-dv', |
|
| 1145 | + '', |
|
| 1146 | + 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 1147 | + ); |
|
| 1148 | + $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1149 | + $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 1150 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 1151 | + EEH_HTML::tr( |
|
| 1152 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1153 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1154 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1155 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1156 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1157 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1158 | + EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 1159 | + ) |
|
| 1160 | + ); |
|
| 1161 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 1162 | + // get registrations for TXN |
|
| 1163 | + $registrations = $this->_transaction->registrations($query_params); |
|
| 1164 | + $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
| 1165 | + foreach ($registrations as $registration) { |
|
| 1166 | + if ($registration instanceof EE_Registration) { |
|
| 1167 | + $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 1168 | + ? $registration->attendee()->full_name() |
|
| 1169 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 1170 | + $owing = $registration->final_price() - $registration->paid(); |
|
| 1171 | + $taxable = $registration->ticket()->taxable() |
|
| 1172 | + ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1173 | + : ''; |
|
| 1174 | + $checked = empty($existing_reg_payments) || in_array($registration->ID(), $existing_reg_payments) |
|
| 1175 | + ? ' checked="checked"' |
|
| 1176 | + : ''; |
|
| 1177 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1178 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 1179 | + EEH_HTML::td($registration->ID()) . |
|
| 1180 | + EEH_HTML::td($attendee_name) . |
|
| 1181 | + EEH_HTML::td( |
|
| 1182 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1183 | + ) . |
|
| 1184 | + EEH_HTML::td($registration->event_name()) . |
|
| 1185 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1186 | + EEH_HTML::td(EEH_Template::format_currency($owing), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1187 | + EEH_HTML::td( |
|
| 1188 | + '<input type="checkbox" value="' . $registration->ID() |
|
| 1189 | + . '" name="txn_admin_payment[registrations]"' |
|
| 1190 | + . $checked . $disabled . '>', |
|
| 1191 | + '', |
|
| 1192 | + 'jst-cntr' |
|
| 1193 | + ), |
|
| 1194 | + 'apply-payment-registration-row-' . $registration->ID() |
|
| 1195 | + ); |
|
| 1196 | + } |
|
| 1197 | + } |
|
| 1198 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1199 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1200 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1201 | + $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1202 | + esc_html__( |
|
| 1203 | + '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.', |
|
| 1204 | + 'event_espresso' |
|
| 1205 | + ), |
|
| 1206 | + '', |
|
| 1207 | + 'clear description' |
|
| 1208 | + ); |
|
| 1209 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1210 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + |
|
| 1214 | + /** |
|
| 1215 | + * _get_reg_status_selection |
|
| 1216 | + * |
|
| 1217 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1218 | + * instead of events. |
|
| 1219 | + * @access protected |
|
| 1220 | + * @return void |
|
| 1221 | + * @throws EE_Error |
|
| 1222 | + */ |
|
| 1223 | + protected function _get_reg_status_selection() |
|
| 1224 | + { |
|
| 1225 | + //first get all possible statuses |
|
| 1226 | + $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1227 | + //let's add a "don't change" option. |
|
| 1228 | + $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1229 | + $status_array = array_merge($status_array, $statuses); |
|
| 1230 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1231 | + 'txn_reg_status_change[reg_status]', |
|
| 1232 | + $status_array, |
|
| 1233 | + 'NAN', |
|
| 1234 | + 'id="txn-admin-payment-reg-status-inp"', |
|
| 1235 | + 'txn-reg-status-change-reg-status' |
|
| 1236 | + ); |
|
| 1237 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1238 | + 'delete_txn_reg_status_change[reg_status]', |
|
| 1239 | + $status_array, |
|
| 1240 | + 'NAN', |
|
| 1241 | + 'delete-txn-admin-payment-reg-status-inp', |
|
| 1242 | + 'delete-txn-reg-status-change-reg-status' |
|
| 1243 | + ); |
|
| 1244 | + } |
|
| 1245 | + |
|
| 1246 | + |
|
| 1247 | + /** |
|
| 1248 | + * _get_payment_methods |
|
| 1249 | + * Gets all the payment methods available generally, or the ones that are already |
|
| 1250 | + * selected on these payments (in case their payment methods are no longer active). |
|
| 1251 | + * Has the side-effect of updating the template args' payment_methods item |
|
| 1252 | + * |
|
| 1253 | + * @access private |
|
| 1254 | + * @param EE_Payment[] to show on this page |
|
| 1255 | + * @return void |
|
| 1256 | + * @throws EE_Error |
|
| 1257 | + * @throws InvalidArgumentException |
|
| 1258 | + * @throws InvalidDataTypeException |
|
| 1259 | + * @throws InvalidInterfaceException |
|
| 1260 | + */ |
|
| 1261 | + private function _get_payment_methods($payments = array()) |
|
| 1262 | + { |
|
| 1263 | + $payment_methods_of_payments = array(); |
|
| 1264 | + foreach ($payments as $payment) { |
|
| 1265 | + if ($payment instanceof EE_Payment) { |
|
| 1266 | + $payment_methods_of_payments[] = $payment->get('PMD_ID'); |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + if ($payment_methods_of_payments) { |
|
| 1270 | + $query_args = array( |
|
| 1271 | + array( |
|
| 1272 | + 'OR*payment_method_for_payment' => array( |
|
| 1273 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1274 | + 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1275 | + ), |
|
| 1276 | + ), |
|
| 1277 | + ); |
|
| 1278 | + } else { |
|
| 1279 | + $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1280 | + } |
|
| 1281 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + |
|
| 1285 | + /** |
|
| 1286 | + * txn_attendees_meta_box |
|
| 1287 | + * generates HTML for the Attendees Transaction main meta box |
|
| 1288 | + * |
|
| 1289 | + * @access public |
|
| 1290 | + * @param WP_Post $post |
|
| 1291 | + * @param array $metabox |
|
| 1292 | + * @return void |
|
| 1293 | + * @throws DomainException |
|
| 1294 | + * @throws EE_Error |
|
| 1295 | + */ |
|
| 1296 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1297 | + { |
|
| 1298 | + |
|
| 1299 | + /** @noinspection NonSecureExtractUsageInspection */ |
|
| 1300 | + extract($metabox['args']); |
|
| 1301 | + $this->_template_args['post'] = $post; |
|
| 1302 | + $this->_template_args['event_attendees'] = array(); |
|
| 1303 | + // process items in cart |
|
| 1304 | + $line_items = $this->_transaction->get_many_related( |
|
| 1305 | + 'Line_Item', |
|
| 1306 | + array(array('LIN_type' => 'line-item')) |
|
| 1307 | + ); |
|
| 1308 | + if (! empty($line_items)) { |
|
| 1309 | + foreach ($line_items as $item) { |
|
| 1310 | + if ($item instanceof EE_Line_Item) { |
|
| 1311 | + switch ($item->OBJ_type()) { |
|
| 1312 | + case 'Event': |
|
| 1313 | + break; |
|
| 1314 | + case 'Ticket': |
|
| 1315 | + $ticket = $item->ticket(); |
|
| 1316 | + //right now we're only handling tickets here. |
|
| 1317 | + //Cause its expected that only tickets will have attendees right? |
|
| 1318 | + if (! $ticket instanceof EE_Ticket) { |
|
| 1319 | + continue; |
|
| 1320 | + } |
|
| 1321 | + try { |
|
| 1322 | + $event_name = $ticket->get_event_name(); |
|
| 1323 | + } catch (Exception $e) { |
|
| 1324 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1325 | + $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1326 | + } |
|
| 1327 | + $event_name .= ' - ' . $item->get('LIN_name'); |
|
| 1328 | + $ticket_price = EEH_Template::format_currency($item->get('LIN_unit_price')); |
|
| 1329 | + // now get all of the registrations for this transaction that use this ticket |
|
| 1330 | + $registrations = $ticket->get_many_related( |
|
| 1331 | + 'Registration', |
|
| 1332 | + array(array('TXN_ID' => $this->_transaction->ID())) |
|
| 1333 | + ); |
|
| 1334 | + foreach ($registrations as $registration) { |
|
| 1335 | + if (! $registration instanceof EE_Registration) { |
|
| 1336 | + continue; |
|
| 1337 | + } |
|
| 1338 | + $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] |
|
| 1339 | + = $registration->status_ID(); |
|
| 1340 | + $this->_template_args['event_attendees'][$registration->ID()]['att_num'] |
|
| 1341 | + = $registration->count(); |
|
| 1342 | + $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] |
|
| 1343 | + = $event_name; |
|
| 1344 | + $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] |
|
| 1345 | + = $ticket_price; |
|
| 1346 | + // attendee info |
|
| 1347 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 1348 | + if ($attendee instanceof EE_Attendee) { |
|
| 1349 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] |
|
| 1350 | + = $attendee->ID(); |
|
| 1351 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] |
|
| 1352 | + = $attendee->full_name(); |
|
| 1353 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] |
|
| 1354 | + = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1355 | + . esc_html__( |
|
| 1356 | + ' Event', |
|
| 1357 | + 'event_espresso' |
|
| 1358 | + ) |
|
| 1359 | + . '">' . $attendee->email() . '</a>'; |
|
| 1360 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] |
|
| 1361 | + = EEH_Address::format($attendee, 'inline', false, false); |
|
| 1362 | + } else { |
|
| 1363 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
| 1364 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
| 1365 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 1366 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
| 1367 | + } |
|
| 1368 | + } |
|
| 1369 | + break; |
|
| 1370 | + |
|
| 1371 | + } |
|
| 1372 | + } |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1376 | + array( |
|
| 1377 | + 'action' => 'edit_transaction', |
|
| 1378 | + 'process' => 'attendees', |
|
| 1379 | + ), |
|
| 1380 | + TXN_ADMIN_URL |
|
| 1381 | + ); |
|
| 1382 | + echo EEH_Template::display_template( |
|
| 1383 | + TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1384 | + $this->_template_args, |
|
| 1385 | + true |
|
| 1386 | + ); |
|
| 1387 | + |
|
| 1388 | + } else { |
|
| 1389 | + echo sprintf( |
|
| 1390 | + esc_html__( |
|
| 1391 | + '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1392 | + 'event_espresso' |
|
| 1393 | + ), |
|
| 1394 | + '<p class="important-notice">', |
|
| 1395 | + '</p>' |
|
| 1396 | + ); |
|
| 1397 | + } |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + |
|
| 1401 | + /** |
|
| 1402 | + * txn_registrant_side_meta_box |
|
| 1403 | + * generates HTML for the Edit Transaction side meta box |
|
| 1404 | + * |
|
| 1405 | + * @access public |
|
| 1406 | + * @return void |
|
| 1407 | + * @throws DomainException |
|
| 1408 | + * @throws EE_Error |
|
| 1409 | + * @throws InvalidArgumentException |
|
| 1410 | + * @throws InvalidDataTypeException |
|
| 1411 | + * @throws InvalidInterfaceException |
|
| 1412 | + */ |
|
| 1413 | + public function txn_registrant_side_meta_box() |
|
| 1414 | + { |
|
| 1415 | + $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1416 | + ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
| 1417 | + : null; |
|
| 1418 | + if (! $primary_att instanceof EE_Attendee) { |
|
| 1419 | + $this->_template_args['no_attendee_message'] = esc_html__( |
|
| 1420 | + 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1421 | + 'event_espresso' |
|
| 1422 | + ); |
|
| 1423 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1424 | + } |
|
| 1425 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1426 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1427 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1428 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1429 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1430 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce(array( |
|
| 1431 | + 'action' => 'edit_attendee', |
|
| 1432 | + 'post' => $primary_att->ID(), |
|
| 1433 | + ), REG_ADMIN_URL); |
|
| 1434 | + // get formatted address for registrant |
|
| 1435 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1436 | + echo EEH_Template::display_template( |
|
| 1437 | + TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1438 | + $this->_template_args, |
|
| 1439 | + true |
|
| 1440 | + ); |
|
| 1441 | + } |
|
| 1442 | + |
|
| 1443 | + |
|
| 1444 | + /** |
|
| 1445 | + * txn_billing_info_side_meta_box |
|
| 1446 | + * generates HTML for the Edit Transaction side meta box |
|
| 1447 | + * |
|
| 1448 | + * @access public |
|
| 1449 | + * @return void |
|
| 1450 | + * @throws DomainException |
|
| 1451 | + * @throws EE_Error |
|
| 1452 | + */ |
|
| 1453 | + public function txn_billing_info_side_meta_box() |
|
| 1454 | + { |
|
| 1455 | + |
|
| 1456 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1457 | + $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1458 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1459 | + TXN_ADMIN_URL |
|
| 1460 | + ); |
|
| 1461 | + |
|
| 1462 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1463 | + echo EEH_Template::display_template($template_path, $this->_template_args, true);/**/ |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + |
|
| 1467 | + /** |
|
| 1468 | + * apply_payments_or_refunds |
|
| 1469 | + * registers a payment or refund made towards a transaction |
|
| 1470 | + * |
|
| 1471 | + * @access public |
|
| 1472 | + * @return void |
|
| 1473 | + * @throws EE_Error |
|
| 1474 | + * @throws InvalidArgumentException |
|
| 1475 | + * @throws ReflectionException |
|
| 1476 | + * @throws RuntimeException |
|
| 1477 | + * @throws InvalidDataTypeException |
|
| 1478 | + * @throws InvalidInterfaceException |
|
| 1479 | + */ |
|
| 1480 | + public function apply_payments_or_refunds() |
|
| 1481 | + { |
|
| 1482 | + $json_response_data = array('return_data' => false); |
|
| 1483 | + $valid_data = $this->_validate_payment_request_data(); |
|
| 1484 | + $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
| 1485 | + 'ee_edit_payments', |
|
| 1486 | + 'apply_payment_or_refund_from_registration_details' |
|
| 1487 | + ); |
|
| 1488 | + if (! empty($valid_data) && $has_access) { |
|
| 1489 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1490 | + //save the new payment |
|
| 1491 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1492 | + // get the TXN for this payment |
|
| 1493 | + $transaction = $payment->transaction(); |
|
| 1494 | + // verify transaction |
|
| 1495 | + if ($transaction instanceof EE_Transaction) { |
|
| 1496 | + // calculate_total_payments_and_update_status |
|
| 1497 | + $this->_process_transaction_payments($transaction); |
|
| 1498 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1499 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1500 | + // apply payment to registrations (if applicable) |
|
| 1501 | + if (! empty($REG_IDs)) { |
|
| 1502 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1503 | + $this->_maybe_send_notifications(); |
|
| 1504 | + // now process status changes for the same registrations |
|
| 1505 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1506 | + } |
|
| 1507 | + $this->_maybe_send_notifications($payment); |
|
| 1508 | + //prepare to render page |
|
| 1509 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1510 | + do_action( |
|
| 1511 | + 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
| 1512 | + $transaction, |
|
| 1513 | + $payment |
|
| 1514 | + ); |
|
| 1515 | + } else { |
|
| 1516 | + EE_Error::add_error( |
|
| 1517 | + esc_html__( |
|
| 1518 | + 'A valid Transaction for this payment could not be retrieved.', |
|
| 1519 | + 'event_espresso' |
|
| 1520 | + ), |
|
| 1521 | + __FILE__, |
|
| 1522 | + __FUNCTION__, |
|
| 1523 | + __LINE__ |
|
| 1524 | + ); |
|
| 1525 | + } |
|
| 1526 | + } else { |
|
| 1527 | + if ($has_access) { |
|
| 1528 | + EE_Error::add_error( |
|
| 1529 | + esc_html__( |
|
| 1530 | + 'The payment form data could not be processed. Please try again.', |
|
| 1531 | + 'event_espresso' |
|
| 1532 | + ), |
|
| 1533 | + __FILE__, |
|
| 1534 | + __FUNCTION__, |
|
| 1535 | + __LINE__ |
|
| 1536 | + ); |
|
| 1537 | + } else { |
|
| 1538 | + EE_Error::add_error( |
|
| 1539 | + esc_html__( |
|
| 1540 | + 'You do not have access to apply payments or refunds to a registration.', |
|
| 1541 | + 'event_espresso' |
|
| 1542 | + ), |
|
| 1543 | + __FILE__, |
|
| 1544 | + __FUNCTION__, |
|
| 1545 | + __LINE__ |
|
| 1546 | + ); |
|
| 1547 | + } |
|
| 1548 | + } |
|
| 1549 | + $notices = EE_Error::get_notices( |
|
| 1550 | + false, |
|
| 1551 | + false, |
|
| 1552 | + false |
|
| 1553 | + ); |
|
| 1554 | + $this->_template_args = array( |
|
| 1555 | + 'data' => $json_response_data, |
|
| 1556 | + 'error' => $notices['errors'], |
|
| 1557 | + 'success' => $notices['success'], |
|
| 1558 | + ); |
|
| 1559 | + $this->_return_json(); |
|
| 1560 | + } |
|
| 1561 | + |
|
| 1562 | + |
|
| 1563 | + /** |
|
| 1564 | + * _validate_payment_request_data |
|
| 1565 | + * |
|
| 1566 | + * @return array |
|
| 1567 | + */ |
|
| 1568 | + protected function _validate_payment_request_data() |
|
| 1569 | + { |
|
| 1570 | + if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1571 | + return false; |
|
| 1572 | + } |
|
| 1573 | + $payment_form = $this->_generate_payment_form_section(); |
|
| 1574 | + try { |
|
| 1575 | + if ($payment_form->was_submitted()) { |
|
| 1576 | + $payment_form->receive_form_submission(); |
|
| 1577 | + if (! $payment_form->is_valid()) { |
|
| 1578 | + $submission_error_messages = array(); |
|
| 1579 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1580 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1581 | + $submission_error_messages[] = sprintf( |
|
| 1582 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1583 | + $validation_error->get_form_section()->html_label_text(), |
|
| 1584 | + $validation_error->getMessage() |
|
| 1585 | + ); |
|
| 1586 | + } |
|
| 1587 | + } |
|
| 1588 | + EE_Error::add_error( |
|
| 1589 | + implode('<br />', $submission_error_messages), |
|
| 1590 | + __FILE__, |
|
| 1591 | + __FUNCTION__, |
|
| 1592 | + __LINE__ |
|
| 1593 | + ); |
|
| 1594 | + |
|
| 1595 | + return array(); |
|
| 1596 | + } |
|
| 1597 | + } |
|
| 1598 | + } catch (EE_Error $e) { |
|
| 1599 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1600 | + |
|
| 1601 | + return array(); |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + return $payment_form->valid_data(); |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + |
|
| 1608 | + /** |
|
| 1609 | + * _generate_payment_form_section |
|
| 1610 | + * |
|
| 1611 | + * @return EE_Form_Section_Proper |
|
| 1612 | + */ |
|
| 1613 | + protected function _generate_payment_form_section() |
|
| 1614 | + { |
|
| 1615 | + return new EE_Form_Section_Proper( |
|
| 1616 | + array( |
|
| 1617 | + 'name' => 'txn_admin_payment', |
|
| 1618 | + 'subsections' => array( |
|
| 1619 | + 'PAY_ID' => new EE_Text_Input( |
|
| 1620 | + array( |
|
| 1621 | + 'default' => 0, |
|
| 1622 | + 'required' => false, |
|
| 1623 | + 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1624 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1625 | + ) |
|
| 1626 | + ), |
|
| 1627 | + 'TXN_ID' => new EE_Text_Input( |
|
| 1628 | + array( |
|
| 1629 | + 'default' => 0, |
|
| 1630 | + 'required' => true, |
|
| 1631 | + 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1632 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1633 | + ) |
|
| 1634 | + ), |
|
| 1635 | + 'type' => new EE_Text_Input( |
|
| 1636 | + array( |
|
| 1637 | + 'default' => 1, |
|
| 1638 | + 'required' => true, |
|
| 1639 | + 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1640 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1641 | + ) |
|
| 1642 | + ), |
|
| 1643 | + 'amount' => new EE_Text_Input( |
|
| 1644 | + array( |
|
| 1645 | + 'default' => 0, |
|
| 1646 | + 'required' => true, |
|
| 1647 | + 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1648 | + 'validation_strategies' => array(new EE_Float_Normalization()), |
|
| 1649 | + ) |
|
| 1650 | + ), |
|
| 1651 | + 'status' => new EE_Text_Input( |
|
| 1652 | + array( |
|
| 1653 | + 'default' => EEM_Payment::status_id_approved, |
|
| 1654 | + 'required' => true, |
|
| 1655 | + 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1656 | + ) |
|
| 1657 | + ), |
|
| 1658 | + 'PMD_ID' => new EE_Text_Input( |
|
| 1659 | + array( |
|
| 1660 | + 'default' => 2, |
|
| 1661 | + 'required' => true, |
|
| 1662 | + 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1663 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1664 | + ) |
|
| 1665 | + ), |
|
| 1666 | + 'date' => new EE_Text_Input( |
|
| 1667 | + array( |
|
| 1668 | + 'default' => time(), |
|
| 1669 | + 'required' => true, |
|
| 1670 | + 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1671 | + ) |
|
| 1672 | + ), |
|
| 1673 | + 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1674 | + array( |
|
| 1675 | + 'default' => '', |
|
| 1676 | + 'required' => false, |
|
| 1677 | + 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1678 | + 'validation_strategies' => array( |
|
| 1679 | + new EE_Max_Length_Validation_Strategy( |
|
| 1680 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1681 | + 100 |
|
| 1682 | + ), |
|
| 1683 | + ), |
|
| 1684 | + ) |
|
| 1685 | + ), |
|
| 1686 | + 'po_number' => new EE_Text_Input( |
|
| 1687 | + array( |
|
| 1688 | + 'default' => '', |
|
| 1689 | + 'required' => false, |
|
| 1690 | + 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1691 | + 'validation_strategies' => array( |
|
| 1692 | + new EE_Max_Length_Validation_Strategy( |
|
| 1693 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1694 | + 100 |
|
| 1695 | + ), |
|
| 1696 | + ), |
|
| 1697 | + ) |
|
| 1698 | + ), |
|
| 1699 | + 'accounting' => new EE_Text_Input( |
|
| 1700 | + array( |
|
| 1701 | + 'default' => '', |
|
| 1702 | + 'required' => false, |
|
| 1703 | + 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1704 | + 'validation_strategies' => array( |
|
| 1705 | + new EE_Max_Length_Validation_Strategy( |
|
| 1706 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1707 | + 100 |
|
| 1708 | + ), |
|
| 1709 | + ), |
|
| 1710 | + ) |
|
| 1711 | + ), |
|
| 1712 | + ), |
|
| 1713 | + ) |
|
| 1714 | + ); |
|
| 1715 | + } |
|
| 1716 | + |
|
| 1717 | + |
|
| 1718 | + /** |
|
| 1719 | + * _create_payment_from_request_data |
|
| 1720 | + * |
|
| 1721 | + * @param array $valid_data |
|
| 1722 | + * @return EE_Payment |
|
| 1723 | + * @throws EE_Error |
|
| 1724 | + */ |
|
| 1725 | + protected function _create_payment_from_request_data($valid_data) |
|
| 1726 | + { |
|
| 1727 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1728 | + // get payment amount |
|
| 1729 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1730 | + // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1731 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1732 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1733 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1734 | + $date = $valid_data['date'] |
|
| 1735 | + ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
| 1736 | + : date('Y-m-d g:i a', current_time('timestamp')); |
|
| 1737 | + $payment = EE_Payment::new_instance( |
|
| 1738 | + array( |
|
| 1739 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1740 | + 'STS_ID' => $valid_data['status'], |
|
| 1741 | + 'PAY_timestamp' => $date, |
|
| 1742 | + 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1743 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1744 | + 'PAY_amount' => $amount, |
|
| 1745 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1746 | + 'PAY_po_number' => $valid_data['po_number'], |
|
| 1747 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1748 | + 'PAY_details' => $valid_data, |
|
| 1749 | + 'PAY_ID' => $PAY_ID, |
|
| 1750 | + ), |
|
| 1751 | + '', |
|
| 1752 | + array('Y-m-d', 'g:i a') |
|
| 1753 | + ); |
|
| 1754 | + |
|
| 1755 | + if (! $payment->save()) { |
|
| 1756 | + EE_Error::add_error( |
|
| 1757 | + sprintf( |
|
| 1758 | + esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1759 | + $payment->ID() |
|
| 1760 | + ), |
|
| 1761 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 1762 | + ); |
|
| 1763 | + } |
|
| 1764 | + |
|
| 1765 | + return $payment; |
|
| 1766 | + } |
|
| 1767 | + |
|
| 1768 | + |
|
| 1769 | + /** |
|
| 1770 | + * _process_transaction_payments |
|
| 1771 | + * |
|
| 1772 | + * @param \EE_Transaction $transaction |
|
| 1773 | + * @return void |
|
| 1774 | + * @throws EE_Error |
|
| 1775 | + * @throws InvalidArgumentException |
|
| 1776 | + * @throws ReflectionException |
|
| 1777 | + * @throws InvalidDataTypeException |
|
| 1778 | + * @throws InvalidInterfaceException |
|
| 1779 | + */ |
|
| 1780 | + protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1781 | + { |
|
| 1782 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1783 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1784 | + //update the transaction with this payment |
|
| 1785 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1786 | + EE_Error::add_success(esc_html__( |
|
| 1787 | + 'The payment has been processed successfully.', 'event_espresso'), |
|
| 1788 | + __FILE__, |
|
| 1789 | + __FUNCTION__, |
|
| 1790 | + __LINE__ |
|
| 1791 | + ); |
|
| 1792 | + } else { |
|
| 1793 | + EE_Error::add_error( |
|
| 1794 | + esc_html__( |
|
| 1795 | + 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1796 | + 'event_espresso' |
|
| 1797 | + ) |
|
| 1798 | + , |
|
| 1799 | + __FILE__, |
|
| 1800 | + __FUNCTION__, |
|
| 1801 | + __LINE__ |
|
| 1802 | + ); |
|
| 1803 | + } |
|
| 1804 | + } |
|
| 1805 | + |
|
| 1806 | + |
|
| 1807 | + /** |
|
| 1808 | + * _get_REG_IDs_to_apply_payment_to |
|
| 1809 | + * returns a list of registration IDs that the payment will apply to |
|
| 1810 | + * |
|
| 1811 | + * @param \EE_Payment $payment |
|
| 1812 | + * @return array |
|
| 1813 | + * @throws EE_Error |
|
| 1814 | + */ |
|
| 1815 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1816 | + { |
|
| 1817 | + $REG_IDs = array(); |
|
| 1818 | + // grab array of IDs for specific registrations to apply changes to |
|
| 1819 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1820 | + $REG_IDs = (array)$this->_req_data['txn_admin_payment']['registrations']; |
|
| 1821 | + } |
|
| 1822 | + //nothing specified ? then get all reg IDs |
|
| 1823 | + if (empty($REG_IDs)) { |
|
| 1824 | + $registrations = $payment->transaction()->registrations(); |
|
| 1825 | + $REG_IDs = ! empty($registrations) |
|
| 1826 | + ? array_keys($registrations) |
|
| 1827 | + : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1828 | + } |
|
| 1829 | + |
|
| 1830 | + // ensure that REG_IDs are integers and NOT strings |
|
| 1831 | + return array_map('intval', $REG_IDs); |
|
| 1832 | + } |
|
| 1833 | + |
|
| 1834 | + |
|
| 1835 | + /** |
|
| 1836 | + * @return array |
|
| 1837 | + */ |
|
| 1838 | + public function existing_reg_payment_REG_IDs() |
|
| 1839 | + { |
|
| 1840 | + return $this->_existing_reg_payment_REG_IDs; |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + |
|
| 1844 | + /** |
|
| 1845 | + * @param array $existing_reg_payment_REG_IDs |
|
| 1846 | + */ |
|
| 1847 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1848 | + { |
|
| 1849 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1850 | + } |
|
| 1851 | + |
|
| 1852 | + |
|
| 1853 | + /** |
|
| 1854 | + * _get_existing_reg_payment_REG_IDs |
|
| 1855 | + * returns a list of registration IDs that the payment is currently related to |
|
| 1856 | + * as recorded in the database |
|
| 1857 | + * |
|
| 1858 | + * @param \EE_Payment $payment |
|
| 1859 | + * @return array |
|
| 1860 | + * @throws EE_Error |
|
| 1861 | + */ |
|
| 1862 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 1863 | + { |
|
| 1864 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 1865 | + // let's get any existing reg payment records for this payment |
|
| 1866 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 1867 | + // but we only want the REG IDs, so grab the array keys |
|
| 1868 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
| 1869 | + ? array_keys($existing_reg_payment_REG_IDs) |
|
| 1870 | + : array(); |
|
| 1871 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 1872 | + } |
|
| 1873 | + |
|
| 1874 | + return $this->existing_reg_payment_REG_IDs(); |
|
| 1875 | + } |
|
| 1876 | + |
|
| 1877 | + |
|
| 1878 | + /** |
|
| 1879 | + * _remove_existing_registration_payments |
|
| 1880 | + * this calculates the difference between existing relations |
|
| 1881 | + * to the supplied payment and the new list registration IDs, |
|
| 1882 | + * removes any related registrations that no longer apply, |
|
| 1883 | + * and then updates the registration paid fields |
|
| 1884 | + * |
|
| 1885 | + * @param \EE_Payment $payment |
|
| 1886 | + * @param int $PAY_ID |
|
| 1887 | + * @return bool; |
|
| 1888 | + * @throws EE_Error |
|
| 1889 | + * @throws InvalidArgumentException |
|
| 1890 | + * @throws ReflectionException |
|
| 1891 | + * @throws InvalidDataTypeException |
|
| 1892 | + * @throws InvalidInterfaceException |
|
| 1893 | + */ |
|
| 1894 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 1895 | + { |
|
| 1896 | + // newly created payments will have nothing recorded for $PAY_ID |
|
| 1897 | + if ($PAY_ID == 0) { |
|
| 1898 | + return false; |
|
| 1899 | + } |
|
| 1900 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1901 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
| 1902 | + return false; |
|
| 1903 | + } |
|
| 1904 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1905 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1906 | + |
|
| 1907 | + return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 1908 | + $payment, |
|
| 1909 | + array( |
|
| 1910 | + array( |
|
| 1911 | + 'PAY_ID' => $payment->ID(), |
|
| 1912 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 1913 | + ), |
|
| 1914 | + ) |
|
| 1915 | + ); |
|
| 1916 | + } |
|
| 1917 | + |
|
| 1918 | + |
|
| 1919 | + /** |
|
| 1920 | + * _update_registration_payments |
|
| 1921 | + * this applies the payments to the selected registrations |
|
| 1922 | + * but only if they have not already been paid for |
|
| 1923 | + * |
|
| 1924 | + * @param EE_Transaction $transaction |
|
| 1925 | + * @param \EE_Payment $payment |
|
| 1926 | + * @param array $REG_IDs |
|
| 1927 | + * @return void |
|
| 1928 | + * @throws EE_Error |
|
| 1929 | + * @throws InvalidArgumentException |
|
| 1930 | + * @throws ReflectionException |
|
| 1931 | + * @throws RuntimeException |
|
| 1932 | + * @throws InvalidDataTypeException |
|
| 1933 | + * @throws InvalidInterfaceException |
|
| 1934 | + */ |
|
| 1935 | + protected function _update_registration_payments( |
|
| 1936 | + EE_Transaction $transaction, |
|
| 1937 | + EE_Payment $payment, |
|
| 1938 | + $REG_IDs = array() |
|
| 1939 | + ) { |
|
| 1940 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 1941 | + // so let's do that using our set of REG_IDs from the form |
|
| 1942 | + $registration_query_where_params = array( |
|
| 1943 | + 'REG_ID' => array('IN', $REG_IDs), |
|
| 1944 | + ); |
|
| 1945 | + // but add in some conditions regarding payment, |
|
| 1946 | + // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 1947 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 1948 | + if (! $payment->is_a_refund()) { |
|
| 1949 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 1950 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 1951 | + } |
|
| 1952 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 1953 | + if (! empty($registrations)) { |
|
| 1954 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 1955 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 1956 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 1957 | + } |
|
| 1958 | + } |
|
| 1959 | + |
|
| 1960 | + |
|
| 1961 | + /** |
|
| 1962 | + * _process_registration_status_change |
|
| 1963 | + * This processes requested registration status changes for all the registrations |
|
| 1964 | + * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 1965 | + * |
|
| 1966 | + * @param EE_Transaction $transaction |
|
| 1967 | + * @param array $REG_IDs |
|
| 1968 | + * @return bool |
|
| 1969 | + * @throws EE_Error |
|
| 1970 | + * @throws InvalidArgumentException |
|
| 1971 | + * @throws ReflectionException |
|
| 1972 | + * @throws InvalidDataTypeException |
|
| 1973 | + * @throws InvalidInterfaceException |
|
| 1974 | + */ |
|
| 1975 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 1976 | + { |
|
| 1977 | + // first if there is no change in status then we get out. |
|
| 1978 | + if ( |
|
| 1979 | + ! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 1980 | + || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
| 1981 | + ) { |
|
| 1982 | + //no error message, no change requested, just nothing to do man. |
|
| 1983 | + return false; |
|
| 1984 | + } |
|
| 1985 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1986 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1987 | + |
|
| 1988 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 1989 | + return $transaction_processor->manually_update_registration_statuses( |
|
| 1990 | + $transaction, |
|
| 1991 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 1992 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 1993 | + ); |
|
| 1994 | + } |
|
| 1995 | + |
|
| 1996 | + |
|
| 1997 | + /** |
|
| 1998 | + * _build_payment_json_response |
|
| 1999 | + * |
|
| 2000 | + * @access public |
|
| 2001 | + * @param \EE_Payment $payment |
|
| 2002 | + * @param array $REG_IDs |
|
| 2003 | + * @param bool | null $delete_txn_reg_status_change |
|
| 2004 | + * @return array |
|
| 2005 | + * @throws EE_Error |
|
| 2006 | + * @throws InvalidArgumentException |
|
| 2007 | + * @throws InvalidDataTypeException |
|
| 2008 | + * @throws InvalidInterfaceException |
|
| 2009 | + */ |
|
| 2010 | + protected function _build_payment_json_response( |
|
| 2011 | + EE_Payment $payment, |
|
| 2012 | + $REG_IDs = array(), |
|
| 2013 | + $delete_txn_reg_status_change = null |
|
| 2014 | + ) { |
|
| 2015 | + // was the payment deleted ? |
|
| 2016 | + if (is_bool($delete_txn_reg_status_change)) { |
|
| 2017 | + return array( |
|
| 2018 | + 'PAY_ID' => $payment->ID(), |
|
| 2019 | + 'amount' => $payment->amount(), |
|
| 2020 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 2021 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2022 | + 'pay_status' => $payment->STS_ID(), |
|
| 2023 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2024 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 2025 | + ); |
|
| 2026 | + } else { |
|
| 2027 | + $this->_get_payment_status_array(); |
|
| 2028 | + |
|
| 2029 | + return array( |
|
| 2030 | + 'amount' => $payment->amount(), |
|
| 2031 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 2032 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2033 | + 'pay_status' => $payment->STS_ID(), |
|
| 2034 | + 'PAY_ID' => $payment->ID(), |
|
| 2035 | + 'STS_ID' => $payment->STS_ID(), |
|
| 2036 | + 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 2037 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 2038 | + 'method' => strtoupper($payment->source()), |
|
| 2039 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 2040 | + 'gateway' => $payment->payment_method() |
|
| 2041 | + ? $payment->payment_method()->admin_name() |
|
| 2042 | + : esc_html__("Unknown", 'event_espresso'), |
|
| 2043 | + 'gateway_response' => $payment->gateway_response(), |
|
| 2044 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 2045 | + 'po_number' => $payment->po_number(), |
|
| 2046 | + 'extra_accntng' => $payment->extra_accntng(), |
|
| 2047 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2048 | + ); |
|
| 2049 | + } |
|
| 2050 | + } |
|
| 2051 | + |
|
| 2052 | + |
|
| 2053 | + /** |
|
| 2054 | + * delete_payment |
|
| 2055 | + * delete a payment or refund made towards a transaction |
|
| 2056 | + * |
|
| 2057 | + * @access public |
|
| 2058 | + * @return void |
|
| 2059 | + * @throws EE_Error |
|
| 2060 | + * @throws InvalidArgumentException |
|
| 2061 | + * @throws ReflectionException |
|
| 2062 | + * @throws InvalidDataTypeException |
|
| 2063 | + * @throws InvalidInterfaceException |
|
| 2064 | + */ |
|
| 2065 | + public function delete_payment() |
|
| 2066 | + { |
|
| 2067 | + $json_response_data = array('return_data' => false); |
|
| 2068 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2069 | + ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2070 | + : 0; |
|
| 2071 | + $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
| 2072 | + 'ee_delete_payments', |
|
| 2073 | + 'delete_payment_from_registration_details' |
|
| 2074 | + ); |
|
| 2075 | + if ($PAY_ID && $can_delete) { |
|
| 2076 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
| 2077 | + ? $this->_req_data['delete_txn_reg_status_change'] |
|
| 2078 | + : false; |
|
| 2079 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 2080 | + if ($payment instanceof EE_Payment) { |
|
| 2081 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2082 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2083 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2084 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 2085 | + $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
| 2086 | + $payment, |
|
| 2087 | + $REG_IDs, |
|
| 2088 | + $delete_txn_reg_status_change |
|
| 2089 | + ); |
|
| 2090 | + if ($delete_txn_reg_status_change) { |
|
| 2091 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2092 | + //MAKE sure we also add the delete_txn_req_status_change to the |
|
| 2093 | + //$_REQUEST global because that's how messages will be looking for it. |
|
| 2094 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2095 | + $this->_maybe_send_notifications(); |
|
| 2096 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 2097 | + } |
|
| 2098 | + } |
|
| 2099 | + } else { |
|
| 2100 | + EE_Error::add_error( |
|
| 2101 | + esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 2102 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2103 | + ); |
|
| 2104 | + } |
|
| 2105 | + } else { |
|
| 2106 | + if ($can_delete) { |
|
| 2107 | + EE_Error::add_error( |
|
| 2108 | + esc_html__( |
|
| 2109 | + 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 2110 | + 'event_espresso' |
|
| 2111 | + ), |
|
| 2112 | + __FILE__, __FUNCTION__, __LINE__ |
|
| 2113 | + ); |
|
| 2114 | + } else { |
|
| 2115 | + EE_Error::add_error( |
|
| 2116 | + esc_html__( |
|
| 2117 | + 'You do not have access to delete a payment.', |
|
| 2118 | + 'event_espresso' |
|
| 2119 | + ), |
|
| 2120 | + __FILE__, |
|
| 2121 | + __FUNCTION__, |
|
| 2122 | + __LINE__ |
|
| 2123 | + ); |
|
| 2124 | + } |
|
| 2125 | + } |
|
| 2126 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 2127 | + $this->_template_args = array( |
|
| 2128 | + 'data' => $json_response_data, |
|
| 2129 | + 'success' => $notices['success'], |
|
| 2130 | + 'error' => $notices['errors'], |
|
| 2131 | + 'attention' => $notices['attention'], |
|
| 2132 | + ); |
|
| 2133 | + $this->_return_json(); |
|
| 2134 | + } |
|
| 2135 | + |
|
| 2136 | + |
|
| 2137 | + /** |
|
| 2138 | + * _registration_payment_data_array |
|
| 2139 | + * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 2140 | + * |
|
| 2141 | + * @access protected |
|
| 2142 | + * @param array $REG_IDs |
|
| 2143 | + * @return array |
|
| 2144 | + * @throws EE_Error |
|
| 2145 | + * @throws InvalidArgumentException |
|
| 2146 | + * @throws InvalidDataTypeException |
|
| 2147 | + * @throws InvalidInterfaceException |
|
| 2148 | + */ |
|
| 2149 | + protected function _registration_payment_data_array($REG_IDs) |
|
| 2150 | + { |
|
| 2151 | + $registration_payment_data = array(); |
|
| 2152 | + //if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 2153 | + if (! empty($REG_IDs)) { |
|
| 2154 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 2155 | + foreach ($registrations as $registration) { |
|
| 2156 | + if ($registration instanceof EE_Registration) { |
|
| 2157 | + $registration_payment_data[$registration->ID()] = array( |
|
| 2158 | + 'paid' => $registration->pretty_paid(), |
|
| 2159 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 2160 | + ); |
|
| 2161 | + } |
|
| 2162 | + } |
|
| 2163 | + } |
|
| 2164 | + |
|
| 2165 | + return $registration_payment_data; |
|
| 2166 | + } |
|
| 2167 | + |
|
| 2168 | + |
|
| 2169 | + /** |
|
| 2170 | + * _maybe_send_notifications |
|
| 2171 | + * determines whether or not the admin has indicated that notifications should be sent. |
|
| 2172 | + * If so, will toggle a filter switch for delivering registration notices. |
|
| 2173 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 2174 | + * |
|
| 2175 | + * @access protected |
|
| 2176 | + * @param \EE_Payment | null $payment |
|
| 2177 | + */ |
|
| 2178 | + protected function _maybe_send_notifications($payment = null) |
|
| 2179 | + { |
|
| 2180 | + switch ($payment instanceof EE_Payment) { |
|
| 2181 | + // payment notifications |
|
| 2182 | + case true : |
|
| 2183 | + if ( |
|
| 2184 | + isset( |
|
| 2185 | + $this->_req_data['txn_payments'], |
|
| 2186 | + $this->_req_data['txn_payments']['send_notifications'] |
|
| 2187 | + ) && |
|
| 2188 | + filter_var($this->_req_data['txn_payments']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 2189 | + ) { |
|
| 2190 | + $this->_process_payment_notification($payment); |
|
| 2191 | + } |
|
| 2192 | + break; |
|
| 2193 | + // registration notifications |
|
| 2194 | + case false : |
|
| 2195 | + if ( |
|
| 2196 | + isset( |
|
| 2197 | + $this->_req_data['txn_reg_status_change'], |
|
| 2198 | + $this->_req_data['txn_reg_status_change']['send_notifications'] |
|
| 2199 | + ) && |
|
| 2200 | + filter_var($this->_req_data['txn_reg_status_change']['send_notifications'], FILTER_VALIDATE_BOOLEAN) |
|
| 2201 | + ) { |
|
| 2202 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 2203 | + } |
|
| 2204 | + break; |
|
| 2205 | + } |
|
| 2206 | + } |
|
| 2207 | + |
|
| 2208 | + |
|
| 2209 | + /** |
|
| 2210 | + * _send_payment_reminder |
|
| 2211 | + * generates HTML for the View Transaction Details Admin page |
|
| 2212 | + * |
|
| 2213 | + * @access protected |
|
| 2214 | + * @return void |
|
| 2215 | + * @throws EE_Error |
|
| 2216 | + * @throws InvalidArgumentException |
|
| 2217 | + * @throws InvalidDataTypeException |
|
| 2218 | + * @throws InvalidInterfaceException |
|
| 2219 | + */ |
|
| 2220 | + protected function _send_payment_reminder() |
|
| 2221 | + { |
|
| 2222 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2223 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2224 | + $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 2225 | + 'action' => $this->_req_data['redirect_to'], |
|
| 2226 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2227 | + ) : array(); |
|
| 2228 | + do_action( |
|
| 2229 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 2230 | + $transaction |
|
| 2231 | + ); |
|
| 2232 | + $this->_redirect_after_action( |
|
| 2233 | + false, |
|
| 2234 | + esc_html__('payment reminder', 'event_espresso'), |
|
| 2235 | + esc_html__('sent', 'event_espresso'), |
|
| 2236 | + $query_args, |
|
| 2237 | + true |
|
| 2238 | + ); |
|
| 2239 | + } |
|
| 2240 | + |
|
| 2241 | + |
|
| 2242 | + /** |
|
| 2243 | + * get_transactions |
|
| 2244 | + * get transactions for given parameters (used by list table) |
|
| 2245 | + * |
|
| 2246 | + * @param int $perpage how many transactions displayed per page |
|
| 2247 | + * @param boolean $count return the count or objects |
|
| 2248 | + * @param string $view |
|
| 2249 | + * @return mixed int = count || array of transaction objects |
|
| 2250 | + * @throws EE_Error |
|
| 2251 | + * @throws InvalidArgumentException |
|
| 2252 | + * @throws InvalidDataTypeException |
|
| 2253 | + * @throws InvalidInterfaceException |
|
| 2254 | + */ |
|
| 2255 | + public function get_transactions($perpage, $count = false, $view = '') |
|
| 2256 | + { |
|
| 2257 | + |
|
| 2258 | + $TXN = EEM_Transaction::instance(); |
|
| 2259 | + |
|
| 2260 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 2261 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 2262 | + : date( |
|
| 2263 | + 'm/d/Y', |
|
| 2264 | + strtotime('-10 year') |
|
| 2265 | + ); |
|
| 2266 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2267 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 2268 | + : date('m/d/Y'); |
|
| 2269 | + |
|
| 2270 | + //make sure our timestamps start and end right at the boundaries for each day |
|
| 2271 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2272 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2273 | + |
|
| 2274 | + |
|
| 2275 | + //convert to timestamps |
|
| 2276 | + $start_date = strtotime($start_date); |
|
| 2277 | + $end_date = strtotime($end_date); |
|
| 2278 | + |
|
| 2279 | + //makes sure start date is the lowest value and vice versa |
|
| 2280 | + $start_date = min($start_date, $end_date); |
|
| 2281 | + $end_date = max($start_date, $end_date); |
|
| 2282 | + |
|
| 2283 | + //convert to correct format for query |
|
| 2284 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2285 | + 'TXN_timestamp', |
|
| 2286 | + date('Y-m-d H:i:s', $start_date), |
|
| 2287 | + 'Y-m-d H:i:s' |
|
| 2288 | + ); |
|
| 2289 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2290 | + 'TXN_timestamp', |
|
| 2291 | + date('Y-m-d H:i:s', $end_date), |
|
| 2292 | + 'Y-m-d H:i:s' |
|
| 2293 | + ); |
|
| 2294 | + |
|
| 2295 | + |
|
| 2296 | + //set orderby |
|
| 2297 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2298 | + |
|
| 2299 | + switch ($this->_req_data['orderby']) { |
|
| 2300 | + case 'TXN_ID': |
|
| 2301 | + $orderby = 'TXN_ID'; |
|
| 2302 | + break; |
|
| 2303 | + case 'ATT_fname': |
|
| 2304 | + $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 2305 | + break; |
|
| 2306 | + case 'event_name': |
|
| 2307 | + $orderby = 'Registration.Event.EVT_name'; |
|
| 2308 | + break; |
|
| 2309 | + default: //'TXN_timestamp' |
|
| 2310 | + $orderby = 'TXN_timestamp'; |
|
| 2311 | + } |
|
| 2312 | + |
|
| 2313 | + $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2314 | + $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 2315 | + $per_page = ! empty($perpage) ? $perpage : 10; |
|
| 2316 | + $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 2317 | + |
|
| 2318 | + $offset = ($current_page - 1) * $per_page; |
|
| 2319 | + $limit = array($offset, $per_page); |
|
| 2320 | + |
|
| 2321 | + $_where = array( |
|
| 2322 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 2323 | + 'Registration.REG_count' => 1, |
|
| 2324 | + ); |
|
| 2325 | + |
|
| 2326 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 2327 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2328 | + } |
|
| 2329 | + |
|
| 2330 | + if (isset($this->_req_data['s'])) { |
|
| 2331 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2332 | + $_where['OR'] = array( |
|
| 2333 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 2334 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 2335 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 2336 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 2337 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 2338 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 2339 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 2340 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 2341 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 2342 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 2343 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 2344 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 2345 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 2346 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 2347 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 2348 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 2349 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 2350 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 2351 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 2352 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
| 2353 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 2354 | + ); |
|
| 2355 | + } |
|
| 2356 | + |
|
| 2357 | + //failed transactions |
|
| 2358 | + $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2359 | + || ($count && $view === 'failed'); |
|
| 2360 | + $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2361 | + || ($count && $view === 'abandoned'); |
|
| 2362 | + |
|
| 2363 | + if ($failed) { |
|
| 2364 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 2365 | + } else if ($abandoned) { |
|
| 2366 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 2367 | + } else { |
|
| 2368 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 2369 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 2370 | + } |
|
| 2371 | + |
|
| 2372 | + $query_params = array( |
|
| 2373 | + $_where, |
|
| 2374 | + 'order_by' => array($orderby => $sort), |
|
| 2375 | + 'limit' => $limit, |
|
| 2376 | + 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
| 2377 | + ); |
|
| 2378 | + |
|
| 2379 | + $transactions = $count |
|
| 2380 | + ? $TXN->count(array($_where), 'TXN_ID', true) |
|
| 2381 | + : $TXN->get_all($query_params); |
|
| 2382 | + |
|
| 2383 | + return $transactions; |
|
| 2384 | + } |
|
| 2385 | 2385 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | <div id="payment-accntng-<?php echo $PAY_ID; ?>"><?php echo $payment->extra_accntng(); ?></div> |
| 160 | 160 | </td> |
| 161 | 161 | <td class=" jst-rght"> |
| 162 | - <?php $payment_class = $payment->amount() > 0 ? 'txn-admin-payment-status-' . $payment->STS_ID() : 'txn-admin-payment-status-PDC'; ?> |
|
| 162 | + <?php $payment_class = $payment->amount() > 0 ? 'txn-admin-payment-status-'.$payment->STS_ID() : 'txn-admin-payment-status-PDC'; ?> |
|
| 163 | 163 | <span class="<?php echo $payment_class; ?>"> |
| 164 | 164 | <div id="payment-amount-<?php echo $PAY_ID; ?>" |
| 165 | 165 | style="display:inline;"><?php echo EEH_Template::format_currency($payment->amount(), |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | <?php endforeach; // $payment?> |
| 174 | 174 | <?php |
| 175 | 175 | $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : ''; |
| 176 | - $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ', |
|
| 177 | - 'event_espresso') . '</span>' : ''; |
|
| 176 | + $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">'.esc_html__('This transaction has been overpaid ! ', |
|
| 177 | + 'event_espresso').'</span>' : ''; |
|
| 178 | 178 | ?> |
| 179 | 179 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden"> |
| 180 | 180 | <td class=" jst-rght" colspan="11"> |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | <tr id="txn-admin-payments-total-tr" |
| 185 | 185 | class="admin-primary-mbox-total-tr<?php echo $pay_totals_class; ?>"> |
| 186 | 186 | <th class=" jst-rght" colspan="10"><span |
| 187 | - id="payments-total-spn"><?php echo $overpaid . sprintf(esc_html__('Payments Total %s', |
|
| 187 | + id="payments-total-spn"><?php echo $overpaid.sprintf(esc_html__('Payments Total %s', |
|
| 188 | 188 | 'event_espresso'), |
| 189 | - '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th> |
|
| 189 | + '('.EE_Registry::instance()->CFG->currency->code.')'); ?></span></th> |
|
| 190 | 190 | <th class=" jst-rght"><span |
| 191 | 191 | id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total, |
| 192 | 192 | false, false); ?></span></th> |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | <h2 id="admin-modal-dialog-apply-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
| 300 | 300 | style="display:none;"> |
| 301 | 301 | <div class="ee-icon ee-icon-cash-add float-left"></div> |
| 302 | - <?php echo esc_html__('Apply a Payment to Transaction #', 'event_espresso') . $txn_nmbr['value']; ?> |
|
| 302 | + <?php echo esc_html__('Apply a Payment to Transaction #', 'event_espresso').$txn_nmbr['value']; ?> |
|
| 303 | 303 | </h2> |
| 304 | 304 | |
| 305 | 305 | <h2 id="admin-modal-dialog-edit-payment-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
| 329 | 329 | style="display:none;"> |
| 330 | 330 | <div class="ee-icon ee-icon-cash-remove float-left"></div> |
| 331 | - <?php echo esc_html__('Apply a Refund to Transaction #', 'event_espresso') . $txn_nmbr['value']; ?> |
|
| 331 | + <?php echo esc_html__('Apply a Refund to Transaction #', 'event_espresso').$txn_nmbr['value']; ?> |
|
| 332 | 332 | </h2> |
| 333 | 333 | |
| 334 | 334 | <form name="txn-admin-apply-payment-frm" id="txn-admin-apply-payment-frm" |
@@ -557,7 +557,7 @@ discard block |
||
| 557 | 557 | style="display:none;"> |
| 558 | 558 | <span class="ee-icon ee-icon-cash-add"></span> |
| 559 | 559 | <?php echo esc_html__('Delete Payment/Refund for Transaction #', |
| 560 | - 'event_espresso') . $txn_nmbr['value']; ?> |
|
| 560 | + 'event_espresso').$txn_nmbr['value']; ?> |
|
| 561 | 561 | </h2> |
| 562 | 562 | |
| 563 | 563 | <form name="txn-admin-delete-payment-frm" id="txn-admin-delete-payment-frm" |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | <?php foreach ($delivered_messages[$TXN_ID] as $timestamp => $delivered_message) : |
| 644 | 644 | ?> |
| 645 | 645 | <tr> |
| 646 | - <td class="jst-left"><?php echo date(get_option('date_format') . ' ' . get_option('time_format'), |
|
| 646 | + <td class="jst-left"><?php echo date(get_option('date_format').' '.get_option('time_format'), |
|
| 647 | 647 | ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td> |
| 648 | 648 | <td class="jst-left"><?php echo isset($delivered_message['message_type']) ? $delivered_message['message_type'] : ''; ?></td> |
| 649 | 649 | <td class="jst-left"><?php echo isset($delivered_message['pay_status']) ? $delivered_message['pay_status'] : ''; ?></td> |
@@ -191,10 +191,13 @@ discard block |
||
| 191 | 191 | id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total, |
| 192 | 192 | false, false); ?></span></th> |
| 193 | 193 | </tr> |
| 194 | - <?php else : ?> |
|
| 194 | + <?php else { |
|
| 195 | + : ?> |
|
| 195 | 196 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr"> |
| 196 | 197 | <td class=" jst-rght" colspan="11"> |
| 197 | - <span class="important-notice"><?php echo $no_payment_text; ?></span> |
|
| 198 | + <span class="important-notice"><?php echo $no_payment_text; |
|
| 199 | +} |
|
| 200 | +?></span> |
|
| 198 | 201 | </td> |
| 199 | 202 | </tr> |
| 200 | 203 | <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden"> |
@@ -285,10 +288,13 @@ discard block |
||
| 285 | 288 | <?php esc_html_e('Apply Refund', 'event_espresso'); ?> |
| 286 | 289 | </a> |
| 287 | 290 | </li> |
| 288 | - <?php else : ?> |
|
| 291 | + <?php else { |
|
| 292 | + : ?> |
|
| 289 | 293 | <li> |
| 290 | 294 | <p><?php esc_html__('You do not have access to apply payments or refunds.', |
| 291 | - 'event_espresso'); ?></p> |
|
| 295 | + 'event_espresso'); |
|
| 296 | +} |
|
| 297 | +?></p> |
|
| 292 | 298 | </li> |
| 293 | 299 | <?php endif; ?> |
| 294 | 300 | </ul> |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | <a id="display-additional-transaction-session-info" class="display-the-hidden smaller-text" |
| 13 | 13 | rel="additional-transaction-session-info"> |
| 14 | 14 | <span class="dashicons dashicons-plus-alt"></span><?php esc_html_e('view additional transaction session details', |
| 15 | - 'event_espresso'); ?> |
|
| 15 | + 'event_espresso'); ?> |
|
| 16 | 16 | </a> |
| 17 | 17 | |
| 18 | 18 | <div id="additional-transaction-session-info-dv" class="hidden"> |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | <a id="hide-additional-transaction-session-info" class="hide-the-displayed hidden smaller-text" |
| 21 | 21 | rel="additional-transaction-session-info"> |
| 22 | 22 | <span class="dashicons dashicons-dismiss"></span><?php esc_html_e('hide additional transaction session details', |
| 23 | - 'event_espresso'); ?> |
|
| 23 | + 'event_espresso'); ?> |
|
| 24 | 24 | </a> |
| 25 | 25 | <br class="clear"/> |
| 26 | 26 | |
@@ -45,16 +45,16 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | |
| 47 | 47 | <?php if ($attendee instanceof EE_Attendee && ($grand_raw_total > 0 || $TXN_status !== EEM_Transaction::complete_status_code || ! empty($payments))) : |
| 48 | - $no_payment_text = $can_edit_payments |
|
| 49 | - ? esc_html__( |
|
| 50 | - 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', |
|
| 51 | - 'event_espresso' |
|
| 52 | - ) |
|
| 53 | - : esc_html__( |
|
| 54 | - 'No payments have been applied to this transaction yet.', |
|
| 55 | - 'event_espresso' |
|
| 56 | - ); |
|
| 57 | - ?> |
|
| 48 | + $no_payment_text = $can_edit_payments |
|
| 49 | + ? esc_html__( |
|
| 50 | + 'No payments have been applied to this transaction yet. Click "Apply Payment" below to make a payment.', |
|
| 51 | + 'event_espresso' |
|
| 52 | + ) |
|
| 53 | + : esc_html__( |
|
| 54 | + 'No payments have been applied to this transaction yet.', |
|
| 55 | + 'event_espresso' |
|
| 56 | + ); |
|
| 57 | + ?> |
|
| 58 | 58 | |
| 59 | 59 | <h3 class="admin-primary-mbox-h4 hdr-has-icon"> |
| 60 | 60 | <span class="ee-icon ee-icon-cash"></span><?php esc_html_e('Payment Details', 'event_espresso'); ?> |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | <?php if ($payments) : ?> |
| 83 | 83 | <?php $payment_total = 0; ?> |
| 84 | 84 | <?php foreach ($payments as $PAY_ID => $payment) : |
| 85 | - $existing_reg_payment_json = isset($existing_reg_payments[$PAY_ID]) |
|
| 86 | - ? wp_json_encode($existing_reg_payments[$PAY_ID]) |
|
| 87 | - : '{}'; |
|
| 88 | - ?> |
|
| 85 | + $existing_reg_payment_json = isset($existing_reg_payments[$PAY_ID]) |
|
| 86 | + ? wp_json_encode($existing_reg_payments[$PAY_ID]) |
|
| 87 | + : '{}'; |
|
| 88 | + ?> |
|
| 89 | 89 | <tr id="txn-admin-payment-tr-<?php echo $PAY_ID; ?>"> |
| 90 | 90 | <td> |
| 91 | 91 | <span id="payment-status-<?php echo $PAY_ID; ?>" |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | <td class=" jst-left"> |
| 133 | 133 | <div id="payment-gateway-<?php echo $PAY_ID; ?>"> |
| 134 | 134 | <?php echo $payment->payment_method() ? $payment->payment_method()->admin_name() : esc_html__("Unknown", |
| 135 | - 'event_espresso'); ?> |
|
| 135 | + 'event_espresso'); ?> |
|
| 136 | 136 | </div> |
| 137 | 137 | <div id="payment-gateway-id-<?php echo $PAY_ID; ?>" |
| 138 | 138 | class="hidden"><?php echo $payment->payment_method() ? $payment->payment_method()->ID() : 0; ?></div> |
@@ -154,19 +154,19 @@ discard block |
||
| 154 | 154 | <span class="<?php echo $payment_class; ?>"> |
| 155 | 155 | <div id="payment-amount-<?php echo $PAY_ID; ?>" |
| 156 | 156 | style="display:inline;"><?php echo EEH_Template::format_currency($payment->amount(), |
| 157 | - false, false); ?></div> |
|
| 157 | + false, false); ?></div> |
|
| 158 | 158 | </span> |
| 159 | 159 | </td> |
| 160 | 160 | </tr> |
| 161 | 161 | <?php |
| 162 | - $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0; |
|
| 163 | - ?> |
|
| 162 | + $payment_total += $payment->STS_ID() == 'PAP' ? $payment->amount() : 0; |
|
| 163 | + ?> |
|
| 164 | 164 | <?php endforeach; // $payment?> |
| 165 | 165 | <?php |
| 166 | - $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : ''; |
|
| 167 | - $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ', |
|
| 168 | - 'event_espresso') . '</span>' : ''; |
|
| 169 | - ?> |
|
| 166 | + $pay_totals_class = $payment_total > $grand_raw_total ? ' important-notice' : ''; |
|
| 167 | + $overpaid = $payment_total > $grand_raw_total ? '<span id="overpaid">' . esc_html__('This transaction has been overpaid ! ', |
|
| 168 | + 'event_espresso') . '</span>' : ''; |
|
| 169 | + ?> |
|
| 170 | 170 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr hidden"> |
| 171 | 171 | <td class=" jst-rght" colspan="11"> |
| 172 | 172 | <span class="important-notice"><?php echo $no_payment_text; ?></span> |
@@ -176,11 +176,11 @@ discard block |
||
| 176 | 176 | class="admin-primary-mbox-total-tr<?php echo $pay_totals_class; ?>"> |
| 177 | 177 | <th class=" jst-rght" colspan="10"><span |
| 178 | 178 | id="payments-total-spn"><?php echo $overpaid . sprintf(esc_html__('Payments Total %s', |
| 179 | - 'event_espresso'), |
|
| 180 | - '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th> |
|
| 179 | + 'event_espresso'), |
|
| 180 | + '(' . EE_Registry::instance()->CFG->currency->code . ')'); ?></span></th> |
|
| 181 | 181 | <th class=" jst-rght"><span |
| 182 | 182 | id="txn-admin-payment-total"><?php echo EEH_Template::format_currency($payment_total, |
| 183 | - false, false); ?></span></th> |
|
| 183 | + false, false); ?></span></th> |
|
| 184 | 184 | </tr> |
| 185 | 185 | <?php else : ?> |
| 186 | 186 | <tr id="txn-admin-no-payments-tr" class="admin-primary-mbox-total-tr"> |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | <tr id="txn-admin-payments-total-tr" class="admin-primary-mbox-total-tr hidden"> |
| 192 | 192 | <th class=" jst-rght" colspan="10"><span |
| 193 | 193 | id="payments-total-spn"><?php echo esc_html__('Payments Total', |
| 194 | - 'event_espresso'); ?></span></th> |
|
| 194 | + 'event_espresso'); ?></span></th> |
|
| 195 | 195 | <th class=" jst-rght"><span id="txn-admin-payment-total"></span></th> |
| 196 | 196 | </tr> |
| 197 | 197 | <?php endif; // $payments |
| 198 | - ?> |
|
| 198 | + ?> |
|
| 199 | 199 | |
| 200 | 200 | <tr id="txn-admin-payment-empty-row-tr" class="hidden"> |
| 201 | 201 | <td> |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | <ul id="txn-admin-payment-options-ul"> |
| 262 | 262 | <?php if ($can_edit_payments) : |
| 263 | - ?> |
|
| 263 | + ?> |
|
| 264 | 264 | <li> |
| 265 | 265 | <a id="display-txn-admin-apply-payment" class="button-primary no-icon no-hide" |
| 266 | 266 | rel="txn-admin-apply-payment"> <!--display-the-hidden --> |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | <?php else : ?> |
| 277 | 277 | <li> |
| 278 | 278 | <p><?php esc_html__('You do not have access to apply payments or refunds.', |
| 279 | - 'event_espresso'); ?></p> |
|
| 279 | + 'event_espresso'); ?></p> |
|
| 280 | 280 | </li> |
| 281 | 281 | <?php endif; ?> |
| 282 | 282 | </ul> |
@@ -294,23 +294,23 @@ discard block |
||
| 294 | 294 | style="display:none;"> |
| 295 | 295 | <div class="ee-icon ee-icon-cash-edit float-left"></div> |
| 296 | 296 | <?php |
| 297 | - echo sprintf( |
|
| 298 | - __('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
| 299 | - '<span></span>', |
|
| 300 | - $txn_nmbr['value'] |
|
| 301 | - ); |
|
| 302 | - ?> |
|
| 297 | + echo sprintf( |
|
| 298 | + __('Edit Payment #%s for Transaction #%s', 'event_espresso'), |
|
| 299 | + '<span></span>', |
|
| 300 | + $txn_nmbr['value'] |
|
| 301 | + ); |
|
| 302 | + ?> |
|
| 303 | 303 | </h2> |
| 304 | 304 | |
| 305 | 305 | <h2 id="admin-modal-dialog-edit-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" style="display:none;"> |
| 306 | 306 | <div class="ee-icon ee-icon-cash-edit float-left"></div> |
| 307 | 307 | <?php |
| 308 | - echo sprintf( |
|
| 309 | - __('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
| 310 | - '<span></span>', |
|
| 311 | - $txn_nmbr['value'] |
|
| 312 | - ); |
|
| 313 | - ?> |
|
| 308 | + echo sprintf( |
|
| 309 | + __('Edit Refund #%s for Transaction #%s', 'event_espresso'), |
|
| 310 | + '<span></span>', |
|
| 311 | + $txn_nmbr['value'] |
|
| 312 | + ); |
|
| 313 | + ?> |
|
| 314 | 314 | </h2> |
| 315 | 315 | |
| 316 | 316 | <h2 id="admin-modal-dialog-apply-refund-h2" class="admin-modal-dialog-h2 hdr-has-icon" |
@@ -343,55 +343,55 @@ discard block |
||
| 343 | 343 | |
| 344 | 344 | <div class="txn-admin-apply-payment-date-dv admin-modal-dialog-row"> |
| 345 | 345 | <div class="validation-notice-dv"><?php esc_html_e('The following is a required field', |
| 346 | - 'event_espresso'); ?></div> |
|
| 346 | + 'event_espresso'); ?></div> |
|
| 347 | 347 | <label for="txn-admin-payment-date-inp" class=""><?php esc_html_e('Payment Date', |
| 348 | - 'event_espresso'); ?></label> |
|
| 348 | + 'event_espresso'); ?></label> |
|
| 349 | 349 | <input name="txn_admin_payment[date]" id="txn-admin-payment-date-inp" |
| 350 | 350 | class="txn-admin-apply-payment-inp required" type="text" |
| 351 | 351 | value="<?php echo date('Y-m-d g:i a', current_time('timestamp')); ?>"/> |
| 352 | 352 | <p class="description"><?php esc_html_e('The date the payment was actually made on', |
| 353 | - 'event_espresso'); ?></p> |
|
| 353 | + 'event_espresso'); ?></p> |
|
| 354 | 354 | </div> |
| 355 | 355 | |
| 356 | 356 | <div class="txn-admin-apply-payment-amount-dv admin-modal-dialog-row"> |
| 357 | 357 | <div class="validation-notice-dv"><?php esc_html_e('The following is a required field', |
| 358 | - 'event_espresso'); ?></div> |
|
| 358 | + 'event_espresso'); ?></div> |
|
| 359 | 359 | <label for="txn-admin-payment-amount-inp" class=""><?php esc_html_e('Amount', |
| 360 | - 'event_espresso'); ?></label> |
|
| 360 | + 'event_espresso'); ?></label> |
|
| 361 | 361 | <input name="txn_admin_payment[amount]" id="txn-admin-payment-amount-inp" |
| 362 | 362 | class="txn-admin-apply-payment-inp required" type="text" value=""/> |
| 363 | 363 | <p class="description"><?php esc_html_e('The amount of the payment', |
| 364 | - 'event_espresso'); ?></p> |
|
| 364 | + 'event_espresso'); ?></p> |
|
| 365 | 365 | </div> |
| 366 | 366 | |
| 367 | 367 | <div class="txn-admin-apply-payment-method-dv admin-modal-dialog-row"> |
| 368 | 368 | <div class="validation-notice-dv"><?php esc_html_e('The following is a required field', |
| 369 | - 'event_espresso'); ?></div> |
|
| 369 | + 'event_espresso'); ?></div> |
|
| 370 | 370 | <label for="txn-admin-payment-method-inp" class=""><?php esc_html_e('Method of Payment', |
| 371 | - 'event_espresso'); ?></label> |
|
| 371 | + 'event_espresso'); ?></label> |
|
| 372 | 372 | <select name="txn_admin_payment[PMD_ID]" id="txn-admin-payment-method-slct" |
| 373 | 373 | class="txn-admin-apply-payment-slct required" type="text"> |
| 374 | 374 | <?php foreach ($payment_methods as $method) : ?> |
| 375 | 375 | <?php $selected = $method->slug() == 'cash' ? ' selected="selected"' : ''; ?> |
| 376 | 376 | <option id="payment-method-opt-<?php echo $method->slug(); ?>" |
| 377 | 377 | value="<?php echo $method->ID(); ?>"<?php echo $selected; ?>><?php echo sanitize_key($method->admin_desc()) ? substr($method->admin_desc(), |
| 378 | - 0, 128) : $method->admin_name(); ?> |
|
| 378 | + 0, 128) : $method->admin_name(); ?> |
|
| 379 | 379 | </option> |
| 380 | 380 | <?php endforeach; ?> |
| 381 | 381 | </select> |
| 382 | 382 | <p class="description"><?php esc_html_e('Whether the payment was made via PayPal, Credit Card, Cheque, or Cash', |
| 383 | - 'event_espresso'); ?></p> |
|
| 383 | + 'event_espresso'); ?></p> |
|
| 384 | 384 | </div> |
| 385 | 385 | |
| 386 | 386 | <div class="mop-PP mop-CC mop-CHQ mop"> |
| 387 | 387 | <div class="txn-admin-apply-payment-gw-txn-id-dv admin-modal-dialog-row"> |
| 388 | 388 | <label for="txn-admin-payment-txn-id-inp" class=""><?php esc_html_e('TXN ID / CHQ #', |
| 389 | - 'event_espresso'); ?></label> |
|
| 389 | + 'event_espresso'); ?></label> |
|
| 390 | 390 | <input name="txn_admin_payment[txn_id_chq_nmbr]" |
| 391 | 391 | id="txn-admin-payment-txn-id-chq-nmbr-inp" class="txn-admin-apply-payment-inp" |
| 392 | 392 | type="text" maxlength="100"/> |
| 393 | 393 | <p class="description"><?php esc_html_e('The Transaction ID sent back from the payment gateway, or the Cheque #', |
| 394 | - 'event_espresso'); ?></p> |
|
| 394 | + 'event_espresso'); ?></p> |
|
| 395 | 395 | </div> |
| 396 | 396 | </div> |
| 397 | 397 | |
@@ -403,14 +403,14 @@ discard block |
||
| 403 | 403 | id="txn-admin-payment-gateway-response-inp" class="txn-admin-apply-payment-inp" |
| 404 | 404 | type="text"/> |
| 405 | 405 | <p class="description"><?php esc_html_e('The gateway response string (optional)', |
| 406 | - 'event_espresso'); ?></p> |
|
| 406 | + 'event_espresso'); ?></p> |
|
| 407 | 407 | </div> |
| 408 | 408 | </div> |
| 409 | 409 | |
| 410 | 410 | <div class="mop-PP mop-CC mop"> |
| 411 | 411 | <div class="txn-admin-apply-payment-status-dv admin-modal-dialog-row"> |
| 412 | 412 | <label for="txn-admin-payment-status-inp" class=""><?php esc_html_e('Payment Status', |
| 413 | - 'event_espresso'); ?></label> |
|
| 413 | + 'event_espresso'); ?></label> |
|
| 414 | 414 | <select name="txn_admin_payment[status]" id="txn-admin-payment-status-slct" |
| 415 | 415 | class="txn-admin-apply-payment-slct" type="text"> |
| 416 | 416 | <?php foreach ($payment_status as $STS_ID => $STS_code) : ?> |
@@ -422,35 +422,35 @@ discard block |
||
| 422 | 422 | <?php endforeach; ?> |
| 423 | 423 | </select> |
| 424 | 424 | <p class="description"><?php esc_html_e('Whether the payment was approved, cancelled, declined or failed after submission to the gateway', |
| 425 | - 'event_espresso'); ?></p> |
|
| 425 | + 'event_espresso'); ?></p> |
|
| 426 | 426 | </div> |
| 427 | 427 | </div> |
| 428 | 428 | |
| 429 | 429 | <div class="txn-admin-apply-payment-po-nmbr-dv admin-modal-dialog-row"> |
| 430 | 430 | <label for="txn-admin-payment-po-nmbr-inp" class=""><?php esc_html_e('P.O. / S.O. #', |
| 431 | - 'event_espresso'); ?></label> |
|
| 431 | + 'event_espresso'); ?></label> |
|
| 432 | 432 | <input name="txn_admin_payment[po_number]" id="txn-admin-payment-po-nmbr-inp" |
| 433 | 433 | class="txn-admin-apply-payment-inp" type="text" maxlength="100"/> |
| 434 | 434 | <p class="description"><?php esc_html_e('The Purchase or Sales Order Number if any (optional)', |
| 435 | - 'event_espresso'); ?></p> |
|
| 435 | + 'event_espresso'); ?></p> |
|
| 436 | 436 | </div> |
| 437 | 437 | |
| 438 | 438 | <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
| 439 | 439 | <label for="txn-admin-payment-accounting-inp" |
| 440 | 440 | class="last"><?php esc_html_e('Notes / Extra Accounting', |
| 441 | - 'event_espresso'); ?></label> |
|
| 441 | + 'event_espresso'); ?></label> |
|
| 442 | 442 | <input name="txn_admin_payment[accounting]" id="txn-admin-payment-accounting-inp" |
| 443 | 443 | class="txn-admin-apply-payment-inp" type="text" value="<?php echo $REG_code; ?>" |
| 444 | 444 | maxlength="100"/> <input type="hidden" id="txn-admin-reg-code-inp" |
| 445 | 445 | value="<?php echo $REG_code; ?>"/> |
| 446 | 446 | <p class="description"><?php esc_html_e('An extra field you may use for accounting purposes or simple notes. Defaults to the primary registrant\'s registration code.', |
| 447 | - 'event_espresso'); ?></p> |
|
| 447 | + 'event_espresso'); ?></p> |
|
| 448 | 448 | </div> |
| 449 | 449 | |
| 450 | 450 | <div class="txn-admin-apply-payment-registrations-dv admin-modal-dialog-row"> |
| 451 | 451 | <label for="txn-admin-payment-registrations-inp" |
| 452 | 452 | class="last"><?php esc_html_e('Registrations to Apply Payment to:', |
| 453 | - 'event_espresso'); ?></label> |
|
| 453 | + 'event_espresso'); ?></label> |
|
| 454 | 454 | <label class="txn-admin-apply-payment-to-registrations-lbl"> |
| 455 | 455 | <input type="radio" value="1" id="txn-admin-apply-payment-to-all-registrations-inp" |
| 456 | 456 | name="txn_admin_payment[apply_to_all_registrations]" checked="checked"/> |
@@ -467,10 +467,10 @@ discard block |
||
| 467 | 467 | <div class="txn-admin-payment-reg-status-dv admin-modal-dialog-row"> |
| 468 | 468 | <label for="txn-admin-payment-reg-status-inp" |
| 469 | 469 | class="last"><?php esc_html_e('Change Registration Status?', |
| 470 | - 'event_espresso'); ?></label> |
|
| 470 | + 'event_espresso'); ?></label> |
|
| 471 | 471 | <?php echo $status_change_select; ?> |
| 472 | 472 | <p class="description"><?php esc_html_e('If you wish to change the status for the registrations selected above, then select which status from this dropdown.', |
| 473 | - 'event_espresso'); ?></p> |
|
| 473 | + 'event_espresso'); ?></p> |
|
| 474 | 474 | <br/> |
| 475 | 475 | </div> |
| 476 | 476 | |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | </label> |
| 491 | 491 | <br class="clear-float"/> |
| 492 | 492 | <p class="description"><?php printf(esc_html__('By default %1$sa payment message is sent to the primary registrant%2$s after submitting this form.%3$sHowever, if you check the "Registration Messages" box, the system will also send any related messages matching the status of the registrations to %1$seach registration for this transaction%2$s.', |
| 493 | - 'event_espresso'), '<strong>', '</strong>', '<br />'); ?></p> |
|
| 493 | + 'event_espresso'), '<strong>', '</strong>', '<br />'); ?></p> |
|
| 494 | 494 | <label></label> |
| 495 | 495 | </div> |
| 496 | 496 | <div class="clear"></div> |
@@ -530,7 +530,7 @@ discard block |
||
| 530 | 530 | </li> |
| 531 | 531 | <li> |
| 532 | 532 | <span id="ee-ajax-processing-text" style="display:none;"><?php esc_html_e('Processing...', |
| 533 | - 'event_espresso'); ?></span> |
|
| 533 | + 'event_espresso'); ?></span> |
|
| 534 | 534 | </li> |
| 535 | 535 | </ul> |
| 536 | 536 | |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | style="display:none;"> |
| 546 | 546 | <span class="ee-icon ee-icon-cash-add"></span> |
| 547 | 547 | <?php echo esc_html__('Delete Payment/Refund for Transaction #', |
| 548 | - 'event_espresso') . $txn_nmbr['value']; ?> |
|
| 548 | + 'event_espresso') . $txn_nmbr['value']; ?> |
|
| 549 | 549 | </h2> |
| 550 | 550 | |
| 551 | 551 | <form name="txn-admin-delete-payment-frm" id="txn-admin-delete-payment-frm" |
@@ -566,10 +566,10 @@ discard block |
||
| 566 | 566 | <div class="txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
| 567 | 567 | <label for="delete-txn-admin-payment-reg-status-inp" |
| 568 | 568 | class="last"><?php esc_html_e('Change Registration Status?', |
| 569 | - 'event_espresso'); ?></label> |
|
| 569 | + 'event_espresso'); ?></label> |
|
| 570 | 570 | <?php echo $delete_status_change_select; ?> |
| 571 | 571 | <p class="description"><?php printf(esc_html__('If you wish to change the status of all the registrations associated with this transaction after deleting this payment/refund, then select which status from this dropdown. %sNote: ALL registrations associated with this transaction will be updated to this new status.%s', |
| 572 | - 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
| 572 | + 'event_espresso'), '<strong>', '</strong>'); ?></p> |
|
| 573 | 573 | </div> |
| 574 | 574 | |
| 575 | 575 | <div class="ee-attention txn-admin-apply-payment-accounting-dv admin-modal-dialog-row"> |
@@ -577,7 +577,7 @@ discard block |
||
| 577 | 577 | class="last"><?php esc_html_e('Send Related Messages?', 'event_espresso'); ?></label> |
| 578 | 578 | <input type="checkbox" value="1" name="delete_txn_reg_status_change[send_notifications]"> |
| 579 | 579 | <p class="description"><?php esc_html_e('If you check this box, the system will send any related registration messages matching the status of the registrations to each registration for this transaction. No Payment notifications are sent when deleting a payment.', |
| 580 | - 'event_espresso'); ?></p> |
|
| 580 | + 'event_espresso'); ?></p> |
|
| 581 | 581 | </div> |
| 582 | 582 | <div class="clear"></div> |
| 583 | 583 | |
@@ -609,13 +609,13 @@ discard block |
||
| 609 | 609 | <?php endif; // $grand_raw_total > 0?> |
| 610 | 610 | |
| 611 | 611 | <?php |
| 612 | - if (WP_DEBUG) { |
|
| 613 | - $delivered_messages = get_option('EED_Messages__payment', array()); |
|
| 614 | - if (isset($delivered_messages[$TXN_ID])) { |
|
| 615 | - ?> |
|
| 612 | + if (WP_DEBUG) { |
|
| 613 | + $delivered_messages = get_option('EED_Messages__payment', array()); |
|
| 614 | + if (isset($delivered_messages[$TXN_ID])) { |
|
| 615 | + ?> |
|
| 616 | 616 | <h4 class="admin-primary-mbox-h4 hdr-has-icon"><span |
| 617 | 617 | class="dashicons dashicons-email-alt"></span><?php esc_html_e('Messages Sent to Primary Registrant', |
| 618 | - 'event_espresso'); ?></h4> |
|
| 618 | + 'event_espresso'); ?></h4> |
|
| 619 | 619 | |
| 620 | 620 | <div class="admin-primary-mbox-tbl-wrap"> |
| 621 | 621 | <table class="admin-primary-mbox-tbl"> |
@@ -629,10 +629,10 @@ discard block |
||
| 629 | 629 | </thead> |
| 630 | 630 | <tbody> |
| 631 | 631 | <?php foreach ($delivered_messages[$TXN_ID] as $timestamp => $delivered_message) : |
| 632 | - ?> |
|
| 632 | + ?> |
|
| 633 | 633 | <tr> |
| 634 | 634 | <td class="jst-left"><?php echo date(get_option('date_format') . ' ' . get_option('time_format'), |
| 635 | - ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td> |
|
| 635 | + ($timestamp + (get_option('gmt_offset') * HOUR_IN_SECONDS))); ?></td> |
|
| 636 | 636 | <td class="jst-left"><?php echo isset($delivered_message['message_type']) ? $delivered_message['message_type'] : ''; ?></td> |
| 637 | 637 | <td class="jst-left"><?php echo isset($delivered_message['pay_status']) ? $delivered_message['pay_status'] : ''; ?></td> |
| 638 | 638 | <td class="jst-left"><?php echo isset($delivered_message['txn_status']) ? $delivered_message['txn_status'] : ''; ?></td> |
@@ -642,9 +642,9 @@ discard block |
||
| 642 | 642 | </table> |
| 643 | 643 | </div> |
| 644 | 644 | <?php |
| 645 | - } |
|
| 646 | - } |
|
| 647 | - ?> |
|
| 645 | + } |
|
| 646 | + } |
|
| 647 | + ?> |
|
| 648 | 648 | |
| 649 | 649 | |
| 650 | 650 | </div> |
@@ -22,744 +22,744 @@ |
||
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return EED_Module|EED_Add_New_State |
|
| 27 | - */ |
|
| 28 | - public static function instance() |
|
| 29 | - { |
|
| 30 | - return parent::get_instance(__CLASS__); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 37 | - * |
|
| 38 | - * @return void |
|
| 39 | - */ |
|
| 40 | - public static function set_hooks() |
|
| 41 | - { |
|
| 42 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 43 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 44 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 45 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 46 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 47 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 48 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 49 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 50 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 51 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 52 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 53 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 54 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 55 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 56 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 57 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 58 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 65 | - * |
|
| 66 | - * @return void |
|
| 67 | - */ |
|
| 68 | - public static function set_hooks_admin() |
|
| 69 | - { |
|
| 70 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 71 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 72 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 73 | - add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 74 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 75 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 76 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 77 | - add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 78 | - array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 79 | - add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 80 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 81 | - add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 82 | - array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 83 | - add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 84 | - array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 85 | - add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 86 | - array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 87 | - add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 88 | - array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 89 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 90 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 91 | - add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 92 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public static function set_definitions() |
|
| 101 | - { |
|
| 102 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 103 | - define('ANS_TEMPLATES_PATH', str_replace( |
|
| 104 | - '\\', |
|
| 105 | - DS, |
|
| 106 | - plugin_dir_path(__FILE__)) . 'templates' . DS |
|
| 107 | - ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @param WP $WP |
|
| 114 | - * @return void |
|
| 115 | - */ |
|
| 116 | - public function run($WP) |
|
| 117 | - { |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - public static function translate_js_strings() |
|
| 126 | - { |
|
| 127 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 128 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 129 | - 'event_espresso' |
|
| 130 | - ); |
|
| 131 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 132 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 133 | - 'event_espresso' |
|
| 134 | - ); |
|
| 135 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 136 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 137 | - 'event_espresso' |
|
| 138 | - ); |
|
| 139 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 140 | - 'The new state was successfully saved to the database.', |
|
| 141 | - 'event_espresso' |
|
| 142 | - ); |
|
| 143 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 144 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 145 | - 'event_espresso' |
|
| 146 | - ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * @return void |
|
| 153 | - */ |
|
| 154 | - public static function wp_enqueue_scripts() |
|
| 155 | - { |
|
| 156 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 157 | - wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 158 | - array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 159 | - wp_enqueue_script('add_new_state'); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * display_add_new_state_micro_form |
|
| 167 | - * |
|
| 168 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 169 | - * @return string |
|
| 170 | - * @throws EE_Error |
|
| 171 | - * @throws InvalidArgumentException |
|
| 172 | - * @throws InvalidDataTypeException |
|
| 173 | - * @throws InvalidInterfaceException |
|
| 174 | - */ |
|
| 175 | - // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 176 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 177 | - { |
|
| 178 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 179 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 180 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 181 | - // is the "state" question in this form section? |
|
| 182 | - $input = $question_group_reg_form->get_subsection('state'); |
|
| 183 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 184 | - //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 185 | - //by forcing it to set it now, like it did while getting the form for display |
|
| 186 | - if ($input instanceof EE_State_Select_Input) { |
|
| 187 | - $input->html_name(); |
|
| 188 | - } |
|
| 189 | - return $question_group_reg_form; |
|
| 190 | - } |
|
| 191 | - // we're only doing this for state select inputs |
|
| 192 | - if ($input instanceof EE_State_Select_Input && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 193 | - // grab any set values from the request |
|
| 194 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 195 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 196 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 197 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 198 | - $country_options = array(); |
|
| 199 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
| 200 | - if (! empty($countries)) { |
|
| 201 | - foreach ($countries as $country) { |
|
| 202 | - if ($country instanceof EE_Country) { |
|
| 203 | - $country_options[$country->ID()] = $country->name(); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 208 | - array( |
|
| 209 | - 'name' => 'new_state_micro_form', |
|
| 210 | - 'html_id' => 'new_state_micro_form', |
|
| 211 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 212 | - 'subsections' => array( |
|
| 213 | - // add hidden input to indicate that a new state is being added |
|
| 214 | - 'add_new_state' => new EE_Hidden_Input( |
|
| 215 | - array( |
|
| 216 | - 'html_name' => str_replace( |
|
| 217 | - 'state', |
|
| 218 | - 'nsmf_add_new_state', |
|
| 219 | - $input->html_name() |
|
| 220 | - ), |
|
| 221 | - 'html_id' => str_replace( |
|
| 222 | - 'state', |
|
| 223 | - 'nsmf_add_new_state', |
|
| 224 | - $input->html_id() |
|
| 225 | - ), |
|
| 226 | - 'default' => 0, |
|
| 227 | - ) |
|
| 228 | - ), |
|
| 229 | - // add link for displaying hidden container |
|
| 230 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
| 231 | - apply_filters( |
|
| 232 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 233 | - EEH_HTML::link( |
|
| 234 | - '', |
|
| 235 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 236 | - '', |
|
| 237 | - 'display-' . $input->html_id(), |
|
| 238 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 239 | - '', |
|
| 240 | - 'data-target="' . $input->html_id() . '"' |
|
| 241 | - ) |
|
| 242 | - ) |
|
| 243 | - ), |
|
| 244 | - // add initial html for hidden container |
|
| 245 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 246 | - apply_filters( |
|
| 247 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 248 | - EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 249 | - 'display: none;') . |
|
| 250 | - EEH_HTML::h6( |
|
| 251 | - esc_html__( |
|
| 252 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 253 | - 'event_espresso' |
|
| 254 | - ) |
|
| 255 | - ) . |
|
| 256 | - EEH_HTML::ul() . |
|
| 257 | - EEH_HTML::li( |
|
| 258 | - esc_html__( |
|
| 259 | - 'first select the Country that your State/Province belongs to', |
|
| 260 | - 'event_espresso' |
|
| 261 | - ) |
|
| 262 | - ) . |
|
| 263 | - EEH_HTML::li( |
|
| 264 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 265 | - ) . |
|
| 266 | - EEH_HTML::li( |
|
| 267 | - esc_html__( |
|
| 268 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 269 | - 'event_espresso' |
|
| 270 | - ) |
|
| 271 | - ) . |
|
| 272 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 273 | - EEH_HTML::ulx() |
|
| 274 | - ) |
|
| 275 | - ), |
|
| 276 | - // NEW STATE COUNTRY |
|
| 277 | - 'new_state_country' => new EE_Country_Select_Input( |
|
| 278 | - $country_options, |
|
| 279 | - array( |
|
| 280 | - 'html_name' => $country_name, |
|
| 281 | - 'html_id' => str_replace( |
|
| 282 | - 'state', |
|
| 283 | - 'nsmf_new_state_country', $input->html_id() |
|
| 284 | - ), |
|
| 285 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 286 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 287 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 288 | - 'required' => false, |
|
| 289 | - ) |
|
| 290 | - ), |
|
| 291 | - // NEW STATE NAME |
|
| 292 | - 'new_state_name' => new EE_Text_Input( |
|
| 293 | - array( |
|
| 294 | - 'html_name' => $state_name, |
|
| 295 | - 'html_id' => str_replace( |
|
| 296 | - 'state', |
|
| 297 | - 'nsmf_new_state_name', $input->html_id() |
|
| 298 | - ), |
|
| 299 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 300 | - 'html_label_text' => esc_html__('New State/Province Name', |
|
| 301 | - 'event_espresso'), |
|
| 302 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 303 | - 'required' => false, |
|
| 304 | - ) |
|
| 305 | - ), |
|
| 306 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 307 | - // NEW STATE NAME |
|
| 308 | - 'new_state_abbrv' => new EE_Text_Input( |
|
| 309 | - array( |
|
| 310 | - 'html_name' => $abbrv_name, |
|
| 311 | - 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 312 | - $input->html_id()), |
|
| 313 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 314 | - 'html_label_text' => esc_html__( |
|
| 315 | - 'New State/Province Abbreviation', |
|
| 316 | - 'event_espresso' |
|
| 317 | - ) . ' *', |
|
| 318 | - 'html_other_attributes' => 'size="24"', |
|
| 319 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 320 | - 'required' => false, |
|
| 321 | - ) |
|
| 322 | - ), |
|
| 323 | - // "submit" button |
|
| 324 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 325 | - apply_filters( |
|
| 326 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 327 | - EEH_HTML::nbsp(3) . |
|
| 328 | - EEH_HTML::link( |
|
| 329 | - '', |
|
| 330 | - esc_html__('ADD', 'event_espresso'), |
|
| 331 | - '', |
|
| 332 | - 'submit-' . $new_state_submit_id, |
|
| 333 | - 'ee-form-add-new-state-submit button button-secondary', |
|
| 334 | - '', |
|
| 335 | - 'data-target="' . $new_state_submit_id . '"' |
|
| 336 | - ) |
|
| 337 | - ) |
|
| 338 | - ), |
|
| 339 | - // extra info |
|
| 340 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 341 | - apply_filters( |
|
| 342 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 343 | - EEH_HTML::br(2) |
|
| 344 | - . |
|
| 345 | - EEH_HTML::div('', '', 'small-text') |
|
| 346 | - . |
|
| 347 | - EEH_HTML::strong( |
|
| 348 | - '* ' . |
|
| 349 | - esc_html__( |
|
| 350 | - 'Don\'t know your State/Province Abbreviation?', |
|
| 351 | - 'event_espresso' |
|
| 352 | - ) |
|
| 353 | - ) |
|
| 354 | - . |
|
| 355 | - EEH_HTML::br() |
|
| 356 | - . |
|
| 357 | - sprintf( |
|
| 358 | - esc_html__( |
|
| 359 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 360 | - 'event_espresso' |
|
| 361 | - ), |
|
| 362 | - EEH_HTML::link( |
|
| 363 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 364 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 365 | - '', |
|
| 366 | - '', |
|
| 367 | - 'ee-form-add-new-state-wiki-lnk', |
|
| 368 | - '', |
|
| 369 | - 'target="_blank"' |
|
| 370 | - ) |
|
| 371 | - ) |
|
| 372 | - . |
|
| 373 | - EEH_HTML::divx() |
|
| 374 | - . |
|
| 375 | - EEH_HTML::br() |
|
| 376 | - . |
|
| 377 | - EEH_HTML::link( |
|
| 378 | - '', |
|
| 379 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 380 | - '', |
|
| 381 | - 'hide-' . $input->html_id(), |
|
| 382 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 383 | - '', |
|
| 384 | - 'data-target="' . $input->html_id() . '"' |
|
| 385 | - ) |
|
| 386 | - . |
|
| 387 | - EEH_HTML::divx() |
|
| 388 | - . |
|
| 389 | - EEH_HTML::br() |
|
| 390 | - ) |
|
| 391 | - ), |
|
| 392 | - ), |
|
| 393 | - ) |
|
| 394 | - ); |
|
| 395 | - $question_group_reg_form->add_subsections( |
|
| 396 | - array('new_state_micro_form' => $new_state_micro_form), |
|
| 397 | - 'state', |
|
| 398 | - false |
|
| 399 | - ); |
|
| 400 | - } |
|
| 401 | - return $question_group_reg_form; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * set_new_state_input_width |
|
| 408 | - * |
|
| 409 | - * @return int|string |
|
| 410 | - * @throws EE_Error |
|
| 411 | - * @throws InvalidArgumentException |
|
| 412 | - * @throws InvalidDataTypeException |
|
| 413 | - * @throws InvalidInterfaceException |
|
| 414 | - * @throws ReflectionException |
|
| 415 | - */ |
|
| 416 | - public static function add_new_state() |
|
| 417 | - { |
|
| 418 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 419 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 420 | - EE_Registry::instance()->load_model('State'); |
|
| 421 | - // grab country ISO code, new state name, and new state abbreviation |
|
| 422 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 423 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 424 | - : false; |
|
| 425 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 426 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 427 | - : false; |
|
| 428 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 429 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 430 | - : false; |
|
| 431 | - if ($state_country && $state_name && $state_abbr) { |
|
| 432 | - $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 433 | - 'CNT_ISO' => strtoupper($state_country), |
|
| 434 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
| 435 | - 'STA_name' => ucwords($state_name), |
|
| 436 | - 'STA_active' => false, |
|
| 437 | - )); |
|
| 438 | - if ($new_state instanceof EE_State) { |
|
| 439 | - // clean house |
|
| 440 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 441 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 442 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 443 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 444 | - // get any existing new states |
|
| 445 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 446 | - 'nsmf_new_states' |
|
| 447 | - ); |
|
| 448 | - $new_states[$new_state->ID()] = $new_state; |
|
| 449 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 450 | - array('nsmf_new_states' => $new_states) |
|
| 451 | - ); |
|
| 452 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 453 | - echo wp_json_encode(array( |
|
| 454 | - 'success' => true, |
|
| 455 | - 'id' => $new_state->ID(), |
|
| 456 | - 'name' => $new_state->name(), |
|
| 457 | - 'abbrev' => $new_state->abbrev(), |
|
| 458 | - 'country_iso' => $new_state->country_iso(), |
|
| 459 | - 'country_name' => $new_state->country()->name(), |
|
| 460 | - )); |
|
| 461 | - exit(); |
|
| 462 | - } |
|
| 463 | - return $new_state->ID(); |
|
| 464 | - } |
|
| 465 | - } else { |
|
| 466 | - $error = esc_html__( |
|
| 467 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 468 | - 'event_espresso' |
|
| 469 | - ); |
|
| 470 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 471 | - echo wp_json_encode(array('error' => $error)); |
|
| 472 | - exit(); |
|
| 473 | - } |
|
| 474 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - return false; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * recursively drills down through request params to remove any that were added by this module |
|
| 484 | - * |
|
| 485 | - * @param array $request_params |
|
| 486 | - * @return array |
|
| 487 | - */ |
|
| 488 | - public static function filter_checkout_request_params($request_params) |
|
| 489 | - { |
|
| 490 | - foreach ($request_params as $form_section) { |
|
| 491 | - if (is_array($form_section)) { |
|
| 492 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 493 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - return $request_params; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - |
|
| 500 | - |
|
| 501 | - /** |
|
| 502 | - * @param array $request_params |
|
| 503 | - * @return array |
|
| 504 | - */ |
|
| 505 | - public static function unset_new_state_request_params($request_params) |
|
| 506 | - { |
|
| 507 | - unset( |
|
| 508 | - $request_params['new_state_micro_form'], |
|
| 509 | - $request_params['new_state_micro_add_new_state'], |
|
| 510 | - $request_params['new_state_micro_new_state_country'], |
|
| 511 | - $request_params['new_state_micro_new_state_name'], |
|
| 512 | - $request_params['new_state_micro_new_state_abbrv'] |
|
| 513 | - ); |
|
| 514 | - return $request_params; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - |
|
| 518 | - |
|
| 519 | - /** |
|
| 520 | - * @param array $props_n_values |
|
| 521 | - * @return bool |
|
| 522 | - * @throws EE_Error |
|
| 523 | - * @throws InvalidArgumentException |
|
| 524 | - * @throws InvalidDataTypeException |
|
| 525 | - * @throws InvalidInterfaceException |
|
| 526 | - */ |
|
| 527 | - public static function save_new_state_to_db($props_n_values = array()) |
|
| 528 | - { |
|
| 529 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 530 | - if (! empty($existing_state)) { |
|
| 531 | - return array_pop($existing_state); |
|
| 532 | - } |
|
| 533 | - $new_state = EE_State::new_instance($props_n_values); |
|
| 534 | - if ($new_state instanceof EE_State) { |
|
| 535 | - $country_settings_url = add_query_arg( |
|
| 536 | - array( |
|
| 537 | - 'page' => 'espresso_general_settings', |
|
| 538 | - 'action' => 'country_settings', |
|
| 539 | - 'country' => $new_state->country_iso(), |
|
| 540 | - ), |
|
| 541 | - admin_url('admin.php') |
|
| 542 | - ); |
|
| 543 | - // if not non-ajax admin |
|
| 544 | - new PersistentAdminNotice( |
|
| 545 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 546 | - sprintf( |
|
| 547 | - esc_html__( |
|
| 548 | - 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 549 | - 'event_espresso' |
|
| 550 | - ), |
|
| 551 | - '<b>' . $new_state->name() . '</b>', |
|
| 552 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 553 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 554 | - '<a href="' |
|
| 555 | - . $country_settings_url |
|
| 556 | - . '">' |
|
| 557 | - . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
| 558 | - 'event_espresso') |
|
| 559 | - . '</a>', |
|
| 560 | - '<br />' |
|
| 561 | - ) |
|
| 562 | - ); |
|
| 563 | - $new_state->save(); |
|
| 564 | - EEM_State::instance()->reset_cached_states(); |
|
| 565 | - return $new_state; |
|
| 566 | - } |
|
| 567 | - return false; |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * @param string $CNT_ISO |
|
| 574 | - * @param string $STA_ID |
|
| 575 | - * @param array $cols_n_values |
|
| 576 | - * @return void |
|
| 577 | - * @throws DomainException |
|
| 578 | - * @throws EE_Error |
|
| 579 | - * @throws InvalidArgumentException |
|
| 580 | - * @throws InvalidDataTypeException |
|
| 581 | - * @throws InvalidInterfaceException |
|
| 582 | - */ |
|
| 583 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 584 | - { |
|
| 585 | - if (! $CNT_ISO) { |
|
| 586 | - EE_Error::add_error( |
|
| 587 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 588 | - __FILE__, |
|
| 589 | - __FUNCTION__, |
|
| 590 | - __LINE__ |
|
| 591 | - ); |
|
| 592 | - } |
|
| 593 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 594 | - : false; |
|
| 595 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 596 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 597 | - if ($state instanceof EE_State) { |
|
| 598 | - $STA_abbrev = $state->abbrev(); |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - if (! $STA_abbrev) { |
|
| 602 | - EE_Error::add_error( |
|
| 603 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 604 | - __FILE__, |
|
| 605 | - __FUNCTION__, |
|
| 606 | - __LINE__ |
|
| 607 | - ); |
|
| 608 | - } |
|
| 609 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 610 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 611 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 612 | - ); |
|
| 613 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * @param EE_State[] $state_options |
|
| 620 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 621 | - * @param EE_Registration $registration |
|
| 622 | - * @param EE_Question $question |
|
| 623 | - * @param $answer |
|
| 624 | - * @return array |
|
| 625 | - * @throws EE_Error |
|
| 626 | - * @throws InvalidArgumentException |
|
| 627 | - * @throws InvalidDataTypeException |
|
| 628 | - * @throws InvalidInterfaceException |
|
| 629 | - */ |
|
| 630 | - public static function inject_new_reg_state_into_options( |
|
| 631 | - $state_options = array(), |
|
| 632 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 633 | - EE_Registration $registration, |
|
| 634 | - EE_Question $question, |
|
| 635 | - $answer |
|
| 636 | - ) { |
|
| 637 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 638 | - && $question->type() === EEM_Question::QST_type_state |
|
| 639 | - ) { |
|
| 640 | - $STA_ID = $answer->value(); |
|
| 641 | - if (! empty($STA_ID)) { |
|
| 642 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 643 | - if ($state instanceof EE_State) { |
|
| 644 | - $country = $state->country(); |
|
| 645 | - if ($country instanceof EE_Country) { |
|
| 646 | - if (! isset($state_options[$country->name()])) { |
|
| 647 | - $state_options[$country->name()] = array(); |
|
| 648 | - } |
|
| 649 | - if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 650 | - $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - return $state_options; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * @param EE_Country[] $country_options |
|
| 663 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 664 | - * @param EE_Registration $registration |
|
| 665 | - * @param EE_Question $question |
|
| 666 | - * @param $answer |
|
| 667 | - * @return array |
|
| 668 | - * @throws EE_Error |
|
| 669 | - * @throws InvalidArgumentException |
|
| 670 | - * @throws InvalidDataTypeException |
|
| 671 | - * @throws InvalidInterfaceException |
|
| 672 | - */ |
|
| 673 | - public static function inject_new_reg_country_into_options( |
|
| 674 | - $country_options = array(), |
|
| 675 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 676 | - EE_Registration $registration, |
|
| 677 | - EE_Question $question, |
|
| 678 | - $answer |
|
| 679 | - ) { |
|
| 680 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 681 | - && $question->type() |
|
| 682 | - === EEM_Question::QST_type_country |
|
| 683 | - ) { |
|
| 684 | - $CNT_ISO = $answer->value(); |
|
| 685 | - if (! empty($CNT_ISO)) { |
|
| 686 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 687 | - if ($country instanceof EE_Country) { |
|
| 688 | - if (! isset($country_options[$CNT_ISO])) { |
|
| 689 | - $country_options[$CNT_ISO] = $country->name(); |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - } |
|
| 693 | - } |
|
| 694 | - return $country_options; |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - |
|
| 698 | - |
|
| 699 | - /** |
|
| 700 | - * @param EE_State[] $state_options |
|
| 701 | - * @return array |
|
| 702 | - * @throws EE_Error |
|
| 703 | - * @throws InvalidArgumentException |
|
| 704 | - * @throws InvalidDataTypeException |
|
| 705 | - * @throws InvalidInterfaceException |
|
| 706 | - */ |
|
| 707 | - public static function state_options($state_options = array()) |
|
| 708 | - { |
|
| 709 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 710 | - foreach ($new_states as $new_state) { |
|
| 711 | - if ( |
|
| 712 | - $new_state instanceof EE_State |
|
| 713 | - && $new_state->country() instanceof EE_Country |
|
| 714 | - ) { |
|
| 715 | - $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - return $state_options; |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - |
|
| 722 | - |
|
| 723 | - /** |
|
| 724 | - * @return array |
|
| 725 | - * @throws InvalidArgumentException |
|
| 726 | - * @throws InvalidDataTypeException |
|
| 727 | - * @throws InvalidInterfaceException |
|
| 728 | - */ |
|
| 729 | - protected static function _get_new_states() |
|
| 730 | - { |
|
| 731 | - $new_states = array(); |
|
| 732 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 733 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 734 | - 'nsmf_new_states' |
|
| 735 | - ); |
|
| 736 | - } |
|
| 737 | - return is_array($new_states) ? $new_states : array(); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - |
|
| 741 | - |
|
| 742 | - /** |
|
| 743 | - * @param EE_Country[] $country_options |
|
| 744 | - * @return array |
|
| 745 | - * @throws EE_Error |
|
| 746 | - * @throws InvalidArgumentException |
|
| 747 | - * @throws InvalidDataTypeException |
|
| 748 | - * @throws InvalidInterfaceException |
|
| 749 | - */ |
|
| 750 | - public static function country_options($country_options = array()) |
|
| 751 | - { |
|
| 752 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 753 | - foreach ($new_states as $new_state) { |
|
| 754 | - if ( |
|
| 755 | - $new_state instanceof EE_State |
|
| 756 | - && $new_state->country() instanceof EE_Country |
|
| 757 | - ) { |
|
| 758 | - $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - return $country_options; |
|
| 762 | - } |
|
| 25 | + /** |
|
| 26 | + * @return EED_Module|EED_Add_New_State |
|
| 27 | + */ |
|
| 28 | + public static function instance() |
|
| 29 | + { |
|
| 30 | + return parent::get_instance(__CLASS__); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 37 | + * |
|
| 38 | + * @return void |
|
| 39 | + */ |
|
| 40 | + public static function set_hooks() |
|
| 41 | + { |
|
| 42 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 43 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 44 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 45 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 46 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 47 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 48 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 49 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 50 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 51 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 52 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 53 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 54 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 55 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 56 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 57 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 58 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 65 | + * |
|
| 66 | + * @return void |
|
| 67 | + */ |
|
| 68 | + public static function set_hooks_admin() |
|
| 69 | + { |
|
| 70 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 71 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 72 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 73 | + add_filter('FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 74 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), 1, 1); |
|
| 75 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 76 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 77 | + add_filter('FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 78 | + array('EED_Add_New_State', 'unset_new_state_request_params'), 10, 1); |
|
| 79 | + add_action('AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 80 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 81 | + add_action('AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 82 | + array('EED_Add_New_State', 'update_country_settings'), 10, 3); |
|
| 83 | + add_filter('FHEE__EE_State_Select_Input____construct__state_options', |
|
| 84 | + array('EED_Add_New_State', 'state_options'), 10, 1); |
|
| 85 | + add_filter('FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 86 | + array('EED_Add_New_State', 'country_options'), 10, 1); |
|
| 87 | + add_filter('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 88 | + array('EED_Add_New_State', 'filter_checkout_request_params'), 10, 1); |
|
| 89 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 90 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), 10, 5); |
|
| 91 | + add_filter('FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 92 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), 10, 5); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public static function set_definitions() |
|
| 101 | + { |
|
| 102 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 103 | + define('ANS_TEMPLATES_PATH', str_replace( |
|
| 104 | + '\\', |
|
| 105 | + DS, |
|
| 106 | + plugin_dir_path(__FILE__)) . 'templates' . DS |
|
| 107 | + ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @param WP $WP |
|
| 114 | + * @return void |
|
| 115 | + */ |
|
| 116 | + public function run($WP) |
|
| 117 | + { |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + public static function translate_js_strings() |
|
| 126 | + { |
|
| 127 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 128 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 129 | + 'event_espresso' |
|
| 130 | + ); |
|
| 131 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 132 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 133 | + 'event_espresso' |
|
| 134 | + ); |
|
| 135 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 136 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 137 | + 'event_espresso' |
|
| 138 | + ); |
|
| 139 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 140 | + 'The new state was successfully saved to the database.', |
|
| 141 | + 'event_espresso' |
|
| 142 | + ); |
|
| 143 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 144 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 145 | + 'event_espresso' |
|
| 146 | + ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * @return void |
|
| 153 | + */ |
|
| 154 | + public static function wp_enqueue_scripts() |
|
| 155 | + { |
|
| 156 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 157 | + wp_register_script('add_new_state', ANS_ASSETS_URL . 'add_new_state.js', |
|
| 158 | + array('espresso_core', 'single_page_checkout'), EVENT_ESPRESSO_VERSION, true); |
|
| 159 | + wp_enqueue_script('add_new_state'); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * display_add_new_state_micro_form |
|
| 167 | + * |
|
| 168 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 169 | + * @return string |
|
| 170 | + * @throws EE_Error |
|
| 171 | + * @throws InvalidArgumentException |
|
| 172 | + * @throws InvalidDataTypeException |
|
| 173 | + * @throws InvalidInterfaceException |
|
| 174 | + */ |
|
| 175 | + // public static function display_add_new_state_micro_form( $html, EE_Form_Input_With_Options_Base $input ){ |
|
| 176 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 177 | + { |
|
| 178 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 179 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 180 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 181 | + // is the "state" question in this form section? |
|
| 182 | + $input = $question_group_reg_form->get_subsection('state'); |
|
| 183 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 184 | + //ok then all we need to do is make sure the input's HTML name is consistent |
|
| 185 | + //by forcing it to set it now, like it did while getting the form for display |
|
| 186 | + if ($input instanceof EE_State_Select_Input) { |
|
| 187 | + $input->html_name(); |
|
| 188 | + } |
|
| 189 | + return $question_group_reg_form; |
|
| 190 | + } |
|
| 191 | + // we're only doing this for state select inputs |
|
| 192 | + if ($input instanceof EE_State_Select_Input && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 193 | + // grab any set values from the request |
|
| 194 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 195 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 196 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 197 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 198 | + $country_options = array(); |
|
| 199 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
| 200 | + if (! empty($countries)) { |
|
| 201 | + foreach ($countries as $country) { |
|
| 202 | + if ($country instanceof EE_Country) { |
|
| 203 | + $country_options[$country->ID()] = $country->name(); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 208 | + array( |
|
| 209 | + 'name' => 'new_state_micro_form', |
|
| 210 | + 'html_id' => 'new_state_micro_form', |
|
| 211 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 212 | + 'subsections' => array( |
|
| 213 | + // add hidden input to indicate that a new state is being added |
|
| 214 | + 'add_new_state' => new EE_Hidden_Input( |
|
| 215 | + array( |
|
| 216 | + 'html_name' => str_replace( |
|
| 217 | + 'state', |
|
| 218 | + 'nsmf_add_new_state', |
|
| 219 | + $input->html_name() |
|
| 220 | + ), |
|
| 221 | + 'html_id' => str_replace( |
|
| 222 | + 'state', |
|
| 223 | + 'nsmf_add_new_state', |
|
| 224 | + $input->html_id() |
|
| 225 | + ), |
|
| 226 | + 'default' => 0, |
|
| 227 | + ) |
|
| 228 | + ), |
|
| 229 | + // add link for displaying hidden container |
|
| 230 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
| 231 | + apply_filters( |
|
| 232 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 233 | + EEH_HTML::link( |
|
| 234 | + '', |
|
| 235 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 236 | + '', |
|
| 237 | + 'display-' . $input->html_id(), |
|
| 238 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 239 | + '', |
|
| 240 | + 'data-target="' . $input->html_id() . '"' |
|
| 241 | + ) |
|
| 242 | + ) |
|
| 243 | + ), |
|
| 244 | + // add initial html for hidden container |
|
| 245 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 246 | + apply_filters( |
|
| 247 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 248 | + EEH_HTML::div('', $input->html_id() . '-dv', 'ee-form-add-new-state-dv', |
|
| 249 | + 'display: none;') . |
|
| 250 | + EEH_HTML::h6( |
|
| 251 | + esc_html__( |
|
| 252 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 253 | + 'event_espresso' |
|
| 254 | + ) |
|
| 255 | + ) . |
|
| 256 | + EEH_HTML::ul() . |
|
| 257 | + EEH_HTML::li( |
|
| 258 | + esc_html__( |
|
| 259 | + 'first select the Country that your State/Province belongs to', |
|
| 260 | + 'event_espresso' |
|
| 261 | + ) |
|
| 262 | + ) . |
|
| 263 | + EEH_HTML::li( |
|
| 264 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 265 | + ) . |
|
| 266 | + EEH_HTML::li( |
|
| 267 | + esc_html__( |
|
| 268 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 269 | + 'event_espresso' |
|
| 270 | + ) |
|
| 271 | + ) . |
|
| 272 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 273 | + EEH_HTML::ulx() |
|
| 274 | + ) |
|
| 275 | + ), |
|
| 276 | + // NEW STATE COUNTRY |
|
| 277 | + 'new_state_country' => new EE_Country_Select_Input( |
|
| 278 | + $country_options, |
|
| 279 | + array( |
|
| 280 | + 'html_name' => $country_name, |
|
| 281 | + 'html_id' => str_replace( |
|
| 282 | + 'state', |
|
| 283 | + 'nsmf_new_state_country', $input->html_id() |
|
| 284 | + ), |
|
| 285 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
| 286 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 287 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 288 | + 'required' => false, |
|
| 289 | + ) |
|
| 290 | + ), |
|
| 291 | + // NEW STATE NAME |
|
| 292 | + 'new_state_name' => new EE_Text_Input( |
|
| 293 | + array( |
|
| 294 | + 'html_name' => $state_name, |
|
| 295 | + 'html_id' => str_replace( |
|
| 296 | + 'state', |
|
| 297 | + 'nsmf_new_state_name', $input->html_id() |
|
| 298 | + ), |
|
| 299 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
| 300 | + 'html_label_text' => esc_html__('New State/Province Name', |
|
| 301 | + 'event_espresso'), |
|
| 302 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 303 | + 'required' => false, |
|
| 304 | + ) |
|
| 305 | + ), |
|
| 306 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 307 | + // NEW STATE NAME |
|
| 308 | + 'new_state_abbrv' => new EE_Text_Input( |
|
| 309 | + array( |
|
| 310 | + 'html_name' => $abbrv_name, |
|
| 311 | + 'html_id' => str_replace('state', 'nsmf_new_state_abbrv', |
|
| 312 | + $input->html_id()), |
|
| 313 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 314 | + 'html_label_text' => esc_html__( |
|
| 315 | + 'New State/Province Abbreviation', |
|
| 316 | + 'event_espresso' |
|
| 317 | + ) . ' *', |
|
| 318 | + 'html_other_attributes' => 'size="24"', |
|
| 319 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 320 | + 'required' => false, |
|
| 321 | + ) |
|
| 322 | + ), |
|
| 323 | + // "submit" button |
|
| 324 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 325 | + apply_filters( |
|
| 326 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 327 | + EEH_HTML::nbsp(3) . |
|
| 328 | + EEH_HTML::link( |
|
| 329 | + '', |
|
| 330 | + esc_html__('ADD', 'event_espresso'), |
|
| 331 | + '', |
|
| 332 | + 'submit-' . $new_state_submit_id, |
|
| 333 | + 'ee-form-add-new-state-submit button button-secondary', |
|
| 334 | + '', |
|
| 335 | + 'data-target="' . $new_state_submit_id . '"' |
|
| 336 | + ) |
|
| 337 | + ) |
|
| 338 | + ), |
|
| 339 | + // extra info |
|
| 340 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 341 | + apply_filters( |
|
| 342 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 343 | + EEH_HTML::br(2) |
|
| 344 | + . |
|
| 345 | + EEH_HTML::div('', '', 'small-text') |
|
| 346 | + . |
|
| 347 | + EEH_HTML::strong( |
|
| 348 | + '* ' . |
|
| 349 | + esc_html__( |
|
| 350 | + 'Don\'t know your State/Province Abbreviation?', |
|
| 351 | + 'event_espresso' |
|
| 352 | + ) |
|
| 353 | + ) |
|
| 354 | + . |
|
| 355 | + EEH_HTML::br() |
|
| 356 | + . |
|
| 357 | + sprintf( |
|
| 358 | + esc_html__( |
|
| 359 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 360 | + 'event_espresso' |
|
| 361 | + ), |
|
| 362 | + EEH_HTML::link( |
|
| 363 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 364 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 365 | + '', |
|
| 366 | + '', |
|
| 367 | + 'ee-form-add-new-state-wiki-lnk', |
|
| 368 | + '', |
|
| 369 | + 'target="_blank"' |
|
| 370 | + ) |
|
| 371 | + ) |
|
| 372 | + . |
|
| 373 | + EEH_HTML::divx() |
|
| 374 | + . |
|
| 375 | + EEH_HTML::br() |
|
| 376 | + . |
|
| 377 | + EEH_HTML::link( |
|
| 378 | + '', |
|
| 379 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 380 | + '', |
|
| 381 | + 'hide-' . $input->html_id(), |
|
| 382 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 383 | + '', |
|
| 384 | + 'data-target="' . $input->html_id() . '"' |
|
| 385 | + ) |
|
| 386 | + . |
|
| 387 | + EEH_HTML::divx() |
|
| 388 | + . |
|
| 389 | + EEH_HTML::br() |
|
| 390 | + ) |
|
| 391 | + ), |
|
| 392 | + ), |
|
| 393 | + ) |
|
| 394 | + ); |
|
| 395 | + $question_group_reg_form->add_subsections( |
|
| 396 | + array('new_state_micro_form' => $new_state_micro_form), |
|
| 397 | + 'state', |
|
| 398 | + false |
|
| 399 | + ); |
|
| 400 | + } |
|
| 401 | + return $question_group_reg_form; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * set_new_state_input_width |
|
| 408 | + * |
|
| 409 | + * @return int|string |
|
| 410 | + * @throws EE_Error |
|
| 411 | + * @throws InvalidArgumentException |
|
| 412 | + * @throws InvalidDataTypeException |
|
| 413 | + * @throws InvalidInterfaceException |
|
| 414 | + * @throws ReflectionException |
|
| 415 | + */ |
|
| 416 | + public static function add_new_state() |
|
| 417 | + { |
|
| 418 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 419 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 420 | + EE_Registry::instance()->load_model('State'); |
|
| 421 | + // grab country ISO code, new state name, and new state abbreviation |
|
| 422 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 423 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 424 | + : false; |
|
| 425 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 426 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 427 | + : false; |
|
| 428 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 429 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 430 | + : false; |
|
| 431 | + if ($state_country && $state_name && $state_abbr) { |
|
| 432 | + $new_state = EED_Add_New_State::save_new_state_to_db(array( |
|
| 433 | + 'CNT_ISO' => strtoupper($state_country), |
|
| 434 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
| 435 | + 'STA_name' => ucwords($state_name), |
|
| 436 | + 'STA_active' => false, |
|
| 437 | + )); |
|
| 438 | + if ($new_state instanceof EE_State) { |
|
| 439 | + // clean house |
|
| 440 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 441 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 442 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 443 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 444 | + // get any existing new states |
|
| 445 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 446 | + 'nsmf_new_states' |
|
| 447 | + ); |
|
| 448 | + $new_states[$new_state->ID()] = $new_state; |
|
| 449 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 450 | + array('nsmf_new_states' => $new_states) |
|
| 451 | + ); |
|
| 452 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 453 | + echo wp_json_encode(array( |
|
| 454 | + 'success' => true, |
|
| 455 | + 'id' => $new_state->ID(), |
|
| 456 | + 'name' => $new_state->name(), |
|
| 457 | + 'abbrev' => $new_state->abbrev(), |
|
| 458 | + 'country_iso' => $new_state->country_iso(), |
|
| 459 | + 'country_name' => $new_state->country()->name(), |
|
| 460 | + )); |
|
| 461 | + exit(); |
|
| 462 | + } |
|
| 463 | + return $new_state->ID(); |
|
| 464 | + } |
|
| 465 | + } else { |
|
| 466 | + $error = esc_html__( |
|
| 467 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 468 | + 'event_espresso' |
|
| 469 | + ); |
|
| 470 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 471 | + echo wp_json_encode(array('error' => $error)); |
|
| 472 | + exit(); |
|
| 473 | + } |
|
| 474 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + return false; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * recursively drills down through request params to remove any that were added by this module |
|
| 484 | + * |
|
| 485 | + * @param array $request_params |
|
| 486 | + * @return array |
|
| 487 | + */ |
|
| 488 | + public static function filter_checkout_request_params($request_params) |
|
| 489 | + { |
|
| 490 | + foreach ($request_params as $form_section) { |
|
| 491 | + if (is_array($form_section)) { |
|
| 492 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 493 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + return $request_params; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + |
|
| 500 | + |
|
| 501 | + /** |
|
| 502 | + * @param array $request_params |
|
| 503 | + * @return array |
|
| 504 | + */ |
|
| 505 | + public static function unset_new_state_request_params($request_params) |
|
| 506 | + { |
|
| 507 | + unset( |
|
| 508 | + $request_params['new_state_micro_form'], |
|
| 509 | + $request_params['new_state_micro_add_new_state'], |
|
| 510 | + $request_params['new_state_micro_new_state_country'], |
|
| 511 | + $request_params['new_state_micro_new_state_name'], |
|
| 512 | + $request_params['new_state_micro_new_state_abbrv'] |
|
| 513 | + ); |
|
| 514 | + return $request_params; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + |
|
| 518 | + |
|
| 519 | + /** |
|
| 520 | + * @param array $props_n_values |
|
| 521 | + * @return bool |
|
| 522 | + * @throws EE_Error |
|
| 523 | + * @throws InvalidArgumentException |
|
| 524 | + * @throws InvalidDataTypeException |
|
| 525 | + * @throws InvalidInterfaceException |
|
| 526 | + */ |
|
| 527 | + public static function save_new_state_to_db($props_n_values = array()) |
|
| 528 | + { |
|
| 529 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 530 | + if (! empty($existing_state)) { |
|
| 531 | + return array_pop($existing_state); |
|
| 532 | + } |
|
| 533 | + $new_state = EE_State::new_instance($props_n_values); |
|
| 534 | + if ($new_state instanceof EE_State) { |
|
| 535 | + $country_settings_url = add_query_arg( |
|
| 536 | + array( |
|
| 537 | + 'page' => 'espresso_general_settings', |
|
| 538 | + 'action' => 'country_settings', |
|
| 539 | + 'country' => $new_state->country_iso(), |
|
| 540 | + ), |
|
| 541 | + admin_url('admin.php') |
|
| 542 | + ); |
|
| 543 | + // if not non-ajax admin |
|
| 544 | + new PersistentAdminNotice( |
|
| 545 | + 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 546 | + sprintf( |
|
| 547 | + esc_html__( |
|
| 548 | + 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 549 | + 'event_espresso' |
|
| 550 | + ), |
|
| 551 | + '<b>' . $new_state->name() . '</b>', |
|
| 552 | + '<b>' . $new_state->abbrev() . '</b>', |
|
| 553 | + '<b>' . $new_state->country()->name() . '</b>', |
|
| 554 | + '<a href="' |
|
| 555 | + . $country_settings_url |
|
| 556 | + . '">' |
|
| 557 | + . esc_html__('Event Espresso - General Settings > Countries Tab', |
|
| 558 | + 'event_espresso') |
|
| 559 | + . '</a>', |
|
| 560 | + '<br />' |
|
| 561 | + ) |
|
| 562 | + ); |
|
| 563 | + $new_state->save(); |
|
| 564 | + EEM_State::instance()->reset_cached_states(); |
|
| 565 | + return $new_state; |
|
| 566 | + } |
|
| 567 | + return false; |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * @param string $CNT_ISO |
|
| 574 | + * @param string $STA_ID |
|
| 575 | + * @param array $cols_n_values |
|
| 576 | + * @return void |
|
| 577 | + * @throws DomainException |
|
| 578 | + * @throws EE_Error |
|
| 579 | + * @throws InvalidArgumentException |
|
| 580 | + * @throws InvalidDataTypeException |
|
| 581 | + * @throws InvalidInterfaceException |
|
| 582 | + */ |
|
| 583 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 584 | + { |
|
| 585 | + if (! $CNT_ISO) { |
|
| 586 | + EE_Error::add_error( |
|
| 587 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 588 | + __FILE__, |
|
| 589 | + __FUNCTION__, |
|
| 590 | + __LINE__ |
|
| 591 | + ); |
|
| 592 | + } |
|
| 593 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 594 | + : false; |
|
| 595 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 596 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 597 | + if ($state instanceof EE_State) { |
|
| 598 | + $STA_abbrev = $state->abbrev(); |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + if (! $STA_abbrev) { |
|
| 602 | + EE_Error::add_error( |
|
| 603 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 604 | + __FILE__, |
|
| 605 | + __FUNCTION__, |
|
| 606 | + __LINE__ |
|
| 607 | + ); |
|
| 608 | + } |
|
| 609 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 610 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 611 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 612 | + ); |
|
| 613 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * @param EE_State[] $state_options |
|
| 620 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 621 | + * @param EE_Registration $registration |
|
| 622 | + * @param EE_Question $question |
|
| 623 | + * @param $answer |
|
| 624 | + * @return array |
|
| 625 | + * @throws EE_Error |
|
| 626 | + * @throws InvalidArgumentException |
|
| 627 | + * @throws InvalidDataTypeException |
|
| 628 | + * @throws InvalidInterfaceException |
|
| 629 | + */ |
|
| 630 | + public static function inject_new_reg_state_into_options( |
|
| 631 | + $state_options = array(), |
|
| 632 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 633 | + EE_Registration $registration, |
|
| 634 | + EE_Question $question, |
|
| 635 | + $answer |
|
| 636 | + ) { |
|
| 637 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 638 | + && $question->type() === EEM_Question::QST_type_state |
|
| 639 | + ) { |
|
| 640 | + $STA_ID = $answer->value(); |
|
| 641 | + if (! empty($STA_ID)) { |
|
| 642 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 643 | + if ($state instanceof EE_State) { |
|
| 644 | + $country = $state->country(); |
|
| 645 | + if ($country instanceof EE_Country) { |
|
| 646 | + if (! isset($state_options[$country->name()])) { |
|
| 647 | + $state_options[$country->name()] = array(); |
|
| 648 | + } |
|
| 649 | + if (! isset($state_options[$country->name()][$STA_ID])) { |
|
| 650 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + return $state_options; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * @param EE_Country[] $country_options |
|
| 663 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 664 | + * @param EE_Registration $registration |
|
| 665 | + * @param EE_Question $question |
|
| 666 | + * @param $answer |
|
| 667 | + * @return array |
|
| 668 | + * @throws EE_Error |
|
| 669 | + * @throws InvalidArgumentException |
|
| 670 | + * @throws InvalidDataTypeException |
|
| 671 | + * @throws InvalidInterfaceException |
|
| 672 | + */ |
|
| 673 | + public static function inject_new_reg_country_into_options( |
|
| 674 | + $country_options = array(), |
|
| 675 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 676 | + EE_Registration $registration, |
|
| 677 | + EE_Question $question, |
|
| 678 | + $answer |
|
| 679 | + ) { |
|
| 680 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 681 | + && $question->type() |
|
| 682 | + === EEM_Question::QST_type_country |
|
| 683 | + ) { |
|
| 684 | + $CNT_ISO = $answer->value(); |
|
| 685 | + if (! empty($CNT_ISO)) { |
|
| 686 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 687 | + if ($country instanceof EE_Country) { |
|
| 688 | + if (! isset($country_options[$CNT_ISO])) { |
|
| 689 | + $country_options[$CNT_ISO] = $country->name(); |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + } |
|
| 693 | + } |
|
| 694 | + return $country_options; |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + |
|
| 698 | + |
|
| 699 | + /** |
|
| 700 | + * @param EE_State[] $state_options |
|
| 701 | + * @return array |
|
| 702 | + * @throws EE_Error |
|
| 703 | + * @throws InvalidArgumentException |
|
| 704 | + * @throws InvalidDataTypeException |
|
| 705 | + * @throws InvalidInterfaceException |
|
| 706 | + */ |
|
| 707 | + public static function state_options($state_options = array()) |
|
| 708 | + { |
|
| 709 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 710 | + foreach ($new_states as $new_state) { |
|
| 711 | + if ( |
|
| 712 | + $new_state instanceof EE_State |
|
| 713 | + && $new_state->country() instanceof EE_Country |
|
| 714 | + ) { |
|
| 715 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + return $state_options; |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + |
|
| 722 | + |
|
| 723 | + /** |
|
| 724 | + * @return array |
|
| 725 | + * @throws InvalidArgumentException |
|
| 726 | + * @throws InvalidDataTypeException |
|
| 727 | + * @throws InvalidInterfaceException |
|
| 728 | + */ |
|
| 729 | + protected static function _get_new_states() |
|
| 730 | + { |
|
| 731 | + $new_states = array(); |
|
| 732 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 733 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 734 | + 'nsmf_new_states' |
|
| 735 | + ); |
|
| 736 | + } |
|
| 737 | + return is_array($new_states) ? $new_states : array(); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + |
|
| 741 | + |
|
| 742 | + /** |
|
| 743 | + * @param EE_Country[] $country_options |
|
| 744 | + * @return array |
|
| 745 | + * @throws EE_Error |
|
| 746 | + * @throws InvalidArgumentException |
|
| 747 | + * @throws InvalidDataTypeException |
|
| 748 | + * @throws InvalidInterfaceException |
|
| 749 | + */ |
|
| 750 | + public static function country_options($country_options = array()) |
|
| 751 | + { |
|
| 752 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 753 | + foreach ($new_states as $new_state) { |
|
| 754 | + if ( |
|
| 755 | + $new_state instanceof EE_State |
|
| 756 | + && $new_state->country() instanceof EE_Country |
|
| 757 | + ) { |
|
| 758 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + return $country_options; |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | 764 | |
| 765 | 765 | |
@@ -27,746 +27,746 @@ |
||
| 27 | 27 | class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee |
| 28 | 28 | { |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Sets some dynamic defaults |
|
| 32 | - * |
|
| 33 | - * @param array $fieldValues |
|
| 34 | - * @param bool $bydb |
|
| 35 | - * @param string $timezone |
|
| 36 | - * @param array $date_formats |
|
| 37 | - * @throws EE_Error |
|
| 38 | - */ |
|
| 39 | - protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
| 40 | - { |
|
| 41 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 43 | - $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 44 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 45 | - } |
|
| 46 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 47 | - // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 48 | - $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 49 | - } |
|
| 50 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 51 | - $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 52 | - } |
|
| 53 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param array $props_n_values incoming values |
|
| 59 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 60 | - * used.) |
|
| 61 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 62 | - * date_format and the second value is the time format |
|
| 63 | - * @return EE_Attendee |
|
| 64 | - * @throws EE_Error |
|
| 65 | - */ |
|
| 66 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 67 | - { |
|
| 68 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 69 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param array $props_n_values incoming values from the database |
|
| 75 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 76 | - * the website will be used. |
|
| 77 | - * @return EE_Attendee |
|
| 78 | - */ |
|
| 79 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 80 | - { |
|
| 81 | - return new self($props_n_values, true, $timezone); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Set Attendee First Name |
|
| 87 | - * |
|
| 88 | - * @access public |
|
| 89 | - * @param string $fname |
|
| 90 | - * @throws EE_Error |
|
| 91 | - */ |
|
| 92 | - public function set_fname($fname = '') |
|
| 93 | - { |
|
| 94 | - $this->set('ATT_fname', $fname); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Set Attendee Last Name |
|
| 100 | - * |
|
| 101 | - * @access public |
|
| 102 | - * @param string $lname |
|
| 103 | - * @throws EE_Error |
|
| 104 | - */ |
|
| 105 | - public function set_lname($lname = '') |
|
| 106 | - { |
|
| 107 | - $this->set('ATT_lname', $lname); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Set Attendee Address |
|
| 113 | - * |
|
| 114 | - * @access public |
|
| 115 | - * @param string $address |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function set_address($address = '') |
|
| 119 | - { |
|
| 120 | - $this->set('ATT_address', $address); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Set Attendee Address2 |
|
| 126 | - * |
|
| 127 | - * @access public |
|
| 128 | - * @param string $address2 |
|
| 129 | - * @throws EE_Error |
|
| 130 | - */ |
|
| 131 | - public function set_address2($address2 = '') |
|
| 132 | - { |
|
| 133 | - $this->set('ATT_address2', $address2); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Set Attendee City |
|
| 139 | - * |
|
| 140 | - * @access public |
|
| 141 | - * @param string $city |
|
| 142 | - * @throws EE_Error |
|
| 143 | - */ |
|
| 144 | - public function set_city($city = '') |
|
| 145 | - { |
|
| 146 | - $this->set('ATT_city', $city); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Set Attendee State ID |
|
| 152 | - * |
|
| 153 | - * @access public |
|
| 154 | - * @param int $STA_ID |
|
| 155 | - * @throws EE_Error |
|
| 156 | - */ |
|
| 157 | - public function set_state($STA_ID = 0) |
|
| 158 | - { |
|
| 159 | - $this->set('STA_ID', $STA_ID); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Set Attendee Country ISO Code |
|
| 165 | - * |
|
| 166 | - * @access public |
|
| 167 | - * @param string $CNT_ISO |
|
| 168 | - * @throws EE_Error |
|
| 169 | - */ |
|
| 170 | - public function set_country($CNT_ISO = '') |
|
| 171 | - { |
|
| 172 | - $this->set('CNT_ISO', $CNT_ISO); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Set Attendee Zip/Postal Code |
|
| 178 | - * |
|
| 179 | - * @access public |
|
| 180 | - * @param string $zip |
|
| 181 | - * @throws EE_Error |
|
| 182 | - */ |
|
| 183 | - public function set_zip($zip = '') |
|
| 184 | - { |
|
| 185 | - $this->set('ATT_zip', $zip); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Set Attendee Email Address |
|
| 191 | - * |
|
| 192 | - * @access public |
|
| 193 | - * @param string $email |
|
| 194 | - * @throws EE_Error |
|
| 195 | - */ |
|
| 196 | - public function set_email($email = '') |
|
| 197 | - { |
|
| 198 | - $this->set('ATT_email', $email); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Set Attendee Phone |
|
| 204 | - * |
|
| 205 | - * @access public |
|
| 206 | - * @param string $phone |
|
| 207 | - * @throws EE_Error |
|
| 208 | - */ |
|
| 209 | - public function set_phone($phone = '') |
|
| 210 | - { |
|
| 211 | - $this->set('ATT_phone', $phone); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * set deleted |
|
| 217 | - * |
|
| 218 | - * @access public |
|
| 219 | - * @param bool $ATT_deleted |
|
| 220 | - * @throws EE_Error |
|
| 221 | - */ |
|
| 222 | - public function set_deleted($ATT_deleted = false) |
|
| 223 | - { |
|
| 224 | - $this->set('ATT_deleted', $ATT_deleted); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Returns the value for the post_author id saved with the cpt |
|
| 230 | - * |
|
| 231 | - * @since 4.5.0 |
|
| 232 | - * @return int |
|
| 233 | - * @throws EE_Error |
|
| 234 | - */ |
|
| 235 | - public function wp_user() |
|
| 236 | - { |
|
| 237 | - return $this->get('ATT_author'); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * get Attendee First Name |
|
| 243 | - * |
|
| 244 | - * @access public |
|
| 245 | - * @return string |
|
| 246 | - * @throws EE_Error |
|
| 247 | - */ |
|
| 248 | - public function fname() |
|
| 249 | - { |
|
| 250 | - return $this->get('ATT_fname'); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * echoes out the attendee's first name |
|
| 256 | - * |
|
| 257 | - * @return void |
|
| 258 | - * @throws EE_Error |
|
| 259 | - */ |
|
| 260 | - public function e_full_name() |
|
| 261 | - { |
|
| 262 | - echo $this->full_name(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Returns the first and last name concatenated together with a space. |
|
| 268 | - * |
|
| 269 | - * @param bool $apply_html_entities |
|
| 270 | - * @return string |
|
| 271 | - * @throws EE_Error |
|
| 272 | - */ |
|
| 273 | - public function full_name($apply_html_entities = false) |
|
| 274 | - { |
|
| 275 | - $full_name = array( |
|
| 276 | - $this->fname(), |
|
| 277 | - $this->lname(), |
|
| 278 | - ); |
|
| 279 | - $full_name = array_filter($full_name); |
|
| 280 | - $full_name = implode(' ', $full_name); |
|
| 281 | - return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - |
|
| 285 | - /** |
|
| 286 | - * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
| 287 | - * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
| 288 | - * attendee. |
|
| 289 | - * |
|
| 290 | - * @param bool $apply_html_entities |
|
| 291 | - * @return string |
|
| 292 | - * @throws EE_Error |
|
| 293 | - */ |
|
| 294 | - public function ATT_full_name($apply_html_entities = false) |
|
| 295 | - { |
|
| 296 | - return $apply_html_entities |
|
| 297 | - ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
| 298 | - : $this->get('ATT_full_name'); |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * get Attendee Last Name |
|
| 304 | - * |
|
| 305 | - * @access public |
|
| 306 | - * @return string |
|
| 307 | - * @throws EE_Error |
|
| 308 | - */ |
|
| 309 | - public function lname() |
|
| 310 | - { |
|
| 311 | - return $this->get('ATT_lname'); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
| 317 | - * |
|
| 318 | - * @return array numerically indexed, with each part of the address that is known. |
|
| 319 | - * Eg, if the user only responded to state and country, |
|
| 320 | - * it would be array(0=>'Alabama',1=>'USA') |
|
| 321 | - * @return array |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - public function full_address_as_array() |
|
| 325 | - { |
|
| 326 | - $full_address_array = array(); |
|
| 327 | - $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
| 328 | - foreach ($initial_address_fields as $address_field_name) { |
|
| 329 | - $address_fields_value = $this->get($address_field_name); |
|
| 330 | - if (! empty($address_fields_value)) { |
|
| 331 | - $full_address_array[] = $address_fields_value; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - //now handle state and country |
|
| 335 | - $state_obj = $this->state_obj(); |
|
| 336 | - if ($state_obj instanceof EE_State) { |
|
| 337 | - $full_address_array[] = $state_obj->name(); |
|
| 338 | - } |
|
| 339 | - $country_obj = $this->country_obj(); |
|
| 340 | - if ($country_obj instanceof EE_Country) { |
|
| 341 | - $full_address_array[] = $country_obj->name(); |
|
| 342 | - } |
|
| 343 | - //lastly get the xip |
|
| 344 | - $zip_value = $this->zip(); |
|
| 345 | - if (! empty($zip_value)) { |
|
| 346 | - $full_address_array[] = $zip_value; |
|
| 347 | - } |
|
| 348 | - return $full_address_array; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * get Attendee Address |
|
| 354 | - * |
|
| 355 | - * @return string |
|
| 356 | - * @throws EE_Error |
|
| 357 | - */ |
|
| 358 | - public function address() |
|
| 359 | - { |
|
| 360 | - return $this->get('ATT_address'); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * get Attendee Address2 |
|
| 366 | - * |
|
| 367 | - * @return string |
|
| 368 | - * @throws EE_Error |
|
| 369 | - */ |
|
| 370 | - public function address2() |
|
| 371 | - { |
|
| 372 | - return $this->get('ATT_address2'); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * get Attendee City |
|
| 378 | - * |
|
| 379 | - * @return string |
|
| 380 | - * @throws EE_Error |
|
| 381 | - */ |
|
| 382 | - public function city() |
|
| 383 | - { |
|
| 384 | - return $this->get('ATT_city'); |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - /** |
|
| 389 | - * get Attendee State ID |
|
| 390 | - * |
|
| 391 | - * @return string |
|
| 392 | - * @throws EE_Error |
|
| 393 | - */ |
|
| 394 | - public function state_ID() |
|
| 395 | - { |
|
| 396 | - return $this->get('STA_ID'); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - |
|
| 400 | - /** |
|
| 401 | - * @return string |
|
| 402 | - * @throws EE_Error |
|
| 403 | - */ |
|
| 404 | - public function state_abbrev() |
|
| 405 | - { |
|
| 406 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Gets the state set to this attendee |
|
| 412 | - * |
|
| 413 | - * @return EE_State |
|
| 414 | - * @throws EE_Error |
|
| 415 | - */ |
|
| 416 | - public function state_obj() |
|
| 417 | - { |
|
| 418 | - return $this->get_first_related('State'); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Returns the state's name, otherwise 'Unknown' |
|
| 424 | - * |
|
| 425 | - * @return string |
|
| 426 | - * @throws EE_Error |
|
| 427 | - */ |
|
| 428 | - public function state_name() |
|
| 429 | - { |
|
| 430 | - if ($this->state_obj()) { |
|
| 431 | - return $this->state_obj()->name(); |
|
| 432 | - } else { |
|
| 433 | - return ''; |
|
| 434 | - } |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * either displays the state abbreviation or the state name, as determined |
|
| 440 | - * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 441 | - * defaults to abbreviation |
|
| 442 | - * |
|
| 443 | - * @return string |
|
| 444 | - * @throws EE_Error |
|
| 445 | - */ |
|
| 446 | - public function state() |
|
| 447 | - { |
|
| 448 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 449 | - return $this->state_abbrev(); |
|
| 450 | - } |
|
| 451 | - return $this->state_name(); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * get Attendee Country ISO Code |
|
| 457 | - * |
|
| 458 | - * @return string |
|
| 459 | - * @throws EE_Error |
|
| 460 | - */ |
|
| 461 | - public function country_ID() |
|
| 462 | - { |
|
| 463 | - return $this->get('CNT_ISO'); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Gets country set for this attendee |
|
| 469 | - * |
|
| 470 | - * @return EE_Country |
|
| 471 | - * @throws EE_Error |
|
| 472 | - */ |
|
| 473 | - public function country_obj() |
|
| 474 | - { |
|
| 475 | - return $this->get_first_related('Country'); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Returns the country's name if known, otherwise 'Unknown' |
|
| 481 | - * |
|
| 482 | - * @return string |
|
| 483 | - * @throws EE_Error |
|
| 484 | - */ |
|
| 485 | - public function country_name() |
|
| 486 | - { |
|
| 487 | - if ($this->country_obj()) { |
|
| 488 | - return $this->country_obj()->name(); |
|
| 489 | - } |
|
| 490 | - return ''; |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * either displays the country ISO2 code or the country name, as determined |
|
| 496 | - * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 497 | - * defaults to abbreviation |
|
| 498 | - * |
|
| 499 | - * @return string |
|
| 500 | - * @throws EE_Error |
|
| 501 | - */ |
|
| 502 | - public function country() |
|
| 503 | - { |
|
| 504 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 505 | - return $this->country_ID(); |
|
| 506 | - } |
|
| 507 | - return $this->country_name(); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * get Attendee Zip/Postal Code |
|
| 513 | - * |
|
| 514 | - * @return string |
|
| 515 | - * @throws EE_Error |
|
| 516 | - */ |
|
| 517 | - public function zip() |
|
| 518 | - { |
|
| 519 | - return $this->get('ATT_zip'); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * get Attendee Email Address |
|
| 525 | - * |
|
| 526 | - * @return string |
|
| 527 | - * @throws EE_Error |
|
| 528 | - */ |
|
| 529 | - public function email() |
|
| 530 | - { |
|
| 531 | - return $this->get('ATT_email'); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - |
|
| 535 | - /** |
|
| 536 | - * get Attendee Phone # |
|
| 537 | - * |
|
| 538 | - * @return string |
|
| 539 | - * @throws EE_Error |
|
| 540 | - */ |
|
| 541 | - public function phone() |
|
| 542 | - { |
|
| 543 | - return $this->get('ATT_phone'); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - |
|
| 547 | - /** |
|
| 548 | - * get deleted |
|
| 549 | - * |
|
| 550 | - * @return bool |
|
| 551 | - * @throws EE_Error |
|
| 552 | - */ |
|
| 553 | - public function deleted() |
|
| 554 | - { |
|
| 555 | - return $this->get('ATT_deleted'); |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * Gets registrations of this attendee |
|
| 561 | - * |
|
| 562 | - * @param array $query_params |
|
| 563 | - * @return EE_Registration[] |
|
| 564 | - * @throws EE_Error |
|
| 565 | - */ |
|
| 566 | - public function get_registrations($query_params = array()) |
|
| 567 | - { |
|
| 568 | - return $this->get_many_related('Registration', $query_params); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Gets the most recent registration of this attendee |
|
| 574 | - * |
|
| 575 | - * @return EE_Registration |
|
| 576 | - * @throws EE_Error |
|
| 577 | - */ |
|
| 578 | - public function get_most_recent_registration() |
|
| 579 | - { |
|
| 580 | - return $this->get_first_related( |
|
| 581 | - 'Registration', |
|
| 582 | - array('order_by' => array('REG_date' => 'DESC')) |
|
| 583 | - ); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - |
|
| 587 | - /** |
|
| 588 | - * Gets the most recent registration for this attend at this event |
|
| 589 | - * |
|
| 590 | - * @param int $event_id |
|
| 591 | - * @return EE_Registration |
|
| 592 | - * @throws EE_Error |
|
| 593 | - */ |
|
| 594 | - public function get_most_recent_registration_for_event($event_id) |
|
| 595 | - { |
|
| 596 | - return $this->get_first_related( |
|
| 597 | - 'Registration', |
|
| 598 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')) |
|
| 599 | - ); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * returns any events attached to this attendee ($_Event property); |
|
| 605 | - * |
|
| 606 | - * @return array |
|
| 607 | - * @throws EE_Error |
|
| 608 | - */ |
|
| 609 | - public function events() |
|
| 610 | - { |
|
| 611 | - return $this->get_many_related('Event'); |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 617 | - * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 618 | - * used to save the billing info |
|
| 619 | - * |
|
| 620 | - * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 621 | - * @return EE_Form_Section_Proper|null |
|
| 622 | - * @throws EE_Error |
|
| 623 | - */ |
|
| 624 | - public function billing_info_for_payment_method($payment_method) |
|
| 625 | - { |
|
| 626 | - $pm_type = $payment_method->type_obj(); |
|
| 627 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 628 | - return null; |
|
| 629 | - } |
|
| 630 | - $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 631 | - if (! $billing_info) { |
|
| 632 | - return null; |
|
| 633 | - } |
|
| 634 | - $billing_form = $pm_type->billing_form(); |
|
| 635 | - //double-check the form isn't totally hidden, in which case pretend there is no form |
|
| 636 | - $form_totally_hidden = true; |
|
| 637 | - foreach($billing_form->inputs_in_subsections() as $input){ |
|
| 638 | - if(! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 639 | - $form_totally_hidden = false; |
|
| 640 | - break; |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - if($form_totally_hidden) { |
|
| 644 | - return null; |
|
| 645 | - } |
|
| 646 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 647 | - $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - return $billing_form; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Gets the postmeta key that holds this attendee's billing info for the |
|
| 656 | - * specified payment method |
|
| 657 | - * |
|
| 658 | - * @param EE_Payment_Method $payment_method |
|
| 659 | - * @return string |
|
| 660 | - * @throws EE_Error |
|
| 661 | - */ |
|
| 662 | - public function get_billing_info_postmeta_name($payment_method) |
|
| 663 | - { |
|
| 664 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 665 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 666 | - } |
|
| 667 | - return null; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - |
|
| 671 | - /** |
|
| 672 | - * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 673 | - * retrieve it |
|
| 674 | - * |
|
| 675 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 676 | - * @param EE_Payment_Method $payment_method |
|
| 677 | - * @return boolean |
|
| 678 | - * @throws EE_Error |
|
| 679 | - */ |
|
| 680 | - public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 681 | - { |
|
| 682 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 683 | - EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
| 684 | - return false; |
|
| 685 | - } |
|
| 686 | - $billing_form->clean_sensitive_data(); |
|
| 687 | - return update_post_meta( |
|
| 688 | - $this->ID(), |
|
| 689 | - $this->get_billing_info_postmeta_name($payment_method), |
|
| 690 | - $billing_form->input_values(true) |
|
| 691 | - ); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Return the link to the admin details for the object. |
|
| 697 | - * |
|
| 698 | - * @return string |
|
| 699 | - * @throws EE_Error |
|
| 700 | - * @throws InvalidArgumentException |
|
| 701 | - * @throws InvalidDataTypeException |
|
| 702 | - * @throws InvalidInterfaceException |
|
| 703 | - * @throws ReflectionException |
|
| 704 | - */ |
|
| 705 | - public function get_admin_details_link() |
|
| 706 | - { |
|
| 707 | - return $this->get_admin_edit_link(); |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - |
|
| 711 | - /** |
|
| 712 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 713 | - * |
|
| 714 | - * @return string |
|
| 715 | - * @throws EE_Error |
|
| 716 | - * @throws InvalidArgumentException |
|
| 717 | - * @throws ReflectionException |
|
| 718 | - * @throws InvalidDataTypeException |
|
| 719 | - * @throws InvalidInterfaceException |
|
| 720 | - */ |
|
| 721 | - public function get_admin_edit_link() |
|
| 722 | - { |
|
| 723 | - EE_Registry::instance()->load_helper('URL'); |
|
| 724 | - return EEH_URL::add_query_args_and_nonce( |
|
| 725 | - array( |
|
| 726 | - 'page' => 'espresso_registrations', |
|
| 727 | - 'action' => 'edit_attendee', |
|
| 728 | - 'post' => $this->ID(), |
|
| 729 | - ), |
|
| 730 | - admin_url('admin.php') |
|
| 731 | - ); |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * Returns the link to a settings page for the object. |
|
| 737 | - * |
|
| 738 | - * @return string |
|
| 739 | - * @throws EE_Error |
|
| 740 | - * @throws InvalidArgumentException |
|
| 741 | - * @throws InvalidDataTypeException |
|
| 742 | - * @throws InvalidInterfaceException |
|
| 743 | - * @throws ReflectionException |
|
| 744 | - */ |
|
| 745 | - public function get_admin_settings_link() |
|
| 746 | - { |
|
| 747 | - return $this->get_admin_edit_link(); |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 753 | - * |
|
| 754 | - * @return string |
|
| 755 | - * @throws EE_Error |
|
| 756 | - * @throws InvalidArgumentException |
|
| 757 | - * @throws ReflectionException |
|
| 758 | - * @throws InvalidDataTypeException |
|
| 759 | - * @throws InvalidInterfaceException |
|
| 760 | - */ |
|
| 761 | - public function get_admin_overview_link() |
|
| 762 | - { |
|
| 763 | - EE_Registry::instance()->load_helper('URL'); |
|
| 764 | - return EEH_URL::add_query_args_and_nonce( |
|
| 765 | - array( |
|
| 766 | - 'page' => 'espresso_registrations', |
|
| 767 | - 'action' => 'contact_list', |
|
| 768 | - ), |
|
| 769 | - admin_url('admin.php') |
|
| 770 | - ); |
|
| 771 | - } |
|
| 30 | + /** |
|
| 31 | + * Sets some dynamic defaults |
|
| 32 | + * |
|
| 33 | + * @param array $fieldValues |
|
| 34 | + * @param bool $bydb |
|
| 35 | + * @param string $timezone |
|
| 36 | + * @param array $date_formats |
|
| 37 | + * @throws EE_Error |
|
| 38 | + */ |
|
| 39 | + protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
| 40 | + { |
|
| 41 | + if (! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 43 | + $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
| 44 | + $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 45 | + } |
|
| 46 | + if (! isset($fieldValues['ATT_slug'])) { |
|
| 47 | + // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
| 48 | + $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
| 49 | + } |
|
| 50 | + if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 51 | + $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
| 52 | + } |
|
| 53 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param array $props_n_values incoming values |
|
| 59 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 60 | + * used.) |
|
| 61 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 62 | + * date_format and the second value is the time format |
|
| 63 | + * @return EE_Attendee |
|
| 64 | + * @throws EE_Error |
|
| 65 | + */ |
|
| 66 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 67 | + { |
|
| 68 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 69 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param array $props_n_values incoming values from the database |
|
| 75 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 76 | + * the website will be used. |
|
| 77 | + * @return EE_Attendee |
|
| 78 | + */ |
|
| 79 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 80 | + { |
|
| 81 | + return new self($props_n_values, true, $timezone); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Set Attendee First Name |
|
| 87 | + * |
|
| 88 | + * @access public |
|
| 89 | + * @param string $fname |
|
| 90 | + * @throws EE_Error |
|
| 91 | + */ |
|
| 92 | + public function set_fname($fname = '') |
|
| 93 | + { |
|
| 94 | + $this->set('ATT_fname', $fname); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Set Attendee Last Name |
|
| 100 | + * |
|
| 101 | + * @access public |
|
| 102 | + * @param string $lname |
|
| 103 | + * @throws EE_Error |
|
| 104 | + */ |
|
| 105 | + public function set_lname($lname = '') |
|
| 106 | + { |
|
| 107 | + $this->set('ATT_lname', $lname); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Set Attendee Address |
|
| 113 | + * |
|
| 114 | + * @access public |
|
| 115 | + * @param string $address |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function set_address($address = '') |
|
| 119 | + { |
|
| 120 | + $this->set('ATT_address', $address); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Set Attendee Address2 |
|
| 126 | + * |
|
| 127 | + * @access public |
|
| 128 | + * @param string $address2 |
|
| 129 | + * @throws EE_Error |
|
| 130 | + */ |
|
| 131 | + public function set_address2($address2 = '') |
|
| 132 | + { |
|
| 133 | + $this->set('ATT_address2', $address2); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Set Attendee City |
|
| 139 | + * |
|
| 140 | + * @access public |
|
| 141 | + * @param string $city |
|
| 142 | + * @throws EE_Error |
|
| 143 | + */ |
|
| 144 | + public function set_city($city = '') |
|
| 145 | + { |
|
| 146 | + $this->set('ATT_city', $city); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Set Attendee State ID |
|
| 152 | + * |
|
| 153 | + * @access public |
|
| 154 | + * @param int $STA_ID |
|
| 155 | + * @throws EE_Error |
|
| 156 | + */ |
|
| 157 | + public function set_state($STA_ID = 0) |
|
| 158 | + { |
|
| 159 | + $this->set('STA_ID', $STA_ID); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Set Attendee Country ISO Code |
|
| 165 | + * |
|
| 166 | + * @access public |
|
| 167 | + * @param string $CNT_ISO |
|
| 168 | + * @throws EE_Error |
|
| 169 | + */ |
|
| 170 | + public function set_country($CNT_ISO = '') |
|
| 171 | + { |
|
| 172 | + $this->set('CNT_ISO', $CNT_ISO); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Set Attendee Zip/Postal Code |
|
| 178 | + * |
|
| 179 | + * @access public |
|
| 180 | + * @param string $zip |
|
| 181 | + * @throws EE_Error |
|
| 182 | + */ |
|
| 183 | + public function set_zip($zip = '') |
|
| 184 | + { |
|
| 185 | + $this->set('ATT_zip', $zip); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Set Attendee Email Address |
|
| 191 | + * |
|
| 192 | + * @access public |
|
| 193 | + * @param string $email |
|
| 194 | + * @throws EE_Error |
|
| 195 | + */ |
|
| 196 | + public function set_email($email = '') |
|
| 197 | + { |
|
| 198 | + $this->set('ATT_email', $email); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Set Attendee Phone |
|
| 204 | + * |
|
| 205 | + * @access public |
|
| 206 | + * @param string $phone |
|
| 207 | + * @throws EE_Error |
|
| 208 | + */ |
|
| 209 | + public function set_phone($phone = '') |
|
| 210 | + { |
|
| 211 | + $this->set('ATT_phone', $phone); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * set deleted |
|
| 217 | + * |
|
| 218 | + * @access public |
|
| 219 | + * @param bool $ATT_deleted |
|
| 220 | + * @throws EE_Error |
|
| 221 | + */ |
|
| 222 | + public function set_deleted($ATT_deleted = false) |
|
| 223 | + { |
|
| 224 | + $this->set('ATT_deleted', $ATT_deleted); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Returns the value for the post_author id saved with the cpt |
|
| 230 | + * |
|
| 231 | + * @since 4.5.0 |
|
| 232 | + * @return int |
|
| 233 | + * @throws EE_Error |
|
| 234 | + */ |
|
| 235 | + public function wp_user() |
|
| 236 | + { |
|
| 237 | + return $this->get('ATT_author'); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * get Attendee First Name |
|
| 243 | + * |
|
| 244 | + * @access public |
|
| 245 | + * @return string |
|
| 246 | + * @throws EE_Error |
|
| 247 | + */ |
|
| 248 | + public function fname() |
|
| 249 | + { |
|
| 250 | + return $this->get('ATT_fname'); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * echoes out the attendee's first name |
|
| 256 | + * |
|
| 257 | + * @return void |
|
| 258 | + * @throws EE_Error |
|
| 259 | + */ |
|
| 260 | + public function e_full_name() |
|
| 261 | + { |
|
| 262 | + echo $this->full_name(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Returns the first and last name concatenated together with a space. |
|
| 268 | + * |
|
| 269 | + * @param bool $apply_html_entities |
|
| 270 | + * @return string |
|
| 271 | + * @throws EE_Error |
|
| 272 | + */ |
|
| 273 | + public function full_name($apply_html_entities = false) |
|
| 274 | + { |
|
| 275 | + $full_name = array( |
|
| 276 | + $this->fname(), |
|
| 277 | + $this->lname(), |
|
| 278 | + ); |
|
| 279 | + $full_name = array_filter($full_name); |
|
| 280 | + $full_name = implode(' ', $full_name); |
|
| 281 | + return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + |
|
| 285 | + /** |
|
| 286 | + * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
| 287 | + * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
| 288 | + * attendee. |
|
| 289 | + * |
|
| 290 | + * @param bool $apply_html_entities |
|
| 291 | + * @return string |
|
| 292 | + * @throws EE_Error |
|
| 293 | + */ |
|
| 294 | + public function ATT_full_name($apply_html_entities = false) |
|
| 295 | + { |
|
| 296 | + return $apply_html_entities |
|
| 297 | + ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
| 298 | + : $this->get('ATT_full_name'); |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * get Attendee Last Name |
|
| 304 | + * |
|
| 305 | + * @access public |
|
| 306 | + * @return string |
|
| 307 | + * @throws EE_Error |
|
| 308 | + */ |
|
| 309 | + public function lname() |
|
| 310 | + { |
|
| 311 | + return $this->get('ATT_lname'); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
| 317 | + * |
|
| 318 | + * @return array numerically indexed, with each part of the address that is known. |
|
| 319 | + * Eg, if the user only responded to state and country, |
|
| 320 | + * it would be array(0=>'Alabama',1=>'USA') |
|
| 321 | + * @return array |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + public function full_address_as_array() |
|
| 325 | + { |
|
| 326 | + $full_address_array = array(); |
|
| 327 | + $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
| 328 | + foreach ($initial_address_fields as $address_field_name) { |
|
| 329 | + $address_fields_value = $this->get($address_field_name); |
|
| 330 | + if (! empty($address_fields_value)) { |
|
| 331 | + $full_address_array[] = $address_fields_value; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + //now handle state and country |
|
| 335 | + $state_obj = $this->state_obj(); |
|
| 336 | + if ($state_obj instanceof EE_State) { |
|
| 337 | + $full_address_array[] = $state_obj->name(); |
|
| 338 | + } |
|
| 339 | + $country_obj = $this->country_obj(); |
|
| 340 | + if ($country_obj instanceof EE_Country) { |
|
| 341 | + $full_address_array[] = $country_obj->name(); |
|
| 342 | + } |
|
| 343 | + //lastly get the xip |
|
| 344 | + $zip_value = $this->zip(); |
|
| 345 | + if (! empty($zip_value)) { |
|
| 346 | + $full_address_array[] = $zip_value; |
|
| 347 | + } |
|
| 348 | + return $full_address_array; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * get Attendee Address |
|
| 354 | + * |
|
| 355 | + * @return string |
|
| 356 | + * @throws EE_Error |
|
| 357 | + */ |
|
| 358 | + public function address() |
|
| 359 | + { |
|
| 360 | + return $this->get('ATT_address'); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * get Attendee Address2 |
|
| 366 | + * |
|
| 367 | + * @return string |
|
| 368 | + * @throws EE_Error |
|
| 369 | + */ |
|
| 370 | + public function address2() |
|
| 371 | + { |
|
| 372 | + return $this->get('ATT_address2'); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * get Attendee City |
|
| 378 | + * |
|
| 379 | + * @return string |
|
| 380 | + * @throws EE_Error |
|
| 381 | + */ |
|
| 382 | + public function city() |
|
| 383 | + { |
|
| 384 | + return $this->get('ATT_city'); |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + /** |
|
| 389 | + * get Attendee State ID |
|
| 390 | + * |
|
| 391 | + * @return string |
|
| 392 | + * @throws EE_Error |
|
| 393 | + */ |
|
| 394 | + public function state_ID() |
|
| 395 | + { |
|
| 396 | + return $this->get('STA_ID'); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + |
|
| 400 | + /** |
|
| 401 | + * @return string |
|
| 402 | + * @throws EE_Error |
|
| 403 | + */ |
|
| 404 | + public function state_abbrev() |
|
| 405 | + { |
|
| 406 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Gets the state set to this attendee |
|
| 412 | + * |
|
| 413 | + * @return EE_State |
|
| 414 | + * @throws EE_Error |
|
| 415 | + */ |
|
| 416 | + public function state_obj() |
|
| 417 | + { |
|
| 418 | + return $this->get_first_related('State'); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Returns the state's name, otherwise 'Unknown' |
|
| 424 | + * |
|
| 425 | + * @return string |
|
| 426 | + * @throws EE_Error |
|
| 427 | + */ |
|
| 428 | + public function state_name() |
|
| 429 | + { |
|
| 430 | + if ($this->state_obj()) { |
|
| 431 | + return $this->state_obj()->name(); |
|
| 432 | + } else { |
|
| 433 | + return ''; |
|
| 434 | + } |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * either displays the state abbreviation or the state name, as determined |
|
| 440 | + * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
| 441 | + * defaults to abbreviation |
|
| 442 | + * |
|
| 443 | + * @return string |
|
| 444 | + * @throws EE_Error |
|
| 445 | + */ |
|
| 446 | + public function state() |
|
| 447 | + { |
|
| 448 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
| 449 | + return $this->state_abbrev(); |
|
| 450 | + } |
|
| 451 | + return $this->state_name(); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * get Attendee Country ISO Code |
|
| 457 | + * |
|
| 458 | + * @return string |
|
| 459 | + * @throws EE_Error |
|
| 460 | + */ |
|
| 461 | + public function country_ID() |
|
| 462 | + { |
|
| 463 | + return $this->get('CNT_ISO'); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Gets country set for this attendee |
|
| 469 | + * |
|
| 470 | + * @return EE_Country |
|
| 471 | + * @throws EE_Error |
|
| 472 | + */ |
|
| 473 | + public function country_obj() |
|
| 474 | + { |
|
| 475 | + return $this->get_first_related('Country'); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Returns the country's name if known, otherwise 'Unknown' |
|
| 481 | + * |
|
| 482 | + * @return string |
|
| 483 | + * @throws EE_Error |
|
| 484 | + */ |
|
| 485 | + public function country_name() |
|
| 486 | + { |
|
| 487 | + if ($this->country_obj()) { |
|
| 488 | + return $this->country_obj()->name(); |
|
| 489 | + } |
|
| 490 | + return ''; |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + |
|
| 494 | + /** |
|
| 495 | + * either displays the country ISO2 code or the country name, as determined |
|
| 496 | + * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
| 497 | + * defaults to abbreviation |
|
| 498 | + * |
|
| 499 | + * @return string |
|
| 500 | + * @throws EE_Error |
|
| 501 | + */ |
|
| 502 | + public function country() |
|
| 503 | + { |
|
| 504 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
| 505 | + return $this->country_ID(); |
|
| 506 | + } |
|
| 507 | + return $this->country_name(); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * get Attendee Zip/Postal Code |
|
| 513 | + * |
|
| 514 | + * @return string |
|
| 515 | + * @throws EE_Error |
|
| 516 | + */ |
|
| 517 | + public function zip() |
|
| 518 | + { |
|
| 519 | + return $this->get('ATT_zip'); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * get Attendee Email Address |
|
| 525 | + * |
|
| 526 | + * @return string |
|
| 527 | + * @throws EE_Error |
|
| 528 | + */ |
|
| 529 | + public function email() |
|
| 530 | + { |
|
| 531 | + return $this->get('ATT_email'); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + |
|
| 535 | + /** |
|
| 536 | + * get Attendee Phone # |
|
| 537 | + * |
|
| 538 | + * @return string |
|
| 539 | + * @throws EE_Error |
|
| 540 | + */ |
|
| 541 | + public function phone() |
|
| 542 | + { |
|
| 543 | + return $this->get('ATT_phone'); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + |
|
| 547 | + /** |
|
| 548 | + * get deleted |
|
| 549 | + * |
|
| 550 | + * @return bool |
|
| 551 | + * @throws EE_Error |
|
| 552 | + */ |
|
| 553 | + public function deleted() |
|
| 554 | + { |
|
| 555 | + return $this->get('ATT_deleted'); |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * Gets registrations of this attendee |
|
| 561 | + * |
|
| 562 | + * @param array $query_params |
|
| 563 | + * @return EE_Registration[] |
|
| 564 | + * @throws EE_Error |
|
| 565 | + */ |
|
| 566 | + public function get_registrations($query_params = array()) |
|
| 567 | + { |
|
| 568 | + return $this->get_many_related('Registration', $query_params); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Gets the most recent registration of this attendee |
|
| 574 | + * |
|
| 575 | + * @return EE_Registration |
|
| 576 | + * @throws EE_Error |
|
| 577 | + */ |
|
| 578 | + public function get_most_recent_registration() |
|
| 579 | + { |
|
| 580 | + return $this->get_first_related( |
|
| 581 | + 'Registration', |
|
| 582 | + array('order_by' => array('REG_date' => 'DESC')) |
|
| 583 | + ); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + |
|
| 587 | + /** |
|
| 588 | + * Gets the most recent registration for this attend at this event |
|
| 589 | + * |
|
| 590 | + * @param int $event_id |
|
| 591 | + * @return EE_Registration |
|
| 592 | + * @throws EE_Error |
|
| 593 | + */ |
|
| 594 | + public function get_most_recent_registration_for_event($event_id) |
|
| 595 | + { |
|
| 596 | + return $this->get_first_related( |
|
| 597 | + 'Registration', |
|
| 598 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')) |
|
| 599 | + ); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * returns any events attached to this attendee ($_Event property); |
|
| 605 | + * |
|
| 606 | + * @return array |
|
| 607 | + * @throws EE_Error |
|
| 608 | + */ |
|
| 609 | + public function events() |
|
| 610 | + { |
|
| 611 | + return $this->get_many_related('Event'); |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
| 617 | + * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
| 618 | + * used to save the billing info |
|
| 619 | + * |
|
| 620 | + * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
| 621 | + * @return EE_Form_Section_Proper|null |
|
| 622 | + * @throws EE_Error |
|
| 623 | + */ |
|
| 624 | + public function billing_info_for_payment_method($payment_method) |
|
| 625 | + { |
|
| 626 | + $pm_type = $payment_method->type_obj(); |
|
| 627 | + if (! $pm_type instanceof EE_PMT_Base) { |
|
| 628 | + return null; |
|
| 629 | + } |
|
| 630 | + $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
| 631 | + if (! $billing_info) { |
|
| 632 | + return null; |
|
| 633 | + } |
|
| 634 | + $billing_form = $pm_type->billing_form(); |
|
| 635 | + //double-check the form isn't totally hidden, in which case pretend there is no form |
|
| 636 | + $form_totally_hidden = true; |
|
| 637 | + foreach($billing_form->inputs_in_subsections() as $input){ |
|
| 638 | + if(! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 639 | + $form_totally_hidden = false; |
|
| 640 | + break; |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + if($form_totally_hidden) { |
|
| 644 | + return null; |
|
| 645 | + } |
|
| 646 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
| 647 | + $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + return $billing_form; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Gets the postmeta key that holds this attendee's billing info for the |
|
| 656 | + * specified payment method |
|
| 657 | + * |
|
| 658 | + * @param EE_Payment_Method $payment_method |
|
| 659 | + * @return string |
|
| 660 | + * @throws EE_Error |
|
| 661 | + */ |
|
| 662 | + public function get_billing_info_postmeta_name($payment_method) |
|
| 663 | + { |
|
| 664 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
| 665 | + return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 666 | + } |
|
| 667 | + return null; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + |
|
| 671 | + /** |
|
| 672 | + * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
| 673 | + * retrieve it |
|
| 674 | + * |
|
| 675 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
| 676 | + * @param EE_Payment_Method $payment_method |
|
| 677 | + * @return boolean |
|
| 678 | + * @throws EE_Error |
|
| 679 | + */ |
|
| 680 | + public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
| 681 | + { |
|
| 682 | + if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 683 | + EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
| 684 | + return false; |
|
| 685 | + } |
|
| 686 | + $billing_form->clean_sensitive_data(); |
|
| 687 | + return update_post_meta( |
|
| 688 | + $this->ID(), |
|
| 689 | + $this->get_billing_info_postmeta_name($payment_method), |
|
| 690 | + $billing_form->input_values(true) |
|
| 691 | + ); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Return the link to the admin details for the object. |
|
| 697 | + * |
|
| 698 | + * @return string |
|
| 699 | + * @throws EE_Error |
|
| 700 | + * @throws InvalidArgumentException |
|
| 701 | + * @throws InvalidDataTypeException |
|
| 702 | + * @throws InvalidInterfaceException |
|
| 703 | + * @throws ReflectionException |
|
| 704 | + */ |
|
| 705 | + public function get_admin_details_link() |
|
| 706 | + { |
|
| 707 | + return $this->get_admin_edit_link(); |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + |
|
| 711 | + /** |
|
| 712 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
| 713 | + * |
|
| 714 | + * @return string |
|
| 715 | + * @throws EE_Error |
|
| 716 | + * @throws InvalidArgumentException |
|
| 717 | + * @throws ReflectionException |
|
| 718 | + * @throws InvalidDataTypeException |
|
| 719 | + * @throws InvalidInterfaceException |
|
| 720 | + */ |
|
| 721 | + public function get_admin_edit_link() |
|
| 722 | + { |
|
| 723 | + EE_Registry::instance()->load_helper('URL'); |
|
| 724 | + return EEH_URL::add_query_args_and_nonce( |
|
| 725 | + array( |
|
| 726 | + 'page' => 'espresso_registrations', |
|
| 727 | + 'action' => 'edit_attendee', |
|
| 728 | + 'post' => $this->ID(), |
|
| 729 | + ), |
|
| 730 | + admin_url('admin.php') |
|
| 731 | + ); |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * Returns the link to a settings page for the object. |
|
| 737 | + * |
|
| 738 | + * @return string |
|
| 739 | + * @throws EE_Error |
|
| 740 | + * @throws InvalidArgumentException |
|
| 741 | + * @throws InvalidDataTypeException |
|
| 742 | + * @throws InvalidInterfaceException |
|
| 743 | + * @throws ReflectionException |
|
| 744 | + */ |
|
| 745 | + public function get_admin_settings_link() |
|
| 746 | + { |
|
| 747 | + return $this->get_admin_edit_link(); |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
| 753 | + * |
|
| 754 | + * @return string |
|
| 755 | + * @throws EE_Error |
|
| 756 | + * @throws InvalidArgumentException |
|
| 757 | + * @throws ReflectionException |
|
| 758 | + * @throws InvalidDataTypeException |
|
| 759 | + * @throws InvalidInterfaceException |
|
| 760 | + */ |
|
| 761 | + public function get_admin_overview_link() |
|
| 762 | + { |
|
| 763 | + EE_Registry::instance()->load_helper('URL'); |
|
| 764 | + return EEH_URL::add_query_args_and_nonce( |
|
| 765 | + array( |
|
| 766 | + 'page' => 'espresso_registrations', |
|
| 767 | + 'action' => 'contact_list', |
|
| 768 | + ), |
|
| 769 | + admin_url('admin.php') |
|
| 770 | + ); |
|
| 771 | + } |
|
| 772 | 772 | } |
@@ -38,16 +38,16 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
| 40 | 40 | { |
| 41 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
| 41 | + if ( ! isset($fieldValues['ATT_full_name'])) { |
|
| 42 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : ''; |
|
| 43 | 43 | $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
| 44 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
| 44 | + $fieldValues['ATT_full_name'] = $fname.$lname; |
|
| 45 | 45 | } |
| 46 | - if (! isset($fieldValues['ATT_slug'])) { |
|
| 46 | + if ( ! isset($fieldValues['ATT_slug'])) { |
|
| 47 | 47 | // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
| 48 | 48 | $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
| 49 | 49 | } |
| 50 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 50 | + if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
| 51 | 51 | $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
| 52 | 52 | } |
| 53 | 53 | parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
| 328 | 328 | foreach ($initial_address_fields as $address_field_name) { |
| 329 | 329 | $address_fields_value = $this->get($address_field_name); |
| 330 | - if (! empty($address_fields_value)) { |
|
| 330 | + if ( ! empty($address_fields_value)) { |
|
| 331 | 331 | $full_address_array[] = $address_fields_value; |
| 332 | 332 | } |
| 333 | 333 | } |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | } |
| 343 | 343 | //lastly get the xip |
| 344 | 344 | $zip_value = $this->zip(); |
| 345 | - if (! empty($zip_value)) { |
|
| 345 | + if ( ! empty($zip_value)) { |
|
| 346 | 346 | $full_address_array[] = $zip_value; |
| 347 | 347 | } |
| 348 | 348 | return $full_address_array; |
@@ -624,23 +624,23 @@ discard block |
||
| 624 | 624 | public function billing_info_for_payment_method($payment_method) |
| 625 | 625 | { |
| 626 | 626 | $pm_type = $payment_method->type_obj(); |
| 627 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
| 627 | + if ( ! $pm_type instanceof EE_PMT_Base) { |
|
| 628 | 628 | return null; |
| 629 | 629 | } |
| 630 | 630 | $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
| 631 | - if (! $billing_info) { |
|
| 631 | + if ( ! $billing_info) { |
|
| 632 | 632 | return null; |
| 633 | 633 | } |
| 634 | 634 | $billing_form = $pm_type->billing_form(); |
| 635 | 635 | //double-check the form isn't totally hidden, in which case pretend there is no form |
| 636 | 636 | $form_totally_hidden = true; |
| 637 | - foreach($billing_form->inputs_in_subsections() as $input){ |
|
| 638 | - if(! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 637 | + foreach ($billing_form->inputs_in_subsections() as $input) { |
|
| 638 | + if ( ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 639 | 639 | $form_totally_hidden = false; |
| 640 | 640 | break; |
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | - if($form_totally_hidden) { |
|
| 643 | + if ($form_totally_hidden) { |
|
| 644 | 644 | return null; |
| 645 | 645 | } |
| 646 | 646 | if ($billing_form instanceof EE_Form_Section_Proper) { |
@@ -662,7 +662,7 @@ discard block |
||
| 662 | 662 | public function get_billing_info_postmeta_name($payment_method) |
| 663 | 663 | { |
| 664 | 664 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
| 665 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
| 665 | + return 'billing_info_'.$payment_method->type_obj()->system_name(); |
|
| 666 | 666 | } |
| 667 | 667 | return null; |
| 668 | 668 | } |
@@ -679,7 +679,7 @@ discard block |
||
| 679 | 679 | */ |
| 680 | 680 | public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
| 681 | 681 | { |
| 682 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 682 | + if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
| 683 | 683 | EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
| 684 | 684 | return false; |
| 685 | 685 | } |
@@ -15,288 +15,288 @@ |
||
| 15 | 15 | abstract class EE_Form_Section_Layout_Base |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Form form section to lay out |
|
| 20 | - * |
|
| 21 | - * @var EE_Form_Section_Proper |
|
| 22 | - */ |
|
| 23 | - protected $_form_section; |
|
| 24 | - |
|
| 25 | - |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * __construct |
|
| 29 | - */ |
|
| 30 | - public function __construct() |
|
| 31 | - { |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * The form section on which this strategy is to perform |
|
| 38 | - * |
|
| 39 | - * @param EE_Form_Section_Proper $form |
|
| 40 | - */ |
|
| 41 | - public function _construct_finalize(EE_Form_Section_Proper $form) |
|
| 42 | - { |
|
| 43 | - $this->_form_section = $form; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @return EE_Form_Section_Proper |
|
| 50 | - */ |
|
| 51 | - public function form_section() |
|
| 52 | - { |
|
| 53 | - return $this->_form_section; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Also has teh side effect of enqueuing any needed JS and CSS for |
|
| 60 | - * this form. |
|
| 61 | - * Creates all the HTML necessary for displaying this form, its inputs, and |
|
| 62 | - * proper subsections. |
|
| 63 | - * Returns the HTML |
|
| 64 | - * |
|
| 65 | - * @return string HTML for displaying |
|
| 66 | - * @throws EE_Error |
|
| 67 | - */ |
|
| 68 | - public function layout_form() |
|
| 69 | - { |
|
| 70 | - $html = ''; |
|
| 71 | - // layout_form_begin |
|
| 72 | - $html .= apply_filters( |
|
| 73 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
| 74 | - $this->layout_form_begin(), |
|
| 75 | - $this->_form_section |
|
| 76 | - ); |
|
| 77 | - // layout_form_loop |
|
| 78 | - $html .= apply_filters( |
|
| 79 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
| 80 | - $this->layout_form_loop(), |
|
| 81 | - $this->_form_section |
|
| 82 | - ); |
|
| 83 | - // layout_form_end |
|
| 84 | - $html .= apply_filters( |
|
| 85 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
| 86 | - $this->layout_form_end(), |
|
| 87 | - $this->_form_section |
|
| 88 | - ); |
|
| 89 | - $html = $this->add_form_section_hooks_and_filters($html); |
|
| 90 | - return $html; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @return string |
|
| 97 | - * @throws EE_Error |
|
| 98 | - */ |
|
| 99 | - public function layout_form_loop() |
|
| 100 | - { |
|
| 101 | - $html = ''; |
|
| 102 | - foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
| 103 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
| 104 | - $html .= apply_filters( |
|
| 105 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
| 106 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 107 | - $this->layout_input($subsection), |
|
| 108 | - $this->_form_section, |
|
| 109 | - $subsection |
|
| 110 | - ); |
|
| 111 | - } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
| 112 | - $html .= apply_filters( |
|
| 113 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
| 114 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 115 | - $this->layout_subsection($subsection), |
|
| 116 | - $this->_form_section, |
|
| 117 | - $subsection |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - return $html; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
| 128 | - * |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - abstract public function layout_form_begin(); |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
| 137 | - * |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - abstract public function layout_form_end(); |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
| 146 | - * is putting each input in a row of its own, this should probably be called by a |
|
| 147 | - * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
| 148 | - * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
| 149 | - * customize the form's layout, but would like to make use of it for laying out |
|
| 150 | - * 'easy-to-layout' inputs |
|
| 151 | - * |
|
| 152 | - * @param EE_Form_Input_Base $input |
|
| 153 | - * @return string html |
|
| 154 | - */ |
|
| 155 | - abstract public function layout_input($input); |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Similar to layout_input(), should be used internally by layout_form() within a |
|
| 161 | - * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
| 162 | - * that the proper subsection will layout its container, label, etc on its own. |
|
| 163 | - * |
|
| 164 | - * @param EE_Form_Section_Base $subsection |
|
| 165 | - * @return string html |
|
| 166 | - */ |
|
| 167 | - abstract public function layout_subsection($subsection); |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Gets the HTML for the label tag and its contents for the input |
|
| 173 | - * |
|
| 174 | - * @param EE_Form_Input_Base $input |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 177 | - public function display_label($input) |
|
| 178 | - { |
|
| 179 | - if($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy){ |
|
| 180 | - return ''; |
|
| 181 | - } |
|
| 182 | - $class = $input->required() |
|
| 183 | - ? 'ee-required-label ' . $input->html_label_class() |
|
| 184 | - : $input->html_label_class(); |
|
| 185 | - $label_text = $input->required() |
|
| 186 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
| 187 | - : $input->html_label_text(); |
|
| 188 | - return '<label id="' |
|
| 189 | - . $input->html_label_id() |
|
| 190 | - . '" class="' |
|
| 191 | - . $class |
|
| 192 | - . '" style="' |
|
| 193 | - . $input->html_label_style() |
|
| 194 | - . '" for="' . $input->html_name() |
|
| 195 | - . '">' |
|
| 196 | - . $label_text |
|
| 197 | - . '</label>'; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
| 204 | - * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
| 205 | - * those errors would probably be on the form section, not one of its inputs) |
|
| 206 | - * @return string |
|
| 207 | - */ |
|
| 208 | - public function display_form_wide_errors() |
|
| 209 | - { |
|
| 210 | - $html = ''; |
|
| 211 | - if ($this->_form_section->get_validation_errors()) { |
|
| 212 | - $html .= "<div class='ee-form-wide-errors'>"; |
|
| 213 | - //get all the errors on THIS form section (errors which aren't |
|
| 214 | - //for specific inputs, but instead for the entire form section) |
|
| 215 | - foreach ($this->_form_section->get_validation_errors() as $error) { |
|
| 216 | - $html .= $error->getMessage() . '<br>'; |
|
| 217 | - } |
|
| 218 | - $html .= '</div>'; |
|
| 219 | - } |
|
| 220 | - return apply_filters( |
|
| 221 | - 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
| 222 | - $html, |
|
| 223 | - $this |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * returns the HTML for the server-side validation errors for the specified input |
|
| 231 | - * Note that if JS is enabled, it should remove these and instead |
|
| 232 | - * populate the form's errors in the jquery validate fashion |
|
| 233 | - * using the localized data provided to the JS |
|
| 234 | - * |
|
| 235 | - * @param EE_Form_Input_Base $input |
|
| 236 | - * @return string |
|
| 237 | - */ |
|
| 238 | - public function display_errors($input) |
|
| 239 | - { |
|
| 240 | - if ($input->get_validation_errors()) { |
|
| 241 | - return "<label id='" |
|
| 242 | - . $input->html_id() |
|
| 243 | - . "-error' class='error' for='{$input->html_name()}'>" |
|
| 244 | - . $input->get_validation_error_string() |
|
| 245 | - . '</label>'; |
|
| 246 | - } |
|
| 247 | - return ''; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Displays the help span for the specified input |
|
| 254 | - * |
|
| 255 | - * @param EE_Form_Input_Base $input |
|
| 256 | - * @return string |
|
| 257 | - */ |
|
| 258 | - public function display_help_text($input) |
|
| 259 | - { |
|
| 260 | - $help_text = $input->html_help_text(); |
|
| 261 | - if ($help_text !== '' && $help_text !== null) { |
|
| 262 | - $tag = is_admin() ? 'p' : 'span'; |
|
| 263 | - return '<' |
|
| 264 | - . $tag |
|
| 265 | - . ' id="' |
|
| 266 | - . $input->html_id() |
|
| 267 | - . '-help" class="' |
|
| 268 | - . $input->html_help_class() |
|
| 269 | - . '" style="' |
|
| 270 | - . $input->html_help_style() |
|
| 271 | - . '">' |
|
| 272 | - . $help_text |
|
| 273 | - . '</' |
|
| 274 | - . $tag |
|
| 275 | - . '>'; |
|
| 276 | - } |
|
| 277 | - return ''; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Does an action and hook onto the end of teh form |
|
| 284 | - * |
|
| 285 | - * @param string $html |
|
| 286 | - * @return string |
|
| 287 | - */ |
|
| 288 | - public function add_form_section_hooks_and_filters($html) |
|
| 289 | - { |
|
| 290 | - // replace dashes and spaces with underscores |
|
| 291 | - $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
| 292 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
| 293 | - $html = (string) apply_filters( |
|
| 294 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
| 295 | - $html, |
|
| 296 | - $this->_form_section |
|
| 297 | - ); |
|
| 298 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
| 299 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
| 300 | - return $html; |
|
| 301 | - } |
|
| 18 | + /** |
|
| 19 | + * Form form section to lay out |
|
| 20 | + * |
|
| 21 | + * @var EE_Form_Section_Proper |
|
| 22 | + */ |
|
| 23 | + protected $_form_section; |
|
| 24 | + |
|
| 25 | + |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * __construct |
|
| 29 | + */ |
|
| 30 | + public function __construct() |
|
| 31 | + { |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * The form section on which this strategy is to perform |
|
| 38 | + * |
|
| 39 | + * @param EE_Form_Section_Proper $form |
|
| 40 | + */ |
|
| 41 | + public function _construct_finalize(EE_Form_Section_Proper $form) |
|
| 42 | + { |
|
| 43 | + $this->_form_section = $form; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @return EE_Form_Section_Proper |
|
| 50 | + */ |
|
| 51 | + public function form_section() |
|
| 52 | + { |
|
| 53 | + return $this->_form_section; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Also has teh side effect of enqueuing any needed JS and CSS for |
|
| 60 | + * this form. |
|
| 61 | + * Creates all the HTML necessary for displaying this form, its inputs, and |
|
| 62 | + * proper subsections. |
|
| 63 | + * Returns the HTML |
|
| 64 | + * |
|
| 65 | + * @return string HTML for displaying |
|
| 66 | + * @throws EE_Error |
|
| 67 | + */ |
|
| 68 | + public function layout_form() |
|
| 69 | + { |
|
| 70 | + $html = ''; |
|
| 71 | + // layout_form_begin |
|
| 72 | + $html .= apply_filters( |
|
| 73 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
| 74 | + $this->layout_form_begin(), |
|
| 75 | + $this->_form_section |
|
| 76 | + ); |
|
| 77 | + // layout_form_loop |
|
| 78 | + $html .= apply_filters( |
|
| 79 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
| 80 | + $this->layout_form_loop(), |
|
| 81 | + $this->_form_section |
|
| 82 | + ); |
|
| 83 | + // layout_form_end |
|
| 84 | + $html .= apply_filters( |
|
| 85 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
| 86 | + $this->layout_form_end(), |
|
| 87 | + $this->_form_section |
|
| 88 | + ); |
|
| 89 | + $html = $this->add_form_section_hooks_and_filters($html); |
|
| 90 | + return $html; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @return string |
|
| 97 | + * @throws EE_Error |
|
| 98 | + */ |
|
| 99 | + public function layout_form_loop() |
|
| 100 | + { |
|
| 101 | + $html = ''; |
|
| 102 | + foreach ($this->_form_section->subsections() as $name => $subsection) { |
|
| 103 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
| 104 | + $html .= apply_filters( |
|
| 105 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
|
| 106 | + . $name . '__in_' . $this->_form_section->name(), |
|
| 107 | + $this->layout_input($subsection), |
|
| 108 | + $this->_form_section, |
|
| 109 | + $subsection |
|
| 110 | + ); |
|
| 111 | + } elseif ($subsection instanceof EE_Form_Section_Base) { |
|
| 112 | + $html .= apply_filters( |
|
| 113 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
|
| 114 | + . $name . '__in_' . $this->_form_section->name(), |
|
| 115 | + $this->layout_subsection($subsection), |
|
| 116 | + $this->_form_section, |
|
| 117 | + $subsection |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + return $html; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Should be used to start teh form section (Eg a table tag, or a div tag, etc.) |
|
| 128 | + * |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + abstract public function layout_form_begin(); |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Should be used to end the form section (eg a /table tag, or a /div tag, etc) |
|
| 137 | + * |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + abstract public function layout_form_end(); |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Should be used internally by layout_form() to layout each input (eg, if this layout |
|
| 146 | + * is putting each input in a row of its own, this should probably be called by a |
|
| 147 | + * foreach loop in layout_form() (WITHOUT adding any content directly within layout_form()'s foreach loop. |
|
| 148 | + * Eg, this method should add the tr and td tags). This method is exposed in case you want to completely |
|
| 149 | + * customize the form's layout, but would like to make use of it for laying out |
|
| 150 | + * 'easy-to-layout' inputs |
|
| 151 | + * |
|
| 152 | + * @param EE_Form_Input_Base $input |
|
| 153 | + * @return string html |
|
| 154 | + */ |
|
| 155 | + abstract public function layout_input($input); |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Similar to layout_input(), should be used internally by layout_form() within a |
|
| 161 | + * loop to layout each proper subsection. Unlike layout_input(), however, it is assumed |
|
| 162 | + * that the proper subsection will layout its container, label, etc on its own. |
|
| 163 | + * |
|
| 164 | + * @param EE_Form_Section_Base $subsection |
|
| 165 | + * @return string html |
|
| 166 | + */ |
|
| 167 | + abstract public function layout_subsection($subsection); |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Gets the HTML for the label tag and its contents for the input |
|
| 173 | + * |
|
| 174 | + * @param EE_Form_Input_Base $input |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | + public function display_label($input) |
|
| 178 | + { |
|
| 179 | + if($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy){ |
|
| 180 | + return ''; |
|
| 181 | + } |
|
| 182 | + $class = $input->required() |
|
| 183 | + ? 'ee-required-label ' . $input->html_label_class() |
|
| 184 | + : $input->html_label_class(); |
|
| 185 | + $label_text = $input->required() |
|
| 186 | + ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
| 187 | + : $input->html_label_text(); |
|
| 188 | + return '<label id="' |
|
| 189 | + . $input->html_label_id() |
|
| 190 | + . '" class="' |
|
| 191 | + . $class |
|
| 192 | + . '" style="' |
|
| 193 | + . $input->html_label_style() |
|
| 194 | + . '" for="' . $input->html_name() |
|
| 195 | + . '">' |
|
| 196 | + . $label_text |
|
| 197 | + . '</label>'; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Gets the HTML for all the form's form-wide errors (ie, errors which |
|
| 204 | + * are not for specific inputs. E.g., if two inputs somehow disagree, |
|
| 205 | + * those errors would probably be on the form section, not one of its inputs) |
|
| 206 | + * @return string |
|
| 207 | + */ |
|
| 208 | + public function display_form_wide_errors() |
|
| 209 | + { |
|
| 210 | + $html = ''; |
|
| 211 | + if ($this->_form_section->get_validation_errors()) { |
|
| 212 | + $html .= "<div class='ee-form-wide-errors'>"; |
|
| 213 | + //get all the errors on THIS form section (errors which aren't |
|
| 214 | + //for specific inputs, but instead for the entire form section) |
|
| 215 | + foreach ($this->_form_section->get_validation_errors() as $error) { |
|
| 216 | + $html .= $error->getMessage() . '<br>'; |
|
| 217 | + } |
|
| 218 | + $html .= '</div>'; |
|
| 219 | + } |
|
| 220 | + return apply_filters( |
|
| 221 | + 'FHEE__EE_Form_Section_Layout_Base__display_form_wide_errors', |
|
| 222 | + $html, |
|
| 223 | + $this |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * returns the HTML for the server-side validation errors for the specified input |
|
| 231 | + * Note that if JS is enabled, it should remove these and instead |
|
| 232 | + * populate the form's errors in the jquery validate fashion |
|
| 233 | + * using the localized data provided to the JS |
|
| 234 | + * |
|
| 235 | + * @param EE_Form_Input_Base $input |
|
| 236 | + * @return string |
|
| 237 | + */ |
|
| 238 | + public function display_errors($input) |
|
| 239 | + { |
|
| 240 | + if ($input->get_validation_errors()) { |
|
| 241 | + return "<label id='" |
|
| 242 | + . $input->html_id() |
|
| 243 | + . "-error' class='error' for='{$input->html_name()}'>" |
|
| 244 | + . $input->get_validation_error_string() |
|
| 245 | + . '</label>'; |
|
| 246 | + } |
|
| 247 | + return ''; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Displays the help span for the specified input |
|
| 254 | + * |
|
| 255 | + * @param EE_Form_Input_Base $input |
|
| 256 | + * @return string |
|
| 257 | + */ |
|
| 258 | + public function display_help_text($input) |
|
| 259 | + { |
|
| 260 | + $help_text = $input->html_help_text(); |
|
| 261 | + if ($help_text !== '' && $help_text !== null) { |
|
| 262 | + $tag = is_admin() ? 'p' : 'span'; |
|
| 263 | + return '<' |
|
| 264 | + . $tag |
|
| 265 | + . ' id="' |
|
| 266 | + . $input->html_id() |
|
| 267 | + . '-help" class="' |
|
| 268 | + . $input->html_help_class() |
|
| 269 | + . '" style="' |
|
| 270 | + . $input->html_help_style() |
|
| 271 | + . '">' |
|
| 272 | + . $help_text |
|
| 273 | + . '</' |
|
| 274 | + . $tag |
|
| 275 | + . '>'; |
|
| 276 | + } |
|
| 277 | + return ''; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Does an action and hook onto the end of teh form |
|
| 284 | + * |
|
| 285 | + * @param string $html |
|
| 286 | + * @return string |
|
| 287 | + */ |
|
| 288 | + public function add_form_section_hooks_and_filters($html) |
|
| 289 | + { |
|
| 290 | + // replace dashes and spaces with underscores |
|
| 291 | + $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
|
| 292 | + do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
| 293 | + $html = (string) apply_filters( |
|
| 294 | + 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
| 295 | + $html, |
|
| 296 | + $this->_form_section |
|
| 297 | + ); |
|
| 298 | + $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
| 299 | + $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
| 300 | + return $html; |
|
| 301 | + } |
|
| 302 | 302 | } |
@@ -70,19 +70,19 @@ discard block |
||
| 70 | 70 | $html = ''; |
| 71 | 71 | // layout_form_begin |
| 72 | 72 | $html .= apply_filters( |
| 73 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_' . $this->_form_section->name(), |
|
| 73 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__start__for_'.$this->_form_section->name(), |
|
| 74 | 74 | $this->layout_form_begin(), |
| 75 | 75 | $this->_form_section |
| 76 | 76 | ); |
| 77 | 77 | // layout_form_loop |
| 78 | 78 | $html .= apply_filters( |
| 79 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_' . $this->_form_section->name(), |
|
| 79 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop__for_'.$this->_form_section->name(), |
|
| 80 | 80 | $this->layout_form_loop(), |
| 81 | 81 | $this->_form_section |
| 82 | 82 | ); |
| 83 | 83 | // layout_form_end |
| 84 | 84 | $html .= apply_filters( |
| 85 | - 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_' . $this->_form_section->name(), |
|
| 85 | + 'FHEE__EE_Form_Section_Layout_Base__layout_form__end__for_'.$this->_form_section->name(), |
|
| 86 | 86 | $this->layout_form_end(), |
| 87 | 87 | $this->_form_section |
| 88 | 88 | ); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | if ($subsection instanceof EE_Form_Input_Base) { |
| 104 | 104 | $html .= apply_filters( |
| 105 | 105 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_input_' |
| 106 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 106 | + . $name.'__in_'.$this->_form_section->name(), |
|
| 107 | 107 | $this->layout_input($subsection), |
| 108 | 108 | $this->_form_section, |
| 109 | 109 | $subsection |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | } elseif ($subsection instanceof EE_Form_Section_Base) { |
| 112 | 112 | $html .= apply_filters( |
| 113 | 113 | 'FHEE__EE_Form_Section_Layout_Base__layout_form__loop_for_non_input_' |
| 114 | - . $name . '__in_' . $this->_form_section->name(), |
|
| 114 | + . $name.'__in_'.$this->_form_section->name(), |
|
| 115 | 115 | $this->layout_subsection($subsection), |
| 116 | 116 | $this->_form_section, |
| 117 | 117 | $subsection |
@@ -176,14 +176,14 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | public function display_label($input) |
| 178 | 178 | { |
| 179 | - if($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy){ |
|
| 179 | + if ($input->get_display_strategy() instanceof EE_Hidden_Display_Strategy) { |
|
| 180 | 180 | return ''; |
| 181 | 181 | } |
| 182 | 182 | $class = $input->required() |
| 183 | - ? 'ee-required-label ' . $input->html_label_class() |
|
| 183 | + ? 'ee-required-label '.$input->html_label_class() |
|
| 184 | 184 | : $input->html_label_class(); |
| 185 | 185 | $label_text = $input->required() |
| 186 | - ? $input->html_label_text() . '<span class="ee-asterisk">*</span>' |
|
| 186 | + ? $input->html_label_text().'<span class="ee-asterisk">*</span>' |
|
| 187 | 187 | : $input->html_label_text(); |
| 188 | 188 | return '<label id="' |
| 189 | 189 | . $input->html_label_id() |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | . $class |
| 192 | 192 | . '" style="' |
| 193 | 193 | . $input->html_label_style() |
| 194 | - . '" for="' . $input->html_name() |
|
| 194 | + . '" for="'.$input->html_name() |
|
| 195 | 195 | . '">' |
| 196 | 196 | . $label_text |
| 197 | 197 | . '</label>'; |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | //get all the errors on THIS form section (errors which aren't |
| 214 | 214 | //for specific inputs, but instead for the entire form section) |
| 215 | 215 | foreach ($this->_form_section->get_validation_errors() as $error) { |
| 216 | - $html .= $error->getMessage() . '<br>'; |
|
| 216 | + $html .= $error->getMessage().'<br>'; |
|
| 217 | 217 | } |
| 218 | 218 | $html .= '</div>'; |
| 219 | 219 | } |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public function display_help_text($input) |
| 259 | 259 | { |
| 260 | - $help_text = $input->html_help_text(); |
|
| 260 | + $help_text = $input->html_help_text(); |
|
| 261 | 261 | if ($help_text !== '' && $help_text !== null) { |
| 262 | 262 | $tag = is_admin() ? 'p' : 'span'; |
| 263 | 263 | return '<' |
@@ -289,14 +289,14 @@ discard block |
||
| 289 | 289 | { |
| 290 | 290 | // replace dashes and spaces with underscores |
| 291 | 291 | $hook_name = str_replace(array('-', ' '), '_', $this->_form_section->html_id()); |
| 292 | - do_action('AHEE__Form_Section_Layout__' . $hook_name, $this->_form_section); |
|
| 292 | + do_action('AHEE__Form_Section_Layout__'.$hook_name, $this->_form_section); |
|
| 293 | 293 | $html = (string) apply_filters( |
| 294 | - 'AFEE__Form_Section_Layout__' . $hook_name . '__html', |
|
| 294 | + 'AFEE__Form_Section_Layout__'.$hook_name.'__html', |
|
| 295 | 295 | $html, |
| 296 | 296 | $this->_form_section |
| 297 | 297 | ); |
| 298 | - $html .= EEH_HTML::nl() . '<!-- AHEE__Form_Section_Layout__' . $hook_name . '__html -->'; |
|
| 299 | - $html .= EEH_HTML::nl() . '<!-- AFEE__Form_Section_Layout__' . $hook_name . ' -->'; |
|
| 298 | + $html .= EEH_HTML::nl().'<!-- AHEE__Form_Section_Layout__'.$hook_name.'__html -->'; |
|
| 299 | + $html .= EEH_HTML::nl().'<!-- AFEE__Form_Section_Layout__'.$hook_name.' -->'; |
|
| 300 | 300 | return $html; |
| 301 | 301 | } |
| 302 | 302 | } |
@@ -17,1343 +17,1343 @@ |
||
| 17 | 17 | class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @type bool $_print_copy_info |
|
| 22 | - */ |
|
| 23 | - private $_print_copy_info = false; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @type array $_attendee_data |
|
| 27 | - */ |
|
| 28 | - private $_attendee_data = array(); |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @type array $_required_questions |
|
| 32 | - */ |
|
| 33 | - private $_required_questions = array(); |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @type array $_registration_answers |
|
| 37 | - */ |
|
| 38 | - private $_registration_answers = array(); |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * class constructor |
|
| 43 | - * |
|
| 44 | - * @access public |
|
| 45 | - * @param EE_Checkout $checkout |
|
| 46 | - */ |
|
| 47 | - public function __construct(EE_Checkout $checkout) |
|
| 48 | - { |
|
| 49 | - $this->_slug = 'attendee_information'; |
|
| 50 | - $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
| 51 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
| 52 | - $this->checkout = $checkout; |
|
| 53 | - $this->_reset_success_message(); |
|
| 54 | - $this->set_instructions( |
|
| 55 | - esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - public function translate_js_strings() |
|
| 61 | - { |
|
| 62 | - EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
| 63 | - ' is a required question.', |
|
| 64 | - 'event_espresso' |
|
| 65 | - ); |
|
| 66 | - EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
| 67 | - ' is a required question. Please enter a value for at least one of the options.', |
|
| 68 | - 'event_espresso' |
|
| 69 | - ); |
|
| 70 | - EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
| 71 | - 'Please answer all required questions correctly before proceeding.', |
|
| 72 | - 'event_espresso' |
|
| 73 | - ); |
|
| 74 | - EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
| 75 | - esc_html__( |
|
| 76 | - 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
| 77 | - 'event_espresso' |
|
| 78 | - ), |
|
| 79 | - '<br/>' |
|
| 80 | - ); |
|
| 81 | - EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
| 82 | - 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
| 83 | - 'event_espresso' |
|
| 84 | - ); |
|
| 85 | - EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
| 86 | - 'You must enter a valid email address.', |
|
| 87 | - 'event_espresso' |
|
| 88 | - ); |
|
| 89 | - EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
| 90 | - 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
| 91 | - 'event_espresso' |
|
| 92 | - ); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - public function enqueue_styles_and_scripts() |
|
| 97 | - { |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @return boolean |
|
| 103 | - */ |
|
| 104 | - public function initialize_reg_step() |
|
| 105 | - { |
|
| 106 | - return true; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @return EE_Form_Section_Proper |
|
| 112 | - * @throws EE_Error |
|
| 113 | - * @throws InvalidArgumentException |
|
| 114 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 115 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 116 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 117 | - */ |
|
| 118 | - public function generate_reg_form() |
|
| 119 | - { |
|
| 120 | - $this->_print_copy_info = false; |
|
| 121 | - $primary_registrant = null; |
|
| 122 | - // autoload Line_Item_Display classes |
|
| 123 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 124 | - $Line_Item_Display = new EE_Line_Item_Display(); |
|
| 125 | - // calculate taxes |
|
| 126 | - $Line_Item_Display->display_line_item( |
|
| 127 | - $this->checkout->cart->get_grand_total(), |
|
| 128 | - array('set_tax_rate' => true) |
|
| 129 | - ); |
|
| 130 | - /** @var $subsections EE_Form_Section_Proper[] */ |
|
| 131 | - $subsections = array( |
|
| 132 | - 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
| 133 | - ); |
|
| 134 | - $template_args = array( |
|
| 135 | - 'revisit' => $this->checkout->revisit, |
|
| 136 | - 'registrations' => array(), |
|
| 137 | - 'ticket_count' => array(), |
|
| 138 | - ); |
|
| 139 | - // grab the saved registrations from the transaction |
|
| 140 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 141 | - if ($registrations) { |
|
| 142 | - foreach ($registrations as $registration) { |
|
| 143 | - // can this registration be processed during this visit ? |
|
| 144 | - if ($registration instanceof EE_Registration |
|
| 145 | - && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
| 146 | - ) { |
|
| 147 | - $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
|
| 148 | - if (! $this->checkout->admin_request) { |
|
| 149 | - $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
| 150 | - $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
| 151 | - $template_args['ticket_count'][$registration->ticket()->ID()] |
|
| 152 | - ) |
|
| 153 | - ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
| 154 | - : 1; |
|
| 155 | - $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
| 156 | - $this->checkout->cart->get_grand_total(), |
|
| 157 | - 'Ticket', |
|
| 158 | - array($registration->ticket()->ID()) |
|
| 159 | - ); |
|
| 160 | - $ticket_line_item = is_array($ticket_line_item) |
|
| 161 | - ? reset($ticket_line_item) |
|
| 162 | - : $ticket_line_item; |
|
| 163 | - $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
| 164 | - $Line_Item_Display->display_line_item($ticket_line_item); |
|
| 165 | - } |
|
| 166 | - if ($registration->is_primary_registrant()) { |
|
| 167 | - $primary_registrant = $registration->reg_url_link(); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - // print_copy_info ? |
|
| 172 | - if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
| 173 | - // TODO: add admin option for toggling copy attendee info, |
|
| 174 | - // then use that value to change $this->_print_copy_info |
|
| 175 | - $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
| 176 | - ? $this->_copy_attendee_info_form() |
|
| 177 | - : $this->_auto_copy_attendee_info(); |
|
| 178 | - // generate hidden input |
|
| 179 | - if (isset($subsections[$primary_registrant]) |
|
| 180 | - && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
| 181 | - ) { |
|
| 182 | - $subsections[$primary_registrant]->add_subsections( |
|
| 183 | - $copy_options, |
|
| 184 | - 'primary_registrant', |
|
| 185 | - false |
|
| 186 | - ); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return new EE_Form_Section_Proper( |
|
| 192 | - array( |
|
| 193 | - 'name' => $this->reg_form_name(), |
|
| 194 | - 'html_id' => $this->reg_form_name(), |
|
| 195 | - 'subsections' => $subsections, |
|
| 196 | - 'layout_strategy' => $this->checkout->admin_request ? |
|
| 197 | - new EE_Div_Per_Section_Layout() : |
|
| 198 | - new EE_Template_Layout( |
|
| 199 | - array( |
|
| 200 | - 'layout_template_file' => $this->_template, // layout_template |
|
| 201 | - 'template_args' => $template_args, |
|
| 202 | - ) |
|
| 203 | - ), |
|
| 204 | - ) |
|
| 205 | - ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * @param EE_Registration $registration |
|
| 211 | - * @return EE_Form_Section_Base |
|
| 212 | - * @throws EE_Error |
|
| 213 | - * @throws InvalidArgumentException |
|
| 214 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 215 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 216 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 217 | - */ |
|
| 218 | - private function _registrations_reg_form(EE_Registration $registration) |
|
| 219 | - { |
|
| 220 | - static $attendee_nmbr = 1; |
|
| 221 | - $form_args = array(); |
|
| 222 | - // verify that registration has valid event |
|
| 223 | - if ($registration->event() instanceof EE_Event) { |
|
| 224 | - $question_groups = $registration->event()->question_groups( |
|
| 225 | - apply_filters( |
|
| 226 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
| 227 | - array( |
|
| 228 | - array( |
|
| 229 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
| 230 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
| 231 | - ), |
|
| 232 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
| 233 | - ), |
|
| 234 | - $registration, |
|
| 235 | - $this |
|
| 236 | - ) |
|
| 237 | - ); |
|
| 238 | - if ($question_groups) { |
|
| 239 | - // array of params to pass to parent constructor |
|
| 240 | - $form_args = array( |
|
| 241 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
| 242 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
| 243 | - 'html_style' => $this->checkout->admin_request |
|
| 244 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
| 245 | - : '', |
|
| 246 | - 'subsections' => array(), |
|
| 247 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
| 248 | - array( |
|
| 249 | - 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
| 250 | - 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr), |
|
| 251 | - ) |
|
| 252 | - ), |
|
| 253 | - ); |
|
| 254 | - foreach ($question_groups as $question_group) { |
|
| 255 | - if ($question_group instanceof EE_Question_Group) { |
|
| 256 | - $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
| 257 | - $registration, |
|
| 258 | - $question_group |
|
| 259 | - ); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - // add hidden input |
|
| 263 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
| 264 | - $registration |
|
| 265 | - ); |
|
| 266 | - // if we have question groups for additional attendees, then display the copy options |
|
| 267 | - $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
|
| 268 | - if ($registration->is_primary_registrant()) { |
|
| 269 | - // generate hidden input |
|
| 270 | - $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
| 271 | - $registration |
|
| 272 | - ); |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - $attendee_nmbr++; |
|
| 277 | - return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : new EE_Form_Section_HTML(); |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * _additional_attendee_reg_info_input |
|
| 283 | - * |
|
| 284 | - * @access public |
|
| 285 | - * @param EE_Registration $registration |
|
| 286 | - * @param bool $additional_attendee_reg_info |
|
| 287 | - * @return EE_Form_Input_Base |
|
| 288 | - * @throws \EE_Error |
|
| 289 | - */ |
|
| 290 | - private function _additional_attendee_reg_info_input( |
|
| 291 | - EE_Registration $registration, |
|
| 292 | - $additional_attendee_reg_info = true |
|
| 293 | - ) { |
|
| 294 | - // generate hidden input |
|
| 295 | - return new EE_Hidden_Input( |
|
| 296 | - array( |
|
| 297 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
| 298 | - 'default' => $additional_attendee_reg_info, |
|
| 299 | - ) |
|
| 300 | - ); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * @param EE_Registration $registration |
|
| 306 | - * @param EE_Question_Group $question_group |
|
| 307 | - * @return EE_Form_Section_Proper |
|
| 308 | - * @throws EE_Error |
|
| 309 | - * @throws InvalidArgumentException |
|
| 310 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 311 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 312 | - */ |
|
| 313 | - private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
| 314 | - { |
|
| 315 | - // array of params to pass to parent constructor |
|
| 316 | - $form_args = array( |
|
| 317 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
| 318 | - 'html_class' => $this->checkout->admin_request |
|
| 319 | - ? 'form-table ee-reg-form-qstn-grp-dv' |
|
| 320 | - : 'ee-reg-form-qstn-grp-dv', |
|
| 321 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID() . '-lbl', |
|
| 322 | - 'subsections' => array( |
|
| 323 | - 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
| 324 | - ), |
|
| 325 | - 'layout_strategy' => $this->checkout->admin_request |
|
| 326 | - ? new EE_Admin_Two_Column_Layout() |
|
| 327 | - : new EE_Div_Per_Section_Layout(), |
|
| 328 | - ); |
|
| 329 | - // where params |
|
| 330 | - $query_params = array('QST_deleted' => 0); |
|
| 331 | - // don't load admin only questions on the frontend |
|
| 332 | - if (! $this->checkout->admin_request) { |
|
| 333 | - $query_params['QST_admin_only'] = array('!=', true); |
|
| 334 | - } |
|
| 335 | - $questions = $question_group->get_many_related( |
|
| 336 | - 'Question', |
|
| 337 | - apply_filters( |
|
| 338 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
| 339 | - array( |
|
| 340 | - $query_params, |
|
| 341 | - 'order_by' => array( |
|
| 342 | - 'Question_Group_Question.QGQ_order' => 'ASC', |
|
| 343 | - ), |
|
| 344 | - ), |
|
| 345 | - $question_group, |
|
| 346 | - $registration, |
|
| 347 | - $this |
|
| 348 | - ) |
|
| 349 | - ); |
|
| 350 | - // filter for additional content before questions |
|
| 351 | - $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
| 352 | - apply_filters( |
|
| 353 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
| 354 | - '', |
|
| 355 | - $registration, |
|
| 356 | - $question_group, |
|
| 357 | - $this |
|
| 358 | - ) |
|
| 359 | - ); |
|
| 360 | - // loop thru questions |
|
| 361 | - foreach ($questions as $question) { |
|
| 362 | - if ($question instanceof EE_Question) { |
|
| 363 | - $identifier = $question->is_system_question() |
|
| 364 | - ? $question->system_ID() |
|
| 365 | - : $question->ID(); |
|
| 366 | - $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - $form_args['subsections'] = apply_filters( |
|
| 370 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
| 371 | - $form_args['subsections'], |
|
| 372 | - $registration, |
|
| 373 | - $question_group, |
|
| 374 | - $this |
|
| 375 | - ); |
|
| 376 | - // filter for additional content after questions |
|
| 377 | - $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
| 378 | - apply_filters( |
|
| 379 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
| 380 | - '', |
|
| 381 | - $registration, |
|
| 382 | - $question_group, |
|
| 383 | - $this |
|
| 384 | - ) |
|
| 385 | - ); |
|
| 20 | + /** |
|
| 21 | + * @type bool $_print_copy_info |
|
| 22 | + */ |
|
| 23 | + private $_print_copy_info = false; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @type array $_attendee_data |
|
| 27 | + */ |
|
| 28 | + private $_attendee_data = array(); |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @type array $_required_questions |
|
| 32 | + */ |
|
| 33 | + private $_required_questions = array(); |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @type array $_registration_answers |
|
| 37 | + */ |
|
| 38 | + private $_registration_answers = array(); |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * class constructor |
|
| 43 | + * |
|
| 44 | + * @access public |
|
| 45 | + * @param EE_Checkout $checkout |
|
| 46 | + */ |
|
| 47 | + public function __construct(EE_Checkout $checkout) |
|
| 48 | + { |
|
| 49 | + $this->_slug = 'attendee_information'; |
|
| 50 | + $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
| 51 | + $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
| 52 | + $this->checkout = $checkout; |
|
| 53 | + $this->_reset_success_message(); |
|
| 54 | + $this->set_instructions( |
|
| 55 | + esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + public function translate_js_strings() |
|
| 61 | + { |
|
| 62 | + EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
| 63 | + ' is a required question.', |
|
| 64 | + 'event_espresso' |
|
| 65 | + ); |
|
| 66 | + EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
| 67 | + ' is a required question. Please enter a value for at least one of the options.', |
|
| 68 | + 'event_espresso' |
|
| 69 | + ); |
|
| 70 | + EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
| 71 | + 'Please answer all required questions correctly before proceeding.', |
|
| 72 | + 'event_espresso' |
|
| 73 | + ); |
|
| 74 | + EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
| 75 | + esc_html__( |
|
| 76 | + 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
| 77 | + 'event_espresso' |
|
| 78 | + ), |
|
| 79 | + '<br/>' |
|
| 80 | + ); |
|
| 81 | + EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
| 82 | + 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
| 83 | + 'event_espresso' |
|
| 84 | + ); |
|
| 85 | + EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
| 86 | + 'You must enter a valid email address.', |
|
| 87 | + 'event_espresso' |
|
| 88 | + ); |
|
| 89 | + EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
| 90 | + 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
| 91 | + 'event_espresso' |
|
| 92 | + ); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + public function enqueue_styles_and_scripts() |
|
| 97 | + { |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @return boolean |
|
| 103 | + */ |
|
| 104 | + public function initialize_reg_step() |
|
| 105 | + { |
|
| 106 | + return true; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @return EE_Form_Section_Proper |
|
| 112 | + * @throws EE_Error |
|
| 113 | + * @throws InvalidArgumentException |
|
| 114 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 115 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 116 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 117 | + */ |
|
| 118 | + public function generate_reg_form() |
|
| 119 | + { |
|
| 120 | + $this->_print_copy_info = false; |
|
| 121 | + $primary_registrant = null; |
|
| 122 | + // autoload Line_Item_Display classes |
|
| 123 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 124 | + $Line_Item_Display = new EE_Line_Item_Display(); |
|
| 125 | + // calculate taxes |
|
| 126 | + $Line_Item_Display->display_line_item( |
|
| 127 | + $this->checkout->cart->get_grand_total(), |
|
| 128 | + array('set_tax_rate' => true) |
|
| 129 | + ); |
|
| 130 | + /** @var $subsections EE_Form_Section_Proper[] */ |
|
| 131 | + $subsections = array( |
|
| 132 | + 'default_hidden_inputs' => $this->reg_step_hidden_inputs(), |
|
| 133 | + ); |
|
| 134 | + $template_args = array( |
|
| 135 | + 'revisit' => $this->checkout->revisit, |
|
| 136 | + 'registrations' => array(), |
|
| 137 | + 'ticket_count' => array(), |
|
| 138 | + ); |
|
| 139 | + // grab the saved registrations from the transaction |
|
| 140 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 141 | + if ($registrations) { |
|
| 142 | + foreach ($registrations as $registration) { |
|
| 143 | + // can this registration be processed during this visit ? |
|
| 144 | + if ($registration instanceof EE_Registration |
|
| 145 | + && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
| 146 | + ) { |
|
| 147 | + $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
|
| 148 | + if (! $this->checkout->admin_request) { |
|
| 149 | + $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
| 150 | + $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
| 151 | + $template_args['ticket_count'][$registration->ticket()->ID()] |
|
| 152 | + ) |
|
| 153 | + ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
| 154 | + : 1; |
|
| 155 | + $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
| 156 | + $this->checkout->cart->get_grand_total(), |
|
| 157 | + 'Ticket', |
|
| 158 | + array($registration->ticket()->ID()) |
|
| 159 | + ); |
|
| 160 | + $ticket_line_item = is_array($ticket_line_item) |
|
| 161 | + ? reset($ticket_line_item) |
|
| 162 | + : $ticket_line_item; |
|
| 163 | + $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
| 164 | + $Line_Item_Display->display_line_item($ticket_line_item); |
|
| 165 | + } |
|
| 166 | + if ($registration->is_primary_registrant()) { |
|
| 167 | + $primary_registrant = $registration->reg_url_link(); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + // print_copy_info ? |
|
| 172 | + if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
| 173 | + // TODO: add admin option for toggling copy attendee info, |
|
| 174 | + // then use that value to change $this->_print_copy_info |
|
| 175 | + $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
| 176 | + ? $this->_copy_attendee_info_form() |
|
| 177 | + : $this->_auto_copy_attendee_info(); |
|
| 178 | + // generate hidden input |
|
| 179 | + if (isset($subsections[$primary_registrant]) |
|
| 180 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
| 181 | + ) { |
|
| 182 | + $subsections[$primary_registrant]->add_subsections( |
|
| 183 | + $copy_options, |
|
| 184 | + 'primary_registrant', |
|
| 185 | + false |
|
| 186 | + ); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return new EE_Form_Section_Proper( |
|
| 192 | + array( |
|
| 193 | + 'name' => $this->reg_form_name(), |
|
| 194 | + 'html_id' => $this->reg_form_name(), |
|
| 195 | + 'subsections' => $subsections, |
|
| 196 | + 'layout_strategy' => $this->checkout->admin_request ? |
|
| 197 | + new EE_Div_Per_Section_Layout() : |
|
| 198 | + new EE_Template_Layout( |
|
| 199 | + array( |
|
| 200 | + 'layout_template_file' => $this->_template, // layout_template |
|
| 201 | + 'template_args' => $template_args, |
|
| 202 | + ) |
|
| 203 | + ), |
|
| 204 | + ) |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * @param EE_Registration $registration |
|
| 211 | + * @return EE_Form_Section_Base |
|
| 212 | + * @throws EE_Error |
|
| 213 | + * @throws InvalidArgumentException |
|
| 214 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 215 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 216 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 217 | + */ |
|
| 218 | + private function _registrations_reg_form(EE_Registration $registration) |
|
| 219 | + { |
|
| 220 | + static $attendee_nmbr = 1; |
|
| 221 | + $form_args = array(); |
|
| 222 | + // verify that registration has valid event |
|
| 223 | + if ($registration->event() instanceof EE_Event) { |
|
| 224 | + $question_groups = $registration->event()->question_groups( |
|
| 225 | + apply_filters( |
|
| 226 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
| 227 | + array( |
|
| 228 | + array( |
|
| 229 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
| 230 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
| 231 | + ), |
|
| 232 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
| 233 | + ), |
|
| 234 | + $registration, |
|
| 235 | + $this |
|
| 236 | + ) |
|
| 237 | + ); |
|
| 238 | + if ($question_groups) { |
|
| 239 | + // array of params to pass to parent constructor |
|
| 240 | + $form_args = array( |
|
| 241 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
| 242 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
| 243 | + 'html_style' => $this->checkout->admin_request |
|
| 244 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
| 245 | + : '', |
|
| 246 | + 'subsections' => array(), |
|
| 247 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
| 248 | + array( |
|
| 249 | + 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
| 250 | + 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr), |
|
| 251 | + ) |
|
| 252 | + ), |
|
| 253 | + ); |
|
| 254 | + foreach ($question_groups as $question_group) { |
|
| 255 | + if ($question_group instanceof EE_Question_Group) { |
|
| 256 | + $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
| 257 | + $registration, |
|
| 258 | + $question_group |
|
| 259 | + ); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + // add hidden input |
|
| 263 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
| 264 | + $registration |
|
| 265 | + ); |
|
| 266 | + // if we have question groups for additional attendees, then display the copy options |
|
| 267 | + $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
|
| 268 | + if ($registration->is_primary_registrant()) { |
|
| 269 | + // generate hidden input |
|
| 270 | + $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
| 271 | + $registration |
|
| 272 | + ); |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + $attendee_nmbr++; |
|
| 277 | + return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : new EE_Form_Section_HTML(); |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * _additional_attendee_reg_info_input |
|
| 283 | + * |
|
| 284 | + * @access public |
|
| 285 | + * @param EE_Registration $registration |
|
| 286 | + * @param bool $additional_attendee_reg_info |
|
| 287 | + * @return EE_Form_Input_Base |
|
| 288 | + * @throws \EE_Error |
|
| 289 | + */ |
|
| 290 | + private function _additional_attendee_reg_info_input( |
|
| 291 | + EE_Registration $registration, |
|
| 292 | + $additional_attendee_reg_info = true |
|
| 293 | + ) { |
|
| 294 | + // generate hidden input |
|
| 295 | + return new EE_Hidden_Input( |
|
| 296 | + array( |
|
| 297 | + 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
| 298 | + 'default' => $additional_attendee_reg_info, |
|
| 299 | + ) |
|
| 300 | + ); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * @param EE_Registration $registration |
|
| 306 | + * @param EE_Question_Group $question_group |
|
| 307 | + * @return EE_Form_Section_Proper |
|
| 308 | + * @throws EE_Error |
|
| 309 | + * @throws InvalidArgumentException |
|
| 310 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 311 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 312 | + */ |
|
| 313 | + private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
| 314 | + { |
|
| 315 | + // array of params to pass to parent constructor |
|
| 316 | + $form_args = array( |
|
| 317 | + 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
| 318 | + 'html_class' => $this->checkout->admin_request |
|
| 319 | + ? 'form-table ee-reg-form-qstn-grp-dv' |
|
| 320 | + : 'ee-reg-form-qstn-grp-dv', |
|
| 321 | + 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID() . '-lbl', |
|
| 322 | + 'subsections' => array( |
|
| 323 | + 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
| 324 | + ), |
|
| 325 | + 'layout_strategy' => $this->checkout->admin_request |
|
| 326 | + ? new EE_Admin_Two_Column_Layout() |
|
| 327 | + : new EE_Div_Per_Section_Layout(), |
|
| 328 | + ); |
|
| 329 | + // where params |
|
| 330 | + $query_params = array('QST_deleted' => 0); |
|
| 331 | + // don't load admin only questions on the frontend |
|
| 332 | + if (! $this->checkout->admin_request) { |
|
| 333 | + $query_params['QST_admin_only'] = array('!=', true); |
|
| 334 | + } |
|
| 335 | + $questions = $question_group->get_many_related( |
|
| 336 | + 'Question', |
|
| 337 | + apply_filters( |
|
| 338 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
| 339 | + array( |
|
| 340 | + $query_params, |
|
| 341 | + 'order_by' => array( |
|
| 342 | + 'Question_Group_Question.QGQ_order' => 'ASC', |
|
| 343 | + ), |
|
| 344 | + ), |
|
| 345 | + $question_group, |
|
| 346 | + $registration, |
|
| 347 | + $this |
|
| 348 | + ) |
|
| 349 | + ); |
|
| 350 | + // filter for additional content before questions |
|
| 351 | + $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
| 352 | + apply_filters( |
|
| 353 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
| 354 | + '', |
|
| 355 | + $registration, |
|
| 356 | + $question_group, |
|
| 357 | + $this |
|
| 358 | + ) |
|
| 359 | + ); |
|
| 360 | + // loop thru questions |
|
| 361 | + foreach ($questions as $question) { |
|
| 362 | + if ($question instanceof EE_Question) { |
|
| 363 | + $identifier = $question->is_system_question() |
|
| 364 | + ? $question->system_ID() |
|
| 365 | + : $question->ID(); |
|
| 366 | + $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + $form_args['subsections'] = apply_filters( |
|
| 370 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
| 371 | + $form_args['subsections'], |
|
| 372 | + $registration, |
|
| 373 | + $question_group, |
|
| 374 | + $this |
|
| 375 | + ); |
|
| 376 | + // filter for additional content after questions |
|
| 377 | + $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
| 378 | + apply_filters( |
|
| 379 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
| 380 | + '', |
|
| 381 | + $registration, |
|
| 382 | + $question_group, |
|
| 383 | + $this |
|
| 384 | + ) |
|
| 385 | + ); |
|
| 386 | 386 | // d( $form_args ); |
| 387 | - $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
| 388 | - return apply_filters( |
|
| 389 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 390 | - $question_group_reg_form, |
|
| 391 | - $registration, |
|
| 392 | - $question_group, |
|
| 393 | - $this |
|
| 394 | - ); |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * @access public |
|
| 400 | - * @param EE_Question_Group $question_group |
|
| 401 | - * @return EE_Form_Section_HTML |
|
| 402 | - */ |
|
| 403 | - private function _question_group_header(EE_Question_Group $question_group) |
|
| 404 | - { |
|
| 405 | - $html = ''; |
|
| 406 | - // group_name |
|
| 407 | - if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
| 408 | - if ($this->checkout->admin_request) { |
|
| 409 | - $html .= EEH_HTML::br(); |
|
| 410 | - $html .= EEH_HTML::h3( |
|
| 411 | - $question_group->name(), |
|
| 412 | - '', |
|
| 413 | - 'ee-reg-form-qstn-grp-title title', |
|
| 414 | - 'font-size: 1.3em; padding-left:0;' |
|
| 415 | - ); |
|
| 416 | - } else { |
|
| 417 | - $html .= EEH_HTML::h4( |
|
| 418 | - $question_group->name(), |
|
| 419 | - '', |
|
| 420 | - 'ee-reg-form-qstn-grp-title section-title' |
|
| 421 | - ); |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - // group_desc |
|
| 425 | - if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
| 426 | - $html .= EEH_HTML::p( |
|
| 427 | - $question_group->desc(), |
|
| 428 | - '', |
|
| 429 | - $this->checkout->admin_request |
|
| 430 | - ? 'ee-reg-form-qstn-grp-desc-pg' |
|
| 431 | - : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
| 432 | - ); |
|
| 433 | - } |
|
| 434 | - return new EE_Form_Section_HTML($html); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * @access public |
|
| 440 | - * @return EE_Form_Section_Proper |
|
| 441 | - * @throws \EE_Error |
|
| 442 | - */ |
|
| 443 | - private function _copy_attendee_info_form() |
|
| 444 | - { |
|
| 445 | - // array of params to pass to parent constructor |
|
| 446 | - return new EE_Form_Section_Proper( |
|
| 447 | - array( |
|
| 448 | - 'subsections' => $this->_copy_attendee_info_inputs(), |
|
| 449 | - 'layout_strategy' => new EE_Template_Layout( |
|
| 450 | - array( |
|
| 451 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 452 | - . $this->_slug |
|
| 453 | - . DS |
|
| 454 | - . 'copy_attendee_info.template.php', |
|
| 455 | - 'begin_template_file' => null, |
|
| 456 | - 'input_template_file' => null, |
|
| 457 | - 'subsection_template_file' => null, |
|
| 458 | - 'end_template_file' => null, |
|
| 459 | - ) |
|
| 460 | - ), |
|
| 461 | - ) |
|
| 462 | - ); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - |
|
| 466 | - /** |
|
| 467 | - * _auto_copy_attendee_info |
|
| 468 | - * |
|
| 469 | - * @access public |
|
| 470 | - * @return EE_Form_Section_HTML |
|
| 471 | - */ |
|
| 472 | - private function _auto_copy_attendee_info() |
|
| 473 | - { |
|
| 474 | - return new EE_Form_Section_HTML( |
|
| 475 | - EEH_Template::locate_template( |
|
| 476 | - SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
| 477 | - apply_filters( |
|
| 478 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
| 479 | - array() |
|
| 480 | - ), |
|
| 481 | - true, |
|
| 482 | - true |
|
| 483 | - ) |
|
| 484 | - ); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - |
|
| 488 | - /** |
|
| 489 | - * _copy_attendee_info_inputs |
|
| 490 | - * |
|
| 491 | - * @access public |
|
| 492 | - * @return array |
|
| 493 | - * @throws \EE_Error |
|
| 494 | - */ |
|
| 495 | - private function _copy_attendee_info_inputs() |
|
| 496 | - { |
|
| 497 | - $copy_attendee_info_inputs = array(); |
|
| 498 | - $prev_ticket = null; |
|
| 499 | - // grab the saved registrations from the transaction |
|
| 500 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 501 | - foreach ($registrations as $registration) { |
|
| 502 | - // for all attendees other than the primary attendee |
|
| 503 | - if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
| 504 | - // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
| 505 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
| 506 | - $item_name = $registration->ticket()->name(); |
|
| 507 | - $item_name .= $registration->ticket()->description() !== '' |
|
| 508 | - ? ' - ' . $registration->ticket()->description() |
|
| 509 | - : ''; |
|
| 510 | - $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] = |
|
| 511 | - new EE_Form_Section_HTML( |
|
| 512 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
| 513 | - ); |
|
| 514 | - $prev_ticket = $registration->ticket()->ID(); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - $copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] = |
|
| 518 | - new EE_Checkbox_Multi_Input( |
|
| 519 | - array( |
|
| 520 | - $registration->ID() => sprintf( |
|
| 521 | - esc_html__('Attendee #%s', 'event_espresso'), |
|
| 522 | - $registration->count() |
|
| 523 | - ), |
|
| 524 | - ), |
|
| 525 | - array( |
|
| 526 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
| 527 | - 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
| 528 | - 'display_html_label_text' => false, |
|
| 529 | - ) |
|
| 530 | - ); |
|
| 531 | - } |
|
| 532 | - } |
|
| 533 | - return $copy_attendee_info_inputs; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - |
|
| 537 | - /** |
|
| 538 | - * _additional_primary_registrant_inputs |
|
| 539 | - * |
|
| 540 | - * @access public |
|
| 541 | - * @param EE_Registration $registration |
|
| 542 | - * @return EE_Form_Input_Base |
|
| 543 | - * @throws \EE_Error |
|
| 544 | - */ |
|
| 545 | - private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
| 546 | - { |
|
| 547 | - // generate hidden input |
|
| 548 | - return new EE_Hidden_Input( |
|
| 549 | - array( |
|
| 550 | - 'html_id' => 'primary_registrant', |
|
| 551 | - 'default' => $registration->reg_url_link(), |
|
| 552 | - ) |
|
| 553 | - ); |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - |
|
| 557 | - /** |
|
| 558 | - * @access public |
|
| 559 | - * @param EE_Registration $registration |
|
| 560 | - * @param EE_Question $question |
|
| 561 | - * @return EE_Form_Input_Base |
|
| 562 | - * @throws EE_Error |
|
| 563 | - * @throws InvalidArgumentException |
|
| 564 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 565 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 566 | - */ |
|
| 567 | - public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
| 568 | - { |
|
| 569 | - |
|
| 570 | - // if this question was for an attendee detail, then check for that answer |
|
| 571 | - $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
| 572 | - $registration, |
|
| 573 | - $question->system_ID() |
|
| 574 | - ); |
|
| 575 | - $answer = $answer_value === null |
|
| 576 | - ? EEM_Answer::instance()->get_one( |
|
| 577 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
| 578 | - ) |
|
| 579 | - : null; |
|
| 580 | - // if NOT returning to edit an existing registration |
|
| 581 | - // OR if this question is for an attendee property |
|
| 582 | - // OR we still don't have an EE_Answer object |
|
| 583 | - if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
| 584 | - // create an EE_Answer object for storing everything in |
|
| 585 | - $answer = EE_Answer::new_instance(array( |
|
| 586 | - 'QST_ID' => $question->ID(), |
|
| 587 | - 'REG_ID' => $registration->ID(), |
|
| 588 | - )); |
|
| 589 | - } |
|
| 590 | - // verify instance |
|
| 591 | - if ($answer instanceof EE_Answer) { |
|
| 592 | - if (! empty($answer_value)) { |
|
| 593 | - $answer->set('ANS_value', $answer_value); |
|
| 594 | - } |
|
| 595 | - $answer->cache('Question', $question); |
|
| 596 | - //remember system ID had a bug where sometimes it could be null |
|
| 597 | - $answer_cache_id = $question->is_system_question() |
|
| 598 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
| 599 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
| 600 | - $registration->cache('Answer', $answer, $answer_cache_id); |
|
| 601 | - } |
|
| 602 | - return $this->_generate_question_input($registration, $question, $answer); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * @param EE_Registration $registration |
|
| 608 | - * @param EE_Question $question |
|
| 609 | - * @param mixed EE_Answer|NULL $answer |
|
| 610 | - * @return EE_Form_Input_Base |
|
| 611 | - * @throws \EE_Error |
|
| 612 | - */ |
|
| 613 | - private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
| 614 | - { |
|
| 615 | - $identifier = $question->is_system_question() |
|
| 616 | - ? $question->system_ID() |
|
| 617 | - : $question->ID(); |
|
| 618 | - $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
| 619 | - add_filter( |
|
| 620 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
| 621 | - array($this, 'use_cached_countries_for_form_input'), |
|
| 622 | - 10, |
|
| 623 | - 4 |
|
| 624 | - ); |
|
| 625 | - add_filter( |
|
| 626 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
| 627 | - array($this, 'use_cached_states_for_form_input'), |
|
| 628 | - 10, |
|
| 629 | - 4 |
|
| 630 | - ); |
|
| 631 | - $input_constructor_args = array( |
|
| 632 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
| 633 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 634 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
| 635 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 636 | - 'html_label_class' => 'ee-reg-qstn', |
|
| 637 | - ); |
|
| 638 | - $input_constructor_args['html_label_id'] .= '-lbl'; |
|
| 639 | - if ($answer instanceof EE_Answer && $answer->ID()) { |
|
| 640 | - $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
| 641 | - $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
| 642 | - $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
| 643 | - } |
|
| 644 | - $form_input = $question->generate_form_input( |
|
| 645 | - $registration, |
|
| 646 | - $answer, |
|
| 647 | - $input_constructor_args |
|
| 648 | - ); |
|
| 649 | - remove_filter( |
|
| 650 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
| 651 | - array($this, 'use_cached_countries_for_form_input') |
|
| 652 | - ); |
|
| 653 | - remove_filter( |
|
| 654 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
| 655 | - array($this, 'use_cached_states_for_form_input') |
|
| 656 | - ); |
|
| 657 | - return $form_input; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * Gets the list of countries for the form input |
|
| 663 | - * |
|
| 664 | - * @param array|null $countries_list |
|
| 665 | - * @param \EE_Question $question |
|
| 666 | - * @param \EE_Registration $registration |
|
| 667 | - * @param \EE_Answer $answer |
|
| 668 | - * @return array 2d keys are country IDs, values are their names |
|
| 669 | - * @throws EE_Error |
|
| 670 | - * @throws InvalidArgumentException |
|
| 671 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 672 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 673 | - */ |
|
| 674 | - public function use_cached_countries_for_form_input( |
|
| 675 | - $countries_list, |
|
| 676 | - \EE_Question $question = null, |
|
| 677 | - \EE_Registration $registration = null, |
|
| 678 | - \EE_Answer $answer = null |
|
| 679 | - ) { |
|
| 680 | - $country_options = array('' => ''); |
|
| 681 | - // get possibly cached list of countries |
|
| 682 | - $countries = $this->checkout->action === 'process_reg_step' |
|
| 683 | - ? EEM_Country::instance()->get_all_countries() |
|
| 684 | - : EEM_Country::instance()->get_all_active_countries(); |
|
| 685 | - if (! empty($countries)) { |
|
| 686 | - foreach ($countries as $country) { |
|
| 687 | - if ($country instanceof EE_Country) { |
|
| 688 | - $country_options[$country->ID()] = $country->name(); |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - if ($question instanceof EE_Question |
|
| 693 | - && $registration instanceof EE_Registration) { |
|
| 694 | - $answer = EEM_Answer::instance()->get_one( |
|
| 695 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
| 696 | - ); |
|
| 697 | - } else { |
|
| 698 | - $answer = EE_Answer::new_instance(); |
|
| 699 | - } |
|
| 700 | - $country_options = apply_filters( |
|
| 701 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 702 | - $country_options, |
|
| 703 | - $this, |
|
| 704 | - $registration, |
|
| 705 | - $question, |
|
| 706 | - $answer |
|
| 707 | - ); |
|
| 708 | - return $country_options; |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * Gets the list of states for the form input |
|
| 714 | - * |
|
| 715 | - * @param array|null $states_list |
|
| 716 | - * @param \EE_Question $question |
|
| 717 | - * @param \EE_Registration $registration |
|
| 718 | - * @param \EE_Answer $answer |
|
| 719 | - * @return array 2d keys are state IDs, values are their names |
|
| 720 | - * @throws EE_Error |
|
| 721 | - * @throws InvalidArgumentException |
|
| 722 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 723 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 724 | - */ |
|
| 725 | - public function use_cached_states_for_form_input( |
|
| 726 | - $states_list, |
|
| 727 | - \EE_Question $question = null, |
|
| 728 | - \EE_Registration $registration = null, |
|
| 729 | - \EE_Answer $answer = null |
|
| 730 | - ) { |
|
| 731 | - $state_options = array('' => array('' => '')); |
|
| 732 | - $states = $this->checkout->action === 'process_reg_step' |
|
| 733 | - ? EEM_State::instance()->get_all_states() |
|
| 734 | - : EEM_State::instance()->get_all_active_states(); |
|
| 735 | - if (! empty($states)) { |
|
| 736 | - foreach ($states as $state) { |
|
| 737 | - if ($state instanceof EE_State) { |
|
| 738 | - $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - } |
|
| 742 | - $state_options = apply_filters( |
|
| 743 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 744 | - $state_options, |
|
| 745 | - $this, |
|
| 746 | - $registration, |
|
| 747 | - $question, |
|
| 748 | - $answer |
|
| 749 | - ); |
|
| 750 | - return $state_options; |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - |
|
| 754 | - |
|
| 755 | - |
|
| 756 | - |
|
| 757 | - |
|
| 758 | - /********************************************************************************************************/ |
|
| 759 | - /**************************************** PROCESS REG STEP ****************************************/ |
|
| 760 | - /********************************************************************************************************/ |
|
| 761 | - /** |
|
| 762 | - * @return bool |
|
| 763 | - * @throws EE_Error |
|
| 764 | - * @throws InvalidArgumentException |
|
| 765 | - * @throws ReflectionException |
|
| 766 | - * @throws RuntimeException |
|
| 767 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 768 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 769 | - */ |
|
| 770 | - public function process_reg_step() |
|
| 771 | - { |
|
| 772 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 773 | - // grab validated data from form |
|
| 774 | - $valid_data = $this->checkout->current_step->valid_data(); |
|
| 775 | - // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
| 776 | - // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
| 777 | - // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
| 778 | - if (empty($valid_data)) { |
|
| 779 | - EE_Error::add_error( |
|
| 780 | - esc_html__('No valid question responses were received.', 'event_espresso'), |
|
| 781 | - __FILE__, |
|
| 782 | - __FUNCTION__, |
|
| 783 | - __LINE__ |
|
| 784 | - ); |
|
| 785 | - return false; |
|
| 786 | - } |
|
| 787 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
| 788 | - EE_Error::add_error( |
|
| 789 | - esc_html__( |
|
| 790 | - 'A valid transaction could not be initiated for processing your registrations.', |
|
| 791 | - 'event_espresso' |
|
| 792 | - ), |
|
| 793 | - __FILE__, |
|
| 794 | - __FUNCTION__, |
|
| 795 | - __LINE__ |
|
| 796 | - ); |
|
| 797 | - return false; |
|
| 798 | - } |
|
| 799 | - // get cached registrations |
|
| 800 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 801 | - // verify we got the goods |
|
| 802 | - if (empty($registrations)) { |
|
| 803 | - //combine the old translated string with a new one, in order to not break translations |
|
| 804 | - $error_message = esc_html__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' ) |
|
| 805 | - . sprintf( |
|
| 806 | - esc_html__('%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', 'event_espresso'), |
|
| 807 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
| 808 | - '</a>', |
|
| 809 | - '<br />' |
|
| 810 | - ); |
|
| 811 | - EE_Error::add_error( |
|
| 812 | - $error_message, |
|
| 813 | - __FILE__, |
|
| 814 | - __FUNCTION__, |
|
| 815 | - __LINE__ |
|
| 816 | - ); |
|
| 817 | - return false; |
|
| 818 | - } |
|
| 819 | - // extract attendee info from form data and save to model objects |
|
| 820 | - $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
| 821 | - // if first pass thru SPCO, |
|
| 822 | - // then let's check processed registrations against the total number of tickets in the cart |
|
| 823 | - if ($registrations_processed === false) { |
|
| 824 | - // but return immediately if the previous step exited early due to errors |
|
| 825 | - return false; |
|
| 826 | - } elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
| 827 | - // generate a correctly translated string for all possible singular/plural combinations |
|
| 828 | - if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
| 829 | - $error_msg = sprintf( |
|
| 830 | - esc_html__( |
|
| 831 | - 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
| 832 | - 'event_espresso' |
|
| 833 | - ), |
|
| 834 | - $this->checkout->total_ticket_count, |
|
| 835 | - $registrations_processed |
|
| 836 | - ); |
|
| 837 | - } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
| 838 | - $error_msg = sprintf( |
|
| 839 | - esc_html__( |
|
| 840 | - 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
| 841 | - 'event_espresso' |
|
| 842 | - ), |
|
| 843 | - $this->checkout->total_ticket_count, |
|
| 844 | - $registrations_processed |
|
| 845 | - ); |
|
| 846 | - } else { |
|
| 847 | - $error_msg = sprintf( |
|
| 848 | - esc_html__( |
|
| 849 | - 'There was a total of %1$d tickets in the Event Queue, but %2$ds registrations were processed', |
|
| 850 | - 'event_espresso' |
|
| 851 | - ), |
|
| 852 | - $this->checkout->total_ticket_count, |
|
| 853 | - $registrations_processed |
|
| 854 | - ); |
|
| 855 | - } |
|
| 856 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 857 | - return false; |
|
| 858 | - } |
|
| 859 | - // mark this reg step as completed |
|
| 860 | - $this->set_completed(); |
|
| 861 | - $this->_set_success_message( |
|
| 862 | - esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
| 863 | - ); |
|
| 864 | - //do action in case a plugin wants to do something with the data submitted in step 1. |
|
| 865 | - //passes EE_Single_Page_Checkout, and it's posted data |
|
| 866 | - do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
| 867 | - return true; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - |
|
| 871 | - /** |
|
| 872 | - * _process_registrations |
|
| 873 | - * |
|
| 874 | - * @param EE_Registration[] $registrations |
|
| 875 | - * @param array $valid_data |
|
| 876 | - * @return bool|int |
|
| 877 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 878 | - * @throws EE_Error |
|
| 879 | - * @throws InvalidArgumentException |
|
| 880 | - * @throws ReflectionException |
|
| 881 | - * @throws RuntimeException |
|
| 882 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 883 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 884 | - */ |
|
| 885 | - private function _process_registrations($registrations = array(), $valid_data = array()) |
|
| 886 | - { |
|
| 887 | - // load resources and set some defaults |
|
| 888 | - EE_Registry::instance()->load_model('Attendee'); |
|
| 889 | - // holder for primary registrant attendee object |
|
| 890 | - $this->checkout->primary_attendee_obj = null; |
|
| 891 | - // array for tracking reg form data for the primary registrant |
|
| 892 | - $primary_registrant = array( |
|
| 893 | - 'line_item_id' => null, |
|
| 894 | - ); |
|
| 895 | - $copy_primary = false; |
|
| 896 | - // reg form sections that do not contain inputs |
|
| 897 | - $non_input_form_sections = array( |
|
| 898 | - 'primary_registrant', |
|
| 899 | - 'additional_attendee_reg_info', |
|
| 900 | - 'spco_copy_attendee_chk', |
|
| 901 | - ); |
|
| 902 | - // attendee counter |
|
| 903 | - $att_nmbr = 0; |
|
| 904 | - // grab the saved registrations from the transaction |
|
| 905 | - foreach ($registrations as $registration) { |
|
| 906 | - // verify EE_Registration object |
|
| 907 | - if (! $registration instanceof EE_Registration) { |
|
| 908 | - EE_Error::add_error( |
|
| 909 | - esc_html__( |
|
| 910 | - 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
| 911 | - 'event_espresso' |
|
| 912 | - ), |
|
| 913 | - __FILE__, |
|
| 914 | - __FUNCTION__, |
|
| 915 | - __LINE__ |
|
| 916 | - ); |
|
| 917 | - return false; |
|
| 918 | - } |
|
| 919 | - /** @var string $reg_url_link */ |
|
| 920 | - $reg_url_link = $registration->reg_url_link(); |
|
| 921 | - // reg_url_link exists ? |
|
| 922 | - if (! empty($reg_url_link)) { |
|
| 923 | - // should this registration be processed during this visit ? |
|
| 924 | - if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
| 925 | - // if NOT revisiting, then let's save the registration now, |
|
| 926 | - // so that we have a REG_ID to use when generating other objects |
|
| 927 | - if (! $this->checkout->revisit) { |
|
| 928 | - $registration->save(); |
|
| 929 | - } |
|
| 930 | - /** |
|
| 931 | - * This allows plugins to trigger a fail on processing of a |
|
| 932 | - * registration for any conditions they may have for it to pass. |
|
| 933 | - * |
|
| 934 | - * @var bool if true is returned by the plugin then the |
|
| 935 | - * registration processing is halted. |
|
| 936 | - */ |
|
| 937 | - if (apply_filters( |
|
| 938 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
| 939 | - false, |
|
| 940 | - $att_nmbr, |
|
| 941 | - $registration, |
|
| 942 | - $registrations, |
|
| 943 | - $valid_data, |
|
| 944 | - $this |
|
| 945 | - )) { |
|
| 946 | - return false; |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - // Houston, we have a registration! |
|
| 950 | - $att_nmbr++; |
|
| 951 | - $this->_attendee_data[$reg_url_link] = array(); |
|
| 952 | - // grab any existing related answer objects |
|
| 953 | - $this->_registration_answers = $registration->answers(); |
|
| 954 | - // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
| 955 | - if (isset($valid_data[$reg_url_link])) { |
|
| 956 | - // do we need to copy basic info from primary attendee ? |
|
| 957 | - $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
| 958 | - && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0 |
|
| 959 | - ? true |
|
| 960 | - : false; |
|
| 961 | - // filter form input data for this registration |
|
| 962 | - $valid_data[$reg_url_link] = (array)apply_filters( |
|
| 963 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 964 | - $valid_data[$reg_url_link] |
|
| 965 | - ); |
|
| 966 | - if (isset($valid_data['primary_attendee'])) { |
|
| 967 | - $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
| 968 | - ? $valid_data['primary_attendee'] |
|
| 969 | - : false; |
|
| 970 | - unset($valid_data['primary_attendee']); |
|
| 971 | - } |
|
| 972 | - // now loop through our array of valid post data && process attendee reg forms |
|
| 973 | - foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
| 974 | - if (! in_array($form_section, $non_input_form_sections)) { |
|
| 975 | - foreach ($form_inputs as $form_input => $input_value) { |
|
| 976 | - // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
| 977 | - // check for critical inputs |
|
| 978 | - if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
| 979 | - $form_input, |
|
| 980 | - $input_value |
|
| 981 | - ) |
|
| 982 | - ) { |
|
| 983 | - return false; |
|
| 984 | - } |
|
| 985 | - // store a bit of data about the primary attendee |
|
| 986 | - if ($att_nmbr === 1 |
|
| 987 | - && ! empty($input_value) |
|
| 988 | - && $reg_url_link === $primary_registrant['line_item_id'] |
|
| 989 | - ) { |
|
| 990 | - $primary_registrant[$form_input] = $input_value; |
|
| 991 | - } elseif ($copy_primary |
|
| 992 | - && $input_value === null |
|
| 993 | - && isset($primary_registrant[$form_input]) |
|
| 994 | - ) { |
|
| 995 | - $input_value = $primary_registrant[$form_input]; |
|
| 996 | - } |
|
| 997 | - // now attempt to save the input data |
|
| 998 | - if (! $this->_save_registration_form_input( |
|
| 999 | - $registration, |
|
| 1000 | - $form_input, |
|
| 1001 | - $input_value |
|
| 1002 | - ) |
|
| 1003 | - ) { |
|
| 1004 | - EE_Error::add_error( |
|
| 1005 | - sprintf( |
|
| 1006 | - esc_html__( |
|
| 1007 | - 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
| 1008 | - 'event_espresso' |
|
| 1009 | - ), |
|
| 1010 | - $form_input, |
|
| 1011 | - $input_value |
|
| 1012 | - ), |
|
| 1013 | - __FILE__, |
|
| 1014 | - __FUNCTION__, |
|
| 1015 | - __LINE__ |
|
| 1016 | - ); |
|
| 1017 | - return false; |
|
| 1018 | - } |
|
| 1019 | - } |
|
| 1020 | - } |
|
| 1021 | - } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
| 1022 | - } |
|
| 1023 | - //EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
| 1024 | - // this registration does not require additional attendee information ? |
|
| 1025 | - if ($copy_primary |
|
| 1026 | - && $att_nmbr > 1 |
|
| 1027 | - && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
| 1028 | - ) { |
|
| 1029 | - // just copy the primary registrant |
|
| 1030 | - $attendee = $this->checkout->primary_attendee_obj; |
|
| 1031 | - } else { |
|
| 1032 | - // ensure critical details are set for additional attendees |
|
| 1033 | - $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
| 1034 | - ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
| 1035 | - $this->_attendee_data[$reg_url_link] |
|
| 1036 | - ) |
|
| 1037 | - : $this->_attendee_data[$reg_url_link]; |
|
| 1038 | - // execute create attendee command (which may return an existing attendee) |
|
| 1039 | - $attendee = EE_Registry::instance()->BUS->execute( |
|
| 1040 | - new CreateAttendeeCommand( |
|
| 1041 | - $this->_attendee_data[$reg_url_link], |
|
| 1042 | - $registration |
|
| 1043 | - ) |
|
| 1044 | - ); |
|
| 1045 | - // who's #1 ? |
|
| 1046 | - if ($att_nmbr === 1) { |
|
| 1047 | - $this->checkout->primary_attendee_obj = $attendee; |
|
| 1048 | - } |
|
| 1049 | - } |
|
| 1050 | - // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
| 1051 | - // add relation to registration, set attendee ID, and cache attendee |
|
| 1052 | - $this->_associate_attendee_with_registration($registration, $attendee); |
|
| 1053 | - // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
| 1054 | - if (! $registration->attendee() instanceof EE_Attendee) { |
|
| 1055 | - EE_Error::add_error( |
|
| 1056 | - sprintf( |
|
| 1057 | - esc_html__( |
|
| 1058 | - 'Registration %s has an invalid or missing Attendee object.', |
|
| 1059 | - 'event_espresso' |
|
| 1060 | - ), |
|
| 1061 | - $reg_url_link |
|
| 1062 | - ), |
|
| 1063 | - __FILE__, |
|
| 1064 | - __FUNCTION__, |
|
| 1065 | - __LINE__ |
|
| 1066 | - ); |
|
| 1067 | - return false; |
|
| 1068 | - } |
|
| 1069 | - /** @type EE_Registration_Processor $registration_processor */ |
|
| 1070 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 1071 | - // at this point, we should have enough details about the registrant to consider the registration |
|
| 1072 | - // NOT incomplete |
|
| 1073 | - $registration_processor->toggle_incomplete_registration_status_to_default( |
|
| 1074 | - $registration, |
|
| 1075 | - false, |
|
| 1076 | - new Context( |
|
| 1077 | - 'spco_reg_step_attendee_information_process_registrations', |
|
| 1078 | - esc_html__( |
|
| 1079 | - 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
| 1080 | - 'event_espresso' |
|
| 1081 | - ) |
|
| 1082 | - ) |
|
| 1083 | - ); |
|
| 1084 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
| 1085 | - // abandoned |
|
| 1086 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 1087 | - // if we've gotten this far, then let's save what we have |
|
| 1088 | - $registration->save(); |
|
| 1089 | - // add relation between TXN and registration |
|
| 1090 | - $this->_associate_registration_with_transaction($registration); |
|
| 1091 | - } |
|
| 1092 | - } else { |
|
| 1093 | - EE_Error::add_error( |
|
| 1094 | - esc_html__( |
|
| 1095 | - 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
| 1096 | - 'event_espresso' |
|
| 1097 | - ), |
|
| 1098 | - __FILE__, |
|
| 1099 | - __FUNCTION__, |
|
| 1100 | - __LINE__ |
|
| 1101 | - ); |
|
| 1102 | - // remove malformed data |
|
| 1103 | - unset($valid_data[$reg_url_link]); |
|
| 1104 | - return false; |
|
| 1105 | - } |
|
| 1106 | - |
|
| 1107 | - } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
| 1108 | - return $att_nmbr; |
|
| 1109 | - } |
|
| 1110 | - |
|
| 1111 | - |
|
| 1112 | - /** |
|
| 1113 | - * _save_registration_form_input |
|
| 1114 | - * |
|
| 1115 | - * @param EE_Registration $registration |
|
| 1116 | - * @param string $form_input |
|
| 1117 | - * @param string $input_value |
|
| 1118 | - * @return bool |
|
| 1119 | - * @throws EE_Error |
|
| 1120 | - * @throws InvalidArgumentException |
|
| 1121 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1122 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1123 | - */ |
|
| 1124 | - private function _save_registration_form_input( |
|
| 1125 | - EE_Registration $registration, |
|
| 1126 | - $form_input = '', |
|
| 1127 | - $input_value = '' |
|
| 1128 | - ) { |
|
| 1129 | - // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
| 1130 | - // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
| 1131 | - // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
| 1132 | - // allow for plugins to hook in and do their own processing of the form input. |
|
| 1133 | - // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
| 1134 | - if (apply_filters( |
|
| 1135 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
| 1136 | - false, |
|
| 1137 | - $registration, |
|
| 1138 | - $form_input, |
|
| 1139 | - $input_value, |
|
| 1140 | - $this |
|
| 1141 | - )) { |
|
| 1142 | - return true; |
|
| 1143 | - } |
|
| 1144 | - /* |
|
| 387 | + $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
| 388 | + return apply_filters( |
|
| 389 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 390 | + $question_group_reg_form, |
|
| 391 | + $registration, |
|
| 392 | + $question_group, |
|
| 393 | + $this |
|
| 394 | + ); |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * @access public |
|
| 400 | + * @param EE_Question_Group $question_group |
|
| 401 | + * @return EE_Form_Section_HTML |
|
| 402 | + */ |
|
| 403 | + private function _question_group_header(EE_Question_Group $question_group) |
|
| 404 | + { |
|
| 405 | + $html = ''; |
|
| 406 | + // group_name |
|
| 407 | + if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
| 408 | + if ($this->checkout->admin_request) { |
|
| 409 | + $html .= EEH_HTML::br(); |
|
| 410 | + $html .= EEH_HTML::h3( |
|
| 411 | + $question_group->name(), |
|
| 412 | + '', |
|
| 413 | + 'ee-reg-form-qstn-grp-title title', |
|
| 414 | + 'font-size: 1.3em; padding-left:0;' |
|
| 415 | + ); |
|
| 416 | + } else { |
|
| 417 | + $html .= EEH_HTML::h4( |
|
| 418 | + $question_group->name(), |
|
| 419 | + '', |
|
| 420 | + 'ee-reg-form-qstn-grp-title section-title' |
|
| 421 | + ); |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + // group_desc |
|
| 425 | + if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
| 426 | + $html .= EEH_HTML::p( |
|
| 427 | + $question_group->desc(), |
|
| 428 | + '', |
|
| 429 | + $this->checkout->admin_request |
|
| 430 | + ? 'ee-reg-form-qstn-grp-desc-pg' |
|
| 431 | + : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
| 432 | + ); |
|
| 433 | + } |
|
| 434 | + return new EE_Form_Section_HTML($html); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * @access public |
|
| 440 | + * @return EE_Form_Section_Proper |
|
| 441 | + * @throws \EE_Error |
|
| 442 | + */ |
|
| 443 | + private function _copy_attendee_info_form() |
|
| 444 | + { |
|
| 445 | + // array of params to pass to parent constructor |
|
| 446 | + return new EE_Form_Section_Proper( |
|
| 447 | + array( |
|
| 448 | + 'subsections' => $this->_copy_attendee_info_inputs(), |
|
| 449 | + 'layout_strategy' => new EE_Template_Layout( |
|
| 450 | + array( |
|
| 451 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
| 452 | + . $this->_slug |
|
| 453 | + . DS |
|
| 454 | + . 'copy_attendee_info.template.php', |
|
| 455 | + 'begin_template_file' => null, |
|
| 456 | + 'input_template_file' => null, |
|
| 457 | + 'subsection_template_file' => null, |
|
| 458 | + 'end_template_file' => null, |
|
| 459 | + ) |
|
| 460 | + ), |
|
| 461 | + ) |
|
| 462 | + ); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + |
|
| 466 | + /** |
|
| 467 | + * _auto_copy_attendee_info |
|
| 468 | + * |
|
| 469 | + * @access public |
|
| 470 | + * @return EE_Form_Section_HTML |
|
| 471 | + */ |
|
| 472 | + private function _auto_copy_attendee_info() |
|
| 473 | + { |
|
| 474 | + return new EE_Form_Section_HTML( |
|
| 475 | + EEH_Template::locate_template( |
|
| 476 | + SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
| 477 | + apply_filters( |
|
| 478 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
| 479 | + array() |
|
| 480 | + ), |
|
| 481 | + true, |
|
| 482 | + true |
|
| 483 | + ) |
|
| 484 | + ); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + |
|
| 488 | + /** |
|
| 489 | + * _copy_attendee_info_inputs |
|
| 490 | + * |
|
| 491 | + * @access public |
|
| 492 | + * @return array |
|
| 493 | + * @throws \EE_Error |
|
| 494 | + */ |
|
| 495 | + private function _copy_attendee_info_inputs() |
|
| 496 | + { |
|
| 497 | + $copy_attendee_info_inputs = array(); |
|
| 498 | + $prev_ticket = null; |
|
| 499 | + // grab the saved registrations from the transaction |
|
| 500 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 501 | + foreach ($registrations as $registration) { |
|
| 502 | + // for all attendees other than the primary attendee |
|
| 503 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
| 504 | + // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
| 505 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
| 506 | + $item_name = $registration->ticket()->name(); |
|
| 507 | + $item_name .= $registration->ticket()->description() !== '' |
|
| 508 | + ? ' - ' . $registration->ticket()->description() |
|
| 509 | + : ''; |
|
| 510 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] = |
|
| 511 | + new EE_Form_Section_HTML( |
|
| 512 | + '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
| 513 | + ); |
|
| 514 | + $prev_ticket = $registration->ticket()->ID(); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] = |
|
| 518 | + new EE_Checkbox_Multi_Input( |
|
| 519 | + array( |
|
| 520 | + $registration->ID() => sprintf( |
|
| 521 | + esc_html__('Attendee #%s', 'event_espresso'), |
|
| 522 | + $registration->count() |
|
| 523 | + ), |
|
| 524 | + ), |
|
| 525 | + array( |
|
| 526 | + 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
| 527 | + 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
| 528 | + 'display_html_label_text' => false, |
|
| 529 | + ) |
|
| 530 | + ); |
|
| 531 | + } |
|
| 532 | + } |
|
| 533 | + return $copy_attendee_info_inputs; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + |
|
| 537 | + /** |
|
| 538 | + * _additional_primary_registrant_inputs |
|
| 539 | + * |
|
| 540 | + * @access public |
|
| 541 | + * @param EE_Registration $registration |
|
| 542 | + * @return EE_Form_Input_Base |
|
| 543 | + * @throws \EE_Error |
|
| 544 | + */ |
|
| 545 | + private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
| 546 | + { |
|
| 547 | + // generate hidden input |
|
| 548 | + return new EE_Hidden_Input( |
|
| 549 | + array( |
|
| 550 | + 'html_id' => 'primary_registrant', |
|
| 551 | + 'default' => $registration->reg_url_link(), |
|
| 552 | + ) |
|
| 553 | + ); |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + |
|
| 557 | + /** |
|
| 558 | + * @access public |
|
| 559 | + * @param EE_Registration $registration |
|
| 560 | + * @param EE_Question $question |
|
| 561 | + * @return EE_Form_Input_Base |
|
| 562 | + * @throws EE_Error |
|
| 563 | + * @throws InvalidArgumentException |
|
| 564 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 565 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 566 | + */ |
|
| 567 | + public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
| 568 | + { |
|
| 569 | + |
|
| 570 | + // if this question was for an attendee detail, then check for that answer |
|
| 571 | + $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
| 572 | + $registration, |
|
| 573 | + $question->system_ID() |
|
| 574 | + ); |
|
| 575 | + $answer = $answer_value === null |
|
| 576 | + ? EEM_Answer::instance()->get_one( |
|
| 577 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
| 578 | + ) |
|
| 579 | + : null; |
|
| 580 | + // if NOT returning to edit an existing registration |
|
| 581 | + // OR if this question is for an attendee property |
|
| 582 | + // OR we still don't have an EE_Answer object |
|
| 583 | + if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
| 584 | + // create an EE_Answer object for storing everything in |
|
| 585 | + $answer = EE_Answer::new_instance(array( |
|
| 586 | + 'QST_ID' => $question->ID(), |
|
| 587 | + 'REG_ID' => $registration->ID(), |
|
| 588 | + )); |
|
| 589 | + } |
|
| 590 | + // verify instance |
|
| 591 | + if ($answer instanceof EE_Answer) { |
|
| 592 | + if (! empty($answer_value)) { |
|
| 593 | + $answer->set('ANS_value', $answer_value); |
|
| 594 | + } |
|
| 595 | + $answer->cache('Question', $question); |
|
| 596 | + //remember system ID had a bug where sometimes it could be null |
|
| 597 | + $answer_cache_id = $question->is_system_question() |
|
| 598 | + ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
| 599 | + : $question->ID() . '-' . $registration->reg_url_link(); |
|
| 600 | + $registration->cache('Answer', $answer, $answer_cache_id); |
|
| 601 | + } |
|
| 602 | + return $this->_generate_question_input($registration, $question, $answer); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * @param EE_Registration $registration |
|
| 608 | + * @param EE_Question $question |
|
| 609 | + * @param mixed EE_Answer|NULL $answer |
|
| 610 | + * @return EE_Form_Input_Base |
|
| 611 | + * @throws \EE_Error |
|
| 612 | + */ |
|
| 613 | + private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
| 614 | + { |
|
| 615 | + $identifier = $question->is_system_question() |
|
| 616 | + ? $question->system_ID() |
|
| 617 | + : $question->ID(); |
|
| 618 | + $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
| 619 | + add_filter( |
|
| 620 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
| 621 | + array($this, 'use_cached_countries_for_form_input'), |
|
| 622 | + 10, |
|
| 623 | + 4 |
|
| 624 | + ); |
|
| 625 | + add_filter( |
|
| 626 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
| 627 | + array($this, 'use_cached_states_for_form_input'), |
|
| 628 | + 10, |
|
| 629 | + 4 |
|
| 630 | + ); |
|
| 631 | + $input_constructor_args = array( |
|
| 632 | + 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
| 633 | + 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 634 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
| 635 | + 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 636 | + 'html_label_class' => 'ee-reg-qstn', |
|
| 637 | + ); |
|
| 638 | + $input_constructor_args['html_label_id'] .= '-lbl'; |
|
| 639 | + if ($answer instanceof EE_Answer && $answer->ID()) { |
|
| 640 | + $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
| 641 | + $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
| 642 | + $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
| 643 | + } |
|
| 644 | + $form_input = $question->generate_form_input( |
|
| 645 | + $registration, |
|
| 646 | + $answer, |
|
| 647 | + $input_constructor_args |
|
| 648 | + ); |
|
| 649 | + remove_filter( |
|
| 650 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
| 651 | + array($this, 'use_cached_countries_for_form_input') |
|
| 652 | + ); |
|
| 653 | + remove_filter( |
|
| 654 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
| 655 | + array($this, 'use_cached_states_for_form_input') |
|
| 656 | + ); |
|
| 657 | + return $form_input; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * Gets the list of countries for the form input |
|
| 663 | + * |
|
| 664 | + * @param array|null $countries_list |
|
| 665 | + * @param \EE_Question $question |
|
| 666 | + * @param \EE_Registration $registration |
|
| 667 | + * @param \EE_Answer $answer |
|
| 668 | + * @return array 2d keys are country IDs, values are their names |
|
| 669 | + * @throws EE_Error |
|
| 670 | + * @throws InvalidArgumentException |
|
| 671 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 672 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 673 | + */ |
|
| 674 | + public function use_cached_countries_for_form_input( |
|
| 675 | + $countries_list, |
|
| 676 | + \EE_Question $question = null, |
|
| 677 | + \EE_Registration $registration = null, |
|
| 678 | + \EE_Answer $answer = null |
|
| 679 | + ) { |
|
| 680 | + $country_options = array('' => ''); |
|
| 681 | + // get possibly cached list of countries |
|
| 682 | + $countries = $this->checkout->action === 'process_reg_step' |
|
| 683 | + ? EEM_Country::instance()->get_all_countries() |
|
| 684 | + : EEM_Country::instance()->get_all_active_countries(); |
|
| 685 | + if (! empty($countries)) { |
|
| 686 | + foreach ($countries as $country) { |
|
| 687 | + if ($country instanceof EE_Country) { |
|
| 688 | + $country_options[$country->ID()] = $country->name(); |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + if ($question instanceof EE_Question |
|
| 693 | + && $registration instanceof EE_Registration) { |
|
| 694 | + $answer = EEM_Answer::instance()->get_one( |
|
| 695 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
| 696 | + ); |
|
| 697 | + } else { |
|
| 698 | + $answer = EE_Answer::new_instance(); |
|
| 699 | + } |
|
| 700 | + $country_options = apply_filters( |
|
| 701 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 702 | + $country_options, |
|
| 703 | + $this, |
|
| 704 | + $registration, |
|
| 705 | + $question, |
|
| 706 | + $answer |
|
| 707 | + ); |
|
| 708 | + return $country_options; |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * Gets the list of states for the form input |
|
| 714 | + * |
|
| 715 | + * @param array|null $states_list |
|
| 716 | + * @param \EE_Question $question |
|
| 717 | + * @param \EE_Registration $registration |
|
| 718 | + * @param \EE_Answer $answer |
|
| 719 | + * @return array 2d keys are state IDs, values are their names |
|
| 720 | + * @throws EE_Error |
|
| 721 | + * @throws InvalidArgumentException |
|
| 722 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 723 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 724 | + */ |
|
| 725 | + public function use_cached_states_for_form_input( |
|
| 726 | + $states_list, |
|
| 727 | + \EE_Question $question = null, |
|
| 728 | + \EE_Registration $registration = null, |
|
| 729 | + \EE_Answer $answer = null |
|
| 730 | + ) { |
|
| 731 | + $state_options = array('' => array('' => '')); |
|
| 732 | + $states = $this->checkout->action === 'process_reg_step' |
|
| 733 | + ? EEM_State::instance()->get_all_states() |
|
| 734 | + : EEM_State::instance()->get_all_active_states(); |
|
| 735 | + if (! empty($states)) { |
|
| 736 | + foreach ($states as $state) { |
|
| 737 | + if ($state instanceof EE_State) { |
|
| 738 | + $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + } |
|
| 742 | + $state_options = apply_filters( |
|
| 743 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 744 | + $state_options, |
|
| 745 | + $this, |
|
| 746 | + $registration, |
|
| 747 | + $question, |
|
| 748 | + $answer |
|
| 749 | + ); |
|
| 750 | + return $state_options; |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + |
|
| 754 | + |
|
| 755 | + |
|
| 756 | + |
|
| 757 | + |
|
| 758 | + /********************************************************************************************************/ |
|
| 759 | + /**************************************** PROCESS REG STEP ****************************************/ |
|
| 760 | + /********************************************************************************************************/ |
|
| 761 | + /** |
|
| 762 | + * @return bool |
|
| 763 | + * @throws EE_Error |
|
| 764 | + * @throws InvalidArgumentException |
|
| 765 | + * @throws ReflectionException |
|
| 766 | + * @throws RuntimeException |
|
| 767 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 768 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 769 | + */ |
|
| 770 | + public function process_reg_step() |
|
| 771 | + { |
|
| 772 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 773 | + // grab validated data from form |
|
| 774 | + $valid_data = $this->checkout->current_step->valid_data(); |
|
| 775 | + // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
| 776 | + // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
| 777 | + // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
| 778 | + if (empty($valid_data)) { |
|
| 779 | + EE_Error::add_error( |
|
| 780 | + esc_html__('No valid question responses were received.', 'event_espresso'), |
|
| 781 | + __FILE__, |
|
| 782 | + __FUNCTION__, |
|
| 783 | + __LINE__ |
|
| 784 | + ); |
|
| 785 | + return false; |
|
| 786 | + } |
|
| 787 | + if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
| 788 | + EE_Error::add_error( |
|
| 789 | + esc_html__( |
|
| 790 | + 'A valid transaction could not be initiated for processing your registrations.', |
|
| 791 | + 'event_espresso' |
|
| 792 | + ), |
|
| 793 | + __FILE__, |
|
| 794 | + __FUNCTION__, |
|
| 795 | + __LINE__ |
|
| 796 | + ); |
|
| 797 | + return false; |
|
| 798 | + } |
|
| 799 | + // get cached registrations |
|
| 800 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
| 801 | + // verify we got the goods |
|
| 802 | + if (empty($registrations)) { |
|
| 803 | + //combine the old translated string with a new one, in order to not break translations |
|
| 804 | + $error_message = esc_html__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' ) |
|
| 805 | + . sprintf( |
|
| 806 | + esc_html__('%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', 'event_espresso'), |
|
| 807 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
| 808 | + '</a>', |
|
| 809 | + '<br />' |
|
| 810 | + ); |
|
| 811 | + EE_Error::add_error( |
|
| 812 | + $error_message, |
|
| 813 | + __FILE__, |
|
| 814 | + __FUNCTION__, |
|
| 815 | + __LINE__ |
|
| 816 | + ); |
|
| 817 | + return false; |
|
| 818 | + } |
|
| 819 | + // extract attendee info from form data and save to model objects |
|
| 820 | + $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
| 821 | + // if first pass thru SPCO, |
|
| 822 | + // then let's check processed registrations against the total number of tickets in the cart |
|
| 823 | + if ($registrations_processed === false) { |
|
| 824 | + // but return immediately if the previous step exited early due to errors |
|
| 825 | + return false; |
|
| 826 | + } elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
| 827 | + // generate a correctly translated string for all possible singular/plural combinations |
|
| 828 | + if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
| 829 | + $error_msg = sprintf( |
|
| 830 | + esc_html__( |
|
| 831 | + 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
| 832 | + 'event_espresso' |
|
| 833 | + ), |
|
| 834 | + $this->checkout->total_ticket_count, |
|
| 835 | + $registrations_processed |
|
| 836 | + ); |
|
| 837 | + } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
| 838 | + $error_msg = sprintf( |
|
| 839 | + esc_html__( |
|
| 840 | + 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
| 841 | + 'event_espresso' |
|
| 842 | + ), |
|
| 843 | + $this->checkout->total_ticket_count, |
|
| 844 | + $registrations_processed |
|
| 845 | + ); |
|
| 846 | + } else { |
|
| 847 | + $error_msg = sprintf( |
|
| 848 | + esc_html__( |
|
| 849 | + 'There was a total of %1$d tickets in the Event Queue, but %2$ds registrations were processed', |
|
| 850 | + 'event_espresso' |
|
| 851 | + ), |
|
| 852 | + $this->checkout->total_ticket_count, |
|
| 853 | + $registrations_processed |
|
| 854 | + ); |
|
| 855 | + } |
|
| 856 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 857 | + return false; |
|
| 858 | + } |
|
| 859 | + // mark this reg step as completed |
|
| 860 | + $this->set_completed(); |
|
| 861 | + $this->_set_success_message( |
|
| 862 | + esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
| 863 | + ); |
|
| 864 | + //do action in case a plugin wants to do something with the data submitted in step 1. |
|
| 865 | + //passes EE_Single_Page_Checkout, and it's posted data |
|
| 866 | + do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
| 867 | + return true; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + |
|
| 871 | + /** |
|
| 872 | + * _process_registrations |
|
| 873 | + * |
|
| 874 | + * @param EE_Registration[] $registrations |
|
| 875 | + * @param array $valid_data |
|
| 876 | + * @return bool|int |
|
| 877 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 878 | + * @throws EE_Error |
|
| 879 | + * @throws InvalidArgumentException |
|
| 880 | + * @throws ReflectionException |
|
| 881 | + * @throws RuntimeException |
|
| 882 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 883 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 884 | + */ |
|
| 885 | + private function _process_registrations($registrations = array(), $valid_data = array()) |
|
| 886 | + { |
|
| 887 | + // load resources and set some defaults |
|
| 888 | + EE_Registry::instance()->load_model('Attendee'); |
|
| 889 | + // holder for primary registrant attendee object |
|
| 890 | + $this->checkout->primary_attendee_obj = null; |
|
| 891 | + // array for tracking reg form data for the primary registrant |
|
| 892 | + $primary_registrant = array( |
|
| 893 | + 'line_item_id' => null, |
|
| 894 | + ); |
|
| 895 | + $copy_primary = false; |
|
| 896 | + // reg form sections that do not contain inputs |
|
| 897 | + $non_input_form_sections = array( |
|
| 898 | + 'primary_registrant', |
|
| 899 | + 'additional_attendee_reg_info', |
|
| 900 | + 'spco_copy_attendee_chk', |
|
| 901 | + ); |
|
| 902 | + // attendee counter |
|
| 903 | + $att_nmbr = 0; |
|
| 904 | + // grab the saved registrations from the transaction |
|
| 905 | + foreach ($registrations as $registration) { |
|
| 906 | + // verify EE_Registration object |
|
| 907 | + if (! $registration instanceof EE_Registration) { |
|
| 908 | + EE_Error::add_error( |
|
| 909 | + esc_html__( |
|
| 910 | + 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
| 911 | + 'event_espresso' |
|
| 912 | + ), |
|
| 913 | + __FILE__, |
|
| 914 | + __FUNCTION__, |
|
| 915 | + __LINE__ |
|
| 916 | + ); |
|
| 917 | + return false; |
|
| 918 | + } |
|
| 919 | + /** @var string $reg_url_link */ |
|
| 920 | + $reg_url_link = $registration->reg_url_link(); |
|
| 921 | + // reg_url_link exists ? |
|
| 922 | + if (! empty($reg_url_link)) { |
|
| 923 | + // should this registration be processed during this visit ? |
|
| 924 | + if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
| 925 | + // if NOT revisiting, then let's save the registration now, |
|
| 926 | + // so that we have a REG_ID to use when generating other objects |
|
| 927 | + if (! $this->checkout->revisit) { |
|
| 928 | + $registration->save(); |
|
| 929 | + } |
|
| 930 | + /** |
|
| 931 | + * This allows plugins to trigger a fail on processing of a |
|
| 932 | + * registration for any conditions they may have for it to pass. |
|
| 933 | + * |
|
| 934 | + * @var bool if true is returned by the plugin then the |
|
| 935 | + * registration processing is halted. |
|
| 936 | + */ |
|
| 937 | + if (apply_filters( |
|
| 938 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
| 939 | + false, |
|
| 940 | + $att_nmbr, |
|
| 941 | + $registration, |
|
| 942 | + $registrations, |
|
| 943 | + $valid_data, |
|
| 944 | + $this |
|
| 945 | + )) { |
|
| 946 | + return false; |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + // Houston, we have a registration! |
|
| 950 | + $att_nmbr++; |
|
| 951 | + $this->_attendee_data[$reg_url_link] = array(); |
|
| 952 | + // grab any existing related answer objects |
|
| 953 | + $this->_registration_answers = $registration->answers(); |
|
| 954 | + // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
| 955 | + if (isset($valid_data[$reg_url_link])) { |
|
| 956 | + // do we need to copy basic info from primary attendee ? |
|
| 957 | + $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
| 958 | + && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0 |
|
| 959 | + ? true |
|
| 960 | + : false; |
|
| 961 | + // filter form input data for this registration |
|
| 962 | + $valid_data[$reg_url_link] = (array)apply_filters( |
|
| 963 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 964 | + $valid_data[$reg_url_link] |
|
| 965 | + ); |
|
| 966 | + if (isset($valid_data['primary_attendee'])) { |
|
| 967 | + $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
| 968 | + ? $valid_data['primary_attendee'] |
|
| 969 | + : false; |
|
| 970 | + unset($valid_data['primary_attendee']); |
|
| 971 | + } |
|
| 972 | + // now loop through our array of valid post data && process attendee reg forms |
|
| 973 | + foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
| 974 | + if (! in_array($form_section, $non_input_form_sections)) { |
|
| 975 | + foreach ($form_inputs as $form_input => $input_value) { |
|
| 976 | + // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
| 977 | + // check for critical inputs |
|
| 978 | + if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
| 979 | + $form_input, |
|
| 980 | + $input_value |
|
| 981 | + ) |
|
| 982 | + ) { |
|
| 983 | + return false; |
|
| 984 | + } |
|
| 985 | + // store a bit of data about the primary attendee |
|
| 986 | + if ($att_nmbr === 1 |
|
| 987 | + && ! empty($input_value) |
|
| 988 | + && $reg_url_link === $primary_registrant['line_item_id'] |
|
| 989 | + ) { |
|
| 990 | + $primary_registrant[$form_input] = $input_value; |
|
| 991 | + } elseif ($copy_primary |
|
| 992 | + && $input_value === null |
|
| 993 | + && isset($primary_registrant[$form_input]) |
|
| 994 | + ) { |
|
| 995 | + $input_value = $primary_registrant[$form_input]; |
|
| 996 | + } |
|
| 997 | + // now attempt to save the input data |
|
| 998 | + if (! $this->_save_registration_form_input( |
|
| 999 | + $registration, |
|
| 1000 | + $form_input, |
|
| 1001 | + $input_value |
|
| 1002 | + ) |
|
| 1003 | + ) { |
|
| 1004 | + EE_Error::add_error( |
|
| 1005 | + sprintf( |
|
| 1006 | + esc_html__( |
|
| 1007 | + 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
| 1008 | + 'event_espresso' |
|
| 1009 | + ), |
|
| 1010 | + $form_input, |
|
| 1011 | + $input_value |
|
| 1012 | + ), |
|
| 1013 | + __FILE__, |
|
| 1014 | + __FUNCTION__, |
|
| 1015 | + __LINE__ |
|
| 1016 | + ); |
|
| 1017 | + return false; |
|
| 1018 | + } |
|
| 1019 | + } |
|
| 1020 | + } |
|
| 1021 | + } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
| 1022 | + } |
|
| 1023 | + //EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
| 1024 | + // this registration does not require additional attendee information ? |
|
| 1025 | + if ($copy_primary |
|
| 1026 | + && $att_nmbr > 1 |
|
| 1027 | + && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
| 1028 | + ) { |
|
| 1029 | + // just copy the primary registrant |
|
| 1030 | + $attendee = $this->checkout->primary_attendee_obj; |
|
| 1031 | + } else { |
|
| 1032 | + // ensure critical details are set for additional attendees |
|
| 1033 | + $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
| 1034 | + ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
| 1035 | + $this->_attendee_data[$reg_url_link] |
|
| 1036 | + ) |
|
| 1037 | + : $this->_attendee_data[$reg_url_link]; |
|
| 1038 | + // execute create attendee command (which may return an existing attendee) |
|
| 1039 | + $attendee = EE_Registry::instance()->BUS->execute( |
|
| 1040 | + new CreateAttendeeCommand( |
|
| 1041 | + $this->_attendee_data[$reg_url_link], |
|
| 1042 | + $registration |
|
| 1043 | + ) |
|
| 1044 | + ); |
|
| 1045 | + // who's #1 ? |
|
| 1046 | + if ($att_nmbr === 1) { |
|
| 1047 | + $this->checkout->primary_attendee_obj = $attendee; |
|
| 1048 | + } |
|
| 1049 | + } |
|
| 1050 | + // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
| 1051 | + // add relation to registration, set attendee ID, and cache attendee |
|
| 1052 | + $this->_associate_attendee_with_registration($registration, $attendee); |
|
| 1053 | + // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
| 1054 | + if (! $registration->attendee() instanceof EE_Attendee) { |
|
| 1055 | + EE_Error::add_error( |
|
| 1056 | + sprintf( |
|
| 1057 | + esc_html__( |
|
| 1058 | + 'Registration %s has an invalid or missing Attendee object.', |
|
| 1059 | + 'event_espresso' |
|
| 1060 | + ), |
|
| 1061 | + $reg_url_link |
|
| 1062 | + ), |
|
| 1063 | + __FILE__, |
|
| 1064 | + __FUNCTION__, |
|
| 1065 | + __LINE__ |
|
| 1066 | + ); |
|
| 1067 | + return false; |
|
| 1068 | + } |
|
| 1069 | + /** @type EE_Registration_Processor $registration_processor */ |
|
| 1070 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
| 1071 | + // at this point, we should have enough details about the registrant to consider the registration |
|
| 1072 | + // NOT incomplete |
|
| 1073 | + $registration_processor->toggle_incomplete_registration_status_to_default( |
|
| 1074 | + $registration, |
|
| 1075 | + false, |
|
| 1076 | + new Context( |
|
| 1077 | + 'spco_reg_step_attendee_information_process_registrations', |
|
| 1078 | + esc_html__( |
|
| 1079 | + 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
| 1080 | + 'event_espresso' |
|
| 1081 | + ) |
|
| 1082 | + ) |
|
| 1083 | + ); |
|
| 1084 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
| 1085 | + // abandoned |
|
| 1086 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
| 1087 | + // if we've gotten this far, then let's save what we have |
|
| 1088 | + $registration->save(); |
|
| 1089 | + // add relation between TXN and registration |
|
| 1090 | + $this->_associate_registration_with_transaction($registration); |
|
| 1091 | + } |
|
| 1092 | + } else { |
|
| 1093 | + EE_Error::add_error( |
|
| 1094 | + esc_html__( |
|
| 1095 | + 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
| 1096 | + 'event_espresso' |
|
| 1097 | + ), |
|
| 1098 | + __FILE__, |
|
| 1099 | + __FUNCTION__, |
|
| 1100 | + __LINE__ |
|
| 1101 | + ); |
|
| 1102 | + // remove malformed data |
|
| 1103 | + unset($valid_data[$reg_url_link]); |
|
| 1104 | + return false; |
|
| 1105 | + } |
|
| 1106 | + |
|
| 1107 | + } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
| 1108 | + return $att_nmbr; |
|
| 1109 | + } |
|
| 1110 | + |
|
| 1111 | + |
|
| 1112 | + /** |
|
| 1113 | + * _save_registration_form_input |
|
| 1114 | + * |
|
| 1115 | + * @param EE_Registration $registration |
|
| 1116 | + * @param string $form_input |
|
| 1117 | + * @param string $input_value |
|
| 1118 | + * @return bool |
|
| 1119 | + * @throws EE_Error |
|
| 1120 | + * @throws InvalidArgumentException |
|
| 1121 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1122 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1123 | + */ |
|
| 1124 | + private function _save_registration_form_input( |
|
| 1125 | + EE_Registration $registration, |
|
| 1126 | + $form_input = '', |
|
| 1127 | + $input_value = '' |
|
| 1128 | + ) { |
|
| 1129 | + // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
| 1130 | + // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
| 1131 | + // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
| 1132 | + // allow for plugins to hook in and do their own processing of the form input. |
|
| 1133 | + // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
| 1134 | + if (apply_filters( |
|
| 1135 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
| 1136 | + false, |
|
| 1137 | + $registration, |
|
| 1138 | + $form_input, |
|
| 1139 | + $input_value, |
|
| 1140 | + $this |
|
| 1141 | + )) { |
|
| 1142 | + return true; |
|
| 1143 | + } |
|
| 1144 | + /* |
|
| 1145 | 1145 | * $answer_cache_id is the key used to find the EE_Answer we want |
| 1146 | 1146 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
| 1147 | 1147 | */ |
| 1148 | - $answer_cache_id = $this->checkout->reg_url_link |
|
| 1149 | - ? $form_input . '-' . $registration->reg_url_link() |
|
| 1150 | - : $form_input; |
|
| 1151 | - $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
| 1152 | - && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
|
| 1153 | - ? true |
|
| 1154 | - : false; |
|
| 1155 | - //rename form_inputs if they are EE_Attendee properties |
|
| 1156 | - switch ((string) $form_input) { |
|
| 1157 | - case 'state': |
|
| 1158 | - case 'STA_ID': |
|
| 1159 | - $attendee_property = true; |
|
| 1160 | - $form_input = 'STA_ID'; |
|
| 1161 | - break; |
|
| 1162 | - |
|
| 1163 | - case 'country': |
|
| 1164 | - case 'CNT_ISO': |
|
| 1165 | - $attendee_property = true; |
|
| 1166 | - $form_input = 'CNT_ISO'; |
|
| 1167 | - break; |
|
| 1168 | - |
|
| 1169 | - default: |
|
| 1170 | - $ATT_input = 'ATT_' . $form_input; |
|
| 1171 | - //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
| 1172 | - $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
| 1173 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
| 1174 | - } |
|
| 1175 | - // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
| 1176 | - // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
| 1177 | - // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
| 1178 | - // if this form input has a corresponding attendee property |
|
| 1179 | - if ($attendee_property) { |
|
| 1180 | - $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
| 1181 | - if ($answer_is_obj) { |
|
| 1182 | - // and delete the corresponding answer since we won't be storing this data in that object |
|
| 1183 | - $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
| 1184 | - $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
| 1185 | - } |
|
| 1186 | - return true; |
|
| 1187 | - } elseif ($answer_is_obj) { |
|
| 1188 | - // save this data to the answer object |
|
| 1189 | - $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
| 1190 | - $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
| 1191 | - return $result !== false ? true : false; |
|
| 1192 | - } else { |
|
| 1193 | - foreach ($this->_registration_answers as $answer) { |
|
| 1194 | - if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
| 1195 | - $answer->set_value($input_value); |
|
| 1196 | - $result = $answer->save(); |
|
| 1197 | - return $result !== false ? true : false; |
|
| 1198 | - } |
|
| 1199 | - } |
|
| 1200 | - } |
|
| 1201 | - return false; |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - |
|
| 1205 | - /** |
|
| 1206 | - * _verify_critical_attendee_details_are_set |
|
| 1207 | - * |
|
| 1208 | - * @param string $form_input |
|
| 1209 | - * @param string $input_value |
|
| 1210 | - * @return boolean |
|
| 1211 | - */ |
|
| 1212 | - private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
| 1213 | - $form_input = '', |
|
| 1214 | - $input_value = '' |
|
| 1215 | - ) { |
|
| 1216 | - if (empty($input_value)) { |
|
| 1217 | - // if the form input isn't marked as being required, then just return |
|
| 1218 | - if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
| 1219 | - return true; |
|
| 1220 | - } |
|
| 1221 | - switch ($form_input) { |
|
| 1222 | - case 'fname': |
|
| 1223 | - EE_Error::add_error( |
|
| 1224 | - esc_html__('First Name is a required value.', 'event_espresso'), |
|
| 1225 | - __FILE__, |
|
| 1226 | - __FUNCTION__, |
|
| 1227 | - __LINE__ |
|
| 1228 | - ); |
|
| 1229 | - return false; |
|
| 1230 | - break; |
|
| 1231 | - case 'lname': |
|
| 1232 | - EE_Error::add_error( |
|
| 1233 | - esc_html__('Last Name is a required value.', 'event_espresso'), |
|
| 1234 | - __FILE__, |
|
| 1235 | - __FUNCTION__, |
|
| 1236 | - __LINE__ |
|
| 1237 | - ); |
|
| 1238 | - return false; |
|
| 1239 | - break; |
|
| 1240 | - case 'email': |
|
| 1241 | - EE_Error::add_error( |
|
| 1242 | - esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
| 1243 | - __FILE__, |
|
| 1244 | - __FUNCTION__, |
|
| 1245 | - __LINE__ |
|
| 1246 | - ); |
|
| 1247 | - return false; |
|
| 1248 | - break; |
|
| 1249 | - } |
|
| 1250 | - } |
|
| 1251 | - return true; |
|
| 1252 | - } |
|
| 1253 | - |
|
| 1254 | - |
|
| 1255 | - /** |
|
| 1256 | - * _associate_attendee_with_registration |
|
| 1257 | - * |
|
| 1258 | - * @param EE_Registration $registration |
|
| 1259 | - * @param EE_Attendee $attendee |
|
| 1260 | - * @return void |
|
| 1261 | - * @throws EE_Error |
|
| 1262 | - * @throws RuntimeException |
|
| 1263 | - */ |
|
| 1264 | - private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
| 1265 | - { |
|
| 1266 | - // add relation to attendee |
|
| 1267 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
| 1268 | - $registration->set_attendee_id($attendee->ID()); |
|
| 1269 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
| 1270 | - } |
|
| 1271 | - |
|
| 1272 | - |
|
| 1273 | - /** |
|
| 1274 | - * _associate_registration_with_transaction |
|
| 1275 | - * |
|
| 1276 | - * @param EE_Registration $registration |
|
| 1277 | - * @return void |
|
| 1278 | - * @throws \EE_Error |
|
| 1279 | - */ |
|
| 1280 | - private function _associate_registration_with_transaction(EE_Registration $registration) |
|
| 1281 | - { |
|
| 1282 | - // add relation to registration |
|
| 1283 | - $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
| 1284 | - $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
| 1285 | - } |
|
| 1286 | - |
|
| 1287 | - |
|
| 1288 | - /** |
|
| 1289 | - * _copy_critical_attendee_details_from_primary_registrant |
|
| 1290 | - * ensures that all attendees at least have data for first name, last name, and email address |
|
| 1291 | - * |
|
| 1292 | - * @param array $attendee_data |
|
| 1293 | - * @return array |
|
| 1294 | - * @throws \EE_Error |
|
| 1295 | - */ |
|
| 1296 | - private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
| 1297 | - { |
|
| 1298 | - // bare minimum critical details include first name, last name, email address |
|
| 1299 | - $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
| 1300 | - // add address info to critical details? |
|
| 1301 | - if (apply_filters( |
|
| 1302 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
| 1303 | - false |
|
| 1304 | - )) { |
|
| 1305 | - $address_details = array( |
|
| 1306 | - 'ATT_address', |
|
| 1307 | - 'ATT_address2', |
|
| 1308 | - 'ATT_city', |
|
| 1309 | - 'STA_ID', |
|
| 1310 | - 'CNT_ISO', |
|
| 1311 | - 'ATT_zip', |
|
| 1312 | - 'ATT_phone', |
|
| 1313 | - ); |
|
| 1314 | - $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
| 1315 | - } |
|
| 1316 | - foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
| 1317 | - if (! isset($attendee_data[$critical_attendee_detail]) |
|
| 1318 | - || empty($attendee_data[$critical_attendee_detail]) |
|
| 1319 | - ) { |
|
| 1320 | - $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
| 1321 | - $critical_attendee_detail |
|
| 1322 | - ); |
|
| 1323 | - } |
|
| 1324 | - } |
|
| 1325 | - return $attendee_data; |
|
| 1326 | - } |
|
| 1327 | - |
|
| 1328 | - |
|
| 1329 | - /** |
|
| 1330 | - * update_reg_step |
|
| 1331 | - * this is the final step after a user revisits the site to edit their attendee information |
|
| 1332 | - * this gets called AFTER the process_reg_step() method above |
|
| 1333 | - * |
|
| 1334 | - * @return bool |
|
| 1335 | - * @throws EE_Error |
|
| 1336 | - * @throws InvalidArgumentException |
|
| 1337 | - * @throws ReflectionException |
|
| 1338 | - * @throws RuntimeException |
|
| 1339 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1340 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1341 | - */ |
|
| 1342 | - public function update_reg_step() |
|
| 1343 | - { |
|
| 1344 | - // save everything |
|
| 1345 | - if ($this->process_reg_step()) { |
|
| 1346 | - $this->checkout->redirect = true; |
|
| 1347 | - $this->checkout->redirect_url = add_query_arg( |
|
| 1348 | - array( |
|
| 1349 | - 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
| 1350 | - 'revisit' => true, |
|
| 1351 | - ), |
|
| 1352 | - $this->checkout->thank_you_page_url |
|
| 1353 | - ); |
|
| 1354 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1355 | - return true; |
|
| 1356 | - } |
|
| 1357 | - return false; |
|
| 1358 | - } |
|
| 1148 | + $answer_cache_id = $this->checkout->reg_url_link |
|
| 1149 | + ? $form_input . '-' . $registration->reg_url_link() |
|
| 1150 | + : $form_input; |
|
| 1151 | + $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
| 1152 | + && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
|
| 1153 | + ? true |
|
| 1154 | + : false; |
|
| 1155 | + //rename form_inputs if they are EE_Attendee properties |
|
| 1156 | + switch ((string) $form_input) { |
|
| 1157 | + case 'state': |
|
| 1158 | + case 'STA_ID': |
|
| 1159 | + $attendee_property = true; |
|
| 1160 | + $form_input = 'STA_ID'; |
|
| 1161 | + break; |
|
| 1162 | + |
|
| 1163 | + case 'country': |
|
| 1164 | + case 'CNT_ISO': |
|
| 1165 | + $attendee_property = true; |
|
| 1166 | + $form_input = 'CNT_ISO'; |
|
| 1167 | + break; |
|
| 1168 | + |
|
| 1169 | + default: |
|
| 1170 | + $ATT_input = 'ATT_' . $form_input; |
|
| 1171 | + //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
| 1172 | + $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
| 1173 | + $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
| 1174 | + } |
|
| 1175 | + // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
| 1176 | + // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
| 1177 | + // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
| 1178 | + // if this form input has a corresponding attendee property |
|
| 1179 | + if ($attendee_property) { |
|
| 1180 | + $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
| 1181 | + if ($answer_is_obj) { |
|
| 1182 | + // and delete the corresponding answer since we won't be storing this data in that object |
|
| 1183 | + $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
| 1184 | + $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
| 1185 | + } |
|
| 1186 | + return true; |
|
| 1187 | + } elseif ($answer_is_obj) { |
|
| 1188 | + // save this data to the answer object |
|
| 1189 | + $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
| 1190 | + $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
| 1191 | + return $result !== false ? true : false; |
|
| 1192 | + } else { |
|
| 1193 | + foreach ($this->_registration_answers as $answer) { |
|
| 1194 | + if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
| 1195 | + $answer->set_value($input_value); |
|
| 1196 | + $result = $answer->save(); |
|
| 1197 | + return $result !== false ? true : false; |
|
| 1198 | + } |
|
| 1199 | + } |
|
| 1200 | + } |
|
| 1201 | + return false; |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + |
|
| 1205 | + /** |
|
| 1206 | + * _verify_critical_attendee_details_are_set |
|
| 1207 | + * |
|
| 1208 | + * @param string $form_input |
|
| 1209 | + * @param string $input_value |
|
| 1210 | + * @return boolean |
|
| 1211 | + */ |
|
| 1212 | + private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
| 1213 | + $form_input = '', |
|
| 1214 | + $input_value = '' |
|
| 1215 | + ) { |
|
| 1216 | + if (empty($input_value)) { |
|
| 1217 | + // if the form input isn't marked as being required, then just return |
|
| 1218 | + if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
| 1219 | + return true; |
|
| 1220 | + } |
|
| 1221 | + switch ($form_input) { |
|
| 1222 | + case 'fname': |
|
| 1223 | + EE_Error::add_error( |
|
| 1224 | + esc_html__('First Name is a required value.', 'event_espresso'), |
|
| 1225 | + __FILE__, |
|
| 1226 | + __FUNCTION__, |
|
| 1227 | + __LINE__ |
|
| 1228 | + ); |
|
| 1229 | + return false; |
|
| 1230 | + break; |
|
| 1231 | + case 'lname': |
|
| 1232 | + EE_Error::add_error( |
|
| 1233 | + esc_html__('Last Name is a required value.', 'event_espresso'), |
|
| 1234 | + __FILE__, |
|
| 1235 | + __FUNCTION__, |
|
| 1236 | + __LINE__ |
|
| 1237 | + ); |
|
| 1238 | + return false; |
|
| 1239 | + break; |
|
| 1240 | + case 'email': |
|
| 1241 | + EE_Error::add_error( |
|
| 1242 | + esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
| 1243 | + __FILE__, |
|
| 1244 | + __FUNCTION__, |
|
| 1245 | + __LINE__ |
|
| 1246 | + ); |
|
| 1247 | + return false; |
|
| 1248 | + break; |
|
| 1249 | + } |
|
| 1250 | + } |
|
| 1251 | + return true; |
|
| 1252 | + } |
|
| 1253 | + |
|
| 1254 | + |
|
| 1255 | + /** |
|
| 1256 | + * _associate_attendee_with_registration |
|
| 1257 | + * |
|
| 1258 | + * @param EE_Registration $registration |
|
| 1259 | + * @param EE_Attendee $attendee |
|
| 1260 | + * @return void |
|
| 1261 | + * @throws EE_Error |
|
| 1262 | + * @throws RuntimeException |
|
| 1263 | + */ |
|
| 1264 | + private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
| 1265 | + { |
|
| 1266 | + // add relation to attendee |
|
| 1267 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
| 1268 | + $registration->set_attendee_id($attendee->ID()); |
|
| 1269 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
| 1270 | + } |
|
| 1271 | + |
|
| 1272 | + |
|
| 1273 | + /** |
|
| 1274 | + * _associate_registration_with_transaction |
|
| 1275 | + * |
|
| 1276 | + * @param EE_Registration $registration |
|
| 1277 | + * @return void |
|
| 1278 | + * @throws \EE_Error |
|
| 1279 | + */ |
|
| 1280 | + private function _associate_registration_with_transaction(EE_Registration $registration) |
|
| 1281 | + { |
|
| 1282 | + // add relation to registration |
|
| 1283 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
| 1284 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
| 1285 | + } |
|
| 1286 | + |
|
| 1287 | + |
|
| 1288 | + /** |
|
| 1289 | + * _copy_critical_attendee_details_from_primary_registrant |
|
| 1290 | + * ensures that all attendees at least have data for first name, last name, and email address |
|
| 1291 | + * |
|
| 1292 | + * @param array $attendee_data |
|
| 1293 | + * @return array |
|
| 1294 | + * @throws \EE_Error |
|
| 1295 | + */ |
|
| 1296 | + private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
| 1297 | + { |
|
| 1298 | + // bare minimum critical details include first name, last name, email address |
|
| 1299 | + $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
| 1300 | + // add address info to critical details? |
|
| 1301 | + if (apply_filters( |
|
| 1302 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
| 1303 | + false |
|
| 1304 | + )) { |
|
| 1305 | + $address_details = array( |
|
| 1306 | + 'ATT_address', |
|
| 1307 | + 'ATT_address2', |
|
| 1308 | + 'ATT_city', |
|
| 1309 | + 'STA_ID', |
|
| 1310 | + 'CNT_ISO', |
|
| 1311 | + 'ATT_zip', |
|
| 1312 | + 'ATT_phone', |
|
| 1313 | + ); |
|
| 1314 | + $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
| 1315 | + } |
|
| 1316 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
| 1317 | + if (! isset($attendee_data[$critical_attendee_detail]) |
|
| 1318 | + || empty($attendee_data[$critical_attendee_detail]) |
|
| 1319 | + ) { |
|
| 1320 | + $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
| 1321 | + $critical_attendee_detail |
|
| 1322 | + ); |
|
| 1323 | + } |
|
| 1324 | + } |
|
| 1325 | + return $attendee_data; |
|
| 1326 | + } |
|
| 1327 | + |
|
| 1328 | + |
|
| 1329 | + /** |
|
| 1330 | + * update_reg_step |
|
| 1331 | + * this is the final step after a user revisits the site to edit their attendee information |
|
| 1332 | + * this gets called AFTER the process_reg_step() method above |
|
| 1333 | + * |
|
| 1334 | + * @return bool |
|
| 1335 | + * @throws EE_Error |
|
| 1336 | + * @throws InvalidArgumentException |
|
| 1337 | + * @throws ReflectionException |
|
| 1338 | + * @throws RuntimeException |
|
| 1339 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 1340 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 1341 | + */ |
|
| 1342 | + public function update_reg_step() |
|
| 1343 | + { |
|
| 1344 | + // save everything |
|
| 1345 | + if ($this->process_reg_step()) { |
|
| 1346 | + $this->checkout->redirect = true; |
|
| 1347 | + $this->checkout->redirect_url = add_query_arg( |
|
| 1348 | + array( |
|
| 1349 | + 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
| 1350 | + 'revisit' => true, |
|
| 1351 | + ), |
|
| 1352 | + $this->checkout->thank_you_page_url |
|
| 1353 | + ); |
|
| 1354 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
| 1355 | + return true; |
|
| 1356 | + } |
|
| 1357 | + return false; |
|
| 1358 | + } |
|
| 1359 | 1359 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | { |
| 49 | 49 | $this->_slug = 'attendee_information'; |
| 50 | 50 | $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
| 51 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
| 51 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'attendee_info_main.template.php'; |
|
| 52 | 52 | $this->checkout = $checkout; |
| 53 | 53 | $this->_reset_success_message(); |
| 54 | 54 | $this->set_instructions( |
@@ -59,11 +59,11 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | public function translate_js_strings() |
| 61 | 61 | { |
| 62 | - EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
| 62 | + EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
| 63 | 63 | ' is a required question.', |
| 64 | 64 | 'event_espresso' |
| 65 | 65 | ); |
| 66 | - EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
| 66 | + EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
| 67 | 67 | ' is a required question. Please enter a value for at least one of the options.', |
| 68 | 68 | 'event_espresso' |
| 69 | 69 | ); |
@@ -71,18 +71,18 @@ discard block |
||
| 71 | 71 | 'Please answer all required questions correctly before proceeding.', |
| 72 | 72 | 'event_espresso' |
| 73 | 73 | ); |
| 74 | - EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
| 74 | + EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
| 75 | 75 | esc_html__( |
| 76 | 76 | 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
| 77 | 77 | 'event_espresso' |
| 78 | 78 | ), |
| 79 | 79 | '<br/>' |
| 80 | 80 | ); |
| 81 | - EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
| 81 | + EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
| 82 | 82 | 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
| 83 | 83 | 'event_espresso' |
| 84 | 84 | ); |
| 85 | - EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
| 85 | + EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
| 86 | 86 | 'You must enter a valid email address.', |
| 87 | 87 | 'event_espresso' |
| 88 | 88 | ); |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | && $this->checkout->visit_allows_processing_of_this_registration($registration) |
| 146 | 146 | ) { |
| 147 | 147 | $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
| 148 | - if (! $this->checkout->admin_request) { |
|
| 148 | + if ( ! $this->checkout->admin_request) { |
|
| 149 | 149 | $template_args['registrations'][$registration->reg_url_link()] = $registration; |
| 150 | 150 | $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
| 151 | 151 | $template_args['ticket_count'][$registration->ticket()->ID()] |
@@ -194,8 +194,7 @@ discard block |
||
| 194 | 194 | 'html_id' => $this->reg_form_name(), |
| 195 | 195 | 'subsections' => $subsections, |
| 196 | 196 | 'layout_strategy' => $this->checkout->admin_request ? |
| 197 | - new EE_Div_Per_Section_Layout() : |
|
| 198 | - new EE_Template_Layout( |
|
| 197 | + new EE_Div_Per_Section_Layout() : new EE_Template_Layout( |
|
| 199 | 198 | array( |
| 200 | 199 | 'layout_template_file' => $this->_template, // layout_template |
| 201 | 200 | 'template_args' => $template_args, |
@@ -238,7 +237,7 @@ discard block |
||
| 238 | 237 | if ($question_groups) { |
| 239 | 238 | // array of params to pass to parent constructor |
| 240 | 239 | $form_args = array( |
| 241 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
| 240 | + 'html_id' => 'ee-registration-'.$registration->reg_url_link(), |
|
| 242 | 241 | 'html_class' => 'ee-reg-form-attendee-dv', |
| 243 | 242 | 'html_style' => $this->checkout->admin_request |
| 244 | 243 | ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
@@ -294,7 +293,7 @@ discard block |
||
| 294 | 293 | // generate hidden input |
| 295 | 294 | return new EE_Hidden_Input( |
| 296 | 295 | array( |
| 297 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
| 296 | + 'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(), |
|
| 298 | 297 | 'default' => $additional_attendee_reg_info, |
| 299 | 298 | ) |
| 300 | 299 | ); |
@@ -314,11 +313,11 @@ discard block |
||
| 314 | 313 | { |
| 315 | 314 | // array of params to pass to parent constructor |
| 316 | 315 | $form_args = array( |
| 317 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
| 316 | + 'html_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-'.$registration->ID(), |
|
| 318 | 317 | 'html_class' => $this->checkout->admin_request |
| 319 | 318 | ? 'form-table ee-reg-form-qstn-grp-dv' |
| 320 | 319 | : 'ee-reg-form-qstn-grp-dv', |
| 321 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID() . '-lbl', |
|
| 320 | + 'html_label_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-'.$registration->ID().'-lbl', |
|
| 322 | 321 | 'subsections' => array( |
| 323 | 322 | 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
| 324 | 323 | ), |
@@ -329,7 +328,7 @@ discard block |
||
| 329 | 328 | // where params |
| 330 | 329 | $query_params = array('QST_deleted' => 0); |
| 331 | 330 | // don't load admin only questions on the frontend |
| 332 | - if (! $this->checkout->admin_request) { |
|
| 331 | + if ( ! $this->checkout->admin_request) { |
|
| 333 | 332 | $query_params['QST_admin_only'] = array('!=', true); |
| 334 | 333 | } |
| 335 | 334 | $questions = $question_group->get_many_related( |
@@ -473,7 +472,7 @@ discard block |
||
| 473 | 472 | { |
| 474 | 473 | return new EE_Form_Section_HTML( |
| 475 | 474 | EEH_Template::locate_template( |
| 476 | - SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
| 475 | + SPCO_REG_STEPS_PATH.$this->_slug.DS.'_auto_copy_attendee_info.template.php', |
|
| 477 | 476 | apply_filters( |
| 478 | 477 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
| 479 | 478 | array() |
@@ -505,16 +504,16 @@ discard block |
||
| 505 | 504 | if ($registration->ticket()->ID() !== $prev_ticket) { |
| 506 | 505 | $item_name = $registration->ticket()->name(); |
| 507 | 506 | $item_name .= $registration->ticket()->description() !== '' |
| 508 | - ? ' - ' . $registration->ticket()->description() |
|
| 507 | + ? ' - '.$registration->ticket()->description() |
|
| 509 | 508 | : ''; |
| 510 | - $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']'] = |
|
| 509 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID().']'] = |
|
| 511 | 510 | new EE_Form_Section_HTML( |
| 512 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
| 511 | + '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>' |
|
| 513 | 512 | ); |
| 514 | 513 | $prev_ticket = $registration->ticket()->ID(); |
| 515 | 514 | } |
| 516 | 515 | |
| 517 | - $copy_attendee_info_inputs['spco_copy_attendee_chk[' . $registration->ID() . ']'] = |
|
| 516 | + $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] = |
|
| 518 | 517 | new EE_Checkbox_Multi_Input( |
| 519 | 518 | array( |
| 520 | 519 | $registration->ID() => sprintf( |
@@ -523,7 +522,7 @@ discard block |
||
| 523 | 522 | ), |
| 524 | 523 | ), |
| 525 | 524 | array( |
| 526 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
| 525 | + 'html_id' => 'spco-copy-attendee-chk-'.$registration->reg_url_link(), |
|
| 527 | 526 | 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
| 528 | 527 | 'display_html_label_text' => false, |
| 529 | 528 | ) |
@@ -572,7 +571,7 @@ discard block |
||
| 572 | 571 | $registration, |
| 573 | 572 | $question->system_ID() |
| 574 | 573 | ); |
| 575 | - $answer = $answer_value === null |
|
| 574 | + $answer = $answer_value === null |
|
| 576 | 575 | ? EEM_Answer::instance()->get_one( |
| 577 | 576 | array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
| 578 | 577 | ) |
@@ -589,14 +588,14 @@ discard block |
||
| 589 | 588 | } |
| 590 | 589 | // verify instance |
| 591 | 590 | if ($answer instanceof EE_Answer) { |
| 592 | - if (! empty($answer_value)) { |
|
| 591 | + if ( ! empty($answer_value)) { |
|
| 593 | 592 | $answer->set('ANS_value', $answer_value); |
| 594 | 593 | } |
| 595 | 594 | $answer->cache('Question', $question); |
| 596 | 595 | //remember system ID had a bug where sometimes it could be null |
| 597 | 596 | $answer_cache_id = $question->is_system_question() |
| 598 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
| 599 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
| 597 | + ? $question->system_ID().'-'.$registration->reg_url_link() |
|
| 598 | + : $question->ID().'-'.$registration->reg_url_link(); |
|
| 600 | 599 | $registration->cache('Answer', $answer, $answer_cache_id); |
| 601 | 600 | } |
| 602 | 601 | return $this->_generate_question_input($registration, $question, $answer); |
@@ -628,18 +627,18 @@ discard block |
||
| 628 | 627 | 10, |
| 629 | 628 | 4 |
| 630 | 629 | ); |
| 631 | - $input_constructor_args = array( |
|
| 632 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
| 633 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 634 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
| 635 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
| 630 | + $input_constructor_args = array( |
|
| 631 | + 'html_name' => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']', |
|
| 632 | + 'html_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
| 633 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-'.$identifier, |
|
| 634 | + 'html_label_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
| 636 | 635 | 'html_label_class' => 'ee-reg-qstn', |
| 637 | 636 | ); |
| 638 | 637 | $input_constructor_args['html_label_id'] .= '-lbl'; |
| 639 | 638 | if ($answer instanceof EE_Answer && $answer->ID()) { |
| 640 | - $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
| 641 | - $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
| 642 | - $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
| 639 | + $input_constructor_args['html_name'] .= '['.$answer->ID().']'; |
|
| 640 | + $input_constructor_args['html_id'] .= '-'.$answer->ID(); |
|
| 641 | + $input_constructor_args['html_label_id'] .= '-'.$answer->ID(); |
|
| 643 | 642 | } |
| 644 | 643 | $form_input = $question->generate_form_input( |
| 645 | 644 | $registration, |
@@ -682,7 +681,7 @@ discard block |
||
| 682 | 681 | $countries = $this->checkout->action === 'process_reg_step' |
| 683 | 682 | ? EEM_Country::instance()->get_all_countries() |
| 684 | 683 | : EEM_Country::instance()->get_all_active_countries(); |
| 685 | - if (! empty($countries)) { |
|
| 684 | + if ( ! empty($countries)) { |
|
| 686 | 685 | foreach ($countries as $country) { |
| 687 | 686 | if ($country instanceof EE_Country) { |
| 688 | 687 | $country_options[$country->ID()] = $country->name(); |
@@ -732,7 +731,7 @@ discard block |
||
| 732 | 731 | $states = $this->checkout->action === 'process_reg_step' |
| 733 | 732 | ? EEM_State::instance()->get_all_states() |
| 734 | 733 | : EEM_State::instance()->get_all_active_states(); |
| 735 | - if (! empty($states)) { |
|
| 734 | + if ( ! empty($states)) { |
|
| 736 | 735 | foreach ($states as $state) { |
| 737 | 736 | if ($state instanceof EE_State) { |
| 738 | 737 | $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
@@ -784,7 +783,7 @@ discard block |
||
| 784 | 783 | ); |
| 785 | 784 | return false; |
| 786 | 785 | } |
| 787 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
| 786 | + if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
| 788 | 787 | EE_Error::add_error( |
| 789 | 788 | esc_html__( |
| 790 | 789 | 'A valid transaction could not be initiated for processing your registrations.', |
@@ -801,10 +800,10 @@ discard block |
||
| 801 | 800 | // verify we got the goods |
| 802 | 801 | if (empty($registrations)) { |
| 803 | 802 | //combine the old translated string with a new one, in order to not break translations |
| 804 | - $error_message = esc_html__( 'Your form data could not be applied to any valid registrations.', 'event_espresso' ) |
|
| 803 | + $error_message = esc_html__('Your form data could not be applied to any valid registrations.', 'event_espresso') |
|
| 805 | 804 | . sprintf( |
| 806 | 805 | esc_html__('%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', 'event_espresso'), |
| 807 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
| 806 | + '<a href="'.get_post_type_archive_link('espresso_events').'" >', |
|
| 808 | 807 | '</a>', |
| 809 | 808 | '<br />' |
| 810 | 809 | ); |
@@ -823,7 +822,7 @@ discard block |
||
| 823 | 822 | if ($registrations_processed === false) { |
| 824 | 823 | // but return immediately if the previous step exited early due to errors |
| 825 | 824 | return false; |
| 826 | - } elseif (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
| 825 | + } elseif ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
| 827 | 826 | // generate a correctly translated string for all possible singular/plural combinations |
| 828 | 827 | if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
| 829 | 828 | $error_msg = sprintf( |
@@ -904,7 +903,7 @@ discard block |
||
| 904 | 903 | // grab the saved registrations from the transaction |
| 905 | 904 | foreach ($registrations as $registration) { |
| 906 | 905 | // verify EE_Registration object |
| 907 | - if (! $registration instanceof EE_Registration) { |
|
| 906 | + if ( ! $registration instanceof EE_Registration) { |
|
| 908 | 907 | EE_Error::add_error( |
| 909 | 908 | esc_html__( |
| 910 | 909 | 'An invalid Registration object was discovered when attempting to process your registration information.', |
@@ -919,12 +918,12 @@ discard block |
||
| 919 | 918 | /** @var string $reg_url_link */ |
| 920 | 919 | $reg_url_link = $registration->reg_url_link(); |
| 921 | 920 | // reg_url_link exists ? |
| 922 | - if (! empty($reg_url_link)) { |
|
| 921 | + if ( ! empty($reg_url_link)) { |
|
| 923 | 922 | // should this registration be processed during this visit ? |
| 924 | 923 | if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
| 925 | 924 | // if NOT revisiting, then let's save the registration now, |
| 926 | 925 | // so that we have a REG_ID to use when generating other objects |
| 927 | - if (! $this->checkout->revisit) { |
|
| 926 | + if ( ! $this->checkout->revisit) { |
|
| 928 | 927 | $registration->save(); |
| 929 | 928 | } |
| 930 | 929 | /** |
@@ -959,7 +958,7 @@ discard block |
||
| 959 | 958 | ? true |
| 960 | 959 | : false; |
| 961 | 960 | // filter form input data for this registration |
| 962 | - $valid_data[$reg_url_link] = (array)apply_filters( |
|
| 961 | + $valid_data[$reg_url_link] = (array) apply_filters( |
|
| 963 | 962 | 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
| 964 | 963 | $valid_data[$reg_url_link] |
| 965 | 964 | ); |
@@ -971,11 +970,11 @@ discard block |
||
| 971 | 970 | } |
| 972 | 971 | // now loop through our array of valid post data && process attendee reg forms |
| 973 | 972 | foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
| 974 | - if (! in_array($form_section, $non_input_form_sections)) { |
|
| 973 | + if ( ! in_array($form_section, $non_input_form_sections)) { |
|
| 975 | 974 | foreach ($form_inputs as $form_input => $input_value) { |
| 976 | 975 | // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
| 977 | 976 | // check for critical inputs |
| 978 | - if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
| 977 | + if ( ! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
| 979 | 978 | $form_input, |
| 980 | 979 | $input_value |
| 981 | 980 | ) |
@@ -995,7 +994,7 @@ discard block |
||
| 995 | 994 | $input_value = $primary_registrant[$form_input]; |
| 996 | 995 | } |
| 997 | 996 | // now attempt to save the input data |
| 998 | - if (! $this->_save_registration_form_input( |
|
| 997 | + if ( ! $this->_save_registration_form_input( |
|
| 999 | 998 | $registration, |
| 1000 | 999 | $form_input, |
| 1001 | 1000 | $input_value |
@@ -1051,7 +1050,7 @@ discard block |
||
| 1051 | 1050 | // add relation to registration, set attendee ID, and cache attendee |
| 1052 | 1051 | $this->_associate_attendee_with_registration($registration, $attendee); |
| 1053 | 1052 | // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
| 1054 | - if (! $registration->attendee() instanceof EE_Attendee) { |
|
| 1053 | + if ( ! $registration->attendee() instanceof EE_Attendee) { |
|
| 1055 | 1054 | EE_Error::add_error( |
| 1056 | 1055 | sprintf( |
| 1057 | 1056 | esc_html__( |
@@ -1146,7 +1145,7 @@ discard block |
||
| 1146 | 1145 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
| 1147 | 1146 | */ |
| 1148 | 1147 | $answer_cache_id = $this->checkout->reg_url_link |
| 1149 | - ? $form_input . '-' . $registration->reg_url_link() |
|
| 1148 | + ? $form_input.'-'.$registration->reg_url_link() |
|
| 1150 | 1149 | : $form_input; |
| 1151 | 1150 | $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
| 1152 | 1151 | && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
@@ -1167,10 +1166,10 @@ discard block |
||
| 1167 | 1166 | break; |
| 1168 | 1167 | |
| 1169 | 1168 | default: |
| 1170 | - $ATT_input = 'ATT_' . $form_input; |
|
| 1169 | + $ATT_input = 'ATT_'.$form_input; |
|
| 1171 | 1170 | //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
| 1172 | 1171 | $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
| 1173 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
| 1172 | + $form_input = $attendee_property ? 'ATT_'.$form_input : $form_input; |
|
| 1174 | 1173 | } |
| 1175 | 1174 | // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
| 1176 | 1175 | // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
@@ -1215,7 +1214,7 @@ discard block |
||
| 1215 | 1214 | ) { |
| 1216 | 1215 | if (empty($input_value)) { |
| 1217 | 1216 | // if the form input isn't marked as being required, then just return |
| 1218 | - if (! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
| 1217 | + if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
| 1219 | 1218 | return true; |
| 1220 | 1219 | } |
| 1221 | 1220 | switch ($form_input) { |
@@ -1302,7 +1301,7 @@ discard block |
||
| 1302 | 1301 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
| 1303 | 1302 | false |
| 1304 | 1303 | )) { |
| 1305 | - $address_details = array( |
|
| 1304 | + $address_details = array( |
|
| 1306 | 1305 | 'ATT_address', |
| 1307 | 1306 | 'ATT_address2', |
| 1308 | 1307 | 'ATT_city', |
@@ -1314,7 +1313,7 @@ discard block |
||
| 1314 | 1313 | $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
| 1315 | 1314 | } |
| 1316 | 1315 | foreach ($critical_attendee_details as $critical_attendee_detail) { |
| 1317 | - if (! isset($attendee_data[$critical_attendee_detail]) |
|
| 1316 | + if ( ! isset($attendee_data[$critical_attendee_detail]) |
|
| 1318 | 1317 | || empty($attendee_data[$critical_attendee_detail]) |
| 1319 | 1318 | ) { |
| 1320 | 1319 | $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | * |
| 327 | 327 | * @param EE_Ticket $ticket |
| 328 | 328 | * @param int $quantity |
| 329 | - * @return bool |
|
| 329 | + * @return integer |
|
| 330 | 330 | * @throws EE_Error |
| 331 | 331 | */ |
| 332 | 332 | protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | /** |
| 344 | 344 | * @param EE_Ticket $ticket |
| 345 | 345 | * @param int $quantity |
| 346 | - * @return bool |
|
| 346 | + * @return integer |
|
| 347 | 347 | * @throws EE_Error |
| 348 | 348 | */ |
| 349 | 349 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
@@ -969,6 +969,7 @@ discard block |
||
| 969 | 969 | /** |
| 970 | 970 | * @param EE_Ticket[] $tickets_with_reservations |
| 971 | 971 | * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
| 972 | + * @param string $source |
|
| 972 | 973 | * @return int |
| 973 | 974 | * @throws UnexpectedEntityException |
| 974 | 975 | * @throws DomainException |
@@ -23,1060 +23,1060 @@ |
||
| 23 | 23 | class EED_Ticket_Sales_Monitor extends EED_Module |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - const debug = false; // true false |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * an array of raw ticket data from EED_Ticket_Selector |
|
| 30 | - * |
|
| 31 | - * @var array $ticket_selections |
|
| 32 | - */ |
|
| 33 | - protected $ticket_selections = array(); |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
| 37 | - * according to how they are displayed in the actual Ticket_Selector |
|
| 38 | - * this tracks the current row being processed |
|
| 39 | - * |
|
| 40 | - * @var int $current_row |
|
| 41 | - */ |
|
| 42 | - protected $current_row = 0; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * an array for tracking names of tickets that have sold out |
|
| 46 | - * |
|
| 47 | - * @var array $sold_out_tickets |
|
| 48 | - */ |
|
| 49 | - protected $sold_out_tickets = array(); |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * an array for tracking names of tickets that have had their quantities reduced |
|
| 53 | - * |
|
| 54 | - * @var array $decremented_tickets |
|
| 55 | - */ |
|
| 56 | - protected $decremented_tickets = array(); |
|
| 57 | - |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 62 | - * |
|
| 63 | - * @return void |
|
| 64 | - */ |
|
| 65 | - public static function set_hooks() |
|
| 66 | - { |
|
| 67 | - // release tickets for expired carts |
|
| 68 | - add_action( |
|
| 69 | - 'EED_Ticket_Selector__process_ticket_selections__before', |
|
| 70 | - array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
| 71 | - 1 |
|
| 72 | - ); |
|
| 73 | - // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
| 74 | - add_filter( |
|
| 75 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
| 76 | - array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
| 77 | - 20, |
|
| 78 | - 3 |
|
| 79 | - ); |
|
| 80 | - // add notices for sold out tickets |
|
| 81 | - add_action( |
|
| 82 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 83 | - array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
| 84 | - 10 |
|
| 85 | - ); |
|
| 86 | - // handle ticket quantities adjusted in cart |
|
| 87 | - //add_action( |
|
| 88 | - // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
| 89 | - // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
| 90 | - // 10, 2 |
|
| 91 | - //); |
|
| 92 | - // handle tickets deleted from cart |
|
| 93 | - add_action( |
|
| 94 | - 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
| 95 | - array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
| 96 | - 10, |
|
| 97 | - 2 |
|
| 98 | - ); |
|
| 99 | - // handle emptied carts |
|
| 100 | - add_action( |
|
| 101 | - 'AHEE__EE_Session__reset_cart__before_reset', |
|
| 102 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 103 | - 10, |
|
| 104 | - 1 |
|
| 105 | - ); |
|
| 106 | - add_action( |
|
| 107 | - 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
| 108 | - array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 109 | - 10, |
|
| 110 | - 1 |
|
| 111 | - ); |
|
| 112 | - // handle cancelled registrations |
|
| 113 | - add_action( |
|
| 114 | - 'AHEE__EE_Session__reset_checkout__before_reset', |
|
| 115 | - array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
| 116 | - 10, |
|
| 117 | - 1 |
|
| 118 | - ); |
|
| 119 | - // cron tasks |
|
| 120 | - add_action( |
|
| 121 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 122 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 123 | - 10, |
|
| 124 | - 1 |
|
| 125 | - ); |
|
| 126 | - add_action( |
|
| 127 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 128 | - array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 129 | - 10, |
|
| 130 | - 1 |
|
| 131 | - ); |
|
| 132 | - add_action( |
|
| 133 | - 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 134 | - array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
| 135 | - 10, |
|
| 136 | - 1 |
|
| 137 | - ); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 144 | - * |
|
| 145 | - * @return void |
|
| 146 | - */ |
|
| 147 | - public static function set_hooks_admin() |
|
| 148 | - { |
|
| 149 | - EED_Ticket_Sales_Monitor::set_hooks(); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @return EED_Ticket_Sales_Monitor|EED_Module |
|
| 156 | - */ |
|
| 157 | - public static function instance() |
|
| 158 | - { |
|
| 159 | - return parent::get_instance(__CLASS__); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param WP_Query $WP_Query |
|
| 166 | - * @return void |
|
| 167 | - */ |
|
| 168 | - public function run($WP_Query) |
|
| 169 | - { |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /********************************** PRE_TICKET_SALES **********************************/ |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Retrieves grand totals from the line items that have no TXN ID |
|
| 180 | - * and timestamps less than the current time minus the session lifespan. |
|
| 181 | - * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
| 182 | - * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
| 183 | - * |
|
| 184 | - * @return void |
|
| 185 | - * @throws DomainException |
|
| 186 | - * @throws EE_Error |
|
| 187 | - * @throws InvalidArgumentException |
|
| 188 | - * @throws InvalidDataTypeException |
|
| 189 | - * @throws InvalidInterfaceException |
|
| 190 | - * @throws UnexpectedEntityException |
|
| 191 | - */ |
|
| 192 | - public static function release_tickets_for_expired_carts() |
|
| 193 | - { |
|
| 194 | - do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
| 195 | - $expired_ticket_IDs = array(); |
|
| 196 | - $valid_ticket_line_items = array(); |
|
| 197 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
| 198 | - if (empty($total_line_items)) { |
|
| 199 | - do_action( |
|
| 200 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 201 | - $total_line_items, |
|
| 202 | - $valid_ticket_line_items, |
|
| 203 | - $expired_ticket_IDs |
|
| 204 | - ); |
|
| 205 | - return; |
|
| 206 | - } |
|
| 207 | - $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
| 208 | - foreach ($total_line_items as $total_line_item) { |
|
| 209 | - /** @var EE_Line_Item $total_line_item */ |
|
| 210 | - $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
| 211 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 212 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
| 213 | - continue; |
|
| 214 | - } |
|
| 215 | - if ($total_line_item->timestamp(true) <= $expired) { |
|
| 216 | - $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID(); |
|
| 217 | - } else { |
|
| 218 | - $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item; |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - if (! empty($expired_ticket_IDs)) { |
|
| 223 | - EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 224 | - \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
| 225 | - $valid_ticket_line_items, |
|
| 226 | - __FUNCTION__ |
|
| 227 | - ); |
|
| 228 | - // let's get rid of expired line items so that they can't interfere with tracking |
|
| 229 | - add_action( |
|
| 230 | - 'shutdown', |
|
| 231 | - array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
| 232 | - 999 |
|
| 233 | - ); |
|
| 234 | - } |
|
| 235 | - do_action( |
|
| 236 | - 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 237 | - $total_line_items, |
|
| 238 | - $valid_ticket_line_items, |
|
| 239 | - $expired_ticket_IDs |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
| 246 | - |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
| 251 | - * |
|
| 252 | - * @param int $qty |
|
| 253 | - * @param EE_Ticket $ticket |
|
| 254 | - * @return bool |
|
| 255 | - * @throws UnexpectedEntityException |
|
| 256 | - * @throws EE_Error |
|
| 257 | - */ |
|
| 258 | - public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
| 259 | - { |
|
| 260 | - $qty = absint($qty); |
|
| 261 | - if ($qty > 0) { |
|
| 262 | - $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
| 263 | - } |
|
| 264 | - if (self::debug) { |
|
| 265 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 266 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 267 | - } |
|
| 268 | - return $qty; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
| 275 | - * |
|
| 276 | - * @param EE_Ticket $ticket |
|
| 277 | - * @param int $qty |
|
| 278 | - * @return int |
|
| 279 | - * @throws UnexpectedEntityException |
|
| 280 | - * @throws EE_Error |
|
| 281 | - */ |
|
| 282 | - protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
| 283 | - { |
|
| 284 | - if (self::debug) { |
|
| 285 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 286 | - } |
|
| 287 | - if (! $ticket instanceof EE_Ticket) { |
|
| 288 | - return 0; |
|
| 289 | - } |
|
| 290 | - if (self::debug) { |
|
| 291 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 292 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
| 293 | - } |
|
| 294 | - $ticket->refresh_from_db(); |
|
| 295 | - // first let's determine the ticket availability based on sales |
|
| 296 | - $available = $ticket->qty('saleable'); |
|
| 297 | - if (self::debug) { |
|
| 298 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
| 299 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
| 300 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 301 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 302 | - echo '<br /> . . . available: ' . $available; |
|
| 303 | - } |
|
| 304 | - if ($available < 1) { |
|
| 305 | - $this->_ticket_sold_out($ticket); |
|
| 306 | - return 0; |
|
| 307 | - } |
|
| 308 | - if (self::debug) { |
|
| 309 | - echo '<br /> . . . qty: ' . $qty; |
|
| 310 | - } |
|
| 311 | - if ($available < $qty) { |
|
| 312 | - $qty = $available; |
|
| 313 | - if (self::debug) { |
|
| 314 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
| 315 | - } |
|
| 316 | - $this->_ticket_quantity_decremented($ticket); |
|
| 317 | - } |
|
| 318 | - $this->_reserve_ticket($ticket, $qty); |
|
| 319 | - return $qty; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * increments ticket reserved based on quantity passed |
|
| 326 | - * |
|
| 327 | - * @param EE_Ticket $ticket |
|
| 328 | - * @param int $quantity |
|
| 329 | - * @return bool |
|
| 330 | - * @throws EE_Error |
|
| 331 | - */ |
|
| 332 | - protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 333 | - { |
|
| 334 | - if (self::debug) { |
|
| 335 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
| 336 | - } |
|
| 337 | - $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__); |
|
| 338 | - return $ticket->save(); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * @param EE_Ticket $ticket |
|
| 345 | - * @param int $quantity |
|
| 346 | - * @return bool |
|
| 347 | - * @throws EE_Error |
|
| 348 | - */ |
|
| 349 | - protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 350 | - { |
|
| 351 | - if (self::debug) { |
|
| 352 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
| 353 | - echo '<br /> . . . ticket->reserved before: ' . $ticket->reserved(); |
|
| 354 | - } |
|
| 355 | - $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 356 | - if (self::debug) { |
|
| 357 | - echo '<br /> . . . ticket->reserved after: ' . $ticket->reserved(); |
|
| 358 | - } |
|
| 359 | - return $ticket->save() ? 1 : 0; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * removes quantities within the ticket selector based on zero ticket availability |
|
| 366 | - * |
|
| 367 | - * @param EE_Ticket $ticket |
|
| 368 | - * @return void |
|
| 369 | - * @throws UnexpectedEntityException |
|
| 370 | - * @throws EE_Error |
|
| 371 | - */ |
|
| 372 | - protected function _ticket_sold_out(EE_Ticket $ticket) |
|
| 373 | - { |
|
| 374 | - if (self::debug) { |
|
| 375 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 376 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 377 | - } |
|
| 378 | - $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * adjusts quantities within the ticket selector based on decreased ticket availability |
|
| 385 | - * |
|
| 386 | - * @param EE_Ticket $ticket |
|
| 387 | - * @return void |
|
| 388 | - * @throws UnexpectedEntityException |
|
| 389 | - * @throws EE_Error |
|
| 390 | - */ |
|
| 391 | - protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
| 392 | - { |
|
| 393 | - if (self::debug) { |
|
| 394 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 395 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 396 | - } |
|
| 397 | - $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * builds string out of ticket and event name |
|
| 404 | - * |
|
| 405 | - * @param EE_Ticket $ticket |
|
| 406 | - * @return string |
|
| 407 | - * @throws UnexpectedEntityException |
|
| 408 | - * @throws EE_Error |
|
| 409 | - */ |
|
| 410 | - protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
| 411 | - { |
|
| 412 | - $event = $ticket->get_related_event(); |
|
| 413 | - if ($event instanceof EE_Event) { |
|
| 414 | - $ticket_name = sprintf( |
|
| 415 | - _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
| 416 | - $ticket->name(), |
|
| 417 | - $event->name() |
|
| 418 | - ); |
|
| 419 | - } else { |
|
| 420 | - $ticket_name = $ticket->name(); |
|
| 421 | - } |
|
| 422 | - return $ticket_name; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - |
|
| 426 | - |
|
| 427 | - /********************************** EVENT CART **********************************/ |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * releases or reserves ticket(s) based on quantity passed |
|
| 433 | - * |
|
| 434 | - * @param EE_Line_Item $line_item |
|
| 435 | - * @param int $quantity |
|
| 436 | - * @return void |
|
| 437 | - * @throws EE_Error |
|
| 438 | - * @throws InvalidArgumentException |
|
| 439 | - * @throws InvalidDataTypeException |
|
| 440 | - * @throws InvalidInterfaceException |
|
| 441 | - */ |
|
| 442 | - public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
| 443 | - { |
|
| 444 | - $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
| 445 | - if ($ticket instanceof EE_Ticket) { |
|
| 446 | - $ticket->add_extra_meta( |
|
| 447 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 448 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 449 | - ); |
|
| 450 | - if ($quantity > 0) { |
|
| 451 | - EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
| 452 | - } else { |
|
| 453 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 454 | - } |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * releases reserved ticket(s) based on quantity passed |
|
| 462 | - * |
|
| 463 | - * @param EE_Ticket $ticket |
|
| 464 | - * @param int $quantity |
|
| 465 | - * @return void |
|
| 466 | - * @throws EE_Error |
|
| 467 | - */ |
|
| 468 | - public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
| 469 | - { |
|
| 470 | - $ticket->add_extra_meta( |
|
| 471 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 472 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 473 | - ); |
|
| 474 | - EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /********************************** POST_NOTICES **********************************/ |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * @return void |
|
| 485 | - * @throws EE_Error |
|
| 486 | - * @throws InvalidArgumentException |
|
| 487 | - * @throws ReflectionException |
|
| 488 | - * @throws InvalidDataTypeException |
|
| 489 | - * @throws InvalidInterfaceException |
|
| 490 | - */ |
|
| 491 | - public static function post_notices() |
|
| 492 | - { |
|
| 493 | - EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * @return void |
|
| 500 | - * @throws EE_Error |
|
| 501 | - * @throws InvalidArgumentException |
|
| 502 | - * @throws ReflectionException |
|
| 503 | - * @throws InvalidDataTypeException |
|
| 504 | - * @throws InvalidInterfaceException |
|
| 505 | - */ |
|
| 506 | - protected function _post_notices() |
|
| 507 | - { |
|
| 508 | - if (self::debug) { |
|
| 509 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 510 | - } |
|
| 511 | - $refresh_msg = ''; |
|
| 512 | - $none_added_msg = ''; |
|
| 513 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 514 | - $refresh_msg = __( |
|
| 515 | - 'Please refresh the page to view updated ticket quantities.', |
|
| 516 | - 'event_espresso' |
|
| 517 | - ); |
|
| 518 | - $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
| 519 | - } |
|
| 520 | - if (! empty($this->sold_out_tickets)) { |
|
| 521 | - EE_Error::add_attention( |
|
| 522 | - sprintf( |
|
| 523 | - apply_filters( |
|
| 524 | - 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
| 525 | - __( |
|
| 526 | - 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 527 | - 'event_espresso' |
|
| 528 | - ) |
|
| 529 | - ), |
|
| 530 | - '<br />', |
|
| 531 | - implode('<br />', $this->sold_out_tickets), |
|
| 532 | - $none_added_msg, |
|
| 533 | - $refresh_msg |
|
| 534 | - ) |
|
| 535 | - ); |
|
| 536 | - // alter code flow in the Ticket Selector for better UX |
|
| 537 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
| 538 | - add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
| 539 | - $this->sold_out_tickets = array(); |
|
| 540 | - // and reset the cart |
|
| 541 | - EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
| 542 | - } |
|
| 543 | - if (! empty($this->decremented_tickets)) { |
|
| 544 | - EE_Error::add_attention( |
|
| 545 | - sprintf( |
|
| 546 | - apply_filters( |
|
| 547 | - 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
| 548 | - __( |
|
| 549 | - 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 550 | - 'event_espresso' |
|
| 551 | - ) |
|
| 552 | - ), |
|
| 553 | - '<br />', |
|
| 554 | - implode('<br />', $this->decremented_tickets), |
|
| 555 | - $none_added_msg, |
|
| 556 | - $refresh_msg |
|
| 557 | - ) |
|
| 558 | - ); |
|
| 559 | - $this->decremented_tickets = array(); |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - |
|
| 565 | - /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
| 566 | - |
|
| 567 | - |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * releases reserved tickets for all registrations of an EE_Transaction |
|
| 571 | - * by default, will NOT release tickets for finalized transactions |
|
| 572 | - * |
|
| 573 | - * @param EE_Transaction $transaction |
|
| 574 | - * @return int |
|
| 575 | - * @throws EE_Error |
|
| 576 | - * @throws InvalidSessionDataException |
|
| 577 | - */ |
|
| 578 | - protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
| 579 | - { |
|
| 580 | - if (self::debug) { |
|
| 581 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 582 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
| 583 | - echo '<br /> . TXN status_ID: ' . $transaction->status_ID(); |
|
| 584 | - } |
|
| 585 | - // check if 'finalize_registration' step has been completed... |
|
| 586 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
| 587 | - if (self::debug) { |
|
| 588 | - // DEBUG LOG |
|
| 589 | - EEH_Debug_Tools::log( |
|
| 590 | - __CLASS__, |
|
| 591 | - __FUNCTION__, |
|
| 592 | - __LINE__, |
|
| 593 | - array('finalized' => $finalized), |
|
| 594 | - false, |
|
| 595 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 596 | - ); |
|
| 597 | - } |
|
| 598 | - // how many tickets were released |
|
| 599 | - $count = 0; |
|
| 600 | - if (self::debug) { |
|
| 601 | - echo '<br /> . . . TXN finalized: ' . $finalized; |
|
| 602 | - } |
|
| 603 | - $release_tickets_with_TXN_status = array( |
|
| 604 | - EEM_Transaction::failed_status_code, |
|
| 605 | - EEM_Transaction::abandoned_status_code, |
|
| 606 | - EEM_Transaction::incomplete_status_code, |
|
| 607 | - ); |
|
| 608 | - $events = array(); |
|
| 609 | - // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
| 610 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 611 | - // cancel any reserved tickets for registrations that were not approved |
|
| 612 | - $registrations = $transaction->registrations(); |
|
| 613 | - if (self::debug) { |
|
| 614 | - echo '<br /> . . . # registrations: ' . count($registrations); |
|
| 615 | - $reg = reset($registrations); |
|
| 616 | - $ticket = $reg->ticket(); |
|
| 617 | - if ($ticket instanceof EE_Ticket) { |
|
| 618 | - $ticket->add_extra_meta( |
|
| 619 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 620 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
| 621 | - ); |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - if (! empty($registrations)) { |
|
| 625 | - foreach ($registrations as $registration) { |
|
| 626 | - if ( |
|
| 627 | - $registration instanceof EE_Registration |
|
| 628 | - && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
| 629 | - ) { |
|
| 630 | - $count++; |
|
| 631 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - } |
|
| 636 | - if ($events !== array()) { |
|
| 637 | - foreach ($events as $event) { |
|
| 638 | - /** @var EE_Event $event */ |
|
| 639 | - $event->perform_sold_out_status_check(); |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - return $count; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * releases reserved tickets for an EE_Registration |
|
| 649 | - * by default, will NOT release tickets for APPROVED registrations |
|
| 650 | - * |
|
| 651 | - * @param EE_Registration $registration |
|
| 652 | - * @param EE_Transaction $transaction |
|
| 653 | - * @return int |
|
| 654 | - * @throws EE_Error |
|
| 655 | - */ |
|
| 656 | - protected function _release_reserved_ticket_for_registration( |
|
| 657 | - EE_Registration $registration, |
|
| 658 | - EE_Transaction $transaction |
|
| 659 | - ) { |
|
| 660 | - $STS_ID = $transaction->status_ID(); |
|
| 661 | - if (self::debug) { |
|
| 662 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 663 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
| 664 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
| 665 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
| 666 | - } |
|
| 667 | - if ( |
|
| 668 | - // release Tickets for Failed Transactions and Abandoned Transactions |
|
| 669 | - $STS_ID === EEM_Transaction::failed_status_code |
|
| 670 | - || $STS_ID === EEM_Transaction::abandoned_status_code |
|
| 671 | - || ( |
|
| 672 | - // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
| 673 | - $STS_ID === EEM_Transaction::incomplete_status_code |
|
| 674 | - && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 675 | - ) |
|
| 676 | - ) { |
|
| 677 | - if (self::debug) { |
|
| 678 | - echo '<br /><br /> . . RELEASE RESERVED TICKET'; |
|
| 679 | - $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
| 680 | - echo '<br /> . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
| 681 | - var_dump($rsrvd); |
|
| 682 | - } |
|
| 683 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__); |
|
| 684 | - return 1; |
|
| 685 | - } |
|
| 686 | - return 0; |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - |
|
| 690 | - |
|
| 691 | - /********************************** SESSION_CART_RESET **********************************/ |
|
| 692 | - |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
| 697 | - * |
|
| 698 | - * @param EE_Session $session |
|
| 699 | - * @return void |
|
| 700 | - * @throws EE_Error |
|
| 701 | - * @throws InvalidArgumentException |
|
| 702 | - * @throws ReflectionException |
|
| 703 | - * @throws InvalidDataTypeException |
|
| 704 | - * @throws InvalidInterfaceException |
|
| 705 | - */ |
|
| 706 | - public static function session_cart_reset(EE_Session $session) |
|
| 707 | - { |
|
| 708 | - // don't release tickets if checkout was already reset |
|
| 709 | - if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) { |
|
| 710 | - return; |
|
| 711 | - } |
|
| 712 | - if (self::debug) { |
|
| 713 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 714 | - } |
|
| 715 | - // first check of the session has a valid Checkout object |
|
| 716 | - $checkout = $session->checkout(); |
|
| 717 | - if ($checkout instanceof EE_Checkout) { |
|
| 718 | - // and use that to clear ticket reservations because it will update the associated registration meta data |
|
| 719 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 720 | - return; |
|
| 721 | - } |
|
| 722 | - $cart = $session->cart(); |
|
| 723 | - if ($cart instanceof EE_Cart) { |
|
| 724 | - if (self::debug) { |
|
| 725 | - echo '<br /><br /> cart instance of EE_Cart: '; |
|
| 726 | - } |
|
| 727 | - EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
| 728 | - } else { |
|
| 729 | - if (self::debug) { |
|
| 730 | - echo '<br /><br /> invalid EE_Cart: '; |
|
| 731 | - var_export($cart, true); |
|
| 732 | - } |
|
| 733 | - } |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - |
|
| 738 | - /** |
|
| 739 | - * releases reserved tickets in the EE_Cart |
|
| 740 | - * |
|
| 741 | - * @param EE_Cart $cart |
|
| 742 | - * @return void |
|
| 743 | - * @throws EE_Error |
|
| 744 | - * @throws InvalidArgumentException |
|
| 745 | - * @throws ReflectionException |
|
| 746 | - * @throws InvalidDataTypeException |
|
| 747 | - * @throws InvalidInterfaceException |
|
| 748 | - */ |
|
| 749 | - protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
| 750 | - { |
|
| 751 | - if (self::debug) { |
|
| 752 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 753 | - } |
|
| 754 | - $ticket_line_items = $cart->get_tickets(); |
|
| 755 | - if (empty($ticket_line_items)) { |
|
| 756 | - return; |
|
| 757 | - } |
|
| 758 | - if (self::debug) { |
|
| 759 | - echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
| 760 | - } |
|
| 761 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 762 | - if (self::debug) { |
|
| 763 | - echo '<br /> . . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 764 | - } |
|
| 765 | - if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
| 766 | - if (self::debug) { |
|
| 767 | - echo '<br /> . . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 768 | - } |
|
| 769 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
| 770 | - if ($ticket instanceof EE_Ticket) { |
|
| 771 | - if (self::debug) { |
|
| 772 | - echo '<br /> . . . ticket->ID(): ' . $ticket->ID(); |
|
| 773 | - echo '<br /> . . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 774 | - } |
|
| 775 | - $ticket->add_extra_meta( |
|
| 776 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 777 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
| 778 | - ); |
|
| 779 | - $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
| 780 | - } |
|
| 781 | - } |
|
| 782 | - } |
|
| 783 | - if (self::debug) { |
|
| 784 | - echo '<br /><br /> RESET COMPLETED '; |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - |
|
| 789 | - |
|
| 790 | - /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
| 791 | - |
|
| 792 | - |
|
| 793 | - |
|
| 794 | - /** |
|
| 795 | - * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
| 796 | - * |
|
| 797 | - * @param EE_Session $session |
|
| 798 | - * @return void |
|
| 799 | - * @throws EE_Error |
|
| 800 | - * @throws InvalidSessionDataException |
|
| 801 | - */ |
|
| 802 | - public static function session_checkout_reset(EE_Session $session) |
|
| 803 | - { |
|
| 804 | - // don't release tickets if cart was already reset |
|
| 805 | - if(did_action('AHEE__EE_Session__reset_cart__before_reset')) { |
|
| 806 | - return; |
|
| 807 | - } |
|
| 808 | - $checkout = $session->checkout(); |
|
| 809 | - if ($checkout instanceof EE_Checkout) { |
|
| 810 | - EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 811 | - } |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - |
|
| 816 | - /** |
|
| 817 | - * releases reserved tickets for the EE_Checkout->transaction |
|
| 818 | - * |
|
| 819 | - * @param EE_Checkout $checkout |
|
| 820 | - * @return void |
|
| 821 | - * @throws EE_Error |
|
| 822 | - * @throws InvalidSessionDataException |
|
| 823 | - */ |
|
| 824 | - protected function _session_checkout_reset(EE_Checkout $checkout) |
|
| 825 | - { |
|
| 826 | - if (self::debug) { |
|
| 827 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 828 | - } |
|
| 829 | - // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
| 830 | - if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
| 831 | - return; |
|
| 832 | - } |
|
| 833 | - $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - |
|
| 837 | - |
|
| 838 | - /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
| 839 | - |
|
| 840 | - |
|
| 841 | - |
|
| 842 | - /** |
|
| 843 | - * @param EE_Session $session |
|
| 844 | - * @return void |
|
| 845 | - */ |
|
| 846 | - public static function session_expired_reset(EE_Session $session) |
|
| 847 | - { |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - |
|
| 851 | - |
|
| 852 | - /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
| 853 | - |
|
| 854 | - |
|
| 855 | - |
|
| 856 | - /** |
|
| 857 | - * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
| 858 | - * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
| 859 | - * |
|
| 860 | - * @param EE_Transaction $transaction |
|
| 861 | - * @return void |
|
| 862 | - * @throws EE_Error |
|
| 863 | - * @throws InvalidSessionDataException |
|
| 864 | - */ |
|
| 865 | - public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
| 866 | - { |
|
| 867 | - // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
| 868 | - if ($transaction->is_free() || $transaction->paid() > 0) { |
|
| 869 | - if (self::debug) { |
|
| 870 | - // DEBUG LOG |
|
| 871 | - EEH_Debug_Tools::log( |
|
| 872 | - __CLASS__, |
|
| 873 | - __FUNCTION__, |
|
| 874 | - __LINE__, |
|
| 875 | - array($transaction), |
|
| 876 | - false, |
|
| 877 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 878 | - ); |
|
| 879 | - } |
|
| 880 | - return; |
|
| 881 | - } |
|
| 882 | - // have their been any successful payments made ? |
|
| 883 | - $payments = $transaction->payments(); |
|
| 884 | - foreach ($payments as $payment) { |
|
| 885 | - if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
| 886 | - if (self::debug) { |
|
| 887 | - // DEBUG LOG |
|
| 888 | - EEH_Debug_Tools::log( |
|
| 889 | - __CLASS__, |
|
| 890 | - __FUNCTION__, |
|
| 891 | - __LINE__, |
|
| 892 | - array($payment), |
|
| 893 | - false, |
|
| 894 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 895 | - ); |
|
| 896 | - } |
|
| 897 | - return; |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - // since you haven't even attempted to pay for your ticket... |
|
| 901 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - |
|
| 905 | - |
|
| 906 | - /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
| 907 | - |
|
| 908 | - |
|
| 909 | - |
|
| 910 | - /** |
|
| 911 | - * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
| 912 | - * |
|
| 913 | - * @param EE_Transaction $transaction |
|
| 914 | - * @return void |
|
| 915 | - * @throws EE_Error |
|
| 916 | - * @throws InvalidSessionDataException |
|
| 917 | - */ |
|
| 918 | - public static function process_failed_transactions(EE_Transaction $transaction) |
|
| 919 | - { |
|
| 920 | - // since you haven't even attempted to pay for your ticket... |
|
| 921 | - EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - |
|
| 925 | - |
|
| 926 | - /********************************** RESET RESERVATION COUNTS *********************************/ |
|
| 927 | - |
|
| 928 | - |
|
| 929 | - |
|
| 930 | - /** |
|
| 931 | - * Resets all ticket and datetime reserved counts to zero |
|
| 932 | - * Tickets that are currently associated with a Transaction that is in progress |
|
| 933 | - * |
|
| 934 | - * @throws EE_Error |
|
| 935 | - * @throws DomainException |
|
| 936 | - * @throws InvalidDataTypeException |
|
| 937 | - * @throws InvalidInterfaceException |
|
| 938 | - * @throws InvalidArgumentException |
|
| 939 | - * @throws UnexpectedEntityException |
|
| 940 | - */ |
|
| 941 | - public static function reset_reservation_counts() |
|
| 942 | - { |
|
| 943 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 944 | - $valid_reserved_tickets = array(); |
|
| 945 | - /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
| 946 | - $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
| 947 | - foreach ($transactions_not_in_progress as $transaction) { |
|
| 948 | - // if this TXN has been fully completed, then skip it |
|
| 949 | - if ($transaction->reg_step_completed('finalize_registration')) { |
|
| 950 | - continue; |
|
| 951 | - } |
|
| 952 | - $total_line_item = $transaction->total_line_item(); |
|
| 953 | - // $transaction_in_progress->line |
|
| 954 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
| 955 | - throw new DomainException( |
|
| 956 | - esc_html__( |
|
| 957 | - 'Transaction does not have a valid Total Line Item associated with it.', |
|
| 958 | - 'event_espresso' |
|
| 959 | - ) |
|
| 960 | - ); |
|
| 961 | - } |
|
| 962 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 963 | - $total_line_item |
|
| 964 | - ); |
|
| 965 | - } |
|
| 966 | - $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
| 967 | - foreach ($total_line_items as $total_line_item) { |
|
| 968 | - $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 969 | - $total_line_item |
|
| 970 | - ); |
|
| 971 | - } |
|
| 972 | - $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
| 973 | - return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 974 | - $tickets_with_reservations, |
|
| 975 | - $valid_reserved_tickets, |
|
| 976 | - __FUNCTION__ |
|
| 977 | - ); |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * @param EE_Line_Item $total_line_item |
|
| 984 | - * @return EE_Line_Item[] |
|
| 985 | - */ |
|
| 986 | - private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
| 987 | - { |
|
| 988 | - /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 989 | - $valid_reserved_tickets = array(); |
|
| 990 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 991 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
| 992 | - if ($ticket_line_item instanceof EE_Line_Item) { |
|
| 993 | - $valid_reserved_tickets[] = $ticket_line_item; |
|
| 994 | - } |
|
| 995 | - } |
|
| 996 | - return $valid_reserved_tickets; |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - |
|
| 1000 | - |
|
| 1001 | - /** |
|
| 1002 | - * @param EE_Ticket[] $tickets_with_reservations |
|
| 1003 | - * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
| 1004 | - * @return int |
|
| 1005 | - * @throws UnexpectedEntityException |
|
| 1006 | - * @throws DomainException |
|
| 1007 | - * @throws EE_Error |
|
| 1008 | - */ |
|
| 1009 | - private static function release_reservations_for_tickets( |
|
| 1010 | - array $tickets_with_reservations, |
|
| 1011 | - array $valid_reserved_ticket_line_items = array(), |
|
| 1012 | - $source |
|
| 1013 | - ) { |
|
| 1014 | - $total_tickets_released = 0; |
|
| 1015 | - $sold_out_events = array(); |
|
| 1016 | - foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
| 1017 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1018 | - continue; |
|
| 1019 | - } |
|
| 1020 | - $reserved_qty = $ticket_with_reservations->reserved(); |
|
| 1021 | - foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
| 1022 | - if ( |
|
| 1023 | - $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
| 1024 | - && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
| 1025 | - ) { |
|
| 1026 | - $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
| 1027 | - } |
|
| 1028 | - } |
|
| 1029 | - if ($reserved_qty > 0) { |
|
| 1030 | - $ticket_with_reservations->add_extra_meta( |
|
| 1031 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 1032 | - __LINE__ . ') ' . $source . '()' |
|
| 1033 | - ); |
|
| 1034 | - $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 1035 | - $ticket_with_reservations->save(); |
|
| 1036 | - $total_tickets_released += $reserved_qty; |
|
| 1037 | - $event = $ticket_with_reservations->get_related_event(); |
|
| 1038 | - // track sold out events |
|
| 1039 | - if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
| 1040 | - $sold_out_events[] = $event; |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - } |
|
| 1044 | - // double check whether sold out events should remain sold out after releasing tickets |
|
| 1045 | - if($sold_out_events !== array()){ |
|
| 1046 | - foreach ($sold_out_events as $sold_out_event) { |
|
| 1047 | - /** @var EE_Event $sold_out_event */ |
|
| 1048 | - $sold_out_event->perform_sold_out_status_check(); |
|
| 1049 | - } |
|
| 1050 | - } |
|
| 1051 | - return $total_tickets_released; |
|
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - |
|
| 1055 | - |
|
| 1056 | - /********************************** SHUTDOWN **********************************/ |
|
| 1057 | - |
|
| 1058 | - |
|
| 1059 | - |
|
| 1060 | - /** |
|
| 1061 | - * @return false|int |
|
| 1062 | - * @throws EE_Error |
|
| 1063 | - * @throws InvalidArgumentException |
|
| 1064 | - * @throws InvalidDataTypeException |
|
| 1065 | - * @throws InvalidInterfaceException |
|
| 1066 | - */ |
|
| 1067 | - public static function clear_expired_line_items_with_no_transaction() |
|
| 1068 | - { |
|
| 1069 | - /** @type WPDB $wpdb */ |
|
| 1070 | - global $wpdb; |
|
| 1071 | - return $wpdb->query( |
|
| 1072 | - $wpdb->prepare( |
|
| 1073 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 26 | + const debug = false; // true false |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * an array of raw ticket data from EED_Ticket_Selector |
|
| 30 | + * |
|
| 31 | + * @var array $ticket_selections |
|
| 32 | + */ |
|
| 33 | + protected $ticket_selections = array(); |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * the raw ticket data from EED_Ticket_Selector is organized in rows |
|
| 37 | + * according to how they are displayed in the actual Ticket_Selector |
|
| 38 | + * this tracks the current row being processed |
|
| 39 | + * |
|
| 40 | + * @var int $current_row |
|
| 41 | + */ |
|
| 42 | + protected $current_row = 0; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * an array for tracking names of tickets that have sold out |
|
| 46 | + * |
|
| 47 | + * @var array $sold_out_tickets |
|
| 48 | + */ |
|
| 49 | + protected $sold_out_tickets = array(); |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * an array for tracking names of tickets that have had their quantities reduced |
|
| 53 | + * |
|
| 54 | + * @var array $decremented_tickets |
|
| 55 | + */ |
|
| 56 | + protected $decremented_tickets = array(); |
|
| 57 | + |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 62 | + * |
|
| 63 | + * @return void |
|
| 64 | + */ |
|
| 65 | + public static function set_hooks() |
|
| 66 | + { |
|
| 67 | + // release tickets for expired carts |
|
| 68 | + add_action( |
|
| 69 | + 'EED_Ticket_Selector__process_ticket_selections__before', |
|
| 70 | + array('EED_Ticket_Sales_Monitor', 'release_tickets_for_expired_carts'), |
|
| 71 | + 1 |
|
| 72 | + ); |
|
| 73 | + // check ticket reserves AFTER MER does it's check (hence priority 20) |
|
| 74 | + add_filter( |
|
| 75 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', |
|
| 76 | + array('EED_Ticket_Sales_Monitor', 'validate_ticket_sale'), |
|
| 77 | + 20, |
|
| 78 | + 3 |
|
| 79 | + ); |
|
| 80 | + // add notices for sold out tickets |
|
| 81 | + add_action( |
|
| 82 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
| 83 | + array('EED_Ticket_Sales_Monitor', 'post_notices'), |
|
| 84 | + 10 |
|
| 85 | + ); |
|
| 86 | + // handle ticket quantities adjusted in cart |
|
| 87 | + //add_action( |
|
| 88 | + // 'FHEE__EED_Multi_Event_Registration__adjust_line_item_quantity__line_item_quantity_updated', |
|
| 89 | + // array( 'EED_Ticket_Sales_Monitor', 'ticket_quantity_updated' ), |
|
| 90 | + // 10, 2 |
|
| 91 | + //); |
|
| 92 | + // handle tickets deleted from cart |
|
| 93 | + add_action( |
|
| 94 | + 'FHEE__EED_Multi_Event_Registration__delete_ticket__ticket_removed_from_cart', |
|
| 95 | + array('EED_Ticket_Sales_Monitor', 'ticket_removed_from_cart'), |
|
| 96 | + 10, |
|
| 97 | + 2 |
|
| 98 | + ); |
|
| 99 | + // handle emptied carts |
|
| 100 | + add_action( |
|
| 101 | + 'AHEE__EE_Session__reset_cart__before_reset', |
|
| 102 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 103 | + 10, |
|
| 104 | + 1 |
|
| 105 | + ); |
|
| 106 | + add_action( |
|
| 107 | + 'AHEE__EED_Multi_Event_Registration__empty_event_cart__before_delete_cart', |
|
| 108 | + array('EED_Ticket_Sales_Monitor', 'session_cart_reset'), |
|
| 109 | + 10, |
|
| 110 | + 1 |
|
| 111 | + ); |
|
| 112 | + // handle cancelled registrations |
|
| 113 | + add_action( |
|
| 114 | + 'AHEE__EE_Session__reset_checkout__before_reset', |
|
| 115 | + array('EED_Ticket_Sales_Monitor', 'session_checkout_reset'), |
|
| 116 | + 10, |
|
| 117 | + 1 |
|
| 118 | + ); |
|
| 119 | + // cron tasks |
|
| 120 | + add_action( |
|
| 121 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__abandoned_transaction', |
|
| 122 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 123 | + 10, |
|
| 124 | + 1 |
|
| 125 | + ); |
|
| 126 | + add_action( |
|
| 127 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__incomplete_transaction', |
|
| 128 | + array('EED_Ticket_Sales_Monitor', 'process_abandoned_transactions'), |
|
| 129 | + 10, |
|
| 130 | + 1 |
|
| 131 | + ); |
|
| 132 | + add_action( |
|
| 133 | + 'AHEE__EE_Cron_Tasks__process_expired_transactions__failed_transaction', |
|
| 134 | + array('EED_Ticket_Sales_Monitor', 'process_failed_transactions'), |
|
| 135 | + 10, |
|
| 136 | + 1 |
|
| 137 | + ); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 144 | + * |
|
| 145 | + * @return void |
|
| 146 | + */ |
|
| 147 | + public static function set_hooks_admin() |
|
| 148 | + { |
|
| 149 | + EED_Ticket_Sales_Monitor::set_hooks(); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @return EED_Ticket_Sales_Monitor|EED_Module |
|
| 156 | + */ |
|
| 157 | + public static function instance() |
|
| 158 | + { |
|
| 159 | + return parent::get_instance(__CLASS__); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param WP_Query $WP_Query |
|
| 166 | + * @return void |
|
| 167 | + */ |
|
| 168 | + public function run($WP_Query) |
|
| 169 | + { |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /********************************** PRE_TICKET_SALES **********************************/ |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Retrieves grand totals from the line items that have no TXN ID |
|
| 180 | + * and timestamps less than the current time minus the session lifespan. |
|
| 181 | + * These are carts that have been abandoned before the "registrant" even attempted to checkout. |
|
| 182 | + * We're going to release the tickets for these line items before attempting to add more to the cart. |
|
| 183 | + * |
|
| 184 | + * @return void |
|
| 185 | + * @throws DomainException |
|
| 186 | + * @throws EE_Error |
|
| 187 | + * @throws InvalidArgumentException |
|
| 188 | + * @throws InvalidDataTypeException |
|
| 189 | + * @throws InvalidInterfaceException |
|
| 190 | + * @throws UnexpectedEntityException |
|
| 191 | + */ |
|
| 192 | + public static function release_tickets_for_expired_carts() |
|
| 193 | + { |
|
| 194 | + do_action('AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__begin'); |
|
| 195 | + $expired_ticket_IDs = array(); |
|
| 196 | + $valid_ticket_line_items = array(); |
|
| 197 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_with_no_transaction(); |
|
| 198 | + if (empty($total_line_items)) { |
|
| 199 | + do_action( |
|
| 200 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 201 | + $total_line_items, |
|
| 202 | + $valid_ticket_line_items, |
|
| 203 | + $expired_ticket_IDs |
|
| 204 | + ); |
|
| 205 | + return; |
|
| 206 | + } |
|
| 207 | + $expired = current_time('timestamp') - EE_Registry::instance()->SSN->lifespan(); |
|
| 208 | + foreach ($total_line_items as $total_line_item) { |
|
| 209 | + /** @var EE_Line_Item $total_line_item */ |
|
| 210 | + $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
|
| 211 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 212 | + if (! $ticket_line_item instanceof EE_Line_Item) { |
|
| 213 | + continue; |
|
| 214 | + } |
|
| 215 | + if ($total_line_item->timestamp(true) <= $expired) { |
|
| 216 | + $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID(); |
|
| 217 | + } else { |
|
| 218 | + $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item; |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + if (! empty($expired_ticket_IDs)) { |
|
| 223 | + EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 224 | + \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
|
| 225 | + $valid_ticket_line_items, |
|
| 226 | + __FUNCTION__ |
|
| 227 | + ); |
|
| 228 | + // let's get rid of expired line items so that they can't interfere with tracking |
|
| 229 | + add_action( |
|
| 230 | + 'shutdown', |
|
| 231 | + array('EED_Ticket_Sales_Monitor', 'clear_expired_line_items_with_no_transaction'), |
|
| 232 | + 999 |
|
| 233 | + ); |
|
| 234 | + } |
|
| 235 | + do_action( |
|
| 236 | + 'AHEE__EED_Ticket_Sales_Monitor__release_tickets_for_expired_carts__end', |
|
| 237 | + $total_line_items, |
|
| 238 | + $valid_ticket_line_items, |
|
| 239 | + $expired_ticket_IDs |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /********************************** VALIDATE_TICKET_SALE **********************************/ |
|
| 246 | + |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * callback for 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data' |
|
| 251 | + * |
|
| 252 | + * @param int $qty |
|
| 253 | + * @param EE_Ticket $ticket |
|
| 254 | + * @return bool |
|
| 255 | + * @throws UnexpectedEntityException |
|
| 256 | + * @throws EE_Error |
|
| 257 | + */ |
|
| 258 | + public static function validate_ticket_sale($qty = 1, EE_Ticket $ticket) |
|
| 259 | + { |
|
| 260 | + $qty = absint($qty); |
|
| 261 | + if ($qty > 0) { |
|
| 262 | + $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
|
| 263 | + } |
|
| 264 | + if (self::debug) { |
|
| 265 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 266 | + echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 267 | + } |
|
| 268 | + return $qty; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * checks whether an individual ticket is available for purchase based on datetime, and ticket details |
|
| 275 | + * |
|
| 276 | + * @param EE_Ticket $ticket |
|
| 277 | + * @param int $qty |
|
| 278 | + * @return int |
|
| 279 | + * @throws UnexpectedEntityException |
|
| 280 | + * @throws EE_Error |
|
| 281 | + */ |
|
| 282 | + protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
|
| 283 | + { |
|
| 284 | + if (self::debug) { |
|
| 285 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 286 | + } |
|
| 287 | + if (! $ticket instanceof EE_Ticket) { |
|
| 288 | + return 0; |
|
| 289 | + } |
|
| 290 | + if (self::debug) { |
|
| 291 | + echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 292 | + echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
| 293 | + } |
|
| 294 | + $ticket->refresh_from_db(); |
|
| 295 | + // first let's determine the ticket availability based on sales |
|
| 296 | + $available = $ticket->qty('saleable'); |
|
| 297 | + if (self::debug) { |
|
| 298 | + echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
| 299 | + echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
| 300 | + echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 301 | + echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 302 | + echo '<br /> . . . available: ' . $available; |
|
| 303 | + } |
|
| 304 | + if ($available < 1) { |
|
| 305 | + $this->_ticket_sold_out($ticket); |
|
| 306 | + return 0; |
|
| 307 | + } |
|
| 308 | + if (self::debug) { |
|
| 309 | + echo '<br /> . . . qty: ' . $qty; |
|
| 310 | + } |
|
| 311 | + if ($available < $qty) { |
|
| 312 | + $qty = $available; |
|
| 313 | + if (self::debug) { |
|
| 314 | + echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
| 315 | + } |
|
| 316 | + $this->_ticket_quantity_decremented($ticket); |
|
| 317 | + } |
|
| 318 | + $this->_reserve_ticket($ticket, $qty); |
|
| 319 | + return $qty; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + |
|
| 323 | + |
|
| 324 | + /** |
|
| 325 | + * increments ticket reserved based on quantity passed |
|
| 326 | + * |
|
| 327 | + * @param EE_Ticket $ticket |
|
| 328 | + * @param int $quantity |
|
| 329 | + * @return bool |
|
| 330 | + * @throws EE_Error |
|
| 331 | + */ |
|
| 332 | + protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 333 | + { |
|
| 334 | + if (self::debug) { |
|
| 335 | + echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
| 336 | + } |
|
| 337 | + $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__); |
|
| 338 | + return $ticket->save(); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * @param EE_Ticket $ticket |
|
| 345 | + * @param int $quantity |
|
| 346 | + * @return bool |
|
| 347 | + * @throws EE_Error |
|
| 348 | + */ |
|
| 349 | + protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
|
| 350 | + { |
|
| 351 | + if (self::debug) { |
|
| 352 | + echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
| 353 | + echo '<br /> . . . ticket->reserved before: ' . $ticket->reserved(); |
|
| 354 | + } |
|
| 355 | + $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 356 | + if (self::debug) { |
|
| 357 | + echo '<br /> . . . ticket->reserved after: ' . $ticket->reserved(); |
|
| 358 | + } |
|
| 359 | + return $ticket->save() ? 1 : 0; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * removes quantities within the ticket selector based on zero ticket availability |
|
| 366 | + * |
|
| 367 | + * @param EE_Ticket $ticket |
|
| 368 | + * @return void |
|
| 369 | + * @throws UnexpectedEntityException |
|
| 370 | + * @throws EE_Error |
|
| 371 | + */ |
|
| 372 | + protected function _ticket_sold_out(EE_Ticket $ticket) |
|
| 373 | + { |
|
| 374 | + if (self::debug) { |
|
| 375 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 376 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 377 | + } |
|
| 378 | + $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * adjusts quantities within the ticket selector based on decreased ticket availability |
|
| 385 | + * |
|
| 386 | + * @param EE_Ticket $ticket |
|
| 387 | + * @return void |
|
| 388 | + * @throws UnexpectedEntityException |
|
| 389 | + * @throws EE_Error |
|
| 390 | + */ |
|
| 391 | + protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
|
| 392 | + { |
|
| 393 | + if (self::debug) { |
|
| 394 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 395 | + echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 396 | + } |
|
| 397 | + $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * builds string out of ticket and event name |
|
| 404 | + * |
|
| 405 | + * @param EE_Ticket $ticket |
|
| 406 | + * @return string |
|
| 407 | + * @throws UnexpectedEntityException |
|
| 408 | + * @throws EE_Error |
|
| 409 | + */ |
|
| 410 | + protected function _get_ticket_and_event_name(EE_Ticket $ticket) |
|
| 411 | + { |
|
| 412 | + $event = $ticket->get_related_event(); |
|
| 413 | + if ($event instanceof EE_Event) { |
|
| 414 | + $ticket_name = sprintf( |
|
| 415 | + _x('%1$s for %2$s', 'ticket name for event name', 'event_espresso'), |
|
| 416 | + $ticket->name(), |
|
| 417 | + $event->name() |
|
| 418 | + ); |
|
| 419 | + } else { |
|
| 420 | + $ticket_name = $ticket->name(); |
|
| 421 | + } |
|
| 422 | + return $ticket_name; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + |
|
| 426 | + |
|
| 427 | + /********************************** EVENT CART **********************************/ |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * releases or reserves ticket(s) based on quantity passed |
|
| 433 | + * |
|
| 434 | + * @param EE_Line_Item $line_item |
|
| 435 | + * @param int $quantity |
|
| 436 | + * @return void |
|
| 437 | + * @throws EE_Error |
|
| 438 | + * @throws InvalidArgumentException |
|
| 439 | + * @throws InvalidDataTypeException |
|
| 440 | + * @throws InvalidInterfaceException |
|
| 441 | + */ |
|
| 442 | + public static function ticket_quantity_updated(EE_Line_Item $line_item, $quantity = 1) |
|
| 443 | + { |
|
| 444 | + $ticket = EEM_Ticket::instance()->get_one_by_ID(absint($line_item->OBJ_ID())); |
|
| 445 | + if ($ticket instanceof EE_Ticket) { |
|
| 446 | + $ticket->add_extra_meta( |
|
| 447 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 448 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
| 449 | + ); |
|
| 450 | + if ($quantity > 0) { |
|
| 451 | + EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
|
| 452 | + } else { |
|
| 453 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 454 | + } |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * releases reserved ticket(s) based on quantity passed |
|
| 462 | + * |
|
| 463 | + * @param EE_Ticket $ticket |
|
| 464 | + * @param int $quantity |
|
| 465 | + * @return void |
|
| 466 | + * @throws EE_Error |
|
| 467 | + */ |
|
| 468 | + public static function ticket_removed_from_cart(EE_Ticket $ticket, $quantity = 1) |
|
| 469 | + { |
|
| 470 | + $ticket->add_extra_meta( |
|
| 471 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 472 | + __LINE__ . ') ' . __METHOD__ . '()' |
|
| 473 | + ); |
|
| 474 | + EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /********************************** POST_NOTICES **********************************/ |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * @return void |
|
| 485 | + * @throws EE_Error |
|
| 486 | + * @throws InvalidArgumentException |
|
| 487 | + * @throws ReflectionException |
|
| 488 | + * @throws InvalidDataTypeException |
|
| 489 | + * @throws InvalidInterfaceException |
|
| 490 | + */ |
|
| 491 | + public static function post_notices() |
|
| 492 | + { |
|
| 493 | + EED_Ticket_Sales_Monitor::instance()->_post_notices(); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * @return void |
|
| 500 | + * @throws EE_Error |
|
| 501 | + * @throws InvalidArgumentException |
|
| 502 | + * @throws ReflectionException |
|
| 503 | + * @throws InvalidDataTypeException |
|
| 504 | + * @throws InvalidInterfaceException |
|
| 505 | + */ |
|
| 506 | + protected function _post_notices() |
|
| 507 | + { |
|
| 508 | + if (self::debug) { |
|
| 509 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 510 | + } |
|
| 511 | + $refresh_msg = ''; |
|
| 512 | + $none_added_msg = ''; |
|
| 513 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
| 514 | + $refresh_msg = __( |
|
| 515 | + 'Please refresh the page to view updated ticket quantities.', |
|
| 516 | + 'event_espresso' |
|
| 517 | + ); |
|
| 518 | + $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
|
| 519 | + } |
|
| 520 | + if (! empty($this->sold_out_tickets)) { |
|
| 521 | + EE_Error::add_attention( |
|
| 522 | + sprintf( |
|
| 523 | + apply_filters( |
|
| 524 | + 'FHEE__EED_Ticket_Sales_Monitor___post_notices__sold_out_tickets_notice', |
|
| 525 | + __( |
|
| 526 | + 'We\'re sorry...%1$sThe following items have sold out since you first viewed this page, and can no longer be registered for:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 527 | + 'event_espresso' |
|
| 528 | + ) |
|
| 529 | + ), |
|
| 530 | + '<br />', |
|
| 531 | + implode('<br />', $this->sold_out_tickets), |
|
| 532 | + $none_added_msg, |
|
| 533 | + $refresh_msg |
|
| 534 | + ) |
|
| 535 | + ); |
|
| 536 | + // alter code flow in the Ticket Selector for better UX |
|
| 537 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', '__return_true'); |
|
| 538 | + add_filter('FHEE__EED_Ticket_Selector__process_ticket_selections__success', '__return_false'); |
|
| 539 | + $this->sold_out_tickets = array(); |
|
| 540 | + // and reset the cart |
|
| 541 | + EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
|
| 542 | + } |
|
| 543 | + if (! empty($this->decremented_tickets)) { |
|
| 544 | + EE_Error::add_attention( |
|
| 545 | + sprintf( |
|
| 546 | + apply_filters( |
|
| 547 | + 'FHEE__EED_Ticket_Sales_Monitor___ticket_quantity_decremented__notice', |
|
| 548 | + __( |
|
| 549 | + 'We\'re sorry...%1$sDue to sales that have occurred since you first viewed the last page, the following items have had their quantities adjusted to match the current available amount:%1$s%1$s%2$s%1$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%1$s%1$s%3$s%1$s%4$s%1$s', |
|
| 550 | + 'event_espresso' |
|
| 551 | + ) |
|
| 552 | + ), |
|
| 553 | + '<br />', |
|
| 554 | + implode('<br />', $this->decremented_tickets), |
|
| 555 | + $none_added_msg, |
|
| 556 | + $refresh_msg |
|
| 557 | + ) |
|
| 558 | + ); |
|
| 559 | + $this->decremented_tickets = array(); |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + |
|
| 565 | + /********************************** RELEASE_ALL_RESERVED_TICKETS_FOR_TRANSACTION **********************************/ |
|
| 566 | + |
|
| 567 | + |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * releases reserved tickets for all registrations of an EE_Transaction |
|
| 571 | + * by default, will NOT release tickets for finalized transactions |
|
| 572 | + * |
|
| 573 | + * @param EE_Transaction $transaction |
|
| 574 | + * @return int |
|
| 575 | + * @throws EE_Error |
|
| 576 | + * @throws InvalidSessionDataException |
|
| 577 | + */ |
|
| 578 | + protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
|
| 579 | + { |
|
| 580 | + if (self::debug) { |
|
| 581 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 582 | + echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
| 583 | + echo '<br /> . TXN status_ID: ' . $transaction->status_ID(); |
|
| 584 | + } |
|
| 585 | + // check if 'finalize_registration' step has been completed... |
|
| 586 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
| 587 | + if (self::debug) { |
|
| 588 | + // DEBUG LOG |
|
| 589 | + EEH_Debug_Tools::log( |
|
| 590 | + __CLASS__, |
|
| 591 | + __FUNCTION__, |
|
| 592 | + __LINE__, |
|
| 593 | + array('finalized' => $finalized), |
|
| 594 | + false, |
|
| 595 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 596 | + ); |
|
| 597 | + } |
|
| 598 | + // how many tickets were released |
|
| 599 | + $count = 0; |
|
| 600 | + if (self::debug) { |
|
| 601 | + echo '<br /> . . . TXN finalized: ' . $finalized; |
|
| 602 | + } |
|
| 603 | + $release_tickets_with_TXN_status = array( |
|
| 604 | + EEM_Transaction::failed_status_code, |
|
| 605 | + EEM_Transaction::abandoned_status_code, |
|
| 606 | + EEM_Transaction::incomplete_status_code, |
|
| 607 | + ); |
|
| 608 | + $events = array(); |
|
| 609 | + // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
|
| 610 | + if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 611 | + // cancel any reserved tickets for registrations that were not approved |
|
| 612 | + $registrations = $transaction->registrations(); |
|
| 613 | + if (self::debug) { |
|
| 614 | + echo '<br /> . . . # registrations: ' . count($registrations); |
|
| 615 | + $reg = reset($registrations); |
|
| 616 | + $ticket = $reg->ticket(); |
|
| 617 | + if ($ticket instanceof EE_Ticket) { |
|
| 618 | + $ticket->add_extra_meta( |
|
| 619 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 620 | + __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
| 621 | + ); |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + if (! empty($registrations)) { |
|
| 625 | + foreach ($registrations as $registration) { |
|
| 626 | + if ( |
|
| 627 | + $registration instanceof EE_Registration |
|
| 628 | + && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
|
| 629 | + ) { |
|
| 630 | + $count++; |
|
| 631 | + $events[ $registration->event_ID() ] = $registration->event(); |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | + if ($events !== array()) { |
|
| 637 | + foreach ($events as $event) { |
|
| 638 | + /** @var EE_Event $event */ |
|
| 639 | + $event->perform_sold_out_status_check(); |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + return $count; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * releases reserved tickets for an EE_Registration |
|
| 649 | + * by default, will NOT release tickets for APPROVED registrations |
|
| 650 | + * |
|
| 651 | + * @param EE_Registration $registration |
|
| 652 | + * @param EE_Transaction $transaction |
|
| 653 | + * @return int |
|
| 654 | + * @throws EE_Error |
|
| 655 | + */ |
|
| 656 | + protected function _release_reserved_ticket_for_registration( |
|
| 657 | + EE_Registration $registration, |
|
| 658 | + EE_Transaction $transaction |
|
| 659 | + ) { |
|
| 660 | + $STS_ID = $transaction->status_ID(); |
|
| 661 | + if (self::debug) { |
|
| 662 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 663 | + echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
| 664 | + echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
| 665 | + echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
| 666 | + } |
|
| 667 | + if ( |
|
| 668 | + // release Tickets for Failed Transactions and Abandoned Transactions |
|
| 669 | + $STS_ID === EEM_Transaction::failed_status_code |
|
| 670 | + || $STS_ID === EEM_Transaction::abandoned_status_code |
|
| 671 | + || ( |
|
| 672 | + // also release Tickets for Incomplete Transactions, but ONLY if the Registrations are NOT Approved |
|
| 673 | + $STS_ID === EEM_Transaction::incomplete_status_code |
|
| 674 | + && $registration->status_ID() !== EEM_Registration::status_id_approved |
|
| 675 | + ) |
|
| 676 | + ) { |
|
| 677 | + if (self::debug) { |
|
| 678 | + echo '<br /><br /> . . RELEASE RESERVED TICKET'; |
|
| 679 | + $rsrvd = $registration->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true); |
|
| 680 | + echo '<br /> . . . registration HAS_RESERVED_TICKET_KEY: '; |
|
| 681 | + var_dump($rsrvd); |
|
| 682 | + } |
|
| 683 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__); |
|
| 684 | + return 1; |
|
| 685 | + } |
|
| 686 | + return 0; |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + |
|
| 690 | + |
|
| 691 | + /********************************** SESSION_CART_RESET **********************************/ |
|
| 692 | + |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * callback hooked into 'AHEE__EE_Session__reset_cart__before_reset' |
|
| 697 | + * |
|
| 698 | + * @param EE_Session $session |
|
| 699 | + * @return void |
|
| 700 | + * @throws EE_Error |
|
| 701 | + * @throws InvalidArgumentException |
|
| 702 | + * @throws ReflectionException |
|
| 703 | + * @throws InvalidDataTypeException |
|
| 704 | + * @throws InvalidInterfaceException |
|
| 705 | + */ |
|
| 706 | + public static function session_cart_reset(EE_Session $session) |
|
| 707 | + { |
|
| 708 | + // don't release tickets if checkout was already reset |
|
| 709 | + if (did_action('AHEE__EE_Session__reset_checkout__before_reset')) { |
|
| 710 | + return; |
|
| 711 | + } |
|
| 712 | + if (self::debug) { |
|
| 713 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 714 | + } |
|
| 715 | + // first check of the session has a valid Checkout object |
|
| 716 | + $checkout = $session->checkout(); |
|
| 717 | + if ($checkout instanceof EE_Checkout) { |
|
| 718 | + // and use that to clear ticket reservations because it will update the associated registration meta data |
|
| 719 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 720 | + return; |
|
| 721 | + } |
|
| 722 | + $cart = $session->cart(); |
|
| 723 | + if ($cart instanceof EE_Cart) { |
|
| 724 | + if (self::debug) { |
|
| 725 | + echo '<br /><br /> cart instance of EE_Cart: '; |
|
| 726 | + } |
|
| 727 | + EED_Ticket_Sales_Monitor::instance()->_session_cart_reset($cart, $session); |
|
| 728 | + } else { |
|
| 729 | + if (self::debug) { |
|
| 730 | + echo '<br /><br /> invalid EE_Cart: '; |
|
| 731 | + var_export($cart, true); |
|
| 732 | + } |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + |
|
| 738 | + /** |
|
| 739 | + * releases reserved tickets in the EE_Cart |
|
| 740 | + * |
|
| 741 | + * @param EE_Cart $cart |
|
| 742 | + * @return void |
|
| 743 | + * @throws EE_Error |
|
| 744 | + * @throws InvalidArgumentException |
|
| 745 | + * @throws ReflectionException |
|
| 746 | + * @throws InvalidDataTypeException |
|
| 747 | + * @throws InvalidInterfaceException |
|
| 748 | + */ |
|
| 749 | + protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
|
| 750 | + { |
|
| 751 | + if (self::debug) { |
|
| 752 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 753 | + } |
|
| 754 | + $ticket_line_items = $cart->get_tickets(); |
|
| 755 | + if (empty($ticket_line_items)) { |
|
| 756 | + return; |
|
| 757 | + } |
|
| 758 | + if (self::debug) { |
|
| 759 | + echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
| 760 | + } |
|
| 761 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 762 | + if (self::debug) { |
|
| 763 | + echo '<br /> . . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 764 | + } |
|
| 765 | + if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
|
| 766 | + if (self::debug) { |
|
| 767 | + echo '<br /> . . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 768 | + } |
|
| 769 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
|
| 770 | + if ($ticket instanceof EE_Ticket) { |
|
| 771 | + if (self::debug) { |
|
| 772 | + echo '<br /> . . . ticket->ID(): ' . $ticket->ID(); |
|
| 773 | + echo '<br /> . . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 774 | + } |
|
| 775 | + $ticket->add_extra_meta( |
|
| 776 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 777 | + __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
| 778 | + ); |
|
| 779 | + $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
|
| 780 | + } |
|
| 781 | + } |
|
| 782 | + } |
|
| 783 | + if (self::debug) { |
|
| 784 | + echo '<br /><br /> RESET COMPLETED '; |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + |
|
| 789 | + |
|
| 790 | + /********************************** SESSION_CHECKOUT_RESET **********************************/ |
|
| 791 | + |
|
| 792 | + |
|
| 793 | + |
|
| 794 | + /** |
|
| 795 | + * callback hooked into 'AHEE__EE_Session__reset_checkout__before_reset' |
|
| 796 | + * |
|
| 797 | + * @param EE_Session $session |
|
| 798 | + * @return void |
|
| 799 | + * @throws EE_Error |
|
| 800 | + * @throws InvalidSessionDataException |
|
| 801 | + */ |
|
| 802 | + public static function session_checkout_reset(EE_Session $session) |
|
| 803 | + { |
|
| 804 | + // don't release tickets if cart was already reset |
|
| 805 | + if(did_action('AHEE__EE_Session__reset_cart__before_reset')) { |
|
| 806 | + return; |
|
| 807 | + } |
|
| 808 | + $checkout = $session->checkout(); |
|
| 809 | + if ($checkout instanceof EE_Checkout) { |
|
| 810 | + EED_Ticket_Sales_Monitor::instance()->_session_checkout_reset($checkout); |
|
| 811 | + } |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + |
|
| 816 | + /** |
|
| 817 | + * releases reserved tickets for the EE_Checkout->transaction |
|
| 818 | + * |
|
| 819 | + * @param EE_Checkout $checkout |
|
| 820 | + * @return void |
|
| 821 | + * @throws EE_Error |
|
| 822 | + * @throws InvalidSessionDataException |
|
| 823 | + */ |
|
| 824 | + protected function _session_checkout_reset(EE_Checkout $checkout) |
|
| 825 | + { |
|
| 826 | + if (self::debug) { |
|
| 827 | + echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 828 | + } |
|
| 829 | + // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
|
| 830 | + if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
|
| 831 | + return; |
|
| 832 | + } |
|
| 833 | + $this->_release_all_reserved_tickets_for_transaction($checkout->transaction); |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + |
|
| 837 | + |
|
| 838 | + /********************************** SESSION_EXPIRED_RESET **********************************/ |
|
| 839 | + |
|
| 840 | + |
|
| 841 | + |
|
| 842 | + /** |
|
| 843 | + * @param EE_Session $session |
|
| 844 | + * @return void |
|
| 845 | + */ |
|
| 846 | + public static function session_expired_reset(EE_Session $session) |
|
| 847 | + { |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + |
|
| 851 | + |
|
| 852 | + /********************************** PROCESS_ABANDONED_TRANSACTIONS **********************************/ |
|
| 853 | + |
|
| 854 | + |
|
| 855 | + |
|
| 856 | + /** |
|
| 857 | + * releases reserved tickets for all registrations of an ABANDONED EE_Transaction |
|
| 858 | + * by default, will NOT release tickets for free transactions, or any that have received a payment |
|
| 859 | + * |
|
| 860 | + * @param EE_Transaction $transaction |
|
| 861 | + * @return void |
|
| 862 | + * @throws EE_Error |
|
| 863 | + * @throws InvalidSessionDataException |
|
| 864 | + */ |
|
| 865 | + public static function process_abandoned_transactions(EE_Transaction $transaction) |
|
| 866 | + { |
|
| 867 | + // is this TXN free or has any money been paid towards this TXN? If so, then leave it alone |
|
| 868 | + if ($transaction->is_free() || $transaction->paid() > 0) { |
|
| 869 | + if (self::debug) { |
|
| 870 | + // DEBUG LOG |
|
| 871 | + EEH_Debug_Tools::log( |
|
| 872 | + __CLASS__, |
|
| 873 | + __FUNCTION__, |
|
| 874 | + __LINE__, |
|
| 875 | + array($transaction), |
|
| 876 | + false, |
|
| 877 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 878 | + ); |
|
| 879 | + } |
|
| 880 | + return; |
|
| 881 | + } |
|
| 882 | + // have their been any successful payments made ? |
|
| 883 | + $payments = $transaction->payments(); |
|
| 884 | + foreach ($payments as $payment) { |
|
| 885 | + if ($payment instanceof EE_Payment && $payment->status() === EEM_Payment::status_id_approved) { |
|
| 886 | + if (self::debug) { |
|
| 887 | + // DEBUG LOG |
|
| 888 | + EEH_Debug_Tools::log( |
|
| 889 | + __CLASS__, |
|
| 890 | + __FUNCTION__, |
|
| 891 | + __LINE__, |
|
| 892 | + array($payment), |
|
| 893 | + false, |
|
| 894 | + 'EE_Transaction: ' . $transaction->ID() |
|
| 895 | + ); |
|
| 896 | + } |
|
| 897 | + return; |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + // since you haven't even attempted to pay for your ticket... |
|
| 901 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + |
|
| 905 | + |
|
| 906 | + /********************************** PROCESS_FAILED_TRANSACTIONS **********************************/ |
|
| 907 | + |
|
| 908 | + |
|
| 909 | + |
|
| 910 | + /** |
|
| 911 | + * releases reserved tickets for absolutely ALL registrations of a FAILED EE_Transaction |
|
| 912 | + * |
|
| 913 | + * @param EE_Transaction $transaction |
|
| 914 | + * @return void |
|
| 915 | + * @throws EE_Error |
|
| 916 | + * @throws InvalidSessionDataException |
|
| 917 | + */ |
|
| 918 | + public static function process_failed_transactions(EE_Transaction $transaction) |
|
| 919 | + { |
|
| 920 | + // since you haven't even attempted to pay for your ticket... |
|
| 921 | + EED_Ticket_Sales_Monitor::instance()->_release_all_reserved_tickets_for_transaction($transaction); |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + |
|
| 925 | + |
|
| 926 | + /********************************** RESET RESERVATION COUNTS *********************************/ |
|
| 927 | + |
|
| 928 | + |
|
| 929 | + |
|
| 930 | + /** |
|
| 931 | + * Resets all ticket and datetime reserved counts to zero |
|
| 932 | + * Tickets that are currently associated with a Transaction that is in progress |
|
| 933 | + * |
|
| 934 | + * @throws EE_Error |
|
| 935 | + * @throws DomainException |
|
| 936 | + * @throws InvalidDataTypeException |
|
| 937 | + * @throws InvalidInterfaceException |
|
| 938 | + * @throws InvalidArgumentException |
|
| 939 | + * @throws UnexpectedEntityException |
|
| 940 | + */ |
|
| 941 | + public static function reset_reservation_counts() |
|
| 942 | + { |
|
| 943 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 944 | + $valid_reserved_tickets = array(); |
|
| 945 | + /** @var EE_Transaction[] $transactions_not_in_progress */ |
|
| 946 | + $transactions_not_in_progress = EEM_Transaction::instance()->get_transactions_not_in_progress(); |
|
| 947 | + foreach ($transactions_not_in_progress as $transaction) { |
|
| 948 | + // if this TXN has been fully completed, then skip it |
|
| 949 | + if ($transaction->reg_step_completed('finalize_registration')) { |
|
| 950 | + continue; |
|
| 951 | + } |
|
| 952 | + $total_line_item = $transaction->total_line_item(); |
|
| 953 | + // $transaction_in_progress->line |
|
| 954 | + if (! $total_line_item instanceof EE_Line_Item) { |
|
| 955 | + throw new DomainException( |
|
| 956 | + esc_html__( |
|
| 957 | + 'Transaction does not have a valid Total Line Item associated with it.', |
|
| 958 | + 'event_espresso' |
|
| 959 | + ) |
|
| 960 | + ); |
|
| 961 | + } |
|
| 962 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 963 | + $total_line_item |
|
| 964 | + ); |
|
| 965 | + } |
|
| 966 | + $total_line_items = EEM_Line_Item::instance()->get_total_line_items_for_active_carts(); |
|
| 967 | + foreach ($total_line_items as $total_line_item) { |
|
| 968 | + $valid_reserved_tickets += EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total( |
|
| 969 | + $total_line_item |
|
| 970 | + ); |
|
| 971 | + } |
|
| 972 | + $tickets_with_reservations = EEM_Ticket::instance()->get_tickets_with_reservations(); |
|
| 973 | + return EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
|
| 974 | + $tickets_with_reservations, |
|
| 975 | + $valid_reserved_tickets, |
|
| 976 | + __FUNCTION__ |
|
| 977 | + ); |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * @param EE_Line_Item $total_line_item |
|
| 984 | + * @return EE_Line_Item[] |
|
| 985 | + */ |
|
| 986 | + private static function get_ticket_line_items_for_grand_total(EE_Line_Item $total_line_item) |
|
| 987 | + { |
|
| 988 | + /** @var EE_Line_Item[] $valid_reserved_tickets */ |
|
| 989 | + $valid_reserved_tickets = array(); |
|
| 990 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
| 991 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
| 992 | + if ($ticket_line_item instanceof EE_Line_Item) { |
|
| 993 | + $valid_reserved_tickets[] = $ticket_line_item; |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | + return $valid_reserved_tickets; |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + |
|
| 1000 | + |
|
| 1001 | + /** |
|
| 1002 | + * @param EE_Ticket[] $tickets_with_reservations |
|
| 1003 | + * @param EE_Line_Item[] $valid_reserved_ticket_line_items |
|
| 1004 | + * @return int |
|
| 1005 | + * @throws UnexpectedEntityException |
|
| 1006 | + * @throws DomainException |
|
| 1007 | + * @throws EE_Error |
|
| 1008 | + */ |
|
| 1009 | + private static function release_reservations_for_tickets( |
|
| 1010 | + array $tickets_with_reservations, |
|
| 1011 | + array $valid_reserved_ticket_line_items = array(), |
|
| 1012 | + $source |
|
| 1013 | + ) { |
|
| 1014 | + $total_tickets_released = 0; |
|
| 1015 | + $sold_out_events = array(); |
|
| 1016 | + foreach ($tickets_with_reservations as $ticket_with_reservations) { |
|
| 1017 | + if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1018 | + continue; |
|
| 1019 | + } |
|
| 1020 | + $reserved_qty = $ticket_with_reservations->reserved(); |
|
| 1021 | + foreach ($valid_reserved_ticket_line_items as $valid_reserved_ticket_line_item) { |
|
| 1022 | + if ( |
|
| 1023 | + $valid_reserved_ticket_line_item instanceof EE_Line_Item |
|
| 1024 | + && $valid_reserved_ticket_line_item->OBJ_ID() === $ticket_with_reservations->ID() |
|
| 1025 | + ) { |
|
| 1026 | + $reserved_qty -= $valid_reserved_ticket_line_item->quantity(); |
|
| 1027 | + } |
|
| 1028 | + } |
|
| 1029 | + if ($reserved_qty > 0) { |
|
| 1030 | + $ticket_with_reservations->add_extra_meta( |
|
| 1031 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 1032 | + __LINE__ . ') ' . $source . '()' |
|
| 1033 | + ); |
|
| 1034 | + $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 1035 | + $ticket_with_reservations->save(); |
|
| 1036 | + $total_tickets_released += $reserved_qty; |
|
| 1037 | + $event = $ticket_with_reservations->get_related_event(); |
|
| 1038 | + // track sold out events |
|
| 1039 | + if ($event instanceof EE_Event && $event->is_sold_out()) { |
|
| 1040 | + $sold_out_events[] = $event; |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + } |
|
| 1044 | + // double check whether sold out events should remain sold out after releasing tickets |
|
| 1045 | + if($sold_out_events !== array()){ |
|
| 1046 | + foreach ($sold_out_events as $sold_out_event) { |
|
| 1047 | + /** @var EE_Event $sold_out_event */ |
|
| 1048 | + $sold_out_event->perform_sold_out_status_check(); |
|
| 1049 | + } |
|
| 1050 | + } |
|
| 1051 | + return $total_tickets_released; |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + |
|
| 1055 | + |
|
| 1056 | + /********************************** SHUTDOWN **********************************/ |
|
| 1057 | + |
|
| 1058 | + |
|
| 1059 | + |
|
| 1060 | + /** |
|
| 1061 | + * @return false|int |
|
| 1062 | + * @throws EE_Error |
|
| 1063 | + * @throws InvalidArgumentException |
|
| 1064 | + * @throws InvalidDataTypeException |
|
| 1065 | + * @throws InvalidInterfaceException |
|
| 1066 | + */ |
|
| 1067 | + public static function clear_expired_line_items_with_no_transaction() |
|
| 1068 | + { |
|
| 1069 | + /** @type WPDB $wpdb */ |
|
| 1070 | + global $wpdb; |
|
| 1071 | + return $wpdb->query( |
|
| 1072 | + $wpdb->prepare( |
|
| 1073 | + 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 1074 | 1074 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
| 1075 | - // use GMT time because that's what LIN_timestamps are in |
|
| 1076 | - date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
|
| 1077 | - ) |
|
| 1078 | - ); |
|
| 1079 | - } |
|
| 1075 | + // use GMT time because that's what LIN_timestamps are in |
|
| 1076 | + date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
|
| 1077 | + ) |
|
| 1078 | + ); |
|
| 1079 | + } |
|
| 1080 | 1080 | |
| 1081 | 1081 | } |
| 1082 | 1082 | // End of file EED_Ticket_Sales_Monitor.module.php |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | class EED_Ticket_Sales_Monitor extends EED_Module |
| 24 | 24 | { |
| 25 | 25 | |
| 26 | - const debug = false; // true false |
|
| 26 | + const debug = false; // true false |
|
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * an array of raw ticket data from EED_Ticket_Selector |
@@ -209,17 +209,17 @@ discard block |
||
| 209 | 209 | /** @var EE_Line_Item $total_line_item */ |
| 210 | 210 | $ticket_line_items = EED_Ticket_Sales_Monitor::get_ticket_line_items_for_grand_total($total_line_item); |
| 211 | 211 | foreach ($ticket_line_items as $ticket_line_item) { |
| 212 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
| 212 | + if ( ! $ticket_line_item instanceof EE_Line_Item) { |
|
| 213 | 213 | continue; |
| 214 | 214 | } |
| 215 | 215 | if ($total_line_item->timestamp(true) <= $expired) { |
| 216 | - $expired_ticket_IDs[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item->OBJ_ID(); |
|
| 216 | + $expired_ticket_IDs[$ticket_line_item->OBJ_ID()] = $ticket_line_item->OBJ_ID(); |
|
| 217 | 217 | } else { |
| 218 | - $valid_ticket_line_items[ $ticket_line_item->OBJ_ID() ] = $ticket_line_item; |
|
| 218 | + $valid_ticket_line_items[$ticket_line_item->OBJ_ID()] = $ticket_line_item; |
|
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | - if (! empty($expired_ticket_IDs)) { |
|
| 222 | + if ( ! empty($expired_ticket_IDs)) { |
|
| 223 | 223 | EED_Ticket_Sales_Monitor::release_reservations_for_tickets( |
| 224 | 224 | \EEM_Ticket::instance()->get_tickets_with_IDs($expired_ticket_IDs), |
| 225 | 225 | $valid_ticket_line_items, |
@@ -262,8 +262,8 @@ discard block |
||
| 262 | 262 | $qty = EED_Ticket_Sales_Monitor::instance()->_validate_ticket_sale($ticket, $qty); |
| 263 | 263 | } |
| 264 | 264 | if (self::debug) { |
| 265 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '()'; |
|
| 266 | - echo '<br /><br /><b> RETURNED QTY: ' . $qty . '</b>'; |
|
| 265 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'()'; |
|
| 266 | + echo '<br /><br /><b> RETURNED QTY: '.$qty.'</b>'; |
|
| 267 | 267 | } |
| 268 | 268 | return $qty; |
| 269 | 269 | } |
@@ -282,36 +282,36 @@ discard block |
||
| 282 | 282 | protected function _validate_ticket_sale(EE_Ticket $ticket, $qty = 1) |
| 283 | 283 | { |
| 284 | 284 | if (self::debug) { |
| 285 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 285 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 286 | 286 | } |
| 287 | - if (! $ticket instanceof EE_Ticket) { |
|
| 287 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 288 | 288 | return 0; |
| 289 | 289 | } |
| 290 | 290 | if (self::debug) { |
| 291 | - echo '<br /><b> . ticket->ID: ' . $ticket->ID() . '</b>'; |
|
| 292 | - echo '<br /> . original ticket->reserved: ' . $ticket->reserved(); |
|
| 291 | + echo '<br /><b> . ticket->ID: '.$ticket->ID().'</b>'; |
|
| 292 | + echo '<br /> . original ticket->reserved: '.$ticket->reserved(); |
|
| 293 | 293 | } |
| 294 | 294 | $ticket->refresh_from_db(); |
| 295 | 295 | // first let's determine the ticket availability based on sales |
| 296 | 296 | $available = $ticket->qty('saleable'); |
| 297 | 297 | if (self::debug) { |
| 298 | - echo '<br /> . . . ticket->qty: ' . $ticket->qty(); |
|
| 299 | - echo '<br /> . . . ticket->sold: ' . $ticket->sold(); |
|
| 300 | - echo '<br /> . . . ticket->reserved: ' . $ticket->reserved(); |
|
| 301 | - echo '<br /> . . . ticket->qty(saleable): ' . $ticket->qty('saleable'); |
|
| 302 | - echo '<br /> . . . available: ' . $available; |
|
| 298 | + echo '<br /> . . . ticket->qty: '.$ticket->qty(); |
|
| 299 | + echo '<br /> . . . ticket->sold: '.$ticket->sold(); |
|
| 300 | + echo '<br /> . . . ticket->reserved: '.$ticket->reserved(); |
|
| 301 | + echo '<br /> . . . ticket->qty(saleable): '.$ticket->qty('saleable'); |
|
| 302 | + echo '<br /> . . . available: '.$available; |
|
| 303 | 303 | } |
| 304 | 304 | if ($available < 1) { |
| 305 | 305 | $this->_ticket_sold_out($ticket); |
| 306 | 306 | return 0; |
| 307 | 307 | } |
| 308 | 308 | if (self::debug) { |
| 309 | - echo '<br /> . . . qty: ' . $qty; |
|
| 309 | + echo '<br /> . . . qty: '.$qty; |
|
| 310 | 310 | } |
| 311 | 311 | if ($available < $qty) { |
| 312 | 312 | $qty = $available; |
| 313 | 313 | if (self::debug) { |
| 314 | - echo '<br /> . . . QTY ADJUSTED: ' . $qty; |
|
| 314 | + echo '<br /> . . . QTY ADJUSTED: '.$qty; |
|
| 315 | 315 | } |
| 316 | 316 | $this->_ticket_quantity_decremented($ticket); |
| 317 | 317 | } |
@@ -332,9 +332,9 @@ discard block |
||
| 332 | 332 | protected function _reserve_ticket(EE_Ticket $ticket, $quantity = 1) |
| 333 | 333 | { |
| 334 | 334 | if (self::debug) { |
| 335 | - echo '<br /><br /> . . . INCREASE RESERVED: ' . $quantity; |
|
| 335 | + echo '<br /><br /> . . . INCREASE RESERVED: '.$quantity; |
|
| 336 | 336 | } |
| 337 | - $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'. __LINE__); |
|
| 337 | + $ticket->increase_reserved($quantity, 'TicketSalesMonitor:'.__LINE__); |
|
| 338 | 338 | return $ticket->save(); |
| 339 | 339 | } |
| 340 | 340 | |
@@ -349,12 +349,12 @@ discard block |
||
| 349 | 349 | protected function _release_reserved_ticket(EE_Ticket $ticket, $quantity = 1) |
| 350 | 350 | { |
| 351 | 351 | if (self::debug) { |
| 352 | - echo '<br /> . . . ticket->ID: ' . $ticket->ID(); |
|
| 353 | - echo '<br /> . . . ticket->reserved before: ' . $ticket->reserved(); |
|
| 352 | + echo '<br /> . . . ticket->ID: '.$ticket->ID(); |
|
| 353 | + echo '<br /> . . . ticket->reserved before: '.$ticket->reserved(); |
|
| 354 | 354 | } |
| 355 | - $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 355 | + $ticket->decrease_reserved($quantity, true, 'TicketSalesMonitor:'.__LINE__); |
|
| 356 | 356 | if (self::debug) { |
| 357 | - echo '<br /> . . . ticket->reserved after: ' . $ticket->reserved(); |
|
| 357 | + echo '<br /> . . . ticket->reserved after: '.$ticket->reserved(); |
|
| 358 | 358 | } |
| 359 | 359 | return $ticket->save() ? 1 : 0; |
| 360 | 360 | } |
@@ -372,8 +372,8 @@ discard block |
||
| 372 | 372 | protected function _ticket_sold_out(EE_Ticket $ticket) |
| 373 | 373 | { |
| 374 | 374 | if (self::debug) { |
| 375 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 376 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 375 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 376 | + echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
| 377 | 377 | } |
| 378 | 378 | $this->sold_out_tickets[] = $this->_get_ticket_and_event_name($ticket); |
| 379 | 379 | } |
@@ -391,8 +391,8 @@ discard block |
||
| 391 | 391 | protected function _ticket_quantity_decremented(EE_Ticket $ticket) |
| 392 | 392 | { |
| 393 | 393 | if (self::debug) { |
| 394 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 395 | - echo '<br /> . . ticket->name: ' . $this->_get_ticket_and_event_name($ticket); |
|
| 394 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 395 | + echo '<br /> . . ticket->name: '.$this->_get_ticket_and_event_name($ticket); |
|
| 396 | 396 | } |
| 397 | 397 | $this->decremented_tickets[] = $this->_get_ticket_and_event_name($ticket); |
| 398 | 398 | } |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | if ($ticket instanceof EE_Ticket) { |
| 446 | 446 | $ticket->add_extra_meta( |
| 447 | 447 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 448 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 448 | + __LINE__.') '.__METHOD__.'()' |
|
| 449 | 449 | ); |
| 450 | 450 | if ($quantity > 0) { |
| 451 | 451 | EED_Ticket_Sales_Monitor::instance()->_reserve_ticket($ticket, $quantity); |
@@ -469,7 +469,7 @@ discard block |
||
| 469 | 469 | { |
| 470 | 470 | $ticket->add_extra_meta( |
| 471 | 471 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 472 | - __LINE__ . ') ' . __METHOD__ . '()' |
|
| 472 | + __LINE__.') '.__METHOD__.'()' |
|
| 473 | 473 | ); |
| 474 | 474 | EED_Ticket_Sales_Monitor::instance()->_release_reserved_ticket($ticket, $quantity); |
| 475 | 475 | } |
@@ -506,18 +506,18 @@ discard block |
||
| 506 | 506 | protected function _post_notices() |
| 507 | 507 | { |
| 508 | 508 | if (self::debug) { |
| 509 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 509 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 510 | 510 | } |
| 511 | 511 | $refresh_msg = ''; |
| 512 | 512 | $none_added_msg = ''; |
| 513 | 513 | if (defined('DOING_AJAX') && DOING_AJAX) { |
| 514 | - $refresh_msg = __( |
|
| 514 | + $refresh_msg = __( |
|
| 515 | 515 | 'Please refresh the page to view updated ticket quantities.', |
| 516 | 516 | 'event_espresso' |
| 517 | 517 | ); |
| 518 | 518 | $none_added_msg = __('No tickets were added for the event.', 'event_espresso'); |
| 519 | 519 | } |
| 520 | - if (! empty($this->sold_out_tickets)) { |
|
| 520 | + if ( ! empty($this->sold_out_tickets)) { |
|
| 521 | 521 | EE_Error::add_attention( |
| 522 | 522 | sprintf( |
| 523 | 523 | apply_filters( |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | // and reset the cart |
| 541 | 541 | EED_Ticket_Sales_Monitor::session_cart_reset(EE_Registry::instance()->SSN); |
| 542 | 542 | } |
| 543 | - if (! empty($this->decremented_tickets)) { |
|
| 543 | + if ( ! empty($this->decremented_tickets)) { |
|
| 544 | 544 | EE_Error::add_attention( |
| 545 | 545 | sprintf( |
| 546 | 546 | apply_filters( |
@@ -578,9 +578,9 @@ discard block |
||
| 578 | 578 | protected function _release_all_reserved_tickets_for_transaction(EE_Transaction $transaction) |
| 579 | 579 | { |
| 580 | 580 | if (self::debug) { |
| 581 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 582 | - echo '<br /> . transaction->ID: ' . $transaction->ID(); |
|
| 583 | - echo '<br /> . TXN status_ID: ' . $transaction->status_ID(); |
|
| 581 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 582 | + echo '<br /> . transaction->ID: '.$transaction->ID(); |
|
| 583 | + echo '<br /> . TXN status_ID: '.$transaction->status_ID(); |
|
| 584 | 584 | } |
| 585 | 585 | // check if 'finalize_registration' step has been completed... |
| 586 | 586 | $finalized = $transaction->reg_step_completed('finalize_registration'); |
@@ -592,13 +592,13 @@ discard block |
||
| 592 | 592 | __LINE__, |
| 593 | 593 | array('finalized' => $finalized), |
| 594 | 594 | false, |
| 595 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 595 | + 'EE_Transaction: '.$transaction->ID() |
|
| 596 | 596 | ); |
| 597 | 597 | } |
| 598 | 598 | // how many tickets were released |
| 599 | 599 | $count = 0; |
| 600 | 600 | if (self::debug) { |
| 601 | - echo '<br /> . . . TXN finalized: ' . $finalized; |
|
| 601 | + echo '<br /> . . . TXN finalized: '.$finalized; |
|
| 602 | 602 | } |
| 603 | 603 | $release_tickets_with_TXN_status = array( |
| 604 | 604 | EEM_Transaction::failed_status_code, |
@@ -607,28 +607,28 @@ discard block |
||
| 607 | 607 | ); |
| 608 | 608 | $events = array(); |
| 609 | 609 | // if the session is getting cleared BEFORE the TXN has been finalized or the transaction is not completed |
| 610 | - if (! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 610 | + if ( ! $finalized || in_array($transaction->status_ID(), $release_tickets_with_TXN_status, true)) { |
|
| 611 | 611 | // cancel any reserved tickets for registrations that were not approved |
| 612 | 612 | $registrations = $transaction->registrations(); |
| 613 | 613 | if (self::debug) { |
| 614 | - echo '<br /> . . . # registrations: ' . count($registrations); |
|
| 614 | + echo '<br /> . . . # registrations: '.count($registrations); |
|
| 615 | 615 | $reg = reset($registrations); |
| 616 | 616 | $ticket = $reg->ticket(); |
| 617 | 617 | if ($ticket instanceof EE_Ticket) { |
| 618 | 618 | $ticket->add_extra_meta( |
| 619 | 619 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 620 | - __LINE__ . ') Release All Tickets TXN:' . $transaction->ID() |
|
| 620 | + __LINE__.') Release All Tickets TXN:'.$transaction->ID() |
|
| 621 | 621 | ); |
| 622 | 622 | } |
| 623 | 623 | } |
| 624 | - if (! empty($registrations)) { |
|
| 624 | + if ( ! empty($registrations)) { |
|
| 625 | 625 | foreach ($registrations as $registration) { |
| 626 | 626 | if ( |
| 627 | 627 | $registration instanceof EE_Registration |
| 628 | 628 | && $this->_release_reserved_ticket_for_registration($registration, $transaction) |
| 629 | 629 | ) { |
| 630 | 630 | $count++; |
| 631 | - $events[ $registration->event_ID() ] = $registration->event(); |
|
| 631 | + $events[$registration->event_ID()] = $registration->event(); |
|
| 632 | 632 | } |
| 633 | 633 | } |
| 634 | 634 | } |
@@ -659,10 +659,10 @@ discard block |
||
| 659 | 659 | ) { |
| 660 | 660 | $STS_ID = $transaction->status_ID(); |
| 661 | 661 | if (self::debug) { |
| 662 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 663 | - echo '<br /> . . registration->ID: ' . $registration->ID(); |
|
| 664 | - echo '<br /> . . registration->status_ID: ' . $registration->status_ID(); |
|
| 665 | - echo '<br /> . . transaction->status_ID(): ' . $STS_ID; |
|
| 662 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 663 | + echo '<br /> . . registration->ID: '.$registration->ID(); |
|
| 664 | + echo '<br /> . . registration->status_ID: '.$registration->status_ID(); |
|
| 665 | + echo '<br /> . . transaction->status_ID(): '.$STS_ID; |
|
| 666 | 666 | } |
| 667 | 667 | if ( |
| 668 | 668 | // release Tickets for Failed Transactions and Abandoned Transactions |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | echo '<br /> . . . registration HAS_RESERVED_TICKET_KEY: '; |
| 681 | 681 | var_dump($rsrvd); |
| 682 | 682 | } |
| 683 | - $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'. __LINE__); |
|
| 683 | + $registration->release_reserved_ticket(true, 'TicketSalesMonitor:'.__LINE__); |
|
| 684 | 684 | return 1; |
| 685 | 685 | } |
| 686 | 686 | return 0; |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | return; |
| 711 | 711 | } |
| 712 | 712 | if (self::debug) { |
| 713 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 713 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 714 | 714 | } |
| 715 | 715 | // first check of the session has a valid Checkout object |
| 716 | 716 | $checkout = $session->checkout(); |
@@ -749,32 +749,32 @@ discard block |
||
| 749 | 749 | protected function _session_cart_reset(EE_Cart $cart, EE_Session $session) |
| 750 | 750 | { |
| 751 | 751 | if (self::debug) { |
| 752 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 752 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 753 | 753 | } |
| 754 | 754 | $ticket_line_items = $cart->get_tickets(); |
| 755 | 755 | if (empty($ticket_line_items)) { |
| 756 | 756 | return; |
| 757 | 757 | } |
| 758 | 758 | if (self::debug) { |
| 759 | - echo '<br /> . ticket_line_item count: ' . count($ticket_line_items); |
|
| 759 | + echo '<br /> . ticket_line_item count: '.count($ticket_line_items); |
|
| 760 | 760 | } |
| 761 | 761 | foreach ($ticket_line_items as $ticket_line_item) { |
| 762 | 762 | if (self::debug) { |
| 763 | - echo '<br /> . . ticket_line_item->ID(): ' . $ticket_line_item->ID(); |
|
| 763 | + echo '<br /> . . ticket_line_item->ID(): '.$ticket_line_item->ID(); |
|
| 764 | 764 | } |
| 765 | 765 | if ($ticket_line_item instanceof EE_Line_Item && $ticket_line_item->OBJ_type() === 'Ticket') { |
| 766 | 766 | if (self::debug) { |
| 767 | - echo '<br /> . . . ticket_line_item->OBJ_ID(): ' . $ticket_line_item->OBJ_ID(); |
|
| 767 | + echo '<br /> . . . ticket_line_item->OBJ_ID(): '.$ticket_line_item->OBJ_ID(); |
|
| 768 | 768 | } |
| 769 | 769 | $ticket = EEM_Ticket::instance()->get_one_by_ID($ticket_line_item->OBJ_ID()); |
| 770 | 770 | if ($ticket instanceof EE_Ticket) { |
| 771 | 771 | if (self::debug) { |
| 772 | - echo '<br /> . . . ticket->ID(): ' . $ticket->ID(); |
|
| 773 | - echo '<br /> . . . ticket_line_item->quantity(): ' . $ticket_line_item->quantity(); |
|
| 772 | + echo '<br /> . . . ticket->ID(): '.$ticket->ID(); |
|
| 773 | + echo '<br /> . . . ticket_line_item->quantity(): '.$ticket_line_item->quantity(); |
|
| 774 | 774 | } |
| 775 | 775 | $ticket->add_extra_meta( |
| 776 | 776 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 777 | - __LINE__ . ') ' . __METHOD__ . '() SID = ' . $session->id() |
|
| 777 | + __LINE__.') '.__METHOD__.'() SID = '.$session->id() |
|
| 778 | 778 | ); |
| 779 | 779 | $this->_release_reserved_ticket($ticket, $ticket_line_item->quantity()); |
| 780 | 780 | } |
@@ -802,7 +802,7 @@ discard block |
||
| 802 | 802 | public static function session_checkout_reset(EE_Session $session) |
| 803 | 803 | { |
| 804 | 804 | // don't release tickets if cart was already reset |
| 805 | - if(did_action('AHEE__EE_Session__reset_cart__before_reset')) { |
|
| 805 | + if (did_action('AHEE__EE_Session__reset_cart__before_reset')) { |
|
| 806 | 806 | return; |
| 807 | 807 | } |
| 808 | 808 | $checkout = $session->checkout(); |
@@ -824,7 +824,7 @@ discard block |
||
| 824 | 824 | protected function _session_checkout_reset(EE_Checkout $checkout) |
| 825 | 825 | { |
| 826 | 826 | if (self::debug) { |
| 827 | - echo '<br /><br /> ' . __LINE__ . ') ' . __METHOD__ . '() '; |
|
| 827 | + echo '<br /><br /> '.__LINE__.') '.__METHOD__.'() '; |
|
| 828 | 828 | } |
| 829 | 829 | // we want to release the each registration's reserved tickets if the session was cleared, but not if this is a revisit |
| 830 | 830 | if ($checkout->revisit || ! $checkout->transaction instanceof EE_Transaction) { |
@@ -874,7 +874,7 @@ discard block |
||
| 874 | 874 | __LINE__, |
| 875 | 875 | array($transaction), |
| 876 | 876 | false, |
| 877 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 877 | + 'EE_Transaction: '.$transaction->ID() |
|
| 878 | 878 | ); |
| 879 | 879 | } |
| 880 | 880 | return; |
@@ -891,7 +891,7 @@ discard block |
||
| 891 | 891 | __LINE__, |
| 892 | 892 | array($payment), |
| 893 | 893 | false, |
| 894 | - 'EE_Transaction: ' . $transaction->ID() |
|
| 894 | + 'EE_Transaction: '.$transaction->ID() |
|
| 895 | 895 | ); |
| 896 | 896 | } |
| 897 | 897 | return; |
@@ -951,7 +951,7 @@ discard block |
||
| 951 | 951 | } |
| 952 | 952 | $total_line_item = $transaction->total_line_item(); |
| 953 | 953 | // $transaction_in_progress->line |
| 954 | - if (! $total_line_item instanceof EE_Line_Item) { |
|
| 954 | + if ( ! $total_line_item instanceof EE_Line_Item) { |
|
| 955 | 955 | throw new DomainException( |
| 956 | 956 | esc_html__( |
| 957 | 957 | 'Transaction does not have a valid Total Line Item associated with it.', |
@@ -1014,7 +1014,7 @@ discard block |
||
| 1014 | 1014 | $total_tickets_released = 0; |
| 1015 | 1015 | $sold_out_events = array(); |
| 1016 | 1016 | foreach ($tickets_with_reservations as $ticket_with_reservations) { |
| 1017 | - if (! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1017 | + if ( ! $ticket_with_reservations instanceof EE_Ticket) { |
|
| 1018 | 1018 | continue; |
| 1019 | 1019 | } |
| 1020 | 1020 | $reserved_qty = $ticket_with_reservations->reserved(); |
@@ -1029,9 +1029,9 @@ discard block |
||
| 1029 | 1029 | if ($reserved_qty > 0) { |
| 1030 | 1030 | $ticket_with_reservations->add_extra_meta( |
| 1031 | 1031 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
| 1032 | - __LINE__ . ') ' . $source . '()' |
|
| 1032 | + __LINE__.') '.$source.'()' |
|
| 1033 | 1033 | ); |
| 1034 | - $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'. __LINE__); |
|
| 1034 | + $ticket_with_reservations->decrease_reserved($reserved_qty, true, 'TicketSalesMonitor:'.__LINE__); |
|
| 1035 | 1035 | $ticket_with_reservations->save(); |
| 1036 | 1036 | $total_tickets_released += $reserved_qty; |
| 1037 | 1037 | $event = $ticket_with_reservations->get_related_event(); |
@@ -1042,7 +1042,7 @@ discard block |
||
| 1042 | 1042 | } |
| 1043 | 1043 | } |
| 1044 | 1044 | // double check whether sold out events should remain sold out after releasing tickets |
| 1045 | - if($sold_out_events !== array()){ |
|
| 1045 | + if ($sold_out_events !== array()) { |
|
| 1046 | 1046 | foreach ($sold_out_events as $sold_out_event) { |
| 1047 | 1047 | /** @var EE_Event $sold_out_event */ |
| 1048 | 1048 | $sold_out_event->perform_sold_out_status_check(); |
@@ -1070,7 +1070,7 @@ discard block |
||
| 1070 | 1070 | global $wpdb; |
| 1071 | 1071 | return $wpdb->query( |
| 1072 | 1072 | $wpdb->prepare( |
| 1073 | - 'DELETE FROM ' . EEM_Line_Item::instance()->table() . ' |
|
| 1073 | + 'DELETE FROM '.EEM_Line_Item::instance()->table().' |
|
| 1074 | 1074 | WHERE TXN_ID = 0 AND LIN_timestamp <= %s', |
| 1075 | 1075 | // use GMT time because that's what LIN_timestamps are in |
| 1076 | 1076 | date('Y-m-d H:i:s', time() - EE_Registry::instance()->SSN->lifespan()) |
@@ -53,14 +53,14 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | const onsale = 'TKO'; |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * extra meta key for tracking ticket reservations |
|
| 58 | - * |
|
| 59 | - * @type string |
|
| 60 | - */ |
|
| 61 | - const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
| 62 | - |
|
| 63 | - /** |
|
| 56 | + /** |
|
| 57 | + * extra meta key for tracking ticket reservations |
|
| 58 | + * |
|
| 59 | + * @type string |
|
| 60 | + */ |
|
| 61 | + const META_KEY_TICKET_RESERVATIONS = 'ticket_reservations'; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | 64 | * cached result from method of the same name |
| 65 | 65 | * @var float $_ticket_total_with_taxes |
| 66 | 66 | */ |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param array $props_n_values incoming values |
|
| 73 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 74 | - * used.) |
|
| 75 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 76 | - * date_format and the second value is the time format |
|
| 77 | - * @return EE_Ticket |
|
| 78 | - * @throws \EE_Error |
|
| 79 | - */ |
|
| 71 | + /** |
|
| 72 | + * @param array $props_n_values incoming values |
|
| 73 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 74 | + * used.) |
|
| 75 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 76 | + * date_format and the second value is the time format |
|
| 77 | + * @return EE_Ticket |
|
| 78 | + * @throws \EE_Error |
|
| 79 | + */ |
|
| 80 | 80 | public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
| 81 | 81 | $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
| 82 | 82 | return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
@@ -84,36 +84,36 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @param array $props_n_values incoming values from the database |
|
| 89 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 90 | - * the website will be used. |
|
| 91 | - * @return EE_Ticket |
|
| 92 | - * @throws \EE_Error |
|
| 93 | - */ |
|
| 87 | + /** |
|
| 88 | + * @param array $props_n_values incoming values from the database |
|
| 89 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 90 | + * the website will be used. |
|
| 91 | + * @return EE_Ticket |
|
| 92 | + * @throws \EE_Error |
|
| 93 | + */ |
|
| 94 | 94 | public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
| 95 | 95 | return new self( $props_n_values, TRUE, $timezone ); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * @return bool |
|
| 102 | - * @throws \EE_Error |
|
| 103 | - */ |
|
| 100 | + /** |
|
| 101 | + * @return bool |
|
| 102 | + * @throws \EE_Error |
|
| 103 | + */ |
|
| 104 | 104 | public function parent() { |
| 105 | 105 | return $this->get( 'TKT_parent' ); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * return if a ticket has quantities available for purchase |
|
| 112 | - * |
|
| 113 | - * @param int $DTT_ID the primary key for a particular datetime |
|
| 114 | - * @return boolean |
|
| 115 | - * @throws \EE_Error |
|
| 116 | - */ |
|
| 110 | + /** |
|
| 111 | + * return if a ticket has quantities available for purchase |
|
| 112 | + * |
|
| 113 | + * @param int $DTT_ID the primary key for a particular datetime |
|
| 114 | + * @return boolean |
|
| 115 | + * @throws \EE_Error |
|
| 116 | + */ |
|
| 117 | 117 | public function available( $DTT_ID = 0 ) { |
| 118 | 118 | // are we checking availability for a particular datetime ? |
| 119 | 119 | if ( $DTT_ID ) { |
@@ -130,14 +130,14 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | |
| 132 | 132 | |
| 133 | - /** |
|
| 134 | - * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 135 | - * |
|
| 136 | - * @param bool $display true = we'll return a localized string, otherwise we just return the value of the relevant status const |
|
| 137 | - * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing |
|
| 138 | - * @return mixed status int if the display string isn't requested |
|
| 139 | - * @throws \EE_Error |
|
| 140 | - */ |
|
| 133 | + /** |
|
| 134 | + * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
| 135 | + * |
|
| 136 | + * @param bool $display true = we'll return a localized string, otherwise we just return the value of the relevant status const |
|
| 137 | + * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing |
|
| 138 | + * @return mixed status int if the display string isn't requested |
|
| 139 | + * @throws \EE_Error |
|
| 140 | + */ |
|
| 141 | 141 | public function ticket_status( $display = FALSE, $remaining = null ) { |
| 142 | 142 | $remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining(); |
| 143 | 143 | if ( ! $remaining ) { |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | |
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out. |
|
| 165 | - * |
|
| 166 | - * @access public |
|
| 167 | - * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 168 | - * @return boolean true = tickets remaining, false not. |
|
| 169 | - * @throws \EE_Error |
|
| 170 | - */ |
|
| 163 | + /** |
|
| 164 | + * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out. |
|
| 165 | + * |
|
| 166 | + * @access public |
|
| 167 | + * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
| 168 | + * @return boolean true = tickets remaining, false not. |
|
| 169 | + * @throws \EE_Error |
|
| 170 | + */ |
|
| 171 | 171 | public function is_remaining( $DTT_ID = 0 ) { |
| 172 | 172 | $num_remaining = $this->remaining( $DTT_ID ); |
| 173 | 173 | if ( $num_remaining === 0 ) { |
@@ -181,76 +181,76 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | |
| 183 | 183 | |
| 184 | - /** |
|
| 185 | - * return the total number of tickets available for purchase |
|
| 186 | - * |
|
| 187 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 188 | - * set to 0 for all related datetimes |
|
| 189 | - * @return int |
|
| 190 | - * @throws \EE_Error |
|
| 191 | - */ |
|
| 184 | + /** |
|
| 185 | + * return the total number of tickets available for purchase |
|
| 186 | + * |
|
| 187 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 188 | + * set to 0 for all related datetimes |
|
| 189 | + * @return int |
|
| 190 | + * @throws \EE_Error |
|
| 191 | + */ |
|
| 192 | 192 | public function remaining( $DTT_ID = 0 ) { |
| 193 | 193 | return $this->real_quantity_on_ticket('saleable', $DTT_ID ); |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | |
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Gets min |
|
| 200 | - * |
|
| 201 | - * @return int |
|
| 202 | - * @throws \EE_Error |
|
| 203 | - */ |
|
| 198 | + /** |
|
| 199 | + * Gets min |
|
| 200 | + * |
|
| 201 | + * @return int |
|
| 202 | + * @throws \EE_Error |
|
| 203 | + */ |
|
| 204 | 204 | public function min() { |
| 205 | 205 | return $this->get( 'TKT_min' ); |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * return if a ticket is no longer available cause its available dates have expired. |
|
| 212 | - * |
|
| 213 | - * @return boolean |
|
| 214 | - * @throws \EE_Error |
|
| 215 | - */ |
|
| 210 | + /** |
|
| 211 | + * return if a ticket is no longer available cause its available dates have expired. |
|
| 212 | + * |
|
| 213 | + * @return boolean |
|
| 214 | + * @throws \EE_Error |
|
| 215 | + */ |
|
| 216 | 216 | public function is_expired() { |
| 217 | 217 | return ( $this->get_raw( 'TKT_end_date' ) < time() ); |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | |
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * Return if a ticket is yet to go on sale or not |
|
| 224 | - * |
|
| 225 | - * @return boolean |
|
| 226 | - * @throws \EE_Error |
|
| 227 | - */ |
|
| 222 | + /** |
|
| 223 | + * Return if a ticket is yet to go on sale or not |
|
| 224 | + * |
|
| 225 | + * @return boolean |
|
| 226 | + * @throws \EE_Error |
|
| 227 | + */ |
|
| 228 | 228 | public function is_pending() { |
| 229 | 229 | return ( $this->get_raw( 'TKT_start_date' ) > time() ); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Return if a ticket is on sale or not |
|
| 236 | - * |
|
| 237 | - * @return boolean |
|
| 238 | - * @throws \EE_Error |
|
| 239 | - */ |
|
| 234 | + /** |
|
| 235 | + * Return if a ticket is on sale or not |
|
| 236 | + * |
|
| 237 | + * @return boolean |
|
| 238 | + * @throws \EE_Error |
|
| 239 | + */ |
|
| 240 | 240 | public function is_on_sale() { |
| 241 | 241 | return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() ); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
| 245 | 245 | |
| 246 | - /** |
|
| 247 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 248 | - * |
|
| 249 | - * @param string $dt_frmt |
|
| 250 | - * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
| 251 | - * @return string |
|
| 252 | - * @throws \EE_Error |
|
| 253 | - */ |
|
| 246 | + /** |
|
| 247 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 248 | + * |
|
| 249 | + * @param string $dt_frmt |
|
| 250 | + * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
| 251 | + * @return string |
|
| 252 | + * @throws \EE_Error |
|
| 253 | + */ |
|
| 254 | 254 | public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
| 255 | 255 | $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : ''; |
| 256 | 256 | $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : ''; |
@@ -260,12 +260,12 @@ discard block |
||
| 260 | 260 | |
| 261 | 261 | |
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * This returns the chronologically first datetime that this ticket is associated with |
|
| 265 | - * |
|
| 266 | - * @return EE_Datetime |
|
| 267 | - * @throws \EE_Error |
|
| 268 | - */ |
|
| 263 | + /** |
|
| 264 | + * This returns the chronologically first datetime that this ticket is associated with |
|
| 265 | + * |
|
| 266 | + * @return EE_Datetime |
|
| 267 | + * @throws \EE_Error |
|
| 268 | + */ |
|
| 269 | 269 | public function first_datetime() { |
| 270 | 270 | $datetimes = $this->datetimes( array( 'limit' => 1 ) ); |
| 271 | 271 | return reset( $datetimes ); |
@@ -273,14 +273,14 @@ discard block |
||
| 273 | 273 | |
| 274 | 274 | |
| 275 | 275 | |
| 276 | - /** |
|
| 277 | - * Gets all the datetimes this ticket can be used for attending. |
|
| 278 | - * Unless otherwise specified, orders datetimes by start date. |
|
| 279 | - * |
|
| 280 | - * @param array $query_params see EEM_Base::get_all() |
|
| 281 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
| 282 | - * @throws \EE_Error |
|
| 283 | - */ |
|
| 276 | + /** |
|
| 277 | + * Gets all the datetimes this ticket can be used for attending. |
|
| 278 | + * Unless otherwise specified, orders datetimes by start date. |
|
| 279 | + * |
|
| 280 | + * @param array $query_params see EEM_Base::get_all() |
|
| 281 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
| 282 | + * @throws \EE_Error |
|
| 283 | + */ |
|
| 284 | 284 | public function datetimes( $query_params = array() ) { |
| 285 | 285 | if ( ! isset( $query_params[ 'order_by' ] ) ) { |
| 286 | 286 | $query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC'; |
@@ -290,12 +290,12 @@ discard block |
||
| 290 | 290 | |
| 291 | 291 | |
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * This returns the chronologically last datetime that this ticket is associated with |
|
| 295 | - * |
|
| 296 | - * @return EE_Datetime |
|
| 297 | - * @throws \EE_Error |
|
| 298 | - */ |
|
| 293 | + /** |
|
| 294 | + * This returns the chronologically last datetime that this ticket is associated with |
|
| 295 | + * |
|
| 296 | + * @return EE_Datetime |
|
| 297 | + * @throws \EE_Error |
|
| 298 | + */ |
|
| 299 | 299 | public function last_datetime() { |
| 300 | 300 | $datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) ); |
| 301 | 301 | return end( $datetimes ); |
@@ -303,19 +303,19 @@ discard block |
||
| 303 | 303 | |
| 304 | 304 | |
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * This returns the total tickets sold depending on the given parameters. |
|
| 308 | - * |
|
| 309 | - * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 310 | - * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 311 | - * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 312 | - * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 313 | - * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 314 | - * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 315 | - * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 316 | - * @return mixed (array|int) how many tickets have sold |
|
| 317 | - * @throws \EE_Error |
|
| 318 | - */ |
|
| 306 | + /** |
|
| 307 | + * This returns the total tickets sold depending on the given parameters. |
|
| 308 | + * |
|
| 309 | + * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
| 310 | + * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
| 311 | + * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
| 312 | + * 'datetime' = total ticket sales in the datetime_ticket table. |
|
| 313 | + * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
| 314 | + * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
| 315 | + * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
| 316 | + * @return mixed (array|int) how many tickets have sold |
|
| 317 | + * @throws \EE_Error |
|
| 318 | + */ |
|
| 319 | 319 | public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) { |
| 320 | 320 | $total = 0; |
| 321 | 321 | $tickets_sold = $this->_all_tickets_sold(); |
@@ -340,12 +340,12 @@ discard block |
||
| 340 | 340 | |
| 341 | 341 | |
| 342 | 342 | |
| 343 | - /** |
|
| 344 | - * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 345 | - * |
|
| 346 | - * @return EE_Ticket[] |
|
| 347 | - * @throws \EE_Error |
|
| 348 | - */ |
|
| 343 | + /** |
|
| 344 | + * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
| 345 | + * |
|
| 346 | + * @return EE_Ticket[] |
|
| 347 | + * @throws \EE_Error |
|
| 348 | + */ |
|
| 349 | 349 | protected function _all_tickets_sold() { |
| 350 | 350 | $datetimes = $this->get_many_related( 'Datetime' ); |
| 351 | 351 | $tickets_sold = array(); |
@@ -361,29 +361,29 @@ discard block |
||
| 361 | 361 | |
| 362 | 362 | |
| 363 | 363 | |
| 364 | - /** |
|
| 365 | - * This returns the base price object for the ticket. |
|
| 366 | - * |
|
| 367 | - * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 368 | - * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 369 | - * @throws \EE_Error |
|
| 370 | - */ |
|
| 364 | + /** |
|
| 365 | + * This returns the base price object for the ticket. |
|
| 366 | + * |
|
| 367 | + * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
| 368 | + * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
| 369 | + * @throws \EE_Error |
|
| 370 | + */ |
|
| 371 | 371 | public function base_price( $return_array = FALSE ) { |
| 372 | 372 | $_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price ); |
| 373 | 373 | return $return_array |
| 374 | - ? $this->get_many_related( 'Price', array( $_where ) ) |
|
| 375 | - : $this->get_first_related( 'Price', array( $_where ) ); |
|
| 374 | + ? $this->get_many_related( 'Price', array( $_where ) ) |
|
| 375 | + : $this->get_first_related( 'Price', array( $_where ) ); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | |
| 379 | 379 | |
| 380 | - /** |
|
| 381 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 382 | - * |
|
| 383 | - * @access public |
|
| 384 | - * @return EE_Price[] |
|
| 385 | - * @throws \EE_Error |
|
| 386 | - */ |
|
| 380 | + /** |
|
| 381 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
| 382 | + * |
|
| 383 | + * @access public |
|
| 384 | + * @return EE_Price[] |
|
| 385 | + * @throws \EE_Error |
|
| 386 | + */ |
|
| 387 | 387 | public function price_modifiers() { |
| 388 | 388 | $query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) ); |
| 389 | 389 | return $this->prices( $query_params ); |
@@ -391,132 +391,132 @@ discard block |
||
| 391 | 391 | |
| 392 | 392 | |
| 393 | 393 | |
| 394 | - /** |
|
| 395 | - * Gets all the prices that combine to form the final price of this ticket |
|
| 396 | - * |
|
| 397 | - * @param array $query_params like EEM_Base::get_all |
|
| 398 | - * @return EE_Price[]|EE_Base_Class[] |
|
| 399 | - * @throws \EE_Error |
|
| 400 | - */ |
|
| 394 | + /** |
|
| 395 | + * Gets all the prices that combine to form the final price of this ticket |
|
| 396 | + * |
|
| 397 | + * @param array $query_params like EEM_Base::get_all |
|
| 398 | + * @return EE_Price[]|EE_Base_Class[] |
|
| 399 | + * @throws \EE_Error |
|
| 400 | + */ |
|
| 401 | 401 | public function prices( $query_params = array() ) { |
| 402 | 402 | return $this->get_many_related( 'Price', $query_params ); |
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
| 406 | 406 | |
| 407 | - /** |
|
| 408 | - * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
| 409 | - * |
|
| 410 | - * @param array $query_params see EEM_Base::get_all() |
|
| 411 | - * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 412 | - * @throws \EE_Error |
|
| 413 | - */ |
|
| 407 | + /** |
|
| 408 | + * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
| 409 | + * |
|
| 410 | + * @param array $query_params see EEM_Base::get_all() |
|
| 411 | + * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
| 412 | + * @throws \EE_Error |
|
| 413 | + */ |
|
| 414 | 414 | public function datetime_tickets( $query_params = array() ) { |
| 415 | 415 | return $this->get_many_related( 'Datetime_Ticket', $query_params ); |
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | |
| 419 | 419 | |
| 420 | - /** |
|
| 421 | - * Gets all the datetimes from the db ordered by DTT_order |
|
| 422 | - * |
|
| 423 | - * @param boolean $show_expired |
|
| 424 | - * @param boolean $show_deleted |
|
| 425 | - * @return EE_Datetime[] |
|
| 426 | - * @throws \EE_Error |
|
| 427 | - */ |
|
| 420 | + /** |
|
| 421 | + * Gets all the datetimes from the db ordered by DTT_order |
|
| 422 | + * |
|
| 423 | + * @param boolean $show_expired |
|
| 424 | + * @param boolean $show_deleted |
|
| 425 | + * @return EE_Datetime[] |
|
| 426 | + * @throws \EE_Error |
|
| 427 | + */ |
|
| 428 | 428 | public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) { |
| 429 | 429 | return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted ); |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | |
| 433 | 433 | |
| 434 | - /** |
|
| 435 | - * Gets ID |
|
| 436 | - * |
|
| 437 | - * @return string |
|
| 438 | - * @throws \EE_Error |
|
| 439 | - */ |
|
| 434 | + /** |
|
| 435 | + * Gets ID |
|
| 436 | + * |
|
| 437 | + * @return string |
|
| 438 | + * @throws \EE_Error |
|
| 439 | + */ |
|
| 440 | 440 | public function ID() { |
| 441 | 441 | return $this->get( 'TKT_ID' ); |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | |
| 445 | 445 | |
| 446 | - /** |
|
| 447 | - * get the author of the ticket. |
|
| 448 | - * |
|
| 449 | - * @since 4.5.0 |
|
| 450 | - * @return int |
|
| 451 | - * @throws \EE_Error |
|
| 452 | - */ |
|
| 446 | + /** |
|
| 447 | + * get the author of the ticket. |
|
| 448 | + * |
|
| 449 | + * @since 4.5.0 |
|
| 450 | + * @return int |
|
| 451 | + * @throws \EE_Error |
|
| 452 | + */ |
|
| 453 | 453 | public function wp_user() { |
| 454 | 454 | return $this->get('TKT_wp_user'); |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | |
| 458 | 458 | |
| 459 | - /** |
|
| 460 | - * Gets the template for the ticket |
|
| 461 | - * |
|
| 462 | - * @return EE_Ticket_Template|EE_Base_Class |
|
| 463 | - * @throws \EE_Error |
|
| 464 | - */ |
|
| 459 | + /** |
|
| 460 | + * Gets the template for the ticket |
|
| 461 | + * |
|
| 462 | + * @return EE_Ticket_Template|EE_Base_Class |
|
| 463 | + * @throws \EE_Error |
|
| 464 | + */ |
|
| 465 | 465 | public function template() { |
| 466 | 466 | return $this->get_first_related( 'Ticket_Template' ); |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
| 470 | 470 | |
| 471 | - /** |
|
| 472 | - * Simply returns an array of EE_Price objects that are taxes. |
|
| 473 | - * |
|
| 474 | - * @return EE_Price[] |
|
| 475 | - * @throws \EE_Error |
|
| 476 | - */ |
|
| 471 | + /** |
|
| 472 | + * Simply returns an array of EE_Price objects that are taxes. |
|
| 473 | + * |
|
| 474 | + * @return EE_Price[] |
|
| 475 | + * @throws \EE_Error |
|
| 476 | + */ |
|
| 477 | 477 | public function get_ticket_taxes_for_admin() { |
| 478 | 478 | return EE_Taxes::get_taxes_for_admin(); |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | 481 | |
| 482 | 482 | |
| 483 | - /** |
|
| 484 | - * @return float |
|
| 485 | - * @throws \EE_Error |
|
| 486 | - */ |
|
| 483 | + /** |
|
| 484 | + * @return float |
|
| 485 | + * @throws \EE_Error |
|
| 486 | + */ |
|
| 487 | 487 | public function ticket_price() { |
| 488 | 488 | return $this->get( 'TKT_price' ); |
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | |
| 492 | 492 | |
| 493 | - /** |
|
| 494 | - * @return mixed |
|
| 495 | - * @throws \EE_Error |
|
| 496 | - */ |
|
| 493 | + /** |
|
| 494 | + * @return mixed |
|
| 495 | + * @throws \EE_Error |
|
| 496 | + */ |
|
| 497 | 497 | public function pretty_price() { |
| 498 | 498 | return $this->get_pretty( 'TKT_price' ); |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | |
| 502 | 502 | |
| 503 | - /** |
|
| 504 | - * @return bool |
|
| 505 | - * @throws \EE_Error |
|
| 506 | - */ |
|
| 503 | + /** |
|
| 504 | + * @return bool |
|
| 505 | + * @throws \EE_Error |
|
| 506 | + */ |
|
| 507 | 507 | public function is_free() { |
| 508 | 508 | return $this->get_ticket_total_with_taxes() === (float) 0; |
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | |
| 512 | 512 | |
| 513 | - /** |
|
| 514 | - * get_ticket_total_with_taxes |
|
| 515 | - * |
|
| 516 | - * @param bool $no_cache |
|
| 517 | - * @return float |
|
| 518 | - * @throws \EE_Error |
|
| 519 | - */ |
|
| 513 | + /** |
|
| 514 | + * get_ticket_total_with_taxes |
|
| 515 | + * |
|
| 516 | + * @param bool $no_cache |
|
| 517 | + * @return float |
|
| 518 | + * @throws \EE_Error |
|
| 519 | + */ |
|
| 520 | 520 | public function get_ticket_total_with_taxes( $no_cache = FALSE ) { |
| 521 | 521 | if ($this->_ticket_total_with_taxes === null || $no_cache ) { |
| 522 | 522 | $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
@@ -533,201 +533,201 @@ discard block |
||
| 533 | 533 | |
| 534 | 534 | |
| 535 | 535 | |
| 536 | - /** |
|
| 537 | - * @return float |
|
| 538 | - * @throws \EE_Error |
|
| 539 | - */ |
|
| 536 | + /** |
|
| 537 | + * @return float |
|
| 538 | + * @throws \EE_Error |
|
| 539 | + */ |
|
| 540 | 540 | public function get_ticket_subtotal() { |
| 541 | 541 | return EE_Taxes::get_subtotal_for_admin( $this ); |
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | |
| 545 | 545 | |
| 546 | - /** |
|
| 547 | - * Returns the total taxes applied to this ticket |
|
| 548 | - * |
|
| 549 | - * @return float |
|
| 550 | - * @throws \EE_Error |
|
| 551 | - */ |
|
| 546 | + /** |
|
| 547 | + * Returns the total taxes applied to this ticket |
|
| 548 | + * |
|
| 549 | + * @return float |
|
| 550 | + * @throws \EE_Error |
|
| 551 | + */ |
|
| 552 | 552 | public function get_ticket_taxes_total_for_admin() { |
| 553 | 553 | return EE_Taxes::get_total_taxes_for_admin( $this ); |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | |
| 557 | 557 | |
| 558 | - /** |
|
| 559 | - * Sets name |
|
| 560 | - * |
|
| 561 | - * @param string $name |
|
| 562 | - * @throws \EE_Error |
|
| 563 | - */ |
|
| 558 | + /** |
|
| 559 | + * Sets name |
|
| 560 | + * |
|
| 561 | + * @param string $name |
|
| 562 | + * @throws \EE_Error |
|
| 563 | + */ |
|
| 564 | 564 | public function set_name( $name ) { |
| 565 | 565 | $this->set( 'TKT_name', $name ); |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | |
| 569 | 569 | |
| 570 | - /** |
|
| 571 | - * Gets description |
|
| 572 | - * |
|
| 573 | - * @return string |
|
| 574 | - * @throws \EE_Error |
|
| 575 | - */ |
|
| 570 | + /** |
|
| 571 | + * Gets description |
|
| 572 | + * |
|
| 573 | + * @return string |
|
| 574 | + * @throws \EE_Error |
|
| 575 | + */ |
|
| 576 | 576 | public function description() { |
| 577 | 577 | return $this->get( 'TKT_description' ); |
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | |
| 581 | 581 | |
| 582 | - /** |
|
| 583 | - * Sets description |
|
| 584 | - * |
|
| 585 | - * @param string $description |
|
| 586 | - * @throws \EE_Error |
|
| 587 | - */ |
|
| 582 | + /** |
|
| 583 | + * Sets description |
|
| 584 | + * |
|
| 585 | + * @param string $description |
|
| 586 | + * @throws \EE_Error |
|
| 587 | + */ |
|
| 588 | 588 | public function set_description( $description ) { |
| 589 | 589 | $this->set( 'TKT_description', $description ); |
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | |
| 593 | 593 | |
| 594 | - /** |
|
| 595 | - * Gets start_date |
|
| 596 | - * |
|
| 597 | - * @param string $dt_frmt |
|
| 598 | - * @param string $tm_frmt |
|
| 599 | - * @return string |
|
| 600 | - * @throws \EE_Error |
|
| 601 | - */ |
|
| 594 | + /** |
|
| 595 | + * Gets start_date |
|
| 596 | + * |
|
| 597 | + * @param string $dt_frmt |
|
| 598 | + * @param string $tm_frmt |
|
| 599 | + * @return string |
|
| 600 | + * @throws \EE_Error |
|
| 601 | + */ |
|
| 602 | 602 | public function start_date( $dt_frmt = '', $tm_frmt = '' ) { |
| 603 | 603 | return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt ); |
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | |
| 607 | 607 | |
| 608 | - /** |
|
| 609 | - * Sets start_date |
|
| 610 | - * |
|
| 611 | - * @param string $start_date |
|
| 612 | - * @return void |
|
| 613 | - * @throws \EE_Error |
|
| 614 | - */ |
|
| 608 | + /** |
|
| 609 | + * Sets start_date |
|
| 610 | + * |
|
| 611 | + * @param string $start_date |
|
| 612 | + * @return void |
|
| 613 | + * @throws \EE_Error |
|
| 614 | + */ |
|
| 615 | 615 | public function set_start_date( $start_date ) { |
| 616 | 616 | $this->_set_date_time( 'B', $start_date, 'TKT_start_date' ); |
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | |
| 620 | 620 | |
| 621 | - /** |
|
| 622 | - * Gets end_date |
|
| 623 | - * |
|
| 624 | - * @param string $dt_frmt |
|
| 625 | - * @param string $tm_frmt |
|
| 626 | - * @return string |
|
| 627 | - * @throws \EE_Error |
|
| 628 | - */ |
|
| 621 | + /** |
|
| 622 | + * Gets end_date |
|
| 623 | + * |
|
| 624 | + * @param string $dt_frmt |
|
| 625 | + * @param string $tm_frmt |
|
| 626 | + * @return string |
|
| 627 | + * @throws \EE_Error |
|
| 628 | + */ |
|
| 629 | 629 | public function end_date( $dt_frmt = '', $tm_frmt = '' ) { |
| 630 | 630 | return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt ); |
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | |
| 634 | 634 | |
| 635 | - /** |
|
| 636 | - * Sets end_date |
|
| 637 | - * |
|
| 638 | - * @param string $end_date |
|
| 639 | - * @return void |
|
| 640 | - * @throws \EE_Error |
|
| 641 | - */ |
|
| 635 | + /** |
|
| 636 | + * Sets end_date |
|
| 637 | + * |
|
| 638 | + * @param string $end_date |
|
| 639 | + * @return void |
|
| 640 | + * @throws \EE_Error |
|
| 641 | + */ |
|
| 642 | 642 | public function set_end_date( $end_date ) { |
| 643 | 643 | $this->_set_date_time( 'B', $end_date, 'TKT_end_date' ); |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | |
| 647 | 647 | |
| 648 | - /** |
|
| 649 | - * Sets sell until time |
|
| 650 | - * |
|
| 651 | - * @since 4.5.0 |
|
| 652 | - * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 653 | - * @throws \EE_Error |
|
| 654 | - */ |
|
| 648 | + /** |
|
| 649 | + * Sets sell until time |
|
| 650 | + * |
|
| 651 | + * @since 4.5.0 |
|
| 652 | + * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
| 653 | + * @throws \EE_Error |
|
| 654 | + */ |
|
| 655 | 655 | public function set_end_time( $time ) { |
| 656 | 656 | $this->_set_time_for( $time, 'TKT_end_date' ); |
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | |
| 660 | 660 | |
| 661 | - /** |
|
| 662 | - * Sets min |
|
| 663 | - * |
|
| 664 | - * @param int $min |
|
| 665 | - * @return void |
|
| 666 | - * @throws \EE_Error |
|
| 667 | - */ |
|
| 661 | + /** |
|
| 662 | + * Sets min |
|
| 663 | + * |
|
| 664 | + * @param int $min |
|
| 665 | + * @return void |
|
| 666 | + * @throws \EE_Error |
|
| 667 | + */ |
|
| 668 | 668 | public function set_min( $min ) { |
| 669 | 669 | $this->set( 'TKT_min', $min ); |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | |
| 673 | 673 | |
| 674 | - /** |
|
| 675 | - * Gets max |
|
| 676 | - * |
|
| 677 | - * @return int |
|
| 678 | - * @throws \EE_Error |
|
| 679 | - */ |
|
| 674 | + /** |
|
| 675 | + * Gets max |
|
| 676 | + * |
|
| 677 | + * @return int |
|
| 678 | + * @throws \EE_Error |
|
| 679 | + */ |
|
| 680 | 680 | public function max() { |
| 681 | 681 | return $this->get( 'TKT_max' ); |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | |
| 685 | 685 | |
| 686 | - /** |
|
| 687 | - * Sets max |
|
| 688 | - * |
|
| 689 | - * @param int $max |
|
| 690 | - * @return void |
|
| 691 | - * @throws \EE_Error |
|
| 692 | - */ |
|
| 686 | + /** |
|
| 687 | + * Sets max |
|
| 688 | + * |
|
| 689 | + * @param int $max |
|
| 690 | + * @return void |
|
| 691 | + * @throws \EE_Error |
|
| 692 | + */ |
|
| 693 | 693 | public function set_max( $max ) { |
| 694 | 694 | $this->set( 'TKT_max', $max ); |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | |
| 698 | 698 | |
| 699 | - /** |
|
| 700 | - * Sets price |
|
| 701 | - * |
|
| 702 | - * @param float $price |
|
| 703 | - * @return void |
|
| 704 | - * @throws \EE_Error |
|
| 705 | - */ |
|
| 699 | + /** |
|
| 700 | + * Sets price |
|
| 701 | + * |
|
| 702 | + * @param float $price |
|
| 703 | + * @return void |
|
| 704 | + * @throws \EE_Error |
|
| 705 | + */ |
|
| 706 | 706 | public function set_price( $price ) { |
| 707 | 707 | $this->set( 'TKT_price', $price ); |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | |
| 711 | 711 | |
| 712 | - /** |
|
| 713 | - * Gets sold |
|
| 714 | - * |
|
| 715 | - * @return int |
|
| 716 | - * @throws \EE_Error |
|
| 717 | - */ |
|
| 712 | + /** |
|
| 713 | + * Gets sold |
|
| 714 | + * |
|
| 715 | + * @return int |
|
| 716 | + * @throws \EE_Error |
|
| 717 | + */ |
|
| 718 | 718 | public function sold() { |
| 719 | 719 | return $this->get_raw( 'TKT_sold' ); |
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
| 723 | 723 | |
| 724 | - /** |
|
| 725 | - * Sets sold |
|
| 726 | - * |
|
| 727 | - * @param int $sold |
|
| 728 | - * @return void |
|
| 729 | - * @throws \EE_Error |
|
| 730 | - */ |
|
| 724 | + /** |
|
| 725 | + * Sets sold |
|
| 726 | + * |
|
| 727 | + * @param int $sold |
|
| 728 | + * @return void |
|
| 729 | + * @throws \EE_Error |
|
| 730 | + */ |
|
| 731 | 731 | public function set_sold( $sold ) { |
| 732 | 732 | // sold can not go below zero |
| 733 | 733 | $sold = max( 0, $sold ); |
@@ -736,13 +736,13 @@ discard block |
||
| 736 | 736 | |
| 737 | 737 | |
| 738 | 738 | |
| 739 | - /** |
|
| 740 | - * increments sold by amount passed by $qty |
|
| 741 | - * |
|
| 742 | - * @param int $qty |
|
| 743 | - * @return void |
|
| 744 | - * @throws \EE_Error |
|
| 745 | - */ |
|
| 739 | + /** |
|
| 740 | + * increments sold by amount passed by $qty |
|
| 741 | + * |
|
| 742 | + * @param int $qty |
|
| 743 | + * @return void |
|
| 744 | + * @throws \EE_Error |
|
| 745 | + */ |
|
| 746 | 746 | public function increase_sold( $qty = 1 ) { |
| 747 | 747 | $sold = $this->sold() + $qty; |
| 748 | 748 | // remove ticket reservation, but don't adjust datetime reservations, because that will happen |
@@ -751,22 +751,22 @@ discard block |
||
| 751 | 751 | $this->_increase_sold_for_datetimes( $qty ); |
| 752 | 752 | $this->set_sold( $sold ); |
| 753 | 753 | do_action( |
| 754 | - 'AHEE__EE_Ticket__increase_sold', |
|
| 755 | - $this, |
|
| 756 | - $qty, |
|
| 757 | - $sold |
|
| 758 | - ); |
|
| 754 | + 'AHEE__EE_Ticket__increase_sold', |
|
| 755 | + $this, |
|
| 756 | + $qty, |
|
| 757 | + $sold |
|
| 758 | + ); |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | |
| 762 | 762 | |
| 763 | - /** |
|
| 764 | - * Increases sold on related datetimes |
|
| 765 | - * |
|
| 766 | - * @param int $qty |
|
| 767 | - * @return void |
|
| 768 | - * @throws \EE_Error |
|
| 769 | - */ |
|
| 763 | + /** |
|
| 764 | + * Increases sold on related datetimes |
|
| 765 | + * |
|
| 766 | + * @param int $qty |
|
| 767 | + * @return void |
|
| 768 | + * @throws \EE_Error |
|
| 769 | + */ |
|
| 770 | 770 | protected function _increase_sold_for_datetimes( $qty = 1 ) { |
| 771 | 771 | $datetimes = $this->datetimes(); |
| 772 | 772 | if ( is_array( $datetimes ) ) { |
@@ -781,34 +781,34 @@ discard block |
||
| 781 | 781 | |
| 782 | 782 | |
| 783 | 783 | |
| 784 | - /** |
|
| 785 | - * decrements (subtracts) sold by amount passed by $qty |
|
| 786 | - * |
|
| 787 | - * @param int $qty |
|
| 788 | - * @return void |
|
| 789 | - * @throws \EE_Error |
|
| 790 | - */ |
|
| 784 | + /** |
|
| 785 | + * decrements (subtracts) sold by amount passed by $qty |
|
| 786 | + * |
|
| 787 | + * @param int $qty |
|
| 788 | + * @return void |
|
| 789 | + * @throws \EE_Error |
|
| 790 | + */ |
|
| 791 | 791 | public function decrease_sold( $qty = 1 ) { |
| 792 | 792 | $sold = $this->sold() - $qty; |
| 793 | 793 | $this->_decrease_sold_for_datetimes( $qty ); |
| 794 | 794 | $this->set_sold( $sold ); |
| 795 | - do_action( |
|
| 796 | - 'AHEE__EE_Ticket__decrease_sold', |
|
| 797 | - $this, |
|
| 798 | - $qty, |
|
| 799 | - $sold |
|
| 800 | - ); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - |
|
| 805 | - /** |
|
| 806 | - * Decreases sold on related datetimes |
|
| 807 | - * |
|
| 808 | - * @param int $qty |
|
| 809 | - * @return void |
|
| 810 | - * @throws \EE_Error |
|
| 811 | - */ |
|
| 795 | + do_action( |
|
| 796 | + 'AHEE__EE_Ticket__decrease_sold', |
|
| 797 | + $this, |
|
| 798 | + $qty, |
|
| 799 | + $sold |
|
| 800 | + ); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + |
|
| 805 | + /** |
|
| 806 | + * Decreases sold on related datetimes |
|
| 807 | + * |
|
| 808 | + * @param int $qty |
|
| 809 | + * @return void |
|
| 810 | + * @throws \EE_Error |
|
| 811 | + */ |
|
| 812 | 812 | protected function _decrease_sold_for_datetimes( $qty = 1 ) { |
| 813 | 813 | $datetimes = $this->datetimes(); |
| 814 | 814 | if ( is_array( $datetimes ) ) { |
@@ -823,25 +823,25 @@ discard block |
||
| 823 | 823 | |
| 824 | 824 | |
| 825 | 825 | |
| 826 | - /** |
|
| 827 | - * Gets qty of reserved tickets |
|
| 828 | - * |
|
| 829 | - * @return int |
|
| 830 | - * @throws \EE_Error |
|
| 831 | - */ |
|
| 826 | + /** |
|
| 827 | + * Gets qty of reserved tickets |
|
| 828 | + * |
|
| 829 | + * @return int |
|
| 830 | + * @throws \EE_Error |
|
| 831 | + */ |
|
| 832 | 832 | public function reserved() { |
| 833 | 833 | return $this->get_raw( 'TKT_reserved' ); |
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | |
| 837 | 837 | |
| 838 | - /** |
|
| 839 | - * Sets reserved |
|
| 840 | - * |
|
| 841 | - * @param int $reserved |
|
| 842 | - * @return void |
|
| 843 | - * @throws \EE_Error |
|
| 844 | - */ |
|
| 838 | + /** |
|
| 839 | + * Sets reserved |
|
| 840 | + * |
|
| 841 | + * @param int $reserved |
|
| 842 | + * @return void |
|
| 843 | + * @throws \EE_Error |
|
| 844 | + */ |
|
| 845 | 845 | public function set_reserved( $reserved ) { |
| 846 | 846 | // reserved can not go below zero |
| 847 | 847 | $reserved = max( 0, (int) $reserved ); |
@@ -849,48 +849,48 @@ discard block |
||
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | |
| 852 | - /** |
|
| 853 | - * increments reserved by amount passed by $qty |
|
| 854 | - * |
|
| 855 | - * @param int $qty |
|
| 856 | - * @param string $source |
|
| 857 | - * @return void |
|
| 858 | - * @throws EE_Error |
|
| 859 | - * @throws InvalidArgumentException |
|
| 860 | - * @throws ReflectionException |
|
| 861 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 862 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 863 | - */ |
|
| 852 | + /** |
|
| 853 | + * increments reserved by amount passed by $qty |
|
| 854 | + * |
|
| 855 | + * @param int $qty |
|
| 856 | + * @param string $source |
|
| 857 | + * @return void |
|
| 858 | + * @throws EE_Error |
|
| 859 | + * @throws InvalidArgumentException |
|
| 860 | + * @throws ReflectionException |
|
| 861 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 862 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 863 | + */ |
|
| 864 | 864 | public function increase_reserved( $qty = 1, $source = 'unknown' ) { |
| 865 | 865 | $qty = absint( $qty ); |
| 866 | 866 | $reserved = $this->reserved() + $qty; |
| 867 | - if ( |
|
| 868 | - $reserved |
|
| 869 | - && $this->add_extra_meta( |
|
| 870 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 871 | - "{$qty} from {$source}" |
|
| 872 | - ) |
|
| 873 | - ) { |
|
| 874 | - $this->_increase_reserved_for_datetimes($qty); |
|
| 875 | - $this->set_reserved($reserved); |
|
| 876 | - do_action( |
|
| 877 | - 'AHEE__EE_Ticket__increase_reserved', |
|
| 878 | - $this, |
|
| 879 | - $qty, |
|
| 880 | - $reserved |
|
| 881 | - ); |
|
| 882 | - } |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - |
|
| 886 | - |
|
| 887 | - /** |
|
| 888 | - * Increases sold on related datetimes |
|
| 889 | - * |
|
| 890 | - * @param int $qty |
|
| 891 | - * @return void |
|
| 892 | - * @throws \EE_Error |
|
| 893 | - */ |
|
| 867 | + if ( |
|
| 868 | + $reserved |
|
| 869 | + && $this->add_extra_meta( |
|
| 870 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 871 | + "{$qty} from {$source}" |
|
| 872 | + ) |
|
| 873 | + ) { |
|
| 874 | + $this->_increase_reserved_for_datetimes($qty); |
|
| 875 | + $this->set_reserved($reserved); |
|
| 876 | + do_action( |
|
| 877 | + 'AHEE__EE_Ticket__increase_reserved', |
|
| 878 | + $this, |
|
| 879 | + $qty, |
|
| 880 | + $reserved |
|
| 881 | + ); |
|
| 882 | + } |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + |
|
| 886 | + |
|
| 887 | + /** |
|
| 888 | + * Increases sold on related datetimes |
|
| 889 | + * |
|
| 890 | + * @param int $qty |
|
| 891 | + * @return void |
|
| 892 | + * @throws \EE_Error |
|
| 893 | + */ |
|
| 894 | 894 | protected function _increase_reserved_for_datetimes( $qty = 1 ) { |
| 895 | 895 | $datetimes = $this->datetimes(); |
| 896 | 896 | if ( is_array( $datetimes ) ) { |
@@ -904,49 +904,49 @@ discard block |
||
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | |
| 907 | - /** |
|
| 908 | - * decrements (subtracts) reserved by amount passed by $qty |
|
| 909 | - * |
|
| 910 | - * @param int $qty |
|
| 911 | - * @param bool $adjust_datetimes |
|
| 912 | - * @param string $source |
|
| 913 | - * @return void |
|
| 914 | - * @throws EE_Error |
|
| 915 | - * @throws InvalidArgumentException |
|
| 916 | - * @throws ReflectionException |
|
| 917 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 918 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 919 | - */ |
|
| 907 | + /** |
|
| 908 | + * decrements (subtracts) reserved by amount passed by $qty |
|
| 909 | + * |
|
| 910 | + * @param int $qty |
|
| 911 | + * @param bool $adjust_datetimes |
|
| 912 | + * @param string $source |
|
| 913 | + * @return void |
|
| 914 | + * @throws EE_Error |
|
| 915 | + * @throws InvalidArgumentException |
|
| 916 | + * @throws ReflectionException |
|
| 917 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
| 918 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
| 919 | + */ |
|
| 920 | 920 | public function decrease_reserved( $qty = 1, $adjust_datetimes = true, $source = 'unknown' ) { |
| 921 | 921 | $reserved = $this->reserved() - absint( $qty ); |
| 922 | - if ( |
|
| 923 | - $this->add_extra_meta( |
|
| 924 | - EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 925 | - "-{$qty} from {$source}" |
|
| 926 | - ) |
|
| 927 | - ) { |
|
| 928 | - if ($adjust_datetimes) { |
|
| 929 | - $this->_decrease_reserved_for_datetimes($qty); |
|
| 930 | - } |
|
| 931 | - $this->set_reserved($reserved); |
|
| 932 | - do_action( |
|
| 933 | - 'AHEE__EE_Ticket__decrease_reserved', |
|
| 934 | - $this, |
|
| 935 | - $qty, |
|
| 936 | - $reserved |
|
| 937 | - ); |
|
| 938 | - } |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - |
|
| 942 | - |
|
| 943 | - /** |
|
| 944 | - * Increases sold on related datetimes |
|
| 945 | - * |
|
| 946 | - * @param int $qty |
|
| 947 | - * @return void |
|
| 948 | - * @throws \EE_Error |
|
| 949 | - */ |
|
| 922 | + if ( |
|
| 923 | + $this->add_extra_meta( |
|
| 924 | + EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
|
| 925 | + "-{$qty} from {$source}" |
|
| 926 | + ) |
|
| 927 | + ) { |
|
| 928 | + if ($adjust_datetimes) { |
|
| 929 | + $this->_decrease_reserved_for_datetimes($qty); |
|
| 930 | + } |
|
| 931 | + $this->set_reserved($reserved); |
|
| 932 | + do_action( |
|
| 933 | + 'AHEE__EE_Ticket__decrease_reserved', |
|
| 934 | + $this, |
|
| 935 | + $qty, |
|
| 936 | + $reserved |
|
| 937 | + ); |
|
| 938 | + } |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + |
|
| 942 | + |
|
| 943 | + /** |
|
| 944 | + * Increases sold on related datetimes |
|
| 945 | + * |
|
| 946 | + * @param int $qty |
|
| 947 | + * @return void |
|
| 948 | + * @throws \EE_Error |
|
| 949 | + */ |
|
| 950 | 950 | protected function _decrease_reserved_for_datetimes( $qty = 1 ) { |
| 951 | 951 | $datetimes = $this->datetimes(); |
| 952 | 952 | if ( is_array( $datetimes ) ) { |
@@ -961,18 +961,18 @@ discard block |
||
| 961 | 961 | |
| 962 | 962 | |
| 963 | 963 | |
| 964 | - /** |
|
| 965 | - * Gets ticket quantity |
|
| 966 | - * |
|
| 967 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 968 | - * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 969 | - * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 970 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 971 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 972 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 973 | - * @return int |
|
| 974 | - * @throws \EE_Error |
|
| 975 | - */ |
|
| 964 | + /** |
|
| 965 | + * Gets ticket quantity |
|
| 966 | + * |
|
| 967 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 968 | + * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
| 969 | + * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
| 970 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 971 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 972 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 973 | + * @return int |
|
| 974 | + * @throws \EE_Error |
|
| 975 | + */ |
|
| 976 | 976 | public function qty( $context = '' ) { |
| 977 | 977 | switch ( $context ) { |
| 978 | 978 | case 'reg_limit' : |
@@ -986,19 +986,19 @@ discard block |
||
| 986 | 986 | |
| 987 | 987 | |
| 988 | 988 | |
| 989 | - /** |
|
| 990 | - * Gets ticket quantity |
|
| 991 | - * |
|
| 992 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 993 | - * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 994 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 995 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 996 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 997 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
| 998 | - * set to 0 for all related datetimes |
|
| 999 | - * @return int |
|
| 1000 | - * @throws \EE_Error |
|
| 1001 | - */ |
|
| 989 | + /** |
|
| 990 | + * Gets ticket quantity |
|
| 991 | + * |
|
| 992 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
| 993 | + * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
| 994 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
| 995 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
| 996 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
| 997 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
| 998 | + * set to 0 for all related datetimes |
|
| 999 | + * @return int |
|
| 1000 | + * @throws \EE_Error |
|
| 1001 | + */ |
|
| 1002 | 1002 | public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) { |
| 1003 | 1003 | $raw = $this->get_raw( 'TKT_qty' ); |
| 1004 | 1004 | // return immediately if it's zero |
@@ -1081,212 +1081,212 @@ discard block |
||
| 1081 | 1081 | |
| 1082 | 1082 | |
| 1083 | 1083 | |
| 1084 | - /** |
|
| 1085 | - * Gets uses |
|
| 1086 | - * |
|
| 1087 | - * @return int |
|
| 1088 | - * @throws \EE_Error |
|
| 1089 | - */ |
|
| 1084 | + /** |
|
| 1085 | + * Gets uses |
|
| 1086 | + * |
|
| 1087 | + * @return int |
|
| 1088 | + * @throws \EE_Error |
|
| 1089 | + */ |
|
| 1090 | 1090 | public function uses() { |
| 1091 | 1091 | return $this->get( 'TKT_uses' ); |
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | 1094 | |
| 1095 | 1095 | |
| 1096 | - /** |
|
| 1097 | - * Sets uses |
|
| 1098 | - * |
|
| 1099 | - * @param int $uses |
|
| 1100 | - * @return void |
|
| 1101 | - * @throws \EE_Error |
|
| 1102 | - */ |
|
| 1096 | + /** |
|
| 1097 | + * Sets uses |
|
| 1098 | + * |
|
| 1099 | + * @param int $uses |
|
| 1100 | + * @return void |
|
| 1101 | + * @throws \EE_Error |
|
| 1102 | + */ |
|
| 1103 | 1103 | public function set_uses( $uses ) { |
| 1104 | 1104 | $this->set( 'TKT_uses', $uses ); |
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | 1107 | |
| 1108 | 1108 | |
| 1109 | - /** |
|
| 1110 | - * returns whether ticket is required or not. |
|
| 1111 | - * |
|
| 1112 | - * @return boolean |
|
| 1113 | - * @throws \EE_Error |
|
| 1114 | - */ |
|
| 1109 | + /** |
|
| 1110 | + * returns whether ticket is required or not. |
|
| 1111 | + * |
|
| 1112 | + * @return boolean |
|
| 1113 | + * @throws \EE_Error |
|
| 1114 | + */ |
|
| 1115 | 1115 | public function required() { |
| 1116 | 1116 | return $this->get( 'TKT_required' ); |
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | |
| 1120 | 1120 | |
| 1121 | - /** |
|
| 1122 | - * sets the TKT_required property |
|
| 1123 | - * |
|
| 1124 | - * @param boolean $required |
|
| 1125 | - * @return void |
|
| 1126 | - * @throws \EE_Error |
|
| 1127 | - */ |
|
| 1121 | + /** |
|
| 1122 | + * sets the TKT_required property |
|
| 1123 | + * |
|
| 1124 | + * @param boolean $required |
|
| 1125 | + * @return void |
|
| 1126 | + * @throws \EE_Error |
|
| 1127 | + */ |
|
| 1128 | 1128 | public function set_required( $required ) { |
| 1129 | 1129 | $this->set( 'TKT_required', $required ); |
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | 1132 | |
| 1133 | 1133 | |
| 1134 | - /** |
|
| 1135 | - * Gets taxable |
|
| 1136 | - * |
|
| 1137 | - * @return boolean |
|
| 1138 | - * @throws \EE_Error |
|
| 1139 | - */ |
|
| 1134 | + /** |
|
| 1135 | + * Gets taxable |
|
| 1136 | + * |
|
| 1137 | + * @return boolean |
|
| 1138 | + * @throws \EE_Error |
|
| 1139 | + */ |
|
| 1140 | 1140 | public function taxable() { |
| 1141 | 1141 | return $this->get( 'TKT_taxable' ); |
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | 1144 | |
| 1145 | 1145 | |
| 1146 | - /** |
|
| 1147 | - * Sets taxable |
|
| 1148 | - * |
|
| 1149 | - * @param boolean $taxable |
|
| 1150 | - * @return void |
|
| 1151 | - * @throws \EE_Error |
|
| 1152 | - */ |
|
| 1146 | + /** |
|
| 1147 | + * Sets taxable |
|
| 1148 | + * |
|
| 1149 | + * @param boolean $taxable |
|
| 1150 | + * @return void |
|
| 1151 | + * @throws \EE_Error |
|
| 1152 | + */ |
|
| 1153 | 1153 | public function set_taxable( $taxable ) { |
| 1154 | 1154 | $this->set( 'TKT_taxable', $taxable ); |
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | 1157 | |
| 1158 | 1158 | |
| 1159 | - /** |
|
| 1160 | - * Gets is_default |
|
| 1161 | - * |
|
| 1162 | - * @return boolean |
|
| 1163 | - * @throws \EE_Error |
|
| 1164 | - */ |
|
| 1159 | + /** |
|
| 1160 | + * Gets is_default |
|
| 1161 | + * |
|
| 1162 | + * @return boolean |
|
| 1163 | + * @throws \EE_Error |
|
| 1164 | + */ |
|
| 1165 | 1165 | public function is_default() { |
| 1166 | 1166 | return $this->get( 'TKT_is_default' ); |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | |
| 1170 | 1170 | |
| 1171 | - /** |
|
| 1172 | - * Sets is_default |
|
| 1173 | - * |
|
| 1174 | - * @param boolean $is_default |
|
| 1175 | - * @return void |
|
| 1176 | - * @throws \EE_Error |
|
| 1177 | - */ |
|
| 1171 | + /** |
|
| 1172 | + * Sets is_default |
|
| 1173 | + * |
|
| 1174 | + * @param boolean $is_default |
|
| 1175 | + * @return void |
|
| 1176 | + * @throws \EE_Error |
|
| 1177 | + */ |
|
| 1178 | 1178 | public function set_is_default( $is_default ) { |
| 1179 | 1179 | $this->set( 'TKT_is_default', $is_default ); |
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | |
| 1183 | 1183 | |
| 1184 | - /** |
|
| 1185 | - * Gets order |
|
| 1186 | - * |
|
| 1187 | - * @return int |
|
| 1188 | - * @throws \EE_Error |
|
| 1189 | - */ |
|
| 1184 | + /** |
|
| 1185 | + * Gets order |
|
| 1186 | + * |
|
| 1187 | + * @return int |
|
| 1188 | + * @throws \EE_Error |
|
| 1189 | + */ |
|
| 1190 | 1190 | public function order() { |
| 1191 | 1191 | return $this->get( 'TKT_order' ); |
| 1192 | 1192 | } |
| 1193 | 1193 | |
| 1194 | 1194 | |
| 1195 | 1195 | |
| 1196 | - /** |
|
| 1197 | - * Sets order |
|
| 1198 | - * |
|
| 1199 | - * @param int $order |
|
| 1200 | - * @return void |
|
| 1201 | - * @throws \EE_Error |
|
| 1202 | - */ |
|
| 1196 | + /** |
|
| 1197 | + * Sets order |
|
| 1198 | + * |
|
| 1199 | + * @param int $order |
|
| 1200 | + * @return void |
|
| 1201 | + * @throws \EE_Error |
|
| 1202 | + */ |
|
| 1203 | 1203 | public function set_order( $order ) { |
| 1204 | 1204 | $this->set( 'TKT_order', $order ); |
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | 1207 | |
| 1208 | 1208 | |
| 1209 | - /** |
|
| 1210 | - * Gets row |
|
| 1211 | - * |
|
| 1212 | - * @return int |
|
| 1213 | - * @throws \EE_Error |
|
| 1214 | - */ |
|
| 1209 | + /** |
|
| 1210 | + * Gets row |
|
| 1211 | + * |
|
| 1212 | + * @return int |
|
| 1213 | + * @throws \EE_Error |
|
| 1214 | + */ |
|
| 1215 | 1215 | public function row() { |
| 1216 | 1216 | return $this->get( 'TKT_row' ); |
| 1217 | 1217 | } |
| 1218 | 1218 | |
| 1219 | 1219 | |
| 1220 | 1220 | |
| 1221 | - /** |
|
| 1222 | - * Sets row |
|
| 1223 | - * |
|
| 1224 | - * @param int $row |
|
| 1225 | - * @return void |
|
| 1226 | - * @throws \EE_Error |
|
| 1227 | - */ |
|
| 1221 | + /** |
|
| 1222 | + * Sets row |
|
| 1223 | + * |
|
| 1224 | + * @param int $row |
|
| 1225 | + * @return void |
|
| 1226 | + * @throws \EE_Error |
|
| 1227 | + */ |
|
| 1228 | 1228 | public function set_row( $row ) { |
| 1229 | 1229 | $this->set( 'TKT_row', $row ); |
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | |
| 1233 | 1233 | |
| 1234 | - /** |
|
| 1235 | - * Gets deleted |
|
| 1236 | - * |
|
| 1237 | - * @return boolean |
|
| 1238 | - * @throws \EE_Error |
|
| 1239 | - */ |
|
| 1234 | + /** |
|
| 1235 | + * Gets deleted |
|
| 1236 | + * |
|
| 1237 | + * @return boolean |
|
| 1238 | + * @throws \EE_Error |
|
| 1239 | + */ |
|
| 1240 | 1240 | public function deleted() { |
| 1241 | 1241 | return $this->get( 'TKT_deleted' ); |
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | 1244 | |
| 1245 | 1245 | |
| 1246 | - /** |
|
| 1247 | - * Sets deleted |
|
| 1248 | - * |
|
| 1249 | - * @param boolean $deleted |
|
| 1250 | - * @return void |
|
| 1251 | - * @throws \EE_Error |
|
| 1252 | - */ |
|
| 1246 | + /** |
|
| 1247 | + * Sets deleted |
|
| 1248 | + * |
|
| 1249 | + * @param boolean $deleted |
|
| 1250 | + * @return void |
|
| 1251 | + * @throws \EE_Error |
|
| 1252 | + */ |
|
| 1253 | 1253 | public function set_deleted( $deleted ) { |
| 1254 | 1254 | $this->set( 'TKT_deleted', $deleted ); |
| 1255 | 1255 | } |
| 1256 | 1256 | |
| 1257 | 1257 | |
| 1258 | 1258 | |
| 1259 | - /** |
|
| 1260 | - * Gets parent |
|
| 1261 | - * |
|
| 1262 | - * @return int |
|
| 1263 | - * @throws \EE_Error |
|
| 1264 | - */ |
|
| 1259 | + /** |
|
| 1260 | + * Gets parent |
|
| 1261 | + * |
|
| 1262 | + * @return int |
|
| 1263 | + * @throws \EE_Error |
|
| 1264 | + */ |
|
| 1265 | 1265 | public function parent_ID() { |
| 1266 | 1266 | return $this->get( 'TKT_parent' ); |
| 1267 | 1267 | } |
| 1268 | 1268 | |
| 1269 | 1269 | |
| 1270 | 1270 | |
| 1271 | - /** |
|
| 1272 | - * Sets parent |
|
| 1273 | - * |
|
| 1274 | - * @param int $parent |
|
| 1275 | - * @return void |
|
| 1276 | - * @throws \EE_Error |
|
| 1277 | - */ |
|
| 1271 | + /** |
|
| 1272 | + * Sets parent |
|
| 1273 | + * |
|
| 1274 | + * @param int $parent |
|
| 1275 | + * @return void |
|
| 1276 | + * @throws \EE_Error |
|
| 1277 | + */ |
|
| 1278 | 1278 | public function set_parent_ID( $parent ) { |
| 1279 | 1279 | $this->set( 'TKT_parent', $parent ); |
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | |
| 1283 | 1283 | |
| 1284 | - /** |
|
| 1285 | - * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1286 | - * |
|
| 1287 | - * @return string |
|
| 1288 | - * @throws \EE_Error |
|
| 1289 | - */ |
|
| 1284 | + /** |
|
| 1285 | + * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
| 1286 | + * |
|
| 1287 | + * @return string |
|
| 1288 | + * @throws \EE_Error |
|
| 1289 | + */ |
|
| 1290 | 1290 | public function name_and_info() { |
| 1291 | 1291 | $times = array(); |
| 1292 | 1292 | foreach ( $this->datetimes() as $datetime ) { |
@@ -1297,67 +1297,67 @@ discard block |
||
| 1297 | 1297 | |
| 1298 | 1298 | |
| 1299 | 1299 | |
| 1300 | - /** |
|
| 1301 | - * Gets name |
|
| 1302 | - * |
|
| 1303 | - * @return string |
|
| 1304 | - * @throws \EE_Error |
|
| 1305 | - */ |
|
| 1300 | + /** |
|
| 1301 | + * Gets name |
|
| 1302 | + * |
|
| 1303 | + * @return string |
|
| 1304 | + * @throws \EE_Error |
|
| 1305 | + */ |
|
| 1306 | 1306 | public function name() { |
| 1307 | 1307 | return $this->get( 'TKT_name' ); |
| 1308 | 1308 | } |
| 1309 | 1309 | |
| 1310 | 1310 | |
| 1311 | 1311 | |
| 1312 | - /** |
|
| 1313 | - * Gets price |
|
| 1314 | - * |
|
| 1315 | - * @return float |
|
| 1316 | - * @throws \EE_Error |
|
| 1317 | - */ |
|
| 1312 | + /** |
|
| 1313 | + * Gets price |
|
| 1314 | + * |
|
| 1315 | + * @return float |
|
| 1316 | + * @throws \EE_Error |
|
| 1317 | + */ |
|
| 1318 | 1318 | public function price() { |
| 1319 | 1319 | return $this->get( 'TKT_price' ); |
| 1320 | 1320 | } |
| 1321 | 1321 | |
| 1322 | 1322 | |
| 1323 | 1323 | |
| 1324 | - /** |
|
| 1325 | - * Gets all the registrations for this ticket |
|
| 1326 | - * |
|
| 1327 | - * @param array $query_params like EEM_Base::get_all's |
|
| 1328 | - * @return EE_Registration[]|EE_Base_Class[] |
|
| 1329 | - * @throws \EE_Error |
|
| 1330 | - */ |
|
| 1324 | + /** |
|
| 1325 | + * Gets all the registrations for this ticket |
|
| 1326 | + * |
|
| 1327 | + * @param array $query_params like EEM_Base::get_all's |
|
| 1328 | + * @return EE_Registration[]|EE_Base_Class[] |
|
| 1329 | + * @throws \EE_Error |
|
| 1330 | + */ |
|
| 1331 | 1331 | public function registrations( $query_params = array() ) { |
| 1332 | 1332 | return $this->get_many_related( 'Registration', $query_params ); |
| 1333 | 1333 | } |
| 1334 | 1334 | |
| 1335 | 1335 | |
| 1336 | 1336 | |
| 1337 | - /** |
|
| 1338 | - * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1339 | - * into account |
|
| 1340 | - * |
|
| 1341 | - * @return int |
|
| 1342 | - * @throws \EE_Error |
|
| 1343 | - */ |
|
| 1337 | + /** |
|
| 1338 | + * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
| 1339 | + * into account |
|
| 1340 | + * |
|
| 1341 | + * @return int |
|
| 1342 | + * @throws \EE_Error |
|
| 1343 | + */ |
|
| 1344 | 1344 | public function update_tickets_sold() { |
| 1345 | - $count_regs_for_this_ticket = $this->count_registrations( |
|
| 1346 | - array( |
|
| 1347 | - array( |
|
| 1348 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1349 | - 'REG_deleted' => 0, |
|
| 1350 | - ), |
|
| 1351 | - ) |
|
| 1352 | - ); |
|
| 1353 | - $sold = $this->sold(); |
|
| 1354 | - if ($count_regs_for_this_ticket > $sold) { |
|
| 1355 | - $this->increase_sold($count_regs_for_this_ticket - $sold); |
|
| 1356 | - $this->save(); |
|
| 1357 | - } else if ($count_regs_for_this_ticket < $sold) { |
|
| 1358 | - $this->decrease_sold($count_regs_for_this_ticket - $sold); |
|
| 1359 | - $this->save(); |
|
| 1360 | - } |
|
| 1345 | + $count_regs_for_this_ticket = $this->count_registrations( |
|
| 1346 | + array( |
|
| 1347 | + array( |
|
| 1348 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1349 | + 'REG_deleted' => 0, |
|
| 1350 | + ), |
|
| 1351 | + ) |
|
| 1352 | + ); |
|
| 1353 | + $sold = $this->sold(); |
|
| 1354 | + if ($count_regs_for_this_ticket > $sold) { |
|
| 1355 | + $this->increase_sold($count_regs_for_this_ticket - $sold); |
|
| 1356 | + $this->save(); |
|
| 1357 | + } else if ($count_regs_for_this_ticket < $sold) { |
|
| 1358 | + $this->decrease_sold($count_regs_for_this_ticket - $sold); |
|
| 1359 | + $this->save(); |
|
| 1360 | + } |
|
| 1361 | 1361 | return $count_regs_for_this_ticket; |
| 1362 | 1362 | } |
| 1363 | 1363 | |
@@ -1385,21 +1385,21 @@ discard block |
||
| 1385 | 1385 | |
| 1386 | 1386 | |
| 1387 | 1387 | |
| 1388 | - /** |
|
| 1389 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1390 | - * |
|
| 1391 | - * @see EEI_Event_Relation for comments |
|
| 1392 | - * @return EE_Event |
|
| 1393 | - * @throws \EE_Error |
|
| 1394 | - * @throws UnexpectedEntityException |
|
| 1395 | - */ |
|
| 1388 | + /** |
|
| 1389 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1390 | + * |
|
| 1391 | + * @see EEI_Event_Relation for comments |
|
| 1392 | + * @return EE_Event |
|
| 1393 | + * @throws \EE_Error |
|
| 1394 | + * @throws UnexpectedEntityException |
|
| 1395 | + */ |
|
| 1396 | 1396 | public function get_related_event() { |
| 1397 | 1397 | //get one datetime to use for getting the event |
| 1398 | 1398 | $datetime = $this->first_datetime(); |
| 1399 | 1399 | if ( ! $datetime instanceof \EE_Datetime ) { |
| 1400 | 1400 | throw new UnexpectedEntityException( |
| 1401 | 1401 | $datetime, |
| 1402 | - 'EE_Datetime', |
|
| 1402 | + 'EE_Datetime', |
|
| 1403 | 1403 | sprintf( |
| 1404 | 1404 | __( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
| 1405 | 1405 | $this->name() |
@@ -1410,7 +1410,7 @@ discard block |
||
| 1410 | 1410 | if ( ! $event instanceof \EE_Event ) { |
| 1411 | 1411 | throw new UnexpectedEntityException( |
| 1412 | 1412 | $event, |
| 1413 | - 'EE_Event', |
|
| 1413 | + 'EE_Event', |
|
| 1414 | 1414 | sprintf( |
| 1415 | 1415 | __( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
| 1416 | 1416 | $this->name() |
@@ -1422,14 +1422,14 @@ discard block |
||
| 1422 | 1422 | |
| 1423 | 1423 | |
| 1424 | 1424 | |
| 1425 | - /** |
|
| 1426 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1427 | - * |
|
| 1428 | - * @see EEI_Event_Relation for comments |
|
| 1429 | - * @return string |
|
| 1430 | - * @throws UnexpectedEntityException |
|
| 1431 | - * @throws \EE_Error |
|
| 1432 | - */ |
|
| 1425 | + /** |
|
| 1426 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1427 | + * |
|
| 1428 | + * @see EEI_Event_Relation for comments |
|
| 1429 | + * @return string |
|
| 1430 | + * @throws UnexpectedEntityException |
|
| 1431 | + * @throws \EE_Error |
|
| 1432 | + */ |
|
| 1433 | 1433 | public function get_event_name() { |
| 1434 | 1434 | $event = $this->get_related_event(); |
| 1435 | 1435 | return $event instanceof EE_Event ? $event->name() : ''; |
@@ -1437,28 +1437,28 @@ discard block |
||
| 1437 | 1437 | |
| 1438 | 1438 | |
| 1439 | 1439 | |
| 1440 | - /** |
|
| 1441 | - * Implementation of the EEI_Event_Relation interface method |
|
| 1442 | - * |
|
| 1443 | - * @see EEI_Event_Relation for comments |
|
| 1444 | - * @return int |
|
| 1445 | - * @throws UnexpectedEntityException |
|
| 1446 | - * @throws \EE_Error |
|
| 1447 | - */ |
|
| 1440 | + /** |
|
| 1441 | + * Implementation of the EEI_Event_Relation interface method |
|
| 1442 | + * |
|
| 1443 | + * @see EEI_Event_Relation for comments |
|
| 1444 | + * @return int |
|
| 1445 | + * @throws UnexpectedEntityException |
|
| 1446 | + * @throws \EE_Error |
|
| 1447 | + */ |
|
| 1448 | 1448 | public function get_event_ID() { |
| 1449 | 1449 | $event = $this->get_related_event(); |
| 1450 | 1450 | return $event instanceof EE_Event ? $event->ID() : 0; |
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | 1453 | |
| 1454 | - /** |
|
| 1455 | - * This simply returns whether a ticket can be permanently deleted or not. |
|
| 1456 | - * The criteria for determining this is whether the ticket has any related registrations. |
|
| 1457 | - * If there are none then it can be permanently deleted. |
|
| 1458 | - * |
|
| 1459 | - * @return bool |
|
| 1460 | - */ |
|
| 1454 | + /** |
|
| 1455 | + * This simply returns whether a ticket can be permanently deleted or not. |
|
| 1456 | + * The criteria for determining this is whether the ticket has any related registrations. |
|
| 1457 | + * If there are none then it can be permanently deleted. |
|
| 1458 | + * |
|
| 1459 | + * @return bool |
|
| 1460 | + */ |
|
| 1461 | 1461 | public function is_permanently_deleteable() { |
| 1462 | - return $this->count_registrations() === 0; |
|
| 1463 | - } |
|
| 1462 | + return $this->count_registrations() === 0; |
|
| 1463 | + } |
|
| 1464 | 1464 | } //end EE_Ticket class |
@@ -1,7 +1,7 @@ discard block |
||
| 1 | 1 | <?php use EventEspresso\core\exceptions\UnexpectedEntityException; |
| 2 | 2 | |
| 3 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
| 4 | - exit( 'No direct script access allowed' ); |
|
| 3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
| 4 | + exit('No direct script access allowed'); |
|
| 5 | 5 | } |
| 6 | 6 | /** |
| 7 | 7 | * Event Espresso |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @return EE_Ticket |
| 78 | 78 | * @throws \EE_Error |
| 79 | 79 | */ |
| 80 | - public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
|
| 81 | - $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
|
| 82 | - return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
|
| 80 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) { |
|
| 81 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 82 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * @return EE_Ticket |
| 92 | 92 | * @throws \EE_Error |
| 93 | 93 | */ |
| 94 | - public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
|
| 95 | - return new self( $props_n_values, TRUE, $timezone ); |
|
| 94 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) { |
|
| 95 | + return new self($props_n_values, TRUE, $timezone); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | * @throws \EE_Error |
| 103 | 103 | */ |
| 104 | 104 | public function parent() { |
| 105 | - return $this->get( 'TKT_parent' ); |
|
| 105 | + return $this->get('TKT_parent'); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | |
@@ -114,13 +114,13 @@ discard block |
||
| 114 | 114 | * @return boolean |
| 115 | 115 | * @throws \EE_Error |
| 116 | 116 | */ |
| 117 | - public function available( $DTT_ID = 0 ) { |
|
| 117 | + public function available($DTT_ID = 0) { |
|
| 118 | 118 | // are we checking availability for a particular datetime ? |
| 119 | - if ( $DTT_ID ) { |
|
| 119 | + if ($DTT_ID) { |
|
| 120 | 120 | // get that datetime object |
| 121 | - $datetime = $this->get_first_related( 'Datetime', array( array( 'DTT_ID' => $DTT_ID ) ) ); |
|
| 121 | + $datetime = $this->get_first_related('Datetime', array(array('DTT_ID' => $DTT_ID))); |
|
| 122 | 122 | // if ticket sales for this datetime have exceeded the reg limit... |
| 123 | - if ( $datetime instanceof EE_Datetime && $datetime->sold_out() ) { |
|
| 123 | + if ($datetime instanceof EE_Datetime && $datetime->sold_out()) { |
|
| 124 | 124 | return FALSE; |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -138,22 +138,22 @@ discard block |
||
| 138 | 138 | * @return mixed status int if the display string isn't requested |
| 139 | 139 | * @throws \EE_Error |
| 140 | 140 | */ |
| 141 | - public function ticket_status( $display = FALSE, $remaining = null ) { |
|
| 142 | - $remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining(); |
|
| 143 | - if ( ! $remaining ) { |
|
| 144 | - return $display ? EEH_Template::pretty_status( EE_Ticket::sold_out, FALSE, 'sentence' ) : EE_Ticket::sold_out; |
|
| 141 | + public function ticket_status($display = FALSE, $remaining = null) { |
|
| 142 | + $remaining = is_bool($remaining) ? $remaining : $this->is_remaining(); |
|
| 143 | + if ( ! $remaining) { |
|
| 144 | + return $display ? EEH_Template::pretty_status(EE_Ticket::sold_out, FALSE, 'sentence') : EE_Ticket::sold_out; |
|
| 145 | 145 | } |
| 146 | - if ( $this->get( 'TKT_deleted' ) ) { |
|
| 147 | - return $display ? EEH_Template::pretty_status( EE_Ticket::archived, FALSE, 'sentence' ) : EE_Ticket::archived; |
|
| 146 | + if ($this->get('TKT_deleted')) { |
|
| 147 | + return $display ? EEH_Template::pretty_status(EE_Ticket::archived, FALSE, 'sentence') : EE_Ticket::archived; |
|
| 148 | 148 | } |
| 149 | - if ( $this->is_expired() ) { |
|
| 150 | - return $display ? EEH_Template::pretty_status( EE_Ticket::expired, FALSE, 'sentence' ) : EE_Ticket::expired; |
|
| 149 | + if ($this->is_expired()) { |
|
| 150 | + return $display ? EEH_Template::pretty_status(EE_Ticket::expired, FALSE, 'sentence') : EE_Ticket::expired; |
|
| 151 | 151 | } |
| 152 | - if ( $this->is_pending() ) { |
|
| 153 | - return $display ? EEH_Template::pretty_status( EE_Ticket::pending, FALSE, 'sentence' ) : EE_Ticket::pending; |
|
| 152 | + if ($this->is_pending()) { |
|
| 153 | + return $display ? EEH_Template::pretty_status(EE_Ticket::pending, FALSE, 'sentence') : EE_Ticket::pending; |
|
| 154 | 154 | } |
| 155 | - if ( $this->is_on_sale() ) { |
|
| 156 | - return $display ? EEH_Template::pretty_status( EE_Ticket::onsale, FALSE, 'sentence' ) : EE_Ticket::onsale; |
|
| 155 | + if ($this->is_on_sale()) { |
|
| 156 | + return $display ? EEH_Template::pretty_status(EE_Ticket::onsale, FALSE, 'sentence') : EE_Ticket::onsale; |
|
| 157 | 157 | } |
| 158 | 158 | return ''; |
| 159 | 159 | } |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | * @return boolean true = tickets remaining, false not. |
| 169 | 169 | * @throws \EE_Error |
| 170 | 170 | */ |
| 171 | - public function is_remaining( $DTT_ID = 0 ) { |
|
| 172 | - $num_remaining = $this->remaining( $DTT_ID ); |
|
| 173 | - if ( $num_remaining === 0 ) { |
|
| 171 | + public function is_remaining($DTT_ID = 0) { |
|
| 172 | + $num_remaining = $this->remaining($DTT_ID); |
|
| 173 | + if ($num_remaining === 0) { |
|
| 174 | 174 | return FALSE; |
| 175 | 175 | } |
| 176 | - if ( $num_remaining > 0 && $num_remaining < $this->min() ) { |
|
| 176 | + if ($num_remaining > 0 && $num_remaining < $this->min()) { |
|
| 177 | 177 | return FALSE; |
| 178 | 178 | } |
| 179 | 179 | return TRUE; |
@@ -189,8 +189,8 @@ discard block |
||
| 189 | 189 | * @return int |
| 190 | 190 | * @throws \EE_Error |
| 191 | 191 | */ |
| 192 | - public function remaining( $DTT_ID = 0 ) { |
|
| 193 | - return $this->real_quantity_on_ticket('saleable', $DTT_ID ); |
|
| 192 | + public function remaining($DTT_ID = 0) { |
|
| 193 | + return $this->real_quantity_on_ticket('saleable', $DTT_ID); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @throws \EE_Error |
| 203 | 203 | */ |
| 204 | 204 | public function min() { |
| 205 | - return $this->get( 'TKT_min' ); |
|
| 205 | + return $this->get('TKT_min'); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | * @throws \EE_Error |
| 215 | 215 | */ |
| 216 | 216 | public function is_expired() { |
| 217 | - return ( $this->get_raw( 'TKT_end_date' ) < time() ); |
|
| 217 | + return ($this->get_raw('TKT_end_date') < time()); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | * @throws \EE_Error |
| 227 | 227 | */ |
| 228 | 228 | public function is_pending() { |
| 229 | - return ( $this->get_raw( 'TKT_start_date' ) > time() ); |
|
| 229 | + return ($this->get_raw('TKT_start_date') > time()); |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * @throws \EE_Error |
| 239 | 239 | */ |
| 240 | 240 | public function is_on_sale() { |
| 241 | - return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() ); |
|
| 241 | + return ($this->get_raw('TKT_start_date') < time() && $this->get_raw('TKT_end_date') > time()); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * @return string |
| 252 | 252 | * @throws \EE_Error |
| 253 | 253 | */ |
| 254 | - public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
|
| 255 | - $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : ''; |
|
| 256 | - $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : ''; |
|
| 254 | + public function date_range($dt_frmt = '', $conjunction = ' - ') { |
|
| 255 | + $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date($dt_frmt) : ''; |
|
| 256 | + $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date($dt_frmt) : ''; |
|
| 257 | 257 | |
| 258 | - return $first_date && $last_date ? $first_date . $conjunction . $last_date : ''; |
|
| 258 | + return $first_date && $last_date ? $first_date.$conjunction.$last_date : ''; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | * @throws \EE_Error |
| 268 | 268 | */ |
| 269 | 269 | public function first_datetime() { |
| 270 | - $datetimes = $this->datetimes( array( 'limit' => 1 ) ); |
|
| 271 | - return reset( $datetimes ); |
|
| 270 | + $datetimes = $this->datetimes(array('limit' => 1)); |
|
| 271 | + return reset($datetimes); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | |
@@ -281,11 +281,11 @@ discard block |
||
| 281 | 281 | * @return EE_Datetime[]|EE_Base_Class[] |
| 282 | 282 | * @throws \EE_Error |
| 283 | 283 | */ |
| 284 | - public function datetimes( $query_params = array() ) { |
|
| 285 | - if ( ! isset( $query_params[ 'order_by' ] ) ) { |
|
| 286 | - $query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC'; |
|
| 284 | + public function datetimes($query_params = array()) { |
|
| 285 | + if ( ! isset($query_params['order_by'])) { |
|
| 286 | + $query_params['order_by']['DTT_order'] = 'ASC'; |
|
| 287 | 287 | } |
| 288 | - return $this->get_many_related( 'Datetime', $query_params ); |
|
| 288 | + return $this->get_many_related('Datetime', $query_params); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | |
@@ -297,8 +297,8 @@ discard block |
||
| 297 | 297 | * @throws \EE_Error |
| 298 | 298 | */ |
| 299 | 299 | public function last_datetime() { |
| 300 | - $datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) ); |
|
| 301 | - return end( $datetimes ); |
|
| 300 | + $datetimes = $this->datetimes(array('limit' => 1, 'order_by' => array('DTT_EVT_start' => 'DESC'))); |
|
| 301 | + return end($datetimes); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | |
@@ -316,22 +316,22 @@ discard block |
||
| 316 | 316 | * @return mixed (array|int) how many tickets have sold |
| 317 | 317 | * @throws \EE_Error |
| 318 | 318 | */ |
| 319 | - public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) { |
|
| 319 | + public function tickets_sold($what = 'ticket', $dtt_id = NULL) { |
|
| 320 | 320 | $total = 0; |
| 321 | 321 | $tickets_sold = $this->_all_tickets_sold(); |
| 322 | - switch ( $what ) { |
|
| 322 | + switch ($what) { |
|
| 323 | 323 | case 'ticket' : |
| 324 | - return $tickets_sold[ 'ticket' ]; |
|
| 324 | + return $tickets_sold['ticket']; |
|
| 325 | 325 | break; |
| 326 | 326 | case 'datetime' : |
| 327 | - if ( empty( $tickets_sold[ 'datetime' ] ) ) { |
|
| 327 | + if (empty($tickets_sold['datetime'])) { |
|
| 328 | 328 | return $total; |
| 329 | 329 | } |
| 330 | - if ( ! empty( $dtt_id ) && ! isset( $tickets_sold[ 'datetime' ][ $dtt_id ] ) ) { |
|
| 331 | - EE_Error::add_error( __( 'You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
| 330 | + if ( ! empty($dtt_id) && ! isset($tickets_sold['datetime'][$dtt_id])) { |
|
| 331 | + EE_Error::add_error(__('You\'ve requested the amount of tickets sold for a given ticket and datetime, however there are no records for the datetime id you included. Are you SURE that is a datetime related to this ticket?', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
| 332 | 332 | return $total; |
| 333 | 333 | } |
| 334 | - return empty( $dtt_id ) ? $tickets_sold[ 'datetime' ] : $tickets_sold[ 'datetime' ][ $dtt_id ]; |
|
| 334 | + return empty($dtt_id) ? $tickets_sold['datetime'] : $tickets_sold['datetime'][$dtt_id]; |
|
| 335 | 335 | break; |
| 336 | 336 | default: |
| 337 | 337 | return $total; |
@@ -347,15 +347,15 @@ discard block |
||
| 347 | 347 | * @throws \EE_Error |
| 348 | 348 | */ |
| 349 | 349 | protected function _all_tickets_sold() { |
| 350 | - $datetimes = $this->get_many_related( 'Datetime' ); |
|
| 350 | + $datetimes = $this->get_many_related('Datetime'); |
|
| 351 | 351 | $tickets_sold = array(); |
| 352 | - if ( ! empty( $datetimes ) ) { |
|
| 353 | - foreach ( $datetimes as $datetime ) { |
|
| 354 | - $tickets_sold[ 'datetime' ][ $datetime->ID() ] = $datetime->get( 'DTT_sold' ); |
|
| 352 | + if ( ! empty($datetimes)) { |
|
| 353 | + foreach ($datetimes as $datetime) { |
|
| 354 | + $tickets_sold['datetime'][$datetime->ID()] = $datetime->get('DTT_sold'); |
|
| 355 | 355 | } |
| 356 | 356 | } |
| 357 | 357 | //Tickets sold |
| 358 | - $tickets_sold[ 'ticket' ] = $this->sold(); |
|
| 358 | + $tickets_sold['ticket'] = $this->sold(); |
|
| 359 | 359 | return $tickets_sold; |
| 360 | 360 | } |
| 361 | 361 | |
@@ -368,11 +368,11 @@ discard block |
||
| 368 | 368 | * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
| 369 | 369 | * @throws \EE_Error |
| 370 | 370 | */ |
| 371 | - public function base_price( $return_array = FALSE ) { |
|
| 372 | - $_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price ); |
|
| 371 | + public function base_price($return_array = FALSE) { |
|
| 372 | + $_where = array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price); |
|
| 373 | 373 | return $return_array |
| 374 | - ? $this->get_many_related( 'Price', array( $_where ) ) |
|
| 375 | - : $this->get_first_related( 'Price', array( $_where ) ); |
|
| 374 | + ? $this->get_many_related('Price', array($_where)) |
|
| 375 | + : $this->get_first_related('Price', array($_where)); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | |
@@ -385,8 +385,8 @@ discard block |
||
| 385 | 385 | * @throws \EE_Error |
| 386 | 386 | */ |
| 387 | 387 | public function price_modifiers() { |
| 388 | - $query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) ); |
|
| 389 | - return $this->prices( $query_params ); |
|
| 388 | + $query_params = array(0 => array('Price_Type.PBT_ID' => array('NOT IN', array(EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax)))); |
|
| 389 | + return $this->prices($query_params); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | * @return EE_Price[]|EE_Base_Class[] |
| 399 | 399 | * @throws \EE_Error |
| 400 | 400 | */ |
| 401 | - public function prices( $query_params = array() ) { |
|
| 402 | - return $this->get_many_related( 'Price', $query_params ); |
|
| 401 | + public function prices($query_params = array()) { |
|
| 402 | + return $this->get_many_related('Price', $query_params); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
@@ -411,8 +411,8 @@ discard block |
||
| 411 | 411 | * @return EE_Datetime_Ticket|EE_Base_Class[] |
| 412 | 412 | * @throws \EE_Error |
| 413 | 413 | */ |
| 414 | - public function datetime_tickets( $query_params = array() ) { |
|
| 415 | - return $this->get_many_related( 'Datetime_Ticket', $query_params ); |
|
| 414 | + public function datetime_tickets($query_params = array()) { |
|
| 415 | + return $this->get_many_related('Datetime_Ticket', $query_params); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | |
@@ -425,8 +425,8 @@ discard block |
||
| 425 | 425 | * @return EE_Datetime[] |
| 426 | 426 | * @throws \EE_Error |
| 427 | 427 | */ |
| 428 | - public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) { |
|
| 429 | - return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted ); |
|
| 428 | + public function datetimes_ordered($show_expired = TRUE, $show_deleted = FALSE) { |
|
| 429 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_ticket_ordered_by_DTT_order($this->ID(), $show_expired, $show_deleted); |
|
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | |
@@ -438,7 +438,7 @@ discard block |
||
| 438 | 438 | * @throws \EE_Error |
| 439 | 439 | */ |
| 440 | 440 | public function ID() { |
| 441 | - return $this->get( 'TKT_ID' ); |
|
| 441 | + return $this->get('TKT_ID'); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | * @throws \EE_Error |
| 464 | 464 | */ |
| 465 | 465 | public function template() { |
| 466 | - return $this->get_first_related( 'Ticket_Template' ); |
|
| 466 | + return $this->get_first_related('Ticket_Template'); |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
@@ -485,7 +485,7 @@ discard block |
||
| 485 | 485 | * @throws \EE_Error |
| 486 | 486 | */ |
| 487 | 487 | public function ticket_price() { |
| 488 | - return $this->get( 'TKT_price' ); |
|
| 488 | + return $this->get('TKT_price'); |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | * @throws \EE_Error |
| 496 | 496 | */ |
| 497 | 497 | public function pretty_price() { |
| 498 | - return $this->get_pretty( 'TKT_price' ); |
|
| 498 | + return $this->get_pretty('TKT_price'); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | |
@@ -517,8 +517,8 @@ discard block |
||
| 517 | 517 | * @return float |
| 518 | 518 | * @throws \EE_Error |
| 519 | 519 | */ |
| 520 | - public function get_ticket_total_with_taxes( $no_cache = FALSE ) { |
|
| 521 | - if ($this->_ticket_total_with_taxes === null || $no_cache ) { |
|
| 520 | + public function get_ticket_total_with_taxes($no_cache = FALSE) { |
|
| 521 | + if ($this->_ticket_total_with_taxes === null || $no_cache) { |
|
| 522 | 522 | $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
| 523 | 523 | } |
| 524 | 524 | return (float) $this->_ticket_total_with_taxes; |
@@ -527,7 +527,7 @@ discard block |
||
| 527 | 527 | |
| 528 | 528 | |
| 529 | 529 | public function ensure_TKT_Price_correct() { |
| 530 | - $this->set( 'TKT_price', EE_Taxes::get_subtotal_for_admin( $this ) ); |
|
| 530 | + $this->set('TKT_price', EE_Taxes::get_subtotal_for_admin($this)); |
|
| 531 | 531 | $this->save(); |
| 532 | 532 | } |
| 533 | 533 | |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | * @throws \EE_Error |
| 539 | 539 | */ |
| 540 | 540 | public function get_ticket_subtotal() { |
| 541 | - return EE_Taxes::get_subtotal_for_admin( $this ); |
|
| 541 | + return EE_Taxes::get_subtotal_for_admin($this); |
|
| 542 | 542 | } |
| 543 | 543 | |
| 544 | 544 | |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | * @throws \EE_Error |
| 551 | 551 | */ |
| 552 | 552 | public function get_ticket_taxes_total_for_admin() { |
| 553 | - return EE_Taxes::get_total_taxes_for_admin( $this ); |
|
| 553 | + return EE_Taxes::get_total_taxes_for_admin($this); |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | |
@@ -561,8 +561,8 @@ discard block |
||
| 561 | 561 | * @param string $name |
| 562 | 562 | * @throws \EE_Error |
| 563 | 563 | */ |
| 564 | - public function set_name( $name ) { |
|
| 565 | - $this->set( 'TKT_name', $name ); |
|
| 564 | + public function set_name($name) { |
|
| 565 | + $this->set('TKT_name', $name); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * @throws \EE_Error |
| 575 | 575 | */ |
| 576 | 576 | public function description() { |
| 577 | - return $this->get( 'TKT_description' ); |
|
| 577 | + return $this->get('TKT_description'); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | |
@@ -585,8 +585,8 @@ discard block |
||
| 585 | 585 | * @param string $description |
| 586 | 586 | * @throws \EE_Error |
| 587 | 587 | */ |
| 588 | - public function set_description( $description ) { |
|
| 589 | - $this->set( 'TKT_description', $description ); |
|
| 588 | + public function set_description($description) { |
|
| 589 | + $this->set('TKT_description', $description); |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | |
@@ -599,8 +599,8 @@ discard block |
||
| 599 | 599 | * @return string |
| 600 | 600 | * @throws \EE_Error |
| 601 | 601 | */ |
| 602 | - public function start_date( $dt_frmt = '', $tm_frmt = '' ) { |
|
| 603 | - return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt ); |
|
| 602 | + public function start_date($dt_frmt = '', $tm_frmt = '') { |
|
| 603 | + return $this->_get_datetime('TKT_start_date', $dt_frmt, $tm_frmt); |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | |
@@ -612,8 +612,8 @@ discard block |
||
| 612 | 612 | * @return void |
| 613 | 613 | * @throws \EE_Error |
| 614 | 614 | */ |
| 615 | - public function set_start_date( $start_date ) { |
|
| 616 | - $this->_set_date_time( 'B', $start_date, 'TKT_start_date' ); |
|
| 615 | + public function set_start_date($start_date) { |
|
| 616 | + $this->_set_date_time('B', $start_date, 'TKT_start_date'); |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | |
@@ -626,8 +626,8 @@ discard block |
||
| 626 | 626 | * @return string |
| 627 | 627 | * @throws \EE_Error |
| 628 | 628 | */ |
| 629 | - public function end_date( $dt_frmt = '', $tm_frmt = '' ) { |
|
| 630 | - return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt ); |
|
| 629 | + public function end_date($dt_frmt = '', $tm_frmt = '') { |
|
| 630 | + return $this->_get_datetime('TKT_end_date', $dt_frmt, $tm_frmt); |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | |
@@ -639,8 +639,8 @@ discard block |
||
| 639 | 639 | * @return void |
| 640 | 640 | * @throws \EE_Error |
| 641 | 641 | */ |
| 642 | - public function set_end_date( $end_date ) { |
|
| 643 | - $this->_set_date_time( 'B', $end_date, 'TKT_end_date' ); |
|
| 642 | + public function set_end_date($end_date) { |
|
| 643 | + $this->_set_date_time('B', $end_date, 'TKT_end_date'); |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | |
@@ -652,8 +652,8 @@ discard block |
||
| 652 | 652 | * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
| 653 | 653 | * @throws \EE_Error |
| 654 | 654 | */ |
| 655 | - public function set_end_time( $time ) { |
|
| 656 | - $this->_set_time_for( $time, 'TKT_end_date' ); |
|
| 655 | + public function set_end_time($time) { |
|
| 656 | + $this->_set_time_for($time, 'TKT_end_date'); |
|
| 657 | 657 | } |
| 658 | 658 | |
| 659 | 659 | |
@@ -665,8 +665,8 @@ discard block |
||
| 665 | 665 | * @return void |
| 666 | 666 | * @throws \EE_Error |
| 667 | 667 | */ |
| 668 | - public function set_min( $min ) { |
|
| 669 | - $this->set( 'TKT_min', $min ); |
|
| 668 | + public function set_min($min) { |
|
| 669 | + $this->set('TKT_min', $min); |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | |
@@ -678,7 +678,7 @@ discard block |
||
| 678 | 678 | * @throws \EE_Error |
| 679 | 679 | */ |
| 680 | 680 | public function max() { |
| 681 | - return $this->get( 'TKT_max' ); |
|
| 681 | + return $this->get('TKT_max'); |
|
| 682 | 682 | } |
| 683 | 683 | |
| 684 | 684 | |
@@ -690,8 +690,8 @@ discard block |
||
| 690 | 690 | * @return void |
| 691 | 691 | * @throws \EE_Error |
| 692 | 692 | */ |
| 693 | - public function set_max( $max ) { |
|
| 694 | - $this->set( 'TKT_max', $max ); |
|
| 693 | + public function set_max($max) { |
|
| 694 | + $this->set('TKT_max', $max); |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | |
@@ -703,8 +703,8 @@ discard block |
||
| 703 | 703 | * @return void |
| 704 | 704 | * @throws \EE_Error |
| 705 | 705 | */ |
| 706 | - public function set_price( $price ) { |
|
| 707 | - $this->set( 'TKT_price', $price ); |
|
| 706 | + public function set_price($price) { |
|
| 707 | + $this->set('TKT_price', $price); |
|
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | |
@@ -716,7 +716,7 @@ discard block |
||
| 716 | 716 | * @throws \EE_Error |
| 717 | 717 | */ |
| 718 | 718 | public function sold() { |
| 719 | - return $this->get_raw( 'TKT_sold' ); |
|
| 719 | + return $this->get_raw('TKT_sold'); |
|
| 720 | 720 | } |
| 721 | 721 | |
| 722 | 722 | |
@@ -728,10 +728,10 @@ discard block |
||
| 728 | 728 | * @return void |
| 729 | 729 | * @throws \EE_Error |
| 730 | 730 | */ |
| 731 | - public function set_sold( $sold ) { |
|
| 731 | + public function set_sold($sold) { |
|
| 732 | 732 | // sold can not go below zero |
| 733 | - $sold = max( 0, $sold ); |
|
| 734 | - $this->set( 'TKT_sold', $sold ); |
|
| 733 | + $sold = max(0, $sold); |
|
| 734 | + $this->set('TKT_sold', $sold); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | |
@@ -743,13 +743,13 @@ discard block |
||
| 743 | 743 | * @return void |
| 744 | 744 | * @throws \EE_Error |
| 745 | 745 | */ |
| 746 | - public function increase_sold( $qty = 1 ) { |
|
| 746 | + public function increase_sold($qty = 1) { |
|
| 747 | 747 | $sold = $this->sold() + $qty; |
| 748 | 748 | // remove ticket reservation, but don't adjust datetime reservations, because that will happen |
| 749 | 749 | // via \EE_Datetime::increase_sold() when \EE_Ticket::_increase_sold_for_datetimes() is called |
| 750 | - $this->decrease_reserved( $qty, false, "TKT: {$this->ID()} (ln:" . __LINE__ . ')'); |
|
| 751 | - $this->_increase_sold_for_datetimes( $qty ); |
|
| 752 | - $this->set_sold( $sold ); |
|
| 750 | + $this->decrease_reserved($qty, false, "TKT: {$this->ID()} (ln:".__LINE__.')'); |
|
| 751 | + $this->_increase_sold_for_datetimes($qty); |
|
| 752 | + $this->set_sold($sold); |
|
| 753 | 753 | do_action( |
| 754 | 754 | 'AHEE__EE_Ticket__increase_sold', |
| 755 | 755 | $this, |
@@ -767,12 +767,12 @@ discard block |
||
| 767 | 767 | * @return void |
| 768 | 768 | * @throws \EE_Error |
| 769 | 769 | */ |
| 770 | - protected function _increase_sold_for_datetimes( $qty = 1 ) { |
|
| 770 | + protected function _increase_sold_for_datetimes($qty = 1) { |
|
| 771 | 771 | $datetimes = $this->datetimes(); |
| 772 | - if ( is_array( $datetimes ) ) { |
|
| 773 | - foreach ( $datetimes as $datetime ) { |
|
| 774 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 775 | - $datetime->increase_sold( $qty ); |
|
| 772 | + if (is_array($datetimes)) { |
|
| 773 | + foreach ($datetimes as $datetime) { |
|
| 774 | + if ($datetime instanceof EE_Datetime) { |
|
| 775 | + $datetime->increase_sold($qty); |
|
| 776 | 776 | $datetime->save(); |
| 777 | 777 | } |
| 778 | 778 | } |
@@ -788,10 +788,10 @@ discard block |
||
| 788 | 788 | * @return void |
| 789 | 789 | * @throws \EE_Error |
| 790 | 790 | */ |
| 791 | - public function decrease_sold( $qty = 1 ) { |
|
| 791 | + public function decrease_sold($qty = 1) { |
|
| 792 | 792 | $sold = $this->sold() - $qty; |
| 793 | - $this->_decrease_sold_for_datetimes( $qty ); |
|
| 794 | - $this->set_sold( $sold ); |
|
| 793 | + $this->_decrease_sold_for_datetimes($qty); |
|
| 794 | + $this->set_sold($sold); |
|
| 795 | 795 | do_action( |
| 796 | 796 | 'AHEE__EE_Ticket__decrease_sold', |
| 797 | 797 | $this, |
@@ -809,12 +809,12 @@ discard block |
||
| 809 | 809 | * @return void |
| 810 | 810 | * @throws \EE_Error |
| 811 | 811 | */ |
| 812 | - protected function _decrease_sold_for_datetimes( $qty = 1 ) { |
|
| 812 | + protected function _decrease_sold_for_datetimes($qty = 1) { |
|
| 813 | 813 | $datetimes = $this->datetimes(); |
| 814 | - if ( is_array( $datetimes ) ) { |
|
| 815 | - foreach ( $datetimes as $datetime ) { |
|
| 816 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 817 | - $datetime->decrease_sold( $qty ); |
|
| 814 | + if (is_array($datetimes)) { |
|
| 815 | + foreach ($datetimes as $datetime) { |
|
| 816 | + if ($datetime instanceof EE_Datetime) { |
|
| 817 | + $datetime->decrease_sold($qty); |
|
| 818 | 818 | $datetime->save(); |
| 819 | 819 | } |
| 820 | 820 | } |
@@ -830,7 +830,7 @@ discard block |
||
| 830 | 830 | * @throws \EE_Error |
| 831 | 831 | */ |
| 832 | 832 | public function reserved() { |
| 833 | - return $this->get_raw( 'TKT_reserved' ); |
|
| 833 | + return $this->get_raw('TKT_reserved'); |
|
| 834 | 834 | } |
| 835 | 835 | |
| 836 | 836 | |
@@ -842,10 +842,10 @@ discard block |
||
| 842 | 842 | * @return void |
| 843 | 843 | * @throws \EE_Error |
| 844 | 844 | */ |
| 845 | - public function set_reserved( $reserved ) { |
|
| 845 | + public function set_reserved($reserved) { |
|
| 846 | 846 | // reserved can not go below zero |
| 847 | - $reserved = max( 0, (int) $reserved ); |
|
| 848 | - $this->set( 'TKT_reserved', $reserved ); |
|
| 847 | + $reserved = max(0, (int) $reserved); |
|
| 848 | + $this->set('TKT_reserved', $reserved); |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | |
@@ -861,8 +861,8 @@ discard block |
||
| 861 | 861 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
| 862 | 862 | * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
| 863 | 863 | */ |
| 864 | - public function increase_reserved( $qty = 1, $source = 'unknown' ) { |
|
| 865 | - $qty = absint( $qty ); |
|
| 864 | + public function increase_reserved($qty = 1, $source = 'unknown') { |
|
| 865 | + $qty = absint($qty); |
|
| 866 | 866 | $reserved = $this->reserved() + $qty; |
| 867 | 867 | if ( |
| 868 | 868 | $reserved |
@@ -891,12 +891,12 @@ discard block |
||
| 891 | 891 | * @return void |
| 892 | 892 | * @throws \EE_Error |
| 893 | 893 | */ |
| 894 | - protected function _increase_reserved_for_datetimes( $qty = 1 ) { |
|
| 894 | + protected function _increase_reserved_for_datetimes($qty = 1) { |
|
| 895 | 895 | $datetimes = $this->datetimes(); |
| 896 | - if ( is_array( $datetimes ) ) { |
|
| 897 | - foreach ( $datetimes as $datetime ) { |
|
| 898 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 899 | - $datetime->increase_reserved( $qty ); |
|
| 896 | + if (is_array($datetimes)) { |
|
| 897 | + foreach ($datetimes as $datetime) { |
|
| 898 | + if ($datetime instanceof EE_Datetime) { |
|
| 899 | + $datetime->increase_reserved($qty); |
|
| 900 | 900 | $datetime->save(); |
| 901 | 901 | } |
| 902 | 902 | } |
@@ -917,8 +917,8 @@ discard block |
||
| 917 | 917 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
| 918 | 918 | * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
| 919 | 919 | */ |
| 920 | - public function decrease_reserved( $qty = 1, $adjust_datetimes = true, $source = 'unknown' ) { |
|
| 921 | - $reserved = $this->reserved() - absint( $qty ); |
|
| 920 | + public function decrease_reserved($qty = 1, $adjust_datetimes = true, $source = 'unknown') { |
|
| 921 | + $reserved = $this->reserved() - absint($qty); |
|
| 922 | 922 | if ( |
| 923 | 923 | $this->add_extra_meta( |
| 924 | 924 | EE_Ticket::META_KEY_TICKET_RESERVATIONS, |
@@ -947,12 +947,12 @@ discard block |
||
| 947 | 947 | * @return void |
| 948 | 948 | * @throws \EE_Error |
| 949 | 949 | */ |
| 950 | - protected function _decrease_reserved_for_datetimes( $qty = 1 ) { |
|
| 950 | + protected function _decrease_reserved_for_datetimes($qty = 1) { |
|
| 951 | 951 | $datetimes = $this->datetimes(); |
| 952 | - if ( is_array( $datetimes ) ) { |
|
| 953 | - foreach ( $datetimes as $datetime ) { |
|
| 954 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 955 | - $datetime->decrease_reserved( $qty ); |
|
| 952 | + if (is_array($datetimes)) { |
|
| 953 | + foreach ($datetimes as $datetime) { |
|
| 954 | + if ($datetime instanceof EE_Datetime) { |
|
| 955 | + $datetime->decrease_reserved($qty); |
|
| 956 | 956 | $datetime->save(); |
| 957 | 957 | } |
| 958 | 958 | } |
@@ -973,14 +973,14 @@ discard block |
||
| 973 | 973 | * @return int |
| 974 | 974 | * @throws \EE_Error |
| 975 | 975 | */ |
| 976 | - public function qty( $context = '' ) { |
|
| 977 | - switch ( $context ) { |
|
| 976 | + public function qty($context = '') { |
|
| 977 | + switch ($context) { |
|
| 978 | 978 | case 'reg_limit' : |
| 979 | 979 | return $this->real_quantity_on_ticket(); |
| 980 | 980 | case 'saleable' : |
| 981 | - return $this->real_quantity_on_ticket( 'saleable' ); |
|
| 981 | + return $this->real_quantity_on_ticket('saleable'); |
|
| 982 | 982 | default: |
| 983 | - return $this->get_raw( 'TKT_qty' ); |
|
| 983 | + return $this->get_raw('TKT_qty'); |
|
| 984 | 984 | } |
| 985 | 985 | } |
| 986 | 986 | |
@@ -999,15 +999,15 @@ discard block |
||
| 999 | 999 | * @return int |
| 1000 | 1000 | * @throws \EE_Error |
| 1001 | 1001 | */ |
| 1002 | - public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) { |
|
| 1003 | - $raw = $this->get_raw( 'TKT_qty' ); |
|
| 1002 | + public function real_quantity_on_ticket($context = 'reg_limit', $DTT_ID = 0) { |
|
| 1003 | + $raw = $this->get_raw('TKT_qty'); |
|
| 1004 | 1004 | // return immediately if it's zero |
| 1005 | - if ( $raw === 0 ) { |
|
| 1005 | + if ($raw === 0) { |
|
| 1006 | 1006 | return $raw; |
| 1007 | 1007 | } |
| 1008 | 1008 | //echo "\n\n<br />Ticket: " . $this->name() . '<br />'; |
| 1009 | 1009 | // ensure qty doesn't exceed raw value for THIS ticket |
| 1010 | - $qty = min( EE_INF, $raw ); |
|
| 1010 | + $qty = min(EE_INF, $raw); |
|
| 1011 | 1011 | //echo "\n . qty: " . $qty . '<br />'; |
| 1012 | 1012 | // calculate this ticket's total sales and reservations |
| 1013 | 1013 | $sold_and_reserved_for_this_ticket = $this->sold() + $this->reserved(); |
@@ -1016,23 +1016,23 @@ discard block |
||
| 1016 | 1016 | //echo "\n . sold_and_reserved_for_this_ticket: " . $sold_and_reserved_for_this_ticket . '<br />'; |
| 1017 | 1017 | // first we need to calculate the maximum number of tickets available for the datetime |
| 1018 | 1018 | // do we want data for one datetime or all of them ? |
| 1019 | - $query_params = $DTT_ID ? array( array( 'DTT_ID' => $DTT_ID ) ) : array(); |
|
| 1020 | - $datetimes = $this->datetimes( $query_params ); |
|
| 1021 | - if ( is_array( $datetimes ) && ! empty( $datetimes ) ) { |
|
| 1022 | - foreach ( $datetimes as $datetime ) { |
|
| 1023 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 1019 | + $query_params = $DTT_ID ? array(array('DTT_ID' => $DTT_ID)) : array(); |
|
| 1020 | + $datetimes = $this->datetimes($query_params); |
|
| 1021 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 1022 | + foreach ($datetimes as $datetime) { |
|
| 1023 | + if ($datetime instanceof EE_Datetime) { |
|
| 1024 | 1024 | $datetime->refresh_from_db(); |
| 1025 | 1025 | //echo "\n . . datetime name: " . $datetime->name() . '<br />'; |
| 1026 | 1026 | //echo "\n . . datetime ID: " . $datetime->ID() . '<br />'; |
| 1027 | 1027 | // initialize with no restrictions for each datetime |
| 1028 | 1028 | // but adjust datetime qty based on datetime reg limit |
| 1029 | - $datetime_qty = min( EE_INF, $datetime->reg_limit() ); |
|
| 1029 | + $datetime_qty = min(EE_INF, $datetime->reg_limit()); |
|
| 1030 | 1030 | //echo "\n . . . datetime reg_limit: " . $datetime->reg_limit() . '<br />'; |
| 1031 | 1031 | //echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
| 1032 | 1032 | // if we want the actual saleable amount, then we need to consider OTHER ticket sales |
| 1033 | 1033 | // and reservations for this datetime, that do NOT include sales and reservations |
| 1034 | 1034 | // for this ticket (so we add $this->sold() and $this->reserved() back in) |
| 1035 | - if ( $context === 'saleable' ) { |
|
| 1035 | + if ($context === 'saleable') { |
|
| 1036 | 1036 | $datetime_qty = max( |
| 1037 | 1037 | $datetime_qty - $datetime->sold_and_reserved() + $sold_and_reserved_for_this_ticket, |
| 1038 | 1038 | 0 |
@@ -1044,16 +1044,16 @@ discard block |
||
| 1044 | 1044 | $datetime_qty = ! $datetime->sold_out() ? $datetime_qty : 0; |
| 1045 | 1045 | //echo "\n . . . datetime_qty: " . $datetime_qty . '<br />'; |
| 1046 | 1046 | } |
| 1047 | - $qty = min( $datetime_qty, $qty ); |
|
| 1047 | + $qty = min($datetime_qty, $qty); |
|
| 1048 | 1048 | //echo "\n . . qty: " . $qty . '<br />'; |
| 1049 | 1049 | } |
| 1050 | 1050 | } |
| 1051 | 1051 | } |
| 1052 | 1052 | // NOW that we know the maximum number of tickets available for the datetime |
| 1053 | 1053 | // we can finally factor in the details for this specific ticket |
| 1054 | - if ( $qty > 0 && $context === 'saleable' ) { |
|
| 1054 | + if ($qty > 0 && $context === 'saleable') { |
|
| 1055 | 1055 | // and subtract the sales for THIS ticket |
| 1056 | - $qty = max( $qty - $sold_and_reserved_for_this_ticket, 0 ); |
|
| 1056 | + $qty = max($qty - $sold_and_reserved_for_this_ticket, 0); |
|
| 1057 | 1057 | //echo "\n . qty: " . $qty . '<br />'; |
| 1058 | 1058 | } |
| 1059 | 1059 | //echo "\nFINAL QTY: " . $qty . "<br /><br />"; |
@@ -1069,14 +1069,14 @@ discard block |
||
| 1069 | 1069 | * @return void |
| 1070 | 1070 | * @throws \EE_Error |
| 1071 | 1071 | */ |
| 1072 | - public function set_qty( $qty ) { |
|
| 1072 | + public function set_qty($qty) { |
|
| 1073 | 1073 | $datetimes = $this->datetimes(); |
| 1074 | - foreach ( $datetimes as $datetime ) { |
|
| 1075 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 1076 | - $qty = min( $qty, $datetime->reg_limit() ); |
|
| 1074 | + foreach ($datetimes as $datetime) { |
|
| 1075 | + if ($datetime instanceof EE_Datetime) { |
|
| 1076 | + $qty = min($qty, $datetime->reg_limit()); |
|
| 1077 | 1077 | } |
| 1078 | 1078 | } |
| 1079 | - $this->set( 'TKT_qty', $qty ); |
|
| 1079 | + $this->set('TKT_qty', $qty); |
|
| 1080 | 1080 | } |
| 1081 | 1081 | |
| 1082 | 1082 | |
@@ -1088,7 +1088,7 @@ discard block |
||
| 1088 | 1088 | * @throws \EE_Error |
| 1089 | 1089 | */ |
| 1090 | 1090 | public function uses() { |
| 1091 | - return $this->get( 'TKT_uses' ); |
|
| 1091 | + return $this->get('TKT_uses'); |
|
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | 1094 | |
@@ -1100,8 +1100,8 @@ discard block |
||
| 1100 | 1100 | * @return void |
| 1101 | 1101 | * @throws \EE_Error |
| 1102 | 1102 | */ |
| 1103 | - public function set_uses( $uses ) { |
|
| 1104 | - $this->set( 'TKT_uses', $uses ); |
|
| 1103 | + public function set_uses($uses) { |
|
| 1104 | + $this->set('TKT_uses', $uses); |
|
| 1105 | 1105 | } |
| 1106 | 1106 | |
| 1107 | 1107 | |
@@ -1113,7 +1113,7 @@ discard block |
||
| 1113 | 1113 | * @throws \EE_Error |
| 1114 | 1114 | */ |
| 1115 | 1115 | public function required() { |
| 1116 | - return $this->get( 'TKT_required' ); |
|
| 1116 | + return $this->get('TKT_required'); |
|
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | |
@@ -1125,8 +1125,8 @@ discard block |
||
| 1125 | 1125 | * @return void |
| 1126 | 1126 | * @throws \EE_Error |
| 1127 | 1127 | */ |
| 1128 | - public function set_required( $required ) { |
|
| 1129 | - $this->set( 'TKT_required', $required ); |
|
| 1128 | + public function set_required($required) { |
|
| 1129 | + $this->set('TKT_required', $required); |
|
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | 1132 | |
@@ -1138,7 +1138,7 @@ discard block |
||
| 1138 | 1138 | * @throws \EE_Error |
| 1139 | 1139 | */ |
| 1140 | 1140 | public function taxable() { |
| 1141 | - return $this->get( 'TKT_taxable' ); |
|
| 1141 | + return $this->get('TKT_taxable'); |
|
| 1142 | 1142 | } |
| 1143 | 1143 | |
| 1144 | 1144 | |
@@ -1150,8 +1150,8 @@ discard block |
||
| 1150 | 1150 | * @return void |
| 1151 | 1151 | * @throws \EE_Error |
| 1152 | 1152 | */ |
| 1153 | - public function set_taxable( $taxable ) { |
|
| 1154 | - $this->set( 'TKT_taxable', $taxable ); |
|
| 1153 | + public function set_taxable($taxable) { |
|
| 1154 | + $this->set('TKT_taxable', $taxable); |
|
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | 1157 | |
@@ -1163,7 +1163,7 @@ discard block |
||
| 1163 | 1163 | * @throws \EE_Error |
| 1164 | 1164 | */ |
| 1165 | 1165 | public function is_default() { |
| 1166 | - return $this->get( 'TKT_is_default' ); |
|
| 1166 | + return $this->get('TKT_is_default'); |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | |
@@ -1175,8 +1175,8 @@ discard block |
||
| 1175 | 1175 | * @return void |
| 1176 | 1176 | * @throws \EE_Error |
| 1177 | 1177 | */ |
| 1178 | - public function set_is_default( $is_default ) { |
|
| 1179 | - $this->set( 'TKT_is_default', $is_default ); |
|
| 1178 | + public function set_is_default($is_default) { |
|
| 1179 | + $this->set('TKT_is_default', $is_default); |
|
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | |
@@ -1188,7 +1188,7 @@ discard block |
||
| 1188 | 1188 | * @throws \EE_Error |
| 1189 | 1189 | */ |
| 1190 | 1190 | public function order() { |
| 1191 | - return $this->get( 'TKT_order' ); |
|
| 1191 | + return $this->get('TKT_order'); |
|
| 1192 | 1192 | } |
| 1193 | 1193 | |
| 1194 | 1194 | |
@@ -1200,8 +1200,8 @@ discard block |
||
| 1200 | 1200 | * @return void |
| 1201 | 1201 | * @throws \EE_Error |
| 1202 | 1202 | */ |
| 1203 | - public function set_order( $order ) { |
|
| 1204 | - $this->set( 'TKT_order', $order ); |
|
| 1203 | + public function set_order($order) { |
|
| 1204 | + $this->set('TKT_order', $order); |
|
| 1205 | 1205 | } |
| 1206 | 1206 | |
| 1207 | 1207 | |
@@ -1213,7 +1213,7 @@ discard block |
||
| 1213 | 1213 | * @throws \EE_Error |
| 1214 | 1214 | */ |
| 1215 | 1215 | public function row() { |
| 1216 | - return $this->get( 'TKT_row' ); |
|
| 1216 | + return $this->get('TKT_row'); |
|
| 1217 | 1217 | } |
| 1218 | 1218 | |
| 1219 | 1219 | |
@@ -1225,8 +1225,8 @@ discard block |
||
| 1225 | 1225 | * @return void |
| 1226 | 1226 | * @throws \EE_Error |
| 1227 | 1227 | */ |
| 1228 | - public function set_row( $row ) { |
|
| 1229 | - $this->set( 'TKT_row', $row ); |
|
| 1228 | + public function set_row($row) { |
|
| 1229 | + $this->set('TKT_row', $row); |
|
| 1230 | 1230 | } |
| 1231 | 1231 | |
| 1232 | 1232 | |
@@ -1238,7 +1238,7 @@ discard block |
||
| 1238 | 1238 | * @throws \EE_Error |
| 1239 | 1239 | */ |
| 1240 | 1240 | public function deleted() { |
| 1241 | - return $this->get( 'TKT_deleted' ); |
|
| 1241 | + return $this->get('TKT_deleted'); |
|
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | 1244 | |
@@ -1250,8 +1250,8 @@ discard block |
||
| 1250 | 1250 | * @return void |
| 1251 | 1251 | * @throws \EE_Error |
| 1252 | 1252 | */ |
| 1253 | - public function set_deleted( $deleted ) { |
|
| 1254 | - $this->set( 'TKT_deleted', $deleted ); |
|
| 1253 | + public function set_deleted($deleted) { |
|
| 1254 | + $this->set('TKT_deleted', $deleted); |
|
| 1255 | 1255 | } |
| 1256 | 1256 | |
| 1257 | 1257 | |
@@ -1263,7 +1263,7 @@ discard block |
||
| 1263 | 1263 | * @throws \EE_Error |
| 1264 | 1264 | */ |
| 1265 | 1265 | public function parent_ID() { |
| 1266 | - return $this->get( 'TKT_parent' ); |
|
| 1266 | + return $this->get('TKT_parent'); |
|
| 1267 | 1267 | } |
| 1268 | 1268 | |
| 1269 | 1269 | |
@@ -1275,8 +1275,8 @@ discard block |
||
| 1275 | 1275 | * @return void |
| 1276 | 1276 | * @throws \EE_Error |
| 1277 | 1277 | */ |
| 1278 | - public function set_parent_ID( $parent ) { |
|
| 1279 | - $this->set( 'TKT_parent', $parent ); |
|
| 1278 | + public function set_parent_ID($parent) { |
|
| 1279 | + $this->set('TKT_parent', $parent); |
|
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | 1282 | |
@@ -1289,10 +1289,10 @@ discard block |
||
| 1289 | 1289 | */ |
| 1290 | 1290 | public function name_and_info() { |
| 1291 | 1291 | $times = array(); |
| 1292 | - foreach ( $this->datetimes() as $datetime ) { |
|
| 1292 | + foreach ($this->datetimes() as $datetime) { |
|
| 1293 | 1293 | $times[] = $datetime->start_date_and_time(); |
| 1294 | 1294 | } |
| 1295 | - return $this->name() . ' @ ' . implode( ', ', $times ) . ' for ' . $this->pretty_price(); |
|
| 1295 | + return $this->name().' @ '.implode(', ', $times).' for '.$this->pretty_price(); |
|
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | 1298 | |
@@ -1304,7 +1304,7 @@ discard block |
||
| 1304 | 1304 | * @throws \EE_Error |
| 1305 | 1305 | */ |
| 1306 | 1306 | public function name() { |
| 1307 | - return $this->get( 'TKT_name' ); |
|
| 1307 | + return $this->get('TKT_name'); |
|
| 1308 | 1308 | } |
| 1309 | 1309 | |
| 1310 | 1310 | |
@@ -1316,7 +1316,7 @@ discard block |
||
| 1316 | 1316 | * @throws \EE_Error |
| 1317 | 1317 | */ |
| 1318 | 1318 | public function price() { |
| 1319 | - return $this->get( 'TKT_price' ); |
|
| 1319 | + return $this->get('TKT_price'); |
|
| 1320 | 1320 | } |
| 1321 | 1321 | |
| 1322 | 1322 | |
@@ -1328,8 +1328,8 @@ discard block |
||
| 1328 | 1328 | * @return EE_Registration[]|EE_Base_Class[] |
| 1329 | 1329 | * @throws \EE_Error |
| 1330 | 1330 | */ |
| 1331 | - public function registrations( $query_params = array() ) { |
|
| 1332 | - return $this->get_many_related( 'Registration', $query_params ); |
|
| 1331 | + public function registrations($query_params = array()) { |
|
| 1332 | + return $this->get_many_related('Registration', $query_params); |
|
| 1333 | 1333 | } |
| 1334 | 1334 | |
| 1335 | 1335 | |
@@ -1368,7 +1368,7 @@ discard block |
||
| 1368 | 1368 | * @param array $query_params like EEM_Base::get_all's |
| 1369 | 1369 | * @return int |
| 1370 | 1370 | */ |
| 1371 | - public function count_registrations( $query_params = array() ) { |
|
| 1371 | + public function count_registrations($query_params = array()) { |
|
| 1372 | 1372 | return $this->count_related('Registration', $query_params); |
| 1373 | 1373 | } |
| 1374 | 1374 | |
@@ -1396,23 +1396,23 @@ discard block |
||
| 1396 | 1396 | public function get_related_event() { |
| 1397 | 1397 | //get one datetime to use for getting the event |
| 1398 | 1398 | $datetime = $this->first_datetime(); |
| 1399 | - if ( ! $datetime instanceof \EE_Datetime ) { |
|
| 1399 | + if ( ! $datetime instanceof \EE_Datetime) { |
|
| 1400 | 1400 | throw new UnexpectedEntityException( |
| 1401 | 1401 | $datetime, |
| 1402 | 1402 | 'EE_Datetime', |
| 1403 | 1403 | sprintf( |
| 1404 | - __( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1404 | + __('The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
|
| 1405 | 1405 | $this->name() |
| 1406 | 1406 | ) |
| 1407 | 1407 | ); |
| 1408 | 1408 | } |
| 1409 | 1409 | $event = $datetime->event(); |
| 1410 | - if ( ! $event instanceof \EE_Event ) { |
|
| 1410 | + if ( ! $event instanceof \EE_Event) { |
|
| 1411 | 1411 | throw new UnexpectedEntityException( |
| 1412 | 1412 | $event, |
| 1413 | 1413 | 'EE_Event', |
| 1414 | 1414 | sprintf( |
| 1415 | - __( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1415 | + __('The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
|
| 1416 | 1416 | $this->name() |
| 1417 | 1417 | ) |
| 1418 | 1418 | ); |
@@ -115,14 +115,14 @@ discard block |
||
| 115 | 115 | public function _validate() |
| 116 | 116 | { |
| 117 | 117 | parent::_validate(); |
| 118 | - if (! $this->_payment_method_type instanceof \EE_PMT_Paypal_Express) { |
|
| 118 | + if ( ! $this->_payment_method_type instanceof \EE_PMT_Paypal_Express) { |
|
| 119 | 119 | throw new EntityNotFoundException('EE_PMT_Paypal_Express', '$this->_payment_method_type'); |
| 120 | 120 | } |
| 121 | - if (! $this->_payment_method_type->get_gateway() instanceof \EEG_Paypal_Express) { |
|
| 121 | + if ( ! $this->_payment_method_type->get_gateway() instanceof \EEG_Paypal_Express) { |
|
| 122 | 122 | throw new EntityNotFoundException('EEG_Paypal_Express', '$this->_payment_method_type->get_gateway()'); |
| 123 | 123 | } |
| 124 | 124 | $credentials_message = $this->checkForCredentialsErrors(); |
| 125 | - if( $credentials_message !== '') { |
|
| 125 | + if ($credentials_message !== '') { |
|
| 126 | 126 | $this->add_validation_error($credentials_message); |
| 127 | 127 | $this->get_input('PMD_debug_mode')->add_validation_error( |
| 128 | 128 | esc_html__('If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".', 'event_espresso') |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * Gets the HTML to show the link to the help tab |
| 155 | 155 | * @return string |
| 156 | 156 | */ |
| 157 | - protected function helpTabLink(){ |
|
| 157 | + protected function helpTabLink() { |
|
| 158 | 158 | return $this->helpTabLink; |
| 159 | 159 | } |
| 160 | 160 | /** |
@@ -24,210 +24,210 @@ |
||
| 24 | 24 | class SettingsForm extends EE_Payment_Method_Form |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var string of HTML being the help tab link |
|
| 29 | - */ |
|
| 30 | - protected $helpTabLink; |
|
| 27 | + /** |
|
| 28 | + * @var string of HTML being the help tab link |
|
| 29 | + */ |
|
| 30 | + protected $helpTabLink; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * SettingsForm constructor. |
|
| 34 | - * |
|
| 35 | - * @param array $options_array |
|
| 36 | - * @param string $help_tab_link |
|
| 37 | - */ |
|
| 38 | - public function __construct(array $options_array = array(), $help_tab_link) |
|
| 39 | - { |
|
| 40 | - $this->helpTabLink = $help_tab_link; |
|
| 41 | - $options_array = array_replace_recursive( |
|
| 42 | - array( |
|
| 43 | - 'extra_meta_inputs' => array( |
|
| 44 | - 'api_username' => new EE_Text_Input( |
|
| 45 | - array( |
|
| 46 | - 'html_label_text' => sprintf( |
|
| 47 | - esc_html__('API Username %s', 'event_espresso'), |
|
| 48 | - $help_tab_link |
|
| 49 | - ), |
|
| 50 | - 'required' => true, |
|
| 51 | - ) |
|
| 52 | - ), |
|
| 53 | - 'api_password' => new EE_Text_Input( |
|
| 54 | - array( |
|
| 55 | - 'html_label_text' => sprintf( |
|
| 56 | - esc_html__('API Password %s', 'event_espresso'), |
|
| 57 | - $help_tab_link |
|
| 58 | - ), |
|
| 59 | - 'required' => true, |
|
| 60 | - ) |
|
| 61 | - ), |
|
| 62 | - 'api_signature' => new EE_Text_Input( |
|
| 63 | - array( |
|
| 64 | - 'html_label_text' => sprintf( |
|
| 65 | - esc_html__('API Signature %s', 'event_espresso'), |
|
| 66 | - $help_tab_link |
|
| 67 | - ), |
|
| 68 | - 'required' => true, |
|
| 69 | - ) |
|
| 70 | - ), |
|
| 71 | - 'request_shipping_addr' => new EE_Yes_No_Input( |
|
| 72 | - array( |
|
| 73 | - 'html_label_text' => sprintf( |
|
| 74 | - esc_html__('Request Shipping Address %s', 'event_espresso'), |
|
| 75 | - $help_tab_link |
|
| 76 | - ), |
|
| 77 | - 'html_help_text' => esc_html__( |
|
| 78 | - // @codingStandardsIgnoreStart |
|
| 79 | - 'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.', |
|
| 80 | - // @codingStandardsIgnoreEnd |
|
| 81 | - 'event_espresso' |
|
| 82 | - ), |
|
| 83 | - 'required' => true, |
|
| 84 | - 'default' => false, |
|
| 85 | - ) |
|
| 86 | - ), |
|
| 87 | - 'image_url' => new EE_Admin_File_Uploader_Input( |
|
| 88 | - array( |
|
| 89 | - 'html_label_text' => sprintf( |
|
| 90 | - esc_html__('Image URL %s', 'event_espresso'), |
|
| 91 | - $help_tab_link |
|
| 92 | - ), |
|
| 93 | - 'html_help_text' => esc_html__( |
|
| 94 | - 'Used for your business/personal logo on the PayPal page', |
|
| 95 | - 'event_espresso' |
|
| 96 | - ), |
|
| 97 | - 'required' => false, |
|
| 98 | - ) |
|
| 99 | - ), |
|
| 100 | - ) |
|
| 101 | - ), |
|
| 102 | - $options_array |
|
| 103 | - ); |
|
| 104 | - parent::__construct($options_array); |
|
| 105 | - } |
|
| 32 | + /** |
|
| 33 | + * SettingsForm constructor. |
|
| 34 | + * |
|
| 35 | + * @param array $options_array |
|
| 36 | + * @param string $help_tab_link |
|
| 37 | + */ |
|
| 38 | + public function __construct(array $options_array = array(), $help_tab_link) |
|
| 39 | + { |
|
| 40 | + $this->helpTabLink = $help_tab_link; |
|
| 41 | + $options_array = array_replace_recursive( |
|
| 42 | + array( |
|
| 43 | + 'extra_meta_inputs' => array( |
|
| 44 | + 'api_username' => new EE_Text_Input( |
|
| 45 | + array( |
|
| 46 | + 'html_label_text' => sprintf( |
|
| 47 | + esc_html__('API Username %s', 'event_espresso'), |
|
| 48 | + $help_tab_link |
|
| 49 | + ), |
|
| 50 | + 'required' => true, |
|
| 51 | + ) |
|
| 52 | + ), |
|
| 53 | + 'api_password' => new EE_Text_Input( |
|
| 54 | + array( |
|
| 55 | + 'html_label_text' => sprintf( |
|
| 56 | + esc_html__('API Password %s', 'event_espresso'), |
|
| 57 | + $help_tab_link |
|
| 58 | + ), |
|
| 59 | + 'required' => true, |
|
| 60 | + ) |
|
| 61 | + ), |
|
| 62 | + 'api_signature' => new EE_Text_Input( |
|
| 63 | + array( |
|
| 64 | + 'html_label_text' => sprintf( |
|
| 65 | + esc_html__('API Signature %s', 'event_espresso'), |
|
| 66 | + $help_tab_link |
|
| 67 | + ), |
|
| 68 | + 'required' => true, |
|
| 69 | + ) |
|
| 70 | + ), |
|
| 71 | + 'request_shipping_addr' => new EE_Yes_No_Input( |
|
| 72 | + array( |
|
| 73 | + 'html_label_text' => sprintf( |
|
| 74 | + esc_html__('Request Shipping Address %s', 'event_espresso'), |
|
| 75 | + $help_tab_link |
|
| 76 | + ), |
|
| 77 | + 'html_help_text' => esc_html__( |
|
| 78 | + // @codingStandardsIgnoreStart |
|
| 79 | + 'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.', |
|
| 80 | + // @codingStandardsIgnoreEnd |
|
| 81 | + 'event_espresso' |
|
| 82 | + ), |
|
| 83 | + 'required' => true, |
|
| 84 | + 'default' => false, |
|
| 85 | + ) |
|
| 86 | + ), |
|
| 87 | + 'image_url' => new EE_Admin_File_Uploader_Input( |
|
| 88 | + array( |
|
| 89 | + 'html_label_text' => sprintf( |
|
| 90 | + esc_html__('Image URL %s', 'event_espresso'), |
|
| 91 | + $help_tab_link |
|
| 92 | + ), |
|
| 93 | + 'html_help_text' => esc_html__( |
|
| 94 | + 'Used for your business/personal logo on the PayPal page', |
|
| 95 | + 'event_espresso' |
|
| 96 | + ), |
|
| 97 | + 'required' => false, |
|
| 98 | + ) |
|
| 99 | + ), |
|
| 100 | + ) |
|
| 101 | + ), |
|
| 102 | + $options_array |
|
| 103 | + ); |
|
| 104 | + parent::__construct($options_array); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | 107 | |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Does the normal validation, but also verifies the PayPal API credentials work. |
|
| 111 | - * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more tips) |
|
| 112 | - * on each of the inputs that could be the cause of the problem. |
|
| 113 | - * @throws EntityNotFoundException |
|
| 114 | - */ |
|
| 115 | - public function _validate() |
|
| 116 | - { |
|
| 117 | - parent::_validate(); |
|
| 118 | - if (! $this->_payment_method_type instanceof \EE_PMT_Paypal_Express) { |
|
| 119 | - throw new EntityNotFoundException('EE_PMT_Paypal_Express', '$this->_payment_method_type'); |
|
| 120 | - } |
|
| 121 | - if (! $this->_payment_method_type->get_gateway() instanceof \EEG_Paypal_Express) { |
|
| 122 | - throw new EntityNotFoundException('EEG_Paypal_Express', '$this->_payment_method_type->get_gateway()'); |
|
| 123 | - } |
|
| 124 | - $credentials_message = $this->checkForCredentialsErrors(); |
|
| 125 | - if( $credentials_message !== '') { |
|
| 126 | - $this->add_validation_error($credentials_message); |
|
| 127 | - $this->get_input('PMD_debug_mode')->add_validation_error( |
|
| 128 | - esc_html__('If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".', 'event_espresso') |
|
| 129 | - ); |
|
| 130 | - $this->get_input('api_username')->add_validation_error( |
|
| 131 | - sprintf( |
|
| 132 | - esc_html__('Are you sure this is your API username, not your login username?%1$s', 'event_espresso'), |
|
| 133 | - $this->helpTabLink() |
|
| 134 | - ) |
|
| 135 | - ); |
|
| 136 | - $this->get_input('api_password')->add_validation_error( |
|
| 137 | - sprintf( |
|
| 138 | - esc_html__('Are you sure this is your API password, not your login password.%1$s', 'event_espresso'), |
|
| 139 | - $this->helpTabLink() |
|
| 140 | - ) |
|
| 141 | - ); |
|
| 142 | - $this->get_input('api_signature')->add_validation_error( |
|
| 143 | - sprintf( |
|
| 144 | - esc_html__('Please verify your API signature is correct.%1$s', 'event_espresso'), |
|
| 145 | - $this->helpTabLink() |
|
| 146 | - ) |
|
| 147 | - ); |
|
| 148 | - } |
|
| 149 | - } |
|
| 109 | + /** |
|
| 110 | + * Does the normal validation, but also verifies the PayPal API credentials work. |
|
| 111 | + * If they don't, sets a validation error on the entire form, and adds validation errors (which are really more tips) |
|
| 112 | + * on each of the inputs that could be the cause of the problem. |
|
| 113 | + * @throws EntityNotFoundException |
|
| 114 | + */ |
|
| 115 | + public function _validate() |
|
| 116 | + { |
|
| 117 | + parent::_validate(); |
|
| 118 | + if (! $this->_payment_method_type instanceof \EE_PMT_Paypal_Express) { |
|
| 119 | + throw new EntityNotFoundException('EE_PMT_Paypal_Express', '$this->_payment_method_type'); |
|
| 120 | + } |
|
| 121 | + if (! $this->_payment_method_type->get_gateway() instanceof \EEG_Paypal_Express) { |
|
| 122 | + throw new EntityNotFoundException('EEG_Paypal_Express', '$this->_payment_method_type->get_gateway()'); |
|
| 123 | + } |
|
| 124 | + $credentials_message = $this->checkForCredentialsErrors(); |
|
| 125 | + if( $credentials_message !== '') { |
|
| 126 | + $this->add_validation_error($credentials_message); |
|
| 127 | + $this->get_input('PMD_debug_mode')->add_validation_error( |
|
| 128 | + esc_html__('If you are using PayPal Sandbox (test) credentials, Debug mode should be set to "Yes". Otherwise, if you are using live PayPal credentials, set this to "No".', 'event_espresso') |
|
| 129 | + ); |
|
| 130 | + $this->get_input('api_username')->add_validation_error( |
|
| 131 | + sprintf( |
|
| 132 | + esc_html__('Are you sure this is your API username, not your login username?%1$s', 'event_espresso'), |
|
| 133 | + $this->helpTabLink() |
|
| 134 | + ) |
|
| 135 | + ); |
|
| 136 | + $this->get_input('api_password')->add_validation_error( |
|
| 137 | + sprintf( |
|
| 138 | + esc_html__('Are you sure this is your API password, not your login password.%1$s', 'event_espresso'), |
|
| 139 | + $this->helpTabLink() |
|
| 140 | + ) |
|
| 141 | + ); |
|
| 142 | + $this->get_input('api_signature')->add_validation_error( |
|
| 143 | + sprintf( |
|
| 144 | + esc_html__('Please verify your API signature is correct.%1$s', 'event_espresso'), |
|
| 145 | + $this->helpTabLink() |
|
| 146 | + ) |
|
| 147 | + ); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | 151 | |
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Gets the HTML to show the link to the help tab |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - protected function helpTabLink(){ |
|
| 158 | - return $this->helpTabLink; |
|
| 159 | - } |
|
| 160 | - /** |
|
| 161 | - * Tests the the PayPal API credentials work ok |
|
| 162 | - * @return string of an error using the credentials, otherwise, if the credentials work, returns a blank string |
|
| 163 | - */ |
|
| 164 | - protected function checkForCredentialsErrors() |
|
| 165 | - { |
|
| 166 | - $request_params = array( |
|
| 167 | - 'METHOD' => 'GetBalance', |
|
| 168 | - 'VERSION' => '204.0', |
|
| 169 | - 'USER' => urlencode($this->get_input_value('api_username')), |
|
| 170 | - 'PWD' => urlencode($this->get_input_value('api_password')), |
|
| 171 | - 'SIGNATURE' => urlencode($this->get_input_value('api_signature')), |
|
| 172 | - ); |
|
| 173 | - $gateway_url = $this->get_input_value('PMD_debug_mode') |
|
| 174 | - ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
| 175 | - : 'https://api-3t.paypal.com/nvp'; |
|
| 176 | - // Request Customer Details. |
|
| 177 | - $response = wp_remote_post( |
|
| 178 | - $gateway_url, |
|
| 179 | - array( |
|
| 180 | - 'method' => 'POST', |
|
| 181 | - 'timeout' => 45, |
|
| 182 | - 'httpversion' => '1.1', |
|
| 183 | - 'cookies' => array(), |
|
| 184 | - 'headers' => array(), |
|
| 185 | - 'body' => http_build_query($request_params, '', '&'), |
|
| 186 | - ) |
|
| 187 | - ); |
|
| 188 | - if (is_wp_error($response) || empty($response['body'])) { |
|
| 189 | - // If we got here then there was an error in this request. |
|
| 190 | - //maybe is turned off. We don't know the credentials are invalid |
|
| 191 | - EE_Error::add_error( |
|
| 192 | - sprintf( |
|
| 193 | - esc_html__('Your PayPal credentials could not be verified. There was an error communicating with PayPal, it was %1$s', 'event_espresso'), |
|
| 194 | - $response->get_error_message() |
|
| 195 | - ), |
|
| 196 | - __FILE__, |
|
| 197 | - __FUNCTION__, |
|
| 198 | - __LINE__ |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - $response_args = array(); |
|
| 202 | - parse_str(urldecode($response['body']), $response_args); |
|
| 153 | + /** |
|
| 154 | + * Gets the HTML to show the link to the help tab |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + protected function helpTabLink(){ |
|
| 158 | + return $this->helpTabLink; |
|
| 159 | + } |
|
| 160 | + /** |
|
| 161 | + * Tests the the PayPal API credentials work ok |
|
| 162 | + * @return string of an error using the credentials, otherwise, if the credentials work, returns a blank string |
|
| 163 | + */ |
|
| 164 | + protected function checkForCredentialsErrors() |
|
| 165 | + { |
|
| 166 | + $request_params = array( |
|
| 167 | + 'METHOD' => 'GetBalance', |
|
| 168 | + 'VERSION' => '204.0', |
|
| 169 | + 'USER' => urlencode($this->get_input_value('api_username')), |
|
| 170 | + 'PWD' => urlencode($this->get_input_value('api_password')), |
|
| 171 | + 'SIGNATURE' => urlencode($this->get_input_value('api_signature')), |
|
| 172 | + ); |
|
| 173 | + $gateway_url = $this->get_input_value('PMD_debug_mode') |
|
| 174 | + ? 'https://api-3t.sandbox.paypal.com/nvp' |
|
| 175 | + : 'https://api-3t.paypal.com/nvp'; |
|
| 176 | + // Request Customer Details. |
|
| 177 | + $response = wp_remote_post( |
|
| 178 | + $gateway_url, |
|
| 179 | + array( |
|
| 180 | + 'method' => 'POST', |
|
| 181 | + 'timeout' => 45, |
|
| 182 | + 'httpversion' => '1.1', |
|
| 183 | + 'cookies' => array(), |
|
| 184 | + 'headers' => array(), |
|
| 185 | + 'body' => http_build_query($request_params, '', '&'), |
|
| 186 | + ) |
|
| 187 | + ); |
|
| 188 | + if (is_wp_error($response) || empty($response['body'])) { |
|
| 189 | + // If we got here then there was an error in this request. |
|
| 190 | + //maybe is turned off. We don't know the credentials are invalid |
|
| 191 | + EE_Error::add_error( |
|
| 192 | + sprintf( |
|
| 193 | + esc_html__('Your PayPal credentials could not be verified. There was an error communicating with PayPal, it was %1$s', 'event_espresso'), |
|
| 194 | + $response->get_error_message() |
|
| 195 | + ), |
|
| 196 | + __FILE__, |
|
| 197 | + __FUNCTION__, |
|
| 198 | + __LINE__ |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + $response_args = array(); |
|
| 202 | + parse_str(urldecode($response['body']), $response_args); |
|
| 203 | 203 | |
| 204 | - if (empty($response_args['ACK'])) { |
|
| 205 | - EE_Error::add_error( |
|
| 206 | - esc_html__('Your PayPal credentials could not be verified. Part of their response was missing.', 'event_espresso'), |
|
| 207 | - __FILE__, |
|
| 208 | - __FUNCTION__, |
|
| 209 | - __LINE__ |
|
| 210 | - ); |
|
| 211 | - } |
|
| 212 | - if ( |
|
| 213 | - in_array( |
|
| 214 | - $response_args['ACK'], |
|
| 215 | - array( |
|
| 216 | - 'Success', |
|
| 217 | - 'SuccessWithWarning' |
|
| 218 | - ), |
|
| 219 | - true |
|
| 220 | - ) |
|
| 221 | - ) { |
|
| 222 | - return ''; |
|
| 223 | - } else { |
|
| 224 | - return sprintf( |
|
| 225 | - esc_html__('Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.', 'event_espresso'), |
|
| 226 | - isset($response_args['L_LONGMESSAGE0']) ? $response_args['L_LONGMESSAGE0'] : esc_html__('No error message received from PayPal', 'event_espresso'), |
|
| 227 | - isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0 |
|
| 228 | - ); |
|
| 229 | - } |
|
| 230 | - } |
|
| 204 | + if (empty($response_args['ACK'])) { |
|
| 205 | + EE_Error::add_error( |
|
| 206 | + esc_html__('Your PayPal credentials could not be verified. Part of their response was missing.', 'event_espresso'), |
|
| 207 | + __FILE__, |
|
| 208 | + __FUNCTION__, |
|
| 209 | + __LINE__ |
|
| 210 | + ); |
|
| 211 | + } |
|
| 212 | + if ( |
|
| 213 | + in_array( |
|
| 214 | + $response_args['ACK'], |
|
| 215 | + array( |
|
| 216 | + 'Success', |
|
| 217 | + 'SuccessWithWarning' |
|
| 218 | + ), |
|
| 219 | + true |
|
| 220 | + ) |
|
| 221 | + ) { |
|
| 222 | + return ''; |
|
| 223 | + } else { |
|
| 224 | + return sprintf( |
|
| 225 | + esc_html__('Your PayPal API credentials appear to be invalid. PayPal said "%1$s (%2$s)". Please see tips below.', 'event_espresso'), |
|
| 226 | + isset($response_args['L_LONGMESSAGE0']) ? $response_args['L_LONGMESSAGE0'] : esc_html__('No error message received from PayPal', 'event_espresso'), |
|
| 227 | + isset($response_args['L_ERRORCODE0']) ? $response_args['L_ERRORCODE0'] : 0 |
|
| 228 | + ); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | 231 | } |
| 232 | 232 | // End of file SettingsForm.php |
| 233 | 233 | // Location: EventEspresso\payment_methods\Paypal_Express\forms/SettingsForm.php |
| 234 | 234 | \ No newline at end of file |