AmeliaBookingElementorWidget.php
2 years ago
AmeliaCatalogBookingElementorWidget.php
2 years 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
AmeliaCatalogBookingElementorWidget.php
309 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 AmeliaCatalogBookingElementorWidget |
| 14 | * |
| 15 | * @package AmeliaBooking\Infrastructure\WP\Elementor |
| 16 | */ |
| 17 | class AmeliaCatalogBookingElementorWidget extends Widget_Base |
| 18 | { |
| 19 | protected $controls_data; |
| 20 | |
| 21 | public function get_name() { |
| 22 | return 'catalogbooking'; |
| 23 | } |
| 24 | |
| 25 | public function get_title() { |
| 26 | return BackendStrings::getWordPressStrings()['catalog_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_catalog_section', |
| 43 | [ |
| 44 | 'label' => '<div class="amelia-elementor-content"><p class="amelia-elementor-content-title">' |
| 45 | . BackendStrings::getWordPressStrings()['catalog_booking_gutenberg_block']['title'] |
| 46 | . '</p><br><p class="amelia-elementor-content-p">' |
| 47 | . BackendStrings::getWordPressStrings()['catalog_booking_gutenberg_block']['description'] |
| 48 | . '</p>', |
| 49 | ] |
| 50 | ); |
| 51 | |
| 52 | $options = [ |
| 53 | 'show_catalog' => BackendStrings::getWordPressStrings()['show_catalog'], |
| 54 | 'show_category' => BackendStrings::getWordPressStrings()['show_categories'], |
| 55 | 'show_service' => BackendStrings::getWordPressStrings()['show_services'], |
| 56 | ]; |
| 57 | |
| 58 | if ($controls_data['packages']) { |
| 59 | $options['show_package'] = BackendStrings::getWordPressStrings()['show_packages']; |
| 60 | } |
| 61 | |
| 62 | if ($controls_data['categories'] && sizeof($controls_data['locations']) > 1) {} |
| 63 | |
| 64 | $this->add_control( |
| 65 | 'select_catalog', |
| 66 | [ |
| 67 | 'label' => BackendStrings::getWordPressStrings()['select_catalog_view'], |
| 68 | 'type' => Controls_Manager::SELECT, |
| 69 | 'label_block' => true, |
| 70 | 'options' => $options, |
| 71 | 'default' => 'show_catalog', |
| 72 | ] |
| 73 | ); |
| 74 | |
| 75 | $this->add_control( |
| 76 | 'select_category', |
| 77 | [ |
| 78 | 'label' => BackendStrings::getWordPressStrings()['select_category'], |
| 79 | 'type' => Controls_Manager::SELECT2, |
| 80 | 'multiple' => true, |
| 81 | 'options' => $controls_data['categories'], |
| 82 | 'condition' => ['select_catalog' => 'show_category'], |
| 83 | 'default' => array_keys($controls_data['categories']) ? [array_keys($controls_data['categories'])[0]] : 0, |
| 84 | ] |
| 85 | ); |
| 86 | |
| 87 | if ($controls_data['services'] && sizeof($controls_data['services']) > 1) { |
| 88 | $this->add_control( |
| 89 | 'select_service', |
| 90 | [ |
| 91 | 'label' => BackendStrings::getWordPressStrings()['select_service'], |
| 92 | 'type' => Controls_Manager::SELECT2, |
| 93 | 'multiple' => true, |
| 94 | 'options' => $controls_data['services'], |
| 95 | 'condition' => ['select_catalog' => 'show_service'], |
| 96 | 'default' => array_keys($controls_data['services']) ? [array_keys($controls_data['services'])[0]] : 0, |
| 97 | ] |
| 98 | ); |
| 99 | } |
| 100 | |
| 101 | if ($controls_data['packages']) { |
| 102 | $this->add_control( |
| 103 | 'select_package', |
| 104 | [ |
| 105 | 'label' => BackendStrings::getWordPressStrings()['select_package'], |
| 106 | 'type' => Controls_Manager::SELECT2, |
| 107 | 'multiple' => true, |
| 108 | 'options' => $controls_data['packages'], |
| 109 | 'condition' => ['select_catalog' => 'show_package'], |
| 110 | 'default' => array_keys($controls_data['packages']) ? [array_keys($controls_data['packages'])[0]] : 0, |
| 111 | ] |
| 112 | ); |
| 113 | } |
| 114 | |
| 115 | $this->add_control( |
| 116 | 'preselect', |
| 117 | [ |
| 118 | 'label' => BackendStrings::getWordPressStrings()['filter'], |
| 119 | 'type' => Controls_Manager::SWITCHER, |
| 120 | 'default' => false, |
| 121 | 'label_on' => BackendStrings::getCommonStrings()['yes'], |
| 122 | 'label_off' => BackendStrings::getCommonStrings()['no'], |
| 123 | ] |
| 124 | ); |
| 125 | |
| 126 | $this->add_control( |
| 127 | 'skip_categories', |
| 128 | [ |
| 129 | 'label' => BackendStrings::getWordPressStrings()['skip_categories'], |
| 130 | 'type' => Controls_Manager::SWITCHER, |
| 131 | 'default' => false, |
| 132 | 'label_on' => BackendStrings::getCommonStrings()['yes'], |
| 133 | 'label_off' => BackendStrings::getCommonStrings()['no'], |
| 134 | 'condition' => ['preselect' => 'yes'], |
| 135 | ] |
| 136 | ); |
| 137 | |
| 138 | if ($controls_data['employees'] && sizeof($controls_data['employees']) > 1) { |
| 139 | $this->add_control( |
| 140 | 'select_employee', |
| 141 | [ |
| 142 | 'label' => BackendStrings::getWordPressStrings()['select_employee'], |
| 143 | 'type' => Controls_Manager::SELECT2, |
| 144 | 'multiple' => true, |
| 145 | 'options' => $controls_data['employees'], |
| 146 | 'condition' => ['preselect' => 'yes'], |
| 147 | ] |
| 148 | ); |
| 149 | } |
| 150 | |
| 151 | if ($controls_data['locations'] && sizeof($controls_data['locations']) > 1) { |
| 152 | $this->add_control( |
| 153 | 'select_location', |
| 154 | [ |
| 155 | 'label' => BackendStrings::getWordPressStrings()['select_location'], |
| 156 | 'type' => Controls_Manager::SELECT2, |
| 157 | 'multiple' => true, |
| 158 | 'options' => $controls_data['locations'], |
| 159 | 'condition' => ['preselect' => 'yes'], |
| 160 | ] |
| 161 | ); |
| 162 | } |
| 163 | |
| 164 | if ($controls_data['show']) { |
| 165 | $this->add_control( |
| 166 | 'select_show', |
| 167 | [ |
| 168 | 'label' => BackendStrings::getWordPressStrings()['show_all'], |
| 169 | 'type' => Controls_Manager::SELECT, |
| 170 | 'options' => $controls_data['show'], |
| 171 | 'condition' => ['preselect' => 'yes'], |
| 172 | 'default' => '', |
| 173 | ] |
| 174 | ); |
| 175 | } |
| 176 | |
| 177 | $this->add_control( |
| 178 | 'load_manually', |
| 179 | [ |
| 180 | 'label' => BackendStrings::getWordPressStrings()['manually_loading'], |
| 181 | 'label_block' => true, |
| 182 | 'type' => Controls_Manager::TEXT, |
| 183 | 'placeholder' => '', |
| 184 | 'description' => BackendStrings::getWordPressStrings()['manually_loading_description'], |
| 185 | ] |
| 186 | ); |
| 187 | |
| 188 | $this->add_control( |
| 189 | 'trigger_type', |
| 190 | [ |
| 191 | 'label' => BackendStrings::getWordPressStrings()['trigger_type'], |
| 192 | 'type' => Controls_Manager::SELECT, |
| 193 | 'description' => BackendStrings::getWordPressStrings()['trigger_type_tooltip'], |
| 194 | 'options' => $controls_data['trigger_types'], |
| 195 | 'default' => 'id' |
| 196 | ] |
| 197 | ); |
| 198 | |
| 199 | $this->add_control( |
| 200 | 'in_dialog', |
| 201 | [ |
| 202 | 'label' => BackendStrings::getWordPressStrings()['in_dialog'], |
| 203 | 'type' => Controls_Manager::SWITCHER, |
| 204 | 'default' => false, |
| 205 | 'label_on' => BackendStrings::getCommonStrings()['yes'], |
| 206 | 'label_off' => BackendStrings::getCommonStrings()['no'], |
| 207 | ] |
| 208 | ); |
| 209 | |
| 210 | $this->end_controls_section(); |
| 211 | } |
| 212 | |
| 213 | protected function render() { |
| 214 | $settings = $this->get_settings_for_display(); |
| 215 | |
| 216 | if ($settings['select_catalog'] === 'show_package') { |
| 217 | $this->remove_control('select_show'); |
| 218 | } |
| 219 | |
| 220 | $skip_categories = $settings['skip_categories'] === 'yes' ? ' categories_hidden=1' : ''; |
| 221 | |
| 222 | $trigger = $settings['load_manually'] !== '' ? ' trigger=' . $settings['load_manually'] : ''; |
| 223 | $trigger_type = $settings['load_manually'] && $settings['trigger_type'] !== '' ? ' trigger_type=' . $settings['trigger_type'] : ''; |
| 224 | $in_dialog = $settings['load_manually'] && $settings['in_dialog'] === 'yes' ? ' in_dialog=1' : ''; |
| 225 | |
| 226 | $show = ''; |
| 227 | |
| 228 | if ($settings['select_catalog'] === 'show_catalog') { |
| 229 | $category_service = ''; |
| 230 | |
| 231 | $show = empty($settings['select_show']) ? '' : ' show=' . $settings['select_show']; |
| 232 | } elseif ($settings['select_catalog'] === 'show_category' && !empty($settings['select_category'])) { |
| 233 | $category_service = ' category=' . (is_array($settings['select_category']) ? |
| 234 | implode(',', $settings['select_category']) : $settings['select_category']); |
| 235 | |
| 236 | $show = empty($settings['select_show']) ? '' : ' show=' . $settings['select_show']; |
| 237 | } elseif ($settings['select_catalog'] === 'show_service' && !empty($settings['select_service'])) { |
| 238 | $category_service = ' service=' . (is_array($settings['select_service']) ? |
| 239 | implode(',', $settings['select_service']) : $settings['select_service']); |
| 240 | |
| 241 | $show = empty($settings['select_show']) || $settings['select_show'] === 'packages' ? '' : ' show=' . $settings['select_show']; |
| 242 | } elseif ($settings['select_catalog'] === 'show_package' && !empty($settings['select_package'])) { |
| 243 | $category_service = ' package=' . (is_array($settings['select_package']) ? |
| 244 | implode(',', $settings['select_package']) : $settings['select_package']); |
| 245 | } else { |
| 246 | $category_service = ''; |
| 247 | } |
| 248 | |
| 249 | if ($settings['preselect']) { |
| 250 | $employee = empty($settings['select_employee']) ? '' : ' employee=' . (is_array($settings['select_employee']) ? |
| 251 | implode(',', $settings['select_employee']) : $settings['select_employee']); |
| 252 | $location = empty($settings['select_location']) ? '' : ' location=' . (is_array($settings['select_location']) ? |
| 253 | implode(',', $settings['select_location']) : $settings['select_location']); |
| 254 | } else { |
| 255 | $employee = ''; |
| 256 | $location = ''; |
| 257 | } |
| 258 | echo esc_html('[ameliacatalogbooking' . $show . $trigger . $trigger_type . $in_dialog . $category_service . $employee . $location . $skip_categories . ']'); |
| 259 | } |
| 260 | |
| 261 | public static function amelia_elementor_get_data() { |
| 262 | $data = GutenbergBlock::getEntitiesData()['data']; |
| 263 | $elementorData = []; |
| 264 | |
| 265 | $elementorData['categories'] = []; |
| 266 | |
| 267 | foreach ($data['categories'] as $category) { |
| 268 | $elementorData['categories'][$category['id']] = $category['name'] . ' (id: ' . $category['id'] . ')'; |
| 269 | } |
| 270 | |
| 271 | $elementorData['services'] = []; |
| 272 | |
| 273 | foreach ($data['servicesList'] as $service) { |
| 274 | if ($service) { |
| 275 | $elementorData['services'][$service['id']] = $service['name'] . ' (id: ' . $service['id'] . ')'; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | $elementorData['packages'] = []; |
| 280 | |
| 281 | foreach ($data['packages'] as $package) { |
| 282 | $elementorData['packages'][$package['id']] = $package['name'] . ' (id: ' . $package['id'] . ')'; |
| 283 | } |
| 284 | |
| 285 | $elementorData['employees'] = []; |
| 286 | foreach ($data['employees'] as $provider) { |
| 287 | $elementorData['employees'][$provider['id']] = $provider['firstName'] . $provider['lastName'] . ' (id: ' . $provider['id'] . ')'; |
| 288 | } |
| 289 | |
| 290 | $elementorData['locations'] = []; |
| 291 | foreach ($data['locations'] as $location) { |
| 292 | $elementorData['locations'][$location['id']] = $location['name'] . ' (id: ' . $location['id'] . ')'; |
| 293 | } |
| 294 | |
| 295 | $elementorData['show'] = $data['packages'] ? [ |
| 296 | '' => BackendStrings::getWordPressStrings()['show_all'], |
| 297 | 'services' => BackendStrings::getCommonStrings()['services'], |
| 298 | 'packages' => BackendStrings::getCommonStrings()['packages'] |
| 299 | ] : []; |
| 300 | |
| 301 | $elementorData['trigger_types'] = [ |
| 302 | 'id' => BackendStrings::getWordPressStrings()['trigger_type_id'], |
| 303 | 'class' => BackendStrings::getWordPressStrings()['trigger_type_class'] |
| 304 | ]; |
| 305 | |
| 306 | return $elementorData; |
| 307 | } |
| 308 | } |
| 309 |