number.php
195 lines
| 1 | <?php |
| 2 | class Number_Format_Cost_Calculator_Widget extends \Elementor\Widget_Base{ |
| 3 | public function get_name() { |
| 4 | return 'number_input'; |
| 5 | } |
| 6 | /** |
| 7 | * Get widget title. |
| 8 | * |
| 9 | * Retrieve currency widget title. |
| 10 | * |
| 11 | * @since 1.0.0 |
| 12 | * @access public |
| 13 | * @return string Widget title. |
| 14 | */ |
| 15 | public function get_title() { |
| 16 | return esc_html__( 'Calculator number', 'cost-calculator-for-elementor' ); |
| 17 | } |
| 18 | /** |
| 19 | * Get widget icon. |
| 20 | * |
| 21 | * Retrieve currency widget icon. |
| 22 | * |
| 23 | * @since 1.0.0 |
| 24 | * @access public |
| 25 | * @return string Widget icon. |
| 26 | */ |
| 27 | public function get_icon() { |
| 28 | return 'eicon-number-field'; |
| 29 | } |
| 30 | /** |
| 31 | * Get custom help URL. |
| 32 | * |
| 33 | * Retrieve a URL where the user can get more information about the widget. |
| 34 | * |
| 35 | * @since 1.0.0 |
| 36 | * @access public |
| 37 | * @return string Widget help URL. |
| 38 | */ |
| 39 | public function get_custom_help_url() { |
| 40 | return 'https://calculator.add-ons.org/'; |
| 41 | } |
| 42 | /** |
| 43 | * Get widget categories. |
| 44 | * |
| 45 | * Retrieve the list of categories the currency widget belongs to. |
| 46 | * |
| 47 | * @since 1.0.0 |
| 48 | * @access public |
| 49 | * @return array Widget categories. |
| 50 | */ |
| 51 | public function get_categories() { |
| 52 | return [ 'basic' ]; |
| 53 | } |
| 54 | /** |
| 55 | * Get widget keywords. |
| 56 | * |
| 57 | * Retrieve the list of keywords the currency widget belongs to. |
| 58 | * |
| 59 | * @since 1.0.0 |
| 60 | * @access public |
| 61 | * @return array Widget keywords. |
| 62 | */ |
| 63 | public function get_keywords() { |
| 64 | return [ 'currency', 'currencies','number','calculator','cost','formula' ]; |
| 65 | } |
| 66 | /** |
| 67 | * Register currency widget controls. |
| 68 | * |
| 69 | * Add input fields to allow the user to customize the widget settings. |
| 70 | * |
| 71 | * @since 1.0.0 |
| 72 | * @access protected |
| 73 | */ |
| 74 | protected function register_controls() { |
| 75 | $this->start_controls_section( |
| 76 | 'content_section', |
| 77 | [ |
| 78 | 'label' => esc_html__( 'Content', 'cost-calculator-for-elementor' ), |
| 79 | 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, |
| 80 | ] |
| 81 | ); |
| 82 | $this->add_control( |
| 83 | 'name', |
| 84 | [ |
| 85 | 'label' => esc_html__( 'Name', 'cost-calculator-for-elementor' ), |
| 86 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 87 | 'default' => 'number-change_name', |
| 88 | ] |
| 89 | ); |
| 90 | $this->add_control( |
| 91 | 'default', |
| 92 | [ |
| 93 | 'label' => esc_html__( 'Default', 'cost-calculator-for-elementor' ), |
| 94 | 'type' => \Elementor\Controls_Manager::NUMBER, |
| 95 | 'default' => 0, |
| 96 | ] |
| 97 | ); |
| 98 | $this->add_control( |
| 99 | 'number_format', |
| 100 | [ |
| 101 | 'label' => esc_html__( 'Currency', 'cost-calculator-for-elementor' ), |
| 102 | 'type' => \Elementor\Controls_Manager::SWITCHER, |
| 103 | 'default' => 'yes' |
| 104 | ] |
| 105 | ); |
| 106 | $this->add_control( |
| 107 | 'number_format_symbols', |
| 108 | [ |
| 109 | 'name' => 'number_format_symbols', |
| 110 | 'label' => esc_html__( 'Symbols', 'cost-calculator-for-elementor' ), |
| 111 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 112 | 'condition' => [ |
| 113 | 'number_format' => 'yes' |
| 114 | ], |
| 115 | ] |
| 116 | ); |
| 117 | $this->add_control( |
| 118 | 'number_format_symbols_position', |
| 119 | [ |
| 120 | 'name' => 'number_format_symbols_position', |
| 121 | 'label' => esc_html__( 'Symbols Position', 'cost-calculator-for-elementor' ), |
| 122 | 'options'=> array("left"=>"Left","right"=>"Right"), |
| 123 | 'default' => 'left', |
| 124 | 'type' => \Elementor\Controls_Manager::SELECT, |
| 125 | 'condition' => [ |
| 126 | 'number_format' => 'yes' |
| 127 | ], |
| 128 | ] |
| 129 | ); |
| 130 | $this->add_control( |
| 131 | 'number_format_thousand_sep', |
| 132 | [ |
| 133 | 'name' => 'number_format_thousand_sep', |
| 134 | 'label' => esc_html__( 'Thousand separator', 'cost-calculator-for-elementor' ), |
| 135 | 'default' => ',', |
| 136 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 137 | 'condition' => [ |
| 138 | 'number_format' => 'yes' |
| 139 | ], |
| 140 | ] |
| 141 | ); |
| 142 | $this->add_control( |
| 143 | 'number_format_decimal_sep', |
| 144 | [ |
| 145 | 'name' => 'number_format_decimal_sep', |
| 146 | 'label' => esc_html__( 'Decimal separator', 'cost-calculator-for-elementor' ), |
| 147 | 'default' => '.', |
| 148 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 149 | 'condition' => [ |
| 150 | 'number_format' => 'yes' |
| 151 | ], |
| 152 | ] |
| 153 | ); |
| 154 | $this->add_control( |
| 155 | 'number_format_num_decimals', |
| 156 | [ |
| 157 | 'name' => 'number_format_num_decimals', |
| 158 | 'label' => esc_html__( 'Number Decimals', 'cost-calculator-for-elementor' ), |
| 159 | 'default' => 2, |
| 160 | 'type' => \Elementor\Controls_Manager::TEXT, |
| 161 | 'condition' => [ |
| 162 | 'number_format' => 'yes' |
| 163 | ], |
| 164 | ] |
| 165 | ); |
| 166 | $this->end_controls_section(); |
| 167 | } |
| 168 | /** |
| 169 | * Render currency widget output on the frontend. |
| 170 | * |
| 171 | * Written in PHP and used to generate the final HTML. |
| 172 | * |
| 173 | * @since 1.0.0 |
| 174 | * @access protected |
| 175 | */ |
| 176 | protected function render() { |
| 177 | $settings = $this->get_settings_for_display(); |
| 178 | $name = $settings["name"]; |
| 179 | $atts = ""; |
| 180 | $class = "elementor-number "; |
| 181 | if( $settings["number_format"] == "yes" ){ |
| 182 | $class .="elementor-number-format"; |
| 183 | $atts .='data-a-sign="'.$settings["number_format_symbols"].'" '; |
| 184 | $atts .='data-a-dec="'.$settings["number_format_decimal_sep"].'" '; |
| 185 | $atts .='data-a-sep="'.$settings["number_format_thousand_sep"].'" '; |
| 186 | $atts .='data-m-dec="'.$settings["number_format_num_decimals"].'" '; |
| 187 | if( $settings['number_format_symbols_position'] == "right" ){ |
| 188 | $atts .='data-p-sign="s" '; |
| 189 | } |
| 190 | } |
| 191 | ?> |
| 192 | <input <?php echo ($atts) ?> value="<?php echo esc_attr($settings["default"]) ?>" class="<?php echo esc_attr($class) ?>" type="text" name="<?php echo esc_attr($name) ?>" id="<?php echo esc_attr($name) ?>"> |
| 193 | <?php |
| 194 | } |
| 195 | } |