PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.1
Booking for Appointments and Events Calendar – Amelia v2.4.1
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 8 months ago AmeliaCatalogBookingElementorWidget.php 8 months ago AmeliaCatalogElementorWidget.php 8 months ago AmeliaEventsCalendarBookingElementorWidget.php 2 months ago AmeliaEventsElementorWidget.php 2 months ago AmeliaEventsListBookingButtonElementorWidget.php 3 months ago AmeliaEventsListBookingElementorWidget.php 2 months ago AmeliaStepBookingButtonElementorWidget.php 3 months ago AmeliaStepBookingElementorWidget.php 2 months ago ElementorBlock.php 3 months ago
AmeliaEventsListBookingElementorWidget.php
305 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 $this->start_controls_section(
42 'amelia_events_section',
43 [
44 'label' => '<div class="amelia-elementor-content"><p class="amelia-elementor-content-title">'
45 . BackendStrings::get('events_list_booking_gutenberg_block')['title']
46 . '</p><br><p class="amelia-elementor-content-p">'
47 . BackendStrings::get('events_list_booking_gutenberg_block')['description']
48 . '</p>',
49 ]
50 );
51
52 $this->add_control(
53 'preselect',
54 [
55 'label' => BackendStrings::get('filter'),
56 'type' => Controls_Manager::SWITCHER,
57 'default' => false,
58 'label_on' => BackendStrings::get('yes'),
59 'label_off' => BackendStrings::get('no'),
60 ]
61 );
62
63 $this->add_control(
64 'event_to_show',
65 [
66 'label' => BackendStrings::get('event_time_scope'),
67 'type' => Controls_Manager::SELECT,
68 'condition' => ['preselect' => 'yes'],
69 'default' => 'all',
70 'options' => [
71 'all' => BackendStrings::get('all_events'),
72 'future' => BackendStrings::get('future_events'),
73 'past' => BackendStrings::get('past_events'),
74 'custom' => BackendStrings::get('custom_range'),
75 ],
76 ]
77 );
78
79 $this->add_control(
80 'start_date',
81 [
82 'label' => BackendStrings::get('red_start_date'),
83 'type' => Controls_Manager::DATE_TIME,
84 'picker_options' => [
85 'enableTime' => false,
86 'dateFormat' => 'Y-m-d',
87 ],
88 'condition' => [
89 'preselect' => 'yes',
90 'event_to_show' => 'custom'
91 ],
92 ]
93 );
94
95 $this->add_control(
96 'end_date',
97 [
98 'label' => BackendStrings::get('red_end_date'),
99 'type' => Controls_Manager::DATE_TIME,
100 'picker_options' => [
101 'enableTime' => false,
102 'dateFormat' => 'Y-m-d',
103 ],
104 'condition' => [
105 'preselect' => 'yes',
106 'event_to_show' => 'custom'
107 ],
108 ]
109 );
110
111 $this->add_control(
112 'select_event',
113 [
114 'label' => BackendStrings::get('select_event'),
115 'type' => Controls_Manager::SELECT2,
116 'multiple' => true,
117 'options' => self::amelia_elementor_get_events(),
118 'condition' => ['preselect' => 'yes'],
119 'placeholder' => BackendStrings::get('show_all_events')
120 ]
121 );
122
123 $this->add_control(
124 'select_tag',
125 [
126 'label' => BackendStrings::get('select_tag'),
127 'type' => Controls_Manager::SELECT2,
128 'multiple' => true,
129 'options' => self::amelia_elementor_get_tags(),
130 'condition' => ['preselect' => 'yes'],
131 'placeholder' => BackendStrings::get('show_all_tags')
132 ]
133 );
134
135
136 $this->add_control(
137 'select_location',
138 [
139 'label' => BackendStrings::get('select_location'),
140 'type' => Controls_Manager::SELECT2,
141 'multiple' => true,
142 'options' => self::amelia_elementor_get_locations(),
143 'condition' => ['preselect' => 'yes'],
144 'placeholder' => BackendStrings::get('show_all_locations')
145 ]
146 );
147
148 $this->add_control(
149 'show_recurring',
150 [
151 'label' => __('Show recurring events:'),
152 'type' => Controls_Manager::SWITCHER,
153 'condition' => ['preselect' => 'yes'],
154 'default' => false,
155 'label_on' => BackendStrings::get('yes'),
156 'label_off' => BackendStrings::get('no'),
157 ]
158 );
159
160 $this->add_control(
161 'load_manually',
162 [
163 'label' => BackendStrings::get('manually_loading'),
164 'label_block' => true,
165 'type' => Controls_Manager::TEXT,
166 'condition' => ['preselect' => 'yes'],
167 'placeholder' => '',
168 'description' => BackendStrings::get('manually_loading_description'),
169 ]
170 );
171
172 $this->add_control(
173 'trigger_type',
174 [
175 'label' => BackendStrings::get('trigger_type'),
176 'type' => Controls_Manager::SELECT,
177 'condition' => ['preselect' => 'yes'],
178 'description' => BackendStrings::get('trigger_type_tooltip'),
179 'options' => [
180 'id' => BackendStrings::get('trigger_type_id'),
181 'class' => BackendStrings::get('trigger_type_class')
182 ],
183 'default' => 'id'
184 ]
185 );
186
187 $this->add_control(
188 'in_dialog',
189 [
190 'label' => BackendStrings::get('in_dialog'),
191 'type' => Controls_Manager::SWITCHER,
192 'condition' => ['preselect' => 'yes'],
193 'default' => false,
194 'label_on' => BackendStrings::get('yes'),
195 'label_off' => BackendStrings::get('no'),
196 ]
197 );
198
199 $this->end_controls_section();
200 }
201
202 protected function render()
203 {
204
205 $settings = $this->get_settings_for_display();
206
207 if ($settings['preselect']) {
208 $trigger = $settings['load_manually'] !== '' ? ' trigger=' . $settings['load_manually'] : '';
209 $trigger_type = $settings['load_manually'] && $settings['trigger_type'] !== '' ? ' trigger_type=' . $settings['trigger_type'] : '';
210 $in_dialog = $settings['load_manually'] && $settings['in_dialog'] === 'yes' ? ' in_dialog=1' : '';
211
212 $selected_event = empty($settings['select_event']) ? '' : ' event=' . (is_array($settings['select_event']) ?
213 implode(',', $settings['select_event']) : $settings['select_event']);
214
215 $event_to_show = '';
216 if (empty($settings['select_event']) && !empty($settings['event_to_show']) && $settings['event_to_show'] !== 'all') {
217 if ($settings['event_to_show'] === 'custom') {
218 if (empty($settings['start_date']) || empty($settings['end_date'])) {
219 echo BackendStrings::get('notice_for_missing_dates');
220 return;
221 }
222
223 $event_to_show = ' range="' . $settings['start_date'] . ' - ' . $settings['end_date'] . '"';
224 } else {
225 $event_to_show = ' range="' . $settings['event_to_show'] . '"';
226 }
227 }
228
229 $show_recurring = $settings['show_recurring'] ? ' recurring=1' : '';
230
231 $selected_location = empty($settings['select_location']) ? '' : ' location=' . (is_array($settings['select_location']) ?
232 implode(',', $settings['select_location']) : $settings['select_location']);
233
234 $selected_tag = '';
235 if (!empty($settings['select_tag'])) {
236 $selected_tag .= ' tag="';
237 if (is_array($settings['select_tag'])) {
238 foreach (array_filter($settings['select_tag']) as $index => $tag) {
239 $selected_tag .= ($index === 0 ? '' : ',') . '{' . $tag . '}';
240 }
241 } else {
242 $selected_tag .= $settings['select_tag'];
243 }
244 $selected_tag .= '"';
245 }
246
247 echo esc_html('[ameliaeventslistbooking' .
248 $trigger .
249 $trigger_type .
250 $in_dialog .
251 $selected_event .
252 $event_to_show .
253 $selected_location .
254 $selected_tag .
255 $show_recurring . ']');
256 } else {
257 echo '[ameliaeventslistbooking]';
258 }
259 }
260
261
262 public static function amelia_elementor_get_events()
263 {
264 $events = GutenbergBlock::getEntitiesData()['data']['events'];
265
266 $returnEvents = [];
267
268 $returnEvents['0'] = BackendStrings::get('show_all_events');
269
270 foreach ($events as $event) {
271 $returnEvents[$event['id']] = $event['name'] . ' (id: ' . $event['id'] . ') - ' . $event['formattedPeriodStart'];
272 }
273
274 return $returnEvents;
275 }
276
277 public static function amelia_elementor_get_locations()
278 {
279 $locations = GutenbergBlock::getEntitiesData()['data']['locations'];
280
281 $returnLocations = [];
282
283 $returnLocations['0'] = BackendStrings::get('show_all_locations');
284
285 foreach ($locations as $location) {
286 $returnLocations[$location['id']] = $location['name'];
287 }
288
289 return $returnLocations;
290 }
291
292 public static function amelia_elementor_get_tags()
293 {
294 $tags = GutenbergBlock::getEntitiesData()['data']['tags'];
295
296 $returnTags = [];
297
298 foreach ($tags as $index => $tag) {
299 $returnTags[$tag['name']] = $tag['name'];
300 }
301
302 return $returnTags;
303 }
304 }
305