@@ -17,818 +17,818 @@ |
||
| 17 | 17 | { |
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @return EED_Module|EED_Add_New_State |
|
| 22 | - */ |
|
| 23 | - public static function instance() |
|
| 24 | - { |
|
| 25 | - return parent::get_instance(__CLASS__); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
| 31 | - * |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - public static function set_hooks() |
|
| 35 | - { |
|
| 36 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 37 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 38 | - add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 39 | - add_filter( |
|
| 40 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 41 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 42 | - 1, |
|
| 43 | - 1 |
|
| 44 | - ); |
|
| 45 | - add_filter( |
|
| 46 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 47 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 48 | - 1, |
|
| 49 | - 1 |
|
| 50 | - ); |
|
| 51 | - add_filter( |
|
| 52 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 53 | - array('EED_Add_New_State', 'unset_new_state_request_params'), |
|
| 54 | - 10, |
|
| 55 | - 1 |
|
| 56 | - ); |
|
| 57 | - add_filter( |
|
| 58 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 59 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), |
|
| 60 | - 10, |
|
| 61 | - 5 |
|
| 62 | - ); |
|
| 63 | - add_filter( |
|
| 64 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 65 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), |
|
| 66 | - 10, |
|
| 67 | - 5 |
|
| 68 | - ); |
|
| 69 | - add_filter( |
|
| 70 | - 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 71 | - array('EED_Add_New_State', 'state_options'), |
|
| 72 | - 10, |
|
| 73 | - 1 |
|
| 74 | - ); |
|
| 75 | - add_filter( |
|
| 76 | - 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 77 | - array('EED_Add_New_State', 'country_options'), |
|
| 78 | - 10, |
|
| 79 | - 1 |
|
| 80 | - ); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 86 | - * |
|
| 87 | - * @return void |
|
| 88 | - */ |
|
| 89 | - public static function set_hooks_admin() |
|
| 90 | - { |
|
| 91 | - add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 92 | - add_filter( |
|
| 93 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 94 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 95 | - 1, |
|
| 96 | - 1 |
|
| 97 | - ); |
|
| 98 | - add_filter( |
|
| 99 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 100 | - array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 101 | - 1, |
|
| 102 | - 1 |
|
| 103 | - ); |
|
| 104 | - add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 105 | - add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 106 | - add_filter( |
|
| 107 | - 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 108 | - array('EED_Add_New_State', 'unset_new_state_request_params'), |
|
| 109 | - 10, |
|
| 110 | - 1 |
|
| 111 | - ); |
|
| 112 | - add_action( |
|
| 113 | - 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 114 | - array('EED_Add_New_State', 'update_country_settings'), |
|
| 115 | - 10, |
|
| 116 | - 3 |
|
| 117 | - ); |
|
| 118 | - add_action( |
|
| 119 | - 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 120 | - array('EED_Add_New_State', 'update_country_settings'), |
|
| 121 | - 10, |
|
| 122 | - 3 |
|
| 123 | - ); |
|
| 124 | - add_filter( |
|
| 125 | - 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 126 | - array('EED_Add_New_State', 'state_options'), |
|
| 127 | - 10, |
|
| 128 | - 1 |
|
| 129 | - ); |
|
| 130 | - add_filter( |
|
| 131 | - 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 132 | - array('EED_Add_New_State', 'country_options'), |
|
| 133 | - 10, |
|
| 134 | - 1 |
|
| 135 | - ); |
|
| 136 | - add_filter( |
|
| 137 | - 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 138 | - array('EED_Add_New_State', 'filter_checkout_request_params'), |
|
| 139 | - 10, |
|
| 140 | - 1 |
|
| 141 | - ); |
|
| 142 | - add_filter( |
|
| 143 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 144 | - array('EED_Add_New_State', 'inject_new_reg_state_into_options'), |
|
| 145 | - 10, |
|
| 146 | - 5 |
|
| 147 | - ); |
|
| 148 | - add_filter( |
|
| 149 | - 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 150 | - array('EED_Add_New_State', 'inject_new_reg_country_into_options'), |
|
| 151 | - 10, |
|
| 152 | - 5 |
|
| 153 | - ); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @return void |
|
| 159 | - */ |
|
| 160 | - public static function set_definitions() |
|
| 161 | - { |
|
| 162 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 163 | - define( |
|
| 164 | - 'ANS_TEMPLATES_PATH', |
|
| 165 | - str_replace( |
|
| 166 | - '\\', |
|
| 167 | - DS, |
|
| 168 | - plugin_dir_path(__FILE__) |
|
| 169 | - ) . 'templates' . DS |
|
| 170 | - ); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * @param WP $WP |
|
| 176 | - * @return void |
|
| 177 | - */ |
|
| 178 | - public function run($WP) |
|
| 179 | - { |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * @return void |
|
| 185 | - */ |
|
| 186 | - public static function translate_js_strings() |
|
| 187 | - { |
|
| 188 | - EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 189 | - 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 190 | - 'event_espresso' |
|
| 191 | - ); |
|
| 192 | - EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 193 | - 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 194 | - 'event_espresso' |
|
| 195 | - ); |
|
| 196 | - EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 197 | - 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 198 | - 'event_espresso' |
|
| 199 | - ); |
|
| 200 | - EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 201 | - 'The new state was successfully saved to the database.', |
|
| 202 | - 'event_espresso' |
|
| 203 | - ); |
|
| 204 | - EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 205 | - 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 206 | - 'event_espresso' |
|
| 207 | - ); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * @return void |
|
| 213 | - */ |
|
| 214 | - public static function wp_enqueue_scripts() |
|
| 215 | - { |
|
| 216 | - if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 217 | - wp_register_script( |
|
| 218 | - 'add_new_state', |
|
| 219 | - ANS_ASSETS_URL . 'add_new_state.js', |
|
| 220 | - array('espresso_core', 'single_page_checkout'), |
|
| 221 | - EVENT_ESPRESSO_VERSION, |
|
| 222 | - true |
|
| 223 | - ); |
|
| 224 | - wp_enqueue_script('add_new_state'); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * display_add_new_state_micro_form |
|
| 232 | - * |
|
| 233 | - * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 234 | - * @return string |
|
| 235 | - * @throws EE_Error |
|
| 236 | - * @throws InvalidArgumentException |
|
| 237 | - * @throws InvalidDataTypeException |
|
| 238 | - * @throws InvalidInterfaceException |
|
| 239 | - */ |
|
| 240 | - public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 241 | - { |
|
| 242 | - // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 243 | - // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 244 | - $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 245 | - // is the "state" question in this form section? |
|
| 246 | - $input = $question_group_reg_form->get_subsection('state'); |
|
| 247 | - if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 248 | - // ok then all we need to do is make sure the input's HTML name is consistent |
|
| 249 | - // by forcing it to set it now, like it did while getting the form for display |
|
| 250 | - if ($input instanceof EE_State_Select_Input) { |
|
| 251 | - $input->html_name(); |
|
| 252 | - } |
|
| 253 | - return $question_group_reg_form; |
|
| 254 | - } |
|
| 255 | - // we're only doing this for state select inputs |
|
| 256 | - if ($input instanceof EE_State_Select_Input |
|
| 257 | - && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy |
|
| 258 | - ) { |
|
| 259 | - // grab any set values from the request |
|
| 260 | - $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 261 | - $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 262 | - $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 263 | - $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 264 | - $country_options = array(); |
|
| 265 | - $countries = EEM_Country::instance()->get_all_countries(); |
|
| 266 | - if (! empty($countries)) { |
|
| 267 | - foreach ($countries as $country) { |
|
| 268 | - if ($country instanceof EE_Country) { |
|
| 269 | - $country_options[ $country->ID() ] = $country->name(); |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 274 | - array( |
|
| 275 | - 'name' => 'new_state_micro_form', |
|
| 276 | - 'html_id' => 'new_state_micro_form', |
|
| 277 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 278 | - 'subsections' => array( |
|
| 279 | - // add hidden input to indicate that a new state is being added |
|
| 280 | - 'add_new_state' => new EE_Hidden_Input( |
|
| 281 | - array( |
|
| 282 | - 'html_name' => str_replace( |
|
| 283 | - 'state', |
|
| 284 | - 'nsmf_add_new_state', |
|
| 285 | - $input->html_name() |
|
| 286 | - ), |
|
| 287 | - 'html_id' => str_replace( |
|
| 288 | - 'state', |
|
| 289 | - 'nsmf_add_new_state', |
|
| 290 | - $input->html_id() |
|
| 291 | - ), |
|
| 292 | - 'default' => 0, |
|
| 293 | - ) |
|
| 294 | - ), |
|
| 295 | - // add link for displaying hidden container |
|
| 296 | - 'click_here_link' => new EE_Form_Section_HTML( |
|
| 297 | - apply_filters( |
|
| 298 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 299 | - EEH_HTML::link( |
|
| 300 | - '', |
|
| 301 | - esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 302 | - '', |
|
| 303 | - 'display-' . $input->html_id(), |
|
| 304 | - 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 305 | - '', |
|
| 306 | - 'data-target="' . $input->html_id() . '"' |
|
| 307 | - ) |
|
| 308 | - ) |
|
| 309 | - ), |
|
| 310 | - // add initial html for hidden container |
|
| 311 | - 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 312 | - apply_filters( |
|
| 313 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 314 | - EEH_HTML::div( |
|
| 315 | - '', |
|
| 316 | - $input->html_id() . '-dv', |
|
| 317 | - 'ee-form-add-new-state-dv', |
|
| 318 | - 'display: none;' |
|
| 319 | - ) . |
|
| 320 | - EEH_HTML::h6( |
|
| 321 | - esc_html__( |
|
| 322 | - 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 323 | - 'event_espresso' |
|
| 324 | - ) |
|
| 325 | - ) . |
|
| 326 | - EEH_HTML::ul() . |
|
| 327 | - EEH_HTML::li( |
|
| 328 | - esc_html__( |
|
| 329 | - 'first select the Country that your State/Province belongs to', |
|
| 330 | - 'event_espresso' |
|
| 331 | - ) |
|
| 332 | - ) . |
|
| 333 | - EEH_HTML::li( |
|
| 334 | - esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 335 | - ) . |
|
| 336 | - EEH_HTML::li( |
|
| 337 | - esc_html__( |
|
| 338 | - 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 339 | - 'event_espresso' |
|
| 340 | - ) |
|
| 341 | - ) . |
|
| 342 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 343 | - EEH_HTML::ulx() |
|
| 344 | - ) |
|
| 345 | - ), |
|
| 346 | - // NEW STATE COUNTRY |
|
| 347 | - 'new_state_country' => new EE_Country_Select_Input( |
|
| 348 | - $country_options, |
|
| 349 | - array( |
|
| 350 | - 'html_name' => $country_name, |
|
| 351 | - 'html_id' => str_replace( |
|
| 352 | - 'state', |
|
| 353 | - 'nsmf_new_state_country', |
|
| 354 | - $input->html_id() |
|
| 355 | - ), |
|
| 356 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 357 | - 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 358 | - 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 359 | - 'required' => false, |
|
| 360 | - ) |
|
| 361 | - ), |
|
| 362 | - // NEW STATE NAME |
|
| 363 | - 'new_state_name' => new EE_Text_Input( |
|
| 364 | - array( |
|
| 365 | - 'html_name' => $state_name, |
|
| 366 | - 'html_id' => str_replace( |
|
| 367 | - 'state', |
|
| 368 | - 'nsmf_new_state_name', |
|
| 369 | - $input->html_id() |
|
| 370 | - ), |
|
| 371 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 372 | - 'html_label_text' => esc_html__( |
|
| 373 | - 'New State/Province Name', |
|
| 374 | - 'event_espresso' |
|
| 375 | - ), |
|
| 376 | - 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 377 | - 'required' => false, |
|
| 378 | - ) |
|
| 379 | - ), |
|
| 380 | - 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 381 | - // NEW STATE NAME |
|
| 382 | - 'new_state_abbrv' => new EE_Text_Input( |
|
| 383 | - array( |
|
| 384 | - 'html_name' => $abbrv_name, |
|
| 385 | - 'html_id' => str_replace( |
|
| 386 | - 'state', |
|
| 387 | - 'nsmf_new_state_abbrv', |
|
| 388 | - $input->html_id() |
|
| 389 | - ), |
|
| 390 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 391 | - 'html_label_text' => esc_html__( |
|
| 392 | - 'New State/Province Abbreviation', |
|
| 393 | - 'event_espresso' |
|
| 394 | - ) . ' *', |
|
| 395 | - 'html_other_attributes' => 'size="24"', |
|
| 396 | - 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 397 | - 'required' => false, |
|
| 398 | - ) |
|
| 399 | - ), |
|
| 400 | - // "submit" button |
|
| 401 | - 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 402 | - apply_filters( |
|
| 403 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 404 | - EEH_HTML::nbsp(3) . |
|
| 405 | - EEH_HTML::link( |
|
| 406 | - '', |
|
| 407 | - esc_html__('ADD', 'event_espresso'), |
|
| 408 | - '', |
|
| 409 | - 'submit-' . $new_state_submit_id, |
|
| 410 | - 'ee-form-add-new-state-submit button button-secondary', |
|
| 411 | - '', |
|
| 412 | - 'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"' |
|
| 413 | - ) |
|
| 414 | - ) |
|
| 415 | - ), |
|
| 416 | - // extra info |
|
| 417 | - 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 418 | - apply_filters( |
|
| 419 | - 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 420 | - EEH_HTML::br(2) |
|
| 421 | - . |
|
| 422 | - EEH_HTML::div('', '', 'small-text') |
|
| 423 | - . |
|
| 424 | - EEH_HTML::strong( |
|
| 425 | - '* ' . |
|
| 426 | - esc_html__( |
|
| 427 | - 'Don\'t know your State/Province Abbreviation?', |
|
| 428 | - 'event_espresso' |
|
| 429 | - ) |
|
| 430 | - ) |
|
| 431 | - . |
|
| 432 | - EEH_HTML::br() |
|
| 433 | - . |
|
| 434 | - sprintf( |
|
| 435 | - esc_html__( |
|
| 436 | - 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 437 | - 'event_espresso' |
|
| 438 | - ), |
|
| 439 | - EEH_HTML::link( |
|
| 440 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 441 | - 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 442 | - '', |
|
| 443 | - '', |
|
| 444 | - 'ee-form-add-new-state-wiki-lnk', |
|
| 445 | - '', |
|
| 446 | - 'target="_blank"' |
|
| 447 | - ) |
|
| 448 | - ) |
|
| 449 | - . |
|
| 450 | - EEH_HTML::divx() |
|
| 451 | - . |
|
| 452 | - EEH_HTML::br() |
|
| 453 | - . |
|
| 454 | - EEH_HTML::link( |
|
| 455 | - '', |
|
| 456 | - esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 457 | - '', |
|
| 458 | - 'hide-' . $input->html_id(), |
|
| 459 | - 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 460 | - '', |
|
| 461 | - 'data-target="' . $input->html_id() . '"' |
|
| 462 | - ) |
|
| 463 | - . |
|
| 464 | - EEH_HTML::divx() |
|
| 465 | - . |
|
| 466 | - EEH_HTML::br() |
|
| 467 | - ) |
|
| 468 | - ), |
|
| 469 | - ), |
|
| 470 | - ) |
|
| 471 | - ); |
|
| 472 | - $question_group_reg_form->add_subsections( |
|
| 473 | - array('new_state_micro_form' => $new_state_micro_form), |
|
| 474 | - 'state', |
|
| 475 | - false |
|
| 476 | - ); |
|
| 477 | - } |
|
| 478 | - return $question_group_reg_form; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * set_new_state_input_width |
|
| 484 | - * |
|
| 485 | - * @return int|string |
|
| 486 | - * @throws EE_Error |
|
| 487 | - * @throws InvalidArgumentException |
|
| 488 | - * @throws InvalidDataTypeException |
|
| 489 | - * @throws InvalidInterfaceException |
|
| 490 | - * @throws ReflectionException |
|
| 491 | - */ |
|
| 492 | - public static function add_new_state() |
|
| 493 | - { |
|
| 494 | - $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 495 | - if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 496 | - EE_Registry::instance()->load_model('State'); |
|
| 497 | - // grab country ISO code, new state name, and new state abbreviation |
|
| 498 | - $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 499 | - ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 500 | - : false; |
|
| 501 | - $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 502 | - ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 503 | - : false; |
|
| 504 | - $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 505 | - ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 506 | - : false; |
|
| 507 | - if ($state_country && $state_name && $state_abbr) { |
|
| 508 | - $new_state = EED_Add_New_State::save_new_state_to_db( |
|
| 509 | - array( |
|
| 510 | - 'CNT_ISO' => strtoupper($state_country), |
|
| 511 | - 'STA_abbrev' => strtoupper($state_abbr), |
|
| 512 | - 'STA_name' => ucwords($state_name), |
|
| 513 | - 'STA_active' => false, |
|
| 514 | - ) |
|
| 515 | - ); |
|
| 516 | - if ($new_state instanceof EE_State) { |
|
| 517 | - // clean house |
|
| 518 | - EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 519 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 520 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 521 | - EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 522 | - // get any existing new states |
|
| 523 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 524 | - 'nsmf_new_states' |
|
| 525 | - ); |
|
| 526 | - $new_states[ $new_state->ID() ] = $new_state; |
|
| 527 | - EE_Registry::instance()->SSN->set_session_data( |
|
| 528 | - array('nsmf_new_states' => $new_states) |
|
| 529 | - ); |
|
| 530 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 531 | - echo wp_json_encode( |
|
| 532 | - array( |
|
| 533 | - 'success' => true, |
|
| 534 | - 'id' => $new_state->ID(), |
|
| 535 | - 'name' => $new_state->name(), |
|
| 536 | - 'abbrev' => $new_state->abbrev(), |
|
| 537 | - 'country_iso' => $new_state->country_iso(), |
|
| 538 | - 'country_name' => $new_state->country()->name(), |
|
| 539 | - ) |
|
| 540 | - ); |
|
| 541 | - exit(); |
|
| 542 | - } |
|
| 543 | - return $new_state->ID(); |
|
| 544 | - } |
|
| 545 | - } else { |
|
| 546 | - $error = esc_html__( |
|
| 547 | - 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 548 | - 'event_espresso' |
|
| 549 | - ); |
|
| 550 | - if (EE_Registry::instance()->REQ->ajax) { |
|
| 551 | - echo wp_json_encode(array('error' => $error)); |
|
| 552 | - exit(); |
|
| 553 | - } |
|
| 554 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - return false; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - |
|
| 561 | - /** |
|
| 562 | - * recursively drills down through request params to remove any that were added by this module |
|
| 563 | - * |
|
| 564 | - * @param array $request_params |
|
| 565 | - * @return array |
|
| 566 | - */ |
|
| 567 | - public static function filter_checkout_request_params($request_params) |
|
| 568 | - { |
|
| 569 | - foreach ($request_params as $form_section) { |
|
| 570 | - if (is_array($form_section)) { |
|
| 571 | - EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 572 | - EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - return $request_params; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - |
|
| 579 | - /** |
|
| 580 | - * @param array $request_params |
|
| 581 | - * @return array |
|
| 582 | - */ |
|
| 583 | - public static function unset_new_state_request_params($request_params) |
|
| 584 | - { |
|
| 585 | - unset( |
|
| 586 | - $request_params['new_state_micro_form'], |
|
| 587 | - $request_params['new_state_micro_add_new_state'], |
|
| 588 | - $request_params['new_state_micro_new_state_country'], |
|
| 589 | - $request_params['new_state_micro_new_state_name'], |
|
| 590 | - $request_params['new_state_micro_new_state_abbrv'] |
|
| 591 | - ); |
|
| 592 | - return $request_params; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * @param array $props_n_values |
|
| 598 | - * @return bool |
|
| 599 | - * @throws EE_Error |
|
| 600 | - * @throws InvalidArgumentException |
|
| 601 | - * @throws InvalidDataTypeException |
|
| 602 | - * @throws InvalidInterfaceException |
|
| 603 | - */ |
|
| 604 | - public static function save_new_state_to_db($props_n_values = array()) |
|
| 605 | - { |
|
| 606 | - $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 607 | - if (! empty($existing_state)) { |
|
| 608 | - return array_pop($existing_state); |
|
| 609 | - } |
|
| 610 | - $new_state = EE_State::new_instance($props_n_values); |
|
| 611 | - if ($new_state instanceof EE_State) { |
|
| 612 | - $country_settings_url = add_query_arg( |
|
| 613 | - array( |
|
| 614 | - 'page' => 'espresso_general_settings', |
|
| 615 | - 'action' => 'country_settings', |
|
| 616 | - 'country' => $new_state->country_iso(), |
|
| 617 | - ), |
|
| 618 | - admin_url('admin.php') |
|
| 619 | - ); |
|
| 620 | - // if not non-ajax admin |
|
| 621 | - new PersistentAdminNotice( |
|
| 622 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 623 | - sprintf( |
|
| 624 | - esc_html__( |
|
| 625 | - 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 626 | - 'event_espresso' |
|
| 627 | - ), |
|
| 628 | - '<b>' . $new_state->name() . '</b>', |
|
| 629 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 630 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 631 | - '<a href="' |
|
| 632 | - . $country_settings_url |
|
| 633 | - . '">' |
|
| 634 | - . esc_html__( |
|
| 635 | - 'Event Espresso - General Settings > Countries Tab', |
|
| 636 | - 'event_espresso' |
|
| 637 | - ) |
|
| 638 | - . '</a>', |
|
| 639 | - '<br />' |
|
| 640 | - ) |
|
| 641 | - ); |
|
| 642 | - $new_state->save(); |
|
| 643 | - EEM_State::instance()->reset_cached_states(); |
|
| 644 | - return $new_state; |
|
| 645 | - } |
|
| 646 | - return false; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - |
|
| 650 | - /** |
|
| 651 | - * @param string $CNT_ISO |
|
| 652 | - * @param string $STA_ID |
|
| 653 | - * @param array $cols_n_values |
|
| 654 | - * @return void |
|
| 655 | - * @throws DomainException |
|
| 656 | - * @throws EE_Error |
|
| 657 | - * @throws InvalidArgumentException |
|
| 658 | - * @throws InvalidDataTypeException |
|
| 659 | - * @throws InvalidInterfaceException |
|
| 660 | - */ |
|
| 661 | - public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 662 | - { |
|
| 663 | - if (! $CNT_ISO) { |
|
| 664 | - EE_Error::add_error( |
|
| 665 | - esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 666 | - __FILE__, |
|
| 667 | - __FUNCTION__, |
|
| 668 | - __LINE__ |
|
| 669 | - ); |
|
| 670 | - } |
|
| 671 | - $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 672 | - : false; |
|
| 673 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 674 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 675 | - if ($state instanceof EE_State) { |
|
| 676 | - $STA_abbrev = $state->abbrev(); |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - if (! $STA_abbrev) { |
|
| 680 | - EE_Error::add_error( |
|
| 681 | - esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 682 | - __FILE__, |
|
| 683 | - __FUNCTION__, |
|
| 684 | - __LINE__ |
|
| 685 | - ); |
|
| 686 | - } |
|
| 687 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 688 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 689 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 690 | - ); |
|
| 691 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * @param EE_State[] $state_options |
|
| 697 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 698 | - * @param EE_Registration $registration |
|
| 699 | - * @param EE_Question $question |
|
| 700 | - * @param $answer |
|
| 701 | - * @return array |
|
| 702 | - * @throws EE_Error |
|
| 703 | - * @throws InvalidArgumentException |
|
| 704 | - * @throws InvalidDataTypeException |
|
| 705 | - * @throws InvalidInterfaceException |
|
| 706 | - */ |
|
| 707 | - public static function inject_new_reg_state_into_options( |
|
| 708 | - $state_options = array(), |
|
| 709 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 710 | - EE_Registration $registration, |
|
| 711 | - EE_Question $question, |
|
| 712 | - $answer |
|
| 713 | - ) { |
|
| 714 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 715 | - && $question->type() === EEM_Question::QST_type_state |
|
| 716 | - ) { |
|
| 717 | - $STA_ID = $answer->value(); |
|
| 718 | - if (! empty($STA_ID)) { |
|
| 719 | - $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 720 | - if ($state instanceof EE_State) { |
|
| 721 | - $country = $state->country(); |
|
| 722 | - if ($country instanceof EE_Country) { |
|
| 723 | - if (! isset($state_options[ $country->name() ])) { |
|
| 724 | - $state_options[ $country->name() ] = array(); |
|
| 725 | - } |
|
| 726 | - if (! isset($state_options[ $country->name() ][ $STA_ID ])) { |
|
| 727 | - $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
| 728 | - } |
|
| 729 | - } |
|
| 730 | - } |
|
| 731 | - } |
|
| 732 | - } |
|
| 733 | - return $state_options; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - |
|
| 737 | - /** |
|
| 738 | - * @param EE_Country[] $country_options |
|
| 739 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 740 | - * @param EE_Registration $registration |
|
| 741 | - * @param EE_Question $question |
|
| 742 | - * @param $answer |
|
| 743 | - * @return array |
|
| 744 | - * @throws EE_Error |
|
| 745 | - * @throws InvalidArgumentException |
|
| 746 | - * @throws InvalidDataTypeException |
|
| 747 | - * @throws InvalidInterfaceException |
|
| 748 | - */ |
|
| 749 | - public static function inject_new_reg_country_into_options( |
|
| 750 | - $country_options = array(), |
|
| 751 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 752 | - EE_Registration $registration, |
|
| 753 | - EE_Question $question, |
|
| 754 | - $answer |
|
| 755 | - ) { |
|
| 756 | - if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 757 | - && $question->type() |
|
| 758 | - === EEM_Question::QST_type_country |
|
| 759 | - ) { |
|
| 760 | - $CNT_ISO = $answer->value(); |
|
| 761 | - if (! empty($CNT_ISO)) { |
|
| 762 | - $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 763 | - if ($country instanceof EE_Country) { |
|
| 764 | - if (! isset($country_options[ $CNT_ISO ])) { |
|
| 765 | - $country_options[ $CNT_ISO ] = $country->name(); |
|
| 766 | - } |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - return $country_options; |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - |
|
| 774 | - /** |
|
| 775 | - * @param EE_State[] $state_options |
|
| 776 | - * @return array |
|
| 777 | - * @throws EE_Error |
|
| 778 | - * @throws InvalidArgumentException |
|
| 779 | - * @throws InvalidDataTypeException |
|
| 780 | - * @throws InvalidInterfaceException |
|
| 781 | - */ |
|
| 782 | - public static function state_options($state_options = array()) |
|
| 783 | - { |
|
| 784 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 785 | - foreach ($new_states as $new_state) { |
|
| 786 | - if ($new_state instanceof EE_State |
|
| 787 | - && $new_state->country() instanceof EE_Country |
|
| 788 | - ) { |
|
| 789 | - $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - return $state_options; |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - |
|
| 796 | - /** |
|
| 797 | - * @return array |
|
| 798 | - * @throws InvalidArgumentException |
|
| 799 | - * @throws InvalidDataTypeException |
|
| 800 | - * @throws InvalidInterfaceException |
|
| 801 | - */ |
|
| 802 | - protected static function _get_new_states() |
|
| 803 | - { |
|
| 804 | - $new_states = array(); |
|
| 805 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 806 | - $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 807 | - 'nsmf_new_states' |
|
| 808 | - ); |
|
| 809 | - } |
|
| 810 | - return is_array($new_states) ? $new_states : array(); |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * @param EE_Country[] $country_options |
|
| 816 | - * @return array |
|
| 817 | - * @throws EE_Error |
|
| 818 | - * @throws InvalidArgumentException |
|
| 819 | - * @throws InvalidDataTypeException |
|
| 820 | - * @throws InvalidInterfaceException |
|
| 821 | - */ |
|
| 822 | - public static function country_options($country_options = array()) |
|
| 823 | - { |
|
| 824 | - $new_states = EED_Add_New_State::_get_new_states(); |
|
| 825 | - foreach ($new_states as $new_state) { |
|
| 826 | - if ($new_state instanceof EE_State |
|
| 827 | - && $new_state->country() instanceof EE_Country |
|
| 828 | - ) { |
|
| 829 | - $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
| 830 | - } |
|
| 831 | - } |
|
| 832 | - return $country_options; |
|
| 833 | - } |
|
| 20 | + /** |
|
| 21 | + * @return EED_Module|EED_Add_New_State |
|
| 22 | + */ |
|
| 23 | + public static function instance() |
|
| 24 | + { |
|
| 25 | + return parent::get_instance(__CLASS__); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
| 31 | + * |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + public static function set_hooks() |
|
| 35 | + { |
|
| 36 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 37 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'translate_js_strings'), 0); |
|
| 38 | + add_action('wp_enqueue_scripts', array('EED_Add_New_State', 'wp_enqueue_scripts'), 10); |
|
| 39 | + add_filter( |
|
| 40 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 41 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 42 | + 1, |
|
| 43 | + 1 |
|
| 44 | + ); |
|
| 45 | + add_filter( |
|
| 46 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 47 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 48 | + 1, |
|
| 49 | + 1 |
|
| 50 | + ); |
|
| 51 | + add_filter( |
|
| 52 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 53 | + array('EED_Add_New_State', 'unset_new_state_request_params'), |
|
| 54 | + 10, |
|
| 55 | + 1 |
|
| 56 | + ); |
|
| 57 | + add_filter( |
|
| 58 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 59 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), |
|
| 60 | + 10, |
|
| 61 | + 5 |
|
| 62 | + ); |
|
| 63 | + add_filter( |
|
| 64 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 65 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), |
|
| 66 | + 10, |
|
| 67 | + 5 |
|
| 68 | + ); |
|
| 69 | + add_filter( |
|
| 70 | + 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 71 | + array('EED_Add_New_State', 'state_options'), |
|
| 72 | + 10, |
|
| 73 | + 1 |
|
| 74 | + ); |
|
| 75 | + add_filter( |
|
| 76 | + 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 77 | + array('EED_Add_New_State', 'country_options'), |
|
| 78 | + 10, |
|
| 79 | + 1 |
|
| 80 | + ); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
| 86 | + * |
|
| 87 | + * @return void |
|
| 88 | + */ |
|
| 89 | + public static function set_hooks_admin() |
|
| 90 | + { |
|
| 91 | + add_action('wp_loaded', array('EED_Add_New_State', 'set_definitions'), 2); |
|
| 92 | + add_filter( |
|
| 93 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
|
| 94 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 95 | + 1, |
|
| 96 | + 1 |
|
| 97 | + ); |
|
| 98 | + add_filter( |
|
| 99 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options___get_billing_form_for_payment_method__billing_form', |
|
| 100 | + array('EED_Add_New_State', 'display_add_new_state_micro_form'), |
|
| 101 | + 1, |
|
| 102 | + 1 |
|
| 103 | + ); |
|
| 104 | + add_action('wp_ajax_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 105 | + add_action('wp_ajax_nopriv_espresso_add_new_state', array('EED_Add_New_State', 'add_new_state')); |
|
| 106 | + add_filter( |
|
| 107 | + 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
|
| 108 | + array('EED_Add_New_State', 'unset_new_state_request_params'), |
|
| 109 | + 10, |
|
| 110 | + 1 |
|
| 111 | + ); |
|
| 112 | + add_action( |
|
| 113 | + 'AHEE__General_Settings_Admin_Page__update_country_settings__state_saved', |
|
| 114 | + array('EED_Add_New_State', 'update_country_settings'), |
|
| 115 | + 10, |
|
| 116 | + 3 |
|
| 117 | + ); |
|
| 118 | + add_action( |
|
| 119 | + 'AHEE__General_Settings_Admin_Page__delete_state__state_deleted', |
|
| 120 | + array('EED_Add_New_State', 'update_country_settings'), |
|
| 121 | + 10, |
|
| 122 | + 3 |
|
| 123 | + ); |
|
| 124 | + add_filter( |
|
| 125 | + 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 126 | + array('EED_Add_New_State', 'state_options'), |
|
| 127 | + 10, |
|
| 128 | + 1 |
|
| 129 | + ); |
|
| 130 | + add_filter( |
|
| 131 | + 'FHEE__EE_Country_Select_Input____construct__country_options', |
|
| 132 | + array('EED_Add_New_State', 'country_options'), |
|
| 133 | + 10, |
|
| 134 | + 1 |
|
| 135 | + ); |
|
| 136 | + add_filter( |
|
| 137 | + 'FHEE__EE_Form_Section_Proper__receive_form_submission__request_data', |
|
| 138 | + array('EED_Add_New_State', 'filter_checkout_request_params'), |
|
| 139 | + 10, |
|
| 140 | + 1 |
|
| 141 | + ); |
|
| 142 | + add_filter( |
|
| 143 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__state_options', |
|
| 144 | + array('EED_Add_New_State', 'inject_new_reg_state_into_options'), |
|
| 145 | + 10, |
|
| 146 | + 5 |
|
| 147 | + ); |
|
| 148 | + add_filter( |
|
| 149 | + 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__country_options', |
|
| 150 | + array('EED_Add_New_State', 'inject_new_reg_country_into_options'), |
|
| 151 | + 10, |
|
| 152 | + 5 |
|
| 153 | + ); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * @return void |
|
| 159 | + */ |
|
| 160 | + public static function set_definitions() |
|
| 161 | + { |
|
| 162 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 163 | + define( |
|
| 164 | + 'ANS_TEMPLATES_PATH', |
|
| 165 | + str_replace( |
|
| 166 | + '\\', |
|
| 167 | + DS, |
|
| 168 | + plugin_dir_path(__FILE__) |
|
| 169 | + ) . 'templates' . DS |
|
| 170 | + ); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * @param WP $WP |
|
| 176 | + * @return void |
|
| 177 | + */ |
|
| 178 | + public function run($WP) |
|
| 179 | + { |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * @return void |
|
| 185 | + */ |
|
| 186 | + public static function translate_js_strings() |
|
| 187 | + { |
|
| 188 | + EE_Registry::$i18n_js_strings['ans_no_country'] = esc_html__( |
|
| 189 | + 'In order to proceed, you need to select the Country that your State/Province belongs to.', |
|
| 190 | + 'event_espresso' |
|
| 191 | + ); |
|
| 192 | + EE_Registry::$i18n_js_strings['ans_no_name'] = esc_html__( |
|
| 193 | + 'In order to proceed, you need to enter the name of your State/Province.', |
|
| 194 | + 'event_espresso' |
|
| 195 | + ); |
|
| 196 | + EE_Registry::$i18n_js_strings['ans_no_abbreviation'] = esc_html__( |
|
| 197 | + 'In order to proceed, you need to enter an abbreviation for the name of your State/Province.', |
|
| 198 | + 'event_espresso' |
|
| 199 | + ); |
|
| 200 | + EE_Registry::$i18n_js_strings['ans_save_success'] = esc_html__( |
|
| 201 | + 'The new state was successfully saved to the database.', |
|
| 202 | + 'event_espresso' |
|
| 203 | + ); |
|
| 204 | + EE_Registry::$i18n_js_strings['ans_server_save_error'] = esc_html__( |
|
| 205 | + 'An unknown error has occurred on the server while saving the new state to the database.', |
|
| 206 | + 'event_espresso' |
|
| 207 | + ); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * @return void |
|
| 213 | + */ |
|
| 214 | + public static function wp_enqueue_scripts() |
|
| 215 | + { |
|
| 216 | + if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
|
| 217 | + wp_register_script( |
|
| 218 | + 'add_new_state', |
|
| 219 | + ANS_ASSETS_URL . 'add_new_state.js', |
|
| 220 | + array('espresso_core', 'single_page_checkout'), |
|
| 221 | + EVENT_ESPRESSO_VERSION, |
|
| 222 | + true |
|
| 223 | + ); |
|
| 224 | + wp_enqueue_script('add_new_state'); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * display_add_new_state_micro_form |
|
| 232 | + * |
|
| 233 | + * @param EE_Form_Section_Proper $question_group_reg_form |
|
| 234 | + * @return string |
|
| 235 | + * @throws EE_Error |
|
| 236 | + * @throws InvalidArgumentException |
|
| 237 | + * @throws InvalidDataTypeException |
|
| 238 | + * @throws InvalidInterfaceException |
|
| 239 | + */ |
|
| 240 | + public static function display_add_new_state_micro_form(EE_Form_Section_Proper $question_group_reg_form) |
|
| 241 | + { |
|
| 242 | + // only add the 'new_state_micro_form' when displaying reg forms, |
|
| 243 | + // not during processing since we process the 'new_state_micro_form' in it's own AJAX request |
|
| 244 | + $action = EE_Registry::instance()->REQ->get('action', ''); |
|
| 245 | + // is the "state" question in this form section? |
|
| 246 | + $input = $question_group_reg_form->get_subsection('state'); |
|
| 247 | + if ($action === 'process_reg_step' || $action === 'update_reg_step') { |
|
| 248 | + // ok then all we need to do is make sure the input's HTML name is consistent |
|
| 249 | + // by forcing it to set it now, like it did while getting the form for display |
|
| 250 | + if ($input instanceof EE_State_Select_Input) { |
|
| 251 | + $input->html_name(); |
|
| 252 | + } |
|
| 253 | + return $question_group_reg_form; |
|
| 254 | + } |
|
| 255 | + // we're only doing this for state select inputs |
|
| 256 | + if ($input instanceof EE_State_Select_Input |
|
| 257 | + && ! $input->get_display_strategy() instanceof EE_Hidden_Display_Strategy |
|
| 258 | + ) { |
|
| 259 | + // grab any set values from the request |
|
| 260 | + $country_name = str_replace('state', 'nsmf_new_state_country', $input->html_name()); |
|
| 261 | + $state_name = str_replace('state', 'nsmf_new_state_name', $input->html_name()); |
|
| 262 | + $abbrv_name = str_replace('state', 'nsmf_new_state_abbrv', $input->html_name()); |
|
| 263 | + $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
|
| 264 | + $country_options = array(); |
|
| 265 | + $countries = EEM_Country::instance()->get_all_countries(); |
|
| 266 | + if (! empty($countries)) { |
|
| 267 | + foreach ($countries as $country) { |
|
| 268 | + if ($country instanceof EE_Country) { |
|
| 269 | + $country_options[ $country->ID() ] = $country->name(); |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + $new_state_micro_form = new EE_Form_Section_Proper( |
|
| 274 | + array( |
|
| 275 | + 'name' => 'new_state_micro_form', |
|
| 276 | + 'html_id' => 'new_state_micro_form', |
|
| 277 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
| 278 | + 'subsections' => array( |
|
| 279 | + // add hidden input to indicate that a new state is being added |
|
| 280 | + 'add_new_state' => new EE_Hidden_Input( |
|
| 281 | + array( |
|
| 282 | + 'html_name' => str_replace( |
|
| 283 | + 'state', |
|
| 284 | + 'nsmf_add_new_state', |
|
| 285 | + $input->html_name() |
|
| 286 | + ), |
|
| 287 | + 'html_id' => str_replace( |
|
| 288 | + 'state', |
|
| 289 | + 'nsmf_add_new_state', |
|
| 290 | + $input->html_id() |
|
| 291 | + ), |
|
| 292 | + 'default' => 0, |
|
| 293 | + ) |
|
| 294 | + ), |
|
| 295 | + // add link for displaying hidden container |
|
| 296 | + 'click_here_link' => new EE_Form_Section_HTML( |
|
| 297 | + apply_filters( |
|
| 298 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__click_here_link', |
|
| 299 | + EEH_HTML::link( |
|
| 300 | + '', |
|
| 301 | + esc_html__('click here to add a new state/province', 'event_espresso'), |
|
| 302 | + '', |
|
| 303 | + 'display-' . $input->html_id(), |
|
| 304 | + 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
|
| 305 | + '', |
|
| 306 | + 'data-target="' . $input->html_id() . '"' |
|
| 307 | + ) |
|
| 308 | + ) |
|
| 309 | + ), |
|
| 310 | + // add initial html for hidden container |
|
| 311 | + 'add_new_state_micro_form' => new EE_Form_Section_HTML( |
|
| 312 | + apply_filters( |
|
| 313 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
|
| 314 | + EEH_HTML::div( |
|
| 315 | + '', |
|
| 316 | + $input->html_id() . '-dv', |
|
| 317 | + 'ee-form-add-new-state-dv', |
|
| 318 | + 'display: none;' |
|
| 319 | + ) . |
|
| 320 | + EEH_HTML::h6( |
|
| 321 | + esc_html__( |
|
| 322 | + 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
|
| 323 | + 'event_espresso' |
|
| 324 | + ) |
|
| 325 | + ) . |
|
| 326 | + EEH_HTML::ul() . |
|
| 327 | + EEH_HTML::li( |
|
| 328 | + esc_html__( |
|
| 329 | + 'first select the Country that your State/Province belongs to', |
|
| 330 | + 'event_espresso' |
|
| 331 | + ) |
|
| 332 | + ) . |
|
| 333 | + EEH_HTML::li( |
|
| 334 | + esc_html__('enter the name of your State/Province', 'event_espresso') |
|
| 335 | + ) . |
|
| 336 | + EEH_HTML::li( |
|
| 337 | + esc_html__( |
|
| 338 | + 'enter a two to six letter abbreviation for the name of your State/Province', |
|
| 339 | + 'event_espresso' |
|
| 340 | + ) |
|
| 341 | + ) . |
|
| 342 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 343 | + EEH_HTML::ulx() |
|
| 344 | + ) |
|
| 345 | + ), |
|
| 346 | + // NEW STATE COUNTRY |
|
| 347 | + 'new_state_country' => new EE_Country_Select_Input( |
|
| 348 | + $country_options, |
|
| 349 | + array( |
|
| 350 | + 'html_name' => $country_name, |
|
| 351 | + 'html_id' => str_replace( |
|
| 352 | + 'state', |
|
| 353 | + 'nsmf_new_state_country', |
|
| 354 | + $input->html_id() |
|
| 355 | + ), |
|
| 356 | + 'html_class' => $input->html_class() . ' new-state-country', |
|
| 357 | + 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
|
| 358 | + 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
|
| 359 | + 'required' => false, |
|
| 360 | + ) |
|
| 361 | + ), |
|
| 362 | + // NEW STATE NAME |
|
| 363 | + 'new_state_name' => new EE_Text_Input( |
|
| 364 | + array( |
|
| 365 | + 'html_name' => $state_name, |
|
| 366 | + 'html_id' => str_replace( |
|
| 367 | + 'state', |
|
| 368 | + 'nsmf_new_state_name', |
|
| 369 | + $input->html_id() |
|
| 370 | + ), |
|
| 371 | + 'html_class' => $input->html_class() . ' new-state-state', |
|
| 372 | + 'html_label_text' => esc_html__( |
|
| 373 | + 'New State/Province Name', |
|
| 374 | + 'event_espresso' |
|
| 375 | + ), |
|
| 376 | + 'default' => EE_Registry::instance()->REQ->get($state_name, ''), |
|
| 377 | + 'required' => false, |
|
| 378 | + ) |
|
| 379 | + ), |
|
| 380 | + 'spacer' => new EE_Form_Section_HTML(EEH_HTML::br()), |
|
| 381 | + // NEW STATE NAME |
|
| 382 | + 'new_state_abbrv' => new EE_Text_Input( |
|
| 383 | + array( |
|
| 384 | + 'html_name' => $abbrv_name, |
|
| 385 | + 'html_id' => str_replace( |
|
| 386 | + 'state', |
|
| 387 | + 'nsmf_new_state_abbrv', |
|
| 388 | + $input->html_id() |
|
| 389 | + ), |
|
| 390 | + 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 391 | + 'html_label_text' => esc_html__( |
|
| 392 | + 'New State/Province Abbreviation', |
|
| 393 | + 'event_espresso' |
|
| 394 | + ) . ' *', |
|
| 395 | + 'html_other_attributes' => 'size="24"', |
|
| 396 | + 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
|
| 397 | + 'required' => false, |
|
| 398 | + ) |
|
| 399 | + ), |
|
| 400 | + // "submit" button |
|
| 401 | + 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
|
| 402 | + apply_filters( |
|
| 403 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
|
| 404 | + EEH_HTML::nbsp(3) . |
|
| 405 | + EEH_HTML::link( |
|
| 406 | + '', |
|
| 407 | + esc_html__('ADD', 'event_espresso'), |
|
| 408 | + '', |
|
| 409 | + 'submit-' . $new_state_submit_id, |
|
| 410 | + 'ee-form-add-new-state-submit button button-secondary', |
|
| 411 | + '', |
|
| 412 | + 'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"' |
|
| 413 | + ) |
|
| 414 | + ) |
|
| 415 | + ), |
|
| 416 | + // extra info |
|
| 417 | + 'add_new_state_extra' => new EE_Form_Section_HTML( |
|
| 418 | + apply_filters( |
|
| 419 | + 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_extra', |
|
| 420 | + EEH_HTML::br(2) |
|
| 421 | + . |
|
| 422 | + EEH_HTML::div('', '', 'small-text') |
|
| 423 | + . |
|
| 424 | + EEH_HTML::strong( |
|
| 425 | + '* ' . |
|
| 426 | + esc_html__( |
|
| 427 | + 'Don\'t know your State/Province Abbreviation?', |
|
| 428 | + 'event_espresso' |
|
| 429 | + ) |
|
| 430 | + ) |
|
| 431 | + . |
|
| 432 | + EEH_HTML::br() |
|
| 433 | + . |
|
| 434 | + sprintf( |
|
| 435 | + esc_html__( |
|
| 436 | + 'You can look here: %s, for a list of Countries and links to their State/Province Abbreviations ("Subdivisions assigned codes" column).', |
|
| 437 | + 'event_espresso' |
|
| 438 | + ), |
|
| 439 | + EEH_HTML::link( |
|
| 440 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 441 | + 'http://en.wikipedia.org/wiki/ISO_3166-2', |
|
| 442 | + '', |
|
| 443 | + '', |
|
| 444 | + 'ee-form-add-new-state-wiki-lnk', |
|
| 445 | + '', |
|
| 446 | + 'target="_blank"' |
|
| 447 | + ) |
|
| 448 | + ) |
|
| 449 | + . |
|
| 450 | + EEH_HTML::divx() |
|
| 451 | + . |
|
| 452 | + EEH_HTML::br() |
|
| 453 | + . |
|
| 454 | + EEH_HTML::link( |
|
| 455 | + '', |
|
| 456 | + esc_html__('cancel new State/Province', 'event_espresso'), |
|
| 457 | + '', |
|
| 458 | + 'hide-' . $input->html_id(), |
|
| 459 | + 'ee-form-cancel-new-state-lnk smaller-text', |
|
| 460 | + '', |
|
| 461 | + 'data-target="' . $input->html_id() . '"' |
|
| 462 | + ) |
|
| 463 | + . |
|
| 464 | + EEH_HTML::divx() |
|
| 465 | + . |
|
| 466 | + EEH_HTML::br() |
|
| 467 | + ) |
|
| 468 | + ), |
|
| 469 | + ), |
|
| 470 | + ) |
|
| 471 | + ); |
|
| 472 | + $question_group_reg_form->add_subsections( |
|
| 473 | + array('new_state_micro_form' => $new_state_micro_form), |
|
| 474 | + 'state', |
|
| 475 | + false |
|
| 476 | + ); |
|
| 477 | + } |
|
| 478 | + return $question_group_reg_form; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * set_new_state_input_width |
|
| 484 | + * |
|
| 485 | + * @return int|string |
|
| 486 | + * @throws EE_Error |
|
| 487 | + * @throws InvalidArgumentException |
|
| 488 | + * @throws InvalidDataTypeException |
|
| 489 | + * @throws InvalidInterfaceException |
|
| 490 | + * @throws ReflectionException |
|
| 491 | + */ |
|
| 492 | + public static function add_new_state() |
|
| 493 | + { |
|
| 494 | + $REQ = EE_Registry::instance()->load_core('Request_Handler'); |
|
| 495 | + if (absint($REQ->get('nsmf_add_new_state')) === 1) { |
|
| 496 | + EE_Registry::instance()->load_model('State'); |
|
| 497 | + // grab country ISO code, new state name, and new state abbreviation |
|
| 498 | + $state_country = $REQ->is_set('nsmf_new_state_country') |
|
| 499 | + ? sanitize_text_field($REQ->get('nsmf_new_state_country')) |
|
| 500 | + : false; |
|
| 501 | + $state_name = $REQ->is_set('nsmf_new_state_name') |
|
| 502 | + ? sanitize_text_field($REQ->get('nsmf_new_state_name')) |
|
| 503 | + : false; |
|
| 504 | + $state_abbr = $REQ->is_set('nsmf_new_state_abbrv') |
|
| 505 | + ? sanitize_text_field($REQ->get('nsmf_new_state_abbrv')) |
|
| 506 | + : false; |
|
| 507 | + if ($state_country && $state_name && $state_abbr) { |
|
| 508 | + $new_state = EED_Add_New_State::save_new_state_to_db( |
|
| 509 | + array( |
|
| 510 | + 'CNT_ISO' => strtoupper($state_country), |
|
| 511 | + 'STA_abbrev' => strtoupper($state_abbr), |
|
| 512 | + 'STA_name' => ucwords($state_name), |
|
| 513 | + 'STA_active' => false, |
|
| 514 | + ) |
|
| 515 | + ); |
|
| 516 | + if ($new_state instanceof EE_State) { |
|
| 517 | + // clean house |
|
| 518 | + EE_Registry::instance()->REQ->un_set('nsmf_add_new_state'); |
|
| 519 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_country'); |
|
| 520 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_name'); |
|
| 521 | + EE_Registry::instance()->REQ->un_set('nsmf_new_state_abbrv'); |
|
| 522 | + // get any existing new states |
|
| 523 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 524 | + 'nsmf_new_states' |
|
| 525 | + ); |
|
| 526 | + $new_states[ $new_state->ID() ] = $new_state; |
|
| 527 | + EE_Registry::instance()->SSN->set_session_data( |
|
| 528 | + array('nsmf_new_states' => $new_states) |
|
| 529 | + ); |
|
| 530 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 531 | + echo wp_json_encode( |
|
| 532 | + array( |
|
| 533 | + 'success' => true, |
|
| 534 | + 'id' => $new_state->ID(), |
|
| 535 | + 'name' => $new_state->name(), |
|
| 536 | + 'abbrev' => $new_state->abbrev(), |
|
| 537 | + 'country_iso' => $new_state->country_iso(), |
|
| 538 | + 'country_name' => $new_state->country()->name(), |
|
| 539 | + ) |
|
| 540 | + ); |
|
| 541 | + exit(); |
|
| 542 | + } |
|
| 543 | + return $new_state->ID(); |
|
| 544 | + } |
|
| 545 | + } else { |
|
| 546 | + $error = esc_html__( |
|
| 547 | + 'A new State/Province could not be added because invalid or missing data was received.', |
|
| 548 | + 'event_espresso' |
|
| 549 | + ); |
|
| 550 | + if (EE_Registry::instance()->REQ->ajax) { |
|
| 551 | + echo wp_json_encode(array('error' => $error)); |
|
| 552 | + exit(); |
|
| 553 | + } |
|
| 554 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + return false; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + |
|
| 561 | + /** |
|
| 562 | + * recursively drills down through request params to remove any that were added by this module |
|
| 563 | + * |
|
| 564 | + * @param array $request_params |
|
| 565 | + * @return array |
|
| 566 | + */ |
|
| 567 | + public static function filter_checkout_request_params($request_params) |
|
| 568 | + { |
|
| 569 | + foreach ($request_params as $form_section) { |
|
| 570 | + if (is_array($form_section)) { |
|
| 571 | + EED_Add_New_State::unset_new_state_request_params($form_section); |
|
| 572 | + EED_Add_New_State::filter_checkout_request_params($form_section); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + return $request_params; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + |
|
| 579 | + /** |
|
| 580 | + * @param array $request_params |
|
| 581 | + * @return array |
|
| 582 | + */ |
|
| 583 | + public static function unset_new_state_request_params($request_params) |
|
| 584 | + { |
|
| 585 | + unset( |
|
| 586 | + $request_params['new_state_micro_form'], |
|
| 587 | + $request_params['new_state_micro_add_new_state'], |
|
| 588 | + $request_params['new_state_micro_new_state_country'], |
|
| 589 | + $request_params['new_state_micro_new_state_name'], |
|
| 590 | + $request_params['new_state_micro_new_state_abbrv'] |
|
| 591 | + ); |
|
| 592 | + return $request_params; |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * @param array $props_n_values |
|
| 598 | + * @return bool |
|
| 599 | + * @throws EE_Error |
|
| 600 | + * @throws InvalidArgumentException |
|
| 601 | + * @throws InvalidDataTypeException |
|
| 602 | + * @throws InvalidInterfaceException |
|
| 603 | + */ |
|
| 604 | + public static function save_new_state_to_db($props_n_values = array()) |
|
| 605 | + { |
|
| 606 | + $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
|
| 607 | + if (! empty($existing_state)) { |
|
| 608 | + return array_pop($existing_state); |
|
| 609 | + } |
|
| 610 | + $new_state = EE_State::new_instance($props_n_values); |
|
| 611 | + if ($new_state instanceof EE_State) { |
|
| 612 | + $country_settings_url = add_query_arg( |
|
| 613 | + array( |
|
| 614 | + 'page' => 'espresso_general_settings', |
|
| 615 | + 'action' => 'country_settings', |
|
| 616 | + 'country' => $new_state->country_iso(), |
|
| 617 | + ), |
|
| 618 | + admin_url('admin.php') |
|
| 619 | + ); |
|
| 620 | + // if not non-ajax admin |
|
| 621 | + new PersistentAdminNotice( |
|
| 622 | + 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 623 | + sprintf( |
|
| 624 | + esc_html__( |
|
| 625 | + 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
|
| 626 | + 'event_espresso' |
|
| 627 | + ), |
|
| 628 | + '<b>' . $new_state->name() . '</b>', |
|
| 629 | + '<b>' . $new_state->abbrev() . '</b>', |
|
| 630 | + '<b>' . $new_state->country()->name() . '</b>', |
|
| 631 | + '<a href="' |
|
| 632 | + . $country_settings_url |
|
| 633 | + . '">' |
|
| 634 | + . esc_html__( |
|
| 635 | + 'Event Espresso - General Settings > Countries Tab', |
|
| 636 | + 'event_espresso' |
|
| 637 | + ) |
|
| 638 | + . '</a>', |
|
| 639 | + '<br />' |
|
| 640 | + ) |
|
| 641 | + ); |
|
| 642 | + $new_state->save(); |
|
| 643 | + EEM_State::instance()->reset_cached_states(); |
|
| 644 | + return $new_state; |
|
| 645 | + } |
|
| 646 | + return false; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + |
|
| 650 | + /** |
|
| 651 | + * @param string $CNT_ISO |
|
| 652 | + * @param string $STA_ID |
|
| 653 | + * @param array $cols_n_values |
|
| 654 | + * @return void |
|
| 655 | + * @throws DomainException |
|
| 656 | + * @throws EE_Error |
|
| 657 | + * @throws InvalidArgumentException |
|
| 658 | + * @throws InvalidDataTypeException |
|
| 659 | + * @throws InvalidInterfaceException |
|
| 660 | + */ |
|
| 661 | + public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
|
| 662 | + { |
|
| 663 | + if (! $CNT_ISO) { |
|
| 664 | + EE_Error::add_error( |
|
| 665 | + esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
|
| 666 | + __FILE__, |
|
| 667 | + __FUNCTION__, |
|
| 668 | + __LINE__ |
|
| 669 | + ); |
|
| 670 | + } |
|
| 671 | + $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
|
| 672 | + : false; |
|
| 673 | + if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 674 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 675 | + if ($state instanceof EE_State) { |
|
| 676 | + $STA_abbrev = $state->abbrev(); |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + if (! $STA_abbrev) { |
|
| 680 | + EE_Error::add_error( |
|
| 681 | + esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
|
| 682 | + __FILE__, |
|
| 683 | + __FUNCTION__, |
|
| 684 | + __LINE__ |
|
| 685 | + ); |
|
| 686 | + } |
|
| 687 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
| 688 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
| 689 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
| 690 | + ); |
|
| 691 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * @param EE_State[] $state_options |
|
| 697 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 698 | + * @param EE_Registration $registration |
|
| 699 | + * @param EE_Question $question |
|
| 700 | + * @param $answer |
|
| 701 | + * @return array |
|
| 702 | + * @throws EE_Error |
|
| 703 | + * @throws InvalidArgumentException |
|
| 704 | + * @throws InvalidDataTypeException |
|
| 705 | + * @throws InvalidInterfaceException |
|
| 706 | + */ |
|
| 707 | + public static function inject_new_reg_state_into_options( |
|
| 708 | + $state_options = array(), |
|
| 709 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 710 | + EE_Registration $registration, |
|
| 711 | + EE_Question $question, |
|
| 712 | + $answer |
|
| 713 | + ) { |
|
| 714 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 715 | + && $question->type() === EEM_Question::QST_type_state |
|
| 716 | + ) { |
|
| 717 | + $STA_ID = $answer->value(); |
|
| 718 | + if (! empty($STA_ID)) { |
|
| 719 | + $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
|
| 720 | + if ($state instanceof EE_State) { |
|
| 721 | + $country = $state->country(); |
|
| 722 | + if ($country instanceof EE_Country) { |
|
| 723 | + if (! isset($state_options[ $country->name() ])) { |
|
| 724 | + $state_options[ $country->name() ] = array(); |
|
| 725 | + } |
|
| 726 | + if (! isset($state_options[ $country->name() ][ $STA_ID ])) { |
|
| 727 | + $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
| 728 | + } |
|
| 729 | + } |
|
| 730 | + } |
|
| 731 | + } |
|
| 732 | + } |
|
| 733 | + return $state_options; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + |
|
| 737 | + /** |
|
| 738 | + * @param EE_Country[] $country_options |
|
| 739 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
| 740 | + * @param EE_Registration $registration |
|
| 741 | + * @param EE_Question $question |
|
| 742 | + * @param $answer |
|
| 743 | + * @return array |
|
| 744 | + * @throws EE_Error |
|
| 745 | + * @throws InvalidArgumentException |
|
| 746 | + * @throws InvalidDataTypeException |
|
| 747 | + * @throws InvalidInterfaceException |
|
| 748 | + */ |
|
| 749 | + public static function inject_new_reg_country_into_options( |
|
| 750 | + $country_options = array(), |
|
| 751 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
| 752 | + EE_Registration $registration, |
|
| 753 | + EE_Question $question, |
|
| 754 | + $answer |
|
| 755 | + ) { |
|
| 756 | + if ($answer instanceof EE_Answer && $question instanceof EE_Question |
|
| 757 | + && $question->type() |
|
| 758 | + === EEM_Question::QST_type_country |
|
| 759 | + ) { |
|
| 760 | + $CNT_ISO = $answer->value(); |
|
| 761 | + if (! empty($CNT_ISO)) { |
|
| 762 | + $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
|
| 763 | + if ($country instanceof EE_Country) { |
|
| 764 | + if (! isset($country_options[ $CNT_ISO ])) { |
|
| 765 | + $country_options[ $CNT_ISO ] = $country->name(); |
|
| 766 | + } |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + return $country_options; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + |
|
| 774 | + /** |
|
| 775 | + * @param EE_State[] $state_options |
|
| 776 | + * @return array |
|
| 777 | + * @throws EE_Error |
|
| 778 | + * @throws InvalidArgumentException |
|
| 779 | + * @throws InvalidDataTypeException |
|
| 780 | + * @throws InvalidInterfaceException |
|
| 781 | + */ |
|
| 782 | + public static function state_options($state_options = array()) |
|
| 783 | + { |
|
| 784 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 785 | + foreach ($new_states as $new_state) { |
|
| 786 | + if ($new_state instanceof EE_State |
|
| 787 | + && $new_state->country() instanceof EE_Country |
|
| 788 | + ) { |
|
| 789 | + $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + return $state_options; |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + |
|
| 796 | + /** |
|
| 797 | + * @return array |
|
| 798 | + * @throws InvalidArgumentException |
|
| 799 | + * @throws InvalidDataTypeException |
|
| 800 | + * @throws InvalidInterfaceException |
|
| 801 | + */ |
|
| 802 | + protected static function _get_new_states() |
|
| 803 | + { |
|
| 804 | + $new_states = array(); |
|
| 805 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
| 806 | + $new_states = EE_Registry::instance()->SSN->get_session_data( |
|
| 807 | + 'nsmf_new_states' |
|
| 808 | + ); |
|
| 809 | + } |
|
| 810 | + return is_array($new_states) ? $new_states : array(); |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * @param EE_Country[] $country_options |
|
| 816 | + * @return array |
|
| 817 | + * @throws EE_Error |
|
| 818 | + * @throws InvalidArgumentException |
|
| 819 | + * @throws InvalidDataTypeException |
|
| 820 | + * @throws InvalidInterfaceException |
|
| 821 | + */ |
|
| 822 | + public static function country_options($country_options = array()) |
|
| 823 | + { |
|
| 824 | + $new_states = EED_Add_New_State::_get_new_states(); |
|
| 825 | + foreach ($new_states as $new_state) { |
|
| 826 | + if ($new_state instanceof EE_State |
|
| 827 | + && $new_state->country() instanceof EE_Country |
|
| 828 | + ) { |
|
| 829 | + $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
| 830 | + } |
|
| 831 | + } |
|
| 832 | + return $country_options; |
|
| 833 | + } |
|
| 834 | 834 | } |
@@ -159,14 +159,14 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | public static function set_definitions() |
| 161 | 161 | { |
| 162 | - define('ANS_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets' . DS); |
|
| 162 | + define('ANS_ASSETS_URL', plugin_dir_url(__FILE__).'assets'.DS); |
|
| 163 | 163 | define( |
| 164 | 164 | 'ANS_TEMPLATES_PATH', |
| 165 | 165 | str_replace( |
| 166 | 166 | '\\', |
| 167 | 167 | DS, |
| 168 | 168 | plugin_dir_path(__FILE__) |
| 169 | - ) . 'templates' . DS |
|
| 169 | + ).'templates'.DS |
|
| 170 | 170 | ); |
| 171 | 171 | } |
| 172 | 172 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | if (apply_filters('EED_Single_Page_Checkout__SPCO_active', false)) { |
| 217 | 217 | wp_register_script( |
| 218 | 218 | 'add_new_state', |
| 219 | - ANS_ASSETS_URL . 'add_new_state.js', |
|
| 219 | + ANS_ASSETS_URL.'add_new_state.js', |
|
| 220 | 220 | array('espresso_core', 'single_page_checkout'), |
| 221 | 221 | EVENT_ESPRESSO_VERSION, |
| 222 | 222 | true |
@@ -263,10 +263,10 @@ discard block |
||
| 263 | 263 | $new_state_submit_id = str_replace('state', 'new_state', $input->html_id()); |
| 264 | 264 | $country_options = array(); |
| 265 | 265 | $countries = EEM_Country::instance()->get_all_countries(); |
| 266 | - if (! empty($countries)) { |
|
| 266 | + if ( ! empty($countries)) { |
|
| 267 | 267 | foreach ($countries as $country) { |
| 268 | 268 | if ($country instanceof EE_Country) { |
| 269 | - $country_options[ $country->ID() ] = $country->name(); |
|
| 269 | + $country_options[$country->ID()] = $country->name(); |
|
| 270 | 270 | } |
| 271 | 271 | } |
| 272 | 272 | } |
@@ -300,10 +300,10 @@ discard block |
||
| 300 | 300 | '', |
| 301 | 301 | esc_html__('click here to add a new state/province', 'event_espresso'), |
| 302 | 302 | '', |
| 303 | - 'display-' . $input->html_id(), |
|
| 303 | + 'display-'.$input->html_id(), |
|
| 304 | 304 | 'ee-form-add-new-state-lnk display-the-hidden smaller-text hide-if-no-js', |
| 305 | 305 | '', |
| 306 | - 'data-target="' . $input->html_id() . '"' |
|
| 306 | + 'data-target="'.$input->html_id().'"' |
|
| 307 | 307 | ) |
| 308 | 308 | ) |
| 309 | 309 | ), |
@@ -313,33 +313,33 @@ discard block |
||
| 313 | 313 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_micro_form', |
| 314 | 314 | EEH_HTML::div( |
| 315 | 315 | '', |
| 316 | - $input->html_id() . '-dv', |
|
| 316 | + $input->html_id().'-dv', |
|
| 317 | 317 | 'ee-form-add-new-state-dv', |
| 318 | 318 | 'display: none;' |
| 319 | - ) . |
|
| 319 | + ). |
|
| 320 | 320 | EEH_HTML::h6( |
| 321 | 321 | esc_html__( |
| 322 | 322 | 'Is your state/province missing from the dropdown menu above? You can add it by completing the following steps:', |
| 323 | 323 | 'event_espresso' |
| 324 | 324 | ) |
| 325 | - ) . |
|
| 326 | - EEH_HTML::ul() . |
|
| 325 | + ). |
|
| 326 | + EEH_HTML::ul(). |
|
| 327 | 327 | EEH_HTML::li( |
| 328 | 328 | esc_html__( |
| 329 | 329 | 'first select the Country that your State/Province belongs to', |
| 330 | 330 | 'event_espresso' |
| 331 | 331 | ) |
| 332 | - ) . |
|
| 332 | + ). |
|
| 333 | 333 | EEH_HTML::li( |
| 334 | 334 | esc_html__('enter the name of your State/Province', 'event_espresso') |
| 335 | - ) . |
|
| 335 | + ). |
|
| 336 | 336 | EEH_HTML::li( |
| 337 | 337 | esc_html__( |
| 338 | 338 | 'enter a two to six letter abbreviation for the name of your State/Province', |
| 339 | 339 | 'event_espresso' |
| 340 | 340 | ) |
| 341 | - ) . |
|
| 342 | - EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')) . |
|
| 341 | + ). |
|
| 342 | + EEH_HTML::li(esc_html__('click the ADD button', 'event_espresso')). |
|
| 343 | 343 | EEH_HTML::ulx() |
| 344 | 344 | ) |
| 345 | 345 | ), |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | 'nsmf_new_state_country', |
| 354 | 354 | $input->html_id() |
| 355 | 355 | ), |
| 356 | - 'html_class' => $input->html_class() . ' new-state-country', |
|
| 356 | + 'html_class' => $input->html_class().' new-state-country', |
|
| 357 | 357 | 'html_label_text' => esc_html__('New State/Province Country', 'event_espresso'), |
| 358 | 358 | 'default' => EE_Registry::instance()->REQ->get($country_name, ''), |
| 359 | 359 | 'required' => false, |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | 'nsmf_new_state_name', |
| 369 | 369 | $input->html_id() |
| 370 | 370 | ), |
| 371 | - 'html_class' => $input->html_class() . ' new-state-state', |
|
| 371 | + 'html_class' => $input->html_class().' new-state-state', |
|
| 372 | 372 | 'html_label_text' => esc_html__( |
| 373 | 373 | 'New State/Province Name', |
| 374 | 374 | 'event_espresso' |
@@ -387,11 +387,11 @@ discard block |
||
| 387 | 387 | 'nsmf_new_state_abbrv', |
| 388 | 388 | $input->html_id() |
| 389 | 389 | ), |
| 390 | - 'html_class' => $input->html_class() . ' new-state-abbrv', |
|
| 390 | + 'html_class' => $input->html_class().' new-state-abbrv', |
|
| 391 | 391 | 'html_label_text' => esc_html__( |
| 392 | 392 | 'New State/Province Abbreviation', |
| 393 | 393 | 'event_espresso' |
| 394 | - ) . ' *', |
|
| 394 | + ).' *', |
|
| 395 | 395 | 'html_other_attributes' => 'size="24"', |
| 396 | 396 | 'default' => EE_Registry::instance()->REQ->get($abbrv_name, ''), |
| 397 | 397 | 'required' => false, |
@@ -401,15 +401,15 @@ discard block |
||
| 401 | 401 | 'add_new_state_submit_button' => new EE_Form_Section_HTML( |
| 402 | 402 | apply_filters( |
| 403 | 403 | 'FHEE__EED_Add_New_State__display_add_new_state_micro_form__add_new_state_submit_button', |
| 404 | - EEH_HTML::nbsp(3) . |
|
| 404 | + EEH_HTML::nbsp(3). |
|
| 405 | 405 | EEH_HTML::link( |
| 406 | 406 | '', |
| 407 | 407 | esc_html__('ADD', 'event_espresso'), |
| 408 | 408 | '', |
| 409 | - 'submit-' . $new_state_submit_id, |
|
| 409 | + 'submit-'.$new_state_submit_id, |
|
| 410 | 410 | 'ee-form-add-new-state-submit button button-secondary', |
| 411 | 411 | '', |
| 412 | - 'data-target="' . $new_state_submit_id . '" data-value-field-name="' . $input->valueFieldName(). '"' |
|
| 412 | + 'data-target="'.$new_state_submit_id.'" data-value-field-name="'.$input->valueFieldName().'"' |
|
| 413 | 413 | ) |
| 414 | 414 | ) |
| 415 | 415 | ), |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | EEH_HTML::div('', '', 'small-text') |
| 423 | 423 | . |
| 424 | 424 | EEH_HTML::strong( |
| 425 | - '* ' . |
|
| 425 | + '* '. |
|
| 426 | 426 | esc_html__( |
| 427 | 427 | 'Don\'t know your State/Province Abbreviation?', |
| 428 | 428 | 'event_espresso' |
@@ -455,10 +455,10 @@ discard block |
||
| 455 | 455 | '', |
| 456 | 456 | esc_html__('cancel new State/Province', 'event_espresso'), |
| 457 | 457 | '', |
| 458 | - 'hide-' . $input->html_id(), |
|
| 458 | + 'hide-'.$input->html_id(), |
|
| 459 | 459 | 'ee-form-cancel-new-state-lnk smaller-text', |
| 460 | 460 | '', |
| 461 | - 'data-target="' . $input->html_id() . '"' |
|
| 461 | + 'data-target="'.$input->html_id().'"' |
|
| 462 | 462 | ) |
| 463 | 463 | . |
| 464 | 464 | EEH_HTML::divx() |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | $new_states = EE_Registry::instance()->SSN->get_session_data( |
| 524 | 524 | 'nsmf_new_states' |
| 525 | 525 | ); |
| 526 | - $new_states[ $new_state->ID() ] = $new_state; |
|
| 526 | + $new_states[$new_state->ID()] = $new_state; |
|
| 527 | 527 | EE_Registry::instance()->SSN->set_session_data( |
| 528 | 528 | array('nsmf_new_states' => $new_states) |
| 529 | 529 | ); |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | public static function save_new_state_to_db($props_n_values = array()) |
| 605 | 605 | { |
| 606 | 606 | $existing_state = EEM_State::instance()->get_all(array($props_n_values, 'limit' => 1)); |
| 607 | - if (! empty($existing_state)) { |
|
| 607 | + if ( ! empty($existing_state)) { |
|
| 608 | 608 | return array_pop($existing_state); |
| 609 | 609 | } |
| 610 | 610 | $new_state = EE_State::new_instance($props_n_values); |
@@ -619,15 +619,15 @@ discard block |
||
| 619 | 619 | ); |
| 620 | 620 | // if not non-ajax admin |
| 621 | 621 | new PersistentAdminNotice( |
| 622 | - 'new-state-added-' . $new_state->country_iso() . '-' . $new_state->abbrev(), |
|
| 622 | + 'new-state-added-'.$new_state->country_iso().'-'.$new_state->abbrev(), |
|
| 623 | 623 | sprintf( |
| 624 | 624 | esc_html__( |
| 625 | 625 | 'A new State named "%1$s (%2$s)" was dynamically added from an Event Espresso form for the Country of "%3$s".%5$sTo verify, edit, and/or delete this new State, please go to the %4$s and update the States / Provinces section.%5$sCheck "Yes" to have this new State added to dropdown select lists in forms.', |
| 626 | 626 | 'event_espresso' |
| 627 | 627 | ), |
| 628 | - '<b>' . $new_state->name() . '</b>', |
|
| 629 | - '<b>' . $new_state->abbrev() . '</b>', |
|
| 630 | - '<b>' . $new_state->country()->name() . '</b>', |
|
| 628 | + '<b>'.$new_state->name().'</b>', |
|
| 629 | + '<b>'.$new_state->abbrev().'</b>', |
|
| 630 | + '<b>'.$new_state->country()->name().'</b>', |
|
| 631 | 631 | '<a href="' |
| 632 | 632 | . $country_settings_url |
| 633 | 633 | . '">' |
@@ -660,7 +660,7 @@ discard block |
||
| 660 | 660 | */ |
| 661 | 661 | public static function update_country_settings($CNT_ISO = '', $STA_ID = '', $cols_n_values = array()) |
| 662 | 662 | { |
| 663 | - if (! $CNT_ISO) { |
|
| 663 | + if ( ! $CNT_ISO) { |
|
| 664 | 664 | EE_Error::add_error( |
| 665 | 665 | esc_html__('An invalid or missing Country ISO Code was received.', 'event_espresso'), |
| 666 | 666 | __FILE__, |
@@ -670,13 +670,13 @@ discard block |
||
| 670 | 670 | } |
| 671 | 671 | $STA_abbrev = is_array($cols_n_values) && isset($cols_n_values['STA_abbrev']) ? $cols_n_values['STA_abbrev'] |
| 672 | 672 | : false; |
| 673 | - if (! $STA_abbrev && ! empty($STA_ID)) { |
|
| 673 | + if ( ! $STA_abbrev && ! empty($STA_ID)) { |
|
| 674 | 674 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
| 675 | 675 | if ($state instanceof EE_State) { |
| 676 | 676 | $STA_abbrev = $state->abbrev(); |
| 677 | 677 | } |
| 678 | 678 | } |
| 679 | - if (! $STA_abbrev) { |
|
| 679 | + if ( ! $STA_abbrev) { |
|
| 680 | 680 | EE_Error::add_error( |
| 681 | 681 | esc_html__('An invalid or missing State Abbreviation was received.', 'event_espresso'), |
| 682 | 682 | __FILE__, |
@@ -688,7 +688,7 @@ discard block |
||
| 688 | 688 | $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
| 689 | 689 | 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
| 690 | 690 | ); |
| 691 | - $persistent_admin_notice_manager->dismissNotice($CNT_ISO . '-' . $STA_abbrev, true, true); |
|
| 691 | + $persistent_admin_notice_manager->dismissNotice($CNT_ISO.'-'.$STA_abbrev, true, true); |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | |
@@ -715,16 +715,16 @@ discard block |
||
| 715 | 715 | && $question->type() === EEM_Question::QST_type_state |
| 716 | 716 | ) { |
| 717 | 717 | $STA_ID = $answer->value(); |
| 718 | - if (! empty($STA_ID)) { |
|
| 718 | + if ( ! empty($STA_ID)) { |
|
| 719 | 719 | $state = EEM_State::instance()->get_one_by_ID($STA_ID); |
| 720 | 720 | if ($state instanceof EE_State) { |
| 721 | 721 | $country = $state->country(); |
| 722 | 722 | if ($country instanceof EE_Country) { |
| 723 | - if (! isset($state_options[ $country->name() ])) { |
|
| 724 | - $state_options[ $country->name() ] = array(); |
|
| 723 | + if ( ! isset($state_options[$country->name()])) { |
|
| 724 | + $state_options[$country->name()] = array(); |
|
| 725 | 725 | } |
| 726 | - if (! isset($state_options[ $country->name() ][ $STA_ID ])) { |
|
| 727 | - $state_options[ $country->name() ][ $STA_ID ] = $state->name(); |
|
| 726 | + if ( ! isset($state_options[$country->name()][$STA_ID])) { |
|
| 727 | + $state_options[$country->name()][$STA_ID] = $state->name(); |
|
| 728 | 728 | } |
| 729 | 729 | } |
| 730 | 730 | } |
@@ -758,11 +758,11 @@ discard block |
||
| 758 | 758 | === EEM_Question::QST_type_country |
| 759 | 759 | ) { |
| 760 | 760 | $CNT_ISO = $answer->value(); |
| 761 | - if (! empty($CNT_ISO)) { |
|
| 761 | + if ( ! empty($CNT_ISO)) { |
|
| 762 | 762 | $country = EEM_Country::instance()->get_one_by_ID($CNT_ISO); |
| 763 | 763 | if ($country instanceof EE_Country) { |
| 764 | - if (! isset($country_options[ $CNT_ISO ])) { |
|
| 765 | - $country_options[ $CNT_ISO ] = $country->name(); |
|
| 764 | + if ( ! isset($country_options[$CNT_ISO])) { |
|
| 765 | + $country_options[$CNT_ISO] = $country->name(); |
|
| 766 | 766 | } |
| 767 | 767 | } |
| 768 | 768 | } |
@@ -786,7 +786,7 @@ discard block |
||
| 786 | 786 | if ($new_state instanceof EE_State |
| 787 | 787 | && $new_state->country() instanceof EE_Country |
| 788 | 788 | ) { |
| 789 | - $state_options[ $new_state->country()->name() ][ $new_state->ID() ] = $new_state->name(); |
|
| 789 | + $state_options[$new_state->country()->name()][$new_state->ID()] = $new_state->name(); |
|
| 790 | 790 | } |
| 791 | 791 | } |
| 792 | 792 | return $state_options; |
@@ -826,7 +826,7 @@ discard block |
||
| 826 | 826 | if ($new_state instanceof EE_State |
| 827 | 827 | && $new_state->country() instanceof EE_Country |
| 828 | 828 | ) { |
| 829 | - $country_options[ $new_state->country()->ID() ] = $new_state->country()->name(); |
|
| 829 | + $country_options[$new_state->country()->ID()] = $new_state->country()->name(); |
|
| 830 | 830 | } |
| 831 | 831 | } |
| 832 | 832 | return $country_options; |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | { |
| 37 | 37 | if (isset($input_settings['value_field_name'])) { |
| 38 | 38 | $this->valueFieldName = $input_settings['value_field_name']; |
| 39 | - if (! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
|
| 39 | + if ( ! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
|
| 40 | 40 | throw new InvalidArgumentException( |
| 41 | 41 | sprintf( |
| 42 | 42 | esc_html__('An invalid state field "%1$s" was specified for the state input\'s option values.', 'event_espresso'), |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $this |
| 54 | 54 | ); |
| 55 | 55 | $input_settings['html_class'] = isset($input_settings['html_class']) |
| 56 | - ? $input_settings['html_class'] . ' ee-state-select-js' |
|
| 56 | + ? $input_settings['html_class'].' ee-state-select-js' |
|
| 57 | 57 | : 'ee-state-select-js'; |
| 58 | 58 | parent::__construct($state_options, $input_settings); |
| 59 | 59 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | public function get_state_answer_options($state_options = null) |
| 84 | 84 | { |
| 85 | 85 | // if passed something that is NOT an array |
| 86 | - if (! is_array($state_options) || empty($state_options)) { |
|
| 86 | + if ( ! is_array($state_options) || empty($state_options)) { |
|
| 87 | 87 | // get possibly cached list of states |
| 88 | 88 | $states = EEM_State::instance()->get_all_active_states(); |
| 89 | 89 | } |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | $states = $state_options; |
| 92 | 92 | $state_options = array(); |
| 93 | 93 | } |
| 94 | - if (! empty($states)) { |
|
| 94 | + if ( ! empty($states)) { |
|
| 95 | 95 | // set the default |
| 96 | 96 | $state_options[''][''] = ''; |
| 97 | 97 | foreach ($states as $state) { |
| 98 | 98 | if ($state instanceof EE_State) { |
| 99 | - $state_options[ $state->country()->name() ][ $state->get($this->valueFieldName()) ] = $state->name(); |
|
| 99 | + $state_options[$state->country()->name()][$state->get($this->valueFieldName())] = $state->name(); |
|
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | } |
@@ -12,94 +12,94 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class EE_State_Select_Input extends EE_Select_Input |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * @var string the name of the EE_State field to use for option values in the HTML form input. |
|
| 17 | - */ |
|
| 18 | - protected $valueFieldName; |
|
| 15 | + /** |
|
| 16 | + * @var string the name of the EE_State field to use for option values in the HTML form input. |
|
| 17 | + */ |
|
| 18 | + protected $valueFieldName; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @param EE_State[]|array|null $state_options. If a flat array of string is provided, |
|
| 22 | - * $input_settings['value_field_name'] is ignored. If an array of states is passed, that field will be used for |
|
| 23 | - * the keys (which will become the option values). If null or empty is passed, all active states will be used, |
|
| 24 | - * and $input_settings['value_field_name'] will again be used. * |
|
| 25 | - * @param array $input_settings same as parent, but also { |
|
| 26 | - * @type string $value_field_name the name of the field to use |
|
| 27 | - * for the HTML option values, ie, `STA_ID`, `STA_abbrev`, or `STA_name`. |
|
| 28 | - * } |
|
| 29 | - * @throws EE_Error |
|
| 30 | - * @throws InvalidArgumentException |
|
| 31 | - * @throws InvalidDataTypeException |
|
| 32 | - * @throws InvalidInterfaceException |
|
| 33 | - * @throws ReflectionException |
|
| 34 | - */ |
|
| 35 | - public function __construct($state_options, $input_settings = array()) |
|
| 36 | - { |
|
| 37 | - if (isset($input_settings['value_field_name'])) { |
|
| 38 | - $this->valueFieldName = $input_settings['value_field_name']; |
|
| 39 | - if (! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
|
| 40 | - throw new InvalidArgumentException( |
|
| 41 | - sprintf( |
|
| 42 | - esc_html__('An invalid state field "%1$s" was specified for the state input\'s option values.', 'event_espresso'), |
|
| 43 | - $this->valueFieldName() |
|
| 44 | - ) |
|
| 45 | - ); |
|
| 46 | - } |
|
| 47 | - } else { |
|
| 48 | - $this->valueFieldName = 'STA_ID'; |
|
| 49 | - } |
|
| 50 | - $state_options = apply_filters( |
|
| 51 | - 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 52 | - $this->get_state_answer_options($state_options), |
|
| 53 | - $this |
|
| 54 | - ); |
|
| 55 | - $input_settings['html_class'] = isset($input_settings['html_class']) |
|
| 56 | - ? $input_settings['html_class'] . ' ee-state-select-js' |
|
| 57 | - : 'ee-state-select-js'; |
|
| 58 | - parent::__construct($state_options, $input_settings); |
|
| 59 | - } |
|
| 20 | + /** |
|
| 21 | + * @param EE_State[]|array|null $state_options. If a flat array of string is provided, |
|
| 22 | + * $input_settings['value_field_name'] is ignored. If an array of states is passed, that field will be used for |
|
| 23 | + * the keys (which will become the option values). If null or empty is passed, all active states will be used, |
|
| 24 | + * and $input_settings['value_field_name'] will again be used. * |
|
| 25 | + * @param array $input_settings same as parent, but also { |
|
| 26 | + * @type string $value_field_name the name of the field to use |
|
| 27 | + * for the HTML option values, ie, `STA_ID`, `STA_abbrev`, or `STA_name`. |
|
| 28 | + * } |
|
| 29 | + * @throws EE_Error |
|
| 30 | + * @throws InvalidArgumentException |
|
| 31 | + * @throws InvalidDataTypeException |
|
| 32 | + * @throws InvalidInterfaceException |
|
| 33 | + * @throws ReflectionException |
|
| 34 | + */ |
|
| 35 | + public function __construct($state_options, $input_settings = array()) |
|
| 36 | + { |
|
| 37 | + if (isset($input_settings['value_field_name'])) { |
|
| 38 | + $this->valueFieldName = $input_settings['value_field_name']; |
|
| 39 | + if (! EEM_State::instance()->has_field((string) $this->valueFieldName())) { |
|
| 40 | + throw new InvalidArgumentException( |
|
| 41 | + sprintf( |
|
| 42 | + esc_html__('An invalid state field "%1$s" was specified for the state input\'s option values.', 'event_espresso'), |
|
| 43 | + $this->valueFieldName() |
|
| 44 | + ) |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | + } else { |
|
| 48 | + $this->valueFieldName = 'STA_ID'; |
|
| 49 | + } |
|
| 50 | + $state_options = apply_filters( |
|
| 51 | + 'FHEE__EE_State_Select_Input____construct__state_options', |
|
| 52 | + $this->get_state_answer_options($state_options), |
|
| 53 | + $this |
|
| 54 | + ); |
|
| 55 | + $input_settings['html_class'] = isset($input_settings['html_class']) |
|
| 56 | + ? $input_settings['html_class'] . ' ee-state-select-js' |
|
| 57 | + : 'ee-state-select-js'; |
|
| 58 | + parent::__construct($state_options, $input_settings); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Returns the name of the state field used for the HTML option values. |
|
| 63 | - * @since $VID:$ |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - public function valueFieldName() |
|
| 67 | - { |
|
| 68 | - return $this->valueFieldName; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Returns the name of the state field used for the HTML option values. |
|
| 63 | + * @since $VID:$ |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + public function valueFieldName() |
|
| 67 | + { |
|
| 68 | + return $this->valueFieldName; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * get_state_answer_options |
|
| 74 | - * |
|
| 75 | - * @param array $state_options |
|
| 76 | - * @return array |
|
| 77 | - * @throws EE_Error |
|
| 78 | - * @throws InvalidArgumentException |
|
| 79 | - * @throws ReflectionException |
|
| 80 | - * @throws InvalidDataTypeException |
|
| 81 | - * @throws InvalidInterfaceException |
|
| 82 | - */ |
|
| 83 | - public function get_state_answer_options($state_options = null) |
|
| 84 | - { |
|
| 85 | - // if passed something that is NOT an array |
|
| 86 | - if (! is_array($state_options) || empty($state_options)) { |
|
| 87 | - // get possibly cached list of states |
|
| 88 | - $states = EEM_State::instance()->get_all_active_states(); |
|
| 89 | - } |
|
| 90 | - if (is_array($state_options) && reset($state_options) instanceof EE_State) { |
|
| 91 | - $states = $state_options; |
|
| 92 | - $state_options = array(); |
|
| 93 | - } |
|
| 94 | - if (! empty($states)) { |
|
| 95 | - // set the default |
|
| 96 | - $state_options[''][''] = ''; |
|
| 97 | - foreach ($states as $state) { |
|
| 98 | - if ($state instanceof EE_State) { |
|
| 99 | - $state_options[ $state->country()->name() ][ $state->get($this->valueFieldName()) ] = $state->name(); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - return $state_options; |
|
| 104 | - } |
|
| 72 | + /** |
|
| 73 | + * get_state_answer_options |
|
| 74 | + * |
|
| 75 | + * @param array $state_options |
|
| 76 | + * @return array |
|
| 77 | + * @throws EE_Error |
|
| 78 | + * @throws InvalidArgumentException |
|
| 79 | + * @throws ReflectionException |
|
| 80 | + * @throws InvalidDataTypeException |
|
| 81 | + * @throws InvalidInterfaceException |
|
| 82 | + */ |
|
| 83 | + public function get_state_answer_options($state_options = null) |
|
| 84 | + { |
|
| 85 | + // if passed something that is NOT an array |
|
| 86 | + if (! is_array($state_options) || empty($state_options)) { |
|
| 87 | + // get possibly cached list of states |
|
| 88 | + $states = EEM_State::instance()->get_all_active_states(); |
|
| 89 | + } |
|
| 90 | + if (is_array($state_options) && reset($state_options) instanceof EE_State) { |
|
| 91 | + $states = $state_options; |
|
| 92 | + $state_options = array(); |
|
| 93 | + } |
|
| 94 | + if (! empty($states)) { |
|
| 95 | + // set the default |
|
| 96 | + $state_options[''][''] = ''; |
|
| 97 | + foreach ($states as $state) { |
|
| 98 | + if ($state instanceof EE_State) { |
|
| 99 | + $state_options[ $state->country()->name() ][ $state->get($this->valueFieldName()) ] = $state->name(); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + return $state_options; |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -14,168 +14,168 @@ |
||
| 14 | 14 | class EE_Billing_Attendee_Info_Form extends EE_Billing_Info_Form |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * |
|
| 19 | - * @param EE_Payment_Method $payment_method |
|
| 20 | - * @param array $options_array @see EE_Form_Section_Proper::__construct() |
|
| 21 | - */ |
|
| 22 | - public function __construct(EE_Payment_Method $payment_method, $options_array = array()) |
|
| 23 | - { |
|
| 24 | - $options_array['subsections'] = array_merge( |
|
| 25 | - array( |
|
| 26 | - 'first_name' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => __('First Name', 'event_espresso') )), |
|
| 27 | - 'last_name' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => __('Last Name', 'event_espresso') )), |
|
| 28 | - 'email' => new EE_Email_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => __('Email', 'event_espresso') )), |
|
| 29 | - 'address' => new EE_Text_Input(array( 'html_label_text'=> __('Address', 'event_espresso'), 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )), |
|
| 30 | - 'address2' => new EE_Text_Input(array( 'html_label_text'=> __('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )), |
|
| 31 | - 'city' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => __('City', 'event_espresso') )), |
|
| 32 | - 'state' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => __('State', 'event_espresso') ))), |
|
| 33 | - 'country' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => __('Country', 'event_espresso') ))), |
|
| 34 | - 'zip' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => __('Zip', 'event_espresso') )), |
|
| 35 | - 'phone' => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => __('Phone', 'event_espresso') )), |
|
| 36 | - ), |
|
| 37 | - isset($options_array['subsections']) ? $options_array['subsections'] : array() |
|
| 38 | - ); |
|
| 17 | + /** |
|
| 18 | + * |
|
| 19 | + * @param EE_Payment_Method $payment_method |
|
| 20 | + * @param array $options_array @see EE_Form_Section_Proper::__construct() |
|
| 21 | + */ |
|
| 22 | + public function __construct(EE_Payment_Method $payment_method, $options_array = array()) |
|
| 23 | + { |
|
| 24 | + $options_array['subsections'] = array_merge( |
|
| 25 | + array( |
|
| 26 | + 'first_name' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => __('First Name', 'event_espresso') )), |
|
| 27 | + 'last_name' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => __('Last Name', 'event_espresso') )), |
|
| 28 | + 'email' => new EE_Email_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => __('Email', 'event_espresso') )), |
|
| 29 | + 'address' => new EE_Text_Input(array( 'html_label_text'=> __('Address', 'event_espresso'), 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )), |
|
| 30 | + 'address2' => new EE_Text_Input(array( 'html_label_text'=> __('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )), |
|
| 31 | + 'city' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => __('City', 'event_espresso') )), |
|
| 32 | + 'state' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => __('State', 'event_espresso') ))), |
|
| 33 | + 'country' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => __('Country', 'event_espresso') ))), |
|
| 34 | + 'zip' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => __('Zip', 'event_espresso') )), |
|
| 35 | + 'phone' => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => __('Phone', 'event_espresso') )), |
|
| 36 | + ), |
|
| 37 | + isset($options_array['subsections']) ? $options_array['subsections'] : array() |
|
| 38 | + ); |
|
| 39 | 39 | |
| 40 | - parent::__construct($payment_method, $options_array); |
|
| 41 | - } |
|
| 40 | + parent::__construct($payment_method, $options_array); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Sets the defaults for the billing form according to the attendee's details |
|
| 45 | - * @param EE_Attendee $attendee |
|
| 46 | - */ |
|
| 47 | - public function populate_from_attendee($attendee) |
|
| 48 | - { |
|
| 49 | - $attendee = EEM_Attendee::instance()->ensure_is_obj($attendee); |
|
| 43 | + /** |
|
| 44 | + * Sets the defaults for the billing form according to the attendee's details |
|
| 45 | + * @param EE_Attendee $attendee |
|
| 46 | + */ |
|
| 47 | + public function populate_from_attendee($attendee) |
|
| 48 | + { |
|
| 49 | + $attendee = EEM_Attendee::instance()->ensure_is_obj($attendee); |
|
| 50 | 50 | |
| 51 | - /** @var $attendee EE_Attendee */ |
|
| 52 | - $this->populate_defaults( |
|
| 53 | - apply_filters( |
|
| 54 | - 'FHEE__EE_Billing_Attendee_Info_Form__populate_from_attendee', |
|
| 55 | - array( |
|
| 56 | - 'first_name'=>$attendee->fname(), |
|
| 57 | - 'last_name'=>$attendee->lname(), |
|
| 58 | - 'email'=>$attendee->email(), |
|
| 59 | - 'address'=>$attendee->address(), |
|
| 60 | - 'address2'=>$attendee->address2(), |
|
| 61 | - 'city'=>$attendee->city(), |
|
| 62 | - 'state'=> $this->getAttendeeStateValueForForm($attendee), |
|
| 63 | - 'country'=> $attendee->country_ID(), |
|
| 64 | - 'zip'=>$attendee->zip(), |
|
| 65 | - 'phone'=>$attendee->phone(), |
|
| 66 | - ), |
|
| 67 | - $attendee, |
|
| 68 | - $this |
|
| 69 | - ) |
|
| 70 | - ); |
|
| 71 | - } |
|
| 51 | + /** @var $attendee EE_Attendee */ |
|
| 52 | + $this->populate_defaults( |
|
| 53 | + apply_filters( |
|
| 54 | + 'FHEE__EE_Billing_Attendee_Info_Form__populate_from_attendee', |
|
| 55 | + array( |
|
| 56 | + 'first_name'=>$attendee->fname(), |
|
| 57 | + 'last_name'=>$attendee->lname(), |
|
| 58 | + 'email'=>$attendee->email(), |
|
| 59 | + 'address'=>$attendee->address(), |
|
| 60 | + 'address2'=>$attendee->address2(), |
|
| 61 | + 'city'=>$attendee->city(), |
|
| 62 | + 'state'=> $this->getAttendeeStateValueForForm($attendee), |
|
| 63 | + 'country'=> $attendee->country_ID(), |
|
| 64 | + 'zip'=>$attendee->zip(), |
|
| 65 | + 'phone'=>$attendee->phone(), |
|
| 66 | + ), |
|
| 67 | + $attendee, |
|
| 68 | + $this |
|
| 69 | + ) |
|
| 70 | + ); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Gets the default value to use for the billing form's state value. |
|
| 75 | - * @since $VID:$ |
|
| 76 | - * @param EE_Attendee $attendee |
|
| 77 | - * @return string |
|
| 78 | - * @throws EE_Error2 |
|
| 79 | - */ |
|
| 80 | - protected function getAttendeeStateValueForForm(EE_Attendee $attendee) |
|
| 81 | - { |
|
| 82 | - $state_input = $this->get_input('state', false); |
|
| 83 | - if( $state_input instanceof EE_State_Select_Input){ |
|
| 84 | - $state_field_to_use = $state_input->valueFieldName(); |
|
| 85 | - } else { |
|
| 86 | - $state_field_to_use = 'STA_ID'; |
|
| 87 | - } |
|
| 88 | - switch ($state_field_to_use) { |
|
| 89 | - case 'STA_abbrev': |
|
| 90 | - $state_value = $attendee->state_abbrev(); |
|
| 91 | - break; |
|
| 92 | - case 'STA_name': |
|
| 93 | - $state_value = $attendee->state_name(); |
|
| 94 | - break; |
|
| 95 | - default: |
|
| 96 | - $state_value = $attendee->state_ID(); |
|
| 97 | - } |
|
| 98 | - return $state_value; |
|
| 99 | - } |
|
| 73 | + /** |
|
| 74 | + * Gets the default value to use for the billing form's state value. |
|
| 75 | + * @since $VID:$ |
|
| 76 | + * @param EE_Attendee $attendee |
|
| 77 | + * @return string |
|
| 78 | + * @throws EE_Error2 |
|
| 79 | + */ |
|
| 80 | + protected function getAttendeeStateValueForForm(EE_Attendee $attendee) |
|
| 81 | + { |
|
| 82 | + $state_input = $this->get_input('state', false); |
|
| 83 | + if( $state_input instanceof EE_State_Select_Input){ |
|
| 84 | + $state_field_to_use = $state_input->valueFieldName(); |
|
| 85 | + } else { |
|
| 86 | + $state_field_to_use = 'STA_ID'; |
|
| 87 | + } |
|
| 88 | + switch ($state_field_to_use) { |
|
| 89 | + case 'STA_abbrev': |
|
| 90 | + $state_value = $attendee->state_abbrev(); |
|
| 91 | + break; |
|
| 92 | + case 'STA_name': |
|
| 93 | + $state_value = $attendee->state_name(); |
|
| 94 | + break; |
|
| 95 | + default: |
|
| 96 | + $state_value = $attendee->state_ID(); |
|
| 97 | + } |
|
| 98 | + return $state_value; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | 101 | |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * copy_billing_form_data_to_attendee |
|
| 105 | - * copies info from the billing form to the attendee's details |
|
| 106 | - * @param \EE_Attendee $attendee - the attendee object to copy details to |
|
| 107 | - * @return \EE_Attendee |
|
| 108 | - */ |
|
| 109 | - public function copy_billing_form_data_to_attendee(EE_Attendee $attendee) |
|
| 110 | - { |
|
| 111 | - // grab billing form data |
|
| 112 | - $data = $this->valid_data(); |
|
| 113 | - // copy first_name |
|
| 114 | - if (! empty($data['first_name'])) { |
|
| 115 | - $attendee->set_fname($data['first_name']); |
|
| 116 | - } |
|
| 117 | - // copy last_name |
|
| 118 | - if (! empty($data['last_name'])) { |
|
| 119 | - $attendee->set_lname($data['last_name']); |
|
| 120 | - } |
|
| 121 | - // copy email |
|
| 122 | - if (! empty($data['email'])) { |
|
| 123 | - $attendee->set_email($data['email']); |
|
| 124 | - } |
|
| 125 | - // copy address |
|
| 126 | - if (! empty($data['address'])) { |
|
| 127 | - $attendee->set_address($data['address']); |
|
| 128 | - } |
|
| 129 | - // copy address2 |
|
| 130 | - if (! empty($data['address2'])) { |
|
| 131 | - $attendee->set_address2($data['address2']); |
|
| 132 | - } |
|
| 133 | - // copy city |
|
| 134 | - if (! empty($data['city'])) { |
|
| 135 | - $attendee->set_city($data['city']); |
|
| 136 | - } |
|
| 137 | - // copy state |
|
| 138 | - if (! empty($data['state'])) { |
|
| 139 | - $attendee->set_state($data['state']); |
|
| 140 | - } |
|
| 141 | - // copy country |
|
| 142 | - if (! empty($data['country'])) { |
|
| 143 | - $attendee->set_country($data['country']); |
|
| 144 | - } |
|
| 145 | - // copy zip |
|
| 146 | - if (! empty($data['zip'])) { |
|
| 147 | - $attendee->set_zip($data['zip']); |
|
| 148 | - } |
|
| 149 | - // copy phone |
|
| 150 | - if (! empty($data['phone'])) { |
|
| 151 | - $attendee->set_phone($data['phone']); |
|
| 152 | - } |
|
| 153 | - return $attendee; |
|
| 154 | - } |
|
| 103 | + /** |
|
| 104 | + * copy_billing_form_data_to_attendee |
|
| 105 | + * copies info from the billing form to the attendee's details |
|
| 106 | + * @param \EE_Attendee $attendee - the attendee object to copy details to |
|
| 107 | + * @return \EE_Attendee |
|
| 108 | + */ |
|
| 109 | + public function copy_billing_form_data_to_attendee(EE_Attendee $attendee) |
|
| 110 | + { |
|
| 111 | + // grab billing form data |
|
| 112 | + $data = $this->valid_data(); |
|
| 113 | + // copy first_name |
|
| 114 | + if (! empty($data['first_name'])) { |
|
| 115 | + $attendee->set_fname($data['first_name']); |
|
| 116 | + } |
|
| 117 | + // copy last_name |
|
| 118 | + if (! empty($data['last_name'])) { |
|
| 119 | + $attendee->set_lname($data['last_name']); |
|
| 120 | + } |
|
| 121 | + // copy email |
|
| 122 | + if (! empty($data['email'])) { |
|
| 123 | + $attendee->set_email($data['email']); |
|
| 124 | + } |
|
| 125 | + // copy address |
|
| 126 | + if (! empty($data['address'])) { |
|
| 127 | + $attendee->set_address($data['address']); |
|
| 128 | + } |
|
| 129 | + // copy address2 |
|
| 130 | + if (! empty($data['address2'])) { |
|
| 131 | + $attendee->set_address2($data['address2']); |
|
| 132 | + } |
|
| 133 | + // copy city |
|
| 134 | + if (! empty($data['city'])) { |
|
| 135 | + $attendee->set_city($data['city']); |
|
| 136 | + } |
|
| 137 | + // copy state |
|
| 138 | + if (! empty($data['state'])) { |
|
| 139 | + $attendee->set_state($data['state']); |
|
| 140 | + } |
|
| 141 | + // copy country |
|
| 142 | + if (! empty($data['country'])) { |
|
| 143 | + $attendee->set_country($data['country']); |
|
| 144 | + } |
|
| 145 | + // copy zip |
|
| 146 | + if (! empty($data['zip'])) { |
|
| 147 | + $attendee->set_zip($data['zip']); |
|
| 148 | + } |
|
| 149 | + // copy phone |
|
| 150 | + if (! empty($data['phone'])) { |
|
| 151 | + $attendee->set_phone($data['phone']); |
|
| 152 | + } |
|
| 153 | + return $attendee; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * create_attendee_from_billing_form_data |
|
| 159 | - * uses info from the billing form to create a new attendee |
|
| 160 | - * @return \EE_Attendee |
|
| 161 | - */ |
|
| 162 | - public function create_attendee_from_billing_form_data() |
|
| 163 | - { |
|
| 164 | - // grab billing form data |
|
| 165 | - $data = $this->valid_data(); |
|
| 166 | - return EE_Attendee::new_instance(array( |
|
| 167 | - 'ATT_fname' => ! empty($data['first_name']) ? $data['first_name'] : '', |
|
| 168 | - 'ATT_lname' => ! empty($data['last_name']) ? $data['last_name'] : '', |
|
| 169 | - 'ATT_email' => ! empty($data['email']) ? $data['email'] : '', |
|
| 170 | - 'ATT_address' => ! empty($data['address']) ? $data['address'] : '', |
|
| 171 | - 'ATT_address2' => ! empty($data['address2']) ? $data['address2'] : '', |
|
| 172 | - 'ATT_city' => ! empty($data['city']) ? $data['city'] : '', |
|
| 173 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : '', |
|
| 174 | - 'CNT_ISO' => ! empty($data['country']) ? $data['country'] : '', |
|
| 175 | - 'ATT_zip' => ! empty($data['zip']) ? $data['zip'] : '', |
|
| 176 | - 'ATT_phone' => ! empty($data['phone']) ? $data['phone'] : '', |
|
| 177 | - )); |
|
| 178 | - } |
|
| 157 | + /** |
|
| 158 | + * create_attendee_from_billing_form_data |
|
| 159 | + * uses info from the billing form to create a new attendee |
|
| 160 | + * @return \EE_Attendee |
|
| 161 | + */ |
|
| 162 | + public function create_attendee_from_billing_form_data() |
|
| 163 | + { |
|
| 164 | + // grab billing form data |
|
| 165 | + $data = $this->valid_data(); |
|
| 166 | + return EE_Attendee::new_instance(array( |
|
| 167 | + 'ATT_fname' => ! empty($data['first_name']) ? $data['first_name'] : '', |
|
| 168 | + 'ATT_lname' => ! empty($data['last_name']) ? $data['last_name'] : '', |
|
| 169 | + 'ATT_email' => ! empty($data['email']) ? $data['email'] : '', |
|
| 170 | + 'ATT_address' => ! empty($data['address']) ? $data['address'] : '', |
|
| 171 | + 'ATT_address2' => ! empty($data['address2']) ? $data['address2'] : '', |
|
| 172 | + 'ATT_city' => ! empty($data['city']) ? $data['city'] : '', |
|
| 173 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : '', |
|
| 174 | + 'CNT_ISO' => ! empty($data['country']) ? $data['country'] : '', |
|
| 175 | + 'ATT_zip' => ! empty($data['zip']) ? $data['zip'] : '', |
|
| 176 | + 'ATT_phone' => ! empty($data['phone']) ? $data['phone'] : '', |
|
| 177 | + )); |
|
| 178 | + } |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | // End of file EE_Billing_Attendee_Info_Form.form.php |
@@ -23,16 +23,16 @@ discard block |
||
| 23 | 23 | { |
| 24 | 24 | $options_array['subsections'] = array_merge( |
| 25 | 25 | array( |
| 26 | - 'first_name' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => __('First Name', 'event_espresso') )), |
|
| 27 | - 'last_name' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => __('Last Name', 'event_espresso') )), |
|
| 28 | - 'email' => new EE_Email_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => __('Email', 'event_espresso') )), |
|
| 29 | - 'address' => new EE_Text_Input(array( 'html_label_text'=> __('Address', 'event_espresso'), 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address' )), |
|
| 30 | - 'address2' => new EE_Text_Input(array( 'html_label_text'=> __('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2' )), |
|
| 31 | - 'city' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => __('City', 'event_espresso') )), |
|
| 32 | - 'state' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => __('State', 'event_espresso') ))), |
|
| 33 | - 'country' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => __('Country', 'event_espresso') ))), |
|
| 34 | - 'zip' => new EE_Text_Input(array( 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => __('Zip', 'event_espresso') )), |
|
| 35 | - 'phone' => new EE_Text_Input(array( 'html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => __('Phone', 'event_espresso') )), |
|
| 26 | + 'first_name' => new EE_Text_Input(array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-fname', 'html_label_text' => __('First Name', 'event_espresso'))), |
|
| 27 | + 'last_name' => new EE_Text_Input(array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-lname', 'html_label_text' => __('Last Name', 'event_espresso'))), |
|
| 28 | + 'email' => new EE_Email_Input(array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-email', 'html_label_text' => __('Email', 'event_espresso'))), |
|
| 29 | + 'address' => new EE_Text_Input(array('html_label_text'=> __('Address', 'event_espresso'), 'required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-address')), |
|
| 30 | + 'address2' => new EE_Text_Input(array('html_label_text'=> __('Address 2', 'event_espresso'), 'html_class' => 'ee-billing-qstn ee-billing-qstn-address2')), |
|
| 31 | + 'city' => new EE_Text_Input(array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-city', 'html_label_text' => __('City', 'event_espresso'))), |
|
| 32 | + 'state' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__state_field', new EE_State_Select_Input(null, array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-state', 'html_label_text' => __('State', 'event_espresso')))), |
|
| 33 | + 'country' => apply_filters('FHEE__EE_Billing_Attendee_Info_Form__country_field', new EE_Country_Select_Input(null, array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-country', 'html_label_text' => __('Country', 'event_espresso')))), |
|
| 34 | + 'zip' => new EE_Text_Input(array('required'=>true, 'html_class' => 'ee-billing-qstn ee-billing-qstn-zip', 'html_label_text' => __('Zip', 'event_espresso'))), |
|
| 35 | + 'phone' => new EE_Text_Input(array('html_class' => 'ee-billing-qstn ee-billing-qstn-phone', 'html_label_text' => __('Phone', 'event_espresso'))), |
|
| 36 | 36 | ), |
| 37 | 37 | isset($options_array['subsections']) ? $options_array['subsections'] : array() |
| 38 | 38 | ); |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | */ |
| 80 | 80 | protected function getAttendeeStateValueForForm(EE_Attendee $attendee) |
| 81 | 81 | { |
| 82 | - $state_input = $this->get_input('state', false); |
|
| 83 | - if( $state_input instanceof EE_State_Select_Input){ |
|
| 84 | - $state_field_to_use = $state_input->valueFieldName(); |
|
| 82 | + $state_input = $this->get_input('state', false); |
|
| 83 | + if ($state_input instanceof EE_State_Select_Input) { |
|
| 84 | + $state_field_to_use = $state_input->valueFieldName(); |
|
| 85 | 85 | } else { |
| 86 | 86 | $state_field_to_use = 'STA_ID'; |
| 87 | 87 | } |
@@ -111,43 +111,43 @@ discard block |
||
| 111 | 111 | // grab billing form data |
| 112 | 112 | $data = $this->valid_data(); |
| 113 | 113 | // copy first_name |
| 114 | - if (! empty($data['first_name'])) { |
|
| 114 | + if ( ! empty($data['first_name'])) { |
|
| 115 | 115 | $attendee->set_fname($data['first_name']); |
| 116 | 116 | } |
| 117 | 117 | // copy last_name |
| 118 | - if (! empty($data['last_name'])) { |
|
| 118 | + if ( ! empty($data['last_name'])) { |
|
| 119 | 119 | $attendee->set_lname($data['last_name']); |
| 120 | 120 | } |
| 121 | 121 | // copy email |
| 122 | - if (! empty($data['email'])) { |
|
| 122 | + if ( ! empty($data['email'])) { |
|
| 123 | 123 | $attendee->set_email($data['email']); |
| 124 | 124 | } |
| 125 | 125 | // copy address |
| 126 | - if (! empty($data['address'])) { |
|
| 126 | + if ( ! empty($data['address'])) { |
|
| 127 | 127 | $attendee->set_address($data['address']); |
| 128 | 128 | } |
| 129 | 129 | // copy address2 |
| 130 | - if (! empty($data['address2'])) { |
|
| 130 | + if ( ! empty($data['address2'])) { |
|
| 131 | 131 | $attendee->set_address2($data['address2']); |
| 132 | 132 | } |
| 133 | 133 | // copy city |
| 134 | - if (! empty($data['city'])) { |
|
| 134 | + if ( ! empty($data['city'])) { |
|
| 135 | 135 | $attendee->set_city($data['city']); |
| 136 | 136 | } |
| 137 | 137 | // copy state |
| 138 | - if (! empty($data['state'])) { |
|
| 138 | + if ( ! empty($data['state'])) { |
|
| 139 | 139 | $attendee->set_state($data['state']); |
| 140 | 140 | } |
| 141 | 141 | // copy country |
| 142 | - if (! empty($data['country'])) { |
|
| 142 | + if ( ! empty($data['country'])) { |
|
| 143 | 143 | $attendee->set_country($data['country']); |
| 144 | 144 | } |
| 145 | 145 | // copy zip |
| 146 | - if (! empty($data['zip'])) { |
|
| 146 | + if ( ! empty($data['zip'])) { |
|
| 147 | 147 | $attendee->set_zip($data['zip']); |
| 148 | 148 | } |
| 149 | 149 | // copy phone |
| 150 | - if (! empty($data['phone'])) { |
|
| 150 | + if ( ! empty($data['phone'])) { |
|
| 151 | 151 | $attendee->set_phone($data['phone']); |
| 152 | 152 | } |
| 153 | 153 | return $attendee; |