PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
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 6 months ago AmeliaCatalogBookingElementorWidget.php 3 weeks ago AmeliaCatalogElementorWidget.php 6 months ago AmeliaEventsCalendarBookingElementorWidget.php 3 weeks ago AmeliaEventsElementorWidget.php 3 weeks ago AmeliaEventsListBookingButtonElementorWidget.php 3 weeks ago AmeliaEventsListBookingElementorWidget.php 3 weeks ago AmeliaStepBookingButtonElementorWidget.php 1 month ago AmeliaStepBookingElementorWidget.php 3 weeks ago ElementorBlock.php 3 weeks ago ElementorSharedShortcodeWidget.php 3 weeks ago
AmeliaEventsListBookingElementorWidget.php
338 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 Widget_Base
19 {
20 public function get_name()
21 {
22 return 'ameliaeventslistbooking';
23 }
24
25 public function get_title()
26 {
27 return BackendStrings::get('events_list_booking_gutenberg_block')['title'];
28 }
29
30 public function get_icon()
31 {
32 return 'amelia-logo';
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 . BackendStrings::get('events_list_booking_gutenberg_block')['title']
50 . '</p><br><p class="amelia-elementor-content-p">'
51 . 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->add_control(
165 'load_manually',
166 [
167 'label' => BackendStrings::get('manually_loading'),
168 'label_block' => true,
169 'type' => Controls_Manager::TEXT,
170 'placeholder' => '',
171 'description' => BackendStrings::get('manually_loading_description'),
172 ]
173 );
174
175 $this->add_control(
176 'trigger_type',
177 [
178 'label' => BackendStrings::get('trigger_type'),
179 'type' => Controls_Manager::SELECT,
180 'description' => BackendStrings::get('trigger_type_tooltip'),
181 'options' => [
182 'id' => BackendStrings::get('trigger_type_id'),
183 'class' => BackendStrings::get('trigger_type_class')
184 ],
185 'condition' => [
186 'load_manually!' => '',
187 ],
188 'default' => 'id'
189 ]
190 );
191
192 $this->add_control(
193 'in_dialog',
194 [
195 'label' => BackendStrings::get('in_dialog'),
196 'type' => Controls_Manager::SWITCHER,
197 'default' => false,
198 'label_on' => BackendStrings::get('yes'),
199 'label_off' => BackendStrings::get('no'),
200 'condition' => [
201 'load_manually!' => '',
202 ],
203 ]
204 );
205
206 if (!empty($controls_data['ivy'])) {
207 $this->add_control(
208 'ivy',
209 [
210 'label' => BackendStrings::get('ivy'),
211 'type' => Controls_Manager::SELECT,
212 'description' => BackendStrings::get('ivy_tooltip'),
213 'options' => $controls_data['ivy'],
214 'default' => '',
215 'condition' => [
216 'load_manually' => '',
217 ],
218 ]
219 );
220 }
221
222 $this->end_controls_section();
223 }
224
225 protected function render()
226 {
227
228 $settings = $this->get_settings_for_display();
229
230 $ivy = empty($settings['load_manually']) && !empty($settings['ivy']) && $settings['ivy'] !== '0' ?
231 ' ivy="' . esc_attr($settings['ivy']) . '"' : '';
232
233 $trigger = $settings['load_manually'] !== '' ? ' trigger="' . esc_attr($settings['load_manually']) . '"' : '';
234 $trigger_type = $settings['load_manually'] && $settings['trigger_type'] !== '' ? ' trigger_type="' . esc_attr($settings['trigger_type']) . '"' : '';
235 $in_dialog = $settings['load_manually'] && $settings['in_dialog'] === 'yes' ? ' in_dialog=1' : '';
236
237 if ($settings['preselect']) {
238 $selected_event = empty($settings['select_event']) ? '' : ' event="' . (is_array($settings['select_event']) ?
239 implode(',', array_map('esc_attr', $settings['select_event'])) : esc_attr($settings['select_event'])) . '"';
240
241 $event_to_show = '';
242 if (empty($settings['select_event']) && !empty($settings['event_to_show']) && $settings['event_to_show'] !== 'all') {
243 if ($settings['event_to_show'] === 'custom') {
244 if (empty($settings['start_date']) || empty($settings['end_date'])) {
245 echo BackendStrings::get('notice_for_missing_dates');
246 return;
247 }
248
249 $event_to_show = ' range="' . esc_attr($settings['start_date'] . ' - ' . $settings['end_date']) . '"';
250 } else {
251 $event_to_show = ' range="' . esc_attr($settings['event_to_show']) . '"';
252 }
253 }
254
255 $show_recurring = $settings['show_recurring'] ? ' recurring=1' : '';
256
257 $selected_location = empty($settings['select_location']) ? '' : ' location="' . (is_array($settings['select_location']) ?
258 implode(',', array_map('esc_attr', $settings['select_location'])) : esc_attr($settings['select_location'])) . '"';
259
260 $selected_tag = '';
261 if (!empty($settings['select_tag'])) {
262 $selected_tag .= ' tag="';
263 if (is_array($settings['select_tag'])) {
264 $tags = array_values(array_filter($settings['select_tag']));
265 foreach ($tags as $index => $tag) {
266 $selected_tag .= ($index === 0 ? '' : ',') . '{' . esc_attr($tag) . '}';
267 }
268 } else {
269 $selected_tag .= esc_attr($settings['select_tag']);
270 }
271 $selected_tag .= '"';
272 }
273
274 echo '[ameliaeventslistbooking' .
275 $trigger .
276 $trigger_type .
277 $in_dialog .
278 $selected_event .
279 $event_to_show .
280 $selected_location .
281 $selected_tag .
282 $ivy .
283 $show_recurring . ']';
284 } else {
285 echo '[ameliaeventslistbooking' .
286 $trigger .
287 $trigger_type .
288 $in_dialog .
289 $ivy .
290 ']';
291 }
292 }
293
294
295 public static function amelia_elementor_get_events()
296 {
297 $events = GutenbergBlock::getEntitiesData()['data']['events'];
298
299 $returnEvents = [];
300
301 $returnEvents['0'] = BackendStrings::get('show_all_events');
302
303 foreach ($events as $event) {
304 $returnEvents[$event['id']] = $event['name'] . ' (id: ' . $event['id'] . ') - ' . $event['formattedPeriodStart'];
305 }
306
307 return $returnEvents;
308 }
309
310 public static function amelia_elementor_get_locations()
311 {
312 $locations = GutenbergBlock::getEntitiesData()['data']['locations'];
313
314 $returnLocations = [];
315
316 $returnLocations['0'] = BackendStrings::get('show_all_locations');
317
318 foreach ($locations as $location) {
319 $returnLocations[$location['id']] = $location['name'];
320 }
321
322 return $returnLocations;
323 }
324
325 public static function amelia_elementor_get_tags()
326 {
327 $tags = GutenbergBlock::getEntitiesData()['data']['tags'];
328
329 $returnTags = [];
330
331 foreach ($tags as $index => $tag) {
332 $returnTags[$tag['name']] = $tag['name'];
333 }
334
335 return $returnTags;
336 }
337 }
338