AmeliaBookingElementorWidget.php
2 years ago
AmeliaCatalogBookingElementorWidget.php
1 year ago
AmeliaCatalogElementorWidget.php
2 years ago
AmeliaEventsCalendarBookingElementorWidget.php
1 year ago
AmeliaEventsElementorWidget.php
2 years ago
AmeliaEventsListBookingElementorWidget.php
2 years ago
AmeliaStepBookingElementorWidget.php
2 years ago
ElementorBlock.php
2 years ago
AmeliaStepBookingElementorWidget.php
264 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @copyright © TMS-Plugins. All rights reserved. |
| 4 | * @licence See LICENCE.md for license details. |
| 5 | */ |
| 6 | |
| 7 | namespace Elementor; |
| 8 | |
| 9 | use AmeliaBooking\Infrastructure\WP\GutenbergBlock\GutenbergBlock; |
| 10 | use AmeliaBooking\Infrastructure\WP\Translations\BackendStrings; |
| 11 | |
| 12 | /** |
| 13 | * Class AmeliaStepBookingElementorWidget |
| 14 | * |
| 15 | * @package AmeliaBooking\Infrastructure\WP\Elementor |
| 16 | */ |
| 17 | class AmeliaStepBookingElementorWidget extends Widget_Base |
| 18 | { |
| 19 | protected $controls_data; |
| 20 | |
| 21 | public function get_name() { |
| 22 | return 'stepbooking'; |
| 23 | } |
| 24 | |
| 25 | public function get_title() { |
| 26 | return BackendStrings::getWordPressStrings()['step_booking_gutenberg_block']['title']; |
| 27 | } |
| 28 | |
| 29 | public function get_icon() { |
| 30 | return 'amelia-logo'; |
| 31 | } |
| 32 | |
| 33 | public function get_categories() { |
| 34 | return [ 'amelia-elementor' ]; |
| 35 | } |
| 36 | |
| 37 | protected function register_controls() { |
| 38 | |
| 39 | $controls_data = self::amelia_elementor_get_data(); |
| 40 | |
| 41 | $this->start_controls_section( |
| 42 | 'amelia_booking_section', |
| 43 | [ |
| 44 | 'label' => '<div class="amelia-elementor-content"><p class="amelia-elementor-content-title">' |
| 45 | . BackendStrings::getWordPressStrings()['step_booking_gutenberg_block']['title'] |
| 46 | . '</p><br><p class="amelia-elementor-content-p">' |
| 47 | . BackendStrings::getWordPressStrings()['step_booking_gutenberg_block']['description'] |
| 48 | . '</p>', |
| 49 | ] |
| 50 | ); |
| 51 | |
| 52 | $this->add_control( |
| 53 | 'preselect', |
| 54 | [ |
| 55 | 'label' => BackendStrings::getWordPressStrings()['filter'], |
| 56 | 'type' => Controls_Manager::SWITCHER, |
| 57 | 'default' => false, |
| 58 | 'label_on' => BackendStrings::getCommonStrings()['yes'], |
| 59 | 'label_off' => BackendStrings::getCommonStrings()['no'], |
| 60 | ] |
| 61 | ); |
| 62 | |
| 63 | if ($controls_data['categories'] && sizeof($controls_data['categories']) > 1) { |
| 64 | $this->add_control( |
| 65 | 'select_category', |
| 66 | [ |
| 67 | 'label' => BackendStrings::getWordPressStrings()['select_category'], |
| 68 | 'type' => Controls_Manager::SELECT2, |
| 69 | 'multiple' => true, |
| 70 | 'options' => $controls_data['categories'], |
| 71 | 'condition' => ['preselect' => 'yes'], |
| 72 | 'placeholder' => BackendStrings::getWordPressStrings()['show_all_categories'] |
| 73 | ] |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | if ($controls_data['services'] && sizeof($controls_data['services']) > 1) { |
| 78 | $this->add_control( |
| 79 | 'select_service', |
| 80 | [ |
| 81 | 'label' => BackendStrings::getWordPressStrings()['select_service'], |
| 82 | 'type' => Controls_Manager::SELECT2, |
| 83 | 'multiple' => true, |
| 84 | 'options' => $controls_data['services'], |
| 85 | 'condition' => ['preselect' => 'yes'], |
| 86 | 'placeholder' => BackendStrings::getWordPressStrings()['show_all_services'], |
| 87 | ] |
| 88 | ); |
| 89 | } |
| 90 | |
| 91 | if ($controls_data['employees'] && sizeof($controls_data['employees']) > 1) { |
| 92 | $this->add_control( |
| 93 | 'select_employee', |
| 94 | [ |
| 95 | 'label' => BackendStrings::getWordPressStrings()['select_employee'], |
| 96 | 'type' => Controls_Manager::SELECT2, |
| 97 | 'multiple' => true, |
| 98 | 'options' => $controls_data['employees'], |
| 99 | 'condition' => ['preselect' => 'yes'], |
| 100 | 'placeholder' => BackendStrings::getWordPressStrings()['show_all_employees'], |
| 101 | ] |
| 102 | ); |
| 103 | } |
| 104 | |
| 105 | if ($controls_data['locations'] && sizeof($controls_data['locations']) > 1) { |
| 106 | $this->add_control( |
| 107 | 'select_location', |
| 108 | [ |
| 109 | 'label' => BackendStrings::getWordPressStrings()['select_location'], |
| 110 | 'type' => Controls_Manager::SELECT2, |
| 111 | 'multiple' => true, |
| 112 | 'options' => $controls_data['locations'], |
| 113 | 'condition' => ['preselect' => 'yes'], |
| 114 | 'placeholder' => BackendStrings::getWordPressStrings()['show_all_locations'], |
| 115 | ] |
| 116 | ); |
| 117 | } |
| 118 | |
| 119 | if ($controls_data['show']) { |
| 120 | $this->add_control( |
| 121 | 'select_package', |
| 122 | [ |
| 123 | 'label' => BackendStrings::getWordPressStrings()['select_package'], |
| 124 | 'type' => Controls_Manager::SELECT2, |
| 125 | 'multiple' => true, |
| 126 | 'options' => $controls_data['packages'], |
| 127 | 'condition' => ['preselect' => 'yes'], |
| 128 | 'placeholder' => BackendStrings::getWordPressStrings()['show_all_packages'], |
| 129 | ] |
| 130 | ); |
| 131 | } |
| 132 | |
| 133 | if ($controls_data['show']) { |
| 134 | $this->add_control( |
| 135 | 'select_show', |
| 136 | [ |
| 137 | 'label' => BackendStrings::getWordPressStrings()['show_all'], |
| 138 | 'type' => Controls_Manager::SELECT, |
| 139 | 'options' => $controls_data['show'], |
| 140 | 'condition' => ['preselect' => 'yes'], |
| 141 | 'default' => '', |
| 142 | ] |
| 143 | ); |
| 144 | } |
| 145 | |
| 146 | $this->add_control( |
| 147 | 'load_manually', |
| 148 | [ |
| 149 | 'label' => BackendStrings::getWordPressStrings()['manually_loading'], |
| 150 | 'label_block' => true, |
| 151 | 'type' => Controls_Manager::TEXT, |
| 152 | 'placeholder' => '', |
| 153 | 'description' => BackendStrings::getWordPressStrings()['manually_loading_description'], |
| 154 | ] |
| 155 | ); |
| 156 | |
| 157 | $this->add_control( |
| 158 | 'trigger_type', |
| 159 | [ |
| 160 | 'label' => BackendStrings::getWordPressStrings()['trigger_type'], |
| 161 | 'type' => Controls_Manager::SELECT, |
| 162 | 'description' => BackendStrings::getWordPressStrings()['trigger_type_tooltip'], |
| 163 | 'options' => $controls_data['trigger_types'], |
| 164 | 'default' => 'id' |
| 165 | ] |
| 166 | ); |
| 167 | |
| 168 | $this->add_control( |
| 169 | 'in_dialog', |
| 170 | [ |
| 171 | 'label' => BackendStrings::getWordPressStrings()['in_dialog'], |
| 172 | 'type' => Controls_Manager::SWITCHER, |
| 173 | 'default' => false, |
| 174 | 'label_on' => BackendStrings::getCommonStrings()['yes'], |
| 175 | 'label_off' => BackendStrings::getCommonStrings()['no'], |
| 176 | ] |
| 177 | ); |
| 178 | |
| 179 | $this->end_controls_section(); |
| 180 | } |
| 181 | protected function render() { |
| 182 | $settings = $this->get_settings_for_display(); |
| 183 | |
| 184 | $trigger = $settings['load_manually'] !== '' ? ' trigger=' . $settings['load_manually'] : ''; |
| 185 | $trigger_type = $settings['load_manually'] && $settings['trigger_type'] !== '' ? ' trigger_type=' . $settings['trigger_type'] : ''; |
| 186 | $in_dialog = $settings['load_manually'] && $settings['in_dialog'] === 'yes' ? ' in_dialog=1' : ''; |
| 187 | |
| 188 | $category = empty($settings['select_category']) ? '' : ' category=' . (is_array($settings['select_category']) ? |
| 189 | implode(',', $settings['select_category']) : $settings['select_category']); |
| 190 | $service = empty($settings['select_service']) ? '' : ' service=' . (is_array($settings['select_service']) ? |
| 191 | implode(',', $settings['select_service']) : $settings['select_service']); |
| 192 | |
| 193 | $category_service = empty($settings['select_service']) ? $category : $service; |
| 194 | |
| 195 | $employee = empty($settings['select_employee']) ? '' : ' employee=' . (is_array($settings['select_employee']) ? |
| 196 | implode(',', $settings['select_employee']) : $settings['select_employee']); |
| 197 | $location = empty($settings['select_location']) ? '' : ' location=' . (is_array($settings['select_location']) ? |
| 198 | implode(',', $settings['select_location']) : $settings['select_location']); |
| 199 | $package = empty($settings['select_package']) ? '' : ' package=' . (is_array($settings['select_package']) ? |
| 200 | implode(',', $settings['select_package']) : $settings['select_package']); |
| 201 | |
| 202 | $show = empty($settings['select_show']) ? '' : ' show=' . $settings['select_show']; |
| 203 | |
| 204 | $shortcode = '[ameliastepbooking' . $trigger . $trigger_type . $in_dialog; |
| 205 | if ($settings['preselect']) { |
| 206 | echo $shortcode . $show . $category_service . $employee . $location . $package . ']'; |
| 207 | } else { |
| 208 | echo $shortcode . ']'; |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | |
| 213 | public static function amelia_elementor_get_data() { |
| 214 | $data = GutenbergBlock::getEntitiesData()['data']; |
| 215 | $elementorData = []; |
| 216 | |
| 217 | $elementorData['categories'] = []; |
| 218 | |
| 219 | foreach ($data['categories'] as $category) { |
| 220 | $elementorData['categories'][$category['id']] = $category['name'] . ' (id: ' . $category['id'] . ')'; |
| 221 | } |
| 222 | |
| 223 | $elementorData['services'] = []; |
| 224 | |
| 225 | foreach ($data['servicesList'] as $service) { |
| 226 | if ($service) { |
| 227 | $elementorData['services'][$service['id']] = $service['name'] . ' (id: ' . $service['id'] . ')'; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | $elementorData['employees'] = []; |
| 232 | |
| 233 | foreach ($data['employees'] as $provider) { |
| 234 | $elementorData['employees'][$provider['id']] = $provider['firstName'] . $provider['lastName'] . ' (id: ' . $provider['id'] . ')'; |
| 235 | } |
| 236 | |
| 237 | $elementorData['locations'] = []; |
| 238 | |
| 239 | foreach ($data['locations'] as $location) { |
| 240 | $elementorData['locations'][$location['id']] = $location['name'] . ' (id: ' . $location['id'] . ')'; |
| 241 | } |
| 242 | |
| 243 | $elementorData['packages'] = []; |
| 244 | |
| 245 | foreach ($data['packages'] as $package) { |
| 246 | $elementorData['packages'][$package['id']] = $package['name'] . ' (id: ' . $package['id'] . ')'; |
| 247 | } |
| 248 | |
| 249 | |
| 250 | $elementorData['show'] = $data['packages'] ? [ |
| 251 | '' => BackendStrings::getWordPressStrings()['show_all'], |
| 252 | 'services' => BackendStrings::getCommonStrings()['services'], |
| 253 | 'packages' => BackendStrings::getCommonStrings()['packages'] |
| 254 | ] : []; |
| 255 | |
| 256 | $elementorData['trigger_types'] = [ |
| 257 | 'id' => BackendStrings::getWordPressStrings()['trigger_type_id'], |
| 258 | 'class' => BackendStrings::getWordPressStrings()['trigger_type_class'] |
| 259 | ]; |
| 260 | |
| 261 | return $elementorData; |
| 262 | } |
| 263 | } |
| 264 |