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
AmeliaEventsElementorWidget.php
181 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 | use AmeliaBooking\Infrastructure\Licence; |
| 12 | |
| 13 | /** |
| 14 | * Class AmeliaEventsElementorWidget |
| 15 | * |
| 16 | * @package AmeliaBooking\Infrastructure\WP\Elementor |
| 17 | */ |
| 18 | class AmeliaEventsElementorWidget extends Widget_Base |
| 19 | { |
| 20 | |
| 21 | public function get_name() { |
| 22 | return 'ameliaevents'; |
| 23 | } |
| 24 | |
| 25 | public function get_title() { |
| 26 | return BackendStrings::getWordPressStrings()['events_gutenberg_block']['title']; |
| 27 | } |
| 28 | |
| 29 | public function get_icon() { |
| 30 | return 'amelia-logo-outdated'; |
| 31 | } |
| 32 | |
| 33 | public function get_categories() { |
| 34 | return [ 'amelia-elementor' ]; |
| 35 | } |
| 36 | protected function register_controls() { |
| 37 | |
| 38 | $isLite = !Licence\Licence::$premium; |
| 39 | |
| 40 | $this->start_controls_section( |
| 41 | 'amelia_events_section', |
| 42 | [ |
| 43 | 'label' => '<div class="amelia-elementor-content-outdated"><p class="amelia-elementor-content-title">' |
| 44 | . BackendStrings::getWordPressStrings()['events_gutenberg_block']['title'] |
| 45 | . '</p><br><p class="amelia-elementor-content-p">' |
| 46 | . BackendStrings::getWordPressStrings()['events_gutenberg_block']['description'] |
| 47 | . '</p><br><p class="amelia-elementor-content-p amelia-elementor-content-p-outdated">' |
| 48 | . BackendStrings::getWordPressStrings()['outdated_booking_gutenberg_block'] |
| 49 | . '</p>', |
| 50 | ] |
| 51 | ); |
| 52 | |
| 53 | if (!$isLite) { |
| 54 | $this->add_control( |
| 55 | 'selected_type', |
| 56 | [ |
| 57 | 'label' => BackendStrings::getWordPressStrings()['show_event_view_type'], |
| 58 | 'type' => Controls_Manager::SELECT, |
| 59 | 'options' => [ |
| 60 | 'list' => BackendStrings::getWordPressStrings()['show_event_view_list'], |
| 61 | 'calendar' => BackendStrings::getWordPressStrings()['show_event_view_calendar'] |
| 62 | ], |
| 63 | 'default' => 'list', |
| 64 | ] |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | $this->add_control( |
| 69 | 'preselect', |
| 70 | [ |
| 71 | 'label' => BackendStrings::getWordPressStrings()['filter'], |
| 72 | 'type' => Controls_Manager::SWITCHER, |
| 73 | 'default' => false, |
| 74 | 'label_on' => BackendStrings::getCommonStrings()['yes'], |
| 75 | 'label_off' => BackendStrings::getCommonStrings()['no'], |
| 76 | ] |
| 77 | ); |
| 78 | |
| 79 | $this->add_control( |
| 80 | 'select_event', |
| 81 | [ |
| 82 | 'label' => BackendStrings::getWordPressStrings()['select_event'], |
| 83 | 'type' => Controls_Manager::SELECT, |
| 84 | 'options' => self::amelia_elementor_get_events(), |
| 85 | 'condition' => ['preselect' => 'yes'], |
| 86 | 'default' => '0', |
| 87 | ] |
| 88 | ); |
| 89 | |
| 90 | $this->add_control( |
| 91 | 'select_tag', |
| 92 | [ |
| 93 | 'label' => BackendStrings::getWordPressStrings()['select_tag'], |
| 94 | 'type' => Controls_Manager::SELECT, |
| 95 | 'options' => self::amelia_elementor_get_tags(), |
| 96 | 'condition' => ['preselect' => 'yes'], |
| 97 | 'default' => '', |
| 98 | ] |
| 99 | ); |
| 100 | |
| 101 | $this->add_control( |
| 102 | 'show_recurring', |
| 103 | [ |
| 104 | 'label' => __('Show recurring events:'), |
| 105 | 'type' => Controls_Manager::SWITCHER, |
| 106 | 'condition' => ['preselect' => 'yes'], |
| 107 | 'default' => false, |
| 108 | 'label_on' => BackendStrings::getCommonStrings()['yes'], |
| 109 | 'label_off' => BackendStrings::getCommonStrings()['no'], |
| 110 | ] |
| 111 | ); |
| 112 | |
| 113 | $this->add_control( |
| 114 | 'load_manually', |
| 115 | [ |
| 116 | 'label' => BackendStrings::getWordPressStrings()['manually_loading'], |
| 117 | 'label_block' => true, |
| 118 | 'type' => Controls_Manager::TEXT, |
| 119 | 'condition' => ['preselect' => 'yes'], |
| 120 | 'placeholder' => '', |
| 121 | 'description' => BackendStrings::getWordPressStrings()['manually_loading_description'], |
| 122 | ] |
| 123 | ); |
| 124 | |
| 125 | $this->end_controls_section(); |
| 126 | } |
| 127 | |
| 128 | protected function render() { |
| 129 | |
| 130 | $settings = $this->get_settings_for_display(); |
| 131 | |
| 132 | $selected_type = $settings['selected_type'] ? ' type=' . $settings['selected_type'] : ''; |
| 133 | |
| 134 | if ($settings['preselect']) { |
| 135 | $trigger = $settings['load_manually'] !== '' ? ' trigger=' . $settings['load_manually'] : ''; |
| 136 | |
| 137 | $selected_event = $settings['select_event'] === '0' ? '' : ' event=' . $settings['select_event']; |
| 138 | |
| 139 | $show_recurring = $settings['show_recurring'] ? ' recurring=1' : ''; |
| 140 | |
| 141 | $selected_tag = $settings['select_tag'] ? ' tag=' . '"' . $settings['select_tag'] . '"' : ''; |
| 142 | |
| 143 | echo '[ameliaevents' . $selected_type . $trigger . $selected_event . $selected_tag . $show_recurring . ']'; |
| 144 | } else { |
| 145 | $selected_type = $settings['selected_type'] ? ' type=' . $settings['selected_type'] : ''; |
| 146 | echo '[ameliaevents' . $selected_type . ']'; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | |
| 151 | public static function amelia_elementor_get_events() |
| 152 | { |
| 153 | $events = GutenbergBlock::getEntitiesData()['data']['events']; |
| 154 | |
| 155 | $returnEvents = []; |
| 156 | |
| 157 | $returnEvents['0'] = BackendStrings::getWordPressStrings()['show_all_events']; |
| 158 | |
| 159 | foreach ($events as $event) { |
| 160 | $returnEvents[$event['id']] = $event['name'] . ' (id: ' . $event['id'] . ') - ' . $event['formattedPeriodStart']; |
| 161 | } |
| 162 | |
| 163 | return $returnEvents; |
| 164 | } |
| 165 | |
| 166 | public static function amelia_elementor_get_tags() |
| 167 | { |
| 168 | $tags = GutenbergBlock::getEntitiesData()['data']['tags']; |
| 169 | |
| 170 | $returnTags = []; |
| 171 | |
| 172 | $returnTags[''] = BackendStrings::getWordPressStrings()['show_all_tags']; |
| 173 | |
| 174 | foreach ($tags as $index => $tag) { |
| 175 | $returnTags[$tag['name']] = $tag['name']; |
| 176 | } |
| 177 | |
| 178 | return $returnTags; |
| 179 | } |
| 180 | } |
| 181 |