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 / AmeliaEventsCalendarBookingElementorWidget.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
AmeliaEventsCalendarBookingElementorWidget.php
294 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 AmeliaEventsCalendarBookingElementorWidget
15 *
16 * @package AmeliaBooking\Infrastructure\WP\Elementor
17 */
18 class AmeliaEventsCalendarBookingElementorWidget extends ElementorSharedShortcodeWidget
19 {
20 public function get_name()
21 {
22 return 'ameliaeventscalendarbooking';
23 }
24
25 public function get_title()
26 {
27 return AmeliaElementorWhiteLabelHelper::label(BackendStrings::get('events_calendar_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_calendar_booking_gutenberg_block')['title'])
50 . '</p><br><p class="amelia-elementor-content-p">'
51 . AmeliaElementorWhiteLabelHelper::label(BackendStrings::get('events_calendar_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 'select_event',
69 [
70 'label' => BackendStrings::get('select_event'),
71 'type' => Controls_Manager::SELECT2,
72 'multiple' => true,
73 'options' => self::amelia_elementor_get_events(),
74 'condition' => ['preselect' => 'yes'],
75 'placeholder' => BackendStrings::get('show_all_events')
76 ]
77 );
78
79 $this->add_control(
80 'select_tag',
81 [
82 'label' => BackendStrings::get('select_tag'),
83 'type' => Controls_Manager::SELECT2,
84 'multiple' => true,
85 'options' => self::amelia_elementor_get_tags(),
86 'condition' => ['preselect' => 'yes'],
87 'placeholder' => BackendStrings::get('show_all_tags')
88 ]
89 );
90
91
92 $this->add_control(
93 'select_location',
94 [
95 'label' => BackendStrings::get('select_location'),
96 'type' => Controls_Manager::SELECT2,
97 'multiple' => true,
98 'options' => self::amelia_elementor_get_locations(),
99 'condition' => ['preselect' => 'yes'],
100 'placeholder' => BackendStrings::get('show_all_locations')
101 ]
102 );
103
104 $this->add_control(
105 'show_recurring',
106 [
107 'label' => __('Show recurring events:'),
108 'type' => Controls_Manager::SWITCHER,
109 'condition' => ['preselect' => 'yes'],
110 'default' => false,
111 'label_on' => BackendStrings::get('yes'),
112 'label_off' => BackendStrings::get('no'),
113 ]
114 );
115
116 $this->add_control(
117 'load_manually',
118 [
119 'label' => BackendStrings::get('manually_loading'),
120 'label_block' => true,
121 'type' => Controls_Manager::TEXT,
122 'placeholder' => '',
123 'description' => BackendStrings::get('manually_loading_description'),
124 ]
125 );
126
127 $this->add_control(
128 'trigger_type',
129 [
130 'label' => BackendStrings::get('trigger_type'),
131 'type' => Controls_Manager::SELECT,
132 'description' => BackendStrings::get('trigger_type_tooltip'),
133 'options' => [
134 'id' => BackendStrings::get('trigger_type_id'),
135 'class' => BackendStrings::get('trigger_type_class')
136 ],
137 'condition' => [
138 'load_manually!' => '',
139 ],
140 'default' => 'id'
141 ]
142 );
143
144 $this->add_control(
145 'in_dialog',
146 [
147 'label' => AmeliaElementorWhiteLabelHelper::label(BackendStrings::get('in_dialog')),
148 'type' => Controls_Manager::SWITCHER,
149 'default' => false,
150 'label_on' => BackendStrings::get('yes'),
151 'label_off' => BackendStrings::get('no'),
152 'condition' => [
153 'load_manually!' => '',
154 ],
155 ]
156 );
157
158 if (!empty($controls_data['ivy'])) {
159 $this->add_control(
160 'ivy',
161 [
162 'label' => BackendStrings::get('ivy'),
163 'type' => Controls_Manager::SELECT,
164 'description' => BackendStrings::get('ivy_tooltip'),
165 'options' => $controls_data['ivy'],
166 'default' => '',
167 'condition' => [
168 'load_manually' => '',
169 ],
170 ]
171 );
172 }
173
174 $this->end_controls_section();
175 }
176
177 protected function render(): void
178 {
179 if (Plugin::$instance->editor->is_edit_mode()) {
180 $alt = esc_attr(BackendStrings::get('events_calendar_booking_gutenberg_block')['title']);
181 printf(
182 '<picture>' .
183 '<source media="(max-width: 360px)" srcset="%s" />' .
184 '<img class="amelia-elementor-preview" src="%s" alt="%s" style="max-width:100%%;height:auto;display:block;margin:0 auto;" />' .
185 '</picture>',
186 esc_url(AMELIA_URL . 'public/img/shortcode/ecf-mobile-preview.svg'),
187 esc_url(AMELIA_URL . 'public/img/shortcode/ecf-preview.svg'),
188 $alt
189 );
190 return;
191 }
192
193 $settings = $this->get_settings_for_display();
194
195 $ivy = empty($settings['load_manually']) && !empty($settings['ivy']) && $settings['ivy'] !== '0' ?
196 ' ivy="' . esc_attr($settings['ivy']) . '"' : '';
197
198 $trigger = $settings['load_manually'] !== '' ? ' trigger="' . esc_attr($settings['load_manually']) . '"' : '';
199 $trigger_type = $settings['load_manually'] && $settings['trigger_type'] !== '' ? ' trigger_type="' . esc_attr($settings['trigger_type']) . '"' : '';
200 $in_dialog = $settings['load_manually'] && $settings['in_dialog'] === 'yes' ? ' in_dialog=1' : '';
201
202 if ($settings['preselect']) {
203 $selected_event = empty($settings['select_event']) ? '' : ' event="' . (is_array($settings['select_event']) ?
204 implode(',', array_map('esc_attr', $settings['select_event'])) : esc_attr($settings['select_event'])) . '"';
205
206 $show_recurring = $settings['show_recurring'] ? ' recurring=1' : '';
207
208 $selected_location = empty($settings['select_location']) ? '' : ' location="' . (is_array($settings['select_location']) ?
209 implode(',', array_map('esc_attr', $settings['select_location'])) : esc_attr($settings['select_location'])) . '"';
210
211 $selected_tag = '';
212 if (!empty($settings['select_tag'])) {
213 $selected_tag .= ' tag="';
214 if (is_array($settings['select_tag'])) {
215 $tags = array_values(array_filter($settings['select_tag']));
216 foreach ($tags as $index => $tag) {
217 $selected_tag .= ($index === 0 ? '' : ',') . '{' . esc_attr($tag) . '}';
218 }
219 } else {
220 $selected_tag .= esc_attr($settings['select_tag']);
221 }
222 $selected_tag .= '"';
223 }
224
225 echo do_shortcode('[' . AmeliaElementorWhiteLabelHelper::shortcodeTag(
226 'eventscalendarbooking',
227 'ameliaeventscalendarbooking'
228 ) .
229 $trigger .
230 $trigger_type .
231 $in_dialog .
232 $selected_event .
233 $selected_location .
234 $selected_tag .
235 $ivy .
236 $show_recurring . ']');
237 } else {
238 echo do_shortcode('[' . AmeliaElementorWhiteLabelHelper::shortcodeTag(
239 'eventscalendarbooking',
240 'ameliaeventscalendarbooking'
241 ) .
242 $trigger .
243 $trigger_type .
244 $in_dialog .
245 $ivy .
246 ']');
247 }
248 }
249
250
251 public static function amelia_elementor_get_events()
252 {
253 $events = GutenbergBlock::getEntitiesData()['data']['events'];
254
255 $returnEvents = [];
256
257 $returnEvents['0'] = BackendStrings::get('show_all_events');
258
259 foreach ($events as $event) {
260 $returnEvents[$event['id']] = $event['name'] . ' (id: ' . $event['id'] . ') - ' . $event['formattedPeriodStart'];
261 }
262
263 return $returnEvents;
264 }
265
266 public static function amelia_elementor_get_locations()
267 {
268 $locations = GutenbergBlock::getEntitiesData()['data']['locations'];
269
270 $returnLocations = [];
271
272 $returnLocations['0'] = BackendStrings::get('show_all_locations');
273
274 foreach ($locations as $location) {
275 $returnLocations[$location['id']] = $location['name'];
276 }
277
278 return $returnLocations;
279 }
280
281 public static function amelia_elementor_get_tags()
282 {
283 $tags = GutenbergBlock::getEntitiesData()['data']['tags'];
284
285 $returnTags = [];
286
287 foreach ($tags as $index => $tag) {
288 $returnTags[$tag['name']] = $tag['name'];
289 }
290
291 return $returnTags;
292 }
293 }
294