@@ -20,33 +20,33 @@ |
||
20 | 20 | class Windows1252 extends FormatterBase |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Converts the string to windows-1252 encoding. |
|
25 | - * |
|
26 | - * @param string|int|float $input anything easily cast into a string |
|
27 | - * @return string |
|
28 | - */ |
|
29 | - public function format($input) |
|
30 | - { |
|
31 | - //in case an int or float etc was passed in |
|
32 | - $input = (string)$input; |
|
33 | - if (function_exists('iconv')) { |
|
34 | - $input = iconv('utf-8', 'cp1252//TRANSLIT', $input); |
|
35 | - } elseif ( WP_DEBUG) { |
|
36 | - trigger_error( |
|
37 | - sprintf( |
|
38 | - // @codingStandardsIgnoreStart |
|
39 | - esc_html__('%1$s could not format the string "%2$s" because the function "%3$s" does not exist. Please verify PHP is installed with this function, see %4$s', 'event_espresso'), |
|
40 | - // @codingStandardsIgnoreEnd |
|
41 | - get_class($this), |
|
42 | - $input, |
|
43 | - 'iconv', |
|
44 | - '<a href="http://php.net/manual/en/iconv.installation.php">http://php.net/manual/en/iconv.installation.php</a>' |
|
45 | - ) |
|
46 | - ); |
|
47 | - } |
|
48 | - return $input; |
|
49 | - } |
|
23 | + /** |
|
24 | + * Converts the string to windows-1252 encoding. |
|
25 | + * |
|
26 | + * @param string|int|float $input anything easily cast into a string |
|
27 | + * @return string |
|
28 | + */ |
|
29 | + public function format($input) |
|
30 | + { |
|
31 | + //in case an int or float etc was passed in |
|
32 | + $input = (string)$input; |
|
33 | + if (function_exists('iconv')) { |
|
34 | + $input = iconv('utf-8', 'cp1252//TRANSLIT', $input); |
|
35 | + } elseif ( WP_DEBUG) { |
|
36 | + trigger_error( |
|
37 | + sprintf( |
|
38 | + // @codingStandardsIgnoreStart |
|
39 | + esc_html__('%1$s could not format the string "%2$s" because the function "%3$s" does not exist. Please verify PHP is installed with this function, see %4$s', 'event_espresso'), |
|
40 | + // @codingStandardsIgnoreEnd |
|
41 | + get_class($this), |
|
42 | + $input, |
|
43 | + 'iconv', |
|
44 | + '<a href="http://php.net/manual/en/iconv.installation.php">http://php.net/manual/en/iconv.installation.php</a>' |
|
45 | + ) |
|
46 | + ); |
|
47 | + } |
|
48 | + return $input; |
|
49 | + } |
|
50 | 50 | } |
51 | 51 | // End of file EmojiRemoval.php |
52 | 52 | // Location: core\services\formatters/EmojiRemoval.php |
@@ -29,10 +29,10 @@ |
||
29 | 29 | public function format($input) |
30 | 30 | { |
31 | 31 | //in case an int or float etc was passed in |
32 | - $input = (string)$input; |
|
32 | + $input = (string) $input; |
|
33 | 33 | if (function_exists('iconv')) { |
34 | 34 | $input = iconv('utf-8', 'cp1252//TRANSLIT', $input); |
35 | - } elseif ( WP_DEBUG) { |
|
35 | + } elseif (WP_DEBUG) { |
|
36 | 36 | trigger_error( |
37 | 37 | sprintf( |
38 | 38 | // @codingStandardsIgnoreStart |
@@ -108,10 +108,10 @@ |
||
108 | 108 | } |
109 | 109 | } |
110 | 110 | $csv_data[] = apply_filters( |
111 | - 'FHEE___EventEspresso_core_libraries_batch_JobHandlers_AttendeesReport__get_csv_data__row', |
|
112 | - $csv_row, |
|
113 | - $attendee_row |
|
114 | - ); |
|
111 | + 'FHEE___EventEspresso_core_libraries_batch_JobHandlers_AttendeesReport__get_csv_data__row', |
|
112 | + $csv_row, |
|
113 | + $attendee_row |
|
114 | + ); |
|
115 | 115 | } |
116 | 116 | return $csv_data; |
117 | 117 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | use EventEspressoBatchRequest\Helpers\JobParameters; |
19 | 19 | use EventEspressoBatchRequest\Helpers\JobStepResponse; |
20 | 20 | |
21 | -if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
21 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
22 | 22 | exit('No direct script access allowed'); |
23 | 23 | } |
24 | 24 | |
@@ -27,84 +27,84 @@ discard block |
||
27 | 27 | |
28 | 28 | |
29 | 29 | public function create_job(JobParameters $job_parameters) { |
30 | - if( ! \EE_Capabilities::instance()->current_user_can( 'ee_read_contacts', 'generating_report' ) ) { |
|
30 | + if ( ! \EE_Capabilities::instance()->current_user_can('ee_read_contacts', 'generating_report')) { |
|
31 | 31 | throw new BatchRequestException( |
32 | - __( 'You do not have permission to view contacts', 'event_espresso') |
|
32 | + __('You do not have permission to view contacts', 'event_espresso') |
|
33 | 33 | ); |
34 | 34 | } |
35 | 35 | $filepath = $this->create_file_from_job_with_name( |
36 | 36 | $job_parameters->job_id(), |
37 | 37 | __('contact-list-report.csv', 'event_espresso') |
38 | 38 | ); |
39 | - $job_parameters->add_extra_data( 'filepath', $filepath ); |
|
40 | - $job_parameters->set_job_size( $this->count_units_to_process() ); |
|
39 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
40 | + $job_parameters->set_job_size($this->count_units_to_process()); |
|
41 | 41 | //we should also set the header columns |
42 | - $csv_data_for_row = $this->get_csv_data( 0, 1 ); |
|
43 | - \EEH_Export::write_data_array_to_csv( $filepath, $csv_data_for_row, true ); |
|
42 | + $csv_data_for_row = $this->get_csv_data(0, 1); |
|
43 | + \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
44 | 44 | //if we actually processed a row there, record it |
45 | - if( $job_parameters->job_size() ) { |
|
46 | - $job_parameters->mark_processed( 1 ); |
|
45 | + if ($job_parameters->job_size()) { |
|
46 | + $job_parameters->mark_processed(1); |
|
47 | 47 | } |
48 | 48 | return new JobStepResponse( |
49 | 49 | $job_parameters, |
50 | - __( 'Contacts report started successfully...', 'event_espresso' ) |
|
50 | + __('Contacts report started successfully...', 'event_espresso') |
|
51 | 51 | ); |
52 | 52 | } |
53 | 53 | |
54 | 54 | |
55 | 55 | public function continue_job(JobParameters $job_parameters, $batch_size = 50) { |
56 | - $csv_data = $this->get_csv_data( $job_parameters->units_processed(), $batch_size ); |
|
57 | - \EEH_Export::write_data_array_to_csv( $job_parameters->extra_datum( 'filepath' ), $csv_data, false ); |
|
58 | - $units_processed = count( $csv_data ); |
|
59 | - $job_parameters->mark_processed( $units_processed ); |
|
56 | + $csv_data = $this->get_csv_data($job_parameters->units_processed(), $batch_size); |
|
57 | + \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
58 | + $units_processed = count($csv_data); |
|
59 | + $job_parameters->mark_processed($units_processed); |
|
60 | 60 | $extra_response_data = array( |
61 | 61 | 'file_url' => '' |
62 | 62 | ); |
63 | - if( $units_processed < $batch_size ) { |
|
64 | - $job_parameters->set_status( JobParameters::status_complete ); |
|
65 | - $extra_response_data[ 'file_url' ] = $this->get_url_to_file( $job_parameters->extra_datum( 'filepath' ) ); |
|
63 | + if ($units_processed < $batch_size) { |
|
64 | + $job_parameters->set_status(JobParameters::status_complete); |
|
65 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
66 | 66 | } |
67 | 67 | return new JobStepResponse( |
68 | 68 | $job_parameters, |
69 | 69 | sprintf( |
70 | - __( 'Wrote %1$s rows to report CSV file...', 'event_espresso' ), |
|
71 | - count( $csv_data ) ), |
|
70 | + __('Wrote %1$s rows to report CSV file...', 'event_espresso'), |
|
71 | + count($csv_data) ), |
|
72 | 72 | $extra_response_data ); |
73 | 73 | } |
74 | 74 | |
75 | 75 | |
76 | 76 | public function cleanup_job(JobParameters $job_parameters) { |
77 | 77 | $this->_file_helper->delete( |
78 | - \EEH_File::remove_filename_from_filepath( $job_parameters->extra_datum( 'filepath' ) ), |
|
78 | + \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
79 | 79 | true, |
80 | 80 | 'd' |
81 | 81 | ); |
82 | - return new JobStepResponse( $job_parameters, __( 'Cleaned up temporary file', 'event_espresso' ) ); |
|
82 | + return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | public function count_units_to_process() { |
86 | - return \EEM_Attendee::instance()->count( array( 'caps' => \EEM_Base::caps_read_admin )); |
|
86 | + return \EEM_Attendee::instance()->count(array('caps' => \EEM_Base::caps_read_admin)); |
|
87 | 87 | } |
88 | - public function get_csv_data( $offset, $limit ) { |
|
88 | + public function get_csv_data($offset, $limit) { |
|
89 | 89 | $attendee_rows = \EEM_Attendee::instance()->get_all_wpdb_results( |
90 | 90 | array( |
91 | - 'limit' => array( $offset, $limit ), |
|
92 | - 'force_join' => array( 'State', 'Country' ), |
|
91 | + 'limit' => array($offset, $limit), |
|
92 | + 'force_join' => array('State', 'Country'), |
|
93 | 93 | 'caps' => \EEM_Base::caps_read_admin |
94 | 94 | ) |
95 | 95 | ); |
96 | 96 | $csv_data = array(); |
97 | - foreach( $attendee_rows as $attendee_row ){ |
|
97 | + foreach ($attendee_rows as $attendee_row) { |
|
98 | 98 | $csv_row = array(); |
99 | - foreach( \EEM_Attendee::instance()->field_settings() as $field_name => $field_obj ){ |
|
100 | - if( $field_name == 'STA_ID' ){ |
|
101 | - $state_name_field = \EEM_State::instance()->field_settings_for( 'STA_name' ); |
|
102 | - $csv_row[ __( 'State', 'event_espresso' ) ] = $attendee_row[ $state_name_field->get_qualified_column() ]; |
|
103 | - }elseif( $field_name == 'CNT_ISO' ){ |
|
104 | - $country_name_field = \EEM_Country::instance()->field_settings_for( 'CNT_name' ); |
|
105 | - $csv_row[ __( 'Country', 'event_espresso' ) ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
106 | - }else{ |
|
107 | - $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
99 | + foreach (\EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
100 | + if ($field_name == 'STA_ID') { |
|
101 | + $state_name_field = \EEM_State::instance()->field_settings_for('STA_name'); |
|
102 | + $csv_row[__('State', 'event_espresso')] = $attendee_row[$state_name_field->get_qualified_column()]; |
|
103 | + }elseif ($field_name == 'CNT_ISO') { |
|
104 | + $country_name_field = \EEM_Country::instance()->field_settings_for('CNT_name'); |
|
105 | + $csv_row[__('Country', 'event_espresso')] = $attendee_row[$country_name_field->get_qualified_column()]; |
|
106 | + } else { |
|
107 | + $csv_row[$field_obj->get_nicename()] = $attendee_row[$field_obj->get_qualified_column()]; |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | $csv_data[] = apply_filters( |
@@ -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 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
117 | 117 | { |
118 | 118 | // check if class object is instantiated, and instantiated properly |
119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
119 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | 120 | self::$_instance = new EE_Dependency_Map($request, $response); |
121 | 121 | } |
122 | 122 | return self::$_instance; |
@@ -141,15 +141,15 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public static function register_dependencies($class, $dependencies) |
143 | 143 | { |
144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
144 | + if ( ! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | 145 | // we need to make sure that any aliases used when registering a dependency |
146 | 146 | // get resolved to the correct class name |
147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
147 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
148 | 148 | $alias = self::$_instance->get_alias($dependency); |
149 | 149 | unset($dependencies[$dependency]); |
150 | 150 | $dependencies[$alias] = $load_source; |
151 | 151 | } |
152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
152 | + self::$_instance->_dependency_map[$class] = (array) $dependencies; |
|
153 | 153 | return true; |
154 | 154 | } |
155 | 155 | return false; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ); |
182 | 182 | } |
183 | 183 | $class_name = self::$_instance->get_alias($class_name); |
184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
184 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | 185 | self::$_instance->_class_loaders[$class_name] = $loader; |
186 | 186 | return true; |
187 | 187 | } |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | public function add_alias($class_name, $alias, $for_class = '') |
280 | 280 | { |
281 | 281 | if ($for_class !== '') { |
282 | - if (! isset($this->_aliases[$for_class])) { |
|
282 | + if ( ! isset($this->_aliases[$for_class])) { |
|
283 | 283 | $this->_aliases[$for_class] = array(); |
284 | 284 | } |
285 | 285 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | */ |
325 | 325 | public function get_alias($class_name = '', $for_class = '') |
326 | 326 | { |
327 | - if (! $this->has_alias($class_name, $for_class)) { |
|
327 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
328 | 328 | return $class_name; |
329 | 329 | } |
330 | 330 | if ($for_class !== '') { |
@@ -526,10 +526,10 @@ discard block |
||
526 | 526 | 'EE_Front_Controller' => 'load_core', |
527 | 527 | 'EE_Module_Request_Router' => 'load_core', |
528 | 528 | 'EE_Registry' => 'load_core', |
529 | - 'EE_Request' => function () use (&$request) { |
|
529 | + 'EE_Request' => function() use (&$request) { |
|
530 | 530 | return $request; |
531 | 531 | }, |
532 | - 'EE_Response' => function () use (&$response) { |
|
532 | + 'EE_Response' => function() use (&$response) { |
|
533 | 533 | return $response; |
534 | 534 | }, |
535 | 535 | 'EE_Request_Handler' => 'load_core', |
@@ -546,10 +546,10 @@ discard block |
||
546 | 546 | 'EE_Messages_Queue' => 'load_lib', |
547 | 547 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
548 | 548 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
549 | - 'EE_Messages_Generator' => function () { |
|
549 | + 'EE_Messages_Generator' => function() { |
|
550 | 550 | return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
551 | 551 | }, |
552 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
552 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
553 | 553 | return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
554 | 554 | }, |
555 | 555 | //load_model |
@@ -557,13 +557,13 @@ discard block |
||
557 | 557 | 'EEM_Message_Template_Group' => 'load_model', |
558 | 558 | 'EEM_Message_Template' => 'load_model', |
559 | 559 | //load_helper |
560 | - 'EEH_Parse_Shortcodes' => function () { |
|
560 | + 'EEH_Parse_Shortcodes' => function() { |
|
561 | 561 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
562 | 562 | return new EEH_Parse_Shortcodes(); |
563 | 563 | } |
564 | 564 | return null; |
565 | 565 | }, |
566 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
566 | + 'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) { |
|
567 | 567 | return $loader; |
568 | 568 | }, |
569 | 569 | ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -22,629 +22,629 @@ discard block |
||
22 | 22 | { |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * This means that the requested class dependency is not present in the dependency map |
|
27 | - */ |
|
28 | - const not_registered = 0; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
33 | - */ |
|
34 | - const load_new_object = 1; |
|
35 | - |
|
36 | - /** |
|
37 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
38 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
39 | - */ |
|
40 | - const load_from_cache = 2; |
|
41 | - |
|
42 | - /** |
|
43 | - * @type EE_Dependency_Map $_instance |
|
44 | - */ |
|
45 | - protected static $_instance; |
|
46 | - |
|
47 | - /** |
|
48 | - * @type EE_Request $request |
|
49 | - */ |
|
50 | - protected $_request; |
|
51 | - |
|
52 | - /** |
|
53 | - * @type EE_Response $response |
|
54 | - */ |
|
55 | - protected $_response; |
|
56 | - |
|
57 | - /** |
|
58 | - * @type LoaderInterface $loader |
|
59 | - */ |
|
60 | - protected $loader; |
|
61 | - |
|
62 | - /** |
|
63 | - * @type array $_dependency_map |
|
64 | - */ |
|
65 | - protected $_dependency_map = array(); |
|
66 | - |
|
67 | - /** |
|
68 | - * @type array $_class_loaders |
|
69 | - */ |
|
70 | - protected $_class_loaders = array(); |
|
71 | - |
|
72 | - /** |
|
73 | - * @type array $_aliases |
|
74 | - */ |
|
75 | - protected $_aliases = array(); |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * EE_Dependency_Map constructor. |
|
81 | - * |
|
82 | - * @param EE_Request $request |
|
83 | - * @param EE_Response $response |
|
84 | - */ |
|
85 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
86 | - { |
|
87 | - $this->_request = $request; |
|
88 | - $this->_response = $response; |
|
89 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
90 | - do_action('EE_Dependency_Map____construct'); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - * @throws InvalidInterfaceException |
|
98 | - * @throws InvalidArgumentException |
|
99 | - */ |
|
100 | - public function initialize() |
|
101 | - { |
|
102 | - $this->_register_core_dependencies(); |
|
103 | - $this->_register_core_class_loaders(); |
|
104 | - $this->_register_core_aliases(); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @singleton method used to instantiate class object |
|
111 | - * @access public |
|
112 | - * @param EE_Request $request |
|
113 | - * @param EE_Response $response |
|
114 | - * @return EE_Dependency_Map |
|
115 | - */ |
|
116 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
117 | - { |
|
118 | - // check if class object is instantiated, and instantiated properly |
|
119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
121 | - } |
|
122 | - return self::$_instance; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param LoaderInterface $loader |
|
129 | - */ |
|
130 | - public function setLoader(LoaderInterface $loader) |
|
131 | - { |
|
132 | - $this->loader = $loader; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param string $class |
|
139 | - * @param array $dependencies |
|
140 | - * @return boolean |
|
141 | - */ |
|
142 | - public static function register_dependencies($class, $dependencies) |
|
143 | - { |
|
144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | - // we need to make sure that any aliases used when registering a dependency |
|
146 | - // get resolved to the correct class name |
|
147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
148 | - $alias = self::$_instance->get_alias($dependency); |
|
149 | - unset($dependencies[$dependency]); |
|
150 | - $dependencies[$alias] = $load_source; |
|
151 | - } |
|
152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
153 | - return true; |
|
154 | - } |
|
155 | - return false; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @param string $class_name |
|
162 | - * @param string $loader |
|
163 | - * @return bool |
|
164 | - * @throws EE_Error |
|
165 | - */ |
|
166 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
167 | - { |
|
168 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
169 | - if ( |
|
170 | - ! is_callable($loader) |
|
171 | - && ( |
|
172 | - strpos($loader, 'load_') !== 0 |
|
173 | - || ! method_exists('EE_Registry', $loader) |
|
174 | - ) |
|
175 | - ) { |
|
176 | - throw new EE_Error( |
|
177 | - sprintf( |
|
178 | - esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
179 | - $loader |
|
180 | - ) |
|
181 | - ); |
|
182 | - } |
|
183 | - $class_name = self::$_instance->get_alias($class_name); |
|
184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
186 | - return true; |
|
187 | - } |
|
188 | - return false; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @return array |
|
195 | - */ |
|
196 | - public function dependency_map() |
|
197 | - { |
|
198 | - return $this->_dependency_map; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
205 | - * |
|
206 | - * @param string $class_name |
|
207 | - * @return boolean |
|
208 | - */ |
|
209 | - public function has($class_name = '') |
|
210 | - { |
|
211 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
218 | - * |
|
219 | - * @param string $class_name |
|
220 | - * @param string $dependency |
|
221 | - * @return bool |
|
222 | - */ |
|
223 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
224 | - { |
|
225 | - $dependency = $this->get_alias($dependency); |
|
226 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
227 | - ? true |
|
228 | - : false; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
235 | - * |
|
236 | - * @param string $class_name |
|
237 | - * @param string $dependency |
|
238 | - * @return int |
|
239 | - */ |
|
240 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
241 | - { |
|
242 | - $dependency = $this->get_alias($dependency); |
|
243 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
244 | - ? $this->_dependency_map[$class_name][$dependency] |
|
245 | - : EE_Dependency_Map::not_registered; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param string $class_name |
|
252 | - * @return string | Closure |
|
253 | - */ |
|
254 | - public function class_loader($class_name) |
|
255 | - { |
|
256 | - $class_name = $this->get_alias($class_name); |
|
257 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @return array |
|
264 | - */ |
|
265 | - public function class_loaders() |
|
266 | - { |
|
267 | - return $this->_class_loaders; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * adds an alias for a classname |
|
274 | - * |
|
275 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
276 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
277 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
278 | - */ |
|
279 | - public function add_alias($class_name, $alias, $for_class = '') |
|
280 | - { |
|
281 | - if ($for_class !== '') { |
|
282 | - if (! isset($this->_aliases[$for_class])) { |
|
283 | - $this->_aliases[$for_class] = array(); |
|
284 | - } |
|
285 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
286 | - } |
|
287 | - $this->_aliases[$class_name] = $alias; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * returns TRUE if the provided class name has an alias |
|
294 | - * |
|
295 | - * @param string $class_name |
|
296 | - * @param string $for_class |
|
297 | - * @return bool |
|
298 | - */ |
|
299 | - public function has_alias($class_name = '', $for_class = '') |
|
300 | - { |
|
301 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
302 | - || ( |
|
303 | - isset($this->_aliases[$class_name]) |
|
304 | - && ! is_array($this->_aliases[$class_name]) |
|
305 | - ); |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
312 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
313 | - * for example: |
|
314 | - * if the following two entries were added to the _aliases array: |
|
315 | - * array( |
|
316 | - * 'interface_alias' => 'some\namespace\interface' |
|
317 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
318 | - * ) |
|
319 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
320 | - * to load an instance of 'some\namespace\classname' |
|
321 | - * |
|
322 | - * @param string $class_name |
|
323 | - * @param string $for_class |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - public function get_alias($class_name = '', $for_class = '') |
|
327 | - { |
|
328 | - if (! $this->has_alias($class_name, $for_class)) { |
|
329 | - return $class_name; |
|
330 | - } |
|
331 | - if ($for_class !== '') { |
|
332 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
333 | - } |
|
334 | - return $this->get_alias($this->_aliases[$class_name]); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
341 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
342 | - * This is done by using the following class constants: |
|
343 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
344 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
345 | - */ |
|
346 | - protected function _register_core_dependencies() |
|
347 | - { |
|
348 | - $this->_dependency_map = array( |
|
349 | - 'EE_Request_Handler' => array( |
|
350 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
351 | - ), |
|
352 | - 'EE_System' => array( |
|
353 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
354 | - ), |
|
355 | - 'EE_Session' => array( |
|
356 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
357 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
358 | - ), |
|
359 | - 'EE_Cart' => array( |
|
360 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
361 | - ), |
|
362 | - 'EE_Front_Controller' => array( |
|
363 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
364 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
365 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
366 | - ), |
|
367 | - 'EE_Messenger_Collection_Loader' => array( |
|
368 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
369 | - ), |
|
370 | - 'EE_Message_Type_Collection_Loader' => array( |
|
371 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
372 | - ), |
|
373 | - 'EE_Message_Resource_Manager' => array( |
|
374 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
375 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
376 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
377 | - ), |
|
378 | - 'EE_Message_Factory' => array( |
|
379 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
380 | - ), |
|
381 | - 'EE_messages' => array( |
|
382 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
383 | - ), |
|
384 | - 'EE_Messages_Generator' => array( |
|
385 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
386 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
387 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
388 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
389 | - ), |
|
390 | - 'EE_Messages_Processor' => array( |
|
391 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
392 | - ), |
|
393 | - 'EE_Messages_Queue' => array( |
|
394 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
395 | - ), |
|
396 | - 'EE_Messages_Template_Defaults' => array( |
|
397 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
398 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
399 | - ), |
|
400 | - 'EE_Message_To_Generate_From_Request' => array( |
|
401 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
402 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
403 | - ), |
|
404 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
405 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
406 | - ), |
|
407 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
408 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
409 | - ), |
|
410 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
411 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
412 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
413 | - ), |
|
414 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
415 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
416 | - ), |
|
417 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
418 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
419 | - ), |
|
420 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
421 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
422 | - ), |
|
423 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
424 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
425 | - ), |
|
426 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
427 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
428 | - ), |
|
429 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
430 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
431 | - ), |
|
432 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
433 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
434 | - ), |
|
435 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
436 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
437 | - ), |
|
438 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
439 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
440 | - ), |
|
441 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
442 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
443 | - ), |
|
444 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
445 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
446 | - ), |
|
447 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
448 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
449 | - ), |
|
450 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
451 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
452 | - ), |
|
453 | - 'EE_Data_Migration_Class_Base' => array( |
|
454 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
455 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
456 | - ), |
|
457 | - 'EE_DMS_Core_4_1_0' => array( |
|
458 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
460 | - ), |
|
461 | - 'EE_DMS_Core_4_2_0' => array( |
|
462 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
463 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
464 | - ), |
|
465 | - 'EE_DMS_Core_4_3_0' => array( |
|
466 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
467 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
468 | - ), |
|
469 | - 'EE_DMS_Core_4_4_0' => array( |
|
470 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
471 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
472 | - ), |
|
473 | - 'EE_DMS_Core_4_5_0' => array( |
|
474 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
475 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
476 | - ), |
|
477 | - 'EE_DMS_Core_4_6_0' => array( |
|
478 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
479 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
480 | - ), |
|
481 | - 'EE_DMS_Core_4_7_0' => array( |
|
482 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
483 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
484 | - ), |
|
485 | - 'EE_DMS_Core_4_8_0' => array( |
|
486 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
487 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
488 | - ), |
|
489 | - 'EE_DMS_Core_4_9_0' => array( |
|
490 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
491 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
492 | - ), |
|
493 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
494 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
495 | - ), |
|
496 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
497 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
498 | - ), |
|
499 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
500 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
501 | - ), |
|
502 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
503 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
504 | - ), |
|
505 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
506 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
507 | - ), |
|
508 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
509 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
510 | - ), |
|
511 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
512 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
513 | - ), |
|
514 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
515 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
516 | - ), |
|
517 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
518 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
519 | - ), |
|
520 | - ); |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * Registers how core classes are loaded. |
|
527 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
528 | - * 'EE_Request_Handler' => 'load_core' |
|
529 | - * 'EE_Messages_Queue' => 'load_lib' |
|
530 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
531 | - * or, if greater control is required, by providing a custom closure. For example: |
|
532 | - * 'Some_Class' => function () { |
|
533 | - * return new Some_Class(); |
|
534 | - * }, |
|
535 | - * This is required for instantiating dependencies |
|
536 | - * where an interface has been type hinted in a class constructor. For example: |
|
537 | - * 'Required_Interface' => function () { |
|
538 | - * return new A_Class_That_Implements_Required_Interface(); |
|
539 | - * }, |
|
540 | - */ |
|
541 | - protected function _register_core_class_loaders() |
|
542 | - { |
|
543 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
544 | - //be used in a closure. |
|
545 | - $request = &$this->_request; |
|
546 | - $response = &$this->_response; |
|
547 | - $loader = &$this->loader; |
|
548 | - $this->_class_loaders = array( |
|
549 | - //load_core |
|
550 | - 'EE_Capabilities' => 'load_core', |
|
551 | - 'EE_Encryption' => 'load_core', |
|
552 | - 'EE_Front_Controller' => 'load_core', |
|
553 | - 'EE_Module_Request_Router' => 'load_core', |
|
554 | - 'EE_Registry' => 'load_core', |
|
555 | - 'EE_Request' => function () use (&$request) { |
|
556 | - return $request; |
|
557 | - }, |
|
558 | - 'EE_Response' => function () use (&$response) { |
|
559 | - return $response; |
|
560 | - }, |
|
561 | - 'EE_Request_Handler' => 'load_core', |
|
562 | - 'EE_Session' => 'load_core', |
|
563 | - 'EE_System' => 'load_core', |
|
564 | - //load_lib |
|
565 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
566 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
567 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
568 | - 'EE_Messenger_Collection' => 'load_lib', |
|
569 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
570 | - 'EE_Messages_Processor' => 'load_lib', |
|
571 | - 'EE_Message_Repository' => 'load_lib', |
|
572 | - 'EE_Messages_Queue' => 'load_lib', |
|
573 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
574 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
575 | - 'EE_Messages_Generator' => function () { |
|
576 | - return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
577 | - }, |
|
578 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
579 | - return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
580 | - }, |
|
581 | - //load_model |
|
582 | - 'EEM_Message_Template_Group' => 'load_model', |
|
583 | - 'EEM_Message_Template' => 'load_model', |
|
584 | - //load_helper |
|
585 | - 'EEH_Parse_Shortcodes' => function () { |
|
586 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
587 | - return new EEH_Parse_Shortcodes(); |
|
588 | - } |
|
589 | - return null; |
|
590 | - }, |
|
591 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
592 | - return $loader; |
|
593 | - }, |
|
594 | - ); |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * can be used for supplying alternate names for classes, |
|
601 | - * or for connecting interface names to instantiable classes |
|
602 | - */ |
|
603 | - protected function _register_core_aliases() |
|
604 | - { |
|
605 | - $this->_aliases = array( |
|
606 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
607 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
608 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
609 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
610 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
611 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
612 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
613 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
614 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
615 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
616 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
617 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
618 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
619 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
620 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
621 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
622 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
623 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
624 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
625 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
626 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
627 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
628 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
629 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
630 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
631 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
632 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
633 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
634 | - ); |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
641 | - * request Primarily used by unit tests. |
|
642 | - */ |
|
643 | - public function reset() |
|
644 | - { |
|
645 | - $this->_register_core_class_loaders(); |
|
646 | - $this->_register_core_dependencies(); |
|
647 | - } |
|
25 | + /** |
|
26 | + * This means that the requested class dependency is not present in the dependency map |
|
27 | + */ |
|
28 | + const not_registered = 0; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
33 | + */ |
|
34 | + const load_new_object = 1; |
|
35 | + |
|
36 | + /** |
|
37 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
38 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
39 | + */ |
|
40 | + const load_from_cache = 2; |
|
41 | + |
|
42 | + /** |
|
43 | + * @type EE_Dependency_Map $_instance |
|
44 | + */ |
|
45 | + protected static $_instance; |
|
46 | + |
|
47 | + /** |
|
48 | + * @type EE_Request $request |
|
49 | + */ |
|
50 | + protected $_request; |
|
51 | + |
|
52 | + /** |
|
53 | + * @type EE_Response $response |
|
54 | + */ |
|
55 | + protected $_response; |
|
56 | + |
|
57 | + /** |
|
58 | + * @type LoaderInterface $loader |
|
59 | + */ |
|
60 | + protected $loader; |
|
61 | + |
|
62 | + /** |
|
63 | + * @type array $_dependency_map |
|
64 | + */ |
|
65 | + protected $_dependency_map = array(); |
|
66 | + |
|
67 | + /** |
|
68 | + * @type array $_class_loaders |
|
69 | + */ |
|
70 | + protected $_class_loaders = array(); |
|
71 | + |
|
72 | + /** |
|
73 | + * @type array $_aliases |
|
74 | + */ |
|
75 | + protected $_aliases = array(); |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * EE_Dependency_Map constructor. |
|
81 | + * |
|
82 | + * @param EE_Request $request |
|
83 | + * @param EE_Response $response |
|
84 | + */ |
|
85 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
86 | + { |
|
87 | + $this->_request = $request; |
|
88 | + $this->_response = $response; |
|
89 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
90 | + do_action('EE_Dependency_Map____construct'); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + * @throws InvalidInterfaceException |
|
98 | + * @throws InvalidArgumentException |
|
99 | + */ |
|
100 | + public function initialize() |
|
101 | + { |
|
102 | + $this->_register_core_dependencies(); |
|
103 | + $this->_register_core_class_loaders(); |
|
104 | + $this->_register_core_aliases(); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @singleton method used to instantiate class object |
|
111 | + * @access public |
|
112 | + * @param EE_Request $request |
|
113 | + * @param EE_Response $response |
|
114 | + * @return EE_Dependency_Map |
|
115 | + */ |
|
116 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
117 | + { |
|
118 | + // check if class object is instantiated, and instantiated properly |
|
119 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
121 | + } |
|
122 | + return self::$_instance; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param LoaderInterface $loader |
|
129 | + */ |
|
130 | + public function setLoader(LoaderInterface $loader) |
|
131 | + { |
|
132 | + $this->loader = $loader; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param string $class |
|
139 | + * @param array $dependencies |
|
140 | + * @return boolean |
|
141 | + */ |
|
142 | + public static function register_dependencies($class, $dependencies) |
|
143 | + { |
|
144 | + if (! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | + // we need to make sure that any aliases used when registering a dependency |
|
146 | + // get resolved to the correct class name |
|
147 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
148 | + $alias = self::$_instance->get_alias($dependency); |
|
149 | + unset($dependencies[$dependency]); |
|
150 | + $dependencies[$alias] = $load_source; |
|
151 | + } |
|
152 | + self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
153 | + return true; |
|
154 | + } |
|
155 | + return false; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @param string $class_name |
|
162 | + * @param string $loader |
|
163 | + * @return bool |
|
164 | + * @throws EE_Error |
|
165 | + */ |
|
166 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
167 | + { |
|
168 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
169 | + if ( |
|
170 | + ! is_callable($loader) |
|
171 | + && ( |
|
172 | + strpos($loader, 'load_') !== 0 |
|
173 | + || ! method_exists('EE_Registry', $loader) |
|
174 | + ) |
|
175 | + ) { |
|
176 | + throw new EE_Error( |
|
177 | + sprintf( |
|
178 | + esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
179 | + $loader |
|
180 | + ) |
|
181 | + ); |
|
182 | + } |
|
183 | + $class_name = self::$_instance->get_alias($class_name); |
|
184 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
186 | + return true; |
|
187 | + } |
|
188 | + return false; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @return array |
|
195 | + */ |
|
196 | + public function dependency_map() |
|
197 | + { |
|
198 | + return $this->_dependency_map; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
205 | + * |
|
206 | + * @param string $class_name |
|
207 | + * @return boolean |
|
208 | + */ |
|
209 | + public function has($class_name = '') |
|
210 | + { |
|
211 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
218 | + * |
|
219 | + * @param string $class_name |
|
220 | + * @param string $dependency |
|
221 | + * @return bool |
|
222 | + */ |
|
223 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
224 | + { |
|
225 | + $dependency = $this->get_alias($dependency); |
|
226 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
227 | + ? true |
|
228 | + : false; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
235 | + * |
|
236 | + * @param string $class_name |
|
237 | + * @param string $dependency |
|
238 | + * @return int |
|
239 | + */ |
|
240 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
241 | + { |
|
242 | + $dependency = $this->get_alias($dependency); |
|
243 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
244 | + ? $this->_dependency_map[$class_name][$dependency] |
|
245 | + : EE_Dependency_Map::not_registered; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param string $class_name |
|
252 | + * @return string | Closure |
|
253 | + */ |
|
254 | + public function class_loader($class_name) |
|
255 | + { |
|
256 | + $class_name = $this->get_alias($class_name); |
|
257 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @return array |
|
264 | + */ |
|
265 | + public function class_loaders() |
|
266 | + { |
|
267 | + return $this->_class_loaders; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * adds an alias for a classname |
|
274 | + * |
|
275 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
276 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
277 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
278 | + */ |
|
279 | + public function add_alias($class_name, $alias, $for_class = '') |
|
280 | + { |
|
281 | + if ($for_class !== '') { |
|
282 | + if (! isset($this->_aliases[$for_class])) { |
|
283 | + $this->_aliases[$for_class] = array(); |
|
284 | + } |
|
285 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
286 | + } |
|
287 | + $this->_aliases[$class_name] = $alias; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * returns TRUE if the provided class name has an alias |
|
294 | + * |
|
295 | + * @param string $class_name |
|
296 | + * @param string $for_class |
|
297 | + * @return bool |
|
298 | + */ |
|
299 | + public function has_alias($class_name = '', $for_class = '') |
|
300 | + { |
|
301 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
302 | + || ( |
|
303 | + isset($this->_aliases[$class_name]) |
|
304 | + && ! is_array($this->_aliases[$class_name]) |
|
305 | + ); |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
312 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
313 | + * for example: |
|
314 | + * if the following two entries were added to the _aliases array: |
|
315 | + * array( |
|
316 | + * 'interface_alias' => 'some\namespace\interface' |
|
317 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
318 | + * ) |
|
319 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
320 | + * to load an instance of 'some\namespace\classname' |
|
321 | + * |
|
322 | + * @param string $class_name |
|
323 | + * @param string $for_class |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + public function get_alias($class_name = '', $for_class = '') |
|
327 | + { |
|
328 | + if (! $this->has_alias($class_name, $for_class)) { |
|
329 | + return $class_name; |
|
330 | + } |
|
331 | + if ($for_class !== '') { |
|
332 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
333 | + } |
|
334 | + return $this->get_alias($this->_aliases[$class_name]); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
341 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
342 | + * This is done by using the following class constants: |
|
343 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
344 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
345 | + */ |
|
346 | + protected function _register_core_dependencies() |
|
347 | + { |
|
348 | + $this->_dependency_map = array( |
|
349 | + 'EE_Request_Handler' => array( |
|
350 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
351 | + ), |
|
352 | + 'EE_System' => array( |
|
353 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
354 | + ), |
|
355 | + 'EE_Session' => array( |
|
356 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
357 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
358 | + ), |
|
359 | + 'EE_Cart' => array( |
|
360 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
361 | + ), |
|
362 | + 'EE_Front_Controller' => array( |
|
363 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
364 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
365 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
366 | + ), |
|
367 | + 'EE_Messenger_Collection_Loader' => array( |
|
368 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
369 | + ), |
|
370 | + 'EE_Message_Type_Collection_Loader' => array( |
|
371 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
372 | + ), |
|
373 | + 'EE_Message_Resource_Manager' => array( |
|
374 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
375 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
376 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
377 | + ), |
|
378 | + 'EE_Message_Factory' => array( |
|
379 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
380 | + ), |
|
381 | + 'EE_messages' => array( |
|
382 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
383 | + ), |
|
384 | + 'EE_Messages_Generator' => array( |
|
385 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
386 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
387 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
388 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
389 | + ), |
|
390 | + 'EE_Messages_Processor' => array( |
|
391 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
392 | + ), |
|
393 | + 'EE_Messages_Queue' => array( |
|
394 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
395 | + ), |
|
396 | + 'EE_Messages_Template_Defaults' => array( |
|
397 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
398 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
399 | + ), |
|
400 | + 'EE_Message_To_Generate_From_Request' => array( |
|
401 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
402 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
403 | + ), |
|
404 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
405 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
406 | + ), |
|
407 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
408 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
409 | + ), |
|
410 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
411 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
412 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
413 | + ), |
|
414 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
415 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
416 | + ), |
|
417 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
418 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
419 | + ), |
|
420 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
421 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
422 | + ), |
|
423 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
424 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
425 | + ), |
|
426 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
427 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
428 | + ), |
|
429 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
430 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
431 | + ), |
|
432 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
433 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
434 | + ), |
|
435 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
436 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
437 | + ), |
|
438 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
439 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
440 | + ), |
|
441 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
442 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
443 | + ), |
|
444 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
445 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
446 | + ), |
|
447 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
448 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
449 | + ), |
|
450 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
451 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
452 | + ), |
|
453 | + 'EE_Data_Migration_Class_Base' => array( |
|
454 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
455 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
456 | + ), |
|
457 | + 'EE_DMS_Core_4_1_0' => array( |
|
458 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
460 | + ), |
|
461 | + 'EE_DMS_Core_4_2_0' => array( |
|
462 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
463 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
464 | + ), |
|
465 | + 'EE_DMS_Core_4_3_0' => array( |
|
466 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
467 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
468 | + ), |
|
469 | + 'EE_DMS_Core_4_4_0' => array( |
|
470 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
471 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
472 | + ), |
|
473 | + 'EE_DMS_Core_4_5_0' => array( |
|
474 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
475 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
476 | + ), |
|
477 | + 'EE_DMS_Core_4_6_0' => array( |
|
478 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
479 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
480 | + ), |
|
481 | + 'EE_DMS_Core_4_7_0' => array( |
|
482 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
483 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
484 | + ), |
|
485 | + 'EE_DMS_Core_4_8_0' => array( |
|
486 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
487 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
488 | + ), |
|
489 | + 'EE_DMS_Core_4_9_0' => array( |
|
490 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
491 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
492 | + ), |
|
493 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
494 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
495 | + ), |
|
496 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
497 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
498 | + ), |
|
499 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
500 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
501 | + ), |
|
502 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
503 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
504 | + ), |
|
505 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
506 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
507 | + ), |
|
508 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
509 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
510 | + ), |
|
511 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
512 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
513 | + ), |
|
514 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
515 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
516 | + ), |
|
517 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
518 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
519 | + ), |
|
520 | + ); |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * Registers how core classes are loaded. |
|
527 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
528 | + * 'EE_Request_Handler' => 'load_core' |
|
529 | + * 'EE_Messages_Queue' => 'load_lib' |
|
530 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
531 | + * or, if greater control is required, by providing a custom closure. For example: |
|
532 | + * 'Some_Class' => function () { |
|
533 | + * return new Some_Class(); |
|
534 | + * }, |
|
535 | + * This is required for instantiating dependencies |
|
536 | + * where an interface has been type hinted in a class constructor. For example: |
|
537 | + * 'Required_Interface' => function () { |
|
538 | + * return new A_Class_That_Implements_Required_Interface(); |
|
539 | + * }, |
|
540 | + */ |
|
541 | + protected function _register_core_class_loaders() |
|
542 | + { |
|
543 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
544 | + //be used in a closure. |
|
545 | + $request = &$this->_request; |
|
546 | + $response = &$this->_response; |
|
547 | + $loader = &$this->loader; |
|
548 | + $this->_class_loaders = array( |
|
549 | + //load_core |
|
550 | + 'EE_Capabilities' => 'load_core', |
|
551 | + 'EE_Encryption' => 'load_core', |
|
552 | + 'EE_Front_Controller' => 'load_core', |
|
553 | + 'EE_Module_Request_Router' => 'load_core', |
|
554 | + 'EE_Registry' => 'load_core', |
|
555 | + 'EE_Request' => function () use (&$request) { |
|
556 | + return $request; |
|
557 | + }, |
|
558 | + 'EE_Response' => function () use (&$response) { |
|
559 | + return $response; |
|
560 | + }, |
|
561 | + 'EE_Request_Handler' => 'load_core', |
|
562 | + 'EE_Session' => 'load_core', |
|
563 | + 'EE_System' => 'load_core', |
|
564 | + //load_lib |
|
565 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
566 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
567 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
568 | + 'EE_Messenger_Collection' => 'load_lib', |
|
569 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
570 | + 'EE_Messages_Processor' => 'load_lib', |
|
571 | + 'EE_Message_Repository' => 'load_lib', |
|
572 | + 'EE_Messages_Queue' => 'load_lib', |
|
573 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
574 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
575 | + 'EE_Messages_Generator' => function () { |
|
576 | + return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
577 | + }, |
|
578 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
579 | + return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
580 | + }, |
|
581 | + //load_model |
|
582 | + 'EEM_Message_Template_Group' => 'load_model', |
|
583 | + 'EEM_Message_Template' => 'load_model', |
|
584 | + //load_helper |
|
585 | + 'EEH_Parse_Shortcodes' => function () { |
|
586 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
587 | + return new EEH_Parse_Shortcodes(); |
|
588 | + } |
|
589 | + return null; |
|
590 | + }, |
|
591 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
592 | + return $loader; |
|
593 | + }, |
|
594 | + ); |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * can be used for supplying alternate names for classes, |
|
601 | + * or for connecting interface names to instantiable classes |
|
602 | + */ |
|
603 | + protected function _register_core_aliases() |
|
604 | + { |
|
605 | + $this->_aliases = array( |
|
606 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
607 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
608 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
609 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
610 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
611 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
612 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
613 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
614 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
615 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
616 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
617 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
618 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
619 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
620 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
621 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
622 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
623 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
624 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
625 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
626 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
627 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
628 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
629 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
630 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
631 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
632 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
633 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
634 | + ); |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
641 | + * request Primarily used by unit tests. |
|
642 | + */ |
|
643 | + public function reset() |
|
644 | + { |
|
645 | + $this->_register_core_class_loaders(); |
|
646 | + $this->_register_core_dependencies(); |
|
647 | + } |
|
648 | 648 | |
649 | 649 | |
650 | 650 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * |
26 | 26 | * ------------------------------------------------------------------------ |
27 | 27 | */ |
28 | -class EEG_Aim extends EE_Onsite_Gateway{ |
|
28 | +class EEG_Aim extends EE_Onsite_Gateway { |
|
29 | 29 | |
30 | 30 | const LIVE_URL = 'https://secure2.authorize.net/gateway/transact.dll'; //Authnet URL |
31 | 31 | |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | * @param EEG_Aim $gateway_object |
158 | 158 | * @return string |
159 | 159 | */ |
160 | - public function possibly_use_deprecated_aim_server( $url, EEG_Aim $gateway_object ) { |
|
161 | - if( $gateway_object->_server === 'authorize.net' |
|
162 | - && ! $gateway_object->_debug_mode ) { |
|
160 | + public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object) { |
|
161 | + if ($gateway_object->_server === 'authorize.net' |
|
162 | + && ! $gateway_object->_debug_mode) { |
|
163 | 163 | return 'https://secure.authorize.net/gateway/transact.dll'; |
164 | 164 | } else { |
165 | 165 | return $url; |
@@ -182,33 +182,33 @@ discard block |
||
182 | 182 | */ |
183 | 183 | |
184 | 184 | public function do_direct_payment($payment, $billing_info = null) { |
185 | - add_filter( 'FHEE__EEG_Aim___get_server_url', array( $this, 'possibly_use_deprecated_aim_server' ), 10, 2 ); |
|
185 | + add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2); |
|
186 | 186 | // Enable test mode if needed |
187 | 187 | //4007000000027 <-- test successful visa |
188 | 188 | //4222222222222 <-- test failure card number |
189 | 189 | |
190 | 190 | $item_num = 1; |
191 | 191 | $transaction = $payment->transaction(); |
192 | - $order_description = $this->_format_order_description( $payment ); |
|
192 | + $order_description = $this->_format_order_description($payment); |
|
193 | 193 | $primary_registrant = $transaction->primary_registration(); |
194 | 194 | //if we're are charging for the full amount, show the normal line items |
195 | 195 | //and the itemized total adds up properly |
196 | - if( $this->_can_easily_itemize_transaction_for( $payment ) ){ |
|
196 | + if ($this->_can_easily_itemize_transaction_for($payment)) { |
|
197 | 197 | $total_line_item = $transaction->total_line_item(); |
198 | 198 | foreach ($total_line_item->get_items() as $line_item) { |
199 | - if( $line_item->quantity() == 0 ){ |
|
199 | + if ($line_item->quantity() == 0) { |
|
200 | 200 | continue; |
201 | 201 | } |
202 | 202 | $this->addLineItem( |
203 | 203 | $item_num++, |
204 | - $this->_format_line_item_name( $line_item, $payment ), |
|
205 | - $this->_format_line_item_desc( $line_item, $payment ), |
|
204 | + $this->_format_line_item_name($line_item, $payment), |
|
205 | + $this->_format_line_item_desc($line_item, $payment), |
|
206 | 206 | $line_item->quantity(), |
207 | 207 | $line_item->unit_price(), |
208 | 208 | 'N'); |
209 | 209 | $order_description .= $line_item->desc().', '; |
210 | 210 | } |
211 | - foreach($total_line_item->tax_descendants() as $tax_line_item){ |
|
211 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
212 | 212 | $this->addLineItem($item_num++, $tax_line_item->name(), $tax_line_item->desc(), 1, $tax_line_item->total(), 'N'); |
213 | 213 | } |
214 | 214 | } |
@@ -219,18 +219,18 @@ discard block |
||
219 | 219 | //start transaction |
220 | 220 | //if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id |
221 | 221 | $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363'; |
222 | - $this->setField( 'solution_id', $partner_id ); |
|
222 | + $this->setField('solution_id', $partner_id); |
|
223 | 223 | $this->setField('amount', $this->format_currency($payment->amount())); |
224 | - $this->setField('description',substr(rtrim($order_description, ', '), 0, 255)); |
|
225 | - $this->_set_sensitive_billing_data( $billing_info ); |
|
224 | + $this->setField('description', substr(rtrim($order_description, ', '), 0, 255)); |
|
225 | + $this->_set_sensitive_billing_data($billing_info); |
|
226 | 226 | $this->setField('first_name', $billing_info['first_name']); |
227 | 227 | $this->setField('last_name', $billing_info['last_name']); |
228 | 228 | $this->setField('email', $billing_info['email']); |
229 | 229 | $this->setField('company', $billing_info['company']); |
230 | 230 | $this->setField('address', $billing_info['address'].' '.$billing_info['address2']); |
231 | 231 | $this->setField('city', $billing_info['city']); |
232 | - $this->setField('state', $billing_info['state'] ); |
|
233 | - $this->setField('country', $billing_info['country'] ); |
|
232 | + $this->setField('state', $billing_info['state']); |
|
233 | + $this->setField('country', $billing_info['country']); |
|
234 | 234 | $this->setField('zip', $billing_info['zip']); |
235 | 235 | $this->setField('fax', $billing_info['fax']); |
236 | 236 | $this->setField('cust_id', $primary_registrant->ID()); |
@@ -238,9 +238,9 @@ discard block |
||
238 | 238 | //invoice_num would be nice to have it be unique per SPCO page-load, that way if users |
239 | 239 | //press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page |
240 | 240 | //in which case, we need to generate teh invoice num per request right here... |
241 | - $this->setField('invoice_num', wp_generate_password(12,false));//$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
241 | + $this->setField('invoice_num', wp_generate_password(12, false)); //$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
|
242 | 242 | //tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
243 | - $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS ); |
|
243 | + $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS); |
|
244 | 244 | |
245 | 245 | |
246 | 246 | if ($this->_test_transactions) { |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | //Capture response |
251 | 251 | $this->type = "AUTH_CAPTURE"; |
252 | 252 | $response = $this->_sendRequest($payment); |
253 | - if (!empty($response)){ |
|
253 | + if ( ! empty($response)) { |
|
254 | 254 | if ($response->error_message) { |
255 | 255 | $payment->set_status($this->_pay_model->failed_status()); |
256 | 256 | $payment->set_gateway_response($response->error_message); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | $payment_status = $response->approved ? $this->_pay_model->approved_status() : $this->_pay_model->declined_status(); |
259 | 259 | $payment->set_status($payment_status); |
260 | 260 | //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
261 | - $payment->set_amount( (float) $response->amount ); |
|
261 | + $payment->set_amount((float) $response->amount); |
|
262 | 262 | $payment->set_gateway_response( |
263 | 263 | sprintf( |
264 | 264 | esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
@@ -271,14 +271,14 @@ discard block |
||
271 | 271 | } else { |
272 | 272 | $txn_id = $response->transaction_id; |
273 | 273 | } |
274 | - $payment->set_txn_id_chq_nmbr( $txn_id ); |
|
274 | + $payment->set_txn_id_chq_nmbr($txn_id); |
|
275 | 275 | } |
276 | 276 | $payment->set_extra_accntng($primary_registrant->reg_code()); |
277 | - $payment->set_details(print_r($response,true)); |
|
277 | + $payment->set_details(print_r($response, true)); |
|
278 | 278 | } else { |
279 | 279 | $payment->set_status($this->_pay_model->failed_status()); |
280 | 280 | $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso')); |
281 | - $payment->set_details(print_r($response,true)); |
|
281 | + $payment->set_details(print_r($response, true)); |
|
282 | 282 | } |
283 | 283 | return $payment; |
284 | 284 | } |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * what billing data gets sent |
290 | 290 | * @param array $billing_info |
291 | 291 | */ |
292 | - protected function _set_sensitive_billing_data( $billing_info ) { |
|
292 | + protected function _set_sensitive_billing_data($billing_info) { |
|
293 | 293 | $this->setField('card_num', $billing_info['credit_card']); |
294 | 294 | $this->setField('exp_date', $billing_info['exp_month'].$billing_info['exp_year']); |
295 | 295 | $this->setField('card_code', $billing_info['cvv']); |
@@ -347,23 +347,23 @@ discard block |
||
347 | 347 | $this->_x_post_fields['tran_key'] = $this->_transaction_key; |
348 | 348 | $x_keys = array(); |
349 | 349 | foreach ($this->_x_post_fields as $key => $value) { |
350 | - $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
350 | + $x_keys[] = "x_$key=".urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
351 | 351 | } |
352 | 352 | // Add line items |
353 | 353 | foreach ($this->_additional_line_items as $key => $value) { |
354 | - $x_keys[] = "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
354 | + $x_keys[] = "x_line_item=".urlencode($this->_get_unsupported_character_remover()->format($value)); |
|
355 | 355 | } |
356 | 356 | $this->_log_clean_request($x_keys, $payment); |
357 | 357 | $post_url = $this->_get_server_url(); |
358 | 358 | $curl_request = curl_init($post_url); |
359 | - $post_body = implode("&",$x_keys); |
|
359 | + $post_body = implode("&", $x_keys); |
|
360 | 360 | curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
361 | 361 | curl_setopt($curl_request, CURLOPT_HEADER, 0); |
362 | 362 | curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
363 | 363 | curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1); |
364 | 364 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2); |
365 | 365 | if ($this->VERIFY_PEER) { |
366 | - curl_setopt($curl_request, CURLOPT_CAINFO, dirname( __DIR__ ) . '/ssl/cert.pem'); |
|
366 | + curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__).'/ssl/cert.pem'); |
|
367 | 367 | } else { |
368 | 368 | curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false); |
369 | 369 | } |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | $response = curl_exec($curl_request); |
376 | 376 | |
377 | 377 | curl_close($curl_request); |
378 | - $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
378 | + $response_obj = new EE_AuthorizeNetAIM_Response($response); |
|
379 | 379 | |
380 | 380 | return $this->_log_and_clean_response($response_obj, $payment); |
381 | 381 | } |
@@ -384,18 +384,18 @@ discard block |
||
384 | 384 | * @param array $request_array |
385 | 385 | * @param EEI_Payment $payment |
386 | 386 | */ |
387 | - protected function _log_clean_request($request_array,$payment){ |
|
388 | - $keys_to_filter_out = array( 'x_card_num', 'x_card_code', 'x_exp_date' ); |
|
389 | - foreach($request_array as $index => $keyvaltogether ) { |
|
390 | - foreach( $keys_to_filter_out as $key ) { |
|
391 | - if( strpos( $keyvaltogether, $key ) === 0 ){ |
|
387 | + protected function _log_clean_request($request_array, $payment) { |
|
388 | + $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date'); |
|
389 | + foreach ($request_array as $index => $keyvaltogether) { |
|
390 | + foreach ($keys_to_filter_out as $key) { |
|
391 | + if (strpos($keyvaltogether, $key) === 0) { |
|
392 | 392 | //found it at the first character |
393 | 393 | //so its one of them |
394 | - unset( $request_array[ $index ] ); |
|
394 | + unset($request_array[$index]); |
|
395 | 395 | } |
396 | 396 | } |
397 | 397 | } |
398 | - $this->log(array('AIM Request sent:'=>$request_array, 'Server URL' => $this->_get_server_url() ),$payment); |
|
398 | + $this->log(array('AIM Request sent:'=>$request_array, 'Server URL' => $this->_get_server_url()), $payment); |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | |
@@ -407,9 +407,9 @@ discard block |
||
407 | 407 | * @param EE_Payment $payment |
408 | 408 | * @return \EE_AuthorizeNetAIM_Response |
409 | 409 | */ |
410 | - private function _log_and_clean_response($response_obj,$payment){ |
|
410 | + private function _log_and_clean_response($response_obj, $payment) { |
|
411 | 411 | $response_obj->account_number = ''; |
412 | - $this->log(array('AIM Response received:'=>(array)$response_obj),$payment); |
|
412 | + $this->log(array('AIM Response received:'=>(array) $response_obj), $payment); |
|
413 | 413 | return $response_obj; |
414 | 414 | } |
415 | 415 | |
@@ -508,7 +508,7 @@ discard block |
||
508 | 508 | // Split Array |
509 | 509 | $this->response = $response; |
510 | 510 | if ($encap_char) { |
511 | - $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1)); |
|
511 | + $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1)); |
|
512 | 512 | } else { |
513 | 513 | $this->_response_array = explode($delimiter, $response); |
514 | 514 | } |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | |
592 | 592 | } |
593 | 593 | |
594 | -if ( ! class_exists( 'AuthorizeNetException' ) ) { |
|
594 | +if ( ! class_exists('AuthorizeNetException')) { |
|
595 | 595 | /** |
596 | 596 | * Class AuthorizeNetException |
597 | 597 | * |
@@ -607,8 +607,8 @@ discard block |
||
607 | 607 | * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0 |
608 | 608 | * @since 5.1.0 |
609 | 609 | */ |
610 | - public function __construct( $message = "", $code = 0, Exception $previous = null ) { |
|
611 | - parent::__construct( $message, $code, $previous ); |
|
610 | + public function __construct($message = "", $code = 0, Exception $previous = null) { |
|
611 | + parent::__construct($message, $code, $previous); |
|
612 | 612 | } |
613 | 613 | } |
614 | 614 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | //in which case, we need to generate teh invoice num per request right here... |
241 | 241 | $this->setField('invoice_num', wp_generate_password(12,false));//$billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']); |
242 | 242 | //tell AIM that any duplicates sent in the next 5 minutes are to be ignored |
243 | - $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS ); |
|
243 | + $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS ); |
|
244 | 244 | |
245 | 245 | |
246 | 246 | if ($this->_test_transactions) { |
@@ -252,27 +252,27 @@ discard block |
||
252 | 252 | $response = $this->_sendRequest($payment); |
253 | 253 | if (!empty($response)){ |
254 | 254 | if ($response->error_message) { |
255 | - $payment->set_status($this->_pay_model->failed_status()); |
|
256 | - $payment->set_gateway_response($response->error_message); |
|
257 | - } else { |
|
258 | - $payment_status = $response->approved ? $this->_pay_model->approved_status() : $this->_pay_model->declined_status(); |
|
259 | - $payment->set_status($payment_status); |
|
260 | - //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
261 | - $payment->set_amount( (float) $response->amount ); |
|
262 | - $payment->set_gateway_response( |
|
263 | - sprintf( |
|
264 | - esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
265 | - $response->response_reason_text, |
|
266 | - $response->response_reason_code |
|
267 | - ) |
|
268 | - ); |
|
269 | - if ($this->_debug_mode) { |
|
270 | - $txn_id = $response->invoice_number; |
|
271 | - } else { |
|
272 | - $txn_id = $response->transaction_id; |
|
273 | - } |
|
274 | - $payment->set_txn_id_chq_nmbr( $txn_id ); |
|
275 | - } |
|
255 | + $payment->set_status($this->_pay_model->failed_status()); |
|
256 | + $payment->set_gateway_response($response->error_message); |
|
257 | + } else { |
|
258 | + $payment_status = $response->approved ? $this->_pay_model->approved_status() : $this->_pay_model->declined_status(); |
|
259 | + $payment->set_status($payment_status); |
|
260 | + //make sure we interpret the AMT as a float, not an international string (where periods are thousand separators) |
|
261 | + $payment->set_amount( (float) $response->amount ); |
|
262 | + $payment->set_gateway_response( |
|
263 | + sprintf( |
|
264 | + esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'), |
|
265 | + $response->response_reason_text, |
|
266 | + $response->response_reason_code |
|
267 | + ) |
|
268 | + ); |
|
269 | + if ($this->_debug_mode) { |
|
270 | + $txn_id = $response->invoice_number; |
|
271 | + } else { |
|
272 | + $txn_id = $response->transaction_id; |
|
273 | + } |
|
274 | + $payment->set_txn_id_chq_nmbr( $txn_id ); |
|
275 | + } |
|
276 | 276 | $payment->set_extra_accntng($primary_registrant->reg_code()); |
277 | 277 | $payment->set_details(print_r($response,true)); |
278 | 278 | } else { |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | $this->_log_clean_request($x_keys, $payment); |
357 | 357 | $post_url = $this->_get_server_url(); |
358 | 358 | $curl_request = curl_init($post_url); |
359 | - $post_body = implode("&",$x_keys); |
|
359 | + $post_body = implode("&",$x_keys); |
|
360 | 360 | curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body); |
361 | 361 | curl_setopt($curl_request, CURLOPT_HEADER, 0); |
362 | 362 | curl_setopt($curl_request, CURLOPT_TIMEOUT, 45); |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | public $requested_amount; |
490 | 490 | public $balance_on_card; |
491 | 491 | public $response; // The response string from AuthorizeNet. |
492 | - public $error_message; |
|
492 | + public $error_message; |
|
493 | 493 | private $_response_array = array(); // An array with the split response. |
494 | 494 | |
495 | 495 | /** |
@@ -521,9 +521,9 @@ discard block |
||
521 | 521 | $this->approved = false; |
522 | 522 | $this->error = true; |
523 | 523 | $this->error_message = sprintf( |
524 | - esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
525 | - esc_html($response) |
|
526 | - ); |
|
524 | + esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'), |
|
525 | + esc_html($response) |
|
526 | + ); |
|
527 | 527 | return; |
528 | 528 | } |
529 | 529 | |
@@ -584,9 +584,9 @@ discard block |
||
584 | 584 | $this->approved = false; |
585 | 585 | $this->error = true; |
586 | 586 | $this->error_message = esc_html__( |
587 | - 'Error connecting to Authorize.net', |
|
588 | - 'event_espresso' |
|
589 | - ); |
|
587 | + 'Error connecting to Authorize.net', |
|
588 | + 'event_espresso' |
|
589 | + ); |
|
590 | 590 | } |
591 | 591 | } |
592 | 592 |
@@ -8,71 +8,71 @@ discard block |
||
8 | 8 | */ |
9 | 9 | if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
10 | 10 | /** |
11 | - * |
|
12 | - * Money helper class. |
|
13 | - * This class has helper methods that help with money related conversions and calculations. |
|
14 | - * |
|
15 | - * @since %VER% |
|
16 | - * |
|
17 | - * @package Event Espresso |
|
18 | - * @subpackage helpers |
|
19 | - * @author Darren Ethier |
|
20 | - * |
|
21 | - * ------------------------------------------------------------------------ |
|
22 | - */ |
|
11 | + * |
|
12 | + * Money helper class. |
|
13 | + * This class has helper methods that help with money related conversions and calculations. |
|
14 | + * |
|
15 | + * @since %VER% |
|
16 | + * |
|
17 | + * @package Event Espresso |
|
18 | + * @subpackage helpers |
|
19 | + * @author Darren Ethier |
|
20 | + * |
|
21 | + * ------------------------------------------------------------------------ |
|
22 | + */ |
|
23 | 23 | class EEH_Money extends EEH_Base { |
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * This removes all localized money formatting from the incoming value |
|
28 | - * |
|
29 | - * Note: uses this site's currency settings for deciding what is considered a |
|
30 | - * "thousands separator" (usually the character "," ) |
|
31 | - * and what is a "decimal mark" (usually the character ".") |
|
32 | - * |
|
33 | - * @param int|float|string $money_value |
|
34 | - * @param string $CNT_ISO |
|
35 | - * @return float |
|
36 | - * @throws EE_Error |
|
37 | - */ |
|
26 | + /** |
|
27 | + * This removes all localized money formatting from the incoming value |
|
28 | + * |
|
29 | + * Note: uses this site's currency settings for deciding what is considered a |
|
30 | + * "thousands separator" (usually the character "," ) |
|
31 | + * and what is a "decimal mark" (usually the character ".") |
|
32 | + * |
|
33 | + * @param int|float|string $money_value |
|
34 | + * @param string $CNT_ISO |
|
35 | + * @return float |
|
36 | + * @throws EE_Error |
|
37 | + */ |
|
38 | 38 | public static function strip_localized_money_formatting($money_value, $CNT_ISO = '') { |
39 | - $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
40 | - $money_value = str_replace( |
|
41 | - array( |
|
42 | - $currency_config->thsnds, |
|
43 | - $currency_config->dec_mrk, |
|
44 | - ), |
|
45 | - array( |
|
46 | - '', // remove thousands separator |
|
47 | - '.', // convert decimal mark to what PHP expects |
|
48 | - ), |
|
49 | - $money_value |
|
50 | - ); |
|
51 | - $money_value = filter_var( |
|
52 | - $money_value, |
|
53 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
54 | - FILTER_FLAG_ALLOW_FRACTION |
|
55 | - ); |
|
56 | - return $money_value; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * This converts an incoming localized money value into a standard float item (to three decimal places) |
|
63 | - * |
|
64 | - * Only use this if you know the $money_value follows your currency configuration's |
|
65 | - * settings. Note: this uses this site's currency settings for deciding what is considered a |
|
66 | - * "thousands separator" (usually the character "," ) |
|
67 | - * and what is a "decimal mark" (usually the character ".") |
|
68 | - * |
|
69 | - * @param int|string $money_value |
|
70 | - * @return float |
|
71 | - * @throws EE_Error |
|
72 | - */ |
|
39 | + $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
|
40 | + $money_value = str_replace( |
|
41 | + array( |
|
42 | + $currency_config->thsnds, |
|
43 | + $currency_config->dec_mrk, |
|
44 | + ), |
|
45 | + array( |
|
46 | + '', // remove thousands separator |
|
47 | + '.', // convert decimal mark to what PHP expects |
|
48 | + ), |
|
49 | + $money_value |
|
50 | + ); |
|
51 | + $money_value = filter_var( |
|
52 | + $money_value, |
|
53 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
54 | + FILTER_FLAG_ALLOW_FRACTION |
|
55 | + ); |
|
56 | + return $money_value; |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * This converts an incoming localized money value into a standard float item (to three decimal places) |
|
63 | + * |
|
64 | + * Only use this if you know the $money_value follows your currency configuration's |
|
65 | + * settings. Note: this uses this site's currency settings for deciding what is considered a |
|
66 | + * "thousands separator" (usually the character "," ) |
|
67 | + * and what is a "decimal mark" (usually the character ".") |
|
68 | + * |
|
69 | + * @param int|string $money_value |
|
70 | + * @return float |
|
71 | + * @throws EE_Error |
|
72 | + */ |
|
73 | 73 | public static function convert_to_float_from_localized_money($money_value ) { |
74 | 74 | //float it! and round to three decimal places |
75 | - return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 ); |
|
75 | + return round ( (float) EEH_Money::strip_localized_money_formatting($money_value), 3 ); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | |
@@ -160,19 +160,19 @@ discard block |
||
160 | 160 | |
161 | 161 | |
162 | 162 | |
163 | - /** |
|
164 | - * This returns a localized format string suitable for jQplot. |
|
165 | - * |
|
166 | - * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
167 | - * Otherwise will use currency settings for current active country on site. |
|
168 | - * @return string |
|
169 | - * @throws EE_Error |
|
170 | - */ |
|
163 | + /** |
|
164 | + * This returns a localized format string suitable for jQplot. |
|
165 | + * |
|
166 | + * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
167 | + * Otherwise will use currency settings for current active country on site. |
|
168 | + * @return string |
|
169 | + * @throws EE_Error |
|
170 | + */ |
|
171 | 171 | public static function get_format_for_jqplot( $CNT_ISO = '') { |
172 | 172 | //default format |
173 | 173 | $format = 'f'; |
174 | 174 | $currency_config = $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
175 | - //first get the decimal place and number of places |
|
175 | + //first get the decimal place and number of places |
|
176 | 176 | $format = "%'." . $currency_config->dec_plc . $format; |
177 | 177 | //currency symbol on right side. |
178 | 178 | $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
@@ -181,16 +181,16 @@ discard block |
||
181 | 181 | |
182 | 182 | |
183 | 183 | |
184 | - /** |
|
185 | - * This returns a localized format string suitable for usage with the Google Charts API format param. |
|
186 | - * |
|
187 | - * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
188 | - * Otherwise will use currency settings for current active country on site. |
|
189 | - * Note: GoogleCharts uses ICU pattern set |
|
190 | - * (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) |
|
191 | - * @return string |
|
192 | - * @throws EE_Error |
|
193 | - */ |
|
184 | + /** |
|
185 | + * This returns a localized format string suitable for usage with the Google Charts API format param. |
|
186 | + * |
|
187 | + * @param string $CNT_ISO If this is provided, then will attempt to get the currency settings for the country. |
|
188 | + * Otherwise will use currency settings for current active country on site. |
|
189 | + * Note: GoogleCharts uses ICU pattern set |
|
190 | + * (@see http://icu-project.org/apiref/icu4c/classDecimalFormat.html#_details) |
|
191 | + * @return string |
|
192 | + * @throws EE_Error |
|
193 | + */ |
|
194 | 194 | public static function get_format_for_google_charts( $CNT_ISO = '' ) { |
195 | 195 | $currency_config = EEH_Money::get_currency_config($CNT_ISO); |
196 | 196 | $decimal_places_placeholder = str_pad( '', $currency_config->dec_plc, '0' ); |
@@ -217,24 +217,24 @@ discard block |
||
217 | 217 | |
218 | 218 | |
219 | 219 | |
220 | - /** |
|
221 | - * @param string $CNT_ISO |
|
222 | - * @return EE_Currency_Config|null |
|
223 | - * @throws EE_Error |
|
224 | - */ |
|
225 | - public static function get_currency_config($CNT_ISO = '') |
|
226 | - { |
|
227 | - //if CNT_ISO passed lets try to get currency settings for it. |
|
228 | - $currency_config = $CNT_ISO !== '' |
|
229 | - ? new EE_Currency_Config($CNT_ISO) |
|
230 | - : null; |
|
231 | - //default currency settings for site if not set |
|
232 | - if (! $currency_config instanceof EE_Currency_Config) { |
|
233 | - $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
234 | - ? EE_Registry::instance()->CFG->currency |
|
235 | - : new EE_Currency_Config(); |
|
236 | - } |
|
237 | - return $currency_config; |
|
238 | - } |
|
220 | + /** |
|
221 | + * @param string $CNT_ISO |
|
222 | + * @return EE_Currency_Config|null |
|
223 | + * @throws EE_Error |
|
224 | + */ |
|
225 | + public static function get_currency_config($CNT_ISO = '') |
|
226 | + { |
|
227 | + //if CNT_ISO passed lets try to get currency settings for it. |
|
228 | + $currency_config = $CNT_ISO !== '' |
|
229 | + ? new EE_Currency_Config($CNT_ISO) |
|
230 | + : null; |
|
231 | + //default currency settings for site if not set |
|
232 | + if (! $currency_config instanceof EE_Currency_Config) { |
|
233 | + $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
234 | + ? EE_Registry::instance()->CFG->currency |
|
235 | + : new EE_Currency_Config(); |
|
236 | + } |
|
237 | + return $currency_config; |
|
238 | + } |
|
239 | 239 | |
240 | 240 | } //end class EEH_Money |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('NO direct script access allowed'); |
|
4 | + exit('NO direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -36,82 +36,82 @@ discard block |
||
36 | 36 | { |
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * _init_props |
|
41 | - * |
|
42 | - * @access protected |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - protected function _init_props() |
|
46 | - { |
|
47 | - $this->label = __('Attendee Shortcodes', 'event_espresso'); |
|
48 | - $this->description = __('All shortcodes specific to attendee related data', 'event_espresso'); |
|
49 | - $this->_shortcodes = array( |
|
50 | - '[QUESTION]' => __('Will parse to a question.', 'event_espresso'), |
|
51 | - '[ANSWER]' => __('Will parse to the answer for a question', 'event_espresso') |
|
52 | - ); |
|
53 | - } |
|
39 | + /** |
|
40 | + * _init_props |
|
41 | + * |
|
42 | + * @access protected |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + protected function _init_props() |
|
46 | + { |
|
47 | + $this->label = __('Attendee Shortcodes', 'event_espresso'); |
|
48 | + $this->description = __('All shortcodes specific to attendee related data', 'event_espresso'); |
|
49 | + $this->_shortcodes = array( |
|
50 | + '[QUESTION]' => __('Will parse to a question.', 'event_espresso'), |
|
51 | + '[ANSWER]' => __('Will parse to the answer for a question', 'event_espresso') |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
58 | - * will have to take care of handling. |
|
59 | - * |
|
60 | - * @access protected |
|
61 | - * |
|
62 | - * @param string $shortcode the shortcode to be parsed. |
|
63 | - * |
|
64 | - * @return string parsed shortcode |
|
65 | - */ |
|
66 | - protected function _parser($shortcode) |
|
67 | - { |
|
56 | + /** |
|
57 | + * This method will give parsing instructions for each shortcode defined in the _shortcodes array. Child methods |
|
58 | + * will have to take care of handling. |
|
59 | + * |
|
60 | + * @access protected |
|
61 | + * |
|
62 | + * @param string $shortcode the shortcode to be parsed. |
|
63 | + * |
|
64 | + * @return string parsed shortcode |
|
65 | + */ |
|
66 | + protected function _parser($shortcode) |
|
67 | + { |
|
68 | 68 | |
69 | - if ( ! $this->_data instanceof EE_Answer || ! isset($this->_extra_data['data']) || ! $this->_extra_data['data'] instanceof EE_Messages_Addressee) { |
|
70 | - return ''; |
|
71 | - } |
|
69 | + if ( ! $this->_data instanceof EE_Answer || ! isset($this->_extra_data['data']) || ! $this->_extra_data['data'] instanceof EE_Messages_Addressee) { |
|
70 | + return ''; |
|
71 | + } |
|
72 | 72 | |
73 | - switch ($shortcode) { |
|
73 | + switch ($shortcode) { |
|
74 | 74 | |
75 | - case '[QUESTION]' : |
|
76 | - $question = isset($this->_extra_data['data']->questions[$this->_data->ID()]) ? $this->_extra_data['data']->questions[$this->_data->ID()] : $this->_data->question(); |
|
77 | - if ( ! $question instanceof EE_Question) { |
|
78 | - return ''; //get out because we can't figure out what the question is. |
|
79 | - } |
|
75 | + case '[QUESTION]' : |
|
76 | + $question = isset($this->_extra_data['data']->questions[$this->_data->ID()]) ? $this->_extra_data['data']->questions[$this->_data->ID()] : $this->_data->question(); |
|
77 | + if ( ! $question instanceof EE_Question) { |
|
78 | + return ''; //get out because we can't figure out what the question is. |
|
79 | + } |
|
80 | 80 | |
81 | - return $question->get('QST_display_text'); |
|
82 | - break; |
|
81 | + return $question->get('QST_display_text'); |
|
82 | + break; |
|
83 | 83 | |
84 | - case '[ANSWER]' : |
|
85 | - //need to get the question to determine the type of question (some questions require translation of the answer). |
|
86 | - $question = isset($this->_extra_data['data']->questions[$this->_data->ID()]) ? $this->_extra_data['data']->questions[$this->_data->ID()] : $this->_data->question(); |
|
87 | - if ( ! $question instanceof EE_Question) { |
|
88 | - return ''; //get out cause we can't figure out what the question type is! |
|
89 | - } |
|
84 | + case '[ANSWER]' : |
|
85 | + //need to get the question to determine the type of question (some questions require translation of the answer). |
|
86 | + $question = isset($this->_extra_data['data']->questions[$this->_data->ID()]) ? $this->_extra_data['data']->questions[$this->_data->ID()] : $this->_data->question(); |
|
87 | + if ( ! $question instanceof EE_Question) { |
|
88 | + return ''; //get out cause we can't figure out what the question type is! |
|
89 | + } |
|
90 | 90 | |
91 | - //what we show for the answer depends on the question type! |
|
92 | - switch ($question->get('QST_type')) { |
|
91 | + //what we show for the answer depends on the question type! |
|
92 | + switch ($question->get('QST_type')) { |
|
93 | 93 | |
94 | - case 'STATE' : |
|
95 | - $state = EEM_State::instance()->get_one_by_ID($this->_data->get('ANS_value')); |
|
96 | - $answer = $state instanceof EE_State ? $state->name() : ''; |
|
97 | - break; |
|
94 | + case 'STATE' : |
|
95 | + $state = EEM_State::instance()->get_one_by_ID($this->_data->get('ANS_value')); |
|
96 | + $answer = $state instanceof EE_State ? $state->name() : ''; |
|
97 | + break; |
|
98 | 98 | |
99 | - case 'COUNTRY' : |
|
100 | - $country = EEM_Country::instance()->get_one_by_ID($this->_data->get('ANS_value')); |
|
101 | - $answer = $country instanceof EE_Country ? $country->name() : ''; |
|
102 | - break; |
|
99 | + case 'COUNTRY' : |
|
100 | + $country = EEM_Country::instance()->get_one_by_ID($this->_data->get('ANS_value')); |
|
101 | + $answer = $country instanceof EE_Country ? $country->name() : ''; |
|
102 | + break; |
|
103 | 103 | |
104 | - default : |
|
105 | - $answer = $this->_data->get_pretty('ANS_value', 'no_wpautop'); |
|
106 | - break; |
|
107 | - } |
|
104 | + default : |
|
105 | + $answer = $this->_data->get_pretty('ANS_value', 'no_wpautop'); |
|
106 | + break; |
|
107 | + } |
|
108 | 108 | |
109 | - return $answer; |
|
110 | - break; |
|
109 | + return $answer; |
|
110 | + break; |
|
111 | 111 | |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - return ''; |
|
115 | - } |
|
114 | + return ''; |
|
115 | + } |
|
116 | 116 | |
117 | 117 | } //end EE_Question_Shortcodes class |
@@ -43,7 +43,7 @@ |
||
43 | 43 | <div class="padding"> |
44 | 44 | <h4 class="espresso-header"><span class="dashicons dashicons-post-trash ee-icon-size-22"></span><?php esc_html_e('Permanently Delete ALL Event Espresso Data', 'event_espresso');?></h4> |
45 | 45 | <p><?php esc_html_e(' This will delete data for Event Espresso 4, and all currently active add-ons. Event Espresso will then be deactivated. You may need to manually deactivate each add-on individually.', |
46 | - 'event_espresso');?></p> |
|
46 | + 'event_espresso');?></p> |
|
47 | 47 | <p><?php esc_html_e('If you know for certain that you will no longer be using Event Espresso and you wish to remove ALL traces of the plugin from your system, then perform the following steps.', 'event_espresso');?></p> |
48 | 48 | <p class="important-notice"><?php printf( esc_html__('Please note: %sThis is permanent and can NOT be undone.%s', 'event_espresso'), '<em>', '</em>' ); ?><br/></p> |
49 | 49 | <ol> |
@@ -7,13 +7,13 @@ discard block |
||
7 | 7 | /** @var string $delete_db_url */ |
8 | 8 | ?> |
9 | 9 | <h2> |
10 | - <?php esc_html_e( 'Reset/Delete Data for Event Espresso', 'event_espresso' );?> |
|
10 | + <?php esc_html_e('Reset/Delete Data for Event Espresso', 'event_espresso'); ?> |
|
11 | 11 | </h2> |
12 | 12 | <br /> |
13 | 13 | |
14 | 14 | <div class="padding"> |
15 | - <h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Ticket and Datetime Reserved Counts', 'event_espresso');?></h4> |
|
16 | - <p><?php esc_html_e('Use this to reset the counts for ticket and datetime reservations.', 'event_espresso');?></p> |
|
15 | + <h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Ticket and Datetime Reserved Counts', 'event_espresso'); ?></h4> |
|
16 | + <p><?php esc_html_e('Use this to reset the counts for ticket and datetime reservations.', 'event_espresso'); ?></p> |
|
17 | 17 | <div class="float-right"><?php echo $reset_reservations_button; ?></div> |
18 | 18 | <div class="clear"></div> |
19 | 19 | </div> |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | |
23 | 23 | <!-- reset DB url is here. Just need to make it look pretty and unhide it--> |
24 | 24 | <div class="padding"> |
25 | - <h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Capabilities', 'event_espresso');?></h4> |
|
26 | - <p><?php esc_html_e('Use this to reset the capabilities on WP roles to the defaults as defined via EE_Capabilities. Note this reset does not REMOVE any existing capabilities, it just ensures that all the defaults are ADDED to the roles.', 'event_espresso');?></p> |
|
25 | + <h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Capabilities', 'event_espresso'); ?></h4> |
|
26 | + <p><?php esc_html_e('Use this to reset the capabilities on WP roles to the defaults as defined via EE_Capabilities. Note this reset does not REMOVE any existing capabilities, it just ensures that all the defaults are ADDED to the roles.', 'event_espresso'); ?></p> |
|
27 | 27 | <div class="float-right"><?php echo $reset_capabilities_button; ?></div> |
28 | 28 | <div class="clear"></div> |
29 | 29 | </div> |
@@ -31,27 +31,27 @@ discard block |
||
31 | 31 | <br /> |
32 | 32 | |
33 | 33 | <div class="padding"> |
34 | - <h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Data', 'event_espresso');?></h4> |
|
35 | - <p><?php esc_html_e(' This will reset data for Event Espresso 4, and for all active add-ons. Inactive add-ons will not be affected.', 'event_espresso');?></p> |
|
36 | - <p><?php esc_html_e('Your Event Espresso data will return to its default settings. The rest of your website will be unaffected.', 'event_espresso');?></p> |
|
37 | - <div class="float-right"><a class="button button-primary" href="<?php echo $reset_db_url;?>"><?php esc_html_e('Reset Event Espresso Tables', 'event_espresso');?></a></div> |
|
34 | + <h4 class="espresso-header"><span class="dashicons dashicons-update ee-icon-size-22"></span><?php esc_html_e('Reset Event Espresso Data', 'event_espresso'); ?></h4> |
|
35 | + <p><?php esc_html_e(' This will reset data for Event Espresso 4, and for all active add-ons. Inactive add-ons will not be affected.', 'event_espresso'); ?></p> |
|
36 | + <p><?php esc_html_e('Your Event Espresso data will return to its default settings. The rest of your website will be unaffected.', 'event_espresso'); ?></p> |
|
37 | + <div class="float-right"><a class="button button-primary" href="<?php echo $reset_db_url; ?>"><?php esc_html_e('Reset Event Espresso Tables', 'event_espresso'); ?></a></div> |
|
38 | 38 | <div class="clear"></div> |
39 | 39 | </div> |
40 | 40 | <br /> |
41 | 41 | <br /> |
42 | 42 | |
43 | 43 | <div class="padding"> |
44 | - <h4 class="espresso-header"><span class="dashicons dashicons-post-trash ee-icon-size-22"></span><?php esc_html_e('Permanently Delete ALL Event Espresso Data', 'event_espresso');?></h4> |
|
44 | + <h4 class="espresso-header"><span class="dashicons dashicons-post-trash ee-icon-size-22"></span><?php esc_html_e('Permanently Delete ALL Event Espresso Data', 'event_espresso'); ?></h4> |
|
45 | 45 | <p><?php esc_html_e(' This will delete data for Event Espresso 4, and all currently active add-ons. Event Espresso will then be deactivated. You may need to manually deactivate each add-on individually.', |
46 | - 'event_espresso');?></p> |
|
47 | - <p><?php esc_html_e('If you know for certain that you will no longer be using Event Espresso and you wish to remove ALL traces of the plugin from your system, then perform the following steps.', 'event_espresso');?></p> |
|
48 | - <p class="important-notice"><?php printf( esc_html__('Please note: %sThis is permanent and can NOT be undone.%s', 'event_espresso'), '<em>', '</em>' ); ?><br/></p> |
|
46 | + 'event_espresso'); ?></p> |
|
47 | + <p><?php esc_html_e('If you know for certain that you will no longer be using Event Espresso and you wish to remove ALL traces of the plugin from your system, then perform the following steps.', 'event_espresso'); ?></p> |
|
48 | + <p class="important-notice"><?php printf(esc_html__('Please note: %sThis is permanent and can NOT be undone.%s', 'event_espresso'), '<em>', '</em>'); ?><br/></p> |
|
49 | 49 | <ol> |
50 | - <li><?php printf( esc_html__('First, click the button below to permanently delete all Event Espresso tables, records, and options from your WordPress database . If you receive a "500 Internal Server Error" or a blank white screen, it means the server has timed out due to the large number of records being updated. This is not a cause for concern. Simply %1$srefresh the page%2$s and the Database Update will continue where it left off.', 'event_espresso'), '<strong>', '</strong>' );?></li> |
|
51 | - <li><?php printf( esc_html__('Then, locate Event Espresso on the WordPress Plugins page, and click on %sDelete%s', 'event_espresso'), '<strong>', '</strong>' ); ?></li> |
|
52 | - <li><?php printf( esc_html__('Once you are on the Delete Plugin page, click on %sYes, Delete these files and data%s', 'event_espresso'), '<strong>', '</strong>' ); ?></li> |
|
50 | + <li><?php printf(esc_html__('First, click the button below to permanently delete all Event Espresso tables, records, and options from your WordPress database . If you receive a "500 Internal Server Error" or a blank white screen, it means the server has timed out due to the large number of records being updated. This is not a cause for concern. Simply %1$srefresh the page%2$s and the Database Update will continue where it left off.', 'event_espresso'), '<strong>', '</strong>'); ?></li> |
|
51 | + <li><?php printf(esc_html__('Then, locate Event Espresso on the WordPress Plugins page, and click on %sDelete%s', 'event_espresso'), '<strong>', '</strong>'); ?></li> |
|
52 | + <li><?php printf(esc_html__('Once you are on the Delete Plugin page, click on %sYes, Delete these files and data%s', 'event_espresso'), '<strong>', '</strong>'); ?></li> |
|
53 | 53 | </ol> |
54 | - <div class="float-right"><a href="<?php echo $delete_db_url; ?>" id="delete-all-data-btn" class="button-primary"><?php esc_html_e('Permanently Delete All Event Espresso Data', 'event_espresso');?></a></div> |
|
54 | + <div class="float-right"><a href="<?php echo $delete_db_url; ?>" id="delete-all-data-btn" class="button-primary"><?php esc_html_e('Permanently Delete All Event Espresso Data', 'event_espresso'); ?></a></div> |
|
55 | 55 | <div class="clear"></div> |
56 | 56 | </div> |
57 | 57 | <br/> |
@@ -14,326 +14,326 @@ |
||
14 | 14 | class EEM_Ticket extends EEM_Soft_Delete_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * private instance of the EEM_Ticket object |
|
19 | - * |
|
20 | - * @var EEM_Ticket $_instance |
|
21 | - */ |
|
22 | - protected static $_instance; |
|
17 | + /** |
|
18 | + * private instance of the EEM_Ticket object |
|
19 | + * |
|
20 | + * @var EEM_Ticket $_instance |
|
21 | + */ |
|
22 | + protected static $_instance; |
|
23 | 23 | |
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * private constructor to prevent direct creation |
|
28 | - * |
|
29 | - * @Constructor |
|
30 | - * @access private |
|
31 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
32 | - * (and any incoming timezone data that gets saved). |
|
33 | - * Note this just sends the timezone info to the date time model field objects. |
|
34 | - * Default is NULL |
|
35 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
36 | - * @throws EE_Error |
|
37 | - */ |
|
38 | - protected function __construct($timezone) |
|
39 | - { |
|
40 | - $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
41 | - $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
42 | - $this->_tables = array( |
|
43 | - 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
44 | - ); |
|
45 | - $this->_fields = array( |
|
46 | - 'Ticket' => array( |
|
47 | - 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
48 | - 'TKT_ID', |
|
49 | - esc_html__('Ticket ID', 'event_espresso') |
|
50 | - ), |
|
51 | - 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
52 | - 'TTM_ID', |
|
53 | - esc_html__('Ticket Template ID', 'event_espresso'), |
|
54 | - false, |
|
55 | - 0, |
|
56 | - 'Ticket_Template' |
|
57 | - ), |
|
58 | - 'TKT_name' => new EE_Plain_Text_Field( |
|
59 | - 'TKT_name', |
|
60 | - esc_html__('Ticket Name', 'event_espresso'), |
|
61 | - false, |
|
62 | - '' |
|
63 | - ), |
|
64 | - 'TKT_description' => new EE_Post_Content_Field( |
|
65 | - 'TKT_description', |
|
66 | - esc_html__('Description of Ticket', 'event_espresso'), |
|
67 | - false, |
|
68 | - '' |
|
69 | - ), |
|
70 | - 'TKT_start_date' => new EE_Datetime_Field( |
|
71 | - 'TKT_start_date', |
|
72 | - esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
73 | - false, |
|
74 | - EE_Datetime_Field::now, |
|
75 | - $timezone |
|
76 | - ), |
|
77 | - 'TKT_end_date' => new EE_Datetime_Field( |
|
78 | - 'TKT_end_date', |
|
79 | - esc_html__('End time/date of Ticket', 'event_espresso'), |
|
80 | - false, |
|
81 | - EE_Datetime_Field::now, |
|
82 | - $timezone |
|
83 | - ), |
|
84 | - 'TKT_min' => new EE_Integer_Field( |
|
85 | - 'TKT_min', |
|
86 | - esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
87 | - false, |
|
88 | - 0 |
|
89 | - ), |
|
90 | - 'TKT_max' => new EE_Infinite_Integer_Field( |
|
91 | - 'TKT_max', |
|
92 | - esc_html__( |
|
93 | - 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
94 | - 'event_espresso' |
|
95 | - ), |
|
96 | - false, |
|
97 | - EE_INF |
|
98 | - ), |
|
99 | - 'TKT_price' => new EE_Money_Field( |
|
100 | - 'TKT_price', |
|
101 | - esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
102 | - false, |
|
103 | - 0 |
|
104 | - ), |
|
105 | - 'TKT_sold' => new EE_Integer_Field( |
|
106 | - 'TKT_sold', |
|
107 | - esc_html__('Number of this ticket sold', 'event_espresso'), |
|
108 | - false, |
|
109 | - 0 |
|
110 | - ), |
|
111 | - 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
112 | - 'TKT_qty', |
|
113 | - esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
114 | - false, |
|
115 | - EE_INF |
|
116 | - ), |
|
117 | - 'TKT_reserved' => new EE_Integer_Field( |
|
118 | - 'TKT_reserved', |
|
119 | - esc_html__( |
|
120 | - 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
121 | - 'event_espresso' |
|
122 | - ), |
|
123 | - false, |
|
124 | - 0 |
|
125 | - ), |
|
126 | - 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
127 | - 'TKT_uses', |
|
128 | - esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
129 | - false, |
|
130 | - EE_INF |
|
131 | - ), |
|
132 | - 'TKT_required' => new EE_Boolean_Field( |
|
133 | - 'TKT_required', |
|
134 | - esc_html__( |
|
135 | - 'Flag indicating whether this ticket must be purchased with a transaction', |
|
136 | - 'event_espresso' |
|
137 | - ), |
|
138 | - false, |
|
139 | - false |
|
140 | - ), |
|
141 | - 'TKT_taxable' => new EE_Boolean_Field( |
|
142 | - 'TKT_taxable', |
|
143 | - esc_html__( |
|
144 | - 'Flag indicating whether there is tax applied on this ticket', |
|
145 | - 'event_espresso' |
|
146 | - ), |
|
147 | - false, |
|
148 | - false |
|
149 | - ), |
|
150 | - 'TKT_is_default' => new EE_Boolean_Field( |
|
151 | - 'TKT_is_default', |
|
152 | - esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
153 | - false, |
|
154 | - false |
|
155 | - ), |
|
156 | - 'TKT_order' => new EE_Integer_Field( |
|
157 | - 'TKT_order', |
|
158 | - esc_html__( |
|
159 | - 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
160 | - 'event_espresso' |
|
161 | - ), |
|
162 | - false, |
|
163 | - 0 |
|
164 | - ), |
|
165 | - 'TKT_row' => new EE_Integer_Field( |
|
166 | - 'TKT_row', |
|
167 | - esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
168 | - false, |
|
169 | - 0 |
|
170 | - ), |
|
171 | - 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
172 | - 'TKT_deleted', |
|
173 | - esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
174 | - false, |
|
175 | - false |
|
176 | - ), |
|
177 | - 'TKT_wp_user' => new EE_WP_User_Field( |
|
178 | - 'TKT_wp_user', |
|
179 | - esc_html__('Ticket Creator ID', 'event_espresso'), |
|
180 | - false |
|
181 | - ), |
|
182 | - 'TKT_parent' => new EE_Integer_Field( |
|
183 | - 'TKT_parent', |
|
184 | - esc_html__( |
|
185 | - 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
186 | - 'event_espresso' |
|
187 | - ), |
|
188 | - true, |
|
189 | - 0 |
|
190 | - ), |
|
191 | - ), |
|
192 | - ); |
|
193 | - $this->_model_relations = array( |
|
194 | - 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
195 | - 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
196 | - 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
197 | - 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
198 | - 'Registration' => new EE_Has_Many_Relation(), |
|
199 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
200 | - ); |
|
201 | - //this model is generally available for reading |
|
202 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public( |
|
203 | - 'TKT_is_default', |
|
204 | - 'Datetime.Event' |
|
205 | - ); |
|
206 | - //account for default tickets in the caps |
|
207 | - $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected( |
|
208 | - 'TKT_is_default', |
|
209 | - 'Datetime.Event' |
|
210 | - ); |
|
211 | - $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected( |
|
212 | - 'TKT_is_default', |
|
213 | - 'Datetime.Event' |
|
214 | - ); |
|
215 | - $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected( |
|
216 | - 'TKT_is_default', |
|
217 | - 'Datetime.Event' |
|
218 | - ); |
|
219 | - parent::__construct($timezone); |
|
220 | - } |
|
26 | + /** |
|
27 | + * private constructor to prevent direct creation |
|
28 | + * |
|
29 | + * @Constructor |
|
30 | + * @access private |
|
31 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
32 | + * (and any incoming timezone data that gets saved). |
|
33 | + * Note this just sends the timezone info to the date time model field objects. |
|
34 | + * Default is NULL |
|
35 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
36 | + * @throws EE_Error |
|
37 | + */ |
|
38 | + protected function __construct($timezone) |
|
39 | + { |
|
40 | + $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
41 | + $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
42 | + $this->_tables = array( |
|
43 | + 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
44 | + ); |
|
45 | + $this->_fields = array( |
|
46 | + 'Ticket' => array( |
|
47 | + 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
48 | + 'TKT_ID', |
|
49 | + esc_html__('Ticket ID', 'event_espresso') |
|
50 | + ), |
|
51 | + 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
52 | + 'TTM_ID', |
|
53 | + esc_html__('Ticket Template ID', 'event_espresso'), |
|
54 | + false, |
|
55 | + 0, |
|
56 | + 'Ticket_Template' |
|
57 | + ), |
|
58 | + 'TKT_name' => new EE_Plain_Text_Field( |
|
59 | + 'TKT_name', |
|
60 | + esc_html__('Ticket Name', 'event_espresso'), |
|
61 | + false, |
|
62 | + '' |
|
63 | + ), |
|
64 | + 'TKT_description' => new EE_Post_Content_Field( |
|
65 | + 'TKT_description', |
|
66 | + esc_html__('Description of Ticket', 'event_espresso'), |
|
67 | + false, |
|
68 | + '' |
|
69 | + ), |
|
70 | + 'TKT_start_date' => new EE_Datetime_Field( |
|
71 | + 'TKT_start_date', |
|
72 | + esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
73 | + false, |
|
74 | + EE_Datetime_Field::now, |
|
75 | + $timezone |
|
76 | + ), |
|
77 | + 'TKT_end_date' => new EE_Datetime_Field( |
|
78 | + 'TKT_end_date', |
|
79 | + esc_html__('End time/date of Ticket', 'event_espresso'), |
|
80 | + false, |
|
81 | + EE_Datetime_Field::now, |
|
82 | + $timezone |
|
83 | + ), |
|
84 | + 'TKT_min' => new EE_Integer_Field( |
|
85 | + 'TKT_min', |
|
86 | + esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
87 | + false, |
|
88 | + 0 |
|
89 | + ), |
|
90 | + 'TKT_max' => new EE_Infinite_Integer_Field( |
|
91 | + 'TKT_max', |
|
92 | + esc_html__( |
|
93 | + 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
94 | + 'event_espresso' |
|
95 | + ), |
|
96 | + false, |
|
97 | + EE_INF |
|
98 | + ), |
|
99 | + 'TKT_price' => new EE_Money_Field( |
|
100 | + 'TKT_price', |
|
101 | + esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
102 | + false, |
|
103 | + 0 |
|
104 | + ), |
|
105 | + 'TKT_sold' => new EE_Integer_Field( |
|
106 | + 'TKT_sold', |
|
107 | + esc_html__('Number of this ticket sold', 'event_espresso'), |
|
108 | + false, |
|
109 | + 0 |
|
110 | + ), |
|
111 | + 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
112 | + 'TKT_qty', |
|
113 | + esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
114 | + false, |
|
115 | + EE_INF |
|
116 | + ), |
|
117 | + 'TKT_reserved' => new EE_Integer_Field( |
|
118 | + 'TKT_reserved', |
|
119 | + esc_html__( |
|
120 | + 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
121 | + 'event_espresso' |
|
122 | + ), |
|
123 | + false, |
|
124 | + 0 |
|
125 | + ), |
|
126 | + 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
127 | + 'TKT_uses', |
|
128 | + esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
129 | + false, |
|
130 | + EE_INF |
|
131 | + ), |
|
132 | + 'TKT_required' => new EE_Boolean_Field( |
|
133 | + 'TKT_required', |
|
134 | + esc_html__( |
|
135 | + 'Flag indicating whether this ticket must be purchased with a transaction', |
|
136 | + 'event_espresso' |
|
137 | + ), |
|
138 | + false, |
|
139 | + false |
|
140 | + ), |
|
141 | + 'TKT_taxable' => new EE_Boolean_Field( |
|
142 | + 'TKT_taxable', |
|
143 | + esc_html__( |
|
144 | + 'Flag indicating whether there is tax applied on this ticket', |
|
145 | + 'event_espresso' |
|
146 | + ), |
|
147 | + false, |
|
148 | + false |
|
149 | + ), |
|
150 | + 'TKT_is_default' => new EE_Boolean_Field( |
|
151 | + 'TKT_is_default', |
|
152 | + esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
153 | + false, |
|
154 | + false |
|
155 | + ), |
|
156 | + 'TKT_order' => new EE_Integer_Field( |
|
157 | + 'TKT_order', |
|
158 | + esc_html__( |
|
159 | + 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
160 | + 'event_espresso' |
|
161 | + ), |
|
162 | + false, |
|
163 | + 0 |
|
164 | + ), |
|
165 | + 'TKT_row' => new EE_Integer_Field( |
|
166 | + 'TKT_row', |
|
167 | + esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
168 | + false, |
|
169 | + 0 |
|
170 | + ), |
|
171 | + 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
172 | + 'TKT_deleted', |
|
173 | + esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
174 | + false, |
|
175 | + false |
|
176 | + ), |
|
177 | + 'TKT_wp_user' => new EE_WP_User_Field( |
|
178 | + 'TKT_wp_user', |
|
179 | + esc_html__('Ticket Creator ID', 'event_espresso'), |
|
180 | + false |
|
181 | + ), |
|
182 | + 'TKT_parent' => new EE_Integer_Field( |
|
183 | + 'TKT_parent', |
|
184 | + esc_html__( |
|
185 | + 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
186 | + 'event_espresso' |
|
187 | + ), |
|
188 | + true, |
|
189 | + 0 |
|
190 | + ), |
|
191 | + ), |
|
192 | + ); |
|
193 | + $this->_model_relations = array( |
|
194 | + 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
195 | + 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
196 | + 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
197 | + 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
198 | + 'Registration' => new EE_Has_Many_Relation(), |
|
199 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
200 | + ); |
|
201 | + //this model is generally available for reading |
|
202 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public( |
|
203 | + 'TKT_is_default', |
|
204 | + 'Datetime.Event' |
|
205 | + ); |
|
206 | + //account for default tickets in the caps |
|
207 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected( |
|
208 | + 'TKT_is_default', |
|
209 | + 'Datetime.Event' |
|
210 | + ); |
|
211 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected( |
|
212 | + 'TKT_is_default', |
|
213 | + 'Datetime.Event' |
|
214 | + ); |
|
215 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected( |
|
216 | + 'TKT_is_default', |
|
217 | + 'Datetime.Event' |
|
218 | + ); |
|
219 | + parent::__construct($timezone); |
|
220 | + } |
|
221 | 221 | |
222 | 222 | |
223 | 223 | |
224 | - /** |
|
225 | - * This returns all tickets that are defaults from the db |
|
226 | - * |
|
227 | - * @return EE_Ticket[] |
|
228 | - * @throws EE_Error |
|
229 | - */ |
|
230 | - public function get_all_default_tickets() |
|
231 | - { |
|
232 | - /** @type EE_Ticket[] $tickets */ |
|
233 | - $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
234 | - //we need to set the start date and end date to today's date and the start of the default dtt |
|
235 | - return $this->_set_default_dates($tickets); |
|
236 | - } |
|
224 | + /** |
|
225 | + * This returns all tickets that are defaults from the db |
|
226 | + * |
|
227 | + * @return EE_Ticket[] |
|
228 | + * @throws EE_Error |
|
229 | + */ |
|
230 | + public function get_all_default_tickets() |
|
231 | + { |
|
232 | + /** @type EE_Ticket[] $tickets */ |
|
233 | + $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
234 | + //we need to set the start date and end date to today's date and the start of the default dtt |
|
235 | + return $this->_set_default_dates($tickets); |
|
236 | + } |
|
237 | 237 | |
238 | 238 | |
239 | 239 | |
240 | - /** |
|
241 | - * sets up relevant start and end date for EE_Ticket (s) |
|
242 | - * |
|
243 | - * @param EE_Ticket[] $tickets |
|
244 | - * @return EE_Ticket[] |
|
245 | - * @throws EE_Error |
|
246 | - */ |
|
247 | - private function _set_default_dates($tickets) |
|
248 | - { |
|
249 | - foreach ($tickets as $ticket) { |
|
250 | - $ticket->set( |
|
251 | - 'TKT_start_date', |
|
252 | - (int)$this->current_time_for_query('TKT_start_date', true) |
|
253 | - ); |
|
254 | - $ticket->set('TKT_end_date', |
|
255 | - (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
256 | - ); |
|
257 | - $ticket->set_end_time($this->convert_datetime_for_query( |
|
258 | - 'TKT_end_date', |
|
259 | - '11:59 pm', |
|
260 | - 'g:i a', |
|
261 | - $this->_timezone) |
|
262 | - ); |
|
263 | - } |
|
264 | - return $tickets; |
|
265 | - } |
|
240 | + /** |
|
241 | + * sets up relevant start and end date for EE_Ticket (s) |
|
242 | + * |
|
243 | + * @param EE_Ticket[] $tickets |
|
244 | + * @return EE_Ticket[] |
|
245 | + * @throws EE_Error |
|
246 | + */ |
|
247 | + private function _set_default_dates($tickets) |
|
248 | + { |
|
249 | + foreach ($tickets as $ticket) { |
|
250 | + $ticket->set( |
|
251 | + 'TKT_start_date', |
|
252 | + (int)$this->current_time_for_query('TKT_start_date', true) |
|
253 | + ); |
|
254 | + $ticket->set('TKT_end_date', |
|
255 | + (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
256 | + ); |
|
257 | + $ticket->set_end_time($this->convert_datetime_for_query( |
|
258 | + 'TKT_end_date', |
|
259 | + '11:59 pm', |
|
260 | + 'g:i a', |
|
261 | + $this->_timezone) |
|
262 | + ); |
|
263 | + } |
|
264 | + return $tickets; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | |
268 | 268 | |
269 | - /** |
|
270 | - * Gets the total number of tickets available at a particular datetime (does |
|
271 | - * NOT take int account the datetime's spaces available) |
|
272 | - * |
|
273 | - * @param int $DTT_ID |
|
274 | - * @param array $query_params |
|
275 | - * @return int |
|
276 | - */ |
|
277 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
278 | - { |
|
279 | - return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
280 | - } |
|
269 | + /** |
|
270 | + * Gets the total number of tickets available at a particular datetime (does |
|
271 | + * NOT take int account the datetime's spaces available) |
|
272 | + * |
|
273 | + * @param int $DTT_ID |
|
274 | + * @param array $query_params |
|
275 | + * @return int |
|
276 | + */ |
|
277 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
278 | + { |
|
279 | + return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
280 | + } |
|
281 | 281 | |
282 | 282 | |
283 | 283 | |
284 | - /** |
|
285 | - * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
286 | - * |
|
287 | - * @param EE_Ticket[] $tickets |
|
288 | - * @return void |
|
289 | - * @throws EE_Error |
|
290 | - */ |
|
291 | - public function update_tickets_sold($tickets) |
|
292 | - { |
|
293 | - foreach ($tickets as $ticket) { |
|
294 | - /* @var $ticket EE_Ticket */ |
|
295 | - $ticket->update_tickets_sold(); |
|
296 | - } |
|
297 | - } |
|
284 | + /** |
|
285 | + * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
286 | + * |
|
287 | + * @param EE_Ticket[] $tickets |
|
288 | + * @return void |
|
289 | + * @throws EE_Error |
|
290 | + */ |
|
291 | + public function update_tickets_sold($tickets) |
|
292 | + { |
|
293 | + foreach ($tickets as $ticket) { |
|
294 | + /* @var $ticket EE_Ticket */ |
|
295 | + $ticket->update_tickets_sold(); |
|
296 | + } |
|
297 | + } |
|
298 | 298 | |
299 | 299 | |
300 | 300 | |
301 | - /** |
|
302 | - * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
303 | - * |
|
304 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
305 | - * @throws EE_Error |
|
306 | - */ |
|
307 | - public function get_tickets_with_reservations() |
|
308 | - { |
|
309 | - return $this->get_all( |
|
310 | - array( |
|
311 | - array( |
|
312 | - 'TKT_reserved' => array('>', 0), |
|
313 | - ), |
|
314 | - ) |
|
315 | - ); |
|
316 | - } |
|
301 | + /** |
|
302 | + * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
303 | + * |
|
304 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
305 | + * @throws EE_Error |
|
306 | + */ |
|
307 | + public function get_tickets_with_reservations() |
|
308 | + { |
|
309 | + return $this->get_all( |
|
310 | + array( |
|
311 | + array( |
|
312 | + 'TKT_reserved' => array('>', 0), |
|
313 | + ), |
|
314 | + ) |
|
315 | + ); |
|
316 | + } |
|
317 | 317 | |
318 | 318 | |
319 | 319 | |
320 | - /** |
|
321 | - * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
322 | - * |
|
323 | - * @param array $ticket_IDs |
|
324 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
325 | - * @throws EE_Error |
|
326 | - */ |
|
327 | - public function get_tickets_with_IDs(array $ticket_IDs) |
|
328 | - { |
|
329 | - return $this->get_all( |
|
330 | - array( |
|
331 | - array( |
|
332 | - 'TKT_ID' => array('IN', $ticket_IDs) |
|
333 | - ) |
|
334 | - ) |
|
335 | - ); |
|
336 | - } |
|
320 | + /** |
|
321 | + * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
322 | + * |
|
323 | + * @param array $ticket_IDs |
|
324 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
325 | + * @throws EE_Error |
|
326 | + */ |
|
327 | + public function get_tickets_with_IDs(array $ticket_IDs) |
|
328 | + { |
|
329 | + return $this->get_all( |
|
330 | + array( |
|
331 | + array( |
|
332 | + 'TKT_ID' => array('IN', $ticket_IDs) |
|
333 | + ) |
|
334 | + ) |
|
335 | + ); |
|
336 | + } |
|
337 | 337 | |
338 | 338 | |
339 | 339 |
@@ -2,8 +2,8 @@ discard block |
||
2 | 2 | |
3 | 3 | defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
4 | 4 | |
5 | -require_once(EE_MODELS . 'EEM_Soft_Delete_Base.model.php'); |
|
6 | -require_once(EE_CLASSES . 'EE_Ticket.class.php'); |
|
5 | +require_once(EE_MODELS.'EEM_Soft_Delete_Base.model.php'); |
|
6 | +require_once(EE_CLASSES.'EE_Ticket.class.php'); |
|
7 | 7 | /** |
8 | 8 | * Ticket Model |
9 | 9 | * |
@@ -249,10 +249,10 @@ discard block |
||
249 | 249 | foreach ($tickets as $ticket) { |
250 | 250 | $ticket->set( |
251 | 251 | 'TKT_start_date', |
252 | - (int)$this->current_time_for_query('TKT_start_date', true) |
|
252 | + (int) $this->current_time_for_query('TKT_start_date', true) |
|
253 | 253 | ); |
254 | 254 | $ticket->set('TKT_end_date', |
255 | - (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
255 | + (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
256 | 256 | ); |
257 | 257 | $ticket->set_end_time($this->convert_datetime_for_query( |
258 | 258 | 'TKT_end_date', |