|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Field for allowing the import of historical data. |
| 4 | + * |
| 5 | + * @since 2019-06-05 |
| 6 | + * @author Zach Owen <zach@webdevstudios> |
| 7 | + * @package cc-woo-view-admin-field |
| 8 | + */ |
| 9 | + |
| 10 | +namespace WebDevStudios\CCForWoo\View\Admin\Field; |
| 11 | + |
| 12 | +/** |
| 13 | + * ImportHistoricalData clss |
| 14 | + * |
| 15 | + * @since 2019-06-05 |
| 16 | + * @author Zach Owen <zach@webdevstudios> |
| 17 | + * @package cc-woo-view-admin-field |
| 18 | + */ |
| 19 | +class ImportHistoricalData { |
| 20 | + /** |
| 21 | + * Historical customer data import field. |
| 22 | + * |
| 23 | + * @since 2019-03-12 |
| 24 | + */ |
| 25 | + const OPTION_FIELD_NAME = 'cc_woo_customer_data_allow_import'; |
| 26 | + |
| 27 | + /** |
| 28 | + * Returns the form field configuration. |
| 29 | + * |
| 30 | + * @since 2019-06-05 |
| 31 | + * @author Zach Owen <zach@webdevstudios> |
| 32 | + * @return array. |
| 33 | + */ |
| 34 | + public function get_form_field() : array { |
| 35 | + return [ |
| 36 | + 'title' => esc_html__( 'Import historical customer data', 'cc-woo' ), |
| 37 | + 'desc' => $this->get_description(), |
| 38 | + 'type' => 'select', |
| 39 | + 'id' => self::OPTION_FIELD_NAME, |
| 40 | + 'default' => '', |
| 41 | + 'custom_attributes' => $this->get_custom_attributes(), |
| 42 | + 'options' => [ |
| 43 | + '' => '----', |
| 44 | + 'false' => esc_html__( 'No', 'cc-woo' ), |
| 45 | + 'true' => esc_html__( 'Yes', 'cc-woo' ), |
| 46 | + ], |
| 47 | + ]; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Get the field's custom attribute configuration. |
| 52 | + * |
| 53 | + * @TODO "$configuration" should probably be an object. |
| 54 | + * @since 2019-06-05 |
| 55 | + * @author Zach Owen <zach@webdevstudios> |
| 56 | + * |
| 57 | + * @return array |
| 58 | + */ |
| 59 | + private function get_custom_attributes() : array { |
| 60 | + $attributes = []; |
| 61 | + |
| 62 | + if ( $this->is_required() ) { |
| 63 | + $attributes['required'] = true; |
| 64 | + } |
| 65 | + |
| 66 | + if ( $this->is_readonly() ) { |
| 67 | + $attributes['readonly'] = 'readonly'; |
| 68 | + $attributes['disabled'] = 'disabled'; |
| 69 | + } |
| 70 | + |
| 71 | + return $attributes; |
| 72 | + } |
| 73 | + |
| 74 | + /** |
| 75 | + * Return whether the field is required. |
| 76 | + * |
| 77 | + * @since 2019-06-05 |
| 78 | + * @author Zach Owen <zach@webdevstudios> |
| 79 | + * @return bool |
| 80 | + */ |
| 81 | + protected function is_required() : bool { |
| 82 | + return true; |
| 83 | + } |
| 84 | + |
| 85 | + /** |
| 86 | + * Returns the value of the field option. |
| 87 | + * |
| 88 | + * @since 2019-06-05 |
| 89 | + * @author Zach Owen <zach@webdevstudios> |
| 90 | + * @return bool |
| 91 | + */ |
| 92 | + protected function is_readonly() : bool { |
| 93 | + return 'true' === get_option( self::OPTION_FIELD_NAME, 'false' ); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Get the field description based on the option's readonly state. |
| 98 | + * |
| 99 | + * @since 2019-06-05 |
| 100 | + * @author Zach Owen <zach@webdevstudios> |
| 101 | + * @return string |
| 102 | + */ |
| 103 | + private function get_description() : string { |
| 104 | + return $this->is_readonly() ? '' : esc_html__( 'Selecting Yes here will enable the ability to import your historical customer information to Constant Contact.', 'cc-woo' ); |
| 105 | + } |
| 106 | +} |
0 commit comments