@@ -1,29 +1,29 @@ |
||
1 | 1 | <div class="padding"> |
2 | 2 | <h3><?php esc_html_e('Need help with Event Espresso?', 'event_espresso'); ?></h3> |
3 | 3 | |
4 | - <h4><?php esc_html_e( 'You may be able to find an answer for your question or concern here:', 'event_espresso' ); ?></h4> |
|
4 | + <h4><?php esc_html_e('You may be able to find an answer for your question or concern here:', 'event_espresso'); ?></h4> |
|
5 | 5 | <ol> |
6 | - <li><strong><em><?php esc_html_e( 'A known issue.', 'event_espresso' ); ?></em></strong> <?php printf( esc_html__( 'Some themes and plugins have %1$sknown conflicts%2$s with Event Espresso. (You can also browse the %3$sEvent Espresso support pages%2$s or %4$sEvent Espresso support forums%2$s to see if other members have experienced and solved the problem.)', 'event_espresso' ), '<a href="https://eventespresso.com/wiki/known-third-party-plugin-theme-conflicts/" target="_blank">','</a>', '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4" target="_blank">', '<a href="https://eventespresso.com/support/forums/" target="_blank">' ); ?></li> |
|
7 | - <li><strong><em><?php esc_html_e( 'A plugin conflict.', 'event_espresso' ); ?></em></strong> <?php esc_html_e( 'You can check to see if there is a plugin conflict by temporarily deactivating all plugins except for Event Espresso. If the problem goes away, then reactivate your plugins one by one until the issue returns. This will help you pinpoint the source of the conflict.', 'event_espresso' ); ?></li> |
|
6 | + <li><strong><em><?php esc_html_e('A known issue.', 'event_espresso'); ?></em></strong> <?php printf(esc_html__('Some themes and plugins have %1$sknown conflicts%2$s with Event Espresso. (You can also browse the %3$sEvent Espresso support pages%2$s or %4$sEvent Espresso support forums%2$s to see if other members have experienced and solved the problem.)', 'event_espresso'), '<a href="https://eventespresso.com/wiki/known-third-party-plugin-theme-conflicts/" target="_blank">', '</a>', '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4" target="_blank">', '<a href="https://eventespresso.com/support/forums/" target="_blank">'); ?></li> |
|
7 | + <li><strong><em><?php esc_html_e('A plugin conflict.', 'event_espresso'); ?></em></strong> <?php esc_html_e('You can check to see if there is a plugin conflict by temporarily deactivating all plugins except for Event Espresso. If the problem goes away, then reactivate your plugins one by one until the issue returns. This will help you pinpoint the source of the conflict.', 'event_espresso'); ?></li> |
|
8 | 8 | <li> |
9 | - <strong><em><?php esc_html_e( 'A theme conflict.', 'event_espresso' ); ?></em></strong> |
|
9 | + <strong><em><?php esc_html_e('A theme conflict.', 'event_espresso'); ?></em></strong> |
|
10 | 10 | <?php |
11 | - $default_theme = wp_get_theme( WP_DEFAULT_THEME ); |
|
11 | + $default_theme = wp_get_theme(WP_DEFAULT_THEME); |
|
12 | 12 | |
13 | - if ( $default_theme->exists() ) { |
|
14 | - printf( esc_html__( 'If your problem is not a known issue or caused by a plugin, then try activating %s (the default WordPress theme).', 'event_espresso' ), $default_theme->get( 'Name' ) ); |
|
13 | + if ($default_theme->exists()) { |
|
14 | + printf(esc_html__('If your problem is not a known issue or caused by a plugin, then try activating %s (the default WordPress theme).', 'event_espresso'), $default_theme->get('Name')); |
|
15 | 15 | } else { |
16 | - esc_html_e( 'If your problem is not a known issue or caused by a plugin, then try activating the default WordPress theme.', 'event_espresso' ); |
|
16 | + esc_html_e('If your problem is not a known issue or caused by a plugin, then try activating the default WordPress theme.', 'event_espresso'); |
|
17 | 17 | } |
18 | 18 | ?> |
19 | - <?php esc_html_e( 'If this solves the problem for you, then something in your theme is causing this issue. Check to see if an update is available for your WordPress theme or reach out to the theme author.', 'event_espresso' ); ?> |
|
19 | + <?php esc_html_e('If this solves the problem for you, then something in your theme is causing this issue. Check to see if an update is available for your WordPress theme or reach out to the theme author.', 'event_espresso'); ?> |
|
20 | 20 | </li> |
21 | 21 | </ol> |
22 | 22 | |
23 | - <p><?php esc_html_e( 'If none of the suggestions above help you find a solution, then feel free to reach out to the support team at Event Espresso.', 'event_espresso' ); ?></p> |
|
24 | - <p><?php printf( esc_html__( 'Login to your account on EventEspresso.com and %1$screate a support post in our member support forums%2$s. Use a %3$sclear and descriptive title%4$s in your support post, %3$sdescribe the issue to the best of your knowledge%4$s, and %3$snever post any sensitive information such as login details%4$s. Be sure to also include %5$simportant information in the section below%2$s about your WordPress site.', 'event_espresso' ), '<a href="https://eventespresso.com/support/forums/" target="_blank">','</a>','<strong>','</strong>','<a href="#espresso_important_information_settings">' ); ?></p> |
|
23 | + <p><?php esc_html_e('If none of the suggestions above help you find a solution, then feel free to reach out to the support team at Event Espresso.', 'event_espresso'); ?></p> |
|
24 | + <p><?php printf(esc_html__('Login to your account on EventEspresso.com and %1$screate a support post in our member support forums%2$s. Use a %3$sclear and descriptive title%4$s in your support post, %3$sdescribe the issue to the best of your knowledge%4$s, and %3$snever post any sensitive information such as login details%4$s. Be sure to also include %5$simportant information in the section below%2$s about your WordPress site.', 'event_espresso'), '<a href="https://eventespresso.com/support/forums/" target="_blank">', '</a>', '<strong>', '</strong>', '<a href="#espresso_important_information_settings">'); ?></p> |
|
25 | 25 | |
26 | - <h4><?php esc_html_e( 'Have an emergency?', 'event_espresso' ); ?></h4> |
|
26 | + <h4><?php esc_html_e('Have an emergency?', 'event_espresso'); ?></h4> |
|
27 | 27 | |
28 | - <p><?php printf( esc_html__( 'We offer support tokens to members that need help with a time-sensitive issue. A support token will provide you with up to 30 minutes of one-on-one time with a team member at Event Espresso. If you have an emergency and need help quickly, then please %1$spurchase a support token%2$s.', 'event_espresso' ), '<a href="https://eventespresso.com/product/premium-support-token/?utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=help_support_tab&utm_content=support_token" target="_blank">','</a>' ); ?></p> |
|
28 | + <p><?php printf(esc_html__('We offer support tokens to members that need help with a time-sensitive issue. A support token will provide you with up to 30 minutes of one-on-one time with a team member at Event Espresso. If you have an emergency and need help quickly, then please %1$spurchase a support token%2$s.', 'event_espresso'), '<a href="https://eventespresso.com/product/premium-support-token/?utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=help_support_tab&utm_content=support_token" target="_blank">', '</a>'); ?></p> |
|
29 | 29 | </div> |
30 | 30 | \ No newline at end of file |
@@ -1,26 +1,26 @@ |
||
1 | 1 | <div class="padding"> |
2 | - <?php esc_html_e( 'If you want to integrate with Event Espresso or participate in building code, then you are in the right place. The following resources can help you get started.', 'event_espresso' ); ?> |
|
3 | - <h2><?php esc_html_e( 'Developer Resources', 'event_espresso' ); ?></h2> |
|
2 | + <?php esc_html_e('If you want to integrate with Event Espresso or participate in building code, then you are in the right place. The following resources can help you get started.', 'event_espresso'); ?> |
|
3 | + <h2><?php esc_html_e('Developer Resources', 'event_espresso'); ?></h2> |
|
4 | 4 | <ul> |
5 | - <li><?php printf( esc_html__( '%1$sEvent Espresso 4 Developer Documentation%2$s', 'event_espresso' ), '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs#getting-started-with-the-ee-developer-docs" target="_blank">','</a>' ); ?></li> |
|
6 | - <li><?php printf( esc_html__( '%1$sEvent Espresso 4 Developer News%2$s', 'event_espresso' ), '<a href="http://developer.eventespresso.com/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">','</a>' ); ?></li> |
|
7 | - <li><?php printf( esc_html__( '%1$sApply%2$s to be listed as an %3$sEvent Espresso Professional%2$s', 'event_espresso' ), '<a href="https://eventespresso.com/developers/event-espresso-pros-application/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">','</a>','<a href="https://eventespresso.com/developers/event-espresso-pros/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">' ); ?></li> |
|
5 | + <li><?php printf(esc_html__('%1$sEvent Espresso 4 Developer Documentation%2$s', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core/tree/master/docs#getting-started-with-the-ee-developer-docs" target="_blank">', '</a>'); ?></li> |
|
6 | + <li><?php printf(esc_html__('%1$sEvent Espresso 4 Developer News%2$s', 'event_espresso'), '<a href="http://developer.eventespresso.com/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">', '</a>'); ?></li> |
|
7 | + <li><?php printf(esc_html__('%1$sApply%2$s to be listed as an %3$sEvent Espresso Professional%2$s', 'event_espresso'), '<a href="https://eventespresso.com/developers/event-espresso-pros-application/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">', '</a>', '<a href="https://eventespresso.com/developers/event-espresso-pros/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">'); ?></li> |
|
8 | 8 | </ul> |
9 | 9 | |
10 | - <h2><?php esc_html_e( 'Event Espresso 4 Articles for Developers', 'event_espresso' ); ?></h2> |
|
10 | + <h2><?php esc_html_e('Event Espresso 4 Articles for Developers', 'event_espresso'); ?></h2> |
|
11 | 11 | <ul> |
12 | - <li><?php printf( esc_html__( '%1$sCustom Post Types Usage%2$s', 'event_espresso' ), '<a href="https://eventespresso.com/2014/02/epsresso-brewery-custom-post-types-event-espresso/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">','</a>' ); ?></li> |
|
13 | - <li><?php printf( esc_html__( '%1$sTheme Development%2$s', 'event_espresso' ), '<a href="https://eventespresso.com/2014/02/developers-corner-theming-event-espresso-4/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">','</a>' ); ?></li> |
|
14 | - <li><?php printf( esc_html__( '%1$sCapability System%2$s', 'event_espresso' ), '<a href="http://developer.eventespresso.com/docs/ee-capability-system-overview/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">','</a>' ); ?></li> |
|
15 | - <li><?php printf( esc_html__( '%1$sPayment Method Development%2$s', 'event_espresso' ), '<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/L--Payment-Methods-and-Gateways/creating-a-payment-method.md" target="_blank">','</a>' ); ?></li> |
|
16 | - <li><?php printf( esc_html__( '%1$sMessages System in Event Espresso 4%2$s', 'event_espresso' ), '<a href="https://eventespresso.com/2014/03/messages-systemyour-tool-getting-word/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">','</a>' ); ?></li> |
|
17 | - <li><?php printf( esc_html__( '%1$sDatabase Model System%2$s (used for interfacing with EE4 data via WordPress plugins and server side querying)', 'event_espresso' ), '<a href="http://developer.eventespresso.com/docs/using-ee4-model-objects/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">','</a>' ); ?></li> |
|
12 | + <li><?php printf(esc_html__('%1$sCustom Post Types Usage%2$s', 'event_espresso'), '<a href="https://eventespresso.com/2014/02/epsresso-brewery-custom-post-types-event-espresso/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">', '</a>'); ?></li> |
|
13 | + <li><?php printf(esc_html__('%1$sTheme Development%2$s', 'event_espresso'), '<a href="https://eventespresso.com/2014/02/developers-corner-theming-event-espresso-4/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">', '</a>'); ?></li> |
|
14 | + <li><?php printf(esc_html__('%1$sCapability System%2$s', 'event_espresso'), '<a href="http://developer.eventespresso.com/docs/ee-capability-system-overview/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">', '</a>'); ?></li> |
|
15 | + <li><?php printf(esc_html__('%1$sPayment Method Development%2$s', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/L--Payment-Methods-and-Gateways/creating-a-payment-method.md" target="_blank">', '</a>'); ?></li> |
|
16 | + <li><?php printf(esc_html__('%1$sMessages System in Event Espresso 4%2$s', 'event_espresso'), '<a href="https://eventespresso.com/2014/03/messages-systemyour-tool-getting-word/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">', '</a>'); ?></li> |
|
17 | + <li><?php printf(esc_html__('%1$sDatabase Model System%2$s (used for interfacing with EE4 data via WordPress plugins and server side querying)', 'event_espresso'), '<a href="http://developer.eventespresso.com/docs/using-ee4-model-objects/?ee_ver=ee4&utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=ee_support_page&utm_content=developers_tab" target="_blank">', '</a>'); ?></li> |
|
18 | 18 | </ul> |
19 | 19 | |
20 | - <h2><?php esc_html_e( 'REST API Resources', 'event_espresso' ); ?></h2> |
|
20 | + <h2><?php esc_html_e('REST API Resources', 'event_espresso'); ?></h2> |
|
21 | 21 | <ul> |
22 | - <li><?php printf( esc_html__( '%1$sREST API: Introduction%2$s', 'event_espresso' ), '<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/C--REST-API/ee4-rest-api-introduction.md" target="_blank">','</a>' ); ?></li> |
|
23 | - <li><?php printf( esc_html__( '%1$sREST API: Reading Data%2$s', 'event_espresso' ), '<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/C--REST-API/ee4-rest-api-reading-data.md" target="_blank">','</a>' ); ?></li> |
|
24 | - <li><?php printf( esc_html__( '%1$sBuilding an EE4 Add-on Using the REST API%2$s', 'event_espresso' ), '<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/T--Tutorials/building-an-ee4-addon-that-uses-angular-js-and-the-ee4-json-rest-api.md" target="_blank">','</a>' ); ?></li> |
|
22 | + <li><?php printf(esc_html__('%1$sREST API: Introduction%2$s', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/C--REST-API/ee4-rest-api-introduction.md" target="_blank">', '</a>'); ?></li> |
|
23 | + <li><?php printf(esc_html__('%1$sREST API: Reading Data%2$s', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/C--REST-API/ee4-rest-api-reading-data.md" target="_blank">', '</a>'); ?></li> |
|
24 | + <li><?php printf(esc_html__('%1$sBuilding an EE4 Add-on Using the REST API%2$s', 'event_espresso'), '<a href="https://github.com/eventespresso/event-espresso-core/blob/master/docs/T--Tutorials/building-an-ee4-addon-that-uses-angular-js-and-the-ee4-json-rest-api.md" target="_blank">', '</a>'); ?></li> |
|
25 | 25 | </ul> |
26 | 26 | </div> |
27 | 27 | \ No newline at end of file |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | /** |
580 | 580 | * returns any events attached to this attendee ($_Event property); |
581 | 581 | * |
582 | - * @return array |
|
582 | + * @return EE_Base_Class[] |
|
583 | 583 | */ |
584 | 584 | public function events() |
585 | 585 | { |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | * used to save the billing info |
595 | 595 | * |
596 | 596 | * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
597 | - * @return EE_Form_Section_Proper|null |
|
597 | + * @return null|EE_Billing_Info_Form |
|
598 | 598 | */ |
599 | 599 | public function billing_info_for_payment_method($payment_method) |
600 | 600 | { |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | /** |
@@ -33,16 +33,16 @@ discard block |
||
33 | 33 | */ |
34 | 34 | protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
35 | 35 | { |
36 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
37 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
36 | + if ( ! isset($fieldValues['ATT_full_name'])) { |
|
37 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'].' ' : ''; |
|
38 | 38 | $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
39 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
39 | + $fieldValues['ATT_full_name'] = $fname.$lname; |
|
40 | 40 | } |
41 | - if (! isset($fieldValues['ATT_slug'])) { |
|
41 | + if ( ! isset($fieldValues['ATT_slug'])) { |
|
42 | 42 | // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
43 | 43 | $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
44 | 44 | } |
45 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
45 | + if ( ! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
46 | 46 | $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
47 | 47 | } |
48 | 48 | parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
@@ -303,22 +303,22 @@ discard block |
||
303 | 303 | $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
304 | 304 | foreach ($initial_address_fields as $address_field_name) { |
305 | 305 | $address_fields_value = $this->get($address_field_name); |
306 | - if (! empty($address_fields_value)) { |
|
306 | + if ( ! empty($address_fields_value)) { |
|
307 | 307 | $full_address_array[] = $address_fields_value; |
308 | 308 | } |
309 | 309 | } |
310 | 310 | //now handle state and country |
311 | 311 | $state_obj = $this->state_obj(); |
312 | - if (! empty($state_obj)) { |
|
312 | + if ( ! empty($state_obj)) { |
|
313 | 313 | $full_address_array[] = $state_obj->name(); |
314 | 314 | } |
315 | 315 | $country_obj = $this->country_obj(); |
316 | - if (! empty($country_obj)) { |
|
316 | + if ( ! empty($country_obj)) { |
|
317 | 317 | $full_address_array[] = $country_obj->name(); |
318 | 318 | } |
319 | 319 | //lastly get the xip |
320 | 320 | $zip_value = $this->zip(); |
321 | - if (! empty($zip_value)) { |
|
321 | + if ( ! empty($zip_value)) { |
|
322 | 322 | $full_address_array[] = $zip_value; |
323 | 323 | } |
324 | 324 | return $full_address_array; |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | public function get_most_recent_registration_for_event($event_id) |
553 | 553 | { |
554 | 554 | return $this->get_first_related('Registration', |
555 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')));//, '=', 'OBJECT_K' ); |
|
555 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC'))); //, '=', 'OBJECT_K' ); |
|
556 | 556 | } |
557 | 557 | |
558 | 558 | |
@@ -578,11 +578,11 @@ discard block |
||
578 | 578 | public function billing_info_for_payment_method($payment_method) |
579 | 579 | { |
580 | 580 | $pm_type = $payment_method->type_obj(); |
581 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
581 | + if ( ! $pm_type instanceof EE_PMT_Base) { |
|
582 | 582 | return null; |
583 | 583 | } |
584 | 584 | $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
585 | - if (! $billing_info) { |
|
585 | + if ( ! $billing_info) { |
|
586 | 586 | return null; |
587 | 587 | } |
588 | 588 | $billing_form = $pm_type->billing_form(); |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | public function get_billing_info_postmeta_name($payment_method) |
604 | 604 | { |
605 | 605 | if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
606 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
606 | + return 'billing_info_'.$payment_method->type_obj()->system_name(); |
|
607 | 607 | } else { |
608 | 608 | return null; |
609 | 609 | } |
@@ -620,7 +620,7 @@ discard block |
||
620 | 620 | */ |
621 | 621 | public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
622 | 622 | { |
623 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
623 | + if ( ! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
624 | 624 | EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
625 | 625 | return false; |
626 | 626 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Event Espresso |
@@ -23,670 +23,670 @@ discard block |
||
23 | 23 | class EE_Attendee extends EE_CPT_Base implements EEI_Contact, EEI_Address, EEI_Admin_Links, EEI_Attendee |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * Sets some dynamic defaults |
|
28 | - * |
|
29 | - * @param array $fieldValues |
|
30 | - * @param bool $bydb |
|
31 | - * @param string $timezone |
|
32 | - * @param array $date_formats |
|
33 | - */ |
|
34 | - protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
35 | - { |
|
36 | - if (! isset($fieldValues['ATT_full_name'])) { |
|
37 | - $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
38 | - $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
39 | - $fieldValues['ATT_full_name'] = $fname . $lname; |
|
40 | - } |
|
41 | - if (! isset($fieldValues['ATT_slug'])) { |
|
42 | - // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
43 | - $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
44 | - } |
|
45 | - if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
46 | - $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
47 | - } |
|
48 | - parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @param array $props_n_values incoming values |
|
54 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
55 | - * used.) |
|
56 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
57 | - * date_format and the second value is the time format |
|
58 | - * @return EE_Attendee |
|
59 | - */ |
|
60 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
61 | - { |
|
62 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
63 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @param array $props_n_values incoming values from the database |
|
69 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
70 | - * the website will be used. |
|
71 | - * @return EE_Attendee |
|
72 | - */ |
|
73 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
74 | - { |
|
75 | - return new self($props_n_values, true, $timezone); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Set Attendee First Name |
|
81 | - * |
|
82 | - * @access public |
|
83 | - * @param string $fname |
|
84 | - */ |
|
85 | - public function set_fname($fname = '') |
|
86 | - { |
|
87 | - $this->set('ATT_fname', $fname); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Set Attendee Last Name |
|
93 | - * |
|
94 | - * @access public |
|
95 | - * @param string $lname |
|
96 | - */ |
|
97 | - public function set_lname($lname = '') |
|
98 | - { |
|
99 | - $this->set('ATT_lname', $lname); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Set Attendee Address |
|
105 | - * |
|
106 | - * @access public |
|
107 | - * @param string $address |
|
108 | - */ |
|
109 | - public function set_address($address = '') |
|
110 | - { |
|
111 | - $this->set('ATT_address', $address); |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * Set Attendee Address2 |
|
117 | - * |
|
118 | - * @access public |
|
119 | - * @param string $address2 |
|
120 | - */ |
|
121 | - public function set_address2($address2 = '') |
|
122 | - { |
|
123 | - $this->set('ATT_address2', $address2); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * Set Attendee City |
|
129 | - * |
|
130 | - * @access public |
|
131 | - * @param string $city |
|
132 | - */ |
|
133 | - public function set_city($city = '') |
|
134 | - { |
|
135 | - $this->set('ATT_city', $city); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * Set Attendee State ID |
|
141 | - * |
|
142 | - * @access public |
|
143 | - * @param int $STA_ID |
|
144 | - */ |
|
145 | - public function set_state($STA_ID = 0) |
|
146 | - { |
|
147 | - $this->set('STA_ID', $STA_ID); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * Set Attendee Country ISO Code |
|
153 | - * |
|
154 | - * @access public |
|
155 | - * @param string $CNT_ISO |
|
156 | - */ |
|
157 | - public function set_country($CNT_ISO = '') |
|
158 | - { |
|
159 | - $this->set('CNT_ISO', $CNT_ISO); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Set Attendee Zip/Postal Code |
|
165 | - * |
|
166 | - * @access public |
|
167 | - * @param string $zip |
|
168 | - */ |
|
169 | - public function set_zip($zip = '') |
|
170 | - { |
|
171 | - $this->set('ATT_zip', $zip); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * Set Attendee Email Address |
|
177 | - * |
|
178 | - * @access public |
|
179 | - * @param string $email |
|
180 | - */ |
|
181 | - public function set_email($email = '') |
|
182 | - { |
|
183 | - $this->set('ATT_email', $email); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Set Attendee Phone |
|
189 | - * |
|
190 | - * @access public |
|
191 | - * @param string $phone |
|
192 | - */ |
|
193 | - public function set_phone($phone = '') |
|
194 | - { |
|
195 | - $this->set('ATT_phone', $phone); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * set deleted |
|
201 | - * |
|
202 | - * @access public |
|
203 | - * @param bool $ATT_deleted |
|
204 | - */ |
|
205 | - public function set_deleted($ATT_deleted = false) |
|
206 | - { |
|
207 | - $this->set('ATT_deleted', $ATT_deleted); |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Returns the value for the post_author id saved with the cpt |
|
213 | - * |
|
214 | - * @since 4.5.0 |
|
215 | - * @return int |
|
216 | - */ |
|
217 | - public function wp_user() |
|
218 | - { |
|
219 | - return $this->get('ATT_author'); |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * get Attendee First Name |
|
225 | - * |
|
226 | - * @access public |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - public function fname() |
|
230 | - { |
|
231 | - return $this->get('ATT_fname'); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * echoes out the attendee's first name |
|
237 | - * |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - public function e_full_name() |
|
241 | - { |
|
242 | - echo $this->full_name(); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * Returns the first and last name concatenated together with a space. |
|
248 | - * |
|
249 | - * @param bool $apply_html_entities |
|
250 | - * @return string |
|
251 | - */ |
|
252 | - public function full_name($apply_html_entities = false) |
|
253 | - { |
|
254 | - $full_name = array( |
|
255 | - $this->fname(), |
|
256 | - $this->lname(), |
|
257 | - ); |
|
258 | - $full_name = array_filter($full_name); |
|
259 | - $full_name = implode(' ', $full_name); |
|
260 | - return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
266 | - * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
267 | - * attendee. |
|
268 | - * |
|
269 | - * @param bool $apply_html_entities |
|
270 | - * @return string |
|
271 | - */ |
|
272 | - public function ATT_full_name($apply_html_entities = false) |
|
273 | - { |
|
274 | - return $apply_html_entities |
|
275 | - ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
276 | - : $this->get('ATT_full_name'); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * get Attendee Last Name |
|
282 | - * |
|
283 | - * @access public |
|
284 | - * @return string |
|
285 | - */ |
|
286 | - public function lname() |
|
287 | - { |
|
288 | - return $this->get('ATT_lname'); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
294 | - * |
|
295 | - * @return array numerically indexed, with each part of the address that is known. |
|
296 | - * Eg, if the user only responded to state and country, |
|
297 | - * it would be array(0=>'Alabama',1=>'USA') |
|
298 | - * @return array |
|
299 | - */ |
|
300 | - public function full_address_as_array() |
|
301 | - { |
|
302 | - $full_address_array = array(); |
|
303 | - $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
304 | - foreach ($initial_address_fields as $address_field_name) { |
|
305 | - $address_fields_value = $this->get($address_field_name); |
|
306 | - if (! empty($address_fields_value)) { |
|
307 | - $full_address_array[] = $address_fields_value; |
|
308 | - } |
|
309 | - } |
|
310 | - //now handle state and country |
|
311 | - $state_obj = $this->state_obj(); |
|
312 | - if (! empty($state_obj)) { |
|
313 | - $full_address_array[] = $state_obj->name(); |
|
314 | - } |
|
315 | - $country_obj = $this->country_obj(); |
|
316 | - if (! empty($country_obj)) { |
|
317 | - $full_address_array[] = $country_obj->name(); |
|
318 | - } |
|
319 | - //lastly get the xip |
|
320 | - $zip_value = $this->zip(); |
|
321 | - if (! empty($zip_value)) { |
|
322 | - $full_address_array[] = $zip_value; |
|
323 | - } |
|
324 | - return $full_address_array; |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * get Attendee Address |
|
330 | - * |
|
331 | - * @return string |
|
332 | - */ |
|
333 | - public function address() |
|
334 | - { |
|
335 | - return $this->get('ATT_address'); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * get Attendee Address2 |
|
341 | - * |
|
342 | - * @return string |
|
343 | - */ |
|
344 | - public function address2() |
|
345 | - { |
|
346 | - return $this->get('ATT_address2'); |
|
347 | - } |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * get Attendee City |
|
352 | - * |
|
353 | - * @return string |
|
354 | - */ |
|
355 | - public function city() |
|
356 | - { |
|
357 | - return $this->get('ATT_city'); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * get Attendee State ID |
|
363 | - * |
|
364 | - * @return string |
|
365 | - */ |
|
366 | - public function state_ID() |
|
367 | - { |
|
368 | - return $this->get('STA_ID'); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - /** |
|
373 | - * @return string |
|
374 | - */ |
|
375 | - public function state_abbrev() |
|
376 | - { |
|
377 | - return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * Gets the state set to this attendee |
|
383 | - * |
|
384 | - * @return EE_State |
|
385 | - */ |
|
386 | - public function state_obj() |
|
387 | - { |
|
388 | - return $this->get_first_related('State'); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * Returns the state's name, otherwise 'Unknown' |
|
394 | - * |
|
395 | - * @return string |
|
396 | - */ |
|
397 | - public function state_name() |
|
398 | - { |
|
399 | - if ($this->state_obj()) { |
|
400 | - return $this->state_obj()->name(); |
|
401 | - } else { |
|
402 | - return ''; |
|
403 | - } |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * either displays the state abbreviation or the state name, as determined |
|
409 | - * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
410 | - * defaults to abbreviation |
|
411 | - * |
|
412 | - * @return string |
|
413 | - */ |
|
414 | - public function state() |
|
415 | - { |
|
416 | - if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
417 | - return $this->state_abbrev(); |
|
418 | - } else { |
|
419 | - return $this->state_name(); |
|
420 | - } |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * get Attendee Country ISO Code |
|
426 | - * |
|
427 | - * @return string |
|
428 | - */ |
|
429 | - public function country_ID() |
|
430 | - { |
|
431 | - return $this->get('CNT_ISO'); |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - /** |
|
436 | - * Gets country set for this attendee |
|
437 | - * |
|
438 | - * @return EE_Country |
|
439 | - */ |
|
440 | - public function country_obj() |
|
441 | - { |
|
442 | - return $this->get_first_related('Country'); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * Returns the country's name if known, otherwise 'Unknown' |
|
448 | - * |
|
449 | - * @return string |
|
450 | - */ |
|
451 | - public function country_name() |
|
452 | - { |
|
453 | - if ($this->country_obj()) { |
|
454 | - return $this->country_obj()->name(); |
|
455 | - } else { |
|
456 | - return ''; |
|
457 | - } |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * either displays the country ISO2 code or the country name, as determined |
|
463 | - * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
464 | - * defaults to abbreviation |
|
465 | - * |
|
466 | - * @return string |
|
467 | - */ |
|
468 | - public function country() |
|
469 | - { |
|
470 | - if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
471 | - return $this->country_ID(); |
|
472 | - } else { |
|
473 | - return $this->country_name(); |
|
474 | - } |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * get Attendee Zip/Postal Code |
|
480 | - * |
|
481 | - * @return string |
|
482 | - */ |
|
483 | - public function zip() |
|
484 | - { |
|
485 | - return $this->get('ATT_zip'); |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * get Attendee Email Address |
|
491 | - * |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - public function email() |
|
495 | - { |
|
496 | - return $this->get('ATT_email'); |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * get Attendee Phone # |
|
502 | - * |
|
503 | - * @return string |
|
504 | - */ |
|
505 | - public function phone() |
|
506 | - { |
|
507 | - return $this->get('ATT_phone'); |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * get deleted |
|
513 | - * |
|
514 | - * @return bool |
|
515 | - */ |
|
516 | - public function deleted() |
|
517 | - { |
|
518 | - return $this->get('ATT_deleted'); |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * Gets registrations of this attendee |
|
524 | - * |
|
525 | - * @param array $query_params |
|
526 | - * @return EE_Registration[] |
|
527 | - */ |
|
528 | - public function get_registrations($query_params = array()) |
|
529 | - { |
|
530 | - return $this->get_many_related('Registration', $query_params); |
|
531 | - } |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * Gets the most recent registration of this attendee |
|
536 | - * |
|
537 | - * @return EE_Registration |
|
538 | - */ |
|
539 | - public function get_most_recent_registration() |
|
540 | - { |
|
541 | - return $this->get_first_related('Registration', |
|
542 | - array('order_by' => array('REG_date' => 'DESC'))); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * Gets the most recent registration for this attend at this event |
|
548 | - * |
|
549 | - * @param int $event_id |
|
550 | - * @return EE_Registration |
|
551 | - */ |
|
552 | - public function get_most_recent_registration_for_event($event_id) |
|
553 | - { |
|
554 | - return $this->get_first_related('Registration', |
|
555 | - array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')));//, '=', 'OBJECT_K' ); |
|
556 | - } |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * returns any events attached to this attendee ($_Event property); |
|
561 | - * |
|
562 | - * @return array |
|
563 | - */ |
|
564 | - public function events() |
|
565 | - { |
|
566 | - return $this->get_many_related('Event'); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
572 | - * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
573 | - * used to save the billing info |
|
574 | - * |
|
575 | - * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
576 | - * @return EE_Form_Section_Proper|null |
|
577 | - */ |
|
578 | - public function billing_info_for_payment_method($payment_method) |
|
579 | - { |
|
580 | - $pm_type = $payment_method->type_obj(); |
|
581 | - if (! $pm_type instanceof EE_PMT_Base) { |
|
582 | - return null; |
|
583 | - } |
|
584 | - $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
585 | - if (! $billing_info) { |
|
586 | - return null; |
|
587 | - } |
|
588 | - $billing_form = $pm_type->billing_form(); |
|
589 | - if ($billing_form instanceof EE_Form_Section_Proper) { |
|
590 | - $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
591 | - } |
|
592 | - return $billing_form; |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - /** |
|
597 | - * Gets the postmeta key that holds this attendee's billing info for the |
|
598 | - * specified payment method |
|
599 | - * |
|
600 | - * @param EE_Payment_Method $payment_method |
|
601 | - * @return string |
|
602 | - */ |
|
603 | - public function get_billing_info_postmeta_name($payment_method) |
|
604 | - { |
|
605 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
606 | - return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
607 | - } else { |
|
608 | - return null; |
|
609 | - } |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
615 | - * retrieve it |
|
616 | - * |
|
617 | - * @param EE_Billing_Attendee_Info_Form $billing_form |
|
618 | - * @param EE_Payment_Method $payment_method |
|
619 | - * @return boolean |
|
620 | - */ |
|
621 | - public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
622 | - { |
|
623 | - if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
624 | - EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
625 | - return false; |
|
626 | - } |
|
627 | - $billing_form->clean_sensitive_data(); |
|
628 | - return update_post_meta($this->ID(), $this->get_billing_info_postmeta_name($payment_method), |
|
629 | - $billing_form->input_values(true)); |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * Return the link to the admin details for the object. |
|
635 | - * |
|
636 | - * @return string |
|
637 | - */ |
|
638 | - public function get_admin_details_link() |
|
639 | - { |
|
640 | - return $this->get_admin_edit_link(); |
|
641 | - } |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
646 | - * |
|
647 | - * @return string |
|
648 | - */ |
|
649 | - public function get_admin_edit_link() |
|
650 | - { |
|
651 | - EE_Registry::instance()->load_helper('URL'); |
|
652 | - return EEH_URL::add_query_args_and_nonce( |
|
653 | - array( |
|
654 | - 'page' => 'espresso_registrations', |
|
655 | - 'action' => 'edit_attendee', |
|
656 | - 'post' => $this->ID(), |
|
657 | - ), |
|
658 | - admin_url('admin.php') |
|
659 | - ); |
|
660 | - } |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * Returns the link to a settings page for the object. |
|
665 | - * |
|
666 | - * @return string |
|
667 | - */ |
|
668 | - public function get_admin_settings_link() |
|
669 | - { |
|
670 | - return $this->get_admin_edit_link(); |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - /** |
|
675 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
676 | - * |
|
677 | - * @return string |
|
678 | - */ |
|
679 | - public function get_admin_overview_link() |
|
680 | - { |
|
681 | - EE_Registry::instance()->load_helper('URL'); |
|
682 | - return EEH_URL::add_query_args_and_nonce( |
|
683 | - array( |
|
684 | - 'page' => 'espresso_registrations', |
|
685 | - 'action' => 'contact_list', |
|
686 | - ), |
|
687 | - admin_url('admin.php') |
|
688 | - ); |
|
689 | - } |
|
26 | + /** |
|
27 | + * Sets some dynamic defaults |
|
28 | + * |
|
29 | + * @param array $fieldValues |
|
30 | + * @param bool $bydb |
|
31 | + * @param string $timezone |
|
32 | + * @param array $date_formats |
|
33 | + */ |
|
34 | + protected function __construct($fieldValues = null, $bydb = false, $timezone = null, $date_formats = array()) |
|
35 | + { |
|
36 | + if (! isset($fieldValues['ATT_full_name'])) { |
|
37 | + $fname = isset($fieldValues['ATT_fname']) ? $fieldValues['ATT_fname'] . ' ' : ''; |
|
38 | + $lname = isset($fieldValues['ATT_lname']) ? $fieldValues['ATT_lname'] : ''; |
|
39 | + $fieldValues['ATT_full_name'] = $fname . $lname; |
|
40 | + } |
|
41 | + if (! isset($fieldValues['ATT_slug'])) { |
|
42 | + // $fieldValues['ATT_slug'] = sanitize_key(wp_generate_password(20)); |
|
43 | + $fieldValues['ATT_slug'] = sanitize_title($fieldValues['ATT_full_name']); |
|
44 | + } |
|
45 | + if (! isset($fieldValues['ATT_short_bio']) && isset($fieldValues['ATT_bio'])) { |
|
46 | + $fieldValues['ATT_short_bio'] = substr($fieldValues['ATT_bio'], 0, 50); |
|
47 | + } |
|
48 | + parent::__construct($fieldValues, $bydb, $timezone, $date_formats); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @param array $props_n_values incoming values |
|
54 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
55 | + * used.) |
|
56 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
57 | + * date_format and the second value is the time format |
|
58 | + * @return EE_Attendee |
|
59 | + */ |
|
60 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
61 | + { |
|
62 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
63 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @param array $props_n_values incoming values from the database |
|
69 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
70 | + * the website will be used. |
|
71 | + * @return EE_Attendee |
|
72 | + */ |
|
73 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
74 | + { |
|
75 | + return new self($props_n_values, true, $timezone); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Set Attendee First Name |
|
81 | + * |
|
82 | + * @access public |
|
83 | + * @param string $fname |
|
84 | + */ |
|
85 | + public function set_fname($fname = '') |
|
86 | + { |
|
87 | + $this->set('ATT_fname', $fname); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Set Attendee Last Name |
|
93 | + * |
|
94 | + * @access public |
|
95 | + * @param string $lname |
|
96 | + */ |
|
97 | + public function set_lname($lname = '') |
|
98 | + { |
|
99 | + $this->set('ATT_lname', $lname); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Set Attendee Address |
|
105 | + * |
|
106 | + * @access public |
|
107 | + * @param string $address |
|
108 | + */ |
|
109 | + public function set_address($address = '') |
|
110 | + { |
|
111 | + $this->set('ATT_address', $address); |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * Set Attendee Address2 |
|
117 | + * |
|
118 | + * @access public |
|
119 | + * @param string $address2 |
|
120 | + */ |
|
121 | + public function set_address2($address2 = '') |
|
122 | + { |
|
123 | + $this->set('ATT_address2', $address2); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * Set Attendee City |
|
129 | + * |
|
130 | + * @access public |
|
131 | + * @param string $city |
|
132 | + */ |
|
133 | + public function set_city($city = '') |
|
134 | + { |
|
135 | + $this->set('ATT_city', $city); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * Set Attendee State ID |
|
141 | + * |
|
142 | + * @access public |
|
143 | + * @param int $STA_ID |
|
144 | + */ |
|
145 | + public function set_state($STA_ID = 0) |
|
146 | + { |
|
147 | + $this->set('STA_ID', $STA_ID); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * Set Attendee Country ISO Code |
|
153 | + * |
|
154 | + * @access public |
|
155 | + * @param string $CNT_ISO |
|
156 | + */ |
|
157 | + public function set_country($CNT_ISO = '') |
|
158 | + { |
|
159 | + $this->set('CNT_ISO', $CNT_ISO); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Set Attendee Zip/Postal Code |
|
165 | + * |
|
166 | + * @access public |
|
167 | + * @param string $zip |
|
168 | + */ |
|
169 | + public function set_zip($zip = '') |
|
170 | + { |
|
171 | + $this->set('ATT_zip', $zip); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * Set Attendee Email Address |
|
177 | + * |
|
178 | + * @access public |
|
179 | + * @param string $email |
|
180 | + */ |
|
181 | + public function set_email($email = '') |
|
182 | + { |
|
183 | + $this->set('ATT_email', $email); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Set Attendee Phone |
|
189 | + * |
|
190 | + * @access public |
|
191 | + * @param string $phone |
|
192 | + */ |
|
193 | + public function set_phone($phone = '') |
|
194 | + { |
|
195 | + $this->set('ATT_phone', $phone); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * set deleted |
|
201 | + * |
|
202 | + * @access public |
|
203 | + * @param bool $ATT_deleted |
|
204 | + */ |
|
205 | + public function set_deleted($ATT_deleted = false) |
|
206 | + { |
|
207 | + $this->set('ATT_deleted', $ATT_deleted); |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Returns the value for the post_author id saved with the cpt |
|
213 | + * |
|
214 | + * @since 4.5.0 |
|
215 | + * @return int |
|
216 | + */ |
|
217 | + public function wp_user() |
|
218 | + { |
|
219 | + return $this->get('ATT_author'); |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * get Attendee First Name |
|
225 | + * |
|
226 | + * @access public |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + public function fname() |
|
230 | + { |
|
231 | + return $this->get('ATT_fname'); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * echoes out the attendee's first name |
|
237 | + * |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + public function e_full_name() |
|
241 | + { |
|
242 | + echo $this->full_name(); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * Returns the first and last name concatenated together with a space. |
|
248 | + * |
|
249 | + * @param bool $apply_html_entities |
|
250 | + * @return string |
|
251 | + */ |
|
252 | + public function full_name($apply_html_entities = false) |
|
253 | + { |
|
254 | + $full_name = array( |
|
255 | + $this->fname(), |
|
256 | + $this->lname(), |
|
257 | + ); |
|
258 | + $full_name = array_filter($full_name); |
|
259 | + $full_name = implode(' ', $full_name); |
|
260 | + return $apply_html_entities ? htmlentities($full_name, ENT_QUOTES, 'UTF-8') : $full_name; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * This returns the value of the `ATT_full_name` field which is usually equivalent to calling `full_name()` unless |
|
266 | + * the post_title field has been directly modified in the db for the post (espresso_attendees post type) for this |
|
267 | + * attendee. |
|
268 | + * |
|
269 | + * @param bool $apply_html_entities |
|
270 | + * @return string |
|
271 | + */ |
|
272 | + public function ATT_full_name($apply_html_entities = false) |
|
273 | + { |
|
274 | + return $apply_html_entities |
|
275 | + ? htmlentities($this->get('ATT_full_name'), ENT_QUOTES, 'UTF-8') |
|
276 | + : $this->get('ATT_full_name'); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * get Attendee Last Name |
|
282 | + * |
|
283 | + * @access public |
|
284 | + * @return string |
|
285 | + */ |
|
286 | + public function lname() |
|
287 | + { |
|
288 | + return $this->get('ATT_lname'); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Gets the attendee's full address as an array so client code can decide hwo to display it |
|
294 | + * |
|
295 | + * @return array numerically indexed, with each part of the address that is known. |
|
296 | + * Eg, if the user only responded to state and country, |
|
297 | + * it would be array(0=>'Alabama',1=>'USA') |
|
298 | + * @return array |
|
299 | + */ |
|
300 | + public function full_address_as_array() |
|
301 | + { |
|
302 | + $full_address_array = array(); |
|
303 | + $initial_address_fields = array('ATT_address', 'ATT_address2', 'ATT_city',); |
|
304 | + foreach ($initial_address_fields as $address_field_name) { |
|
305 | + $address_fields_value = $this->get($address_field_name); |
|
306 | + if (! empty($address_fields_value)) { |
|
307 | + $full_address_array[] = $address_fields_value; |
|
308 | + } |
|
309 | + } |
|
310 | + //now handle state and country |
|
311 | + $state_obj = $this->state_obj(); |
|
312 | + if (! empty($state_obj)) { |
|
313 | + $full_address_array[] = $state_obj->name(); |
|
314 | + } |
|
315 | + $country_obj = $this->country_obj(); |
|
316 | + if (! empty($country_obj)) { |
|
317 | + $full_address_array[] = $country_obj->name(); |
|
318 | + } |
|
319 | + //lastly get the xip |
|
320 | + $zip_value = $this->zip(); |
|
321 | + if (! empty($zip_value)) { |
|
322 | + $full_address_array[] = $zip_value; |
|
323 | + } |
|
324 | + return $full_address_array; |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * get Attendee Address |
|
330 | + * |
|
331 | + * @return string |
|
332 | + */ |
|
333 | + public function address() |
|
334 | + { |
|
335 | + return $this->get('ATT_address'); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * get Attendee Address2 |
|
341 | + * |
|
342 | + * @return string |
|
343 | + */ |
|
344 | + public function address2() |
|
345 | + { |
|
346 | + return $this->get('ATT_address2'); |
|
347 | + } |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * get Attendee City |
|
352 | + * |
|
353 | + * @return string |
|
354 | + */ |
|
355 | + public function city() |
|
356 | + { |
|
357 | + return $this->get('ATT_city'); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * get Attendee State ID |
|
363 | + * |
|
364 | + * @return string |
|
365 | + */ |
|
366 | + public function state_ID() |
|
367 | + { |
|
368 | + return $this->get('STA_ID'); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + /** |
|
373 | + * @return string |
|
374 | + */ |
|
375 | + public function state_abbrev() |
|
376 | + { |
|
377 | + return $this->state_obj() instanceof EE_State ? $this->state_obj()->abbrev() : ''; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * Gets the state set to this attendee |
|
383 | + * |
|
384 | + * @return EE_State |
|
385 | + */ |
|
386 | + public function state_obj() |
|
387 | + { |
|
388 | + return $this->get_first_related('State'); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * Returns the state's name, otherwise 'Unknown' |
|
394 | + * |
|
395 | + * @return string |
|
396 | + */ |
|
397 | + public function state_name() |
|
398 | + { |
|
399 | + if ($this->state_obj()) { |
|
400 | + return $this->state_obj()->name(); |
|
401 | + } else { |
|
402 | + return ''; |
|
403 | + } |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * either displays the state abbreviation or the state name, as determined |
|
409 | + * by the "FHEE__EEI_Address__state__use_abbreviation" filter. |
|
410 | + * defaults to abbreviation |
|
411 | + * |
|
412 | + * @return string |
|
413 | + */ |
|
414 | + public function state() |
|
415 | + { |
|
416 | + if (apply_filters('FHEE__EEI_Address__state__use_abbreviation', true, $this->state_obj())) { |
|
417 | + return $this->state_abbrev(); |
|
418 | + } else { |
|
419 | + return $this->state_name(); |
|
420 | + } |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * get Attendee Country ISO Code |
|
426 | + * |
|
427 | + * @return string |
|
428 | + */ |
|
429 | + public function country_ID() |
|
430 | + { |
|
431 | + return $this->get('CNT_ISO'); |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + /** |
|
436 | + * Gets country set for this attendee |
|
437 | + * |
|
438 | + * @return EE_Country |
|
439 | + */ |
|
440 | + public function country_obj() |
|
441 | + { |
|
442 | + return $this->get_first_related('Country'); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * Returns the country's name if known, otherwise 'Unknown' |
|
448 | + * |
|
449 | + * @return string |
|
450 | + */ |
|
451 | + public function country_name() |
|
452 | + { |
|
453 | + if ($this->country_obj()) { |
|
454 | + return $this->country_obj()->name(); |
|
455 | + } else { |
|
456 | + return ''; |
|
457 | + } |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * either displays the country ISO2 code or the country name, as determined |
|
463 | + * by the "FHEE__EEI_Address__country__use_abbreviation" filter. |
|
464 | + * defaults to abbreviation |
|
465 | + * |
|
466 | + * @return string |
|
467 | + */ |
|
468 | + public function country() |
|
469 | + { |
|
470 | + if (apply_filters('FHEE__EEI_Address__country__use_abbreviation', true, $this->country_obj())) { |
|
471 | + return $this->country_ID(); |
|
472 | + } else { |
|
473 | + return $this->country_name(); |
|
474 | + } |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * get Attendee Zip/Postal Code |
|
480 | + * |
|
481 | + * @return string |
|
482 | + */ |
|
483 | + public function zip() |
|
484 | + { |
|
485 | + return $this->get('ATT_zip'); |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * get Attendee Email Address |
|
491 | + * |
|
492 | + * @return string |
|
493 | + */ |
|
494 | + public function email() |
|
495 | + { |
|
496 | + return $this->get('ATT_email'); |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * get Attendee Phone # |
|
502 | + * |
|
503 | + * @return string |
|
504 | + */ |
|
505 | + public function phone() |
|
506 | + { |
|
507 | + return $this->get('ATT_phone'); |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * get deleted |
|
513 | + * |
|
514 | + * @return bool |
|
515 | + */ |
|
516 | + public function deleted() |
|
517 | + { |
|
518 | + return $this->get('ATT_deleted'); |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * Gets registrations of this attendee |
|
524 | + * |
|
525 | + * @param array $query_params |
|
526 | + * @return EE_Registration[] |
|
527 | + */ |
|
528 | + public function get_registrations($query_params = array()) |
|
529 | + { |
|
530 | + return $this->get_many_related('Registration', $query_params); |
|
531 | + } |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * Gets the most recent registration of this attendee |
|
536 | + * |
|
537 | + * @return EE_Registration |
|
538 | + */ |
|
539 | + public function get_most_recent_registration() |
|
540 | + { |
|
541 | + return $this->get_first_related('Registration', |
|
542 | + array('order_by' => array('REG_date' => 'DESC'))); //null, 'REG_date', 'DESC', '=', 'OBJECT_K'); |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * Gets the most recent registration for this attend at this event |
|
548 | + * |
|
549 | + * @param int $event_id |
|
550 | + * @return EE_Registration |
|
551 | + */ |
|
552 | + public function get_most_recent_registration_for_event($event_id) |
|
553 | + { |
|
554 | + return $this->get_first_related('Registration', |
|
555 | + array(array('EVT_ID' => $event_id), 'order_by' => array('REG_date' => 'DESC')));//, '=', 'OBJECT_K' ); |
|
556 | + } |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * returns any events attached to this attendee ($_Event property); |
|
561 | + * |
|
562 | + * @return array |
|
563 | + */ |
|
564 | + public function events() |
|
565 | + { |
|
566 | + return $this->get_many_related('Event'); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * Gets the billing info array where keys match espresso_reg_page_billing_inputs(), |
|
572 | + * and keys are their cleaned values. @see EE_Attendee::save_and_clean_billing_info_for_payment_method() which was |
|
573 | + * used to save the billing info |
|
574 | + * |
|
575 | + * @param EE_Payment_Method $payment_method the _gateway_name property on the gateway class |
|
576 | + * @return EE_Form_Section_Proper|null |
|
577 | + */ |
|
578 | + public function billing_info_for_payment_method($payment_method) |
|
579 | + { |
|
580 | + $pm_type = $payment_method->type_obj(); |
|
581 | + if (! $pm_type instanceof EE_PMT_Base) { |
|
582 | + return null; |
|
583 | + } |
|
584 | + $billing_info = $this->get_post_meta($this->get_billing_info_postmeta_name($payment_method), true); |
|
585 | + if (! $billing_info) { |
|
586 | + return null; |
|
587 | + } |
|
588 | + $billing_form = $pm_type->billing_form(); |
|
589 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
590 | + $billing_form->receive_form_submission(array($billing_form->name() => $billing_info), false); |
|
591 | + } |
|
592 | + return $billing_form; |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + /** |
|
597 | + * Gets the postmeta key that holds this attendee's billing info for the |
|
598 | + * specified payment method |
|
599 | + * |
|
600 | + * @param EE_Payment_Method $payment_method |
|
601 | + * @return string |
|
602 | + */ |
|
603 | + public function get_billing_info_postmeta_name($payment_method) |
|
604 | + { |
|
605 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
606 | + return 'billing_info_' . $payment_method->type_obj()->system_name(); |
|
607 | + } else { |
|
608 | + return null; |
|
609 | + } |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * Saves the billing info to the attendee. @see EE_Attendee::billing_info_for_payment_method() which is used to |
|
615 | + * retrieve it |
|
616 | + * |
|
617 | + * @param EE_Billing_Attendee_Info_Form $billing_form |
|
618 | + * @param EE_Payment_Method $payment_method |
|
619 | + * @return boolean |
|
620 | + */ |
|
621 | + public function save_and_clean_billing_info_for_payment_method($billing_form, $payment_method) |
|
622 | + { |
|
623 | + if (! $billing_form instanceof EE_Billing_Attendee_Info_Form) { |
|
624 | + EE_Error::add_error(__('Cannot save billing info because there is none.', 'event_espresso')); |
|
625 | + return false; |
|
626 | + } |
|
627 | + $billing_form->clean_sensitive_data(); |
|
628 | + return update_post_meta($this->ID(), $this->get_billing_info_postmeta_name($payment_method), |
|
629 | + $billing_form->input_values(true)); |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * Return the link to the admin details for the object. |
|
635 | + * |
|
636 | + * @return string |
|
637 | + */ |
|
638 | + public function get_admin_details_link() |
|
639 | + { |
|
640 | + return $this->get_admin_edit_link(); |
|
641 | + } |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
646 | + * |
|
647 | + * @return string |
|
648 | + */ |
|
649 | + public function get_admin_edit_link() |
|
650 | + { |
|
651 | + EE_Registry::instance()->load_helper('URL'); |
|
652 | + return EEH_URL::add_query_args_and_nonce( |
|
653 | + array( |
|
654 | + 'page' => 'espresso_registrations', |
|
655 | + 'action' => 'edit_attendee', |
|
656 | + 'post' => $this->ID(), |
|
657 | + ), |
|
658 | + admin_url('admin.php') |
|
659 | + ); |
|
660 | + } |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * Returns the link to a settings page for the object. |
|
665 | + * |
|
666 | + * @return string |
|
667 | + */ |
|
668 | + public function get_admin_settings_link() |
|
669 | + { |
|
670 | + return $this->get_admin_edit_link(); |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + /** |
|
675 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
676 | + * |
|
677 | + * @return string |
|
678 | + */ |
|
679 | + public function get_admin_overview_link() |
|
680 | + { |
|
681 | + EE_Registry::instance()->load_helper('URL'); |
|
682 | + return EEH_URL::add_query_args_and_nonce( |
|
683 | + array( |
|
684 | + 'page' => 'espresso_registrations', |
|
685 | + 'action' => 'contact_list', |
|
686 | + ), |
|
687 | + admin_url('admin.php') |
|
688 | + ); |
|
689 | + } |
|
690 | 690 | |
691 | 691 | |
692 | 692 | } |
@@ -1,36 +1,36 @@ |
||
1 | 1 | <div id="admin-primary-mbox-reg-details-dv" class="admin-primary-mbox-dv"> |
2 | 2 | |
3 | - <?php do_action( 'AHEE__reg_admin_details_main_meta_box_reg_details__top', $REG_ID ); ?> |
|
3 | + <?php do_action('AHEE__reg_admin_details_main_meta_box_reg_details__top', $REG_ID); ?> |
|
4 | 4 | <?php echo $resend_registration_button; ?> |
5 | 5 | <?php echo $view_transaction_button; ?> |
6 | 6 | <br/> |
7 | 7 | |
8 | - <h3 class="admin-primary-mbox-h4 hdr-has-icon"><span class="dashicons dashicons-clipboard"></span><?php _e( 'Registration Items', 'event_espresso' );?></h3> |
|
8 | + <h3 class="admin-primary-mbox-h4 hdr-has-icon"><span class="dashicons dashicons-clipboard"></span><?php _e('Registration Items', 'event_espresso'); ?></h3> |
|
9 | 9 | |
10 | 10 | <?php echo $line_item_table; ?> |
11 | 11 | |
12 | 12 | <a id="display-additional-registration-session-info" class="display-the-hidden smaller-text" rel="additional-registration-session-info"> |
13 | - <span class="dashicons dashicons-plus-alt"></span><?php _e( 'view additional registration session details', 'event_espresso' );?> |
|
13 | + <span class="dashicons dashicons-plus-alt"></span><?php _e('view additional registration session details', 'event_espresso'); ?> |
|
14 | 14 | </a> |
15 | 15 | |
16 | 16 | <div id="additional-registration-session-info-dv" class="hidden"> |
17 | 17 | |
18 | 18 | <a id="hide-additional-registration-session-info" class="hide-the-displayed hidden smaller-text" rel="additional-registration-session-info"> |
19 | - <span class="dashicons dashicons-dismiss"></span><?php _e( 'hide additional registration session details', 'event_espresso' );?> |
|
19 | + <span class="dashicons dashicons-dismiss"></span><?php _e('hide additional registration session details', 'event_espresso'); ?> |
|
20 | 20 | </a> |
21 | 21 | <br class="clear"/> |
22 | 22 | |
23 | - <h3 class="admin-primary-mbox-h4"><?php _e( 'Registration Session Details', 'event_espresso' );?></h3> |
|
23 | + <h3 class="admin-primary-mbox-h4"><?php _e('Registration Session Details', 'event_espresso'); ?></h3> |
|
24 | 24 | |
25 | 25 | <table id="admin-primary-mbox-reg-extra-session-info-tbl" class="form-table skinny-rows"> |
26 | 26 | <tbody> |
27 | - <?php foreach ( $reg_details as $key => $reg_detail ) : ?> |
|
27 | + <?php foreach ($reg_details as $key => $reg_detail) : ?> |
|
28 | 28 | <tr> |
29 | 29 | <th> |
30 | - <label for="<?php echo $key;?>"><?php echo $reg_detail['label'];?></label> |
|
30 | + <label for="<?php echo $key; ?>"><?php echo $reg_detail['label']; ?></label> |
|
31 | 31 | </th> |
32 | 32 | <td> |
33 | - <?php echo $reg_detail['value'];?> |
|
33 | + <?php echo $reg_detail['value']; ?> |
|
34 | 34 | </td> |
35 | 35 | </tr> |
36 | 36 | <?php endforeach; // $reg_details?> |
@@ -418,7 +418,7 @@ |
||
418 | 418 | * In this case, we delete the temporary file |
419 | 419 | * |
420 | 420 | * @param JobParameters $job_parameters |
421 | - * @return boolean |
|
421 | + * @return JobStepResponse |
|
422 | 422 | */ |
423 | 423 | public function cleanup_job(JobParameters $job_parameters) |
424 | 424 | { |
@@ -174,7 +174,7 @@ |
||
174 | 174 | $job_parameters->extra_datum('query_params')); |
175 | 175 | \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
176 | 176 | $units_processed = count($csv_data); |
177 | - }else{ |
|
177 | + } else{ |
|
178 | 178 | $units_processed = 0; |
179 | 179 | } |
180 | 180 | $job_parameters->mark_processed($units_processed); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | array_diff_key( |
84 | 84 | $query_params, |
85 | 85 | array_flip( |
86 | - array( 'limit' ) |
|
86 | + array('limit') |
|
87 | 87 | ) |
88 | 88 | ) |
89 | 89 | ) |
@@ -130,11 +130,11 @@ discard block |
||
130 | 130 | ); |
131 | 131 | } |
132 | 132 | $question_query_params[0]['QST_system'] = array('NOT_IN', array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping())); |
133 | - if(apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) { |
|
133 | + if (apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) { |
|
134 | 134 | $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
135 | 135 | } |
136 | - $question_query_params['group_by'] = array( 'QST_ID' ); |
|
137 | - return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) ); |
|
136 | + $question_query_params['group_by'] = array('QST_ID'); |
|
137 | + return array_unique(\EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val); |
154 | 154 | } else { |
155 | 155 | //it's a normal where condition |
156 | - $question_where_params['Question_Group.Event.Registration.' . $key] = $val; |
|
156 | + $question_where_params['Question_Group.Event.Registration.'.$key] = $val; |
|
157 | 157 | } |
158 | 158 | } |
159 | 159 | return $question_where_params; |
@@ -171,13 +171,13 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
173 | 173 | { |
174 | - if( $job_parameters->units_processed() < $job_parameters->job_size() ) { |
|
174 | + if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
175 | 175 | $csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'), |
176 | 176 | $job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'), |
177 | 177 | $job_parameters->extra_datum('query_params')); |
178 | 178 | \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
179 | 179 | $units_processed = count($csv_data); |
180 | - }else{ |
|
180 | + } else { |
|
181 | 181 | $units_processed = 0; |
182 | 182 | } |
183 | 183 | $job_parameters->mark_processed($units_processed); |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | use EventEspressoBatchRequest\Helpers\JobStepResponse; |
18 | 18 | |
19 | 19 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
20 | - exit('No direct script access allowed'); |
|
20 | + exit('No direct script access allowed'); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | |
@@ -25,443 +25,442 @@ discard block |
||
25 | 25 | class RegistrationsReport extends JobHandlerFile |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Performs any necessary setup for starting the job. This is also a good |
|
30 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
31 | - * when continue_job will be called |
|
32 | - * |
|
33 | - * @param JobParameters $job_parameters |
|
34 | - * @throws BatchRequestException |
|
35 | - * @return JobStepResponse |
|
36 | - */ |
|
37 | - public function create_job(JobParameters $job_parameters) |
|
38 | - { |
|
39 | - $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
40 | - if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
41 | - throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
42 | - } |
|
43 | - $filepath = $this->create_file_from_job_with_name($job_parameters->job_id(), |
|
44 | - $this->get_filename($event_id)); |
|
45 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
46 | - if ($job_parameters->request_datum('use_filters', false)) { |
|
47 | - $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
48 | - } else { |
|
49 | - $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
50 | - array( |
|
51 | - 'OR' => array( |
|
52 | - //don't include registrations from failed or abandoned transactions... |
|
53 | - 'Transaction.STS_ID' => array( |
|
54 | - 'NOT IN', |
|
55 | - array( |
|
56 | - \EEM_Transaction::failed_status_code, |
|
57 | - \EEM_Transaction::abandoned_status_code, |
|
58 | - ), |
|
59 | - ), |
|
60 | - //unless the registration is approved, in which case include it regardless of transaction status |
|
61 | - 'STS_ID' => \EEM_Registration::status_id_approved, |
|
62 | - ), |
|
63 | - 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
64 | - ), |
|
65 | - 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
66 | - 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
67 | - 'caps' => \EEM_Base::caps_read_admin, |
|
68 | - ), $event_id); |
|
69 | - if ($event_id) { |
|
70 | - $query_params[0]['EVT_ID'] = $event_id; |
|
71 | - } else { |
|
72 | - $query_params['force_join'][] = 'Event'; |
|
73 | - } |
|
74 | - } |
|
75 | - if ( ! isset($query_params['force_join'])) { |
|
76 | - $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
77 | - } |
|
78 | - $job_parameters->add_extra_data('query_params', $query_params); |
|
79 | - $question_labels = $this->_get_question_labels($query_params); |
|
80 | - $job_parameters->add_extra_data('question_labels', $question_labels); |
|
81 | - $job_parameters->set_job_size( |
|
82 | - \EEM_Registration::instance()->count( |
|
83 | - array_diff_key( |
|
84 | - $query_params, |
|
85 | - array_flip( |
|
86 | - array( 'limit' ) |
|
87 | - ) |
|
88 | - ) |
|
89 | - ) |
|
90 | - ); |
|
91 | - //we should also set the header columns |
|
92 | - $csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $job_parameters->extra_datum('question_labels'), |
|
93 | - $job_parameters->extra_datum('query_params')); |
|
94 | - \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
95 | - //if we actually processed a row there, record it |
|
96 | - if ($job_parameters->job_size()) { |
|
97 | - $job_parameters->mark_processed(1); |
|
98 | - } |
|
99 | - return new JobStepResponse($job_parameters, |
|
100 | - __('Registrations report started successfully...', 'event_espresso')); |
|
101 | - } |
|
28 | + /** |
|
29 | + * Performs any necessary setup for starting the job. This is also a good |
|
30 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
31 | + * when continue_job will be called |
|
32 | + * |
|
33 | + * @param JobParameters $job_parameters |
|
34 | + * @throws BatchRequestException |
|
35 | + * @return JobStepResponse |
|
36 | + */ |
|
37 | + public function create_job(JobParameters $job_parameters) |
|
38 | + { |
|
39 | + $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
40 | + if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
41 | + throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
42 | + } |
|
43 | + $filepath = $this->create_file_from_job_with_name($job_parameters->job_id(), |
|
44 | + $this->get_filename($event_id)); |
|
45 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
46 | + if ($job_parameters->request_datum('use_filters', false)) { |
|
47 | + $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
48 | + } else { |
|
49 | + $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
50 | + array( |
|
51 | + 'OR' => array( |
|
52 | + //don't include registrations from failed or abandoned transactions... |
|
53 | + 'Transaction.STS_ID' => array( |
|
54 | + 'NOT IN', |
|
55 | + array( |
|
56 | + \EEM_Transaction::failed_status_code, |
|
57 | + \EEM_Transaction::abandoned_status_code, |
|
58 | + ), |
|
59 | + ), |
|
60 | + //unless the registration is approved, in which case include it regardless of transaction status |
|
61 | + 'STS_ID' => \EEM_Registration::status_id_approved, |
|
62 | + ), |
|
63 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
64 | + ), |
|
65 | + 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
66 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
67 | + 'caps' => \EEM_Base::caps_read_admin, |
|
68 | + ), $event_id); |
|
69 | + if ($event_id) { |
|
70 | + $query_params[0]['EVT_ID'] = $event_id; |
|
71 | + } else { |
|
72 | + $query_params['force_join'][] = 'Event'; |
|
73 | + } |
|
74 | + } |
|
75 | + if ( ! isset($query_params['force_join'])) { |
|
76 | + $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
77 | + } |
|
78 | + $job_parameters->add_extra_data('query_params', $query_params); |
|
79 | + $question_labels = $this->_get_question_labels($query_params); |
|
80 | + $job_parameters->add_extra_data('question_labels', $question_labels); |
|
81 | + $job_parameters->set_job_size( |
|
82 | + \EEM_Registration::instance()->count( |
|
83 | + array_diff_key( |
|
84 | + $query_params, |
|
85 | + array_flip( |
|
86 | + array( 'limit' ) |
|
87 | + ) |
|
88 | + ) |
|
89 | + ) |
|
90 | + ); |
|
91 | + //we should also set the header columns |
|
92 | + $csv_data_for_row = $this->get_csv_data_for($event_id, 0, 1, $job_parameters->extra_datum('question_labels'), |
|
93 | + $job_parameters->extra_datum('query_params')); |
|
94 | + \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
95 | + //if we actually processed a row there, record it |
|
96 | + if ($job_parameters->job_size()) { |
|
97 | + $job_parameters->mark_processed(1); |
|
98 | + } |
|
99 | + return new JobStepResponse($job_parameters, |
|
100 | + __('Registrations report started successfully...', 'event_espresso')); |
|
101 | + } |
|
102 | 102 | |
103 | 103 | |
104 | 104 | |
105 | - /** |
|
106 | - * Gets the filename |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - protected function get_filename() |
|
110 | - { |
|
111 | - return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql'))); |
|
112 | - } |
|
105 | + /** |
|
106 | + * Gets the filename |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + protected function get_filename() |
|
110 | + { |
|
111 | + return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql'))); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * Gets the questions which are to be used for this report, so they |
|
118 | - * can be remembered for later |
|
119 | - * |
|
120 | - * @param array $registration_query_params |
|
121 | - * @return array question admin labels to be used for this report |
|
122 | - */ |
|
123 | - protected function _get_question_labels($registration_query_params) |
|
124 | - { |
|
125 | - $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
126 | - $question_query_params = array(); |
|
127 | - if ($where !== null) { |
|
128 | - $question_query_params = array( |
|
129 | - $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
130 | - ); |
|
131 | - } |
|
132 | - $question_query_params[0]['QST_system'] = array('NOT_IN', array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping())); |
|
133 | - if(apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) { |
|
134 | - $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
135 | - } |
|
136 | - $question_query_params['group_by'] = array( 'QST_ID' ); |
|
137 | - return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) ); |
|
138 | - } |
|
116 | + /** |
|
117 | + * Gets the questions which are to be used for this report, so they |
|
118 | + * can be remembered for later |
|
119 | + * |
|
120 | + * @param array $registration_query_params |
|
121 | + * @return array question admin labels to be used for this report |
|
122 | + */ |
|
123 | + protected function _get_question_labels($registration_query_params) |
|
124 | + { |
|
125 | + $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
126 | + $question_query_params = array(); |
|
127 | + if ($where !== null) { |
|
128 | + $question_query_params = array( |
|
129 | + $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
130 | + ); |
|
131 | + } |
|
132 | + $question_query_params[0]['QST_system'] = array('NOT_IN', array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping())); |
|
133 | + if(apply_filters('FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', false, $registration_query_params)) { |
|
134 | + $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
135 | + } |
|
136 | + $question_query_params['group_by'] = array( 'QST_ID' ); |
|
137 | + return array_unique( \EEM_Question::instance()->get_col( $question_query_params, 'QST_admin_label' ) ); |
|
138 | + } |
|
139 | 139 | |
140 | 140 | |
141 | 141 | |
142 | - /** |
|
143 | - * Takes where params meant for registrations and changes them to work for questions |
|
144 | - * |
|
145 | - * @param array $reg_where_params |
|
146 | - * @return array |
|
147 | - */ |
|
148 | - protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
149 | - { |
|
150 | - $question_where_params = array(); |
|
151 | - foreach ($reg_where_params as $key => $val) { |
|
152 | - if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
153 | - $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val); |
|
154 | - } else { |
|
155 | - //it's a normal where condition |
|
156 | - $question_where_params['Question_Group.Event.Registration.' . $key] = $val; |
|
157 | - } |
|
158 | - } |
|
159 | - return $question_where_params; |
|
160 | - } |
|
142 | + /** |
|
143 | + * Takes where params meant for registrations and changes them to work for questions |
|
144 | + * |
|
145 | + * @param array $reg_where_params |
|
146 | + * @return array |
|
147 | + */ |
|
148 | + protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
149 | + { |
|
150 | + $question_where_params = array(); |
|
151 | + foreach ($reg_where_params as $key => $val) { |
|
152 | + if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
153 | + $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val); |
|
154 | + } else { |
|
155 | + //it's a normal where condition |
|
156 | + $question_where_params['Question_Group.Event.Registration.' . $key] = $val; |
|
157 | + } |
|
158 | + } |
|
159 | + return $question_where_params; |
|
160 | + } |
|
161 | 161 | |
162 | 162 | |
163 | 163 | |
164 | - /** |
|
165 | - * Performs another step of the job |
|
166 | - * |
|
167 | - * @param JobParameters $job_parameters |
|
168 | - * @param int $batch_size |
|
169 | - * @return JobStepResponse |
|
170 | - * @throws \EE_Error |
|
171 | - */ |
|
172 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
173 | - { |
|
174 | - if( $job_parameters->units_processed() < $job_parameters->job_size() ) { |
|
175 | - $csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'), |
|
176 | - $job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'), |
|
177 | - $job_parameters->extra_datum('query_params')); |
|
178 | - \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
179 | - $units_processed = count($csv_data); |
|
180 | - }else{ |
|
181 | - $units_processed = 0; |
|
182 | - } |
|
183 | - $job_parameters->mark_processed($units_processed); |
|
184 | - $extra_response_data = array( |
|
185 | - 'file_url' => '', |
|
186 | - ); |
|
187 | - if ($units_processed < $batch_size) { |
|
188 | - $job_parameters->set_status(JobParameters::status_complete); |
|
189 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
190 | - } |
|
164 | + /** |
|
165 | + * Performs another step of the job |
|
166 | + * |
|
167 | + * @param JobParameters $job_parameters |
|
168 | + * @param int $batch_size |
|
169 | + * @return JobStepResponse |
|
170 | + * @throws \EE_Error |
|
171 | + */ |
|
172 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
173 | + { |
|
174 | + if( $job_parameters->units_processed() < $job_parameters->job_size() ) { |
|
175 | + $csv_data = $this->get_csv_data_for($job_parameters->request_datum('EVT_ID', '0'), |
|
176 | + $job_parameters->units_processed(), $batch_size, $job_parameters->extra_datum('question_labels'), |
|
177 | + $job_parameters->extra_datum('query_params')); |
|
178 | + \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
179 | + $units_processed = count($csv_data); |
|
180 | + }else{ |
|
181 | + $units_processed = 0; |
|
182 | + } |
|
183 | + $job_parameters->mark_processed($units_processed); |
|
184 | + $extra_response_data = array( |
|
185 | + 'file_url' => '', |
|
186 | + ); |
|
187 | + if ($units_processed < $batch_size) { |
|
188 | + $job_parameters->set_status(JobParameters::status_complete); |
|
189 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
190 | + } |
|
191 | 191 | |
192 | - return new JobStepResponse($job_parameters, |
|
193 | - sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count($csv_data)), |
|
194 | - $extra_response_data); |
|
195 | - } |
|
192 | + return new JobStepResponse($job_parameters, |
|
193 | + sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count($csv_data)), |
|
194 | + $extra_response_data); |
|
195 | + } |
|
196 | 196 | |
197 | 197 | |
198 | 198 | |
199 | - /** |
|
200 | - * Gets the csv data for a batch of registrations |
|
201 | - |
|
202 | - * |
|
199 | + /** |
|
200 | + * Gets the csv data for a batch of registrations |
|
201 | + * |
|
203 | 202 | *@param int|null $event_id |
204 | - * @param int $offset |
|
205 | - * @param int $limit |
|
206 | - * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
207 | - * @param array $query_params for using where querying the model |
|
208 | - * @return array top-level keys are numeric, next-level keys are column headers |
|
209 | - */ |
|
210 | - function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
211 | - { |
|
212 | - $reg_fields_to_include = array( |
|
213 | - 'TXN_ID', |
|
214 | - 'ATT_ID', |
|
215 | - 'REG_ID', |
|
216 | - 'REG_date', |
|
217 | - 'REG_code', |
|
218 | - 'REG_count', |
|
219 | - 'REG_final_price', |
|
220 | - ); |
|
221 | - $att_fields_to_include = array( |
|
222 | - 'ATT_fname', |
|
223 | - 'ATT_lname', |
|
224 | - 'ATT_email', |
|
225 | - 'ATT_address', |
|
226 | - 'ATT_address2', |
|
227 | - 'ATT_city', |
|
228 | - 'STA_ID', |
|
229 | - 'CNT_ISO', |
|
230 | - 'ATT_zip', |
|
231 | - 'ATT_phone', |
|
232 | - ); |
|
233 | - $registrations_csv_ready_array = array(); |
|
234 | - $reg_model = \EE_Registry::instance()->load_model('Registration'); |
|
235 | - $query_params['limit'] = array($offset, $limit); |
|
236 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
237 | - $registration_ids = array(); |
|
238 | - foreach ($registration_rows as $reg_row) { |
|
239 | - $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
240 | - } |
|
241 | - foreach ($registration_rows as $reg_row) { |
|
242 | - if (is_array($reg_row)) { |
|
243 | - $reg_csv_array = array(); |
|
244 | - if ( ! $event_id) { |
|
245 | - //get the event's name and Id |
|
246 | - $reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'), |
|
247 | - \EEH_Export::prepare_value_from_db_for_display(\EEM_Event::instance(), 'EVT_name', |
|
248 | - $reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']); |
|
249 | - } |
|
250 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
251 | - /*@var $reg_row EE_Registration */ |
|
252 | - foreach ($reg_fields_to_include as $field_name) { |
|
253 | - $field = $reg_model->field_settings_for($field_name); |
|
254 | - if ($field_name == 'REG_final_price') { |
|
255 | - $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name, |
|
256 | - $reg_row['Registration.REG_final_price'], 'localized_float'); |
|
257 | - } elseif ($field_name == 'REG_count') { |
|
258 | - $value = sprintf(__('%s of %s', 'event_espresso'), |
|
259 | - \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_count', |
|
260 | - $reg_row['Registration.REG_count']), |
|
261 | - \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_group_size', |
|
262 | - $reg_row['Registration.REG_group_size'])); |
|
263 | - } elseif ($field_name == 'REG_date') { |
|
264 | - $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name, |
|
265 | - $reg_row['Registration.REG_date'], 'no_html'); |
|
266 | - } else { |
|
267 | - $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name, |
|
268 | - $reg_row[$field->get_qualified_column()]); |
|
269 | - } |
|
270 | - $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = $value; |
|
271 | - if ($field_name == 'REG_final_price') { |
|
272 | - //add a column named Currency after the final price |
|
273 | - $reg_csv_array[__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code; |
|
274 | - } |
|
275 | - } |
|
276 | - //get pretty status |
|
277 | - $stati = \EEM_Status::instance()->localized_status(array( |
|
278 | - $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
279 | - $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
280 | - ), false, 'sentence'); |
|
281 | - $reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']]; |
|
282 | - //get pretty transaction status |
|
283 | - $reg_csv_array[__("Transaction Status", |
|
284 | - 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']]; |
|
285 | - $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg |
|
286 | - ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_total', |
|
287 | - $reg_row['TransactionTable.TXN_total'], 'localized_float') : '0.00'; |
|
288 | - $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg |
|
289 | - ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_paid', |
|
290 | - $reg_row['TransactionTable.TXN_paid'], 'localized_float') : '0.00'; |
|
291 | - $payment_methods = array(); |
|
292 | - $gateway_txn_ids_etc = array(); |
|
293 | - $payment_times = array(); |
|
294 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
295 | - $payments_info = \EEM_Payment::instance()->get_all_wpdb_results(array( |
|
296 | - array( |
|
297 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
298 | - 'STS_ID' => \EEM_Payment::status_id_approved, |
|
299 | - ), |
|
300 | - 'force_join' => array('Payment_Method'), |
|
301 | - ), ARRAY_A, |
|
302 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'); |
|
303 | - foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
304 | - $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
305 | - ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
306 | - $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
307 | - ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
308 | - $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
309 | - ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
310 | - } |
|
311 | - } |
|
312 | - $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
313 | - $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
314 | - $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc); |
|
315 | - //get whether or not the user has checked in |
|
316 | - $reg_csv_array[__("Check-Ins", |
|
317 | - "event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin'); |
|
318 | - //get ticket of registration and its price |
|
319 | - $ticket_model = \EE_Registry::instance()->load_model('Ticket'); |
|
320 | - if ($reg_row['Ticket.TKT_ID']) { |
|
321 | - $ticket_name = \EEH_Export::prepare_value_from_db_for_display($ticket_model, 'TKT_name', |
|
322 | - $reg_row['Ticket.TKT_name']); |
|
323 | - $datetimes_strings = array(); |
|
324 | - foreach ( |
|
325 | - \EEM_Datetime::instance()->get_all_wpdb_results(array( |
|
326 | - array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
327 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
328 | - 'default_where_conditions' => 'none', |
|
329 | - )) as $datetime |
|
330 | - ) { |
|
331 | - $datetimes_strings[] = \EEH_Export::prepare_value_from_db_for_display(\EEM_Datetime::instance(), |
|
332 | - 'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']); |
|
333 | - } |
|
334 | - } else { |
|
335 | - $ticket_name = __('Unknown', 'event_espresso'); |
|
336 | - $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
337 | - } |
|
338 | - $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
|
339 | - $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
|
340 | - //get datetime(s) of registration |
|
341 | - //add attendee columns |
|
342 | - foreach ($att_fields_to_include as $att_field_name) { |
|
343 | - $field_obj = \EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
344 | - if ($reg_row['Attendee_CPT.ID']) { |
|
345 | - if ($att_field_name == 'STA_ID') { |
|
346 | - $value = \EEM_State::instance() |
|
347 | - ->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
348 | - 'STA_name'); |
|
349 | - } elseif ($att_field_name == 'CNT_ISO') { |
|
350 | - $value = \EEM_Country::instance() |
|
351 | - ->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
352 | - 'CNT_name'); |
|
353 | - } else { |
|
354 | - $value = \EEH_Export::prepare_value_from_db_for_display(\EEM_Attendee::instance(), |
|
355 | - $att_field_name, $reg_row[$field_obj->get_qualified_column()]); |
|
356 | - } |
|
357 | - } else { |
|
358 | - $value = ''; |
|
359 | - } |
|
360 | - $reg_csv_array[\EEH_Export::get_column_name_for_field($field_obj)] = $value; |
|
361 | - } |
|
362 | - //make sure each registration has the same questions in the same order |
|
363 | - foreach ($question_labels as $question_label) { |
|
364 | - if ( ! isset($reg_csv_array[$question_label])) { |
|
365 | - $reg_csv_array[$question_label] = null; |
|
366 | - } |
|
367 | - } |
|
368 | - $answers = \EEM_Answer::instance()->get_all_wpdb_results(array( |
|
369 | - array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
370 | - 'force_join' => array('Question'), |
|
371 | - )); |
|
372 | - //now fill out the questions THEY answered |
|
373 | - foreach ($answers as $answer_row) { |
|
374 | - if ($answer_row['Question.QST_ID']) { |
|
375 | - $question_label = \EEH_Export::prepare_value_from_db_for_display(\EEM_Question::instance(), |
|
376 | - 'QST_admin_label', $answer_row['Question.QST_admin_label']); |
|
377 | - } else { |
|
378 | - $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
379 | - } |
|
380 | - if (isset($answer_row['Question.QST_type']) |
|
381 | - && $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state |
|
382 | - ) { |
|
383 | - $reg_csv_array[$question_label] = \EEM_State::instance() |
|
384 | - ->get_state_name_by_ID($answer_row['Answer.ANS_value']); |
|
385 | - } else { |
|
386 | - //this isn't for html, so don't show html entities |
|
387 | - $reg_csv_array[$question_label] = html_entity_decode(\EEH_Export::prepare_value_from_db_for_display(\EEM_Answer::instance(), |
|
388 | - 'ANS_value', $answer_row['Answer.ANS_value'])); |
|
389 | - } |
|
390 | - } |
|
391 | - /** |
|
392 | - * Filter to change the contents of each row of the registrations report CSV file. |
|
393 | - * |
|
394 | - * This can be used to add or remote columns from the CSV file, or change their values. * |
|
395 | - * Note: it has this name because originally that's where this filter resided, |
|
396 | - * and we've left its name as-is for backward compatibility. |
|
397 | - * Note when using: all rows in the CSV should have the same columns. |
|
398 | - * |
|
399 | - * @param array $reg_csv_array keys are column-header names, and values are that columns' value |
|
400 | - * in this row |
|
401 | - * @param array $reg_row is the row from the database's wp_esp_registration table |
|
402 | - * |
|
403 | - */ |
|
404 | - $registrations_csv_ready_array[] = apply_filters( |
|
405 | - 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
406 | - $reg_csv_array, |
|
407 | - $reg_row |
|
408 | - ); |
|
409 | - } |
|
410 | - } |
|
411 | - //if we couldn't export anything, we want to at least show the column headers |
|
412 | - if (empty($registrations_csv_ready_array)) { |
|
413 | - $reg_csv_array = array(); |
|
414 | - $model_and_fields_to_include = array( |
|
415 | - 'Registration' => $reg_fields_to_include, |
|
416 | - 'Attendee' => $att_fields_to_include, |
|
417 | - ); |
|
418 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
419 | - $model = \EE_Registry::instance()->load_model($model_name); |
|
420 | - foreach ($field_list as $field_name) { |
|
421 | - $field = $model->field_settings_for($field_name); |
|
422 | - $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = null; |
|
423 | - } |
|
424 | - } |
|
425 | - $registrations_csv_ready_array[] = $reg_csv_array; |
|
426 | - } |
|
427 | - return $registrations_csv_ready_array; |
|
428 | - } |
|
203 | + * @param int $offset |
|
204 | + * @param int $limit |
|
205 | + * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
206 | + * @param array $query_params for using where querying the model |
|
207 | + * @return array top-level keys are numeric, next-level keys are column headers |
|
208 | + */ |
|
209 | + function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
210 | + { |
|
211 | + $reg_fields_to_include = array( |
|
212 | + 'TXN_ID', |
|
213 | + 'ATT_ID', |
|
214 | + 'REG_ID', |
|
215 | + 'REG_date', |
|
216 | + 'REG_code', |
|
217 | + 'REG_count', |
|
218 | + 'REG_final_price', |
|
219 | + ); |
|
220 | + $att_fields_to_include = array( |
|
221 | + 'ATT_fname', |
|
222 | + 'ATT_lname', |
|
223 | + 'ATT_email', |
|
224 | + 'ATT_address', |
|
225 | + 'ATT_address2', |
|
226 | + 'ATT_city', |
|
227 | + 'STA_ID', |
|
228 | + 'CNT_ISO', |
|
229 | + 'ATT_zip', |
|
230 | + 'ATT_phone', |
|
231 | + ); |
|
232 | + $registrations_csv_ready_array = array(); |
|
233 | + $reg_model = \EE_Registry::instance()->load_model('Registration'); |
|
234 | + $query_params['limit'] = array($offset, $limit); |
|
235 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
236 | + $registration_ids = array(); |
|
237 | + foreach ($registration_rows as $reg_row) { |
|
238 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
239 | + } |
|
240 | + foreach ($registration_rows as $reg_row) { |
|
241 | + if (is_array($reg_row)) { |
|
242 | + $reg_csv_array = array(); |
|
243 | + if ( ! $event_id) { |
|
244 | + //get the event's name and Id |
|
245 | + $reg_csv_array[__('Event', 'event_espresso')] = sprintf(__('%1$s (%2$s)', 'event_espresso'), |
|
246 | + \EEH_Export::prepare_value_from_db_for_display(\EEM_Event::instance(), 'EVT_name', |
|
247 | + $reg_row['Event_CPT.post_title']), $reg_row['Event_CPT.ID']); |
|
248 | + } |
|
249 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
250 | + /*@var $reg_row EE_Registration */ |
|
251 | + foreach ($reg_fields_to_include as $field_name) { |
|
252 | + $field = $reg_model->field_settings_for($field_name); |
|
253 | + if ($field_name == 'REG_final_price') { |
|
254 | + $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name, |
|
255 | + $reg_row['Registration.REG_final_price'], 'localized_float'); |
|
256 | + } elseif ($field_name == 'REG_count') { |
|
257 | + $value = sprintf(__('%s of %s', 'event_espresso'), |
|
258 | + \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_count', |
|
259 | + $reg_row['Registration.REG_count']), |
|
260 | + \EEH_Export::prepare_value_from_db_for_display($reg_model, 'REG_group_size', |
|
261 | + $reg_row['Registration.REG_group_size'])); |
|
262 | + } elseif ($field_name == 'REG_date') { |
|
263 | + $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name, |
|
264 | + $reg_row['Registration.REG_date'], 'no_html'); |
|
265 | + } else { |
|
266 | + $value = \EEH_Export::prepare_value_from_db_for_display($reg_model, $field_name, |
|
267 | + $reg_row[$field->get_qualified_column()]); |
|
268 | + } |
|
269 | + $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = $value; |
|
270 | + if ($field_name == 'REG_final_price') { |
|
271 | + //add a column named Currency after the final price |
|
272 | + $reg_csv_array[__("Currency", "event_espresso")] = \EE_Config::instance()->currency->code; |
|
273 | + } |
|
274 | + } |
|
275 | + //get pretty status |
|
276 | + $stati = \EEM_Status::instance()->localized_status(array( |
|
277 | + $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
278 | + $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
279 | + ), false, 'sentence'); |
|
280 | + $reg_csv_array[__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']]; |
|
281 | + //get pretty transaction status |
|
282 | + $reg_csv_array[__("Transaction Status", |
|
283 | + 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']]; |
|
284 | + $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg |
|
285 | + ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_total', |
|
286 | + $reg_row['TransactionTable.TXN_total'], 'localized_float') : '0.00'; |
|
287 | + $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg |
|
288 | + ? \EEH_Export::prepare_value_from_db_for_display(\EEM_Transaction::instance(), 'TXN_paid', |
|
289 | + $reg_row['TransactionTable.TXN_paid'], 'localized_float') : '0.00'; |
|
290 | + $payment_methods = array(); |
|
291 | + $gateway_txn_ids_etc = array(); |
|
292 | + $payment_times = array(); |
|
293 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
294 | + $payments_info = \EEM_Payment::instance()->get_all_wpdb_results(array( |
|
295 | + array( |
|
296 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
297 | + 'STS_ID' => \EEM_Payment::status_id_approved, |
|
298 | + ), |
|
299 | + 'force_join' => array('Payment_Method'), |
|
300 | + ), ARRAY_A, |
|
301 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time'); |
|
302 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
303 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
304 | + ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
305 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
306 | + ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
307 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
308 | + ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
309 | + } |
|
310 | + } |
|
311 | + $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
312 | + $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
313 | + $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode(',', $gateway_txn_ids_etc); |
|
314 | + //get whether or not the user has checked in |
|
315 | + $reg_csv_array[__("Check-Ins", |
|
316 | + "event_espresso")] = $reg_model->count_related($reg_row['Registration.REG_ID'], 'Checkin'); |
|
317 | + //get ticket of registration and its price |
|
318 | + $ticket_model = \EE_Registry::instance()->load_model('Ticket'); |
|
319 | + if ($reg_row['Ticket.TKT_ID']) { |
|
320 | + $ticket_name = \EEH_Export::prepare_value_from_db_for_display($ticket_model, 'TKT_name', |
|
321 | + $reg_row['Ticket.TKT_name']); |
|
322 | + $datetimes_strings = array(); |
|
323 | + foreach ( |
|
324 | + \EEM_Datetime::instance()->get_all_wpdb_results(array( |
|
325 | + array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
326 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
327 | + 'default_where_conditions' => 'none', |
|
328 | + )) as $datetime |
|
329 | + ) { |
|
330 | + $datetimes_strings[] = \EEH_Export::prepare_value_from_db_for_display(\EEM_Datetime::instance(), |
|
331 | + 'DTT_EVT_start', $datetime['Datetime.DTT_EVT_start']); |
|
332 | + } |
|
333 | + } else { |
|
334 | + $ticket_name = __('Unknown', 'event_espresso'); |
|
335 | + $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
336 | + } |
|
337 | + $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
|
338 | + $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
|
339 | + //get datetime(s) of registration |
|
340 | + //add attendee columns |
|
341 | + foreach ($att_fields_to_include as $att_field_name) { |
|
342 | + $field_obj = \EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
343 | + if ($reg_row['Attendee_CPT.ID']) { |
|
344 | + if ($att_field_name == 'STA_ID') { |
|
345 | + $value = \EEM_State::instance() |
|
346 | + ->get_var(array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
347 | + 'STA_name'); |
|
348 | + } elseif ($att_field_name == 'CNT_ISO') { |
|
349 | + $value = \EEM_Country::instance() |
|
350 | + ->get_var(array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
351 | + 'CNT_name'); |
|
352 | + } else { |
|
353 | + $value = \EEH_Export::prepare_value_from_db_for_display(\EEM_Attendee::instance(), |
|
354 | + $att_field_name, $reg_row[$field_obj->get_qualified_column()]); |
|
355 | + } |
|
356 | + } else { |
|
357 | + $value = ''; |
|
358 | + } |
|
359 | + $reg_csv_array[\EEH_Export::get_column_name_for_field($field_obj)] = $value; |
|
360 | + } |
|
361 | + //make sure each registration has the same questions in the same order |
|
362 | + foreach ($question_labels as $question_label) { |
|
363 | + if ( ! isset($reg_csv_array[$question_label])) { |
|
364 | + $reg_csv_array[$question_label] = null; |
|
365 | + } |
|
366 | + } |
|
367 | + $answers = \EEM_Answer::instance()->get_all_wpdb_results(array( |
|
368 | + array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
369 | + 'force_join' => array('Question'), |
|
370 | + )); |
|
371 | + //now fill out the questions THEY answered |
|
372 | + foreach ($answers as $answer_row) { |
|
373 | + if ($answer_row['Question.QST_ID']) { |
|
374 | + $question_label = \EEH_Export::prepare_value_from_db_for_display(\EEM_Question::instance(), |
|
375 | + 'QST_admin_label', $answer_row['Question.QST_admin_label']); |
|
376 | + } else { |
|
377 | + $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
378 | + } |
|
379 | + if (isset($answer_row['Question.QST_type']) |
|
380 | + && $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state |
|
381 | + ) { |
|
382 | + $reg_csv_array[$question_label] = \EEM_State::instance() |
|
383 | + ->get_state_name_by_ID($answer_row['Answer.ANS_value']); |
|
384 | + } else { |
|
385 | + //this isn't for html, so don't show html entities |
|
386 | + $reg_csv_array[$question_label] = html_entity_decode(\EEH_Export::prepare_value_from_db_for_display(\EEM_Answer::instance(), |
|
387 | + 'ANS_value', $answer_row['Answer.ANS_value'])); |
|
388 | + } |
|
389 | + } |
|
390 | + /** |
|
391 | + * Filter to change the contents of each row of the registrations report CSV file. |
|
392 | + * |
|
393 | + * This can be used to add or remote columns from the CSV file, or change their values. * |
|
394 | + * Note: it has this name because originally that's where this filter resided, |
|
395 | + * and we've left its name as-is for backward compatibility. |
|
396 | + * Note when using: all rows in the CSV should have the same columns. |
|
397 | + * |
|
398 | + * @param array $reg_csv_array keys are column-header names, and values are that columns' value |
|
399 | + * in this row |
|
400 | + * @param array $reg_row is the row from the database's wp_esp_registration table |
|
401 | + * |
|
402 | + */ |
|
403 | + $registrations_csv_ready_array[] = apply_filters( |
|
404 | + 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
405 | + $reg_csv_array, |
|
406 | + $reg_row |
|
407 | + ); |
|
408 | + } |
|
409 | + } |
|
410 | + //if we couldn't export anything, we want to at least show the column headers |
|
411 | + if (empty($registrations_csv_ready_array)) { |
|
412 | + $reg_csv_array = array(); |
|
413 | + $model_and_fields_to_include = array( |
|
414 | + 'Registration' => $reg_fields_to_include, |
|
415 | + 'Attendee' => $att_fields_to_include, |
|
416 | + ); |
|
417 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
418 | + $model = \EE_Registry::instance()->load_model($model_name); |
|
419 | + foreach ($field_list as $field_name) { |
|
420 | + $field = $model->field_settings_for($field_name); |
|
421 | + $reg_csv_array[\EEH_Export::get_column_name_for_field($field)] = null; |
|
422 | + } |
|
423 | + } |
|
424 | + $registrations_csv_ready_array[] = $reg_csv_array; |
|
425 | + } |
|
426 | + return $registrations_csv_ready_array; |
|
427 | + } |
|
429 | 428 | |
430 | 429 | |
431 | 430 | |
432 | - /** |
|
433 | - * Counts total unit to process |
|
434 | - * |
|
435 | - * @deprecated since 4.9.19 |
|
436 | - * @param int|array $event_id |
|
437 | - * @return int |
|
438 | - */ |
|
439 | - public function count_units_to_process($event_id) |
|
440 | - { |
|
441 | - //use the legacy filter |
|
442 | - if ($event_id) { |
|
443 | - $query_params[0]['EVT_ID'] = $event_id; |
|
444 | - } else { |
|
445 | - $query_params['force_join'][] = 'Event'; |
|
446 | - } |
|
447 | - return \EEM_Registration::instance()->count($query_params); |
|
448 | - } |
|
431 | + /** |
|
432 | + * Counts total unit to process |
|
433 | + * |
|
434 | + * @deprecated since 4.9.19 |
|
435 | + * @param int|array $event_id |
|
436 | + * @return int |
|
437 | + */ |
|
438 | + public function count_units_to_process($event_id) |
|
439 | + { |
|
440 | + //use the legacy filter |
|
441 | + if ($event_id) { |
|
442 | + $query_params[0]['EVT_ID'] = $event_id; |
|
443 | + } else { |
|
444 | + $query_params['force_join'][] = 'Event'; |
|
445 | + } |
|
446 | + return \EEM_Registration::instance()->count($query_params); |
|
447 | + } |
|
449 | 448 | |
450 | 449 | |
451 | 450 | |
452 | - /** |
|
453 | - * Performs any clean-up logic when we know the job is completed. |
|
454 | - * In this case, we delete the temporary file |
|
455 | - * |
|
456 | - * @param JobParameters $job_parameters |
|
457 | - * @return boolean |
|
458 | - */ |
|
459 | - public function cleanup_job(JobParameters $job_parameters) |
|
460 | - { |
|
461 | - $this->_file_helper->delete(\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
462 | - true, 'd'); |
|
463 | - return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
464 | - } |
|
451 | + /** |
|
452 | + * Performs any clean-up logic when we know the job is completed. |
|
453 | + * In this case, we delete the temporary file |
|
454 | + * |
|
455 | + * @param JobParameters $job_parameters |
|
456 | + * @return boolean |
|
457 | + */ |
|
458 | + public function cleanup_job(JobParameters $job_parameters) |
|
459 | + { |
|
460 | + $this->_file_helper->delete(\EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
461 | + true, 'd'); |
|
462 | + return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
463 | + } |
|
465 | 464 | } |
466 | 465 | |
467 | 466 |
@@ -227,7 +227,7 @@ |
||
227 | 227 | * _get_table_filters |
228 | 228 | * |
229 | 229 | * @access protected |
230 | - * @return array |
|
230 | + * @return string[] |
|
231 | 231 | */ |
232 | 232 | protected function _get_table_filters() |
233 | 233 | { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | ); |
158 | 158 | $this->_primary_column = '_REG_ID'; |
159 | 159 | $this->_sortable_columns = array( |
160 | - '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
160 | + '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
161 | 161 | /** |
162 | 162 | * Allows users to change the default sort if they wish. |
163 | 163 | * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | { |
190 | 190 | $class = parent::_get_row_class($item); |
191 | 191 | //add status class |
192 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
192 | + $class .= ' ee-status-strip reg-status-'.$item->status_ID(); |
|
193 | 193 | if ($this->_has_checkbox_column) { |
194 | 194 | $class .= ' has-checkbox-column'; |
195 | 195 | } |
@@ -337,11 +337,11 @@ discard block |
||
337 | 337 | //setup date query. |
338 | 338 | $beginning_string = EEM_Registration::instance() |
339 | 339 | ->convert_datetime_for_query('REG_date', |
340 | - $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
340 | + $this_year_r.'-'.$this_month_r.'-01'.' '.$time_start, |
|
341 | 341 | 'Y-m-d H:i:s'); |
342 | 342 | $end_string = EEM_Registration::instance() |
343 | 343 | ->convert_datetime_for_query('REG_date', |
344 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
344 | + $this_year_r.'-'.$this_month_r.'-'.$days_this_month.' '.$time_end, |
|
345 | 345 | 'Y-m-d H:i:s'); |
346 | 346 | $_where['REG_date'] = array( |
347 | 347 | 'BETWEEN', |
@@ -374,9 +374,9 @@ discard block |
||
374 | 374 | 'BETWEEN', |
375 | 375 | array( |
376 | 376 | EEM_Registration::instance() |
377 | - ->convert_datetime_for_query('REG_date', $current_date . $time_start, 'Y-m-d H:i:s'), |
|
377 | + ->convert_datetime_for_query('REG_date', $current_date.$time_start, 'Y-m-d H:i:s'), |
|
378 | 378 | EEM_Registration::instance() |
379 | - ->convert_datetime_for_query('REG_date', $current_date . $time_end, 'Y-m-d H:i:s'), |
|
379 | + ->convert_datetime_for_query('REG_date', $current_date.$time_end, 'Y-m-d H:i:s'), |
|
380 | 380 | ), |
381 | 381 | ); |
382 | 382 | $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
@@ -420,8 +420,8 @@ discard block |
||
420 | 420 | $content .= '<div class="show-on-mobile-view-only">'; |
421 | 421 | $content .= '<br>'; |
422 | 422 | $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
423 | - $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
424 | - $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
423 | + $content .= ' '.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
424 | + $content .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
425 | 425 | $content .= '</div>'; |
426 | 426 | return $content; |
427 | 427 | } |
@@ -492,10 +492,10 @@ discard block |
||
492 | 492 | . $event_name |
493 | 493 | . '</a>' : $event_name; |
494 | 494 | $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
495 | - $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
495 | + $actions['event_filter'] = '<a href="'.$edit_event_url.'" title="'; |
|
496 | 496 | $actions['event_filter'] .= sprintf(esc_attr__('Filter this list to only show registrations for %s', |
497 | 497 | 'event_espresso'), $event_name); |
498 | - $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
498 | + $actions['event_filter'] .= '">'.__('View Registrations', 'event_espresso').'</a>'; |
|
499 | 499 | } else { |
500 | 500 | $edit_event = $event_name; |
501 | 501 | $actions['event_filter'] = ''; |
@@ -561,12 +561,12 @@ discard block |
||
561 | 561 | $t = $item->get_first_related('Transaction'); |
562 | 562 | $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
563 | 563 | //append group count to name |
564 | - $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
564 | + $link .= ' '.sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
565 | 565 | //append reg_code |
566 | - $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
566 | + $link .= '<br>'.sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
567 | 567 | //reg status text for accessibility |
568 | - $link .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false, |
|
569 | - 'sentence') . '</span>'; |
|
568 | + $link .= '<br><span class="ee-status-text-small">'.EEH_Template::pretty_status($item->status_ID(), false, |
|
569 | + 'sentence').'</span>'; |
|
570 | 570 | //trash/restore/delete actions |
571 | 571 | $actions = array(); |
572 | 572 | if ($this->_view !== 'trash' |
@@ -578,8 +578,8 @@ discard block |
||
578 | 578 | 'action' => 'trash_registrations', |
579 | 579 | '_REG_ID' => $item->ID(), |
580 | 580 | ), REG_ADMIN_URL); |
581 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' . esc_attr__('Trash Registration', |
|
582 | - 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
581 | + $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="'.esc_attr__('Trash Registration', |
|
582 | + 'event_espresso').'">'.__('Trash', 'event_espresso').'</a>'; |
|
583 | 583 | } elseif ($this->_view === 'trash') { |
584 | 584 | // restore registration link |
585 | 585 | if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
@@ -589,8 +589,8 @@ discard block |
||
589 | 589 | 'action' => 'restore_registrations', |
590 | 590 | '_REG_ID' => $item->ID(), |
591 | 591 | ), REG_ADMIN_URL); |
592 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' . esc_attr__('Restore Registration', |
|
593 | - 'event_espresso') . '">' . __('Restore', 'event_espresso') . '</a>'; |
|
592 | + $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="'.esc_attr__('Restore Registration', |
|
593 | + 'event_espresso').'">'.__('Restore', 'event_espresso').'</a>'; |
|
594 | 594 | } |
595 | 595 | if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
596 | 596 | 'espresso_registrations_ee_delete_registrations', $item->ID()) |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | . $ticket->name() |
659 | 659 | . '</span><br />' : ''; |
660 | 660 | if ($item->final_price() > 0) { |
661 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
661 | + $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>'; |
|
662 | 662 | } else { |
663 | 663 | // free event |
664 | 664 | $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
@@ -685,7 +685,7 @@ discard block |
||
685 | 685 | : '<span class="TKT_name">' |
686 | 686 | . $ticket->name() |
687 | 687 | . '</span><br />'; |
688 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
688 | + $content .= '<span class="reg-pad-rght">'.$item->pretty_final_price().'</span>'; |
|
689 | 689 | return $content; |
690 | 690 | } |
691 | 691 | |
@@ -703,10 +703,10 @@ discard block |
||
703 | 703 | $payment_method = $item->payment_method(); |
704 | 704 | $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
705 | 705 | : __('Unknown', 'event_espresso'); |
706 | - $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
706 | + $content = '<span class="reg-pad-rght">'.$item->pretty_paid().'</span>'; |
|
707 | 707 | if ($item->paid() > 0) { |
708 | - $content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'), |
|
709 | - $payment_method_name) . '</span>'; |
|
708 | + $content .= '<br><span class="ee-status-text-small">'.sprintf(__('...via %s', 'event_espresso'), |
|
709 | + $payment_method_name).'</span>'; |
|
710 | 710 | } |
711 | 711 | return $content; |
712 | 712 | } |
@@ -738,7 +738,7 @@ discard block |
||
738 | 738 | . esc_attr__('View Transaction', 'event_espresso') |
739 | 739 | . '">' |
740 | 740 | . $item->transaction()->pretty_total() |
741 | - . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
741 | + . '</a></span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_total().'</span>'; |
|
742 | 742 | } else { |
743 | 743 | return __("None", "event_espresso"); |
744 | 744 | } |
@@ -775,7 +775,7 @@ discard block |
||
775 | 775 | . esc_attr__('View Transaction', 'event_espresso') |
776 | 776 | . '">' |
777 | 777 | . $item->transaction()->pretty_paid() |
778 | - . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
778 | + . '</a><span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>'; |
|
779 | 779 | } |
780 | 780 | } |
781 | 781 | return ' '; |
@@ -815,7 +815,7 @@ discard block |
||
815 | 815 | $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
816 | 816 | 'espresso_registrations_view_registration', $item->ID()) ? ' |
817 | 817 | <li> |
818 | - <a href="' . $view_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
|
818 | + <a href="' . $view_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'" class="tiny-text"> |
|
819 | 819 | <div class="dashicons dashicons-clipboard"></div> |
820 | 820 | </a> |
821 | 821 | </li>' : ''; |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | 'espresso_registrations_edit_attendee') |
824 | 824 | && $attendee instanceof EE_Attendee ? ' |
825 | 825 | <li> |
826 | - <a href="' . $edit_lnk_url . '" title="' . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
|
826 | + <a href="' . $edit_lnk_url.'" title="'.esc_attr__('Edit Contact Details', 'event_espresso').'" class="tiny-text"> |
|
827 | 827 | <div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div> |
828 | 828 | </a> |
829 | 829 | </li>' : ''; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -26,875 +26,875 @@ discard block |
||
26 | 26 | |
27 | 27 | |
28 | 28 | |
29 | - private $_status; |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * An array of transaction details for the related transaction to the registration being processed. |
|
35 | - * This is set via the _set_related_details method. |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - protected $_transaction_details = array(); |
|
40 | - |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * An array of event details for the related event to the registration being processed. |
|
45 | - * This is set via the _set_related_details method. |
|
46 | - * |
|
47 | - * @var array |
|
48 | - */ |
|
49 | - protected $_event_details = array(); |
|
50 | - |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @param \Registrations_Admin_Page $admin_page |
|
55 | - */ |
|
56 | - public function __construct(Registrations_Admin_Page $admin_page) |
|
57 | - { |
|
58 | - if ( ! empty($_GET['event_id'])) { |
|
59 | - $extra_query_args = array(); |
|
60 | - foreach ($admin_page->get_views() as $key => $view_details) { |
|
61 | - $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']); |
|
62 | - } |
|
63 | - $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args); |
|
64 | - } |
|
65 | - parent::__construct($admin_page); |
|
66 | - $this->_status = $this->_admin_page->get_registration_status_array(); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * _setup_data |
|
73 | - * |
|
74 | - * @access protected |
|
75 | - * @return void |
|
76 | - */ |
|
77 | - protected function _setup_data() |
|
78 | - { |
|
79 | - $this->_data = $this->_admin_page->get_registrations($this->_per_page); |
|
80 | - $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * _set_properties |
|
87 | - * |
|
88 | - * @access protected |
|
89 | - * @return void |
|
90 | - */ |
|
91 | - protected function _set_properties() |
|
92 | - { |
|
93 | - $this->_wp_list_args = array( |
|
94 | - 'singular' => __('registration', 'event_espresso'), |
|
95 | - 'plural' => __('registrations', 'event_espresso'), |
|
96 | - 'ajax' => true, |
|
97 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
98 | - ); |
|
99 | - $ID_column_name = __('ID', 'event_espresso'); |
|
100 | - $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
101 | - $ID_column_name .= __('Registrant Name', 'event_espresso'); |
|
102 | - $ID_column_name .= '</span> '; |
|
103 | - if (isset($_GET['event_id'])) { |
|
104 | - $this->_columns = array( |
|
105 | - 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
106 | - '_REG_ID' => $ID_column_name, |
|
107 | - 'ATT_fname' => __('Name', 'event_espresso'), |
|
108 | - 'ATT_email' => __('Email', 'event_espresso'), |
|
109 | - '_REG_date' => __('Reg Date', 'event_espresso'), |
|
110 | - 'PRC_amount' => __('TKT Price', 'event_espresso'), |
|
111 | - '_REG_final_price' => __('Final Price', 'event_espresso'), |
|
112 | - 'TXN_total' => __('Total Txn', 'event_espresso'), |
|
113 | - 'TXN_paid' => __('Paid', 'event_espresso'), |
|
114 | - 'actions' => __('Actions', 'event_espresso'), |
|
115 | - ); |
|
116 | - $this->_bottom_buttons = array( |
|
117 | - 'report' => array( |
|
118 | - 'route' => 'registrations_report', |
|
119 | - 'extra_request' => array( |
|
120 | - 'EVT_ID' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
121 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
122 | - ), |
|
123 | - ), |
|
124 | - ); |
|
125 | - } else { |
|
126 | - $this->_columns = array( |
|
127 | - 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
128 | - '_REG_ID' => $ID_column_name, |
|
129 | - 'ATT_fname' => __('Name', 'event_espresso'), |
|
130 | - '_REG_date' => __('TXN Date', 'event_espresso'), |
|
131 | - 'event_name' => __('Event', 'event_espresso'), |
|
132 | - 'DTT_EVT_start' => __('Event Date', 'event_espresso'), |
|
133 | - '_REG_final_price' => __('Price', 'event_espresso'), |
|
134 | - '_REG_paid' => __('Paid', 'event_espresso'), |
|
135 | - 'actions' => __('Actions', 'event_espresso'), |
|
136 | - ); |
|
137 | - $this->_bottom_buttons = array( |
|
138 | - 'report_all' => array( |
|
139 | - 'route' => 'registrations_report', |
|
140 | - 'extra_request' => array( |
|
141 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
142 | - ), |
|
143 | - ), |
|
144 | - ); |
|
145 | - } |
|
146 | - $this->_bottom_buttons['report_filtered'] = array( |
|
147 | - 'route' => 'registrations_report', |
|
148 | - 'extra_request' => array( |
|
149 | - 'use_filters' => true, |
|
150 | - 'filters' => array_diff_key($this->_req_data, array_flip(array( |
|
151 | - 'page', |
|
152 | - 'action', |
|
153 | - 'default_nonce', |
|
154 | - ))), |
|
155 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
156 | - ), |
|
157 | - ); |
|
158 | - $this->_primary_column = '_REG_ID'; |
|
159 | - $this->_sortable_columns = array( |
|
160 | - '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
161 | - /** |
|
162 | - * Allows users to change the default sort if they wish. |
|
163 | - * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
164 | - */ |
|
165 | - 'ATT_fname' => array( |
|
166 | - 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
167 | - true, |
|
168 | - $this |
|
169 | - ) |
|
170 | - ? array('ATT_lname' => false) |
|
171 | - : array('ATT_fname' => false), |
|
172 | - 'event_name' => array('event_name' => false), |
|
173 | - 'DTT_EVT_start' => array('DTT_EVT_start' => false), |
|
174 | - '_REG_ID' => array('_REG_ID' => false), |
|
175 | - ); |
|
176 | - $this->_hidden_columns = array(); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * This simply sets up the row class for the table rows. |
|
183 | - * Allows for easier overriding of child methods for setting up sorting. |
|
184 | - * |
|
185 | - * @param EE_Registration $item the current item |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - protected function _get_row_class($item) |
|
189 | - { |
|
190 | - $class = parent::_get_row_class($item); |
|
191 | - //add status class |
|
192 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
193 | - if ($this->_has_checkbox_column) { |
|
194 | - $class .= ' has-checkbox-column'; |
|
195 | - } |
|
196 | - return $class; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Set the $_transaction_details property if not set yet. |
|
203 | - * |
|
204 | - * @param EE_Registration $registration |
|
205 | - * @throws \EE_Error |
|
206 | - */ |
|
207 | - protected function _set_related_details(EE_Registration $registration) |
|
208 | - { |
|
209 | - $transaction = $registration->get_first_related('Transaction'); |
|
210 | - $status = $transaction instanceof EE_Transaction ? $transaction->status_ID() |
|
211 | - : EEM_Transaction::failed_status_code; |
|
212 | - $this->_transaction_details = array( |
|
213 | - 'transaction' => $transaction, |
|
214 | - 'status' => $status, |
|
215 | - 'id' => $transaction instanceof EE_Transaction ? $transaction->ID() : 0, |
|
216 | - 'title_attr' => sprintf(__('View Transaction Details (%s)', 'event_espresso'), |
|
217 | - EEH_Template::pretty_status($status, false, 'sentence')), |
|
218 | - ); |
|
219 | - try { |
|
220 | - $event = $registration->event(); |
|
221 | - } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
222 | - $event = null; |
|
223 | - } |
|
224 | - $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive; |
|
225 | - $this->_event_details = array( |
|
226 | - 'event' => $event, |
|
227 | - 'status' => $status, |
|
228 | - 'id' => $event instanceof EE_Event ? $event->ID() : 0, |
|
229 | - 'title_attr' => sprintf(__('Edit Event (%s)', 'event_espresso'), |
|
230 | - EEH_Template::pretty_status($status, false, 'sentence')), |
|
231 | - ); |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * _get_table_filters |
|
238 | - * |
|
239 | - * @access protected |
|
240 | - * @return array |
|
241 | - */ |
|
242 | - protected function _get_table_filters() |
|
243 | - { |
|
244 | - $filters = array(); |
|
245 | - //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as methods. |
|
246 | - $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
247 | - $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
248 | - $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : ''; |
|
249 | - $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category); |
|
250 | - $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category); |
|
251 | - $status = array(); |
|
252 | - $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso')); |
|
253 | - foreach ($this->_status as $key => $value) { |
|
254 | - $status[] = array('id' => $key, 'text' => $value); |
|
255 | - } |
|
256 | - if ($this->_view !== 'incomplete') { |
|
257 | - $filters[] = EEH_Form_Fields::select_input('_reg_status', $status, |
|
258 | - isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status'])) |
|
259 | - : ''); |
|
260 | - } |
|
261 | - if (isset($this->_req_data['event_id'])) { |
|
262 | - $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id'); |
|
263 | - } |
|
264 | - return $filters; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * _add_view_counts |
|
271 | - * |
|
272 | - * @access protected |
|
273 | - * @return void |
|
274 | - * @throws \EE_Error |
|
275 | - */ |
|
276 | - protected function _add_view_counts() |
|
277 | - { |
|
278 | - $this->_views['all']['count'] = $this->_total_registrations(); |
|
279 | - $this->_views['month']['count'] = $this->_total_registrations_this_month(); |
|
280 | - $this->_views['today']['count'] = $this->_total_registrations_today(); |
|
281 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations', |
|
282 | - 'espresso_registrations_trash_registrations') |
|
283 | - ) { |
|
284 | - $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete'); |
|
285 | - $this->_views['trash']['count'] = $this->_total_registrations('trash'); |
|
286 | - } |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * _total_registrations |
|
293 | - * |
|
294 | - * @access protected |
|
295 | - * @param string $view |
|
296 | - * @return int |
|
297 | - * @throws \EE_Error |
|
298 | - */ |
|
299 | - protected function _total_registrations($view = '') |
|
300 | - { |
|
301 | - $_where = array(); |
|
302 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
303 | - if ($EVT_ID) { |
|
304 | - $_where['EVT_ID'] = $EVT_ID; |
|
305 | - } |
|
306 | - switch ($view) { |
|
307 | - case 'trash' : |
|
308 | - return EEM_Registration::instance()->count_deleted(array($_where)); |
|
309 | - break; |
|
310 | - case 'incomplete' : |
|
311 | - $_where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
312 | - break; |
|
313 | - default : |
|
314 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
315 | - } |
|
316 | - return EEM_Registration::instance()->count(array($_where)); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * _total_registrations_this_month |
|
323 | - * |
|
324 | - * @access protected |
|
325 | - * @return int |
|
326 | - * @throws \EE_Error |
|
327 | - */ |
|
328 | - protected function _total_registrations_this_month() |
|
329 | - { |
|
330 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
331 | - $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
332 | - $this_year_r = date('Y', current_time('timestamp')); |
|
333 | - $time_start = ' 00:00:00'; |
|
334 | - $time_end = ' 23:59:59'; |
|
335 | - $this_month_r = date('m', current_time('timestamp')); |
|
336 | - $days_this_month = date('t', current_time('timestamp')); |
|
337 | - //setup date query. |
|
338 | - $beginning_string = EEM_Registration::instance() |
|
339 | - ->convert_datetime_for_query('REG_date', |
|
340 | - $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
341 | - 'Y-m-d H:i:s'); |
|
342 | - $end_string = EEM_Registration::instance() |
|
343 | - ->convert_datetime_for_query('REG_date', |
|
344 | - $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
345 | - 'Y-m-d H:i:s'); |
|
346 | - $_where['REG_date'] = array( |
|
347 | - 'BETWEEN', |
|
348 | - array( |
|
349 | - $beginning_string, |
|
350 | - $end_string, |
|
351 | - ), |
|
352 | - ); |
|
353 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
354 | - return EEM_Registration::instance()->count(array($_where)); |
|
355 | - } |
|
356 | - |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * _total_registrations_today |
|
361 | - * |
|
362 | - * @access protected |
|
363 | - * @return int |
|
364 | - * @throws \EE_Error |
|
365 | - */ |
|
366 | - protected function _total_registrations_today() |
|
367 | - { |
|
368 | - $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
369 | - $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
370 | - $current_date = date('Y-m-d', current_time('timestamp')); |
|
371 | - $time_start = ' 00:00:00'; |
|
372 | - $time_end = ' 23:59:59'; |
|
373 | - $_where['REG_date'] = array( |
|
374 | - 'BETWEEN', |
|
375 | - array( |
|
376 | - EEM_Registration::instance() |
|
377 | - ->convert_datetime_for_query('REG_date', $current_date . $time_start, 'Y-m-d H:i:s'), |
|
378 | - EEM_Registration::instance() |
|
379 | - ->convert_datetime_for_query('REG_date', $current_date . $time_end, 'Y-m-d H:i:s'), |
|
380 | - ), |
|
381 | - ); |
|
382 | - $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
383 | - return EEM_Registration::instance()->count(array($_where)); |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * column_cb |
|
390 | - * |
|
391 | - * @access public |
|
392 | - * @param \EE_Registration $item |
|
393 | - * @return string |
|
394 | - * @throws \EE_Error |
|
395 | - */ |
|
396 | - public function column_cb($item) |
|
397 | - { |
|
398 | - /** checkbox/lock **/ |
|
399 | - $transaction = $item->get_first_related('Transaction'); |
|
400 | - $payment_count = $transaction instanceof EE_Transaction ? $transaction->count_related('Payment') : 0; |
|
401 | - return $payment_count > 0 |
|
402 | - || ! EE_Registry::instance()->CAP->current_user_can( |
|
403 | - 'ee_edit_registration', |
|
404 | - 'registration_list_table_checkbox_input', |
|
405 | - $item->ID() |
|
406 | - ) |
|
407 | - ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()) |
|
408 | - . '<span class="ee-lock-icon"></span>' |
|
409 | - : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()); |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * column__REG_ID |
|
416 | - * |
|
417 | - * @access public |
|
418 | - * @param \EE_Registration $item |
|
419 | - * @return string |
|
420 | - * @throws \EE_Error |
|
421 | - */ |
|
422 | - public function column__REG_ID(EE_Registration $item) |
|
423 | - { |
|
424 | - $attendee = $item->attendee(); |
|
425 | - $content = $item->ID(); |
|
426 | - $content .= '<div class="show-on-mobile-view-only">'; |
|
427 | - $content .= '<br>'; |
|
428 | - $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
429 | - $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
430 | - $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
431 | - $content .= '</div>'; |
|
432 | - return $content; |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * column__REG_date |
|
439 | - * |
|
440 | - * @access public |
|
441 | - * @param \EE_Registration $item |
|
442 | - * @return string |
|
443 | - * @throws \EE_Error |
|
444 | - */ |
|
445 | - public function column__REG_date(EE_Registration $item) |
|
446 | - { |
|
447 | - $this->_set_related_details($item); |
|
448 | - //Build row actions |
|
449 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
450 | - 'action' => 'view_transaction', |
|
451 | - 'TXN_ID' => $this->_transaction_details['id'], |
|
452 | - ), TXN_ADMIN_URL); |
|
453 | - $view_link = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
454 | - 'espresso_transactions_view_transaction') ? '<a class="ee-status-color-' |
|
455 | - . $this->_transaction_details['status'] |
|
456 | - . '" href="' |
|
457 | - . $view_lnk_url |
|
458 | - . '" title="' |
|
459 | - . esc_attr($this->_transaction_details['title_attr']) |
|
460 | - . '">' |
|
461 | - . $item->get_i18n_datetime('REG_date') |
|
462 | - . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
463 | - $view_link .= '<br><span class="ee-status-text-small">' |
|
464 | - . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence') |
|
465 | - . '</span>'; |
|
466 | - return $view_link; |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * column_event_name |
|
473 | - * |
|
474 | - * @access public |
|
475 | - * @param \EE_Registration $item |
|
476 | - * @return string |
|
477 | - * @throws \EE_Error |
|
478 | - */ |
|
479 | - public function column_event_name(EE_Registration $item) |
|
480 | - { |
|
481 | - $this->_set_related_details($item); |
|
482 | - // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62 |
|
483 | - $EVT_ID = $item->event_ID(); |
|
484 | - $event_name = $item->event_name(); |
|
485 | - $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso'); |
|
486 | - $event_name = wp_trim_words($event_name, 30, '...'); |
|
487 | - if ($EVT_ID) { |
|
488 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $EVT_ID), |
|
489 | - EVENTS_ADMIN_URL); |
|
490 | - $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID) |
|
491 | - ? '<a class="ee-status-color-' |
|
492 | - . $this->_event_details['status'] |
|
493 | - . '" href="' |
|
494 | - . $edit_event_url |
|
495 | - . '" title="' |
|
496 | - . esc_attr($this->_event_details['title_attr']) |
|
497 | - . '">' |
|
498 | - . $event_name |
|
499 | - . '</a>' : $event_name; |
|
500 | - $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
|
501 | - $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
502 | - $actions['event_filter'] .= sprintf(esc_attr__('Filter this list to only show registrations for %s', |
|
503 | - 'event_espresso'), $event_name); |
|
504 | - $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
505 | - } else { |
|
506 | - $edit_event = $event_name; |
|
507 | - $actions['event_filter'] = ''; |
|
508 | - } |
|
509 | - return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions)); |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * column_DTT_EVT_start |
|
516 | - * |
|
517 | - * @access public |
|
518 | - * @param \EE_Registration $item |
|
519 | - * @return string |
|
520 | - * @throws \EE_Error |
|
521 | - */ |
|
522 | - public function column_DTT_EVT_start(EE_Registration $item) |
|
523 | - { |
|
524 | - $datetime_strings = array(); |
|
525 | - $ticket = $item->ticket(true); |
|
526 | - if ($ticket instanceof EE_Ticket) { |
|
527 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
528 | - $datetimes = $ticket->datetimes($remove_defaults); |
|
529 | - foreach ($datetimes as $datetime) { |
|
530 | - $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
531 | - } |
|
532 | - return implode("<br />", $datetime_strings); |
|
533 | - } else { |
|
534 | - return __('There is no ticket on this registration', 'event_espresso'); |
|
535 | - } |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * column_ATT_fname |
|
542 | - * |
|
543 | - * @access public |
|
544 | - * @param \EE_Registration $item |
|
545 | - * @return string |
|
546 | - * @throws \EE_Error |
|
547 | - */ |
|
548 | - public function column_ATT_fname(EE_Registration $item) |
|
549 | - { |
|
550 | - $attendee = $item->attendee(); |
|
551 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
552 | - 'action' => 'view_registration', |
|
553 | - '_REG_ID' => $item->ID(), |
|
554 | - ), REG_ADMIN_URL); |
|
555 | - $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
556 | - $link = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
557 | - 'espresso_registrations_view_registration', $item->ID()) ? '<a href="' |
|
558 | - . $edit_lnk_url |
|
559 | - . '" title="' |
|
560 | - . esc_attr__('View Registration Details', |
|
561 | - 'event_espresso') |
|
562 | - . '">' |
|
563 | - . $attendee_name |
|
564 | - . '</a>' : $attendee_name; |
|
565 | - $link .= $item->count() === 1 |
|
566 | - ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : ''; |
|
567 | - $t = $item->get_first_related('Transaction'); |
|
568 | - $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
|
569 | - //append group count to name |
|
570 | - $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
571 | - //append reg_code |
|
572 | - $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
573 | - //reg status text for accessibility |
|
574 | - $link .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false, |
|
575 | - 'sentence') . '</span>'; |
|
576 | - //trash/restore/delete actions |
|
577 | - $actions = array(); |
|
578 | - if ($this->_view !== 'trash' |
|
579 | - && $payment_count === 0 |
|
580 | - && EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
|
581 | - 'espresso_registrations_trash_registrations', $item->ID()) |
|
582 | - ) { |
|
583 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
584 | - 'action' => 'trash_registrations', |
|
585 | - '_REG_ID' => $item->ID(), |
|
586 | - ), REG_ADMIN_URL); |
|
587 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' . esc_attr__('Trash Registration', |
|
588 | - 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
589 | - } elseif ($this->_view === 'trash') { |
|
590 | - // restore registration link |
|
591 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
|
592 | - 'espresso_registrations_restore_registrations', $item->ID()) |
|
593 | - ) { |
|
594 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
595 | - 'action' => 'restore_registrations', |
|
596 | - '_REG_ID' => $item->ID(), |
|
597 | - ), REG_ADMIN_URL); |
|
598 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' . esc_attr__('Restore Registration', |
|
599 | - 'event_espresso') . '">' . __('Restore', 'event_espresso') . '</a>'; |
|
600 | - } |
|
601 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
|
602 | - 'espresso_registrations_ee_delete_registrations', $item->ID()) |
|
603 | - ) { |
|
604 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
605 | - 'action' => 'delete_registrations', |
|
606 | - '_REG_ID' => $item->ID(), |
|
607 | - ), REG_ADMIN_URL); |
|
608 | - $actions['delete'] = '<a href="' |
|
609 | - . $delete_lnk_url |
|
610 | - . '" title="' |
|
611 | - . esc_attr__('Delete Registration Permanently', 'event_espresso') |
|
612 | - . '">' |
|
613 | - . __('Delete', 'event_espresso') |
|
614 | - . '</a>'; |
|
615 | - } |
|
616 | - } |
|
617 | - return sprintf('%1$s %2$s', $link, $this->row_actions($actions)); |
|
618 | - } |
|
619 | - |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * column_ATT_email |
|
624 | - * |
|
625 | - * @access public |
|
626 | - * @param \EE_Registration $item |
|
627 | - * @return string |
|
628 | - * @throws \EE_Error |
|
629 | - */ |
|
630 | - public function column_ATT_email(EE_Registration $item) |
|
631 | - { |
|
632 | - $attendee = $item->get_first_related('Attendee'); |
|
633 | - return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso') |
|
634 | - : $attendee->email(); |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * column__REG_count |
|
641 | - * |
|
642 | - * @access public |
|
643 | - * @param \EE_Registration $item |
|
644 | - * @return string |
|
645 | - */ |
|
646 | - public function column__REG_count(EE_Registration $item) |
|
647 | - { |
|
648 | - return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size()); |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - |
|
653 | - /** |
|
654 | - * column_PRC_amount |
|
655 | - * |
|
656 | - * @access public |
|
657 | - * @param \EE_Registration $item |
|
658 | - * @return string |
|
659 | - */ |
|
660 | - public function column_PRC_amount(EE_Registration $item) |
|
661 | - { |
|
662 | - $ticket = $item->ticket(); |
|
663 | - $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">' |
|
664 | - . $ticket->name() |
|
665 | - . '</span><br />' : ''; |
|
666 | - if ($item->final_price() > 0) { |
|
667 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
668 | - } else { |
|
669 | - // free event |
|
670 | - $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
|
671 | - . __('free', 'event_espresso') |
|
672 | - . '</span>'; |
|
673 | - } |
|
674 | - return $content; |
|
675 | - } |
|
676 | - |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * column__REG_final_price |
|
681 | - * |
|
682 | - * @access public |
|
683 | - * @param \EE_Registration $item |
|
684 | - * @return string |
|
685 | - */ |
|
686 | - public function column__REG_final_price(EE_Registration $item) |
|
687 | - { |
|
688 | - $ticket = $item->ticket(); |
|
689 | - $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket |
|
690 | - ? '' |
|
691 | - : '<span class="TKT_name">' |
|
692 | - . $ticket->name() |
|
693 | - . '</span><br />'; |
|
694 | - $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
695 | - return $content; |
|
696 | - } |
|
697 | - |
|
698 | - |
|
699 | - |
|
700 | - /** |
|
701 | - * column__REG_paid |
|
702 | - * |
|
703 | - * @access public |
|
704 | - * @param \EE_Registration $item |
|
705 | - * @return string |
|
706 | - */ |
|
707 | - public function column__REG_paid(EE_Registration $item) |
|
708 | - { |
|
709 | - $payment_method = $item->payment_method(); |
|
710 | - $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
|
711 | - : __('Unknown', 'event_espresso'); |
|
712 | - $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
713 | - if ($item->paid() > 0) { |
|
714 | - $content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'), |
|
715 | - $payment_method_name) . '</span>'; |
|
716 | - } |
|
717 | - return $content; |
|
718 | - } |
|
719 | - |
|
720 | - |
|
721 | - |
|
722 | - /** |
|
723 | - * column_TXN_total |
|
724 | - * |
|
725 | - * @access public |
|
726 | - * @param \EE_Registration $item |
|
727 | - * @return string |
|
728 | - * @throws \EE_Error |
|
729 | - */ |
|
730 | - public function column_TXN_total(EE_Registration $item) |
|
731 | - { |
|
732 | - if ($item->transaction()) { |
|
733 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
734 | - 'action' => 'view_transaction', |
|
735 | - 'TXN_ID' => $item->transaction_ID(), |
|
736 | - ), TXN_ADMIN_URL); |
|
737 | - return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
738 | - 'espresso_transactions_view_transaction', $item->transaction_ID()) |
|
739 | - ? '<span class="reg-pad-rght"><a class="status-' |
|
740 | - . $item->transaction()->status_ID() |
|
741 | - . '" href="' |
|
742 | - . $view_txn_lnk_url |
|
743 | - . '" title="' |
|
744 | - . esc_attr__('View Transaction', 'event_espresso') |
|
745 | - . '">' |
|
746 | - . $item->transaction()->pretty_total() |
|
747 | - . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
748 | - } else { |
|
749 | - return __("None", "event_espresso"); |
|
750 | - } |
|
751 | - } |
|
752 | - |
|
753 | - |
|
754 | - |
|
755 | - /** |
|
756 | - * column_TXN_paid |
|
757 | - * |
|
758 | - * @access public |
|
759 | - * @param \EE_Registration $item |
|
760 | - * @return string |
|
761 | - * @throws \EE_Error |
|
762 | - */ |
|
763 | - public function column_TXN_paid(EE_Registration $item) |
|
764 | - { |
|
765 | - if ($item->count() === 1) { |
|
766 | - $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance(); |
|
767 | - if ($transaction->paid() >= $transaction->total()) { |
|
768 | - return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
769 | - } else { |
|
770 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
771 | - 'action' => 'view_transaction', |
|
772 | - 'TXN_ID' => $item->transaction_ID(), |
|
773 | - ), TXN_ADMIN_URL); |
|
774 | - return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
775 | - 'espresso_transactions_view_transaction', $item->transaction_ID()) |
|
776 | - ? '<span class="reg-pad-rght"><a class="status-' |
|
777 | - . $transaction->status_ID() |
|
778 | - . '" href="' |
|
779 | - . $view_txn_lnk_url |
|
780 | - . '" title="' |
|
781 | - . esc_attr__('View Transaction', 'event_espresso') |
|
782 | - . '">' |
|
783 | - . $item->transaction()->pretty_paid() |
|
784 | - . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
785 | - } |
|
786 | - } |
|
787 | - return ' '; |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - |
|
792 | - /** |
|
793 | - * column_actions |
|
794 | - * |
|
795 | - * @access public |
|
796 | - * @param \EE_Registration $item |
|
797 | - * @return string |
|
798 | - * @throws \EE_Error |
|
799 | - */ |
|
800 | - public function column_actions(EE_Registration $item) |
|
801 | - { |
|
802 | - $actions = array(); |
|
803 | - $attendee = $item->attendee(); |
|
804 | - $this->_set_related_details($item); |
|
805 | - //Build row actions |
|
806 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
807 | - 'action' => 'view_registration', |
|
808 | - '_REG_ID' => $item->ID(), |
|
809 | - ), REG_ADMIN_URL); |
|
810 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
811 | - 'action' => 'edit_attendee', |
|
812 | - 'post' => $item->attendee_ID(), |
|
813 | - ), REG_ADMIN_URL); |
|
814 | - // page=attendees&event_admin_reports=resend_email®istration_id=43653465634&event_id=2&form_action=resend_email |
|
815 | - //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID ); |
|
816 | - $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
817 | - 'action' => 'resend_registration', |
|
818 | - '_REG_ID' => $item->ID(), |
|
819 | - ), REG_ADMIN_URL, true); |
|
820 | - //Build row actions |
|
821 | - $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
822 | - 'espresso_registrations_view_registration', $item->ID()) ? ' |
|
29 | + private $_status; |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * An array of transaction details for the related transaction to the registration being processed. |
|
35 | + * This is set via the _set_related_details method. |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + protected $_transaction_details = array(); |
|
40 | + |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * An array of event details for the related event to the registration being processed. |
|
45 | + * This is set via the _set_related_details method. |
|
46 | + * |
|
47 | + * @var array |
|
48 | + */ |
|
49 | + protected $_event_details = array(); |
|
50 | + |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @param \Registrations_Admin_Page $admin_page |
|
55 | + */ |
|
56 | + public function __construct(Registrations_Admin_Page $admin_page) |
|
57 | + { |
|
58 | + if ( ! empty($_GET['event_id'])) { |
|
59 | + $extra_query_args = array(); |
|
60 | + foreach ($admin_page->get_views() as $key => $view_details) { |
|
61 | + $extra_query_args[$view_details['slug']] = array('event_id' => $_GET['event_id']); |
|
62 | + } |
|
63 | + $this->_views = $admin_page->get_list_table_view_RLs($extra_query_args); |
|
64 | + } |
|
65 | + parent::__construct($admin_page); |
|
66 | + $this->_status = $this->_admin_page->get_registration_status_array(); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * _setup_data |
|
73 | + * |
|
74 | + * @access protected |
|
75 | + * @return void |
|
76 | + */ |
|
77 | + protected function _setup_data() |
|
78 | + { |
|
79 | + $this->_data = $this->_admin_page->get_registrations($this->_per_page); |
|
80 | + $this->_all_data_count = $this->_admin_page->get_registrations($this->_per_page, true, false, false); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * _set_properties |
|
87 | + * |
|
88 | + * @access protected |
|
89 | + * @return void |
|
90 | + */ |
|
91 | + protected function _set_properties() |
|
92 | + { |
|
93 | + $this->_wp_list_args = array( |
|
94 | + 'singular' => __('registration', 'event_espresso'), |
|
95 | + 'plural' => __('registrations', 'event_espresso'), |
|
96 | + 'ajax' => true, |
|
97 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
98 | + ); |
|
99 | + $ID_column_name = __('ID', 'event_espresso'); |
|
100 | + $ID_column_name .= ' : <span class="show-on-mobile-view-only" style="float:none">'; |
|
101 | + $ID_column_name .= __('Registrant Name', 'event_espresso'); |
|
102 | + $ID_column_name .= '</span> '; |
|
103 | + if (isset($_GET['event_id'])) { |
|
104 | + $this->_columns = array( |
|
105 | + 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
106 | + '_REG_ID' => $ID_column_name, |
|
107 | + 'ATT_fname' => __('Name', 'event_espresso'), |
|
108 | + 'ATT_email' => __('Email', 'event_espresso'), |
|
109 | + '_REG_date' => __('Reg Date', 'event_espresso'), |
|
110 | + 'PRC_amount' => __('TKT Price', 'event_espresso'), |
|
111 | + '_REG_final_price' => __('Final Price', 'event_espresso'), |
|
112 | + 'TXN_total' => __('Total Txn', 'event_espresso'), |
|
113 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
114 | + 'actions' => __('Actions', 'event_espresso'), |
|
115 | + ); |
|
116 | + $this->_bottom_buttons = array( |
|
117 | + 'report' => array( |
|
118 | + 'route' => 'registrations_report', |
|
119 | + 'extra_request' => array( |
|
120 | + 'EVT_ID' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
121 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
122 | + ), |
|
123 | + ), |
|
124 | + ); |
|
125 | + } else { |
|
126 | + $this->_columns = array( |
|
127 | + 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
128 | + '_REG_ID' => $ID_column_name, |
|
129 | + 'ATT_fname' => __('Name', 'event_espresso'), |
|
130 | + '_REG_date' => __('TXN Date', 'event_espresso'), |
|
131 | + 'event_name' => __('Event', 'event_espresso'), |
|
132 | + 'DTT_EVT_start' => __('Event Date', 'event_espresso'), |
|
133 | + '_REG_final_price' => __('Price', 'event_espresso'), |
|
134 | + '_REG_paid' => __('Paid', 'event_espresso'), |
|
135 | + 'actions' => __('Actions', 'event_espresso'), |
|
136 | + ); |
|
137 | + $this->_bottom_buttons = array( |
|
138 | + 'report_all' => array( |
|
139 | + 'route' => 'registrations_report', |
|
140 | + 'extra_request' => array( |
|
141 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
142 | + ), |
|
143 | + ), |
|
144 | + ); |
|
145 | + } |
|
146 | + $this->_bottom_buttons['report_filtered'] = array( |
|
147 | + 'route' => 'registrations_report', |
|
148 | + 'extra_request' => array( |
|
149 | + 'use_filters' => true, |
|
150 | + 'filters' => array_diff_key($this->_req_data, array_flip(array( |
|
151 | + 'page', |
|
152 | + 'action', |
|
153 | + 'default_nonce', |
|
154 | + ))), |
|
155 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
156 | + ), |
|
157 | + ); |
|
158 | + $this->_primary_column = '_REG_ID'; |
|
159 | + $this->_sortable_columns = array( |
|
160 | + '_REG_date' => array('_REG_date' => true), //true means its already sorted |
|
161 | + /** |
|
162 | + * Allows users to change the default sort if they wish. |
|
163 | + * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
164 | + */ |
|
165 | + 'ATT_fname' => array( |
|
166 | + 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
167 | + true, |
|
168 | + $this |
|
169 | + ) |
|
170 | + ? array('ATT_lname' => false) |
|
171 | + : array('ATT_fname' => false), |
|
172 | + 'event_name' => array('event_name' => false), |
|
173 | + 'DTT_EVT_start' => array('DTT_EVT_start' => false), |
|
174 | + '_REG_ID' => array('_REG_ID' => false), |
|
175 | + ); |
|
176 | + $this->_hidden_columns = array(); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * This simply sets up the row class for the table rows. |
|
183 | + * Allows for easier overriding of child methods for setting up sorting. |
|
184 | + * |
|
185 | + * @param EE_Registration $item the current item |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + protected function _get_row_class($item) |
|
189 | + { |
|
190 | + $class = parent::_get_row_class($item); |
|
191 | + //add status class |
|
192 | + $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
193 | + if ($this->_has_checkbox_column) { |
|
194 | + $class .= ' has-checkbox-column'; |
|
195 | + } |
|
196 | + return $class; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Set the $_transaction_details property if not set yet. |
|
203 | + * |
|
204 | + * @param EE_Registration $registration |
|
205 | + * @throws \EE_Error |
|
206 | + */ |
|
207 | + protected function _set_related_details(EE_Registration $registration) |
|
208 | + { |
|
209 | + $transaction = $registration->get_first_related('Transaction'); |
|
210 | + $status = $transaction instanceof EE_Transaction ? $transaction->status_ID() |
|
211 | + : EEM_Transaction::failed_status_code; |
|
212 | + $this->_transaction_details = array( |
|
213 | + 'transaction' => $transaction, |
|
214 | + 'status' => $status, |
|
215 | + 'id' => $transaction instanceof EE_Transaction ? $transaction->ID() : 0, |
|
216 | + 'title_attr' => sprintf(__('View Transaction Details (%s)', 'event_espresso'), |
|
217 | + EEH_Template::pretty_status($status, false, 'sentence')), |
|
218 | + ); |
|
219 | + try { |
|
220 | + $event = $registration->event(); |
|
221 | + } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
222 | + $event = null; |
|
223 | + } |
|
224 | + $status = $event instanceof EE_Event ? $event->get_active_status() : EE_Datetime::inactive; |
|
225 | + $this->_event_details = array( |
|
226 | + 'event' => $event, |
|
227 | + 'status' => $status, |
|
228 | + 'id' => $event instanceof EE_Event ? $event->ID() : 0, |
|
229 | + 'title_attr' => sprintf(__('Edit Event (%s)', 'event_espresso'), |
|
230 | + EEH_Template::pretty_status($status, false, 'sentence')), |
|
231 | + ); |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * _get_table_filters |
|
238 | + * |
|
239 | + * @access protected |
|
240 | + * @return array |
|
241 | + */ |
|
242 | + protected function _get_table_filters() |
|
243 | + { |
|
244 | + $filters = array(); |
|
245 | + //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as methods. |
|
246 | + $cur_date = isset($this->_req_data['month_range']) ? $this->_req_data['month_range'] : ''; |
|
247 | + $cur_category = isset($this->_req_data['EVT_CAT']) ? $this->_req_data['EVT_CAT'] : -1; |
|
248 | + $reg_status = isset($this->_req_data['_reg_status']) ? $this->_req_data['_reg_status'] : ''; |
|
249 | + $filters[] = EEH_Form_Fields::generate_registration_months_dropdown($cur_date, $reg_status, $cur_category); |
|
250 | + $filters[] = EEH_Form_Fields::generate_event_category_dropdown($cur_category); |
|
251 | + $status = array(); |
|
252 | + $status[] = array('id' => 0, 'text' => __('Select Status', 'event_espresso')); |
|
253 | + foreach ($this->_status as $key => $value) { |
|
254 | + $status[] = array('id' => $key, 'text' => $value); |
|
255 | + } |
|
256 | + if ($this->_view !== 'incomplete') { |
|
257 | + $filters[] = EEH_Form_Fields::select_input('_reg_status', $status, |
|
258 | + isset($this->_req_data['_reg_status']) ? strtoupper(sanitize_key($this->_req_data['_reg_status'])) |
|
259 | + : ''); |
|
260 | + } |
|
261 | + if (isset($this->_req_data['event_id'])) { |
|
262 | + $filters[] = EEH_Form_Fields::hidden_input('event_id', $this->_req_data['event_id'], 'reg_event_id'); |
|
263 | + } |
|
264 | + return $filters; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * _add_view_counts |
|
271 | + * |
|
272 | + * @access protected |
|
273 | + * @return void |
|
274 | + * @throws \EE_Error |
|
275 | + */ |
|
276 | + protected function _add_view_counts() |
|
277 | + { |
|
278 | + $this->_views['all']['count'] = $this->_total_registrations(); |
|
279 | + $this->_views['month']['count'] = $this->_total_registrations_this_month(); |
|
280 | + $this->_views['today']['count'] = $this->_total_registrations_today(); |
|
281 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registrations', |
|
282 | + 'espresso_registrations_trash_registrations') |
|
283 | + ) { |
|
284 | + $this->_views['incomplete']['count'] = $this->_total_registrations('incomplete'); |
|
285 | + $this->_views['trash']['count'] = $this->_total_registrations('trash'); |
|
286 | + } |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * _total_registrations |
|
293 | + * |
|
294 | + * @access protected |
|
295 | + * @param string $view |
|
296 | + * @return int |
|
297 | + * @throws \EE_Error |
|
298 | + */ |
|
299 | + protected function _total_registrations($view = '') |
|
300 | + { |
|
301 | + $_where = array(); |
|
302 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
303 | + if ($EVT_ID) { |
|
304 | + $_where['EVT_ID'] = $EVT_ID; |
|
305 | + } |
|
306 | + switch ($view) { |
|
307 | + case 'trash' : |
|
308 | + return EEM_Registration::instance()->count_deleted(array($_where)); |
|
309 | + break; |
|
310 | + case 'incomplete' : |
|
311 | + $_where['STS_ID'] = EEM_Registration::status_id_incomplete; |
|
312 | + break; |
|
313 | + default : |
|
314 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
315 | + } |
|
316 | + return EEM_Registration::instance()->count(array($_where)); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * _total_registrations_this_month |
|
323 | + * |
|
324 | + * @access protected |
|
325 | + * @return int |
|
326 | + * @throws \EE_Error |
|
327 | + */ |
|
328 | + protected function _total_registrations_this_month() |
|
329 | + { |
|
330 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
331 | + $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
332 | + $this_year_r = date('Y', current_time('timestamp')); |
|
333 | + $time_start = ' 00:00:00'; |
|
334 | + $time_end = ' 23:59:59'; |
|
335 | + $this_month_r = date('m', current_time('timestamp')); |
|
336 | + $days_this_month = date('t', current_time('timestamp')); |
|
337 | + //setup date query. |
|
338 | + $beginning_string = EEM_Registration::instance() |
|
339 | + ->convert_datetime_for_query('REG_date', |
|
340 | + $this_year_r . '-' . $this_month_r . '-01' . ' ' . $time_start, |
|
341 | + 'Y-m-d H:i:s'); |
|
342 | + $end_string = EEM_Registration::instance() |
|
343 | + ->convert_datetime_for_query('REG_date', |
|
344 | + $this_year_r . '-' . $this_month_r . '-' . $days_this_month . ' ' . $time_end, |
|
345 | + 'Y-m-d H:i:s'); |
|
346 | + $_where['REG_date'] = array( |
|
347 | + 'BETWEEN', |
|
348 | + array( |
|
349 | + $beginning_string, |
|
350 | + $end_string, |
|
351 | + ), |
|
352 | + ); |
|
353 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
354 | + return EEM_Registration::instance()->count(array($_where)); |
|
355 | + } |
|
356 | + |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * _total_registrations_today |
|
361 | + * |
|
362 | + * @access protected |
|
363 | + * @return int |
|
364 | + * @throws \EE_Error |
|
365 | + */ |
|
366 | + protected function _total_registrations_today() |
|
367 | + { |
|
368 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
369 | + $_where = $EVT_ID ? array('EVT_ID' => $EVT_ID) : array(); |
|
370 | + $current_date = date('Y-m-d', current_time('timestamp')); |
|
371 | + $time_start = ' 00:00:00'; |
|
372 | + $time_end = ' 23:59:59'; |
|
373 | + $_where['REG_date'] = array( |
|
374 | + 'BETWEEN', |
|
375 | + array( |
|
376 | + EEM_Registration::instance() |
|
377 | + ->convert_datetime_for_query('REG_date', $current_date . $time_start, 'Y-m-d H:i:s'), |
|
378 | + EEM_Registration::instance() |
|
379 | + ->convert_datetime_for_query('REG_date', $current_date . $time_end, 'Y-m-d H:i:s'), |
|
380 | + ), |
|
381 | + ); |
|
382 | + $_where['STS_ID'] = array('!=', EEM_Registration::status_id_incomplete); |
|
383 | + return EEM_Registration::instance()->count(array($_where)); |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * column_cb |
|
390 | + * |
|
391 | + * @access public |
|
392 | + * @param \EE_Registration $item |
|
393 | + * @return string |
|
394 | + * @throws \EE_Error |
|
395 | + */ |
|
396 | + public function column_cb($item) |
|
397 | + { |
|
398 | + /** checkbox/lock **/ |
|
399 | + $transaction = $item->get_first_related('Transaction'); |
|
400 | + $payment_count = $transaction instanceof EE_Transaction ? $transaction->count_related('Payment') : 0; |
|
401 | + return $payment_count > 0 |
|
402 | + || ! EE_Registry::instance()->CAP->current_user_can( |
|
403 | + 'ee_edit_registration', |
|
404 | + 'registration_list_table_checkbox_input', |
|
405 | + $item->ID() |
|
406 | + ) |
|
407 | + ? sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()) |
|
408 | + . '<span class="ee-lock-icon"></span>' |
|
409 | + : sprintf('<input type="checkbox" name="_REG_ID[]" value="%1$d" />', $item->ID()); |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * column__REG_ID |
|
416 | + * |
|
417 | + * @access public |
|
418 | + * @param \EE_Registration $item |
|
419 | + * @return string |
|
420 | + * @throws \EE_Error |
|
421 | + */ |
|
422 | + public function column__REG_ID(EE_Registration $item) |
|
423 | + { |
|
424 | + $attendee = $item->attendee(); |
|
425 | + $content = $item->ID(); |
|
426 | + $content .= '<div class="show-on-mobile-view-only">'; |
|
427 | + $content .= '<br>'; |
|
428 | + $content .= $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
429 | + $content .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
430 | + $content .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
431 | + $content .= '</div>'; |
|
432 | + return $content; |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * column__REG_date |
|
439 | + * |
|
440 | + * @access public |
|
441 | + * @param \EE_Registration $item |
|
442 | + * @return string |
|
443 | + * @throws \EE_Error |
|
444 | + */ |
|
445 | + public function column__REG_date(EE_Registration $item) |
|
446 | + { |
|
447 | + $this->_set_related_details($item); |
|
448 | + //Build row actions |
|
449 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
450 | + 'action' => 'view_transaction', |
|
451 | + 'TXN_ID' => $this->_transaction_details['id'], |
|
452 | + ), TXN_ADMIN_URL); |
|
453 | + $view_link = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
454 | + 'espresso_transactions_view_transaction') ? '<a class="ee-status-color-' |
|
455 | + . $this->_transaction_details['status'] |
|
456 | + . '" href="' |
|
457 | + . $view_lnk_url |
|
458 | + . '" title="' |
|
459 | + . esc_attr($this->_transaction_details['title_attr']) |
|
460 | + . '">' |
|
461 | + . $item->get_i18n_datetime('REG_date') |
|
462 | + . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
463 | + $view_link .= '<br><span class="ee-status-text-small">' |
|
464 | + . EEH_Template::pretty_status($this->_transaction_details['status'], false, 'sentence') |
|
465 | + . '</span>'; |
|
466 | + return $view_link; |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * column_event_name |
|
473 | + * |
|
474 | + * @access public |
|
475 | + * @param \EE_Registration $item |
|
476 | + * @return string |
|
477 | + * @throws \EE_Error |
|
478 | + */ |
|
479 | + public function column_event_name(EE_Registration $item) |
|
480 | + { |
|
481 | + $this->_set_related_details($item); |
|
482 | + // page=espresso_events&action=edit_event&EVT_ID=2&edit_event_nonce=cf3a7e5b62 |
|
483 | + $EVT_ID = $item->event_ID(); |
|
484 | + $event_name = $item->event_name(); |
|
485 | + $event_name = $event_name ? $event_name : __("No Associated Event", 'event_espresso'); |
|
486 | + $event_name = wp_trim_words($event_name, 30, '...'); |
|
487 | + if ($EVT_ID) { |
|
488 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'edit', 'post' => $EVT_ID), |
|
489 | + EVENTS_ADMIN_URL); |
|
490 | + $edit_event = EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'edit_event', $EVT_ID) |
|
491 | + ? '<a class="ee-status-color-' |
|
492 | + . $this->_event_details['status'] |
|
493 | + . '" href="' |
|
494 | + . $edit_event_url |
|
495 | + . '" title="' |
|
496 | + . esc_attr($this->_event_details['title_attr']) |
|
497 | + . '">' |
|
498 | + . $event_name |
|
499 | + . '</a>' : $event_name; |
|
500 | + $edit_event_url = EE_Admin_Page::add_query_args_and_nonce(array('event_id' => $EVT_ID), REG_ADMIN_URL); |
|
501 | + $actions['event_filter'] = '<a href="' . $edit_event_url . '" title="'; |
|
502 | + $actions['event_filter'] .= sprintf(esc_attr__('Filter this list to only show registrations for %s', |
|
503 | + 'event_espresso'), $event_name); |
|
504 | + $actions['event_filter'] .= '">' . __('View Registrations', 'event_espresso') . '</a>'; |
|
505 | + } else { |
|
506 | + $edit_event = $event_name; |
|
507 | + $actions['event_filter'] = ''; |
|
508 | + } |
|
509 | + return sprintf('%1$s %2$s', $edit_event, $this->row_actions($actions)); |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * column_DTT_EVT_start |
|
516 | + * |
|
517 | + * @access public |
|
518 | + * @param \EE_Registration $item |
|
519 | + * @return string |
|
520 | + * @throws \EE_Error |
|
521 | + */ |
|
522 | + public function column_DTT_EVT_start(EE_Registration $item) |
|
523 | + { |
|
524 | + $datetime_strings = array(); |
|
525 | + $ticket = $item->ticket(true); |
|
526 | + if ($ticket instanceof EE_Ticket) { |
|
527 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
528 | + $datetimes = $ticket->datetimes($remove_defaults); |
|
529 | + foreach ($datetimes as $datetime) { |
|
530 | + $datetime_strings[] = $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
531 | + } |
|
532 | + return implode("<br />", $datetime_strings); |
|
533 | + } else { |
|
534 | + return __('There is no ticket on this registration', 'event_espresso'); |
|
535 | + } |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * column_ATT_fname |
|
542 | + * |
|
543 | + * @access public |
|
544 | + * @param \EE_Registration $item |
|
545 | + * @return string |
|
546 | + * @throws \EE_Error |
|
547 | + */ |
|
548 | + public function column_ATT_fname(EE_Registration $item) |
|
549 | + { |
|
550 | + $attendee = $item->attendee(); |
|
551 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
552 | + 'action' => 'view_registration', |
|
553 | + '_REG_ID' => $item->ID(), |
|
554 | + ), REG_ADMIN_URL); |
|
555 | + $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
|
556 | + $link = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
557 | + 'espresso_registrations_view_registration', $item->ID()) ? '<a href="' |
|
558 | + . $edit_lnk_url |
|
559 | + . '" title="' |
|
560 | + . esc_attr__('View Registration Details', |
|
561 | + 'event_espresso') |
|
562 | + . '">' |
|
563 | + . $attendee_name |
|
564 | + . '</a>' : $attendee_name; |
|
565 | + $link .= $item->count() === 1 |
|
566 | + ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup>' : ''; |
|
567 | + $t = $item->get_first_related('Transaction'); |
|
568 | + $payment_count = $t instanceof EE_Transaction ? $t->count_related('Payment') : 0; |
|
569 | + //append group count to name |
|
570 | + $link .= ' ' . sprintf(__('(%1$s / %2$s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
571 | + //append reg_code |
|
572 | + $link .= '<br>' . sprintf(__('Reg Code: %s', 'event_espresso'), $item->get('REG_code')); |
|
573 | + //reg status text for accessibility |
|
574 | + $link .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->status_ID(), false, |
|
575 | + 'sentence') . '</span>'; |
|
576 | + //trash/restore/delete actions |
|
577 | + $actions = array(); |
|
578 | + if ($this->_view !== 'trash' |
|
579 | + && $payment_count === 0 |
|
580 | + && EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
|
581 | + 'espresso_registrations_trash_registrations', $item->ID()) |
|
582 | + ) { |
|
583 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
584 | + 'action' => 'trash_registrations', |
|
585 | + '_REG_ID' => $item->ID(), |
|
586 | + ), REG_ADMIN_URL); |
|
587 | + $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' . esc_attr__('Trash Registration', |
|
588 | + 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
589 | + } elseif ($this->_view === 'trash') { |
|
590 | + // restore registration link |
|
591 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
|
592 | + 'espresso_registrations_restore_registrations', $item->ID()) |
|
593 | + ) { |
|
594 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
595 | + 'action' => 'restore_registrations', |
|
596 | + '_REG_ID' => $item->ID(), |
|
597 | + ), REG_ADMIN_URL); |
|
598 | + $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' . esc_attr__('Restore Registration', |
|
599 | + 'event_espresso') . '">' . __('Restore', 'event_espresso') . '</a>'; |
|
600 | + } |
|
601 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_registration', |
|
602 | + 'espresso_registrations_ee_delete_registrations', $item->ID()) |
|
603 | + ) { |
|
604 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
605 | + 'action' => 'delete_registrations', |
|
606 | + '_REG_ID' => $item->ID(), |
|
607 | + ), REG_ADMIN_URL); |
|
608 | + $actions['delete'] = '<a href="' |
|
609 | + . $delete_lnk_url |
|
610 | + . '" title="' |
|
611 | + . esc_attr__('Delete Registration Permanently', 'event_espresso') |
|
612 | + . '">' |
|
613 | + . __('Delete', 'event_espresso') |
|
614 | + . '</a>'; |
|
615 | + } |
|
616 | + } |
|
617 | + return sprintf('%1$s %2$s', $link, $this->row_actions($actions)); |
|
618 | + } |
|
619 | + |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * column_ATT_email |
|
624 | + * |
|
625 | + * @access public |
|
626 | + * @param \EE_Registration $item |
|
627 | + * @return string |
|
628 | + * @throws \EE_Error |
|
629 | + */ |
|
630 | + public function column_ATT_email(EE_Registration $item) |
|
631 | + { |
|
632 | + $attendee = $item->get_first_related('Attendee'); |
|
633 | + return ! $attendee instanceof EE_Attendee ? __('No attached contact record.', 'event_espresso') |
|
634 | + : $attendee->email(); |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * column__REG_count |
|
641 | + * |
|
642 | + * @access public |
|
643 | + * @param \EE_Registration $item |
|
644 | + * @return string |
|
645 | + */ |
|
646 | + public function column__REG_count(EE_Registration $item) |
|
647 | + { |
|
648 | + return sprintf(__('%1$s / %2$s', 'event_espresso'), $item->count(), $item->group_size()); |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + |
|
653 | + /** |
|
654 | + * column_PRC_amount |
|
655 | + * |
|
656 | + * @access public |
|
657 | + * @param \EE_Registration $item |
|
658 | + * @return string |
|
659 | + */ |
|
660 | + public function column_PRC_amount(EE_Registration $item) |
|
661 | + { |
|
662 | + $ticket = $item->ticket(); |
|
663 | + $content = isset($_GET['event_id']) && $ticket instanceof EE_Ticket ? '<span class="TKT_name">' |
|
664 | + . $ticket->name() |
|
665 | + . '</span><br />' : ''; |
|
666 | + if ($item->final_price() > 0) { |
|
667 | + $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
668 | + } else { |
|
669 | + // free event |
|
670 | + $content .= '<span class="reg-overview-free-event-spn reg-pad-rght">' |
|
671 | + . __('free', 'event_espresso') |
|
672 | + . '</span>'; |
|
673 | + } |
|
674 | + return $content; |
|
675 | + } |
|
676 | + |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * column__REG_final_price |
|
681 | + * |
|
682 | + * @access public |
|
683 | + * @param \EE_Registration $item |
|
684 | + * @return string |
|
685 | + */ |
|
686 | + public function column__REG_final_price(EE_Registration $item) |
|
687 | + { |
|
688 | + $ticket = $item->ticket(); |
|
689 | + $content = isset($_GET['event_id']) || ! $ticket instanceof EE_Ticket |
|
690 | + ? '' |
|
691 | + : '<span class="TKT_name">' |
|
692 | + . $ticket->name() |
|
693 | + . '</span><br />'; |
|
694 | + $content .= '<span class="reg-pad-rght">' . $item->pretty_final_price() . '</span>'; |
|
695 | + return $content; |
|
696 | + } |
|
697 | + |
|
698 | + |
|
699 | + |
|
700 | + /** |
|
701 | + * column__REG_paid |
|
702 | + * |
|
703 | + * @access public |
|
704 | + * @param \EE_Registration $item |
|
705 | + * @return string |
|
706 | + */ |
|
707 | + public function column__REG_paid(EE_Registration $item) |
|
708 | + { |
|
709 | + $payment_method = $item->payment_method(); |
|
710 | + $payment_method_name = $payment_method instanceof EE_Payment_Method ? $payment_method->admin_name() |
|
711 | + : __('Unknown', 'event_espresso'); |
|
712 | + $content = '<span class="reg-pad-rght">' . $item->pretty_paid() . '</span>'; |
|
713 | + if ($item->paid() > 0) { |
|
714 | + $content .= '<br><span class="ee-status-text-small">' . sprintf(__('...via %s', 'event_espresso'), |
|
715 | + $payment_method_name) . '</span>'; |
|
716 | + } |
|
717 | + return $content; |
|
718 | + } |
|
719 | + |
|
720 | + |
|
721 | + |
|
722 | + /** |
|
723 | + * column_TXN_total |
|
724 | + * |
|
725 | + * @access public |
|
726 | + * @param \EE_Registration $item |
|
727 | + * @return string |
|
728 | + * @throws \EE_Error |
|
729 | + */ |
|
730 | + public function column_TXN_total(EE_Registration $item) |
|
731 | + { |
|
732 | + if ($item->transaction()) { |
|
733 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
734 | + 'action' => 'view_transaction', |
|
735 | + 'TXN_ID' => $item->transaction_ID(), |
|
736 | + ), TXN_ADMIN_URL); |
|
737 | + return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
738 | + 'espresso_transactions_view_transaction', $item->transaction_ID()) |
|
739 | + ? '<span class="reg-pad-rght"><a class="status-' |
|
740 | + . $item->transaction()->status_ID() |
|
741 | + . '" href="' |
|
742 | + . $view_txn_lnk_url |
|
743 | + . '" title="' |
|
744 | + . esc_attr__('View Transaction', 'event_espresso') |
|
745 | + . '">' |
|
746 | + . $item->transaction()->pretty_total() |
|
747 | + . '</a></span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_total() . '</span>'; |
|
748 | + } else { |
|
749 | + return __("None", "event_espresso"); |
|
750 | + } |
|
751 | + } |
|
752 | + |
|
753 | + |
|
754 | + |
|
755 | + /** |
|
756 | + * column_TXN_paid |
|
757 | + * |
|
758 | + * @access public |
|
759 | + * @param \EE_Registration $item |
|
760 | + * @return string |
|
761 | + * @throws \EE_Error |
|
762 | + */ |
|
763 | + public function column_TXN_paid(EE_Registration $item) |
|
764 | + { |
|
765 | + if ($item->count() === 1) { |
|
766 | + $transaction = $item->transaction() ? $item->transaction() : EE_Transaction::new_instance(); |
|
767 | + if ($transaction->paid() >= $transaction->total()) { |
|
768 | + return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
|
769 | + } else { |
|
770 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
771 | + 'action' => 'view_transaction', |
|
772 | + 'TXN_ID' => $item->transaction_ID(), |
|
773 | + ), TXN_ADMIN_URL); |
|
774 | + return EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
775 | + 'espresso_transactions_view_transaction', $item->transaction_ID()) |
|
776 | + ? '<span class="reg-pad-rght"><a class="status-' |
|
777 | + . $transaction->status_ID() |
|
778 | + . '" href="' |
|
779 | + . $view_txn_lnk_url |
|
780 | + . '" title="' |
|
781 | + . esc_attr__('View Transaction', 'event_espresso') |
|
782 | + . '">' |
|
783 | + . $item->transaction()->pretty_paid() |
|
784 | + . '</a><span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
785 | + } |
|
786 | + } |
|
787 | + return ' '; |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + |
|
792 | + /** |
|
793 | + * column_actions |
|
794 | + * |
|
795 | + * @access public |
|
796 | + * @param \EE_Registration $item |
|
797 | + * @return string |
|
798 | + * @throws \EE_Error |
|
799 | + */ |
|
800 | + public function column_actions(EE_Registration $item) |
|
801 | + { |
|
802 | + $actions = array(); |
|
803 | + $attendee = $item->attendee(); |
|
804 | + $this->_set_related_details($item); |
|
805 | + //Build row actions |
|
806 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
807 | + 'action' => 'view_registration', |
|
808 | + '_REG_ID' => $item->ID(), |
|
809 | + ), REG_ADMIN_URL); |
|
810 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
811 | + 'action' => 'edit_attendee', |
|
812 | + 'post' => $item->attendee_ID(), |
|
813 | + ), REG_ADMIN_URL); |
|
814 | + // page=attendees&event_admin_reports=resend_email®istration_id=43653465634&event_id=2&form_action=resend_email |
|
815 | + //$resend_reg_lnk_url_params = array( 'action'=>'resend_registration', '_REG_ID'=>$item->REG_ID ); |
|
816 | + $resend_reg_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
817 | + 'action' => 'resend_registration', |
|
818 | + '_REG_ID' => $item->ID(), |
|
819 | + ), REG_ADMIN_URL, true); |
|
820 | + //Build row actions |
|
821 | + $actions['view_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
822 | + 'espresso_registrations_view_registration', $item->ID()) ? ' |
|
823 | 823 | <li> |
824 | 824 | <a href="' . $view_lnk_url . '" title="' . esc_attr__('View Registration Details', 'event_espresso') . '" class="tiny-text"> |
825 | 825 | <div class="dashicons dashicons-clipboard"></div> |
826 | 826 | </a> |
827 | 827 | </li>' : ''; |
828 | - $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts', |
|
829 | - 'espresso_registrations_edit_attendee') |
|
830 | - && $attendee instanceof EE_Attendee ? ' |
|
828 | + $actions['edit_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_edit_contacts', |
|
829 | + 'espresso_registrations_edit_attendee') |
|
830 | + && $attendee instanceof EE_Attendee ? ' |
|
831 | 831 | <li> |
832 | 832 | <a href="' . $edit_lnk_url . '" title="' . esc_attr__('Edit Contact Details', 'event_espresso') . '" class="tiny-text"> |
833 | 833 | <div class="ee-icon ee-icon-user-edit ee-icon-size-16"></div> |
834 | 834 | </a> |
835 | 835 | </li>' : ''; |
836 | - $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee |
|
837 | - && EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
838 | - 'espresso_registrations_resend_registration', $item->ID()) ? ' |
|
836 | + $actions['resend_reg_lnk'] = $attendee instanceof EE_Attendee |
|
837 | + && EE_Registry::instance()->CAP->current_user_can('ee_send_message', |
|
838 | + 'espresso_registrations_resend_registration', $item->ID()) ? ' |
|
839 | 839 | <li> |
840 | 840 | <a href="' |
841 | - . $resend_reg_lnk_url |
|
842 | - . '" title="' |
|
843 | - . esc_attr__('Resend Registration Details', |
|
844 | - 'event_espresso') |
|
845 | - . '" class="tiny-text"> |
|
841 | + . $resend_reg_lnk_url |
|
842 | + . '" title="' |
|
843 | + . esc_attr__('Resend Registration Details', |
|
844 | + 'event_espresso') |
|
845 | + . '" class="tiny-text"> |
|
846 | 846 | <div class="dashicons dashicons-email-alt"></div> |
847 | 847 | </a> |
848 | 848 | </li>' : ''; |
849 | - // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb |
|
850 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
851 | - 'action' => 'view_transaction', |
|
852 | - 'TXN_ID' => $this->_transaction_details['id'], |
|
853 | - ), TXN_ADMIN_URL); |
|
854 | - $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
855 | - 'espresso_transactions_view_transaction', $this->_transaction_details['id']) ? ' |
|
849 | + // page=transactions&action=view_transaction&txn=256&_wpnonce=6414da4dbb |
|
850 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
851 | + 'action' => 'view_transaction', |
|
852 | + 'TXN_ID' => $this->_transaction_details['id'], |
|
853 | + ), TXN_ADMIN_URL); |
|
854 | + $actions['view_txn_lnk'] = EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', |
|
855 | + 'espresso_transactions_view_transaction', $this->_transaction_details['id']) ? ' |
|
856 | 856 | <li> |
857 | 857 | <a class="ee-status-color-' |
858 | - . $this->_transaction_details['status'] |
|
859 | - . ' tiny-text" href="' |
|
860 | - . $view_txn_lnk_url |
|
861 | - . '" title="' |
|
862 | - . $this->_transaction_details['title_attr'] |
|
863 | - . '"> |
|
858 | + . $this->_transaction_details['status'] |
|
859 | + . ' tiny-text" href="' |
|
860 | + . $view_txn_lnk_url |
|
861 | + . '" title="' |
|
862 | + . $this->_transaction_details['title_attr'] |
|
863 | + . '"> |
|
864 | 864 | <div class="dashicons dashicons-cart"></div> |
865 | 865 | </a> |
866 | 866 | </li>' : ''; |
867 | - //invoice link |
|
868 | - $actions['dl_invoice_lnk'] = ''; |
|
869 | - $dl_invoice_lnk_url = $item->invoice_url(); |
|
870 | - //only show invoice link if message type is active. |
|
871 | - if ($attendee instanceof EE_Attendee |
|
872 | - && $item->is_primary_registrant() |
|
873 | - && EEH_MSG_Template::is_mt_active('invoice') |
|
874 | - ) { |
|
875 | - $actions['dl_invoice_lnk'] = ' |
|
867 | + //invoice link |
|
868 | + $actions['dl_invoice_lnk'] = ''; |
|
869 | + $dl_invoice_lnk_url = $item->invoice_url(); |
|
870 | + //only show invoice link if message type is active. |
|
871 | + if ($attendee instanceof EE_Attendee |
|
872 | + && $item->is_primary_registrant() |
|
873 | + && EEH_MSG_Template::is_mt_active('invoice') |
|
874 | + ) { |
|
875 | + $actions['dl_invoice_lnk'] = ' |
|
876 | 876 | <li> |
877 | 877 | <a title="' |
878 | - . esc_attr__('View Transaction Invoice', 'event_espresso') |
|
879 | - . '" target="_blank" href="' |
|
880 | - . $dl_invoice_lnk_url |
|
881 | - . '" class="tiny-text"> |
|
878 | + . esc_attr__('View Transaction Invoice', 'event_espresso') |
|
879 | + . '" target="_blank" href="' |
|
880 | + . $dl_invoice_lnk_url |
|
881 | + . '" class="tiny-text"> |
|
882 | 882 | <span class="dashicons dashicons-media-spreadsheet ee-icon-size-18"></span> |
883 | 883 | </a> |
884 | 884 | </li>'; |
885 | - } |
|
886 | - $actions['filtered_messages_link'] = ''; |
|
887 | - //message list table link (filtered by REG_ID |
|
888 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
889 | - $actions['filtered_messages_link'] = '<li>' |
|
890 | - . EEH_MSG_Template::get_message_action_link('see_notifications_for', |
|
891 | - null, array( |
|
892 | - '_REG_ID' => $item->ID(), |
|
893 | - )) |
|
894 | - . '</li>'; |
|
895 | - } |
|
896 | - $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
|
897 | - return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
|
898 | - } |
|
885 | + } |
|
886 | + $actions['filtered_messages_link'] = ''; |
|
887 | + //message list table link (filtered by REG_ID |
|
888 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_global_messages', 'view_filtered_messages')) { |
|
889 | + $actions['filtered_messages_link'] = '<li>' |
|
890 | + . EEH_MSG_Template::get_message_action_link('see_notifications_for', |
|
891 | + null, array( |
|
892 | + '_REG_ID' => $item->ID(), |
|
893 | + )) |
|
894 | + . '</li>'; |
|
895 | + } |
|
896 | + $actions = apply_filters('FHEE__EE_Registrations_List_Table__column_actions__actions', $actions, $item, $this); |
|
897 | + return $this->_action_string(implode('', $actions), $item, 'ul', 'reg-overview-actions-ul'); |
|
898 | + } |
|
899 | 899 | |
900 | 900 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | |
@@ -29,91 +29,91 @@ discard block |
||
29 | 29 | { |
30 | 30 | |
31 | 31 | |
32 | - public function __construct() |
|
33 | - { |
|
34 | - //define some page related constants |
|
35 | - define('EE_MAINTENANCE_LABEL', __('Maintenance', 'event_espresso')); |
|
36 | - define('EE_MAINTENANCE_PG_SLUG', 'espresso_maintenance_settings'); |
|
37 | - define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page=' . EE_MAINTENANCE_PG_SLUG)); |
|
38 | - define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES . 'maintenance' . DS); |
|
39 | - define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN . 'templates' . DS); |
|
40 | - define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL . 'maintenance/assets/'); |
|
41 | - //check that if we're in maintenance mode that we tell the admin that |
|
42 | - add_action('admin_notices', array($this, 'check_maintenance_mode')); |
|
43 | - parent::__construct(); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - protected function _set_init_properties() |
|
49 | - { |
|
50 | - $this->label = EE_MAINTENANCE_LABEL; |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - protected function _set_menu_map() |
|
56 | - { |
|
57 | - $menu_map = $this->_menu_map(); |
|
58 | - $this->_menu_map = EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
59 | - ? new EE_Admin_Page_Main_Menu($menu_map) : new EE_Admin_Page_Sub_Menu($menu_map); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - protected function _menu_map() |
|
65 | - { |
|
66 | - $map = array( |
|
67 | - 'menu_group' => 'extras', |
|
68 | - 'menu_order' => 30, |
|
69 | - 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
70 | - 'parent_slug' => 'espresso_events', |
|
71 | - 'menu_slug' => EE_MAINTENANCE_PG_SLUG, |
|
72 | - 'menu_label' => EE_MAINTENANCE_LABEL, |
|
73 | - 'capability' => 'manage_options', |
|
74 | - 'maintenance_mode_parent' => EE_MAINTENANCE_PG_SLUG, |
|
75 | - 'admin_init_page' => $this, |
|
76 | - ); |
|
77 | - if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
78 | - $map['menu_group'] = 'main'; |
|
79 | - $map['subtitle'] = EE_MAINTENANCE_LABEL; |
|
80 | - $map['menu_label'] = __('Event Espresso', 'event_espresso'); |
|
81 | - } |
|
82 | - return $map; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * Checks if we're in maintenance mode, and if so we notify the admin adn tell them how to take the site OUT of |
|
89 | - * maintenance mode |
|
90 | - */ |
|
91 | - public function check_maintenance_mode() |
|
92 | - { |
|
93 | - $notice = ''; |
|
94 | - $maintenance_page_url = ''; |
|
95 | - if (EE_Maintenance_Mode::instance()->level()) { |
|
96 | - $maintenance_page_url = EE_Admin_Page::add_query_args_and_nonce(array(), EE_MAINTENANCE_ADMIN_URL); |
|
97 | - switch (EE_Maintenance_Mode::instance()->level()) { |
|
98 | - case EE_Maintenance_Mode::level_1_frontend_only_maintenance: |
|
99 | - $notice = '<div class="update-nag"> |
|
32 | + public function __construct() |
|
33 | + { |
|
34 | + //define some page related constants |
|
35 | + define('EE_MAINTENANCE_LABEL', __('Maintenance', 'event_espresso')); |
|
36 | + define('EE_MAINTENANCE_PG_SLUG', 'espresso_maintenance_settings'); |
|
37 | + define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page=' . EE_MAINTENANCE_PG_SLUG)); |
|
38 | + define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES . 'maintenance' . DS); |
|
39 | + define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN . 'templates' . DS); |
|
40 | + define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL . 'maintenance/assets/'); |
|
41 | + //check that if we're in maintenance mode that we tell the admin that |
|
42 | + add_action('admin_notices', array($this, 'check_maintenance_mode')); |
|
43 | + parent::__construct(); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + protected function _set_init_properties() |
|
49 | + { |
|
50 | + $this->label = EE_MAINTENANCE_LABEL; |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + protected function _set_menu_map() |
|
56 | + { |
|
57 | + $menu_map = $this->_menu_map(); |
|
58 | + $this->_menu_map = EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
59 | + ? new EE_Admin_Page_Main_Menu($menu_map) : new EE_Admin_Page_Sub_Menu($menu_map); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + protected function _menu_map() |
|
65 | + { |
|
66 | + $map = array( |
|
67 | + 'menu_group' => 'extras', |
|
68 | + 'menu_order' => 30, |
|
69 | + 'show_on_menu' => EE_Admin_Page_Menu_Map::BLOG_ADMIN_ONLY, |
|
70 | + 'parent_slug' => 'espresso_events', |
|
71 | + 'menu_slug' => EE_MAINTENANCE_PG_SLUG, |
|
72 | + 'menu_label' => EE_MAINTENANCE_LABEL, |
|
73 | + 'capability' => 'manage_options', |
|
74 | + 'maintenance_mode_parent' => EE_MAINTENANCE_PG_SLUG, |
|
75 | + 'admin_init_page' => $this, |
|
76 | + ); |
|
77 | + if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
78 | + $map['menu_group'] = 'main'; |
|
79 | + $map['subtitle'] = EE_MAINTENANCE_LABEL; |
|
80 | + $map['menu_label'] = __('Event Espresso', 'event_espresso'); |
|
81 | + } |
|
82 | + return $map; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * Checks if we're in maintenance mode, and if so we notify the admin adn tell them how to take the site OUT of |
|
89 | + * maintenance mode |
|
90 | + */ |
|
91 | + public function check_maintenance_mode() |
|
92 | + { |
|
93 | + $notice = ''; |
|
94 | + $maintenance_page_url = ''; |
|
95 | + if (EE_Maintenance_Mode::instance()->level()) { |
|
96 | + $maintenance_page_url = EE_Admin_Page::add_query_args_and_nonce(array(), EE_MAINTENANCE_ADMIN_URL); |
|
97 | + switch (EE_Maintenance_Mode::instance()->level()) { |
|
98 | + case EE_Maintenance_Mode::level_1_frontend_only_maintenance: |
|
99 | + $notice = '<div class="update-nag"> |
|
100 | 100 | ' |
101 | - . sprintf(__("Event Espresso is in Frontend-Only MAINTENANCE MODE. This means the front-end (ie, non-wp-admin pages) is disabled for ALL users except site admins. Visit the %s Maintenance Page %s to disable maintenance mode.", |
|
102 | - "event_espresso"), "<a href='$maintenance_page_url'>", "</a>") |
|
103 | - . |
|
104 | - '</div>'; |
|
105 | - break; |
|
106 | - case EE_Maintenance_Mode::level_2_complete_maintenance: |
|
107 | - $notice = '<div class="error"> |
|
101 | + . sprintf(__("Event Espresso is in Frontend-Only MAINTENANCE MODE. This means the front-end (ie, non-wp-admin pages) is disabled for ALL users except site admins. Visit the %s Maintenance Page %s to disable maintenance mode.", |
|
102 | + "event_espresso"), "<a href='$maintenance_page_url'>", "</a>") |
|
103 | + . |
|
104 | + '</div>'; |
|
105 | + break; |
|
106 | + case EE_Maintenance_Mode::level_2_complete_maintenance: |
|
107 | + $notice = '<div class="error"> |
|
108 | 108 | <p>' . sprintf(__("As part of the process for updating Event Espresso, your database also |
109 | 109 | needs to be updated. Event Espresso is in COMPLETE MAINTENANCE MODE (both WordPress admin pages and front-end event registration pages are disabled) until you run the database update script. %s Visit the Maintenance Page to get started,%s it only takes a moment.", |
110 | - "event_espresso"), "<a href='$maintenance_page_url'>", "</a>") . |
|
111 | - '</div>'; |
|
112 | - break; |
|
113 | - } |
|
114 | - } |
|
115 | - echo apply_filters('FHEE__Maintenance_Admin_Page_Init__check_maintenance_mode__notice', $notice, |
|
116 | - $maintenance_page_url); |
|
117 | - } |
|
110 | + "event_espresso"), "<a href='$maintenance_page_url'>", "</a>") . |
|
111 | + '</div>'; |
|
112 | + break; |
|
113 | + } |
|
114 | + } |
|
115 | + echo apply_filters('FHEE__Maintenance_Admin_Page_Init__check_maintenance_mode__notice', $notice, |
|
116 | + $maintenance_page_url); |
|
117 | + } |
|
118 | 118 | |
119 | 119 | } //end class Payments_Admin_Page_Init |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | //define some page related constants |
35 | 35 | define('EE_MAINTENANCE_LABEL', __('Maintenance', 'event_espresso')); |
36 | 36 | define('EE_MAINTENANCE_PG_SLUG', 'espresso_maintenance_settings'); |
37 | - define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page=' . EE_MAINTENANCE_PG_SLUG)); |
|
38 | - define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES . 'maintenance' . DS); |
|
39 | - define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN . 'templates' . DS); |
|
40 | - define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL . 'maintenance/assets/'); |
|
37 | + define('EE_MAINTENANCE_ADMIN_URL', admin_url('admin.php?page='.EE_MAINTENANCE_PG_SLUG)); |
|
38 | + define('EE_MAINTENANCE_ADMIN', EE_ADMIN_PAGES.'maintenance'.DS); |
|
39 | + define('EE_MAINTENANCE_TEMPLATE_PATH', EE_MAINTENANCE_ADMIN.'templates'.DS); |
|
40 | + define('EE_MAINTENANCE_ASSETS_URL', EE_ADMIN_PAGES_URL.'maintenance/assets/'); |
|
41 | 41 | //check that if we're in maintenance mode that we tell the admin that |
42 | 42 | add_action('admin_notices', array($this, 'check_maintenance_mode')); |
43 | 43 | parent::__construct(); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | $notice = '<div class="error"> |
108 | 108 | <p>' . sprintf(__("As part of the process for updating Event Espresso, your database also |
109 | 109 | needs to be updated. Event Espresso is in COMPLETE MAINTENANCE MODE (both WordPress admin pages and front-end event registration pages are disabled) until you run the database update script. %s Visit the Maintenance Page to get started,%s it only takes a moment.", |
110 | - "event_espresso"), "<a href='$maintenance_page_url'>", "</a>") . |
|
110 | + "event_espresso"), "<a href='$maintenance_page_url'>", "</a>"). |
|
111 | 111 | '</div>'; |
112 | 112 | break; |
113 | 113 | } |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | if ( |
40 | 40 | ! ( $checkout->uts || $checkout->reg_url_link ) |
41 | 41 | && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
42 | - && \EE_Config::instance()->registration->track_invalid_checkout_access() |
|
43 | - ) { |
|
42 | + && \EE_Config::instance()->registration->track_invalid_checkout_access() |
|
43 | + ) { |
|
44 | 44 | /** @var \EE_Request $request */ |
45 | 45 | $request = \EE_Registry::instance()->load_core( 'EE_Request' ); |
46 | 46 | $ip_address = $request->ip_address(); |
@@ -60,14 +60,14 @@ discard block |
||
60 | 60 | } |
61 | 61 | $ee_bot_checkout[ $ip_address ][ $http_referer ]++; |
62 | 62 | update_option( InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout ); |
63 | - if (WP_DEBUG) { |
|
64 | - \EE_Error::add_error( |
|
65 | - esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'), |
|
66 | - __FILE__, |
|
67 | - __FUNCTION__, |
|
68 | - __LINE__ |
|
69 | - ); |
|
70 | - } |
|
63 | + if (WP_DEBUG) { |
|
64 | + \EE_Error::add_error( |
|
65 | + esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'), |
|
66 | + __FILE__, |
|
67 | + __FUNCTION__, |
|
68 | + __LINE__ |
|
69 | + ); |
|
70 | + } |
|
71 | 71 | return true; |
72 | 72 | } |
73 | 73 | return false; |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\modules\invalid_checkout_access; |
3 | 3 | |
4 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -35,31 +35,31 @@ discard block |
||
35 | 35 | * @param \EE_Checkout $checkout |
36 | 36 | * @return bool true if access to registration checkout appears to be invalid |
37 | 37 | */ |
38 | - public function checkoutAccessIsInvalid( \EE_Checkout $checkout ) { |
|
38 | + public function checkoutAccessIsInvalid(\EE_Checkout $checkout) { |
|
39 | 39 | if ( |
40 | - ! ( $checkout->uts || $checkout->reg_url_link ) |
|
41 | - && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
|
40 | + ! ($checkout->uts || $checkout->reg_url_link) |
|
41 | + && ! (defined('DOING_AJAX') && DOING_AJAX) |
|
42 | 42 | && \EE_Config::instance()->registration->track_invalid_checkout_access() |
43 | 43 | ) { |
44 | 44 | /** @var \EE_Request $request */ |
45 | - $request = \EE_Registry::instance()->load_core( 'EE_Request' ); |
|
45 | + $request = \EE_Registry::instance()->load_core('EE_Request'); |
|
46 | 46 | $ip_address = $request->ip_address(); |
47 | - $ee_bot_checkout = get_option( InvalidCheckoutAccess::OPTION_KEY ); |
|
48 | - if ( $ee_bot_checkout === false ) { |
|
47 | + $ee_bot_checkout = get_option(InvalidCheckoutAccess::OPTION_KEY); |
|
48 | + if ($ee_bot_checkout === false) { |
|
49 | 49 | $ee_bot_checkout = array(); |
50 | - add_option( InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false ); |
|
50 | + add_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout, '', false); |
|
51 | 51 | } |
52 | - if ( ! isset( $ee_bot_checkout[ $ip_address ] ) ) { |
|
53 | - $ee_bot_checkout[ $ip_address ] = array(); |
|
52 | + if ( ! isset($ee_bot_checkout[$ip_address])) { |
|
53 | + $ee_bot_checkout[$ip_address] = array(); |
|
54 | 54 | } |
55 | - $http_referer = isset( $_SERVER['HTTP_REFERER'] ) |
|
56 | - ? esc_attr( $_SERVER['HTTP_REFERER'] ) |
|
55 | + $http_referer = isset($_SERVER['HTTP_REFERER']) |
|
56 | + ? esc_attr($_SERVER['HTTP_REFERER']) |
|
57 | 57 | : 0; |
58 | - if ( ! isset( $ee_bot_checkout[ $ip_address ][ $http_referer ] ) ) { |
|
59 | - $ee_bot_checkout[ $ip_address ][ $http_referer ] = 0; |
|
58 | + if ( ! isset($ee_bot_checkout[$ip_address][$http_referer])) { |
|
59 | + $ee_bot_checkout[$ip_address][$http_referer] = 0; |
|
60 | 60 | } |
61 | - $ee_bot_checkout[ $ip_address ][ $http_referer ]++; |
|
62 | - update_option( InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout ); |
|
61 | + $ee_bot_checkout[$ip_address][$http_referer]++; |
|
62 | + update_option(InvalidCheckoutAccess::OPTION_KEY, $ee_bot_checkout); |
|
63 | 63 | if (WP_DEBUG) { |
64 | 64 | \EE_Error::add_error( |
65 | 65 | esc_html__('Direct access to the registration checkout page is not allowed.', 'event_espresso'), |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | 'layout_strategy' => new \EE_Admin_Two_Column_Layout(), |
89 | 89 | 'subsections' => array( |
90 | 90 | 'invalid_checkout_access_hdr' => new \EE_Form_Section_HTML( |
91 | - \EEH_HTML::h2( esc_html__( 'Invalid Checkout Access', 'event_espresso' ) ) |
|
91 | + \EEH_HTML::h2(esc_html__('Invalid Checkout Access', 'event_espresso')) |
|
92 | 92 | ), |
93 | 93 | 'ee_bot_checkout_data' => new \EE_Text_Area_Input( |
94 | 94 | array( |
95 | - 'html_label_text' => esc_html__( 'Invalid Checkout Data', 'event_espresso' ), |
|
95 | + 'html_label_text' => esc_html__('Invalid Checkout Data', 'event_espresso'), |
|
96 | 96 | 'default' => var_export( |
97 | - get_option( InvalidCheckoutAccess::OPTION_KEY, array() ), |
|
97 | + get_option(InvalidCheckoutAccess::OPTION_KEY, array()), |
|
98 | 98 | true |
99 | 99 | ), |
100 | 100 | 'required' => false, |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | ), |
107 | 107 | 'track_invalid_checkout_access' => new \EE_Yes_No_Input( |
108 | 108 | array( |
109 | - 'html_label_text' => __( 'Track Invalid Checkout Access?', 'event_espresso' ), |
|
109 | + 'html_label_text' => __('Track Invalid Checkout Access?', 'event_espresso'), |
|
110 | 110 | 'html_help_text' => esc_html__( |
111 | 111 | 'Controls whether or not invalid attempts to directly access the registration checkout page should be tracked. Setting this to "No" means that the above data will no longer be collected.', |
112 | 112 | 'event_espresso' |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | ), |
120 | 120 | 'delete_invalid_checkout_data' => new \EE_Yes_No_Input( |
121 | 121 | array( |
122 | - 'html_label_text' => __( 'Reset Invalid Checkout Data', 'event_espresso' ), |
|
122 | + 'html_label_text' => __('Reset Invalid Checkout Data', 'event_espresso'), |
|
123 | 123 | 'html_help_text' => esc_html__( |
124 | 124 | 'Setting this to "Yes" will delete all existing invalid checkout access data.', |
125 | 125 | 'event_espresso' |
@@ -141,15 +141,15 @@ discard block |
||
141 | 141 | * @param \EE_Registration_Config $EE_Registration_Config |
142 | 142 | * @return \EE_Registration_Config |
143 | 143 | */ |
144 | - public function processForm( \EE_Registration_Config $EE_Registration_Config ) { |
|
144 | + public function processForm(\EE_Registration_Config $EE_Registration_Config) { |
|
145 | 145 | try { |
146 | 146 | $invalid_checkout_access_form = $this->getForm(); |
147 | 147 | // if not displaying a form, then check for form submission |
148 | - if ( $invalid_checkout_access_form->was_submitted() ) { |
|
148 | + if ($invalid_checkout_access_form->was_submitted()) { |
|
149 | 149 | // capture form data |
150 | 150 | $invalid_checkout_access_form->receive_form_submission(); |
151 | 151 | // validate form data |
152 | - if ( $invalid_checkout_access_form->is_valid() ) { |
|
152 | + if ($invalid_checkout_access_form->is_valid()) { |
|
153 | 153 | // grab validated data from form |
154 | 154 | $valid_data = $invalid_checkout_access_form->valid_data(); |
155 | 155 | // ensure form inputs we want are set |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | $valid_data['track_invalid_checkout_access'] |
164 | 164 | ); |
165 | 165 | // if deleting, then update option with empty array |
166 | - if ( filter_var( $valid_data['delete_invalid_checkout_data'], FILTER_VALIDATE_BOOLEAN ) ) { |
|
167 | - update_option( InvalidCheckoutAccess::OPTION_KEY, array() ); |
|
166 | + if (filter_var($valid_data['delete_invalid_checkout_data'], FILTER_VALIDATE_BOOLEAN)) { |
|
167 | + update_option(InvalidCheckoutAccess::OPTION_KEY, array()); |
|
168 | 168 | } |
169 | 169 | } else { |
170 | 170 | \EE_Error::add_error( |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | ); |
179 | 179 | } |
180 | 180 | } else { |
181 | - if ( $invalid_checkout_access_form->submission_error_message() !== '' ) { |
|
181 | + if ($invalid_checkout_access_form->submission_error_message() !== '') { |
|
182 | 182 | \EE_Error::add_error( |
183 | 183 | $invalid_checkout_access_form->submission_error_message(), |
184 | 184 | __FILE__, |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | } |
189 | 189 | } |
190 | 190 | } |
191 | - } catch ( \EE_Error $e ) { |
|
191 | + } catch (\EE_Error $e) { |
|
192 | 192 | $e->get_error(); |
193 | 193 | } |
194 | 194 | return $EE_Registration_Config; |
@@ -370,7 +370,7 @@ |
||
370 | 370 | * with construction finalize being called later |
371 | 371 | * (realizing that the subsections' html names |
372 | 372 | * might not be set yet, etc.) |
373 | - * @return EE_Form_Section_Base |
|
373 | + * @return EE_Form_Section_Validatable|null |
|
374 | 374 | * @throws \EE_Error |
375 | 375 | */ |
376 | 376 | public function get_subsection($name, $require_construction_to_be_finalized = true) |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function __construct($options_array = array()) |
86 | 86 | { |
87 | - $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
87 | + $options_array = (array) apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
88 | 88 | $this); |
89 | 89 | //call parent first, as it may be setting the name |
90 | 90 | parent::__construct($options_array); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | if (isset($options_array['layout_strategy'])) { |
108 | 108 | $this->_layout_strategy = $options_array['layout_strategy']; |
109 | 109 | } |
110 | - if (! $this->_layout_strategy) { |
|
110 | + if ( ! $this->_layout_strategy) { |
|
111 | 111 | $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
112 | 112 | } |
113 | 113 | $this->_layout_strategy->_construct_finalize($this); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | if ($validate) { |
259 | 259 | $this->_validate(); |
260 | 260 | //if it's invalid, we're going to want to re-display so remember what they submitted |
261 | - if (! $this->is_valid()) { |
|
261 | + if ( ! $this->is_valid()) { |
|
262 | 262 | $this->store_submitted_form_data_in_session(); |
263 | 263 | } |
264 | 264 | } |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | public function get_input($name, $require_construction_to_be_finalized = true) |
439 | 439 | { |
440 | 440 | $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
441 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
441 | + if ( ! $subsection instanceof EE_Form_Input_Base) { |
|
442 | 442 | throw new EE_Error( |
443 | 443 | sprintf( |
444 | 444 | __( |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
474 | 474 | { |
475 | 475 | $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
476 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
476 | + if ( ! $subsection instanceof EE_Form_Section_Proper) { |
|
477 | 477 | throw new EE_Error( |
478 | 478 | sprintf( |
479 | 479 | __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | */ |
512 | 512 | public function is_valid() |
513 | 513 | { |
514 | - if (! $this->has_received_submission()) { |
|
514 | + if ( ! $this->has_received_submission()) { |
|
515 | 515 | throw new EE_Error( |
516 | 516 | sprintf( |
517 | 517 | __( |
@@ -521,14 +521,14 @@ discard block |
||
521 | 521 | ) |
522 | 522 | ); |
523 | 523 | } |
524 | - if (! parent::is_valid()) { |
|
524 | + if ( ! parent::is_valid()) { |
|
525 | 525 | return false; |
526 | 526 | } |
527 | 527 | // ok so no general errors to this entire form section. |
528 | 528 | // so let's check the subsections, but only set errors if that hasn't been done yet |
529 | 529 | $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
530 | 530 | foreach ($this->get_validatable_subsections() as $subsection) { |
531 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
531 | + if ( ! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
532 | 532 | if ($set_submission_errors) { |
533 | 533 | $this->set_submission_error_message($subsection->get_validation_error_string()); |
534 | 534 | } |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | */ |
548 | 548 | protected function _set_default_name_if_empty() |
549 | 549 | { |
550 | - if (! $this->_name) { |
|
550 | + if ( ! $this->_name) { |
|
551 | 551 | $classname = get_class($this); |
552 | 552 | $default_name = str_replace("EE_", "", $classname); |
553 | 553 | $this->_name = $default_name; |
@@ -632,7 +632,7 @@ discard block |
||
632 | 632 | { |
633 | 633 | wp_register_script( |
634 | 634 | 'ee_form_section_validation', |
635 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
635 | + EE_GLOBAL_ASSETS_URL.'scripts'.DS.'form_section_validation.js', |
|
636 | 636 | array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
637 | 637 | EVENT_ESPRESSO_VERSION, |
638 | 638 | true |
@@ -778,7 +778,7 @@ discard block |
||
778 | 778 | */ |
779 | 779 | public function ensure_scripts_localized() |
780 | 780 | { |
781 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
781 | + if ( ! EE_Form_Section_Proper::$_scripts_localized) { |
|
782 | 782 | $this->_enqueue_and_localize_form_js(); |
783 | 783 | } |
784 | 784 | } |
@@ -874,8 +874,8 @@ discard block |
||
874 | 874 | protected function _validate() |
875 | 875 | { |
876 | 876 | foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
877 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
878 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
877 | + if (method_exists($this, '_validate_'.$subsection_name)) { |
|
878 | + call_user_func_array(array($this, '_validate_'.$subsection_name), array($subsection)); |
|
879 | 879 | } |
880 | 880 | $subsection->_validate(); |
881 | 881 | } |
@@ -1151,7 +1151,7 @@ discard block |
||
1151 | 1151 | public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
1152 | 1152 | { |
1153 | 1153 | foreach ($new_subsections as $subsection_name => $subsection) { |
1154 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1154 | + if ( ! $subsection instanceof EE_Form_Section_Base) { |
|
1155 | 1155 | EE_Error::add_error( |
1156 | 1156 | sprintf( |
1157 | 1157 | __( |
@@ -1249,7 +1249,7 @@ discard block |
||
1249 | 1249 | public function html_name_prefix() |
1250 | 1250 | { |
1251 | 1251 | if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
1252 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1252 | + return $this->parent_section()->html_name_prefix().'['.$this->name().']'; |
|
1253 | 1253 | } else { |
1254 | 1254 | return $this->name(); |
1255 | 1255 | } |
@@ -1293,7 +1293,7 @@ discard block |
||
1293 | 1293 | */ |
1294 | 1294 | public function ensure_construct_finalized_called() |
1295 | 1295 | { |
1296 | - if (! $this->_construction_finalized) { |
|
1296 | + if ( ! $this->_construction_finalized) { |
|
1297 | 1297 | $this->_construct_finalize($this->_parent_section, $this->_name); |
1298 | 1298 | } |
1299 | 1299 | } |
@@ -11,1385 +11,1385 @@ |
||
11 | 11 | class EE_Form_Section_Proper extends EE_Form_Section_Validatable |
12 | 12 | { |
13 | 13 | |
14 | - const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
15 | - |
|
16 | - /** |
|
17 | - * Subsections |
|
18 | - * |
|
19 | - * @var EE_Form_Section_Validatable[] |
|
20 | - */ |
|
21 | - protected $_subsections = array(); |
|
22 | - |
|
23 | - /** |
|
24 | - * Strategy for laying out the form |
|
25 | - * |
|
26 | - * @var EE_Form_Section_Layout_Base |
|
27 | - */ |
|
28 | - protected $_layout_strategy; |
|
29 | - |
|
30 | - /** |
|
31 | - * Whether or not this form has received and validated a form submission yet |
|
32 | - * |
|
33 | - * @var boolean |
|
34 | - */ |
|
35 | - protected $_received_submission = false; |
|
36 | - |
|
37 | - /** |
|
38 | - * message displayed to users upon successful form submission |
|
39 | - * |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - protected $_form_submission_success_message = ''; |
|
43 | - |
|
44 | - /** |
|
45 | - * message displayed to users upon unsuccessful form submission |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - protected $_form_submission_error_message = ''; |
|
50 | - |
|
51 | - /** |
|
52 | - * Stores all the data that will localized for form validation |
|
53 | - * |
|
54 | - * @var array |
|
55 | - */ |
|
56 | - static protected $_js_localization = array(); |
|
57 | - |
|
58 | - /** |
|
59 | - * whether or not the form's localized validation JS vars have been set |
|
60 | - * |
|
61 | - * @type boolean |
|
62 | - */ |
|
63 | - static protected $_scripts_localized = false; |
|
64 | - |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * when constructing a proper form section, calls _construct_finalize on children |
|
69 | - * so that they know who their parent is, and what name they've been given. |
|
70 | - * |
|
71 | - * @param array $options_array { |
|
72 | - * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
73 | - * @type $include string[] numerically-indexed where values are section names to be included, |
|
74 | - * and in that order. This is handy if you want |
|
75 | - * the subsections to be ordered differently than the default, and if you override |
|
76 | - * which fields are shown |
|
77 | - * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
78 | - * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
79 | - * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
80 | - * items from that list of inclusions) |
|
81 | - * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
82 | - * } @see EE_Form_Section_Validatable::__construct() |
|
83 | - * @throws \EE_Error |
|
84 | - */ |
|
85 | - public function __construct($options_array = array()) |
|
86 | - { |
|
87 | - $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
88 | - $this); |
|
89 | - //call parent first, as it may be setting the name |
|
90 | - parent::__construct($options_array); |
|
91 | - //if they've included subsections in the constructor, add them now |
|
92 | - if (isset($options_array['include'])) { |
|
93 | - //we are going to make sure we ONLY have those subsections to include |
|
94 | - //AND we are going to make sure they're in that specified order |
|
95 | - $reordered_subsections = array(); |
|
96 | - foreach ($options_array['include'] as $input_name) { |
|
97 | - if (isset($this->_subsections[$input_name])) { |
|
98 | - $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
99 | - } |
|
100 | - } |
|
101 | - $this->_subsections = $reordered_subsections; |
|
102 | - } |
|
103 | - if (isset($options_array['exclude'])) { |
|
104 | - $exclude = $options_array['exclude']; |
|
105 | - $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
106 | - } |
|
107 | - if (isset($options_array['layout_strategy'])) { |
|
108 | - $this->_layout_strategy = $options_array['layout_strategy']; |
|
109 | - } |
|
110 | - if (! $this->_layout_strategy) { |
|
111 | - $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
112 | - } |
|
113 | - $this->_layout_strategy->_construct_finalize($this); |
|
114 | - //ok so we are definitely going to want the forms JS, |
|
115 | - //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
116 | - if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
117 | - //ok so they've constructed this object after when they should have. |
|
118 | - //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
119 | - \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
120 | - } else { |
|
121 | - add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
122 | - add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
123 | - } |
|
124 | - add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
125 | - |
|
126 | - /** |
|
127 | - * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't |
|
128 | - * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to |
|
129 | - * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
130 | - * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
131 | - * @since 4.9.32 |
|
132 | - * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling |
|
133 | - * _construct_finalize has been done |
|
134 | - * @param array $options_array options passed into the constructor |
|
135 | - */ |
|
136 | - do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array); |
|
137 | - |
|
138 | - if (isset($options_array['name'])) { |
|
139 | - $this->_construct_finalize(null, $options_array['name']); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * Finishes construction given the parent form section and this form section's name |
|
147 | - * |
|
148 | - * @param EE_Form_Section_Proper $parent_form_section |
|
149 | - * @param string $name |
|
150 | - * @throws \EE_Error |
|
151 | - */ |
|
152 | - public function _construct_finalize($parent_form_section, $name) |
|
153 | - { |
|
154 | - parent::_construct_finalize($parent_form_section, $name); |
|
155 | - $this->_set_default_name_if_empty(); |
|
156 | - $this->_set_default_html_id_if_empty(); |
|
157 | - foreach ($this->_subsections as $subsection_name => $subsection) { |
|
158 | - if ($subsection instanceof EE_Form_Section_Base) { |
|
159 | - $subsection->_construct_finalize($this, $subsection_name); |
|
160 | - } else { |
|
161 | - throw new EE_Error( |
|
162 | - sprintf( |
|
163 | - __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
164 | - 'event_espresso'), |
|
165 | - $subsection_name, |
|
166 | - get_class($this), |
|
167 | - $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
168 | - ) |
|
169 | - ); |
|
170 | - } |
|
171 | - } |
|
172 | - /** |
|
173 | - * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
174 | - * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived |
|
175 | - * from the name like the HTML label id, etc), this is where it should be done. |
|
176 | - * This might only happen just before displaying the form, or just before it receives form submission data. |
|
177 | - * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
178 | - * ensured it has a name, HTML IDs, etc |
|
179 | - * @param EE_Form_Section_Proper $this |
|
180 | - * @param EE_Form_Section_Proper|null $parent_form_section |
|
181 | - * @param string $name |
|
182 | - */ |
|
183 | - do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Gets the layout strategy for this form section |
|
190 | - * |
|
191 | - * @return EE_Form_Section_Layout_Base |
|
192 | - */ |
|
193 | - public function get_layout_strategy() |
|
194 | - { |
|
195 | - return $this->_layout_strategy; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Gets the HTML for a single input for this form section according |
|
202 | - * to the layout strategy |
|
203 | - * |
|
204 | - * @param EE_Form_Input_Base $input |
|
205 | - * @return string |
|
206 | - */ |
|
207 | - public function get_html_for_input($input) |
|
208 | - { |
|
209 | - return $this->_layout_strategy->layout_input($input); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * was_submitted - checks if form inputs are present in request data |
|
216 | - * Basically an alias for form_data_present_in() (which is used by both |
|
217 | - * proper form sections and form inputs) |
|
218 | - * |
|
219 | - * @param null $form_data |
|
220 | - * @return boolean |
|
221 | - */ |
|
222 | - public function was_submitted($form_data = null) |
|
223 | - { |
|
224 | - return $this->form_data_present_in($form_data); |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * After the form section is initially created, call this to sanitize the data in the submission |
|
231 | - * which relates to this form section, validate it, and set it as properties on the form. |
|
232 | - * |
|
233 | - * @param array|null $req_data should usually be $_POST (the default). |
|
234 | - * However, you CAN supply a different array. |
|
235 | - * Consider using set_defaults() instead however. |
|
236 | - * (If you rendered the form in the page using echo $form_x->get_html() |
|
237 | - * the inputs will have the correct name in the request data for this function |
|
238 | - * to find them and populate the form with them. |
|
239 | - * If you have a flat form (with only input subsections), |
|
240 | - * you can supply a flat array where keys |
|
241 | - * are the form input names and values are their values) |
|
242 | - * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
243 | - * of course, to validate that data, and set errors on the invalid values. |
|
244 | - * But if the data has already been validated |
|
245 | - * (eg you validated the data then stored it in the DB) |
|
246 | - * you may want to skip this step. |
|
247 | - */ |
|
248 | - public function receive_form_submission($req_data = null, $validate = true) |
|
249 | - { |
|
250 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
251 | - $validate); |
|
252 | - if ($req_data === null) { |
|
253 | - $req_data = array_merge($_GET, $_POST); |
|
254 | - } |
|
255 | - $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
256 | - $this); |
|
257 | - $this->_normalize($req_data); |
|
258 | - if ($validate) { |
|
259 | - $this->_validate(); |
|
260 | - //if it's invalid, we're going to want to re-display so remember what they submitted |
|
261 | - if (! $this->is_valid()) { |
|
262 | - $this->store_submitted_form_data_in_session(); |
|
263 | - } |
|
264 | - } |
|
265 | - do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * caches the originally submitted input values in the session |
|
272 | - * so that they can be used to repopulate the form if it failed validation |
|
273 | - * |
|
274 | - * @return boolean whether or not the data was successfully stored in the session |
|
275 | - */ |
|
276 | - protected function store_submitted_form_data_in_session() |
|
277 | - { |
|
278 | - return EE_Registry::instance()->SSN->set_session_data( |
|
279 | - array( |
|
280 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
281 | - ) |
|
282 | - ); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * retrieves the originally submitted input values in the session |
|
289 | - * so that they can be used to repopulate the form if it failed validation |
|
290 | - * |
|
291 | - * @return array |
|
292 | - */ |
|
293 | - protected function get_submitted_form_data_from_session() |
|
294 | - { |
|
295 | - $session = EE_Registry::instance()->SSN; |
|
296 | - if ($session instanceof EE_Session) { |
|
297 | - return $session->get_session_data( |
|
298 | - \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
299 | - ); |
|
300 | - } else { |
|
301 | - return array(); |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * flushed the originally submitted input values from the session |
|
309 | - * |
|
310 | - * @return boolean whether or not the data was successfully removed from the session |
|
311 | - */ |
|
312 | - protected function flush_submitted_form_data_from_session() |
|
313 | - { |
|
314 | - return EE_Registry::instance()->SSN->reset_data( |
|
315 | - array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
316 | - ); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * Populates this form and its subsections with data from the session. |
|
323 | - * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
324 | - * validation errors when displaying too) |
|
325 | - * Returns true if the form was populated from the session, false otherwise |
|
326 | - * |
|
327 | - * @return boolean |
|
328 | - */ |
|
329 | - public function populate_from_session() |
|
330 | - { |
|
331 | - $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
332 | - if (empty($form_data_in_session)) { |
|
333 | - return false; |
|
334 | - } |
|
335 | - $this->receive_form_submission($form_data_in_session); |
|
336 | - $this->flush_submitted_form_data_from_session(); |
|
337 | - if ($this->form_data_present_in($form_data_in_session)) { |
|
338 | - return true; |
|
339 | - } else { |
|
340 | - return false; |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * Populates the default data for the form, given an array where keys are |
|
348 | - * the input names, and values are their values (preferably normalized to be their |
|
349 | - * proper PHP types, not all strings... although that should be ok too). |
|
350 | - * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
351 | - * the value being an array formatted in teh same way |
|
352 | - * |
|
353 | - * @param array $default_data |
|
354 | - */ |
|
355 | - public function populate_defaults($default_data) |
|
356 | - { |
|
357 | - foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
358 | - if (isset($default_data[$subsection_name])) { |
|
359 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
360 | - $subsection->set_default($default_data[$subsection_name]); |
|
361 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
362 | - $subsection->populate_defaults($default_data[$subsection_name]); |
|
363 | - } |
|
364 | - } |
|
365 | - } |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * returns true if subsection exists |
|
372 | - * |
|
373 | - * @param string $name |
|
374 | - * @return boolean |
|
375 | - */ |
|
376 | - public function subsection_exists($name) |
|
377 | - { |
|
378 | - return isset($this->_subsections[$name]) ? true : false; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * Gets the subsection specified by its name |
|
385 | - * |
|
386 | - * @param string $name |
|
387 | - * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
388 | - * so that the inputs will be properly configured. |
|
389 | - * However, some client code may be ok |
|
390 | - * with construction finalize being called later |
|
391 | - * (realizing that the subsections' html names |
|
392 | - * might not be set yet, etc.) |
|
393 | - * @return EE_Form_Section_Base |
|
394 | - * @throws \EE_Error |
|
395 | - */ |
|
396 | - public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
397 | - { |
|
398 | - if ($require_construction_to_be_finalized) { |
|
399 | - $this->ensure_construct_finalized_called(); |
|
400 | - } |
|
401 | - return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * Gets all the validatable subsections of this form section |
|
408 | - * |
|
409 | - * @return EE_Form_Section_Validatable[] |
|
410 | - */ |
|
411 | - public function get_validatable_subsections() |
|
412 | - { |
|
413 | - $validatable_subsections = array(); |
|
414 | - foreach ($this->subsections() as $name => $obj) { |
|
415 | - if ($obj instanceof EE_Form_Section_Validatable) { |
|
416 | - $validatable_subsections[$name] = $obj; |
|
417 | - } |
|
418 | - } |
|
419 | - return $validatable_subsections; |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
426 | - * throw an EE_Error. |
|
427 | - * |
|
428 | - * @param string $name |
|
429 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
430 | - * leave this as TRUE so that the inputs will be properly |
|
431 | - * configured. However, some client code may be ok with |
|
432 | - * construction finalize being called later |
|
433 | - * (realizing that the subsections' html names might not be |
|
434 | - * set yet, etc.) |
|
435 | - * @return EE_Form_Input_Base |
|
436 | - * @throws EE_Error |
|
437 | - */ |
|
438 | - public function get_input($name, $require_construction_to_be_finalized = true) |
|
439 | - { |
|
440 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
441 | - if (! $subsection instanceof EE_Form_Input_Base) { |
|
442 | - throw new EE_Error( |
|
443 | - sprintf( |
|
444 | - __( |
|
445 | - "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
446 | - 'event_espresso' |
|
447 | - ), |
|
448 | - $name, |
|
449 | - get_class($this), |
|
450 | - $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
451 | - ) |
|
452 | - ); |
|
453 | - } |
|
454 | - return $subsection; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Like get_input(), gets the proper subsection of the form given the name, |
|
461 | - * otherwise throws an EE_Error |
|
462 | - * |
|
463 | - * @param string $name |
|
464 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
465 | - * leave this as TRUE so that the inputs will be properly |
|
466 | - * configured. However, some client code may be ok with |
|
467 | - * construction finalize being called later |
|
468 | - * (realizing that the subsections' html names might not be |
|
469 | - * set yet, etc.) |
|
470 | - * @return EE_Form_Section_Proper |
|
471 | - * @throws EE_Error |
|
472 | - */ |
|
473 | - public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
474 | - { |
|
475 | - $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
476 | - if (! $subsection instanceof EE_Form_Section_Proper) { |
|
477 | - throw new EE_Error( |
|
478 | - sprintf( |
|
479 | - __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
480 | - $name, |
|
481 | - get_class($this) |
|
482 | - ) |
|
483 | - ); |
|
484 | - } |
|
485 | - return $subsection; |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * Gets the value of the specified input. Should be called after receive_form_submission() |
|
492 | - * or populate_defaults() on the form, where the normalized value on the input is set. |
|
493 | - * |
|
494 | - * @param string $name |
|
495 | - * @return mixed depending on the input's type and its normalization strategy |
|
496 | - * @throws \EE_Error |
|
497 | - */ |
|
498 | - public function get_input_value($name) |
|
499 | - { |
|
500 | - $input = $this->get_input($name); |
|
501 | - return $input->normalized_value(); |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * Checks if this form section itself is valid, and then checks its subsections |
|
508 | - * |
|
509 | - * @throws EE_Error |
|
510 | - * @return boolean |
|
511 | - */ |
|
512 | - public function is_valid() |
|
513 | - { |
|
514 | - if (! $this->has_received_submission()) { |
|
515 | - throw new EE_Error( |
|
516 | - sprintf( |
|
517 | - __( |
|
518 | - "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
519 | - "event_espresso" |
|
520 | - ) |
|
521 | - ) |
|
522 | - ); |
|
523 | - } |
|
524 | - if (! parent::is_valid()) { |
|
525 | - return false; |
|
526 | - } |
|
527 | - // ok so no general errors to this entire form section. |
|
528 | - // so let's check the subsections, but only set errors if that hasn't been done yet |
|
529 | - $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
530 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
531 | - if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
532 | - if ($set_submission_errors) { |
|
533 | - $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
534 | - } |
|
535 | - return false; |
|
536 | - } |
|
537 | - } |
|
538 | - return true; |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - /** |
|
544 | - * gets teh default name of this form section if none is specified |
|
545 | - * |
|
546 | - * @return string |
|
547 | - */ |
|
548 | - protected function _set_default_name_if_empty() |
|
549 | - { |
|
550 | - if (! $this->_name) { |
|
551 | - $classname = get_class($this); |
|
552 | - $default_name = str_replace("EE_", "", $classname); |
|
553 | - $this->_name = $default_name; |
|
554 | - } |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - |
|
559 | - /** |
|
560 | - * Returns the HTML for the form, except for the form opening and closing tags |
|
561 | - * (as the form section doesn't know where you necessarily want to send the information to), |
|
562 | - * and except for a submit button. Enqueus JS and CSS; if called early enough we will |
|
563 | - * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
564 | - * Not doing_it_wrong because theoretically this CAN be used properly, |
|
565 | - * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
566 | - * any CSS. |
|
567 | - * |
|
568 | - * @throws \EE_Error |
|
569 | - */ |
|
570 | - public function get_html_and_js() |
|
571 | - { |
|
572 | - $this->enqueue_js(); |
|
573 | - return $this->get_html(); |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
580 | - * |
|
581 | - * @param bool $display_previously_submitted_data |
|
582 | - * @return string |
|
583 | - */ |
|
584 | - public function get_html($display_previously_submitted_data = true) |
|
585 | - { |
|
586 | - $this->ensure_construct_finalized_called(); |
|
587 | - if ($display_previously_submitted_data) { |
|
588 | - $this->populate_from_session(); |
|
589 | - } |
|
590 | - return $this->_form_html_filter |
|
591 | - ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
592 | - : $this->_layout_strategy->layout_form(); |
|
593 | - } |
|
594 | - |
|
595 | - |
|
596 | - |
|
597 | - /** |
|
598 | - * enqueues JS and CSS for the form. |
|
599 | - * It is preferred to call this before wp_enqueue_scripts so the |
|
600 | - * scripts and styles can be put in the header, but if called later |
|
601 | - * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
602 | - * only be in the header; but in HTML5 its ok in the body. |
|
603 | - * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
604 | - * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
605 | - * |
|
606 | - * @return string |
|
607 | - * @throws \EE_Error |
|
608 | - */ |
|
609 | - public function enqueue_js() |
|
610 | - { |
|
611 | - $this->_enqueue_and_localize_form_js(); |
|
612 | - foreach ($this->subsections() as $subsection) { |
|
613 | - $subsection->enqueue_js(); |
|
614 | - } |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - |
|
619 | - /** |
|
620 | - * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
621 | - * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
622 | - * the wp_enqueue_scripts hook. |
|
623 | - * However, registering the form js and localizing it can happen when we |
|
624 | - * actually output the form (which is preferred, seeing how teh form's fields |
|
625 | - * could change until it's actually outputted) |
|
626 | - * |
|
627 | - * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
628 | - * to be triggered automatically or not |
|
629 | - * @return void |
|
630 | - */ |
|
631 | - public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
632 | - { |
|
633 | - wp_register_script( |
|
634 | - 'ee_form_section_validation', |
|
635 | - EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
636 | - array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
637 | - EVENT_ESPRESSO_VERSION, |
|
638 | - true |
|
639 | - ); |
|
640 | - wp_localize_script( |
|
641 | - 'ee_form_section_validation', |
|
642 | - 'ee_form_section_validation_init', |
|
643 | - array('init' => $init_form_validation_automatically ? '1' : '0') |
|
644 | - ); |
|
645 | - } |
|
646 | - |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * gets the variables used by form_section_validation.js. |
|
651 | - * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
652 | - * but before the wordpress hook wp_loaded |
|
653 | - * |
|
654 | - * @throws \EE_Error |
|
655 | - */ |
|
656 | - public function _enqueue_and_localize_form_js() |
|
657 | - { |
|
658 | - $this->ensure_construct_finalized_called(); |
|
659 | - //actually, we don't want to localize just yet. There may be other forms on the page. |
|
660 | - //so we need to add our form section data to a static variable accessible by all form sections |
|
661 | - //and localize it just before the footer |
|
662 | - $this->localize_validation_rules(); |
|
663 | - add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
664 | - add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
665 | - } |
|
666 | - |
|
667 | - |
|
668 | - |
|
669 | - /** |
|
670 | - * add our form section data to a static variable accessible by all form sections |
|
671 | - * |
|
672 | - * @param bool $return_for_subsection |
|
673 | - * @return void |
|
674 | - * @throws \EE_Error |
|
675 | - */ |
|
676 | - public function localize_validation_rules($return_for_subsection = false) |
|
677 | - { |
|
678 | - // we only want to localize vars ONCE for the entire form, |
|
679 | - // so if the form section doesn't have a parent, then it must be the top dog |
|
680 | - if ($return_for_subsection || ! $this->parent_section()) { |
|
681 | - EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
682 | - 'form_section_id' => $this->html_id(true), |
|
683 | - 'validation_rules' => $this->get_jquery_validation_rules(), |
|
684 | - 'other_data' => $this->get_other_js_data(), |
|
685 | - 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
686 | - ); |
|
687 | - EE_Form_Section_Proper::$_scripts_localized = true; |
|
688 | - } |
|
689 | - } |
|
690 | - |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * Gets an array of extra data that will be useful for client-side javascript. |
|
695 | - * This is primarily data added by inputs and forms in addition to any |
|
696 | - * scripts they might enqueue |
|
697 | - * |
|
698 | - * @param array $form_other_js_data |
|
699 | - * @return array |
|
700 | - */ |
|
701 | - public function get_other_js_data($form_other_js_data = array()) |
|
702 | - { |
|
703 | - foreach ($this->subsections() as $subsection) { |
|
704 | - $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
705 | - } |
|
706 | - return $form_other_js_data; |
|
707 | - } |
|
708 | - |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * Gets a flat array of inputs for this form section and its subsections. |
|
713 | - * Keys are their form names, and values are the inputs themselves |
|
714 | - * |
|
715 | - * @return EE_Form_Input_Base |
|
716 | - */ |
|
717 | - public function inputs_in_subsections() |
|
718 | - { |
|
719 | - $inputs = array(); |
|
720 | - foreach ($this->subsections() as $subsection) { |
|
721 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
722 | - $inputs[$subsection->html_name()] = $subsection; |
|
723 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
724 | - $inputs += $subsection->inputs_in_subsections(); |
|
725 | - } |
|
726 | - } |
|
727 | - return $inputs; |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - |
|
732 | - /** |
|
733 | - * Gets a flat array of all the validation errors. |
|
734 | - * Keys are html names (because those should be unique) |
|
735 | - * and values are a string of all their validation errors |
|
736 | - * |
|
737 | - * @return string[] |
|
738 | - */ |
|
739 | - public function subsection_validation_errors_by_html_name() |
|
740 | - { |
|
741 | - $inputs = $this->inputs(); |
|
742 | - $errors = array(); |
|
743 | - foreach ($inputs as $form_input) { |
|
744 | - if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
745 | - $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
746 | - } |
|
747 | - } |
|
748 | - return $errors; |
|
749 | - } |
|
750 | - |
|
751 | - |
|
752 | - |
|
753 | - /** |
|
754 | - * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
755 | - * Should be setup by each form during the _enqueues_and_localize_form_js |
|
756 | - */ |
|
757 | - public static function localize_script_for_all_forms() |
|
758 | - { |
|
759 | - //allow inputs and stuff to hook in their JS and stuff here |
|
760 | - do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
761 | - EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
762 | - $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
763 | - ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
764 | - : 'wp_default'; |
|
765 | - EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
766 | - wp_enqueue_script('ee_form_section_validation'); |
|
767 | - wp_localize_script( |
|
768 | - 'ee_form_section_validation', |
|
769 | - 'ee_form_section_vars', |
|
770 | - EE_Form_Section_Proper::$_js_localization |
|
771 | - ); |
|
772 | - } |
|
773 | - |
|
774 | - |
|
775 | - |
|
776 | - /** |
|
777 | - * ensure_scripts_localized |
|
778 | - */ |
|
779 | - public function ensure_scripts_localized() |
|
780 | - { |
|
781 | - if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
782 | - $this->_enqueue_and_localize_form_js(); |
|
783 | - } |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - |
|
788 | - /** |
|
789 | - * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
790 | - * is that the key here should be the same as the custom validation rule put in the JS file |
|
791 | - * |
|
792 | - * @return array keys are custom validation rules, and values are internationalized strings |
|
793 | - */ |
|
794 | - private static function _get_localized_error_messages() |
|
795 | - { |
|
796 | - return array( |
|
797 | - 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
798 | - 'regex' => __('Please check your input', 'event_espresso'), |
|
799 | - ); |
|
800 | - } |
|
801 | - |
|
802 | - |
|
803 | - |
|
804 | - /** |
|
805 | - * @return array |
|
806 | - */ |
|
807 | - public static function js_localization() |
|
808 | - { |
|
809 | - return self::$_js_localization; |
|
810 | - } |
|
811 | - |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * @return array |
|
816 | - */ |
|
817 | - public static function reset_js_localization() |
|
818 | - { |
|
819 | - self::$_js_localization = array(); |
|
820 | - } |
|
821 | - |
|
822 | - |
|
823 | - |
|
824 | - /** |
|
825 | - * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
826 | - * See parent function for more... |
|
827 | - * |
|
828 | - * @return array |
|
829 | - */ |
|
830 | - public function get_jquery_validation_rules() |
|
831 | - { |
|
832 | - $jquery_validation_rules = array(); |
|
833 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
834 | - $jquery_validation_rules = array_merge( |
|
835 | - $jquery_validation_rules, |
|
836 | - $subsection->get_jquery_validation_rules() |
|
837 | - ); |
|
838 | - } |
|
839 | - return $jquery_validation_rules; |
|
840 | - } |
|
841 | - |
|
842 | - |
|
843 | - |
|
844 | - /** |
|
845 | - * Sanitizes all the data and sets the sanitized value of each field |
|
846 | - * |
|
847 | - * @param array $req_data like $_POST |
|
848 | - * @return void |
|
849 | - */ |
|
850 | - protected function _normalize($req_data) |
|
851 | - { |
|
852 | - $this->_received_submission = true; |
|
853 | - $this->_validation_errors = array(); |
|
854 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
855 | - try { |
|
856 | - $subsection->_normalize($req_data); |
|
857 | - } catch (EE_Validation_Error $e) { |
|
858 | - $subsection->add_validation_error($e); |
|
859 | - } |
|
860 | - } |
|
861 | - } |
|
862 | - |
|
863 | - |
|
864 | - |
|
865 | - /** |
|
866 | - * Performs validation on this form section and its subsections. |
|
867 | - * For each subsection, |
|
868 | - * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
869 | - * and passes it the subsection, then calls _validate on that subsection. |
|
870 | - * If you need to perform validation on the form as a whole (considering multiple) |
|
871 | - * you would be best to override this _validate method, |
|
872 | - * calling parent::_validate() first. |
|
873 | - */ |
|
874 | - protected function _validate() |
|
875 | - { |
|
876 | - foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
877 | - if (method_exists($this, '_validate_' . $subsection_name)) { |
|
878 | - call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
879 | - } |
|
880 | - $subsection->_validate(); |
|
881 | - } |
|
882 | - } |
|
883 | - |
|
884 | - |
|
885 | - |
|
886 | - /** |
|
887 | - * Gets all the validated inputs for the form section |
|
888 | - * |
|
889 | - * @return array |
|
890 | - */ |
|
891 | - public function valid_data() |
|
892 | - { |
|
893 | - $inputs = array(); |
|
894 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
895 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
896 | - $inputs[$subsection_name] = $subsection->valid_data(); |
|
897 | - } else if ($subsection instanceof EE_Form_Input_Base) { |
|
898 | - $inputs[$subsection_name] = $subsection->normalized_value(); |
|
899 | - } |
|
900 | - } |
|
901 | - return $inputs; |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - |
|
906 | - /** |
|
907 | - * Gets all the inputs on this form section |
|
908 | - * |
|
909 | - * @return EE_Form_Input_Base[] |
|
910 | - */ |
|
911 | - public function inputs() |
|
912 | - { |
|
913 | - $inputs = array(); |
|
914 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
915 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
916 | - $inputs[$subsection_name] = $subsection; |
|
917 | - } |
|
918 | - } |
|
919 | - return $inputs; |
|
920 | - } |
|
921 | - |
|
922 | - |
|
923 | - |
|
924 | - /** |
|
925 | - * Gets all the subsections which are a proper form |
|
926 | - * |
|
927 | - * @return EE_Form_Section_Proper[] |
|
928 | - */ |
|
929 | - public function subforms() |
|
930 | - { |
|
931 | - $form_sections = array(); |
|
932 | - foreach ($this->subsections() as $name => $obj) { |
|
933 | - if ($obj instanceof EE_Form_Section_Proper) { |
|
934 | - $form_sections[$name] = $obj; |
|
935 | - } |
|
936 | - } |
|
937 | - return $form_sections; |
|
938 | - } |
|
939 | - |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
944 | - * Consider using inputs() or subforms() |
|
945 | - * if you only want form inputs or proper form sections. |
|
946 | - * |
|
947 | - * @param boolean $require_construction_to_be_finalized most client code should |
|
948 | - * leave this as TRUE so that the inputs will be properly |
|
949 | - * configured. However, some client code may be ok with |
|
950 | - * construction finalize being called later |
|
951 | - * (realizing that the subsections' html names might not be |
|
952 | - * set yet, etc.) |
|
953 | - * @return EE_Form_Section_Proper[] |
|
954 | - */ |
|
955 | - public function subsections($require_construction_to_be_finalized = true) |
|
956 | - { |
|
957 | - if ($require_construction_to_be_finalized) { |
|
958 | - $this->ensure_construct_finalized_called(); |
|
959 | - } |
|
960 | - return $this->_subsections; |
|
961 | - } |
|
962 | - |
|
963 | - |
|
964 | - |
|
965 | - /** |
|
966 | - * Returns a simple array where keys are input names, and values are their normalized |
|
967 | - * values. (Similar to calling get_input_value on inputs) |
|
968 | - * |
|
969 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
970 | - * or just this forms' direct children inputs |
|
971 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
972 | - * or allow multidimensional array |
|
973 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
974 | - * with array keys being input names |
|
975 | - * (regardless of whether they are from a subsection or not), |
|
976 | - * and if $flatten is FALSE it can be a multidimensional array |
|
977 | - * where keys are always subsection names and values are either |
|
978 | - * the input's normalized value, or an array like the top-level array |
|
979 | - */ |
|
980 | - public function input_values($include_subform_inputs = false, $flatten = false) |
|
981 | - { |
|
982 | - return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
983 | - } |
|
984 | - |
|
985 | - |
|
986 | - |
|
987 | - /** |
|
988 | - * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
989 | - * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
990 | - * is not necessarily the value we want to display to users. This creates an array |
|
991 | - * where keys are the input names, and values are their display values |
|
992 | - * |
|
993 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
994 | - * or just this forms' direct children inputs |
|
995 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
996 | - * or allow multidimensional array |
|
997 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
998 | - * with array keys being input names |
|
999 | - * (regardless of whether they are from a subsection or not), |
|
1000 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1001 | - * where keys are always subsection names and values are either |
|
1002 | - * the input's normalized value, or an array like the top-level array |
|
1003 | - */ |
|
1004 | - public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1005 | - { |
|
1006 | - return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1007 | - } |
|
1008 | - |
|
1009 | - |
|
1010 | - |
|
1011 | - /** |
|
1012 | - * Gets the input values from the form |
|
1013 | - * |
|
1014 | - * @param boolean $pretty Whether to retrieve the pretty value, |
|
1015 | - * or just the normalized value |
|
1016 | - * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1017 | - * or just this forms' direct children inputs |
|
1018 | - * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1019 | - * or allow multidimensional array |
|
1020 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1021 | - * input names (regardless of whether they are from a subsection or not), |
|
1022 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1023 | - * where keys are always subsection names and values are either |
|
1024 | - * the input's normalized value, or an array like the top-level array |
|
1025 | - */ |
|
1026 | - public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1027 | - { |
|
1028 | - $input_values = array(); |
|
1029 | - foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1030 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1031 | - $input_values[$subsection_name] = $pretty |
|
1032 | - ? $subsection->pretty_value() |
|
1033 | - : $subsection->normalized_value(); |
|
1034 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1035 | - $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
1036 | - if ($flatten) { |
|
1037 | - $input_values = array_merge($input_values, $subform_input_values); |
|
1038 | - } else { |
|
1039 | - $input_values[$subsection_name] = $subform_input_values; |
|
1040 | - } |
|
1041 | - } |
|
1042 | - } |
|
1043 | - return $input_values; |
|
1044 | - } |
|
1045 | - |
|
1046 | - |
|
1047 | - |
|
1048 | - /** |
|
1049 | - * Gets the originally submitted input values from the form |
|
1050 | - * |
|
1051 | - * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1052 | - * or just this forms' direct children inputs |
|
1053 | - * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1054 | - * with array keys being input names |
|
1055 | - * (regardless of whether they are from a subsection or not), |
|
1056 | - * and if $flatten is FALSE it can be a multidimensional array |
|
1057 | - * where keys are always subsection names and values are either |
|
1058 | - * the input's normalized value, or an array like the top-level array |
|
1059 | - */ |
|
1060 | - public function submitted_values($include_subforms = false) |
|
1061 | - { |
|
1062 | - $submitted_values = array(); |
|
1063 | - foreach ($this->subsections() as $subsection) { |
|
1064 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1065 | - // is this input part of an array of inputs? |
|
1066 | - if (strpos($subsection->html_name(), '[') !== false) { |
|
1067 | - $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
1068 | - explode('[', str_replace(']', '', $subsection->html_name())), |
|
1069 | - $subsection->raw_value() |
|
1070 | - ); |
|
1071 | - $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1072 | - } else { |
|
1073 | - $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
1074 | - } |
|
1075 | - } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1076 | - $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1077 | - $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1078 | - } |
|
1079 | - } |
|
1080 | - return $submitted_values; |
|
1081 | - } |
|
1082 | - |
|
1083 | - |
|
1084 | - |
|
1085 | - /** |
|
1086 | - * Indicates whether or not this form has received a submission yet |
|
1087 | - * (ie, had receive_form_submission called on it yet) |
|
1088 | - * |
|
1089 | - * @return boolean |
|
1090 | - * @throws \EE_Error |
|
1091 | - */ |
|
1092 | - public function has_received_submission() |
|
1093 | - { |
|
1094 | - $this->ensure_construct_finalized_called(); |
|
1095 | - return $this->_received_submission; |
|
1096 | - } |
|
1097 | - |
|
1098 | - |
|
1099 | - |
|
1100 | - /** |
|
1101 | - * Equivalent to passing 'exclude' in the constructor's options array. |
|
1102 | - * Removes the listed inputs from the form |
|
1103 | - * |
|
1104 | - * @param array $inputs_to_exclude values are the input names |
|
1105 | - * @return void |
|
1106 | - */ |
|
1107 | - public function exclude(array $inputs_to_exclude = array()) |
|
1108 | - { |
|
1109 | - foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1110 | - unset($this->_subsections[$input_to_exclude_name]); |
|
1111 | - } |
|
1112 | - } |
|
1113 | - |
|
1114 | - |
|
1115 | - |
|
1116 | - /** |
|
1117 | - * @param array $inputs_to_hide |
|
1118 | - * @throws \EE_Error |
|
1119 | - */ |
|
1120 | - public function hide(array $inputs_to_hide = array()) |
|
1121 | - { |
|
1122 | - foreach ($inputs_to_hide as $input_to_hide) { |
|
1123 | - $input = $this->get_input($input_to_hide); |
|
1124 | - $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1125 | - } |
|
1126 | - } |
|
1127 | - |
|
1128 | - |
|
1129 | - |
|
1130 | - /** |
|
1131 | - * add_subsections |
|
1132 | - * Adds the listed subsections to the form section. |
|
1133 | - * If $subsection_name_to_target is provided, |
|
1134 | - * then new subsections are added before or after that subsection, |
|
1135 | - * otherwise to the start or end of the entire subsections array. |
|
1136 | - * |
|
1137 | - * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1138 | - * where keys are their names |
|
1139 | - * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1140 | - * should be added before or after |
|
1141 | - * IF $subsection_name_to_target is null, |
|
1142 | - * then $new_subsections will be added to |
|
1143 | - * the beginning or end of the entire subsections array |
|
1144 | - * @param boolean $add_before whether to add $new_subsections, before or after |
|
1145 | - * $subsection_name_to_target, |
|
1146 | - * or if $subsection_name_to_target is null, |
|
1147 | - * before or after entire subsections array |
|
1148 | - * @return void |
|
1149 | - * @throws \EE_Error |
|
1150 | - */ |
|
1151 | - public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1152 | - { |
|
1153 | - foreach ($new_subsections as $subsection_name => $subsection) { |
|
1154 | - if (! $subsection instanceof EE_Form_Section_Base) { |
|
1155 | - EE_Error::add_error( |
|
1156 | - sprintf( |
|
1157 | - __( |
|
1158 | - "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1159 | - "event_espresso" |
|
1160 | - ), |
|
1161 | - get_class($subsection), |
|
1162 | - $subsection_name, |
|
1163 | - $this->name() |
|
1164 | - ) |
|
1165 | - ); |
|
1166 | - unset($new_subsections[$subsection_name]); |
|
1167 | - } |
|
1168 | - } |
|
1169 | - $this->_subsections = EEH_Array::insert_into_array( |
|
1170 | - $this->_subsections, |
|
1171 | - $new_subsections, |
|
1172 | - $subsection_name_to_target, |
|
1173 | - $add_before |
|
1174 | - ); |
|
1175 | - if ($this->_construction_finalized) { |
|
1176 | - foreach ($this->_subsections as $name => $subsection) { |
|
1177 | - $subsection->_construct_finalize($this, $name); |
|
1178 | - } |
|
1179 | - } |
|
1180 | - } |
|
1181 | - |
|
1182 | - |
|
1183 | - |
|
1184 | - /** |
|
1185 | - * Just gets all validatable subsections to clean their sensitive data |
|
1186 | - */ |
|
1187 | - public function clean_sensitive_data() |
|
1188 | - { |
|
1189 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1190 | - $subsection->clean_sensitive_data(); |
|
1191 | - } |
|
1192 | - } |
|
1193 | - |
|
1194 | - |
|
1195 | - |
|
1196 | - /** |
|
1197 | - * @param string $form_submission_error_message |
|
1198 | - */ |
|
1199 | - public function set_submission_error_message($form_submission_error_message = '') |
|
1200 | - { |
|
1201 | - $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
1202 | - ? $form_submission_error_message |
|
1203 | - : __('Form submission failed due to errors', 'event_espresso'); |
|
1204 | - } |
|
1205 | - |
|
1206 | - |
|
1207 | - |
|
1208 | - /** |
|
1209 | - * @return string |
|
1210 | - */ |
|
1211 | - public function submission_error_message() |
|
1212 | - { |
|
1213 | - return $this->_form_submission_error_message; |
|
1214 | - } |
|
1215 | - |
|
1216 | - |
|
1217 | - |
|
1218 | - /** |
|
1219 | - * @param string $form_submission_success_message |
|
1220 | - */ |
|
1221 | - public function set_submission_success_message($form_submission_success_message) |
|
1222 | - { |
|
1223 | - $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
1224 | - ? $form_submission_success_message |
|
1225 | - : __('Form submitted successfully', 'event_espresso'); |
|
1226 | - } |
|
1227 | - |
|
1228 | - |
|
1229 | - |
|
1230 | - /** |
|
1231 | - * @return string |
|
1232 | - */ |
|
1233 | - public function submission_success_message() |
|
1234 | - { |
|
1235 | - return $this->_form_submission_success_message; |
|
1236 | - } |
|
1237 | - |
|
1238 | - |
|
1239 | - |
|
1240 | - /** |
|
1241 | - * Returns the prefix that should be used on child of this form section for |
|
1242 | - * their html names. If this form section itself has a parent, prepends ITS |
|
1243 | - * prefix onto this form section's prefix. Used primarily by |
|
1244 | - * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1245 | - * |
|
1246 | - * @return string |
|
1247 | - * @throws \EE_Error |
|
1248 | - */ |
|
1249 | - public function html_name_prefix() |
|
1250 | - { |
|
1251 | - if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1252 | - return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1253 | - } else { |
|
1254 | - return $this->name(); |
|
1255 | - } |
|
1256 | - } |
|
1257 | - |
|
1258 | - |
|
1259 | - |
|
1260 | - /** |
|
1261 | - * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1262 | - * calls it (assumes there is no parent and that we want the name to be whatever |
|
1263 | - * was set, which is probably nothing, or the classname) |
|
1264 | - * |
|
1265 | - * @return string |
|
1266 | - * @throws \EE_Error |
|
1267 | - */ |
|
1268 | - public function name() |
|
1269 | - { |
|
1270 | - $this->ensure_construct_finalized_called(); |
|
1271 | - return parent::name(); |
|
1272 | - } |
|
1273 | - |
|
1274 | - |
|
1275 | - |
|
1276 | - /** |
|
1277 | - * @return EE_Form_Section_Proper |
|
1278 | - * @throws \EE_Error |
|
1279 | - */ |
|
1280 | - public function parent_section() |
|
1281 | - { |
|
1282 | - $this->ensure_construct_finalized_called(); |
|
1283 | - return parent::parent_section(); |
|
1284 | - } |
|
1285 | - |
|
1286 | - |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * make sure construction finalized was called, otherwise children might not be ready |
|
1290 | - * |
|
1291 | - * @return void |
|
1292 | - * @throws \EE_Error |
|
1293 | - */ |
|
1294 | - public function ensure_construct_finalized_called() |
|
1295 | - { |
|
1296 | - if (! $this->_construction_finalized) { |
|
1297 | - $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1298 | - } |
|
1299 | - } |
|
1300 | - |
|
1301 | - |
|
1302 | - |
|
1303 | - /** |
|
1304 | - * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1305 | - * are in teh form data. If any are found, returns true. Else false |
|
1306 | - * |
|
1307 | - * @param array $req_data |
|
1308 | - * @return boolean |
|
1309 | - */ |
|
1310 | - public function form_data_present_in($req_data = null) |
|
1311 | - { |
|
1312 | - if ($req_data === null) { |
|
1313 | - $req_data = $_POST; |
|
1314 | - } |
|
1315 | - foreach ($this->subsections() as $subsection) { |
|
1316 | - if ($subsection instanceof EE_Form_Input_Base) { |
|
1317 | - if ($subsection->form_data_present_in($req_data)) { |
|
1318 | - return true; |
|
1319 | - } |
|
1320 | - } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1321 | - if ($subsection->form_data_present_in($req_data)) { |
|
1322 | - return true; |
|
1323 | - } |
|
1324 | - } |
|
1325 | - } |
|
1326 | - return false; |
|
1327 | - } |
|
1328 | - |
|
1329 | - |
|
1330 | - |
|
1331 | - /** |
|
1332 | - * Gets validation errors for this form section and subsections |
|
1333 | - * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1334 | - * gets the validation errors for ALL subsection |
|
1335 | - * |
|
1336 | - * @return EE_Validation_Error[] |
|
1337 | - */ |
|
1338 | - public function get_validation_errors_accumulated() |
|
1339 | - { |
|
1340 | - $validation_errors = $this->get_validation_errors(); |
|
1341 | - foreach ($this->get_validatable_subsections() as $subsection) { |
|
1342 | - if ($subsection instanceof EE_Form_Section_Proper) { |
|
1343 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1344 | - } else { |
|
1345 | - $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1346 | - } |
|
1347 | - if ($validation_errors_on_this_subsection) { |
|
1348 | - $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1349 | - } |
|
1350 | - } |
|
1351 | - return $validation_errors; |
|
1352 | - } |
|
1353 | - |
|
1354 | - |
|
1355 | - |
|
1356 | - /** |
|
1357 | - * This isn't just the name of an input, it's a path pointing to an input. The |
|
1358 | - * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1359 | - * dot-dot-slash (../) means to ascend into the parent section. |
|
1360 | - * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1361 | - * which will be returned. |
|
1362 | - * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1363 | - * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1364 | - * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1365 | - * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1366 | - * Etc |
|
1367 | - * |
|
1368 | - * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1369 | - * @return EE_Form_Section_Base |
|
1370 | - */ |
|
1371 | - public function find_section_from_path($form_section_path) |
|
1372 | - { |
|
1373 | - //check if we can find the input from purely going straight up the tree |
|
1374 | - $input = parent::find_section_from_path($form_section_path); |
|
1375 | - if ($input instanceof EE_Form_Section_Base) { |
|
1376 | - return $input; |
|
1377 | - } |
|
1378 | - $next_slash_pos = strpos($form_section_path, '/'); |
|
1379 | - if ($next_slash_pos !== false) { |
|
1380 | - $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1381 | - $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1382 | - } else { |
|
1383 | - $child_section_name = $form_section_path; |
|
1384 | - $subpath = ''; |
|
1385 | - } |
|
1386 | - $child_section = $this->get_subsection($child_section_name); |
|
1387 | - if ($child_section instanceof EE_Form_Section_Base) { |
|
1388 | - return $child_section->find_section_from_path($subpath); |
|
1389 | - } else { |
|
1390 | - return null; |
|
1391 | - } |
|
1392 | - } |
|
14 | + const SUBMITTED_FORM_DATA_SSN_KEY = 'submitted_form_data'; |
|
15 | + |
|
16 | + /** |
|
17 | + * Subsections |
|
18 | + * |
|
19 | + * @var EE_Form_Section_Validatable[] |
|
20 | + */ |
|
21 | + protected $_subsections = array(); |
|
22 | + |
|
23 | + /** |
|
24 | + * Strategy for laying out the form |
|
25 | + * |
|
26 | + * @var EE_Form_Section_Layout_Base |
|
27 | + */ |
|
28 | + protected $_layout_strategy; |
|
29 | + |
|
30 | + /** |
|
31 | + * Whether or not this form has received and validated a form submission yet |
|
32 | + * |
|
33 | + * @var boolean |
|
34 | + */ |
|
35 | + protected $_received_submission = false; |
|
36 | + |
|
37 | + /** |
|
38 | + * message displayed to users upon successful form submission |
|
39 | + * |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + protected $_form_submission_success_message = ''; |
|
43 | + |
|
44 | + /** |
|
45 | + * message displayed to users upon unsuccessful form submission |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + protected $_form_submission_error_message = ''; |
|
50 | + |
|
51 | + /** |
|
52 | + * Stores all the data that will localized for form validation |
|
53 | + * |
|
54 | + * @var array |
|
55 | + */ |
|
56 | + static protected $_js_localization = array(); |
|
57 | + |
|
58 | + /** |
|
59 | + * whether or not the form's localized validation JS vars have been set |
|
60 | + * |
|
61 | + * @type boolean |
|
62 | + */ |
|
63 | + static protected $_scripts_localized = false; |
|
64 | + |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * when constructing a proper form section, calls _construct_finalize on children |
|
69 | + * so that they know who their parent is, and what name they've been given. |
|
70 | + * |
|
71 | + * @param array $options_array { |
|
72 | + * @type $subsections EE_Form_Section_Validatable[] where keys are the section's name |
|
73 | + * @type $include string[] numerically-indexed where values are section names to be included, |
|
74 | + * and in that order. This is handy if you want |
|
75 | + * the subsections to be ordered differently than the default, and if you override |
|
76 | + * which fields are shown |
|
77 | + * @type $exclude string[] values are subsections to be excluded. This is handy if you want |
|
78 | + * to remove certain default subsections (note: if you specify BOTH 'include' AND |
|
79 | + * 'exclude', the inclusions will be applied first, and the exclusions will exclude |
|
80 | + * items from that list of inclusions) |
|
81 | + * @type $layout_strategy EE_Form_Section_Layout_Base strategy for laying out the form |
|
82 | + * } @see EE_Form_Section_Validatable::__construct() |
|
83 | + * @throws \EE_Error |
|
84 | + */ |
|
85 | + public function __construct($options_array = array()) |
|
86 | + { |
|
87 | + $options_array = (array)apply_filters('FHEE__EE_Form_Section_Proper___construct__options_array', $options_array, |
|
88 | + $this); |
|
89 | + //call parent first, as it may be setting the name |
|
90 | + parent::__construct($options_array); |
|
91 | + //if they've included subsections in the constructor, add them now |
|
92 | + if (isset($options_array['include'])) { |
|
93 | + //we are going to make sure we ONLY have those subsections to include |
|
94 | + //AND we are going to make sure they're in that specified order |
|
95 | + $reordered_subsections = array(); |
|
96 | + foreach ($options_array['include'] as $input_name) { |
|
97 | + if (isset($this->_subsections[$input_name])) { |
|
98 | + $reordered_subsections[$input_name] = $this->_subsections[$input_name]; |
|
99 | + } |
|
100 | + } |
|
101 | + $this->_subsections = $reordered_subsections; |
|
102 | + } |
|
103 | + if (isset($options_array['exclude'])) { |
|
104 | + $exclude = $options_array['exclude']; |
|
105 | + $this->_subsections = array_diff_key($this->_subsections, array_flip($exclude)); |
|
106 | + } |
|
107 | + if (isset($options_array['layout_strategy'])) { |
|
108 | + $this->_layout_strategy = $options_array['layout_strategy']; |
|
109 | + } |
|
110 | + if (! $this->_layout_strategy) { |
|
111 | + $this->_layout_strategy = is_admin() ? new EE_Admin_Two_Column_Layout() : new EE_Two_Column_Layout(); |
|
112 | + } |
|
113 | + $this->_layout_strategy->_construct_finalize($this); |
|
114 | + //ok so we are definitely going to want the forms JS, |
|
115 | + //so enqueue it or remember to enqueue it during wp_enqueue_scripts |
|
116 | + if (did_action('wp_enqueue_scripts') || did_action('admin_enqueue_scripts')) { |
|
117 | + //ok so they've constructed this object after when they should have. |
|
118 | + //just enqueue the generic form scripts and initialize the form immediately in the JS |
|
119 | + \EE_Form_Section_Proper::wp_enqueue_scripts(true); |
|
120 | + } else { |
|
121 | + add_action('wp_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
122 | + add_action('admin_enqueue_scripts', array('EE_Form_Section_Proper', 'wp_enqueue_scripts')); |
|
123 | + } |
|
124 | + add_action('wp_footer', array($this, 'ensure_scripts_localized'), 1); |
|
125 | + |
|
126 | + /** |
|
127 | + * Gives other plugins a chance to hook in before construct finalize is called. The form probably doesn't |
|
128 | + * yet have a parent form section. Since 4.9.32, when this action was introduced, this is the best place to |
|
129 | + * add a subsection onto a form, assuming you don't care what the form section's name, HTML ID, or HTML name etc are. |
|
130 | + * Also see AHEE__EE_Form_Section_Proper___construct_finalize__end |
|
131 | + * @since 4.9.32 |
|
132 | + * @param EE_Form_Section_Proper $this before __construct is done, but all of its logic, except maybe calling |
|
133 | + * _construct_finalize has been done |
|
134 | + * @param array $options_array options passed into the constructor |
|
135 | + */ |
|
136 | + do_action('AHEE__EE_Form_Input_Base___construct__before_construct_finalize_called', $this, $options_array); |
|
137 | + |
|
138 | + if (isset($options_array['name'])) { |
|
139 | + $this->_construct_finalize(null, $options_array['name']); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * Finishes construction given the parent form section and this form section's name |
|
147 | + * |
|
148 | + * @param EE_Form_Section_Proper $parent_form_section |
|
149 | + * @param string $name |
|
150 | + * @throws \EE_Error |
|
151 | + */ |
|
152 | + public function _construct_finalize($parent_form_section, $name) |
|
153 | + { |
|
154 | + parent::_construct_finalize($parent_form_section, $name); |
|
155 | + $this->_set_default_name_if_empty(); |
|
156 | + $this->_set_default_html_id_if_empty(); |
|
157 | + foreach ($this->_subsections as $subsection_name => $subsection) { |
|
158 | + if ($subsection instanceof EE_Form_Section_Base) { |
|
159 | + $subsection->_construct_finalize($this, $subsection_name); |
|
160 | + } else { |
|
161 | + throw new EE_Error( |
|
162 | + sprintf( |
|
163 | + __('Subsection "%s" is not an instanceof EE_Form_Section_Base on form "%s". It is a "%s"', |
|
164 | + 'event_espresso'), |
|
165 | + $subsection_name, |
|
166 | + get_class($this), |
|
167 | + $subsection ? get_class($subsection) : __('NULL', 'event_espresso') |
|
168 | + ) |
|
169 | + ); |
|
170 | + } |
|
171 | + } |
|
172 | + /** |
|
173 | + * Action performed just after form has been given a name (and HTML ID etc) and is fully constructed. |
|
174 | + * If you have code that should modify the form and needs it and its subsections to have a name, HTML ID (or other attributes derived |
|
175 | + * from the name like the HTML label id, etc), this is where it should be done. |
|
176 | + * This might only happen just before displaying the form, or just before it receives form submission data. |
|
177 | + * If you need to modify the form or its subsections before _construct_finalize is called on it (and we've |
|
178 | + * ensured it has a name, HTML IDs, etc |
|
179 | + * @param EE_Form_Section_Proper $this |
|
180 | + * @param EE_Form_Section_Proper|null $parent_form_section |
|
181 | + * @param string $name |
|
182 | + */ |
|
183 | + do_action('AHEE__EE_Form_Section_Proper___construct_finalize__end', $this, $parent_form_section, $name); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Gets the layout strategy for this form section |
|
190 | + * |
|
191 | + * @return EE_Form_Section_Layout_Base |
|
192 | + */ |
|
193 | + public function get_layout_strategy() |
|
194 | + { |
|
195 | + return $this->_layout_strategy; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Gets the HTML for a single input for this form section according |
|
202 | + * to the layout strategy |
|
203 | + * |
|
204 | + * @param EE_Form_Input_Base $input |
|
205 | + * @return string |
|
206 | + */ |
|
207 | + public function get_html_for_input($input) |
|
208 | + { |
|
209 | + return $this->_layout_strategy->layout_input($input); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * was_submitted - checks if form inputs are present in request data |
|
216 | + * Basically an alias for form_data_present_in() (which is used by both |
|
217 | + * proper form sections and form inputs) |
|
218 | + * |
|
219 | + * @param null $form_data |
|
220 | + * @return boolean |
|
221 | + */ |
|
222 | + public function was_submitted($form_data = null) |
|
223 | + { |
|
224 | + return $this->form_data_present_in($form_data); |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * After the form section is initially created, call this to sanitize the data in the submission |
|
231 | + * which relates to this form section, validate it, and set it as properties on the form. |
|
232 | + * |
|
233 | + * @param array|null $req_data should usually be $_POST (the default). |
|
234 | + * However, you CAN supply a different array. |
|
235 | + * Consider using set_defaults() instead however. |
|
236 | + * (If you rendered the form in the page using echo $form_x->get_html() |
|
237 | + * the inputs will have the correct name in the request data for this function |
|
238 | + * to find them and populate the form with them. |
|
239 | + * If you have a flat form (with only input subsections), |
|
240 | + * you can supply a flat array where keys |
|
241 | + * are the form input names and values are their values) |
|
242 | + * @param boolean $validate whether or not to perform validation on this data. Default is, |
|
243 | + * of course, to validate that data, and set errors on the invalid values. |
|
244 | + * But if the data has already been validated |
|
245 | + * (eg you validated the data then stored it in the DB) |
|
246 | + * you may want to skip this step. |
|
247 | + */ |
|
248 | + public function receive_form_submission($req_data = null, $validate = true) |
|
249 | + { |
|
250 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__req_data', $req_data, $this, |
|
251 | + $validate); |
|
252 | + if ($req_data === null) { |
|
253 | + $req_data = array_merge($_GET, $_POST); |
|
254 | + } |
|
255 | + $req_data = apply_filters('FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', $req_data, |
|
256 | + $this); |
|
257 | + $this->_normalize($req_data); |
|
258 | + if ($validate) { |
|
259 | + $this->_validate(); |
|
260 | + //if it's invalid, we're going to want to re-display so remember what they submitted |
|
261 | + if (! $this->is_valid()) { |
|
262 | + $this->store_submitted_form_data_in_session(); |
|
263 | + } |
|
264 | + } |
|
265 | + do_action('AHEE__EE_Form_Section_Proper__receive_form_submission__end', $req_data, $this, $validate); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * caches the originally submitted input values in the session |
|
272 | + * so that they can be used to repopulate the form if it failed validation |
|
273 | + * |
|
274 | + * @return boolean whether or not the data was successfully stored in the session |
|
275 | + */ |
|
276 | + protected function store_submitted_form_data_in_session() |
|
277 | + { |
|
278 | + return EE_Registry::instance()->SSN->set_session_data( |
|
279 | + array( |
|
280 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY => $this->submitted_values(true), |
|
281 | + ) |
|
282 | + ); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * retrieves the originally submitted input values in the session |
|
289 | + * so that they can be used to repopulate the form if it failed validation |
|
290 | + * |
|
291 | + * @return array |
|
292 | + */ |
|
293 | + protected function get_submitted_form_data_from_session() |
|
294 | + { |
|
295 | + $session = EE_Registry::instance()->SSN; |
|
296 | + if ($session instanceof EE_Session) { |
|
297 | + return $session->get_session_data( |
|
298 | + \EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY |
|
299 | + ); |
|
300 | + } else { |
|
301 | + return array(); |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * flushed the originally submitted input values from the session |
|
309 | + * |
|
310 | + * @return boolean whether or not the data was successfully removed from the session |
|
311 | + */ |
|
312 | + protected function flush_submitted_form_data_from_session() |
|
313 | + { |
|
314 | + return EE_Registry::instance()->SSN->reset_data( |
|
315 | + array(\EE_Form_Section_Proper::SUBMITTED_FORM_DATA_SSN_KEY) |
|
316 | + ); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * Populates this form and its subsections with data from the session. |
|
323 | + * (Wrapper for EE_Form_Section_Proper::receive_form_submission, so it shows |
|
324 | + * validation errors when displaying too) |
|
325 | + * Returns true if the form was populated from the session, false otherwise |
|
326 | + * |
|
327 | + * @return boolean |
|
328 | + */ |
|
329 | + public function populate_from_session() |
|
330 | + { |
|
331 | + $form_data_in_session = $this->get_submitted_form_data_from_session(); |
|
332 | + if (empty($form_data_in_session)) { |
|
333 | + return false; |
|
334 | + } |
|
335 | + $this->receive_form_submission($form_data_in_session); |
|
336 | + $this->flush_submitted_form_data_from_session(); |
|
337 | + if ($this->form_data_present_in($form_data_in_session)) { |
|
338 | + return true; |
|
339 | + } else { |
|
340 | + return false; |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * Populates the default data for the form, given an array where keys are |
|
348 | + * the input names, and values are their values (preferably normalized to be their |
|
349 | + * proper PHP types, not all strings... although that should be ok too). |
|
350 | + * Proper subsections are sub-arrays, the key being the subsection's name, and |
|
351 | + * the value being an array formatted in teh same way |
|
352 | + * |
|
353 | + * @param array $default_data |
|
354 | + */ |
|
355 | + public function populate_defaults($default_data) |
|
356 | + { |
|
357 | + foreach ($this->subsections(false) as $subsection_name => $subsection) { |
|
358 | + if (isset($default_data[$subsection_name])) { |
|
359 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
360 | + $subsection->set_default($default_data[$subsection_name]); |
|
361 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
362 | + $subsection->populate_defaults($default_data[$subsection_name]); |
|
363 | + } |
|
364 | + } |
|
365 | + } |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * returns true if subsection exists |
|
372 | + * |
|
373 | + * @param string $name |
|
374 | + * @return boolean |
|
375 | + */ |
|
376 | + public function subsection_exists($name) |
|
377 | + { |
|
378 | + return isset($this->_subsections[$name]) ? true : false; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * Gets the subsection specified by its name |
|
385 | + * |
|
386 | + * @param string $name |
|
387 | + * @param boolean $require_construction_to_be_finalized most client code should leave this as TRUE |
|
388 | + * so that the inputs will be properly configured. |
|
389 | + * However, some client code may be ok |
|
390 | + * with construction finalize being called later |
|
391 | + * (realizing that the subsections' html names |
|
392 | + * might not be set yet, etc.) |
|
393 | + * @return EE_Form_Section_Base |
|
394 | + * @throws \EE_Error |
|
395 | + */ |
|
396 | + public function get_subsection($name, $require_construction_to_be_finalized = true) |
|
397 | + { |
|
398 | + if ($require_construction_to_be_finalized) { |
|
399 | + $this->ensure_construct_finalized_called(); |
|
400 | + } |
|
401 | + return $this->subsection_exists($name) ? $this->_subsections[$name] : null; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * Gets all the validatable subsections of this form section |
|
408 | + * |
|
409 | + * @return EE_Form_Section_Validatable[] |
|
410 | + */ |
|
411 | + public function get_validatable_subsections() |
|
412 | + { |
|
413 | + $validatable_subsections = array(); |
|
414 | + foreach ($this->subsections() as $name => $obj) { |
|
415 | + if ($obj instanceof EE_Form_Section_Validatable) { |
|
416 | + $validatable_subsections[$name] = $obj; |
|
417 | + } |
|
418 | + } |
|
419 | + return $validatable_subsections; |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * Gets an input by the given name. If not found, or if its not an EE_FOrm_Input_Base child, |
|
426 | + * throw an EE_Error. |
|
427 | + * |
|
428 | + * @param string $name |
|
429 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
430 | + * leave this as TRUE so that the inputs will be properly |
|
431 | + * configured. However, some client code may be ok with |
|
432 | + * construction finalize being called later |
|
433 | + * (realizing that the subsections' html names might not be |
|
434 | + * set yet, etc.) |
|
435 | + * @return EE_Form_Input_Base |
|
436 | + * @throws EE_Error |
|
437 | + */ |
|
438 | + public function get_input($name, $require_construction_to_be_finalized = true) |
|
439 | + { |
|
440 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
441 | + if (! $subsection instanceof EE_Form_Input_Base) { |
|
442 | + throw new EE_Error( |
|
443 | + sprintf( |
|
444 | + __( |
|
445 | + "Subsection '%s' is not an instanceof EE_Form_Input_Base on form '%s'. It is a '%s'", |
|
446 | + 'event_espresso' |
|
447 | + ), |
|
448 | + $name, |
|
449 | + get_class($this), |
|
450 | + $subsection ? get_class($subsection) : __("NULL", 'event_espresso') |
|
451 | + ) |
|
452 | + ); |
|
453 | + } |
|
454 | + return $subsection; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Like get_input(), gets the proper subsection of the form given the name, |
|
461 | + * otherwise throws an EE_Error |
|
462 | + * |
|
463 | + * @param string $name |
|
464 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
465 | + * leave this as TRUE so that the inputs will be properly |
|
466 | + * configured. However, some client code may be ok with |
|
467 | + * construction finalize being called later |
|
468 | + * (realizing that the subsections' html names might not be |
|
469 | + * set yet, etc.) |
|
470 | + * @return EE_Form_Section_Proper |
|
471 | + * @throws EE_Error |
|
472 | + */ |
|
473 | + public function get_proper_subsection($name, $require_construction_to_be_finalized = true) |
|
474 | + { |
|
475 | + $subsection = $this->get_subsection($name, $require_construction_to_be_finalized); |
|
476 | + if (! $subsection instanceof EE_Form_Section_Proper) { |
|
477 | + throw new EE_Error( |
|
478 | + sprintf( |
|
479 | + __("Subsection '%'s is not an instanceof EE_Form_Section_Proper on form '%s'", 'event_espresso'), |
|
480 | + $name, |
|
481 | + get_class($this) |
|
482 | + ) |
|
483 | + ); |
|
484 | + } |
|
485 | + return $subsection; |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * Gets the value of the specified input. Should be called after receive_form_submission() |
|
492 | + * or populate_defaults() on the form, where the normalized value on the input is set. |
|
493 | + * |
|
494 | + * @param string $name |
|
495 | + * @return mixed depending on the input's type and its normalization strategy |
|
496 | + * @throws \EE_Error |
|
497 | + */ |
|
498 | + public function get_input_value($name) |
|
499 | + { |
|
500 | + $input = $this->get_input($name); |
|
501 | + return $input->normalized_value(); |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * Checks if this form section itself is valid, and then checks its subsections |
|
508 | + * |
|
509 | + * @throws EE_Error |
|
510 | + * @return boolean |
|
511 | + */ |
|
512 | + public function is_valid() |
|
513 | + { |
|
514 | + if (! $this->has_received_submission()) { |
|
515 | + throw new EE_Error( |
|
516 | + sprintf( |
|
517 | + __( |
|
518 | + "You cannot check if a form is valid before receiving the form submission using receive_form_submission", |
|
519 | + "event_espresso" |
|
520 | + ) |
|
521 | + ) |
|
522 | + ); |
|
523 | + } |
|
524 | + if (! parent::is_valid()) { |
|
525 | + return false; |
|
526 | + } |
|
527 | + // ok so no general errors to this entire form section. |
|
528 | + // so let's check the subsections, but only set errors if that hasn't been done yet |
|
529 | + $set_submission_errors = $this->submission_error_message() === '' ? true : false; |
|
530 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
531 | + if (! $subsection->is_valid() || $subsection->get_validation_error_string() !== '') { |
|
532 | + if ($set_submission_errors) { |
|
533 | + $this->set_submission_error_message($subsection->get_validation_error_string()); |
|
534 | + } |
|
535 | + return false; |
|
536 | + } |
|
537 | + } |
|
538 | + return true; |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + /** |
|
544 | + * gets teh default name of this form section if none is specified |
|
545 | + * |
|
546 | + * @return string |
|
547 | + */ |
|
548 | + protected function _set_default_name_if_empty() |
|
549 | + { |
|
550 | + if (! $this->_name) { |
|
551 | + $classname = get_class($this); |
|
552 | + $default_name = str_replace("EE_", "", $classname); |
|
553 | + $this->_name = $default_name; |
|
554 | + } |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + |
|
559 | + /** |
|
560 | + * Returns the HTML for the form, except for the form opening and closing tags |
|
561 | + * (as the form section doesn't know where you necessarily want to send the information to), |
|
562 | + * and except for a submit button. Enqueus JS and CSS; if called early enough we will |
|
563 | + * try to enqueue them in the header, otherwise they'll be enqueued in the footer. |
|
564 | + * Not doing_it_wrong because theoretically this CAN be used properly, |
|
565 | + * provided its used during "wp_enqueue_scripts", or it doesn't need to enqueue |
|
566 | + * any CSS. |
|
567 | + * |
|
568 | + * @throws \EE_Error |
|
569 | + */ |
|
570 | + public function get_html_and_js() |
|
571 | + { |
|
572 | + $this->enqueue_js(); |
|
573 | + return $this->get_html(); |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * returns HTML for displaying this form section. recursively calls display_section() on all subsections |
|
580 | + * |
|
581 | + * @param bool $display_previously_submitted_data |
|
582 | + * @return string |
|
583 | + */ |
|
584 | + public function get_html($display_previously_submitted_data = true) |
|
585 | + { |
|
586 | + $this->ensure_construct_finalized_called(); |
|
587 | + if ($display_previously_submitted_data) { |
|
588 | + $this->populate_from_session(); |
|
589 | + } |
|
590 | + return $this->_form_html_filter |
|
591 | + ? $this->_form_html_filter->filterHtml($this->_layout_strategy->layout_form(), $this) |
|
592 | + : $this->_layout_strategy->layout_form(); |
|
593 | + } |
|
594 | + |
|
595 | + |
|
596 | + |
|
597 | + /** |
|
598 | + * enqueues JS and CSS for the form. |
|
599 | + * It is preferred to call this before wp_enqueue_scripts so the |
|
600 | + * scripts and styles can be put in the header, but if called later |
|
601 | + * they will be put in the footer (which is OK for JS, but in HTML4 CSS should |
|
602 | + * only be in the header; but in HTML5 its ok in the body. |
|
603 | + * See http://stackoverflow.com/questions/4957446/load-external-css-file-in-body-tag. |
|
604 | + * So if your form enqueues CSS, it's preferred to call this before wp_enqueue_scripts.) |
|
605 | + * |
|
606 | + * @return string |
|
607 | + * @throws \EE_Error |
|
608 | + */ |
|
609 | + public function enqueue_js() |
|
610 | + { |
|
611 | + $this->_enqueue_and_localize_form_js(); |
|
612 | + foreach ($this->subsections() as $subsection) { |
|
613 | + $subsection->enqueue_js(); |
|
614 | + } |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + |
|
619 | + /** |
|
620 | + * adds a filter so that jquery validate gets enqueued in EE_System::wp_enqueue_scripts(). |
|
621 | + * This must be done BEFORE wp_enqueue_scripts() gets called, which is on |
|
622 | + * the wp_enqueue_scripts hook. |
|
623 | + * However, registering the form js and localizing it can happen when we |
|
624 | + * actually output the form (which is preferred, seeing how teh form's fields |
|
625 | + * could change until it's actually outputted) |
|
626 | + * |
|
627 | + * @param boolean $init_form_validation_automatically whether or not we want the form validation |
|
628 | + * to be triggered automatically or not |
|
629 | + * @return void |
|
630 | + */ |
|
631 | + public static function wp_enqueue_scripts($init_form_validation_automatically = true) |
|
632 | + { |
|
633 | + wp_register_script( |
|
634 | + 'ee_form_section_validation', |
|
635 | + EE_GLOBAL_ASSETS_URL . 'scripts' . DS . 'form_section_validation.js', |
|
636 | + array('jquery-validate', 'jquery-ui-datepicker', 'jquery-validate-extra-methods'), |
|
637 | + EVENT_ESPRESSO_VERSION, |
|
638 | + true |
|
639 | + ); |
|
640 | + wp_localize_script( |
|
641 | + 'ee_form_section_validation', |
|
642 | + 'ee_form_section_validation_init', |
|
643 | + array('init' => $init_form_validation_automatically ? '1' : '0') |
|
644 | + ); |
|
645 | + } |
|
646 | + |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * gets the variables used by form_section_validation.js. |
|
651 | + * This needs to be called AFTER we've called $this->_enqueue_jquery_validate_script, |
|
652 | + * but before the wordpress hook wp_loaded |
|
653 | + * |
|
654 | + * @throws \EE_Error |
|
655 | + */ |
|
656 | + public function _enqueue_and_localize_form_js() |
|
657 | + { |
|
658 | + $this->ensure_construct_finalized_called(); |
|
659 | + //actually, we don't want to localize just yet. There may be other forms on the page. |
|
660 | + //so we need to add our form section data to a static variable accessible by all form sections |
|
661 | + //and localize it just before the footer |
|
662 | + $this->localize_validation_rules(); |
|
663 | + add_action('wp_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms'), 2); |
|
664 | + add_action('admin_footer', array('EE_Form_Section_Proper', 'localize_script_for_all_forms')); |
|
665 | + } |
|
666 | + |
|
667 | + |
|
668 | + |
|
669 | + /** |
|
670 | + * add our form section data to a static variable accessible by all form sections |
|
671 | + * |
|
672 | + * @param bool $return_for_subsection |
|
673 | + * @return void |
|
674 | + * @throws \EE_Error |
|
675 | + */ |
|
676 | + public function localize_validation_rules($return_for_subsection = false) |
|
677 | + { |
|
678 | + // we only want to localize vars ONCE for the entire form, |
|
679 | + // so if the form section doesn't have a parent, then it must be the top dog |
|
680 | + if ($return_for_subsection || ! $this->parent_section()) { |
|
681 | + EE_Form_Section_Proper::$_js_localization['form_data'][$this->html_id()] = array( |
|
682 | + 'form_section_id' => $this->html_id(true), |
|
683 | + 'validation_rules' => $this->get_jquery_validation_rules(), |
|
684 | + 'other_data' => $this->get_other_js_data(), |
|
685 | + 'errors' => $this->subsection_validation_errors_by_html_name(), |
|
686 | + ); |
|
687 | + EE_Form_Section_Proper::$_scripts_localized = true; |
|
688 | + } |
|
689 | + } |
|
690 | + |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * Gets an array of extra data that will be useful for client-side javascript. |
|
695 | + * This is primarily data added by inputs and forms in addition to any |
|
696 | + * scripts they might enqueue |
|
697 | + * |
|
698 | + * @param array $form_other_js_data |
|
699 | + * @return array |
|
700 | + */ |
|
701 | + public function get_other_js_data($form_other_js_data = array()) |
|
702 | + { |
|
703 | + foreach ($this->subsections() as $subsection) { |
|
704 | + $form_other_js_data = $subsection->get_other_js_data($form_other_js_data); |
|
705 | + } |
|
706 | + return $form_other_js_data; |
|
707 | + } |
|
708 | + |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * Gets a flat array of inputs for this form section and its subsections. |
|
713 | + * Keys are their form names, and values are the inputs themselves |
|
714 | + * |
|
715 | + * @return EE_Form_Input_Base |
|
716 | + */ |
|
717 | + public function inputs_in_subsections() |
|
718 | + { |
|
719 | + $inputs = array(); |
|
720 | + foreach ($this->subsections() as $subsection) { |
|
721 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
722 | + $inputs[$subsection->html_name()] = $subsection; |
|
723 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
724 | + $inputs += $subsection->inputs_in_subsections(); |
|
725 | + } |
|
726 | + } |
|
727 | + return $inputs; |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + |
|
732 | + /** |
|
733 | + * Gets a flat array of all the validation errors. |
|
734 | + * Keys are html names (because those should be unique) |
|
735 | + * and values are a string of all their validation errors |
|
736 | + * |
|
737 | + * @return string[] |
|
738 | + */ |
|
739 | + public function subsection_validation_errors_by_html_name() |
|
740 | + { |
|
741 | + $inputs = $this->inputs(); |
|
742 | + $errors = array(); |
|
743 | + foreach ($inputs as $form_input) { |
|
744 | + if ($form_input instanceof EE_Form_Input_Base && $form_input->get_validation_errors()) { |
|
745 | + $errors[$form_input->html_name()] = $form_input->get_validation_error_string(); |
|
746 | + } |
|
747 | + } |
|
748 | + return $errors; |
|
749 | + } |
|
750 | + |
|
751 | + |
|
752 | + |
|
753 | + /** |
|
754 | + * passes all the form data required by the JS to the JS, and enqueues the few required JS files. |
|
755 | + * Should be setup by each form during the _enqueues_and_localize_form_js |
|
756 | + */ |
|
757 | + public static function localize_script_for_all_forms() |
|
758 | + { |
|
759 | + //allow inputs and stuff to hook in their JS and stuff here |
|
760 | + do_action('AHEE__EE_Form_Section_Proper__localize_script_for_all_forms__begin'); |
|
761 | + EE_Form_Section_Proper::$_js_localization['localized_error_messages'] = EE_Form_Section_Proper::_get_localized_error_messages(); |
|
762 | + $email_validation_level = isset(EE_Registry::instance()->CFG->registration->email_validation_level) |
|
763 | + ? EE_Registry::instance()->CFG->registration->email_validation_level |
|
764 | + : 'wp_default'; |
|
765 | + EE_Form_Section_Proper::$_js_localization['email_validation_level'] = $email_validation_level; |
|
766 | + wp_enqueue_script('ee_form_section_validation'); |
|
767 | + wp_localize_script( |
|
768 | + 'ee_form_section_validation', |
|
769 | + 'ee_form_section_vars', |
|
770 | + EE_Form_Section_Proper::$_js_localization |
|
771 | + ); |
|
772 | + } |
|
773 | + |
|
774 | + |
|
775 | + |
|
776 | + /** |
|
777 | + * ensure_scripts_localized |
|
778 | + */ |
|
779 | + public function ensure_scripts_localized() |
|
780 | + { |
|
781 | + if (! EE_Form_Section_Proper::$_scripts_localized) { |
|
782 | + $this->_enqueue_and_localize_form_js(); |
|
783 | + } |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + |
|
788 | + /** |
|
789 | + * Gets the hard-coded validation error messages to be used in the JS. The convention |
|
790 | + * is that the key here should be the same as the custom validation rule put in the JS file |
|
791 | + * |
|
792 | + * @return array keys are custom validation rules, and values are internationalized strings |
|
793 | + */ |
|
794 | + private static function _get_localized_error_messages() |
|
795 | + { |
|
796 | + return array( |
|
797 | + 'validUrl' => __("This is not a valid absolute URL. Eg, http://domain.com/monkey.jpg", "event_espresso"), |
|
798 | + 'regex' => __('Please check your input', 'event_espresso'), |
|
799 | + ); |
|
800 | + } |
|
801 | + |
|
802 | + |
|
803 | + |
|
804 | + /** |
|
805 | + * @return array |
|
806 | + */ |
|
807 | + public static function js_localization() |
|
808 | + { |
|
809 | + return self::$_js_localization; |
|
810 | + } |
|
811 | + |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * @return array |
|
816 | + */ |
|
817 | + public static function reset_js_localization() |
|
818 | + { |
|
819 | + self::$_js_localization = array(); |
|
820 | + } |
|
821 | + |
|
822 | + |
|
823 | + |
|
824 | + /** |
|
825 | + * Gets the JS to put inside the jquery validation rules for subsection of this form section. |
|
826 | + * See parent function for more... |
|
827 | + * |
|
828 | + * @return array |
|
829 | + */ |
|
830 | + public function get_jquery_validation_rules() |
|
831 | + { |
|
832 | + $jquery_validation_rules = array(); |
|
833 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
834 | + $jquery_validation_rules = array_merge( |
|
835 | + $jquery_validation_rules, |
|
836 | + $subsection->get_jquery_validation_rules() |
|
837 | + ); |
|
838 | + } |
|
839 | + return $jquery_validation_rules; |
|
840 | + } |
|
841 | + |
|
842 | + |
|
843 | + |
|
844 | + /** |
|
845 | + * Sanitizes all the data and sets the sanitized value of each field |
|
846 | + * |
|
847 | + * @param array $req_data like $_POST |
|
848 | + * @return void |
|
849 | + */ |
|
850 | + protected function _normalize($req_data) |
|
851 | + { |
|
852 | + $this->_received_submission = true; |
|
853 | + $this->_validation_errors = array(); |
|
854 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
855 | + try { |
|
856 | + $subsection->_normalize($req_data); |
|
857 | + } catch (EE_Validation_Error $e) { |
|
858 | + $subsection->add_validation_error($e); |
|
859 | + } |
|
860 | + } |
|
861 | + } |
|
862 | + |
|
863 | + |
|
864 | + |
|
865 | + /** |
|
866 | + * Performs validation on this form section and its subsections. |
|
867 | + * For each subsection, |
|
868 | + * calls _validate_{subsection_name} on THIS form (if the function exists) |
|
869 | + * and passes it the subsection, then calls _validate on that subsection. |
|
870 | + * If you need to perform validation on the form as a whole (considering multiple) |
|
871 | + * you would be best to override this _validate method, |
|
872 | + * calling parent::_validate() first. |
|
873 | + */ |
|
874 | + protected function _validate() |
|
875 | + { |
|
876 | + foreach ($this->get_validatable_subsections() as $subsection_name => $subsection) { |
|
877 | + if (method_exists($this, '_validate_' . $subsection_name)) { |
|
878 | + call_user_func_array(array($this, '_validate_' . $subsection_name), array($subsection)); |
|
879 | + } |
|
880 | + $subsection->_validate(); |
|
881 | + } |
|
882 | + } |
|
883 | + |
|
884 | + |
|
885 | + |
|
886 | + /** |
|
887 | + * Gets all the validated inputs for the form section |
|
888 | + * |
|
889 | + * @return array |
|
890 | + */ |
|
891 | + public function valid_data() |
|
892 | + { |
|
893 | + $inputs = array(); |
|
894 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
895 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
896 | + $inputs[$subsection_name] = $subsection->valid_data(); |
|
897 | + } else if ($subsection instanceof EE_Form_Input_Base) { |
|
898 | + $inputs[$subsection_name] = $subsection->normalized_value(); |
|
899 | + } |
|
900 | + } |
|
901 | + return $inputs; |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + |
|
906 | + /** |
|
907 | + * Gets all the inputs on this form section |
|
908 | + * |
|
909 | + * @return EE_Form_Input_Base[] |
|
910 | + */ |
|
911 | + public function inputs() |
|
912 | + { |
|
913 | + $inputs = array(); |
|
914 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
915 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
916 | + $inputs[$subsection_name] = $subsection; |
|
917 | + } |
|
918 | + } |
|
919 | + return $inputs; |
|
920 | + } |
|
921 | + |
|
922 | + |
|
923 | + |
|
924 | + /** |
|
925 | + * Gets all the subsections which are a proper form |
|
926 | + * |
|
927 | + * @return EE_Form_Section_Proper[] |
|
928 | + */ |
|
929 | + public function subforms() |
|
930 | + { |
|
931 | + $form_sections = array(); |
|
932 | + foreach ($this->subsections() as $name => $obj) { |
|
933 | + if ($obj instanceof EE_Form_Section_Proper) { |
|
934 | + $form_sections[$name] = $obj; |
|
935 | + } |
|
936 | + } |
|
937 | + return $form_sections; |
|
938 | + } |
|
939 | + |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * Gets all the subsections (inputs, proper subsections, or html-only sections). |
|
944 | + * Consider using inputs() or subforms() |
|
945 | + * if you only want form inputs or proper form sections. |
|
946 | + * |
|
947 | + * @param boolean $require_construction_to_be_finalized most client code should |
|
948 | + * leave this as TRUE so that the inputs will be properly |
|
949 | + * configured. However, some client code may be ok with |
|
950 | + * construction finalize being called later |
|
951 | + * (realizing that the subsections' html names might not be |
|
952 | + * set yet, etc.) |
|
953 | + * @return EE_Form_Section_Proper[] |
|
954 | + */ |
|
955 | + public function subsections($require_construction_to_be_finalized = true) |
|
956 | + { |
|
957 | + if ($require_construction_to_be_finalized) { |
|
958 | + $this->ensure_construct_finalized_called(); |
|
959 | + } |
|
960 | + return $this->_subsections; |
|
961 | + } |
|
962 | + |
|
963 | + |
|
964 | + |
|
965 | + /** |
|
966 | + * Returns a simple array where keys are input names, and values are their normalized |
|
967 | + * values. (Similar to calling get_input_value on inputs) |
|
968 | + * |
|
969 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
970 | + * or just this forms' direct children inputs |
|
971 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
972 | + * or allow multidimensional array |
|
973 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
974 | + * with array keys being input names |
|
975 | + * (regardless of whether they are from a subsection or not), |
|
976 | + * and if $flatten is FALSE it can be a multidimensional array |
|
977 | + * where keys are always subsection names and values are either |
|
978 | + * the input's normalized value, or an array like the top-level array |
|
979 | + */ |
|
980 | + public function input_values($include_subform_inputs = false, $flatten = false) |
|
981 | + { |
|
982 | + return $this->_input_values(false, $include_subform_inputs, $flatten); |
|
983 | + } |
|
984 | + |
|
985 | + |
|
986 | + |
|
987 | + /** |
|
988 | + * Similar to EE_Form_Section_Proper::input_values(), except this returns the 'display_value' |
|
989 | + * of each input. On some inputs (especially radio boxes or checkboxes), the value stored |
|
990 | + * is not necessarily the value we want to display to users. This creates an array |
|
991 | + * where keys are the input names, and values are their display values |
|
992 | + * |
|
993 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
994 | + * or just this forms' direct children inputs |
|
995 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
996 | + * or allow multidimensional array |
|
997 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
998 | + * with array keys being input names |
|
999 | + * (regardless of whether they are from a subsection or not), |
|
1000 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1001 | + * where keys are always subsection names and values are either |
|
1002 | + * the input's normalized value, or an array like the top-level array |
|
1003 | + */ |
|
1004 | + public function input_pretty_values($include_subform_inputs = false, $flatten = false) |
|
1005 | + { |
|
1006 | + return $this->_input_values(true, $include_subform_inputs, $flatten); |
|
1007 | + } |
|
1008 | + |
|
1009 | + |
|
1010 | + |
|
1011 | + /** |
|
1012 | + * Gets the input values from the form |
|
1013 | + * |
|
1014 | + * @param boolean $pretty Whether to retrieve the pretty value, |
|
1015 | + * or just the normalized value |
|
1016 | + * @param boolean $include_subform_inputs Whether to include inputs from subforms, |
|
1017 | + * or just this forms' direct children inputs |
|
1018 | + * @param boolean $flatten Whether to force the results into 1-dimensional array, |
|
1019 | + * or allow multidimensional array |
|
1020 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array with array keys being |
|
1021 | + * input names (regardless of whether they are from a subsection or not), |
|
1022 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1023 | + * where keys are always subsection names and values are either |
|
1024 | + * the input's normalized value, or an array like the top-level array |
|
1025 | + */ |
|
1026 | + public function _input_values($pretty = false, $include_subform_inputs = false, $flatten = false) |
|
1027 | + { |
|
1028 | + $input_values = array(); |
|
1029 | + foreach ($this->subsections() as $subsection_name => $subsection) { |
|
1030 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1031 | + $input_values[$subsection_name] = $pretty |
|
1032 | + ? $subsection->pretty_value() |
|
1033 | + : $subsection->normalized_value(); |
|
1034 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subform_inputs) { |
|
1035 | + $subform_input_values = $subsection->_input_values($pretty, $include_subform_inputs, $flatten); |
|
1036 | + if ($flatten) { |
|
1037 | + $input_values = array_merge($input_values, $subform_input_values); |
|
1038 | + } else { |
|
1039 | + $input_values[$subsection_name] = $subform_input_values; |
|
1040 | + } |
|
1041 | + } |
|
1042 | + } |
|
1043 | + return $input_values; |
|
1044 | + } |
|
1045 | + |
|
1046 | + |
|
1047 | + |
|
1048 | + /** |
|
1049 | + * Gets the originally submitted input values from the form |
|
1050 | + * |
|
1051 | + * @param boolean $include_subforms Whether to include inputs from subforms, |
|
1052 | + * or just this forms' direct children inputs |
|
1053 | + * @return array if $flatten is TRUE it will always be a 1-dimensional array |
|
1054 | + * with array keys being input names |
|
1055 | + * (regardless of whether they are from a subsection or not), |
|
1056 | + * and if $flatten is FALSE it can be a multidimensional array |
|
1057 | + * where keys are always subsection names and values are either |
|
1058 | + * the input's normalized value, or an array like the top-level array |
|
1059 | + */ |
|
1060 | + public function submitted_values($include_subforms = false) |
|
1061 | + { |
|
1062 | + $submitted_values = array(); |
|
1063 | + foreach ($this->subsections() as $subsection) { |
|
1064 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1065 | + // is this input part of an array of inputs? |
|
1066 | + if (strpos($subsection->html_name(), '[') !== false) { |
|
1067 | + $full_input_name = \EEH_Array::convert_array_values_to_keys( |
|
1068 | + explode('[', str_replace(']', '', $subsection->html_name())), |
|
1069 | + $subsection->raw_value() |
|
1070 | + ); |
|
1071 | + $submitted_values = array_replace_recursive($submitted_values, $full_input_name); |
|
1072 | + } else { |
|
1073 | + $submitted_values[$subsection->html_name()] = $subsection->raw_value(); |
|
1074 | + } |
|
1075 | + } else if ($subsection instanceof EE_Form_Section_Proper && $include_subforms) { |
|
1076 | + $subform_input_values = $subsection->submitted_values($include_subforms); |
|
1077 | + $submitted_values = array_replace_recursive($submitted_values, $subform_input_values); |
|
1078 | + } |
|
1079 | + } |
|
1080 | + return $submitted_values; |
|
1081 | + } |
|
1082 | + |
|
1083 | + |
|
1084 | + |
|
1085 | + /** |
|
1086 | + * Indicates whether or not this form has received a submission yet |
|
1087 | + * (ie, had receive_form_submission called on it yet) |
|
1088 | + * |
|
1089 | + * @return boolean |
|
1090 | + * @throws \EE_Error |
|
1091 | + */ |
|
1092 | + public function has_received_submission() |
|
1093 | + { |
|
1094 | + $this->ensure_construct_finalized_called(); |
|
1095 | + return $this->_received_submission; |
|
1096 | + } |
|
1097 | + |
|
1098 | + |
|
1099 | + |
|
1100 | + /** |
|
1101 | + * Equivalent to passing 'exclude' in the constructor's options array. |
|
1102 | + * Removes the listed inputs from the form |
|
1103 | + * |
|
1104 | + * @param array $inputs_to_exclude values are the input names |
|
1105 | + * @return void |
|
1106 | + */ |
|
1107 | + public function exclude(array $inputs_to_exclude = array()) |
|
1108 | + { |
|
1109 | + foreach ($inputs_to_exclude as $input_to_exclude_name) { |
|
1110 | + unset($this->_subsections[$input_to_exclude_name]); |
|
1111 | + } |
|
1112 | + } |
|
1113 | + |
|
1114 | + |
|
1115 | + |
|
1116 | + /** |
|
1117 | + * @param array $inputs_to_hide |
|
1118 | + * @throws \EE_Error |
|
1119 | + */ |
|
1120 | + public function hide(array $inputs_to_hide = array()) |
|
1121 | + { |
|
1122 | + foreach ($inputs_to_hide as $input_to_hide) { |
|
1123 | + $input = $this->get_input($input_to_hide); |
|
1124 | + $input->set_display_strategy(new EE_Hidden_Display_Strategy()); |
|
1125 | + } |
|
1126 | + } |
|
1127 | + |
|
1128 | + |
|
1129 | + |
|
1130 | + /** |
|
1131 | + * add_subsections |
|
1132 | + * Adds the listed subsections to the form section. |
|
1133 | + * If $subsection_name_to_target is provided, |
|
1134 | + * then new subsections are added before or after that subsection, |
|
1135 | + * otherwise to the start or end of the entire subsections array. |
|
1136 | + * |
|
1137 | + * @param EE_Form_Section_Base[] $new_subsections array of new form subsections |
|
1138 | + * where keys are their names |
|
1139 | + * @param string $subsection_name_to_target an existing for section that $new_subsections |
|
1140 | + * should be added before or after |
|
1141 | + * IF $subsection_name_to_target is null, |
|
1142 | + * then $new_subsections will be added to |
|
1143 | + * the beginning or end of the entire subsections array |
|
1144 | + * @param boolean $add_before whether to add $new_subsections, before or after |
|
1145 | + * $subsection_name_to_target, |
|
1146 | + * or if $subsection_name_to_target is null, |
|
1147 | + * before or after entire subsections array |
|
1148 | + * @return void |
|
1149 | + * @throws \EE_Error |
|
1150 | + */ |
|
1151 | + public function add_subsections($new_subsections, $subsection_name_to_target = null, $add_before = true) |
|
1152 | + { |
|
1153 | + foreach ($new_subsections as $subsection_name => $subsection) { |
|
1154 | + if (! $subsection instanceof EE_Form_Section_Base) { |
|
1155 | + EE_Error::add_error( |
|
1156 | + sprintf( |
|
1157 | + __( |
|
1158 | + "Trying to add a %s as a subsection (it was named '%s') to the form section '%s'. It was removed.", |
|
1159 | + "event_espresso" |
|
1160 | + ), |
|
1161 | + get_class($subsection), |
|
1162 | + $subsection_name, |
|
1163 | + $this->name() |
|
1164 | + ) |
|
1165 | + ); |
|
1166 | + unset($new_subsections[$subsection_name]); |
|
1167 | + } |
|
1168 | + } |
|
1169 | + $this->_subsections = EEH_Array::insert_into_array( |
|
1170 | + $this->_subsections, |
|
1171 | + $new_subsections, |
|
1172 | + $subsection_name_to_target, |
|
1173 | + $add_before |
|
1174 | + ); |
|
1175 | + if ($this->_construction_finalized) { |
|
1176 | + foreach ($this->_subsections as $name => $subsection) { |
|
1177 | + $subsection->_construct_finalize($this, $name); |
|
1178 | + } |
|
1179 | + } |
|
1180 | + } |
|
1181 | + |
|
1182 | + |
|
1183 | + |
|
1184 | + /** |
|
1185 | + * Just gets all validatable subsections to clean their sensitive data |
|
1186 | + */ |
|
1187 | + public function clean_sensitive_data() |
|
1188 | + { |
|
1189 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1190 | + $subsection->clean_sensitive_data(); |
|
1191 | + } |
|
1192 | + } |
|
1193 | + |
|
1194 | + |
|
1195 | + |
|
1196 | + /** |
|
1197 | + * @param string $form_submission_error_message |
|
1198 | + */ |
|
1199 | + public function set_submission_error_message($form_submission_error_message = '') |
|
1200 | + { |
|
1201 | + $this->_form_submission_error_message .= ! empty($form_submission_error_message) |
|
1202 | + ? $form_submission_error_message |
|
1203 | + : __('Form submission failed due to errors', 'event_espresso'); |
|
1204 | + } |
|
1205 | + |
|
1206 | + |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * @return string |
|
1210 | + */ |
|
1211 | + public function submission_error_message() |
|
1212 | + { |
|
1213 | + return $this->_form_submission_error_message; |
|
1214 | + } |
|
1215 | + |
|
1216 | + |
|
1217 | + |
|
1218 | + /** |
|
1219 | + * @param string $form_submission_success_message |
|
1220 | + */ |
|
1221 | + public function set_submission_success_message($form_submission_success_message) |
|
1222 | + { |
|
1223 | + $this->_form_submission_success_message .= ! empty($form_submission_success_message) |
|
1224 | + ? $form_submission_success_message |
|
1225 | + : __('Form submitted successfully', 'event_espresso'); |
|
1226 | + } |
|
1227 | + |
|
1228 | + |
|
1229 | + |
|
1230 | + /** |
|
1231 | + * @return string |
|
1232 | + */ |
|
1233 | + public function submission_success_message() |
|
1234 | + { |
|
1235 | + return $this->_form_submission_success_message; |
|
1236 | + } |
|
1237 | + |
|
1238 | + |
|
1239 | + |
|
1240 | + /** |
|
1241 | + * Returns the prefix that should be used on child of this form section for |
|
1242 | + * their html names. If this form section itself has a parent, prepends ITS |
|
1243 | + * prefix onto this form section's prefix. Used primarily by |
|
1244 | + * EE_Form_Input_Base::_set_default_html_name_if_empty |
|
1245 | + * |
|
1246 | + * @return string |
|
1247 | + * @throws \EE_Error |
|
1248 | + */ |
|
1249 | + public function html_name_prefix() |
|
1250 | + { |
|
1251 | + if ($this->parent_section() instanceof EE_Form_Section_Proper) { |
|
1252 | + return $this->parent_section()->html_name_prefix() . '[' . $this->name() . ']'; |
|
1253 | + } else { |
|
1254 | + return $this->name(); |
|
1255 | + } |
|
1256 | + } |
|
1257 | + |
|
1258 | + |
|
1259 | + |
|
1260 | + /** |
|
1261 | + * Gets the name, but first checks _construct_finalize has been called. If not, |
|
1262 | + * calls it (assumes there is no parent and that we want the name to be whatever |
|
1263 | + * was set, which is probably nothing, or the classname) |
|
1264 | + * |
|
1265 | + * @return string |
|
1266 | + * @throws \EE_Error |
|
1267 | + */ |
|
1268 | + public function name() |
|
1269 | + { |
|
1270 | + $this->ensure_construct_finalized_called(); |
|
1271 | + return parent::name(); |
|
1272 | + } |
|
1273 | + |
|
1274 | + |
|
1275 | + |
|
1276 | + /** |
|
1277 | + * @return EE_Form_Section_Proper |
|
1278 | + * @throws \EE_Error |
|
1279 | + */ |
|
1280 | + public function parent_section() |
|
1281 | + { |
|
1282 | + $this->ensure_construct_finalized_called(); |
|
1283 | + return parent::parent_section(); |
|
1284 | + } |
|
1285 | + |
|
1286 | + |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * make sure construction finalized was called, otherwise children might not be ready |
|
1290 | + * |
|
1291 | + * @return void |
|
1292 | + * @throws \EE_Error |
|
1293 | + */ |
|
1294 | + public function ensure_construct_finalized_called() |
|
1295 | + { |
|
1296 | + if (! $this->_construction_finalized) { |
|
1297 | + $this->_construct_finalize($this->_parent_section, $this->_name); |
|
1298 | + } |
|
1299 | + } |
|
1300 | + |
|
1301 | + |
|
1302 | + |
|
1303 | + /** |
|
1304 | + * Checks if any of this form section's inputs, or any of its children's inputs, |
|
1305 | + * are in teh form data. If any are found, returns true. Else false |
|
1306 | + * |
|
1307 | + * @param array $req_data |
|
1308 | + * @return boolean |
|
1309 | + */ |
|
1310 | + public function form_data_present_in($req_data = null) |
|
1311 | + { |
|
1312 | + if ($req_data === null) { |
|
1313 | + $req_data = $_POST; |
|
1314 | + } |
|
1315 | + foreach ($this->subsections() as $subsection) { |
|
1316 | + if ($subsection instanceof EE_Form_Input_Base) { |
|
1317 | + if ($subsection->form_data_present_in($req_data)) { |
|
1318 | + return true; |
|
1319 | + } |
|
1320 | + } elseif ($subsection instanceof EE_Form_Section_Proper) { |
|
1321 | + if ($subsection->form_data_present_in($req_data)) { |
|
1322 | + return true; |
|
1323 | + } |
|
1324 | + } |
|
1325 | + } |
|
1326 | + return false; |
|
1327 | + } |
|
1328 | + |
|
1329 | + |
|
1330 | + |
|
1331 | + /** |
|
1332 | + * Gets validation errors for this form section and subsections |
|
1333 | + * Similar to EE_Form_Section_Validatable::get_validation_errors() except this |
|
1334 | + * gets the validation errors for ALL subsection |
|
1335 | + * |
|
1336 | + * @return EE_Validation_Error[] |
|
1337 | + */ |
|
1338 | + public function get_validation_errors_accumulated() |
|
1339 | + { |
|
1340 | + $validation_errors = $this->get_validation_errors(); |
|
1341 | + foreach ($this->get_validatable_subsections() as $subsection) { |
|
1342 | + if ($subsection instanceof EE_Form_Section_Proper) { |
|
1343 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors_accumulated(); |
|
1344 | + } else { |
|
1345 | + $validation_errors_on_this_subsection = $subsection->get_validation_errors(); |
|
1346 | + } |
|
1347 | + if ($validation_errors_on_this_subsection) { |
|
1348 | + $validation_errors = array_merge($validation_errors, $validation_errors_on_this_subsection); |
|
1349 | + } |
|
1350 | + } |
|
1351 | + return $validation_errors; |
|
1352 | + } |
|
1353 | + |
|
1354 | + |
|
1355 | + |
|
1356 | + /** |
|
1357 | + * This isn't just the name of an input, it's a path pointing to an input. The |
|
1358 | + * path is similar to a folder path: slash (/) means to descend into a subsection, |
|
1359 | + * dot-dot-slash (../) means to ascend into the parent section. |
|
1360 | + * After a series of slashes and dot-dot-slashes, there should be the name of an input, |
|
1361 | + * which will be returned. |
|
1362 | + * Eg, if you want the related input to be conditional on a sibling input name 'foobar' |
|
1363 | + * just use 'foobar'. If you want it to be conditional on an aunt/uncle input name |
|
1364 | + * 'baz', use '../baz'. If you want it to be conditional on a cousin input, |
|
1365 | + * the child of 'baz_section' named 'baz_child', use '../baz_section/baz_child'. |
|
1366 | + * Etc |
|
1367 | + * |
|
1368 | + * @param string|false $form_section_path we accept false also because substr( '../', '../' ) = false |
|
1369 | + * @return EE_Form_Section_Base |
|
1370 | + */ |
|
1371 | + public function find_section_from_path($form_section_path) |
|
1372 | + { |
|
1373 | + //check if we can find the input from purely going straight up the tree |
|
1374 | + $input = parent::find_section_from_path($form_section_path); |
|
1375 | + if ($input instanceof EE_Form_Section_Base) { |
|
1376 | + return $input; |
|
1377 | + } |
|
1378 | + $next_slash_pos = strpos($form_section_path, '/'); |
|
1379 | + if ($next_slash_pos !== false) { |
|
1380 | + $child_section_name = substr($form_section_path, 0, $next_slash_pos); |
|
1381 | + $subpath = substr($form_section_path, $next_slash_pos + 1); |
|
1382 | + } else { |
|
1383 | + $child_section_name = $form_section_path; |
|
1384 | + $subpath = ''; |
|
1385 | + } |
|
1386 | + $child_section = $this->get_subsection($child_section_name); |
|
1387 | + if ($child_section instanceof EE_Form_Section_Base) { |
|
1388 | + return $child_section->find_section_from_path($subpath); |
|
1389 | + } else { |
|
1390 | + return null; |
|
1391 | + } |
|
1392 | + } |
|
1393 | 1393 | |
1394 | 1394 | } |
1395 | 1395 |