PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.9 2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / src / Infrastructure / WP / Elementor / AmeliaEventsListBookingElementorWidget.php
ameliabooking / src / Infrastructure / WP / Elementor Last commit date
AmeliaBookingElementorWidget.php 1 week ago AmeliaCatalogBookingElementorWidget.php 1 week ago AmeliaCatalogElementorWidget.php 1 week ago AmeliaElementorWhiteLabelHelper.php 1 week ago AmeliaEventsCalendarBookingElementorWidget.php 1 week ago AmeliaEventsElementorWidget.php 1 week ago AmeliaEventsListBookingButtonElementorWidget.php 1 week ago AmeliaEventsListBookingElementorWidget.php 1 week ago AmeliaStepBookingButtonElementorWidget.php 1 week ago AmeliaStepBookingElementorWidget.php 1 week ago ElementorBlock.php 1 week ago ElementorSharedShortcodeWidget.php 2 months ago
AmeliaEventsListBookingElementorWidget.php
284 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 AmeliaEventsListBookingElementorWidget
15 *
16 * @package AmeliaBooking\Infrastructure\WP\Elementor
17 */
18 class AmeliaEventsListBookingElementorWidget extends ElementorSharedShortcodeWidget
19 {
20 public function get_name()
21 {
22 return 'ameliaeventslistbooking';
23 }
24
25 public function get_title()
26 {
27 return AmeliaElementorWhiteLabelHelper::label(BackendStrings::get('events_list_booking_gutenberg_block')['title']);
28 }
29
30 public function get_icon()
31 {
32 return AmeliaElementorWhiteLabelHelper::icon();
33 }
34
35 public function get_categories()
36 {
37 return [ 'amelia-elementor' ];
38 }
39 protected function register_controls()
40 {
41 $controls_data = [];
42
43 ElementorSharedShortcodeWidget::setSharedShortcodeData(GutenbergBlock::getEntitiesData()['data'], $controls_data);
44
45 $this->start_controls_section(
46 'amelia_events_section',
47 [
48 'label' => '<div class="amelia-elementor-content"><p class="amelia-elementor-content-title">'
49 . AmeliaElementorWhiteLabelHelper::label(BackendStrings::get('events_list_booking_gutenberg_block')['title'])
50 . '</p><br><p class="amelia-elementor-content-p">'
51 . AmeliaElementorWhiteLabelHelper::label(BackendStrings::get('events_list_booking_gutenberg_block')['description'])
52 . '</p>',
53 ]
54 );
55
56 $this->add_control(
57 'preselect',
58 [
59 'label' => BackendStrings::get('filter'),
60 'type' => Controls_Manager::SWITCHER,
61 'default' => false,
62 'label_on' => BackendStrings::get('yes'),
63 'label_off' => BackendStrings::get('no'),
64 ]
65 );
66
67 $this->add_control(
68 'event_to_show',
69 [
70 'label' => BackendStrings::get('event_time_scope'),
71 'type' => Controls_Manager::SELECT,
72 'condition' => ['preselect' => 'yes'],
73 'default' => 'all',
74 'options' => [
75 'all' => BackendStrings::get('all_events'),
76 'future' => BackendStrings::get('future_events'),
77 'past' => BackendStrings::get('past_events'),
78 'custom' => BackendStrings::get('custom_range'),
79 ],
80 ]
81 );
82
83 $this->add_control(
84 'start_date',
85 [
86 'label' => BackendStrings::get('red_start_date'),
87 'type' => Controls_Manager::DATE_TIME,
88 'picker_options' => [
89 'enableTime' => false,
90 'dateFormat' => 'Y-m-d',
91 ],
92 'condition' => [
93 'preselect' => 'yes',
94 'event_to_show' => 'custom'
95 ],
96 ]
97 );
98
99 $this->add_control(
100 'end_date',
101 [
102 'label' => BackendStrings::get('red_end_date'),
103 'type' => Controls_Manager::DATE_TIME,
104 'picker_options' => [
105 'enableTime' => false,
106 'dateFormat' => 'Y-m-d',
107 ],
108 'condition' => [
109 'preselect' => 'yes',
110 'event_to_show' => 'custom'
111 ],
112 ]
113 );
114
115 $this->add_control(
116 'select_event',
117 [
118 'label' => BackendStrings::get('select_event'),
119 'type' => Controls_Manager::SELECT2,
120 'multiple' => true,
121 'options' => self::amelia_elementor_get_events(),
122 'condition' => ['preselect' => 'yes'],
123 'placeholder' => BackendStrings::get('show_all_events')
124 ]
125 );
126
127 $this->add_control(
128 'select_tag',
129 [
130 'label' => BackendStrings::get('select_tag'),
131 'type' => Controls_Manager::SELECT2,
132 'multiple' => true,
133 'options' => self::amelia_elementor_get_tags(),
134 'condition' => ['preselect' => 'yes'],
135 'placeholder' => BackendStrings::get('show_all_tags')
136 ]
137 );
138
139
140 $this->add_control(
141 'select_location',
142 [
143 'label' => BackendStrings::get('select_location'),
144 'type' => Controls_Manager::SELECT2,
145 'multiple' => true,
146 'options' => self::amelia_elementor_get_locations(),
147 'condition' => ['preselect' => 'yes'],
148 'placeholder' => BackendStrings::get('show_all_locations')
149 ]
150 );
151
152 $this->add_control(
153 'show_recurring',
154 [
155 'label' => __('Show recurring events:'),
156 'type' => Controls_Manager::SWITCHER,
157 'condition' => ['preselect' => 'yes'],
158 'default' => false,
159 'label_on' => BackendStrings::get('yes'),
160 'label_off' => BackendStrings::get('no'),
161 ]
162 );
163
164 $this->setSharedShortcodeElements($controls_data);
165
166 $this->end_controls_section();
167 }
168
169 protected function render(): void
170 {
171 if (Plugin::$instance->editor->is_edit_mode()) {
172 $alt = esc_attr(BackendStrings::get('events_list_booking_gutenberg_block')['title']);
173 printf(
174 '<picture>' .
175 '<source media="(max-width: 360px)" srcset="%s" />' .
176 '<img class="amelia-elementor-preview" src="%s" alt="%s" style="max-width:100%%;height:auto;display:block;margin:0 auto;" />' .
177 '</picture>',
178 esc_url(AMELIA_URL . 'public/img/shortcode/elf-mobile-preview.svg'),
179 esc_url(AMELIA_URL . 'public/img/shortcode/elf-preview.svg'),
180 $alt
181 );
182 return;
183 }
184
185 $settings = $this->get_settings_for_display();
186
187 $sharedShortcode = $this->getSharedShortcodeString($settings);
188
189 if ($settings['preselect']) {
190 $selected_event = empty($settings['select_event']) ? '' : ' event="' . (is_array($settings['select_event']) ?
191 implode(',', array_map('esc_attr', $settings['select_event'])) : esc_attr($settings['select_event'])) . '"';
192
193 $event_to_show = '';
194 if (empty($settings['select_event']) && !empty($settings['event_to_show']) && $settings['event_to_show'] !== 'all') {
195 if ($settings['event_to_show'] === 'custom') {
196 if (empty($settings['start_date']) || empty($settings['end_date'])) {
197 echo BackendStrings::get('notice_for_missing_dates');
198 return;
199 }
200
201 $event_to_show = ' range="' . esc_attr($settings['start_date'] . ' - ' . $settings['end_date']) . '"';
202 } else {
203 $event_to_show = ' range="' . esc_attr($settings['event_to_show']) . '"';
204 }
205 }
206
207 $show_recurring = $settings['show_recurring'] ? ' recurring=1' : '';
208
209 $selected_location = empty($settings['select_location']) ? '' : ' location="' . (is_array($settings['select_location']) ?
210 implode(',', array_map('esc_attr', $settings['select_location'])) : esc_attr($settings['select_location'])) . '"';
211
212 $selected_tag = '';
213 if (!empty($settings['select_tag'])) {
214 $selected_tag .= ' tag="';
215 if (is_array($settings['select_tag'])) {
216 $tags = array_values(array_filter($settings['select_tag']));
217 foreach ($tags as $index => $tag) {
218 $selected_tag .= ($index === 0 ? '' : ',') . '{' . esc_attr($tag) . '}';
219 }
220 } else {
221 $selected_tag .= esc_attr($settings['select_tag']);
222 }
223 $selected_tag .= '"';
224 }
225
226 echo do_shortcode('[' . AmeliaElementorWhiteLabelHelper::shortcodeTag('eventslistbooking', 'ameliaeventslistbooking') .
227 $sharedShortcode .
228 $selected_event .
229 $event_to_show .
230 $selected_location .
231 $selected_tag .
232 $show_recurring . ']');
233 } else {
234 echo do_shortcode('[' . AmeliaElementorWhiteLabelHelper::shortcodeTag('eventslistbooking', 'ameliaeventslistbooking') .
235 $sharedShortcode .
236 ']');
237 }
238 }
239
240
241 public static function amelia_elementor_get_events()
242 {
243 $events = GutenbergBlock::getEntitiesData()['data']['events'];
244
245 $returnEvents = [];
246
247 $returnEvents['0'] = BackendStrings::get('show_all_events');
248
249 foreach ($events as $event) {
250 $returnEvents[$event['id']] = $event['name'] . ' (id: ' . $event['id'] . ') - ' . $event['formattedPeriodStart'];
251 }
252
253 return $returnEvents;
254 }
255
256 public static function amelia_elementor_get_locations()
257 {
258 $locations = GutenbergBlock::getEntitiesData()['data']['locations'];
259
260 $returnLocations = [];
261
262 $returnLocations['0'] = BackendStrings::get('show_all_locations');
263
264 foreach ($locations as $location) {
265 $returnLocations[$location['id']] = $location['name'];
266 }
267
268 return $returnLocations;
269 }
270
271 public static function amelia_elementor_get_tags()
272 {
273 $tags = GutenbergBlock::getEntitiesData()['data']['tags'];
274
275 $returnTags = [];
276
277 foreach ($tags as $index => $tag) {
278 $returnTags[$tag['name']] = $tag['name'];
279 }
280
281 return $returnTags;
282 }
283 }
284