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
AmeliaEventsListBookingElementorWidget.php
230 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 AmeliaEventsListBookingElementorWidget |
| 14 | * |
| 15 | * @package AmeliaBooking\Infrastructure\WP\Elementor |
| 16 | */ |
| 17 | class AmeliaEventsListBookingElementorWidget extends Widget_Base |
| 18 | { |
| 19 | |
| 20 | public function get_name() { |
| 21 | return 'ameliaeventslistbooking'; |
| 22 | } |
| 23 | |
| 24 | public function get_title() { |
| 25 | return BackendStrings::getWordPressStrings()['events_list_booking_gutenberg_block']['title']; |
| 26 | } |
| 27 | |
| 28 | public function get_icon() { |
| 29 | return 'amelia-logo'; |
| 30 | } |
| 31 | |
| 32 | public function get_categories() { |
| 33 | return [ 'amelia-elementor' ]; |
| 34 | } |
| 35 | protected function register_controls() { |
| 36 | |
| 37 | $this->start_controls_section( |
| 38 | 'amelia_events_section', |
| 39 | [ |
| 40 | 'label' => '<div class="amelia-elementor-content"><p class="amelia-elementor-content-title">' |
| 41 | . BackendStrings::getWordPressStrings()['events_list_booking_gutenberg_block']['title'] |
| 42 | . '</p><br><p class="amelia-elementor-content-p">' |
| 43 | . BackendStrings::getWordPressStrings()['events_list_booking_gutenberg_block']['description'] |
| 44 | . '</p>', |
| 45 | ] |
| 46 | ); |
| 47 | |
| 48 | $this->add_control( |
| 49 | 'preselect', |
| 50 | [ |
| 51 | 'label' => BackendStrings::getWordPressStrings()['filter'], |
| 52 | 'type' => Controls_Manager::SWITCHER, |
| 53 | 'default' => false, |
| 54 | 'label_on' => BackendStrings::getCommonStrings()['yes'], |
| 55 | 'label_off' => BackendStrings::getCommonStrings()['no'], |
| 56 | ] |
| 57 | ); |
| 58 | |
| 59 | $this->add_control( |
| 60 | 'select_event', |
| 61 | [ |
| 62 | 'label' => BackendStrings::getWordPressStrings()['select_event'], |
| 63 | 'type' => Controls_Manager::SELECT2, |
| 64 | 'multiple' => true, |
| 65 | 'options' => self::amelia_elementor_get_events(), |
| 66 | 'condition' => ['preselect' => 'yes'], |
| 67 | 'placeholder' => BackendStrings::getWordPressStrings()['show_all_events'] |
| 68 | ] |
| 69 | ); |
| 70 | |
| 71 | $this->add_control( |
| 72 | 'select_tag', |
| 73 | [ |
| 74 | 'label' => BackendStrings::getWordPressStrings()['select_tag'], |
| 75 | 'type' => Controls_Manager::SELECT2, |
| 76 | 'multiple' => true, |
| 77 | 'options' => self::amelia_elementor_get_tags(), |
| 78 | 'condition' => ['preselect' => 'yes'], |
| 79 | 'placeholder' => BackendStrings::getWordPressStrings()['show_all_tags'] |
| 80 | ] |
| 81 | ); |
| 82 | |
| 83 | |
| 84 | $this->add_control( |
| 85 | 'select_location', |
| 86 | [ |
| 87 | 'label' => BackendStrings::getWordPressStrings()['select_location'], |
| 88 | 'type' => Controls_Manager::SELECT2, |
| 89 | 'multiple' => true, |
| 90 | 'options' => self::amelia_elementor_get_locations(), |
| 91 | 'condition' => ['preselect' => 'yes'], |
| 92 | 'placeholder' => BackendStrings::getWordPressStrings()['show_all_locations'] |
| 93 | ] |
| 94 | ); |
| 95 | |
| 96 | $this->add_control( |
| 97 | 'show_recurring', |
| 98 | [ |
| 99 | 'label' => __('Show recurring events:'), |
| 100 | 'type' => Controls_Manager::SWITCHER, |
| 101 | 'condition' => ['preselect' => 'yes'], |
| 102 | 'default' => false, |
| 103 | 'label_on' => BackendStrings::getCommonStrings()['yes'], |
| 104 | 'label_off' => BackendStrings::getCommonStrings()['no'], |
| 105 | ] |
| 106 | ); |
| 107 | |
| 108 | $this->add_control( |
| 109 | 'load_manually', |
| 110 | [ |
| 111 | 'label' => BackendStrings::getWordPressStrings()['manually_loading'], |
| 112 | 'label_block' => true, |
| 113 | 'type' => Controls_Manager::TEXT, |
| 114 | 'condition' => ['preselect' => 'yes'], |
| 115 | 'placeholder' => '', |
| 116 | 'description' => BackendStrings::getWordPressStrings()['manually_loading_description'], |
| 117 | ] |
| 118 | ); |
| 119 | |
| 120 | $this->add_control( |
| 121 | 'trigger_type', |
| 122 | [ |
| 123 | 'label' => BackendStrings::getWordPressStrings()['trigger_type'], |
| 124 | 'type' => Controls_Manager::SELECT, |
| 125 | 'condition' => ['preselect' => 'yes'], |
| 126 | 'description' => BackendStrings::getWordPressStrings()['trigger_type_tooltip'], |
| 127 | 'options' => [ |
| 128 | 'id' => BackendStrings::getWordPressStrings()['trigger_type_id'], |
| 129 | 'class' => BackendStrings::getWordPressStrings()['trigger_type_class'] |
| 130 | ], |
| 131 | 'default' => 'id' |
| 132 | ] |
| 133 | ); |
| 134 | |
| 135 | $this->add_control( |
| 136 | 'in_dialog', |
| 137 | [ |
| 138 | 'label' => BackendStrings::getWordPressStrings()['in_dialog'], |
| 139 | 'type' => Controls_Manager::SWITCHER, |
| 140 | 'condition' => ['preselect' => 'yes'], |
| 141 | 'default' => false, |
| 142 | 'label_on' => BackendStrings::getCommonStrings()['yes'], |
| 143 | 'label_off' => BackendStrings::getCommonStrings()['no'], |
| 144 | ] |
| 145 | ); |
| 146 | |
| 147 | $this->end_controls_section(); |
| 148 | } |
| 149 | |
| 150 | protected function render() { |
| 151 | |
| 152 | $settings = $this->get_settings_for_display(); |
| 153 | |
| 154 | if ($settings['preselect']) { |
| 155 | $trigger = $settings['load_manually'] !== '' ? ' trigger=' . $settings['load_manually'] : ''; |
| 156 | $trigger_type = $settings['load_manually'] && $settings['trigger_type'] !== '' ? ' trigger_type=' . $settings['trigger_type'] : ''; |
| 157 | $in_dialog = $settings['load_manually'] && $settings['in_dialog'] === 'yes' ? ' in_dialog=1' : ''; |
| 158 | |
| 159 | $selected_event = empty($settings['select_event']) ? '' : ' event=' . (is_array($settings['select_event']) ? |
| 160 | implode(',', $settings['select_event']) : $settings['select_event']); |
| 161 | |
| 162 | $show_recurring = $settings['show_recurring'] ? ' recurring=1' : ''; |
| 163 | |
| 164 | $selected_location = empty($settings['select_location']) ? '' : ' location=' . (is_array($settings['select_location']) ? |
| 165 | implode(',', $settings['select_location']) : $settings['select_location']); |
| 166 | |
| 167 | $selected_tag = ''; |
| 168 | if (!empty($settings['select_tag'])) { |
| 169 | $selected_tag .= ' tag="'; |
| 170 | if (is_array($settings['select_tag'])) { |
| 171 | foreach (array_filter($settings['select_tag']) as $index => $tag) { |
| 172 | $selected_tag .= ($index === 0 ? '' : ',') . '{' . $tag . '}'; |
| 173 | } |
| 174 | } else { |
| 175 | $selected_tag .= $settings['select_tag']; |
| 176 | } |
| 177 | $selected_tag .= '"'; |
| 178 | } |
| 179 | |
| 180 | echo '[ameliaeventslistbooking' . $trigger . $trigger_type . $in_dialog . $selected_event . $selected_location . $selected_tag . $show_recurring . ']'; |
| 181 | } else { |
| 182 | echo '[ameliaeventslistbooking]'; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | |
| 187 | public static function amelia_elementor_get_events() |
| 188 | { |
| 189 | $events = GutenbergBlock::getEntitiesData()['data']['events']; |
| 190 | |
| 191 | $returnEvents = []; |
| 192 | |
| 193 | $returnEvents['0'] = BackendStrings::getWordPressStrings()['show_all_events']; |
| 194 | |
| 195 | foreach ($events as $event) { |
| 196 | $returnEvents[$event['id']] = $event['name'] . ' (id: ' . $event['id'] . ') - ' . $event['formattedPeriodStart']; |
| 197 | } |
| 198 | |
| 199 | return $returnEvents; |
| 200 | } |
| 201 | |
| 202 | public static function amelia_elementor_get_locations() |
| 203 | { |
| 204 | $locations = GutenbergBlock::getEntitiesData()['data']['locations']; |
| 205 | |
| 206 | $returnLocations = []; |
| 207 | |
| 208 | $returnLocations['0'] = BackendStrings::getWordPressStrings()['show_all_locations']; |
| 209 | |
| 210 | foreach ($locations as $location) { |
| 211 | $returnLocations[$location['id']] = $location['name']; |
| 212 | } |
| 213 | |
| 214 | return $returnLocations; |
| 215 | } |
| 216 | |
| 217 | public static function amelia_elementor_get_tags() |
| 218 | { |
| 219 | $tags = GutenbergBlock::getEntitiesData()['data']['tags']; |
| 220 | |
| 221 | $returnTags = []; |
| 222 | |
| 223 | foreach ($tags as $index => $tag) { |
| 224 | $returnTags[$tag['name']] = $tag['name']; |
| 225 | } |
| 226 | |
| 227 | return $returnTags; |
| 228 | } |
| 229 | } |
| 230 |