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