@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | // enqueue style |
| 357 | 357 | wp_register_style( |
| 358 | 358 | 'espresso_txn', |
| 359 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 359 | + TXN_ASSETS_URL.'espresso_transactions_admin.css', |
|
| 360 | 360 | array(), |
| 361 | 361 | EVENT_ESPRESSO_VERSION |
| 362 | 362 | ); |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | // scripts |
| 365 | 365 | wp_register_script( |
| 366 | 366 | 'espresso_txn', |
| 367 | - TXN_ASSETS_URL . 'espresso_transactions_admin.js', |
|
| 367 | + TXN_ASSETS_URL.'espresso_transactions_admin.js', |
|
| 368 | 368 | array( |
| 369 | 369 | 'ee_admin_js', |
| 370 | 370 | 'ee-datepicker', |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | $this->_transaction->verify_abandoned_transaction_status(); |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 495 | + if ( ! $this->_transaction instanceof EE_Transaction) { |
|
| 496 | 496 | $error_msg = sprintf( |
| 497 | 497 | esc_html__( |
| 498 | 498 | 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
@@ -585,7 +585,7 @@ discard block |
||
| 585 | 585 | 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
| 586 | 586 | array( |
| 587 | 587 | 'overpaid' => array( |
| 588 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 588 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::overpaid_status_code, |
|
| 589 | 589 | 'desc' => EEH_Template::pretty_status( |
| 590 | 590 | EEM_Transaction::overpaid_status_code, |
| 591 | 591 | false, |
@@ -593,7 +593,7 @@ discard block |
||
| 593 | 593 | ), |
| 594 | 594 | ), |
| 595 | 595 | 'complete' => array( |
| 596 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 596 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::complete_status_code, |
|
| 597 | 597 | 'desc' => EEH_Template::pretty_status( |
| 598 | 598 | EEM_Transaction::complete_status_code, |
| 599 | 599 | false, |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | ), |
| 602 | 602 | ), |
| 603 | 603 | 'incomplete' => array( |
| 604 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 604 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::incomplete_status_code, |
|
| 605 | 605 | 'desc' => EEH_Template::pretty_status( |
| 606 | 606 | EEM_Transaction::incomplete_status_code, |
| 607 | 607 | false, |
@@ -609,7 +609,7 @@ discard block |
||
| 609 | 609 | ), |
| 610 | 610 | ), |
| 611 | 611 | 'abandoned' => array( |
| 612 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 612 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::abandoned_status_code, |
|
| 613 | 613 | 'desc' => EEH_Template::pretty_status( |
| 614 | 614 | EEM_Transaction::abandoned_status_code, |
| 615 | 615 | false, |
@@ -617,7 +617,7 @@ discard block |
||
| 617 | 617 | ), |
| 618 | 618 | ), |
| 619 | 619 | 'failed' => array( |
| 620 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 620 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Transaction::failed_status_code, |
|
| 621 | 621 | 'desc' => EEH_Template::pretty_status( |
| 622 | 622 | EEM_Transaction::failed_status_code, |
| 623 | 623 | false, |
@@ -666,7 +666,7 @@ discard block |
||
| 666 | 666 | 'Click to Edit event', |
| 667 | 667 | 'event_espresso' |
| 668 | 668 | ) |
| 669 | - . '">' . $event->name() . '</a>', |
|
| 669 | + . '">'.$event->name().'</a>', |
|
| 670 | 670 | '</h3>' |
| 671 | 671 | ) |
| 672 | 672 | : ''; |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | |
| 701 | 701 | $this->_set_transaction_object(); |
| 702 | 702 | |
| 703 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 703 | + if ( ! $this->_transaction instanceof EE_Transaction) { |
|
| 704 | 704 | return; |
| 705 | 705 | } |
| 706 | 706 | $primary_registration = $this->_transaction->primary_registration(); |
@@ -714,9 +714,9 @@ discard block |
||
| 714 | 714 | $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
| 715 | 715 | $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
| 716 | 716 | |
| 717 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ]; |
|
| 717 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[$this->_transaction->status_ID()]; |
|
| 718 | 718 | $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
| 719 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID(); |
|
| 719 | + $this->_template_args['txn_status']['class'] = 'status-'.$this->_transaction->status_ID(); |
|
| 720 | 720 | |
| 721 | 721 | $this->_template_args['grand_total'] = $this->_transaction->total(); |
| 722 | 722 | $this->_template_args['total_paid'] = $this->_transaction->paid(); |
@@ -832,7 +832,7 @@ discard block |
||
| 832 | 832 | // grab messages at the last second |
| 833 | 833 | $this->_template_args['notices'] = EE_Error::get_notices(); |
| 834 | 834 | // path to template |
| 835 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 835 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_header.template.php'; |
|
| 836 | 836 | $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
| 837 | 837 | $template_path, |
| 838 | 838 | $this->_template_args, |
@@ -861,7 +861,7 @@ discard block |
||
| 861 | 861 | |
| 862 | 862 | $this->_set_transaction_object(); |
| 863 | 863 | |
| 864 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 864 | + if ( ! $this->_transaction instanceof EE_Transaction) { |
|
| 865 | 865 | return; |
| 866 | 866 | } |
| 867 | 867 | add_meta_box( |
@@ -917,7 +917,7 @@ discard block |
||
| 917 | 917 | { |
| 918 | 918 | $content = ''; |
| 919 | 919 | $actions = array(); |
| 920 | - if (! $transaction instanceof EE_Transaction) { |
|
| 920 | + if ( ! $transaction instanceof EE_Transaction) { |
|
| 921 | 921 | return $content; |
| 922 | 922 | } |
| 923 | 923 | /** @var EE_Registration $primary_registration */ |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | ); |
| 999 | 999 | if ($actions) { |
| 1000 | 1000 | $content = '<ul>'; |
| 1001 | - $content .= '<li>' . implode('</li><li>', $actions) . '</li>'; |
|
| 1001 | + $content .= '<li>'.implode('</li><li>', $actions).'</li>'; |
|
| 1002 | 1002 | $content .= '</uL>'; |
| 1003 | 1003 | } |
| 1004 | 1004 | return $content; |
@@ -1059,7 +1059,7 @@ discard block |
||
| 1059 | 1059 | |
| 1060 | 1060 | // process payment details |
| 1061 | 1061 | $payments = $this->_transaction->payments(); |
| 1062 | - if (! empty($payments)) { |
|
| 1062 | + if ( ! empty($payments)) { |
|
| 1063 | 1063 | $this->_template_args['payments'] = $payments; |
| 1064 | 1064 | $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
| 1065 | 1065 | } else { |
@@ -1120,7 +1120,7 @@ discard block |
||
| 1120 | 1120 | esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
| 1121 | 1121 | ucwords(str_replace('_', ' ', $reg_step)), |
| 1122 | 1122 | date( |
| 1123 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1123 | + get_option('date_format').' '.get_option('time_format'), |
|
| 1124 | 1124 | $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
| 1125 | 1125 | ) |
| 1126 | 1126 | ) |
@@ -1173,7 +1173,7 @@ discard block |
||
| 1173 | 1173 | |
| 1174 | 1174 | // 'espresso_delete_payment_nonce' |
| 1175 | 1175 | |
| 1176 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1176 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1177 | 1177 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 1178 | 1178 | } |
| 1179 | 1179 | |
@@ -1205,18 +1205,18 @@ discard block |
||
| 1205 | 1205 | ), |
| 1206 | 1206 | ) |
| 1207 | 1207 | ); |
| 1208 | - if (! empty($reg_payments)) { |
|
| 1208 | + if ( ! empty($reg_payments)) { |
|
| 1209 | 1209 | foreach ($payments as $payment) { |
| 1210 | - if (! $payment instanceof EE_Payment) { |
|
| 1210 | + if ( ! $payment instanceof EE_Payment) { |
|
| 1211 | 1211 | continue; |
| 1212 | - } elseif (! isset($existing_reg_payments[ $payment->ID() ])) { |
|
| 1213 | - $existing_reg_payments[ $payment->ID() ] = array(); |
|
| 1212 | + } elseif ( ! isset($existing_reg_payments[$payment->ID()])) { |
|
| 1213 | + $existing_reg_payments[$payment->ID()] = array(); |
|
| 1214 | 1214 | } |
| 1215 | 1215 | foreach ($reg_payments as $reg_payment) { |
| 1216 | 1216 | if ($reg_payment instanceof EE_Registration_Payment |
| 1217 | 1217 | && $reg_payment->payment_ID() === $payment->ID() |
| 1218 | 1218 | ) { |
| 1219 | - $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID(); |
|
| 1219 | + $existing_reg_payments[$payment->ID()][] = $reg_payment->registration_ID(); |
|
| 1220 | 1220 | } |
| 1221 | 1221 | } |
| 1222 | 1222 | } |
@@ -1254,22 +1254,22 @@ discard block |
||
| 1254 | 1254 | ), |
| 1255 | 1255 | ), |
| 1256 | 1256 | ); |
| 1257 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 1257 | + $registrations_to_apply_payment_to = EEH_HTML::br().EEH_HTML::div( |
|
| 1258 | 1258 | '', |
| 1259 | 1259 | 'txn-admin-apply-payment-to-registrations-dv', |
| 1260 | 1260 | '', |
| 1261 | 1261 | 'clear: both; margin: 1.5em 0 0; display: none;' |
| 1262 | 1262 | ); |
| 1263 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1263 | + $registrations_to_apply_payment_to .= EEH_HTML::br().EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1264 | 1264 | $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
| 1265 | 1265 | $registrations_to_apply_payment_to .= EEH_HTML::thead( |
| 1266 | 1266 | EEH_HTML::tr( |
| 1267 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1268 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1269 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1270 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1271 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1272 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1267 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')). |
|
| 1268 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')). |
|
| 1269 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')). |
|
| 1270 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')). |
|
| 1271 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
| 1272 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr'). |
|
| 1273 | 1273 | EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
| 1274 | 1274 | ) |
| 1275 | 1275 | ); |
@@ -1284,7 +1284,7 @@ discard block |
||
| 1284 | 1284 | : esc_html__('Unknown Attendee', 'event_espresso'); |
| 1285 | 1285 | $owing = $registration->final_price() - $registration->paid(); |
| 1286 | 1286 | $taxable = $registration->ticket()->taxable() |
| 1287 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1287 | + ? ' <span class="smaller-text lt-grey-text"> '.esc_html__('+ tax', 'event_espresso').'</span>' |
|
| 1288 | 1288 | : ''; |
| 1289 | 1289 | $checked = empty($existing_reg_payments) |
| 1290 | 1290 | || in_array($registration->ID(), $existing_reg_payments, true) |
@@ -1292,26 +1292,26 @@ discard block |
||
| 1292 | 1292 | : ''; |
| 1293 | 1293 | $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
| 1294 | 1294 | $registrations_to_apply_payment_to .= EEH_HTML::tr( |
| 1295 | - EEH_HTML::td($registration->ID()) . |
|
| 1296 | - EEH_HTML::td($attendee_name) . |
|
| 1295 | + EEH_HTML::td($registration->ID()). |
|
| 1296 | + EEH_HTML::td($attendee_name). |
|
| 1297 | 1297 | EEH_HTML::td( |
| 1298 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1299 | - ) . |
|
| 1300 | - EEH_HTML::td($registration->event_name()) . |
|
| 1301 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1298 | + $registration->ticket()->name().' : '.$registration->ticket()->pretty_price().$taxable |
|
| 1299 | + ). |
|
| 1300 | + EEH_HTML::td($registration->event_name()). |
|
| 1301 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr'). |
|
| 1302 | 1302 | EEH_HTML::td( |
| 1303 | 1303 | EEH_Template::format_currency($owing), |
| 1304 | 1304 | '', |
| 1305 | 1305 | 'txn-admin-payment-owing-td jst-cntr' |
| 1306 | - ) . |
|
| 1306 | + ). |
|
| 1307 | 1307 | EEH_HTML::td( |
| 1308 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 1308 | + '<input type="checkbox" value="'.$registration->ID() |
|
| 1309 | 1309 | . '" name="txn_admin_payment[registrations]"' |
| 1310 | - . $checked . $disabled . '>', |
|
| 1310 | + . $checked.$disabled.'>', |
|
| 1311 | 1311 | '', |
| 1312 | 1312 | 'jst-cntr' |
| 1313 | 1313 | ), |
| 1314 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1314 | + 'apply-payment-registration-row-'.$registration->ID() |
|
| 1315 | 1315 | ); |
| 1316 | 1316 | } |
| 1317 | 1317 | } |
@@ -1392,12 +1392,12 @@ discard block |
||
| 1392 | 1392 | array( |
| 1393 | 1393 | 'OR*payment_method_for_payment' => array( |
| 1394 | 1394 | 'PMD_ID' => array('IN', $payment_methods_of_payments), |
| 1395 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1395 | + 'PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'), |
|
| 1396 | 1396 | ), |
| 1397 | 1397 | ), |
| 1398 | 1398 | ); |
| 1399 | 1399 | } else { |
| 1400 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1400 | + $query_args = array(array('PMD_scope' => array('LIKE', '%'.EEM_Payment_Method::scope_admin.'%'))); |
|
| 1401 | 1401 | } |
| 1402 | 1402 | $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
| 1403 | 1403 | } |
@@ -1430,7 +1430,7 @@ discard block |
||
| 1430 | 1430 | 'Line_Item', |
| 1431 | 1431 | array(array('LIN_type' => 'line-item')) |
| 1432 | 1432 | ); |
| 1433 | - if (! empty($line_items)) { |
|
| 1433 | + if ( ! empty($line_items)) { |
|
| 1434 | 1434 | foreach ($line_items as $item) { |
| 1435 | 1435 | if ($item instanceof EE_Line_Item) { |
| 1436 | 1436 | switch ($item->OBJ_type()) { |
@@ -1440,7 +1440,7 @@ discard block |
||
| 1440 | 1440 | $ticket = $item->ticket(); |
| 1441 | 1441 | // right now we're only handling tickets here. |
| 1442 | 1442 | // Cause its expected that only tickets will have attendees right? |
| 1443 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1443 | + if ( ! $ticket instanceof EE_Ticket) { |
|
| 1444 | 1444 | break; |
| 1445 | 1445 | } |
| 1446 | 1446 | try { |
@@ -1449,45 +1449,45 @@ discard block |
||
| 1449 | 1449 | EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
| 1450 | 1450 | $event_name = esc_html__('Unknown Event', 'event_espresso'); |
| 1451 | 1451 | } |
| 1452 | - $event_name .= ' - ' . $item->name(); |
|
| 1452 | + $event_name .= ' - '.$item->name(); |
|
| 1453 | 1453 | $ticket_price = EEH_Template::format_currency($item->unit_price()); |
| 1454 | 1454 | // now get all of the registrations for this transaction that use this ticket |
| 1455 | 1455 | $registrations = $ticket->registrations( |
| 1456 | 1456 | array(array('TXN_ID' => $this->_transaction->ID())) |
| 1457 | 1457 | ); |
| 1458 | 1458 | foreach ($registrations as $registration) { |
| 1459 | - if (! $registration instanceof EE_Registration) { |
|
| 1459 | + if ( ! $registration instanceof EE_Registration) { |
|
| 1460 | 1460 | break; |
| 1461 | 1461 | } |
| 1462 | - $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID'] |
|
| 1462 | + $this->_template_args['event_attendees'][$registration->ID()]['STS_ID'] |
|
| 1463 | 1463 | = $registration->status_ID(); |
| 1464 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_num'] |
|
| 1464 | + $this->_template_args['event_attendees'][$registration->ID()]['att_num'] |
|
| 1465 | 1465 | = $registration->count(); |
| 1466 | - $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name'] |
|
| 1466 | + $this->_template_args['event_attendees'][$registration->ID()]['event_ticket_name'] |
|
| 1467 | 1467 | = $event_name; |
| 1468 | - $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price'] |
|
| 1468 | + $this->_template_args['event_attendees'][$registration->ID()]['ticket_price'] |
|
| 1469 | 1469 | = $ticket_price; |
| 1470 | 1470 | // attendee info |
| 1471 | 1471 | $attendee = $registration->get_first_related('Attendee'); |
| 1472 | 1472 | if ($attendee instanceof EE_Attendee) { |
| 1473 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] |
|
| 1473 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] |
|
| 1474 | 1474 | = $attendee->ID(); |
| 1475 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] |
|
| 1475 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] |
|
| 1476 | 1476 | = $attendee->full_name(); |
| 1477 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] |
|
| 1478 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1477 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] |
|
| 1478 | + = '<a href="mailto:'.$attendee->email().'?subject='.$event_name |
|
| 1479 | 1479 | . esc_html__( |
| 1480 | 1480 | ' Event', |
| 1481 | 1481 | 'event_espresso' |
| 1482 | 1482 | ) |
| 1483 | - . '">' . $attendee->email() . '</a>'; |
|
| 1484 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] |
|
| 1483 | + . '">'.$attendee->email().'</a>'; |
|
| 1484 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] |
|
| 1485 | 1485 | = EEH_Address::format($attendee, 'inline', false, false); |
| 1486 | 1486 | } else { |
| 1487 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = ''; |
|
| 1488 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = ''; |
|
| 1489 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = ''; |
|
| 1490 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = ''; |
|
| 1487 | + $this->_template_args['event_attendees'][$registration->ID()]['att_id'] = ''; |
|
| 1488 | + $this->_template_args['event_attendees'][$registration->ID()]['attendee'] = ''; |
|
| 1489 | + $this->_template_args['event_attendees'][$registration->ID()]['email'] = ''; |
|
| 1490 | + $this->_template_args['event_attendees'][$registration->ID()]['address'] = ''; |
|
| 1491 | 1491 | } |
| 1492 | 1492 | } |
| 1493 | 1493 | break; |
@@ -1503,7 +1503,7 @@ discard block |
||
| 1503 | 1503 | TXN_ADMIN_URL |
| 1504 | 1504 | ); |
| 1505 | 1505 | echo EEH_Template::display_template( |
| 1506 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1506 | + TXN_TEMPLATE_PATH.'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1507 | 1507 | $this->_template_args, |
| 1508 | 1508 | true |
| 1509 | 1509 | ); |
@@ -1538,7 +1538,7 @@ discard block |
||
| 1538 | 1538 | $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
| 1539 | 1539 | ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
| 1540 | 1540 | : null; |
| 1541 | - if (! $primary_att instanceof EE_Attendee) { |
|
| 1541 | + if ( ! $primary_att instanceof EE_Attendee) { |
|
| 1542 | 1542 | $this->_template_args['no_attendee_message'] = esc_html__( |
| 1543 | 1543 | 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
| 1544 | 1544 | 'event_espresso' |
@@ -1560,7 +1560,7 @@ discard block |
||
| 1560 | 1560 | // get formatted address for registrant |
| 1561 | 1561 | $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
| 1562 | 1562 | echo EEH_Template::display_template( |
| 1563 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1563 | + TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1564 | 1564 | $this->_template_args, |
| 1565 | 1565 | true |
| 1566 | 1566 | ); |
@@ -1585,7 +1585,7 @@ discard block |
||
| 1585 | 1585 | TXN_ADMIN_URL |
| 1586 | 1586 | ); |
| 1587 | 1587 | |
| 1588 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1588 | + $template_path = TXN_TEMPLATE_PATH.'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1589 | 1589 | echo EEH_Template::display_template($template_path, $this->_template_args, true); |
| 1590 | 1590 | } |
| 1591 | 1591 | |
@@ -1611,7 +1611,7 @@ discard block |
||
| 1611 | 1611 | 'ee_edit_payments', |
| 1612 | 1612 | 'apply_payment_or_refund_from_registration_details' |
| 1613 | 1613 | ); |
| 1614 | - if (! empty($valid_data) && $has_access) { |
|
| 1614 | + if ( ! empty($valid_data) && $has_access) { |
|
| 1615 | 1615 | $PAY_ID = $valid_data['PAY_ID']; |
| 1616 | 1616 | // save the new payment |
| 1617 | 1617 | $payment = $this->_create_payment_from_request_data($valid_data); |
@@ -1624,7 +1624,7 @@ discard block |
||
| 1624 | 1624 | $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
| 1625 | 1625 | $this->_remove_existing_registration_payments($payment, $PAY_ID); |
| 1626 | 1626 | // apply payment to registrations (if applicable) |
| 1627 | - if (! empty($REG_IDs)) { |
|
| 1627 | + if ( ! empty($REG_IDs)) { |
|
| 1628 | 1628 | $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
| 1629 | 1629 | $this->_maybe_send_notifications(); |
| 1630 | 1630 | // now process status changes for the same registrations |
@@ -1695,14 +1695,14 @@ discard block |
||
| 1695 | 1695 | */ |
| 1696 | 1696 | protected function _validate_payment_request_data() |
| 1697 | 1697 | { |
| 1698 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1698 | + if ( ! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1699 | 1699 | return array(); |
| 1700 | 1700 | } |
| 1701 | 1701 | $payment_form = $this->_generate_payment_form_section(); |
| 1702 | 1702 | try { |
| 1703 | 1703 | if ($payment_form->was_submitted()) { |
| 1704 | 1704 | $payment_form->receive_form_submission(); |
| 1705 | - if (! $payment_form->is_valid()) { |
|
| 1705 | + if ( ! $payment_form->is_valid()) { |
|
| 1706 | 1706 | $submission_error_messages = array(); |
| 1707 | 1707 | foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
| 1708 | 1708 | if ($validation_error instanceof EE_Validation_Error) { |
@@ -1883,7 +1883,7 @@ discard block |
||
| 1883 | 1883 | array('Y-m-d', 'g:i a') |
| 1884 | 1884 | ); |
| 1885 | 1885 | |
| 1886 | - if (! $payment->save()) { |
|
| 1886 | + if ( ! $payment->save()) { |
|
| 1887 | 1887 | EE_Error::add_error( |
| 1888 | 1888 | sprintf( |
| 1889 | 1889 | esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
@@ -2088,12 +2088,12 @@ discard block |
||
| 2088 | 2088 | // but add in some conditions regarding payment, |
| 2089 | 2089 | // so that we don't apply payments to registrations that are free or have already been paid for |
| 2090 | 2090 | // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
| 2091 | - if (! $payment->is_a_refund()) { |
|
| 2091 | + if ( ! $payment->is_a_refund()) { |
|
| 2092 | 2092 | $registration_query_where_params['REG_final_price'] = array('!=', 0); |
| 2093 | 2093 | $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
| 2094 | 2094 | } |
| 2095 | 2095 | $registrations = $transaction->registrations(array($registration_query_where_params)); |
| 2096 | - if (! empty($registrations)) { |
|
| 2096 | + if ( ! empty($registrations)) { |
|
| 2097 | 2097 | /** @type EE_Payment_Processor $payment_processor */ |
| 2098 | 2098 | $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
| 2099 | 2099 | $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
@@ -2118,7 +2118,7 @@ discard block |
||
| 2118 | 2118 | protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
| 2119 | 2119 | { |
| 2120 | 2120 | // first if there is no change in status then we get out. |
| 2121 | - if (! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 2121 | + if ( ! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 2122 | 2122 | || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
| 2123 | 2123 | ) { |
| 2124 | 2124 | // no error message, no change requested, just nothing to do man. |
@@ -2176,7 +2176,7 @@ discard block |
||
| 2176 | 2176 | 'pay_status' => $payment->STS_ID(), |
| 2177 | 2177 | 'PAY_ID' => $payment->ID(), |
| 2178 | 2178 | 'STS_ID' => $payment->STS_ID(), |
| 2179 | - 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
| 2179 | + 'status' => self::$_pay_status[$payment->STS_ID()], |
|
| 2180 | 2180 | 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
| 2181 | 2181 | 'method' => strtoupper($payment->source()), |
| 2182 | 2182 | 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
@@ -2296,11 +2296,11 @@ discard block |
||
| 2296 | 2296 | { |
| 2297 | 2297 | $registration_payment_data = array(); |
| 2298 | 2298 | // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
| 2299 | - if (! empty($REG_IDs)) { |
|
| 2299 | + if ( ! empty($REG_IDs)) { |
|
| 2300 | 2300 | $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
| 2301 | 2301 | foreach ($registrations as $registration) { |
| 2302 | 2302 | if ($registration instanceof EE_Registration) { |
| 2303 | - $registration_payment_data[ $registration->ID() ] = array( |
|
| 2303 | + $registration_payment_data[$registration->ID()] = array( |
|
| 2304 | 2304 | 'paid' => $registration->pretty_paid(), |
| 2305 | 2305 | 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
| 2306 | 2306 | ); |
@@ -2412,8 +2412,8 @@ discard block |
||
| 2412 | 2412 | : date('m/d/Y'); |
| 2413 | 2413 | |
| 2414 | 2414 | // make sure our timestamps start and end right at the boundaries for each day |
| 2415 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2416 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2415 | + $start_date = date('Y-m-d', strtotime($start_date)).' 00:00:00'; |
|
| 2416 | + $end_date = date('Y-m-d', strtotime($end_date)).' 23:59:59'; |
|
| 2417 | 2417 | |
| 2418 | 2418 | |
| 2419 | 2419 | // convert to timestamps |
@@ -2472,7 +2472,7 @@ discard block |
||
| 2472 | 2472 | } |
| 2473 | 2473 | |
| 2474 | 2474 | if (isset($this->_req_data['s'])) { |
| 2475 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2475 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
| 2476 | 2476 | $_where['OR'] = array( |
| 2477 | 2477 | 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
| 2478 | 2478 | 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
@@ -2499,11 +2499,11 @@ discard block |
||
| 2499 | 2499 | } |
| 2500 | 2500 | |
| 2501 | 2501 | // failed transactions |
| 2502 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2502 | + $failed = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2503 | 2503 | || ($count && $view === 'failed'); |
| 2504 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2504 | + $abandoned = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2505 | 2505 | || ($count && $view === 'abandoned'); |
| 2506 | - $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count) |
|
| 2506 | + $incomplete = ( ! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count) |
|
| 2507 | 2507 | || ($count && $view === 'incomplete'); |
| 2508 | 2508 | |
| 2509 | 2509 | if ($failed) { |
@@ -13,2562 +13,2562 @@ |
||
| 13 | 13 | class Transactions_Admin_Page extends EE_Admin_Page |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @var EE_Transaction |
|
| 18 | - */ |
|
| 19 | - private $_transaction; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @var EE_Session |
|
| 23 | - */ |
|
| 24 | - private $_session; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var array $_txn_status |
|
| 28 | - */ |
|
| 29 | - private static $_txn_status; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var array $_pay_status |
|
| 33 | - */ |
|
| 34 | - private static $_pay_status; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var array $_existing_reg_payment_REG_IDs |
|
| 38 | - */ |
|
| 39 | - protected $_existing_reg_payment_REG_IDs; |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * _init_page_props |
|
| 44 | - * |
|
| 45 | - * @return void |
|
| 46 | - */ |
|
| 47 | - protected function _init_page_props() |
|
| 48 | - { |
|
| 49 | - $this->page_slug = TXN_PG_SLUG; |
|
| 50 | - $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 51 | - $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 52 | - $this->_admin_base_path = TXN_ADMIN; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * _ajax_hooks |
|
| 58 | - * |
|
| 59 | - * @return void |
|
| 60 | - */ |
|
| 61 | - protected function _ajax_hooks() |
|
| 62 | - { |
|
| 63 | - add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 64 | - add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 65 | - add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * _define_page_props |
|
| 71 | - * |
|
| 72 | - * @return void |
|
| 73 | - */ |
|
| 74 | - protected function _define_page_props() |
|
| 75 | - { |
|
| 76 | - $this->_admin_page_title = $this->page_label; |
|
| 77 | - $this->_labels = array( |
|
| 78 | - 'buttons' => array( |
|
| 79 | - 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 80 | - 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 81 | - 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 82 | - ), |
|
| 83 | - ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * grab url requests and route them |
|
| 89 | - * |
|
| 90 | - * @access private |
|
| 91 | - * @return void |
|
| 92 | - * @throws EE_Error |
|
| 93 | - * @throws InvalidArgumentException |
|
| 94 | - * @throws InvalidDataTypeException |
|
| 95 | - * @throws InvalidInterfaceException |
|
| 96 | - */ |
|
| 97 | - public function _set_page_routes() |
|
| 98 | - { |
|
| 99 | - |
|
| 100 | - $this->_set_transaction_status_array(); |
|
| 101 | - |
|
| 102 | - $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
| 103 | - && ! is_array($this->_req_data['TXN_ID']) |
|
| 104 | - ? $this->_req_data['TXN_ID'] |
|
| 105 | - : 0; |
|
| 106 | - |
|
| 107 | - $this->_page_routes = array( |
|
| 108 | - |
|
| 109 | - 'default' => array( |
|
| 110 | - 'func' => '_transactions_overview_list_table', |
|
| 111 | - 'capability' => 'ee_read_transactions', |
|
| 112 | - ), |
|
| 113 | - |
|
| 114 | - 'view_transaction' => array( |
|
| 115 | - 'func' => '_transaction_details', |
|
| 116 | - 'capability' => 'ee_read_transaction', |
|
| 117 | - 'obj_id' => $txn_id, |
|
| 118 | - ), |
|
| 119 | - |
|
| 120 | - 'send_payment_reminder' => array( |
|
| 121 | - 'func' => '_send_payment_reminder', |
|
| 122 | - 'noheader' => true, |
|
| 123 | - 'capability' => 'ee_send_message', |
|
| 124 | - ), |
|
| 125 | - |
|
| 126 | - 'espresso_apply_payment' => array( |
|
| 127 | - 'func' => 'apply_payments_or_refunds', |
|
| 128 | - 'noheader' => true, |
|
| 129 | - 'capability' => 'ee_edit_payments', |
|
| 130 | - ), |
|
| 131 | - |
|
| 132 | - 'espresso_apply_refund' => array( |
|
| 133 | - 'func' => 'apply_payments_or_refunds', |
|
| 134 | - 'noheader' => true, |
|
| 135 | - 'capability' => 'ee_edit_payments', |
|
| 136 | - ), |
|
| 137 | - |
|
| 138 | - 'espresso_delete_payment' => array( |
|
| 139 | - 'func' => 'delete_payment', |
|
| 140 | - 'noheader' => true, |
|
| 141 | - 'capability' => 'ee_delete_payments', |
|
| 142 | - ), |
|
| 143 | - |
|
| 144 | - 'espresso_recalculate_line_items' => array( |
|
| 145 | - 'func' => 'recalculateLineItems', |
|
| 146 | - 'noheader' => true, |
|
| 147 | - 'capability' => 'ee_edit_payments', |
|
| 148 | - ), |
|
| 149 | - |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - protected function _set_page_config() |
|
| 155 | - { |
|
| 156 | - $this->_page_config = array( |
|
| 157 | - 'default' => array( |
|
| 158 | - 'nav' => array( |
|
| 159 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 160 | - 'order' => 10, |
|
| 161 | - ), |
|
| 162 | - 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 163 | - 'help_tabs' => array( |
|
| 164 | - 'transactions_overview_help_tab' => array( |
|
| 165 | - 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 166 | - 'filename' => 'transactions_overview', |
|
| 167 | - ), |
|
| 168 | - 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 169 | - 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 170 | - 'filename' => 'transactions_overview_table_column_headings', |
|
| 171 | - ), |
|
| 172 | - 'transactions_overview_views_filters_help_tab' => array( |
|
| 173 | - 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 174 | - 'filename' => 'transactions_overview_views_filters_search', |
|
| 175 | - ), |
|
| 176 | - ), |
|
| 177 | - 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 178 | - /** |
|
| 179 | - * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 180 | - * may change in a later iteration so want to keep the code for then. |
|
| 181 | - */ |
|
| 182 | - // 'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 183 | - 'require_nonce' => false, |
|
| 184 | - ), |
|
| 185 | - 'view_transaction' => array( |
|
| 186 | - 'nav' => array( |
|
| 187 | - 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 188 | - 'order' => 5, |
|
| 189 | - 'url' => isset($this->_req_data['TXN_ID']) |
|
| 190 | - ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
| 191 | - : $this->_admin_base_url, |
|
| 192 | - 'persistent' => false, |
|
| 193 | - ), |
|
| 194 | - 'help_tabs' => array( |
|
| 195 | - 'transactions_view_transaction_help_tab' => array( |
|
| 196 | - 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 197 | - 'filename' => 'transactions_view_transaction', |
|
| 198 | - ), |
|
| 199 | - 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 200 | - 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 201 | - 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
| 202 | - ), |
|
| 203 | - 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 204 | - 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 205 | - 'filename' => 'transactions_view_transaction_attendees_registered', |
|
| 206 | - ), |
|
| 207 | - 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 208 | - 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 209 | - 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
| 210 | - ), |
|
| 211 | - ), |
|
| 212 | - 'qtips' => array('Transaction_Details_Tips'), |
|
| 213 | - 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 214 | - 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 215 | - |
|
| 216 | - 'require_nonce' => false, |
|
| 217 | - ), |
|
| 218 | - ); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * The below methods aren't used by this class currently |
|
| 224 | - */ |
|
| 225 | - protected function _add_screen_options() |
|
| 226 | - { |
|
| 227 | - // noop |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - protected function _add_feature_pointers() |
|
| 232 | - { |
|
| 233 | - // noop |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - public function admin_init() |
|
| 238 | - { |
|
| 239 | - // IF a registration was JUST added via the admin... |
|
| 240 | - if (isset( |
|
| 241 | - $this->_req_data['redirect_from'], |
|
| 242 | - $this->_req_data['EVT_ID'], |
|
| 243 | - $this->_req_data['event_name'] |
|
| 244 | - )) { |
|
| 245 | - // then set a cookie so that we can block any attempts to use |
|
| 246 | - // the back button as a way to enter another registration. |
|
| 247 | - setcookie( |
|
| 248 | - 'ee_registration_added', |
|
| 249 | - $this->_req_data['EVT_ID'], |
|
| 250 | - time() + WEEK_IN_SECONDS, |
|
| 251 | - '/' |
|
| 252 | - ); |
|
| 253 | - // and update the global |
|
| 254 | - $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 255 | - } |
|
| 256 | - EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
| 257 | - '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.', |
|
| 258 | - 'event_espresso' |
|
| 259 | - ); |
|
| 260 | - EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 261 | - 'An error occurred! Please refresh the page and try again.', |
|
| 262 | - 'event_espresso' |
|
| 263 | - ); |
|
| 264 | - EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 265 | - EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 266 | - EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 267 | - EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
| 268 | - 'This transaction has been overpaid ! Payments Total', |
|
| 269 | - 'event_espresso' |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - |
|
| 274 | - public function admin_notices() |
|
| 275 | - { |
|
| 276 | - // noop |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - |
|
| 280 | - public function admin_footer_scripts() |
|
| 281 | - { |
|
| 282 | - // noop |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * _set_transaction_status_array |
|
| 288 | - * sets list of transaction statuses |
|
| 289 | - * |
|
| 290 | - * @access private |
|
| 291 | - * @return void |
|
| 292 | - * @throws EE_Error |
|
| 293 | - * @throws InvalidArgumentException |
|
| 294 | - * @throws InvalidDataTypeException |
|
| 295 | - * @throws InvalidInterfaceException |
|
| 296 | - */ |
|
| 297 | - private function _set_transaction_status_array() |
|
| 298 | - { |
|
| 299 | - self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * get_transaction_status_array |
|
| 305 | - * return the transaction status array for wp_list_table |
|
| 306 | - * |
|
| 307 | - * @access public |
|
| 308 | - * @return array |
|
| 309 | - */ |
|
| 310 | - public function get_transaction_status_array() |
|
| 311 | - { |
|
| 312 | - return self::$_txn_status; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - |
|
| 316 | - /** |
|
| 317 | - * get list of payment statuses |
|
| 318 | - * |
|
| 319 | - * @access private |
|
| 320 | - * @return void |
|
| 321 | - * @throws EE_Error |
|
| 322 | - * @throws InvalidArgumentException |
|
| 323 | - * @throws InvalidDataTypeException |
|
| 324 | - * @throws InvalidInterfaceException |
|
| 325 | - */ |
|
| 326 | - private function _get_payment_status_array() |
|
| 327 | - { |
|
| 328 | - self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 329 | - $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - /** |
|
| 334 | - * _add_screen_options_default |
|
| 335 | - * |
|
| 336 | - * @access protected |
|
| 337 | - * @return void |
|
| 338 | - * @throws InvalidArgumentException |
|
| 339 | - * @throws InvalidDataTypeException |
|
| 340 | - * @throws InvalidInterfaceException |
|
| 341 | - */ |
|
| 342 | - protected function _add_screen_options_default() |
|
| 343 | - { |
|
| 344 | - $this->_per_page_screen_option(); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * load_scripts_styles |
|
| 350 | - * |
|
| 351 | - * @access public |
|
| 352 | - * @return void |
|
| 353 | - */ |
|
| 354 | - public function load_scripts_styles() |
|
| 355 | - { |
|
| 356 | - // enqueue style |
|
| 357 | - wp_register_style( |
|
| 358 | - 'espresso_txn', |
|
| 359 | - TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 360 | - array(), |
|
| 361 | - EVENT_ESPRESSO_VERSION |
|
| 362 | - ); |
|
| 363 | - wp_enqueue_style('espresso_txn'); |
|
| 364 | - // scripts |
|
| 365 | - wp_register_script( |
|
| 366 | - 'espresso_txn', |
|
| 367 | - TXN_ASSETS_URL . 'espresso_transactions_admin.js', |
|
| 368 | - array( |
|
| 369 | - 'ee_admin_js', |
|
| 370 | - 'ee-datepicker', |
|
| 371 | - 'jquery-ui-datepicker', |
|
| 372 | - 'jquery-ui-draggable', |
|
| 373 | - 'ee-dialog', |
|
| 374 | - 'ee-accounting', |
|
| 375 | - 'ee-serialize-full-array', |
|
| 376 | - ), |
|
| 377 | - EVENT_ESPRESSO_VERSION, |
|
| 378 | - true |
|
| 379 | - ); |
|
| 380 | - wp_enqueue_script('espresso_txn'); |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * load_scripts_styles_view_transaction |
|
| 386 | - * |
|
| 387 | - * @access public |
|
| 388 | - * @return void |
|
| 389 | - */ |
|
| 390 | - public function load_scripts_styles_view_transaction() |
|
| 391 | - { |
|
| 392 | - // styles |
|
| 393 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * load_scripts_styles_default |
|
| 399 | - * |
|
| 400 | - * @access public |
|
| 401 | - * @return void |
|
| 402 | - */ |
|
| 403 | - public function load_scripts_styles_default() |
|
| 404 | - { |
|
| 405 | - // styles |
|
| 406 | - wp_enqueue_style('espresso-ui-theme'); |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * _set_list_table_views_default |
|
| 412 | - * |
|
| 413 | - * @access protected |
|
| 414 | - * @return void |
|
| 415 | - */ |
|
| 416 | - protected function _set_list_table_views_default() |
|
| 417 | - { |
|
| 418 | - $this->_views = array( |
|
| 419 | - 'all' => array( |
|
| 420 | - 'slug' => 'all', |
|
| 421 | - 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 422 | - 'count' => 0, |
|
| 423 | - ), |
|
| 424 | - 'abandoned' => array( |
|
| 425 | - 'slug' => 'abandoned', |
|
| 426 | - 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 427 | - 'count' => 0, |
|
| 428 | - ), |
|
| 429 | - 'incomplete' => array( |
|
| 430 | - 'slug' => 'incomplete', |
|
| 431 | - 'label' => esc_html__('Incomplete Transactions', 'event_espresso'), |
|
| 432 | - 'count' => 0, |
|
| 433 | - ), |
|
| 434 | - ); |
|
| 435 | - if (/** |
|
| 436 | - * Filters whether a link to the "Failed Transactions" list table |
|
| 437 | - * appears on the Transactions Admin Page list table. |
|
| 438 | - * List display can be turned back on via the following: |
|
| 439 | - * add_filter( |
|
| 440 | - * 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 441 | - * '__return_true' |
|
| 442 | - * ); |
|
| 443 | - * |
|
| 444 | - * @since 4.9.70.p |
|
| 445 | - * @param boolean $display_failed_txns_list |
|
| 446 | - * @param Transactions_Admin_Page $this |
|
| 447 | - */ |
|
| 448 | - apply_filters( |
|
| 449 | - 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 450 | - false, |
|
| 451 | - $this |
|
| 452 | - ) |
|
| 453 | - ) { |
|
| 454 | - $this->_views['failed'] = array( |
|
| 455 | - 'slug' => 'failed', |
|
| 456 | - 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 457 | - 'count' => 0, |
|
| 458 | - ); |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * _set_transaction_object |
|
| 465 | - * This sets the _transaction property for the transaction details screen |
|
| 466 | - * |
|
| 467 | - * @access private |
|
| 468 | - * @return void |
|
| 469 | - * @throws EE_Error |
|
| 470 | - * @throws InvalidArgumentException |
|
| 471 | - * @throws RuntimeException |
|
| 472 | - * @throws InvalidDataTypeException |
|
| 473 | - * @throws InvalidInterfaceException |
|
| 474 | - * @throws ReflectionException |
|
| 475 | - */ |
|
| 476 | - private function _set_transaction_object() |
|
| 477 | - { |
|
| 478 | - if ($this->_transaction instanceof EE_Transaction) { |
|
| 479 | - return; |
|
| 480 | - } //get out we've already set the object |
|
| 481 | - |
|
| 482 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
| 483 | - ? absint($this->_req_data['TXN_ID']) |
|
| 484 | - : false; |
|
| 485 | - |
|
| 486 | - // get transaction object |
|
| 487 | - $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 488 | - $this->_session = $this->_transaction instanceof EE_Transaction |
|
| 489 | - ? $this->_transaction->session_data() |
|
| 490 | - : null; |
|
| 491 | - if ($this->_transaction instanceof EE_Transaction) { |
|
| 492 | - $this->_transaction->verify_abandoned_transaction_status(); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 496 | - $error_msg = sprintf( |
|
| 497 | - esc_html__( |
|
| 498 | - 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
| 499 | - 'event_espresso' |
|
| 500 | - ), |
|
| 501 | - $TXN_ID |
|
| 502 | - ); |
|
| 503 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 504 | - } |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - |
|
| 508 | - /** |
|
| 509 | - * _transaction_legend_items |
|
| 510 | - * |
|
| 511 | - * @access protected |
|
| 512 | - * @return array |
|
| 513 | - * @throws EE_Error |
|
| 514 | - * @throws InvalidArgumentException |
|
| 515 | - * @throws ReflectionException |
|
| 516 | - * @throws InvalidDataTypeException |
|
| 517 | - * @throws InvalidInterfaceException |
|
| 518 | - */ |
|
| 519 | - protected function _transaction_legend_items() |
|
| 520 | - { |
|
| 521 | - EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 522 | - $items = array(); |
|
| 523 | - |
|
| 524 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 525 | - 'ee_read_global_messages', |
|
| 526 | - 'view_filtered_messages' |
|
| 527 | - )) { |
|
| 528 | - $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 529 | - if (is_array($related_for_icon) |
|
| 530 | - && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
| 531 | - ) { |
|
| 532 | - $items['view_related_messages'] = array( |
|
| 533 | - 'class' => $related_for_icon['css_class'], |
|
| 534 | - 'desc' => $related_for_icon['label'], |
|
| 535 | - ); |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - $items = apply_filters( |
|
| 540 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 541 | - array_merge( |
|
| 542 | - $items, |
|
| 543 | - array( |
|
| 544 | - 'view_details' => array( |
|
| 545 | - 'class' => 'dashicons dashicons-cart', |
|
| 546 | - 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 547 | - ), |
|
| 548 | - 'view_invoice' => array( |
|
| 549 | - 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 550 | - 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 551 | - ), |
|
| 552 | - 'view_receipt' => array( |
|
| 553 | - 'class' => 'dashicons dashicons-media-default', |
|
| 554 | - 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
| 555 | - ), |
|
| 556 | - 'view_registration' => array( |
|
| 557 | - 'class' => 'dashicons dashicons-clipboard', |
|
| 558 | - 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 559 | - ), |
|
| 560 | - 'payment_overview_link' => array( |
|
| 561 | - 'class' => 'dashicons dashicons-money', |
|
| 562 | - 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
| 563 | - ), |
|
| 564 | - ) |
|
| 565 | - ) |
|
| 566 | - ); |
|
| 567 | - |
|
| 568 | - if (EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 569 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 570 | - 'ee_send_message', |
|
| 571 | - 'espresso_transactions_send_payment_reminder' |
|
| 572 | - ) |
|
| 573 | - ) { |
|
| 574 | - $items['send_payment_reminder'] = array( |
|
| 575 | - 'class' => 'dashicons dashicons-email-alt', |
|
| 576 | - 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
| 577 | - ); |
|
| 578 | - } else { |
|
| 579 | - $items['blank*'] = array( |
|
| 580 | - 'class' => '', |
|
| 581 | - 'desc' => '', |
|
| 582 | - ); |
|
| 583 | - } |
|
| 584 | - $more_items = apply_filters( |
|
| 585 | - 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 586 | - array( |
|
| 587 | - 'overpaid' => array( |
|
| 588 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 589 | - 'desc' => EEH_Template::pretty_status( |
|
| 590 | - EEM_Transaction::overpaid_status_code, |
|
| 591 | - false, |
|
| 592 | - 'sentence' |
|
| 593 | - ), |
|
| 594 | - ), |
|
| 595 | - 'complete' => array( |
|
| 596 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 597 | - 'desc' => EEH_Template::pretty_status( |
|
| 598 | - EEM_Transaction::complete_status_code, |
|
| 599 | - false, |
|
| 600 | - 'sentence' |
|
| 601 | - ), |
|
| 602 | - ), |
|
| 603 | - 'incomplete' => array( |
|
| 604 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 605 | - 'desc' => EEH_Template::pretty_status( |
|
| 606 | - EEM_Transaction::incomplete_status_code, |
|
| 607 | - false, |
|
| 608 | - 'sentence' |
|
| 609 | - ), |
|
| 610 | - ), |
|
| 611 | - 'abandoned' => array( |
|
| 612 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 613 | - 'desc' => EEH_Template::pretty_status( |
|
| 614 | - EEM_Transaction::abandoned_status_code, |
|
| 615 | - false, |
|
| 616 | - 'sentence' |
|
| 617 | - ), |
|
| 618 | - ), |
|
| 619 | - 'failed' => array( |
|
| 620 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 621 | - 'desc' => EEH_Template::pretty_status( |
|
| 622 | - EEM_Transaction::failed_status_code, |
|
| 623 | - false, |
|
| 624 | - 'sentence' |
|
| 625 | - ), |
|
| 626 | - ), |
|
| 627 | - ) |
|
| 628 | - ); |
|
| 629 | - |
|
| 630 | - return array_merge($items, $more_items); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - |
|
| 634 | - /** |
|
| 635 | - * _transactions_overview_list_table |
|
| 636 | - * |
|
| 637 | - * @access protected |
|
| 638 | - * @return void |
|
| 639 | - * @throws DomainException |
|
| 640 | - * @throws EE_Error |
|
| 641 | - * @throws InvalidArgumentException |
|
| 642 | - * @throws InvalidDataTypeException |
|
| 643 | - * @throws InvalidInterfaceException |
|
| 644 | - * @throws ReflectionException |
|
| 645 | - */ |
|
| 646 | - protected function _transactions_overview_list_table() |
|
| 647 | - { |
|
| 648 | - $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 649 | - $event = isset($this->_req_data['EVT_ID']) |
|
| 650 | - ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
| 651 | - : null; |
|
| 652 | - $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
| 653 | - ? sprintf( |
|
| 654 | - esc_html__( |
|
| 655 | - '%sViewing Transactions for the Event: %s%s', |
|
| 656 | - 'event_espresso' |
|
| 657 | - ), |
|
| 658 | - '<h3>', |
|
| 659 | - '<a href="' |
|
| 660 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
| 661 | - array('action' => 'edit', 'post' => $event->ID()), |
|
| 662 | - EVENTS_ADMIN_URL |
|
| 663 | - ) |
|
| 664 | - . '" title="' |
|
| 665 | - . esc_attr__( |
|
| 666 | - 'Click to Edit event', |
|
| 667 | - 'event_espresso' |
|
| 668 | - ) |
|
| 669 | - . '">' . $event->name() . '</a>', |
|
| 670 | - '</h3>' |
|
| 671 | - ) |
|
| 672 | - : ''; |
|
| 673 | - $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 674 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 675 | - } |
|
| 676 | - |
|
| 677 | - |
|
| 678 | - /** |
|
| 679 | - * _transaction_details |
|
| 680 | - * generates HTML for the View Transaction Details Admin page |
|
| 681 | - * |
|
| 682 | - * @access protected |
|
| 683 | - * @return void |
|
| 684 | - * @throws DomainException |
|
| 685 | - * @throws EE_Error |
|
| 686 | - * @throws InvalidArgumentException |
|
| 687 | - * @throws InvalidDataTypeException |
|
| 688 | - * @throws InvalidInterfaceException |
|
| 689 | - * @throws RuntimeException |
|
| 690 | - * @throws ReflectionException |
|
| 691 | - */ |
|
| 692 | - protected function _transaction_details() |
|
| 693 | - { |
|
| 694 | - do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 695 | - |
|
| 696 | - $this->_set_transaction_status_array(); |
|
| 697 | - |
|
| 698 | - $this->_template_args = array(); |
|
| 699 | - $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 700 | - |
|
| 701 | - $this->_set_transaction_object(); |
|
| 702 | - |
|
| 703 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 704 | - return; |
|
| 705 | - } |
|
| 706 | - $primary_registration = $this->_transaction->primary_registration(); |
|
| 707 | - $attendee = $primary_registration instanceof EE_Registration |
|
| 708 | - ? $primary_registration->attendee() |
|
| 709 | - : null; |
|
| 710 | - |
|
| 711 | - $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 712 | - $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 713 | - |
|
| 714 | - $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 715 | - $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 716 | - |
|
| 717 | - $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ]; |
|
| 718 | - $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 719 | - $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID(); |
|
| 720 | - |
|
| 721 | - $this->_template_args['grand_total'] = $this->_transaction->total(); |
|
| 722 | - $this->_template_args['total_paid'] = $this->_transaction->paid(); |
|
| 723 | - |
|
| 724 | - $amount_due = $this->_transaction->total() - $this->_transaction->paid(); |
|
| 725 | - $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
| 726 | - $amount_due, |
|
| 727 | - true |
|
| 728 | - ); |
|
| 729 | - if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 730 | - $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
| 731 | - . $this->_template_args['amount_due']; |
|
| 732 | - } else { |
|
| 733 | - $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
| 734 | - } |
|
| 735 | - $this->_template_args['amount_due_class'] = ''; |
|
| 736 | - |
|
| 737 | - if ($this->_transaction->paid() === $this->_transaction->total()) { |
|
| 738 | - // paid in full |
|
| 739 | - $this->_template_args['amount_due'] = false; |
|
| 740 | - } elseif ($this->_transaction->paid() > $this->_transaction->total()) { |
|
| 741 | - // overpaid |
|
| 742 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 743 | - } elseif ($this->_transaction->total() > (float) 0) { |
|
| 744 | - if ($this->_transaction->paid() > (float) 0) { |
|
| 745 | - // monies owing |
|
| 746 | - $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 747 | - } elseif ($this->_transaction->paid() === (float) 0) { |
|
| 748 | - // no payments made yet |
|
| 749 | - $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 750 | - } |
|
| 751 | - } elseif ($this->_transaction->total() === (float) 0) { |
|
| 752 | - // free event |
|
| 753 | - $this->_template_args['amount_due'] = false; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - $payment_method = $this->_transaction->payment_method(); |
|
| 757 | - |
|
| 758 | - $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 759 | - ? $payment_method->admin_name() |
|
| 760 | - : esc_html__('Unknown', 'event_espresso'); |
|
| 761 | - |
|
| 762 | - $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 763 | - // link back to overview |
|
| 764 | - $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
| 765 | - ? $_SERVER['HTTP_REFERER'] |
|
| 766 | - : TXN_ADMIN_URL; |
|
| 767 | - |
|
| 768 | - |
|
| 769 | - // next link |
|
| 770 | - $next_txn = $this->_transaction->next( |
|
| 771 | - null, |
|
| 772 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 773 | - 'TXN_ID' |
|
| 774 | - ); |
|
| 775 | - $this->_template_args['next_transaction'] = $next_txn |
|
| 776 | - ? $this->_next_link( |
|
| 777 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 778 | - array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 779 | - TXN_ADMIN_URL |
|
| 780 | - ), |
|
| 781 | - 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 782 | - ) |
|
| 783 | - : ''; |
|
| 784 | - // previous link |
|
| 785 | - $previous_txn = $this->_transaction->previous( |
|
| 786 | - null, |
|
| 787 | - array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 788 | - 'TXN_ID' |
|
| 789 | - ); |
|
| 790 | - $this->_template_args['previous_transaction'] = $previous_txn |
|
| 791 | - ? $this->_previous_link( |
|
| 792 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 793 | - array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 794 | - TXN_ADMIN_URL |
|
| 795 | - ), |
|
| 796 | - 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 797 | - ) |
|
| 798 | - : ''; |
|
| 799 | - |
|
| 800 | - // were we just redirected here after adding a new registration ??? |
|
| 801 | - if (isset( |
|
| 802 | - $this->_req_data['redirect_from'], |
|
| 803 | - $this->_req_data['EVT_ID'], |
|
| 804 | - $this->_req_data['event_name'] |
|
| 805 | - )) { |
|
| 806 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 807 | - 'ee_edit_registrations', |
|
| 808 | - 'espresso_registrations_new_registration', |
|
| 809 | - $this->_req_data['EVT_ID'] |
|
| 810 | - )) { |
|
| 811 | - $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 812 | - $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 813 | - array( |
|
| 814 | - 'page' => 'espresso_registrations', |
|
| 815 | - 'action' => 'new_registration', |
|
| 816 | - 'return' => 'default', |
|
| 817 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 818 | - 'event_id' => $this->_req_data['EVT_ID'], |
|
| 819 | - ), |
|
| 820 | - REG_ADMIN_URL |
|
| 821 | - ); |
|
| 822 | - $this->_admin_page_title .= '">'; |
|
| 823 | - |
|
| 824 | - $this->_admin_page_title .= sprintf( |
|
| 825 | - esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 826 | - htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 827 | - ); |
|
| 828 | - $this->_admin_page_title .= '</a>'; |
|
| 829 | - } |
|
| 830 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 831 | - } |
|
| 832 | - // grab messages at the last second |
|
| 833 | - $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 834 | - // path to template |
|
| 835 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 836 | - $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 837 | - $template_path, |
|
| 838 | - $this->_template_args, |
|
| 839 | - true |
|
| 840 | - ); |
|
| 841 | - |
|
| 842 | - // the details template wrapper |
|
| 843 | - $this->display_admin_page_with_sidebar(); |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - |
|
| 847 | - /** |
|
| 848 | - * _transaction_details_metaboxes |
|
| 849 | - * |
|
| 850 | - * @access protected |
|
| 851 | - * @return void |
|
| 852 | - * @throws EE_Error |
|
| 853 | - * @throws InvalidArgumentException |
|
| 854 | - * @throws InvalidDataTypeException |
|
| 855 | - * @throws InvalidInterfaceException |
|
| 856 | - * @throws RuntimeException |
|
| 857 | - * @throws ReflectionException |
|
| 858 | - */ |
|
| 859 | - protected function _transaction_details_metaboxes() |
|
| 860 | - { |
|
| 861 | - |
|
| 862 | - $this->_set_transaction_object(); |
|
| 863 | - |
|
| 864 | - if (! $this->_transaction instanceof EE_Transaction) { |
|
| 865 | - return; |
|
| 866 | - } |
|
| 867 | - add_meta_box( |
|
| 868 | - 'edit-txn-details-mbox', |
|
| 869 | - esc_html__('Transaction Details', 'event_espresso'), |
|
| 870 | - array($this, 'txn_details_meta_box'), |
|
| 871 | - $this->_wp_page_slug, |
|
| 872 | - 'normal', |
|
| 873 | - 'high' |
|
| 874 | - ); |
|
| 875 | - add_meta_box( |
|
| 876 | - 'edit-txn-attendees-mbox', |
|
| 877 | - esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 878 | - array($this, 'txn_attendees_meta_box'), |
|
| 879 | - $this->_wp_page_slug, |
|
| 880 | - 'normal', |
|
| 881 | - 'high', |
|
| 882 | - array('TXN_ID' => $this->_transaction->ID()) |
|
| 883 | - ); |
|
| 884 | - add_meta_box( |
|
| 885 | - 'edit-txn-registrant-mbox', |
|
| 886 | - esc_html__('Primary Contact', 'event_espresso'), |
|
| 887 | - array($this, 'txn_registrant_side_meta_box'), |
|
| 888 | - $this->_wp_page_slug, |
|
| 889 | - 'side', |
|
| 890 | - 'high' |
|
| 891 | - ); |
|
| 892 | - add_meta_box( |
|
| 893 | - 'edit-txn-billing-info-mbox', |
|
| 894 | - esc_html__('Billing Information', 'event_espresso'), |
|
| 895 | - array($this, 'txn_billing_info_side_meta_box'), |
|
| 896 | - $this->_wp_page_slug, |
|
| 897 | - 'side', |
|
| 898 | - 'high' |
|
| 899 | - ); |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * Callback for transaction actions metabox. |
|
| 905 | - * |
|
| 906 | - * @param EE_Transaction|null $transaction |
|
| 907 | - * @return string |
|
| 908 | - * @throws DomainException |
|
| 909 | - * @throws EE_Error |
|
| 910 | - * @throws InvalidArgumentException |
|
| 911 | - * @throws InvalidDataTypeException |
|
| 912 | - * @throws InvalidInterfaceException |
|
| 913 | - * @throws ReflectionException |
|
| 914 | - * @throws RuntimeException |
|
| 915 | - */ |
|
| 916 | - public function getActionButtons(EE_Transaction $transaction = null) |
|
| 917 | - { |
|
| 918 | - $content = ''; |
|
| 919 | - $actions = array(); |
|
| 920 | - if (! $transaction instanceof EE_Transaction) { |
|
| 921 | - return $content; |
|
| 922 | - } |
|
| 923 | - /** @var EE_Registration $primary_registration */ |
|
| 924 | - $primary_registration = $transaction->primary_registration(); |
|
| 925 | - $attendee = $primary_registration instanceof EE_Registration |
|
| 926 | - ? $primary_registration->attendee() |
|
| 927 | - : null; |
|
| 928 | - |
|
| 929 | - if ($attendee instanceof EE_Attendee |
|
| 930 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 931 | - 'ee_send_message', |
|
| 932 | - 'espresso_transactions_send_payment_reminder' |
|
| 933 | - ) |
|
| 934 | - ) { |
|
| 935 | - $actions['payment_reminder'] = |
|
| 936 | - EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 937 | - && $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
| 938 | - && $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code |
|
| 939 | - ? EEH_Template::get_button_or_link( |
|
| 940 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 941 | - array( |
|
| 942 | - 'action' => 'send_payment_reminder', |
|
| 943 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 944 | - 'redirect_to' => 'view_transaction', |
|
| 945 | - ), |
|
| 946 | - TXN_ADMIN_URL |
|
| 947 | - ), |
|
| 948 | - esc_html__(' Send Payment Reminder', 'event_espresso'), |
|
| 949 | - 'button secondary-button', |
|
| 950 | - 'dashicons dashicons-email-alt' |
|
| 951 | - ) |
|
| 952 | - : ''; |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
| 956 | - 'ee_edit_payments', |
|
| 957 | - 'espresso_transactions_recalculate_line_items' |
|
| 958 | - ) |
|
| 959 | - ) { |
|
| 960 | - $actions['recalculate_line_items'] = EEH_Template::get_button_or_link( |
|
| 961 | - EE_Admin_Page::add_query_args_and_nonce( |
|
| 962 | - array( |
|
| 963 | - 'action' => 'espresso_recalculate_line_items', |
|
| 964 | - 'TXN_ID' => $this->_transaction->ID(), |
|
| 965 | - 'redirect_to' => 'view_transaction', |
|
| 966 | - ), |
|
| 967 | - TXN_ADMIN_URL |
|
| 968 | - ), |
|
| 969 | - esc_html__(' Recalculate Taxes and Total', 'event_espresso'), |
|
| 970 | - 'button secondary-button', |
|
| 971 | - 'dashicons dashicons-update' |
|
| 972 | - ); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - if ($primary_registration instanceof EE_Registration |
|
| 976 | - && EEH_MSG_Template::is_mt_active('receipt') |
|
| 977 | - ) { |
|
| 978 | - $actions['receipt'] = EEH_Template::get_button_or_link( |
|
| 979 | - $primary_registration->receipt_url(), |
|
| 980 | - esc_html__('View Receipt', 'event_espresso'), |
|
| 981 | - 'button secondary-button', |
|
| 982 | - 'dashicons dashicons-media-default' |
|
| 983 | - ); |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - if ($primary_registration instanceof EE_Registration |
|
| 987 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
| 988 | - ) { |
|
| 989 | - $actions['invoice'] = EEH_Template::get_button_or_link( |
|
| 990 | - $primary_registration->invoice_url(), |
|
| 991 | - esc_html__('View Invoice', 'event_espresso'), |
|
| 992 | - 'button secondary-button', |
|
| 993 | - 'dashicons dashicons-media-spreadsheet' |
|
| 994 | - ); |
|
| 995 | - } |
|
| 996 | - $actions = array_filter( |
|
| 997 | - apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction) |
|
| 998 | - ); |
|
| 999 | - if ($actions) { |
|
| 1000 | - $content = '<ul>'; |
|
| 1001 | - $content .= '<li>' . implode('</li><li>', $actions) . '</li>'; |
|
| 1002 | - $content .= '</uL>'; |
|
| 1003 | - } |
|
| 1004 | - return $content; |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - |
|
| 1008 | - /** |
|
| 1009 | - * txn_details_meta_box |
|
| 1010 | - * generates HTML for the Transaction main meta box |
|
| 1011 | - * |
|
| 1012 | - * @return void |
|
| 1013 | - * @throws DomainException |
|
| 1014 | - * @throws EE_Error |
|
| 1015 | - * @throws InvalidArgumentException |
|
| 1016 | - * @throws InvalidDataTypeException |
|
| 1017 | - * @throws InvalidInterfaceException |
|
| 1018 | - * @throws RuntimeException |
|
| 1019 | - * @throws ReflectionException |
|
| 1020 | - */ |
|
| 1021 | - public function txn_details_meta_box() |
|
| 1022 | - { |
|
| 1023 | - $this->_set_transaction_object(); |
|
| 1024 | - $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 1025 | - $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1026 | - ? $this->_transaction->primary_registration()->attendee() |
|
| 1027 | - : null; |
|
| 1028 | - $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1029 | - 'ee_edit_payments', |
|
| 1030 | - 'apply_payment_or_refund_from_registration_details' |
|
| 1031 | - ); |
|
| 1032 | - $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1033 | - 'ee_delete_payments', |
|
| 1034 | - 'delete_payment_from_registration_details' |
|
| 1035 | - ); |
|
| 1036 | - |
|
| 1037 | - // get line table |
|
| 1038 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1039 | - $Line_Item_Display = new EE_Line_Item_Display( |
|
| 1040 | - 'admin_table', |
|
| 1041 | - 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
| 1042 | - ); |
|
| 1043 | - $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
| 1044 | - $this->_transaction->total_line_item() |
|
| 1045 | - ); |
|
| 1046 | - $this->_template_args['REG_code'] = $this->_transaction->primary_registration()->reg_code(); |
|
| 1047 | - |
|
| 1048 | - // process taxes |
|
| 1049 | - $taxes = $this->_transaction->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 1050 | - $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 1051 | - |
|
| 1052 | - $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 1053 | - $this->_transaction->total(), |
|
| 1054 | - false, |
|
| 1055 | - false |
|
| 1056 | - ); |
|
| 1057 | - $this->_template_args['grand_raw_total'] = $this->_transaction->total(); |
|
| 1058 | - $this->_template_args['TXN_status'] = $this->_transaction->status_ID(); |
|
| 1059 | - |
|
| 1060 | - // process payment details |
|
| 1061 | - $payments = $this->_transaction->payments(); |
|
| 1062 | - if (! empty($payments)) { |
|
| 1063 | - $this->_template_args['payments'] = $payments; |
|
| 1064 | - $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 1065 | - } else { |
|
| 1066 | - $this->_template_args['payments'] = false; |
|
| 1067 | - $this->_template_args['existing_reg_payments'] = array(); |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 1071 | - $this->_template_args['delete_payment_url'] = add_query_arg( |
|
| 1072 | - array('action' => 'espresso_delete_payment'), |
|
| 1073 | - TXN_ADMIN_URL |
|
| 1074 | - ); |
|
| 1075 | - |
|
| 1076 | - if (isset($txn_details['invoice_number'])) { |
|
| 1077 | - $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 1078 | - $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
| 1079 | - 'Invoice Number', |
|
| 1080 | - 'event_espresso' |
|
| 1081 | - ); |
|
| 1082 | - } |
|
| 1083 | - |
|
| 1084 | - $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
| 1085 | - ->primary_registration() |
|
| 1086 | - ->session_ID(); |
|
| 1087 | - $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
| 1088 | - 'Registration Session', |
|
| 1089 | - 'event_espresso' |
|
| 1090 | - ); |
|
| 1091 | - |
|
| 1092 | - $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
| 1093 | - ? $this->_session['ip_address'] |
|
| 1094 | - : ''; |
|
| 1095 | - $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
| 1096 | - 'Transaction placed from IP', |
|
| 1097 | - 'event_espresso' |
|
| 1098 | - ); |
|
| 1099 | - |
|
| 1100 | - $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
| 1101 | - ? $this->_session['user_agent'] |
|
| 1102 | - : ''; |
|
| 1103 | - $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
| 1104 | - 'Registrant User Agent', |
|
| 1105 | - 'event_espresso' |
|
| 1106 | - ); |
|
| 1107 | - |
|
| 1108 | - $reg_steps = '<ul>'; |
|
| 1109 | - foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 1110 | - if ($reg_step_status === true) { |
|
| 1111 | - $reg_steps .= '<li style="color:#70cc50">' |
|
| 1112 | - . sprintf( |
|
| 1113 | - esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 1114 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1115 | - ) |
|
| 1116 | - . '</li>'; |
|
| 1117 | - } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 1118 | - $reg_steps .= '<li style="color:#2EA2CC">' |
|
| 1119 | - . sprintf( |
|
| 1120 | - esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 1121 | - ucwords(str_replace('_', ' ', $reg_step)), |
|
| 1122 | - date( |
|
| 1123 | - get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1124 | - $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1125 | - ) |
|
| 1126 | - ) |
|
| 1127 | - . '</li>'; |
|
| 1128 | - } else { |
|
| 1129 | - $reg_steps .= '<li style="color:#E76700">' |
|
| 1130 | - . sprintf( |
|
| 1131 | - esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
| 1132 | - ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1133 | - ) |
|
| 1134 | - . '</li>'; |
|
| 1135 | - } |
|
| 1136 | - } |
|
| 1137 | - $reg_steps .= '</ul>'; |
|
| 1138 | - $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 1139 | - $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
| 1140 | - 'Registration Step Progress', |
|
| 1141 | - 'event_espresso' |
|
| 1142 | - ); |
|
| 1143 | - |
|
| 1144 | - |
|
| 1145 | - $this->_get_registrations_to_apply_payment_to(); |
|
| 1146 | - $this->_get_payment_methods($payments); |
|
| 1147 | - $this->_get_payment_status_array(); |
|
| 1148 | - $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction. |
|
| 1149 | - |
|
| 1150 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1151 | - array( |
|
| 1152 | - 'action' => 'edit_transaction', |
|
| 1153 | - 'process' => 'transaction', |
|
| 1154 | - ), |
|
| 1155 | - TXN_ADMIN_URL |
|
| 1156 | - ); |
|
| 1157 | - $this->_template_args['apply_payment_form_url'] = add_query_arg( |
|
| 1158 | - array( |
|
| 1159 | - 'page' => 'espresso_transactions', |
|
| 1160 | - 'action' => 'espresso_apply_payment', |
|
| 1161 | - ), |
|
| 1162 | - WP_AJAX_URL |
|
| 1163 | - ); |
|
| 1164 | - $this->_template_args['delete_payment_form_url'] = add_query_arg( |
|
| 1165 | - array( |
|
| 1166 | - 'page' => 'espresso_transactions', |
|
| 1167 | - 'action' => 'espresso_delete_payment', |
|
| 1168 | - ), |
|
| 1169 | - WP_AJAX_URL |
|
| 1170 | - ); |
|
| 1171 | - |
|
| 1172 | - $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction); |
|
| 1173 | - |
|
| 1174 | - // 'espresso_delete_payment_nonce' |
|
| 1175 | - |
|
| 1176 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1177 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1178 | - } |
|
| 1179 | - |
|
| 1180 | - |
|
| 1181 | - /** |
|
| 1182 | - * _get_registration_payment_IDs |
|
| 1183 | - * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 1184 | - * |
|
| 1185 | - * @access protected |
|
| 1186 | - * @param EE_Payment[] $payments |
|
| 1187 | - * @return array |
|
| 1188 | - * @throws EE_Error |
|
| 1189 | - * @throws InvalidArgumentException |
|
| 1190 | - * @throws InvalidDataTypeException |
|
| 1191 | - * @throws InvalidInterfaceException |
|
| 1192 | - * @throws ReflectionException |
|
| 1193 | - */ |
|
| 1194 | - protected function _get_registration_payment_IDs($payments = array()) |
|
| 1195 | - { |
|
| 1196 | - $existing_reg_payments = array(); |
|
| 1197 | - // get all reg payments for these payments |
|
| 1198 | - $reg_payments = EEM_Registration_Payment::instance()->get_all( |
|
| 1199 | - array( |
|
| 1200 | - array( |
|
| 1201 | - 'PAY_ID' => array( |
|
| 1202 | - 'IN', |
|
| 1203 | - array_keys($payments), |
|
| 1204 | - ), |
|
| 1205 | - ), |
|
| 1206 | - ) |
|
| 1207 | - ); |
|
| 1208 | - if (! empty($reg_payments)) { |
|
| 1209 | - foreach ($payments as $payment) { |
|
| 1210 | - if (! $payment instanceof EE_Payment) { |
|
| 1211 | - continue; |
|
| 1212 | - } elseif (! isset($existing_reg_payments[ $payment->ID() ])) { |
|
| 1213 | - $existing_reg_payments[ $payment->ID() ] = array(); |
|
| 1214 | - } |
|
| 1215 | - foreach ($reg_payments as $reg_payment) { |
|
| 1216 | - if ($reg_payment instanceof EE_Registration_Payment |
|
| 1217 | - && $reg_payment->payment_ID() === $payment->ID() |
|
| 1218 | - ) { |
|
| 1219 | - $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID(); |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - } |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - return $existing_reg_payments; |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - |
|
| 1229 | - /** |
|
| 1230 | - * _get_registrations_to_apply_payment_to |
|
| 1231 | - * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 1232 | - * which allows the admin to only apply the payment to the specific registrations |
|
| 1233 | - * |
|
| 1234 | - * @access protected |
|
| 1235 | - * @return void |
|
| 1236 | - * @throws EE_Error |
|
| 1237 | - * @throws InvalidArgumentException |
|
| 1238 | - * @throws InvalidDataTypeException |
|
| 1239 | - * @throws InvalidInterfaceException |
|
| 1240 | - * @throws ReflectionException |
|
| 1241 | - */ |
|
| 1242 | - protected function _get_registrations_to_apply_payment_to() |
|
| 1243 | - { |
|
| 1244 | - // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 1245 | - $query_params = array( |
|
| 1246 | - array( |
|
| 1247 | - 'STS_ID' => array( |
|
| 1248 | - 'IN', |
|
| 1249 | - array( |
|
| 1250 | - EEM_Registration::status_id_approved, |
|
| 1251 | - EEM_Registration::status_id_pending_payment, |
|
| 1252 | - EEM_Registration::status_id_not_approved, |
|
| 1253 | - ), |
|
| 1254 | - ), |
|
| 1255 | - ), |
|
| 1256 | - ); |
|
| 1257 | - $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 1258 | - '', |
|
| 1259 | - 'txn-admin-apply-payment-to-registrations-dv', |
|
| 1260 | - '', |
|
| 1261 | - 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 1262 | - ); |
|
| 1263 | - $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1264 | - $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 1265 | - $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 1266 | - EEH_HTML::tr( |
|
| 1267 | - EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1268 | - EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1269 | - EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1270 | - EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1271 | - EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1272 | - EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1273 | - EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 1274 | - ) |
|
| 1275 | - ); |
|
| 1276 | - $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 1277 | - // get registrations for TXN |
|
| 1278 | - $registrations = $this->_transaction->registrations($query_params); |
|
| 1279 | - $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
| 1280 | - foreach ($registrations as $registration) { |
|
| 1281 | - if ($registration instanceof EE_Registration) { |
|
| 1282 | - $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 1283 | - ? $registration->attendee()->full_name() |
|
| 1284 | - : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 1285 | - $owing = $registration->final_price() - $registration->paid(); |
|
| 1286 | - $taxable = $registration->ticket()->taxable() |
|
| 1287 | - ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1288 | - : ''; |
|
| 1289 | - $checked = empty($existing_reg_payments) |
|
| 1290 | - || in_array($registration->ID(), $existing_reg_payments, true) |
|
| 1291 | - ? ' checked="checked"' |
|
| 1292 | - : ''; |
|
| 1293 | - $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1294 | - $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 1295 | - EEH_HTML::td($registration->ID()) . |
|
| 1296 | - EEH_HTML::td($attendee_name) . |
|
| 1297 | - EEH_HTML::td( |
|
| 1298 | - $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1299 | - ) . |
|
| 1300 | - EEH_HTML::td($registration->event_name()) . |
|
| 1301 | - EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1302 | - EEH_HTML::td( |
|
| 1303 | - EEH_Template::format_currency($owing), |
|
| 1304 | - '', |
|
| 1305 | - 'txn-admin-payment-owing-td jst-cntr' |
|
| 1306 | - ) . |
|
| 1307 | - EEH_HTML::td( |
|
| 1308 | - '<input type="checkbox" value="' . $registration->ID() |
|
| 1309 | - . '" name="txn_admin_payment[registrations]"' |
|
| 1310 | - . $checked . $disabled . '>', |
|
| 1311 | - '', |
|
| 1312 | - 'jst-cntr' |
|
| 1313 | - ), |
|
| 1314 | - 'apply-payment-registration-row-' . $registration->ID() |
|
| 1315 | - ); |
|
| 1316 | - } |
|
| 1317 | - } |
|
| 1318 | - $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1319 | - $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1320 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1321 | - $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1322 | - esc_html__( |
|
| 1323 | - '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.', |
|
| 1324 | - 'event_espresso' |
|
| 1325 | - ), |
|
| 1326 | - '', |
|
| 1327 | - 'clear description' |
|
| 1328 | - ); |
|
| 1329 | - $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1330 | - $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - |
|
| 1334 | - /** |
|
| 1335 | - * _get_reg_status_selection |
|
| 1336 | - * |
|
| 1337 | - * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1338 | - * instead of events. |
|
| 1339 | - * @access protected |
|
| 1340 | - * @return void |
|
| 1341 | - * @throws EE_Error |
|
| 1342 | - */ |
|
| 1343 | - protected function _get_reg_status_selection() |
|
| 1344 | - { |
|
| 1345 | - // first get all possible statuses |
|
| 1346 | - $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1347 | - // let's add a "don't change" option. |
|
| 1348 | - $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1349 | - $status_array = array_merge($status_array, $statuses); |
|
| 1350 | - $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1351 | - 'txn_reg_status_change[reg_status]', |
|
| 1352 | - $status_array, |
|
| 1353 | - 'NAN', |
|
| 1354 | - 'id="txn-admin-payment-reg-status-inp"', |
|
| 1355 | - 'txn-reg-status-change-reg-status' |
|
| 1356 | - ); |
|
| 1357 | - $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1358 | - 'delete_txn_reg_status_change[reg_status]', |
|
| 1359 | - $status_array, |
|
| 1360 | - 'NAN', |
|
| 1361 | - 'delete-txn-admin-payment-reg-status-inp', |
|
| 1362 | - 'delete-txn-reg-status-change-reg-status' |
|
| 1363 | - ); |
|
| 1364 | - } |
|
| 1365 | - |
|
| 1366 | - |
|
| 1367 | - /** |
|
| 1368 | - * _get_payment_methods |
|
| 1369 | - * Gets all the payment methods available generally, or the ones that are already |
|
| 1370 | - * selected on these payments (in case their payment methods are no longer active). |
|
| 1371 | - * Has the side-effect of updating the template args' payment_methods item |
|
| 1372 | - * |
|
| 1373 | - * @access private |
|
| 1374 | - * @param EE_Payment[] to show on this page |
|
| 1375 | - * @return void |
|
| 1376 | - * @throws EE_Error |
|
| 1377 | - * @throws InvalidArgumentException |
|
| 1378 | - * @throws InvalidDataTypeException |
|
| 1379 | - * @throws InvalidInterfaceException |
|
| 1380 | - * @throws ReflectionException |
|
| 1381 | - */ |
|
| 1382 | - private function _get_payment_methods($payments = array()) |
|
| 1383 | - { |
|
| 1384 | - $payment_methods_of_payments = array(); |
|
| 1385 | - foreach ($payments as $payment) { |
|
| 1386 | - if ($payment instanceof EE_Payment) { |
|
| 1387 | - $payment_methods_of_payments[] = $payment->ID(); |
|
| 1388 | - } |
|
| 1389 | - } |
|
| 1390 | - if ($payment_methods_of_payments) { |
|
| 1391 | - $query_args = array( |
|
| 1392 | - array( |
|
| 1393 | - 'OR*payment_method_for_payment' => array( |
|
| 1394 | - 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1395 | - 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1396 | - ), |
|
| 1397 | - ), |
|
| 1398 | - ); |
|
| 1399 | - } else { |
|
| 1400 | - $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1401 | - } |
|
| 1402 | - $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - |
|
| 1406 | - /** |
|
| 1407 | - * txn_attendees_meta_box |
|
| 1408 | - * generates HTML for the Attendees Transaction main meta box |
|
| 1409 | - * |
|
| 1410 | - * @access public |
|
| 1411 | - * @param WP_Post $post |
|
| 1412 | - * @param array $metabox |
|
| 1413 | - * @return void |
|
| 1414 | - * @throws DomainException |
|
| 1415 | - * @throws EE_Error |
|
| 1416 | - * @throws InvalidArgumentException |
|
| 1417 | - * @throws InvalidDataTypeException |
|
| 1418 | - * @throws InvalidInterfaceException |
|
| 1419 | - * @throws ReflectionException |
|
| 1420 | - */ |
|
| 1421 | - public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1422 | - { |
|
| 1423 | - |
|
| 1424 | - /** @noinspection NonSecureExtractUsageInspection */ |
|
| 1425 | - extract($metabox['args']); |
|
| 1426 | - $this->_template_args['post'] = $post; |
|
| 1427 | - $this->_template_args['event_attendees'] = array(); |
|
| 1428 | - // process items in cart |
|
| 1429 | - $line_items = $this->_transaction->get_many_related( |
|
| 1430 | - 'Line_Item', |
|
| 1431 | - array(array('LIN_type' => 'line-item')) |
|
| 1432 | - ); |
|
| 1433 | - if (! empty($line_items)) { |
|
| 1434 | - foreach ($line_items as $item) { |
|
| 1435 | - if ($item instanceof EE_Line_Item) { |
|
| 1436 | - switch ($item->OBJ_type()) { |
|
| 1437 | - case 'Event': |
|
| 1438 | - break; |
|
| 1439 | - case 'Ticket': |
|
| 1440 | - $ticket = $item->ticket(); |
|
| 1441 | - // right now we're only handling tickets here. |
|
| 1442 | - // Cause its expected that only tickets will have attendees right? |
|
| 1443 | - if (! $ticket instanceof EE_Ticket) { |
|
| 1444 | - break; |
|
| 1445 | - } |
|
| 1446 | - try { |
|
| 1447 | - $event_name = $ticket->get_event_name(); |
|
| 1448 | - } catch (Exception $e) { |
|
| 1449 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1450 | - $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1451 | - } |
|
| 1452 | - $event_name .= ' - ' . $item->name(); |
|
| 1453 | - $ticket_price = EEH_Template::format_currency($item->unit_price()); |
|
| 1454 | - // now get all of the registrations for this transaction that use this ticket |
|
| 1455 | - $registrations = $ticket->registrations( |
|
| 1456 | - array(array('TXN_ID' => $this->_transaction->ID())) |
|
| 1457 | - ); |
|
| 1458 | - foreach ($registrations as $registration) { |
|
| 1459 | - if (! $registration instanceof EE_Registration) { |
|
| 1460 | - break; |
|
| 1461 | - } |
|
| 1462 | - $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID'] |
|
| 1463 | - = $registration->status_ID(); |
|
| 1464 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_num'] |
|
| 1465 | - = $registration->count(); |
|
| 1466 | - $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name'] |
|
| 1467 | - = $event_name; |
|
| 1468 | - $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price'] |
|
| 1469 | - = $ticket_price; |
|
| 1470 | - // attendee info |
|
| 1471 | - $attendee = $registration->get_first_related('Attendee'); |
|
| 1472 | - if ($attendee instanceof EE_Attendee) { |
|
| 1473 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] |
|
| 1474 | - = $attendee->ID(); |
|
| 1475 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] |
|
| 1476 | - = $attendee->full_name(); |
|
| 1477 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] |
|
| 1478 | - = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1479 | - . esc_html__( |
|
| 1480 | - ' Event', |
|
| 1481 | - 'event_espresso' |
|
| 1482 | - ) |
|
| 1483 | - . '">' . $attendee->email() . '</a>'; |
|
| 1484 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] |
|
| 1485 | - = EEH_Address::format($attendee, 'inline', false, false); |
|
| 1486 | - } else { |
|
| 1487 | - $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = ''; |
|
| 1488 | - $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = ''; |
|
| 1489 | - $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = ''; |
|
| 1490 | - $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = ''; |
|
| 1491 | - } |
|
| 1492 | - } |
|
| 1493 | - break; |
|
| 1494 | - } |
|
| 1495 | - } |
|
| 1496 | - } |
|
| 1497 | - |
|
| 1498 | - $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1499 | - array( |
|
| 1500 | - 'action' => 'edit_transaction', |
|
| 1501 | - 'process' => 'attendees', |
|
| 1502 | - ), |
|
| 1503 | - TXN_ADMIN_URL |
|
| 1504 | - ); |
|
| 1505 | - echo EEH_Template::display_template( |
|
| 1506 | - TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1507 | - $this->_template_args, |
|
| 1508 | - true |
|
| 1509 | - ); |
|
| 1510 | - } else { |
|
| 1511 | - echo sprintf( |
|
| 1512 | - esc_html__( |
|
| 1513 | - '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1514 | - 'event_espresso' |
|
| 1515 | - ), |
|
| 1516 | - '<p class="important-notice">', |
|
| 1517 | - '</p>' |
|
| 1518 | - ); |
|
| 1519 | - } |
|
| 1520 | - } |
|
| 1521 | - |
|
| 1522 | - |
|
| 1523 | - /** |
|
| 1524 | - * txn_registrant_side_meta_box |
|
| 1525 | - * generates HTML for the Edit Transaction side meta box |
|
| 1526 | - * |
|
| 1527 | - * @access public |
|
| 1528 | - * @return void |
|
| 1529 | - * @throws DomainException |
|
| 1530 | - * @throws EE_Error |
|
| 1531 | - * @throws InvalidArgumentException |
|
| 1532 | - * @throws InvalidDataTypeException |
|
| 1533 | - * @throws InvalidInterfaceException |
|
| 1534 | - * @throws ReflectionException |
|
| 1535 | - */ |
|
| 1536 | - public function txn_registrant_side_meta_box() |
|
| 1537 | - { |
|
| 1538 | - $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1539 | - ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
| 1540 | - : null; |
|
| 1541 | - if (! $primary_att instanceof EE_Attendee) { |
|
| 1542 | - $this->_template_args['no_attendee_message'] = esc_html__( |
|
| 1543 | - 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1544 | - 'event_espresso' |
|
| 1545 | - ); |
|
| 1546 | - $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1547 | - } |
|
| 1548 | - $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1549 | - $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1550 | - $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1551 | - $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1552 | - $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1553 | - $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1554 | - array( |
|
| 1555 | - 'action' => 'edit_attendee', |
|
| 1556 | - 'post' => $primary_att->ID(), |
|
| 1557 | - ), |
|
| 1558 | - REG_ADMIN_URL |
|
| 1559 | - ); |
|
| 1560 | - // get formatted address for registrant |
|
| 1561 | - $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1562 | - echo EEH_Template::display_template( |
|
| 1563 | - TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1564 | - $this->_template_args, |
|
| 1565 | - true |
|
| 1566 | - ); |
|
| 1567 | - } |
|
| 1568 | - |
|
| 1569 | - |
|
| 1570 | - /** |
|
| 1571 | - * txn_billing_info_side_meta_box |
|
| 1572 | - * generates HTML for the Edit Transaction side meta box |
|
| 1573 | - * |
|
| 1574 | - * @access public |
|
| 1575 | - * @return void |
|
| 1576 | - * @throws DomainException |
|
| 1577 | - * @throws EE_Error |
|
| 1578 | - */ |
|
| 1579 | - public function txn_billing_info_side_meta_box() |
|
| 1580 | - { |
|
| 1581 | - |
|
| 1582 | - $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1583 | - $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1584 | - array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1585 | - TXN_ADMIN_URL |
|
| 1586 | - ); |
|
| 1587 | - |
|
| 1588 | - $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1589 | - echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - |
|
| 1593 | - /** |
|
| 1594 | - * apply_payments_or_refunds |
|
| 1595 | - * registers a payment or refund made towards a transaction |
|
| 1596 | - * |
|
| 1597 | - * @access public |
|
| 1598 | - * @return void |
|
| 1599 | - * @throws EE_Error |
|
| 1600 | - * @throws InvalidArgumentException |
|
| 1601 | - * @throws ReflectionException |
|
| 1602 | - * @throws RuntimeException |
|
| 1603 | - * @throws InvalidDataTypeException |
|
| 1604 | - * @throws InvalidInterfaceException |
|
| 1605 | - */ |
|
| 1606 | - public function apply_payments_or_refunds() |
|
| 1607 | - { |
|
| 1608 | - $json_response_data = array('return_data' => false); |
|
| 1609 | - $valid_data = $this->_validate_payment_request_data(); |
|
| 1610 | - $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
| 1611 | - 'ee_edit_payments', |
|
| 1612 | - 'apply_payment_or_refund_from_registration_details' |
|
| 1613 | - ); |
|
| 1614 | - if (! empty($valid_data) && $has_access) { |
|
| 1615 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1616 | - // save the new payment |
|
| 1617 | - $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1618 | - // get the TXN for this payment |
|
| 1619 | - $transaction = $payment->transaction(); |
|
| 1620 | - // verify transaction |
|
| 1621 | - if ($transaction instanceof EE_Transaction) { |
|
| 1622 | - // calculate_total_payments_and_update_status |
|
| 1623 | - $this->_process_transaction_payments($transaction); |
|
| 1624 | - $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1625 | - $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1626 | - // apply payment to registrations (if applicable) |
|
| 1627 | - if (! empty($REG_IDs)) { |
|
| 1628 | - $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1629 | - $this->_maybe_send_notifications(); |
|
| 1630 | - // now process status changes for the same registrations |
|
| 1631 | - $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1632 | - } |
|
| 1633 | - $this->_maybe_send_notifications($payment); |
|
| 1634 | - // prepare to render page |
|
| 1635 | - $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1636 | - do_action( |
|
| 1637 | - 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
| 1638 | - $transaction, |
|
| 1639 | - $payment |
|
| 1640 | - ); |
|
| 1641 | - } else { |
|
| 1642 | - EE_Error::add_error( |
|
| 1643 | - esc_html__( |
|
| 1644 | - 'A valid Transaction for this payment could not be retrieved.', |
|
| 1645 | - 'event_espresso' |
|
| 1646 | - ), |
|
| 1647 | - __FILE__, |
|
| 1648 | - __FUNCTION__, |
|
| 1649 | - __LINE__ |
|
| 1650 | - ); |
|
| 1651 | - } |
|
| 1652 | - } elseif ($has_access) { |
|
| 1653 | - EE_Error::add_error( |
|
| 1654 | - esc_html__( |
|
| 1655 | - 'The payment form data could not be processed. Please try again.', |
|
| 1656 | - 'event_espresso' |
|
| 1657 | - ), |
|
| 1658 | - __FILE__, |
|
| 1659 | - __FUNCTION__, |
|
| 1660 | - __LINE__ |
|
| 1661 | - ); |
|
| 1662 | - } else { |
|
| 1663 | - EE_Error::add_error( |
|
| 1664 | - esc_html__( |
|
| 1665 | - 'You do not have access to apply payments or refunds to a registration.', |
|
| 1666 | - 'event_espresso' |
|
| 1667 | - ), |
|
| 1668 | - __FILE__, |
|
| 1669 | - __FUNCTION__, |
|
| 1670 | - __LINE__ |
|
| 1671 | - ); |
|
| 1672 | - } |
|
| 1673 | - $notices = EE_Error::get_notices( |
|
| 1674 | - false, |
|
| 1675 | - false, |
|
| 1676 | - false |
|
| 1677 | - ); |
|
| 1678 | - $this->_template_args = array( |
|
| 1679 | - 'data' => $json_response_data, |
|
| 1680 | - 'error' => $notices['errors'], |
|
| 1681 | - 'success' => $notices['success'], |
|
| 1682 | - ); |
|
| 1683 | - $this->_return_json(); |
|
| 1684 | - } |
|
| 1685 | - |
|
| 1686 | - |
|
| 1687 | - /** |
|
| 1688 | - * _validate_payment_request_data |
|
| 1689 | - * |
|
| 1690 | - * @return array |
|
| 1691 | - * @throws EE_Error |
|
| 1692 | - * @throws InvalidArgumentException |
|
| 1693 | - * @throws InvalidDataTypeException |
|
| 1694 | - * @throws InvalidInterfaceException |
|
| 1695 | - */ |
|
| 1696 | - protected function _validate_payment_request_data() |
|
| 1697 | - { |
|
| 1698 | - if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1699 | - return array(); |
|
| 1700 | - } |
|
| 1701 | - $payment_form = $this->_generate_payment_form_section(); |
|
| 1702 | - try { |
|
| 1703 | - if ($payment_form->was_submitted()) { |
|
| 1704 | - $payment_form->receive_form_submission(); |
|
| 1705 | - if (! $payment_form->is_valid()) { |
|
| 1706 | - $submission_error_messages = array(); |
|
| 1707 | - foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1708 | - if ($validation_error instanceof EE_Validation_Error) { |
|
| 1709 | - $submission_error_messages[] = sprintf( |
|
| 1710 | - _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1711 | - $validation_error->get_form_section()->html_label_text(), |
|
| 1712 | - $validation_error->getMessage() |
|
| 1713 | - ); |
|
| 1714 | - } |
|
| 1715 | - } |
|
| 1716 | - EE_Error::add_error( |
|
| 1717 | - implode('<br />', $submission_error_messages), |
|
| 1718 | - __FILE__, |
|
| 1719 | - __FUNCTION__, |
|
| 1720 | - __LINE__ |
|
| 1721 | - ); |
|
| 1722 | - return array(); |
|
| 1723 | - } |
|
| 1724 | - } |
|
| 1725 | - } catch (EE_Error $e) { |
|
| 1726 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1727 | - return array(); |
|
| 1728 | - } |
|
| 1729 | - |
|
| 1730 | - return $payment_form->valid_data(); |
|
| 1731 | - } |
|
| 1732 | - |
|
| 1733 | - |
|
| 1734 | - /** |
|
| 1735 | - * _generate_payment_form_section |
|
| 1736 | - * |
|
| 1737 | - * @return EE_Form_Section_Proper |
|
| 1738 | - * @throws EE_Error |
|
| 1739 | - */ |
|
| 1740 | - protected function _generate_payment_form_section() |
|
| 1741 | - { |
|
| 1742 | - return new EE_Form_Section_Proper( |
|
| 1743 | - array( |
|
| 1744 | - 'name' => 'txn_admin_payment', |
|
| 1745 | - 'subsections' => array( |
|
| 1746 | - 'PAY_ID' => new EE_Text_Input( |
|
| 1747 | - array( |
|
| 1748 | - 'default' => 0, |
|
| 1749 | - 'required' => false, |
|
| 1750 | - 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1751 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1752 | - ) |
|
| 1753 | - ), |
|
| 1754 | - 'TXN_ID' => new EE_Text_Input( |
|
| 1755 | - array( |
|
| 1756 | - 'default' => 0, |
|
| 1757 | - 'required' => true, |
|
| 1758 | - 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1759 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1760 | - ) |
|
| 1761 | - ), |
|
| 1762 | - 'type' => new EE_Text_Input( |
|
| 1763 | - array( |
|
| 1764 | - 'default' => 1, |
|
| 1765 | - 'required' => true, |
|
| 1766 | - 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1767 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1768 | - ) |
|
| 1769 | - ), |
|
| 1770 | - 'amount' => new EE_Text_Input( |
|
| 1771 | - array( |
|
| 1772 | - 'default' => 0, |
|
| 1773 | - 'required' => true, |
|
| 1774 | - 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1775 | - 'validation_strategies' => array(new EE_Float_Normalization()), |
|
| 1776 | - ) |
|
| 1777 | - ), |
|
| 1778 | - 'status' => new EE_Text_Input( |
|
| 1779 | - array( |
|
| 1780 | - 'default' => EEM_Payment::status_id_approved, |
|
| 1781 | - 'required' => true, |
|
| 1782 | - 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1783 | - ) |
|
| 1784 | - ), |
|
| 1785 | - 'PMD_ID' => new EE_Text_Input( |
|
| 1786 | - array( |
|
| 1787 | - 'default' => 2, |
|
| 1788 | - 'required' => true, |
|
| 1789 | - 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1790 | - 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1791 | - ) |
|
| 1792 | - ), |
|
| 1793 | - 'date' => new EE_Text_Input( |
|
| 1794 | - array( |
|
| 1795 | - 'default' => time(), |
|
| 1796 | - 'required' => true, |
|
| 1797 | - 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1798 | - ) |
|
| 1799 | - ), |
|
| 1800 | - 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1801 | - array( |
|
| 1802 | - 'default' => '', |
|
| 1803 | - 'required' => false, |
|
| 1804 | - 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1805 | - 'validation_strategies' => array( |
|
| 1806 | - new EE_Max_Length_Validation_Strategy( |
|
| 1807 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1808 | - 100 |
|
| 1809 | - ), |
|
| 1810 | - ), |
|
| 1811 | - ) |
|
| 1812 | - ), |
|
| 1813 | - 'po_number' => new EE_Text_Input( |
|
| 1814 | - array( |
|
| 1815 | - 'default' => '', |
|
| 1816 | - 'required' => false, |
|
| 1817 | - 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1818 | - 'validation_strategies' => array( |
|
| 1819 | - new EE_Max_Length_Validation_Strategy( |
|
| 1820 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1821 | - 100 |
|
| 1822 | - ), |
|
| 1823 | - ), |
|
| 1824 | - ) |
|
| 1825 | - ), |
|
| 1826 | - 'accounting' => new EE_Text_Input( |
|
| 1827 | - array( |
|
| 1828 | - 'default' => '', |
|
| 1829 | - 'required' => false, |
|
| 1830 | - 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1831 | - 'validation_strategies' => array( |
|
| 1832 | - new EE_Max_Length_Validation_Strategy( |
|
| 1833 | - esc_html__('Input too long', 'event_espresso'), |
|
| 1834 | - 100 |
|
| 1835 | - ), |
|
| 1836 | - ), |
|
| 1837 | - ) |
|
| 1838 | - ), |
|
| 1839 | - ), |
|
| 1840 | - ) |
|
| 1841 | - ); |
|
| 1842 | - } |
|
| 1843 | - |
|
| 1844 | - |
|
| 1845 | - /** |
|
| 1846 | - * _create_payment_from_request_data |
|
| 1847 | - * |
|
| 1848 | - * @param array $valid_data |
|
| 1849 | - * @return EE_Payment |
|
| 1850 | - * @throws EE_Error |
|
| 1851 | - * @throws InvalidArgumentException |
|
| 1852 | - * @throws InvalidDataTypeException |
|
| 1853 | - * @throws InvalidInterfaceException |
|
| 1854 | - * @throws ReflectionException |
|
| 1855 | - */ |
|
| 1856 | - protected function _create_payment_from_request_data($valid_data) |
|
| 1857 | - { |
|
| 1858 | - $PAY_ID = $valid_data['PAY_ID']; |
|
| 1859 | - // get payment amount |
|
| 1860 | - $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1861 | - // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1862 | - // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1863 | - $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1864 | - // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1865 | - $date = $valid_data['date'] |
|
| 1866 | - ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
| 1867 | - : date('Y-m-d g:i a', current_time('timestamp')); |
|
| 1868 | - $payment = EE_Payment::new_instance( |
|
| 1869 | - array( |
|
| 1870 | - 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1871 | - 'STS_ID' => $valid_data['status'], |
|
| 1872 | - 'PAY_timestamp' => $date, |
|
| 1873 | - 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1874 | - 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1875 | - 'PAY_amount' => $amount, |
|
| 1876 | - 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1877 | - 'PAY_po_number' => $valid_data['po_number'], |
|
| 1878 | - 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1879 | - 'PAY_details' => $valid_data, |
|
| 1880 | - 'PAY_ID' => $PAY_ID, |
|
| 1881 | - ), |
|
| 1882 | - '', |
|
| 1883 | - array('Y-m-d', 'g:i a') |
|
| 1884 | - ); |
|
| 1885 | - |
|
| 1886 | - if (! $payment->save()) { |
|
| 1887 | - EE_Error::add_error( |
|
| 1888 | - sprintf( |
|
| 1889 | - esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1890 | - $payment->ID() |
|
| 1891 | - ), |
|
| 1892 | - __FILE__, |
|
| 1893 | - __FUNCTION__, |
|
| 1894 | - __LINE__ |
|
| 1895 | - ); |
|
| 1896 | - } |
|
| 1897 | - |
|
| 1898 | - return $payment; |
|
| 1899 | - } |
|
| 1900 | - |
|
| 1901 | - |
|
| 1902 | - /** |
|
| 1903 | - * _process_transaction_payments |
|
| 1904 | - * |
|
| 1905 | - * @param \EE_Transaction $transaction |
|
| 1906 | - * @return void |
|
| 1907 | - * @throws EE_Error |
|
| 1908 | - * @throws InvalidArgumentException |
|
| 1909 | - * @throws ReflectionException |
|
| 1910 | - * @throws InvalidDataTypeException |
|
| 1911 | - * @throws InvalidInterfaceException |
|
| 1912 | - */ |
|
| 1913 | - protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1914 | - { |
|
| 1915 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1916 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1917 | - // update the transaction with this payment |
|
| 1918 | - if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1919 | - EE_Error::add_success( |
|
| 1920 | - esc_html__( |
|
| 1921 | - 'The payment has been processed successfully.', |
|
| 1922 | - 'event_espresso' |
|
| 1923 | - ), |
|
| 1924 | - __FILE__, |
|
| 1925 | - __FUNCTION__, |
|
| 1926 | - __LINE__ |
|
| 1927 | - ); |
|
| 1928 | - } else { |
|
| 1929 | - EE_Error::add_error( |
|
| 1930 | - esc_html__( |
|
| 1931 | - 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1932 | - 'event_espresso' |
|
| 1933 | - ), |
|
| 1934 | - __FILE__, |
|
| 1935 | - __FUNCTION__, |
|
| 1936 | - __LINE__ |
|
| 1937 | - ); |
|
| 1938 | - } |
|
| 1939 | - } |
|
| 1940 | - |
|
| 1941 | - |
|
| 1942 | - /** |
|
| 1943 | - * _get_REG_IDs_to_apply_payment_to |
|
| 1944 | - * returns a list of registration IDs that the payment will apply to |
|
| 1945 | - * |
|
| 1946 | - * @param \EE_Payment $payment |
|
| 1947 | - * @return array |
|
| 1948 | - * @throws EE_Error |
|
| 1949 | - * @throws InvalidArgumentException |
|
| 1950 | - * @throws InvalidDataTypeException |
|
| 1951 | - * @throws InvalidInterfaceException |
|
| 1952 | - * @throws ReflectionException |
|
| 1953 | - */ |
|
| 1954 | - protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1955 | - { |
|
| 1956 | - $REG_IDs = array(); |
|
| 1957 | - // grab array of IDs for specific registrations to apply changes to |
|
| 1958 | - if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1959 | - $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1960 | - } |
|
| 1961 | - // nothing specified ? then get all reg IDs |
|
| 1962 | - if (empty($REG_IDs)) { |
|
| 1963 | - $registrations = $payment->transaction()->registrations(); |
|
| 1964 | - $REG_IDs = ! empty($registrations) |
|
| 1965 | - ? array_keys($registrations) |
|
| 1966 | - : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1967 | - } |
|
| 1968 | - |
|
| 1969 | - // ensure that REG_IDs are integers and NOT strings |
|
| 1970 | - return array_map('intval', $REG_IDs); |
|
| 1971 | - } |
|
| 1972 | - |
|
| 1973 | - |
|
| 1974 | - /** |
|
| 1975 | - * @return array |
|
| 1976 | - */ |
|
| 1977 | - public function existing_reg_payment_REG_IDs() |
|
| 1978 | - { |
|
| 1979 | - return $this->_existing_reg_payment_REG_IDs; |
|
| 1980 | - } |
|
| 1981 | - |
|
| 1982 | - |
|
| 1983 | - /** |
|
| 1984 | - * @param array $existing_reg_payment_REG_IDs |
|
| 1985 | - */ |
|
| 1986 | - public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1987 | - { |
|
| 1988 | - $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1989 | - } |
|
| 1990 | - |
|
| 1991 | - |
|
| 1992 | - /** |
|
| 1993 | - * _get_existing_reg_payment_REG_IDs |
|
| 1994 | - * returns a list of registration IDs that the payment is currently related to |
|
| 1995 | - * as recorded in the database |
|
| 1996 | - * |
|
| 1997 | - * @param \EE_Payment $payment |
|
| 1998 | - * @return array |
|
| 1999 | - * @throws EE_Error |
|
| 2000 | - * @throws InvalidArgumentException |
|
| 2001 | - * @throws InvalidDataTypeException |
|
| 2002 | - * @throws InvalidInterfaceException |
|
| 2003 | - * @throws ReflectionException |
|
| 2004 | - */ |
|
| 2005 | - protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 2006 | - { |
|
| 2007 | - if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 2008 | - // let's get any existing reg payment records for this payment |
|
| 2009 | - $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 2010 | - // but we only want the REG IDs, so grab the array keys |
|
| 2011 | - $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
| 2012 | - ? array_keys($existing_reg_payment_REG_IDs) |
|
| 2013 | - : array(); |
|
| 2014 | - $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 2015 | - } |
|
| 2016 | - |
|
| 2017 | - return $this->existing_reg_payment_REG_IDs(); |
|
| 2018 | - } |
|
| 2019 | - |
|
| 2020 | - |
|
| 2021 | - /** |
|
| 2022 | - * _remove_existing_registration_payments |
|
| 2023 | - * this calculates the difference between existing relations |
|
| 2024 | - * to the supplied payment and the new list registration IDs, |
|
| 2025 | - * removes any related registrations that no longer apply, |
|
| 2026 | - * and then updates the registration paid fields |
|
| 2027 | - * |
|
| 2028 | - * @param \EE_Payment $payment |
|
| 2029 | - * @param int $PAY_ID |
|
| 2030 | - * @return bool; |
|
| 2031 | - * @throws EE_Error |
|
| 2032 | - * @throws InvalidArgumentException |
|
| 2033 | - * @throws ReflectionException |
|
| 2034 | - * @throws InvalidDataTypeException |
|
| 2035 | - * @throws InvalidInterfaceException |
|
| 2036 | - */ |
|
| 2037 | - protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 2038 | - { |
|
| 2039 | - // newly created payments will have nothing recorded for $PAY_ID |
|
| 2040 | - if (absint($PAY_ID) === 0) { |
|
| 2041 | - return false; |
|
| 2042 | - } |
|
| 2043 | - $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2044 | - if (empty($existing_reg_payment_REG_IDs)) { |
|
| 2045 | - return false; |
|
| 2046 | - } |
|
| 2047 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2048 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2049 | - |
|
| 2050 | - return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 2051 | - $payment, |
|
| 2052 | - array( |
|
| 2053 | - array( |
|
| 2054 | - 'PAY_ID' => $payment->ID(), |
|
| 2055 | - 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 2056 | - ), |
|
| 2057 | - ) |
|
| 2058 | - ); |
|
| 2059 | - } |
|
| 2060 | - |
|
| 2061 | - |
|
| 2062 | - /** |
|
| 2063 | - * _update_registration_payments |
|
| 2064 | - * this applies the payments to the selected registrations |
|
| 2065 | - * but only if they have not already been paid for |
|
| 2066 | - * |
|
| 2067 | - * @param EE_Transaction $transaction |
|
| 2068 | - * @param \EE_Payment $payment |
|
| 2069 | - * @param array $REG_IDs |
|
| 2070 | - * @return void |
|
| 2071 | - * @throws EE_Error |
|
| 2072 | - * @throws InvalidArgumentException |
|
| 2073 | - * @throws ReflectionException |
|
| 2074 | - * @throws RuntimeException |
|
| 2075 | - * @throws InvalidDataTypeException |
|
| 2076 | - * @throws InvalidInterfaceException |
|
| 2077 | - */ |
|
| 2078 | - protected function _update_registration_payments( |
|
| 2079 | - EE_Transaction $transaction, |
|
| 2080 | - EE_Payment $payment, |
|
| 2081 | - $REG_IDs = array() |
|
| 2082 | - ) { |
|
| 2083 | - // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 2084 | - // so let's do that using our set of REG_IDs from the form |
|
| 2085 | - $registration_query_where_params = array( |
|
| 2086 | - 'REG_ID' => array('IN', $REG_IDs), |
|
| 2087 | - ); |
|
| 2088 | - // but add in some conditions regarding payment, |
|
| 2089 | - // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 2090 | - // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 2091 | - if (! $payment->is_a_refund()) { |
|
| 2092 | - $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 2093 | - $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 2094 | - } |
|
| 2095 | - $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 2096 | - if (! empty($registrations)) { |
|
| 2097 | - /** @type EE_Payment_Processor $payment_processor */ |
|
| 2098 | - $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2099 | - $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 2100 | - } |
|
| 2101 | - } |
|
| 2102 | - |
|
| 2103 | - |
|
| 2104 | - /** |
|
| 2105 | - * _process_registration_status_change |
|
| 2106 | - * This processes requested registration status changes for all the registrations |
|
| 2107 | - * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 2108 | - * |
|
| 2109 | - * @param EE_Transaction $transaction |
|
| 2110 | - * @param array $REG_IDs |
|
| 2111 | - * @return bool |
|
| 2112 | - * @throws EE_Error |
|
| 2113 | - * @throws InvalidArgumentException |
|
| 2114 | - * @throws ReflectionException |
|
| 2115 | - * @throws InvalidDataTypeException |
|
| 2116 | - * @throws InvalidInterfaceException |
|
| 2117 | - */ |
|
| 2118 | - protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 2119 | - { |
|
| 2120 | - // first if there is no change in status then we get out. |
|
| 2121 | - if (! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 2122 | - || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
| 2123 | - ) { |
|
| 2124 | - // no error message, no change requested, just nothing to do man. |
|
| 2125 | - return false; |
|
| 2126 | - } |
|
| 2127 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 2128 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 2129 | - |
|
| 2130 | - // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 2131 | - return $transaction_processor->manually_update_registration_statuses( |
|
| 2132 | - $transaction, |
|
| 2133 | - sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 2134 | - array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 2135 | - ); |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - |
|
| 2139 | - /** |
|
| 2140 | - * _build_payment_json_response |
|
| 2141 | - * |
|
| 2142 | - * @access public |
|
| 2143 | - * @param \EE_Payment $payment |
|
| 2144 | - * @param array $REG_IDs |
|
| 2145 | - * @param bool | null $delete_txn_reg_status_change |
|
| 2146 | - * @return array |
|
| 2147 | - * @throws EE_Error |
|
| 2148 | - * @throws InvalidArgumentException |
|
| 2149 | - * @throws InvalidDataTypeException |
|
| 2150 | - * @throws InvalidInterfaceException |
|
| 2151 | - * @throws ReflectionException |
|
| 2152 | - */ |
|
| 2153 | - protected function _build_payment_json_response( |
|
| 2154 | - EE_Payment $payment, |
|
| 2155 | - $REG_IDs = array(), |
|
| 2156 | - $delete_txn_reg_status_change = null |
|
| 2157 | - ) { |
|
| 2158 | - // was the payment deleted ? |
|
| 2159 | - if (is_bool($delete_txn_reg_status_change)) { |
|
| 2160 | - return array( |
|
| 2161 | - 'PAY_ID' => $payment->ID(), |
|
| 2162 | - 'amount' => $payment->amount(), |
|
| 2163 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 2164 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2165 | - 'pay_status' => $payment->STS_ID(), |
|
| 2166 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2167 | - 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 2168 | - ); |
|
| 2169 | - } else { |
|
| 2170 | - $this->_get_payment_status_array(); |
|
| 2171 | - |
|
| 2172 | - return array( |
|
| 2173 | - 'amount' => $payment->amount(), |
|
| 2174 | - 'total_paid' => $payment->transaction()->paid(), |
|
| 2175 | - 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2176 | - 'pay_status' => $payment->STS_ID(), |
|
| 2177 | - 'PAY_ID' => $payment->ID(), |
|
| 2178 | - 'STS_ID' => $payment->STS_ID(), |
|
| 2179 | - 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
| 2180 | - 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 2181 | - 'method' => strtoupper($payment->source()), |
|
| 2182 | - 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 2183 | - 'gateway' => $payment->payment_method() |
|
| 2184 | - ? $payment->payment_method()->admin_name() |
|
| 2185 | - : esc_html__('Unknown', 'event_espresso'), |
|
| 2186 | - 'gateway_response' => $payment->gateway_response(), |
|
| 2187 | - 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 2188 | - 'po_number' => $payment->po_number(), |
|
| 2189 | - 'extra_accntng' => $payment->extra_accntng(), |
|
| 2190 | - 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2191 | - ); |
|
| 2192 | - } |
|
| 2193 | - } |
|
| 2194 | - |
|
| 2195 | - |
|
| 2196 | - /** |
|
| 2197 | - * delete_payment |
|
| 2198 | - * delete a payment or refund made towards a transaction |
|
| 2199 | - * |
|
| 2200 | - * @access public |
|
| 2201 | - * @return void |
|
| 2202 | - * @throws EE_Error |
|
| 2203 | - * @throws InvalidArgumentException |
|
| 2204 | - * @throws ReflectionException |
|
| 2205 | - * @throws InvalidDataTypeException |
|
| 2206 | - * @throws InvalidInterfaceException |
|
| 2207 | - */ |
|
| 2208 | - public function delete_payment() |
|
| 2209 | - { |
|
| 2210 | - $json_response_data = array('return_data' => false); |
|
| 2211 | - $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2212 | - ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2213 | - : 0; |
|
| 2214 | - $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
| 2215 | - 'ee_delete_payments', |
|
| 2216 | - 'delete_payment_from_registration_details' |
|
| 2217 | - ); |
|
| 2218 | - if ($PAY_ID && $can_delete) { |
|
| 2219 | - $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
| 2220 | - ? $this->_req_data['delete_txn_reg_status_change'] |
|
| 2221 | - : false; |
|
| 2222 | - $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 2223 | - if ($payment instanceof EE_Payment) { |
|
| 2224 | - $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2225 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2226 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2227 | - if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 2228 | - $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
| 2229 | - $payment, |
|
| 2230 | - $REG_IDs, |
|
| 2231 | - $delete_txn_reg_status_change |
|
| 2232 | - ); |
|
| 2233 | - if ($delete_txn_reg_status_change) { |
|
| 2234 | - $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2235 | - // MAKE sure we also add the delete_txn_req_status_change to the |
|
| 2236 | - // $_REQUEST global because that's how messages will be looking for it. |
|
| 2237 | - $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2238 | - $this->_maybe_send_notifications(); |
|
| 2239 | - $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 2240 | - } |
|
| 2241 | - } |
|
| 2242 | - } else { |
|
| 2243 | - EE_Error::add_error( |
|
| 2244 | - esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 2245 | - __FILE__, |
|
| 2246 | - __FUNCTION__, |
|
| 2247 | - __LINE__ |
|
| 2248 | - ); |
|
| 2249 | - } |
|
| 2250 | - } elseif ($can_delete) { |
|
| 2251 | - EE_Error::add_error( |
|
| 2252 | - esc_html__( |
|
| 2253 | - 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 2254 | - 'event_espresso' |
|
| 2255 | - ), |
|
| 2256 | - __FILE__, |
|
| 2257 | - __FUNCTION__, |
|
| 2258 | - __LINE__ |
|
| 2259 | - ); |
|
| 2260 | - } else { |
|
| 2261 | - EE_Error::add_error( |
|
| 2262 | - esc_html__( |
|
| 2263 | - 'You do not have access to delete a payment.', |
|
| 2264 | - 'event_espresso' |
|
| 2265 | - ), |
|
| 2266 | - __FILE__, |
|
| 2267 | - __FUNCTION__, |
|
| 2268 | - __LINE__ |
|
| 2269 | - ); |
|
| 2270 | - } |
|
| 2271 | - $notices = EE_Error::get_notices(false, false, false); |
|
| 2272 | - $this->_template_args = array( |
|
| 2273 | - 'data' => $json_response_data, |
|
| 2274 | - 'success' => $notices['success'], |
|
| 2275 | - 'error' => $notices['errors'], |
|
| 2276 | - 'attention' => $notices['attention'], |
|
| 2277 | - ); |
|
| 2278 | - $this->_return_json(); |
|
| 2279 | - } |
|
| 2280 | - |
|
| 2281 | - |
|
| 2282 | - /** |
|
| 2283 | - * _registration_payment_data_array |
|
| 2284 | - * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 2285 | - * |
|
| 2286 | - * @access protected |
|
| 2287 | - * @param array $REG_IDs |
|
| 2288 | - * @return array |
|
| 2289 | - * @throws EE_Error |
|
| 2290 | - * @throws InvalidArgumentException |
|
| 2291 | - * @throws InvalidDataTypeException |
|
| 2292 | - * @throws InvalidInterfaceException |
|
| 2293 | - * @throws ReflectionException |
|
| 2294 | - */ |
|
| 2295 | - protected function _registration_payment_data_array($REG_IDs) |
|
| 2296 | - { |
|
| 2297 | - $registration_payment_data = array(); |
|
| 2298 | - // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 2299 | - if (! empty($REG_IDs)) { |
|
| 2300 | - $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 2301 | - foreach ($registrations as $registration) { |
|
| 2302 | - if ($registration instanceof EE_Registration) { |
|
| 2303 | - $registration_payment_data[ $registration->ID() ] = array( |
|
| 2304 | - 'paid' => $registration->pretty_paid(), |
|
| 2305 | - 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 2306 | - ); |
|
| 2307 | - } |
|
| 2308 | - } |
|
| 2309 | - } |
|
| 2310 | - |
|
| 2311 | - return $registration_payment_data; |
|
| 2312 | - } |
|
| 2313 | - |
|
| 2314 | - |
|
| 2315 | - /** |
|
| 2316 | - * _maybe_send_notifications |
|
| 2317 | - * determines whether or not the admin has indicated that notifications should be sent. |
|
| 2318 | - * If so, will toggle a filter switch for delivering registration notices. |
|
| 2319 | - * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 2320 | - * |
|
| 2321 | - * @access protected |
|
| 2322 | - * @param \EE_Payment | null $payment |
|
| 2323 | - */ |
|
| 2324 | - protected function _maybe_send_notifications($payment = null) |
|
| 2325 | - { |
|
| 2326 | - switch ($payment instanceof EE_Payment) { |
|
| 2327 | - // payment notifications |
|
| 2328 | - case true: |
|
| 2329 | - if (isset($this->_req_data['txn_payments']['send_notifications']) |
|
| 2330 | - && filter_var( |
|
| 2331 | - $this->_req_data['txn_payments']['send_notifications'], |
|
| 2332 | - FILTER_VALIDATE_BOOLEAN |
|
| 2333 | - ) |
|
| 2334 | - ) { |
|
| 2335 | - $this->_process_payment_notification($payment); |
|
| 2336 | - } |
|
| 2337 | - break; |
|
| 2338 | - // registration notifications |
|
| 2339 | - case false: |
|
| 2340 | - if (isset($this->_req_data['txn_reg_status_change']['send_notifications']) |
|
| 2341 | - && filter_var( |
|
| 2342 | - $this->_req_data['txn_reg_status_change']['send_notifications'], |
|
| 2343 | - FILTER_VALIDATE_BOOLEAN |
|
| 2344 | - ) |
|
| 2345 | - ) { |
|
| 2346 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 2347 | - } |
|
| 2348 | - break; |
|
| 2349 | - } |
|
| 2350 | - } |
|
| 2351 | - |
|
| 2352 | - |
|
| 2353 | - /** |
|
| 2354 | - * _send_payment_reminder |
|
| 2355 | - * generates HTML for the View Transaction Details Admin page |
|
| 2356 | - * |
|
| 2357 | - * @access protected |
|
| 2358 | - * @return void |
|
| 2359 | - * @throws EE_Error |
|
| 2360 | - * @throws InvalidArgumentException |
|
| 2361 | - * @throws InvalidDataTypeException |
|
| 2362 | - * @throws InvalidInterfaceException |
|
| 2363 | - */ |
|
| 2364 | - protected function _send_payment_reminder() |
|
| 2365 | - { |
|
| 2366 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2367 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2368 | - $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 2369 | - 'action' => $this->_req_data['redirect_to'], |
|
| 2370 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2371 | - ) : array(); |
|
| 2372 | - do_action( |
|
| 2373 | - 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 2374 | - $transaction |
|
| 2375 | - ); |
|
| 2376 | - $this->_redirect_after_action( |
|
| 2377 | - false, |
|
| 2378 | - esc_html__('payment reminder', 'event_espresso'), |
|
| 2379 | - esc_html__('sent', 'event_espresso'), |
|
| 2380 | - $query_args, |
|
| 2381 | - true |
|
| 2382 | - ); |
|
| 2383 | - } |
|
| 2384 | - |
|
| 2385 | - |
|
| 2386 | - /** |
|
| 2387 | - * get_transactions |
|
| 2388 | - * get transactions for given parameters (used by list table) |
|
| 2389 | - * |
|
| 2390 | - * @param int $perpage how many transactions displayed per page |
|
| 2391 | - * @param boolean $count return the count or objects |
|
| 2392 | - * @param string $view |
|
| 2393 | - * @return mixed int = count || array of transaction objects |
|
| 2394 | - * @throws EE_Error |
|
| 2395 | - * @throws InvalidArgumentException |
|
| 2396 | - * @throws InvalidDataTypeException |
|
| 2397 | - * @throws InvalidInterfaceException |
|
| 2398 | - */ |
|
| 2399 | - public function get_transactions($perpage, $count = false, $view = '') |
|
| 2400 | - { |
|
| 2401 | - |
|
| 2402 | - $TXN = EEM_Transaction::instance(); |
|
| 2403 | - |
|
| 2404 | - $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 2405 | - ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 2406 | - : date( |
|
| 2407 | - 'm/d/Y', |
|
| 2408 | - strtotime('-10 year') |
|
| 2409 | - ); |
|
| 2410 | - $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2411 | - ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 2412 | - : date('m/d/Y'); |
|
| 2413 | - |
|
| 2414 | - // make sure our timestamps start and end right at the boundaries for each day |
|
| 2415 | - $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2416 | - $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2417 | - |
|
| 2418 | - |
|
| 2419 | - // convert to timestamps |
|
| 2420 | - $start_date = strtotime($start_date); |
|
| 2421 | - $end_date = strtotime($end_date); |
|
| 2422 | - |
|
| 2423 | - // makes sure start date is the lowest value and vice versa |
|
| 2424 | - $start_date = min($start_date, $end_date); |
|
| 2425 | - $end_date = max($start_date, $end_date); |
|
| 2426 | - |
|
| 2427 | - // convert to correct format for query |
|
| 2428 | - $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2429 | - 'TXN_timestamp', |
|
| 2430 | - date('Y-m-d H:i:s', $start_date), |
|
| 2431 | - 'Y-m-d H:i:s' |
|
| 2432 | - ); |
|
| 2433 | - $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2434 | - 'TXN_timestamp', |
|
| 2435 | - date('Y-m-d H:i:s', $end_date), |
|
| 2436 | - 'Y-m-d H:i:s' |
|
| 2437 | - ); |
|
| 2438 | - |
|
| 2439 | - |
|
| 2440 | - // set orderby |
|
| 2441 | - $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2442 | - |
|
| 2443 | - switch ($this->_req_data['orderby']) { |
|
| 2444 | - case 'TXN_ID': |
|
| 2445 | - $orderby = 'TXN_ID'; |
|
| 2446 | - break; |
|
| 2447 | - case 'ATT_fname': |
|
| 2448 | - $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 2449 | - break; |
|
| 2450 | - case 'event_name': |
|
| 2451 | - $orderby = 'Registration.Event.EVT_name'; |
|
| 2452 | - break; |
|
| 2453 | - default: // 'TXN_timestamp' |
|
| 2454 | - $orderby = 'TXN_timestamp'; |
|
| 2455 | - } |
|
| 2456 | - |
|
| 2457 | - $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2458 | - $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 2459 | - $per_page = ! empty($perpage) ? $perpage : 10; |
|
| 2460 | - $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 2461 | - |
|
| 2462 | - $offset = ($current_page - 1) * $per_page; |
|
| 2463 | - $limit = array($offset, $per_page); |
|
| 2464 | - |
|
| 2465 | - $_where = array( |
|
| 2466 | - 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 2467 | - 'Registration.REG_count' => 1, |
|
| 2468 | - ); |
|
| 2469 | - |
|
| 2470 | - if (isset($this->_req_data['EVT_ID'])) { |
|
| 2471 | - $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2472 | - } |
|
| 2473 | - |
|
| 2474 | - if (isset($this->_req_data['s'])) { |
|
| 2475 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2476 | - $_where['OR'] = array( |
|
| 2477 | - 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 2478 | - 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 2479 | - 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 2480 | - 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 2481 | - 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 2482 | - 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 2483 | - 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 2484 | - 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 2485 | - 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 2486 | - 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 2487 | - 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 2488 | - 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 2489 | - 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 2490 | - 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 2491 | - 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 2492 | - 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 2493 | - 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 2494 | - 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 2495 | - 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 2496 | - 'TXN_session_data' => array('LIKE', $search_string), |
|
| 2497 | - 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 2498 | - ); |
|
| 2499 | - } |
|
| 2500 | - |
|
| 2501 | - // failed transactions |
|
| 2502 | - $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2503 | - || ($count && $view === 'failed'); |
|
| 2504 | - $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2505 | - || ($count && $view === 'abandoned'); |
|
| 2506 | - $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count) |
|
| 2507 | - || ($count && $view === 'incomplete'); |
|
| 2508 | - |
|
| 2509 | - if ($failed) { |
|
| 2510 | - $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 2511 | - } elseif ($abandoned) { |
|
| 2512 | - $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 2513 | - } elseif ($incomplete) { |
|
| 2514 | - $_where['STS_ID'] = EEM_Transaction::incomplete_status_code; |
|
| 2515 | - } else { |
|
| 2516 | - $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 2517 | - $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 2518 | - } |
|
| 2519 | - |
|
| 2520 | - $query_params = apply_filters( |
|
| 2521 | - 'FHEE__Transactions_Admin_Page___get_transactions_query_params', |
|
| 2522 | - array( |
|
| 2523 | - $_where, |
|
| 2524 | - 'order_by' => array($orderby => $sort), |
|
| 2525 | - 'limit' => $limit, |
|
| 2526 | - 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
| 2527 | - ), |
|
| 2528 | - $this->_req_data, |
|
| 2529 | - $view, |
|
| 2530 | - $count |
|
| 2531 | - ); |
|
| 2532 | - |
|
| 2533 | - $transactions = $count |
|
| 2534 | - ? $TXN->count(array($query_params[0]), 'TXN_ID', true) |
|
| 2535 | - : $TXN->get_all($query_params); |
|
| 2536 | - |
|
| 2537 | - return $transactions; |
|
| 2538 | - } |
|
| 2539 | - |
|
| 2540 | - |
|
| 2541 | - /** |
|
| 2542 | - * @since 4.9.79.p |
|
| 2543 | - * @throws EE_Error |
|
| 2544 | - * @throws InvalidArgumentException |
|
| 2545 | - * @throws InvalidDataTypeException |
|
| 2546 | - * @throws InvalidInterfaceException |
|
| 2547 | - * @throws ReflectionException |
|
| 2548 | - * @throws RuntimeException |
|
| 2549 | - */ |
|
| 2550 | - public function recalculateLineItems() |
|
| 2551 | - { |
|
| 2552 | - $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2553 | - /** @var EE_Transaction $transaction */ |
|
| 2554 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2555 | - $total_line_item = $transaction->total_line_item(false); |
|
| 2556 | - $success = false; |
|
| 2557 | - if ($total_line_item instanceof EE_Line_Item) { |
|
| 2558 | - EEH_Line_Item::resetIsTaxableForTickets($total_line_item); |
|
| 2559 | - $success = EEH_Line_Item::apply_taxes($total_line_item, true); |
|
| 2560 | - } |
|
| 2561 | - $this->_redirect_after_action( |
|
| 2562 | - (bool) $success, |
|
| 2563 | - esc_html__('Transaction taxes and totals', 'event_espresso'), |
|
| 2564 | - esc_html__('recalculated', 'event_espresso'), |
|
| 2565 | - isset($this->_req_data['redirect_to']) |
|
| 2566 | - ? array( |
|
| 2567 | - 'action' => $this->_req_data['redirect_to'], |
|
| 2568 | - 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2569 | - ) |
|
| 2570 | - : array(), |
|
| 2571 | - true |
|
| 2572 | - ); |
|
| 2573 | - } |
|
| 16 | + /** |
|
| 17 | + * @var EE_Transaction |
|
| 18 | + */ |
|
| 19 | + private $_transaction; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @var EE_Session |
|
| 23 | + */ |
|
| 24 | + private $_session; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var array $_txn_status |
|
| 28 | + */ |
|
| 29 | + private static $_txn_status; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var array $_pay_status |
|
| 33 | + */ |
|
| 34 | + private static $_pay_status; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var array $_existing_reg_payment_REG_IDs |
|
| 38 | + */ |
|
| 39 | + protected $_existing_reg_payment_REG_IDs; |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * _init_page_props |
|
| 44 | + * |
|
| 45 | + * @return void |
|
| 46 | + */ |
|
| 47 | + protected function _init_page_props() |
|
| 48 | + { |
|
| 49 | + $this->page_slug = TXN_PG_SLUG; |
|
| 50 | + $this->page_label = esc_html__('Transactions', 'event_espresso'); |
|
| 51 | + $this->_admin_base_url = TXN_ADMIN_URL; |
|
| 52 | + $this->_admin_base_path = TXN_ADMIN; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * _ajax_hooks |
|
| 58 | + * |
|
| 59 | + * @return void |
|
| 60 | + */ |
|
| 61 | + protected function _ajax_hooks() |
|
| 62 | + { |
|
| 63 | + add_action('wp_ajax_espresso_apply_payment', array($this, 'apply_payments_or_refunds')); |
|
| 64 | + add_action('wp_ajax_espresso_apply_refund', array($this, 'apply_payments_or_refunds')); |
|
| 65 | + add_action('wp_ajax_espresso_delete_payment', array($this, 'delete_payment')); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * _define_page_props |
|
| 71 | + * |
|
| 72 | + * @return void |
|
| 73 | + */ |
|
| 74 | + protected function _define_page_props() |
|
| 75 | + { |
|
| 76 | + $this->_admin_page_title = $this->page_label; |
|
| 77 | + $this->_labels = array( |
|
| 78 | + 'buttons' => array( |
|
| 79 | + 'add' => esc_html__('Add New Transaction', 'event_espresso'), |
|
| 80 | + 'edit' => esc_html__('Edit Transaction', 'event_espresso'), |
|
| 81 | + 'delete' => esc_html__('Delete Transaction', 'event_espresso'), |
|
| 82 | + ), |
|
| 83 | + ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * grab url requests and route them |
|
| 89 | + * |
|
| 90 | + * @access private |
|
| 91 | + * @return void |
|
| 92 | + * @throws EE_Error |
|
| 93 | + * @throws InvalidArgumentException |
|
| 94 | + * @throws InvalidDataTypeException |
|
| 95 | + * @throws InvalidInterfaceException |
|
| 96 | + */ |
|
| 97 | + public function _set_page_routes() |
|
| 98 | + { |
|
| 99 | + |
|
| 100 | + $this->_set_transaction_status_array(); |
|
| 101 | + |
|
| 102 | + $txn_id = ! empty($this->_req_data['TXN_ID']) |
|
| 103 | + && ! is_array($this->_req_data['TXN_ID']) |
|
| 104 | + ? $this->_req_data['TXN_ID'] |
|
| 105 | + : 0; |
|
| 106 | + |
|
| 107 | + $this->_page_routes = array( |
|
| 108 | + |
|
| 109 | + 'default' => array( |
|
| 110 | + 'func' => '_transactions_overview_list_table', |
|
| 111 | + 'capability' => 'ee_read_transactions', |
|
| 112 | + ), |
|
| 113 | + |
|
| 114 | + 'view_transaction' => array( |
|
| 115 | + 'func' => '_transaction_details', |
|
| 116 | + 'capability' => 'ee_read_transaction', |
|
| 117 | + 'obj_id' => $txn_id, |
|
| 118 | + ), |
|
| 119 | + |
|
| 120 | + 'send_payment_reminder' => array( |
|
| 121 | + 'func' => '_send_payment_reminder', |
|
| 122 | + 'noheader' => true, |
|
| 123 | + 'capability' => 'ee_send_message', |
|
| 124 | + ), |
|
| 125 | + |
|
| 126 | + 'espresso_apply_payment' => array( |
|
| 127 | + 'func' => 'apply_payments_or_refunds', |
|
| 128 | + 'noheader' => true, |
|
| 129 | + 'capability' => 'ee_edit_payments', |
|
| 130 | + ), |
|
| 131 | + |
|
| 132 | + 'espresso_apply_refund' => array( |
|
| 133 | + 'func' => 'apply_payments_or_refunds', |
|
| 134 | + 'noheader' => true, |
|
| 135 | + 'capability' => 'ee_edit_payments', |
|
| 136 | + ), |
|
| 137 | + |
|
| 138 | + 'espresso_delete_payment' => array( |
|
| 139 | + 'func' => 'delete_payment', |
|
| 140 | + 'noheader' => true, |
|
| 141 | + 'capability' => 'ee_delete_payments', |
|
| 142 | + ), |
|
| 143 | + |
|
| 144 | + 'espresso_recalculate_line_items' => array( |
|
| 145 | + 'func' => 'recalculateLineItems', |
|
| 146 | + 'noheader' => true, |
|
| 147 | + 'capability' => 'ee_edit_payments', |
|
| 148 | + ), |
|
| 149 | + |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + protected function _set_page_config() |
|
| 155 | + { |
|
| 156 | + $this->_page_config = array( |
|
| 157 | + 'default' => array( |
|
| 158 | + 'nav' => array( |
|
| 159 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
| 160 | + 'order' => 10, |
|
| 161 | + ), |
|
| 162 | + 'list_table' => 'EE_Admin_Transactions_List_Table', |
|
| 163 | + 'help_tabs' => array( |
|
| 164 | + 'transactions_overview_help_tab' => array( |
|
| 165 | + 'title' => esc_html__('Transactions Overview', 'event_espresso'), |
|
| 166 | + 'filename' => 'transactions_overview', |
|
| 167 | + ), |
|
| 168 | + 'transactions_overview_table_column_headings_help_tab' => array( |
|
| 169 | + 'title' => esc_html__('Transactions Table Column Headings', 'event_espresso'), |
|
| 170 | + 'filename' => 'transactions_overview_table_column_headings', |
|
| 171 | + ), |
|
| 172 | + 'transactions_overview_views_filters_help_tab' => array( |
|
| 173 | + 'title' => esc_html__('Transaction Views & Filters & Search', 'event_espresso'), |
|
| 174 | + 'filename' => 'transactions_overview_views_filters_search', |
|
| 175 | + ), |
|
| 176 | + ), |
|
| 177 | + 'help_tour' => array('Transactions_Overview_Help_Tour'), |
|
| 178 | + /** |
|
| 179 | + * commented out because currently we are not displaying tips for transaction list table status but this |
|
| 180 | + * may change in a later iteration so want to keep the code for then. |
|
| 181 | + */ |
|
| 182 | + // 'qtips' => array( 'Transactions_List_Table_Tips' ), |
|
| 183 | + 'require_nonce' => false, |
|
| 184 | + ), |
|
| 185 | + 'view_transaction' => array( |
|
| 186 | + 'nav' => array( |
|
| 187 | + 'label' => esc_html__('View Transaction', 'event_espresso'), |
|
| 188 | + 'order' => 5, |
|
| 189 | + 'url' => isset($this->_req_data['TXN_ID']) |
|
| 190 | + ? add_query_arg(array('TXN_ID' => $this->_req_data['TXN_ID']), $this->_current_page_view_url) |
|
| 191 | + : $this->_admin_base_url, |
|
| 192 | + 'persistent' => false, |
|
| 193 | + ), |
|
| 194 | + 'help_tabs' => array( |
|
| 195 | + 'transactions_view_transaction_help_tab' => array( |
|
| 196 | + 'title' => esc_html__('View Transaction', 'event_espresso'), |
|
| 197 | + 'filename' => 'transactions_view_transaction', |
|
| 198 | + ), |
|
| 199 | + 'transactions_view_transaction_transaction_details_table_help_tab' => array( |
|
| 200 | + 'title' => esc_html__('Transaction Details Table', 'event_espresso'), |
|
| 201 | + 'filename' => 'transactions_view_transaction_transaction_details_table', |
|
| 202 | + ), |
|
| 203 | + 'transactions_view_transaction_attendees_registered_help_tab' => array( |
|
| 204 | + 'title' => esc_html__('Attendees Registered', 'event_espresso'), |
|
| 205 | + 'filename' => 'transactions_view_transaction_attendees_registered', |
|
| 206 | + ), |
|
| 207 | + 'transactions_view_transaction_views_primary_registrant_billing_information_help_tab' => array( |
|
| 208 | + 'title' => esc_html__('Primary Registrant & Billing Information', 'event_espresso'), |
|
| 209 | + 'filename' => 'transactions_view_transaction_primary_registrant_billing_information', |
|
| 210 | + ), |
|
| 211 | + ), |
|
| 212 | + 'qtips' => array('Transaction_Details_Tips'), |
|
| 213 | + 'help_tour' => array('Transaction_Details_Help_Tour'), |
|
| 214 | + 'metaboxes' => array('_transaction_details_metaboxes'), |
|
| 215 | + |
|
| 216 | + 'require_nonce' => false, |
|
| 217 | + ), |
|
| 218 | + ); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * The below methods aren't used by this class currently |
|
| 224 | + */ |
|
| 225 | + protected function _add_screen_options() |
|
| 226 | + { |
|
| 227 | + // noop |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + protected function _add_feature_pointers() |
|
| 232 | + { |
|
| 233 | + // noop |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + public function admin_init() |
|
| 238 | + { |
|
| 239 | + // IF a registration was JUST added via the admin... |
|
| 240 | + if (isset( |
|
| 241 | + $this->_req_data['redirect_from'], |
|
| 242 | + $this->_req_data['EVT_ID'], |
|
| 243 | + $this->_req_data['event_name'] |
|
| 244 | + )) { |
|
| 245 | + // then set a cookie so that we can block any attempts to use |
|
| 246 | + // the back button as a way to enter another registration. |
|
| 247 | + setcookie( |
|
| 248 | + 'ee_registration_added', |
|
| 249 | + $this->_req_data['EVT_ID'], |
|
| 250 | + time() + WEEK_IN_SECONDS, |
|
| 251 | + '/' |
|
| 252 | + ); |
|
| 253 | + // and update the global |
|
| 254 | + $_COOKIE['ee_registration_added'] = $this->_req_data['EVT_ID']; |
|
| 255 | + } |
|
| 256 | + EE_Registry::$i18n_js_strings['invalid_server_response'] = esc_html__( |
|
| 257 | + '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.', |
|
| 258 | + 'event_espresso' |
|
| 259 | + ); |
|
| 260 | + EE_Registry::$i18n_js_strings['error_occurred'] = esc_html__( |
|
| 261 | + 'An error occurred! Please refresh the page and try again.', |
|
| 262 | + 'event_espresso' |
|
| 263 | + ); |
|
| 264 | + EE_Registry::$i18n_js_strings['txn_status_array'] = self::$_txn_status; |
|
| 265 | + EE_Registry::$i18n_js_strings['pay_status_array'] = self::$_pay_status; |
|
| 266 | + EE_Registry::$i18n_js_strings['payments_total'] = esc_html__('Payments Total', 'event_espresso'); |
|
| 267 | + EE_Registry::$i18n_js_strings['transaction_overpaid'] = esc_html__( |
|
| 268 | + 'This transaction has been overpaid ! Payments Total', |
|
| 269 | + 'event_espresso' |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + |
|
| 274 | + public function admin_notices() |
|
| 275 | + { |
|
| 276 | + // noop |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + |
|
| 280 | + public function admin_footer_scripts() |
|
| 281 | + { |
|
| 282 | + // noop |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * _set_transaction_status_array |
|
| 288 | + * sets list of transaction statuses |
|
| 289 | + * |
|
| 290 | + * @access private |
|
| 291 | + * @return void |
|
| 292 | + * @throws EE_Error |
|
| 293 | + * @throws InvalidArgumentException |
|
| 294 | + * @throws InvalidDataTypeException |
|
| 295 | + * @throws InvalidInterfaceException |
|
| 296 | + */ |
|
| 297 | + private function _set_transaction_status_array() |
|
| 298 | + { |
|
| 299 | + self::$_txn_status = EEM_Transaction::instance()->status_array(true); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * get_transaction_status_array |
|
| 305 | + * return the transaction status array for wp_list_table |
|
| 306 | + * |
|
| 307 | + * @access public |
|
| 308 | + * @return array |
|
| 309 | + */ |
|
| 310 | + public function get_transaction_status_array() |
|
| 311 | + { |
|
| 312 | + return self::$_txn_status; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + |
|
| 316 | + /** |
|
| 317 | + * get list of payment statuses |
|
| 318 | + * |
|
| 319 | + * @access private |
|
| 320 | + * @return void |
|
| 321 | + * @throws EE_Error |
|
| 322 | + * @throws InvalidArgumentException |
|
| 323 | + * @throws InvalidDataTypeException |
|
| 324 | + * @throws InvalidInterfaceException |
|
| 325 | + */ |
|
| 326 | + private function _get_payment_status_array() |
|
| 327 | + { |
|
| 328 | + self::$_pay_status = EEM_Payment::instance()->status_array(true); |
|
| 329 | + $this->_template_args['payment_status'] = self::$_pay_status; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + /** |
|
| 334 | + * _add_screen_options_default |
|
| 335 | + * |
|
| 336 | + * @access protected |
|
| 337 | + * @return void |
|
| 338 | + * @throws InvalidArgumentException |
|
| 339 | + * @throws InvalidDataTypeException |
|
| 340 | + * @throws InvalidInterfaceException |
|
| 341 | + */ |
|
| 342 | + protected function _add_screen_options_default() |
|
| 343 | + { |
|
| 344 | + $this->_per_page_screen_option(); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * load_scripts_styles |
|
| 350 | + * |
|
| 351 | + * @access public |
|
| 352 | + * @return void |
|
| 353 | + */ |
|
| 354 | + public function load_scripts_styles() |
|
| 355 | + { |
|
| 356 | + // enqueue style |
|
| 357 | + wp_register_style( |
|
| 358 | + 'espresso_txn', |
|
| 359 | + TXN_ASSETS_URL . 'espresso_transactions_admin.css', |
|
| 360 | + array(), |
|
| 361 | + EVENT_ESPRESSO_VERSION |
|
| 362 | + ); |
|
| 363 | + wp_enqueue_style('espresso_txn'); |
|
| 364 | + // scripts |
|
| 365 | + wp_register_script( |
|
| 366 | + 'espresso_txn', |
|
| 367 | + TXN_ASSETS_URL . 'espresso_transactions_admin.js', |
|
| 368 | + array( |
|
| 369 | + 'ee_admin_js', |
|
| 370 | + 'ee-datepicker', |
|
| 371 | + 'jquery-ui-datepicker', |
|
| 372 | + 'jquery-ui-draggable', |
|
| 373 | + 'ee-dialog', |
|
| 374 | + 'ee-accounting', |
|
| 375 | + 'ee-serialize-full-array', |
|
| 376 | + ), |
|
| 377 | + EVENT_ESPRESSO_VERSION, |
|
| 378 | + true |
|
| 379 | + ); |
|
| 380 | + wp_enqueue_script('espresso_txn'); |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * load_scripts_styles_view_transaction |
|
| 386 | + * |
|
| 387 | + * @access public |
|
| 388 | + * @return void |
|
| 389 | + */ |
|
| 390 | + public function load_scripts_styles_view_transaction() |
|
| 391 | + { |
|
| 392 | + // styles |
|
| 393 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * load_scripts_styles_default |
|
| 399 | + * |
|
| 400 | + * @access public |
|
| 401 | + * @return void |
|
| 402 | + */ |
|
| 403 | + public function load_scripts_styles_default() |
|
| 404 | + { |
|
| 405 | + // styles |
|
| 406 | + wp_enqueue_style('espresso-ui-theme'); |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * _set_list_table_views_default |
|
| 412 | + * |
|
| 413 | + * @access protected |
|
| 414 | + * @return void |
|
| 415 | + */ |
|
| 416 | + protected function _set_list_table_views_default() |
|
| 417 | + { |
|
| 418 | + $this->_views = array( |
|
| 419 | + 'all' => array( |
|
| 420 | + 'slug' => 'all', |
|
| 421 | + 'label' => esc_html__('View All Transactions', 'event_espresso'), |
|
| 422 | + 'count' => 0, |
|
| 423 | + ), |
|
| 424 | + 'abandoned' => array( |
|
| 425 | + 'slug' => 'abandoned', |
|
| 426 | + 'label' => esc_html__('Abandoned Transactions', 'event_espresso'), |
|
| 427 | + 'count' => 0, |
|
| 428 | + ), |
|
| 429 | + 'incomplete' => array( |
|
| 430 | + 'slug' => 'incomplete', |
|
| 431 | + 'label' => esc_html__('Incomplete Transactions', 'event_espresso'), |
|
| 432 | + 'count' => 0, |
|
| 433 | + ), |
|
| 434 | + ); |
|
| 435 | + if (/** |
|
| 436 | + * Filters whether a link to the "Failed Transactions" list table |
|
| 437 | + * appears on the Transactions Admin Page list table. |
|
| 438 | + * List display can be turned back on via the following: |
|
| 439 | + * add_filter( |
|
| 440 | + * 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 441 | + * '__return_true' |
|
| 442 | + * ); |
|
| 443 | + * |
|
| 444 | + * @since 4.9.70.p |
|
| 445 | + * @param boolean $display_failed_txns_list |
|
| 446 | + * @param Transactions_Admin_Page $this |
|
| 447 | + */ |
|
| 448 | + apply_filters( |
|
| 449 | + 'FHEE__Transactions_Admin_Page___set_list_table_views_default__display_failed_txns_list', |
|
| 450 | + false, |
|
| 451 | + $this |
|
| 452 | + ) |
|
| 453 | + ) { |
|
| 454 | + $this->_views['failed'] = array( |
|
| 455 | + 'slug' => 'failed', |
|
| 456 | + 'label' => esc_html__('Failed Transactions', 'event_espresso'), |
|
| 457 | + 'count' => 0, |
|
| 458 | + ); |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * _set_transaction_object |
|
| 465 | + * This sets the _transaction property for the transaction details screen |
|
| 466 | + * |
|
| 467 | + * @access private |
|
| 468 | + * @return void |
|
| 469 | + * @throws EE_Error |
|
| 470 | + * @throws InvalidArgumentException |
|
| 471 | + * @throws RuntimeException |
|
| 472 | + * @throws InvalidDataTypeException |
|
| 473 | + * @throws InvalidInterfaceException |
|
| 474 | + * @throws ReflectionException |
|
| 475 | + */ |
|
| 476 | + private function _set_transaction_object() |
|
| 477 | + { |
|
| 478 | + if ($this->_transaction instanceof EE_Transaction) { |
|
| 479 | + return; |
|
| 480 | + } //get out we've already set the object |
|
| 481 | + |
|
| 482 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) |
|
| 483 | + ? absint($this->_req_data['TXN_ID']) |
|
| 484 | + : false; |
|
| 485 | + |
|
| 486 | + // get transaction object |
|
| 487 | + $this->_transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 488 | + $this->_session = $this->_transaction instanceof EE_Transaction |
|
| 489 | + ? $this->_transaction->session_data() |
|
| 490 | + : null; |
|
| 491 | + if ($this->_transaction instanceof EE_Transaction) { |
|
| 492 | + $this->_transaction->verify_abandoned_transaction_status(); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 496 | + $error_msg = sprintf( |
|
| 497 | + esc_html__( |
|
| 498 | + 'An error occurred and the details for the transaction with the ID # %d could not be retrieved.', |
|
| 499 | + 'event_espresso' |
|
| 500 | + ), |
|
| 501 | + $TXN_ID |
|
| 502 | + ); |
|
| 503 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
| 504 | + } |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + |
|
| 508 | + /** |
|
| 509 | + * _transaction_legend_items |
|
| 510 | + * |
|
| 511 | + * @access protected |
|
| 512 | + * @return array |
|
| 513 | + * @throws EE_Error |
|
| 514 | + * @throws InvalidArgumentException |
|
| 515 | + * @throws ReflectionException |
|
| 516 | + * @throws InvalidDataTypeException |
|
| 517 | + * @throws InvalidInterfaceException |
|
| 518 | + */ |
|
| 519 | + protected function _transaction_legend_items() |
|
| 520 | + { |
|
| 521 | + EE_Registry::instance()->load_helper('MSG_Template'); |
|
| 522 | + $items = array(); |
|
| 523 | + |
|
| 524 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 525 | + 'ee_read_global_messages', |
|
| 526 | + 'view_filtered_messages' |
|
| 527 | + )) { |
|
| 528 | + $related_for_icon = EEH_MSG_Template::get_message_action_icon('see_notifications_for'); |
|
| 529 | + if (is_array($related_for_icon) |
|
| 530 | + && isset($related_for_icon['css_class'], $related_for_icon['label']) |
|
| 531 | + ) { |
|
| 532 | + $items['view_related_messages'] = array( |
|
| 533 | + 'class' => $related_for_icon['css_class'], |
|
| 534 | + 'desc' => $related_for_icon['label'], |
|
| 535 | + ); |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + $items = apply_filters( |
|
| 540 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__items', |
|
| 541 | + array_merge( |
|
| 542 | + $items, |
|
| 543 | + array( |
|
| 544 | + 'view_details' => array( |
|
| 545 | + 'class' => 'dashicons dashicons-cart', |
|
| 546 | + 'desc' => esc_html__('View Transaction Details', 'event_espresso'), |
|
| 547 | + ), |
|
| 548 | + 'view_invoice' => array( |
|
| 549 | + 'class' => 'dashicons dashicons-media-spreadsheet', |
|
| 550 | + 'desc' => esc_html__('View Transaction Invoice', 'event_espresso'), |
|
| 551 | + ), |
|
| 552 | + 'view_receipt' => array( |
|
| 553 | + 'class' => 'dashicons dashicons-media-default', |
|
| 554 | + 'desc' => esc_html__('View Transaction Receipt', 'event_espresso'), |
|
| 555 | + ), |
|
| 556 | + 'view_registration' => array( |
|
| 557 | + 'class' => 'dashicons dashicons-clipboard', |
|
| 558 | + 'desc' => esc_html__('View Registration Details', 'event_espresso'), |
|
| 559 | + ), |
|
| 560 | + 'payment_overview_link' => array( |
|
| 561 | + 'class' => 'dashicons dashicons-money', |
|
| 562 | + 'desc' => esc_html__('Make Payment on Frontend', 'event_espresso'), |
|
| 563 | + ), |
|
| 564 | + ) |
|
| 565 | + ) |
|
| 566 | + ); |
|
| 567 | + |
|
| 568 | + if (EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 569 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 570 | + 'ee_send_message', |
|
| 571 | + 'espresso_transactions_send_payment_reminder' |
|
| 572 | + ) |
|
| 573 | + ) { |
|
| 574 | + $items['send_payment_reminder'] = array( |
|
| 575 | + 'class' => 'dashicons dashicons-email-alt', |
|
| 576 | + 'desc' => esc_html__('Send Payment Reminder', 'event_espresso'), |
|
| 577 | + ); |
|
| 578 | + } else { |
|
| 579 | + $items['blank*'] = array( |
|
| 580 | + 'class' => '', |
|
| 581 | + 'desc' => '', |
|
| 582 | + ); |
|
| 583 | + } |
|
| 584 | + $more_items = apply_filters( |
|
| 585 | + 'FHEE__Transactions_Admin_Page___transaction_legend_items__more_items', |
|
| 586 | + array( |
|
| 587 | + 'overpaid' => array( |
|
| 588 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::overpaid_status_code, |
|
| 589 | + 'desc' => EEH_Template::pretty_status( |
|
| 590 | + EEM_Transaction::overpaid_status_code, |
|
| 591 | + false, |
|
| 592 | + 'sentence' |
|
| 593 | + ), |
|
| 594 | + ), |
|
| 595 | + 'complete' => array( |
|
| 596 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::complete_status_code, |
|
| 597 | + 'desc' => EEH_Template::pretty_status( |
|
| 598 | + EEM_Transaction::complete_status_code, |
|
| 599 | + false, |
|
| 600 | + 'sentence' |
|
| 601 | + ), |
|
| 602 | + ), |
|
| 603 | + 'incomplete' => array( |
|
| 604 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::incomplete_status_code, |
|
| 605 | + 'desc' => EEH_Template::pretty_status( |
|
| 606 | + EEM_Transaction::incomplete_status_code, |
|
| 607 | + false, |
|
| 608 | + 'sentence' |
|
| 609 | + ), |
|
| 610 | + ), |
|
| 611 | + 'abandoned' => array( |
|
| 612 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::abandoned_status_code, |
|
| 613 | + 'desc' => EEH_Template::pretty_status( |
|
| 614 | + EEM_Transaction::abandoned_status_code, |
|
| 615 | + false, |
|
| 616 | + 'sentence' |
|
| 617 | + ), |
|
| 618 | + ), |
|
| 619 | + 'failed' => array( |
|
| 620 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Transaction::failed_status_code, |
|
| 621 | + 'desc' => EEH_Template::pretty_status( |
|
| 622 | + EEM_Transaction::failed_status_code, |
|
| 623 | + false, |
|
| 624 | + 'sentence' |
|
| 625 | + ), |
|
| 626 | + ), |
|
| 627 | + ) |
|
| 628 | + ); |
|
| 629 | + |
|
| 630 | + return array_merge($items, $more_items); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + |
|
| 634 | + /** |
|
| 635 | + * _transactions_overview_list_table |
|
| 636 | + * |
|
| 637 | + * @access protected |
|
| 638 | + * @return void |
|
| 639 | + * @throws DomainException |
|
| 640 | + * @throws EE_Error |
|
| 641 | + * @throws InvalidArgumentException |
|
| 642 | + * @throws InvalidDataTypeException |
|
| 643 | + * @throws InvalidInterfaceException |
|
| 644 | + * @throws ReflectionException |
|
| 645 | + */ |
|
| 646 | + protected function _transactions_overview_list_table() |
|
| 647 | + { |
|
| 648 | + $this->_admin_page_title = esc_html__('Transactions', 'event_espresso'); |
|
| 649 | + $event = isset($this->_req_data['EVT_ID']) |
|
| 650 | + ? EEM_Event::instance()->get_one_by_ID($this->_req_data['EVT_ID']) |
|
| 651 | + : null; |
|
| 652 | + $this->_template_args['admin_page_header'] = $event instanceof EE_Event |
|
| 653 | + ? sprintf( |
|
| 654 | + esc_html__( |
|
| 655 | + '%sViewing Transactions for the Event: %s%s', |
|
| 656 | + 'event_espresso' |
|
| 657 | + ), |
|
| 658 | + '<h3>', |
|
| 659 | + '<a href="' |
|
| 660 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
| 661 | + array('action' => 'edit', 'post' => $event->ID()), |
|
| 662 | + EVENTS_ADMIN_URL |
|
| 663 | + ) |
|
| 664 | + . '" title="' |
|
| 665 | + . esc_attr__( |
|
| 666 | + 'Click to Edit event', |
|
| 667 | + 'event_espresso' |
|
| 668 | + ) |
|
| 669 | + . '">' . $event->name() . '</a>', |
|
| 670 | + '</h3>' |
|
| 671 | + ) |
|
| 672 | + : ''; |
|
| 673 | + $this->_template_args['after_list_table'] = $this->_display_legend($this->_transaction_legend_items()); |
|
| 674 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 675 | + } |
|
| 676 | + |
|
| 677 | + |
|
| 678 | + /** |
|
| 679 | + * _transaction_details |
|
| 680 | + * generates HTML for the View Transaction Details Admin page |
|
| 681 | + * |
|
| 682 | + * @access protected |
|
| 683 | + * @return void |
|
| 684 | + * @throws DomainException |
|
| 685 | + * @throws EE_Error |
|
| 686 | + * @throws InvalidArgumentException |
|
| 687 | + * @throws InvalidDataTypeException |
|
| 688 | + * @throws InvalidInterfaceException |
|
| 689 | + * @throws RuntimeException |
|
| 690 | + * @throws ReflectionException |
|
| 691 | + */ |
|
| 692 | + protected function _transaction_details() |
|
| 693 | + { |
|
| 694 | + do_action('AHEE__Transactions_Admin_Page__transaction_details__start', $this->_transaction); |
|
| 695 | + |
|
| 696 | + $this->_set_transaction_status_array(); |
|
| 697 | + |
|
| 698 | + $this->_template_args = array(); |
|
| 699 | + $this->_template_args['transactions_page'] = $this->_wp_page_slug; |
|
| 700 | + |
|
| 701 | + $this->_set_transaction_object(); |
|
| 702 | + |
|
| 703 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 704 | + return; |
|
| 705 | + } |
|
| 706 | + $primary_registration = $this->_transaction->primary_registration(); |
|
| 707 | + $attendee = $primary_registration instanceof EE_Registration |
|
| 708 | + ? $primary_registration->attendee() |
|
| 709 | + : null; |
|
| 710 | + |
|
| 711 | + $this->_template_args['txn_nmbr']['value'] = $this->_transaction->ID(); |
|
| 712 | + $this->_template_args['txn_nmbr']['label'] = esc_html__('Transaction Number', 'event_espresso'); |
|
| 713 | + |
|
| 714 | + $this->_template_args['txn_datetime']['value'] = $this->_transaction->get_i18n_datetime('TXN_timestamp'); |
|
| 715 | + $this->_template_args['txn_datetime']['label'] = esc_html__('Date', 'event_espresso'); |
|
| 716 | + |
|
| 717 | + $this->_template_args['txn_status']['value'] = self::$_txn_status[ $this->_transaction->status_ID() ]; |
|
| 718 | + $this->_template_args['txn_status']['label'] = esc_html__('Transaction Status', 'event_espresso'); |
|
| 719 | + $this->_template_args['txn_status']['class'] = 'status-' . $this->_transaction->status_ID(); |
|
| 720 | + |
|
| 721 | + $this->_template_args['grand_total'] = $this->_transaction->total(); |
|
| 722 | + $this->_template_args['total_paid'] = $this->_transaction->paid(); |
|
| 723 | + |
|
| 724 | + $amount_due = $this->_transaction->total() - $this->_transaction->paid(); |
|
| 725 | + $this->_template_args['amount_due'] = EEH_Template::format_currency( |
|
| 726 | + $amount_due, |
|
| 727 | + true |
|
| 728 | + ); |
|
| 729 | + if (EE_Registry::instance()->CFG->currency->sign_b4) { |
|
| 730 | + $this->_template_args['amount_due'] = EE_Registry::instance()->CFG->currency->sign |
|
| 731 | + . $this->_template_args['amount_due']; |
|
| 732 | + } else { |
|
| 733 | + $this->_template_args['amount_due'] .= EE_Registry::instance()->CFG->currency->sign; |
|
| 734 | + } |
|
| 735 | + $this->_template_args['amount_due_class'] = ''; |
|
| 736 | + |
|
| 737 | + if ($this->_transaction->paid() === $this->_transaction->total()) { |
|
| 738 | + // paid in full |
|
| 739 | + $this->_template_args['amount_due'] = false; |
|
| 740 | + } elseif ($this->_transaction->paid() > $this->_transaction->total()) { |
|
| 741 | + // overpaid |
|
| 742 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 743 | + } elseif ($this->_transaction->total() > (float) 0) { |
|
| 744 | + if ($this->_transaction->paid() > (float) 0) { |
|
| 745 | + // monies owing |
|
| 746 | + $this->_template_args['amount_due_class'] = 'txn-overview-part-payment-spn'; |
|
| 747 | + } elseif ($this->_transaction->paid() === (float) 0) { |
|
| 748 | + // no payments made yet |
|
| 749 | + $this->_template_args['amount_due_class'] = 'txn-overview-no-payment-spn'; |
|
| 750 | + } |
|
| 751 | + } elseif ($this->_transaction->total() === (float) 0) { |
|
| 752 | + // free event |
|
| 753 | + $this->_template_args['amount_due'] = false; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + $payment_method = $this->_transaction->payment_method(); |
|
| 757 | + |
|
| 758 | + $this->_template_args['method_of_payment_name'] = $payment_method instanceof EE_Payment_Method |
|
| 759 | + ? $payment_method->admin_name() |
|
| 760 | + : esc_html__('Unknown', 'event_espresso'); |
|
| 761 | + |
|
| 762 | + $this->_template_args['currency_sign'] = EE_Registry::instance()->CFG->currency->sign; |
|
| 763 | + // link back to overview |
|
| 764 | + $this->_template_args['txn_overview_url'] = ! empty($_SERVER['HTTP_REFERER']) |
|
| 765 | + ? $_SERVER['HTTP_REFERER'] |
|
| 766 | + : TXN_ADMIN_URL; |
|
| 767 | + |
|
| 768 | + |
|
| 769 | + // next link |
|
| 770 | + $next_txn = $this->_transaction->next( |
|
| 771 | + null, |
|
| 772 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 773 | + 'TXN_ID' |
|
| 774 | + ); |
|
| 775 | + $this->_template_args['next_transaction'] = $next_txn |
|
| 776 | + ? $this->_next_link( |
|
| 777 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 778 | + array('action' => 'view_transaction', 'TXN_ID' => $next_txn['TXN_ID']), |
|
| 779 | + TXN_ADMIN_URL |
|
| 780 | + ), |
|
| 781 | + 'dashicons dashicons-arrow-right ee-icon-size-22' |
|
| 782 | + ) |
|
| 783 | + : ''; |
|
| 784 | + // previous link |
|
| 785 | + $previous_txn = $this->_transaction->previous( |
|
| 786 | + null, |
|
| 787 | + array(array('STS_ID' => array('!=', EEM_Transaction::failed_status_code))), |
|
| 788 | + 'TXN_ID' |
|
| 789 | + ); |
|
| 790 | + $this->_template_args['previous_transaction'] = $previous_txn |
|
| 791 | + ? $this->_previous_link( |
|
| 792 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 793 | + array('action' => 'view_transaction', 'TXN_ID' => $previous_txn['TXN_ID']), |
|
| 794 | + TXN_ADMIN_URL |
|
| 795 | + ), |
|
| 796 | + 'dashicons dashicons-arrow-left ee-icon-size-22' |
|
| 797 | + ) |
|
| 798 | + : ''; |
|
| 799 | + |
|
| 800 | + // were we just redirected here after adding a new registration ??? |
|
| 801 | + if (isset( |
|
| 802 | + $this->_req_data['redirect_from'], |
|
| 803 | + $this->_req_data['EVT_ID'], |
|
| 804 | + $this->_req_data['event_name'] |
|
| 805 | + )) { |
|
| 806 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 807 | + 'ee_edit_registrations', |
|
| 808 | + 'espresso_registrations_new_registration', |
|
| 809 | + $this->_req_data['EVT_ID'] |
|
| 810 | + )) { |
|
| 811 | + $this->_admin_page_title .= '<a id="add-new-registration" class="add-new-h2 button-primary" href="'; |
|
| 812 | + $this->_admin_page_title .= EE_Admin_Page::add_query_args_and_nonce( |
|
| 813 | + array( |
|
| 814 | + 'page' => 'espresso_registrations', |
|
| 815 | + 'action' => 'new_registration', |
|
| 816 | + 'return' => 'default', |
|
| 817 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 818 | + 'event_id' => $this->_req_data['EVT_ID'], |
|
| 819 | + ), |
|
| 820 | + REG_ADMIN_URL |
|
| 821 | + ); |
|
| 822 | + $this->_admin_page_title .= '">'; |
|
| 823 | + |
|
| 824 | + $this->_admin_page_title .= sprintf( |
|
| 825 | + esc_html__('Add Another New Registration to Event: "%1$s" ?', 'event_espresso'), |
|
| 826 | + htmlentities(urldecode($this->_req_data['event_name']), ENT_QUOTES, 'UTF-8') |
|
| 827 | + ); |
|
| 828 | + $this->_admin_page_title .= '</a>'; |
|
| 829 | + } |
|
| 830 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
| 831 | + } |
|
| 832 | + // grab messages at the last second |
|
| 833 | + $this->_template_args['notices'] = EE_Error::get_notices(); |
|
| 834 | + // path to template |
|
| 835 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_header.template.php'; |
|
| 836 | + $this->_template_args['admin_page_header'] = EEH_Template::display_template( |
|
| 837 | + $template_path, |
|
| 838 | + $this->_template_args, |
|
| 839 | + true |
|
| 840 | + ); |
|
| 841 | + |
|
| 842 | + // the details template wrapper |
|
| 843 | + $this->display_admin_page_with_sidebar(); |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + |
|
| 847 | + /** |
|
| 848 | + * _transaction_details_metaboxes |
|
| 849 | + * |
|
| 850 | + * @access protected |
|
| 851 | + * @return void |
|
| 852 | + * @throws EE_Error |
|
| 853 | + * @throws InvalidArgumentException |
|
| 854 | + * @throws InvalidDataTypeException |
|
| 855 | + * @throws InvalidInterfaceException |
|
| 856 | + * @throws RuntimeException |
|
| 857 | + * @throws ReflectionException |
|
| 858 | + */ |
|
| 859 | + protected function _transaction_details_metaboxes() |
|
| 860 | + { |
|
| 861 | + |
|
| 862 | + $this->_set_transaction_object(); |
|
| 863 | + |
|
| 864 | + if (! $this->_transaction instanceof EE_Transaction) { |
|
| 865 | + return; |
|
| 866 | + } |
|
| 867 | + add_meta_box( |
|
| 868 | + 'edit-txn-details-mbox', |
|
| 869 | + esc_html__('Transaction Details', 'event_espresso'), |
|
| 870 | + array($this, 'txn_details_meta_box'), |
|
| 871 | + $this->_wp_page_slug, |
|
| 872 | + 'normal', |
|
| 873 | + 'high' |
|
| 874 | + ); |
|
| 875 | + add_meta_box( |
|
| 876 | + 'edit-txn-attendees-mbox', |
|
| 877 | + esc_html__('Attendees Registered in this Transaction', 'event_espresso'), |
|
| 878 | + array($this, 'txn_attendees_meta_box'), |
|
| 879 | + $this->_wp_page_slug, |
|
| 880 | + 'normal', |
|
| 881 | + 'high', |
|
| 882 | + array('TXN_ID' => $this->_transaction->ID()) |
|
| 883 | + ); |
|
| 884 | + add_meta_box( |
|
| 885 | + 'edit-txn-registrant-mbox', |
|
| 886 | + esc_html__('Primary Contact', 'event_espresso'), |
|
| 887 | + array($this, 'txn_registrant_side_meta_box'), |
|
| 888 | + $this->_wp_page_slug, |
|
| 889 | + 'side', |
|
| 890 | + 'high' |
|
| 891 | + ); |
|
| 892 | + add_meta_box( |
|
| 893 | + 'edit-txn-billing-info-mbox', |
|
| 894 | + esc_html__('Billing Information', 'event_espresso'), |
|
| 895 | + array($this, 'txn_billing_info_side_meta_box'), |
|
| 896 | + $this->_wp_page_slug, |
|
| 897 | + 'side', |
|
| 898 | + 'high' |
|
| 899 | + ); |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * Callback for transaction actions metabox. |
|
| 905 | + * |
|
| 906 | + * @param EE_Transaction|null $transaction |
|
| 907 | + * @return string |
|
| 908 | + * @throws DomainException |
|
| 909 | + * @throws EE_Error |
|
| 910 | + * @throws InvalidArgumentException |
|
| 911 | + * @throws InvalidDataTypeException |
|
| 912 | + * @throws InvalidInterfaceException |
|
| 913 | + * @throws ReflectionException |
|
| 914 | + * @throws RuntimeException |
|
| 915 | + */ |
|
| 916 | + public function getActionButtons(EE_Transaction $transaction = null) |
|
| 917 | + { |
|
| 918 | + $content = ''; |
|
| 919 | + $actions = array(); |
|
| 920 | + if (! $transaction instanceof EE_Transaction) { |
|
| 921 | + return $content; |
|
| 922 | + } |
|
| 923 | + /** @var EE_Registration $primary_registration */ |
|
| 924 | + $primary_registration = $transaction->primary_registration(); |
|
| 925 | + $attendee = $primary_registration instanceof EE_Registration |
|
| 926 | + ? $primary_registration->attendee() |
|
| 927 | + : null; |
|
| 928 | + |
|
| 929 | + if ($attendee instanceof EE_Attendee |
|
| 930 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 931 | + 'ee_send_message', |
|
| 932 | + 'espresso_transactions_send_payment_reminder' |
|
| 933 | + ) |
|
| 934 | + ) { |
|
| 935 | + $actions['payment_reminder'] = |
|
| 936 | + EEH_MSG_Template::is_mt_active('payment_reminder') |
|
| 937 | + && $this->_transaction->status_ID() !== EEM_Transaction::complete_status_code |
|
| 938 | + && $this->_transaction->status_ID() !== EEM_Transaction::overpaid_status_code |
|
| 939 | + ? EEH_Template::get_button_or_link( |
|
| 940 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 941 | + array( |
|
| 942 | + 'action' => 'send_payment_reminder', |
|
| 943 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 944 | + 'redirect_to' => 'view_transaction', |
|
| 945 | + ), |
|
| 946 | + TXN_ADMIN_URL |
|
| 947 | + ), |
|
| 948 | + esc_html__(' Send Payment Reminder', 'event_espresso'), |
|
| 949 | + 'button secondary-button', |
|
| 950 | + 'dashicons dashicons-email-alt' |
|
| 951 | + ) |
|
| 952 | + : ''; |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
| 956 | + 'ee_edit_payments', |
|
| 957 | + 'espresso_transactions_recalculate_line_items' |
|
| 958 | + ) |
|
| 959 | + ) { |
|
| 960 | + $actions['recalculate_line_items'] = EEH_Template::get_button_or_link( |
|
| 961 | + EE_Admin_Page::add_query_args_and_nonce( |
|
| 962 | + array( |
|
| 963 | + 'action' => 'espresso_recalculate_line_items', |
|
| 964 | + 'TXN_ID' => $this->_transaction->ID(), |
|
| 965 | + 'redirect_to' => 'view_transaction', |
|
| 966 | + ), |
|
| 967 | + TXN_ADMIN_URL |
|
| 968 | + ), |
|
| 969 | + esc_html__(' Recalculate Taxes and Total', 'event_espresso'), |
|
| 970 | + 'button secondary-button', |
|
| 971 | + 'dashicons dashicons-update' |
|
| 972 | + ); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + if ($primary_registration instanceof EE_Registration |
|
| 976 | + && EEH_MSG_Template::is_mt_active('receipt') |
|
| 977 | + ) { |
|
| 978 | + $actions['receipt'] = EEH_Template::get_button_or_link( |
|
| 979 | + $primary_registration->receipt_url(), |
|
| 980 | + esc_html__('View Receipt', 'event_espresso'), |
|
| 981 | + 'button secondary-button', |
|
| 982 | + 'dashicons dashicons-media-default' |
|
| 983 | + ); |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + if ($primary_registration instanceof EE_Registration |
|
| 987 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
| 988 | + ) { |
|
| 989 | + $actions['invoice'] = EEH_Template::get_button_or_link( |
|
| 990 | + $primary_registration->invoice_url(), |
|
| 991 | + esc_html__('View Invoice', 'event_espresso'), |
|
| 992 | + 'button secondary-button', |
|
| 993 | + 'dashicons dashicons-media-spreadsheet' |
|
| 994 | + ); |
|
| 995 | + } |
|
| 996 | + $actions = array_filter( |
|
| 997 | + apply_filters('FHEE__Transactions_Admin_Page__getActionButtons__actions', $actions, $transaction) |
|
| 998 | + ); |
|
| 999 | + if ($actions) { |
|
| 1000 | + $content = '<ul>'; |
|
| 1001 | + $content .= '<li>' . implode('</li><li>', $actions) . '</li>'; |
|
| 1002 | + $content .= '</uL>'; |
|
| 1003 | + } |
|
| 1004 | + return $content; |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + |
|
| 1008 | + /** |
|
| 1009 | + * txn_details_meta_box |
|
| 1010 | + * generates HTML for the Transaction main meta box |
|
| 1011 | + * |
|
| 1012 | + * @return void |
|
| 1013 | + * @throws DomainException |
|
| 1014 | + * @throws EE_Error |
|
| 1015 | + * @throws InvalidArgumentException |
|
| 1016 | + * @throws InvalidDataTypeException |
|
| 1017 | + * @throws InvalidInterfaceException |
|
| 1018 | + * @throws RuntimeException |
|
| 1019 | + * @throws ReflectionException |
|
| 1020 | + */ |
|
| 1021 | + public function txn_details_meta_box() |
|
| 1022 | + { |
|
| 1023 | + $this->_set_transaction_object(); |
|
| 1024 | + $this->_template_args['TXN_ID'] = $this->_transaction->ID(); |
|
| 1025 | + $this->_template_args['attendee'] = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1026 | + ? $this->_transaction->primary_registration()->attendee() |
|
| 1027 | + : null; |
|
| 1028 | + $this->_template_args['can_edit_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1029 | + 'ee_edit_payments', |
|
| 1030 | + 'apply_payment_or_refund_from_registration_details' |
|
| 1031 | + ); |
|
| 1032 | + $this->_template_args['can_delete_payments'] = EE_Registry::instance()->CAP->current_user_can( |
|
| 1033 | + 'ee_delete_payments', |
|
| 1034 | + 'delete_payment_from_registration_details' |
|
| 1035 | + ); |
|
| 1036 | + |
|
| 1037 | + // get line table |
|
| 1038 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
| 1039 | + $Line_Item_Display = new EE_Line_Item_Display( |
|
| 1040 | + 'admin_table', |
|
| 1041 | + 'EE_Admin_Table_Line_Item_Display_Strategy' |
|
| 1042 | + ); |
|
| 1043 | + $this->_template_args['line_item_table'] = $Line_Item_Display->display_line_item( |
|
| 1044 | + $this->_transaction->total_line_item() |
|
| 1045 | + ); |
|
| 1046 | + $this->_template_args['REG_code'] = $this->_transaction->primary_registration()->reg_code(); |
|
| 1047 | + |
|
| 1048 | + // process taxes |
|
| 1049 | + $taxes = $this->_transaction->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 1050 | + $this->_template_args['taxes'] = ! empty($taxes) ? $taxes : false; |
|
| 1051 | + |
|
| 1052 | + $this->_template_args['grand_total'] = EEH_Template::format_currency( |
|
| 1053 | + $this->_transaction->total(), |
|
| 1054 | + false, |
|
| 1055 | + false |
|
| 1056 | + ); |
|
| 1057 | + $this->_template_args['grand_raw_total'] = $this->_transaction->total(); |
|
| 1058 | + $this->_template_args['TXN_status'] = $this->_transaction->status_ID(); |
|
| 1059 | + |
|
| 1060 | + // process payment details |
|
| 1061 | + $payments = $this->_transaction->payments(); |
|
| 1062 | + if (! empty($payments)) { |
|
| 1063 | + $this->_template_args['payments'] = $payments; |
|
| 1064 | + $this->_template_args['existing_reg_payments'] = $this->_get_registration_payment_IDs($payments); |
|
| 1065 | + } else { |
|
| 1066 | + $this->_template_args['payments'] = false; |
|
| 1067 | + $this->_template_args['existing_reg_payments'] = array(); |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + $this->_template_args['edit_payment_url'] = add_query_arg(array('action' => 'edit_payment'), TXN_ADMIN_URL); |
|
| 1071 | + $this->_template_args['delete_payment_url'] = add_query_arg( |
|
| 1072 | + array('action' => 'espresso_delete_payment'), |
|
| 1073 | + TXN_ADMIN_URL |
|
| 1074 | + ); |
|
| 1075 | + |
|
| 1076 | + if (isset($txn_details['invoice_number'])) { |
|
| 1077 | + $this->_template_args['txn_details']['invoice_number']['value'] = $this->_template_args['REG_code']; |
|
| 1078 | + $this->_template_args['txn_details']['invoice_number']['label'] = esc_html__( |
|
| 1079 | + 'Invoice Number', |
|
| 1080 | + 'event_espresso' |
|
| 1081 | + ); |
|
| 1082 | + } |
|
| 1083 | + |
|
| 1084 | + $this->_template_args['txn_details']['registration_session']['value'] = $this->_transaction |
|
| 1085 | + ->primary_registration() |
|
| 1086 | + ->session_ID(); |
|
| 1087 | + $this->_template_args['txn_details']['registration_session']['label'] = esc_html__( |
|
| 1088 | + 'Registration Session', |
|
| 1089 | + 'event_espresso' |
|
| 1090 | + ); |
|
| 1091 | + |
|
| 1092 | + $this->_template_args['txn_details']['ip_address']['value'] = isset($this->_session['ip_address']) |
|
| 1093 | + ? $this->_session['ip_address'] |
|
| 1094 | + : ''; |
|
| 1095 | + $this->_template_args['txn_details']['ip_address']['label'] = esc_html__( |
|
| 1096 | + 'Transaction placed from IP', |
|
| 1097 | + 'event_espresso' |
|
| 1098 | + ); |
|
| 1099 | + |
|
| 1100 | + $this->_template_args['txn_details']['user_agent']['value'] = isset($this->_session['user_agent']) |
|
| 1101 | + ? $this->_session['user_agent'] |
|
| 1102 | + : ''; |
|
| 1103 | + $this->_template_args['txn_details']['user_agent']['label'] = esc_html__( |
|
| 1104 | + 'Registrant User Agent', |
|
| 1105 | + 'event_espresso' |
|
| 1106 | + ); |
|
| 1107 | + |
|
| 1108 | + $reg_steps = '<ul>'; |
|
| 1109 | + foreach ($this->_transaction->reg_steps() as $reg_step => $reg_step_status) { |
|
| 1110 | + if ($reg_step_status === true) { |
|
| 1111 | + $reg_steps .= '<li style="color:#70cc50">' |
|
| 1112 | + . sprintf( |
|
| 1113 | + esc_html__('%1$s : Completed', 'event_espresso'), |
|
| 1114 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1115 | + ) |
|
| 1116 | + . '</li>'; |
|
| 1117 | + } elseif (is_numeric($reg_step_status) && $reg_step_status !== false) { |
|
| 1118 | + $reg_steps .= '<li style="color:#2EA2CC">' |
|
| 1119 | + . sprintf( |
|
| 1120 | + esc_html__('%1$s : Initiated %2$s', 'event_espresso'), |
|
| 1121 | + ucwords(str_replace('_', ' ', $reg_step)), |
|
| 1122 | + date( |
|
| 1123 | + get_option('date_format') . ' ' . get_option('time_format'), |
|
| 1124 | + $reg_step_status + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
| 1125 | + ) |
|
| 1126 | + ) |
|
| 1127 | + . '</li>'; |
|
| 1128 | + } else { |
|
| 1129 | + $reg_steps .= '<li style="color:#E76700">' |
|
| 1130 | + . sprintf( |
|
| 1131 | + esc_html__('%1$s : Never Initiated', 'event_espresso'), |
|
| 1132 | + ucwords(str_replace('_', ' ', $reg_step)) |
|
| 1133 | + ) |
|
| 1134 | + . '</li>'; |
|
| 1135 | + } |
|
| 1136 | + } |
|
| 1137 | + $reg_steps .= '</ul>'; |
|
| 1138 | + $this->_template_args['txn_details']['reg_steps']['value'] = $reg_steps; |
|
| 1139 | + $this->_template_args['txn_details']['reg_steps']['label'] = esc_html__( |
|
| 1140 | + 'Registration Step Progress', |
|
| 1141 | + 'event_espresso' |
|
| 1142 | + ); |
|
| 1143 | + |
|
| 1144 | + |
|
| 1145 | + $this->_get_registrations_to_apply_payment_to(); |
|
| 1146 | + $this->_get_payment_methods($payments); |
|
| 1147 | + $this->_get_payment_status_array(); |
|
| 1148 | + $this->_get_reg_status_selection(); // sets up the template args for the reg status array for the transaction. |
|
| 1149 | + |
|
| 1150 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1151 | + array( |
|
| 1152 | + 'action' => 'edit_transaction', |
|
| 1153 | + 'process' => 'transaction', |
|
| 1154 | + ), |
|
| 1155 | + TXN_ADMIN_URL |
|
| 1156 | + ); |
|
| 1157 | + $this->_template_args['apply_payment_form_url'] = add_query_arg( |
|
| 1158 | + array( |
|
| 1159 | + 'page' => 'espresso_transactions', |
|
| 1160 | + 'action' => 'espresso_apply_payment', |
|
| 1161 | + ), |
|
| 1162 | + WP_AJAX_URL |
|
| 1163 | + ); |
|
| 1164 | + $this->_template_args['delete_payment_form_url'] = add_query_arg( |
|
| 1165 | + array( |
|
| 1166 | + 'page' => 'espresso_transactions', |
|
| 1167 | + 'action' => 'espresso_delete_payment', |
|
| 1168 | + ), |
|
| 1169 | + WP_AJAX_URL |
|
| 1170 | + ); |
|
| 1171 | + |
|
| 1172 | + $this->_template_args['action_buttons'] = $this->getActionButtons($this->_transaction); |
|
| 1173 | + |
|
| 1174 | + // 'espresso_delete_payment_nonce' |
|
| 1175 | + |
|
| 1176 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_txn_details.template.php'; |
|
| 1177 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1178 | + } |
|
| 1179 | + |
|
| 1180 | + |
|
| 1181 | + /** |
|
| 1182 | + * _get_registration_payment_IDs |
|
| 1183 | + * generates an array of Payment IDs and their corresponding Registration IDs |
|
| 1184 | + * |
|
| 1185 | + * @access protected |
|
| 1186 | + * @param EE_Payment[] $payments |
|
| 1187 | + * @return array |
|
| 1188 | + * @throws EE_Error |
|
| 1189 | + * @throws InvalidArgumentException |
|
| 1190 | + * @throws InvalidDataTypeException |
|
| 1191 | + * @throws InvalidInterfaceException |
|
| 1192 | + * @throws ReflectionException |
|
| 1193 | + */ |
|
| 1194 | + protected function _get_registration_payment_IDs($payments = array()) |
|
| 1195 | + { |
|
| 1196 | + $existing_reg_payments = array(); |
|
| 1197 | + // get all reg payments for these payments |
|
| 1198 | + $reg_payments = EEM_Registration_Payment::instance()->get_all( |
|
| 1199 | + array( |
|
| 1200 | + array( |
|
| 1201 | + 'PAY_ID' => array( |
|
| 1202 | + 'IN', |
|
| 1203 | + array_keys($payments), |
|
| 1204 | + ), |
|
| 1205 | + ), |
|
| 1206 | + ) |
|
| 1207 | + ); |
|
| 1208 | + if (! empty($reg_payments)) { |
|
| 1209 | + foreach ($payments as $payment) { |
|
| 1210 | + if (! $payment instanceof EE_Payment) { |
|
| 1211 | + continue; |
|
| 1212 | + } elseif (! isset($existing_reg_payments[ $payment->ID() ])) { |
|
| 1213 | + $existing_reg_payments[ $payment->ID() ] = array(); |
|
| 1214 | + } |
|
| 1215 | + foreach ($reg_payments as $reg_payment) { |
|
| 1216 | + if ($reg_payment instanceof EE_Registration_Payment |
|
| 1217 | + && $reg_payment->payment_ID() === $payment->ID() |
|
| 1218 | + ) { |
|
| 1219 | + $existing_reg_payments[ $payment->ID() ][] = $reg_payment->registration_ID(); |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + } |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + return $existing_reg_payments; |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + |
|
| 1229 | + /** |
|
| 1230 | + * _get_registrations_to_apply_payment_to |
|
| 1231 | + * generates HTML for displaying a series of checkboxes in the admin payment modal window |
|
| 1232 | + * which allows the admin to only apply the payment to the specific registrations |
|
| 1233 | + * |
|
| 1234 | + * @access protected |
|
| 1235 | + * @return void |
|
| 1236 | + * @throws EE_Error |
|
| 1237 | + * @throws InvalidArgumentException |
|
| 1238 | + * @throws InvalidDataTypeException |
|
| 1239 | + * @throws InvalidInterfaceException |
|
| 1240 | + * @throws ReflectionException |
|
| 1241 | + */ |
|
| 1242 | + protected function _get_registrations_to_apply_payment_to() |
|
| 1243 | + { |
|
| 1244 | + // we want any registration with an active status (ie: not deleted or cancelled) |
|
| 1245 | + $query_params = array( |
|
| 1246 | + array( |
|
| 1247 | + 'STS_ID' => array( |
|
| 1248 | + 'IN', |
|
| 1249 | + array( |
|
| 1250 | + EEM_Registration::status_id_approved, |
|
| 1251 | + EEM_Registration::status_id_pending_payment, |
|
| 1252 | + EEM_Registration::status_id_not_approved, |
|
| 1253 | + ), |
|
| 1254 | + ), |
|
| 1255 | + ), |
|
| 1256 | + ); |
|
| 1257 | + $registrations_to_apply_payment_to = EEH_HTML::br() . EEH_HTML::div( |
|
| 1258 | + '', |
|
| 1259 | + 'txn-admin-apply-payment-to-registrations-dv', |
|
| 1260 | + '', |
|
| 1261 | + 'clear: both; margin: 1.5em 0 0; display: none;' |
|
| 1262 | + ); |
|
| 1263 | + $registrations_to_apply_payment_to .= EEH_HTML::br() . EEH_HTML::div('', '', 'admin-primary-mbox-tbl-wrap'); |
|
| 1264 | + $registrations_to_apply_payment_to .= EEH_HTML::table('', '', 'admin-primary-mbox-tbl'); |
|
| 1265 | + $registrations_to_apply_payment_to .= EEH_HTML::thead( |
|
| 1266 | + EEH_HTML::tr( |
|
| 1267 | + EEH_HTML::th(esc_html__('ID', 'event_espresso')) . |
|
| 1268 | + EEH_HTML::th(esc_html__('Registrant', 'event_espresso')) . |
|
| 1269 | + EEH_HTML::th(esc_html__('Ticket', 'event_espresso')) . |
|
| 1270 | + EEH_HTML::th(esc_html__('Event', 'event_espresso')) . |
|
| 1271 | + EEH_HTML::th(esc_html__('Paid', 'event_espresso'), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1272 | + EEH_HTML::th(esc_html__('Owing', 'event_espresso'), '', 'txn-admin-payment-owing-td jst-cntr') . |
|
| 1273 | + EEH_HTML::th(esc_html__('Apply', 'event_espresso'), '', 'jst-cntr') |
|
| 1274 | + ) |
|
| 1275 | + ); |
|
| 1276 | + $registrations_to_apply_payment_to .= EEH_HTML::tbody(); |
|
| 1277 | + // get registrations for TXN |
|
| 1278 | + $registrations = $this->_transaction->registrations($query_params); |
|
| 1279 | + $existing_reg_payments = $this->_template_args['existing_reg_payments']; |
|
| 1280 | + foreach ($registrations as $registration) { |
|
| 1281 | + if ($registration instanceof EE_Registration) { |
|
| 1282 | + $attendee_name = $registration->attendee() instanceof EE_Attendee |
|
| 1283 | + ? $registration->attendee()->full_name() |
|
| 1284 | + : esc_html__('Unknown Attendee', 'event_espresso'); |
|
| 1285 | + $owing = $registration->final_price() - $registration->paid(); |
|
| 1286 | + $taxable = $registration->ticket()->taxable() |
|
| 1287 | + ? ' <span class="smaller-text lt-grey-text"> ' . esc_html__('+ tax', 'event_espresso') . '</span>' |
|
| 1288 | + : ''; |
|
| 1289 | + $checked = empty($existing_reg_payments) |
|
| 1290 | + || in_array($registration->ID(), $existing_reg_payments, true) |
|
| 1291 | + ? ' checked="checked"' |
|
| 1292 | + : ''; |
|
| 1293 | + $disabled = $registration->final_price() > 0 ? '' : ' disabled'; |
|
| 1294 | + $registrations_to_apply_payment_to .= EEH_HTML::tr( |
|
| 1295 | + EEH_HTML::td($registration->ID()) . |
|
| 1296 | + EEH_HTML::td($attendee_name) . |
|
| 1297 | + EEH_HTML::td( |
|
| 1298 | + $registration->ticket()->name() . ' : ' . $registration->ticket()->pretty_price() . $taxable |
|
| 1299 | + ) . |
|
| 1300 | + EEH_HTML::td($registration->event_name()) . |
|
| 1301 | + EEH_HTML::td($registration->pretty_paid(), '', 'txn-admin-payment-paid-td jst-cntr') . |
|
| 1302 | + EEH_HTML::td( |
|
| 1303 | + EEH_Template::format_currency($owing), |
|
| 1304 | + '', |
|
| 1305 | + 'txn-admin-payment-owing-td jst-cntr' |
|
| 1306 | + ) . |
|
| 1307 | + EEH_HTML::td( |
|
| 1308 | + '<input type="checkbox" value="' . $registration->ID() |
|
| 1309 | + . '" name="txn_admin_payment[registrations]"' |
|
| 1310 | + . $checked . $disabled . '>', |
|
| 1311 | + '', |
|
| 1312 | + 'jst-cntr' |
|
| 1313 | + ), |
|
| 1314 | + 'apply-payment-registration-row-' . $registration->ID() |
|
| 1315 | + ); |
|
| 1316 | + } |
|
| 1317 | + } |
|
| 1318 | + $registrations_to_apply_payment_to .= EEH_HTML::tbodyx(); |
|
| 1319 | + $registrations_to_apply_payment_to .= EEH_HTML::tablex(); |
|
| 1320 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1321 | + $registrations_to_apply_payment_to .= EEH_HTML::p( |
|
| 1322 | + esc_html__( |
|
| 1323 | + '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.', |
|
| 1324 | + 'event_espresso' |
|
| 1325 | + ), |
|
| 1326 | + '', |
|
| 1327 | + 'clear description' |
|
| 1328 | + ); |
|
| 1329 | + $registrations_to_apply_payment_to .= EEH_HTML::divx(); |
|
| 1330 | + $this->_template_args['registrations_to_apply_payment_to'] = $registrations_to_apply_payment_to; |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + |
|
| 1334 | + /** |
|
| 1335 | + * _get_reg_status_selection |
|
| 1336 | + * |
|
| 1337 | + * @todo this will need to be adjusted either once MER comes along OR we move default reg status to tickets |
|
| 1338 | + * instead of events. |
|
| 1339 | + * @access protected |
|
| 1340 | + * @return void |
|
| 1341 | + * @throws EE_Error |
|
| 1342 | + */ |
|
| 1343 | + protected function _get_reg_status_selection() |
|
| 1344 | + { |
|
| 1345 | + // first get all possible statuses |
|
| 1346 | + $statuses = EEM_Registration::reg_status_array(array(), true); |
|
| 1347 | + // let's add a "don't change" option. |
|
| 1348 | + $status_array['NAN'] = esc_html__('Leave the Same', 'event_espresso'); |
|
| 1349 | + $status_array = array_merge($status_array, $statuses); |
|
| 1350 | + $this->_template_args['status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1351 | + 'txn_reg_status_change[reg_status]', |
|
| 1352 | + $status_array, |
|
| 1353 | + 'NAN', |
|
| 1354 | + 'id="txn-admin-payment-reg-status-inp"', |
|
| 1355 | + 'txn-reg-status-change-reg-status' |
|
| 1356 | + ); |
|
| 1357 | + $this->_template_args['delete_status_change_select'] = EEH_Form_Fields::select_input( |
|
| 1358 | + 'delete_txn_reg_status_change[reg_status]', |
|
| 1359 | + $status_array, |
|
| 1360 | + 'NAN', |
|
| 1361 | + 'delete-txn-admin-payment-reg-status-inp', |
|
| 1362 | + 'delete-txn-reg-status-change-reg-status' |
|
| 1363 | + ); |
|
| 1364 | + } |
|
| 1365 | + |
|
| 1366 | + |
|
| 1367 | + /** |
|
| 1368 | + * _get_payment_methods |
|
| 1369 | + * Gets all the payment methods available generally, or the ones that are already |
|
| 1370 | + * selected on these payments (in case their payment methods are no longer active). |
|
| 1371 | + * Has the side-effect of updating the template args' payment_methods item |
|
| 1372 | + * |
|
| 1373 | + * @access private |
|
| 1374 | + * @param EE_Payment[] to show on this page |
|
| 1375 | + * @return void |
|
| 1376 | + * @throws EE_Error |
|
| 1377 | + * @throws InvalidArgumentException |
|
| 1378 | + * @throws InvalidDataTypeException |
|
| 1379 | + * @throws InvalidInterfaceException |
|
| 1380 | + * @throws ReflectionException |
|
| 1381 | + */ |
|
| 1382 | + private function _get_payment_methods($payments = array()) |
|
| 1383 | + { |
|
| 1384 | + $payment_methods_of_payments = array(); |
|
| 1385 | + foreach ($payments as $payment) { |
|
| 1386 | + if ($payment instanceof EE_Payment) { |
|
| 1387 | + $payment_methods_of_payments[] = $payment->ID(); |
|
| 1388 | + } |
|
| 1389 | + } |
|
| 1390 | + if ($payment_methods_of_payments) { |
|
| 1391 | + $query_args = array( |
|
| 1392 | + array( |
|
| 1393 | + 'OR*payment_method_for_payment' => array( |
|
| 1394 | + 'PMD_ID' => array('IN', $payment_methods_of_payments), |
|
| 1395 | + 'PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'), |
|
| 1396 | + ), |
|
| 1397 | + ), |
|
| 1398 | + ); |
|
| 1399 | + } else { |
|
| 1400 | + $query_args = array(array('PMD_scope' => array('LIKE', '%' . EEM_Payment_Method::scope_admin . '%'))); |
|
| 1401 | + } |
|
| 1402 | + $this->_template_args['payment_methods'] = EEM_Payment_Method::instance()->get_all($query_args); |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + |
|
| 1406 | + /** |
|
| 1407 | + * txn_attendees_meta_box |
|
| 1408 | + * generates HTML for the Attendees Transaction main meta box |
|
| 1409 | + * |
|
| 1410 | + * @access public |
|
| 1411 | + * @param WP_Post $post |
|
| 1412 | + * @param array $metabox |
|
| 1413 | + * @return void |
|
| 1414 | + * @throws DomainException |
|
| 1415 | + * @throws EE_Error |
|
| 1416 | + * @throws InvalidArgumentException |
|
| 1417 | + * @throws InvalidDataTypeException |
|
| 1418 | + * @throws InvalidInterfaceException |
|
| 1419 | + * @throws ReflectionException |
|
| 1420 | + */ |
|
| 1421 | + public function txn_attendees_meta_box($post, $metabox = array('args' => array())) |
|
| 1422 | + { |
|
| 1423 | + |
|
| 1424 | + /** @noinspection NonSecureExtractUsageInspection */ |
|
| 1425 | + extract($metabox['args']); |
|
| 1426 | + $this->_template_args['post'] = $post; |
|
| 1427 | + $this->_template_args['event_attendees'] = array(); |
|
| 1428 | + // process items in cart |
|
| 1429 | + $line_items = $this->_transaction->get_many_related( |
|
| 1430 | + 'Line_Item', |
|
| 1431 | + array(array('LIN_type' => 'line-item')) |
|
| 1432 | + ); |
|
| 1433 | + if (! empty($line_items)) { |
|
| 1434 | + foreach ($line_items as $item) { |
|
| 1435 | + if ($item instanceof EE_Line_Item) { |
|
| 1436 | + switch ($item->OBJ_type()) { |
|
| 1437 | + case 'Event': |
|
| 1438 | + break; |
|
| 1439 | + case 'Ticket': |
|
| 1440 | + $ticket = $item->ticket(); |
|
| 1441 | + // right now we're only handling tickets here. |
|
| 1442 | + // Cause its expected that only tickets will have attendees right? |
|
| 1443 | + if (! $ticket instanceof EE_Ticket) { |
|
| 1444 | + break; |
|
| 1445 | + } |
|
| 1446 | + try { |
|
| 1447 | + $event_name = $ticket->get_event_name(); |
|
| 1448 | + } catch (Exception $e) { |
|
| 1449 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1450 | + $event_name = esc_html__('Unknown Event', 'event_espresso'); |
|
| 1451 | + } |
|
| 1452 | + $event_name .= ' - ' . $item->name(); |
|
| 1453 | + $ticket_price = EEH_Template::format_currency($item->unit_price()); |
|
| 1454 | + // now get all of the registrations for this transaction that use this ticket |
|
| 1455 | + $registrations = $ticket->registrations( |
|
| 1456 | + array(array('TXN_ID' => $this->_transaction->ID())) |
|
| 1457 | + ); |
|
| 1458 | + foreach ($registrations as $registration) { |
|
| 1459 | + if (! $registration instanceof EE_Registration) { |
|
| 1460 | + break; |
|
| 1461 | + } |
|
| 1462 | + $this->_template_args['event_attendees'][ $registration->ID() ]['STS_ID'] |
|
| 1463 | + = $registration->status_ID(); |
|
| 1464 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_num'] |
|
| 1465 | + = $registration->count(); |
|
| 1466 | + $this->_template_args['event_attendees'][ $registration->ID() ]['event_ticket_name'] |
|
| 1467 | + = $event_name; |
|
| 1468 | + $this->_template_args['event_attendees'][ $registration->ID() ]['ticket_price'] |
|
| 1469 | + = $ticket_price; |
|
| 1470 | + // attendee info |
|
| 1471 | + $attendee = $registration->get_first_related('Attendee'); |
|
| 1472 | + if ($attendee instanceof EE_Attendee) { |
|
| 1473 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] |
|
| 1474 | + = $attendee->ID(); |
|
| 1475 | + $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] |
|
| 1476 | + = $attendee->full_name(); |
|
| 1477 | + $this->_template_args['event_attendees'][ $registration->ID() ]['email'] |
|
| 1478 | + = '<a href="mailto:' . $attendee->email() . '?subject=' . $event_name |
|
| 1479 | + . esc_html__( |
|
| 1480 | + ' Event', |
|
| 1481 | + 'event_espresso' |
|
| 1482 | + ) |
|
| 1483 | + . '">' . $attendee->email() . '</a>'; |
|
| 1484 | + $this->_template_args['event_attendees'][ $registration->ID() ]['address'] |
|
| 1485 | + = EEH_Address::format($attendee, 'inline', false, false); |
|
| 1486 | + } else { |
|
| 1487 | + $this->_template_args['event_attendees'][ $registration->ID() ]['att_id'] = ''; |
|
| 1488 | + $this->_template_args['event_attendees'][ $registration->ID() ]['attendee'] = ''; |
|
| 1489 | + $this->_template_args['event_attendees'][ $registration->ID() ]['email'] = ''; |
|
| 1490 | + $this->_template_args['event_attendees'][ $registration->ID() ]['address'] = ''; |
|
| 1491 | + } |
|
| 1492 | + } |
|
| 1493 | + break; |
|
| 1494 | + } |
|
| 1495 | + } |
|
| 1496 | + } |
|
| 1497 | + |
|
| 1498 | + $this->_template_args['transaction_form_url'] = add_query_arg( |
|
| 1499 | + array( |
|
| 1500 | + 'action' => 'edit_transaction', |
|
| 1501 | + 'process' => 'attendees', |
|
| 1502 | + ), |
|
| 1503 | + TXN_ADMIN_URL |
|
| 1504 | + ); |
|
| 1505 | + echo EEH_Template::display_template( |
|
| 1506 | + TXN_TEMPLATE_PATH . 'txn_admin_details_main_meta_box_attendees.template.php', |
|
| 1507 | + $this->_template_args, |
|
| 1508 | + true |
|
| 1509 | + ); |
|
| 1510 | + } else { |
|
| 1511 | + echo sprintf( |
|
| 1512 | + esc_html__( |
|
| 1513 | + '%1$sFor some reason, there are no attendees registered for this transaction. Likely the registration was abandoned in process.%2$s', |
|
| 1514 | + 'event_espresso' |
|
| 1515 | + ), |
|
| 1516 | + '<p class="important-notice">', |
|
| 1517 | + '</p>' |
|
| 1518 | + ); |
|
| 1519 | + } |
|
| 1520 | + } |
|
| 1521 | + |
|
| 1522 | + |
|
| 1523 | + /** |
|
| 1524 | + * txn_registrant_side_meta_box |
|
| 1525 | + * generates HTML for the Edit Transaction side meta box |
|
| 1526 | + * |
|
| 1527 | + * @access public |
|
| 1528 | + * @return void |
|
| 1529 | + * @throws DomainException |
|
| 1530 | + * @throws EE_Error |
|
| 1531 | + * @throws InvalidArgumentException |
|
| 1532 | + * @throws InvalidDataTypeException |
|
| 1533 | + * @throws InvalidInterfaceException |
|
| 1534 | + * @throws ReflectionException |
|
| 1535 | + */ |
|
| 1536 | + public function txn_registrant_side_meta_box() |
|
| 1537 | + { |
|
| 1538 | + $primary_att = $this->_transaction->primary_registration() instanceof EE_Registration |
|
| 1539 | + ? $this->_transaction->primary_registration()->get_first_related('Attendee') |
|
| 1540 | + : null; |
|
| 1541 | + if (! $primary_att instanceof EE_Attendee) { |
|
| 1542 | + $this->_template_args['no_attendee_message'] = esc_html__( |
|
| 1543 | + 'There is no attached contact for this transaction. The transaction either failed due to an error or was abandoned.', |
|
| 1544 | + 'event_espresso' |
|
| 1545 | + ); |
|
| 1546 | + $primary_att = EEM_Attendee::instance()->create_default_object(); |
|
| 1547 | + } |
|
| 1548 | + $this->_template_args['ATT_ID'] = $primary_att->ID(); |
|
| 1549 | + $this->_template_args['prime_reg_fname'] = $primary_att->fname(); |
|
| 1550 | + $this->_template_args['prime_reg_lname'] = $primary_att->lname(); |
|
| 1551 | + $this->_template_args['prime_reg_email'] = $primary_att->email(); |
|
| 1552 | + $this->_template_args['prime_reg_phone'] = $primary_att->phone(); |
|
| 1553 | + $this->_template_args['edit_attendee_url'] = EE_Admin_Page::add_query_args_and_nonce( |
|
| 1554 | + array( |
|
| 1555 | + 'action' => 'edit_attendee', |
|
| 1556 | + 'post' => $primary_att->ID(), |
|
| 1557 | + ), |
|
| 1558 | + REG_ADMIN_URL |
|
| 1559 | + ); |
|
| 1560 | + // get formatted address for registrant |
|
| 1561 | + $this->_template_args['formatted_address'] = EEH_Address::format($primary_att); |
|
| 1562 | + echo EEH_Template::display_template( |
|
| 1563 | + TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_registrant.template.php', |
|
| 1564 | + $this->_template_args, |
|
| 1565 | + true |
|
| 1566 | + ); |
|
| 1567 | + } |
|
| 1568 | + |
|
| 1569 | + |
|
| 1570 | + /** |
|
| 1571 | + * txn_billing_info_side_meta_box |
|
| 1572 | + * generates HTML for the Edit Transaction side meta box |
|
| 1573 | + * |
|
| 1574 | + * @access public |
|
| 1575 | + * @return void |
|
| 1576 | + * @throws DomainException |
|
| 1577 | + * @throws EE_Error |
|
| 1578 | + */ |
|
| 1579 | + public function txn_billing_info_side_meta_box() |
|
| 1580 | + { |
|
| 1581 | + |
|
| 1582 | + $this->_template_args['billing_form'] = $this->_transaction->billing_info(); |
|
| 1583 | + $this->_template_args['billing_form_url'] = add_query_arg( |
|
| 1584 | + array('action' => 'edit_transaction', 'process' => 'billing'), |
|
| 1585 | + TXN_ADMIN_URL |
|
| 1586 | + ); |
|
| 1587 | + |
|
| 1588 | + $template_path = TXN_TEMPLATE_PATH . 'txn_admin_details_side_meta_box_billing_info.template.php'; |
|
| 1589 | + echo EEH_Template::display_template($template_path, $this->_template_args, true); |
|
| 1590 | + } |
|
| 1591 | + |
|
| 1592 | + |
|
| 1593 | + /** |
|
| 1594 | + * apply_payments_or_refunds |
|
| 1595 | + * registers a payment or refund made towards a transaction |
|
| 1596 | + * |
|
| 1597 | + * @access public |
|
| 1598 | + * @return void |
|
| 1599 | + * @throws EE_Error |
|
| 1600 | + * @throws InvalidArgumentException |
|
| 1601 | + * @throws ReflectionException |
|
| 1602 | + * @throws RuntimeException |
|
| 1603 | + * @throws InvalidDataTypeException |
|
| 1604 | + * @throws InvalidInterfaceException |
|
| 1605 | + */ |
|
| 1606 | + public function apply_payments_or_refunds() |
|
| 1607 | + { |
|
| 1608 | + $json_response_data = array('return_data' => false); |
|
| 1609 | + $valid_data = $this->_validate_payment_request_data(); |
|
| 1610 | + $has_access = EE_Registry::instance()->CAP->current_user_can( |
|
| 1611 | + 'ee_edit_payments', |
|
| 1612 | + 'apply_payment_or_refund_from_registration_details' |
|
| 1613 | + ); |
|
| 1614 | + if (! empty($valid_data) && $has_access) { |
|
| 1615 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1616 | + // save the new payment |
|
| 1617 | + $payment = $this->_create_payment_from_request_data($valid_data); |
|
| 1618 | + // get the TXN for this payment |
|
| 1619 | + $transaction = $payment->transaction(); |
|
| 1620 | + // verify transaction |
|
| 1621 | + if ($transaction instanceof EE_Transaction) { |
|
| 1622 | + // calculate_total_payments_and_update_status |
|
| 1623 | + $this->_process_transaction_payments($transaction); |
|
| 1624 | + $REG_IDs = $this->_get_REG_IDs_to_apply_payment_to($payment); |
|
| 1625 | + $this->_remove_existing_registration_payments($payment, $PAY_ID); |
|
| 1626 | + // apply payment to registrations (if applicable) |
|
| 1627 | + if (! empty($REG_IDs)) { |
|
| 1628 | + $this->_update_registration_payments($transaction, $payment, $REG_IDs); |
|
| 1629 | + $this->_maybe_send_notifications(); |
|
| 1630 | + // now process status changes for the same registrations |
|
| 1631 | + $this->_process_registration_status_change($transaction, $REG_IDs); |
|
| 1632 | + } |
|
| 1633 | + $this->_maybe_send_notifications($payment); |
|
| 1634 | + // prepare to render page |
|
| 1635 | + $json_response_data['return_data'] = $this->_build_payment_json_response($payment, $REG_IDs); |
|
| 1636 | + do_action( |
|
| 1637 | + 'AHEE__Transactions_Admin_Page__apply_payments_or_refund__after_recording', |
|
| 1638 | + $transaction, |
|
| 1639 | + $payment |
|
| 1640 | + ); |
|
| 1641 | + } else { |
|
| 1642 | + EE_Error::add_error( |
|
| 1643 | + esc_html__( |
|
| 1644 | + 'A valid Transaction for this payment could not be retrieved.', |
|
| 1645 | + 'event_espresso' |
|
| 1646 | + ), |
|
| 1647 | + __FILE__, |
|
| 1648 | + __FUNCTION__, |
|
| 1649 | + __LINE__ |
|
| 1650 | + ); |
|
| 1651 | + } |
|
| 1652 | + } elseif ($has_access) { |
|
| 1653 | + EE_Error::add_error( |
|
| 1654 | + esc_html__( |
|
| 1655 | + 'The payment form data could not be processed. Please try again.', |
|
| 1656 | + 'event_espresso' |
|
| 1657 | + ), |
|
| 1658 | + __FILE__, |
|
| 1659 | + __FUNCTION__, |
|
| 1660 | + __LINE__ |
|
| 1661 | + ); |
|
| 1662 | + } else { |
|
| 1663 | + EE_Error::add_error( |
|
| 1664 | + esc_html__( |
|
| 1665 | + 'You do not have access to apply payments or refunds to a registration.', |
|
| 1666 | + 'event_espresso' |
|
| 1667 | + ), |
|
| 1668 | + __FILE__, |
|
| 1669 | + __FUNCTION__, |
|
| 1670 | + __LINE__ |
|
| 1671 | + ); |
|
| 1672 | + } |
|
| 1673 | + $notices = EE_Error::get_notices( |
|
| 1674 | + false, |
|
| 1675 | + false, |
|
| 1676 | + false |
|
| 1677 | + ); |
|
| 1678 | + $this->_template_args = array( |
|
| 1679 | + 'data' => $json_response_data, |
|
| 1680 | + 'error' => $notices['errors'], |
|
| 1681 | + 'success' => $notices['success'], |
|
| 1682 | + ); |
|
| 1683 | + $this->_return_json(); |
|
| 1684 | + } |
|
| 1685 | + |
|
| 1686 | + |
|
| 1687 | + /** |
|
| 1688 | + * _validate_payment_request_data |
|
| 1689 | + * |
|
| 1690 | + * @return array |
|
| 1691 | + * @throws EE_Error |
|
| 1692 | + * @throws InvalidArgumentException |
|
| 1693 | + * @throws InvalidDataTypeException |
|
| 1694 | + * @throws InvalidInterfaceException |
|
| 1695 | + */ |
|
| 1696 | + protected function _validate_payment_request_data() |
|
| 1697 | + { |
|
| 1698 | + if (! isset($this->_req_data['txn_admin_payment'])) { |
|
| 1699 | + return array(); |
|
| 1700 | + } |
|
| 1701 | + $payment_form = $this->_generate_payment_form_section(); |
|
| 1702 | + try { |
|
| 1703 | + if ($payment_form->was_submitted()) { |
|
| 1704 | + $payment_form->receive_form_submission(); |
|
| 1705 | + if (! $payment_form->is_valid()) { |
|
| 1706 | + $submission_error_messages = array(); |
|
| 1707 | + foreach ($payment_form->get_validation_errors_accumulated() as $validation_error) { |
|
| 1708 | + if ($validation_error instanceof EE_Validation_Error) { |
|
| 1709 | + $submission_error_messages[] = sprintf( |
|
| 1710 | + _x('%s : %s', 'Form Section Name : Form Validation Error', 'event_espresso'), |
|
| 1711 | + $validation_error->get_form_section()->html_label_text(), |
|
| 1712 | + $validation_error->getMessage() |
|
| 1713 | + ); |
|
| 1714 | + } |
|
| 1715 | + } |
|
| 1716 | + EE_Error::add_error( |
|
| 1717 | + implode('<br />', $submission_error_messages), |
|
| 1718 | + __FILE__, |
|
| 1719 | + __FUNCTION__, |
|
| 1720 | + __LINE__ |
|
| 1721 | + ); |
|
| 1722 | + return array(); |
|
| 1723 | + } |
|
| 1724 | + } |
|
| 1725 | + } catch (EE_Error $e) { |
|
| 1726 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
| 1727 | + return array(); |
|
| 1728 | + } |
|
| 1729 | + |
|
| 1730 | + return $payment_form->valid_data(); |
|
| 1731 | + } |
|
| 1732 | + |
|
| 1733 | + |
|
| 1734 | + /** |
|
| 1735 | + * _generate_payment_form_section |
|
| 1736 | + * |
|
| 1737 | + * @return EE_Form_Section_Proper |
|
| 1738 | + * @throws EE_Error |
|
| 1739 | + */ |
|
| 1740 | + protected function _generate_payment_form_section() |
|
| 1741 | + { |
|
| 1742 | + return new EE_Form_Section_Proper( |
|
| 1743 | + array( |
|
| 1744 | + 'name' => 'txn_admin_payment', |
|
| 1745 | + 'subsections' => array( |
|
| 1746 | + 'PAY_ID' => new EE_Text_Input( |
|
| 1747 | + array( |
|
| 1748 | + 'default' => 0, |
|
| 1749 | + 'required' => false, |
|
| 1750 | + 'html_label_text' => esc_html__('Payment ID', 'event_espresso'), |
|
| 1751 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1752 | + ) |
|
| 1753 | + ), |
|
| 1754 | + 'TXN_ID' => new EE_Text_Input( |
|
| 1755 | + array( |
|
| 1756 | + 'default' => 0, |
|
| 1757 | + 'required' => true, |
|
| 1758 | + 'html_label_text' => esc_html__('Transaction ID', 'event_espresso'), |
|
| 1759 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1760 | + ) |
|
| 1761 | + ), |
|
| 1762 | + 'type' => new EE_Text_Input( |
|
| 1763 | + array( |
|
| 1764 | + 'default' => 1, |
|
| 1765 | + 'required' => true, |
|
| 1766 | + 'html_label_text' => esc_html__('Payment or Refund', 'event_espresso'), |
|
| 1767 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1768 | + ) |
|
| 1769 | + ), |
|
| 1770 | + 'amount' => new EE_Text_Input( |
|
| 1771 | + array( |
|
| 1772 | + 'default' => 0, |
|
| 1773 | + 'required' => true, |
|
| 1774 | + 'html_label_text' => esc_html__('Payment amount', 'event_espresso'), |
|
| 1775 | + 'validation_strategies' => array(new EE_Float_Normalization()), |
|
| 1776 | + ) |
|
| 1777 | + ), |
|
| 1778 | + 'status' => new EE_Text_Input( |
|
| 1779 | + array( |
|
| 1780 | + 'default' => EEM_Payment::status_id_approved, |
|
| 1781 | + 'required' => true, |
|
| 1782 | + 'html_label_text' => esc_html__('Payment status', 'event_espresso'), |
|
| 1783 | + ) |
|
| 1784 | + ), |
|
| 1785 | + 'PMD_ID' => new EE_Text_Input( |
|
| 1786 | + array( |
|
| 1787 | + 'default' => 2, |
|
| 1788 | + 'required' => true, |
|
| 1789 | + 'html_label_text' => esc_html__('Payment Method', 'event_espresso'), |
|
| 1790 | + 'validation_strategies' => array(new EE_Int_Normalization()), |
|
| 1791 | + ) |
|
| 1792 | + ), |
|
| 1793 | + 'date' => new EE_Text_Input( |
|
| 1794 | + array( |
|
| 1795 | + 'default' => time(), |
|
| 1796 | + 'required' => true, |
|
| 1797 | + 'html_label_text' => esc_html__('Payment date', 'event_espresso'), |
|
| 1798 | + ) |
|
| 1799 | + ), |
|
| 1800 | + 'txn_id_chq_nmbr' => new EE_Text_Input( |
|
| 1801 | + array( |
|
| 1802 | + 'default' => '', |
|
| 1803 | + 'required' => false, |
|
| 1804 | + 'html_label_text' => esc_html__('Transaction or Cheque Number', 'event_espresso'), |
|
| 1805 | + 'validation_strategies' => array( |
|
| 1806 | + new EE_Max_Length_Validation_Strategy( |
|
| 1807 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1808 | + 100 |
|
| 1809 | + ), |
|
| 1810 | + ), |
|
| 1811 | + ) |
|
| 1812 | + ), |
|
| 1813 | + 'po_number' => new EE_Text_Input( |
|
| 1814 | + array( |
|
| 1815 | + 'default' => '', |
|
| 1816 | + 'required' => false, |
|
| 1817 | + 'html_label_text' => esc_html__('Purchase Order Number', 'event_espresso'), |
|
| 1818 | + 'validation_strategies' => array( |
|
| 1819 | + new EE_Max_Length_Validation_Strategy( |
|
| 1820 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1821 | + 100 |
|
| 1822 | + ), |
|
| 1823 | + ), |
|
| 1824 | + ) |
|
| 1825 | + ), |
|
| 1826 | + 'accounting' => new EE_Text_Input( |
|
| 1827 | + array( |
|
| 1828 | + 'default' => '', |
|
| 1829 | + 'required' => false, |
|
| 1830 | + 'html_label_text' => esc_html__('Extra Field for Accounting', 'event_espresso'), |
|
| 1831 | + 'validation_strategies' => array( |
|
| 1832 | + new EE_Max_Length_Validation_Strategy( |
|
| 1833 | + esc_html__('Input too long', 'event_espresso'), |
|
| 1834 | + 100 |
|
| 1835 | + ), |
|
| 1836 | + ), |
|
| 1837 | + ) |
|
| 1838 | + ), |
|
| 1839 | + ), |
|
| 1840 | + ) |
|
| 1841 | + ); |
|
| 1842 | + } |
|
| 1843 | + |
|
| 1844 | + |
|
| 1845 | + /** |
|
| 1846 | + * _create_payment_from_request_data |
|
| 1847 | + * |
|
| 1848 | + * @param array $valid_data |
|
| 1849 | + * @return EE_Payment |
|
| 1850 | + * @throws EE_Error |
|
| 1851 | + * @throws InvalidArgumentException |
|
| 1852 | + * @throws InvalidDataTypeException |
|
| 1853 | + * @throws InvalidInterfaceException |
|
| 1854 | + * @throws ReflectionException |
|
| 1855 | + */ |
|
| 1856 | + protected function _create_payment_from_request_data($valid_data) |
|
| 1857 | + { |
|
| 1858 | + $PAY_ID = $valid_data['PAY_ID']; |
|
| 1859 | + // get payment amount |
|
| 1860 | + $amount = $valid_data['amount'] ? abs($valid_data['amount']) : 0; |
|
| 1861 | + // payments have a type value of 1 and refunds have a type value of -1 |
|
| 1862 | + // so multiplying amount by type will give a positive value for payments, and negative values for refunds |
|
| 1863 | + $amount = $valid_data['type'] < 0 ? $amount * -1 : $amount; |
|
| 1864 | + // for some reason the date string coming in has extra spaces between the date and time. This fixes that. |
|
| 1865 | + $date = $valid_data['date'] |
|
| 1866 | + ? preg_replace('/\s+/', ' ', $valid_data['date']) |
|
| 1867 | + : date('Y-m-d g:i a', current_time('timestamp')); |
|
| 1868 | + $payment = EE_Payment::new_instance( |
|
| 1869 | + array( |
|
| 1870 | + 'TXN_ID' => $valid_data['TXN_ID'], |
|
| 1871 | + 'STS_ID' => $valid_data['status'], |
|
| 1872 | + 'PAY_timestamp' => $date, |
|
| 1873 | + 'PAY_source' => EEM_Payment_Method::scope_admin, |
|
| 1874 | + 'PMD_ID' => $valid_data['PMD_ID'], |
|
| 1875 | + 'PAY_amount' => $amount, |
|
| 1876 | + 'PAY_txn_id_chq_nmbr' => $valid_data['txn_id_chq_nmbr'], |
|
| 1877 | + 'PAY_po_number' => $valid_data['po_number'], |
|
| 1878 | + 'PAY_extra_accntng' => $valid_data['accounting'], |
|
| 1879 | + 'PAY_details' => $valid_data, |
|
| 1880 | + 'PAY_ID' => $PAY_ID, |
|
| 1881 | + ), |
|
| 1882 | + '', |
|
| 1883 | + array('Y-m-d', 'g:i a') |
|
| 1884 | + ); |
|
| 1885 | + |
|
| 1886 | + if (! $payment->save()) { |
|
| 1887 | + EE_Error::add_error( |
|
| 1888 | + sprintf( |
|
| 1889 | + esc_html__('Payment %1$d has not been successfully saved to the database.', 'event_espresso'), |
|
| 1890 | + $payment->ID() |
|
| 1891 | + ), |
|
| 1892 | + __FILE__, |
|
| 1893 | + __FUNCTION__, |
|
| 1894 | + __LINE__ |
|
| 1895 | + ); |
|
| 1896 | + } |
|
| 1897 | + |
|
| 1898 | + return $payment; |
|
| 1899 | + } |
|
| 1900 | + |
|
| 1901 | + |
|
| 1902 | + /** |
|
| 1903 | + * _process_transaction_payments |
|
| 1904 | + * |
|
| 1905 | + * @param \EE_Transaction $transaction |
|
| 1906 | + * @return void |
|
| 1907 | + * @throws EE_Error |
|
| 1908 | + * @throws InvalidArgumentException |
|
| 1909 | + * @throws ReflectionException |
|
| 1910 | + * @throws InvalidDataTypeException |
|
| 1911 | + * @throws InvalidInterfaceException |
|
| 1912 | + */ |
|
| 1913 | + protected function _process_transaction_payments(EE_Transaction $transaction) |
|
| 1914 | + { |
|
| 1915 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 1916 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 1917 | + // update the transaction with this payment |
|
| 1918 | + if ($transaction_payments->calculate_total_payments_and_update_status($transaction)) { |
|
| 1919 | + EE_Error::add_success( |
|
| 1920 | + esc_html__( |
|
| 1921 | + 'The payment has been processed successfully.', |
|
| 1922 | + 'event_espresso' |
|
| 1923 | + ), |
|
| 1924 | + __FILE__, |
|
| 1925 | + __FUNCTION__, |
|
| 1926 | + __LINE__ |
|
| 1927 | + ); |
|
| 1928 | + } else { |
|
| 1929 | + EE_Error::add_error( |
|
| 1930 | + esc_html__( |
|
| 1931 | + 'The payment was processed successfully but the amount paid for the transaction was not updated.', |
|
| 1932 | + 'event_espresso' |
|
| 1933 | + ), |
|
| 1934 | + __FILE__, |
|
| 1935 | + __FUNCTION__, |
|
| 1936 | + __LINE__ |
|
| 1937 | + ); |
|
| 1938 | + } |
|
| 1939 | + } |
|
| 1940 | + |
|
| 1941 | + |
|
| 1942 | + /** |
|
| 1943 | + * _get_REG_IDs_to_apply_payment_to |
|
| 1944 | + * returns a list of registration IDs that the payment will apply to |
|
| 1945 | + * |
|
| 1946 | + * @param \EE_Payment $payment |
|
| 1947 | + * @return array |
|
| 1948 | + * @throws EE_Error |
|
| 1949 | + * @throws InvalidArgumentException |
|
| 1950 | + * @throws InvalidDataTypeException |
|
| 1951 | + * @throws InvalidInterfaceException |
|
| 1952 | + * @throws ReflectionException |
|
| 1953 | + */ |
|
| 1954 | + protected function _get_REG_IDs_to_apply_payment_to(EE_Payment $payment) |
|
| 1955 | + { |
|
| 1956 | + $REG_IDs = array(); |
|
| 1957 | + // grab array of IDs for specific registrations to apply changes to |
|
| 1958 | + if (isset($this->_req_data['txn_admin_payment']['registrations'])) { |
|
| 1959 | + $REG_IDs = (array) $this->_req_data['txn_admin_payment']['registrations']; |
|
| 1960 | + } |
|
| 1961 | + // nothing specified ? then get all reg IDs |
|
| 1962 | + if (empty($REG_IDs)) { |
|
| 1963 | + $registrations = $payment->transaction()->registrations(); |
|
| 1964 | + $REG_IDs = ! empty($registrations) |
|
| 1965 | + ? array_keys($registrations) |
|
| 1966 | + : $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 1967 | + } |
|
| 1968 | + |
|
| 1969 | + // ensure that REG_IDs are integers and NOT strings |
|
| 1970 | + return array_map('intval', $REG_IDs); |
|
| 1971 | + } |
|
| 1972 | + |
|
| 1973 | + |
|
| 1974 | + /** |
|
| 1975 | + * @return array |
|
| 1976 | + */ |
|
| 1977 | + public function existing_reg_payment_REG_IDs() |
|
| 1978 | + { |
|
| 1979 | + return $this->_existing_reg_payment_REG_IDs; |
|
| 1980 | + } |
|
| 1981 | + |
|
| 1982 | + |
|
| 1983 | + /** |
|
| 1984 | + * @param array $existing_reg_payment_REG_IDs |
|
| 1985 | + */ |
|
| 1986 | + public function set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs = null) |
|
| 1987 | + { |
|
| 1988 | + $this->_existing_reg_payment_REG_IDs = $existing_reg_payment_REG_IDs; |
|
| 1989 | + } |
|
| 1990 | + |
|
| 1991 | + |
|
| 1992 | + /** |
|
| 1993 | + * _get_existing_reg_payment_REG_IDs |
|
| 1994 | + * returns a list of registration IDs that the payment is currently related to |
|
| 1995 | + * as recorded in the database |
|
| 1996 | + * |
|
| 1997 | + * @param \EE_Payment $payment |
|
| 1998 | + * @return array |
|
| 1999 | + * @throws EE_Error |
|
| 2000 | + * @throws InvalidArgumentException |
|
| 2001 | + * @throws InvalidDataTypeException |
|
| 2002 | + * @throws InvalidInterfaceException |
|
| 2003 | + * @throws ReflectionException |
|
| 2004 | + */ |
|
| 2005 | + protected function _get_existing_reg_payment_REG_IDs(EE_Payment $payment) |
|
| 2006 | + { |
|
| 2007 | + if ($this->existing_reg_payment_REG_IDs() === null) { |
|
| 2008 | + // let's get any existing reg payment records for this payment |
|
| 2009 | + $existing_reg_payment_REG_IDs = $payment->get_many_related('Registration'); |
|
| 2010 | + // but we only want the REG IDs, so grab the array keys |
|
| 2011 | + $existing_reg_payment_REG_IDs = ! empty($existing_reg_payment_REG_IDs) |
|
| 2012 | + ? array_keys($existing_reg_payment_REG_IDs) |
|
| 2013 | + : array(); |
|
| 2014 | + $this->set_existing_reg_payment_REG_IDs($existing_reg_payment_REG_IDs); |
|
| 2015 | + } |
|
| 2016 | + |
|
| 2017 | + return $this->existing_reg_payment_REG_IDs(); |
|
| 2018 | + } |
|
| 2019 | + |
|
| 2020 | + |
|
| 2021 | + /** |
|
| 2022 | + * _remove_existing_registration_payments |
|
| 2023 | + * this calculates the difference between existing relations |
|
| 2024 | + * to the supplied payment and the new list registration IDs, |
|
| 2025 | + * removes any related registrations that no longer apply, |
|
| 2026 | + * and then updates the registration paid fields |
|
| 2027 | + * |
|
| 2028 | + * @param \EE_Payment $payment |
|
| 2029 | + * @param int $PAY_ID |
|
| 2030 | + * @return bool; |
|
| 2031 | + * @throws EE_Error |
|
| 2032 | + * @throws InvalidArgumentException |
|
| 2033 | + * @throws ReflectionException |
|
| 2034 | + * @throws InvalidDataTypeException |
|
| 2035 | + * @throws InvalidInterfaceException |
|
| 2036 | + */ |
|
| 2037 | + protected function _remove_existing_registration_payments(EE_Payment $payment, $PAY_ID = 0) |
|
| 2038 | + { |
|
| 2039 | + // newly created payments will have nothing recorded for $PAY_ID |
|
| 2040 | + if (absint($PAY_ID) === 0) { |
|
| 2041 | + return false; |
|
| 2042 | + } |
|
| 2043 | + $existing_reg_payment_REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2044 | + if (empty($existing_reg_payment_REG_IDs)) { |
|
| 2045 | + return false; |
|
| 2046 | + } |
|
| 2047 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2048 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2049 | + |
|
| 2050 | + return $transaction_payments->delete_registration_payments_and_update_registrations( |
|
| 2051 | + $payment, |
|
| 2052 | + array( |
|
| 2053 | + array( |
|
| 2054 | + 'PAY_ID' => $payment->ID(), |
|
| 2055 | + 'REG_ID' => array('IN', $existing_reg_payment_REG_IDs), |
|
| 2056 | + ), |
|
| 2057 | + ) |
|
| 2058 | + ); |
|
| 2059 | + } |
|
| 2060 | + |
|
| 2061 | + |
|
| 2062 | + /** |
|
| 2063 | + * _update_registration_payments |
|
| 2064 | + * this applies the payments to the selected registrations |
|
| 2065 | + * but only if they have not already been paid for |
|
| 2066 | + * |
|
| 2067 | + * @param EE_Transaction $transaction |
|
| 2068 | + * @param \EE_Payment $payment |
|
| 2069 | + * @param array $REG_IDs |
|
| 2070 | + * @return void |
|
| 2071 | + * @throws EE_Error |
|
| 2072 | + * @throws InvalidArgumentException |
|
| 2073 | + * @throws ReflectionException |
|
| 2074 | + * @throws RuntimeException |
|
| 2075 | + * @throws InvalidDataTypeException |
|
| 2076 | + * @throws InvalidInterfaceException |
|
| 2077 | + */ |
|
| 2078 | + protected function _update_registration_payments( |
|
| 2079 | + EE_Transaction $transaction, |
|
| 2080 | + EE_Payment $payment, |
|
| 2081 | + $REG_IDs = array() |
|
| 2082 | + ) { |
|
| 2083 | + // we can pass our own custom set of registrations to EE_Payment_Processor::process_registration_payments() |
|
| 2084 | + // so let's do that using our set of REG_IDs from the form |
|
| 2085 | + $registration_query_where_params = array( |
|
| 2086 | + 'REG_ID' => array('IN', $REG_IDs), |
|
| 2087 | + ); |
|
| 2088 | + // but add in some conditions regarding payment, |
|
| 2089 | + // so that we don't apply payments to registrations that are free or have already been paid for |
|
| 2090 | + // but ONLY if the payment is NOT a refund ( ie: the payment amount is not negative ) |
|
| 2091 | + if (! $payment->is_a_refund()) { |
|
| 2092 | + $registration_query_where_params['REG_final_price'] = array('!=', 0); |
|
| 2093 | + $registration_query_where_params['REG_final_price*'] = array('!=', 'REG_paid', true); |
|
| 2094 | + } |
|
| 2095 | + $registrations = $transaction->registrations(array($registration_query_where_params)); |
|
| 2096 | + if (! empty($registrations)) { |
|
| 2097 | + /** @type EE_Payment_Processor $payment_processor */ |
|
| 2098 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
| 2099 | + $payment_processor->process_registration_payments($transaction, $payment, $registrations); |
|
| 2100 | + } |
|
| 2101 | + } |
|
| 2102 | + |
|
| 2103 | + |
|
| 2104 | + /** |
|
| 2105 | + * _process_registration_status_change |
|
| 2106 | + * This processes requested registration status changes for all the registrations |
|
| 2107 | + * on a given transaction and (optionally) sends out notifications for the changes. |
|
| 2108 | + * |
|
| 2109 | + * @param EE_Transaction $transaction |
|
| 2110 | + * @param array $REG_IDs |
|
| 2111 | + * @return bool |
|
| 2112 | + * @throws EE_Error |
|
| 2113 | + * @throws InvalidArgumentException |
|
| 2114 | + * @throws ReflectionException |
|
| 2115 | + * @throws InvalidDataTypeException |
|
| 2116 | + * @throws InvalidInterfaceException |
|
| 2117 | + */ |
|
| 2118 | + protected function _process_registration_status_change(EE_Transaction $transaction, $REG_IDs = array()) |
|
| 2119 | + { |
|
| 2120 | + // first if there is no change in status then we get out. |
|
| 2121 | + if (! isset($this->_req_data['txn_reg_status_change']['reg_status']) |
|
| 2122 | + || $this->_req_data['txn_reg_status_change']['reg_status'] === 'NAN' |
|
| 2123 | + ) { |
|
| 2124 | + // no error message, no change requested, just nothing to do man. |
|
| 2125 | + return false; |
|
| 2126 | + } |
|
| 2127 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 2128 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 2129 | + |
|
| 2130 | + // made it here dude? Oh WOW. K, let's take care of changing the statuses |
|
| 2131 | + return $transaction_processor->manually_update_registration_statuses( |
|
| 2132 | + $transaction, |
|
| 2133 | + sanitize_text_field($this->_req_data['txn_reg_status_change']['reg_status']), |
|
| 2134 | + array(array('REG_ID' => array('IN', $REG_IDs))) |
|
| 2135 | + ); |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + |
|
| 2139 | + /** |
|
| 2140 | + * _build_payment_json_response |
|
| 2141 | + * |
|
| 2142 | + * @access public |
|
| 2143 | + * @param \EE_Payment $payment |
|
| 2144 | + * @param array $REG_IDs |
|
| 2145 | + * @param bool | null $delete_txn_reg_status_change |
|
| 2146 | + * @return array |
|
| 2147 | + * @throws EE_Error |
|
| 2148 | + * @throws InvalidArgumentException |
|
| 2149 | + * @throws InvalidDataTypeException |
|
| 2150 | + * @throws InvalidInterfaceException |
|
| 2151 | + * @throws ReflectionException |
|
| 2152 | + */ |
|
| 2153 | + protected function _build_payment_json_response( |
|
| 2154 | + EE_Payment $payment, |
|
| 2155 | + $REG_IDs = array(), |
|
| 2156 | + $delete_txn_reg_status_change = null |
|
| 2157 | + ) { |
|
| 2158 | + // was the payment deleted ? |
|
| 2159 | + if (is_bool($delete_txn_reg_status_change)) { |
|
| 2160 | + return array( |
|
| 2161 | + 'PAY_ID' => $payment->ID(), |
|
| 2162 | + 'amount' => $payment->amount(), |
|
| 2163 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 2164 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2165 | + 'pay_status' => $payment->STS_ID(), |
|
| 2166 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2167 | + 'delete_txn_reg_status_change' => $delete_txn_reg_status_change, |
|
| 2168 | + ); |
|
| 2169 | + } else { |
|
| 2170 | + $this->_get_payment_status_array(); |
|
| 2171 | + |
|
| 2172 | + return array( |
|
| 2173 | + 'amount' => $payment->amount(), |
|
| 2174 | + 'total_paid' => $payment->transaction()->paid(), |
|
| 2175 | + 'txn_status' => $payment->transaction()->status_ID(), |
|
| 2176 | + 'pay_status' => $payment->STS_ID(), |
|
| 2177 | + 'PAY_ID' => $payment->ID(), |
|
| 2178 | + 'STS_ID' => $payment->STS_ID(), |
|
| 2179 | + 'status' => self::$_pay_status[ $payment->STS_ID() ], |
|
| 2180 | + 'date' => $payment->timestamp('Y-m-d', 'h:i a'), |
|
| 2181 | + 'method' => strtoupper($payment->source()), |
|
| 2182 | + 'PM_ID' => $payment->payment_method() ? $payment->payment_method()->ID() : 1, |
|
| 2183 | + 'gateway' => $payment->payment_method() |
|
| 2184 | + ? $payment->payment_method()->admin_name() |
|
| 2185 | + : esc_html__('Unknown', 'event_espresso'), |
|
| 2186 | + 'gateway_response' => $payment->gateway_response(), |
|
| 2187 | + 'txn_id_chq_nmbr' => $payment->txn_id_chq_nmbr(), |
|
| 2188 | + 'po_number' => $payment->po_number(), |
|
| 2189 | + 'extra_accntng' => $payment->extra_accntng(), |
|
| 2190 | + 'registrations' => $this->_registration_payment_data_array($REG_IDs), |
|
| 2191 | + ); |
|
| 2192 | + } |
|
| 2193 | + } |
|
| 2194 | + |
|
| 2195 | + |
|
| 2196 | + /** |
|
| 2197 | + * delete_payment |
|
| 2198 | + * delete a payment or refund made towards a transaction |
|
| 2199 | + * |
|
| 2200 | + * @access public |
|
| 2201 | + * @return void |
|
| 2202 | + * @throws EE_Error |
|
| 2203 | + * @throws InvalidArgumentException |
|
| 2204 | + * @throws ReflectionException |
|
| 2205 | + * @throws InvalidDataTypeException |
|
| 2206 | + * @throws InvalidInterfaceException |
|
| 2207 | + */ |
|
| 2208 | + public function delete_payment() |
|
| 2209 | + { |
|
| 2210 | + $json_response_data = array('return_data' => false); |
|
| 2211 | + $PAY_ID = isset($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2212 | + ? absint($this->_req_data['delete_txn_admin_payment']['PAY_ID']) |
|
| 2213 | + : 0; |
|
| 2214 | + $can_delete = EE_Registry::instance()->CAP->current_user_can( |
|
| 2215 | + 'ee_delete_payments', |
|
| 2216 | + 'delete_payment_from_registration_details' |
|
| 2217 | + ); |
|
| 2218 | + if ($PAY_ID && $can_delete) { |
|
| 2219 | + $delete_txn_reg_status_change = isset($this->_req_data['delete_txn_reg_status_change']) |
|
| 2220 | + ? $this->_req_data['delete_txn_reg_status_change'] |
|
| 2221 | + : false; |
|
| 2222 | + $payment = EEM_Payment::instance()->get_one_by_ID($PAY_ID); |
|
| 2223 | + if ($payment instanceof EE_Payment) { |
|
| 2224 | + $REG_IDs = $this->_get_existing_reg_payment_REG_IDs($payment); |
|
| 2225 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
| 2226 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
| 2227 | + if ($transaction_payments->delete_payment_and_update_transaction($payment)) { |
|
| 2228 | + $json_response_data['return_data'] = $this->_build_payment_json_response( |
|
| 2229 | + $payment, |
|
| 2230 | + $REG_IDs, |
|
| 2231 | + $delete_txn_reg_status_change |
|
| 2232 | + ); |
|
| 2233 | + if ($delete_txn_reg_status_change) { |
|
| 2234 | + $this->_req_data['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2235 | + // MAKE sure we also add the delete_txn_req_status_change to the |
|
| 2236 | + // $_REQUEST global because that's how messages will be looking for it. |
|
| 2237 | + $_REQUEST['txn_reg_status_change'] = $delete_txn_reg_status_change; |
|
| 2238 | + $this->_maybe_send_notifications(); |
|
| 2239 | + $this->_process_registration_status_change($payment->transaction(), $REG_IDs); |
|
| 2240 | + } |
|
| 2241 | + } |
|
| 2242 | + } else { |
|
| 2243 | + EE_Error::add_error( |
|
| 2244 | + esc_html__('Valid Payment data could not be retrieved from the database.', 'event_espresso'), |
|
| 2245 | + __FILE__, |
|
| 2246 | + __FUNCTION__, |
|
| 2247 | + __LINE__ |
|
| 2248 | + ); |
|
| 2249 | + } |
|
| 2250 | + } elseif ($can_delete) { |
|
| 2251 | + EE_Error::add_error( |
|
| 2252 | + esc_html__( |
|
| 2253 | + 'A valid Payment ID was not received, therefore payment form data could not be loaded.', |
|
| 2254 | + 'event_espresso' |
|
| 2255 | + ), |
|
| 2256 | + __FILE__, |
|
| 2257 | + __FUNCTION__, |
|
| 2258 | + __LINE__ |
|
| 2259 | + ); |
|
| 2260 | + } else { |
|
| 2261 | + EE_Error::add_error( |
|
| 2262 | + esc_html__( |
|
| 2263 | + 'You do not have access to delete a payment.', |
|
| 2264 | + 'event_espresso' |
|
| 2265 | + ), |
|
| 2266 | + __FILE__, |
|
| 2267 | + __FUNCTION__, |
|
| 2268 | + __LINE__ |
|
| 2269 | + ); |
|
| 2270 | + } |
|
| 2271 | + $notices = EE_Error::get_notices(false, false, false); |
|
| 2272 | + $this->_template_args = array( |
|
| 2273 | + 'data' => $json_response_data, |
|
| 2274 | + 'success' => $notices['success'], |
|
| 2275 | + 'error' => $notices['errors'], |
|
| 2276 | + 'attention' => $notices['attention'], |
|
| 2277 | + ); |
|
| 2278 | + $this->_return_json(); |
|
| 2279 | + } |
|
| 2280 | + |
|
| 2281 | + |
|
| 2282 | + /** |
|
| 2283 | + * _registration_payment_data_array |
|
| 2284 | + * adds info for 'owing' and 'paid' for each registration to the json response |
|
| 2285 | + * |
|
| 2286 | + * @access protected |
|
| 2287 | + * @param array $REG_IDs |
|
| 2288 | + * @return array |
|
| 2289 | + * @throws EE_Error |
|
| 2290 | + * @throws InvalidArgumentException |
|
| 2291 | + * @throws InvalidDataTypeException |
|
| 2292 | + * @throws InvalidInterfaceException |
|
| 2293 | + * @throws ReflectionException |
|
| 2294 | + */ |
|
| 2295 | + protected function _registration_payment_data_array($REG_IDs) |
|
| 2296 | + { |
|
| 2297 | + $registration_payment_data = array(); |
|
| 2298 | + // if non empty reg_ids lets get an array of registrations and update the values for the apply_payment/refund rows. |
|
| 2299 | + if (! empty($REG_IDs)) { |
|
| 2300 | + $registrations = EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $REG_IDs)))); |
|
| 2301 | + foreach ($registrations as $registration) { |
|
| 2302 | + if ($registration instanceof EE_Registration) { |
|
| 2303 | + $registration_payment_data[ $registration->ID() ] = array( |
|
| 2304 | + 'paid' => $registration->pretty_paid(), |
|
| 2305 | + 'owing' => EEH_Template::format_currency($registration->final_price() - $registration->paid()), |
|
| 2306 | + ); |
|
| 2307 | + } |
|
| 2308 | + } |
|
| 2309 | + } |
|
| 2310 | + |
|
| 2311 | + return $registration_payment_data; |
|
| 2312 | + } |
|
| 2313 | + |
|
| 2314 | + |
|
| 2315 | + /** |
|
| 2316 | + * _maybe_send_notifications |
|
| 2317 | + * determines whether or not the admin has indicated that notifications should be sent. |
|
| 2318 | + * If so, will toggle a filter switch for delivering registration notices. |
|
| 2319 | + * If passed an EE_Payment object, then it will trigger payment notifications instead. |
|
| 2320 | + * |
|
| 2321 | + * @access protected |
|
| 2322 | + * @param \EE_Payment | null $payment |
|
| 2323 | + */ |
|
| 2324 | + protected function _maybe_send_notifications($payment = null) |
|
| 2325 | + { |
|
| 2326 | + switch ($payment instanceof EE_Payment) { |
|
| 2327 | + // payment notifications |
|
| 2328 | + case true: |
|
| 2329 | + if (isset($this->_req_data['txn_payments']['send_notifications']) |
|
| 2330 | + && filter_var( |
|
| 2331 | + $this->_req_data['txn_payments']['send_notifications'], |
|
| 2332 | + FILTER_VALIDATE_BOOLEAN |
|
| 2333 | + ) |
|
| 2334 | + ) { |
|
| 2335 | + $this->_process_payment_notification($payment); |
|
| 2336 | + } |
|
| 2337 | + break; |
|
| 2338 | + // registration notifications |
|
| 2339 | + case false: |
|
| 2340 | + if (isset($this->_req_data['txn_reg_status_change']['send_notifications']) |
|
| 2341 | + && filter_var( |
|
| 2342 | + $this->_req_data['txn_reg_status_change']['send_notifications'], |
|
| 2343 | + FILTER_VALIDATE_BOOLEAN |
|
| 2344 | + ) |
|
| 2345 | + ) { |
|
| 2346 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
| 2347 | + } |
|
| 2348 | + break; |
|
| 2349 | + } |
|
| 2350 | + } |
|
| 2351 | + |
|
| 2352 | + |
|
| 2353 | + /** |
|
| 2354 | + * _send_payment_reminder |
|
| 2355 | + * generates HTML for the View Transaction Details Admin page |
|
| 2356 | + * |
|
| 2357 | + * @access protected |
|
| 2358 | + * @return void |
|
| 2359 | + * @throws EE_Error |
|
| 2360 | + * @throws InvalidArgumentException |
|
| 2361 | + * @throws InvalidDataTypeException |
|
| 2362 | + * @throws InvalidInterfaceException |
|
| 2363 | + */ |
|
| 2364 | + protected function _send_payment_reminder() |
|
| 2365 | + { |
|
| 2366 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2367 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2368 | + $query_args = isset($this->_req_data['redirect_to']) ? array( |
|
| 2369 | + 'action' => $this->_req_data['redirect_to'], |
|
| 2370 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2371 | + ) : array(); |
|
| 2372 | + do_action( |
|
| 2373 | + 'AHEE__Transactions_Admin_Page___send_payment_reminder__process_admin_payment_reminder', |
|
| 2374 | + $transaction |
|
| 2375 | + ); |
|
| 2376 | + $this->_redirect_after_action( |
|
| 2377 | + false, |
|
| 2378 | + esc_html__('payment reminder', 'event_espresso'), |
|
| 2379 | + esc_html__('sent', 'event_espresso'), |
|
| 2380 | + $query_args, |
|
| 2381 | + true |
|
| 2382 | + ); |
|
| 2383 | + } |
|
| 2384 | + |
|
| 2385 | + |
|
| 2386 | + /** |
|
| 2387 | + * get_transactions |
|
| 2388 | + * get transactions for given parameters (used by list table) |
|
| 2389 | + * |
|
| 2390 | + * @param int $perpage how many transactions displayed per page |
|
| 2391 | + * @param boolean $count return the count or objects |
|
| 2392 | + * @param string $view |
|
| 2393 | + * @return mixed int = count || array of transaction objects |
|
| 2394 | + * @throws EE_Error |
|
| 2395 | + * @throws InvalidArgumentException |
|
| 2396 | + * @throws InvalidDataTypeException |
|
| 2397 | + * @throws InvalidInterfaceException |
|
| 2398 | + */ |
|
| 2399 | + public function get_transactions($perpage, $count = false, $view = '') |
|
| 2400 | + { |
|
| 2401 | + |
|
| 2402 | + $TXN = EEM_Transaction::instance(); |
|
| 2403 | + |
|
| 2404 | + $start_date = isset($this->_req_data['txn-filter-start-date']) |
|
| 2405 | + ? wp_strip_all_tags($this->_req_data['txn-filter-start-date']) |
|
| 2406 | + : date( |
|
| 2407 | + 'm/d/Y', |
|
| 2408 | + strtotime('-10 year') |
|
| 2409 | + ); |
|
| 2410 | + $end_date = isset($this->_req_data['txn-filter-end-date']) |
|
| 2411 | + ? wp_strip_all_tags($this->_req_data['txn-filter-end-date']) |
|
| 2412 | + : date('m/d/Y'); |
|
| 2413 | + |
|
| 2414 | + // make sure our timestamps start and end right at the boundaries for each day |
|
| 2415 | + $start_date = date('Y-m-d', strtotime($start_date)) . ' 00:00:00'; |
|
| 2416 | + $end_date = date('Y-m-d', strtotime($end_date)) . ' 23:59:59'; |
|
| 2417 | + |
|
| 2418 | + |
|
| 2419 | + // convert to timestamps |
|
| 2420 | + $start_date = strtotime($start_date); |
|
| 2421 | + $end_date = strtotime($end_date); |
|
| 2422 | + |
|
| 2423 | + // makes sure start date is the lowest value and vice versa |
|
| 2424 | + $start_date = min($start_date, $end_date); |
|
| 2425 | + $end_date = max($start_date, $end_date); |
|
| 2426 | + |
|
| 2427 | + // convert to correct format for query |
|
| 2428 | + $start_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2429 | + 'TXN_timestamp', |
|
| 2430 | + date('Y-m-d H:i:s', $start_date), |
|
| 2431 | + 'Y-m-d H:i:s' |
|
| 2432 | + ); |
|
| 2433 | + $end_date = EEM_Transaction::instance()->convert_datetime_for_query( |
|
| 2434 | + 'TXN_timestamp', |
|
| 2435 | + date('Y-m-d H:i:s', $end_date), |
|
| 2436 | + 'Y-m-d H:i:s' |
|
| 2437 | + ); |
|
| 2438 | + |
|
| 2439 | + |
|
| 2440 | + // set orderby |
|
| 2441 | + $this->_req_data['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
| 2442 | + |
|
| 2443 | + switch ($this->_req_data['orderby']) { |
|
| 2444 | + case 'TXN_ID': |
|
| 2445 | + $orderby = 'TXN_ID'; |
|
| 2446 | + break; |
|
| 2447 | + case 'ATT_fname': |
|
| 2448 | + $orderby = 'Registration.Attendee.ATT_fname'; |
|
| 2449 | + break; |
|
| 2450 | + case 'event_name': |
|
| 2451 | + $orderby = 'Registration.Event.EVT_name'; |
|
| 2452 | + break; |
|
| 2453 | + default: // 'TXN_timestamp' |
|
| 2454 | + $orderby = 'TXN_timestamp'; |
|
| 2455 | + } |
|
| 2456 | + |
|
| 2457 | + $sort = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
| 2458 | + $current_page = ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
| 2459 | + $per_page = ! empty($perpage) ? $perpage : 10; |
|
| 2460 | + $per_page = ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
| 2461 | + |
|
| 2462 | + $offset = ($current_page - 1) * $per_page; |
|
| 2463 | + $limit = array($offset, $per_page); |
|
| 2464 | + |
|
| 2465 | + $_where = array( |
|
| 2466 | + 'TXN_timestamp' => array('BETWEEN', array($start_date, $end_date)), |
|
| 2467 | + 'Registration.REG_count' => 1, |
|
| 2468 | + ); |
|
| 2469 | + |
|
| 2470 | + if (isset($this->_req_data['EVT_ID'])) { |
|
| 2471 | + $_where['Registration.EVT_ID'] = $this->_req_data['EVT_ID']; |
|
| 2472 | + } |
|
| 2473 | + |
|
| 2474 | + if (isset($this->_req_data['s'])) { |
|
| 2475 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
| 2476 | + $_where['OR'] = array( |
|
| 2477 | + 'Registration.Event.EVT_name' => array('LIKE', $search_string), |
|
| 2478 | + 'Registration.Event.EVT_desc' => array('LIKE', $search_string), |
|
| 2479 | + 'Registration.Event.EVT_short_desc' => array('LIKE', $search_string), |
|
| 2480 | + 'Registration.Attendee.ATT_full_name' => array('LIKE', $search_string), |
|
| 2481 | + 'Registration.Attendee.ATT_fname' => array('LIKE', $search_string), |
|
| 2482 | + 'Registration.Attendee.ATT_lname' => array('LIKE', $search_string), |
|
| 2483 | + 'Registration.Attendee.ATT_short_bio' => array('LIKE', $search_string), |
|
| 2484 | + 'Registration.Attendee.ATT_email' => array('LIKE', $search_string), |
|
| 2485 | + 'Registration.Attendee.ATT_address' => array('LIKE', $search_string), |
|
| 2486 | + 'Registration.Attendee.ATT_address2' => array('LIKE', $search_string), |
|
| 2487 | + 'Registration.Attendee.ATT_city' => array('LIKE', $search_string), |
|
| 2488 | + 'Registration.REG_final_price' => array('LIKE', $search_string), |
|
| 2489 | + 'Registration.REG_code' => array('LIKE', $search_string), |
|
| 2490 | + 'Registration.REG_count' => array('LIKE', $search_string), |
|
| 2491 | + 'Registration.REG_group_size' => array('LIKE', $search_string), |
|
| 2492 | + 'Registration.Ticket.TKT_name' => array('LIKE', $search_string), |
|
| 2493 | + 'Registration.Ticket.TKT_description' => array('LIKE', $search_string), |
|
| 2494 | + 'Payment.PAY_source' => array('LIKE', $search_string), |
|
| 2495 | + 'Payment.Payment_Method.PMD_name' => array('LIKE', $search_string), |
|
| 2496 | + 'TXN_session_data' => array('LIKE', $search_string), |
|
| 2497 | + 'Payment.PAY_txn_id_chq_nmbr' => array('LIKE', $search_string), |
|
| 2498 | + ); |
|
| 2499 | + } |
|
| 2500 | + |
|
| 2501 | + // failed transactions |
|
| 2502 | + $failed = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'failed' && ! $count) |
|
| 2503 | + || ($count && $view === 'failed'); |
|
| 2504 | + $abandoned = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'abandoned' && ! $count) |
|
| 2505 | + || ($count && $view === 'abandoned'); |
|
| 2506 | + $incomplete = (! empty($this->_req_data['status']) && $this->_req_data['status'] === 'incomplete' && ! $count) |
|
| 2507 | + || ($count && $view === 'incomplete'); |
|
| 2508 | + |
|
| 2509 | + if ($failed) { |
|
| 2510 | + $_where['STS_ID'] = EEM_Transaction::failed_status_code; |
|
| 2511 | + } elseif ($abandoned) { |
|
| 2512 | + $_where['STS_ID'] = EEM_Transaction::abandoned_status_code; |
|
| 2513 | + } elseif ($incomplete) { |
|
| 2514 | + $_where['STS_ID'] = EEM_Transaction::incomplete_status_code; |
|
| 2515 | + } else { |
|
| 2516 | + $_where['STS_ID'] = array('!=', EEM_Transaction::failed_status_code); |
|
| 2517 | + $_where['STS_ID*'] = array('!=', EEM_Transaction::abandoned_status_code); |
|
| 2518 | + } |
|
| 2519 | + |
|
| 2520 | + $query_params = apply_filters( |
|
| 2521 | + 'FHEE__Transactions_Admin_Page___get_transactions_query_params', |
|
| 2522 | + array( |
|
| 2523 | + $_where, |
|
| 2524 | + 'order_by' => array($orderby => $sort), |
|
| 2525 | + 'limit' => $limit, |
|
| 2526 | + 'default_where_conditions' => EEM_Base::default_where_conditions_this_only, |
|
| 2527 | + ), |
|
| 2528 | + $this->_req_data, |
|
| 2529 | + $view, |
|
| 2530 | + $count |
|
| 2531 | + ); |
|
| 2532 | + |
|
| 2533 | + $transactions = $count |
|
| 2534 | + ? $TXN->count(array($query_params[0]), 'TXN_ID', true) |
|
| 2535 | + : $TXN->get_all($query_params); |
|
| 2536 | + |
|
| 2537 | + return $transactions; |
|
| 2538 | + } |
|
| 2539 | + |
|
| 2540 | + |
|
| 2541 | + /** |
|
| 2542 | + * @since 4.9.79.p |
|
| 2543 | + * @throws EE_Error |
|
| 2544 | + * @throws InvalidArgumentException |
|
| 2545 | + * @throws InvalidDataTypeException |
|
| 2546 | + * @throws InvalidInterfaceException |
|
| 2547 | + * @throws ReflectionException |
|
| 2548 | + * @throws RuntimeException |
|
| 2549 | + */ |
|
| 2550 | + public function recalculateLineItems() |
|
| 2551 | + { |
|
| 2552 | + $TXN_ID = ! empty($this->_req_data['TXN_ID']) ? absint($this->_req_data['TXN_ID']) : false; |
|
| 2553 | + /** @var EE_Transaction $transaction */ |
|
| 2554 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
| 2555 | + $total_line_item = $transaction->total_line_item(false); |
|
| 2556 | + $success = false; |
|
| 2557 | + if ($total_line_item instanceof EE_Line_Item) { |
|
| 2558 | + EEH_Line_Item::resetIsTaxableForTickets($total_line_item); |
|
| 2559 | + $success = EEH_Line_Item::apply_taxes($total_line_item, true); |
|
| 2560 | + } |
|
| 2561 | + $this->_redirect_after_action( |
|
| 2562 | + (bool) $success, |
|
| 2563 | + esc_html__('Transaction taxes and totals', 'event_espresso'), |
|
| 2564 | + esc_html__('recalculated', 'event_espresso'), |
|
| 2565 | + isset($this->_req_data['redirect_to']) |
|
| 2566 | + ? array( |
|
| 2567 | + 'action' => $this->_req_data['redirect_to'], |
|
| 2568 | + 'TXN_ID' => $this->_req_data['TXN_ID'], |
|
| 2569 | + ) |
|
| 2570 | + : array(), |
|
| 2571 | + true |
|
| 2572 | + ); |
|
| 2573 | + } |
|
| 2574 | 2574 | } |
@@ -13,1410 +13,1410 @@ |
||
| 13 | 13 | class EE_Datetime extends EE_Soft_Delete_Base_Class |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * constant used by get_active_status, indicates datetime has no more available spaces |
|
| 18 | - */ |
|
| 19 | - const sold_out = 'DTS'; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * constant used by get_active_status, indicating datetime is still active (even is not over, can be registered-for) |
|
| 23 | - */ |
|
| 24 | - const active = 'DTA'; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * constant used by get_active_status, indicating the datetime cannot be used for registrations yet, but has not |
|
| 28 | - * expired |
|
| 29 | - */ |
|
| 30 | - const upcoming = 'DTU'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Datetime is postponed |
|
| 34 | - */ |
|
| 35 | - const postponed = 'DTP'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Datetime is cancelled |
|
| 39 | - */ |
|
| 40 | - const cancelled = 'DTC'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * constant used by get_active_status, indicates datetime has expired (event is over) |
|
| 44 | - */ |
|
| 45 | - const expired = 'DTE'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * constant used in various places indicating that an event is INACTIVE (not yet ready to be published) |
|
| 49 | - */ |
|
| 50 | - const inactive = 'DTI'; |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param array $props_n_values incoming values |
|
| 55 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be used.) |
|
| 56 | - * @param array $date_formats incoming date_formats in an array where the first value is the date_format |
|
| 57 | - * and the second value is the time format |
|
| 58 | - * @return EE_Datetime |
|
| 59 | - * @throws ReflectionException |
|
| 60 | - * @throws InvalidArgumentException |
|
| 61 | - * @throws InvalidInterfaceException |
|
| 62 | - * @throws InvalidDataTypeException |
|
| 63 | - * @throws EE_Error |
|
| 64 | - */ |
|
| 65 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 66 | - { |
|
| 67 | - $has_object = parent::_check_for_object( |
|
| 68 | - $props_n_values, |
|
| 69 | - __CLASS__, |
|
| 70 | - $timezone, |
|
| 71 | - $date_formats |
|
| 72 | - ); |
|
| 73 | - return $has_object |
|
| 74 | - ? $has_object |
|
| 75 | - : new self($props_n_values, false, $timezone, $date_formats); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @param array $props_n_values incoming values from the database |
|
| 81 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 82 | - * the website will be used. |
|
| 83 | - * @return EE_Datetime |
|
| 84 | - * @throws ReflectionException |
|
| 85 | - * @throws InvalidArgumentException |
|
| 86 | - * @throws InvalidInterfaceException |
|
| 87 | - * @throws InvalidDataTypeException |
|
| 88 | - * @throws EE_Error |
|
| 89 | - */ |
|
| 90 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 91 | - { |
|
| 92 | - return new self($props_n_values, true, $timezone); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @param $name |
|
| 98 | - * @throws ReflectionException |
|
| 99 | - * @throws InvalidArgumentException |
|
| 100 | - * @throws InvalidInterfaceException |
|
| 101 | - * @throws InvalidDataTypeException |
|
| 102 | - * @throws EE_Error |
|
| 103 | - */ |
|
| 104 | - public function set_name($name) |
|
| 105 | - { |
|
| 106 | - $this->set('DTT_name', $name); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @param $description |
|
| 112 | - * @throws ReflectionException |
|
| 113 | - * @throws InvalidArgumentException |
|
| 114 | - * @throws InvalidInterfaceException |
|
| 115 | - * @throws InvalidDataTypeException |
|
| 116 | - * @throws EE_Error |
|
| 117 | - */ |
|
| 118 | - public function set_description($description) |
|
| 119 | - { |
|
| 120 | - $this->set('DTT_description', $description); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Set event start date |
|
| 126 | - * set the start date for an event |
|
| 127 | - * |
|
| 128 | - * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 |
|
| 129 | - * @throws ReflectionException |
|
| 130 | - * @throws InvalidArgumentException |
|
| 131 | - * @throws InvalidInterfaceException |
|
| 132 | - * @throws InvalidDataTypeException |
|
| 133 | - * @throws EE_Error |
|
| 134 | - */ |
|
| 135 | - public function set_start_date($date) |
|
| 136 | - { |
|
| 137 | - $this->_set_date_for($date, 'DTT_EVT_start'); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Set event start time |
|
| 143 | - * set the start time for an event |
|
| 144 | - * |
|
| 145 | - * @param string $time a string representation of the event time ex: 9am or 7:30 PM |
|
| 146 | - * @throws ReflectionException |
|
| 147 | - * @throws InvalidArgumentException |
|
| 148 | - * @throws InvalidInterfaceException |
|
| 149 | - * @throws InvalidDataTypeException |
|
| 150 | - * @throws EE_Error |
|
| 151 | - */ |
|
| 152 | - public function set_start_time($time) |
|
| 153 | - { |
|
| 154 | - $this->_set_time_for($time, 'DTT_EVT_start'); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Set event end date |
|
| 160 | - * set the end date for an event |
|
| 161 | - * |
|
| 162 | - * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 |
|
| 163 | - * @throws ReflectionException |
|
| 164 | - * @throws InvalidArgumentException |
|
| 165 | - * @throws InvalidInterfaceException |
|
| 166 | - * @throws InvalidDataTypeException |
|
| 167 | - * @throws EE_Error |
|
| 168 | - */ |
|
| 169 | - public function set_end_date($date) |
|
| 170 | - { |
|
| 171 | - $this->_set_date_for($date, 'DTT_EVT_end'); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Set event end time |
|
| 177 | - * set the end time for an event |
|
| 178 | - * |
|
| 179 | - * @param string $time a string representation of the event time ex: 9am or 7:30 PM |
|
| 180 | - * @throws ReflectionException |
|
| 181 | - * @throws InvalidArgumentException |
|
| 182 | - * @throws InvalidInterfaceException |
|
| 183 | - * @throws InvalidDataTypeException |
|
| 184 | - * @throws EE_Error |
|
| 185 | - */ |
|
| 186 | - public function set_end_time($time) |
|
| 187 | - { |
|
| 188 | - $this->_set_time_for($time, 'DTT_EVT_end'); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Set registration limit |
|
| 194 | - * set the maximum number of attendees that can be registered for this datetime slot |
|
| 195 | - * |
|
| 196 | - * @param int $reg_limit |
|
| 197 | - * @throws ReflectionException |
|
| 198 | - * @throws InvalidArgumentException |
|
| 199 | - * @throws InvalidInterfaceException |
|
| 200 | - * @throws InvalidDataTypeException |
|
| 201 | - * @throws EE_Error |
|
| 202 | - */ |
|
| 203 | - public function set_reg_limit($reg_limit) |
|
| 204 | - { |
|
| 205 | - $this->set('DTT_reg_limit', $reg_limit); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * get the number of tickets sold for this datetime slot |
|
| 211 | - * |
|
| 212 | - * @return mixed int on success, FALSE on fail |
|
| 213 | - * @throws ReflectionException |
|
| 214 | - * @throws InvalidArgumentException |
|
| 215 | - * @throws InvalidInterfaceException |
|
| 216 | - * @throws InvalidDataTypeException |
|
| 217 | - * @throws EE_Error |
|
| 218 | - */ |
|
| 219 | - public function sold() |
|
| 220 | - { |
|
| 221 | - return $this->get_raw('DTT_sold'); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * @param int $sold |
|
| 227 | - * @throws ReflectionException |
|
| 228 | - * @throws InvalidArgumentException |
|
| 229 | - * @throws InvalidInterfaceException |
|
| 230 | - * @throws InvalidDataTypeException |
|
| 231 | - * @throws EE_Error |
|
| 232 | - */ |
|
| 233 | - public function set_sold($sold) |
|
| 234 | - { |
|
| 235 | - // sold can not go below zero |
|
| 236 | - $sold = max(0, $sold); |
|
| 237 | - $this->set('DTT_sold', $sold); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Increments sold by amount passed by $qty, and persists it immediately to the database. |
|
| 243 | - * Simultaneously decreases the reserved count, unless $also_decrease_reserved is false. |
|
| 244 | - * |
|
| 245 | - * @param int $qty |
|
| 246 | - * @param boolean $also_decrease_reserved |
|
| 247 | - * @return boolean indicating success |
|
| 248 | - * @throws ReflectionException |
|
| 249 | - * @throws InvalidArgumentException |
|
| 250 | - * @throws InvalidInterfaceException |
|
| 251 | - * @throws InvalidDataTypeException |
|
| 252 | - * @throws EE_Error |
|
| 253 | - */ |
|
| 254 | - public function increaseSold($qty = 1, $also_decrease_reserved = true) |
|
| 255 | - { |
|
| 256 | - $qty = absint($qty); |
|
| 257 | - if ($also_decrease_reserved) { |
|
| 258 | - $success = $this->adjustNumericFieldsInDb( |
|
| 259 | - [ |
|
| 260 | - 'DTT_reserved' => $qty * -1, |
|
| 261 | - 'DTT_sold' => $qty |
|
| 262 | - ] |
|
| 263 | - ); |
|
| 264 | - } else { |
|
| 265 | - $success = $this->adjustNumericFieldsInDb( |
|
| 266 | - [ |
|
| 267 | - 'DTT_sold' => $qty |
|
| 268 | - ] |
|
| 269 | - ); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - do_action( |
|
| 273 | - 'AHEE__EE_Datetime__increase_sold', |
|
| 274 | - $this, |
|
| 275 | - $qty, |
|
| 276 | - $this->sold(), |
|
| 277 | - $success |
|
| 278 | - ); |
|
| 279 | - return $success; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Decrements (subtracts) sold amount passed by $qty directly in the DB and on the model object. (Ie, no need |
|
| 285 | - * to save afterwards.) |
|
| 286 | - * |
|
| 287 | - * @param int $qty |
|
| 288 | - * @return boolean indicating success |
|
| 289 | - * @throws ReflectionException |
|
| 290 | - * @throws InvalidArgumentException |
|
| 291 | - * @throws InvalidInterfaceException |
|
| 292 | - * @throws InvalidDataTypeException |
|
| 293 | - * @throws EE_Error |
|
| 294 | - */ |
|
| 295 | - public function decreaseSold($qty = 1) |
|
| 296 | - { |
|
| 297 | - $qty = absint($qty); |
|
| 298 | - $success = $this->adjustNumericFieldsInDb( |
|
| 299 | - [ |
|
| 300 | - 'DTT_sold' => $qty * -1 |
|
| 301 | - ] |
|
| 302 | - ); |
|
| 303 | - do_action( |
|
| 304 | - 'AHEE__EE_Datetime__decrease_sold', |
|
| 305 | - $this, |
|
| 306 | - $qty, |
|
| 307 | - $this->sold(), |
|
| 308 | - $success |
|
| 309 | - ); |
|
| 310 | - return $success; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Gets qty of reserved tickets for this datetime |
|
| 316 | - * |
|
| 317 | - * @return int |
|
| 318 | - * @throws ReflectionException |
|
| 319 | - * @throws InvalidArgumentException |
|
| 320 | - * @throws InvalidInterfaceException |
|
| 321 | - * @throws InvalidDataTypeException |
|
| 322 | - * @throws EE_Error |
|
| 323 | - */ |
|
| 324 | - public function reserved() |
|
| 325 | - { |
|
| 326 | - return $this->get_raw('DTT_reserved'); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Sets qty of reserved tickets for this datetime |
|
| 332 | - * |
|
| 333 | - * @param int $reserved |
|
| 334 | - * @throws ReflectionException |
|
| 335 | - * @throws InvalidArgumentException |
|
| 336 | - * @throws InvalidInterfaceException |
|
| 337 | - * @throws InvalidDataTypeException |
|
| 338 | - * @throws EE_Error |
|
| 339 | - */ |
|
| 340 | - public function set_reserved($reserved) |
|
| 341 | - { |
|
| 342 | - // reserved can not go below zero |
|
| 343 | - $reserved = max(0, (int) $reserved); |
|
| 344 | - $this->set('DTT_reserved', $reserved); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 350 | - * |
|
| 351 | - * @param int $qty |
|
| 352 | - * @return boolean indicating success |
|
| 353 | - * @throws ReflectionException |
|
| 354 | - * @throws InvalidArgumentException |
|
| 355 | - * @throws InvalidInterfaceException |
|
| 356 | - * @throws InvalidDataTypeException |
|
| 357 | - * @throws EE_Error |
|
| 358 | - */ |
|
| 359 | - public function increaseReserved($qty = 1) |
|
| 360 | - { |
|
| 361 | - $qty = absint($qty); |
|
| 362 | - $success = $this->incrementFieldConditionallyInDb( |
|
| 363 | - 'DTT_reserved', |
|
| 364 | - 'DTT_sold', |
|
| 365 | - 'DTT_reg_limit', |
|
| 366 | - $qty |
|
| 367 | - ); |
|
| 368 | - do_action( |
|
| 369 | - 'AHEE__EE_Datetime__increase_reserved', |
|
| 370 | - $this, |
|
| 371 | - $qty, |
|
| 372 | - $this->reserved(), |
|
| 373 | - $success |
|
| 374 | - ); |
|
| 375 | - return $success; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 381 | - * |
|
| 382 | - * @param int $qty |
|
| 383 | - * @return boolean indicating success |
|
| 384 | - * @throws ReflectionException |
|
| 385 | - * @throws InvalidArgumentException |
|
| 386 | - * @throws InvalidInterfaceException |
|
| 387 | - * @throws InvalidDataTypeException |
|
| 388 | - * @throws EE_Error |
|
| 389 | - */ |
|
| 390 | - public function decreaseReserved($qty = 1) |
|
| 391 | - { |
|
| 392 | - $qty = absint($qty); |
|
| 393 | - $success = $this->adjustNumericFieldsInDb( |
|
| 394 | - [ |
|
| 395 | - 'DTT_reserved' => $qty * -1 |
|
| 396 | - ] |
|
| 397 | - ); |
|
| 398 | - do_action( |
|
| 399 | - 'AHEE__EE_Datetime__decrease_reserved', |
|
| 400 | - $this, |
|
| 401 | - $qty, |
|
| 402 | - $this->reserved(), |
|
| 403 | - $success |
|
| 404 | - ); |
|
| 405 | - return $success; |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * total sold and reserved tickets |
|
| 411 | - * |
|
| 412 | - * @return int |
|
| 413 | - * @throws ReflectionException |
|
| 414 | - * @throws InvalidArgumentException |
|
| 415 | - * @throws InvalidInterfaceException |
|
| 416 | - * @throws InvalidDataTypeException |
|
| 417 | - * @throws EE_Error |
|
| 418 | - */ |
|
| 419 | - public function sold_and_reserved() |
|
| 420 | - { |
|
| 421 | - return $this->sold() + $this->reserved(); |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * returns the datetime name |
|
| 427 | - * |
|
| 428 | - * @return string |
|
| 429 | - * @throws ReflectionException |
|
| 430 | - * @throws InvalidArgumentException |
|
| 431 | - * @throws InvalidInterfaceException |
|
| 432 | - * @throws InvalidDataTypeException |
|
| 433 | - * @throws EE_Error |
|
| 434 | - */ |
|
| 435 | - public function name() |
|
| 436 | - { |
|
| 437 | - return $this->get('DTT_name'); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * returns the datetime description |
|
| 443 | - * |
|
| 444 | - * @return string |
|
| 445 | - * @throws ReflectionException |
|
| 446 | - * @throws InvalidArgumentException |
|
| 447 | - * @throws InvalidInterfaceException |
|
| 448 | - * @throws InvalidDataTypeException |
|
| 449 | - * @throws EE_Error |
|
| 450 | - */ |
|
| 451 | - public function description() |
|
| 452 | - { |
|
| 453 | - return $this->get('DTT_description'); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * This helper simply returns whether the event_datetime for the current datetime is a primary datetime |
|
| 459 | - * |
|
| 460 | - * @return boolean TRUE if is primary, FALSE if not. |
|
| 461 | - * @throws ReflectionException |
|
| 462 | - * @throws InvalidArgumentException |
|
| 463 | - * @throws InvalidInterfaceException |
|
| 464 | - * @throws InvalidDataTypeException |
|
| 465 | - * @throws EE_Error |
|
| 466 | - */ |
|
| 467 | - public function is_primary() |
|
| 468 | - { |
|
| 469 | - return $this->get('DTT_is_primary'); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * This helper simply returns the order for the datetime |
|
| 475 | - * |
|
| 476 | - * @return int The order of the datetime for this event. |
|
| 477 | - * @throws ReflectionException |
|
| 478 | - * @throws InvalidArgumentException |
|
| 479 | - * @throws InvalidInterfaceException |
|
| 480 | - * @throws InvalidDataTypeException |
|
| 481 | - * @throws EE_Error |
|
| 482 | - */ |
|
| 483 | - public function order() |
|
| 484 | - { |
|
| 485 | - return $this->get('DTT_order'); |
|
| 486 | - } |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * This helper simply returns the parent id for the datetime |
|
| 491 | - * |
|
| 492 | - * @return int |
|
| 493 | - * @throws ReflectionException |
|
| 494 | - * @throws InvalidArgumentException |
|
| 495 | - * @throws InvalidInterfaceException |
|
| 496 | - * @throws InvalidDataTypeException |
|
| 497 | - * @throws EE_Error |
|
| 498 | - */ |
|
| 499 | - public function parent() |
|
| 500 | - { |
|
| 501 | - return $this->get('DTT_parent'); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * show date and/or time |
|
| 507 | - * |
|
| 508 | - * @param string $date_or_time whether to display a date or time or both |
|
| 509 | - * @param string $start_or_end whether to display start or end datetimes |
|
| 510 | - * @param string $dt_frmt |
|
| 511 | - * @param string $tm_frmt |
|
| 512 | - * @param bool $echo whether we echo or return (note echoing uses "pretty" formats, |
|
| 513 | - * otherwise we use the standard formats) |
|
| 514 | - * @return string|bool string on success, FALSE on fail |
|
| 515 | - * @throws ReflectionException |
|
| 516 | - * @throws InvalidArgumentException |
|
| 517 | - * @throws InvalidInterfaceException |
|
| 518 | - * @throws InvalidDataTypeException |
|
| 519 | - * @throws EE_Error |
|
| 520 | - */ |
|
| 521 | - private function _show_datetime( |
|
| 522 | - $date_or_time = null, |
|
| 523 | - $start_or_end = 'start', |
|
| 524 | - $dt_frmt = '', |
|
| 525 | - $tm_frmt = '', |
|
| 526 | - $echo = false |
|
| 527 | - ) { |
|
| 528 | - $field_name = "DTT_EVT_{$start_or_end}"; |
|
| 529 | - $dtt = $this->_get_datetime( |
|
| 530 | - $field_name, |
|
| 531 | - $dt_frmt, |
|
| 532 | - $tm_frmt, |
|
| 533 | - $date_or_time, |
|
| 534 | - $echo |
|
| 535 | - ); |
|
| 536 | - if (! $echo) { |
|
| 537 | - return $dtt; |
|
| 538 | - } |
|
| 539 | - return ''; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * get event start date. Provide either the date format, or NULL to re-use the |
|
| 545 | - * last-used format, or '' to use the default date format |
|
| 546 | - * |
|
| 547 | - * @param string $dt_frmt string representation of date format defaults to 'F j, Y' |
|
| 548 | - * @return mixed string on success, FALSE on fail |
|
| 549 | - * @throws ReflectionException |
|
| 550 | - * @throws InvalidArgumentException |
|
| 551 | - * @throws InvalidInterfaceException |
|
| 552 | - * @throws InvalidDataTypeException |
|
| 553 | - * @throws EE_Error |
|
| 554 | - */ |
|
| 555 | - public function start_date($dt_frmt = '') |
|
| 556 | - { |
|
| 557 | - return $this->_show_datetime('D', 'start', $dt_frmt); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * Echoes start_date() |
|
| 563 | - * |
|
| 564 | - * @param string $dt_frmt |
|
| 565 | - * @throws ReflectionException |
|
| 566 | - * @throws InvalidArgumentException |
|
| 567 | - * @throws InvalidInterfaceException |
|
| 568 | - * @throws InvalidDataTypeException |
|
| 569 | - * @throws EE_Error |
|
| 570 | - */ |
|
| 571 | - public function e_start_date($dt_frmt = '') |
|
| 572 | - { |
|
| 573 | - $this->_show_datetime('D', 'start', $dt_frmt, null, true); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - |
|
| 577 | - /** |
|
| 578 | - * get end date. Provide either the date format, or NULL to re-use the |
|
| 579 | - * last-used format, or '' to use the default date format |
|
| 580 | - * |
|
| 581 | - * @param string $dt_frmt string representation of date format defaults to 'F j, Y' |
|
| 582 | - * @return mixed string on success, FALSE on fail |
|
| 583 | - * @throws ReflectionException |
|
| 584 | - * @throws InvalidArgumentException |
|
| 585 | - * @throws InvalidInterfaceException |
|
| 586 | - * @throws InvalidDataTypeException |
|
| 587 | - * @throws EE_Error |
|
| 588 | - */ |
|
| 589 | - public function end_date($dt_frmt = '') |
|
| 590 | - { |
|
| 591 | - return $this->_show_datetime('D', 'end', $dt_frmt); |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Echoes the end date. See end_date() |
|
| 597 | - * |
|
| 598 | - * @param string $dt_frmt |
|
| 599 | - * @throws ReflectionException |
|
| 600 | - * @throws InvalidArgumentException |
|
| 601 | - * @throws InvalidInterfaceException |
|
| 602 | - * @throws InvalidDataTypeException |
|
| 603 | - * @throws EE_Error |
|
| 604 | - */ |
|
| 605 | - public function e_end_date($dt_frmt = '') |
|
| 606 | - { |
|
| 607 | - $this->_show_datetime('D', 'end', $dt_frmt, null, true); |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * get date_range - meaning the start AND end date |
|
| 613 | - * |
|
| 614 | - * @access public |
|
| 615 | - * @param string $dt_frmt string representation of date format defaults to WP settings |
|
| 616 | - * @param string $conjunction conjunction junction what's your function ? |
|
| 617 | - * this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
| 618 | - * @return mixed string on success, FALSE on fail |
|
| 619 | - * @throws ReflectionException |
|
| 620 | - * @throws InvalidArgumentException |
|
| 621 | - * @throws InvalidInterfaceException |
|
| 622 | - * @throws InvalidDataTypeException |
|
| 623 | - * @throws EE_Error |
|
| 624 | - */ |
|
| 625 | - public function date_range($dt_frmt = '', $conjunction = ' - ') |
|
| 626 | - { |
|
| 627 | - $dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt; |
|
| 628 | - $start = str_replace( |
|
| 629 | - ' ', |
|
| 630 | - ' ', |
|
| 631 | - $this->get_i18n_datetime('DTT_EVT_start', $dt_frmt) |
|
| 632 | - ); |
|
| 633 | - $end = str_replace( |
|
| 634 | - ' ', |
|
| 635 | - ' ', |
|
| 636 | - $this->get_i18n_datetime('DTT_EVT_end', $dt_frmt) |
|
| 637 | - ); |
|
| 638 | - return $start !== $end ? $start . $conjunction . $end : $start; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - |
|
| 642 | - /** |
|
| 643 | - * @param string $dt_frmt |
|
| 644 | - * @param string $conjunction |
|
| 645 | - * @throws ReflectionException |
|
| 646 | - * @throws InvalidArgumentException |
|
| 647 | - * @throws InvalidInterfaceException |
|
| 648 | - * @throws InvalidDataTypeException |
|
| 649 | - * @throws EE_Error |
|
| 650 | - */ |
|
| 651 | - public function e_date_range($dt_frmt = '', $conjunction = ' - ') |
|
| 652 | - { |
|
| 653 | - echo $this->date_range($dt_frmt, $conjunction); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - |
|
| 657 | - /** |
|
| 658 | - * get start time |
|
| 659 | - * |
|
| 660 | - * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 661 | - * @return mixed string on success, FALSE on fail |
|
| 662 | - * @throws ReflectionException |
|
| 663 | - * @throws InvalidArgumentException |
|
| 664 | - * @throws InvalidInterfaceException |
|
| 665 | - * @throws InvalidDataTypeException |
|
| 666 | - * @throws EE_Error |
|
| 667 | - */ |
|
| 668 | - public function start_time($tm_format = '') |
|
| 669 | - { |
|
| 670 | - return $this->_show_datetime('T', 'start', null, $tm_format); |
|
| 671 | - } |
|
| 672 | - |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * @param string $tm_format |
|
| 676 | - * @throws ReflectionException |
|
| 677 | - * @throws InvalidArgumentException |
|
| 678 | - * @throws InvalidInterfaceException |
|
| 679 | - * @throws InvalidDataTypeException |
|
| 680 | - * @throws EE_Error |
|
| 681 | - */ |
|
| 682 | - public function e_start_time($tm_format = '') |
|
| 683 | - { |
|
| 684 | - $this->_show_datetime('T', 'start', null, $tm_format, true); |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * get end time |
|
| 690 | - * |
|
| 691 | - * @param string $tm_format string representation of time format defaults to 'g:i a' |
|
| 692 | - * @return mixed string on success, FALSE on fail |
|
| 693 | - * @throws ReflectionException |
|
| 694 | - * @throws InvalidArgumentException |
|
| 695 | - * @throws InvalidInterfaceException |
|
| 696 | - * @throws InvalidDataTypeException |
|
| 697 | - * @throws EE_Error |
|
| 698 | - */ |
|
| 699 | - public function end_time($tm_format = '') |
|
| 700 | - { |
|
| 701 | - return $this->_show_datetime('T', 'end', null, $tm_format); |
|
| 702 | - } |
|
| 703 | - |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * @param string $tm_format |
|
| 707 | - * @throws ReflectionException |
|
| 708 | - * @throws InvalidArgumentException |
|
| 709 | - * @throws InvalidInterfaceException |
|
| 710 | - * @throws InvalidDataTypeException |
|
| 711 | - * @throws EE_Error |
|
| 712 | - */ |
|
| 713 | - public function e_end_time($tm_format = '') |
|
| 714 | - { |
|
| 715 | - $this->_show_datetime('T', 'end', null, $tm_format, true); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - /** |
|
| 720 | - * get time_range |
|
| 721 | - * |
|
| 722 | - * @access public |
|
| 723 | - * @param string $tm_format string representation of time format defaults to 'g:i a' |
|
| 724 | - * @param string $conjunction conjunction junction what's your function ? |
|
| 725 | - * this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
| 726 | - * @return mixed string on success, FALSE on fail |
|
| 727 | - * @throws ReflectionException |
|
| 728 | - * @throws InvalidArgumentException |
|
| 729 | - * @throws InvalidInterfaceException |
|
| 730 | - * @throws InvalidDataTypeException |
|
| 731 | - * @throws EE_Error |
|
| 732 | - */ |
|
| 733 | - public function time_range($tm_format = '', $conjunction = ' - ') |
|
| 734 | - { |
|
| 735 | - $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt; |
|
| 736 | - $start = str_replace( |
|
| 737 | - ' ', |
|
| 738 | - ' ', |
|
| 739 | - $this->get_i18n_datetime('DTT_EVT_start', $tm_format) |
|
| 740 | - ); |
|
| 741 | - $end = str_replace( |
|
| 742 | - ' ', |
|
| 743 | - ' ', |
|
| 744 | - $this->get_i18n_datetime('DTT_EVT_end', $tm_format) |
|
| 745 | - ); |
|
| 746 | - return $start !== $end ? $start . $conjunction . $end : $start; |
|
| 747 | - } |
|
| 748 | - |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * @param string $tm_format |
|
| 752 | - * @param string $conjunction |
|
| 753 | - * @throws ReflectionException |
|
| 754 | - * @throws InvalidArgumentException |
|
| 755 | - * @throws InvalidInterfaceException |
|
| 756 | - * @throws InvalidDataTypeException |
|
| 757 | - * @throws EE_Error |
|
| 758 | - */ |
|
| 759 | - public function e_time_range($tm_format = '', $conjunction = ' - ') |
|
| 760 | - { |
|
| 761 | - echo $this->time_range($tm_format, $conjunction); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - |
|
| 765 | - /** |
|
| 766 | - * This returns a range representation of the date and times. |
|
| 767 | - * Output is dependent on the difference (or similarity) between DTT_EVT_start and DTT_EVT_end. |
|
| 768 | - * Also, the return value is localized. |
|
| 769 | - * |
|
| 770 | - * @param string $dt_format |
|
| 771 | - * @param string $tm_format |
|
| 772 | - * @param string $conjunction used between two different dates or times. |
|
| 773 | - * ex: Dec 1{$conjunction}}Dec 6, or 2pm{$conjunction}3pm |
|
| 774 | - * @param string $separator used between the date and time formats. |
|
| 775 | - * ex: Dec 1, 2016{$separator}2pm |
|
| 776 | - * @return string |
|
| 777 | - * @throws ReflectionException |
|
| 778 | - * @throws InvalidArgumentException |
|
| 779 | - * @throws InvalidInterfaceException |
|
| 780 | - * @throws InvalidDataTypeException |
|
| 781 | - * @throws EE_Error |
|
| 782 | - */ |
|
| 783 | - public function date_and_time_range( |
|
| 784 | - $dt_format = '', |
|
| 785 | - $tm_format = '', |
|
| 786 | - $conjunction = ' - ', |
|
| 787 | - $separator = ' ' |
|
| 788 | - ) { |
|
| 789 | - $dt_format = ! empty($dt_format) ? $dt_format : $this->_dt_frmt; |
|
| 790 | - $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt; |
|
| 791 | - $full_format = $dt_format . $separator . $tm_format; |
|
| 792 | - // the range output depends on various conditions |
|
| 793 | - switch (true) { |
|
| 794 | - // start date timestamp and end date timestamp are the same. |
|
| 795 | - case ($this->get_raw('DTT_EVT_start') === $this->get_raw('DTT_EVT_end')): |
|
| 796 | - $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format); |
|
| 797 | - break; |
|
| 798 | - // start and end date are the same but times are different |
|
| 799 | - case ($this->start_date() === $this->end_date()): |
|
| 800 | - $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format) |
|
| 801 | - . $conjunction |
|
| 802 | - . $this->get_i18n_datetime('DTT_EVT_end', $tm_format); |
|
| 803 | - break; |
|
| 804 | - // all other conditions |
|
| 805 | - default: |
|
| 806 | - $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format) |
|
| 807 | - . $conjunction |
|
| 808 | - . $this->get_i18n_datetime('DTT_EVT_end', $full_format); |
|
| 809 | - break; |
|
| 810 | - } |
|
| 811 | - return $output; |
|
| 812 | - } |
|
| 813 | - |
|
| 814 | - |
|
| 815 | - /** |
|
| 816 | - * This echos the results of date and time range. |
|
| 817 | - * |
|
| 818 | - * @see date_and_time_range() for more details on purpose. |
|
| 819 | - * @param string $dt_format |
|
| 820 | - * @param string $tm_format |
|
| 821 | - * @param string $conjunction |
|
| 822 | - * @return void |
|
| 823 | - * @throws ReflectionException |
|
| 824 | - * @throws InvalidArgumentException |
|
| 825 | - * @throws InvalidInterfaceException |
|
| 826 | - * @throws InvalidDataTypeException |
|
| 827 | - * @throws EE_Error |
|
| 828 | - */ |
|
| 829 | - public function e_date_and_time_range($dt_format = '', $tm_format = '', $conjunction = ' - ') |
|
| 830 | - { |
|
| 831 | - echo $this->date_and_time_range($dt_format, $tm_format, $conjunction); |
|
| 832 | - } |
|
| 833 | - |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * get start date and start time |
|
| 837 | - * |
|
| 838 | - * @param string $dt_format - string representation of date format defaults to 'F j, Y' |
|
| 839 | - * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 840 | - * @return mixed string on success, FALSE on fail |
|
| 841 | - * @throws ReflectionException |
|
| 842 | - * @throws InvalidArgumentException |
|
| 843 | - * @throws InvalidInterfaceException |
|
| 844 | - * @throws InvalidDataTypeException |
|
| 845 | - * @throws EE_Error |
|
| 846 | - */ |
|
| 847 | - public function start_date_and_time($dt_format = '', $tm_format = '') |
|
| 848 | - { |
|
| 849 | - return $this->_show_datetime('', 'start', $dt_format, $tm_format); |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - |
|
| 853 | - /** |
|
| 854 | - * @param string $dt_frmt |
|
| 855 | - * @param string $tm_format |
|
| 856 | - * @throws ReflectionException |
|
| 857 | - * @throws InvalidArgumentException |
|
| 858 | - * @throws InvalidInterfaceException |
|
| 859 | - * @throws InvalidDataTypeException |
|
| 860 | - * @throws EE_Error |
|
| 861 | - */ |
|
| 862 | - public function e_start_date_and_time($dt_frmt = '', $tm_format = '') |
|
| 863 | - { |
|
| 864 | - $this->_show_datetime('', 'start', $dt_frmt, $tm_format, true); |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - |
|
| 868 | - /** |
|
| 869 | - * Shows the length of the event (start to end time). |
|
| 870 | - * Can be shown in 'seconds','minutes','hours', or 'days'. |
|
| 871 | - * By default, rounds up. (So if you use 'days', and then event |
|
| 872 | - * only occurs for 1 hour, it will return 1 day). |
|
| 873 | - * |
|
| 874 | - * @param string $units 'seconds','minutes','hours','days' |
|
| 875 | - * @param bool $round_up |
|
| 876 | - * @return float|int|mixed |
|
| 877 | - * @throws ReflectionException |
|
| 878 | - * @throws InvalidArgumentException |
|
| 879 | - * @throws InvalidInterfaceException |
|
| 880 | - * @throws InvalidDataTypeException |
|
| 881 | - * @throws EE_Error |
|
| 882 | - */ |
|
| 883 | - public function length($units = 'seconds', $round_up = false) |
|
| 884 | - { |
|
| 885 | - $start = $this->get_raw('DTT_EVT_start'); |
|
| 886 | - $end = $this->get_raw('DTT_EVT_end'); |
|
| 887 | - $length_in_units = $end - $start; |
|
| 888 | - switch ($units) { |
|
| 889 | - // NOTE: We purposefully don't use "break;" in order to chain the divisions |
|
| 890 | - /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 891 | - // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
| 892 | - case 'days': |
|
| 893 | - $length_in_units /= 24; |
|
| 894 | - /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 895 | - case 'hours': |
|
| 896 | - // fall through is intentional |
|
| 897 | - $length_in_units /= 60; |
|
| 898 | - /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 899 | - case 'minutes': |
|
| 900 | - // fall through is intentional |
|
| 901 | - $length_in_units /= 60; |
|
| 902 | - case 'seconds': |
|
| 903 | - default: |
|
| 904 | - $length_in_units = ceil($length_in_units); |
|
| 905 | - } |
|
| 906 | - // phpcs:enable |
|
| 907 | - if ($round_up) { |
|
| 908 | - $length_in_units = max($length_in_units, 1); |
|
| 909 | - } |
|
| 910 | - return $length_in_units; |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - |
|
| 914 | - /** |
|
| 915 | - * get end date and time |
|
| 916 | - * |
|
| 917 | - * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
| 918 | - * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 919 | - * @return mixed string on success, FALSE on fail |
|
| 920 | - * @throws ReflectionException |
|
| 921 | - * @throws InvalidArgumentException |
|
| 922 | - * @throws InvalidInterfaceException |
|
| 923 | - * @throws InvalidDataTypeException |
|
| 924 | - * @throws EE_Error |
|
| 925 | - */ |
|
| 926 | - public function end_date_and_time($dt_frmt = '', $tm_format = '') |
|
| 927 | - { |
|
| 928 | - return $this->_show_datetime('', 'end', $dt_frmt, $tm_format); |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - |
|
| 932 | - /** |
|
| 933 | - * @param string $dt_frmt |
|
| 934 | - * @param string $tm_format |
|
| 935 | - * @throws ReflectionException |
|
| 936 | - * @throws InvalidArgumentException |
|
| 937 | - * @throws InvalidInterfaceException |
|
| 938 | - * @throws InvalidDataTypeException |
|
| 939 | - * @throws EE_Error |
|
| 940 | - */ |
|
| 941 | - public function e_end_date_and_time($dt_frmt = '', $tm_format = '') |
|
| 942 | - { |
|
| 943 | - $this->_show_datetime('', 'end', $dt_frmt, $tm_format, true); |
|
| 944 | - } |
|
| 945 | - |
|
| 946 | - |
|
| 947 | - /** |
|
| 948 | - * get start timestamp |
|
| 949 | - * |
|
| 950 | - * @return int |
|
| 951 | - * @throws ReflectionException |
|
| 952 | - * @throws InvalidArgumentException |
|
| 953 | - * @throws InvalidInterfaceException |
|
| 954 | - * @throws InvalidDataTypeException |
|
| 955 | - * @throws EE_Error |
|
| 956 | - */ |
|
| 957 | - public function start() |
|
| 958 | - { |
|
| 959 | - return $this->get_raw('DTT_EVT_start'); |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - |
|
| 963 | - /** |
|
| 964 | - * get end timestamp |
|
| 965 | - * |
|
| 966 | - * @return int |
|
| 967 | - * @throws ReflectionException |
|
| 968 | - * @throws InvalidArgumentException |
|
| 969 | - * @throws InvalidInterfaceException |
|
| 970 | - * @throws InvalidDataTypeException |
|
| 971 | - * @throws EE_Error |
|
| 972 | - */ |
|
| 973 | - public function end() |
|
| 974 | - { |
|
| 975 | - return $this->get_raw('DTT_EVT_end'); |
|
| 976 | - } |
|
| 977 | - |
|
| 978 | - |
|
| 979 | - /** |
|
| 980 | - * get the registration limit for this datetime slot |
|
| 981 | - * |
|
| 982 | - * @return mixed int on success, FALSE on fail |
|
| 983 | - * @throws ReflectionException |
|
| 984 | - * @throws InvalidArgumentException |
|
| 985 | - * @throws InvalidInterfaceException |
|
| 986 | - * @throws InvalidDataTypeException |
|
| 987 | - * @throws EE_Error |
|
| 988 | - */ |
|
| 989 | - public function reg_limit() |
|
| 990 | - { |
|
| 991 | - return $this->get_raw('DTT_reg_limit'); |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - |
|
| 995 | - /** |
|
| 996 | - * have the tickets sold for this datetime, met or exceed the registration limit ? |
|
| 997 | - * |
|
| 998 | - * @return boolean |
|
| 999 | - * @throws ReflectionException |
|
| 1000 | - * @throws InvalidArgumentException |
|
| 1001 | - * @throws InvalidInterfaceException |
|
| 1002 | - * @throws InvalidDataTypeException |
|
| 1003 | - * @throws EE_Error |
|
| 1004 | - */ |
|
| 1005 | - public function sold_out() |
|
| 1006 | - { |
|
| 1007 | - return $this->reg_limit() > 0 && $this->sold() >= $this->reg_limit(); |
|
| 1008 | - } |
|
| 1009 | - |
|
| 1010 | - |
|
| 1011 | - /** |
|
| 1012 | - * return the total number of spaces remaining at this venue. |
|
| 1013 | - * This only takes the venue's capacity into account, NOT the tickets available for sale |
|
| 1014 | - * |
|
| 1015 | - * @param bool $consider_tickets Whether to consider tickets remaining when determining if there are any spaces left |
|
| 1016 | - * Because if all tickets attached to this datetime have no spaces left, |
|
| 1017 | - * then this datetime IS effectively sold out. |
|
| 1018 | - * However, there are cases where we just want to know the spaces |
|
| 1019 | - * remaining for this particular datetime, hence the flag. |
|
| 1020 | - * @return int |
|
| 1021 | - * @throws ReflectionException |
|
| 1022 | - * @throws InvalidArgumentException |
|
| 1023 | - * @throws InvalidInterfaceException |
|
| 1024 | - * @throws InvalidDataTypeException |
|
| 1025 | - * @throws EE_Error |
|
| 1026 | - */ |
|
| 1027 | - public function spaces_remaining($consider_tickets = false) |
|
| 1028 | - { |
|
| 1029 | - // tickets remaining available for purchase |
|
| 1030 | - // no need for special checks for infinite, because if DTT_reg_limit == EE_INF, then EE_INF - x = EE_INF |
|
| 1031 | - $dtt_remaining = $this->reg_limit() - $this->sold_and_reserved(); |
|
| 1032 | - if (! $consider_tickets) { |
|
| 1033 | - return $dtt_remaining; |
|
| 1034 | - } |
|
| 1035 | - $tickets_remaining = $this->tickets_remaining(); |
|
| 1036 | - return min($dtt_remaining, $tickets_remaining); |
|
| 1037 | - } |
|
| 1038 | - |
|
| 1039 | - |
|
| 1040 | - /** |
|
| 1041 | - * Counts the total tickets available |
|
| 1042 | - * (from all the different types of tickets which are available for this datetime). |
|
| 1043 | - * |
|
| 1044 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1045 | - * @return int |
|
| 1046 | - * @throws ReflectionException |
|
| 1047 | - * @throws InvalidArgumentException |
|
| 1048 | - * @throws InvalidInterfaceException |
|
| 1049 | - * @throws InvalidDataTypeException |
|
| 1050 | - * @throws EE_Error |
|
| 1051 | - */ |
|
| 1052 | - public function tickets_remaining($query_params = array()) |
|
| 1053 | - { |
|
| 1054 | - $sum = 0; |
|
| 1055 | - $tickets = $this->tickets($query_params); |
|
| 1056 | - if (! empty($tickets)) { |
|
| 1057 | - foreach ($tickets as $ticket) { |
|
| 1058 | - if ($ticket instanceof EE_Ticket) { |
|
| 1059 | - // get the actual amount of tickets that can be sold |
|
| 1060 | - $qty = $ticket->qty('saleable'); |
|
| 1061 | - if ($qty === EE_INF) { |
|
| 1062 | - return EE_INF; |
|
| 1063 | - } |
|
| 1064 | - // no negative ticket quantities plz |
|
| 1065 | - if ($qty > 0) { |
|
| 1066 | - $sum += $qty; |
|
| 1067 | - } |
|
| 1068 | - } |
|
| 1069 | - } |
|
| 1070 | - } |
|
| 1071 | - return $sum; |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - |
|
| 1075 | - /** |
|
| 1076 | - * Gets the count of all the tickets available at this datetime (not ticket types) |
|
| 1077 | - * before any were sold |
|
| 1078 | - * |
|
| 1079 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1080 | - * @return int |
|
| 1081 | - * @throws ReflectionException |
|
| 1082 | - * @throws InvalidArgumentException |
|
| 1083 | - * @throws InvalidInterfaceException |
|
| 1084 | - * @throws InvalidDataTypeException |
|
| 1085 | - * @throws EE_Error |
|
| 1086 | - */ |
|
| 1087 | - public function sum_tickets_initially_available($query_params = array()) |
|
| 1088 | - { |
|
| 1089 | - return $this->sum_related('Ticket', $query_params, 'TKT_qty'); |
|
| 1090 | - } |
|
| 1091 | - |
|
| 1092 | - |
|
| 1093 | - /** |
|
| 1094 | - * Returns the lesser-of-the two: spaces remaining at this datetime, or |
|
| 1095 | - * the total tickets remaining (a sum of the tickets remaining for each ticket type |
|
| 1096 | - * that is available for this datetime). |
|
| 1097 | - * |
|
| 1098 | - * @return int |
|
| 1099 | - * @throws ReflectionException |
|
| 1100 | - * @throws InvalidArgumentException |
|
| 1101 | - * @throws InvalidInterfaceException |
|
| 1102 | - * @throws InvalidDataTypeException |
|
| 1103 | - * @throws EE_Error |
|
| 1104 | - */ |
|
| 1105 | - public function total_tickets_available_at_this_datetime() |
|
| 1106 | - { |
|
| 1107 | - return $this->spaces_remaining(true); |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - |
|
| 1111 | - /** |
|
| 1112 | - * This simply compares the internal dtt for the given string with NOW |
|
| 1113 | - * and determines if the date is upcoming or not. |
|
| 1114 | - * |
|
| 1115 | - * @access public |
|
| 1116 | - * @return boolean |
|
| 1117 | - * @throws ReflectionException |
|
| 1118 | - * @throws InvalidArgumentException |
|
| 1119 | - * @throws InvalidInterfaceException |
|
| 1120 | - * @throws InvalidDataTypeException |
|
| 1121 | - * @throws EE_Error |
|
| 1122 | - */ |
|
| 1123 | - public function is_upcoming() |
|
| 1124 | - { |
|
| 1125 | - return ($this->get_raw('DTT_EVT_start') > time()); |
|
| 1126 | - } |
|
| 1127 | - |
|
| 1128 | - |
|
| 1129 | - /** |
|
| 1130 | - * This simply compares the internal datetime for the given string with NOW |
|
| 1131 | - * and returns if the date is active (i.e. start and end time) |
|
| 1132 | - * |
|
| 1133 | - * @return boolean |
|
| 1134 | - * @throws ReflectionException |
|
| 1135 | - * @throws InvalidArgumentException |
|
| 1136 | - * @throws InvalidInterfaceException |
|
| 1137 | - * @throws InvalidDataTypeException |
|
| 1138 | - * @throws EE_Error |
|
| 1139 | - */ |
|
| 1140 | - public function is_active() |
|
| 1141 | - { |
|
| 1142 | - return ($this->get_raw('DTT_EVT_start') < time() && $this->get_raw('DTT_EVT_end') > time()); |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - |
|
| 1146 | - /** |
|
| 1147 | - * This simply compares the internal dtt for the given string with NOW |
|
| 1148 | - * and determines if the date is expired or not. |
|
| 1149 | - * |
|
| 1150 | - * @return boolean |
|
| 1151 | - * @throws ReflectionException |
|
| 1152 | - * @throws InvalidArgumentException |
|
| 1153 | - * @throws InvalidInterfaceException |
|
| 1154 | - * @throws InvalidDataTypeException |
|
| 1155 | - * @throws EE_Error |
|
| 1156 | - */ |
|
| 1157 | - public function is_expired() |
|
| 1158 | - { |
|
| 1159 | - return ($this->get_raw('DTT_EVT_end') < time()); |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - |
|
| 1163 | - /** |
|
| 1164 | - * This returns the active status for whether an event is active, upcoming, or expired |
|
| 1165 | - * |
|
| 1166 | - * @return int return value will be one of the EE_Datetime status constants. |
|
| 1167 | - * @throws ReflectionException |
|
| 1168 | - * @throws InvalidArgumentException |
|
| 1169 | - * @throws InvalidInterfaceException |
|
| 1170 | - * @throws InvalidDataTypeException |
|
| 1171 | - * @throws EE_Error |
|
| 1172 | - */ |
|
| 1173 | - public function get_active_status() |
|
| 1174 | - { |
|
| 1175 | - $total_tickets_for_this_dtt = $this->total_tickets_available_at_this_datetime(); |
|
| 1176 | - if ($total_tickets_for_this_dtt !== false && $total_tickets_for_this_dtt < 1) { |
|
| 1177 | - return EE_Datetime::sold_out; |
|
| 1178 | - } |
|
| 1179 | - if ($this->is_expired()) { |
|
| 1180 | - return EE_Datetime::expired; |
|
| 1181 | - } |
|
| 1182 | - if ($this->is_upcoming()) { |
|
| 1183 | - return EE_Datetime::upcoming; |
|
| 1184 | - } |
|
| 1185 | - if ($this->is_active()) { |
|
| 1186 | - return EE_Datetime::active; |
|
| 1187 | - } |
|
| 1188 | - return null; |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - /** |
|
| 1193 | - * This returns a nice display name for the datetime that is contingent on the span between the dates and times. |
|
| 1194 | - * |
|
| 1195 | - * @param boolean $use_dtt_name if TRUE then we'll use DTT->name() if its not empty. |
|
| 1196 | - * @return string |
|
| 1197 | - * @throws ReflectionException |
|
| 1198 | - * @throws InvalidArgumentException |
|
| 1199 | - * @throws InvalidInterfaceException |
|
| 1200 | - * @throws InvalidDataTypeException |
|
| 1201 | - * @throws EE_Error |
|
| 1202 | - */ |
|
| 1203 | - public function get_dtt_display_name($use_dtt_name = false) |
|
| 1204 | - { |
|
| 1205 | - if ($use_dtt_name) { |
|
| 1206 | - $dtt_name = $this->name(); |
|
| 1207 | - if (! empty($dtt_name)) { |
|
| 1208 | - return $dtt_name; |
|
| 1209 | - } |
|
| 1210 | - } |
|
| 1211 | - // first condition is to see if the months are different |
|
| 1212 | - if (date('m', $this->get_raw('DTT_EVT_start')) !== date('m', $this->get_raw('DTT_EVT_end')) |
|
| 1213 | - ) { |
|
| 1214 | - $display_date = $this->start_date('M j\, Y g:i a') . ' - ' . $this->end_date('M j\, Y g:i a'); |
|
| 1215 | - // next condition is if its the same month but different day |
|
| 1216 | - } else { |
|
| 1217 | - if (date('m', $this->get_raw('DTT_EVT_start')) === date('m', $this->get_raw('DTT_EVT_end')) |
|
| 1218 | - && date('d', $this->get_raw('DTT_EVT_start')) !== date('d', $this->get_raw('DTT_EVT_end')) |
|
| 1219 | - ) { |
|
| 1220 | - $display_date = $this->start_date('M j\, g:i a') . ' - ' . $this->end_date('M j\, g:i a Y'); |
|
| 1221 | - } else { |
|
| 1222 | - $display_date = $this->start_date('F j\, Y') |
|
| 1223 | - . ' @ ' |
|
| 1224 | - . $this->start_date('g:i a') |
|
| 1225 | - . ' - ' |
|
| 1226 | - . $this->end_date('g:i a'); |
|
| 1227 | - } |
|
| 1228 | - } |
|
| 1229 | - return $display_date; |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - |
|
| 1233 | - /** |
|
| 1234 | - * Gets all the tickets for this datetime |
|
| 1235 | - * |
|
| 1236 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1237 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
| 1238 | - * @throws ReflectionException |
|
| 1239 | - * @throws InvalidArgumentException |
|
| 1240 | - * @throws InvalidInterfaceException |
|
| 1241 | - * @throws InvalidDataTypeException |
|
| 1242 | - * @throws EE_Error |
|
| 1243 | - */ |
|
| 1244 | - public function tickets($query_params = array()) |
|
| 1245 | - { |
|
| 1246 | - return $this->get_many_related('Ticket', $query_params); |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - |
|
| 1250 | - /** |
|
| 1251 | - * Gets all the ticket types currently available for purchase |
|
| 1252 | - * |
|
| 1253 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1254 | - * @return EE_Ticket[] |
|
| 1255 | - * @throws ReflectionException |
|
| 1256 | - * @throws InvalidArgumentException |
|
| 1257 | - * @throws InvalidInterfaceException |
|
| 1258 | - * @throws InvalidDataTypeException |
|
| 1259 | - * @throws EE_Error |
|
| 1260 | - */ |
|
| 1261 | - public function ticket_types_available_for_purchase($query_params = array()) |
|
| 1262 | - { |
|
| 1263 | - // first check if datetime is valid |
|
| 1264 | - if ($this->sold_out() || ! ($this->is_upcoming() || $this->is_active())) { |
|
| 1265 | - return array(); |
|
| 1266 | - } |
|
| 1267 | - if (empty($query_params)) { |
|
| 1268 | - $query_params = array( |
|
| 1269 | - array( |
|
| 1270 | - 'TKT_start_date' => array('<=', EEM_Ticket::instance()->current_time_for_query('TKT_start_date')), |
|
| 1271 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 1272 | - 'TKT_deleted' => false, |
|
| 1273 | - ), |
|
| 1274 | - ); |
|
| 1275 | - } |
|
| 1276 | - return $this->tickets($query_params); |
|
| 1277 | - } |
|
| 1278 | - |
|
| 1279 | - |
|
| 1280 | - /** |
|
| 1281 | - * @return EE_Base_Class|EE_Event |
|
| 1282 | - * @throws ReflectionException |
|
| 1283 | - * @throws InvalidArgumentException |
|
| 1284 | - * @throws InvalidInterfaceException |
|
| 1285 | - * @throws InvalidDataTypeException |
|
| 1286 | - * @throws EE_Error |
|
| 1287 | - */ |
|
| 1288 | - public function event() |
|
| 1289 | - { |
|
| 1290 | - return $this->get_first_related('Event'); |
|
| 1291 | - } |
|
| 1292 | - |
|
| 1293 | - |
|
| 1294 | - /** |
|
| 1295 | - * Updates the DTT_sold attribute (and saves) based on the number of registrations for this datetime |
|
| 1296 | - * (via the tickets). |
|
| 1297 | - * |
|
| 1298 | - * @return int |
|
| 1299 | - * @throws ReflectionException |
|
| 1300 | - * @throws InvalidArgumentException |
|
| 1301 | - * @throws InvalidInterfaceException |
|
| 1302 | - * @throws InvalidDataTypeException |
|
| 1303 | - * @throws EE_Error |
|
| 1304 | - */ |
|
| 1305 | - public function update_sold() |
|
| 1306 | - { |
|
| 1307 | - $count_regs_for_this_datetime = EEM_Registration::instance()->count( |
|
| 1308 | - array( |
|
| 1309 | - array( |
|
| 1310 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1311 | - 'REG_deleted' => 0, |
|
| 1312 | - 'Ticket.Datetime.DTT_ID' => $this->ID(), |
|
| 1313 | - ), |
|
| 1314 | - ) |
|
| 1315 | - ); |
|
| 1316 | - $this->set_sold($count_regs_for_this_datetime); |
|
| 1317 | - $this->save(); |
|
| 1318 | - return $count_regs_for_this_datetime; |
|
| 1319 | - } |
|
| 1320 | - |
|
| 1321 | - |
|
| 1322 | - /******************************************************************* |
|
| 16 | + /** |
|
| 17 | + * constant used by get_active_status, indicates datetime has no more available spaces |
|
| 18 | + */ |
|
| 19 | + const sold_out = 'DTS'; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * constant used by get_active_status, indicating datetime is still active (even is not over, can be registered-for) |
|
| 23 | + */ |
|
| 24 | + const active = 'DTA'; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * constant used by get_active_status, indicating the datetime cannot be used for registrations yet, but has not |
|
| 28 | + * expired |
|
| 29 | + */ |
|
| 30 | + const upcoming = 'DTU'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Datetime is postponed |
|
| 34 | + */ |
|
| 35 | + const postponed = 'DTP'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Datetime is cancelled |
|
| 39 | + */ |
|
| 40 | + const cancelled = 'DTC'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * constant used by get_active_status, indicates datetime has expired (event is over) |
|
| 44 | + */ |
|
| 45 | + const expired = 'DTE'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * constant used in various places indicating that an event is INACTIVE (not yet ready to be published) |
|
| 49 | + */ |
|
| 50 | + const inactive = 'DTI'; |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param array $props_n_values incoming values |
|
| 55 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be used.) |
|
| 56 | + * @param array $date_formats incoming date_formats in an array where the first value is the date_format |
|
| 57 | + * and the second value is the time format |
|
| 58 | + * @return EE_Datetime |
|
| 59 | + * @throws ReflectionException |
|
| 60 | + * @throws InvalidArgumentException |
|
| 61 | + * @throws InvalidInterfaceException |
|
| 62 | + * @throws InvalidDataTypeException |
|
| 63 | + * @throws EE_Error |
|
| 64 | + */ |
|
| 65 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 66 | + { |
|
| 67 | + $has_object = parent::_check_for_object( |
|
| 68 | + $props_n_values, |
|
| 69 | + __CLASS__, |
|
| 70 | + $timezone, |
|
| 71 | + $date_formats |
|
| 72 | + ); |
|
| 73 | + return $has_object |
|
| 74 | + ? $has_object |
|
| 75 | + : new self($props_n_values, false, $timezone, $date_formats); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @param array $props_n_values incoming values from the database |
|
| 81 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 82 | + * the website will be used. |
|
| 83 | + * @return EE_Datetime |
|
| 84 | + * @throws ReflectionException |
|
| 85 | + * @throws InvalidArgumentException |
|
| 86 | + * @throws InvalidInterfaceException |
|
| 87 | + * @throws InvalidDataTypeException |
|
| 88 | + * @throws EE_Error |
|
| 89 | + */ |
|
| 90 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 91 | + { |
|
| 92 | + return new self($props_n_values, true, $timezone); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @param $name |
|
| 98 | + * @throws ReflectionException |
|
| 99 | + * @throws InvalidArgumentException |
|
| 100 | + * @throws InvalidInterfaceException |
|
| 101 | + * @throws InvalidDataTypeException |
|
| 102 | + * @throws EE_Error |
|
| 103 | + */ |
|
| 104 | + public function set_name($name) |
|
| 105 | + { |
|
| 106 | + $this->set('DTT_name', $name); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @param $description |
|
| 112 | + * @throws ReflectionException |
|
| 113 | + * @throws InvalidArgumentException |
|
| 114 | + * @throws InvalidInterfaceException |
|
| 115 | + * @throws InvalidDataTypeException |
|
| 116 | + * @throws EE_Error |
|
| 117 | + */ |
|
| 118 | + public function set_description($description) |
|
| 119 | + { |
|
| 120 | + $this->set('DTT_description', $description); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Set event start date |
|
| 126 | + * set the start date for an event |
|
| 127 | + * |
|
| 128 | + * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 |
|
| 129 | + * @throws ReflectionException |
|
| 130 | + * @throws InvalidArgumentException |
|
| 131 | + * @throws InvalidInterfaceException |
|
| 132 | + * @throws InvalidDataTypeException |
|
| 133 | + * @throws EE_Error |
|
| 134 | + */ |
|
| 135 | + public function set_start_date($date) |
|
| 136 | + { |
|
| 137 | + $this->_set_date_for($date, 'DTT_EVT_start'); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Set event start time |
|
| 143 | + * set the start time for an event |
|
| 144 | + * |
|
| 145 | + * @param string $time a string representation of the event time ex: 9am or 7:30 PM |
|
| 146 | + * @throws ReflectionException |
|
| 147 | + * @throws InvalidArgumentException |
|
| 148 | + * @throws InvalidInterfaceException |
|
| 149 | + * @throws InvalidDataTypeException |
|
| 150 | + * @throws EE_Error |
|
| 151 | + */ |
|
| 152 | + public function set_start_time($time) |
|
| 153 | + { |
|
| 154 | + $this->_set_time_for($time, 'DTT_EVT_start'); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Set event end date |
|
| 160 | + * set the end date for an event |
|
| 161 | + * |
|
| 162 | + * @param string $date a string representation of the event's date ex: Dec. 25, 2025 or 12-25-2025 |
|
| 163 | + * @throws ReflectionException |
|
| 164 | + * @throws InvalidArgumentException |
|
| 165 | + * @throws InvalidInterfaceException |
|
| 166 | + * @throws InvalidDataTypeException |
|
| 167 | + * @throws EE_Error |
|
| 168 | + */ |
|
| 169 | + public function set_end_date($date) |
|
| 170 | + { |
|
| 171 | + $this->_set_date_for($date, 'DTT_EVT_end'); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Set event end time |
|
| 177 | + * set the end time for an event |
|
| 178 | + * |
|
| 179 | + * @param string $time a string representation of the event time ex: 9am or 7:30 PM |
|
| 180 | + * @throws ReflectionException |
|
| 181 | + * @throws InvalidArgumentException |
|
| 182 | + * @throws InvalidInterfaceException |
|
| 183 | + * @throws InvalidDataTypeException |
|
| 184 | + * @throws EE_Error |
|
| 185 | + */ |
|
| 186 | + public function set_end_time($time) |
|
| 187 | + { |
|
| 188 | + $this->_set_time_for($time, 'DTT_EVT_end'); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Set registration limit |
|
| 194 | + * set the maximum number of attendees that can be registered for this datetime slot |
|
| 195 | + * |
|
| 196 | + * @param int $reg_limit |
|
| 197 | + * @throws ReflectionException |
|
| 198 | + * @throws InvalidArgumentException |
|
| 199 | + * @throws InvalidInterfaceException |
|
| 200 | + * @throws InvalidDataTypeException |
|
| 201 | + * @throws EE_Error |
|
| 202 | + */ |
|
| 203 | + public function set_reg_limit($reg_limit) |
|
| 204 | + { |
|
| 205 | + $this->set('DTT_reg_limit', $reg_limit); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * get the number of tickets sold for this datetime slot |
|
| 211 | + * |
|
| 212 | + * @return mixed int on success, FALSE on fail |
|
| 213 | + * @throws ReflectionException |
|
| 214 | + * @throws InvalidArgumentException |
|
| 215 | + * @throws InvalidInterfaceException |
|
| 216 | + * @throws InvalidDataTypeException |
|
| 217 | + * @throws EE_Error |
|
| 218 | + */ |
|
| 219 | + public function sold() |
|
| 220 | + { |
|
| 221 | + return $this->get_raw('DTT_sold'); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * @param int $sold |
|
| 227 | + * @throws ReflectionException |
|
| 228 | + * @throws InvalidArgumentException |
|
| 229 | + * @throws InvalidInterfaceException |
|
| 230 | + * @throws InvalidDataTypeException |
|
| 231 | + * @throws EE_Error |
|
| 232 | + */ |
|
| 233 | + public function set_sold($sold) |
|
| 234 | + { |
|
| 235 | + // sold can not go below zero |
|
| 236 | + $sold = max(0, $sold); |
|
| 237 | + $this->set('DTT_sold', $sold); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Increments sold by amount passed by $qty, and persists it immediately to the database. |
|
| 243 | + * Simultaneously decreases the reserved count, unless $also_decrease_reserved is false. |
|
| 244 | + * |
|
| 245 | + * @param int $qty |
|
| 246 | + * @param boolean $also_decrease_reserved |
|
| 247 | + * @return boolean indicating success |
|
| 248 | + * @throws ReflectionException |
|
| 249 | + * @throws InvalidArgumentException |
|
| 250 | + * @throws InvalidInterfaceException |
|
| 251 | + * @throws InvalidDataTypeException |
|
| 252 | + * @throws EE_Error |
|
| 253 | + */ |
|
| 254 | + public function increaseSold($qty = 1, $also_decrease_reserved = true) |
|
| 255 | + { |
|
| 256 | + $qty = absint($qty); |
|
| 257 | + if ($also_decrease_reserved) { |
|
| 258 | + $success = $this->adjustNumericFieldsInDb( |
|
| 259 | + [ |
|
| 260 | + 'DTT_reserved' => $qty * -1, |
|
| 261 | + 'DTT_sold' => $qty |
|
| 262 | + ] |
|
| 263 | + ); |
|
| 264 | + } else { |
|
| 265 | + $success = $this->adjustNumericFieldsInDb( |
|
| 266 | + [ |
|
| 267 | + 'DTT_sold' => $qty |
|
| 268 | + ] |
|
| 269 | + ); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + do_action( |
|
| 273 | + 'AHEE__EE_Datetime__increase_sold', |
|
| 274 | + $this, |
|
| 275 | + $qty, |
|
| 276 | + $this->sold(), |
|
| 277 | + $success |
|
| 278 | + ); |
|
| 279 | + return $success; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Decrements (subtracts) sold amount passed by $qty directly in the DB and on the model object. (Ie, no need |
|
| 285 | + * to save afterwards.) |
|
| 286 | + * |
|
| 287 | + * @param int $qty |
|
| 288 | + * @return boolean indicating success |
|
| 289 | + * @throws ReflectionException |
|
| 290 | + * @throws InvalidArgumentException |
|
| 291 | + * @throws InvalidInterfaceException |
|
| 292 | + * @throws InvalidDataTypeException |
|
| 293 | + * @throws EE_Error |
|
| 294 | + */ |
|
| 295 | + public function decreaseSold($qty = 1) |
|
| 296 | + { |
|
| 297 | + $qty = absint($qty); |
|
| 298 | + $success = $this->adjustNumericFieldsInDb( |
|
| 299 | + [ |
|
| 300 | + 'DTT_sold' => $qty * -1 |
|
| 301 | + ] |
|
| 302 | + ); |
|
| 303 | + do_action( |
|
| 304 | + 'AHEE__EE_Datetime__decrease_sold', |
|
| 305 | + $this, |
|
| 306 | + $qty, |
|
| 307 | + $this->sold(), |
|
| 308 | + $success |
|
| 309 | + ); |
|
| 310 | + return $success; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Gets qty of reserved tickets for this datetime |
|
| 316 | + * |
|
| 317 | + * @return int |
|
| 318 | + * @throws ReflectionException |
|
| 319 | + * @throws InvalidArgumentException |
|
| 320 | + * @throws InvalidInterfaceException |
|
| 321 | + * @throws InvalidDataTypeException |
|
| 322 | + * @throws EE_Error |
|
| 323 | + */ |
|
| 324 | + public function reserved() |
|
| 325 | + { |
|
| 326 | + return $this->get_raw('DTT_reserved'); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Sets qty of reserved tickets for this datetime |
|
| 332 | + * |
|
| 333 | + * @param int $reserved |
|
| 334 | + * @throws ReflectionException |
|
| 335 | + * @throws InvalidArgumentException |
|
| 336 | + * @throws InvalidInterfaceException |
|
| 337 | + * @throws InvalidDataTypeException |
|
| 338 | + * @throws EE_Error |
|
| 339 | + */ |
|
| 340 | + public function set_reserved($reserved) |
|
| 341 | + { |
|
| 342 | + // reserved can not go below zero |
|
| 343 | + $reserved = max(0, (int) $reserved); |
|
| 344 | + $this->set('DTT_reserved', $reserved); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 350 | + * |
|
| 351 | + * @param int $qty |
|
| 352 | + * @return boolean indicating success |
|
| 353 | + * @throws ReflectionException |
|
| 354 | + * @throws InvalidArgumentException |
|
| 355 | + * @throws InvalidInterfaceException |
|
| 356 | + * @throws InvalidDataTypeException |
|
| 357 | + * @throws EE_Error |
|
| 358 | + */ |
|
| 359 | + public function increaseReserved($qty = 1) |
|
| 360 | + { |
|
| 361 | + $qty = absint($qty); |
|
| 362 | + $success = $this->incrementFieldConditionallyInDb( |
|
| 363 | + 'DTT_reserved', |
|
| 364 | + 'DTT_sold', |
|
| 365 | + 'DTT_reg_limit', |
|
| 366 | + $qty |
|
| 367 | + ); |
|
| 368 | + do_action( |
|
| 369 | + 'AHEE__EE_Datetime__increase_reserved', |
|
| 370 | + $this, |
|
| 371 | + $qty, |
|
| 372 | + $this->reserved(), |
|
| 373 | + $success |
|
| 374 | + ); |
|
| 375 | + return $success; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 381 | + * |
|
| 382 | + * @param int $qty |
|
| 383 | + * @return boolean indicating success |
|
| 384 | + * @throws ReflectionException |
|
| 385 | + * @throws InvalidArgumentException |
|
| 386 | + * @throws InvalidInterfaceException |
|
| 387 | + * @throws InvalidDataTypeException |
|
| 388 | + * @throws EE_Error |
|
| 389 | + */ |
|
| 390 | + public function decreaseReserved($qty = 1) |
|
| 391 | + { |
|
| 392 | + $qty = absint($qty); |
|
| 393 | + $success = $this->adjustNumericFieldsInDb( |
|
| 394 | + [ |
|
| 395 | + 'DTT_reserved' => $qty * -1 |
|
| 396 | + ] |
|
| 397 | + ); |
|
| 398 | + do_action( |
|
| 399 | + 'AHEE__EE_Datetime__decrease_reserved', |
|
| 400 | + $this, |
|
| 401 | + $qty, |
|
| 402 | + $this->reserved(), |
|
| 403 | + $success |
|
| 404 | + ); |
|
| 405 | + return $success; |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * total sold and reserved tickets |
|
| 411 | + * |
|
| 412 | + * @return int |
|
| 413 | + * @throws ReflectionException |
|
| 414 | + * @throws InvalidArgumentException |
|
| 415 | + * @throws InvalidInterfaceException |
|
| 416 | + * @throws InvalidDataTypeException |
|
| 417 | + * @throws EE_Error |
|
| 418 | + */ |
|
| 419 | + public function sold_and_reserved() |
|
| 420 | + { |
|
| 421 | + return $this->sold() + $this->reserved(); |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * returns the datetime name |
|
| 427 | + * |
|
| 428 | + * @return string |
|
| 429 | + * @throws ReflectionException |
|
| 430 | + * @throws InvalidArgumentException |
|
| 431 | + * @throws InvalidInterfaceException |
|
| 432 | + * @throws InvalidDataTypeException |
|
| 433 | + * @throws EE_Error |
|
| 434 | + */ |
|
| 435 | + public function name() |
|
| 436 | + { |
|
| 437 | + return $this->get('DTT_name'); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * returns the datetime description |
|
| 443 | + * |
|
| 444 | + * @return string |
|
| 445 | + * @throws ReflectionException |
|
| 446 | + * @throws InvalidArgumentException |
|
| 447 | + * @throws InvalidInterfaceException |
|
| 448 | + * @throws InvalidDataTypeException |
|
| 449 | + * @throws EE_Error |
|
| 450 | + */ |
|
| 451 | + public function description() |
|
| 452 | + { |
|
| 453 | + return $this->get('DTT_description'); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * This helper simply returns whether the event_datetime for the current datetime is a primary datetime |
|
| 459 | + * |
|
| 460 | + * @return boolean TRUE if is primary, FALSE if not. |
|
| 461 | + * @throws ReflectionException |
|
| 462 | + * @throws InvalidArgumentException |
|
| 463 | + * @throws InvalidInterfaceException |
|
| 464 | + * @throws InvalidDataTypeException |
|
| 465 | + * @throws EE_Error |
|
| 466 | + */ |
|
| 467 | + public function is_primary() |
|
| 468 | + { |
|
| 469 | + return $this->get('DTT_is_primary'); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * This helper simply returns the order for the datetime |
|
| 475 | + * |
|
| 476 | + * @return int The order of the datetime for this event. |
|
| 477 | + * @throws ReflectionException |
|
| 478 | + * @throws InvalidArgumentException |
|
| 479 | + * @throws InvalidInterfaceException |
|
| 480 | + * @throws InvalidDataTypeException |
|
| 481 | + * @throws EE_Error |
|
| 482 | + */ |
|
| 483 | + public function order() |
|
| 484 | + { |
|
| 485 | + return $this->get('DTT_order'); |
|
| 486 | + } |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * This helper simply returns the parent id for the datetime |
|
| 491 | + * |
|
| 492 | + * @return int |
|
| 493 | + * @throws ReflectionException |
|
| 494 | + * @throws InvalidArgumentException |
|
| 495 | + * @throws InvalidInterfaceException |
|
| 496 | + * @throws InvalidDataTypeException |
|
| 497 | + * @throws EE_Error |
|
| 498 | + */ |
|
| 499 | + public function parent() |
|
| 500 | + { |
|
| 501 | + return $this->get('DTT_parent'); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * show date and/or time |
|
| 507 | + * |
|
| 508 | + * @param string $date_or_time whether to display a date or time or both |
|
| 509 | + * @param string $start_or_end whether to display start or end datetimes |
|
| 510 | + * @param string $dt_frmt |
|
| 511 | + * @param string $tm_frmt |
|
| 512 | + * @param bool $echo whether we echo or return (note echoing uses "pretty" formats, |
|
| 513 | + * otherwise we use the standard formats) |
|
| 514 | + * @return string|bool string on success, FALSE on fail |
|
| 515 | + * @throws ReflectionException |
|
| 516 | + * @throws InvalidArgumentException |
|
| 517 | + * @throws InvalidInterfaceException |
|
| 518 | + * @throws InvalidDataTypeException |
|
| 519 | + * @throws EE_Error |
|
| 520 | + */ |
|
| 521 | + private function _show_datetime( |
|
| 522 | + $date_or_time = null, |
|
| 523 | + $start_or_end = 'start', |
|
| 524 | + $dt_frmt = '', |
|
| 525 | + $tm_frmt = '', |
|
| 526 | + $echo = false |
|
| 527 | + ) { |
|
| 528 | + $field_name = "DTT_EVT_{$start_or_end}"; |
|
| 529 | + $dtt = $this->_get_datetime( |
|
| 530 | + $field_name, |
|
| 531 | + $dt_frmt, |
|
| 532 | + $tm_frmt, |
|
| 533 | + $date_or_time, |
|
| 534 | + $echo |
|
| 535 | + ); |
|
| 536 | + if (! $echo) { |
|
| 537 | + return $dtt; |
|
| 538 | + } |
|
| 539 | + return ''; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * get event start date. Provide either the date format, or NULL to re-use the |
|
| 545 | + * last-used format, or '' to use the default date format |
|
| 546 | + * |
|
| 547 | + * @param string $dt_frmt string representation of date format defaults to 'F j, Y' |
|
| 548 | + * @return mixed string on success, FALSE on fail |
|
| 549 | + * @throws ReflectionException |
|
| 550 | + * @throws InvalidArgumentException |
|
| 551 | + * @throws InvalidInterfaceException |
|
| 552 | + * @throws InvalidDataTypeException |
|
| 553 | + * @throws EE_Error |
|
| 554 | + */ |
|
| 555 | + public function start_date($dt_frmt = '') |
|
| 556 | + { |
|
| 557 | + return $this->_show_datetime('D', 'start', $dt_frmt); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * Echoes start_date() |
|
| 563 | + * |
|
| 564 | + * @param string $dt_frmt |
|
| 565 | + * @throws ReflectionException |
|
| 566 | + * @throws InvalidArgumentException |
|
| 567 | + * @throws InvalidInterfaceException |
|
| 568 | + * @throws InvalidDataTypeException |
|
| 569 | + * @throws EE_Error |
|
| 570 | + */ |
|
| 571 | + public function e_start_date($dt_frmt = '') |
|
| 572 | + { |
|
| 573 | + $this->_show_datetime('D', 'start', $dt_frmt, null, true); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + |
|
| 577 | + /** |
|
| 578 | + * get end date. Provide either the date format, or NULL to re-use the |
|
| 579 | + * last-used format, or '' to use the default date format |
|
| 580 | + * |
|
| 581 | + * @param string $dt_frmt string representation of date format defaults to 'F j, Y' |
|
| 582 | + * @return mixed string on success, FALSE on fail |
|
| 583 | + * @throws ReflectionException |
|
| 584 | + * @throws InvalidArgumentException |
|
| 585 | + * @throws InvalidInterfaceException |
|
| 586 | + * @throws InvalidDataTypeException |
|
| 587 | + * @throws EE_Error |
|
| 588 | + */ |
|
| 589 | + public function end_date($dt_frmt = '') |
|
| 590 | + { |
|
| 591 | + return $this->_show_datetime('D', 'end', $dt_frmt); |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Echoes the end date. See end_date() |
|
| 597 | + * |
|
| 598 | + * @param string $dt_frmt |
|
| 599 | + * @throws ReflectionException |
|
| 600 | + * @throws InvalidArgumentException |
|
| 601 | + * @throws InvalidInterfaceException |
|
| 602 | + * @throws InvalidDataTypeException |
|
| 603 | + * @throws EE_Error |
|
| 604 | + */ |
|
| 605 | + public function e_end_date($dt_frmt = '') |
|
| 606 | + { |
|
| 607 | + $this->_show_datetime('D', 'end', $dt_frmt, null, true); |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * get date_range - meaning the start AND end date |
|
| 613 | + * |
|
| 614 | + * @access public |
|
| 615 | + * @param string $dt_frmt string representation of date format defaults to WP settings |
|
| 616 | + * @param string $conjunction conjunction junction what's your function ? |
|
| 617 | + * this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
| 618 | + * @return mixed string on success, FALSE on fail |
|
| 619 | + * @throws ReflectionException |
|
| 620 | + * @throws InvalidArgumentException |
|
| 621 | + * @throws InvalidInterfaceException |
|
| 622 | + * @throws InvalidDataTypeException |
|
| 623 | + * @throws EE_Error |
|
| 624 | + */ |
|
| 625 | + public function date_range($dt_frmt = '', $conjunction = ' - ') |
|
| 626 | + { |
|
| 627 | + $dt_frmt = ! empty($dt_frmt) ? $dt_frmt : $this->_dt_frmt; |
|
| 628 | + $start = str_replace( |
|
| 629 | + ' ', |
|
| 630 | + ' ', |
|
| 631 | + $this->get_i18n_datetime('DTT_EVT_start', $dt_frmt) |
|
| 632 | + ); |
|
| 633 | + $end = str_replace( |
|
| 634 | + ' ', |
|
| 635 | + ' ', |
|
| 636 | + $this->get_i18n_datetime('DTT_EVT_end', $dt_frmt) |
|
| 637 | + ); |
|
| 638 | + return $start !== $end ? $start . $conjunction . $end : $start; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + |
|
| 642 | + /** |
|
| 643 | + * @param string $dt_frmt |
|
| 644 | + * @param string $conjunction |
|
| 645 | + * @throws ReflectionException |
|
| 646 | + * @throws InvalidArgumentException |
|
| 647 | + * @throws InvalidInterfaceException |
|
| 648 | + * @throws InvalidDataTypeException |
|
| 649 | + * @throws EE_Error |
|
| 650 | + */ |
|
| 651 | + public function e_date_range($dt_frmt = '', $conjunction = ' - ') |
|
| 652 | + { |
|
| 653 | + echo $this->date_range($dt_frmt, $conjunction); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + |
|
| 657 | + /** |
|
| 658 | + * get start time |
|
| 659 | + * |
|
| 660 | + * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 661 | + * @return mixed string on success, FALSE on fail |
|
| 662 | + * @throws ReflectionException |
|
| 663 | + * @throws InvalidArgumentException |
|
| 664 | + * @throws InvalidInterfaceException |
|
| 665 | + * @throws InvalidDataTypeException |
|
| 666 | + * @throws EE_Error |
|
| 667 | + */ |
|
| 668 | + public function start_time($tm_format = '') |
|
| 669 | + { |
|
| 670 | + return $this->_show_datetime('T', 'start', null, $tm_format); |
|
| 671 | + } |
|
| 672 | + |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * @param string $tm_format |
|
| 676 | + * @throws ReflectionException |
|
| 677 | + * @throws InvalidArgumentException |
|
| 678 | + * @throws InvalidInterfaceException |
|
| 679 | + * @throws InvalidDataTypeException |
|
| 680 | + * @throws EE_Error |
|
| 681 | + */ |
|
| 682 | + public function e_start_time($tm_format = '') |
|
| 683 | + { |
|
| 684 | + $this->_show_datetime('T', 'start', null, $tm_format, true); |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * get end time |
|
| 690 | + * |
|
| 691 | + * @param string $tm_format string representation of time format defaults to 'g:i a' |
|
| 692 | + * @return mixed string on success, FALSE on fail |
|
| 693 | + * @throws ReflectionException |
|
| 694 | + * @throws InvalidArgumentException |
|
| 695 | + * @throws InvalidInterfaceException |
|
| 696 | + * @throws InvalidDataTypeException |
|
| 697 | + * @throws EE_Error |
|
| 698 | + */ |
|
| 699 | + public function end_time($tm_format = '') |
|
| 700 | + { |
|
| 701 | + return $this->_show_datetime('T', 'end', null, $tm_format); |
|
| 702 | + } |
|
| 703 | + |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * @param string $tm_format |
|
| 707 | + * @throws ReflectionException |
|
| 708 | + * @throws InvalidArgumentException |
|
| 709 | + * @throws InvalidInterfaceException |
|
| 710 | + * @throws InvalidDataTypeException |
|
| 711 | + * @throws EE_Error |
|
| 712 | + */ |
|
| 713 | + public function e_end_time($tm_format = '') |
|
| 714 | + { |
|
| 715 | + $this->_show_datetime('T', 'end', null, $tm_format, true); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + |
|
| 719 | + /** |
|
| 720 | + * get time_range |
|
| 721 | + * |
|
| 722 | + * @access public |
|
| 723 | + * @param string $tm_format string representation of time format defaults to 'g:i a' |
|
| 724 | + * @param string $conjunction conjunction junction what's your function ? |
|
| 725 | + * this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
| 726 | + * @return mixed string on success, FALSE on fail |
|
| 727 | + * @throws ReflectionException |
|
| 728 | + * @throws InvalidArgumentException |
|
| 729 | + * @throws InvalidInterfaceException |
|
| 730 | + * @throws InvalidDataTypeException |
|
| 731 | + * @throws EE_Error |
|
| 732 | + */ |
|
| 733 | + public function time_range($tm_format = '', $conjunction = ' - ') |
|
| 734 | + { |
|
| 735 | + $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt; |
|
| 736 | + $start = str_replace( |
|
| 737 | + ' ', |
|
| 738 | + ' ', |
|
| 739 | + $this->get_i18n_datetime('DTT_EVT_start', $tm_format) |
|
| 740 | + ); |
|
| 741 | + $end = str_replace( |
|
| 742 | + ' ', |
|
| 743 | + ' ', |
|
| 744 | + $this->get_i18n_datetime('DTT_EVT_end', $tm_format) |
|
| 745 | + ); |
|
| 746 | + return $start !== $end ? $start . $conjunction . $end : $start; |
|
| 747 | + } |
|
| 748 | + |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * @param string $tm_format |
|
| 752 | + * @param string $conjunction |
|
| 753 | + * @throws ReflectionException |
|
| 754 | + * @throws InvalidArgumentException |
|
| 755 | + * @throws InvalidInterfaceException |
|
| 756 | + * @throws InvalidDataTypeException |
|
| 757 | + * @throws EE_Error |
|
| 758 | + */ |
|
| 759 | + public function e_time_range($tm_format = '', $conjunction = ' - ') |
|
| 760 | + { |
|
| 761 | + echo $this->time_range($tm_format, $conjunction); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + |
|
| 765 | + /** |
|
| 766 | + * This returns a range representation of the date and times. |
|
| 767 | + * Output is dependent on the difference (or similarity) between DTT_EVT_start and DTT_EVT_end. |
|
| 768 | + * Also, the return value is localized. |
|
| 769 | + * |
|
| 770 | + * @param string $dt_format |
|
| 771 | + * @param string $tm_format |
|
| 772 | + * @param string $conjunction used between two different dates or times. |
|
| 773 | + * ex: Dec 1{$conjunction}}Dec 6, or 2pm{$conjunction}3pm |
|
| 774 | + * @param string $separator used between the date and time formats. |
|
| 775 | + * ex: Dec 1, 2016{$separator}2pm |
|
| 776 | + * @return string |
|
| 777 | + * @throws ReflectionException |
|
| 778 | + * @throws InvalidArgumentException |
|
| 779 | + * @throws InvalidInterfaceException |
|
| 780 | + * @throws InvalidDataTypeException |
|
| 781 | + * @throws EE_Error |
|
| 782 | + */ |
|
| 783 | + public function date_and_time_range( |
|
| 784 | + $dt_format = '', |
|
| 785 | + $tm_format = '', |
|
| 786 | + $conjunction = ' - ', |
|
| 787 | + $separator = ' ' |
|
| 788 | + ) { |
|
| 789 | + $dt_format = ! empty($dt_format) ? $dt_format : $this->_dt_frmt; |
|
| 790 | + $tm_format = ! empty($tm_format) ? $tm_format : $this->_tm_frmt; |
|
| 791 | + $full_format = $dt_format . $separator . $tm_format; |
|
| 792 | + // the range output depends on various conditions |
|
| 793 | + switch (true) { |
|
| 794 | + // start date timestamp and end date timestamp are the same. |
|
| 795 | + case ($this->get_raw('DTT_EVT_start') === $this->get_raw('DTT_EVT_end')): |
|
| 796 | + $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format); |
|
| 797 | + break; |
|
| 798 | + // start and end date are the same but times are different |
|
| 799 | + case ($this->start_date() === $this->end_date()): |
|
| 800 | + $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format) |
|
| 801 | + . $conjunction |
|
| 802 | + . $this->get_i18n_datetime('DTT_EVT_end', $tm_format); |
|
| 803 | + break; |
|
| 804 | + // all other conditions |
|
| 805 | + default: |
|
| 806 | + $output = $this->get_i18n_datetime('DTT_EVT_start', $full_format) |
|
| 807 | + . $conjunction |
|
| 808 | + . $this->get_i18n_datetime('DTT_EVT_end', $full_format); |
|
| 809 | + break; |
|
| 810 | + } |
|
| 811 | + return $output; |
|
| 812 | + } |
|
| 813 | + |
|
| 814 | + |
|
| 815 | + /** |
|
| 816 | + * This echos the results of date and time range. |
|
| 817 | + * |
|
| 818 | + * @see date_and_time_range() for more details on purpose. |
|
| 819 | + * @param string $dt_format |
|
| 820 | + * @param string $tm_format |
|
| 821 | + * @param string $conjunction |
|
| 822 | + * @return void |
|
| 823 | + * @throws ReflectionException |
|
| 824 | + * @throws InvalidArgumentException |
|
| 825 | + * @throws InvalidInterfaceException |
|
| 826 | + * @throws InvalidDataTypeException |
|
| 827 | + * @throws EE_Error |
|
| 828 | + */ |
|
| 829 | + public function e_date_and_time_range($dt_format = '', $tm_format = '', $conjunction = ' - ') |
|
| 830 | + { |
|
| 831 | + echo $this->date_and_time_range($dt_format, $tm_format, $conjunction); |
|
| 832 | + } |
|
| 833 | + |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * get start date and start time |
|
| 837 | + * |
|
| 838 | + * @param string $dt_format - string representation of date format defaults to 'F j, Y' |
|
| 839 | + * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 840 | + * @return mixed string on success, FALSE on fail |
|
| 841 | + * @throws ReflectionException |
|
| 842 | + * @throws InvalidArgumentException |
|
| 843 | + * @throws InvalidInterfaceException |
|
| 844 | + * @throws InvalidDataTypeException |
|
| 845 | + * @throws EE_Error |
|
| 846 | + */ |
|
| 847 | + public function start_date_and_time($dt_format = '', $tm_format = '') |
|
| 848 | + { |
|
| 849 | + return $this->_show_datetime('', 'start', $dt_format, $tm_format); |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + |
|
| 853 | + /** |
|
| 854 | + * @param string $dt_frmt |
|
| 855 | + * @param string $tm_format |
|
| 856 | + * @throws ReflectionException |
|
| 857 | + * @throws InvalidArgumentException |
|
| 858 | + * @throws InvalidInterfaceException |
|
| 859 | + * @throws InvalidDataTypeException |
|
| 860 | + * @throws EE_Error |
|
| 861 | + */ |
|
| 862 | + public function e_start_date_and_time($dt_frmt = '', $tm_format = '') |
|
| 863 | + { |
|
| 864 | + $this->_show_datetime('', 'start', $dt_frmt, $tm_format, true); |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + |
|
| 868 | + /** |
|
| 869 | + * Shows the length of the event (start to end time). |
|
| 870 | + * Can be shown in 'seconds','minutes','hours', or 'days'. |
|
| 871 | + * By default, rounds up. (So if you use 'days', and then event |
|
| 872 | + * only occurs for 1 hour, it will return 1 day). |
|
| 873 | + * |
|
| 874 | + * @param string $units 'seconds','minutes','hours','days' |
|
| 875 | + * @param bool $round_up |
|
| 876 | + * @return float|int|mixed |
|
| 877 | + * @throws ReflectionException |
|
| 878 | + * @throws InvalidArgumentException |
|
| 879 | + * @throws InvalidInterfaceException |
|
| 880 | + * @throws InvalidDataTypeException |
|
| 881 | + * @throws EE_Error |
|
| 882 | + */ |
|
| 883 | + public function length($units = 'seconds', $round_up = false) |
|
| 884 | + { |
|
| 885 | + $start = $this->get_raw('DTT_EVT_start'); |
|
| 886 | + $end = $this->get_raw('DTT_EVT_end'); |
|
| 887 | + $length_in_units = $end - $start; |
|
| 888 | + switch ($units) { |
|
| 889 | + // NOTE: We purposefully don't use "break;" in order to chain the divisions |
|
| 890 | + /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 891 | + // phpcs:disable PSR2.ControlStructures.SwitchDeclaration.TerminatingComment |
|
| 892 | + case 'days': |
|
| 893 | + $length_in_units /= 24; |
|
| 894 | + /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 895 | + case 'hours': |
|
| 896 | + // fall through is intentional |
|
| 897 | + $length_in_units /= 60; |
|
| 898 | + /** @noinspection PhpMissingBreakStatementInspection */ |
|
| 899 | + case 'minutes': |
|
| 900 | + // fall through is intentional |
|
| 901 | + $length_in_units /= 60; |
|
| 902 | + case 'seconds': |
|
| 903 | + default: |
|
| 904 | + $length_in_units = ceil($length_in_units); |
|
| 905 | + } |
|
| 906 | + // phpcs:enable |
|
| 907 | + if ($round_up) { |
|
| 908 | + $length_in_units = max($length_in_units, 1); |
|
| 909 | + } |
|
| 910 | + return $length_in_units; |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + |
|
| 914 | + /** |
|
| 915 | + * get end date and time |
|
| 916 | + * |
|
| 917 | + * @param string $dt_frmt - string representation of date format defaults to 'F j, Y' |
|
| 918 | + * @param string $tm_format - string representation of time format defaults to 'g:i a' |
|
| 919 | + * @return mixed string on success, FALSE on fail |
|
| 920 | + * @throws ReflectionException |
|
| 921 | + * @throws InvalidArgumentException |
|
| 922 | + * @throws InvalidInterfaceException |
|
| 923 | + * @throws InvalidDataTypeException |
|
| 924 | + * @throws EE_Error |
|
| 925 | + */ |
|
| 926 | + public function end_date_and_time($dt_frmt = '', $tm_format = '') |
|
| 927 | + { |
|
| 928 | + return $this->_show_datetime('', 'end', $dt_frmt, $tm_format); |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + |
|
| 932 | + /** |
|
| 933 | + * @param string $dt_frmt |
|
| 934 | + * @param string $tm_format |
|
| 935 | + * @throws ReflectionException |
|
| 936 | + * @throws InvalidArgumentException |
|
| 937 | + * @throws InvalidInterfaceException |
|
| 938 | + * @throws InvalidDataTypeException |
|
| 939 | + * @throws EE_Error |
|
| 940 | + */ |
|
| 941 | + public function e_end_date_and_time($dt_frmt = '', $tm_format = '') |
|
| 942 | + { |
|
| 943 | + $this->_show_datetime('', 'end', $dt_frmt, $tm_format, true); |
|
| 944 | + } |
|
| 945 | + |
|
| 946 | + |
|
| 947 | + /** |
|
| 948 | + * get start timestamp |
|
| 949 | + * |
|
| 950 | + * @return int |
|
| 951 | + * @throws ReflectionException |
|
| 952 | + * @throws InvalidArgumentException |
|
| 953 | + * @throws InvalidInterfaceException |
|
| 954 | + * @throws InvalidDataTypeException |
|
| 955 | + * @throws EE_Error |
|
| 956 | + */ |
|
| 957 | + public function start() |
|
| 958 | + { |
|
| 959 | + return $this->get_raw('DTT_EVT_start'); |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + |
|
| 963 | + /** |
|
| 964 | + * get end timestamp |
|
| 965 | + * |
|
| 966 | + * @return int |
|
| 967 | + * @throws ReflectionException |
|
| 968 | + * @throws InvalidArgumentException |
|
| 969 | + * @throws InvalidInterfaceException |
|
| 970 | + * @throws InvalidDataTypeException |
|
| 971 | + * @throws EE_Error |
|
| 972 | + */ |
|
| 973 | + public function end() |
|
| 974 | + { |
|
| 975 | + return $this->get_raw('DTT_EVT_end'); |
|
| 976 | + } |
|
| 977 | + |
|
| 978 | + |
|
| 979 | + /** |
|
| 980 | + * get the registration limit for this datetime slot |
|
| 981 | + * |
|
| 982 | + * @return mixed int on success, FALSE on fail |
|
| 983 | + * @throws ReflectionException |
|
| 984 | + * @throws InvalidArgumentException |
|
| 985 | + * @throws InvalidInterfaceException |
|
| 986 | + * @throws InvalidDataTypeException |
|
| 987 | + * @throws EE_Error |
|
| 988 | + */ |
|
| 989 | + public function reg_limit() |
|
| 990 | + { |
|
| 991 | + return $this->get_raw('DTT_reg_limit'); |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + |
|
| 995 | + /** |
|
| 996 | + * have the tickets sold for this datetime, met or exceed the registration limit ? |
|
| 997 | + * |
|
| 998 | + * @return boolean |
|
| 999 | + * @throws ReflectionException |
|
| 1000 | + * @throws InvalidArgumentException |
|
| 1001 | + * @throws InvalidInterfaceException |
|
| 1002 | + * @throws InvalidDataTypeException |
|
| 1003 | + * @throws EE_Error |
|
| 1004 | + */ |
|
| 1005 | + public function sold_out() |
|
| 1006 | + { |
|
| 1007 | + return $this->reg_limit() > 0 && $this->sold() >= $this->reg_limit(); |
|
| 1008 | + } |
|
| 1009 | + |
|
| 1010 | + |
|
| 1011 | + /** |
|
| 1012 | + * return the total number of spaces remaining at this venue. |
|
| 1013 | + * This only takes the venue's capacity into account, NOT the tickets available for sale |
|
| 1014 | + * |
|
| 1015 | + * @param bool $consider_tickets Whether to consider tickets remaining when determining if there are any spaces left |
|
| 1016 | + * Because if all tickets attached to this datetime have no spaces left, |
|
| 1017 | + * then this datetime IS effectively sold out. |
|
| 1018 | + * However, there are cases where we just want to know the spaces |
|
| 1019 | + * remaining for this particular datetime, hence the flag. |
|
| 1020 | + * @return int |
|
| 1021 | + * @throws ReflectionException |
|
| 1022 | + * @throws InvalidArgumentException |
|
| 1023 | + * @throws InvalidInterfaceException |
|
| 1024 | + * @throws InvalidDataTypeException |
|
| 1025 | + * @throws EE_Error |
|
| 1026 | + */ |
|
| 1027 | + public function spaces_remaining($consider_tickets = false) |
|
| 1028 | + { |
|
| 1029 | + // tickets remaining available for purchase |
|
| 1030 | + // no need for special checks for infinite, because if DTT_reg_limit == EE_INF, then EE_INF - x = EE_INF |
|
| 1031 | + $dtt_remaining = $this->reg_limit() - $this->sold_and_reserved(); |
|
| 1032 | + if (! $consider_tickets) { |
|
| 1033 | + return $dtt_remaining; |
|
| 1034 | + } |
|
| 1035 | + $tickets_remaining = $this->tickets_remaining(); |
|
| 1036 | + return min($dtt_remaining, $tickets_remaining); |
|
| 1037 | + } |
|
| 1038 | + |
|
| 1039 | + |
|
| 1040 | + /** |
|
| 1041 | + * Counts the total tickets available |
|
| 1042 | + * (from all the different types of tickets which are available for this datetime). |
|
| 1043 | + * |
|
| 1044 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1045 | + * @return int |
|
| 1046 | + * @throws ReflectionException |
|
| 1047 | + * @throws InvalidArgumentException |
|
| 1048 | + * @throws InvalidInterfaceException |
|
| 1049 | + * @throws InvalidDataTypeException |
|
| 1050 | + * @throws EE_Error |
|
| 1051 | + */ |
|
| 1052 | + public function tickets_remaining($query_params = array()) |
|
| 1053 | + { |
|
| 1054 | + $sum = 0; |
|
| 1055 | + $tickets = $this->tickets($query_params); |
|
| 1056 | + if (! empty($tickets)) { |
|
| 1057 | + foreach ($tickets as $ticket) { |
|
| 1058 | + if ($ticket instanceof EE_Ticket) { |
|
| 1059 | + // get the actual amount of tickets that can be sold |
|
| 1060 | + $qty = $ticket->qty('saleable'); |
|
| 1061 | + if ($qty === EE_INF) { |
|
| 1062 | + return EE_INF; |
|
| 1063 | + } |
|
| 1064 | + // no negative ticket quantities plz |
|
| 1065 | + if ($qty > 0) { |
|
| 1066 | + $sum += $qty; |
|
| 1067 | + } |
|
| 1068 | + } |
|
| 1069 | + } |
|
| 1070 | + } |
|
| 1071 | + return $sum; |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + |
|
| 1075 | + /** |
|
| 1076 | + * Gets the count of all the tickets available at this datetime (not ticket types) |
|
| 1077 | + * before any were sold |
|
| 1078 | + * |
|
| 1079 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1080 | + * @return int |
|
| 1081 | + * @throws ReflectionException |
|
| 1082 | + * @throws InvalidArgumentException |
|
| 1083 | + * @throws InvalidInterfaceException |
|
| 1084 | + * @throws InvalidDataTypeException |
|
| 1085 | + * @throws EE_Error |
|
| 1086 | + */ |
|
| 1087 | + public function sum_tickets_initially_available($query_params = array()) |
|
| 1088 | + { |
|
| 1089 | + return $this->sum_related('Ticket', $query_params, 'TKT_qty'); |
|
| 1090 | + } |
|
| 1091 | + |
|
| 1092 | + |
|
| 1093 | + /** |
|
| 1094 | + * Returns the lesser-of-the two: spaces remaining at this datetime, or |
|
| 1095 | + * the total tickets remaining (a sum of the tickets remaining for each ticket type |
|
| 1096 | + * that is available for this datetime). |
|
| 1097 | + * |
|
| 1098 | + * @return int |
|
| 1099 | + * @throws ReflectionException |
|
| 1100 | + * @throws InvalidArgumentException |
|
| 1101 | + * @throws InvalidInterfaceException |
|
| 1102 | + * @throws InvalidDataTypeException |
|
| 1103 | + * @throws EE_Error |
|
| 1104 | + */ |
|
| 1105 | + public function total_tickets_available_at_this_datetime() |
|
| 1106 | + { |
|
| 1107 | + return $this->spaces_remaining(true); |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + |
|
| 1111 | + /** |
|
| 1112 | + * This simply compares the internal dtt for the given string with NOW |
|
| 1113 | + * and determines if the date is upcoming or not. |
|
| 1114 | + * |
|
| 1115 | + * @access public |
|
| 1116 | + * @return boolean |
|
| 1117 | + * @throws ReflectionException |
|
| 1118 | + * @throws InvalidArgumentException |
|
| 1119 | + * @throws InvalidInterfaceException |
|
| 1120 | + * @throws InvalidDataTypeException |
|
| 1121 | + * @throws EE_Error |
|
| 1122 | + */ |
|
| 1123 | + public function is_upcoming() |
|
| 1124 | + { |
|
| 1125 | + return ($this->get_raw('DTT_EVT_start') > time()); |
|
| 1126 | + } |
|
| 1127 | + |
|
| 1128 | + |
|
| 1129 | + /** |
|
| 1130 | + * This simply compares the internal datetime for the given string with NOW |
|
| 1131 | + * and returns if the date is active (i.e. start and end time) |
|
| 1132 | + * |
|
| 1133 | + * @return boolean |
|
| 1134 | + * @throws ReflectionException |
|
| 1135 | + * @throws InvalidArgumentException |
|
| 1136 | + * @throws InvalidInterfaceException |
|
| 1137 | + * @throws InvalidDataTypeException |
|
| 1138 | + * @throws EE_Error |
|
| 1139 | + */ |
|
| 1140 | + public function is_active() |
|
| 1141 | + { |
|
| 1142 | + return ($this->get_raw('DTT_EVT_start') < time() && $this->get_raw('DTT_EVT_end') > time()); |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + |
|
| 1146 | + /** |
|
| 1147 | + * This simply compares the internal dtt for the given string with NOW |
|
| 1148 | + * and determines if the date is expired or not. |
|
| 1149 | + * |
|
| 1150 | + * @return boolean |
|
| 1151 | + * @throws ReflectionException |
|
| 1152 | + * @throws InvalidArgumentException |
|
| 1153 | + * @throws InvalidInterfaceException |
|
| 1154 | + * @throws InvalidDataTypeException |
|
| 1155 | + * @throws EE_Error |
|
| 1156 | + */ |
|
| 1157 | + public function is_expired() |
|
| 1158 | + { |
|
| 1159 | + return ($this->get_raw('DTT_EVT_end') < time()); |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + |
|
| 1163 | + /** |
|
| 1164 | + * This returns the active status for whether an event is active, upcoming, or expired |
|
| 1165 | + * |
|
| 1166 | + * @return int return value will be one of the EE_Datetime status constants. |
|
| 1167 | + * @throws ReflectionException |
|
| 1168 | + * @throws InvalidArgumentException |
|
| 1169 | + * @throws InvalidInterfaceException |
|
| 1170 | + * @throws InvalidDataTypeException |
|
| 1171 | + * @throws EE_Error |
|
| 1172 | + */ |
|
| 1173 | + public function get_active_status() |
|
| 1174 | + { |
|
| 1175 | + $total_tickets_for_this_dtt = $this->total_tickets_available_at_this_datetime(); |
|
| 1176 | + if ($total_tickets_for_this_dtt !== false && $total_tickets_for_this_dtt < 1) { |
|
| 1177 | + return EE_Datetime::sold_out; |
|
| 1178 | + } |
|
| 1179 | + if ($this->is_expired()) { |
|
| 1180 | + return EE_Datetime::expired; |
|
| 1181 | + } |
|
| 1182 | + if ($this->is_upcoming()) { |
|
| 1183 | + return EE_Datetime::upcoming; |
|
| 1184 | + } |
|
| 1185 | + if ($this->is_active()) { |
|
| 1186 | + return EE_Datetime::active; |
|
| 1187 | + } |
|
| 1188 | + return null; |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + /** |
|
| 1193 | + * This returns a nice display name for the datetime that is contingent on the span between the dates and times. |
|
| 1194 | + * |
|
| 1195 | + * @param boolean $use_dtt_name if TRUE then we'll use DTT->name() if its not empty. |
|
| 1196 | + * @return string |
|
| 1197 | + * @throws ReflectionException |
|
| 1198 | + * @throws InvalidArgumentException |
|
| 1199 | + * @throws InvalidInterfaceException |
|
| 1200 | + * @throws InvalidDataTypeException |
|
| 1201 | + * @throws EE_Error |
|
| 1202 | + */ |
|
| 1203 | + public function get_dtt_display_name($use_dtt_name = false) |
|
| 1204 | + { |
|
| 1205 | + if ($use_dtt_name) { |
|
| 1206 | + $dtt_name = $this->name(); |
|
| 1207 | + if (! empty($dtt_name)) { |
|
| 1208 | + return $dtt_name; |
|
| 1209 | + } |
|
| 1210 | + } |
|
| 1211 | + // first condition is to see if the months are different |
|
| 1212 | + if (date('m', $this->get_raw('DTT_EVT_start')) !== date('m', $this->get_raw('DTT_EVT_end')) |
|
| 1213 | + ) { |
|
| 1214 | + $display_date = $this->start_date('M j\, Y g:i a') . ' - ' . $this->end_date('M j\, Y g:i a'); |
|
| 1215 | + // next condition is if its the same month but different day |
|
| 1216 | + } else { |
|
| 1217 | + if (date('m', $this->get_raw('DTT_EVT_start')) === date('m', $this->get_raw('DTT_EVT_end')) |
|
| 1218 | + && date('d', $this->get_raw('DTT_EVT_start')) !== date('d', $this->get_raw('DTT_EVT_end')) |
|
| 1219 | + ) { |
|
| 1220 | + $display_date = $this->start_date('M j\, g:i a') . ' - ' . $this->end_date('M j\, g:i a Y'); |
|
| 1221 | + } else { |
|
| 1222 | + $display_date = $this->start_date('F j\, Y') |
|
| 1223 | + . ' @ ' |
|
| 1224 | + . $this->start_date('g:i a') |
|
| 1225 | + . ' - ' |
|
| 1226 | + . $this->end_date('g:i a'); |
|
| 1227 | + } |
|
| 1228 | + } |
|
| 1229 | + return $display_date; |
|
| 1230 | + } |
|
| 1231 | + |
|
| 1232 | + |
|
| 1233 | + /** |
|
| 1234 | + * Gets all the tickets for this datetime |
|
| 1235 | + * |
|
| 1236 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1237 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
| 1238 | + * @throws ReflectionException |
|
| 1239 | + * @throws InvalidArgumentException |
|
| 1240 | + * @throws InvalidInterfaceException |
|
| 1241 | + * @throws InvalidDataTypeException |
|
| 1242 | + * @throws EE_Error |
|
| 1243 | + */ |
|
| 1244 | + public function tickets($query_params = array()) |
|
| 1245 | + { |
|
| 1246 | + return $this->get_many_related('Ticket', $query_params); |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + |
|
| 1250 | + /** |
|
| 1251 | + * Gets all the ticket types currently available for purchase |
|
| 1252 | + * |
|
| 1253 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1254 | + * @return EE_Ticket[] |
|
| 1255 | + * @throws ReflectionException |
|
| 1256 | + * @throws InvalidArgumentException |
|
| 1257 | + * @throws InvalidInterfaceException |
|
| 1258 | + * @throws InvalidDataTypeException |
|
| 1259 | + * @throws EE_Error |
|
| 1260 | + */ |
|
| 1261 | + public function ticket_types_available_for_purchase($query_params = array()) |
|
| 1262 | + { |
|
| 1263 | + // first check if datetime is valid |
|
| 1264 | + if ($this->sold_out() || ! ($this->is_upcoming() || $this->is_active())) { |
|
| 1265 | + return array(); |
|
| 1266 | + } |
|
| 1267 | + if (empty($query_params)) { |
|
| 1268 | + $query_params = array( |
|
| 1269 | + array( |
|
| 1270 | + 'TKT_start_date' => array('<=', EEM_Ticket::instance()->current_time_for_query('TKT_start_date')), |
|
| 1271 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
| 1272 | + 'TKT_deleted' => false, |
|
| 1273 | + ), |
|
| 1274 | + ); |
|
| 1275 | + } |
|
| 1276 | + return $this->tickets($query_params); |
|
| 1277 | + } |
|
| 1278 | + |
|
| 1279 | + |
|
| 1280 | + /** |
|
| 1281 | + * @return EE_Base_Class|EE_Event |
|
| 1282 | + * @throws ReflectionException |
|
| 1283 | + * @throws InvalidArgumentException |
|
| 1284 | + * @throws InvalidInterfaceException |
|
| 1285 | + * @throws InvalidDataTypeException |
|
| 1286 | + * @throws EE_Error |
|
| 1287 | + */ |
|
| 1288 | + public function event() |
|
| 1289 | + { |
|
| 1290 | + return $this->get_first_related('Event'); |
|
| 1291 | + } |
|
| 1292 | + |
|
| 1293 | + |
|
| 1294 | + /** |
|
| 1295 | + * Updates the DTT_sold attribute (and saves) based on the number of registrations for this datetime |
|
| 1296 | + * (via the tickets). |
|
| 1297 | + * |
|
| 1298 | + * @return int |
|
| 1299 | + * @throws ReflectionException |
|
| 1300 | + * @throws InvalidArgumentException |
|
| 1301 | + * @throws InvalidInterfaceException |
|
| 1302 | + * @throws InvalidDataTypeException |
|
| 1303 | + * @throws EE_Error |
|
| 1304 | + */ |
|
| 1305 | + public function update_sold() |
|
| 1306 | + { |
|
| 1307 | + $count_regs_for_this_datetime = EEM_Registration::instance()->count( |
|
| 1308 | + array( |
|
| 1309 | + array( |
|
| 1310 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
| 1311 | + 'REG_deleted' => 0, |
|
| 1312 | + 'Ticket.Datetime.DTT_ID' => $this->ID(), |
|
| 1313 | + ), |
|
| 1314 | + ) |
|
| 1315 | + ); |
|
| 1316 | + $this->set_sold($count_regs_for_this_datetime); |
|
| 1317 | + $this->save(); |
|
| 1318 | + return $count_regs_for_this_datetime; |
|
| 1319 | + } |
|
| 1320 | + |
|
| 1321 | + |
|
| 1322 | + /******************************************************************* |
|
| 1323 | 1323 | *********************** DEPRECATED METHODS ********************** |
| 1324 | 1324 | *******************************************************************/ |
| 1325 | 1325 | |
| 1326 | 1326 | |
| 1327 | - /** |
|
| 1328 | - * Increments sold by amount passed by $qty, and persists it immediately to the database. |
|
| 1329 | - * |
|
| 1330 | - * @deprecated $VID:$ |
|
| 1331 | - * @param int $qty |
|
| 1332 | - * @return boolean |
|
| 1333 | - * @throws ReflectionException |
|
| 1334 | - * @throws InvalidArgumentException |
|
| 1335 | - * @throws InvalidInterfaceException |
|
| 1336 | - * @throws InvalidDataTypeException |
|
| 1337 | - * @throws EE_Error |
|
| 1338 | - */ |
|
| 1339 | - public function increase_sold($qty = 1) |
|
| 1340 | - { |
|
| 1341 | - EE_Error::doing_it_wrong( |
|
| 1342 | - __FUNCTION__, |
|
| 1343 | - esc_html__('Please use EE_Datetime::increaseSold() instead', 'event_espresso'), |
|
| 1344 | - '$VID:$', |
|
| 1345 | - '5.0.0.p' |
|
| 1346 | - ); |
|
| 1347 | - return $this->increaseSold($qty); |
|
| 1348 | - } |
|
| 1349 | - |
|
| 1350 | - |
|
| 1351 | - /** |
|
| 1352 | - * Decrements (subtracts) sold amount passed by $qty directly in the DB and on the model object. (Ie, no need |
|
| 1353 | - * to save afterwards.) |
|
| 1354 | - * |
|
| 1355 | - * @deprecated $VID:$ |
|
| 1356 | - * @param int $qty |
|
| 1357 | - * @return boolean |
|
| 1358 | - * @throws ReflectionException |
|
| 1359 | - * @throws InvalidArgumentException |
|
| 1360 | - * @throws InvalidInterfaceException |
|
| 1361 | - * @throws InvalidDataTypeException |
|
| 1362 | - * @throws EE_Error |
|
| 1363 | - */ |
|
| 1364 | - public function decrease_sold($qty = 1) |
|
| 1365 | - { |
|
| 1366 | - EE_Error::doing_it_wrong( |
|
| 1367 | - __FUNCTION__, |
|
| 1368 | - esc_html__('Please use EE_Datetime::decreaseSold() instead', 'event_espresso'), |
|
| 1369 | - '$VID:$', |
|
| 1370 | - '5.0.0.p' |
|
| 1371 | - ); |
|
| 1372 | - return $this->decreaseSold($qty); |
|
| 1373 | - } |
|
| 1374 | - |
|
| 1375 | - |
|
| 1376 | - /** |
|
| 1377 | - * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1378 | - * |
|
| 1379 | - * @deprecated $VID:$ |
|
| 1380 | - * @param int $qty |
|
| 1381 | - * @return boolean indicating success |
|
| 1382 | - * @throws ReflectionException |
|
| 1383 | - * @throws InvalidArgumentException |
|
| 1384 | - * @throws InvalidInterfaceException |
|
| 1385 | - * @throws InvalidDataTypeException |
|
| 1386 | - * @throws EE_Error |
|
| 1387 | - */ |
|
| 1388 | - public function increase_reserved($qty = 1) |
|
| 1389 | - { |
|
| 1390 | - EE_Error::doing_it_wrong( |
|
| 1391 | - __FUNCTION__, |
|
| 1392 | - esc_html__('Please use EE_Datetime::increaseReserved() instead', 'event_espresso'), |
|
| 1393 | - '$VID:$', |
|
| 1394 | - '5.0.0.p' |
|
| 1395 | - ); |
|
| 1396 | - return $this->increaseReserved($qty); |
|
| 1397 | - } |
|
| 1398 | - |
|
| 1399 | - |
|
| 1400 | - /** |
|
| 1401 | - * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1402 | - * |
|
| 1403 | - * @deprecated $VID:$ |
|
| 1404 | - * @param int $qty |
|
| 1405 | - * @return boolean |
|
| 1406 | - * @throws ReflectionException |
|
| 1407 | - * @throws InvalidArgumentException |
|
| 1408 | - * @throws InvalidInterfaceException |
|
| 1409 | - * @throws InvalidDataTypeException |
|
| 1410 | - * @throws EE_Error |
|
| 1411 | - */ |
|
| 1412 | - public function decrease_reserved($qty = 1) |
|
| 1413 | - { |
|
| 1414 | - EE_Error::doing_it_wrong( |
|
| 1415 | - __FUNCTION__, |
|
| 1416 | - esc_html__('Please use EE_Datetime::decreaseReserved() instead', 'event_espresso'), |
|
| 1417 | - '$VID:$', |
|
| 1418 | - '5.0.0.p' |
|
| 1419 | - ); |
|
| 1420 | - return $this->decreaseReserved($qty); |
|
| 1421 | - } |
|
| 1327 | + /** |
|
| 1328 | + * Increments sold by amount passed by $qty, and persists it immediately to the database. |
|
| 1329 | + * |
|
| 1330 | + * @deprecated $VID:$ |
|
| 1331 | + * @param int $qty |
|
| 1332 | + * @return boolean |
|
| 1333 | + * @throws ReflectionException |
|
| 1334 | + * @throws InvalidArgumentException |
|
| 1335 | + * @throws InvalidInterfaceException |
|
| 1336 | + * @throws InvalidDataTypeException |
|
| 1337 | + * @throws EE_Error |
|
| 1338 | + */ |
|
| 1339 | + public function increase_sold($qty = 1) |
|
| 1340 | + { |
|
| 1341 | + EE_Error::doing_it_wrong( |
|
| 1342 | + __FUNCTION__, |
|
| 1343 | + esc_html__('Please use EE_Datetime::increaseSold() instead', 'event_espresso'), |
|
| 1344 | + '$VID:$', |
|
| 1345 | + '5.0.0.p' |
|
| 1346 | + ); |
|
| 1347 | + return $this->increaseSold($qty); |
|
| 1348 | + } |
|
| 1349 | + |
|
| 1350 | + |
|
| 1351 | + /** |
|
| 1352 | + * Decrements (subtracts) sold amount passed by $qty directly in the DB and on the model object. (Ie, no need |
|
| 1353 | + * to save afterwards.) |
|
| 1354 | + * |
|
| 1355 | + * @deprecated $VID:$ |
|
| 1356 | + * @param int $qty |
|
| 1357 | + * @return boolean |
|
| 1358 | + * @throws ReflectionException |
|
| 1359 | + * @throws InvalidArgumentException |
|
| 1360 | + * @throws InvalidInterfaceException |
|
| 1361 | + * @throws InvalidDataTypeException |
|
| 1362 | + * @throws EE_Error |
|
| 1363 | + */ |
|
| 1364 | + public function decrease_sold($qty = 1) |
|
| 1365 | + { |
|
| 1366 | + EE_Error::doing_it_wrong( |
|
| 1367 | + __FUNCTION__, |
|
| 1368 | + esc_html__('Please use EE_Datetime::decreaseSold() instead', 'event_espresso'), |
|
| 1369 | + '$VID:$', |
|
| 1370 | + '5.0.0.p' |
|
| 1371 | + ); |
|
| 1372 | + return $this->decreaseSold($qty); |
|
| 1373 | + } |
|
| 1374 | + |
|
| 1375 | + |
|
| 1376 | + /** |
|
| 1377 | + * Increments reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1378 | + * |
|
| 1379 | + * @deprecated $VID:$ |
|
| 1380 | + * @param int $qty |
|
| 1381 | + * @return boolean indicating success |
|
| 1382 | + * @throws ReflectionException |
|
| 1383 | + * @throws InvalidArgumentException |
|
| 1384 | + * @throws InvalidInterfaceException |
|
| 1385 | + * @throws InvalidDataTypeException |
|
| 1386 | + * @throws EE_Error |
|
| 1387 | + */ |
|
| 1388 | + public function increase_reserved($qty = 1) |
|
| 1389 | + { |
|
| 1390 | + EE_Error::doing_it_wrong( |
|
| 1391 | + __FUNCTION__, |
|
| 1392 | + esc_html__('Please use EE_Datetime::increaseReserved() instead', 'event_espresso'), |
|
| 1393 | + '$VID:$', |
|
| 1394 | + '5.0.0.p' |
|
| 1395 | + ); |
|
| 1396 | + return $this->increaseReserved($qty); |
|
| 1397 | + } |
|
| 1398 | + |
|
| 1399 | + |
|
| 1400 | + /** |
|
| 1401 | + * Decrements (subtracts) reserved by amount passed by $qty, and persists it immediately to the database. |
|
| 1402 | + * |
|
| 1403 | + * @deprecated $VID:$ |
|
| 1404 | + * @param int $qty |
|
| 1405 | + * @return boolean |
|
| 1406 | + * @throws ReflectionException |
|
| 1407 | + * @throws InvalidArgumentException |
|
| 1408 | + * @throws InvalidInterfaceException |
|
| 1409 | + * @throws InvalidDataTypeException |
|
| 1410 | + * @throws EE_Error |
|
| 1411 | + */ |
|
| 1412 | + public function decrease_reserved($qty = 1) |
|
| 1413 | + { |
|
| 1414 | + EE_Error::doing_it_wrong( |
|
| 1415 | + __FUNCTION__, |
|
| 1416 | + esc_html__('Please use EE_Datetime::decreaseReserved() instead', 'event_espresso'), |
|
| 1417 | + '$VID:$', |
|
| 1418 | + '5.0.0.p' |
|
| 1419 | + ); |
|
| 1420 | + return $this->decreaseReserved($qty); |
|
| 1421 | + } |
|
| 1422 | 1422 | } |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | |
| 368 | 368 | /** |
| 369 | - * @return mixed|null |
|
| 369 | + * @return EE_Cart|null |
|
| 370 | 370 | * @throws EE_Error |
| 371 | 371 | * @throws InvalidArgumentException |
| 372 | 372 | * @throws InvalidDataTypeException |
@@ -508,7 +508,7 @@ discard block |
||
| 508 | 508 | * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
| 509 | 509 | * function for getting attendees and how many registrations they each have for an event) |
| 510 | 510 | * |
| 511 | - * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
| 511 | + * @return EE_Base_Class[] EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
| 512 | 512 | * @throws EE_Error |
| 513 | 513 | * @throws InvalidArgumentException |
| 514 | 514 | * @throws InvalidDataTypeException |
@@ -564,7 +564,7 @@ discard block |
||
| 564 | 564 | /** |
| 565 | 565 | * Gets all payments which have not been approved |
| 566 | 566 | * |
| 567 | - * @return EE_Base_Class[]|EEI_Payment[] |
|
| 567 | + * @return EE_Base_Class[] |
|
| 568 | 568 | * @throws EE_Error if a model is misconfigured somehow |
| 569 | 569 | * @throws InvalidArgumentException |
| 570 | 570 | * @throws InvalidDataTypeException |
@@ -13,1682 +13,1682 @@ |
||
| 13 | 13 | class EE_Transaction extends EE_Base_Class implements EEI_Transaction |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * The length of time in seconds that a lock is applied before being considered expired. |
|
| 18 | - * It is not long because a transaction should only be locked for the duration of the request that locked it |
|
| 19 | - */ |
|
| 20 | - const LOCK_EXPIRATION = 2; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * txn status upon initial construction. |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected $_old_txn_status; |
|
| 28 | - |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @param array $props_n_values incoming values |
|
| 32 | - * @param string $timezone incoming timezone |
|
| 33 | - * (if not set the timezone set for the website will be used.) |
|
| 34 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 35 | - * date_format and the second value is the time format |
|
| 36 | - * @return EE_Transaction |
|
| 37 | - * @throws EE_Error |
|
| 38 | - * @throws InvalidArgumentException |
|
| 39 | - * @throws InvalidDataTypeException |
|
| 40 | - * @throws InvalidInterfaceException |
|
| 41 | - * @throws ReflectionException |
|
| 42 | - */ |
|
| 43 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 44 | - { |
|
| 45 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 46 | - $txn = $has_object |
|
| 47 | - ? $has_object |
|
| 48 | - : new self($props_n_values, false, $timezone, $date_formats); |
|
| 49 | - if (! $has_object) { |
|
| 50 | - $txn->set_old_txn_status($txn->status_ID()); |
|
| 51 | - } |
|
| 52 | - return $txn; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @param array $props_n_values incoming values from the database |
|
| 58 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 59 | - * the website will be used. |
|
| 60 | - * @return EE_Transaction |
|
| 61 | - * @throws EE_Error |
|
| 62 | - * @throws InvalidArgumentException |
|
| 63 | - * @throws InvalidDataTypeException |
|
| 64 | - * @throws InvalidInterfaceException |
|
| 65 | - * @throws ReflectionException |
|
| 66 | - */ |
|
| 67 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 68 | - { |
|
| 69 | - $txn = new self($props_n_values, true, $timezone); |
|
| 70 | - $txn->set_old_txn_status($txn->status_ID()); |
|
| 71 | - return $txn; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Sets a meta field indicating that this TXN is locked and should not be updated in the db. |
|
| 77 | - * If a lock has already been set, then we will attempt to remove it in case it has expired. |
|
| 78 | - * If that also fails, then an exception is thrown. |
|
| 79 | - * |
|
| 80 | - * @throws EE_Error |
|
| 81 | - * @throws InvalidArgumentException |
|
| 82 | - * @throws InvalidDataTypeException |
|
| 83 | - * @throws InvalidInterfaceException |
|
| 84 | - * @throws ReflectionException |
|
| 85 | - */ |
|
| 86 | - public function lock() |
|
| 87 | - { |
|
| 88 | - // attempt to set lock, but if that fails... |
|
| 89 | - if (! $this->add_extra_meta('lock', time(), true)) { |
|
| 90 | - // then attempt to remove the lock in case it is expired |
|
| 91 | - if ($this->_remove_expired_lock()) { |
|
| 92 | - // if removal was successful, then try setting lock again |
|
| 93 | - $this->lock(); |
|
| 94 | - } else { |
|
| 95 | - // but if the lock can not be removed, then throw an exception |
|
| 96 | - throw new EE_Error( |
|
| 97 | - sprintf( |
|
| 98 | - __( |
|
| 99 | - 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', |
|
| 100 | - 'event_espresso' |
|
| 101 | - ), |
|
| 102 | - $this->ID() |
|
| 103 | - ) |
|
| 104 | - ); |
|
| 105 | - } |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * removes transaction lock applied in EE_Transaction::lock() |
|
| 112 | - * |
|
| 113 | - * @return int |
|
| 114 | - * @throws EE_Error |
|
| 115 | - * @throws InvalidArgumentException |
|
| 116 | - * @throws InvalidDataTypeException |
|
| 117 | - * @throws InvalidInterfaceException |
|
| 118 | - * @throws ReflectionException |
|
| 119 | - */ |
|
| 120 | - public function unlock() |
|
| 121 | - { |
|
| 122 | - return $this->delete_extra_meta('lock'); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Decides whether or not now is the right time to update the transaction. |
|
| 128 | - * This is useful because we don't always know if it is safe to update the transaction |
|
| 129 | - * and its related data. why? |
|
| 130 | - * because it's possible that the transaction is being used in another |
|
| 131 | - * request and could overwrite anything we save. |
|
| 132 | - * So we want to only update the txn once we know that won't happen. |
|
| 133 | - * We also check that the lock isn't expired, and remove it if it is |
|
| 134 | - * |
|
| 135 | - * @return boolean |
|
| 136 | - * @throws EE_Error |
|
| 137 | - * @throws InvalidArgumentException |
|
| 138 | - * @throws InvalidDataTypeException |
|
| 139 | - * @throws InvalidInterfaceException |
|
| 140 | - * @throws ReflectionException |
|
| 141 | - */ |
|
| 142 | - public function is_locked() |
|
| 143 | - { |
|
| 144 | - // if TXN is not locked, then return false immediately |
|
| 145 | - if (! $this->_get_lock()) { |
|
| 146 | - return false; |
|
| 147 | - } |
|
| 148 | - // if not, then let's try and remove the lock in case it's expired... |
|
| 149 | - // _remove_expired_lock() returns 0 when lock is valid (ie: removed = false) |
|
| 150 | - // and a positive number if the lock was removed (ie: number of locks deleted), |
|
| 151 | - // so we need to return the opposite |
|
| 152 | - return ! $this->_remove_expired_lock() ? true : false; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Gets the meta field indicating that this TXN is locked |
|
| 158 | - * |
|
| 159 | - * @return int |
|
| 160 | - * @throws EE_Error |
|
| 161 | - * @throws InvalidArgumentException |
|
| 162 | - * @throws InvalidDataTypeException |
|
| 163 | - * @throws InvalidInterfaceException |
|
| 164 | - * @throws ReflectionException |
|
| 165 | - */ |
|
| 166 | - protected function _get_lock() |
|
| 167 | - { |
|
| 168 | - return (int) $this->get_extra_meta('lock', true, 0); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated |
|
| 174 | - * |
|
| 175 | - * @return int |
|
| 176 | - * @throws EE_Error |
|
| 177 | - * @throws InvalidArgumentException |
|
| 178 | - * @throws InvalidDataTypeException |
|
| 179 | - * @throws InvalidInterfaceException |
|
| 180 | - * @throws ReflectionException |
|
| 181 | - */ |
|
| 182 | - protected function _remove_expired_lock() |
|
| 183 | - { |
|
| 184 | - $locked = $this->_get_lock(); |
|
| 185 | - if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
| 186 | - return $this->unlock(); |
|
| 187 | - } |
|
| 188 | - return 0; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Set transaction total |
|
| 194 | - * |
|
| 195 | - * @param float $total total value of transaction |
|
| 196 | - * @throws EE_Error |
|
| 197 | - * @throws InvalidArgumentException |
|
| 198 | - * @throws InvalidDataTypeException |
|
| 199 | - * @throws InvalidInterfaceException |
|
| 200 | - * @throws ReflectionException |
|
| 201 | - */ |
|
| 202 | - public function set_total($total = 0.00) |
|
| 203 | - { |
|
| 204 | - $this->set('TXN_total', (float) $total); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - |
|
| 208 | - /** |
|
| 209 | - * Set Total Amount Paid to Date |
|
| 210 | - * |
|
| 211 | - * @param float $total_paid total amount paid to date (sum of all payments) |
|
| 212 | - * @throws EE_Error |
|
| 213 | - * @throws InvalidArgumentException |
|
| 214 | - * @throws InvalidDataTypeException |
|
| 215 | - * @throws InvalidInterfaceException |
|
| 216 | - * @throws ReflectionException |
|
| 217 | - */ |
|
| 218 | - public function set_paid($total_paid = 0.00) |
|
| 219 | - { |
|
| 220 | - $this->set('TXN_paid', (float) $total_paid); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Set transaction status |
|
| 226 | - * |
|
| 227 | - * @param string $status whether the transaction is open, declined, accepted, |
|
| 228 | - * or any number of custom values that can be set |
|
| 229 | - * @throws EE_Error |
|
| 230 | - * @throws InvalidArgumentException |
|
| 231 | - * @throws InvalidDataTypeException |
|
| 232 | - * @throws InvalidInterfaceException |
|
| 233 | - * @throws ReflectionException |
|
| 234 | - */ |
|
| 235 | - public function set_status($status = '') |
|
| 236 | - { |
|
| 237 | - $this->set('STS_ID', $status); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Set hash salt |
|
| 243 | - * |
|
| 244 | - * @param string $hash_salt required for some payment gateways |
|
| 245 | - * @throws EE_Error |
|
| 246 | - * @throws InvalidArgumentException |
|
| 247 | - * @throws InvalidDataTypeException |
|
| 248 | - * @throws InvalidInterfaceException |
|
| 249 | - * @throws ReflectionException |
|
| 250 | - */ |
|
| 251 | - public function set_hash_salt($hash_salt = '') |
|
| 252 | - { |
|
| 253 | - $this->set('TXN_hash_salt', $hash_salt); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Sets TXN_reg_steps array |
|
| 259 | - * |
|
| 260 | - * @param array $txn_reg_steps |
|
| 261 | - * @throws EE_Error |
|
| 262 | - * @throws InvalidArgumentException |
|
| 263 | - * @throws InvalidDataTypeException |
|
| 264 | - * @throws InvalidInterfaceException |
|
| 265 | - * @throws ReflectionException |
|
| 266 | - */ |
|
| 267 | - public function set_reg_steps(array $txn_reg_steps) |
|
| 268 | - { |
|
| 269 | - $this->set('TXN_reg_steps', $txn_reg_steps); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Gets TXN_reg_steps |
|
| 275 | - * |
|
| 276 | - * @return array |
|
| 277 | - * @throws EE_Error |
|
| 278 | - * @throws InvalidArgumentException |
|
| 279 | - * @throws InvalidDataTypeException |
|
| 280 | - * @throws InvalidInterfaceException |
|
| 281 | - * @throws ReflectionException |
|
| 282 | - */ |
|
| 283 | - public function reg_steps() |
|
| 284 | - { |
|
| 285 | - $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
| 286 | - return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array(); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * @return string of transaction's total cost, with currency symbol and decimal |
|
| 292 | - * @throws EE_Error |
|
| 293 | - * @throws InvalidArgumentException |
|
| 294 | - * @throws InvalidDataTypeException |
|
| 295 | - * @throws InvalidInterfaceException |
|
| 296 | - * @throws ReflectionException |
|
| 297 | - */ |
|
| 298 | - public function pretty_total() |
|
| 299 | - { |
|
| 300 | - return $this->get_pretty('TXN_total'); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Gets the amount paid in a pretty string (formatted and with currency symbol) |
|
| 306 | - * |
|
| 307 | - * @return string |
|
| 308 | - * @throws EE_Error |
|
| 309 | - * @throws InvalidArgumentException |
|
| 310 | - * @throws InvalidDataTypeException |
|
| 311 | - * @throws InvalidInterfaceException |
|
| 312 | - * @throws ReflectionException |
|
| 313 | - */ |
|
| 314 | - public function pretty_paid() |
|
| 315 | - { |
|
| 316 | - return $this->get_pretty('TXN_paid'); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * calculate the amount remaining for this transaction and return; |
|
| 322 | - * |
|
| 323 | - * @return float amount remaining |
|
| 324 | - * @throws EE_Error |
|
| 325 | - * @throws InvalidArgumentException |
|
| 326 | - * @throws InvalidDataTypeException |
|
| 327 | - * @throws InvalidInterfaceException |
|
| 328 | - * @throws ReflectionException |
|
| 329 | - */ |
|
| 330 | - public function remaining() |
|
| 331 | - { |
|
| 332 | - return $this->total() - $this->paid(); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * get Transaction Total |
|
| 338 | - * |
|
| 339 | - * @return float |
|
| 340 | - * @throws EE_Error |
|
| 341 | - * @throws InvalidArgumentException |
|
| 342 | - * @throws InvalidDataTypeException |
|
| 343 | - * @throws InvalidInterfaceException |
|
| 344 | - * @throws ReflectionException |
|
| 345 | - */ |
|
| 346 | - public function total() |
|
| 347 | - { |
|
| 348 | - return (float) $this->get('TXN_total'); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * get Total Amount Paid to Date |
|
| 354 | - * |
|
| 355 | - * @return float |
|
| 356 | - * @throws EE_Error |
|
| 357 | - * @throws InvalidArgumentException |
|
| 358 | - * @throws InvalidDataTypeException |
|
| 359 | - * @throws InvalidInterfaceException |
|
| 360 | - * @throws ReflectionException |
|
| 361 | - */ |
|
| 362 | - public function paid() |
|
| 363 | - { |
|
| 364 | - return (float) $this->get('TXN_paid'); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * @return mixed|null |
|
| 370 | - * @throws EE_Error |
|
| 371 | - * @throws InvalidArgumentException |
|
| 372 | - * @throws InvalidDataTypeException |
|
| 373 | - * @throws InvalidInterfaceException |
|
| 374 | - * @throws ReflectionException |
|
| 375 | - */ |
|
| 376 | - public function get_cart_session() |
|
| 377 | - { |
|
| 378 | - $session_data = (array) $this->get('TXN_session_data'); |
|
| 379 | - return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
| 380 | - ? $session_data['cart'] |
|
| 381 | - : null; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * get Transaction session data |
|
| 387 | - * |
|
| 388 | - * @return array|mixed |
|
| 389 | - * @throws EE_Error |
|
| 390 | - * @throws InvalidArgumentException |
|
| 391 | - * @throws InvalidDataTypeException |
|
| 392 | - * @throws InvalidInterfaceException |
|
| 393 | - * @throws ReflectionException |
|
| 394 | - */ |
|
| 395 | - public function session_data() |
|
| 396 | - { |
|
| 397 | - $session_data = $this->get('TXN_session_data'); |
|
| 398 | - if (empty($session_data)) { |
|
| 399 | - $session_data = array( |
|
| 400 | - 'id' => null, |
|
| 401 | - 'user_id' => null, |
|
| 402 | - 'ip_address' => null, |
|
| 403 | - 'user_agent' => null, |
|
| 404 | - 'init_access' => null, |
|
| 405 | - 'last_access' => null, |
|
| 406 | - 'pages_visited' => array(), |
|
| 407 | - ); |
|
| 408 | - } |
|
| 409 | - return $session_data; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - |
|
| 413 | - /** |
|
| 414 | - * Set session data within the TXN object |
|
| 415 | - * |
|
| 416 | - * @param EE_Session|array $session_data |
|
| 417 | - * @throws EE_Error |
|
| 418 | - * @throws InvalidArgumentException |
|
| 419 | - * @throws InvalidDataTypeException |
|
| 420 | - * @throws InvalidInterfaceException |
|
| 421 | - * @throws ReflectionException |
|
| 422 | - */ |
|
| 423 | - public function set_txn_session_data($session_data) |
|
| 424 | - { |
|
| 425 | - if ($session_data instanceof EE_Session) { |
|
| 426 | - $this->set('TXN_session_data', $session_data->get_session_data(null, true)); |
|
| 427 | - } else { |
|
| 428 | - $this->set('TXN_session_data', $session_data); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * get Transaction hash salt |
|
| 435 | - * |
|
| 436 | - * @return mixed |
|
| 437 | - * @throws EE_Error |
|
| 438 | - * @throws InvalidArgumentException |
|
| 439 | - * @throws InvalidDataTypeException |
|
| 440 | - * @throws InvalidInterfaceException |
|
| 441 | - * @throws ReflectionException |
|
| 442 | - */ |
|
| 443 | - public function hash_salt_() |
|
| 444 | - { |
|
| 445 | - return $this->get('TXN_hash_salt'); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Returns the transaction datetime as either: |
|
| 451 | - * - unix timestamp format ($format = false, $gmt = true) |
|
| 452 | - * - formatted date string including the UTC (timezone) offset ($format = true ($gmt |
|
| 453 | - * has no affect with this option)), this also may include a timezone abbreviation if the |
|
| 454 | - * set timezone in this class differs from what the timezone is on the blog. |
|
| 455 | - * - formatted date string including the UTC (timezone) offset (default). |
|
| 456 | - * |
|
| 457 | - * @param boolean $format - whether to return a unix timestamp (default) or formatted date string |
|
| 458 | - * @param boolean $gmt - whether to return a unix timestamp with UTC offset applied (default) |
|
| 459 | - * or no UTC offset applied |
|
| 460 | - * @return string | int |
|
| 461 | - * @throws EE_Error |
|
| 462 | - * @throws InvalidArgumentException |
|
| 463 | - * @throws InvalidDataTypeException |
|
| 464 | - * @throws InvalidInterfaceException |
|
| 465 | - * @throws ReflectionException |
|
| 466 | - */ |
|
| 467 | - public function datetime($format = false, $gmt = false) |
|
| 468 | - { |
|
| 469 | - if ($format) { |
|
| 470 | - return $this->get_pretty('TXN_timestamp'); |
|
| 471 | - } |
|
| 472 | - if ($gmt) { |
|
| 473 | - return $this->get_raw('TXN_timestamp'); |
|
| 474 | - } |
|
| 475 | - return $this->get('TXN_timestamp'); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Gets registrations on this transaction |
|
| 481 | - * |
|
| 482 | - * @param array $query_params array of query parameters |
|
| 483 | - * @param boolean $get_cached TRUE to retrieve cached registrations or FALSE to pull from the db |
|
| 484 | - * @return EE_Base_Class[]|EE_Registration[] |
|
| 485 | - * @throws EE_Error |
|
| 486 | - * @throws InvalidArgumentException |
|
| 487 | - * @throws InvalidDataTypeException |
|
| 488 | - * @throws InvalidInterfaceException |
|
| 489 | - * @throws ReflectionException |
|
| 490 | - */ |
|
| 491 | - public function registrations($query_params = array(), $get_cached = false) |
|
| 492 | - { |
|
| 493 | - $query_params = (empty($query_params) || ! is_array($query_params)) |
|
| 494 | - ? array( |
|
| 495 | - 'order_by' => array( |
|
| 496 | - 'Event.EVT_name' => 'ASC', |
|
| 497 | - 'Attendee.ATT_lname' => 'ASC', |
|
| 498 | - 'Attendee.ATT_fname' => 'ASC', |
|
| 499 | - ), |
|
| 500 | - ) |
|
| 501 | - : $query_params; |
|
| 502 | - $query_params = $get_cached ? array() : $query_params; |
|
| 503 | - return $this->get_many_related('Registration', $query_params); |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
|
| 509 | - * function for getting attendees and how many registrations they each have for an event) |
|
| 510 | - * |
|
| 511 | - * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
| 512 | - * @throws EE_Error |
|
| 513 | - * @throws InvalidArgumentException |
|
| 514 | - * @throws InvalidDataTypeException |
|
| 515 | - * @throws InvalidInterfaceException |
|
| 516 | - * @throws ReflectionException |
|
| 517 | - */ |
|
| 518 | - public function attendees() |
|
| 519 | - { |
|
| 520 | - return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default |
|
| 526 | - * |
|
| 527 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 528 | - * @return EE_Base_Class[]|EE_Payment[] |
|
| 529 | - * @throws EE_Error |
|
| 530 | - * @throws InvalidArgumentException |
|
| 531 | - * @throws InvalidDataTypeException |
|
| 532 | - * @throws InvalidInterfaceException |
|
| 533 | - * @throws ReflectionException |
|
| 534 | - */ |
|
| 535 | - public function payments($query_params = array()) |
|
| 536 | - { |
|
| 537 | - return $this->get_many_related('Payment', $query_params); |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * gets only approved payments for this transaction |
|
| 543 | - * |
|
| 544 | - * @return EE_Base_Class[]|EE_Payment[] |
|
| 545 | - * @throws EE_Error |
|
| 546 | - * @throws InvalidArgumentException |
|
| 547 | - * @throws ReflectionException |
|
| 548 | - * @throws InvalidDataTypeException |
|
| 549 | - * @throws InvalidInterfaceException |
|
| 550 | - */ |
|
| 551 | - public function approved_payments() |
|
| 552 | - { |
|
| 553 | - EE_Registry::instance()->load_model('Payment'); |
|
| 554 | - return $this->get_many_related( |
|
| 555 | - 'Payment', |
|
| 556 | - array( |
|
| 557 | - array('STS_ID' => EEM_Payment::status_id_approved), |
|
| 558 | - 'order_by' => array('PAY_timestamp' => 'DESC'), |
|
| 559 | - ) |
|
| 560 | - ); |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Gets all payments which have not been approved |
|
| 566 | - * |
|
| 567 | - * @return EE_Base_Class[]|EEI_Payment[] |
|
| 568 | - * @throws EE_Error if a model is misconfigured somehow |
|
| 569 | - * @throws InvalidArgumentException |
|
| 570 | - * @throws InvalidDataTypeException |
|
| 571 | - * @throws InvalidInterfaceException |
|
| 572 | - * @throws ReflectionException |
|
| 573 | - */ |
|
| 574 | - public function pending_payments() |
|
| 575 | - { |
|
| 576 | - return $this->get_many_related( |
|
| 577 | - 'Payment', |
|
| 578 | - array( |
|
| 579 | - array( |
|
| 580 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
| 581 | - ), |
|
| 582 | - 'order_by' => array( |
|
| 583 | - 'PAY_timestamp' => 'DESC', |
|
| 584 | - ), |
|
| 585 | - ) |
|
| 586 | - ); |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * echoes $this->pretty_status() |
|
| 592 | - * |
|
| 593 | - * @param bool $show_icons |
|
| 594 | - * @throws EE_Error |
|
| 595 | - * @throws InvalidArgumentException |
|
| 596 | - * @throws InvalidDataTypeException |
|
| 597 | - * @throws InvalidInterfaceException |
|
| 598 | - * @throws ReflectionException |
|
| 599 | - */ |
|
| 600 | - public function e_pretty_status($show_icons = false) |
|
| 601 | - { |
|
| 602 | - echo $this->pretty_status($show_icons); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - |
|
| 606 | - /** |
|
| 607 | - * returns a pretty version of the status, good for displaying to users |
|
| 608 | - * |
|
| 609 | - * @param bool $show_icons |
|
| 610 | - * @return string |
|
| 611 | - * @throws EE_Error |
|
| 612 | - * @throws InvalidArgumentException |
|
| 613 | - * @throws InvalidDataTypeException |
|
| 614 | - * @throws InvalidInterfaceException |
|
| 615 | - * @throws ReflectionException |
|
| 616 | - */ |
|
| 617 | - public function pretty_status($show_icons = false) |
|
| 618 | - { |
|
| 619 | - $status = EEM_Status::instance()->localized_status( |
|
| 620 | - array($this->status_ID() => __('unknown', 'event_espresso')), |
|
| 621 | - false, |
|
| 622 | - 'sentence' |
|
| 623 | - ); |
|
| 624 | - $icon = ''; |
|
| 625 | - switch ($this->status_ID()) { |
|
| 626 | - case EEM_Transaction::complete_status_code: |
|
| 627 | - $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
|
| 628 | - break; |
|
| 629 | - case EEM_Transaction::incomplete_status_code: |
|
| 630 | - $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>' |
|
| 631 | - : ''; |
|
| 632 | - break; |
|
| 633 | - case EEM_Transaction::abandoned_status_code: |
|
| 634 | - $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : ''; |
|
| 635 | - break; |
|
| 636 | - case EEM_Transaction::failed_status_code: |
|
| 637 | - $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : ''; |
|
| 638 | - break; |
|
| 639 | - case EEM_Transaction::overpaid_status_code: |
|
| 640 | - $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
|
| 641 | - break; |
|
| 642 | - } |
|
| 643 | - return $icon . $status[ $this->status_ID() ]; |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - |
|
| 647 | - /** |
|
| 648 | - * get Transaction Status |
|
| 649 | - * |
|
| 650 | - * @return mixed |
|
| 651 | - * @throws EE_Error |
|
| 652 | - * @throws InvalidArgumentException |
|
| 653 | - * @throws InvalidDataTypeException |
|
| 654 | - * @throws InvalidInterfaceException |
|
| 655 | - * @throws ReflectionException |
|
| 656 | - */ |
|
| 657 | - public function status_ID() |
|
| 658 | - { |
|
| 659 | - return $this->get('STS_ID'); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - |
|
| 663 | - /** |
|
| 664 | - * Returns TRUE or FALSE for whether or not this transaction cost any money |
|
| 665 | - * |
|
| 666 | - * @return boolean |
|
| 667 | - * @throws EE_Error |
|
| 668 | - * @throws InvalidArgumentException |
|
| 669 | - * @throws InvalidDataTypeException |
|
| 670 | - * @throws InvalidInterfaceException |
|
| 671 | - * @throws ReflectionException |
|
| 672 | - */ |
|
| 673 | - public function is_free() |
|
| 674 | - { |
|
| 675 | - return EEH_Money::compare_floats($this->get('TXN_total'), 0, '=='); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - |
|
| 679 | - /** |
|
| 680 | - * Returns whether this transaction is complete |
|
| 681 | - * Useful in templates and other logic for deciding if we should ask for another payment... |
|
| 682 | - * |
|
| 683 | - * @return boolean |
|
| 684 | - * @throws EE_Error |
|
| 685 | - * @throws InvalidArgumentException |
|
| 686 | - * @throws InvalidDataTypeException |
|
| 687 | - * @throws InvalidInterfaceException |
|
| 688 | - * @throws ReflectionException |
|
| 689 | - */ |
|
| 690 | - public function is_completed() |
|
| 691 | - { |
|
| 692 | - return $this->status_ID() === EEM_Transaction::complete_status_code; |
|
| 693 | - } |
|
| 694 | - |
|
| 695 | - |
|
| 696 | - /** |
|
| 697 | - * Returns whether this transaction is incomplete |
|
| 698 | - * Useful in templates and other logic for deciding if we should ask for another payment... |
|
| 699 | - * |
|
| 700 | - * @return boolean |
|
| 701 | - * @throws EE_Error |
|
| 702 | - * @throws InvalidArgumentException |
|
| 703 | - * @throws InvalidDataTypeException |
|
| 704 | - * @throws InvalidInterfaceException |
|
| 705 | - * @throws ReflectionException |
|
| 706 | - */ |
|
| 707 | - public function is_incomplete() |
|
| 708 | - { |
|
| 709 | - return $this->status_ID() === EEM_Transaction::incomplete_status_code; |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * Returns whether this transaction is overpaid |
|
| 715 | - * Useful in templates and other logic for deciding if monies need to be refunded |
|
| 716 | - * |
|
| 717 | - * @return boolean |
|
| 718 | - * @throws EE_Error |
|
| 719 | - * @throws InvalidArgumentException |
|
| 720 | - * @throws InvalidDataTypeException |
|
| 721 | - * @throws InvalidInterfaceException |
|
| 722 | - * @throws ReflectionException |
|
| 723 | - */ |
|
| 724 | - public function is_overpaid() |
|
| 725 | - { |
|
| 726 | - return $this->status_ID() === EEM_Transaction::overpaid_status_code; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - |
|
| 730 | - /** |
|
| 731 | - * Returns whether this transaction was abandoned |
|
| 732 | - * meaning that the transaction/registration process was somehow interrupted and never completed |
|
| 733 | - * but that contact information exists for at least one registrant |
|
| 734 | - * |
|
| 735 | - * @return boolean |
|
| 736 | - * @throws EE_Error |
|
| 737 | - * @throws InvalidArgumentException |
|
| 738 | - * @throws InvalidDataTypeException |
|
| 739 | - * @throws InvalidInterfaceException |
|
| 740 | - * @throws ReflectionException |
|
| 741 | - */ |
|
| 742 | - public function is_abandoned() |
|
| 743 | - { |
|
| 744 | - return $this->status_ID() === EEM_Transaction::abandoned_status_code; |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - |
|
| 748 | - /** |
|
| 749 | - * Returns whether this transaction failed |
|
| 750 | - * meaning that the transaction/registration process was somehow interrupted and never completed |
|
| 751 | - * and that NO contact information exists for any registrants |
|
| 752 | - * |
|
| 753 | - * @return boolean |
|
| 754 | - * @throws EE_Error |
|
| 755 | - * @throws InvalidArgumentException |
|
| 756 | - * @throws InvalidDataTypeException |
|
| 757 | - * @throws InvalidInterfaceException |
|
| 758 | - * @throws ReflectionException |
|
| 759 | - */ |
|
| 760 | - public function failed() |
|
| 761 | - { |
|
| 762 | - return $this->status_ID() === EEM_Transaction::failed_status_code; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * This returns the url for the invoice of this transaction |
|
| 768 | - * |
|
| 769 | - * @param string $type 'html' or 'pdf' (default is pdf) |
|
| 770 | - * @return string |
|
| 771 | - * @throws EE_Error |
|
| 772 | - * @throws InvalidArgumentException |
|
| 773 | - * @throws InvalidDataTypeException |
|
| 774 | - * @throws InvalidInterfaceException |
|
| 775 | - * @throws ReflectionException |
|
| 776 | - */ |
|
| 777 | - public function invoice_url($type = 'html') |
|
| 778 | - { |
|
| 779 | - $REG = $this->primary_registration(); |
|
| 780 | - if (! $REG instanceof EE_Registration) { |
|
| 781 | - return ''; |
|
| 782 | - } |
|
| 783 | - return $REG->invoice_url($type); |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - |
|
| 787 | - /** |
|
| 788 | - * Gets the primary registration only |
|
| 789 | - * |
|
| 790 | - * @return EE_Base_Class|EE_Registration |
|
| 791 | - * @throws EE_Error |
|
| 792 | - * @throws InvalidArgumentException |
|
| 793 | - * @throws InvalidDataTypeException |
|
| 794 | - * @throws InvalidInterfaceException |
|
| 795 | - * @throws ReflectionException |
|
| 796 | - */ |
|
| 797 | - public function primary_registration() |
|
| 798 | - { |
|
| 799 | - $registrations = (array) $this->get_many_related( |
|
| 800 | - 'Registration', |
|
| 801 | - array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
|
| 802 | - ); |
|
| 803 | - foreach ($registrations as $registration) { |
|
| 804 | - // valid registration that is NOT cancelled or declined ? |
|
| 805 | - if ($registration instanceof EE_Registration |
|
| 806 | - && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
|
| 807 | - ) { |
|
| 808 | - return $registration; |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - // nothing valid found, so just return first thing from array of results |
|
| 812 | - return reset($registrations); |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - |
|
| 816 | - /** |
|
| 817 | - * Gets the URL for viewing the receipt |
|
| 818 | - * |
|
| 819 | - * @param string $type 'pdf' or 'html' (default is 'html') |
|
| 820 | - * @return string |
|
| 821 | - * @throws EE_Error |
|
| 822 | - * @throws InvalidArgumentException |
|
| 823 | - * @throws InvalidDataTypeException |
|
| 824 | - * @throws InvalidInterfaceException |
|
| 825 | - * @throws ReflectionException |
|
| 826 | - */ |
|
| 827 | - public function receipt_url($type = 'html') |
|
| 828 | - { |
|
| 829 | - $REG = $this->primary_registration(); |
|
| 830 | - if (! $REG instanceof EE_Registration) { |
|
| 831 | - return ''; |
|
| 832 | - } |
|
| 833 | - return $REG->receipt_url($type); |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - |
|
| 837 | - /** |
|
| 838 | - * Gets the URL of the thank you page with this registration REG_url_link added as |
|
| 839 | - * a query parameter |
|
| 840 | - * |
|
| 841 | - * @return string |
|
| 842 | - * @throws EE_Error |
|
| 843 | - * @throws InvalidArgumentException |
|
| 844 | - * @throws InvalidDataTypeException |
|
| 845 | - * @throws InvalidInterfaceException |
|
| 846 | - * @throws ReflectionException |
|
| 847 | - */ |
|
| 848 | - public function payment_overview_url() |
|
| 849 | - { |
|
| 850 | - $primary_registration = $this->primary_registration(); |
|
| 851 | - return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false; |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - |
|
| 855 | - /** |
|
| 856 | - * @return string |
|
| 857 | - * @throws EE_Error |
|
| 858 | - * @throws InvalidArgumentException |
|
| 859 | - * @throws InvalidDataTypeException |
|
| 860 | - * @throws InvalidInterfaceException |
|
| 861 | - * @throws ReflectionException |
|
| 862 | - */ |
|
| 863 | - public function gateway_response_on_transaction() |
|
| 864 | - { |
|
| 865 | - $payment = $this->get_first_related('Payment'); |
|
| 866 | - return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * Get the status object of this object |
|
| 872 | - * |
|
| 873 | - * @return EE_Base_Class|EE_Status |
|
| 874 | - * @throws EE_Error |
|
| 875 | - * @throws InvalidArgumentException |
|
| 876 | - * @throws InvalidDataTypeException |
|
| 877 | - * @throws InvalidInterfaceException |
|
| 878 | - * @throws ReflectionException |
|
| 879 | - */ |
|
| 880 | - public function status_obj() |
|
| 881 | - { |
|
| 882 | - return $this->get_first_related('Status'); |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - |
|
| 886 | - /** |
|
| 887 | - * Gets all the extra meta info on this payment |
|
| 888 | - * |
|
| 889 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 890 | - * @return EE_Base_Class[]|EE_Extra_Meta |
|
| 891 | - * @throws EE_Error |
|
| 892 | - * @throws InvalidArgumentException |
|
| 893 | - * @throws InvalidDataTypeException |
|
| 894 | - * @throws InvalidInterfaceException |
|
| 895 | - * @throws ReflectionException |
|
| 896 | - */ |
|
| 897 | - public function extra_meta($query_params = array()) |
|
| 898 | - { |
|
| 899 | - return $this->get_many_related('Extra_Meta', $query_params); |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - |
|
| 903 | - /** |
|
| 904 | - * Wrapper for _add_relation_to |
|
| 905 | - * |
|
| 906 | - * @param EE_Registration $registration |
|
| 907 | - * @return EE_Base_Class the relation was added to |
|
| 908 | - * @throws EE_Error |
|
| 909 | - * @throws InvalidArgumentException |
|
| 910 | - * @throws InvalidDataTypeException |
|
| 911 | - * @throws InvalidInterfaceException |
|
| 912 | - * @throws ReflectionException |
|
| 913 | - */ |
|
| 914 | - public function add_registration(EE_Registration $registration) |
|
| 915 | - { |
|
| 916 | - return $this->_add_relation_to($registration, 'Registration'); |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - |
|
| 920 | - /** |
|
| 921 | - * Removes the given registration from being related (even before saving this transaction). |
|
| 922 | - * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations |
|
| 923 | - * |
|
| 924 | - * @param int $registration_or_id |
|
| 925 | - * @return EE_Base_Class that was removed from being related |
|
| 926 | - * @throws EE_Error |
|
| 927 | - * @throws InvalidArgumentException |
|
| 928 | - * @throws InvalidDataTypeException |
|
| 929 | - * @throws InvalidInterfaceException |
|
| 930 | - * @throws ReflectionException |
|
| 931 | - */ |
|
| 932 | - public function remove_registration_with_id($registration_or_id) |
|
| 933 | - { |
|
| 934 | - return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - |
|
| 938 | - /** |
|
| 939 | - * Gets all the line items which are for ACTUAL items |
|
| 940 | - * |
|
| 941 | - * @return EE_Line_Item[] |
|
| 942 | - * @throws EE_Error |
|
| 943 | - * @throws InvalidArgumentException |
|
| 944 | - * @throws InvalidDataTypeException |
|
| 945 | - * @throws InvalidInterfaceException |
|
| 946 | - * @throws ReflectionException |
|
| 947 | - */ |
|
| 948 | - public function items_purchased() |
|
| 949 | - { |
|
| 950 | - return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - |
|
| 954 | - /** |
|
| 955 | - * Wrapper for _add_relation_to |
|
| 956 | - * |
|
| 957 | - * @param EE_Line_Item $line_item |
|
| 958 | - * @return EE_Base_Class the relation was added to |
|
| 959 | - * @throws EE_Error |
|
| 960 | - * @throws InvalidArgumentException |
|
| 961 | - * @throws InvalidDataTypeException |
|
| 962 | - * @throws InvalidInterfaceException |
|
| 963 | - * @throws ReflectionException |
|
| 964 | - */ |
|
| 965 | - public function add_line_item(EE_Line_Item $line_item) |
|
| 966 | - { |
|
| 967 | - return $this->_add_relation_to($line_item, 'Line_Item'); |
|
| 968 | - } |
|
| 969 | - |
|
| 970 | - |
|
| 971 | - /** |
|
| 972 | - * Gets ALL the line items related to this transaction (unstructured) |
|
| 973 | - * |
|
| 974 | - * @param array $query_params |
|
| 975 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 976 | - * @throws EE_Error |
|
| 977 | - * @throws InvalidArgumentException |
|
| 978 | - * @throws InvalidDataTypeException |
|
| 979 | - * @throws InvalidInterfaceException |
|
| 980 | - * @throws ReflectionException |
|
| 981 | - */ |
|
| 982 | - public function line_items($query_params = array()) |
|
| 983 | - { |
|
| 984 | - return $this->get_many_related('Line_Item', $query_params); |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - |
|
| 988 | - /** |
|
| 989 | - * Gets all the line items which are taxes on the total |
|
| 990 | - * |
|
| 991 | - * @return EE_Line_Item[] |
|
| 992 | - * @throws EE_Error |
|
| 993 | - * @throws InvalidArgumentException |
|
| 994 | - * @throws InvalidDataTypeException |
|
| 995 | - * @throws InvalidInterfaceException |
|
| 996 | - * @throws ReflectionException |
|
| 997 | - */ |
|
| 998 | - public function tax_items() |
|
| 999 | - { |
|
| 1000 | - return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - |
|
| 1004 | - /** |
|
| 1005 | - * Gets the total line item (which is a parent of all other related line items, |
|
| 1006 | - * meaning it takes them all into account on its total) |
|
| 1007 | - * |
|
| 1008 | - * @param bool $create_if_not_found |
|
| 1009 | - * @return \EE_Line_Item |
|
| 1010 | - * @throws EE_Error |
|
| 1011 | - * @throws InvalidArgumentException |
|
| 1012 | - * @throws InvalidDataTypeException |
|
| 1013 | - * @throws InvalidInterfaceException |
|
| 1014 | - * @throws ReflectionException |
|
| 1015 | - */ |
|
| 1016 | - public function total_line_item($create_if_not_found = true) |
|
| 1017 | - { |
|
| 1018 | - $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
| 1019 | - if (! $item && $create_if_not_found) { |
|
| 1020 | - $item = EEH_Line_Item::create_total_line_item($this); |
|
| 1021 | - } |
|
| 1022 | - return $item; |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - |
|
| 1026 | - /** |
|
| 1027 | - * Returns the total amount of tax on this transaction |
|
| 1028 | - * (assumes there's only one tax subtotal line item) |
|
| 1029 | - * |
|
| 1030 | - * @return float |
|
| 1031 | - * @throws EE_Error |
|
| 1032 | - * @throws InvalidArgumentException |
|
| 1033 | - * @throws InvalidDataTypeException |
|
| 1034 | - * @throws InvalidInterfaceException |
|
| 1035 | - * @throws ReflectionException |
|
| 1036 | - */ |
|
| 1037 | - public function tax_total() |
|
| 1038 | - { |
|
| 1039 | - $tax_line_item = $this->tax_total_line_item(); |
|
| 1040 | - if ($tax_line_item) { |
|
| 1041 | - return (float) $tax_line_item->total(); |
|
| 1042 | - } |
|
| 1043 | - return (float) 0; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - |
|
| 1047 | - /** |
|
| 1048 | - * Gets the tax subtotal line item (assumes there's only one) |
|
| 1049 | - * |
|
| 1050 | - * @return EE_Line_Item |
|
| 1051 | - * @throws EE_Error |
|
| 1052 | - * @throws InvalidArgumentException |
|
| 1053 | - * @throws InvalidDataTypeException |
|
| 1054 | - * @throws InvalidInterfaceException |
|
| 1055 | - * @throws ReflectionException |
|
| 1056 | - */ |
|
| 1057 | - public function tax_total_line_item() |
|
| 1058 | - { |
|
| 1059 | - return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
| 1060 | - } |
|
| 1061 | - |
|
| 1062 | - |
|
| 1063 | - /** |
|
| 1064 | - * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee. |
|
| 1065 | - * |
|
| 1066 | - * @return EE_Form_Section_Proper |
|
| 1067 | - * @throws EE_Error |
|
| 1068 | - * @throws InvalidArgumentException |
|
| 1069 | - * @throws InvalidDataTypeException |
|
| 1070 | - * @throws InvalidInterfaceException |
|
| 1071 | - * @throws ReflectionException |
|
| 1072 | - */ |
|
| 1073 | - public function billing_info() |
|
| 1074 | - { |
|
| 1075 | - $payment_method = $this->payment_method(); |
|
| 1076 | - if (! $payment_method) { |
|
| 1077 | - EE_Error::add_error( |
|
| 1078 | - __( |
|
| 1079 | - 'Could not find billing info for transaction because no gateway has been used for it yet', |
|
| 1080 | - 'event_espresso' |
|
| 1081 | - ), |
|
| 1082 | - __FILE__, |
|
| 1083 | - __FUNCTION__, |
|
| 1084 | - __LINE__ |
|
| 1085 | - ); |
|
| 1086 | - return null; |
|
| 1087 | - } |
|
| 1088 | - $primary_reg = $this->primary_registration(); |
|
| 1089 | - if (! $primary_reg) { |
|
| 1090 | - EE_Error::add_error( |
|
| 1091 | - __( |
|
| 1092 | - 'Cannot get billing info for gateway %s on transaction because no primary registration exists', |
|
| 1093 | - 'event_espresso' |
|
| 1094 | - ), |
|
| 1095 | - __FILE__, |
|
| 1096 | - __FUNCTION__, |
|
| 1097 | - __LINE__ |
|
| 1098 | - ); |
|
| 1099 | - return null; |
|
| 1100 | - } |
|
| 1101 | - $attendee = $primary_reg->attendee(); |
|
| 1102 | - if (! $attendee) { |
|
| 1103 | - EE_Error::add_error( |
|
| 1104 | - __( |
|
| 1105 | - 'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists', |
|
| 1106 | - 'event_espresso' |
|
| 1107 | - ), |
|
| 1108 | - __FILE__, |
|
| 1109 | - __FUNCTION__, |
|
| 1110 | - __LINE__ |
|
| 1111 | - ); |
|
| 1112 | - return null; |
|
| 1113 | - } |
|
| 1114 | - return $attendee->billing_info_for_payment_method($payment_method); |
|
| 1115 | - } |
|
| 1116 | - |
|
| 1117 | - |
|
| 1118 | - /** |
|
| 1119 | - * Gets PMD_ID |
|
| 1120 | - * |
|
| 1121 | - * @return int |
|
| 1122 | - * @throws EE_Error |
|
| 1123 | - * @throws InvalidArgumentException |
|
| 1124 | - * @throws InvalidDataTypeException |
|
| 1125 | - * @throws InvalidInterfaceException |
|
| 1126 | - * @throws ReflectionException |
|
| 1127 | - */ |
|
| 1128 | - public function payment_method_ID() |
|
| 1129 | - { |
|
| 1130 | - return $this->get('PMD_ID'); |
|
| 1131 | - } |
|
| 1132 | - |
|
| 1133 | - |
|
| 1134 | - /** |
|
| 1135 | - * Sets PMD_ID |
|
| 1136 | - * |
|
| 1137 | - * @param int $PMD_ID |
|
| 1138 | - * @throws EE_Error |
|
| 1139 | - * @throws InvalidArgumentException |
|
| 1140 | - * @throws InvalidDataTypeException |
|
| 1141 | - * @throws InvalidInterfaceException |
|
| 1142 | - * @throws ReflectionException |
|
| 1143 | - */ |
|
| 1144 | - public function set_payment_method_ID($PMD_ID) |
|
| 1145 | - { |
|
| 1146 | - $this->set('PMD_ID', $PMD_ID); |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * Gets the last-used payment method on this transaction |
|
| 1152 | - * (we COULD just use the last-made payment, but some payment methods, namely |
|
| 1153 | - * offline ones, dont' create payments) |
|
| 1154 | - * |
|
| 1155 | - * @return EE_Payment_Method |
|
| 1156 | - * @throws EE_Error |
|
| 1157 | - * @throws InvalidArgumentException |
|
| 1158 | - * @throws InvalidDataTypeException |
|
| 1159 | - * @throws InvalidInterfaceException |
|
| 1160 | - * @throws ReflectionException |
|
| 1161 | - */ |
|
| 1162 | - public function payment_method() |
|
| 1163 | - { |
|
| 1164 | - $pm = $this->get_first_related('Payment_Method'); |
|
| 1165 | - if ($pm instanceof EE_Payment_Method) { |
|
| 1166 | - return $pm; |
|
| 1167 | - } |
|
| 1168 | - $last_payment = $this->last_payment(); |
|
| 1169 | - if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
| 1170 | - return $last_payment->payment_method(); |
|
| 1171 | - } |
|
| 1172 | - return null; |
|
| 1173 | - } |
|
| 1174 | - |
|
| 1175 | - |
|
| 1176 | - /** |
|
| 1177 | - * Gets the last payment made |
|
| 1178 | - * |
|
| 1179 | - * @return EE_Base_Class|EE_Payment |
|
| 1180 | - * @throws EE_Error |
|
| 1181 | - * @throws InvalidArgumentException |
|
| 1182 | - * @throws InvalidDataTypeException |
|
| 1183 | - * @throws InvalidInterfaceException |
|
| 1184 | - * @throws ReflectionException |
|
| 1185 | - */ |
|
| 1186 | - public function last_payment() |
|
| 1187 | - { |
|
| 1188 | - return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
| 1189 | - } |
|
| 1190 | - |
|
| 1191 | - |
|
| 1192 | - /** |
|
| 1193 | - * Gets all the line items which are unrelated to tickets on this transaction |
|
| 1194 | - * |
|
| 1195 | - * @return EE_Line_Item[] |
|
| 1196 | - * @throws EE_Error |
|
| 1197 | - * @throws InvalidArgumentException |
|
| 1198 | - * @throws InvalidDataTypeException |
|
| 1199 | - * @throws InvalidInterfaceException |
|
| 1200 | - * @throws ReflectionException |
|
| 1201 | - */ |
|
| 1202 | - public function non_ticket_line_items() |
|
| 1203 | - { |
|
| 1204 | - return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
| 1205 | - } |
|
| 1206 | - |
|
| 1207 | - |
|
| 1208 | - /** |
|
| 1209 | - * possibly toggles TXN status |
|
| 1210 | - * |
|
| 1211 | - * @param boolean $update whether to save the TXN |
|
| 1212 | - * @return bool whether the TXN was saved |
|
| 1213 | - * @throws EE_Error |
|
| 1214 | - * @throws InvalidArgumentException |
|
| 1215 | - * @throws InvalidDataTypeException |
|
| 1216 | - * @throws InvalidInterfaceException |
|
| 1217 | - * @throws ReflectionException |
|
| 1218 | - * @throws RuntimeException |
|
| 1219 | - */ |
|
| 1220 | - public function update_status_based_on_total_paid($update = true) |
|
| 1221 | - { |
|
| 1222 | - // set transaction status based on comparison of TXN_paid vs TXN_total |
|
| 1223 | - if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) { |
|
| 1224 | - $new_txn_status = EEM_Transaction::overpaid_status_code; |
|
| 1225 | - } elseif (EEH_Money::compare_floats($this->paid(), $this->total())) { |
|
| 1226 | - $new_txn_status = EEM_Transaction::complete_status_code; |
|
| 1227 | - } elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) { |
|
| 1228 | - $new_txn_status = EEM_Transaction::incomplete_status_code; |
|
| 1229 | - } else { |
|
| 1230 | - throw new RuntimeException( |
|
| 1231 | - __('The total paid calculation for this transaction is inaccurate.', 'event_espresso') |
|
| 1232 | - ); |
|
| 1233 | - } |
|
| 1234 | - if ($new_txn_status !== $this->status_ID()) { |
|
| 1235 | - $this->set_status($new_txn_status); |
|
| 1236 | - if ($update) { |
|
| 1237 | - return $this->save() ? true : false; |
|
| 1238 | - } |
|
| 1239 | - } |
|
| 1240 | - return false; |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - |
|
| 1244 | - /** |
|
| 1245 | - * Updates the transaction's status and total_paid based on all the payments |
|
| 1246 | - * that apply to it |
|
| 1247 | - * |
|
| 1248 | - * @deprecated |
|
| 1249 | - * @return array|bool |
|
| 1250 | - * @throws EE_Error |
|
| 1251 | - * @throws InvalidArgumentException |
|
| 1252 | - * @throws ReflectionException |
|
| 1253 | - * @throws InvalidDataTypeException |
|
| 1254 | - * @throws InvalidInterfaceException |
|
| 1255 | - */ |
|
| 1256 | - public function update_based_on_payments() |
|
| 1257 | - { |
|
| 1258 | - EE_Error::doing_it_wrong( |
|
| 1259 | - __CLASS__ . '::' . __FUNCTION__, |
|
| 1260 | - sprintf( |
|
| 1261 | - __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 1262 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
| 1263 | - ), |
|
| 1264 | - '4.6.0' |
|
| 1265 | - ); |
|
| 1266 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1267 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1268 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - |
|
| 1272 | - /** |
|
| 1273 | - * @return string |
|
| 1274 | - */ |
|
| 1275 | - public function old_txn_status() |
|
| 1276 | - { |
|
| 1277 | - return $this->_old_txn_status; |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - |
|
| 1281 | - /** |
|
| 1282 | - * @param string $old_txn_status |
|
| 1283 | - */ |
|
| 1284 | - public function set_old_txn_status($old_txn_status) |
|
| 1285 | - { |
|
| 1286 | - // only set the first time |
|
| 1287 | - if ($this->_old_txn_status === null) { |
|
| 1288 | - $this->_old_txn_status = $old_txn_status; |
|
| 1289 | - } |
|
| 1290 | - } |
|
| 1291 | - |
|
| 1292 | - |
|
| 1293 | - /** |
|
| 1294 | - * reg_status_updated |
|
| 1295 | - * |
|
| 1296 | - * @return bool |
|
| 1297 | - * @throws EE_Error |
|
| 1298 | - * @throws InvalidArgumentException |
|
| 1299 | - * @throws InvalidDataTypeException |
|
| 1300 | - * @throws InvalidInterfaceException |
|
| 1301 | - * @throws ReflectionException |
|
| 1302 | - */ |
|
| 1303 | - public function txn_status_updated() |
|
| 1304 | - { |
|
| 1305 | - return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null; |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - |
|
| 1309 | - /** |
|
| 1310 | - * _reg_steps_completed |
|
| 1311 | - * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed, |
|
| 1312 | - * if a $reg_step_slug is provided, then this step will be skipped when testing for completion |
|
| 1313 | - * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion |
|
| 1314 | - * |
|
| 1315 | - * @param string $reg_step_slug |
|
| 1316 | - * @param bool $check_all |
|
| 1317 | - * @return bool|int |
|
| 1318 | - * @throws EE_Error |
|
| 1319 | - * @throws InvalidArgumentException |
|
| 1320 | - * @throws InvalidDataTypeException |
|
| 1321 | - * @throws InvalidInterfaceException |
|
| 1322 | - * @throws ReflectionException |
|
| 1323 | - */ |
|
| 1324 | - private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
|
| 1325 | - { |
|
| 1326 | - $reg_steps = $this->reg_steps(); |
|
| 1327 | - if (! is_array($reg_steps) || empty($reg_steps)) { |
|
| 1328 | - return false; |
|
| 1329 | - } |
|
| 1330 | - // loop thru reg steps array) |
|
| 1331 | - foreach ($reg_steps as $slug => $reg_step_completed) { |
|
| 1332 | - // if NOT checking ALL steps (only checking one step) |
|
| 1333 | - if (! $check_all) { |
|
| 1334 | - // and this is the one |
|
| 1335 | - if ($slug === $reg_step_slug) { |
|
| 1336 | - return $reg_step_completed; |
|
| 1337 | - } |
|
| 1338 | - // skip to next reg step in loop |
|
| 1339 | - continue; |
|
| 1340 | - } |
|
| 1341 | - // $check_all must be true, else we would never have gotten to this point |
|
| 1342 | - if ($slug === $reg_step_slug) { |
|
| 1343 | - // if we reach this point, then we are testing either: |
|
| 1344 | - // all_reg_steps_completed_except() or |
|
| 1345 | - // all_reg_steps_completed_except_final_step(), |
|
| 1346 | - // and since this is the reg step EXCEPTION being tested |
|
| 1347 | - // we want to return true (yes true) if this reg step is NOT completed |
|
| 1348 | - // ie: "is everything completed except the final step?" |
|
| 1349 | - // "that is correct... the final step is not completed, but all others are." |
|
| 1350 | - return $reg_step_completed !== true; |
|
| 1351 | - } |
|
| 1352 | - if ($reg_step_completed !== true) { |
|
| 1353 | - // if any reg step is NOT completed, then ALL steps are not completed |
|
| 1354 | - return false; |
|
| 1355 | - } |
|
| 1356 | - } |
|
| 1357 | - return true; |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - |
|
| 1361 | - /** |
|
| 1362 | - * all_reg_steps_completed |
|
| 1363 | - * returns: |
|
| 1364 | - * true if ALL reg steps have been marked as completed |
|
| 1365 | - * or false if any step is not completed |
|
| 1366 | - * |
|
| 1367 | - * @return bool |
|
| 1368 | - * @throws EE_Error |
|
| 1369 | - * @throws InvalidArgumentException |
|
| 1370 | - * @throws InvalidDataTypeException |
|
| 1371 | - * @throws InvalidInterfaceException |
|
| 1372 | - * @throws ReflectionException |
|
| 1373 | - */ |
|
| 1374 | - public function all_reg_steps_completed() |
|
| 1375 | - { |
|
| 1376 | - return $this->_reg_steps_completed(); |
|
| 1377 | - } |
|
| 1378 | - |
|
| 1379 | - |
|
| 1380 | - /** |
|
| 1381 | - * all_reg_steps_completed_except |
|
| 1382 | - * returns: |
|
| 1383 | - * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
|
| 1384 | - * or false if any other step is not completed |
|
| 1385 | - * or false if ALL steps are completed including the exception you are testing !!! |
|
| 1386 | - * |
|
| 1387 | - * @param string $exception |
|
| 1388 | - * @return bool |
|
| 1389 | - * @throws EE_Error |
|
| 1390 | - * @throws InvalidArgumentException |
|
| 1391 | - * @throws InvalidDataTypeException |
|
| 1392 | - * @throws InvalidInterfaceException |
|
| 1393 | - * @throws ReflectionException |
|
| 1394 | - */ |
|
| 1395 | - public function all_reg_steps_completed_except($exception = '') |
|
| 1396 | - { |
|
| 1397 | - return $this->_reg_steps_completed($exception); |
|
| 1398 | - } |
|
| 1399 | - |
|
| 1400 | - |
|
| 1401 | - /** |
|
| 1402 | - * all_reg_steps_completed_except |
|
| 1403 | - * returns: |
|
| 1404 | - * true if ALL reg steps, except the final step, have been marked as completed |
|
| 1405 | - * or false if any step is not completed |
|
| 1406 | - * or false if ALL steps are completed including the final step !!! |
|
| 1407 | - * |
|
| 1408 | - * @return bool |
|
| 1409 | - * @throws EE_Error |
|
| 1410 | - * @throws InvalidArgumentException |
|
| 1411 | - * @throws InvalidDataTypeException |
|
| 1412 | - * @throws InvalidInterfaceException |
|
| 1413 | - * @throws ReflectionException |
|
| 1414 | - */ |
|
| 1415 | - public function all_reg_steps_completed_except_final_step() |
|
| 1416 | - { |
|
| 1417 | - return $this->_reg_steps_completed('finalize_registration'); |
|
| 1418 | - } |
|
| 1419 | - |
|
| 1420 | - |
|
| 1421 | - /** |
|
| 1422 | - * reg_step_completed |
|
| 1423 | - * returns: |
|
| 1424 | - * true if a specific reg step has been marked as completed |
|
| 1425 | - * a Unix timestamp if it has been initialized but not yet completed, |
|
| 1426 | - * or false if it has not yet been initialized |
|
| 1427 | - * |
|
| 1428 | - * @param string $reg_step_slug |
|
| 1429 | - * @return bool|int |
|
| 1430 | - * @throws EE_Error |
|
| 1431 | - * @throws InvalidArgumentException |
|
| 1432 | - * @throws InvalidDataTypeException |
|
| 1433 | - * @throws InvalidInterfaceException |
|
| 1434 | - * @throws ReflectionException |
|
| 1435 | - */ |
|
| 1436 | - public function reg_step_completed($reg_step_slug) |
|
| 1437 | - { |
|
| 1438 | - return $this->_reg_steps_completed($reg_step_slug, false); |
|
| 1439 | - } |
|
| 1440 | - |
|
| 1441 | - |
|
| 1442 | - /** |
|
| 1443 | - * completed_final_reg_step |
|
| 1444 | - * returns: |
|
| 1445 | - * true if the finalize_registration reg step has been marked as completed |
|
| 1446 | - * a Unix timestamp if it has been initialized but not yet completed, |
|
| 1447 | - * or false if it has not yet been initialized |
|
| 1448 | - * |
|
| 1449 | - * @return bool|int |
|
| 1450 | - * @throws EE_Error |
|
| 1451 | - * @throws InvalidArgumentException |
|
| 1452 | - * @throws InvalidDataTypeException |
|
| 1453 | - * @throws InvalidInterfaceException |
|
| 1454 | - * @throws ReflectionException |
|
| 1455 | - */ |
|
| 1456 | - public function final_reg_step_completed() |
|
| 1457 | - { |
|
| 1458 | - return $this->_reg_steps_completed('finalize_registration', false); |
|
| 1459 | - } |
|
| 1460 | - |
|
| 1461 | - |
|
| 1462 | - /** |
|
| 1463 | - * set_reg_step_initiated |
|
| 1464 | - * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
|
| 1465 | - * |
|
| 1466 | - * @param string $reg_step_slug |
|
| 1467 | - * @return boolean |
|
| 1468 | - * @throws EE_Error |
|
| 1469 | - * @throws InvalidArgumentException |
|
| 1470 | - * @throws InvalidDataTypeException |
|
| 1471 | - * @throws InvalidInterfaceException |
|
| 1472 | - * @throws ReflectionException |
|
| 1473 | - */ |
|
| 1474 | - public function set_reg_step_initiated($reg_step_slug) |
|
| 1475 | - { |
|
| 1476 | - return $this->_set_reg_step_completed_status($reg_step_slug, time()); |
|
| 1477 | - } |
|
| 1478 | - |
|
| 1479 | - |
|
| 1480 | - /** |
|
| 1481 | - * set_reg_step_completed |
|
| 1482 | - * given a valid TXN_reg_step, this sets the step as completed |
|
| 1483 | - * |
|
| 1484 | - * @param string $reg_step_slug |
|
| 1485 | - * @return boolean |
|
| 1486 | - * @throws EE_Error |
|
| 1487 | - * @throws InvalidArgumentException |
|
| 1488 | - * @throws InvalidDataTypeException |
|
| 1489 | - * @throws InvalidInterfaceException |
|
| 1490 | - * @throws ReflectionException |
|
| 1491 | - */ |
|
| 1492 | - public function set_reg_step_completed($reg_step_slug) |
|
| 1493 | - { |
|
| 1494 | - return $this->_set_reg_step_completed_status($reg_step_slug, true); |
|
| 1495 | - } |
|
| 1496 | - |
|
| 1497 | - |
|
| 1498 | - /** |
|
| 1499 | - * set_reg_step_completed |
|
| 1500 | - * given a valid TXN_reg_step slug, this sets the step as NOT completed |
|
| 1501 | - * |
|
| 1502 | - * @param string $reg_step_slug |
|
| 1503 | - * @return boolean |
|
| 1504 | - * @throws EE_Error |
|
| 1505 | - * @throws InvalidArgumentException |
|
| 1506 | - * @throws InvalidDataTypeException |
|
| 1507 | - * @throws InvalidInterfaceException |
|
| 1508 | - * @throws ReflectionException |
|
| 1509 | - */ |
|
| 1510 | - public function set_reg_step_not_completed($reg_step_slug) |
|
| 1511 | - { |
|
| 1512 | - return $this->_set_reg_step_completed_status($reg_step_slug, false); |
|
| 1513 | - } |
|
| 1514 | - |
|
| 1515 | - |
|
| 1516 | - /** |
|
| 1517 | - * set_reg_step_completed |
|
| 1518 | - * given a valid reg step slug, this sets the TXN_reg_step completed status which is either: |
|
| 1519 | - * |
|
| 1520 | - * @param string $reg_step_slug |
|
| 1521 | - * @param boolean|int $status |
|
| 1522 | - * @return boolean |
|
| 1523 | - * @throws EE_Error |
|
| 1524 | - * @throws InvalidArgumentException |
|
| 1525 | - * @throws InvalidDataTypeException |
|
| 1526 | - * @throws InvalidInterfaceException |
|
| 1527 | - * @throws ReflectionException |
|
| 1528 | - */ |
|
| 1529 | - private function _set_reg_step_completed_status($reg_step_slug, $status) |
|
| 1530 | - { |
|
| 1531 | - // validate status |
|
| 1532 | - $status = is_bool($status) || is_int($status) ? $status : false; |
|
| 1533 | - // get reg steps array |
|
| 1534 | - $txn_reg_steps = $this->reg_steps(); |
|
| 1535 | - // if reg step does NOT exist |
|
| 1536 | - if (! isset($txn_reg_steps[ $reg_step_slug ])) { |
|
| 1537 | - return false; |
|
| 1538 | - } |
|
| 1539 | - // if we're trying to complete a step that is already completed |
|
| 1540 | - if ($txn_reg_steps[ $reg_step_slug ] === true) { |
|
| 1541 | - return true; |
|
| 1542 | - } |
|
| 1543 | - // if we're trying to complete a step that hasn't even started |
|
| 1544 | - if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) { |
|
| 1545 | - return false; |
|
| 1546 | - } |
|
| 1547 | - // if current status value matches the incoming value (no change) |
|
| 1548 | - // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
|
| 1549 | - if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) { |
|
| 1550 | - // this will happen in cases where multiple AJAX requests occur during the same step |
|
| 1551 | - return true; |
|
| 1552 | - } |
|
| 1553 | - // if we're trying to set a start time, but it has already been set... |
|
| 1554 | - if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) { |
|
| 1555 | - // skip the update below, but don't return FALSE so that errors won't be displayed |
|
| 1556 | - return true; |
|
| 1557 | - } |
|
| 1558 | - // update completed status |
|
| 1559 | - $txn_reg_steps[ $reg_step_slug ] = $status; |
|
| 1560 | - $this->set_reg_steps($txn_reg_steps); |
|
| 1561 | - $this->save(); |
|
| 1562 | - return true; |
|
| 1563 | - } |
|
| 1564 | - |
|
| 1565 | - |
|
| 1566 | - /** |
|
| 1567 | - * remove_reg_step |
|
| 1568 | - * given a valid TXN_reg_step slug, this will remove (unset) |
|
| 1569 | - * the reg step from the TXN reg step array |
|
| 1570 | - * |
|
| 1571 | - * @param string $reg_step_slug |
|
| 1572 | - * @return void |
|
| 1573 | - * @throws EE_Error |
|
| 1574 | - * @throws InvalidArgumentException |
|
| 1575 | - * @throws InvalidDataTypeException |
|
| 1576 | - * @throws InvalidInterfaceException |
|
| 1577 | - * @throws ReflectionException |
|
| 1578 | - */ |
|
| 1579 | - public function remove_reg_step($reg_step_slug) |
|
| 1580 | - { |
|
| 1581 | - // get reg steps array |
|
| 1582 | - $txn_reg_steps = $this->reg_steps(); |
|
| 1583 | - unset($txn_reg_steps[ $reg_step_slug ]); |
|
| 1584 | - $this->set_reg_steps($txn_reg_steps); |
|
| 1585 | - } |
|
| 1586 | - |
|
| 1587 | - |
|
| 1588 | - /** |
|
| 1589 | - * toggle_failed_transaction_status |
|
| 1590 | - * upgrades a TXNs status from failed to abandoned, |
|
| 1591 | - * meaning that contact information has been captured for at least one registrant |
|
| 1592 | - * |
|
| 1593 | - * @param bool $save |
|
| 1594 | - * @return bool |
|
| 1595 | - * @throws EE_Error |
|
| 1596 | - * @throws InvalidArgumentException |
|
| 1597 | - * @throws InvalidDataTypeException |
|
| 1598 | - * @throws InvalidInterfaceException |
|
| 1599 | - * @throws ReflectionException |
|
| 1600 | - */ |
|
| 1601 | - public function toggle_failed_transaction_status($save = true) |
|
| 1602 | - { |
|
| 1603 | - // if TXN status is still set as "failed"... |
|
| 1604 | - if ($this->status_ID() === EEM_Transaction::failed_status_code) { |
|
| 1605 | - $this->set_status(EEM_Transaction::abandoned_status_code); |
|
| 1606 | - if ($save) { |
|
| 1607 | - $this->save(); |
|
| 1608 | - } |
|
| 1609 | - return true; |
|
| 1610 | - } |
|
| 1611 | - return false; |
|
| 1612 | - } |
|
| 1613 | - |
|
| 1614 | - |
|
| 1615 | - /** |
|
| 1616 | - * toggle_abandoned_transaction_status |
|
| 1617 | - * upgrades a TXNs status from failed or abandoned to incomplete |
|
| 1618 | - * |
|
| 1619 | - * @return bool |
|
| 1620 | - * @throws EE_Error |
|
| 1621 | - * @throws InvalidArgumentException |
|
| 1622 | - * @throws InvalidDataTypeException |
|
| 1623 | - * @throws InvalidInterfaceException |
|
| 1624 | - * @throws ReflectionException |
|
| 1625 | - */ |
|
| 1626 | - public function toggle_abandoned_transaction_status() |
|
| 1627 | - { |
|
| 1628 | - // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"... |
|
| 1629 | - $txn_status = $this->status_ID(); |
|
| 1630 | - if ($txn_status === EEM_Transaction::failed_status_code |
|
| 1631 | - || $txn_status === EEM_Transaction::abandoned_status_code |
|
| 1632 | - ) { |
|
| 1633 | - // if a contact record for the primary registrant has been created |
|
| 1634 | - if ($this->primary_registration() instanceof EE_Registration |
|
| 1635 | - && $this->primary_registration()->attendee() instanceof EE_Attendee |
|
| 1636 | - ) { |
|
| 1637 | - $this->set_status(EEM_Transaction::incomplete_status_code); |
|
| 1638 | - } else { |
|
| 1639 | - // no contact record? yer abandoned! |
|
| 1640 | - $this->set_status(EEM_Transaction::abandoned_status_code); |
|
| 1641 | - } |
|
| 1642 | - return true; |
|
| 1643 | - } |
|
| 1644 | - return false; |
|
| 1645 | - } |
|
| 1646 | - |
|
| 1647 | - |
|
| 1648 | - /** |
|
| 1649 | - * checks if an Abandoned TXN has any related payments, and if so, |
|
| 1650 | - * updates the TXN status based on the amount paid |
|
| 1651 | - * |
|
| 1652 | - * @throws EE_Error |
|
| 1653 | - * @throws InvalidDataTypeException |
|
| 1654 | - * @throws InvalidInterfaceException |
|
| 1655 | - * @throws InvalidArgumentException |
|
| 1656 | - * @throws RuntimeException |
|
| 1657 | - * @throws ReflectionException |
|
| 1658 | - */ |
|
| 1659 | - public function verify_abandoned_transaction_status() |
|
| 1660 | - { |
|
| 1661 | - if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) { |
|
| 1662 | - return; |
|
| 1663 | - } |
|
| 1664 | - $payments = $this->get_many_related('Payment'); |
|
| 1665 | - if (! empty($payments)) { |
|
| 1666 | - foreach ($payments as $payment) { |
|
| 1667 | - if ($payment instanceof EE_Payment) { |
|
| 1668 | - // kk this TXN should NOT be abandoned |
|
| 1669 | - $this->update_status_based_on_total_paid(); |
|
| 1670 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 1671 | - EE_Error::add_attention( |
|
| 1672 | - sprintf( |
|
| 1673 | - esc_html__( |
|
| 1674 | - 'The status for Transaction #%1$d has been updated from "Abandoned" to "%2$s", because at least one payment has been made towards it. If the payment appears in the "Payment Details" table below, you may need to edit its status and/or other details as well.', |
|
| 1675 | - 'event_espresso' |
|
| 1676 | - ), |
|
| 1677 | - $this->ID(), |
|
| 1678 | - $this->pretty_status() |
|
| 1679 | - ) |
|
| 1680 | - ); |
|
| 1681 | - } |
|
| 1682 | - // get final reg step status |
|
| 1683 | - $finalized = $this->final_reg_step_completed(); |
|
| 1684 | - // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
| 1685 | - // but has not yet been fully completed (TRUE) |
|
| 1686 | - if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
| 1687 | - $this->set_reg_step_completed('finalize_registration'); |
|
| 1688 | - $this->save(); |
|
| 1689 | - } |
|
| 1690 | - } |
|
| 1691 | - } |
|
| 1692 | - } |
|
| 1693 | - } |
|
| 16 | + /** |
|
| 17 | + * The length of time in seconds that a lock is applied before being considered expired. |
|
| 18 | + * It is not long because a transaction should only be locked for the duration of the request that locked it |
|
| 19 | + */ |
|
| 20 | + const LOCK_EXPIRATION = 2; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * txn status upon initial construction. |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected $_old_txn_status; |
|
| 28 | + |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @param array $props_n_values incoming values |
|
| 32 | + * @param string $timezone incoming timezone |
|
| 33 | + * (if not set the timezone set for the website will be used.) |
|
| 34 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 35 | + * date_format and the second value is the time format |
|
| 36 | + * @return EE_Transaction |
|
| 37 | + * @throws EE_Error |
|
| 38 | + * @throws InvalidArgumentException |
|
| 39 | + * @throws InvalidDataTypeException |
|
| 40 | + * @throws InvalidInterfaceException |
|
| 41 | + * @throws ReflectionException |
|
| 42 | + */ |
|
| 43 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 44 | + { |
|
| 45 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 46 | + $txn = $has_object |
|
| 47 | + ? $has_object |
|
| 48 | + : new self($props_n_values, false, $timezone, $date_formats); |
|
| 49 | + if (! $has_object) { |
|
| 50 | + $txn->set_old_txn_status($txn->status_ID()); |
|
| 51 | + } |
|
| 52 | + return $txn; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @param array $props_n_values incoming values from the database |
|
| 58 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 59 | + * the website will be used. |
|
| 60 | + * @return EE_Transaction |
|
| 61 | + * @throws EE_Error |
|
| 62 | + * @throws InvalidArgumentException |
|
| 63 | + * @throws InvalidDataTypeException |
|
| 64 | + * @throws InvalidInterfaceException |
|
| 65 | + * @throws ReflectionException |
|
| 66 | + */ |
|
| 67 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 68 | + { |
|
| 69 | + $txn = new self($props_n_values, true, $timezone); |
|
| 70 | + $txn->set_old_txn_status($txn->status_ID()); |
|
| 71 | + return $txn; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Sets a meta field indicating that this TXN is locked and should not be updated in the db. |
|
| 77 | + * If a lock has already been set, then we will attempt to remove it in case it has expired. |
|
| 78 | + * If that also fails, then an exception is thrown. |
|
| 79 | + * |
|
| 80 | + * @throws EE_Error |
|
| 81 | + * @throws InvalidArgumentException |
|
| 82 | + * @throws InvalidDataTypeException |
|
| 83 | + * @throws InvalidInterfaceException |
|
| 84 | + * @throws ReflectionException |
|
| 85 | + */ |
|
| 86 | + public function lock() |
|
| 87 | + { |
|
| 88 | + // attempt to set lock, but if that fails... |
|
| 89 | + if (! $this->add_extra_meta('lock', time(), true)) { |
|
| 90 | + // then attempt to remove the lock in case it is expired |
|
| 91 | + if ($this->_remove_expired_lock()) { |
|
| 92 | + // if removal was successful, then try setting lock again |
|
| 93 | + $this->lock(); |
|
| 94 | + } else { |
|
| 95 | + // but if the lock can not be removed, then throw an exception |
|
| 96 | + throw new EE_Error( |
|
| 97 | + sprintf( |
|
| 98 | + __( |
|
| 99 | + 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', |
|
| 100 | + 'event_espresso' |
|
| 101 | + ), |
|
| 102 | + $this->ID() |
|
| 103 | + ) |
|
| 104 | + ); |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * removes transaction lock applied in EE_Transaction::lock() |
|
| 112 | + * |
|
| 113 | + * @return int |
|
| 114 | + * @throws EE_Error |
|
| 115 | + * @throws InvalidArgumentException |
|
| 116 | + * @throws InvalidDataTypeException |
|
| 117 | + * @throws InvalidInterfaceException |
|
| 118 | + * @throws ReflectionException |
|
| 119 | + */ |
|
| 120 | + public function unlock() |
|
| 121 | + { |
|
| 122 | + return $this->delete_extra_meta('lock'); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Decides whether or not now is the right time to update the transaction. |
|
| 128 | + * This is useful because we don't always know if it is safe to update the transaction |
|
| 129 | + * and its related data. why? |
|
| 130 | + * because it's possible that the transaction is being used in another |
|
| 131 | + * request and could overwrite anything we save. |
|
| 132 | + * So we want to only update the txn once we know that won't happen. |
|
| 133 | + * We also check that the lock isn't expired, and remove it if it is |
|
| 134 | + * |
|
| 135 | + * @return boolean |
|
| 136 | + * @throws EE_Error |
|
| 137 | + * @throws InvalidArgumentException |
|
| 138 | + * @throws InvalidDataTypeException |
|
| 139 | + * @throws InvalidInterfaceException |
|
| 140 | + * @throws ReflectionException |
|
| 141 | + */ |
|
| 142 | + public function is_locked() |
|
| 143 | + { |
|
| 144 | + // if TXN is not locked, then return false immediately |
|
| 145 | + if (! $this->_get_lock()) { |
|
| 146 | + return false; |
|
| 147 | + } |
|
| 148 | + // if not, then let's try and remove the lock in case it's expired... |
|
| 149 | + // _remove_expired_lock() returns 0 when lock is valid (ie: removed = false) |
|
| 150 | + // and a positive number if the lock was removed (ie: number of locks deleted), |
|
| 151 | + // so we need to return the opposite |
|
| 152 | + return ! $this->_remove_expired_lock() ? true : false; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Gets the meta field indicating that this TXN is locked |
|
| 158 | + * |
|
| 159 | + * @return int |
|
| 160 | + * @throws EE_Error |
|
| 161 | + * @throws InvalidArgumentException |
|
| 162 | + * @throws InvalidDataTypeException |
|
| 163 | + * @throws InvalidInterfaceException |
|
| 164 | + * @throws ReflectionException |
|
| 165 | + */ |
|
| 166 | + protected function _get_lock() |
|
| 167 | + { |
|
| 168 | + return (int) $this->get_extra_meta('lock', true, 0); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated |
|
| 174 | + * |
|
| 175 | + * @return int |
|
| 176 | + * @throws EE_Error |
|
| 177 | + * @throws InvalidArgumentException |
|
| 178 | + * @throws InvalidDataTypeException |
|
| 179 | + * @throws InvalidInterfaceException |
|
| 180 | + * @throws ReflectionException |
|
| 181 | + */ |
|
| 182 | + protected function _remove_expired_lock() |
|
| 183 | + { |
|
| 184 | + $locked = $this->_get_lock(); |
|
| 185 | + if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
| 186 | + return $this->unlock(); |
|
| 187 | + } |
|
| 188 | + return 0; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Set transaction total |
|
| 194 | + * |
|
| 195 | + * @param float $total total value of transaction |
|
| 196 | + * @throws EE_Error |
|
| 197 | + * @throws InvalidArgumentException |
|
| 198 | + * @throws InvalidDataTypeException |
|
| 199 | + * @throws InvalidInterfaceException |
|
| 200 | + * @throws ReflectionException |
|
| 201 | + */ |
|
| 202 | + public function set_total($total = 0.00) |
|
| 203 | + { |
|
| 204 | + $this->set('TXN_total', (float) $total); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + |
|
| 208 | + /** |
|
| 209 | + * Set Total Amount Paid to Date |
|
| 210 | + * |
|
| 211 | + * @param float $total_paid total amount paid to date (sum of all payments) |
|
| 212 | + * @throws EE_Error |
|
| 213 | + * @throws InvalidArgumentException |
|
| 214 | + * @throws InvalidDataTypeException |
|
| 215 | + * @throws InvalidInterfaceException |
|
| 216 | + * @throws ReflectionException |
|
| 217 | + */ |
|
| 218 | + public function set_paid($total_paid = 0.00) |
|
| 219 | + { |
|
| 220 | + $this->set('TXN_paid', (float) $total_paid); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Set transaction status |
|
| 226 | + * |
|
| 227 | + * @param string $status whether the transaction is open, declined, accepted, |
|
| 228 | + * or any number of custom values that can be set |
|
| 229 | + * @throws EE_Error |
|
| 230 | + * @throws InvalidArgumentException |
|
| 231 | + * @throws InvalidDataTypeException |
|
| 232 | + * @throws InvalidInterfaceException |
|
| 233 | + * @throws ReflectionException |
|
| 234 | + */ |
|
| 235 | + public function set_status($status = '') |
|
| 236 | + { |
|
| 237 | + $this->set('STS_ID', $status); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Set hash salt |
|
| 243 | + * |
|
| 244 | + * @param string $hash_salt required for some payment gateways |
|
| 245 | + * @throws EE_Error |
|
| 246 | + * @throws InvalidArgumentException |
|
| 247 | + * @throws InvalidDataTypeException |
|
| 248 | + * @throws InvalidInterfaceException |
|
| 249 | + * @throws ReflectionException |
|
| 250 | + */ |
|
| 251 | + public function set_hash_salt($hash_salt = '') |
|
| 252 | + { |
|
| 253 | + $this->set('TXN_hash_salt', $hash_salt); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Sets TXN_reg_steps array |
|
| 259 | + * |
|
| 260 | + * @param array $txn_reg_steps |
|
| 261 | + * @throws EE_Error |
|
| 262 | + * @throws InvalidArgumentException |
|
| 263 | + * @throws InvalidDataTypeException |
|
| 264 | + * @throws InvalidInterfaceException |
|
| 265 | + * @throws ReflectionException |
|
| 266 | + */ |
|
| 267 | + public function set_reg_steps(array $txn_reg_steps) |
|
| 268 | + { |
|
| 269 | + $this->set('TXN_reg_steps', $txn_reg_steps); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Gets TXN_reg_steps |
|
| 275 | + * |
|
| 276 | + * @return array |
|
| 277 | + * @throws EE_Error |
|
| 278 | + * @throws InvalidArgumentException |
|
| 279 | + * @throws InvalidDataTypeException |
|
| 280 | + * @throws InvalidInterfaceException |
|
| 281 | + * @throws ReflectionException |
|
| 282 | + */ |
|
| 283 | + public function reg_steps() |
|
| 284 | + { |
|
| 285 | + $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
| 286 | + return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array(); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * @return string of transaction's total cost, with currency symbol and decimal |
|
| 292 | + * @throws EE_Error |
|
| 293 | + * @throws InvalidArgumentException |
|
| 294 | + * @throws InvalidDataTypeException |
|
| 295 | + * @throws InvalidInterfaceException |
|
| 296 | + * @throws ReflectionException |
|
| 297 | + */ |
|
| 298 | + public function pretty_total() |
|
| 299 | + { |
|
| 300 | + return $this->get_pretty('TXN_total'); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Gets the amount paid in a pretty string (formatted and with currency symbol) |
|
| 306 | + * |
|
| 307 | + * @return string |
|
| 308 | + * @throws EE_Error |
|
| 309 | + * @throws InvalidArgumentException |
|
| 310 | + * @throws InvalidDataTypeException |
|
| 311 | + * @throws InvalidInterfaceException |
|
| 312 | + * @throws ReflectionException |
|
| 313 | + */ |
|
| 314 | + public function pretty_paid() |
|
| 315 | + { |
|
| 316 | + return $this->get_pretty('TXN_paid'); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * calculate the amount remaining for this transaction and return; |
|
| 322 | + * |
|
| 323 | + * @return float amount remaining |
|
| 324 | + * @throws EE_Error |
|
| 325 | + * @throws InvalidArgumentException |
|
| 326 | + * @throws InvalidDataTypeException |
|
| 327 | + * @throws InvalidInterfaceException |
|
| 328 | + * @throws ReflectionException |
|
| 329 | + */ |
|
| 330 | + public function remaining() |
|
| 331 | + { |
|
| 332 | + return $this->total() - $this->paid(); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * get Transaction Total |
|
| 338 | + * |
|
| 339 | + * @return float |
|
| 340 | + * @throws EE_Error |
|
| 341 | + * @throws InvalidArgumentException |
|
| 342 | + * @throws InvalidDataTypeException |
|
| 343 | + * @throws InvalidInterfaceException |
|
| 344 | + * @throws ReflectionException |
|
| 345 | + */ |
|
| 346 | + public function total() |
|
| 347 | + { |
|
| 348 | + return (float) $this->get('TXN_total'); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * get Total Amount Paid to Date |
|
| 354 | + * |
|
| 355 | + * @return float |
|
| 356 | + * @throws EE_Error |
|
| 357 | + * @throws InvalidArgumentException |
|
| 358 | + * @throws InvalidDataTypeException |
|
| 359 | + * @throws InvalidInterfaceException |
|
| 360 | + * @throws ReflectionException |
|
| 361 | + */ |
|
| 362 | + public function paid() |
|
| 363 | + { |
|
| 364 | + return (float) $this->get('TXN_paid'); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * @return mixed|null |
|
| 370 | + * @throws EE_Error |
|
| 371 | + * @throws InvalidArgumentException |
|
| 372 | + * @throws InvalidDataTypeException |
|
| 373 | + * @throws InvalidInterfaceException |
|
| 374 | + * @throws ReflectionException |
|
| 375 | + */ |
|
| 376 | + public function get_cart_session() |
|
| 377 | + { |
|
| 378 | + $session_data = (array) $this->get('TXN_session_data'); |
|
| 379 | + return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
| 380 | + ? $session_data['cart'] |
|
| 381 | + : null; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * get Transaction session data |
|
| 387 | + * |
|
| 388 | + * @return array|mixed |
|
| 389 | + * @throws EE_Error |
|
| 390 | + * @throws InvalidArgumentException |
|
| 391 | + * @throws InvalidDataTypeException |
|
| 392 | + * @throws InvalidInterfaceException |
|
| 393 | + * @throws ReflectionException |
|
| 394 | + */ |
|
| 395 | + public function session_data() |
|
| 396 | + { |
|
| 397 | + $session_data = $this->get('TXN_session_data'); |
|
| 398 | + if (empty($session_data)) { |
|
| 399 | + $session_data = array( |
|
| 400 | + 'id' => null, |
|
| 401 | + 'user_id' => null, |
|
| 402 | + 'ip_address' => null, |
|
| 403 | + 'user_agent' => null, |
|
| 404 | + 'init_access' => null, |
|
| 405 | + 'last_access' => null, |
|
| 406 | + 'pages_visited' => array(), |
|
| 407 | + ); |
|
| 408 | + } |
|
| 409 | + return $session_data; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + |
|
| 413 | + /** |
|
| 414 | + * Set session data within the TXN object |
|
| 415 | + * |
|
| 416 | + * @param EE_Session|array $session_data |
|
| 417 | + * @throws EE_Error |
|
| 418 | + * @throws InvalidArgumentException |
|
| 419 | + * @throws InvalidDataTypeException |
|
| 420 | + * @throws InvalidInterfaceException |
|
| 421 | + * @throws ReflectionException |
|
| 422 | + */ |
|
| 423 | + public function set_txn_session_data($session_data) |
|
| 424 | + { |
|
| 425 | + if ($session_data instanceof EE_Session) { |
|
| 426 | + $this->set('TXN_session_data', $session_data->get_session_data(null, true)); |
|
| 427 | + } else { |
|
| 428 | + $this->set('TXN_session_data', $session_data); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * get Transaction hash salt |
|
| 435 | + * |
|
| 436 | + * @return mixed |
|
| 437 | + * @throws EE_Error |
|
| 438 | + * @throws InvalidArgumentException |
|
| 439 | + * @throws InvalidDataTypeException |
|
| 440 | + * @throws InvalidInterfaceException |
|
| 441 | + * @throws ReflectionException |
|
| 442 | + */ |
|
| 443 | + public function hash_salt_() |
|
| 444 | + { |
|
| 445 | + return $this->get('TXN_hash_salt'); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * Returns the transaction datetime as either: |
|
| 451 | + * - unix timestamp format ($format = false, $gmt = true) |
|
| 452 | + * - formatted date string including the UTC (timezone) offset ($format = true ($gmt |
|
| 453 | + * has no affect with this option)), this also may include a timezone abbreviation if the |
|
| 454 | + * set timezone in this class differs from what the timezone is on the blog. |
|
| 455 | + * - formatted date string including the UTC (timezone) offset (default). |
|
| 456 | + * |
|
| 457 | + * @param boolean $format - whether to return a unix timestamp (default) or formatted date string |
|
| 458 | + * @param boolean $gmt - whether to return a unix timestamp with UTC offset applied (default) |
|
| 459 | + * or no UTC offset applied |
|
| 460 | + * @return string | int |
|
| 461 | + * @throws EE_Error |
|
| 462 | + * @throws InvalidArgumentException |
|
| 463 | + * @throws InvalidDataTypeException |
|
| 464 | + * @throws InvalidInterfaceException |
|
| 465 | + * @throws ReflectionException |
|
| 466 | + */ |
|
| 467 | + public function datetime($format = false, $gmt = false) |
|
| 468 | + { |
|
| 469 | + if ($format) { |
|
| 470 | + return $this->get_pretty('TXN_timestamp'); |
|
| 471 | + } |
|
| 472 | + if ($gmt) { |
|
| 473 | + return $this->get_raw('TXN_timestamp'); |
|
| 474 | + } |
|
| 475 | + return $this->get('TXN_timestamp'); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Gets registrations on this transaction |
|
| 481 | + * |
|
| 482 | + * @param array $query_params array of query parameters |
|
| 483 | + * @param boolean $get_cached TRUE to retrieve cached registrations or FALSE to pull from the db |
|
| 484 | + * @return EE_Base_Class[]|EE_Registration[] |
|
| 485 | + * @throws EE_Error |
|
| 486 | + * @throws InvalidArgumentException |
|
| 487 | + * @throws InvalidDataTypeException |
|
| 488 | + * @throws InvalidInterfaceException |
|
| 489 | + * @throws ReflectionException |
|
| 490 | + */ |
|
| 491 | + public function registrations($query_params = array(), $get_cached = false) |
|
| 492 | + { |
|
| 493 | + $query_params = (empty($query_params) || ! is_array($query_params)) |
|
| 494 | + ? array( |
|
| 495 | + 'order_by' => array( |
|
| 496 | + 'Event.EVT_name' => 'ASC', |
|
| 497 | + 'Attendee.ATT_lname' => 'ASC', |
|
| 498 | + 'Attendee.ATT_fname' => 'ASC', |
|
| 499 | + ), |
|
| 500 | + ) |
|
| 501 | + : $query_params; |
|
| 502 | + $query_params = $get_cached ? array() : $query_params; |
|
| 503 | + return $this->get_many_related('Registration', $query_params); |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
|
| 509 | + * function for getting attendees and how many registrations they each have for an event) |
|
| 510 | + * |
|
| 511 | + * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
| 512 | + * @throws EE_Error |
|
| 513 | + * @throws InvalidArgumentException |
|
| 514 | + * @throws InvalidDataTypeException |
|
| 515 | + * @throws InvalidInterfaceException |
|
| 516 | + * @throws ReflectionException |
|
| 517 | + */ |
|
| 518 | + public function attendees() |
|
| 519 | + { |
|
| 520 | + return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default |
|
| 526 | + * |
|
| 527 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 528 | + * @return EE_Base_Class[]|EE_Payment[] |
|
| 529 | + * @throws EE_Error |
|
| 530 | + * @throws InvalidArgumentException |
|
| 531 | + * @throws InvalidDataTypeException |
|
| 532 | + * @throws InvalidInterfaceException |
|
| 533 | + * @throws ReflectionException |
|
| 534 | + */ |
|
| 535 | + public function payments($query_params = array()) |
|
| 536 | + { |
|
| 537 | + return $this->get_many_related('Payment', $query_params); |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * gets only approved payments for this transaction |
|
| 543 | + * |
|
| 544 | + * @return EE_Base_Class[]|EE_Payment[] |
|
| 545 | + * @throws EE_Error |
|
| 546 | + * @throws InvalidArgumentException |
|
| 547 | + * @throws ReflectionException |
|
| 548 | + * @throws InvalidDataTypeException |
|
| 549 | + * @throws InvalidInterfaceException |
|
| 550 | + */ |
|
| 551 | + public function approved_payments() |
|
| 552 | + { |
|
| 553 | + EE_Registry::instance()->load_model('Payment'); |
|
| 554 | + return $this->get_many_related( |
|
| 555 | + 'Payment', |
|
| 556 | + array( |
|
| 557 | + array('STS_ID' => EEM_Payment::status_id_approved), |
|
| 558 | + 'order_by' => array('PAY_timestamp' => 'DESC'), |
|
| 559 | + ) |
|
| 560 | + ); |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Gets all payments which have not been approved |
|
| 566 | + * |
|
| 567 | + * @return EE_Base_Class[]|EEI_Payment[] |
|
| 568 | + * @throws EE_Error if a model is misconfigured somehow |
|
| 569 | + * @throws InvalidArgumentException |
|
| 570 | + * @throws InvalidDataTypeException |
|
| 571 | + * @throws InvalidInterfaceException |
|
| 572 | + * @throws ReflectionException |
|
| 573 | + */ |
|
| 574 | + public function pending_payments() |
|
| 575 | + { |
|
| 576 | + return $this->get_many_related( |
|
| 577 | + 'Payment', |
|
| 578 | + array( |
|
| 579 | + array( |
|
| 580 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
| 581 | + ), |
|
| 582 | + 'order_by' => array( |
|
| 583 | + 'PAY_timestamp' => 'DESC', |
|
| 584 | + ), |
|
| 585 | + ) |
|
| 586 | + ); |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * echoes $this->pretty_status() |
|
| 592 | + * |
|
| 593 | + * @param bool $show_icons |
|
| 594 | + * @throws EE_Error |
|
| 595 | + * @throws InvalidArgumentException |
|
| 596 | + * @throws InvalidDataTypeException |
|
| 597 | + * @throws InvalidInterfaceException |
|
| 598 | + * @throws ReflectionException |
|
| 599 | + */ |
|
| 600 | + public function e_pretty_status($show_icons = false) |
|
| 601 | + { |
|
| 602 | + echo $this->pretty_status($show_icons); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + |
|
| 606 | + /** |
|
| 607 | + * returns a pretty version of the status, good for displaying to users |
|
| 608 | + * |
|
| 609 | + * @param bool $show_icons |
|
| 610 | + * @return string |
|
| 611 | + * @throws EE_Error |
|
| 612 | + * @throws InvalidArgumentException |
|
| 613 | + * @throws InvalidDataTypeException |
|
| 614 | + * @throws InvalidInterfaceException |
|
| 615 | + * @throws ReflectionException |
|
| 616 | + */ |
|
| 617 | + public function pretty_status($show_icons = false) |
|
| 618 | + { |
|
| 619 | + $status = EEM_Status::instance()->localized_status( |
|
| 620 | + array($this->status_ID() => __('unknown', 'event_espresso')), |
|
| 621 | + false, |
|
| 622 | + 'sentence' |
|
| 623 | + ); |
|
| 624 | + $icon = ''; |
|
| 625 | + switch ($this->status_ID()) { |
|
| 626 | + case EEM_Transaction::complete_status_code: |
|
| 627 | + $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
|
| 628 | + break; |
|
| 629 | + case EEM_Transaction::incomplete_status_code: |
|
| 630 | + $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>' |
|
| 631 | + : ''; |
|
| 632 | + break; |
|
| 633 | + case EEM_Transaction::abandoned_status_code: |
|
| 634 | + $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : ''; |
|
| 635 | + break; |
|
| 636 | + case EEM_Transaction::failed_status_code: |
|
| 637 | + $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : ''; |
|
| 638 | + break; |
|
| 639 | + case EEM_Transaction::overpaid_status_code: |
|
| 640 | + $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
|
| 641 | + break; |
|
| 642 | + } |
|
| 643 | + return $icon . $status[ $this->status_ID() ]; |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + |
|
| 647 | + /** |
|
| 648 | + * get Transaction Status |
|
| 649 | + * |
|
| 650 | + * @return mixed |
|
| 651 | + * @throws EE_Error |
|
| 652 | + * @throws InvalidArgumentException |
|
| 653 | + * @throws InvalidDataTypeException |
|
| 654 | + * @throws InvalidInterfaceException |
|
| 655 | + * @throws ReflectionException |
|
| 656 | + */ |
|
| 657 | + public function status_ID() |
|
| 658 | + { |
|
| 659 | + return $this->get('STS_ID'); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + |
|
| 663 | + /** |
|
| 664 | + * Returns TRUE or FALSE for whether or not this transaction cost any money |
|
| 665 | + * |
|
| 666 | + * @return boolean |
|
| 667 | + * @throws EE_Error |
|
| 668 | + * @throws InvalidArgumentException |
|
| 669 | + * @throws InvalidDataTypeException |
|
| 670 | + * @throws InvalidInterfaceException |
|
| 671 | + * @throws ReflectionException |
|
| 672 | + */ |
|
| 673 | + public function is_free() |
|
| 674 | + { |
|
| 675 | + return EEH_Money::compare_floats($this->get('TXN_total'), 0, '=='); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + |
|
| 679 | + /** |
|
| 680 | + * Returns whether this transaction is complete |
|
| 681 | + * Useful in templates and other logic for deciding if we should ask for another payment... |
|
| 682 | + * |
|
| 683 | + * @return boolean |
|
| 684 | + * @throws EE_Error |
|
| 685 | + * @throws InvalidArgumentException |
|
| 686 | + * @throws InvalidDataTypeException |
|
| 687 | + * @throws InvalidInterfaceException |
|
| 688 | + * @throws ReflectionException |
|
| 689 | + */ |
|
| 690 | + public function is_completed() |
|
| 691 | + { |
|
| 692 | + return $this->status_ID() === EEM_Transaction::complete_status_code; |
|
| 693 | + } |
|
| 694 | + |
|
| 695 | + |
|
| 696 | + /** |
|
| 697 | + * Returns whether this transaction is incomplete |
|
| 698 | + * Useful in templates and other logic for deciding if we should ask for another payment... |
|
| 699 | + * |
|
| 700 | + * @return boolean |
|
| 701 | + * @throws EE_Error |
|
| 702 | + * @throws InvalidArgumentException |
|
| 703 | + * @throws InvalidDataTypeException |
|
| 704 | + * @throws InvalidInterfaceException |
|
| 705 | + * @throws ReflectionException |
|
| 706 | + */ |
|
| 707 | + public function is_incomplete() |
|
| 708 | + { |
|
| 709 | + return $this->status_ID() === EEM_Transaction::incomplete_status_code; |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * Returns whether this transaction is overpaid |
|
| 715 | + * Useful in templates and other logic for deciding if monies need to be refunded |
|
| 716 | + * |
|
| 717 | + * @return boolean |
|
| 718 | + * @throws EE_Error |
|
| 719 | + * @throws InvalidArgumentException |
|
| 720 | + * @throws InvalidDataTypeException |
|
| 721 | + * @throws InvalidInterfaceException |
|
| 722 | + * @throws ReflectionException |
|
| 723 | + */ |
|
| 724 | + public function is_overpaid() |
|
| 725 | + { |
|
| 726 | + return $this->status_ID() === EEM_Transaction::overpaid_status_code; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + |
|
| 730 | + /** |
|
| 731 | + * Returns whether this transaction was abandoned |
|
| 732 | + * meaning that the transaction/registration process was somehow interrupted and never completed |
|
| 733 | + * but that contact information exists for at least one registrant |
|
| 734 | + * |
|
| 735 | + * @return boolean |
|
| 736 | + * @throws EE_Error |
|
| 737 | + * @throws InvalidArgumentException |
|
| 738 | + * @throws InvalidDataTypeException |
|
| 739 | + * @throws InvalidInterfaceException |
|
| 740 | + * @throws ReflectionException |
|
| 741 | + */ |
|
| 742 | + public function is_abandoned() |
|
| 743 | + { |
|
| 744 | + return $this->status_ID() === EEM_Transaction::abandoned_status_code; |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + |
|
| 748 | + /** |
|
| 749 | + * Returns whether this transaction failed |
|
| 750 | + * meaning that the transaction/registration process was somehow interrupted and never completed |
|
| 751 | + * and that NO contact information exists for any registrants |
|
| 752 | + * |
|
| 753 | + * @return boolean |
|
| 754 | + * @throws EE_Error |
|
| 755 | + * @throws InvalidArgumentException |
|
| 756 | + * @throws InvalidDataTypeException |
|
| 757 | + * @throws InvalidInterfaceException |
|
| 758 | + * @throws ReflectionException |
|
| 759 | + */ |
|
| 760 | + public function failed() |
|
| 761 | + { |
|
| 762 | + return $this->status_ID() === EEM_Transaction::failed_status_code; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * This returns the url for the invoice of this transaction |
|
| 768 | + * |
|
| 769 | + * @param string $type 'html' or 'pdf' (default is pdf) |
|
| 770 | + * @return string |
|
| 771 | + * @throws EE_Error |
|
| 772 | + * @throws InvalidArgumentException |
|
| 773 | + * @throws InvalidDataTypeException |
|
| 774 | + * @throws InvalidInterfaceException |
|
| 775 | + * @throws ReflectionException |
|
| 776 | + */ |
|
| 777 | + public function invoice_url($type = 'html') |
|
| 778 | + { |
|
| 779 | + $REG = $this->primary_registration(); |
|
| 780 | + if (! $REG instanceof EE_Registration) { |
|
| 781 | + return ''; |
|
| 782 | + } |
|
| 783 | + return $REG->invoice_url($type); |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + |
|
| 787 | + /** |
|
| 788 | + * Gets the primary registration only |
|
| 789 | + * |
|
| 790 | + * @return EE_Base_Class|EE_Registration |
|
| 791 | + * @throws EE_Error |
|
| 792 | + * @throws InvalidArgumentException |
|
| 793 | + * @throws InvalidDataTypeException |
|
| 794 | + * @throws InvalidInterfaceException |
|
| 795 | + * @throws ReflectionException |
|
| 796 | + */ |
|
| 797 | + public function primary_registration() |
|
| 798 | + { |
|
| 799 | + $registrations = (array) $this->get_many_related( |
|
| 800 | + 'Registration', |
|
| 801 | + array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
|
| 802 | + ); |
|
| 803 | + foreach ($registrations as $registration) { |
|
| 804 | + // valid registration that is NOT cancelled or declined ? |
|
| 805 | + if ($registration instanceof EE_Registration |
|
| 806 | + && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
|
| 807 | + ) { |
|
| 808 | + return $registration; |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + // nothing valid found, so just return first thing from array of results |
|
| 812 | + return reset($registrations); |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + |
|
| 816 | + /** |
|
| 817 | + * Gets the URL for viewing the receipt |
|
| 818 | + * |
|
| 819 | + * @param string $type 'pdf' or 'html' (default is 'html') |
|
| 820 | + * @return string |
|
| 821 | + * @throws EE_Error |
|
| 822 | + * @throws InvalidArgumentException |
|
| 823 | + * @throws InvalidDataTypeException |
|
| 824 | + * @throws InvalidInterfaceException |
|
| 825 | + * @throws ReflectionException |
|
| 826 | + */ |
|
| 827 | + public function receipt_url($type = 'html') |
|
| 828 | + { |
|
| 829 | + $REG = $this->primary_registration(); |
|
| 830 | + if (! $REG instanceof EE_Registration) { |
|
| 831 | + return ''; |
|
| 832 | + } |
|
| 833 | + return $REG->receipt_url($type); |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + |
|
| 837 | + /** |
|
| 838 | + * Gets the URL of the thank you page with this registration REG_url_link added as |
|
| 839 | + * a query parameter |
|
| 840 | + * |
|
| 841 | + * @return string |
|
| 842 | + * @throws EE_Error |
|
| 843 | + * @throws InvalidArgumentException |
|
| 844 | + * @throws InvalidDataTypeException |
|
| 845 | + * @throws InvalidInterfaceException |
|
| 846 | + * @throws ReflectionException |
|
| 847 | + */ |
|
| 848 | + public function payment_overview_url() |
|
| 849 | + { |
|
| 850 | + $primary_registration = $this->primary_registration(); |
|
| 851 | + return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false; |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + |
|
| 855 | + /** |
|
| 856 | + * @return string |
|
| 857 | + * @throws EE_Error |
|
| 858 | + * @throws InvalidArgumentException |
|
| 859 | + * @throws InvalidDataTypeException |
|
| 860 | + * @throws InvalidInterfaceException |
|
| 861 | + * @throws ReflectionException |
|
| 862 | + */ |
|
| 863 | + public function gateway_response_on_transaction() |
|
| 864 | + { |
|
| 865 | + $payment = $this->get_first_related('Payment'); |
|
| 866 | + return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * Get the status object of this object |
|
| 872 | + * |
|
| 873 | + * @return EE_Base_Class|EE_Status |
|
| 874 | + * @throws EE_Error |
|
| 875 | + * @throws InvalidArgumentException |
|
| 876 | + * @throws InvalidDataTypeException |
|
| 877 | + * @throws InvalidInterfaceException |
|
| 878 | + * @throws ReflectionException |
|
| 879 | + */ |
|
| 880 | + public function status_obj() |
|
| 881 | + { |
|
| 882 | + return $this->get_first_related('Status'); |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + |
|
| 886 | + /** |
|
| 887 | + * Gets all the extra meta info on this payment |
|
| 888 | + * |
|
| 889 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 890 | + * @return EE_Base_Class[]|EE_Extra_Meta |
|
| 891 | + * @throws EE_Error |
|
| 892 | + * @throws InvalidArgumentException |
|
| 893 | + * @throws InvalidDataTypeException |
|
| 894 | + * @throws InvalidInterfaceException |
|
| 895 | + * @throws ReflectionException |
|
| 896 | + */ |
|
| 897 | + public function extra_meta($query_params = array()) |
|
| 898 | + { |
|
| 899 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + |
|
| 903 | + /** |
|
| 904 | + * Wrapper for _add_relation_to |
|
| 905 | + * |
|
| 906 | + * @param EE_Registration $registration |
|
| 907 | + * @return EE_Base_Class the relation was added to |
|
| 908 | + * @throws EE_Error |
|
| 909 | + * @throws InvalidArgumentException |
|
| 910 | + * @throws InvalidDataTypeException |
|
| 911 | + * @throws InvalidInterfaceException |
|
| 912 | + * @throws ReflectionException |
|
| 913 | + */ |
|
| 914 | + public function add_registration(EE_Registration $registration) |
|
| 915 | + { |
|
| 916 | + return $this->_add_relation_to($registration, 'Registration'); |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + |
|
| 920 | + /** |
|
| 921 | + * Removes the given registration from being related (even before saving this transaction). |
|
| 922 | + * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations |
|
| 923 | + * |
|
| 924 | + * @param int $registration_or_id |
|
| 925 | + * @return EE_Base_Class that was removed from being related |
|
| 926 | + * @throws EE_Error |
|
| 927 | + * @throws InvalidArgumentException |
|
| 928 | + * @throws InvalidDataTypeException |
|
| 929 | + * @throws InvalidInterfaceException |
|
| 930 | + * @throws ReflectionException |
|
| 931 | + */ |
|
| 932 | + public function remove_registration_with_id($registration_or_id) |
|
| 933 | + { |
|
| 934 | + return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + |
|
| 938 | + /** |
|
| 939 | + * Gets all the line items which are for ACTUAL items |
|
| 940 | + * |
|
| 941 | + * @return EE_Line_Item[] |
|
| 942 | + * @throws EE_Error |
|
| 943 | + * @throws InvalidArgumentException |
|
| 944 | + * @throws InvalidDataTypeException |
|
| 945 | + * @throws InvalidInterfaceException |
|
| 946 | + * @throws ReflectionException |
|
| 947 | + */ |
|
| 948 | + public function items_purchased() |
|
| 949 | + { |
|
| 950 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + |
|
| 954 | + /** |
|
| 955 | + * Wrapper for _add_relation_to |
|
| 956 | + * |
|
| 957 | + * @param EE_Line_Item $line_item |
|
| 958 | + * @return EE_Base_Class the relation was added to |
|
| 959 | + * @throws EE_Error |
|
| 960 | + * @throws InvalidArgumentException |
|
| 961 | + * @throws InvalidDataTypeException |
|
| 962 | + * @throws InvalidInterfaceException |
|
| 963 | + * @throws ReflectionException |
|
| 964 | + */ |
|
| 965 | + public function add_line_item(EE_Line_Item $line_item) |
|
| 966 | + { |
|
| 967 | + return $this->_add_relation_to($line_item, 'Line_Item'); |
|
| 968 | + } |
|
| 969 | + |
|
| 970 | + |
|
| 971 | + /** |
|
| 972 | + * Gets ALL the line items related to this transaction (unstructured) |
|
| 973 | + * |
|
| 974 | + * @param array $query_params |
|
| 975 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
| 976 | + * @throws EE_Error |
|
| 977 | + * @throws InvalidArgumentException |
|
| 978 | + * @throws InvalidDataTypeException |
|
| 979 | + * @throws InvalidInterfaceException |
|
| 980 | + * @throws ReflectionException |
|
| 981 | + */ |
|
| 982 | + public function line_items($query_params = array()) |
|
| 983 | + { |
|
| 984 | + return $this->get_many_related('Line_Item', $query_params); |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + |
|
| 988 | + /** |
|
| 989 | + * Gets all the line items which are taxes on the total |
|
| 990 | + * |
|
| 991 | + * @return EE_Line_Item[] |
|
| 992 | + * @throws EE_Error |
|
| 993 | + * @throws InvalidArgumentException |
|
| 994 | + * @throws InvalidDataTypeException |
|
| 995 | + * @throws InvalidInterfaceException |
|
| 996 | + * @throws ReflectionException |
|
| 997 | + */ |
|
| 998 | + public function tax_items() |
|
| 999 | + { |
|
| 1000 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + |
|
| 1004 | + /** |
|
| 1005 | + * Gets the total line item (which is a parent of all other related line items, |
|
| 1006 | + * meaning it takes them all into account on its total) |
|
| 1007 | + * |
|
| 1008 | + * @param bool $create_if_not_found |
|
| 1009 | + * @return \EE_Line_Item |
|
| 1010 | + * @throws EE_Error |
|
| 1011 | + * @throws InvalidArgumentException |
|
| 1012 | + * @throws InvalidDataTypeException |
|
| 1013 | + * @throws InvalidInterfaceException |
|
| 1014 | + * @throws ReflectionException |
|
| 1015 | + */ |
|
| 1016 | + public function total_line_item($create_if_not_found = true) |
|
| 1017 | + { |
|
| 1018 | + $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
| 1019 | + if (! $item && $create_if_not_found) { |
|
| 1020 | + $item = EEH_Line_Item::create_total_line_item($this); |
|
| 1021 | + } |
|
| 1022 | + return $item; |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + |
|
| 1026 | + /** |
|
| 1027 | + * Returns the total amount of tax on this transaction |
|
| 1028 | + * (assumes there's only one tax subtotal line item) |
|
| 1029 | + * |
|
| 1030 | + * @return float |
|
| 1031 | + * @throws EE_Error |
|
| 1032 | + * @throws InvalidArgumentException |
|
| 1033 | + * @throws InvalidDataTypeException |
|
| 1034 | + * @throws InvalidInterfaceException |
|
| 1035 | + * @throws ReflectionException |
|
| 1036 | + */ |
|
| 1037 | + public function tax_total() |
|
| 1038 | + { |
|
| 1039 | + $tax_line_item = $this->tax_total_line_item(); |
|
| 1040 | + if ($tax_line_item) { |
|
| 1041 | + return (float) $tax_line_item->total(); |
|
| 1042 | + } |
|
| 1043 | + return (float) 0; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + |
|
| 1047 | + /** |
|
| 1048 | + * Gets the tax subtotal line item (assumes there's only one) |
|
| 1049 | + * |
|
| 1050 | + * @return EE_Line_Item |
|
| 1051 | + * @throws EE_Error |
|
| 1052 | + * @throws InvalidArgumentException |
|
| 1053 | + * @throws InvalidDataTypeException |
|
| 1054 | + * @throws InvalidInterfaceException |
|
| 1055 | + * @throws ReflectionException |
|
| 1056 | + */ |
|
| 1057 | + public function tax_total_line_item() |
|
| 1058 | + { |
|
| 1059 | + return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
| 1060 | + } |
|
| 1061 | + |
|
| 1062 | + |
|
| 1063 | + /** |
|
| 1064 | + * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee. |
|
| 1065 | + * |
|
| 1066 | + * @return EE_Form_Section_Proper |
|
| 1067 | + * @throws EE_Error |
|
| 1068 | + * @throws InvalidArgumentException |
|
| 1069 | + * @throws InvalidDataTypeException |
|
| 1070 | + * @throws InvalidInterfaceException |
|
| 1071 | + * @throws ReflectionException |
|
| 1072 | + */ |
|
| 1073 | + public function billing_info() |
|
| 1074 | + { |
|
| 1075 | + $payment_method = $this->payment_method(); |
|
| 1076 | + if (! $payment_method) { |
|
| 1077 | + EE_Error::add_error( |
|
| 1078 | + __( |
|
| 1079 | + 'Could not find billing info for transaction because no gateway has been used for it yet', |
|
| 1080 | + 'event_espresso' |
|
| 1081 | + ), |
|
| 1082 | + __FILE__, |
|
| 1083 | + __FUNCTION__, |
|
| 1084 | + __LINE__ |
|
| 1085 | + ); |
|
| 1086 | + return null; |
|
| 1087 | + } |
|
| 1088 | + $primary_reg = $this->primary_registration(); |
|
| 1089 | + if (! $primary_reg) { |
|
| 1090 | + EE_Error::add_error( |
|
| 1091 | + __( |
|
| 1092 | + 'Cannot get billing info for gateway %s on transaction because no primary registration exists', |
|
| 1093 | + 'event_espresso' |
|
| 1094 | + ), |
|
| 1095 | + __FILE__, |
|
| 1096 | + __FUNCTION__, |
|
| 1097 | + __LINE__ |
|
| 1098 | + ); |
|
| 1099 | + return null; |
|
| 1100 | + } |
|
| 1101 | + $attendee = $primary_reg->attendee(); |
|
| 1102 | + if (! $attendee) { |
|
| 1103 | + EE_Error::add_error( |
|
| 1104 | + __( |
|
| 1105 | + 'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists', |
|
| 1106 | + 'event_espresso' |
|
| 1107 | + ), |
|
| 1108 | + __FILE__, |
|
| 1109 | + __FUNCTION__, |
|
| 1110 | + __LINE__ |
|
| 1111 | + ); |
|
| 1112 | + return null; |
|
| 1113 | + } |
|
| 1114 | + return $attendee->billing_info_for_payment_method($payment_method); |
|
| 1115 | + } |
|
| 1116 | + |
|
| 1117 | + |
|
| 1118 | + /** |
|
| 1119 | + * Gets PMD_ID |
|
| 1120 | + * |
|
| 1121 | + * @return int |
|
| 1122 | + * @throws EE_Error |
|
| 1123 | + * @throws InvalidArgumentException |
|
| 1124 | + * @throws InvalidDataTypeException |
|
| 1125 | + * @throws InvalidInterfaceException |
|
| 1126 | + * @throws ReflectionException |
|
| 1127 | + */ |
|
| 1128 | + public function payment_method_ID() |
|
| 1129 | + { |
|
| 1130 | + return $this->get('PMD_ID'); |
|
| 1131 | + } |
|
| 1132 | + |
|
| 1133 | + |
|
| 1134 | + /** |
|
| 1135 | + * Sets PMD_ID |
|
| 1136 | + * |
|
| 1137 | + * @param int $PMD_ID |
|
| 1138 | + * @throws EE_Error |
|
| 1139 | + * @throws InvalidArgumentException |
|
| 1140 | + * @throws InvalidDataTypeException |
|
| 1141 | + * @throws InvalidInterfaceException |
|
| 1142 | + * @throws ReflectionException |
|
| 1143 | + */ |
|
| 1144 | + public function set_payment_method_ID($PMD_ID) |
|
| 1145 | + { |
|
| 1146 | + $this->set('PMD_ID', $PMD_ID); |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * Gets the last-used payment method on this transaction |
|
| 1152 | + * (we COULD just use the last-made payment, but some payment methods, namely |
|
| 1153 | + * offline ones, dont' create payments) |
|
| 1154 | + * |
|
| 1155 | + * @return EE_Payment_Method |
|
| 1156 | + * @throws EE_Error |
|
| 1157 | + * @throws InvalidArgumentException |
|
| 1158 | + * @throws InvalidDataTypeException |
|
| 1159 | + * @throws InvalidInterfaceException |
|
| 1160 | + * @throws ReflectionException |
|
| 1161 | + */ |
|
| 1162 | + public function payment_method() |
|
| 1163 | + { |
|
| 1164 | + $pm = $this->get_first_related('Payment_Method'); |
|
| 1165 | + if ($pm instanceof EE_Payment_Method) { |
|
| 1166 | + return $pm; |
|
| 1167 | + } |
|
| 1168 | + $last_payment = $this->last_payment(); |
|
| 1169 | + if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
| 1170 | + return $last_payment->payment_method(); |
|
| 1171 | + } |
|
| 1172 | + return null; |
|
| 1173 | + } |
|
| 1174 | + |
|
| 1175 | + |
|
| 1176 | + /** |
|
| 1177 | + * Gets the last payment made |
|
| 1178 | + * |
|
| 1179 | + * @return EE_Base_Class|EE_Payment |
|
| 1180 | + * @throws EE_Error |
|
| 1181 | + * @throws InvalidArgumentException |
|
| 1182 | + * @throws InvalidDataTypeException |
|
| 1183 | + * @throws InvalidInterfaceException |
|
| 1184 | + * @throws ReflectionException |
|
| 1185 | + */ |
|
| 1186 | + public function last_payment() |
|
| 1187 | + { |
|
| 1188 | + return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
| 1189 | + } |
|
| 1190 | + |
|
| 1191 | + |
|
| 1192 | + /** |
|
| 1193 | + * Gets all the line items which are unrelated to tickets on this transaction |
|
| 1194 | + * |
|
| 1195 | + * @return EE_Line_Item[] |
|
| 1196 | + * @throws EE_Error |
|
| 1197 | + * @throws InvalidArgumentException |
|
| 1198 | + * @throws InvalidDataTypeException |
|
| 1199 | + * @throws InvalidInterfaceException |
|
| 1200 | + * @throws ReflectionException |
|
| 1201 | + */ |
|
| 1202 | + public function non_ticket_line_items() |
|
| 1203 | + { |
|
| 1204 | + return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
| 1205 | + } |
|
| 1206 | + |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * possibly toggles TXN status |
|
| 1210 | + * |
|
| 1211 | + * @param boolean $update whether to save the TXN |
|
| 1212 | + * @return bool whether the TXN was saved |
|
| 1213 | + * @throws EE_Error |
|
| 1214 | + * @throws InvalidArgumentException |
|
| 1215 | + * @throws InvalidDataTypeException |
|
| 1216 | + * @throws InvalidInterfaceException |
|
| 1217 | + * @throws ReflectionException |
|
| 1218 | + * @throws RuntimeException |
|
| 1219 | + */ |
|
| 1220 | + public function update_status_based_on_total_paid($update = true) |
|
| 1221 | + { |
|
| 1222 | + // set transaction status based on comparison of TXN_paid vs TXN_total |
|
| 1223 | + if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) { |
|
| 1224 | + $new_txn_status = EEM_Transaction::overpaid_status_code; |
|
| 1225 | + } elseif (EEH_Money::compare_floats($this->paid(), $this->total())) { |
|
| 1226 | + $new_txn_status = EEM_Transaction::complete_status_code; |
|
| 1227 | + } elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) { |
|
| 1228 | + $new_txn_status = EEM_Transaction::incomplete_status_code; |
|
| 1229 | + } else { |
|
| 1230 | + throw new RuntimeException( |
|
| 1231 | + __('The total paid calculation for this transaction is inaccurate.', 'event_espresso') |
|
| 1232 | + ); |
|
| 1233 | + } |
|
| 1234 | + if ($new_txn_status !== $this->status_ID()) { |
|
| 1235 | + $this->set_status($new_txn_status); |
|
| 1236 | + if ($update) { |
|
| 1237 | + return $this->save() ? true : false; |
|
| 1238 | + } |
|
| 1239 | + } |
|
| 1240 | + return false; |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + |
|
| 1244 | + /** |
|
| 1245 | + * Updates the transaction's status and total_paid based on all the payments |
|
| 1246 | + * that apply to it |
|
| 1247 | + * |
|
| 1248 | + * @deprecated |
|
| 1249 | + * @return array|bool |
|
| 1250 | + * @throws EE_Error |
|
| 1251 | + * @throws InvalidArgumentException |
|
| 1252 | + * @throws ReflectionException |
|
| 1253 | + * @throws InvalidDataTypeException |
|
| 1254 | + * @throws InvalidInterfaceException |
|
| 1255 | + */ |
|
| 1256 | + public function update_based_on_payments() |
|
| 1257 | + { |
|
| 1258 | + EE_Error::doing_it_wrong( |
|
| 1259 | + __CLASS__ . '::' . __FUNCTION__, |
|
| 1260 | + sprintf( |
|
| 1261 | + __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
| 1262 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
| 1263 | + ), |
|
| 1264 | + '4.6.0' |
|
| 1265 | + ); |
|
| 1266 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
| 1267 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
| 1268 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + |
|
| 1272 | + /** |
|
| 1273 | + * @return string |
|
| 1274 | + */ |
|
| 1275 | + public function old_txn_status() |
|
| 1276 | + { |
|
| 1277 | + return $this->_old_txn_status; |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + |
|
| 1281 | + /** |
|
| 1282 | + * @param string $old_txn_status |
|
| 1283 | + */ |
|
| 1284 | + public function set_old_txn_status($old_txn_status) |
|
| 1285 | + { |
|
| 1286 | + // only set the first time |
|
| 1287 | + if ($this->_old_txn_status === null) { |
|
| 1288 | + $this->_old_txn_status = $old_txn_status; |
|
| 1289 | + } |
|
| 1290 | + } |
|
| 1291 | + |
|
| 1292 | + |
|
| 1293 | + /** |
|
| 1294 | + * reg_status_updated |
|
| 1295 | + * |
|
| 1296 | + * @return bool |
|
| 1297 | + * @throws EE_Error |
|
| 1298 | + * @throws InvalidArgumentException |
|
| 1299 | + * @throws InvalidDataTypeException |
|
| 1300 | + * @throws InvalidInterfaceException |
|
| 1301 | + * @throws ReflectionException |
|
| 1302 | + */ |
|
| 1303 | + public function txn_status_updated() |
|
| 1304 | + { |
|
| 1305 | + return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null; |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + |
|
| 1309 | + /** |
|
| 1310 | + * _reg_steps_completed |
|
| 1311 | + * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed, |
|
| 1312 | + * if a $reg_step_slug is provided, then this step will be skipped when testing for completion |
|
| 1313 | + * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion |
|
| 1314 | + * |
|
| 1315 | + * @param string $reg_step_slug |
|
| 1316 | + * @param bool $check_all |
|
| 1317 | + * @return bool|int |
|
| 1318 | + * @throws EE_Error |
|
| 1319 | + * @throws InvalidArgumentException |
|
| 1320 | + * @throws InvalidDataTypeException |
|
| 1321 | + * @throws InvalidInterfaceException |
|
| 1322 | + * @throws ReflectionException |
|
| 1323 | + */ |
|
| 1324 | + private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
|
| 1325 | + { |
|
| 1326 | + $reg_steps = $this->reg_steps(); |
|
| 1327 | + if (! is_array($reg_steps) || empty($reg_steps)) { |
|
| 1328 | + return false; |
|
| 1329 | + } |
|
| 1330 | + // loop thru reg steps array) |
|
| 1331 | + foreach ($reg_steps as $slug => $reg_step_completed) { |
|
| 1332 | + // if NOT checking ALL steps (only checking one step) |
|
| 1333 | + if (! $check_all) { |
|
| 1334 | + // and this is the one |
|
| 1335 | + if ($slug === $reg_step_slug) { |
|
| 1336 | + return $reg_step_completed; |
|
| 1337 | + } |
|
| 1338 | + // skip to next reg step in loop |
|
| 1339 | + continue; |
|
| 1340 | + } |
|
| 1341 | + // $check_all must be true, else we would never have gotten to this point |
|
| 1342 | + if ($slug === $reg_step_slug) { |
|
| 1343 | + // if we reach this point, then we are testing either: |
|
| 1344 | + // all_reg_steps_completed_except() or |
|
| 1345 | + // all_reg_steps_completed_except_final_step(), |
|
| 1346 | + // and since this is the reg step EXCEPTION being tested |
|
| 1347 | + // we want to return true (yes true) if this reg step is NOT completed |
|
| 1348 | + // ie: "is everything completed except the final step?" |
|
| 1349 | + // "that is correct... the final step is not completed, but all others are." |
|
| 1350 | + return $reg_step_completed !== true; |
|
| 1351 | + } |
|
| 1352 | + if ($reg_step_completed !== true) { |
|
| 1353 | + // if any reg step is NOT completed, then ALL steps are not completed |
|
| 1354 | + return false; |
|
| 1355 | + } |
|
| 1356 | + } |
|
| 1357 | + return true; |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + |
|
| 1361 | + /** |
|
| 1362 | + * all_reg_steps_completed |
|
| 1363 | + * returns: |
|
| 1364 | + * true if ALL reg steps have been marked as completed |
|
| 1365 | + * or false if any step is not completed |
|
| 1366 | + * |
|
| 1367 | + * @return bool |
|
| 1368 | + * @throws EE_Error |
|
| 1369 | + * @throws InvalidArgumentException |
|
| 1370 | + * @throws InvalidDataTypeException |
|
| 1371 | + * @throws InvalidInterfaceException |
|
| 1372 | + * @throws ReflectionException |
|
| 1373 | + */ |
|
| 1374 | + public function all_reg_steps_completed() |
|
| 1375 | + { |
|
| 1376 | + return $this->_reg_steps_completed(); |
|
| 1377 | + } |
|
| 1378 | + |
|
| 1379 | + |
|
| 1380 | + /** |
|
| 1381 | + * all_reg_steps_completed_except |
|
| 1382 | + * returns: |
|
| 1383 | + * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
|
| 1384 | + * or false if any other step is not completed |
|
| 1385 | + * or false if ALL steps are completed including the exception you are testing !!! |
|
| 1386 | + * |
|
| 1387 | + * @param string $exception |
|
| 1388 | + * @return bool |
|
| 1389 | + * @throws EE_Error |
|
| 1390 | + * @throws InvalidArgumentException |
|
| 1391 | + * @throws InvalidDataTypeException |
|
| 1392 | + * @throws InvalidInterfaceException |
|
| 1393 | + * @throws ReflectionException |
|
| 1394 | + */ |
|
| 1395 | + public function all_reg_steps_completed_except($exception = '') |
|
| 1396 | + { |
|
| 1397 | + return $this->_reg_steps_completed($exception); |
|
| 1398 | + } |
|
| 1399 | + |
|
| 1400 | + |
|
| 1401 | + /** |
|
| 1402 | + * all_reg_steps_completed_except |
|
| 1403 | + * returns: |
|
| 1404 | + * true if ALL reg steps, except the final step, have been marked as completed |
|
| 1405 | + * or false if any step is not completed |
|
| 1406 | + * or false if ALL steps are completed including the final step !!! |
|
| 1407 | + * |
|
| 1408 | + * @return bool |
|
| 1409 | + * @throws EE_Error |
|
| 1410 | + * @throws InvalidArgumentException |
|
| 1411 | + * @throws InvalidDataTypeException |
|
| 1412 | + * @throws InvalidInterfaceException |
|
| 1413 | + * @throws ReflectionException |
|
| 1414 | + */ |
|
| 1415 | + public function all_reg_steps_completed_except_final_step() |
|
| 1416 | + { |
|
| 1417 | + return $this->_reg_steps_completed('finalize_registration'); |
|
| 1418 | + } |
|
| 1419 | + |
|
| 1420 | + |
|
| 1421 | + /** |
|
| 1422 | + * reg_step_completed |
|
| 1423 | + * returns: |
|
| 1424 | + * true if a specific reg step has been marked as completed |
|
| 1425 | + * a Unix timestamp if it has been initialized but not yet completed, |
|
| 1426 | + * or false if it has not yet been initialized |
|
| 1427 | + * |
|
| 1428 | + * @param string $reg_step_slug |
|
| 1429 | + * @return bool|int |
|
| 1430 | + * @throws EE_Error |
|
| 1431 | + * @throws InvalidArgumentException |
|
| 1432 | + * @throws InvalidDataTypeException |
|
| 1433 | + * @throws InvalidInterfaceException |
|
| 1434 | + * @throws ReflectionException |
|
| 1435 | + */ |
|
| 1436 | + public function reg_step_completed($reg_step_slug) |
|
| 1437 | + { |
|
| 1438 | + return $this->_reg_steps_completed($reg_step_slug, false); |
|
| 1439 | + } |
|
| 1440 | + |
|
| 1441 | + |
|
| 1442 | + /** |
|
| 1443 | + * completed_final_reg_step |
|
| 1444 | + * returns: |
|
| 1445 | + * true if the finalize_registration reg step has been marked as completed |
|
| 1446 | + * a Unix timestamp if it has been initialized but not yet completed, |
|
| 1447 | + * or false if it has not yet been initialized |
|
| 1448 | + * |
|
| 1449 | + * @return bool|int |
|
| 1450 | + * @throws EE_Error |
|
| 1451 | + * @throws InvalidArgumentException |
|
| 1452 | + * @throws InvalidDataTypeException |
|
| 1453 | + * @throws InvalidInterfaceException |
|
| 1454 | + * @throws ReflectionException |
|
| 1455 | + */ |
|
| 1456 | + public function final_reg_step_completed() |
|
| 1457 | + { |
|
| 1458 | + return $this->_reg_steps_completed('finalize_registration', false); |
|
| 1459 | + } |
|
| 1460 | + |
|
| 1461 | + |
|
| 1462 | + /** |
|
| 1463 | + * set_reg_step_initiated |
|
| 1464 | + * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
|
| 1465 | + * |
|
| 1466 | + * @param string $reg_step_slug |
|
| 1467 | + * @return boolean |
|
| 1468 | + * @throws EE_Error |
|
| 1469 | + * @throws InvalidArgumentException |
|
| 1470 | + * @throws InvalidDataTypeException |
|
| 1471 | + * @throws InvalidInterfaceException |
|
| 1472 | + * @throws ReflectionException |
|
| 1473 | + */ |
|
| 1474 | + public function set_reg_step_initiated($reg_step_slug) |
|
| 1475 | + { |
|
| 1476 | + return $this->_set_reg_step_completed_status($reg_step_slug, time()); |
|
| 1477 | + } |
|
| 1478 | + |
|
| 1479 | + |
|
| 1480 | + /** |
|
| 1481 | + * set_reg_step_completed |
|
| 1482 | + * given a valid TXN_reg_step, this sets the step as completed |
|
| 1483 | + * |
|
| 1484 | + * @param string $reg_step_slug |
|
| 1485 | + * @return boolean |
|
| 1486 | + * @throws EE_Error |
|
| 1487 | + * @throws InvalidArgumentException |
|
| 1488 | + * @throws InvalidDataTypeException |
|
| 1489 | + * @throws InvalidInterfaceException |
|
| 1490 | + * @throws ReflectionException |
|
| 1491 | + */ |
|
| 1492 | + public function set_reg_step_completed($reg_step_slug) |
|
| 1493 | + { |
|
| 1494 | + return $this->_set_reg_step_completed_status($reg_step_slug, true); |
|
| 1495 | + } |
|
| 1496 | + |
|
| 1497 | + |
|
| 1498 | + /** |
|
| 1499 | + * set_reg_step_completed |
|
| 1500 | + * given a valid TXN_reg_step slug, this sets the step as NOT completed |
|
| 1501 | + * |
|
| 1502 | + * @param string $reg_step_slug |
|
| 1503 | + * @return boolean |
|
| 1504 | + * @throws EE_Error |
|
| 1505 | + * @throws InvalidArgumentException |
|
| 1506 | + * @throws InvalidDataTypeException |
|
| 1507 | + * @throws InvalidInterfaceException |
|
| 1508 | + * @throws ReflectionException |
|
| 1509 | + */ |
|
| 1510 | + public function set_reg_step_not_completed($reg_step_slug) |
|
| 1511 | + { |
|
| 1512 | + return $this->_set_reg_step_completed_status($reg_step_slug, false); |
|
| 1513 | + } |
|
| 1514 | + |
|
| 1515 | + |
|
| 1516 | + /** |
|
| 1517 | + * set_reg_step_completed |
|
| 1518 | + * given a valid reg step slug, this sets the TXN_reg_step completed status which is either: |
|
| 1519 | + * |
|
| 1520 | + * @param string $reg_step_slug |
|
| 1521 | + * @param boolean|int $status |
|
| 1522 | + * @return boolean |
|
| 1523 | + * @throws EE_Error |
|
| 1524 | + * @throws InvalidArgumentException |
|
| 1525 | + * @throws InvalidDataTypeException |
|
| 1526 | + * @throws InvalidInterfaceException |
|
| 1527 | + * @throws ReflectionException |
|
| 1528 | + */ |
|
| 1529 | + private function _set_reg_step_completed_status($reg_step_slug, $status) |
|
| 1530 | + { |
|
| 1531 | + // validate status |
|
| 1532 | + $status = is_bool($status) || is_int($status) ? $status : false; |
|
| 1533 | + // get reg steps array |
|
| 1534 | + $txn_reg_steps = $this->reg_steps(); |
|
| 1535 | + // if reg step does NOT exist |
|
| 1536 | + if (! isset($txn_reg_steps[ $reg_step_slug ])) { |
|
| 1537 | + return false; |
|
| 1538 | + } |
|
| 1539 | + // if we're trying to complete a step that is already completed |
|
| 1540 | + if ($txn_reg_steps[ $reg_step_slug ] === true) { |
|
| 1541 | + return true; |
|
| 1542 | + } |
|
| 1543 | + // if we're trying to complete a step that hasn't even started |
|
| 1544 | + if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) { |
|
| 1545 | + return false; |
|
| 1546 | + } |
|
| 1547 | + // if current status value matches the incoming value (no change) |
|
| 1548 | + // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
|
| 1549 | + if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) { |
|
| 1550 | + // this will happen in cases where multiple AJAX requests occur during the same step |
|
| 1551 | + return true; |
|
| 1552 | + } |
|
| 1553 | + // if we're trying to set a start time, but it has already been set... |
|
| 1554 | + if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) { |
|
| 1555 | + // skip the update below, but don't return FALSE so that errors won't be displayed |
|
| 1556 | + return true; |
|
| 1557 | + } |
|
| 1558 | + // update completed status |
|
| 1559 | + $txn_reg_steps[ $reg_step_slug ] = $status; |
|
| 1560 | + $this->set_reg_steps($txn_reg_steps); |
|
| 1561 | + $this->save(); |
|
| 1562 | + return true; |
|
| 1563 | + } |
|
| 1564 | + |
|
| 1565 | + |
|
| 1566 | + /** |
|
| 1567 | + * remove_reg_step |
|
| 1568 | + * given a valid TXN_reg_step slug, this will remove (unset) |
|
| 1569 | + * the reg step from the TXN reg step array |
|
| 1570 | + * |
|
| 1571 | + * @param string $reg_step_slug |
|
| 1572 | + * @return void |
|
| 1573 | + * @throws EE_Error |
|
| 1574 | + * @throws InvalidArgumentException |
|
| 1575 | + * @throws InvalidDataTypeException |
|
| 1576 | + * @throws InvalidInterfaceException |
|
| 1577 | + * @throws ReflectionException |
|
| 1578 | + */ |
|
| 1579 | + public function remove_reg_step($reg_step_slug) |
|
| 1580 | + { |
|
| 1581 | + // get reg steps array |
|
| 1582 | + $txn_reg_steps = $this->reg_steps(); |
|
| 1583 | + unset($txn_reg_steps[ $reg_step_slug ]); |
|
| 1584 | + $this->set_reg_steps($txn_reg_steps); |
|
| 1585 | + } |
|
| 1586 | + |
|
| 1587 | + |
|
| 1588 | + /** |
|
| 1589 | + * toggle_failed_transaction_status |
|
| 1590 | + * upgrades a TXNs status from failed to abandoned, |
|
| 1591 | + * meaning that contact information has been captured for at least one registrant |
|
| 1592 | + * |
|
| 1593 | + * @param bool $save |
|
| 1594 | + * @return bool |
|
| 1595 | + * @throws EE_Error |
|
| 1596 | + * @throws InvalidArgumentException |
|
| 1597 | + * @throws InvalidDataTypeException |
|
| 1598 | + * @throws InvalidInterfaceException |
|
| 1599 | + * @throws ReflectionException |
|
| 1600 | + */ |
|
| 1601 | + public function toggle_failed_transaction_status($save = true) |
|
| 1602 | + { |
|
| 1603 | + // if TXN status is still set as "failed"... |
|
| 1604 | + if ($this->status_ID() === EEM_Transaction::failed_status_code) { |
|
| 1605 | + $this->set_status(EEM_Transaction::abandoned_status_code); |
|
| 1606 | + if ($save) { |
|
| 1607 | + $this->save(); |
|
| 1608 | + } |
|
| 1609 | + return true; |
|
| 1610 | + } |
|
| 1611 | + return false; |
|
| 1612 | + } |
|
| 1613 | + |
|
| 1614 | + |
|
| 1615 | + /** |
|
| 1616 | + * toggle_abandoned_transaction_status |
|
| 1617 | + * upgrades a TXNs status from failed or abandoned to incomplete |
|
| 1618 | + * |
|
| 1619 | + * @return bool |
|
| 1620 | + * @throws EE_Error |
|
| 1621 | + * @throws InvalidArgumentException |
|
| 1622 | + * @throws InvalidDataTypeException |
|
| 1623 | + * @throws InvalidInterfaceException |
|
| 1624 | + * @throws ReflectionException |
|
| 1625 | + */ |
|
| 1626 | + public function toggle_abandoned_transaction_status() |
|
| 1627 | + { |
|
| 1628 | + // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"... |
|
| 1629 | + $txn_status = $this->status_ID(); |
|
| 1630 | + if ($txn_status === EEM_Transaction::failed_status_code |
|
| 1631 | + || $txn_status === EEM_Transaction::abandoned_status_code |
|
| 1632 | + ) { |
|
| 1633 | + // if a contact record for the primary registrant has been created |
|
| 1634 | + if ($this->primary_registration() instanceof EE_Registration |
|
| 1635 | + && $this->primary_registration()->attendee() instanceof EE_Attendee |
|
| 1636 | + ) { |
|
| 1637 | + $this->set_status(EEM_Transaction::incomplete_status_code); |
|
| 1638 | + } else { |
|
| 1639 | + // no contact record? yer abandoned! |
|
| 1640 | + $this->set_status(EEM_Transaction::abandoned_status_code); |
|
| 1641 | + } |
|
| 1642 | + return true; |
|
| 1643 | + } |
|
| 1644 | + return false; |
|
| 1645 | + } |
|
| 1646 | + |
|
| 1647 | + |
|
| 1648 | + /** |
|
| 1649 | + * checks if an Abandoned TXN has any related payments, and if so, |
|
| 1650 | + * updates the TXN status based on the amount paid |
|
| 1651 | + * |
|
| 1652 | + * @throws EE_Error |
|
| 1653 | + * @throws InvalidDataTypeException |
|
| 1654 | + * @throws InvalidInterfaceException |
|
| 1655 | + * @throws InvalidArgumentException |
|
| 1656 | + * @throws RuntimeException |
|
| 1657 | + * @throws ReflectionException |
|
| 1658 | + */ |
|
| 1659 | + public function verify_abandoned_transaction_status() |
|
| 1660 | + { |
|
| 1661 | + if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) { |
|
| 1662 | + return; |
|
| 1663 | + } |
|
| 1664 | + $payments = $this->get_many_related('Payment'); |
|
| 1665 | + if (! empty($payments)) { |
|
| 1666 | + foreach ($payments as $payment) { |
|
| 1667 | + if ($payment instanceof EE_Payment) { |
|
| 1668 | + // kk this TXN should NOT be abandoned |
|
| 1669 | + $this->update_status_based_on_total_paid(); |
|
| 1670 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
| 1671 | + EE_Error::add_attention( |
|
| 1672 | + sprintf( |
|
| 1673 | + esc_html__( |
|
| 1674 | + 'The status for Transaction #%1$d has been updated from "Abandoned" to "%2$s", because at least one payment has been made towards it. If the payment appears in the "Payment Details" table below, you may need to edit its status and/or other details as well.', |
|
| 1675 | + 'event_espresso' |
|
| 1676 | + ), |
|
| 1677 | + $this->ID(), |
|
| 1678 | + $this->pretty_status() |
|
| 1679 | + ) |
|
| 1680 | + ); |
|
| 1681 | + } |
|
| 1682 | + // get final reg step status |
|
| 1683 | + $finalized = $this->final_reg_step_completed(); |
|
| 1684 | + // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
| 1685 | + // but has not yet been fully completed (TRUE) |
|
| 1686 | + if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
| 1687 | + $this->set_reg_step_completed('finalize_registration'); |
|
| 1688 | + $this->save(); |
|
| 1689 | + } |
|
| 1690 | + } |
|
| 1691 | + } |
|
| 1692 | + } |
|
| 1693 | + } |
|
| 1694 | 1694 | } |
@@ -16,1259 +16,1259 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This is used to hold the reports template data which is setup early in the request. |
|
| 21 | - * |
|
| 22 | - * @type array |
|
| 23 | - */ |
|
| 24 | - protected $_reports_template_data = array(); |
|
| 19 | + /** |
|
| 20 | + * This is used to hold the reports template data which is setup early in the request. |
|
| 21 | + * |
|
| 22 | + * @type array |
|
| 23 | + */ |
|
| 24 | + protected $_reports_template_data = array(); |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Extend_Registrations_Admin_Page constructor. |
|
| 29 | - * |
|
| 30 | - * @param bool $routing |
|
| 31 | - */ |
|
| 32 | - public function __construct($routing = true) |
|
| 33 | - { |
|
| 34 | - parent::__construct($routing); |
|
| 35 | - if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 37 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 38 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 39 | - } |
|
| 40 | - } |
|
| 27 | + /** |
|
| 28 | + * Extend_Registrations_Admin_Page constructor. |
|
| 29 | + * |
|
| 30 | + * @param bool $routing |
|
| 31 | + */ |
|
| 32 | + public function __construct($routing = true) |
|
| 33 | + { |
|
| 34 | + parent::__construct($routing); |
|
| 35 | + if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 37 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 38 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Extending page configuration. |
|
| 45 | - */ |
|
| 46 | - protected function _extend_page_config() |
|
| 47 | - { |
|
| 48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 49 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 50 | - ? $this->_req_data['_REG_ID'] |
|
| 51 | - : 0; |
|
| 52 | - $new_page_routes = array( |
|
| 53 | - 'reports' => array( |
|
| 54 | - 'func' => '_registration_reports', |
|
| 55 | - 'capability' => 'ee_read_registrations', |
|
| 56 | - ), |
|
| 57 | - 'registration_checkins' => array( |
|
| 58 | - 'func' => '_registration_checkin_list_table', |
|
| 59 | - 'capability' => 'ee_read_checkins', |
|
| 60 | - ), |
|
| 61 | - 'newsletter_selected_send' => array( |
|
| 62 | - 'func' => '_newsletter_selected_send', |
|
| 63 | - 'noheader' => true, |
|
| 64 | - 'capability' => 'ee_send_message', |
|
| 65 | - ), |
|
| 66 | - 'delete_checkin_rows' => array( |
|
| 67 | - 'func' => '_delete_checkin_rows', |
|
| 68 | - 'noheader' => true, |
|
| 69 | - 'capability' => 'ee_delete_checkins', |
|
| 70 | - ), |
|
| 71 | - 'delete_checkin_row' => array( |
|
| 72 | - 'func' => '_delete_checkin_row', |
|
| 73 | - 'noheader' => true, |
|
| 74 | - 'capability' => 'ee_delete_checkin', |
|
| 75 | - 'obj_id' => $reg_id, |
|
| 76 | - ), |
|
| 77 | - 'toggle_checkin_status' => array( |
|
| 78 | - 'func' => '_toggle_checkin_status', |
|
| 79 | - 'noheader' => true, |
|
| 80 | - 'capability' => 'ee_edit_checkin', |
|
| 81 | - 'obj_id' => $reg_id, |
|
| 82 | - ), |
|
| 83 | - 'toggle_checkin_status_bulk' => array( |
|
| 84 | - 'func' => '_toggle_checkin_status', |
|
| 85 | - 'noheader' => true, |
|
| 86 | - 'capability' => 'ee_edit_checkins', |
|
| 87 | - ), |
|
| 88 | - 'event_registrations' => array( |
|
| 89 | - 'func' => '_event_registrations_list_table', |
|
| 90 | - 'capability' => 'ee_read_checkins', |
|
| 91 | - ), |
|
| 92 | - 'registrations_checkin_report' => array( |
|
| 93 | - 'func' => '_registrations_checkin_report', |
|
| 94 | - 'noheader' => true, |
|
| 95 | - 'capability' => 'ee_read_registrations', |
|
| 96 | - ), |
|
| 97 | - ); |
|
| 98 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 99 | - $new_page_config = array( |
|
| 100 | - 'reports' => array( |
|
| 101 | - 'nav' => array( |
|
| 102 | - 'label' => esc_html__('Reports', 'event_espresso'), |
|
| 103 | - 'order' => 30, |
|
| 104 | - ), |
|
| 105 | - 'help_tabs' => array( |
|
| 106 | - 'registrations_reports_help_tab' => array( |
|
| 107 | - 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
| 108 | - 'filename' => 'registrations_reports', |
|
| 109 | - ), |
|
| 110 | - ), |
|
| 111 | - /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
| 112 | - 'require_nonce' => false, |
|
| 113 | - ), |
|
| 114 | - 'event_registrations' => array( |
|
| 115 | - 'nav' => array( |
|
| 116 | - 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
| 117 | - 'order' => 10, |
|
| 118 | - 'persistent' => true, |
|
| 119 | - ), |
|
| 120 | - 'help_tabs' => array( |
|
| 121 | - 'registrations_event_checkin_help_tab' => array( |
|
| 122 | - 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
| 123 | - 'filename' => 'registrations_event_checkin', |
|
| 124 | - ), |
|
| 125 | - 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
| 126 | - 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
| 127 | - 'filename' => 'registrations_event_checkin_table_column_headings', |
|
| 128 | - ), |
|
| 129 | - 'registrations_event_checkin_filters_help_tab' => array( |
|
| 130 | - 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
| 131 | - 'filename' => 'registrations_event_checkin_filters', |
|
| 132 | - ), |
|
| 133 | - 'registrations_event_checkin_views_help_tab' => array( |
|
| 134 | - 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
| 135 | - 'filename' => 'registrations_event_checkin_views', |
|
| 136 | - ), |
|
| 137 | - 'registrations_event_checkin_other_help_tab' => array( |
|
| 138 | - 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
| 139 | - 'filename' => 'registrations_event_checkin_other', |
|
| 140 | - ), |
|
| 141 | - ), |
|
| 142 | - 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
| 143 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
| 144 | - 'list_table' => 'EE_Event_Registrations_List_Table', |
|
| 145 | - 'metaboxes' => array(), |
|
| 146 | - 'require_nonce' => false, |
|
| 147 | - ), |
|
| 148 | - 'registration_checkins' => array( |
|
| 149 | - 'nav' => array( |
|
| 150 | - 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
| 151 | - 'order' => 15, |
|
| 152 | - 'persistent' => false, |
|
| 153 | - 'url' => '', |
|
| 154 | - ), |
|
| 155 | - 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
| 156 | - // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
| 157 | - 'metaboxes' => array(), |
|
| 158 | - 'require_nonce' => false, |
|
| 159 | - ), |
|
| 160 | - ); |
|
| 161 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 162 | - $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
| 163 | - $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
| 164 | - } |
|
| 43 | + /** |
|
| 44 | + * Extending page configuration. |
|
| 45 | + */ |
|
| 46 | + protected function _extend_page_config() |
|
| 47 | + { |
|
| 48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 49 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 50 | + ? $this->_req_data['_REG_ID'] |
|
| 51 | + : 0; |
|
| 52 | + $new_page_routes = array( |
|
| 53 | + 'reports' => array( |
|
| 54 | + 'func' => '_registration_reports', |
|
| 55 | + 'capability' => 'ee_read_registrations', |
|
| 56 | + ), |
|
| 57 | + 'registration_checkins' => array( |
|
| 58 | + 'func' => '_registration_checkin_list_table', |
|
| 59 | + 'capability' => 'ee_read_checkins', |
|
| 60 | + ), |
|
| 61 | + 'newsletter_selected_send' => array( |
|
| 62 | + 'func' => '_newsletter_selected_send', |
|
| 63 | + 'noheader' => true, |
|
| 64 | + 'capability' => 'ee_send_message', |
|
| 65 | + ), |
|
| 66 | + 'delete_checkin_rows' => array( |
|
| 67 | + 'func' => '_delete_checkin_rows', |
|
| 68 | + 'noheader' => true, |
|
| 69 | + 'capability' => 'ee_delete_checkins', |
|
| 70 | + ), |
|
| 71 | + 'delete_checkin_row' => array( |
|
| 72 | + 'func' => '_delete_checkin_row', |
|
| 73 | + 'noheader' => true, |
|
| 74 | + 'capability' => 'ee_delete_checkin', |
|
| 75 | + 'obj_id' => $reg_id, |
|
| 76 | + ), |
|
| 77 | + 'toggle_checkin_status' => array( |
|
| 78 | + 'func' => '_toggle_checkin_status', |
|
| 79 | + 'noheader' => true, |
|
| 80 | + 'capability' => 'ee_edit_checkin', |
|
| 81 | + 'obj_id' => $reg_id, |
|
| 82 | + ), |
|
| 83 | + 'toggle_checkin_status_bulk' => array( |
|
| 84 | + 'func' => '_toggle_checkin_status', |
|
| 85 | + 'noheader' => true, |
|
| 86 | + 'capability' => 'ee_edit_checkins', |
|
| 87 | + ), |
|
| 88 | + 'event_registrations' => array( |
|
| 89 | + 'func' => '_event_registrations_list_table', |
|
| 90 | + 'capability' => 'ee_read_checkins', |
|
| 91 | + ), |
|
| 92 | + 'registrations_checkin_report' => array( |
|
| 93 | + 'func' => '_registrations_checkin_report', |
|
| 94 | + 'noheader' => true, |
|
| 95 | + 'capability' => 'ee_read_registrations', |
|
| 96 | + ), |
|
| 97 | + ); |
|
| 98 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 99 | + $new_page_config = array( |
|
| 100 | + 'reports' => array( |
|
| 101 | + 'nav' => array( |
|
| 102 | + 'label' => esc_html__('Reports', 'event_espresso'), |
|
| 103 | + 'order' => 30, |
|
| 104 | + ), |
|
| 105 | + 'help_tabs' => array( |
|
| 106 | + 'registrations_reports_help_tab' => array( |
|
| 107 | + 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
| 108 | + 'filename' => 'registrations_reports', |
|
| 109 | + ), |
|
| 110 | + ), |
|
| 111 | + /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
| 112 | + 'require_nonce' => false, |
|
| 113 | + ), |
|
| 114 | + 'event_registrations' => array( |
|
| 115 | + 'nav' => array( |
|
| 116 | + 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
| 117 | + 'order' => 10, |
|
| 118 | + 'persistent' => true, |
|
| 119 | + ), |
|
| 120 | + 'help_tabs' => array( |
|
| 121 | + 'registrations_event_checkin_help_tab' => array( |
|
| 122 | + 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
| 123 | + 'filename' => 'registrations_event_checkin', |
|
| 124 | + ), |
|
| 125 | + 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
| 126 | + 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
| 127 | + 'filename' => 'registrations_event_checkin_table_column_headings', |
|
| 128 | + ), |
|
| 129 | + 'registrations_event_checkin_filters_help_tab' => array( |
|
| 130 | + 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
| 131 | + 'filename' => 'registrations_event_checkin_filters', |
|
| 132 | + ), |
|
| 133 | + 'registrations_event_checkin_views_help_tab' => array( |
|
| 134 | + 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
| 135 | + 'filename' => 'registrations_event_checkin_views', |
|
| 136 | + ), |
|
| 137 | + 'registrations_event_checkin_other_help_tab' => array( |
|
| 138 | + 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
| 139 | + 'filename' => 'registrations_event_checkin_other', |
|
| 140 | + ), |
|
| 141 | + ), |
|
| 142 | + 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
| 143 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
| 144 | + 'list_table' => 'EE_Event_Registrations_List_Table', |
|
| 145 | + 'metaboxes' => array(), |
|
| 146 | + 'require_nonce' => false, |
|
| 147 | + ), |
|
| 148 | + 'registration_checkins' => array( |
|
| 149 | + 'nav' => array( |
|
| 150 | + 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
| 151 | + 'order' => 15, |
|
| 152 | + 'persistent' => false, |
|
| 153 | + 'url' => '', |
|
| 154 | + ), |
|
| 155 | + 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
| 156 | + // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
| 157 | + 'metaboxes' => array(), |
|
| 158 | + 'require_nonce' => false, |
|
| 159 | + ), |
|
| 160 | + ); |
|
| 161 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 162 | + $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
| 163 | + $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Ajax hooks for all routes in this page. |
|
| 169 | - */ |
|
| 170 | - protected function _ajax_hooks() |
|
| 171 | - { |
|
| 172 | - parent::_ajax_hooks(); |
|
| 173 | - add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
| 174 | - } |
|
| 167 | + /** |
|
| 168 | + * Ajax hooks for all routes in this page. |
|
| 169 | + */ |
|
| 170 | + protected function _ajax_hooks() |
|
| 171 | + { |
|
| 172 | + parent::_ajax_hooks(); |
|
| 173 | + add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Global scripts for all routes in this page. |
|
| 179 | - */ |
|
| 180 | - public function load_scripts_styles() |
|
| 181 | - { |
|
| 182 | - parent::load_scripts_styles(); |
|
| 183 | - // if newsletter message type is active then let's add filter and load js for it. |
|
| 184 | - if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
| 185 | - // enqueue newsletter js |
|
| 186 | - wp_enqueue_script( |
|
| 187 | - 'ee-newsletter-trigger', |
|
| 188 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 189 | - array('ee-dialog'), |
|
| 190 | - EVENT_ESPRESSO_VERSION, |
|
| 191 | - true |
|
| 192 | - ); |
|
| 193 | - wp_enqueue_style( |
|
| 194 | - 'ee-newsletter-trigger-css', |
|
| 195 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 196 | - array(), |
|
| 197 | - EVENT_ESPRESSO_VERSION |
|
| 198 | - ); |
|
| 199 | - // hook in buttons for newsletter message type trigger. |
|
| 200 | - add_action( |
|
| 201 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 202 | - array($this, 'add_newsletter_action_buttons'), |
|
| 203 | - 10 |
|
| 204 | - ); |
|
| 205 | - } |
|
| 206 | - } |
|
| 177 | + /** |
|
| 178 | + * Global scripts for all routes in this page. |
|
| 179 | + */ |
|
| 180 | + public function load_scripts_styles() |
|
| 181 | + { |
|
| 182 | + parent::load_scripts_styles(); |
|
| 183 | + // if newsletter message type is active then let's add filter and load js for it. |
|
| 184 | + if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
| 185 | + // enqueue newsletter js |
|
| 186 | + wp_enqueue_script( |
|
| 187 | + 'ee-newsletter-trigger', |
|
| 188 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 189 | + array('ee-dialog'), |
|
| 190 | + EVENT_ESPRESSO_VERSION, |
|
| 191 | + true |
|
| 192 | + ); |
|
| 193 | + wp_enqueue_style( |
|
| 194 | + 'ee-newsletter-trigger-css', |
|
| 195 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 196 | + array(), |
|
| 197 | + EVENT_ESPRESSO_VERSION |
|
| 198 | + ); |
|
| 199 | + // hook in buttons for newsletter message type trigger. |
|
| 200 | + add_action( |
|
| 201 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 202 | + array($this, 'add_newsletter_action_buttons'), |
|
| 203 | + 10 |
|
| 204 | + ); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Scripts and styles for just the reports route. |
|
| 211 | - */ |
|
| 212 | - public function load_scripts_styles_reports() |
|
| 213 | - { |
|
| 214 | - wp_register_script( |
|
| 215 | - 'ee-reg-reports-js', |
|
| 216 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 217 | - array('google-charts'), |
|
| 218 | - EVENT_ESPRESSO_VERSION, |
|
| 219 | - true |
|
| 220 | - ); |
|
| 221 | - wp_enqueue_script('ee-reg-reports-js'); |
|
| 222 | - $this->_registration_reports_js_setup(); |
|
| 223 | - } |
|
| 209 | + /** |
|
| 210 | + * Scripts and styles for just the reports route. |
|
| 211 | + */ |
|
| 212 | + public function load_scripts_styles_reports() |
|
| 213 | + { |
|
| 214 | + wp_register_script( |
|
| 215 | + 'ee-reg-reports-js', |
|
| 216 | + REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 217 | + array('google-charts'), |
|
| 218 | + EVENT_ESPRESSO_VERSION, |
|
| 219 | + true |
|
| 220 | + ); |
|
| 221 | + wp_enqueue_script('ee-reg-reports-js'); |
|
| 222 | + $this->_registration_reports_js_setup(); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Register screen options for event_registrations route. |
|
| 228 | - */ |
|
| 229 | - protected function _add_screen_options_event_registrations() |
|
| 230 | - { |
|
| 231 | - $this->_per_page_screen_option(); |
|
| 232 | - } |
|
| 226 | + /** |
|
| 227 | + * Register screen options for event_registrations route. |
|
| 228 | + */ |
|
| 229 | + protected function _add_screen_options_event_registrations() |
|
| 230 | + { |
|
| 231 | + $this->_per_page_screen_option(); |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | 234 | |
| 235 | - /** |
|
| 236 | - * Register screen options for registration_checkins route |
|
| 237 | - */ |
|
| 238 | - protected function _add_screen_options_registration_checkins() |
|
| 239 | - { |
|
| 240 | - $page_title = $this->_admin_page_title; |
|
| 241 | - $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
| 242 | - $this->_per_page_screen_option(); |
|
| 243 | - $this->_admin_page_title = $page_title; |
|
| 244 | - } |
|
| 235 | + /** |
|
| 236 | + * Register screen options for registration_checkins route |
|
| 237 | + */ |
|
| 238 | + protected function _add_screen_options_registration_checkins() |
|
| 239 | + { |
|
| 240 | + $page_title = $this->_admin_page_title; |
|
| 241 | + $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
| 242 | + $this->_per_page_screen_option(); |
|
| 243 | + $this->_admin_page_title = $page_title; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * Set views property for event_registrations route. |
|
| 249 | - */ |
|
| 250 | - protected function _set_list_table_views_event_registrations() |
|
| 251 | - { |
|
| 252 | - $this->_views = array( |
|
| 253 | - 'all' => array( |
|
| 254 | - 'slug' => 'all', |
|
| 255 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 256 | - 'count' => 0, |
|
| 257 | - 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
| 258 | - ? array() |
|
| 259 | - : array( |
|
| 260 | - 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
| 261 | - ), |
|
| 262 | - ), |
|
| 263 | - ); |
|
| 264 | - } |
|
| 247 | + /** |
|
| 248 | + * Set views property for event_registrations route. |
|
| 249 | + */ |
|
| 250 | + protected function _set_list_table_views_event_registrations() |
|
| 251 | + { |
|
| 252 | + $this->_views = array( |
|
| 253 | + 'all' => array( |
|
| 254 | + 'slug' => 'all', |
|
| 255 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 256 | + 'count' => 0, |
|
| 257 | + 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
| 258 | + ? array() |
|
| 259 | + : array( |
|
| 260 | + 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
| 261 | + ), |
|
| 262 | + ), |
|
| 263 | + ); |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * Set views property for registration_checkins route. |
|
| 269 | - */ |
|
| 270 | - protected function _set_list_table_views_registration_checkins() |
|
| 271 | - { |
|
| 272 | - $this->_views = array( |
|
| 273 | - 'all' => array( |
|
| 274 | - 'slug' => 'all', |
|
| 275 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 276 | - 'count' => 0, |
|
| 277 | - 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
| 278 | - ), |
|
| 279 | - ); |
|
| 280 | - } |
|
| 267 | + /** |
|
| 268 | + * Set views property for registration_checkins route. |
|
| 269 | + */ |
|
| 270 | + protected function _set_list_table_views_registration_checkins() |
|
| 271 | + { |
|
| 272 | + $this->_views = array( |
|
| 273 | + 'all' => array( |
|
| 274 | + 'slug' => 'all', |
|
| 275 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 276 | + 'count' => 0, |
|
| 277 | + 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
| 278 | + ), |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * callback for ajax action. |
|
| 285 | - * |
|
| 286 | - * @since 4.3.0 |
|
| 287 | - * @return void (JSON) |
|
| 288 | - * @throws EE_Error |
|
| 289 | - * @throws InvalidArgumentException |
|
| 290 | - * @throws InvalidDataTypeException |
|
| 291 | - * @throws InvalidInterfaceException |
|
| 292 | - */ |
|
| 293 | - public function get_newsletter_form_content() |
|
| 294 | - { |
|
| 295 | - // do a nonce check cause we're not coming in from an normal route here. |
|
| 296 | - $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
| 297 | - $this->_req_data['get_newsletter_form_content_nonce'] |
|
| 298 | - ) : ''; |
|
| 299 | - $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
| 300 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 301 | - // let's get the mtp for the incoming MTP_ ID |
|
| 302 | - if (! isset($this->_req_data['GRP_ID'])) { |
|
| 303 | - EE_Error::add_error( |
|
| 304 | - esc_html__( |
|
| 305 | - 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
| 306 | - 'event_espresso' |
|
| 307 | - ), |
|
| 308 | - __FILE__, |
|
| 309 | - __FUNCTION__, |
|
| 310 | - __LINE__ |
|
| 311 | - ); |
|
| 312 | - $this->_template_args['success'] = false; |
|
| 313 | - $this->_template_args['error'] = true; |
|
| 314 | - $this->_return_json(); |
|
| 315 | - } |
|
| 316 | - $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
| 317 | - if (! $MTPG instanceof EE_Message_Template_Group) { |
|
| 318 | - EE_Error::add_error( |
|
| 319 | - sprintf( |
|
| 320 | - esc_html__( |
|
| 321 | - 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
| 322 | - 'event_espresso' |
|
| 323 | - ), |
|
| 324 | - $this->_req_data['GRP_ID'] |
|
| 325 | - ), |
|
| 326 | - __FILE__, |
|
| 327 | - __FUNCTION__, |
|
| 328 | - __LINE__ |
|
| 329 | - ); |
|
| 330 | - $this->_template_args['success'] = false; |
|
| 331 | - $this->_template_args['error'] = true; |
|
| 332 | - $this->_return_json(); |
|
| 333 | - } |
|
| 334 | - $MTPs = $MTPG->context_templates(); |
|
| 335 | - $MTPs = $MTPs['attendee']; |
|
| 336 | - $template_fields = array(); |
|
| 337 | - /** @var EE_Message_Template $MTP */ |
|
| 338 | - foreach ($MTPs as $MTP) { |
|
| 339 | - $field = $MTP->get('MTP_template_field'); |
|
| 340 | - if ($field === 'content') { |
|
| 341 | - $content = $MTP->get('MTP_content'); |
|
| 342 | - if (! empty($content['newsletter_content'])) { |
|
| 343 | - $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
| 344 | - } |
|
| 345 | - continue; |
|
| 346 | - } |
|
| 347 | - $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
| 348 | - } |
|
| 349 | - $this->_template_args['success'] = true; |
|
| 350 | - $this->_template_args['error'] = false; |
|
| 351 | - $this->_template_args['data'] = array( |
|
| 352 | - 'batch_message_from' => isset($template_fields['from']) |
|
| 353 | - ? $template_fields['from'] |
|
| 354 | - : '', |
|
| 355 | - 'batch_message_subject' => isset($template_fields['subject']) |
|
| 356 | - ? $template_fields['subject'] |
|
| 357 | - : '', |
|
| 358 | - 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
| 359 | - ? $template_fields['newsletter_content'] |
|
| 360 | - : '', |
|
| 361 | - ); |
|
| 362 | - $this->_return_json(); |
|
| 363 | - } |
|
| 283 | + /** |
|
| 284 | + * callback for ajax action. |
|
| 285 | + * |
|
| 286 | + * @since 4.3.0 |
|
| 287 | + * @return void (JSON) |
|
| 288 | + * @throws EE_Error |
|
| 289 | + * @throws InvalidArgumentException |
|
| 290 | + * @throws InvalidDataTypeException |
|
| 291 | + * @throws InvalidInterfaceException |
|
| 292 | + */ |
|
| 293 | + public function get_newsletter_form_content() |
|
| 294 | + { |
|
| 295 | + // do a nonce check cause we're not coming in from an normal route here. |
|
| 296 | + $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
| 297 | + $this->_req_data['get_newsletter_form_content_nonce'] |
|
| 298 | + ) : ''; |
|
| 299 | + $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
| 300 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 301 | + // let's get the mtp for the incoming MTP_ ID |
|
| 302 | + if (! isset($this->_req_data['GRP_ID'])) { |
|
| 303 | + EE_Error::add_error( |
|
| 304 | + esc_html__( |
|
| 305 | + 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
| 306 | + 'event_espresso' |
|
| 307 | + ), |
|
| 308 | + __FILE__, |
|
| 309 | + __FUNCTION__, |
|
| 310 | + __LINE__ |
|
| 311 | + ); |
|
| 312 | + $this->_template_args['success'] = false; |
|
| 313 | + $this->_template_args['error'] = true; |
|
| 314 | + $this->_return_json(); |
|
| 315 | + } |
|
| 316 | + $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
| 317 | + if (! $MTPG instanceof EE_Message_Template_Group) { |
|
| 318 | + EE_Error::add_error( |
|
| 319 | + sprintf( |
|
| 320 | + esc_html__( |
|
| 321 | + 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
| 322 | + 'event_espresso' |
|
| 323 | + ), |
|
| 324 | + $this->_req_data['GRP_ID'] |
|
| 325 | + ), |
|
| 326 | + __FILE__, |
|
| 327 | + __FUNCTION__, |
|
| 328 | + __LINE__ |
|
| 329 | + ); |
|
| 330 | + $this->_template_args['success'] = false; |
|
| 331 | + $this->_template_args['error'] = true; |
|
| 332 | + $this->_return_json(); |
|
| 333 | + } |
|
| 334 | + $MTPs = $MTPG->context_templates(); |
|
| 335 | + $MTPs = $MTPs['attendee']; |
|
| 336 | + $template_fields = array(); |
|
| 337 | + /** @var EE_Message_Template $MTP */ |
|
| 338 | + foreach ($MTPs as $MTP) { |
|
| 339 | + $field = $MTP->get('MTP_template_field'); |
|
| 340 | + if ($field === 'content') { |
|
| 341 | + $content = $MTP->get('MTP_content'); |
|
| 342 | + if (! empty($content['newsletter_content'])) { |
|
| 343 | + $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
| 344 | + } |
|
| 345 | + continue; |
|
| 346 | + } |
|
| 347 | + $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
| 348 | + } |
|
| 349 | + $this->_template_args['success'] = true; |
|
| 350 | + $this->_template_args['error'] = false; |
|
| 351 | + $this->_template_args['data'] = array( |
|
| 352 | + 'batch_message_from' => isset($template_fields['from']) |
|
| 353 | + ? $template_fields['from'] |
|
| 354 | + : '', |
|
| 355 | + 'batch_message_subject' => isset($template_fields['subject']) |
|
| 356 | + ? $template_fields['subject'] |
|
| 357 | + : '', |
|
| 358 | + 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
| 359 | + ? $template_fields['newsletter_content'] |
|
| 360 | + : '', |
|
| 361 | + ); |
|
| 362 | + $this->_return_json(); |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | 365 | |
| 366 | - /** |
|
| 367 | - * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
| 368 | - * |
|
| 369 | - * @since 4.3.0 |
|
| 370 | - * @param EE_Admin_List_Table $list_table |
|
| 371 | - * @return void |
|
| 372 | - * @throws InvalidArgumentException |
|
| 373 | - * @throws InvalidDataTypeException |
|
| 374 | - * @throws InvalidInterfaceException |
|
| 375 | - */ |
|
| 376 | - public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
| 377 | - { |
|
| 378 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 379 | - 'ee_send_message', |
|
| 380 | - 'espresso_registrations_newsletter_selected_send' |
|
| 381 | - ) |
|
| 382 | - ) { |
|
| 383 | - return; |
|
| 384 | - } |
|
| 385 | - $routes_to_add_to = array( |
|
| 386 | - 'contact_list', |
|
| 387 | - 'event_registrations', |
|
| 388 | - 'default', |
|
| 389 | - ); |
|
| 390 | - if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
| 391 | - if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
| 392 | - || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
| 393 | - ) { |
|
| 394 | - echo ''; |
|
| 395 | - } else { |
|
| 396 | - $button_text = sprintf( |
|
| 397 | - esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
| 398 | - '<span class="send-selected-newsletter-count">0</span>' |
|
| 399 | - ); |
|
| 400 | - echo '<button id="selected-batch-send-trigger" class="button secondary-button">' |
|
| 401 | - . '<span class="dashicons dashicons-email "></span>' |
|
| 402 | - . $button_text |
|
| 403 | - . '</button>'; |
|
| 404 | - add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 366 | + /** |
|
| 367 | + * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
| 368 | + * |
|
| 369 | + * @since 4.3.0 |
|
| 370 | + * @param EE_Admin_List_Table $list_table |
|
| 371 | + * @return void |
|
| 372 | + * @throws InvalidArgumentException |
|
| 373 | + * @throws InvalidDataTypeException |
|
| 374 | + * @throws InvalidInterfaceException |
|
| 375 | + */ |
|
| 376 | + public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
| 377 | + { |
|
| 378 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 379 | + 'ee_send_message', |
|
| 380 | + 'espresso_registrations_newsletter_selected_send' |
|
| 381 | + ) |
|
| 382 | + ) { |
|
| 383 | + return; |
|
| 384 | + } |
|
| 385 | + $routes_to_add_to = array( |
|
| 386 | + 'contact_list', |
|
| 387 | + 'event_registrations', |
|
| 388 | + 'default', |
|
| 389 | + ); |
|
| 390 | + if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
| 391 | + if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
| 392 | + || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
| 393 | + ) { |
|
| 394 | + echo ''; |
|
| 395 | + } else { |
|
| 396 | + $button_text = sprintf( |
|
| 397 | + esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
| 398 | + '<span class="send-selected-newsletter-count">0</span>' |
|
| 399 | + ); |
|
| 400 | + echo '<button id="selected-batch-send-trigger" class="button secondary-button">' |
|
| 401 | + . '<span class="dashicons dashicons-email "></span>' |
|
| 402 | + . $button_text |
|
| 403 | + . '</button>'; |
|
| 404 | + add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | 409 | |
| 410 | - /** |
|
| 411 | - * @throws DomainException |
|
| 412 | - * @throws EE_Error |
|
| 413 | - * @throws InvalidArgumentException |
|
| 414 | - * @throws InvalidDataTypeException |
|
| 415 | - * @throws InvalidInterfaceException |
|
| 416 | - */ |
|
| 417 | - public function newsletter_send_form_skeleton() |
|
| 418 | - { |
|
| 419 | - $list_table = $this->_list_table_object; |
|
| 420 | - $codes = array(); |
|
| 421 | - // need to templates for the newsletter message type for the template selector. |
|
| 422 | - $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
| 423 | - $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
| 424 | - array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
| 425 | - ); |
|
| 426 | - foreach ($mtps as $mtp) { |
|
| 427 | - $name = $mtp->name(); |
|
| 428 | - $values[] = array( |
|
| 429 | - 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
| 430 | - 'id' => $mtp->ID(), |
|
| 431 | - ); |
|
| 432 | - } |
|
| 433 | - // need to get a list of shortcodes that are available for the newsletter message type. |
|
| 434 | - $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
| 435 | - 'newsletter', |
|
| 436 | - 'email', |
|
| 437 | - array(), |
|
| 438 | - 'attendee', |
|
| 439 | - false |
|
| 440 | - ); |
|
| 441 | - foreach ($shortcodes as $field => $shortcode_array) { |
|
| 442 | - $available_shortcodes = array(); |
|
| 443 | - foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
| 444 | - $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
| 445 | - ? 'content' |
|
| 446 | - : $field; |
|
| 447 | - $field_id = 'batch-message-' . strtolower($field_id); |
|
| 448 | - $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
| 449 | - . $shortcode |
|
| 450 | - . '" data-linked-input-id="' . $field_id . '">' |
|
| 451 | - . $shortcode |
|
| 452 | - . '</span>'; |
|
| 453 | - } |
|
| 454 | - $codes[ $field ] = implode(', ', $available_shortcodes); |
|
| 455 | - } |
|
| 456 | - $shortcodes = $codes; |
|
| 457 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 458 | - $form_template_args = array( |
|
| 459 | - 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
| 460 | - 'form_route' => 'newsletter_selected_send', |
|
| 461 | - 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
| 462 | - 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
| 463 | - 'redirect_back_to' => $this->_req_action, |
|
| 464 | - 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
| 465 | - 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
| 466 | - 'shortcodes' => $shortcodes, |
|
| 467 | - 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
| 468 | - ); |
|
| 469 | - EEH_Template::display_template($form_template, $form_template_args); |
|
| 470 | - } |
|
| 410 | + /** |
|
| 411 | + * @throws DomainException |
|
| 412 | + * @throws EE_Error |
|
| 413 | + * @throws InvalidArgumentException |
|
| 414 | + * @throws InvalidDataTypeException |
|
| 415 | + * @throws InvalidInterfaceException |
|
| 416 | + */ |
|
| 417 | + public function newsletter_send_form_skeleton() |
|
| 418 | + { |
|
| 419 | + $list_table = $this->_list_table_object; |
|
| 420 | + $codes = array(); |
|
| 421 | + // need to templates for the newsletter message type for the template selector. |
|
| 422 | + $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
| 423 | + $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
| 424 | + array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
| 425 | + ); |
|
| 426 | + foreach ($mtps as $mtp) { |
|
| 427 | + $name = $mtp->name(); |
|
| 428 | + $values[] = array( |
|
| 429 | + 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
| 430 | + 'id' => $mtp->ID(), |
|
| 431 | + ); |
|
| 432 | + } |
|
| 433 | + // need to get a list of shortcodes that are available for the newsletter message type. |
|
| 434 | + $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
| 435 | + 'newsletter', |
|
| 436 | + 'email', |
|
| 437 | + array(), |
|
| 438 | + 'attendee', |
|
| 439 | + false |
|
| 440 | + ); |
|
| 441 | + foreach ($shortcodes as $field => $shortcode_array) { |
|
| 442 | + $available_shortcodes = array(); |
|
| 443 | + foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
| 444 | + $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
| 445 | + ? 'content' |
|
| 446 | + : $field; |
|
| 447 | + $field_id = 'batch-message-' . strtolower($field_id); |
|
| 448 | + $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
| 449 | + . $shortcode |
|
| 450 | + . '" data-linked-input-id="' . $field_id . '">' |
|
| 451 | + . $shortcode |
|
| 452 | + . '</span>'; |
|
| 453 | + } |
|
| 454 | + $codes[ $field ] = implode(', ', $available_shortcodes); |
|
| 455 | + } |
|
| 456 | + $shortcodes = $codes; |
|
| 457 | + $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 458 | + $form_template_args = array( |
|
| 459 | + 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
| 460 | + 'form_route' => 'newsletter_selected_send', |
|
| 461 | + 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
| 462 | + 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
| 463 | + 'redirect_back_to' => $this->_req_action, |
|
| 464 | + 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
| 465 | + 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
| 466 | + 'shortcodes' => $shortcodes, |
|
| 467 | + 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
| 468 | + ); |
|
| 469 | + EEH_Template::display_template($form_template, $form_template_args); |
|
| 470 | + } |
|
| 471 | 471 | |
| 472 | 472 | |
| 473 | - /** |
|
| 474 | - * Handles sending selected registrations/contacts a newsletter. |
|
| 475 | - * |
|
| 476 | - * @since 4.3.0 |
|
| 477 | - * @return void |
|
| 478 | - * @throws EE_Error |
|
| 479 | - * @throws InvalidArgumentException |
|
| 480 | - * @throws InvalidDataTypeException |
|
| 481 | - * @throws InvalidInterfaceException |
|
| 482 | - */ |
|
| 483 | - protected function _newsletter_selected_send() |
|
| 484 | - { |
|
| 485 | - $success = true; |
|
| 486 | - // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
| 487 | - if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
| 488 | - EE_Error::add_error( |
|
| 489 | - esc_html__( |
|
| 490 | - 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
| 491 | - 'event_espresso' |
|
| 492 | - ), |
|
| 493 | - __FILE__, |
|
| 494 | - __FUNCTION__, |
|
| 495 | - __LINE__ |
|
| 496 | - ); |
|
| 497 | - $success = false; |
|
| 498 | - } |
|
| 499 | - if ($success) { |
|
| 500 | - // update Message template in case there are any changes |
|
| 501 | - $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 502 | - $this->_req_data['newsletter_mtp_selected'] |
|
| 503 | - ); |
|
| 504 | - $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
| 505 | - ? $Message_Template_Group->context_templates() |
|
| 506 | - : array(); |
|
| 507 | - if (empty($Message_Templates)) { |
|
| 508 | - EE_Error::add_error( |
|
| 509 | - esc_html__( |
|
| 510 | - 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
| 511 | - 'event_espresso' |
|
| 512 | - ), |
|
| 513 | - __FILE__, |
|
| 514 | - __FUNCTION__, |
|
| 515 | - __LINE__ |
|
| 516 | - ); |
|
| 517 | - } |
|
| 518 | - // let's just update the specific fields |
|
| 519 | - foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
| 520 | - if ($Message_Template instanceof EE_Message_Template) { |
|
| 521 | - $field = $Message_Template->get('MTP_template_field'); |
|
| 522 | - $content = $Message_Template->get('MTP_content'); |
|
| 523 | - $new_content = $content; |
|
| 524 | - switch ($field) { |
|
| 525 | - case 'from': |
|
| 526 | - $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
| 527 | - ? $this->_req_data['batch_message']['from'] |
|
| 528 | - : $content; |
|
| 529 | - break; |
|
| 530 | - case 'subject': |
|
| 531 | - $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
| 532 | - ? $this->_req_data['batch_message']['subject'] |
|
| 533 | - : $content; |
|
| 534 | - break; |
|
| 535 | - case 'content': |
|
| 536 | - $new_content = $content; |
|
| 537 | - $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
| 538 | - ? $this->_req_data['batch_message']['content'] |
|
| 539 | - : $content['newsletter_content']; |
|
| 540 | - break; |
|
| 541 | - default: |
|
| 542 | - // continue the foreach loop, we don't want to set $new_content nor save. |
|
| 543 | - continue 2; |
|
| 544 | - } |
|
| 545 | - $Message_Template->set('MTP_content', $new_content); |
|
| 546 | - $Message_Template->save(); |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
| 550 | - $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
| 551 | - ? $this->_req_data['batch_message']['id_type'] |
|
| 552 | - : 'registration'; |
|
| 553 | - // id_type will affect how we assemble the ids. |
|
| 554 | - $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
| 555 | - ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
| 556 | - : array(); |
|
| 557 | - $registrations_used_for_contact_data = array(); |
|
| 558 | - // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
| 559 | - switch ($id_type) { |
|
| 560 | - case 'registration': |
|
| 561 | - $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
| 562 | - array( |
|
| 563 | - array( |
|
| 564 | - 'REG_ID' => array('IN', $ids), |
|
| 565 | - ), |
|
| 566 | - ) |
|
| 567 | - ); |
|
| 568 | - break; |
|
| 569 | - case 'contact': |
|
| 570 | - $registrations_used_for_contact_data = EEM_Registration::instance() |
|
| 571 | - ->get_latest_registration_for_each_of_given_contacts( |
|
| 572 | - $ids |
|
| 573 | - ); |
|
| 574 | - break; |
|
| 575 | - } |
|
| 576 | - do_action_ref_array( |
|
| 577 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 578 | - array( |
|
| 579 | - $registrations_used_for_contact_data, |
|
| 580 | - $Message_Template_Group->ID(), |
|
| 581 | - ) |
|
| 582 | - ); |
|
| 583 | - // kept for backward compat, internally we no longer use this action. |
|
| 584 | - // @deprecated 4.8.36.rc.002 |
|
| 585 | - $contacts = $id_type === 'registration' |
|
| 586 | - ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
| 587 | - : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
| 588 | - do_action_ref_array( |
|
| 589 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
| 590 | - array( |
|
| 591 | - $contacts, |
|
| 592 | - $Message_Template_Group->ID(), |
|
| 593 | - ) |
|
| 594 | - ); |
|
| 595 | - } |
|
| 596 | - $query_args = array( |
|
| 597 | - 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
| 598 | - ? $this->_req_data['redirect_back_to'] |
|
| 599 | - : 'default', |
|
| 600 | - ); |
|
| 601 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 602 | - } |
|
| 473 | + /** |
|
| 474 | + * Handles sending selected registrations/contacts a newsletter. |
|
| 475 | + * |
|
| 476 | + * @since 4.3.0 |
|
| 477 | + * @return void |
|
| 478 | + * @throws EE_Error |
|
| 479 | + * @throws InvalidArgumentException |
|
| 480 | + * @throws InvalidDataTypeException |
|
| 481 | + * @throws InvalidInterfaceException |
|
| 482 | + */ |
|
| 483 | + protected function _newsletter_selected_send() |
|
| 484 | + { |
|
| 485 | + $success = true; |
|
| 486 | + // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
| 487 | + if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
| 488 | + EE_Error::add_error( |
|
| 489 | + esc_html__( |
|
| 490 | + 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
| 491 | + 'event_espresso' |
|
| 492 | + ), |
|
| 493 | + __FILE__, |
|
| 494 | + __FUNCTION__, |
|
| 495 | + __LINE__ |
|
| 496 | + ); |
|
| 497 | + $success = false; |
|
| 498 | + } |
|
| 499 | + if ($success) { |
|
| 500 | + // update Message template in case there are any changes |
|
| 501 | + $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 502 | + $this->_req_data['newsletter_mtp_selected'] |
|
| 503 | + ); |
|
| 504 | + $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
| 505 | + ? $Message_Template_Group->context_templates() |
|
| 506 | + : array(); |
|
| 507 | + if (empty($Message_Templates)) { |
|
| 508 | + EE_Error::add_error( |
|
| 509 | + esc_html__( |
|
| 510 | + 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
| 511 | + 'event_espresso' |
|
| 512 | + ), |
|
| 513 | + __FILE__, |
|
| 514 | + __FUNCTION__, |
|
| 515 | + __LINE__ |
|
| 516 | + ); |
|
| 517 | + } |
|
| 518 | + // let's just update the specific fields |
|
| 519 | + foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
| 520 | + if ($Message_Template instanceof EE_Message_Template) { |
|
| 521 | + $field = $Message_Template->get('MTP_template_field'); |
|
| 522 | + $content = $Message_Template->get('MTP_content'); |
|
| 523 | + $new_content = $content; |
|
| 524 | + switch ($field) { |
|
| 525 | + case 'from': |
|
| 526 | + $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
| 527 | + ? $this->_req_data['batch_message']['from'] |
|
| 528 | + : $content; |
|
| 529 | + break; |
|
| 530 | + case 'subject': |
|
| 531 | + $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
| 532 | + ? $this->_req_data['batch_message']['subject'] |
|
| 533 | + : $content; |
|
| 534 | + break; |
|
| 535 | + case 'content': |
|
| 536 | + $new_content = $content; |
|
| 537 | + $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
| 538 | + ? $this->_req_data['batch_message']['content'] |
|
| 539 | + : $content['newsletter_content']; |
|
| 540 | + break; |
|
| 541 | + default: |
|
| 542 | + // continue the foreach loop, we don't want to set $new_content nor save. |
|
| 543 | + continue 2; |
|
| 544 | + } |
|
| 545 | + $Message_Template->set('MTP_content', $new_content); |
|
| 546 | + $Message_Template->save(); |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
| 550 | + $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
| 551 | + ? $this->_req_data['batch_message']['id_type'] |
|
| 552 | + : 'registration'; |
|
| 553 | + // id_type will affect how we assemble the ids. |
|
| 554 | + $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
| 555 | + ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
| 556 | + : array(); |
|
| 557 | + $registrations_used_for_contact_data = array(); |
|
| 558 | + // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
| 559 | + switch ($id_type) { |
|
| 560 | + case 'registration': |
|
| 561 | + $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
| 562 | + array( |
|
| 563 | + array( |
|
| 564 | + 'REG_ID' => array('IN', $ids), |
|
| 565 | + ), |
|
| 566 | + ) |
|
| 567 | + ); |
|
| 568 | + break; |
|
| 569 | + case 'contact': |
|
| 570 | + $registrations_used_for_contact_data = EEM_Registration::instance() |
|
| 571 | + ->get_latest_registration_for_each_of_given_contacts( |
|
| 572 | + $ids |
|
| 573 | + ); |
|
| 574 | + break; |
|
| 575 | + } |
|
| 576 | + do_action_ref_array( |
|
| 577 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 578 | + array( |
|
| 579 | + $registrations_used_for_contact_data, |
|
| 580 | + $Message_Template_Group->ID(), |
|
| 581 | + ) |
|
| 582 | + ); |
|
| 583 | + // kept for backward compat, internally we no longer use this action. |
|
| 584 | + // @deprecated 4.8.36.rc.002 |
|
| 585 | + $contacts = $id_type === 'registration' |
|
| 586 | + ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
| 587 | + : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
| 588 | + do_action_ref_array( |
|
| 589 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
| 590 | + array( |
|
| 591 | + $contacts, |
|
| 592 | + $Message_Template_Group->ID(), |
|
| 593 | + ) |
|
| 594 | + ); |
|
| 595 | + } |
|
| 596 | + $query_args = array( |
|
| 597 | + 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
| 598 | + ? $this->_req_data['redirect_back_to'] |
|
| 599 | + : 'default', |
|
| 600 | + ); |
|
| 601 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | 604 | |
| 605 | - /** |
|
| 606 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
| 607 | - * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
| 608 | - */ |
|
| 609 | - protected function _registration_reports_js_setup() |
|
| 610 | - { |
|
| 611 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
| 612 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
| 613 | - } |
|
| 605 | + /** |
|
| 606 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
| 607 | + * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
| 608 | + */ |
|
| 609 | + protected function _registration_reports_js_setup() |
|
| 610 | + { |
|
| 611 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
| 612 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
| 613 | + } |
|
| 614 | 614 | |
| 615 | 615 | |
| 616 | - /** |
|
| 617 | - * generates Business Reports regarding Registrations |
|
| 618 | - * |
|
| 619 | - * @access protected |
|
| 620 | - * @return void |
|
| 621 | - * @throws DomainException |
|
| 622 | - */ |
|
| 623 | - protected function _registration_reports() |
|
| 624 | - { |
|
| 625 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 626 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 627 | - $template_path, |
|
| 628 | - $this->_reports_template_data, |
|
| 629 | - true |
|
| 630 | - ); |
|
| 631 | - // the final template wrapper |
|
| 632 | - $this->display_admin_page_with_no_sidebar(); |
|
| 633 | - } |
|
| 616 | + /** |
|
| 617 | + * generates Business Reports regarding Registrations |
|
| 618 | + * |
|
| 619 | + * @access protected |
|
| 620 | + * @return void |
|
| 621 | + * @throws DomainException |
|
| 622 | + */ |
|
| 623 | + protected function _registration_reports() |
|
| 624 | + { |
|
| 625 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 626 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 627 | + $template_path, |
|
| 628 | + $this->_reports_template_data, |
|
| 629 | + true |
|
| 630 | + ); |
|
| 631 | + // the final template wrapper |
|
| 632 | + $this->display_admin_page_with_no_sidebar(); |
|
| 633 | + } |
|
| 634 | 634 | |
| 635 | 635 | |
| 636 | - /** |
|
| 637 | - * Generates Business Report showing total registrations per day. |
|
| 638 | - * |
|
| 639 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 640 | - * @return string |
|
| 641 | - * @throws EE_Error |
|
| 642 | - * @throws InvalidArgumentException |
|
| 643 | - * @throws InvalidDataTypeException |
|
| 644 | - * @throws InvalidInterfaceException |
|
| 645 | - */ |
|
| 646 | - private function _registrations_per_day_report($period = '-1 month') |
|
| 647 | - { |
|
| 648 | - $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
| 649 | - $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
| 650 | - $results = (array) $results; |
|
| 651 | - $regs = array(); |
|
| 652 | - $subtitle = ''; |
|
| 653 | - if ($results) { |
|
| 654 | - $column_titles = array(); |
|
| 655 | - $tracker = 0; |
|
| 656 | - foreach ($results as $result) { |
|
| 657 | - $report_column_values = array(); |
|
| 658 | - foreach ($result as $property_name => $property_value) { |
|
| 659 | - $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
| 660 | - : (int) $property_value; |
|
| 661 | - $report_column_values[] = $property_value; |
|
| 662 | - if ($tracker === 0) { |
|
| 663 | - if ($property_name === 'Registration_REG_date') { |
|
| 664 | - $column_titles[] = esc_html__( |
|
| 665 | - 'Date (only days with registrations are shown)', |
|
| 666 | - 'event_espresso' |
|
| 667 | - ); |
|
| 668 | - } else { |
|
| 669 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - $tracker++; |
|
| 674 | - $regs[] = $report_column_values; |
|
| 675 | - } |
|
| 676 | - // make sure the column_titles is pushed to the beginning of the array |
|
| 677 | - array_unshift($regs, $column_titles); |
|
| 678 | - // setup the date range. |
|
| 679 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 680 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 681 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
| 682 | - $subtitle = sprintf( |
|
| 683 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 684 | - $beginning_date->format('Y-m-d'), |
|
| 685 | - $ending_date->format('Y-m-d') |
|
| 686 | - ); |
|
| 687 | - } |
|
| 688 | - $report_title = esc_html__('Total Registrations per Day', 'event_espresso'); |
|
| 689 | - $report_params = array( |
|
| 690 | - 'title' => $report_title, |
|
| 691 | - 'subtitle' => $subtitle, |
|
| 692 | - 'id' => $report_ID, |
|
| 693 | - 'regs' => $regs, |
|
| 694 | - 'noResults' => empty($regs), |
|
| 695 | - 'noRegsMsg' => sprintf( |
|
| 696 | - esc_html__( |
|
| 697 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
| 698 | - 'event_espresso' |
|
| 699 | - ), |
|
| 700 | - '<h2>' . $report_title . '</h2><p>', |
|
| 701 | - '</p>' |
|
| 702 | - ), |
|
| 703 | - ); |
|
| 704 | - wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
| 705 | - return $report_ID; |
|
| 706 | - } |
|
| 636 | + /** |
|
| 637 | + * Generates Business Report showing total registrations per day. |
|
| 638 | + * |
|
| 639 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 640 | + * @return string |
|
| 641 | + * @throws EE_Error |
|
| 642 | + * @throws InvalidArgumentException |
|
| 643 | + * @throws InvalidDataTypeException |
|
| 644 | + * @throws InvalidInterfaceException |
|
| 645 | + */ |
|
| 646 | + private function _registrations_per_day_report($period = '-1 month') |
|
| 647 | + { |
|
| 648 | + $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
| 649 | + $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
| 650 | + $results = (array) $results; |
|
| 651 | + $regs = array(); |
|
| 652 | + $subtitle = ''; |
|
| 653 | + if ($results) { |
|
| 654 | + $column_titles = array(); |
|
| 655 | + $tracker = 0; |
|
| 656 | + foreach ($results as $result) { |
|
| 657 | + $report_column_values = array(); |
|
| 658 | + foreach ($result as $property_name => $property_value) { |
|
| 659 | + $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
| 660 | + : (int) $property_value; |
|
| 661 | + $report_column_values[] = $property_value; |
|
| 662 | + if ($tracker === 0) { |
|
| 663 | + if ($property_name === 'Registration_REG_date') { |
|
| 664 | + $column_titles[] = esc_html__( |
|
| 665 | + 'Date (only days with registrations are shown)', |
|
| 666 | + 'event_espresso' |
|
| 667 | + ); |
|
| 668 | + } else { |
|
| 669 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + $tracker++; |
|
| 674 | + $regs[] = $report_column_values; |
|
| 675 | + } |
|
| 676 | + // make sure the column_titles is pushed to the beginning of the array |
|
| 677 | + array_unshift($regs, $column_titles); |
|
| 678 | + // setup the date range. |
|
| 679 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 680 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 681 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
| 682 | + $subtitle = sprintf( |
|
| 683 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 684 | + $beginning_date->format('Y-m-d'), |
|
| 685 | + $ending_date->format('Y-m-d') |
|
| 686 | + ); |
|
| 687 | + } |
|
| 688 | + $report_title = esc_html__('Total Registrations per Day', 'event_espresso'); |
|
| 689 | + $report_params = array( |
|
| 690 | + 'title' => $report_title, |
|
| 691 | + 'subtitle' => $subtitle, |
|
| 692 | + 'id' => $report_ID, |
|
| 693 | + 'regs' => $regs, |
|
| 694 | + 'noResults' => empty($regs), |
|
| 695 | + 'noRegsMsg' => sprintf( |
|
| 696 | + esc_html__( |
|
| 697 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
| 698 | + 'event_espresso' |
|
| 699 | + ), |
|
| 700 | + '<h2>' . $report_title . '</h2><p>', |
|
| 701 | + '</p>' |
|
| 702 | + ), |
|
| 703 | + ); |
|
| 704 | + wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
| 705 | + return $report_ID; |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | 708 | |
| 709 | - /** |
|
| 710 | - * Generates Business Report showing total registrations per event. |
|
| 711 | - * |
|
| 712 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 713 | - * @return string |
|
| 714 | - * @throws EE_Error |
|
| 715 | - * @throws InvalidArgumentException |
|
| 716 | - * @throws InvalidDataTypeException |
|
| 717 | - * @throws InvalidInterfaceException |
|
| 718 | - */ |
|
| 719 | - private function _registrations_per_event_report($period = '-1 month') |
|
| 720 | - { |
|
| 721 | - $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
| 722 | - $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
| 723 | - $results = (array) $results; |
|
| 724 | - $regs = array(); |
|
| 725 | - $subtitle = ''; |
|
| 726 | - if ($results) { |
|
| 727 | - $column_titles = array(); |
|
| 728 | - $tracker = 0; |
|
| 729 | - foreach ($results as $result) { |
|
| 730 | - $report_column_values = array(); |
|
| 731 | - foreach ($result as $property_name => $property_value) { |
|
| 732 | - $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
| 733 | - $property_value, |
|
| 734 | - 4, |
|
| 735 | - '...' |
|
| 736 | - ) : (int) $property_value; |
|
| 737 | - $report_column_values[] = $property_value; |
|
| 738 | - if ($tracker === 0) { |
|
| 739 | - if ($property_name === 'Registration_Event') { |
|
| 740 | - $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
| 741 | - } else { |
|
| 742 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - $tracker++; |
|
| 747 | - $regs[] = $report_column_values; |
|
| 748 | - } |
|
| 749 | - // make sure the column_titles is pushed to the beginning of the array |
|
| 750 | - array_unshift($regs, $column_titles); |
|
| 751 | - // setup the date range. |
|
| 752 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 753 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 754 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
| 755 | - $subtitle = sprintf( |
|
| 756 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 757 | - $beginning_date->format('Y-m-d'), |
|
| 758 | - $ending_date->format('Y-m-d') |
|
| 759 | - ); |
|
| 760 | - } |
|
| 761 | - $report_title = esc_html__('Total Registrations per Event', 'event_espresso'); |
|
| 762 | - $report_params = array( |
|
| 763 | - 'title' => $report_title, |
|
| 764 | - 'subtitle' => $subtitle, |
|
| 765 | - 'id' => $report_ID, |
|
| 766 | - 'regs' => $regs, |
|
| 767 | - 'noResults' => empty($regs), |
|
| 768 | - 'noRegsMsg' => sprintf( |
|
| 769 | - esc_html__( |
|
| 770 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
| 771 | - 'event_espresso' |
|
| 772 | - ), |
|
| 773 | - '<h2>' . $report_title . '</h2><p>', |
|
| 774 | - '</p>' |
|
| 775 | - ), |
|
| 776 | - ); |
|
| 777 | - wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
| 778 | - return $report_ID; |
|
| 779 | - } |
|
| 709 | + /** |
|
| 710 | + * Generates Business Report showing total registrations per event. |
|
| 711 | + * |
|
| 712 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 713 | + * @return string |
|
| 714 | + * @throws EE_Error |
|
| 715 | + * @throws InvalidArgumentException |
|
| 716 | + * @throws InvalidDataTypeException |
|
| 717 | + * @throws InvalidInterfaceException |
|
| 718 | + */ |
|
| 719 | + private function _registrations_per_event_report($period = '-1 month') |
|
| 720 | + { |
|
| 721 | + $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
| 722 | + $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
| 723 | + $results = (array) $results; |
|
| 724 | + $regs = array(); |
|
| 725 | + $subtitle = ''; |
|
| 726 | + if ($results) { |
|
| 727 | + $column_titles = array(); |
|
| 728 | + $tracker = 0; |
|
| 729 | + foreach ($results as $result) { |
|
| 730 | + $report_column_values = array(); |
|
| 731 | + foreach ($result as $property_name => $property_value) { |
|
| 732 | + $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
| 733 | + $property_value, |
|
| 734 | + 4, |
|
| 735 | + '...' |
|
| 736 | + ) : (int) $property_value; |
|
| 737 | + $report_column_values[] = $property_value; |
|
| 738 | + if ($tracker === 0) { |
|
| 739 | + if ($property_name === 'Registration_Event') { |
|
| 740 | + $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
| 741 | + } else { |
|
| 742 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + $tracker++; |
|
| 747 | + $regs[] = $report_column_values; |
|
| 748 | + } |
|
| 749 | + // make sure the column_titles is pushed to the beginning of the array |
|
| 750 | + array_unshift($regs, $column_titles); |
|
| 751 | + // setup the date range. |
|
| 752 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 753 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 754 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
| 755 | + $subtitle = sprintf( |
|
| 756 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 757 | + $beginning_date->format('Y-m-d'), |
|
| 758 | + $ending_date->format('Y-m-d') |
|
| 759 | + ); |
|
| 760 | + } |
|
| 761 | + $report_title = esc_html__('Total Registrations per Event', 'event_espresso'); |
|
| 762 | + $report_params = array( |
|
| 763 | + 'title' => $report_title, |
|
| 764 | + 'subtitle' => $subtitle, |
|
| 765 | + 'id' => $report_ID, |
|
| 766 | + 'regs' => $regs, |
|
| 767 | + 'noResults' => empty($regs), |
|
| 768 | + 'noRegsMsg' => sprintf( |
|
| 769 | + esc_html__( |
|
| 770 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
| 771 | + 'event_espresso' |
|
| 772 | + ), |
|
| 773 | + '<h2>' . $report_title . '</h2><p>', |
|
| 774 | + '</p>' |
|
| 775 | + ), |
|
| 776 | + ); |
|
| 777 | + wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
| 778 | + return $report_ID; |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | 781 | |
| 782 | - /** |
|
| 783 | - * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
| 784 | - * |
|
| 785 | - * @access protected |
|
| 786 | - * @return void |
|
| 787 | - * @throws EE_Error |
|
| 788 | - * @throws InvalidArgumentException |
|
| 789 | - * @throws InvalidDataTypeException |
|
| 790 | - * @throws InvalidInterfaceException |
|
| 791 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 792 | - */ |
|
| 793 | - protected function _registration_checkin_list_table() |
|
| 794 | - { |
|
| 795 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 796 | - $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null; |
|
| 797 | - /** @var EE_Registration $registration */ |
|
| 798 | - $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
| 799 | - $attendee = $registration->attendee(); |
|
| 800 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 801 | - 'new_registration', |
|
| 802 | - 'add-registrant', |
|
| 803 | - array('event_id' => $registration->event_ID()), |
|
| 804 | - 'add-new-h2' |
|
| 805 | - ); |
|
| 806 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 807 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 808 | - $legend_items = array( |
|
| 809 | - 'checkin' => array( |
|
| 810 | - 'class' => $checked_in->cssClasses(), |
|
| 811 | - 'desc' => $checked_in->legendLabel(), |
|
| 812 | - ), |
|
| 813 | - 'checkout' => array( |
|
| 814 | - 'class' => $checked_out->cssClasses(), |
|
| 815 | - 'desc' => $checked_out->legendLabel(), |
|
| 816 | - ), |
|
| 817 | - ); |
|
| 818 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 819 | - $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 820 | - /** @var EE_Datetime $datetime */ |
|
| 821 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
| 822 | - $datetime_label = ''; |
|
| 823 | - if ($datetime instanceof EE_Datetime) { |
|
| 824 | - $datetime_label = $datetime->get_dtt_display_name(true); |
|
| 825 | - $datetime_label .= ! empty($datetime_label) |
|
| 826 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
| 827 | - : $datetime->get_dtt_display_name(); |
|
| 828 | - } |
|
| 829 | - $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
| 830 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 831 | - array( |
|
| 832 | - 'action' => 'event_registrations', |
|
| 833 | - 'event_id' => $registration->event_ID(), |
|
| 834 | - 'DTT_ID' => $dtt_id, |
|
| 835 | - ), |
|
| 836 | - $this->_admin_base_url |
|
| 837 | - ) |
|
| 838 | - : ''; |
|
| 839 | - $datetime_link = ! empty($datetime_link) |
|
| 840 | - ? '<a href="' . $datetime_link . '">' |
|
| 841 | - . '<span id="checkin-dtt">' |
|
| 842 | - . $datetime_label |
|
| 843 | - . '</span></a>' |
|
| 844 | - : $datetime_label; |
|
| 845 | - $attendee_name = $attendee instanceof EE_Attendee |
|
| 846 | - ? $attendee->full_name() |
|
| 847 | - : ''; |
|
| 848 | - $attendee_link = $attendee instanceof EE_Attendee |
|
| 849 | - ? $attendee->get_admin_details_link() |
|
| 850 | - : ''; |
|
| 851 | - $attendee_link = ! empty($attendee_link) |
|
| 852 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
| 853 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
| 854 | - . '<span id="checkin-attendee-name">' |
|
| 855 | - . $attendee_name |
|
| 856 | - . '</span></a>' |
|
| 857 | - : ''; |
|
| 858 | - $event_link = $registration->event() instanceof EE_Event |
|
| 859 | - ? $registration->event()->get_admin_details_link() |
|
| 860 | - : ''; |
|
| 861 | - $event_link = ! empty($event_link) |
|
| 862 | - ? '<a href="' . $event_link . '"' |
|
| 863 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
| 864 | - . '<span id="checkin-event-name">' |
|
| 865 | - . $registration->event_name() |
|
| 866 | - . '</span>' |
|
| 867 | - . '</a>' |
|
| 868 | - : ''; |
|
| 869 | - $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
| 870 | - ? '<h2>' . sprintf( |
|
| 871 | - esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
| 872 | - $attendee_link, |
|
| 873 | - $datetime_link, |
|
| 874 | - $event_link |
|
| 875 | - ) . '</h2>' |
|
| 876 | - : ''; |
|
| 877 | - $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
| 878 | - ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
| 879 | - $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
| 880 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 881 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 882 | - } |
|
| 782 | + /** |
|
| 783 | + * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
| 784 | + * |
|
| 785 | + * @access protected |
|
| 786 | + * @return void |
|
| 787 | + * @throws EE_Error |
|
| 788 | + * @throws InvalidArgumentException |
|
| 789 | + * @throws InvalidDataTypeException |
|
| 790 | + * @throws InvalidInterfaceException |
|
| 791 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 792 | + */ |
|
| 793 | + protected function _registration_checkin_list_table() |
|
| 794 | + { |
|
| 795 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 796 | + $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null; |
|
| 797 | + /** @var EE_Registration $registration */ |
|
| 798 | + $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
| 799 | + $attendee = $registration->attendee(); |
|
| 800 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 801 | + 'new_registration', |
|
| 802 | + 'add-registrant', |
|
| 803 | + array('event_id' => $registration->event_ID()), |
|
| 804 | + 'add-new-h2' |
|
| 805 | + ); |
|
| 806 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 807 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 808 | + $legend_items = array( |
|
| 809 | + 'checkin' => array( |
|
| 810 | + 'class' => $checked_in->cssClasses(), |
|
| 811 | + 'desc' => $checked_in->legendLabel(), |
|
| 812 | + ), |
|
| 813 | + 'checkout' => array( |
|
| 814 | + 'class' => $checked_out->cssClasses(), |
|
| 815 | + 'desc' => $checked_out->legendLabel(), |
|
| 816 | + ), |
|
| 817 | + ); |
|
| 818 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 819 | + $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 820 | + /** @var EE_Datetime $datetime */ |
|
| 821 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
| 822 | + $datetime_label = ''; |
|
| 823 | + if ($datetime instanceof EE_Datetime) { |
|
| 824 | + $datetime_label = $datetime->get_dtt_display_name(true); |
|
| 825 | + $datetime_label .= ! empty($datetime_label) |
|
| 826 | + ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
| 827 | + : $datetime->get_dtt_display_name(); |
|
| 828 | + } |
|
| 829 | + $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
| 830 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 831 | + array( |
|
| 832 | + 'action' => 'event_registrations', |
|
| 833 | + 'event_id' => $registration->event_ID(), |
|
| 834 | + 'DTT_ID' => $dtt_id, |
|
| 835 | + ), |
|
| 836 | + $this->_admin_base_url |
|
| 837 | + ) |
|
| 838 | + : ''; |
|
| 839 | + $datetime_link = ! empty($datetime_link) |
|
| 840 | + ? '<a href="' . $datetime_link . '">' |
|
| 841 | + . '<span id="checkin-dtt">' |
|
| 842 | + . $datetime_label |
|
| 843 | + . '</span></a>' |
|
| 844 | + : $datetime_label; |
|
| 845 | + $attendee_name = $attendee instanceof EE_Attendee |
|
| 846 | + ? $attendee->full_name() |
|
| 847 | + : ''; |
|
| 848 | + $attendee_link = $attendee instanceof EE_Attendee |
|
| 849 | + ? $attendee->get_admin_details_link() |
|
| 850 | + : ''; |
|
| 851 | + $attendee_link = ! empty($attendee_link) |
|
| 852 | + ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
| 853 | + . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
| 854 | + . '<span id="checkin-attendee-name">' |
|
| 855 | + . $attendee_name |
|
| 856 | + . '</span></a>' |
|
| 857 | + : ''; |
|
| 858 | + $event_link = $registration->event() instanceof EE_Event |
|
| 859 | + ? $registration->event()->get_admin_details_link() |
|
| 860 | + : ''; |
|
| 861 | + $event_link = ! empty($event_link) |
|
| 862 | + ? '<a href="' . $event_link . '"' |
|
| 863 | + . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
| 864 | + . '<span id="checkin-event-name">' |
|
| 865 | + . $registration->event_name() |
|
| 866 | + . '</span>' |
|
| 867 | + . '</a>' |
|
| 868 | + : ''; |
|
| 869 | + $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
| 870 | + ? '<h2>' . sprintf( |
|
| 871 | + esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
| 872 | + $attendee_link, |
|
| 873 | + $datetime_link, |
|
| 874 | + $event_link |
|
| 875 | + ) . '</h2>' |
|
| 876 | + : ''; |
|
| 877 | + $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
| 878 | + ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
| 879 | + $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
| 880 | + ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 881 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 882 | + } |
|
| 883 | 883 | |
| 884 | 884 | |
| 885 | - /** |
|
| 886 | - * toggle the Check-in status for the given registration (coming from ajax) |
|
| 887 | - * |
|
| 888 | - * @return void (JSON) |
|
| 889 | - * @throws EE_Error |
|
| 890 | - * @throws InvalidArgumentException |
|
| 891 | - * @throws InvalidDataTypeException |
|
| 892 | - * @throws InvalidInterfaceException |
|
| 893 | - */ |
|
| 894 | - public function toggle_checkin_status() |
|
| 895 | - { |
|
| 896 | - // first make sure we have the necessary data |
|
| 897 | - if (! isset($this->_req_data['_regid'])) { |
|
| 898 | - EE_Error::add_error( |
|
| 899 | - esc_html__( |
|
| 900 | - 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
| 901 | - 'event_espresso' |
|
| 902 | - ), |
|
| 903 | - __FILE__, |
|
| 904 | - __FUNCTION__, |
|
| 905 | - __LINE__ |
|
| 906 | - ); |
|
| 907 | - $this->_template_args['success'] = false; |
|
| 908 | - $this->_template_args['error'] = true; |
|
| 909 | - $this->_return_json(); |
|
| 910 | - }; |
|
| 911 | - // do a nonce check cause we're not coming in from an normal route here. |
|
| 912 | - $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
| 913 | - : ''; |
|
| 914 | - $nonce_ref = 'checkin_nonce'; |
|
| 915 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 916 | - // beautiful! Made it this far so let's get the status. |
|
| 917 | - $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
| 918 | - // setup new class to return via ajax |
|
| 919 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
| 920 | - $this->_template_args['success'] = true; |
|
| 921 | - $this->_return_json(); |
|
| 922 | - } |
|
| 885 | + /** |
|
| 886 | + * toggle the Check-in status for the given registration (coming from ajax) |
|
| 887 | + * |
|
| 888 | + * @return void (JSON) |
|
| 889 | + * @throws EE_Error |
|
| 890 | + * @throws InvalidArgumentException |
|
| 891 | + * @throws InvalidDataTypeException |
|
| 892 | + * @throws InvalidInterfaceException |
|
| 893 | + */ |
|
| 894 | + public function toggle_checkin_status() |
|
| 895 | + { |
|
| 896 | + // first make sure we have the necessary data |
|
| 897 | + if (! isset($this->_req_data['_regid'])) { |
|
| 898 | + EE_Error::add_error( |
|
| 899 | + esc_html__( |
|
| 900 | + 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
| 901 | + 'event_espresso' |
|
| 902 | + ), |
|
| 903 | + __FILE__, |
|
| 904 | + __FUNCTION__, |
|
| 905 | + __LINE__ |
|
| 906 | + ); |
|
| 907 | + $this->_template_args['success'] = false; |
|
| 908 | + $this->_template_args['error'] = true; |
|
| 909 | + $this->_return_json(); |
|
| 910 | + }; |
|
| 911 | + // do a nonce check cause we're not coming in from an normal route here. |
|
| 912 | + $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
| 913 | + : ''; |
|
| 914 | + $nonce_ref = 'checkin_nonce'; |
|
| 915 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 916 | + // beautiful! Made it this far so let's get the status. |
|
| 917 | + $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
| 918 | + // setup new class to return via ajax |
|
| 919 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
| 920 | + $this->_template_args['success'] = true; |
|
| 921 | + $this->_return_json(); |
|
| 922 | + } |
|
| 923 | 923 | |
| 924 | 924 | |
| 925 | - /** |
|
| 926 | - * handles toggling the checkin status for the registration, |
|
| 927 | - * |
|
| 928 | - * @access protected |
|
| 929 | - * @return int|void |
|
| 930 | - * @throws EE_Error |
|
| 931 | - * @throws InvalidArgumentException |
|
| 932 | - * @throws InvalidDataTypeException |
|
| 933 | - * @throws InvalidInterfaceException |
|
| 934 | - */ |
|
| 935 | - protected function _toggle_checkin_status() |
|
| 936 | - { |
|
| 937 | - // first let's get the query args out of the way for the redirect |
|
| 938 | - $query_args = array( |
|
| 939 | - 'action' => 'event_registrations', |
|
| 940 | - 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 941 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
| 942 | - ); |
|
| 943 | - $new_status = false; |
|
| 944 | - // bulk action check in toggle |
|
| 945 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 946 | - // cycle thru checkboxes |
|
| 947 | - while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 948 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 949 | - $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
| 950 | - } |
|
| 951 | - } elseif (isset($this->_req_data['_regid'])) { |
|
| 952 | - // coming from ajax request |
|
| 953 | - $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
| 954 | - $query_args['DTT_ID'] = $DTT_ID; |
|
| 955 | - $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
| 956 | - } else { |
|
| 957 | - EE_Error::add_error( |
|
| 958 | - esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
| 959 | - __FILE__, |
|
| 960 | - __FUNCTION__, |
|
| 961 | - __LINE__ |
|
| 962 | - ); |
|
| 963 | - } |
|
| 964 | - if (defined('DOING_AJAX')) { |
|
| 965 | - return $new_status; |
|
| 966 | - } |
|
| 967 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 968 | - } |
|
| 925 | + /** |
|
| 926 | + * handles toggling the checkin status for the registration, |
|
| 927 | + * |
|
| 928 | + * @access protected |
|
| 929 | + * @return int|void |
|
| 930 | + * @throws EE_Error |
|
| 931 | + * @throws InvalidArgumentException |
|
| 932 | + * @throws InvalidDataTypeException |
|
| 933 | + * @throws InvalidInterfaceException |
|
| 934 | + */ |
|
| 935 | + protected function _toggle_checkin_status() |
|
| 936 | + { |
|
| 937 | + // first let's get the query args out of the way for the redirect |
|
| 938 | + $query_args = array( |
|
| 939 | + 'action' => 'event_registrations', |
|
| 940 | + 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 941 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
| 942 | + ); |
|
| 943 | + $new_status = false; |
|
| 944 | + // bulk action check in toggle |
|
| 945 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 946 | + // cycle thru checkboxes |
|
| 947 | + while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 948 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 949 | + $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
| 950 | + } |
|
| 951 | + } elseif (isset($this->_req_data['_regid'])) { |
|
| 952 | + // coming from ajax request |
|
| 953 | + $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
| 954 | + $query_args['DTT_ID'] = $DTT_ID; |
|
| 955 | + $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
| 956 | + } else { |
|
| 957 | + EE_Error::add_error( |
|
| 958 | + esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
| 959 | + __FILE__, |
|
| 960 | + __FUNCTION__, |
|
| 961 | + __LINE__ |
|
| 962 | + ); |
|
| 963 | + } |
|
| 964 | + if (defined('DOING_AJAX')) { |
|
| 965 | + return $new_status; |
|
| 966 | + } |
|
| 967 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 968 | + } |
|
| 969 | 969 | |
| 970 | 970 | |
| 971 | - /** |
|
| 972 | - * This is toggles a single Check-in for the given registration and datetime. |
|
| 973 | - * |
|
| 974 | - * @param int $REG_ID The registration we're toggling |
|
| 975 | - * @param int $DTT_ID The datetime we're toggling |
|
| 976 | - * @return int The new status toggled to. |
|
| 977 | - * @throws EE_Error |
|
| 978 | - * @throws InvalidArgumentException |
|
| 979 | - * @throws InvalidDataTypeException |
|
| 980 | - * @throws InvalidInterfaceException |
|
| 981 | - */ |
|
| 982 | - private function _toggle_checkin($REG_ID, $DTT_ID) |
|
| 983 | - { |
|
| 984 | - /** @var EE_Registration $REG */ |
|
| 985 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 986 | - $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
| 987 | - if ($new_status !== false) { |
|
| 988 | - EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
| 989 | - } else { |
|
| 990 | - EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
| 991 | - $new_status = false; |
|
| 992 | - } |
|
| 993 | - return $new_status; |
|
| 994 | - } |
|
| 971 | + /** |
|
| 972 | + * This is toggles a single Check-in for the given registration and datetime. |
|
| 973 | + * |
|
| 974 | + * @param int $REG_ID The registration we're toggling |
|
| 975 | + * @param int $DTT_ID The datetime we're toggling |
|
| 976 | + * @return int The new status toggled to. |
|
| 977 | + * @throws EE_Error |
|
| 978 | + * @throws InvalidArgumentException |
|
| 979 | + * @throws InvalidDataTypeException |
|
| 980 | + * @throws InvalidInterfaceException |
|
| 981 | + */ |
|
| 982 | + private function _toggle_checkin($REG_ID, $DTT_ID) |
|
| 983 | + { |
|
| 984 | + /** @var EE_Registration $REG */ |
|
| 985 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 986 | + $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
| 987 | + if ($new_status !== false) { |
|
| 988 | + EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
| 989 | + } else { |
|
| 990 | + EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
| 991 | + $new_status = false; |
|
| 992 | + } |
|
| 993 | + return $new_status; |
|
| 994 | + } |
|
| 995 | 995 | |
| 996 | 996 | |
| 997 | - /** |
|
| 998 | - * Takes care of deleting multiple EE_Checkin table rows |
|
| 999 | - * |
|
| 1000 | - * @access protected |
|
| 1001 | - * @return void |
|
| 1002 | - * @throws EE_Error |
|
| 1003 | - * @throws InvalidArgumentException |
|
| 1004 | - * @throws InvalidDataTypeException |
|
| 1005 | - * @throws InvalidInterfaceException |
|
| 1006 | - */ |
|
| 1007 | - protected function _delete_checkin_rows() |
|
| 1008 | - { |
|
| 1009 | - $query_args = array( |
|
| 1010 | - 'action' => 'registration_checkins', |
|
| 1011 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1012 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1013 | - ); |
|
| 1014 | - $errors = 0; |
|
| 1015 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1016 | - while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1017 | - if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1018 | - $errors++; |
|
| 1019 | - } |
|
| 1020 | - } |
|
| 1021 | - } else { |
|
| 1022 | - EE_Error::add_error( |
|
| 1023 | - esc_html__( |
|
| 1024 | - 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
| 1025 | - 'event_espresso' |
|
| 1026 | - ), |
|
| 1027 | - __FILE__, |
|
| 1028 | - __FUNCTION__, |
|
| 1029 | - __LINE__ |
|
| 1030 | - ); |
|
| 1031 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1032 | - } |
|
| 1033 | - if ($errors > 0) { |
|
| 1034 | - EE_Error::add_error( |
|
| 1035 | - sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
| 1036 | - __FILE__, |
|
| 1037 | - __FUNCTION__, |
|
| 1038 | - __LINE__ |
|
| 1039 | - ); |
|
| 1040 | - } else { |
|
| 1041 | - EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
| 1042 | - } |
|
| 1043 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1044 | - } |
|
| 997 | + /** |
|
| 998 | + * Takes care of deleting multiple EE_Checkin table rows |
|
| 999 | + * |
|
| 1000 | + * @access protected |
|
| 1001 | + * @return void |
|
| 1002 | + * @throws EE_Error |
|
| 1003 | + * @throws InvalidArgumentException |
|
| 1004 | + * @throws InvalidDataTypeException |
|
| 1005 | + * @throws InvalidInterfaceException |
|
| 1006 | + */ |
|
| 1007 | + protected function _delete_checkin_rows() |
|
| 1008 | + { |
|
| 1009 | + $query_args = array( |
|
| 1010 | + 'action' => 'registration_checkins', |
|
| 1011 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1012 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1013 | + ); |
|
| 1014 | + $errors = 0; |
|
| 1015 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1016 | + while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1017 | + if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1018 | + $errors++; |
|
| 1019 | + } |
|
| 1020 | + } |
|
| 1021 | + } else { |
|
| 1022 | + EE_Error::add_error( |
|
| 1023 | + esc_html__( |
|
| 1024 | + 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
| 1025 | + 'event_espresso' |
|
| 1026 | + ), |
|
| 1027 | + __FILE__, |
|
| 1028 | + __FUNCTION__, |
|
| 1029 | + __LINE__ |
|
| 1030 | + ); |
|
| 1031 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1032 | + } |
|
| 1033 | + if ($errors > 0) { |
|
| 1034 | + EE_Error::add_error( |
|
| 1035 | + sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
| 1036 | + __FILE__, |
|
| 1037 | + __FUNCTION__, |
|
| 1038 | + __LINE__ |
|
| 1039 | + ); |
|
| 1040 | + } else { |
|
| 1041 | + EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
| 1042 | + } |
|
| 1043 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1044 | + } |
|
| 1045 | 1045 | |
| 1046 | 1046 | |
| 1047 | - /** |
|
| 1048 | - * Deletes a single EE_Checkin row |
|
| 1049 | - * |
|
| 1050 | - * @return void |
|
| 1051 | - * @throws EE_Error |
|
| 1052 | - * @throws InvalidArgumentException |
|
| 1053 | - * @throws InvalidDataTypeException |
|
| 1054 | - * @throws InvalidInterfaceException |
|
| 1055 | - */ |
|
| 1056 | - protected function _delete_checkin_row() |
|
| 1057 | - { |
|
| 1058 | - $query_args = array( |
|
| 1059 | - 'action' => 'registration_checkins', |
|
| 1060 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1061 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1062 | - ); |
|
| 1063 | - if (! empty($this->_req_data['CHK_ID'])) { |
|
| 1064 | - if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1065 | - EE_Error::add_error( |
|
| 1066 | - esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
| 1067 | - __FILE__, |
|
| 1068 | - __FUNCTION__, |
|
| 1069 | - __LINE__ |
|
| 1070 | - ); |
|
| 1071 | - } else { |
|
| 1072 | - EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
| 1073 | - } |
|
| 1074 | - } else { |
|
| 1075 | - EE_Error::add_error( |
|
| 1076 | - esc_html__( |
|
| 1077 | - 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
| 1078 | - 'event_espresso' |
|
| 1079 | - ), |
|
| 1080 | - __FILE__, |
|
| 1081 | - __FUNCTION__, |
|
| 1082 | - __LINE__ |
|
| 1083 | - ); |
|
| 1084 | - } |
|
| 1085 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1086 | - } |
|
| 1047 | + /** |
|
| 1048 | + * Deletes a single EE_Checkin row |
|
| 1049 | + * |
|
| 1050 | + * @return void |
|
| 1051 | + * @throws EE_Error |
|
| 1052 | + * @throws InvalidArgumentException |
|
| 1053 | + * @throws InvalidDataTypeException |
|
| 1054 | + * @throws InvalidInterfaceException |
|
| 1055 | + */ |
|
| 1056 | + protected function _delete_checkin_row() |
|
| 1057 | + { |
|
| 1058 | + $query_args = array( |
|
| 1059 | + 'action' => 'registration_checkins', |
|
| 1060 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1061 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1062 | + ); |
|
| 1063 | + if (! empty($this->_req_data['CHK_ID'])) { |
|
| 1064 | + if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1065 | + EE_Error::add_error( |
|
| 1066 | + esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
| 1067 | + __FILE__, |
|
| 1068 | + __FUNCTION__, |
|
| 1069 | + __LINE__ |
|
| 1070 | + ); |
|
| 1071 | + } else { |
|
| 1072 | + EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
| 1073 | + } |
|
| 1074 | + } else { |
|
| 1075 | + EE_Error::add_error( |
|
| 1076 | + esc_html__( |
|
| 1077 | + 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
| 1078 | + 'event_espresso' |
|
| 1079 | + ), |
|
| 1080 | + __FILE__, |
|
| 1081 | + __FUNCTION__, |
|
| 1082 | + __LINE__ |
|
| 1083 | + ); |
|
| 1084 | + } |
|
| 1085 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1086 | + } |
|
| 1087 | 1087 | |
| 1088 | 1088 | |
| 1089 | - /** |
|
| 1090 | - * generates HTML for the Event Registrations List Table |
|
| 1091 | - * |
|
| 1092 | - * @access protected |
|
| 1093 | - * @return void |
|
| 1094 | - * @throws EE_Error |
|
| 1095 | - * @throws InvalidArgumentException |
|
| 1096 | - * @throws InvalidDataTypeException |
|
| 1097 | - * @throws InvalidInterfaceException |
|
| 1098 | - */ |
|
| 1099 | - protected function _event_registrations_list_table() |
|
| 1100 | - { |
|
| 1101 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1102 | - $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
| 1103 | - ? $this->get_action_link_or_button( |
|
| 1104 | - 'new_registration', |
|
| 1105 | - 'add-registrant', |
|
| 1106 | - array('event_id' => $this->_req_data['event_id']), |
|
| 1107 | - 'add-new-h2', |
|
| 1108 | - '', |
|
| 1109 | - false |
|
| 1110 | - ) |
|
| 1111 | - : ''; |
|
| 1112 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 1113 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 1114 | - $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
| 1115 | - $legend_items = array( |
|
| 1116 | - 'star-icon' => array( |
|
| 1117 | - 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 1118 | - 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
| 1119 | - ), |
|
| 1120 | - 'checkin' => array( |
|
| 1121 | - 'class' => $checked_in->cssClasses(), |
|
| 1122 | - 'desc' => $checked_in->legendLabel(), |
|
| 1123 | - ), |
|
| 1124 | - 'checkout' => array( |
|
| 1125 | - 'class' => $checked_out->cssClasses(), |
|
| 1126 | - 'desc' => $checked_out->legendLabel(), |
|
| 1127 | - ), |
|
| 1128 | - 'nocheckinrecord' => array( |
|
| 1129 | - 'class' => $checked_never->cssClasses(), |
|
| 1130 | - 'desc' => $checked_never->legendLabel(), |
|
| 1131 | - ), |
|
| 1132 | - 'approved_status' => array( |
|
| 1133 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 1134 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 1135 | - ), |
|
| 1136 | - 'cancelled_status' => array( |
|
| 1137 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1138 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 1139 | - ), |
|
| 1140 | - 'declined_status' => array( |
|
| 1141 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 1142 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 1143 | - ), |
|
| 1144 | - 'not_approved' => array( |
|
| 1145 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 1146 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 1147 | - ), |
|
| 1148 | - 'pending_status' => array( |
|
| 1149 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 1150 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 1151 | - ), |
|
| 1152 | - 'wait_list' => array( |
|
| 1153 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 1154 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 1155 | - ), |
|
| 1156 | - ); |
|
| 1157 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 1158 | - $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 1159 | - /** @var EE_Event $event */ |
|
| 1160 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 1161 | - $this->_template_args['before_list_table'] = $event instanceof EE_Event |
|
| 1162 | - ? '<h2>' . sprintf( |
|
| 1163 | - esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
| 1164 | - EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
| 1165 | - ) . '</h2>' |
|
| 1166 | - : ''; |
|
| 1167 | - // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
| 1168 | - // the event. |
|
| 1169 | - $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
| 1170 | - $datetime = null; |
|
| 1171 | - if ($event instanceof EE_Event) { |
|
| 1172 | - $datetimes_on_event = $event->datetimes(); |
|
| 1173 | - if (count($datetimes_on_event) === 1) { |
|
| 1174 | - $datetime = reset($datetimes_on_event); |
|
| 1175 | - } |
|
| 1176 | - } |
|
| 1177 | - $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1178 | - if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
| 1179 | - $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
| 1180 | - $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
| 1181 | - $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1182 | - $this->_template_args['before_list_table'] .= $datetime->name(); |
|
| 1183 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1184 | - $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
| 1185 | - } |
|
| 1186 | - // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
| 1187 | - // column represents |
|
| 1188 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1189 | - $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
| 1190 | - . esc_html__( |
|
| 1191 | - 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
| 1192 | - 'event_espresso' |
|
| 1193 | - ) |
|
| 1194 | - . '</p>'; |
|
| 1195 | - } |
|
| 1196 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1197 | - } |
|
| 1089 | + /** |
|
| 1090 | + * generates HTML for the Event Registrations List Table |
|
| 1091 | + * |
|
| 1092 | + * @access protected |
|
| 1093 | + * @return void |
|
| 1094 | + * @throws EE_Error |
|
| 1095 | + * @throws InvalidArgumentException |
|
| 1096 | + * @throws InvalidDataTypeException |
|
| 1097 | + * @throws InvalidInterfaceException |
|
| 1098 | + */ |
|
| 1099 | + protected function _event_registrations_list_table() |
|
| 1100 | + { |
|
| 1101 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1102 | + $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
| 1103 | + ? $this->get_action_link_or_button( |
|
| 1104 | + 'new_registration', |
|
| 1105 | + 'add-registrant', |
|
| 1106 | + array('event_id' => $this->_req_data['event_id']), |
|
| 1107 | + 'add-new-h2', |
|
| 1108 | + '', |
|
| 1109 | + false |
|
| 1110 | + ) |
|
| 1111 | + : ''; |
|
| 1112 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 1113 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 1114 | + $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
| 1115 | + $legend_items = array( |
|
| 1116 | + 'star-icon' => array( |
|
| 1117 | + 'class' => 'dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8', |
|
| 1118 | + 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
| 1119 | + ), |
|
| 1120 | + 'checkin' => array( |
|
| 1121 | + 'class' => $checked_in->cssClasses(), |
|
| 1122 | + 'desc' => $checked_in->legendLabel(), |
|
| 1123 | + ), |
|
| 1124 | + 'checkout' => array( |
|
| 1125 | + 'class' => $checked_out->cssClasses(), |
|
| 1126 | + 'desc' => $checked_out->legendLabel(), |
|
| 1127 | + ), |
|
| 1128 | + 'nocheckinrecord' => array( |
|
| 1129 | + 'class' => $checked_never->cssClasses(), |
|
| 1130 | + 'desc' => $checked_never->legendLabel(), |
|
| 1131 | + ), |
|
| 1132 | + 'approved_status' => array( |
|
| 1133 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 1134 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 1135 | + ), |
|
| 1136 | + 'cancelled_status' => array( |
|
| 1137 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1138 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 1139 | + ), |
|
| 1140 | + 'declined_status' => array( |
|
| 1141 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 1142 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 1143 | + ), |
|
| 1144 | + 'not_approved' => array( |
|
| 1145 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 1146 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 1147 | + ), |
|
| 1148 | + 'pending_status' => array( |
|
| 1149 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 1150 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 1151 | + ), |
|
| 1152 | + 'wait_list' => array( |
|
| 1153 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 1154 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 1155 | + ), |
|
| 1156 | + ); |
|
| 1157 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 1158 | + $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 1159 | + /** @var EE_Event $event */ |
|
| 1160 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 1161 | + $this->_template_args['before_list_table'] = $event instanceof EE_Event |
|
| 1162 | + ? '<h2>' . sprintf( |
|
| 1163 | + esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
| 1164 | + EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
| 1165 | + ) . '</h2>' |
|
| 1166 | + : ''; |
|
| 1167 | + // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
| 1168 | + // the event. |
|
| 1169 | + $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
| 1170 | + $datetime = null; |
|
| 1171 | + if ($event instanceof EE_Event) { |
|
| 1172 | + $datetimes_on_event = $event->datetimes(); |
|
| 1173 | + if (count($datetimes_on_event) === 1) { |
|
| 1174 | + $datetime = reset($datetimes_on_event); |
|
| 1175 | + } |
|
| 1176 | + } |
|
| 1177 | + $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1178 | + if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
| 1179 | + $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
| 1180 | + $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
| 1181 | + $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1182 | + $this->_template_args['before_list_table'] .= $datetime->name(); |
|
| 1183 | + $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1184 | + $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
| 1185 | + } |
|
| 1186 | + // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
| 1187 | + // column represents |
|
| 1188 | + if (! $datetime instanceof EE_Datetime) { |
|
| 1189 | + $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
| 1190 | + . esc_html__( |
|
| 1191 | + 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
| 1192 | + 'event_espresso' |
|
| 1193 | + ) |
|
| 1194 | + . '</p>'; |
|
| 1195 | + } |
|
| 1196 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1197 | + } |
|
| 1198 | 1198 | |
| 1199 | - /** |
|
| 1200 | - * Download the registrations check-in report (same as the normal registration report, but with different where |
|
| 1201 | - * conditions) |
|
| 1202 | - * |
|
| 1203 | - * @return void ends the request by a redirect or download |
|
| 1204 | - */ |
|
| 1205 | - public function _registrations_checkin_report() |
|
| 1206 | - { |
|
| 1207 | - $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
| 1208 | - } |
|
| 1199 | + /** |
|
| 1200 | + * Download the registrations check-in report (same as the normal registration report, but with different where |
|
| 1201 | + * conditions) |
|
| 1202 | + * |
|
| 1203 | + * @return void ends the request by a redirect or download |
|
| 1204 | + */ |
|
| 1205 | + public function _registrations_checkin_report() |
|
| 1206 | + { |
|
| 1207 | + $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
| 1208 | + } |
|
| 1209 | 1209 | |
| 1210 | - /** |
|
| 1211 | - * Gets the query params from the request, plus adds a where condition for the registration status, |
|
| 1212 | - * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
| 1213 | - * |
|
| 1214 | - * @param array $request |
|
| 1215 | - * @param int $per_page |
|
| 1216 | - * @param bool $count |
|
| 1217 | - * @return array |
|
| 1218 | - * @throws EE_Error |
|
| 1219 | - */ |
|
| 1220 | - protected function _get_checkin_query_params_from_request( |
|
| 1221 | - $request, |
|
| 1222 | - $per_page = 10, |
|
| 1223 | - $count = false |
|
| 1224 | - ) { |
|
| 1225 | - $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
| 1226 | - // unlike the regular registrations list table, |
|
| 1227 | - $status_ids_array = apply_filters( |
|
| 1228 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
| 1229 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
| 1230 | - ); |
|
| 1231 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
| 1232 | - return $query_params; |
|
| 1233 | - } |
|
| 1210 | + /** |
|
| 1211 | + * Gets the query params from the request, plus adds a where condition for the registration status, |
|
| 1212 | + * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
| 1213 | + * |
|
| 1214 | + * @param array $request |
|
| 1215 | + * @param int $per_page |
|
| 1216 | + * @param bool $count |
|
| 1217 | + * @return array |
|
| 1218 | + * @throws EE_Error |
|
| 1219 | + */ |
|
| 1220 | + protected function _get_checkin_query_params_from_request( |
|
| 1221 | + $request, |
|
| 1222 | + $per_page = 10, |
|
| 1223 | + $count = false |
|
| 1224 | + ) { |
|
| 1225 | + $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
| 1226 | + // unlike the regular registrations list table, |
|
| 1227 | + $status_ids_array = apply_filters( |
|
| 1228 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
| 1229 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
| 1230 | + ); |
|
| 1231 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
| 1232 | + return $query_params; |
|
| 1233 | + } |
|
| 1234 | 1234 | |
| 1235 | 1235 | |
| 1236 | - /** |
|
| 1237 | - * Gets registrations for an event |
|
| 1238 | - * |
|
| 1239 | - * @param int $per_page |
|
| 1240 | - * @param bool $count whether to return count or data. |
|
| 1241 | - * @param bool $trash |
|
| 1242 | - * @param string $orderby |
|
| 1243 | - * @return EE_Registration[]|int |
|
| 1244 | - * @throws EE_Error |
|
| 1245 | - * @throws InvalidArgumentException |
|
| 1246 | - * @throws InvalidDataTypeException |
|
| 1247 | - * @throws InvalidInterfaceException |
|
| 1248 | - */ |
|
| 1249 | - public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
| 1250 | - { |
|
| 1251 | - // normalize some request params that get setup by the parent `get_registrations` method. |
|
| 1252 | - $request = $this->_req_data; |
|
| 1253 | - $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
| 1254 | - $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 1255 | - if ($trash) { |
|
| 1256 | - $request['status'] = 'trash'; |
|
| 1257 | - } |
|
| 1258 | - $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
| 1259 | - /** |
|
| 1260 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1261 | - * |
|
| 1262 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1263 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1264 | - * or if you have the development copy of EE you can view this at the path: |
|
| 1265 | - * /docs/G--Model-System/model-query-params.md |
|
| 1266 | - */ |
|
| 1267 | - $query_params['group_by'] = ''; |
|
| 1236 | + /** |
|
| 1237 | + * Gets registrations for an event |
|
| 1238 | + * |
|
| 1239 | + * @param int $per_page |
|
| 1240 | + * @param bool $count whether to return count or data. |
|
| 1241 | + * @param bool $trash |
|
| 1242 | + * @param string $orderby |
|
| 1243 | + * @return EE_Registration[]|int |
|
| 1244 | + * @throws EE_Error |
|
| 1245 | + * @throws InvalidArgumentException |
|
| 1246 | + * @throws InvalidDataTypeException |
|
| 1247 | + * @throws InvalidInterfaceException |
|
| 1248 | + */ |
|
| 1249 | + public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
| 1250 | + { |
|
| 1251 | + // normalize some request params that get setup by the parent `get_registrations` method. |
|
| 1252 | + $request = $this->_req_data; |
|
| 1253 | + $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
| 1254 | + $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 1255 | + if ($trash) { |
|
| 1256 | + $request['status'] = 'trash'; |
|
| 1257 | + } |
|
| 1258 | + $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
| 1259 | + /** |
|
| 1260 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1261 | + * |
|
| 1262 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1263 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1264 | + * or if you have the development copy of EE you can view this at the path: |
|
| 1265 | + * /docs/G--Model-System/model-query-params.md |
|
| 1266 | + */ |
|
| 1267 | + $query_params['group_by'] = ''; |
|
| 1268 | 1268 | |
| 1269 | - return $count |
|
| 1270 | - ? EEM_Registration::instance()->count($query_params) |
|
| 1271 | - /** @type EE_Registration[] */ |
|
| 1272 | - : EEM_Registration::instance()->get_all($query_params); |
|
| 1273 | - } |
|
| 1269 | + return $count |
|
| 1270 | + ? EEM_Registration::instance()->count($query_params) |
|
| 1271 | + /** @type EE_Registration[] */ |
|
| 1272 | + : EEM_Registration::instance()->get_all($query_params); |
|
| 1273 | + } |
|
| 1274 | 1274 | } |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | public function __construct($routing = true) |
| 33 | 33 | { |
| 34 | 34 | parent::__construct($routing); |
| 35 | - if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 37 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 38 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 35 | + if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/'); |
|
| 37 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/'); |
|
| 38 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/'); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | protected function _extend_page_config() |
| 47 | 47 | { |
| 48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations'; |
|
| 49 | 49 | $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
| 50 | 50 | ? $this->_req_data['_REG_ID'] |
| 51 | 51 | : 0; |
@@ -185,14 +185,14 @@ discard block |
||
| 185 | 185 | // enqueue newsletter js |
| 186 | 186 | wp_enqueue_script( |
| 187 | 187 | 'ee-newsletter-trigger', |
| 188 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 188 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js', |
|
| 189 | 189 | array('ee-dialog'), |
| 190 | 190 | EVENT_ESPRESSO_VERSION, |
| 191 | 191 | true |
| 192 | 192 | ); |
| 193 | 193 | wp_enqueue_style( |
| 194 | 194 | 'ee-newsletter-trigger-css', |
| 195 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 195 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css', |
|
| 196 | 196 | array(), |
| 197 | 197 | EVENT_ESPRESSO_VERSION |
| 198 | 198 | ); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | { |
| 214 | 214 | wp_register_script( |
| 215 | 215 | 'ee-reg-reports-js', |
| 216 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 216 | + REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js', |
|
| 217 | 217 | array('google-charts'), |
| 218 | 218 | EVENT_ESPRESSO_VERSION, |
| 219 | 219 | true |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | $nonce_ref = 'get_newsletter_form_content_nonce'; |
| 300 | 300 | $this->_verify_nonce($nonce, $nonce_ref); |
| 301 | 301 | // let's get the mtp for the incoming MTP_ ID |
| 302 | - if (! isset($this->_req_data['GRP_ID'])) { |
|
| 302 | + if ( ! isset($this->_req_data['GRP_ID'])) { |
|
| 303 | 303 | EE_Error::add_error( |
| 304 | 304 | esc_html__( |
| 305 | 305 | 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | $this->_return_json(); |
| 315 | 315 | } |
| 316 | 316 | $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
| 317 | - if (! $MTPG instanceof EE_Message_Template_Group) { |
|
| 317 | + if ( ! $MTPG instanceof EE_Message_Template_Group) { |
|
| 318 | 318 | EE_Error::add_error( |
| 319 | 319 | sprintf( |
| 320 | 320 | esc_html__( |
@@ -339,12 +339,12 @@ discard block |
||
| 339 | 339 | $field = $MTP->get('MTP_template_field'); |
| 340 | 340 | if ($field === 'content') { |
| 341 | 341 | $content = $MTP->get('MTP_content'); |
| 342 | - if (! empty($content['newsletter_content'])) { |
|
| 342 | + if ( ! empty($content['newsletter_content'])) { |
|
| 343 | 343 | $template_fields['newsletter_content'] = $content['newsletter_content']; |
| 344 | 344 | } |
| 345 | 345 | continue; |
| 346 | 346 | } |
| 347 | - $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
| 347 | + $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content'); |
|
| 348 | 348 | } |
| 349 | 349 | $this->_template_args['success'] = true; |
| 350 | 350 | $this->_template_args['error'] = false; |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | */ |
| 376 | 376 | public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
| 377 | 377 | { |
| 378 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 378 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
| 379 | 379 | 'ee_send_message', |
| 380 | 380 | 'espresso_registrations_newsletter_selected_send' |
| 381 | 381 | ) |
@@ -444,17 +444,17 @@ discard block |
||
| 444 | 444 | $field_id = $field === '[NEWSLETTER_CONTENT]' |
| 445 | 445 | ? 'content' |
| 446 | 446 | : $field; |
| 447 | - $field_id = 'batch-message-' . strtolower($field_id); |
|
| 447 | + $field_id = 'batch-message-'.strtolower($field_id); |
|
| 448 | 448 | $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
| 449 | 449 | . $shortcode |
| 450 | - . '" data-linked-input-id="' . $field_id . '">' |
|
| 450 | + . '" data-linked-input-id="'.$field_id.'">' |
|
| 451 | 451 | . $shortcode |
| 452 | 452 | . '</span>'; |
| 453 | 453 | } |
| 454 | - $codes[ $field ] = implode(', ', $available_shortcodes); |
|
| 454 | + $codes[$field] = implode(', ', $available_shortcodes); |
|
| 455 | 455 | } |
| 456 | 456 | $shortcodes = $codes; |
| 457 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 457 | + $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php'; |
|
| 458 | 458 | $form_template_args = array( |
| 459 | 459 | 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
| 460 | 460 | 'form_route' => 'newsletter_selected_send', |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | */ |
| 623 | 623 | protected function _registration_reports() |
| 624 | 624 | { |
| 625 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 625 | + $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php'; |
|
| 626 | 626 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 627 | 627 | $template_path, |
| 628 | 628 | $this->_reports_template_data, |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | array_unshift($regs, $column_titles); |
| 678 | 678 | // setup the date range. |
| 679 | 679 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
| 680 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 680 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
| 681 | 681 | $ending_date = new DateTime("now", $DateTimeZone); |
| 682 | 682 | $subtitle = sprintf( |
| 683 | 683 | _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | '%sThere are currently no registration records in the last month for this report.%s', |
| 698 | 698 | 'event_espresso' |
| 699 | 699 | ), |
| 700 | - '<h2>' . $report_title . '</h2><p>', |
|
| 700 | + '<h2>'.$report_title.'</h2><p>', |
|
| 701 | 701 | '</p>' |
| 702 | 702 | ), |
| 703 | 703 | ); |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | array_unshift($regs, $column_titles); |
| 751 | 751 | // setup the date range. |
| 752 | 752 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
| 753 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 753 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
| 754 | 754 | $ending_date = new DateTime("now", $DateTimeZone); |
| 755 | 755 | $subtitle = sprintf( |
| 756 | 756 | _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | '%sThere are currently no registration records in the last month for this report.%s', |
| 771 | 771 | 'event_espresso' |
| 772 | 772 | ), |
| 773 | - '<h2>' . $report_title . '</h2><p>', |
|
| 773 | + '<h2>'.$report_title.'</h2><p>', |
|
| 774 | 774 | '</p>' |
| 775 | 775 | ), |
| 776 | 776 | ); |
@@ -823,7 +823,7 @@ discard block |
||
| 823 | 823 | if ($datetime instanceof EE_Datetime) { |
| 824 | 824 | $datetime_label = $datetime->get_dtt_display_name(true); |
| 825 | 825 | $datetime_label .= ! empty($datetime_label) |
| 826 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
| 826 | + ? ' ('.$datetime->get_dtt_display_name().')' |
|
| 827 | 827 | : $datetime->get_dtt_display_name(); |
| 828 | 828 | } |
| 829 | 829 | $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
@@ -837,7 +837,7 @@ discard block |
||
| 837 | 837 | ) |
| 838 | 838 | : ''; |
| 839 | 839 | $datetime_link = ! empty($datetime_link) |
| 840 | - ? '<a href="' . $datetime_link . '">' |
|
| 840 | + ? '<a href="'.$datetime_link.'">' |
|
| 841 | 841 | . '<span id="checkin-dtt">' |
| 842 | 842 | . $datetime_label |
| 843 | 843 | . '</span></a>' |
@@ -849,8 +849,8 @@ discard block |
||
| 849 | 849 | ? $attendee->get_admin_details_link() |
| 850 | 850 | : ''; |
| 851 | 851 | $attendee_link = ! empty($attendee_link) |
| 852 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
| 853 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
| 852 | + ? '<a href="'.$attendee->get_admin_details_link().'"' |
|
| 853 | + . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">' |
|
| 854 | 854 | . '<span id="checkin-attendee-name">' |
| 855 | 855 | . $attendee_name |
| 856 | 856 | . '</span></a>' |
@@ -859,25 +859,25 @@ discard block |
||
| 859 | 859 | ? $registration->event()->get_admin_details_link() |
| 860 | 860 | : ''; |
| 861 | 861 | $event_link = ! empty($event_link) |
| 862 | - ? '<a href="' . $event_link . '"' |
|
| 863 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
| 862 | + ? '<a href="'.$event_link.'"' |
|
| 863 | + . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">' |
|
| 864 | 864 | . '<span id="checkin-event-name">' |
| 865 | 865 | . $registration->event_name() |
| 866 | 866 | . '</span>' |
| 867 | 867 | . '</a>' |
| 868 | 868 | : ''; |
| 869 | 869 | $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
| 870 | - ? '<h2>' . sprintf( |
|
| 870 | + ? '<h2>'.sprintf( |
|
| 871 | 871 | esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
| 872 | 872 | $attendee_link, |
| 873 | 873 | $datetime_link, |
| 874 | 874 | $event_link |
| 875 | - ) . '</h2>' |
|
| 875 | + ).'</h2>' |
|
| 876 | 876 | : ''; |
| 877 | 877 | $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
| 878 | - ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
| 878 | + ? '<input type="hidden" name="_REG_ID" value="'.$reg_id.'">' : ''; |
|
| 879 | 879 | $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
| 880 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 880 | + ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : ''; |
|
| 881 | 881 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 882 | 882 | } |
| 883 | 883 | |
@@ -894,7 +894,7 @@ discard block |
||
| 894 | 894 | public function toggle_checkin_status() |
| 895 | 895 | { |
| 896 | 896 | // first make sure we have the necessary data |
| 897 | - if (! isset($this->_req_data['_regid'])) { |
|
| 897 | + if ( ! isset($this->_req_data['_regid'])) { |
|
| 898 | 898 | EE_Error::add_error( |
| 899 | 899 | esc_html__( |
| 900 | 900 | 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
@@ -916,7 +916,7 @@ discard block |
||
| 916 | 916 | // beautiful! Made it this far so let's get the status. |
| 917 | 917 | $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
| 918 | 918 | // setup new class to return via ajax |
| 919 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
| 919 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin '.$new_status->cssClasses(); |
|
| 920 | 920 | $this->_template_args['success'] = true; |
| 921 | 921 | $this->_return_json(); |
| 922 | 922 | } |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | ); |
| 943 | 943 | $new_status = false; |
| 944 | 944 | // bulk action check in toggle |
| 945 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 945 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 946 | 946 | // cycle thru checkboxes |
| 947 | 947 | while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
| 948 | 948 | $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
@@ -1012,9 +1012,9 @@ discard block |
||
| 1012 | 1012 | '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
| 1013 | 1013 | ); |
| 1014 | 1014 | $errors = 0; |
| 1015 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1015 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1016 | 1016 | while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
| 1017 | - if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1017 | + if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1018 | 1018 | $errors++; |
| 1019 | 1019 | } |
| 1020 | 1020 | } |
@@ -1060,8 +1060,8 @@ discard block |
||
| 1060 | 1060 | 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
| 1061 | 1061 | '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
| 1062 | 1062 | ); |
| 1063 | - if (! empty($this->_req_data['CHK_ID'])) { |
|
| 1064 | - if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1063 | + if ( ! empty($this->_req_data['CHK_ID'])) { |
|
| 1064 | + if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1065 | 1065 | EE_Error::add_error( |
| 1066 | 1066 | esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
| 1067 | 1067 | __FILE__, |
@@ -1130,27 +1130,27 @@ discard block |
||
| 1130 | 1130 | 'desc' => $checked_never->legendLabel(), |
| 1131 | 1131 | ), |
| 1132 | 1132 | 'approved_status' => array( |
| 1133 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 1133 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved, |
|
| 1134 | 1134 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
| 1135 | 1135 | ), |
| 1136 | 1136 | 'cancelled_status' => array( |
| 1137 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1137 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled, |
|
| 1138 | 1138 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
| 1139 | 1139 | ), |
| 1140 | 1140 | 'declined_status' => array( |
| 1141 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 1141 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined, |
|
| 1142 | 1142 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
| 1143 | 1143 | ), |
| 1144 | 1144 | 'not_approved' => array( |
| 1145 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 1145 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved, |
|
| 1146 | 1146 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
| 1147 | 1147 | ), |
| 1148 | 1148 | 'pending_status' => array( |
| 1149 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 1149 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment, |
|
| 1150 | 1150 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
| 1151 | 1151 | ), |
| 1152 | 1152 | 'wait_list' => array( |
| 1153 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 1153 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list, |
|
| 1154 | 1154 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
| 1155 | 1155 | ), |
| 1156 | 1156 | ); |
@@ -1159,10 +1159,10 @@ discard block |
||
| 1159 | 1159 | /** @var EE_Event $event */ |
| 1160 | 1160 | $event = EEM_Event::instance()->get_one_by_ID($event_id); |
| 1161 | 1161 | $this->_template_args['before_list_table'] = $event instanceof EE_Event |
| 1162 | - ? '<h2>' . sprintf( |
|
| 1162 | + ? '<h2>'.sprintf( |
|
| 1163 | 1163 | esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
| 1164 | 1164 | EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
| 1165 | - ) . '</h2>' |
|
| 1165 | + ).'</h2>' |
|
| 1166 | 1166 | : ''; |
| 1167 | 1167 | // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
| 1168 | 1168 | // the event. |
@@ -1180,12 +1180,12 @@ discard block |
||
| 1180 | 1180 | $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
| 1181 | 1181 | $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
| 1182 | 1182 | $this->_template_args['before_list_table'] .= $datetime->name(); |
| 1183 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1183 | + $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )'; |
|
| 1184 | 1184 | $this->_template_args['before_list_table'] .= '</span></h2>'; |
| 1185 | 1185 | } |
| 1186 | 1186 | // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
| 1187 | 1187 | // column represents |
| 1188 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1188 | + if ( ! $datetime instanceof EE_Datetime) { |
|
| 1189 | 1189 | $this->_template_args['before_list_table'] .= '<br><p class="description">' |
| 1190 | 1190 | . esc_html__( |
| 1191 | 1191 | 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
@@ -14,12 +14,12 @@ discard block |
||
| 14 | 14 | * @param int | \EE_Event $event |
| 15 | 15 | * @return bool |
| 16 | 16 | */ |
| 17 | -function is_espresso_event( $event = NULL ) { |
|
| 18 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 17 | +function is_espresso_event($event = NULL) { |
|
| 18 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 19 | 19 | // extract EE_Event object from passed param regardless of what it is (within reason of course) |
| 20 | - $event = EEH_Event_View::get_event( $event ); |
|
| 20 | + $event = EEH_Event_View::get_event($event); |
|
| 21 | 21 | // do we have a valid event ? |
| 22 | - return $event instanceof EE_Event ? TRUE : FALSE; |
|
| 22 | + return $event instanceof EE_Event ? TRUE : FALSE; |
|
| 23 | 23 | } |
| 24 | 24 | return FALSE; |
| 25 | 25 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @return bool |
| 32 | 32 | */ |
| 33 | 33 | function is_espresso_event_single() { |
| 34 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 34 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 35 | 35 | global $wp_query; |
| 36 | 36 | // return conditionals set by CPTs |
| 37 | 37 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_single : FALSE; |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * @return bool |
| 47 | 47 | */ |
| 48 | 48 | function is_espresso_event_archive() { |
| 49 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 49 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 50 | 50 | global $wp_query; |
| 51 | 51 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_archive : FALSE; |
| 52 | 52 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * @return bool |
| 61 | 61 | */ |
| 62 | 62 | function is_espresso_event_taxonomy() { |
| 63 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 63 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 64 | 64 | global $wp_query; |
| 65 | 65 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_taxonomy : FALSE; |
| 66 | 66 | } |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | * @param int | \EE_Venue $venue |
| 75 | 75 | * @return bool |
| 76 | 76 | */ |
| 77 | -function is_espresso_venue( $venue = NULL ) { |
|
| 78 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 77 | +function is_espresso_venue($venue = NULL) { |
|
| 78 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 79 | 79 | // extract EE_Venue object from passed param regardless of what it is (within reason of course) |
| 80 | - $venue = EEH_Venue_View::get_venue( $venue, FALSE ); |
|
| 80 | + $venue = EEH_Venue_View::get_venue($venue, FALSE); |
|
| 81 | 81 | // do we have a valid event ? |
| 82 | 82 | return $venue instanceof EE_Venue ? TRUE : FALSE; |
| 83 | 83 | } |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @return bool |
| 92 | 92 | */ |
| 93 | 93 | function is_espresso_venue_single() { |
| 94 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 94 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 95 | 95 | global $wp_query; |
| 96 | 96 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_single : FALSE; |
| 97 | 97 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * @return bool |
| 106 | 106 | */ |
| 107 | 107 | function is_espresso_venue_archive() { |
| 108 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 108 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 109 | 109 | global $wp_query; |
| 110 | 110 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_archive : FALSE; |
| 111 | 111 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @return bool |
| 120 | 120 | */ |
| 121 | 121 | function is_espresso_venue_taxonomy() { |
| 122 | - if ( can_use_espresso_conditionals( __FUNCTION__ )) { |
|
| 122 | + if (can_use_espresso_conditionals(__FUNCTION__)) { |
|
| 123 | 123 | global $wp_query; |
| 124 | 124 | return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_taxonomy : FALSE; |
| 125 | 125 | } |
@@ -133,12 +133,12 @@ discard block |
||
| 133 | 133 | * @param $conditional_tag |
| 134 | 134 | * @return bool |
| 135 | 135 | */ |
| 136 | -function can_use_espresso_conditionals( $conditional_tag ) { |
|
| 137 | - if ( ! did_action( 'AHEE__EE_System__initialize' )) { |
|
| 136 | +function can_use_espresso_conditionals($conditional_tag) { |
|
| 137 | + if ( ! did_action('AHEE__EE_System__initialize')) { |
|
| 138 | 138 | EE_Error::doing_it_wrong( |
| 139 | 139 | __FUNCTION__, |
| 140 | 140 | sprintf( |
| 141 | - __( 'The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.','event_espresso'), |
|
| 141 | + __('The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.', 'event_espresso'), |
|
| 142 | 142 | $conditional_tag |
| 143 | 143 | ), |
| 144 | 144 | '4.4.0' |
@@ -153,13 +153,13 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | /*************************** Event Queries ***************************/ |
| 155 | 155 | |
| 156 | -if ( ! function_exists( 'espresso_get_events' )) { |
|
| 156 | +if ( ! function_exists('espresso_get_events')) { |
|
| 157 | 157 | /** |
| 158 | 158 | * espresso_get_events |
| 159 | 159 | * @param array $params |
| 160 | 160 | * @return array |
| 161 | 161 | */ |
| 162 | - function espresso_get_events( $params = array() ) { |
|
| 162 | + function espresso_get_events($params = array()) { |
|
| 163 | 163 | //set default params |
| 164 | 164 | $default_espresso_events_params = array( |
| 165 | 165 | 'limit' => 10, |
@@ -170,18 +170,18 @@ discard block |
||
| 170 | 170 | 'sort' => 'ASC' |
| 171 | 171 | ); |
| 172 | 172 | // allow the defaults to be filtered |
| 173 | - $default_espresso_events_params = apply_filters( 'espresso_get_events__default_espresso_events_params', $default_espresso_events_params ); |
|
| 173 | + $default_espresso_events_params = apply_filters('espresso_get_events__default_espresso_events_params', $default_espresso_events_params); |
|
| 174 | 174 | // grab params and merge with defaults, then extract |
| 175 | - $params = array_merge( $default_espresso_events_params, $params ); |
|
| 175 | + $params = array_merge($default_espresso_events_params, $params); |
|
| 176 | 176 | // run the query |
| 177 | - $events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $params ); |
|
| 177 | + $events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery($params); |
|
| 178 | 178 | // assign results to a variable so we can return it |
| 179 | 179 | $events = $events_query->have_posts() ? $events_query->posts : array(); |
| 180 | 180 | // but first reset the query and postdata |
| 181 | 181 | wp_reset_query(); |
| 182 | 182 | wp_reset_postdata(); |
| 183 | 183 | EED_Events_Archive::remove_all_events_archive_filters(); |
| 184 | - unset( $events_query ); |
|
| 184 | + unset($events_query); |
|
| 185 | 185 | return $events; |
| 186 | 186 | } |
| 187 | 187 | } |
@@ -195,33 +195,33 @@ discard block |
||
| 195 | 195 | * espresso_load_ticket_selector |
| 196 | 196 | */ |
| 197 | 197 | function espresso_load_ticket_selector() { |
| 198 | - EE_Registry::instance()->load_file( EE_MODULES . 'ticket_selector', 'EED_Ticket_Selector', 'module' ); |
|
| 198 | + EE_Registry::instance()->load_file(EE_MODULES.'ticket_selector', 'EED_Ticket_Selector', 'module'); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | -if ( ! function_exists( 'espresso_ticket_selector' )) { |
|
| 201 | +if ( ! function_exists('espresso_ticket_selector')) { |
|
| 202 | 202 | /** |
| 203 | 203 | * espresso_ticket_selector |
| 204 | 204 | * @param null $event |
| 205 | 205 | */ |
| 206 | - function espresso_ticket_selector( $event = NULL ) { |
|
| 207 | - if ( ! apply_filters( 'FHEE_disable_espresso_ticket_selector', FALSE ) ) { |
|
| 206 | + function espresso_ticket_selector($event = NULL) { |
|
| 207 | + if ( ! apply_filters('FHEE_disable_espresso_ticket_selector', FALSE)) { |
|
| 208 | 208 | espresso_load_ticket_selector(); |
| 209 | 209 | \EED_Ticket_Selector::set_definitions(); |
| 210 | - echo EED_Ticket_Selector::display_ticket_selector( $event ); |
|
| 210 | + echo EED_Ticket_Selector::display_ticket_selector($event); |
|
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
| 216 | - if ( ! function_exists( 'espresso_view_details_btn' )) { |
|
| 216 | + if ( ! function_exists('espresso_view_details_btn')) { |
|
| 217 | 217 | /** |
| 218 | 218 | * espresso_view_details_btn |
| 219 | 219 | * @param null $event |
| 220 | 220 | */ |
| 221 | - function espresso_view_details_btn( $event = NULL ) { |
|
| 222 | - if ( ! apply_filters( 'FHEE_disable_espresso_view_details_btn', FALSE ) ) { |
|
| 221 | + function espresso_view_details_btn($event = NULL) { |
|
| 222 | + if ( ! apply_filters('FHEE_disable_espresso_view_details_btn', FALSE)) { |
|
| 223 | 223 | espresso_load_ticket_selector(); |
| 224 | - echo EED_Ticket_Selector::display_ticket_selector( $event, TRUE ); |
|
| 224 | + echo EED_Ticket_Selector::display_ticket_selector($event, TRUE); |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | |
| 232 | 232 | /*************************** EEH_Event_View ***************************/ |
| 233 | 233 | |
| 234 | -if ( ! function_exists( 'espresso_load_event_list_assets' )) { |
|
| 234 | +if ( ! function_exists('espresso_load_event_list_assets')) { |
|
| 235 | 235 | /** |
| 236 | 236 | * espresso_load_event_list_assets |
| 237 | 237 | * ensures that event list styles and scripts are loaded |
@@ -240,13 +240,13 @@ discard block |
||
| 240 | 240 | */ |
| 241 | 241 | function espresso_load_event_list_assets() { |
| 242 | 242 | $event_list = EED_Events_Archive::instance(); |
| 243 | - add_action( 'AHEE__EE_System__initialize_last', array( $event_list, 'load_event_list_assets' ), 10 ); |
|
| 244 | - add_filter( 'FHEE_enable_default_espresso_css', '__return_true' ); |
|
| 243 | + add_action('AHEE__EE_System__initialize_last', array($event_list, 'load_event_list_assets'), 10); |
|
| 244 | + add_filter('FHEE_enable_default_espresso_css', '__return_true'); |
|
| 245 | 245 | } |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
| 249 | -if ( ! function_exists( 'espresso_event_reg_button' )) { |
|
| 249 | +if ( ! function_exists('espresso_event_reg_button')) { |
|
| 250 | 250 | /** |
| 251 | 251 | * espresso_event_reg_button |
| 252 | 252 | * returns the "Register Now" button if event is active, |
@@ -258,9 +258,9 @@ discard block |
||
| 258 | 258 | * @param bool $EVT_ID |
| 259 | 259 | * @return string |
| 260 | 260 | */ |
| 261 | - function espresso_event_reg_button( $btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE ) { |
|
| 262 | - $event_status = EEH_Event_View::event_active_status( $EVT_ID ); |
|
| 263 | - switch ( $event_status ) { |
|
| 261 | + function espresso_event_reg_button($btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE) { |
|
| 262 | + $event_status = EEH_Event_View::event_active_status($EVT_ID); |
|
| 263 | + switch ($event_status) { |
|
| 264 | 264 | case EE_Datetime::sold_out : |
| 265 | 265 | $btn_text = __('Sold Out', 'event_espresso'); |
| 266 | 266 | $class = 'ee-pink'; |
@@ -276,10 +276,10 @@ discard block |
||
| 276 | 276 | case EE_Datetime::upcoming : |
| 277 | 277 | case EE_Datetime::active : |
| 278 | 278 | default : |
| 279 | - $btn_text =! empty( $btn_text_if_active ) ? $btn_text_if_active : __( 'Register Now', 'event_espresso' ); |
|
| 279 | + $btn_text = ! empty($btn_text_if_active) ? $btn_text_if_active : __('Register Now', 'event_espresso'); |
|
| 280 | 280 | $class = 'ee-green'; |
| 281 | 281 | } |
| 282 | - if ( $event_status < 1 && ! empty( $btn_text_if_inactive )) { |
|
| 282 | + if ($event_status < 1 && ! empty($btn_text_if_inactive)) { |
|
| 283 | 283 | $btn_text = $btn_text_if_inactive; |
| 284 | 284 | $class = 'ee-grey'; |
| 285 | 285 | } |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | |
| 294 | 294 | |
| 295 | 295 | |
| 296 | -if ( ! function_exists( 'espresso_display_ticket_selector' )) { |
|
| 296 | +if ( ! function_exists('espresso_display_ticket_selector')) { |
|
| 297 | 297 | /** |
| 298 | 298 | * espresso_display_ticket_selector |
| 299 | 299 | * whether or not to display the Ticket Selector for an event |
@@ -301,14 +301,14 @@ discard block |
||
| 301 | 301 | * @param bool $EVT_ID |
| 302 | 302 | * @return boolean |
| 303 | 303 | */ |
| 304 | - function espresso_display_ticket_selector( $EVT_ID = FALSE ) { |
|
| 305 | - return EEH_Event_View::display_ticket_selector( $EVT_ID ); |
|
| 304 | + function espresso_display_ticket_selector($EVT_ID = FALSE) { |
|
| 305 | + return EEH_Event_View::display_ticket_selector($EVT_ID); |
|
| 306 | 306 | } |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | |
| 310 | 310 | |
| 311 | -if ( ! function_exists( 'espresso_event_status_banner' )) { |
|
| 311 | +if ( ! function_exists('espresso_event_status_banner')) { |
|
| 312 | 312 | /** |
| 313 | 313 | * espresso_event_status |
| 314 | 314 | * returns a banner showing the event status if it is sold out, expired, or inactive |
@@ -316,13 +316,13 @@ discard block |
||
| 316 | 316 | * @param bool $EVT_ID |
| 317 | 317 | * @return string |
| 318 | 318 | */ |
| 319 | - function espresso_event_status_banner( $EVT_ID = FALSE ) { |
|
| 320 | - return EEH_Event_View::event_status( $EVT_ID ); |
|
| 319 | + function espresso_event_status_banner($EVT_ID = FALSE) { |
|
| 320 | + return EEH_Event_View::event_status($EVT_ID); |
|
| 321 | 321 | } |
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | |
| 325 | -if ( ! function_exists( 'espresso_event_status' )) { |
|
| 325 | +if ( ! function_exists('espresso_event_status')) { |
|
| 326 | 326 | /** |
| 327 | 327 | * espresso_event_status |
| 328 | 328 | * returns the event status if it is sold out, expired, or inactive |
@@ -331,13 +331,13 @@ discard block |
||
| 331 | 331 | * @param bool $echo |
| 332 | 332 | * @return string |
| 333 | 333 | */ |
| 334 | - function espresso_event_status( $EVT_ID = 0, $echo = TRUE ) { |
|
| 335 | - return EEH_Event_View::event_active_status( $EVT_ID, $echo ); |
|
| 334 | + function espresso_event_status($EVT_ID = 0, $echo = TRUE) { |
|
| 335 | + return EEH_Event_View::event_active_status($EVT_ID, $echo); |
|
| 336 | 336 | } |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | 339 | |
| 340 | -if ( ! function_exists( 'espresso_event_categories' )) { |
|
| 340 | +if ( ! function_exists('espresso_event_categories')) { |
|
| 341 | 341 | /** |
| 342 | 342 | * espresso_event_categories |
| 343 | 343 | * returns the terms associated with an event |
@@ -347,17 +347,17 @@ discard block |
||
| 347 | 347 | * @param bool $echo |
| 348 | 348 | * @return string |
| 349 | 349 | */ |
| 350 | - function espresso_event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) { |
|
| 351 | - if ( $echo ) { |
|
| 352 | - echo EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized ); |
|
| 350 | + function espresso_event_categories($EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) { |
|
| 351 | + if ($echo) { |
|
| 352 | + echo EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
| 353 | 353 | return ''; |
| 354 | 354 | } |
| 355 | - return EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized ); |
|
| 355 | + return EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized); |
|
| 356 | 356 | } |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | |
| 360 | -if ( ! function_exists( 'espresso_event_tickets_available' )) { |
|
| 360 | +if ( ! function_exists('espresso_event_tickets_available')) { |
|
| 361 | 361 | /** |
| 362 | 362 | * espresso_event_tickets_available |
| 363 | 363 | * returns the ticket types available for purchase for an event |
@@ -367,26 +367,26 @@ discard block |
||
| 367 | 367 | * @param bool $format |
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | - function espresso_event_tickets_available( $EVT_ID = 0, $echo = TRUE, $format = TRUE ) { |
|
| 371 | - $tickets = EEH_Event_View::event_tickets_available( $EVT_ID ); |
|
| 372 | - if ( is_array( $tickets ) && ! empty( $tickets )) { |
|
| 370 | + function espresso_event_tickets_available($EVT_ID = 0, $echo = TRUE, $format = TRUE) { |
|
| 371 | + $tickets = EEH_Event_View::event_tickets_available($EVT_ID); |
|
| 372 | + if (is_array($tickets) && ! empty($tickets)) { |
|
| 373 | 373 | // if formatting then $html will be a string, else it will be an array of ticket objects |
| 374 | - $html = $format ? '<ul id="ee-event-tickets-ul-' . $EVT_ID . '" class="ee-event-tickets-ul">' : array(); |
|
| 375 | - foreach ( $tickets as $ticket ) { |
|
| 376 | - if ( $ticket instanceof EE_Ticket ) { |
|
| 377 | - if ( $format ) { |
|
| 378 | - $html .= '<li id="ee-event-tickets-li-' . $ticket->ID() . '" class="ee-event-tickets-li">'; |
|
| 379 | - $html .= $ticket->name() . ' ' . EEH_Template::format_currency( $ticket->get_ticket_total_with_taxes() ); |
|
| 374 | + $html = $format ? '<ul id="ee-event-tickets-ul-'.$EVT_ID.'" class="ee-event-tickets-ul">' : array(); |
|
| 375 | + foreach ($tickets as $ticket) { |
|
| 376 | + if ($ticket instanceof EE_Ticket) { |
|
| 377 | + if ($format) { |
|
| 378 | + $html .= '<li id="ee-event-tickets-li-'.$ticket->ID().'" class="ee-event-tickets-li">'; |
|
| 379 | + $html .= $ticket->name().' '.EEH_Template::format_currency($ticket->get_ticket_total_with_taxes()); |
|
| 380 | 380 | $html .= '</li>'; |
| 381 | 381 | } else { |
| 382 | 382 | $html[] = $ticket; |
| 383 | 383 | } |
| 384 | 384 | } |
| 385 | 385 | } |
| 386 | - if ( $format ) { |
|
| 386 | + if ($format) { |
|
| 387 | 387 | $html .= '</ul>'; |
| 388 | 388 | } |
| 389 | - if ( $echo && $format ) { |
|
| 389 | + if ($echo && $format) { |
|
| 390 | 390 | echo $html; |
| 391 | 391 | return ''; |
| 392 | 392 | } |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | -if ( ! function_exists( 'espresso_event_date_obj' )) { |
|
| 399 | +if ( ! function_exists('espresso_event_date_obj')) { |
|
| 400 | 400 | /** |
| 401 | 401 | * espresso_event_date_obj |
| 402 | 402 | * returns the primary date object for an event |
@@ -404,13 +404,13 @@ discard block |
||
| 404 | 404 | * @param bool $EVT_ID |
| 405 | 405 | * @return object |
| 406 | 406 | */ |
| 407 | - function espresso_event_date_obj( $EVT_ID = FALSE ) { |
|
| 408 | - return EEH_Event_View::get_primary_date_obj( $EVT_ID ); |
|
| 407 | + function espresso_event_date_obj($EVT_ID = FALSE) { |
|
| 408 | + return EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
| 409 | 409 | } |
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
| 413 | -if ( ! function_exists( 'espresso_event_date' )) { |
|
| 413 | +if ( ! function_exists('espresso_event_date')) { |
|
| 414 | 414 | /** |
| 415 | 415 | * espresso_event_date |
| 416 | 416 | * returns the primary date for an event |
@@ -421,22 +421,22 @@ discard block |
||
| 421 | 421 | * @param bool $echo |
| 422 | 422 | * @return string |
| 423 | 423 | */ |
| 424 | - function espresso_event_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
| 425 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
| 426 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
| 427 | - $date_format = apply_filters( 'FHEE__espresso_event_date__date_format', $date_format ); |
|
| 428 | - $time_format = apply_filters( 'FHEE__espresso_event_date__time_format', $time_format ); |
|
| 429 | - if($echo){ |
|
| 430 | - echo EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID ); |
|
| 424 | + function espresso_event_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
| 425 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 426 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 427 | + $date_format = apply_filters('FHEE__espresso_event_date__date_format', $date_format); |
|
| 428 | + $time_format = apply_filters('FHEE__espresso_event_date__time_format', $time_format); |
|
| 429 | + if ($echo) { |
|
| 430 | + echo EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
| 431 | 431 | return ''; |
| 432 | 432 | } |
| 433 | - return EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID ); |
|
| 433 | + return EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID); |
|
| 434 | 434 | |
| 435 | 435 | } |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | |
| 439 | -if ( ! function_exists( 'espresso_list_of_event_dates' )) { |
|
| 439 | +if ( ! function_exists('espresso_list_of_event_dates')) { |
|
| 440 | 440 | /** |
| 441 | 441 | * espresso_list_of_event_dates |
| 442 | 442 | * returns a unordered list of dates for an event |
@@ -451,40 +451,40 @@ discard block |
||
| 451 | 451 | * @param null $limit |
| 452 | 452 | * @return string |
| 453 | 453 | */ |
| 454 | - function espresso_list_of_event_dates( $EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL ) { |
|
| 455 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
| 456 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
| 457 | - $date_format = apply_filters( 'FHEE__espresso_list_of_event_dates__date_format', $date_format ); |
|
| 458 | - $time_format = apply_filters( 'FHEE__espresso_list_of_event_dates__time_format', $time_format ); |
|
| 459 | - $datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, $show_expired, FALSE, $limit ); |
|
| 460 | - if ( ! $format ) { |
|
| 461 | - return apply_filters( 'FHEE__espresso_list_of_event_dates__datetimes', $datetimes ); |
|
| 454 | + function espresso_list_of_event_dates($EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL) { |
|
| 455 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 456 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 457 | + $date_format = apply_filters('FHEE__espresso_list_of_event_dates__date_format', $date_format); |
|
| 458 | + $time_format = apply_filters('FHEE__espresso_list_of_event_dates__time_format', $time_format); |
|
| 459 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, $show_expired, FALSE, $limit); |
|
| 460 | + if ( ! $format) { |
|
| 461 | + return apply_filters('FHEE__espresso_list_of_event_dates__datetimes', $datetimes); |
|
| 462 | 462 | } |
| 463 | 463 | //d( $datetimes ); |
| 464 | - if ( is_array( $datetimes ) && ! empty( $datetimes )) { |
|
| 464 | + if (is_array($datetimes) && ! empty($datetimes)) { |
|
| 465 | 465 | global $post; |
| 466 | - $html = $format ? '<ul id="ee-event-datetimes-ul-' . $post->ID . '" class="ee-event-datetimes-ul ee-clearfix">' : ''; |
|
| 467 | - foreach ( $datetimes as $datetime ) { |
|
| 468 | - if ( $datetime instanceof EE_Datetime ) { |
|
| 469 | - $html .= '<li id="ee-event-datetimes-li-' . $datetime->ID(); |
|
| 470 | - $html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-' . $datetime->get_active_status() . '">'; |
|
| 466 | + $html = $format ? '<ul id="ee-event-datetimes-ul-'.$post->ID.'" class="ee-event-datetimes-ul ee-clearfix">' : ''; |
|
| 467 | + foreach ($datetimes as $datetime) { |
|
| 468 | + if ($datetime instanceof EE_Datetime) { |
|
| 469 | + $html .= '<li id="ee-event-datetimes-li-'.$datetime->ID(); |
|
| 470 | + $html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-'.$datetime->get_active_status().'">'; |
|
| 471 | 471 | $datetime_name = $datetime->name(); |
| 472 | - $html .= ! empty( $datetime_name ) ? '<strong>' . $datetime_name . '</strong>' : ''; |
|
| 473 | - $html .= ! empty( $datetime_name ) && $add_breaks ? '<br />' : ''; |
|
| 474 | - $html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">' . $datetime->date_range( $date_format ) . '</span><br/>'; |
|
| 475 | - $html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">' . $datetime->time_range( $time_format ) . '</span>'; |
|
| 472 | + $html .= ! empty($datetime_name) ? '<strong>'.$datetime_name.'</strong>' : ''; |
|
| 473 | + $html .= ! empty($datetime_name) && $add_breaks ? '<br />' : ''; |
|
| 474 | + $html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">'.$datetime->date_range($date_format).'</span><br/>'; |
|
| 475 | + $html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">'.$datetime->time_range($time_format).'</span>'; |
|
| 476 | 476 | $datetime_description = $datetime->description(); |
| 477 | - $html .= ! empty( $datetime_description ) && $add_breaks ? '<br />' : ''; |
|
| 478 | - $html .= ! empty( $datetime_description ) ? ' - ' . $datetime_description : ''; |
|
| 479 | - $html = apply_filters( 'FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime ); |
|
| 477 | + $html .= ! empty($datetime_description) && $add_breaks ? '<br />' : ''; |
|
| 478 | + $html .= ! empty($datetime_description) ? ' - '.$datetime_description : ''; |
|
| 479 | + $html = apply_filters('FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime); |
|
| 480 | 480 | $html .= '</li>'; |
| 481 | 481 | } |
| 482 | 482 | } |
| 483 | 483 | $html .= $format ? '</ul>' : ''; |
| 484 | 484 | } else { |
| 485 | - $html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>' . __( 'There are no upcoming dates for this event.', 'event_espresso' ) . '</p><br/>' : ''; |
|
| 485 | + $html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>'.__('There are no upcoming dates for this event.', 'event_espresso').'</p><br/>' : ''; |
|
| 486 | 486 | } |
| 487 | - if ( $echo ) { |
|
| 487 | + if ($echo) { |
|
| 488 | 488 | echo $html; |
| 489 | 489 | return ''; |
| 490 | 490 | } |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | |
| 496 | -if ( ! function_exists( 'espresso_event_end_date' )) { |
|
| 496 | +if ( ! function_exists('espresso_event_end_date')) { |
|
| 497 | 497 | /** |
| 498 | 498 | * espresso_event_end_date |
| 499 | 499 | * returns the last date for an event |
@@ -504,20 +504,20 @@ discard block |
||
| 504 | 504 | * @param bool $echo |
| 505 | 505 | * @return string |
| 506 | 506 | */ |
| 507 | - function espresso_event_end_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
| 508 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
| 509 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
| 510 | - $date_format = apply_filters( 'FHEE__espresso_event_end_date__date_format', $date_format ); |
|
| 511 | - $time_format = apply_filters( 'FHEE__espresso_event_end_date__time_format', $time_format ); |
|
| 512 | - if($echo){ |
|
| 513 | - echo EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID ); |
|
| 507 | + function espresso_event_end_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
| 508 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 509 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 510 | + $date_format = apply_filters('FHEE__espresso_event_end_date__date_format', $date_format); |
|
| 511 | + $time_format = apply_filters('FHEE__espresso_event_end_date__time_format', $time_format); |
|
| 512 | + if ($echo) { |
|
| 513 | + echo EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
| 514 | 514 | return ''; |
| 515 | 515 | } |
| 516 | - return EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID ); |
|
| 516 | + return EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID); |
|
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | |
| 520 | -if ( ! function_exists( 'espresso_event_date_range' )) { |
|
| 520 | +if ( ! function_exists('espresso_event_date_range')) { |
|
| 521 | 521 | /** |
| 522 | 522 | * espresso_event_date_range |
| 523 | 523 | * returns the first and last chronologically ordered dates for an event (if different) |
@@ -530,31 +530,31 @@ discard block |
||
| 530 | 530 | * @param bool $echo |
| 531 | 531 | * @return string |
| 532 | 532 | */ |
| 533 | - function espresso_event_date_range( $date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE ) { |
|
| 533 | + function espresso_event_date_range($date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE) { |
|
| 534 | 534 | // set and filter date and time formats when a range is returned |
| 535 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
| 536 | - $date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', $date_format ); |
|
| 535 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 536 | + $date_format = apply_filters('FHEE__espresso_event_date_range__date_format', $date_format); |
|
| 537 | 537 | // get the start and end date with NO time portion |
| 538 | - $the_event_date = EEH_Event_View::the_earliest_event_date( $date_format, '', $EVT_ID ); |
|
| 539 | - $the_event_end_date = EEH_Event_View::the_latest_event_date( $date_format, '', $EVT_ID ); |
|
| 538 | + $the_event_date = EEH_Event_View::the_earliest_event_date($date_format, '', $EVT_ID); |
|
| 539 | + $the_event_end_date = EEH_Event_View::the_latest_event_date($date_format, '', $EVT_ID); |
|
| 540 | 540 | // now we can determine if date range spans more than one day |
| 541 | - if ( $the_event_date != $the_event_end_date ) { |
|
| 542 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
| 543 | - $time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', $time_format ); |
|
| 541 | + if ($the_event_date != $the_event_end_date) { |
|
| 542 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 543 | + $time_format = apply_filters('FHEE__espresso_event_date_range__time_format', $time_format); |
|
| 544 | 544 | $html = sprintf( |
| 545 | - __( '%1$s - %2$s', 'event_espresso' ), |
|
| 546 | - EEH_Event_View::the_earliest_event_date( $date_format, $time_format, $EVT_ID ), |
|
| 547 | - EEH_Event_View::the_latest_event_date( $date_format, $time_format, $EVT_ID ) |
|
| 545 | + __('%1$s - %2$s', 'event_espresso'), |
|
| 546 | + EEH_Event_View::the_earliest_event_date($date_format, $time_format, $EVT_ID), |
|
| 547 | + EEH_Event_View::the_latest_event_date($date_format, $time_format, $EVT_ID) |
|
| 548 | 548 | ); |
| 549 | 549 | } else { |
| 550 | 550 | // set and filter date and time formats when only a single datetime is returned |
| 551 | - $single_date_format = ! empty( $single_date_format ) ? $single_date_format : get_option( 'date_format' ); |
|
| 552 | - $single_time_format = ! empty( $single_time_format ) ? $single_time_format : get_option( 'time_format' ); |
|
| 553 | - $single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', $single_date_format ); |
|
| 554 | - $single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', $single_time_format ); |
|
| 555 | - $html = EEH_Event_View::the_earliest_event_date( $single_date_format, $single_time_format, $EVT_ID ); |
|
| 551 | + $single_date_format = ! empty($single_date_format) ? $single_date_format : get_option('date_format'); |
|
| 552 | + $single_time_format = ! empty($single_time_format) ? $single_time_format : get_option('time_format'); |
|
| 553 | + $single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', $single_date_format); |
|
| 554 | + $single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', $single_time_format); |
|
| 555 | + $html = EEH_Event_View::the_earliest_event_date($single_date_format, $single_time_format, $EVT_ID); |
|
| 556 | 556 | } |
| 557 | - if ( $echo ) { |
|
| 557 | + if ($echo) { |
|
| 558 | 558 | echo $html; |
| 559 | 559 | return ''; |
| 560 | 560 | } |
@@ -562,7 +562,7 @@ discard block |
||
| 562 | 562 | } |
| 563 | 563 | } |
| 564 | 564 | |
| 565 | -if ( ! function_exists( 'espresso_next_upcoming_datetime_obj' )) { |
|
| 565 | +if ( ! function_exists('espresso_next_upcoming_datetime_obj')) { |
|
| 566 | 566 | /** |
| 567 | 567 | * espresso_next_upcoming_datetime_obj |
| 568 | 568 | * returns the next upcoming datetime object for an event |
@@ -570,12 +570,12 @@ discard block |
||
| 570 | 570 | * @param int $EVT_ID |
| 571 | 571 | * @return EE_Datetime|null |
| 572 | 572 | */ |
| 573 | - function espresso_next_upcoming_datetime_obj( $EVT_ID = 0 ) { |
|
| 574 | - return EEH_Event_View::get_next_upcoming_date_obj( $EVT_ID ); |
|
| 573 | + function espresso_next_upcoming_datetime_obj($EVT_ID = 0) { |
|
| 574 | + return EEH_Event_View::get_next_upcoming_date_obj($EVT_ID); |
|
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | -if ( ! function_exists( 'espresso_next_upcoming_datetime' ) ) { |
|
| 578 | +if ( ! function_exists('espresso_next_upcoming_datetime')) { |
|
| 579 | 579 | /** |
| 580 | 580 | * espresso_next_upcoming_datetime |
| 581 | 581 | * returns the start date and time for the next upcoming event. |
@@ -586,30 +586,30 @@ discard block |
||
| 586 | 586 | * @param bool $echo |
| 587 | 587 | * @return string |
| 588 | 588 | */ |
| 589 | - function espresso_next_upcoming_datetime( $date_format = '', $time_format = '', $EVT_ID = 0, $echo = true ) { |
|
| 589 | + function espresso_next_upcoming_datetime($date_format = '', $time_format = '', $EVT_ID = 0, $echo = true) { |
|
| 590 | 590 | |
| 591 | - $date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' ); |
|
| 592 | - $date_format = apply_filters( 'FHEE__espresso_next_upcoming_datetime__date_format', $date_format ); |
|
| 591 | + $date_format = ! empty($date_format) ? $date_format : get_option('date_format'); |
|
| 592 | + $date_format = apply_filters('FHEE__espresso_next_upcoming_datetime__date_format', $date_format); |
|
| 593 | 593 | |
| 594 | - $time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' ); |
|
| 595 | - $time_format = apply_filters( 'FHEE__espresso_next_upcoming_datetime__time_format', $time_format ); |
|
| 594 | + $time_format = ! empty($time_format) ? $time_format : get_option('time_format'); |
|
| 595 | + $time_format = apply_filters('FHEE__espresso_next_upcoming_datetime__time_format', $time_format); |
|
| 596 | 596 | |
| 597 | - $datetime_format = trim( $date_format . ' ' . $time_format); |
|
| 597 | + $datetime_format = trim($date_format.' '.$time_format); |
|
| 598 | 598 | |
| 599 | - $datetime = espresso_next_upcoming_datetime_obj( $EVT_ID ); |
|
| 599 | + $datetime = espresso_next_upcoming_datetime_obj($EVT_ID); |
|
| 600 | 600 | |
| 601 | - if( ! $datetime instanceof EE_Datetime ) { |
|
| 601 | + if ( ! $datetime instanceof EE_Datetime) { |
|
| 602 | 602 | return ''; |
| 603 | 603 | } |
| 604 | - if ( $echo ){ |
|
| 605 | - echo $datetime->get_i18n_datetime( 'DTT_EVT_start', $datetime_format ); |
|
| 604 | + if ($echo) { |
|
| 605 | + echo $datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format); |
|
| 606 | 606 | return ''; |
| 607 | 607 | } |
| 608 | - return $datetime->get_i18n_datetime( 'DTT_EVT_start', $datetime_format ); |
|
| 608 | + return $datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format); |
|
| 609 | 609 | } |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | -if ( ! function_exists( 'espresso_event_date_as_calendar_page' )) { |
|
| 612 | +if ( ! function_exists('espresso_event_date_as_calendar_page')) { |
|
| 613 | 613 | /** |
| 614 | 614 | * espresso_event_date_as_calendar_page |
| 615 | 615 | * returns the primary date for an event, stylized to appear as the page of a calendar |
@@ -617,15 +617,15 @@ discard block |
||
| 617 | 617 | * @param bool $EVT_ID |
| 618 | 618 | * @return string |
| 619 | 619 | */ |
| 620 | - function espresso_event_date_as_calendar_page( $EVT_ID = FALSE ) { |
|
| 621 | - EEH_Event_View::event_date_as_calendar_page( $EVT_ID ); |
|
| 620 | + function espresso_event_date_as_calendar_page($EVT_ID = FALSE) { |
|
| 621 | + EEH_Event_View::event_date_as_calendar_page($EVT_ID); |
|
| 622 | 622 | } |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | |
| 626 | 626 | |
| 627 | 627 | |
| 628 | -if ( ! function_exists( 'espresso_event_link_url' )) { |
|
| 628 | +if ( ! function_exists('espresso_event_link_url')) { |
|
| 629 | 629 | /** |
| 630 | 630 | * espresso_event_link_url |
| 631 | 631 | * |
@@ -633,18 +633,18 @@ discard block |
||
| 633 | 633 | * @param bool $echo |
| 634 | 634 | * @return string |
| 635 | 635 | */ |
| 636 | - function espresso_event_link_url( $EVT_ID = 0, $echo = TRUE ) { |
|
| 637 | - if ( $echo ) { |
|
| 638 | - echo EEH_Event_View::event_link_url( $EVT_ID ); |
|
| 636 | + function espresso_event_link_url($EVT_ID = 0, $echo = TRUE) { |
|
| 637 | + if ($echo) { |
|
| 638 | + echo EEH_Event_View::event_link_url($EVT_ID); |
|
| 639 | 639 | return ''; |
| 640 | 640 | } |
| 641 | - return EEH_Event_View::event_link_url( $EVT_ID ); |
|
| 641 | + return EEH_Event_View::event_link_url($EVT_ID); |
|
| 642 | 642 | } |
| 643 | 643 | } |
| 644 | 644 | |
| 645 | 645 | |
| 646 | 646 | |
| 647 | -if ( ! function_exists( 'espresso_event_has_content_or_excerpt' )) { |
|
| 647 | +if ( ! function_exists('espresso_event_has_content_or_excerpt')) { |
|
| 648 | 648 | /** |
| 649 | 649 | * espresso_event_has_content_or_excerpt |
| 650 | 650 | * |
@@ -652,15 +652,15 @@ discard block |
||
| 652 | 652 | * @param bool $EVT_ID |
| 653 | 653 | * @return boolean |
| 654 | 654 | */ |
| 655 | - function espresso_event_has_content_or_excerpt( $EVT_ID = FALSE ) { |
|
| 656 | - return EEH_Event_View::event_has_content_or_excerpt( $EVT_ID ); |
|
| 655 | + function espresso_event_has_content_or_excerpt($EVT_ID = FALSE) { |
|
| 656 | + return EEH_Event_View::event_has_content_or_excerpt($EVT_ID); |
|
| 657 | 657 | } |
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | |
| 661 | 661 | |
| 662 | 662 | |
| 663 | -if ( ! function_exists( 'espresso_event_content_or_excerpt' )) { |
|
| 663 | +if ( ! function_exists('espresso_event_content_or_excerpt')) { |
|
| 664 | 664 | /** |
| 665 | 665 | * espresso_event_content_or_excerpt |
| 666 | 666 | * |
@@ -669,18 +669,18 @@ discard block |
||
| 669 | 669 | * @param bool $echo |
| 670 | 670 | * @return string |
| 671 | 671 | */ |
| 672 | - function espresso_event_content_or_excerpt( $num_words = 55, $more = NULL, $echo = TRUE ) { |
|
| 673 | - if ( $echo ) { |
|
| 674 | - echo EEH_Event_View::event_content_or_excerpt( $num_words, $more ); |
|
| 672 | + function espresso_event_content_or_excerpt($num_words = 55, $more = NULL, $echo = TRUE) { |
|
| 673 | + if ($echo) { |
|
| 674 | + echo EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
| 675 | 675 | return ''; |
| 676 | 676 | } |
| 677 | - return EEH_Event_View::event_content_or_excerpt( $num_words, $more ); |
|
| 677 | + return EEH_Event_View::event_content_or_excerpt($num_words, $more); |
|
| 678 | 678 | } |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | |
| 682 | 682 | |
| 683 | -if ( ! function_exists( 'espresso_event_phone' )) { |
|
| 683 | +if ( ! function_exists('espresso_event_phone')) { |
|
| 684 | 684 | /** |
| 685 | 685 | * espresso_event_phone |
| 686 | 686 | * |
@@ -688,18 +688,18 @@ discard block |
||
| 688 | 688 | * @param bool $echo |
| 689 | 689 | * @return string |
| 690 | 690 | */ |
| 691 | - function espresso_event_phone( $EVT_ID = 0, $echo = TRUE ) { |
|
| 692 | - if ( $echo ) { |
|
| 693 | - echo EEH_Event_View::event_phone( $EVT_ID ); |
|
| 691 | + function espresso_event_phone($EVT_ID = 0, $echo = TRUE) { |
|
| 692 | + if ($echo) { |
|
| 693 | + echo EEH_Event_View::event_phone($EVT_ID); |
|
| 694 | 694 | return ''; |
| 695 | 695 | } |
| 696 | - return EEH_Event_View::event_phone( $EVT_ID ); |
|
| 696 | + return EEH_Event_View::event_phone($EVT_ID); |
|
| 697 | 697 | } |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
| 701 | 701 | |
| 702 | -if ( ! function_exists( 'espresso_edit_event_link' )) { |
|
| 702 | +if ( ! function_exists('espresso_edit_event_link')) { |
|
| 703 | 703 | /** |
| 704 | 704 | * espresso_edit_event_link |
| 705 | 705 | * returns a link to edit an event |
@@ -708,39 +708,39 @@ discard block |
||
| 708 | 708 | * @param bool $echo |
| 709 | 709 | * @return string |
| 710 | 710 | */ |
| 711 | - function espresso_edit_event_link( $EVT_ID = 0, $echo = TRUE ) { |
|
| 712 | - if ( $echo ) { |
|
| 713 | - echo EEH_Event_View::edit_event_link( $EVT_ID ); |
|
| 711 | + function espresso_edit_event_link($EVT_ID = 0, $echo = TRUE) { |
|
| 712 | + if ($echo) { |
|
| 713 | + echo EEH_Event_View::edit_event_link($EVT_ID); |
|
| 714 | 714 | return ''; |
| 715 | 715 | } |
| 716 | - return EEH_Event_View::edit_event_link( $EVT_ID ); |
|
| 716 | + return EEH_Event_View::edit_event_link($EVT_ID); |
|
| 717 | 717 | } |
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | |
| 721 | -if ( ! function_exists( 'espresso_organization_name' )) { |
|
| 721 | +if ( ! function_exists('espresso_organization_name')) { |
|
| 722 | 722 | /** |
| 723 | 723 | * espresso_organization_name |
| 724 | 724 | * @param bool $echo |
| 725 | 725 | * @return string |
| 726 | 726 | */ |
| 727 | 727 | function espresso_organization_name($echo = TRUE) { |
| 728 | - if($echo){ |
|
| 729 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'name' ); |
|
| 728 | + if ($echo) { |
|
| 729 | + echo EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
| 730 | 730 | return ''; |
| 731 | 731 | } |
| 732 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'name' ); |
|
| 732 | + return EE_Registry::instance()->CFG->organization->get_pretty('name'); |
|
| 733 | 733 | } |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | -if ( ! function_exists( 'espresso_organization_address' )) { |
|
| 736 | +if ( ! function_exists('espresso_organization_address')) { |
|
| 737 | 737 | /** |
| 738 | 738 | * espresso_organization_address |
| 739 | 739 | * @param string $type |
| 740 | 740 | * @return string |
| 741 | 741 | */ |
| 742 | - function espresso_organization_address( $type = 'inline' ) { |
|
| 743 | - if ( EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config ) { |
|
| 742 | + function espresso_organization_address($type = 'inline') { |
|
| 743 | + if (EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config) { |
|
| 744 | 744 | $address = new EventEspresso\core\domain\entities\GenericAddress( |
| 745 | 745 | EE_Registry::instance()->CFG->organization->address_1, |
| 746 | 746 | EE_Registry::instance()->CFG->organization->address_2, |
@@ -749,129 +749,129 @@ discard block |
||
| 749 | 749 | EE_Registry::instance()->CFG->organization->zip, |
| 750 | 750 | EE_Registry::instance()->CFG->organization->CNT_ISO |
| 751 | 751 | ); |
| 752 | - return EEH_Address::format( $address, $type ); |
|
| 752 | + return EEH_Address::format($address, $type); |
|
| 753 | 753 | } |
| 754 | 754 | return ''; |
| 755 | 755 | } |
| 756 | 756 | } |
| 757 | 757 | |
| 758 | -if ( ! function_exists( 'espresso_organization_email' )) { |
|
| 758 | +if ( ! function_exists('espresso_organization_email')) { |
|
| 759 | 759 | /** |
| 760 | 760 | * espresso_organization_email |
| 761 | 761 | * @param bool $echo |
| 762 | 762 | * @return string |
| 763 | 763 | */ |
| 764 | - function espresso_organization_email( $echo = TRUE ) { |
|
| 765 | - if($echo){ |
|
| 766 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'email' ); |
|
| 764 | + function espresso_organization_email($echo = TRUE) { |
|
| 765 | + if ($echo) { |
|
| 766 | + echo EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
| 767 | 767 | return ''; |
| 768 | 768 | } |
| 769 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'email' ); |
|
| 769 | + return EE_Registry::instance()->CFG->organization->get_pretty('email'); |
|
| 770 | 770 | } |
| 771 | 771 | } |
| 772 | 772 | |
| 773 | -if ( ! function_exists( 'espresso_organization_logo_url' )) { |
|
| 773 | +if ( ! function_exists('espresso_organization_logo_url')) { |
|
| 774 | 774 | /** |
| 775 | 775 | * espresso_organization_logo_url |
| 776 | 776 | * @param bool $echo |
| 777 | 777 | * @return string |
| 778 | 778 | */ |
| 779 | - function espresso_organization_logo_url( $echo = TRUE ) { |
|
| 780 | - if($echo){ |
|
| 781 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' ); |
|
| 779 | + function espresso_organization_logo_url($echo = TRUE) { |
|
| 780 | + if ($echo) { |
|
| 781 | + echo EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
| 782 | 782 | return ''; |
| 783 | 783 | } |
| 784 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' ); |
|
| 784 | + return EE_Registry::instance()->CFG->organization->get_pretty('logo_url'); |
|
| 785 | 785 | } |
| 786 | 786 | } |
| 787 | 787 | |
| 788 | -if ( ! function_exists( 'espresso_organization_facebook' )) { |
|
| 788 | +if ( ! function_exists('espresso_organization_facebook')) { |
|
| 789 | 789 | /** |
| 790 | 790 | * espresso_organization_facebook |
| 791 | 791 | * @param bool $echo |
| 792 | 792 | * @return string |
| 793 | 793 | */ |
| 794 | - function espresso_organization_facebook( $echo = TRUE ) { |
|
| 795 | - if($echo){ |
|
| 796 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' ); |
|
| 794 | + function espresso_organization_facebook($echo = TRUE) { |
|
| 795 | + if ($echo) { |
|
| 796 | + echo EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
| 797 | 797 | return ''; |
| 798 | 798 | } |
| 799 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' ); |
|
| 799 | + return EE_Registry::instance()->CFG->organization->get_pretty('facebook'); |
|
| 800 | 800 | } |
| 801 | 801 | } |
| 802 | 802 | |
| 803 | -if ( ! function_exists( 'espresso_organization_twitter' )) { |
|
| 803 | +if ( ! function_exists('espresso_organization_twitter')) { |
|
| 804 | 804 | /** |
| 805 | 805 | * espresso_organization_twitter |
| 806 | 806 | * @param bool $echo |
| 807 | 807 | * @return string |
| 808 | 808 | */ |
| 809 | - function espresso_organization_twitter( $echo = TRUE ) { |
|
| 810 | - if($echo){ |
|
| 811 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' ); |
|
| 809 | + function espresso_organization_twitter($echo = TRUE) { |
|
| 810 | + if ($echo) { |
|
| 811 | + echo EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
| 812 | 812 | return ''; |
| 813 | 813 | } |
| 814 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' ); |
|
| 814 | + return EE_Registry::instance()->CFG->organization->get_pretty('twitter'); |
|
| 815 | 815 | } |
| 816 | 816 | } |
| 817 | 817 | |
| 818 | -if ( ! function_exists( 'espresso_organization_linkedin' )) { |
|
| 818 | +if ( ! function_exists('espresso_organization_linkedin')) { |
|
| 819 | 819 | /** |
| 820 | 820 | * espresso_organization_linkedin |
| 821 | 821 | * @param bool $echo |
| 822 | 822 | * @return string |
| 823 | 823 | */ |
| 824 | - function espresso_organization_linkedin( $echo = TRUE ) { |
|
| 825 | - if($echo){ |
|
| 826 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' ); |
|
| 824 | + function espresso_organization_linkedin($echo = TRUE) { |
|
| 825 | + if ($echo) { |
|
| 826 | + echo EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
| 827 | 827 | return ''; |
| 828 | 828 | } |
| 829 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' ); |
|
| 829 | + return EE_Registry::instance()->CFG->organization->get_pretty('linkedin'); |
|
| 830 | 830 | } |
| 831 | 831 | } |
| 832 | 832 | |
| 833 | -if ( ! function_exists( 'espresso_organization_pinterest' )) { |
|
| 833 | +if ( ! function_exists('espresso_organization_pinterest')) { |
|
| 834 | 834 | /** |
| 835 | 835 | * espresso_organization_pinterest |
| 836 | 836 | * @param bool $echo |
| 837 | 837 | * @return string |
| 838 | 838 | */ |
| 839 | - function espresso_organization_pinterest( $echo = TRUE ) { |
|
| 840 | - if($echo){ |
|
| 841 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' ); |
|
| 839 | + function espresso_organization_pinterest($echo = TRUE) { |
|
| 840 | + if ($echo) { |
|
| 841 | + echo EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
| 842 | 842 | return ''; |
| 843 | 843 | } |
| 844 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' ); |
|
| 844 | + return EE_Registry::instance()->CFG->organization->get_pretty('pinterest'); |
|
| 845 | 845 | } |
| 846 | 846 | } |
| 847 | 847 | |
| 848 | -if ( ! function_exists( 'espresso_organization_google' )) { |
|
| 848 | +if ( ! function_exists('espresso_organization_google')) { |
|
| 849 | 849 | /** |
| 850 | 850 | * espresso_organization_google |
| 851 | 851 | * @param bool $echo |
| 852 | 852 | * @return string |
| 853 | 853 | */ |
| 854 | - function espresso_organization_google( $echo = TRUE ) { |
|
| 855 | - if($echo){ |
|
| 856 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'google' ); |
|
| 854 | + function espresso_organization_google($echo = TRUE) { |
|
| 855 | + if ($echo) { |
|
| 856 | + echo EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
| 857 | 857 | return ''; |
| 858 | 858 | } |
| 859 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'google' ); |
|
| 859 | + return EE_Registry::instance()->CFG->organization->get_pretty('google'); |
|
| 860 | 860 | } |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | -if ( ! function_exists( 'espresso_organization_instagram' )) { |
|
| 863 | +if ( ! function_exists('espresso_organization_instagram')) { |
|
| 864 | 864 | /** |
| 865 | 865 | * espresso_organization_instagram |
| 866 | 866 | * @param bool $echo |
| 867 | 867 | * @return string |
| 868 | 868 | */ |
| 869 | - function espresso_organization_instagram( $echo = TRUE ) { |
|
| 870 | - if($echo){ |
|
| 871 | - echo EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' ); |
|
| 869 | + function espresso_organization_instagram($echo = TRUE) { |
|
| 870 | + if ($echo) { |
|
| 871 | + echo EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
| 872 | 872 | return ''; |
| 873 | 873 | } |
| 874 | - return EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' ); |
|
| 874 | + return EE_Registry::instance()->CFG->organization->get_pretty('instagram'); |
|
| 875 | 875 | } |
| 876 | 876 | } |
| 877 | 877 | |
@@ -881,7 +881,7 @@ discard block |
||
| 881 | 881 | |
| 882 | 882 | |
| 883 | 883 | |
| 884 | -if ( ! function_exists( 'espresso_event_venues' )) { |
|
| 884 | +if ( ! function_exists('espresso_event_venues')) { |
|
| 885 | 885 | /** |
| 886 | 886 | * espresso_event_venues |
| 887 | 887 | * |
@@ -895,7 +895,7 @@ discard block |
||
| 895 | 895 | |
| 896 | 896 | |
| 897 | 897 | |
| 898 | -if ( ! function_exists( 'espresso_venue_id' )) { |
|
| 898 | +if ( ! function_exists('espresso_venue_id')) { |
|
| 899 | 899 | /** |
| 900 | 900 | * espresso_venue_name |
| 901 | 901 | * |
@@ -903,15 +903,15 @@ discard block |
||
| 903 | 903 | * @param int $EVT_ID |
| 904 | 904 | * @return string |
| 905 | 905 | */ |
| 906 | - function espresso_venue_id( $EVT_ID = 0 ) { |
|
| 907 | - $venue = EEH_Venue_View::get_venue( $EVT_ID ); |
|
| 906 | + function espresso_venue_id($EVT_ID = 0) { |
|
| 907 | + $venue = EEH_Venue_View::get_venue($EVT_ID); |
|
| 908 | 908 | return $venue instanceof EE_Venue ? $venue->ID() : 0; |
| 909 | 909 | } |
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | |
| 913 | 913 | |
| 914 | -if ( ! function_exists( 'espresso_is_venue_private' ) ) { |
|
| 914 | +if ( ! function_exists('espresso_is_venue_private')) { |
|
| 915 | 915 | /** |
| 916 | 916 | * Return whether a venue is private or not. |
| 917 | 917 | * @see EEH_Venue_View::get_venue() for more info on expected return results. |
@@ -920,45 +920,45 @@ discard block |
||
| 920 | 920 | * |
| 921 | 921 | * @return bool | null |
| 922 | 922 | */ |
| 923 | - function espresso_is_venue_private( $VNU_ID = 0 ) { |
|
| 924 | - return EEH_Venue_View::is_venue_private( $VNU_ID ); |
|
| 923 | + function espresso_is_venue_private($VNU_ID = 0) { |
|
| 924 | + return EEH_Venue_View::is_venue_private($VNU_ID); |
|
| 925 | 925 | } |
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | |
| 929 | 929 | |
| 930 | -if ( ! function_exists( 'espresso_venue_is_password_protected' ) ) { |
|
| 930 | +if ( ! function_exists('espresso_venue_is_password_protected')) { |
|
| 931 | 931 | /** |
| 932 | 932 | * returns true or false if a venue is password protected or not |
| 933 | 933 | * |
| 934 | 934 | * @param int $VNU_ID optional, the venue id to check. |
| 935 | 935 | * @return string |
| 936 | 936 | */ |
| 937 | - function espresso_venue_is_password_protected( $VNU_ID = 0 ) { |
|
| 938 | - EE_Registry::instance()->load_helper( 'Venue_View' ); |
|
| 939 | - return EEH_Venue_View::is_venue_password_protected( $VNU_ID ); |
|
| 937 | + function espresso_venue_is_password_protected($VNU_ID = 0) { |
|
| 938 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
| 939 | + return EEH_Venue_View::is_venue_password_protected($VNU_ID); |
|
| 940 | 940 | } |
| 941 | 941 | } |
| 942 | 942 | |
| 943 | 943 | |
| 944 | 944 | |
| 945 | -if ( ! function_exists( 'espresso_password_protected_venue_form' ) ) { |
|
| 945 | +if ( ! function_exists('espresso_password_protected_venue_form')) { |
|
| 946 | 946 | /** |
| 947 | 947 | * Returns a password form if venue is password protected. |
| 948 | 948 | * |
| 949 | 949 | * @param int $VNU_ID optional, the venue id to check. |
| 950 | 950 | * @return string |
| 951 | 951 | */ |
| 952 | - function espresso_password_protected_venue_form( $VNU_ID = 0 ) { |
|
| 953 | - EE_Registry::instance()->load_helper( 'Venue_View' ); |
|
| 954 | - return EEH_Venue_View::password_protected_venue_form( $VNU_ID ); |
|
| 952 | + function espresso_password_protected_venue_form($VNU_ID = 0) { |
|
| 953 | + EE_Registry::instance()->load_helper('Venue_View'); |
|
| 954 | + return EEH_Venue_View::password_protected_venue_form($VNU_ID); |
|
| 955 | 955 | } |
| 956 | 956 | } |
| 957 | 957 | |
| 958 | 958 | |
| 959 | 959 | |
| 960 | 960 | |
| 961 | -if ( ! function_exists( 'espresso_venue_name' )) { |
|
| 961 | +if ( ! function_exists('espresso_venue_name')) { |
|
| 962 | 962 | /** |
| 963 | 963 | * espresso_venue_name |
| 964 | 964 | * |
@@ -968,19 +968,19 @@ discard block |
||
| 968 | 968 | * @param bool $echo |
| 969 | 969 | * @return string |
| 970 | 970 | */ |
| 971 | - function espresso_venue_name( $VNU_ID = 0, $link_to = 'details', $echo = TRUE ) { |
|
| 972 | - if($echo){ |
|
| 973 | - echo EEH_Venue_View::venue_name( $link_to, $VNU_ID ); |
|
| 971 | + function espresso_venue_name($VNU_ID = 0, $link_to = 'details', $echo = TRUE) { |
|
| 972 | + if ($echo) { |
|
| 973 | + echo EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
| 974 | 974 | return ''; |
| 975 | 975 | } |
| 976 | - return EEH_Venue_View::venue_name( $link_to, $VNU_ID ); |
|
| 976 | + return EEH_Venue_View::venue_name($link_to, $VNU_ID); |
|
| 977 | 977 | } |
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | |
| 981 | 981 | |
| 982 | 982 | |
| 983 | -if ( ! function_exists( 'espresso_venue_link' )) { |
|
| 983 | +if ( ! function_exists('espresso_venue_link')) { |
|
| 984 | 984 | /** |
| 985 | 985 | * espresso_venue_link |
| 986 | 986 | * |
@@ -989,14 +989,14 @@ discard block |
||
| 989 | 989 | * @param string $text |
| 990 | 990 | * @return string |
| 991 | 991 | */ |
| 992 | - function espresso_venue_link( $VNU_ID = 0, $text = '' ) { |
|
| 993 | - return EEH_Venue_View::venue_details_link( $VNU_ID, $text ); |
|
| 992 | + function espresso_venue_link($VNU_ID = 0, $text = '') { |
|
| 993 | + return EEH_Venue_View::venue_details_link($VNU_ID, $text); |
|
| 994 | 994 | } |
| 995 | 995 | } |
| 996 | 996 | |
| 997 | 997 | |
| 998 | 998 | |
| 999 | -if ( ! function_exists( 'espresso_venue_description' )) { |
|
| 999 | +if ( ! function_exists('espresso_venue_description')) { |
|
| 1000 | 1000 | /** |
| 1001 | 1001 | * espresso_venue_description |
| 1002 | 1002 | * |
@@ -1005,17 +1005,17 @@ discard block |
||
| 1005 | 1005 | * @param bool $echo |
| 1006 | 1006 | * @return string |
| 1007 | 1007 | */ |
| 1008 | - function espresso_venue_description( $VNU_ID = FALSE, $echo = TRUE ) { |
|
| 1009 | - if($echo){ |
|
| 1010 | - echo EEH_Venue_View::venue_description( $VNU_ID ); |
|
| 1008 | + function espresso_venue_description($VNU_ID = FALSE, $echo = TRUE) { |
|
| 1009 | + if ($echo) { |
|
| 1010 | + echo EEH_Venue_View::venue_description($VNU_ID); |
|
| 1011 | 1011 | return ''; |
| 1012 | 1012 | } |
| 1013 | - return EEH_Venue_View::venue_description( $VNU_ID ); |
|
| 1013 | + return EEH_Venue_View::venue_description($VNU_ID); |
|
| 1014 | 1014 | } |
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | 1017 | |
| 1018 | -if ( ! function_exists( 'espresso_venue_excerpt' )) { |
|
| 1018 | +if ( ! function_exists('espresso_venue_excerpt')) { |
|
| 1019 | 1019 | /** |
| 1020 | 1020 | * espresso_venue_excerpt |
| 1021 | 1021 | * |
@@ -1024,18 +1024,18 @@ discard block |
||
| 1024 | 1024 | * @param bool $echo |
| 1025 | 1025 | * @return string |
| 1026 | 1026 | */ |
| 1027 | - function espresso_venue_excerpt( $VNU_ID = 0, $echo = TRUE ) { |
|
| 1028 | - if ( $echo ) { |
|
| 1029 | - echo EEH_Venue_View::venue_excerpt( $VNU_ID ); |
|
| 1027 | + function espresso_venue_excerpt($VNU_ID = 0, $echo = TRUE) { |
|
| 1028 | + if ($echo) { |
|
| 1029 | + echo EEH_Venue_View::venue_excerpt($VNU_ID); |
|
| 1030 | 1030 | return ''; |
| 1031 | 1031 | } |
| 1032 | - return EEH_Venue_View::venue_excerpt( $VNU_ID ); |
|
| 1032 | + return EEH_Venue_View::venue_excerpt($VNU_ID); |
|
| 1033 | 1033 | } |
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | |
| 1037 | 1037 | |
| 1038 | -if ( ! function_exists( 'espresso_venue_categories' )) { |
|
| 1038 | +if ( ! function_exists('espresso_venue_categories')) { |
|
| 1039 | 1039 | /** |
| 1040 | 1040 | * espresso_venue_categories |
| 1041 | 1041 | * returns the terms associated with a venue |
@@ -1045,17 +1045,17 @@ discard block |
||
| 1045 | 1045 | * @param bool $echo |
| 1046 | 1046 | * @return string |
| 1047 | 1047 | */ |
| 1048 | - function espresso_venue_categories( $VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) { |
|
| 1049 | - if ( $echo ) { |
|
| 1050 | - echo EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized ); |
|
| 1048 | + function espresso_venue_categories($VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) { |
|
| 1049 | + if ($echo) { |
|
| 1050 | + echo EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
| 1051 | 1051 | return ''; |
| 1052 | 1052 | } |
| 1053 | - return EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized ); |
|
| 1053 | + return EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized); |
|
| 1054 | 1054 | } |
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | |
| 1058 | -if ( ! function_exists( 'espresso_venue_address' )) { |
|
| 1058 | +if ( ! function_exists('espresso_venue_address')) { |
|
| 1059 | 1059 | /** |
| 1060 | 1060 | * espresso_venue_address |
| 1061 | 1061 | * returns a formatted block of html for displaying a venue's address |
@@ -1065,17 +1065,17 @@ discard block |
||
| 1065 | 1065 | * @param bool $echo |
| 1066 | 1066 | * @return string |
| 1067 | 1067 | */ |
| 1068 | - function espresso_venue_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) { |
|
| 1069 | - if ( $echo ) { |
|
| 1070 | - echo EEH_Venue_View::venue_address( $type, $VNU_ID ); |
|
| 1068 | + function espresso_venue_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) { |
|
| 1069 | + if ($echo) { |
|
| 1070 | + echo EEH_Venue_View::venue_address($type, $VNU_ID); |
|
| 1071 | 1071 | return ''; |
| 1072 | 1072 | } |
| 1073 | - return EEH_Venue_View::venue_address( $type, $VNU_ID ); |
|
| 1073 | + return EEH_Venue_View::venue_address($type, $VNU_ID); |
|
| 1074 | 1074 | } |
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | |
| 1078 | -if ( ! function_exists( 'espresso_venue_raw_address' )) { |
|
| 1078 | +if ( ! function_exists('espresso_venue_raw_address')) { |
|
| 1079 | 1079 | /** |
| 1080 | 1080 | * espresso_venue_address |
| 1081 | 1081 | * returns an UN-formatted string containing a venue's address |
@@ -1085,17 +1085,17 @@ discard block |
||
| 1085 | 1085 | * @param bool $echo |
| 1086 | 1086 | * @return string |
| 1087 | 1087 | */ |
| 1088 | - function espresso_venue_raw_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) { |
|
| 1089 | - if ( $echo ) { |
|
| 1090 | - echo EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE ); |
|
| 1088 | + function espresso_venue_raw_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) { |
|
| 1089 | + if ($echo) { |
|
| 1090 | + echo EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE); |
|
| 1091 | 1091 | return ''; |
| 1092 | 1092 | } |
| 1093 | - return EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE ); |
|
| 1093 | + return EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE); |
|
| 1094 | 1094 | } |
| 1095 | 1095 | } |
| 1096 | 1096 | |
| 1097 | 1097 | |
| 1098 | -if ( ! function_exists( 'espresso_venue_has_address' )) { |
|
| 1098 | +if ( ! function_exists('espresso_venue_has_address')) { |
|
| 1099 | 1099 | /** |
| 1100 | 1100 | * espresso_venue_has_address |
| 1101 | 1101 | * returns TRUE or FALSE if a Venue has address information |
@@ -1103,13 +1103,13 @@ discard block |
||
| 1103 | 1103 | * @param int $VNU_ID |
| 1104 | 1104 | * @return bool |
| 1105 | 1105 | */ |
| 1106 | - function espresso_venue_has_address( $VNU_ID = 0 ) { |
|
| 1107 | - return EEH_Venue_View::venue_has_address( $VNU_ID ); |
|
| 1106 | + function espresso_venue_has_address($VNU_ID = 0) { |
|
| 1107 | + return EEH_Venue_View::venue_has_address($VNU_ID); |
|
| 1108 | 1108 | } |
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | 1111 | |
| 1112 | -if ( ! function_exists( 'espresso_venue_gmap' )) { |
|
| 1112 | +if ( ! function_exists('espresso_venue_gmap')) { |
|
| 1113 | 1113 | /** |
| 1114 | 1114 | * espresso_venue_gmap |
| 1115 | 1115 | * returns a google map for the venue address |
@@ -1120,17 +1120,17 @@ discard block |
||
| 1120 | 1120 | * @param bool $echo |
| 1121 | 1121 | * @return string |
| 1122 | 1122 | */ |
| 1123 | - function espresso_venue_gmap( $VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE ) { |
|
| 1124 | - if ( $echo ) { |
|
| 1125 | - echo EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap ); |
|
| 1123 | + function espresso_venue_gmap($VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE) { |
|
| 1124 | + if ($echo) { |
|
| 1125 | + echo EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
| 1126 | 1126 | return ''; |
| 1127 | 1127 | } |
| 1128 | - return EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap ); |
|
| 1128 | + return EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap); |
|
| 1129 | 1129 | } |
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | 1132 | |
| 1133 | -if ( ! function_exists( 'espresso_venue_phone' )) { |
|
| 1133 | +if ( ! function_exists('espresso_venue_phone')) { |
|
| 1134 | 1134 | /** |
| 1135 | 1135 | * espresso_venue_phone |
| 1136 | 1136 | * |
@@ -1138,18 +1138,18 @@ discard block |
||
| 1138 | 1138 | * @param bool $echo |
| 1139 | 1139 | * @return string |
| 1140 | 1140 | */ |
| 1141 | - function espresso_venue_phone( $VNU_ID = 0, $echo = TRUE ) { |
|
| 1142 | - if ( $echo ) { |
|
| 1143 | - echo EEH_Venue_View::venue_phone( $VNU_ID ); |
|
| 1141 | + function espresso_venue_phone($VNU_ID = 0, $echo = TRUE) { |
|
| 1142 | + if ($echo) { |
|
| 1143 | + echo EEH_Venue_View::venue_phone($VNU_ID); |
|
| 1144 | 1144 | return ''; |
| 1145 | 1145 | } |
| 1146 | - return EEH_Venue_View::venue_phone( $VNU_ID ); |
|
| 1146 | + return EEH_Venue_View::venue_phone($VNU_ID); |
|
| 1147 | 1147 | } |
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | |
| 1151 | 1151 | |
| 1152 | -if ( ! function_exists( 'espresso_venue_website' )) { |
|
| 1152 | +if ( ! function_exists('espresso_venue_website')) { |
|
| 1153 | 1153 | /** |
| 1154 | 1154 | * espresso_venue_website |
| 1155 | 1155 | * |
@@ -1157,18 +1157,18 @@ discard block |
||
| 1157 | 1157 | * @param bool $echo |
| 1158 | 1158 | * @return string |
| 1159 | 1159 | */ |
| 1160 | - function espresso_venue_website( $VNU_ID = 0, $echo = TRUE ) { |
|
| 1161 | - if ( $echo ) { |
|
| 1162 | - echo EEH_Venue_View::venue_website_link( $VNU_ID ); |
|
| 1160 | + function espresso_venue_website($VNU_ID = 0, $echo = TRUE) { |
|
| 1161 | + if ($echo) { |
|
| 1162 | + echo EEH_Venue_View::venue_website_link($VNU_ID); |
|
| 1163 | 1163 | return ''; |
| 1164 | 1164 | } |
| 1165 | - return EEH_Venue_View::venue_website_link( $VNU_ID ); |
|
| 1165 | + return EEH_Venue_View::venue_website_link($VNU_ID); |
|
| 1166 | 1166 | } |
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | |
| 1170 | 1170 | |
| 1171 | -if ( ! function_exists( 'espresso_edit_venue_link' )) { |
|
| 1171 | +if ( ! function_exists('espresso_edit_venue_link')) { |
|
| 1172 | 1172 | /** |
| 1173 | 1173 | * espresso_edit_venue_link |
| 1174 | 1174 | * |
@@ -1176,12 +1176,12 @@ discard block |
||
| 1176 | 1176 | * @param bool $echo |
| 1177 | 1177 | * @return string |
| 1178 | 1178 | */ |
| 1179 | - function espresso_edit_venue_link( $VNU_ID = 0, $echo = TRUE ) { |
|
| 1180 | - if($echo){ |
|
| 1181 | - echo EEH_Venue_View::edit_venue_link( $VNU_ID ); |
|
| 1179 | + function espresso_edit_venue_link($VNU_ID = 0, $echo = TRUE) { |
|
| 1180 | + if ($echo) { |
|
| 1181 | + echo EEH_Venue_View::edit_venue_link($VNU_ID); |
|
| 1182 | 1182 | return ''; |
| 1183 | 1183 | } |
| 1184 | - return EEH_Venue_View::edit_venue_link( $VNU_ID ); |
|
| 1184 | + return EEH_Venue_View::edit_venue_link($VNU_ID); |
|
| 1185 | 1185 | } |
| 1186 | 1186 | } |
| 1187 | 1187 | |
@@ -11,578 +11,578 @@ |
||
| 11 | 11 | class EEH_Event_View extends EEH_Base |
| 12 | 12 | { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @var EE_Event $_event |
|
| 16 | - */ |
|
| 17 | - private static $_event = null; |
|
| 18 | - |
|
| 19 | - |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * get_event |
|
| 23 | - * attempts to retrieve an EE_Event object any way it can |
|
| 24 | - * |
|
| 25 | - * @param int|WP_Post $EVT_ID |
|
| 26 | - * @return EE_Event|null |
|
| 27 | - * @throws \EE_Error |
|
| 28 | - */ |
|
| 29 | - public static function get_event($EVT_ID = 0) |
|
| 30 | - { |
|
| 31 | - // international newspaper? |
|
| 32 | - global $post; |
|
| 33 | - $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events' |
|
| 34 | - ? $EVT_ID->ID |
|
| 35 | - : absint($EVT_ID); |
|
| 36 | - // do we already have the Event you are looking for? |
|
| 37 | - if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) { |
|
| 38 | - return EEH_Event_View::$_event; |
|
| 39 | - } |
|
| 40 | - // reset property so that the new event is cached. |
|
| 41 | - EEH_Event_View::$_event = null; |
|
| 42 | - if (! $EVT_ID && $post instanceof EE_Event) { |
|
| 43 | - EEH_Event_View::$_event = $post; |
|
| 44 | - return EEH_Event_View::$_event; |
|
| 45 | - } |
|
| 46 | - // if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID |
|
| 47 | - // then let's just use that cached event on the $post object. |
|
| 48 | - if ($post instanceof WP_Post |
|
| 49 | - && $post->post_type === 'espresso_events' |
|
| 50 | - && isset($post->EE_Event) |
|
| 51 | - && ( |
|
| 52 | - $EVT_ID === 0 |
|
| 53 | - || $EVT_ID === $post->ID |
|
| 54 | - ) |
|
| 55 | - ) { |
|
| 56 | - EEH_Event_View::$_event = $post->EE_Event; |
|
| 57 | - return EEH_Event_View::$_event; |
|
| 58 | - } |
|
| 59 | - // If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID. |
|
| 60 | - if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
| 61 | - EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 62 | - } |
|
| 63 | - return EEH_Event_View::$_event; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * display_ticket_selector |
|
| 70 | - * |
|
| 71 | - * @access public |
|
| 72 | - * @param int $EVT_ID |
|
| 73 | - * @return boolean |
|
| 74 | - */ |
|
| 75 | - public static function display_ticket_selector($EVT_ID = 0) |
|
| 76 | - { |
|
| 77 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 78 | - return $event instanceof EE_Event ? $event->display_ticket_selector() : false; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * event_status |
|
| 85 | - * |
|
| 86 | - * @access public |
|
| 87 | - * @param int $EVT_ID |
|
| 88 | - * @return string |
|
| 89 | - */ |
|
| 90 | - public static function event_status($EVT_ID = 0) |
|
| 91 | - { |
|
| 92 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 93 | - return $event instanceof EE_Event ? $event->pretty_active_status(false) : ''; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * event_active_status |
|
| 100 | - * |
|
| 101 | - * @access public |
|
| 102 | - * @param int $EVT_ID |
|
| 103 | - * @return string |
|
| 104 | - */ |
|
| 105 | - public static function event_active_status($EVT_ID = 0, $echo = true) |
|
| 106 | - { |
|
| 107 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 108 | - return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive'; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * event_has_content_or_excerpt |
|
| 115 | - * |
|
| 116 | - * @access public |
|
| 117 | - * @param int $EVT_ID |
|
| 118 | - * @return string |
|
| 119 | - */ |
|
| 120 | - public static function event_has_content_or_excerpt($EVT_ID = 0) |
|
| 121 | - { |
|
| 122 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 123 | - $has_content_or_excerpt = false; |
|
| 124 | - if ($event instanceof EE_Event) { |
|
| 125 | - $has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != '' ? true : false; |
|
| 126 | - } |
|
| 127 | - if (is_archive() && ! ( espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list() )) { |
|
| 128 | - $has_content_or_excerpt = false; |
|
| 129 | - } |
|
| 130 | - return $has_content_or_excerpt; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * event_active_status |
|
| 137 | - * |
|
| 138 | - * @access public |
|
| 139 | - * @param null $num_words |
|
| 140 | - * @param null $more |
|
| 141 | - * @return string |
|
| 142 | - */ |
|
| 143 | - public static function event_content_or_excerpt($num_words = null, $more = null) |
|
| 144 | - { |
|
| 145 | - global $post; |
|
| 146 | - ob_start(); |
|
| 147 | - if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) { |
|
| 148 | - // admin has chosen "full description" |
|
| 149 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
| 150 | - the_content(); |
|
| 151 | - } elseif (( is_archive() && espresso_display_excerpt_in_event_list() )) { |
|
| 152 | - if (has_excerpt($post->ID)) { |
|
| 153 | - // admin has chosen "excerpt (short desc)" |
|
| 154 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
| 155 | - // AND an excerpt actually exists |
|
| 156 | - the_excerpt(); |
|
| 157 | - } else { |
|
| 158 | - // admin has chosen "excerpt (short desc)" |
|
| 159 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
| 160 | - // but NO excerpt actually exists, so we need to create one |
|
| 161 | - if (! empty($num_words)) { |
|
| 162 | - if (empty($more)) { |
|
| 163 | - $more_link_text = __('(more…)', 'event_espresso'); |
|
| 164 | - $more = ' <a href="' . get_permalink() . '"'; |
|
| 165 | - $more .= ' class="more-link"'; |
|
| 166 | - $more .= \EED_Events_Archive::link_target(); |
|
| 167 | - $more .= '>' . $more_link_text . '</a>'; |
|
| 168 | - $more = apply_filters('the_content_more_link', $more, $more_link_text); |
|
| 169 | - } |
|
| 170 | - $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK')); |
|
| 171 | - |
|
| 172 | - $content = wp_trim_words($content, $num_words, ' ') . $more; |
|
| 173 | - } else { |
|
| 174 | - $content = get_the_content(); |
|
| 175 | - } |
|
| 176 | - global $allowedtags; |
|
| 177 | - // make sure links are allowed |
|
| 178 | - $allowedtags['a'] = isset($allowedtags['a']) |
|
| 179 | - ? $allowedtags['a'] |
|
| 180 | - : array(); |
|
| 181 | - // as well as target attribute |
|
| 182 | - $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
| 183 | - ? $allowedtags['a']['target'] |
|
| 184 | - : false; |
|
| 185 | - // but get previous value so we can reset it |
|
| 186 | - $prev_value = $allowedtags['a']['target']; |
|
| 187 | - $allowedtags['a']['target'] = true; |
|
| 188 | - $content = wp_kses($content, $allowedtags); |
|
| 189 | - $content = strip_shortcodes($content); |
|
| 190 | - echo apply_filters('the_content', $content); |
|
| 191 | - $allowedtags['a']['target'] = $prev_value; |
|
| 192 | - } |
|
| 193 | - } else { |
|
| 194 | - // admin has chosen "none" |
|
| 195 | - // for the "Event Espresso - Events > Templates > Display Description" option |
|
| 196 | - echo apply_filters('the_content', ''); |
|
| 197 | - } |
|
| 198 | - return ob_get_clean(); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * event_tickets_available |
|
| 205 | - * |
|
| 206 | - * @access public |
|
| 207 | - * @param int $EVT_ID |
|
| 208 | - * @return EE_Ticket[] |
|
| 209 | - */ |
|
| 210 | - public static function event_tickets_available($EVT_ID = 0) |
|
| 211 | - { |
|
| 212 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 213 | - $tickets_available_for_purchase = array(); |
|
| 214 | - if ($event instanceof EE_Event) { |
|
| 215 | - $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, false); |
|
| 216 | - foreach ($datetimes as $datetime) { |
|
| 217 | - $tickets_available_for_purchase = array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase()); |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - return $tickets_available_for_purchase; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - |
|
| 225 | - /** |
|
| 226 | - * the_event_date |
|
| 227 | - * |
|
| 228 | - * @access public |
|
| 229 | - * @param int $EVT_ID |
|
| 230 | - * @param bool $hide_uncategorized |
|
| 231 | - * @return string |
|
| 232 | - */ |
|
| 233 | - public static function event_categories($EVT_ID = 0, $hide_uncategorized = true) |
|
| 234 | - { |
|
| 235 | - $category_links = array(); |
|
| 236 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 237 | - if ($event instanceof EE_Event) { |
|
| 238 | - $event_categories = get_the_terms($event->ID(), 'espresso_event_categories'); |
|
| 239 | - if ($event_categories) { |
|
| 240 | - // loop thru terms and create links |
|
| 241 | - foreach ($event_categories as $term) { |
|
| 242 | - $url = get_term_link($term, 'espresso_venue_categories'); |
|
| 243 | - if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) { |
|
| 244 | - $category_links[] = '<a href="' . esc_url($url) |
|
| 245 | - . '" rel="tag"' |
|
| 246 | - . \EED_Events_Archive::link_target() |
|
| 247 | - .'>' |
|
| 248 | - . $term->name |
|
| 249 | - . '</a>'; |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - return implode(', ', $category_links); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * the_event_date - first date by date order |
|
| 261 | - * |
|
| 262 | - * @access public |
|
| 263 | - * @param string $dt_frmt |
|
| 264 | - * @param string $tm_frmt |
|
| 265 | - * @param int $EVT_ID |
|
| 266 | - * @return string |
|
| 267 | - */ |
|
| 268 | - public static function the_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) |
|
| 269 | - { |
|
| 270 | - $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
| 271 | - $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 272 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * the_event_end_date - last date by date order |
|
| 279 | - * |
|
| 280 | - * @access public |
|
| 281 | - * @param string $dt_frmt |
|
| 282 | - * @param string $tm_frmt |
|
| 283 | - * @param int $EVT_ID |
|
| 284 | - * @return string |
|
| 285 | - */ |
|
| 286 | - public static function the_event_end_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) |
|
| 287 | - { |
|
| 288 | - $datetime = EEH_Event_View::get_last_date_obj($EVT_ID); |
|
| 289 | - $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 290 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * the_earliest_event_date - first date chronologically |
|
| 297 | - * |
|
| 298 | - * @access public |
|
| 299 | - * @param string $dt_frmt |
|
| 300 | - * @param string $tm_frmt |
|
| 301 | - * @param int $EVT_ID |
|
| 302 | - * @return string |
|
| 303 | - */ |
|
| 304 | - public static function the_earliest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) |
|
| 305 | - { |
|
| 306 | - $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID); |
|
| 307 | - $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 308 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * the_latest_event_date - latest date chronologically |
|
| 315 | - * |
|
| 316 | - * @access public |
|
| 317 | - * @param string $dt_frmt |
|
| 318 | - * @param string $tm_frmt |
|
| 319 | - * @param int $EVT_ID |
|
| 320 | - * @return string |
|
| 321 | - */ |
|
| 322 | - public static function the_latest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) |
|
| 323 | - { |
|
| 324 | - $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID); |
|
| 325 | - $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 326 | - return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * event_date_as_calendar_page |
|
| 333 | - * |
|
| 334 | - * @access public |
|
| 335 | - * @param int $EVT_ID |
|
| 336 | - * @return string |
|
| 337 | - */ |
|
| 338 | - public static function event_date_as_calendar_page($EVT_ID = 0) |
|
| 339 | - { |
|
| 340 | - $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
| 341 | - if ($datetime instanceof EE_Datetime) { |
|
| 342 | - ?> |
|
| 14 | + /** |
|
| 15 | + * @var EE_Event $_event |
|
| 16 | + */ |
|
| 17 | + private static $_event = null; |
|
| 18 | + |
|
| 19 | + |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * get_event |
|
| 23 | + * attempts to retrieve an EE_Event object any way it can |
|
| 24 | + * |
|
| 25 | + * @param int|WP_Post $EVT_ID |
|
| 26 | + * @return EE_Event|null |
|
| 27 | + * @throws \EE_Error |
|
| 28 | + */ |
|
| 29 | + public static function get_event($EVT_ID = 0) |
|
| 30 | + { |
|
| 31 | + // international newspaper? |
|
| 32 | + global $post; |
|
| 33 | + $EVT_ID = $EVT_ID instanceof WP_Post && $EVT_ID->post_type === 'espresso_events' |
|
| 34 | + ? $EVT_ID->ID |
|
| 35 | + : absint($EVT_ID); |
|
| 36 | + // do we already have the Event you are looking for? |
|
| 37 | + if (EEH_Event_View::$_event instanceof EE_Event && $EVT_ID && EEH_Event_View::$_event->ID() === $EVT_ID) { |
|
| 38 | + return EEH_Event_View::$_event; |
|
| 39 | + } |
|
| 40 | + // reset property so that the new event is cached. |
|
| 41 | + EEH_Event_View::$_event = null; |
|
| 42 | + if (! $EVT_ID && $post instanceof EE_Event) { |
|
| 43 | + EEH_Event_View::$_event = $post; |
|
| 44 | + return EEH_Event_View::$_event; |
|
| 45 | + } |
|
| 46 | + // if the post type is for an event and it has a cached event and we don't have a different incoming $EVT_ID |
|
| 47 | + // then let's just use that cached event on the $post object. |
|
| 48 | + if ($post instanceof WP_Post |
|
| 49 | + && $post->post_type === 'espresso_events' |
|
| 50 | + && isset($post->EE_Event) |
|
| 51 | + && ( |
|
| 52 | + $EVT_ID === 0 |
|
| 53 | + || $EVT_ID === $post->ID |
|
| 54 | + ) |
|
| 55 | + ) { |
|
| 56 | + EEH_Event_View::$_event = $post->EE_Event; |
|
| 57 | + return EEH_Event_View::$_event; |
|
| 58 | + } |
|
| 59 | + // If the event we have isn't an event but we do have an EVT_ID, let's try getting the event using the ID. |
|
| 60 | + if (! EEH_Event_View::$_event instanceof EE_Event && $EVT_ID) { |
|
| 61 | + EEH_Event_View::$_event = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
| 62 | + } |
|
| 63 | + return EEH_Event_View::$_event; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * display_ticket_selector |
|
| 70 | + * |
|
| 71 | + * @access public |
|
| 72 | + * @param int $EVT_ID |
|
| 73 | + * @return boolean |
|
| 74 | + */ |
|
| 75 | + public static function display_ticket_selector($EVT_ID = 0) |
|
| 76 | + { |
|
| 77 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 78 | + return $event instanceof EE_Event ? $event->display_ticket_selector() : false; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * event_status |
|
| 85 | + * |
|
| 86 | + * @access public |
|
| 87 | + * @param int $EVT_ID |
|
| 88 | + * @return string |
|
| 89 | + */ |
|
| 90 | + public static function event_status($EVT_ID = 0) |
|
| 91 | + { |
|
| 92 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 93 | + return $event instanceof EE_Event ? $event->pretty_active_status(false) : ''; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * event_active_status |
|
| 100 | + * |
|
| 101 | + * @access public |
|
| 102 | + * @param int $EVT_ID |
|
| 103 | + * @return string |
|
| 104 | + */ |
|
| 105 | + public static function event_active_status($EVT_ID = 0, $echo = true) |
|
| 106 | + { |
|
| 107 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 108 | + return $event instanceof EE_Event ? $event->pretty_active_status($echo) : 'inactive'; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * event_has_content_or_excerpt |
|
| 115 | + * |
|
| 116 | + * @access public |
|
| 117 | + * @param int $EVT_ID |
|
| 118 | + * @return string |
|
| 119 | + */ |
|
| 120 | + public static function event_has_content_or_excerpt($EVT_ID = 0) |
|
| 121 | + { |
|
| 122 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 123 | + $has_content_or_excerpt = false; |
|
| 124 | + if ($event instanceof EE_Event) { |
|
| 125 | + $has_content_or_excerpt = $event->description() != '' || $event->short_description(null, null, true) != '' ? true : false; |
|
| 126 | + } |
|
| 127 | + if (is_archive() && ! ( espresso_display_full_description_in_event_list() || espresso_display_excerpt_in_event_list() )) { |
|
| 128 | + $has_content_or_excerpt = false; |
|
| 129 | + } |
|
| 130 | + return $has_content_or_excerpt; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * event_active_status |
|
| 137 | + * |
|
| 138 | + * @access public |
|
| 139 | + * @param null $num_words |
|
| 140 | + * @param null $more |
|
| 141 | + * @return string |
|
| 142 | + */ |
|
| 143 | + public static function event_content_or_excerpt($num_words = null, $more = null) |
|
| 144 | + { |
|
| 145 | + global $post; |
|
| 146 | + ob_start(); |
|
| 147 | + if (( is_single() ) || ( is_archive() && espresso_display_full_description_in_event_list() )) { |
|
| 148 | + // admin has chosen "full description" |
|
| 149 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
| 150 | + the_content(); |
|
| 151 | + } elseif (( is_archive() && espresso_display_excerpt_in_event_list() )) { |
|
| 152 | + if (has_excerpt($post->ID)) { |
|
| 153 | + // admin has chosen "excerpt (short desc)" |
|
| 154 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
| 155 | + // AND an excerpt actually exists |
|
| 156 | + the_excerpt(); |
|
| 157 | + } else { |
|
| 158 | + // admin has chosen "excerpt (short desc)" |
|
| 159 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
| 160 | + // but NO excerpt actually exists, so we need to create one |
|
| 161 | + if (! empty($num_words)) { |
|
| 162 | + if (empty($more)) { |
|
| 163 | + $more_link_text = __('(more…)', 'event_espresso'); |
|
| 164 | + $more = ' <a href="' . get_permalink() . '"'; |
|
| 165 | + $more .= ' class="more-link"'; |
|
| 166 | + $more .= \EED_Events_Archive::link_target(); |
|
| 167 | + $more .= '>' . $more_link_text . '</a>'; |
|
| 168 | + $more = apply_filters('the_content_more_link', $more, $more_link_text); |
|
| 169 | + } |
|
| 170 | + $content = str_replace('NOMORELINK', '', get_the_content('NOMORELINK')); |
|
| 171 | + |
|
| 172 | + $content = wp_trim_words($content, $num_words, ' ') . $more; |
|
| 173 | + } else { |
|
| 174 | + $content = get_the_content(); |
|
| 175 | + } |
|
| 176 | + global $allowedtags; |
|
| 177 | + // make sure links are allowed |
|
| 178 | + $allowedtags['a'] = isset($allowedtags['a']) |
|
| 179 | + ? $allowedtags['a'] |
|
| 180 | + : array(); |
|
| 181 | + // as well as target attribute |
|
| 182 | + $allowedtags['a']['target'] = isset($allowedtags['a']['target']) |
|
| 183 | + ? $allowedtags['a']['target'] |
|
| 184 | + : false; |
|
| 185 | + // but get previous value so we can reset it |
|
| 186 | + $prev_value = $allowedtags['a']['target']; |
|
| 187 | + $allowedtags['a']['target'] = true; |
|
| 188 | + $content = wp_kses($content, $allowedtags); |
|
| 189 | + $content = strip_shortcodes($content); |
|
| 190 | + echo apply_filters('the_content', $content); |
|
| 191 | + $allowedtags['a']['target'] = $prev_value; |
|
| 192 | + } |
|
| 193 | + } else { |
|
| 194 | + // admin has chosen "none" |
|
| 195 | + // for the "Event Espresso - Events > Templates > Display Description" option |
|
| 196 | + echo apply_filters('the_content', ''); |
|
| 197 | + } |
|
| 198 | + return ob_get_clean(); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * event_tickets_available |
|
| 205 | + * |
|
| 206 | + * @access public |
|
| 207 | + * @param int $EVT_ID |
|
| 208 | + * @return EE_Ticket[] |
|
| 209 | + */ |
|
| 210 | + public static function event_tickets_available($EVT_ID = 0) |
|
| 211 | + { |
|
| 212 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 213 | + $tickets_available_for_purchase = array(); |
|
| 214 | + if ($event instanceof EE_Event) { |
|
| 215 | + $datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, false); |
|
| 216 | + foreach ($datetimes as $datetime) { |
|
| 217 | + $tickets_available_for_purchase = array_merge($tickets_available_for_purchase, $datetime->ticket_types_available_for_purchase()); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + return $tickets_available_for_purchase; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + |
|
| 225 | + /** |
|
| 226 | + * the_event_date |
|
| 227 | + * |
|
| 228 | + * @access public |
|
| 229 | + * @param int $EVT_ID |
|
| 230 | + * @param bool $hide_uncategorized |
|
| 231 | + * @return string |
|
| 232 | + */ |
|
| 233 | + public static function event_categories($EVT_ID = 0, $hide_uncategorized = true) |
|
| 234 | + { |
|
| 235 | + $category_links = array(); |
|
| 236 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 237 | + if ($event instanceof EE_Event) { |
|
| 238 | + $event_categories = get_the_terms($event->ID(), 'espresso_event_categories'); |
|
| 239 | + if ($event_categories) { |
|
| 240 | + // loop thru terms and create links |
|
| 241 | + foreach ($event_categories as $term) { |
|
| 242 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
| 243 | + if (! is_wp_error($url) && (( $hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized )) { |
|
| 244 | + $category_links[] = '<a href="' . esc_url($url) |
|
| 245 | + . '" rel="tag"' |
|
| 246 | + . \EED_Events_Archive::link_target() |
|
| 247 | + .'>' |
|
| 248 | + . $term->name |
|
| 249 | + . '</a>'; |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + return implode(', ', $category_links); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * the_event_date - first date by date order |
|
| 261 | + * |
|
| 262 | + * @access public |
|
| 263 | + * @param string $dt_frmt |
|
| 264 | + * @param string $tm_frmt |
|
| 265 | + * @param int $EVT_ID |
|
| 266 | + * @return string |
|
| 267 | + */ |
|
| 268 | + public static function the_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) |
|
| 269 | + { |
|
| 270 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
| 271 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 272 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * the_event_end_date - last date by date order |
|
| 279 | + * |
|
| 280 | + * @access public |
|
| 281 | + * @param string $dt_frmt |
|
| 282 | + * @param string $tm_frmt |
|
| 283 | + * @param int $EVT_ID |
|
| 284 | + * @return string |
|
| 285 | + */ |
|
| 286 | + public static function the_event_end_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) |
|
| 287 | + { |
|
| 288 | + $datetime = EEH_Event_View::get_last_date_obj($EVT_ID); |
|
| 289 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 290 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * the_earliest_event_date - first date chronologically |
|
| 297 | + * |
|
| 298 | + * @access public |
|
| 299 | + * @param string $dt_frmt |
|
| 300 | + * @param string $tm_frmt |
|
| 301 | + * @param int $EVT_ID |
|
| 302 | + * @return string |
|
| 303 | + */ |
|
| 304 | + public static function the_earliest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) |
|
| 305 | + { |
|
| 306 | + $datetime = EEH_Event_View::get_earliest_date_obj($EVT_ID); |
|
| 307 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 308 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_start', $format) : ''; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * the_latest_event_date - latest date chronologically |
|
| 315 | + * |
|
| 316 | + * @access public |
|
| 317 | + * @param string $dt_frmt |
|
| 318 | + * @param string $tm_frmt |
|
| 319 | + * @param int $EVT_ID |
|
| 320 | + * @return string |
|
| 321 | + */ |
|
| 322 | + public static function the_latest_event_date($dt_frmt = 'D M jS', $tm_frmt = 'g:i a', $EVT_ID = 0) |
|
| 323 | + { |
|
| 324 | + $datetime = EEH_Event_View::get_latest_date_obj($EVT_ID); |
|
| 325 | + $format = ! empty($dt_frmt) && ! empty($tm_frmt) ? $dt_frmt . ' ' . $tm_frmt : $dt_frmt . $tm_frmt; |
|
| 326 | + return $datetime instanceof EE_Datetime ? $datetime->get_i18n_datetime('DTT_EVT_end', $format) : ''; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * event_date_as_calendar_page |
|
| 333 | + * |
|
| 334 | + * @access public |
|
| 335 | + * @param int $EVT_ID |
|
| 336 | + * @return string |
|
| 337 | + */ |
|
| 338 | + public static function event_date_as_calendar_page($EVT_ID = 0) |
|
| 339 | + { |
|
| 340 | + $datetime = EEH_Event_View::get_primary_date_obj($EVT_ID); |
|
| 341 | + if ($datetime instanceof EE_Datetime) { |
|
| 342 | + ?> |
|
| 343 | 343 | <div class="event-date-calendar-page-dv"> |
| 344 | 344 | <div class="event-date-calendar-page-month-dv"><?php echo $datetime->get_i18n_datetime('DTT_EVT_start', 'M');?></div> |
| 345 | 345 | <div class="event-date-calendar-page-day-dv"><?php echo $datetime->start_date('d');?></div> |
| 346 | 346 | </div> |
| 347 | 347 | <?php |
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * get_primary_date_obj - orders date by DTT_order |
|
| 355 | - * |
|
| 356 | - * @access public |
|
| 357 | - * @param int $EVT_ID |
|
| 358 | - * @return string |
|
| 359 | - */ |
|
| 360 | - public static function get_primary_date_obj($EVT_ID = 0) |
|
| 361 | - { |
|
| 362 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 363 | - if ($event instanceof EE_Event) { |
|
| 364 | - $datetimes = $event->get_many_related( |
|
| 365 | - 'Datetime', |
|
| 366 | - array( |
|
| 367 | - 'limit' => 1, |
|
| 368 | - 'order_by' => array( 'DTT_order' => 'ASC' ) |
|
| 369 | - ) |
|
| 370 | - ); |
|
| 371 | - return reset($datetimes); |
|
| 372 | - } else { |
|
| 373 | - return false; |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * get_last_date_obj - orders date by DTT_order |
|
| 381 | - * |
|
| 382 | - * @access public |
|
| 383 | - * @param int $EVT_ID |
|
| 384 | - * @return string |
|
| 385 | - */ |
|
| 386 | - public static function get_last_date_obj($EVT_ID = 0) |
|
| 387 | - { |
|
| 388 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 389 | - if ($event instanceof EE_Event) { |
|
| 390 | - $datetimes = $event->get_many_related( |
|
| 391 | - 'Datetime', |
|
| 392 | - array( |
|
| 393 | - 'limit' => 1, |
|
| 394 | - 'order_by' => array( 'DTT_order' => 'DESC' ) |
|
| 395 | - ) |
|
| 396 | - ); |
|
| 397 | - return end($datetimes); |
|
| 398 | - } else { |
|
| 399 | - return false; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * get_earliest_date_obj - orders date chronologically |
|
| 407 | - * |
|
| 408 | - * @access public |
|
| 409 | - * @param int $EVT_ID |
|
| 410 | - * @return string |
|
| 411 | - */ |
|
| 412 | - public static function get_earliest_date_obj($EVT_ID = 0) |
|
| 413 | - { |
|
| 414 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 415 | - if ($event instanceof EE_Event) { |
|
| 416 | - $datetimes = $event->get_many_related( |
|
| 417 | - 'Datetime', |
|
| 418 | - array( |
|
| 419 | - 'limit' => 1, |
|
| 420 | - 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) |
|
| 421 | - ) |
|
| 422 | - ); |
|
| 423 | - return reset($datetimes); |
|
| 424 | - } else { |
|
| 425 | - return false; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - |
|
| 431 | - /** |
|
| 432 | - * get_latest_date_obj - orders date chronologically |
|
| 433 | - * |
|
| 434 | - * @access public |
|
| 435 | - * @param int $EVT_ID |
|
| 436 | - * @return string |
|
| 437 | - */ |
|
| 438 | - public static function get_latest_date_obj($EVT_ID = 0) |
|
| 439 | - { |
|
| 440 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 441 | - if ($event instanceof EE_Event) { |
|
| 442 | - $datetimes = $event->get_many_related( |
|
| 443 | - 'Datetime', |
|
| 444 | - array( |
|
| 445 | - 'limit' => 1, |
|
| 446 | - 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) |
|
| 447 | - ) |
|
| 448 | - ); |
|
| 449 | - return end($datetimes); |
|
| 450 | - } else { |
|
| 451 | - return false; |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * get_next_upcoming_date_obj - return the next upcoming datetime |
|
| 457 | - * |
|
| 458 | - * @access public |
|
| 459 | - * @param int $EVT_ID |
|
| 460 | - * @return EE_Datetime|null |
|
| 461 | - */ |
|
| 462 | - public static function get_next_upcoming_date_obj($EVT_ID = 0) |
|
| 463 | - { |
|
| 464 | - $datetime = EEM_Datetime::instance()->get_one( |
|
| 465 | - array( |
|
| 466 | - array( |
|
| 467 | - 'Event.EVT_ID' => $EVT_ID, |
|
| 468 | - 'DTT_EVT_start' => array('>=', current_time('mysql', true)) |
|
| 469 | - ), |
|
| 470 | - 'order_by' => array('DTT_EVT_start' => 'asc') |
|
| 471 | - ) |
|
| 472 | - ); |
|
| 473 | - return $datetime instanceof EE_Datetime ? $datetime : null; |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - /** |
|
| 477 | - * get_all_date_obj |
|
| 478 | - * |
|
| 479 | - * @access public |
|
| 480 | - * @param int $EVT_ID |
|
| 481 | - * @param null $include_expired |
|
| 482 | - * @param bool $include_deleted |
|
| 483 | - * @param null $limit |
|
| 484 | - * @return EE_Datetime[] |
|
| 485 | - */ |
|
| 486 | - public static function get_all_date_obj($EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = null) |
|
| 487 | - { |
|
| 488 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 489 | - if ($include_expired === null) { |
|
| 490 | - if ($event instanceof EE_Event && $event->is_expired()) { |
|
| 491 | - $include_expired = true; |
|
| 492 | - } else { |
|
| 493 | - $include_expired = false; |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - if ($event instanceof EE_Event) { |
|
| 498 | - return $event->datetimes_ordered($include_expired, $include_deleted, $limit); |
|
| 499 | - } else { |
|
| 500 | - return array(); |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * event_link_url |
|
| 508 | - * |
|
| 509 | - * @access public |
|
| 510 | - * @param int $EVT_ID |
|
| 511 | - * @return string |
|
| 512 | - */ |
|
| 513 | - public static function event_link_url($EVT_ID = 0) |
|
| 514 | - { |
|
| 515 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 516 | - if ($event instanceof EE_Event) { |
|
| 517 | - $url = $event->external_url() !== null && $event->external_url() !== '' ? $event->external_url() : get_permalink($event->ID()); |
|
| 518 | - return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://' . $url; |
|
| 519 | - } |
|
| 520 | - return null; |
|
| 521 | - } |
|
| 522 | - |
|
| 523 | - |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * event_phone |
|
| 527 | - * |
|
| 528 | - * @access public |
|
| 529 | - * @param int $EVT_ID |
|
| 530 | - * @return string |
|
| 531 | - */ |
|
| 532 | - public static function event_phone($EVT_ID = 0) |
|
| 533 | - { |
|
| 534 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 535 | - if ($event instanceof EE_Event) { |
|
| 536 | - return EEH_Schema::telephone($event->phone()); |
|
| 537 | - } |
|
| 538 | - return null; |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - |
|
| 542 | - |
|
| 543 | - /** |
|
| 544 | - * edit_event_link |
|
| 545 | - * |
|
| 546 | - * @access public |
|
| 547 | - * @param int $EVT_ID |
|
| 548 | - * @param string $link |
|
| 549 | - * @param string $before |
|
| 550 | - * @param string $after |
|
| 551 | - * @return string |
|
| 552 | - */ |
|
| 553 | - public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '') |
|
| 554 | - { |
|
| 555 | - $event = EEH_Event_View::get_event($EVT_ID); |
|
| 556 | - if ($event instanceof EE_Event) { |
|
| 557 | - // can the user edit this post ? |
|
| 558 | - if (current_user_can('edit_post', $event->ID())) { |
|
| 559 | - // set link text |
|
| 560 | - $link_text = ! empty($link) ? $link : __('edit this event', 'event_espresso'); |
|
| 561 | - // generate nonce |
|
| 562 | - $nonce = wp_create_nonce('edit_nonce'); |
|
| 563 | - // generate url to event editor for this event |
|
| 564 | - $url = add_query_arg(array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce ), admin_url()); |
|
| 565 | - // get edit CPT text |
|
| 566 | - $post_type_obj = get_post_type_object('espresso_events'); |
|
| 567 | - // build final link html |
|
| 568 | - $link = '<a class="post-edit-link" href="' . $url . '" '; |
|
| 569 | - $link .= ' title="' . esc_attr($post_type_obj->labels->edit_item) . '"'; |
|
| 570 | - $link .= \EED_Events_Archive::link_target(); |
|
| 571 | - $link .='>' . $link_text . '</a>'; |
|
| 572 | - // put it all together |
|
| 573 | - return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after; |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - return ''; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - |
|
| 581 | - /** |
|
| 582 | - * @return string |
|
| 583 | - */ |
|
| 584 | - public static function event_archive_url() |
|
| 585 | - { |
|
| 586 | - return get_post_type_archive_link('espresso_events'); |
|
| 587 | - } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * get_primary_date_obj - orders date by DTT_order |
|
| 355 | + * |
|
| 356 | + * @access public |
|
| 357 | + * @param int $EVT_ID |
|
| 358 | + * @return string |
|
| 359 | + */ |
|
| 360 | + public static function get_primary_date_obj($EVT_ID = 0) |
|
| 361 | + { |
|
| 362 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 363 | + if ($event instanceof EE_Event) { |
|
| 364 | + $datetimes = $event->get_many_related( |
|
| 365 | + 'Datetime', |
|
| 366 | + array( |
|
| 367 | + 'limit' => 1, |
|
| 368 | + 'order_by' => array( 'DTT_order' => 'ASC' ) |
|
| 369 | + ) |
|
| 370 | + ); |
|
| 371 | + return reset($datetimes); |
|
| 372 | + } else { |
|
| 373 | + return false; |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * get_last_date_obj - orders date by DTT_order |
|
| 381 | + * |
|
| 382 | + * @access public |
|
| 383 | + * @param int $EVT_ID |
|
| 384 | + * @return string |
|
| 385 | + */ |
|
| 386 | + public static function get_last_date_obj($EVT_ID = 0) |
|
| 387 | + { |
|
| 388 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 389 | + if ($event instanceof EE_Event) { |
|
| 390 | + $datetimes = $event->get_many_related( |
|
| 391 | + 'Datetime', |
|
| 392 | + array( |
|
| 393 | + 'limit' => 1, |
|
| 394 | + 'order_by' => array( 'DTT_order' => 'DESC' ) |
|
| 395 | + ) |
|
| 396 | + ); |
|
| 397 | + return end($datetimes); |
|
| 398 | + } else { |
|
| 399 | + return false; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * get_earliest_date_obj - orders date chronologically |
|
| 407 | + * |
|
| 408 | + * @access public |
|
| 409 | + * @param int $EVT_ID |
|
| 410 | + * @return string |
|
| 411 | + */ |
|
| 412 | + public static function get_earliest_date_obj($EVT_ID = 0) |
|
| 413 | + { |
|
| 414 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 415 | + if ($event instanceof EE_Event) { |
|
| 416 | + $datetimes = $event->get_many_related( |
|
| 417 | + 'Datetime', |
|
| 418 | + array( |
|
| 419 | + 'limit' => 1, |
|
| 420 | + 'order_by' => array( 'DTT_EVT_start' => 'ASC' ) |
|
| 421 | + ) |
|
| 422 | + ); |
|
| 423 | + return reset($datetimes); |
|
| 424 | + } else { |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + |
|
| 431 | + /** |
|
| 432 | + * get_latest_date_obj - orders date chronologically |
|
| 433 | + * |
|
| 434 | + * @access public |
|
| 435 | + * @param int $EVT_ID |
|
| 436 | + * @return string |
|
| 437 | + */ |
|
| 438 | + public static function get_latest_date_obj($EVT_ID = 0) |
|
| 439 | + { |
|
| 440 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 441 | + if ($event instanceof EE_Event) { |
|
| 442 | + $datetimes = $event->get_many_related( |
|
| 443 | + 'Datetime', |
|
| 444 | + array( |
|
| 445 | + 'limit' => 1, |
|
| 446 | + 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) |
|
| 447 | + ) |
|
| 448 | + ); |
|
| 449 | + return end($datetimes); |
|
| 450 | + } else { |
|
| 451 | + return false; |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * get_next_upcoming_date_obj - return the next upcoming datetime |
|
| 457 | + * |
|
| 458 | + * @access public |
|
| 459 | + * @param int $EVT_ID |
|
| 460 | + * @return EE_Datetime|null |
|
| 461 | + */ |
|
| 462 | + public static function get_next_upcoming_date_obj($EVT_ID = 0) |
|
| 463 | + { |
|
| 464 | + $datetime = EEM_Datetime::instance()->get_one( |
|
| 465 | + array( |
|
| 466 | + array( |
|
| 467 | + 'Event.EVT_ID' => $EVT_ID, |
|
| 468 | + 'DTT_EVT_start' => array('>=', current_time('mysql', true)) |
|
| 469 | + ), |
|
| 470 | + 'order_by' => array('DTT_EVT_start' => 'asc') |
|
| 471 | + ) |
|
| 472 | + ); |
|
| 473 | + return $datetime instanceof EE_Datetime ? $datetime : null; |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + /** |
|
| 477 | + * get_all_date_obj |
|
| 478 | + * |
|
| 479 | + * @access public |
|
| 480 | + * @param int $EVT_ID |
|
| 481 | + * @param null $include_expired |
|
| 482 | + * @param bool $include_deleted |
|
| 483 | + * @param null $limit |
|
| 484 | + * @return EE_Datetime[] |
|
| 485 | + */ |
|
| 486 | + public static function get_all_date_obj($EVT_ID = 0, $include_expired = null, $include_deleted = false, $limit = null) |
|
| 487 | + { |
|
| 488 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 489 | + if ($include_expired === null) { |
|
| 490 | + if ($event instanceof EE_Event && $event->is_expired()) { |
|
| 491 | + $include_expired = true; |
|
| 492 | + } else { |
|
| 493 | + $include_expired = false; |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + if ($event instanceof EE_Event) { |
|
| 498 | + return $event->datetimes_ordered($include_expired, $include_deleted, $limit); |
|
| 499 | + } else { |
|
| 500 | + return array(); |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * event_link_url |
|
| 508 | + * |
|
| 509 | + * @access public |
|
| 510 | + * @param int $EVT_ID |
|
| 511 | + * @return string |
|
| 512 | + */ |
|
| 513 | + public static function event_link_url($EVT_ID = 0) |
|
| 514 | + { |
|
| 515 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 516 | + if ($event instanceof EE_Event) { |
|
| 517 | + $url = $event->external_url() !== null && $event->external_url() !== '' ? $event->external_url() : get_permalink($event->ID()); |
|
| 518 | + return preg_match("~^(?:f|ht)tps?://~i", $url) ? $url : 'http://' . $url; |
|
| 519 | + } |
|
| 520 | + return null; |
|
| 521 | + } |
|
| 522 | + |
|
| 523 | + |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * event_phone |
|
| 527 | + * |
|
| 528 | + * @access public |
|
| 529 | + * @param int $EVT_ID |
|
| 530 | + * @return string |
|
| 531 | + */ |
|
| 532 | + public static function event_phone($EVT_ID = 0) |
|
| 533 | + { |
|
| 534 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 535 | + if ($event instanceof EE_Event) { |
|
| 536 | + return EEH_Schema::telephone($event->phone()); |
|
| 537 | + } |
|
| 538 | + return null; |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + |
|
| 542 | + |
|
| 543 | + /** |
|
| 544 | + * edit_event_link |
|
| 545 | + * |
|
| 546 | + * @access public |
|
| 547 | + * @param int $EVT_ID |
|
| 548 | + * @param string $link |
|
| 549 | + * @param string $before |
|
| 550 | + * @param string $after |
|
| 551 | + * @return string |
|
| 552 | + */ |
|
| 553 | + public static function edit_event_link($EVT_ID = 0, $link = '', $before = '', $after = '') |
|
| 554 | + { |
|
| 555 | + $event = EEH_Event_View::get_event($EVT_ID); |
|
| 556 | + if ($event instanceof EE_Event) { |
|
| 557 | + // can the user edit this post ? |
|
| 558 | + if (current_user_can('edit_post', $event->ID())) { |
|
| 559 | + // set link text |
|
| 560 | + $link_text = ! empty($link) ? $link : __('edit this event', 'event_espresso'); |
|
| 561 | + // generate nonce |
|
| 562 | + $nonce = wp_create_nonce('edit_nonce'); |
|
| 563 | + // generate url to event editor for this event |
|
| 564 | + $url = add_query_arg(array( 'page' => 'espresso_events', 'action' => 'edit', 'post' => $event->ID(), 'edit_nonce' => $nonce ), admin_url()); |
|
| 565 | + // get edit CPT text |
|
| 566 | + $post_type_obj = get_post_type_object('espresso_events'); |
|
| 567 | + // build final link html |
|
| 568 | + $link = '<a class="post-edit-link" href="' . $url . '" '; |
|
| 569 | + $link .= ' title="' . esc_attr($post_type_obj->labels->edit_item) . '"'; |
|
| 570 | + $link .= \EED_Events_Archive::link_target(); |
|
| 571 | + $link .='>' . $link_text . '</a>'; |
|
| 572 | + // put it all together |
|
| 573 | + return $before . apply_filters('edit_post_link', $link, $event->ID()) . $after; |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + return ''; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + |
|
| 581 | + /** |
|
| 582 | + * @return string |
|
| 583 | + */ |
|
| 584 | + public static function event_archive_url() |
|
| 585 | + { |
|
| 586 | + return get_post_type_archive_link('espresso_events'); |
|
| 587 | + } |
|
| 588 | 588 | } |
@@ -13,354 +13,354 @@ |
||
| 13 | 13 | { |
| 14 | 14 | |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @return Messages_Admin_Page |
|
| 18 | - */ |
|
| 19 | - public function get_admin_page() |
|
| 20 | - { |
|
| 21 | - return $this->_admin_page; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Setup data object |
|
| 27 | - */ |
|
| 28 | - protected function _setup_data() |
|
| 29 | - { |
|
| 30 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
| 31 | - $this->_per_page, |
|
| 32 | - $this->_view, |
|
| 33 | - false |
|
| 34 | - ); |
|
| 35 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
| 36 | - $this->_per_page, |
|
| 37 | - $this->_view, |
|
| 38 | - true, |
|
| 39 | - true |
|
| 40 | - ); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Set internal properties |
|
| 46 | - */ |
|
| 47 | - protected function _set_properties() |
|
| 48 | - { |
|
| 49 | - $this->_wp_list_args = array( |
|
| 50 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
| 51 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
| 52 | - 'ajax' => true, // for now, |
|
| 53 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
| 54 | - ); |
|
| 55 | - $this->_columns = array( |
|
| 56 | - // 'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
| 57 | - 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
| 58 | - 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
| 59 | - 'description' => esc_html__('Description', 'event_espresso'), |
|
| 60 | - ); |
|
| 61 | - |
|
| 62 | - $this->_sortable_columns = array( |
|
| 63 | - 'messenger' => array('MTP_messenger' => true), |
|
| 64 | - ); |
|
| 65 | - |
|
| 66 | - $this->_hidden_columns = array(); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
| 72 | - * message_type or messenger object before generating the row. |
|
| 73 | - * |
|
| 74 | - * @param EE_Message_Template_Group $item |
|
| 75 | - * @return string |
|
| 76 | - * @throws EE_Error |
|
| 77 | - */ |
|
| 78 | - public function single_row($item) |
|
| 79 | - { |
|
| 80 | - $message_type = $item->message_type_obj(); |
|
| 81 | - $messenger = $item->messenger_obj(); |
|
| 82 | - |
|
| 83 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
| 84 | - echo ''; |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - parent::single_row($item); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return array |
|
| 94 | - * @throws EE_Error |
|
| 95 | - */ |
|
| 96 | - protected function _get_table_filters() |
|
| 97 | - { |
|
| 98 | - $filters = array(); |
|
| 99 | - |
|
| 100 | - // get select inputs |
|
| 101 | - $select_inputs = array( |
|
| 102 | - $this->_get_messengers_dropdown_filter(), |
|
| 103 | - $this->_get_message_types_dropdown_filter(), |
|
| 104 | - ); |
|
| 105 | - |
|
| 106 | - // set filters to select inputs if they aren't empty |
|
| 107 | - foreach ($select_inputs as $select_input) { |
|
| 108 | - if ($select_input) { |
|
| 109 | - $filters[] = $select_input; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - return $filters; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * We're just removing the search box for message templates, not needed. |
|
| 117 | - * |
|
| 118 | - * @param string $text |
|
| 119 | - * @param string $input_id |
|
| 120 | - * @return string ; |
|
| 121 | - */ |
|
| 122 | - public function search_box($text, $input_id) |
|
| 123 | - { |
|
| 124 | - return ''; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Add counts to the _views property |
|
| 130 | - */ |
|
| 131 | - protected function _add_view_counts() |
|
| 132 | - { |
|
| 133 | - foreach ($this->_views as $view => $args) { |
|
| 134 | - $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 135 | - $this->_per_page, |
|
| 136 | - $view, |
|
| 137 | - true, |
|
| 138 | - true |
|
| 139 | - ); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param EE_Message_Template_Group $item |
|
| 146 | - * @return string |
|
| 147 | - */ |
|
| 148 | - public function column_cb($item) |
|
| 149 | - { |
|
| 150 | - return ''; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @param EE_Message_Template_Group $item |
|
| 156 | - * @return string |
|
| 157 | - * @throws EE_Error |
|
| 158 | - */ |
|
| 159 | - public function column_description($item) |
|
| 160 | - { |
|
| 161 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * @param EE_Message_Template_Group $item |
|
| 167 | - * @return string |
|
| 168 | - * @throws EE_Error |
|
| 169 | - */ |
|
| 170 | - public function column_messenger($item) |
|
| 171 | - { |
|
| 172 | - // Return the name contents |
|
| 173 | - return sprintf( |
|
| 174 | - '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
| 175 | - /* $1%s */ |
|
| 176 | - ucwords($item->messenger_obj()->label['singular']), |
|
| 177 | - /* $2%s */ |
|
| 178 | - $item->GRP_ID(), |
|
| 179 | - /* %4$s */ |
|
| 180 | - $this->_get_context_links($item), |
|
| 181 | - $this->row_actions($this->_get_actions_for_messenger_column($item)) |
|
| 182 | - ); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * column_message_type |
|
| 187 | - * |
|
| 188 | - * @param EE_Message_Template_Group $item message info for the row |
|
| 189 | - * @return string message_type name |
|
| 190 | - * @throws EE_Error |
|
| 191 | - */ |
|
| 192 | - public function column_message_type($item) |
|
| 193 | - { |
|
| 194 | - return ucwords($item->message_type_obj()->label['singular']); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Generate dropdown filter select input for messengers |
|
| 200 | - * |
|
| 201 | - * @param bool $global |
|
| 202 | - * @return string |
|
| 203 | - * @throws EE_Error |
|
| 204 | - */ |
|
| 205 | - protected function _get_messengers_dropdown_filter($global = true) |
|
| 206 | - { |
|
| 207 | - $messenger_options = array(); |
|
| 208 | - $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
| 209 | - array( |
|
| 210 | - array( |
|
| 211 | - 'MTP_is_active' => true, |
|
| 212 | - 'MTP_is_global' => $global, |
|
| 213 | - ), |
|
| 214 | - 'group_by' => 'MTP_messenger', |
|
| 215 | - ) |
|
| 216 | - ); |
|
| 217 | - |
|
| 218 | - foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
| 219 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 220 | - $messenger = $active_message_template_group->messenger_obj(); |
|
| 221 | - $messenger_label = $messenger instanceof EE_messenger |
|
| 222 | - ? $messenger->label['singular'] |
|
| 223 | - : $active_message_template_group->messenger(); |
|
| 224 | - $messenger_options[ $active_message_template_group->messenger() ] = ucwords($messenger_label); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Generate dropdown filter select input for message types |
|
| 233 | - * |
|
| 234 | - * @param bool $global |
|
| 235 | - * @return string |
|
| 236 | - * @throws EE_Error |
|
| 237 | - */ |
|
| 238 | - protected function _get_message_types_dropdown_filter($global = true) |
|
| 239 | - { |
|
| 240 | - $message_type_options = array(); |
|
| 241 | - $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
| 242 | - array( |
|
| 243 | - array( |
|
| 244 | - 'MTP_is_active' => true, |
|
| 245 | - 'MTP_is_global' => true, |
|
| 246 | - ), |
|
| 247 | - 'group_by' => 'MTP_message_type', |
|
| 248 | - ) |
|
| 249 | - ); |
|
| 250 | - |
|
| 251 | - foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
| 252 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 253 | - $message_type = $active_message_template_group->message_type_obj(); |
|
| 254 | - $message_type_label = $message_type instanceof EE_message_type |
|
| 255 | - ? $message_type->label['singular'] |
|
| 256 | - : $active_message_template_group->message_type(); |
|
| 257 | - $message_type_options[ $active_message_template_group->message_type() ] = ucwords($message_type_label); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Return the edit url for the message template group. |
|
| 266 | - * |
|
| 267 | - * @param EE_Message_Template_Group $item |
|
| 268 | - * @return string |
|
| 269 | - * @throws EE_Error |
|
| 270 | - */ |
|
| 271 | - protected function _get_edit_url(EE_Message_Template_Group $item) |
|
| 272 | - { |
|
| 273 | - $edit_url = ''; |
|
| 274 | - // edit link but only if item isn't trashed. |
|
| 275 | - if (! $item->get('MTP_deleted') |
|
| 276 | - && EE_Registry::instance()->CAP->current_user_can( |
|
| 277 | - 'ee_edit_message', |
|
| 278 | - 'espresso_messages_edit_message_template', |
|
| 279 | - $item->ID() |
|
| 280 | - )) { |
|
| 281 | - $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 282 | - array( |
|
| 283 | - 'action' => 'edit_message_template', |
|
| 284 | - 'id' => $item->GRP_ID(), |
|
| 285 | - ), |
|
| 286 | - EE_MSG_ADMIN_URL |
|
| 287 | - ); |
|
| 288 | - } |
|
| 289 | - return $edit_url; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Get the context link string for the messenger column. |
|
| 295 | - * |
|
| 296 | - * @param EE_Message_Template_Group $item |
|
| 297 | - * @return string |
|
| 298 | - * @throws EE_Error |
|
| 299 | - */ |
|
| 300 | - protected function _get_context_links(EE_Message_Template_Group $item) |
|
| 301 | - { |
|
| 302 | - // first check if we even show the context links or not. |
|
| 303 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 304 | - 'ee_edit_message', |
|
| 305 | - 'espresso_messages_edit_message_template', |
|
| 306 | - $item->ID() |
|
| 307 | - ) |
|
| 308 | - || $item->get('MTP_deleted') |
|
| 309 | - ) { |
|
| 310 | - return ''; |
|
| 311 | - } |
|
| 312 | - // we want to display the contexts in here so we need to set them up |
|
| 313 | - $c_label = $item->context_label(); |
|
| 314 | - $c_configs = $item->contexts_config(); |
|
| 315 | - $ctxt = array(); |
|
| 316 | - $context_templates = $item->context_templates(); |
|
| 317 | - foreach ($context_templates as $context => $template_fields) { |
|
| 318 | - $mtp_to = ! empty($context_templates[ $context ]['to']) |
|
| 319 | - && $context_templates[ $context ]['to'] instanceof EE_Message_Template |
|
| 320 | - ? $context_templates[ $context ]['to']->get('MTP_content') |
|
| 321 | - : null; |
|
| 322 | - $inactive_class = ( |
|
| 323 | - empty($mtp_to) |
|
| 324 | - && ! empty($context_templates[ $context ]['to']) |
|
| 325 | - ) |
|
| 326 | - || ! $item->is_context_active($context) |
|
| 327 | - ? ' mtp-inactive' |
|
| 328 | - : ''; |
|
| 329 | - $context_title = sprintf( |
|
| 330 | - /* translators: Placeholder represents the context label. Example "Edit Event Admin" */ |
|
| 331 | - esc_html__('Edit %1$s', 'event_espresso'), |
|
| 332 | - ucwords($c_configs[ $context ]['label']) |
|
| 333 | - ); |
|
| 334 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 335 | - array( |
|
| 336 | - 'action' => 'edit_message_template', |
|
| 337 | - 'id' => $item->GRP_ID(), |
|
| 338 | - 'context' => $context, |
|
| 339 | - ), |
|
| 340 | - EE_MSG_ADMIN_URL |
|
| 341 | - ); |
|
| 342 | - $ctxt[] = '<a' |
|
| 343 | - . ' href="' . $edit_link . '"' |
|
| 344 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link' . $inactive_class . '"' |
|
| 345 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
| 346 | - . $context_title |
|
| 347 | - . '</a>'; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * Returns the actions for the messenger column. |
|
| 356 | - * |
|
| 357 | - * Note: Children classes may override this so do not remove it. |
|
| 358 | - * |
|
| 359 | - * @param EE_Message_Template_Group $item |
|
| 360 | - * @return array |
|
| 361 | - */ |
|
| 362 | - protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
| 363 | - { |
|
| 364 | - return []; |
|
| 365 | - } |
|
| 16 | + /** |
|
| 17 | + * @return Messages_Admin_Page |
|
| 18 | + */ |
|
| 19 | + public function get_admin_page() |
|
| 20 | + { |
|
| 21 | + return $this->_admin_page; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Setup data object |
|
| 27 | + */ |
|
| 28 | + protected function _setup_data() |
|
| 29 | + { |
|
| 30 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
| 31 | + $this->_per_page, |
|
| 32 | + $this->_view, |
|
| 33 | + false |
|
| 34 | + ); |
|
| 35 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
| 36 | + $this->_per_page, |
|
| 37 | + $this->_view, |
|
| 38 | + true, |
|
| 39 | + true |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Set internal properties |
|
| 46 | + */ |
|
| 47 | + protected function _set_properties() |
|
| 48 | + { |
|
| 49 | + $this->_wp_list_args = array( |
|
| 50 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
| 51 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
| 52 | + 'ajax' => true, // for now, |
|
| 53 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
| 54 | + ); |
|
| 55 | + $this->_columns = array( |
|
| 56 | + // 'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
| 57 | + 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
| 58 | + 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
| 59 | + 'description' => esc_html__('Description', 'event_espresso'), |
|
| 60 | + ); |
|
| 61 | + |
|
| 62 | + $this->_sortable_columns = array( |
|
| 63 | + 'messenger' => array('MTP_messenger' => true), |
|
| 64 | + ); |
|
| 65 | + |
|
| 66 | + $this->_hidden_columns = array(); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
| 72 | + * message_type or messenger object before generating the row. |
|
| 73 | + * |
|
| 74 | + * @param EE_Message_Template_Group $item |
|
| 75 | + * @return string |
|
| 76 | + * @throws EE_Error |
|
| 77 | + */ |
|
| 78 | + public function single_row($item) |
|
| 79 | + { |
|
| 80 | + $message_type = $item->message_type_obj(); |
|
| 81 | + $messenger = $item->messenger_obj(); |
|
| 82 | + |
|
| 83 | + if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
| 84 | + echo ''; |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + parent::single_row($item); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return array |
|
| 94 | + * @throws EE_Error |
|
| 95 | + */ |
|
| 96 | + protected function _get_table_filters() |
|
| 97 | + { |
|
| 98 | + $filters = array(); |
|
| 99 | + |
|
| 100 | + // get select inputs |
|
| 101 | + $select_inputs = array( |
|
| 102 | + $this->_get_messengers_dropdown_filter(), |
|
| 103 | + $this->_get_message_types_dropdown_filter(), |
|
| 104 | + ); |
|
| 105 | + |
|
| 106 | + // set filters to select inputs if they aren't empty |
|
| 107 | + foreach ($select_inputs as $select_input) { |
|
| 108 | + if ($select_input) { |
|
| 109 | + $filters[] = $select_input; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + return $filters; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * We're just removing the search box for message templates, not needed. |
|
| 117 | + * |
|
| 118 | + * @param string $text |
|
| 119 | + * @param string $input_id |
|
| 120 | + * @return string ; |
|
| 121 | + */ |
|
| 122 | + public function search_box($text, $input_id) |
|
| 123 | + { |
|
| 124 | + return ''; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Add counts to the _views property |
|
| 130 | + */ |
|
| 131 | + protected function _add_view_counts() |
|
| 132 | + { |
|
| 133 | + foreach ($this->_views as $view => $args) { |
|
| 134 | + $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 135 | + $this->_per_page, |
|
| 136 | + $view, |
|
| 137 | + true, |
|
| 138 | + true |
|
| 139 | + ); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param EE_Message_Template_Group $item |
|
| 146 | + * @return string |
|
| 147 | + */ |
|
| 148 | + public function column_cb($item) |
|
| 149 | + { |
|
| 150 | + return ''; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @param EE_Message_Template_Group $item |
|
| 156 | + * @return string |
|
| 157 | + * @throws EE_Error |
|
| 158 | + */ |
|
| 159 | + public function column_description($item) |
|
| 160 | + { |
|
| 161 | + return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * @param EE_Message_Template_Group $item |
|
| 167 | + * @return string |
|
| 168 | + * @throws EE_Error |
|
| 169 | + */ |
|
| 170 | + public function column_messenger($item) |
|
| 171 | + { |
|
| 172 | + // Return the name contents |
|
| 173 | + return sprintf( |
|
| 174 | + '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
| 175 | + /* $1%s */ |
|
| 176 | + ucwords($item->messenger_obj()->label['singular']), |
|
| 177 | + /* $2%s */ |
|
| 178 | + $item->GRP_ID(), |
|
| 179 | + /* %4$s */ |
|
| 180 | + $this->_get_context_links($item), |
|
| 181 | + $this->row_actions($this->_get_actions_for_messenger_column($item)) |
|
| 182 | + ); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * column_message_type |
|
| 187 | + * |
|
| 188 | + * @param EE_Message_Template_Group $item message info for the row |
|
| 189 | + * @return string message_type name |
|
| 190 | + * @throws EE_Error |
|
| 191 | + */ |
|
| 192 | + public function column_message_type($item) |
|
| 193 | + { |
|
| 194 | + return ucwords($item->message_type_obj()->label['singular']); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Generate dropdown filter select input for messengers |
|
| 200 | + * |
|
| 201 | + * @param bool $global |
|
| 202 | + * @return string |
|
| 203 | + * @throws EE_Error |
|
| 204 | + */ |
|
| 205 | + protected function _get_messengers_dropdown_filter($global = true) |
|
| 206 | + { |
|
| 207 | + $messenger_options = array(); |
|
| 208 | + $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
| 209 | + array( |
|
| 210 | + array( |
|
| 211 | + 'MTP_is_active' => true, |
|
| 212 | + 'MTP_is_global' => $global, |
|
| 213 | + ), |
|
| 214 | + 'group_by' => 'MTP_messenger', |
|
| 215 | + ) |
|
| 216 | + ); |
|
| 217 | + |
|
| 218 | + foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
| 219 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 220 | + $messenger = $active_message_template_group->messenger_obj(); |
|
| 221 | + $messenger_label = $messenger instanceof EE_messenger |
|
| 222 | + ? $messenger->label['singular'] |
|
| 223 | + : $active_message_template_group->messenger(); |
|
| 224 | + $messenger_options[ $active_message_template_group->messenger() ] = ucwords($messenger_label); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Generate dropdown filter select input for message types |
|
| 233 | + * |
|
| 234 | + * @param bool $global |
|
| 235 | + * @return string |
|
| 236 | + * @throws EE_Error |
|
| 237 | + */ |
|
| 238 | + protected function _get_message_types_dropdown_filter($global = true) |
|
| 239 | + { |
|
| 240 | + $message_type_options = array(); |
|
| 241 | + $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
| 242 | + array( |
|
| 243 | + array( |
|
| 244 | + 'MTP_is_active' => true, |
|
| 245 | + 'MTP_is_global' => true, |
|
| 246 | + ), |
|
| 247 | + 'group_by' => 'MTP_message_type', |
|
| 248 | + ) |
|
| 249 | + ); |
|
| 250 | + |
|
| 251 | + foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
| 252 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
| 253 | + $message_type = $active_message_template_group->message_type_obj(); |
|
| 254 | + $message_type_label = $message_type instanceof EE_message_type |
|
| 255 | + ? $message_type->label['singular'] |
|
| 256 | + : $active_message_template_group->message_type(); |
|
| 257 | + $message_type_options[ $active_message_template_group->message_type() ] = ucwords($message_type_label); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Return the edit url for the message template group. |
|
| 266 | + * |
|
| 267 | + * @param EE_Message_Template_Group $item |
|
| 268 | + * @return string |
|
| 269 | + * @throws EE_Error |
|
| 270 | + */ |
|
| 271 | + protected function _get_edit_url(EE_Message_Template_Group $item) |
|
| 272 | + { |
|
| 273 | + $edit_url = ''; |
|
| 274 | + // edit link but only if item isn't trashed. |
|
| 275 | + if (! $item->get('MTP_deleted') |
|
| 276 | + && EE_Registry::instance()->CAP->current_user_can( |
|
| 277 | + 'ee_edit_message', |
|
| 278 | + 'espresso_messages_edit_message_template', |
|
| 279 | + $item->ID() |
|
| 280 | + )) { |
|
| 281 | + $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
| 282 | + array( |
|
| 283 | + 'action' => 'edit_message_template', |
|
| 284 | + 'id' => $item->GRP_ID(), |
|
| 285 | + ), |
|
| 286 | + EE_MSG_ADMIN_URL |
|
| 287 | + ); |
|
| 288 | + } |
|
| 289 | + return $edit_url; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Get the context link string for the messenger column. |
|
| 295 | + * |
|
| 296 | + * @param EE_Message_Template_Group $item |
|
| 297 | + * @return string |
|
| 298 | + * @throws EE_Error |
|
| 299 | + */ |
|
| 300 | + protected function _get_context_links(EE_Message_Template_Group $item) |
|
| 301 | + { |
|
| 302 | + // first check if we even show the context links or not. |
|
| 303 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 304 | + 'ee_edit_message', |
|
| 305 | + 'espresso_messages_edit_message_template', |
|
| 306 | + $item->ID() |
|
| 307 | + ) |
|
| 308 | + || $item->get('MTP_deleted') |
|
| 309 | + ) { |
|
| 310 | + return ''; |
|
| 311 | + } |
|
| 312 | + // we want to display the contexts in here so we need to set them up |
|
| 313 | + $c_label = $item->context_label(); |
|
| 314 | + $c_configs = $item->contexts_config(); |
|
| 315 | + $ctxt = array(); |
|
| 316 | + $context_templates = $item->context_templates(); |
|
| 317 | + foreach ($context_templates as $context => $template_fields) { |
|
| 318 | + $mtp_to = ! empty($context_templates[ $context ]['to']) |
|
| 319 | + && $context_templates[ $context ]['to'] instanceof EE_Message_Template |
|
| 320 | + ? $context_templates[ $context ]['to']->get('MTP_content') |
|
| 321 | + : null; |
|
| 322 | + $inactive_class = ( |
|
| 323 | + empty($mtp_to) |
|
| 324 | + && ! empty($context_templates[ $context ]['to']) |
|
| 325 | + ) |
|
| 326 | + || ! $item->is_context_active($context) |
|
| 327 | + ? ' mtp-inactive' |
|
| 328 | + : ''; |
|
| 329 | + $context_title = sprintf( |
|
| 330 | + /* translators: Placeholder represents the context label. Example "Edit Event Admin" */ |
|
| 331 | + esc_html__('Edit %1$s', 'event_espresso'), |
|
| 332 | + ucwords($c_configs[ $context ]['label']) |
|
| 333 | + ); |
|
| 334 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
| 335 | + array( |
|
| 336 | + 'action' => 'edit_message_template', |
|
| 337 | + 'id' => $item->GRP_ID(), |
|
| 338 | + 'context' => $context, |
|
| 339 | + ), |
|
| 340 | + EE_MSG_ADMIN_URL |
|
| 341 | + ); |
|
| 342 | + $ctxt[] = '<a' |
|
| 343 | + . ' href="' . $edit_link . '"' |
|
| 344 | + . ' class="' . $item->message_type() . '-' . $context . '-edit-link' . $inactive_class . '"' |
|
| 345 | + . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
| 346 | + . $context_title |
|
| 347 | + . '</a>'; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + |
|
| 354 | + /** |
|
| 355 | + * Returns the actions for the messenger column. |
|
| 356 | + * |
|
| 357 | + * Note: Children classes may override this so do not remove it. |
|
| 358 | + * |
|
| 359 | + * @param EE_Message_Template_Group $item |
|
| 360 | + * @return array |
|
| 361 | + */ |
|
| 362 | + protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
| 363 | + { |
|
| 364 | + return []; |
|
| 365 | + } |
|
| 366 | 366 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | $message_type = $item->message_type_obj(); |
| 81 | 81 | $messenger = $item->messenger_obj(); |
| 82 | 82 | |
| 83 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
| 83 | + if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
| 84 | 84 | echo ''; |
| 85 | 85 | return; |
| 86 | 86 | } |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | protected function _add_view_counts() |
| 132 | 132 | { |
| 133 | 133 | foreach ($this->_views as $view => $args) { |
| 134 | - $this->_views[ $view ]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 134 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
| 135 | 135 | $this->_per_page, |
| 136 | 136 | $view, |
| 137 | 137 | true, |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | public function column_description($item) |
| 160 | 160 | { |
| 161 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
| 161 | + return '<p>'.$item->message_type_obj()->description.'</p>'; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | $messenger_label = $messenger instanceof EE_messenger |
| 222 | 222 | ? $messenger->label['singular'] |
| 223 | 223 | : $active_message_template_group->messenger(); |
| 224 | - $messenger_options[ $active_message_template_group->messenger() ] = ucwords($messenger_label); |
|
| 224 | + $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
| 225 | 225 | } |
| 226 | 226 | } |
| 227 | 227 | return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | $message_type_label = $message_type instanceof EE_message_type |
| 255 | 255 | ? $message_type->label['singular'] |
| 256 | 256 | : $active_message_template_group->message_type(); |
| 257 | - $message_type_options[ $active_message_template_group->message_type() ] = ucwords($message_type_label); |
|
| 257 | + $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
| 258 | 258 | } |
| 259 | 259 | } |
| 260 | 260 | return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | { |
| 273 | 273 | $edit_url = ''; |
| 274 | 274 | // edit link but only if item isn't trashed. |
| 275 | - if (! $item->get('MTP_deleted') |
|
| 275 | + if ( ! $item->get('MTP_deleted') |
|
| 276 | 276 | && EE_Registry::instance()->CAP->current_user_can( |
| 277 | 277 | 'ee_edit_message', |
| 278 | 278 | 'espresso_messages_edit_message_template', |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | protected function _get_context_links(EE_Message_Template_Group $item) |
| 301 | 301 | { |
| 302 | 302 | // first check if we even show the context links or not. |
| 303 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 303 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
| 304 | 304 | 'ee_edit_message', |
| 305 | 305 | 'espresso_messages_edit_message_template', |
| 306 | 306 | $item->ID() |
@@ -315,13 +315,13 @@ discard block |
||
| 315 | 315 | $ctxt = array(); |
| 316 | 316 | $context_templates = $item->context_templates(); |
| 317 | 317 | foreach ($context_templates as $context => $template_fields) { |
| 318 | - $mtp_to = ! empty($context_templates[ $context ]['to']) |
|
| 319 | - && $context_templates[ $context ]['to'] instanceof EE_Message_Template |
|
| 320 | - ? $context_templates[ $context ]['to']->get('MTP_content') |
|
| 318 | + $mtp_to = ! empty($context_templates[$context]['to']) |
|
| 319 | + && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
| 320 | + ? $context_templates[$context]['to']->get('MTP_content') |
|
| 321 | 321 | : null; |
| 322 | 322 | $inactive_class = ( |
| 323 | 323 | empty($mtp_to) |
| 324 | - && ! empty($context_templates[ $context ]['to']) |
|
| 324 | + && ! empty($context_templates[$context]['to']) |
|
| 325 | 325 | ) |
| 326 | 326 | || ! $item->is_context_active($context) |
| 327 | 327 | ? ' mtp-inactive' |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | $context_title = sprintf( |
| 330 | 330 | /* translators: Placeholder represents the context label. Example "Edit Event Admin" */ |
| 331 | 331 | esc_html__('Edit %1$s', 'event_espresso'), |
| 332 | - ucwords($c_configs[ $context ]['label']) |
|
| 332 | + ucwords($c_configs[$context]['label']) |
|
| 333 | 333 | ); |
| 334 | 334 | $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
| 335 | 335 | array( |
@@ -340,14 +340,14 @@ discard block |
||
| 340 | 340 | EE_MSG_ADMIN_URL |
| 341 | 341 | ); |
| 342 | 342 | $ctxt[] = '<a' |
| 343 | - . ' href="' . $edit_link . '"' |
|
| 344 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link' . $inactive_class . '"' |
|
| 345 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
| 343 | + . ' href="'.$edit_link.'"' |
|
| 344 | + . ' class="'.$item->message_type().'-'.$context.'-edit-link'.$inactive_class.'"' |
|
| 345 | + . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">' |
|
| 346 | 346 | . $context_title |
| 347 | 347 | . '</a>'; |
| 348 | 348 | } |
| 349 | 349 | |
| 350 | - return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
| 350 | + return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])).implode(' | ', $ctxt); |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | |
@@ -21,172 +21,172 @@ |
||
| 21 | 21 | class EventAttendees extends Block |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - const BLOCK_TYPE = 'event-attendees'; |
|
| 24 | + const BLOCK_TYPE = 'event-attendees'; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var EventAttendeesBlockRenderer $renderer |
|
| 28 | - */ |
|
| 29 | - protected $renderer; |
|
| 26 | + /** |
|
| 27 | + * @var EventAttendeesBlockRenderer $renderer |
|
| 28 | + */ |
|
| 29 | + protected $renderer; |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * EventAttendees constructor. |
|
| 34 | - * |
|
| 35 | - * @param CoreBlocksAssetManager $block_asset_manager |
|
| 36 | - * @param RequestInterface $request |
|
| 37 | - * @param EventAttendeesBlockRenderer $renderer |
|
| 38 | - */ |
|
| 39 | - public function __construct( |
|
| 40 | - CoreBlocksAssetManager $block_asset_manager, |
|
| 41 | - RequestInterface $request, |
|
| 42 | - EventAttendeesBlockRenderer $renderer |
|
| 43 | - ) { |
|
| 44 | - parent::__construct($block_asset_manager, $request); |
|
| 45 | - $this->renderer= $renderer; |
|
| 46 | - } |
|
| 32 | + /** |
|
| 33 | + * EventAttendees constructor. |
|
| 34 | + * |
|
| 35 | + * @param CoreBlocksAssetManager $block_asset_manager |
|
| 36 | + * @param RequestInterface $request |
|
| 37 | + * @param EventAttendeesBlockRenderer $renderer |
|
| 38 | + */ |
|
| 39 | + public function __construct( |
|
| 40 | + CoreBlocksAssetManager $block_asset_manager, |
|
| 41 | + RequestInterface $request, |
|
| 42 | + EventAttendeesBlockRenderer $renderer |
|
| 43 | + ) { |
|
| 44 | + parent::__construct($block_asset_manager, $request); |
|
| 45 | + $this->renderer= $renderer; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Perform any early setup required by the block |
|
| 51 | - * including setting the block type and supported post types |
|
| 52 | - * |
|
| 53 | - * @return void |
|
| 54 | - */ |
|
| 55 | - public function initialize() |
|
| 56 | - { |
|
| 57 | - $this->setBlockType(self::BLOCK_TYPE); |
|
| 58 | - $this->setSupportedRoutes( |
|
| 59 | - array( |
|
| 60 | - 'EventEspresso\core\domain\entities\route_match\specifications\admin\EspressoStandardPostTypeEditor', |
|
| 61 | - 'EventEspresso\core\domain\entities\route_match\specifications\admin\WordPressPostTypeEditor', |
|
| 62 | - 'EventEspresso\core\domain\entities\route_match\specifications\frontend\EspressoBlockRenderer', |
|
| 63 | - 'EventEspresso\core\domain\entities\route_match\specifications\frontend\AnyFrontendRequest' |
|
| 64 | - ) |
|
| 65 | - ); |
|
| 66 | - $EVT_ID = $this->request->getRequestParam('page') === 'espresso_events' |
|
| 67 | - ? $this->request->getRequestParam('post', 0) |
|
| 68 | - : 0; |
|
| 69 | - $this->setAttributes( |
|
| 70 | - array( |
|
| 71 | - 'eventId' => array( |
|
| 72 | - 'type' => 'number', |
|
| 73 | - 'default' => $EVT_ID, |
|
| 74 | - ), |
|
| 75 | - 'datetimeId' => array( |
|
| 76 | - 'type' => 'number', |
|
| 77 | - 'default' => 0, |
|
| 78 | - ), |
|
| 79 | - 'ticketId' => array( |
|
| 80 | - 'type' => 'number', |
|
| 81 | - 'default' => 0, |
|
| 82 | - ), |
|
| 83 | - 'status' => array( |
|
| 84 | - 'type' => 'string', |
|
| 85 | - 'default' => EEM_Registration::status_id_approved, |
|
| 86 | - ), |
|
| 87 | - 'limit' => array( |
|
| 88 | - 'type' => 'number', |
|
| 89 | - 'default' => 100, |
|
| 90 | - ), |
|
| 91 | - 'order' => array( |
|
| 92 | - 'type' => 'string', |
|
| 93 | - 'default' => 'ASC' |
|
| 94 | - ), |
|
| 95 | - 'orderBy' => array( |
|
| 96 | - 'type' => 'string', |
|
| 97 | - 'default' => 'lastThenFirstName', |
|
| 98 | - ), |
|
| 99 | - 'showGravatar' => array( |
|
| 100 | - 'type' => 'boolean', |
|
| 101 | - 'default' => false, |
|
| 102 | - ), |
|
| 103 | - 'avatarClass' => array( |
|
| 104 | - 'type' => 'string', |
|
| 105 | - 'default' => 'contact', |
|
| 106 | - ), |
|
| 107 | - 'avatarSize' => array( |
|
| 108 | - 'type' => 'number', |
|
| 109 | - 'default' => 24, |
|
| 110 | - ), |
|
| 111 | - 'displayOnArchives' => array( |
|
| 112 | - 'type' => 'boolean', |
|
| 113 | - 'default' => false, |
|
| 114 | - ), |
|
| 115 | - ) |
|
| 116 | - ); |
|
| 117 | - $this->setDynamic(); |
|
| 118 | - } |
|
| 49 | + /** |
|
| 50 | + * Perform any early setup required by the block |
|
| 51 | + * including setting the block type and supported post types |
|
| 52 | + * |
|
| 53 | + * @return void |
|
| 54 | + */ |
|
| 55 | + public function initialize() |
|
| 56 | + { |
|
| 57 | + $this->setBlockType(self::BLOCK_TYPE); |
|
| 58 | + $this->setSupportedRoutes( |
|
| 59 | + array( |
|
| 60 | + 'EventEspresso\core\domain\entities\route_match\specifications\admin\EspressoStandardPostTypeEditor', |
|
| 61 | + 'EventEspresso\core\domain\entities\route_match\specifications\admin\WordPressPostTypeEditor', |
|
| 62 | + 'EventEspresso\core\domain\entities\route_match\specifications\frontend\EspressoBlockRenderer', |
|
| 63 | + 'EventEspresso\core\domain\entities\route_match\specifications\frontend\AnyFrontendRequest' |
|
| 64 | + ) |
|
| 65 | + ); |
|
| 66 | + $EVT_ID = $this->request->getRequestParam('page') === 'espresso_events' |
|
| 67 | + ? $this->request->getRequestParam('post', 0) |
|
| 68 | + : 0; |
|
| 69 | + $this->setAttributes( |
|
| 70 | + array( |
|
| 71 | + 'eventId' => array( |
|
| 72 | + 'type' => 'number', |
|
| 73 | + 'default' => $EVT_ID, |
|
| 74 | + ), |
|
| 75 | + 'datetimeId' => array( |
|
| 76 | + 'type' => 'number', |
|
| 77 | + 'default' => 0, |
|
| 78 | + ), |
|
| 79 | + 'ticketId' => array( |
|
| 80 | + 'type' => 'number', |
|
| 81 | + 'default' => 0, |
|
| 82 | + ), |
|
| 83 | + 'status' => array( |
|
| 84 | + 'type' => 'string', |
|
| 85 | + 'default' => EEM_Registration::status_id_approved, |
|
| 86 | + ), |
|
| 87 | + 'limit' => array( |
|
| 88 | + 'type' => 'number', |
|
| 89 | + 'default' => 100, |
|
| 90 | + ), |
|
| 91 | + 'order' => array( |
|
| 92 | + 'type' => 'string', |
|
| 93 | + 'default' => 'ASC' |
|
| 94 | + ), |
|
| 95 | + 'orderBy' => array( |
|
| 96 | + 'type' => 'string', |
|
| 97 | + 'default' => 'lastThenFirstName', |
|
| 98 | + ), |
|
| 99 | + 'showGravatar' => array( |
|
| 100 | + 'type' => 'boolean', |
|
| 101 | + 'default' => false, |
|
| 102 | + ), |
|
| 103 | + 'avatarClass' => array( |
|
| 104 | + 'type' => 'string', |
|
| 105 | + 'default' => 'contact', |
|
| 106 | + ), |
|
| 107 | + 'avatarSize' => array( |
|
| 108 | + 'type' => 'number', |
|
| 109 | + 'default' => 24, |
|
| 110 | + ), |
|
| 111 | + 'displayOnArchives' => array( |
|
| 112 | + 'type' => 'boolean', |
|
| 113 | + 'default' => false, |
|
| 114 | + ), |
|
| 115 | + ) |
|
| 116 | + ); |
|
| 117 | + $this->setDynamic(); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Returns an array where the key corresponds to the incoming attribute name from the WP block |
|
| 123 | - * and the value corresponds to the attribute name for the existing EspressoEventAttendees shortcode |
|
| 124 | - * |
|
| 125 | - * @since 4.9.71.p |
|
| 126 | - * @return array |
|
| 127 | - */ |
|
| 128 | - private function getAttributesMap() |
|
| 129 | - { |
|
| 130 | - return array( |
|
| 131 | - 'eventId' => 'absint', |
|
| 132 | - 'datetimeId' => 'absint', |
|
| 133 | - 'ticketId' => 'absint', |
|
| 134 | - 'status' => 'sanitize_text_field', |
|
| 135 | - 'limit' => 'intval', |
|
| 136 | - 'showGravatar' => 'bool', |
|
| 137 | - 'avatarClass' => 'sanitize_text_field', |
|
| 138 | - 'avatarSize' => 'absint', |
|
| 139 | - 'displayOnArchives' => 'bool', |
|
| 140 | - 'order' => 'sanitize_text_field', |
|
| 141 | - 'orderBy' => 'sanitize_text_field', |
|
| 142 | - ); |
|
| 143 | - } |
|
| 121 | + /** |
|
| 122 | + * Returns an array where the key corresponds to the incoming attribute name from the WP block |
|
| 123 | + * and the value corresponds to the attribute name for the existing EspressoEventAttendees shortcode |
|
| 124 | + * |
|
| 125 | + * @since 4.9.71.p |
|
| 126 | + * @return array |
|
| 127 | + */ |
|
| 128 | + private function getAttributesMap() |
|
| 129 | + { |
|
| 130 | + return array( |
|
| 131 | + 'eventId' => 'absint', |
|
| 132 | + 'datetimeId' => 'absint', |
|
| 133 | + 'ticketId' => 'absint', |
|
| 134 | + 'status' => 'sanitize_text_field', |
|
| 135 | + 'limit' => 'intval', |
|
| 136 | + 'showGravatar' => 'bool', |
|
| 137 | + 'avatarClass' => 'sanitize_text_field', |
|
| 138 | + 'avatarSize' => 'absint', |
|
| 139 | + 'displayOnArchives' => 'bool', |
|
| 140 | + 'order' => 'sanitize_text_field', |
|
| 141 | + 'orderBy' => 'sanitize_text_field', |
|
| 142 | + ); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Sanitizes attributes. |
|
| 148 | - * |
|
| 149 | - * @param array $attributes |
|
| 150 | - * @return array |
|
| 151 | - */ |
|
| 152 | - private function sanitizeAttributes(array $attributes) |
|
| 153 | - { |
|
| 154 | - $sanitized_attributes = array(); |
|
| 155 | - foreach ($attributes as $attribute => $value) { |
|
| 156 | - $convert = $this->getAttributesMap(); |
|
| 157 | - if (isset($convert[ $attribute ])) { |
|
| 158 | - $sanitize = $convert[ $attribute ]; |
|
| 159 | - if ($sanitize === 'bool') { |
|
| 160 | - $sanitized_attributes[ $attribute ] = filter_var( |
|
| 161 | - $value, |
|
| 162 | - FILTER_VALIDATE_BOOLEAN |
|
| 163 | - ); |
|
| 164 | - } else { |
|
| 165 | - $sanitized_attributes[ $attribute ] = $sanitize($value); |
|
| 166 | - } |
|
| 167 | - // don't pass along attributes with a 0 value |
|
| 168 | - if ($sanitized_attributes[ $attribute ] === 0) { |
|
| 169 | - unset($sanitized_attributes[ $attribute ]); |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - return $attributes; |
|
| 174 | - } |
|
| 146 | + /** |
|
| 147 | + * Sanitizes attributes. |
|
| 148 | + * |
|
| 149 | + * @param array $attributes |
|
| 150 | + * @return array |
|
| 151 | + */ |
|
| 152 | + private function sanitizeAttributes(array $attributes) |
|
| 153 | + { |
|
| 154 | + $sanitized_attributes = array(); |
|
| 155 | + foreach ($attributes as $attribute => $value) { |
|
| 156 | + $convert = $this->getAttributesMap(); |
|
| 157 | + if (isset($convert[ $attribute ])) { |
|
| 158 | + $sanitize = $convert[ $attribute ]; |
|
| 159 | + if ($sanitize === 'bool') { |
|
| 160 | + $sanitized_attributes[ $attribute ] = filter_var( |
|
| 161 | + $value, |
|
| 162 | + FILTER_VALIDATE_BOOLEAN |
|
| 163 | + ); |
|
| 164 | + } else { |
|
| 165 | + $sanitized_attributes[ $attribute ] = $sanitize($value); |
|
| 166 | + } |
|
| 167 | + // don't pass along attributes with a 0 value |
|
| 168 | + if ($sanitized_attributes[ $attribute ] === 0) { |
|
| 169 | + unset($sanitized_attributes[ $attribute ]); |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + return $attributes; |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Returns the rendered HTML for the block |
|
| 179 | - * |
|
| 180 | - * @param array $attributes |
|
| 181 | - * @return string |
|
| 182 | - * @throws DomainException |
|
| 183 | - * @throws EE_Error |
|
| 184 | - */ |
|
| 185 | - public function renderBlock(array $attributes = array()) |
|
| 186 | - { |
|
| 187 | - $attributes = $this->sanitizeAttributes($attributes); |
|
| 188 | - return (is_archive() || is_front_page() || is_home()) && ! $attributes['displayOnArchives'] |
|
| 189 | - ? '' |
|
| 190 | - : $this->renderer->render($attributes); |
|
| 191 | - } |
|
| 177 | + /** |
|
| 178 | + * Returns the rendered HTML for the block |
|
| 179 | + * |
|
| 180 | + * @param array $attributes |
|
| 181 | + * @return string |
|
| 182 | + * @throws DomainException |
|
| 183 | + * @throws EE_Error |
|
| 184 | + */ |
|
| 185 | + public function renderBlock(array $attributes = array()) |
|
| 186 | + { |
|
| 187 | + $attributes = $this->sanitizeAttributes($attributes); |
|
| 188 | + return (is_archive() || is_front_page() || is_home()) && ! $attributes['displayOnArchives'] |
|
| 189 | + ? '' |
|
| 190 | + : $this->renderer->render($attributes); |
|
| 191 | + } |
|
| 192 | 192 | } |
@@ -18,314 +18,314 @@ |
||
| 18 | 18 | class RegisterCustomPostTypes |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var CustomPostTypeDefinitions $custom_post_types |
|
| 23 | - */ |
|
| 24 | - public $custom_post_types; |
|
| 21 | + /** |
|
| 22 | + * @var CustomPostTypeDefinitions $custom_post_types |
|
| 23 | + */ |
|
| 24 | + public $custom_post_types; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * @var WP_Post_Type[] $wp_post_types |
|
| 28 | - */ |
|
| 29 | - public $wp_post_types = array(); |
|
| 26 | + /** |
|
| 27 | + * @var WP_Post_Type[] $wp_post_types |
|
| 28 | + */ |
|
| 29 | + public $wp_post_types = array(); |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * RegisterCustomPostTypes constructor. |
|
| 34 | - * |
|
| 35 | - * @param CustomPostTypeDefinitions $custom_post_types |
|
| 36 | - */ |
|
| 37 | - public function __construct(CustomPostTypeDefinitions $custom_post_types) |
|
| 38 | - { |
|
| 39 | - $this->custom_post_types = $custom_post_types; |
|
| 40 | - } |
|
| 32 | + /** |
|
| 33 | + * RegisterCustomPostTypes constructor. |
|
| 34 | + * |
|
| 35 | + * @param CustomPostTypeDefinitions $custom_post_types |
|
| 36 | + */ |
|
| 37 | + public function __construct(CustomPostTypeDefinitions $custom_post_types) |
|
| 38 | + { |
|
| 39 | + $this->custom_post_types = $custom_post_types; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return WP_Post_Type[] |
|
| 45 | - */ |
|
| 46 | - public function getRegisteredCustomPostTypes() |
|
| 47 | - { |
|
| 48 | - return $this->wp_post_types; |
|
| 49 | - } |
|
| 43 | + /** |
|
| 44 | + * @return WP_Post_Type[] |
|
| 45 | + */ |
|
| 46 | + public function getRegisteredCustomPostTypes() |
|
| 47 | + { |
|
| 48 | + return $this->wp_post_types; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return void |
|
| 54 | - * @throws DomainException |
|
| 55 | - */ |
|
| 56 | - public function registerCustomPostTypes() |
|
| 57 | - { |
|
| 58 | - $custom_post_types = $this->custom_post_types->getDefinitions(); |
|
| 59 | - foreach ($custom_post_types as $custom_post_type => $CPT) { |
|
| 60 | - $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType( |
|
| 61 | - $custom_post_type, |
|
| 62 | - $CPT['singular_name'], |
|
| 63 | - $CPT['plural_name'], |
|
| 64 | - $CPT['singular_slug'], |
|
| 65 | - $CPT['plural_slug'], |
|
| 66 | - $CPT['args'] |
|
| 67 | - ); |
|
| 68 | - } |
|
| 69 | - } |
|
| 52 | + /** |
|
| 53 | + * @return void |
|
| 54 | + * @throws DomainException |
|
| 55 | + */ |
|
| 56 | + public function registerCustomPostTypes() |
|
| 57 | + { |
|
| 58 | + $custom_post_types = $this->custom_post_types->getDefinitions(); |
|
| 59 | + foreach ($custom_post_types as $custom_post_type => $CPT) { |
|
| 60 | + $this->wp_post_types[ $custom_post_type ] = $this->registerCustomPostType( |
|
| 61 | + $custom_post_type, |
|
| 62 | + $CPT['singular_name'], |
|
| 63 | + $CPT['plural_name'], |
|
| 64 | + $CPT['singular_slug'], |
|
| 65 | + $CPT['plural_slug'], |
|
| 66 | + $CPT['args'] |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Registers a new custom post type. Sets default settings given only the following params. |
|
| 74 | - * Returns the registered post type object, or an error object. |
|
| 75 | - * |
|
| 76 | - * @param string $post_type the actual post type name |
|
| 77 | - * IMPORTANT: |
|
| 78 | - * this must match what the slug is for admin pages related to this CPT |
|
| 79 | - * Also any models must use this slug as well |
|
| 80 | - * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
| 81 | - * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
| 82 | - * @param string $singular_slug |
|
| 83 | - * @param string $plural_slug |
|
| 84 | - * @param array $override_arguments exactly like $args as described in |
|
| 85 | - * http://codex.wordpress.org/Function_Reference/register_post_type |
|
| 86 | - * @return WP_Post_Type|WP_Error |
|
| 87 | - * @throws DomainException |
|
| 88 | - */ |
|
| 89 | - public function registerCustomPostType( |
|
| 90 | - $post_type, |
|
| 91 | - $singular_name, |
|
| 92 | - $plural_name, |
|
| 93 | - $singular_slug = '', |
|
| 94 | - $plural_slug = '', |
|
| 95 | - array $override_arguments = array() |
|
| 96 | - ) { |
|
| 97 | - $wp_post_type = register_post_type( |
|
| 98 | - $post_type, |
|
| 99 | - $this->prepareArguments( |
|
| 100 | - $post_type, |
|
| 101 | - $singular_name, |
|
| 102 | - $plural_name, |
|
| 103 | - $singular_slug, |
|
| 104 | - $plural_slug, |
|
| 105 | - $override_arguments |
|
| 106 | - ) |
|
| 107 | - ); |
|
| 108 | - if ($wp_post_type instanceof WP_Error) { |
|
| 109 | - throw new DomainException($wp_post_type->get_error_message()); |
|
| 110 | - } |
|
| 111 | - return $wp_post_type; |
|
| 112 | - } |
|
| 72 | + /** |
|
| 73 | + * Registers a new custom post type. Sets default settings given only the following params. |
|
| 74 | + * Returns the registered post type object, or an error object. |
|
| 75 | + * |
|
| 76 | + * @param string $post_type the actual post type name |
|
| 77 | + * IMPORTANT: |
|
| 78 | + * this must match what the slug is for admin pages related to this CPT |
|
| 79 | + * Also any models must use this slug as well |
|
| 80 | + * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
| 81 | + * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
| 82 | + * @param string $singular_slug |
|
| 83 | + * @param string $plural_slug |
|
| 84 | + * @param array $override_arguments exactly like $args as described in |
|
| 85 | + * http://codex.wordpress.org/Function_Reference/register_post_type |
|
| 86 | + * @return WP_Post_Type|WP_Error |
|
| 87 | + * @throws DomainException |
|
| 88 | + */ |
|
| 89 | + public function registerCustomPostType( |
|
| 90 | + $post_type, |
|
| 91 | + $singular_name, |
|
| 92 | + $plural_name, |
|
| 93 | + $singular_slug = '', |
|
| 94 | + $plural_slug = '', |
|
| 95 | + array $override_arguments = array() |
|
| 96 | + ) { |
|
| 97 | + $wp_post_type = register_post_type( |
|
| 98 | + $post_type, |
|
| 99 | + $this->prepareArguments( |
|
| 100 | + $post_type, |
|
| 101 | + $singular_name, |
|
| 102 | + $plural_name, |
|
| 103 | + $singular_slug, |
|
| 104 | + $plural_slug, |
|
| 105 | + $override_arguments |
|
| 106 | + ) |
|
| 107 | + ); |
|
| 108 | + if ($wp_post_type instanceof WP_Error) { |
|
| 109 | + throw new DomainException($wp_post_type->get_error_message()); |
|
| 110 | + } |
|
| 111 | + return $wp_post_type; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * @param string $post_type the actual post type name |
|
| 117 | - * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
| 118 | - * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
| 119 | - * @param string $singular_slug |
|
| 120 | - * @param string $plural_slug |
|
| 121 | - * @param array $override_arguments The default values set in this function will be overridden |
|
| 122 | - * by whatever you set in $override_arguments |
|
| 123 | - * @return array |
|
| 124 | - */ |
|
| 125 | - protected function prepareArguments( |
|
| 126 | - $post_type, |
|
| 127 | - $singular_name, |
|
| 128 | - $plural_name, |
|
| 129 | - $singular_slug, |
|
| 130 | - $plural_slug, |
|
| 131 | - array $override_arguments = array() |
|
| 132 | - ) { |
|
| 133 | - // verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name |
|
| 134 | - $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name; |
|
| 135 | - $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name; |
|
| 136 | - $labels = $this->getLabels( |
|
| 137 | - $singular_name, |
|
| 138 | - $plural_name, |
|
| 139 | - $singular_slug, |
|
| 140 | - $plural_slug |
|
| 141 | - ); |
|
| 142 | - // note the page_templates arg in the supports index is something specific to EE. |
|
| 143 | - // WordPress doesn't actually have that in their register_post_type api. |
|
| 144 | - $arguments = $this->getDefaultArguments($labels, $post_type, $plural_slug); |
|
| 145 | - if ($override_arguments) { |
|
| 146 | - if (isset($override_arguments['labels'])) { |
|
| 147 | - $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
| 148 | - } |
|
| 149 | - $arguments = array_merge($arguments, $override_arguments); |
|
| 150 | - $arguments['labels'] = $labels; |
|
| 151 | - } |
|
| 152 | - return $arguments; |
|
| 153 | - } |
|
| 115 | + /** |
|
| 116 | + * @param string $post_type the actual post type name |
|
| 117 | + * @param string $singular_name a pre-internationalized string for the singular name of the objects |
|
| 118 | + * @param string $plural_name a pre-internationalized string for the plural name of the objects |
|
| 119 | + * @param string $singular_slug |
|
| 120 | + * @param string $plural_slug |
|
| 121 | + * @param array $override_arguments The default values set in this function will be overridden |
|
| 122 | + * by whatever you set in $override_arguments |
|
| 123 | + * @return array |
|
| 124 | + */ |
|
| 125 | + protected function prepareArguments( |
|
| 126 | + $post_type, |
|
| 127 | + $singular_name, |
|
| 128 | + $plural_name, |
|
| 129 | + $singular_slug, |
|
| 130 | + $plural_slug, |
|
| 131 | + array $override_arguments = array() |
|
| 132 | + ) { |
|
| 133 | + // verify plural slug and singular slug, if they aren't we'll use $singular_name and $plural_name |
|
| 134 | + $singular_slug = ! empty($singular_slug) ? $singular_slug : $singular_name; |
|
| 135 | + $plural_slug = ! empty($plural_slug) ? $plural_slug : $plural_name; |
|
| 136 | + $labels = $this->getLabels( |
|
| 137 | + $singular_name, |
|
| 138 | + $plural_name, |
|
| 139 | + $singular_slug, |
|
| 140 | + $plural_slug |
|
| 141 | + ); |
|
| 142 | + // note the page_templates arg in the supports index is something specific to EE. |
|
| 143 | + // WordPress doesn't actually have that in their register_post_type api. |
|
| 144 | + $arguments = $this->getDefaultArguments($labels, $post_type, $plural_slug); |
|
| 145 | + if ($override_arguments) { |
|
| 146 | + if (isset($override_arguments['labels'])) { |
|
| 147 | + $labels = array_merge($arguments['labels'], $override_arguments['labels']); |
|
| 148 | + } |
|
| 149 | + $arguments = array_merge($arguments, $override_arguments); |
|
| 150 | + $arguments['labels'] = $labels; |
|
| 151 | + } |
|
| 152 | + return $arguments; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * @param string $singular_name |
|
| 158 | - * @param string $plural_name |
|
| 159 | - * @param string $singular_slug |
|
| 160 | - * @param string $plural_slug |
|
| 161 | - * @return array |
|
| 162 | - */ |
|
| 163 | - private function getLabels($singular_name, $plural_name, $singular_slug, $plural_slug) |
|
| 164 | - { |
|
| 165 | - return array( |
|
| 166 | - 'name' => $plural_name, |
|
| 167 | - 'singular_name' => $singular_name, |
|
| 168 | - 'singular_slug' => $singular_slug, |
|
| 169 | - 'plural_slug' => $plural_slug, |
|
| 170 | - 'add_new' => sprintf( |
|
| 171 | - /* Translators: Post Type Label */ |
|
| 172 | - esc_html_x('Add %s', 'Add Event', 'event_espresso'), |
|
| 173 | - $singular_name |
|
| 174 | - ), |
|
| 175 | - 'add_new_item' => sprintf( |
|
| 176 | - /* Translators: Post Type Label */ |
|
| 177 | - esc_html_x('Add New %s', 'Add New Event', 'event_espresso'), |
|
| 178 | - $singular_name |
|
| 179 | - ), |
|
| 180 | - 'edit_item' => sprintf( |
|
| 181 | - /* Translators: Post Type Label */ |
|
| 182 | - esc_html_x('Edit %s', 'Edit Event', 'event_espresso'), |
|
| 183 | - $singular_name |
|
| 184 | - ), |
|
| 185 | - 'new_item' => sprintf( |
|
| 186 | - /* Translators: Post Type Label */ |
|
| 187 | - esc_html_x('New %s', 'New Event', 'event_espresso'), |
|
| 188 | - $singular_name |
|
| 189 | - ), |
|
| 190 | - 'all_items' => sprintf( |
|
| 191 | - /* Translators: Post Type Label */ |
|
| 192 | - esc_html_x('All %s', 'All Events', 'event_espresso'), |
|
| 193 | - $plural_name |
|
| 194 | - ), |
|
| 195 | - 'view_item' => sprintf( |
|
| 196 | - /* Translators: Post Type Label */ |
|
| 197 | - esc_html_x('View %s', 'View Event', 'event_espresso'), |
|
| 198 | - $singular_name |
|
| 199 | - ), |
|
| 200 | - 'view_items' => sprintf( |
|
| 201 | - /* Translators: Post Type Label */ |
|
| 202 | - esc_html_x('View %s', 'View Events', 'event_espresso'), |
|
| 203 | - $plural_name |
|
| 204 | - ), |
|
| 205 | - 'archives' => sprintf( |
|
| 206 | - /* Translators: Post Type Label */ |
|
| 207 | - esc_html_x('%s Archives', 'Event Archives', 'event_espresso'), |
|
| 208 | - $singular_name |
|
| 209 | - ), |
|
| 210 | - 'attributes' => sprintf( |
|
| 211 | - /* Translators: Post Type Label */ |
|
| 212 | - esc_html_x('%s Attributes', 'Event Attributes', 'event_espresso'), |
|
| 213 | - $singular_name |
|
| 214 | - ), |
|
| 215 | - 'insert_into_item' => sprintf( |
|
| 216 | - /* Translators: Post Type Label */ |
|
| 217 | - esc_html_x('Insert into this %s', 'Insert into this Event', 'event_espresso'), |
|
| 218 | - $singular_name |
|
| 219 | - ), |
|
| 220 | - 'uploaded_to_this_item' => sprintf( |
|
| 221 | - /* Translators: Post Type Label */ |
|
| 222 | - esc_html_x('Uploaded to this %s', 'Uploaded to this Event', 'event_espresso'), |
|
| 223 | - $singular_name |
|
| 224 | - ), |
|
| 225 | - 'filter_items_list' => sprintf( |
|
| 226 | - /* Translators: Post Type Label */ |
|
| 227 | - esc_html_x('Filter %s list', 'Filter Events list', 'event_espresso'), |
|
| 228 | - $plural_name |
|
| 229 | - ), |
|
| 230 | - 'items_list_navigation' => sprintf( |
|
| 231 | - /* Translators: Post Type Label */ |
|
| 232 | - esc_html_x('%s list navigation', 'Events list navigation', 'event_espresso'), |
|
| 233 | - $plural_name |
|
| 234 | - ), |
|
| 235 | - 'items_list' => sprintf( |
|
| 236 | - /* Translators: Post Type Label */ |
|
| 237 | - esc_html_x('%s list', 'Events list', 'event_espresso'), |
|
| 238 | - $plural_name |
|
| 239 | - ), |
|
| 240 | - 'item_published' => sprintf( |
|
| 241 | - /* Translators: Post Type Label */ |
|
| 242 | - esc_html_x('%s published', 'Event published', 'event_espresso'), |
|
| 243 | - $singular_name |
|
| 244 | - ), |
|
| 245 | - 'item_published_privately' => sprintf( |
|
| 246 | - /* Translators: Post Type Label */ |
|
| 247 | - esc_html_x('%s published privately', 'Event published privately', 'event_espresso'), |
|
| 248 | - $singular_name |
|
| 249 | - ), |
|
| 250 | - 'item_reverted_to_draft' => sprintf( |
|
| 251 | - /* Translators: Post Type Label */ |
|
| 252 | - esc_html_x('%s reverted to draft', 'Event reverted to draft', 'event_espresso'), |
|
| 253 | - $singular_name |
|
| 254 | - ), |
|
| 255 | - 'item_scheduled' => sprintf( |
|
| 256 | - /* Translators: Post Type Label */ |
|
| 257 | - esc_html_x('%s scheduled', 'Event scheduled', 'event_espresso'), |
|
| 258 | - $singular_name |
|
| 259 | - ), |
|
| 260 | - 'item_updated' => sprintf( |
|
| 261 | - /* Translators: Post Type Label */ |
|
| 262 | - esc_html_x('%s updated', 'Event updated', 'event_espresso'), |
|
| 263 | - $singular_name |
|
| 264 | - ), |
|
| 265 | - 'search_items' => sprintf( |
|
| 266 | - /* Translators: Post Type Label */ |
|
| 267 | - esc_html_x('Search %s', 'Search Events', 'event_espresso'), |
|
| 268 | - $plural_name |
|
| 269 | - ), |
|
| 270 | - 'not_found' => sprintf( |
|
| 271 | - /* Translators: Post Type Label */ |
|
| 272 | - esc_html_x('No %s found', 'No Events found', 'event_espresso'), |
|
| 273 | - $plural_name |
|
| 274 | - ), |
|
| 275 | - 'not_found_in_trash' => sprintf( |
|
| 276 | - /* Translators: Post Type Label */ |
|
| 277 | - esc_html_x('No %s found in Trash', 'No Events found in Trash', 'event_espresso'), |
|
| 278 | - $plural_name |
|
| 279 | - ), |
|
| 280 | - 'parent_item_colon' => '', |
|
| 281 | - 'menu_name' => $plural_name, |
|
| 282 | - ); |
|
| 283 | - } |
|
| 156 | + /** |
|
| 157 | + * @param string $singular_name |
|
| 158 | + * @param string $plural_name |
|
| 159 | + * @param string $singular_slug |
|
| 160 | + * @param string $plural_slug |
|
| 161 | + * @return array |
|
| 162 | + */ |
|
| 163 | + private function getLabels($singular_name, $plural_name, $singular_slug, $plural_slug) |
|
| 164 | + { |
|
| 165 | + return array( |
|
| 166 | + 'name' => $plural_name, |
|
| 167 | + 'singular_name' => $singular_name, |
|
| 168 | + 'singular_slug' => $singular_slug, |
|
| 169 | + 'plural_slug' => $plural_slug, |
|
| 170 | + 'add_new' => sprintf( |
|
| 171 | + /* Translators: Post Type Label */ |
|
| 172 | + esc_html_x('Add %s', 'Add Event', 'event_espresso'), |
|
| 173 | + $singular_name |
|
| 174 | + ), |
|
| 175 | + 'add_new_item' => sprintf( |
|
| 176 | + /* Translators: Post Type Label */ |
|
| 177 | + esc_html_x('Add New %s', 'Add New Event', 'event_espresso'), |
|
| 178 | + $singular_name |
|
| 179 | + ), |
|
| 180 | + 'edit_item' => sprintf( |
|
| 181 | + /* Translators: Post Type Label */ |
|
| 182 | + esc_html_x('Edit %s', 'Edit Event', 'event_espresso'), |
|
| 183 | + $singular_name |
|
| 184 | + ), |
|
| 185 | + 'new_item' => sprintf( |
|
| 186 | + /* Translators: Post Type Label */ |
|
| 187 | + esc_html_x('New %s', 'New Event', 'event_espresso'), |
|
| 188 | + $singular_name |
|
| 189 | + ), |
|
| 190 | + 'all_items' => sprintf( |
|
| 191 | + /* Translators: Post Type Label */ |
|
| 192 | + esc_html_x('All %s', 'All Events', 'event_espresso'), |
|
| 193 | + $plural_name |
|
| 194 | + ), |
|
| 195 | + 'view_item' => sprintf( |
|
| 196 | + /* Translators: Post Type Label */ |
|
| 197 | + esc_html_x('View %s', 'View Event', 'event_espresso'), |
|
| 198 | + $singular_name |
|
| 199 | + ), |
|
| 200 | + 'view_items' => sprintf( |
|
| 201 | + /* Translators: Post Type Label */ |
|
| 202 | + esc_html_x('View %s', 'View Events', 'event_espresso'), |
|
| 203 | + $plural_name |
|
| 204 | + ), |
|
| 205 | + 'archives' => sprintf( |
|
| 206 | + /* Translators: Post Type Label */ |
|
| 207 | + esc_html_x('%s Archives', 'Event Archives', 'event_espresso'), |
|
| 208 | + $singular_name |
|
| 209 | + ), |
|
| 210 | + 'attributes' => sprintf( |
|
| 211 | + /* Translators: Post Type Label */ |
|
| 212 | + esc_html_x('%s Attributes', 'Event Attributes', 'event_espresso'), |
|
| 213 | + $singular_name |
|
| 214 | + ), |
|
| 215 | + 'insert_into_item' => sprintf( |
|
| 216 | + /* Translators: Post Type Label */ |
|
| 217 | + esc_html_x('Insert into this %s', 'Insert into this Event', 'event_espresso'), |
|
| 218 | + $singular_name |
|
| 219 | + ), |
|
| 220 | + 'uploaded_to_this_item' => sprintf( |
|
| 221 | + /* Translators: Post Type Label */ |
|
| 222 | + esc_html_x('Uploaded to this %s', 'Uploaded to this Event', 'event_espresso'), |
|
| 223 | + $singular_name |
|
| 224 | + ), |
|
| 225 | + 'filter_items_list' => sprintf( |
|
| 226 | + /* Translators: Post Type Label */ |
|
| 227 | + esc_html_x('Filter %s list', 'Filter Events list', 'event_espresso'), |
|
| 228 | + $plural_name |
|
| 229 | + ), |
|
| 230 | + 'items_list_navigation' => sprintf( |
|
| 231 | + /* Translators: Post Type Label */ |
|
| 232 | + esc_html_x('%s list navigation', 'Events list navigation', 'event_espresso'), |
|
| 233 | + $plural_name |
|
| 234 | + ), |
|
| 235 | + 'items_list' => sprintf( |
|
| 236 | + /* Translators: Post Type Label */ |
|
| 237 | + esc_html_x('%s list', 'Events list', 'event_espresso'), |
|
| 238 | + $plural_name |
|
| 239 | + ), |
|
| 240 | + 'item_published' => sprintf( |
|
| 241 | + /* Translators: Post Type Label */ |
|
| 242 | + esc_html_x('%s published', 'Event published', 'event_espresso'), |
|
| 243 | + $singular_name |
|
| 244 | + ), |
|
| 245 | + 'item_published_privately' => sprintf( |
|
| 246 | + /* Translators: Post Type Label */ |
|
| 247 | + esc_html_x('%s published privately', 'Event published privately', 'event_espresso'), |
|
| 248 | + $singular_name |
|
| 249 | + ), |
|
| 250 | + 'item_reverted_to_draft' => sprintf( |
|
| 251 | + /* Translators: Post Type Label */ |
|
| 252 | + esc_html_x('%s reverted to draft', 'Event reverted to draft', 'event_espresso'), |
|
| 253 | + $singular_name |
|
| 254 | + ), |
|
| 255 | + 'item_scheduled' => sprintf( |
|
| 256 | + /* Translators: Post Type Label */ |
|
| 257 | + esc_html_x('%s scheduled', 'Event scheduled', 'event_espresso'), |
|
| 258 | + $singular_name |
|
| 259 | + ), |
|
| 260 | + 'item_updated' => sprintf( |
|
| 261 | + /* Translators: Post Type Label */ |
|
| 262 | + esc_html_x('%s updated', 'Event updated', 'event_espresso'), |
|
| 263 | + $singular_name |
|
| 264 | + ), |
|
| 265 | + 'search_items' => sprintf( |
|
| 266 | + /* Translators: Post Type Label */ |
|
| 267 | + esc_html_x('Search %s', 'Search Events', 'event_espresso'), |
|
| 268 | + $plural_name |
|
| 269 | + ), |
|
| 270 | + 'not_found' => sprintf( |
|
| 271 | + /* Translators: Post Type Label */ |
|
| 272 | + esc_html_x('No %s found', 'No Events found', 'event_espresso'), |
|
| 273 | + $plural_name |
|
| 274 | + ), |
|
| 275 | + 'not_found_in_trash' => sprintf( |
|
| 276 | + /* Translators: Post Type Label */ |
|
| 277 | + esc_html_x('No %s found in Trash', 'No Events found in Trash', 'event_espresso'), |
|
| 278 | + $plural_name |
|
| 279 | + ), |
|
| 280 | + 'parent_item_colon' => '', |
|
| 281 | + 'menu_name' => $plural_name, |
|
| 282 | + ); |
|
| 283 | + } |
|
| 284 | 284 | |
| 285 | 285 | |
| 286 | - /** |
|
| 287 | - * @param array $labels |
|
| 288 | - * @param string $post_type |
|
| 289 | - * @param string $plural_slug |
|
| 290 | - * @return array |
|
| 291 | - */ |
|
| 292 | - private function getDefaultArguments(array $labels, $post_type, $plural_slug) |
|
| 293 | - { |
|
| 294 | - return array( |
|
| 295 | - 'labels' => $labels, |
|
| 296 | - 'public' => true, |
|
| 297 | - 'publicly_queryable' => true, |
|
| 298 | - 'show_ui' => false, |
|
| 299 | - 'show_ee_ui' => true, |
|
| 300 | - 'show_in_menu' => false, |
|
| 301 | - 'show_in_nav_menus' => false, |
|
| 302 | - 'query_var' => true, |
|
| 303 | - 'rewrite' => apply_filters( |
|
| 304 | - 'FHEE__EventEspresso_core_domain_entities_custom_post_types_RegisterCustomPostTypes__getDefaultArguments__rewrite', |
|
| 305 | - // legacy filter applied for now, |
|
| 306 | - // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
| 307 | - apply_filters( |
|
| 308 | - 'FHEE__EE_Register_CPTs__register_CPT__rewrite', |
|
| 309 | - array('slug' => $plural_slug), |
|
| 310 | - $post_type |
|
| 311 | - ), |
|
| 312 | - $post_type, |
|
| 313 | - $plural_slug |
|
| 314 | - ), |
|
| 315 | - 'capability_type' => 'post', |
|
| 316 | - 'map_meta_cap' => true, |
|
| 317 | - 'has_archive' => true, |
|
| 318 | - 'hierarchical' => false, |
|
| 319 | - 'menu_position' => null, |
|
| 320 | - 'supports' => array( |
|
| 321 | - 'title', |
|
| 322 | - 'editor', |
|
| 323 | - 'author', |
|
| 324 | - 'thumbnail', |
|
| 325 | - 'excerpt', |
|
| 326 | - 'custom-fields', |
|
| 327 | - 'comments', |
|
| 328 | - ), |
|
| 329 | - ); |
|
| 330 | - } |
|
| 286 | + /** |
|
| 287 | + * @param array $labels |
|
| 288 | + * @param string $post_type |
|
| 289 | + * @param string $plural_slug |
|
| 290 | + * @return array |
|
| 291 | + */ |
|
| 292 | + private function getDefaultArguments(array $labels, $post_type, $plural_slug) |
|
| 293 | + { |
|
| 294 | + return array( |
|
| 295 | + 'labels' => $labels, |
|
| 296 | + 'public' => true, |
|
| 297 | + 'publicly_queryable' => true, |
|
| 298 | + 'show_ui' => false, |
|
| 299 | + 'show_ee_ui' => true, |
|
| 300 | + 'show_in_menu' => false, |
|
| 301 | + 'show_in_nav_menus' => false, |
|
| 302 | + 'query_var' => true, |
|
| 303 | + 'rewrite' => apply_filters( |
|
| 304 | + 'FHEE__EventEspresso_core_domain_entities_custom_post_types_RegisterCustomPostTypes__getDefaultArguments__rewrite', |
|
| 305 | + // legacy filter applied for now, |
|
| 306 | + // later on we'll run a has_filter($tag) check and throw a doing_it_wrong() notice |
|
| 307 | + apply_filters( |
|
| 308 | + 'FHEE__EE_Register_CPTs__register_CPT__rewrite', |
|
| 309 | + array('slug' => $plural_slug), |
|
| 310 | + $post_type |
|
| 311 | + ), |
|
| 312 | + $post_type, |
|
| 313 | + $plural_slug |
|
| 314 | + ), |
|
| 315 | + 'capability_type' => 'post', |
|
| 316 | + 'map_meta_cap' => true, |
|
| 317 | + 'has_archive' => true, |
|
| 318 | + 'hierarchical' => false, |
|
| 319 | + 'menu_position' => null, |
|
| 320 | + 'supports' => array( |
|
| 321 | + 'title', |
|
| 322 | + 'editor', |
|
| 323 | + 'author', |
|
| 324 | + 'thumbnail', |
|
| 325 | + 'excerpt', |
|
| 326 | + 'custom-fields', |
|
| 327 | + 'comments', |
|
| 328 | + ), |
|
| 329 | + ); |
|
| 330 | + } |
|
| 331 | 331 | } |