@@ -18,1453 +18,1453 @@ |
||
18 | 18 | class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @type bool $_print_copy_info |
|
23 | - */ |
|
24 | - private $_print_copy_info = false; |
|
25 | - |
|
26 | - /** |
|
27 | - * @type array $_attendee_data |
|
28 | - */ |
|
29 | - private $_attendee_data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * @type array $_required_questions |
|
33 | - */ |
|
34 | - private $_required_questions = array(); |
|
35 | - |
|
36 | - /** |
|
37 | - * @type array $_registration_answers |
|
38 | - */ |
|
39 | - private $_registration_answers = array(); |
|
21 | + /** |
|
22 | + * @type bool $_print_copy_info |
|
23 | + */ |
|
24 | + private $_print_copy_info = false; |
|
25 | + |
|
26 | + /** |
|
27 | + * @type array $_attendee_data |
|
28 | + */ |
|
29 | + private $_attendee_data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * @type array $_required_questions |
|
33 | + */ |
|
34 | + private $_required_questions = array(); |
|
35 | + |
|
36 | + /** |
|
37 | + * @type array $_registration_answers |
|
38 | + */ |
|
39 | + private $_registration_answers = array(); |
|
40 | 40 | |
41 | - /** |
|
42 | - * @type int $reg_form_count |
|
43 | - */ |
|
44 | - protected $reg_form_count = 0; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * class constructor |
|
49 | - * |
|
50 | - * @access public |
|
51 | - * @param EE_Checkout $checkout |
|
52 | - */ |
|
53 | - public function __construct(EE_Checkout $checkout) |
|
54 | - { |
|
55 | - $this->_slug = 'attendee_information'; |
|
56 | - $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
57 | - $this->checkout = $checkout; |
|
58 | - $this->_reset_success_message(); |
|
59 | - $this->set_instructions( |
|
60 | - esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
61 | - ); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - public function translate_js_strings() |
|
66 | - { |
|
67 | - EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
68 | - ' is a required question.', |
|
69 | - 'event_espresso' |
|
70 | - ); |
|
71 | - EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
72 | - ' is a required question. Please enter a value for at least one of the options.', |
|
73 | - 'event_espresso' |
|
74 | - ); |
|
75 | - EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
76 | - 'Please answer all required questions correctly before proceeding.', |
|
77 | - 'event_espresso' |
|
78 | - ); |
|
79 | - EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
80 | - esc_html_x( |
|
81 | - 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
82 | - 'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.', |
|
83 | - 'event_espresso' |
|
84 | - ), |
|
85 | - '<br/>' |
|
86 | - ); |
|
87 | - EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
88 | - 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
89 | - 'event_espresso' |
|
90 | - ); |
|
91 | - EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
92 | - 'You must enter a valid email address.', |
|
93 | - 'event_espresso' |
|
94 | - ); |
|
95 | - EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
96 | - 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
97 | - 'event_espresso' |
|
98 | - ); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - public function enqueue_styles_and_scripts() |
|
103 | - { |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @return boolean |
|
109 | - */ |
|
110 | - public function initialize_reg_step() |
|
111 | - { |
|
112 | - return true; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * @return EE_Form_Section_Proper |
|
118 | - * @throws DomainException |
|
119 | - * @throws EE_Error |
|
120 | - * @throws InvalidArgumentException |
|
121 | - * @throws ReflectionException |
|
122 | - * @throws EntityNotFoundException |
|
123 | - * @throws InvalidDataTypeException |
|
124 | - * @throws InvalidInterfaceException |
|
125 | - */ |
|
126 | - public function generate_reg_form() |
|
127 | - { |
|
128 | - /** |
|
129 | - * @var $reg_config EE_Registration_Config |
|
130 | - */ |
|
131 | - $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
41 | + /** |
|
42 | + * @type int $reg_form_count |
|
43 | + */ |
|
44 | + protected $reg_form_count = 0; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * class constructor |
|
49 | + * |
|
50 | + * @access public |
|
51 | + * @param EE_Checkout $checkout |
|
52 | + */ |
|
53 | + public function __construct(EE_Checkout $checkout) |
|
54 | + { |
|
55 | + $this->_slug = 'attendee_information'; |
|
56 | + $this->_name = esc_html__('Attendee Information', 'event_espresso'); |
|
57 | + $this->checkout = $checkout; |
|
58 | + $this->_reset_success_message(); |
|
59 | + $this->set_instructions( |
|
60 | + esc_html__('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
61 | + ); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + public function translate_js_strings() |
|
66 | + { |
|
67 | + EE_Registry::$i18n_js_strings['required_field'] = esc_html__( |
|
68 | + ' is a required question.', |
|
69 | + 'event_espresso' |
|
70 | + ); |
|
71 | + EE_Registry::$i18n_js_strings['required_multi_field'] = esc_html__( |
|
72 | + ' is a required question. Please enter a value for at least one of the options.', |
|
73 | + 'event_espresso' |
|
74 | + ); |
|
75 | + EE_Registry::$i18n_js_strings['answer_required_questions'] = esc_html__( |
|
76 | + 'Please answer all required questions correctly before proceeding.', |
|
77 | + 'event_espresso' |
|
78 | + ); |
|
79 | + EE_Registry::$i18n_js_strings['attendee_info_copied'] = sprintf( |
|
80 | + esc_html_x( |
|
81 | + 'The attendee information was successfully copied.%sPlease ensure the rest of the registration form is completed before proceeding.', |
|
82 | + 'The attendee information was successfully copied.(line break)Please ensure the rest of the registration form is completed before proceeding.', |
|
83 | + 'event_espresso' |
|
84 | + ), |
|
85 | + '<br/>' |
|
86 | + ); |
|
87 | + EE_Registry::$i18n_js_strings['attendee_info_copy_error'] = esc_html__( |
|
88 | + 'An unknown error occurred on the server while attempting to copy the attendee information. Please refresh the page and try again.', |
|
89 | + 'event_espresso' |
|
90 | + ); |
|
91 | + EE_Registry::$i18n_js_strings['enter_valid_email'] = esc_html__( |
|
92 | + 'You must enter a valid email address.', |
|
93 | + 'event_espresso' |
|
94 | + ); |
|
95 | + EE_Registry::$i18n_js_strings['valid_email_and_questions'] = esc_html__( |
|
96 | + 'You must enter a valid email address and answer all other required questions before you can proceed.', |
|
97 | + 'event_espresso' |
|
98 | + ); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + public function enqueue_styles_and_scripts() |
|
103 | + { |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @return boolean |
|
109 | + */ |
|
110 | + public function initialize_reg_step() |
|
111 | + { |
|
112 | + return true; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * @return EE_Form_Section_Proper |
|
118 | + * @throws DomainException |
|
119 | + * @throws EE_Error |
|
120 | + * @throws InvalidArgumentException |
|
121 | + * @throws ReflectionException |
|
122 | + * @throws EntityNotFoundException |
|
123 | + * @throws InvalidDataTypeException |
|
124 | + * @throws InvalidInterfaceException |
|
125 | + */ |
|
126 | + public function generate_reg_form() |
|
127 | + { |
|
128 | + /** |
|
129 | + * @var $reg_config EE_Registration_Config |
|
130 | + */ |
|
131 | + $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
132 | 132 | |
133 | - $this->_print_copy_info = $reg_config->copyAttendeeInfo(); |
|
134 | - |
|
135 | - // Init reg forms count. |
|
136 | - $this->reg_form_count = 0; |
|
137 | - |
|
138 | - $primary_registrant = null; |
|
139 | - // autoload Line_Item_Display classes |
|
140 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
141 | - $Line_Item_Display = new EE_Line_Item_Display(); |
|
142 | - // calculate taxes |
|
143 | - $Line_Item_Display->display_line_item( |
|
144 | - $this->checkout->cart->get_grand_total(), |
|
145 | - array('set_tax_rate' => true) |
|
146 | - ); |
|
147 | - /** @var $subsections EE_Form_Section_Proper[] */ |
|
148 | - $extra_inputs_section = $this->reg_step_hidden_inputs(); |
|
149 | - $subsections = array( |
|
150 | - 'default_hidden_inputs' => $extra_inputs_section, |
|
151 | - ); |
|
152 | - |
|
153 | - // if this isn't a revisit, and they have the privacy consent box enalbed, add it |
|
154 | - if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
155 | - $extra_inputs_section->add_subsections( |
|
156 | - array( |
|
157 | - 'consent_box' => new EE_Form_Section_Proper( |
|
158 | - array( |
|
159 | - 'layout_strategy' => |
|
160 | - new EE_Template_Layout( |
|
161 | - array( |
|
162 | - 'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php', |
|
163 | - ) |
|
164 | - ), |
|
165 | - 'subsections' => array( |
|
166 | - 'consent' => new EE_Checkbox_Multi_Input( |
|
167 | - array( |
|
168 | - 'consent' => $reg_config->getConsentCheckboxLabelText(), |
|
169 | - ), |
|
170 | - array( |
|
171 | - 'required' => true, |
|
172 | - 'required_validation_error_message' => esc_html__( |
|
173 | - 'You must consent to these terms in order to register.', |
|
174 | - 'event_espresso' |
|
175 | - ), |
|
176 | - 'html_label_text' => '', |
|
177 | - ) |
|
178 | - ), |
|
179 | - ), |
|
180 | - ) |
|
181 | - ), |
|
182 | - ), |
|
183 | - null, |
|
184 | - false |
|
185 | - ); |
|
186 | - } |
|
187 | - $template_args = array( |
|
188 | - 'revisit' => $this->checkout->revisit, |
|
189 | - 'registrations' => array(), |
|
190 | - 'ticket_count' => array(), |
|
191 | - ); |
|
192 | - // grab the saved registrations from the transaction |
|
193 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
194 | - if ($registrations) { |
|
195 | - foreach ($registrations as $registration) { |
|
196 | - // can this registration be processed during this visit ? |
|
197 | - if ($registration instanceof EE_Registration |
|
198 | - && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
199 | - ) { |
|
200 | - $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration); |
|
201 | - $template_args['registrations'][ $registration->reg_url_link() ] = $registration; |
|
202 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
203 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
204 | - ) |
|
205 | - ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
206 | - : 1; |
|
207 | - $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
208 | - $this->checkout->cart->get_grand_total(), |
|
209 | - 'Ticket', |
|
210 | - array($registration->ticket()->ID()) |
|
211 | - ); |
|
212 | - $ticket_line_item = is_array($ticket_line_item) |
|
213 | - ? reset($ticket_line_item) |
|
214 | - : $ticket_line_item; |
|
215 | - $template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
216 | - $Line_Item_Display->display_line_item($ticket_line_item); |
|
217 | - if ($registration->is_primary_registrant()) { |
|
218 | - $primary_registrant = $registration->reg_url_link(); |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - if ($primary_registrant && count($registrations) > 1) { |
|
224 | - $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
225 | - ? $this->_copy_attendee_info_form() |
|
226 | - : $this->_auto_copy_attendee_info(); |
|
227 | - // generate hidden input |
|
228 | - if (isset($subsections[ $primary_registrant ]) |
|
229 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
230 | - ) { |
|
231 | - $subsections[ $primary_registrant ]->add_subsections( |
|
232 | - $copy_options, |
|
233 | - 'primary_registrant', |
|
234 | - false |
|
235 | - ); |
|
236 | - } |
|
237 | - } |
|
238 | - } |
|
239 | - |
|
240 | - // Set the registration form template (default: one form per ticket details table). |
|
241 | - // We decide the template to used based on the number of forms. |
|
242 | - $this->_template = $this->reg_form_count > 1 |
|
243 | - ? SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php' |
|
244 | - : SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_single.template.php'; |
|
245 | - |
|
246 | - return new EE_Form_Section_Proper( |
|
247 | - array( |
|
248 | - 'name' => $this->reg_form_name(), |
|
249 | - 'html_id' => $this->reg_form_name(), |
|
250 | - 'subsections' => $subsections, |
|
251 | - 'layout_strategy' => new EE_Template_Layout( |
|
252 | - array( |
|
253 | - 'layout_template_file' => $this->_template, // layout_template |
|
254 | - 'template_args' => $template_args, |
|
255 | - ) |
|
256 | - ), |
|
257 | - ) |
|
258 | - ); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @param EE_Registration $registration |
|
264 | - * @return EE_Form_Section_Base |
|
265 | - * @throws EE_Error |
|
266 | - * @throws InvalidArgumentException |
|
267 | - * @throws EntityNotFoundException |
|
268 | - * @throws InvalidDataTypeException |
|
269 | - * @throws InvalidInterfaceException |
|
270 | - * @throws ReflectionException |
|
271 | - */ |
|
272 | - private function _registrations_reg_form(EE_Registration $registration) |
|
273 | - { |
|
274 | - static $attendee_nmbr = 1; |
|
275 | - $form_args = array(); |
|
276 | - // verify that registration has valid event |
|
277 | - if ($registration->event() instanceof EE_Event) { |
|
278 | - $field_name = 'Event_Question_Group.' |
|
279 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
280 | - $registration->is_primary_registrant() |
|
281 | - ); |
|
282 | - $question_groups = $registration->event()->question_groups( |
|
283 | - apply_filters( |
|
284 | - // @codingStandardsIgnoreStart |
|
285 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
286 | - // @codingStandardsIgnoreEnd |
|
287 | - [ |
|
288 | - [ |
|
289 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
290 | - $field_name => true, |
|
291 | - ], |
|
292 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
293 | - ], |
|
294 | - $registration, |
|
295 | - $this |
|
296 | - ) |
|
297 | - ); |
|
298 | - if ($question_groups) { |
|
299 | - // array of params to pass to parent constructor |
|
300 | - $form_args = array( |
|
301 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
302 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
303 | - 'html_style' => $this->checkout->admin_request |
|
304 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
305 | - : '', |
|
306 | - 'subsections' => array(), |
|
307 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
308 | - array( |
|
309 | - 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
310 | - 'legend_text' => sprintf( |
|
311 | - esc_html_x( |
|
312 | - 'Attendee %d', |
|
313 | - 'Attendee 123', |
|
314 | - 'event_espresso' |
|
315 | - ), |
|
316 | - $attendee_nmbr |
|
317 | - ), |
|
318 | - ) |
|
319 | - ), |
|
320 | - ); |
|
321 | - foreach ($question_groups as $question_group) { |
|
322 | - if ($question_group instanceof EE_Question_Group) { |
|
323 | - $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
324 | - $registration, |
|
325 | - $question_group |
|
326 | - ); |
|
327 | - } |
|
328 | - } |
|
329 | - // add hidden input |
|
330 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
331 | - $registration |
|
332 | - ); |
|
333 | - |
|
334 | - /** |
|
335 | - * @var $reg_config EE_Registration_Config |
|
336 | - */ |
|
337 | - $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
338 | - |
|
339 | - // If we have question groups for additional attendees, then display the copy options |
|
340 | - $this->_print_copy_info = apply_filters( |
|
341 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo', |
|
342 | - $attendee_nmbr > 1 ? $reg_config->copyAttendeeInfo() : false, |
|
343 | - $attendee_nmbr |
|
344 | - ); |
|
345 | - |
|
346 | - if ($registration->is_primary_registrant()) { |
|
347 | - // generate hidden input |
|
348 | - $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
349 | - $registration |
|
350 | - ); |
|
351 | - } |
|
352 | - } |
|
353 | - } |
|
354 | - $attendee_nmbr++; |
|
133 | + $this->_print_copy_info = $reg_config->copyAttendeeInfo(); |
|
134 | + |
|
135 | + // Init reg forms count. |
|
136 | + $this->reg_form_count = 0; |
|
137 | + |
|
138 | + $primary_registrant = null; |
|
139 | + // autoload Line_Item_Display classes |
|
140 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
141 | + $Line_Item_Display = new EE_Line_Item_Display(); |
|
142 | + // calculate taxes |
|
143 | + $Line_Item_Display->display_line_item( |
|
144 | + $this->checkout->cart->get_grand_total(), |
|
145 | + array('set_tax_rate' => true) |
|
146 | + ); |
|
147 | + /** @var $subsections EE_Form_Section_Proper[] */ |
|
148 | + $extra_inputs_section = $this->reg_step_hidden_inputs(); |
|
149 | + $subsections = array( |
|
150 | + 'default_hidden_inputs' => $extra_inputs_section, |
|
151 | + ); |
|
152 | + |
|
153 | + // if this isn't a revisit, and they have the privacy consent box enalbed, add it |
|
154 | + if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
155 | + $extra_inputs_section->add_subsections( |
|
156 | + array( |
|
157 | + 'consent_box' => new EE_Form_Section_Proper( |
|
158 | + array( |
|
159 | + 'layout_strategy' => |
|
160 | + new EE_Template_Layout( |
|
161 | + array( |
|
162 | + 'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php', |
|
163 | + ) |
|
164 | + ), |
|
165 | + 'subsections' => array( |
|
166 | + 'consent' => new EE_Checkbox_Multi_Input( |
|
167 | + array( |
|
168 | + 'consent' => $reg_config->getConsentCheckboxLabelText(), |
|
169 | + ), |
|
170 | + array( |
|
171 | + 'required' => true, |
|
172 | + 'required_validation_error_message' => esc_html__( |
|
173 | + 'You must consent to these terms in order to register.', |
|
174 | + 'event_espresso' |
|
175 | + ), |
|
176 | + 'html_label_text' => '', |
|
177 | + ) |
|
178 | + ), |
|
179 | + ), |
|
180 | + ) |
|
181 | + ), |
|
182 | + ), |
|
183 | + null, |
|
184 | + false |
|
185 | + ); |
|
186 | + } |
|
187 | + $template_args = array( |
|
188 | + 'revisit' => $this->checkout->revisit, |
|
189 | + 'registrations' => array(), |
|
190 | + 'ticket_count' => array(), |
|
191 | + ); |
|
192 | + // grab the saved registrations from the transaction |
|
193 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
194 | + if ($registrations) { |
|
195 | + foreach ($registrations as $registration) { |
|
196 | + // can this registration be processed during this visit ? |
|
197 | + if ($registration instanceof EE_Registration |
|
198 | + && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
199 | + ) { |
|
200 | + $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration); |
|
201 | + $template_args['registrations'][ $registration->reg_url_link() ] = $registration; |
|
202 | + $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
203 | + $template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
204 | + ) |
|
205 | + ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
206 | + : 1; |
|
207 | + $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
208 | + $this->checkout->cart->get_grand_total(), |
|
209 | + 'Ticket', |
|
210 | + array($registration->ticket()->ID()) |
|
211 | + ); |
|
212 | + $ticket_line_item = is_array($ticket_line_item) |
|
213 | + ? reset($ticket_line_item) |
|
214 | + : $ticket_line_item; |
|
215 | + $template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
216 | + $Line_Item_Display->display_line_item($ticket_line_item); |
|
217 | + if ($registration->is_primary_registrant()) { |
|
218 | + $primary_registrant = $registration->reg_url_link(); |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + if ($primary_registrant && count($registrations) > 1) { |
|
224 | + $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
|
225 | + ? $this->_copy_attendee_info_form() |
|
226 | + : $this->_auto_copy_attendee_info(); |
|
227 | + // generate hidden input |
|
228 | + if (isset($subsections[ $primary_registrant ]) |
|
229 | + && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
230 | + ) { |
|
231 | + $subsections[ $primary_registrant ]->add_subsections( |
|
232 | + $copy_options, |
|
233 | + 'primary_registrant', |
|
234 | + false |
|
235 | + ); |
|
236 | + } |
|
237 | + } |
|
238 | + } |
|
239 | + |
|
240 | + // Set the registration form template (default: one form per ticket details table). |
|
241 | + // We decide the template to used based on the number of forms. |
|
242 | + $this->_template = $this->reg_form_count > 1 |
|
243 | + ? SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php' |
|
244 | + : SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_single.template.php'; |
|
245 | + |
|
246 | + return new EE_Form_Section_Proper( |
|
247 | + array( |
|
248 | + 'name' => $this->reg_form_name(), |
|
249 | + 'html_id' => $this->reg_form_name(), |
|
250 | + 'subsections' => $subsections, |
|
251 | + 'layout_strategy' => new EE_Template_Layout( |
|
252 | + array( |
|
253 | + 'layout_template_file' => $this->_template, // layout_template |
|
254 | + 'template_args' => $template_args, |
|
255 | + ) |
|
256 | + ), |
|
257 | + ) |
|
258 | + ); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @param EE_Registration $registration |
|
264 | + * @return EE_Form_Section_Base |
|
265 | + * @throws EE_Error |
|
266 | + * @throws InvalidArgumentException |
|
267 | + * @throws EntityNotFoundException |
|
268 | + * @throws InvalidDataTypeException |
|
269 | + * @throws InvalidInterfaceException |
|
270 | + * @throws ReflectionException |
|
271 | + */ |
|
272 | + private function _registrations_reg_form(EE_Registration $registration) |
|
273 | + { |
|
274 | + static $attendee_nmbr = 1; |
|
275 | + $form_args = array(); |
|
276 | + // verify that registration has valid event |
|
277 | + if ($registration->event() instanceof EE_Event) { |
|
278 | + $field_name = 'Event_Question_Group.' |
|
279 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
280 | + $registration->is_primary_registrant() |
|
281 | + ); |
|
282 | + $question_groups = $registration->event()->question_groups( |
|
283 | + apply_filters( |
|
284 | + // @codingStandardsIgnoreStart |
|
285 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form__question_groups_query_parameters', |
|
286 | + // @codingStandardsIgnoreEnd |
|
287 | + [ |
|
288 | + [ |
|
289 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
290 | + $field_name => true, |
|
291 | + ], |
|
292 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
293 | + ], |
|
294 | + $registration, |
|
295 | + $this |
|
296 | + ) |
|
297 | + ); |
|
298 | + if ($question_groups) { |
|
299 | + // array of params to pass to parent constructor |
|
300 | + $form_args = array( |
|
301 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
302 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
303 | + 'html_style' => $this->checkout->admin_request |
|
304 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
305 | + : '', |
|
306 | + 'subsections' => array(), |
|
307 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
308 | + array( |
|
309 | + 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
310 | + 'legend_text' => sprintf( |
|
311 | + esc_html_x( |
|
312 | + 'Attendee %d', |
|
313 | + 'Attendee 123', |
|
314 | + 'event_espresso' |
|
315 | + ), |
|
316 | + $attendee_nmbr |
|
317 | + ), |
|
318 | + ) |
|
319 | + ), |
|
320 | + ); |
|
321 | + foreach ($question_groups as $question_group) { |
|
322 | + if ($question_group instanceof EE_Question_Group) { |
|
323 | + $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
324 | + $registration, |
|
325 | + $question_group |
|
326 | + ); |
|
327 | + } |
|
328 | + } |
|
329 | + // add hidden input |
|
330 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
331 | + $registration |
|
332 | + ); |
|
333 | + |
|
334 | + /** |
|
335 | + * @var $reg_config EE_Registration_Config |
|
336 | + */ |
|
337 | + $reg_config = LoaderFactory::getLoader()->getShared('EE_Registration_Config'); |
|
338 | + |
|
339 | + // If we have question groups for additional attendees, then display the copy options |
|
340 | + $this->_print_copy_info = apply_filters( |
|
341 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___registrations_reg_form___printCopyInfo', |
|
342 | + $attendee_nmbr > 1 ? $reg_config->copyAttendeeInfo() : false, |
|
343 | + $attendee_nmbr |
|
344 | + ); |
|
345 | + |
|
346 | + if ($registration->is_primary_registrant()) { |
|
347 | + // generate hidden input |
|
348 | + $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs( |
|
349 | + $registration |
|
350 | + ); |
|
351 | + } |
|
352 | + } |
|
353 | + } |
|
354 | + $attendee_nmbr++; |
|
355 | 355 | |
356 | - // Increment the reg forms number if form is valid. |
|
357 | - if (!empty($form_args)) { |
|
358 | - $this->reg_form_count++; |
|
359 | - } |
|
360 | - |
|
361 | - return ! empty($form_args) |
|
362 | - ? new EE_Form_Section_Proper($form_args) |
|
363 | - : new EE_Form_Section_HTML(); |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * @param EE_Registration $registration |
|
369 | - * @param bool $additional_attendee_reg_info |
|
370 | - * @return EE_Form_Input_Base |
|
371 | - * @throws EE_Error |
|
372 | - */ |
|
373 | - private function _additional_attendee_reg_info_input( |
|
374 | - EE_Registration $registration, |
|
375 | - $additional_attendee_reg_info = true |
|
376 | - ) { |
|
377 | - // generate hidden input |
|
378 | - return new EE_Hidden_Input( |
|
379 | - array( |
|
380 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
381 | - 'default' => $additional_attendee_reg_info, |
|
382 | - ) |
|
383 | - ); |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * @param EE_Registration $registration |
|
389 | - * @param EE_Question_Group $question_group |
|
390 | - * @return EE_Form_Section_Proper |
|
391 | - * @throws EE_Error |
|
392 | - * @throws InvalidArgumentException |
|
393 | - * @throws InvalidDataTypeException |
|
394 | - * @throws InvalidInterfaceException |
|
395 | - * @throws ReflectionException |
|
396 | - */ |
|
397 | - private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
398 | - { |
|
399 | - // array of params to pass to parent constructor |
|
400 | - $form_args = array( |
|
401 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
402 | - 'html_class' => $this->checkout->admin_request |
|
403 | - ? 'form-table ee-reg-form-qstn-grp-dv' |
|
404 | - : 'ee-reg-form-qstn-grp-dv', |
|
405 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' |
|
406 | - . $registration->ID() . '-lbl', |
|
407 | - 'subsections' => array( |
|
408 | - 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
409 | - ), |
|
410 | - 'layout_strategy' => $this->checkout->admin_request |
|
411 | - ? new EE_Admin_Two_Column_Layout() |
|
412 | - : new EE_Div_Per_Section_Layout(), |
|
413 | - ); |
|
414 | - // where params |
|
415 | - $query_params = array('QST_deleted' => 0); |
|
416 | - // don't load admin only questions on the frontend |
|
417 | - if (! $this->checkout->admin_request) { |
|
418 | - $query_params['QST_admin_only'] = array('!=', true); |
|
419 | - } |
|
420 | - $questions = $question_group->get_many_related( |
|
421 | - 'Question', |
|
422 | - apply_filters( |
|
423 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
424 | - array( |
|
425 | - $query_params, |
|
426 | - 'order_by' => array( |
|
427 | - 'Question_Group_Question.QGQ_order' => 'ASC', |
|
428 | - ), |
|
429 | - ), |
|
430 | - $question_group, |
|
431 | - $registration, |
|
432 | - $this |
|
433 | - ) |
|
434 | - ); |
|
435 | - // filter for additional content before questions |
|
436 | - $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
437 | - apply_filters( |
|
438 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
439 | - '', |
|
440 | - $registration, |
|
441 | - $question_group, |
|
442 | - $this |
|
443 | - ) |
|
444 | - ); |
|
445 | - // loop thru questions |
|
446 | - foreach ($questions as $question) { |
|
447 | - if ($question instanceof EE_Question) { |
|
448 | - $identifier = $question->is_system_question() |
|
449 | - ? $question->system_ID() |
|
450 | - : $question->ID(); |
|
451 | - $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question); |
|
452 | - } |
|
453 | - } |
|
454 | - $form_args['subsections'] = apply_filters( |
|
455 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
456 | - $form_args['subsections'], |
|
457 | - $registration, |
|
458 | - $question_group, |
|
459 | - $this |
|
460 | - ); |
|
461 | - // filter for additional content after questions |
|
462 | - $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
463 | - apply_filters( |
|
464 | - 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
465 | - '', |
|
466 | - $registration, |
|
467 | - $question_group, |
|
468 | - $this |
|
469 | - ) |
|
470 | - ); |
|
471 | - // d($form_args); |
|
472 | - $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
473 | - return apply_filters( |
|
474 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
475 | - $question_group_reg_form, |
|
476 | - $registration, |
|
477 | - $question_group, |
|
478 | - $this |
|
479 | - ); |
|
480 | - } |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * @param EE_Question_Group $question_group |
|
485 | - * @return EE_Form_Section_HTML |
|
486 | - */ |
|
487 | - private function _question_group_header(EE_Question_Group $question_group) |
|
488 | - { |
|
489 | - $html = ''; |
|
490 | - // group_name |
|
491 | - if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
492 | - if ($this->checkout->admin_request) { |
|
493 | - $html .= EEH_HTML::br(); |
|
494 | - $html .= EEH_HTML::h3( |
|
495 | - $question_group->name(), |
|
496 | - '', |
|
497 | - 'ee-reg-form-qstn-grp-title title', |
|
498 | - 'font-size: 1.3em; padding-left:0;' |
|
499 | - ); |
|
500 | - } else { |
|
501 | - $html .= EEH_HTML::h4( |
|
502 | - $question_group->name(), |
|
503 | - '', |
|
504 | - 'ee-reg-form-qstn-grp-title section-title' |
|
505 | - ); |
|
506 | - } |
|
507 | - } |
|
508 | - // group_desc |
|
509 | - if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
510 | - $html .= EEH_HTML::p( |
|
511 | - $question_group->desc(), |
|
512 | - '', |
|
513 | - $this->checkout->admin_request |
|
514 | - ? 'ee-reg-form-qstn-grp-desc-pg' |
|
515 | - : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
516 | - ); |
|
517 | - } |
|
518 | - return new EE_Form_Section_HTML($html); |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - /** |
|
523 | - * @return EE_Form_Section_Proper |
|
524 | - * @throws EE_Error |
|
525 | - * @throws InvalidArgumentException |
|
526 | - * @throws ReflectionException |
|
527 | - * @throws InvalidDataTypeException |
|
528 | - * @throws InvalidInterfaceException |
|
529 | - */ |
|
530 | - private function _copy_attendee_info_form() |
|
531 | - { |
|
532 | - // array of params to pass to parent constructor |
|
533 | - return new EE_Form_Section_Proper( |
|
534 | - array( |
|
535 | - 'subsections' => $this->_copy_attendee_info_inputs(), |
|
536 | - 'layout_strategy' => new EE_Template_Layout( |
|
537 | - array( |
|
538 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
539 | - . $this->_slug |
|
540 | - . '/copy_attendee_info.template.php', |
|
541 | - 'begin_template_file' => null, |
|
542 | - 'input_template_file' => null, |
|
543 | - 'subsection_template_file' => null, |
|
544 | - 'end_template_file' => null, |
|
545 | - ) |
|
546 | - ), |
|
547 | - ) |
|
548 | - ); |
|
549 | - } |
|
550 | - |
|
551 | - |
|
552 | - /** |
|
553 | - * @return EE_Form_Section_HTML |
|
554 | - * @throws DomainException |
|
555 | - * @throws InvalidArgumentException |
|
556 | - * @throws InvalidDataTypeException |
|
557 | - * @throws InvalidInterfaceException |
|
558 | - */ |
|
559 | - private function _auto_copy_attendee_info() |
|
560 | - { |
|
561 | - return new EE_Form_Section_HTML( |
|
562 | - EEH_Template::locate_template( |
|
563 | - SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php', |
|
564 | - apply_filters( |
|
565 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
566 | - array() |
|
567 | - ), |
|
568 | - true, |
|
569 | - true |
|
570 | - ) |
|
571 | - ); |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - /** |
|
576 | - * @return array |
|
577 | - * @throws EE_Error |
|
578 | - * @throws InvalidArgumentException |
|
579 | - * @throws ReflectionException |
|
580 | - * @throws InvalidDataTypeException |
|
581 | - * @throws InvalidInterfaceException |
|
582 | - */ |
|
583 | - private function _copy_attendee_info_inputs() |
|
584 | - { |
|
585 | - $copy_attendee_info_inputs = array(); |
|
586 | - $prev_ticket = null; |
|
587 | - // grab the saved registrations from the transaction |
|
588 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
589 | - foreach ($registrations as $registration) { |
|
590 | - // for all attendees other than the primary attendee |
|
591 | - if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
592 | - // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
593 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
594 | - $item_name = $registration->ticket()->name(); |
|
595 | - $item_name .= $registration->ticket()->description() !== '' |
|
596 | - ? ' - ' . $registration->ticket()->description() |
|
597 | - : ''; |
|
598 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID( |
|
599 | - ) . ']' ] = |
|
600 | - new EE_Form_Section_HTML( |
|
601 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
602 | - ); |
|
603 | - $prev_ticket = $registration->ticket()->ID(); |
|
604 | - } |
|
605 | - |
|
606 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = |
|
607 | - new EE_Checkbox_Multi_Input( |
|
608 | - array( |
|
609 | - $registration->ID() => sprintf( |
|
610 | - esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
611 | - $registration->count() |
|
612 | - ), |
|
613 | - ), |
|
614 | - array( |
|
615 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
616 | - 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
617 | - 'display_html_label_text' => false, |
|
618 | - ) |
|
619 | - ); |
|
620 | - } |
|
621 | - } |
|
622 | - return $copy_attendee_info_inputs; |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - /** |
|
627 | - * @param EE_Registration $registration |
|
628 | - * @return EE_Form_Input_Base |
|
629 | - * @throws EE_Error |
|
630 | - */ |
|
631 | - private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
632 | - { |
|
633 | - // generate hidden input |
|
634 | - return new EE_Hidden_Input( |
|
635 | - array( |
|
636 | - 'html_id' => 'primary_registrant', |
|
637 | - 'default' => $registration->reg_url_link(), |
|
638 | - ) |
|
639 | - ); |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - /** |
|
644 | - * @param EE_Registration $registration |
|
645 | - * @param EE_Question $question |
|
646 | - * @return EE_Form_Input_Base |
|
647 | - * @throws EE_Error |
|
648 | - * @throws InvalidArgumentException |
|
649 | - * @throws InvalidDataTypeException |
|
650 | - * @throws InvalidInterfaceException |
|
651 | - * @throws ReflectionException |
|
652 | - */ |
|
653 | - public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
654 | - { |
|
655 | - |
|
656 | - // if this question was for an attendee detail, then check for that answer |
|
657 | - $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
658 | - $registration, |
|
659 | - $question->system_ID() |
|
660 | - ); |
|
661 | - $answer = $answer_value === null |
|
662 | - ? EEM_Answer::instance()->get_one( |
|
663 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
664 | - ) |
|
665 | - : null; |
|
666 | - // if NOT returning to edit an existing registration |
|
667 | - // OR if this question is for an attendee property |
|
668 | - // OR we still don't have an EE_Answer object |
|
669 | - if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
670 | - // create an EE_Answer object for storing everything in |
|
671 | - $answer = EE_Answer::new_instance( |
|
672 | - array( |
|
673 | - 'QST_ID' => $question->ID(), |
|
674 | - 'REG_ID' => $registration->ID(), |
|
675 | - ) |
|
676 | - ); |
|
677 | - } |
|
678 | - // verify instance |
|
679 | - if ($answer instanceof EE_Answer) { |
|
680 | - if (! empty($answer_value)) { |
|
681 | - $answer->set('ANS_value', $answer_value); |
|
682 | - } |
|
683 | - $answer->cache('Question', $question); |
|
684 | - // remember system ID had a bug where sometimes it could be null |
|
685 | - $answer_cache_id = $question->is_system_question() |
|
686 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
687 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
688 | - $registration->cache('Answer', $answer, $answer_cache_id); |
|
689 | - } |
|
690 | - return $this->_generate_question_input($registration, $question, $answer); |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * @param EE_Registration $registration |
|
696 | - * @param EE_Question $question |
|
697 | - * @param $answer |
|
698 | - * @return EE_Form_Input_Base |
|
699 | - * @throws EE_Error |
|
700 | - * @throws InvalidArgumentException |
|
701 | - * @throws ReflectionException |
|
702 | - * @throws InvalidDataTypeException |
|
703 | - * @throws InvalidInterfaceException |
|
704 | - */ |
|
705 | - private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
706 | - { |
|
707 | - $identifier = $question->is_system_question() |
|
708 | - ? $question->system_ID() |
|
709 | - : $question->ID(); |
|
710 | - $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
711 | - add_filter( |
|
712 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
713 | - array($this, 'use_cached_countries_for_form_input'), |
|
714 | - 10, |
|
715 | - 4 |
|
716 | - ); |
|
717 | - add_filter( |
|
718 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
719 | - array($this, 'use_cached_states_for_form_input'), |
|
720 | - 10, |
|
721 | - 4 |
|
722 | - ); |
|
723 | - $input_constructor_args = array( |
|
724 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
725 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
726 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
727 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
728 | - 'html_label_class' => 'ee-reg-qstn', |
|
729 | - ); |
|
730 | - $input_constructor_args['html_label_id'] .= '-lbl'; |
|
731 | - if ($answer instanceof EE_Answer && $answer->ID()) { |
|
732 | - $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
733 | - $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
734 | - $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
735 | - } |
|
736 | - $form_input = $question->generate_form_input( |
|
737 | - $registration, |
|
738 | - $answer, |
|
739 | - $input_constructor_args |
|
740 | - ); |
|
741 | - remove_filter( |
|
742 | - 'FHEE__EE_Question__generate_form_input__country_options', |
|
743 | - array($this, 'use_cached_countries_for_form_input') |
|
744 | - ); |
|
745 | - remove_filter( |
|
746 | - 'FHEE__EE_Question__generate_form_input__state_options', |
|
747 | - array($this, 'use_cached_states_for_form_input') |
|
748 | - ); |
|
749 | - return $form_input; |
|
750 | - } |
|
751 | - |
|
752 | - |
|
753 | - /** |
|
754 | - * Gets the list of countries for the form input |
|
755 | - * |
|
756 | - * @param array|null $countries_list |
|
757 | - * @param EE_Question $question |
|
758 | - * @param EE_Registration $registration |
|
759 | - * @param EE_Answer $answer |
|
760 | - * @return array 2d keys are country IDs, values are their names |
|
761 | - * @throws EE_Error |
|
762 | - * @throws InvalidArgumentException |
|
763 | - * @throws InvalidDataTypeException |
|
764 | - * @throws InvalidInterfaceException |
|
765 | - * @throws ReflectionException |
|
766 | - */ |
|
767 | - public function use_cached_countries_for_form_input( |
|
768 | - $countries_list, |
|
769 | - EE_Question $question = null, |
|
770 | - EE_Registration $registration = null, |
|
771 | - EE_Answer $answer = null |
|
772 | - ) { |
|
773 | - $country_options = array('' => ''); |
|
774 | - // get possibly cached list of countries |
|
775 | - $countries = $this->checkout->action === 'process_reg_step' |
|
776 | - ? EEM_Country::instance()->get_all_countries() |
|
777 | - : EEM_Country::instance()->get_all_active_countries(); |
|
778 | - if (! empty($countries)) { |
|
779 | - foreach ($countries as $country) { |
|
780 | - if ($country instanceof EE_Country) { |
|
781 | - $country_options[ $country->ID() ] = $country->name(); |
|
782 | - } |
|
783 | - } |
|
784 | - } |
|
785 | - if ($question instanceof EE_Question && $registration instanceof EE_Registration) { |
|
786 | - $answer = EEM_Answer::instance()->get_one( |
|
787 | - array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
788 | - ); |
|
789 | - } else { |
|
790 | - $answer = EE_Answer::new_instance(); |
|
791 | - } |
|
792 | - $country_options = apply_filters( |
|
793 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
794 | - $country_options, |
|
795 | - $this, |
|
796 | - $registration, |
|
797 | - $question, |
|
798 | - $answer |
|
799 | - ); |
|
800 | - return $country_options; |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - /** |
|
805 | - * Gets the list of states for the form input |
|
806 | - * |
|
807 | - * @param array|null $states_list |
|
808 | - * @param EE_Question $question |
|
809 | - * @param EE_Registration $registration |
|
810 | - * @param EE_Answer $answer |
|
811 | - * @return array 2d keys are state IDs, values are their names |
|
812 | - * @throws EE_Error |
|
813 | - * @throws InvalidArgumentException |
|
814 | - * @throws InvalidDataTypeException |
|
815 | - * @throws InvalidInterfaceException |
|
816 | - * @throws ReflectionException |
|
817 | - */ |
|
818 | - public function use_cached_states_for_form_input( |
|
819 | - $states_list, |
|
820 | - EE_Question $question = null, |
|
821 | - EE_Registration $registration = null, |
|
822 | - EE_Answer $answer = null |
|
823 | - ) { |
|
824 | - $state_options = array('' => array('' => '')); |
|
825 | - $states = $this->checkout->action === 'process_reg_step' |
|
826 | - ? EEM_State::instance()->get_all_states() |
|
827 | - : EEM_State::instance()->get_all_active_states(); |
|
828 | - if (! empty($states)) { |
|
829 | - foreach ($states as $state) { |
|
830 | - if ($state instanceof EE_State) { |
|
831 | - $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
832 | - } |
|
833 | - } |
|
834 | - } |
|
835 | - $state_options = apply_filters( |
|
836 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
837 | - $state_options, |
|
838 | - $this, |
|
839 | - $registration, |
|
840 | - $question, |
|
841 | - $answer |
|
842 | - ); |
|
843 | - return $state_options; |
|
844 | - } |
|
845 | - |
|
846 | - |
|
847 | - /********************************************************************************************************/ |
|
848 | - /**************************************** PROCESS REG STEP ****************************************/ |
|
849 | - /********************************************************************************************************/ |
|
850 | - |
|
851 | - |
|
852 | - /** |
|
853 | - * @return bool |
|
854 | - * @throws EE_Error |
|
855 | - * @throws InvalidArgumentException |
|
856 | - * @throws ReflectionException |
|
857 | - * @throws RuntimeException |
|
858 | - * @throws InvalidDataTypeException |
|
859 | - * @throws InvalidInterfaceException |
|
860 | - */ |
|
861 | - public function process_reg_step() |
|
862 | - { |
|
863 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
864 | - // grab validated data from form |
|
865 | - $valid_data = $this->checkout->current_step->valid_data(); |
|
866 | - // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
867 | - // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
868 | - // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
869 | - if (empty($valid_data)) { |
|
870 | - EE_Error::add_error( |
|
871 | - esc_html__('No valid question responses were received.', 'event_espresso'), |
|
872 | - __FILE__, |
|
873 | - __FUNCTION__, |
|
874 | - __LINE__ |
|
875 | - ); |
|
876 | - return false; |
|
877 | - } |
|
878 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
879 | - EE_Error::add_error( |
|
880 | - esc_html__( |
|
881 | - 'A valid transaction could not be initiated for processing your registrations.', |
|
882 | - 'event_espresso' |
|
883 | - ), |
|
884 | - __FILE__, |
|
885 | - __FUNCTION__, |
|
886 | - __LINE__ |
|
887 | - ); |
|
888 | - return false; |
|
889 | - } |
|
890 | - // get cached registrations |
|
891 | - $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
892 | - // verify we got the goods |
|
893 | - if (empty($registrations)) { |
|
894 | - // combine the old translated string with a new one, in order to not break translations |
|
895 | - $error_message = esc_html__( |
|
896 | - 'Your form data could not be applied to any valid registrations.', |
|
897 | - 'event_espresso' |
|
898 | - ) |
|
899 | - . sprintf( |
|
900 | - esc_html_x( |
|
901 | - '%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.', |
|
902 | - '(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.', |
|
903 | - 'event_espresso' |
|
904 | - ), |
|
905 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
906 | - '</a>', |
|
907 | - '<br />' |
|
908 | - ); |
|
909 | - EE_Error::add_error( |
|
910 | - $error_message, |
|
911 | - __FILE__, |
|
912 | - __FUNCTION__, |
|
913 | - __LINE__ |
|
914 | - ); |
|
915 | - return false; |
|
916 | - } |
|
917 | - // extract attendee info from form data and save to model objects |
|
918 | - $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
919 | - // if first pass thru SPCO, |
|
920 | - // then let's check processed registrations against the total number of tickets in the cart |
|
921 | - if ($registrations_processed === false) { |
|
922 | - // but return immediately if the previous step exited early due to errors |
|
923 | - return false; |
|
924 | - } |
|
925 | - if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
926 | - // generate a correctly translated string for all possible singular/plural combinations |
|
927 | - if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
928 | - $error_msg = sprintf( |
|
929 | - esc_html_x( |
|
930 | - 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
931 | - 'There was 1 ticket in the Event Queue, but 2 registrations were processed', |
|
932 | - 'event_espresso' |
|
933 | - ), |
|
934 | - $this->checkout->total_ticket_count, |
|
935 | - $registrations_processed |
|
936 | - ); |
|
937 | - } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
938 | - $error_msg = sprintf( |
|
939 | - esc_html_x( |
|
940 | - 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
941 | - 'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed', |
|
942 | - 'event_espresso' |
|
943 | - ), |
|
944 | - $this->checkout->total_ticket_count, |
|
945 | - $registrations_processed |
|
946 | - ); |
|
947 | - } else { |
|
948 | - $error_msg = sprintf( |
|
949 | - esc_html__( |
|
950 | - 'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed', |
|
951 | - 'event_espresso' |
|
952 | - ), |
|
953 | - $this->checkout->total_ticket_count, |
|
954 | - $registrations_processed |
|
955 | - ); |
|
956 | - } |
|
957 | - EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
958 | - return false; |
|
959 | - } |
|
960 | - // mark this reg step as completed |
|
961 | - $this->set_completed(); |
|
962 | - $this->_set_success_message( |
|
963 | - esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
964 | - ); |
|
965 | - // do action in case a plugin wants to do something with the data submitted in step 1. |
|
966 | - // passes EE_Single_Page_Checkout, and it's posted data |
|
967 | - do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
968 | - return true; |
|
969 | - } |
|
970 | - |
|
971 | - |
|
972 | - /** |
|
973 | - * _process_registrations |
|
974 | - * |
|
975 | - * @param EE_Registration[] $registrations |
|
976 | - * @param array[][] $valid_data |
|
977 | - * @return bool|int |
|
978 | - * @throws EntityNotFoundException |
|
979 | - * @throws EE_Error |
|
980 | - * @throws InvalidArgumentException |
|
981 | - * @throws ReflectionException |
|
982 | - * @throws RuntimeException |
|
983 | - * @throws InvalidDataTypeException |
|
984 | - * @throws InvalidInterfaceException |
|
985 | - */ |
|
986 | - private function _process_registrations($registrations = array(), $valid_data = array()) |
|
987 | - { |
|
988 | - // load resources and set some defaults |
|
989 | - EE_Registry::instance()->load_model('Attendee'); |
|
990 | - // holder for primary registrant attendee object |
|
991 | - $this->checkout->primary_attendee_obj = null; |
|
992 | - // array for tracking reg form data for the primary registrant |
|
993 | - $primary_registrant = array( |
|
994 | - 'line_item_id' => null, |
|
995 | - ); |
|
996 | - $copy_primary = false; |
|
997 | - // reg form sections that do not contain inputs |
|
998 | - $non_input_form_sections = array( |
|
999 | - 'primary_registrant', |
|
1000 | - 'additional_attendee_reg_info', |
|
1001 | - 'spco_copy_attendee_chk', |
|
1002 | - ); |
|
1003 | - // attendee counter |
|
1004 | - $att_nmbr = 0; |
|
1005 | - // grab the saved registrations from the transaction |
|
1006 | - foreach ($registrations as $registration) { |
|
1007 | - // verify EE_Registration object |
|
1008 | - if (! $registration instanceof EE_Registration) { |
|
1009 | - EE_Error::add_error( |
|
1010 | - esc_html__( |
|
1011 | - 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
1012 | - 'event_espresso' |
|
1013 | - ), |
|
1014 | - __FILE__, |
|
1015 | - __FUNCTION__, |
|
1016 | - __LINE__ |
|
1017 | - ); |
|
1018 | - return false; |
|
1019 | - } |
|
1020 | - /** @var string $reg_url_link */ |
|
1021 | - $reg_url_link = $registration->reg_url_link(); |
|
1022 | - // reg_url_link exists ? |
|
1023 | - if (! empty($reg_url_link)) { |
|
1024 | - // should this registration be processed during this visit ? |
|
1025 | - if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
1026 | - // if NOT revisiting, then let's save the registration now, |
|
1027 | - // so that we have a REG_ID to use when generating other objects |
|
1028 | - if (! $this->checkout->revisit) { |
|
1029 | - $registration->save(); |
|
1030 | - } |
|
1031 | - /** |
|
1032 | - * This allows plugins to trigger a fail on processing of a |
|
1033 | - * registration for any conditions they may have for it to pass. |
|
1034 | - * |
|
1035 | - * @var bool if true is returned by the plugin then the |
|
1036 | - * registration processing is halted. |
|
1037 | - */ |
|
1038 | - if (apply_filters( |
|
1039 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
1040 | - false, |
|
1041 | - $att_nmbr, |
|
1042 | - $registration, |
|
1043 | - $registrations, |
|
1044 | - $valid_data, |
|
1045 | - $this |
|
1046 | - )) { |
|
1047 | - return false; |
|
1048 | - } |
|
1049 | - |
|
1050 | - // Houston, we have a registration! |
|
1051 | - $att_nmbr++; |
|
1052 | - $this->_attendee_data[ $reg_url_link ] = array(); |
|
1053 | - // grab any existing related answer objects |
|
1054 | - $this->_registration_answers = $registration->answers(); |
|
1055 | - // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
1056 | - if (isset($valid_data[ $reg_url_link ])) { |
|
1057 | - // do we need to copy basic info from primary attendee ? |
|
1058 | - $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
1059 | - && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
1060 | - // filter form input data for this registration |
|
1061 | - $valid_data[ $reg_url_link ] = (array) apply_filters( |
|
1062 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
1063 | - $valid_data[ $reg_url_link ] |
|
1064 | - ); |
|
1065 | - if (isset($valid_data['primary_attendee'])) { |
|
1066 | - $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
1067 | - ? $valid_data['primary_attendee'] |
|
1068 | - : false; |
|
1069 | - unset($valid_data['primary_attendee']); |
|
1070 | - } |
|
1071 | - // now loop through our array of valid post data && process attendee reg forms |
|
1072 | - foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
1073 | - if (! in_array($form_section, $non_input_form_sections, true)) { |
|
1074 | - foreach ($form_inputs as $form_input => $input_value) { |
|
1075 | - // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
1076 | - // check for critical inputs |
|
1077 | - if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
1078 | - $form_input, |
|
1079 | - $input_value |
|
1080 | - ) |
|
1081 | - ) { |
|
1082 | - return false; |
|
1083 | - } |
|
1084 | - // store a bit of data about the primary attendee |
|
1085 | - if ($att_nmbr === 1 |
|
1086 | - && ! empty($input_value) |
|
1087 | - && $reg_url_link === $primary_registrant['line_item_id'] |
|
1088 | - ) { |
|
1089 | - $primary_registrant[ $form_input ] = $input_value; |
|
1090 | - } elseif ($copy_primary |
|
1091 | - && $input_value === null |
|
1092 | - && isset($primary_registrant[ $form_input ]) |
|
1093 | - ) { |
|
1094 | - $input_value = $primary_registrant[ $form_input ]; |
|
1095 | - } |
|
1096 | - // now attempt to save the input data |
|
1097 | - if (! $this->_save_registration_form_input( |
|
1098 | - $registration, |
|
1099 | - $form_input, |
|
1100 | - $input_value |
|
1101 | - ) |
|
1102 | - ) { |
|
1103 | - EE_Error::add_error( |
|
1104 | - sprintf( |
|
1105 | - esc_html_x( |
|
1106 | - 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
1107 | - 'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"', |
|
1108 | - 'event_espresso' |
|
1109 | - ), |
|
1110 | - $form_input, |
|
1111 | - $input_value |
|
1112 | - ), |
|
1113 | - __FILE__, |
|
1114 | - __FUNCTION__, |
|
1115 | - __LINE__ |
|
1116 | - ); |
|
1117 | - return false; |
|
1118 | - } |
|
1119 | - } |
|
1120 | - } |
|
1121 | - } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
1122 | - } |
|
1123 | - // EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
1124 | - // this registration does not require additional attendee information ? |
|
1125 | - if ($copy_primary |
|
1126 | - && $att_nmbr > 1 |
|
1127 | - && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
1128 | - ) { |
|
1129 | - // just copy the primary registrant |
|
1130 | - $attendee = $this->checkout->primary_attendee_obj; |
|
1131 | - } else { |
|
1132 | - // ensure critical details are set for additional attendees |
|
1133 | - $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
1134 | - ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
1135 | - $this->_attendee_data[ $reg_url_link ] |
|
1136 | - ) |
|
1137 | - : $this->_attendee_data[ $reg_url_link ]; |
|
1138 | - // execute create attendee command (which may return an existing attendee) |
|
1139 | - $attendee = EE_Registry::instance()->BUS->execute( |
|
1140 | - new CreateAttendeeCommand( |
|
1141 | - $this->_attendee_data[ $reg_url_link ], |
|
1142 | - $registration |
|
1143 | - ) |
|
1144 | - ); |
|
1145 | - // who's #1 ? |
|
1146 | - if ($att_nmbr === 1) { |
|
1147 | - $this->checkout->primary_attendee_obj = $attendee; |
|
1148 | - } |
|
1149 | - } |
|
1150 | - // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
1151 | - // add relation to registration, set attendee ID, and cache attendee |
|
1152 | - $this->_associate_attendee_with_registration($registration, $attendee); |
|
1153 | - // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
1154 | - if (! $registration->attendee() instanceof EE_Attendee) { |
|
1155 | - EE_Error::add_error( |
|
1156 | - sprintf( |
|
1157 | - esc_html_x( |
|
1158 | - 'Registration %s has an invalid or missing Attendee object.', |
|
1159 | - 'Registration 123-456-789 has an invalid or missing Attendee object.', |
|
1160 | - 'event_espresso' |
|
1161 | - ), |
|
1162 | - $reg_url_link |
|
1163 | - ), |
|
1164 | - __FILE__, |
|
1165 | - __FUNCTION__, |
|
1166 | - __LINE__ |
|
1167 | - ); |
|
1168 | - return false; |
|
1169 | - } |
|
1170 | - /** @type EE_Registration_Processor $registration_processor */ |
|
1171 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1172 | - // at this point, we should have enough details about the registrant to consider the registration |
|
1173 | - // NOT incomplete |
|
1174 | - $registration_processor->toggle_incomplete_registration_status_to_default( |
|
1175 | - $registration, |
|
1176 | - false, |
|
1177 | - new Context( |
|
1178 | - 'spco_reg_step_attendee_information_process_registrations', |
|
1179 | - esc_html__( |
|
1180 | - 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
1181 | - 'event_espresso' |
|
1182 | - ) |
|
1183 | - ) |
|
1184 | - ); |
|
1185 | - // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
1186 | - // abandoned |
|
1187 | - $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1188 | - // if we've gotten this far, then let's save what we have |
|
1189 | - $registration->save(); |
|
1190 | - // add relation between TXN and registration |
|
1191 | - $this->_associate_registration_with_transaction($registration); |
|
1192 | - } |
|
1193 | - } else { |
|
1194 | - EE_Error::add_error( |
|
1195 | - esc_html__( |
|
1196 | - 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
1197 | - 'event_espresso' |
|
1198 | - ), |
|
1199 | - __FILE__, |
|
1200 | - __FUNCTION__, |
|
1201 | - __LINE__ |
|
1202 | - ); |
|
1203 | - // remove malformed data |
|
1204 | - unset($valid_data[ $reg_url_link ]); |
|
1205 | - return false; |
|
1206 | - } |
|
1207 | - } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
1208 | - return $att_nmbr; |
|
1209 | - } |
|
1210 | - |
|
1211 | - |
|
1212 | - /** |
|
1213 | - * _save_registration_form_input |
|
1214 | - * |
|
1215 | - * @param EE_Registration $registration |
|
1216 | - * @param string $form_input |
|
1217 | - * @param string $input_value |
|
1218 | - * @return bool |
|
1219 | - * @throws EE_Error |
|
1220 | - * @throws InvalidArgumentException |
|
1221 | - * @throws InvalidDataTypeException |
|
1222 | - * @throws InvalidInterfaceException |
|
1223 | - * @throws ReflectionException |
|
1224 | - */ |
|
1225 | - private function _save_registration_form_input( |
|
1226 | - EE_Registration $registration, |
|
1227 | - $form_input = '', |
|
1228 | - $input_value = '' |
|
1229 | - ) { |
|
1230 | - // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
1231 | - // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
1232 | - // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
1233 | - // allow for plugins to hook in and do their own processing of the form input. |
|
1234 | - // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
1235 | - if (apply_filters( |
|
1236 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
1237 | - false, |
|
1238 | - $registration, |
|
1239 | - $form_input, |
|
1240 | - $input_value, |
|
1241 | - $this |
|
1242 | - )) { |
|
1243 | - return true; |
|
1244 | - } |
|
1245 | - /* |
|
356 | + // Increment the reg forms number if form is valid. |
|
357 | + if (!empty($form_args)) { |
|
358 | + $this->reg_form_count++; |
|
359 | + } |
|
360 | + |
|
361 | + return ! empty($form_args) |
|
362 | + ? new EE_Form_Section_Proper($form_args) |
|
363 | + : new EE_Form_Section_HTML(); |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * @param EE_Registration $registration |
|
369 | + * @param bool $additional_attendee_reg_info |
|
370 | + * @return EE_Form_Input_Base |
|
371 | + * @throws EE_Error |
|
372 | + */ |
|
373 | + private function _additional_attendee_reg_info_input( |
|
374 | + EE_Registration $registration, |
|
375 | + $additional_attendee_reg_info = true |
|
376 | + ) { |
|
377 | + // generate hidden input |
|
378 | + return new EE_Hidden_Input( |
|
379 | + array( |
|
380 | + 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
381 | + 'default' => $additional_attendee_reg_info, |
|
382 | + ) |
|
383 | + ); |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * @param EE_Registration $registration |
|
389 | + * @param EE_Question_Group $question_group |
|
390 | + * @return EE_Form_Section_Proper |
|
391 | + * @throws EE_Error |
|
392 | + * @throws InvalidArgumentException |
|
393 | + * @throws InvalidDataTypeException |
|
394 | + * @throws InvalidInterfaceException |
|
395 | + * @throws ReflectionException |
|
396 | + */ |
|
397 | + private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) |
|
398 | + { |
|
399 | + // array of params to pass to parent constructor |
|
400 | + $form_args = array( |
|
401 | + 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
402 | + 'html_class' => $this->checkout->admin_request |
|
403 | + ? 'form-table ee-reg-form-qstn-grp-dv' |
|
404 | + : 'ee-reg-form-qstn-grp-dv', |
|
405 | + 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' |
|
406 | + . $registration->ID() . '-lbl', |
|
407 | + 'subsections' => array( |
|
408 | + 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
|
409 | + ), |
|
410 | + 'layout_strategy' => $this->checkout->admin_request |
|
411 | + ? new EE_Admin_Two_Column_Layout() |
|
412 | + : new EE_Div_Per_Section_Layout(), |
|
413 | + ); |
|
414 | + // where params |
|
415 | + $query_params = array('QST_deleted' => 0); |
|
416 | + // don't load admin only questions on the frontend |
|
417 | + if (! $this->checkout->admin_request) { |
|
418 | + $query_params['QST_admin_only'] = array('!=', true); |
|
419 | + } |
|
420 | + $questions = $question_group->get_many_related( |
|
421 | + 'Question', |
|
422 | + apply_filters( |
|
423 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
424 | + array( |
|
425 | + $query_params, |
|
426 | + 'order_by' => array( |
|
427 | + 'Question_Group_Question.QGQ_order' => 'ASC', |
|
428 | + ), |
|
429 | + ), |
|
430 | + $question_group, |
|
431 | + $registration, |
|
432 | + $this |
|
433 | + ) |
|
434 | + ); |
|
435 | + // filter for additional content before questions |
|
436 | + $form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
437 | + apply_filters( |
|
438 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
439 | + '', |
|
440 | + $registration, |
|
441 | + $question_group, |
|
442 | + $this |
|
443 | + ) |
|
444 | + ); |
|
445 | + // loop thru questions |
|
446 | + foreach ($questions as $question) { |
|
447 | + if ($question instanceof EE_Question) { |
|
448 | + $identifier = $question->is_system_question() |
|
449 | + ? $question->system_ID() |
|
450 | + : $question->ID(); |
|
451 | + $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question); |
|
452 | + } |
|
453 | + } |
|
454 | + $form_args['subsections'] = apply_filters( |
|
455 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
456 | + $form_args['subsections'], |
|
457 | + $registration, |
|
458 | + $question_group, |
|
459 | + $this |
|
460 | + ); |
|
461 | + // filter for additional content after questions |
|
462 | + $form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
463 | + apply_filters( |
|
464 | + 'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
465 | + '', |
|
466 | + $registration, |
|
467 | + $question_group, |
|
468 | + $this |
|
469 | + ) |
|
470 | + ); |
|
471 | + // d($form_args); |
|
472 | + $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
473 | + return apply_filters( |
|
474 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
475 | + $question_group_reg_form, |
|
476 | + $registration, |
|
477 | + $question_group, |
|
478 | + $this |
|
479 | + ); |
|
480 | + } |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * @param EE_Question_Group $question_group |
|
485 | + * @return EE_Form_Section_HTML |
|
486 | + */ |
|
487 | + private function _question_group_header(EE_Question_Group $question_group) |
|
488 | + { |
|
489 | + $html = ''; |
|
490 | + // group_name |
|
491 | + if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
492 | + if ($this->checkout->admin_request) { |
|
493 | + $html .= EEH_HTML::br(); |
|
494 | + $html .= EEH_HTML::h3( |
|
495 | + $question_group->name(), |
|
496 | + '', |
|
497 | + 'ee-reg-form-qstn-grp-title title', |
|
498 | + 'font-size: 1.3em; padding-left:0;' |
|
499 | + ); |
|
500 | + } else { |
|
501 | + $html .= EEH_HTML::h4( |
|
502 | + $question_group->name(), |
|
503 | + '', |
|
504 | + 'ee-reg-form-qstn-grp-title section-title' |
|
505 | + ); |
|
506 | + } |
|
507 | + } |
|
508 | + // group_desc |
|
509 | + if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
510 | + $html .= EEH_HTML::p( |
|
511 | + $question_group->desc(), |
|
512 | + '', |
|
513 | + $this->checkout->admin_request |
|
514 | + ? 'ee-reg-form-qstn-grp-desc-pg' |
|
515 | + : 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
516 | + ); |
|
517 | + } |
|
518 | + return new EE_Form_Section_HTML($html); |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + /** |
|
523 | + * @return EE_Form_Section_Proper |
|
524 | + * @throws EE_Error |
|
525 | + * @throws InvalidArgumentException |
|
526 | + * @throws ReflectionException |
|
527 | + * @throws InvalidDataTypeException |
|
528 | + * @throws InvalidInterfaceException |
|
529 | + */ |
|
530 | + private function _copy_attendee_info_form() |
|
531 | + { |
|
532 | + // array of params to pass to parent constructor |
|
533 | + return new EE_Form_Section_Proper( |
|
534 | + array( |
|
535 | + 'subsections' => $this->_copy_attendee_info_inputs(), |
|
536 | + 'layout_strategy' => new EE_Template_Layout( |
|
537 | + array( |
|
538 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
539 | + . $this->_slug |
|
540 | + . '/copy_attendee_info.template.php', |
|
541 | + 'begin_template_file' => null, |
|
542 | + 'input_template_file' => null, |
|
543 | + 'subsection_template_file' => null, |
|
544 | + 'end_template_file' => null, |
|
545 | + ) |
|
546 | + ), |
|
547 | + ) |
|
548 | + ); |
|
549 | + } |
|
550 | + |
|
551 | + |
|
552 | + /** |
|
553 | + * @return EE_Form_Section_HTML |
|
554 | + * @throws DomainException |
|
555 | + * @throws InvalidArgumentException |
|
556 | + * @throws InvalidDataTypeException |
|
557 | + * @throws InvalidInterfaceException |
|
558 | + */ |
|
559 | + private function _auto_copy_attendee_info() |
|
560 | + { |
|
561 | + return new EE_Form_Section_HTML( |
|
562 | + EEH_Template::locate_template( |
|
563 | + SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php', |
|
564 | + apply_filters( |
|
565 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
|
566 | + array() |
|
567 | + ), |
|
568 | + true, |
|
569 | + true |
|
570 | + ) |
|
571 | + ); |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + /** |
|
576 | + * @return array |
|
577 | + * @throws EE_Error |
|
578 | + * @throws InvalidArgumentException |
|
579 | + * @throws ReflectionException |
|
580 | + * @throws InvalidDataTypeException |
|
581 | + * @throws InvalidInterfaceException |
|
582 | + */ |
|
583 | + private function _copy_attendee_info_inputs() |
|
584 | + { |
|
585 | + $copy_attendee_info_inputs = array(); |
|
586 | + $prev_ticket = null; |
|
587 | + // grab the saved registrations from the transaction |
|
588 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
589 | + foreach ($registrations as $registration) { |
|
590 | + // for all attendees other than the primary attendee |
|
591 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
592 | + // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
593 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
594 | + $item_name = $registration->ticket()->name(); |
|
595 | + $item_name .= $registration->ticket()->description() !== '' |
|
596 | + ? ' - ' . $registration->ticket()->description() |
|
597 | + : ''; |
|
598 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID( |
|
599 | + ) . ']' ] = |
|
600 | + new EE_Form_Section_HTML( |
|
601 | + '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
602 | + ); |
|
603 | + $prev_ticket = $registration->ticket()->ID(); |
|
604 | + } |
|
605 | + |
|
606 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = |
|
607 | + new EE_Checkbox_Multi_Input( |
|
608 | + array( |
|
609 | + $registration->ID() => sprintf( |
|
610 | + esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
611 | + $registration->count() |
|
612 | + ), |
|
613 | + ), |
|
614 | + array( |
|
615 | + 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
616 | + 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
617 | + 'display_html_label_text' => false, |
|
618 | + ) |
|
619 | + ); |
|
620 | + } |
|
621 | + } |
|
622 | + return $copy_attendee_info_inputs; |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + /** |
|
627 | + * @param EE_Registration $registration |
|
628 | + * @return EE_Form_Input_Base |
|
629 | + * @throws EE_Error |
|
630 | + */ |
|
631 | + private function _additional_primary_registrant_inputs(EE_Registration $registration) |
|
632 | + { |
|
633 | + // generate hidden input |
|
634 | + return new EE_Hidden_Input( |
|
635 | + array( |
|
636 | + 'html_id' => 'primary_registrant', |
|
637 | + 'default' => $registration->reg_url_link(), |
|
638 | + ) |
|
639 | + ); |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + /** |
|
644 | + * @param EE_Registration $registration |
|
645 | + * @param EE_Question $question |
|
646 | + * @return EE_Form_Input_Base |
|
647 | + * @throws EE_Error |
|
648 | + * @throws InvalidArgumentException |
|
649 | + * @throws InvalidDataTypeException |
|
650 | + * @throws InvalidInterfaceException |
|
651 | + * @throws ReflectionException |
|
652 | + */ |
|
653 | + public function reg_form_question(EE_Registration $registration, EE_Question $question) |
|
654 | + { |
|
655 | + |
|
656 | + // if this question was for an attendee detail, then check for that answer |
|
657 | + $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
|
658 | + $registration, |
|
659 | + $question->system_ID() |
|
660 | + ); |
|
661 | + $answer = $answer_value === null |
|
662 | + ? EEM_Answer::instance()->get_one( |
|
663 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
664 | + ) |
|
665 | + : null; |
|
666 | + // if NOT returning to edit an existing registration |
|
667 | + // OR if this question is for an attendee property |
|
668 | + // OR we still don't have an EE_Answer object |
|
669 | + if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
670 | + // create an EE_Answer object for storing everything in |
|
671 | + $answer = EE_Answer::new_instance( |
|
672 | + array( |
|
673 | + 'QST_ID' => $question->ID(), |
|
674 | + 'REG_ID' => $registration->ID(), |
|
675 | + ) |
|
676 | + ); |
|
677 | + } |
|
678 | + // verify instance |
|
679 | + if ($answer instanceof EE_Answer) { |
|
680 | + if (! empty($answer_value)) { |
|
681 | + $answer->set('ANS_value', $answer_value); |
|
682 | + } |
|
683 | + $answer->cache('Question', $question); |
|
684 | + // remember system ID had a bug where sometimes it could be null |
|
685 | + $answer_cache_id = $question->is_system_question() |
|
686 | + ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
687 | + : $question->ID() . '-' . $registration->reg_url_link(); |
|
688 | + $registration->cache('Answer', $answer, $answer_cache_id); |
|
689 | + } |
|
690 | + return $this->_generate_question_input($registration, $question, $answer); |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * @param EE_Registration $registration |
|
696 | + * @param EE_Question $question |
|
697 | + * @param $answer |
|
698 | + * @return EE_Form_Input_Base |
|
699 | + * @throws EE_Error |
|
700 | + * @throws InvalidArgumentException |
|
701 | + * @throws ReflectionException |
|
702 | + * @throws InvalidDataTypeException |
|
703 | + * @throws InvalidInterfaceException |
|
704 | + */ |
|
705 | + private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) |
|
706 | + { |
|
707 | + $identifier = $question->is_system_question() |
|
708 | + ? $question->system_ID() |
|
709 | + : $question->ID(); |
|
710 | + $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
711 | + add_filter( |
|
712 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
713 | + array($this, 'use_cached_countries_for_form_input'), |
|
714 | + 10, |
|
715 | + 4 |
|
716 | + ); |
|
717 | + add_filter( |
|
718 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
719 | + array($this, 'use_cached_states_for_form_input'), |
|
720 | + 10, |
|
721 | + 4 |
|
722 | + ); |
|
723 | + $input_constructor_args = array( |
|
724 | + 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
725 | + 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
726 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
727 | + 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
728 | + 'html_label_class' => 'ee-reg-qstn', |
|
729 | + ); |
|
730 | + $input_constructor_args['html_label_id'] .= '-lbl'; |
|
731 | + if ($answer instanceof EE_Answer && $answer->ID()) { |
|
732 | + $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
733 | + $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
734 | + $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
735 | + } |
|
736 | + $form_input = $question->generate_form_input( |
|
737 | + $registration, |
|
738 | + $answer, |
|
739 | + $input_constructor_args |
|
740 | + ); |
|
741 | + remove_filter( |
|
742 | + 'FHEE__EE_Question__generate_form_input__country_options', |
|
743 | + array($this, 'use_cached_countries_for_form_input') |
|
744 | + ); |
|
745 | + remove_filter( |
|
746 | + 'FHEE__EE_Question__generate_form_input__state_options', |
|
747 | + array($this, 'use_cached_states_for_form_input') |
|
748 | + ); |
|
749 | + return $form_input; |
|
750 | + } |
|
751 | + |
|
752 | + |
|
753 | + /** |
|
754 | + * Gets the list of countries for the form input |
|
755 | + * |
|
756 | + * @param array|null $countries_list |
|
757 | + * @param EE_Question $question |
|
758 | + * @param EE_Registration $registration |
|
759 | + * @param EE_Answer $answer |
|
760 | + * @return array 2d keys are country IDs, values are their names |
|
761 | + * @throws EE_Error |
|
762 | + * @throws InvalidArgumentException |
|
763 | + * @throws InvalidDataTypeException |
|
764 | + * @throws InvalidInterfaceException |
|
765 | + * @throws ReflectionException |
|
766 | + */ |
|
767 | + public function use_cached_countries_for_form_input( |
|
768 | + $countries_list, |
|
769 | + EE_Question $question = null, |
|
770 | + EE_Registration $registration = null, |
|
771 | + EE_Answer $answer = null |
|
772 | + ) { |
|
773 | + $country_options = array('' => ''); |
|
774 | + // get possibly cached list of countries |
|
775 | + $countries = $this->checkout->action === 'process_reg_step' |
|
776 | + ? EEM_Country::instance()->get_all_countries() |
|
777 | + : EEM_Country::instance()->get_all_active_countries(); |
|
778 | + if (! empty($countries)) { |
|
779 | + foreach ($countries as $country) { |
|
780 | + if ($country instanceof EE_Country) { |
|
781 | + $country_options[ $country->ID() ] = $country->name(); |
|
782 | + } |
|
783 | + } |
|
784 | + } |
|
785 | + if ($question instanceof EE_Question && $registration instanceof EE_Registration) { |
|
786 | + $answer = EEM_Answer::instance()->get_one( |
|
787 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
788 | + ); |
|
789 | + } else { |
|
790 | + $answer = EE_Answer::new_instance(); |
|
791 | + } |
|
792 | + $country_options = apply_filters( |
|
793 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
794 | + $country_options, |
|
795 | + $this, |
|
796 | + $registration, |
|
797 | + $question, |
|
798 | + $answer |
|
799 | + ); |
|
800 | + return $country_options; |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + /** |
|
805 | + * Gets the list of states for the form input |
|
806 | + * |
|
807 | + * @param array|null $states_list |
|
808 | + * @param EE_Question $question |
|
809 | + * @param EE_Registration $registration |
|
810 | + * @param EE_Answer $answer |
|
811 | + * @return array 2d keys are state IDs, values are their names |
|
812 | + * @throws EE_Error |
|
813 | + * @throws InvalidArgumentException |
|
814 | + * @throws InvalidDataTypeException |
|
815 | + * @throws InvalidInterfaceException |
|
816 | + * @throws ReflectionException |
|
817 | + */ |
|
818 | + public function use_cached_states_for_form_input( |
|
819 | + $states_list, |
|
820 | + EE_Question $question = null, |
|
821 | + EE_Registration $registration = null, |
|
822 | + EE_Answer $answer = null |
|
823 | + ) { |
|
824 | + $state_options = array('' => array('' => '')); |
|
825 | + $states = $this->checkout->action === 'process_reg_step' |
|
826 | + ? EEM_State::instance()->get_all_states() |
|
827 | + : EEM_State::instance()->get_all_active_states(); |
|
828 | + if (! empty($states)) { |
|
829 | + foreach ($states as $state) { |
|
830 | + if ($state instanceof EE_State) { |
|
831 | + $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
832 | + } |
|
833 | + } |
|
834 | + } |
|
835 | + $state_options = apply_filters( |
|
836 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
837 | + $state_options, |
|
838 | + $this, |
|
839 | + $registration, |
|
840 | + $question, |
|
841 | + $answer |
|
842 | + ); |
|
843 | + return $state_options; |
|
844 | + } |
|
845 | + |
|
846 | + |
|
847 | + /********************************************************************************************************/ |
|
848 | + /**************************************** PROCESS REG STEP ****************************************/ |
|
849 | + /********************************************************************************************************/ |
|
850 | + |
|
851 | + |
|
852 | + /** |
|
853 | + * @return bool |
|
854 | + * @throws EE_Error |
|
855 | + * @throws InvalidArgumentException |
|
856 | + * @throws ReflectionException |
|
857 | + * @throws RuntimeException |
|
858 | + * @throws InvalidDataTypeException |
|
859 | + * @throws InvalidInterfaceException |
|
860 | + */ |
|
861 | + public function process_reg_step() |
|
862 | + { |
|
863 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
864 | + // grab validated data from form |
|
865 | + $valid_data = $this->checkout->current_step->valid_data(); |
|
866 | + // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
|
867 | + // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
|
868 | + // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
|
869 | + if (empty($valid_data)) { |
|
870 | + EE_Error::add_error( |
|
871 | + esc_html__('No valid question responses were received.', 'event_espresso'), |
|
872 | + __FILE__, |
|
873 | + __FUNCTION__, |
|
874 | + __LINE__ |
|
875 | + ); |
|
876 | + return false; |
|
877 | + } |
|
878 | + if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
879 | + EE_Error::add_error( |
|
880 | + esc_html__( |
|
881 | + 'A valid transaction could not be initiated for processing your registrations.', |
|
882 | + 'event_espresso' |
|
883 | + ), |
|
884 | + __FILE__, |
|
885 | + __FUNCTION__, |
|
886 | + __LINE__ |
|
887 | + ); |
|
888 | + return false; |
|
889 | + } |
|
890 | + // get cached registrations |
|
891 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
892 | + // verify we got the goods |
|
893 | + if (empty($registrations)) { |
|
894 | + // combine the old translated string with a new one, in order to not break translations |
|
895 | + $error_message = esc_html__( |
|
896 | + 'Your form data could not be applied to any valid registrations.', |
|
897 | + 'event_espresso' |
|
898 | + ) |
|
899 | + . sprintf( |
|
900 | + esc_html_x( |
|
901 | + '%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.', |
|
902 | + '(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.', |
|
903 | + 'event_espresso' |
|
904 | + ), |
|
905 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
906 | + '</a>', |
|
907 | + '<br />' |
|
908 | + ); |
|
909 | + EE_Error::add_error( |
|
910 | + $error_message, |
|
911 | + __FILE__, |
|
912 | + __FUNCTION__, |
|
913 | + __LINE__ |
|
914 | + ); |
|
915 | + return false; |
|
916 | + } |
|
917 | + // extract attendee info from form data and save to model objects |
|
918 | + $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
919 | + // if first pass thru SPCO, |
|
920 | + // then let's check processed registrations against the total number of tickets in the cart |
|
921 | + if ($registrations_processed === false) { |
|
922 | + // but return immediately if the previous step exited early due to errors |
|
923 | + return false; |
|
924 | + } |
|
925 | + if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
926 | + // generate a correctly translated string for all possible singular/plural combinations |
|
927 | + if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
928 | + $error_msg = sprintf( |
|
929 | + esc_html_x( |
|
930 | + 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
|
931 | + 'There was 1 ticket in the Event Queue, but 2 registrations were processed', |
|
932 | + 'event_espresso' |
|
933 | + ), |
|
934 | + $this->checkout->total_ticket_count, |
|
935 | + $registrations_processed |
|
936 | + ); |
|
937 | + } elseif ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
938 | + $error_msg = sprintf( |
|
939 | + esc_html_x( |
|
940 | + 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
|
941 | + 'There was a total of 2 tickets in the Event Queue, but only 1 registration was processed', |
|
942 | + 'event_espresso' |
|
943 | + ), |
|
944 | + $this->checkout->total_ticket_count, |
|
945 | + $registrations_processed |
|
946 | + ); |
|
947 | + } else { |
|
948 | + $error_msg = sprintf( |
|
949 | + esc_html__( |
|
950 | + 'There was a total of 2 tickets in the Event Queue, but 2 registrations were processed', |
|
951 | + 'event_espresso' |
|
952 | + ), |
|
953 | + $this->checkout->total_ticket_count, |
|
954 | + $registrations_processed |
|
955 | + ); |
|
956 | + } |
|
957 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
958 | + return false; |
|
959 | + } |
|
960 | + // mark this reg step as completed |
|
961 | + $this->set_completed(); |
|
962 | + $this->_set_success_message( |
|
963 | + esc_html__('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
964 | + ); |
|
965 | + // do action in case a plugin wants to do something with the data submitted in step 1. |
|
966 | + // passes EE_Single_Page_Checkout, and it's posted data |
|
967 | + do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
968 | + return true; |
|
969 | + } |
|
970 | + |
|
971 | + |
|
972 | + /** |
|
973 | + * _process_registrations |
|
974 | + * |
|
975 | + * @param EE_Registration[] $registrations |
|
976 | + * @param array[][] $valid_data |
|
977 | + * @return bool|int |
|
978 | + * @throws EntityNotFoundException |
|
979 | + * @throws EE_Error |
|
980 | + * @throws InvalidArgumentException |
|
981 | + * @throws ReflectionException |
|
982 | + * @throws RuntimeException |
|
983 | + * @throws InvalidDataTypeException |
|
984 | + * @throws InvalidInterfaceException |
|
985 | + */ |
|
986 | + private function _process_registrations($registrations = array(), $valid_data = array()) |
|
987 | + { |
|
988 | + // load resources and set some defaults |
|
989 | + EE_Registry::instance()->load_model('Attendee'); |
|
990 | + // holder for primary registrant attendee object |
|
991 | + $this->checkout->primary_attendee_obj = null; |
|
992 | + // array for tracking reg form data for the primary registrant |
|
993 | + $primary_registrant = array( |
|
994 | + 'line_item_id' => null, |
|
995 | + ); |
|
996 | + $copy_primary = false; |
|
997 | + // reg form sections that do not contain inputs |
|
998 | + $non_input_form_sections = array( |
|
999 | + 'primary_registrant', |
|
1000 | + 'additional_attendee_reg_info', |
|
1001 | + 'spco_copy_attendee_chk', |
|
1002 | + ); |
|
1003 | + // attendee counter |
|
1004 | + $att_nmbr = 0; |
|
1005 | + // grab the saved registrations from the transaction |
|
1006 | + foreach ($registrations as $registration) { |
|
1007 | + // verify EE_Registration object |
|
1008 | + if (! $registration instanceof EE_Registration) { |
|
1009 | + EE_Error::add_error( |
|
1010 | + esc_html__( |
|
1011 | + 'An invalid Registration object was discovered when attempting to process your registration information.', |
|
1012 | + 'event_espresso' |
|
1013 | + ), |
|
1014 | + __FILE__, |
|
1015 | + __FUNCTION__, |
|
1016 | + __LINE__ |
|
1017 | + ); |
|
1018 | + return false; |
|
1019 | + } |
|
1020 | + /** @var string $reg_url_link */ |
|
1021 | + $reg_url_link = $registration->reg_url_link(); |
|
1022 | + // reg_url_link exists ? |
|
1023 | + if (! empty($reg_url_link)) { |
|
1024 | + // should this registration be processed during this visit ? |
|
1025 | + if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
1026 | + // if NOT revisiting, then let's save the registration now, |
|
1027 | + // so that we have a REG_ID to use when generating other objects |
|
1028 | + if (! $this->checkout->revisit) { |
|
1029 | + $registration->save(); |
|
1030 | + } |
|
1031 | + /** |
|
1032 | + * This allows plugins to trigger a fail on processing of a |
|
1033 | + * registration for any conditions they may have for it to pass. |
|
1034 | + * |
|
1035 | + * @var bool if true is returned by the plugin then the |
|
1036 | + * registration processing is halted. |
|
1037 | + */ |
|
1038 | + if (apply_filters( |
|
1039 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
|
1040 | + false, |
|
1041 | + $att_nmbr, |
|
1042 | + $registration, |
|
1043 | + $registrations, |
|
1044 | + $valid_data, |
|
1045 | + $this |
|
1046 | + )) { |
|
1047 | + return false; |
|
1048 | + } |
|
1049 | + |
|
1050 | + // Houston, we have a registration! |
|
1051 | + $att_nmbr++; |
|
1052 | + $this->_attendee_data[ $reg_url_link ] = array(); |
|
1053 | + // grab any existing related answer objects |
|
1054 | + $this->_registration_answers = $registration->answers(); |
|
1055 | + // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
|
1056 | + if (isset($valid_data[ $reg_url_link ])) { |
|
1057 | + // do we need to copy basic info from primary attendee ? |
|
1058 | + $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
1059 | + && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
1060 | + // filter form input data for this registration |
|
1061 | + $valid_data[ $reg_url_link ] = (array) apply_filters( |
|
1062 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
1063 | + $valid_data[ $reg_url_link ] |
|
1064 | + ); |
|
1065 | + if (isset($valid_data['primary_attendee'])) { |
|
1066 | + $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
1067 | + ? $valid_data['primary_attendee'] |
|
1068 | + : false; |
|
1069 | + unset($valid_data['primary_attendee']); |
|
1070 | + } |
|
1071 | + // now loop through our array of valid post data && process attendee reg forms |
|
1072 | + foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
1073 | + if (! in_array($form_section, $non_input_form_sections, true)) { |
|
1074 | + foreach ($form_inputs as $form_input => $input_value) { |
|
1075 | + // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
|
1076 | + // check for critical inputs |
|
1077 | + if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
1078 | + $form_input, |
|
1079 | + $input_value |
|
1080 | + ) |
|
1081 | + ) { |
|
1082 | + return false; |
|
1083 | + } |
|
1084 | + // store a bit of data about the primary attendee |
|
1085 | + if ($att_nmbr === 1 |
|
1086 | + && ! empty($input_value) |
|
1087 | + && $reg_url_link === $primary_registrant['line_item_id'] |
|
1088 | + ) { |
|
1089 | + $primary_registrant[ $form_input ] = $input_value; |
|
1090 | + } elseif ($copy_primary |
|
1091 | + && $input_value === null |
|
1092 | + && isset($primary_registrant[ $form_input ]) |
|
1093 | + ) { |
|
1094 | + $input_value = $primary_registrant[ $form_input ]; |
|
1095 | + } |
|
1096 | + // now attempt to save the input data |
|
1097 | + if (! $this->_save_registration_form_input( |
|
1098 | + $registration, |
|
1099 | + $form_input, |
|
1100 | + $input_value |
|
1101 | + ) |
|
1102 | + ) { |
|
1103 | + EE_Error::add_error( |
|
1104 | + sprintf( |
|
1105 | + esc_html_x( |
|
1106 | + 'Unable to save registration form data for the form input: "%1$s" with the submitted value: "%2$s"', |
|
1107 | + 'Unable to save registration form data for the form input: "form input name" with the submitted value: "form input value"', |
|
1108 | + 'event_espresso' |
|
1109 | + ), |
|
1110 | + $form_input, |
|
1111 | + $input_value |
|
1112 | + ), |
|
1113 | + __FILE__, |
|
1114 | + __FUNCTION__, |
|
1115 | + __LINE__ |
|
1116 | + ); |
|
1117 | + return false; |
|
1118 | + } |
|
1119 | + } |
|
1120 | + } |
|
1121 | + } // end of foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) |
|
1122 | + } |
|
1123 | + // EEH_Debug_Tools::printr( $this->_attendee_data, '$this->_attendee_data', __FILE__, __LINE__ ); |
|
1124 | + // this registration does not require additional attendee information ? |
|
1125 | + if ($copy_primary |
|
1126 | + && $att_nmbr > 1 |
|
1127 | + && $this->checkout->primary_attendee_obj instanceof EE_Attendee |
|
1128 | + ) { |
|
1129 | + // just copy the primary registrant |
|
1130 | + $attendee = $this->checkout->primary_attendee_obj; |
|
1131 | + } else { |
|
1132 | + // ensure critical details are set for additional attendees |
|
1133 | + $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
1134 | + ? $this->_copy_critical_attendee_details_from_primary_registrant( |
|
1135 | + $this->_attendee_data[ $reg_url_link ] |
|
1136 | + ) |
|
1137 | + : $this->_attendee_data[ $reg_url_link ]; |
|
1138 | + // execute create attendee command (which may return an existing attendee) |
|
1139 | + $attendee = EE_Registry::instance()->BUS->execute( |
|
1140 | + new CreateAttendeeCommand( |
|
1141 | + $this->_attendee_data[ $reg_url_link ], |
|
1142 | + $registration |
|
1143 | + ) |
|
1144 | + ); |
|
1145 | + // who's #1 ? |
|
1146 | + if ($att_nmbr === 1) { |
|
1147 | + $this->checkout->primary_attendee_obj = $attendee; |
|
1148 | + } |
|
1149 | + } |
|
1150 | + // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
|
1151 | + // add relation to registration, set attendee ID, and cache attendee |
|
1152 | + $this->_associate_attendee_with_registration($registration, $attendee); |
|
1153 | + // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
|
1154 | + if (! $registration->attendee() instanceof EE_Attendee) { |
|
1155 | + EE_Error::add_error( |
|
1156 | + sprintf( |
|
1157 | + esc_html_x( |
|
1158 | + 'Registration %s has an invalid or missing Attendee object.', |
|
1159 | + 'Registration 123-456-789 has an invalid or missing Attendee object.', |
|
1160 | + 'event_espresso' |
|
1161 | + ), |
|
1162 | + $reg_url_link |
|
1163 | + ), |
|
1164 | + __FILE__, |
|
1165 | + __FUNCTION__, |
|
1166 | + __LINE__ |
|
1167 | + ); |
|
1168 | + return false; |
|
1169 | + } |
|
1170 | + /** @type EE_Registration_Processor $registration_processor */ |
|
1171 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1172 | + // at this point, we should have enough details about the registrant to consider the registration |
|
1173 | + // NOT incomplete |
|
1174 | + $registration_processor->toggle_incomplete_registration_status_to_default( |
|
1175 | + $registration, |
|
1176 | + false, |
|
1177 | + new Context( |
|
1178 | + 'spco_reg_step_attendee_information_process_registrations', |
|
1179 | + esc_html__( |
|
1180 | + 'Finished populating registration with details from the registration form after submitting the Attendee Information Reg Step.', |
|
1181 | + 'event_espresso' |
|
1182 | + ) |
|
1183 | + ) |
|
1184 | + ); |
|
1185 | + // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to |
|
1186 | + // abandoned |
|
1187 | + $this->checkout->transaction->toggle_failed_transaction_status(); |
|
1188 | + // if we've gotten this far, then let's save what we have |
|
1189 | + $registration->save(); |
|
1190 | + // add relation between TXN and registration |
|
1191 | + $this->_associate_registration_with_transaction($registration); |
|
1192 | + } |
|
1193 | + } else { |
|
1194 | + EE_Error::add_error( |
|
1195 | + esc_html__( |
|
1196 | + 'An invalid or missing line item ID was encountered while attempting to process the registration form.', |
|
1197 | + 'event_espresso' |
|
1198 | + ), |
|
1199 | + __FILE__, |
|
1200 | + __FUNCTION__, |
|
1201 | + __LINE__ |
|
1202 | + ); |
|
1203 | + // remove malformed data |
|
1204 | + unset($valid_data[ $reg_url_link ]); |
|
1205 | + return false; |
|
1206 | + } |
|
1207 | + } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
|
1208 | + return $att_nmbr; |
|
1209 | + } |
|
1210 | + |
|
1211 | + |
|
1212 | + /** |
|
1213 | + * _save_registration_form_input |
|
1214 | + * |
|
1215 | + * @param EE_Registration $registration |
|
1216 | + * @param string $form_input |
|
1217 | + * @param string $input_value |
|
1218 | + * @return bool |
|
1219 | + * @throws EE_Error |
|
1220 | + * @throws InvalidArgumentException |
|
1221 | + * @throws InvalidDataTypeException |
|
1222 | + * @throws InvalidInterfaceException |
|
1223 | + * @throws ReflectionException |
|
1224 | + */ |
|
1225 | + private function _save_registration_form_input( |
|
1226 | + EE_Registration $registration, |
|
1227 | + $form_input = '', |
|
1228 | + $input_value = '' |
|
1229 | + ) { |
|
1230 | + // \EEH_Debug_Tools::printr( __FUNCTION__, __CLASS__, __FILE__, __LINE__, 2 ); |
|
1231 | + // \EEH_Debug_Tools::printr( $form_input, '$form_input', __FILE__, __LINE__ ); |
|
1232 | + // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
|
1233 | + // allow for plugins to hook in and do their own processing of the form input. |
|
1234 | + // For plugins to bypass normal processing here, they just need to return a boolean value. |
|
1235 | + if (apply_filters( |
|
1236 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
|
1237 | + false, |
|
1238 | + $registration, |
|
1239 | + $form_input, |
|
1240 | + $input_value, |
|
1241 | + $this |
|
1242 | + )) { |
|
1243 | + return true; |
|
1244 | + } |
|
1245 | + /* |
|
1246 | 1246 | * $answer_cache_id is the key used to find the EE_Answer we want |
1247 | 1247 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
1248 | 1248 | */ |
1249 | - $answer_cache_id = $this->checkout->reg_url_link |
|
1250 | - ? $form_input . '-' . $registration->reg_url_link() |
|
1251 | - : $form_input; |
|
1252 | - $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ]) |
|
1253 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer; |
|
1254 | - // rename form_inputs if they are EE_Attendee properties |
|
1255 | - switch ((string) $form_input) { |
|
1256 | - case 'state': |
|
1257 | - case 'STA_ID': |
|
1258 | - $attendee_property = true; |
|
1259 | - $form_input = 'STA_ID'; |
|
1260 | - break; |
|
1261 | - |
|
1262 | - case 'country': |
|
1263 | - case 'CNT_ISO': |
|
1264 | - $attendee_property = true; |
|
1265 | - $form_input = 'CNT_ISO'; |
|
1266 | - break; |
|
1267 | - |
|
1268 | - default: |
|
1269 | - $ATT_input = 'ATT_' . $form_input; |
|
1270 | - // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
1271 | - $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1272 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1273 | - } |
|
1274 | - // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
1275 | - // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
1276 | - // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
1277 | - // if this form input has a corresponding attendee property |
|
1278 | - if ($attendee_property) { |
|
1279 | - $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
1280 | - if ($answer_is_obj) { |
|
1281 | - // and delete the corresponding answer since we won't be storing this data in that object |
|
1282 | - $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer'); |
|
1283 | - $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
1284 | - } |
|
1285 | - return true; |
|
1286 | - } |
|
1287 | - if ($answer_is_obj) { |
|
1288 | - // save this data to the answer object |
|
1289 | - $this->_registration_answers[ $answer_cache_id ]->set_value($input_value); |
|
1290 | - $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
1291 | - return $result !== false; |
|
1292 | - } |
|
1293 | - foreach ($this->_registration_answers as $answer) { |
|
1294 | - if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1295 | - $answer->set_value($input_value); |
|
1296 | - $result = $answer->save(); |
|
1297 | - return $result !== false; |
|
1298 | - } |
|
1299 | - } |
|
1300 | - return false; |
|
1301 | - } |
|
1302 | - |
|
1303 | - |
|
1304 | - /** |
|
1305 | - * _verify_critical_attendee_details_are_set |
|
1306 | - * |
|
1307 | - * @param string $form_input |
|
1308 | - * @param string $input_value |
|
1309 | - * @return boolean |
|
1310 | - */ |
|
1311 | - private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
1312 | - $form_input = '', |
|
1313 | - $input_value = '' |
|
1314 | - ) { |
|
1315 | - if (empty($input_value)) { |
|
1316 | - // if the form input isn't marked as being required, then just return |
|
1317 | - if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) { |
|
1318 | - return true; |
|
1319 | - } |
|
1320 | - switch ($form_input) { |
|
1321 | - case 'fname': |
|
1322 | - EE_Error::add_error( |
|
1323 | - esc_html__('First Name is a required value.', 'event_espresso'), |
|
1324 | - __FILE__, |
|
1325 | - __FUNCTION__, |
|
1326 | - __LINE__ |
|
1327 | - ); |
|
1328 | - return false; |
|
1329 | - break; |
|
1330 | - case 'lname': |
|
1331 | - EE_Error::add_error( |
|
1332 | - esc_html__('Last Name is a required value.', 'event_espresso'), |
|
1333 | - __FILE__, |
|
1334 | - __FUNCTION__, |
|
1335 | - __LINE__ |
|
1336 | - ); |
|
1337 | - return false; |
|
1338 | - break; |
|
1339 | - case 'email': |
|
1340 | - EE_Error::add_error( |
|
1341 | - esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
1342 | - __FILE__, |
|
1343 | - __FUNCTION__, |
|
1344 | - __LINE__ |
|
1345 | - ); |
|
1346 | - return false; |
|
1347 | - break; |
|
1348 | - } |
|
1349 | - } |
|
1350 | - return true; |
|
1351 | - } |
|
1352 | - |
|
1353 | - |
|
1354 | - /** |
|
1355 | - * _associate_attendee_with_registration |
|
1356 | - * |
|
1357 | - * @param EE_Registration $registration |
|
1358 | - * @param EE_Attendee $attendee |
|
1359 | - * @return void |
|
1360 | - * @throws EE_Error |
|
1361 | - * @throws InvalidArgumentException |
|
1362 | - * @throws ReflectionException |
|
1363 | - * @throws RuntimeException |
|
1364 | - * @throws InvalidDataTypeException |
|
1365 | - * @throws InvalidInterfaceException |
|
1366 | - */ |
|
1367 | - private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
1368 | - { |
|
1369 | - // add relation to attendee |
|
1370 | - $registration->_add_relation_to($attendee, 'Attendee'); |
|
1371 | - $registration->set_attendee_id($attendee->ID()); |
|
1372 | - $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1373 | - } |
|
1374 | - |
|
1375 | - |
|
1376 | - /** |
|
1377 | - * _associate_registration_with_transaction |
|
1378 | - * |
|
1379 | - * @param EE_Registration $registration |
|
1380 | - * @return void |
|
1381 | - * @throws EE_Error |
|
1382 | - * @throws InvalidArgumentException |
|
1383 | - * @throws ReflectionException |
|
1384 | - * @throws InvalidDataTypeException |
|
1385 | - * @throws InvalidInterfaceException |
|
1386 | - */ |
|
1387 | - private function _associate_registration_with_transaction(EE_Registration $registration) |
|
1388 | - { |
|
1389 | - // add relation to registration |
|
1390 | - $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1391 | - $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1392 | - } |
|
1393 | - |
|
1394 | - |
|
1395 | - /** |
|
1396 | - * _copy_critical_attendee_details_from_primary_registrant |
|
1397 | - * ensures that all attendees at least have data for first name, last name, and email address |
|
1398 | - * |
|
1399 | - * @param array $attendee_data |
|
1400 | - * @return array |
|
1401 | - * @throws EE_Error |
|
1402 | - * @throws InvalidArgumentException |
|
1403 | - * @throws ReflectionException |
|
1404 | - * @throws InvalidDataTypeException |
|
1405 | - * @throws InvalidInterfaceException |
|
1406 | - */ |
|
1407 | - private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
1408 | - { |
|
1409 | - // bare minimum critical details include first name, last name, email address |
|
1410 | - $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1411 | - // add address info to critical details? |
|
1412 | - if (apply_filters( |
|
1413 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
1414 | - false |
|
1415 | - )) { |
|
1416 | - $address_details = array( |
|
1417 | - 'ATT_address', |
|
1418 | - 'ATT_address2', |
|
1419 | - 'ATT_city', |
|
1420 | - 'STA_ID', |
|
1421 | - 'CNT_ISO', |
|
1422 | - 'ATT_zip', |
|
1423 | - 'ATT_phone', |
|
1424 | - ); |
|
1425 | - $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1426 | - } |
|
1427 | - foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1428 | - if (! isset($attendee_data[ $critical_attendee_detail ]) |
|
1429 | - || empty($attendee_data[ $critical_attendee_detail ]) |
|
1430 | - ) { |
|
1431 | - $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
1432 | - $critical_attendee_detail |
|
1433 | - ); |
|
1434 | - } |
|
1435 | - } |
|
1436 | - return $attendee_data; |
|
1437 | - } |
|
1438 | - |
|
1439 | - |
|
1440 | - /** |
|
1441 | - * update_reg_step |
|
1442 | - * this is the final step after a user revisits the site to edit their attendee information |
|
1443 | - * this gets called AFTER the process_reg_step() method above |
|
1444 | - * |
|
1445 | - * @return bool |
|
1446 | - * @throws EE_Error |
|
1447 | - * @throws InvalidArgumentException |
|
1448 | - * @throws ReflectionException |
|
1449 | - * @throws RuntimeException |
|
1450 | - * @throws InvalidDataTypeException |
|
1451 | - * @throws InvalidInterfaceException |
|
1452 | - */ |
|
1453 | - public function update_reg_step() |
|
1454 | - { |
|
1455 | - // save everything |
|
1456 | - if ($this->process_reg_step()) { |
|
1457 | - $this->checkout->redirect = true; |
|
1458 | - $this->checkout->redirect_url = add_query_arg( |
|
1459 | - array( |
|
1460 | - 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
1461 | - 'revisit' => true, |
|
1462 | - ), |
|
1463 | - $this->checkout->thank_you_page_url |
|
1464 | - ); |
|
1465 | - $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1466 | - return true; |
|
1467 | - } |
|
1468 | - return false; |
|
1469 | - } |
|
1249 | + $answer_cache_id = $this->checkout->reg_url_link |
|
1250 | + ? $form_input . '-' . $registration->reg_url_link() |
|
1251 | + : $form_input; |
|
1252 | + $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ]) |
|
1253 | + && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer; |
|
1254 | + // rename form_inputs if they are EE_Attendee properties |
|
1255 | + switch ((string) $form_input) { |
|
1256 | + case 'state': |
|
1257 | + case 'STA_ID': |
|
1258 | + $attendee_property = true; |
|
1259 | + $form_input = 'STA_ID'; |
|
1260 | + break; |
|
1261 | + |
|
1262 | + case 'country': |
|
1263 | + case 'CNT_ISO': |
|
1264 | + $attendee_property = true; |
|
1265 | + $form_input = 'CNT_ISO'; |
|
1266 | + break; |
|
1267 | + |
|
1268 | + default: |
|
1269 | + $ATT_input = 'ATT_' . $form_input; |
|
1270 | + // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
|
1271 | + $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1272 | + $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1273 | + } |
|
1274 | + // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
|
1275 | + // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
|
1276 | + // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
|
1277 | + // if this form input has a corresponding attendee property |
|
1278 | + if ($attendee_property) { |
|
1279 | + $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
1280 | + if ($answer_is_obj) { |
|
1281 | + // and delete the corresponding answer since we won't be storing this data in that object |
|
1282 | + $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer'); |
|
1283 | + $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
1284 | + } |
|
1285 | + return true; |
|
1286 | + } |
|
1287 | + if ($answer_is_obj) { |
|
1288 | + // save this data to the answer object |
|
1289 | + $this->_registration_answers[ $answer_cache_id ]->set_value($input_value); |
|
1290 | + $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
1291 | + return $result !== false; |
|
1292 | + } |
|
1293 | + foreach ($this->_registration_answers as $answer) { |
|
1294 | + if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1295 | + $answer->set_value($input_value); |
|
1296 | + $result = $answer->save(); |
|
1297 | + return $result !== false; |
|
1298 | + } |
|
1299 | + } |
|
1300 | + return false; |
|
1301 | + } |
|
1302 | + |
|
1303 | + |
|
1304 | + /** |
|
1305 | + * _verify_critical_attendee_details_are_set |
|
1306 | + * |
|
1307 | + * @param string $form_input |
|
1308 | + * @param string $input_value |
|
1309 | + * @return boolean |
|
1310 | + */ |
|
1311 | + private function _verify_critical_attendee_details_are_set_and_validate_email( |
|
1312 | + $form_input = '', |
|
1313 | + $input_value = '' |
|
1314 | + ) { |
|
1315 | + if (empty($input_value)) { |
|
1316 | + // if the form input isn't marked as being required, then just return |
|
1317 | + if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) { |
|
1318 | + return true; |
|
1319 | + } |
|
1320 | + switch ($form_input) { |
|
1321 | + case 'fname': |
|
1322 | + EE_Error::add_error( |
|
1323 | + esc_html__('First Name is a required value.', 'event_espresso'), |
|
1324 | + __FILE__, |
|
1325 | + __FUNCTION__, |
|
1326 | + __LINE__ |
|
1327 | + ); |
|
1328 | + return false; |
|
1329 | + break; |
|
1330 | + case 'lname': |
|
1331 | + EE_Error::add_error( |
|
1332 | + esc_html__('Last Name is a required value.', 'event_espresso'), |
|
1333 | + __FILE__, |
|
1334 | + __FUNCTION__, |
|
1335 | + __LINE__ |
|
1336 | + ); |
|
1337 | + return false; |
|
1338 | + break; |
|
1339 | + case 'email': |
|
1340 | + EE_Error::add_error( |
|
1341 | + esc_html__('Please enter a valid email address.', 'event_espresso'), |
|
1342 | + __FILE__, |
|
1343 | + __FUNCTION__, |
|
1344 | + __LINE__ |
|
1345 | + ); |
|
1346 | + return false; |
|
1347 | + break; |
|
1348 | + } |
|
1349 | + } |
|
1350 | + return true; |
|
1351 | + } |
|
1352 | + |
|
1353 | + |
|
1354 | + /** |
|
1355 | + * _associate_attendee_with_registration |
|
1356 | + * |
|
1357 | + * @param EE_Registration $registration |
|
1358 | + * @param EE_Attendee $attendee |
|
1359 | + * @return void |
|
1360 | + * @throws EE_Error |
|
1361 | + * @throws InvalidArgumentException |
|
1362 | + * @throws ReflectionException |
|
1363 | + * @throws RuntimeException |
|
1364 | + * @throws InvalidDataTypeException |
|
1365 | + * @throws InvalidInterfaceException |
|
1366 | + */ |
|
1367 | + private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) |
|
1368 | + { |
|
1369 | + // add relation to attendee |
|
1370 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1371 | + $registration->set_attendee_id($attendee->ID()); |
|
1372 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1373 | + } |
|
1374 | + |
|
1375 | + |
|
1376 | + /** |
|
1377 | + * _associate_registration_with_transaction |
|
1378 | + * |
|
1379 | + * @param EE_Registration $registration |
|
1380 | + * @return void |
|
1381 | + * @throws EE_Error |
|
1382 | + * @throws InvalidArgumentException |
|
1383 | + * @throws ReflectionException |
|
1384 | + * @throws InvalidDataTypeException |
|
1385 | + * @throws InvalidInterfaceException |
|
1386 | + */ |
|
1387 | + private function _associate_registration_with_transaction(EE_Registration $registration) |
|
1388 | + { |
|
1389 | + // add relation to registration |
|
1390 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1391 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1392 | + } |
|
1393 | + |
|
1394 | + |
|
1395 | + /** |
|
1396 | + * _copy_critical_attendee_details_from_primary_registrant |
|
1397 | + * ensures that all attendees at least have data for first name, last name, and email address |
|
1398 | + * |
|
1399 | + * @param array $attendee_data |
|
1400 | + * @return array |
|
1401 | + * @throws EE_Error |
|
1402 | + * @throws InvalidArgumentException |
|
1403 | + * @throws ReflectionException |
|
1404 | + * @throws InvalidDataTypeException |
|
1405 | + * @throws InvalidInterfaceException |
|
1406 | + */ |
|
1407 | + private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) |
|
1408 | + { |
|
1409 | + // bare minimum critical details include first name, last name, email address |
|
1410 | + $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1411 | + // add address info to critical details? |
|
1412 | + if (apply_filters( |
|
1413 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
|
1414 | + false |
|
1415 | + )) { |
|
1416 | + $address_details = array( |
|
1417 | + 'ATT_address', |
|
1418 | + 'ATT_address2', |
|
1419 | + 'ATT_city', |
|
1420 | + 'STA_ID', |
|
1421 | + 'CNT_ISO', |
|
1422 | + 'ATT_zip', |
|
1423 | + 'ATT_phone', |
|
1424 | + ); |
|
1425 | + $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1426 | + } |
|
1427 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1428 | + if (! isset($attendee_data[ $critical_attendee_detail ]) |
|
1429 | + || empty($attendee_data[ $critical_attendee_detail ]) |
|
1430 | + ) { |
|
1431 | + $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
1432 | + $critical_attendee_detail |
|
1433 | + ); |
|
1434 | + } |
|
1435 | + } |
|
1436 | + return $attendee_data; |
|
1437 | + } |
|
1438 | + |
|
1439 | + |
|
1440 | + /** |
|
1441 | + * update_reg_step |
|
1442 | + * this is the final step after a user revisits the site to edit their attendee information |
|
1443 | + * this gets called AFTER the process_reg_step() method above |
|
1444 | + * |
|
1445 | + * @return bool |
|
1446 | + * @throws EE_Error |
|
1447 | + * @throws InvalidArgumentException |
|
1448 | + * @throws ReflectionException |
|
1449 | + * @throws RuntimeException |
|
1450 | + * @throws InvalidDataTypeException |
|
1451 | + * @throws InvalidInterfaceException |
|
1452 | + */ |
|
1453 | + public function update_reg_step() |
|
1454 | + { |
|
1455 | + // save everything |
|
1456 | + if ($this->process_reg_step()) { |
|
1457 | + $this->checkout->redirect = true; |
|
1458 | + $this->checkout->redirect_url = add_query_arg( |
|
1459 | + array( |
|
1460 | + 'e_reg_url_link' => $this->checkout->reg_url_link, |
|
1461 | + 'revisit' => true, |
|
1462 | + ), |
|
1463 | + $this->checkout->thank_you_page_url |
|
1464 | + ); |
|
1465 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1466 | + return true; |
|
1467 | + } |
|
1468 | + return false; |
|
1469 | + } |
|
1470 | 1470 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | ); |
152 | 152 | |
153 | 153 | // if this isn't a revisit, and they have the privacy consent box enalbed, add it |
154 | - if (! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
154 | + if ( ! $this->checkout->revisit && $reg_config->isConsentCheckboxEnabled()) { |
|
155 | 155 | $extra_inputs_section->add_subsections( |
156 | 156 | array( |
157 | 157 | 'consent_box' => new EE_Form_Section_Proper( |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | 'layout_strategy' => |
160 | 160 | new EE_Template_Layout( |
161 | 161 | array( |
162 | - 'input_template_file' => SPCO_REG_STEPS_PATH . $this->_slug . '/privacy_consent.template.php', |
|
162 | + 'input_template_file' => SPCO_REG_STEPS_PATH.$this->_slug.'/privacy_consent.template.php', |
|
163 | 163 | ) |
164 | 164 | ), |
165 | 165 | 'subsections' => array( |
@@ -197,12 +197,12 @@ discard block |
||
197 | 197 | if ($registration instanceof EE_Registration |
198 | 198 | && $this->checkout->visit_allows_processing_of_this_registration($registration) |
199 | 199 | ) { |
200 | - $subsections[ $registration->reg_url_link() ] = $this->_registrations_reg_form($registration); |
|
201 | - $template_args['registrations'][ $registration->reg_url_link() ] = $registration; |
|
202 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
203 | - $template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
200 | + $subsections[$registration->reg_url_link()] = $this->_registrations_reg_form($registration); |
|
201 | + $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
202 | + $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
203 | + $template_args['ticket_count'][$registration->ticket()->ID()] |
|
204 | 204 | ) |
205 | - ? $template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
205 | + ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
206 | 206 | : 1; |
207 | 207 | $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
208 | 208 | $this->checkout->cart->get_grand_total(), |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $ticket_line_item = is_array($ticket_line_item) |
213 | 213 | ? reset($ticket_line_item) |
214 | 214 | : $ticket_line_item; |
215 | - $template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
215 | + $template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
216 | 216 | $Line_Item_Display->display_line_item($ticket_line_item); |
217 | 217 | if ($registration->is_primary_registrant()) { |
218 | 218 | $primary_registrant = $registration->reg_url_link(); |
@@ -225,10 +225,10 @@ discard block |
||
225 | 225 | ? $this->_copy_attendee_info_form() |
226 | 226 | : $this->_auto_copy_attendee_info(); |
227 | 227 | // generate hidden input |
228 | - if (isset($subsections[ $primary_registrant ]) |
|
229 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
228 | + if (isset($subsections[$primary_registrant]) |
|
229 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
230 | 230 | ) { |
231 | - $subsections[ $primary_registrant ]->add_subsections( |
|
231 | + $subsections[$primary_registrant]->add_subsections( |
|
232 | 232 | $copy_options, |
233 | 233 | 'primary_registrant', |
234 | 234 | false |
@@ -240,8 +240,8 @@ discard block |
||
240 | 240 | // Set the registration form template (default: one form per ticket details table). |
241 | 241 | // We decide the template to used based on the number of forms. |
242 | 242 | $this->_template = $this->reg_form_count > 1 |
243 | - ? SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_main.template.php' |
|
244 | - : SPCO_REG_STEPS_PATH . $this->_slug . '/attendee_info_single.template.php'; |
|
243 | + ? SPCO_REG_STEPS_PATH . $this->_slug.'/attendee_info_main.template.php' |
|
244 | + : SPCO_REG_STEPS_PATH.$this->_slug.'/attendee_info_single.template.php'; |
|
245 | 245 | |
246 | 246 | return new EE_Form_Section_Proper( |
247 | 247 | array( |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | if ($question_groups) { |
299 | 299 | // array of params to pass to parent constructor |
300 | 300 | $form_args = array( |
301 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
301 | + 'html_id' => 'ee-registration-'.$registration->reg_url_link(), |
|
302 | 302 | 'html_class' => 'ee-reg-form-attendee-dv', |
303 | 303 | 'html_style' => $this->checkout->admin_request |
304 | 304 | ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | ); |
321 | 321 | foreach ($question_groups as $question_group) { |
322 | 322 | if ($question_group instanceof EE_Question_Group) { |
323 | - $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
323 | + $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
324 | 324 | $registration, |
325 | 325 | $question_group |
326 | 326 | ); |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | $attendee_nmbr++; |
355 | 355 | |
356 | 356 | // Increment the reg forms number if form is valid. |
357 | - if (!empty($form_args)) { |
|
357 | + if ( ! empty($form_args)) { |
|
358 | 358 | $this->reg_form_count++; |
359 | 359 | } |
360 | 360 | |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | // generate hidden input |
378 | 378 | return new EE_Hidden_Input( |
379 | 379 | array( |
380 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
380 | + 'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(), |
|
381 | 381 | 'default' => $additional_attendee_reg_info, |
382 | 382 | ) |
383 | 383 | ); |
@@ -398,12 +398,12 @@ discard block |
||
398 | 398 | { |
399 | 399 | // array of params to pass to parent constructor |
400 | 400 | $form_args = array( |
401 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
401 | + 'html_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-'.$registration->ID(), |
|
402 | 402 | 'html_class' => $this->checkout->admin_request |
403 | 403 | ? 'form-table ee-reg-form-qstn-grp-dv' |
404 | 404 | : 'ee-reg-form-qstn-grp-dv', |
405 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' |
|
406 | - . $registration->ID() . '-lbl', |
|
405 | + 'html_label_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-' |
|
406 | + . $registration->ID().'-lbl', |
|
407 | 407 | 'subsections' => array( |
408 | 408 | 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group), |
409 | 409 | ), |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | // where params |
415 | 415 | $query_params = array('QST_deleted' => 0); |
416 | 416 | // don't load admin only questions on the frontend |
417 | - if (! $this->checkout->admin_request) { |
|
417 | + if ( ! $this->checkout->admin_request) { |
|
418 | 418 | $query_params['QST_admin_only'] = array('!=', true); |
419 | 419 | } |
420 | 420 | $questions = $question_group->get_many_related( |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | $identifier = $question->is_system_question() |
449 | 449 | ? $question->system_ID() |
450 | 450 | : $question->ID(); |
451 | - $form_args['subsections'][ $identifier ] = $this->reg_form_question($registration, $question); |
|
451 | + $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
452 | 452 | } |
453 | 453 | } |
454 | 454 | $form_args['subsections'] = apply_filters( |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | { |
561 | 561 | return new EE_Form_Section_HTML( |
562 | 562 | EEH_Template::locate_template( |
563 | - SPCO_REG_STEPS_PATH . $this->_slug . '/_auto_copy_attendee_info.template.php', |
|
563 | + SPCO_REG_STEPS_PATH.$this->_slug.'/_auto_copy_attendee_info.template.php', |
|
564 | 564 | apply_filters( |
565 | 565 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
566 | 566 | array() |
@@ -593,17 +593,17 @@ discard block |
||
593 | 593 | if ($registration->ticket()->ID() !== $prev_ticket) { |
594 | 594 | $item_name = $registration->ticket()->name(); |
595 | 595 | $item_name .= $registration->ticket()->description() !== '' |
596 | - ? ' - ' . $registration->ticket()->description() |
|
596 | + ? ' - '.$registration->ticket()->description() |
|
597 | 597 | : ''; |
598 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID( |
|
599 | - ) . ']' ] = |
|
598 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID( |
|
599 | + ).']'] = |
|
600 | 600 | new EE_Form_Section_HTML( |
601 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
601 | + '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>' |
|
602 | 602 | ); |
603 | 603 | $prev_ticket = $registration->ticket()->ID(); |
604 | 604 | } |
605 | 605 | |
606 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = |
|
606 | + $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] = |
|
607 | 607 | new EE_Checkbox_Multi_Input( |
608 | 608 | array( |
609 | 609 | $registration->ID() => sprintf( |
@@ -612,7 +612,7 @@ discard block |
||
612 | 612 | ), |
613 | 613 | ), |
614 | 614 | array( |
615 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
615 | + 'html_id' => 'spco-copy-attendee-chk-'.$registration->reg_url_link(), |
|
616 | 616 | 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
617 | 617 | 'display_html_label_text' => false, |
618 | 618 | ) |
@@ -677,14 +677,14 @@ discard block |
||
677 | 677 | } |
678 | 678 | // verify instance |
679 | 679 | if ($answer instanceof EE_Answer) { |
680 | - if (! empty($answer_value)) { |
|
680 | + if ( ! empty($answer_value)) { |
|
681 | 681 | $answer->set('ANS_value', $answer_value); |
682 | 682 | } |
683 | 683 | $answer->cache('Question', $question); |
684 | 684 | // remember system ID had a bug where sometimes it could be null |
685 | 685 | $answer_cache_id = $question->is_system_question() |
686 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
687 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
686 | + ? $question->system_ID().'-'.$registration->reg_url_link() |
|
687 | + : $question->ID().'-'.$registration->reg_url_link(); |
|
688 | 688 | $registration->cache('Answer', $answer, $answer_cache_id); |
689 | 689 | } |
690 | 690 | return $this->_generate_question_input($registration, $question, $answer); |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | $identifier = $question->is_system_question() |
708 | 708 | ? $question->system_ID() |
709 | 709 | : $question->ID(); |
710 | - $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
710 | + $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
711 | 711 | add_filter( |
712 | 712 | 'FHEE__EE_Question__generate_form_input__country_options', |
713 | 713 | array($this, 'use_cached_countries_for_form_input'), |
@@ -721,17 +721,17 @@ discard block |
||
721 | 721 | 4 |
722 | 722 | ); |
723 | 723 | $input_constructor_args = array( |
724 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
725 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
726 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
727 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
724 | + 'html_name' => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']', |
|
725 | + 'html_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
726 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-'.$identifier, |
|
727 | + 'html_label_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
728 | 728 | 'html_label_class' => 'ee-reg-qstn', |
729 | 729 | ); |
730 | 730 | $input_constructor_args['html_label_id'] .= '-lbl'; |
731 | 731 | if ($answer instanceof EE_Answer && $answer->ID()) { |
732 | - $input_constructor_args['html_name'] .= '[' . $answer->ID() . ']'; |
|
733 | - $input_constructor_args['html_id'] .= '-' . $answer->ID(); |
|
734 | - $input_constructor_args['html_label_id'] .= '-' . $answer->ID(); |
|
732 | + $input_constructor_args['html_name'] .= '['.$answer->ID().']'; |
|
733 | + $input_constructor_args['html_id'] .= '-'.$answer->ID(); |
|
734 | + $input_constructor_args['html_label_id'] .= '-'.$answer->ID(); |
|
735 | 735 | } |
736 | 736 | $form_input = $question->generate_form_input( |
737 | 737 | $registration, |
@@ -775,10 +775,10 @@ discard block |
||
775 | 775 | $countries = $this->checkout->action === 'process_reg_step' |
776 | 776 | ? EEM_Country::instance()->get_all_countries() |
777 | 777 | : EEM_Country::instance()->get_all_active_countries(); |
778 | - if (! empty($countries)) { |
|
778 | + if ( ! empty($countries)) { |
|
779 | 779 | foreach ($countries as $country) { |
780 | 780 | if ($country instanceof EE_Country) { |
781 | - $country_options[ $country->ID() ] = $country->name(); |
|
781 | + $country_options[$country->ID()] = $country->name(); |
|
782 | 782 | } |
783 | 783 | } |
784 | 784 | } |
@@ -825,10 +825,10 @@ discard block |
||
825 | 825 | $states = $this->checkout->action === 'process_reg_step' |
826 | 826 | ? EEM_State::instance()->get_all_states() |
827 | 827 | : EEM_State::instance()->get_all_active_states(); |
828 | - if (! empty($states)) { |
|
828 | + if ( ! empty($states)) { |
|
829 | 829 | foreach ($states as $state) { |
830 | 830 | if ($state instanceof EE_State) { |
831 | - $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
831 | + $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
832 | 832 | } |
833 | 833 | } |
834 | 834 | } |
@@ -875,7 +875,7 @@ discard block |
||
875 | 875 | ); |
876 | 876 | return false; |
877 | 877 | } |
878 | - if (! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
878 | + if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
879 | 879 | EE_Error::add_error( |
880 | 880 | esc_html__( |
881 | 881 | 'A valid transaction could not be initiated for processing your registrations.', |
@@ -902,7 +902,7 @@ discard block |
||
902 | 902 | '(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.', |
903 | 903 | 'event_espresso' |
904 | 904 | ), |
905 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" >', |
|
905 | + '<a href="'.get_post_type_archive_link('espresso_events').'" >', |
|
906 | 906 | '</a>', |
907 | 907 | '<br />' |
908 | 908 | ); |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | // but return immediately if the previous step exited early due to errors |
923 | 923 | return false; |
924 | 924 | } |
925 | - if (! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
925 | + if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
926 | 926 | // generate a correctly translated string for all possible singular/plural combinations |
927 | 927 | if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
928 | 928 | $error_msg = sprintf( |
@@ -1005,7 +1005,7 @@ discard block |
||
1005 | 1005 | // grab the saved registrations from the transaction |
1006 | 1006 | foreach ($registrations as $registration) { |
1007 | 1007 | // verify EE_Registration object |
1008 | - if (! $registration instanceof EE_Registration) { |
|
1008 | + if ( ! $registration instanceof EE_Registration) { |
|
1009 | 1009 | EE_Error::add_error( |
1010 | 1010 | esc_html__( |
1011 | 1011 | 'An invalid Registration object was discovered when attempting to process your registration information.', |
@@ -1020,12 +1020,12 @@ discard block |
||
1020 | 1020 | /** @var string $reg_url_link */ |
1021 | 1021 | $reg_url_link = $registration->reg_url_link(); |
1022 | 1022 | // reg_url_link exists ? |
1023 | - if (! empty($reg_url_link)) { |
|
1023 | + if ( ! empty($reg_url_link)) { |
|
1024 | 1024 | // should this registration be processed during this visit ? |
1025 | 1025 | if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
1026 | 1026 | // if NOT revisiting, then let's save the registration now, |
1027 | 1027 | // so that we have a REG_ID to use when generating other objects |
1028 | - if (! $this->checkout->revisit) { |
|
1028 | + if ( ! $this->checkout->revisit) { |
|
1029 | 1029 | $registration->save(); |
1030 | 1030 | } |
1031 | 1031 | /** |
@@ -1049,18 +1049,18 @@ discard block |
||
1049 | 1049 | |
1050 | 1050 | // Houston, we have a registration! |
1051 | 1051 | $att_nmbr++; |
1052 | - $this->_attendee_data[ $reg_url_link ] = array(); |
|
1052 | + $this->_attendee_data[$reg_url_link] = array(); |
|
1053 | 1053 | // grab any existing related answer objects |
1054 | 1054 | $this->_registration_answers = $registration->answers(); |
1055 | 1055 | // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
1056 | - if (isset($valid_data[ $reg_url_link ])) { |
|
1056 | + if (isset($valid_data[$reg_url_link])) { |
|
1057 | 1057 | // do we need to copy basic info from primary attendee ? |
1058 | - $copy_primary = isset($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) |
|
1059 | - && absint($valid_data[ $reg_url_link ]['additional_attendee_reg_info']) === 0; |
|
1058 | + $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
1059 | + && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0; |
|
1060 | 1060 | // filter form input data for this registration |
1061 | - $valid_data[ $reg_url_link ] = (array) apply_filters( |
|
1061 | + $valid_data[$reg_url_link] = (array) apply_filters( |
|
1062 | 1062 | 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
1063 | - $valid_data[ $reg_url_link ] |
|
1063 | + $valid_data[$reg_url_link] |
|
1064 | 1064 | ); |
1065 | 1065 | if (isset($valid_data['primary_attendee'])) { |
1066 | 1066 | $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
@@ -1069,12 +1069,12 @@ discard block |
||
1069 | 1069 | unset($valid_data['primary_attendee']); |
1070 | 1070 | } |
1071 | 1071 | // now loop through our array of valid post data && process attendee reg forms |
1072 | - foreach ($valid_data[ $reg_url_link ] as $form_section => $form_inputs) { |
|
1073 | - if (! in_array($form_section, $non_input_form_sections, true)) { |
|
1072 | + foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
1073 | + if ( ! in_array($form_section, $non_input_form_sections, true)) { |
|
1074 | 1074 | foreach ($form_inputs as $form_input => $input_value) { |
1075 | 1075 | // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
1076 | 1076 | // check for critical inputs |
1077 | - if (! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
1077 | + if ( ! $this->_verify_critical_attendee_details_are_set_and_validate_email( |
|
1078 | 1078 | $form_input, |
1079 | 1079 | $input_value |
1080 | 1080 | ) |
@@ -1086,15 +1086,15 @@ discard block |
||
1086 | 1086 | && ! empty($input_value) |
1087 | 1087 | && $reg_url_link === $primary_registrant['line_item_id'] |
1088 | 1088 | ) { |
1089 | - $primary_registrant[ $form_input ] = $input_value; |
|
1089 | + $primary_registrant[$form_input] = $input_value; |
|
1090 | 1090 | } elseif ($copy_primary |
1091 | 1091 | && $input_value === null |
1092 | - && isset($primary_registrant[ $form_input ]) |
|
1092 | + && isset($primary_registrant[$form_input]) |
|
1093 | 1093 | ) { |
1094 | - $input_value = $primary_registrant[ $form_input ]; |
|
1094 | + $input_value = $primary_registrant[$form_input]; |
|
1095 | 1095 | } |
1096 | 1096 | // now attempt to save the input data |
1097 | - if (! $this->_save_registration_form_input( |
|
1097 | + if ( ! $this->_save_registration_form_input( |
|
1098 | 1098 | $registration, |
1099 | 1099 | $form_input, |
1100 | 1100 | $input_value |
@@ -1130,15 +1130,15 @@ discard block |
||
1130 | 1130 | $attendee = $this->checkout->primary_attendee_obj; |
1131 | 1131 | } else { |
1132 | 1132 | // ensure critical details are set for additional attendees |
1133 | - $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
1133 | + $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
1134 | 1134 | ? $this->_copy_critical_attendee_details_from_primary_registrant( |
1135 | - $this->_attendee_data[ $reg_url_link ] |
|
1135 | + $this->_attendee_data[$reg_url_link] |
|
1136 | 1136 | ) |
1137 | - : $this->_attendee_data[ $reg_url_link ]; |
|
1137 | + : $this->_attendee_data[$reg_url_link]; |
|
1138 | 1138 | // execute create attendee command (which may return an existing attendee) |
1139 | 1139 | $attendee = EE_Registry::instance()->BUS->execute( |
1140 | 1140 | new CreateAttendeeCommand( |
1141 | - $this->_attendee_data[ $reg_url_link ], |
|
1141 | + $this->_attendee_data[$reg_url_link], |
|
1142 | 1142 | $registration |
1143 | 1143 | ) |
1144 | 1144 | ); |
@@ -1151,7 +1151,7 @@ discard block |
||
1151 | 1151 | // add relation to registration, set attendee ID, and cache attendee |
1152 | 1152 | $this->_associate_attendee_with_registration($registration, $attendee); |
1153 | 1153 | // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
1154 | - if (! $registration->attendee() instanceof EE_Attendee) { |
|
1154 | + if ( ! $registration->attendee() instanceof EE_Attendee) { |
|
1155 | 1155 | EE_Error::add_error( |
1156 | 1156 | sprintf( |
1157 | 1157 | esc_html_x( |
@@ -1201,7 +1201,7 @@ discard block |
||
1201 | 1201 | __LINE__ |
1202 | 1202 | ); |
1203 | 1203 | // remove malformed data |
1204 | - unset($valid_data[ $reg_url_link ]); |
|
1204 | + unset($valid_data[$reg_url_link]); |
|
1205 | 1205 | return false; |
1206 | 1206 | } |
1207 | 1207 | } // end of foreach ( $this->checkout->transaction->registrations() as $registration ) |
@@ -1247,10 +1247,10 @@ discard block |
||
1247 | 1247 | * @see https://events.codebasehq.com/projects/event-espresso/tickets/10477 |
1248 | 1248 | */ |
1249 | 1249 | $answer_cache_id = $this->checkout->reg_url_link |
1250 | - ? $form_input . '-' . $registration->reg_url_link() |
|
1250 | + ? $form_input.'-'.$registration->reg_url_link() |
|
1251 | 1251 | : $form_input; |
1252 | - $answer_is_obj = isset($this->_registration_answers[ $answer_cache_id ]) |
|
1253 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer; |
|
1252 | + $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
1253 | + && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer; |
|
1254 | 1254 | // rename form_inputs if they are EE_Attendee properties |
1255 | 1255 | switch ((string) $form_input) { |
1256 | 1256 | case 'state': |
@@ -1266,28 +1266,28 @@ discard block |
||
1266 | 1266 | break; |
1267 | 1267 | |
1268 | 1268 | default: |
1269 | - $ATT_input = 'ATT_' . $form_input; |
|
1269 | + $ATT_input = 'ATT_'.$form_input; |
|
1270 | 1270 | // EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
1271 | 1271 | $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
1272 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1272 | + $form_input = $attendee_property ? 'ATT_'.$form_input : $form_input; |
|
1273 | 1273 | } |
1274 | 1274 | // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
1275 | 1275 | // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
1276 | 1276 | // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
1277 | 1277 | // if this form input has a corresponding attendee property |
1278 | 1278 | if ($attendee_property) { |
1279 | - $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
1279 | + $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
1280 | 1280 | if ($answer_is_obj) { |
1281 | 1281 | // and delete the corresponding answer since we won't be storing this data in that object |
1282 | - $registration->_remove_relation_to($this->_registration_answers[ $answer_cache_id ], 'Answer'); |
|
1283 | - $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
1282 | + $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
1283 | + $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
1284 | 1284 | } |
1285 | 1285 | return true; |
1286 | 1286 | } |
1287 | 1287 | if ($answer_is_obj) { |
1288 | 1288 | // save this data to the answer object |
1289 | - $this->_registration_answers[ $answer_cache_id ]->set_value($input_value); |
|
1290 | - $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
1289 | + $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
1290 | + $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
1291 | 1291 | return $result !== false; |
1292 | 1292 | } |
1293 | 1293 | foreach ($this->_registration_answers as $answer) { |
@@ -1314,7 +1314,7 @@ discard block |
||
1314 | 1314 | ) { |
1315 | 1315 | if (empty($input_value)) { |
1316 | 1316 | // if the form input isn't marked as being required, then just return |
1317 | - if (! isset($this->_required_questions[ $form_input ]) || ! $this->_required_questions[ $form_input ]) { |
|
1317 | + if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
1318 | 1318 | return true; |
1319 | 1319 | } |
1320 | 1320 | switch ($form_input) { |
@@ -1425,10 +1425,10 @@ discard block |
||
1425 | 1425 | $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
1426 | 1426 | } |
1427 | 1427 | foreach ($critical_attendee_details as $critical_attendee_detail) { |
1428 | - if (! isset($attendee_data[ $critical_attendee_detail ]) |
|
1429 | - || empty($attendee_data[ $critical_attendee_detail ]) |
|
1428 | + if ( ! isset($attendee_data[$critical_attendee_detail]) |
|
1429 | + || empty($attendee_data[$critical_attendee_detail]) |
|
1430 | 1430 | ) { |
1431 | - $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
1431 | + $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
1432 | 1432 | $critical_attendee_detail |
1433 | 1433 | ); |
1434 | 1434 | } |
@@ -6,16 +6,16 @@ discard block |
||
6 | 6 | <?php if (!is_admin()) : ?> |
7 | 7 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
8 | 8 | <?php echo apply_filters( |
9 | - 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
10 | - sprintf( |
|
11 | - __( |
|
12 | - 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
13 | - 'event_espresso' |
|
14 | - ), |
|
15 | - '<br />', |
|
16 | - '<span class="asterisk">*</span>' |
|
17 | - ) |
|
18 | - ); ?> |
|
9 | + 'FHEE__registration_page_attendee_information__attendee_information_pg', |
|
10 | + sprintf( |
|
11 | + __( |
|
12 | + 'In order to process your registration, we ask you to provide the following information.%1$sPlease note that all fields marked with an asterisk (%2$s) are required.', |
|
13 | + 'event_espresso' |
|
14 | + ), |
|
15 | + '<br />', |
|
16 | + '<span class="asterisk">*</span>' |
|
17 | + ) |
|
18 | + ); ?> |
|
19 | 19 | </p> |
20 | 20 | <?php endif; ?> |
21 | 21 | |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | $prev_ticket = 0; |
26 | 26 | |
27 | 27 | if (count($registrations) > 0) { |
28 | - ?> |
|
28 | + ?> |
|
29 | 29 | |
30 | 30 | <div id="spco-attendee-panel-dv-single" |
31 | 31 | class="spco-attendee-panel-dv spco-attendee-ticket-single"> |
@@ -40,52 +40,52 @@ discard block |
||
40 | 40 | <th scope="col" width="" class="jst-left"><?php _e('Name and Description', 'event_espresso'); ?></th> |
41 | 41 | <th scope="col" width="7.5%" class="jst-rght"> |
42 | 42 | <?php _e( |
43 | - 'Qty', |
|
44 | - 'event_espresso' |
|
45 | - ); ?></th> |
|
43 | + 'Qty', |
|
44 | + 'event_espresso' |
|
45 | + ); ?></th> |
|
46 | 46 | <th scope="col" width="17.5%" class="jst-rght"> |
47 | 47 | <?php _e( |
48 | - 'Price', |
|
49 | - 'event_espresso' |
|
50 | - ); ?></th> |
|
48 | + 'Price', |
|
49 | + 'event_espresso' |
|
50 | + ); ?></th> |
|
51 | 51 | <th scope="col" width="17.5%" class="jst-rght"> |
52 | 52 | <?php _e( |
53 | - 'Total', |
|
54 | - 'event_espresso' |
|
55 | - ); ?></th> |
|
53 | + 'Total', |
|
54 | + 'event_espresso' |
|
55 | + ); ?></th> |
|
56 | 56 | </tr> |
57 | 57 | </thead> |
58 | 58 | <tbody> |
59 | 59 | <?php |
60 | - // Store previous values to avoid duplicated rows. |
|
61 | - $prev_ticket = 0; |
|
62 | - // Display all tickets inside. |
|
63 | - foreach ($registrations as $registration) { |
|
64 | - if ($registration instanceof EE_Registration) { |
|
65 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
66 | - echo $ticket_line_item[ $registration->ticket()->ID() ]; |
|
67 | - } |
|
60 | + // Store previous values to avoid duplicated rows. |
|
61 | + $prev_ticket = 0; |
|
62 | + // Display all tickets inside. |
|
63 | + foreach ($registrations as $registration) { |
|
64 | + if ($registration instanceof EE_Registration) { |
|
65 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
66 | + echo $ticket_line_item[ $registration->ticket()->ID() ]; |
|
67 | + } |
|
68 | 68 | |
69 | - $prev_ticket = $registration->ticket()->ID(); |
|
70 | - } |
|
71 | - } |
|
72 | - ?> |
|
69 | + $prev_ticket = $registration->ticket()->ID(); |
|
70 | + } |
|
71 | + } |
|
72 | + ?> |
|
73 | 73 | </tbody> |
74 | 74 | </table> |
75 | 75 | </div> |
76 | 76 | </div> |
77 | 77 | |
78 | 78 | <?php |
79 | - // Display the forms below the table. |
|
80 | - foreach ($registrations as $registration) { |
|
81 | - if ($registration instanceof EE_Registration) { |
|
82 | - // Attendee Questions. |
|
83 | - $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
84 | - echo ${$reg_form}; |
|
85 | - } // if ( $registration instanceof EE_Registration ) |
|
86 | - } // end foreach ( $registrations as $registration ) |
|
79 | + // Display the forms below the table. |
|
80 | + foreach ($registrations as $registration) { |
|
81 | + if ($registration instanceof EE_Registration) { |
|
82 | + // Attendee Questions. |
|
83 | + $reg_form = EE_Template_Layout::get_subform_name($registration->reg_url_link()); |
|
84 | + echo ${$reg_form}; |
|
85 | + } // if ( $registration instanceof EE_Registration ) |
|
86 | + } // end foreach ( $registrations as $registration ) |
|
87 | 87 | |
88 | - echo $default_hidden_inputs; |
|
88 | + echo $default_hidden_inputs; |
|
89 | 89 | } // end if ( count( $registrations ) > 0 ) |
90 | 90 | |
91 | 91 | ?> |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | /** @var array $ticket_line_item */ |
4 | 4 | /** @var string $default_hidden_inputs */ |
5 | 5 | ?> |
6 | -<?php if (!is_admin()) : ?> |
|
6 | +<?php if ( ! is_admin()) : ?> |
|
7 | 7 | <p id="spco-attendee_information-pg" class="spco-steps-pg small-text drk-grey-text"> |
8 | 8 | <?php echo apply_filters( |
9 | 9 | 'FHEE__registration_page_attendee_information__attendee_information_pg', |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | class="spco-attendee-panel-dv spco-attendee-ticket-single"> |
32 | 32 | |
33 | 33 | <div class="spco-ticket-info-dv small-text"> |
34 | - <?php if (!is_admin()) : ?> |
|
34 | + <?php if ( ! is_admin()) : ?> |
|
35 | 35 | <h5><?php _e('Details', 'event_espresso'); ?></h5> |
36 | 36 | <?php endif; ?> |
37 | 37 | <table class="spco-ticket-details"> |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | foreach ($registrations as $registration) { |
64 | 64 | if ($registration instanceof EE_Registration) { |
65 | 65 | if ($registration->ticket()->ID() !== $prev_ticket) { |
66 | - echo $ticket_line_item[ $registration->ticket()->ID() ]; |
|
66 | + echo $ticket_line_item[$registration->ticket()->ID()]; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | $prev_ticket = $registration->ticket()->ID(); |
@@ -270,7 +270,7 @@ |
||
270 | 270 | * @param string $asset_type |
271 | 271 | * @param string $handle |
272 | 272 | * @param array $extra_dependencies |
273 | - * @return array |
|
273 | + * @return string |
|
274 | 274 | * @since 4.10.2.p |
275 | 275 | */ |
276 | 276 | private function getAssetDetails($asset_type, $handle, $extra_dependencies = []) |
@@ -23,284 +23,284 @@ |
||
23 | 23 | abstract class AssetManager implements AssetManagerInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var AssetCollection $assets |
|
28 | - */ |
|
29 | - protected $assets; |
|
26 | + /** |
|
27 | + * @var AssetCollection $assets |
|
28 | + */ |
|
29 | + protected $assets; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var DomainInterface |
|
33 | - */ |
|
34 | - protected $domain; |
|
31 | + /** |
|
32 | + * @var DomainInterface |
|
33 | + */ |
|
34 | + protected $domain; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var Registry $registry |
|
38 | - */ |
|
39 | - protected $registry; |
|
36 | + /** |
|
37 | + * @var Registry $registry |
|
38 | + */ |
|
39 | + protected $registry; |
|
40 | 40 | |
41 | 41 | |
42 | - /** |
|
43 | - * AssetRegister constructor. |
|
44 | - * |
|
45 | - * @param DomainInterface $domain |
|
46 | - * @param AssetCollection $assets |
|
47 | - * @param Registry $registry |
|
48 | - */ |
|
49 | - public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
|
50 | - { |
|
51 | - $this->domain = $domain; |
|
52 | - $this->assets = $assets; |
|
53 | - $this->registry = $registry; |
|
54 | - add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
55 | - add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
56 | - add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2); |
|
57 | - add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2); |
|
58 | - } |
|
42 | + /** |
|
43 | + * AssetRegister constructor. |
|
44 | + * |
|
45 | + * @param DomainInterface $domain |
|
46 | + * @param AssetCollection $assets |
|
47 | + * @param Registry $registry |
|
48 | + */ |
|
49 | + public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
|
50 | + { |
|
51 | + $this->domain = $domain; |
|
52 | + $this->assets = $assets; |
|
53 | + $this->registry = $registry; |
|
54 | + add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
55 | + add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
56 | + add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2); |
|
57 | + add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * @since 4.9.71.p |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function assetNamespace() |
|
66 | - { |
|
67 | - return $this->domain->assetNamespace(); |
|
68 | - } |
|
61 | + /** |
|
62 | + * @since 4.9.71.p |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function assetNamespace() |
|
66 | + { |
|
67 | + return $this->domain->assetNamespace(); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * @return void |
|
73 | - * @throws DuplicateCollectionIdentifierException |
|
74 | - * @throws InvalidDataTypeException |
|
75 | - * @throws InvalidEntityException |
|
76 | - * @since 4.9.62.p |
|
77 | - */ |
|
78 | - public function addManifestFile() |
|
79 | - { |
|
80 | - // if a manifest file has already been added for this domain, then just return |
|
81 | - if ($this->assets->has($this->domain->assetNamespace())) { |
|
82 | - return; |
|
83 | - } |
|
84 | - $asset = new ManifestFile($this->domain); |
|
85 | - $this->assets->add($asset, $this->domain->assetNamespace()); |
|
86 | - } |
|
71 | + /** |
|
72 | + * @return void |
|
73 | + * @throws DuplicateCollectionIdentifierException |
|
74 | + * @throws InvalidDataTypeException |
|
75 | + * @throws InvalidEntityException |
|
76 | + * @since 4.9.62.p |
|
77 | + */ |
|
78 | + public function addManifestFile() |
|
79 | + { |
|
80 | + // if a manifest file has already been added for this domain, then just return |
|
81 | + if ($this->assets->has($this->domain->assetNamespace())) { |
|
82 | + return; |
|
83 | + } |
|
84 | + $asset = new ManifestFile($this->domain); |
|
85 | + $this->assets->add($asset, $this->domain->assetNamespace()); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * @return ManifestFile[] |
|
91 | - * @since 4.9.62.p |
|
92 | - */ |
|
93 | - public function getManifestFile() |
|
94 | - { |
|
95 | - return $this->assets->getManifestFiles(); |
|
96 | - } |
|
89 | + /** |
|
90 | + * @return ManifestFile[] |
|
91 | + * @since 4.9.62.p |
|
92 | + */ |
|
93 | + public function getManifestFile() |
|
94 | + { |
|
95 | + return $this->assets->getManifestFiles(); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * @param string $handle |
|
101 | - * @param string $source |
|
102 | - * @param array $dependencies |
|
103 | - * @param bool $load_in_footer |
|
104 | - * @param string $version |
|
105 | - * @return JavascriptAsset |
|
106 | - * @throws DuplicateCollectionIdentifierException |
|
107 | - * @throws InvalidDataTypeException |
|
108 | - * @throws InvalidEntityException |
|
109 | - * @throws DomainException |
|
110 | - * @since 4.9.62.p |
|
111 | - */ |
|
112 | - public function addJavascript( |
|
113 | - $handle, |
|
114 | - $source, |
|
115 | - array $dependencies = array(), |
|
116 | - $load_in_footer = true, |
|
117 | - $version = '' |
|
118 | - ) { |
|
119 | - $asset = new JavascriptAsset( |
|
120 | - $handle, |
|
121 | - $source, |
|
122 | - array_unique($dependencies), |
|
123 | - $load_in_footer, |
|
124 | - $this->domain, |
|
125 | - $version |
|
126 | - ); |
|
127 | - $this->assets->add($asset, $handle); |
|
128 | - return $asset; |
|
129 | - } |
|
99 | + /** |
|
100 | + * @param string $handle |
|
101 | + * @param string $source |
|
102 | + * @param array $dependencies |
|
103 | + * @param bool $load_in_footer |
|
104 | + * @param string $version |
|
105 | + * @return JavascriptAsset |
|
106 | + * @throws DuplicateCollectionIdentifierException |
|
107 | + * @throws InvalidDataTypeException |
|
108 | + * @throws InvalidEntityException |
|
109 | + * @throws DomainException |
|
110 | + * @since 4.9.62.p |
|
111 | + */ |
|
112 | + public function addJavascript( |
|
113 | + $handle, |
|
114 | + $source, |
|
115 | + array $dependencies = array(), |
|
116 | + $load_in_footer = true, |
|
117 | + $version = '' |
|
118 | + ) { |
|
119 | + $asset = new JavascriptAsset( |
|
120 | + $handle, |
|
121 | + $source, |
|
122 | + array_unique($dependencies), |
|
123 | + $load_in_footer, |
|
124 | + $this->domain, |
|
125 | + $version |
|
126 | + ); |
|
127 | + $this->assets->add($asset, $handle); |
|
128 | + return $asset; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * Used to register a javascript asset where everything is dynamically derived from the given handle. |
|
134 | - * |
|
135 | - * @param string $handle |
|
136 | - * @param string|array $extra_dependencies |
|
137 | - * @return JavascriptAsset |
|
138 | - * @throws DuplicateCollectionIdentifierException |
|
139 | - * @throws InvalidDataTypeException |
|
140 | - * @throws InvalidEntityException |
|
141 | - * @throws DomainException |
|
142 | - */ |
|
143 | - public function addJs($handle, $extra_dependencies = []) |
|
144 | - { |
|
145 | - $details = $this->getAssetDetails( |
|
146 | - Asset::TYPE_JS, |
|
147 | - $handle, |
|
148 | - $extra_dependencies |
|
149 | - ); |
|
150 | - return $this->addJavascript( |
|
151 | - $handle, |
|
152 | - $this->registry->getJsUrl($this->domain->assetNamespace(), $handle), |
|
153 | - $details['dependencies'], |
|
154 | - true, |
|
155 | - $details['version'] |
|
156 | - ); |
|
157 | - } |
|
132 | + /** |
|
133 | + * Used to register a javascript asset where everything is dynamically derived from the given handle. |
|
134 | + * |
|
135 | + * @param string $handle |
|
136 | + * @param string|array $extra_dependencies |
|
137 | + * @return JavascriptAsset |
|
138 | + * @throws DuplicateCollectionIdentifierException |
|
139 | + * @throws InvalidDataTypeException |
|
140 | + * @throws InvalidEntityException |
|
141 | + * @throws DomainException |
|
142 | + */ |
|
143 | + public function addJs($handle, $extra_dependencies = []) |
|
144 | + { |
|
145 | + $details = $this->getAssetDetails( |
|
146 | + Asset::TYPE_JS, |
|
147 | + $handle, |
|
148 | + $extra_dependencies |
|
149 | + ); |
|
150 | + return $this->addJavascript( |
|
151 | + $handle, |
|
152 | + $this->registry->getJsUrl($this->domain->assetNamespace(), $handle), |
|
153 | + $details['dependencies'], |
|
154 | + true, |
|
155 | + $details['version'] |
|
156 | + ); |
|
157 | + } |
|
158 | 158 | |
159 | 159 | |
160 | - /** |
|
161 | - * @param string $handle |
|
162 | - * @param array $dependencies |
|
163 | - * @param bool $load_in_footer |
|
164 | - * @param string $version |
|
165 | - * @return JavascriptAsset |
|
166 | - * @throws DomainException |
|
167 | - * @throws DuplicateCollectionIdentifierException |
|
168 | - * @throws InvalidDataTypeException |
|
169 | - * @throws InvalidEntityException |
|
170 | - * @since 4.9.71.p |
|
171 | - */ |
|
172 | - public function addVendorJavascript( |
|
173 | - $handle, |
|
174 | - array $dependencies = array(), |
|
175 | - $load_in_footer = true, |
|
176 | - $version = '' |
|
177 | - ) { |
|
178 | - $dev_suffix = wp_scripts_get_suffix('dev'); |
|
179 | - $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/'; |
|
180 | - return $this->addJavascript( |
|
181 | - $handle, |
|
182 | - "{$vendor_path}{$handle}{$dev_suffix}.js", |
|
183 | - $dependencies, |
|
184 | - $load_in_footer, |
|
185 | - $version |
|
186 | - ); |
|
187 | - } |
|
160 | + /** |
|
161 | + * @param string $handle |
|
162 | + * @param array $dependencies |
|
163 | + * @param bool $load_in_footer |
|
164 | + * @param string $version |
|
165 | + * @return JavascriptAsset |
|
166 | + * @throws DomainException |
|
167 | + * @throws DuplicateCollectionIdentifierException |
|
168 | + * @throws InvalidDataTypeException |
|
169 | + * @throws InvalidEntityException |
|
170 | + * @since 4.9.71.p |
|
171 | + */ |
|
172 | + public function addVendorJavascript( |
|
173 | + $handle, |
|
174 | + array $dependencies = array(), |
|
175 | + $load_in_footer = true, |
|
176 | + $version = '' |
|
177 | + ) { |
|
178 | + $dev_suffix = wp_scripts_get_suffix('dev'); |
|
179 | + $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/'; |
|
180 | + return $this->addJavascript( |
|
181 | + $handle, |
|
182 | + "{$vendor_path}{$handle}{$dev_suffix}.js", |
|
183 | + $dependencies, |
|
184 | + $load_in_footer, |
|
185 | + $version |
|
186 | + ); |
|
187 | + } |
|
188 | 188 | |
189 | 189 | |
190 | - /** |
|
191 | - * @param string $handle |
|
192 | - * @param string $source |
|
193 | - * @param array $dependencies |
|
194 | - * @param string $media |
|
195 | - * @param string $version |
|
196 | - * @return StylesheetAsset |
|
197 | - * @throws DomainException |
|
198 | - * @throws DuplicateCollectionIdentifierException |
|
199 | - * @throws InvalidDataTypeException |
|
200 | - * @throws InvalidEntityException |
|
201 | - * @since 4.9.62.p |
|
202 | - */ |
|
203 | - public function addStylesheet( |
|
204 | - $handle, |
|
205 | - $source, |
|
206 | - array $dependencies = array(), |
|
207 | - $media = 'all', |
|
208 | - $version = '' |
|
209 | - ) { |
|
210 | - $asset = new StylesheetAsset( |
|
211 | - $handle, |
|
212 | - $source, |
|
213 | - array_unique($dependencies), |
|
214 | - $this->domain, |
|
215 | - $media, |
|
216 | - $version |
|
217 | - ); |
|
218 | - $this->assets->add($asset, $handle); |
|
219 | - return $asset; |
|
220 | - } |
|
190 | + /** |
|
191 | + * @param string $handle |
|
192 | + * @param string $source |
|
193 | + * @param array $dependencies |
|
194 | + * @param string $media |
|
195 | + * @param string $version |
|
196 | + * @return StylesheetAsset |
|
197 | + * @throws DomainException |
|
198 | + * @throws DuplicateCollectionIdentifierException |
|
199 | + * @throws InvalidDataTypeException |
|
200 | + * @throws InvalidEntityException |
|
201 | + * @since 4.9.62.p |
|
202 | + */ |
|
203 | + public function addStylesheet( |
|
204 | + $handle, |
|
205 | + $source, |
|
206 | + array $dependencies = array(), |
|
207 | + $media = 'all', |
|
208 | + $version = '' |
|
209 | + ) { |
|
210 | + $asset = new StylesheetAsset( |
|
211 | + $handle, |
|
212 | + $source, |
|
213 | + array_unique($dependencies), |
|
214 | + $this->domain, |
|
215 | + $media, |
|
216 | + $version |
|
217 | + ); |
|
218 | + $this->assets->add($asset, $handle); |
|
219 | + return $asset; |
|
220 | + } |
|
221 | 221 | |
222 | 222 | |
223 | - /** |
|
224 | - * Used to register a css asset where everything is dynamically derived from the given handle. |
|
225 | - * |
|
226 | - * @param string $handle |
|
227 | - * @param string|array $extra_dependencies |
|
228 | - * @return StylesheetAsset |
|
229 | - * @throws DuplicateCollectionIdentifierException |
|
230 | - * @throws InvalidDataTypeException |
|
231 | - * @throws InvalidEntityException |
|
232 | - * @throws DomainException |
|
233 | - */ |
|
234 | - public function addCss($handle, $extra_dependencies = []) |
|
235 | - { |
|
236 | - $details = $this->getAssetDetails( |
|
237 | - Asset::TYPE_CSS, |
|
238 | - $handle, |
|
239 | - $extra_dependencies |
|
240 | - ); |
|
241 | - return $this->addStylesheet( |
|
242 | - $handle, |
|
243 | - $this->registry->getCssUrl($this->domain->assetNamespace(), $handle), |
|
244 | - $details['dependencies'], |
|
245 | - 'all', |
|
246 | - $details['version'] |
|
247 | - ); |
|
248 | - } |
|
223 | + /** |
|
224 | + * Used to register a css asset where everything is dynamically derived from the given handle. |
|
225 | + * |
|
226 | + * @param string $handle |
|
227 | + * @param string|array $extra_dependencies |
|
228 | + * @return StylesheetAsset |
|
229 | + * @throws DuplicateCollectionIdentifierException |
|
230 | + * @throws InvalidDataTypeException |
|
231 | + * @throws InvalidEntityException |
|
232 | + * @throws DomainException |
|
233 | + */ |
|
234 | + public function addCss($handle, $extra_dependencies = []) |
|
235 | + { |
|
236 | + $details = $this->getAssetDetails( |
|
237 | + Asset::TYPE_CSS, |
|
238 | + $handle, |
|
239 | + $extra_dependencies |
|
240 | + ); |
|
241 | + return $this->addStylesheet( |
|
242 | + $handle, |
|
243 | + $this->registry->getCssUrl($this->domain->assetNamespace(), $handle), |
|
244 | + $details['dependencies'], |
|
245 | + 'all', |
|
246 | + $details['version'] |
|
247 | + ); |
|
248 | + } |
|
249 | 249 | |
250 | 250 | |
251 | - /** |
|
252 | - * @param string $handle |
|
253 | - * @return bool |
|
254 | - * @since 4.9.62.p |
|
255 | - */ |
|
256 | - public function enqueueAsset($handle) |
|
257 | - { |
|
258 | - if ($this->assets->has($handle)) { |
|
259 | - $asset = $this->assets->get($handle); |
|
260 | - if ($asset->isRegistered()) { |
|
261 | - $asset->enqueueAsset(); |
|
262 | - return true; |
|
263 | - } |
|
264 | - } |
|
265 | - return false; |
|
266 | - } |
|
251 | + /** |
|
252 | + * @param string $handle |
|
253 | + * @return bool |
|
254 | + * @since 4.9.62.p |
|
255 | + */ |
|
256 | + public function enqueueAsset($handle) |
|
257 | + { |
|
258 | + if ($this->assets->has($handle)) { |
|
259 | + $asset = $this->assets->get($handle); |
|
260 | + if ($asset->isRegistered()) { |
|
261 | + $asset->enqueueAsset(); |
|
262 | + return true; |
|
263 | + } |
|
264 | + } |
|
265 | + return false; |
|
266 | + } |
|
267 | 267 | |
268 | 268 | |
269 | - /** |
|
270 | - * @param string $asset_type |
|
271 | - * @param string $handle |
|
272 | - * @param array $extra_dependencies |
|
273 | - * @return array |
|
274 | - * @since 4.10.2.p |
|
275 | - */ |
|
276 | - private function getAssetDetails($asset_type, $handle, $extra_dependencies = []) |
|
277 | - { |
|
278 | - $getAssetDetails = ''; |
|
279 | - switch ($asset_type) { |
|
280 | - case Asset::TYPE_JS : |
|
281 | - $getAssetDetails = 'getJsAssetDetails'; |
|
282 | - break; |
|
283 | - case Asset::TYPE_CSS : |
|
284 | - $getAssetDetails = 'getCssAssetDetails'; |
|
285 | - break; |
|
286 | - } |
|
287 | - if ($getAssetDetails === '') { |
|
288 | - return ['dependencies' => [], 'version' => '']; |
|
289 | - } |
|
290 | - $details = $this->registry->$getAssetDetails( |
|
291 | - $this->domain->assetNamespace(), |
|
292 | - $handle |
|
293 | - ); |
|
294 | - $details['dependencies'] = isset($details['dependencies']) |
|
295 | - ? $details['dependencies'] |
|
296 | - : []; |
|
297 | - $details['version'] = isset($details['version']) |
|
298 | - ? $details['version'] |
|
299 | - : ''; |
|
300 | - $details['dependencies'] = ! empty($extra_dependencies) |
|
301 | - ? array_merge($details['dependencies'], (array) $extra_dependencies) |
|
302 | - : $details['dependencies']; |
|
303 | - return $details; |
|
269 | + /** |
|
270 | + * @param string $asset_type |
|
271 | + * @param string $handle |
|
272 | + * @param array $extra_dependencies |
|
273 | + * @return array |
|
274 | + * @since 4.10.2.p |
|
275 | + */ |
|
276 | + private function getAssetDetails($asset_type, $handle, $extra_dependencies = []) |
|
277 | + { |
|
278 | + $getAssetDetails = ''; |
|
279 | + switch ($asset_type) { |
|
280 | + case Asset::TYPE_JS : |
|
281 | + $getAssetDetails = 'getJsAssetDetails'; |
|
282 | + break; |
|
283 | + case Asset::TYPE_CSS : |
|
284 | + $getAssetDetails = 'getCssAssetDetails'; |
|
285 | + break; |
|
286 | + } |
|
287 | + if ($getAssetDetails === '') { |
|
288 | + return ['dependencies' => [], 'version' => '']; |
|
289 | + } |
|
290 | + $details = $this->registry->$getAssetDetails( |
|
291 | + $this->domain->assetNamespace(), |
|
292 | + $handle |
|
293 | + ); |
|
294 | + $details['dependencies'] = isset($details['dependencies']) |
|
295 | + ? $details['dependencies'] |
|
296 | + : []; |
|
297 | + $details['version'] = isset($details['version']) |
|
298 | + ? $details['version'] |
|
299 | + : ''; |
|
300 | + $details['dependencies'] = ! empty($extra_dependencies) |
|
301 | + ? array_merge($details['dependencies'], (array) $extra_dependencies) |
|
302 | + : $details['dependencies']; |
|
303 | + return $details; |
|
304 | 304 | |
305 | - } |
|
305 | + } |
|
306 | 306 | } |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.3.rc.000'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.3.rc.000'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -13,10 +13,10 @@ |
||
13 | 13 | interface AdminPageHeaderDecoratorInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param string $text |
|
18 | - * @return string |
|
19 | - * @since 4.10.2.p |
|
20 | - */ |
|
21 | - public function getHeaderText($text = ''); |
|
16 | + /** |
|
17 | + * @param string $text |
|
18 | + * @return string |
|
19 | + * @since 4.10.2.p |
|
20 | + */ |
|
21 | + public function getHeaderText($text = ''); |
|
22 | 22 | } |
@@ -11,1257 +11,1257 @@ |
||
11 | 11 | abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * the input's name attribute |
|
16 | - * |
|
17 | - * @var string |
|
18 | - */ |
|
19 | - protected $_html_name; |
|
20 | - |
|
21 | - /** |
|
22 | - * id for the html label tag |
|
23 | - * |
|
24 | - * @var string |
|
25 | - */ |
|
26 | - protected $_html_label_id; |
|
27 | - |
|
28 | - /** |
|
29 | - * class for teh html label tag |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected $_html_label_class; |
|
34 | - |
|
35 | - /** |
|
36 | - * style for teh html label tag |
|
37 | - * |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected $_html_label_style; |
|
41 | - |
|
42 | - /** |
|
43 | - * text to be placed in the html label |
|
44 | - * |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - protected $_html_label_text; |
|
48 | - |
|
49 | - /** |
|
50 | - * the full html label. If used, all other html_label_* properties are invalid |
|
51 | - * |
|
52 | - * @var string |
|
53 | - */ |
|
54 | - protected $_html_label; |
|
55 | - |
|
56 | - /** |
|
57 | - * HTML to use for help text (normally placed below form input), in a span which normally |
|
58 | - * has a class of 'description' |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - protected $_html_help_text; |
|
63 | - |
|
64 | - /** |
|
65 | - * CSS classes for displaying the help span |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
69 | - protected $_html_help_class = 'description'; |
|
70 | - |
|
71 | - /** |
|
72 | - * CSS to put in the style attribute on the help span |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - protected $_html_help_style; |
|
77 | - |
|
78 | - /** |
|
79 | - * Stores whether or not this input's response is required. |
|
80 | - * Because certain styling elements may also want to know that this |
|
81 | - * input is required etc. |
|
82 | - * |
|
83 | - * @var boolean |
|
84 | - */ |
|
85 | - protected $_required; |
|
86 | - |
|
87 | - /** |
|
88 | - * css class added to required inputs |
|
89 | - * |
|
90 | - * @var string |
|
91 | - */ |
|
92 | - protected $_required_css_class = 'ee-required'; |
|
93 | - |
|
94 | - /** |
|
95 | - * css styles applied to button type inputs |
|
96 | - * |
|
97 | - * @var string |
|
98 | - */ |
|
99 | - protected $_button_css_attributes; |
|
100 | - |
|
101 | - /** |
|
102 | - * The raw data submitted for this, like in the $_POST super global. |
|
103 | - * Generally unsafe for usage in client code |
|
104 | - * |
|
105 | - * @var mixed string or array |
|
106 | - */ |
|
107 | - protected $_raw_value; |
|
108 | - |
|
109 | - /** |
|
110 | - * Value normalized according to the input's normalization strategy. |
|
111 | - * The normalization strategy dictates whether this is a string, int, float, |
|
112 | - * boolean, or array of any of those. |
|
113 | - * |
|
114 | - * @var mixed |
|
115 | - */ |
|
116 | - protected $_normalized_value; |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Normalized default value either initially set on the input, or provided by calling |
|
121 | - * set_default(). |
|
122 | - * @var mixed |
|
123 | - */ |
|
124 | - protected $_default; |
|
125 | - |
|
126 | - /** |
|
127 | - * Strategy used for displaying this field. |
|
128 | - * Child classes must use _get_display_strategy to access it. |
|
129 | - * |
|
130 | - * @var EE_Display_Strategy_Base |
|
131 | - */ |
|
132 | - private $_display_strategy; |
|
133 | - |
|
134 | - /** |
|
135 | - * Gets all the validation strategies used on this field |
|
136 | - * |
|
137 | - * @var EE_Validation_Strategy_Base[] |
|
138 | - */ |
|
139 | - private $_validation_strategies = array(); |
|
140 | - |
|
141 | - /** |
|
142 | - * The normalization strategy for this field |
|
143 | - * |
|
144 | - * @var EE_Normalization_Strategy_Base |
|
145 | - */ |
|
146 | - private $_normalization_strategy; |
|
147 | - |
|
148 | - /** |
|
149 | - * Strategy for removing sensitive data after we're done with the form input |
|
150 | - * |
|
151 | - * @var EE_Sensitive_Data_Removal_Base |
|
152 | - */ |
|
153 | - protected $_sensitive_data_removal_strategy; |
|
154 | - |
|
155 | - /** |
|
156 | - * Whether this input has been disabled or not. |
|
157 | - * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled. |
|
158 | - * (Client-side code that wants to dynamically disable it must also add this hidden input). |
|
159 | - * When the form is submitted, if the input is disabled in the PHP formsection, then input is ignored. |
|
160 | - * If the input is missing from the $_REQUEST data but the hidden input indicating the input is disabled, then the input is again ignored. |
|
161 | - * |
|
162 | - * @var boolean |
|
163 | - */ |
|
164 | - protected $disabled = false; |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @param array $input_args { |
|
170 | - * @type string $html_name the html name for the input |
|
171 | - * @type string $html_label_id the id attribute to give to the html label tag |
|
172 | - * @type string $html_label_class the class attribute to give to the html label tag |
|
173 | - * @type string $html_label_style the style attribute to give ot teh label tag |
|
174 | - * @type string $html_label_text the text to put in the label tag |
|
175 | - * @type string $html_label the full html label. If used, |
|
176 | - * all other html_label_* args are invalid |
|
177 | - * @type string $html_help_text text to put in help element |
|
178 | - * @type string $html_help_style style attribute to give to teh help element |
|
179 | - * @type string $html_help_class class attribute to give to the help element |
|
180 | - * @type string $default default value NORMALIZED (eg, if providing the default |
|
181 | - * for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') |
|
182 | - * @type EE_Display_Strategy_Base $display strategy |
|
183 | - * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
184 | - * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
185 | - * @type boolean $ignore_input special argument which can be used to avoid adding any validation strategies, |
|
186 | - * and sets the normalization strategy to the Null normalization. This is good |
|
187 | - * when you want the input to be totally ignored server-side (like when using |
|
188 | - * React.js form inputs) |
|
189 | - * } |
|
190 | - */ |
|
191 | - public function __construct($input_args = array()) |
|
192 | - { |
|
193 | - $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
194 | - // the following properties must be cast as arrays |
|
195 | - if (isset($input_args['validation_strategies'])) { |
|
196 | - foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { |
|
197 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) { |
|
198 | - $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy; |
|
199 | - } |
|
200 | - } |
|
201 | - unset($input_args['validation_strategies']); |
|
202 | - } |
|
203 | - if (isset($input_args['ignore_input'])) { |
|
204 | - $this->_validation_strategies = array(); |
|
205 | - } |
|
206 | - // loop thru incoming options |
|
207 | - foreach ($input_args as $key => $value) { |
|
208 | - // add underscore to $key to match property names |
|
209 | - $_key = '_' . $key; |
|
210 | - if (property_exists($this, $_key)) { |
|
211 | - $this->{$_key} = $value; |
|
212 | - } |
|
213 | - } |
|
214 | - // ensure that "required" is set correctly |
|
215 | - $this->set_required( |
|
216 | - $this->_required, |
|
217 | - isset($input_args['required_validation_error_message']) |
|
218 | - ? $input_args['required_validation_error_message'] |
|
219 | - : null |
|
220 | - ); |
|
221 | - // $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
222 | - $this->_display_strategy->_construct_finalize($this); |
|
223 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
224 | - $validation_strategy->_construct_finalize($this); |
|
225 | - } |
|
226 | - if (isset($input_args['ignore_input'])) { |
|
227 | - $this->_normalization_strategy = new EE_Null_Normalization(); |
|
228 | - } |
|
229 | - if (! $this->_normalization_strategy) { |
|
230 | - $this->_normalization_strategy = new EE_Text_Normalization(); |
|
231 | - } |
|
232 | - $this->_normalization_strategy->_construct_finalize($this); |
|
233 | - // at least we can use the normalization strategy to populate the default |
|
234 | - if (isset($input_args['default'])) { |
|
235 | - $this->set_default($input_args['default']); |
|
236 | - unset($input_args['default']); |
|
237 | - } |
|
238 | - if (! $this->_sensitive_data_removal_strategy) { |
|
239 | - $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
240 | - } |
|
241 | - $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
242 | - parent::__construct($input_args); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Sets the html_name to its default value, if none was specified in teh constructor. |
|
249 | - * Calculation involves using the name and the parent's html_name |
|
250 | - * |
|
251 | - * @throws \EE_Error |
|
252 | - */ |
|
253 | - protected function _set_default_html_name_if_empty() |
|
254 | - { |
|
255 | - if (! $this->_html_name) { |
|
256 | - $this->_html_name = $this->name(); |
|
257 | - if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
258 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
259 | - } |
|
260 | - } |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @param $parent_form_section |
|
267 | - * @param $name |
|
268 | - * @throws \EE_Error |
|
269 | - */ |
|
270 | - public function _construct_finalize($parent_form_section, $name) |
|
271 | - { |
|
272 | - parent::_construct_finalize($parent_form_section, $name); |
|
273 | - if ($this->_html_label === null && $this->_html_label_text === null) { |
|
274 | - $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
275 | - } |
|
276 | - do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
283 | - * |
|
284 | - * @return EE_Display_Strategy_Base |
|
285 | - * @throws EE_Error |
|
286 | - */ |
|
287 | - protected function _get_display_strategy() |
|
288 | - { |
|
289 | - $this->ensure_construct_finalized_called(); |
|
290 | - if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
291 | - throw new EE_Error( |
|
292 | - sprintf( |
|
293 | - __( |
|
294 | - "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
295 | - "event_espresso" |
|
296 | - ), |
|
297 | - $this->html_name(), |
|
298 | - $this->html_id() |
|
299 | - ) |
|
300 | - ); |
|
301 | - } else { |
|
302 | - return $this->_display_strategy; |
|
303 | - } |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * Sets the display strategy. |
|
310 | - * |
|
311 | - * @param EE_Display_Strategy_Base $strategy |
|
312 | - */ |
|
313 | - protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
314 | - { |
|
315 | - $this->_display_strategy = $strategy; |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * Sets the sanitization strategy |
|
322 | - * |
|
323 | - * @param EE_Normalization_Strategy_Base $strategy |
|
324 | - */ |
|
325 | - protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
326 | - { |
|
327 | - $this->_normalization_strategy = $strategy; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * Gets sensitive_data_removal_strategy |
|
334 | - * |
|
335 | - * @return EE_Sensitive_Data_Removal_Base |
|
336 | - */ |
|
337 | - public function get_sensitive_data_removal_strategy() |
|
338 | - { |
|
339 | - return $this->_sensitive_data_removal_strategy; |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * Sets sensitive_data_removal_strategy |
|
346 | - * |
|
347 | - * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
348 | - * @return boolean |
|
349 | - */ |
|
350 | - public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
351 | - { |
|
352 | - $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * Gets the display strategy for this input |
|
359 | - * |
|
360 | - * @return EE_Display_Strategy_Base |
|
361 | - */ |
|
362 | - public function get_display_strategy() |
|
363 | - { |
|
364 | - return $this->_display_strategy; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * Overwrites the display strategy |
|
371 | - * |
|
372 | - * @param EE_Display_Strategy_Base $display_strategy |
|
373 | - */ |
|
374 | - public function set_display_strategy($display_strategy) |
|
375 | - { |
|
376 | - $this->_display_strategy = $display_strategy; |
|
377 | - $this->_display_strategy->_construct_finalize($this); |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * Gets the normalization strategy set on this input |
|
384 | - * |
|
385 | - * @return EE_Normalization_Strategy_Base |
|
386 | - */ |
|
387 | - public function get_normalization_strategy() |
|
388 | - { |
|
389 | - return $this->_normalization_strategy; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * Overwrites the normalization strategy |
|
396 | - * |
|
397 | - * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
398 | - */ |
|
399 | - public function set_normalization_strategy($normalization_strategy) |
|
400 | - { |
|
401 | - $this->_normalization_strategy = $normalization_strategy; |
|
402 | - $this->_normalization_strategy->_construct_finalize($this); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * Returns all teh validation strategies which apply to this field, numerically indexed |
|
409 | - * |
|
410 | - * @return EE_Validation_Strategy_Base[] |
|
411 | - */ |
|
412 | - public function get_validation_strategies() |
|
413 | - { |
|
414 | - return $this->_validation_strategies; |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
421 | - * |
|
422 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
423 | - * @return void |
|
424 | - */ |
|
425 | - protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
426 | - { |
|
427 | - $validation_strategy->_construct_finalize($this); |
|
428 | - $this->_validation_strategies[] = $validation_strategy; |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * Adds a new validation strategy onto the form input |
|
435 | - * |
|
436 | - * @param EE_Validation_Strategy_Base $validation_strategy |
|
437 | - * @return void |
|
438 | - */ |
|
439 | - public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
440 | - { |
|
441 | - $this->_add_validation_strategy($validation_strategy); |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * The classname of the validation strategy to remove |
|
448 | - * |
|
449 | - * @param string $validation_strategy_classname |
|
450 | - */ |
|
451 | - public function remove_validation_strategy($validation_strategy_classname) |
|
452 | - { |
|
453 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
454 | - if ($validation_strategy instanceof $validation_strategy_classname |
|
455 | - || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
456 | - ) { |
|
457 | - unset($this->_validation_strategies[ $key ]); |
|
458 | - } |
|
459 | - } |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
466 | - * |
|
467 | - * @param array $validation_strategy_classnames |
|
468 | - * @return bool |
|
469 | - */ |
|
470 | - public function has_validation_strategy($validation_strategy_classnames) |
|
471 | - { |
|
472 | - $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
473 | - ? $validation_strategy_classnames |
|
474 | - : array($validation_strategy_classnames); |
|
475 | - foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
476 | - if (in_array($key, $validation_strategy_classnames)) { |
|
477 | - return true; |
|
478 | - } |
|
479 | - } |
|
480 | - return false; |
|
481 | - } |
|
482 | - |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * Gets the HTML |
|
487 | - * |
|
488 | - * @return string |
|
489 | - */ |
|
490 | - public function get_html() |
|
491 | - { |
|
492 | - return $this->_parent_section->get_html_for_input($this); |
|
493 | - } |
|
494 | - |
|
495 | - |
|
496 | - |
|
497 | - /** |
|
498 | - * Gets the HTML for the input itself (no label or errors) according to the |
|
499 | - * input's display strategy |
|
500 | - * Makes sure the JS and CSS are enqueued for it |
|
501 | - * |
|
502 | - * @return string |
|
503 | - * @throws \EE_Error |
|
504 | - */ |
|
505 | - public function get_html_for_input() |
|
506 | - { |
|
507 | - return $this->_form_html_filter |
|
508 | - ? $this->_form_html_filter->filterHtml( |
|
509 | - $this->_get_display_strategy()->display(), |
|
510 | - $this |
|
511 | - ) |
|
512 | - : $this->_get_display_strategy()->display(); |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * @return string |
|
519 | - */ |
|
520 | - public function html_other_attributes() |
|
521 | - { |
|
522 | - EE_Error::doing_it_wrong( |
|
523 | - __METHOD__, |
|
524 | - sprintf( |
|
525 | - esc_html__( |
|
526 | - 'This method is no longer in use. You should replace it by %s', |
|
527 | - 'event_espresso' |
|
528 | - ), |
|
529 | - 'EE_Form_Section_Base::other_html_attributes()' |
|
530 | - ), |
|
531 | - '4.10.2.p' |
|
532 | - ); |
|
533 | - |
|
534 | - return $this->other_html_attributes(); |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * @param string $html_other_attributes |
|
541 | - */ |
|
542 | - public function set_html_other_attributes($html_other_attributes) |
|
543 | - { |
|
544 | - EE_Error::doing_it_wrong( |
|
545 | - __METHOD__, |
|
546 | - sprintf( |
|
547 | - esc_html__( |
|
548 | - 'This method is no longer in use. You should replace it by %s', |
|
549 | - 'event_espresso' |
|
550 | - ), |
|
551 | - 'EE_Form_Section_Base::set_other_html_attributes()' |
|
552 | - ), |
|
553 | - '4.10.2.p' |
|
554 | - ); |
|
555 | - |
|
556 | - $this->set_other_html_attributes($html_other_attributes); |
|
557 | - } |
|
558 | - |
|
559 | - |
|
560 | - |
|
561 | - /** |
|
562 | - * Gets the HTML for displaying the label for this form input |
|
563 | - * according to the form section's layout strategy |
|
564 | - * |
|
565 | - * @return string |
|
566 | - */ |
|
567 | - public function get_html_for_label() |
|
568 | - { |
|
569 | - return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - |
|
574 | - /** |
|
575 | - * Gets the HTML for displaying the errors section for this form input |
|
576 | - * according to the form section's layout strategy |
|
577 | - * |
|
578 | - * @return string |
|
579 | - */ |
|
580 | - public function get_html_for_errors() |
|
581 | - { |
|
582 | - return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * Gets the HTML for displaying the help text for this form input |
|
589 | - * according to the form section's layout strategy |
|
590 | - * |
|
591 | - * @return string |
|
592 | - */ |
|
593 | - public function get_html_for_help() |
|
594 | - { |
|
595 | - return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
602 | - * and returns whether or not the form input's submitted value is value |
|
603 | - * |
|
604 | - * @return boolean |
|
605 | - */ |
|
606 | - protected function _validate() |
|
607 | - { |
|
608 | - if ($this->isDisabled()) { |
|
609 | - return true; |
|
610 | - } |
|
611 | - foreach ($this->_validation_strategies as $validation_strategy) { |
|
612 | - if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
613 | - try { |
|
614 | - $validation_strategy->validate($this->normalized_value()); |
|
615 | - } catch (EE_Validation_Error $e) { |
|
616 | - $this->add_validation_error($e); |
|
617 | - } |
|
618 | - } |
|
619 | - } |
|
620 | - if ($this->get_validation_errors()) { |
|
621 | - return false; |
|
622 | - } else { |
|
623 | - return true; |
|
624 | - } |
|
625 | - } |
|
626 | - |
|
627 | - |
|
628 | - |
|
629 | - /** |
|
630 | - * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
631 | - * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
632 | - * |
|
633 | - * @param string $value |
|
634 | - * @return null|string |
|
635 | - */ |
|
636 | - protected function _sanitize($value) |
|
637 | - { |
|
638 | - return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
639 | - } |
|
640 | - |
|
641 | - |
|
642 | - |
|
643 | - /** |
|
644 | - * Picks out the form value that relates to this form input, |
|
645 | - * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
646 | - * Returns whether or not any validation errors occurred |
|
647 | - * |
|
648 | - * @param array $req_data like $_POST |
|
649 | - * @return boolean whether or not there was an error |
|
650 | - * @throws \EE_Error |
|
651 | - */ |
|
652 | - protected function _normalize($req_data) |
|
653 | - { |
|
654 | - // any existing validation errors don't apply so clear them |
|
655 | - $this->_validation_errors = array(); |
|
656 | - // if the input is disabled, ignore whatever input was sent in |
|
657 | - if ($this->isDisabled()) { |
|
658 | - $this->_set_raw_value(null); |
|
659 | - $this->_set_normalized_value($this->get_default()); |
|
660 | - return false; |
|
661 | - } |
|
662 | - try { |
|
663 | - $raw_input = $this->find_form_data_for_this_section($req_data); |
|
664 | - // super simple sanitization for now |
|
665 | - if (is_array($raw_input)) { |
|
666 | - $raw_value = array(); |
|
667 | - foreach ($raw_input as $key => $value) { |
|
668 | - $raw_value[ $key ] = $this->_sanitize($value); |
|
669 | - } |
|
670 | - $this->_set_raw_value($raw_value); |
|
671 | - } else { |
|
672 | - $this->_set_raw_value($this->_sanitize($raw_input)); |
|
673 | - } |
|
674 | - // we want to mostly leave the input alone in case we need to re-display it to the user |
|
675 | - $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
676 | - return false; |
|
677 | - } catch (EE_Validation_Error $e) { |
|
678 | - $this->add_validation_error($e); |
|
679 | - return true; |
|
680 | - } |
|
681 | - } |
|
682 | - |
|
683 | - |
|
684 | - |
|
685 | - /** |
|
686 | - * @return string |
|
687 | - */ |
|
688 | - public function html_name() |
|
689 | - { |
|
690 | - $this->_set_default_html_name_if_empty(); |
|
691 | - return $this->_html_name; |
|
692 | - } |
|
693 | - |
|
694 | - |
|
695 | - |
|
696 | - /** |
|
697 | - * @return string |
|
698 | - */ |
|
699 | - public function html_label_id() |
|
700 | - { |
|
701 | - return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
702 | - } |
|
703 | - |
|
704 | - |
|
705 | - |
|
706 | - /** |
|
707 | - * @return string |
|
708 | - */ |
|
709 | - public function html_label_class() |
|
710 | - { |
|
711 | - return $this->_html_label_class; |
|
712 | - } |
|
713 | - |
|
714 | - |
|
715 | - |
|
716 | - /** |
|
717 | - * @return string |
|
718 | - */ |
|
719 | - public function html_label_style() |
|
720 | - { |
|
721 | - return $this->_html_label_style; |
|
722 | - } |
|
723 | - |
|
724 | - |
|
725 | - |
|
726 | - /** |
|
727 | - * @return string |
|
728 | - */ |
|
729 | - public function html_label_text() |
|
730 | - { |
|
731 | - return $this->_html_label_text; |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * @return string |
|
738 | - */ |
|
739 | - public function html_help_text() |
|
740 | - { |
|
741 | - return $this->_html_help_text; |
|
742 | - } |
|
743 | - |
|
744 | - |
|
745 | - |
|
746 | - /** |
|
747 | - * @return string |
|
748 | - */ |
|
749 | - public function html_help_class() |
|
750 | - { |
|
751 | - return $this->_html_help_class; |
|
752 | - } |
|
753 | - |
|
754 | - |
|
755 | - |
|
756 | - /** |
|
757 | - * @return string |
|
758 | - */ |
|
759 | - public function html_help_style() |
|
760 | - { |
|
761 | - return $this->_html_style; |
|
762 | - } |
|
763 | - |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
768 | - * Please note that almost all client code should instead use the normalized_value; |
|
769 | - * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
770 | - * mostly by escaping quotes) |
|
771 | - * Note, we do not store the exact original value sent in the user's request because |
|
772 | - * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
773 | - * in which case, we would have stored the malicious content to our database. |
|
774 | - * |
|
775 | - * @return string |
|
776 | - */ |
|
777 | - public function raw_value() |
|
778 | - { |
|
779 | - return $this->_raw_value; |
|
780 | - } |
|
781 | - |
|
782 | - |
|
783 | - |
|
784 | - /** |
|
785 | - * Returns a string safe to usage in form inputs when displaying, because |
|
786 | - * it escapes all html entities |
|
787 | - * |
|
788 | - * @return string |
|
789 | - */ |
|
790 | - public function raw_value_in_form() |
|
791 | - { |
|
792 | - return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - |
|
797 | - /** |
|
798 | - * returns the value after it's been sanitized, and then converted into it's proper type |
|
799 | - * in PHP. Eg, a string, an int, an array, |
|
800 | - * |
|
801 | - * @return mixed |
|
802 | - */ |
|
803 | - public function normalized_value() |
|
804 | - { |
|
805 | - return $this->_normalized_value; |
|
806 | - } |
|
807 | - |
|
808 | - |
|
809 | - |
|
810 | - /** |
|
811 | - * Returns the normalized value is a presentable way. By default this is just |
|
812 | - * the normalized value by itself, but it can be overridden for when that's not |
|
813 | - * the best thing to display |
|
814 | - * |
|
815 | - * @return string |
|
816 | - */ |
|
817 | - public function pretty_value() |
|
818 | - { |
|
819 | - return $this->_normalized_value; |
|
820 | - } |
|
821 | - |
|
822 | - |
|
823 | - |
|
824 | - /** |
|
825 | - * When generating the JS for the jquery validation rules like<br> |
|
826 | - * <code>$( "#myform" ).validate({ |
|
827 | - * rules: { |
|
828 | - * password: "required", |
|
829 | - * password_again: { |
|
830 | - * equalTo: "#password" |
|
831 | - * } |
|
832 | - * } |
|
833 | - * });</code> |
|
834 | - * if this field had the name 'password_again', it should return |
|
835 | - * <br><code>password_again: { |
|
836 | - * equalTo: "#password" |
|
837 | - * }</code> |
|
838 | - * |
|
839 | - * @return array |
|
840 | - */ |
|
841 | - public function get_jquery_validation_rules() |
|
842 | - { |
|
843 | - $jquery_validation_js = array(); |
|
844 | - $jquery_validation_rules = array(); |
|
845 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
846 | - $jquery_validation_rules = array_replace_recursive( |
|
847 | - $jquery_validation_rules, |
|
848 | - $validation_strategy->get_jquery_validation_rule_array() |
|
849 | - ); |
|
850 | - } |
|
851 | - if (! empty($jquery_validation_rules)) { |
|
852 | - foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
853 | - $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules; |
|
854 | - } |
|
855 | - } |
|
856 | - return $jquery_validation_js; |
|
857 | - } |
|
858 | - |
|
859 | - |
|
860 | - |
|
861 | - /** |
|
862 | - * Sets the input's default value for use in displaying in the form. Note: value should be |
|
863 | - * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
864 | - * |
|
865 | - * @param mixed $value |
|
866 | - * @return void |
|
867 | - */ |
|
868 | - public function set_default($value) |
|
869 | - { |
|
870 | - $this->_default = $value; |
|
871 | - $this->_set_normalized_value($value); |
|
872 | - $this->_set_raw_value($value); |
|
873 | - } |
|
874 | - |
|
875 | - |
|
876 | - |
|
877 | - /** |
|
878 | - * Sets the normalized value on this input |
|
879 | - * |
|
880 | - * @param mixed $value |
|
881 | - */ |
|
882 | - protected function _set_normalized_value($value) |
|
883 | - { |
|
884 | - $this->_normalized_value = $value; |
|
885 | - } |
|
886 | - |
|
887 | - |
|
888 | - |
|
889 | - /** |
|
890 | - * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
891 | - * |
|
892 | - * @param mixed $value |
|
893 | - */ |
|
894 | - protected function _set_raw_value($value) |
|
895 | - { |
|
896 | - $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
897 | - } |
|
898 | - |
|
899 | - |
|
900 | - |
|
901 | - /** |
|
902 | - * Sets the HTML label text after it has already been defined |
|
903 | - * |
|
904 | - * @param string $label |
|
905 | - * @return void |
|
906 | - */ |
|
907 | - public function set_html_label_text($label) |
|
908 | - { |
|
909 | - $this->_html_label_text = $label; |
|
910 | - } |
|
911 | - |
|
912 | - |
|
913 | - |
|
914 | - /** |
|
915 | - * Sets whether or not this field is required, and adjusts the validation strategy. |
|
916 | - * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
917 | - * please add it as a validation strategy using add_validation_strategy as normal |
|
918 | - * |
|
919 | - * @param boolean $required boolean |
|
920 | - * @param null $required_text |
|
921 | - */ |
|
922 | - public function set_required($required = true, $required_text = null) |
|
923 | - { |
|
924 | - $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
925 | - // whether $required is a string or a boolean, we want to add a required validation strategy |
|
926 | - if ($required) { |
|
927 | - $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
928 | - } else { |
|
929 | - $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
930 | - } |
|
931 | - $this->_required = $required; |
|
932 | - } |
|
933 | - |
|
934 | - |
|
935 | - |
|
936 | - /** |
|
937 | - * Returns whether or not this field is required |
|
938 | - * |
|
939 | - * @return boolean |
|
940 | - */ |
|
941 | - public function required() |
|
942 | - { |
|
943 | - return $this->_required; |
|
944 | - } |
|
945 | - |
|
946 | - |
|
947 | - |
|
948 | - /** |
|
949 | - * @param string $required_css_class |
|
950 | - */ |
|
951 | - public function set_required_css_class($required_css_class) |
|
952 | - { |
|
953 | - $this->_required_css_class = $required_css_class; |
|
954 | - } |
|
955 | - |
|
956 | - |
|
957 | - |
|
958 | - /** |
|
959 | - * @return string |
|
960 | - */ |
|
961 | - public function required_css_class() |
|
962 | - { |
|
963 | - return $this->_required_css_class; |
|
964 | - } |
|
965 | - |
|
966 | - |
|
967 | - |
|
968 | - /** |
|
969 | - * @param bool $add_required |
|
970 | - * @return string |
|
971 | - */ |
|
972 | - public function html_class($add_required = false) |
|
973 | - { |
|
974 | - return $add_required && $this->required() |
|
975 | - ? $this->required_css_class() . ' ' . $this->_html_class |
|
976 | - : $this->_html_class; |
|
977 | - } |
|
978 | - |
|
979 | - |
|
980 | - /** |
|
981 | - * Sets the help text, in case |
|
982 | - * |
|
983 | - * @param string $text |
|
984 | - */ |
|
985 | - public function set_html_help_text($text) |
|
986 | - { |
|
987 | - $this->_html_help_text = $text; |
|
988 | - } |
|
989 | - |
|
990 | - |
|
991 | - |
|
992 | - /** |
|
993 | - * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
994 | - * input. If there is any kind of sensitive data removal on this input, we clear |
|
995 | - * out the raw value completely |
|
996 | - * |
|
997 | - * @return void |
|
998 | - */ |
|
999 | - public function clean_sensitive_data() |
|
1000 | - { |
|
1001 | - // if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
1002 | - // if we need more logic than this we'll make a strategy for it |
|
1003 | - if ($this->_sensitive_data_removal_strategy |
|
1004 | - && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
1005 | - ) { |
|
1006 | - $this->_set_raw_value(null); |
|
1007 | - } |
|
1008 | - // and clean the normalized value according to the appropriate strategy |
|
1009 | - $this->_set_normalized_value( |
|
1010 | - $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
1011 | - $this->_normalized_value |
|
1012 | - ) |
|
1013 | - ); |
|
1014 | - } |
|
1015 | - |
|
1016 | - |
|
1017 | - |
|
1018 | - /** |
|
1019 | - * @param bool $primary |
|
1020 | - * @param string $button_size |
|
1021 | - * @param string $other_attributes |
|
1022 | - */ |
|
1023 | - public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
1024 | - { |
|
1025 | - $button_css_attributes = 'button'; |
|
1026 | - $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary'; |
|
1027 | - switch ($button_size) { |
|
1028 | - case 'xs': |
|
1029 | - case 'extra-small': |
|
1030 | - $button_css_attributes .= ' button-xs'; |
|
1031 | - break; |
|
1032 | - case 'sm': |
|
1033 | - case 'small': |
|
1034 | - $button_css_attributes .= ' button-sm'; |
|
1035 | - break; |
|
1036 | - case 'lg': |
|
1037 | - case 'large': |
|
1038 | - $button_css_attributes .= ' button-lg'; |
|
1039 | - break; |
|
1040 | - case 'block': |
|
1041 | - $button_css_attributes .= ' button-block'; |
|
1042 | - break; |
|
1043 | - case 'md': |
|
1044 | - case 'medium': |
|
1045 | - default: |
|
1046 | - $button_css_attributes .= ''; |
|
1047 | - } |
|
1048 | - $this->_button_css_attributes .= ! empty($other_attributes) |
|
1049 | - ? $button_css_attributes . ' ' . $other_attributes |
|
1050 | - : $button_css_attributes; |
|
1051 | - } |
|
1052 | - |
|
1053 | - |
|
1054 | - |
|
1055 | - /** |
|
1056 | - * @return string |
|
1057 | - */ |
|
1058 | - public function button_css_attributes() |
|
1059 | - { |
|
1060 | - if (empty($this->_button_css_attributes)) { |
|
1061 | - $this->set_button_css_attributes(); |
|
1062 | - } |
|
1063 | - return $this->_button_css_attributes; |
|
1064 | - } |
|
1065 | - |
|
1066 | - |
|
1067 | - |
|
1068 | - /** |
|
1069 | - * find_form_data_for_this_section |
|
1070 | - * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
1071 | - * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
1072 | - * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1']. |
|
1073 | - * (If that doesn't exist, we also check for this subsection's name |
|
1074 | - * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].) |
|
1075 | - * This function finds its value in the form. |
|
1076 | - * |
|
1077 | - * @param array $req_data |
|
1078 | - * @return mixed whatever the raw value of this form section is in the request data |
|
1079 | - * @throws \EE_Error |
|
1080 | - */ |
|
1081 | - public function find_form_data_for_this_section($req_data) |
|
1082 | - { |
|
1083 | - $name_parts = $this->getInputNameParts(); |
|
1084 | - // now get the value for the input |
|
1085 | - $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data); |
|
1086 | - // check if this thing's name is at the TOP level of the request data |
|
1087 | - if ($value === null && isset($req_data[ $this->name() ])) { |
|
1088 | - $value = $req_data[ $this->name() ]; |
|
1089 | - } |
|
1090 | - return $value; |
|
1091 | - } |
|
1092 | - |
|
1093 | - |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * If this input's name is something like "foo[bar][baz]" |
|
1097 | - * returns an array like `array('foo','bar',baz')` |
|
1098 | - * @return array |
|
1099 | - */ |
|
1100 | - protected function getInputNameParts() |
|
1101 | - { |
|
1102 | - // break up the html name by "[]" |
|
1103 | - if (strpos($this->html_name(), '[') !== false) { |
|
1104 | - $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
1105 | - } else { |
|
1106 | - $before_any_brackets = $this->html_name(); |
|
1107 | - } |
|
1108 | - // grab all of the segments |
|
1109 | - preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
1110 | - if (isset($matches[1]) && is_array($matches[1])) { |
|
1111 | - $name_parts = $matches[1]; |
|
1112 | - array_unshift($name_parts, $before_any_brackets); |
|
1113 | - } else { |
|
1114 | - $name_parts = array($before_any_brackets); |
|
1115 | - } |
|
1116 | - return $name_parts; |
|
1117 | - } |
|
1118 | - |
|
1119 | - |
|
1120 | - |
|
1121 | - /** |
|
1122 | - * @param array $html_name_parts |
|
1123 | - * @param array $req_data |
|
1124 | - * @return array | NULL |
|
1125 | - */ |
|
1126 | - public function findRequestForSectionUsingNameParts($html_name_parts, $req_data) |
|
1127 | - { |
|
1128 | - $first_part_to_consider = array_shift($html_name_parts); |
|
1129 | - if (isset($req_data[ $first_part_to_consider ])) { |
|
1130 | - if (empty($html_name_parts)) { |
|
1131 | - return $req_data[ $first_part_to_consider ]; |
|
1132 | - } else { |
|
1133 | - return $this->findRequestForSectionUsingNameParts( |
|
1134 | - $html_name_parts, |
|
1135 | - $req_data[ $first_part_to_consider ] |
|
1136 | - ); |
|
1137 | - } |
|
1138 | - } else { |
|
1139 | - return null; |
|
1140 | - } |
|
1141 | - } |
|
1142 | - |
|
1143 | - |
|
1144 | - |
|
1145 | - /** |
|
1146 | - * Checks if this form input's data is in the request data |
|
1147 | - * |
|
1148 | - * @param array $req_data like $_POST |
|
1149 | - * @return boolean |
|
1150 | - * @throws \EE_Error |
|
1151 | - */ |
|
1152 | - public function form_data_present_in($req_data = null) |
|
1153 | - { |
|
1154 | - if ($req_data === null) { |
|
1155 | - $req_data = $_POST; |
|
1156 | - } |
|
1157 | - $checked_value = $this->find_form_data_for_this_section($req_data); |
|
1158 | - if ($checked_value !== null) { |
|
1159 | - return true; |
|
1160 | - } else { |
|
1161 | - return false; |
|
1162 | - } |
|
1163 | - } |
|
1164 | - |
|
1165 | - |
|
1166 | - |
|
1167 | - /** |
|
1168 | - * Overrides parent to add js data from validation and display strategies |
|
1169 | - * |
|
1170 | - * @param array $form_other_js_data |
|
1171 | - * @return array |
|
1172 | - */ |
|
1173 | - public function get_other_js_data($form_other_js_data = array()) |
|
1174 | - { |
|
1175 | - $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
1176 | - return $form_other_js_data; |
|
1177 | - } |
|
1178 | - |
|
1179 | - |
|
1180 | - |
|
1181 | - /** |
|
1182 | - * Gets other JS data for localization from this input's strategies, like |
|
1183 | - * the validation strategies and the display strategy |
|
1184 | - * |
|
1185 | - * @param array $form_other_js_data |
|
1186 | - * @return array |
|
1187 | - */ |
|
1188 | - public function get_other_js_data_from_strategies($form_other_js_data = array()) |
|
1189 | - { |
|
1190 | - $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
1191 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1192 | - $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
1193 | - } |
|
1194 | - return $form_other_js_data; |
|
1195 | - } |
|
1196 | - |
|
1197 | - |
|
1198 | - |
|
1199 | - /** |
|
1200 | - * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
1201 | - * |
|
1202 | - * @return void |
|
1203 | - */ |
|
1204 | - public function enqueue_js() |
|
1205 | - { |
|
1206 | - // ask our display strategy and validation strategies if they have js to enqueue |
|
1207 | - $this->enqueue_js_from_strategies(); |
|
1208 | - } |
|
1209 | - |
|
1210 | - |
|
1211 | - |
|
1212 | - /** |
|
1213 | - * Tells strategies when its ok to enqueue their js and css |
|
1214 | - * |
|
1215 | - * @return void |
|
1216 | - */ |
|
1217 | - public function enqueue_js_from_strategies() |
|
1218 | - { |
|
1219 | - $this->get_display_strategy()->enqueue_js(); |
|
1220 | - foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1221 | - $validation_strategy->enqueue_js(); |
|
1222 | - } |
|
1223 | - } |
|
1224 | - |
|
1225 | - |
|
1226 | - |
|
1227 | - /** |
|
1228 | - * Gets the default value set on the input (not the current value, which may have been |
|
1229 | - * changed because of a form submission). If no default was set, this us null. |
|
1230 | - * @return mixed |
|
1231 | - */ |
|
1232 | - public function get_default() |
|
1233 | - { |
|
1234 | - return $this->_default; |
|
1235 | - } |
|
1236 | - |
|
1237 | - |
|
1238 | - |
|
1239 | - /** |
|
1240 | - * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"', |
|
1241 | - * and server-side if any input was received it will be ignored |
|
1242 | - */ |
|
1243 | - public function disable($disable = true) |
|
1244 | - { |
|
1245 | - $disabled_attribute = ' disabled="disabled"'; |
|
1246 | - $this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN); |
|
1247 | - if ($this->disabled) { |
|
1248 | - if (strpos($this->_other_html_attributes, $disabled_attribute) === false) { |
|
1249 | - $this->_other_html_attributes .= $disabled_attribute; |
|
1250 | - } |
|
1251 | - $this->_set_normalized_value($this->get_default()); |
|
1252 | - } else { |
|
1253 | - $this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes); |
|
1254 | - } |
|
1255 | - } |
|
1256 | - |
|
1257 | - |
|
1258 | - |
|
1259 | - /** |
|
1260 | - * Returns whether or not this input is currently disabled. |
|
1261 | - * @return bool |
|
1262 | - */ |
|
1263 | - public function isDisabled() |
|
1264 | - { |
|
1265 | - return $this->disabled; |
|
1266 | - } |
|
14 | + /** |
|
15 | + * the input's name attribute |
|
16 | + * |
|
17 | + * @var string |
|
18 | + */ |
|
19 | + protected $_html_name; |
|
20 | + |
|
21 | + /** |
|
22 | + * id for the html label tag |
|
23 | + * |
|
24 | + * @var string |
|
25 | + */ |
|
26 | + protected $_html_label_id; |
|
27 | + |
|
28 | + /** |
|
29 | + * class for teh html label tag |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected $_html_label_class; |
|
34 | + |
|
35 | + /** |
|
36 | + * style for teh html label tag |
|
37 | + * |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected $_html_label_style; |
|
41 | + |
|
42 | + /** |
|
43 | + * text to be placed in the html label |
|
44 | + * |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + protected $_html_label_text; |
|
48 | + |
|
49 | + /** |
|
50 | + * the full html label. If used, all other html_label_* properties are invalid |
|
51 | + * |
|
52 | + * @var string |
|
53 | + */ |
|
54 | + protected $_html_label; |
|
55 | + |
|
56 | + /** |
|
57 | + * HTML to use for help text (normally placed below form input), in a span which normally |
|
58 | + * has a class of 'description' |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + protected $_html_help_text; |
|
63 | + |
|
64 | + /** |
|
65 | + * CSS classes for displaying the help span |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | + protected $_html_help_class = 'description'; |
|
70 | + |
|
71 | + /** |
|
72 | + * CSS to put in the style attribute on the help span |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + protected $_html_help_style; |
|
77 | + |
|
78 | + /** |
|
79 | + * Stores whether or not this input's response is required. |
|
80 | + * Because certain styling elements may also want to know that this |
|
81 | + * input is required etc. |
|
82 | + * |
|
83 | + * @var boolean |
|
84 | + */ |
|
85 | + protected $_required; |
|
86 | + |
|
87 | + /** |
|
88 | + * css class added to required inputs |
|
89 | + * |
|
90 | + * @var string |
|
91 | + */ |
|
92 | + protected $_required_css_class = 'ee-required'; |
|
93 | + |
|
94 | + /** |
|
95 | + * css styles applied to button type inputs |
|
96 | + * |
|
97 | + * @var string |
|
98 | + */ |
|
99 | + protected $_button_css_attributes; |
|
100 | + |
|
101 | + /** |
|
102 | + * The raw data submitted for this, like in the $_POST super global. |
|
103 | + * Generally unsafe for usage in client code |
|
104 | + * |
|
105 | + * @var mixed string or array |
|
106 | + */ |
|
107 | + protected $_raw_value; |
|
108 | + |
|
109 | + /** |
|
110 | + * Value normalized according to the input's normalization strategy. |
|
111 | + * The normalization strategy dictates whether this is a string, int, float, |
|
112 | + * boolean, or array of any of those. |
|
113 | + * |
|
114 | + * @var mixed |
|
115 | + */ |
|
116 | + protected $_normalized_value; |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Normalized default value either initially set on the input, or provided by calling |
|
121 | + * set_default(). |
|
122 | + * @var mixed |
|
123 | + */ |
|
124 | + protected $_default; |
|
125 | + |
|
126 | + /** |
|
127 | + * Strategy used for displaying this field. |
|
128 | + * Child classes must use _get_display_strategy to access it. |
|
129 | + * |
|
130 | + * @var EE_Display_Strategy_Base |
|
131 | + */ |
|
132 | + private $_display_strategy; |
|
133 | + |
|
134 | + /** |
|
135 | + * Gets all the validation strategies used on this field |
|
136 | + * |
|
137 | + * @var EE_Validation_Strategy_Base[] |
|
138 | + */ |
|
139 | + private $_validation_strategies = array(); |
|
140 | + |
|
141 | + /** |
|
142 | + * The normalization strategy for this field |
|
143 | + * |
|
144 | + * @var EE_Normalization_Strategy_Base |
|
145 | + */ |
|
146 | + private $_normalization_strategy; |
|
147 | + |
|
148 | + /** |
|
149 | + * Strategy for removing sensitive data after we're done with the form input |
|
150 | + * |
|
151 | + * @var EE_Sensitive_Data_Removal_Base |
|
152 | + */ |
|
153 | + protected $_sensitive_data_removal_strategy; |
|
154 | + |
|
155 | + /** |
|
156 | + * Whether this input has been disabled or not. |
|
157 | + * If it's disabled while rendering, an extra hidden input is added that indicates it has been knowingly disabled. |
|
158 | + * (Client-side code that wants to dynamically disable it must also add this hidden input). |
|
159 | + * When the form is submitted, if the input is disabled in the PHP formsection, then input is ignored. |
|
160 | + * If the input is missing from the $_REQUEST data but the hidden input indicating the input is disabled, then the input is again ignored. |
|
161 | + * |
|
162 | + * @var boolean |
|
163 | + */ |
|
164 | + protected $disabled = false; |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @param array $input_args { |
|
170 | + * @type string $html_name the html name for the input |
|
171 | + * @type string $html_label_id the id attribute to give to the html label tag |
|
172 | + * @type string $html_label_class the class attribute to give to the html label tag |
|
173 | + * @type string $html_label_style the style attribute to give ot teh label tag |
|
174 | + * @type string $html_label_text the text to put in the label tag |
|
175 | + * @type string $html_label the full html label. If used, |
|
176 | + * all other html_label_* args are invalid |
|
177 | + * @type string $html_help_text text to put in help element |
|
178 | + * @type string $html_help_style style attribute to give to teh help element |
|
179 | + * @type string $html_help_class class attribute to give to the help element |
|
180 | + * @type string $default default value NORMALIZED (eg, if providing the default |
|
181 | + * for a Yes_No_Input, you should provide TRUE or FALSE, not '1' or '0') |
|
182 | + * @type EE_Display_Strategy_Base $display strategy |
|
183 | + * @type EE_Normalization_Strategy_Base $normalization_strategy |
|
184 | + * @type EE_Validation_Strategy_Base[] $validation_strategies |
|
185 | + * @type boolean $ignore_input special argument which can be used to avoid adding any validation strategies, |
|
186 | + * and sets the normalization strategy to the Null normalization. This is good |
|
187 | + * when you want the input to be totally ignored server-side (like when using |
|
188 | + * React.js form inputs) |
|
189 | + * } |
|
190 | + */ |
|
191 | + public function __construct($input_args = array()) |
|
192 | + { |
|
193 | + $input_args = (array) apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
194 | + // the following properties must be cast as arrays |
|
195 | + if (isset($input_args['validation_strategies'])) { |
|
196 | + foreach ((array) $input_args['validation_strategies'] as $validation_strategy) { |
|
197 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base && empty($input_args['ignore_input'])) { |
|
198 | + $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy; |
|
199 | + } |
|
200 | + } |
|
201 | + unset($input_args['validation_strategies']); |
|
202 | + } |
|
203 | + if (isset($input_args['ignore_input'])) { |
|
204 | + $this->_validation_strategies = array(); |
|
205 | + } |
|
206 | + // loop thru incoming options |
|
207 | + foreach ($input_args as $key => $value) { |
|
208 | + // add underscore to $key to match property names |
|
209 | + $_key = '_' . $key; |
|
210 | + if (property_exists($this, $_key)) { |
|
211 | + $this->{$_key} = $value; |
|
212 | + } |
|
213 | + } |
|
214 | + // ensure that "required" is set correctly |
|
215 | + $this->set_required( |
|
216 | + $this->_required, |
|
217 | + isset($input_args['required_validation_error_message']) |
|
218 | + ? $input_args['required_validation_error_message'] |
|
219 | + : null |
|
220 | + ); |
|
221 | + // $this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
|
222 | + $this->_display_strategy->_construct_finalize($this); |
|
223 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
224 | + $validation_strategy->_construct_finalize($this); |
|
225 | + } |
|
226 | + if (isset($input_args['ignore_input'])) { |
|
227 | + $this->_normalization_strategy = new EE_Null_Normalization(); |
|
228 | + } |
|
229 | + if (! $this->_normalization_strategy) { |
|
230 | + $this->_normalization_strategy = new EE_Text_Normalization(); |
|
231 | + } |
|
232 | + $this->_normalization_strategy->_construct_finalize($this); |
|
233 | + // at least we can use the normalization strategy to populate the default |
|
234 | + if (isset($input_args['default'])) { |
|
235 | + $this->set_default($input_args['default']); |
|
236 | + unset($input_args['default']); |
|
237 | + } |
|
238 | + if (! $this->_sensitive_data_removal_strategy) { |
|
239 | + $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
|
240 | + } |
|
241 | + $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
|
242 | + parent::__construct($input_args); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Sets the html_name to its default value, if none was specified in teh constructor. |
|
249 | + * Calculation involves using the name and the parent's html_name |
|
250 | + * |
|
251 | + * @throws \EE_Error |
|
252 | + */ |
|
253 | + protected function _set_default_html_name_if_empty() |
|
254 | + { |
|
255 | + if (! $this->_html_name) { |
|
256 | + $this->_html_name = $this->name(); |
|
257 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
258 | + $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
259 | + } |
|
260 | + } |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @param $parent_form_section |
|
267 | + * @param $name |
|
268 | + * @throws \EE_Error |
|
269 | + */ |
|
270 | + public function _construct_finalize($parent_form_section, $name) |
|
271 | + { |
|
272 | + parent::_construct_finalize($parent_form_section, $name); |
|
273 | + if ($this->_html_label === null && $this->_html_label_text === null) { |
|
274 | + $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
275 | + } |
|
276 | + do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Returns the strategy for displaying this form input. If none is set, throws an exception. |
|
283 | + * |
|
284 | + * @return EE_Display_Strategy_Base |
|
285 | + * @throws EE_Error |
|
286 | + */ |
|
287 | + protected function _get_display_strategy() |
|
288 | + { |
|
289 | + $this->ensure_construct_finalized_called(); |
|
290 | + if (! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
291 | + throw new EE_Error( |
|
292 | + sprintf( |
|
293 | + __( |
|
294 | + "Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", |
|
295 | + "event_espresso" |
|
296 | + ), |
|
297 | + $this->html_name(), |
|
298 | + $this->html_id() |
|
299 | + ) |
|
300 | + ); |
|
301 | + } else { |
|
302 | + return $this->_display_strategy; |
|
303 | + } |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * Sets the display strategy. |
|
310 | + * |
|
311 | + * @param EE_Display_Strategy_Base $strategy |
|
312 | + */ |
|
313 | + protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) |
|
314 | + { |
|
315 | + $this->_display_strategy = $strategy; |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * Sets the sanitization strategy |
|
322 | + * |
|
323 | + * @param EE_Normalization_Strategy_Base $strategy |
|
324 | + */ |
|
325 | + protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) |
|
326 | + { |
|
327 | + $this->_normalization_strategy = $strategy; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * Gets sensitive_data_removal_strategy |
|
334 | + * |
|
335 | + * @return EE_Sensitive_Data_Removal_Base |
|
336 | + */ |
|
337 | + public function get_sensitive_data_removal_strategy() |
|
338 | + { |
|
339 | + return $this->_sensitive_data_removal_strategy; |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * Sets sensitive_data_removal_strategy |
|
346 | + * |
|
347 | + * @param EE_Sensitive_Data_Removal_Base $sensitive_data_removal_strategy |
|
348 | + * @return boolean |
|
349 | + */ |
|
350 | + public function set_sensitive_data_removal_strategy($sensitive_data_removal_strategy) |
|
351 | + { |
|
352 | + $this->_sensitive_data_removal_strategy = $sensitive_data_removal_strategy; |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * Gets the display strategy for this input |
|
359 | + * |
|
360 | + * @return EE_Display_Strategy_Base |
|
361 | + */ |
|
362 | + public function get_display_strategy() |
|
363 | + { |
|
364 | + return $this->_display_strategy; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * Overwrites the display strategy |
|
371 | + * |
|
372 | + * @param EE_Display_Strategy_Base $display_strategy |
|
373 | + */ |
|
374 | + public function set_display_strategy($display_strategy) |
|
375 | + { |
|
376 | + $this->_display_strategy = $display_strategy; |
|
377 | + $this->_display_strategy->_construct_finalize($this); |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * Gets the normalization strategy set on this input |
|
384 | + * |
|
385 | + * @return EE_Normalization_Strategy_Base |
|
386 | + */ |
|
387 | + public function get_normalization_strategy() |
|
388 | + { |
|
389 | + return $this->_normalization_strategy; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * Overwrites the normalization strategy |
|
396 | + * |
|
397 | + * @param EE_Normalization_Strategy_Base $normalization_strategy |
|
398 | + */ |
|
399 | + public function set_normalization_strategy($normalization_strategy) |
|
400 | + { |
|
401 | + $this->_normalization_strategy = $normalization_strategy; |
|
402 | + $this->_normalization_strategy->_construct_finalize($this); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * Returns all teh validation strategies which apply to this field, numerically indexed |
|
409 | + * |
|
410 | + * @return EE_Validation_Strategy_Base[] |
|
411 | + */ |
|
412 | + public function get_validation_strategies() |
|
413 | + { |
|
414 | + return $this->_validation_strategies; |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * Adds this strategy to the field so it will be used in both JS validation and server-side validation |
|
421 | + * |
|
422 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
423 | + * @return void |
|
424 | + */ |
|
425 | + protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
426 | + { |
|
427 | + $validation_strategy->_construct_finalize($this); |
|
428 | + $this->_validation_strategies[] = $validation_strategy; |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * Adds a new validation strategy onto the form input |
|
435 | + * |
|
436 | + * @param EE_Validation_Strategy_Base $validation_strategy |
|
437 | + * @return void |
|
438 | + */ |
|
439 | + public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) |
|
440 | + { |
|
441 | + $this->_add_validation_strategy($validation_strategy); |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * The classname of the validation strategy to remove |
|
448 | + * |
|
449 | + * @param string $validation_strategy_classname |
|
450 | + */ |
|
451 | + public function remove_validation_strategy($validation_strategy_classname) |
|
452 | + { |
|
453 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
454 | + if ($validation_strategy instanceof $validation_strategy_classname |
|
455 | + || is_subclass_of($validation_strategy, $validation_strategy_classname) |
|
456 | + ) { |
|
457 | + unset($this->_validation_strategies[ $key ]); |
|
458 | + } |
|
459 | + } |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * returns true if input employs any of the validation strategy defined by the supplied array of classnames |
|
466 | + * |
|
467 | + * @param array $validation_strategy_classnames |
|
468 | + * @return bool |
|
469 | + */ |
|
470 | + public function has_validation_strategy($validation_strategy_classnames) |
|
471 | + { |
|
472 | + $validation_strategy_classnames = is_array($validation_strategy_classnames) |
|
473 | + ? $validation_strategy_classnames |
|
474 | + : array($validation_strategy_classnames); |
|
475 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
476 | + if (in_array($key, $validation_strategy_classnames)) { |
|
477 | + return true; |
|
478 | + } |
|
479 | + } |
|
480 | + return false; |
|
481 | + } |
|
482 | + |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * Gets the HTML |
|
487 | + * |
|
488 | + * @return string |
|
489 | + */ |
|
490 | + public function get_html() |
|
491 | + { |
|
492 | + return $this->_parent_section->get_html_for_input($this); |
|
493 | + } |
|
494 | + |
|
495 | + |
|
496 | + |
|
497 | + /** |
|
498 | + * Gets the HTML for the input itself (no label or errors) according to the |
|
499 | + * input's display strategy |
|
500 | + * Makes sure the JS and CSS are enqueued for it |
|
501 | + * |
|
502 | + * @return string |
|
503 | + * @throws \EE_Error |
|
504 | + */ |
|
505 | + public function get_html_for_input() |
|
506 | + { |
|
507 | + return $this->_form_html_filter |
|
508 | + ? $this->_form_html_filter->filterHtml( |
|
509 | + $this->_get_display_strategy()->display(), |
|
510 | + $this |
|
511 | + ) |
|
512 | + : $this->_get_display_strategy()->display(); |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * @return string |
|
519 | + */ |
|
520 | + public function html_other_attributes() |
|
521 | + { |
|
522 | + EE_Error::doing_it_wrong( |
|
523 | + __METHOD__, |
|
524 | + sprintf( |
|
525 | + esc_html__( |
|
526 | + 'This method is no longer in use. You should replace it by %s', |
|
527 | + 'event_espresso' |
|
528 | + ), |
|
529 | + 'EE_Form_Section_Base::other_html_attributes()' |
|
530 | + ), |
|
531 | + '4.10.2.p' |
|
532 | + ); |
|
533 | + |
|
534 | + return $this->other_html_attributes(); |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * @param string $html_other_attributes |
|
541 | + */ |
|
542 | + public function set_html_other_attributes($html_other_attributes) |
|
543 | + { |
|
544 | + EE_Error::doing_it_wrong( |
|
545 | + __METHOD__, |
|
546 | + sprintf( |
|
547 | + esc_html__( |
|
548 | + 'This method is no longer in use. You should replace it by %s', |
|
549 | + 'event_espresso' |
|
550 | + ), |
|
551 | + 'EE_Form_Section_Base::set_other_html_attributes()' |
|
552 | + ), |
|
553 | + '4.10.2.p' |
|
554 | + ); |
|
555 | + |
|
556 | + $this->set_other_html_attributes($html_other_attributes); |
|
557 | + } |
|
558 | + |
|
559 | + |
|
560 | + |
|
561 | + /** |
|
562 | + * Gets the HTML for displaying the label for this form input |
|
563 | + * according to the form section's layout strategy |
|
564 | + * |
|
565 | + * @return string |
|
566 | + */ |
|
567 | + public function get_html_for_label() |
|
568 | + { |
|
569 | + return $this->_parent_section->get_layout_strategy()->display_label($this); |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + |
|
574 | + /** |
|
575 | + * Gets the HTML for displaying the errors section for this form input |
|
576 | + * according to the form section's layout strategy |
|
577 | + * |
|
578 | + * @return string |
|
579 | + */ |
|
580 | + public function get_html_for_errors() |
|
581 | + { |
|
582 | + return $this->_parent_section->get_layout_strategy()->display_errors($this); |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * Gets the HTML for displaying the help text for this form input |
|
589 | + * according to the form section's layout strategy |
|
590 | + * |
|
591 | + * @return string |
|
592 | + */ |
|
593 | + public function get_html_for_help() |
|
594 | + { |
|
595 | + return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * Validates the input's sanitized value (assumes _sanitize() has already been called) |
|
602 | + * and returns whether or not the form input's submitted value is value |
|
603 | + * |
|
604 | + * @return boolean |
|
605 | + */ |
|
606 | + protected function _validate() |
|
607 | + { |
|
608 | + if ($this->isDisabled()) { |
|
609 | + return true; |
|
610 | + } |
|
611 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
612 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
613 | + try { |
|
614 | + $validation_strategy->validate($this->normalized_value()); |
|
615 | + } catch (EE_Validation_Error $e) { |
|
616 | + $this->add_validation_error($e); |
|
617 | + } |
|
618 | + } |
|
619 | + } |
|
620 | + if ($this->get_validation_errors()) { |
|
621 | + return false; |
|
622 | + } else { |
|
623 | + return true; |
|
624 | + } |
|
625 | + } |
|
626 | + |
|
627 | + |
|
628 | + |
|
629 | + /** |
|
630 | + * Performs basic sanitization on this value. But what sanitization can be performed anyways? |
|
631 | + * This value MIGHT be allowed to have tags, so we can't really remove them. |
|
632 | + * |
|
633 | + * @param string $value |
|
634 | + * @return null|string |
|
635 | + */ |
|
636 | + protected function _sanitize($value) |
|
637 | + { |
|
638 | + return $value !== null ? stripslashes(html_entity_decode(trim($value))) : null; |
|
639 | + } |
|
640 | + |
|
641 | + |
|
642 | + |
|
643 | + /** |
|
644 | + * Picks out the form value that relates to this form input, |
|
645 | + * and stores it as the sanitized value on the form input, and sets the normalized value. |
|
646 | + * Returns whether or not any validation errors occurred |
|
647 | + * |
|
648 | + * @param array $req_data like $_POST |
|
649 | + * @return boolean whether or not there was an error |
|
650 | + * @throws \EE_Error |
|
651 | + */ |
|
652 | + protected function _normalize($req_data) |
|
653 | + { |
|
654 | + // any existing validation errors don't apply so clear them |
|
655 | + $this->_validation_errors = array(); |
|
656 | + // if the input is disabled, ignore whatever input was sent in |
|
657 | + if ($this->isDisabled()) { |
|
658 | + $this->_set_raw_value(null); |
|
659 | + $this->_set_normalized_value($this->get_default()); |
|
660 | + return false; |
|
661 | + } |
|
662 | + try { |
|
663 | + $raw_input = $this->find_form_data_for_this_section($req_data); |
|
664 | + // super simple sanitization for now |
|
665 | + if (is_array($raw_input)) { |
|
666 | + $raw_value = array(); |
|
667 | + foreach ($raw_input as $key => $value) { |
|
668 | + $raw_value[ $key ] = $this->_sanitize($value); |
|
669 | + } |
|
670 | + $this->_set_raw_value($raw_value); |
|
671 | + } else { |
|
672 | + $this->_set_raw_value($this->_sanitize($raw_input)); |
|
673 | + } |
|
674 | + // we want to mostly leave the input alone in case we need to re-display it to the user |
|
675 | + $this->_set_normalized_value($this->_normalization_strategy->normalize($this->raw_value())); |
|
676 | + return false; |
|
677 | + } catch (EE_Validation_Error $e) { |
|
678 | + $this->add_validation_error($e); |
|
679 | + return true; |
|
680 | + } |
|
681 | + } |
|
682 | + |
|
683 | + |
|
684 | + |
|
685 | + /** |
|
686 | + * @return string |
|
687 | + */ |
|
688 | + public function html_name() |
|
689 | + { |
|
690 | + $this->_set_default_html_name_if_empty(); |
|
691 | + return $this->_html_name; |
|
692 | + } |
|
693 | + |
|
694 | + |
|
695 | + |
|
696 | + /** |
|
697 | + * @return string |
|
698 | + */ |
|
699 | + public function html_label_id() |
|
700 | + { |
|
701 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->html_id() . '-lbl'; |
|
702 | + } |
|
703 | + |
|
704 | + |
|
705 | + |
|
706 | + /** |
|
707 | + * @return string |
|
708 | + */ |
|
709 | + public function html_label_class() |
|
710 | + { |
|
711 | + return $this->_html_label_class; |
|
712 | + } |
|
713 | + |
|
714 | + |
|
715 | + |
|
716 | + /** |
|
717 | + * @return string |
|
718 | + */ |
|
719 | + public function html_label_style() |
|
720 | + { |
|
721 | + return $this->_html_label_style; |
|
722 | + } |
|
723 | + |
|
724 | + |
|
725 | + |
|
726 | + /** |
|
727 | + * @return string |
|
728 | + */ |
|
729 | + public function html_label_text() |
|
730 | + { |
|
731 | + return $this->_html_label_text; |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * @return string |
|
738 | + */ |
|
739 | + public function html_help_text() |
|
740 | + { |
|
741 | + return $this->_html_help_text; |
|
742 | + } |
|
743 | + |
|
744 | + |
|
745 | + |
|
746 | + /** |
|
747 | + * @return string |
|
748 | + */ |
|
749 | + public function html_help_class() |
|
750 | + { |
|
751 | + return $this->_html_help_class; |
|
752 | + } |
|
753 | + |
|
754 | + |
|
755 | + |
|
756 | + /** |
|
757 | + * @return string |
|
758 | + */ |
|
759 | + public function html_help_style() |
|
760 | + { |
|
761 | + return $this->_html_style; |
|
762 | + } |
|
763 | + |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * returns the raw, UNSAFE, input, almost exactly as the user submitted it. |
|
768 | + * Please note that almost all client code should instead use the normalized_value; |
|
769 | + * or possibly raw_value_in_form (which prepares the string for displaying in an HTML attribute on a tag, |
|
770 | + * mostly by escaping quotes) |
|
771 | + * Note, we do not store the exact original value sent in the user's request because |
|
772 | + * it may have malicious content, and we MIGHT want to store the form input in a transient or something... |
|
773 | + * in which case, we would have stored the malicious content to our database. |
|
774 | + * |
|
775 | + * @return string |
|
776 | + */ |
|
777 | + public function raw_value() |
|
778 | + { |
|
779 | + return $this->_raw_value; |
|
780 | + } |
|
781 | + |
|
782 | + |
|
783 | + |
|
784 | + /** |
|
785 | + * Returns a string safe to usage in form inputs when displaying, because |
|
786 | + * it escapes all html entities |
|
787 | + * |
|
788 | + * @return string |
|
789 | + */ |
|
790 | + public function raw_value_in_form() |
|
791 | + { |
|
792 | + return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + |
|
797 | + /** |
|
798 | + * returns the value after it's been sanitized, and then converted into it's proper type |
|
799 | + * in PHP. Eg, a string, an int, an array, |
|
800 | + * |
|
801 | + * @return mixed |
|
802 | + */ |
|
803 | + public function normalized_value() |
|
804 | + { |
|
805 | + return $this->_normalized_value; |
|
806 | + } |
|
807 | + |
|
808 | + |
|
809 | + |
|
810 | + /** |
|
811 | + * Returns the normalized value is a presentable way. By default this is just |
|
812 | + * the normalized value by itself, but it can be overridden for when that's not |
|
813 | + * the best thing to display |
|
814 | + * |
|
815 | + * @return string |
|
816 | + */ |
|
817 | + public function pretty_value() |
|
818 | + { |
|
819 | + return $this->_normalized_value; |
|
820 | + } |
|
821 | + |
|
822 | + |
|
823 | + |
|
824 | + /** |
|
825 | + * When generating the JS for the jquery validation rules like<br> |
|
826 | + * <code>$( "#myform" ).validate({ |
|
827 | + * rules: { |
|
828 | + * password: "required", |
|
829 | + * password_again: { |
|
830 | + * equalTo: "#password" |
|
831 | + * } |
|
832 | + * } |
|
833 | + * });</code> |
|
834 | + * if this field had the name 'password_again', it should return |
|
835 | + * <br><code>password_again: { |
|
836 | + * equalTo: "#password" |
|
837 | + * }</code> |
|
838 | + * |
|
839 | + * @return array |
|
840 | + */ |
|
841 | + public function get_jquery_validation_rules() |
|
842 | + { |
|
843 | + $jquery_validation_js = array(); |
|
844 | + $jquery_validation_rules = array(); |
|
845 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
846 | + $jquery_validation_rules = array_replace_recursive( |
|
847 | + $jquery_validation_rules, |
|
848 | + $validation_strategy->get_jquery_validation_rule_array() |
|
849 | + ); |
|
850 | + } |
|
851 | + if (! empty($jquery_validation_rules)) { |
|
852 | + foreach ($this->get_display_strategy()->get_html_input_ids(true) as $html_id_with_pound_sign) { |
|
853 | + $jquery_validation_js[ $html_id_with_pound_sign ] = $jquery_validation_rules; |
|
854 | + } |
|
855 | + } |
|
856 | + return $jquery_validation_js; |
|
857 | + } |
|
858 | + |
|
859 | + |
|
860 | + |
|
861 | + /** |
|
862 | + * Sets the input's default value for use in displaying in the form. Note: value should be |
|
863 | + * normalized (Eg, if providing a default of ra Yes_NO_Input you would provide TRUE or FALSE, not '1' or '0') |
|
864 | + * |
|
865 | + * @param mixed $value |
|
866 | + * @return void |
|
867 | + */ |
|
868 | + public function set_default($value) |
|
869 | + { |
|
870 | + $this->_default = $value; |
|
871 | + $this->_set_normalized_value($value); |
|
872 | + $this->_set_raw_value($value); |
|
873 | + } |
|
874 | + |
|
875 | + |
|
876 | + |
|
877 | + /** |
|
878 | + * Sets the normalized value on this input |
|
879 | + * |
|
880 | + * @param mixed $value |
|
881 | + */ |
|
882 | + protected function _set_normalized_value($value) |
|
883 | + { |
|
884 | + $this->_normalized_value = $value; |
|
885 | + } |
|
886 | + |
|
887 | + |
|
888 | + |
|
889 | + /** |
|
890 | + * Sets the raw value on this input (ie, exactly as the user submitted it) |
|
891 | + * |
|
892 | + * @param mixed $value |
|
893 | + */ |
|
894 | + protected function _set_raw_value($value) |
|
895 | + { |
|
896 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
897 | + } |
|
898 | + |
|
899 | + |
|
900 | + |
|
901 | + /** |
|
902 | + * Sets the HTML label text after it has already been defined |
|
903 | + * |
|
904 | + * @param string $label |
|
905 | + * @return void |
|
906 | + */ |
|
907 | + public function set_html_label_text($label) |
|
908 | + { |
|
909 | + $this->_html_label_text = $label; |
|
910 | + } |
|
911 | + |
|
912 | + |
|
913 | + |
|
914 | + /** |
|
915 | + * Sets whether or not this field is required, and adjusts the validation strategy. |
|
916 | + * If you want to use the EE_Conditionally_Required_Validation_Strategy, |
|
917 | + * please add it as a validation strategy using add_validation_strategy as normal |
|
918 | + * |
|
919 | + * @param boolean $required boolean |
|
920 | + * @param null $required_text |
|
921 | + */ |
|
922 | + public function set_required($required = true, $required_text = null) |
|
923 | + { |
|
924 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
925 | + // whether $required is a string or a boolean, we want to add a required validation strategy |
|
926 | + if ($required) { |
|
927 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
928 | + } else { |
|
929 | + $this->remove_validation_strategy('EE_Required_Validation_Strategy'); |
|
930 | + } |
|
931 | + $this->_required = $required; |
|
932 | + } |
|
933 | + |
|
934 | + |
|
935 | + |
|
936 | + /** |
|
937 | + * Returns whether or not this field is required |
|
938 | + * |
|
939 | + * @return boolean |
|
940 | + */ |
|
941 | + public function required() |
|
942 | + { |
|
943 | + return $this->_required; |
|
944 | + } |
|
945 | + |
|
946 | + |
|
947 | + |
|
948 | + /** |
|
949 | + * @param string $required_css_class |
|
950 | + */ |
|
951 | + public function set_required_css_class($required_css_class) |
|
952 | + { |
|
953 | + $this->_required_css_class = $required_css_class; |
|
954 | + } |
|
955 | + |
|
956 | + |
|
957 | + |
|
958 | + /** |
|
959 | + * @return string |
|
960 | + */ |
|
961 | + public function required_css_class() |
|
962 | + { |
|
963 | + return $this->_required_css_class; |
|
964 | + } |
|
965 | + |
|
966 | + |
|
967 | + |
|
968 | + /** |
|
969 | + * @param bool $add_required |
|
970 | + * @return string |
|
971 | + */ |
|
972 | + public function html_class($add_required = false) |
|
973 | + { |
|
974 | + return $add_required && $this->required() |
|
975 | + ? $this->required_css_class() . ' ' . $this->_html_class |
|
976 | + : $this->_html_class; |
|
977 | + } |
|
978 | + |
|
979 | + |
|
980 | + /** |
|
981 | + * Sets the help text, in case |
|
982 | + * |
|
983 | + * @param string $text |
|
984 | + */ |
|
985 | + public function set_html_help_text($text) |
|
986 | + { |
|
987 | + $this->_html_help_text = $text; |
|
988 | + } |
|
989 | + |
|
990 | + |
|
991 | + |
|
992 | + /** |
|
993 | + * Uses the sensitive data removal strategy to remove the sensitive data from this |
|
994 | + * input. If there is any kind of sensitive data removal on this input, we clear |
|
995 | + * out the raw value completely |
|
996 | + * |
|
997 | + * @return void |
|
998 | + */ |
|
999 | + public function clean_sensitive_data() |
|
1000 | + { |
|
1001 | + // if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
|
1002 | + // if we need more logic than this we'll make a strategy for it |
|
1003 | + if ($this->_sensitive_data_removal_strategy |
|
1004 | + && ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal |
|
1005 | + ) { |
|
1006 | + $this->_set_raw_value(null); |
|
1007 | + } |
|
1008 | + // and clean the normalized value according to the appropriate strategy |
|
1009 | + $this->_set_normalized_value( |
|
1010 | + $this->get_sensitive_data_removal_strategy()->remove_sensitive_data( |
|
1011 | + $this->_normalized_value |
|
1012 | + ) |
|
1013 | + ); |
|
1014 | + } |
|
1015 | + |
|
1016 | + |
|
1017 | + |
|
1018 | + /** |
|
1019 | + * @param bool $primary |
|
1020 | + * @param string $button_size |
|
1021 | + * @param string $other_attributes |
|
1022 | + */ |
|
1023 | + public function set_button_css_attributes($primary = true, $button_size = '', $other_attributes = '') |
|
1024 | + { |
|
1025 | + $button_css_attributes = 'button'; |
|
1026 | + $button_css_attributes .= $primary === true ? ' button-primary' : ' button-secondary'; |
|
1027 | + switch ($button_size) { |
|
1028 | + case 'xs': |
|
1029 | + case 'extra-small': |
|
1030 | + $button_css_attributes .= ' button-xs'; |
|
1031 | + break; |
|
1032 | + case 'sm': |
|
1033 | + case 'small': |
|
1034 | + $button_css_attributes .= ' button-sm'; |
|
1035 | + break; |
|
1036 | + case 'lg': |
|
1037 | + case 'large': |
|
1038 | + $button_css_attributes .= ' button-lg'; |
|
1039 | + break; |
|
1040 | + case 'block': |
|
1041 | + $button_css_attributes .= ' button-block'; |
|
1042 | + break; |
|
1043 | + case 'md': |
|
1044 | + case 'medium': |
|
1045 | + default: |
|
1046 | + $button_css_attributes .= ''; |
|
1047 | + } |
|
1048 | + $this->_button_css_attributes .= ! empty($other_attributes) |
|
1049 | + ? $button_css_attributes . ' ' . $other_attributes |
|
1050 | + : $button_css_attributes; |
|
1051 | + } |
|
1052 | + |
|
1053 | + |
|
1054 | + |
|
1055 | + /** |
|
1056 | + * @return string |
|
1057 | + */ |
|
1058 | + public function button_css_attributes() |
|
1059 | + { |
|
1060 | + if (empty($this->_button_css_attributes)) { |
|
1061 | + $this->set_button_css_attributes(); |
|
1062 | + } |
|
1063 | + return $this->_button_css_attributes; |
|
1064 | + } |
|
1065 | + |
|
1066 | + |
|
1067 | + |
|
1068 | + /** |
|
1069 | + * find_form_data_for_this_section |
|
1070 | + * using this section's name and its parents, finds the value of the form data that corresponds to it. |
|
1071 | + * For example, if this form section's HTML name is my_form[subform][form_input_1], |
|
1072 | + * then it's value should be in $_REQUEST at $_REQUEST['my_form']['subform']['form_input_1']. |
|
1073 | + * (If that doesn't exist, we also check for this subsection's name |
|
1074 | + * at the TOP LEVEL of the request data. Eg $_REQUEST['form_input_1'].) |
|
1075 | + * This function finds its value in the form. |
|
1076 | + * |
|
1077 | + * @param array $req_data |
|
1078 | + * @return mixed whatever the raw value of this form section is in the request data |
|
1079 | + * @throws \EE_Error |
|
1080 | + */ |
|
1081 | + public function find_form_data_for_this_section($req_data) |
|
1082 | + { |
|
1083 | + $name_parts = $this->getInputNameParts(); |
|
1084 | + // now get the value for the input |
|
1085 | + $value = $this->findRequestForSectionUsingNameParts($name_parts, $req_data); |
|
1086 | + // check if this thing's name is at the TOP level of the request data |
|
1087 | + if ($value === null && isset($req_data[ $this->name() ])) { |
|
1088 | + $value = $req_data[ $this->name() ]; |
|
1089 | + } |
|
1090 | + return $value; |
|
1091 | + } |
|
1092 | + |
|
1093 | + |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * If this input's name is something like "foo[bar][baz]" |
|
1097 | + * returns an array like `array('foo','bar',baz')` |
|
1098 | + * @return array |
|
1099 | + */ |
|
1100 | + protected function getInputNameParts() |
|
1101 | + { |
|
1102 | + // break up the html name by "[]" |
|
1103 | + if (strpos($this->html_name(), '[') !== false) { |
|
1104 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
1105 | + } else { |
|
1106 | + $before_any_brackets = $this->html_name(); |
|
1107 | + } |
|
1108 | + // grab all of the segments |
|
1109 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
1110 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
1111 | + $name_parts = $matches[1]; |
|
1112 | + array_unshift($name_parts, $before_any_brackets); |
|
1113 | + } else { |
|
1114 | + $name_parts = array($before_any_brackets); |
|
1115 | + } |
|
1116 | + return $name_parts; |
|
1117 | + } |
|
1118 | + |
|
1119 | + |
|
1120 | + |
|
1121 | + /** |
|
1122 | + * @param array $html_name_parts |
|
1123 | + * @param array $req_data |
|
1124 | + * @return array | NULL |
|
1125 | + */ |
|
1126 | + public function findRequestForSectionUsingNameParts($html_name_parts, $req_data) |
|
1127 | + { |
|
1128 | + $first_part_to_consider = array_shift($html_name_parts); |
|
1129 | + if (isset($req_data[ $first_part_to_consider ])) { |
|
1130 | + if (empty($html_name_parts)) { |
|
1131 | + return $req_data[ $first_part_to_consider ]; |
|
1132 | + } else { |
|
1133 | + return $this->findRequestForSectionUsingNameParts( |
|
1134 | + $html_name_parts, |
|
1135 | + $req_data[ $first_part_to_consider ] |
|
1136 | + ); |
|
1137 | + } |
|
1138 | + } else { |
|
1139 | + return null; |
|
1140 | + } |
|
1141 | + } |
|
1142 | + |
|
1143 | + |
|
1144 | + |
|
1145 | + /** |
|
1146 | + * Checks if this form input's data is in the request data |
|
1147 | + * |
|
1148 | + * @param array $req_data like $_POST |
|
1149 | + * @return boolean |
|
1150 | + * @throws \EE_Error |
|
1151 | + */ |
|
1152 | + public function form_data_present_in($req_data = null) |
|
1153 | + { |
|
1154 | + if ($req_data === null) { |
|
1155 | + $req_data = $_POST; |
|
1156 | + } |
|
1157 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
1158 | + if ($checked_value !== null) { |
|
1159 | + return true; |
|
1160 | + } else { |
|
1161 | + return false; |
|
1162 | + } |
|
1163 | + } |
|
1164 | + |
|
1165 | + |
|
1166 | + |
|
1167 | + /** |
|
1168 | + * Overrides parent to add js data from validation and display strategies |
|
1169 | + * |
|
1170 | + * @param array $form_other_js_data |
|
1171 | + * @return array |
|
1172 | + */ |
|
1173 | + public function get_other_js_data($form_other_js_data = array()) |
|
1174 | + { |
|
1175 | + $form_other_js_data = $this->get_other_js_data_from_strategies($form_other_js_data); |
|
1176 | + return $form_other_js_data; |
|
1177 | + } |
|
1178 | + |
|
1179 | + |
|
1180 | + |
|
1181 | + /** |
|
1182 | + * Gets other JS data for localization from this input's strategies, like |
|
1183 | + * the validation strategies and the display strategy |
|
1184 | + * |
|
1185 | + * @param array $form_other_js_data |
|
1186 | + * @return array |
|
1187 | + */ |
|
1188 | + public function get_other_js_data_from_strategies($form_other_js_data = array()) |
|
1189 | + { |
|
1190 | + $form_other_js_data = $this->get_display_strategy()->get_other_js_data($form_other_js_data); |
|
1191 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1192 | + $form_other_js_data = $validation_strategy->get_other_js_data($form_other_js_data); |
|
1193 | + } |
|
1194 | + return $form_other_js_data; |
|
1195 | + } |
|
1196 | + |
|
1197 | + |
|
1198 | + |
|
1199 | + /** |
|
1200 | + * Override parent because we want to give our strategies an opportunity to enqueue some js and css |
|
1201 | + * |
|
1202 | + * @return void |
|
1203 | + */ |
|
1204 | + public function enqueue_js() |
|
1205 | + { |
|
1206 | + // ask our display strategy and validation strategies if they have js to enqueue |
|
1207 | + $this->enqueue_js_from_strategies(); |
|
1208 | + } |
|
1209 | + |
|
1210 | + |
|
1211 | + |
|
1212 | + /** |
|
1213 | + * Tells strategies when its ok to enqueue their js and css |
|
1214 | + * |
|
1215 | + * @return void |
|
1216 | + */ |
|
1217 | + public function enqueue_js_from_strategies() |
|
1218 | + { |
|
1219 | + $this->get_display_strategy()->enqueue_js(); |
|
1220 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
1221 | + $validation_strategy->enqueue_js(); |
|
1222 | + } |
|
1223 | + } |
|
1224 | + |
|
1225 | + |
|
1226 | + |
|
1227 | + /** |
|
1228 | + * Gets the default value set on the input (not the current value, which may have been |
|
1229 | + * changed because of a form submission). If no default was set, this us null. |
|
1230 | + * @return mixed |
|
1231 | + */ |
|
1232 | + public function get_default() |
|
1233 | + { |
|
1234 | + return $this->_default; |
|
1235 | + } |
|
1236 | + |
|
1237 | + |
|
1238 | + |
|
1239 | + /** |
|
1240 | + * Makes this input disabled. That means it will have the HTML attribute 'disabled="disabled"', |
|
1241 | + * and server-side if any input was received it will be ignored |
|
1242 | + */ |
|
1243 | + public function disable($disable = true) |
|
1244 | + { |
|
1245 | + $disabled_attribute = ' disabled="disabled"'; |
|
1246 | + $this->disabled = filter_var($disable, FILTER_VALIDATE_BOOLEAN); |
|
1247 | + if ($this->disabled) { |
|
1248 | + if (strpos($this->_other_html_attributes, $disabled_attribute) === false) { |
|
1249 | + $this->_other_html_attributes .= $disabled_attribute; |
|
1250 | + } |
|
1251 | + $this->_set_normalized_value($this->get_default()); |
|
1252 | + } else { |
|
1253 | + $this->_other_html_attributes = str_replace($disabled_attribute, '', $this->_other_html_attributes); |
|
1254 | + } |
|
1255 | + } |
|
1256 | + |
|
1257 | + |
|
1258 | + |
|
1259 | + /** |
|
1260 | + * Returns whether or not this input is currently disabled. |
|
1261 | + * @return bool |
|
1262 | + */ |
|
1263 | + public function isDisabled() |
|
1264 | + { |
|
1265 | + return $this->disabled; |
|
1266 | + } |
|
1267 | 1267 | } |
@@ -23,65 +23,65 @@ |
||
23 | 23 | class TicketFilterHeader extends AdminPageHeaderDecorator |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var EEM_Ticket $ticket_model |
|
28 | - */ |
|
29 | - private $ticket_model; |
|
26 | + /** |
|
27 | + * @var EEM_Ticket $ticket_model |
|
28 | + */ |
|
29 | + private $ticket_model; |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * TicketFilterHeader constructor. |
|
34 | - * |
|
35 | - * @param RequestInterface $request |
|
36 | - * @param EEM_Ticket $ticket_model |
|
37 | - */ |
|
38 | - public function __construct(RequestInterface $request, EEM_Ticket $ticket_model) |
|
39 | - { |
|
40 | - parent::__construct($request); |
|
41 | - $this->ticket_model = $ticket_model; |
|
42 | - } |
|
32 | + /** |
|
33 | + * TicketFilterHeader constructor. |
|
34 | + * |
|
35 | + * @param RequestInterface $request |
|
36 | + * @param EEM_Ticket $ticket_model |
|
37 | + */ |
|
38 | + public function __construct(RequestInterface $request, EEM_Ticket $ticket_model) |
|
39 | + { |
|
40 | + parent::__construct($request); |
|
41 | + $this->ticket_model = $ticket_model; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @param string $text |
|
47 | - * @return string |
|
48 | - * @throws EE_Error |
|
49 | - * @throws InvalidDataTypeException |
|
50 | - * @throws InvalidInterfaceException |
|
51 | - * @throws InvalidArgumentException |
|
52 | - * @throws ReflectionException |
|
53 | - * @since 4.10.2.p |
|
54 | - */ |
|
55 | - public function getHeaderText($text = '') |
|
56 | - { |
|
57 | - $TKT_ID = $this->request->getRequestParam('TKT_ID'); |
|
58 | - $TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID); |
|
59 | - $TKT_ID = absint($TKT_ID); |
|
60 | - if ($TKT_ID) { |
|
61 | - $ticket = $this->ticket_model->get_one_by_ID($TKT_ID); |
|
62 | - if ($ticket instanceof EE_Ticket) { |
|
63 | - $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> '; |
|
64 | - $ticket_details .= ! $ticket->is_free() |
|
65 | - ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>' |
|
66 | - : '<span class="reg-overview-free-event-spn">' |
|
67 | - . __('free', 'event_espresso') |
|
68 | - . '</span>'; |
|
69 | - // remove the closing h3 heading tag if it exists |
|
70 | - $text = str_replace( |
|
71 | - '</h3>', |
|
72 | - '', |
|
73 | - $text |
|
74 | - ); |
|
75 | - if (empty($text)) { |
|
76 | - $text = '<h3 style="line-height:1.5em;">'; |
|
77 | - $text .= esc_html__('Viewing registrations for ticket:', 'event_espresso'); |
|
78 | - } |
|
79 | - $text .= ' '; |
|
80 | - $text .= '<span class="drk-grey-text" style="font-size:.9em;">'; |
|
81 | - $text .= '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
82 | - $text .= $ticket_details . '</span></h3>'; |
|
83 | - } |
|
84 | - } |
|
85 | - return $text; |
|
86 | - } |
|
45 | + /** |
|
46 | + * @param string $text |
|
47 | + * @return string |
|
48 | + * @throws EE_Error |
|
49 | + * @throws InvalidDataTypeException |
|
50 | + * @throws InvalidInterfaceException |
|
51 | + * @throws InvalidArgumentException |
|
52 | + * @throws ReflectionException |
|
53 | + * @since 4.10.2.p |
|
54 | + */ |
|
55 | + public function getHeaderText($text = '') |
|
56 | + { |
|
57 | + $TKT_ID = $this->request->getRequestParam('TKT_ID'); |
|
58 | + $TKT_ID = $this->request->getRequestParam('ticket_id', $TKT_ID); |
|
59 | + $TKT_ID = absint($TKT_ID); |
|
60 | + if ($TKT_ID) { |
|
61 | + $ticket = $this->ticket_model->get_one_by_ID($TKT_ID); |
|
62 | + if ($ticket instanceof EE_Ticket) { |
|
63 | + $ticket_details = '<span class="ee-ticket-name">' . $ticket->name() . '</span> '; |
|
64 | + $ticket_details .= ! $ticket->is_free() |
|
65 | + ? '<span class="ee-ticket-price">' . $ticket->pretty_price() . '</span>' |
|
66 | + : '<span class="reg-overview-free-event-spn">' |
|
67 | + . __('free', 'event_espresso') |
|
68 | + . '</span>'; |
|
69 | + // remove the closing h3 heading tag if it exists |
|
70 | + $text = str_replace( |
|
71 | + '</h3>', |
|
72 | + '', |
|
73 | + $text |
|
74 | + ); |
|
75 | + if (empty($text)) { |
|
76 | + $text = '<h3 style="line-height:1.5em;">'; |
|
77 | + $text .= esc_html__('Viewing registrations for ticket:', 'event_espresso'); |
|
78 | + } |
|
79 | + $text .= ' '; |
|
80 | + $text .= '<span class="drk-grey-text" style="font-size:.9em;">'; |
|
81 | + $text .= '<span class="dashicons dashicons-tickets-alt"></span>'; |
|
82 | + $text .= $ticket_details . '</span></h3>'; |
|
83 | + } |
|
84 | + } |
|
85 | + return $text; |
|
86 | + } |
|
87 | 87 | } |
@@ -23,58 +23,58 @@ |
||
23 | 23 | class DateFilterHeader extends AdminPageHeaderDecorator |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var EEM_Datetime $datetime_model |
|
28 | - */ |
|
29 | - private $datetime_model; |
|
26 | + /** |
|
27 | + * @var EEM_Datetime $datetime_model |
|
28 | + */ |
|
29 | + private $datetime_model; |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * DateFilterHeader constructor. |
|
34 | - * |
|
35 | - * @param RequestInterface $request |
|
36 | - * @param EEM_Datetime $datetime_model |
|
37 | - */ |
|
38 | - public function __construct(RequestInterface $request, EEM_Datetime $datetime_model) |
|
39 | - { |
|
40 | - parent::__construct($request); |
|
41 | - $this->datetime_model = $datetime_model; |
|
42 | - } |
|
32 | + /** |
|
33 | + * DateFilterHeader constructor. |
|
34 | + * |
|
35 | + * @param RequestInterface $request |
|
36 | + * @param EEM_Datetime $datetime_model |
|
37 | + */ |
|
38 | + public function __construct(RequestInterface $request, EEM_Datetime $datetime_model) |
|
39 | + { |
|
40 | + parent::__construct($request); |
|
41 | + $this->datetime_model = $datetime_model; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @param string $text |
|
47 | - * @return string |
|
48 | - * @throws EE_Error |
|
49 | - * @throws InvalidDataTypeException |
|
50 | - * @throws InvalidInterfaceException |
|
51 | - * @throws InvalidArgumentException |
|
52 | - * @throws ReflectionException |
|
53 | - * @since 4.10.2.p |
|
54 | - */ |
|
55 | - public function getHeaderText($text = '') |
|
56 | - { |
|
57 | - $DTT_ID = $this->request->getRequestParam('DTT_ID'); |
|
58 | - $DTT_ID = $this->request->getRequestParam('datetime_id', $DTT_ID); |
|
59 | - $DTT_ID = absint($DTT_ID); |
|
60 | - if ($DTT_ID) { |
|
61 | - $datetime = $this->datetime_model->get_one_by_ID($DTT_ID); |
|
62 | - if ($datetime instanceof EE_Datetime && $text !== '') { |
|
63 | - // remove the closing h3 heading tag if it exists |
|
64 | - $text = str_replace( |
|
65 | - '</h3>', |
|
66 | - '', |
|
67 | - $text |
|
68 | - ); |
|
69 | - $text .= ' '; |
|
70 | - $text .= '<span class="drk-grey-text">'; |
|
71 | - $text .= '<span class="dashicons dashicons-calendar"></span>'; |
|
72 | - $text .= $datetime->name(); |
|
73 | - $text .= ' ( ' . $datetime->start_date() . ' )'; |
|
74 | - $text .= '</span></h3>'; |
|
75 | - } |
|
76 | - } |
|
45 | + /** |
|
46 | + * @param string $text |
|
47 | + * @return string |
|
48 | + * @throws EE_Error |
|
49 | + * @throws InvalidDataTypeException |
|
50 | + * @throws InvalidInterfaceException |
|
51 | + * @throws InvalidArgumentException |
|
52 | + * @throws ReflectionException |
|
53 | + * @since 4.10.2.p |
|
54 | + */ |
|
55 | + public function getHeaderText($text = '') |
|
56 | + { |
|
57 | + $DTT_ID = $this->request->getRequestParam('DTT_ID'); |
|
58 | + $DTT_ID = $this->request->getRequestParam('datetime_id', $DTT_ID); |
|
59 | + $DTT_ID = absint($DTT_ID); |
|
60 | + if ($DTT_ID) { |
|
61 | + $datetime = $this->datetime_model->get_one_by_ID($DTT_ID); |
|
62 | + if ($datetime instanceof EE_Datetime && $text !== '') { |
|
63 | + // remove the closing h3 heading tag if it exists |
|
64 | + $text = str_replace( |
|
65 | + '</h3>', |
|
66 | + '', |
|
67 | + $text |
|
68 | + ); |
|
69 | + $text .= ' '; |
|
70 | + $text .= '<span class="drk-grey-text">'; |
|
71 | + $text .= '<span class="dashicons dashicons-calendar"></span>'; |
|
72 | + $text .= $datetime->name(); |
|
73 | + $text .= ' ( ' . $datetime->start_date() . ' )'; |
|
74 | + $text .= '</span></h3>'; |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - return $text; |
|
79 | - } |
|
78 | + return $text; |
|
79 | + } |
|
80 | 80 | } |
@@ -24,63 +24,63 @@ |
||
24 | 24 | class EventFilterHeader extends AdminPageHeaderDecorator |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var EEM_Event $event_model |
|
29 | - */ |
|
30 | - private $event_model; |
|
27 | + /** |
|
28 | + * @var EEM_Event $event_model |
|
29 | + */ |
|
30 | + private $event_model; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * EventFilterHeader constructor. |
|
35 | - * |
|
36 | - * @param RequestInterface $request |
|
37 | - * @param EEM_Event $event_model |
|
38 | - */ |
|
39 | - public function __construct(RequestInterface $request, EEM_Event $event_model) |
|
40 | - { |
|
41 | - parent::__construct($request); |
|
42 | - $this->event_model = $event_model; |
|
43 | - } |
|
33 | + /** |
|
34 | + * EventFilterHeader constructor. |
|
35 | + * |
|
36 | + * @param RequestInterface $request |
|
37 | + * @param EEM_Event $event_model |
|
38 | + */ |
|
39 | + public function __construct(RequestInterface $request, EEM_Event $event_model) |
|
40 | + { |
|
41 | + parent::__construct($request); |
|
42 | + $this->event_model = $event_model; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @param string $text |
|
48 | - * @return string |
|
49 | - * @throws EE_Error |
|
50 | - * @throws InvalidDataTypeException |
|
51 | - * @throws InvalidInterfaceException |
|
52 | - * @throws InvalidArgumentException |
|
53 | - * @throws ReflectionException |
|
54 | - * @since 4.10.2.p |
|
55 | - */ |
|
56 | - public function getHeaderText($text = '') |
|
57 | - { |
|
58 | - $EVT_ID = $this->request->getRequestParam('EVT_ID'); |
|
59 | - $EVT_ID = $this->request->getRequestParam('event_id', $EVT_ID); |
|
60 | - $EVT_ID = absint($EVT_ID); |
|
61 | - if ($EVT_ID) { |
|
62 | - $event = $this->event_model->get_one_by_ID($EVT_ID); |
|
63 | - if ($event instanceof EE_Event) { |
|
64 | - $text .= sprintf( |
|
65 | - /* translators: %s: <h3> %s: <a href>Event Name</a> %s: </h3> */ |
|
66 | - // phpcs:ignore WordPress.WP.I18n.UnorderedPlaceholdersText |
|
67 | - esc_html__('%s Viewing registrations for the event: %s%s', 'event_espresso'), |
|
68 | - '<h3 style="line-height:1.5em;">', |
|
69 | - ' <a href="' |
|
70 | - . EE_Admin_Page::add_query_args_and_nonce( |
|
71 | - array( |
|
72 | - 'action' => 'edit', |
|
73 | - 'post' => $event->ID(), |
|
74 | - ), |
|
75 | - EVENTS_ADMIN_URL |
|
76 | - ) |
|
77 | - . '">' |
|
78 | - . $event->get('EVT_name') |
|
79 | - . '</a> ', |
|
80 | - '</h3>' |
|
81 | - ); |
|
82 | - } |
|
83 | - } |
|
84 | - return $text; |
|
85 | - } |
|
46 | + /** |
|
47 | + * @param string $text |
|
48 | + * @return string |
|
49 | + * @throws EE_Error |
|
50 | + * @throws InvalidDataTypeException |
|
51 | + * @throws InvalidInterfaceException |
|
52 | + * @throws InvalidArgumentException |
|
53 | + * @throws ReflectionException |
|
54 | + * @since 4.10.2.p |
|
55 | + */ |
|
56 | + public function getHeaderText($text = '') |
|
57 | + { |
|
58 | + $EVT_ID = $this->request->getRequestParam('EVT_ID'); |
|
59 | + $EVT_ID = $this->request->getRequestParam('event_id', $EVT_ID); |
|
60 | + $EVT_ID = absint($EVT_ID); |
|
61 | + if ($EVT_ID) { |
|
62 | + $event = $this->event_model->get_one_by_ID($EVT_ID); |
|
63 | + if ($event instanceof EE_Event) { |
|
64 | + $text .= sprintf( |
|
65 | + /* translators: %s: <h3> %s: <a href>Event Name</a> %s: </h3> */ |
|
66 | + // phpcs:ignore WordPress.WP.I18n.UnorderedPlaceholdersText |
|
67 | + esc_html__('%s Viewing registrations for the event: %s%s', 'event_espresso'), |
|
68 | + '<h3 style="line-height:1.5em;">', |
|
69 | + ' <a href="' |
|
70 | + . EE_Admin_Page::add_query_args_and_nonce( |
|
71 | + array( |
|
72 | + 'action' => 'edit', |
|
73 | + 'post' => $event->ID(), |
|
74 | + ), |
|
75 | + EVENTS_ADMIN_URL |
|
76 | + ) |
|
77 | + . '">' |
|
78 | + . $event->get('EVT_name') |
|
79 | + . '</a> ', |
|
80 | + '</h3>' |
|
81 | + ); |
|
82 | + } |
|
83 | + } |
|
84 | + return $text; |
|
85 | + } |
|
86 | 86 | } |