@@ -18,310 +18,310 @@ |
||
18 | 18 | class RegFormHandler |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var EE_Checkout |
|
23 | - */ |
|
24 | - public $checkout; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var RegFormInputHandler |
|
28 | - */ |
|
29 | - public $input_handler; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - private $non_input_form_sections; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var RegFormAttendeeFactory |
|
38 | - */ |
|
39 | - private $attendee_factory; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var RegistrantData |
|
43 | - */ |
|
44 | - private $registrant_data; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var EE_Registration_Processor |
|
48 | - */ |
|
49 | - private $registration_processor; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var bool |
|
53 | - */ |
|
54 | - private $valid; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * RegFormHandler constructor. |
|
59 | - */ |
|
60 | - public function __construct( |
|
61 | - EE_Checkout $checkout, |
|
62 | - RegistrantData $registrant_data, |
|
63 | - RegFormAttendeeFactory $attendee_factory, |
|
64 | - EE_Registration_Processor $registration_processor |
|
65 | - ) { |
|
66 | - $this->checkout = $checkout; |
|
67 | - $this->registrant_data = $registrant_data; |
|
68 | - $this->attendee_factory = $attendee_factory; |
|
69 | - $this->registration_processor = $registration_processor; |
|
70 | - // reg form sections that do not contain inputs |
|
71 | - $this->non_input_form_sections = [ |
|
72 | - 'primary_registrant_data', |
|
73 | - 'additional_attendee_reg_info', |
|
74 | - 'spco_copy_attendee_chk', |
|
75 | - ]; |
|
76 | - $this->initializeInputHandler(); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - private function initializeInputHandler() |
|
81 | - { |
|
82 | - $reg_form = $this->checkout->current_step->reg_form; |
|
83 | - $required_questions = $reg_form instanceof RegForm ? $reg_form->requiredQuestions() : []; |
|
84 | - $this->input_handler = LoaderFactory::getShared( |
|
85 | - RegFormInputHandler::class, |
|
86 | - [ $this->checkout->reg_url_link, $required_questions ] |
|
87 | - ); |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @return int |
|
94 | - */ |
|
95 | - public function attendeeCount(): int |
|
96 | - { |
|
97 | - return $this->registrant_data->attendeeCount(); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - private function isInvalid(): bool |
|
105 | - { |
|
106 | - $this->valid = false; |
|
107 | - return $this->valid; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @param EE_Registration[] $registrations |
|
113 | - * @param array[][] $reg_form_data |
|
114 | - * @return bool |
|
115 | - * @throws EntityNotFoundException |
|
116 | - * @throws EE_Error |
|
117 | - * @throws InvalidArgumentException |
|
118 | - * @throws ReflectionException |
|
119 | - * @throws RuntimeException |
|
120 | - * @throws InvalidDataTypeException |
|
121 | - * @throws InvalidInterfaceException |
|
122 | - */ |
|
123 | - public function processRegistrations(array $registrations, array $reg_form_data): bool |
|
124 | - { |
|
125 | - // start off optimistic, then trip this to false if anything goes wrong |
|
126 | - $this->valid = true; |
|
127 | - foreach ($registrations as $registration) { |
|
128 | - // verify EE_Registration object |
|
129 | - if (! $this->isValidRegistration($registration)) { |
|
130 | - return $this->isInvalid(); |
|
131 | - } |
|
132 | - $reg_url_link = $registration->reg_url_link(); |
|
133 | - // reg_url_link exists ? |
|
134 | - if (! $this->isValidRegUrlLink($reg_url_link)) { |
|
135 | - return $this->isInvalid(); |
|
136 | - } |
|
137 | - // should this registration be processed during this visit ? |
|
138 | - if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
139 | - continue; |
|
140 | - } |
|
141 | - // if NOT revisiting, then let's save the registration now, |
|
142 | - // so that we have a REG_ID to use when generating other objects |
|
143 | - if (! $this->checkout->revisit) { |
|
144 | - $registration->save(); |
|
145 | - } |
|
146 | - /** |
|
147 | - * This allows plugins to trigger a fail on processing of a |
|
148 | - * registration for any conditions they may have for it to pass. |
|
149 | - * |
|
150 | - * @var bool if true is returned by the plugin then the registration processing is halted. |
|
151 | - */ |
|
152 | - if ( |
|
153 | - apply_filters( |
|
154 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
155 | - false, |
|
156 | - $this->registrant_data->attendeeCount(), |
|
157 | - $registration, |
|
158 | - $registrations, |
|
159 | - $reg_form_data, |
|
160 | - $this |
|
161 | - ) |
|
162 | - ) { |
|
163 | - return $this->isInvalid(); |
|
164 | - } |
|
165 | - |
|
166 | - // Houston, we have a registration! |
|
167 | - if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) { |
|
168 | - return $this->isInvalid(); |
|
169 | - } |
|
170 | - } |
|
171 | - return $this->valid; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @param string $reg_url_link |
|
177 | - * @return bool |
|
178 | - */ |
|
179 | - private function isValidRegUrlLink(string $reg_url_link): bool |
|
180 | - { |
|
181 | - if (! empty($reg_url_link)) { |
|
182 | - return true; |
|
183 | - } |
|
184 | - EE_Error::add_error( |
|
185 | - esc_html__( |
|
186 | - 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
187 | - 'event_espresso' |
|
188 | - ), |
|
189 | - __FILE__, |
|
190 | - __FUNCTION__, |
|
191 | - __LINE__ |
|
192 | - ); |
|
193 | - return false; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param EE_Registration $registration |
|
199 | - * @return bool |
|
200 | - */ |
|
201 | - private function isValidRegistration(EE_Registration $registration): bool |
|
202 | - { |
|
203 | - // verify EE_Registration object |
|
204 | - if ($registration instanceof EE_Registration) { |
|
205 | - return true; |
|
206 | - } |
|
207 | - EE_Error::add_error( |
|
208 | - esc_html__( |
|
209 | - 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
210 | - 'event_espresso' |
|
211 | - ), |
|
212 | - __FILE__, |
|
213 | - __FUNCTION__, |
|
214 | - __LINE__ |
|
215 | - ); |
|
216 | - return false; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @param EE_Registration $registration |
|
222 | - * @param string $reg_url_link |
|
223 | - * @param array[][] $reg_form_data |
|
224 | - * @return bool |
|
225 | - * @throws EE_Error |
|
226 | - * @throws ReflectionException |
|
227 | - */ |
|
228 | - private function processRegistration( |
|
229 | - EE_Registration $registration, |
|
230 | - string $reg_url_link, |
|
231 | - array $reg_form_data |
|
232 | - ): bool { |
|
233 | - $this->registrant_data->initializeRegistrantData($registration); |
|
234 | - if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) { |
|
235 | - return false; |
|
236 | - } |
|
237 | - // RegFormAttendeeFactory |
|
238 | - if (! $this->attendee_factory->create($registration, $reg_url_link)) { |
|
239 | - return false; |
|
240 | - } |
|
241 | - // at this point, we should have enough details about the registrant to consider the registration |
|
242 | - // NOT incomplete |
|
243 | - $this->registration_processor->toggle_incomplete_registration_status_to_default( |
|
244 | - $registration, |
|
245 | - false, |
|
246 | - new Context( |
|
247 | - 'spco_reg_step_attendee_information_process_registrations', |
|
248 | - esc_html__( |
|
249 | - 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
250 | - 'event_espresso' |
|
251 | - ) |
|
252 | - ) |
|
253 | - ); |
|
254 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
255 | - // abandoned |
|
256 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
257 | - // if we've gotten this far, then let's save what we have |
|
258 | - $registration->save(); |
|
259 | - // add relation between TXN and registration |
|
260 | - $this->associateRegistrationWithTransaction($registration); |
|
261 | - return true; |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @param EE_Registration $registration |
|
267 | - * @param string $reg_url_link |
|
268 | - * @param array $reg_form_data |
|
269 | - * @return bool |
|
270 | - * @throws EE_Error |
|
271 | - * @throws ReflectionException |
|
272 | - */ |
|
273 | - private function processRegFormData(EE_Registration $registration, string $reg_url_link, array $reg_form_data): bool |
|
274 | - { |
|
275 | - if (isset($reg_form_data[ $reg_url_link ])) { |
|
276 | - // do we need to copy basic info from primary attendee ? |
|
277 | - $copy_primary = isset($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
278 | - && absint($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
279 | - $this->registrant_data->setCopyPrimary($copy_primary); |
|
280 | - // filter form input data for this registration |
|
281 | - $reg_form_data[ $reg_url_link ] = (array) apply_filters( |
|
282 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
283 | - $reg_form_data[ $reg_url_link ] |
|
284 | - ); |
|
285 | - if (isset($reg_form_data['primary_attendee'])) { |
|
286 | - $primary_reg_url_link = $reg_form_data['primary_attendee'] ?? ''; |
|
287 | - $this->registrant_data->addPrimaryRegistrantDataValue('reg_url_link', $primary_reg_url_link); |
|
288 | - unset($reg_form_data['primary_attendee']); |
|
289 | - } |
|
290 | - // now loop through our array of valid post data && process attendee reg forms |
|
291 | - foreach ($reg_form_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
292 | - if (in_array($form_section, $this->non_input_form_sections, true)) { |
|
293 | - continue; |
|
294 | - } |
|
295 | - foreach ($form_inputs as $form_input => $input_value) { |
|
296 | - $input_processed = $this->input_handler->processFormInput( |
|
297 | - $registration, |
|
298 | - $reg_url_link, |
|
299 | - $form_input, |
|
300 | - $input_value |
|
301 | - ); |
|
302 | - if (! $input_processed) { |
|
303 | - return false; |
|
304 | - } |
|
305 | - } |
|
306 | - } |
|
307 | - } |
|
308 | - return true; |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * @param EE_Registration $registration |
|
314 | - * @return void |
|
315 | - * @throws EE_Error |
|
316 | - * @throws InvalidArgumentException |
|
317 | - * @throws ReflectionException |
|
318 | - * @throws InvalidDataTypeException |
|
319 | - * @throws InvalidInterfaceException |
|
320 | - */ |
|
321 | - private function associateRegistrationWithTransaction(EE_Registration $registration) |
|
322 | - { |
|
323 | - // add relation to registration |
|
324 | - $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
325 | - $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
326 | - } |
|
21 | + /** |
|
22 | + * @var EE_Checkout |
|
23 | + */ |
|
24 | + public $checkout; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var RegFormInputHandler |
|
28 | + */ |
|
29 | + public $input_handler; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + private $non_input_form_sections; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var RegFormAttendeeFactory |
|
38 | + */ |
|
39 | + private $attendee_factory; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var RegistrantData |
|
43 | + */ |
|
44 | + private $registrant_data; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var EE_Registration_Processor |
|
48 | + */ |
|
49 | + private $registration_processor; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var bool |
|
53 | + */ |
|
54 | + private $valid; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * RegFormHandler constructor. |
|
59 | + */ |
|
60 | + public function __construct( |
|
61 | + EE_Checkout $checkout, |
|
62 | + RegistrantData $registrant_data, |
|
63 | + RegFormAttendeeFactory $attendee_factory, |
|
64 | + EE_Registration_Processor $registration_processor |
|
65 | + ) { |
|
66 | + $this->checkout = $checkout; |
|
67 | + $this->registrant_data = $registrant_data; |
|
68 | + $this->attendee_factory = $attendee_factory; |
|
69 | + $this->registration_processor = $registration_processor; |
|
70 | + // reg form sections that do not contain inputs |
|
71 | + $this->non_input_form_sections = [ |
|
72 | + 'primary_registrant_data', |
|
73 | + 'additional_attendee_reg_info', |
|
74 | + 'spco_copy_attendee_chk', |
|
75 | + ]; |
|
76 | + $this->initializeInputHandler(); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + private function initializeInputHandler() |
|
81 | + { |
|
82 | + $reg_form = $this->checkout->current_step->reg_form; |
|
83 | + $required_questions = $reg_form instanceof RegForm ? $reg_form->requiredQuestions() : []; |
|
84 | + $this->input_handler = LoaderFactory::getShared( |
|
85 | + RegFormInputHandler::class, |
|
86 | + [ $this->checkout->reg_url_link, $required_questions ] |
|
87 | + ); |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @return int |
|
94 | + */ |
|
95 | + public function attendeeCount(): int |
|
96 | + { |
|
97 | + return $this->registrant_data->attendeeCount(); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + private function isInvalid(): bool |
|
105 | + { |
|
106 | + $this->valid = false; |
|
107 | + return $this->valid; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @param EE_Registration[] $registrations |
|
113 | + * @param array[][] $reg_form_data |
|
114 | + * @return bool |
|
115 | + * @throws EntityNotFoundException |
|
116 | + * @throws EE_Error |
|
117 | + * @throws InvalidArgumentException |
|
118 | + * @throws ReflectionException |
|
119 | + * @throws RuntimeException |
|
120 | + * @throws InvalidDataTypeException |
|
121 | + * @throws InvalidInterfaceException |
|
122 | + */ |
|
123 | + public function processRegistrations(array $registrations, array $reg_form_data): bool |
|
124 | + { |
|
125 | + // start off optimistic, then trip this to false if anything goes wrong |
|
126 | + $this->valid = true; |
|
127 | + foreach ($registrations as $registration) { |
|
128 | + // verify EE_Registration object |
|
129 | + if (! $this->isValidRegistration($registration)) { |
|
130 | + return $this->isInvalid(); |
|
131 | + } |
|
132 | + $reg_url_link = $registration->reg_url_link(); |
|
133 | + // reg_url_link exists ? |
|
134 | + if (! $this->isValidRegUrlLink($reg_url_link)) { |
|
135 | + return $this->isInvalid(); |
|
136 | + } |
|
137 | + // should this registration be processed during this visit ? |
|
138 | + if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
139 | + continue; |
|
140 | + } |
|
141 | + // if NOT revisiting, then let's save the registration now, |
|
142 | + // so that we have a REG_ID to use when generating other objects |
|
143 | + if (! $this->checkout->revisit) { |
|
144 | + $registration->save(); |
|
145 | + } |
|
146 | + /** |
|
147 | + * This allows plugins to trigger a fail on processing of a |
|
148 | + * registration for any conditions they may have for it to pass. |
|
149 | + * |
|
150 | + * @var bool if true is returned by the plugin then the registration processing is halted. |
|
151 | + */ |
|
152 | + if ( |
|
153 | + apply_filters( |
|
154 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
155 | + false, |
|
156 | + $this->registrant_data->attendeeCount(), |
|
157 | + $registration, |
|
158 | + $registrations, |
|
159 | + $reg_form_data, |
|
160 | + $this |
|
161 | + ) |
|
162 | + ) { |
|
163 | + return $this->isInvalid(); |
|
164 | + } |
|
165 | + |
|
166 | + // Houston, we have a registration! |
|
167 | + if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) { |
|
168 | + return $this->isInvalid(); |
|
169 | + } |
|
170 | + } |
|
171 | + return $this->valid; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @param string $reg_url_link |
|
177 | + * @return bool |
|
178 | + */ |
|
179 | + private function isValidRegUrlLink(string $reg_url_link): bool |
|
180 | + { |
|
181 | + if (! empty($reg_url_link)) { |
|
182 | + return true; |
|
183 | + } |
|
184 | + EE_Error::add_error( |
|
185 | + esc_html__( |
|
186 | + 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
187 | + 'event_espresso' |
|
188 | + ), |
|
189 | + __FILE__, |
|
190 | + __FUNCTION__, |
|
191 | + __LINE__ |
|
192 | + ); |
|
193 | + return false; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param EE_Registration $registration |
|
199 | + * @return bool |
|
200 | + */ |
|
201 | + private function isValidRegistration(EE_Registration $registration): bool |
|
202 | + { |
|
203 | + // verify EE_Registration object |
|
204 | + if ($registration instanceof EE_Registration) { |
|
205 | + return true; |
|
206 | + } |
|
207 | + EE_Error::add_error( |
|
208 | + esc_html__( |
|
209 | + 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
210 | + 'event_espresso' |
|
211 | + ), |
|
212 | + __FILE__, |
|
213 | + __FUNCTION__, |
|
214 | + __LINE__ |
|
215 | + ); |
|
216 | + return false; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @param EE_Registration $registration |
|
222 | + * @param string $reg_url_link |
|
223 | + * @param array[][] $reg_form_data |
|
224 | + * @return bool |
|
225 | + * @throws EE_Error |
|
226 | + * @throws ReflectionException |
|
227 | + */ |
|
228 | + private function processRegistration( |
|
229 | + EE_Registration $registration, |
|
230 | + string $reg_url_link, |
|
231 | + array $reg_form_data |
|
232 | + ): bool { |
|
233 | + $this->registrant_data->initializeRegistrantData($registration); |
|
234 | + if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) { |
|
235 | + return false; |
|
236 | + } |
|
237 | + // RegFormAttendeeFactory |
|
238 | + if (! $this->attendee_factory->create($registration, $reg_url_link)) { |
|
239 | + return false; |
|
240 | + } |
|
241 | + // at this point, we should have enough details about the registrant to consider the registration |
|
242 | + // NOT incomplete |
|
243 | + $this->registration_processor->toggle_incomplete_registration_status_to_default( |
|
244 | + $registration, |
|
245 | + false, |
|
246 | + new Context( |
|
247 | + 'spco_reg_step_attendee_information_process_registrations', |
|
248 | + esc_html__( |
|
249 | + 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
250 | + 'event_espresso' |
|
251 | + ) |
|
252 | + ) |
|
253 | + ); |
|
254 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
255 | + // abandoned |
|
256 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
257 | + // if we've gotten this far, then let's save what we have |
|
258 | + $registration->save(); |
|
259 | + // add relation between TXN and registration |
|
260 | + $this->associateRegistrationWithTransaction($registration); |
|
261 | + return true; |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @param EE_Registration $registration |
|
267 | + * @param string $reg_url_link |
|
268 | + * @param array $reg_form_data |
|
269 | + * @return bool |
|
270 | + * @throws EE_Error |
|
271 | + * @throws ReflectionException |
|
272 | + */ |
|
273 | + private function processRegFormData(EE_Registration $registration, string $reg_url_link, array $reg_form_data): bool |
|
274 | + { |
|
275 | + if (isset($reg_form_data[ $reg_url_link ])) { |
|
276 | + // do we need to copy basic info from primary attendee ? |
|
277 | + $copy_primary = isset($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
278 | + && absint($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
279 | + $this->registrant_data->setCopyPrimary($copy_primary); |
|
280 | + // filter form input data for this registration |
|
281 | + $reg_form_data[ $reg_url_link ] = (array) apply_filters( |
|
282 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
283 | + $reg_form_data[ $reg_url_link ] |
|
284 | + ); |
|
285 | + if (isset($reg_form_data['primary_attendee'])) { |
|
286 | + $primary_reg_url_link = $reg_form_data['primary_attendee'] ?? ''; |
|
287 | + $this->registrant_data->addPrimaryRegistrantDataValue('reg_url_link', $primary_reg_url_link); |
|
288 | + unset($reg_form_data['primary_attendee']); |
|
289 | + } |
|
290 | + // now loop through our array of valid post data && process attendee reg forms |
|
291 | + foreach ($reg_form_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
292 | + if (in_array($form_section, $this->non_input_form_sections, true)) { |
|
293 | + continue; |
|
294 | + } |
|
295 | + foreach ($form_inputs as $form_input => $input_value) { |
|
296 | + $input_processed = $this->input_handler->processFormInput( |
|
297 | + $registration, |
|
298 | + $reg_url_link, |
|
299 | + $form_input, |
|
300 | + $input_value |
|
301 | + ); |
|
302 | + if (! $input_processed) { |
|
303 | + return false; |
|
304 | + } |
|
305 | + } |
|
306 | + } |
|
307 | + } |
|
308 | + return true; |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * @param EE_Registration $registration |
|
314 | + * @return void |
|
315 | + * @throws EE_Error |
|
316 | + * @throws InvalidArgumentException |
|
317 | + * @throws ReflectionException |
|
318 | + * @throws InvalidDataTypeException |
|
319 | + * @throws InvalidInterfaceException |
|
320 | + */ |
|
321 | + private function associateRegistrationWithTransaction(EE_Registration $registration) |
|
322 | + { |
|
323 | + // add relation to registration |
|
324 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
325 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
326 | + } |
|
327 | 327 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $required_questions = $reg_form instanceof RegForm ? $reg_form->requiredQuestions() : []; |
84 | 84 | $this->input_handler = LoaderFactory::getShared( |
85 | 85 | RegFormInputHandler::class, |
86 | - [ $this->checkout->reg_url_link, $required_questions ] |
|
86 | + [$this->checkout->reg_url_link, $required_questions] |
|
87 | 87 | ); |
88 | 88 | |
89 | 89 | } |
@@ -126,21 +126,21 @@ discard block |
||
126 | 126 | $this->valid = true; |
127 | 127 | foreach ($registrations as $registration) { |
128 | 128 | // verify EE_Registration object |
129 | - if (! $this->isValidRegistration($registration)) { |
|
129 | + if ( ! $this->isValidRegistration($registration)) { |
|
130 | 130 | return $this->isInvalid(); |
131 | 131 | } |
132 | 132 | $reg_url_link = $registration->reg_url_link(); |
133 | 133 | // reg_url_link exists ? |
134 | - if (! $this->isValidRegUrlLink($reg_url_link)) { |
|
134 | + if ( ! $this->isValidRegUrlLink($reg_url_link)) { |
|
135 | 135 | return $this->isInvalid(); |
136 | 136 | } |
137 | 137 | // should this registration be processed during this visit ? |
138 | - if (! $this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
138 | + if ( ! $this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
139 | 139 | continue; |
140 | 140 | } |
141 | 141 | // if NOT revisiting, then let's save the registration now, |
142 | 142 | // so that we have a REG_ID to use when generating other objects |
143 | - if (! $this->checkout->revisit) { |
|
143 | + if ( ! $this->checkout->revisit) { |
|
144 | 144 | $registration->save(); |
145 | 145 | } |
146 | 146 | /** |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | } |
165 | 165 | |
166 | 166 | // Houston, we have a registration! |
167 | - if (! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) { |
|
167 | + if ( ! $this->processRegistration($registration, $reg_url_link, $reg_form_data)) { |
|
168 | 168 | return $this->isInvalid(); |
169 | 169 | } |
170 | 170 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | */ |
179 | 179 | private function isValidRegUrlLink(string $reg_url_link): bool |
180 | 180 | { |
181 | - if (! empty($reg_url_link)) { |
|
181 | + if ( ! empty($reg_url_link)) { |
|
182 | 182 | return true; |
183 | 183 | } |
184 | 184 | EE_Error::add_error( |
@@ -231,11 +231,11 @@ discard block |
||
231 | 231 | array $reg_form_data |
232 | 232 | ): bool { |
233 | 233 | $this->registrant_data->initializeRegistrantData($registration); |
234 | - if (! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) { |
|
234 | + if ( ! $this->processRegFormData($registration, $reg_url_link, $reg_form_data)) { |
|
235 | 235 | return false; |
236 | 236 | } |
237 | 237 | // RegFormAttendeeFactory |
238 | - if (! $this->attendee_factory->create($registration, $reg_url_link)) { |
|
238 | + if ( ! $this->attendee_factory->create($registration, $reg_url_link)) { |
|
239 | 239 | return false; |
240 | 240 | } |
241 | 241 | // at this point, we should have enough details about the registrant to consider the registration |
@@ -272,15 +272,15 @@ discard block |
||
272 | 272 | */ |
273 | 273 | private function processRegFormData(EE_Registration $registration, string $reg_url_link, array $reg_form_data): bool |
274 | 274 | { |
275 | - if (isset($reg_form_data[ $reg_url_link ])) { |
|
275 | + if (isset($reg_form_data[$reg_url_link])) { |
|
276 | 276 | // do we need to copy basic info from primary attendee ? |
277 | - $copy_primary = isset($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
278 | - && absint($reg_form_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
277 | + $copy_primary = isset($reg_form_data[$reg_url_link]['additional_attendee_reg_info']) |
|
278 | + && absint($reg_form_data[$reg_url_link]['additional_attendee_reg_info']) === 0; |
|
279 | 279 | $this->registrant_data->setCopyPrimary($copy_primary); |
280 | 280 | // filter form input data for this registration |
281 | - $reg_form_data[ $reg_url_link ] = (array) apply_filters( |
|
281 | + $reg_form_data[$reg_url_link] = (array) apply_filters( |
|
282 | 282 | 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
283 | - $reg_form_data[ $reg_url_link ] |
|
283 | + $reg_form_data[$reg_url_link] |
|
284 | 284 | ); |
285 | 285 | if (isset($reg_form_data['primary_attendee'])) { |
286 | 286 | $primary_reg_url_link = $reg_form_data['primary_attendee'] ?? ''; |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | unset($reg_form_data['primary_attendee']); |
289 | 289 | } |
290 | 290 | // now loop through our array of valid post data && process attendee reg forms |
291 | - foreach ($reg_form_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
291 | + foreach ($reg_form_data[$reg_url_link] as $form_section => $form_inputs) { |
|
292 | 292 | if (in_array($form_section, $this->non_input_form_sections, true)) { |
293 | 293 | continue; |
294 | 294 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | $form_input, |
300 | 300 | $input_value |
301 | 301 | ); |
302 | - if (! $input_processed) { |
|
302 | + if ( ! $input_processed) { |
|
303 | 303 | return false; |
304 | 304 | } |
305 | 305 | } |
@@ -9,39 +9,39 @@ |
||
9 | 9 | |
10 | 10 | class PrivacyConsentCheckboxForm extends EE_Form_Section_Proper |
11 | 11 | { |
12 | - /** |
|
13 | - * @param string $reg_step_slug |
|
14 | - * @param string $consent_checkbox_label_text |
|
15 | - * @throws EE_Error |
|
16 | - */ |
|
17 | - public function __construct(string $reg_step_slug, string $consent_checkbox_label_text) |
|
18 | - { |
|
19 | - parent::__construct( |
|
20 | - [ |
|
21 | - 'layout_strategy' => |
|
22 | - new EE_Template_Layout( |
|
23 | - [ |
|
24 | - 'input_template_file' => SPCO_REG_STEPS_PATH |
|
25 | - . $reg_step_slug |
|
26 | - . '/privacy_consent.template.php', |
|
27 | - ] |
|
28 | - ), |
|
29 | - 'subsections' => [ |
|
30 | - 'consent' => new EE_Checkbox_Multi_Input( |
|
31 | - [ |
|
32 | - 'consent' => $consent_checkbox_label_text, |
|
33 | - ], |
|
34 | - [ |
|
35 | - 'required' => true, |
|
36 | - 'required_validation_error_message' => esc_html__( |
|
37 | - 'You must consent to these terms in order to register.', |
|
38 | - 'event_espresso' |
|
39 | - ), |
|
40 | - 'html_label_text' => '', |
|
41 | - ] |
|
42 | - ), |
|
43 | - ], |
|
44 | - ] |
|
45 | - ); |
|
46 | - } |
|
12 | + /** |
|
13 | + * @param string $reg_step_slug |
|
14 | + * @param string $consent_checkbox_label_text |
|
15 | + * @throws EE_Error |
|
16 | + */ |
|
17 | + public function __construct(string $reg_step_slug, string $consent_checkbox_label_text) |
|
18 | + { |
|
19 | + parent::__construct( |
|
20 | + [ |
|
21 | + 'layout_strategy' => |
|
22 | + new EE_Template_Layout( |
|
23 | + [ |
|
24 | + 'input_template_file' => SPCO_REG_STEPS_PATH |
|
25 | + . $reg_step_slug |
|
26 | + . '/privacy_consent.template.php', |
|
27 | + ] |
|
28 | + ), |
|
29 | + 'subsections' => [ |
|
30 | + 'consent' => new EE_Checkbox_Multi_Input( |
|
31 | + [ |
|
32 | + 'consent' => $consent_checkbox_label_text, |
|
33 | + ], |
|
34 | + [ |
|
35 | + 'required' => true, |
|
36 | + 'required_validation_error_message' => esc_html__( |
|
37 | + 'You must consent to these terms in order to register.', |
|
38 | + 'event_espresso' |
|
39 | + ), |
|
40 | + 'html_label_text' => '', |
|
41 | + ] |
|
42 | + ), |
|
43 | + ], |
|
44 | + ] |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | } |
@@ -19,354 +19,354 @@ |
||
19 | 19 | class RegistrantData |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var int |
|
24 | - */ |
|
25 | - private $attendee_counter = 0; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - private $registrant_data = []; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var bool |
|
34 | - */ |
|
35 | - private $copy_primary = false; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - private $required_questions = []; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Registration[] |
|
44 | - */ |
|
45 | - private $registrations = []; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var EE_Answer[][] |
|
49 | - */ |
|
50 | - private $registrant_answers = []; |
|
51 | - |
|
52 | - /** |
|
53 | - * array for tracking reg form data for the primary registrant |
|
54 | - * |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - private $primary_registrant_data; |
|
58 | - |
|
59 | - /** |
|
60 | - * the attendee object created for the primary registrant |
|
61 | - * |
|
62 | - * @var EE_Attendee |
|
63 | - */ |
|
64 | - private $primary_registrant; |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * RegistrantData constructor. |
|
69 | - */ |
|
70 | - public function __construct() |
|
71 | - { |
|
72 | - $this->primary_registrant_data = ['line_item_id' => null,]; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @param EE_Registration $registration |
|
78 | - * @throws EE_Error |
|
79 | - */ |
|
80 | - public function initializeRegistrantData(EE_Registration $registration): void |
|
81 | - { |
|
82 | - $reg_url_link = $registration->reg_url_link(); |
|
83 | - $this->registrations[ $reg_url_link ] = $registration; |
|
84 | - $this->registrant_answers[ $reg_url_link ] = $registration->answers(); |
|
85 | - $this->registrant_data[ $reg_url_link ] = []; |
|
86 | - $this->attendee_counter++; |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * @return int |
|
92 | - */ |
|
93 | - public function attendeeCount(): int |
|
94 | - { |
|
95 | - return $this->attendee_counter; |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - public function copyPrimary(): bool |
|
103 | - { |
|
104 | - return $this->copy_primary; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @param bool $copy_primary |
|
110 | - */ |
|
111 | - public function setCopyPrimary(bool $copy_primary): void |
|
112 | - { |
|
113 | - $this->copy_primary = filter_var($copy_primary, FILTER_VALIDATE_BOOLEAN); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @param string $reg_url_link |
|
119 | - * @return array|null |
|
120 | - */ |
|
121 | - public function getRegistrant(string $reg_url_link): ?EE_Registration |
|
122 | - { |
|
123 | - return $this->registrations[ $reg_url_link ] ?? null; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param string $reg_url_link |
|
129 | - * @return array|null |
|
130 | - */ |
|
131 | - public function getRegistrantData(string $reg_url_link): ?array |
|
132 | - { |
|
133 | - return $this->registrant_data[ $reg_url_link ] ?? null; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param string $reg_url_link |
|
139 | - * @param string $key |
|
140 | - * @param mixed $value |
|
141 | - */ |
|
142 | - public function addRegistrantDataValue(string $reg_url_link, string $key, $value): void |
|
143 | - { |
|
144 | - $this->registrant_data[ $reg_url_link ][ $key ] = $value; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * ensures that all attendees at least have data for first name, last name, and email address |
|
150 | - * |
|
151 | - * @param string $reg_url_link |
|
152 | - * @throws EE_Error |
|
153 | - * @throws ReflectionException |
|
154 | - */ |
|
155 | - public function ensureCriticalRegistrantDataIsSet(string $reg_url_link): void { |
|
156 | - if ($this->currentRegistrantIsPrimary()) { |
|
157 | - return; |
|
158 | - } |
|
159 | - // bare minimum critical details include first name, last name, email address |
|
160 | - $critical_attendee_details = ['ATT_fname', 'ATT_lname', 'ATT_email']; |
|
161 | - // add address info to critical details? |
|
162 | - if ( |
|
163 | - apply_filters( |
|
164 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
165 | - false |
|
166 | - ) |
|
167 | - ) { |
|
168 | - $critical_attendee_details += [ |
|
169 | - 'ATT_address', |
|
170 | - 'ATT_address2', |
|
171 | - 'ATT_city', |
|
172 | - 'STA_ID', |
|
173 | - 'CNT_ISO', |
|
174 | - 'ATT_zip', |
|
175 | - 'ATT_phone', |
|
176 | - ]; |
|
177 | - } |
|
178 | - foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
179 | - if ( |
|
180 | - ! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
181 | - || empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
182 | - ) { |
|
183 | - $this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get( |
|
184 | - $critical_attendee_detail |
|
185 | - ); |
|
186 | - } |
|
187 | - } |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @param string $reg_url_link |
|
193 | - * @param array $registrant_data |
|
194 | - */ |
|
195 | - public function setRegistrantData(string $reg_url_link, array $registrant_data): void |
|
196 | - { |
|
197 | - $this->registrant_data[ $reg_url_link ] = $registrant_data; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function getRequiredQuestions(): array |
|
205 | - { |
|
206 | - return $this->required_questions; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * @param string $identifier |
|
212 | - * @param string $required_question |
|
213 | - */ |
|
214 | - public function addRequiredQuestion(string $identifier, string $required_question): void |
|
215 | - { |
|
216 | - $this->required_questions[ $identifier ] = $required_question; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * @return EE_Answer[] |
|
222 | - */ |
|
223 | - public function registrantAnswers(string $reg_url_link): array |
|
224 | - { |
|
225 | - return $this->registrant_answers[ $reg_url_link ] ?? []; |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * @param string $reg_url_link |
|
231 | - * @param string $identifier the answer cache ID |
|
232 | - * @param EE_Answer $answer |
|
233 | - */ |
|
234 | - public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void |
|
235 | - { |
|
236 | - $this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer; |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * @param string $reg_url_link |
|
242 | - * @param string $identifier |
|
243 | - * @return EE_Answer|null |
|
244 | - */ |
|
245 | - public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer |
|
246 | - { |
|
247 | - return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param string $reg_url_link |
|
254 | - * @param string $identifier |
|
255 | - * @return bool |
|
256 | - */ |
|
257 | - public function registrantAnswerIsObject(string $reg_url_link, string $identifier): bool |
|
258 | - { |
|
259 | - $registrant_answer = $this->getRegistrantAnswer($reg_url_link, $identifier); |
|
260 | - return $registrant_answer instanceof EE_Answer; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @return array |
|
266 | - */ |
|
267 | - public function primaryRegistrantData(): array |
|
268 | - { |
|
269 | - return $this->primary_registrant_data; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * @param string $key |
|
275 | - * @param mixed $value |
|
276 | - */ |
|
277 | - public function addPrimaryRegistrantDataValue(string $key, $value): void |
|
278 | - { |
|
279 | - $this->primary_registrant_data[ $key ] = $value; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * @param string $key |
|
285 | - * @return mixed |
|
286 | - */ |
|
287 | - public function getPrimaryRegistrantDataValue(string $key) |
|
288 | - { |
|
289 | - return $this->primary_registrant_data[ $key ] ?? null; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * @param array $primary_registrant_data |
|
295 | - */ |
|
296 | - public function setPrimaryRegistrantData(array $primary_registrant_data): void |
|
297 | - { |
|
298 | - $this->primary_registrant_data = $primary_registrant_data; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * @return EE_Attendee |
|
304 | - */ |
|
305 | - public function primaryRegistrant(): EE_Attendee |
|
306 | - { |
|
307 | - return $this->primary_registrant; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * @return bool |
|
313 | - */ |
|
314 | - public function primaryRegistrantIsValid(): bool |
|
315 | - { |
|
316 | - return $this->primary_registrant instanceof EE_Attendee; |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * @param EE_Attendee $primary_registrant |
|
322 | - */ |
|
323 | - public function setPrimaryRegistrant(EE_Attendee $primary_registrant): void |
|
324 | - { |
|
325 | - $this->primary_registrant = $primary_registrant; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * @param string $reg_url_link |
|
331 | - * @return bool |
|
332 | - */ |
|
333 | - public function currentRegistrantIsPrimary(string $reg_url_link = ''): bool |
|
334 | - { |
|
335 | - return $this->attendeeCount() === 1 |
|
336 | - || ( |
|
337 | - $this->attendeeCount() === 1 |
|
338 | - && $reg_url_link !== '' |
|
339 | - && $this->getPrimaryRegistrantDataValue('reg_url_link') === $reg_url_link |
|
340 | - ); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * @return bool |
|
346 | - */ |
|
347 | - public function currentRegistrantIsNotPrimary(): bool |
|
348 | - { |
|
349 | - return $this->attendeeCount() > 1; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * @param string $reg_url_link |
|
355 | - * @param string $form_input |
|
356 | - * @param mixed $input_value |
|
357 | - * @return mixed|null |
|
358 | - */ |
|
359 | - public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value) |
|
360 | - { |
|
361 | - // store a bit of data about the primary attendee |
|
362 | - if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) { |
|
363 | - $this->primary_registrant_data[ $form_input ] = $input_value; |
|
364 | - return $input_value; |
|
365 | - } |
|
366 | - // or copy value from primary if incoming value is not set |
|
367 | - if ($input_value === null && $this->copyPrimary()) { |
|
368 | - $input_value = $this->getPrimaryRegistrantDataValue($form_input); |
|
369 | - } |
|
370 | - return $input_value; |
|
371 | - } |
|
22 | + /** |
|
23 | + * @var int |
|
24 | + */ |
|
25 | + private $attendee_counter = 0; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + private $registrant_data = []; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var bool |
|
34 | + */ |
|
35 | + private $copy_primary = false; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + private $required_questions = []; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Registration[] |
|
44 | + */ |
|
45 | + private $registrations = []; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var EE_Answer[][] |
|
49 | + */ |
|
50 | + private $registrant_answers = []; |
|
51 | + |
|
52 | + /** |
|
53 | + * array for tracking reg form data for the primary registrant |
|
54 | + * |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + private $primary_registrant_data; |
|
58 | + |
|
59 | + /** |
|
60 | + * the attendee object created for the primary registrant |
|
61 | + * |
|
62 | + * @var EE_Attendee |
|
63 | + */ |
|
64 | + private $primary_registrant; |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * RegistrantData constructor. |
|
69 | + */ |
|
70 | + public function __construct() |
|
71 | + { |
|
72 | + $this->primary_registrant_data = ['line_item_id' => null,]; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @param EE_Registration $registration |
|
78 | + * @throws EE_Error |
|
79 | + */ |
|
80 | + public function initializeRegistrantData(EE_Registration $registration): void |
|
81 | + { |
|
82 | + $reg_url_link = $registration->reg_url_link(); |
|
83 | + $this->registrations[ $reg_url_link ] = $registration; |
|
84 | + $this->registrant_answers[ $reg_url_link ] = $registration->answers(); |
|
85 | + $this->registrant_data[ $reg_url_link ] = []; |
|
86 | + $this->attendee_counter++; |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * @return int |
|
92 | + */ |
|
93 | + public function attendeeCount(): int |
|
94 | + { |
|
95 | + return $this->attendee_counter; |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + public function copyPrimary(): bool |
|
103 | + { |
|
104 | + return $this->copy_primary; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @param bool $copy_primary |
|
110 | + */ |
|
111 | + public function setCopyPrimary(bool $copy_primary): void |
|
112 | + { |
|
113 | + $this->copy_primary = filter_var($copy_primary, FILTER_VALIDATE_BOOLEAN); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @param string $reg_url_link |
|
119 | + * @return array|null |
|
120 | + */ |
|
121 | + public function getRegistrant(string $reg_url_link): ?EE_Registration |
|
122 | + { |
|
123 | + return $this->registrations[ $reg_url_link ] ?? null; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param string $reg_url_link |
|
129 | + * @return array|null |
|
130 | + */ |
|
131 | + public function getRegistrantData(string $reg_url_link): ?array |
|
132 | + { |
|
133 | + return $this->registrant_data[ $reg_url_link ] ?? null; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param string $reg_url_link |
|
139 | + * @param string $key |
|
140 | + * @param mixed $value |
|
141 | + */ |
|
142 | + public function addRegistrantDataValue(string $reg_url_link, string $key, $value): void |
|
143 | + { |
|
144 | + $this->registrant_data[ $reg_url_link ][ $key ] = $value; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * ensures that all attendees at least have data for first name, last name, and email address |
|
150 | + * |
|
151 | + * @param string $reg_url_link |
|
152 | + * @throws EE_Error |
|
153 | + * @throws ReflectionException |
|
154 | + */ |
|
155 | + public function ensureCriticalRegistrantDataIsSet(string $reg_url_link): void { |
|
156 | + if ($this->currentRegistrantIsPrimary()) { |
|
157 | + return; |
|
158 | + } |
|
159 | + // bare minimum critical details include first name, last name, email address |
|
160 | + $critical_attendee_details = ['ATT_fname', 'ATT_lname', 'ATT_email']; |
|
161 | + // add address info to critical details? |
|
162 | + if ( |
|
163 | + apply_filters( |
|
164 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
165 | + false |
|
166 | + ) |
|
167 | + ) { |
|
168 | + $critical_attendee_details += [ |
|
169 | + 'ATT_address', |
|
170 | + 'ATT_address2', |
|
171 | + 'ATT_city', |
|
172 | + 'STA_ID', |
|
173 | + 'CNT_ISO', |
|
174 | + 'ATT_zip', |
|
175 | + 'ATT_phone', |
|
176 | + ]; |
|
177 | + } |
|
178 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
179 | + if ( |
|
180 | + ! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
181 | + || empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
182 | + ) { |
|
183 | + $this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get( |
|
184 | + $critical_attendee_detail |
|
185 | + ); |
|
186 | + } |
|
187 | + } |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @param string $reg_url_link |
|
193 | + * @param array $registrant_data |
|
194 | + */ |
|
195 | + public function setRegistrantData(string $reg_url_link, array $registrant_data): void |
|
196 | + { |
|
197 | + $this->registrant_data[ $reg_url_link ] = $registrant_data; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function getRequiredQuestions(): array |
|
205 | + { |
|
206 | + return $this->required_questions; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * @param string $identifier |
|
212 | + * @param string $required_question |
|
213 | + */ |
|
214 | + public function addRequiredQuestion(string $identifier, string $required_question): void |
|
215 | + { |
|
216 | + $this->required_questions[ $identifier ] = $required_question; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * @return EE_Answer[] |
|
222 | + */ |
|
223 | + public function registrantAnswers(string $reg_url_link): array |
|
224 | + { |
|
225 | + return $this->registrant_answers[ $reg_url_link ] ?? []; |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * @param string $reg_url_link |
|
231 | + * @param string $identifier the answer cache ID |
|
232 | + * @param EE_Answer $answer |
|
233 | + */ |
|
234 | + public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void |
|
235 | + { |
|
236 | + $this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer; |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * @param string $reg_url_link |
|
242 | + * @param string $identifier |
|
243 | + * @return EE_Answer|null |
|
244 | + */ |
|
245 | + public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer |
|
246 | + { |
|
247 | + return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param string $reg_url_link |
|
254 | + * @param string $identifier |
|
255 | + * @return bool |
|
256 | + */ |
|
257 | + public function registrantAnswerIsObject(string $reg_url_link, string $identifier): bool |
|
258 | + { |
|
259 | + $registrant_answer = $this->getRegistrantAnswer($reg_url_link, $identifier); |
|
260 | + return $registrant_answer instanceof EE_Answer; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @return array |
|
266 | + */ |
|
267 | + public function primaryRegistrantData(): array |
|
268 | + { |
|
269 | + return $this->primary_registrant_data; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * @param string $key |
|
275 | + * @param mixed $value |
|
276 | + */ |
|
277 | + public function addPrimaryRegistrantDataValue(string $key, $value): void |
|
278 | + { |
|
279 | + $this->primary_registrant_data[ $key ] = $value; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * @param string $key |
|
285 | + * @return mixed |
|
286 | + */ |
|
287 | + public function getPrimaryRegistrantDataValue(string $key) |
|
288 | + { |
|
289 | + return $this->primary_registrant_data[ $key ] ?? null; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @param array $primary_registrant_data |
|
295 | + */ |
|
296 | + public function setPrimaryRegistrantData(array $primary_registrant_data): void |
|
297 | + { |
|
298 | + $this->primary_registrant_data = $primary_registrant_data; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * @return EE_Attendee |
|
304 | + */ |
|
305 | + public function primaryRegistrant(): EE_Attendee |
|
306 | + { |
|
307 | + return $this->primary_registrant; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * @return bool |
|
313 | + */ |
|
314 | + public function primaryRegistrantIsValid(): bool |
|
315 | + { |
|
316 | + return $this->primary_registrant instanceof EE_Attendee; |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * @param EE_Attendee $primary_registrant |
|
322 | + */ |
|
323 | + public function setPrimaryRegistrant(EE_Attendee $primary_registrant): void |
|
324 | + { |
|
325 | + $this->primary_registrant = $primary_registrant; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * @param string $reg_url_link |
|
331 | + * @return bool |
|
332 | + */ |
|
333 | + public function currentRegistrantIsPrimary(string $reg_url_link = ''): bool |
|
334 | + { |
|
335 | + return $this->attendeeCount() === 1 |
|
336 | + || ( |
|
337 | + $this->attendeeCount() === 1 |
|
338 | + && $reg_url_link !== '' |
|
339 | + && $this->getPrimaryRegistrantDataValue('reg_url_link') === $reg_url_link |
|
340 | + ); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * @return bool |
|
346 | + */ |
|
347 | + public function currentRegistrantIsNotPrimary(): bool |
|
348 | + { |
|
349 | + return $this->attendeeCount() > 1; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * @param string $reg_url_link |
|
355 | + * @param string $form_input |
|
356 | + * @param mixed $input_value |
|
357 | + * @return mixed|null |
|
358 | + */ |
|
359 | + public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value) |
|
360 | + { |
|
361 | + // store a bit of data about the primary attendee |
|
362 | + if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) { |
|
363 | + $this->primary_registrant_data[ $form_input ] = $input_value; |
|
364 | + return $input_value; |
|
365 | + } |
|
366 | + // or copy value from primary if incoming value is not set |
|
367 | + if ($input_value === null && $this->copyPrimary()) { |
|
368 | + $input_value = $this->getPrimaryRegistrantDataValue($form_input); |
|
369 | + } |
|
370 | + return $input_value; |
|
371 | + } |
|
372 | 372 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function __construct() |
71 | 71 | { |
72 | - $this->primary_registrant_data = ['line_item_id' => null,]; |
|
72 | + $this->primary_registrant_data = ['line_item_id' => null, ]; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | public function initializeRegistrantData(EE_Registration $registration): void |
81 | 81 | { |
82 | 82 | $reg_url_link = $registration->reg_url_link(); |
83 | - $this->registrations[ $reg_url_link ] = $registration; |
|
84 | - $this->registrant_answers[ $reg_url_link ] = $registration->answers(); |
|
85 | - $this->registrant_data[ $reg_url_link ] = []; |
|
83 | + $this->registrations[$reg_url_link] = $registration; |
|
84 | + $this->registrant_answers[$reg_url_link] = $registration->answers(); |
|
85 | + $this->registrant_data[$reg_url_link] = []; |
|
86 | 86 | $this->attendee_counter++; |
87 | 87 | } |
88 | 88 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function getRegistrant(string $reg_url_link): ?EE_Registration |
122 | 122 | { |
123 | - return $this->registrations[ $reg_url_link ] ?? null; |
|
123 | + return $this->registrations[$reg_url_link] ?? null; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function getRegistrantData(string $reg_url_link): ?array |
132 | 132 | { |
133 | - return $this->registrant_data[ $reg_url_link ] ?? null; |
|
133 | + return $this->registrant_data[$reg_url_link] ?? null; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public function addRegistrantDataValue(string $reg_url_link, string $key, $value): void |
143 | 143 | { |
144 | - $this->registrant_data[ $reg_url_link ][ $key ] = $value; |
|
144 | + $this->registrant_data[$reg_url_link][$key] = $value; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | |
@@ -177,10 +177,10 @@ discard block |
||
177 | 177 | } |
178 | 178 | foreach ($critical_attendee_details as $critical_attendee_detail) { |
179 | 179 | if ( |
180 | - ! isset($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
181 | - || empty($this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ]) |
|
180 | + ! isset($this->registrant_data[$reg_url_link][$critical_attendee_detail]) |
|
181 | + || empty($this->registrant_data[$reg_url_link][$critical_attendee_detail]) |
|
182 | 182 | ) { |
183 | - $this->registrant_data[ $reg_url_link ][ $critical_attendee_detail ] = $this->primary_registrant->get( |
|
183 | + $this->registrant_data[$reg_url_link][$critical_attendee_detail] = $this->primary_registrant->get( |
|
184 | 184 | $critical_attendee_detail |
185 | 185 | ); |
186 | 186 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function setRegistrantData(string $reg_url_link, array $registrant_data): void |
196 | 196 | { |
197 | - $this->registrant_data[ $reg_url_link ] = $registrant_data; |
|
197 | + $this->registrant_data[$reg_url_link] = $registrant_data; |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | */ |
214 | 214 | public function addRequiredQuestion(string $identifier, string $required_question): void |
215 | 215 | { |
216 | - $this->required_questions[ $identifier ] = $required_question; |
|
216 | + $this->required_questions[$identifier] = $required_question; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | */ |
223 | 223 | public function registrantAnswers(string $reg_url_link): array |
224 | 224 | { |
225 | - return $this->registrant_answers[ $reg_url_link ] ?? []; |
|
225 | + return $this->registrant_answers[$reg_url_link] ?? []; |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | */ |
234 | 234 | public function addRegistrantAnswer(string $reg_url_link, string $identifier, EE_Answer $answer): void |
235 | 235 | { |
236 | - $this->registrant_answers[ $reg_url_link ][ $identifier ] = $answer; |
|
236 | + $this->registrant_answers[$reg_url_link][$identifier] = $answer; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | */ |
245 | 245 | public function getRegistrantAnswer(string $reg_url_link, string $identifier): ?EE_Answer |
246 | 246 | { |
247 | - return $this->registrant_answers[ $reg_url_link ][ $identifier ] ?? null; |
|
247 | + return $this->registrant_answers[$reg_url_link][$identifier] ?? null; |
|
248 | 248 | } |
249 | 249 | |
250 | 250 | |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | */ |
277 | 277 | public function addPrimaryRegistrantDataValue(string $key, $value): void |
278 | 278 | { |
279 | - $this->primary_registrant_data[ $key ] = $value; |
|
279 | + $this->primary_registrant_data[$key] = $value; |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | */ |
287 | 287 | public function getPrimaryRegistrantDataValue(string $key) |
288 | 288 | { |
289 | - return $this->primary_registrant_data[ $key ] ?? null; |
|
289 | + return $this->primary_registrant_data[$key] ?? null; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | |
@@ -359,8 +359,8 @@ discard block |
||
359 | 359 | public function saveOrCopyPrimaryRegistrantData(string $reg_url_link, string $form_input, $input_value) |
360 | 360 | { |
361 | 361 | // store a bit of data about the primary attendee |
362 | - if (! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) { |
|
363 | - $this->primary_registrant_data[ $form_input ] = $input_value; |
|
362 | + if ( ! empty($input_value) && $this->currentRegistrantIsPrimary($reg_url_link)) { |
|
363 | + $this->primary_registrant_data[$form_input] = $input_value; |
|
364 | 364 | return $input_value; |
365 | 365 | } |
366 | 366 | // or copy value from primary if incoming value is not set |
@@ -22,472 +22,472 @@ |
||
22 | 22 | class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var RegForm |
|
27 | - */ |
|
28 | - public $reg_form; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var int |
|
32 | - */ |
|
33 | - protected $reg_form_count = 0; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * class constructor |
|
38 | - * |
|
39 | - * @access public |
|
40 | - * @param EE_Checkout $checkout |
|
41 | - */ |
|
42 | - public function __construct(EE_Checkout $checkout) |
|
43 | - { |
|
44 | - $this->_slug = 'attendee_information'; |
|
45 | - $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
46 | - $this->checkout = $checkout; |
|
47 | - $this->_reset_success_message(); |
|
48 | - $this->set_instructions( |
|
49 | - esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
50 | - ); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - public function translate_js_strings() |
|
55 | - { |
|
56 | - EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
57 | - ' is a required question.', |
|
58 | - 'event_espresso' |
|
59 | - ); |
|
60 | - EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
61 | - ' is a required question. Please enter a value for at least one of the options.', |
|
62 | - 'event_espresso' |
|
63 | - ); |
|
64 | - EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
65 | - 'Please answer all required questions correctly before proceeding.', |
|
66 | - 'event_espresso' |
|
67 | - ); |
|
68 | - EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
69 | - esc_html_x( |
|
70 | - 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
71 | - 'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.', |
|
72 | - 'event_espresso' |
|
73 | - ), |
|
74 | - '<br/>' |
|
75 | - ); |
|
76 | - EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
77 | - 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
78 | - 'event_espresso' |
|
79 | - ); |
|
80 | - EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
81 | - 'You must enter a valid email address.', |
|
82 | - 'event_espresso' |
|
83 | - ); |
|
84 | - EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
85 | - 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
86 | - 'event_espresso' |
|
87 | - ); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - public function enqueue_styles_and_scripts() |
|
92 | - { |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @return boolean |
|
98 | - */ |
|
99 | - public function initialize_reg_step(): bool |
|
100 | - { |
|
101 | - return true; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @return RegForm |
|
107 | - * @throws DomainException |
|
108 | - * @throws InvalidArgumentException |
|
109 | - * @throws EntityNotFoundException |
|
110 | - * @throws InvalidDataTypeException |
|
111 | - * @throws InvalidInterfaceException |
|
112 | - */ |
|
113 | - public function generate_reg_form(): RegForm |
|
114 | - { |
|
115 | - /** @var RegFormDependencyHandler $dependency_handler */ |
|
116 | - $dependency_handler = LoaderFactory::getShared(RegFormDependencyHandler::class); |
|
117 | - $dependency_handler->registerDependencies(); |
|
118 | - // TODO detect if event has a reg form UUID and swap this out for form generated by new reg form builder |
|
119 | - return LoaderFactory::getShared(RegForm::class, [$this]); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * looking for hooks? |
|
125 | - * this method has been replaced by: |
|
126 | - * EventEspresso\core\domain\services\registration\form\v1\RegForm::getRegForm() |
|
127 | - * |
|
128 | - * @deprecated $VID:$ |
|
129 | - */ |
|
130 | - private function _registrations_reg_form() |
|
131 | - { |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * looking for hooks? |
|
137 | - * this method has been replaced by: |
|
138 | - * EventEspresso\core\domain\services\registration\form\v1\RegForm::additionalAttendeeRegInfoInput() |
|
139 | - * |
|
140 | - * @deprecated $VID:$ |
|
141 | - */ |
|
142 | - private function _additional_attendee_reg_info_input() |
|
143 | - { |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * looking for hooks? |
|
149 | - * this method has been replaced by: |
|
150 | - * EventEspresso\core\domain\services\registration\form\v1\RegForm::questionGroupRegForm() |
|
151 | - * |
|
152 | - * @deprecated $VID:$ |
|
153 | - */ |
|
154 | - private function _question_group_reg_form() |
|
155 | - { |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * looking for hooks? |
|
161 | - * this method has been replaced by: |
|
162 | - * EventEspresso\core\domain\services\registration\form\v1\RegForm::questionGroupHeader() |
|
163 | - * |
|
164 | - * @deprecated $VID:$ |
|
165 | - */ |
|
166 | - private function _question_group_header() |
|
167 | - { |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * looking for hooks? |
|
173 | - * this method has been replaced by: |
|
174 | - * EventEspresso\core\domain\services\registration\form\v1\CopyAttendeeInfoForm |
|
175 | - * |
|
176 | - * @deprecated $VID:$ |
|
177 | - */ |
|
178 | - private function _copy_attendee_info_form() |
|
179 | - { |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * looking for hooks? |
|
185 | - * this method has been replaced by: |
|
186 | - * EventEspresso\core\domain\services\registration\form\v1\AutoCopyAttendeeInfoForm |
|
187 | - * |
|
188 | - * @deprecated $VID:$ |
|
189 | - */ |
|
190 | - private function _auto_copy_attendee_info() |
|
191 | - { |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * looking for hooks? |
|
197 | - * this method has been replaced by: |
|
198 | - * EventEspresso\core\domain\services\registration\form\v1\CopyAttendeeInfoForm |
|
199 | - * |
|
200 | - * @deprecated $VID:$ |
|
201 | - */ |
|
202 | - private function _copy_attendee_info_inputs() |
|
203 | - { |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * looking for hooks? |
|
209 | - * this method has been replaced by: |
|
210 | - * EventEspresso\core\domain\services\registration\form\v1\RegForm::additionalPrimaryRegistrantInputs() |
|
211 | - * |
|
212 | - * @deprecated $VID:$ |
|
213 | - */ |
|
214 | - private function _additional_primary_registrant_inputs() |
|
215 | - { |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * looking for hooks? |
|
221 | - * this method has been replaced by: |
|
222 | - * EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory::create() |
|
223 | - * |
|
224 | - * @param EE_Registration $registration |
|
225 | - * @param EE_Question $question |
|
226 | - * @return EE_Form_Input_Base |
|
227 | - * @throws EE_Error |
|
228 | - * @throws ReflectionException |
|
229 | - * @deprecated $VID:$ |
|
230 | - */ |
|
231 | - public function reg_form_question(EE_Registration $registration, EE_Question $question): EE_Form_Input_Base |
|
232 | - { |
|
233 | - /** @var RegFormQuestionFactory $reg_form_question_factory */ |
|
234 | - $reg_form_question_factory = LoaderFactory::getShared(RegFormQuestionFactory::class); |
|
235 | - return $reg_form_question_factory->create($registration, $question); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * looking for hooks? |
|
241 | - * this method has been replaced by: |
|
242 | - * EventEspresso\core\domain\services\registration\form\v1\RegForm::generateQuestionInput() |
|
243 | - * |
|
244 | - * @deprecated $VID:$ |
|
245 | - */ |
|
246 | - private function _generate_question_input() |
|
247 | - { |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * looking for hooks? |
|
253 | - * this method has been replaced by: |
|
254 | - * EventEspresso\core\domain\services\registration\form\v1\CountryOptions::forLegacyFormInput() |
|
255 | - * |
|
256 | - * @param array|null $countries_list |
|
257 | - * @param EE_Question|null $question |
|
258 | - * @param EE_Registration|null $registration |
|
259 | - * @param EE_Answer|null $answer |
|
260 | - * @return array 2d keys are country IDs, values are their names |
|
261 | - * @throws EE_Error |
|
262 | - * @throws ReflectionException |
|
263 | - * @deprecated $VID:$ |
|
264 | - */ |
|
265 | - public function use_cached_countries_for_form_input( |
|
266 | - array $countries_list = null, |
|
267 | - EE_Question $question = null, |
|
268 | - EE_Registration $registration = null, |
|
269 | - EE_Answer $answer = null |
|
270 | - ): array { |
|
271 | - /** @var CountryOptions $country_options */ |
|
272 | - $country_options = LoaderFactory::getShared(CountryOptions::class, [$this->checkout->action]); |
|
273 | - return $country_options->forLegacyFormInput($countries_list, $question, $registration, $answer); |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * looking for hooks? |
|
279 | - * this method has been replaced by: |
|
280 | - * EventEspresso\core\domain\services\registration\form\v1\StateOptions::forLegacyFormInput() |
|
281 | - * |
|
282 | - * @param array|null $states_list |
|
283 | - * @param EE_Question|null $question |
|
284 | - * @param EE_Registration|null $registration |
|
285 | - * @param EE_Answer|null $answer |
|
286 | - * @return array 2d keys are state IDs, values are their names |
|
287 | - * @throws EE_Error |
|
288 | - * @throws ReflectionException |
|
289 | - * @deprecated $VID:$ |
|
290 | - */ |
|
291 | - public function use_cached_states_for_form_input( |
|
292 | - array $states_list = null, |
|
293 | - EE_Question $question = null, |
|
294 | - EE_Registration $registration = null, |
|
295 | - EE_Answer $answer = null |
|
296 | - ): array { |
|
297 | - /** @var StateOptions $state_options */ |
|
298 | - $state_options = LoaderFactory::getShared(StateOptions::class, [$this->checkout->action]); |
|
299 | - return $state_options->forLegacyFormInput($states_list, $question, $registration, $answer); |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /********************************************************************************************************/ |
|
304 | - /**************************************** PROCESS REG STEP ****************************************/ |
|
305 | - /********************************************************************************************************/ |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * @return bool |
|
310 | - * @throws EE_Error |
|
311 | - * @throws InvalidArgumentException |
|
312 | - * @throws ReflectionException |
|
313 | - * @throws RuntimeException |
|
314 | - * @throws InvalidDataTypeException |
|
315 | - * @throws InvalidInterfaceException |
|
316 | - */ |
|
317 | - public function process_reg_step(): bool |
|
318 | - { |
|
319 | - // grab validated data from form |
|
320 | - $valid_data = $this->checkout->current_step->valid_data(); |
|
321 | - // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
322 | - if (empty($valid_data)) { |
|
323 | - return $this->inValidDataError(); |
|
324 | - } |
|
325 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
326 | - return $this->inValidTransactionError(); |
|
327 | - } |
|
328 | - // get cached registrations |
|
329 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
330 | - // verify we got the goods |
|
331 | - if (empty($registrations)) { |
|
332 | - return $this->noRegistrationsError(); |
|
333 | - } |
|
334 | - /** @var RegFormHandler $reg_form_handler */ |
|
335 | - $reg_form_handler = LoaderFactory::getNew(RegFormHandler::class, [$this->checkout]); |
|
336 | - // extract attendee info from form data and save to model objects |
|
337 | - if (! $reg_form_handler->processRegistrations($registrations, $valid_data)) { |
|
338 | - // return immediately if the previous step exited early due to errors |
|
339 | - return false; |
|
340 | - } |
|
341 | - // if first pass thru SPCO, |
|
342 | - // then let's check processed registrations against the total number of tickets in the cart |
|
343 | - $registrations_processed = $reg_form_handler->attendeeCount(); |
|
344 | - if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
345 | - return $this->registrationProcessingError($registrations_processed); |
|
346 | - } |
|
347 | - // mark this reg step as completed |
|
348 | - $this->set_completed(); |
|
349 | - $this->_set_success_message( |
|
350 | - esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
351 | - ); |
|
352 | - // do action in case a plugin wants to do something with the data submitted in step 1. |
|
353 | - // passes EE_Single_Page_Checkout, and it's posted data |
|
354 | - do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
355 | - return true; |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * @return bool |
|
361 | - * @since $VID:$ |
|
362 | - */ |
|
363 | - private function inValidDataError(): bool |
|
364 | - { |
|
365 | - EE_Error::add_error( |
|
366 | - esc_html__('No valid question responses were received.', 'event_espresso'), |
|
367 | - __FILE__, |
|
368 | - __FUNCTION__, |
|
369 | - __LINE__ |
|
370 | - ); |
|
371 | - return false; |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * @return bool |
|
377 | - * @since $VID:$ |
|
378 | - */ |
|
379 | - private function inValidTransactionError(): bool |
|
380 | - { |
|
381 | - EE_Error::add_error( |
|
382 | - esc_html__( |
|
383 | - 'A valid transaction could not be initiated for processing your registrations.', |
|
384 | - 'event_espresso' |
|
385 | - ), |
|
386 | - __FILE__, |
|
387 | - __FUNCTION__, |
|
388 | - __LINE__ |
|
389 | - ); |
|
390 | - return false; |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * @return bool |
|
396 | - * @since $VID:$ |
|
397 | - */ |
|
398 | - private function noRegistrationsError(): bool |
|
399 | - { |
|
400 | - // combine the old translated string with a new one, in order to not break translations |
|
401 | - $error_message = esc_html__( |
|
402 | - 'Your form data could not be applied to any valid registrations.', |
|
403 | - 'event_espresso' |
|
404 | - ); |
|
405 | - $error_message .= sprintf( |
|
406 | - esc_html_x( |
|
407 | - '%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
408 | - '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
409 | - 'event_espresso' |
|
410 | - ), |
|
411 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
412 | - '</a>', |
|
413 | - '<br />' |
|
414 | - ); |
|
415 | - EE_Error::add_error($error_message, __FILE__, __FUNCTION__, __LINE__); |
|
416 | - return false; |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * @param int $registrations_processed |
|
422 | - * @return bool |
|
423 | - * @since $VID:$ |
|
424 | - */ |
|
425 | - private function registrationProcessingError(int $registrations_processed): bool |
|
426 | - { |
|
427 | - // generate a correctly translated string for all possible singular/plural combinations |
|
428 | - if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
429 | - $error_msg = sprintf( |
|
430 | - esc_html_x( |
|
431 | - 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
432 | - 'There was 1 ticket in the Event Queue, but 2 registrations were processed', |
|
433 | - 'event_espresso' |
|
434 | - ), |
|
435 | - $this->checkout->total_ticket_count, |
|
436 | - $registrations_processed |
|
437 | - ); |
|
438 | - } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
439 | - $error_msg = sprintf( |
|
440 | - esc_html_x( |
|
441 | - 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
442 | - 'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed', |
|
443 | - 'event_espresso' |
|
444 | - ), |
|
445 | - $this->checkout->total_ticket_count, |
|
446 | - $registrations_processed |
|
447 | - ); |
|
448 | - } else { |
|
449 | - $error_msg = sprintf( |
|
450 | - esc_html__( |
|
451 | - 'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed', |
|
452 | - 'event_espresso' |
|
453 | - ), |
|
454 | - $this->checkout->total_ticket_count, |
|
455 | - $registrations_processed |
|
456 | - ); |
|
457 | - } |
|
458 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
459 | - return false; |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * update_reg_step |
|
465 | - * this is the final step after a user revisits the site to edit their attendee information |
|
466 | - * this gets called AFTER the process_reg_step() method above |
|
467 | - * |
|
468 | - * @return bool |
|
469 | - * @throws EE_Error |
|
470 | - * @throws InvalidArgumentException |
|
471 | - * @throws ReflectionException |
|
472 | - * @throws RuntimeException |
|
473 | - * @throws InvalidDataTypeException |
|
474 | - * @throws InvalidInterfaceException |
|
475 | - */ |
|
476 | - public function update_reg_step(): bool |
|
477 | - { |
|
478 | - // save everything |
|
479 | - if ($this->process_reg_step()) { |
|
480 | - $this->checkout->redirect = true; |
|
481 | - $this->checkout->redirect_url = add_query_arg( |
|
482 | - [ |
|
483 | - 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
484 | - 'revisit' => true, |
|
485 | - ], |
|
486 | - $this->checkout->thank_you_page_url |
|
487 | - ); |
|
488 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
489 | - return true; |
|
490 | - } |
|
491 | - return false; |
|
492 | - } |
|
25 | + /** |
|
26 | + * @var RegForm |
|
27 | + */ |
|
28 | + public $reg_form; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var int |
|
32 | + */ |
|
33 | + protected $reg_form_count = 0; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * class constructor |
|
38 | + * |
|
39 | + * @access public |
|
40 | + * @param EE_Checkout $checkout |
|
41 | + */ |
|
42 | + public function __construct(EE_Checkout $checkout) |
|
43 | + { |
|
44 | + $this->_slug = 'attendee_information'; |
|
45 | + $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
46 | + $this->checkout = $checkout; |
|
47 | + $this->_reset_success_message(); |
|
48 | + $this->set_instructions( |
|
49 | + esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
50 | + ); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + public function translate_js_strings() |
|
55 | + { |
|
56 | + EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
57 | + ' is a required question.', |
|
58 | + 'event_espresso' |
|
59 | + ); |
|
60 | + EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
61 | + ' is a required question. Please enter a value for at least one of the options.', |
|
62 | + 'event_espresso' |
|
63 | + ); |
|
64 | + EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
65 | + 'Please answer all required questions correctly before proceeding.', |
|
66 | + 'event_espresso' |
|
67 | + ); |
|
68 | + EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
69 | + esc_html_x( |
|
70 | + 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
71 | + 'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.', |
|
72 | + 'event_espresso' |
|
73 | + ), |
|
74 | + '<br/>' |
|
75 | + ); |
|
76 | + EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
77 | + 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
78 | + 'event_espresso' |
|
79 | + ); |
|
80 | + EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
81 | + 'You must enter a valid email address.', |
|
82 | + 'event_espresso' |
|
83 | + ); |
|
84 | + EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
85 | + 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
86 | + 'event_espresso' |
|
87 | + ); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + public function enqueue_styles_and_scripts() |
|
92 | + { |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @return boolean |
|
98 | + */ |
|
99 | + public function initialize_reg_step(): bool |
|
100 | + { |
|
101 | + return true; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @return RegForm |
|
107 | + * @throws DomainException |
|
108 | + * @throws InvalidArgumentException |
|
109 | + * @throws EntityNotFoundException |
|
110 | + * @throws InvalidDataTypeException |
|
111 | + * @throws InvalidInterfaceException |
|
112 | + */ |
|
113 | + public function generate_reg_form(): RegForm |
|
114 | + { |
|
115 | + /** @var RegFormDependencyHandler $dependency_handler */ |
|
116 | + $dependency_handler = LoaderFactory::getShared(RegFormDependencyHandler::class); |
|
117 | + $dependency_handler->registerDependencies(); |
|
118 | + // TODO detect if event has a reg form UUID and swap this out for form generated by new reg form builder |
|
119 | + return LoaderFactory::getShared(RegForm::class, [$this]); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * looking for hooks? |
|
125 | + * this method has been replaced by: |
|
126 | + * EventEspresso\core\domain\services\registration\form\v1\RegForm::getRegForm() |
|
127 | + * |
|
128 | + * @deprecated $VID:$ |
|
129 | + */ |
|
130 | + private function _registrations_reg_form() |
|
131 | + { |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * looking for hooks? |
|
137 | + * this method has been replaced by: |
|
138 | + * EventEspresso\core\domain\services\registration\form\v1\RegForm::additionalAttendeeRegInfoInput() |
|
139 | + * |
|
140 | + * @deprecated $VID:$ |
|
141 | + */ |
|
142 | + private function _additional_attendee_reg_info_input() |
|
143 | + { |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * looking for hooks? |
|
149 | + * this method has been replaced by: |
|
150 | + * EventEspresso\core\domain\services\registration\form\v1\RegForm::questionGroupRegForm() |
|
151 | + * |
|
152 | + * @deprecated $VID:$ |
|
153 | + */ |
|
154 | + private function _question_group_reg_form() |
|
155 | + { |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * looking for hooks? |
|
161 | + * this method has been replaced by: |
|
162 | + * EventEspresso\core\domain\services\registration\form\v1\RegForm::questionGroupHeader() |
|
163 | + * |
|
164 | + * @deprecated $VID:$ |
|
165 | + */ |
|
166 | + private function _question_group_header() |
|
167 | + { |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * looking for hooks? |
|
173 | + * this method has been replaced by: |
|
174 | + * EventEspresso\core\domain\services\registration\form\v1\CopyAttendeeInfoForm |
|
175 | + * |
|
176 | + * @deprecated $VID:$ |
|
177 | + */ |
|
178 | + private function _copy_attendee_info_form() |
|
179 | + { |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * looking for hooks? |
|
185 | + * this method has been replaced by: |
|
186 | + * EventEspresso\core\domain\services\registration\form\v1\AutoCopyAttendeeInfoForm |
|
187 | + * |
|
188 | + * @deprecated $VID:$ |
|
189 | + */ |
|
190 | + private function _auto_copy_attendee_info() |
|
191 | + { |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * looking for hooks? |
|
197 | + * this method has been replaced by: |
|
198 | + * EventEspresso\core\domain\services\registration\form\v1\CopyAttendeeInfoForm |
|
199 | + * |
|
200 | + * @deprecated $VID:$ |
|
201 | + */ |
|
202 | + private function _copy_attendee_info_inputs() |
|
203 | + { |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * looking for hooks? |
|
209 | + * this method has been replaced by: |
|
210 | + * EventEspresso\core\domain\services\registration\form\v1\RegForm::additionalPrimaryRegistrantInputs() |
|
211 | + * |
|
212 | + * @deprecated $VID:$ |
|
213 | + */ |
|
214 | + private function _additional_primary_registrant_inputs() |
|
215 | + { |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * looking for hooks? |
|
221 | + * this method has been replaced by: |
|
222 | + * EventEspresso\core\domain\services\registration\form\v1\RegFormQuestionFactory::create() |
|
223 | + * |
|
224 | + * @param EE_Registration $registration |
|
225 | + * @param EE_Question $question |
|
226 | + * @return EE_Form_Input_Base |
|
227 | + * @throws EE_Error |
|
228 | + * @throws ReflectionException |
|
229 | + * @deprecated $VID:$ |
|
230 | + */ |
|
231 | + public function reg_form_question(EE_Registration $registration, EE_Question $question): EE_Form_Input_Base |
|
232 | + { |
|
233 | + /** @var RegFormQuestionFactory $reg_form_question_factory */ |
|
234 | + $reg_form_question_factory = LoaderFactory::getShared(RegFormQuestionFactory::class); |
|
235 | + return $reg_form_question_factory->create($registration, $question); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * looking for hooks? |
|
241 | + * this method has been replaced by: |
|
242 | + * EventEspresso\core\domain\services\registration\form\v1\RegForm::generateQuestionInput() |
|
243 | + * |
|
244 | + * @deprecated $VID:$ |
|
245 | + */ |
|
246 | + private function _generate_question_input() |
|
247 | + { |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * looking for hooks? |
|
253 | + * this method has been replaced by: |
|
254 | + * EventEspresso\core\domain\services\registration\form\v1\CountryOptions::forLegacyFormInput() |
|
255 | + * |
|
256 | + * @param array|null $countries_list |
|
257 | + * @param EE_Question|null $question |
|
258 | + * @param EE_Registration|null $registration |
|
259 | + * @param EE_Answer|null $answer |
|
260 | + * @return array 2d keys are country IDs, values are their names |
|
261 | + * @throws EE_Error |
|
262 | + * @throws ReflectionException |
|
263 | + * @deprecated $VID:$ |
|
264 | + */ |
|
265 | + public function use_cached_countries_for_form_input( |
|
266 | + array $countries_list = null, |
|
267 | + EE_Question $question = null, |
|
268 | + EE_Registration $registration = null, |
|
269 | + EE_Answer $answer = null |
|
270 | + ): array { |
|
271 | + /** @var CountryOptions $country_options */ |
|
272 | + $country_options = LoaderFactory::getShared(CountryOptions::class, [$this->checkout->action]); |
|
273 | + return $country_options->forLegacyFormInput($countries_list, $question, $registration, $answer); |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * looking for hooks? |
|
279 | + * this method has been replaced by: |
|
280 | + * EventEspresso\core\domain\services\registration\form\v1\StateOptions::forLegacyFormInput() |
|
281 | + * |
|
282 | + * @param array|null $states_list |
|
283 | + * @param EE_Question|null $question |
|
284 | + * @param EE_Registration|null $registration |
|
285 | + * @param EE_Answer|null $answer |
|
286 | + * @return array 2d keys are state IDs, values are their names |
|
287 | + * @throws EE_Error |
|
288 | + * @throws ReflectionException |
|
289 | + * @deprecated $VID:$ |
|
290 | + */ |
|
291 | + public function use_cached_states_for_form_input( |
|
292 | + array $states_list = null, |
|
293 | + EE_Question $question = null, |
|
294 | + EE_Registration $registration = null, |
|
295 | + EE_Answer $answer = null |
|
296 | + ): array { |
|
297 | + /** @var StateOptions $state_options */ |
|
298 | + $state_options = LoaderFactory::getShared(StateOptions::class, [$this->checkout->action]); |
|
299 | + return $state_options->forLegacyFormInput($states_list, $question, $registration, $answer); |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /********************************************************************************************************/ |
|
304 | + /**************************************** PROCESS REG STEP ****************************************/ |
|
305 | + /********************************************************************************************************/ |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * @return bool |
|
310 | + * @throws EE_Error |
|
311 | + * @throws InvalidArgumentException |
|
312 | + * @throws ReflectionException |
|
313 | + * @throws RuntimeException |
|
314 | + * @throws InvalidDataTypeException |
|
315 | + * @throws InvalidInterfaceException |
|
316 | + */ |
|
317 | + public function process_reg_step(): bool |
|
318 | + { |
|
319 | + // grab validated data from form |
|
320 | + $valid_data = $this->checkout->current_step->valid_data(); |
|
321 | + // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
322 | + if (empty($valid_data)) { |
|
323 | + return $this->inValidDataError(); |
|
324 | + } |
|
325 | + if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
326 | + return $this->inValidTransactionError(); |
|
327 | + } |
|
328 | + // get cached registrations |
|
329 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
330 | + // verify we got the goods |
|
331 | + if (empty($registrations)) { |
|
332 | + return $this->noRegistrationsError(); |
|
333 | + } |
|
334 | + /** @var RegFormHandler $reg_form_handler */ |
|
335 | + $reg_form_handler = LoaderFactory::getNew(RegFormHandler::class, [$this->checkout]); |
|
336 | + // extract attendee info from form data and save to model objects |
|
337 | + if (! $reg_form_handler->processRegistrations($registrations, $valid_data)) { |
|
338 | + // return immediately if the previous step exited early due to errors |
|
339 | + return false; |
|
340 | + } |
|
341 | + // if first pass thru SPCO, |
|
342 | + // then let's check processed registrations against the total number of tickets in the cart |
|
343 | + $registrations_processed = $reg_form_handler->attendeeCount(); |
|
344 | + if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
345 | + return $this->registrationProcessingError($registrations_processed); |
|
346 | + } |
|
347 | + // mark this reg step as completed |
|
348 | + $this->set_completed(); |
|
349 | + $this->_set_success_message( |
|
350 | + esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
351 | + ); |
|
352 | + // do action in case a plugin wants to do something with the data submitted in step 1. |
|
353 | + // passes EE_Single_Page_Checkout, and it's posted data |
|
354 | + do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
355 | + return true; |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * @return bool |
|
361 | + * @since $VID:$ |
|
362 | + */ |
|
363 | + private function inValidDataError(): bool |
|
364 | + { |
|
365 | + EE_Error::add_error( |
|
366 | + esc_html__('No valid question responses were received.', 'event_espresso'), |
|
367 | + __FILE__, |
|
368 | + __FUNCTION__, |
|
369 | + __LINE__ |
|
370 | + ); |
|
371 | + return false; |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * @return bool |
|
377 | + * @since $VID:$ |
|
378 | + */ |
|
379 | + private function inValidTransactionError(): bool |
|
380 | + { |
|
381 | + EE_Error::add_error( |
|
382 | + esc_html__( |
|
383 | + 'A valid transaction could not be initiated for processing your registrations.', |
|
384 | + 'event_espresso' |
|
385 | + ), |
|
386 | + __FILE__, |
|
387 | + __FUNCTION__, |
|
388 | + __LINE__ |
|
389 | + ); |
|
390 | + return false; |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * @return bool |
|
396 | + * @since $VID:$ |
|
397 | + */ |
|
398 | + private function noRegistrationsError(): bool |
|
399 | + { |
|
400 | + // combine the old translated string with a new one, in order to not break translations |
|
401 | + $error_message = esc_html__( |
|
402 | + 'Your form data could not be applied to any valid registrations.', |
|
403 | + 'event_espresso' |
|
404 | + ); |
|
405 | + $error_message .= sprintf( |
|
406 | + esc_html_x( |
|
407 | + '%3$sThis can sometimes happen if too much time has been taken to complete the registration process.%3$sPlease return to the %1$sEvent List%2$s and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
408 | + '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.', |
|
409 | + 'event_espresso' |
|
410 | + ), |
|
411 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
412 | + '</a>', |
|
413 | + '<br />' |
|
414 | + ); |
|
415 | + EE_Error::add_error($error_message, __FILE__, __FUNCTION__, __LINE__); |
|
416 | + return false; |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * @param int $registrations_processed |
|
422 | + * @return bool |
|
423 | + * @since $VID:$ |
|
424 | + */ |
|
425 | + private function registrationProcessingError(int $registrations_processed): bool |
|
426 | + { |
|
427 | + // generate a correctly translated string for all possible singular/plural combinations |
|
428 | + if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
429 | + $error_msg = sprintf( |
|
430 | + esc_html_x( |
|
431 | + 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
432 | + 'There was 1 ticket in the Event Queue, but 2 registrations were processed', |
|
433 | + 'event_espresso' |
|
434 | + ), |
|
435 | + $this->checkout->total_ticket_count, |
|
436 | + $registrations_processed |
|
437 | + ); |
|
438 | + } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
439 | + $error_msg = sprintf( |
|
440 | + esc_html_x( |
|
441 | + 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
442 | + 'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed', |
|
443 | + 'event_espresso' |
|
444 | + ), |
|
445 | + $this->checkout->total_ticket_count, |
|
446 | + $registrations_processed |
|
447 | + ); |
|
448 | + } else { |
|
449 | + $error_msg = sprintf( |
|
450 | + esc_html__( |
|
451 | + 'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed', |
|
452 | + 'event_espresso' |
|
453 | + ), |
|
454 | + $this->checkout->total_ticket_count, |
|
455 | + $registrations_processed |
|
456 | + ); |
|
457 | + } |
|
458 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
459 | + return false; |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * update_reg_step |
|
465 | + * this is the final step after a user revisits the site to edit their attendee information |
|
466 | + * this gets called AFTER the process_reg_step() method above |
|
467 | + * |
|
468 | + * @return bool |
|
469 | + * @throws EE_Error |
|
470 | + * @throws InvalidArgumentException |
|
471 | + * @throws ReflectionException |
|
472 | + * @throws RuntimeException |
|
473 | + * @throws InvalidDataTypeException |
|
474 | + * @throws InvalidInterfaceException |
|
475 | + */ |
|
476 | + public function update_reg_step(): bool |
|
477 | + { |
|
478 | + // save everything |
|
479 | + if ($this->process_reg_step()) { |
|
480 | + $this->checkout->redirect = true; |
|
481 | + $this->checkout->redirect_url = add_query_arg( |
|
482 | + [ |
|
483 | + 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
484 | + 'revisit' => true, |
|
485 | + ], |
|
486 | + $this->checkout->thank_you_page_url |
|
487 | + ); |
|
488 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
489 | + return true; |
|
490 | + } |
|
491 | + return false; |
|
492 | + } |
|
493 | 493 | } |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | |
54 | 54 | public function translate_js_strings() |
55 | 55 | { |
56 | - EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
56 | + EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
57 | 57 | ' is a required question.', |
58 | 58 | 'event_espresso' |
59 | 59 | ); |
60 | - EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
60 | + EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
61 | 61 | ' is a required question. Please enter a value for at least one of the options.', |
62 | 62 | 'event_espresso' |
63 | 63 | ); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | 'Please answer all required questions correctly before proceeding.', |
66 | 66 | 'event_espresso' |
67 | 67 | ); |
68 | - EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
68 | + EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
69 | 69 | esc_html_x( |
70 | 70 | 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
71 | 71 | 'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.', |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | ), |
74 | 74 | '<br/>' |
75 | 75 | ); |
76 | - EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
76 | + EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
77 | 77 | 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
78 | 78 | 'event_espresso' |
79 | 79 | ); |
80 | - EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
80 | + EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
81 | 81 | 'You must enter a valid email address.', |
82 | 82 | 'event_espresso' |
83 | 83 | ); |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | if (empty($valid_data)) { |
323 | 323 | return $this->inValidDataError(); |
324 | 324 | } |
325 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
325 | + if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
326 | 326 | return $this->inValidTransactionError(); |
327 | 327 | } |
328 | 328 | // get cached registrations |
@@ -334,14 +334,14 @@ discard block |
||
334 | 334 | /** @var RegFormHandler $reg_form_handler */ |
335 | 335 | $reg_form_handler = LoaderFactory::getNew(RegFormHandler::class, [$this->checkout]); |
336 | 336 | // extract attendee info from form data and save to model objects |
337 | - if (! $reg_form_handler->processRegistrations($registrations, $valid_data)) { |
|
337 | + if ( ! $reg_form_handler->processRegistrations($registrations, $valid_data)) { |
|
338 | 338 | // return immediately if the previous step exited early due to errors |
339 | 339 | return false; |
340 | 340 | } |
341 | 341 | // if first pass thru SPCO, |
342 | 342 | // then let's check processed registrations against the total number of tickets in the cart |
343 | 343 | $registrations_processed = $reg_form_handler->attendeeCount(); |
344 | - if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
344 | + if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
345 | 345 | return $this->registrationProcessingError($registrations_processed); |
346 | 346 | } |
347 | 347 | // mark this reg step as completed |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | '(line break)This can sometimes happen if too much time has been taken to complete the registration process.(line break)Please return to the (link)Event List(end link) and reselect your tickets. If the problem continues, please contact the site administrator.', |
409 | 409 | 'event_espresso' |
410 | 410 | ), |
411 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
411 | + '<a href="'.get_post_type_archive_link('espresso_events').'" >', |
|
412 | 412 | '</a>', |
413 | 413 | '<br />' |
414 | 414 | ); |