@@ -19,523 +19,523 @@ |
||
19 | 19 | */ |
20 | 20 | class RegistrationsReport extends JobHandlerFile |
21 | 21 | { |
22 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
23 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
24 | - /** |
|
25 | - * Performs any necessary setup for starting the job. This is also a good |
|
26 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
27 | - * when continue_job will be called |
|
28 | - * |
|
29 | - * @param JobParameters $job_parameters |
|
30 | - * @throws BatchRequestException |
|
31 | - * @return JobStepResponse |
|
32 | - */ |
|
33 | - public function create_job(JobParameters $job_parameters) |
|
34 | - { |
|
35 | - $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
36 | - if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
37 | - throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
38 | - } |
|
39 | - $filepath = $this->create_file_from_job_with_name( |
|
40 | - $job_parameters->job_id(), |
|
41 | - $this->get_filename($event_id) |
|
42 | - ); |
|
43 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
44 | - if ($job_parameters->request_datum('use_filters', false)) { |
|
45 | - $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
46 | - } else { |
|
47 | - $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
48 | - array( |
|
49 | - 'OR' => array( |
|
50 | - // don't include registrations from failed or abandoned transactions... |
|
51 | - 'Transaction.STS_ID' => array( |
|
52 | - 'NOT IN', |
|
53 | - array( |
|
54 | - \EEM_Transaction::failed_status_code, |
|
55 | - \EEM_Transaction::abandoned_status_code, |
|
56 | - ), |
|
57 | - ), |
|
58 | - // unless the registration is approved, in which case include it regardless of transaction status |
|
59 | - 'STS_ID' => \EEM_Registration::status_id_approved, |
|
60 | - ), |
|
61 | - 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
62 | - ), |
|
63 | - 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
64 | - 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
65 | - 'caps' => \EEM_Base::caps_read_admin, |
|
66 | - ), $event_id); |
|
67 | - if ($event_id) { |
|
68 | - $query_params[0]['EVT_ID'] = $event_id; |
|
69 | - } else { |
|
70 | - $query_params['force_join'][] = 'Event'; |
|
71 | - } |
|
72 | - } |
|
73 | - if (! isset($query_params['force_join'])) { |
|
74 | - $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
75 | - } |
|
76 | - $job_parameters->add_extra_data('query_params', $query_params); |
|
77 | - $question_labels = $this->_get_question_labels($query_params); |
|
78 | - $job_parameters->add_extra_data('question_labels', $question_labels); |
|
79 | - $job_parameters->set_job_size( |
|
80 | - \EEM_Registration::instance()->count( |
|
81 | - array_diff_key( |
|
82 | - $query_params, |
|
83 | - array_flip( |
|
84 | - array('limit') |
|
85 | - ) |
|
86 | - ) |
|
87 | - ) |
|
88 | - ); |
|
89 | - // we should also set the header columns |
|
90 | - $csv_data_for_row = $this->get_csv_data_for( |
|
91 | - $event_id, |
|
92 | - 0, |
|
93 | - 1, |
|
94 | - $job_parameters->extra_datum('question_labels'), |
|
95 | - $job_parameters->extra_datum('query_params') |
|
96 | - ); |
|
97 | - \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
98 | - // if we actually processed a row there, record it |
|
99 | - if ($job_parameters->job_size()) { |
|
100 | - $job_parameters->mark_processed(1); |
|
101 | - } |
|
102 | - return new JobStepResponse( |
|
103 | - $job_parameters, |
|
104 | - __('Registrations report started successfully...', 'event_espresso') |
|
105 | - ); |
|
106 | - } |
|
22 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
23 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
24 | + /** |
|
25 | + * Performs any necessary setup for starting the job. This is also a good |
|
26 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
27 | + * when continue_job will be called |
|
28 | + * |
|
29 | + * @param JobParameters $job_parameters |
|
30 | + * @throws BatchRequestException |
|
31 | + * @return JobStepResponse |
|
32 | + */ |
|
33 | + public function create_job(JobParameters $job_parameters) |
|
34 | + { |
|
35 | + $event_id = intval($job_parameters->request_datum('EVT_ID', '0')); |
|
36 | + if (! \EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
37 | + throw new BatchRequestException(__('You do not have permission to view registrations', 'event_espresso')); |
|
38 | + } |
|
39 | + $filepath = $this->create_file_from_job_with_name( |
|
40 | + $job_parameters->job_id(), |
|
41 | + $this->get_filename($event_id) |
|
42 | + ); |
|
43 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
44 | + if ($job_parameters->request_datum('use_filters', false)) { |
|
45 | + $query_params = maybe_unserialize(stripslashes($job_parameters->request_datum('filters', array()))); |
|
46 | + } else { |
|
47 | + $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
48 | + array( |
|
49 | + 'OR' => array( |
|
50 | + // don't include registrations from failed or abandoned transactions... |
|
51 | + 'Transaction.STS_ID' => array( |
|
52 | + 'NOT IN', |
|
53 | + array( |
|
54 | + \EEM_Transaction::failed_status_code, |
|
55 | + \EEM_Transaction::abandoned_status_code, |
|
56 | + ), |
|
57 | + ), |
|
58 | + // unless the registration is approved, in which case include it regardless of transaction status |
|
59 | + 'STS_ID' => \EEM_Registration::status_id_approved, |
|
60 | + ), |
|
61 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
62 | + ), |
|
63 | + 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
64 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
65 | + 'caps' => \EEM_Base::caps_read_admin, |
|
66 | + ), $event_id); |
|
67 | + if ($event_id) { |
|
68 | + $query_params[0]['EVT_ID'] = $event_id; |
|
69 | + } else { |
|
70 | + $query_params['force_join'][] = 'Event'; |
|
71 | + } |
|
72 | + } |
|
73 | + if (! isset($query_params['force_join'])) { |
|
74 | + $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
75 | + } |
|
76 | + $job_parameters->add_extra_data('query_params', $query_params); |
|
77 | + $question_labels = $this->_get_question_labels($query_params); |
|
78 | + $job_parameters->add_extra_data('question_labels', $question_labels); |
|
79 | + $job_parameters->set_job_size( |
|
80 | + \EEM_Registration::instance()->count( |
|
81 | + array_diff_key( |
|
82 | + $query_params, |
|
83 | + array_flip( |
|
84 | + array('limit') |
|
85 | + ) |
|
86 | + ) |
|
87 | + ) |
|
88 | + ); |
|
89 | + // we should also set the header columns |
|
90 | + $csv_data_for_row = $this->get_csv_data_for( |
|
91 | + $event_id, |
|
92 | + 0, |
|
93 | + 1, |
|
94 | + $job_parameters->extra_datum('question_labels'), |
|
95 | + $job_parameters->extra_datum('query_params') |
|
96 | + ); |
|
97 | + \EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
98 | + // if we actually processed a row there, record it |
|
99 | + if ($job_parameters->job_size()) { |
|
100 | + $job_parameters->mark_processed(1); |
|
101 | + } |
|
102 | + return new JobStepResponse( |
|
103 | + $job_parameters, |
|
104 | + __('Registrations report started successfully...', 'event_espresso') |
|
105 | + ); |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * Gets the filename |
|
111 | - * |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - protected function get_filename() |
|
115 | - { |
|
116 | - return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql'))); |
|
117 | - } |
|
109 | + /** |
|
110 | + * Gets the filename |
|
111 | + * |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + protected function get_filename() |
|
115 | + { |
|
116 | + return sprintf("event-espresso-registrations-%s.csv", str_replace(':', '-', current_time('mysql'))); |
|
117 | + } |
|
118 | 118 | |
119 | 119 | |
120 | - /** |
|
121 | - * Gets the questions which are to be used for this report, so they |
|
122 | - * can be remembered for later |
|
123 | - * |
|
124 | - * @param array $registration_query_params |
|
125 | - * @return array question admin labels to be used for this report |
|
126 | - */ |
|
127 | - protected function _get_question_labels($registration_query_params) |
|
128 | - { |
|
129 | - $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
130 | - $question_query_params = array(); |
|
131 | - if ($where !== null) { |
|
132 | - $question_query_params = array( |
|
133 | - $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
134 | - ); |
|
135 | - } |
|
136 | - $question_query_params[0]['QST_system'] = array( |
|
137 | - 'NOT_IN', |
|
138 | - array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping()), |
|
139 | - ); |
|
140 | - if (apply_filters( |
|
141 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
142 | - false, |
|
143 | - $registration_query_params |
|
144 | - )) { |
|
145 | - $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
146 | - } |
|
147 | - $question_query_params['group_by'] = array('QST_ID'); |
|
148 | - return array_unique(\EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
149 | - } |
|
120 | + /** |
|
121 | + * Gets the questions which are to be used for this report, so they |
|
122 | + * can be remembered for later |
|
123 | + * |
|
124 | + * @param array $registration_query_params |
|
125 | + * @return array question admin labels to be used for this report |
|
126 | + */ |
|
127 | + protected function _get_question_labels($registration_query_params) |
|
128 | + { |
|
129 | + $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
130 | + $question_query_params = array(); |
|
131 | + if ($where !== null) { |
|
132 | + $question_query_params = array( |
|
133 | + $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
134 | + ); |
|
135 | + } |
|
136 | + $question_query_params[0]['QST_system'] = array( |
|
137 | + 'NOT_IN', |
|
138 | + array_keys(\EEM_Attendee::instance()->system_question_to_attendee_field_mapping()), |
|
139 | + ); |
|
140 | + if (apply_filters( |
|
141 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
142 | + false, |
|
143 | + $registration_query_params |
|
144 | + )) { |
|
145 | + $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
146 | + } |
|
147 | + $question_query_params['group_by'] = array('QST_ID'); |
|
148 | + return array_unique(\EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
149 | + } |
|
150 | 150 | |
151 | 151 | |
152 | - /** |
|
153 | - * Takes where params meant for registrations and changes them to work for questions |
|
154 | - * |
|
155 | - * @param array $reg_where_params |
|
156 | - * @return array |
|
157 | - */ |
|
158 | - protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
159 | - { |
|
160 | - $question_where_params = array(); |
|
161 | - foreach ($reg_where_params as $key => $val) { |
|
162 | - if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
163 | - $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
164 | - } else { |
|
165 | - // it's a normal where condition |
|
166 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
167 | - } |
|
168 | - } |
|
169 | - return $question_where_params; |
|
170 | - } |
|
152 | + /** |
|
153 | + * Takes where params meant for registrations and changes them to work for questions |
|
154 | + * |
|
155 | + * @param array $reg_where_params |
|
156 | + * @return array |
|
157 | + */ |
|
158 | + protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
159 | + { |
|
160 | + $question_where_params = array(); |
|
161 | + foreach ($reg_where_params as $key => $val) { |
|
162 | + if (\EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
163 | + $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
164 | + } else { |
|
165 | + // it's a normal where condition |
|
166 | + $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
167 | + } |
|
168 | + } |
|
169 | + return $question_where_params; |
|
170 | + } |
|
171 | 171 | |
172 | 172 | |
173 | - /** |
|
174 | - * Performs another step of the job |
|
175 | - * |
|
176 | - * @param JobParameters $job_parameters |
|
177 | - * @param int $batch_size |
|
178 | - * @return JobStepResponse |
|
179 | - * @throws \EE_Error |
|
180 | - */ |
|
181 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
182 | - { |
|
183 | - if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
184 | - $csv_data = $this->get_csv_data_for( |
|
185 | - $job_parameters->request_datum('EVT_ID', '0'), |
|
186 | - $job_parameters->units_processed(), |
|
187 | - $batch_size, |
|
188 | - $job_parameters->extra_datum('question_labels'), |
|
189 | - $job_parameters->extra_datum('query_params') |
|
190 | - ); |
|
191 | - \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
192 | - $units_processed = count($csv_data); |
|
193 | - } else { |
|
194 | - $units_processed = 0; |
|
195 | - } |
|
196 | - $job_parameters->mark_processed($units_processed); |
|
197 | - $extra_response_data = array( |
|
198 | - 'file_url' => '', |
|
199 | - ); |
|
200 | - if ($units_processed < $batch_size) { |
|
201 | - $job_parameters->set_status(JobParameters::status_complete); |
|
202 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
203 | - } |
|
173 | + /** |
|
174 | + * Performs another step of the job |
|
175 | + * |
|
176 | + * @param JobParameters $job_parameters |
|
177 | + * @param int $batch_size |
|
178 | + * @return JobStepResponse |
|
179 | + * @throws \EE_Error |
|
180 | + */ |
|
181 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
182 | + { |
|
183 | + if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
184 | + $csv_data = $this->get_csv_data_for( |
|
185 | + $job_parameters->request_datum('EVT_ID', '0'), |
|
186 | + $job_parameters->units_processed(), |
|
187 | + $batch_size, |
|
188 | + $job_parameters->extra_datum('question_labels'), |
|
189 | + $job_parameters->extra_datum('query_params') |
|
190 | + ); |
|
191 | + \EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
192 | + $units_processed = count($csv_data); |
|
193 | + } else { |
|
194 | + $units_processed = 0; |
|
195 | + } |
|
196 | + $job_parameters->mark_processed($units_processed); |
|
197 | + $extra_response_data = array( |
|
198 | + 'file_url' => '', |
|
199 | + ); |
|
200 | + if ($units_processed < $batch_size) { |
|
201 | + $job_parameters->set_status(JobParameters::status_complete); |
|
202 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
203 | + } |
|
204 | 204 | |
205 | - return new JobStepResponse( |
|
206 | - $job_parameters, |
|
207 | - sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
208 | - $extra_response_data |
|
209 | - ); |
|
210 | - } |
|
205 | + return new JobStepResponse( |
|
206 | + $job_parameters, |
|
207 | + sprintf(__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
208 | + $extra_response_data |
|
209 | + ); |
|
210 | + } |
|
211 | 211 | |
212 | 212 | |
213 | - /** |
|
214 | - * Gets the csv data for a batch of registrations |
|
215 | - * |
|
216 | - * @param int|null $event_id |
|
217 | - * @param int $offset |
|
218 | - * @param int $limit |
|
219 | - * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
220 | - * @param array $query_params for using where querying the model |
|
221 | - * @return array top-level keys are numeric, next-level keys are column headers |
|
222 | - */ |
|
223 | - public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
224 | - { |
|
225 | - $reg_fields_to_include = array( |
|
226 | - 'TXN_ID', |
|
227 | - 'ATT_ID', |
|
228 | - 'REG_ID', |
|
229 | - 'REG_date', |
|
230 | - 'REG_code', |
|
231 | - 'REG_count', |
|
232 | - 'REG_final_price', |
|
233 | - ); |
|
234 | - $att_fields_to_include = array( |
|
235 | - 'ATT_fname', |
|
236 | - 'ATT_lname', |
|
237 | - 'ATT_email', |
|
238 | - 'ATT_address', |
|
239 | - 'ATT_address2', |
|
240 | - 'ATT_city', |
|
241 | - 'STA_ID', |
|
242 | - 'CNT_ISO', |
|
243 | - 'ATT_zip', |
|
244 | - 'ATT_phone', |
|
245 | - ); |
|
246 | - $registrations_csv_ready_array = array(); |
|
247 | - $reg_model = \EE_Registry::instance()->load_model('Registration'); |
|
248 | - $query_params['limit'] = array($offset, $limit); |
|
249 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
250 | - $registration_ids = array(); |
|
251 | - foreach ($registration_rows as $reg_row) { |
|
252 | - $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
253 | - } |
|
254 | - foreach ($registration_rows as $reg_row) { |
|
255 | - if (is_array($reg_row)) { |
|
256 | - $reg_csv_array = array(); |
|
257 | - if (! $event_id) { |
|
258 | - // get the event's name and Id |
|
259 | - $reg_csv_array[ __('Event', 'event_espresso') ] = sprintf( |
|
260 | - __('%1$s (%2$s)', 'event_espresso'), |
|
261 | - \EEH_Export::prepare_value_from_db_for_display( |
|
262 | - \EEM_Event::instance(), |
|
263 | - 'EVT_name', |
|
264 | - $reg_row['Event_CPT.post_title'] |
|
265 | - ), |
|
266 | - $reg_row['Event_CPT.ID'] |
|
267 | - ); |
|
268 | - } |
|
269 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
270 | - /*@var $reg_row EE_Registration */ |
|
271 | - foreach ($reg_fields_to_include as $field_name) { |
|
272 | - $field = $reg_model->field_settings_for($field_name); |
|
273 | - if ($field_name == 'REG_final_price') { |
|
274 | - $value = \EEH_Export::prepare_value_from_db_for_display( |
|
275 | - $reg_model, |
|
276 | - $field_name, |
|
277 | - $reg_row['Registration.REG_final_price'], |
|
278 | - 'localized_float' |
|
279 | - ); |
|
280 | - } elseif ($field_name == 'REG_count') { |
|
281 | - $value = sprintf( |
|
282 | - __('%1$s of %2$s', 'event_espresso'), |
|
283 | - \EEH_Export::prepare_value_from_db_for_display( |
|
284 | - $reg_model, |
|
285 | - 'REG_count', |
|
286 | - $reg_row['Registration.REG_count'] |
|
287 | - ), |
|
288 | - \EEH_Export::prepare_value_from_db_for_display( |
|
289 | - $reg_model, |
|
290 | - 'REG_group_size', |
|
291 | - $reg_row['Registration.REG_group_size'] |
|
292 | - ) |
|
293 | - ); |
|
294 | - } elseif ($field_name == 'REG_date') { |
|
295 | - $value = \EEH_Export::prepare_value_from_db_for_display( |
|
296 | - $reg_model, |
|
297 | - $field_name, |
|
298 | - $reg_row['Registration.REG_date'], |
|
299 | - 'no_html' |
|
300 | - ); |
|
301 | - } else { |
|
302 | - $value = \EEH_Export::prepare_value_from_db_for_display( |
|
303 | - $reg_model, |
|
304 | - $field_name, |
|
305 | - $reg_row[ $field->get_qualified_column() ] |
|
306 | - ); |
|
307 | - } |
|
308 | - $reg_csv_array[ \EEH_Export::get_column_name_for_field($field) ] = $value; |
|
309 | - if ($field_name == 'REG_final_price') { |
|
310 | - // add a column named Currency after the final price |
|
311 | - $reg_csv_array[ __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
312 | - } |
|
313 | - } |
|
314 | - // get pretty status |
|
315 | - $stati = \EEM_Status::instance()->localized_status( |
|
316 | - array( |
|
317 | - $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
318 | - $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
319 | - ), |
|
320 | - false, |
|
321 | - 'sentence' |
|
322 | - ); |
|
323 | - $reg_csv_array[ __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
324 | - // get pretty transaction status |
|
325 | - $reg_csv_array[ __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
326 | - $reg_csv_array[ __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
327 | - ? \EEH_Export::prepare_value_from_db_for_display( |
|
328 | - \EEM_Transaction::instance(), |
|
329 | - 'TXN_total', |
|
330 | - $reg_row['TransactionTable.TXN_total'], |
|
331 | - 'localized_float' |
|
332 | - ) : '0.00'; |
|
333 | - $reg_csv_array[ __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
334 | - ? \EEH_Export::prepare_value_from_db_for_display( |
|
335 | - \EEM_Transaction::instance(), |
|
336 | - 'TXN_paid', |
|
337 | - $reg_row['TransactionTable.TXN_paid'], |
|
338 | - 'localized_float' |
|
339 | - ) : '0.00'; |
|
340 | - $payment_methods = array(); |
|
341 | - $gateway_txn_ids_etc = array(); |
|
342 | - $payment_times = array(); |
|
343 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
344 | - $payments_info = \EEM_Payment::instance()->get_all_wpdb_results( |
|
345 | - array( |
|
346 | - array( |
|
347 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
348 | - 'STS_ID' => \EEM_Payment::status_id_approved, |
|
349 | - ), |
|
350 | - 'force_join' => array('Payment_Method'), |
|
351 | - ), |
|
352 | - ARRAY_A, |
|
353 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
354 | - ); |
|
355 | - foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
356 | - $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
357 | - ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
358 | - $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
359 | - ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
360 | - $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
361 | - ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
362 | - } |
|
363 | - } |
|
364 | - $reg_csv_array[ __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
365 | - $reg_csv_array[ __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
366 | - $reg_csv_array[ __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
367 | - ',', |
|
368 | - $gateway_txn_ids_etc |
|
369 | - ); |
|
370 | - // get whether or not the user has checked in |
|
371 | - $reg_csv_array[ __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
372 | - $reg_row['Registration.REG_ID'], |
|
373 | - 'Checkin' |
|
374 | - ); |
|
375 | - // get ticket of registration and its price |
|
376 | - $ticket_model = \EE_Registry::instance()->load_model('Ticket'); |
|
377 | - if ($reg_row['Ticket.TKT_ID']) { |
|
378 | - $ticket_name = \EEH_Export::prepare_value_from_db_for_display( |
|
379 | - $ticket_model, |
|
380 | - 'TKT_name', |
|
381 | - $reg_row['Ticket.TKT_name'] |
|
382 | - ); |
|
383 | - $datetimes_strings = array(); |
|
384 | - foreach (\EEM_Datetime::instance()->get_all_wpdb_results( |
|
385 | - array( |
|
386 | - array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
387 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
388 | - 'default_where_conditions' => 'none', |
|
389 | - ) |
|
390 | - ) as $datetime) { |
|
391 | - $datetimes_strings[] = \EEH_Export::prepare_value_from_db_for_display( |
|
392 | - \EEM_Datetime::instance(), |
|
393 | - 'DTT_EVT_start', |
|
394 | - $datetime['Datetime.DTT_EVT_start'] |
|
395 | - ); |
|
396 | - } |
|
397 | - } else { |
|
398 | - $ticket_name = __('Unknown', 'event_espresso'); |
|
399 | - $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
400 | - } |
|
401 | - $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
402 | - $reg_csv_array[ __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
403 | - // get datetime(s) of registration |
|
404 | - // add attendee columns |
|
405 | - foreach ($att_fields_to_include as $att_field_name) { |
|
406 | - $field_obj = \EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
407 | - if ($reg_row['Attendee_CPT.ID']) { |
|
408 | - if ($att_field_name == 'STA_ID') { |
|
409 | - $value = \EEM_State::instance()->get_var( |
|
410 | - array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
411 | - 'STA_name' |
|
412 | - ); |
|
413 | - } elseif ($att_field_name == 'CNT_ISO') { |
|
414 | - $value = \EEM_Country::instance()->get_var( |
|
415 | - array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
416 | - 'CNT_name' |
|
417 | - ); |
|
418 | - } else { |
|
419 | - $value = \EEH_Export::prepare_value_from_db_for_display( |
|
420 | - \EEM_Attendee::instance(), |
|
421 | - $att_field_name, |
|
422 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
423 | - ); |
|
424 | - } |
|
425 | - } else { |
|
426 | - $value = ''; |
|
427 | - } |
|
428 | - $reg_csv_array[ \EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
429 | - } |
|
430 | - // make sure each registration has the same questions in the same order |
|
431 | - foreach ($question_labels as $question_label) { |
|
432 | - if (! isset($reg_csv_array[ $question_label ])) { |
|
433 | - $reg_csv_array[ $question_label ] = null; |
|
434 | - } |
|
435 | - } |
|
436 | - $answers = \EEM_Answer::instance()->get_all_wpdb_results(array( |
|
437 | - array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
438 | - 'force_join' => array('Question'), |
|
439 | - )); |
|
440 | - // now fill out the questions THEY answered |
|
441 | - foreach ($answers as $answer_row) { |
|
442 | - if ($answer_row['Question.QST_ID']) { |
|
443 | - $question_label = \EEH_Export::prepare_value_from_db_for_display( |
|
444 | - \EEM_Question::instance(), |
|
445 | - 'QST_admin_label', |
|
446 | - $answer_row['Question.QST_admin_label'] |
|
447 | - ); |
|
448 | - } else { |
|
449 | - $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
450 | - } |
|
451 | - if (isset($answer_row['Question.QST_type']) |
|
452 | - && $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state |
|
453 | - ) { |
|
454 | - $reg_csv_array[ $question_label ] = \EEM_State::instance()->get_state_name_by_ID( |
|
455 | - $answer_row['Answer.ANS_value'] |
|
456 | - ); |
|
457 | - } else { |
|
458 | - // this isn't for html, so don't show html entities |
|
459 | - $reg_csv_array[ $question_label ] = html_entity_decode( |
|
460 | - \EEH_Export::prepare_value_from_db_for_display( |
|
461 | - \EEM_Answer::instance(), |
|
462 | - 'ANS_value', |
|
463 | - $answer_row['Answer.ANS_value'] |
|
464 | - ) |
|
465 | - ); |
|
466 | - } |
|
467 | - } |
|
468 | - /** |
|
469 | - * Filter to change the contents of each row of the registrations report CSV file. |
|
470 | - * This can be used to add or remote columns from the CSV file, or change their values. * |
|
471 | - * Note: it has this name because originally that's where this filter resided, |
|
472 | - * and we've left its name as-is for backward compatibility. |
|
473 | - * Note when using: all rows in the CSV should have the same columns. |
|
474 | - * |
|
475 | - * @param array $reg_csv_array keys are column-header names, and values are that columns' value |
|
476 | - * in this row |
|
477 | - * @param array $reg_row is the row from the database's wp_esp_registration table |
|
478 | - */ |
|
479 | - $registrations_csv_ready_array[] = apply_filters( |
|
480 | - 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
481 | - $reg_csv_array, |
|
482 | - $reg_row |
|
483 | - ); |
|
484 | - } |
|
485 | - } |
|
486 | - // if we couldn't export anything, we want to at least show the column headers |
|
487 | - if (empty($registrations_csv_ready_array)) { |
|
488 | - $reg_csv_array = array(); |
|
489 | - $model_and_fields_to_include = array( |
|
490 | - 'Registration' => $reg_fields_to_include, |
|
491 | - 'Attendee' => $att_fields_to_include, |
|
492 | - ); |
|
493 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
494 | - $model = \EE_Registry::instance()->load_model($model_name); |
|
495 | - foreach ($field_list as $field_name) { |
|
496 | - $field = $model->field_settings_for($field_name); |
|
497 | - $reg_csv_array[ \EEH_Export::get_column_name_for_field($field) ] = null; |
|
498 | - } |
|
499 | - } |
|
500 | - $registrations_csv_ready_array[] = $reg_csv_array; |
|
501 | - } |
|
502 | - return $registrations_csv_ready_array; |
|
503 | - } |
|
213 | + /** |
|
214 | + * Gets the csv data for a batch of registrations |
|
215 | + * |
|
216 | + * @param int|null $event_id |
|
217 | + * @param int $offset |
|
218 | + * @param int $limit |
|
219 | + * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
220 | + * @param array $query_params for using where querying the model |
|
221 | + * @return array top-level keys are numeric, next-level keys are column headers |
|
222 | + */ |
|
223 | + public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params) |
|
224 | + { |
|
225 | + $reg_fields_to_include = array( |
|
226 | + 'TXN_ID', |
|
227 | + 'ATT_ID', |
|
228 | + 'REG_ID', |
|
229 | + 'REG_date', |
|
230 | + 'REG_code', |
|
231 | + 'REG_count', |
|
232 | + 'REG_final_price', |
|
233 | + ); |
|
234 | + $att_fields_to_include = array( |
|
235 | + 'ATT_fname', |
|
236 | + 'ATT_lname', |
|
237 | + 'ATT_email', |
|
238 | + 'ATT_address', |
|
239 | + 'ATT_address2', |
|
240 | + 'ATT_city', |
|
241 | + 'STA_ID', |
|
242 | + 'CNT_ISO', |
|
243 | + 'ATT_zip', |
|
244 | + 'ATT_phone', |
|
245 | + ); |
|
246 | + $registrations_csv_ready_array = array(); |
|
247 | + $reg_model = \EE_Registry::instance()->load_model('Registration'); |
|
248 | + $query_params['limit'] = array($offset, $limit); |
|
249 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
250 | + $registration_ids = array(); |
|
251 | + foreach ($registration_rows as $reg_row) { |
|
252 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
253 | + } |
|
254 | + foreach ($registration_rows as $reg_row) { |
|
255 | + if (is_array($reg_row)) { |
|
256 | + $reg_csv_array = array(); |
|
257 | + if (! $event_id) { |
|
258 | + // get the event's name and Id |
|
259 | + $reg_csv_array[ __('Event', 'event_espresso') ] = sprintf( |
|
260 | + __('%1$s (%2$s)', 'event_espresso'), |
|
261 | + \EEH_Export::prepare_value_from_db_for_display( |
|
262 | + \EEM_Event::instance(), |
|
263 | + 'EVT_name', |
|
264 | + $reg_row['Event_CPT.post_title'] |
|
265 | + ), |
|
266 | + $reg_row['Event_CPT.ID'] |
|
267 | + ); |
|
268 | + } |
|
269 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
270 | + /*@var $reg_row EE_Registration */ |
|
271 | + foreach ($reg_fields_to_include as $field_name) { |
|
272 | + $field = $reg_model->field_settings_for($field_name); |
|
273 | + if ($field_name == 'REG_final_price') { |
|
274 | + $value = \EEH_Export::prepare_value_from_db_for_display( |
|
275 | + $reg_model, |
|
276 | + $field_name, |
|
277 | + $reg_row['Registration.REG_final_price'], |
|
278 | + 'localized_float' |
|
279 | + ); |
|
280 | + } elseif ($field_name == 'REG_count') { |
|
281 | + $value = sprintf( |
|
282 | + __('%1$s of %2$s', 'event_espresso'), |
|
283 | + \EEH_Export::prepare_value_from_db_for_display( |
|
284 | + $reg_model, |
|
285 | + 'REG_count', |
|
286 | + $reg_row['Registration.REG_count'] |
|
287 | + ), |
|
288 | + \EEH_Export::prepare_value_from_db_for_display( |
|
289 | + $reg_model, |
|
290 | + 'REG_group_size', |
|
291 | + $reg_row['Registration.REG_group_size'] |
|
292 | + ) |
|
293 | + ); |
|
294 | + } elseif ($field_name == 'REG_date') { |
|
295 | + $value = \EEH_Export::prepare_value_from_db_for_display( |
|
296 | + $reg_model, |
|
297 | + $field_name, |
|
298 | + $reg_row['Registration.REG_date'], |
|
299 | + 'no_html' |
|
300 | + ); |
|
301 | + } else { |
|
302 | + $value = \EEH_Export::prepare_value_from_db_for_display( |
|
303 | + $reg_model, |
|
304 | + $field_name, |
|
305 | + $reg_row[ $field->get_qualified_column() ] |
|
306 | + ); |
|
307 | + } |
|
308 | + $reg_csv_array[ \EEH_Export::get_column_name_for_field($field) ] = $value; |
|
309 | + if ($field_name == 'REG_final_price') { |
|
310 | + // add a column named Currency after the final price |
|
311 | + $reg_csv_array[ __("Currency", "event_espresso") ] = \EE_Config::instance()->currency->code; |
|
312 | + } |
|
313 | + } |
|
314 | + // get pretty status |
|
315 | + $stati = \EEM_Status::instance()->localized_status( |
|
316 | + array( |
|
317 | + $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
318 | + $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
319 | + ), |
|
320 | + false, |
|
321 | + 'sentence' |
|
322 | + ); |
|
323 | + $reg_csv_array[ __("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
324 | + // get pretty transaction status |
|
325 | + $reg_csv_array[ __("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
326 | + $reg_csv_array[ __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
327 | + ? \EEH_Export::prepare_value_from_db_for_display( |
|
328 | + \EEM_Transaction::instance(), |
|
329 | + 'TXN_total', |
|
330 | + $reg_row['TransactionTable.TXN_total'], |
|
331 | + 'localized_float' |
|
332 | + ) : '0.00'; |
|
333 | + $reg_csv_array[ __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
334 | + ? \EEH_Export::prepare_value_from_db_for_display( |
|
335 | + \EEM_Transaction::instance(), |
|
336 | + 'TXN_paid', |
|
337 | + $reg_row['TransactionTable.TXN_paid'], |
|
338 | + 'localized_float' |
|
339 | + ) : '0.00'; |
|
340 | + $payment_methods = array(); |
|
341 | + $gateway_txn_ids_etc = array(); |
|
342 | + $payment_times = array(); |
|
343 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
344 | + $payments_info = \EEM_Payment::instance()->get_all_wpdb_results( |
|
345 | + array( |
|
346 | + array( |
|
347 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
348 | + 'STS_ID' => \EEM_Payment::status_id_approved, |
|
349 | + ), |
|
350 | + 'force_join' => array('Payment_Method'), |
|
351 | + ), |
|
352 | + ARRAY_A, |
|
353 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
354 | + ); |
|
355 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
356 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
357 | + ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
358 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
359 | + ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
360 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
361 | + ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
362 | + } |
|
363 | + } |
|
364 | + $reg_csv_array[ __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
365 | + $reg_csv_array[ __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
366 | + $reg_csv_array[ __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
367 | + ',', |
|
368 | + $gateway_txn_ids_etc |
|
369 | + ); |
|
370 | + // get whether or not the user has checked in |
|
371 | + $reg_csv_array[ __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
372 | + $reg_row['Registration.REG_ID'], |
|
373 | + 'Checkin' |
|
374 | + ); |
|
375 | + // get ticket of registration and its price |
|
376 | + $ticket_model = \EE_Registry::instance()->load_model('Ticket'); |
|
377 | + if ($reg_row['Ticket.TKT_ID']) { |
|
378 | + $ticket_name = \EEH_Export::prepare_value_from_db_for_display( |
|
379 | + $ticket_model, |
|
380 | + 'TKT_name', |
|
381 | + $reg_row['Ticket.TKT_name'] |
|
382 | + ); |
|
383 | + $datetimes_strings = array(); |
|
384 | + foreach (\EEM_Datetime::instance()->get_all_wpdb_results( |
|
385 | + array( |
|
386 | + array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
387 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
388 | + 'default_where_conditions' => 'none', |
|
389 | + ) |
|
390 | + ) as $datetime) { |
|
391 | + $datetimes_strings[] = \EEH_Export::prepare_value_from_db_for_display( |
|
392 | + \EEM_Datetime::instance(), |
|
393 | + 'DTT_EVT_start', |
|
394 | + $datetime['Datetime.DTT_EVT_start'] |
|
395 | + ); |
|
396 | + } |
|
397 | + } else { |
|
398 | + $ticket_name = __('Unknown', 'event_espresso'); |
|
399 | + $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
400 | + } |
|
401 | + $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
402 | + $reg_csv_array[ __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
403 | + // get datetime(s) of registration |
|
404 | + // add attendee columns |
|
405 | + foreach ($att_fields_to_include as $att_field_name) { |
|
406 | + $field_obj = \EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
407 | + if ($reg_row['Attendee_CPT.ID']) { |
|
408 | + if ($att_field_name == 'STA_ID') { |
|
409 | + $value = \EEM_State::instance()->get_var( |
|
410 | + array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
411 | + 'STA_name' |
|
412 | + ); |
|
413 | + } elseif ($att_field_name == 'CNT_ISO') { |
|
414 | + $value = \EEM_Country::instance()->get_var( |
|
415 | + array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
416 | + 'CNT_name' |
|
417 | + ); |
|
418 | + } else { |
|
419 | + $value = \EEH_Export::prepare_value_from_db_for_display( |
|
420 | + \EEM_Attendee::instance(), |
|
421 | + $att_field_name, |
|
422 | + $reg_row[ $field_obj->get_qualified_column() ] |
|
423 | + ); |
|
424 | + } |
|
425 | + } else { |
|
426 | + $value = ''; |
|
427 | + } |
|
428 | + $reg_csv_array[ \EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
429 | + } |
|
430 | + // make sure each registration has the same questions in the same order |
|
431 | + foreach ($question_labels as $question_label) { |
|
432 | + if (! isset($reg_csv_array[ $question_label ])) { |
|
433 | + $reg_csv_array[ $question_label ] = null; |
|
434 | + } |
|
435 | + } |
|
436 | + $answers = \EEM_Answer::instance()->get_all_wpdb_results(array( |
|
437 | + array('REG_ID' => $reg_row['Registration.REG_ID']), |
|
438 | + 'force_join' => array('Question'), |
|
439 | + )); |
|
440 | + // now fill out the questions THEY answered |
|
441 | + foreach ($answers as $answer_row) { |
|
442 | + if ($answer_row['Question.QST_ID']) { |
|
443 | + $question_label = \EEH_Export::prepare_value_from_db_for_display( |
|
444 | + \EEM_Question::instance(), |
|
445 | + 'QST_admin_label', |
|
446 | + $answer_row['Question.QST_admin_label'] |
|
447 | + ); |
|
448 | + } else { |
|
449 | + $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
450 | + } |
|
451 | + if (isset($answer_row['Question.QST_type']) |
|
452 | + && $answer_row['Question.QST_type'] == \EEM_Question::QST_type_state |
|
453 | + ) { |
|
454 | + $reg_csv_array[ $question_label ] = \EEM_State::instance()->get_state_name_by_ID( |
|
455 | + $answer_row['Answer.ANS_value'] |
|
456 | + ); |
|
457 | + } else { |
|
458 | + // this isn't for html, so don't show html entities |
|
459 | + $reg_csv_array[ $question_label ] = html_entity_decode( |
|
460 | + \EEH_Export::prepare_value_from_db_for_display( |
|
461 | + \EEM_Answer::instance(), |
|
462 | + 'ANS_value', |
|
463 | + $answer_row['Answer.ANS_value'] |
|
464 | + ) |
|
465 | + ); |
|
466 | + } |
|
467 | + } |
|
468 | + /** |
|
469 | + * Filter to change the contents of each row of the registrations report CSV file. |
|
470 | + * This can be used to add or remote columns from the CSV file, or change their values. * |
|
471 | + * Note: it has this name because originally that's where this filter resided, |
|
472 | + * and we've left its name as-is for backward compatibility. |
|
473 | + * Note when using: all rows in the CSV should have the same columns. |
|
474 | + * |
|
475 | + * @param array $reg_csv_array keys are column-header names, and values are that columns' value |
|
476 | + * in this row |
|
477 | + * @param array $reg_row is the row from the database's wp_esp_registration table |
|
478 | + */ |
|
479 | + $registrations_csv_ready_array[] = apply_filters( |
|
480 | + 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
481 | + $reg_csv_array, |
|
482 | + $reg_row |
|
483 | + ); |
|
484 | + } |
|
485 | + } |
|
486 | + // if we couldn't export anything, we want to at least show the column headers |
|
487 | + if (empty($registrations_csv_ready_array)) { |
|
488 | + $reg_csv_array = array(); |
|
489 | + $model_and_fields_to_include = array( |
|
490 | + 'Registration' => $reg_fields_to_include, |
|
491 | + 'Attendee' => $att_fields_to_include, |
|
492 | + ); |
|
493 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
494 | + $model = \EE_Registry::instance()->load_model($model_name); |
|
495 | + foreach ($field_list as $field_name) { |
|
496 | + $field = $model->field_settings_for($field_name); |
|
497 | + $reg_csv_array[ \EEH_Export::get_column_name_for_field($field) ] = null; |
|
498 | + } |
|
499 | + } |
|
500 | + $registrations_csv_ready_array[] = $reg_csv_array; |
|
501 | + } |
|
502 | + return $registrations_csv_ready_array; |
|
503 | + } |
|
504 | 504 | |
505 | 505 | |
506 | - /** |
|
507 | - * Counts total unit to process |
|
508 | - * |
|
509 | - * @deprecated since 4.9.19 |
|
510 | - * @param int|array $event_id |
|
511 | - * @return int |
|
512 | - */ |
|
513 | - public function count_units_to_process($event_id) |
|
514 | - { |
|
515 | - // use the legacy filter |
|
516 | - if ($event_id) { |
|
517 | - $query_params[0]['EVT_ID'] = $event_id; |
|
518 | - } else { |
|
519 | - $query_params['force_join'][] = 'Event'; |
|
520 | - } |
|
521 | - return \EEM_Registration::instance()->count($query_params); |
|
522 | - } |
|
506 | + /** |
|
507 | + * Counts total unit to process |
|
508 | + * |
|
509 | + * @deprecated since 4.9.19 |
|
510 | + * @param int|array $event_id |
|
511 | + * @return int |
|
512 | + */ |
|
513 | + public function count_units_to_process($event_id) |
|
514 | + { |
|
515 | + // use the legacy filter |
|
516 | + if ($event_id) { |
|
517 | + $query_params[0]['EVT_ID'] = $event_id; |
|
518 | + } else { |
|
519 | + $query_params['force_join'][] = 'Event'; |
|
520 | + } |
|
521 | + return \EEM_Registration::instance()->count($query_params); |
|
522 | + } |
|
523 | 523 | |
524 | 524 | |
525 | - /** |
|
526 | - * Performs any clean-up logic when we know the job is completed. |
|
527 | - * In this case, we delete the temporary file |
|
528 | - * |
|
529 | - * @param JobParameters $job_parameters |
|
530 | - * @return boolean |
|
531 | - */ |
|
532 | - public function cleanup_job(JobParameters $job_parameters) |
|
533 | - { |
|
534 | - $this->_file_helper->delete( |
|
535 | - \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
536 | - true, |
|
537 | - 'd' |
|
538 | - ); |
|
539 | - return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
540 | - } |
|
525 | + /** |
|
526 | + * Performs any clean-up logic when we know the job is completed. |
|
527 | + * In this case, we delete the temporary file |
|
528 | + * |
|
529 | + * @param JobParameters $job_parameters |
|
530 | + * @return boolean |
|
531 | + */ |
|
532 | + public function cleanup_job(JobParameters $job_parameters) |
|
533 | + { |
|
534 | + $this->_file_helper->delete( |
|
535 | + \EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
536 | + true, |
|
537 | + 'd' |
|
538 | + ); |
|
539 | + return new JobStepResponse($job_parameters, __('Cleaned up temporary file', 'event_espresso')); |
|
540 | + } |
|
541 | 541 | } |
@@ -17,189 +17,189 @@ |
||
17 | 17 | class EE_Select_Ajax_Model_Rest_Input extends EE_Form_Input_With_Options_Base |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $_model_name |
|
22 | - */ |
|
23 | - protected $_model_name; |
|
20 | + /** |
|
21 | + * @var string $_model_name |
|
22 | + */ |
|
23 | + protected $_model_name; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var string $_display_field_name |
|
27 | - */ |
|
28 | - protected $_display_field_name; |
|
25 | + /** |
|
26 | + * @var string $_display_field_name |
|
27 | + */ |
|
28 | + protected $_display_field_name; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var string $_value_field_name |
|
32 | - */ |
|
33 | - protected $_value_field_name; |
|
30 | + /** |
|
31 | + * @var string $_value_field_name |
|
32 | + */ |
|
33 | + protected $_value_field_name; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var array $_extra_select_columns |
|
37 | - */ |
|
38 | - protected $_extra_select_columns = array(); |
|
35 | + /** |
|
36 | + * @var array $_extra_select_columns |
|
37 | + */ |
|
38 | + protected $_extra_select_columns = array(); |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param array $input_settings { |
|
43 | - * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
44 | - * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
45 | - * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
46 | - * the string "where") |
|
47 | - * @type string $value_field_name the name of the model field on this model to |
|
48 | - * be used for the HTML select's option's values |
|
49 | - * @type string $display_field_name the name of the model field on this model |
|
50 | - * to be used for the HTML select's option's display text |
|
51 | - * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
52 | - * } |
|
53 | - * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
54 | - * } |
|
55 | - * @throws EE_Error |
|
56 | - * @throws InvalidArgumentException |
|
57 | - * @throws InvalidDataTypeException |
|
58 | - * @throws InvalidInterfaceException |
|
59 | - */ |
|
60 | - public function __construct($input_settings = array()) |
|
61 | - { |
|
62 | - // needed input settings: |
|
63 | - // select2_args |
|
64 | - $this->_model_name = EEH_Array::is_set( |
|
65 | - $input_settings, |
|
66 | - 'model_name', |
|
67 | - null |
|
68 | - ); |
|
69 | - $model = $this->_get_model(); |
|
70 | - $query_params = EEH_Array::is_set( |
|
71 | - $input_settings, |
|
72 | - 'query_params', |
|
73 | - array() |
|
74 | - ); |
|
75 | - // make sure limit and caps are always set |
|
76 | - $query_params = array_merge( |
|
77 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
78 | - $query_params |
|
79 | - ); |
|
80 | - $this->_value_field_name = EEH_Array::is_set( |
|
81 | - $input_settings, |
|
82 | - 'value_field_name', |
|
83 | - $model->primary_key_name() |
|
84 | - ); |
|
85 | - $this->_display_field_name = EEH_Array::is_set( |
|
86 | - $input_settings, |
|
87 | - 'display_field_name', |
|
88 | - $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
89 | - ); |
|
90 | - $this->_extra_select_columns = EEH_Array::is_set( |
|
91 | - $input_settings, |
|
92 | - 'extra_select_columns', |
|
93 | - array() |
|
94 | - ); |
|
95 | - $this->_add_validation_strategy( |
|
96 | - new EE_Model_Matching_Query_Validation_Strategy( |
|
97 | - '', |
|
98 | - $this->_model_name, |
|
99 | - $query_params, |
|
100 | - $this->_value_field_name |
|
101 | - ) |
|
102 | - ); |
|
103 | - // get resource endpoint |
|
104 | - $rest_controller = LoaderFactory::getLoader()->getNew( |
|
105 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
106 | - ); |
|
107 | - $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
108 | - $default_select2_args = array( |
|
109 | - 'ajax' => array( |
|
110 | - 'url' => $rest_controller->getVersionedLinkTo( |
|
111 | - EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
112 | - ), |
|
113 | - 'dataType' => 'json', |
|
114 | - 'delay' => '250', |
|
115 | - 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
116 | - 'data_interface_args' => array( |
|
117 | - 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
118 | - $query_params, |
|
119 | - $model |
|
120 | - ), |
|
121 | - 'display_field' => $this->_display_field_name, |
|
122 | - 'value_field' => $this->_value_field_name, |
|
123 | - 'nonce' => wp_create_nonce('wp_rest'), |
|
124 | - 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
125 | - ), |
|
126 | - ), |
|
127 | - 'cache' => true, |
|
128 | - 'width' => '100' |
|
129 | - ); |
|
130 | - $select2_args = array_replace_recursive( |
|
131 | - $default_select2_args, |
|
132 | - (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
133 | - ); |
|
134 | - $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
135 | - parent::__construct(array(), $input_settings); |
|
136 | - } |
|
41 | + /** |
|
42 | + * @param array $input_settings { |
|
43 | + * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
44 | + * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
45 | + * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
46 | + * the string "where") |
|
47 | + * @type string $value_field_name the name of the model field on this model to |
|
48 | + * be used for the HTML select's option's values |
|
49 | + * @type string $display_field_name the name of the model field on this model |
|
50 | + * to be used for the HTML select's option's display text |
|
51 | + * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
52 | + * } |
|
53 | + * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
54 | + * } |
|
55 | + * @throws EE_Error |
|
56 | + * @throws InvalidArgumentException |
|
57 | + * @throws InvalidDataTypeException |
|
58 | + * @throws InvalidInterfaceException |
|
59 | + */ |
|
60 | + public function __construct($input_settings = array()) |
|
61 | + { |
|
62 | + // needed input settings: |
|
63 | + // select2_args |
|
64 | + $this->_model_name = EEH_Array::is_set( |
|
65 | + $input_settings, |
|
66 | + 'model_name', |
|
67 | + null |
|
68 | + ); |
|
69 | + $model = $this->_get_model(); |
|
70 | + $query_params = EEH_Array::is_set( |
|
71 | + $input_settings, |
|
72 | + 'query_params', |
|
73 | + array() |
|
74 | + ); |
|
75 | + // make sure limit and caps are always set |
|
76 | + $query_params = array_merge( |
|
77 | + array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
78 | + $query_params |
|
79 | + ); |
|
80 | + $this->_value_field_name = EEH_Array::is_set( |
|
81 | + $input_settings, |
|
82 | + 'value_field_name', |
|
83 | + $model->primary_key_name() |
|
84 | + ); |
|
85 | + $this->_display_field_name = EEH_Array::is_set( |
|
86 | + $input_settings, |
|
87 | + 'display_field_name', |
|
88 | + $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
89 | + ); |
|
90 | + $this->_extra_select_columns = EEH_Array::is_set( |
|
91 | + $input_settings, |
|
92 | + 'extra_select_columns', |
|
93 | + array() |
|
94 | + ); |
|
95 | + $this->_add_validation_strategy( |
|
96 | + new EE_Model_Matching_Query_Validation_Strategy( |
|
97 | + '', |
|
98 | + $this->_model_name, |
|
99 | + $query_params, |
|
100 | + $this->_value_field_name |
|
101 | + ) |
|
102 | + ); |
|
103 | + // get resource endpoint |
|
104 | + $rest_controller = LoaderFactory::getLoader()->getNew( |
|
105 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
106 | + ); |
|
107 | + $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
108 | + $default_select2_args = array( |
|
109 | + 'ajax' => array( |
|
110 | + 'url' => $rest_controller->getVersionedLinkTo( |
|
111 | + EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
112 | + ), |
|
113 | + 'dataType' => 'json', |
|
114 | + 'delay' => '250', |
|
115 | + 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
116 | + 'data_interface_args' => array( |
|
117 | + 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
118 | + $query_params, |
|
119 | + $model |
|
120 | + ), |
|
121 | + 'display_field' => $this->_display_field_name, |
|
122 | + 'value_field' => $this->_value_field_name, |
|
123 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
124 | + 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
125 | + ), |
|
126 | + ), |
|
127 | + 'cache' => true, |
|
128 | + 'width' => '100' |
|
129 | + ); |
|
130 | + $select2_args = array_replace_recursive( |
|
131 | + $default_select2_args, |
|
132 | + (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
133 | + ); |
|
134 | + $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
135 | + parent::__construct(array(), $input_settings); |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | 139 | |
140 | - /** |
|
141 | - * Before setting the raw value (usually because we're setting the default, |
|
142 | - * or we've received a form submission and this might be re-displayed to the user), |
|
143 | - * sets the options so that the current selections appear on initial display. |
|
144 | - * |
|
145 | - * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
146 | - * for validation, this input's options only affect DISPLAY and NOT validation, |
|
147 | - * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
148 | - * |
|
149 | - * @param mixed $value |
|
150 | - * @return void |
|
151 | - * @throws \EE_Error |
|
152 | - */ |
|
153 | - public function _set_raw_value($value) |
|
154 | - { |
|
155 | - $values_for_options = (array) $value; |
|
156 | - $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
157 | - $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
158 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
159 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
160 | - $display_values = $this->_get_model()->get_all_wpdb_results( |
|
161 | - array( |
|
162 | - array( |
|
163 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
164 | - ) |
|
165 | - ), |
|
166 | - ARRAY_A, |
|
167 | - implode(',', $this->_extra_select_columns) |
|
168 | - ); |
|
169 | - $select_options = array(); |
|
170 | - if (is_array($select_options)) { |
|
171 | - foreach ($display_values as $db_rows) { |
|
172 | - $db_rows = (array) $db_rows; |
|
173 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
174 | - 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
175 | - $db_rows[ $this->_display_field_name ], |
|
176 | - $db_rows |
|
177 | - ); |
|
178 | - } |
|
179 | - } |
|
180 | - $this->set_select_options($select_options); |
|
181 | - parent::_set_raw_value($value); |
|
182 | - } |
|
140 | + /** |
|
141 | + * Before setting the raw value (usually because we're setting the default, |
|
142 | + * or we've received a form submission and this might be re-displayed to the user), |
|
143 | + * sets the options so that the current selections appear on initial display. |
|
144 | + * |
|
145 | + * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
146 | + * for validation, this input's options only affect DISPLAY and NOT validation, |
|
147 | + * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
148 | + * |
|
149 | + * @param mixed $value |
|
150 | + * @return void |
|
151 | + * @throws \EE_Error |
|
152 | + */ |
|
153 | + public function _set_raw_value($value) |
|
154 | + { |
|
155 | + $values_for_options = (array) $value; |
|
156 | + $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
157 | + $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
158 | + $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
159 | + $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
160 | + $display_values = $this->_get_model()->get_all_wpdb_results( |
|
161 | + array( |
|
162 | + array( |
|
163 | + $this->_value_field_name => array( 'IN', $values_for_options ) |
|
164 | + ) |
|
165 | + ), |
|
166 | + ARRAY_A, |
|
167 | + implode(',', $this->_extra_select_columns) |
|
168 | + ); |
|
169 | + $select_options = array(); |
|
170 | + if (is_array($select_options)) { |
|
171 | + foreach ($display_values as $db_rows) { |
|
172 | + $db_rows = (array) $db_rows; |
|
173 | + $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
174 | + 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
175 | + $db_rows[ $this->_display_field_name ], |
|
176 | + $db_rows |
|
177 | + ); |
|
178 | + } |
|
179 | + } |
|
180 | + $this->set_select_options($select_options); |
|
181 | + parent::_set_raw_value($value); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
186 | - * @return EEM_Base |
|
187 | - * @throws EE_Error |
|
188 | - */ |
|
189 | - protected function _get_model() |
|
190 | - { |
|
191 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
192 | - throw new EE_Error( |
|
193 | - sprintf( |
|
194 | - __( |
|
195 | - '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
196 | - 'event_espresso' |
|
197 | - ), |
|
198 | - $this->_model_name |
|
199 | - ) |
|
200 | - ); |
|
201 | - } else { |
|
202 | - return EE_Registry::instance()->load_model($this->_model_name); |
|
203 | - } |
|
204 | - } |
|
184 | + /** |
|
185 | + * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
186 | + * @return EEM_Base |
|
187 | + * @throws EE_Error |
|
188 | + */ |
|
189 | + protected function _get_model() |
|
190 | + { |
|
191 | + if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
192 | + throw new EE_Error( |
|
193 | + sprintf( |
|
194 | + __( |
|
195 | + '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
196 | + 'event_espresso' |
|
197 | + ), |
|
198 | + $this->_model_name |
|
199 | + ) |
|
200 | + ); |
|
201 | + } else { |
|
202 | + return EE_Registry::instance()->load_model($this->_model_name); |
|
203 | + } |
|
204 | + } |
|
205 | 205 | } |
@@ -20,1027 +20,1027 @@ |
||
20 | 20 | class EE_Dependency_Map |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * This means that the requested class dependency is not present in the dependency map |
|
25 | - */ |
|
26 | - const not_registered = 0; |
|
27 | - |
|
28 | - /** |
|
29 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
30 | - */ |
|
31 | - const load_new_object = 1; |
|
32 | - |
|
33 | - /** |
|
34 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
35 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
36 | - */ |
|
37 | - const load_from_cache = 2; |
|
38 | - |
|
39 | - /** |
|
40 | - * When registering a dependency, |
|
41 | - * this indicates to keep any existing dependencies that already exist, |
|
42 | - * and simply discard any new dependencies declared in the incoming data |
|
43 | - */ |
|
44 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
45 | - |
|
46 | - /** |
|
47 | - * When registering a dependency, |
|
48 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
49 | - */ |
|
50 | - const OVERWRITE_DEPENDENCIES = 1; |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @type EE_Dependency_Map $_instance |
|
55 | - */ |
|
56 | - protected static $_instance; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var ClassInterfaceCache $class_cache |
|
60 | - */ |
|
61 | - private $class_cache; |
|
62 | - |
|
63 | - /** |
|
64 | - * @type RequestInterface $request |
|
65 | - */ |
|
66 | - protected $request; |
|
67 | - |
|
68 | - /** |
|
69 | - * @type LegacyRequestInterface $legacy_request |
|
70 | - */ |
|
71 | - protected $legacy_request; |
|
72 | - |
|
73 | - /** |
|
74 | - * @type ResponseInterface $response |
|
75 | - */ |
|
76 | - protected $response; |
|
77 | - |
|
78 | - /** |
|
79 | - * @type LoaderInterface $loader |
|
80 | - */ |
|
81 | - protected $loader; |
|
82 | - |
|
83 | - /** |
|
84 | - * @type array $_dependency_map |
|
85 | - */ |
|
86 | - protected $_dependency_map = array(); |
|
87 | - |
|
88 | - /** |
|
89 | - * @type array $_class_loaders |
|
90 | - */ |
|
91 | - protected $_class_loaders = array(); |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * EE_Dependency_Map constructor. |
|
96 | - * |
|
97 | - * @param ClassInterfaceCache $class_cache |
|
98 | - */ |
|
99 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | - { |
|
101 | - $this->class_cache = $class_cache; |
|
102 | - do_action('EE_Dependency_Map____construct', $this); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return void |
|
108 | - */ |
|
109 | - public function initialize() |
|
110 | - { |
|
111 | - $this->_register_core_dependencies(); |
|
112 | - $this->_register_core_class_loaders(); |
|
113 | - $this->_register_core_aliases(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @singleton method used to instantiate class object |
|
119 | - * @param ClassInterfaceCache|null $class_cache |
|
120 | - * @return EE_Dependency_Map |
|
121 | - */ |
|
122 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
123 | - { |
|
124 | - // check if class object is instantiated, and instantiated properly |
|
125 | - if (! self::$_instance instanceof EE_Dependency_Map |
|
126 | - && $class_cache instanceof ClassInterfaceCache |
|
127 | - ) { |
|
128 | - self::$_instance = new EE_Dependency_Map($class_cache); |
|
129 | - } |
|
130 | - return self::$_instance; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param RequestInterface $request |
|
136 | - */ |
|
137 | - public function setRequest(RequestInterface $request) |
|
138 | - { |
|
139 | - $this->request = $request; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param LegacyRequestInterface $legacy_request |
|
145 | - */ |
|
146 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
147 | - { |
|
148 | - $this->legacy_request = $legacy_request; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @param ResponseInterface $response |
|
154 | - */ |
|
155 | - public function setResponse(ResponseInterface $response) |
|
156 | - { |
|
157 | - $this->response = $response; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param LoaderInterface $loader |
|
163 | - */ |
|
164 | - public function setLoader(LoaderInterface $loader) |
|
165 | - { |
|
166 | - $this->loader = $loader; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @param string $class |
|
172 | - * @param array $dependencies |
|
173 | - * @param int $overwrite |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public static function register_dependencies( |
|
177 | - $class, |
|
178 | - array $dependencies, |
|
179 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
180 | - ) { |
|
181 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
187 | - * to the class specified by the first parameter. |
|
188 | - * IMPORTANT !!! |
|
189 | - * The order of elements in the incoming $dependencies array MUST match |
|
190 | - * the order of the constructor parameters for the class in question. |
|
191 | - * This is especially important when overriding any existing dependencies that are registered. |
|
192 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
193 | - * |
|
194 | - * @param string $class |
|
195 | - * @param array $dependencies |
|
196 | - * @param int $overwrite |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function registerDependencies( |
|
200 | - $class, |
|
201 | - array $dependencies, |
|
202 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
203 | - ) { |
|
204 | - $class = trim($class, '\\'); |
|
205 | - $registered = false; |
|
206 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
208 | - } |
|
209 | - // we need to make sure that any aliases used when registering a dependency |
|
210 | - // get resolved to the correct class name |
|
211 | - foreach ($dependencies as $dependency => $load_source) { |
|
212 | - $alias = self::$_instance->getFqnForAlias($dependency); |
|
213 | - if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
214 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
215 | - ) { |
|
216 | - unset($dependencies[ $dependency ]); |
|
217 | - $dependencies[ $alias ] = $load_source; |
|
218 | - $registered = true; |
|
219 | - } |
|
220 | - } |
|
221 | - // now add our two lists of dependencies together. |
|
222 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
223 | - // so $dependencies is NOT overwritten because it is listed first |
|
224 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
225 | - // Union is way faster than array_merge() but should be used with caution... |
|
226 | - // especially with numerically indexed arrays |
|
227 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
228 | - // now we need to ensure that the resulting dependencies |
|
229 | - // array only has the entries that are required for the class |
|
230 | - // so first count how many dependencies were originally registered for the class |
|
231 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
232 | - // if that count is non-zero (meaning dependencies were already registered) |
|
233 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
234 | - // then truncate the final array to match that count |
|
235 | - ? array_slice($dependencies, 0, $dependency_count) |
|
236 | - // otherwise just take the incoming array because nothing previously existed |
|
237 | - : $dependencies; |
|
238 | - return $registered; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * @param string $class_name |
|
244 | - * @param string $loader |
|
245 | - * @return bool |
|
246 | - * @throws DomainException |
|
247 | - */ |
|
248 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
249 | - { |
|
250 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | - throw new DomainException( |
|
252 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
253 | - ); |
|
254 | - } |
|
255 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
256 | - if (! is_callable($loader) |
|
257 | - && ( |
|
258 | - strpos($loader, 'load_') !== 0 |
|
259 | - || ! method_exists('EE_Registry', $loader) |
|
260 | - ) |
|
261 | - ) { |
|
262 | - throw new DomainException( |
|
263 | - sprintf( |
|
264 | - esc_html__( |
|
265 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
266 | - 'event_espresso' |
|
267 | - ), |
|
268 | - $loader |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - $class_name = self::$_instance->getFqnForAlias($class_name); |
|
273 | - if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | - self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
275 | - return true; |
|
276 | - } |
|
277 | - return false; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @return array |
|
283 | - */ |
|
284 | - public function dependency_map() |
|
285 | - { |
|
286 | - return $this->_dependency_map; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
292 | - * |
|
293 | - * @param string $class_name |
|
294 | - * @return boolean |
|
295 | - */ |
|
296 | - public function has($class_name = '') |
|
297 | - { |
|
298 | - // all legacy models have the same dependencies |
|
299 | - if (strpos($class_name, 'EEM_') === 0) { |
|
300 | - $class_name = 'LEGACY_MODELS'; |
|
301 | - } |
|
302 | - return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
308 | - * |
|
309 | - * @param string $class_name |
|
310 | - * @param string $dependency |
|
311 | - * @return bool |
|
312 | - */ |
|
313 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
314 | - { |
|
315 | - // all legacy models have the same dependencies |
|
316 | - if (strpos($class_name, 'EEM_') === 0) { |
|
317 | - $class_name = 'LEGACY_MODELS'; |
|
318 | - } |
|
319 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
320 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
321 | - ? true |
|
322 | - : false; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
328 | - * |
|
329 | - * @param string $class_name |
|
330 | - * @param string $dependency |
|
331 | - * @return int |
|
332 | - */ |
|
333 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
334 | - { |
|
335 | - // all legacy models have the same dependencies |
|
336 | - if (strpos($class_name, 'EEM_') === 0) { |
|
337 | - $class_name = 'LEGACY_MODELS'; |
|
338 | - } |
|
339 | - $dependency = $this->getFqnForAlias($dependency); |
|
340 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
341 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
342 | - : EE_Dependency_Map::not_registered; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @param string $class_name |
|
348 | - * @return string | Closure |
|
349 | - */ |
|
350 | - public function class_loader($class_name) |
|
351 | - { |
|
352 | - // all legacy models use load_model() |
|
353 | - if (strpos($class_name, 'EEM_') === 0) { |
|
354 | - return 'load_model'; |
|
355 | - } |
|
356 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
357 | - // perform strpos() first to avoid loading regex every time we load a class |
|
358 | - if (strpos($class_name, 'EE_CPT_') === 0 |
|
359 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
360 | - ) { |
|
361 | - return 'load_core'; |
|
362 | - } |
|
363 | - $class_name = $this->getFqnForAlias($class_name); |
|
364 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * @return array |
|
370 | - */ |
|
371 | - public function class_loaders() |
|
372 | - { |
|
373 | - return $this->_class_loaders; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * adds an alias for a classname |
|
379 | - * |
|
380 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
381 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
382 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
383 | - */ |
|
384 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
385 | - { |
|
386 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
392 | - * WHY? |
|
393 | - * Because if a class is type hinting for a concretion, |
|
394 | - * then why would we need to find another class to supply it? |
|
395 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
396 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
397 | - * Don't go looking for some substitute. |
|
398 | - * Whereas if a class is type hinting for an interface... |
|
399 | - * then we need to find an actual class to use. |
|
400 | - * So the interface IS the alias for some other FQN, |
|
401 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
402 | - * represents some other class. |
|
403 | - * |
|
404 | - * @param string $fqn |
|
405 | - * @param string $for_class |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - public function isAlias($fqn = '', $for_class = '') |
|
409 | - { |
|
410 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
416 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
417 | - * for example: |
|
418 | - * if the following two entries were added to the _aliases array: |
|
419 | - * array( |
|
420 | - * 'interface_alias' => 'some\namespace\interface' |
|
421 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
422 | - * ) |
|
423 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
424 | - * to load an instance of 'some\namespace\classname' |
|
425 | - * |
|
426 | - * @param string $alias |
|
427 | - * @param string $for_class |
|
428 | - * @return string |
|
429 | - */ |
|
430 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
431 | - { |
|
432 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
438 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
439 | - * This is done by using the following class constants: |
|
440 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
441 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
442 | - */ |
|
443 | - protected function _register_core_dependencies() |
|
444 | - { |
|
445 | - $this->_dependency_map = array( |
|
446 | - 'EE_Request_Handler' => array( |
|
447 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EE_System' => array( |
|
450 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
451 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
452 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
453 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
454 | - ), |
|
455 | - 'EE_Session' => array( |
|
456 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
457 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
458 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
460 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
461 | - ), |
|
462 | - 'EE_Cart' => array( |
|
463 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
464 | - ), |
|
465 | - 'EE_Front_Controller' => array( |
|
466 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
468 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
469 | - ), |
|
470 | - 'EE_Messenger_Collection_Loader' => array( |
|
471 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
472 | - ), |
|
473 | - 'EE_Message_Type_Collection_Loader' => array( |
|
474 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
475 | - ), |
|
476 | - 'EE_Message_Resource_Manager' => array( |
|
477 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
478 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
479 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
480 | - ), |
|
481 | - 'EE_Message_Factory' => array( |
|
482 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
483 | - ), |
|
484 | - 'EE_messages' => array( |
|
485 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | - ), |
|
487 | - 'EE_Messages_Generator' => array( |
|
488 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
489 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
491 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
492 | - ), |
|
493 | - 'EE_Messages_Processor' => array( |
|
494 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
495 | - ), |
|
496 | - 'EE_Messages_Queue' => array( |
|
497 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
498 | - ), |
|
499 | - 'EE_Messages_Template_Defaults' => array( |
|
500 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
501 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
502 | - ), |
|
503 | - 'EE_Message_To_Generate_From_Request' => array( |
|
504 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
505 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
506 | - ), |
|
507 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
508 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
509 | - ), |
|
510 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
511 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
512 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
513 | - ), |
|
514 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
515 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
516 | - ), |
|
517 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
518 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
519 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
520 | - ), |
|
521 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
522 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
523 | - ), |
|
524 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
525 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
526 | - ), |
|
527 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
528 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
529 | - ), |
|
530 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
531 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
532 | - ), |
|
533 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
534 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
535 | - ), |
|
536 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
537 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | - ), |
|
539 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
540 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
541 | - ), |
|
542 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
543 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
546 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
547 | - ), |
|
548 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
549 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
550 | - ), |
|
551 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
552 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
553 | - ), |
|
554 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
555 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
556 | - ), |
|
557 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
558 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
559 | - ), |
|
560 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
561 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
562 | - ), |
|
563 | - 'EE_Data_Migration_Class_Base' => array( |
|
564 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
566 | - ), |
|
567 | - 'EE_DMS_Core_4_1_0' => array( |
|
568 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
569 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
570 | - ), |
|
571 | - 'EE_DMS_Core_4_2_0' => array( |
|
572 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
573 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
574 | - ), |
|
575 | - 'EE_DMS_Core_4_3_0' => array( |
|
576 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
578 | - ), |
|
579 | - 'EE_DMS_Core_4_4_0' => array( |
|
580 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
581 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
582 | - ), |
|
583 | - 'EE_DMS_Core_4_5_0' => array( |
|
584 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
585 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
586 | - ), |
|
587 | - 'EE_DMS_Core_4_6_0' => array( |
|
588 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
589 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
590 | - ), |
|
591 | - 'EE_DMS_Core_4_7_0' => array( |
|
592 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
593 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
594 | - ), |
|
595 | - 'EE_DMS_Core_4_8_0' => array( |
|
596 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
597 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
598 | - ), |
|
599 | - 'EE_DMS_Core_4_9_0' => array( |
|
600 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
601 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
602 | - ), |
|
603 | - 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
604 | - array(), |
|
605 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
606 | - ), |
|
607 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
608 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
609 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
610 | - ), |
|
611 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
612 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
613 | - ), |
|
614 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
615 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
616 | - ), |
|
617 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
618 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
619 | - ), |
|
620 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
621 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
622 | - ), |
|
623 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
624 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
625 | - ), |
|
626 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
627 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
628 | - ), |
|
629 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
630 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
631 | - ), |
|
632 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
633 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
634 | - ), |
|
635 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
636 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
637 | - ), |
|
638 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
639 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
640 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
641 | - ), |
|
642 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
643 | - null, |
|
644 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
645 | - ), |
|
646 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
647 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
648 | - ), |
|
649 | - 'LEGACY_MODELS' => array( |
|
650 | - null, |
|
651 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
652 | - ), |
|
653 | - 'EE_Module_Request_Router' => array( |
|
654 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
655 | - ), |
|
656 | - 'EE_Registration_Processor' => array( |
|
657 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
658 | - ), |
|
659 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
660 | - null, |
|
661 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
662 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
663 | - ), |
|
664 | - 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
665 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
666 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
667 | - ), |
|
668 | - 'EE_Admin_Transactions_List_Table' => array( |
|
669 | - null, |
|
670 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
671 | - ), |
|
672 | - 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
673 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
674 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
675 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
676 | - ), |
|
677 | - 'EventEspresso\core\domain\services\pue\Config' => array( |
|
678 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
679 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
680 | - ), |
|
681 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
682 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
683 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
684 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
685 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
686 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
687 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
688 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
689 | - ), |
|
690 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
691 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
692 | - ), |
|
693 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
694 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
695 | - ), |
|
696 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
697 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
698 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
699 | - ), |
|
700 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
701 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
702 | - ), |
|
703 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
704 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
705 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
706 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
707 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
708 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
709 | - ), |
|
710 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
711 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
712 | - ), |
|
713 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
714 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
715 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
716 | - ), |
|
717 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
718 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
719 | - ), |
|
720 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
721 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
722 | - ), |
|
723 | - 'EE_CPT_Strategy' => array( |
|
724 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
725 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
726 | - ), |
|
727 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
728 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
729 | - ), |
|
730 | - 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
731 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
732 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
733 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
734 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
735 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
736 | - ), |
|
737 | - 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
738 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
739 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
740 | - ), |
|
741 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
742 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
743 | - ), |
|
744 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
745 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
746 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
747 | - ), |
|
748 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
749 | - 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
750 | - ), |
|
751 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
752 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
753 | - ), |
|
754 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
755 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
756 | - ), |
|
757 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
758 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
759 | - ), |
|
760 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
761 | - 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
762 | - 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
763 | - ), |
|
764 | - 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
765 | - null, |
|
766 | - null, |
|
767 | - null, |
|
768 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
769 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
770 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
771 | - ), |
|
772 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array( |
|
773 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
774 | - 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
775 | - ), |
|
776 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array( |
|
777 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
|
778 | - ), |
|
779 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array( |
|
780 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
781 | - ), |
|
782 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array( |
|
783 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache |
|
784 | - ), |
|
785 | - 'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array( |
|
786 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
787 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
788 | - ), |
|
789 | - 'EventEspresso\core\libraries\rest_api\calculations\Event' => array( |
|
790 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
791 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
792 | - ), |
|
793 | - 'EventEspresso\core\libraries\rest_api\calculations\Registration' => array( |
|
794 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
795 | - ), |
|
796 | - 'EventEspresso\core\services\session\SessionStartHandler' => array( |
|
797 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
798 | - ), |
|
799 | - 'EE_URL_Validation_Strategy' => array( |
|
800 | - null, |
|
801 | - null, |
|
802 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache |
|
803 | - ), |
|
804 | - ); |
|
805 | - } |
|
806 | - |
|
807 | - |
|
808 | - /** |
|
809 | - * Registers how core classes are loaded. |
|
810 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
811 | - * 'EE_Request_Handler' => 'load_core' |
|
812 | - * 'EE_Messages_Queue' => 'load_lib' |
|
813 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
814 | - * or, if greater control is required, by providing a custom closure. For example: |
|
815 | - * 'Some_Class' => function () { |
|
816 | - * return new Some_Class(); |
|
817 | - * }, |
|
818 | - * This is required for instantiating dependencies |
|
819 | - * where an interface has been type hinted in a class constructor. For example: |
|
820 | - * 'Required_Interface' => function () { |
|
821 | - * return new A_Class_That_Implements_Required_Interface(); |
|
822 | - * }, |
|
823 | - */ |
|
824 | - protected function _register_core_class_loaders() |
|
825 | - { |
|
826 | - // for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
827 | - // be used in a closure. |
|
828 | - $request = &$this->request; |
|
829 | - $response = &$this->response; |
|
830 | - $legacy_request = &$this->legacy_request; |
|
831 | - // $loader = &$this->loader; |
|
832 | - $this->_class_loaders = array( |
|
833 | - // load_core |
|
834 | - 'EE_Capabilities' => 'load_core', |
|
835 | - 'EE_Encryption' => 'load_core', |
|
836 | - 'EE_Front_Controller' => 'load_core', |
|
837 | - 'EE_Module_Request_Router' => 'load_core', |
|
838 | - 'EE_Registry' => 'load_core', |
|
839 | - 'EE_Request' => function () use (&$legacy_request) { |
|
840 | - return $legacy_request; |
|
841 | - }, |
|
842 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
843 | - return $request; |
|
844 | - }, |
|
845 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
846 | - return $response; |
|
847 | - }, |
|
848 | - 'EE_Base' => 'load_core', |
|
849 | - 'EE_Request_Handler' => 'load_core', |
|
850 | - 'EE_Session' => 'load_core', |
|
851 | - 'EE_Cron_Tasks' => 'load_core', |
|
852 | - 'EE_System' => 'load_core', |
|
853 | - 'EE_Maintenance_Mode' => 'load_core', |
|
854 | - 'EE_Register_CPTs' => 'load_core', |
|
855 | - 'EE_Admin' => 'load_core', |
|
856 | - 'EE_CPT_Strategy' => 'load_core', |
|
857 | - // load_lib |
|
858 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
859 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
860 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
861 | - 'EE_Messenger_Collection' => 'load_lib', |
|
862 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
863 | - 'EE_Messages_Processor' => 'load_lib', |
|
864 | - 'EE_Message_Repository' => 'load_lib', |
|
865 | - 'EE_Messages_Queue' => 'load_lib', |
|
866 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
867 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
868 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
869 | - 'EE_Messages_Generator' => function () { |
|
870 | - return EE_Registry::instance()->load_lib( |
|
871 | - 'Messages_Generator', |
|
872 | - array(), |
|
873 | - false, |
|
874 | - false |
|
875 | - ); |
|
876 | - }, |
|
877 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
878 | - return EE_Registry::instance()->load_lib( |
|
879 | - 'Messages_Template_Defaults', |
|
880 | - $arguments, |
|
881 | - false, |
|
882 | - false |
|
883 | - ); |
|
884 | - }, |
|
885 | - // load_helper |
|
886 | - 'EEH_Parse_Shortcodes' => function () { |
|
887 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
888 | - return new EEH_Parse_Shortcodes(); |
|
889 | - } |
|
890 | - return null; |
|
891 | - }, |
|
892 | - 'EE_Template_Config' => function () { |
|
893 | - return EE_Config::instance()->template_settings; |
|
894 | - }, |
|
895 | - 'EE_Currency_Config' => function () { |
|
896 | - return EE_Config::instance()->currency; |
|
897 | - }, |
|
898 | - 'EE_Registration_Config' => function () { |
|
899 | - return EE_Config::instance()->registration; |
|
900 | - }, |
|
901 | - 'EE_Core_Config' => function () { |
|
902 | - return EE_Config::instance()->core; |
|
903 | - }, |
|
904 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
905 | - return LoaderFactory::getLoader(); |
|
906 | - }, |
|
907 | - 'EE_Network_Config' => function () { |
|
908 | - return EE_Network_Config::instance(); |
|
909 | - }, |
|
910 | - 'EE_Config' => function () { |
|
911 | - return EE_Config::instance(); |
|
912 | - }, |
|
913 | - 'EventEspresso\core\domain\Domain' => function () { |
|
914 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
915 | - }, |
|
916 | - 'EE_Admin_Config' => function () { |
|
917 | - return EE_Config::instance()->admin; |
|
918 | - }, |
|
919 | - ); |
|
920 | - } |
|
921 | - |
|
922 | - |
|
923 | - /** |
|
924 | - * can be used for supplying alternate names for classes, |
|
925 | - * or for connecting interface names to instantiable classes |
|
926 | - */ |
|
927 | - protected function _register_core_aliases() |
|
928 | - { |
|
929 | - $aliases = array( |
|
930 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
931 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
932 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
933 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
934 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
935 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
936 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
937 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
938 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
939 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
940 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
941 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
942 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
943 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
944 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
945 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
946 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
947 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
948 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
949 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
950 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
951 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
952 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
953 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
954 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
955 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
956 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
957 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
958 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
959 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
960 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
961 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
962 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
963 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
964 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
965 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
966 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
967 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
968 | - ); |
|
969 | - foreach ($aliases as $alias => $fqn) { |
|
970 | - if (is_array($fqn)) { |
|
971 | - foreach ($fqn as $class => $for_class) { |
|
972 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
973 | - } |
|
974 | - continue; |
|
975 | - } |
|
976 | - $this->class_cache->addAlias($fqn, $alias); |
|
977 | - } |
|
978 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
979 | - $this->class_cache->addAlias( |
|
980 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
981 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
982 | - ); |
|
983 | - } |
|
984 | - } |
|
985 | - |
|
986 | - |
|
987 | - /** |
|
988 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
989 | - * request Primarily used by unit tests. |
|
990 | - */ |
|
991 | - public function reset() |
|
992 | - { |
|
993 | - $this->_register_core_class_loaders(); |
|
994 | - $this->_register_core_dependencies(); |
|
995 | - } |
|
996 | - |
|
997 | - |
|
998 | - /** |
|
999 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
1000 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
1001 | - * WHY? |
|
1002 | - * Because if a class is type hinting for a concretion, |
|
1003 | - * then why would we need to find another class to supply it? |
|
1004 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1005 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1006 | - * Don't go looking for some substitute. |
|
1007 | - * Whereas if a class is type hinting for an interface... |
|
1008 | - * then we need to find an actual class to use. |
|
1009 | - * So the interface IS the alias for some other FQN, |
|
1010 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1011 | - * represents some other class. |
|
1012 | - * |
|
1013 | - * @deprecated 4.9.62.p |
|
1014 | - * @param string $fqn |
|
1015 | - * @param string $for_class |
|
1016 | - * @return bool |
|
1017 | - */ |
|
1018 | - public function has_alias($fqn = '', $for_class = '') |
|
1019 | - { |
|
1020 | - return $this->isAlias($fqn, $for_class); |
|
1021 | - } |
|
1022 | - |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1026 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1027 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1028 | - * for example: |
|
1029 | - * if the following two entries were added to the _aliases array: |
|
1030 | - * array( |
|
1031 | - * 'interface_alias' => 'some\namespace\interface' |
|
1032 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
1033 | - * ) |
|
1034 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1035 | - * to load an instance of 'some\namespace\classname' |
|
1036 | - * |
|
1037 | - * @deprecated 4.9.62.p |
|
1038 | - * @param string $alias |
|
1039 | - * @param string $for_class |
|
1040 | - * @return string |
|
1041 | - */ |
|
1042 | - public function get_alias($alias = '', $for_class = '') |
|
1043 | - { |
|
1044 | - return $this->getFqnForAlias($alias, $for_class); |
|
1045 | - } |
|
23 | + /** |
|
24 | + * This means that the requested class dependency is not present in the dependency map |
|
25 | + */ |
|
26 | + const not_registered = 0; |
|
27 | + |
|
28 | + /** |
|
29 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
30 | + */ |
|
31 | + const load_new_object = 1; |
|
32 | + |
|
33 | + /** |
|
34 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
35 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
36 | + */ |
|
37 | + const load_from_cache = 2; |
|
38 | + |
|
39 | + /** |
|
40 | + * When registering a dependency, |
|
41 | + * this indicates to keep any existing dependencies that already exist, |
|
42 | + * and simply discard any new dependencies declared in the incoming data |
|
43 | + */ |
|
44 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
45 | + |
|
46 | + /** |
|
47 | + * When registering a dependency, |
|
48 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
49 | + */ |
|
50 | + const OVERWRITE_DEPENDENCIES = 1; |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @type EE_Dependency_Map $_instance |
|
55 | + */ |
|
56 | + protected static $_instance; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var ClassInterfaceCache $class_cache |
|
60 | + */ |
|
61 | + private $class_cache; |
|
62 | + |
|
63 | + /** |
|
64 | + * @type RequestInterface $request |
|
65 | + */ |
|
66 | + protected $request; |
|
67 | + |
|
68 | + /** |
|
69 | + * @type LegacyRequestInterface $legacy_request |
|
70 | + */ |
|
71 | + protected $legacy_request; |
|
72 | + |
|
73 | + /** |
|
74 | + * @type ResponseInterface $response |
|
75 | + */ |
|
76 | + protected $response; |
|
77 | + |
|
78 | + /** |
|
79 | + * @type LoaderInterface $loader |
|
80 | + */ |
|
81 | + protected $loader; |
|
82 | + |
|
83 | + /** |
|
84 | + * @type array $_dependency_map |
|
85 | + */ |
|
86 | + protected $_dependency_map = array(); |
|
87 | + |
|
88 | + /** |
|
89 | + * @type array $_class_loaders |
|
90 | + */ |
|
91 | + protected $_class_loaders = array(); |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * EE_Dependency_Map constructor. |
|
96 | + * |
|
97 | + * @param ClassInterfaceCache $class_cache |
|
98 | + */ |
|
99 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | + { |
|
101 | + $this->class_cache = $class_cache; |
|
102 | + do_action('EE_Dependency_Map____construct', $this); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return void |
|
108 | + */ |
|
109 | + public function initialize() |
|
110 | + { |
|
111 | + $this->_register_core_dependencies(); |
|
112 | + $this->_register_core_class_loaders(); |
|
113 | + $this->_register_core_aliases(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @singleton method used to instantiate class object |
|
119 | + * @param ClassInterfaceCache|null $class_cache |
|
120 | + * @return EE_Dependency_Map |
|
121 | + */ |
|
122 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
123 | + { |
|
124 | + // check if class object is instantiated, and instantiated properly |
|
125 | + if (! self::$_instance instanceof EE_Dependency_Map |
|
126 | + && $class_cache instanceof ClassInterfaceCache |
|
127 | + ) { |
|
128 | + self::$_instance = new EE_Dependency_Map($class_cache); |
|
129 | + } |
|
130 | + return self::$_instance; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param RequestInterface $request |
|
136 | + */ |
|
137 | + public function setRequest(RequestInterface $request) |
|
138 | + { |
|
139 | + $this->request = $request; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param LegacyRequestInterface $legacy_request |
|
145 | + */ |
|
146 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
147 | + { |
|
148 | + $this->legacy_request = $legacy_request; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @param ResponseInterface $response |
|
154 | + */ |
|
155 | + public function setResponse(ResponseInterface $response) |
|
156 | + { |
|
157 | + $this->response = $response; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param LoaderInterface $loader |
|
163 | + */ |
|
164 | + public function setLoader(LoaderInterface $loader) |
|
165 | + { |
|
166 | + $this->loader = $loader; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @param string $class |
|
172 | + * @param array $dependencies |
|
173 | + * @param int $overwrite |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public static function register_dependencies( |
|
177 | + $class, |
|
178 | + array $dependencies, |
|
179 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
180 | + ) { |
|
181 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
187 | + * to the class specified by the first parameter. |
|
188 | + * IMPORTANT !!! |
|
189 | + * The order of elements in the incoming $dependencies array MUST match |
|
190 | + * the order of the constructor parameters for the class in question. |
|
191 | + * This is especially important when overriding any existing dependencies that are registered. |
|
192 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
193 | + * |
|
194 | + * @param string $class |
|
195 | + * @param array $dependencies |
|
196 | + * @param int $overwrite |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function registerDependencies( |
|
200 | + $class, |
|
201 | + array $dependencies, |
|
202 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
203 | + ) { |
|
204 | + $class = trim($class, '\\'); |
|
205 | + $registered = false; |
|
206 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
208 | + } |
|
209 | + // we need to make sure that any aliases used when registering a dependency |
|
210 | + // get resolved to the correct class name |
|
211 | + foreach ($dependencies as $dependency => $load_source) { |
|
212 | + $alias = self::$_instance->getFqnForAlias($dependency); |
|
213 | + if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
214 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
215 | + ) { |
|
216 | + unset($dependencies[ $dependency ]); |
|
217 | + $dependencies[ $alias ] = $load_source; |
|
218 | + $registered = true; |
|
219 | + } |
|
220 | + } |
|
221 | + // now add our two lists of dependencies together. |
|
222 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
223 | + // so $dependencies is NOT overwritten because it is listed first |
|
224 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
225 | + // Union is way faster than array_merge() but should be used with caution... |
|
226 | + // especially with numerically indexed arrays |
|
227 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
228 | + // now we need to ensure that the resulting dependencies |
|
229 | + // array only has the entries that are required for the class |
|
230 | + // so first count how many dependencies were originally registered for the class |
|
231 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
232 | + // if that count is non-zero (meaning dependencies were already registered) |
|
233 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
234 | + // then truncate the final array to match that count |
|
235 | + ? array_slice($dependencies, 0, $dependency_count) |
|
236 | + // otherwise just take the incoming array because nothing previously existed |
|
237 | + : $dependencies; |
|
238 | + return $registered; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * @param string $class_name |
|
244 | + * @param string $loader |
|
245 | + * @return bool |
|
246 | + * @throws DomainException |
|
247 | + */ |
|
248 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
249 | + { |
|
250 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | + throw new DomainException( |
|
252 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
253 | + ); |
|
254 | + } |
|
255 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
256 | + if (! is_callable($loader) |
|
257 | + && ( |
|
258 | + strpos($loader, 'load_') !== 0 |
|
259 | + || ! method_exists('EE_Registry', $loader) |
|
260 | + ) |
|
261 | + ) { |
|
262 | + throw new DomainException( |
|
263 | + sprintf( |
|
264 | + esc_html__( |
|
265 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
266 | + 'event_espresso' |
|
267 | + ), |
|
268 | + $loader |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + $class_name = self::$_instance->getFqnForAlias($class_name); |
|
273 | + if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | + self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
275 | + return true; |
|
276 | + } |
|
277 | + return false; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @return array |
|
283 | + */ |
|
284 | + public function dependency_map() |
|
285 | + { |
|
286 | + return $this->_dependency_map; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
292 | + * |
|
293 | + * @param string $class_name |
|
294 | + * @return boolean |
|
295 | + */ |
|
296 | + public function has($class_name = '') |
|
297 | + { |
|
298 | + // all legacy models have the same dependencies |
|
299 | + if (strpos($class_name, 'EEM_') === 0) { |
|
300 | + $class_name = 'LEGACY_MODELS'; |
|
301 | + } |
|
302 | + return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
308 | + * |
|
309 | + * @param string $class_name |
|
310 | + * @param string $dependency |
|
311 | + * @return bool |
|
312 | + */ |
|
313 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
314 | + { |
|
315 | + // all legacy models have the same dependencies |
|
316 | + if (strpos($class_name, 'EEM_') === 0) { |
|
317 | + $class_name = 'LEGACY_MODELS'; |
|
318 | + } |
|
319 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
320 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
321 | + ? true |
|
322 | + : false; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
328 | + * |
|
329 | + * @param string $class_name |
|
330 | + * @param string $dependency |
|
331 | + * @return int |
|
332 | + */ |
|
333 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
334 | + { |
|
335 | + // all legacy models have the same dependencies |
|
336 | + if (strpos($class_name, 'EEM_') === 0) { |
|
337 | + $class_name = 'LEGACY_MODELS'; |
|
338 | + } |
|
339 | + $dependency = $this->getFqnForAlias($dependency); |
|
340 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
341 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
342 | + : EE_Dependency_Map::not_registered; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @param string $class_name |
|
348 | + * @return string | Closure |
|
349 | + */ |
|
350 | + public function class_loader($class_name) |
|
351 | + { |
|
352 | + // all legacy models use load_model() |
|
353 | + if (strpos($class_name, 'EEM_') === 0) { |
|
354 | + return 'load_model'; |
|
355 | + } |
|
356 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
357 | + // perform strpos() first to avoid loading regex every time we load a class |
|
358 | + if (strpos($class_name, 'EE_CPT_') === 0 |
|
359 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
360 | + ) { |
|
361 | + return 'load_core'; |
|
362 | + } |
|
363 | + $class_name = $this->getFqnForAlias($class_name); |
|
364 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * @return array |
|
370 | + */ |
|
371 | + public function class_loaders() |
|
372 | + { |
|
373 | + return $this->_class_loaders; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * adds an alias for a classname |
|
379 | + * |
|
380 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
381 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
382 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
383 | + */ |
|
384 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
385 | + { |
|
386 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
392 | + * WHY? |
|
393 | + * Because if a class is type hinting for a concretion, |
|
394 | + * then why would we need to find another class to supply it? |
|
395 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
396 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
397 | + * Don't go looking for some substitute. |
|
398 | + * Whereas if a class is type hinting for an interface... |
|
399 | + * then we need to find an actual class to use. |
|
400 | + * So the interface IS the alias for some other FQN, |
|
401 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
402 | + * represents some other class. |
|
403 | + * |
|
404 | + * @param string $fqn |
|
405 | + * @param string $for_class |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + public function isAlias($fqn = '', $for_class = '') |
|
409 | + { |
|
410 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
416 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
417 | + * for example: |
|
418 | + * if the following two entries were added to the _aliases array: |
|
419 | + * array( |
|
420 | + * 'interface_alias' => 'some\namespace\interface' |
|
421 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
422 | + * ) |
|
423 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
424 | + * to load an instance of 'some\namespace\classname' |
|
425 | + * |
|
426 | + * @param string $alias |
|
427 | + * @param string $for_class |
|
428 | + * @return string |
|
429 | + */ |
|
430 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
431 | + { |
|
432 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
438 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
439 | + * This is done by using the following class constants: |
|
440 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
441 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
442 | + */ |
|
443 | + protected function _register_core_dependencies() |
|
444 | + { |
|
445 | + $this->_dependency_map = array( |
|
446 | + 'EE_Request_Handler' => array( |
|
447 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EE_System' => array( |
|
450 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
451 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
452 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
453 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
454 | + ), |
|
455 | + 'EE_Session' => array( |
|
456 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
457 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
458 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
460 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
461 | + ), |
|
462 | + 'EE_Cart' => array( |
|
463 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
464 | + ), |
|
465 | + 'EE_Front_Controller' => array( |
|
466 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
468 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
469 | + ), |
|
470 | + 'EE_Messenger_Collection_Loader' => array( |
|
471 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
472 | + ), |
|
473 | + 'EE_Message_Type_Collection_Loader' => array( |
|
474 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
475 | + ), |
|
476 | + 'EE_Message_Resource_Manager' => array( |
|
477 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
478 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
479 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
480 | + ), |
|
481 | + 'EE_Message_Factory' => array( |
|
482 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
483 | + ), |
|
484 | + 'EE_messages' => array( |
|
485 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | + ), |
|
487 | + 'EE_Messages_Generator' => array( |
|
488 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
489 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
491 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
492 | + ), |
|
493 | + 'EE_Messages_Processor' => array( |
|
494 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
495 | + ), |
|
496 | + 'EE_Messages_Queue' => array( |
|
497 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
498 | + ), |
|
499 | + 'EE_Messages_Template_Defaults' => array( |
|
500 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
501 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
502 | + ), |
|
503 | + 'EE_Message_To_Generate_From_Request' => array( |
|
504 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
505 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
506 | + ), |
|
507 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
508 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
509 | + ), |
|
510 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
511 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
512 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
513 | + ), |
|
514 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
515 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
516 | + ), |
|
517 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
518 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
519 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
520 | + ), |
|
521 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
522 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
523 | + ), |
|
524 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
525 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
526 | + ), |
|
527 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
528 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
529 | + ), |
|
530 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
531 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
532 | + ), |
|
533 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
534 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
535 | + ), |
|
536 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
537 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | + ), |
|
539 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
540 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
541 | + ), |
|
542 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
543 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
546 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
547 | + ), |
|
548 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
549 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
550 | + ), |
|
551 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
552 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
553 | + ), |
|
554 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
555 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
556 | + ), |
|
557 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
558 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
559 | + ), |
|
560 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
561 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
562 | + ), |
|
563 | + 'EE_Data_Migration_Class_Base' => array( |
|
564 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
566 | + ), |
|
567 | + 'EE_DMS_Core_4_1_0' => array( |
|
568 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
569 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
570 | + ), |
|
571 | + 'EE_DMS_Core_4_2_0' => array( |
|
572 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
573 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
574 | + ), |
|
575 | + 'EE_DMS_Core_4_3_0' => array( |
|
576 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
578 | + ), |
|
579 | + 'EE_DMS_Core_4_4_0' => array( |
|
580 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
581 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
582 | + ), |
|
583 | + 'EE_DMS_Core_4_5_0' => array( |
|
584 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
585 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
586 | + ), |
|
587 | + 'EE_DMS_Core_4_6_0' => array( |
|
588 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
589 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
590 | + ), |
|
591 | + 'EE_DMS_Core_4_7_0' => array( |
|
592 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
593 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
594 | + ), |
|
595 | + 'EE_DMS_Core_4_8_0' => array( |
|
596 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
597 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
598 | + ), |
|
599 | + 'EE_DMS_Core_4_9_0' => array( |
|
600 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
601 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
602 | + ), |
|
603 | + 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
604 | + array(), |
|
605 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
606 | + ), |
|
607 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
608 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
609 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
610 | + ), |
|
611 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
612 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
613 | + ), |
|
614 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
615 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
616 | + ), |
|
617 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
618 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
619 | + ), |
|
620 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
621 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
622 | + ), |
|
623 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
624 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
625 | + ), |
|
626 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
627 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
628 | + ), |
|
629 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
630 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
631 | + ), |
|
632 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
633 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
634 | + ), |
|
635 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
636 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
637 | + ), |
|
638 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
639 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
640 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
641 | + ), |
|
642 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
643 | + null, |
|
644 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
645 | + ), |
|
646 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
647 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
648 | + ), |
|
649 | + 'LEGACY_MODELS' => array( |
|
650 | + null, |
|
651 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
652 | + ), |
|
653 | + 'EE_Module_Request_Router' => array( |
|
654 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
655 | + ), |
|
656 | + 'EE_Registration_Processor' => array( |
|
657 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
658 | + ), |
|
659 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
660 | + null, |
|
661 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
662 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
663 | + ), |
|
664 | + 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
665 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
666 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
667 | + ), |
|
668 | + 'EE_Admin_Transactions_List_Table' => array( |
|
669 | + null, |
|
670 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
671 | + ), |
|
672 | + 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
673 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
674 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
675 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
676 | + ), |
|
677 | + 'EventEspresso\core\domain\services\pue\Config' => array( |
|
678 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
679 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
680 | + ), |
|
681 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
682 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
683 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
684 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
685 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
686 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
687 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
688 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
689 | + ), |
|
690 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
691 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
692 | + ), |
|
693 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
694 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
695 | + ), |
|
696 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
697 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
698 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
699 | + ), |
|
700 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
701 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
702 | + ), |
|
703 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
704 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
705 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
706 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
707 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
708 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
709 | + ), |
|
710 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
711 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
712 | + ), |
|
713 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
714 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
715 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
716 | + ), |
|
717 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
718 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
719 | + ), |
|
720 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
721 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
722 | + ), |
|
723 | + 'EE_CPT_Strategy' => array( |
|
724 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
725 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
726 | + ), |
|
727 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
728 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
729 | + ), |
|
730 | + 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
731 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
732 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
733 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
734 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
735 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
736 | + ), |
|
737 | + 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
738 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
739 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
740 | + ), |
|
741 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
742 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
743 | + ), |
|
744 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
745 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
746 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
747 | + ), |
|
748 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
749 | + 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
750 | + ), |
|
751 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
752 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
753 | + ), |
|
754 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
755 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
756 | + ), |
|
757 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
758 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
759 | + ), |
|
760 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
761 | + 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
762 | + 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
763 | + ), |
|
764 | + 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
765 | + null, |
|
766 | + null, |
|
767 | + null, |
|
768 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
769 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
770 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
771 | + ), |
|
772 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array( |
|
773 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
774 | + 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
775 | + ), |
|
776 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array( |
|
777 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
|
778 | + ), |
|
779 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array( |
|
780 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
781 | + ), |
|
782 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array( |
|
783 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache |
|
784 | + ), |
|
785 | + 'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array( |
|
786 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
787 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
788 | + ), |
|
789 | + 'EventEspresso\core\libraries\rest_api\calculations\Event' => array( |
|
790 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
791 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
792 | + ), |
|
793 | + 'EventEspresso\core\libraries\rest_api\calculations\Registration' => array( |
|
794 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
795 | + ), |
|
796 | + 'EventEspresso\core\services\session\SessionStartHandler' => array( |
|
797 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
798 | + ), |
|
799 | + 'EE_URL_Validation_Strategy' => array( |
|
800 | + null, |
|
801 | + null, |
|
802 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache |
|
803 | + ), |
|
804 | + ); |
|
805 | + } |
|
806 | + |
|
807 | + |
|
808 | + /** |
|
809 | + * Registers how core classes are loaded. |
|
810 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
811 | + * 'EE_Request_Handler' => 'load_core' |
|
812 | + * 'EE_Messages_Queue' => 'load_lib' |
|
813 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
814 | + * or, if greater control is required, by providing a custom closure. For example: |
|
815 | + * 'Some_Class' => function () { |
|
816 | + * return new Some_Class(); |
|
817 | + * }, |
|
818 | + * This is required for instantiating dependencies |
|
819 | + * where an interface has been type hinted in a class constructor. For example: |
|
820 | + * 'Required_Interface' => function () { |
|
821 | + * return new A_Class_That_Implements_Required_Interface(); |
|
822 | + * }, |
|
823 | + */ |
|
824 | + protected function _register_core_class_loaders() |
|
825 | + { |
|
826 | + // for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
827 | + // be used in a closure. |
|
828 | + $request = &$this->request; |
|
829 | + $response = &$this->response; |
|
830 | + $legacy_request = &$this->legacy_request; |
|
831 | + // $loader = &$this->loader; |
|
832 | + $this->_class_loaders = array( |
|
833 | + // load_core |
|
834 | + 'EE_Capabilities' => 'load_core', |
|
835 | + 'EE_Encryption' => 'load_core', |
|
836 | + 'EE_Front_Controller' => 'load_core', |
|
837 | + 'EE_Module_Request_Router' => 'load_core', |
|
838 | + 'EE_Registry' => 'load_core', |
|
839 | + 'EE_Request' => function () use (&$legacy_request) { |
|
840 | + return $legacy_request; |
|
841 | + }, |
|
842 | + 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
843 | + return $request; |
|
844 | + }, |
|
845 | + 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
846 | + return $response; |
|
847 | + }, |
|
848 | + 'EE_Base' => 'load_core', |
|
849 | + 'EE_Request_Handler' => 'load_core', |
|
850 | + 'EE_Session' => 'load_core', |
|
851 | + 'EE_Cron_Tasks' => 'load_core', |
|
852 | + 'EE_System' => 'load_core', |
|
853 | + 'EE_Maintenance_Mode' => 'load_core', |
|
854 | + 'EE_Register_CPTs' => 'load_core', |
|
855 | + 'EE_Admin' => 'load_core', |
|
856 | + 'EE_CPT_Strategy' => 'load_core', |
|
857 | + // load_lib |
|
858 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
859 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
860 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
861 | + 'EE_Messenger_Collection' => 'load_lib', |
|
862 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
863 | + 'EE_Messages_Processor' => 'load_lib', |
|
864 | + 'EE_Message_Repository' => 'load_lib', |
|
865 | + 'EE_Messages_Queue' => 'load_lib', |
|
866 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
867 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
868 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
869 | + 'EE_Messages_Generator' => function () { |
|
870 | + return EE_Registry::instance()->load_lib( |
|
871 | + 'Messages_Generator', |
|
872 | + array(), |
|
873 | + false, |
|
874 | + false |
|
875 | + ); |
|
876 | + }, |
|
877 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
878 | + return EE_Registry::instance()->load_lib( |
|
879 | + 'Messages_Template_Defaults', |
|
880 | + $arguments, |
|
881 | + false, |
|
882 | + false |
|
883 | + ); |
|
884 | + }, |
|
885 | + // load_helper |
|
886 | + 'EEH_Parse_Shortcodes' => function () { |
|
887 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
888 | + return new EEH_Parse_Shortcodes(); |
|
889 | + } |
|
890 | + return null; |
|
891 | + }, |
|
892 | + 'EE_Template_Config' => function () { |
|
893 | + return EE_Config::instance()->template_settings; |
|
894 | + }, |
|
895 | + 'EE_Currency_Config' => function () { |
|
896 | + return EE_Config::instance()->currency; |
|
897 | + }, |
|
898 | + 'EE_Registration_Config' => function () { |
|
899 | + return EE_Config::instance()->registration; |
|
900 | + }, |
|
901 | + 'EE_Core_Config' => function () { |
|
902 | + return EE_Config::instance()->core; |
|
903 | + }, |
|
904 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
905 | + return LoaderFactory::getLoader(); |
|
906 | + }, |
|
907 | + 'EE_Network_Config' => function () { |
|
908 | + return EE_Network_Config::instance(); |
|
909 | + }, |
|
910 | + 'EE_Config' => function () { |
|
911 | + return EE_Config::instance(); |
|
912 | + }, |
|
913 | + 'EventEspresso\core\domain\Domain' => function () { |
|
914 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
915 | + }, |
|
916 | + 'EE_Admin_Config' => function () { |
|
917 | + return EE_Config::instance()->admin; |
|
918 | + }, |
|
919 | + ); |
|
920 | + } |
|
921 | + |
|
922 | + |
|
923 | + /** |
|
924 | + * can be used for supplying alternate names for classes, |
|
925 | + * or for connecting interface names to instantiable classes |
|
926 | + */ |
|
927 | + protected function _register_core_aliases() |
|
928 | + { |
|
929 | + $aliases = array( |
|
930 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
931 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
932 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
933 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
934 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
935 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
936 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
937 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
938 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
939 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
940 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
941 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
942 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
943 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
944 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
945 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
946 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
947 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
948 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
949 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
950 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
951 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
952 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
953 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
954 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
955 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
956 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
957 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
958 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
959 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
960 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
961 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
962 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
963 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
964 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
965 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
966 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
967 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
968 | + ); |
|
969 | + foreach ($aliases as $alias => $fqn) { |
|
970 | + if (is_array($fqn)) { |
|
971 | + foreach ($fqn as $class => $for_class) { |
|
972 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
973 | + } |
|
974 | + continue; |
|
975 | + } |
|
976 | + $this->class_cache->addAlias($fqn, $alias); |
|
977 | + } |
|
978 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
979 | + $this->class_cache->addAlias( |
|
980 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
981 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
982 | + ); |
|
983 | + } |
|
984 | + } |
|
985 | + |
|
986 | + |
|
987 | + /** |
|
988 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
989 | + * request Primarily used by unit tests. |
|
990 | + */ |
|
991 | + public function reset() |
|
992 | + { |
|
993 | + $this->_register_core_class_loaders(); |
|
994 | + $this->_register_core_dependencies(); |
|
995 | + } |
|
996 | + |
|
997 | + |
|
998 | + /** |
|
999 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
1000 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
1001 | + * WHY? |
|
1002 | + * Because if a class is type hinting for a concretion, |
|
1003 | + * then why would we need to find another class to supply it? |
|
1004 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1005 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1006 | + * Don't go looking for some substitute. |
|
1007 | + * Whereas if a class is type hinting for an interface... |
|
1008 | + * then we need to find an actual class to use. |
|
1009 | + * So the interface IS the alias for some other FQN, |
|
1010 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1011 | + * represents some other class. |
|
1012 | + * |
|
1013 | + * @deprecated 4.9.62.p |
|
1014 | + * @param string $fqn |
|
1015 | + * @param string $for_class |
|
1016 | + * @return bool |
|
1017 | + */ |
|
1018 | + public function has_alias($fqn = '', $for_class = '') |
|
1019 | + { |
|
1020 | + return $this->isAlias($fqn, $for_class); |
|
1021 | + } |
|
1022 | + |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1026 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1027 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1028 | + * for example: |
|
1029 | + * if the following two entries were added to the _aliases array: |
|
1030 | + * array( |
|
1031 | + * 'interface_alias' => 'some\namespace\interface' |
|
1032 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
1033 | + * ) |
|
1034 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1035 | + * to load an instance of 'some\namespace\classname' |
|
1036 | + * |
|
1037 | + * @deprecated 4.9.62.p |
|
1038 | + * @param string $alias |
|
1039 | + * @param string $for_class |
|
1040 | + * @return string |
|
1041 | + */ |
|
1042 | + public function get_alias($alias = '', $for_class = '') |
|
1043 | + { |
|
1044 | + return $this->getFqnForAlias($alias, $for_class); |
|
1045 | + } |
|
1046 | 1046 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | * @param EE_Line_Item $line_item |
74 | 74 | * @param array $options |
75 | 75 | * @param EE_Line_Item $parent_line_item |
76 | - * @return mixed |
|
76 | + * @return string |
|
77 | 77 | * @throws EE_Error |
78 | 78 | */ |
79 | 79 | public function display_line_item( |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | * _event_row - basically a Heading row displayed once above each event's ticket rows |
217 | 217 | * |
218 | 218 | * @param EE_Line_Item $line_item |
219 | - * @return mixed |
|
219 | + * @return string |
|
220 | 220 | */ |
221 | 221 | private function _event_row(EE_Line_Item $line_item) |
222 | 222 | { |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * |
243 | 243 | * @param EE_Line_Item $line_item |
244 | 244 | * @param array $options |
245 | - * @return mixed |
|
245 | + * @return string |
|
246 | 246 | * @throws EE_Error |
247 | 247 | */ |
248 | 248 | private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * |
300 | 300 | * @param EE_Line_Item $line_item |
301 | 301 | * @param array $options |
302 | - * @return mixed |
|
302 | + * @return string |
|
303 | 303 | * @throws EE_Error |
304 | 304 | */ |
305 | 305 | private function _item_row(EE_Line_Item $line_item, $options = array()) |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | * |
423 | 423 | * @param EE_Line_Item $line_item |
424 | 424 | * @param array $options |
425 | - * @return mixed |
|
425 | + * @return string |
|
426 | 426 | * @throws EE_Error |
427 | 427 | */ |
428 | 428 | private function _tax_row(EE_Line_Item $line_item, $options = array()) |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | * |
467 | 467 | * @param EE_Line_Item $line_item |
468 | 468 | * @param string $text |
469 | - * @return mixed |
|
469 | + * @return string |
|
470 | 470 | * @throws EE_Error |
471 | 471 | */ |
472 | 472 | private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | * @param EE_Line_Item $line_item |
506 | 506 | * @param string $text |
507 | 507 | * @param array $options |
508 | - * @return mixed |
|
508 | + * @return string |
|
509 | 509 | * @throws EE_Error |
510 | 510 | */ |
511 | 511 | private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | * |
542 | 542 | * @param EE_Line_Item $line_item |
543 | 543 | * @param string $text |
544 | - * @return mixed |
|
544 | + * @return string |
|
545 | 545 | * @throws EE_Error |
546 | 546 | */ |
547 | 547 | private function _total_row(EE_Line_Item $line_item, $text = '') |
@@ -568,7 +568,7 @@ discard block |
||
568 | 568 | * |
569 | 569 | * @param EE_Line_Item $line_item |
570 | 570 | * @param array $options |
571 | - * @return mixed |
|
571 | + * @return string |
|
572 | 572 | * @throws EE_Error |
573 | 573 | */ |
574 | 574 | private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
@@ -12,636 +12,636 @@ |
||
12 | 12 | class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * array of events |
|
17 | - * |
|
18 | - * @type EE_Line_Item[] $_events |
|
19 | - */ |
|
20 | - private $_events = array(); |
|
21 | - |
|
22 | - /** |
|
23 | - * whether to display the taxes row or not |
|
24 | - * |
|
25 | - * @type bool $_show_taxes |
|
26 | - */ |
|
27 | - private $_show_taxes = false; |
|
28 | - |
|
29 | - /** |
|
30 | - * html for any tax rows |
|
31 | - * |
|
32 | - * @type string $_show_taxes |
|
33 | - */ |
|
34 | - private $_taxes_html = ''; |
|
35 | - |
|
36 | - /** |
|
37 | - * total amount including tax we can bill for at this time |
|
38 | - * |
|
39 | - * @type float $_grand_total |
|
40 | - */ |
|
41 | - private $_grand_total = 0.00; |
|
42 | - |
|
43 | - /** |
|
44 | - * total number of items being billed for |
|
45 | - * |
|
46 | - * @type int $_total_items |
|
47 | - */ |
|
48 | - private $_total_items = 0; |
|
49 | - |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @return float |
|
54 | - */ |
|
55 | - public function grand_total() |
|
56 | - { |
|
57 | - return $this->_grand_total; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @return int |
|
64 | - */ |
|
65 | - public function total_items() |
|
66 | - { |
|
67 | - return $this->_total_items; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * @param EE_Line_Item $line_item |
|
74 | - * @param array $options |
|
75 | - * @param EE_Line_Item $parent_line_item |
|
76 | - * @return mixed |
|
77 | - * @throws EE_Error |
|
78 | - */ |
|
79 | - public function display_line_item( |
|
80 | - EE_Line_Item $line_item, |
|
81 | - $options = array(), |
|
82 | - EE_Line_Item $parent_line_item = null |
|
83 | - ) { |
|
84 | - $html = ''; |
|
85 | - // set some default options and merge with incoming |
|
86 | - $default_options = array( |
|
87 | - 'show_desc' => true, // true false |
|
88 | - 'odd' => false, |
|
89 | - ); |
|
90 | - $options = array_merge($default_options, (array) $options); |
|
91 | - switch ($line_item->type()) { |
|
92 | - case EEM_Line_Item::type_line_item: |
|
93 | - $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
94 | - if ($line_item->OBJ_type() === 'Ticket') { |
|
95 | - // item row |
|
96 | - $html .= $this->_ticket_row($line_item, $options); |
|
97 | - } else { |
|
98 | - // item row |
|
99 | - $html .= $this->_item_row($line_item, $options); |
|
100 | - } |
|
101 | - if (apply_filters( |
|
102 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
103 | - true |
|
104 | - ) |
|
105 | - ) { |
|
106 | - // got any kids? |
|
107 | - foreach ($line_item->children() as $child_line_item) { |
|
108 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
109 | - } |
|
110 | - } |
|
111 | - break; |
|
112 | - case EEM_Line_Item::type_sub_line_item: |
|
113 | - $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
114 | - break; |
|
115 | - case EEM_Line_Item::type_sub_total: |
|
116 | - static $sub_total = 0; |
|
117 | - $event_sub_total = 0; |
|
118 | - $text = esc_html__('Sub-Total', 'event_espresso'); |
|
119 | - if ($line_item->OBJ_type() === 'Event') { |
|
120 | - $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
121 | - if (! isset($this->_events[ $options['event_id'] ])) { |
|
122 | - $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
123 | - // if event has default reg status of Not Approved, then don't display info on it |
|
124 | - if ($event instanceof EE_Event |
|
125 | - && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
126 | - ) { |
|
127 | - $display_event = false; |
|
128 | - // unless there are registrations for it that are returning to pay |
|
129 | - if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
130 | - foreach ($options['registrations'] as $registration) { |
|
131 | - if (! $registration instanceof EE_Registration) { |
|
132 | - continue; |
|
133 | - } |
|
134 | - $display_event = $registration->event_ID() === $options['event_id'] |
|
135 | - && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
136 | - ? true |
|
137 | - : $display_event; |
|
138 | - } |
|
139 | - } |
|
140 | - if (! $display_event) { |
|
141 | - return ''; |
|
142 | - } |
|
143 | - } |
|
144 | - $this->_events[ $options['event_id'] ] = 0; |
|
145 | - $html .= $this->_event_row($line_item); |
|
146 | - $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
147 | - } |
|
148 | - } |
|
149 | - $child_line_items = $line_item->children(); |
|
150 | - // loop thru children |
|
151 | - foreach ($child_line_items as $child_line_item) { |
|
152 | - // recursively feed children back into this method |
|
153 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
154 | - } |
|
155 | - $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
156 | - $sub_total += $event_sub_total; |
|
157 | - if (( |
|
158 | - // event subtotals |
|
159 | - $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
160 | - ) |
|
161 | - || ( |
|
162 | - // pre-tax subtotals |
|
163 | - $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
164 | - ) |
|
165 | - ) { |
|
166 | - $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
167 | - $html .= $this->_sub_total_row($line_item, $text, $options); |
|
168 | - } |
|
169 | - break; |
|
170 | - case EEM_Line_Item::type_tax: |
|
171 | - if ($this->_show_taxes) { |
|
172 | - $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
173 | - } |
|
174 | - break; |
|
175 | - case EEM_Line_Item::type_tax_sub_total: |
|
176 | - if ($this->_show_taxes) { |
|
177 | - $child_line_items = $line_item->children(); |
|
178 | - // loop thru children |
|
179 | - foreach ($child_line_items as $child_line_item) { |
|
180 | - // recursively feed children back into this method |
|
181 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
182 | - } |
|
183 | - if (count($child_line_items) > 1) { |
|
184 | - $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
185 | - } |
|
186 | - } |
|
187 | - break; |
|
188 | - case EEM_Line_Item::type_total: |
|
189 | - // get all child line items |
|
190 | - $children = $line_item->children(); |
|
191 | - // loop thru all non-tax child line items |
|
192 | - foreach ($children as $child_line_item) { |
|
193 | - if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
194 | - // recursively feed children back into this method |
|
195 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
196 | - } |
|
197 | - } |
|
198 | - // now loop thru tax child line items |
|
199 | - foreach ($children as $child_line_item) { |
|
200 | - if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
201 | - // recursively feed children back into this method |
|
202 | - $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
203 | - } |
|
204 | - } |
|
205 | - $html .= $this->_taxes_html; |
|
206 | - $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
207 | - $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
208 | - break; |
|
209 | - } |
|
210 | - return $html; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
217 | - * |
|
218 | - * @param EE_Line_Item $line_item |
|
219 | - * @return mixed |
|
220 | - */ |
|
221 | - private function _event_row(EE_Line_Item $line_item) |
|
222 | - { |
|
223 | - // start of row |
|
224 | - $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
225 | - // event name td |
|
226 | - $html .= EEH_HTML::td( |
|
227 | - EEH_HTML::strong($line_item->name()), |
|
228 | - '', |
|
229 | - 'event-header', |
|
230 | - '', |
|
231 | - ' colspan="4"' |
|
232 | - ); |
|
233 | - // end of row |
|
234 | - $html .= EEH_HTML::trx(); |
|
235 | - return $html; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * _ticket_row |
|
242 | - * |
|
243 | - * @param EE_Line_Item $line_item |
|
244 | - * @param array $options |
|
245 | - * @return mixed |
|
246 | - * @throws EE_Error |
|
247 | - */ |
|
248 | - private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
249 | - { |
|
250 | - // start of row |
|
251 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
252 | - $html = EEH_HTML::tr('', '', $row_class); |
|
253 | - // name && desc |
|
254 | - $name_and_desc = apply_filters( |
|
255 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
256 | - $line_item->name(), |
|
257 | - $line_item |
|
258 | - ); |
|
259 | - $name_and_desc .= apply_filters( |
|
260 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
261 | - ( |
|
262 | - $options['show_desc'] |
|
263 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
264 | - : '' |
|
265 | - ), |
|
266 | - $line_item, |
|
267 | - $options |
|
268 | - ); |
|
269 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
270 | - // name td |
|
271 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
272 | - $name_and_desc, |
|
273 | - '', |
|
274 | - 'item_l' |
|
275 | - ); |
|
276 | - // price td |
|
277 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
278 | - // quantity td |
|
279 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
280 | - $this->_total_items += $line_item->quantity(); |
|
281 | - // determine total for line item |
|
282 | - $total = $line_item->total(); |
|
283 | - $this->_events[ $options['event_id'] ] += $total; |
|
284 | - // total td |
|
285 | - $html .= EEH_HTML::td( |
|
286 | - EEH_Template::format_currency($total, false, false), |
|
287 | - '', |
|
288 | - 'item_r jst-rght' |
|
289 | - ); |
|
290 | - // end of row |
|
291 | - $html .= EEH_HTML::trx(); |
|
292 | - return $html; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * _item_row |
|
299 | - * |
|
300 | - * @param EE_Line_Item $line_item |
|
301 | - * @param array $options |
|
302 | - * @return mixed |
|
303 | - * @throws EE_Error |
|
304 | - */ |
|
305 | - private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
306 | - { |
|
307 | - // start of row |
|
308 | - $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
309 | - $html = EEH_HTML::tr('', '', $row_class); |
|
310 | - $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
311 | - // name && desc |
|
312 | - $name_and_desc = apply_filters( |
|
313 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
314 | - $obj_name . $line_item->name(), |
|
315 | - $line_item |
|
316 | - ); |
|
317 | - $name_and_desc .= apply_filters( |
|
318 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
319 | - ( |
|
320 | - $options['show_desc'] |
|
321 | - ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
322 | - : '' |
|
323 | - ), |
|
324 | - $line_item, |
|
325 | - $options |
|
326 | - ); |
|
327 | - $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
328 | - // name td |
|
329 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
330 | - // price td |
|
331 | - if ($line_item->is_percent()) { |
|
332 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
333 | - } else { |
|
334 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
335 | - } |
|
336 | - // quantity td |
|
337 | - $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
338 | - // $total = $line_item->total() * $line_item->quantity(); |
|
339 | - $total = $line_item->total(); |
|
340 | - if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
341 | - $this->_events[ $options['event_id'] ] += $total; |
|
342 | - } |
|
343 | - // total td |
|
344 | - $html .= EEH_HTML::td( |
|
345 | - EEH_Template::format_currency($total, false, false), |
|
346 | - '', |
|
347 | - 'item_r jst-rght' |
|
348 | - ); |
|
349 | - // end of row |
|
350 | - $html .= EEH_HTML::trx(); |
|
351 | - return $html; |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * _sub_item_row |
|
358 | - * |
|
359 | - * @param EE_Line_Item $line_item |
|
360 | - * @param array $options |
|
361 | - * @param EE_Line_Item $parent_line_item |
|
362 | - * @return mixed |
|
363 | - * @throws EE_Error |
|
364 | - */ |
|
365 | - private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
366 | - { |
|
367 | - if ($parent_line_item instanceof EE_Line_Item |
|
368 | - && $line_item->children() === array() |
|
369 | - && $line_item->name() === $parent_line_item->name() |
|
370 | - && apply_filters( |
|
371 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item', |
|
372 | - true |
|
373 | - ) |
|
374 | - ) { |
|
375 | - return ''; |
|
376 | - } |
|
377 | - // start of row |
|
378 | - $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
379 | - // name && desc |
|
380 | - $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
381 | - . $line_item->name(); |
|
382 | - $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
383 | - . $line_item->desc() |
|
384 | - . '</span>' : ''; |
|
385 | - // name td |
|
386 | - $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
387 | - $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
388 | - // discount/surcharge td |
|
389 | - if ($line_item->is_percent()) { |
|
390 | - $html .= EEH_HTML::td( |
|
391 | - EEH_Template::format_currency( |
|
392 | - $line_item->total() / $qty, |
|
393 | - false, |
|
394 | - false |
|
395 | - ), |
|
396 | - '', |
|
397 | - 'item_c jst-rght' |
|
398 | - ); |
|
399 | - } else { |
|
400 | - $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
401 | - } |
|
402 | - // no quantity td |
|
403 | - $html .= EEH_HTML::td(); |
|
404 | - // no total td |
|
405 | - $html .= EEH_HTML::td(); |
|
406 | - // end of row |
|
407 | - $html .= EEH_HTML::trx(); |
|
408 | - $html = apply_filters( |
|
409 | - 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html', |
|
410 | - $html, |
|
411 | - $line_item, |
|
412 | - $options, |
|
413 | - $parent_line_item |
|
414 | - ); |
|
415 | - return $html; |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * _tax_row |
|
422 | - * |
|
423 | - * @param EE_Line_Item $line_item |
|
424 | - * @param array $options |
|
425 | - * @return mixed |
|
426 | - * @throws EE_Error |
|
427 | - */ |
|
428 | - private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
429 | - { |
|
430 | - // start of row |
|
431 | - $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
432 | - // name && desc |
|
433 | - $name_and_desc = $line_item->name(); |
|
434 | - $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
435 | - . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
436 | - $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
437 | - // name td |
|
438 | - $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
439 | - $name_and_desc, |
|
440 | - '', |
|
441 | - 'item_l sub-item' |
|
442 | - ); |
|
443 | - // percent td |
|
444 | - $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
445 | - // empty td (price) |
|
446 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
447 | - // total td |
|
448 | - $html .= EEH_HTML::td( |
|
449 | - EEH_Template::format_currency( |
|
450 | - $line_item->total(), |
|
451 | - false, |
|
452 | - false |
|
453 | - ), |
|
454 | - '', |
|
455 | - 'item_r jst-rght' |
|
456 | - ); |
|
457 | - // end of row |
|
458 | - $html .= EEH_HTML::trx(); |
|
459 | - return $html; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * _total_row |
|
466 | - * |
|
467 | - * @param EE_Line_Item $line_item |
|
468 | - * @param string $text |
|
469 | - * @return mixed |
|
470 | - * @throws EE_Error |
|
471 | - */ |
|
472 | - private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
473 | - { |
|
474 | - $html = ''; |
|
475 | - if ($line_item->total()) { |
|
476 | - // start of row |
|
477 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
478 | - // total td |
|
479 | - $html .= EEH_HTML::td( |
|
480 | - $text, |
|
481 | - '', |
|
482 | - 'total_currency total jst-rght', |
|
483 | - '', |
|
484 | - ' colspan="2"' |
|
485 | - ); |
|
486 | - // empty td (price) |
|
487 | - $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
488 | - // total td |
|
489 | - $html .= EEH_HTML::td( |
|
490 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
491 | - '', |
|
492 | - 'total jst-rght' |
|
493 | - ); |
|
494 | - // end of row |
|
495 | - $html .= EEH_HTML::trx(); |
|
496 | - } |
|
497 | - return $html; |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * _total_row |
|
504 | - * |
|
505 | - * @param EE_Line_Item $line_item |
|
506 | - * @param string $text |
|
507 | - * @param array $options |
|
508 | - * @return mixed |
|
509 | - * @throws EE_Error |
|
510 | - */ |
|
511 | - private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
512 | - { |
|
513 | - $html = ''; |
|
514 | - if ($line_item->total()) { |
|
515 | - // start of row |
|
516 | - $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
517 | - // total td |
|
518 | - $html .= EEH_HTML::td( |
|
519 | - $text, |
|
520 | - '', |
|
521 | - 'total_currency total jst-rght', |
|
522 | - '', |
|
523 | - ' colspan="3"' |
|
524 | - ); |
|
525 | - // total td |
|
526 | - $html .= EEH_HTML::td( |
|
527 | - EEH_Template::format_currency($options['sub_total'], false, false), |
|
528 | - '', |
|
529 | - 'total jst-rght' |
|
530 | - ); |
|
531 | - // end of row |
|
532 | - $html .= EEH_HTML::trx(); |
|
533 | - } |
|
534 | - return $html; |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * _total_row |
|
541 | - * |
|
542 | - * @param EE_Line_Item $line_item |
|
543 | - * @param string $text |
|
544 | - * @return mixed |
|
545 | - * @throws EE_Error |
|
546 | - */ |
|
547 | - private function _total_row(EE_Line_Item $line_item, $text = '') |
|
548 | - { |
|
549 | - // start of row |
|
550 | - $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
551 | - // total td |
|
552 | - $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
553 | - // total td |
|
554 | - $html .= EEH_HTML::td( |
|
555 | - EEH_Template::format_currency($line_item->total(), false, false), |
|
556 | - '', |
|
557 | - 'total jst-rght' |
|
558 | - ); |
|
559 | - // end of row |
|
560 | - $html .= EEH_HTML::trx(); |
|
561 | - return $html; |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * _payments_and_amount_owing_rows |
|
568 | - * |
|
569 | - * @param EE_Line_Item $line_item |
|
570 | - * @param array $options |
|
571 | - * @return mixed |
|
572 | - * @throws EE_Error |
|
573 | - */ |
|
574 | - private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
575 | - { |
|
576 | - $html = ''; |
|
577 | - $owing = $line_item->total(); |
|
578 | - $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
579 | - if ($transaction instanceof EE_Transaction) { |
|
580 | - $registration_payments = array(); |
|
581 | - $registrations = ! empty($options['registrations']) |
|
582 | - ? $options['registrations'] |
|
583 | - : $transaction->registrations(); |
|
584 | - foreach ($registrations as $registration) { |
|
585 | - if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
586 | - $registration_payments += $registration->registration_payments(); |
|
587 | - } |
|
588 | - } |
|
589 | - if (! empty($registration_payments)) { |
|
590 | - foreach ($registration_payments as $registration_payment) { |
|
591 | - if ($registration_payment instanceof EE_Registration_Payment) { |
|
592 | - $owing -= $registration_payment->amount(); |
|
593 | - $payment = $registration_payment->payment(); |
|
594 | - $payment_desc = ''; |
|
595 | - if ($payment instanceof EE_Payment) { |
|
596 | - $payment_desc = sprintf( |
|
597 | - esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
598 | - $payment->txn_id_chq_nmbr() !== '' |
|
599 | - ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
600 | - : '', |
|
601 | - $payment->timestamp() |
|
602 | - ); |
|
603 | - } |
|
604 | - // start of row |
|
605 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
606 | - // payment desc |
|
607 | - $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
608 | - // total td |
|
609 | - $html .= EEH_HTML::td( |
|
610 | - EEH_Template::format_currency( |
|
611 | - $registration_payment->amount(), |
|
612 | - false, |
|
613 | - false |
|
614 | - ), |
|
615 | - '', |
|
616 | - 'total jst-rght' |
|
617 | - ); |
|
618 | - // end of row |
|
619 | - $html .= EEH_HTML::trx(); |
|
620 | - } |
|
621 | - } |
|
622 | - if ($line_item->total()) { |
|
623 | - // start of row |
|
624 | - $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
625 | - // total td |
|
626 | - $html .= EEH_HTML::td( |
|
627 | - esc_html__('Amount Owing', 'event_espresso'), |
|
628 | - '', |
|
629 | - 'total_currency total jst-rght', |
|
630 | - '', |
|
631 | - ' colspan="3"' |
|
632 | - ); |
|
633 | - // total td |
|
634 | - $html .= EEH_HTML::td( |
|
635 | - EEH_Template::format_currency($owing, false, false), |
|
636 | - '', |
|
637 | - 'total jst-rght' |
|
638 | - ); |
|
639 | - // end of row |
|
640 | - $html .= EEH_HTML::trx(); |
|
641 | - } |
|
642 | - } |
|
643 | - } |
|
644 | - $this->_grand_total = $owing; |
|
645 | - return $html; |
|
646 | - } |
|
15 | + /** |
|
16 | + * array of events |
|
17 | + * |
|
18 | + * @type EE_Line_Item[] $_events |
|
19 | + */ |
|
20 | + private $_events = array(); |
|
21 | + |
|
22 | + /** |
|
23 | + * whether to display the taxes row or not |
|
24 | + * |
|
25 | + * @type bool $_show_taxes |
|
26 | + */ |
|
27 | + private $_show_taxes = false; |
|
28 | + |
|
29 | + /** |
|
30 | + * html for any tax rows |
|
31 | + * |
|
32 | + * @type string $_show_taxes |
|
33 | + */ |
|
34 | + private $_taxes_html = ''; |
|
35 | + |
|
36 | + /** |
|
37 | + * total amount including tax we can bill for at this time |
|
38 | + * |
|
39 | + * @type float $_grand_total |
|
40 | + */ |
|
41 | + private $_grand_total = 0.00; |
|
42 | + |
|
43 | + /** |
|
44 | + * total number of items being billed for |
|
45 | + * |
|
46 | + * @type int $_total_items |
|
47 | + */ |
|
48 | + private $_total_items = 0; |
|
49 | + |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @return float |
|
54 | + */ |
|
55 | + public function grand_total() |
|
56 | + { |
|
57 | + return $this->_grand_total; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @return int |
|
64 | + */ |
|
65 | + public function total_items() |
|
66 | + { |
|
67 | + return $this->_total_items; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * @param EE_Line_Item $line_item |
|
74 | + * @param array $options |
|
75 | + * @param EE_Line_Item $parent_line_item |
|
76 | + * @return mixed |
|
77 | + * @throws EE_Error |
|
78 | + */ |
|
79 | + public function display_line_item( |
|
80 | + EE_Line_Item $line_item, |
|
81 | + $options = array(), |
|
82 | + EE_Line_Item $parent_line_item = null |
|
83 | + ) { |
|
84 | + $html = ''; |
|
85 | + // set some default options and merge with incoming |
|
86 | + $default_options = array( |
|
87 | + 'show_desc' => true, // true false |
|
88 | + 'odd' => false, |
|
89 | + ); |
|
90 | + $options = array_merge($default_options, (array) $options); |
|
91 | + switch ($line_item->type()) { |
|
92 | + case EEM_Line_Item::type_line_item: |
|
93 | + $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes; |
|
94 | + if ($line_item->OBJ_type() === 'Ticket') { |
|
95 | + // item row |
|
96 | + $html .= $this->_ticket_row($line_item, $options); |
|
97 | + } else { |
|
98 | + // item row |
|
99 | + $html .= $this->_item_row($line_item, $options); |
|
100 | + } |
|
101 | + if (apply_filters( |
|
102 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items', |
|
103 | + true |
|
104 | + ) |
|
105 | + ) { |
|
106 | + // got any kids? |
|
107 | + foreach ($line_item->children() as $child_line_item) { |
|
108 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
109 | + } |
|
110 | + } |
|
111 | + break; |
|
112 | + case EEM_Line_Item::type_sub_line_item: |
|
113 | + $html .= $this->_sub_item_row($line_item, $options, $parent_line_item); |
|
114 | + break; |
|
115 | + case EEM_Line_Item::type_sub_total: |
|
116 | + static $sub_total = 0; |
|
117 | + $event_sub_total = 0; |
|
118 | + $text = esc_html__('Sub-Total', 'event_espresso'); |
|
119 | + if ($line_item->OBJ_type() === 'Event') { |
|
120 | + $options['event_id'] = $event_id = $line_item->OBJ_ID(); |
|
121 | + if (! isset($this->_events[ $options['event_id'] ])) { |
|
122 | + $event = EEM_Event::instance()->get_one_by_ID($options['event_id']); |
|
123 | + // if event has default reg status of Not Approved, then don't display info on it |
|
124 | + if ($event instanceof EE_Event |
|
125 | + && $event->default_registration_status() === EEM_Registration::status_id_not_approved |
|
126 | + ) { |
|
127 | + $display_event = false; |
|
128 | + // unless there are registrations for it that are returning to pay |
|
129 | + if (isset($options['registrations']) && is_array($options['registrations'])) { |
|
130 | + foreach ($options['registrations'] as $registration) { |
|
131 | + if (! $registration instanceof EE_Registration) { |
|
132 | + continue; |
|
133 | + } |
|
134 | + $display_event = $registration->event_ID() === $options['event_id'] |
|
135 | + && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
|
136 | + ? true |
|
137 | + : $display_event; |
|
138 | + } |
|
139 | + } |
|
140 | + if (! $display_event) { |
|
141 | + return ''; |
|
142 | + } |
|
143 | + } |
|
144 | + $this->_events[ $options['event_id'] ] = 0; |
|
145 | + $html .= $this->_event_row($line_item); |
|
146 | + $text = esc_html__('Event Sub-Total', 'event_espresso'); |
|
147 | + } |
|
148 | + } |
|
149 | + $child_line_items = $line_item->children(); |
|
150 | + // loop thru children |
|
151 | + foreach ($child_line_items as $child_line_item) { |
|
152 | + // recursively feed children back into this method |
|
153 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
154 | + } |
|
155 | + $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0; |
|
156 | + $sub_total += $event_sub_total; |
|
157 | + if (( |
|
158 | + // event subtotals |
|
159 | + $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1 |
|
160 | + ) |
|
161 | + || ( |
|
162 | + // pre-tax subtotals |
|
163 | + $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1 |
|
164 | + ) |
|
165 | + ) { |
|
166 | + $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total; |
|
167 | + $html .= $this->_sub_total_row($line_item, $text, $options); |
|
168 | + } |
|
169 | + break; |
|
170 | + case EEM_Line_Item::type_tax: |
|
171 | + if ($this->_show_taxes) { |
|
172 | + $this->_taxes_html .= $this->_tax_row($line_item, $options); |
|
173 | + } |
|
174 | + break; |
|
175 | + case EEM_Line_Item::type_tax_sub_total: |
|
176 | + if ($this->_show_taxes) { |
|
177 | + $child_line_items = $line_item->children(); |
|
178 | + // loop thru children |
|
179 | + foreach ($child_line_items as $child_line_item) { |
|
180 | + // recursively feed children back into this method |
|
181 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
182 | + } |
|
183 | + if (count($child_line_items) > 1) { |
|
184 | + $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso')); |
|
185 | + } |
|
186 | + } |
|
187 | + break; |
|
188 | + case EEM_Line_Item::type_total: |
|
189 | + // get all child line items |
|
190 | + $children = $line_item->children(); |
|
191 | + // loop thru all non-tax child line items |
|
192 | + foreach ($children as $child_line_item) { |
|
193 | + if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) { |
|
194 | + // recursively feed children back into this method |
|
195 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
196 | + } |
|
197 | + } |
|
198 | + // now loop thru tax child line items |
|
199 | + foreach ($children as $child_line_item) { |
|
200 | + if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) { |
|
201 | + // recursively feed children back into this method |
|
202 | + $html .= $this->display_line_item($child_line_item, $options, $line_item); |
|
203 | + } |
|
204 | + } |
|
205 | + $html .= $this->_taxes_html; |
|
206 | + $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso')); |
|
207 | + $html .= $this->_payments_and_amount_owing_rows($line_item, $options); |
|
208 | + break; |
|
209 | + } |
|
210 | + return $html; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * _event_row - basically a Heading row displayed once above each event's ticket rows |
|
217 | + * |
|
218 | + * @param EE_Line_Item $line_item |
|
219 | + * @return mixed |
|
220 | + */ |
|
221 | + private function _event_row(EE_Line_Item $line_item) |
|
222 | + { |
|
223 | + // start of row |
|
224 | + $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd'); |
|
225 | + // event name td |
|
226 | + $html .= EEH_HTML::td( |
|
227 | + EEH_HTML::strong($line_item->name()), |
|
228 | + '', |
|
229 | + 'event-header', |
|
230 | + '', |
|
231 | + ' colspan="4"' |
|
232 | + ); |
|
233 | + // end of row |
|
234 | + $html .= EEH_HTML::trx(); |
|
235 | + return $html; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * _ticket_row |
|
242 | + * |
|
243 | + * @param EE_Line_Item $line_item |
|
244 | + * @param array $options |
|
245 | + * @return mixed |
|
246 | + * @throws EE_Error |
|
247 | + */ |
|
248 | + private function _ticket_row(EE_Line_Item $line_item, $options = array()) |
|
249 | + { |
|
250 | + // start of row |
|
251 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
252 | + $html = EEH_HTML::tr('', '', $row_class); |
|
253 | + // name && desc |
|
254 | + $name_and_desc = apply_filters( |
|
255 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
256 | + $line_item->name(), |
|
257 | + $line_item |
|
258 | + ); |
|
259 | + $name_and_desc .= apply_filters( |
|
260 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
261 | + ( |
|
262 | + $options['show_desc'] |
|
263 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
264 | + : '' |
|
265 | + ), |
|
266 | + $line_item, |
|
267 | + $options |
|
268 | + ); |
|
269 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
270 | + // name td |
|
271 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
272 | + $name_and_desc, |
|
273 | + '', |
|
274 | + 'item_l' |
|
275 | + ); |
|
276 | + // price td |
|
277 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
278 | + // quantity td |
|
279 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
280 | + $this->_total_items += $line_item->quantity(); |
|
281 | + // determine total for line item |
|
282 | + $total = $line_item->total(); |
|
283 | + $this->_events[ $options['event_id'] ] += $total; |
|
284 | + // total td |
|
285 | + $html .= EEH_HTML::td( |
|
286 | + EEH_Template::format_currency($total, false, false), |
|
287 | + '', |
|
288 | + 'item_r jst-rght' |
|
289 | + ); |
|
290 | + // end of row |
|
291 | + $html .= EEH_HTML::trx(); |
|
292 | + return $html; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * _item_row |
|
299 | + * |
|
300 | + * @param EE_Line_Item $line_item |
|
301 | + * @param array $options |
|
302 | + * @return mixed |
|
303 | + * @throws EE_Error |
|
304 | + */ |
|
305 | + private function _item_row(EE_Line_Item $line_item, $options = array()) |
|
306 | + { |
|
307 | + // start of row |
|
308 | + $row_class = $options['odd'] ? 'item odd' : 'item'; |
|
309 | + $html = EEH_HTML::tr('', '', $row_class); |
|
310 | + $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : ''; |
|
311 | + // name && desc |
|
312 | + $name_and_desc = apply_filters( |
|
313 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name', |
|
314 | + $obj_name . $line_item->name(), |
|
315 | + $line_item |
|
316 | + ); |
|
317 | + $name_and_desc .= apply_filters( |
|
318 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc', |
|
319 | + ( |
|
320 | + $options['show_desc'] |
|
321 | + ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>' |
|
322 | + : '' |
|
323 | + ), |
|
324 | + $line_item, |
|
325 | + $options |
|
326 | + ); |
|
327 | + $name_and_desc .= $line_item->is_taxable() ? ' * ' : ''; |
|
328 | + // name td |
|
329 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l'); |
|
330 | + // price td |
|
331 | + if ($line_item->is_percent()) { |
|
332 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght'); |
|
333 | + } else { |
|
334 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
335 | + } |
|
336 | + // quantity td |
|
337 | + $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght'); |
|
338 | + // $total = $line_item->total() * $line_item->quantity(); |
|
339 | + $total = $line_item->total(); |
|
340 | + if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) { |
|
341 | + $this->_events[ $options['event_id'] ] += $total; |
|
342 | + } |
|
343 | + // total td |
|
344 | + $html .= EEH_HTML::td( |
|
345 | + EEH_Template::format_currency($total, false, false), |
|
346 | + '', |
|
347 | + 'item_r jst-rght' |
|
348 | + ); |
|
349 | + // end of row |
|
350 | + $html .= EEH_HTML::trx(); |
|
351 | + return $html; |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * _sub_item_row |
|
358 | + * |
|
359 | + * @param EE_Line_Item $line_item |
|
360 | + * @param array $options |
|
361 | + * @param EE_Line_Item $parent_line_item |
|
362 | + * @return mixed |
|
363 | + * @throws EE_Error |
|
364 | + */ |
|
365 | + private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null) |
|
366 | + { |
|
367 | + if ($parent_line_item instanceof EE_Line_Item |
|
368 | + && $line_item->children() === array() |
|
369 | + && $line_item->name() === $parent_line_item->name() |
|
370 | + && apply_filters( |
|
371 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item', |
|
372 | + true |
|
373 | + ) |
|
374 | + ) { |
|
375 | + return ''; |
|
376 | + } |
|
377 | + // start of row |
|
378 | + $html = EEH_HTML::tr('', '', 'item sub-item-row'); |
|
379 | + // name && desc |
|
380 | + $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right') |
|
381 | + . $line_item->name(); |
|
382 | + $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: ' |
|
383 | + . $line_item->desc() |
|
384 | + . '</span>' : ''; |
|
385 | + // name td |
|
386 | + $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item'); |
|
387 | + $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1; |
|
388 | + // discount/surcharge td |
|
389 | + if ($line_item->is_percent()) { |
|
390 | + $html .= EEH_HTML::td( |
|
391 | + EEH_Template::format_currency( |
|
392 | + $line_item->total() / $qty, |
|
393 | + false, |
|
394 | + false |
|
395 | + ), |
|
396 | + '', |
|
397 | + 'item_c jst-rght' |
|
398 | + ); |
|
399 | + } else { |
|
400 | + $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght'); |
|
401 | + } |
|
402 | + // no quantity td |
|
403 | + $html .= EEH_HTML::td(); |
|
404 | + // no total td |
|
405 | + $html .= EEH_HTML::td(); |
|
406 | + // end of row |
|
407 | + $html .= EEH_HTML::trx(); |
|
408 | + $html = apply_filters( |
|
409 | + 'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html', |
|
410 | + $html, |
|
411 | + $line_item, |
|
412 | + $options, |
|
413 | + $parent_line_item |
|
414 | + ); |
|
415 | + return $html; |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * _tax_row |
|
422 | + * |
|
423 | + * @param EE_Line_Item $line_item |
|
424 | + * @param array $options |
|
425 | + * @return mixed |
|
426 | + * @throws EE_Error |
|
427 | + */ |
|
428 | + private function _tax_row(EE_Line_Item $line_item, $options = array()) |
|
429 | + { |
|
430 | + // start of row |
|
431 | + $html = EEH_HTML::tr('', 'item sub-item tax-total'); |
|
432 | + // name && desc |
|
433 | + $name_and_desc = $line_item->name(); |
|
434 | + $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">' |
|
435 | + . esc_html__(' * taxable items', 'event_espresso') . '</span>'; |
|
436 | + $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : ''; |
|
437 | + // name td |
|
438 | + $html .= EEH_HTML::td( /*__FUNCTION__ .*/ |
|
439 | + $name_and_desc, |
|
440 | + '', |
|
441 | + 'item_l sub-item' |
|
442 | + ); |
|
443 | + // percent td |
|
444 | + $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', ''); |
|
445 | + // empty td (price) |
|
446 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
447 | + // total td |
|
448 | + $html .= EEH_HTML::td( |
|
449 | + EEH_Template::format_currency( |
|
450 | + $line_item->total(), |
|
451 | + false, |
|
452 | + false |
|
453 | + ), |
|
454 | + '', |
|
455 | + 'item_r jst-rght' |
|
456 | + ); |
|
457 | + // end of row |
|
458 | + $html .= EEH_HTML::trx(); |
|
459 | + return $html; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * _total_row |
|
466 | + * |
|
467 | + * @param EE_Line_Item $line_item |
|
468 | + * @param string $text |
|
469 | + * @return mixed |
|
470 | + * @throws EE_Error |
|
471 | + */ |
|
472 | + private function _total_tax_row(EE_Line_Item $line_item, $text = '') |
|
473 | + { |
|
474 | + $html = ''; |
|
475 | + if ($line_item->total()) { |
|
476 | + // start of row |
|
477 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
478 | + // total td |
|
479 | + $html .= EEH_HTML::td( |
|
480 | + $text, |
|
481 | + '', |
|
482 | + 'total_currency total jst-rght', |
|
483 | + '', |
|
484 | + ' colspan="2"' |
|
485 | + ); |
|
486 | + // empty td (price) |
|
487 | + $html .= EEH_HTML::td(EEH_HTML::nbsp()); |
|
488 | + // total td |
|
489 | + $html .= EEH_HTML::td( |
|
490 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
491 | + '', |
|
492 | + 'total jst-rght' |
|
493 | + ); |
|
494 | + // end of row |
|
495 | + $html .= EEH_HTML::trx(); |
|
496 | + } |
|
497 | + return $html; |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * _total_row |
|
504 | + * |
|
505 | + * @param EE_Line_Item $line_item |
|
506 | + * @param string $text |
|
507 | + * @param array $options |
|
508 | + * @return mixed |
|
509 | + * @throws EE_Error |
|
510 | + */ |
|
511 | + private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array()) |
|
512 | + { |
|
513 | + $html = ''; |
|
514 | + if ($line_item->total()) { |
|
515 | + // start of row |
|
516 | + $html = EEH_HTML::tr('', '', 'total_tr odd'); |
|
517 | + // total td |
|
518 | + $html .= EEH_HTML::td( |
|
519 | + $text, |
|
520 | + '', |
|
521 | + 'total_currency total jst-rght', |
|
522 | + '', |
|
523 | + ' colspan="3"' |
|
524 | + ); |
|
525 | + // total td |
|
526 | + $html .= EEH_HTML::td( |
|
527 | + EEH_Template::format_currency($options['sub_total'], false, false), |
|
528 | + '', |
|
529 | + 'total jst-rght' |
|
530 | + ); |
|
531 | + // end of row |
|
532 | + $html .= EEH_HTML::trx(); |
|
533 | + } |
|
534 | + return $html; |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * _total_row |
|
541 | + * |
|
542 | + * @param EE_Line_Item $line_item |
|
543 | + * @param string $text |
|
544 | + * @return mixed |
|
545 | + * @throws EE_Error |
|
546 | + */ |
|
547 | + private function _total_row(EE_Line_Item $line_item, $text = '') |
|
548 | + { |
|
549 | + // start of row |
|
550 | + $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd'); |
|
551 | + // total td |
|
552 | + $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"'); |
|
553 | + // total td |
|
554 | + $html .= EEH_HTML::td( |
|
555 | + EEH_Template::format_currency($line_item->total(), false, false), |
|
556 | + '', |
|
557 | + 'total jst-rght' |
|
558 | + ); |
|
559 | + // end of row |
|
560 | + $html .= EEH_HTML::trx(); |
|
561 | + return $html; |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * _payments_and_amount_owing_rows |
|
568 | + * |
|
569 | + * @param EE_Line_Item $line_item |
|
570 | + * @param array $options |
|
571 | + * @return mixed |
|
572 | + * @throws EE_Error |
|
573 | + */ |
|
574 | + private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array()) |
|
575 | + { |
|
576 | + $html = ''; |
|
577 | + $owing = $line_item->total(); |
|
578 | + $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID()); |
|
579 | + if ($transaction instanceof EE_Transaction) { |
|
580 | + $registration_payments = array(); |
|
581 | + $registrations = ! empty($options['registrations']) |
|
582 | + ? $options['registrations'] |
|
583 | + : $transaction->registrations(); |
|
584 | + foreach ($registrations as $registration) { |
|
585 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
586 | + $registration_payments += $registration->registration_payments(); |
|
587 | + } |
|
588 | + } |
|
589 | + if (! empty($registration_payments)) { |
|
590 | + foreach ($registration_payments as $registration_payment) { |
|
591 | + if ($registration_payment instanceof EE_Registration_Payment) { |
|
592 | + $owing -= $registration_payment->amount(); |
|
593 | + $payment = $registration_payment->payment(); |
|
594 | + $payment_desc = ''; |
|
595 | + if ($payment instanceof EE_Payment) { |
|
596 | + $payment_desc = sprintf( |
|
597 | + esc_html__('Payment%1$s Received: %2$s', 'event_espresso'), |
|
598 | + $payment->txn_id_chq_nmbr() !== '' |
|
599 | + ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> ' |
|
600 | + : '', |
|
601 | + $payment->timestamp() |
|
602 | + ); |
|
603 | + } |
|
604 | + // start of row |
|
605 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
606 | + // payment desc |
|
607 | + $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"'); |
|
608 | + // total td |
|
609 | + $html .= EEH_HTML::td( |
|
610 | + EEH_Template::format_currency( |
|
611 | + $registration_payment->amount(), |
|
612 | + false, |
|
613 | + false |
|
614 | + ), |
|
615 | + '', |
|
616 | + 'total jst-rght' |
|
617 | + ); |
|
618 | + // end of row |
|
619 | + $html .= EEH_HTML::trx(); |
|
620 | + } |
|
621 | + } |
|
622 | + if ($line_item->total()) { |
|
623 | + // start of row |
|
624 | + $html .= EEH_HTML::tr('', '', 'total_tr odd'); |
|
625 | + // total td |
|
626 | + $html .= EEH_HTML::td( |
|
627 | + esc_html__('Amount Owing', 'event_espresso'), |
|
628 | + '', |
|
629 | + 'total_currency total jst-rght', |
|
630 | + '', |
|
631 | + ' colspan="3"' |
|
632 | + ); |
|
633 | + // total td |
|
634 | + $html .= EEH_HTML::td( |
|
635 | + EEH_Template::format_currency($owing, false, false), |
|
636 | + '', |
|
637 | + 'total jst-rght' |
|
638 | + ); |
|
639 | + // end of row |
|
640 | + $html .= EEH_HTML::trx(); |
|
641 | + } |
|
642 | + } |
|
643 | + } |
|
644 | + $this->_grand_total = $owing; |
|
645 | + return $html; |
|
646 | + } |
|
647 | 647 | } |
@@ -1,10 +1,10 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string'); |
3 | 3 | $values = EEH_Form_Fields::prep_answer_options( |
4 | - array( |
|
5 | - array('id' => 1, 'text' => __('Yes', 'event_espresso')), |
|
6 | - array('id' => 0, 'text' => __('No', 'event_espresso')), |
|
7 | - ) |
|
4 | + array( |
|
5 | + array('id' => 1, 'text' => __('Yes', 'event_espresso')), |
|
6 | + array('id' => 0, 'text' => __('No', 'event_espresso')), |
|
7 | + ) |
|
8 | 8 | ); |
9 | 9 | ?> |
10 | 10 | |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | |
13 | 13 | <h2 class="ee-admin-settings-hdr"> |
14 | 14 | <?php _e( |
15 | - 'Single Event Pages', |
|
16 | - 'event_espresso' |
|
17 | - ); ?><?php // echo EEH_Template::get_help_tab_link('event_single_settings_info');?> |
|
15 | + 'Single Event Pages', |
|
16 | + 'event_espresso' |
|
17 | + ); ?><?php // echo EEH_Template::get_help_tab_link('event_single_settings_info');?> |
|
18 | 18 | </h2> |
19 | 19 | <table class="form-table"> |
20 | 20 | <tbody> |
@@ -26,17 +26,17 @@ discard block |
||
26 | 26 | </th> |
27 | 27 | <td> |
28 | 28 | <?php echo EEH_Form_Fields::select( |
29 | - 'display_status_banner_single', |
|
30 | - $display_status_banner_single, |
|
31 | - $values, |
|
32 | - 'display_status_banner_single', |
|
33 | - 'display_status_banner_single' |
|
34 | - ); ?> |
|
29 | + 'display_status_banner_single', |
|
30 | + $display_status_banner_single, |
|
31 | + $values, |
|
32 | + 'display_status_banner_single', |
|
33 | + 'display_status_banner_single' |
|
34 | + ); ?> |
|
35 | 35 | <p class="description"><?php |
36 | - _e( |
|
37 | - 'Selecting "Yes" will inject an Event Status banner with the title whenever Events are displaying on the single event page.', |
|
38 | - 'event_espresso' |
|
39 | - ); ?></p> |
|
36 | + _e( |
|
37 | + 'Selecting "Yes" will inject an Event Status banner with the title whenever Events are displaying on the single event page.', |
|
38 | + 'event_espresso' |
|
39 | + ); ?></p> |
|
40 | 40 | </td> |
41 | 41 | </tr> |
42 | 42 | |
@@ -44,23 +44,23 @@ discard block |
||
44 | 44 | <th> |
45 | 45 | <label for="display_venue"> |
46 | 46 | <?php _e('Display Venue Details', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
47 | - 'display_addresses_in_reg_form_info' |
|
48 | - ); ?> |
|
47 | + 'display_addresses_in_reg_form_info' |
|
48 | + ); ?> |
|
49 | 49 | </label> |
50 | 50 | </th> |
51 | 51 | <td> |
52 | 52 | <?php echo EEH_Form_Fields::select( |
53 | - 'display_venue', |
|
54 | - $display_venue, |
|
55 | - $values, |
|
56 | - 'display_venue', |
|
57 | - 'display_venue' |
|
58 | - ); ?> |
|
53 | + 'display_venue', |
|
54 | + $display_venue, |
|
55 | + $values, |
|
56 | + 'display_venue', |
|
57 | + 'display_venue' |
|
58 | + ); ?> |
|
59 | 59 | <p class="description"><?php |
60 | - _e( |
|
61 | - 'Do not use this if you are using the venue shortcodes in your event description.', |
|
62 | - 'event_espresso' |
|
63 | - ); ?></p> |
|
60 | + _e( |
|
61 | + 'Do not use this if you are using the venue shortcodes in your event description.', |
|
62 | + 'event_espresso' |
|
63 | + ); ?></p> |
|
64 | 64 | </td> |
65 | 65 | </tr> |
66 | 66 | |
@@ -72,37 +72,37 @@ discard block |
||
72 | 72 | </th> |
73 | 73 | <td> |
74 | 74 | <?php |
75 | - echo EEH_Form_Fields::select( |
|
76 | - 'use_sortable_display_order', |
|
77 | - $use_sortable_display_order, |
|
78 | - $values, |
|
79 | - 'EED_Events_Single_use_sortable_display_order', |
|
80 | - 'EED_Events_Single_use_sortable_display_order' |
|
81 | - ); |
|
82 | - ?> |
|
75 | + echo EEH_Form_Fields::select( |
|
76 | + 'use_sortable_display_order', |
|
77 | + $use_sortable_display_order, |
|
78 | + $values, |
|
79 | + 'EED_Events_Single_use_sortable_display_order', |
|
80 | + 'EED_Events_Single_use_sortable_display_order' |
|
81 | + ); |
|
82 | + ?> |
|
83 | 83 | </td> |
84 | 84 | </tr> |
85 | 85 | |
86 | 86 | <tr> |
87 | 87 | <th> |
88 | 88 | <?php _e('Display Order', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
89 | - 'display_addresses_in_reg_form_info' |
|
90 | - ); ?> |
|
89 | + 'display_addresses_in_reg_form_info' |
|
90 | + ); ?> |
|
91 | 91 | </th> |
92 | 92 | <td> |
93 | 93 | |
94 | 94 | <?php wp_nonce_field( |
95 | - 'espresso_update_event_single_order', |
|
96 | - 'espresso_update_event_single_order_nonce', |
|
97 | - false |
|
98 | - ); ?> |
|
95 | + 'espresso_update_event_single_order', |
|
96 | + 'espresso_update_event_single_order_nonce', |
|
97 | + false |
|
98 | + ); ?> |
|
99 | 99 | <?php echo $event_single_display_order; ?> |
100 | 100 | |
101 | 101 | <p class="description"><?php |
102 | - _e( |
|
103 | - 'Drag and Drop the above to determine the display order of the Event Description, Date and Times, Ticket Selector, and Venue Information on the single event page.', |
|
104 | - 'event_espresso' |
|
105 | - ); ?></p> |
|
102 | + _e( |
|
103 | + 'Drag and Drop the above to determine the display order of the Event Description, Date and Times, Ticket Selector, and Venue Information on the single event page.', |
|
104 | + 'event_espresso' |
|
105 | + ); ?></p> |
|
106 | 106 | |
107 | 107 | </td> |
108 | 108 | </tr> |
@@ -2,18 +2,18 @@ discard block |
||
2 | 2 | add_filter('FHEE__EEH_Form_Fields__label_html', '__return_empty_string'); |
3 | 3 | |
4 | 4 | $values = EEH_Form_Fields::prep_answer_options( |
5 | - array( |
|
6 | - array('id' => 1, 'text' => __('Yes', 'event_espresso')), |
|
7 | - array('id' => 0, 'text' => __('No', 'event_espresso')), |
|
8 | - ) |
|
5 | + array( |
|
6 | + array('id' => 1, 'text' => __('Yes', 'event_espresso')), |
|
7 | + array('id' => 0, 'text' => __('No', 'event_espresso')), |
|
8 | + ) |
|
9 | 9 | ); |
10 | 10 | |
11 | 11 | $description = EEH_Form_Fields::prep_answer_options( |
12 | - array( |
|
13 | - array('id' => 0, 'text' => __('none', 'event_espresso')), |
|
14 | - array('id' => 1, 'text' => __('excerpt (short desc)', 'event_espresso')), |
|
15 | - array('id' => 2, 'text' => __('full description', 'event_espresso')), |
|
16 | - ) |
|
12 | + array( |
|
13 | + array('id' => 0, 'text' => __('none', 'event_espresso')), |
|
14 | + array('id' => 1, 'text' => __('excerpt (short desc)', 'event_espresso')), |
|
15 | + array('id' => 2, 'text' => __('full description', 'event_espresso')), |
|
16 | + ) |
|
17 | 17 | ); |
18 | 18 | |
19 | 19 | ?> |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | <th> |
33 | 33 | <label for="event_listings_url"> |
34 | 34 | <?php _e('Event Listings URL', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
35 | - 'event_listings_url_info' |
|
36 | - ); ?> |
|
35 | + 'event_listings_url_info' |
|
36 | + ); ?> |
|
37 | 37 | </label> |
38 | 38 | </th> |
39 | 39 | <td> |
40 | 40 | <a id="event_listings_url" class="ee-admin-settings-hdr-lnk small-text" |
41 | 41 | href="<?php echo EEH_Event_View::event_archive_url(); ?>"><?php |
42 | - echo EEH_Event_View::event_archive_url(); ?></a> |
|
42 | + echo EEH_Event_View::event_archive_url(); ?></a> |
|
43 | 43 | </td> |
44 | 44 | </tr> |
45 | 45 | |
@@ -51,30 +51,30 @@ discard block |
||
51 | 51 | </th> |
52 | 52 | <td> |
53 | 53 | <p><?php echo site_url() . '/ ' |
54 | - . EEH_Form_Fields::text( |
|
55 | - 'not_used', |
|
56 | - EE_Registry::instance()->CFG->core->event_cpt_slug, |
|
57 | - 'event_cpt_slug', |
|
58 | - 'event_cpt_slug', |
|
59 | - 'regular' |
|
60 | - ); ?></p> |
|
54 | + . EEH_Form_Fields::text( |
|
55 | + 'not_used', |
|
56 | + EE_Registry::instance()->CFG->core->event_cpt_slug, |
|
57 | + 'event_cpt_slug', |
|
58 | + 'event_cpt_slug', |
|
59 | + 'regular' |
|
60 | + ); ?></p> |
|
61 | 61 | <p class="description"><?php |
62 | - _e( |
|
63 | - 'This allows you to configure what slug is used for the url of all event pages.', |
|
64 | - 'event_espresso' |
|
65 | - ); ?></p> |
|
62 | + _e( |
|
63 | + 'This allows you to configure what slug is used for the url of all event pages.', |
|
64 | + 'event_espresso' |
|
65 | + ); ?></p> |
|
66 | 66 | <?php if (has_filter('FHEE__EE_Register_CPTs__register_CPT__rewrite')) : ?> |
67 | 67 | <p class="important-notice"> |
68 | 68 | <?php |
69 | - sprintf( |
|
70 | - __( |
|
71 | - 'Usage of the %1$s FHEE__EE_Register_CPTs__register_CPT__rewrite %2$s filter has been detected. Please be aware that while this filter is being used, this setting has no affect.', |
|
72 | - 'event_espresso' |
|
73 | - ), |
|
74 | - '<code>', |
|
75 | - '</code>' |
|
76 | - ); |
|
77 | - ?> |
|
69 | + sprintf( |
|
70 | + __( |
|
71 | + 'Usage of the %1$s FHEE__EE_Register_CPTs__register_CPT__rewrite %2$s filter has been detected. Please be aware that while this filter is being used, this setting has no affect.', |
|
72 | + 'event_espresso' |
|
73 | + ), |
|
74 | + '<code>', |
|
75 | + '</code>' |
|
76 | + ); |
|
77 | + ?> |
|
78 | 78 | </p> |
79 | 79 | <?php endif; ?> |
80 | 80 | </td> |
@@ -88,17 +88,17 @@ discard block |
||
88 | 88 | </th> |
89 | 89 | <td> |
90 | 90 | <?php echo EEH_Form_Fields::select( |
91 | - 'display_status_banner', |
|
92 | - $display_status_banner, |
|
93 | - $values, |
|
94 | - 'EED_Events_Archive_display_status_banner', |
|
95 | - 'EED_Events_Archive_display_status_banner' |
|
96 | - ); ?> |
|
91 | + 'display_status_banner', |
|
92 | + $display_status_banner, |
|
93 | + $values, |
|
94 | + 'EED_Events_Archive_display_status_banner', |
|
95 | + 'EED_Events_Archive_display_status_banner' |
|
96 | + ); ?> |
|
97 | 97 | <p class="description"><?php |
98 | - _e( |
|
99 | - 'Selecting "Yes" will inject an Event Status banner with the title whenever Events are displaying on the events archive page.', |
|
100 | - 'event_espresso' |
|
101 | - ); ?></p> |
|
98 | + _e( |
|
99 | + 'Selecting "Yes" will inject an Event Status banner with the title whenever Events are displaying on the events archive page.', |
|
100 | + 'event_espresso' |
|
101 | + ); ?></p> |
|
102 | 102 | </td> |
103 | 103 | </tr> |
104 | 104 | |
@@ -106,18 +106,18 @@ discard block |
||
106 | 106 | <th> |
107 | 107 | <label for="EED_Events_Archive_display_description"> |
108 | 108 | <?php _e('Display Description', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
109 | - 'display_description_info' |
|
110 | - ); ?> |
|
109 | + 'display_description_info' |
|
110 | + ); ?> |
|
111 | 111 | </label> |
112 | 112 | </th> |
113 | 113 | <td> |
114 | 114 | <?php echo EEH_Form_Fields::select( |
115 | - 'description', |
|
116 | - $display_description, |
|
117 | - $description, |
|
118 | - 'EED_Events_Archive_display_description', |
|
119 | - 'EED_Events_Archive_display_description' |
|
120 | - ); ?> |
|
115 | + 'description', |
|
116 | + $display_description, |
|
117 | + $description, |
|
118 | + 'EED_Events_Archive_display_description', |
|
119 | + 'EED_Events_Archive_display_description' |
|
120 | + ); ?> |
|
121 | 121 | </td> |
122 | 122 | </tr> |
123 | 123 | |
@@ -125,18 +125,18 @@ discard block |
||
125 | 125 | <th> |
126 | 126 | <label for="EED_Events_Archive_display_ticket_selector"> |
127 | 127 | <?php _e('Display Ticket Selector', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
128 | - 'display_ticket_selector_info' |
|
129 | - ); ?> |
|
128 | + 'display_ticket_selector_info' |
|
129 | + ); ?> |
|
130 | 130 | </label> |
131 | 131 | </th> |
132 | 132 | <td> |
133 | 133 | <?php echo EEH_Form_Fields::select( |
134 | - 'ticket_selector', |
|
135 | - $display_ticket_selector, |
|
136 | - $values, |
|
137 | - 'EED_Events_Archive_display_ticket_selector', |
|
138 | - 'EED_Events_Archive_display_ticket_selector' |
|
139 | - ); ?> |
|
134 | + 'ticket_selector', |
|
135 | + $display_ticket_selector, |
|
136 | + $values, |
|
137 | + 'EED_Events_Archive_display_ticket_selector', |
|
138 | + 'EED_Events_Archive_display_ticket_selector' |
|
139 | + ); ?> |
|
140 | 140 | </td> |
141 | 141 | </tr> |
142 | 142 | |
@@ -144,18 +144,18 @@ discard block |
||
144 | 144 | <th> |
145 | 145 | <label for="EED_Events_Archive_display_datetimes"> |
146 | 146 | <?php _e('Display Datetimes', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
147 | - 'display_datetimes_info' |
|
148 | - ); ?> |
|
147 | + 'display_datetimes_info' |
|
148 | + ); ?> |
|
149 | 149 | </label> |
150 | 150 | </th> |
151 | 151 | <td> |
152 | 152 | <?php echo EEH_Form_Fields::select( |
153 | - 'venue_details', |
|
154 | - $display_datetimes, |
|
155 | - $values, |
|
156 | - 'EED_Events_Archive_display_datetimes', |
|
157 | - 'EED_Events_Archive_display_datetimes' |
|
158 | - ); ?> |
|
153 | + 'venue_details', |
|
154 | + $display_datetimes, |
|
155 | + $values, |
|
156 | + 'EED_Events_Archive_display_datetimes', |
|
157 | + 'EED_Events_Archive_display_datetimes' |
|
158 | + ); ?> |
|
159 | 159 | </td> |
160 | 160 | </tr> |
161 | 161 | |
@@ -163,18 +163,18 @@ discard block |
||
163 | 163 | <th> |
164 | 164 | <label for="EED_Events_Archive_display_venue"> |
165 | 165 | <?php _e('Display Venue Details', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
166 | - 'display_venue_details_info' |
|
167 | - ); ?> |
|
166 | + 'display_venue_details_info' |
|
167 | + ); ?> |
|
168 | 168 | </label> |
169 | 169 | </th> |
170 | 170 | <td> |
171 | 171 | <?php echo EEH_Form_Fields::select( |
172 | - 'display_venue', |
|
173 | - $display_venue, |
|
174 | - $values, |
|
175 | - 'EED_Events_Archive_display_venue', |
|
176 | - 'EED_Events_Archive_display_venue' |
|
177 | - ); ?> |
|
172 | + 'display_venue', |
|
173 | + $display_venue, |
|
174 | + $values, |
|
175 | + 'EED_Events_Archive_display_venue', |
|
176 | + 'EED_Events_Archive_display_venue' |
|
177 | + ); ?> |
|
178 | 178 | </td> |
179 | 179 | </tr> |
180 | 180 | |
@@ -182,18 +182,18 @@ discard block |
||
182 | 182 | <th> |
183 | 183 | <label for="EED_Events_Archive_display_expired_events"> |
184 | 184 | <?php _e('Display Expired Events', 'event_espresso'); ?><?php echo EEH_Template::get_help_tab_link( |
185 | - 'display_expired_events_info' |
|
186 | - ); ?> |
|
185 | + 'display_expired_events_info' |
|
186 | + ); ?> |
|
187 | 187 | </label> |
188 | 188 | </th> |
189 | 189 | <td> |
190 | 190 | <?php echo EEH_Form_Fields::select( |
191 | - 'expired_events', |
|
192 | - $display_expired_events, |
|
193 | - $values, |
|
194 | - 'EED_Events_Archive_display_expired_events', |
|
195 | - 'EED_Events_Archive_display_expired_events' |
|
196 | - ); ?> |
|
191 | + 'expired_events', |
|
192 | + $display_expired_events, |
|
193 | + $values, |
|
194 | + 'EED_Events_Archive_display_expired_events', |
|
195 | + 'EED_Events_Archive_display_expired_events' |
|
196 | + ); ?> |
|
197 | 197 | </td> |
198 | 198 | </tr> |
199 | 199 | |
@@ -201,43 +201,43 @@ discard block |
||
201 | 201 | <th> |
202 | 202 | <label for="EED_Events_Archive_use_sortable_display_order"> |
203 | 203 | <?php _e( |
204 | - 'Use Custom Display Order?', |
|
205 | - 'event_espresso' |
|
206 | - ); ?><?php // echo EEH_Template::get_help_tab_link('use_sortable_display_order_info');?> |
|
204 | + 'Use Custom Display Order?', |
|
205 | + 'event_espresso' |
|
206 | + ); ?><?php // echo EEH_Template::get_help_tab_link('use_sortable_display_order_info');?> |
|
207 | 207 | </label> |
208 | 208 | </th> |
209 | 209 | <td> |
210 | 210 | <?php echo EEH_Form_Fields::select( |
211 | - 'use_sortable_display_order', |
|
212 | - $use_sortable_display_order, |
|
213 | - $values, |
|
214 | - 'EED_Events_Archive_use_sortable_display_order', |
|
215 | - 'EED_Events_Archive_use_sortable_display_order' |
|
216 | - ); ?> |
|
211 | + 'use_sortable_display_order', |
|
212 | + $use_sortable_display_order, |
|
213 | + $values, |
|
214 | + 'EED_Events_Archive_use_sortable_display_order', |
|
215 | + 'EED_Events_Archive_use_sortable_display_order' |
|
216 | + ); ?> |
|
217 | 217 | </td> |
218 | 218 | </tr> |
219 | 219 | |
220 | 220 | <tr> |
221 | 221 | <th> |
222 | 222 | <?php _e( |
223 | - 'Display Order', |
|
224 | - 'event_espresso' |
|
225 | - ); ?><?php // echo EEH_Template::get_help_tab_link( 'event_archive_order_info' ); ?> |
|
223 | + 'Display Order', |
|
224 | + 'event_espresso' |
|
225 | + ); ?><?php // echo EEH_Template::get_help_tab_link( 'event_archive_order_info' ); ?> |
|
226 | 226 | </th> |
227 | 227 | <td> |
228 | 228 | |
229 | 229 | <?php wp_nonce_field( |
230 | - 'espresso_update_event_archive_order', |
|
231 | - 'espresso_update_event_archive_order_nonce', |
|
232 | - false |
|
233 | - ); ?> |
|
230 | + 'espresso_update_event_archive_order', |
|
231 | + 'espresso_update_event_archive_order_nonce', |
|
232 | + false |
|
233 | + ); ?> |
|
234 | 234 | <?php echo $event_archive_display_order; ?> |
235 | 235 | |
236 | 236 | <p class="description"><?php |
237 | - _e( |
|
238 | - 'Drag and Drop the above to determine the display order of the Event Description, Date and Times, Ticket Selector, and Venue Information on the event archive page.', |
|
239 | - 'event_espresso' |
|
240 | - ); ?></p> |
|
237 | + _e( |
|
238 | + 'Drag and Drop the above to determine the display order of the Event Description, Date and Times, Ticket Selector, and Venue Information on the event archive page.', |
|
239 | + 'event_espresso' |
|
240 | + ); ?></p> |
|
241 | 241 | |
242 | 242 | </td> |
243 | 243 | </tr> |
@@ -250,12 +250,12 @@ discard block |
||
250 | 250 | </th> |
251 | 251 | <td> |
252 | 252 | <?php echo EEH_Form_Fields::select( |
253 | - 'reset_event_list_settings', |
|
254 | - 0, |
|
255 | - $values, |
|
256 | - 'EED_Events_Archive_reset_event_list_settings', |
|
257 | - 'EED_Events_Archive_reset_event_list_settings' |
|
258 | - ); ?> |
|
253 | + 'reset_event_list_settings', |
|
254 | + 0, |
|
255 | + $values, |
|
256 | + 'EED_Events_Archive_reset_event_list_settings', |
|
257 | + 'EED_Events_Archive_reset_event_list_settings' |
|
258 | + ); ?> |
|
259 | 259 | </td> |
260 | 260 | </tr> |
261 | 261 |
@@ -16,445 +16,445 @@ |
||
16 | 16 | class EE_CPT_Strategy extends EE_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var EE_CPT_Strategy $_instance |
|
21 | - */ |
|
22 | - private static $_instance; |
|
23 | - |
|
24 | - /** |
|
25 | - * the current page, if it utilizes CPTs |
|
26 | - * |
|
27 | - * @var array $CPT |
|
28 | - */ |
|
29 | - protected $CPT; |
|
30 | - |
|
31 | - /** |
|
32 | - * return value from CustomPostTypeDefinitions::getDefinitions() |
|
33 | - * |
|
34 | - * @var array $_CPTs |
|
35 | - */ |
|
36 | - protected $_CPTs = array(); |
|
37 | - |
|
38 | - /** |
|
39 | - * @var array $_CPT_taxonomies |
|
40 | - */ |
|
41 | - protected $_CPT_taxonomies = array(); |
|
42 | - |
|
43 | - /** |
|
44 | - * @var array $_CPT_terms |
|
45 | - */ |
|
46 | - protected $_CPT_terms = array(); |
|
47 | - |
|
48 | - /** |
|
49 | - * @var array $_CPT_endpoints |
|
50 | - */ |
|
51 | - protected $_CPT_endpoints = array(); |
|
52 | - |
|
53 | - /** |
|
54 | - * @var EEM_Base $CPT_model |
|
55 | - */ |
|
56 | - protected $CPT_model; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier |
|
60 | - */ |
|
61 | - protected $query_modifier; |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @singleton method used to instantiate class object |
|
66 | - * @param CustomPostTypeDefinitions|null $custom_post_types |
|
67 | - * @param CustomTaxonomyDefinitions|null $taxonomies |
|
68 | - * @return EE_CPT_Strategy |
|
69 | - */ |
|
70 | - public static function instance( |
|
71 | - CustomPostTypeDefinitions $custom_post_types = null, |
|
72 | - CustomTaxonomyDefinitions $taxonomies = null |
|
73 | - ) { |
|
74 | - // check if class object is instantiated |
|
75 | - if (! self::$_instance instanceof EE_CPT_Strategy |
|
76 | - && $custom_post_types instanceof CustomPostTypeDefinitions |
|
77 | - && $taxonomies instanceof CustomTaxonomyDefinitions |
|
78 | - ) { |
|
79 | - self::$_instance = new self($custom_post_types, $taxonomies); |
|
80 | - } |
|
81 | - return self::$_instance; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @param CustomPostTypeDefinitions $custom_post_types |
|
87 | - * @param CustomTaxonomyDefinitions $taxonomies |
|
88 | - */ |
|
89 | - protected function __construct( |
|
90 | - CustomPostTypeDefinitions $custom_post_types, |
|
91 | - CustomTaxonomyDefinitions $taxonomies |
|
92 | - ) { |
|
93 | - // get CPT data |
|
94 | - $this->_CPTs = $custom_post_types->getDefinitions(); |
|
95 | - $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
96 | - $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
97 | - add_action('pre_get_posts', array($this, 'pre_get_posts'), 5); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public function get_CPT_endpoints() |
|
105 | - { |
|
106 | - return $this->_CPT_endpoints; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return array |
|
112 | - */ |
|
113 | - public function get_CPT_taxonomies() |
|
114 | - { |
|
115 | - return $this->_CPT_taxonomies; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * add CPT "slugs" to array of default espresso "pages" |
|
121 | - * |
|
122 | - * @return array |
|
123 | - */ |
|
124 | - private function _set_CPT_endpoints() |
|
125 | - { |
|
126 | - $_CPT_endpoints = array(); |
|
127 | - if (is_array($this->_CPTs)) { |
|
128 | - foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
129 | - $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type; |
|
130 | - } |
|
131 | - } |
|
132 | - return $_CPT_endpoints; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
138 | - * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
139 | - * adding EE objects to the post to facilitate further querying of related data etc) |
|
140 | - * |
|
141 | - * @param WP_Query $WP_Query |
|
142 | - * @return void |
|
143 | - * @throws \EE_Error |
|
144 | - * @throws \InvalidArgumentException |
|
145 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
146 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
147 | - */ |
|
148 | - public function pre_get_posts($WP_Query) |
|
149 | - { |
|
150 | - // check that post-type is set |
|
151 | - if (! $WP_Query instanceof WP_Query) { |
|
152 | - return; |
|
153 | - } |
|
154 | - // add our conditionals |
|
155 | - $this->_set_EE_tags_on_WP_Query($WP_Query); |
|
156 | - // check for terms |
|
157 | - $this->_set_post_type_for_terms($WP_Query); |
|
158 | - // make sure paging is always set |
|
159 | - $this->_set_paging($WP_Query); |
|
160 | - // is a taxonomy set ? |
|
161 | - $this->_set_CPT_taxonomies_on_WP_Query($WP_Query); |
|
162 | - // loop thru post_types if set |
|
163 | - $this->_process_WP_Query_post_types($WP_Query); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @param WP_Query $WP_Query |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) |
|
172 | - { |
|
173 | - $WP_Query->is_espresso_event_single = false; |
|
174 | - $WP_Query->is_espresso_event_archive = false; |
|
175 | - $WP_Query->is_espresso_event_taxonomy = false; |
|
176 | - $WP_Query->is_espresso_venue_single = false; |
|
177 | - $WP_Query->is_espresso_venue_archive = false; |
|
178 | - $WP_Query->is_espresso_venue_taxonomy = false; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @return void |
|
184 | - * @throws EE_Error |
|
185 | - * @throws InvalidArgumentException |
|
186 | - * @throws InvalidDataTypeException |
|
187 | - * @throws InvalidInterfaceException |
|
188 | - */ |
|
189 | - private function _set_CPT_terms() |
|
190 | - { |
|
191 | - if (empty($this->_CPT_terms)) { |
|
192 | - $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
193 | - foreach ($terms as $term) { |
|
194 | - if ($term instanceof EE_Term) { |
|
195 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
196 | - } |
|
197 | - } |
|
198 | - } |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @param WP_Query $WP_Query |
|
204 | - * @return void |
|
205 | - * @throws EE_Error |
|
206 | - * @throws InvalidArgumentException |
|
207 | - * @throws InvalidDataTypeException |
|
208 | - * @throws InvalidInterfaceException |
|
209 | - */ |
|
210 | - private function _set_post_type_for_terms(WP_Query $WP_Query) |
|
211 | - { |
|
212 | - // is a tag set ? |
|
213 | - if (isset($WP_Query->query['tag'])) { |
|
214 | - // get term for tag |
|
215 | - $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']); |
|
216 | - // verify the term |
|
217 | - if ($term instanceof EE_Term) { |
|
218 | - $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type); |
|
219 | - $term->post_type = apply_filters( |
|
220 | - 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
221 | - $term->post_type, |
|
222 | - $term |
|
223 | - ); |
|
224 | - // if a post type is already set |
|
225 | - if (isset($WP_Query->query_vars['post_type'])) { |
|
226 | - // add to existing array |
|
227 | - $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type); |
|
228 | - } |
|
229 | - // just set post_type to our CPT |
|
230 | - $WP_Query->set('post_type', array_unique($term->post_type)); |
|
231 | - } |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * @param WP_Query $WP_Query |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - public function _set_paging($WP_Query) |
|
241 | - { |
|
242 | - if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
243 | - $page = get_query_var('page') ? get_query_var('page') : null; |
|
244 | - $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
245 | - $WP_Query->set('paged', $paged); |
|
246 | - } |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param \WP_Query $WP_Query |
|
252 | - */ |
|
253 | - protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) |
|
254 | - { |
|
255 | - // is a taxonomy set ? |
|
256 | - if ($WP_Query->is_tax) { |
|
257 | - // loop thru our taxonomies |
|
258 | - foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
259 | - // check if one of our taxonomies is set as a query var |
|
260 | - if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
261 | - // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
262 | - foreach ($this->_CPTs as $post_type => $CPT) { |
|
263 | - // verify our CPT has args, is public and has taxonomies set |
|
264 | - if (isset($CPT['args']['public']) |
|
265 | - && $CPT['args']['public'] |
|
266 | - && ! empty($CPT['args']['taxonomies']) |
|
267 | - && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
268 | - ) { |
|
269 | - // if so, then add this CPT post_type to the current query's array of post_types' |
|
270 | - $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type']) |
|
271 | - ? (array) $WP_Query->query_vars['post_type'] |
|
272 | - : array(); |
|
273 | - $WP_Query->query_vars['post_type'][] = $post_type; |
|
274 | - switch ($post_type) { |
|
275 | - case 'espresso_events': |
|
276 | - $WP_Query->is_espresso_event_taxonomy = true; |
|
277 | - break; |
|
278 | - case 'espresso_venues': |
|
279 | - $WP_Query->is_espresso_venue_taxonomy = true; |
|
280 | - break; |
|
281 | - default: |
|
282 | - do_action( |
|
283 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
284 | - $WP_Query, |
|
285 | - $this |
|
286 | - ); |
|
287 | - } |
|
288 | - } |
|
289 | - } |
|
290 | - } |
|
291 | - } |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * @param \WP_Query $WP_Query |
|
298 | - * @throws InvalidArgumentException |
|
299 | - * @throws InvalidDataTypeException |
|
300 | - * @throws InvalidInterfaceException |
|
301 | - */ |
|
302 | - protected function _process_WP_Query_post_types(WP_Query $WP_Query) |
|
303 | - { |
|
304 | - if (isset($WP_Query->query_vars['post_type'])) { |
|
305 | - // loop thru post_types as array |
|
306 | - foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
|
307 | - // is current query for an EE CPT ? |
|
308 | - if (isset($this->_CPTs[ $post_type ])) { |
|
309 | - // is EE on or off ? |
|
310 | - if (EE_Maintenance_Mode::instance()->level()) { |
|
311 | - // reroute CPT template view to maintenance_mode.template.php |
|
312 | - if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
313 | - add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
|
314 | - } |
|
315 | - if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
|
316 | - add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1); |
|
317 | - } |
|
318 | - return; |
|
319 | - } |
|
320 | - $this->_generate_CptQueryModifier($WP_Query, $post_type); |
|
321 | - } |
|
322 | - } |
|
323 | - } |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * @param \WP_Query $WP_Query |
|
329 | - * @param string $post_type |
|
330 | - * @throws InvalidArgumentException |
|
331 | - * @throws InvalidDataTypeException |
|
332 | - * @throws InvalidInterfaceException |
|
333 | - */ |
|
334 | - protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) |
|
335 | - { |
|
336 | - $this->query_modifier = LoaderFactory::getLoader()->getShared( |
|
337 | - 'EventEspresso\core\CPTs\CptQueryModifier', |
|
338 | - array( |
|
339 | - $post_type, |
|
340 | - $this->_CPTs[ $post_type ], |
|
341 | - $WP_Query, |
|
342 | - ) |
|
343 | - ); |
|
344 | - $this->_CPT_taxonomies = $this->query_modifier->taxonomies(); |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * inject_EE_shortcode_placeholder |
|
350 | - * in order to display the M-Mode notice on our CPT routes, |
|
351 | - * we need to first inject what looks like one of our shortcodes, |
|
352 | - * so that it can be replaced with the actual M-Mode notice |
|
353 | - * |
|
354 | - * @return string |
|
355 | - */ |
|
356 | - public function inject_EE_shortcode_placeholder() |
|
357 | - { |
|
358 | - return '[ESPRESSO_'; |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * @deprecated |
|
364 | - * @since 4.8.41 |
|
365 | - * @return void |
|
366 | - */ |
|
367 | - public function _possibly_set_ee_request_var() |
|
368 | - { |
|
369 | - $this->query_modifier->setRequestVarsIfCpt(); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * @deprecated |
|
375 | - * @since 4.8.41 |
|
376 | - * @param $SQL |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public function posts_fields($SQL) |
|
380 | - { |
|
381 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
382 | - return $this->query_modifier->postsFields($SQL); |
|
383 | - } |
|
384 | - return $SQL; |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * @deprecated |
|
390 | - * @since 4.8.41 |
|
391 | - * @param $SQL |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - public function posts_join($SQL) |
|
395 | - { |
|
396 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
397 | - return $this->query_modifier->postsJoin($SQL); |
|
398 | - } |
|
399 | - return $SQL; |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * @deprecated |
|
405 | - * @since 4.8.41 |
|
406 | - * @param \WP_Post[] $posts |
|
407 | - * @return \WP_Post[] |
|
408 | - */ |
|
409 | - public function the_posts($posts) |
|
410 | - { |
|
411 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
412 | - $this->query_modifier->thePosts($posts); |
|
413 | - } |
|
414 | - return $posts; |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - /** |
|
419 | - * @deprecated |
|
420 | - * @since 4.8.41 |
|
421 | - * @param $url |
|
422 | - * @param $ID |
|
423 | - * @return string |
|
424 | - */ |
|
425 | - public function get_edit_post_link($url, $ID) |
|
426 | - { |
|
427 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
428 | - return $this->query_modifier->getEditPostLink($url, $ID); |
|
429 | - } |
|
430 | - return ''; |
|
431 | - } |
|
432 | - |
|
433 | - |
|
434 | - /** |
|
435 | - * @deprecated |
|
436 | - * @since 4.8.41 |
|
437 | - * @param null $WP_Query |
|
438 | - */ |
|
439 | - protected function _do_template_filters($WP_Query = null) |
|
440 | - { |
|
441 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
442 | - $this->query_modifier->addTemplateFilters(); |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * @deprecated |
|
449 | - * @since 4.8.41 |
|
450 | - * @param string $current_template Existing default template path derived for this page call. |
|
451 | - * @return string the path to the full template file. |
|
452 | - */ |
|
453 | - public function single_cpt_template($current_template) |
|
454 | - { |
|
455 | - if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
456 | - return $this->query_modifier->singleCptTemplate($current_template); |
|
457 | - } |
|
458 | - return $current_template; |
|
459 | - } |
|
19 | + /** |
|
20 | + * @var EE_CPT_Strategy $_instance |
|
21 | + */ |
|
22 | + private static $_instance; |
|
23 | + |
|
24 | + /** |
|
25 | + * the current page, if it utilizes CPTs |
|
26 | + * |
|
27 | + * @var array $CPT |
|
28 | + */ |
|
29 | + protected $CPT; |
|
30 | + |
|
31 | + /** |
|
32 | + * return value from CustomPostTypeDefinitions::getDefinitions() |
|
33 | + * |
|
34 | + * @var array $_CPTs |
|
35 | + */ |
|
36 | + protected $_CPTs = array(); |
|
37 | + |
|
38 | + /** |
|
39 | + * @var array $_CPT_taxonomies |
|
40 | + */ |
|
41 | + protected $_CPT_taxonomies = array(); |
|
42 | + |
|
43 | + /** |
|
44 | + * @var array $_CPT_terms |
|
45 | + */ |
|
46 | + protected $_CPT_terms = array(); |
|
47 | + |
|
48 | + /** |
|
49 | + * @var array $_CPT_endpoints |
|
50 | + */ |
|
51 | + protected $_CPT_endpoints = array(); |
|
52 | + |
|
53 | + /** |
|
54 | + * @var EEM_Base $CPT_model |
|
55 | + */ |
|
56 | + protected $CPT_model; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier |
|
60 | + */ |
|
61 | + protected $query_modifier; |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @singleton method used to instantiate class object |
|
66 | + * @param CustomPostTypeDefinitions|null $custom_post_types |
|
67 | + * @param CustomTaxonomyDefinitions|null $taxonomies |
|
68 | + * @return EE_CPT_Strategy |
|
69 | + */ |
|
70 | + public static function instance( |
|
71 | + CustomPostTypeDefinitions $custom_post_types = null, |
|
72 | + CustomTaxonomyDefinitions $taxonomies = null |
|
73 | + ) { |
|
74 | + // check if class object is instantiated |
|
75 | + if (! self::$_instance instanceof EE_CPT_Strategy |
|
76 | + && $custom_post_types instanceof CustomPostTypeDefinitions |
|
77 | + && $taxonomies instanceof CustomTaxonomyDefinitions |
|
78 | + ) { |
|
79 | + self::$_instance = new self($custom_post_types, $taxonomies); |
|
80 | + } |
|
81 | + return self::$_instance; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @param CustomPostTypeDefinitions $custom_post_types |
|
87 | + * @param CustomTaxonomyDefinitions $taxonomies |
|
88 | + */ |
|
89 | + protected function __construct( |
|
90 | + CustomPostTypeDefinitions $custom_post_types, |
|
91 | + CustomTaxonomyDefinitions $taxonomies |
|
92 | + ) { |
|
93 | + // get CPT data |
|
94 | + $this->_CPTs = $custom_post_types->getDefinitions(); |
|
95 | + $this->_CPT_endpoints = $this->_set_CPT_endpoints(); |
|
96 | + $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions(); |
|
97 | + add_action('pre_get_posts', array($this, 'pre_get_posts'), 5); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public function get_CPT_endpoints() |
|
105 | + { |
|
106 | + return $this->_CPT_endpoints; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return array |
|
112 | + */ |
|
113 | + public function get_CPT_taxonomies() |
|
114 | + { |
|
115 | + return $this->_CPT_taxonomies; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * add CPT "slugs" to array of default espresso "pages" |
|
121 | + * |
|
122 | + * @return array |
|
123 | + */ |
|
124 | + private function _set_CPT_endpoints() |
|
125 | + { |
|
126 | + $_CPT_endpoints = array(); |
|
127 | + if (is_array($this->_CPTs)) { |
|
128 | + foreach ($this->_CPTs as $CPT_type => $CPT) { |
|
129 | + $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type; |
|
130 | + } |
|
131 | + } |
|
132 | + return $_CPT_endpoints; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to |
|
138 | + * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and |
|
139 | + * adding EE objects to the post to facilitate further querying of related data etc) |
|
140 | + * |
|
141 | + * @param WP_Query $WP_Query |
|
142 | + * @return void |
|
143 | + * @throws \EE_Error |
|
144 | + * @throws \InvalidArgumentException |
|
145 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
146 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
147 | + */ |
|
148 | + public function pre_get_posts($WP_Query) |
|
149 | + { |
|
150 | + // check that post-type is set |
|
151 | + if (! $WP_Query instanceof WP_Query) { |
|
152 | + return; |
|
153 | + } |
|
154 | + // add our conditionals |
|
155 | + $this->_set_EE_tags_on_WP_Query($WP_Query); |
|
156 | + // check for terms |
|
157 | + $this->_set_post_type_for_terms($WP_Query); |
|
158 | + // make sure paging is always set |
|
159 | + $this->_set_paging($WP_Query); |
|
160 | + // is a taxonomy set ? |
|
161 | + $this->_set_CPT_taxonomies_on_WP_Query($WP_Query); |
|
162 | + // loop thru post_types if set |
|
163 | + $this->_process_WP_Query_post_types($WP_Query); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @param WP_Query $WP_Query |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query) |
|
172 | + { |
|
173 | + $WP_Query->is_espresso_event_single = false; |
|
174 | + $WP_Query->is_espresso_event_archive = false; |
|
175 | + $WP_Query->is_espresso_event_taxonomy = false; |
|
176 | + $WP_Query->is_espresso_venue_single = false; |
|
177 | + $WP_Query->is_espresso_venue_archive = false; |
|
178 | + $WP_Query->is_espresso_venue_taxonomy = false; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @return void |
|
184 | + * @throws EE_Error |
|
185 | + * @throws InvalidArgumentException |
|
186 | + * @throws InvalidDataTypeException |
|
187 | + * @throws InvalidInterfaceException |
|
188 | + */ |
|
189 | + private function _set_CPT_terms() |
|
190 | + { |
|
191 | + if (empty($this->_CPT_terms)) { |
|
192 | + $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
|
193 | + foreach ($terms as $term) { |
|
194 | + if ($term instanceof EE_Term) { |
|
195 | + $this->_CPT_terms[ $term->slug() ] = $term; |
|
196 | + } |
|
197 | + } |
|
198 | + } |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @param WP_Query $WP_Query |
|
204 | + * @return void |
|
205 | + * @throws EE_Error |
|
206 | + * @throws InvalidArgumentException |
|
207 | + * @throws InvalidDataTypeException |
|
208 | + * @throws InvalidInterfaceException |
|
209 | + */ |
|
210 | + private function _set_post_type_for_terms(WP_Query $WP_Query) |
|
211 | + { |
|
212 | + // is a tag set ? |
|
213 | + if (isset($WP_Query->query['tag'])) { |
|
214 | + // get term for tag |
|
215 | + $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']); |
|
216 | + // verify the term |
|
217 | + if ($term instanceof EE_Term) { |
|
218 | + $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type); |
|
219 | + $term->post_type = apply_filters( |
|
220 | + 'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type', |
|
221 | + $term->post_type, |
|
222 | + $term |
|
223 | + ); |
|
224 | + // if a post type is already set |
|
225 | + if (isset($WP_Query->query_vars['post_type'])) { |
|
226 | + // add to existing array |
|
227 | + $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type); |
|
228 | + } |
|
229 | + // just set post_type to our CPT |
|
230 | + $WP_Query->set('post_type', array_unique($term->post_type)); |
|
231 | + } |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * @param WP_Query $WP_Query |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + public function _set_paging($WP_Query) |
|
241 | + { |
|
242 | + if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) { |
|
243 | + $page = get_query_var('page') ? get_query_var('page') : null; |
|
244 | + $paged = get_query_var('paged') ? get_query_var('paged') : $page; |
|
245 | + $WP_Query->set('paged', $paged); |
|
246 | + } |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param \WP_Query $WP_Query |
|
252 | + */ |
|
253 | + protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query) |
|
254 | + { |
|
255 | + // is a taxonomy set ? |
|
256 | + if ($WP_Query->is_tax) { |
|
257 | + // loop thru our taxonomies |
|
258 | + foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
|
259 | + // check if one of our taxonomies is set as a query var |
|
260 | + if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
261 | + // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
|
262 | + foreach ($this->_CPTs as $post_type => $CPT) { |
|
263 | + // verify our CPT has args, is public and has taxonomies set |
|
264 | + if (isset($CPT['args']['public']) |
|
265 | + && $CPT['args']['public'] |
|
266 | + && ! empty($CPT['args']['taxonomies']) |
|
267 | + && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true) |
|
268 | + ) { |
|
269 | + // if so, then add this CPT post_type to the current query's array of post_types' |
|
270 | + $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type']) |
|
271 | + ? (array) $WP_Query->query_vars['post_type'] |
|
272 | + : array(); |
|
273 | + $WP_Query->query_vars['post_type'][] = $post_type; |
|
274 | + switch ($post_type) { |
|
275 | + case 'espresso_events': |
|
276 | + $WP_Query->is_espresso_event_taxonomy = true; |
|
277 | + break; |
|
278 | + case 'espresso_venues': |
|
279 | + $WP_Query->is_espresso_venue_taxonomy = true; |
|
280 | + break; |
|
281 | + default: |
|
282 | + do_action( |
|
283 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
284 | + $WP_Query, |
|
285 | + $this |
|
286 | + ); |
|
287 | + } |
|
288 | + } |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * @param \WP_Query $WP_Query |
|
298 | + * @throws InvalidArgumentException |
|
299 | + * @throws InvalidDataTypeException |
|
300 | + * @throws InvalidInterfaceException |
|
301 | + */ |
|
302 | + protected function _process_WP_Query_post_types(WP_Query $WP_Query) |
|
303 | + { |
|
304 | + if (isset($WP_Query->query_vars['post_type'])) { |
|
305 | + // loop thru post_types as array |
|
306 | + foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
|
307 | + // is current query for an EE CPT ? |
|
308 | + if (isset($this->_CPTs[ $post_type ])) { |
|
309 | + // is EE on or off ? |
|
310 | + if (EE_Maintenance_Mode::instance()->level()) { |
|
311 | + // reroute CPT template view to maintenance_mode.template.php |
|
312 | + if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
313 | + add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
|
314 | + } |
|
315 | + if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
|
316 | + add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1); |
|
317 | + } |
|
318 | + return; |
|
319 | + } |
|
320 | + $this->_generate_CptQueryModifier($WP_Query, $post_type); |
|
321 | + } |
|
322 | + } |
|
323 | + } |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * @param \WP_Query $WP_Query |
|
329 | + * @param string $post_type |
|
330 | + * @throws InvalidArgumentException |
|
331 | + * @throws InvalidDataTypeException |
|
332 | + * @throws InvalidInterfaceException |
|
333 | + */ |
|
334 | + protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type) |
|
335 | + { |
|
336 | + $this->query_modifier = LoaderFactory::getLoader()->getShared( |
|
337 | + 'EventEspresso\core\CPTs\CptQueryModifier', |
|
338 | + array( |
|
339 | + $post_type, |
|
340 | + $this->_CPTs[ $post_type ], |
|
341 | + $WP_Query, |
|
342 | + ) |
|
343 | + ); |
|
344 | + $this->_CPT_taxonomies = $this->query_modifier->taxonomies(); |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * inject_EE_shortcode_placeholder |
|
350 | + * in order to display the M-Mode notice on our CPT routes, |
|
351 | + * we need to first inject what looks like one of our shortcodes, |
|
352 | + * so that it can be replaced with the actual M-Mode notice |
|
353 | + * |
|
354 | + * @return string |
|
355 | + */ |
|
356 | + public function inject_EE_shortcode_placeholder() |
|
357 | + { |
|
358 | + return '[ESPRESSO_'; |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * @deprecated |
|
364 | + * @since 4.8.41 |
|
365 | + * @return void |
|
366 | + */ |
|
367 | + public function _possibly_set_ee_request_var() |
|
368 | + { |
|
369 | + $this->query_modifier->setRequestVarsIfCpt(); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * @deprecated |
|
375 | + * @since 4.8.41 |
|
376 | + * @param $SQL |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public function posts_fields($SQL) |
|
380 | + { |
|
381 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
382 | + return $this->query_modifier->postsFields($SQL); |
|
383 | + } |
|
384 | + return $SQL; |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * @deprecated |
|
390 | + * @since 4.8.41 |
|
391 | + * @param $SQL |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + public function posts_join($SQL) |
|
395 | + { |
|
396 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
397 | + return $this->query_modifier->postsJoin($SQL); |
|
398 | + } |
|
399 | + return $SQL; |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * @deprecated |
|
405 | + * @since 4.8.41 |
|
406 | + * @param \WP_Post[] $posts |
|
407 | + * @return \WP_Post[] |
|
408 | + */ |
|
409 | + public function the_posts($posts) |
|
410 | + { |
|
411 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
412 | + $this->query_modifier->thePosts($posts); |
|
413 | + } |
|
414 | + return $posts; |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + /** |
|
419 | + * @deprecated |
|
420 | + * @since 4.8.41 |
|
421 | + * @param $url |
|
422 | + * @param $ID |
|
423 | + * @return string |
|
424 | + */ |
|
425 | + public function get_edit_post_link($url, $ID) |
|
426 | + { |
|
427 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
428 | + return $this->query_modifier->getEditPostLink($url, $ID); |
|
429 | + } |
|
430 | + return ''; |
|
431 | + } |
|
432 | + |
|
433 | + |
|
434 | + /** |
|
435 | + * @deprecated |
|
436 | + * @since 4.8.41 |
|
437 | + * @param null $WP_Query |
|
438 | + */ |
|
439 | + protected function _do_template_filters($WP_Query = null) |
|
440 | + { |
|
441 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
442 | + $this->query_modifier->addTemplateFilters(); |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * @deprecated |
|
449 | + * @since 4.8.41 |
|
450 | + * @param string $current_template Existing default template path derived for this page call. |
|
451 | + * @return string the path to the full template file. |
|
452 | + */ |
|
453 | + public function single_cpt_template($current_template) |
|
454 | + { |
|
455 | + if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) { |
|
456 | + return $this->query_modifier->singleCptTemplate($current_template); |
|
457 | + } |
|
458 | + return $current_template; |
|
459 | + } |
|
460 | 460 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | CustomTaxonomyDefinitions $taxonomies = null |
73 | 73 | ) { |
74 | 74 | // check if class object is instantiated |
75 | - if (! self::$_instance instanceof EE_CPT_Strategy |
|
75 | + if ( ! self::$_instance instanceof EE_CPT_Strategy |
|
76 | 76 | && $custom_post_types instanceof CustomPostTypeDefinitions |
77 | 77 | && $taxonomies instanceof CustomTaxonomyDefinitions |
78 | 78 | ) { |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | $_CPT_endpoints = array(); |
127 | 127 | if (is_array($this->_CPTs)) { |
128 | 128 | foreach ($this->_CPTs as $CPT_type => $CPT) { |
129 | - $_CPT_endpoints [ $CPT['plural_slug'] ] = $CPT_type; |
|
129 | + $_CPT_endpoints [$CPT['plural_slug']] = $CPT_type; |
|
130 | 130 | } |
131 | 131 | } |
132 | 132 | return $_CPT_endpoints; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | public function pre_get_posts($WP_Query) |
149 | 149 | { |
150 | 150 | // check that post-type is set |
151 | - if (! $WP_Query instanceof WP_Query) { |
|
151 | + if ( ! $WP_Query instanceof WP_Query) { |
|
152 | 152 | return; |
153 | 153 | } |
154 | 154 | // add our conditionals |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | $terms = EEM_Term::instance()->get_all_CPT_post_tags(); |
193 | 193 | foreach ($terms as $term) { |
194 | 194 | if ($term instanceof EE_Term) { |
195 | - $this->_CPT_terms[ $term->slug() ] = $term; |
|
195 | + $this->_CPT_terms[$term->slug()] = $term; |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | } |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | // loop thru our taxonomies |
258 | 258 | foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) { |
259 | 259 | // check if one of our taxonomies is set as a query var |
260 | - if (isset($WP_Query->query[ $CPT_taxonomy ])) { |
|
260 | + if (isset($WP_Query->query[$CPT_taxonomy])) { |
|
261 | 261 | // but which CPT does that correspond to??? hmmm... guess we gotta go looping |
262 | 262 | foreach ($this->_CPTs as $post_type => $CPT) { |
263 | 263 | // verify our CPT has args, is public and has taxonomies set |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | break; |
281 | 281 | default: |
282 | 282 | do_action( |
283 | - 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type', |
|
283 | + 'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_'.$post_type.'_post_type', |
|
284 | 284 | $WP_Query, |
285 | 285 | $this |
286 | 286 | ); |
@@ -305,11 +305,11 @@ discard block |
||
305 | 305 | // loop thru post_types as array |
306 | 306 | foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) { |
307 | 307 | // is current query for an EE CPT ? |
308 | - if (isset($this->_CPTs[ $post_type ])) { |
|
308 | + if (isset($this->_CPTs[$post_type])) { |
|
309 | 309 | // is EE on or off ? |
310 | 310 | if (EE_Maintenance_Mode::instance()->level()) { |
311 | 311 | // reroute CPT template view to maintenance_mode.template.php |
312 | - if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
312 | + if ( ! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) { |
|
313 | 313 | add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999); |
314 | 314 | } |
315 | 315 | if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) { |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | 'EventEspresso\core\CPTs\CptQueryModifier', |
338 | 338 | array( |
339 | 339 | $post_type, |
340 | - $this->_CPTs[ $post_type ], |
|
340 | + $this->_CPTs[$post_type], |
|
341 | 341 | $WP_Query, |
342 | 342 | ) |
343 | 343 | ); |
@@ -16,16 +16,16 @@ |
||
16 | 16 | */ |
17 | 17 | class URLValidator |
18 | 18 | { |
19 | - /** |
|
20 | - * Returns whether or not the URL is valid |
|
21 | - * @since 4.9.68.p |
|
22 | - * @param $url |
|
23 | - * @return boolean |
|
24 | - */ |
|
25 | - public function isValid($url) |
|
26 | - { |
|
27 | - return esc_url_raw($url) === $url; |
|
28 | - } |
|
19 | + /** |
|
20 | + * Returns whether or not the URL is valid |
|
21 | + * @since 4.9.68.p |
|
22 | + * @param $url |
|
23 | + * @return boolean |
|
24 | + */ |
|
25 | + public function isValid($url) |
|
26 | + { |
|
27 | + return esc_url_raw($url) === $url; |
|
28 | + } |
|
29 | 29 | } |
30 | 30 | // End of file URLValidator.php |
31 | 31 | // Location: ${NAMESPACE}/URLValidator.php |
@@ -17,43 +17,43 @@ |
||
17 | 17 | class Attendee extends AttendeeCalculationsBase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @param array $wpdb_row |
|
22 | - * @param WP_REST_Request $request |
|
23 | - * @param AttendeeControllerBase $controller |
|
24 | - * @since 4.9.66.p |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public function userAvatar(array $wpdb_row, WP_REST_Request $request, AttendeeControllerBase $controller) |
|
28 | - { |
|
29 | - if (is_array($wpdb_row) && isset($wpdb_row['Attendee_Meta.ATT_email'])) { |
|
30 | - $email_address = $wpdb_row['Attendee_Meta.ATT_email']; |
|
31 | - } |
|
32 | - if (empty($email_address)) { |
|
33 | - return ''; |
|
34 | - } |
|
35 | - $avatar = get_avatar_url($email_address); |
|
36 | - return $avatar ? $avatar : ''; |
|
37 | - } |
|
20 | + /** |
|
21 | + * @param array $wpdb_row |
|
22 | + * @param WP_REST_Request $request |
|
23 | + * @param AttendeeControllerBase $controller |
|
24 | + * @since 4.9.66.p |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public function userAvatar(array $wpdb_row, WP_REST_Request $request, AttendeeControllerBase $controller) |
|
28 | + { |
|
29 | + if (is_array($wpdb_row) && isset($wpdb_row['Attendee_Meta.ATT_email'])) { |
|
30 | + $email_address = $wpdb_row['Attendee_Meta.ATT_email']; |
|
31 | + } |
|
32 | + if (empty($email_address)) { |
|
33 | + return ''; |
|
34 | + } |
|
35 | + $avatar = get_avatar_url($email_address); |
|
36 | + return $avatar ? $avatar : ''; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Provides an array for all the calculations possible that outlines a json schema for those calculations. |
|
42 | - * Array is indexed by calculation (snake case) and value is the schema for that calculation. |
|
43 | - * |
|
44 | - * @since 4.9.68.p |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function schemaForCalculations() |
|
48 | - { |
|
49 | - return array( |
|
50 | - 'user_avatar' => array( |
|
51 | - 'description' => esc_html__( |
|
52 | - 'The avatar url for the attendee (if available).', |
|
53 | - 'event_espresso' |
|
54 | - ), |
|
55 | - 'type' => 'string', |
|
56 | - ), |
|
57 | - ); |
|
58 | - } |
|
40 | + /** |
|
41 | + * Provides an array for all the calculations possible that outlines a json schema for those calculations. |
|
42 | + * Array is indexed by calculation (snake case) and value is the schema for that calculation. |
|
43 | + * |
|
44 | + * @since 4.9.68.p |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function schemaForCalculations() |
|
48 | + { |
|
49 | + return array( |
|
50 | + 'user_avatar' => array( |
|
51 | + 'description' => esc_html__( |
|
52 | + 'The avatar url for the attendee (if available).', |
|
53 | + 'event_espresso' |
|
54 | + ), |
|
55 | + 'type' => 'string', |
|
56 | + ), |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | } |